summaryrefslogtreecommitdiffstats
path: root/adapter
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2018-08-23 22:51:56 +0200
committerOndrej Fabry <ofabry@cisco.com>2018-08-24 12:43:05 +0200
commit6b350c65fe0ec845cecf58bfb41ffc63dc9c04f7 (patch)
tree6255495854f43ec2f2d11f88990369aadb48db3f /adapter
parent892683bef86cacc2ccda2b4df2b079171bd92164 (diff)
Simplify subscribing to events and fix events
- there is no need for sending subscription requests through channels, since all the messages are registered and no communication with VPP is needed Change-Id: Ibc29957be02a32e26309f66c369a071559b822a9 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'adapter')
-rw-r--r--adapter/adapter.go2
-rw-r--r--adapter/mock/mock_adapter.go11
-rw-r--r--adapter/vppapiclient/vppapiclient_adapter.go9
3 files changed, 10 insertions, 12 deletions
diff --git a/adapter/adapter.go b/adapter/adapter.go
index 7d3d1e4..aa34329 100644
--- a/adapter/adapter.go
+++ b/adapter/adapter.go
@@ -22,7 +22,7 @@ import (
var ErrNotImplemented = errors.New("not implemented for this OS")
// MsgCallback defines func signature for message callback.
-type MsgCallback func(msgID uint16, context uint32, data []byte)
+type MsgCallback func(msgID uint16, data []byte)
// VppAdapter provides connection to VPP. It is responsible for sending and receiving of binary-encoded messages to/from VPP.
type VppAdapter interface {
diff --git a/adapter/mock/mock_adapter.go b/adapter/mock/mock_adapter.go
index 5ca190f..cdf2081 100644
--- a/adapter/mock/mock_adapter.go
+++ b/adapter/mock/mock_adapter.go
@@ -92,9 +92,9 @@ const (
// NewVppAdapter returns a new mock adapter.
func NewVppAdapter() *VppAdapter {
a := &VppAdapter{
+ msgIDSeq: 1000,
msgIDsToName: make(map[uint16]string),
msgNameToIds: make(map[string]uint16),
- msgIDSeq: 1000,
binAPITypes: make(map[string]reflect.Type),
}
a.registerBinAPITypes()
@@ -186,8 +186,7 @@ func (a *VppAdapter) ReplyBytes(request MessageDTO, reply api.Message) ([]byte,
if err != nil {
return nil, err
}
- err = struc.Pack(buf, reply)
- if err != nil {
+ if err = struc.Pack(buf, reply); err != nil {
return nil, err
}
@@ -245,7 +244,7 @@ func (a *VppAdapter) SendMsg(clientID uint32, data []byte) error {
Data: data,
})
if finished {
- a.callback(msgID, clientID, reply)
+ a.callback(msgID, reply)
return nil
}
}
@@ -276,7 +275,7 @@ func (a *VppAdapter) SendMsg(clientID uint32, data []byte) error {
struc.Pack(buf, &codec.VppOtherHeader{VlMsgID: msgID})
}
struc.Pack(buf, msg.Msg)
- a.callback(msgID, context, buf.Bytes())
+ a.callback(msgID, buf.Bytes())
}
a.replies = a.replies[1:]
@@ -295,7 +294,7 @@ func (a *VppAdapter) SendMsg(clientID uint32, data []byte) error {
msgID := uint16(defaultReplyMsgID)
struc.Pack(buf, &codec.VppReplyHeader{VlMsgID: msgID, Context: clientID})
struc.Pack(buf, &defaultReply{})
- a.callback(msgID, clientID, buf.Bytes())
+ a.callback(msgID, buf.Bytes())
}
return nil
}
diff --git a/adapter/vppapiclient/vppapiclient_adapter.go b/adapter/vppapiclient/vppapiclient_adapter.go
index 7aafa55..e62bccd 100644
--- a/adapter/vppapiclient/vppapiclient_adapter.go
+++ b/adapter/vppapiclient/vppapiclient_adapter.go
@@ -28,7 +28,7 @@ package vppapiclient
#include <arpa/inet.h>
#include <vpp-api/client/vppapiclient.h>
-extern void go_msg_callback(uint16_t msg_id, uint32_t context, void* data, size_t size);
+extern void go_msg_callback(uint16_t msg_id, void* data, size_t size);
typedef struct __attribute__((__packed__)) _req_header {
uint16_t msg_id;
@@ -38,14 +38,13 @@ typedef struct __attribute__((__packed__)) _req_header {
typedef struct __attribute__((__packed__)) _reply_header {
uint16_t msg_id;
- uint32_t context; // currently not all reply messages contain context field
} reply_header_t;
static void
govpp_msg_callback (unsigned char *data, int size)
{
reply_header_t *header = ((reply_header_t *)data);
- go_msg_callback(ntohs(header->msg_id), ntohl(header->context), data, size);
+ go_msg_callback(ntohs(header->msg_id), data, size);
}
static int
@@ -204,10 +203,10 @@ func fileExists(name string) bool {
}
//export go_msg_callback
-func go_msg_callback(msgID C.uint16_t, context C.uint32_t, data unsafe.Pointer, size C.size_t) {
+func go_msg_callback(msgID C.uint16_t, data unsafe.Pointer, size C.size_t) {
// convert unsafe.Pointer to byte slice
slice := &reflect.SliceHeader{Data: uintptr(data), Len: int(size), Cap: int(size)}
byteArr := *(*[]byte)(unsafe.Pointer(slice))
- vppClient.callback(uint16(msgID), uint32(context), byteArr)
+ vppClient.callback(uint16(msgID), byteArr)
}