Fix: generate (un)marshall for memory client messages 53/27853/1
authorVladimir Lavor <vlavor@cisco.com>
Fri, 10 Jul 2020 11:33:05 +0000 (13:33 +0200)
committerVladimir Lavor <vlavor@cisco.com>
Fri, 10 Jul 2020 11:33:05 +0000 (13:33 +0200)
* use generated Marshall/Unmarshall for socket client connection
  messages instead of the generic wrapper

Change-Id: Ie1049e080630dbc60085debc6875e17962e93a0e
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
adapter/socketclient/binapi.go [deleted file]
adapter/socketclient/binapi/gen.go [new file with mode: 0644]
adapter/socketclient/binapi/memclnt/memclnt.ba.go [moved from examples/binapi/memclnt/memclnt.ba.go with 100% similarity]
adapter/socketclient/socketclient.go
examples/binapi/gen.go
examples/binapi/mactime/mactime.ba.go
examples/binapi/memclnt/memclnt_rpc.ba.go [deleted file]

diff --git a/adapter/socketclient/binapi.go b/adapter/socketclient/binapi.go
deleted file mode 100644 (file)
index 5de0c30..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-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/binapi/gen.go b/adapter/socketclient/binapi/gen.go
new file mode 100644 (file)
index 0000000..eb64401
--- /dev/null
@@ -0,0 +1,5 @@
+package binapi
+
+// Generate Go code from the VPP APIs located in the /usr/share/vpp/api directory.
+
+//go:generate binapi-generator -include-services=false memclnt
index 867278b..b2c5d47 100644 (file)
@@ -19,6 +19,7 @@ import (
        "encoding/binary"
        "errors"
        "fmt"
+       "git.fd.io/govpp.git/adapter/socketclient/binapi/memclnt"
        "io"
        "net"
        "os"
@@ -325,7 +326,7 @@ func (c *socketClient) open() error {
        var msgCodec = codec.DefaultCodec
 
        // Request socket client create
-       req := &SockclntCreate{
+       req := &memclnt.SockclntCreate{
                Name: c.clientName,
        }
        msg, err := msgCodec.EncodeMsg(req, sockCreateMsgId)
@@ -346,7 +347,7 @@ func (c *socketClient) open() error {
                return err
        }
 
-       reply := new(SockclntCreateReply)
+       reply := new(memclnt.SockclntCreateReply)
        if err := msgCodec.DecodeMsg(msgReply, reply); err != nil {
                log.Println("Decoding sockclnt_create_reply failed:", err)
                return err
@@ -377,7 +378,7 @@ func (c *socketClient) open() error {
 func (c *socketClient) close() error {
        var msgCodec = codec.DefaultCodec
 
-       req := &SockclntDelete{
+       req := &memclnt.SockclntDelete{
                Index: c.clientIndex,
        }
        msg, err := msgCodec.EncodeMsg(req, c.sockDelMsgId)
@@ -405,7 +406,7 @@ func (c *socketClient) close() error {
                return err
        }
 
-       reply := new(SockclntDeleteReply)
+       reply := new(memclnt.SockclntDeleteReply)
        if err := msgCodec.DecodeMsg(msgReply, reply); err != nil {
                log.Debugln("Decoding sockclnt_delete_reply failed:", err)
                return err
index 46399f4..fe08d7f 100644 (file)
@@ -2,4 +2,4 @@ package binapi
 
 // Generate Go code from the VPP APIs located in the /usr/share/vpp/api directory.
 
-//go:generate binapi-generator --import-types=false mactime af_packet interface interface_types ip memclnt vpe sr acl memif ip_types fib_types
+//go:generate binapi-generator --import-types=false mactime af_packet interface interface_types ip vpe sr acl memif ip_types fib_types
index 38a206e..7b9a0b2 100644 (file)
@@ -19,9 +19,12 @@ import (
        "bytes"
        "context"
        "encoding/binary"
+       "fmt"
        "io"
        "math"
+       "net"
        "strconv"
+       "strings"
 
        api "git.fd.io/govpp.git/api"
        codec "git.fd.io/govpp.git/codec"
@@ -45,23 +48,22 @@ const (
        VersionCrc = 0x9283d3e
 )
 
-type IfStatusFlags = interface_types.IfStatusFlags
-
-type IfType = interface_types.IfType
-
-type LinkDuplex = interface_types.LinkDuplex
-
-type MtuProto = interface_types.MtuProto
-
-type RxMode = interface_types.RxMode
-
-type SubIfFlags = interface_types.SubIfFlags
-
-type InterfaceIndex = interface_types.InterfaceIndex
-
 // MacAddress represents VPP binary API alias 'mac_address'.
 type MacAddress [6]uint8
 
+func ParseMAC(mac string) (parsed MacAddress, err error) {
+       var hw net.HardwareAddr
+       if hw, err = net.ParseMAC(mac); err != nil {
+               return
+       }
+       copy(parsed[:], hw[:])
+       return
+}
+
+func (m *MacAddress) ToString() string {
+       return net.HardwareAddr(m[:]).String()
+}
+
 // MactimeTimeRange represents VPP binary API type 'mactime_time_range'.
 type MactimeTimeRange struct {
        Start float64 `binapi:"f64,name=start" json:"start,omitempty"`
@@ -547,8 +549,8 @@ func (m *MactimeDumpReply) Unmarshal(tmp []byte) error {
 
 // MactimeEnableDisable represents VPP binary API message 'mactime_enable_disable'.
 type MactimeEnableDisable struct {
-       EnableDisable bool           `binapi:"bool,name=enable_disable" json:"enable_disable,omitempty"`
-       SwIfIndex     InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+       EnableDisable bool                           `binapi:"bool,name=enable_disable" json:"enable_disable,omitempty"`
+       SwIfIndex     interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
 }
 
 func (m *MactimeEnableDisable) Reset()                        { *m = MactimeEnableDisable{} }
@@ -597,7 +599,7 @@ func (m *MactimeEnableDisable) Unmarshal(tmp []byte) error {
        m.EnableDisable = tmp[pos] != 0
        pos += 1
        // field[1] m.SwIfIndex
-       m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+       m.SwIfIndex = interface_types.InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
        pos += 4
        return nil
 }
@@ -679,6 +681,9 @@ var _ = bytes.NewBuffer
 var _ = context.Background
 var _ = io.Copy
 var _ = strconv.Itoa
+var _ = strings.Contains
 var _ = struc.Pack
 var _ = binary.BigEndian
 var _ = math.Float32bits
+var _ = net.ParseIP
+var _ = fmt.Errorf
diff --git a/examples/binapi/memclnt/memclnt_rpc.ba.go b/examples/binapi/memclnt/memclnt_rpc.ba.go
deleted file mode 100644 (file)
index 05dfc28..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
-
-package memclnt
-
-import (
-       "context"
-       "io"
-
-       api "git.fd.io/govpp.git/api"
-)
-
-// RPCService represents RPC service API for memclnt module.
-type RPCService interface {
-       APIVersions(ctx context.Context, in *APIVersions) (*APIVersionsReply, error)
-       GetFirstMsgID(ctx context.Context, in *GetFirstMsgID) (*GetFirstMsgIDReply, error)
-       MemclntCreate(ctx context.Context, in *MemclntCreate) (*MemclntCreateReply, error)
-       MemclntDelete(ctx context.Context, in *MemclntDelete) (*MemclntDeleteReply, error)
-       MemclntKeepalive(ctx context.Context, in *MemclntKeepalive) (*MemclntKeepaliveReply, error)
-       MemclntReadTimeout(ctx context.Context, in *MemclntReadTimeout) error
-       MemclntRxThreadSuspend(ctx context.Context, in *MemclntRxThreadSuspend) error
-       RPCCall(ctx context.Context, in *RPCCall) (*RPCCallReply, error)
-       RxThreadExit(ctx context.Context, in *RxThreadExit) error
-       SockInitShm(ctx context.Context, in *SockInitShm) (*SockInitShmReply, error)
-       SockclntCreate(ctx context.Context, in *SockclntCreate) (*SockclntCreateReply, error)
-       SockclntDelete(ctx context.Context, in *SockclntDelete) (*SockclntDeleteReply, error)
-       TracePluginMsgIds(ctx context.Context, in *TracePluginMsgIds) error
-}
-
-type serviceClient struct {
-       ch api.Channel
-}
-
-func NewServiceClient(ch api.Channel) RPCService {
-       return &serviceClient{ch}
-}
-
-func (c *serviceClient) APIVersions(ctx context.Context, in *APIVersions) (*APIVersionsReply, error) {
-       out := new(APIVersionsReply)
-       err := c.ch.SendRequest(in).ReceiveReply(out)
-       if err != nil {
-               return nil, err
-       }
-       return out, nil
-}
-
-func (c *serviceClient) GetFirstMsgID(ctx context.Context, in *GetFirstMsgID) (*GetFirstMsgIDReply, error) {
-       out := new(GetFirstMsgIDReply)
-       err := c.ch.SendRequest(in).ReceiveReply(out)
-       if err != nil {
-               return nil, err
-       }
-       return out, nil
-}
-
-func (c *serviceClient) MemclntCreate(ctx context.Context, in *MemclntCreate) (*MemclntCreateReply, error) {
-       out := new(MemclntCreateReply)
-       err := c.ch.SendRequest(in).ReceiveReply(out)
-       if err != nil {
-               return nil, err
-       }
-       return out, nil
-}
-
-func (c *serviceClient) MemclntDelete(ctx context.Context, in *MemclntDelete) (*MemclntDeleteReply, error) {
-       out := new(MemclntDeleteReply)
-       err := c.ch.SendRequest(in).ReceiveReply(out)
-       if err != nil {
-               return nil, err
-       }
-       return out, nil
-}
-
-func (c *serviceClient) MemclntKeepalive(ctx context.Context, in *MemclntKeepalive) (*MemclntKeepaliveReply, error) {
-       out := new(MemclntKeepaliveReply)
-       err := c.ch.SendRequest(in).ReceiveReply(out)
-       if err != nil {
-               return nil, err
-       }
-       return out, nil
-}
-
-func (c *serviceClient) MemclntReadTimeout(ctx context.Context, in *MemclntReadTimeout) error {
-       c.ch.SendRequest(in)
-       return nil
-}
-
-func (c *serviceClient) MemclntRxThreadSuspend(ctx context.Context, in *MemclntRxThreadSuspend) error {
-       c.ch.SendRequest(in)
-       return nil
-}
-
-func (c *serviceClient) RPCCall(ctx context.Context, in *RPCCall) (*RPCCallReply, error) {
-       out := new(RPCCallReply)
-       err := c.ch.SendRequest(in).ReceiveReply(out)
-       if err != nil {
-               return nil, err
-       }
-       return out, nil
-}
-
-func (c *serviceClient) RxThreadExit(ctx context.Context, in *RxThreadExit) error {
-       c.ch.SendRequest(in)
-       return nil
-}
-
-func (c *serviceClient) SockInitShm(ctx context.Context, in *SockInitShm) (*SockInitShmReply, error) {
-       out := new(SockInitShmReply)
-       err := c.ch.SendRequest(in).ReceiveReply(out)
-       if err != nil {
-               return nil, err
-       }
-       return out, nil
-}
-
-func (c *serviceClient) SockclntCreate(ctx context.Context, in *SockclntCreate) (*SockclntCreateReply, error) {
-       out := new(SockclntCreateReply)
-       err := c.ch.SendRequest(in).ReceiveReply(out)
-       if err != nil {
-               return nil, err
-       }
-       return out, nil
-}
-
-func (c *serviceClient) SockclntDelete(ctx context.Context, in *SockclntDelete) (*SockclntDeleteReply, error) {
-       out := new(SockclntDeleteReply)
-       err := c.ch.SendRequest(in).ReceiveReply(out)
-       if err != nil {
-               return nil, err
-       }
-       return out, nil
-}
-
-func (c *serviceClient) TracePluginMsgIds(ctx context.Context, in *TracePluginMsgIds) error {
-       c.ch.SendRequest(in)
-       return nil
-}
-
-// Reference imports to suppress errors if they are not otherwise used.
-var _ = api.RegisterMessage
-var _ = context.Background
-var _ = io.Copy