diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2017-12-04 09:54:13 +0100 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2017-12-04 09:54:13 +0100 |
commit | de8e6592e23a3819266cea5e9999c7c21fdd826f (patch) | |
tree | b0b3eaf9cc92e36ef1944cb1a4eb09df8ec3cf6b /adapter | |
parent | acf57209ccbd67fa96644abe5aef65f58264c112 (diff) |
Fix events for mock adapter
Change-Id: Iee5fa6282e845ed2aef76c9246a9068f3765139c
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'adapter')
-rw-r--r-- | adapter/mock/mock_adapter.go | 33 |
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()) } |