summaryrefslogtreecommitdiffstats
path: root/binapi/gre
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2020-07-17 10:36:28 +0200
committerOndrej Fabry <ofabry@cisco.com>2020-07-17 11:43:41 +0200
commitd1f24d37bd447b64e402298bb8eb2479681facf9 (patch)
treea3fc21ba730a91d8a402c7a5bf9c614e3677c4fc /binapi/gre
parent1548c7e12531e3d055567d761c580a1c7ff0ac40 (diff)
Improve binapi generator
- simplified Size/Marshal/Unmarshal methods - replace struc in unions with custom marshal/unmarshal - fix imports in generated files - fix mock adapter - generate rpc service using low-level stream API (dumps generate control ping or stream msg..) - move examples/binapi to binapi and generate all API for latest release - add binapigen.Plugin for developing custom generator plugins - optionally generate HTTP handlers (REST API) for RPC services - add govpp program for browsing VPP API Change-Id: I092e9ed2b0c17972b3476463c3d4b14dd76ed42b Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'binapi/gre')
-rw-r--r--binapi/gre/gre.ba.go308
-rw-r--r--binapi/gre/gre_rest.ba.go37
-rw-r--r--binapi/gre/gre_rpc.ba.go73
3 files changed, 418 insertions, 0 deletions
diff --git a/binapi/gre/gre.ba.go b/binapi/gre/gre.ba.go
new file mode 100644
index 0000000..e87e88f
--- /dev/null
+++ b/binapi/gre/gre.ba.go
@@ -0,0 +1,308 @@
+// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+// versions:
+// binapi-generator: v0.4.0-dev
+// VPP: 20.05-release
+// source: /usr/share/vpp/api/core/gre.api.json
+
+// Package gre contains generated bindings for API file gre.api.
+//
+// Contents:
+// 1 enum
+// 1 struct
+// 4 messages
+//
+package gre
+
+import (
+ api "git.fd.io/govpp.git/api"
+ interface_types "git.fd.io/govpp.git/binapi/interface_types"
+ ip_types "git.fd.io/govpp.git/binapi/ip_types"
+ tunnel_types "git.fd.io/govpp.git/binapi/tunnel_types"
+ codec "git.fd.io/govpp.git/codec"
+ "strconv"
+)
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the GoVPP api package it is being compiled against.
+// A compilation error at this line likely means your copy of the
+// GoVPP api package needs to be updated.
+const _ = api.GoVppAPIPackageIsVersion2
+
+const (
+ APIFile = "gre"
+ APIVersion = "2.1.0"
+ VersionCrc = 0xb9021569
+)
+
+// GreTunnelType defines enum 'gre_tunnel_type'.
+type GreTunnelType uint8
+
+const (
+ GRE_API_TUNNEL_TYPE_L3 GreTunnelType = 0
+ GRE_API_TUNNEL_TYPE_TEB GreTunnelType = 1
+ GRE_API_TUNNEL_TYPE_ERSPAN GreTunnelType = 2
+)
+
+var (
+ GreTunnelType_name = map[uint8]string{
+ 0: "GRE_API_TUNNEL_TYPE_L3",
+ 1: "GRE_API_TUNNEL_TYPE_TEB",
+ 2: "GRE_API_TUNNEL_TYPE_ERSPAN",
+ }
+ GreTunnelType_value = map[string]uint8{
+ "GRE_API_TUNNEL_TYPE_L3": 0,
+ "GRE_API_TUNNEL_TYPE_TEB": 1,
+ "GRE_API_TUNNEL_TYPE_ERSPAN": 2,
+ }
+)
+
+func (x GreTunnelType) String() string {
+ s, ok := GreTunnelType_name[uint8(x)]
+ if ok {
+ return s
+ }
+ return "GreTunnelType(" + strconv.Itoa(int(x)) + ")"
+}
+
+// GreTunnel defines type 'gre_tunnel'.
+type GreTunnel struct {
+ Type GreTunnelType `binapi:"gre_tunnel_type,name=type" json:"type,omitempty"`
+ Mode tunnel_types.TunnelMode `binapi:"tunnel_mode,name=mode" json:"mode,omitempty"`
+ Flags tunnel_types.TunnelEncapDecapFlags `binapi:"tunnel_encap_decap_flags,name=flags" json:"flags,omitempty"`
+ SessionID uint16 `binapi:"u16,name=session_id" json:"session_id,omitempty"`
+ Instance uint32 `binapi:"u32,name=instance" json:"instance,omitempty"`
+ OuterTableID uint32 `binapi:"u32,name=outer_table_id" json:"outer_table_id,omitempty"`
+ SwIfIndex interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Src ip_types.Address `binapi:"address,name=src" json:"src,omitempty"`
+ Dst ip_types.Address `binapi:"address,name=dst" json:"dst,omitempty"`
+}
+
+// GreTunnelAddDel defines message 'gre_tunnel_add_del'.
+type GreTunnelAddDel struct {
+ IsAdd bool `binapi:"bool,name=is_add" json:"is_add,omitempty"`
+ Tunnel GreTunnel `binapi:"gre_tunnel,name=tunnel" json:"tunnel,omitempty"`
+}
+
+func (m *GreTunnelAddDel) Reset() { *m = GreTunnelAddDel{} }
+func (*GreTunnelAddDel) GetMessageName() string { return "gre_tunnel_add_del" }
+func (*GreTunnelAddDel) GetCrcString() string { return "6efc9c22" }
+func (*GreTunnelAddDel) GetMessageType() api.MessageType {
+ return api.RequestMessage
+}
+
+func (m *GreTunnelAddDel) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ size += 1 // m.IsAdd
+ size += 1 // m.Tunnel.Type
+ size += 1 // m.Tunnel.Mode
+ size += 1 // m.Tunnel.Flags
+ size += 2 // m.Tunnel.SessionID
+ size += 4 // m.Tunnel.Instance
+ size += 4 // m.Tunnel.OuterTableID
+ size += 4 // m.Tunnel.SwIfIndex
+ size += 1 // m.Tunnel.Src.Af
+ size += 1 * 16 // m.Tunnel.Src.Un
+ size += 1 // m.Tunnel.Dst.Af
+ size += 1 * 16 // m.Tunnel.Dst.Un
+ return size
+}
+func (m *GreTunnelAddDel) Marshal(b []byte) ([]byte, error) {
+ var buf *codec.Buffer
+ if b == nil {
+ buf = codec.NewBuffer(make([]byte, m.Size()))
+ } else {
+ buf = codec.NewBuffer(b)
+ }
+ buf.EncodeBool(m.IsAdd)
+ buf.EncodeUint8(uint8(m.Tunnel.Type))
+ buf.EncodeUint8(uint8(m.Tunnel.Mode))
+ buf.EncodeUint8(uint8(m.Tunnel.Flags))
+ buf.EncodeUint16(uint16(m.Tunnel.SessionID))
+ buf.EncodeUint32(uint32(m.Tunnel.Instance))
+ buf.EncodeUint32(uint32(m.Tunnel.OuterTableID))
+ buf.EncodeUint32(uint32(m.Tunnel.SwIfIndex))
+ buf.EncodeUint8(uint8(m.Tunnel.Src.Af))
+ buf.EncodeBytes(m.Tunnel.Src.Un.XXX_UnionData[:], 0)
+ buf.EncodeUint8(uint8(m.Tunnel.Dst.Af))
+ buf.EncodeBytes(m.Tunnel.Dst.Un.XXX_UnionData[:], 0)
+ return buf.Bytes(), nil
+}
+func (m *GreTunnelAddDel) Unmarshal(b []byte) error {
+ buf := codec.NewBuffer(b)
+ m.IsAdd = buf.DecodeBool()
+ m.Tunnel.Type = GreTunnelType(buf.DecodeUint8())
+ m.Tunnel.Mode = tunnel_types.TunnelMode(buf.DecodeUint8())
+ m.Tunnel.Flags = tunnel_types.TunnelEncapDecapFlags(buf.DecodeUint8())
+ m.Tunnel.SessionID = buf.DecodeUint16()
+ m.Tunnel.Instance = buf.DecodeUint32()
+ m.Tunnel.OuterTableID = buf.DecodeUint32()
+ m.Tunnel.SwIfIndex = interface_types.InterfaceIndex(buf.DecodeUint32())
+ m.Tunnel.Src.Af = ip_types.AddressFamily(buf.DecodeUint8())
+ copy(m.Tunnel.Src.Un.XXX_UnionData[:], buf.DecodeBytes(16))
+ m.Tunnel.Dst.Af = ip_types.AddressFamily(buf.DecodeUint8())
+ copy(m.Tunnel.Dst.Un.XXX_UnionData[:], buf.DecodeBytes(16))
+ return nil
+}
+
+// GreTunnelAddDelReply defines message 'gre_tunnel_add_del_reply'.
+type GreTunnelAddDelReply struct {
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
+ SwIfIndex interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+}
+
+func (m *GreTunnelAddDelReply) Reset() { *m = GreTunnelAddDelReply{} }
+func (*GreTunnelAddDelReply) GetMessageName() string { return "gre_tunnel_add_del_reply" }
+func (*GreTunnelAddDelReply) GetCrcString() string { return "5383d31f" }
+func (*GreTunnelAddDelReply) GetMessageType() api.MessageType {
+ return api.ReplyMessage
+}
+
+func (m *GreTunnelAddDelReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ size += 4 // m.Retval
+ size += 4 // m.SwIfIndex
+ return size
+}
+func (m *GreTunnelAddDelReply) Marshal(b []byte) ([]byte, error) {
+ var buf *codec.Buffer
+ if b == nil {
+ buf = codec.NewBuffer(make([]byte, m.Size()))
+ } else {
+ buf = codec.NewBuffer(b)
+ }
+ buf.EncodeUint32(uint32(m.Retval))
+ buf.EncodeUint32(uint32(m.SwIfIndex))
+ return buf.Bytes(), nil
+}
+func (m *GreTunnelAddDelReply) Unmarshal(b []byte) error {
+ buf := codec.NewBuffer(b)
+ m.Retval = int32(buf.DecodeUint32())
+ m.SwIfIndex = interface_types.InterfaceIndex(buf.DecodeUint32())
+ return nil
+}
+
+// GreTunnelDetails defines message 'gre_tunnel_details'.
+type GreTunnelDetails struct {
+ Tunnel GreTunnel `binapi:"gre_tunnel,name=tunnel" json:"tunnel,omitempty"`
+}
+
+func (m *GreTunnelDetails) Reset() { *m = GreTunnelDetails{} }
+func (*GreTunnelDetails) GetMessageName() string { return "gre_tunnel_details" }
+func (*GreTunnelDetails) GetCrcString() string { return "003bfbf1" }
+func (*GreTunnelDetails) GetMessageType() api.MessageType {
+ return api.ReplyMessage
+}
+
+func (m *GreTunnelDetails) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ size += 1 // m.Tunnel.Type
+ size += 1 // m.Tunnel.Mode
+ size += 1 // m.Tunnel.Flags
+ size += 2 // m.Tunnel.SessionID
+ size += 4 // m.Tunnel.Instance
+ size += 4 // m.Tunnel.OuterTableID
+ size += 4 // m.Tunnel.SwIfIndex
+ size += 1 // m.Tunnel.Src.Af
+ size += 1 * 16 // m.Tunnel.Src.Un
+ size += 1 // m.Tunnel.Dst.Af
+ size += 1 * 16 // m.Tunnel.Dst.Un
+ return size
+}
+func (m *GreTunnelDetails) Marshal(b []byte) ([]byte, error) {
+ var buf *codec.Buffer
+ if b == nil {
+ buf = codec.NewBuffer(make([]byte, m.Size()))
+ } else {
+ buf = codec.NewBuffer(b)
+ }
+ buf.EncodeUint8(uint8(m.Tunnel.Type))
+ buf.EncodeUint8(uint8(m.Tunnel.Mode))
+ buf.EncodeUint8(uint8(m.Tunnel.Flags))
+ buf.EncodeUint16(uint16(m.Tunnel.SessionID))
+ buf.EncodeUint32(uint32(m.Tunnel.Instance))
+ buf.EncodeUint32(uint32(m.Tunnel.OuterTableID))
+ buf.EncodeUint32(uint32(m.Tunnel.SwIfIndex))
+ buf.EncodeUint8(uint8(m.Tunnel.Src.Af))
+ buf.EncodeBytes(m.Tunnel.Src.Un.XXX_UnionData[:], 0)
+ buf.EncodeUint8(uint8(m.Tunnel.Dst.Af))
+ buf.EncodeBytes(m.Tunnel.Dst.Un.XXX_UnionData[:], 0)
+ return buf.Bytes(), nil
+}
+func (m *GreTunnelDetails) Unmarshal(b []byte) error {
+ buf := codec.NewBuffer(b)
+ m.Tunnel.Type = GreTunnelType(buf.DecodeUint8())
+ m.Tunnel.Mode = tunnel_types.TunnelMode(buf.DecodeUint8())
+ m.Tunnel.Flags = tunnel_types.TunnelEncapDecapFlags(buf.DecodeUint8())
+ m.Tunnel.SessionID = buf.DecodeUint16()
+ m.Tunnel.Instance = buf.DecodeUint32()
+ m.Tunnel.OuterTableID = buf.DecodeUint32()
+ m.Tunnel.SwIfIndex = interface_types.InterfaceIndex(buf.DecodeUint32())
+ m.Tunnel.Src.Af = ip_types.AddressFamily(buf.DecodeUint8())
+ copy(m.Tunnel.Src.Un.XXX_UnionData[:], buf.DecodeBytes(16))
+ m.Tunnel.Dst.Af = ip_types.AddressFamily(buf.DecodeUint8())
+ copy(m.Tunnel.Dst.Un.XXX_UnionData[:], buf.DecodeBytes(16))
+ return nil
+}
+
+// GreTunnelDump defines message 'gre_tunnel_dump'.
+type GreTunnelDump struct {
+ SwIfIndex interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+}
+
+func (m *GreTunnelDump) Reset() { *m = GreTunnelDump{} }
+func (*GreTunnelDump) GetMessageName() string { return "gre_tunnel_dump" }
+func (*GreTunnelDump) GetCrcString() string { return "f9e6675e" }
+func (*GreTunnelDump) GetMessageType() api.MessageType {
+ return api.RequestMessage
+}
+
+func (m *GreTunnelDump) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ size += 4 // m.SwIfIndex
+ return size
+}
+func (m *GreTunnelDump) Marshal(b []byte) ([]byte, error) {
+ var buf *codec.Buffer
+ if b == nil {
+ buf = codec.NewBuffer(make([]byte, m.Size()))
+ } else {
+ buf = codec.NewBuffer(b)
+ }
+ buf.EncodeUint32(uint32(m.SwIfIndex))
+ return buf.Bytes(), nil
+}
+func (m *GreTunnelDump) Unmarshal(b []byte) error {
+ buf := codec.NewBuffer(b)
+ m.SwIfIndex = interface_types.InterfaceIndex(buf.DecodeUint32())
+ return nil
+}
+
+func init() { file_gre_binapi_init() }
+func file_gre_binapi_init() {
+ api.RegisterMessage((*GreTunnelAddDel)(nil), "gre_tunnel_add_del_6efc9c22")
+ api.RegisterMessage((*GreTunnelAddDelReply)(nil), "gre_tunnel_add_del_reply_5383d31f")
+ api.RegisterMessage((*GreTunnelDetails)(nil), "gre_tunnel_details_003bfbf1")
+ api.RegisterMessage((*GreTunnelDump)(nil), "gre_tunnel_dump_f9e6675e")
+}
+
+// Messages returns list of all messages in this module.
+func AllMessages() []api.Message {
+ return []api.Message{
+ (*GreTunnelAddDel)(nil),
+ (*GreTunnelAddDelReply)(nil),
+ (*GreTunnelDetails)(nil),
+ (*GreTunnelDump)(nil),
+ }
+}
diff --git a/binapi/gre/gre_rest.ba.go b/binapi/gre/gre_rest.ba.go
new file mode 100644
index 0000000..d344aa8
--- /dev/null
+++ b/binapi/gre/gre_rest.ba.go
@@ -0,0 +1,37 @@
+// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+
+package gre
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "net/http"
+)
+
+func RESTHandler(rpc RPCService) http.Handler {
+ mux := http.NewServeMux()
+ mux.HandleFunc("/gre_tunnel_add_del", func(w http.ResponseWriter, req *http.Request) {
+ var request = new(GreTunnelAddDel)
+ b, err := ioutil.ReadAll(req.Body)
+ if err != nil {
+ http.Error(w, "read body failed", http.StatusBadRequest)
+ return
+ }
+ if err := json.Unmarshal(b, request); err != nil {
+ http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+ return
+ }
+ reply, err := rpc.GreTunnelAddDel(req.Context(), request)
+ if err != nil {
+ http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+ return
+ }
+ rep, err := json.MarshalIndent(reply, "", " ")
+ if err != nil {
+ http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+ return
+ }
+ w.Write(rep)
+ })
+ return http.HandlerFunc(mux.ServeHTTP)
+}
diff --git a/binapi/gre/gre_rpc.ba.go b/binapi/gre/gre_rpc.ba.go
new file mode 100644
index 0000000..f664fb3
--- /dev/null
+++ b/binapi/gre/gre_rpc.ba.go
@@ -0,0 +1,73 @@
+// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+
+package gre
+
+import (
+ "context"
+ "fmt"
+ api "git.fd.io/govpp.git/api"
+ vpe "git.fd.io/govpp.git/binapi/vpe"
+ "io"
+)
+
+// RPCService defines RPC service gre.
+type RPCService interface {
+ GreTunnelAddDel(ctx context.Context, in *GreTunnelAddDel) (*GreTunnelAddDelReply, error)
+ GreTunnelDump(ctx context.Context, in *GreTunnelDump) (RPCService_GreTunnelDumpClient, error)
+}
+
+type serviceClient struct {
+ conn api.Connection
+}
+
+func NewServiceClient(conn api.Connection) RPCService {
+ return &serviceClient{conn}
+}
+
+func (c *serviceClient) GreTunnelAddDel(ctx context.Context, in *GreTunnelAddDel) (*GreTunnelAddDelReply, error) {
+ out := new(GreTunnelAddDelReply)
+ err := c.conn.Invoke(ctx, in, out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) GreTunnelDump(ctx context.Context, in *GreTunnelDump) (RPCService_GreTunnelDumpClient, error) {
+ stream, err := c.conn.NewStream(ctx)
+ if err != nil {
+ return nil, err
+ }
+ x := &serviceClient_GreTunnelDumpClient{stream}
+ if err := x.Stream.SendMsg(in); err != nil {
+ return nil, err
+ }
+ if err = x.Stream.SendMsg(&vpe.ControlPing{}); err != nil {
+ return nil, err
+ }
+ return x, nil
+}
+
+type RPCService_GreTunnelDumpClient interface {
+ Recv() (*GreTunnelDetails, error)
+ api.Stream
+}
+
+type serviceClient_GreTunnelDumpClient struct {
+ api.Stream
+}
+
+func (c *serviceClient_GreTunnelDumpClient) Recv() (*GreTunnelDetails, error) {
+ msg, err := c.Stream.RecvMsg()
+ if err != nil {
+ return nil, err
+ }
+ switch m := msg.(type) {
+ case *GreTunnelDetails:
+ return m, nil
+ case *vpe.ControlPingReply:
+ return nil, io.EOF
+ default:
+ return nil, fmt.Errorf("unexpected message: %T %v", m, m)
+ }
+}