diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2020-07-17 10:36:28 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2020-07-17 11:43:41 +0200 |
commit | d1f24d37bd447b64e402298bb8eb2479681facf9 (patch) | |
tree | a3fc21ba730a91d8a402c7a5bf9c614e3677c4fc /binapi/l3xc | |
parent | 1548c7e12531e3d055567d761c580a1c7ff0ac40 (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/l3xc')
-rw-r--r-- | binapi/l3xc/l3xc.ba.go | 537 | ||||
-rw-r--r-- | binapi/l3xc/l3xc_rest.ba.go | 74 | ||||
-rw-r--r-- | binapi/l3xc/l3xc_rpc.ba.go | 93 |
3 files changed, 704 insertions, 0 deletions
diff --git a/binapi/l3xc/l3xc.ba.go b/binapi/l3xc/l3xc.ba.go new file mode 100644 index 0000000..ee9ecb0 --- /dev/null +++ b/binapi/l3xc/l3xc.ba.go @@ -0,0 +1,537 @@ +// 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/plugins/l3xc.api.json + +// Package l3xc contains generated bindings for API file l3xc.api. +// +// Contents: +// 1 struct +// 8 messages +// +package l3xc + +import ( + api "git.fd.io/govpp.git/api" + fib_types "git.fd.io/govpp.git/binapi/fib_types" + interface_types "git.fd.io/govpp.git/binapi/interface_types" + _ "git.fd.io/govpp.git/binapi/ip_types" + codec "git.fd.io/govpp.git/codec" +) + +// 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 = "l3xc" + APIVersion = "1.0.1" + VersionCrc = 0xaf18effb +) + +// L3xc defines type 'l3xc'. +type L3xc struct { + SwIfIndex interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"` + IsIP6 bool `binapi:"bool,name=is_ip6" json:"is_ip6,omitempty"` + NPaths uint8 `binapi:"u8,name=n_paths" json:"-"` + Paths []fib_types.FibPath `binapi:"fib_path[n_paths],name=paths" json:"paths,omitempty"` +} + +// L3xcDel defines message 'l3xc_del'. +type L3xcDel struct { + SwIfIndex interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"` + IsIP6 bool `binapi:"bool,name=is_ip6" json:"is_ip6,omitempty"` +} + +func (m *L3xcDel) Reset() { *m = L3xcDel{} } +func (*L3xcDel) GetMessageName() string { return "l3xc_del" } +func (*L3xcDel) GetCrcString() string { return "e7dbef91" } +func (*L3xcDel) GetMessageType() api.MessageType { + return api.RequestMessage +} + +func (m *L3xcDel) Size() int { + if m == nil { + return 0 + } + var size int + size += 4 // m.SwIfIndex + size += 1 // m.IsIP6 + return size +} +func (m *L3xcDel) 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)) + buf.EncodeBool(m.IsIP6) + return buf.Bytes(), nil +} +func (m *L3xcDel) Unmarshal(b []byte) error { + buf := codec.NewBuffer(b) + m.SwIfIndex = interface_types.InterfaceIndex(buf.DecodeUint32()) + m.IsIP6 = buf.DecodeBool() + return nil +} + +// L3xcDelReply defines message 'l3xc_del_reply'. +type L3xcDelReply struct { + Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"` +} + +func (m *L3xcDelReply) Reset() { *m = L3xcDelReply{} } +func (*L3xcDelReply) GetMessageName() string { return "l3xc_del_reply" } +func (*L3xcDelReply) GetCrcString() string { return "e8d4e804" } +func (*L3xcDelReply) GetMessageType() api.MessageType { + return api.ReplyMessage +} + +func (m *L3xcDelReply) Size() int { + if m == nil { + return 0 + } + var size int + size += 4 // m.Retval + return size +} +func (m *L3xcDelReply) 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)) + return buf.Bytes(), nil +} +func (m *L3xcDelReply) Unmarshal(b []byte) error { + buf := codec.NewBuffer(b) + m.Retval = int32(buf.DecodeUint32()) + return nil +} + +// L3xcDetails defines message 'l3xc_details'. +type L3xcDetails struct { + L3xc L3xc `binapi:"l3xc,name=l3xc" json:"l3xc,omitempty"` +} + +func (m *L3xcDetails) Reset() { *m = L3xcDetails{} } +func (*L3xcDetails) GetMessageName() string { return "l3xc_details" } +func (*L3xcDetails) GetCrcString() string { return "d4f69627" } +func (*L3xcDetails) GetMessageType() api.MessageType { + return api.ReplyMessage +} + +func (m *L3xcDetails) Size() int { + if m == nil { + return 0 + } + var size int + size += 4 // m.L3xc.SwIfIndex + size += 1 // m.L3xc.IsIP6 + size += 1 // m.L3xc.NPaths + for j2 := 0; j2 < len(m.L3xc.Paths); j2++ { + var s2 fib_types.FibPath + _ = s2 + if j2 < len(m.L3xc.Paths) { + s2 = m.L3xc.Paths[j2] + } + size += 4 // s2.SwIfIndex + size += 4 // s2.TableID + size += 4 // s2.RpfID + size += 1 // s2.Weight + size += 1 // s2.Preference + size += 4 // s2.Type + size += 4 // s2.Flags + size += 4 // s2.Proto + size += 1 * 16 // s2.Nh.Address + size += 4 // s2.Nh.ViaLabel + size += 4 // s2.Nh.ObjID + size += 4 // s2.Nh.ClassifyTableIndex + size += 1 // s2.NLabels + for j3 := 0; j3 < 16; j3++ { + var s3 fib_types.FibMplsLabel + _ = s3 + if j3 < len(s2.LabelStack) { + s3 = s2.LabelStack[j3] + } + size += 1 // s3.IsUniform + size += 4 // s3.Label + size += 1 // s3.TTL + size += 1 // s3.Exp + } + } + return size +} +func (m *L3xcDetails) 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.L3xc.SwIfIndex)) + buf.EncodeBool(m.L3xc.IsIP6) + buf.EncodeUint8(uint8(len(m.L3xc.Paths))) + for j1 := 0; j1 < len(m.L3xc.Paths); j1++ { + var v1 fib_types.FibPath + if j1 < len(m.L3xc.Paths) { + v1 = m.L3xc.Paths[j1] + } + buf.EncodeUint32(uint32(v1.SwIfIndex)) + buf.EncodeUint32(uint32(v1.TableID)) + buf.EncodeUint32(uint32(v1.RpfID)) + buf.EncodeUint8(uint8(v1.Weight)) + buf.EncodeUint8(uint8(v1.Preference)) + buf.EncodeUint32(uint32(v1.Type)) + buf.EncodeUint32(uint32(v1.Flags)) + buf.EncodeUint32(uint32(v1.Proto)) + buf.EncodeBytes(v1.Nh.Address.XXX_UnionData[:], 0) + buf.EncodeUint32(uint32(v1.Nh.ViaLabel)) + buf.EncodeUint32(uint32(v1.Nh.ObjID)) + buf.EncodeUint32(uint32(v1.Nh.ClassifyTableIndex)) + buf.EncodeUint8(uint8(v1.NLabels)) + for j2 := 0; j2 < 16; j2++ { + var v2 fib_types.FibMplsLabel + if j2 < len(v1.LabelStack) { + v2 = v1.LabelStack[j2] + } + buf.EncodeUint8(uint8(v2.IsUniform)) + buf.EncodeUint32(uint32(v2.Label)) + buf.EncodeUint8(uint8(v2.TTL)) + buf.EncodeUint8(uint8(v2.Exp)) + } + } + return buf.Bytes(), nil +} +func (m *L3xcDetails) Unmarshal(b []byte) error { + buf := codec.NewBuffer(b) + m.L3xc.SwIfIndex = interface_types.InterfaceIndex(buf.DecodeUint32()) + m.L3xc.IsIP6 = buf.DecodeBool() + m.L3xc.NPaths = buf.DecodeUint8() + m.L3xc.Paths = make([]fib_types.FibPath, int(m.L3xc.NPaths)) + for j1 := 0; j1 < len(m.L3xc.Paths); j1++ { + m.L3xc.Paths[j1].SwIfIndex = buf.DecodeUint32() + m.L3xc.Paths[j1].TableID = buf.DecodeUint32() + m.L3xc.Paths[j1].RpfID = buf.DecodeUint32() + m.L3xc.Paths[j1].Weight = buf.DecodeUint8() + m.L3xc.Paths[j1].Preference = buf.DecodeUint8() + m.L3xc.Paths[j1].Type = fib_types.FibPathType(buf.DecodeUint32()) + m.L3xc.Paths[j1].Flags = fib_types.FibPathFlags(buf.DecodeUint32()) + m.L3xc.Paths[j1].Proto = fib_types.FibPathNhProto(buf.DecodeUint32()) + copy(m.L3xc.Paths[j1].Nh.Address.XXX_UnionData[:], buf.DecodeBytes(16)) + m.L3xc.Paths[j1].Nh.ViaLabel = buf.DecodeUint32() + m.L3xc.Paths[j1].Nh.ObjID = buf.DecodeUint32() + m.L3xc.Paths[j1].Nh.ClassifyTableIndex = buf.DecodeUint32() + m.L3xc.Paths[j1].NLabels = buf.DecodeUint8() + for j2 := 0; j2 < 16; j2++ { + m.L3xc.Paths[j1].LabelStack[j2].IsUniform = buf.DecodeUint8() + m.L3xc.Paths[j1].LabelStack[j2].Label = buf.DecodeUint32() + m.L3xc.Paths[j1].LabelStack[j2].TTL = buf.DecodeUint8() + m.L3xc.Paths[j1].LabelStack[j2].Exp = buf.DecodeUint8() + } + } + return nil +} + +// L3xcDump defines message 'l3xc_dump'. +type L3xcDump struct { + SwIfIndex interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"` +} + +func (m *L3xcDump) Reset() { *m = L3xcDump{} } +func (*L3xcDump) GetMessageName() string { return "l3xc_dump" } +func (*L3xcDump) GetCrcString() string { return "f9e6675e" } +func (*L3xcDump) GetMessageType() api.MessageType { + return api.RequestMessage +} + +func (m *L3xcDump) Size() int { + if m == nil { + return 0 + } + var size int + size += 4 // m.SwIfIndex + return size +} +func (m *L3xcDump) 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 *L3xcDump) Unmarshal(b []byte) error { + buf := codec.NewBuffer(b) + m.SwIfIndex = interface_types.InterfaceIndex(buf.DecodeUint32()) + return nil +} + +// L3xcPluginGetVersion defines message 'l3xc_plugin_get_version'. +type L3xcPluginGetVersion struct{} + +func (m *L3xcPluginGetVersion) Reset() { *m = L3xcPluginGetVersion{} } +func (*L3xcPluginGetVersion) GetMessageName() string { return "l3xc_plugin_get_version" } +func (*L3xcPluginGetVersion) GetCrcString() string { return "51077d14" } +func (*L3xcPluginGetVersion) GetMessageType() api.MessageType { + return api.RequestMessage +} + +func (m *L3xcPluginGetVersion) Size() int { + if m == nil { + return 0 + } + var size int + return size +} +func (m *L3xcPluginGetVersion) Marshal(b []byte) ([]byte, error) { + var buf *codec.Buffer + if b == nil { + buf = codec.NewBuffer(make([]byte, m.Size())) + } else { + buf = codec.NewBuffer(b) + } + return buf.Bytes(), nil +} +func (m *L3xcPluginGetVersion) Unmarshal(b []byte) error { + return nil +} + +// L3xcPluginGetVersionReply defines message 'l3xc_plugin_get_version_reply'. +type L3xcPluginGetVersionReply struct { + Major uint32 `binapi:"u32,name=major" json:"major,omitempty"` + Minor uint32 `binapi:"u32,name=minor" json:"minor,omitempty"` +} + +func (m *L3xcPluginGetVersionReply) Reset() { *m = L3xcPluginGetVersionReply{} } +func (*L3xcPluginGetVersionReply) GetMessageName() string { return "l3xc_plugin_get_version_reply" } +func (*L3xcPluginGetVersionReply) GetCrcString() string { return "9b32cf86" } +func (*L3xcPluginGetVersionReply) GetMessageType() api.MessageType { + return api.ReplyMessage +} + +func (m *L3xcPluginGetVersionReply) Size() int { + if m == nil { + return 0 + } + var size int + size += 4 // m.Major + size += 4 // m.Minor + return size +} +func (m *L3xcPluginGetVersionReply) 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.Major)) + buf.EncodeUint32(uint32(m.Minor)) + return buf.Bytes(), nil +} +func (m *L3xcPluginGetVersionReply) Unmarshal(b []byte) error { + buf := codec.NewBuffer(b) + m.Major = buf.DecodeUint32() + m.Minor = buf.DecodeUint32() + return nil +} + +// L3xcUpdate defines message 'l3xc_update'. +type L3xcUpdate struct { + L3xc L3xc `binapi:"l3xc,name=l3xc" json:"l3xc,omitempty"` +} + +func (m *L3xcUpdate) Reset() { *m = L3xcUpdate{} } +func (*L3xcUpdate) GetMessageName() string { return "l3xc_update" } +func (*L3xcUpdate) GetCrcString() string { return "0787b1d3" } +func (*L3xcUpdate) GetMessageType() api.MessageType { + return api.RequestMessage +} + +func (m *L3xcUpdate) Size() int { + if m == nil { + return 0 + } + var size int + size += 4 // m.L3xc.SwIfIndex + size += 1 // m.L3xc.IsIP6 + size += 1 // m.L3xc.NPaths + for j2 := 0; j2 < len(m.L3xc.Paths); j2++ { + var s2 fib_types.FibPath + _ = s2 + if j2 < len(m.L3xc.Paths) { + s2 = m.L3xc.Paths[j2] + } + size += 4 // s2.SwIfIndex + size += 4 // s2.TableID + size += 4 // s2.RpfID + size += 1 // s2.Weight + size += 1 // s2.Preference + size += 4 // s2.Type + size += 4 // s2.Flags + size += 4 // s2.Proto + size += 1 * 16 // s2.Nh.Address + size += 4 // s2.Nh.ViaLabel + size += 4 // s2.Nh.ObjID + size += 4 // s2.Nh.ClassifyTableIndex + size += 1 // s2.NLabels + for j3 := 0; j3 < 16; j3++ { + var s3 fib_types.FibMplsLabel + _ = s3 + if j3 < len(s2.LabelStack) { + s3 = s2.LabelStack[j3] + } + size += 1 // s3.IsUniform + size += 4 // s3.Label + size += 1 // s3.TTL + size += 1 // s3.Exp + } + } + return size +} +func (m *L3xcUpdate) 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.L3xc.SwIfIndex)) + buf.EncodeBool(m.L3xc.IsIP6) + buf.EncodeUint8(uint8(len(m.L3xc.Paths))) + for j1 := 0; j1 < len(m.L3xc.Paths); j1++ { + var v1 fib_types.FibPath + if j1 < len(m.L3xc.Paths) { + v1 = m.L3xc.Paths[j1] + } + buf.EncodeUint32(uint32(v1.SwIfIndex)) + buf.EncodeUint32(uint32(v1.TableID)) + buf.EncodeUint32(uint32(v1.RpfID)) + buf.EncodeUint8(uint8(v1.Weight)) + buf.EncodeUint8(uint8(v1.Preference)) + buf.EncodeUint32(uint32(v1.Type)) + buf.EncodeUint32(uint32(v1.Flags)) + buf.EncodeUint32(uint32(v1.Proto)) + buf.EncodeBytes(v1.Nh.Address.XXX_UnionData[:], 0) + buf.EncodeUint32(uint32(v1.Nh.ViaLabel)) + buf.EncodeUint32(uint32(v1.Nh.ObjID)) + buf.EncodeUint32(uint32(v1.Nh.ClassifyTableIndex)) + buf.EncodeUint8(uint8(v1.NLabels)) + for j2 := 0; j2 < 16; j2++ { + var v2 fib_types.FibMplsLabel + if j2 < len(v1.LabelStack) { + v2 = v1.LabelStack[j2] + } + buf.EncodeUint8(uint8(v2.IsUniform)) + buf.EncodeUint32(uint32(v2.Label)) + buf.EncodeUint8(uint8(v2.TTL)) + buf.EncodeUint8(uint8(v2.Exp)) + } + } + return buf.Bytes(), nil +} +func (m *L3xcUpdate) Unmarshal(b []byte) error { + buf := codec.NewBuffer(b) + m.L3xc.SwIfIndex = interface_types.InterfaceIndex(buf.DecodeUint32()) + m.L3xc.IsIP6 = buf.DecodeBool() + m.L3xc.NPaths = buf.DecodeUint8() + m.L3xc.Paths = make([]fib_types.FibPath, int(m.L3xc.NPaths)) + for j1 := 0; j1 < len(m.L3xc.Paths); j1++ { + m.L3xc.Paths[j1].SwIfIndex = buf.DecodeUint32() + m.L3xc.Paths[j1].TableID = buf.DecodeUint32() + m.L3xc.Paths[j1].RpfID = buf.DecodeUint32() + m.L3xc.Paths[j1].Weight = buf.DecodeUint8() + m.L3xc.Paths[j1].Preference = buf.DecodeUint8() + m.L3xc.Paths[j1].Type = fib_types.FibPathType(buf.DecodeUint32()) + m.L3xc.Paths[j1].Flags = fib_types.FibPathFlags(buf.DecodeUint32()) + m.L3xc.Paths[j1].Proto = fib_types.FibPathNhProto(buf.DecodeUint32()) + copy(m.L3xc.Paths[j1].Nh.Address.XXX_UnionData[:], buf.DecodeBytes(16)) + m.L3xc.Paths[j1].Nh.ViaLabel = buf.DecodeUint32() + m.L3xc.Paths[j1].Nh.ObjID = buf.DecodeUint32() + m.L3xc.Paths[j1].Nh.ClassifyTableIndex = buf.DecodeUint32() + m.L3xc.Paths[j1].NLabels = buf.DecodeUint8() + for j2 := 0; j2 < 16; j2++ { + m.L3xc.Paths[j1].LabelStack[j2].IsUniform = buf.DecodeUint8() + m.L3xc.Paths[j1].LabelStack[j2].Label = buf.DecodeUint32() + m.L3xc.Paths[j1].LabelStack[j2].TTL = buf.DecodeUint8() + m.L3xc.Paths[j1].LabelStack[j2].Exp = buf.DecodeUint8() + } + } + return nil +} + +// L3xcUpdateReply defines message 'l3xc_update_reply'. +type L3xcUpdateReply struct { + Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"` + StatsIndex uint32 `binapi:"u32,name=stats_index" json:"stats_index,omitempty"` +} + +func (m *L3xcUpdateReply) Reset() { *m = L3xcUpdateReply{} } +func (*L3xcUpdateReply) GetMessageName() string { return "l3xc_update_reply" } +func (*L3xcUpdateReply) GetCrcString() string { return "1992deab" } +func (*L3xcUpdateReply) GetMessageType() api.MessageType { + return api.ReplyMessage +} + +func (m *L3xcUpdateReply) Size() int { + if m == nil { + return 0 + } + var size int + size += 4 // m.Retval + size += 4 // m.StatsIndex + return size +} +func (m *L3xcUpdateReply) 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.StatsIndex)) + return buf.Bytes(), nil +} +func (m *L3xcUpdateReply) Unmarshal(b []byte) error { + buf := codec.NewBuffer(b) + m.Retval = int32(buf.DecodeUint32()) + m.StatsIndex = buf.DecodeUint32() + return nil +} + +func init() { file_l3xc_binapi_init() } +func file_l3xc_binapi_init() { + api.RegisterMessage((*L3xcDel)(nil), "l3xc_del_e7dbef91") + api.RegisterMessage((*L3xcDelReply)(nil), "l3xc_del_reply_e8d4e804") + api.RegisterMessage((*L3xcDetails)(nil), "l3xc_details_d4f69627") + api.RegisterMessage((*L3xcDump)(nil), "l3xc_dump_f9e6675e") + api.RegisterMessage((*L3xcPluginGetVersion)(nil), "l3xc_plugin_get_version_51077d14") + api.RegisterMessage((*L3xcPluginGetVersionReply)(nil), "l3xc_plugin_get_version_reply_9b32cf86") + api.RegisterMessage((*L3xcUpdate)(nil), "l3xc_update_0787b1d3") + api.RegisterMessage((*L3xcUpdateReply)(nil), "l3xc_update_reply_1992deab") +} + +// Messages returns list of all messages in this module. +func AllMessages() []api.Message { + return []api.Message{ + (*L3xcDel)(nil), + (*L3xcDelReply)(nil), + (*L3xcDetails)(nil), + (*L3xcDump)(nil), + (*L3xcPluginGetVersion)(nil), + (*L3xcPluginGetVersionReply)(nil), + (*L3xcUpdate)(nil), + (*L3xcUpdateReply)(nil), + } +} diff --git a/binapi/l3xc/l3xc_rest.ba.go b/binapi/l3xc/l3xc_rest.ba.go new file mode 100644 index 0000000..2b2c9ba --- /dev/null +++ b/binapi/l3xc/l3xc_rest.ba.go @@ -0,0 +1,74 @@ +// Code generated by GoVPP's binapi-generator. DO NOT EDIT. + +package l3xc + +import ( + "encoding/json" + "io/ioutil" + "net/http" +) + +func RESTHandler(rpc RPCService) http.Handler { + mux := http.NewServeMux() + mux.HandleFunc("/l3xc_del", func(w http.ResponseWriter, req *http.Request) { + var request = new(L3xcDel) + 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.L3xcDel(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) + }) + mux.HandleFunc("/l3xc_plugin_get_version", func(w http.ResponseWriter, req *http.Request) { + var request = new(L3xcPluginGetVersion) + reply, err := rpc.L3xcPluginGetVersion(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) + }) + mux.HandleFunc("/l3xc_update", func(w http.ResponseWriter, req *http.Request) { + var request = new(L3xcUpdate) + 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.L3xcUpdate(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/l3xc/l3xc_rpc.ba.go b/binapi/l3xc/l3xc_rpc.ba.go new file mode 100644 index 0000000..74940a2 --- /dev/null +++ b/binapi/l3xc/l3xc_rpc.ba.go @@ -0,0 +1,93 @@ +// Code generated by GoVPP's binapi-generator. DO NOT EDIT. + +package l3xc + +import ( + "context" + "fmt" + api "git.fd.io/govpp.git/api" + vpe "git.fd.io/govpp.git/binapi/vpe" + "io" +) + +// RPCService defines RPC service l3xc. +type RPCService interface { + L3xcDel(ctx context.Context, in *L3xcDel) (*L3xcDelReply, error) + L3xcDump(ctx context.Context, in *L3xcDump) (RPCService_L3xcDumpClient, error) + L3xcPluginGetVersion(ctx context.Context, in *L3xcPluginGetVersion) (*L3xcPluginGetVersionReply, error) + L3xcUpdate(ctx context.Context, in *L3xcUpdate) (*L3xcUpdateReply, error) +} + +type serviceClient struct { + conn api.Connection +} + +func NewServiceClient(conn api.Connection) RPCService { + return &serviceClient{conn} +} + +func (c *serviceClient) L3xcDel(ctx context.Context, in *L3xcDel) (*L3xcDelReply, error) { + out := new(L3xcDelReply) + err := c.conn.Invoke(ctx, in, out) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *serviceClient) L3xcDump(ctx context.Context, in *L3xcDump) (RPCService_L3xcDumpClient, error) { + stream, err := c.conn.NewStream(ctx) + if err != nil { + return nil, err + } + x := &serviceClient_L3xcDumpClient{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_L3xcDumpClient interface { + Recv() (*L3xcDetails, error) + api.Stream +} + +type serviceClient_L3xcDumpClient struct { + api.Stream +} + +func (c *serviceClient_L3xcDumpClient) Recv() (*L3xcDetails, error) { + msg, err := c.Stream.RecvMsg() + if err != nil { + return nil, err + } + switch m := msg.(type) { + case *L3xcDetails: + return m, nil + case *vpe.ControlPingReply: + return nil, io.EOF + default: + return nil, fmt.Errorf("unexpected message: %T %v", m, m) + } +} + +func (c *serviceClient) L3xcPluginGetVersion(ctx context.Context, in *L3xcPluginGetVersion) (*L3xcPluginGetVersionReply, error) { + out := new(L3xcPluginGetVersionReply) + err := c.conn.Invoke(ctx, in, out) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *serviceClient) L3xcUpdate(ctx context.Context, in *L3xcUpdate) (*L3xcUpdateReply, error) { + out := new(L3xcUpdateReply) + err := c.conn.Invoke(ctx, in, out) + if err != nil { + return nil, err + } + return out, nil +} |