diff options
Diffstat (limited to 'adapter/socketclient')
-rw-r--r-- | adapter/socketclient/binapi.go | 120 | ||||
-rw-r--r-- | adapter/socketclient/socketclient.go | 14 |
2 files changed, 126 insertions, 8 deletions
diff --git a/adapter/socketclient/binapi.go b/adapter/socketclient/binapi.go new file mode 100644 index 0000000..5de0c30 --- /dev/null +++ b/adapter/socketclient/binapi.go @@ -0,0 +1,120 @@ +package socketclient + +import ( + "git.fd.io/govpp.git/api" +) + +// MessageTableEntry represents VPP binary API type 'message_table_entry'. +type MessageTableEntry struct { + Index uint16 + Name string `struc:"[64]byte"` +} + +func (*MessageTableEntry) GetTypeName() string { + return "message_table_entry" +} + +// SockclntCreate represents VPP binary API message 'sockclnt_create'. +type SockclntCreate struct { + Name string `struc:"[64]byte"` +} + +func (*SockclntCreate) GetMessageName() string { + return "sockclnt_create" +} +func (*SockclntCreate) GetCrcString() string { + return "455fb9c4" +} +func (*SockclntCreate) GetMessageType() api.MessageType { + return api.ReplyMessage +} + +// SockclntCreateReply represents VPP binary API message 'sockclnt_create_reply'. +type SockclntCreateReply struct { + Response int32 + Index uint32 + Count uint16 `struc:"sizeof=MessageTable"` + MessageTable []MessageTableEntry +} + +func (*SockclntCreateReply) GetMessageName() string { + return "sockclnt_create_reply" +} +func (*SockclntCreateReply) GetCrcString() string { + return "35166268" +} +func (*SockclntCreateReply) GetMessageType() api.MessageType { + return api.RequestMessage +} + +// SockclntDelete represents VPP binary API message 'sockclnt_delete'. +type SockclntDelete struct { + Index uint32 +} + +func (*SockclntDelete) GetMessageName() string { + return "sockclnt_delete" +} +func (*SockclntDelete) GetCrcString() string { + return "8ac76db6" +} +func (*SockclntDelete) GetMessageType() api.MessageType { + return api.RequestMessage +} + +// SockclntDeleteReply represents VPP binary API message 'sockclnt_delete_reply'. +type SockclntDeleteReply struct { + Response int32 +} + +func (*SockclntDeleteReply) GetMessageName() string { + return "sockclnt_delete_reply" +} +func (*SockclntDeleteReply) GetCrcString() string { + return "8f38b1ee" +} +func (*SockclntDeleteReply) GetMessageType() api.MessageType { + return api.ReplyMessage +} + +// ModuleVersion represents VPP binary API type 'module_version'. +type ModuleVersion struct { + Major uint32 + Minor uint32 + Patch uint32 + Name string `struc:"[64]byte"` +} + +func (*ModuleVersion) GetTypeName() string { + return "module_version" +} + +// APIVersions represents VPP binary API message 'api_versions'. +type APIVersions struct{} + +func (*APIVersions) GetMessageName() string { + return "api_versions" +} +func (*APIVersions) GetCrcString() string { + return "51077d14" +} +func (*APIVersions) GetMessageType() api.MessageType { + return api.RequestMessage +} + +// APIVersionsReply represents VPP binary API message 'api_versions_reply'. +type APIVersionsReply struct { + Retval int32 + Count uint32 `struc:"sizeof=APIVersions"` + APIVersions []ModuleVersion +} + +func (*APIVersionsReply) GetMessageName() string { + return "api_versions_reply" +} +func (*APIVersionsReply) GetCrcString() string { + return "5f0d99d6" +} +func (*APIVersionsReply) GetMessageType() api.MessageType { + return api.ReplyMessage +} diff --git a/adapter/socketclient/socketclient.go b/adapter/socketclient/socketclient.go index 1c425ba..043d253 100644 --- a/adapter/socketclient/socketclient.go +++ b/adapter/socketclient/socketclient.go @@ -32,7 +32,6 @@ import ( "git.fd.io/govpp.git/adapter" "git.fd.io/govpp.git/codec" - "git.fd.io/govpp.git/examples/binapi/memclnt" ) const ( @@ -313,9 +312,7 @@ const ( func (c *vppClient) open() error { msgCodec := new(codec.MsgCodec) - req := &memclnt.SockclntCreate{ - Name: []byte(ClientName), - } + req := &SockclntCreate{Name: ClientName} msg, err := msgCodec.EncodeMsg(req, sockCreateMsgId) if err != nil { Log.Debugln("Encode error:", err) @@ -343,7 +340,7 @@ func (c *vppClient) open() error { return err } - reply := new(memclnt.SockclntCreateReply) + reply := new(SockclntCreateReply) if err := msgCodec.DecodeMsg(msgReply, reply); err != nil { Log.Println("Decode error:", err) return err @@ -355,7 +352,8 @@ func (c *vppClient) open() error { c.clientIndex = reply.Index c.msgTable = make(map[string]uint16, reply.Count) for _, x := range reply.MessageTable { - name := string(bytes.TrimSuffix(bytes.Split(x.Name, []byte{0x00})[0], []byte{0x13})) + msgName := strings.Split(x.Name, "\x00")[0] + name := strings.TrimSuffix(msgName, "\x13") c.msgTable[name] = x.Index if strings.HasPrefix(name, "sockclnt_delete_") { c.sockDelMsgId = x.Index @@ -371,7 +369,7 @@ func (c *vppClient) open() error { func (c *vppClient) close() error { msgCodec := new(codec.MsgCodec) - req := &memclnt.SockclntDelete{ + req := &SockclntDelete{ Index: c.clientIndex, } msg, err := msgCodec.EncodeMsg(req, c.sockDelMsgId) @@ -406,7 +404,7 @@ func (c *vppClient) close() error { return err } - reply := new(memclnt.SockclntDeleteReply) + reply := new(SockclntDeleteReply) if err := msgCodec.DecodeMsg(msgReply, reply); err != nil { Log.Debugln("Decode error:", err) return err |