aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/api.go24
-rw-r--r--api/binapi.go22
-rw-r--r--api/stats.go26
-rw-r--r--api/trace.go46
4 files changed, 95 insertions, 23 deletions
diff --git a/api/api.go b/api/api.go
index 977b02e..c4f069f 100644
--- a/api/api.go
+++ b/api/api.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2020 Cisco and/or its affiliates.
+// Copyright (c) 2021 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -25,31 +25,27 @@ import (
type Connection interface {
// NewStream creates a new stream for sending and receiving messages.
// Context can be used to close the stream using cancel or timeout.
- NewStream(ctx context.Context) (Stream, error)
+ NewStream(ctx context.Context, options ...StreamOption) (Stream, error)
// Invoke can be used for a simple request-reply RPC.
- // It creates stream and calls SendMsg with req and RecvMsg with reply.
+ // It creates stream and calls SendMsg with req and RecvMsg which returns
+ // reply.
Invoke(ctx context.Context, req Message, reply Message) error
}
// Stream provides low-level access for sending and receiving messages.
// Users should handle correct type and ordering of messages.
//
+// It is not safe to call these methods on the same stream in different
+// goroutines.
+//
// NOTE: This API is EXPERIMENTAL.
type Stream interface {
// SendMsg sends a message to the client.
// It blocks until message is sent to the transport.
- //
- // It is safe to have a goroutine calling SendMsg and another goroutine
- // calling RecvMsg on the same stream at the same time, but it is not safe
- // to call SendMsg on the same stream in different goroutines.
SendMsg(Message) error
// RecvMsg blocks until a message is received or error occurs.
- //
- // It is safe to have a goroutine calling SendMsg and another goroutine
- // calling RecvMsg on the same stream at the same time, but it is not safe
- // to call SendMsg on the same stream in different goroutines.
RecvMsg() (Message, error)
// Close closes the stream. Calling SendMsg and RecvMsg will return error
@@ -57,6 +53,12 @@ type Stream interface {
Close() error
}
+// StreamOption allows customizing a Stream. Available options are:
+// - WithRequestSize
+// - WithReplySize
+// - WithReplyTimeout
+type StreamOption func(Stream)
+
// ChannelProvider provides the communication channel with govpp core.
type ChannelProvider interface {
// NewAPIChannel returns a new channel for communication with VPP via govpp core.
diff --git a/api/binapi.go b/api/binapi.go
index cb4ab85..1b07a7e 100644
--- a/api/binapi.go
+++ b/api/binapi.go
@@ -15,7 +15,7 @@
package api
import (
- "fmt"
+ "path"
"reflect"
)
@@ -59,27 +59,27 @@ type DataType interface {
}
var (
- registeredMessageTypes = make(map[reflect.Type]string)
- registeredMessages = make(map[string]Message)
+ registeredMessages = make(map[string]map[string]Message)
+ registeredMessageTypes = make(map[string]map[reflect.Type]string)
)
// RegisterMessage is called from generated code to register message.
func RegisterMessage(x Message, name string) {
- typ := reflect.TypeOf(x)
- namecrc := x.GetMessageName() + "_" + x.GetCrcString()
- if _, ok := registeredMessageTypes[typ]; ok {
- panic(fmt.Errorf("govpp: message type %v already registered as %s (%s)", typ, name, namecrc))
+ binapiPath := path.Dir(reflect.TypeOf(x).Elem().PkgPath())
+ if _, ok := registeredMessages[binapiPath]; !ok {
+ registeredMessages[binapiPath] = make(map[string]Message)
+ registeredMessageTypes[binapiPath] = make(map[reflect.Type]string)
}
- registeredMessages[namecrc] = x
- registeredMessageTypes[typ] = name
+ registeredMessages[binapiPath][x.GetMessageName()+"_"+x.GetCrcString()] = x
+ registeredMessageTypes[binapiPath][reflect.TypeOf(x)] = name
}
// GetRegisteredMessages returns list of all registered messages.
-func GetRegisteredMessages() map[string]Message {
+func GetRegisteredMessages() map[string]map[string]Message {
return registeredMessages
}
// GetRegisteredMessageTypes returns list of all registered message types.
-func GetRegisteredMessageTypes() map[reflect.Type]string {
+func GetRegisteredMessageTypes() map[string]map[reflect.Type]string {
return registeredMessageTypes
}
diff --git a/api/stats.go b/api/stats.go
index 2850b5f..d5665b7 100644
--- a/api/stats.go
+++ b/api/stats.go
@@ -21,6 +21,7 @@ type StatsProvider interface {
GetInterfaceStats(*InterfaceStats) error
GetErrorStats(*ErrorStats) error
GetBufferStats(*BufferStats) error
+ GetMemoryStats(*MemoryStats) error
}
// SystemStats represents global system statistics.
@@ -97,7 +98,7 @@ type ErrorStats struct {
type ErrorCounter struct {
CounterName string
- Value uint64
+ Values []uint64
}
// BufferStats represents statistics per buffer pool.
@@ -113,3 +114,26 @@ type BufferPool struct {
Used float64
Available float64
}
+
+// MemoryStats represents memory stats segment counters.
+type MemoryStats struct {
+ // Deprecated: /mem/statseg total memory directory
+ Total float64
+ // Deprecated: /mem/statseg used memory directory
+ Used float64
+
+ // stat/main memory usage per-heap
+ Stat map[int]MemoryCounters
+ Main map[int]MemoryCounters
+}
+
+// MemoryCounters represents values of various memory usage
+type MemoryCounters struct {
+ Total uint64
+ Used uint64
+ Free uint64
+ UsedMMap uint64
+ TotalAlloc uint64
+ FreeChunks uint64
+ Releasable uint64
+}
diff --git a/api/trace.go b/api/trace.go
new file mode 100644
index 0000000..4ff46e8
--- /dev/null
+++ b/api/trace.go
@@ -0,0 +1,46 @@
+// Copyright (c) 2021 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package api
+
+import (
+ "time"
+)
+
+// Trace gives access to the API trace tool, capturing outcoming and incoming messages
+// to and from GoVPP.
+type Trace interface {
+ // Enable allows to enable or disable API trace for a connection.
+ Enable(enable bool)
+
+ // GetRecords retrieves all messages collected (from all channels if they are used)
+ // since the point the trace was enabled or cleared.
+ GetRecords() []*Record
+
+ // GetRecordsForChannel retrieves messages collected by the given channel since
+ // the point the trace was enabled or cleared.
+ GetRecordsForChannel(chId uint16) []*Record
+
+ // Clear erases messages captured so far.
+ Clear()
+}
+
+// Record contains essential information about traced message, its timestamp and whether
+// the message was received or sent
+type Record struct {
+ Message Message
+ Timestamp time.Time
+ IsReceived bool
+ ChannelID uint16
+}