summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRastislav Szabo <raszabo@cisco.com>2017-09-25 21:58:24 +0200
committerRastislav Szabo <raszabo@cisco.com>2017-09-25 21:58:24 +0200
commit8b66677c2382a8e739d437621de4473d5ec0b9f1 (patch)
treeac0999f92d20b2f1bc630ebcb6ffa2b5317c0baa
parent70ae7c10259161994e49bae8d095dcce840dfed4 (diff)
generator fix - add new message type
Change-Id: I5e2b312e086d18eb7fa3f349750caea20005f530 Signed-off-by: Rastislav Szabo <raszabo@cisco.com>
-rw-r--r--api/api.go2
-rw-r--r--cmd/binapi-generator/generator.go5
-rw-r--r--core/bin_api/vpe/vpe.go3
-rw-r--r--core/msg_codec.go13
4 files changed, 22 insertions, 1 deletions
diff --git a/api/api.go b/api/api.go
index afaa8ad..c247417 100644
--- a/api/api.go
+++ b/api/api.go
@@ -28,6 +28,8 @@ const (
RequestMessage MessageType = iota
// ReplyMessage represents a VPP reply message
ReplyMessage
+ // EventMessage represents a VPP notification event message
+ EventMessage
// OtherMessage represents other VPP message (e.g. counters)
OtherMessage
)
diff --git a/cmd/binapi-generator/generator.go b/cmd/binapi-generator/generator.go
index e3efe0f..d8420f9 100644
--- a/cmd/binapi-generator/generator.go
+++ b/cmd/binapi-generator/generator.go
@@ -38,6 +38,7 @@ type messageType int
const (
requestMessage messageType = iota // VPP request message
replyMessage // VPP reply message
+ eventMessage // VPP event message
otherMessage // other VPP message
)
@@ -260,6 +261,8 @@ func generateMessage(ctx *context, w io.Writer, msg *jsongo.JSONNode, isType boo
if ok {
if j == 2 {
if fieldName == "client_index" {
+ // "client_index" as the second member, this might be an event message or a request
+ msgType = eventMessage
wasClientIndex = true
} else if fieldName == "context" {
// reply needs "context" as the second member
@@ -465,6 +468,8 @@ func generateMessageTypeGetter(w io.Writer, structName string, msgType messageTy
fmt.Fprintln(w, "\treturn api.RequestMessage")
} else if msgType == replyMessage {
fmt.Fprintln(w, "\treturn api.ReplyMessage")
+ } else if msgType == eventMessage {
+ fmt.Fprintln(w, "\treturn api.EventMessage")
} else {
fmt.Fprintln(w, "\treturn api.OtherMessage")
}
diff --git a/core/bin_api/vpe/vpe.go b/core/bin_api/vpe/vpe.go
index 51a245b..c11f466 100644
--- a/core/bin_api/vpe/vpe.go
+++ b/core/bin_api/vpe/vpe.go
@@ -1,5 +1,6 @@
+// Code generated by govpp binapi-generator DO NOT EDIT.
// Package vpe represents the VPP binary API of the 'vpe' VPP module.
-// DO NOT EDIT. Generated from 'bin_api/vpe.api.json'
+// Generated from 'bin_api/vpe.api.json'
package vpe
import "git.fd.io/govpp.git/api"
diff --git a/core/msg_codec.go b/core/msg_codec.go
index 5614a7e..c72b7f3 100644
--- a/core/msg_codec.go
+++ b/core/msg_codec.go
@@ -43,6 +43,12 @@ type vppReplyHeader struct {
Context uint32
}
+// vppEventHeader struct contains header fields implemented by all VPP events.
+type vppEventHeader struct {
+ VlMsgID uint16
+ Context uint32
+}
+
// vppOtherHeader struct contains header fields implemented by other VPP messages (not requests nor replies).
type vppOtherHeader struct {
VlMsgID uint16
@@ -51,6 +57,7 @@ type vppOtherHeader struct {
const (
vppRequestHeaderSize = 10 // size of a VPP request header
vppReplyHeaderSize = 6 // size of a VPP reply header
+ vppEventHeaderSize = 6 // size of a VPP event header
vppOtherHeaderSize = 2 // size of the header of other VPP messages
)
@@ -68,6 +75,8 @@ func (*MsgCodec) EncodeMsg(msg api.Message, msgID uint16) ([]byte, error) {
header = &vppRequestHeader{VlMsgID: msgID}
} else if msg.GetMessageType() == api.ReplyMessage {
header = &vppReplyHeader{VlMsgID: msgID}
+ } else if msg.GetMessageType() == api.EventMessage {
+ header = &vppEventHeader{VlMsgID: msgID}
} else {
header = &vppOtherHeader{VlMsgID: msgID}
}
@@ -109,6 +118,8 @@ func (*MsgCodec) DecodeMsg(data []byte, msg api.Message) error {
header = &vppRequestHeader{}
} else if msg.GetMessageType() == api.ReplyMessage {
header = &vppReplyHeader{}
+ } else if msg.GetMessageType() == api.EventMessage {
+ header = &vppEventHeader{}
} else {
header = &vppOtherHeader{}
}
@@ -128,6 +139,8 @@ func (*MsgCodec) DecodeMsg(data []byte, msg api.Message) error {
buf = bytes.NewReader(data[vppRequestHeaderSize:])
} else if msg.GetMessageType() == api.ReplyMessage {
buf = bytes.NewReader(data[vppReplyHeaderSize:])
+ } else if msg.GetMessageType() == api.EventMessage {
+ buf = bytes.NewReader(data[vppEventHeaderSize:])
} else {
buf = bytes.NewReader(data[vppOtherHeaderSize:])
}