aboutsummaryrefslogtreecommitdiffstats
path: root/adapter/mock/mock_adapter.go
diff options
context:
space:
mode:
Diffstat (limited to 'adapter/mock/mock_adapter.go')
-rw-r--r--adapter/mock/mock_adapter.go33
1 files changed, 10 insertions, 23 deletions
diff --git a/adapter/mock/mock_adapter.go b/adapter/mock/mock_adapter.go
index 5407696..8768725 100644
--- a/adapter/mock/mock_adapter.go
+++ b/adapter/mock/mock_adapter.go
@@ -22,6 +22,7 @@ import (
"reflect"
"sync"
+ "git.fd.io/govpp.git/core"
"github.com/lunixbochs/struc"
"git.fd.io/govpp.git/adapter"
@@ -40,24 +41,6 @@ type VppAdapter struct {
access sync.RWMutex
}
-// replyHeader represents a common header of each VPP request message.
-type requestHeader struct {
- VlMsgID uint16
- ClientIndex uint32
- Context uint32
-}
-
-// replyHeader represents a common header of each VPP reply message.
-type replyHeader struct {
- VlMsgID uint16
- Context uint32
-}
-
-// otherHeader represents a common header of each VPP reply message.
-type otherHeader struct {
- VlMsgID uint16
-}
-
// defaultReply is a default reply message that mock adapter returns for a request.
type defaultReply struct {
Retval int32
@@ -175,7 +158,7 @@ func (a *VppAdapter) ReplyBytes(request MessageDTO, reply api.Message) ([]byte,
log.Println("ReplyBytes ", replyMsgID, " ", reply.GetMessageName(), " clientId: ", request.ClientID)
buf := new(bytes.Buffer)
- struc.Pack(buf, &replyHeader{VlMsgID: replyMsgID, Context: request.ClientID})
+ struc.Pack(buf, &core.VppReplyHeader{VlMsgID: replyMsgID, Context: request.ClientID})
struc.Pack(buf, reply)
return buf.Bytes(), nil
@@ -235,7 +218,7 @@ func (a *VppAdapter) SendMsg(clientID uint32, data []byte) error {
replyHandler := replyHandlers[i]
buf := bytes.NewReader(data)
- reqHeader := requestHeader{}
+ reqHeader := core.VppRequestHeader{}
struc.Unpack(buf, &reqHeader)
a.access.Lock()
@@ -265,9 +248,13 @@ func (a *VppAdapter) SendMsg(clientID uint32, data []byte) error {
msgID, _ := a.GetMsgID(reply.GetMessageName(), reply.GetCrcString())
buf := new(bytes.Buffer)
if reply.GetMessageType() == api.ReplyMessage {
- struc.Pack(buf, &replyHeader{VlMsgID: msgID, Context: clientID})
+ struc.Pack(buf, &core.VppReplyHeader{VlMsgID: msgID, Context: clientID})
+ } else if reply.GetMessageType() == api.EventMessage {
+ struc.Pack(buf, &core.VppEventHeader{VlMsgID: msgID, Context: clientID})
+ } else if reply.GetMessageType() == api.RequestMessage {
+ struc.Pack(buf, &core.VppRequestHeader{VlMsgID: msgID, Context: clientID})
} else {
- struc.Pack(buf, &requestHeader{VlMsgID: msgID, Context: clientID})
+ struc.Pack(buf, &core.VppOtherHeader{VlMsgID: msgID})
}
struc.Pack(buf, reply)
a.callback(clientID, msgID, buf.Bytes())
@@ -282,7 +269,7 @@ func (a *VppAdapter) SendMsg(clientID uint32, data []byte) error {
// return default reply
buf := new(bytes.Buffer)
msgID := uint16(defaultReplyMsgID)
- struc.Pack(buf, &replyHeader{VlMsgID: msgID, Context: clientID})
+ struc.Pack(buf, &core.VppReplyHeader{VlMsgID: msgID, Context: clientID})
struc.Pack(buf, &defaultReply{})
a.callback(clientID, msgID, buf.Bytes())
}