aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2020-06-18 08:22:13 +0200
committerOndrej Fabry <ofabry@cisco.com>2020-06-22 14:37:14 +0200
commit94620e85f0bdbb054af07ce3670fadc1f76cfdf0 (patch)
tree7784ddf381c4e08a6a1ece5b55911b47ea8395f3
parent280b1c6c83b676ef4e592f4ecf60cb5b54b6a753 (diff)
Refactored binapi generator with message encoding
Change-Id: I5a6abb68b9d058866f94818169300e5c2fc43895 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
-rw-r--r--Makefile3
-rw-r--r--api/binapi.go1
-rw-r--r--binapigen/binapigen.go369
-rw-r--r--binapigen/definitions.go (renamed from cmd/binapi-generator/definitions.go)29
-rw-r--r--binapigen/definitions_test.go39
-rw-r--r--binapigen/generate.go1241
-rw-r--r--binapigen/generate_rpc.go188
-rw-r--r--binapigen/generate_test.go (renamed from cmd/binapi-generator/generate_test.go)126
-rw-r--r--binapigen/generator.go172
-rw-r--r--binapigen/generator_test.go (renamed from cmd/binapi-generator/parse_test.go)37
-rw-r--r--binapigen/run.go89
-rw-r--r--binapigen/types.go271
-rw-r--r--binapigen/validate.go66
-rw-r--r--binapigen/vppapi/api.go94
-rw-r--r--binapigen/vppapi/integration_test.go43
-rw-r--r--binapigen/vppapi/parse_json.go552
-rw-r--r--binapigen/vppapi/parser.go111
-rw-r--r--binapigen/vppapi/parser_test.go114
-rw-r--r--binapigen/vppapi/testdata/acl.api.json (renamed from cmd/binapi-generator/testdata/acl.api.json)0
-rw-r--r--binapigen/vppapi/testdata/af_packet.api.json (renamed from cmd/binapi-generator/testdata/af_packet.api.json)22
-rw-r--r--binapigen/vppapi/testdata/input-generate-error.json (renamed from cmd/binapi-generator/testdata/input-generate-error.json)0
-rw-r--r--binapigen/vppapi/testdata/input-read-json-error.json (renamed from cmd/binapi-generator/testdata/input-read-json-error.json)0
-rw-r--r--binapigen/vppapi/testdata/input.txt (renamed from cmd/binapi-generator/testdata/input.txt)0
-rw-r--r--binapigen/vppapi/testdata/ip.api.json (renamed from cmd/binapi-generator/testdata/ip.api.json)0
-rw-r--r--binapigen/vppapi/testdata/test-all.api.json3240
-rw-r--r--binapigen/vppapi/testdata/vpe.api.json775
-rw-r--r--cmd/binapi-generator/definitions_test.go25
-rw-r--r--cmd/binapi-generator/doc.go16
-rw-r--r--cmd/binapi-generator/generate.go848
-rw-r--r--cmd/binapi-generator/main.go350
-rw-r--r--cmd/binapi-generator/objects.go139
-rw-r--r--cmd/binapi-generator/parse.go557
-rw-r--r--cmd/binapi-generator/types.go147
-rw-r--r--cmd/binapi-generator/util.go81
-rw-r--r--codec/bench_test.go90
-rw-r--r--codec/marshaler.go229
-rw-r--r--codec/marshaler_test.go712
-rw-r--r--codec/msg_codec_test.go81
-rw-r--r--examples/binapi/acl/acl.ba.go3172
-rw-r--r--examples/binapi/acl/acl_rpc.ba.go302
-rw-r--r--examples/binapi/af_packet/af_packet.ba.go685
-rw-r--r--examples/binapi/af_packet/af_packet_rpc.ba.go84
-rw-r--r--examples/binapi/ethernet_types/ethernet_types.ba.go44
-rw-r--r--examples/binapi/fib_types/fib_types.ba.go522
-rw-r--r--examples/binapi/gen.go17
-rw-r--r--examples/binapi/interface_types/interface_types.ba.go252
-rw-r--r--examples/binapi/interfaces/interfaces.ba.go3751
-rw-r--r--examples/binapi/interfaces/interfaces_rpc.ba.go321
-rw-r--r--examples/binapi/ip/ip.ba.go5584
-rw-r--r--examples/binapi/ip/ip_rpc.ba.go497
-rw-r--r--examples/binapi/ip_types/ip_types.ba.go261
-rw-r--r--examples/binapi/memclnt/memclnt.ba.go1340
-rw-r--r--examples/binapi/memclnt/memclnt_rpc.ba.go141
-rw-r--r--examples/binapi/memif/memif.ba.go1025
-rw-r--r--examples/binapi/memif/memif_rpc.ba.go111
-rw-r--r--examples/binapi/sr/sr.ba.go1716
-rw-r--r--examples/binapi/sr/sr_rpc.ba.go178
-rw-r--r--examples/binapi/vpe/vpe.ba.go1589
-rw-r--r--examples/binapi/vpe/vpe_rpc.ba.go174
-rw-r--r--examples/binapi/vpe_types/vpe_types.ba.go107
-rw-r--r--examples/simple-client/simple_client.go12
61 files changed, 27510 insertions, 5232 deletions
diff --git a/Makefile b/Makefile
index e5bd0bd..7c6a03b 100644
--- a/Makefile
+++ b/Makefile
@@ -97,11 +97,12 @@ gen-binapi-docker: install-generator ## Generate binapi code (using Docker)
@echo "# generating binapi in docker image ${VPP_IMG}"
$(eval cmds := $(shell go generate -n $(BINAPI_DIR) 2>&1 | tr "\n" ";"))
docker run -t --rm \
+ -e DEBUG_GOVPP \
-v "$(shell which binapi-generator):/usr/local/bin/binapi-generator:ro" \
-v "$(shell pwd):/govpp" -w /govpp \
-u "$(shell id -u):$(shell id -g)" \
"${VPP_IMG}" \
- sh -exc "cd $(BINAPI_DIR) && $(cmds)"
+ sh -ec "cd $(BINAPI_DIR) && $(cmds)"
extras:
@make -C extras
diff --git a/api/binapi.go b/api/binapi.go
index 96eb3bf..20ddd28 100644
--- a/api/binapi.go
+++ b/api/binapi.go
@@ -163,3 +163,4 @@ func GetRegisteredMessageTypes() map[reflect.Type]string {
// GoVppAPIPackageIsVersionX is referenced from generated binapi files
// to assert that that code is compatible with this version of the GoVPP api package.
const GoVppAPIPackageIsVersion1 = true
+const GoVppAPIPackageIsVersion2 = true
diff --git a/binapigen/binapigen.go b/binapigen/binapigen.go
new file mode 100644
index 0000000..0178476
--- /dev/null
+++ b/binapigen/binapigen.go
@@ -0,0 +1,369 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package binapigen
+
+import (
+ "fmt"
+ "path"
+ "sort"
+ "strings"
+
+ "git.fd.io/govpp.git/binapigen/vppapi"
+)
+
+type File struct {
+ vppapi.File
+
+ Generate bool
+
+ PackageName string
+ Imports []string
+
+ Enums []*Enum
+ Unions []*Union
+ Structs []*Struct
+ Aliases []*Alias
+ Messages []*Message
+
+ imports map[string]string
+ refmap map[string]string
+}
+
+func newFile(gen *Generator, apifile *vppapi.File) (*File, error) {
+ file := &File{
+ File: *apifile,
+ PackageName: sanitizedName(apifile.Name),
+ imports: make(map[string]string),
+ refmap: make(map[string]string),
+ }
+
+ sortFileObjects(&file.File)
+
+ for _, imp := range apifile.Imports {
+ file.Imports = append(file.Imports, normalizeImport(imp))
+ }
+ for _, enum := range apifile.EnumTypes {
+ file.Enums = append(file.Enums, newEnum(gen, file, enum))
+ }
+ for _, alias := range apifile.AliasTypes {
+ file.Aliases = append(file.Aliases, newAlias(gen, file, alias))
+ }
+ for _, structType := range apifile.StructTypes {
+ file.Structs = append(file.Structs, newStruct(gen, file, structType))
+ }
+ for _, union := range apifile.UnionTypes {
+ file.Unions = append(file.Unions, newUnion(gen, file, union))
+ }
+ for _, msg := range apifile.Messages {
+ file.Messages = append(file.Messages, newMessage(gen, file, msg))
+ }
+
+ return file, nil
+}
+
+func (file *File) isTypes() bool {
+ return strings.HasSuffix(file.File.Name, "_types")
+}
+
+func (file *File) hasService() bool {
+ return file.Service != nil && len(file.Service.RPCs) > 0
+}
+
+func (file *File) addRef(typ string, name string, ref interface{}) {
+ apiName := toApiType(name)
+ if _, ok := file.refmap[apiName]; ok {
+ logf("%s type %v already in refmap", typ, apiName)
+ return
+ }
+ file.refmap[apiName] = name
+}
+
+func (file *File) importedFiles(gen *Generator) []*File {
+ var files []*File
+ for _, imp := range file.Imports {
+ impFile, ok := gen.FilesByName[imp]
+ if !ok {
+ logf("file %s import %s not found API files", file.Name, imp)
+ continue
+ }
+ //if gen.ImportTypes || impFile.Generate {
+ files = append(files, impFile)
+ //}
+ }
+ return files
+}
+
+func (file *File) loadTypeImports(gen *Generator, typeFiles []*File) {
+ if len(typeFiles) == 0 {
+ return
+ }
+ for _, t := range file.Structs {
+ for _, imp := range typeFiles {
+ if _, ok := file.imports[t.Name]; ok {
+ break
+ }
+ for _, at := range imp.File.StructTypes {
+ if at.Name != t.Name {
+ continue
+ }
+ if len(at.Fields) != len(t.Fields) {
+ continue
+ }
+ file.imports[t.Name] = imp.PackageName
+ }
+ }
+ }
+ for _, t := range file.AliasTypes {
+ for _, imp := range typeFiles {
+ if _, ok := file.imports[t.Name]; ok {
+ break
+ }
+ for _, at := range imp.File.AliasTypes {
+ if at.Name != t.Name {
+ continue
+ }
+ if at.Length != t.Length {
+ continue
+ }
+ if at.Type != t.Type {
+ continue
+ }
+ file.imports[t.Name] = imp.PackageName
+ }
+ }
+ }
+ for _, t := range file.EnumTypes {
+ for _, imp := range typeFiles {
+ if _, ok := file.imports[t.Name]; ok {
+ break
+ }
+ for _, at := range imp.File.EnumTypes {
+ if at.Name != t.Name {
+ continue
+ }
+ if at.Type != t.Type {
+ continue
+ }
+ file.imports[t.Name] = imp.PackageName
+ }
+ }
+ }
+ for _, t := range file.UnionTypes {
+ for _, imp := range typeFiles {
+ if _, ok := file.imports[t.Name]; ok {
+ break
+ }
+ for _, at := range imp.File.UnionTypes {
+ if at.Name != t.Name {
+ continue
+ }
+ file.imports[t.Name] = imp.PackageName
+ /*if gen.ImportTypes {
+ imp.Generate = true
+ }*/
+ }
+ }
+ }
+}
+
+type Enum struct {
+ vppapi.EnumType
+
+ GoName string
+}
+
+func newEnum(gen *Generator, file *File, apitype vppapi.EnumType) *Enum {
+ typ := &Enum{
+ EnumType: apitype,
+ GoName: camelCaseName(apitype.Name),
+ }
+ gen.enumsByName[fmt.Sprintf("%s.%s", file.Name, typ.Name)] = typ
+ file.addRef("enum", typ.Name, typ)
+ return typ
+}
+
+type Alias struct {
+ vppapi.AliasType
+
+ GoName string
+}
+
+func newAlias(gen *Generator, file *File, apitype vppapi.AliasType) *Alias {
+ typ := &Alias{
+ AliasType: apitype,
+ GoName: camelCaseName(apitype.Name),
+ }
+ gen.aliasesByName[fmt.Sprintf("%s.%s", file.Name, typ.Name)] = typ
+ file.addRef("alias", typ.Name, typ)
+ return typ
+}
+
+type Struct struct {
+ vppapi.StructType
+
+ GoName string
+
+ Fields []*Field
+}
+
+func newStruct(gen *Generator, file *File, apitype vppapi.StructType) *Struct {
+ typ := &Struct{
+ StructType: apitype,
+ GoName: camelCaseName(apitype.Name),
+ }
+ for _, fieldType := range apitype.Fields {
+ field := newField(gen, file, fieldType)
+ field.ParentStruct = typ
+ typ.Fields = append(typ.Fields, field)
+ }
+ gen.structsByName[fmt.Sprintf("%s.%s", file.Name, typ.Name)] = typ
+ file.addRef("struct", typ.Name, typ)
+ return typ
+}
+
+type Union struct {
+ vppapi.UnionType
+
+ GoName string
+
+ Fields []*Field
+}
+
+func newUnion(gen *Generator, file *File, apitype vppapi.UnionType) *Union {
+ typ := &Union{
+ UnionType: apitype,
+ GoName: camelCaseName(apitype.Name),
+ }
+ gen.unionsByName[fmt.Sprintf("%s.%s", file.Name, typ.Name)] = typ
+ for _, fieldType := range apitype.Fields {
+ field := newField(gen, file, fieldType)
+ field.ParentUnion = typ
+ typ.Fields = append(typ.Fields, field)
+ }
+ file.addRef("union", typ.Name, typ)
+ return typ
+}
+
+type Message struct {
+ vppapi.Message
+
+ GoName string
+
+ Fields []*Field
+}
+
+func newMessage(gen *Generator, file *File, apitype vppapi.Message) *Message {
+ msg := &Message{
+ Message: apitype,
+ GoName: camelCaseName(apitype.Name),
+ }
+ for _, fieldType := range apitype.Fields {
+ field := newField(gen, file, fieldType)
+ field.ParentMessage = msg
+ msg.Fields = append(msg.Fields, field)
+ }
+ return msg
+}
+
+type Field struct {
+ vppapi.Field
+
+ GoName string
+
+ // Field parent
+ ParentMessage *Message
+ ParentStruct *Struct
+ ParentUnion *Union
+
+ // Type reference
+ Enum *Enum
+ Alias *Alias
+ Struct *Struct
+ Union *Union
+}
+
+func newField(gen *Generator, file *File, apitype vppapi.Field) *Field {
+ typ := &Field{
+ Field: apitype,
+ GoName: camelCaseName(apitype.Name),
+ }
+ return typ
+}
+
+func (f *Field) resolveType(gen *Generator) error {
+ switch {
+
+ }
+ return nil
+}
+
+type Service = vppapi.Service
+type RPC = vppapi.RPC
+
+func sortFileObjects(file *vppapi.File) {
+ // sort imports
+ sort.SliceStable(file.Imports, func(i, j int) bool {
+ return file.Imports[i] < file.Imports[j]
+ })
+ // sort enum types
+ sort.SliceStable(file.EnumTypes, func(i, j int) bool {
+ return file.EnumTypes[i].Name < file.EnumTypes[j].Name
+ })
+ // sort alias types
+ sort.Slice(file.AliasTypes, func(i, j int) bool {
+ return file.AliasTypes[i].Name < file.AliasTypes[j].Name
+ })
+ // sort struct types
+ sort.SliceStable(file.StructTypes, func(i, j int) bool {
+ return file.StructTypes[i].Name < file.StructTypes[j].Name
+ })
+ // sort union types
+ sort.SliceStable(file.UnionTypes, func(i, j int) bool {
+ return file.UnionTypes[i].Name < file.UnionTypes[j].Name
+ })
+ // sort messages
+ sort.SliceStable(file.Messages, func(i, j int) bool {
+ return file.Messages[i].Name < file.Messages[j].Name
+ })
+ // sort services
+ if file.Service != nil {
+ sort.Slice(file.Service.RPCs, func(i, j int) bool {
+ // dumps first
+ if file.Service.RPCs[i].Stream != file.Service.RPCs[j].Stream {
+ return file.Service.RPCs[i].Stream
+ }
+ return file.Service.RPCs[i].RequestMsg < file.Service.RPCs[j].RequestMsg
+ })
+ }
+}
+
+func sanitizedName(name string) string {
+ switch name {
+ case "interface":
+ return "interfaces"
+ case "map":
+ return "maps"
+ default:
+ return name
+ }
+}
+
+func normalizeImport(imp string) string {
+ imp = path.Base(imp)
+ if idx := strings.Index(imp, "."); idx >= 0 {
+ imp = imp[:idx]
+ }
+ return imp
+}
diff --git a/cmd/binapi-generator/definitions.go b/binapigen/definitions.go
index 9bf9e53..3c8a874 100644
--- a/cmd/binapi-generator/definitions.go
+++ b/binapigen/definitions.go
@@ -1,18 +1,18 @@
-// Copyright (c) 2018 Cisco and/or its affiliates.
+// Copyright (c) 2020 Cisco and/or its affiliates.
//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at:
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
-package main
+package binapigen
import (
"strings"
@@ -23,7 +23,10 @@ import (
var commonInitialisms = map[string]bool{
"ACL": true,
"API": true,
- //"ASCII": true, // there are only two use cases for ASCII which already have initialism before and after
+ // NOTE: There are only two occurences of the word 'ascii' and
+ // these already have initialism before and after ASCII part,
+ // thus disabling initialism for this case.
+ "ASCII": false,
"CPU": true,
"CSS": true,
"DNS": true,
@@ -68,8 +71,6 @@ var commonInitialisms = map[string]bool{
// specialInitialisms is a set of special initialisms that need part to stay in upper case.
var specialInitialisms = map[string]string{
"IPV": "IPv",
- //"IPV4": "IPv4",
- //"IPV6": "IPv6",
}
func usesInitialism(s string) string {
diff --git a/binapigen/definitions_test.go b/binapigen/definitions_test.go
new file mode 100644
index 0000000..761c95f
--- /dev/null
+++ b/binapigen/definitions_test.go
@@ -0,0 +1,39 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package binapigen
+
+import (
+ "testing"
+)
+
+func TestInitialism(t *testing.T) {
+ tests := []struct {
+ name string
+ input string
+ expOutput string
+ }{
+ {name: "id", input: "id", expOutput: "ID"},
+ {name: "ipv6", input: "is_ipv6", expOutput: "IsIPv6"},
+ {name: "ip6", input: "is_ip6", expOutput: "IsIP6"},
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ output := camelCaseName(test.input)
+ if output != test.expOutput {
+ t.Errorf("expected %q, got %q", test.expOutput, output)
+ }
+ })
+ }
+}
diff --git a/binapigen/generate.go b/binapigen/generate.go
new file mode 100644
index 0000000..1f9b89a
--- /dev/null
+++ b/binapigen/generate.go
@@ -0,0 +1,1241 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package binapigen
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "os/exec"
+ "path"
+ "path/filepath"
+ "sort"
+ "strings"
+
+ "git.fd.io/govpp.git/version"
+)
+
+// generatedCodeVersion indicates a version of the generated code.
+// It is incremented whenever an incompatibility between the generated code and
+// GoVPP api package is introduced; the generated code references
+// a constant, api.GoVppAPIPackageIsVersionN (where N is generatedCodeVersion).
+const generatedCodeVersion = 2
+
+// message field names
+const (
+ msgIdField = "_vl_msg_id"
+ clientIndexField = "client_index"
+ contextField = "context"
+ retvalField = "retval"
+)
+
+const (
+ outputFileExt = ".ba.go" // file extension of the Go generated files
+ rpcFileSuffix = "_rpc" // file name suffix for the RPC services
+
+ constModuleName = "ModuleName" // module name constant
+ constAPIVersion = "APIVersion" // API version constant
+ constVersionCrc = "VersionCrc" // version CRC constant
+
+ unionDataField = "XXX_UnionData" // name for the union data field
+
+ serviceApiName = "RPCService" // name for the RPC service interface
+ serviceImplName = "serviceClient" // name for the RPC service implementation
+ serviceClientName = "ServiceClient" // name for the RPC service client
+
+ // TODO: register service descriptor
+ //serviceDescType = "ServiceDesc" // name for service descriptor type
+ //serviceDescName = "_ServiceRPC_serviceDesc" // name for service descriptor var
+)
+
+// MessageType represents the type of a VPP message
+type MessageType int
+
+const (
+ requestMessage MessageType = iota // VPP request message
+ replyMessage // VPP reply message
+ eventMessage // VPP event message
+ otherMessage // other VPP message
+)
+
+type GenFile struct {
+ *Generator
+ filename string
+ file *File
+ packageDir string
+ buf bytes.Buffer
+}
+
+func generatePackage(ctx *GenFile, w io.Writer) {
+ logf("----------------------------")
+ logf("generating binapi package: %q", ctx.file.PackageName)
+ logf("----------------------------")
+
+ generateHeader(ctx, w)
+ generateImports(ctx, w)
+
+ // generate module desc
+ fmt.Fprintln(w, "const (")
+ fmt.Fprintf(w, "\t// %s is the name of this module.\n", constModuleName)
+ fmt.Fprintf(w, "\t%s = \"%s\"\n", constModuleName, ctx.file.Name)
+
+ if ctx.IncludeAPIVersion {
+ fmt.Fprintf(w, "\t// %s is the API version of this module.\n", constAPIVersion)
+ fmt.Fprintf(w, "\t%s = \"%s\"\n", constAPIVersion, ctx.file.Version())
+ fmt.Fprintf(w, "\t// %s is the CRC of this module.\n", constVersionCrc)
+ fmt.Fprintf(w, "\t%s = %v\n", constVersionCrc, ctx.file.CRC)
+ }
+ fmt.Fprintln(w, ")")
+ fmt.Fprintln(w)
+
+ // generate enums
+ if len(ctx.file.Enums) > 0 {
+ for _, enum := range ctx.file.Enums {
+ if imp, ok := ctx.file.imports[enum.Name]; ok {
+ generateImportedAlias(ctx, w, enum.GoName, imp)
+ continue
+ }
+ generateEnum(ctx, w, enum)
+ }
+ }
+
+ // generate aliases
+ if len(ctx.file.Aliases) > 0 {
+ for _, alias := range ctx.file.Aliases {
+ if imp, ok := ctx.file.imports[alias.Name]; ok {
+ generateImportedAlias(ctx, w, alias.GoName, imp)
+ continue
+ }
+ generateAlias(ctx, w, alias)
+ }
+ }
+
+ // generate types
+ if len(ctx.file.Structs) > 0 {
+ for _, typ := range ctx.file.Structs {
+ if imp, ok := ctx.file.imports[typ.Name]; ok {
+ generateImportedAlias(ctx, w, typ.GoName, imp)
+ continue
+ }
+ generateStruct(ctx, w, typ)
+ }
+ }
+
+ // generate unions
+ if len(ctx.file.Unions) > 0 {
+ for _, union := range ctx.file.Unions {
+ if imp, ok := ctx.file.imports[union.Name]; ok {
+ generateImportedAlias(ctx, w, union.GoName, imp)
+ continue
+ }
+ generateUnion(ctx, w, union)
+ }
+ }
+
+ // generate messages
+ if len(ctx.file.Messages) > 0 {
+ for _, msg := range ctx.file.Messages {
+ generateMessage(ctx, w, msg)
+ }
+
+ initFnName := fmt.Sprintf("file_%s_binapi_init", ctx.file.PackageName)
+
+ // generate message registrations
+ fmt.Fprintf(w, "func init() { %s() }\n", initFnName)
+ fmt.Fprintf(w, "func %s() {\n", initFnName)
+ for _, msg := range ctx.file.Messages {
+ fmt.Fprintf(w, "\tapi.RegisterMessage((*%s)(nil), \"%s\")\n",
+ msg.GoName, ctx.file.Name+"."+msg.GoName)
+ }
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)
+
+ // generate list of messages
+ fmt.Fprintf(w, "// Messages returns list of all messages in this module.\n")
+ fmt.Fprintln(w, "func AllMessages() []api.Message {")
+ fmt.Fprintln(w, "\treturn []api.Message{")
+ for _, msg := range ctx.file.Messages {
+ fmt.Fprintf(w, "\t(*%s)(nil),\n", msg.GoName)
+ }
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w, "}")
+ }
+
+ generateFooter(ctx, w)
+
+}
+
+func generateHeader(ctx *GenFile, w io.Writer) {
+ fmt.Fprintln(w, "// Code generated by GoVPP's binapi-generator. DO NOT EDIT.")
+ fmt.Fprintln(w, "// versions:")
+ fmt.Fprintf(w, "// binapi-generator: %s\n", version.Version())
+ if ctx.IncludeVppVersion {
+ fmt.Fprintf(w, "// VPP: %s\n", ctx.VPPVersion)
+ }
+ fmt.Fprintf(w, "// source: %s\n", ctx.file.Path)
+ fmt.Fprintln(w)
+
+ fmt.Fprintln(w, "/*")
+ fmt.Fprintf(w, "Package %s contains generated code for VPP binary API defined by %s.api (version %s).\n",
+ ctx.file.PackageName, ctx.file.Name, ctx.file.Version())
+ fmt.Fprintln(w)
+ fmt.Fprintln(w, "It consists of:")
+ printObjNum := func(obj string, num int) {
+ if num > 0 {
+ if num > 1 {
+ if strings.HasSuffix(obj, "s") {
+
+ obj += "es"
+ } else {
+ obj += "s"
+ }
+ }
+ fmt.Fprintf(w, "\t%3d %s\n", num, obj)
+ }
+ }
+ //printObjNum("RPC", len(ctx.file.Service.RPCs))
+ printObjNum("alias", len(ctx.file.Aliases))
+ printObjNum("enum", len(ctx.file.Enums))
+ printObjNum("message", len(ctx.file.Messages))
+ printObjNum("type", len(ctx.file.Structs))
+ printObjNum("union", len(ctx.file.Unions))
+ fmt.Fprintln(w, "*/")
+ fmt.Fprintf(w, "package %s\n", ctx.file.PackageName)
+ fmt.Fprintln(w)
+}
+
+func generateImports(ctx *GenFile, w io.Writer) {
+ fmt.Fprintln(w, "import (")
+ fmt.Fprintln(w, ` "bytes"`)
+ fmt.Fprintln(w, ` "context"`)
+ fmt.Fprintln(w, ` "encoding/binary"`)
+ fmt.Fprintln(w, ` "io"`)
+ fmt.Fprintln(w, ` "math"`)
+ fmt.Fprintln(w, ` "strconv"`)
+ fmt.Fprintln(w)
+ fmt.Fprintf(w, "\tapi \"%s\"\n", "git.fd.io/govpp.git/api")
+ fmt.Fprintf(w, "\tcodec \"%s\"\n", "git.fd.io/govpp.git/codec")
+ fmt.Fprintf(w, "\tstruc \"%s\"\n", "github.com/lunixbochs/struc")
+ if len(ctx.file.Imports) > 0 {
+ fmt.Fprintln(w)
+ for _, imp := range ctx.file.Imports {
+ importPath := path.Join(ctx.ImportPrefix, imp)
+ if ctx.ImportPrefix == "" {
+ importPath = getImportPath(ctx.packageDir, imp)
+ }
+ fmt.Fprintf(w, "\t%s \"%s\"\n", imp, strings.TrimSpace(importPath))
+ }
+ }
+ fmt.Fprintln(w, ")")
+ fmt.Fprintln(w)
+
+ fmt.Fprintln(w, "// This is a compile-time assertion to ensure that this generated file")
+ fmt.Fprintln(w, "// is compatible with the GoVPP api package it is being compiled against.")
+ fmt.Fprintln(w, "// A compilation error at this line likely means your copy of the")
+ fmt.Fprintln(w, "// GoVPP api package needs to be updated.")
+ fmt.Fprintf(w, "const _ = api.GoVppAPIPackageIsVersion%d // please upgrade the GoVPP api package\n", generatedCodeVersion)
+ fmt.Fprintln(w)
+}
+
+func getImportPath(outputDir string, pkg string) string {
+ absPath, err := filepath.Abs(filepath.Join(outputDir, "..", pkg))
+ if err != nil {
+ panic(err)
+ }
+ cmd := exec.Command("go", "list", absPath)
+ var errbuf, outbuf bytes.Buffer
+ cmd.Stdout = &outbuf
+ cmd.Stderr = &errbuf
+ if err := cmd.Run(); err != nil {
+ fmt.Printf("ERR: %v\n", errbuf.String())
+ panic(err)
+ }
+ return outbuf.String()
+}
+
+func generateFooter(ctx *GenFile, w io.Writer) {
+ fmt.Fprintf(w, "// Reference imports to suppress errors if they are not otherwise used.\n")
+ fmt.Fprintf(w, "var _ = api.RegisterMessage\n")
+ fmt.Fprintf(w, "var _ = codec.DecodeString\n")
+ fmt.Fprintf(w, "var _ = bytes.NewBuffer\n")
+ fmt.Fprintf(w, "var _ = context.Background\n")
+ fmt.Fprintf(w, "var _ = io.Copy\n")
+ fmt.Fprintf(w, "var _ = strconv.Itoa\n")
+ fmt.Fprintf(w, "var _ = struc.Pack\n")
+ fmt.Fprintf(w, "var _ = binary.BigEndian\n")
+ fmt.Fprintf(w, "var _ = math.Float32bits\n")
+}
+
+func generateComment(ctx *GenFile, w io.Writer, goName string, vppName string, objKind string) {
+ if objKind == "service" {
+ fmt.Fprintf(w, "// %s represents RPC service API for %s module.\n", goName, ctx.file.Name)
+ } else {
+ fmt.Fprintf(w, "// %s represents VPP binary API %s '%s'.\n", goName, objKind, vppName)
+ }
+}
+
+func generateEnum(ctx *GenFile, w io.Writer, enum *Enum) {
+ name := enum.GoName
+ typ := binapiTypes[enum.Type]
+
+ logf(" writing ENUM %q (%s) with %d entries", enum.Name, name, len(enum.Entries))
+
+ // generate enum comment
+ generateComment(ctx, w, name, enum.Name, "enum")
+
+ // generate enum definition
+ fmt.Fprintf(w, "type %s %s\n", name, typ)
+ fmt.Fprintln(w)
+
+ // generate enum entries
+ fmt.Fprintln(w, "const (")
+ for _, entry := range enum.Entries {
+ fmt.Fprintf(w, "\t%s %s = %v\n", entry.Name, name, entry.Value)
+ }
+ fmt.Fprintln(w, ")")
+ fmt.Fprintln(w)
+
+ // generate enum conversion maps
+ fmt.Fprintln(w, "var (")
+ fmt.Fprintf(w, "%s_name = map[%s]string{\n", name, typ)
+ for _, entry := range enum.Entries {
+ fmt.Fprintf(w, "\t%v: \"%s\",\n", entry.Value, entry.Name)
+ }
+ fmt.Fprintln(w, "}")
+ fmt.Fprintf(w, "%s_value = map[string]%s{\n", name, typ)
+ for _, entry := range enum.Entries {
+ fmt.Fprintf(w, "\t\"%s\": %v,\n", entry.Name, entry.Value)
+ }
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w, ")")
+ fmt.Fprintln(w)
+
+ fmt.Fprintf(w, "func (x %s) String() string {\n", name)
+ fmt.Fprintf(w, "\ts, ok := %s_name[%s(x)]\n", name, typ)
+ fmt.Fprintf(w, "\tif ok { return s }\n")
+ fmt.Fprintf(w, "\treturn \"%s(\" + strconv.Itoa(int(x)) + \")\"\n", name)
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)
+}
+
+func generateImportedAlias(ctx *GenFile, w io.Writer, name string, imp string) {
+ fmt.Fprintf(w, "type %s = %s.%s\n", name, imp, name)
+ fmt.Fprintln(w)
+}
+
+func generateAlias(ctx *GenFile, w io.Writer, alias *Alias) {
+ name := alias.GoName
+
+ logf(" writing ALIAS %q (%s), length: %d", alias.Name, name, alias.Length)
+
+ // generate struct comment
+ generateComment(ctx, w, name, alias.Name, "alias")
+
+ // generate struct definition
+ fmt.Fprintf(w, "type %s ", name)
+
+ if alias.Length > 0 {
+ fmt.Fprintf(w, "[%d]", alias.Length)
+ }
+
+ dataType := convertToGoType(ctx.file, alias.Type)
+ fmt.Fprintf(w, "%s\n", dataType)
+
+ fmt.Fprintln(w)
+}
+
+func generateStruct(ctx *GenFile, w io.Writer, typ *Struct) {
+ name := typ.GoName
+
+ logf(" writing STRUCT %q (%s) with %d fields", typ.Name, name, len(typ.Fields))
+
+ // generate struct comment
+ generateComment(ctx, w, name, typ.Name, "type")
+
+ // generate struct definition
+ fmt.Fprintf(w, "type %s struct {\n", name)
+
+ // generate struct fields
+ for i := range typ.Fields {
+ // skip internal fields
+ switch strings.ToLower(typ.Name) {
+ case msgIdField:
+ continue
+ }
+
+ generateField(ctx, w, typ.Fields, i)
+ }
+
+ // generate end of the struct
+ fmt.Fprintln(w, "}")
+
+ // generate name getter
+ generateTypeNameGetter(w, name, typ.Name)
+
+ fmt.Fprintln(w)
+}
+
+// generateUnionMethods generates methods that implement struc.Custom
+// interface to allow having XXX_uniondata field unexported
+// TODO: do more testing when unions are actually used in some messages
+/*func generateUnionMethods(w io.Writer, structName string) {
+ // generate struc.Custom implementation for union
+ fmt.Fprintf(w, `
+func (u *%[1]s) Pack(p []byte, opt *struc.Options) (int, error) {
+ var b = new(bytes.Buffer)
+ if err := struc.PackWithOptions(b, u.union_data, opt); err != nil {
+ return 0, err
+ }
+ copy(p, b.Bytes())
+ return b.Len(), nil
+}
+func (u *%[1]s) Unpack(r io.Reader, length int, opt *struc.Options) error {
+ return struc.UnpackWithOptions(r, u.union_data[:], opt)
+}
+func (u *%[1]s) Size(opt *struc.Options) int {
+ return len(u.union_data)
+}
+func (u *%[1]s) String() string {
+ return string(u.union_data[:])
+}
+`, structName)
+}*/
+
+/*func generateUnionGetterSetterNew(w io.Writer, structName string, getterField, getterStruct string) {
+ fmt.Fprintf(w, `
+func %[1]s%[2]s(a %[3]s) (u %[1]s) {
+ u.Set%[2]s(a)
+ return
+}
+func (u *%[1]s) Set%[2]s(a %[3]s) {
+ copy(u.%[4]s[:], a[:])
+}
+func (u *%[1]s) Get%[2]s() (a %[3]s) {
+ copy(a[:], u.%[4]s[:])
+ return
+}
+`, structName, getterField, getterStruct, unionDataField)
+}*/
+
+func generateUnion(ctx *GenFile, w io.Writer, union *Union) {
+ name := union.GoName
+
+ logf(" writing UNION %q (%s) with %d fields", union.Name, name, len(union.Fields))
+
+ // generate struct comment
+ generateComment(ctx, w, name, union.Name, "union")
+
+ // generate struct definition
+ fmt.Fprintln(w, "type", name, "struct {")
+
+ // maximum size for union
+ maxSize := getUnionSize(ctx.file, union)
+
+ // generate data field
+ fmt.Fprintf(w, "\t%s [%d]byte\n", unionDataField, maxSize)
+
+ // generate end of the struct
+ fmt.Fprintln(w, "}")
+
+ // generate name getter
+ generateTypeNameGetter(w, name, union.Name)
+
+ // generate getters for fields
+ for _, field := range union.Fields {
+ fieldType := convertToGoType(ctx.file, field.Type)
+ generateUnionGetterSetter(w, name, field.GoName, fieldType)
+ }
+
+ // generate union methods
+ //generateUnionMethods(w, name)
+
+ fmt.Fprintln(w)
+}
+
+func generateUnionGetterSetter(w io.Writer, structName string, getterField, getterStruct string) {
+ fmt.Fprintf(w, `
+func %[1]s%[2]s(a %[3]s) (u %[1]s) {
+ u.Set%[2]s(a)
+ return
+}
+func (u *%[1]s) Set%[2]s(a %[3]s) {
+ var b = new(bytes.Buffer)
+ if err := struc.Pack(b, &a); err != nil {
+ return
+ }
+ copy(u.%[4]s[:], b.Bytes())
+}
+func (u *%[1]s) Get%[2]s() (a %[3]s) {
+ var b = bytes.NewReader(u.%[4]s[:])
+ struc.Unpack(b, &a)
+ return
+}
+`, structName, getterField, getterStruct, unionDataField)
+}
+
+func generateMessage(ctx *GenFile, w io.Writer, msg *Message) {
+ name := msg.GoName
+
+ logf(" writing MESSAGE %q (%s) with %d fields", msg.Name, name, len(msg.Fields))
+
+ // generate struct comment
+ generateComment(ctx, w, name, msg.Name, "message")
+
+ // generate struct definition
+ fmt.Fprintf(w, "type %s struct {", name)
+
+ msgType := otherMessage
+ wasClientIndex := false
+
+ // generate struct fields
+ n := 0
+ for i, field := range msg.Fields {
+ if i == 1 {
+ if field.Name == clientIndexField {
+ // "client_index" as the second member,
+ // this might be an event message or a request
+ msgType = eventMessage
+ wasClientIndex = true
+ } else if field.Name == contextField {
+ // reply needs "context" as the second member
+ msgType = replyMessage
+ }
+ } else if i == 2 {
+ if wasClientIndex && field.Name == contextField {
+ // request needs "client_index" as the second member
+ // and "context" as the third member
+ msgType = requestMessage
+ }
+ }
+
+ // skip internal fields
+ switch strings.ToLower(field.Name) {
+ case /*crcField,*/ msgIdField:
+ continue
+ case clientIndexField, contextField:
+ if n == 0 {
+ continue
+ }
+ }
+ n++
+ if n == 1 {
+ fmt.Fprintln(w)
+ }
+
+ generateField(ctx, w, msg.Fields, i)
+ }
+
+ // generate end of the struct
+ fmt.Fprintln(w, "}")
+
+ // generate message methods
+ generateMessageResetMethod(w, name)
+ generateMessageNameGetter(w, name, msg.Name)
+ generateCrcGetter(w, name, msg.CRC)
+ generateMessageTypeGetter(w, name, msgType)
+ generateMessageSize(ctx, w, name, msg.Fields)
+ generateMessageMarshal(ctx, w, name, msg.Fields)
+ generateMessageUnmarshal(ctx, w, name, msg.Fields)
+
+ fmt.Fprintln(w)
+}
+
+func generateMessageSize(ctx *GenFile, w io.Writer, name string, fields []*Field) {
+ fmt.Fprintf(w, "func (m *%[1]s) Size() int {\n", name)
+
+ fmt.Fprintf(w, "\tif m == nil { return 0 }\n")
+ fmt.Fprintf(w, "\tvar size int\n")
+
+ encodeBaseType := func(typ, name string, length int, sizefrom string) bool {
+ t, ok := BaseTypeNames[typ]
+ if !ok {
+ return false
+ }
+
+ var s = BaseTypeSizes[t]
+ switch t {
+ case STRING:
+ if length > 0 {
+ s = length
+ fmt.Fprintf(w, "\tsize += %d\n", s)
+ } else {
+ s = 4
+ fmt.Fprintf(w, "\tsize += %d + len(%s)\n", s, name)
+ }
+ default:
+ if sizefrom != "" {
+ //fmt.Fprintf(w, "\tsize += %d * int(%s)\n", s, sizefrom)
+ fmt.Fprintf(w, "\tsize += %d * len(%s)\n", s, name)
+ } else {
+ if length > 0 {
+ s = BaseTypeSizes[t] * length
+ }
+ fmt.Fprintf(w, "\tsize += %d\n", s)
+ }
+ }
+
+ return true
+ }
+
+ lvl := 0
+ var encodeFields func(fields []*Field, parentName string)
+ encodeFields = func(fields []*Field, parentName string) {
+ lvl++
+ defer func() { lvl-- }()
+
+ n := 0
+ for _, field := range fields {
+ // skip internal fields
+ switch strings.ToLower(field.Name) {
+ case /*crcField,*/ msgIdField:
+ continue
+ case clientIndexField, contextField:
+ if n == 0 {
+ continue
+ }
+ }
+ n++
+
+ fieldName := field.GoName //camelCaseName(strings.TrimPrefix(field.Name, "_"))
+ name := fmt.Sprintf("%s.%s", parentName, fieldName)
+ sizeFrom := camelCaseName(strings.TrimPrefix(field.SizeFrom, "_"))
+ var sizeFromName string
+ if sizeFrom != "" {
+ sizeFromName = fmt.Sprintf("%s.%s", parentName, sizeFrom)
+ }
+
+ fmt.Fprintf(w, "\t// field[%d] %s\n", lvl, name)
+
+ if encodeBaseType(field.Type, name, field.Length, sizeFromName) {
+ continue
+ }
+
+ char := fmt.Sprintf("s%d", lvl)
+ index := fmt.Sprintf("j%d", lvl)
+
+ if field.Array {
+ if field.Length > 0 {
+ fmt.Fprintf(w, "\tfor %[2]s := 0; %[2]s < %[1]d; %[2]s ++ {\n", field.Length, index)
+ } else if field.SizeFrom != "" {
+ //fmt.Fprintf(w, "\tfor %[1]s := 0; %[1]s < int(%[2]s.%[3]s); %[1]s++ {\n", index, parentName, sizeFrom)
+ fmt.Fprintf(w, "\tfor %[1]s := 0; %[1]s < len(%[2]s); %[1]s++ {\n", index, name)
+ }
+
+ fmt.Fprintf(w, "\tvar %[1]s %[2]s\n_ = %[1]s\n", char, convertToGoType(ctx.file, field.Type))
+ fmt.Fprintf(w, "\tif %[1]s < len(%[2]s) { %[3]s = %[2]s[%[1]s] }\n", index, name, char)
+ name = char
+ }
+
+ if enum := getEnumByRef(ctx.file, field.Type); enum != nil {
+ if encodeBaseType(enum.Type, name, 0, "") {
+ } else {
+ fmt.Fprintf(w, "\t// ??? ENUM %s %s\n", name, enum.Type)
+ }
+ } else if alias := getAliasByRef(ctx.file, field.Type); alias != nil {
+ if encodeBaseType(alias.Type, name, alias.Length, "") {
+ } else if typ := getTypeByRef(ctx.file, alias.Type); typ != nil {
+ encodeFields(typ.Fields, name)
+ } else {
+ fmt.Fprintf(w, "\t// ??? ALIAS %s %s\n", name, alias.Type)
+ }
+ } else if typ := getTypeByRef(ctx.file, field.Type); typ != nil {
+ encodeFields(typ.Fields, name)
+ } else if union := getUnionByRef(ctx.file, field.Type); union != nil {
+ maxSize := getUnionSize(ctx.file, union)
+ fmt.Fprintf(w, "\tsize += %d\n", maxSize)
+ } else {
+ fmt.Fprintf(w, "\t// ??? buf[pos] = (%s)\n", name)
+ }
+
+ if field.Array {
+ fmt.Fprintf(w, "\t}\n")
+ }
+ }
+ }
+
+ encodeFields(fields, "m")
+
+ fmt.Fprintf(w, "return size\n")
+
+ fmt.Fprintf(w, "}\n")
+}
+
+func generateMessageMarshal(ctx *GenFile, w io.Writer, name string, fields []*Field) {
+ fmt.Fprintf(w, "func (m *%[1]s) Marshal(b []byte) ([]byte, error) {\n", name)
+
+ fmt.Fprintf(w, "\to := binary.BigEndian\n")
+ fmt.Fprintf(w, "\t_ = o\n")
+ fmt.Fprintf(w, "\tpos := 0\n")
+ fmt.Fprintf(w, "\t_ = pos\n")
+
+ var buf = new(strings.Builder)
+
+ encodeBaseType := func(typ, name string, length int, sizefrom string) bool {
+ t, ok := BaseTypeNames[typ]
+ if !ok {
+ return false
+ }
+
+ isArray := length > 0 || sizefrom != ""
+
+ switch t {
+ case I8, U8, I16, U16, I32, U32, I64, U64, F64:
+ if isArray {
+ if length != 0 {
+ fmt.Fprintf(buf, "\tfor i := 0; i < %d; i++ {\n", length)
+ } else if sizefrom != "" {
+ //fmt.Fprintf(buf, "\tfor i := 0; i < int(%s); i++ {\n", sizefrom)
+ fmt.Fprintf(buf, "\tfor i := 0; i < len(%s); i++ {\n", name)
+ }
+ }
+ }
+
+ switch t {
+ case I8, U8:
+ if isArray {
+ fmt.Fprintf(buf, "\tvar x uint8\n")
+ fmt.Fprintf(buf, "\tif i < len(%s) { x = uint8(%s[i]) }\n", name, name)
+ name = "x"
+ }
+ fmt.Fprintf(buf, "\tbuf[pos] = uint8(%s)\n", name)
+ fmt.Fprintf(buf, "\tpos += 1\n")
+ if isArray {
+ fmt.Fprintf(buf, "\t}\n")
+ }
+ case I16, U16:
+ if isArray {
+ fmt.Fprintf(buf, "\tvar x uint16\n")
+ fmt.Fprintf(buf, "\tif i < len(%s) { x = uint16(%s[i]) }\n", name, name)
+ name = "x"
+ }
+ fmt.Fprintf(buf, "\to.PutUint16(buf[pos:pos+2], uint16(%s))\n", name)
+ fmt.Fprintf(buf, "\tpos += 2\n")
+ if isArray {
+ fmt.Fprintf(buf, "\t}\n")
+ }
+ case I32, U32:
+ if isArray {
+ fmt.Fprintf(buf, "\tvar x uint32\n")
+ fmt.Fprintf(buf, "\tif i < len(%s) { x = uint32(%s[i]) }\n", name, name)
+ name = "x"
+ }
+ fmt.Fprintf(buf, "\to.PutUint32(buf[pos:pos+4], uint32(%s))\n", name)
+ fmt.Fprintf(buf, "\tpos += 4\n")
+ if isArray {
+ fmt.Fprintf(buf, "\t}\n")
+ }
+ case I64, U64:
+ if isArray {
+ fmt.Fprintf(buf, "\tvar x uint64\n")
+ fmt.Fprintf(buf, "\tif i < len(%s) { x = uint64(%s[i]) }\n", name, name)
+ name = "x"
+ }
+ fmt.Fprintf(buf, "\to.PutUint64(buf[pos:pos+8], uint64(%s))\n", name)
+ fmt.Fprintf(buf, "\tpos += 8\n")
+ if isArray {
+ fmt.Fprintf(buf, "\t}\n")
+ }
+ case F64:
+ if isArray {
+ fmt.Fprintf(buf, "\tvar x float64\n")
+ fmt.Fprintf(buf, "\tif i < len(%s) { x = float64(%s[i]) }\n", name, name)
+ name = "x"
+ }
+ fmt.Fprintf(buf, "\to.PutUint64(buf[pos:pos+8], math.Float64bits(float64(%s)))\n", name)
+ fmt.Fprintf(buf, "\tpos += 8\n")
+ if isArray {
+ fmt.Fprintf(buf, "\t}\n")
+ }
+ case BOOL:
+ fmt.Fprintf(buf, "\tif %s { buf[pos] = 1 }\n", name)
+ fmt.Fprintf(buf, "\tpos += 1\n")
+ case STRING:
+ if length != 0 {
+ fmt.Fprintf(buf, "\tcopy(buf[pos:pos+%d], %s)\n", length, name)
+ fmt.Fprintf(buf, "\tpos += %d\n", length)
+ } else {
+ fmt.Fprintf(buf, "\to.PutUint32(buf[pos:pos+4], uint32(len(%s)))\n", name)
+ fmt.Fprintf(buf, "\tpos += 4\n")
+ fmt.Fprintf(buf, "\tcopy(buf[pos:pos+len(%s)], %s[:])\n", name, name)
+ fmt.Fprintf(buf, "\tpos += len(%s)\n", name)
+ }
+ default:
+ fmt.Fprintf(buf, "\t// ??? %s %s\n", name, typ)
+ return false
+ }
+ return true
+ }
+
+ lvl := 0
+ var encodeFields func(fields []*Field, parentName string)
+ encodeFields = func(fields []*Field, parentName string) {
+ lvl++
+ defer func() { lvl-- }()
+
+ n := 0
+ for _, field := range fields {
+ // skip internal fields
+ switch strings.ToLower(field.Name) {
+ case /*crcField,*/ msgIdField:
+ continue
+ case clientIndexField, contextField:
+ if n == 0 {
+ continue
+ }
+ }
+ n++
+
+ getFieldName := func(name string) string {
+ fieldName := camelCaseName(strings.TrimPrefix(name, "_"))
+ return fmt.Sprintf("%s.%s", parentName, fieldName)
+ }
+
+ fieldName := camelCaseName(strings.TrimPrefix(field.Name, "_"))
+ name := fmt.Sprintf("%s.%s", parentName, fieldName)
+ sizeFrom := camelCaseName(strings.TrimPrefix(field.SizeFrom, "_"))
+ var sizeFromName string
+ if sizeFrom != "" {
+ sizeFromName = fmt.Sprintf("%s.%s", parentName, sizeFrom)
+ }
+
+ fmt.Fprintf(buf, "\t// field[%d] %s\n", lvl, name)
+
+ getSizeOfField := func() *Field {
+ for _, f := range fields {
+ if f.SizeFrom == field.Name {
+ return f
+ }
+ }
+ return nil
+ }
+ if f := getSizeOfField(); f != nil {
+ if encodeBaseType(field.Type, fmt.Sprintf("len(%s)", getFieldName(f.Name)), field.Length, "") {
+ continue
+ }
+ panic(fmt.Sprintf("failed to encode base type of sizefrom field: %s", field.Name))
+ }
+
+ if encodeBaseType(field.Type, name, field.Length, sizeFromName) {
+ continue
+ }
+
+ char := fmt.Sprintf("v%d", lvl)
+ index := fmt.Sprintf("j%d", lvl)
+
+ if field.Array {
+ if field.Length > 0 {
+ fmt.Fprintf(buf, "\tfor %[2]s := 0; %[2]s < %[1]d; %[2]s ++ {\n", field.Length, index)
+ } else if field.SizeFrom != "" {
+ //fmt.Fprintf(buf, "\tfor %[1]s := 0; %[1]s < int(%[2]s.%[3]s); %[1]s++ {\n", index, parentName, sizeFrom)
+ fmt.Fprintf(buf, "\tfor %[1]s := 0; %[1]s < len(%[2]s); %[1]s++ {\n", index, name)
+ }
+
+ fmt.Fprintf(buf, "\tvar %s %s\n", char, convertToGoType(ctx.file, field.Type))
+ fmt.Fprintf(buf, "\tif %[1]s < len(%[2]s) { %[3]s = %[2]s[%[1]s] }\n", index, name, char)
+ name = char
+ }
+
+ if enum := getEnumByRef(ctx.file, field.Type); enum != nil {
+ if encodeBaseType(enum.Type, name, 0, "") {
+ } else {
+ fmt.Fprintf(buf, "\t// ??? ENUM %s %s\n", name, enum.Type)
+ }
+ } else if alias := getAliasByRef(ctx.file, field.Type); alias != nil {
+ if encodeBaseType(alias.Type, name, alias.Length, "") {
+ } else if typ := getTypeByRef(ctx.file, alias.Type); typ != nil {
+ encodeFields(typ.Fields, name)
+ } else {
+ fmt.Fprintf(buf, "\t// ??? ALIAS %s %s\n", name, alias.Type)
+ }
+ } else if typ := getTypeByRef(ctx.file, field.Type); typ != nil {
+ encodeFields(typ.Fields, name)
+ } else if union := getUnionByRef(ctx.file, field.Type); union != nil {
+ maxSize := getUnionSize(ctx.file, union)
+ fmt.Fprintf(buf, "\tcopy(buf[pos:pos+%d], %s.%s[:])\n", maxSize, name, unionDataField)
+ fmt.Fprintf(buf, "\tpos += %d\n", maxSize)
+ } else {
+ fmt.Fprintf(buf, "\t// ??? buf[pos] = (%s)\n", name)
+ }
+
+ if field.Array {
+ fmt.Fprintf(buf, "\t}\n")
+ }
+ }
+ }
+
+ encodeFields(fields, "m")
+
+ fmt.Fprintf(w, "\tvar buf []byte\n")
+ fmt.Fprintf(w, "\tif b == nil {\n")
+ fmt.Fprintf(w, "\tbuf = make([]byte, m.Size())\n")
+ fmt.Fprintf(w, "\t} else {\n")
+ fmt.Fprintf(w, "\tbuf = b\n")
+ fmt.Fprintf(w, "\t}\n")
+ fmt.Fprint(w, buf.String())
+
+ fmt.Fprintf(w, "return buf, nil\n")
+
+ fmt.Fprintf(w, "}\n")
+}
+
+func generateMessageUnmarshal(ctx *GenFile, w io.Writer, name string, fields []*Field) {
+ fmt.Fprintf(w, "func (m *%[1]s) Unmarshal(tmp []byte) error {\n", name)
+
+ fmt.Fprintf(w, "\to := binary.BigEndian\n")
+ fmt.Fprintf(w, "\t_ = o\n")
+ fmt.Fprintf(w, "\tpos := 0\n")
+ fmt.Fprintf(w, "\t_ = pos\n")
+
+ decodeBaseType := func(typ, orig, name string, length int, sizefrom string, alloc bool) bool {
+ t, ok := BaseTypeNames[typ]
+ if !ok {
+ return false
+ }
+
+ isArray := length > 0 || sizefrom != ""
+
+ switch t {
+ case I8, U8, I16, U16, I32, U32, I64, U64, F64:
+ if isArray {
+ if alloc {
+ if length != 0 {
+ fmt.Fprintf(w, "\t%s = make([]%s, %d)\n", name, orig, length)
+ } else if sizefrom != "" {
+ fmt.Fprintf(w, "\t%s = make([]%s, %s)\n", name, orig, sizefrom)
+ }
+ }
+ fmt.Fprintf(w, "\tfor i := 0; i < len(%s); i++ {\n", name)
+ }
+ }
+
+ switch t {
+ case I8, U8:
+ if isArray {
+ fmt.Fprintf(w, "\t%s[i] = %s(tmp[pos])\n", name, convertToGoType(ctx.file, typ))
+ } else {
+ fmt.Fprintf(w, "\t%s = %s(tmp[pos])\n", name, orig)
+ }
+ fmt.Fprintf(w, "\tpos += 1\n")
+ if isArray {
+ fmt.Fprintf(w, "\t}\n")
+ }
+ case I16, U16:
+ if isArray {
+ fmt.Fprintf(w, "\t%s[i] = %s(o.Uint16(tmp[pos:pos+2]))\n", name, orig)
+ } else {
+ fmt.Fprintf(w, "\t%s = %s(o.Uint16(tmp[pos:pos+2]))\n", name, orig)
+ }
+ fmt.Fprintf(w, "\tpos += 2\n")
+ if isArray {
+ fmt.Fprintf(w, "\t}\n")
+ }
+ case I32, U32:
+ if isArray {
+ fmt.Fprintf(w, "\t%s[i] = %s(o.Uint32(tmp[pos:pos+4]))\n", name, orig)
+ } else {
+ fmt.Fprintf(w, "\t%s = %s(o.Uint32(tmp[pos:pos+4]))\n", name, orig)
+ }
+ fmt.Fprintf(w, "\tpos += 4\n")
+ if isArray {
+ fmt.Fprintf(w, "\t}\n")
+ }
+ case I64, U64:
+ if isArray {
+ fmt.Fprintf(w, "\t%s[i] = %s(o.Uint64(tmp[pos:pos+8]))\n", name, orig)
+ } else {
+ fmt.Fprintf(w, "\t%s = %s(o.Uint64(tmp[pos:pos+8]))\n", name, orig)
+ }
+ fmt.Fprintf(w, "\tpos += 8\n")
+ if isArray {
+ fmt.Fprintf(w, "\t}\n")
+ }
+ case F64:
+ if isArray {
+ fmt.Fprintf(w, "\t%s[i] = %s(math.Float64frombits(o.Uint64(tmp[pos:pos+8])))\n", name, orig)
+ } else {
+ fmt.Fprintf(w, "\t%s = %s(math.Float64frombits(o.Uint64(tmp[pos:pos+8])))\n", name, orig)
+ }
+ fmt.Fprintf(w, "\tpos += 8\n")
+ if isArray {
+ fmt.Fprintf(w, "\t}\n")
+ }
+ case BOOL:
+ fmt.Fprintf(w, "\t%s = tmp[pos] != 0\n", name)
+ fmt.Fprintf(w, "\tpos += 1\n")
+ case STRING:
+ if length != 0 {
+ fmt.Fprintf(w, "\t{\n")
+ fmt.Fprintf(w, "\tnul := bytes.Index(tmp[pos:pos+%d], []byte{0x00})\n", length)
+ fmt.Fprintf(w, "\t%[1]s = codec.DecodeString(tmp[pos:pos+nul])\n", name)
+ fmt.Fprintf(w, "\tpos += %d\n", length)
+ fmt.Fprintf(w, "\t}\n")
+ } else {
+ fmt.Fprintf(w, "\t{\n")
+ fmt.Fprintf(w, "\tsiz := o.Uint32(tmp[pos:pos+4])\n")
+ fmt.Fprintf(w, "\tpos += 4\n")
+ fmt.Fprintf(w, "\t%[1]s = codec.DecodeString(tmp[pos:pos+int(siz)])\n", name)
+ fmt.Fprintf(w, "\tpos += len(%s)\n", name)
+ fmt.Fprintf(w, "\t}\n")
+ }
+ default:
+ fmt.Fprintf(w, "\t// ??? %s %s\n", name, typ)
+ return false
+ }
+ return true
+ }
+
+ lvl := 0
+ var decodeFields func(fields []*Field, parentName string)
+ decodeFields = func(fields []*Field, parentName string) {
+ lvl++
+ defer func() { lvl-- }()
+
+ n := 0
+ for _, field := range fields {
+ // skip internal fields
+ switch strings.ToLower(field.Name) {
+ case /*crcField,*/ msgIdField:
+ continue
+ case clientIndexField, contextField:
+ if n == 0 {
+ continue
+ }
+ }
+ n++
+
+ fieldName := camelCaseName(strings.TrimPrefix(field.Name, "_"))
+ name := fmt.Sprintf("%s.%s", parentName, fieldName)
+ sizeFrom := camelCaseName(strings.TrimPrefix(field.SizeFrom, "_"))
+ var sizeFromName string
+ if sizeFrom != "" {
+ sizeFromName = fmt.Sprintf("%s.%s", parentName, sizeFrom)
+ }
+
+ fmt.Fprintf(w, "\t// field[%d] %s\n", lvl, name)
+
+ if decodeBaseType(field.Type, convertToGoType(ctx.file, field.Type), name, field.Length, sizeFromName, true) {
+ continue
+ }
+
+ //char := fmt.Sprintf("v%d", lvl)
+ index := fmt.Sprintf("j%d", lvl)
+
+ if field.Array {
+ if field.Length > 0 {
+ fmt.Fprintf(w, "\tfor %[2]s := 0; %[2]s < %[1]d; %[2]s ++ {\n", field.Length, index)
+ } else if field.SizeFrom != "" {
+ fieldType := getFieldType(ctx, field)
+ if strings.HasPrefix(fieldType, "[]") {
+ fmt.Fprintf(w, "\t%s = make(%s, int(%s.%s))\n", name, fieldType, parentName, sizeFrom)
+ }
+ fmt.Fprintf(w, "\tfor %[1]s := 0; %[1]s < int(%[2]s.%[3]s); %[1]s++ {\n", index, parentName, sizeFrom)
+ }
+
+ /*fmt.Fprintf(w, "\tvar %s %s\n", char, convertToGoType(ctx, field.Type))
+ fmt.Fprintf(w, "\tif %[1]s < len(%[2]s) { %[3]s = %[2]s[%[1]s] }\n", index, name, char)
+ name = char*/
+ name = fmt.Sprintf("%s[%s]", name, index)
+ }
+
+ if enum := getEnumByRef(ctx.file, field.Type); enum != nil {
+ if decodeBaseType(enum.Type, convertToGoType(ctx.file, field.Type), name, 0, "", false) {
+ } else {
+ fmt.Fprintf(w, "\t// ??? ENUM %s %s\n", name, enum.Type)
+ }
+ } else if alias := getAliasByRef(ctx.file, field.Type); alias != nil {
+ if decodeBaseType(alias.Type, convertToGoType(ctx.file, field.Type), name, alias.Length, "", false) {
+ } else if typ := getTypeByRef(ctx.file, alias.Type); typ != nil {
+ decodeFields(typ.Fields, name)
+ } else {
+ fmt.Fprintf(w, "\t// ??? ALIAS %s %s\n", name, alias.Type)
+ }
+ } else if typ := getTypeByRef(ctx.file, field.Type); typ != nil {
+ decodeFields(typ.Fields, name)
+ } else if union := getUnionByRef(ctx.file, field.Type); union != nil {
+ maxSize := getUnionSize(ctx.file, union)
+ fmt.Fprintf(w, "\tcopy(%s.%s[:], tmp[pos:pos+%d])\n", name, unionDataField, maxSize)
+ fmt.Fprintf(w, "\tpos += %d\n", maxSize)
+ } else {
+ fmt.Fprintf(w, "\t// ??? buf[pos] = (%s)\n", name)
+ }
+
+ if field.Array {
+ fmt.Fprintf(w, "\t}\n")
+ }
+ }
+ }
+
+ decodeFields(fields, "m")
+
+ fmt.Fprintf(w, "return nil\n")
+
+ fmt.Fprintf(w, "}\n")
+}
+
+func getFieldType(ctx *GenFile, field *Field) string {
+ //fieldName := strings.TrimPrefix(field.Name, "_")
+ //fieldName = camelCaseName(fieldName)
+ //fieldName := field.GoName
+
+ dataType := convertToGoType(ctx.file, field.Type)
+ fieldType := dataType
+
+ // check if it is array
+ if field.Length > 0 || field.SizeFrom != "" {
+ if dataType == "uint8" {
+ dataType = "byte"
+ }
+ if dataType == "string" && field.Array {
+ fieldType = "string"
+ dataType = "byte"
+ } else if _, ok := BaseTypeNames[field.Type]; !ok && field.SizeFrom == "" {
+ fieldType = fmt.Sprintf("[%d]%s", field.Length, dataType)
+ } else {
+ fieldType = "[]" + dataType
+ }
+ }
+
+ return fieldType
+}
+
+func generateField(ctx *GenFile, w io.Writer, fields []*Field, i int) {
+ field := fields[i]
+
+ //fieldName := strings.TrimPrefix(field.Name, "_")
+ //fieldName = camelCaseName(fieldName)
+ fieldName := field.GoName
+
+ dataType := convertToGoType(ctx.file, field.Type)
+ fieldType := dataType
+
+ // generate length field for strings
+ if field.Type == "string" && field.Length == 0 {
+ fmt.Fprintf(w, "\tXXX_%sLen uint32 `struc:\"sizeof=%s\"`\n", fieldName, fieldName)
+ }
+
+ // check if it is array
+ if field.Length > 0 || field.SizeFrom != "" {
+ if dataType == "uint8" {
+ dataType = "byte"
+ }
+ if dataType == "string" && field.Array {
+ fieldType = "string"
+ dataType = "byte"
+ } else if _, ok := BaseTypeNames[field.Type]; !ok && field.SizeFrom == "" {
+ fieldType = fmt.Sprintf("[%d]%s", field.Length, dataType)
+ } else {
+ fieldType = "[]" + dataType
+ }
+ }
+ fmt.Fprintf(w, "\t%s %s", fieldName, fieldType)
+
+ fieldTags := map[string]string{}
+
+ if field.Length > 0 && field.Array {
+ // fixed size array
+ fieldTags["struc"] = fmt.Sprintf("[%d]%s", field.Length, dataType)
+ } else {
+ for _, f := range fields {
+ if f.SizeFrom == field.Name {
+ // variable sized array
+ //sizeOfName := camelCaseName(f.Name)
+ fieldTags["struc"] = fmt.Sprintf("sizeof=%s", f.GoName)
+ }
+ }
+ }
+
+ if ctx.IncludeBinapiNames {
+ typ := fromApiType(field.Type)
+ if field.Array {
+ if field.Length > 0 {
+ fieldTags["binapi"] = fmt.Sprintf("%s[%d],name=%s", typ, field.Length, field.Name)
+ } else if field.SizeFrom != "" {
+ fieldTags["binapi"] = fmt.Sprintf("%s[%s],name=%s", typ, field.SizeFrom, field.Name)
+ }
+ } else {
+ fieldTags["binapi"] = fmt.Sprintf("%s,name=%s", typ, field.Name)
+ }
+ }
+ if limit, ok := field.Meta["limit"]; ok && limit.(int) > 0 {
+ fieldTags["binapi"] = fmt.Sprintf("%s,limit=%d", fieldTags["binapi"], limit)
+ }
+ if def, ok := field.Meta["default"]; ok && def != nil {
+ actual := getActualType(ctx.file, fieldType)
+ if t, ok := binapiTypes[actual]; ok && t != "float64" {
+ defnum := int(def.(float64))
+ fieldTags["binapi"] = fmt.Sprintf("%s,default=%d", fieldTags["binapi"], defnum)
+ } else {
+ fieldTags["binapi"] = fmt.Sprintf("%s,default=%v", fieldTags["binapi"], def)
+ }
+ }
+
+ fieldTags["json"] = fmt.Sprintf("%s,omitempty", field.Name)
+
+ if len(fieldTags) > 0 {
+ fmt.Fprintf(w, "\t`")
+ var keys []string
+ for k := range fieldTags {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+ var n int
+ for _, tt := range keys {
+ t, ok := fieldTags[tt]
+ if !ok {
+ continue
+ }
+ if n > 0 {
+ fmt.Fprintf(w, " ")
+ }
+ n++
+ fmt.Fprintf(w, `%s:"%s"`, tt, t)
+ }
+ fmt.Fprintf(w, "`")
+ }
+
+ fmt.Fprintln(w)
+}
+
+func generateMessageResetMethod(w io.Writer, structName string) {
+ fmt.Fprintf(w, "func (m *%[1]s) Reset() { *m = %[1]s{} }\n", structName)
+}
+
+func generateMessageNameGetter(w io.Writer, structName, msgName string) {
+ fmt.Fprintf(w, "func (*%s) GetMessageName() string { return %q }\n", structName, msgName)
+}
+
+func generateTypeNameGetter(w io.Writer, structName, msgName string) {
+ fmt.Fprintf(w, "func (*%s) GetTypeName() string { return %q }\n", structName, msgName)
+}
+
+func generateCrcGetter(w io.Writer, structName, crc string) {
+ crc = strings.TrimPrefix(crc, "0x")
+ fmt.Fprintf(w, "func (*%s) GetCrcString() string { return %q }\n", structName, crc)
+}
+
+func generateMessageTypeGetter(w io.Writer, structName string, msgType MessageType) {
+ fmt.Fprintf(w, "func (*"+structName+") GetMessageType() api.MessageType {")
+ if msgType == requestMessage {
+ fmt.Fprintf(w, "\treturn api.RequestMessage")
+ } else if msgType == replyMessage {
+ fmt.Fprintf(w, "\treturn api.ReplyMessage")
+ } else if msgType == eventMessage {
+ fmt.Fprintf(w, "\treturn api.EventMessage")
+ } else {
+ fmt.Fprintf(w, "\treturn api.OtherMessage")
+ }
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)
+}
diff --git a/binapigen/generate_rpc.go b/binapigen/generate_rpc.go
new file mode 100644
index 0000000..b480f4a
--- /dev/null
+++ b/binapigen/generate_rpc.go
@@ -0,0 +1,188 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package binapigen
+
+import (
+ "fmt"
+ "io"
+ "strings"
+)
+
+func generatePackageRPC(ctx *GenFile, w io.Writer) {
+ logf("----------------------------")
+ logf("generating RPC package: %q", ctx.file.PackageName)
+ logf("----------------------------")
+
+ fmt.Fprintln(w, "// Code generated by GoVPP's binapi-generator. DO NOT EDIT.")
+ fmt.Fprintln(w)
+
+ fmt.Fprintf(w, "package %s\n", ctx.file.PackageName)
+ fmt.Fprintln(w)
+
+ fmt.Fprintln(w, "import (")
+ fmt.Fprintln(w, ` "context"`)
+ fmt.Fprintln(w, ` "io"`)
+ fmt.Fprintln(w)
+ fmt.Fprintf(w, "\tapi \"%s\"\n", "git.fd.io/govpp.git/api")
+ fmt.Fprintln(w, ")")
+ fmt.Fprintln(w)
+
+ // generate services
+ if ctx.file.Service != nil && len(ctx.file.Service.RPCs) > 0 {
+ generateServiceMethods(ctx, w, ctx.file.Service.RPCs)
+ }
+
+ // generate message registrations
+ /*fmt.Fprintln(w, "var _RPCService_desc = api.RPCDesc{")
+
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)*/
+
+ fmt.Fprintf(w, "// Reference imports to suppress errors if they are not otherwise used.\n")
+ fmt.Fprintf(w, "var _ = api.RegisterMessage\n")
+ fmt.Fprintf(w, "var _ = context.Background\n")
+ fmt.Fprintf(w, "var _ = io.Copy\n")
+
+}
+
+func generateServiceMethods(ctx *GenFile, w io.Writer, methods []RPC) {
+ // generate services comment
+ generateComment(ctx, w, serviceApiName, "services", "service")
+
+ // generate service api
+ fmt.Fprintf(w, "type %s interface {\n", serviceApiName)
+ for _, svc := range methods {
+ generateServiceMethod(ctx, w, &svc)
+ fmt.Fprintln(w)
+ }
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)
+
+ // generate client implementation
+ fmt.Fprintf(w, "type %s struct {\n", serviceImplName)
+ fmt.Fprintf(w, "\tch api.Channel\n")
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)
+
+ // generate client constructor
+ fmt.Fprintf(w, "func New%s(ch api.Channel) %s {\n", serviceClientName, serviceApiName)
+ fmt.Fprintf(w, "\treturn &%s{ch}\n", serviceImplName)
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)
+
+ for _, met := range methods {
+ method := camelCaseName(met.RequestMsg)
+ if m := strings.TrimSuffix(method, "Dump"); method != m {
+ method = "Dump" + m
+ }
+
+ fmt.Fprintf(w, "func (c *%s) ", serviceImplName)
+ generateServiceMethod(ctx, w, &met)
+ fmt.Fprintln(w, " {")
+ if met.Stream {
+ streamImpl := fmt.Sprintf("%s_%sClient", serviceImplName, method)
+ fmt.Fprintf(w, "\tstream := c.ch.SendMultiRequest(in)\n")
+ fmt.Fprintf(w, "\tx := &%s{stream}\n", streamImpl)
+ fmt.Fprintf(w, "\treturn x, nil\n")
+ } else if replyTyp := camelCaseName(met.ReplyMsg); replyTyp != "" {
+ fmt.Fprintf(w, "\tout := new(%s)\n", replyTyp)
+ fmt.Fprintf(w, "\terr:= c.ch.SendRequest(in).ReceiveReply(out)\n")
+ fmt.Fprintf(w, "\tif err != nil { return nil, err }\n")
+ fmt.Fprintf(w, "\treturn out, nil\n")
+ } else {
+ fmt.Fprintf(w, "\tc.ch.SendRequest(in)\n")
+ fmt.Fprintf(w, "\treturn nil\n")
+ }
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)
+
+ if met.Stream {
+ replyTyp := camelCaseName(met.ReplyMsg)
+ method := camelCaseName(met.RequestMsg)
+ if m := strings.TrimSuffix(method, "Dump"); method != m {
+ method = "Dump" + m
+ }
+ streamApi := fmt.Sprintf("%s_%sClient", serviceApiName, method)
+
+ fmt.Fprintf(w, "type %s interface {\n", streamApi)
+ fmt.Fprintf(w, "\tRecv() (*%s, error)\n", replyTyp)
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)
+
+ streamImpl := fmt.Sprintf("%s_%sClient", serviceImplName, method)
+ fmt.Fprintf(w, "type %s struct {\n", streamImpl)
+ fmt.Fprintf(w, "\tapi.MultiRequestCtx\n")
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)
+
+ fmt.Fprintf(w, "func (c *%s) Recv() (*%s, error) {\n", streamImpl, replyTyp)
+ fmt.Fprintf(w, "\tm := new(%s)\n", replyTyp)
+ fmt.Fprintf(w, "\tstop, err := c.MultiRequestCtx.ReceiveReply(m)\n")
+ fmt.Fprintf(w, "\tif err != nil { return nil, err }\n")
+ fmt.Fprintf(w, "\tif stop { return nil, io.EOF }\n")
+ fmt.Fprintf(w, "\treturn m, nil\n")
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w)
+ }
+ }
+
+ // TODO: generate service descriptor
+ /*fmt.Fprintf(w, "var %s = api.%s{\n", serviceDescName, serviceDescType)
+ fmt.Fprintf(w, "\tServiceName: \"%s\",\n", ctx.moduleName)
+ fmt.Fprintf(w, "\tHandlerType: (*%s)(nil),\n", serviceApiName)
+ fmt.Fprintf(w, "\tMethods: []api.MethodDesc{\n")
+ for _, method := range methods {
+ fmt.Fprintf(w, "\t {\n")
+ fmt.Fprintf(w, "\t MethodName: \"%s\",\n", method.Name)
+ fmt.Fprintf(w, "\t },\n")
+ }
+ fmt.Fprintf(w, "\t},\n")
+ //fmt.Fprintf(w, "\tCompatibility: %s,\n", messageCrcName)
+ //fmt.Fprintf(w, "\tMetadata: reflect.TypeOf((*%s)(nil)).Elem().PkgPath(),\n", serviceApiName)
+ fmt.Fprintf(w, "\tMetadata: \"%s\",\n", ctx.inputFile)
+ fmt.Fprintln(w, "}")*/
+
+ fmt.Fprintln(w)
+}
+
+func generateServiceMethod(ctx *GenFile, w io.Writer, rpc *RPC) {
+ reqTyp := camelCaseName(rpc.RequestMsg)
+
+ logf(" writing RPC: %+v", reqTyp)
+
+ // method name is same as parameter type name by default
+ method := reqTyp
+ if rpc.Stream {
+ // use Dump as prefix instead of suffix for stream services
+ if m := strings.TrimSuffix(method, "Dump"); method != m {
+ method = "Dump" + m
+ }
+ }
+
+ params := fmt.Sprintf("in *%s", reqTyp)
+ returns := "error"
+
+ if replyType := camelCaseName(rpc.ReplyMsg); replyType != "" {
+ var replyTyp string
+ if rpc.Stream {
+ replyTyp = fmt.Sprintf("%s_%sClient", serviceApiName, method)
+ } else {
+ replyTyp = fmt.Sprintf("*%s", replyType)
+ }
+ returns = fmt.Sprintf("(%s, error)", replyTyp)
+ }
+
+ fmt.Fprintf(w, "\t%s(ctx context.Context, %s) %s", method, params, returns)
+}
diff --git a/cmd/binapi-generator/generate_test.go b/binapigen/generate_test.go
index 4bec874..5a2a07a 100644
--- a/cmd/binapi-generator/generate_test.go
+++ b/binapigen/generate_test.go
@@ -1,53 +1,67 @@
-// Copyright (c) 2017 Cisco and/or its affiliates.
+// Copyright (c) 2020 Cisco and/or its affiliates.
//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at:
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
-package main
+package binapigen
import (
- "bufio"
- "io/ioutil"
"os"
"testing"
. "github.com/onsi/gomega"
+
+ "git.fd.io/govpp.git/binapigen/vppapi"
)
-func TestGetInputFiles(t *testing.T) {
- RegisterTestingT(t)
- result, err := getInputFiles("testdata", 1)
- Expect(err).ShouldNot(HaveOccurred())
- Expect(result).To(HaveLen(3))
- for _, file := range result {
- Expect(file).To(BeAnExistingFile())
+const testOutputDir = "test_output_directory"
+
+func GenerateFromFile(apiDir, outputDir string, opts Options) error {
+ // parse API files
+ apifiles, err := vppapi.ParseDir(apiDir)
+ if err != nil {
+ return err
}
-}
-func TestGetInputFilesError(t *testing.T) {
- RegisterTestingT(t)
- result, err := getInputFiles("nonexisting_directory", 1)
- Expect(err).Should(HaveOccurred())
- Expect(result).To(BeNil())
+ g, err := New(opts, apifiles)
+ if err != nil {
+ return err
+ }
+ for _, file := range g.Files {
+ if !file.Generate {
+ continue
+ }
+ GenerateBinapiFile(g, file, outputDir)
+ if file.Service != nil {
+ GenerateRPC(g, file, outputDir)
+ }
+ }
+
+ if err = g.Generate(); err != nil {
+ return err
+ }
+
+ return nil
}
func TestGenerateFromFile(t *testing.T) {
RegisterTestingT(t)
- outDir := "test_output_directory"
+
// remove directory created during test
- defer os.RemoveAll(outDir)
- err := generateFromFile("testdata/acl.api.json", outDir, nil)
+ defer os.RemoveAll(testOutputDir)
+
+ err := GenerateFromFile("testdata/acl.api.json", testOutputDir, Options{})
Expect(err).ShouldNot(HaveOccurred())
- fileInfo, err := os.Stat(outDir + "/acl/acl.ba.go")
+ fileInfo, err := os.Stat(testOutputDir + "/acl/acl.ba.go")
Expect(err).ShouldNot(HaveOccurred())
Expect(fileInfo.IsDir()).To(BeFalse())
Expect(fileInfo.Name()).To(BeEquivalentTo("acl.ba.go"))
@@ -55,35 +69,36 @@ func TestGenerateFromFile(t *testing.T) {
func TestGenerateFromFileInputError(t *testing.T) {
RegisterTestingT(t)
- outDir := "test_output_directory"
- err := generateFromFile("testdata/nonexisting.json", outDir, nil)
+
+ err := GenerateFromFile("testdata/nonexisting.json", testOutputDir, Options{})
Expect(err).Should(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("invalid input file name"))
}
func TestGenerateFromFileReadJsonError(t *testing.T) {
RegisterTestingT(t)
- outDir := "test_output_directory"
- err := generateFromFile("testdata/input-read-json-error.json", outDir, nil)
+
+ err := GenerateFromFile("testdata/input-read-json-error.json", testOutputDir, Options{})
Expect(err).Should(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("invalid input file name"))
}
func TestGenerateFromFileGeneratePackageError(t *testing.T) {
RegisterTestingT(t)
- outDir := "test_output_directory"
+
// generate package throws panic, recover after it
defer func() {
if recovery := recover(); recovery != nil {
t.Logf("Recovered from panic: %v", recovery)
}
- os.RemoveAll(outDir)
+ os.RemoveAll(testOutputDir)
}()
- err := generateFromFile("testdata/input-generate-error.json", outDir, nil)
+
+ err := GenerateFromFile("testdata/input-generate-error.json", testOutputDir, Options{})
Expect(err).Should(HaveOccurred())
}
-func TestGetContext(t *testing.T) {
+/*func TestGetContext(t *testing.T) {
RegisterTestingT(t)
outDir := "test_output_directory"
result, err := newContext("testdata/af_packet.api.json", outDir)
@@ -109,31 +124,12 @@ func TestGetContextInterfaceJson(t *testing.T) {
Expect(result).ToNot(BeNil())
Expect(result.outputFile)
Expect(result.outputFile).To(BeEquivalentTo(outDir + "/ip/ip.ba.go"))
-}
+}*/
-func TestReadJson(t *testing.T) {
- RegisterTestingT(t)
- inputData, err := ioutil.ReadFile("testdata/af_packet.api.json")
- Expect(err).ShouldNot(HaveOccurred())
- result, err := parseInputJSON(inputData)
- Expect(err).ShouldNot(HaveOccurred())
- Expect(result).ToNot(BeNil())
- Expect(result.Len()).To(BeEquivalentTo(5))
-}
-
-func TestReadJsonError(t *testing.T) {
- RegisterTestingT(t)
- inputData, err := ioutil.ReadFile("testdata/input-read-json-error.json")
- Expect(err).ShouldNot(HaveOccurred())
- result, err := parseInputJSON(inputData)
- Expect(err).Should(HaveOccurred())
- Expect(result).To(BeNil())
-}
-
-func TestGeneratePackage(t *testing.T) {
+/*func TestGeneratePackage(t *testing.T) {
RegisterTestingT(t)
// prepare context
- testCtx := new(context)
+ testCtx := new(GenFile)
testCtx.packageName = "test-package-name"
// prepare input/output output files
@@ -141,7 +137,7 @@ func TestGeneratePackage(t *testing.T) {
Expect(err).ShouldNot(HaveOccurred())
jsonRoot, err := parseInputJSON(inputData)
Expect(err).ShouldNot(HaveOccurred())
- testCtx.packageData, err = parsePackage(testCtx, jsonRoot)
+ testCtx.file, err = parseModule(testCtx, jsonRoot)
Expect(err).ShouldNot(HaveOccurred())
outDir := "test_output_directory"
outFile, err := os.Create(outDir)
@@ -158,7 +154,7 @@ func TestGeneratePackage(t *testing.T) {
func TestGenerateMessageType(t *testing.T) {
RegisterTestingT(t)
// prepare context
- testCtx := new(context)
+ testCtx := new(GenFile)
testCtx.packageName = "test-package-name"
// prepare input/output output files
@@ -169,18 +165,18 @@ func TestGenerateMessageType(t *testing.T) {
outDir := "test_output_directory"
outFile, err := os.Create(outDir)
Expect(err).ShouldNot(HaveOccurred())
- testCtx.packageData, err = parsePackage(testCtx, jsonRoot)
+ testCtx.file, err = parseModule(testCtx, jsonRoot)
Expect(err).ShouldNot(HaveOccurred())
defer os.RemoveAll(outDir)
// prepare writer
writer := bufio.NewWriter(outFile)
- for _, msg := range testCtx.packageData.Messages {
+ for _, msg := range testCtx.file.Messages {
generateMessage(testCtx, writer, &msg)
Expect(writer.Buffered()).ToNot(BeZero())
}
-}
+}*/
/*func TestGenerateMessageName(t *testing.T) {
RegisterTestingT(t)
diff --git a/binapigen/generator.go b/binapigen/generator.go
new file mode 100644
index 0000000..9471462
--- /dev/null
+++ b/binapigen/generator.go
@@ -0,0 +1,172 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package binapigen
+
+import (
+ "bytes"
+ "fmt"
+ "go/format"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+
+ "github.com/sirupsen/logrus"
+
+ "git.fd.io/govpp.git/binapigen/vppapi"
+)
+
+type Options struct {
+ VPPVersion string // version of VPP that produced API files
+
+ FilesToGenerate []string // list of API files to generate
+
+ ImportPrefix string // defines import path prefix for importing types
+ ImportTypes bool // generate packages for import types
+ IncludeAPIVersion bool // include constant with API version string
+ IncludeComments bool // include parts of original source in comments
+ IncludeBinapiNames bool // include binary API names as struct tag
+ IncludeServices bool // include service interface with client implementation
+ IncludeVppVersion bool // include info about used VPP version
+}
+
+type Generator struct {
+ Options
+
+ Files []*File
+ FilesByPath map[string]*File
+ FilesByName map[string]*File
+
+ enumsByName map[string]*Enum
+ aliasesByName map[string]*Alias
+ structsByName map[string]*Struct
+ unionsByName map[string]*Union
+
+ genfiles []*GenFile
+}
+
+func New(opts Options, apifiles []*vppapi.File) (*Generator, error) {
+ g := &Generator{
+ Options: opts,
+ FilesByPath: make(map[string]*File),
+ FilesByName: make(map[string]*File),
+ enumsByName: map[string]*Enum{},
+ aliasesByName: map[string]*Alias{},
+ structsByName: map[string]*Struct{},
+ unionsByName: map[string]*Union{},
+ }
+
+ logrus.Debugf("adding %d VPP API files to generator", len(apifiles))
+ for _, apifile := range apifiles {
+ filename := apifile.Path
+ if filename == "" {
+ filename = apifile.Name
+ }
+ if _, ok := g.FilesByPath[filename]; ok {
+ return nil, fmt.Errorf("duplicate file name: %q", filename)
+ }
+ if _, ok := g.FilesByName[apifile.Name]; ok {
+ return nil, fmt.Errorf("duplicate file: %q", apifile.Name)
+ }
+
+ file, err := newFile(g, apifile)
+ if err != nil {
+ return nil, err
+ }
+ g.Files = append(g.Files, file)
+ g.FilesByPath[filename] = file
+ g.FilesByName[apifile.Name] = file
+
+ logrus.Debugf("added file %q (path: %v)", apifile.Name, apifile.Path)
+ if len(file.Imports) > 0 {
+ logrus.Debugf(" - %d imports: %v", len(file.Imports), file.Imports)
+ }
+ }
+
+ logrus.Debugf("Checking %d files to generate: %v", len(opts.FilesToGenerate), opts.FilesToGenerate)
+ for _, genfile := range opts.FilesToGenerate {
+ file, ok := g.FilesByPath[genfile]
+ if !ok {
+ file, ok = g.FilesByName[genfile]
+ if !ok {
+ return nil, fmt.Errorf("no API file found for: %v", genfile)
+ }
+ }
+ file.Generate = true
+ if opts.ImportTypes {
+ for _, impFile := range file.importedFiles(g) {
+ impFile.Generate = true
+ }
+ }
+ }
+
+ logrus.Debugf("Resolving imported types")
+ for _, file := range g.Files {
+ if !file.Generate {
+ continue
+ }
+ importedFiles := file.importedFiles(g)
+ file.loadTypeImports(g, importedFiles)
+ }
+
+ return g, nil
+}
+
+func (g *Generator) Generate() error {
+ if len(g.genfiles) == 0 {
+ return fmt.Errorf("no files to generate")
+ }
+
+ logrus.Infof("Generating %d files", len(g.genfiles))
+ for _, genfile := range g.genfiles {
+ if err := writeSourceTo(genfile.filename, genfile.buf.Bytes()); err != nil {
+ return fmt.Errorf("writing source for RPC package %s failed: %v", genfile.filename, err)
+ }
+ }
+ return nil
+}
+
+func (g *Generator) NewGenFile(filename string) *GenFile {
+ f := &GenFile{
+ Generator: g,
+ filename: filename,
+ }
+ g.genfiles = append(g.genfiles, f)
+ return f
+}
+
+func writeSourceTo(outputFile string, b []byte) error {
+ // create output directory
+ packageDir := filepath.Dir(outputFile)
+ if err := os.MkdirAll(packageDir, 0775); err != nil {
+ return fmt.Errorf("creating output dir %s failed: %v", packageDir, err)
+ }
+
+ // format generated source code
+ gosrc, err := format.Source(b)
+ if err != nil {
+ _ = ioutil.WriteFile(outputFile, b, 0666)
+ return fmt.Errorf("formatting source code failed: %v", err)
+ }
+
+ // write generated code to output file
+ if err := ioutil.WriteFile(outputFile, gosrc, 0666); err != nil {
+ return fmt.Errorf("writing to output file %s failed: %v", outputFile, err)
+ }
+
+ lines := bytes.Count(gosrc, []byte("\n"))
+ logf("wrote %d lines (%d bytes) of code to: %q", lines, len(gosrc), outputFile)
+
+ return nil
+}
diff --git a/cmd/binapi-generator/parse_test.go b/binapigen/generator_test.go
index e145979..ddbda99 100644
--- a/cmd/binapi-generator/parse_test.go
+++ b/binapigen/generator_test.go
@@ -1,4 +1,18 @@
-package main
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package binapigen
import (
"testing"
@@ -14,7 +28,8 @@ func TestBinapiTypeSizes(t *testing.T) {
{name: "basic2", input: "i8", expsize: 1},
{name: "basic3", input: "u16", expsize: 2},
{name: "basic4", input: "i32", expsize: 4},
- {name: "invalid1", input: "x", expsize: -1},
+ {name: "string", input: "string", expsize: 1},
+ {name: "invalid1", input: "x", expsize: 0},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
@@ -26,15 +41,15 @@ func TestBinapiTypeSizes(t *testing.T) {
}
}
-func TestSizeOfType(t *testing.T) {
+/*func TestSizeOfType(t *testing.T) {
tests := []struct {
name string
- input Type
+ input StructType
expsize int
}{
{
name: "basic1",
- input: Type{
+ input: StructType{
Fields: []Field{
{Type: "u8"},
},
@@ -81,17 +96,15 @@ func TestSizeOfType(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- ctx := &context{
- packageData: &Package{
- Enums: []Enum{
- {Name: "myenum", Type: "u32"},
- },
+ module := &File{
+ Enums: []Enum{
+ {Name: "myenum", Type: "u32"},
},
}
- size := getSizeOfType(ctx, &test.input)
+ size := getSizeOfType(module, &test.input)
if size != test.expsize {
t.Errorf("expected %d, got %d", test.expsize, size)
}
})
}
-}
+}*/
diff --git a/binapigen/run.go b/binapigen/run.go
new file mode 100644
index 0000000..441c43d
--- /dev/null
+++ b/binapigen/run.go
@@ -0,0 +1,89 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package binapigen
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "github.com/sirupsen/logrus"
+
+ "git.fd.io/govpp.git/binapigen/vppapi"
+)
+
+var debugMode = true
+
+func logf(f string, v ...interface{}) {
+ if debugMode {
+ logrus.Debugf(f, v...)
+ }
+}
+
+func GenerateBinapiFile(gen *Generator, file *File, outputDir string) *GenFile {
+ packageDir := filepath.Join(outputDir, file.PackageName)
+ filename := filepath.Join(packageDir, file.PackageName+outputFileExt)
+
+ g := gen.NewGenFile(filename)
+ g.file = file
+ g.packageDir = filepath.Join(outputDir, file.PackageName)
+
+ generatePackage(g, &g.buf)
+
+ return g
+}
+
+func GenerateRPC(gen *Generator, file *File, outputDir string) *GenFile {
+ packageDir := filepath.Join(outputDir, file.PackageName)
+ filename := filepath.Join(packageDir, file.PackageName+rpcFileSuffix+outputFileExt)
+
+ g := gen.NewGenFile(filename)
+ g.file = file
+ g.packageDir = filepath.Join(outputDir, file.PackageName)
+
+ generatePackageRPC(g, &g.buf)
+
+ return g
+}
+
+func Run(apiDir string, opts Options, f func(*Generator) error) {
+ if err := run(apiDir, opts, f); err != nil {
+ fmt.Fprintf(os.Stderr, "%s: %v\n", filepath.Base(os.Args[0]), err)
+ os.Exit(1)
+ }
+}
+
+func run(apiDir string, opts Options, f func(*Generator) error) error {
+ // parse API files
+ apifiles, err := vppapi.ParseDir(apiDir)
+ if err != nil {
+ return err
+ }
+
+ g, err := New(opts, apifiles)
+ if err != nil {
+ return err
+ }
+
+ if err := f(g); err != nil {
+ return err
+ }
+
+ if err = g.Generate(); err != nil {
+ return err
+ }
+
+ return nil
+}
diff --git a/binapigen/types.go b/binapigen/types.go
new file mode 100644
index 0000000..0dbbeb1
--- /dev/null
+++ b/binapigen/types.go
@@ -0,0 +1,271 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package binapigen
+
+import (
+ "strings"
+
+ "github.com/sirupsen/logrus"
+)
+
+// define api
+const (
+ defineApiPrefix = "vl_api_"
+ defineApiSuffix = "_t"
+)
+
+// BaseType represents base types in VPP binary API.
+type BaseType int
+
+const (
+ U8 BaseType = iota + 1
+ I8
+ U16
+ I16
+ U32
+ I32
+ U64
+ I64
+ F64
+ BOOL
+ STRING
+)
+
+var (
+ BaseTypes = map[BaseType]string{
+ U8: "u8",
+ I8: "i8",
+ U16: "u16",
+ I16: "i16",
+ U32: "u32",
+ I32: "i32",
+ U64: "u64",
+ I64: "i64",
+ F64: "f64",
+ BOOL: "bool",
+ STRING: "string",
+ }
+ BaseTypeNames = map[string]BaseType{
+ "u8": U8,
+ "i8": I8,
+ "u16": U16,
+ "i16": I16,
+ "u32": U32,
+ "i32": I32,
+ "u64": U64,
+ "i64": I64,
+ "f64": F64,
+ "bool": BOOL,
+ "string": STRING,
+ }
+)
+
+var BaseTypeSizes = map[BaseType]int{
+ U8: 1,
+ I8: 1,
+ U16: 2,
+ I16: 2,
+ U32: 4,
+ I32: 4,
+ U64: 8,
+ I64: 8,
+ F64: 8,
+ BOOL: 1,
+ STRING: 1,
+}
+
+type Kind int
+
+const (
+ _ = iota
+ Uint8Kind
+ Int8Kind
+ Uint16Kind
+ Int16Kind
+ Uint32Kind
+ Int32Kind
+ Uint64Kind
+ Int64Kind
+ Float64Kind
+ BoolKind
+ StringKind
+ EnumKind
+ AliasKind
+ StructKind
+ UnionKind
+ MessageKind
+)
+
+// toApiType returns name that is used as type reference in VPP binary API
+func toApiType(name string) string {
+ return defineApiPrefix + name + defineApiSuffix
+}
+
+func fromApiType(typ string) string {
+ name := typ
+ name = strings.TrimPrefix(name, defineApiPrefix)
+ name = strings.TrimSuffix(name, defineApiSuffix)
+ return name
+}
+
+func getSizeOfType(module *File, typ *Struct) (size int) {
+ for _, field := range typ.Fields {
+ enum := getEnumByRef(module, field.Type)
+ if enum != nil {
+ size += getSizeOfBinapiTypeLength(enum.Type, field.Length)
+ continue
+ }
+ size += getSizeOfBinapiTypeLength(field.Type, field.Length)
+ }
+ return size
+}
+
+func getEnumByRef(file *File, ref string) *Enum {
+ for _, typ := range file.Enums {
+ if ref == toApiType(typ.Name) {
+ return typ
+ }
+ }
+ return nil
+}
+
+func getTypeByRef(file *File, ref string) *Struct {
+ for _, typ := range file.Structs {
+ if ref == toApiType(typ.Name) {
+ return typ
+ }
+ }
+ return nil
+}
+
+func getAliasByRef(file *File, ref string) *Alias {
+ for _, alias := range file.Aliases {
+ if ref == toApiType(alias.Name) {
+ return alias
+ }
+ }
+ return nil
+}
+
+func getUnionByRef(file *File, ref string) *Union {
+ for _, union := range file.Unions {
+ if ref == toApiType(union.Name) {
+ return union
+ }
+ }
+ return nil
+}
+
+func getBinapiTypeSize(binapiType string) (size int) {
+ typName := BaseTypeNames[binapiType]
+ return BaseTypeSizes[typName]
+}
+
+// binapiTypes is a set of types used VPP binary API for translation to Go types
+var binapiTypes = map[string]string{
+ "u8": "uint8",
+ "i8": "int8",
+ "u16": "uint16",
+ "i16": "int16",
+ "u32": "uint32",
+ "i32": "int32",
+ "u64": "uint64",
+ "i64": "int64",
+ "f64": "float64",
+}
+var BaseTypesGo = map[BaseType]string{
+ U8: "uint8",
+ I8: "int8",
+ U16: "uint16",
+ I16: "int16",
+ U32: "uint32",
+ I32: "int32",
+ U64: "uint64",
+ I64: "int64",
+ F64: "float64",
+ BOOL: "bool",
+ STRING: "string",
+}
+
+func getActualType(file *File, typ string) (actual string) {
+ for _, enum := range file.Enums {
+ if enum.GoName == typ {
+ return enum.Type
+ }
+ }
+ for _, alias := range file.Aliases {
+ if alias.GoName == typ {
+ return alias.Type
+ }
+ }
+ return typ
+}
+
+// convertToGoType translates the VPP binary API type into Go type
+func convertToGoType(file *File, binapiType string) (typ string) {
+ if t, ok := binapiTypes[binapiType]; ok {
+ // basic types
+ typ = t
+ } else if r, ok := file.refmap[binapiType]; ok {
+ // specific types (enums/types/unions)
+ typ = camelCaseName(r)
+ } else {
+ switch binapiType {
+ case "bool", "string":
+ typ = binapiType
+ default:
+ // fallback type
+ logrus.Warnf("found unknown VPP binary API type %q, using byte", binapiType)
+ typ = "byte"
+ }
+ }
+ return typ
+}
+
+func getSizeOfBinapiTypeLength(typ string, length int) (size int) {
+ if n := getBinapiTypeSize(typ); n > 0 {
+ if length > 0 {
+ return n * length
+ } else {
+ return n
+ }
+ }
+
+ return
+}
+
+func getUnionSize(file *File, union *Union) (maxSize int) {
+ for _, field := range union.Fields {
+ typ := getTypeByRef(file, field.Type)
+ if typ != nil {
+ if size := getSizeOfType(file, typ); size > maxSize {
+ maxSize = size
+ }
+ continue
+ }
+ alias := getAliasByRef(file, field.Type)
+ if alias != nil {
+ if size := getSizeOfBinapiTypeLength(alias.Type, alias.Length); size > maxSize {
+ maxSize = size
+ }
+ continue
+ } else {
+ logf("no type or alias found for union %s field type %q", union.Name, field.Type)
+ continue
+ }
+ }
+ logf("getUnionSize: %s %+v max=%v", union.Name, union.Fields, maxSize)
+ return
+}
diff --git a/binapigen/validate.go b/binapigen/validate.go
new file mode 100644
index 0000000..2dae903
--- /dev/null
+++ b/binapigen/validate.go
@@ -0,0 +1,66 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package binapigen
+
+import (
+ "strings"
+
+ "git.fd.io/govpp.git/binapigen/vppapi"
+ "github.com/sirupsen/logrus"
+)
+
+const (
+ serviceEventPrefix = "want_"
+ serviceDumpSuffix = "_dump"
+ serviceDetailsSuffix = "_details"
+ serviceReplySuffix = "_reply"
+)
+
+func validateService(svc vppapi.Service) {
+ for _, rpc := range svc.RPCs {
+ validateRPC(rpc)
+ }
+}
+
+func validateRPC(rpc vppapi.RPC) {
+ if len(rpc.Events) > 0 {
+ // EVENT service
+ if !strings.HasPrefix(rpc.RequestMsg, serviceEventPrefix) {
+ logrus.Warnf("unusual EVENTS service: %+v\n"+
+ "- events service %q does not have %q prefix in request.",
+ rpc, rpc.Name, serviceEventPrefix)
+ }
+ } else if rpc.Stream {
+ // STREAM service
+ if !strings.HasSuffix(rpc.RequestMsg, serviceDumpSuffix) {
+ logrus.Warnf("unusual STREAM service: %+v\n"+
+ "- stream service %q does not have %q suffix in request.",
+ rpc, rpc.Name, serviceDumpSuffix)
+ }
+ if !strings.HasSuffix(rpc.ReplyMsg, serviceDetailsSuffix) && !strings.HasSuffix(rpc.StreamMsg, serviceDetailsSuffix) {
+ logrus.Warnf("unusual STREAM service: %+v\n"+
+ "- stream service %q does not have %q suffix in reply or stream msg.",
+ rpc, rpc.Name, serviceDetailsSuffix)
+ }
+ } else if rpc.ReplyMsg != "" {
+ // REQUEST service
+ // some messages might have `null` reply (for example: memclnt)
+ if !strings.HasSuffix(rpc.ReplyMsg, serviceReplySuffix) {
+ logrus.Warnf("unusual REQUEST service: %+v\n"+
+ "- service %q does not have %q suffix in reply.",
+ rpc, rpc.Name, serviceReplySuffix)
+ }
+ }
+}
diff --git a/binapigen/vppapi/api.go b/binapigen/vppapi/api.go
new file mode 100644
index 0000000..06d9046
--- /dev/null
+++ b/binapigen/vppapi/api.go
@@ -0,0 +1,94 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package vppapi
+
+type File struct {
+ Name string
+ Path string
+
+ CRC string
+ Options map[string]string `json:",omitempty"`
+
+ Imports []string `json:",omitempty"`
+
+ AliasTypes []AliasType `json:",omitempty"`
+ EnumTypes []EnumType `json:",omitempty"`
+ StructTypes []StructType `json:",omitempty"`
+ UnionTypes []UnionType `json:",omitempty"`
+ Messages []Message `json:",omitempty"`
+ Service *Service `json:",omitempty"`
+}
+
+func (x File) Version() string {
+ if x.Options != nil {
+ return x.Options[fileOptionVersion]
+ }
+ return ""
+}
+
+type AliasType struct {
+ Name string
+ Type string
+ Length int `json:",omitempty"`
+}
+
+type EnumType struct {
+ Name string
+ Type string
+ Entries []EnumEntry
+}
+
+type EnumEntry struct {
+ Name string
+ Value uint32
+}
+
+type StructType struct {
+ Name string
+ Fields []Field
+}
+
+type UnionType struct {
+ Name string
+ Fields []Field
+}
+
+type Message struct {
+ Name string
+ Fields []Field
+ CRC string
+}
+
+type Field struct {
+ Name string
+ Type string
+ Length int `json:",omitempty"`
+ Array bool `json:",omitempty"`
+ SizeFrom string `json:",omitempty"`
+ Meta map[string]interface{} `json:",omitempty"`
+}
+
+type Service struct {
+ RPCs []RPC `json:",omitempty"`
+}
+
+type RPC struct {
+ Name string
+ RequestMsg string
+ ReplyMsg string
+ Stream bool `json:",omitempty"`
+ StreamMsg string `json:",omitempty"`
+ Events []string `json:",omitempty"`
+}
diff --git a/binapigen/vppapi/integration_test.go b/binapigen/vppapi/integration_test.go
new file mode 100644
index 0000000..142017a
--- /dev/null
+++ b/binapigen/vppapi/integration_test.go
@@ -0,0 +1,43 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// +build integration
+
+package vppapi_test
+
+import (
+ "encoding/json"
+ "testing"
+
+ "git.fd.io/govpp.git/binapigen/vppapi"
+)
+
+func TestParse(t *testing.T) {
+ files, err := vppapi.Parse()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ for _, file := range files {
+ //t.Logf(" - %s: %+v", path, module)
+ b, err := json.MarshalIndent(file, "\t", " ")
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Logf(" - %s:\n%s", file.Name, b)
+ }
+
+ t.Logf("parsed %d files", len(files))
+
+}
diff --git a/binapigen/vppapi/parse_json.go b/binapigen/vppapi/parse_json.go
new file mode 100644
index 0000000..45b5796
--- /dev/null
+++ b/binapigen/vppapi/parse_json.go
@@ -0,0 +1,552 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package vppapi
+
+import (
+ "encoding/json"
+ "errors"
+ "fmt"
+ "os"
+ "strings"
+
+ "github.com/bennyscetbun/jsongo"
+ "github.com/sirupsen/logrus"
+)
+
+var Logger *logrus.Logger
+
+func init() {
+ if strings.Contains(os.Getenv("DEBUG_GOVPP"), "parser") {
+ Logger = logrus.StandardLogger()
+ }
+}
+
+func logf(f string, v ...interface{}) {
+ if Logger != nil {
+ Logger.Debugf(f, v...)
+ }
+}
+
+const (
+ // file
+ objAPIVersion = "vl_api_version"
+ objTypes = "types"
+ objMessages = "messages"
+ objUnions = "unions"
+ objEnums = "enums"
+ objServices = "services"
+ objAliases = "aliases"
+ objOptions = "options"
+ objImports = "imports"
+
+ // message
+ messageFieldCrc = "crc"
+
+ // alias
+ aliasFieldLength = "length"
+ aliasFieldType = "type"
+
+ // service
+ serviceFieldReply = "reply"
+ serviceFieldStream = "stream"
+ serviceFieldStreamMsg = "stream_msg"
+ serviceFieldEvents = "events"
+)
+
+const (
+ // file
+ fileOptionVersion = "version"
+
+ // field
+ fieldOptionLimit = "limit"
+ fieldOptionDefault = "default"
+
+ // service
+ serviceReplyNull = "null"
+)
+
+func parseJSON(data []byte) (module *File, err error) {
+ defer func() {
+ if e := recover(); e != nil {
+ err = fmt.Errorf("recovered panic: %v", e)
+ }
+ }()
+
+ // parse JSON data into objects
+ jsonRoot := new(jsongo.Node)
+ if err := json.Unmarshal(data, jsonRoot); err != nil {
+ return nil, fmt.Errorf("unmarshalling JSON failed: %v", err)
+ }
+
+ logf("file contents:")
+ for _, key := range jsonRoot.GetKeys() {
+ if jsonRoot.At(key).Len() > 0 {
+ logf(" - %2d %s", jsonRoot.At(key).Len(), key)
+ }
+ }
+
+ module = new(File)
+
+ // parse CRC
+ if crc := jsonRoot.At(objAPIVersion); crc.GetType() == jsongo.TypeValue {
+ module.CRC = crc.Get().(string)
+ }
+
+ // parse options
+ opt := jsonRoot.Map(objOptions)
+ if opt.GetType() == jsongo.TypeMap {
+ module.Options = make(map[string]string, 0)
+ for _, key := range opt.GetKeys() {
+ optionsNode := opt.At(key)
+ optionKey := key.(string)
+ optionValue := optionsNode.Get().(string)
+ module.Options[optionKey] = optionValue
+ }
+ }
+
+ // parse imports
+ imports := jsonRoot.Map(objImports)
+ module.Imports = make([]string, 0)
+ imported := make(map[string]struct{})
+ for i := 0; i < imports.Len(); i++ {
+ importNode := imports.At(i)
+ imp, err := parseImport(importNode)
+ if err != nil {
+ return nil, err
+ }
+ if _, ok := imported[*imp]; ok {
+ logf("duplicate import found: %v", *imp)
+ continue
+ }
+ imported[*imp] = struct{}{}
+ module.Imports = append(module.Imports, *imp)
+ }
+
+ // avoid duplicate objects
+ known := make(map[string]struct{})
+ exists := func(name string) bool {
+ if _, ok := known[name]; ok {
+ logf("duplicate object found: %v", name)
+ return true
+ }
+ known[name] = struct{}{}
+ return false
+ }
+
+ // parse enum types
+ enumsNode := jsonRoot.Map(objEnums)
+ module.EnumTypes = make([]EnumType, 0)
+ for i := 0; i < enumsNode.Len(); i++ {
+ enumNode := enumsNode.At(i)
+ enum, err := parseEnum(enumNode)
+ if err != nil {
+ return nil, err
+ }
+ if exists(enum.Name) {
+ continue
+ }
+ module.EnumTypes = append(module.EnumTypes, *enum)
+ }
+
+ // parse alias types
+ aliasesNode := jsonRoot.Map(objAliases)
+ if aliasesNode.GetType() == jsongo.TypeMap {
+ module.AliasTypes = make([]AliasType, 0)
+ for _, key := range aliasesNode.GetKeys() {
+ aliasNode := aliasesNode.At(key)
+ aliasName := key.(string)
+ alias, err := parseAlias(aliasName, aliasNode)
+ if err != nil {
+ return nil, err
+ }
+ if exists(alias.Name) {
+ continue
+ }
+ module.AliasTypes = append(module.AliasTypes, *alias)
+ }
+ }
+
+ // parse struct types
+ typesNode := jsonRoot.Map(objTypes)
+ module.StructTypes = make([]StructType, 0)
+ for i := 0; i < typesNode.Len(); i++ {
+ typNode := typesNode.At(i)
+ structyp, err := parseStruct(typNode)
+ if err != nil {
+ return nil, err
+ }
+ if exists(structyp.Name) {
+ continue
+ }
+ module.StructTypes = append(module.StructTypes, *structyp)
+ }
+
+ // parse union types
+ unionsNode := jsonRoot.Map(objUnions)
+ module.UnionTypes = make([]UnionType, 0)
+ for i := 0; i < unionsNode.Len(); i++ {
+ unionNode := unionsNode.At(i)
+ union, err := parseUnion(unionNode)
+ if err != nil {
+ return nil, err
+ }
+ if exists(union.Name) {
+ continue
+ }
+ module.UnionTypes = append(module.UnionTypes, *union)
+ }
+
+ // parse messages
+ messagesNode := jsonRoot.Map(objMessages)
+ if messagesNode.GetType() == jsongo.TypeArray {
+ module.Messages = make([]Message, messagesNode.Len())
+ for i := 0; i < messagesNode.Len(); i++ {
+ msgNode := messagesNode.At(i)
+ msg, err := parseMessage(msgNode)
+ if err != nil {
+ return nil, err
+ }
+ module.Messages[i] = *msg
+ }
+ }
+
+ // parse services
+ servicesNode := jsonRoot.Map(objServices)
+ if servicesNode.GetType() == jsongo.TypeMap {
+ module.Service = &Service{
+ RPCs: make([]RPC, servicesNode.Len()),
+ }
+ for i, key := range servicesNode.GetKeys() {
+ rpcNode := servicesNode.At(key)
+ rpcName := key.(string)
+ svc, err := parseServiceRPC(rpcName, rpcNode)
+ if err != nil {
+ return nil, err
+ }
+ module.Service.RPCs[i] = *svc
+ }
+ }
+
+ return module, nil
+}
+
+// parseImport parses VPP binary API import from JSON node
+func parseImport(importNode *jsongo.Node) (*string, error) {
+ if importNode.GetType() != jsongo.TypeValue {
+ return nil, errors.New("invalid JSON for import specified")
+ }
+
+ importName, ok := importNode.Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("import name is %T, not a string", importNode.Get())
+ }
+
+ return &importName, nil
+}
+
+// parseEnum parses VPP binary API enum object from JSON node
+func parseEnum(enumNode *jsongo.Node) (*EnumType, error) {
+ if enumNode.Len() == 0 || enumNode.At(0).GetType() != jsongo.TypeValue {
+ return nil, errors.New("invalid JSON for enum specified")
+ }
+
+ enumName, ok := enumNode.At(0).Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("enum name is %T, not a string", enumNode.At(0).Get())
+ }
+ enumType, ok := enumNode.At(enumNode.Len() - 1).At("enumtype").Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("enum type invalid or missing")
+ }
+
+ enum := EnumType{
+ Name: enumName,
+ Type: enumType,
+ }
+
+ // loop through enum entries, skip first (name) and last (enumtype)
+ for j := 1; j < enumNode.Len()-1; j++ {
+ if enumNode.At(j).GetType() == jsongo.TypeArray {
+ entry := enumNode.At(j)
+
+ if entry.Len() < 2 || entry.At(0).GetType() != jsongo.TypeValue || entry.At(1).GetType() != jsongo.TypeValue {
+ return nil, errors.New("invalid JSON for enum entry specified")
+ }
+
+ entryName, ok := entry.At(0).Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("enum entry name is %T, not a string", entry.At(0).Get())
+ }
+ entryVal := entry.At(1).Get().(float64)
+
+ enum.Entries = append(enum.Entries, EnumEntry{
+ Name: entryName,
+ Value: uint32(entryVal),
+ })
+ }
+ }
+
+ return &enum, nil
+}
+
+// parseUnion parses VPP binary API union object from JSON node
+func parseUnion(unionNode *jsongo.Node) (*UnionType, error) {
+ if unionNode.Len() == 0 || unionNode.At(0).GetType() != jsongo.TypeValue {
+ return nil, errors.New("invalid JSON for union specified")
+ }
+
+ unionName, ok := unionNode.At(0).Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("union name is %T, not a string", unionNode.At(0).Get())
+ }
+
+ union := UnionType{
+ Name: unionName,
+ }
+
+ // loop through union fields, skip first (name)
+ for j := 1; j < unionNode.Len(); j++ {
+ if unionNode.At(j).GetType() == jsongo.TypeArray {
+ fieldNode := unionNode.At(j)
+
+ field, err := parseField(fieldNode)
+ if err != nil {
+ return nil, err
+ }
+
+ union.Fields = append(union.Fields, *field)
+ }
+ }
+
+ return &union, nil
+}
+
+// parseStruct parses VPP binary API type object from JSON node
+func parseStruct(typeNode *jsongo.Node) (*StructType, error) {
+ if typeNode.Len() == 0 || typeNode.At(0).GetType() != jsongo.TypeValue {
+ return nil, errors.New("invalid JSON for type specified")
+ }
+
+ typeName, ok := typeNode.At(0).Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("type name is %T, not a string", typeNode.At(0).Get())
+ }
+
+ typ := StructType{
+ Name: typeName,
+ }
+
+ // loop through type fields, skip first (name)
+ for j := 1; j < typeNode.Len(); j++ {
+ if typeNode.At(j).GetType() == jsongo.TypeArray {
+ fieldNode := typeNode.At(j)
+
+ field, err := parseField(fieldNode)
+ if err != nil {
+ return nil, err
+ }
+
+ typ.Fields = append(typ.Fields, *field)
+ }
+ }
+
+ return &typ, nil
+}
+
+// parseAlias parses VPP binary API alias object from JSON node
+func parseAlias(aliasName string, aliasNode *jsongo.Node) (*AliasType, error) {
+ if aliasNode.Len() == 0 || aliasNode.At(aliasFieldType).GetType() != jsongo.TypeValue {
+ return nil, errors.New("invalid JSON for alias specified")
+ }
+
+ alias := AliasType{
+ Name: aliasName,
+ }
+
+ if typeNode := aliasNode.At(aliasFieldType); typeNode.GetType() == jsongo.TypeValue {
+ typ, ok := typeNode.Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("alias type is %T, not a string", typeNode.Get())
+ }
+ if typ != "null" {
+ alias.Type = typ
+ }
+ }
+
+ if lengthNode := aliasNode.At(aliasFieldLength); lengthNode.GetType() == jsongo.TypeValue {
+ length, ok := lengthNode.Get().(float64)
+ if !ok {
+ return nil, fmt.Errorf("alias length is %T, not a float64", lengthNode.Get())
+ }
+ alias.Length = int(length)
+ }
+
+ return &alias, nil
+}
+
+// parseMessage parses VPP binary API message object from JSON node
+func parseMessage(msgNode *jsongo.Node) (*Message, error) {
+ if msgNode.Len() == 0 || msgNode.At(0).GetType() != jsongo.TypeValue {
+ return nil, errors.New("invalid JSON for message specified")
+ }
+
+ msgName, ok := msgNode.At(0).Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("message name is %T, not a string", msgNode.At(0).Get())
+ }
+ msgCRC, ok := msgNode.At(msgNode.Len() - 1).At(messageFieldCrc).Get().(string)
+ if !ok {
+
+ return nil, fmt.Errorf("message crc invalid or missing")
+ }
+
+ msg := Message{
+ Name: msgName,
+ CRC: msgCRC,
+ }
+
+ // loop through message fields, skip first (name) and last (crc)
+ for j := 1; j < msgNode.Len()-1; j++ {
+ if msgNode.At(j).GetType() == jsongo.TypeArray {
+ fieldNode := msgNode.At(j)
+
+ field, err := parseField(fieldNode)
+ if err != nil {
+ return nil, err
+ }
+
+ msg.Fields = append(msg.Fields, *field)
+ }
+ }
+
+ return &msg, nil
+}
+
+// parseField parses VPP binary API object field from JSON node
+func parseField(field *jsongo.Node) (*Field, error) {
+ if field.Len() < 2 || field.At(0).GetType() != jsongo.TypeValue || field.At(1).GetType() != jsongo.TypeValue {
+ return nil, errors.New("invalid JSON for field specified")
+ }
+
+ fieldType, ok := field.At(0).Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("field type is %T, not a string", field.At(0).Get())
+ }
+ fieldName, ok := field.At(1).Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("field name is %T, not a string", field.At(1).Get())
+ }
+
+ f := &Field{
+ Name: fieldName,
+ Type: fieldType,
+ }
+
+ if field.Len() >= 3 {
+ switch field.At(2).GetType() {
+ case jsongo.TypeValue:
+ fieldLength, ok := field.At(2).Get().(float64)
+ if !ok {
+ return nil, fmt.Errorf("field length is %T, not float64", field.At(2).Get())
+ }
+ f.Length = int(fieldLength)
+ f.Array = true
+
+ case jsongo.TypeMap:
+ fieldMeta := field.At(2)
+
+ for _, key := range fieldMeta.GetKeys() {
+ metaNode := fieldMeta.At(key)
+ metaName := key.(string)
+ metaValue := metaNode.Get()
+
+ switch metaName {
+ case fieldOptionLimit:
+ metaValue = int(metaNode.Get().(float64))
+ case fieldOptionDefault:
+ metaValue = metaNode.Get()
+ default:
+ logrus.Warnf("unknown meta info (%s=%v) for field (%s)", metaName, metaValue, fieldName)
+ }
+
+ if f.Meta == nil {
+ f.Meta = map[string]interface{}{}
+ }
+ f.Meta[metaName] = metaValue
+ }
+ default:
+ return nil, errors.New("invalid JSON for field specified")
+ }
+ }
+ if field.Len() >= 4 {
+ fieldLengthFrom, ok := field.At(3).Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("field length from is %T, not a string", field.At(3).Get())
+ }
+ f.SizeFrom = fieldLengthFrom
+ }
+
+ return f, nil
+}
+
+// parseServiceRPC parses VPP binary API service object from JSON node
+func parseServiceRPC(rpcName string, rpcNode *jsongo.Node) (*RPC, error) {
+ if rpcNode.Len() == 0 || rpcNode.At(serviceFieldReply).GetType() != jsongo.TypeValue {
+ return nil, errors.New("invalid JSON for service RPC specified")
+ }
+
+ rpc := RPC{
+ Name: rpcName,
+ RequestMsg: rpcName,
+ }
+
+ if replyNode := rpcNode.At(serviceFieldReply); replyNode.GetType() == jsongo.TypeValue {
+ reply, ok := replyNode.Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("service RPC reply is %T, not a string", replyNode.Get())
+ }
+ if reply != serviceReplyNull {
+ rpc.ReplyMsg = reply
+ }
+ }
+
+ // is stream (dump)
+ if streamNode := rpcNode.At(serviceFieldStream); streamNode.GetType() == jsongo.TypeValue {
+ var ok bool
+ rpc.Stream, ok = streamNode.Get().(bool)
+ if !ok {
+ return nil, fmt.Errorf("service RPC stream is %T, not a boolean", streamNode.Get())
+ }
+ }
+
+ // stream message
+ if streamMsgNode := rpcNode.At(serviceFieldStreamMsg); streamMsgNode.GetType() == jsongo.TypeValue {
+ var ok bool
+ rpc.StreamMsg, ok = streamMsgNode.Get().(string)
+ if !ok {
+ return nil, fmt.Errorf("service RPC stream msg is %T, not a string", streamMsgNode.Get())
+ }
+ }
+
+ // events service (event subscription)
+ if eventsNode := rpcNode.At(serviceFieldEvents); eventsNode.GetType() == jsongo.TypeArray {
+ for j := 0; j < eventsNode.Len(); j++ {
+ event := eventsNode.At(j).Get().(string)
+ rpc.Events = append(rpc.Events, event)
+ }
+ }
+
+ return &rpc, nil
+}
diff --git a/binapigen/vppapi/parser.go b/binapigen/vppapi/parser.go
new file mode 100644
index 0000000..312dd0e
--- /dev/null
+++ b/binapigen/vppapi/parser.go
@@ -0,0 +1,111 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package vppapi
+
+import (
+ "fmt"
+ "io/ioutil"
+ "path/filepath"
+ "strings"
+
+ "github.com/sirupsen/logrus"
+)
+
+const (
+ DefaultAPIDir = "/usr/share/vpp/api"
+)
+
+const apifileSuffixJson = ".api.json"
+
+// FindFiles returns all input files located in specified directory
+func FindFiles(dir string, deep int) (paths []string, err error) {
+ entries, err := ioutil.ReadDir(dir)
+ if err != nil {
+ return nil, fmt.Errorf("reading directory %s failed: %v", dir, err)
+ }
+ for _, e := range entries {
+ if e.IsDir() && deep > 0 {
+ nestedDir := filepath.Join(dir, e.Name())
+ if nested, err := FindFiles(nestedDir, deep-1); err != nil {
+ return nil, err
+ } else {
+ paths = append(paths, nested...)
+ }
+ } else if strings.HasSuffix(e.Name(), apifileSuffixJson) {
+ paths = append(paths, filepath.Join(dir, e.Name()))
+ }
+ }
+ return paths, nil
+}
+
+func Parse() ([]*File, error) {
+ return ParseDir(DefaultAPIDir)
+}
+
+func ParseDir(apidir string) ([]*File, error) {
+ files, err := FindFiles(apidir, 1)
+ if err != nil {
+ return nil, err
+ }
+
+ logrus.Infof("found %d files in API dir %q", len(files), apidir)
+
+ var modules []*File
+
+ for _, file := range files {
+ module, err := ParseFile(file)
+ if err != nil {
+ return nil, err
+ }
+ modules = append(modules, module)
+ }
+
+ return modules, nil
+}
+
+// ParseFile parses API file contents and returns File.
+func ParseFile(apifile string) (*File, error) {
+ if !strings.HasSuffix(apifile, apifileSuffixJson) {
+ return nil, fmt.Errorf("unsupported file format: %q", apifile)
+ }
+
+ data, err := ioutil.ReadFile(apifile)
+ if err != nil {
+ return nil, fmt.Errorf("reading file %s failed: %v", apifile, err)
+ }
+
+ base := filepath.Base(apifile)
+ name := base[:strings.Index(base, ".")]
+
+ logf("parsing file %q", base)
+
+ module, err := ParseRaw(data)
+ if err != nil {
+ return nil, fmt.Errorf("parsing file %s failed: %v", base, err)
+ }
+ module.Name = name
+ module.Path = apifile
+
+ return module, nil
+}
+
+func ParseRaw(data []byte) (file *File, err error) {
+ file, err = parseJSON(data)
+ if err != nil {
+ return nil, err
+ }
+
+ return file, nil
+}
diff --git a/binapigen/vppapi/parser_test.go b/binapigen/vppapi/parser_test.go
new file mode 100644
index 0000000..2dc82e4
--- /dev/null
+++ b/binapigen/vppapi/parser_test.go
@@ -0,0 +1,114 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package vppapi
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "testing"
+
+ . "github.com/onsi/gomega"
+)
+
+func TestGetInputFiles(t *testing.T) {
+ RegisterTestingT(t)
+
+ result, err := FindFiles("testdata", 1)
+ Expect(err).ShouldNot(HaveOccurred())
+ Expect(result).To(HaveLen(5))
+ for _, file := range result {
+ Expect(file).To(BeAnExistingFile())
+ }
+}
+
+func TestGetInputFilesError(t *testing.T) {
+ RegisterTestingT(t)
+
+ result, err := FindFiles("nonexisting_directory", 1)
+ Expect(err).Should(HaveOccurred())
+ Expect(result).To(BeNil())
+}
+
+func TestReadJson(t *testing.T) {
+ RegisterTestingT(t)
+
+ inputData, err := ioutil.ReadFile("testdata/af_packet.api.json")
+ Expect(err).ShouldNot(HaveOccurred())
+ result, err := parseJSON(inputData)
+ Expect(err).ShouldNot(HaveOccurred())
+ Expect(result).ToNot(BeNil())
+ Expect(result.EnumTypes).To(HaveLen(0))
+ Expect(result.StructTypes).To(HaveLen(0))
+ Expect(result.Messages).To(HaveLen(6))
+ Expect(result.Service.RPCs).To(HaveLen(3))
+}
+
+func TestReadJsonError(t *testing.T) {
+ RegisterTestingT(t)
+
+ inputData, err := ioutil.ReadFile("testdata/input-read-json-error.json")
+ Expect(err).ShouldNot(HaveOccurred())
+ result, err := parseJSON(inputData)
+ Expect(err).Should(HaveOccurred())
+ Expect(result).To(BeNil())
+}
+
+func TestParseFile(t *testing.T) {
+ module, err := ParseFile("testdata/vpe.api.json")
+ if err != nil {
+ t.Fatal("unexpected error:", err)
+ }
+
+ b, err := json.MarshalIndent(module, "", " ")
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Logf("parsed module: %s", b)
+
+ if module.Name != "vpe" {
+ t.Errorf("expected Name=%s, got %v", "vpe", module.Name)
+ }
+ if module.CRC != "0xbd2c94f4" {
+ t.Errorf("expected CRC=%s, got %v", "0xbd2c94f4", module.CRC)
+ }
+ if module.Version() != "1.6.1" {
+ t.Errorf("expected Version=%s, got %v", "1.6.1", module.Version())
+ }
+ if len(module.Imports) == 0 {
+ t.Errorf("expected imports, got none")
+ }
+ if len(module.Options) == 0 {
+ t.Errorf("expected options, got none")
+ }
+ if len(module.AliasTypes) == 0 {
+ t.Errorf("expected aliases, got none")
+ }
+ if len(module.StructTypes) == 0 {
+ t.Errorf("expected types, got none")
+ }
+ if len(module.Service.RPCs) == 0 {
+ t.Errorf("expected service method, got none")
+ }
+ if len(module.Messages) == 0 {
+ t.Errorf("expected messages, got none")
+ }
+}
+
+func TestParseFileUnsupported(t *testing.T) {
+ _, err := ParseFile("testdata/input.txt")
+ if err == nil {
+ t.Fatal("expected error")
+ }
+}
diff --git a/cmd/binapi-generator/testdata/acl.api.json b/binapigen/vppapi/testdata/acl.api.json
index 4c6653c..4c6653c 100644
--- a/cmd/binapi-generator/testdata/acl.api.json
+++ b/binapigen/vppapi/testdata/acl.api.json
diff --git a/cmd/binapi-generator/testdata/af_packet.api.json b/binapigen/vppapi/testdata/af_packet.api.json
index 81ee2f9..dc0de16 100644
--- a/cmd/binapi-generator/testdata/af_packet.api.json
+++ b/binapigen/vppapi/testdata/af_packet.api.json
@@ -1,21 +1,15 @@
{
- "services": [
- {
- "af_packet_delete": {
- "reply": "af_packet_delete_reply"
- }
+ "services": {
+ "af_packet_delete": {
+ "reply": "af_packet_delete_reply"
},
- {
- "af_packet_create": {
- "reply": "af_packet_create_reply"
- }
+ "af_packet_create": {
+ "reply": "af_packet_create_reply"
},
- {
- "af_packet_set_l4_cksum_offload": {
- "reply": "af_packet_set_l4_cksum_offload_reply"
- }
+ "af_packet_set_l4_cksum_offload": {
+ "reply": "af_packet_set_l4_cksum_offload_reply"
}
- ],
+ },
"vl_api_version": "0x8957ca8b",
"enums": [],
"messages": [
diff --git a/cmd/binapi-generator/testdata/input-generate-error.json b/binapigen/vppapi/testdata/input-generate-error.json
index d5df76e..d5df76e 100644
--- a/cmd/binapi-generator/testdata/input-generate-error.json
+++ b/binapigen/vppapi/testdata/input-generate-error.json
diff --git a/cmd/binapi-generator/testdata/input-read-json-error.json b/binapigen/vppapi/testdata/input-read-json-error.json
index 02691e3..02691e3 100644
--- a/cmd/binapi-generator/testdata/input-read-json-error.json
+++ b/binapigen/vppapi/testdata/input-read-json-error.json
diff --git a/cmd/binapi-generator/testdata/input.txt b/binapigen/vppapi/testdata/input.txt
index e69de29..e69de29 100644
--- a/cmd/binapi-generator/testdata/input.txt
+++ b/binapigen/vppapi/testdata/input.txt
diff --git a/cmd/binapi-generator/testdata/ip.api.json b/binapigen/vppapi/testdata/ip.api.json
index 530b6d6..530b6d6 100644
--- a/cmd/binapi-generator/testdata/ip.api.json
+++ b/binapigen/vppapi/testdata/ip.api.json
diff --git a/binapigen/vppapi/testdata/test-all.api.json b/binapigen/vppapi/testdata/test-all.api.json
new file mode 100644
index 0000000..4e858b8
--- /dev/null
+++ b/binapigen/vppapi/testdata/test-all.api.json
@@ -0,0 +1,3240 @@
+[
+ {
+ "types": [
+ [
+ "address",
+ [
+ "vl_api_address_family_t",
+ "af"
+ ],
+ [
+ "vl_api_address_union_t",
+ "un"
+ ]
+ ],
+ [
+ "prefix",
+ [
+ "vl_api_address_t",
+ "address"
+ ],
+ [
+ "u8",
+ "len"
+ ]
+ ],
+ [
+ "mprefix",
+ [
+ "vl_api_address_family_t",
+ "af"
+ ],
+ [
+ "u16",
+ "grp_address_length"
+ ],
+ [
+ "vl_api_address_union_t",
+ "grp_address"
+ ],
+ [
+ "vl_api_address_union_t",
+ "src_address"
+ ]
+ ],
+ [
+ "ip6_prefix",
+ [
+ "vl_api_ip6_address_t",
+ "address"
+ ],
+ [
+ "u8",
+ "len"
+ ]
+ ],
+ [
+ "ip4_prefix",
+ [
+ "vl_api_ip4_address_t",
+ "address"
+ ],
+ [
+ "u8",
+ "len"
+ ]
+ ],
+ [
+ "prefix_matcher",
+ [
+ "u8",
+ "le"
+ ],
+ [
+ "u8",
+ "ge"
+ ]
+ ],
+ [
+ "fib_mpls_label",
+ [
+ "u8",
+ "is_uniform"
+ ],
+ [
+ "u32",
+ "label"
+ ],
+ [
+ "u8",
+ "ttl"
+ ],
+ [
+ "u8",
+ "exp"
+ ]
+ ],
+ [
+ "fib_path_nh",
+ [
+ "vl_api_address_union_t",
+ "address"
+ ],
+ [
+ "u32",
+ "via_label"
+ ],
+ [
+ "u32",
+ "obj_id"
+ ],
+ [
+ "u32",
+ "classify_table_index"
+ ]
+ ],
+ [
+ "fib_path",
+ [
+ "u32",
+ "sw_if_index"
+ ],
+ [
+ "u32",
+ "table_id"
+ ],
+ [
+ "u32",
+ "rpf_id"
+ ],
+ [
+ "u8",
+ "weight"
+ ],
+ [
+ "u8",
+ "preference"
+ ],
+ [
+ "vl_api_fib_path_type_t",
+ "type"
+ ],
+ [
+ "vl_api_fib_path_flags_t",
+ "flags"
+ ],
+ [
+ "vl_api_fib_path_nh_proto_t",
+ "proto"
+ ],
+ [
+ "vl_api_fib_path_nh_t",
+ "nh"
+ ],
+ [
+ "u8",
+ "n_labels"
+ ],
+ [
+ "vl_api_fib_mpls_label_t",
+ "label_stack",
+ 16
+ ]
+ ],
+ [
+ "address",
+ [
+ "vl_api_address_family_t",
+ "af"
+ ],
+ [
+ "vl_api_address_union_t",
+ "un"
+ ]
+ ],
+ [
+ "prefix",
+ [
+ "vl_api_address_t",
+ "address"
+ ],
+ [
+ "u8",
+ "len"
+ ]
+ ],
+ [
+ "mprefix",
+ [
+ "vl_api_address_family_t",
+ "af"
+ ],
+ [
+ "u16",
+ "grp_address_length"
+ ],
+ [
+ "vl_api_address_union_t",
+ "grp_address"
+ ],
+ [
+ "vl_api_address_union_t",
+ "src_address"
+ ]
+ ],
+ [
+ "ip6_prefix",
+ [
+ "vl_api_ip6_address_t",
+ "address"
+ ],
+ [
+ "u8",
+ "len"
+ ]
+ ],
+ [
+ "ip4_prefix",
+ [
+ "vl_api_ip4_address_t",
+ "address"
+ ],
+ [
+ "u8",
+ "len"
+ ]
+ ],
+ [
+ "prefix_matcher",
+ [
+ "u8",
+ "le"
+ ],
+ [
+ "u8",
+ "ge"
+ ]
+ ],
+ [
+ "fib_mpls_label",
+ [
+ "u8",
+ "is_uniform"
+ ],
+ [
+ "u32",
+ "label"
+ ],
+ [
+ "u8",
+ "ttl"
+ ],
+ [
+ "u8",
+ "exp"
+ ]
+ ],
+ [
+ "fib_path_nh",
+ [
+ "vl_api_address_union_t",
+ "address"
+ ],
+ [
+ "u32",
+ "via_label"
+ ],
+ [
+ "u32",
+ "obj_id"
+ ],
+ [
+ "u32",
+ "classify_table_index"
+ ]
+ ],
+ [
+ "fib_path",
+ [
+ "u32",
+ "sw_if_index"
+ ],
+ [
+ "u32",
+ "table_id"
+ ],
+ [
+ "u32",
+ "rpf_id"
+ ],
+ [
+ "u8",
+ "weight"
+ ],
+ [
+ "u8",
+ "preference"
+ ],
+ [
+ "vl_api_fib_path_type_t",
+ "type"
+ ],
+ [
+ "vl_api_fib_path_flags_t",
+ "flags"
+ ],
+ [
+ "vl_api_fib_path_nh_proto_t",
+ "proto"
+ ],
+ [
+ "vl_api_fib_path_nh_t",
+ "nh"
+ ],
+ [
+ "u8",
+ "n_labels"
+ ],
+ [
+ "vl_api_fib_mpls_label_t",
+ "label_stack",
+ 16
+ ]
+ ],
+ [
+ "address",
+ [
+ "vl_api_address_family_t",
+ "af"
+ ],
+ [
+ "vl_api_address_union_t",
+ "un"
+ ]
+ ],
+ [
+ "prefix",
+ [
+ "vl_api_address_t",
+ "address"
+ ],
+ [
+ "u8",
+ "len"
+ ]
+ ],
+ [
+ "mprefix",
+ [
+ "vl_api_address_family_t",
+ "af"
+ ],
+ [
+ "u16",
+ "grp_address_length"
+ ],
+ [
+ "vl_api_address_union_t",
+ "grp_address"
+ ],
+ [
+ "vl_api_address_union_t",
+ "src_address"
+ ]
+ ],
+ [
+ "ip6_prefix",
+ [
+ "vl_api_ip6_address_t",
+ "address"
+ ],
+ [
+ "u8",
+ "len"
+ ]
+ ],
+ [
+ "ip4_prefix",
+ [
+ "vl_api_ip4_address_t",
+ "address"
+ ],
+ [
+ "u8",
+ "len"
+ ]
+ ],
+ [
+ "prefix_matcher",
+ [
+ "u8",
+ "le"
+ ],
+ [
+ "u8",
+ "ge"
+ ]
+ ],
+ [
+ "mfib_path",
+ [
+ "vl_api_mfib_itf_flags_t",
+ "itf_flags"
+ ],
+ [
+ "vl_api_fib_path_t",
+ "path"
+ ]
+ ],
+ [
+ "ip_table",
+ [
+ "u32",
+ "table_id"
+ ],
+ [
+ "bool",
+ "is_ip6"
+ ],
+ [
+ "string",
+ "name",
+ 64
+ ]
+ ],
+ [
+ "ip_route",
+ [
+ "u32",
+ "table_id"
+ ],
+ [
+ "u32",
+ "stats_index"
+ ],
+ [
+ "vl_api_prefix_t",
+ "prefix"
+ ],
+ [
+ "u8",
+ "n_paths"
+ ],
+ [
+ "vl_api_fib_path_t",
+ "paths",
+ 0,
+ "n_paths"
+ ]
+ ],
+ [
+ "ip_mroute",
+ [
+ "u32",
+ "table_id"
+ ],
+ [
+ "u32",
+ "entry_flags"
+ ],
+ [
+ "u32",
+ "rpf_id"
+ ],
+ [
+ "vl_api_mprefix_t",
+ "prefix"
+ ],
+ [
+ "u8",
+ "n_paths"
+ ],
+ [
+ "vl_api_mfib_path_t",
+ "paths",
+ 0,
+ "n_paths"
+ ]
+ ],
+ [
+ "punt_redirect",
+ [
+ "vl_api_interface_index_t",
+ "rx_sw_if_index"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "tx_sw_if_index"
+ ],
+ [
+ "vl_api_address_t",
+ "nh"
+ ]
+ ]
+ ],
+ "messages": [
+ [
+ "ip_table_add_del",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "bool",
+ "is_add",
+ {
+ "default": "true"
+ }
+ ],
+ [
+ "vl_api_ip_table_t",
+ "table"
+ ],
+ {
+ "crc": "0x0ffdaec0"
+ }
+ ],
+ [
+ "ip_table_add_del_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_table_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ {
+ "crc": "0x51077d14"
+ }
+ ],
+ [
+ "ip_table_replace_begin",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_ip_table_t",
+ "table"
+ ],
+ {
+ "crc": "0xb9d2e09e"
+ }
+ ],
+ [
+ "ip_table_replace_begin_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_table_replace_end",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_ip_table_t",
+ "table"
+ ],
+ {
+ "crc": "0xb9d2e09e"
+ }
+ ],
+ [
+ "ip_table_replace_end_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_table_flush",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_ip_table_t",
+ "table"
+ ],
+ {
+ "crc": "0xb9d2e09e"
+ }
+ ],
+ [
+ "ip_table_flush_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_table_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_ip_table_t",
+ "table"
+ ],
+ {
+ "crc": "0xc79fca0f"
+ }
+ ],
+ [
+ "ip_route_add_del",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "bool",
+ "is_add",
+ {
+ "default": "true"
+ }
+ ],
+ [
+ "bool",
+ "is_multipath"
+ ],
+ [
+ "vl_api_ip_route_t",
+ "route"
+ ],
+ {
+ "crc": "0xc1ff832d"
+ }
+ ],
+ [
+ "ip_route_add_del_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "u32",
+ "stats_index"
+ ],
+ {
+ "crc": "0x1992deab"
+ }
+ ],
+ [
+ "ip_route_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_ip_table_t",
+ "table"
+ ],
+ {
+ "crc": "0xb9d2e09e"
+ }
+ ],
+ [
+ "ip_route_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_ip_route_t",
+ "route"
+ ],
+ {
+ "crc": "0xd1ffaae1"
+ }
+ ],
+ [
+ "ip_route_lookup",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "u32",
+ "table_id"
+ ],
+ [
+ "u8",
+ "exact"
+ ],
+ [
+ "vl_api_prefix_t",
+ "prefix"
+ ],
+ {
+ "crc": "0xe2986185"
+ }
+ ],
+ [
+ "ip_route_lookup_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "vl_api_ip_route_t",
+ "route"
+ ],
+ {
+ "crc": "0xae99de8e"
+ }
+ ],
+ [
+ "set_ip_flow_hash",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "u32",
+ "vrf_id"
+ ],
+ [
+ "bool",
+ "is_ipv6"
+ ],
+ [
+ "bool",
+ "src"
+ ],
+ [
+ "bool",
+ "dst"
+ ],
+ [
+ "bool",
+ "sport"
+ ],
+ [
+ "bool",
+ "dport"
+ ],
+ [
+ "bool",
+ "proto"
+ ],
+ [
+ "bool",
+ "reverse"
+ ],
+ [
+ "bool",
+ "symmetric"
+ ],
+ {
+ "crc": "0x084ee09e"
+ }
+ ],
+ [
+ "set_ip_flow_hash_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "sw_interface_ip6_enable_disable",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "bool",
+ "enable"
+ ],
+ {
+ "crc": "0xae6cfcfb"
+ }
+ ],
+ [
+ "sw_interface_ip6_enable_disable_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_mtable_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ {
+ "crc": "0x51077d14"
+ }
+ ],
+ [
+ "ip_mtable_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_ip_table_t",
+ "table"
+ ],
+ {
+ "crc": "0xb9d2e09e"
+ }
+ ],
+ [
+ "ip_mroute_add_del",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "bool",
+ "is_add",
+ {
+ "default": "true"
+ }
+ ],
+ [
+ "bool",
+ "is_multipath"
+ ],
+ [
+ "vl_api_ip_mroute_t",
+ "route"
+ ],
+ {
+ "crc": "0xf6627d17"
+ }
+ ],
+ [
+ "ip_mroute_add_del_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "u32",
+ "stats_index"
+ ],
+ {
+ "crc": "0x1992deab"
+ }
+ ],
+ [
+ "ip_mroute_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_ip_table_t",
+ "table"
+ ],
+ {
+ "crc": "0xb9d2e09e"
+ }
+ ],
+ [
+ "ip_mroute_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_ip_mroute_t",
+ "route"
+ ],
+ {
+ "crc": "0xc1cb4b44"
+ }
+ ],
+ [
+ "ip_address_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "vl_api_address_with_prefix_t",
+ "prefix"
+ ],
+ {
+ "crc": "0xb1199745"
+ }
+ ],
+ [
+ "ip_address_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "bool",
+ "is_ipv6"
+ ],
+ {
+ "crc": "0x2d033de4"
+ }
+ ],
+ [
+ "ip_unnumbered_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "ip_sw_if_index"
+ ],
+ {
+ "crc": "0xaa12a483"
+ }
+ ],
+ [
+ "ip_unnumbered_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index",
+ {
+ "default": 4294967295
+ }
+ ],
+ {
+ "crc": "0xf9e6675e"
+ }
+ ],
+ [
+ "ip_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "bool",
+ "is_ipv6"
+ ],
+ {
+ "crc": "0xeb152d07"
+ }
+ ],
+ [
+ "ip_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "bool",
+ "is_ipv6"
+ ],
+ {
+ "crc": "0x98d231ca"
+ }
+ ],
+ [
+ "mfib_signal_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ {
+ "crc": "0x51077d14"
+ }
+ ],
+ [
+ "mfib_signal_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "u32",
+ "table_id"
+ ],
+ [
+ "vl_api_mprefix_t",
+ "prefix"
+ ],
+ [
+ "u16",
+ "ip_packet_len"
+ ],
+ [
+ "u8",
+ "ip_packet_data",
+ 256
+ ],
+ {
+ "crc": "0x64398a9a"
+ }
+ ],
+ [
+ "ip_punt_police",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "u32",
+ "policer_index"
+ ],
+ [
+ "bool",
+ "is_add",
+ {
+ "default": "true"
+ }
+ ],
+ [
+ "bool",
+ "is_ip6"
+ ],
+ {
+ "crc": "0xdb867cea"
+ }
+ ],
+ [
+ "ip_punt_police_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_punt_redirect",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_punt_redirect_t",
+ "punt"
+ ],
+ [
+ "bool",
+ "is_add",
+ {
+ "default": "true"
+ }
+ ],
+ {
+ "crc": "0xa9a5592c"
+ }
+ ],
+ [
+ "ip_punt_redirect_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_punt_redirect_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "bool",
+ "is_ipv6"
+ ],
+ {
+ "crc": "0x2d033de4"
+ }
+ ],
+ [
+ "ip_punt_redirect_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_punt_redirect_t",
+ "punt"
+ ],
+ {
+ "crc": "0x3924f5d3"
+ }
+ ],
+ [
+ "ip_container_proxy_add_del",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_prefix_t",
+ "pfx"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "bool",
+ "is_add",
+ {
+ "default": "true"
+ }
+ ],
+ {
+ "crc": "0x91189f40"
+ }
+ ],
+ [
+ "ip_container_proxy_add_del_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_container_proxy_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ {
+ "crc": "0x51077d14"
+ }
+ ],
+ [
+ "ip_container_proxy_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "vl_api_prefix_t",
+ "prefix"
+ ],
+ {
+ "crc": "0x0ee460e8"
+ }
+ ],
+ [
+ "ip_source_and_port_range_check_add_del",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "bool",
+ "is_add",
+ {
+ "default": "true"
+ }
+ ],
+ [
+ "vl_api_prefix_t",
+ "prefix"
+ ],
+ [
+ "u8",
+ "number_of_ranges"
+ ],
+ [
+ "u16",
+ "low_ports",
+ 32
+ ],
+ [
+ "u16",
+ "high_ports",
+ 32
+ ],
+ [
+ "u32",
+ "vrf_id"
+ ],
+ {
+ "crc": "0x8bfc76f2"
+ }
+ ],
+ [
+ "ip_source_and_port_range_check_add_del_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_source_and_port_range_check_interface_add_del",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "bool",
+ "is_add",
+ {
+ "default": "true"
+ }
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "u32",
+ "tcp_in_vrf_id"
+ ],
+ [
+ "u32",
+ "tcp_out_vrf_id"
+ ],
+ [
+ "u32",
+ "udp_in_vrf_id"
+ ],
+ [
+ "u32",
+ "udp_out_vrf_id"
+ ],
+ {
+ "crc": "0xe1ba8987"
+ }
+ ],
+ [
+ "ip_source_and_port_range_check_interface_add_del_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "sw_interface_ip6_set_link_local_address",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "vl_api_ip6_address_t",
+ "ip"
+ ],
+ {
+ "crc": "0x2931d9fa"
+ }
+ ],
+ [
+ "sw_interface_ip6_set_link_local_address_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ioam_enable",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "u16",
+ "id"
+ ],
+ [
+ "bool",
+ "seqno"
+ ],
+ [
+ "bool",
+ "analyse"
+ ],
+ [
+ "bool",
+ "pot_enable"
+ ],
+ [
+ "bool",
+ "trace_enable"
+ ],
+ [
+ "u32",
+ "node_id"
+ ],
+ {
+ "crc": "0x51ccd868"
+ }
+ ],
+ [
+ "ioam_enable_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ioam_disable",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "u16",
+ "id"
+ ],
+ {
+ "crc": "0x6b16a45e"
+ }
+ ],
+ [
+ "ioam_disable_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_reassembly_set",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "u32",
+ "timeout_ms"
+ ],
+ [
+ "u32",
+ "max_reassemblies"
+ ],
+ [
+ "u32",
+ "max_reassembly_length"
+ ],
+ [
+ "u32",
+ "expire_walk_interval_ms"
+ ],
+ [
+ "bool",
+ "is_ip6"
+ ],
+ [
+ "vl_api_ip_reass_type_t",
+ "type"
+ ],
+ {
+ "crc": "0x16467d25"
+ }
+ ],
+ [
+ "ip_reassembly_set_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ],
+ [
+ "ip_reassembly_get",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "bool",
+ "is_ip6"
+ ],
+ [
+ "vl_api_ip_reass_type_t",
+ "type"
+ ],
+ {
+ "crc": "0xea13ff63"
+ }
+ ],
+ [
+ "ip_reassembly_get_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "u32",
+ "timeout_ms"
+ ],
+ [
+ "u32",
+ "max_reassemblies"
+ ],
+ [
+ "u32",
+ "max_reassembly_length"
+ ],
+ [
+ "u32",
+ "expire_walk_interval_ms"
+ ],
+ [
+ "bool",
+ "is_ip6"
+ ],
+ {
+ "crc": "0xd5eb8d34"
+ }
+ ],
+ [
+ "ip_reassembly_enable_disable",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_interface_index_t",
+ "sw_if_index"
+ ],
+ [
+ "bool",
+ "enable_ip4"
+ ],
+ [
+ "bool",
+ "enable_ip6"
+ ],
+ [
+ "vl_api_ip_reass_type_t",
+ "type"
+ ],
+ {
+ "crc": "0x885c85a6"
+ }
+ ],
+ [
+ "ip_reassembly_enable_disable_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ {
+ "crc": "0xe8d4e804"
+ }
+ ]
+ ],
+ "unions": [
+ [
+ "address_union",
+ [
+ "vl_api_ip4_address_t",
+ "ip4"
+ ],
+ [
+ "vl_api_ip6_address_t",
+ "ip6"
+ ]
+ ],
+ [
+ "address_union",
+ [
+ "vl_api_ip4_address_t",
+ "ip4"
+ ],
+ [
+ "vl_api_ip6_address_t",
+ "ip6"
+ ]
+ ],
+ [
+ "address_union",
+ [
+ "vl_api_ip4_address_t",
+ "ip4"
+ ],
+ [
+ "vl_api_ip6_address_t",
+ "ip6"
+ ]
+ ]
+ ],
+ "enums": [
+ [
+ "if_status_flags",
+ [
+ "IF_STATUS_API_FLAG_ADMIN_UP",
+ 1
+ ],
+ [
+ "IF_STATUS_API_FLAG_LINK_UP",
+ 2
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "mtu_proto",
+ [
+ "MTU_PROTO_API_L3",
+ 0
+ ],
+ [
+ "MTU_PROTO_API_IP4",
+ 1
+ ],
+ [
+ "MTU_PROTO_API_IP6",
+ 2
+ ],
+ [
+ "MTU_PROTO_API_MPLS",
+ 3
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "link_duplex",
+ [
+ "LINK_DUPLEX_API_UNKNOWN",
+ 0
+ ],
+ [
+ "LINK_DUPLEX_API_HALF",
+ 1
+ ],
+ [
+ "LINK_DUPLEX_API_FULL",
+ 2
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "sub_if_flags",
+ [
+ "SUB_IF_API_FLAG_NO_TAGS",
+ 1
+ ],
+ [
+ "SUB_IF_API_FLAG_ONE_TAG",
+ 2
+ ],
+ [
+ "SUB_IF_API_FLAG_TWO_TAGS",
+ 4
+ ],
+ [
+ "SUB_IF_API_FLAG_DOT1AD",
+ 8
+ ],
+ [
+ "SUB_IF_API_FLAG_EXACT_MATCH",
+ 16
+ ],
+ [
+ "SUB_IF_API_FLAG_DEFAULT",
+ 32
+ ],
+ [
+ "SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY",
+ 64
+ ],
+ [
+ "SUB_IF_API_FLAG_INNER_VLAN_ID_ANY",
+ 128
+ ],
+ [
+ "SUB_IF_API_FLAG_MASK_VNET",
+ 254
+ ],
+ [
+ "SUB_IF_API_FLAG_DOT1AH",
+ 256
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "rx_mode",
+ [
+ "RX_MODE_API_UNKNOWN",
+ 0
+ ],
+ [
+ "RX_MODE_API_POLLING",
+ 1
+ ],
+ [
+ "RX_MODE_API_INTERRUPT",
+ 2
+ ],
+ [
+ "RX_MODE_API_ADAPTIVE",
+ 3
+ ],
+ [
+ "RX_MODE_API_DEFAULT",
+ 4
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "if_type",
+ [
+ "IF_API_TYPE_HARDWARE",
+ 0
+ ],
+ [
+ "IF_API_TYPE_SUB",
+ 1
+ ],
+ [
+ "IF_API_TYPE_P2P",
+ 2
+ ],
+ [
+ "IF_API_TYPE_PIPE",
+ 3
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "address_family",
+ [
+ "ADDRESS_IP4",
+ 0
+ ],
+ [
+ "ADDRESS_IP6",
+ 1
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "ip_ecn",
+ [
+ "IP_API_ECN_NONE",
+ 0
+ ],
+ [
+ "IP_API_ECN_ECT0",
+ 1
+ ],
+ [
+ "IP_API_ECN_ECT1",
+ 2
+ ],
+ [
+ "IP_API_ECN_CE",
+ 3
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "ip_dscp",
+ [
+ "IP_API_DSCP_CS0",
+ 0
+ ],
+ [
+ "IP_API_DSCP_CS1",
+ 8
+ ],
+ [
+ "IP_API_DSCP_AF11",
+ 10
+ ],
+ [
+ "IP_API_DSCP_AF12",
+ 12
+ ],
+ [
+ "IP_API_DSCP_AF13",
+ 14
+ ],
+ [
+ "IP_API_DSCP_CS2",
+ 16
+ ],
+ [
+ "IP_API_DSCP_AF21",
+ 18
+ ],
+ [
+ "IP_API_DSCP_AF22",
+ 20
+ ],
+ [
+ "IP_API_DSCP_AF23",
+ 22
+ ],
+ [
+ "IP_API_DSCP_CS3",
+ 24
+ ],
+ [
+ "IP_API_DSCP_AF31",
+ 26
+ ],
+ [
+ "IP_API_DSCP_AF32",
+ 28
+ ],
+ [
+ "IP_API_DSCP_AF33",
+ 30
+ ],
+ [
+ "IP_API_DSCP_CS4",
+ 32
+ ],
+ [
+ "IP_API_DSCP_AF41",
+ 34
+ ],
+ [
+ "IP_API_DSCP_AF42",
+ 36
+ ],
+ [
+ "IP_API_DSCP_AF43",
+ 38
+ ],
+ [
+ "IP_API_DSCP_CS5",
+ 40
+ ],
+ [
+ "IP_API_DSCP_EF",
+ 46
+ ],
+ [
+ "IP_API_DSCP_CS6",
+ 48
+ ],
+ [
+ "IP_API_DSCP_CS7",
+ 50
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "ip_proto",
+ [
+ "IP_API_PROTO_HOPOPT",
+ 0
+ ],
+ [
+ "IP_API_PROTO_ICMP",
+ 1
+ ],
+ [
+ "IP_API_PROTO_IGMP",
+ 2
+ ],
+ [
+ "IP_API_PROTO_TCP",
+ 6
+ ],
+ [
+ "IP_API_PROTO_UDP",
+ 17
+ ],
+ [
+ "IP_API_PROTO_GRE",
+ 47
+ ],
+ [
+ "IP_API_PROTO_ESP",
+ 50
+ ],
+ [
+ "IP_API_PROTO_AH",
+ 51
+ ],
+ [
+ "IP_API_PROTO_ICMP6",
+ 58
+ ],
+ [
+ "IP_API_PROTO_EIGRP",
+ 88
+ ],
+ [
+ "IP_API_PROTO_OSPF",
+ 89
+ ],
+ [
+ "IP_API_PROTO_SCTP",
+ 132
+ ],
+ [
+ "IP_API_PROTO_RESERVED",
+ 255
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "fib_path_nh_proto",
+ [
+ "FIB_API_PATH_NH_PROTO_IP4",
+ 0
+ ],
+ [
+ "FIB_API_PATH_NH_PROTO_IP6",
+ 1
+ ],
+ [
+ "FIB_API_PATH_NH_PROTO_MPLS",
+ 2
+ ],
+ [
+ "FIB_API_PATH_NH_PROTO_ETHERNET",
+ 3
+ ],
+ [
+ "FIB_API_PATH_NH_PROTO_BIER",
+ 4
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "fib_path_flags",
+ [
+ "FIB_API_PATH_FLAG_NONE",
+ 0
+ ],
+ [
+ "FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED",
+ 1
+ ],
+ [
+ "FIB_API_PATH_FLAG_RESOLVE_VIA_HOST",
+ 2
+ ],
+ [
+ "FIB_API_PATH_FLAG_POP_PW_CW",
+ 4
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "fib_path_type",
+ [
+ "FIB_API_PATH_TYPE_NORMAL",
+ 0
+ ],
+ [
+ "FIB_API_PATH_TYPE_LOCAL",
+ 1
+ ],
+ [
+ "FIB_API_PATH_TYPE_DROP",
+ 2
+ ],
+ [
+ "FIB_API_PATH_TYPE_UDP_ENCAP",
+ 3
+ ],
+ [
+ "FIB_API_PATH_TYPE_BIER_IMP",
+ 4
+ ],
+ [
+ "FIB_API_PATH_TYPE_ICMP_UNREACH",
+ 5
+ ],
+ [
+ "FIB_API_PATH_TYPE_ICMP_PROHIBIT",
+ 6
+ ],
+ [
+ "FIB_API_PATH_TYPE_SOURCE_LOOKUP",
+ 7
+ ],
+ [
+ "FIB_API_PATH_TYPE_DVR",
+ 8
+ ],
+ [
+ "FIB_API_PATH_TYPE_INTERFACE_RX",
+ 9
+ ],
+ [
+ "FIB_API_PATH_TYPE_CLASSIFY",
+ 10
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "address_family",
+ [
+ "ADDRESS_IP4",
+ 0
+ ],
+ [
+ "ADDRESS_IP6",
+ 1
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "ip_ecn",
+ [
+ "IP_API_ECN_NONE",
+ 0
+ ],
+ [
+ "IP_API_ECN_ECT0",
+ 1
+ ],
+ [
+ "IP_API_ECN_ECT1",
+ 2
+ ],
+ [
+ "IP_API_ECN_CE",
+ 3
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "ip_dscp",
+ [
+ "IP_API_DSCP_CS0",
+ 0
+ ],
+ [
+ "IP_API_DSCP_CS1",
+ 8
+ ],
+ [
+ "IP_API_DSCP_AF11",
+ 10
+ ],
+ [
+ "IP_API_DSCP_AF12",
+ 12
+ ],
+ [
+ "IP_API_DSCP_AF13",
+ 14
+ ],
+ [
+ "IP_API_DSCP_CS2",
+ 16
+ ],
+ [
+ "IP_API_DSCP_AF21",
+ 18
+ ],
+ [
+ "IP_API_DSCP_AF22",
+ 20
+ ],
+ [
+ "IP_API_DSCP_AF23",
+ 22
+ ],
+ [
+ "IP_API_DSCP_CS3",
+ 24
+ ],
+ [
+ "IP_API_DSCP_AF31",
+ 26
+ ],
+ [
+ "IP_API_DSCP_AF32",
+ 28
+ ],
+ [
+ "IP_API_DSCP_AF33",
+ 30
+ ],
+ [
+ "IP_API_DSCP_CS4",
+ 32
+ ],
+ [
+ "IP_API_DSCP_AF41",
+ 34
+ ],
+ [
+ "IP_API_DSCP_AF42",
+ 36
+ ],
+ [
+ "IP_API_DSCP_AF43",
+ 38
+ ],
+ [
+ "IP_API_DSCP_CS5",
+ 40
+ ],
+ [
+ "IP_API_DSCP_EF",
+ 46
+ ],
+ [
+ "IP_API_DSCP_CS6",
+ 48
+ ],
+ [
+ "IP_API_DSCP_CS7",
+ 50
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "ip_proto",
+ [
+ "IP_API_PROTO_HOPOPT",
+ 0
+ ],
+ [
+ "IP_API_PROTO_ICMP",
+ 1
+ ],
+ [
+ "IP_API_PROTO_IGMP",
+ 2
+ ],
+ [
+ "IP_API_PROTO_TCP",
+ 6
+ ],
+ [
+ "IP_API_PROTO_UDP",
+ 17
+ ],
+ [
+ "IP_API_PROTO_GRE",
+ 47
+ ],
+ [
+ "IP_API_PROTO_ESP",
+ 50
+ ],
+ [
+ "IP_API_PROTO_AH",
+ 51
+ ],
+ [
+ "IP_API_PROTO_ICMP6",
+ 58
+ ],
+ [
+ "IP_API_PROTO_EIGRP",
+ 88
+ ],
+ [
+ "IP_API_PROTO_OSPF",
+ 89
+ ],
+ [
+ "IP_API_PROTO_SCTP",
+ 132
+ ],
+ [
+ "IP_API_PROTO_RESERVED",
+ 255
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "fib_path_nh_proto",
+ [
+ "FIB_API_PATH_NH_PROTO_IP4",
+ 0
+ ],
+ [
+ "FIB_API_PATH_NH_PROTO_IP6",
+ 1
+ ],
+ [
+ "FIB_API_PATH_NH_PROTO_MPLS",
+ 2
+ ],
+ [
+ "FIB_API_PATH_NH_PROTO_ETHERNET",
+ 3
+ ],
+ [
+ "FIB_API_PATH_NH_PROTO_BIER",
+ 4
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "fib_path_flags",
+ [
+ "FIB_API_PATH_FLAG_NONE",
+ 0
+ ],
+ [
+ "FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED",
+ 1
+ ],
+ [
+ "FIB_API_PATH_FLAG_RESOLVE_VIA_HOST",
+ 2
+ ],
+ [
+ "FIB_API_PATH_FLAG_POP_PW_CW",
+ 4
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "fib_path_type",
+ [
+ "FIB_API_PATH_TYPE_NORMAL",
+ 0
+ ],
+ [
+ "FIB_API_PATH_TYPE_LOCAL",
+ 1
+ ],
+ [
+ "FIB_API_PATH_TYPE_DROP",
+ 2
+ ],
+ [
+ "FIB_API_PATH_TYPE_UDP_ENCAP",
+ 3
+ ],
+ [
+ "FIB_API_PATH_TYPE_BIER_IMP",
+ 4
+ ],
+ [
+ "FIB_API_PATH_TYPE_ICMP_UNREACH",
+ 5
+ ],
+ [
+ "FIB_API_PATH_TYPE_ICMP_PROHIBIT",
+ 6
+ ],
+ [
+ "FIB_API_PATH_TYPE_SOURCE_LOOKUP",
+ 7
+ ],
+ [
+ "FIB_API_PATH_TYPE_DVR",
+ 8
+ ],
+ [
+ "FIB_API_PATH_TYPE_INTERFACE_RX",
+ 9
+ ],
+ [
+ "FIB_API_PATH_TYPE_CLASSIFY",
+ 10
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "address_family",
+ [
+ "ADDRESS_IP4",
+ 0
+ ],
+ [
+ "ADDRESS_IP6",
+ 1
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "ip_ecn",
+ [
+ "IP_API_ECN_NONE",
+ 0
+ ],
+ [
+ "IP_API_ECN_ECT0",
+ 1
+ ],
+ [
+ "IP_API_ECN_ECT1",
+ 2
+ ],
+ [
+ "IP_API_ECN_CE",
+ 3
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "ip_dscp",
+ [
+ "IP_API_DSCP_CS0",
+ 0
+ ],
+ [
+ "IP_API_DSCP_CS1",
+ 8
+ ],
+ [
+ "IP_API_DSCP_AF11",
+ 10
+ ],
+ [
+ "IP_API_DSCP_AF12",
+ 12
+ ],
+ [
+ "IP_API_DSCP_AF13",
+ 14
+ ],
+ [
+ "IP_API_DSCP_CS2",
+ 16
+ ],
+ [
+ "IP_API_DSCP_AF21",
+ 18
+ ],
+ [
+ "IP_API_DSCP_AF22",
+ 20
+ ],
+ [
+ "IP_API_DSCP_AF23",
+ 22
+ ],
+ [
+ "IP_API_DSCP_CS3",
+ 24
+ ],
+ [
+ "IP_API_DSCP_AF31",
+ 26
+ ],
+ [
+ "IP_API_DSCP_AF32",
+ 28
+ ],
+ [
+ "IP_API_DSCP_AF33",
+ 30
+ ],
+ [
+ "IP_API_DSCP_CS4",
+ 32
+ ],
+ [
+ "IP_API_DSCP_AF41",
+ 34
+ ],
+ [
+ "IP_API_DSCP_AF42",
+ 36
+ ],
+ [
+ "IP_API_DSCP_AF43",
+ 38
+ ],
+ [
+ "IP_API_DSCP_CS5",
+ 40
+ ],
+ [
+ "IP_API_DSCP_EF",
+ 46
+ ],
+ [
+ "IP_API_DSCP_CS6",
+ 48
+ ],
+ [
+ "IP_API_DSCP_CS7",
+ 50
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "ip_proto",
+ [
+ "IP_API_PROTO_HOPOPT",
+ 0
+ ],
+ [
+ "IP_API_PROTO_ICMP",
+ 1
+ ],
+ [
+ "IP_API_PROTO_IGMP",
+ 2
+ ],
+ [
+ "IP_API_PROTO_TCP",
+ 6
+ ],
+ [
+ "IP_API_PROTO_UDP",
+ 17
+ ],
+ [
+ "IP_API_PROTO_GRE",
+ 47
+ ],
+ [
+ "IP_API_PROTO_ESP",
+ 50
+ ],
+ [
+ "IP_API_PROTO_AH",
+ 51
+ ],
+ [
+ "IP_API_PROTO_ICMP6",
+ 58
+ ],
+ [
+ "IP_API_PROTO_EIGRP",
+ 88
+ ],
+ [
+ "IP_API_PROTO_OSPF",
+ 89
+ ],
+ [
+ "IP_API_PROTO_SCTP",
+ 132
+ ],
+ [
+ "IP_API_PROTO_RESERVED",
+ 255
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "mfib_itf_flags",
+ [
+ "MFIB_API_ITF_FLAG_NONE",
+ 0
+ ],
+ [
+ "MFIB_API_ITF_FLAG_NEGATE_SIGNAL",
+ 1
+ ],
+ [
+ "MFIB_API_ITF_FLAG_ACCEPT",
+ 2
+ ],
+ [
+ "MFIB_API_ITF_FLAG_FORWARD",
+ 4
+ ],
+ [
+ "MFIB_API_ITF_FLAG_SIGNAL_PRESENT",
+ 8
+ ],
+ [
+ "MFIB_API_ITF_FLAG_DONT_PRESERVE",
+ 16
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "if_status_flags",
+ [
+ "IF_STATUS_API_FLAG_ADMIN_UP",
+ 1
+ ],
+ [
+ "IF_STATUS_API_FLAG_LINK_UP",
+ 2
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "mtu_proto",
+ [
+ "MTU_PROTO_API_L3",
+ 0
+ ],
+ [
+ "MTU_PROTO_API_IP4",
+ 1
+ ],
+ [
+ "MTU_PROTO_API_IP6",
+ 2
+ ],
+ [
+ "MTU_PROTO_API_MPLS",
+ 3
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "link_duplex",
+ [
+ "LINK_DUPLEX_API_UNKNOWN",
+ 0
+ ],
+ [
+ "LINK_DUPLEX_API_HALF",
+ 1
+ ],
+ [
+ "LINK_DUPLEX_API_FULL",
+ 2
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "sub_if_flags",
+ [
+ "SUB_IF_API_FLAG_NO_TAGS",
+ 1
+ ],
+ [
+ "SUB_IF_API_FLAG_ONE_TAG",
+ 2
+ ],
+ [
+ "SUB_IF_API_FLAG_TWO_TAGS",
+ 4
+ ],
+ [
+ "SUB_IF_API_FLAG_DOT1AD",
+ 8
+ ],
+ [
+ "SUB_IF_API_FLAG_EXACT_MATCH",
+ 16
+ ],
+ [
+ "SUB_IF_API_FLAG_DEFAULT",
+ 32
+ ],
+ [
+ "SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY",
+ 64
+ ],
+ [
+ "SUB_IF_API_FLAG_INNER_VLAN_ID_ANY",
+ 128
+ ],
+ [
+ "SUB_IF_API_FLAG_MASK_VNET",
+ 254
+ ],
+ [
+ "SUB_IF_API_FLAG_DOT1AH",
+ 256
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "rx_mode",
+ [
+ "RX_MODE_API_UNKNOWN",
+ 0
+ ],
+ [
+ "RX_MODE_API_POLLING",
+ 1
+ ],
+ [
+ "RX_MODE_API_INTERRUPT",
+ 2
+ ],
+ [
+ "RX_MODE_API_ADAPTIVE",
+ 3
+ ],
+ [
+ "RX_MODE_API_DEFAULT",
+ 4
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "if_type",
+ [
+ "IF_API_TYPE_HARDWARE",
+ 0
+ ],
+ [
+ "IF_API_TYPE_SUB",
+ 1
+ ],
+ [
+ "IF_API_TYPE_P2P",
+ 2
+ ],
+ [
+ "IF_API_TYPE_PIPE",
+ 3
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ],
+ [
+ "ip_reass_type",
+ [
+ "IP_REASS_TYPE_FULL",
+ 0
+ ],
+ [
+ "IP_REASS_TYPE_SHALLOW_VIRTUAL",
+ 1
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ]
+ ],
+ "services": {
+ "ip_table_add_del": {
+ "reply": "ip_table_add_del_reply"
+ },
+ "ip_table_dump": {
+ "reply": "ip_table_details",
+ "stream": true
+ },
+ "ip_table_replace_begin": {
+ "reply": "ip_table_replace_begin_reply"
+ },
+ "ip_table_replace_end": {
+ "reply": "ip_table_replace_end_reply"
+ },
+ "ip_table_flush": {
+ "reply": "ip_table_flush_reply"
+ },
+ "ip_route_add_del": {
+ "reply": "ip_route_add_del_reply"
+ },
+ "ip_route_dump": {
+ "reply": "ip_route_details",
+ "stream": true
+ },
+ "ip_route_lookup": {
+ "reply": "ip_route_lookup_reply"
+ },
+ "set_ip_flow_hash": {
+ "reply": "set_ip_flow_hash_reply"
+ },
+ "sw_interface_ip6_enable_disable": {
+ "reply": "sw_interface_ip6_enable_disable_reply"
+ },
+ "ip_mtable_dump": {
+ "reply": "ip_mtable_details",
+ "stream": true
+ },
+ "ip_mroute_add_del": {
+ "reply": "ip_mroute_add_del_reply"
+ },
+ "ip_mroute_dump": {
+ "reply": "ip_mroute_details",
+ "stream": true
+ },
+ "ip_address_dump": {
+ "reply": "ip_address_details",
+ "stream": true
+ },
+ "ip_unnumbered_dump": {
+ "reply": "ip_unnumbered_details",
+ "stream": true
+ },
+ "ip_dump": {
+ "reply": "ip_details",
+ "stream": true
+ },
+ "mfib_signal_dump": {
+ "reply": "mfib_signal_details",
+ "stream": true
+ },
+ "ip_punt_police": {
+ "reply": "ip_punt_police_reply"
+ },
+ "ip_punt_redirect": {
+ "reply": "ip_punt_redirect_reply"
+ },
+ "ip_punt_redirect_dump": {
+ "reply": "ip_punt_redirect_details",
+ "stream": true
+ },
+ "ip_container_proxy_add_del": {
+ "reply": "ip_container_proxy_add_del_reply"
+ },
+ "ip_container_proxy_dump": {
+ "reply": "ip_container_proxy_details",
+ "stream": true
+ },
+ "ip_source_and_port_range_check_add_del": {
+ "reply": "ip_source_and_port_range_check_add_del_reply"
+ },
+ "ip_source_and_port_range_check_interface_add_del": {
+ "reply": "ip_source_and_port_range_check_interface_add_del_reply"
+ },
+ "sw_interface_ip6_set_link_local_address": {
+ "reply": "sw_interface_ip6_set_link_local_address_reply"
+ },
+ "ioam_enable": {
+ "reply": "ioam_enable_reply"
+ },
+ "ioam_disable": {
+ "reply": "ioam_disable_reply"
+ },
+ "ip_reassembly_set": {
+ "reply": "ip_reassembly_set_reply"
+ },
+ "ip_reassembly_get": {
+ "reply": "ip_reassembly_get_reply"
+ },
+ "ip_reassembly_enable_disable": {
+ "reply": "ip_reassembly_enable_disable_reply"
+ }
+ },
+ "options": {
+ "version": "3.0.1"
+ },
+ "aliases": {
+ "interface_index": {
+ "type": "u32"
+ },
+ "ip4_address": {
+ "type": "u8",
+ "length": 4
+ },
+ "ip6_address": {
+ "type": "u8",
+ "length": 16
+ },
+ "address_with_prefix": {
+ "type": "vl_api_prefix_t"
+ },
+ "ip4_address_with_prefix": {
+ "type": "vl_api_ip4_prefix_t"
+ },
+ "ip6_address_with_prefix": {
+ "type": "vl_api_ip6_prefix_t"
+ },
+ "mac_address": {
+ "type": "u8",
+ "length": 6
+ }
+ },
+ "vl_api_version": "0x765d74b1",
+ "imports": [
+ "vnet/interface_types.api",
+ "vnet/fib/fib_types.api",
+ "vnet/ip/ip_types.api",
+ "vnet/ethernet/ethernet_types.api",
+ "vnet/mfib/mfib_types.api",
+ "vnet/fib/fib_types.api",
+ "vnet/ip/ip_types.api",
+ "vnet/ip/ip_types.api",
+ "vnet/interface_types.api"
+ ]
+ }
+]
diff --git a/binapigen/vppapi/testdata/vpe.api.json b/binapigen/vppapi/testdata/vpe.api.json
new file mode 100644
index 0000000..960ba12
--- /dev/null
+++ b/binapigen/vppapi/testdata/vpe.api.json
@@ -0,0 +1,775 @@
+{
+ "types": [
+ [
+ "version",
+ [
+ "u32",
+ "major"
+ ],
+ [
+ "u32",
+ "minor"
+ ],
+ [
+ "u32",
+ "patch"
+ ],
+ [
+ "u8",
+ "pre_release",
+ 17
+ ],
+ [
+ "u8",
+ "build_metadata",
+ 17
+ ]
+ ],
+ [
+ "thread_data",
+ [
+ "u32",
+ "id"
+ ],
+ [
+ "string",
+ "name",
+ 64
+ ],
+ [
+ "string",
+ "type",
+ 64
+ ],
+ [
+ "u32",
+ "pid"
+ ],
+ [
+ "u32",
+ "cpu_id"
+ ],
+ [
+ "u32",
+ "core"
+ ],
+ [
+ "u32",
+ "cpu_socket"
+ ]
+ ]
+ ],
+ "messages": [
+ [
+ "control_ping",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ {
+ "crc": "0x51077d14"
+ }
+ ],
+ [
+ "control_ping_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "vpe_pid"
+ ],
+ {
+ "crc": "0xf6b0b8ca"
+ }
+ ],
+ [
+ "cli",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "u64",
+ "cmd_in_shmem"
+ ],
+ {
+ "crc": "0x23bfbfff"
+ }
+ ],
+ [
+ "cli_inband",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "string",
+ "cmd",
+ 0
+ ],
+ {
+ "crc": "0xf8377302"
+ }
+ ],
+ [
+ "cli_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "u64",
+ "reply_in_shmem"
+ ],
+ {
+ "crc": "0x06d68297"
+ }
+ ],
+ [
+ "cli_inband_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "string",
+ "reply",
+ 0
+ ],
+ {
+ "crc": "0x05879051"
+ }
+ ],
+ [
+ "get_node_index",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "string",
+ "node_name",
+ 64
+ ],
+ {
+ "crc": "0xf1984c64"
+ }
+ ],
+ [
+ "get_node_index_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "u32",
+ "node_index"
+ ],
+ {
+ "crc": "0xa8600b89"
+ }
+ ],
+ [
+ "add_node_next",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "string",
+ "node_name",
+ 64
+ ],
+ [
+ "string",
+ "next_name",
+ 64
+ ],
+ {
+ "crc": "0x2457116d"
+ }
+ ],
+ [
+ "add_node_next_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "u32",
+ "next_index"
+ ],
+ {
+ "crc": "0x2ed75f32"
+ }
+ ],
+ [
+ "show_version",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ {
+ "crc": "0x51077d14"
+ }
+ ],
+ [
+ "show_version_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "string",
+ "program",
+ 32
+ ],
+ [
+ "string",
+ "version",
+ 32
+ ],
+ [
+ "string",
+ "build_date",
+ 32
+ ],
+ [
+ "string",
+ "build_directory",
+ 256
+ ],
+ {
+ "crc": "0xc919bde1"
+ }
+ ],
+ [
+ "show_threads",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ {
+ "crc": "0x51077d14"
+ }
+ ],
+ [
+ "show_threads_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "u32",
+ "count"
+ ],
+ [
+ "vl_api_thread_data_t",
+ "thread_data",
+ 0,
+ "count"
+ ],
+ {
+ "crc": "0xefd78e83"
+ }
+ ],
+ [
+ "get_node_graph",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ {
+ "crc": "0x51077d14"
+ }
+ ],
+ [
+ "get_node_graph_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "u64",
+ "reply_in_shmem"
+ ],
+ {
+ "crc": "0x06d68297"
+ }
+ ],
+ [
+ "get_next_index",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "string",
+ "node_name",
+ 64
+ ],
+ [
+ "string",
+ "next_name",
+ 64
+ ],
+ {
+ "crc": "0x2457116d"
+ }
+ ],
+ [
+ "get_next_index_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "u32",
+ "next_index"
+ ],
+ {
+ "crc": "0x2ed75f32"
+ }
+ ],
+ [
+ "log_dump",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_timestamp_t",
+ "start_timestamp"
+ ],
+ {
+ "crc": "0x6ab31753"
+ }
+ ],
+ [
+ "log_details",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "vl_api_timestamp_t",
+ "timestamp"
+ ],
+ [
+ "vl_api_log_level_t",
+ "level"
+ ],
+ [
+ "string",
+ "msg_class",
+ 32
+ ],
+ [
+ "string",
+ "message",
+ 256
+ ],
+ {
+ "crc": "0x255827a1"
+ }
+ ],
+ [
+ "show_vpe_system_time",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ {
+ "crc": "0x51077d14"
+ }
+ ],
+ [
+ "show_vpe_system_time_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "i32",
+ "retval"
+ ],
+ [
+ "vl_api_timestamp_t",
+ "vpe_system_time"
+ ],
+ {
+ "crc": "0x7ffd8193"
+ }
+ ],
+ [
+ "get_f64_endian_value",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "f64",
+ "f64_one",
+ {
+ "default": 1.0
+ }
+ ],
+ {
+ "crc": "0x809fcd44"
+ }
+ ],
+ [
+ "get_f64_endian_value_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "u32",
+ "retval"
+ ],
+ [
+ "f64",
+ "f64_one_result"
+ ],
+ {
+ "crc": "0x7e02e404"
+ }
+ ],
+ [
+ "get_f64_increment_by_one",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "client_index"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "f64",
+ "f64_value",
+ {
+ "default": 1.0
+ }
+ ],
+ {
+ "crc": "0xb64f027e"
+ }
+ ],
+ [
+ "get_f64_increment_by_one_reply",
+ [
+ "u16",
+ "_vl_msg_id"
+ ],
+ [
+ "u32",
+ "context"
+ ],
+ [
+ "u32",
+ "retval"
+ ],
+ [
+ "f64",
+ "f64_value"
+ ],
+ {
+ "crc": "0xd25dbaa3"
+ }
+ ]
+ ],
+ "unions": [],
+ "enums": [
+ [
+ "log_level",
+ [
+ "VPE_API_LOG_LEVEL_EMERG",
+ 0
+ ],
+ [
+ "VPE_API_LOG_LEVEL_ALERT",
+ 1
+ ],
+ [
+ "VPE_API_LOG_LEVEL_CRIT",
+ 2
+ ],
+ [
+ "VPE_API_LOG_LEVEL_ERR",
+ 3
+ ],
+ [
+ "VPE_API_LOG_LEVEL_WARNING",
+ 4
+ ],
+ [
+ "VPE_API_LOG_LEVEL_NOTICE",
+ 5
+ ],
+ [
+ "VPE_API_LOG_LEVEL_INFO",
+ 6
+ ],
+ [
+ "VPE_API_LOG_LEVEL_DEBUG",
+ 7
+ ],
+ [
+ "VPE_API_LOG_LEVEL_DISABLED",
+ 8
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ]
+ ],
+ "services": {
+ "control_ping": {
+ "reply": "control_ping_reply"
+ },
+ "cli": {
+ "reply": "cli_reply"
+ },
+ "cli_inband": {
+ "reply": "cli_inband_reply"
+ },
+ "get_node_index": {
+ "reply": "get_node_index_reply"
+ },
+ "add_node_next": {
+ "reply": "add_node_next_reply"
+ },
+ "show_version": {
+ "reply": "show_version_reply"
+ },
+ "show_threads": {
+ "reply": "show_threads_reply"
+ },
+ "get_node_graph": {
+ "reply": "get_node_graph_reply"
+ },
+ "get_next_index": {
+ "reply": "get_next_index_reply"
+ },
+ "log_dump": {
+ "reply": "log_details",
+ "stream": true
+ },
+ "show_vpe_system_time": {
+ "reply": "show_vpe_system_time_reply"
+ },
+ "get_f64_endian_value": {
+ "reply": "get_f64_endian_value_reply"
+ },
+ "get_f64_increment_by_one": {
+ "reply": "get_f64_increment_by_one_reply"
+ }
+ },
+ "options": {
+ "version": "1.6.1"
+ },
+ "aliases": {
+ "timestamp": {
+ "type": "f64"
+ },
+ "timedelta": {
+ "type": "f64"
+ }
+ },
+ "vl_api_version": "0xbd2c94f4",
+ "imports": [
+ "vpp/api/vpe_types.api"
+ ]
+}
diff --git a/cmd/binapi-generator/definitions_test.go b/cmd/binapi-generator/definitions_test.go
deleted file mode 100644
index 30c85ae..0000000
--- a/cmd/binapi-generator/definitions_test.go
+++ /dev/null
@@ -1,25 +0,0 @@
-package main
-
-import (
- "testing"
-)
-
-func TestInitialism(t *testing.T) {
- tests := []struct {
- name string
- input string
- expOutput string
- }{
- {name: "id", input: "id", expOutput: "ID"},
- {name: "ipv6", input: "is_ipv6", expOutput: "IsIPv6"},
- {name: "ip6", input: "is_ip6", expOutput: "IsIP6"},
- }
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- output := camelCaseName(test.input)
- if output != test.expOutput {
- t.Errorf("expected %q, got %q", test.expOutput, output)
- }
- })
- }
-}
diff --git a/cmd/binapi-generator/doc.go b/cmd/binapi-generator/doc.go
index d74d47b..9be49e2 100644
--- a/cmd/binapi-generator/doc.go
+++ b/cmd/binapi-generator/doc.go
@@ -1,4 +1,18 @@
-// Generator of Go structs out of the VPP binary API definitions in JSON format.
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Context of Go structs out of the VPP binary API definitions in JSON format.
//
// The JSON input can be specified as a single file (using the `input-file`
// CLI flag), or as a directory that will be scanned for all `.json` files
diff --git a/cmd/binapi-generator/generate.go b/cmd/binapi-generator/generate.go
deleted file mode 100644
index 715836d..0000000
--- a/cmd/binapi-generator/generate.go
+++ /dev/null
@@ -1,848 +0,0 @@
-// Copyright (c) 2017 Cisco and/or its affiliates.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at:
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package main
-
-import (
- "bytes"
- "fmt"
- "io"
- "os/exec"
- "path"
- "path/filepath"
- "sort"
- "strings"
- "unicode"
-)
-
-// generatedCodeVersion indicates a version of the generated code.
-// It is incremented whenever an incompatibility between the generated code and
-// GoVPP api package is introduced; the generated code references
-// a constant, api.GoVppAPIPackageIsVersionN (where N is generatedCodeVersion).
-const generatedCodeVersion = 1
-
-const (
- inputFileExt = ".api.json" // file extension of the VPP API files
- outputFileExt = ".ba.go" // file extension of the Go generated files
-
- constModuleName = "ModuleName" // module name constant
- constAPIVersion = "APIVersion" // API version constant
- constVersionCrc = "VersionCrc" // version CRC constant
-
- unionDataField = "XXX_UnionData" // name for the union data field
-
- serviceApiName = "RPCService" // name for the RPC service interface
- serviceImplName = "serviceClient" // name for the RPC service implementation
- serviceClientName = "ServiceClient" // name for the RPC service client
-)
-
-// context is a structure storing data for code generation
-type context struct {
- inputFile string // input file with VPP API in JSON
- outputFile string // output file with generated Go package
-
- importPrefix string // defines import path prefix for importing types
-
- inputData []byte // contents of the input file
-
- includeAPIVersion bool // include constant with API version string
- includeComments bool // include parts of original source in comments
- includeBinapiNames bool // include binary API names as struct tag
- includeServices bool // include service interface with client implementation
-
- moduleName string // name of the source VPP module
- packageName string // name of the Go package being generated
-
- packageData *Package // parsed package data
-}
-
-// newContext returns context details of the code generation task
-func newContext(inputFile, outputDir string) (*context, error) {
- if !strings.HasSuffix(inputFile, inputFileExt) {
- return nil, fmt.Errorf("invalid input file name: %q", inputFile)
- }
-
- ctx := &context{
- inputFile: inputFile,
- }
-
- // package name
- inputFileName := filepath.Base(inputFile)
- ctx.moduleName = inputFileName[:strings.Index(inputFileName, ".")]
-
- // alter package names for modules that are reserved keywords in Go
- switch ctx.moduleName {
- case "interface":
- ctx.packageName = "interfaces"
- case "map":
- ctx.packageName = "maps"
- default:
- ctx.packageName = ctx.moduleName
- }
-
- // output file
- packageDir := filepath.Join(outputDir, ctx.packageName)
- outputFileName := ctx.packageName + outputFileExt
- ctx.outputFile = filepath.Join(packageDir, outputFileName)
-
- return ctx, nil
-}
-
-func generatePackage(ctx *context, w io.Writer) error {
- logf("----------------------------")
- logf("generating package %q", ctx.packageName)
- logf("----------------------------")
-
- fmt.Fprintln(w, "// Code generated by GoVPP's binapi-generator. DO NOT EDIT.")
- fmt.Fprintf(w, "// source: %s\n", ctx.inputFile)
- fmt.Fprintln(w)
-
- generateHeader(ctx, w)
- generateImports(ctx, w)
-
- // generate module desc
- fmt.Fprintln(w, "const (")
- fmt.Fprintf(w, "\t// %s is the name of this module.\n", constModuleName)
- fmt.Fprintf(w, "\t%s = \"%s\"\n", constModuleName, ctx.moduleName)
-
- if ctx.includeAPIVersion {
- if ctx.packageData.Version != "" {
- fmt.Fprintf(w, "\t// %s is the API version of this module.\n", constAPIVersion)
- fmt.Fprintf(w, "\t%s = \"%s\"\n", constAPIVersion, ctx.packageData.Version)
- }
- fmt.Fprintf(w, "\t// %s is the CRC of this module.\n", constVersionCrc)
- fmt.Fprintf(w, "\t%s = %v\n", constVersionCrc, ctx.packageData.CRC)
- }
- fmt.Fprintln(w, ")")
- fmt.Fprintln(w)
-
- // generate enums
- if len(ctx.packageData.Enums) > 0 {
- for _, enum := range ctx.packageData.Enums {
- if imp, ok := ctx.packageData.Imports[enum.Name]; ok {
- generateImportedAlias(ctx, w, enum.Name, &imp)
- continue
- }
- generateEnum(ctx, w, &enum)
- }
- }
-
- // generate aliases
- if len(ctx.packageData.Aliases) > 0 {
- for _, alias := range ctx.packageData.Aliases {
- if imp, ok := ctx.packageData.Imports[alias.Name]; ok {
- generateImportedAlias(ctx, w, alias.Name, &imp)
- continue
- }
- generateAlias(ctx, w, &alias)
- }
- }
-
- // generate types
- if len(ctx.packageData.Types) > 0 {
- for _, typ := range ctx.packageData.Types {
- if imp, ok := ctx.packageData.Imports[typ.Name]; ok {
- generateImportedAlias(ctx, w, typ.Name, &imp)
- continue
- }
- generateType(ctx, w, &typ)
- }
- }
-
- // generate unions
- if len(ctx.packageData.Unions) > 0 {
- for _, union := range ctx.packageData.Unions {
- if imp, ok := ctx.packageData.Imports[union.Name]; ok {
- generateImportedAlias(ctx, w, union.Name, &imp)
- continue
- }
- generateUnion(ctx, w, &union)
- }
- }
-
- // generate messages
- if len(ctx.packageData.Messages) > 0 {
- for _, msg := range ctx.packageData.Messages {
- generateMessage(ctx, w, &msg)
- }
-
- // generate message registrations
- fmt.Fprintln(w, "func init() {")
- for _, msg := range ctx.packageData.Messages {
- name := camelCaseName(msg.Name)
- fmt.Fprintf(w, "\tapi.RegisterMessage((*%s)(nil), \"%s\")\n", name, ctx.moduleName+"."+name)
- }
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-
- // generate list of messages
- fmt.Fprintf(w, "// Messages returns list of all messages in this module.\n")
- fmt.Fprintln(w, "func AllMessages() []api.Message {")
- fmt.Fprintln(w, "\treturn []api.Message{")
- for _, msg := range ctx.packageData.Messages {
- name := camelCaseName(msg.Name)
- fmt.Fprintf(w, "\t(*%s)(nil),\n", name)
- }
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w, "}")
- }
-
- if ctx.includeServices {
- // generate services
- if len(ctx.packageData.Services) > 0 {
- generateServices(ctx, w, ctx.packageData.Services)
- }
- }
-
- generateFooter(ctx, w)
-
- return nil
-}
-
-func generateHeader(ctx *context, w io.Writer) {
- fmt.Fprintln(w, "/*")
- fmt.Fprintf(w, "Package %s is a generated VPP binary API for '%s' module.\n", ctx.packageName, ctx.moduleName)
- fmt.Fprintln(w)
- fmt.Fprintln(w, "It consists of:")
- printObjNum := func(obj string, num int) {
- if num > 0 {
- if num > 1 {
- if strings.HasSuffix(obj, "s") {
-
- obj += "es"
- } else {
- obj += "s"
- }
- }
- fmt.Fprintf(w, "\t%3d %s\n", num, obj)
- }
- }
- printObjNum("enum", len(ctx.packageData.Enums))
- printObjNum("alias", len(ctx.packageData.Aliases))
- printObjNum("type", len(ctx.packageData.Types))
- printObjNum("union", len(ctx.packageData.Unions))
- printObjNum("message", len(ctx.packageData.Messages))
- printObjNum("service", len(ctx.packageData.Services))
- fmt.Fprintln(w, "*/")
- fmt.Fprintf(w, "package %s\n", ctx.packageName)
- fmt.Fprintln(w)
-
-}
-
-func generateImports(ctx *context, w io.Writer) {
- fmt.Fprintln(w, "import (")
- fmt.Fprintln(w, ` "bytes"`)
- fmt.Fprintln(w, ` "context"`)
- fmt.Fprintln(w, ` "io"`)
- fmt.Fprintln(w, ` "strconv"`)
- fmt.Fprintln(w)
- fmt.Fprintf(w, "\tapi \"%s\"\n", "git.fd.io/govpp.git/api")
- fmt.Fprintf(w, "\tstruc \"%s\"\n", "github.com/lunixbochs/struc")
- if len(ctx.packageData.Imports) > 0 {
- fmt.Fprintln(w)
- for _, imp := range getImports(ctx) {
- importPath := path.Join(ctx.importPrefix, imp)
- if importPath == "" {
- importPath = getImportPath(filepath.Dir(ctx.outputFile), imp)
- }
- fmt.Fprintf(w, "\t%s \"%s\"\n", imp, strings.TrimSpace(importPath))
- }
- }
- fmt.Fprintln(w, ")")
- fmt.Fprintln(w)
-}
-
-func getImportPath(outputDir string, pkg string) string {
- absPath, _ := filepath.Abs(filepath.Join(outputDir, "..", pkg))
- cmd := exec.Command("go", "list", absPath)
- var errbuf, outbuf bytes.Buffer
- cmd.Stdout = &outbuf
- cmd.Stderr = &errbuf
- if err := cmd.Run(); err != nil {
- fmt.Printf("ERR: %v\n", errbuf.String())
- panic(err)
- }
- return outbuf.String()
-}
-
-func getImports(ctx *context) (imports []string) {
- impmap := map[string]struct{}{}
- for _, imp := range ctx.packageData.Imports {
- if _, ok := impmap[imp.Package]; !ok {
- imports = append(imports, imp.Package)
- impmap[imp.Package] = struct{}{}
- }
- }
- sort.Strings(imports)
- return imports
-}
-
-func generateFooter(ctx *context, w io.Writer) {
- fmt.Fprintln(w, "// This is a compile-time assertion to ensure that this generated file")
- fmt.Fprintln(w, "// is compatible with the GoVPP api package it is being compiled against.")
- fmt.Fprintln(w, "// A compilation error at this line likely means your copy of the")
- fmt.Fprintln(w, "// GoVPP api package needs to be updated.")
- fmt.Fprintf(w, "const _ = api.GoVppAPIPackageIsVersion%d // please upgrade the GoVPP api package\n", generatedCodeVersion)
- fmt.Fprintln(w)
-
- fmt.Fprintf(w, "// Reference imports to suppress errors if they are not otherwise used.\n")
- fmt.Fprintf(w, "var _ = api.RegisterMessage\n")
- fmt.Fprintf(w, "var _ = bytes.NewBuffer\n")
- fmt.Fprintf(w, "var _ = context.Background\n")
- fmt.Fprintf(w, "var _ = io.Copy\n")
- fmt.Fprintf(w, "var _ = strconv.Itoa\n")
- fmt.Fprintf(w, "var _ = struc.Pack\n")
-}
-
-func generateComment(ctx *context, w io.Writer, goName string, vppName string, objKind string) {
- if objKind == "service" {
- fmt.Fprintf(w, "// %s represents RPC service API for %s module.\n", goName, ctx.moduleName)
- } else {
- fmt.Fprintf(w, "// %s represents VPP binary API %s '%s'.\n", goName, objKind, vppName)
- }
-
- if !ctx.includeComments {
- return
- }
-
- var isNotSpace = func(r rune) bool {
- return !unicode.IsSpace(r)
- }
-
- // print out the source of the generated object
- mapType := false
- objFound := false
- objTitle := fmt.Sprintf(`"%s",`, vppName)
- switch objKind {
- case "alias", "service":
- objTitle = fmt.Sprintf(`"%s": {`, vppName)
- mapType = true
- }
-
- inputBuff := bytes.NewBuffer(ctx.inputData)
- inputLine := 0
-
- var trimIndent string
- var indent int
- for {
- line, err := inputBuff.ReadString('\n')
- if err != nil {
- break
- }
- inputLine++
-
- noSpaceAt := strings.IndexFunc(line, isNotSpace)
- if !objFound {
- indent = strings.Index(line, objTitle)
- if indent == -1 {
- continue
- }
- trimIndent = line[:indent]
- // If no other non-whitespace character then we are at the message header.
- if trimmed := strings.TrimSpace(line); trimmed == objTitle {
- objFound = true
- fmt.Fprintln(w, "//")
- }
- } else if noSpaceAt < indent {
- break // end of the definition in JSON for array types
- } else if objFound && mapType && noSpaceAt <= indent {
- fmt.Fprintf(w, "//\t%s", strings.TrimPrefix(line, trimIndent))
- break // end of the definition in JSON for map types (aliases, services)
- }
- fmt.Fprintf(w, "//\t%s", strings.TrimPrefix(line, trimIndent))
- }
-
- fmt.Fprintln(w, "//")
-}
-
-func generateEnum(ctx *context, w io.Writer, enum *Enum) {
- name := camelCaseName(enum.Name)
- typ := binapiTypes[enum.Type]
-
- logf(" writing enum %q (%s) with %d entries", enum.Name, name, len(enum.Entries))
-
- // generate enum comment
- generateComment(ctx, w, name, enum.Name, "enum")
-
- // generate enum definition
- fmt.Fprintf(w, "type %s %s\n", name, typ)
- fmt.Fprintln(w)
-
- // generate enum entries
- fmt.Fprintln(w, "const (")
- for _, entry := range enum.Entries {
- fmt.Fprintf(w, "\t%s %s = %v\n", entry.Name, name, entry.Value)
- }
- fmt.Fprintln(w, ")")
- fmt.Fprintln(w)
-
- // generate enum conversion maps
- fmt.Fprintf(w, "var %s_name = map[%s]string{\n", name, typ)
- for _, entry := range enum.Entries {
- fmt.Fprintf(w, "\t%v: \"%s\",\n", entry.Value, entry.Name)
- }
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-
- fmt.Fprintf(w, "var %s_value = map[string]%s{\n", name, typ)
- for _, entry := range enum.Entries {
- fmt.Fprintf(w, "\t\"%s\": %v,\n", entry.Name, entry.Value)
- }
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-
- fmt.Fprintf(w, "func (x %s) String() string {\n", name)
- fmt.Fprintf(w, "\ts, ok := %s_name[%s(x)]\n", name, typ)
- fmt.Fprintf(w, "\tif ok { return s }\n")
- fmt.Fprintf(w, "\treturn strconv.Itoa(int(x))\n")
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-}
-
-func generateImportedAlias(ctx *context, w io.Writer, tName string, imp *Import) {
- name := camelCaseName(tName)
-
- fmt.Fprintf(w, "type %s = %s.%s\n", name, imp.Package, name)
-
- fmt.Fprintln(w)
-}
-
-func generateAlias(ctx *context, w io.Writer, alias *Alias) {
- name := camelCaseName(alias.Name)
-
- logf(" writing type %q (%s), length: %d", alias.Name, name, alias.Length)
-
- // generate struct comment
- generateComment(ctx, w, name, alias.Name, "alias")
-
- // generate struct definition
- fmt.Fprintf(w, "type %s ", name)
-
- if alias.Length > 0 {
- fmt.Fprintf(w, "[%d]", alias.Length)
- }
-
- dataType := convertToGoType(ctx, alias.Type)
- fmt.Fprintf(w, "%s\n", dataType)
-
- fmt.Fprintln(w)
-}
-
-func generateUnion(ctx *context, w io.Writer, union *Union) {
- name := camelCaseName(union.Name)
-
- logf(" writing union %q (%s) with %d fields", union.Name, name, len(union.Fields))
-
- // generate struct comment
- generateComment(ctx, w, name, union.Name, "union")
-
- // generate struct definition
- fmt.Fprintln(w, "type", name, "struct {")
-
- // maximum size for union
- maxSize := getUnionSize(ctx, union)
-
- // generate data field
- fmt.Fprintf(w, "\t%s [%d]byte\n", unionDataField, maxSize)
-
- // generate end of the struct
- fmt.Fprintln(w, "}")
-
- // generate name getter
- generateTypeNameGetter(w, name, union.Name)
-
- // generate CRC getter
- if union.CRC != "" {
- generateCrcGetter(w, name, union.CRC)
- }
-
- // generate getters for fields
- for _, field := range union.Fields {
- fieldName := camelCaseName(field.Name)
- fieldType := convertToGoType(ctx, field.Type)
- generateUnionGetterSetter(w, name, fieldName, fieldType)
- }
-
- // generate union methods
- //generateUnionMethods(w, name)
-
- fmt.Fprintln(w)
-}
-
-// generateUnionMethods generates methods that implement struc.Custom
-// interface to allow having XXX_uniondata field unexported
-// TODO: do more testing when unions are actually used in some messages
-/*func generateUnionMethods(w io.Writer, structName string) {
- // generate struc.Custom implementation for union
- fmt.Fprintf(w, `
-func (u *%[1]s) Pack(p []byte, opt *struc.Options) (int, error) {
- var b = new(bytes.Buffer)
- if err := struc.PackWithOptions(b, u.union_data, opt); err != nil {
- return 0, err
- }
- copy(p, b.Bytes())
- return b.Len(), nil
-}
-func (u *%[1]s) Unpack(r io.Reader, length int, opt *struc.Options) error {
- return struc.UnpackWithOptions(r, u.union_data[:], opt)
-}
-func (u *%[1]s) Size(opt *struc.Options) int {
- return len(u.union_data)
-}
-func (u *%[1]s) String() string {
- return string(u.union_data[:])
-}
-`, structName)
-}*/
-
-func generateUnionGetterSetter(w io.Writer, structName string, getterField, getterStruct string) {
- fmt.Fprintf(w, `
-func %[1]s%[2]s(a %[3]s) (u %[1]s) {
- u.Set%[2]s(a)
- return
-}
-func (u *%[1]s) Set%[2]s(a %[3]s) {
- var b = new(bytes.Buffer)
- if err := struc.Pack(b, &a); err != nil {
- return
- }
- copy(u.%[4]s[:], b.Bytes())
-}
-func (u *%[1]s) Get%[2]s() (a %[3]s) {
- var b = bytes.NewReader(u.%[4]s[:])
- struc.Unpack(b, &a)
- return
-}
-`, structName, getterField, getterStruct, unionDataField)
-}
-
-func generateType(ctx *context, w io.Writer, typ *Type) {
- name := camelCaseName(typ.Name)
-
- logf(" writing type %q (%s) with %d fields", typ.Name, name, len(typ.Fields))
-
- // generate struct comment
- generateComment(ctx, w, name, typ.Name, "type")
-
- // generate struct definition
- fmt.Fprintf(w, "type %s struct {\n", name)
-
- // generate struct fields
- for i, field := range typ.Fields {
- // skip internal fields
- switch strings.ToLower(field.Name) {
- case crcField, msgIdField:
- continue
- }
-
- generateField(ctx, w, typ.Fields, i)
- }
-
- // generate end of the struct
- fmt.Fprintln(w, "}")
-
- // generate name getter
- generateTypeNameGetter(w, name, typ.Name)
-
- // generate CRC getter
- if typ.CRC != "" {
- generateCrcGetter(w, name, typ.CRC)
- }
-
- fmt.Fprintln(w)
-}
-
-func generateMessage(ctx *context, w io.Writer, msg *Message) {
- name := camelCaseName(msg.Name)
-
- logf(" writing message %q (%s) with %d fields", msg.Name, name, len(msg.Fields))
-
- // generate struct comment
- generateComment(ctx, w, name, msg.Name, "message")
-
- // generate struct definition
- fmt.Fprintf(w, "type %s struct {", name)
-
- msgType := otherMessage
- wasClientIndex := false
-
- // generate struct fields
- n := 0
- for i, field := range msg.Fields {
- if i == 1 {
- if field.Name == clientIndexField {
- // "client_index" as the second member,
- // this might be an event message or a request
- msgType = eventMessage
- wasClientIndex = true
- } else if field.Name == contextField {
- // reply needs "context" as the second member
- msgType = replyMessage
- }
- } else if i == 2 {
- if wasClientIndex && field.Name == contextField {
- // request needs "client_index" as the second member
- // and "context" as the third member
- msgType = requestMessage
- }
- }
-
- // skip internal fields
- switch strings.ToLower(field.Name) {
- case crcField, msgIdField:
- continue
- case clientIndexField, contextField:
- if n == 0 {
- continue
- }
- }
- n++
- if n == 1 {
- fmt.Fprintln(w)
- }
-
- generateField(ctx, w, msg.Fields, i)
- }
-
- // generate end of the struct
- fmt.Fprintln(w, "}")
-
- // generate message methods
- generateMessageResetMethod(w, name)
- generateMessageNameGetter(w, name, msg.Name)
- generateCrcGetter(w, name, msg.CRC)
- generateMessageTypeGetter(w, name, msgType)
-
- fmt.Fprintln(w)
-}
-
-func generateField(ctx *context, w io.Writer, fields []Field, i int) {
- field := fields[i]
-
- fieldName := strings.TrimPrefix(field.Name, "_")
- fieldName = camelCaseName(fieldName)
-
- dataType := convertToGoType(ctx, field.Type)
- fieldType := dataType
-
- // generate length field for strings
- if field.Type == "string" && field.Length == 0 {
- fmt.Fprintf(w, "\tXXX_%sLen uint32 `struc:\"sizeof=%s\"`\n", fieldName, fieldName)
- }
-
- // check if it is array
- if field.Length > 0 || field.SizeFrom != "" {
- if dataType == "uint8" {
- dataType = "byte"
- }
- if dataType == "string" && field.SpecifiedLen {
- fieldType = "string"
- dataType = "byte"
- } else {
- fieldType = "[]" + dataType
- }
- }
- fmt.Fprintf(w, "\t%s %s", fieldName, fieldType)
-
- fieldTags := map[string]string{}
-
- if field.Length > 0 && field.SpecifiedLen {
- // fixed size array
- fieldTags["struc"] = fmt.Sprintf("[%d]%s", field.Length, dataType)
- } else {
- for _, f := range fields {
- if f.SizeFrom == field.Name {
- // variable sized array
- sizeOfName := camelCaseName(f.Name)
- fieldTags["struc"] = fmt.Sprintf("sizeof=%s", sizeOfName)
- }
- }
- }
-
- if ctx.includeBinapiNames {
- fieldTags["binapi"] = field.Name
- }
- if field.Meta.Limit > 0 {
- fieldTags["binapi"] = fmt.Sprintf("%s,limit=%d", fieldTags["binapi"], field.Meta.Limit)
- }
-
- if len(fieldTags) > 0 {
- fmt.Fprintf(w, "\t`")
- var keys []string
- for k := range fieldTags {
- keys = append(keys, k)
- }
- sort.Strings(keys)
- var n int
- for _, tt := range keys {
- t, ok := fieldTags[tt]
- if !ok {
- continue
- }
- if n > 0 {
- fmt.Fprintf(w, " ")
- }
- n++
- fmt.Fprintf(w, `%s:"%s"`, tt, t)
- }
- fmt.Fprintf(w, "`")
- }
-
- fmt.Fprintln(w)
-}
-
-func generateMessageResetMethod(w io.Writer, structName string) {
- fmt.Fprintf(w, "func (m *%[1]s) Reset() { *m = %[1]s{} }\n", structName)
-}
-
-func generateMessageNameGetter(w io.Writer, structName, msgName string) {
- fmt.Fprintf(w, "func (*%s) GetMessageName() string { return %q }\n", structName, msgName)
-}
-
-func generateTypeNameGetter(w io.Writer, structName, msgName string) {
- fmt.Fprintf(w, "func (*%s) GetTypeName() string { return %q }\n", structName, msgName)
-}
-
-func generateCrcGetter(w io.Writer, structName, crc string) {
- crc = strings.TrimPrefix(crc, "0x")
- fmt.Fprintf(w, "func (*%s) GetCrcString() string { return %q }\n", structName, crc)
-}
-
-func generateMessageTypeGetter(w io.Writer, structName string, msgType MessageType) {
- fmt.Fprintf(w, "func (*"+structName+") GetMessageType() api.MessageType {")
- if msgType == requestMessage {
- fmt.Fprintf(w, "\treturn api.RequestMessage")
- } else if msgType == replyMessage {
- fmt.Fprintf(w, "\treturn api.ReplyMessage")
- } else if msgType == eventMessage {
- fmt.Fprintf(w, "\treturn api.EventMessage")
- } else {
- fmt.Fprintf(w, "\treturn api.OtherMessage")
- }
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-}
-
-func generateServices(ctx *context, w io.Writer, services []Service) {
-
- // generate services comment
- generateComment(ctx, w, serviceApiName, "services", "service")
-
- // generate service api
- fmt.Fprintf(w, "type %s interface {\n", serviceApiName)
- for _, svc := range services {
- generateServiceMethod(ctx, w, &svc)
- fmt.Fprintln(w)
- }
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-
- // generate client implementation
- fmt.Fprintf(w, "type %s struct {\n", serviceImplName)
- fmt.Fprintf(w, "\tch api.Channel\n")
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-
- // generate client constructor
- fmt.Fprintf(w, "func New%s(ch api.Channel) %s {\n", serviceClientName, serviceApiName)
- fmt.Fprintf(w, "\treturn &%s{ch}\n", serviceImplName)
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-
- for _, svc := range services {
- method := camelCaseName(svc.RequestType)
- if m := strings.TrimSuffix(method, "Dump"); method != m {
- method = "Dump" + m
- }
-
- fmt.Fprintf(w, "func (c *%s) ", serviceImplName)
- generateServiceMethod(ctx, w, &svc)
- fmt.Fprintln(w, " {")
- if svc.Stream {
- streamImpl := fmt.Sprintf("%s_%sClient", serviceImplName, method)
- fmt.Fprintf(w, "\tstream := c.ch.SendMultiRequest(in)\n")
- fmt.Fprintf(w, "\tx := &%s{stream}\n", streamImpl)
- fmt.Fprintf(w, "\treturn x, nil\n")
- } else if replyTyp := camelCaseName(svc.ReplyType); replyTyp != "" {
- fmt.Fprintf(w, "\tout := new(%s)\n", replyTyp)
- fmt.Fprintf(w, "\terr:= c.ch.SendRequest(in).ReceiveReply(out)\n")
- fmt.Fprintf(w, "\tif err != nil { return nil, err }\n")
- fmt.Fprintf(w, "\treturn out, nil\n")
- } else {
- fmt.Fprintf(w, "\tc.ch.SendRequest(in)\n")
- fmt.Fprintf(w, "\treturn nil\n")
- }
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-
- if svc.Stream {
- replyTyp := camelCaseName(svc.ReplyType)
- method := camelCaseName(svc.RequestType)
- if m := strings.TrimSuffix(method, "Dump"); method != m {
- method = "Dump" + m
- }
- streamApi := fmt.Sprintf("%s_%sClient", serviceApiName, method)
-
- fmt.Fprintf(w, "type %s interface {\n", streamApi)
- fmt.Fprintf(w, "\tRecv() (*%s, error)\n", replyTyp)
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-
- streamImpl := fmt.Sprintf("%s_%sClient", serviceImplName, method)
- fmt.Fprintf(w, "type %s struct {\n", streamImpl)
- fmt.Fprintf(w, "\tapi.MultiRequestCtx\n")
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
-
- fmt.Fprintf(w, "func (c *%s) Recv() (*%s, error) {\n", streamImpl, replyTyp)
- fmt.Fprintf(w, "\tm := new(%s)\n", replyTyp)
- fmt.Fprintf(w, "\tstop, err := c.MultiRequestCtx.ReceiveReply(m)\n")
- fmt.Fprintf(w, "\tif err != nil { return nil, err }\n")
- fmt.Fprintf(w, "\tif stop { return nil, io.EOF }\n")
- fmt.Fprintf(w, "\treturn m, nil\n")
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w)
- }
- }
-
- fmt.Fprintln(w)
-}
-
-func generateServiceMethod(ctx *context, w io.Writer, svc *Service) {
- reqTyp := camelCaseName(svc.RequestType)
-
- // method name is same as parameter type name by default
- method := reqTyp
- if svc.Stream {
- // use Dump as prefix instead of suffix for stream services
- if m := strings.TrimSuffix(method, "Dump"); method != m {
- method = "Dump" + m
- }
- }
-
- params := fmt.Sprintf("in *%s", reqTyp)
- returns := "error"
-
- if replyType := camelCaseName(svc.ReplyType); replyType != "" {
- var replyTyp string
- if svc.Stream {
- replyTyp = fmt.Sprintf("%s_%sClient", serviceApiName, method)
- } else {
- replyTyp = fmt.Sprintf("*%s", replyType)
- }
- returns = fmt.Sprintf("(%s, error)", replyTyp)
- }
-
- fmt.Fprintf(w, "\t%s(ctx context.Context, %s) %s", method, params, returns)
-}
diff --git a/cmd/binapi-generator/main.go b/cmd/binapi-generator/main.go
index fcd85ae..c0bdbb9 100644
--- a/cmd/binapi-generator/main.go
+++ b/cmd/binapi-generator/main.go
@@ -15,324 +15,102 @@
package main
import (
- "bytes"
- "encoding/json"
"flag"
"fmt"
- "go/format"
- "io/ioutil"
"os"
- "path/filepath"
- "strings"
- "github.com/bennyscetbun/jsongo"
"github.com/sirupsen/logrus"
+ "git.fd.io/govpp.git/binapigen"
+ "git.fd.io/govpp.git/binapigen/vppapi"
"git.fd.io/govpp.git/version"
)
-var (
- theInputFile = flag.String("input-file", "", "Input file with VPP API in JSON format.")
- theInputTypes = flag.String("input-types", "", "Types input file with VPP API in JSON format. (split by comma)")
- theInputDir = flag.String("input-dir", "/usr/share/vpp/api", "Input directory with VPP API files in JSON format.")
- theOutputDir = flag.String("output-dir", ".", "Output directory where package folders will be generated.")
-
- includeAPIVer = flag.Bool("include-apiver", true, "Include APIVersion constant for each module.")
- includeServices = flag.Bool("include-services", true, "Include RPC service api and client implementation.")
- includeComments = flag.Bool("include-comments", false, "Include JSON API source in comments for each object.")
- includeBinapiNames = flag.Bool("include-binapi-names", false, "Include binary API names in struct tag.")
- importPrefix = flag.String("import-prefix", "", "Define import path prefix to be used to import types.")
-
- continueOnError = flag.Bool("continue-onerror", false, "Continue with next file on error.")
- debugMode = flag.Bool("debug", os.Getenv("GOVPP_DEBUG") != "", "Enable debug mode.")
-
- printVersion = flag.Bool("version", false, "Prints current version and exits.")
-)
+func init() {
+ flag.Usage = func() {
+ fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [OPTION]... [API]...\n", os.Args[0])
+ fmt.Fprintln(flag.CommandLine.Output(), "Generate code for each API.")
+ fmt.Fprintf(flag.CommandLine.Output(), "Example: %s -output-dir=binapi acl interface l2\n", os.Args[0])
+ fmt.Fprintln(flag.CommandLine.Output())
+ fmt.Fprintln(flag.CommandLine.Output(), "Options:")
+ flag.CommandLine.PrintDefaults()
+ }
+}
func main() {
+ var (
+ theInputFile = flag.String("input-file", "", "Input VPP API file. (DEPRECATED: Use program arguments to define VPP API files)")
+ theApiDir = flag.String("input-dir", vppapi.DefaultAPIDir, "Directory with VPP API files.")
+ theOutputDir = flag.String("output-dir", ".", "Output directory where code will be generated.")
+
+ importPrefix = flag.String("import-prefix", "", "Define import path prefix to be used to import types.")
+ importTypes = flag.Bool("import-types", false, "Generate packages for imported types.")
+ includeAPIVer = flag.Bool("include-apiver", true, "Include APIVersion constant for each module.")
+ includeServices = flag.Bool("include-services", true, "Include RPC service api and client implementation.")
+ includeComments = flag.Bool("include-comments", false, "Include JSON API source in comments for each object.")
+ includeBinapiNames = flag.Bool("include-binapi-names", true, "Include binary API names in struct tag.")
+ includeVppVersion = flag.Bool("include-vpp-version", true, "Include version of the VPP that provided input files.")
+
+ debugMode = flag.Bool("debug", os.Getenv("DEBUG_GOVPP") != "", "Enable debug mode.")
+ printVersion = flag.Bool("version", false, "Prints version and exits.")
+ )
flag.Parse()
- if flag.NArg() > 1 {
- flag.Usage()
- os.Exit(1)
- }
-
- if flag.NArg() > 0 {
- switch cmd := flag.Arg(0); cmd {
- case "version":
- fmt.Fprintln(os.Stdout, version.Verbose())
- os.Exit(0)
-
- default:
- fmt.Fprintf(os.Stderr, "unknown command: %s\n", cmd)
- flag.Usage()
- os.Exit(2)
- }
- }
-
if *printVersion {
fmt.Fprintln(os.Stdout, version.Info())
os.Exit(0)
}
- if *debugMode {
- logrus.SetLevel(logrus.DebugLevel)
- logrus.Info("debug mode enabled")
- }
-
- if err := run(*theInputFile, *theInputDir, *theOutputDir, *continueOnError); err != nil {
- logrus.Errorln("binapi-generator:", err)
- os.Exit(1)
+ if flag.NArg() == 1 && flag.Arg(0) == "version" {
+ fmt.Fprintln(os.Stdout, version.Verbose())
+ os.Exit(0)
}
-}
-func run(inputFile, inputDir string, outputDir string, continueErr bool) (err error) {
- if inputFile == "" && inputDir == "" {
- return fmt.Errorf("input-file or input-dir must be specified")
- }
+ var opts binapigen.Options
- var typesPkgs []*context
- if *theInputTypes != "" {
- types := strings.Split(*theInputTypes, ",")
- typesPkgs, err = loadTypesPackages(types...)
- if err != nil {
- return fmt.Errorf("loading types input failed: %v", err)
- }
- }
-
- if inputFile != "" {
- // process one input file
- if err := generateFromFile(inputFile, outputDir, typesPkgs); err != nil {
- return fmt.Errorf("code generation from %s failed: %v\n", inputFile, err)
+ if *theInputFile != "" {
+ if flag.NArg() > 0 {
+ fmt.Fprintln(os.Stderr, "input-file cannot be combined with files to generate in arguments")
+ os.Exit(1)
}
+ opts.FilesToGenerate = append(opts.FilesToGenerate, *theInputFile)
} else {
- // process all files in specified directory
- dir, err := filepath.Abs(inputDir)
- if err != nil {
- return fmt.Errorf("invalid input directory: %v\n", err)
- }
- files, err := getInputFiles(inputDir, 1)
- if err != nil {
- return fmt.Errorf("problem getting files from input directory: %v\n", err)
- } else if len(files) == 0 {
- return fmt.Errorf("no input files found in input directory: %v\n", dir)
- }
- for _, file := range files {
- if err := generateFromFile(file, outputDir, typesPkgs); err != nil {
- if continueErr {
- logrus.Warnf("code generation from %s failed: %v (error ignored)\n", file, err)
- continue
- } else {
- return fmt.Errorf("code generation from %s failed: %v\n", file, err)
- }
- }
- }
- }
-
- return nil
-}
-
-// getInputFiles returns all input files located in specified directory
-func getInputFiles(inputDir string, deep int) (files []string, err error) {
- entries, err := ioutil.ReadDir(inputDir)
- if err != nil {
- return nil, fmt.Errorf("reading directory %s failed: %v", inputDir, err)
- }
- for _, e := range entries {
- if e.IsDir() && deep > 0 {
- nestedDir := filepath.Join(inputDir, e.Name())
- if nested, err := getInputFiles(nestedDir, deep-1); err != nil {
- return nil, err
- } else {
- files = append(files, nested...)
- }
- } else if strings.HasSuffix(e.Name(), inputFileExt) {
- files = append(files, filepath.Join(inputDir, e.Name()))
- }
- }
- return files, nil
-}
-
-func parseInputJSON(inputData []byte) (*jsongo.Node, error) {
- jsonRoot := new(jsongo.Node)
- if err := json.Unmarshal(inputData, jsonRoot); err != nil {
- return nil, fmt.Errorf("unmarshalling JSON failed: %v", err)
- }
- return jsonRoot, nil
-}
-
-// generateFromFile generates Go package from one input JSON file
-func generateFromFile(inputFile, outputDir string, typesPkgs []*context) error {
- // create generator context
- ctx, err := newContext(inputFile, outputDir)
- if err != nil {
- return err
+ opts.FilesToGenerate = append(opts.FilesToGenerate, flag.Args()...)
}
- logf("------------------------------------------------------------")
- logf("module: %s", ctx.moduleName)
- logf(" - input: %s", ctx.inputFile)
- logf(" - output: %s", ctx.outputFile)
- logf("------------------------------------------------------------")
-
// prepare options
- ctx.includeAPIVersion = *includeAPIVer
- ctx.includeComments = *includeComments
- ctx.includeBinapiNames = *includeBinapiNames
- ctx.includeServices = *includeServices
- ctx.importPrefix = *importPrefix
-
- // read API definition from input file
- ctx.inputData, err = ioutil.ReadFile(ctx.inputFile)
- if err != nil {
- return fmt.Errorf("reading input file %s failed: %v", ctx.inputFile, err)
- }
- // parse JSON data into objects
- jsonRoot, err := parseInputJSON(ctx.inputData)
- if err != nil {
- return fmt.Errorf("parsing JSON input failed: %v", err)
- }
- ctx.packageData, err = parsePackage(ctx, jsonRoot)
- if err != nil {
- return fmt.Errorf("parsing package %s failed: %v", ctx.packageName, err)
- }
-
- if len(typesPkgs) > 0 {
- err = loadTypeAliases(ctx, typesPkgs)
- if err != nil {
- return fmt.Errorf("loading type aliases failed: %v", err)
- }
- }
-
- // generate Go package
- var buf bytes.Buffer
- if err := generatePackage(ctx, &buf); err != nil {
- return fmt.Errorf("generating Go package for %s failed: %v", ctx.packageName, err)
- }
- // format generated source code
- gosrc, err := format.Source(buf.Bytes())
- if err != nil {
- return fmt.Errorf("formatting source code for package %s failed: %v", ctx.packageName, err)
+ if ver := os.Getenv("VPP_API_VERSION"); ver != "" {
+ // use version from env var if set
+ opts.VPPVersion = ver
+ } else {
+ opts.VPPVersion = ResolveVppVersion(*theApiDir)
}
+ opts.IncludeAPIVersion = *includeAPIVer
+ opts.IncludeComments = *includeComments
+ opts.IncludeBinapiNames = *includeBinapiNames
+ opts.IncludeServices = *includeServices
+ opts.IncludeVppVersion = *includeVppVersion
+ opts.ImportPrefix = *importPrefix
+ opts.ImportTypes = *importTypes
- // create output directory
- packageDir := filepath.Dir(ctx.outputFile)
- if err := os.MkdirAll(packageDir, 0775); err != nil {
- return fmt.Errorf("creating output dir %s failed: %v", packageDir, err)
- }
- // write generated code to output file
- if err := ioutil.WriteFile(ctx.outputFile, gosrc, 0666); err != nil {
- return fmt.Errorf("writing to output file %s failed: %v", ctx.outputFile, err)
+ if *debugMode {
+ logrus.SetLevel(logrus.DebugLevel)
+ logrus.Debug("debug mode enabled")
}
- return nil
-}
+ apiDir := *theApiDir
+ outputDir := *theOutputDir
-func loadTypesPackages(types ...string) ([]*context, error) {
- var ctxs []*context
- for _, inputFile := range types {
- // create generator context
- ctx, err := newContext(inputFile, "")
- if err != nil {
- return nil, err
- }
- // read API definition from input file
- ctx.inputData, err = ioutil.ReadFile(ctx.inputFile)
- if err != nil {
- return nil, fmt.Errorf("reading input file %s failed: %v", ctx.inputFile, err)
- }
- // parse JSON data into objects
- jsonRoot, err := parseInputJSON(ctx.inputData)
- if err != nil {
- return nil, fmt.Errorf("parsing JSON input failed: %v", err)
- }
- ctx.packageData, err = parsePackage(ctx, jsonRoot)
- if err != nil {
- return nil, fmt.Errorf("parsing package %s failed: %v", ctx.packageName, err)
- }
- ctxs = append(ctxs, ctx)
- }
- return ctxs, nil
-}
-
-func loadTypeAliases(ctx *context, typesCtxs []*context) error {
- for _, t := range ctx.packageData.Types {
- for _, c := range typesCtxs {
- if _, ok := ctx.packageData.Imports[t.Name]; ok {
- break
- }
- for _, at := range c.packageData.Types {
- if at.Name != t.Name {
- continue
- }
- if len(at.Fields) != len(t.Fields) {
- continue
- }
- ctx.packageData.Imports[t.Name] = Import{
- Package: c.packageName,
- }
- }
- }
- }
- for _, t := range ctx.packageData.Aliases {
- for _, c := range typesCtxs {
- if _, ok := ctx.packageData.Imports[t.Name]; ok {
- break
- }
- for _, at := range c.packageData.Aliases {
- if at.Name != t.Name {
- continue
- }
- if at.Length != t.Length {
- continue
- }
- if at.Type != t.Type {
- continue
- }
- ctx.packageData.Imports[t.Name] = Import{
- Package: c.packageName,
- }
- }
- }
- }
- for _, t := range ctx.packageData.Enums {
- for _, c := range typesCtxs {
- if _, ok := ctx.packageData.Imports[t.Name]; ok {
- break
+ binapigen.Run(apiDir, opts, func(g *binapigen.Generator) error {
+ for _, file := range g.Files {
+ if !file.Generate {
+ continue
}
- for _, at := range c.packageData.Enums {
- if at.Name != t.Name {
- continue
- }
- if at.Type != t.Type {
- continue
- }
- ctx.packageData.Imports[t.Name] = Import{
- Package: c.packageName,
- }
+ binapigen.GenerateBinapiFile(g, file, outputDir)
+ if g.IncludeServices && file.Service != nil {
+ binapigen.GenerateRPC(g, file, outputDir)
}
}
- }
- for _, t := range ctx.packageData.Unions {
- for _, c := range typesCtxs {
- if _, ok := ctx.packageData.Imports[t.Name]; ok {
- break
- }
- for _, at := range c.packageData.Unions {
- if at.Name != t.Name {
- continue
- }
- ctx.packageData.Imports[t.Name] = Import{
- Package: c.packageName,
- }
- }
- }
- }
- return nil
-}
-
-func logf(f string, v ...interface{}) {
- if *debugMode {
- logrus.Debugf(f, v...)
- }
+ return nil
+ })
}
diff --git a/cmd/binapi-generator/objects.go b/cmd/binapi-generator/objects.go
deleted file mode 100644
index 9871abc..0000000
--- a/cmd/binapi-generator/objects.go
+++ /dev/null
@@ -1,139 +0,0 @@
-package main
-
-import "fmt"
-
-// Package represents collection of objects parsed from VPP binary API JSON data
-type Package struct {
- Name string
- Version string
- CRC string
- Services []Service
- Enums []Enum
- Aliases []Alias
- Types []Type
- Unions []Union
- Messages []Message
- RefMap map[string]string
- Imports map[string]Import
-}
-
-type Import struct {
- Package string
-}
-
-// Service represents VPP binary API service
-type Service struct {
- Name string
- RequestType string
- ReplyType string
- Stream bool
- Events []string
-}
-
-// Enum represents VPP binary API enum
-type Enum struct {
- Name string
- Type string
- Entries []EnumEntry
-}
-
-// EnumEntry represents VPP binary API enum entry
-type EnumEntry struct {
- Name string
- Value interface{}
-}
-
-// Alias represents VPP binary API alias
-type Alias struct {
- Name string
- Type string
- Length int
-}
-
-// Type represents VPP binary API type
-type Type struct {
- Name string
- CRC string
- Fields []Field
-}
-
-// Field represents VPP binary API object field
-type Field struct {
- Name string
- Type string
- Length int
- SpecifiedLen bool
- SizeFrom string
- Meta FieldMeta
-}
-
-// FieldMeta represents VPP binary API meta info for field
-type FieldMeta struct {
- Limit int
- Default string
-}
-
-// Union represents VPP binary API union
-type Union struct {
- Name string
- CRC string
- Fields []Field
-}
-
-// Message represents VPP binary API message
-type Message struct {
- Name string
- CRC string
- Fields []Field
-}
-
-// MessageType represents the type of a VPP message
-type MessageType int
-
-const (
- requestMessage MessageType = iota // VPP request message
- replyMessage // VPP reply message
- eventMessage // VPP event message
- otherMessage // other VPP message
-)
-
-// printPackage prints all loaded objects for package
-func printPackage(pkg *Package) {
- logf("package: %s %s (%s)", pkg.Name, pkg.Version, pkg.CRC)
- if len(pkg.Enums) > 0 {
- logf(" %d enums:", len(pkg.Enums))
- for _, enum := range pkg.Enums {
- logf(" - %s: %+v", enum.Name, enum)
- }
- }
- if len(pkg.Unions) > 0 {
- logf(" %d unions:", len(pkg.Unions))
- for _, union := range pkg.Unions {
- logf(" - %s: %+v", union.Name, union)
- }
- }
- if len(pkg.Types) > 0 {
- logf(" %d types:", len(pkg.Types))
- for _, typ := range pkg.Types {
- logf(" - %s (%d fields): %+v", typ.Name, len(typ.Fields), typ)
- }
- }
- if len(pkg.Messages) > 0 {
- logf(" %d messages:", len(pkg.Messages))
- for _, msg := range pkg.Messages {
- logf(" - %s (%d fields) %s", msg.Name, len(msg.Fields), msg.CRC)
- }
- }
- if len(pkg.Services) > 0 {
- logf(" %d services:", len(pkg.Services))
- for _, svc := range pkg.Services {
- var info string
- if svc.Stream {
- info = "(STREAM)"
- } else if len(svc.Events) > 0 {
- info = fmt.Sprintf("(EVENTS: %v)", svc.Events)
- }
- logf(" - %s: %q -> %q %s", svc.Name, svc.RequestType, svc.ReplyType, info)
- }
- }
-}
diff --git a/cmd/binapi-generator/parse.go b/cmd/binapi-generator/parse.go
deleted file mode 100644
index 6598b7b..0000000
--- a/cmd/binapi-generator/parse.go
+++ /dev/null
@@ -1,557 +0,0 @@
-// Copyright (c) 2018 Cisco and/or its affiliates.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at:
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package main
-
-import (
- "errors"
- "fmt"
- "sort"
- "strings"
-
- "github.com/bennyscetbun/jsongo"
- "github.com/sirupsen/logrus"
-)
-
-// top level objects
-const (
- objTypes = "types"
- objMessages = "messages"
- objUnions = "unions"
- objEnums = "enums"
- objServices = "services"
- objAliases = "aliases"
- vlAPIVersion = "vl_api_version"
- objOptions = "options"
-)
-
-// various object fields
-const (
- crcField = "crc"
- msgIdField = "_vl_msg_id"
-
- clientIndexField = "client_index"
- contextField = "context"
-
- aliasLengthField = "length"
- aliasTypeField = "type"
-
- replyField = "reply"
- streamField = "stream"
- eventsField = "events"
-)
-
-// service name parts
-const (
- serviceEventPrefix = "want_"
- serviceDumpSuffix = "_dump"
- serviceDetailsSuffix = "_details"
- serviceReplySuffix = "_reply"
- serviceNoReply = "null"
-)
-
-// field meta info
-const (
- fieldMetaLimit = "limit"
- fieldMetaDefault = "default"
-)
-
-// module options
-const (
- versionOption = "version"
-)
-
-// parsePackage parses provided JSON data into objects prepared for code generation
-func parsePackage(ctx *context, jsonRoot *jsongo.Node) (*Package, error) {
- pkg := Package{
- Name: ctx.packageName,
- RefMap: make(map[string]string),
- Imports: map[string]Import{},
- }
-
- // parse CRC for API version
- if crc := jsonRoot.At(vlAPIVersion); crc.GetType() == jsongo.TypeValue {
- pkg.CRC = crc.Get().(string)
- }
-
- // parse version string
- if opt := jsonRoot.Map(objOptions); opt.GetType() == jsongo.TypeMap {
- if ver := opt.Map(versionOption); ver.GetType() == jsongo.TypeValue {
- pkg.Version = ver.Get().(string)
- }
- }
-
- logf("parsing package %s (version: %s, CRC: %s)", pkg.Name, pkg.Version, pkg.CRC)
- logf(" consists of:")
- for _, key := range jsonRoot.GetKeys() {
- logf(" - %d %s", jsonRoot.At(key).Len(), key)
- }
-
- // parse enums
- enums := jsonRoot.Map(objEnums)
- pkg.Enums = make([]Enum, 0)
- for i := 0; i < enums.Len(); i++ {
- enumNode := enums.At(i)
-
- enum, err := parseEnum(ctx, enumNode)
- if err != nil {
- return nil, err
- }
-
- enumApi := toApiType(enum.Name)
- if _, ok := pkg.RefMap[enumApi]; ok {
- logf("enum %v already known", enumApi)
- continue
- }
- pkg.RefMap[enumApi] = enum.Name
- pkg.Enums = append(pkg.Enums, *enum)
- }
- // sort enums
- sort.SliceStable(pkg.Enums, func(i, j int) bool {
- return pkg.Enums[i].Name < pkg.Enums[j].Name
- })
-
- // parse aliases
- aliases := jsonRoot.Map(objAliases)
- if aliases.GetType() == jsongo.TypeMap {
- pkg.Aliases = make([]Alias, 0)
- for _, key := range aliases.GetKeys() {
- aliasNode := aliases.At(key)
-
- alias, err := parseAlias(ctx, key.(string), aliasNode)
- if err != nil {
- return nil, err
- }
-
- aliasApi := toApiType(alias.Name)
- if _, ok := pkg.RefMap[aliasApi]; ok {
- logf("alias %v already known", aliasApi)
- continue
- }
- pkg.RefMap[aliasApi] = alias.Name
- pkg.Aliases = append(pkg.Aliases, *alias)
- }
- }
- // sort aliases to ensure consistent order
- sort.Slice(pkg.Aliases, func(i, j int) bool {
- return pkg.Aliases[i].Name < pkg.Aliases[j].Name
- })
-
- // parse types
- types := jsonRoot.Map(objTypes)
- pkg.Types = make([]Type, 0)
- for i := 0; i < types.Len(); i++ {
- typNode := types.At(i)
-
- typ, err := parseType(ctx, typNode)
- if err != nil {
- return nil, err
- }
-
- typApi := toApiType(typ.Name)
- if _, ok := pkg.RefMap[typApi]; ok {
- logf("type %v already known", typApi)
- continue
- }
- pkg.RefMap[typApi] = typ.Name
- pkg.Types = append(pkg.Types, *typ)
- }
- // sort types
- sort.SliceStable(pkg.Types, func(i, j int) bool {
- return pkg.Types[i].Name < pkg.Types[j].Name
- })
-
- // parse unions
- unions := jsonRoot.Map(objUnions)
- pkg.Unions = make([]Union, 0)
- for i := 0; i < unions.Len(); i++ {
- unionNode := unions.At(i)
-
- union, err := parseUnion(ctx, unionNode)
- if err != nil {
- return nil, err
- }
-
- unionApi := toApiType(union.Name)
- if _, ok := pkg.RefMap[unionApi]; ok {
- logf("union %v already known", unionApi)
- continue
- }
- pkg.RefMap[unionApi] = union.Name
- pkg.Unions = append(pkg.Unions, *union)
- }
- // sort unions
- sort.SliceStable(pkg.Unions, func(i, j int) bool {
- return pkg.Unions[i].Name < pkg.Unions[j].Name
- })
-
- // parse messages
- messages := jsonRoot.Map(objMessages)
- pkg.Messages = make([]Message, messages.Len())
- for i := 0; i < messages.Len(); i++ {
- msgNode := messages.At(i)
-
- msg, err := parseMessage(ctx, msgNode)
- if err != nil {
- return nil, err
- }
- pkg.Messages[i] = *msg
- }
- // sort messages
- sort.SliceStable(pkg.Messages, func(i, j int) bool {
- return pkg.Messages[i].Name < pkg.Messages[j].Name
- })
-
- // parse services
- services := jsonRoot.Map(objServices)
- if services.GetType() == jsongo.TypeMap {
- pkg.Services = make([]Service, services.Len())
- for i, key := range services.GetKeys() {
- svcNode := services.At(key)
-
- svc, err := parseService(ctx, key.(string), svcNode)
- if err != nil {
- return nil, err
- }
- pkg.Services[i] = *svc
- }
- }
- // sort services
- sort.Slice(pkg.Services, func(i, j int) bool {
- // dumps first
- if pkg.Services[i].Stream != pkg.Services[j].Stream {
- return pkg.Services[i].Stream
- }
- return pkg.Services[i].RequestType < pkg.Services[j].RequestType
- })
-
- printPackage(&pkg)
-
- return &pkg, nil
-}
-
-// parseEnum parses VPP binary API enum object from JSON node
-func parseEnum(ctx *context, enumNode *jsongo.Node) (*Enum, error) {
- if enumNode.Len() == 0 || enumNode.At(0).GetType() != jsongo.TypeValue {
- return nil, errors.New("invalid JSON for enum specified")
- }
-
- enumName, ok := enumNode.At(0).Get().(string)
- if !ok {
- return nil, fmt.Errorf("enum name is %T, not a string", enumNode.At(0).Get())
- }
- enumType, ok := enumNode.At(enumNode.Len() - 1).At("enumtype").Get().(string)
- if !ok {
- return nil, fmt.Errorf("enum type invalid or missing")
- }
-
- enum := Enum{
- Name: enumName,
- Type: enumType,
- }
-
- // loop through enum entries, skip first (name) and last (enumtype)
- for j := 1; j < enumNode.Len()-1; j++ {
- if enumNode.At(j).GetType() == jsongo.TypeArray {
- entry := enumNode.At(j)
-
- if entry.Len() < 2 || entry.At(0).GetType() != jsongo.TypeValue || entry.At(1).GetType() != jsongo.TypeValue {
- return nil, errors.New("invalid JSON for enum entry specified")
- }
-
- entryName, ok := entry.At(0).Get().(string)
- if !ok {
- return nil, fmt.Errorf("enum entry name is %T, not a string", entry.At(0).Get())
- }
- entryVal := entry.At(1).Get()
-
- enum.Entries = append(enum.Entries, EnumEntry{
- Name: entryName,
- Value: entryVal,
- })
- }
- }
-
- return &enum, nil
-}
-
-// parseUnion parses VPP binary API union object from JSON node
-func parseUnion(ctx *context, unionNode *jsongo.Node) (*Union, error) {
- if unionNode.Len() == 0 || unionNode.At(0).GetType() != jsongo.TypeValue {
- return nil, errors.New("invalid JSON for union specified")
- }
-
- unionName, ok := unionNode.At(0).Get().(string)
- if !ok {
- return nil, fmt.Errorf("union name is %T, not a string", unionNode.At(0).Get())
- }
- var unionCRC string
- if unionNode.At(unionNode.Len()-1).GetType() == jsongo.TypeMap {
- unionCRC = unionNode.At(unionNode.Len() - 1).At(crcField).Get().(string)
- }
-
- union := Union{
- Name: unionName,
- CRC: unionCRC,
- }
-
- // loop through union fields, skip first (name)
- for j := 1; j < unionNode.Len(); j++ {
- if unionNode.At(j).GetType() == jsongo.TypeArray {
- fieldNode := unionNode.At(j)
-
- field, err := parseField(ctx, fieldNode)
- if err != nil {
- return nil, err
- }
-
- union.Fields = append(union.Fields, *field)
- }
- }
-
- return &union, nil
-}
-
-// parseType parses VPP binary API type object from JSON node
-func parseType(ctx *context, typeNode *jsongo.Node) (*Type, error) {
- if typeNode.Len() == 0 || typeNode.At(0).GetType() != jsongo.TypeValue {
- return nil, errors.New("invalid JSON for type specified")
- }
-
- typeName, ok := typeNode.At(0).Get().(string)
- if !ok {
- return nil, fmt.Errorf("type name is %T, not a string", typeNode.At(0).Get())
- }
- var typeCRC string
- if lastField := typeNode.At(typeNode.Len() - 1); lastField.GetType() == jsongo.TypeMap {
- typeCRC = lastField.At(crcField).Get().(string)
- }
-
- typ := Type{
- Name: typeName,
- CRC: typeCRC,
- }
-
- // loop through type fields, skip first (name)
- for j := 1; j < typeNode.Len(); j++ {
- if typeNode.At(j).GetType() == jsongo.TypeArray {
- fieldNode := typeNode.At(j)
-
- field, err := parseField(ctx, fieldNode)
- if err != nil {
- return nil, err
- }
-
- typ.Fields = append(typ.Fields, *field)
- }
- }
-
- return &typ, nil
-}
-
-// parseAlias parses VPP binary API alias object from JSON node
-func parseAlias(ctx *context, aliasName string, aliasNode *jsongo.Node) (*Alias, error) {
- if aliasNode.Len() == 0 || aliasNode.At(aliasTypeField).GetType() != jsongo.TypeValue {
- return nil, errors.New("invalid JSON for alias specified")
- }
-
- alias := Alias{
- Name: aliasName,
- }
-
- if typeNode := aliasNode.At(aliasTypeField); typeNode.GetType() == jsongo.TypeValue {
- typ, ok := typeNode.Get().(string)
- if !ok {
- return nil, fmt.Errorf("alias type is %T, not a string", typeNode.Get())
- }
- if typ != "null" {
- alias.Type = typ
- }
- }
-
- if lengthNode := aliasNode.At(aliasLengthField); lengthNode.GetType() == jsongo.TypeValue {
- length, ok := lengthNode.Get().(float64)
- if !ok {
- return nil, fmt.Errorf("alias length is %T, not a float64", lengthNode.Get())
- }
- alias.Length = int(length)
- }
-
- return &alias, nil
-}
-
-// parseMessage parses VPP binary API message object from JSON node
-func parseMessage(ctx *context, msgNode *jsongo.Node) (*Message, error) {
- if msgNode.Len() == 0 || msgNode.At(0).GetType() != jsongo.TypeValue {
- return nil, errors.New("invalid JSON for message specified")
- }
-
- msgName, ok := msgNode.At(0).Get().(string)
- if !ok {
- return nil, fmt.Errorf("message name is %T, not a string", msgNode.At(0).Get())
- }
- msgCRC, ok := msgNode.At(msgNode.Len() - 1).At(crcField).Get().(string)
- if !ok {
-
- return nil, fmt.Errorf("message crc invalid or missing")
- }
-
- msg := Message{
- Name: msgName,
- CRC: msgCRC,
- }
-
- // loop through message fields, skip first (name) and last (crc)
- for j := 1; j < msgNode.Len()-1; j++ {
- if msgNode.At(j).GetType() == jsongo.TypeArray {
- fieldNode := msgNode.At(j)
-
- field, err := parseField(ctx, fieldNode)
- if err != nil {
- return nil, err
- }
-
- msg.Fields = append(msg.Fields, *field)
- }
- }
-
- return &msg, nil
-}
-
-// parseField parses VPP binary API object field from JSON node
-func parseField(ctx *context, field *jsongo.Node) (*Field, error) {
- if field.Len() < 2 || field.At(0).GetType() != jsongo.TypeValue || field.At(1).GetType() != jsongo.TypeValue {
- return nil, errors.New("invalid JSON for field specified")
- }
-
- fieldType, ok := field.At(0).Get().(string)
- if !ok {
- return nil, fmt.Errorf("field type is %T, not a string", field.At(0).Get())
- }
- fieldName, ok := field.At(1).Get().(string)
- if !ok {
- return nil, fmt.Errorf("field name is %T, not a string", field.At(1).Get())
- }
-
- f := &Field{
- Name: fieldName,
- Type: fieldType,
- }
-
- if field.Len() >= 3 {
- switch field.At(2).GetType() {
- case jsongo.TypeValue:
- fieldLength, ok := field.At(2).Get().(float64)
- if !ok {
- return nil, fmt.Errorf("field length is %T, not float64", field.At(2).Get())
- }
- f.Length = int(fieldLength)
- f.SpecifiedLen = true
-
- case jsongo.TypeMap:
- fieldMeta := field.At(2)
-
- for _, key := range fieldMeta.GetKeys() {
- metaNode := fieldMeta.At(key)
-
- switch metaName := key.(string); metaName {
- case fieldMetaLimit:
- f.Meta.Limit = int(metaNode.Get().(float64))
- case fieldMetaDefault:
- f.Meta.Default = fmt.Sprint(metaNode.Get())
- default:
- logrus.Warnf("unknown meta info (%s) for field (%s)", metaName, fieldName)
- }
- }
- default:
- return nil, errors.New("invalid JSON for field specified")
- }
- }
- if field.Len() >= 4 {
- fieldLengthFrom, ok := field.At(3).Get().(string)
- if !ok {
- return nil, fmt.Errorf("field length from is %T, not a string", field.At(3).Get())
- }
- f.SizeFrom = fieldLengthFrom
- }
-
- return f, nil
-}
-
-// parseService parses VPP binary API service object from JSON node
-func parseService(ctx *context, svcName string, svcNode *jsongo.Node) (*Service, error) {
- if svcNode.Len() == 0 || svcNode.At(replyField).GetType() != jsongo.TypeValue {
- return nil, errors.New("invalid JSON for service specified")
- }
-
- svc := Service{
- Name: svcName,
- RequestType: svcName,
- }
-
- if replyNode := svcNode.At(replyField); replyNode.GetType() == jsongo.TypeValue {
- reply, ok := replyNode.Get().(string)
- if !ok {
- return nil, fmt.Errorf("service reply is %T, not a string", replyNode.Get())
- }
- if reply != serviceNoReply {
- svc.ReplyType = reply
- }
- }
-
- // stream service (dumps)
- if streamNode := svcNode.At(streamField); streamNode.GetType() == jsongo.TypeValue {
- var ok bool
- svc.Stream, ok = streamNode.Get().(bool)
- if !ok {
- return nil, fmt.Errorf("service stream is %T, not a string", streamNode.Get())
- }
- }
-
- // events service (event subscription)
- if eventsNode := svcNode.At(eventsField); eventsNode.GetType() == jsongo.TypeArray {
- for j := 0; j < eventsNode.Len(); j++ {
- event := eventsNode.At(j).Get().(string)
- svc.Events = append(svc.Events, event)
- }
- }
-
- // validate service
- if len(svc.Events) > 0 {
- // EVENT service
- if !strings.HasPrefix(svc.RequestType, serviceEventPrefix) {
- logrus.Debugf("unusual EVENTS service: %+v\n"+
- "- events service %q does not have %q prefix in request.",
- svc, svc.Name, serviceEventPrefix)
- }
- } else if svc.Stream {
- // STREAM service
- if !strings.HasSuffix(svc.RequestType, serviceDumpSuffix) ||
- !strings.HasSuffix(svc.ReplyType, serviceDetailsSuffix) {
- logrus.Debugf("unusual STREAM service: %+v\n"+
- "- stream service %q does not have %q suffix in request or reply does not have %q suffix.",
- svc, svc.Name, serviceDumpSuffix, serviceDetailsSuffix)
- }
- } else if svc.ReplyType != "" && svc.ReplyType != serviceNoReply {
- // REQUEST service
- // some messages might have `null` reply (for example: memclnt)
- if !strings.HasSuffix(svc.ReplyType, serviceReplySuffix) {
- logrus.Debugf("unusual REQUEST service: %+v\n"+
- "- service %q does not have %q suffix in reply.",
- svc, svc.Name, serviceReplySuffix)
- }
- }
-
- return &svc, nil
-}
diff --git a/cmd/binapi-generator/types.go b/cmd/binapi-generator/types.go
deleted file mode 100644
index 90c890f..0000000
--- a/cmd/binapi-generator/types.go
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright (c) 2019 Cisco and/or its affiliates.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at:
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package main
-
-import (
- "fmt"
- "strconv"
- "strings"
-
- "github.com/sirupsen/logrus"
-)
-
-// toApiType returns name that is used as type reference in VPP binary API
-func toApiType(name string) string {
- return fmt.Sprintf("vl_api_%s_t", name)
-}
-
-// binapiTypes is a set of types used VPP binary API for translation to Go types
-var binapiTypes = map[string]string{
- "u8": "uint8",
- "i8": "int8",
- "u16": "uint16",
- "i16": "int16",
- "u32": "uint32",
- "i32": "int32",
- "u64": "uint64",
- "i64": "int64",
- "f64": "float64",
-}
-
-func getBinapiTypeSize(binapiType string) int {
- if _, ok := binapiTypes[binapiType]; ok {
- b, err := strconv.Atoi(strings.TrimLeft(binapiType, "uif"))
- if err == nil {
- return b / 8
- }
- }
- return -1
-}
-
-// convertToGoType translates the VPP binary API type into Go type
-func convertToGoType(ctx *context, binapiType string) (typ string) {
- if t, ok := binapiTypes[binapiType]; ok {
- // basic types
- typ = t
- } else if r, ok := ctx.packageData.RefMap[binapiType]; ok {
- // specific types (enums/types/unions)
- typ = camelCaseName(r)
- } else {
- switch binapiType {
- case "bool", "string":
- typ = binapiType
- default:
- // fallback type
- logrus.Warnf("found unknown VPP binary API type %q, using byte", binapiType)
- typ = "byte"
- }
- }
- return typ
-}
-
-func getSizeOfType(ctx *context, typ *Type) (size int) {
- for _, field := range typ.Fields {
- enum := getEnumByRef(ctx, field.Type)
- if enum != nil {
- size += getSizeOfBinapiTypeLength(enum.Type, field.Length)
- continue
- }
- size += getSizeOfBinapiTypeLength(field.Type, field.Length)
- }
- return size
-}
-
-func getSizeOfBinapiTypeLength(typ string, length int) (size int) {
- if n := getBinapiTypeSize(typ); n > 0 {
- if length > 0 {
- return n * length
- } else {
- return n
- }
- }
-
- return
-}
-
-func getEnumByRef(ctx *context, ref string) *Enum {
- for _, typ := range ctx.packageData.Enums {
- if ref == toApiType(typ.Name) {
- return &typ
- }
- }
- return nil
-}
-
-func getTypeByRef(ctx *context, ref string) *Type {
- for _, typ := range ctx.packageData.Types {
- if ref == toApiType(typ.Name) {
- return &typ
- }
- }
- return nil
-}
-
-func getAliasByRef(ctx *context, ref string) *Alias {
- for _, alias := range ctx.packageData.Aliases {
- if ref == toApiType(alias.Name) {
- return &alias
- }
- }
- return nil
-}
-
-func getUnionSize(ctx *context, union *Union) (maxSize int) {
- for _, field := range union.Fields {
- typ := getTypeByRef(ctx, field.Type)
- if typ != nil {
- if size := getSizeOfType(ctx, typ); size > maxSize {
- maxSize = size
- }
- continue
- }
- alias := getAliasByRef(ctx, field.Type)
- if alias != nil {
- if size := getSizeOfBinapiTypeLength(alias.Type, alias.Length); size > maxSize {
- maxSize = size
- }
- continue
- } else {
- logf("no type or alias found for union %s field type %q", union.Name, field.Type)
- continue
- }
- }
- logf("getUnionSize: %s %+v max=%v", union.Name, union.Fields, maxSize)
- return
-}
diff --git a/cmd/binapi-generator/util.go b/cmd/binapi-generator/util.go
new file mode 100644
index 0000000..8738963
--- /dev/null
+++ b/cmd/binapi-generator/util.go
@@ -0,0 +1,81 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "io/ioutil"
+ "os/exec"
+ "path"
+ "strings"
+
+ "github.com/sirupsen/logrus"
+)
+
+const (
+ versionScriptPath = "./src/scripts/version"
+ defaultVppApiDir = "/usr/share/vpp/api"
+)
+
+func ResolveVppVersion(inputDir string) string {
+ // assuming VPP package is installed
+ if inputDir == defaultVppApiDir {
+ // resolve VPP version using dpkg
+ cmd := exec.Command("dpkg-query", "-f", "${Version}", "-W", "vpp")
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ logrus.Warnf("resolving VPP version from installed package failed: %v", err)
+ logrus.Warnf("command output: %s", out)
+ } else {
+ version := strings.TrimSpace(string(out))
+ logrus.Debugf("resolved VPP version from installed package: %v", version)
+ return version
+ }
+ }
+ // check if inside VPP git repo
+ if inputDir != "" {
+ repo := findVppGitRepo(inputDir)
+ if repo != "" {
+ cmd := exec.Command(versionScriptPath)
+ cmd.Dir = repo
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ logrus.Warnf("resolving VPP version from version script failed: %v", err)
+ logrus.Warnf("command output: %s", out)
+ } else {
+ version := strings.TrimSpace(string(out))
+ logrus.Debugf("resolved VPP version from version script: %v", version)
+ return version
+ }
+ }
+ file, err := ioutil.ReadFile(path.Join(inputDir, "VPP_VERSION"))
+ if err == nil {
+ return strings.TrimSpace(string(file))
+ }
+ }
+ logrus.Warnf("VPP version could not be resolved, you can set it manually using VPP_API_VERSION env var")
+ return "unknown"
+}
+
+func findVppGitRepo(dir string) string {
+ cmd := exec.Command("git", "rev-parse", "--show-toplevel")
+ cmd.Dir = dir
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ logrus.Warnf("checking VPP git repo failed: %v", err)
+ logrus.Warnf("command output: %s", out)
+ return ""
+ }
+ return strings.TrimSpace(string(out))
+}
diff --git a/codec/bench_test.go b/codec/bench_test.go
new file mode 100644
index 0000000..6889fa7
--- /dev/null
+++ b/codec/bench_test.go
@@ -0,0 +1,90 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package codec_test
+
+import (
+ "fmt"
+ "testing"
+
+ "git.fd.io/govpp.git/codec"
+)
+
+var Data []byte
+
+func BenchmarkEncode(b *testing.B) {
+ m := NewTestAllMsg()
+
+ var err error
+ var data []byte
+
+ for i := 0; i < b.N; i++ {
+ c := codec.MsgCodec{}
+ data, err = c.EncodeMsg(m, 100)
+ if err != nil {
+ b.Fatalf("expected nil error, got: %v", err)
+ }
+ }
+ Data = data
+}
+
+func BenchmarkEncodeStruc(b *testing.B) {
+ m := NewTestAllMsg()
+ c := codec.OldCodec{}
+
+ var err error
+ var data []byte
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ data, err = c.Marshal(m)
+ if err != nil {
+ b.Fatalf("expected nil error, got: %v", err)
+ }
+ }
+ Data = data
+ fmt.Printf("DATA(%d): % 0X\n", len(Data), Data)
+}
+
+/*func BenchmarkEncodeNew(b *testing.B) {
+ m := NewTestAllMsg()
+
+ var err error
+ var data []byte
+
+ for i := 0; i < b.N; i++ {
+ c := CodecNew{}
+ data, err = c.Marshal(m)
+ if err != nil {
+ b.Fatalf("expected nil error, got: %v", err)
+ }
+ }
+ Data = data
+}*/
+func BenchmarkEncodeHard(b *testing.B) {
+ m := NewTestAllMsg()
+
+ var err error
+ var data []byte
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ data, err = m.Marshal(nil)
+ if err != nil {
+ b.Fatalf("expected nil error, got: %v", err)
+ }
+ }
+ Data = data
+ fmt.Printf("DATA(%d): % 0X\n", len(Data), Data)
+}
diff --git a/codec/marshaler.go b/codec/marshaler.go
new file mode 100644
index 0000000..c6d33a3
--- /dev/null
+++ b/codec/marshaler.go
@@ -0,0 +1,229 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package codec
+
+import (
+ "bytes"
+ "encoding/binary"
+ "errors"
+ "fmt"
+ "math"
+ "reflect"
+ "unsafe"
+
+ "github.com/lunixbochs/struc"
+
+ "git.fd.io/govpp.git/api"
+)
+
+var DefaultCodec = &NewCodec{} // &MsgCodec{}
+
+// Marshaler is the interface implemented by the binary API messages that can
+// marshal itself into binary form for the wire.
+type Marshaler interface {
+ Size() int
+ Marshal([]byte) ([]byte, error)
+}
+
+// Unmarshaler is the interface implemented by the binary API messages that can
+// unmarshal a binary representation of itself from the wire.
+type Unmarshaler interface {
+ Unmarshal([]byte) error
+}
+
+type NewCodec struct{}
+
+func (*NewCodec) EncodeMsg(msg api.Message, msgID uint16) (data []byte, err error) {
+ if msg == nil {
+ return nil, errors.New("nil message passed in")
+ }
+ marshaller, ok := msg.(Marshaler)
+ if !ok {
+ return nil, fmt.Errorf("message %s does not implement marshaller", msg.GetMessageName())
+ }
+
+ size := marshaller.Size()
+ offset := getOffset(msg)
+ //fmt.Printf("size=%d offset=%d\n", size, offset)
+
+ b := make([]byte, size+offset)
+ b[0] = byte(msgID >> 8)
+ b[1] = byte(msgID)
+
+ //fmt.Printf("len(b)=%d cap(b)=%d\n", len(b), cap(b))
+ //b = append(b, byte(msgID>>8), byte(msgID))
+
+ //buf := new(bytes.Buffer)
+ //buf.Grow(size)
+
+ // encode msg ID
+ //buf.WriteByte(byte(msgID >> 8))
+ //buf.WriteByte(byte(msgID))
+
+ data, err = marshaller.Marshal(b[offset:])
+ if err != nil {
+ return nil, err
+ }
+ //buf.Write(b)
+
+ return b[0:len(b):len(b)], nil
+}
+
+func getOffset(msg api.Message) (offset int) {
+ switch msg.GetMessageType() {
+ case api.RequestMessage:
+ return 10
+ case api.ReplyMessage:
+ return 6
+ case api.EventMessage:
+ return 6
+ }
+ return 2
+}
+
+func (*NewCodec) DecodeMsg(data []byte, msg api.Message) (err error) {
+ if msg == nil {
+ return errors.New("nil message passed in")
+ }
+ marshaller, ok := msg.(Unmarshaler)
+ if !ok {
+ return fmt.Errorf("message %s does not implement marshaller", msg.GetMessageName())
+ }
+
+ offset := getOffset(msg)
+
+ err = marshaller.Unmarshal(data[offset:len(data)])
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func (*NewCodec) DecodeMsgContext(data []byte, msg api.Message) (context uint32, err error) {
+ if msg == nil {
+ return 0, errors.New("nil message passed in")
+ }
+
+ switch msg.GetMessageType() {
+ case api.RequestMessage:
+ return order.Uint32(data[6:10]), nil
+ case api.ReplyMessage:
+ return order.Uint32(data[2:6]), nil
+ }
+
+ return 0, nil
+}
+
+type OldCodec struct{}
+
+func (c *OldCodec) Marshal(v interface{}) (b []byte, err error) {
+ buf := new(bytes.Buffer)
+ if err := struc.Pack(buf, v); err != nil {
+ return nil, err
+ }
+ return buf.Bytes(), nil
+}
+
+func (c *OldCodec) Unmarshal(data []byte, v interface{}) error {
+ buf := bytes.NewReader(data)
+ if err := struc.Unpack(buf, v); err != nil {
+ return err
+ }
+ return nil
+}
+
+/*type CodecNew struct{}
+
+func (c *CodecNew) Marshal(v interface{}) (b []byte, err error) {
+ buf := new(bytes.Buffer)
+ if err := binary.Write(buf, binary.BigEndian, v); err != nil {
+ return nil, err
+ }
+ return buf.Bytes(), nil
+}*/
+
+func EncodeBool(b bool) byte {
+ if b {
+ return 1
+ }
+ return 0
+}
+
+func MarshalValue(value interface{}) []byte {
+ switch value.(type) {
+ case int8:
+ return []byte{byte(value.(int8))}
+ case uint8:
+ return []byte{byte(value.(uint8))}
+ }
+ return nil
+}
+
+var order = binary.BigEndian
+
+type Buffer struct {
+ pos int
+ buf []byte
+}
+
+func (b *Buffer) Bytes() []byte {
+ return b.buf[:b.pos]
+}
+
+func (b *Buffer) EncodeUint8(v uint8) {
+ b.buf[b.pos] = v
+ b.pos += 1
+}
+
+func (b *Buffer) EncodeUint16(v uint16) {
+ order.PutUint16(b.buf[b.pos:b.pos+2], v)
+ b.pos += 2
+}
+
+func (b *Buffer) EncodeUint32(v uint32) {
+ order.PutUint32(b.buf[b.pos:b.pos+4], v)
+ b.pos += 4
+}
+
+func (b *Buffer) EncodeUint64(v uint64) {
+ order.PutUint64(b.buf[b.pos:b.pos+8], v)
+ b.pos += 8
+}
+
+func (b *Buffer) EncodeFloat64(v float64) {
+ order.PutUint64(b.buf[b.pos:b.pos+8], math.Float64bits(v))
+ b.pos += 8
+}
+
+func (b *Buffer) EncodeBool(v bool) {
+ if v {
+ b.buf[b.pos] = 1
+ } else {
+ b.buf[b.pos] = 0
+ }
+ b.pos += 1
+}
+
+func (b *Buffer) EncodeString(v string) {
+
+ b.pos += 1
+}
+
+func DecodeString(b []byte) string {
+ sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
+ stringHeader := reflect.StringHeader{Data: sliceHeader.Data, Len: sliceHeader.Len}
+ return *(*string)(unsafe.Pointer(&stringHeader))
+}
diff --git a/codec/marshaler_test.go b/codec/marshaler_test.go
new file mode 100644
index 0000000..9a1887b
--- /dev/null
+++ b/codec/marshaler_test.go
@@ -0,0 +1,712 @@
+// Copyright (c) 2020 Cisco and/or its affiliates.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package codec_test
+
+import (
+ "bytes"
+ "encoding/binary"
+ "reflect"
+ "testing"
+
+ "github.com/lunixbochs/struc"
+
+ "git.fd.io/govpp.git/api"
+ "git.fd.io/govpp.git/codec"
+ "git.fd.io/govpp.git/examples/binapi/fib_types"
+ "git.fd.io/govpp.git/examples/binapi/interface_types"
+ "git.fd.io/govpp.git/examples/binapi/interfaces"
+ "git.fd.io/govpp.git/examples/binapi/ip"
+ "git.fd.io/govpp.git/examples/binapi/ip_types"
+ "git.fd.io/govpp.git/examples/binapi/sr"
+)
+
+/*func TestNewCodecEncodeDecode(t *testing.T) {
+ tests := []struct {
+ name string
+ msg Codec
+ }{
+ {
+ "", &TestAllMsg{
+ Bool: true,
+ AliasUint32: 5,
+ AliasArray: MacAddress{0x11, 0x22, 0x33, 0x44, 0x55, 0x66},
+ BaseArray: []uint32{0x00, 0x00, 0x00, 0x00},
+ Enum: IF_STATUS_API_FLAG_LINK_UP,
+ Uint8: 8,
+ Uint16: 16,
+ Uint32: 32,
+ Int8: 88,
+ Int16: 1616,
+ Int32: 3232,
+ Slice: []byte{10, 20, 30, 40, 0, 0, 0},
+ String: "abcdefghikl",
+ SizeOf: 2,
+ VariableSlice: []SliceType{
+ {Proto: IP_API_PROTO_AH},
+ {Proto: IP_API_PROTO_ESP},
+ },
+ TypeUnion: Address{
+ Af: ADDRESS_IP4,
+ Un: AddressUnionIP4(IP4Address{1, 2, 3, 4}),
+ },
+ },
+ },
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ data, err := test.msg.Marshal()
+ if err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+
+ var m2 TestAllMsg
+ if err := m2.Unmarshal(data); err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+
+ t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
+
+ if !reflect.DeepEqual(m, &m2) {
+ t.Fatalf("newData differs from oldData")
+ }
+ })
+ }
+}*/
+
+func NewTestAllMsg() *TestAllMsg {
+ return &TestAllMsg{
+ Bool: true,
+ AliasUint32: 5,
+ AliasArray: MacAddress{0x11, 0x22, 0x33, 0x44, 0x55, 0x66},
+ BaseArray: []uint32{0x00, 0x00, 0x00, 0x00},
+ Enum: IF_STATUS_API_FLAG_LINK_UP,
+ Uint8: 8,
+ Uint16: 16,
+ Uint32: 32,
+ Int8: 88,
+ Int16: 1616,
+ Int32: 3232,
+ Slice: []byte{10, 20, 30, 40, 0, 0, 0},
+ String: "abcdefghikl",
+ SizeOf: 2,
+ VariableSlice: []SliceType{
+ {Proto: IP_API_PROTO_AH},
+ {Proto: IP_API_PROTO_ESP},
+ },
+ TypeUnion: Address{
+ Af: ADDRESS_IP4,
+ Un: AddressUnionIP4(IP4Address{1, 2, 3, 4}),
+ },
+ }
+}
+
+func TestNewCodecEncodeDecode_(t *testing.T) {
+ m := NewTestAllMsg()
+
+ data, err := m.Marshal(nil)
+ if err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+
+ var m2 TestAllMsg
+ if err := m2.Unmarshal(data); err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+
+ t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
+
+ if !reflect.DeepEqual(m, &m2) {
+ t.Fatalf("newData differs from oldData")
+ }
+}
+
+// -------------
+
+func TestNewCodecEncodeDecode3(t *testing.T) {
+ m := NewTestAllMsg()
+ data, err := m.Marshal(nil)
+ if err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+
+ var m2 TestAllMsg
+ if err := m2.Unmarshal(data); err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+
+ t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
+
+ if !reflect.DeepEqual(m, &m2) {
+ t.Fatalf("newData differs from oldData")
+ }
+}
+func TestNewCodecEncodeDecode4(t *testing.T) {
+ m := &interfaces.SwInterfaceSetRxMode{
+ Mode: interface_types.RX_MODE_API_POLLING,
+ QueueID: 70000,
+ QueueIDValid: true,
+ SwIfIndex: 300,
+ }
+
+ b := make([]byte, 2+m.Size())
+
+ data, err := m.Marshal(b[2:])
+ if err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+
+ t.Logf("ENCODED DATA(%d): % 03x", len(data), data)
+
+ var m2 interfaces.SwInterfaceSetRxMode
+ if err := m2.Unmarshal(b[2:]); err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+
+ t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
+
+ if !reflect.DeepEqual(m, &m2) {
+ t.Fatalf("newData differs from oldData")
+ }
+}
+func TestNewCodecEncodeDecode2(t *testing.T) {
+ m := &sr.SrPoliciesDetails{
+ Bsid: sr.IP6Address{00, 11, 22, 33, 44, 55, 66, 77, 88, 99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
+ IsSpray: true,
+ IsEncap: false,
+ FibTable: 33,
+ NumSidLists: 1,
+ SidLists: []sr.Srv6SidList{
+ {
+ Weight: 555,
+ NumSids: 2,
+ Sids: [16]sr.IP6Address{
+ {99},
+ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
+ },
+ },
+ },
+ }
+
+ b := make([]byte, 0, m.Size())
+ data, err := m.Marshal(b)
+ if err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+
+ t.Logf("ENCODED DATA(%d): % 03x", len(data), data)
+
+ var m2 sr.SrPoliciesDetails
+ if err := m2.Unmarshal(data); err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+
+ t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
+
+ if !reflect.DeepEqual(m, &m2) {
+ t.Fatalf("newData differs from oldData")
+ }
+}
+
+func TestNewCodecEncode(t *testing.T) {
+ //m := NewIPRouteLookupReply()
+ m := &sr.SrPoliciesDetails{
+ Bsid: sr.IP6Address{00, 11, 22, 33, 44, 55, 66, 77, 88, 99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
+ IsSpray: true,
+ IsEncap: false,
+ FibTable: 33,
+ NumSidLists: 1,
+ SidLists: []sr.Srv6SidList{
+ {
+ Weight: 555,
+ NumSids: 2,
+ Sids: [16]sr.IP6Address{
+ {99},
+ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
+ },
+ },
+ },
+ }
+
+ size := m.Size()
+ t.Logf("size: %d", size)
+
+ var err error
+ var oldData, newData []byte
+ {
+ var c codec.OldCodec
+ oldData, err = c.Marshal(m)
+ if err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+ }
+ {
+ newData, err = m.Marshal(nil)
+ if err != nil {
+ t.Fatalf("expected nil error, got: %v", err)
+ }
+ }
+ t.Logf("Data:\nOLD[%d]: % 03x\nNEW[%d]: % 03x", len(oldData), oldData, len(newData), newData)
+
+ if !bytes.Equal(oldData, newData) {
+ t.Fatalf("newData differs from oldData")
+ }
+}
+
+func TestNewCodecDecode(t *testing.T) {
+ /*m := &ip.IPRouteLookupReply{}
+ size := m.Size()
+ t.Logf("size: %d", size)*/
+ data := []byte{
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03,
+ 0x00, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00,
+ 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00,
+ 0x00, 0x00, 0x08, 0x09, 0x0a, 0x00, 0x00, 0x00,
+ 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x02, 0x01, 0x09, 0x00,
+ 0x00, 0x00, 0x08, 0x07, 0x06, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ }
+
+ var err error
+ var oldData, newData ip.IPRouteLookupReply
+ {
+ var c codec.OldCodec
+ err = c.Unmarshal(data, &oldData)
+ if err != nil {
+ t.Errorf("expected nil error, got: %v", err)
+ }
+ }
+ {
+ err = newData.Unmarshal(data)
+ if err != nil {
+ t.Errorf("expected nil error, got: %v", err)
+ }
+ }
+ t.Logf("Data:\nOLD: %+v\nNEW: %+v", oldData, newData)
+
+ if !reflect.DeepEqual(oldData, newData) {
+ t.Fatalf("newData differs from oldData")
+ }
+}
+
+func NewIPRouteLookupReply() *ip.IPRouteLookupReply {
+ return &ip.IPRouteLookupReply{
+ Retval: 1,
+ Route: ip.IPRoute{
+ TableID: 3,
+ StatsIndex: 5,
+ Prefix: ip.Prefix{
+ Address: ip_types.Address{
+ Af: fib_types.ADDRESS_IP6,
+ Un: ip_types.AddressUnion{},
+ },
+ Len: 24,
+ },
+ NPaths: 2,
+ Paths: []ip.FibPath{
+ {
+ SwIfIndex: 5,
+ TableID: 6,
+ RpfID: 8,
+ Weight: 9,
+ Preference: 10,
+ Type: 11,
+ Flags: 1,
+ Proto: 2,
+ Nh: ip.FibPathNh{
+ Address: ip.AddressUnion{},
+ ViaLabel: 3,
+ ObjID: 1,
+ ClassifyTableIndex: 2,
+ },
+ NLabels: 1,
+ LabelStack: [16]ip.FibMplsLabel{
+ {
+ IsUniform: 9,
+ Label: 8,
+ TTL: 7,
+ Exp: 6,
+ },
+ },
+ },
+ {
+ SwIfIndex: 7,
+ TableID: 6,
+ RpfID: 8,
+ Weight: 9,
+ Preference: 10,
+ Type: 11,
+ Flags: 1,
+ Proto: 1,
+ Nh: ip.FibPathNh{
+ Address: ip.AddressUnion{},
+ ViaLabel: 3,
+ ObjID: 1,
+ ClassifyTableIndex: 2,
+ },
+ NLabels: 2,
+ LabelStack: [16]ip.FibMplsLabel{
+ {
+ IsUniform: 9,
+ Label: 8,
+ TTL: 7,
+ Exp: 6,
+ },
+ {
+ IsUniform: 10,
+ Label: 8,
+ TTL: 7,
+ Exp: 6,
+ },
+ },
+ },
+ },
+ },
+ }
+}
+
+func TestSize(t *testing.T) {
+ m := NewTestAllMsg()
+ size := binary.Size(*m)
+ t.Logf("size: %v", size)
+}
+
+func (m *TestAllMsg) Marshal(b []byte) ([]byte, error) {
+ order := binary.BigEndian
+ tmp := make([]byte, 143)
+ pos := 0
+
+ tmp[pos] = boolToUint(m.Bool)
+ pos += 1
+
+ tmp[pos] = m.Uint8
+ pos += 1
+
+ order.PutUint16(tmp[pos:pos+2], m.Uint16)
+ pos += 2
+
+ order.PutUint32(tmp[pos:pos+4], m.Uint32)
+ pos += 4
+
+ tmp[pos] = byte(m.Int8)
+ pos += 1
+
+ order.PutUint16(tmp[pos:pos+2], uint16(m.Int16))
+ pos += 2
+
+ order.PutUint32(tmp[pos:pos+4], uint32(m.Int32))
+ pos += 4
+
+ order.PutUint32(tmp[pos:pos+4], uint32(m.AliasUint32))
+ pos += 4
+
+ copy(tmp[pos:pos+6], m.AliasArray[:])
+ pos += 6
+
+ order.PutUint32(tmp[pos:pos+4], uint32(m.Enum))
+ pos += 4
+
+ for i := 0; i < 4; i++ {
+ var x uint32
+ if i < len(m.BaseArray) {
+ x = m.BaseArray[i]
+ }
+ order.PutUint32(tmp[pos:pos+4], uint32(x))
+ pos += 4
+ }
+
+ copy(tmp[pos:pos+7], m.Slice)
+ pos += 7
+
+ copy(tmp[pos:pos+64], m.String)
+ pos += 64
+
+ order.PutUint32(tmp[pos:pos+4], uint32(len(m.VlaStr)) /*m.SizeOf*/)
+ pos += 4
+
+ copy(tmp[pos:pos+len(m.VlaStr)], m.VlaStr[:])
+ pos += len(m.VlaStr)
+
+ order.PutUint32(tmp[pos:pos+4], uint32(len(m.VariableSlice)) /*m.SizeOf*/)
+ pos += 4
+
+ for i := range m.VariableSlice {
+ tmp[pos+i*1] = uint8(m.VariableSlice[i].Proto)
+ //copy(tmp[102+i:103+i], []byte{byte(m.VariableSlice[i].Proto)})
+ }
+ pos += len(m.VariableSlice) * 1
+
+ tmp[pos] = uint8(m.TypeUnion.Af)
+ pos += 1
+
+ copy(tmp[pos:pos+16], m.TypeUnion.Un.XXX_UnionData[:])
+ pos += 16
+
+ return tmp, nil
+
+ /*_, err := buf.Write(tmp)
+ if err != nil {
+ return nil, err
+ }
+ return buf.Bytes(), nil*/
+}
+
+func (m *TestAllMsg) Unmarshal(tmp []byte) error {
+ order := binary.BigEndian
+
+ //tmp := make([]byte, 143)
+ pos := 0
+
+ m.Bool = tmp[pos] != 0
+ pos += 1
+
+ //tmp[pos] = m.Uint8
+ m.Uint8 = tmp[pos]
+ pos += 1
+
+ //order.PutUint16(tmp[pos:pos+2], m.Uint16)
+ m.Uint16 = order.Uint16(tmp[pos : pos+2])
+ pos += 2
+
+ //order.PutUint32(tmp[pos:pos+4], m.Uint32)
+ m.Uint32 = order.Uint32(tmp[pos : pos+4])
+ pos += 4
+
+ //tmp[pos] = byte(m.Int8)
+ m.Int8 = int8(tmp[pos])
+ pos += 1
+
+ //order.PutUint16(tmp[pos:pos+2], uint16(m.Int16))
+ m.Int16 = int16(order.Uint16(tmp[pos : pos+2]))
+ pos += 2
+
+ //order.PutUint32(tmp[pos:pos+4], uint32(m.Int32))
+ m.Int32 = int32(order.Uint32(tmp[pos : pos+4]))
+ pos += 4
+
+ //order.PutUint32(tmp[pos:pos+4], uint32(m.AliasUint32))
+ m.AliasUint32 = InterfaceIndex(order.Uint32(tmp[pos : pos+4]))
+ pos += 4
+
+ //copy(tmp[pos:pos+6], m.AliasArray[:])
+ copy(m.AliasArray[:], tmp[pos:pos+6])
+ pos += 6
+
+ //order.PutUint32(tmp[pos:pos+4], uint32(m.Enum))
+ m.Enum = IfStatusFlags(order.Uint32(tmp[pos : pos+4]))
+ pos += 4
+
+ m.BaseArray = make([]uint32, 4)
+ for i := 0; i < 4; i++ {
+ /*var x uint32
+ if i < len(m.BaseArray) {
+ x = m.BaseArray[i]
+ }
+ order.PutUint32(tmp[pos:pos+4], uint32(x))*/
+ m.BaseArray[i] = order.Uint32(tmp[pos : pos+4])
+ pos += 4
+ }
+
+ m.Slice = make([]byte, 7)
+ copy(m.Slice[:7], tmp[pos:pos+7])
+ //copy(tmp[pos:pos+7], m.Slice)
+ pos += 7
+
+ i := bytes.Index(tmp[pos:pos+64], []byte{0x00})
+ m.String = string(tmp[pos : pos+i])
+ //copy(tmp[pos:pos+64], m.String)
+ pos += 64
+
+ //order.PutUint32(tmp[pos:pos+4], uint32(len(m.VlaStr)) /*m.SizeOf*/)
+ VlaStrLen := int(order.Uint32(tmp[pos : pos+4]))
+ pos += 4
+
+ m.VlaStr = string(tmp[pos : pos+VlaStrLen])
+ //copy(m.VlaStr[pos:pos+VlaStrLen], tmp[pos:pos+64])
+ pos += len(m.VlaStr)
+
+ m.SizeOf = uint32(order.Uint32(tmp[pos : pos+4]))
+ pos += 4
+
+ /*order.PutUint32(tmp[pos:pos+4], uint32(len(m.VariableSlice)))
+ m.VariableSlice = IfStatusFlags(order.Uint32(tmp[pos : pos+4]))
+ pos += 4*/
+
+ m.VariableSlice = make([]SliceType, m.SizeOf)
+ for i := range m.VariableSlice {
+ //tmp[pos+i*1] = uint8(m.VariableSlice[i].Proto)
+ m.VariableSlice[i].Proto = IPProto(tmp[pos+i*1])
+ //copy(tmp[102+i:103+i], []byte{byte(m.VariableSlice[i].Proto)})
+ }
+ pos += len(m.VariableSlice) * 1
+
+ //tmp[pos] = uint8(m.TypeUnion.Af)
+ m.TypeUnion.Af = AddressFamily(tmp[pos])
+ pos += 1
+
+ //copy(tmp[pos:pos+16], m.TypeUnion.Un.XXX_UnionData[:])
+ copy(m.TypeUnion.Un.XXX_UnionData[:], tmp[pos:pos+16])
+ pos += 16
+
+ return nil
+ /*_, err := buf.Write(tmp)
+ if err != nil {
+ return nil, err
+ }
+ return buf.Bytes(), nil*/
+}
+
+func boolToUint(b bool) uint8 {
+ if b {
+ return 1
+ }
+ return 0
+}
+
+// SwInterfaceDetails represents VPP binary API message 'sw_interface_details'.
+type TestAllMsg struct {
+ Bool bool
+ Uint8 uint8
+ Uint16 uint16
+ Uint32 uint32
+ Int8 int8
+ Int16 int16
+ Int32 int32
+ AliasUint32 InterfaceIndex
+ AliasArray MacAddress
+ Enum IfStatusFlags
+ BaseArray []uint32 `struc:"[4]uint32"`
+ Slice []byte `struc:"[7]byte"`
+ String string `struc:"[64]byte"`
+ XXX_VlaStrLen uint32 `struc:"sizeof=VlaStr"`
+ VlaStr string
+ SizeOf uint32 `struc:"sizeof=VariableSlice"`
+ VariableSlice []SliceType
+ TypeUnion Address
+}
+
+type InterfaceIndex uint32
+type MacAddress [6]uint8
+type IfStatusFlags uint32
+
+const (
+ IF_STATUS_API_FLAG_ADMIN_UP IfStatusFlags = 1
+ IF_STATUS_API_FLAG_LINK_UP IfStatusFlags = 2
+)
+
+// Address represents VPP binary API type 'address'.
+type Address struct {
+ Af AddressFamily
+ Un AddressUnion
+}
+
+// AddressFamily represents VPP binary API enum 'address_family'.
+type AddressFamily uint8
+
+const (
+ ADDRESS_IP4 AddressFamily = 0
+ ADDRESS_IP6 AddressFamily = 1
+)
+
+// AddressUnion represents VPP binary API union 'address_union'.
+type AddressUnion struct {
+ XXX_UnionData [16]byte
+}
+
+func (*AddressUnion) GetTypeName() string { return "address_union" }
+
+func AddressUnionIP4(a IP4Address) (u AddressUnion) {
+ u.SetIP4(a)
+ return
+}
+func (u *AddressUnion) SetIP4(a IP4Address) {
+ var b = new(bytes.Buffer)
+ if err := struc.Pack(b, &a); err != nil {
+ return
+ }
+ copy(u.XXX_UnionData[:], b.Bytes())
+}
+func (u *AddressUnion) GetIP4() (a IP4Address) {
+ var b = bytes.NewReader(u.XXX_UnionData[:])
+ struc.Unpack(b, &a)
+ return
+}
+
+func AddressUnionIP6(a IP6Address) (u AddressUnion) {
+ u.SetIP6(a)
+ return
+}
+func (u *AddressUnion) SetIP6(a IP6Address) {
+ var b = new(bytes.Buffer)
+ if err := struc.Pack(b, &a); err != nil {
+ return
+ }
+ copy(u.XXX_UnionData[:], b.Bytes())
+}
+func (u *AddressUnion) GetIP6() (a IP6Address) {
+ var b = bytes.NewReader(u.XXX_UnionData[:])
+ struc.Unpack(b, &a)
+ return
+}
+
+// IP4Address represents VPP binary API alias 'ip4_address'.
+type IP4Address [4]uint8
+
+// IP6Address represents VPP binary API alias 'ip6_address'.
+type IP6Address [16]uint8
+
+type SliceType struct {
+ Proto IPProto
+}
+
+type IPProto uint8
+
+const (
+ IP_API_PROTO_HOPOPT IPProto = 0
+ IP_API_PROTO_ICMP IPProto = 1
+ IP_API_PROTO_IGMP IPProto = 2
+ IP_API_PROTO_TCP IPProto = 6
+ IP_API_PROTO_UDP IPProto = 17
+ IP_API_PROTO_GRE IPProto = 47
+ IP_API_PROTO_ESP IPProto = 50
+ IP_API_PROTO_AH IPProto = 51
+ IP_API_PROTO_ICMP6 IPProto = 58
+ IP_API_PROTO_EIGRP IPProto = 88
+ IP_API_PROTO_OSPF IPProto = 89
+ IP_API_PROTO_SCTP IPProto = 132
+ IP_API_PROTO_RESERVED IPProto = 255
+)
+
+func (m *TestAllMsg) Reset() { *m = TestAllMsg{} }
+func (*TestAllMsg) GetMessageName() string { return "sw_interface_details" }
+func (*TestAllMsg) GetCrcString() string { return "17b69fa2" }
+func (*TestAllMsg) GetMessageType() api.MessageType { return api.ReplyMessage }
diff --git a/codec/msg_codec_test.go b/codec/msg_codec_test.go
index cd1240e..bf0695d 100644
--- a/codec/msg_codec_test.go
+++ b/codec/msg_codec_test.go
@@ -1,10 +1,16 @@
-package codec
+package codec_test
import (
"bytes"
"testing"
+ "github.com/lunixbochs/struc"
+
"git.fd.io/govpp.git/api"
+ "git.fd.io/govpp.git/codec"
+ "git.fd.io/govpp.git/examples/binapi/ip"
+ "git.fd.io/govpp.git/examples/binapi/sr"
+ "git.fd.io/govpp.git/examples/binapi/vpe"
)
type MyMsg struct {
@@ -30,15 +36,69 @@ func TestEncode(t *testing.T) {
msgID uint16
expData []byte
}{
- {name: "basic",
+ /*{name: "basic",
msg: &MyMsg{Index: 1, Label: []byte("Abcdef"), Port: 1000},
msgID: 100,
expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8},
+ },*/
+ {name: "show version",
+ msg: &vpe.ShowVersion{},
+ msgID: 743,
+ expData: []byte{0x02, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ },
+ {name: "ip route",
+ msg: &ip.IPRouteAddDel{
+ IsAdd: true,
+ IsMultipath: true,
+ Route: ip.IPRoute{
+ TableID: 0,
+ StatsIndex: 0,
+ Prefix: ip.Prefix{},
+ NPaths: 0,
+ Paths: []ip.FibPath{
+ {
+ SwIfIndex: 0,
+ TableID: 0,
+ RpfID: 0,
+ Weight: 0,
+ Preference: 0,
+ Type: 0,
+ Flags: 0,
+ Proto: 0,
+ Nh: ip.FibPathNh{},
+ NLabels: 5,
+ LabelStack: [16]ip.FibMplsLabel{
+ {
+ IsUniform: 1,
+ Label: 2,
+ TTL: 3,
+ Exp: 4,
+ },
+ },
+ },
+ },
+ },
+ },
+ msgID: 743,
+ expData: []byte{0x02, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
},
+ /*{name: "sr",
+ msg: &sr.SrPolicyAdd{
+ BsidAddr: sr.IP6Address{},
+ Weight: 0,
+ IsEncap: false,
+ IsSpray: false,
+ FibTable: 0,
+ Sids: sr.Srv6SidList{},
+ },
+ msgID: 99,
+ expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8},
+ },*/
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- c := &MsgCodec{}
+ c := &codec.MsgCodec{}
+ //c := &codec.NewCodec{}
data, err := c.EncodeMsg(test.msg, test.msgID)
if err != nil {
@@ -52,7 +112,7 @@ func TestEncode(t *testing.T) {
}
func TestEncodePanic(t *testing.T) {
- c := &MsgCodec{}
+ c := &codec.MsgCodec{}
msg := &MyMsg{Index: 1, Label: []byte("thisIsLongerThan16Bytes"), Port: 1000}
@@ -61,3 +121,16 @@ func TestEncodePanic(t *testing.T) {
t.Fatalf("expected non-nil error, got: %v", err)
}
}
+
+func TestEncodeSr(t *testing.T) {
+ msg := sr.Srv6SidList{
+ NumSids: 0,
+ Weight: 0,
+ //Sids: nil,
+ }
+ buf := new(bytes.Buffer)
+
+ if err := struc.Pack(buf, msg); err != nil {
+ t.Fatal(err)
+ }
+}
diff --git a/examples/binapi/acl/acl.ba.go b/examples/binapi/acl/acl.ba.go
index 1f9528e..b42fb5f 100644
--- a/examples/binapi/acl/acl.ba.go
+++ b/examples/binapi/acl/acl.ba.go
@@ -1,648 +1,2794 @@
// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+// versions:
+// binapi-generator: v0.4.0-alpha-1-g435c3f4-dirty
+// VPP: 20.01-45~g7a071e370~b63
// source: /usr/share/vpp/api/plugins/acl.api.json
/*
-Package acl is a generated VPP binary API for 'acl' module.
+Package acl contains generated code for VPP binary API defined by acl.api (version 1.0.1).
It consists of:
+ 38 messages
2 types
- 36 messages
- 18 services
*/
package acl
import (
- bytes "bytes"
- context "context"
+ "bytes"
+ "context"
+ "encoding/binary"
+ "io"
+ "math"
+ "strconv"
+
api "git.fd.io/govpp.git/api"
+ codec "git.fd.io/govpp.git/codec"
struc "github.com/lunixbochs/struc"
- io "io"
- strconv "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 // please upgrade the GoVPP api package
+
const (
// ModuleName is the name of this module.
ModuleName = "acl"
// APIVersion is the API version of this module.
APIVersion = "1.0.1"
// VersionCrc is the CRC of this module.
- VersionCrc = 0x8ed22cb9
+ VersionCrc = 0x11c5c1e5
)
// ACLRule represents VPP binary API type 'acl_rule'.
type ACLRule struct {
- IsPermit uint8
- IsIPv6 uint8
- SrcIPAddr []byte `struc:"[16]byte"`
- SrcIPPrefixLen uint8
- DstIPAddr []byte `struc:"[16]byte"`
- DstIPPrefixLen uint8
- Proto uint8
- SrcportOrIcmptypeFirst uint16
- SrcportOrIcmptypeLast uint16
- DstportOrIcmpcodeFirst uint16
- DstportOrIcmpcodeLast uint16
- TCPFlagsMask uint8
- TCPFlagsValue uint8
-}
-
-func (*ACLRule) GetTypeName() string {
- return "acl_rule"
-}
-func (*ACLRule) GetCrcString() string {
- return "6f99bf4d"
-}
+ IsPermit uint8 `binapi:"u8,name=is_permit" json:"is_permit,omitempty"`
+ IsIPv6 uint8 `binapi:"u8,name=is_ipv6" json:"is_ipv6,omitempty"`
+ SrcIPAddr []byte `binapi:"u8[16],name=src_ip_addr" json:"src_ip_addr,omitempty" struc:"[16]byte"`
+ SrcIPPrefixLen uint8 `binapi:"u8,name=src_ip_prefix_len" json:"src_ip_prefix_len,omitempty"`
+ DstIPAddr []byte `binapi:"u8[16],name=dst_ip_addr" json:"dst_ip_addr,omitempty" struc:"[16]byte"`
+ DstIPPrefixLen uint8 `binapi:"u8,name=dst_ip_prefix_len" json:"dst_ip_prefix_len,omitempty"`
+ Proto uint8 `binapi:"u8,name=proto" json:"proto,omitempty"`
+ SrcportOrIcmptypeFirst uint16 `binapi:"u16,name=srcport_or_icmptype_first" json:"srcport_or_icmptype_first,omitempty"`
+ SrcportOrIcmptypeLast uint16 `binapi:"u16,name=srcport_or_icmptype_last" json:"srcport_or_icmptype_last,omitempty"`
+ DstportOrIcmpcodeFirst uint16 `binapi:"u16,name=dstport_or_icmpcode_first" json:"dstport_or_icmpcode_first,omitempty"`
+ DstportOrIcmpcodeLast uint16 `binapi:"u16,name=dstport_or_icmpcode_last" json:"dstport_or_icmpcode_last,omitempty"`
+ TCPFlagsMask uint8 `binapi:"u8,name=tcp_flags_mask" json:"tcp_flags_mask,omitempty"`
+ TCPFlagsValue uint8 `binapi:"u8,name=tcp_flags_value" json:"tcp_flags_value,omitempty"`
+}
+
+func (*ACLRule) GetTypeName() string { return "acl_rule" }
// MacipACLRule represents VPP binary API type 'macip_acl_rule'.
type MacipACLRule struct {
- IsPermit uint8
- IsIPv6 uint8
- SrcMac []byte `struc:"[6]byte"`
- SrcMacMask []byte `struc:"[6]byte"`
- SrcIPAddr []byte `struc:"[16]byte"`
- SrcIPPrefixLen uint8
+ IsPermit uint8 `binapi:"u8,name=is_permit" json:"is_permit,omitempty"`
+ IsIPv6 uint8 `binapi:"u8,name=is_ipv6" json:"is_ipv6,omitempty"`
+ SrcMac []byte `binapi:"u8[6],name=src_mac" json:"src_mac,omitempty" struc:"[6]byte"`
+ SrcMacMask []byte `binapi:"u8[6],name=src_mac_mask" json:"src_mac_mask,omitempty" struc:"[6]byte"`
+ SrcIPAddr []byte `binapi:"u8[16],name=src_ip_addr" json:"src_ip_addr,omitempty" struc:"[16]byte"`
+ SrcIPPrefixLen uint8 `binapi:"u8,name=src_ip_prefix_len" json:"src_ip_prefix_len,omitempty"`
}
-func (*MacipACLRule) GetTypeName() string {
- return "macip_acl_rule"
-}
-func (*MacipACLRule) GetCrcString() string {
- return "70589f1e"
-}
+func (*MacipACLRule) GetTypeName() string { return "macip_acl_rule" }
// ACLAddReplace represents VPP binary API message 'acl_add_replace'.
type ACLAddReplace struct {
- ACLIndex uint32
- Tag []byte `struc:"[64]byte"`
- Count uint32 `struc:"sizeof=R"`
- R []ACLRule
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
+ Tag []byte `binapi:"u8[64],name=tag" json:"tag,omitempty" struc:"[64]byte"`
+ Count uint32 `binapi:"u32,name=count" json:"count,omitempty" struc:"sizeof=R"`
+ R []ACLRule `binapi:"acl_rule[count],name=r" json:"r,omitempty"`
}
-func (*ACLAddReplace) GetMessageName() string {
- return "acl_add_replace"
-}
-func (*ACLAddReplace) GetCrcString() string {
- return "e839997e"
-}
-func (*ACLAddReplace) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *ACLAddReplace) Reset() { *m = ACLAddReplace{} }
+func (*ACLAddReplace) GetMessageName() string { return "acl_add_replace" }
+func (*ACLAddReplace) GetCrcString() string { return "13bc8539" }
+func (*ACLAddReplace) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLAddReplace) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ // field[1] m.Tag
+ size += 64
+ // field[1] m.Count
+ size += 4
+ // field[1] m.R
+ for j1 := 0; j1 < len(m.R); j1++ {
+ var s1 ACLRule
+ _ = s1
+ if j1 < len(m.R) {
+ s1 = m.R[j1]
+ }
+ // field[2] s1.IsPermit
+ size += 1
+ // field[2] s1.IsIPv6
+ size += 1
+ // field[2] s1.SrcIPAddr
+ size += 16
+ // field[2] s1.SrcIPPrefixLen
+ size += 1
+ // field[2] s1.DstIPAddr
+ size += 16
+ // field[2] s1.DstIPPrefixLen
+ size += 1
+ // field[2] s1.Proto
+ size += 1
+ // field[2] s1.SrcportOrIcmptypeFirst
+ size += 2
+ // field[2] s1.SrcportOrIcmptypeLast
+ size += 2
+ // field[2] s1.DstportOrIcmpcodeFirst
+ size += 2
+ // field[2] s1.DstportOrIcmpcodeLast
+ size += 2
+ // field[2] s1.TCPFlagsMask
+ size += 1
+ // field[2] s1.TCPFlagsValue
+ size += 1
+ }
+ return size
+}
+func (m *ACLAddReplace) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ // field[1] m.Tag
+ for i := 0; i < 64; i++ {
+ var x uint8
+ if i < len(m.Tag) {
+ x = uint8(m.Tag[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.Count
+ o.PutUint32(buf[pos:pos+4], uint32(len(m.R)))
+ pos += 4
+ // field[1] m.R
+ for j1 := 0; j1 < len(m.R); j1++ {
+ var v1 ACLRule
+ if j1 < len(m.R) {
+ v1 = m.R[j1]
+ }
+ // field[2] v1.IsPermit
+ buf[pos] = uint8(v1.IsPermit)
+ pos += 1
+ // field[2] v1.IsIPv6
+ buf[pos] = uint8(v1.IsIPv6)
+ pos += 1
+ // field[2] v1.SrcIPAddr
+ for i := 0; i < 16; i++ {
+ var x uint8
+ if i < len(v1.SrcIPAddr) {
+ x = uint8(v1.SrcIPAddr[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcIPPrefixLen
+ buf[pos] = uint8(v1.SrcIPPrefixLen)
+ pos += 1
+ // field[2] v1.DstIPAddr
+ for i := 0; i < 16; i++ {
+ var x uint8
+ if i < len(v1.DstIPAddr) {
+ x = uint8(v1.DstIPAddr[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.DstIPPrefixLen
+ buf[pos] = uint8(v1.DstIPPrefixLen)
+ pos += 1
+ // field[2] v1.Proto
+ buf[pos] = uint8(v1.Proto)
+ pos += 1
+ // field[2] v1.SrcportOrIcmptypeFirst
+ o.PutUint16(buf[pos:pos+2], uint16(v1.SrcportOrIcmptypeFirst))
+ pos += 2
+ // field[2] v1.SrcportOrIcmptypeLast
+ o.PutUint16(buf[pos:pos+2], uint16(v1.SrcportOrIcmptypeLast))
+ pos += 2
+ // field[2] v1.DstportOrIcmpcodeFirst
+ o.PutUint16(buf[pos:pos+2], uint16(v1.DstportOrIcmpcodeFirst))
+ pos += 2
+ // field[2] v1.DstportOrIcmpcodeLast
+ o.PutUint16(buf[pos:pos+2], uint16(v1.DstportOrIcmpcodeLast))
+ pos += 2
+ // field[2] v1.TCPFlagsMask
+ buf[pos] = uint8(v1.TCPFlagsMask)
+ pos += 1
+ // field[2] v1.TCPFlagsValue
+ buf[pos] = uint8(v1.TCPFlagsValue)
+ pos += 1
+ }
+ return buf, nil
+}
+func (m *ACLAddReplace) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Tag
+ m.Tag = make([]uint8, 64)
+ for i := 0; i < len(m.Tag); i++ {
+ m.Tag[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.Count
+ m.Count = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.R
+ m.R = make([]ACLRule, int(m.Count))
+ for j1 := 0; j1 < int(m.Count); j1++ {
+ // field[2] m.R[j1].IsPermit
+ m.R[j1].IsPermit = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].IsIPv6
+ m.R[j1].IsIPv6 = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].SrcIPAddr
+ m.R[j1].SrcIPAddr = make([]uint8, 16)
+ for i := 0; i < len(m.R[j1].SrcIPAddr); i++ {
+ m.R[j1].SrcIPAddr[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcIPPrefixLen
+ m.R[j1].SrcIPPrefixLen = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].DstIPAddr
+ m.R[j1].DstIPAddr = make([]uint8, 16)
+ for i := 0; i < len(m.R[j1].DstIPAddr); i++ {
+ m.R[j1].DstIPAddr[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].DstIPPrefixLen
+ m.R[j1].DstIPPrefixLen = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].Proto
+ m.R[j1].Proto = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].SrcportOrIcmptypeFirst
+ m.R[j1].SrcportOrIcmptypeFirst = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[2] m.R[j1].SrcportOrIcmptypeLast
+ m.R[j1].SrcportOrIcmptypeLast = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[2] m.R[j1].DstportOrIcmpcodeFirst
+ m.R[j1].DstportOrIcmpcodeFirst = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[2] m.R[j1].DstportOrIcmpcodeLast
+ m.R[j1].DstportOrIcmpcodeLast = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[2] m.R[j1].TCPFlagsMask
+ m.R[j1].TCPFlagsMask = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].TCPFlagsValue
+ m.R[j1].TCPFlagsValue = uint8(tmp[pos])
+ pos += 1
+ }
+ return nil
}
// ACLAddReplaceReply represents VPP binary API message 'acl_add_replace_reply'.
type ACLAddReplaceReply struct {
- ACLIndex uint32
- Retval int32
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
-func (*ACLAddReplaceReply) GetMessageName() string {
- return "acl_add_replace_reply"
-}
-func (*ACLAddReplaceReply) GetCrcString() string {
- return "ac407b0c"
-}
-func (*ACLAddReplaceReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *ACLAddReplaceReply) Reset() { *m = ACLAddReplaceReply{} }
+func (*ACLAddReplaceReply) GetMessageName() string { return "acl_add_replace_reply" }
+func (*ACLAddReplaceReply) GetCrcString() string { return "ac407b0c" }
+func (*ACLAddReplaceReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *ACLAddReplaceReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *ACLAddReplaceReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLAddReplaceReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLDel represents VPP binary API message 'acl_del'.
type ACLDel struct {
- ACLIndex uint32
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
}
-func (*ACLDel) GetMessageName() string {
- return "acl_del"
-}
-func (*ACLDel) GetCrcString() string {
- return "ef34fea4"
-}
-func (*ACLDel) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *ACLDel) Reset() { *m = ACLDel{} }
+func (*ACLDel) GetMessageName() string { return "acl_del" }
+func (*ACLDel) GetCrcString() string { return "ef34fea4" }
+func (*ACLDel) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLDel) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ return size
+}
+func (m *ACLDel) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLDel) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLDelReply represents VPP binary API message 'acl_del_reply'.
type ACLDelReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
-func (*ACLDelReply) GetMessageName() string {
- return "acl_del_reply"
-}
-func (*ACLDelReply) GetCrcString() string {
- return "e8d4e804"
-}
-func (*ACLDelReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *ACLDelReply) Reset() { *m = ACLDelReply{} }
+func (*ACLDelReply) GetMessageName() string { return "acl_del_reply" }
+func (*ACLDelReply) GetCrcString() string { return "e8d4e804" }
+func (*ACLDelReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *ACLDelReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *ACLDelReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLDelReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLDetails represents VPP binary API message 'acl_details'.
type ACLDetails struct {
- ACLIndex uint32
- Tag []byte `struc:"[64]byte"`
- Count uint32 `struc:"sizeof=R"`
- R []ACLRule
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
+ Tag []byte `binapi:"u8[64],name=tag" json:"tag,omitempty" struc:"[64]byte"`
+ Count uint32 `binapi:"u32,name=count" json:"count,omitempty" struc:"sizeof=R"`
+ R []ACLRule `binapi:"acl_rule[count],name=r" json:"r,omitempty"`
}
-func (*ACLDetails) GetMessageName() string {
- return "acl_details"
-}
-func (*ACLDetails) GetCrcString() string {
- return "5bd895be"
-}
-func (*ACLDetails) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *ACLDetails) Reset() { *m = ACLDetails{} }
+func (*ACLDetails) GetMessageName() string { return "acl_details" }
+func (*ACLDetails) GetCrcString() string { return "f89d7a88" }
+func (*ACLDetails) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *ACLDetails) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ // field[1] m.Tag
+ size += 64
+ // field[1] m.Count
+ size += 4
+ // field[1] m.R
+ for j1 := 0; j1 < len(m.R); j1++ {
+ var s1 ACLRule
+ _ = s1
+ if j1 < len(m.R) {
+ s1 = m.R[j1]
+ }
+ // field[2] s1.IsPermit
+ size += 1
+ // field[2] s1.IsIPv6
+ size += 1
+ // field[2] s1.SrcIPAddr
+ size += 16
+ // field[2] s1.SrcIPPrefixLen
+ size += 1
+ // field[2] s1.DstIPAddr
+ size += 16
+ // field[2] s1.DstIPPrefixLen
+ size += 1
+ // field[2] s1.Proto
+ size += 1
+ // field[2] s1.SrcportOrIcmptypeFirst
+ size += 2
+ // field[2] s1.SrcportOrIcmptypeLast
+ size += 2
+ // field[2] s1.DstportOrIcmpcodeFirst
+ size += 2
+ // field[2] s1.DstportOrIcmpcodeLast
+ size += 2
+ // field[2] s1.TCPFlagsMask
+ size += 1
+ // field[2] s1.TCPFlagsValue
+ size += 1
+ }
+ return size
+}
+func (m *ACLDetails) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ // field[1] m.Tag
+ for i := 0; i < 64; i++ {
+ var x uint8
+ if i < len(m.Tag) {
+ x = uint8(m.Tag[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.Count
+ o.PutUint32(buf[pos:pos+4], uint32(len(m.R)))
+ pos += 4
+ // field[1] m.R
+ for j1 := 0; j1 < len(m.R); j1++ {
+ var v1 ACLRule
+ if j1 < len(m.R) {
+ v1 = m.R[j1]
+ }
+ // field[2] v1.IsPermit
+ buf[pos] = uint8(v1.IsPermit)
+ pos += 1
+ // field[2] v1.IsIPv6
+ buf[pos] = uint8(v1.IsIPv6)
+ pos += 1
+ // field[2] v1.SrcIPAddr
+ for i := 0; i < 16; i++ {
+ var x uint8
+ if i < len(v1.SrcIPAddr) {
+ x = uint8(v1.SrcIPAddr[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcIPPrefixLen
+ buf[pos] = uint8(v1.SrcIPPrefixLen)
+ pos += 1
+ // field[2] v1.DstIPAddr
+ for i := 0; i < 16; i++ {
+ var x uint8
+ if i < len(v1.DstIPAddr) {
+ x = uint8(v1.DstIPAddr[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.DstIPPrefixLen
+ buf[pos] = uint8(v1.DstIPPrefixLen)
+ pos += 1
+ // field[2] v1.Proto
+ buf[pos] = uint8(v1.Proto)
+ pos += 1
+ // field[2] v1.SrcportOrIcmptypeFirst
+ o.PutUint16(buf[pos:pos+2], uint16(v1.SrcportOrIcmptypeFirst))
+ pos += 2
+ // field[2] v1.SrcportOrIcmptypeLast
+ o.PutUint16(buf[pos:pos+2], uint16(v1.SrcportOrIcmptypeLast))
+ pos += 2
+ // field[2] v1.DstportOrIcmpcodeFirst
+ o.PutUint16(buf[pos:pos+2], uint16(v1.DstportOrIcmpcodeFirst))
+ pos += 2
+ // field[2] v1.DstportOrIcmpcodeLast
+ o.PutUint16(buf[pos:pos+2], uint16(v1.DstportOrIcmpcodeLast))
+ pos += 2
+ // field[2] v1.TCPFlagsMask
+ buf[pos] = uint8(v1.TCPFlagsMask)
+ pos += 1
+ // field[2] v1.TCPFlagsValue
+ buf[pos] = uint8(v1.TCPFlagsValue)
+ pos += 1
+ }
+ return buf, nil
+}
+func (m *ACLDetails) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Tag
+ m.Tag = make([]uint8, 64)
+ for i := 0; i < len(m.Tag); i++ {
+ m.Tag[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.Count
+ m.Count = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.R
+ m.R = make([]ACLRule, int(m.Count))
+ for j1 := 0; j1 < int(m.Count); j1++ {
+ // field[2] m.R[j1].IsPermit
+ m.R[j1].IsPermit = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].IsIPv6
+ m.R[j1].IsIPv6 = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].SrcIPAddr
+ m.R[j1].SrcIPAddr = make([]uint8, 16)
+ for i := 0; i < len(m.R[j1].SrcIPAddr); i++ {
+ m.R[j1].SrcIPAddr[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcIPPrefixLen
+ m.R[j1].SrcIPPrefixLen = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].DstIPAddr
+ m.R[j1].DstIPAddr = make([]uint8, 16)
+ for i := 0; i < len(m.R[j1].DstIPAddr); i++ {
+ m.R[j1].DstIPAddr[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].DstIPPrefixLen
+ m.R[j1].DstIPPrefixLen = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].Proto
+ m.R[j1].Proto = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].SrcportOrIcmptypeFirst
+ m.R[j1].SrcportOrIcmptypeFirst = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[2] m.R[j1].SrcportOrIcmptypeLast
+ m.R[j1].SrcportOrIcmptypeLast = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[2] m.R[j1].DstportOrIcmpcodeFirst
+ m.R[j1].DstportOrIcmpcodeFirst = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[2] m.R[j1].DstportOrIcmpcodeLast
+ m.R[j1].DstportOrIcmpcodeLast = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[2] m.R[j1].TCPFlagsMask
+ m.R[j1].TCPFlagsMask = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].TCPFlagsValue
+ m.R[j1].TCPFlagsValue = uint8(tmp[pos])
+ pos += 1
+ }
+ return nil
}
// ACLDump represents VPP binary API message 'acl_dump'.
type ACLDump struct {
- ACLIndex uint32
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
}
-func (*ACLDump) GetMessageName() string {
- return "acl_dump"
-}
-func (*ACLDump) GetCrcString() string {
- return "ef34fea4"
-}
-func (*ACLDump) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *ACLDump) Reset() { *m = ACLDump{} }
+func (*ACLDump) GetMessageName() string { return "acl_dump" }
+func (*ACLDump) GetCrcString() string { return "ef34fea4" }
+func (*ACLDump) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLDump) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ return size
+}
+func (m *ACLDump) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLDump) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLInterfaceAddDel represents VPP binary API message 'acl_interface_add_del'.
type ACLInterfaceAddDel struct {
- IsAdd uint8
- IsInput uint8
- SwIfIndex uint32
- ACLIndex uint32
+ IsAdd uint8 `binapi:"u8,name=is_add" json:"is_add,omitempty"`
+ IsInput uint8 `binapi:"u8,name=is_input" json:"is_input,omitempty"`
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
}
-func (*ACLInterfaceAddDel) GetMessageName() string {
- return "acl_interface_add_del"
-}
-func (*ACLInterfaceAddDel) GetCrcString() string {
- return "0b2aedd1"
-}
-func (*ACLInterfaceAddDel) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *ACLInterfaceAddDel) Reset() { *m = ACLInterfaceAddDel{} }
+func (*ACLInterfaceAddDel) GetMessageName() string { return "acl_interface_add_del" }
+func (*ACLInterfaceAddDel) GetCrcString() string { return "0b2aedd1" }
+func (*ACLInterfaceAddDel) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLInterfaceAddDel) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.IsAdd
+ size += 1
+ // field[1] m.IsInput
+ size += 1
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.ACLIndex
+ size += 4
+ return size
+}
+func (m *ACLInterfaceAddDel) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.IsAdd
+ buf[pos] = uint8(m.IsAdd)
+ pos += 1
+ // field[1] m.IsInput
+ buf[pos] = uint8(m.IsInput)
+ pos += 1
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLInterfaceAddDel) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.IsAdd
+ m.IsAdd = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.IsInput
+ m.IsInput = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLInterfaceAddDelReply represents VPP binary API message 'acl_interface_add_del_reply'.
type ACLInterfaceAddDelReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
-func (*ACLInterfaceAddDelReply) GetMessageName() string {
- return "acl_interface_add_del_reply"
-}
-func (*ACLInterfaceAddDelReply) GetCrcString() string {
- return "e8d4e804"
-}
-func (*ACLInterfaceAddDelReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *ACLInterfaceAddDelReply) Reset() { *m = ACLInterfaceAddDelReply{} }
+func (*ACLInterfaceAddDelReply) GetMessageName() string { return "acl_interface_add_del_reply" }
+func (*ACLInterfaceAddDelReply) GetCrcString() string { return "e8d4e804" }
+func (*ACLInterfaceAddDelReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *ACLInterfaceAddDelReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *ACLInterfaceAddDelReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLInterfaceAddDelReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLInterfaceEtypeWhitelistDetails represents VPP binary API message 'acl_interface_etype_whitelist_details'.
type ACLInterfaceEtypeWhitelistDetails struct {
- SwIfIndex uint32
- Count uint8 `struc:"sizeof=Whitelist"`
- NInput uint8
- Whitelist []uint16
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Count uint8 `binapi:"u8,name=count" json:"count,omitempty" struc:"sizeof=Whitelist"`
+ NInput uint8 `binapi:"u8,name=n_input" json:"n_input,omitempty"`
+ Whitelist []uint16 `binapi:"u16[count],name=whitelist" json:"whitelist,omitempty"`
}
+func (m *ACLInterfaceEtypeWhitelistDetails) Reset() { *m = ACLInterfaceEtypeWhitelistDetails{} }
func (*ACLInterfaceEtypeWhitelistDetails) GetMessageName() string {
return "acl_interface_etype_whitelist_details"
}
-func (*ACLInterfaceEtypeWhitelistDetails) GetCrcString() string {
- return "6a5d4e81"
-}
-func (*ACLInterfaceEtypeWhitelistDetails) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (*ACLInterfaceEtypeWhitelistDetails) GetCrcString() string { return "6a5d4e81" }
+func (*ACLInterfaceEtypeWhitelistDetails) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *ACLInterfaceEtypeWhitelistDetails) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Count
+ size += 1
+ // field[1] m.NInput
+ size += 1
+ // field[1] m.Whitelist
+ size += 2 * len(m.Whitelist)
+ return size
+}
+func (m *ACLInterfaceEtypeWhitelistDetails) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Count
+ buf[pos] = uint8(len(m.Whitelist))
+ pos += 1
+ // field[1] m.NInput
+ buf[pos] = uint8(m.NInput)
+ pos += 1
+ // field[1] m.Whitelist
+ for i := 0; i < len(m.Whitelist); i++ {
+ var x uint16
+ if i < len(m.Whitelist) {
+ x = uint16(m.Whitelist[i])
+ }
+ o.PutUint16(buf[pos:pos+2], uint16(x))
+ pos += 2
+ }
+ return buf, nil
+}
+func (m *ACLInterfaceEtypeWhitelistDetails) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Count
+ m.Count = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.NInput
+ m.NInput = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.Whitelist
+ m.Whitelist = make([]uint16, m.Count)
+ for i := 0; i < len(m.Whitelist); i++ {
+ m.Whitelist[i] = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ }
+ return nil
}
// ACLInterfaceEtypeWhitelistDump represents VPP binary API message 'acl_interface_etype_whitelist_dump'.
type ACLInterfaceEtypeWhitelistDump struct {
- SwIfIndex uint32
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
}
+func (m *ACLInterfaceEtypeWhitelistDump) Reset() { *m = ACLInterfaceEtypeWhitelistDump{} }
func (*ACLInterfaceEtypeWhitelistDump) GetMessageName() string {
return "acl_interface_etype_whitelist_dump"
}
-func (*ACLInterfaceEtypeWhitelistDump) GetCrcString() string {
- return "529cb13f"
-}
-func (*ACLInterfaceEtypeWhitelistDump) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (*ACLInterfaceEtypeWhitelistDump) GetCrcString() string { return "529cb13f" }
+func (*ACLInterfaceEtypeWhitelistDump) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLInterfaceEtypeWhitelistDump) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *ACLInterfaceEtypeWhitelistDump) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLInterfaceEtypeWhitelistDump) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLInterfaceListDetails represents VPP binary API message 'acl_interface_list_details'.
type ACLInterfaceListDetails struct {
- SwIfIndex uint32
- Count uint8 `struc:"sizeof=Acls"`
- NInput uint8
- Acls []uint32
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Count uint8 `binapi:"u8,name=count" json:"count,omitempty" struc:"sizeof=Acls"`
+ NInput uint8 `binapi:"u8,name=n_input" json:"n_input,omitempty"`
+ Acls []uint32 `binapi:"u32[count],name=acls" json:"acls,omitempty"`
}
-func (*ACLInterfaceListDetails) GetMessageName() string {
- return "acl_interface_list_details"
-}
-func (*ACLInterfaceListDetails) GetCrcString() string {
- return "d5e80809"
-}
-func (*ACLInterfaceListDetails) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *ACLInterfaceListDetails) Reset() { *m = ACLInterfaceListDetails{} }
+func (*ACLInterfaceListDetails) GetMessageName() string { return "acl_interface_list_details" }
+func (*ACLInterfaceListDetails) GetCrcString() string { return "d5e80809" }
+func (*ACLInterfaceListDetails) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *ACLInterfaceListDetails) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Count
+ size += 1
+ // field[1] m.NInput
+ size += 1
+ // field[1] m.Acls
+ size += 4 * len(m.Acls)
+ return size
+}
+func (m *ACLInterfaceListDetails) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Count
+ buf[pos] = uint8(len(m.Acls))
+ pos += 1
+ // field[1] m.NInput
+ buf[pos] = uint8(m.NInput)
+ pos += 1
+ // field[1] m.Acls
+ for i := 0; i < len(m.Acls); i++ {
+ var x uint32
+ if i < len(m.Acls) {
+ x = uint32(m.Acls[i])
+ }
+ o.PutUint32(buf[pos:pos+4], uint32(x))
+ pos += 4
+ }
+ return buf, nil
+}
+func (m *ACLInterfaceListDetails) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Count
+ m.Count = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.NInput
+ m.NInput = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.Acls
+ m.Acls = make([]uint32, m.Count)
+ for i := 0; i < len(m.Acls); i++ {
+ m.Acls[i] = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ }
+ return nil
}
// ACLInterfaceListDump represents VPP binary API message 'acl_interface_list_dump'.
type ACLInterfaceListDump struct {
- SwIfIndex uint32
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
}
-func (*ACLInterfaceListDump) GetMessageName() string {
- return "acl_interface_list_dump"
-}
-func (*ACLInterfaceListDump) GetCrcString() string {
- return "529cb13f"
-}
-func (*ACLInterfaceListDump) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *ACLInterfaceListDump) Reset() { *m = ACLInterfaceListDump{} }
+func (*ACLInterfaceListDump) GetMessageName() string { return "acl_interface_list_dump" }
+func (*ACLInterfaceListDump) GetCrcString() string { return "529cb13f" }
+func (*ACLInterfaceListDump) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLInterfaceListDump) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *ACLInterfaceListDump) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLInterfaceListDump) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLInterfaceSetACLList represents VPP binary API message 'acl_interface_set_acl_list'.
type ACLInterfaceSetACLList struct {
- SwIfIndex uint32
- Count uint8 `struc:"sizeof=Acls"`
- NInput uint8
- Acls []uint32
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Count uint8 `binapi:"u8,name=count" json:"count,omitempty" struc:"sizeof=Acls"`
+ NInput uint8 `binapi:"u8,name=n_input" json:"n_input,omitempty"`
+ Acls []uint32 `binapi:"u32[count],name=acls" json:"acls,omitempty"`
}
-func (*ACLInterfaceSetACLList) GetMessageName() string {
- return "acl_interface_set_acl_list"
-}
-func (*ACLInterfaceSetACLList) GetCrcString() string {
- return "8baece38"
-}
-func (*ACLInterfaceSetACLList) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *ACLInterfaceSetACLList) Reset() { *m = ACLInterfaceSetACLList{} }
+func (*ACLInterfaceSetACLList) GetMessageName() string { return "acl_interface_set_acl_list" }
+func (*ACLInterfaceSetACLList) GetCrcString() string { return "8baece38" }
+func (*ACLInterfaceSetACLList) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLInterfaceSetACLList) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Count
+ size += 1
+ // field[1] m.NInput
+ size += 1
+ // field[1] m.Acls
+ size += 4 * len(m.Acls)
+ return size
+}
+func (m *ACLInterfaceSetACLList) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Count
+ buf[pos] = uint8(len(m.Acls))
+ pos += 1
+ // field[1] m.NInput
+ buf[pos] = uint8(m.NInput)
+ pos += 1
+ // field[1] m.Acls
+ for i := 0; i < len(m.Acls); i++ {
+ var x uint32
+ if i < len(m.Acls) {
+ x = uint32(m.Acls[i])
+ }
+ o.PutUint32(buf[pos:pos+4], uint32(x))
+ pos += 4
+ }
+ return buf, nil
+}
+func (m *ACLInterfaceSetACLList) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Count
+ m.Count = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.NInput
+ m.NInput = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.Acls
+ m.Acls = make([]uint32, m.Count)
+ for i := 0; i < len(m.Acls); i++ {
+ m.Acls[i] = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ }
+ return nil
}
// ACLInterfaceSetACLListReply represents VPP binary API message 'acl_interface_set_acl_list_reply'.
type ACLInterfaceSetACLListReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
+func (m *ACLInterfaceSetACLListReply) Reset() { *m = ACLInterfaceSetACLListReply{} }
func (*ACLInterfaceSetACLListReply) GetMessageName() string {
return "acl_interface_set_acl_list_reply"
}
-func (*ACLInterfaceSetACLListReply) GetCrcString() string {
- return "e8d4e804"
-}
-func (*ACLInterfaceSetACLListReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (*ACLInterfaceSetACLListReply) GetCrcString() string { return "e8d4e804" }
+func (*ACLInterfaceSetACLListReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *ACLInterfaceSetACLListReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *ACLInterfaceSetACLListReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLInterfaceSetACLListReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLInterfaceSetEtypeWhitelist represents VPP binary API message 'acl_interface_set_etype_whitelist'.
type ACLInterfaceSetEtypeWhitelist struct {
- SwIfIndex uint32
- Count uint8 `struc:"sizeof=Whitelist"`
- NInput uint8
- Whitelist []uint16
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Count uint8 `binapi:"u8,name=count" json:"count,omitempty" struc:"sizeof=Whitelist"`
+ NInput uint8 `binapi:"u8,name=n_input" json:"n_input,omitempty"`
+ Whitelist []uint16 `binapi:"u16[count],name=whitelist" json:"whitelist,omitempty"`
}
+func (m *ACLInterfaceSetEtypeWhitelist) Reset() { *m = ACLInterfaceSetEtypeWhitelist{} }
func (*ACLInterfaceSetEtypeWhitelist) GetMessageName() string {
return "acl_interface_set_etype_whitelist"
}
-func (*ACLInterfaceSetEtypeWhitelist) GetCrcString() string {
- return "f515efc5"
-}
-func (*ACLInterfaceSetEtypeWhitelist) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (*ACLInterfaceSetEtypeWhitelist) GetCrcString() string { return "f515efc5" }
+func (*ACLInterfaceSetEtypeWhitelist) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLInterfaceSetEtypeWhitelist) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Count
+ size += 1
+ // field[1] m.NInput
+ size += 1
+ // field[1] m.Whitelist
+ size += 2 * len(m.Whitelist)
+ return size
+}
+func (m *ACLInterfaceSetEtypeWhitelist) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Count
+ buf[pos] = uint8(len(m.Whitelist))
+ pos += 1
+ // field[1] m.NInput
+ buf[pos] = uint8(m.NInput)
+ pos += 1
+ // field[1] m.Whitelist
+ for i := 0; i < len(m.Whitelist); i++ {
+ var x uint16
+ if i < len(m.Whitelist) {
+ x = uint16(m.Whitelist[i])
+ }
+ o.PutUint16(buf[pos:pos+2], uint16(x))
+ pos += 2
+ }
+ return buf, nil
+}
+func (m *ACLInterfaceSetEtypeWhitelist) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Count
+ m.Count = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.NInput
+ m.NInput = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.Whitelist
+ m.Whitelist = make([]uint16, m.Count)
+ for i := 0; i < len(m.Whitelist); i++ {
+ m.Whitelist[i] = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ }
+ return nil
}
// ACLInterfaceSetEtypeWhitelistReply represents VPP binary API message 'acl_interface_set_etype_whitelist_reply'.
type ACLInterfaceSetEtypeWhitelistReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
+func (m *ACLInterfaceSetEtypeWhitelistReply) Reset() { *m = ACLInterfaceSetEtypeWhitelistReply{} }
func (*ACLInterfaceSetEtypeWhitelistReply) GetMessageName() string {
return "acl_interface_set_etype_whitelist_reply"
}
-func (*ACLInterfaceSetEtypeWhitelistReply) GetCrcString() string {
- return "e8d4e804"
-}
-func (*ACLInterfaceSetEtypeWhitelistReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (*ACLInterfaceSetEtypeWhitelistReply) GetCrcString() string { return "e8d4e804" }
+func (*ACLInterfaceSetEtypeWhitelistReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *ACLInterfaceSetEtypeWhitelistReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *ACLInterfaceSetEtypeWhitelistReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLInterfaceSetEtypeWhitelistReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLPluginControlPing represents VPP binary API message 'acl_plugin_control_ping'.
type ACLPluginControlPing struct{}
-func (*ACLPluginControlPing) GetMessageName() string {
- return "acl_plugin_control_ping"
-}
-func (*ACLPluginControlPing) GetCrcString() string {
- return "51077d14"
+func (m *ACLPluginControlPing) Reset() { *m = ACLPluginControlPing{} }
+func (*ACLPluginControlPing) GetMessageName() string { return "acl_plugin_control_ping" }
+func (*ACLPluginControlPing) GetCrcString() string { return "51077d14" }
+func (*ACLPluginControlPing) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLPluginControlPing) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ return size
+}
+func (m *ACLPluginControlPing) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ return buf, nil
}
-func (*ACLPluginControlPing) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *ACLPluginControlPing) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ return nil
}
// ACLPluginControlPingReply represents VPP binary API message 'acl_plugin_control_ping_reply'.
type ACLPluginControlPingReply struct {
- Retval int32
- ClientIndex uint32
- VpePID uint32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
+ ClientIndex uint32 `binapi:"u32,name=client_index" json:"client_index,omitempty"`
+ VpePID uint32 `binapi:"u32,name=vpe_pid" json:"vpe_pid,omitempty"`
}
-func (*ACLPluginControlPingReply) GetMessageName() string {
- return "acl_plugin_control_ping_reply"
-}
-func (*ACLPluginControlPingReply) GetCrcString() string {
- return "f6b0b8ca"
-}
-func (*ACLPluginControlPingReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *ACLPluginControlPingReply) Reset() { *m = ACLPluginControlPingReply{} }
+func (*ACLPluginControlPingReply) GetMessageName() string { return "acl_plugin_control_ping_reply" }
+func (*ACLPluginControlPingReply) GetCrcString() string { return "f6b0b8ca" }
+func (*ACLPluginControlPingReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *ACLPluginControlPingReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ // field[1] m.ClientIndex
+ size += 4
+ // field[1] m.VpePID
+ size += 4
+ return size
+}
+func (m *ACLPluginControlPingReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ // field[1] m.ClientIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ClientIndex))
+ pos += 4
+ // field[1] m.VpePID
+ o.PutUint32(buf[pos:pos+4], uint32(m.VpePID))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLPluginControlPingReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.ClientIndex
+ m.ClientIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.VpePID
+ m.VpePID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// ACLPluginGetConnTableMaxEntries represents VPP binary API message 'acl_plugin_get_conn_table_max_entries'.
type ACLPluginGetConnTableMaxEntries struct{}
+func (m *ACLPluginGetConnTableMaxEntries) Reset() { *m = ACLPluginGetConnTableMaxEntries{} }
func (*ACLPluginGetConnTableMaxEntries) GetMessageName() string {
return "acl_plugin_get_conn_table_max_entries"
}
-func (*ACLPluginGetConnTableMaxEntries) GetCrcString() string {
- return "51077d14"
+func (*ACLPluginGetConnTableMaxEntries) GetCrcString() string { return "51077d14" }
+func (*ACLPluginGetConnTableMaxEntries) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLPluginGetConnTableMaxEntries) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ return size
+}
+func (m *ACLPluginGetConnTableMaxEntries) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ return buf, nil
}
-func (*ACLPluginGetConnTableMaxEntries) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *ACLPluginGetConnTableMaxEntries) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ return nil
}
// ACLPluginGetConnTableMaxEntriesReply represents VPP binary API message 'acl_plugin_get_conn_table_max_entries_reply'.
type ACLPluginGetConnTableMaxEntriesReply struct {
- ConnTableMaxEntries uint64
+ ConnTableMaxEntries uint64 `binapi:"u64,name=conn_table_max_entries" json:"conn_table_max_entries,omitempty"`
}
+func (m *ACLPluginGetConnTableMaxEntriesReply) Reset() { *m = ACLPluginGetConnTableMaxEntriesReply{} }
func (*ACLPluginGetConnTableMaxEntriesReply) GetMessageName() string {
return "acl_plugin_get_conn_table_max_entries_reply"
}
-func (*ACLPluginGetConnTableMaxEntriesReply) GetCrcString() string {
- return "7a096d3d"
-}
+func (*ACLPluginGetConnTableMaxEntriesReply) GetCrcString() string { return "7a096d3d" }
func (*ACLPluginGetConnTableMaxEntriesReply) GetMessageType() api.MessageType {
return api.ReplyMessage
}
+func (m *ACLPluginGetConnTableMaxEntriesReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ConnTableMaxEntries
+ size += 8
+ return size
+}
+func (m *ACLPluginGetConnTableMaxEntriesReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ConnTableMaxEntries
+ o.PutUint64(buf[pos:pos+8], uint64(m.ConnTableMaxEntries))
+ pos += 8
+ return buf, nil
+}
+func (m *ACLPluginGetConnTableMaxEntriesReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ConnTableMaxEntries
+ m.ConnTableMaxEntries = uint64(o.Uint64(tmp[pos : pos+8]))
+ pos += 8
+ return nil
+}
+
// ACLPluginGetVersion represents VPP binary API message 'acl_plugin_get_version'.
type ACLPluginGetVersion struct{}
-func (*ACLPluginGetVersion) GetMessageName() string {
- return "acl_plugin_get_version"
-}
-func (*ACLPluginGetVersion) GetCrcString() string {
- return "51077d14"
+func (m *ACLPluginGetVersion) Reset() { *m = ACLPluginGetVersion{} }
+func (*ACLPluginGetVersion) GetMessageName() string { return "acl_plugin_get_version" }
+func (*ACLPluginGetVersion) GetCrcString() string { return "51077d14" }
+func (*ACLPluginGetVersion) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLPluginGetVersion) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ return size
+}
+func (m *ACLPluginGetVersion) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ return buf, nil
}
-func (*ACLPluginGetVersion) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *ACLPluginGetVersion) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ return nil
}
// ACLPluginGetVersionReply represents VPP binary API message 'acl_plugin_get_version_reply'.
type ACLPluginGetVersionReply struct {
- Major uint32
- Minor uint32
+ Major uint32 `binapi:"u32,name=major" json:"major,omitempty"`
+ Minor uint32 `binapi:"u32,name=minor" json:"minor,omitempty"`
}
-func (*ACLPluginGetVersionReply) GetMessageName() string {
- return "acl_plugin_get_version_reply"
+func (m *ACLPluginGetVersionReply) Reset() { *m = ACLPluginGetVersionReply{} }
+func (*ACLPluginGetVersionReply) GetMessageName() string { return "acl_plugin_get_version_reply" }
+func (*ACLPluginGetVersionReply) GetCrcString() string { return "9b32cf86" }
+func (*ACLPluginGetVersionReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *ACLPluginGetVersionReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Major
+ size += 4
+ // field[1] m.Minor
+ size += 4
+ return size
+}
+func (m *ACLPluginGetVersionReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Major
+ o.PutUint32(buf[pos:pos+4], uint32(m.Major))
+ pos += 4
+ // field[1] m.Minor
+ o.PutUint32(buf[pos:pos+4], uint32(m.Minor))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLPluginGetVersionReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Major
+ m.Major = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Minor
+ m.Minor = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
+// ACLStatsIntfCountersEnable represents VPP binary API message 'acl_stats_intf_counters_enable'.
+type ACLStatsIntfCountersEnable struct {
+ Enable bool `binapi:"bool,name=enable" json:"enable,omitempty"`
+}
+
+func (m *ACLStatsIntfCountersEnable) Reset() { *m = ACLStatsIntfCountersEnable{} }
+func (*ACLStatsIntfCountersEnable) GetMessageName() string { return "acl_stats_intf_counters_enable" }
+func (*ACLStatsIntfCountersEnable) GetCrcString() string { return "b3e225d2" }
+func (*ACLStatsIntfCountersEnable) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *ACLStatsIntfCountersEnable) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Enable
+ size += 1
+ return size
+}
+func (m *ACLStatsIntfCountersEnable) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Enable
+ if m.Enable {
+ buf[pos] = 1
+ }
+ pos += 1
+ return buf, nil
}
-func (*ACLPluginGetVersionReply) GetCrcString() string {
- return "9b32cf86"
+func (m *ACLStatsIntfCountersEnable) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Enable
+ m.Enable = tmp[pos] != 0
+ pos += 1
+ return nil
}
-func (*ACLPluginGetVersionReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+
+// ACLStatsIntfCountersEnableReply represents VPP binary API message 'acl_stats_intf_counters_enable_reply'.
+type ACLStatsIntfCountersEnableReply struct {
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
-// MacipACLAdd represents VPP binary API message 'macip_acl_add'.
-type MacipACLAdd struct {
- Tag []byte `struc:"[64]byte"`
- Count uint32 `struc:"sizeof=R"`
- R []MacipACLRule
+func (m *ACLStatsIntfCountersEnableReply) Reset() { *m = ACLStatsIntfCountersEnableReply{} }
+func (*ACLStatsIntfCountersEnableReply) GetMessageName() string {
+ return "acl_stats_intf_counters_enable_reply"
}
+func (*ACLStatsIntfCountersEnableReply) GetCrcString() string { return "e8d4e804" }
+func (*ACLStatsIntfCountersEnableReply) GetMessageType() api.MessageType { return api.ReplyMessage }
-func (*MacipACLAdd) GetMessageName() string {
- return "macip_acl_add"
+func (m *ACLStatsIntfCountersEnableReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *ACLStatsIntfCountersEnableReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *ACLStatsIntfCountersEnableReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
-func (*MacipACLAdd) GetCrcString() string {
- return "b3d3d65a"
+
+// MacipACLAdd represents VPP binary API message 'macip_acl_add'.
+type MacipACLAdd struct {
+ Tag []byte `binapi:"u8[64],name=tag" json:"tag,omitempty" struc:"[64]byte"`
+ Count uint32 `binapi:"u32,name=count" json:"count,omitempty" struc:"sizeof=R"`
+ R []MacipACLRule `binapi:"macip_acl_rule[count],name=r" json:"r,omitempty"`
}
-func (*MacipACLAdd) GetMessageType() api.MessageType {
- return api.RequestMessage
+
+func (m *MacipACLAdd) Reset() { *m = MacipACLAdd{} }
+func (*MacipACLAdd) GetMessageName() string { return "macip_acl_add" }
+func (*MacipACLAdd) GetCrcString() string { return "0c680ca5" }
+func (*MacipACLAdd) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *MacipACLAdd) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Tag
+ size += 64
+ // field[1] m.Count
+ size += 4
+ // field[1] m.R
+ for j1 := 0; j1 < len(m.R); j1++ {
+ var s1 MacipACLRule
+ _ = s1
+ if j1 < len(m.R) {
+ s1 = m.R[j1]
+ }
+ // field[2] s1.IsPermit
+ size += 1
+ // field[2] s1.IsIPv6
+ size += 1
+ // field[2] s1.SrcMac
+ size += 6
+ // field[2] s1.SrcMacMask
+ size += 6
+ // field[2] s1.SrcIPAddr
+ size += 16
+ // field[2] s1.SrcIPPrefixLen
+ size += 1
+ }
+ return size
+}
+func (m *MacipACLAdd) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Tag
+ for i := 0; i < 64; i++ {
+ var x uint8
+ if i < len(m.Tag) {
+ x = uint8(m.Tag[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.Count
+ o.PutUint32(buf[pos:pos+4], uint32(len(m.R)))
+ pos += 4
+ // field[1] m.R
+ for j1 := 0; j1 < len(m.R); j1++ {
+ var v1 MacipACLRule
+ if j1 < len(m.R) {
+ v1 = m.R[j1]
+ }
+ // field[2] v1.IsPermit
+ buf[pos] = uint8(v1.IsPermit)
+ pos += 1
+ // field[2] v1.IsIPv6
+ buf[pos] = uint8(v1.IsIPv6)
+ pos += 1
+ // field[2] v1.SrcMac
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(v1.SrcMac) {
+ x = uint8(v1.SrcMac[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcMacMask
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(v1.SrcMacMask) {
+ x = uint8(v1.SrcMacMask[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcIPAddr
+ for i := 0; i < 16; i++ {
+ var x uint8
+ if i < len(v1.SrcIPAddr) {
+ x = uint8(v1.SrcIPAddr[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcIPPrefixLen
+ buf[pos] = uint8(v1.SrcIPPrefixLen)
+ pos += 1
+ }
+ return buf, nil
+}
+func (m *MacipACLAdd) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Tag
+ m.Tag = make([]uint8, 64)
+ for i := 0; i < len(m.Tag); i++ {
+ m.Tag[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.Count
+ m.Count = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.R
+ m.R = make([]MacipACLRule, int(m.Count))
+ for j1 := 0; j1 < int(m.Count); j1++ {
+ // field[2] m.R[j1].IsPermit
+ m.R[j1].IsPermit = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].IsIPv6
+ m.R[j1].IsIPv6 = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].SrcMac
+ m.R[j1].SrcMac = make([]uint8, 6)
+ for i := 0; i < len(m.R[j1].SrcMac); i++ {
+ m.R[j1].SrcMac[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcMacMask
+ m.R[j1].SrcMacMask = make([]uint8, 6)
+ for i := 0; i < len(m.R[j1].SrcMacMask); i++ {
+ m.R[j1].SrcMacMask[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcIPAddr
+ m.R[j1].SrcIPAddr = make([]uint8, 16)
+ for i := 0; i < len(m.R[j1].SrcIPAddr); i++ {
+ m.R[j1].SrcIPAddr[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcIPPrefixLen
+ m.R[j1].SrcIPPrefixLen = uint8(tmp[pos])
+ pos += 1
+ }
+ return nil
}
// MacipACLAddReplace represents VPP binary API message 'macip_acl_add_replace'.
type MacipACLAddReplace struct {
- ACLIndex uint32
- Tag []byte `struc:"[64]byte"`
- Count uint32 `struc:"sizeof=R"`
- R []MacipACLRule
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
+ Tag []byte `binapi:"u8[64],name=tag" json:"tag,omitempty" struc:"[64]byte"`
+ Count uint32 `binapi:"u32,name=count" json:"count,omitempty" struc:"sizeof=R"`
+ R []MacipACLRule `binapi:"macip_acl_rule[count],name=r" json:"r,omitempty"`
}
-func (*MacipACLAddReplace) GetMessageName() string {
- return "macip_acl_add_replace"
-}
-func (*MacipACLAddReplace) GetCrcString() string {
- return "a0e8c01b"
-}
-func (*MacipACLAddReplace) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *MacipACLAddReplace) Reset() { *m = MacipACLAddReplace{} }
+func (*MacipACLAddReplace) GetMessageName() string { return "macip_acl_add_replace" }
+func (*MacipACLAddReplace) GetCrcString() string { return "d3d313e7" }
+func (*MacipACLAddReplace) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *MacipACLAddReplace) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ // field[1] m.Tag
+ size += 64
+ // field[1] m.Count
+ size += 4
+ // field[1] m.R
+ for j1 := 0; j1 < len(m.R); j1++ {
+ var s1 MacipACLRule
+ _ = s1
+ if j1 < len(m.R) {
+ s1 = m.R[j1]
+ }
+ // field[2] s1.IsPermit
+ size += 1
+ // field[2] s1.IsIPv6
+ size += 1
+ // field[2] s1.SrcMac
+ size += 6
+ // field[2] s1.SrcMacMask
+ size += 6
+ // field[2] s1.SrcIPAddr
+ size += 16
+ // field[2] s1.SrcIPPrefixLen
+ size += 1
+ }
+ return size
+}
+func (m *MacipACLAddReplace) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ // field[1] m.Tag
+ for i := 0; i < 64; i++ {
+ var x uint8
+ if i < len(m.Tag) {
+ x = uint8(m.Tag[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.Count
+ o.PutUint32(buf[pos:pos+4], uint32(len(m.R)))
+ pos += 4
+ // field[1] m.R
+ for j1 := 0; j1 < len(m.R); j1++ {
+ var v1 MacipACLRule
+ if j1 < len(m.R) {
+ v1 = m.R[j1]
+ }
+ // field[2] v1.IsPermit
+ buf[pos] = uint8(v1.IsPermit)
+ pos += 1
+ // field[2] v1.IsIPv6
+ buf[pos] = uint8(v1.IsIPv6)
+ pos += 1
+ // field[2] v1.SrcMac
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(v1.SrcMac) {
+ x = uint8(v1.SrcMac[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcMacMask
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(v1.SrcMacMask) {
+ x = uint8(v1.SrcMacMask[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcIPAddr
+ for i := 0; i < 16; i++ {
+ var x uint8
+ if i < len(v1.SrcIPAddr) {
+ x = uint8(v1.SrcIPAddr[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcIPPrefixLen
+ buf[pos] = uint8(v1.SrcIPPrefixLen)
+ pos += 1
+ }
+ return buf, nil
+}
+func (m *MacipACLAddReplace) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Tag
+ m.Tag = make([]uint8, 64)
+ for i := 0; i < len(m.Tag); i++ {
+ m.Tag[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.Count
+ m.Count = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.R
+ m.R = make([]MacipACLRule, int(m.Count))
+ for j1 := 0; j1 < int(m.Count); j1++ {
+ // field[2] m.R[j1].IsPermit
+ m.R[j1].IsPermit = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].IsIPv6
+ m.R[j1].IsIPv6 = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].SrcMac
+ m.R[j1].SrcMac = make([]uint8, 6)
+ for i := 0; i < len(m.R[j1].SrcMac); i++ {
+ m.R[j1].SrcMac[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcMacMask
+ m.R[j1].SrcMacMask = make([]uint8, 6)
+ for i := 0; i < len(m.R[j1].SrcMacMask); i++ {
+ m.R[j1].SrcMacMask[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcIPAddr
+ m.R[j1].SrcIPAddr = make([]uint8, 16)
+ for i := 0; i < len(m.R[j1].SrcIPAddr); i++ {
+ m.R[j1].SrcIPAddr[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcIPPrefixLen
+ m.R[j1].SrcIPPrefixLen = uint8(tmp[pos])
+ pos += 1
+ }
+ return nil
}
// MacipACLAddReplaceReply represents VPP binary API message 'macip_acl_add_replace_reply'.
type MacipACLAddReplaceReply struct {
- ACLIndex uint32
- Retval int32
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
-func (*MacipACLAddReplaceReply) GetMessageName() string {
- return "macip_acl_add_replace_reply"
-}
-func (*MacipACLAddReplaceReply) GetCrcString() string {
- return "ac407b0c"
-}
-func (*MacipACLAddReplaceReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *MacipACLAddReplaceReply) Reset() { *m = MacipACLAddReplaceReply{} }
+func (*MacipACLAddReplaceReply) GetMessageName() string { return "macip_acl_add_replace_reply" }
+func (*MacipACLAddReplaceReply) GetCrcString() string { return "ac407b0c" }
+func (*MacipACLAddReplaceReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *MacipACLAddReplaceReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *MacipACLAddReplaceReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *MacipACLAddReplaceReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// MacipACLAddReply represents VPP binary API message 'macip_acl_add_reply'.
type MacipACLAddReply struct {
- ACLIndex uint32
- Retval int32
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
-func (*MacipACLAddReply) GetMessageName() string {
- return "macip_acl_add_reply"
-}
-func (*MacipACLAddReply) GetCrcString() string {
- return "ac407b0c"
-}
-func (*MacipACLAddReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *MacipACLAddReply) Reset() { *m = MacipACLAddReply{} }
+func (*MacipACLAddReply) GetMessageName() string { return "macip_acl_add_reply" }
+func (*MacipACLAddReply) GetCrcString() string { return "ac407b0c" }
+func (*MacipACLAddReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *MacipACLAddReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *MacipACLAddReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *MacipACLAddReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// MacipACLDel represents VPP binary API message 'macip_acl_del'.
type MacipACLDel struct {
- ACLIndex uint32
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
}
-func (*MacipACLDel) GetMessageName() string {
- return "macip_acl_del"
-}
-func (*MacipACLDel) GetCrcString() string {
- return "ef34fea4"
-}
-func (*MacipACLDel) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *MacipACLDel) Reset() { *m = MacipACLDel{} }
+func (*MacipACLDel) GetMessageName() string { return "macip_acl_del" }
+func (*MacipACLDel) GetCrcString() string { return "ef34fea4" }
+func (*MacipACLDel) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *MacipACLDel) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ return size
+}
+func (m *MacipACLDel) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *MacipACLDel) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// MacipACLDelReply represents VPP binary API message 'macip_acl_del_reply'.
type MacipACLDelReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
-func (*MacipACLDelReply) GetMessageName() string {
- return "macip_acl_del_reply"
-}
-func (*MacipACLDelReply) GetCrcString() string {
- return "e8d4e804"
-}
-func (*MacipACLDelReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *MacipACLDelReply) Reset() { *m = MacipACLDelReply{} }
+func (*MacipACLDelReply) GetMessageName() string { return "macip_acl_del_reply" }
+func (*MacipACLDelReply) GetCrcString() string { return "e8d4e804" }
+func (*MacipACLDelReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *MacipACLDelReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *MacipACLDelReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *MacipACLDelReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// MacipACLDetails represents VPP binary API message 'macip_acl_details'.
type MacipACLDetails struct {
- ACLIndex uint32
- Tag []byte `struc:"[64]byte"`
- Count uint32 `struc:"sizeof=R"`
- R []MacipACLRule
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
+ Tag []byte `binapi:"u8[64],name=tag" json:"tag,omitempty" struc:"[64]byte"`
+ Count uint32 `binapi:"u32,name=count" json:"count,omitempty" struc:"sizeof=R"`
+ R []MacipACLRule `binapi:"macip_acl_rule[count],name=r" json:"r,omitempty"`
}
-func (*MacipACLDetails) GetMessageName() string {
- return "macip_acl_details"
-}
-func (*MacipACLDetails) GetCrcString() string {
- return "dd2b55ba"
-}
-func (*MacipACLDetails) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *MacipACLDetails) Reset() { *m = MacipACLDetails{} }
+func (*MacipACLDetails) GetMessageName() string { return "macip_acl_details" }
+func (*MacipACLDetails) GetCrcString() string { return "e164e69a" }
+func (*MacipACLDetails) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *MacipACLDetails) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ // field[1] m.Tag
+ size += 64
+ // field[1] m.Count
+ size += 4
+ // field[1] m.R
+ for j1 := 0; j1 < len(m.R); j1++ {
+ var s1 MacipACLRule
+ _ = s1
+ if j1 < len(m.R) {
+ s1 = m.R[j1]
+ }
+ // field[2] s1.IsPermit
+ size += 1
+ // field[2] s1.IsIPv6
+ size += 1
+ // field[2] s1.SrcMac
+ size += 6
+ // field[2] s1.SrcMacMask
+ size += 6
+ // field[2] s1.SrcIPAddr
+ size += 16
+ // field[2] s1.SrcIPPrefixLen
+ size += 1
+ }
+ return size
+}
+func (m *MacipACLDetails) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ // field[1] m.Tag
+ for i := 0; i < 64; i++ {
+ var x uint8
+ if i < len(m.Tag) {
+ x = uint8(m.Tag[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.Count
+ o.PutUint32(buf[pos:pos+4], uint32(len(m.R)))
+ pos += 4
+ // field[1] m.R
+ for j1 := 0; j1 < len(m.R); j1++ {
+ var v1 MacipACLRule
+ if j1 < len(m.R) {
+ v1 = m.R[j1]
+ }
+ // field[2] v1.IsPermit
+ buf[pos] = uint8(v1.IsPermit)
+ pos += 1
+ // field[2] v1.IsIPv6
+ buf[pos] = uint8(v1.IsIPv6)
+ pos += 1
+ // field[2] v1.SrcMac
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(v1.SrcMac) {
+ x = uint8(v1.SrcMac[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcMacMask
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(v1.SrcMacMask) {
+ x = uint8(v1.SrcMacMask[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcIPAddr
+ for i := 0; i < 16; i++ {
+ var x uint8
+ if i < len(v1.SrcIPAddr) {
+ x = uint8(v1.SrcIPAddr[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[2] v1.SrcIPPrefixLen
+ buf[pos] = uint8(v1.SrcIPPrefixLen)
+ pos += 1
+ }
+ return buf, nil
+}
+func (m *MacipACLDetails) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Tag
+ m.Tag = make([]uint8, 64)
+ for i := 0; i < len(m.Tag); i++ {
+ m.Tag[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.Count
+ m.Count = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.R
+ m.R = make([]MacipACLRule, int(m.Count))
+ for j1 := 0; j1 < int(m.Count); j1++ {
+ // field[2] m.R[j1].IsPermit
+ m.R[j1].IsPermit = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].IsIPv6
+ m.R[j1].IsIPv6 = uint8(tmp[pos])
+ pos += 1
+ // field[2] m.R[j1].SrcMac
+ m.R[j1].SrcMac = make([]uint8, 6)
+ for i := 0; i < len(m.R[j1].SrcMac); i++ {
+ m.R[j1].SrcMac[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcMacMask
+ m.R[j1].SrcMacMask = make([]uint8, 6)
+ for i := 0; i < len(m.R[j1].SrcMacMask); i++ {
+ m.R[j1].SrcMacMask[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcIPAddr
+ m.R[j1].SrcIPAddr = make([]uint8, 16)
+ for i := 0; i < len(m.R[j1].SrcIPAddr); i++ {
+ m.R[j1].SrcIPAddr[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[2] m.R[j1].SrcIPPrefixLen
+ m.R[j1].SrcIPPrefixLen = uint8(tmp[pos])
+ pos += 1
+ }
+ return nil
}
// MacipACLDump represents VPP binary API message 'macip_acl_dump'.
type MacipACLDump struct {
- ACLIndex uint32
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
}
-func (*MacipACLDump) GetMessageName() string {
- return "macip_acl_dump"
-}
-func (*MacipACLDump) GetCrcString() string {
- return "ef34fea4"
-}
-func (*MacipACLDump) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *MacipACLDump) Reset() { *m = MacipACLDump{} }
+func (*MacipACLDump) GetMessageName() string { return "macip_acl_dump" }
+func (*MacipACLDump) GetCrcString() string { return "ef34fea4" }
+func (*MacipACLDump) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *MacipACLDump) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.ACLIndex
+ size += 4
+ return size
+}
+func (m *MacipACLDump) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *MacipACLDump) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// MacipACLInterfaceAddDel represents VPP binary API message 'macip_acl_interface_add_del'.
type MacipACLInterfaceAddDel struct {
- IsAdd uint8
- SwIfIndex uint32
- ACLIndex uint32
+ IsAdd uint8 `binapi:"u8,name=is_add" json:"is_add,omitempty"`
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
+ ACLIndex uint32 `binapi:"u32,name=acl_index" json:"acl_index,omitempty"`
}
-func (*MacipACLInterfaceAddDel) GetMessageName() string {
- return "macip_acl_interface_add_del"
-}
-func (*MacipACLInterfaceAddDel) GetCrcString() string {
- return "6a6be97c"
-}
-func (*MacipACLInterfaceAddDel) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *MacipACLInterfaceAddDel) Reset() { *m = MacipACLInterfaceAddDel{} }
+func (*MacipACLInterfaceAddDel) GetMessageName() string { return "macip_acl_interface_add_del" }
+func (*MacipACLInterfaceAddDel) GetCrcString() string { return "6a6be97c" }
+func (*MacipACLInterfaceAddDel) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *MacipACLInterfaceAddDel) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.IsAdd
+ size += 1
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.ACLIndex
+ size += 4
+ return size
+}
+func (m *MacipACLInterfaceAddDel) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.IsAdd
+ buf[pos] = uint8(m.IsAdd)
+ pos += 1
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.ACLIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.ACLIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *MacipACLInterfaceAddDel) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.IsAdd
+ m.IsAdd = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.ACLIndex
+ m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// MacipACLInterfaceAddDelReply represents VPP binary API message 'macip_acl_interface_add_del_reply'.
type MacipACLInterfaceAddDelReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
+func (m *MacipACLInterfaceAddDelReply) Reset() { *m = MacipACLInterfaceAddDelReply{} }
func (*MacipACLInterfaceAddDelReply) GetMessageName() string {
return "macip_acl_interface_add_del_reply"
}
-func (*MacipACLInterfaceAddDelReply) GetCrcString() string {
- return "e8d4e804"
-}
-func (*MacipACLInterfaceAddDelReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (*MacipACLInterfaceAddDelReply) GetCrcString() string { return "e8d4e804" }
+func (*MacipACLInterfaceAddDelReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *MacipACLInterfaceAddDelReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *MacipACLInterfaceAddDelReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *MacipACLInterfaceAddDelReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
}
// MacipACLInterfaceGet represents VPP binary API message 'macip_acl_interface_get'.
type MacipACLInterfaceGet struct{}
-func (*MacipACLInterfaceGet) GetMessageName() string {
- return "macip_acl_interface_get"
-}
-func (*MacipACLInterfaceGet) GetCrcString() string {
- return "51077d14"
+func (m *MacipACLInterfaceGet) Reset() { *m = MacipACLInterfaceGet{} }
+func (*MacipACLInterfaceGet) GetMessageName() string { return "macip_acl_interface_get" }
+func (*MacipACLInterfaceGet) GetCrcString() string { return "51077d14" }
+func (*MacipACLInterfaceGet) GetMessageType() api.MessageType { return api.RequestMessage }
+
+func (m *MacipACLInterfaceGet) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ return size
+}
+func (m *MacipACLInterfaceGet) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ return buf, nil
}
-func (*MacipACLInterfaceGet) GetMessageType() api.MessageType {
- return api.RequestMessage
+func (m *MacipACLInterfaceGet) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ return nil
}
// MacipACLInterfaceGetReply represents VPP binary API message 'macip_acl_interface_get_reply'.
type MacipACLInterfaceGetReply struct {
- Count uint32 `struc:"sizeof=Acls"`
- Acls []uint32
+ Count uint32 `binapi:"u32,name=count" json:"count,omitempty" struc:"sizeof=Acls"`
+ Acls []uint32 `binapi:"u32[count],name=acls" json:"acls,omitempty"`
}
-func (*MacipACLInterfaceGetReply) GetMessageName() string {
- return "macip_acl_interface_get_reply"
-}
-func (*MacipACLInterfaceGetReply) GetCrcString() string {
- return "accf9b05"
-}
-func (*MacipACLInterfaceGetReply) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (m *MacipACLInterfaceGetReply) Reset() { *m = MacipACLInterfaceGetReply{} }
+func (*MacipACLInterfaceGetReply) GetMessageName() string { return "macip_acl_interface_get_reply" }
+func (*MacipACLInterfaceGetReply) GetCrcString() string { return "accf9b05" }
+func (*MacipACLInterfaceGetReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *MacipACLInterfaceGetReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Count
+ size += 4
+ // field[1] m.Acls
+ size += 4 * len(m.Acls)
+ return size
+}
+func (m *MacipACLInterfaceGetReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Count
+ o.PutUint32(buf[pos:pos+4], uint32(len(m.Acls)))
+ pos += 4
+ // field[1] m.Acls
+ for i := 0; i < len(m.Acls); i++ {
+ var x uint32
+ if i < len(m.Acls) {
+ x = uint32(m.Acls[i])
+ }
+ o.PutUint32(buf[pos:pos+4], uint32(x))
+ pos += 4
+ }
+ return buf, nil
+}
+func (m *MacipACLInterfaceGetReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Count
+ m.Count = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Acls
+ m.Acls = make([]uint32, m.Count)
+ for i := 0; i < len(m.Acls); i++ {
+ m.Acls[i] = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ }
+ return nil
}
// MacipACLInterfaceListDetails represents VPP binary API message 'macip_acl_interface_list_details'.
type MacipACLInterfaceListDetails struct {
- SwIfIndex uint32
- Count uint8 `struc:"sizeof=Acls"`
- Acls []uint32
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Count uint8 `binapi:"u8,name=count" json:"count,omitempty" struc:"sizeof=Acls"`
+ Acls []uint32 `binapi:"u32[count],name=acls" json:"acls,omitempty"`
}
+func (m *MacipACLInterfaceListDetails) Reset() { *m = MacipACLInterfaceListDetails{} }
func (*MacipACLInterfaceListDetails) GetMessageName() string {
return "macip_acl_interface_list_details"
}
-func (*MacipACLInterfaceListDetails) GetCrcString() string {
- return "29783fa0"
-}
-func (*MacipACLInterfaceListDetails) GetMessageType() api.MessageType {
- return api.ReplyMessage
+func (*MacipACLInterfaceListDetails) GetCrcString() string { return "29783fa0" }
+func (*MacipACLInterfaceListDetails) GetMessageType() api.MessageType { return api.ReplyMessage }
+
+func (m *MacipACLInterfaceListDetails) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Count
+ size += 1
+ // field[1] m.Acls
+ size += 4 * len(m.Acls)
+ return size
+}
+func (m *MacipACLInterfaceListDetails) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Count
+ buf[pos] = uint8(len(m.Acls))
+ pos += 1
+ // field[1] m.Acls
+ for i := 0; i < len(m.Acls); i++ {
+ var x uint32
+ if i < len(m.Acls) {
+ x = uint32(m.Acls[i])
+ }
+ o.PutUint32(buf[pos:pos+4], uint32(x))
+ pos += 4
+ }
+ return buf, nil
+}
+func (m *MacipACLInterfaceListDetails) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Count
+ m.Count = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.Acls
+ m.Acls = make([]uint32, m.Count)
+ for i := 0; i < len(m.Acls); i++ {
+ m.Acls[i] = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ }
+ return nil
}
// MacipACLInterfaceListDump represents VPP binary API message 'macip_acl_interface_list_dump'.
type MacipACLInterfaceListDump struct {
- SwIfIndex uint32
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
}
-func (*MacipACLInterfaceListDump) GetMessageName() string {
- return "macip_acl_interface_list_dump"
-}
-func (*MacipACLInterfaceListDump) GetCrcString() string {
- return "529cb13f"
-}
-func (*MacipACLInterfaceListDump) GetMessageType() api.MessageType {
- return api.RequestMessage
-}
+func (m *MacipACLInterfaceListDump) Reset() { *m = MacipACLInterfaceListDump{} }
+func (*MacipACLInterfaceListDump) GetMessageName() string { return "macip_acl_interface_list_dump" }
+func (*MacipACLInterfaceListDump) GetCrcString() string { return "529cb13f" }
+func (*MacipACLInterfaceListDump) GetMessageType() api.MessageType { return api.RequestMessage }
-func init() {
+func (m *MacipACLInterfaceListDump) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *MacipACLInterfaceListDump) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *MacipACLInterfaceListDump) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
+func init() { file_acl_binapi_init() }
+func file_acl_binapi_init() {
api.RegisterMessage((*ACLAddReplace)(nil), "acl.ACLAddReplace")
api.RegisterMessage((*ACLAddReplaceReply)(nil), "acl.ACLAddReplaceReply")
api.RegisterMessage((*ACLDel)(nil), "acl.ACLDel")
@@ -665,6 +2811,8 @@ func init() {
api.RegisterMessage((*ACLPluginGetConnTableMaxEntriesReply)(nil), "acl.ACLPluginGetConnTableMaxEntriesReply")
api.RegisterMessage((*ACLPluginGetVersion)(nil), "acl.ACLPluginGetVersion")
api.RegisterMessage((*ACLPluginGetVersionReply)(nil), "acl.ACLPluginGetVersionReply")
+ api.RegisterMessage((*ACLStatsIntfCountersEnable)(nil), "acl.ACLStatsIntfCountersEnable")
+ api.RegisterMessage((*ACLStatsIntfCountersEnableReply)(nil), "acl.ACLStatsIntfCountersEnableReply")
api.RegisterMessage((*MacipACLAdd)(nil), "acl.MacipACLAdd")
api.RegisterMessage((*MacipACLAddReplace)(nil), "acl.MacipACLAddReplace")
api.RegisterMessage((*MacipACLAddReplaceReply)(nil), "acl.MacipACLAddReplaceReply")
@@ -706,6 +2854,8 @@ func AllMessages() []api.Message {
(*ACLPluginGetConnTableMaxEntriesReply)(nil),
(*ACLPluginGetVersion)(nil),
(*ACLPluginGetVersionReply)(nil),
+ (*ACLStatsIntfCountersEnable)(nil),
+ (*ACLStatsIntfCountersEnableReply)(nil),
(*MacipACLAdd)(nil),
(*MacipACLAddReplace)(nil),
(*MacipACLAddReplaceReply)(nil),
@@ -723,293 +2873,13 @@ func AllMessages() []api.Message {
}
}
-// RPCService represents RPC service API for acl module.
-type RPCService interface {
- DumpACL(ctx context.Context, in *ACLDump) (RPCService_DumpACLClient, error)
- DumpACLInterfaceEtypeWhitelist(ctx context.Context, in *ACLInterfaceEtypeWhitelistDump) (RPCService_DumpACLInterfaceEtypeWhitelistClient, error)
- DumpACLInterfaceList(ctx context.Context, in *ACLInterfaceListDump) (RPCService_DumpACLInterfaceListClient, error)
- DumpMacipACL(ctx context.Context, in *MacipACLDump) (RPCService_DumpMacipACLClient, error)
- DumpMacipACLInterfaceList(ctx context.Context, in *MacipACLInterfaceListDump) (RPCService_DumpMacipACLInterfaceListClient, error)
- ACLAddReplace(ctx context.Context, in *ACLAddReplace) (*ACLAddReplaceReply, error)
- ACLDel(ctx context.Context, in *ACLDel) (*ACLDelReply, error)
- ACLInterfaceAddDel(ctx context.Context, in *ACLInterfaceAddDel) (*ACLInterfaceAddDelReply, error)
- ACLInterfaceSetACLList(ctx context.Context, in *ACLInterfaceSetACLList) (*ACLInterfaceSetACLListReply, error)
- ACLInterfaceSetEtypeWhitelist(ctx context.Context, in *ACLInterfaceSetEtypeWhitelist) (*ACLInterfaceSetEtypeWhitelistReply, error)
- ACLPluginControlPing(ctx context.Context, in *ACLPluginControlPing) (*ACLPluginControlPingReply, error)
- ACLPluginGetConnTableMaxEntries(ctx context.Context, in *ACLPluginGetConnTableMaxEntries) (*ACLPluginGetConnTableMaxEntriesReply, error)
- ACLPluginGetVersion(ctx context.Context, in *ACLPluginGetVersion) (*ACLPluginGetVersionReply, error)
- MacipACLAdd(ctx context.Context, in *MacipACLAdd) (*MacipACLAddReply, error)
- MacipACLAddReplace(ctx context.Context, in *MacipACLAddReplace) (*MacipACLAddReplaceReply, error)
- MacipACLDel(ctx context.Context, in *MacipACLDel) (*MacipACLDelReply, error)
- MacipACLInterfaceAddDel(ctx context.Context, in *MacipACLInterfaceAddDel) (*MacipACLInterfaceAddDelReply, error)
- MacipACLInterfaceGet(ctx context.Context, in *MacipACLInterfaceGet) (*MacipACLInterfaceGetReply, error)
-}
-
-type serviceClient struct {
- ch api.Channel
-}
-
-func NewServiceClient(ch api.Channel) RPCService {
- return &serviceClient{ch}
-}
-
-func (c *serviceClient) DumpACL(ctx context.Context, in *ACLDump) (RPCService_DumpACLClient, error) {
- stream := c.ch.SendMultiRequest(in)
- x := &serviceClient_DumpACLClient{stream}
- return x, nil
-}
-
-type RPCService_DumpACLClient interface {
- Recv() (*ACLDetails, error)
-}
-
-type serviceClient_DumpACLClient struct {
- api.MultiRequestCtx
-}
-
-func (c *serviceClient_DumpACLClient) Recv() (*ACLDetails, error) {
- m := new(ACLDetails)
- stop, err := c.MultiRequestCtx.ReceiveReply(m)
- if err != nil {
- return nil, err
- }
- if stop {
- return nil, io.EOF
- }
- return m, nil
-}
-
-func (c *serviceClient) DumpACLInterfaceEtypeWhitelist(ctx context.Context, in *ACLInterfaceEtypeWhitelistDump) (RPCService_DumpACLInterfaceEtypeWhitelistClient, error) {
- stream := c.ch.SendMultiRequest(in)
- x := &serviceClient_DumpACLInterfaceEtypeWhitelistClient{stream}
- return x, nil
-}
-
-type RPCService_DumpACLInterfaceEtypeWhitelistClient interface {
- Recv() (*ACLInterfaceEtypeWhitelistDetails, error)
-}
-
-type serviceClient_DumpACLInterfaceEtypeWhitelistClient struct {
- api.MultiRequestCtx
-}
-
-func (c *serviceClient_DumpACLInterfaceEtypeWhitelistClient) Recv() (*ACLInterfaceEtypeWhitelistDetails, error) {
- m := new(ACLInterfaceEtypeWhitelistDetails)
- stop, err := c.MultiRequestCtx.ReceiveReply(m)
- if err != nil {
- return nil, err
- }
- if stop {
- return nil, io.EOF
- }
- return m, nil
-}
-
-func (c *serviceClient) DumpACLInterfaceList(ctx context.Context, in *ACLInterfaceListDump) (RPCService_DumpACLInterfaceListClient, error) {
- stream := c.ch.SendMultiRequest(in)
- x := &serviceClient_DumpACLInterfaceListClient{stream}
- return x, nil
-}
-
-type RPCService_DumpACLInterfaceListClient interface {
- Recv() (*ACLInterfaceListDetails, error)
-}
-
-type serviceClient_DumpACLInterfaceListClient struct {
- api.MultiRequestCtx
-}
-
-func (c *serviceClient_DumpACLInterfaceListClient) Recv() (*ACLInterfaceListDetails, error) {
- m := new(ACLInterfaceListDetails)
- stop, err := c.MultiRequestCtx.ReceiveReply(m)
- if err != nil {
- return nil, err
- }
- if stop {
- return nil, io.EOF
- }
- return m, nil
-}
-
-func (c *serviceClient) DumpMacipACL(ctx context.Context, in *MacipACLDump) (RPCService_DumpMacipACLClient, error) {
- stream := c.ch.SendMultiRequest(in)
- x := &serviceClient_DumpMacipACLClient{stream}
- return x, nil
-}
-
-type RPCService_DumpMacipACLClient interface {
- Recv() (*MacipACLDetails, error)
-}
-
-type serviceClient_DumpMacipACLClient struct {
- api.MultiRequestCtx
-}
-
-func (c *serviceClient_DumpMacipACLClient) Recv() (*MacipACLDetails, error) {
- m := new(MacipACLDetails)
- stop, err := c.MultiRequestCtx.ReceiveReply(m)
- if err != nil {
- return nil, err
- }
- if stop {
- return nil, io.EOF
- }
- return m, nil
-}
-
-func (c *serviceClient) DumpMacipACLInterfaceList(ctx context.Context, in *MacipACLInterfaceListDump) (RPCService_DumpMacipACLInterfaceListClient, error) {
- stream := c.ch.SendMultiRequest(in)
- x := &serviceClient_DumpMacipACLInterfaceListClient{stream}
- return x, nil
-}
-
-type RPCService_DumpMacipACLInterfaceListClient interface {
- Recv() (*MacipACLInterfaceListDetails, error)
-}
-
-type serviceClient_DumpMacipACLInterfaceListClient struct {
- api.MultiRequestCtx
-}
-
-func (c *serviceClient_DumpMacipACLInterfaceListClient) Recv() (*MacipACLInterfaceListDetails, error) {
- m := new(MacipACLInterfaceListDetails)
- stop, err := c.MultiRequestCtx.ReceiveReply(m)
- if err != nil {
- return nil, err
- }
- if stop {
- return nil, io.EOF
- }
- return m, nil
-}
-
-func (c *serviceClient) ACLAddReplace(ctx context.Context, in *ACLAddReplace) (*ACLAddReplaceReply, error) {
- out := new(ACLAddReplaceReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) ACLDel(ctx context.Context, in *ACLDel) (*ACLDelReply, error) {
- out := new(ACLDelReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) ACLInterfaceAddDel(ctx context.Context, in *ACLInterfaceAddDel) (*ACLInterfaceAddDelReply, error) {
- out := new(ACLInterfaceAddDelReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) ACLInterfaceSetACLList(ctx context.Context, in *ACLInterfaceSetACLList) (*ACLInterfaceSetACLListReply, error) {
- out := new(ACLInterfaceSetACLListReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) ACLInterfaceSetEtypeWhitelist(ctx context.Context, in *ACLInterfaceSetEtypeWhitelist) (*ACLInterfaceSetEtypeWhitelistReply, error) {
- out := new(ACLInterfaceSetEtypeWhitelistReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) ACLPluginControlPing(ctx context.Context, in *ACLPluginControlPing) (*ACLPluginControlPingReply, error) {
- out := new(ACLPluginControlPingReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) ACLPluginGetConnTableMaxEntries(ctx context.Context, in *ACLPluginGetConnTableMaxEntries) (*ACLPluginGetConnTableMaxEntriesReply, error) {
- out := new(ACLPluginGetConnTableMaxEntriesReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) ACLPluginGetVersion(ctx context.Context, in *ACLPluginGetVersion) (*ACLPluginGetVersionReply, error) {
- out := new(ACLPluginGetVersionReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) MacipACLAdd(ctx context.Context, in *MacipACLAdd) (*MacipACLAddReply, error) {
- out := new(MacipACLAddReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) MacipACLAddReplace(ctx context.Context, in *MacipACLAddReplace) (*MacipACLAddReplaceReply, error) {
- out := new(MacipACLAddReplaceReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) MacipACLDel(ctx context.Context, in *MacipACLDel) (*MacipACLDelReply, error) {
- out := new(MacipACLDelReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) MacipACLInterfaceAddDel(ctx context.Context, in *MacipACLInterfaceAddDel) (*MacipACLInterfaceAddDelReply, error) {
- out := new(MacipACLInterfaceAddDelReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) MacipACLInterfaceGet(ctx context.Context, in *MacipACLInterfaceGet) (*MacipACLInterfaceGetReply, error) {
- out := new(MacipACLInterfaceGetReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-// 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.GoVppAPIPackageIsVersion1 // please upgrade the GoVPP api package
-
// Reference imports to suppress errors if they are not otherwise used.
var _ = api.RegisterMessage
+var _ = codec.DecodeString
var _ = bytes.NewBuffer
var _ = context.Background
var _ = io.Copy
var _ = strconv.Itoa
var _ = struc.Pack
+var _ = binary.BigEndian
+var _ = math.Float32bits
diff --git a/examples/binapi/acl/acl_rpc.ba.go b/examples/binapi/acl/acl_rpc.ba.go
new file mode 100644
index 0000000..62b10c3
--- /dev/null
+++ b/examples/binapi/acl/acl_rpc.ba.go
@@ -0,0 +1,302 @@
+// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+
+package acl
+
+import (
+ "context"
+ "io"
+
+ api "git.fd.io/govpp.git/api"
+)
+
+// RPCService represents RPC service API for acl module.
+type RPCService interface {
+ DumpACL(ctx context.Context, in *ACLDump) (RPCService_DumpACLClient, error)
+ DumpACLInterfaceEtypeWhitelist(ctx context.Context, in *ACLInterfaceEtypeWhitelistDump) (RPCService_DumpACLInterfaceEtypeWhitelistClient, error)
+ DumpACLInterfaceList(ctx context.Context, in *ACLInterfaceListDump) (RPCService_DumpACLInterfaceListClient, error)
+ DumpMacipACL(ctx context.Context, in *MacipACLDump) (RPCService_DumpMacipACLClient, error)
+ DumpMacipACLInterfaceList(ctx context.Context, in *MacipACLInterfaceListDump) (RPCService_DumpMacipACLInterfaceListClient, error)
+ ACLAddReplace(ctx context.Context, in *ACLAddReplace) (*ACLAddReplaceReply, error)
+ ACLDel(ctx context.Context, in *ACLDel) (*ACLDelReply, error)
+ ACLInterfaceAddDel(ctx context.Context, in *ACLInterfaceAddDel) (*ACLInterfaceAddDelReply, error)
+ ACLInterfaceSetACLList(ctx context.Context, in *ACLInterfaceSetACLList) (*ACLInterfaceSetACLListReply, error)
+ ACLInterfaceSetEtypeWhitelist(ctx context.Context, in *ACLInterfaceSetEtypeWhitelist) (*ACLInterfaceSetEtypeWhitelistReply, error)
+ ACLPluginControlPing(ctx context.Context, in *ACLPluginControlPing) (*ACLPluginControlPingReply, error)
+ ACLPluginGetConnTableMaxEntries(ctx context.Context, in *ACLPluginGetConnTableMaxEntries) (*ACLPluginGetConnTableMaxEntriesReply, error)
+ ACLPluginGetVersion(ctx context.Context, in *ACLPluginGetVersion) (*ACLPluginGetVersionReply, error)
+ ACLStatsIntfCountersEnable(ctx context.Context, in *ACLStatsIntfCountersEnable) (*ACLStatsIntfCountersEnableReply, error)
+ MacipACLAdd(ctx context.Context, in *MacipACLAdd) (*MacipACLAddReply, error)
+ MacipACLAddReplace(ctx context.Context, in *MacipACLAddReplace) (*MacipACLAddReplaceReply, error)
+ MacipACLDel(ctx context.Context, in *MacipACLDel) (*MacipACLDelReply, error)
+ MacipACLInterfaceAddDel(ctx context.Context, in *MacipACLInterfaceAddDel) (*MacipACLInterfaceAddDelReply, error)
+ MacipACLInterfaceGet(ctx context.Context, in *MacipACLInterfaceGet) (*MacipACLInterfaceGetReply, error)
+}
+
+type serviceClient struct {
+ ch api.Channel
+}
+
+func NewServiceClient(ch api.Channel) RPCService {
+ return &serviceClient{ch}
+}
+
+func (c *serviceClient) DumpACL(ctx context.Context, in *ACLDump) (RPCService_DumpACLClient, error) {
+ stream := c.ch.SendMultiRequest(in)
+ x := &serviceClient_DumpACLClient{stream}
+ return x, nil
+}
+
+type RPCService_DumpACLClient interface {
+ Recv() (*ACLDetails, error)
+}
+
+type serviceClient_DumpACLClient struct {
+ api.MultiRequestCtx
+}
+
+func (c *serviceClient_DumpACLClient) Recv() (*ACLDetails, error) {
+ m := new(ACLDetails)
+ stop, err := c.MultiRequestCtx.ReceiveReply(m)
+ if err != nil {
+ return nil, err
+ }
+ if stop {
+ return nil, io.EOF
+ }
+ return m, nil
+}
+
+func (c *serviceClient) DumpACLInterfaceEtypeWhitelist(ctx context.Context, in *ACLInterfaceEtypeWhitelistDump) (RPCService_DumpACLInterfaceEtypeWhitelistClient, error) {
+ stream := c.ch.SendMultiRequest(in)
+ x := &serviceClient_DumpACLInterfaceEtypeWhitelistClient{stream}
+ return x, nil
+}
+
+type RPCService_DumpACLInterfaceEtypeWhitelistClient interface {
+ Recv() (*ACLInterfaceEtypeWhitelistDetails, error)
+}
+
+type serviceClient_DumpACLInterfaceEtypeWhitelistClient struct {
+ api.MultiRequestCtx
+}
+
+func (c *serviceClient_DumpACLInterfaceEtypeWhitelistClient) Recv() (*ACLInterfaceEtypeWhitelistDetails, error) {
+ m := new(ACLInterfaceEtypeWhitelistDetails)
+ stop, err := c.MultiRequestCtx.ReceiveReply(m)
+ if err != nil {
+ return nil, err
+ }
+ if stop {
+ return nil, io.EOF
+ }
+ return m, nil
+}
+
+func (c *serviceClient) DumpACLInterfaceList(ctx context.Context, in *ACLInterfaceListDump) (RPCService_DumpACLInterfaceListClient, error) {
+ stream := c.ch.SendMultiRequest(in)
+ x := &serviceClient_DumpACLInterfaceListClient{stream}
+ return x, nil
+}
+
+type RPCService_DumpACLInterfaceListClient interface {
+ Recv() (*ACLInterfaceListDetails, error)
+}
+
+type serviceClient_DumpACLInterfaceListClient struct {
+ api.MultiRequestCtx
+}
+
+func (c *serviceClient_DumpACLInterfaceListClient) Recv() (*ACLInterfaceListDetails, error) {
+ m := new(ACLInterfaceListDetails)
+ stop, err := c.MultiRequestCtx.ReceiveReply(m)
+ if err != nil {
+ return nil, err
+ }
+ if stop {
+ return nil, io.EOF
+ }
+ return m, nil
+}
+
+func (c *serviceClient) DumpMacipACL(ctx context.Context, in *MacipACLDump) (RPCService_DumpMacipACLClient, error) {
+ stream := c.ch.SendMultiRequest(in)
+ x := &serviceClient_DumpMacipACLClient{stream}
+ return x, nil
+}
+
+type RPCService_DumpMacipACLClient interface {
+ Recv() (*MacipACLDetails, error)
+}
+
+type serviceClient_DumpMacipACLClient struct {
+ api.MultiRequestCtx
+}
+
+func (c *serviceClient_DumpMacipACLClient) Recv() (*MacipACLDetails, error) {
+ m := new(MacipACLDetails)
+ stop, err := c.MultiRequestCtx.ReceiveReply(m)
+ if err != nil {
+ return nil, err
+ }
+ if stop {
+ return nil, io.EOF
+ }
+ return m, nil
+}
+
+func (c *serviceClient) DumpMacipACLInterfaceList(ctx context.Context, in *MacipACLInterfaceListDump) (RPCService_DumpMacipACLInterfaceListClient, error) {
+ stream := c.ch.SendMultiRequest(in)
+ x := &serviceClient_DumpMacipACLInterfaceListClient{stream}
+ return x, nil
+}
+
+type RPCService_DumpMacipACLInterfaceListClient interface {
+ Recv() (*MacipACLInterfaceListDetails, error)
+}
+
+type serviceClient_DumpMacipACLInterfaceListClient struct {
+ api.MultiRequestCtx
+}
+
+func (c *serviceClient_DumpMacipACLInterfaceListClient) Recv() (*MacipACLInterfaceListDetails, error) {
+ m := new(MacipACLInterfaceListDetails)
+ stop, err := c.MultiRequestCtx.ReceiveReply(m)
+ if err != nil {
+ return nil, err
+ }
+ if stop {
+ return nil, io.EOF
+ }
+ return m, nil
+}
+
+func (c *serviceClient) ACLAddReplace(ctx context.Context, in *ACLAddReplace) (*ACLAddReplaceReply, error) {
+ out := new(ACLAddReplaceReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) ACLDel(ctx context.Context, in *ACLDel) (*ACLDelReply, error) {
+ out := new(ACLDelReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) ACLInterfaceAddDel(ctx context.Context, in *ACLInterfaceAddDel) (*ACLInterfaceAddDelReply, error) {
+ out := new(ACLInterfaceAddDelReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) ACLInterfaceSetACLList(ctx context.Context, in *ACLInterfaceSetACLList) (*ACLInterfaceSetACLListReply, error) {
+ out := new(ACLInterfaceSetACLListReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) ACLInterfaceSetEtypeWhitelist(ctx context.Context, in *ACLInterfaceSetEtypeWhitelist) (*ACLInterfaceSetEtypeWhitelistReply, error) {
+ out := new(ACLInterfaceSetEtypeWhitelistReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) ACLPluginControlPing(ctx context.Context, in *ACLPluginControlPing) (*ACLPluginControlPingReply, error) {
+ out := new(ACLPluginControlPingReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) ACLPluginGetConnTableMaxEntries(ctx context.Context, in *ACLPluginGetConnTableMaxEntries) (*ACLPluginGetConnTableMaxEntriesReply, error) {
+ out := new(ACLPluginGetConnTableMaxEntriesReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) ACLPluginGetVersion(ctx context.Context, in *ACLPluginGetVersion) (*ACLPluginGetVersionReply, error) {
+ out := new(ACLPluginGetVersionReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) ACLStatsIntfCountersEnable(ctx context.Context, in *ACLStatsIntfCountersEnable) (*ACLStatsIntfCountersEnableReply, error) {
+ out := new(ACLStatsIntfCountersEnableReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) MacipACLAdd(ctx context.Context, in *MacipACLAdd) (*MacipACLAddReply, error) {
+ out := new(MacipACLAddReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) MacipACLAddReplace(ctx context.Context, in *MacipACLAddReplace) (*MacipACLAddReplaceReply, error) {
+ out := new(MacipACLAddReplaceReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) MacipACLDel(ctx context.Context, in *MacipACLDel) (*MacipACLDelReply, error) {
+ out := new(MacipACLDelReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) MacipACLInterfaceAddDel(ctx context.Context, in *MacipACLInterfaceAddDel) (*MacipACLInterfaceAddDelReply, error) {
+ out := new(MacipACLInterfaceAddDelReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) MacipACLInterfaceGet(ctx context.Context, in *MacipACLInterfaceGet) (*MacipACLInterfaceGetReply, error) {
+ out := new(MacipACLInterfaceGetReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ = api.RegisterMessage
+var _ = context.Background
+var _ = io.Copy
diff --git a/examples/binapi/af_packet/af_packet.ba.go b/examples/binapi/af_packet/af_packet.ba.go
index 9660114..ab57c62 100644
--- a/examples/binapi/af_packet/af_packet.ba.go
+++ b/examples/binapi/af_packet/af_packet.ba.go
@@ -1,30 +1,38 @@
// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+// versions:
+// binapi-generator: v0.4.0-alpha-1-g435c3f4-dirty
+// VPP: 20.01-45~g7a071e370~b63
// source: /usr/share/vpp/api/core/af_packet.api.json
/*
-Package af_packet is a generated VPP binary API for 'af_packet' module.
+Package af_packet contains generated code for VPP binary API defined by af_packet.api (version 2.0.0).
It consists of:
- 6 enums
2 aliases
+ 6 enums
8 messages
- 4 services
*/
package af_packet
import (
"bytes"
"context"
+ "encoding/binary"
"io"
+ "math"
"strconv"
api "git.fd.io/govpp.git/api"
+ codec "git.fd.io/govpp.git/codec"
struc "github.com/lunixbochs/struc"
-
- ethernet_types "git.fd.io/govpp.git/examples/binapi/ethernet_types"
- interface_types "git.fd.io/govpp.git/examples/binapi/interface_types"
)
+// 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 // please upgrade the GoVPP api package
+
const (
// ModuleName is the name of this module.
ModuleName = "af_packet"
@@ -34,27 +42,230 @@ const (
VersionCrc = 0xba745e20
)
-type IfStatusFlags = interface_types.IfStatusFlags
+// IfStatusFlags represents VPP binary API enum 'if_status_flags'.
+type IfStatusFlags uint32
-type IfType = interface_types.IfType
+const (
+ IF_STATUS_API_FLAG_ADMIN_UP IfStatusFlags = 1
+ IF_STATUS_API_FLAG_LINK_UP IfStatusFlags = 2
+)
-type LinkDuplex = interface_types.LinkDuplex
+var (
+ IfStatusFlags_name = map[uint32]string{
+ 1: "IF_STATUS_API_FLAG_ADMIN_UP",
+ 2: "IF_STATUS_API_FLAG_LINK_UP",
+ }
+ IfStatusFlags_value = map[string]uint32{
+ "IF_STATUS_API_FLAG_ADMIN_UP": 1,
+ "IF_STATUS_API_FLAG_LINK_UP": 2,
+ }
+)
-type MtuProto = interface_types.MtuProto
+func (x IfStatusFlags) String() string {
+ s, ok := IfStatusFlags_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "IfStatusFlags(" + strconv.Itoa(int(x)) + ")"
+}
-type RxMode = interface_types.RxMode
+// IfType represents VPP binary API enum 'if_type'.
+type IfType uint32
-type SubIfFlags = interface_types.SubIfFlags
+const (
+ IF_API_TYPE_HARDWARE IfType = 1
+ IF_API_TYPE_SUB IfType = 2
+ IF_API_TYPE_P2P IfType = 3
+ IF_API_TYPE_PIPE IfType = 4
+)
-type InterfaceIndex = interface_types.InterfaceIndex
+var (
+ IfType_name = map[uint32]string{
+ 1: "IF_API_TYPE_HARDWARE",
+ 2: "IF_API_TYPE_SUB",
+ 3: "IF_API_TYPE_P2P",
+ 4: "IF_API_TYPE_PIPE",
+ }
+ IfType_value = map[string]uint32{
+ "IF_API_TYPE_HARDWARE": 1,
+ "IF_API_TYPE_SUB": 2,
+ "IF_API_TYPE_P2P": 3,
+ "IF_API_TYPE_PIPE": 4,
+ }
+)
-type MacAddress = ethernet_types.MacAddress
+func (x IfType) String() string {
+ s, ok := IfType_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "IfType(" + strconv.Itoa(int(x)) + ")"
+}
+
+// LinkDuplex represents VPP binary API enum 'link_duplex'.
+type LinkDuplex uint32
+
+const (
+ LINK_DUPLEX_API_UNKNOWN LinkDuplex = 0
+ LINK_DUPLEX_API_HALF LinkDuplex = 1
+ LINK_DUPLEX_API_FULL LinkDuplex = 2
+)
+
+var (
+ LinkDuplex_name = map[uint32]string{
+ 0: "LINK_DUPLEX_API_UNKNOWN",
+ 1: "LINK_DUPLEX_API_HALF",
+ 2: "LINK_DUPLEX_API_FULL",
+ }
+ LinkDuplex_value = map[string]uint32{
+ "LINK_DUPLEX_API_UNKNOWN": 0,
+ "LINK_DUPLEX_API_HALF": 1,
+ "LINK_DUPLEX_API_FULL": 2,
+ }
+)
+
+func (x LinkDuplex) String() string {
+ s, ok := LinkDuplex_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "LinkDuplex(" + strconv.Itoa(int(x)) + ")"
+}
+
+// MtuProto represents VPP binary API enum 'mtu_proto'.
+type MtuProto uint32
+
+const (
+ MTU_PROTO_API_L3 MtuProto = 1
+ MTU_PROTO_API_IP4 MtuProto = 2
+ MTU_PROTO_API_IP6 MtuProto = 3
+ MTU_PROTO_API_MPLS MtuProto = 4
+ MTU_PROTO_API_N MtuProto = 5
+)
+
+var (
+ MtuProto_name = map[uint32]string{
+ 1: "MTU_PROTO_API_L3",
+ 2: "MTU_PROTO_API_IP4",
+ 3: "MTU_PROTO_API_IP6",
+ 4: "MTU_PROTO_API_MPLS",
+ 5: "MTU_PROTO_API_N",
+ }
+ MtuProto_value = map[string]uint32{
+ "MTU_PROTO_API_L3": 1,
+ "MTU_PROTO_API_IP4": 2,
+ "MTU_PROTO_API_IP6": 3,
+ "MTU_PROTO_API_MPLS": 4,
+ "MTU_PROTO_API_N": 5,
+ }
+)
+
+func (x MtuProto) String() string {
+ s, ok := MtuProto_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "MtuProto(" + strconv.Itoa(int(x)) + ")"
+}
+
+// RxMode represents VPP binary API enum 'rx_mode'.
+type RxMode uint32
+
+const (
+ RX_MODE_API_UNKNOWN RxMode = 0
+ RX_MODE_API_POLLING RxMode = 1
+ RX_MODE_API_INTERRUPT RxMode = 2
+ RX_MODE_API_ADAPTIVE RxMode = 3
+ RX_MODE_API_DEFAULT RxMode = 4
+)
+
+var (
+ RxMode_name = map[uint32]string{
+ 0: "RX_MODE_API_UNKNOWN",
+ 1: "RX_MODE_API_POLLING",
+ 2: "RX_MODE_API_INTERRUPT",
+ 3: "RX_MODE_API_ADAPTIVE",
+ 4: "RX_MODE_API_DEFAULT",
+ }
+ RxMode_value = map[string]uint32{
+ "RX_MODE_API_UNKNOWN": 0,
+ "RX_MODE_API_POLLING": 1,
+ "RX_MODE_API_INTERRUPT": 2,
+ "RX_MODE_API_ADAPTIVE": 3,
+ "RX_MODE_API_DEFAULT": 4,
+ }
+)
+
+func (x RxMode) String() string {
+ s, ok := RxMode_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "RxMode(" + strconv.Itoa(int(x)) + ")"
+}
+
+// SubIfFlags represents VPP binary API enum 'sub_if_flags'.
+type SubIfFlags uint32
+
+const (
+ SUB_IF_API_FLAG_NO_TAGS SubIfFlags = 1
+ SUB_IF_API_FLAG_ONE_TAG SubIfFlags = 2
+ SUB_IF_API_FLAG_TWO_TAGS SubIfFlags = 4
+ SUB_IF_API_FLAG_DOT1AD SubIfFlags = 8
+ SUB_IF_API_FLAG_EXACT_MATCH SubIfFlags = 16
+ SUB_IF_API_FLAG_DEFAULT SubIfFlags = 32
+ SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY SubIfFlags = 64
+ SUB_IF_API_FLAG_INNER_VLAN_ID_ANY SubIfFlags = 128
+ SUB_IF_API_FLAG_MASK_VNET SubIfFlags = 254
+ SUB_IF_API_FLAG_DOT1AH SubIfFlags = 256
+)
+
+var (
+ SubIfFlags_name = map[uint32]string{
+ 1: "SUB_IF_API_FLAG_NO_TAGS",
+ 2: "SUB_IF_API_FLAG_ONE_TAG",
+ 4: "SUB_IF_API_FLAG_TWO_TAGS",
+ 8: "SUB_IF_API_FLAG_DOT1AD",
+ 16: "SUB_IF_API_FLAG_EXACT_MATCH",
+ 32: "SUB_IF_API_FLAG_DEFAULT",
+ 64: "SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY",
+ 128: "SUB_IF_API_FLAG_INNER_VLAN_ID_ANY",
+ 254: "SUB_IF_API_FLAG_MASK_VNET",
+ 256: "SUB_IF_API_FLAG_DOT1AH",
+ }
+ SubIfFlags_value = map[string]uint32{
+ "SUB_IF_API_FLAG_NO_TAGS": 1,
+ "SUB_IF_API_FLAG_ONE_TAG": 2,
+ "SUB_IF_API_FLAG_TWO_TAGS": 4,
+ "SUB_IF_API_FLAG_DOT1AD": 8,
+ "SUB_IF_API_FLAG_EXACT_MATCH": 16,
+ "SUB_IF_API_FLAG_DEFAULT": 32,
+ "SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY": 64,
+ "SUB_IF_API_FLAG_INNER_VLAN_ID_ANY": 128,
+ "SUB_IF_API_FLAG_MASK_VNET": 254,
+ "SUB_IF_API_FLAG_DOT1AH": 256,
+ }
+)
+
+func (x SubIfFlags) String() string {
+ s, ok := SubIfFlags_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "SubIfFlags(" + strconv.Itoa(int(x)) + ")"
+}
+
+// InterfaceIndex represents VPP binary API alias 'interface_index'.
+type InterfaceIndex uint32
+
+// MacAddress represents VPP binary API alias 'mac_address'.
+type MacAddress [6]uint8
// AfPacketCreate represents VPP binary API message 'af_packet_create'.
type AfPacketCreate struct {
- HwAddr MacAddress
- UseRandomHwAddr bool
- HostIfName string `struc:"[64]byte"`
+ HwAddr MacAddress `binapi:"mac_address,name=hw_addr" json:"hw_addr,omitempty"`
+ UseRandomHwAddr bool `binapi:"bool,name=use_random_hw_addr" json:"use_random_hw_addr,omitempty"`
+ HostIfName string `binapi:"string[64],name=host_if_name" json:"host_if_name,omitempty" struc:"[64]byte"`
}
func (m *AfPacketCreate) Reset() { *m = AfPacketCreate{} }
@@ -62,10 +273,75 @@ func (*AfPacketCreate) GetMessageName() string { return "af_packet_crea
func (*AfPacketCreate) GetCrcString() string { return "a190415f" }
func (*AfPacketCreate) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *AfPacketCreate) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.HwAddr
+ size += 6
+ // field[1] m.UseRandomHwAddr
+ size += 1
+ // field[1] m.HostIfName
+ size += 64
+ return size
+}
+func (m *AfPacketCreate) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.HwAddr
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(m.HwAddr) {
+ x = uint8(m.HwAddr[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.UseRandomHwAddr
+ if m.UseRandomHwAddr {
+ buf[pos] = 1
+ }
+ pos += 1
+ // field[1] m.HostIfName
+ copy(buf[pos:pos+64], m.HostIfName)
+ pos += 64
+ return buf, nil
+}
+func (m *AfPacketCreate) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.HwAddr
+ for i := 0; i < len(m.HwAddr); i++ {
+ m.HwAddr[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.UseRandomHwAddr
+ m.UseRandomHwAddr = tmp[pos] != 0
+ pos += 1
+ // field[1] m.HostIfName
+ {
+ nul := bytes.Index(tmp[pos:pos+64], []byte{0x00})
+ m.HostIfName = codec.DecodeString(tmp[pos : pos+nul])
+ pos += 64
+ }
+ return nil
+}
+
// AfPacketCreateReply represents VPP binary API message 'af_packet_create_reply'.
type AfPacketCreateReply struct {
- Retval int32
- SwIfIndex InterfaceIndex
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
}
func (m *AfPacketCreateReply) Reset() { *m = AfPacketCreateReply{} }
@@ -73,9 +349,53 @@ func (*AfPacketCreateReply) GetMessageName() string { return "af_packet
func (*AfPacketCreateReply) GetCrcString() string { return "5383d31f" }
func (*AfPacketCreateReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *AfPacketCreateReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *AfPacketCreateReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *AfPacketCreateReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// AfPacketDelete represents VPP binary API message 'af_packet_delete'.
type AfPacketDelete struct {
- HostIfName string `struc:"[64]byte"`
+ HostIfName string `binapi:"string[64],name=host_if_name" json:"host_if_name,omitempty" struc:"[64]byte"`
}
func (m *AfPacketDelete) Reset() { *m = AfPacketDelete{} }
@@ -83,9 +403,48 @@ func (*AfPacketDelete) GetMessageName() string { return "af_packet_dele
func (*AfPacketDelete) GetCrcString() string { return "863fa648" }
func (*AfPacketDelete) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *AfPacketDelete) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.HostIfName
+ size += 64
+ return size
+}
+func (m *AfPacketDelete) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.HostIfName
+ copy(buf[pos:pos+64], m.HostIfName)
+ pos += 64
+ return buf, nil
+}
+func (m *AfPacketDelete) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.HostIfName
+ {
+ nul := bytes.Index(tmp[pos:pos+64], []byte{0x00})
+ m.HostIfName = codec.DecodeString(tmp[pos : pos+nul])
+ pos += 64
+ }
+ return nil
+}
+
// AfPacketDeleteReply represents VPP binary API message 'af_packet_delete_reply'.
type AfPacketDeleteReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *AfPacketDeleteReply) Reset() { *m = AfPacketDeleteReply{} }
@@ -93,10 +452,46 @@ func (*AfPacketDeleteReply) GetMessageName() string { return "af_packet
func (*AfPacketDeleteReply) GetCrcString() string { return "e8d4e804" }
func (*AfPacketDeleteReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *AfPacketDeleteReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *AfPacketDeleteReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *AfPacketDeleteReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// AfPacketDetails represents VPP binary API message 'af_packet_details'.
type AfPacketDetails struct {
- SwIfIndex InterfaceIndex
- HostIfName string `struc:"[64]byte"`
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ HostIfName string `binapi:"string[64],name=host_if_name" json:"host_if_name,omitempty" struc:"[64]byte"`
}
func (m *AfPacketDetails) Reset() { *m = AfPacketDetails{} }
@@ -104,6 +499,53 @@ func (*AfPacketDetails) GetMessageName() string { return "af_packet_det
func (*AfPacketDetails) GetCrcString() string { return "58c7c042" }
func (*AfPacketDetails) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *AfPacketDetails) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.HostIfName
+ size += 64
+ return size
+}
+func (m *AfPacketDetails) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.HostIfName
+ copy(buf[pos:pos+64], m.HostIfName)
+ pos += 64
+ return buf, nil
+}
+func (m *AfPacketDetails) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.HostIfName
+ {
+ nul := bytes.Index(tmp[pos:pos+64], []byte{0x00})
+ m.HostIfName = codec.DecodeString(tmp[pos : pos+nul])
+ pos += 64
+ }
+ return nil
+}
+
// AfPacketDump represents VPP binary API message 'af_packet_dump'.
type AfPacketDump struct{}
@@ -112,10 +554,38 @@ func (*AfPacketDump) GetMessageName() string { return "af_packet_dump"
func (*AfPacketDump) GetCrcString() string { return "51077d14" }
func (*AfPacketDump) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *AfPacketDump) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ return size
+}
+func (m *AfPacketDump) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ return buf, nil
+}
+func (m *AfPacketDump) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ return nil
+}
+
// AfPacketSetL4CksumOffload represents VPP binary API message 'af_packet_set_l4_cksum_offload'.
type AfPacketSetL4CksumOffload struct {
- SwIfIndex InterfaceIndex
- Set bool
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Set bool `binapi:"bool,name=set" json:"set,omitempty"`
}
func (m *AfPacketSetL4CksumOffload) Reset() { *m = AfPacketSetL4CksumOffload{} }
@@ -123,9 +593,55 @@ func (*AfPacketSetL4CksumOffload) GetMessageName() string { return "af_
func (*AfPacketSetL4CksumOffload) GetCrcString() string { return "319cd5c8" }
func (*AfPacketSetL4CksumOffload) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *AfPacketSetL4CksumOffload) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Set
+ size += 1
+ return size
+}
+func (m *AfPacketSetL4CksumOffload) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Set
+ if m.Set {
+ buf[pos] = 1
+ }
+ pos += 1
+ return buf, nil
+}
+func (m *AfPacketSetL4CksumOffload) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Set
+ m.Set = tmp[pos] != 0
+ pos += 1
+ return nil
+}
+
// AfPacketSetL4CksumOffloadReply represents VPP binary API message 'af_packet_set_l4_cksum_offload_reply'.
type AfPacketSetL4CksumOffloadReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *AfPacketSetL4CksumOffloadReply) Reset() { *m = AfPacketSetL4CksumOffloadReply{} }
@@ -135,7 +651,44 @@ func (*AfPacketSetL4CksumOffloadReply) GetMessageName() string {
func (*AfPacketSetL4CksumOffloadReply) GetCrcString() string { return "e8d4e804" }
func (*AfPacketSetL4CksumOffloadReply) GetMessageType() api.MessageType { return api.ReplyMessage }
-func init() {
+func (m *AfPacketSetL4CksumOffloadReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *AfPacketSetL4CksumOffloadReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *AfPacketSetL4CksumOffloadReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
+func init() { file_af_packet_binapi_init() }
+func file_af_packet_binapi_init() {
api.RegisterMessage((*AfPacketCreate)(nil), "af_packet.AfPacketCreate")
api.RegisterMessage((*AfPacketCreateReply)(nil), "af_packet.AfPacketCreateReply")
api.RegisterMessage((*AfPacketDelete)(nil), "af_packet.AfPacketDelete")
@@ -160,85 +713,13 @@ func AllMessages() []api.Message {
}
}
-// RPCService represents RPC service API for af_packet module.
-type RPCService interface {
- DumpAfPacket(ctx context.Context, in *AfPacketDump) (RPCService_DumpAfPacketClient, error)
- AfPacketCreate(ctx context.Context, in *AfPacketCreate) (*AfPacketCreateReply, error)
- AfPacketDelete(ctx context.Context, in *AfPacketDelete) (*AfPacketDeleteReply, error)
- AfPacketSetL4CksumOffload(ctx context.Context, in *AfPacketSetL4CksumOffload) (*AfPacketSetL4CksumOffloadReply, error)
-}
-
-type serviceClient struct {
- ch api.Channel
-}
-
-func NewServiceClient(ch api.Channel) RPCService {
- return &serviceClient{ch}
-}
-
-func (c *serviceClient) DumpAfPacket(ctx context.Context, in *AfPacketDump) (RPCService_DumpAfPacketClient, error) {
- stream := c.ch.SendMultiRequest(in)
- x := &serviceClient_DumpAfPacketClient{stream}
- return x, nil
-}
-
-type RPCService_DumpAfPacketClient interface {
- Recv() (*AfPacketDetails, error)
-}
-
-type serviceClient_DumpAfPacketClient struct {
- api.MultiRequestCtx
-}
-
-func (c *serviceClient_DumpAfPacketClient) Recv() (*AfPacketDetails, error) {
- m := new(AfPacketDetails)
- stop, err := c.MultiRequestCtx.ReceiveReply(m)
- if err != nil {
- return nil, err
- }
- if stop {
- return nil, io.EOF
- }
- return m, nil
-}
-
-func (c *serviceClient) AfPacketCreate(ctx context.Context, in *AfPacketCreate) (*AfPacketCreateReply, error) {
- out := new(AfPacketCreateReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) AfPacketDelete(ctx context.Context, in *AfPacketDelete) (*AfPacketDeleteReply, error) {
- out := new(AfPacketDeleteReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-func (c *serviceClient) AfPacketSetL4CksumOffload(ctx context.Context, in *AfPacketSetL4CksumOffload) (*AfPacketSetL4CksumOffloadReply, error) {
- out := new(AfPacketSetL4CksumOffloadReply)
- err := c.ch.SendRequest(in).ReceiveReply(out)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
-// 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.GoVppAPIPackageIsVersion1 // please upgrade the GoVPP api package
-
// Reference imports to suppress errors if they are not otherwise used.
var _ = api.RegisterMessage
+var _ = codec.DecodeString
var _ = bytes.NewBuffer
var _ = context.Background
var _ = io.Copy
var _ = strconv.Itoa
var _ = struc.Pack
+var _ = binary.BigEndian
+var _ = math.Float32bits
diff --git a/examples/binapi/af_packet/af_packet_rpc.ba.go b/examples/binapi/af_packet/af_packet_rpc.ba.go
new file mode 100644
index 0000000..d2df47a
--- /dev/null
+++ b/examples/binapi/af_packet/af_packet_rpc.ba.go
@@ -0,0 +1,84 @@
+// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+
+package af_packet
+
+import (
+ "context"
+ "io"
+
+ api "git.fd.io/govpp.git/api"
+)
+
+// RPCService represents RPC service API for af_packet module.
+type RPCService interface {
+ DumpAfPacket(ctx context.Context, in *AfPacketDump) (RPCService_DumpAfPacketClient, error)
+ AfPacketCreate(ctx context.Context, in *AfPacketCreate) (*AfPacketCreateReply, error)
+ AfPacketDelete(ctx context.Context, in *AfPacketDelete) (*AfPacketDeleteReply, error)
+ AfPacketSetL4CksumOffload(ctx context.Context, in *AfPacketSetL4CksumOffload) (*AfPacketSetL4CksumOffloadReply, error)
+}
+
+type serviceClient struct {
+ ch api.Channel
+}
+
+func NewServiceClient(ch api.Channel) RPCService {
+ return &serviceClient{ch}
+}
+
+func (c *serviceClient) DumpAfPacket(ctx context.Context, in *AfPacketDump) (RPCService_DumpAfPacketClient, error) {
+ stream := c.ch.SendMultiRequest(in)
+ x := &serviceClient_DumpAfPacketClient{stream}
+ return x, nil
+}
+
+type RPCService_DumpAfPacketClient interface {
+ Recv() (*AfPacketDetails, error)
+}
+
+type serviceClient_DumpAfPacketClient struct {
+ api.MultiRequestCtx
+}
+
+func (c *serviceClient_DumpAfPacketClient) Recv() (*AfPacketDetails, error) {
+ m := new(AfPacketDetails)
+ stop, err := c.MultiRequestCtx.ReceiveReply(m)
+ if err != nil {
+ return nil, err
+ }
+ if stop {
+ return nil, io.EOF
+ }
+ return m, nil
+}
+
+func (c *serviceClient) AfPacketCreate(ctx context.Context, in *AfPacketCreate) (*AfPacketCreateReply, error) {
+ out := new(AfPacketCreateReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) AfPacketDelete(ctx context.Context, in *AfPacketDelete) (*AfPacketDeleteReply, error) {
+ out := new(AfPacketDeleteReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *serviceClient) AfPacketSetL4CksumOffload(ctx context.Context, in *AfPacketSetL4CksumOffload) (*AfPacketSetL4CksumOffloadReply, error) {
+ out := new(AfPacketSetL4CksumOffloadReply)
+ err := c.ch.SendRequest(in).ReceiveReply(out)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ = api.RegisterMessage
+var _ = context.Background
+var _ = io.Copy
diff --git a/examples/binapi/ethernet_types/ethernet_types.ba.go b/examples/binapi/ethernet_types/ethernet_types.ba.go
deleted file mode 100644
index fffa6b1..0000000
--- a/examples/binapi/ethernet_types/ethernet_types.ba.go
+++ /dev/null
@@ -1,44 +0,0 @@
-// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
-// source: /usr/share/vpp/api/core/ethernet_types.api.json
-
-/*
-Package ethernet_types is a generated VPP binary API for 'ethernet_types' module.
-
-It consists of:
- 1 alias
-*/
-package ethernet_types
-
-import (
- "bytes"
- "context"
- "io"
- "strconv"
-
- api "git.fd.io/govpp.git/api"
- struc "github.com/lunixbochs/struc"
-)
-
-const (
- // ModuleName is the name of this module.
- ModuleName = "ethernet_types"
- // VersionCrc is the CRC of this module.
- VersionCrc = 0xd4ff2808
-)
-
-// MacAddress represents VPP binary API alias 'mac_address'.
-type MacAddress [6]uint8
-
-// 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.GoVppAPIPackageIsVersion1 // please upgrade the GoVPP api package
-
-// Reference imports to suppress errors if they are not otherwise used.
-var _ = api.RegisterMessage
-var _ = bytes.NewBuffer
-var _ = context.Background
-var _ = io.Copy
-var _ = strconv.Itoa
-var _ = struc.Pack
diff --git a/examples/binapi/fib_types/fib_types.ba.go b/examples/binapi/fib_types/fib_types.ba.go
new file mode 100644
index 0000000..dd725b6
--- /dev/null
+++ b/examples/binapi/fib_types/fib_types.ba.go
@@ -0,0 +1,522 @@
+// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+// versions:
+// binapi-generator: v0.4.0-alpha-1-g435c3f4-dirty
+// VPP: 20.01-45~g7a071e370~b63
+// source: /usr/share/vpp/api/core/fib_types.api.json
+
+/*
+Package fib_types contains generated code for VPP binary API defined by fib_types.api (version 2.0.0).
+
+It consists of:
+ 5 aliases
+ 7 enums
+ 9 types
+ 1 union
+*/
+package fib_types
+
+import (
+ "bytes"
+ "context"
+ "encoding/binary"
+ "io"
+ "math"
+ "strconv"
+
+ api "git.fd.io/govpp.git/api"
+ codec "git.fd.io/govpp.git/codec"
+ struc "github.com/lunixbochs/struc"
+)
+
+// 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 // please upgrade the GoVPP api package
+
+const (
+ // ModuleName is the name of this module.
+ ModuleName = "fib_types"
+ // APIVersion is the API version of this module.
+ APIVersion = "2.0.0"
+ // VersionCrc is the CRC of this module.
+ VersionCrc = 0x57387845
+)
+
+// AddressFamily represents VPP binary API enum 'address_family'.
+type AddressFamily uint32
+
+const (
+ ADDRESS_IP4 AddressFamily = 0
+ ADDRESS_IP6 AddressFamily = 1
+)
+
+var (
+ AddressFamily_name = map[uint32]string{
+ 0: "ADDRESS_IP4",
+ 1: "ADDRESS_IP6",
+ }
+ AddressFamily_value = map[string]uint32{
+ "ADDRESS_IP4": 0,
+ "ADDRESS_IP6": 1,
+ }
+)
+
+func (x AddressFamily) String() string {
+ s, ok := AddressFamily_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "AddressFamily(" + strconv.Itoa(int(x)) + ")"
+}
+
+// FibPathFlags represents VPP binary API enum 'fib_path_flags'.
+type FibPathFlags uint32
+
+const (
+ FIB_API_PATH_FLAG_NONE FibPathFlags = 0
+ FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED FibPathFlags = 1
+ FIB_API_PATH_FLAG_RESOLVE_VIA_HOST FibPathFlags = 2
+ FIB_API_PATH_FLAG_POP_PW_CW FibPathFlags = 4
+)
+
+var (
+ FibPathFlags_name = map[uint32]string{
+ 0: "FIB_API_PATH_FLAG_NONE",
+ 1: "FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED",
+ 2: "FIB_API_PATH_FLAG_RESOLVE_VIA_HOST",
+ 4: "FIB_API_PATH_FLAG_POP_PW_CW",
+ }
+ FibPathFlags_value = map[string]uint32{
+ "FIB_API_PATH_FLAG_NONE": 0,
+ "FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED": 1,
+ "FIB_API_PATH_FLAG_RESOLVE_VIA_HOST": 2,
+ "FIB_API_PATH_FLAG_POP_PW_CW": 4,
+ }
+)
+
+func (x FibPathFlags) String() string {
+ s, ok := FibPathFlags_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "FibPathFlags(" + strconv.Itoa(int(x)) + ")"
+}
+
+// FibPathNhProto represents VPP binary API enum 'fib_path_nh_proto'.
+type FibPathNhProto uint32
+
+const (
+ FIB_API_PATH_NH_PROTO_IP4 FibPathNhProto = 0
+ FIB_API_PATH_NH_PROTO_IP6 FibPathNhProto = 1
+ FIB_API_PATH_NH_PROTO_MPLS FibPathNhProto = 2
+ FIB_API_PATH_NH_PROTO_ETHERNET FibPathNhProto = 3
+ FIB_API_PATH_NH_PROTO_BIER FibPathNhProto = 4
+)
+
+var (
+ FibPathNhProto_name = map[uint32]string{
+ 0: "FIB_API_PATH_NH_PROTO_IP4",
+ 1: "FIB_API_PATH_NH_PROTO_IP6",
+ 2: "FIB_API_PATH_NH_PROTO_MPLS",
+ 3: "FIB_API_PATH_NH_PROTO_ETHERNET",
+ 4: "FIB_API_PATH_NH_PROTO_BIER",
+ }
+ FibPathNhProto_value = map[string]uint32{
+ "FIB_API_PATH_NH_PROTO_IP4": 0,
+ "FIB_API_PATH_NH_PROTO_IP6": 1,
+ "FIB_API_PATH_NH_PROTO_MPLS": 2,
+ "FIB_API_PATH_NH_PROTO_ETHERNET": 3,
+ "FIB_API_PATH_NH_PROTO_BIER": 4,
+ }
+)
+
+func (x FibPathNhProto) String() string {
+ s, ok := FibPathNhProto_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "FibPathNhProto(" + strconv.Itoa(int(x)) + ")"
+}
+
+// FibPathType represents VPP binary API enum 'fib_path_type'.
+type FibPathType uint32
+
+const (
+ FIB_API_PATH_TYPE_NORMAL FibPathType = 0
+ FIB_API_PATH_TYPE_LOCAL FibPathType = 1
+ FIB_API_PATH_TYPE_DROP FibPathType = 2
+ FIB_API_PATH_TYPE_UDP_ENCAP FibPathType = 3
+ FIB_API_PATH_TYPE_BIER_IMP FibPathType = 4
+ FIB_API_PATH_TYPE_ICMP_UNREACH FibPathType = 5
+ FIB_API_PATH_TYPE_ICMP_PROHIBIT FibPathType = 6
+ FIB_API_PATH_TYPE_SOURCE_LOOKUP FibPathType = 7
+ FIB_API_PATH_TYPE_DVR FibPathType = 8
+ FIB_API_PATH_TYPE_INTERFACE_RX FibPathType = 9
+ FIB_API_PATH_TYPE_CLASSIFY FibPathType = 10
+)
+
+var (
+ FibPathType_name = map[uint32]string{
+ 0: "FIB_API_PATH_TYPE_NORMAL",
+ 1: "FIB_API_PATH_TYPE_LOCAL",
+ 2: "FIB_API_PATH_TYPE_DROP",
+ 3: "FIB_API_PATH_TYPE_UDP_ENCAP",
+ 4: "FIB_API_PATH_TYPE_BIER_IMP",
+ 5: "FIB_API_PATH_TYPE_ICMP_UNREACH",
+ 6: "FIB_API_PATH_TYPE_ICMP_PROHIBIT",
+ 7: "FIB_API_PATH_TYPE_SOURCE_LOOKUP",
+ 8: "FIB_API_PATH_TYPE_DVR",
+ 9: "FIB_API_PATH_TYPE_INTERFACE_RX",
+ 10: "FIB_API_PATH_TYPE_CLASSIFY",
+ }
+ FibPathType_value = map[string]uint32{
+ "FIB_API_PATH_TYPE_NORMAL": 0,
+ "FIB_API_PATH_TYPE_LOCAL": 1,
+ "FIB_API_PATH_TYPE_DROP": 2,
+ "FIB_API_PATH_TYPE_UDP_ENCAP": 3,
+ "FIB_API_PATH_TYPE_BIER_IMP": 4,
+ "FIB_API_PATH_TYPE_ICMP_UNREACH": 5,
+ "FIB_API_PATH_TYPE_ICMP_PROHIBIT": 6,
+ "FIB_API_PATH_TYPE_SOURCE_LOOKUP": 7,
+ "FIB_API_PATH_TYPE_DVR": 8,
+ "FIB_API_PATH_TYPE_INTERFACE_RX": 9,
+ "FIB_API_PATH_TYPE_CLASSIFY": 10,
+ }
+)
+
+func (x FibPathType) String() string {
+ s, ok := FibPathType_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "FibPathType(" + strconv.Itoa(int(x)) + ")"
+}
+
+// IPDscp represents VPP binary API enum 'ip_dscp'.
+type IPDscp uint8
+
+const (
+ IP_API_DSCP_CS0 IPDscp = 0
+ IP_API_DSCP_CS1 IPDscp = 8
+ IP_API_DSCP_AF11 IPDscp = 10
+ IP_API_DSCP_AF12 IPDscp = 12
+ IP_API_DSCP_AF13 IPDscp = 14
+ IP_API_DSCP_CS2 IPDscp = 16
+ IP_API_DSCP_AF21 IPDscp = 18
+ IP_API_DSCP_AF22 IPDscp = 20
+ IP_API_DSCP_AF23 IPDscp = 22
+ IP_API_DSCP_CS3 IPDscp = 24
+ IP_API_DSCP_AF31 IPDscp = 26
+ IP_API_DSCP_AF32 IPDscp = 28
+ IP_API_DSCP_AF33 IPDscp = 30
+ IP_API_DSCP_CS4 IPDscp = 32
+ IP_API_DSCP_AF41 IPDscp = 34
+ IP_API_DSCP_AF42 IPDscp = 36
+ IP_API_DSCP_AF43 IPDscp = 38
+ IP_API_DSCP_CS5 IPDscp = 40
+ IP_API_DSCP_EF IPDscp = 46
+ IP_API_DSCP_CS6 IPDscp = 48
+ IP_API_DSCP_CS7 IPDscp = 50
+)
+
+var (
+ IPDscp_name = map[uint8]string{
+ 0: "IP_API_DSCP_CS0",
+ 8: "IP_API_DSCP_CS1",
+ 10: "IP_API_DSCP_AF11",
+ 12: "IP_API_DSCP_AF12",
+ 14: "IP_API_DSCP_AF13",
+ 16: "IP_API_DSCP_CS2",
+ 18: "IP_API_DSCP_AF21",
+ 20: "IP_API_DSCP_AF22",
+ 22: "IP_API_DSCP_AF23",
+ 24: "IP_API_DSCP_CS3",
+ 26: "IP_API_DSCP_AF31",
+ 28: "IP_API_DSCP_AF32",
+ 30: "IP_API_DSCP_AF33",
+ 32: "IP_API_DSCP_CS4",
+ 34: "IP_API_DSCP_AF41",
+ 36: "IP_API_DSCP_AF42",
+ 38: "IP_API_DSCP_AF43",
+ 40: "IP_API_DSCP_CS5",
+ 46: "IP_API_DSCP_EF",
+ 48: "IP_API_DSCP_CS6",
+ 50: "IP_API_DSCP_CS7",
+ }
+ IPDscp_value = map[string]uint8{
+ "IP_API_DSCP_CS0": 0,
+ "IP_API_DSCP_CS1": 8,
+ "IP_API_DSCP_AF11": 10,
+ "IP_API_DSCP_AF12": 12,
+ "IP_API_DSCP_AF13": 14,
+ "IP_API_DSCP_CS2": 16,
+ "IP_API_DSCP_AF21": 18,
+ "IP_API_DSCP_AF22": 20,
+ "IP_API_DSCP_AF23": 22,
+ "IP_API_DSCP_CS3": 24,
+ "IP_API_DSCP_AF31": 26,
+ "IP_API_DSCP_AF32": 28,
+ "IP_API_DSCP_AF33": 30,
+ "IP_API_DSCP_CS4": 32,
+ "IP_API_DSCP_AF41": 34,
+ "IP_API_DSCP_AF42": 36,
+ "IP_API_DSCP_AF43": 38,
+ "IP_API_DSCP_CS5": 40,
+ "IP_API_DSCP_EF": 46,
+ "IP_API_DSCP_CS6": 48,
+ "IP_API_DSCP_CS7": 50,
+ }
+)
+
+func (x IPDscp) String() string {
+ s, ok := IPDscp_name[uint8(x)]
+ if ok {
+ return s
+ }
+ return "IPDscp(" + strconv.Itoa(int(x)) + ")"
+}
+
+// IPEcn represents VPP binary API enum 'ip_ecn'.
+type IPEcn uint8
+
+const (
+ IP_API_ECN_NONE IPEcn = 0
+ IP_API_ECN_ECT0 IPEcn = 1
+ IP_API_ECN_ECT1 IPEcn = 2
+ IP_API_ECN_CE IPEcn = 3
+)
+
+var (
+ IPEcn_name = map[uint8]string{
+ 0: "IP_API_ECN_NONE",
+ 1: "IP_API_ECN_ECT0",
+ 2: "IP_API_ECN_ECT1",
+ 3: "IP_API_ECN_CE",
+ }
+ IPEcn_value = map[string]uint8{
+ "IP_API_ECN_NONE": 0,
+ "IP_API_ECN_ECT0": 1,
+ "IP_API_ECN_ECT1": 2,
+ "IP_API_ECN_CE": 3,
+ }
+)
+
+func (x IPEcn) String() string {
+ s, ok := IPEcn_name[uint8(x)]
+ if ok {
+ return s
+ }
+ return "IPEcn(" + strconv.Itoa(int(x)) + ")"
+}
+
+// IPProto represents VPP binary API enum 'ip_proto'.
+type IPProto uint32
+
+const (
+ IP_API_PROTO_HOPOPT IPProto = 0
+ IP_API_PROTO_ICMP IPProto = 1
+ IP_API_PROTO_IGMP IPProto = 2
+ IP_API_PROTO_TCP IPProto = 6
+ IP_API_PROTO_UDP IPProto = 17
+ IP_API_PROTO_GRE IPProto = 47
+ IP_API_PROTO_AH IPProto = 50
+ IP_API_PROTO_ESP IPProto = 51
+ IP_API_PROTO_EIGRP IPProto = 88
+ IP_API_PROTO_OSPF IPProto = 89
+ IP_API_PROTO_SCTP IPProto = 132
+ IP_API_PROTO_RESERVED IPProto = 255
+)
+
+var (
+ IPProto_name = map[uint32]string{
+ 0: "IP_API_PROTO_HOPOPT",
+ 1: "IP_API_PROTO_ICMP",
+ 2: "IP_API_PROTO_IGMP",
+ 6: "IP_API_PROTO_TCP",
+ 17: "IP_API_PROTO_UDP",
+ 47: "IP_API_PROTO_GRE",
+ 50: "IP_API_PROTO_AH",
+ 51: "IP_API_PROTO_ESP",
+ 88: "IP_API_PROTO_EIGRP",
+ 89: "IP_API_PROTO_OSPF",
+ 132: "IP_API_PROTO_SCTP",
+ 255: "IP_API_PROTO_RESERVED",
+ }
+ IPProto_value = map[string]uint32{
+ "IP_API_PROTO_HOPOPT": 0,
+ "IP_API_PROTO_ICMP": 1,
+ "IP_API_PROTO_IGMP": 2,
+ "IP_API_PROTO_TCP": 6,
+ "IP_API_PROTO_UDP": 17,
+ "IP_API_PROTO_GRE": 47,
+ "IP_API_PROTO_AH": 50,
+ "IP_API_PROTO_ESP": 51,
+ "IP_API_PROTO_EIGRP": 88,
+ "IP_API_PROTO_OSPF": 89,
+ "IP_API_PROTO_SCTP": 132,
+ "IP_API_PROTO_RESERVED": 255,
+ }
+)
+
+func (x IPProto) String() string {
+ s, ok := IPProto_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "IPProto(" + strconv.Itoa(int(x)) + ")"
+}
+
+// AddressWithPrefix represents VPP binary API alias 'address_with_prefix'.
+type AddressWithPrefix Prefix
+
+// IP4Address represents VPP binary API alias 'ip4_address'.
+type IP4Address [4]uint8
+
+// IP4AddressWithPrefix represents VPP binary API alias 'ip4_address_with_prefix'.
+type IP4AddressWithPrefix IP4Prefix
+
+// IP6Address represents VPP binary API alias 'ip6_address'.
+type IP6Address [16]uint8
+
+// IP6AddressWithPrefix represents VPP binary API alias 'ip6_address_with_prefix'.
+type IP6AddressWithPrefix IP6Prefix
+
+// Address represents VPP binary API type 'address'.
+type Address struct {
+ Af AddressFamily `binapi:"address_family,name=af" json:"af,omitempty"`
+ Un AddressUnion `binapi:"address_union,name=un" json:"un,omitempty"`
+}
+
+func (*Address) GetTypeName() string { return "address" }
+
+// FibMplsLabel represents VPP binary API type 'fib_mpls_label'.
+type FibMplsLabel struct {
+ IsUniform uint8 `binapi:"u8,name=is_uniform" json:"is_uniform,omitempty"`
+ Label uint32 `binapi:"u32,name=label" json:"label,omitempty"`
+ TTL uint8 `binapi:"u8,name=ttl" json:"ttl,omitempty"`
+ Exp uint8 `binapi:"u8,name=exp" json:"exp,omitempty"`
+}
+
+func (*FibMplsLabel) GetTypeName() string { return "fib_mpls_label" }
+
+// FibPath represents VPP binary API type 'fib_path'.
+type FibPath struct {
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
+ TableID uint32 `binapi:"u32,name=table_id" json:"table_id,omitempty"`
+ RpfID uint32 `binapi:"u32,name=rpf_id" json:"rpf_id,omitempty"`
+ Weight uint8 `binapi:"u8,name=weight" json:"weight,omitempty"`
+ Preference uint8 `binapi:"u8,name=preference" json:"preference,omitempty"`
+ Type FibPathType `binapi:"fib_path_type,name=type" json:"type,omitempty"`
+ Flags FibPathFlags `binapi:"fib_path_flags,name=flags" json:"flags,omitempty"`
+ Proto FibPathNhProto `binapi:"fib_path_nh_proto,name=proto" json:"proto,omitempty"`
+ Nh FibPathNh `binapi:"fib_path_nh,name=nh" json:"nh,omitempty"`
+ NLabels uint8 `binapi:"u8,name=n_labels" json:"n_labels,omitempty"`
+ LabelStack [16]FibMplsLabel `binapi:"fib_mpls_label[16],name=label_stack" json:"label_stack,omitempty" struc:"[16]FibMplsLabel"`
+}
+
+func (*FibPath) GetTypeName() string { return "fib_path" }
+
+// FibPathNh represents VPP binary API type 'fib_path_nh'.
+type FibPathNh struct {
+ Address AddressUnion `binapi:"address_union,name=address" json:"address,omitempty"`
+ ViaLabel uint32 `binapi:"u32,name=via_label" json:"via_label,omitempty"`
+ ObjID uint32 `binapi:"u32,name=obj_id" json:"obj_id,omitempty"`
+ ClassifyTableIndex uint32 `binapi:"u32,name=classify_table_index" json:"classify_table_index,omitempty"`
+}
+
+func (*FibPathNh) GetTypeName() string { return "fib_path_nh" }
+
+// IP4Prefix represents VPP binary API type 'ip4_prefix'.
+type IP4Prefix struct {
+ Address IP4Address `binapi:"ip4_address,name=address" json:"address,omitempty"`
+ Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
+}
+
+func (*IP4Prefix) GetTypeName() string { return "ip4_prefix" }
+
+// IP6Prefix represents VPP binary API type 'ip6_prefix'.
+type IP6Prefix struct {
+ Address IP6Address `binapi:"ip6_address,name=address" json:"address,omitempty"`
+ Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
+}
+
+func (*IP6Prefix) GetTypeName() string { return "ip6_prefix" }
+
+// Mprefix represents VPP binary API type 'mprefix'.
+type Mprefix struct {
+ Af AddressFamily `binapi:"address_family,name=af" json:"af,omitempty"`
+ GrpAddressLength uint16 `binapi:"u16,name=grp_address_length" json:"grp_address_length,omitempty"`
+ GrpAddress AddressUnion `binapi:"address_union,name=grp_address" json:"grp_address,omitempty"`
+ SrcAddress AddressUnion `binapi:"address_union,name=src_address" json:"src_address,omitempty"`
+}
+
+func (*Mprefix) GetTypeName() string { return "mprefix" }
+
+// Prefix represents VPP binary API type 'prefix'.
+type Prefix struct {
+ Address Address `binapi:"address,name=address" json:"address,omitempty"`
+ Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
+}
+
+func (*Prefix) GetTypeName() string { return "prefix" }
+
+// PrefixMatcher represents VPP binary API type 'prefix_matcher'.
+type PrefixMatcher struct {
+ Le uint8 `binapi:"u8,name=le" json:"le,omitempty"`
+ Ge uint8 `binapi:"u8,name=ge" json:"ge,omitempty"`
+}
+
+func (*PrefixMatcher) GetTypeName() string { return "prefix_matcher" }
+
+// AddressUnion represents VPP binary API union 'address_union'.
+type AddressUnion struct {
+ XXX_UnionData [16]byte
+}
+
+func (*AddressUnion) GetTypeName() string { return "address_union" }
+
+func AddressUnionIP4(a IP4Address) (u AddressUnion) {
+ u.SetIP4(a)
+ return
+}
+func (u *AddressUnion) SetIP4(a IP4Address) {
+ var b = new(bytes.Buffer)
+ if err := struc.Pack(b, &a); err != nil {
+ return
+ }
+ copy(u.XXX_UnionData[:], b.Bytes())
+}
+func (u *AddressUnion) GetIP4() (a IP4Address) {
+ var b = bytes.NewReader(u.XXX_UnionData[:])
+ struc.Unpack(b, &a)
+ return
+}
+
+func AddressUnionIP6(a IP6Address) (u AddressUnion) {
+ u.SetIP6(a)
+ return
+}
+func (u *AddressUnion) SetIP6(a IP6Address) {
+ var b = new(bytes.Buffer)
+ if err := struc.Pack(b, &a); err != nil {
+ return
+ }
+ copy(u.XXX_UnionData[:], b.Bytes())
+}
+func (u *AddressUnion) GetIP6() (a IP6Address) {
+ var b = bytes.NewReader(u.XXX_UnionData[:])
+ struc.Unpack(b, &a)
+ return
+}
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ = api.RegisterMessage
+var _ = codec.DecodeString
+var _ = bytes.NewBuffer
+var _ = context.Background
+var _ = io.Copy
+var _ = strconv.Itoa
+var _ = struc.Pack
+var _ = binary.BigEndian
+var _ = math.Float32bits
diff --git a/examples/binapi/gen.go b/examples/binapi/gen.go
index 7c2030c..a19ca34 100644
--- a/examples/binapi/gen.go
+++ b/examples/binapi/gen.go
@@ -2,19 +2,4 @@ package binapi
// Generate Go code from the VPP APIs located in the /usr/share/vpp/api directory.
-//go:generate binapi-generator --output-dir=. --input-file=/usr/share/vpp/api/core/ethernet_types.api.json
-//go:generate binapi-generator --output-dir=. --input-file=/usr/share/vpp/api/core/interface_types.api.json
-//go:generate binapi-generator --output-dir=. --input-file=/usr/share/vpp/api/core/ip_types.api.json
-//go:generate binapi-generator --output-dir=. --input-file=/usr/share/vpp/api/core/vpe_types.api.json
-
-//go:generate -command binapigen binapi-generator --output-dir=. --import-prefix=git.fd.io/govpp.git/examples/binapi --input-types=/usr/share/vpp/api/core/ethernet_types.api.json,/usr/share/vpp/api/core/ip_types.api.json,/usr/share/vpp/api/core/interface_types.api.json,/usr/share/vpp/api/core/vpe_types.api.json
-
-//go:generate binapigen --input-file=/usr/share/vpp/api/core/af_packet.api.json
-//go:generate binapigen --input-file=/usr/share/vpp/api/core/interface.api.json
-//go:generate binapigen --input-file=/usr/share/vpp/api/core/ip.api.json
-//go:generate binapigen --input-file=/usr/share/vpp/api/core/memclnt.api.json
-//go:generate binapigen --input-file=/usr/share/vpp/api/core/vpe.api.json
-//go:generate binapigen --input-file=/usr/share/vpp/api/plugins/memif.api.json
-
-// VPP version
-///go:generate sh -c "dpkg-query -f '$DOLLAR{Version}' -W vpp > VPP_VERSION"
+//go:generate binapi-generator --import-prefix=git.fd.io/govpp.git/examples/binapi af_packet interface ip memclnt vpe sr acl memif ip_types fib_types
diff --git a/examples/binapi/interface_types/interface_types.ba.go b/examples/binapi/interface_types/interface_types.ba.go
deleted file mode 100644
index a9a34d1..0000000
--- a/examples/binapi/interface_types/interface_types.ba.go
+++ /dev/null
@@ -1,252 +0,0 @@
-// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
-// source: /usr/share/vpp/api/core/interface_types.api.json
-
-/*
-Package interface_types is a generated VPP binary API for 'interface_types' module.
-
-It consists of:
- 6 enums
- 1 alias
-*/
-package interface_types
-
-import (
- "bytes"
- "context"
- "io"
- "strconv"
-
- api "git.fd.io/govpp.git/api"
- struc "github.com/lunixbochs/struc"
-)
-
-const (
- // ModuleName is the name of this module.
- ModuleName = "interface_types"
- // VersionCrc is the CRC of this module.
- VersionCrc = 0xc97be83d
-)
-
-// IfStatusFlags represents VPP binary API enum 'if_status_flags'.
-type IfStatusFlags uint32
-
-const (
- IF_STATUS_API_FLAG_ADMIN_UP IfStatusFlags = 1
- IF_STATUS_API_FLAG_LINK_UP IfStatusFlags = 2
-)
-
-var IfStatusFlags_name = map[uint32]string{
- 1: "IF_STATUS_API_FLAG_ADMIN_UP",
- 2: "IF_STATUS_API_FLAG_LINK_UP",
-}
-
-var IfStatusFlags_value = map[string]uint32{
- "IF_STATUS_API_FLAG_ADMIN_UP": 1,
- "IF_STATUS_API_FLAG_LINK_UP": 2,
-}
-
-func (x IfStatusFlags) String() string {
- s, ok := IfStatusFlags_name[uint32(x)]
- if ok {
- return s
- }
- return strconv.Itoa(int(x))
-}
-
-// IfType represents VPP binary API enum 'if_type'.
-type IfType uint32
-
-const (
- IF_API_TYPE_HARDWARE IfType = 1
- IF_API_TYPE_SUB IfType = 2
- IF_API_TYPE_P2P IfType = 3
- IF_API_TYPE_PIPE IfType = 4
-)
-
-var IfType_name = map[uint32]string{
- 1: "IF_API_TYPE_HARDWARE",
- 2: "IF_API_TYPE_SUB",
- 3: "IF_API_TYPE_P2P",
- 4: "IF_API_TYPE_PIPE",
-}
-
-var IfType_value = map[string]uint32{
- "IF_API_TYPE_HARDWARE": 1,
- "IF_API_TYPE_SUB": 2,
- "IF_API_TYPE_P2P": 3,
- "IF_API_TYPE_PIPE": 4,
-}
-
-func (x IfType) String() string {
- s, ok := IfType_name[uint32(x)]
- if ok {
- return s
- }
- return strconv.Itoa(int(x))
-}
-
-// LinkDuplex represents VPP binary API enum 'link_duplex'.
-type LinkDuplex uint32
-
-const (
- LINK_DUPLEX_API_UNKNOWN LinkDuplex = 0
- LINK_DUPLEX_API_HALF LinkDuplex = 1
- LINK_DUPLEX_API_FULL LinkDuplex = 2
-)
-
-var LinkDuplex_name = map[uint32]string{
- 0: "LINK_DUPLEX_API_UNKNOWN",
- 1: "LINK_DUPLEX_API_HALF",
- 2: "LINK_DUPLEX_API_FULL",
-}
-
-var LinkDuplex_value = map[string]uint32{
- "LINK_DUPLEX_API_UNKNOWN": 0,
- "LINK_DUPLEX_API_HALF": 1,
- "LINK_DUPLEX_API_FULL": 2,
-}
-
-func (x LinkDuplex) String() string {
- s, ok := LinkDuplex_name[uint32(x)]
- if ok {
- return s
- }
- return strconv.Itoa(int(x))
-}
-
-// MtuProto represents VPP binary API enum 'mtu_proto'.
-type MtuProto uint32
-
-const (
- MTU_PROTO_API_L3 MtuProto = 1
- MTU_PROTO_API_IP4 MtuProto = 2
- MTU_PROTO_API_IP6 MtuProto = 3
- MTU_PROTO_API_MPLS MtuProto = 4
- MTU_PROTO_API_N MtuProto = 5
-)
-
-var MtuProto_name = map[uint32]string{
- 1: "MTU_PROTO_API_L3",
- 2: "MTU_PROTO_API_IP4",
- 3: "MTU_PROTO_API_IP6",
- 4: "MTU_PROTO_API_MPLS",
- 5: "MTU_PROTO_API_N",
-}
-
-var MtuProto_value = map[string]uint32{
- "MTU_PROTO_API_L3": 1,
- "MTU_PROTO_API_IP4": 2,
- "MTU_PROTO_API_IP6": 3,
- "MTU_PROTO_API_MPLS": 4,
- "MTU_PROTO_API_N": 5,
-}
-
-func (x MtuProto) String() string {
- s, ok := MtuProto_name[uint32(x)]
- if ok {
- return s
- }
- return strconv.Itoa(int(x))
-}
-
-// RxMode represents VPP binary API enum 'rx_mode'.
-type RxMode uint32
-
-const (
- RX_MODE_API_UNKNOWN RxMode = 0
- RX_MODE_API_POLLING RxMode = 1
- RX_MODE_API_INTERRUPT RxMode = 2
- RX_MODE_API_ADAPTIVE RxMode = 3
- RX_MODE_API_DEFAULT RxMode = 4
-)
-
-var RxMode_name = map[uint32]string{
- 0: "RX_MODE_API_UNKNOWN",
- 1: "RX_MODE_API_POLLING",
- 2: "RX_MODE_API_INTERRUPT",
- 3: "RX_MODE_API_ADAPTIVE",
- 4: "RX_MODE_API_DEFAULT",
-}
-
-var RxMode_value = map[string]uint32{
- "RX_MODE_API_UNKNOWN": 0,
- "RX_MODE_API_POLLING": 1,
- "RX_MODE_API_INTERRUPT": 2,
- "RX_MODE_API_ADAPTIVE": 3,
- "RX_MODE_API_DEFAULT": 4,
-}
-
-func (x RxMode) String() string {
- s, ok := RxMode_name[uint32(x)]
- if ok {
- return s
- }
- return strconv.Itoa(int(x))
-}
-
-// SubIfFlags represents VPP binary API enum 'sub_if_flags'.
-type SubIfFlags uint32
-
-const (
- SUB_IF_API_FLAG_NO_TAGS SubIfFlags = 1
- SUB_IF_API_FLAG_ONE_TAG SubIfFlags = 2
- SUB_IF_API_FLAG_TWO_TAGS SubIfFlags = 4
- SUB_IF_API_FLAG_DOT1AD SubIfFlags = 8
- SUB_IF_API_FLAG_EXACT_MATCH SubIfFlags = 16
- SUB_IF_API_FLAG_DEFAULT SubIfFlags = 32
- SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY SubIfFlags = 64
- SUB_IF_API_FLAG_INNER_VLAN_ID_ANY SubIfFlags = 128
- SUB_IF_API_FLAG_MASK_VNET SubIfFlags = 254
- SUB_IF_API_FLAG_DOT1AH SubIfFlags = 256
-)
-
-var SubIfFlags_name = map[uint32]string{
- 1: "SUB_IF_API_FLAG_NO_TAGS",
- 2: "SUB_IF_API_FLAG_ONE_TAG",
- 4: "SUB_IF_API_FLAG_TWO_TAGS",
- 8: "SUB_IF_API_FLAG_DOT1AD",
- 16: "SUB_IF_API_FLAG_EXACT_MATCH",
- 32: "SUB_IF_API_FLAG_DEFAULT",
- 64: "SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY",
- 128: "SUB_IF_API_FLAG_INNER_VLAN_ID_ANY",
- 254: "SUB_IF_API_FLAG_MASK_VNET",
- 256: "SUB_IF_API_FLAG_DOT1AH",
-}
-
-var SubIfFlags_value = map[string]uint32{
- "SUB_IF_API_FLAG_NO_TAGS": 1,
- "SUB_IF_API_FLAG_ONE_TAG": 2,
- "SUB_IF_API_FLAG_TWO_TAGS": 4,
- "SUB_IF_API_FLAG_DOT1AD": 8,
- "SUB_IF_API_FLAG_EXACT_MATCH": 16,
- "SUB_IF_API_FLAG_DEFAULT": 32,
- "SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY": 64,
- "SUB_IF_API_FLAG_INNER_VLAN_ID_ANY": 128,
- "SUB_IF_API_FLAG_MASK_VNET": 254,
- "SUB_IF_API_FLAG_DOT1AH": 256,
-}
-
-func (x SubIfFlags) String() string {
- s, ok := SubIfFlags_name[uint32(x)]
- if ok {
- return s
- }
- return strconv.Itoa(int(x))
-}
-
-// InterfaceIndex represents VPP binary API alias 'interface_index'.
-type InterfaceIndex uint32
-
-// 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.GoVppAPIPackageIsVersion1 // please upgrade the GoVPP api package
-
-// Reference imports to suppress errors if they are not otherwise used.
-var _ = api.RegisterMessage
-var _ = bytes.NewBuffer
-var _ = context.Background
-var _ = io.Copy
-var _ = strconv.Itoa
-var _ = struc.Pack
diff --git a/examples/binapi/interfaces/interfaces.ba.go b/examples/binapi/interfaces/interfaces.ba.go
index 7d4031f..82e8f3c 100644
--- a/examples/binapi/interfaces/interfaces.ba.go
+++ b/examples/binapi/interfaces/interfaces.ba.go
@@ -1,33 +1,40 @@
// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+// versions:
+// binapi-generator: v0.4.0-alpha-1-g435c3f4-dirty
+// VPP: 20.01-45~g7a071e370~b63
// source: /usr/share/vpp/api/core/interface.api.json
/*
-Package interfaces is a generated VPP binary API for 'interface' module.
+Package interfaces contains generated code for VPP binary API defined by interface.api (version 3.2.2).
It consists of:
- 10 enums
7 aliases
+ 10 enums
+ 53 messages
6 types
1 union
- 53 messages
- 26 services
*/
package interfaces
import (
"bytes"
"context"
+ "encoding/binary"
"io"
+ "math"
"strconv"
api "git.fd.io/govpp.git/api"
+ codec "git.fd.io/govpp.git/codec"
struc "github.com/lunixbochs/struc"
-
- ethernet_types "git.fd.io/govpp.git/examples/binapi/ethernet_types"
- interface_types "git.fd.io/govpp.git/examples/binapi/interface_types"
- ip_types "git.fd.io/govpp.git/examples/binapi/ip_types"
)
+// 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 // please upgrade the GoVPP api package
+
const (
// ModuleName is the name of this module.
ModuleName = "interface"
@@ -37,58 +44,536 @@ const (
VersionCrc = 0xfebc3ffa
)
-type AddressFamily = ip_types.AddressFamily
+// AddressFamily represents VPP binary API enum 'address_family'.
+type AddressFamily uint32
+
+const (
+ ADDRESS_IP4 AddressFamily = 0
+ ADDRESS_IP6 AddressFamily = 1
+)
+
+var (
+ AddressFamily_name = map[uint32]string{
+ 0: "ADDRESS_IP4",
+ 1: "ADDRESS_IP6",
+ }
+ AddressFamily_value = map[string]uint32{
+ "ADDRESS_IP4": 0,
+ "ADDRESS_IP6": 1,
+ }
+)
+
+func (x AddressFamily) String() string {
+ s, ok := AddressFamily_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "AddressFamily(" + strconv.Itoa(int(x)) + ")"
+}
+
+// IfStatusFlags represents VPP binary API enum 'if_status_flags'.
+type IfStatusFlags uint32
+
+const (
+ IF_STATUS_API_FLAG_ADMIN_UP IfStatusFlags = 1
+ IF_STATUS_API_FLAG_LINK_UP IfStatusFlags = 2
+)
+
+var (
+ IfStatusFlags_name = map[uint32]string{
+ 1: "IF_STATUS_API_FLAG_ADMIN_UP",
+ 2: "IF_STATUS_API_FLAG_LINK_UP",
+ }
+ IfStatusFlags_value = map[string]uint32{
+ "IF_STATUS_API_FLAG_ADMIN_UP": 1,
+ "IF_STATUS_API_FLAG_LINK_UP": 2,
+ }
+)
+
+func (x IfStatusFlags) String() string {
+ s, ok := IfStatusFlags_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "IfStatusFlags(" + strconv.Itoa(int(x)) + ")"
+}
+
+// IfType represents VPP binary API enum 'if_type'.
+type IfType uint32
+
+const (
+ IF_API_TYPE_HARDWARE IfType = 1
+ IF_API_TYPE_SUB IfType = 2
+ IF_API_TYPE_P2P IfType = 3
+ IF_API_TYPE_PIPE IfType = 4
+)
+
+var (
+ IfType_name = map[uint32]string{
+ 1: "IF_API_TYPE_HARDWARE",
+ 2: "IF_API_TYPE_SUB",
+ 3: "IF_API_TYPE_P2P",
+ 4: "IF_API_TYPE_PIPE",
+ }
+ IfType_value = map[string]uint32{
+ "IF_API_TYPE_HARDWARE": 1,
+ "IF_API_TYPE_SUB": 2,
+ "IF_API_TYPE_P2P": 3,
+ "IF_API_TYPE_PIPE": 4,
+ }
+)
+
+func (x IfType) String() string {
+ s, ok := IfType_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "IfType(" + strconv.Itoa(int(x)) + ")"
+}
+
+// IPDscp represents VPP binary API enum 'ip_dscp'.
+type IPDscp uint8
+
+const (
+ IP_API_DSCP_CS0 IPDscp = 0
+ IP_API_DSCP_CS1 IPDscp = 8
+ IP_API_DSCP_AF11 IPDscp = 10
+ IP_API_DSCP_AF12 IPDscp = 12
+ IP_API_DSCP_AF13 IPDscp = 14
+ IP_API_DSCP_CS2 IPDscp = 16
+ IP_API_DSCP_AF21 IPDscp = 18
+ IP_API_DSCP_AF22 IPDscp = 20
+ IP_API_DSCP_AF23 IPDscp = 22
+ IP_API_DSCP_CS3 IPDscp = 24
+ IP_API_DSCP_AF31 IPDscp = 26
+ IP_API_DSCP_AF32 IPDscp = 28
+ IP_API_DSCP_AF33 IPDscp = 30
+ IP_API_DSCP_CS4 IPDscp = 32
+ IP_API_DSCP_AF41 IPDscp = 34
+ IP_API_DSCP_AF42 IPDscp = 36
+ IP_API_DSCP_AF43 IPDscp = 38
+ IP_API_DSCP_CS5 IPDscp = 40
+ IP_API_DSCP_EF IPDscp = 46
+ IP_API_DSCP_CS6 IPDscp = 48
+ IP_API_DSCP_CS7 IPDscp = 50
+)
+
+var (
+ IPDscp_name = map[uint8]string{
+ 0: "IP_API_DSCP_CS0",
+ 8: "IP_API_DSCP_CS1",
+ 10: "IP_API_DSCP_AF11",
+ 12: "IP_API_DSCP_AF12",
+ 14: "IP_API_DSCP_AF13",
+ 16: "IP_API_DSCP_CS2",
+ 18: "IP_API_DSCP_AF21",
+ 20: "IP_API_DSCP_AF22",
+ 22: "IP_API_DSCP_AF23",
+ 24: "IP_API_DSCP_CS3",
+ 26: "IP_API_DSCP_AF31",
+ 28: "IP_API_DSCP_AF32",
+ 30: "IP_API_DSCP_AF33",
+ 32: "IP_API_DSCP_CS4",
+ 34: "IP_API_DSCP_AF41",
+ 36: "IP_API_DSCP_AF42",
+ 38: "IP_API_DSCP_AF43",
+ 40: "IP_API_DSCP_CS5",
+ 46: "IP_API_DSCP_EF",
+ 48: "IP_API_DSCP_CS6",
+ 50: "IP_API_DSCP_CS7",
+ }
+ IPDscp_value = map[string]uint8{
+ "IP_API_DSCP_CS0": 0,
+ "IP_API_DSCP_CS1": 8,
+ "IP_API_DSCP_AF11": 10,
+ "IP_API_DSCP_AF12": 12,
+ "IP_API_DSCP_AF13": 14,
+ "IP_API_DSCP_CS2": 16,
+ "IP_API_DSCP_AF21": 18,
+ "IP_API_DSCP_AF22": 20,
+ "IP_API_DSCP_AF23": 22,
+ "IP_API_DSCP_CS3": 24,
+ "IP_API_DSCP_AF31": 26,
+ "IP_API_DSCP_AF32": 28,
+ "IP_API_DSCP_AF33": 30,
+ "IP_API_DSCP_CS4": 32,
+ "IP_API_DSCP_AF41": 34,
+ "IP_API_DSCP_AF42": 36,
+ "IP_API_DSCP_AF43": 38,
+ "IP_API_DSCP_CS5": 40,
+ "IP_API_DSCP_EF": 46,
+ "IP_API_DSCP_CS6": 48,
+ "IP_API_DSCP_CS7": 50,
+ }
+)
+
+func (x IPDscp) String() string {
+ s, ok := IPDscp_name[uint8(x)]
+ if ok {
+ return s
+ }
+ return "IPDscp(" + strconv.Itoa(int(x)) + ")"
+}
+
+// IPEcn represents VPP binary API enum 'ip_ecn'.
+type IPEcn uint8
+
+const (
+ IP_API_ECN_NONE IPEcn = 0
+ IP_API_ECN_ECT0 IPEcn = 1
+ IP_API_ECN_ECT1 IPEcn = 2
+ IP_API_ECN_CE IPEcn = 3
+)
+
+var (
+ IPEcn_name = map[uint8]string{
+ 0: "IP_API_ECN_NONE",
+ 1: "IP_API_ECN_ECT0",
+ 2: "IP_API_ECN_ECT1",
+ 3: "IP_API_ECN_CE",
+ }
+ IPEcn_value = map[string]uint8{
+ "IP_API_ECN_NONE": 0,
+ "IP_API_ECN_ECT0": 1,
+ "IP_API_ECN_ECT1": 2,
+ "IP_API_ECN_CE": 3,
+ }
+)
+
+func (x IPEcn) String() string {
+ s, ok := IPEcn_name[uint8(x)]
+ if ok {
+ return s
+ }
+ return "IPEcn(" + strconv.Itoa(int(x)) + ")"
+}
-type IfStatusFlags = interface_types.IfStatusFlags
+// IPProto represents VPP binary API enum 'ip_proto'.
+type IPProto uint32
-type IfType = interface_types.IfType
+const (
+ IP_API_PROTO_HOPOPT IPProto = 0
+ IP_API_PROTO_ICMP IPProto = 1
+ IP_API_PROTO_IGMP IPProto = 2
+ IP_API_PROTO_TCP IPProto = 6
+ IP_API_PROTO_UDP IPProto = 17
+ IP_API_PROTO_GRE IPProto = 47
+ IP_API_PROTO_AH IPProto = 50
+ IP_API_PROTO_ESP IPProto = 51
+ IP_API_PROTO_EIGRP IPProto = 88
+ IP_API_PROTO_OSPF IPProto = 89
+ IP_API_PROTO_SCTP IPProto = 132
+ IP_API_PROTO_RESERVED IPProto = 255
+)
-type IPDscp = ip_types.IPDscp
+var (
+ IPProto_name = map[uint32]string{
+ 0: "IP_API_PROTO_HOPOPT",
+ 1: "IP_API_PROTO_ICMP",
+ 2: "IP_API_PROTO_IGMP",
+ 6: "IP_API_PROTO_TCP",
+ 17: "IP_API_PROTO_UDP",
+ 47: "IP_API_PROTO_GRE",
+ 50: "IP_API_PROTO_AH",
+ 51: "IP_API_PROTO_ESP",
+ 88: "IP_API_PROTO_EIGRP",
+ 89: "IP_API_PROTO_OSPF",
+ 132: "IP_API_PROTO_SCTP",
+ 255: "IP_API_PROTO_RESERVED",
+ }
+ IPProto_value = map[string]uint32{
+ "IP_API_PROTO_HOPOPT": 0,
+ "IP_API_PROTO_ICMP": 1,
+ "IP_API_PROTO_IGMP": 2,
+ "IP_API_PROTO_TCP": 6,
+ "IP_API_PROTO_UDP": 17,
+ "IP_API_PROTO_GRE": 47,
+ "IP_API_PROTO_AH": 50,
+ "IP_API_PROTO_ESP": 51,
+ "IP_API_PROTO_EIGRP": 88,
+ "IP_API_PROTO_OSPF": 89,
+ "IP_API_PROTO_SCTP": 132,
+ "IP_API_PROTO_RESERVED": 255,
+ }
+)
-type IPEcn = ip_types.IPEcn
+func (x IPProto) String() string {
+ s, ok := IPProto_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "IPProto(" + strconv.Itoa(int(x)) + ")"
+}
-type IPProto = ip_types.IPProto
+// LinkDuplex represents VPP binary API enum 'link_duplex'.
+type LinkDuplex uint32
-type LinkDuplex = interface_types.LinkDuplex
+const (
+ LINK_DUPLEX_API_UNKNOWN LinkDuplex = 0
+ LINK_DUPLEX_API_HALF LinkDuplex = 1
+ LINK_DUPLEX_API_FULL LinkDuplex = 2
+)
-type MtuProto = interface_types.MtuProto
+var (
+ LinkDuplex_name = map[uint32]string{
+ 0: "LINK_DUPLEX_API_UNKNOWN",
+ 1: "LINK_DUPLEX_API_HALF",
+ 2: "LINK_DUPLEX_API_FULL",
+ }
+ LinkDuplex_value = map[string]uint32{
+ "LINK_DUPLEX_API_UNKNOWN": 0,
+ "LINK_DUPLEX_API_HALF": 1,
+ "LINK_DUPLEX_API_FULL": 2,
+ }
+)
-type RxMode = interface_types.RxMode
+func (x LinkDuplex) String() string {
+ s, ok := LinkDuplex_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "LinkDuplex(" + strconv.Itoa(int(x)) + ")"
+}
-type SubIfFlags = interface_types.SubIfFlags
+// MtuProto represents VPP binary API enum 'mtu_proto'.
+type MtuProto uint32
-type AddressWithPrefix = ip_types.AddressWithPrefix
+const (
+ MTU_PROTO_API_L3 MtuProto = 1
+ MTU_PROTO_API_IP4 MtuProto = 2
+ MTU_PROTO_API_IP6 MtuProto = 3
+ MTU_PROTO_API_MPLS MtuProto = 4
+ MTU_PROTO_API_N MtuProto = 5
+)
-type InterfaceIndex = interface_types.InterfaceIndex
+var (
+ MtuProto_name = map[uint32]string{
+ 1: "MTU_PROTO_API_L3",
+ 2: "MTU_PROTO_API_IP4",
+ 3: "MTU_PROTO_API_IP6",
+ 4: "MTU_PROTO_API_MPLS",
+ 5: "MTU_PROTO_API_N",
+ }
+ MtuProto_value = map[string]uint32{
+ "MTU_PROTO_API_L3": 1,
+ "MTU_PROTO_API_IP4": 2,
+ "MTU_PROTO_API_IP6": 3,
+ "MTU_PROTO_API_MPLS": 4,
+ "MTU_PROTO_API_N": 5,
+ }
+)
-type IP4Address = ip_types.IP4Address
+func (x MtuProto) String() string {
+ s, ok := MtuProto_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "MtuProto(" + strconv.Itoa(int(x)) + ")"
+}
-type IP4AddressWithPrefix = ip_types.IP4AddressWithPrefix
+// RxMode represents VPP binary API enum 'rx_mode'.
+type RxMode uint32
-type IP6Address = ip_types.IP6Address
+const (
+ RX_MODE_API_UNKNOWN RxMode = 0
+ RX_MODE_API_POLLING RxMode = 1
+ RX_MODE_API_INTERRUPT RxMode = 2
+ RX_MODE_API_ADAPTIVE RxMode = 3
+ RX_MODE_API_DEFAULT RxMode = 4
+)
-type IP6AddressWithPrefix = ip_types.IP6AddressWithPrefix
+var (
+ RxMode_name = map[uint32]string{
+ 0: "RX_MODE_API_UNKNOWN",
+ 1: "RX_MODE_API_POLLING",
+ 2: "RX_MODE_API_INTERRUPT",
+ 3: "RX_MODE_API_ADAPTIVE",
+ 4: "RX_MODE_API_DEFAULT",
+ }
+ RxMode_value = map[string]uint32{
+ "RX_MODE_API_UNKNOWN": 0,
+ "RX_MODE_API_POLLING": 1,
+ "RX_MODE_API_INTERRUPT": 2,
+ "RX_MODE_API_ADAPTIVE": 3,
+ "RX_MODE_API_DEFAULT": 4,
+ }
+)
-type MacAddress = ethernet_types.MacAddress
+func (x RxMode) String() string {
+ s, ok := RxMode_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "RxMode(" + strconv.Itoa(int(x)) + ")"
+}
-type Address = ip_types.Address
+// SubIfFlags represents VPP binary API enum 'sub_if_flags'.
+type SubIfFlags uint32
-type IP4Prefix = ip_types.IP4Prefix
+const (
+ SUB_IF_API_FLAG_NO_TAGS SubIfFlags = 1
+ SUB_IF_API_FLAG_ONE_TAG SubIfFlags = 2
+ SUB_IF_API_FLAG_TWO_TAGS SubIfFlags = 4
+ SUB_IF_API_FLAG_DOT1AD SubIfFlags = 8
+ SUB_IF_API_FLAG_EXACT_MATCH SubIfFlags = 16
+ SUB_IF_API_FLAG_DEFAULT SubIfFlags = 32
+ SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY SubIfFlags = 64
+ SUB_IF_API_FLAG_INNER_VLAN_ID_ANY SubIfFlags = 128
+ SUB_IF_API_FLAG_MASK_VNET SubIfFlags = 254
+ SUB_IF_API_FLAG_DOT1AH SubIfFlags = 256
+)
+
+var (
+ SubIfFlags_name = map[uint32]string{
+ 1: "SUB_IF_API_FLAG_NO_TAGS",
+ 2: "SUB_IF_API_FLAG_ONE_TAG",
+ 4: "SUB_IF_API_FLAG_TWO_TAGS",
+ 8: "SUB_IF_API_FLAG_DOT1AD",
+ 16: "SUB_IF_API_FLAG_EXACT_MATCH",
+ 32: "SUB_IF_API_FLAG_DEFAULT",
+ 64: "SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY",
+ 128: "SUB_IF_API_FLAG_INNER_VLAN_ID_ANY",
+ 254: "SUB_IF_API_FLAG_MASK_VNET",
+ 256: "SUB_IF_API_FLAG_DOT1AH",
+ }
+ SubIfFlags_value = map[string]uint32{
+ "SUB_IF_API_FLAG_NO_TAGS": 1,
+ "SUB_IF_API_FLAG_ONE_TAG": 2,
+ "SUB_IF_API_FLAG_TWO_TAGS": 4,
+ "SUB_IF_API_FLAG_DOT1AD": 8,
+ "SUB_IF_API_FLAG_EXACT_MATCH": 16,
+ "SUB_IF_API_FLAG_DEFAULT": 32,
+ "SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY": 64,
+ "SUB_IF_API_FLAG_INNER_VLAN_ID_ANY": 128,
+ "SUB_IF_API_FLAG_MASK_VNET": 254,
+ "SUB_IF_API_FLAG_DOT1AH": 256,
+ }
+)
+
+func (x SubIfFlags) String() string {
+ s, ok := SubIfFlags_name[uint32(x)]
+ if ok {
+ return s
+ }
+ return "SubIfFlags(" + strconv.Itoa(int(x)) + ")"
+}
+
+// AddressWithPrefix represents VPP binary API alias 'address_with_prefix'.
+type AddressWithPrefix Prefix
+
+// InterfaceIndex represents VPP binary API alias 'interface_index'.
+type InterfaceIndex uint32
+
+// IP4Address represents VPP binary API alias 'ip4_address'.
+type IP4Address [4]uint8
+
+// IP4AddressWithPrefix represents VPP binary API alias 'ip4_address_with_prefix'.
+type IP4AddressWithPrefix IP4Prefix
+
+// IP6Address represents VPP binary API alias 'ip6_address'.
+type IP6Address [16]uint8
+
+// IP6AddressWithPrefix represents VPP binary API alias 'ip6_address_with_prefix'.
+type IP6AddressWithPrefix IP6Prefix
-type IP6Prefix = ip_types.IP6Prefix
+// MacAddress represents VPP binary API alias 'mac_address'.
+type MacAddress [6]uint8
-type Mprefix = ip_types.Mprefix
+// Address represents VPP binary API type 'address'.
+type Address struct {
+ Af AddressFamily `binapi:"address_family,name=af" json:"af,omitempty"`
+ Un AddressUnion `binapi:"address_union,name=un" json:"un,omitempty"`
+}
+
+func (*Address) GetTypeName() string { return "address" }
+
+// IP4Prefix represents VPP binary API type 'ip4_prefix'.
+type IP4Prefix struct {
+ Address IP4Address `binapi:"ip4_address,name=address" json:"address,omitempty"`
+ Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
+}
-type Prefix = ip_types.Prefix
+func (*IP4Prefix) GetTypeName() string { return "ip4_prefix" }
-type PrefixMatcher = ip_types.PrefixMatcher
+// IP6Prefix represents VPP binary API type 'ip6_prefix'.
+type IP6Prefix struct {
+ Address IP6Address `binapi:"ip6_address,name=address" json:"address,omitempty"`
+ Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
+}
+
+func (*IP6Prefix) GetTypeName() string { return "ip6_prefix" }
+
+// Mprefix represents VPP binary API type 'mprefix'.
+type Mprefix struct {
+ Af AddressFamily `binapi:"address_family,name=af" json:"af,omitempty"`
+ GrpAddressLength uint16 `binapi:"u16,name=grp_address_length" json:"grp_address_length,omitempty"`
+ GrpAddress AddressUnion `binapi:"address_union,name=grp_address" json:"grp_address,omitempty"`
+ SrcAddress AddressUnion `binapi:"address_union,name=src_address" json:"src_address,omitempty"`
+}
-type AddressUnion = ip_types.AddressUnion
+func (*Mprefix) GetTypeName() string { return "mprefix" }
+
+// Prefix represents VPP binary API type 'prefix'.
+type Prefix struct {
+ Address Address `binapi:"address,name=address" json:"address,omitempty"`
+ Len uint8 `binapi:"u8,name=len" json:"len,omitempty"`
+}
+
+func (*Prefix) GetTypeName() string { return "prefix" }
+
+// PrefixMatcher represents VPP binary API type 'prefix_matcher'.
+type PrefixMatcher struct {
+ Le uint8 `binapi:"u8,name=le" json:"le,omitempty"`
+ Ge uint8 `binapi:"u8,name=ge" json:"ge,omitempty"`
+}
+
+func (*PrefixMatcher) GetTypeName() string { return "prefix_matcher" }
+
+// AddressUnion represents VPP binary API union 'address_union'.
+type AddressUnion struct {
+ XXX_UnionData [16]byte
+}
+
+func (*AddressUnion) GetTypeName() string { return "address_union" }
+
+func AddressUnionIP4(a IP4Address) (u AddressUnion) {
+ u.SetIP4(a)
+ return
+}
+func (u *AddressUnion) SetIP4(a IP4Address) {
+ var b = new(bytes.Buffer)
+ if err := struc.Pack(b, &a); err != nil {
+ return
+ }
+ copy(u.XXX_UnionData[:], b.Bytes())
+}
+func (u *AddressUnion) GetIP4() (a IP4Address) {
+ var b = bytes.NewReader(u.XXX_UnionData[:])
+ struc.Unpack(b, &a)
+ return
+}
+
+func AddressUnionIP6(a IP6Address) (u AddressUnion) {
+ u.SetIP6(a)
+ return
+}
+func (u *AddressUnion) SetIP6(a IP6Address) {
+ var b = new(bytes.Buffer)
+ if err := struc.Pack(b, &a); err != nil {
+ return
+ }
+ copy(u.XXX_UnionData[:], b.Bytes())
+}
+func (u *AddressUnion) GetIP6() (a IP6Address) {
+ var b = bytes.NewReader(u.XXX_UnionData[:])
+ struc.Unpack(b, &a)
+ return
+}
// CollectDetailedInterfaceStats represents VPP binary API message 'collect_detailed_interface_stats'.
type CollectDetailedInterfaceStats struct {
- SwIfIndex InterfaceIndex
- EnableDisable bool
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ EnableDisable bool `binapi:"bool,name=enable_disable" json:"enable_disable,omitempty"`
}
func (m *CollectDetailedInterfaceStats) Reset() { *m = CollectDetailedInterfaceStats{} }
@@ -98,9 +583,55 @@ func (*CollectDetailedInterfaceStats) GetMessageName() string {
func (*CollectDetailedInterfaceStats) GetCrcString() string { return "5501adee" }
func (*CollectDetailedInterfaceStats) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *CollectDetailedInterfaceStats) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.EnableDisable
+ size += 1
+ return size
+}
+func (m *CollectDetailedInterfaceStats) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.EnableDisable
+ if m.EnableDisable {
+ buf[pos] = 1
+ }
+ pos += 1
+ return buf, nil
+}
+func (m *CollectDetailedInterfaceStats) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.EnableDisable
+ m.EnableDisable = tmp[pos] != 0
+ pos += 1
+ return nil
+}
+
// CollectDetailedInterfaceStatsReply represents VPP binary API message 'collect_detailed_interface_stats_reply'.
type CollectDetailedInterfaceStatsReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *CollectDetailedInterfaceStatsReply) Reset() { *m = CollectDetailedInterfaceStatsReply{} }
@@ -110,9 +641,45 @@ func (*CollectDetailedInterfaceStatsReply) GetMessageName() string {
func (*CollectDetailedInterfaceStatsReply) GetCrcString() string { return "e8d4e804" }
func (*CollectDetailedInterfaceStatsReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *CollectDetailedInterfaceStatsReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *CollectDetailedInterfaceStatsReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *CollectDetailedInterfaceStatsReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// CreateLoopback represents VPP binary API message 'create_loopback'.
type CreateLoopback struct {
- MacAddress MacAddress
+ MacAddress MacAddress `binapi:"mac_address,name=mac_address" json:"mac_address,omitempty"`
}
func (m *CreateLoopback) Reset() { *m = CreateLoopback{} }
@@ -120,11 +687,55 @@ func (*CreateLoopback) GetMessageName() string { return "create_loopbac
func (*CreateLoopback) GetCrcString() string { return "42bb5d22" }
func (*CreateLoopback) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *CreateLoopback) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.MacAddress
+ size += 6
+ return size
+}
+func (m *CreateLoopback) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.MacAddress
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(m.MacAddress) {
+ x = uint8(m.MacAddress[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ return buf, nil
+}
+func (m *CreateLoopback) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.MacAddress
+ for i := 0; i < len(m.MacAddress); i++ {
+ m.MacAddress[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ return nil
+}
+
// CreateLoopbackInstance represents VPP binary API message 'create_loopback_instance'.
type CreateLoopbackInstance struct {
- MacAddress MacAddress
- IsSpecified bool
- UserInstance uint32
+ MacAddress MacAddress `binapi:"mac_address,name=mac_address" json:"mac_address,omitempty"`
+ IsSpecified bool `binapi:"bool,name=is_specified" json:"is_specified,omitempty"`
+ UserInstance uint32 `binapi:"u32,name=user_instance" json:"user_instance,omitempty"`
}
func (m *CreateLoopbackInstance) Reset() { *m = CreateLoopbackInstance{} }
@@ -132,10 +743,72 @@ func (*CreateLoopbackInstance) GetMessageName() string { return "create
func (*CreateLoopbackInstance) GetCrcString() string { return "d36a3ee2" }
func (*CreateLoopbackInstance) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *CreateLoopbackInstance) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.MacAddress
+ size += 6
+ // field[1] m.IsSpecified
+ size += 1
+ // field[1] m.UserInstance
+ size += 4
+ return size
+}
+func (m *CreateLoopbackInstance) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.MacAddress
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(m.MacAddress) {
+ x = uint8(m.MacAddress[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.IsSpecified
+ if m.IsSpecified {
+ buf[pos] = 1
+ }
+ pos += 1
+ // field[1] m.UserInstance
+ o.PutUint32(buf[pos:pos+4], uint32(m.UserInstance))
+ pos += 4
+ return buf, nil
+}
+func (m *CreateLoopbackInstance) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.MacAddress
+ for i := 0; i < len(m.MacAddress); i++ {
+ m.MacAddress[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.IsSpecified
+ m.IsSpecified = tmp[pos] != 0
+ pos += 1
+ // field[1] m.UserInstance
+ m.UserInstance = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// CreateLoopbackInstanceReply represents VPP binary API message 'create_loopback_instance_reply'.
type CreateLoopbackInstanceReply struct {
- Retval int32
- SwIfIndex InterfaceIndex
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
}
func (m *CreateLoopbackInstanceReply) Reset() { *m = CreateLoopbackInstanceReply{} }
@@ -143,10 +816,54 @@ func (*CreateLoopbackInstanceReply) GetMessageName() string { return "c
func (*CreateLoopbackInstanceReply) GetCrcString() string { return "5383d31f" }
func (*CreateLoopbackInstanceReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *CreateLoopbackInstanceReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *CreateLoopbackInstanceReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *CreateLoopbackInstanceReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// CreateLoopbackReply represents VPP binary API message 'create_loopback_reply'.
type CreateLoopbackReply struct {
- Retval int32
- SwIfIndex InterfaceIndex
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
}
func (m *CreateLoopbackReply) Reset() { *m = CreateLoopbackReply{} }
@@ -154,13 +871,57 @@ func (*CreateLoopbackReply) GetMessageName() string { return "create_lo
func (*CreateLoopbackReply) GetCrcString() string { return "5383d31f" }
func (*CreateLoopbackReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *CreateLoopbackReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *CreateLoopbackReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *CreateLoopbackReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// CreateSubif represents VPP binary API message 'create_subif'.
type CreateSubif struct {
- SwIfIndex InterfaceIndex
- SubID uint32
- SubIfFlags SubIfFlags
- OuterVlanID uint16
- InnerVlanID uint16
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ SubID uint32 `binapi:"u32,name=sub_id" json:"sub_id,omitempty"`
+ SubIfFlags SubIfFlags `binapi:"sub_if_flags,name=sub_if_flags" json:"sub_if_flags,omitempty"`
+ OuterVlanID uint16 `binapi:"u16,name=outer_vlan_id" json:"outer_vlan_id,omitempty"`
+ InnerVlanID uint16 `binapi:"u16,name=inner_vlan_id" json:"inner_vlan_id,omitempty"`
}
func (m *CreateSubif) Reset() { *m = CreateSubif{} }
@@ -168,10 +929,78 @@ func (*CreateSubif) GetMessageName() string { return "create_subif" }
func (*CreateSubif) GetCrcString() string { return "cb371063" }
func (*CreateSubif) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *CreateSubif) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.SubID
+ size += 4
+ // field[1] m.SubIfFlags
+ size += 4
+ // field[1] m.OuterVlanID
+ size += 2
+ // field[1] m.InnerVlanID
+ size += 2
+ return size
+}
+func (m *CreateSubif) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.SubID
+ o.PutUint32(buf[pos:pos+4], uint32(m.SubID))
+ pos += 4
+ // field[1] m.SubIfFlags
+ o.PutUint32(buf[pos:pos+4], uint32(m.SubIfFlags))
+ pos += 4
+ // field[1] m.OuterVlanID
+ o.PutUint16(buf[pos:pos+2], uint16(m.OuterVlanID))
+ pos += 2
+ // field[1] m.InnerVlanID
+ o.PutUint16(buf[pos:pos+2], uint16(m.InnerVlanID))
+ pos += 2
+ return buf, nil
+}
+func (m *CreateSubif) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.SubID
+ m.SubID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.SubIfFlags
+ m.SubIfFlags = SubIfFlags(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.OuterVlanID
+ m.OuterVlanID = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[1] m.InnerVlanID
+ m.InnerVlanID = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ return nil
+}
+
// CreateSubifReply represents VPP binary API message 'create_subif_reply'.
type CreateSubifReply struct {
- Retval int32
- SwIfIndex InterfaceIndex
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
}
func (m *CreateSubifReply) Reset() { *m = CreateSubifReply{} }
@@ -179,10 +1008,54 @@ func (*CreateSubifReply) GetMessageName() string { return "create_subif
func (*CreateSubifReply) GetCrcString() string { return "5383d31f" }
func (*CreateSubifReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *CreateSubifReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *CreateSubifReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *CreateSubifReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// CreateVlanSubif represents VPP binary API message 'create_vlan_subif'.
type CreateVlanSubif struct {
- SwIfIndex InterfaceIndex
- VlanID uint32
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ VlanID uint32 `binapi:"u32,name=vlan_id" json:"vlan_id,omitempty"`
}
func (m *CreateVlanSubif) Reset() { *m = CreateVlanSubif{} }
@@ -190,10 +1063,54 @@ func (*CreateVlanSubif) GetMessageName() string { return "create_vlan_s
func (*CreateVlanSubif) GetCrcString() string { return "af34ac8b" }
func (*CreateVlanSubif) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *CreateVlanSubif) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.VlanID
+ size += 4
+ return size
+}
+func (m *CreateVlanSubif) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.VlanID
+ o.PutUint32(buf[pos:pos+4], uint32(m.VlanID))
+ pos += 4
+ return buf, nil
+}
+func (m *CreateVlanSubif) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.VlanID
+ m.VlanID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// CreateVlanSubifReply represents VPP binary API message 'create_vlan_subif_reply'.
type CreateVlanSubifReply struct {
- Retval int32
- SwIfIndex InterfaceIndex
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
}
func (m *CreateVlanSubifReply) Reset() { *m = CreateVlanSubifReply{} }
@@ -201,9 +1118,53 @@ func (*CreateVlanSubifReply) GetMessageName() string { return "create_v
func (*CreateVlanSubifReply) GetCrcString() string { return "5383d31f" }
func (*CreateVlanSubifReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *CreateVlanSubifReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *CreateVlanSubifReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *CreateVlanSubifReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// DeleteLoopback represents VPP binary API message 'delete_loopback'.
type DeleteLoopback struct {
- SwIfIndex InterfaceIndex
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
}
func (m *DeleteLoopback) Reset() { *m = DeleteLoopback{} }
@@ -211,9 +1172,45 @@ func (*DeleteLoopback) GetMessageName() string { return "delete_loopbac
func (*DeleteLoopback) GetCrcString() string { return "f9e6675e" }
func (*DeleteLoopback) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *DeleteLoopback) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *DeleteLoopback) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *DeleteLoopback) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// DeleteLoopbackReply represents VPP binary API message 'delete_loopback_reply'.
type DeleteLoopbackReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *DeleteLoopbackReply) Reset() { *m = DeleteLoopbackReply{} }
@@ -221,9 +1218,45 @@ func (*DeleteLoopbackReply) GetMessageName() string { return "delete_lo
func (*DeleteLoopbackReply) GetCrcString() string { return "e8d4e804" }
func (*DeleteLoopbackReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *DeleteLoopbackReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *DeleteLoopbackReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *DeleteLoopbackReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// DeleteSubif represents VPP binary API message 'delete_subif'.
type DeleteSubif struct {
- SwIfIndex InterfaceIndex
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
}
func (m *DeleteSubif) Reset() { *m = DeleteSubif{} }
@@ -231,9 +1264,45 @@ func (*DeleteSubif) GetMessageName() string { return "delete_subif" }
func (*DeleteSubif) GetCrcString() string { return "f9e6675e" }
func (*DeleteSubif) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *DeleteSubif) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *DeleteSubif) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *DeleteSubif) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// DeleteSubifReply represents VPP binary API message 'delete_subif_reply'.
type DeleteSubifReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *DeleteSubifReply) Reset() { *m = DeleteSubifReply{} }
@@ -241,10 +1310,46 @@ func (*DeleteSubifReply) GetMessageName() string { return "delete_subif
func (*DeleteSubifReply) GetCrcString() string { return "e8d4e804" }
func (*DeleteSubifReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *DeleteSubifReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *DeleteSubifReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *DeleteSubifReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// HwInterfaceSetMtu represents VPP binary API message 'hw_interface_set_mtu'.
type HwInterfaceSetMtu struct {
- SwIfIndex InterfaceIndex
- Mtu uint16
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Mtu uint16 `binapi:"u16,name=mtu" json:"mtu,omitempty"`
}
func (m *HwInterfaceSetMtu) Reset() { *m = HwInterfaceSetMtu{} }
@@ -252,9 +1357,53 @@ func (*HwInterfaceSetMtu) GetMessageName() string { return "hw_interfac
func (*HwInterfaceSetMtu) GetCrcString() string { return "e6746899" }
func (*HwInterfaceSetMtu) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *HwInterfaceSetMtu) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Mtu
+ size += 2
+ return size
+}
+func (m *HwInterfaceSetMtu) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Mtu
+ o.PutUint16(buf[pos:pos+2], uint16(m.Mtu))
+ pos += 2
+ return buf, nil
+}
+func (m *HwInterfaceSetMtu) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Mtu
+ m.Mtu = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ return nil
+}
+
// HwInterfaceSetMtuReply represents VPP binary API message 'hw_interface_set_mtu_reply'.
type HwInterfaceSetMtuReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *HwInterfaceSetMtuReply) Reset() { *m = HwInterfaceSetMtuReply{} }
@@ -262,10 +1411,46 @@ func (*HwInterfaceSetMtuReply) GetMessageName() string { return "hw_int
func (*HwInterfaceSetMtuReply) GetCrcString() string { return "e8d4e804" }
func (*HwInterfaceSetMtuReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *HwInterfaceSetMtuReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *HwInterfaceSetMtuReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *HwInterfaceSetMtuReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// InterfaceNameRenumber represents VPP binary API message 'interface_name_renumber'.
type InterfaceNameRenumber struct {
- SwIfIndex InterfaceIndex
- NewShowDevInstance uint32
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ NewShowDevInstance uint32 `binapi:"u32,name=new_show_dev_instance" json:"new_show_dev_instance,omitempty"`
}
func (m *InterfaceNameRenumber) Reset() { *m = InterfaceNameRenumber{} }
@@ -273,9 +1458,53 @@ func (*InterfaceNameRenumber) GetMessageName() string { return "interfa
func (*InterfaceNameRenumber) GetCrcString() string { return "2b8858b8" }
func (*InterfaceNameRenumber) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *InterfaceNameRenumber) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.NewShowDevInstance
+ size += 4
+ return size
+}
+func (m *InterfaceNameRenumber) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.NewShowDevInstance
+ o.PutUint32(buf[pos:pos+4], uint32(m.NewShowDevInstance))
+ pos += 4
+ return buf, nil
+}
+func (m *InterfaceNameRenumber) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.NewShowDevInstance
+ m.NewShowDevInstance = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// InterfaceNameRenumberReply represents VPP binary API message 'interface_name_renumber_reply'.
type InterfaceNameRenumberReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *InterfaceNameRenumberReply) Reset() { *m = InterfaceNameRenumberReply{} }
@@ -283,12 +1512,48 @@ func (*InterfaceNameRenumberReply) GetMessageName() string { return "in
func (*InterfaceNameRenumberReply) GetCrcString() string { return "e8d4e804" }
func (*InterfaceNameRenumberReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *InterfaceNameRenumberReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *InterfaceNameRenumberReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *InterfaceNameRenumberReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceAddDelAddress represents VPP binary API message 'sw_interface_add_del_address'.
type SwInterfaceAddDelAddress struct {
- SwIfIndex InterfaceIndex
- IsAdd bool
- DelAll bool
- Prefix AddressWithPrefix
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ IsAdd bool `binapi:"bool,name=is_add" json:"is_add,omitempty"`
+ DelAll bool `binapi:"bool,name=del_all" json:"del_all,omitempty"`
+ Prefix AddressWithPrefix `binapi:"address_with_prefix,name=prefix" json:"prefix,omitempty"`
}
func (m *SwInterfaceAddDelAddress) Reset() { *m = SwInterfaceAddDelAddress{} }
@@ -296,9 +1561,95 @@ func (*SwInterfaceAddDelAddress) GetMessageName() string { return "sw_i
func (*SwInterfaceAddDelAddress) GetCrcString() string { return "5803d5c4" }
func (*SwInterfaceAddDelAddress) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceAddDelAddress) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.IsAdd
+ size += 1
+ // field[1] m.DelAll
+ size += 1
+ // field[1] m.Prefix
+ // field[2] m.Prefix.Address
+ // field[3] m.Prefix.Address.Af
+ size += 4
+ // field[3] m.Prefix.Address.Un
+ size += 16
+ // field[2] m.Prefix.Len
+ size += 1
+ return size
+}
+func (m *SwInterfaceAddDelAddress) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.IsAdd
+ if m.IsAdd {
+ buf[pos] = 1
+ }
+ pos += 1
+ // field[1] m.DelAll
+ if m.DelAll {
+ buf[pos] = 1
+ }
+ pos += 1
+ // field[1] m.Prefix
+ // field[2] m.Prefix.Address
+ // field[3] m.Prefix.Address.Af
+ o.PutUint32(buf[pos:pos+4], uint32(m.Prefix.Address.Af))
+ pos += 4
+ // field[3] m.Prefix.Address.Un
+ copy(buf[pos:pos+16], m.Prefix.Address.Un.XXX_UnionData[:])
+ pos += 16
+ // field[2] m.Prefix.Len
+ buf[pos] = uint8(m.Prefix.Len)
+ pos += 1
+ return buf, nil
+}
+func (m *SwInterfaceAddDelAddress) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.IsAdd
+ m.IsAdd = tmp[pos] != 0
+ pos += 1
+ // field[1] m.DelAll
+ m.DelAll = tmp[pos] != 0
+ pos += 1
+ // field[1] m.Prefix
+ // field[2] m.Prefix.Address
+ // field[3] m.Prefix.Address.Af
+ m.Prefix.Address.Af = AddressFamily(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[3] m.Prefix.Address.Un
+ copy(m.Prefix.Address.Un.XXX_UnionData[:], tmp[pos:pos+16])
+ pos += 16
+ // field[2] m.Prefix.Len
+ m.Prefix.Len = uint8(tmp[pos])
+ pos += 1
+ return nil
+}
+
// SwInterfaceAddDelAddressReply represents VPP binary API message 'sw_interface_add_del_address_reply'.
type SwInterfaceAddDelAddressReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *SwInterfaceAddDelAddressReply) Reset() { *m = SwInterfaceAddDelAddressReply{} }
@@ -308,11 +1659,47 @@ func (*SwInterfaceAddDelAddressReply) GetMessageName() string {
func (*SwInterfaceAddDelAddressReply) GetCrcString() string { return "e8d4e804" }
func (*SwInterfaceAddDelAddressReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceAddDelAddressReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *SwInterfaceAddDelAddressReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceAddDelAddressReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceAddDelMacAddress represents VPP binary API message 'sw_interface_add_del_mac_address'.
type SwInterfaceAddDelMacAddress struct {
- SwIfIndex uint32
- Addr MacAddress
- IsAdd uint8
+ SwIfIndex uint32 `binapi:"u32,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Addr MacAddress `binapi:"mac_address,name=addr" json:"addr,omitempty"`
+ IsAdd uint8 `binapi:"u8,name=is_add" json:"is_add,omitempty"`
}
func (m *SwInterfaceAddDelMacAddress) Reset() { *m = SwInterfaceAddDelMacAddress{} }
@@ -322,9 +1709,69 @@ func (*SwInterfaceAddDelMacAddress) GetMessageName() string {
func (*SwInterfaceAddDelMacAddress) GetCrcString() string { return "638bb9f4" }
func (*SwInterfaceAddDelMacAddress) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceAddDelMacAddress) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Addr
+ size += 6
+ // field[1] m.IsAdd
+ size += 1
+ return size
+}
+func (m *SwInterfaceAddDelMacAddress) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Addr
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(m.Addr) {
+ x = uint8(m.Addr[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.IsAdd
+ buf[pos] = uint8(m.IsAdd)
+ pos += 1
+ return buf, nil
+}
+func (m *SwInterfaceAddDelMacAddress) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Addr
+ for i := 0; i < len(m.Addr); i++ {
+ m.Addr[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.IsAdd
+ m.IsAdd = uint8(tmp[pos])
+ pos += 1
+ return nil
+}
+
// SwInterfaceAddDelMacAddressReply represents VPP binary API message 'sw_interface_add_del_mac_address_reply'.
type SwInterfaceAddDelMacAddressReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *SwInterfaceAddDelMacAddressReply) Reset() { *m = SwInterfaceAddDelMacAddressReply{} }
@@ -334,9 +1781,45 @@ func (*SwInterfaceAddDelMacAddressReply) GetMessageName() string {
func (*SwInterfaceAddDelMacAddressReply) GetCrcString() string { return "e8d4e804" }
func (*SwInterfaceAddDelMacAddressReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceAddDelMacAddressReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *SwInterfaceAddDelMacAddressReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceAddDelMacAddressReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceClearStats represents VPP binary API message 'sw_interface_clear_stats'.
type SwInterfaceClearStats struct {
- SwIfIndex InterfaceIndex
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
}
func (m *SwInterfaceClearStats) Reset() { *m = SwInterfaceClearStats{} }
@@ -344,9 +1827,45 @@ func (*SwInterfaceClearStats) GetMessageName() string { return "sw_inte
func (*SwInterfaceClearStats) GetCrcString() string { return "f9e6675e" }
func (*SwInterfaceClearStats) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceClearStats) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *SwInterfaceClearStats) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceClearStats) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceClearStatsReply represents VPP binary API message 'sw_interface_clear_stats_reply'.
type SwInterfaceClearStatsReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *SwInterfaceClearStatsReply) Reset() { *m = SwInterfaceClearStatsReply{} }
@@ -354,34 +1873,70 @@ func (*SwInterfaceClearStatsReply) GetMessageName() string { return "sw
func (*SwInterfaceClearStatsReply) GetCrcString() string { return "e8d4e804" }
func (*SwInterfaceClearStatsReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceClearStatsReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *SwInterfaceClearStatsReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceClearStatsReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceDetails represents VPP binary API message 'sw_interface_details'.
type SwInterfaceDetails struct {
- SwIfIndex InterfaceIndex
- SupSwIfIndex uint32
- L2Address MacAddress
- Flags IfStatusFlags
- Type IfType
- LinkDuplex LinkDuplex
- LinkSpeed uint32
- LinkMtu uint16
- Mtu []uint32 `struc:"[4]uint32"`
- SubID uint32
- SubNumberOfTags uint8
- SubOuterVlanID uint16
- SubInnerVlanID uint16
- SubIfFlags SubIfFlags
- VtrOp uint32
- VtrPushDot1q uint32
- VtrTag1 uint32
- VtrTag2 uint32
- OuterTag uint16
- BDmac MacAddress
- BSmac MacAddress
- BVlanid uint16
- ISid uint32
- InterfaceName string `struc:"[64]byte"`
- InterfaceDevType string `struc:"[64]byte"`
- Tag string `struc:"[64]byte"`
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ SupSwIfIndex uint32 `binapi:"u32,name=sup_sw_if_index" json:"sup_sw_if_index,omitempty"`
+ L2Address MacAddress `binapi:"mac_address,name=l2_address" json:"l2_address,omitempty"`
+ Flags IfStatusFlags `binapi:"if_status_flags,name=flags" json:"flags,omitempty"`
+ Type IfType `binapi:"if_type,name=type" json:"type,omitempty"`
+ LinkDuplex LinkDuplex `binapi:"link_duplex,name=link_duplex" json:"link_duplex,omitempty"`
+ LinkSpeed uint32 `binapi:"u32,name=link_speed" json:"link_speed,omitempty"`
+ LinkMtu uint16 `binapi:"u16,name=link_mtu" json:"link_mtu,omitempty"`
+ Mtu []uint32 `binapi:"u32[4],name=mtu" json:"mtu,omitempty" struc:"[4]uint32"`
+ SubID uint32 `binapi:"u32,name=sub_id" json:"sub_id,omitempty"`
+ SubNumberOfTags uint8 `binapi:"u8,name=sub_number_of_tags" json:"sub_number_of_tags,omitempty"`
+ SubOuterVlanID uint16 `binapi:"u16,name=sub_outer_vlan_id" json:"sub_outer_vlan_id,omitempty"`
+ SubInnerVlanID uint16 `binapi:"u16,name=sub_inner_vlan_id" json:"sub_inner_vlan_id,omitempty"`
+ SubIfFlags SubIfFlags `binapi:"sub_if_flags,name=sub_if_flags" json:"sub_if_flags,omitempty"`
+ VtrOp uint32 `binapi:"u32,name=vtr_op" json:"vtr_op,omitempty"`
+ VtrPushDot1q uint32 `binapi:"u32,name=vtr_push_dot1q" json:"vtr_push_dot1q,omitempty"`
+ VtrTag1 uint32 `binapi:"u32,name=vtr_tag1" json:"vtr_tag1,omitempty"`
+ VtrTag2 uint32 `binapi:"u32,name=vtr_tag2" json:"vtr_tag2,omitempty"`
+ OuterTag uint16 `binapi:"u16,name=outer_tag" json:"outer_tag,omitempty"`
+ BDmac MacAddress `binapi:"mac_address,name=b_dmac" json:"b_dmac,omitempty"`
+ BSmac MacAddress `binapi:"mac_address,name=b_smac" json:"b_smac,omitempty"`
+ BVlanid uint16 `binapi:"u16,name=b_vlanid" json:"b_vlanid,omitempty"`
+ ISid uint32 `binapi:"u32,name=i_sid" json:"i_sid,omitempty"`
+ InterfaceName string `binapi:"string[64],name=interface_name" json:"interface_name,omitempty" struc:"[64]byte"`
+ InterfaceDevType string `binapi:"string[64],name=interface_dev_type" json:"interface_dev_type,omitempty" struc:"[64]byte"`
+ Tag string `binapi:"string[64],name=tag" json:"tag,omitempty" struc:"[64]byte"`
}
func (m *SwInterfaceDetails) Reset() { *m = SwInterfaceDetails{} }
@@ -389,12 +1944,290 @@ func (*SwInterfaceDetails) GetMessageName() string { return "sw_interfa
func (*SwInterfaceDetails) GetCrcString() string { return "17b69fa2" }
func (*SwInterfaceDetails) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceDetails) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.SupSwIfIndex
+ size += 4
+ // field[1] m.L2Address
+ size += 6
+ // field[1] m.Flags
+ size += 4
+ // field[1] m.Type
+ size += 4
+ // field[1] m.LinkDuplex
+ size += 4
+ // field[1] m.LinkSpeed
+ size += 4
+ // field[1] m.LinkMtu
+ size += 2
+ // field[1] m.Mtu
+ size += 16
+ // field[1] m.SubID
+ size += 4
+ // field[1] m.SubNumberOfTags
+ size += 1
+ // field[1] m.SubOuterVlanID
+ size += 2
+ // field[1] m.SubInnerVlanID
+ size += 2
+ // field[1] m.SubIfFlags
+ size += 4
+ // field[1] m.VtrOp
+ size += 4
+ // field[1] m.VtrPushDot1q
+ size += 4
+ // field[1] m.VtrTag1
+ size += 4
+ // field[1] m.VtrTag2
+ size += 4
+ // field[1] m.OuterTag
+ size += 2
+ // field[1] m.BDmac
+ size += 6
+ // field[1] m.BSmac
+ size += 6
+ // field[1] m.BVlanid
+ size += 2
+ // field[1] m.ISid
+ size += 4
+ // field[1] m.InterfaceName
+ size += 64
+ // field[1] m.InterfaceDevType
+ size += 64
+ // field[1] m.Tag
+ size += 64
+ return size
+}
+func (m *SwInterfaceDetails) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.SupSwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SupSwIfIndex))
+ pos += 4
+ // field[1] m.L2Address
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(m.L2Address) {
+ x = uint8(m.L2Address[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.Flags
+ o.PutUint32(buf[pos:pos+4], uint32(m.Flags))
+ pos += 4
+ // field[1] m.Type
+ o.PutUint32(buf[pos:pos+4], uint32(m.Type))
+ pos += 4
+ // field[1] m.LinkDuplex
+ o.PutUint32(buf[pos:pos+4], uint32(m.LinkDuplex))
+ pos += 4
+ // field[1] m.LinkSpeed
+ o.PutUint32(buf[pos:pos+4], uint32(m.LinkSpeed))
+ pos += 4
+ // field[1] m.LinkMtu
+ o.PutUint16(buf[pos:pos+2], uint16(m.LinkMtu))
+ pos += 2
+ // field[1] m.Mtu
+ for i := 0; i < 4; i++ {
+ var x uint32
+ if i < len(m.Mtu) {
+ x = uint32(m.Mtu[i])
+ }
+ o.PutUint32(buf[pos:pos+4], uint32(x))
+ pos += 4
+ }
+ // field[1] m.SubID
+ o.PutUint32(buf[pos:pos+4], uint32(m.SubID))
+ pos += 4
+ // field[1] m.SubNumberOfTags
+ buf[pos] = uint8(m.SubNumberOfTags)
+ pos += 1
+ // field[1] m.SubOuterVlanID
+ o.PutUint16(buf[pos:pos+2], uint16(m.SubOuterVlanID))
+ pos += 2
+ // field[1] m.SubInnerVlanID
+ o.PutUint16(buf[pos:pos+2], uint16(m.SubInnerVlanID))
+ pos += 2
+ // field[1] m.SubIfFlags
+ o.PutUint32(buf[pos:pos+4], uint32(m.SubIfFlags))
+ pos += 4
+ // field[1] m.VtrOp
+ o.PutUint32(buf[pos:pos+4], uint32(m.VtrOp))
+ pos += 4
+ // field[1] m.VtrPushDot1q
+ o.PutUint32(buf[pos:pos+4], uint32(m.VtrPushDot1q))
+ pos += 4
+ // field[1] m.VtrTag1
+ o.PutUint32(buf[pos:pos+4], uint32(m.VtrTag1))
+ pos += 4
+ // field[1] m.VtrTag2
+ o.PutUint32(buf[pos:pos+4], uint32(m.VtrTag2))
+ pos += 4
+ // field[1] m.OuterTag
+ o.PutUint16(buf[pos:pos+2], uint16(m.OuterTag))
+ pos += 2
+ // field[1] m.BDmac
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(m.BDmac) {
+ x = uint8(m.BDmac[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.BSmac
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(m.BSmac) {
+ x = uint8(m.BSmac[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ // field[1] m.BVlanid
+ o.PutUint16(buf[pos:pos+2], uint16(m.BVlanid))
+ pos += 2
+ // field[1] m.ISid
+ o.PutUint32(buf[pos:pos+4], uint32(m.ISid))
+ pos += 4
+ // field[1] m.InterfaceName
+ copy(buf[pos:pos+64], m.InterfaceName)
+ pos += 64
+ // field[1] m.InterfaceDevType
+ copy(buf[pos:pos+64], m.InterfaceDevType)
+ pos += 64
+ // field[1] m.Tag
+ copy(buf[pos:pos+64], m.Tag)
+ pos += 64
+ return buf, nil
+}
+func (m *SwInterfaceDetails) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.SupSwIfIndex
+ m.SupSwIfIndex = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.L2Address
+ for i := 0; i < len(m.L2Address); i++ {
+ m.L2Address[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.Flags
+ m.Flags = IfStatusFlags(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Type
+ m.Type = IfType(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.LinkDuplex
+ m.LinkDuplex = LinkDuplex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.LinkSpeed
+ m.LinkSpeed = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.LinkMtu
+ m.LinkMtu = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[1] m.Mtu
+ m.Mtu = make([]uint32, 4)
+ for i := 0; i < len(m.Mtu); i++ {
+ m.Mtu[i] = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ }
+ // field[1] m.SubID
+ m.SubID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.SubNumberOfTags
+ m.SubNumberOfTags = uint8(tmp[pos])
+ pos += 1
+ // field[1] m.SubOuterVlanID
+ m.SubOuterVlanID = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[1] m.SubInnerVlanID
+ m.SubInnerVlanID = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[1] m.SubIfFlags
+ m.SubIfFlags = SubIfFlags(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.VtrOp
+ m.VtrOp = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.VtrPushDot1q
+ m.VtrPushDot1q = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.VtrTag1
+ m.VtrTag1 = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.VtrTag2
+ m.VtrTag2 = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.OuterTag
+ m.OuterTag = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[1] m.BDmac
+ for i := 0; i < len(m.BDmac); i++ {
+ m.BDmac[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.BSmac
+ for i := 0; i < len(m.BSmac); i++ {
+ m.BSmac[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ // field[1] m.BVlanid
+ m.BVlanid = uint16(o.Uint16(tmp[pos : pos+2]))
+ pos += 2
+ // field[1] m.ISid
+ m.ISid = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.InterfaceName
+ {
+ nul := bytes.Index(tmp[pos:pos+64], []byte{0x00})
+ m.InterfaceName = codec.DecodeString(tmp[pos : pos+nul])
+ pos += 64
+ }
+ // field[1] m.InterfaceDevType
+ {
+ nul := bytes.Index(tmp[pos:pos+64], []byte{0x00})
+ m.InterfaceDevType = codec.DecodeString(tmp[pos : pos+nul])
+ pos += 64
+ }
+ // field[1] m.Tag
+ {
+ nul := bytes.Index(tmp[pos:pos+64], []byte{0x00})
+ m.Tag = codec.DecodeString(tmp[pos : pos+nul])
+ pos += 64
+ }
+ return nil
+}
+
// SwInterfaceDump represents VPP binary API message 'sw_interface_dump'.
type SwInterfaceDump struct {
- SwIfIndex InterfaceIndex
- NameFilterValid bool
- XXX_NameFilterLen uint32 `struc:"sizeof=NameFilter"`
- NameFilter string
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index,default=4294967295" json:"sw_if_index,omitempty"`
+ NameFilterValid bool `binapi:"bool,name=name_filter_valid" json:"name_filter_valid,omitempty"`
+ XXX_NameFilterLen uint32 `struc:"sizeof=NameFilter"`
+ NameFilter string `json:"name_filter,omitempty"`
}
func (m *SwInterfaceDump) Reset() { *m = SwInterfaceDump{} }
@@ -402,12 +2235,72 @@ func (*SwInterfaceDump) GetMessageName() string { return "sw_interface_
func (*SwInterfaceDump) GetCrcString() string { return "aa610c27" }
func (*SwInterfaceDump) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceDump) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.NameFilterValid
+ size += 1
+ // field[1] m.NameFilter
+ size += 4 + len(m.NameFilter)
+ return size
+}
+func (m *SwInterfaceDump) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.NameFilterValid
+ if m.NameFilterValid {
+ buf[pos] = 1
+ }
+ pos += 1
+ // field[1] m.NameFilter
+ o.PutUint32(buf[pos:pos+4], uint32(len(m.NameFilter)))
+ pos += 4
+ copy(buf[pos:pos+len(m.NameFilter)], m.NameFilter[:])
+ pos += len(m.NameFilter)
+ return buf, nil
+}
+func (m *SwInterfaceDump) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.NameFilterValid
+ m.NameFilterValid = tmp[pos] != 0
+ pos += 1
+ // field[1] m.NameFilter
+ {
+ siz := o.Uint32(tmp[pos : pos+4])
+ pos += 4
+ m.NameFilter = codec.DecodeString(tmp[pos : pos+int(siz)])
+ pos += len(m.NameFilter)
+ }
+ return nil
+}
+
// SwInterfaceEvent represents VPP binary API message 'sw_interface_event'.
type SwInterfaceEvent struct {
- PID uint32
- SwIfIndex InterfaceIndex
- Flags IfStatusFlags
- Deleted bool
+ PID uint32 `binapi:"u32,name=pid" json:"pid,omitempty"`
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Flags IfStatusFlags `binapi:"if_status_flags,name=flags" json:"flags,omitempty"`
+ Deleted bool `binapi:"bool,name=deleted" json:"deleted,omitempty"`
}
func (m *SwInterfaceEvent) Reset() { *m = SwInterfaceEvent{} }
@@ -415,9 +2308,71 @@ func (*SwInterfaceEvent) GetMessageName() string { return "sw_interface
func (*SwInterfaceEvent) GetCrcString() string { return "f709f78d" }
func (*SwInterfaceEvent) GetMessageType() api.MessageType { return api.EventMessage }
+func (m *SwInterfaceEvent) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.PID
+ size += 4
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Flags
+ size += 4
+ // field[1] m.Deleted
+ size += 1
+ return size
+}
+func (m *SwInterfaceEvent) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.PID
+ o.PutUint32(buf[pos:pos+4], uint32(m.PID))
+ pos += 4
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Flags
+ o.PutUint32(buf[pos:pos+4], uint32(m.Flags))
+ pos += 4
+ // field[1] m.Deleted
+ if m.Deleted {
+ buf[pos] = 1
+ }
+ pos += 1
+ return buf, nil
+}
+func (m *SwInterfaceEvent) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.PID
+ m.PID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Flags
+ m.Flags = IfStatusFlags(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Deleted
+ m.Deleted = tmp[pos] != 0
+ pos += 1
+ return nil
+}
+
// SwInterfaceGetMacAddress represents VPP binary API message 'sw_interface_get_mac_address'.
type SwInterfaceGetMacAddress struct {
- SwIfIndex InterfaceIndex
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
}
func (m *SwInterfaceGetMacAddress) Reset() { *m = SwInterfaceGetMacAddress{} }
@@ -425,10 +2380,46 @@ func (*SwInterfaceGetMacAddress) GetMessageName() string { return "sw_i
func (*SwInterfaceGetMacAddress) GetCrcString() string { return "f9e6675e" }
func (*SwInterfaceGetMacAddress) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceGetMacAddress) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *SwInterfaceGetMacAddress) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceGetMacAddress) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceGetMacAddressReply represents VPP binary API message 'sw_interface_get_mac_address_reply'.
type SwInterfaceGetMacAddressReply struct {
- Retval int32
- MacAddress MacAddress
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
+ MacAddress MacAddress `binapi:"mac_address,name=mac_address" json:"mac_address,omitempty"`
}
func (m *SwInterfaceGetMacAddressReply) Reset() { *m = SwInterfaceGetMacAddressReply{} }
@@ -438,10 +2429,62 @@ func (*SwInterfaceGetMacAddressReply) GetMessageName() string {
func (*SwInterfaceGetMacAddressReply) GetCrcString() string { return "40ef2c08" }
func (*SwInterfaceGetMacAddressReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceGetMacAddressReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ // field[1] m.MacAddress
+ size += 6
+ return size
+}
+func (m *SwInterfaceGetMacAddressReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ // field[1] m.MacAddress
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(m.MacAddress) {
+ x = uint8(m.MacAddress[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ return buf, nil
+}
+func (m *SwInterfaceGetMacAddressReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.MacAddress
+ for i := 0; i < len(m.MacAddress); i++ {
+ m.MacAddress[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ return nil
+}
+
// SwInterfaceGetTable represents VPP binary API message 'sw_interface_get_table'.
type SwInterfaceGetTable struct {
- SwIfIndex InterfaceIndex
- IsIPv6 bool
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ IsIPv6 bool `binapi:"bool,name=is_ipv6" json:"is_ipv6,omitempty"`
}
func (m *SwInterfaceGetTable) Reset() { *m = SwInterfaceGetTable{} }
@@ -449,10 +2492,56 @@ func (*SwInterfaceGetTable) GetMessageName() string { return "sw_interf
func (*SwInterfaceGetTable) GetCrcString() string { return "2d033de4" }
func (*SwInterfaceGetTable) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceGetTable) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.IsIPv6
+ size += 1
+ return size
+}
+func (m *SwInterfaceGetTable) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.IsIPv6
+ if m.IsIPv6 {
+ buf[pos] = 1
+ }
+ pos += 1
+ return buf, nil
+}
+func (m *SwInterfaceGetTable) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.IsIPv6
+ m.IsIPv6 = tmp[pos] != 0
+ pos += 1
+ return nil
+}
+
// SwInterfaceGetTableReply represents VPP binary API message 'sw_interface_get_table_reply'.
type SwInterfaceGetTableReply struct {
- Retval int32
- VrfID uint32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
+ VrfID uint32 `binapi:"u32,name=vrf_id" json:"vrf_id,omitempty"`
}
func (m *SwInterfaceGetTableReply) Reset() { *m = SwInterfaceGetTableReply{} }
@@ -460,12 +2549,56 @@ func (*SwInterfaceGetTableReply) GetMessageName() string { return "sw_i
func (*SwInterfaceGetTableReply) GetCrcString() string { return "a6eb0109" }
func (*SwInterfaceGetTableReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceGetTableReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ // field[1] m.VrfID
+ size += 4
+ return size
+}
+func (m *SwInterfaceGetTableReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ // field[1] m.VrfID
+ o.PutUint32(buf[pos:pos+4], uint32(m.VrfID))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceGetTableReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.VrfID
+ m.VrfID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceRxPlacementDetails represents VPP binary API message 'sw_interface_rx_placement_details'.
type SwInterfaceRxPlacementDetails struct {
- SwIfIndex InterfaceIndex
- QueueID uint32
- WorkerID uint32
- Mode RxMode
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ QueueID uint32 `binapi:"u32,name=queue_id" json:"queue_id,omitempty"`
+ WorkerID uint32 `binapi:"u32,name=worker_id" json:"worker_id,omitempty"`
+ Mode RxMode `binapi:"rx_mode,name=mode" json:"mode,omitempty"`
}
func (m *SwInterfaceRxPlacementDetails) Reset() { *m = SwInterfaceRxPlacementDetails{} }
@@ -475,9 +2608,69 @@ func (*SwInterfaceRxPlacementDetails) GetMessageName() string {
func (*SwInterfaceRxPlacementDetails) GetCrcString() string { return "f6d7d024" }
func (*SwInterfaceRxPlacementDetails) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceRxPlacementDetails) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.QueueID
+ size += 4
+ // field[1] m.WorkerID
+ size += 4
+ // field[1] m.Mode
+ size += 4
+ return size
+}
+func (m *SwInterfaceRxPlacementDetails) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.QueueID
+ o.PutUint32(buf[pos:pos+4], uint32(m.QueueID))
+ pos += 4
+ // field[1] m.WorkerID
+ o.PutUint32(buf[pos:pos+4], uint32(m.WorkerID))
+ pos += 4
+ // field[1] m.Mode
+ o.PutUint32(buf[pos:pos+4], uint32(m.Mode))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceRxPlacementDetails) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.QueueID
+ m.QueueID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.WorkerID
+ m.WorkerID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Mode
+ m.Mode = RxMode(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceRxPlacementDump represents VPP binary API message 'sw_interface_rx_placement_dump'.
type SwInterfaceRxPlacementDump struct {
- SwIfIndex InterfaceIndex
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
}
func (m *SwInterfaceRxPlacementDump) Reset() { *m = SwInterfaceRxPlacementDump{} }
@@ -485,10 +2678,46 @@ func (*SwInterfaceRxPlacementDump) GetMessageName() string { return "sw
func (*SwInterfaceRxPlacementDump) GetCrcString() string { return "f9e6675e" }
func (*SwInterfaceRxPlacementDump) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceRxPlacementDump) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ return size
+}
+func (m *SwInterfaceRxPlacementDump) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceRxPlacementDump) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceSetFlags represents VPP binary API message 'sw_interface_set_flags'.
type SwInterfaceSetFlags struct {
- SwIfIndex InterfaceIndex
- Flags IfStatusFlags
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Flags IfStatusFlags `binapi:"if_status_flags,name=flags" json:"flags,omitempty"`
}
func (m *SwInterfaceSetFlags) Reset() { *m = SwInterfaceSetFlags{} }
@@ -496,9 +2725,53 @@ func (*SwInterfaceSetFlags) GetMessageName() string { return "sw_interf
func (*SwInterfaceSetFlags) GetCrcString() string { return "6a2b491a" }
func (*SwInterfaceSetFlags) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceSetFlags) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Flags
+ size += 4
+ return size
+}
+func (m *SwInterfaceSetFlags) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Flags
+ o.PutUint32(buf[pos:pos+4], uint32(m.Flags))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceSetFlags) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Flags
+ m.Flags = IfStatusFlags(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceSetFlagsReply represents VPP binary API message 'sw_interface_set_flags_reply'.
type SwInterfaceSetFlagsReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *SwInterfaceSetFlagsReply) Reset() { *m = SwInterfaceSetFlagsReply{} }
@@ -506,10 +2779,46 @@ func (*SwInterfaceSetFlagsReply) GetMessageName() string { return "sw_i
func (*SwInterfaceSetFlagsReply) GetCrcString() string { return "e8d4e804" }
func (*SwInterfaceSetFlagsReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceSetFlagsReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *SwInterfaceSetFlagsReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceSetFlagsReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceSetIPDirectedBroadcast represents VPP binary API message 'sw_interface_set_ip_directed_broadcast'.
type SwInterfaceSetIPDirectedBroadcast struct {
- SwIfIndex InterfaceIndex
- Enable bool
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Enable bool `binapi:"bool,name=enable" json:"enable,omitempty"`
}
func (m *SwInterfaceSetIPDirectedBroadcast) Reset() { *m = SwInterfaceSetIPDirectedBroadcast{} }
@@ -519,9 +2828,55 @@ func (*SwInterfaceSetIPDirectedBroadcast) GetMessageName() string {
func (*SwInterfaceSetIPDirectedBroadcast) GetCrcString() string { return "ae6cfcfb" }
func (*SwInterfaceSetIPDirectedBroadcast) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceSetIPDirectedBroadcast) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Enable
+ size += 1
+ return size
+}
+func (m *SwInterfaceSetIPDirectedBroadcast) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Enable
+ if m.Enable {
+ buf[pos] = 1
+ }
+ pos += 1
+ return buf, nil
+}
+func (m *SwInterfaceSetIPDirectedBroadcast) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Enable
+ m.Enable = tmp[pos] != 0
+ pos += 1
+ return nil
+}
+
// SwInterfaceSetIPDirectedBroadcastReply represents VPP binary API message 'sw_interface_set_ip_directed_broadcast_reply'.
type SwInterfaceSetIPDirectedBroadcastReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *SwInterfaceSetIPDirectedBroadcastReply) Reset() {
@@ -535,10 +2890,46 @@ func (*SwInterfaceSetIPDirectedBroadcastReply) GetMessageType() api.MessageType
return api.ReplyMessage
}
+func (m *SwInterfaceSetIPDirectedBroadcastReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *SwInterfaceSetIPDirectedBroadcastReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceSetIPDirectedBroadcastReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceSetMacAddress represents VPP binary API message 'sw_interface_set_mac_address'.
type SwInterfaceSetMacAddress struct {
- SwIfIndex InterfaceIndex
- MacAddress MacAddress
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ MacAddress MacAddress `binapi:"mac_address,name=mac_address" json:"mac_address,omitempty"`
}
func (m *SwInterfaceSetMacAddress) Reset() { *m = SwInterfaceSetMacAddress{} }
@@ -546,9 +2937,61 @@ func (*SwInterfaceSetMacAddress) GetMessageName() string { return "sw_i
func (*SwInterfaceSetMacAddress) GetCrcString() string { return "6aca746a" }
func (*SwInterfaceSetMacAddress) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceSetMacAddress) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.MacAddress
+ size += 6
+ return size
+}
+func (m *SwInterfaceSetMacAddress) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.MacAddress
+ for i := 0; i < 6; i++ {
+ var x uint8
+ if i < len(m.MacAddress) {
+ x = uint8(m.MacAddress[i])
+ }
+ buf[pos] = uint8(x)
+ pos += 1
+ }
+ return buf, nil
+}
+func (m *SwInterfaceSetMacAddress) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.MacAddress
+ for i := 0; i < len(m.MacAddress); i++ {
+ m.MacAddress[i] = uint8(tmp[pos])
+ pos += 1
+ }
+ return nil
+}
+
// SwInterfaceSetMacAddressReply represents VPP binary API message 'sw_interface_set_mac_address_reply'.
type SwInterfaceSetMacAddressReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *SwInterfaceSetMacAddressReply) Reset() { *m = SwInterfaceSetMacAddressReply{} }
@@ -558,10 +3001,46 @@ func (*SwInterfaceSetMacAddressReply) GetMessageName() string {
func (*SwInterfaceSetMacAddressReply) GetCrcString() string { return "e8d4e804" }
func (*SwInterfaceSetMacAddressReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceSetMacAddressReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *SwInterfaceSetMacAddressReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceSetMacAddressReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceSetMtu represents VPP binary API message 'sw_interface_set_mtu'.
type SwInterfaceSetMtu struct {
- SwIfIndex InterfaceIndex
- Mtu []uint32 `struc:"[4]uint32"`
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ Mtu []uint32 `binapi:"u32[4],name=mtu" json:"mtu,omitempty" struc:"[4]uint32"`
}
func (m *SwInterfaceSetMtu) Reset() { *m = SwInterfaceSetMtu{} }
@@ -569,9 +3048,62 @@ func (*SwInterfaceSetMtu) GetMessageName() string { return "sw_interfac
func (*SwInterfaceSetMtu) GetCrcString() string { return "5cbe85e5" }
func (*SwInterfaceSetMtu) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceSetMtu) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.Mtu
+ size += 16
+ return size
+}
+func (m *SwInterfaceSetMtu) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.Mtu
+ for i := 0; i < 4; i++ {
+ var x uint32
+ if i < len(m.Mtu) {
+ x = uint32(m.Mtu[i])
+ }
+ o.PutUint32(buf[pos:pos+4], uint32(x))
+ pos += 4
+ }
+ return buf, nil
+}
+func (m *SwInterfaceSetMtu) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Mtu
+ m.Mtu = make([]uint32, 4)
+ for i := 0; i < len(m.Mtu); i++ {
+ m.Mtu[i] = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ }
+ return nil
+}
+
// SwInterfaceSetMtuReply represents VPP binary API message 'sw_interface_set_mtu_reply'.
type SwInterfaceSetMtuReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *SwInterfaceSetMtuReply) Reset() { *m = SwInterfaceSetMtuReply{} }
@@ -579,12 +3111,48 @@ func (*SwInterfaceSetMtuReply) GetMessageName() string { return "sw_int
func (*SwInterfaceSetMtuReply) GetCrcString() string { return "e8d4e804" }
func (*SwInterfaceSetMtuReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceSetMtuReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *SwInterfaceSetMtuReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceSetMtuReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceSetRxMode represents VPP binary API message 'sw_interface_set_rx_mode'.
type SwInterfaceSetRxMode struct {
- SwIfIndex InterfaceIndex
- QueueIDValid bool
- QueueID uint32
- Mode RxMode
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ QueueIDValid bool `binapi:"bool,name=queue_id_valid" json:"queue_id_valid,omitempty"`
+ QueueID uint32 `binapi:"u32,name=queue_id" json:"queue_id,omitempty"`
+ Mode RxMode `binapi:"rx_mode,name=mode" json:"mode,omitempty"`
}
func (m *SwInterfaceSetRxMode) Reset() { *m = SwInterfaceSetRxMode{} }
@@ -592,9 +3160,71 @@ func (*SwInterfaceSetRxMode) GetMessageName() string { return "sw_inter
func (*SwInterfaceSetRxMode) GetCrcString() string { return "780f5cee" }
func (*SwInterfaceSetRxMode) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceSetRxMode) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.QueueIDValid
+ size += 1
+ // field[1] m.QueueID
+ size += 4
+ // field[1] m.Mode
+ size += 4
+ return size
+}
+func (m *SwInterfaceSetRxMode) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.QueueIDValid
+ if m.QueueIDValid {
+ buf[pos] = 1
+ }
+ pos += 1
+ // field[1] m.QueueID
+ o.PutUint32(buf[pos:pos+4], uint32(m.QueueID))
+ pos += 4
+ // field[1] m.Mode
+ o.PutUint32(buf[pos:pos+4], uint32(m.Mode))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceSetRxMode) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.QueueIDValid
+ m.QueueIDValid = tmp[pos] != 0
+ pos += 1
+ // field[1] m.QueueID
+ m.QueueID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.Mode
+ m.Mode = RxMode(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceSetRxModeReply represents VPP binary API message 'sw_interface_set_rx_mode_reply'.
type SwInterfaceSetRxModeReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *SwInterfaceSetRxModeReply) Reset() { *m = SwInterfaceSetRxModeReply{} }
@@ -602,12 +3232,48 @@ func (*SwInterfaceSetRxModeReply) GetMessageName() string { return "sw_
func (*SwInterfaceSetRxModeReply) GetCrcString() string { return "e8d4e804" }
func (*SwInterfaceSetRxModeReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceSetRxModeReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *SwInterfaceSetRxModeReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.Retval
+ o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
+ pos += 4
+ return buf, nil
+}
+func (m *SwInterfaceSetRxModeReply) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.Retval
+ m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ return nil
+}
+
// SwInterfaceSetRxPlacement represents VPP binary API message 'sw_interface_set_rx_placement'.
type SwInterfaceSetRxPlacement struct {
- SwIfIndex InterfaceIndex
- QueueID uint32
- WorkerID uint32
- IsMain bool
+ SwIfIndex InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
+ QueueID uint32 `binapi:"u32,name=queue_id" json:"queue_id,omitempty"`
+ WorkerID uint32 `binapi:"u32,name=worker_id" json:"worker_id,omitempty"`
+ IsMain bool `binapi:"bool,name=is_main" json:"is_main,omitempty"`
}
func (m *SwInterfaceSetRxPlacement) Reset() { *m = SwInterfaceSetRxPlacement{} }
@@ -615,9 +3281,71 @@ func (*SwInterfaceSetRxPlacement) GetMessageName() string { return "sw_
func (*SwInterfaceSetRxPlacement) GetCrcString() string { return "db65f3c9" }
func (*SwInterfaceSetRxPlacement) GetMessageType() api.MessageType { return api.RequestMessage }
+func (m *SwInterfaceSetRxPlacement) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.SwIfIndex
+ size += 4
+ // field[1] m.QueueID
+ size += 4
+ // field[1] m.WorkerID
+ size += 4
+ // field[1] m.IsMain
+ size += 1
+ return size
+}
+func (m *SwInterfaceSetRxPlacement) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ var buf []byte
+ if b == nil {
+ buf = make([]byte, m.Size())
+ } else {
+ buf = b
+ }
+ // field[1] m.SwIfIndex
+ o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
+ pos += 4
+ // field[1] m.QueueID
+ o.PutUint32(buf[pos:pos+4], uint32(m.QueueID))
+ pos += 4
+ // field[1] m.WorkerID
+ o.PutUint32(buf[pos:pos+4], uint32(m.WorkerID))
+ pos += 4
+ // field[1] m.IsMain
+ if m.IsMain {
+ buf[pos] = 1
+ }
+ pos += 1
+ return buf, nil
+}
+func (m *SwInterfaceSetRxPlacement) Unmarshal(tmp []byte) error {
+ o := binary.BigEndian
+ _ = o
+ pos := 0
+ _ = pos
+ // field[1] m.SwIfIndex
+ m.SwIfIndex = InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.QueueID
+ m.QueueID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.WorkerID
+ m.WorkerID = uint32(o.Uint32(tmp[pos : pos+4]))
+ pos += 4
+ // field[1] m.IsMain
+ m.IsMain = tmp[pos] != 0
+ pos += 1
+ return nil
+}
+
// SwInterfaceSetRxPlacementReply represents VPP binary API message 'sw_interface_set_rx_placement_reply'.
type SwInterfaceSetRxPlacementReply struct {
- Retval int32
+ Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
}
func (m *SwInterfaceSetRxPlacementReply) Reset() { *m = SwInterfaceSetRxPlacementReply{} }
@@ -627,11 +3355,47 @@ func (*SwInterfaceSetRxPlacementReply) GetMessageName() string {
func (*SwInterfaceSetRxPlacementReply) GetCrcString() string { return "e8d4e804" }
func (*SwInterfaceSetRxPlacementReply) GetMessageType() api.MessageType { return api.ReplyMessage }
+func (m *SwInterfaceSetRxPlacementReply) Size() int {
+ if m == nil {
+ return 0
+ }
+ var size int
+ // field[1] m.Retval
+ size += 4
+ return size
+}
+func (m *SwInterfaceSetRxPlacementReply) Marshal(b []byte) ([]byte, error) {
+ o := binary.BigEndian
+ _ = o