├── binapigen ├── vppapi │ ├── testdata │ │ ├── input.txt │ │ ├── input-read-json-error.json │ │ └── input-generate-error.json │ ├── log.go │ ├── integration_test.go │ └── input_test.go ├── binapigen_test.go ├── log.go ├── generate.go └── strings_test.go ├── docs ├── govpp-logo.png ├── RELEASE.md └── GENERATOR.md ├── api ├── doc.go ├── errors_test.go └── trace.go ├── codec ├── doc.go ├── bench_test.go └── marshaler.go ├── .github ├── ci │ └── yamllint.yml ├── dependabot.yml ├── workflows │ ├── test.yaml │ └── release.yaml └── ISSUE_TEMPLATE │ └── bug_report.md ├── Dockerfile.govpp ├── extras ├── libmemif │ └── doc.go ├── .gitignore ├── test │ ├── build │ │ ├── vpp.conf │ │ └── Dockerfile.extras │ └── run_integration.sh ├── go.mod ├── Makefile └── gomemif │ ├── README.rst │ └── memif │ ├── interface_unsafe.go │ ├── control_channel_unsafe.go │ └── memif_unsafe.go ├── test ├── build │ ├── vpp.conf │ └── Dockerfile.integration ├── performance │ └── binapi_bench_test.go ├── integration │ ├── main_test.go │ ├── examples_test.go │ ├── trace_test.go │ └── README.md └── run_integration.sh ├── .golangci.yml ├── .gitignore ├── adapter ├── doc.go ├── socketclient │ └── doc.go ├── vpp_api.go └── mock │ ├── mock_stats_adapter.go │ └── binapi │ └── binapi_reflect.go ├── core ├── genericpool │ └── generic_pool.go ├── control_ping.go ├── request_handler_test.go ├── log.go └── stream_test.go ├── proxy ├── log.go └── proxy.go ├── examples ├── README.md ├── api-trace │ └── README.md └── multi-vpp │ └── README.md ├── binapi ├── auto_sdl │ └── auto_sdl_rpc.ba.go ├── cdp │ └── cdp_rpc.ba.go ├── ct6 │ └── ct6_rpc.ba.go ├── mdata │ └── mdata_rpc.ba.go ├── npt66 │ └── npt66_rpc.ba.go ├── oddbuf │ └── oddbuf_rpc.ba.go ├── ping │ └── ping_rpc.ba.go ├── gso │ └── gso_rpc.ba.go ├── rd_cp │ └── rd_cp_rpc.ba.go ├── tls_openssl │ └── tls_openssl_rpc.ba.go ├── tcp │ └── tcp_rpc.ba.go ├── tracenode │ └── tracenode_rpc.ba.go ├── ioam_cache │ └── ioam_cache_rpc.ba.go ├── ioam_export │ └── ioam_export_rpc.ba.go ├── dhcp6_ia_na_client_cp │ └── dhcp6_ia_na_client_cp_rpc.ba.go ├── crypto_sw_scheduler │ └── crypto_sw_scheduler_rpc.ba.go ├── gen.go ├── vxlan_gpe_ioam_export │ └── vxlan_gpe_ioam_export_rpc.ba.go ├── arping │ └── arping_rpc.ba.go ├── avf │ └── avf_rpc.ba.go ├── idpf │ └── idpf_rpc.ba.go ├── pci_types │ └── pci_types.ba.go ├── af_xdp │ └── af_xdp_rpc.ba.go ├── udp_ping │ └── udp_ping_rpc.ba.go ├── p2p_ethernet │ └── p2p_ethernet_rpc.ba.go ├── feature │ └── feature_rpc.ba.go ├── http_static │ └── http_static_rpc.ba.go ├── sr_mobile │ └── sr_mobile_rpc.ba.go ├── bpf_trace_filter │ └── bpf_trace_filter_rpc.ba.go ├── vpe │ ├── vpe_http.ba.go │ └── vpe_rpc.ba.go ├── adl │ └── adl_rpc.ba.go ├── dhcp6_pd_client_cp │ └── dhcp6_pd_client_cp_rpc.ba.go ├── trace │ └── trace_rpc.ba.go ├── crypto │ └── crypto_rpc.ba.go ├── graph │ └── graph_rpc.ba.go ├── sr_mobile_types │ └── sr_mobile_types.ba.go ├── ethernet_types │ └── ethernet_types.ba.go ├── lacp │ └── lacp_rpc.ba.go ├── dev │ └── dev_rpc.ba.go ├── gre │ └── gre_rpc.ba.go ├── dns │ └── dns_rpc.ba.go ├── syslog │ └── syslog_rpc.ba.go ├── teib │ └── teib_rpc.ba.go ├── stn │ └── stn_rpc.ba.go ├── fib │ └── fib_rpc.ba.go ├── nsim │ └── nsim_rpc.ba.go ├── flow │ └── flow_rpc.ba.go ├── mss_clamp │ └── mss_clamp_rpc.ba.go ├── rdma │ └── rdma_rpc.ba.go ├── span │ └── span_rpc.ba.go ├── pipe │ └── pipe_rpc.ba.go ├── lldp │ └── lldp_rpc.ba.go ├── sr_pt │ └── sr_pt_rpc.ba.go ├── urpf │ └── urpf_rpc.ba.go ├── sr_mpls │ └── sr_mpls_rpc.ba.go ├── mactime │ └── mactime_rpc.ba.go ├── pppoe │ └── pppoe_rpc.ba.go ├── pvti │ └── pvti_rpc.ba.go ├── l3xc │ └── l3xc_rpc.ba.go ├── udp │ └── udp_rpc.ba.go ├── tapv2 │ └── tapv2_rpc.ba.go ├── pot │ └── pot_rpc.ba.go ├── virtio │ └── virtio_rpc.ba.go ├── geneve │ └── geneve_rpc.ba.go └── ioam_vxlan_gpe │ └── ioam_vxlan_gpe_rpc.ba.go ├── gen.go ├── cmd ├── govpp │ ├── main.go │ ├── util.go │ ├── log.go │ └── options.go └── binapi-generator │ └── doc.go ├── Dockerfile ├── doc.go ├── INFO.yaml ├── go.mod ├── govpp.go └── .goreleaser.yml /binapigen/vppapi/testdata/input.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /binapigen/vppapi/testdata/input-read-json-error.json: -------------------------------------------------------------------------------- 1 | % -------------------------------------------------------------------------------- /binapigen/vppapi/testdata/input-generate-error.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "value" 3 | } -------------------------------------------------------------------------------- /docs/govpp-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FDio/govpp/HEAD/docs/govpp-logo.png -------------------------------------------------------------------------------- /api/doc.go: -------------------------------------------------------------------------------- 1 | // Package api defines interfaces required by every file generated with binapi-generator 2 | package api 3 | -------------------------------------------------------------------------------- /codec/doc.go: -------------------------------------------------------------------------------- 1 | // Package codec provides methods allowing to encode and decode message structs to/from binary format accepted by VPP. 2 | package codec 3 | -------------------------------------------------------------------------------- /.github/ci/yamllint.yml: -------------------------------------------------------------------------------- 1 | --- 2 | extends: relaxed 3 | 4 | yaml-files: 5 | - '*.yaml' 6 | - '*.yml' 7 | 8 | rules: 9 | truthy: disable 10 | # 80 chars should be enough, but don't fail if a line is longer 11 | line-length: disable 12 | -------------------------------------------------------------------------------- /Dockerfile.govpp: -------------------------------------------------------------------------------- 1 | FROM alpine:3.22 2 | 3 | RUN set -eux; \ 4 | apk add --no-cache \ 5 | bash \ 6 | git \ 7 | make \ 8 | python3 \ 9 | py3-ply 10 | 11 | COPY govpp / 12 | 13 | ENTRYPOINT ["/govpp"] 14 | -------------------------------------------------------------------------------- /extras/libmemif/doc.go: -------------------------------------------------------------------------------- 1 | // Package libmemif is a Golang adapter for the libmemif library 2 | // (extras/libmemif in the VPP repository). To differentiate between the adapter 3 | // and the underlying C-written library, labels "Go-libmemif" and "C-libmemif" 4 | // are used in the documentation. 5 | package libmemif 6 | -------------------------------------------------------------------------------- /extras/.gitignore: -------------------------------------------------------------------------------- 1 | # libmemif 2 | libmemif/examples/gopacket/gopacket 3 | libmemif/examples/icmp-responder/icmp-responder 4 | libmemif/examples/jumbo-frames/jumbo-frames 5 | libmemif/examples/raw-data/raw-data 6 | gomemif/examples/bridge/bridge 7 | gomemif/examples/icmp_responder_cb/icmp_responder_cb 8 | gomemif/examples/icmp_responder_poll/icmp_responder_poll 9 | -------------------------------------------------------------------------------- /test/build/vpp.conf: -------------------------------------------------------------------------------- 1 | unix { 2 | nodaemon 3 | log /var/log/vpp.log 4 | cli-listen /run/vpp/cli.sock 5 | cli-no-pager 6 | full-coredump 7 | pidfile /run/vpp/vpp.pid 8 | } 9 | api-trace { 10 | on 11 | } 12 | socksvr { 13 | socket-name /run/vpp/api.sock 14 | } 15 | statseg { 16 | socket-name /run/vpp/stats.sock 17 | per-node-counters on 18 | } 19 | plugins { 20 | plugin dpdk_plugin.so { disable } 21 | } 22 | -------------------------------------------------------------------------------- /extras/test/build/vpp.conf: -------------------------------------------------------------------------------- 1 | unix { 2 | nodaemon 3 | log /var/log/vpp.log 4 | cli-listen /run/vpp/cli.sock 5 | cli-no-pager 6 | full-coredump 7 | pidfile /run/vpp/vpp.pid 8 | } 9 | api-trace { 10 | on 11 | } 12 | socksvr { 13 | socket-name /run/vpp/api.sock 14 | } 15 | statseg { 16 | socket-name /run/vpp/stats.sock 17 | per-node-counters on 18 | } 19 | plugins { 20 | plugin dpdk_plugin.so { disable } 21 | } 22 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | linters: 3 | exclusions: 4 | generated: lax 5 | presets: 6 | - comments 7 | - common-false-positives 8 | - legacy 9 | - std-error-handling 10 | paths: 11 | - .*\.ba.\.go$ 12 | - adapter/mock 13 | - third_party$ 14 | - builtin$ 15 | - examples$ 16 | formatters: 17 | exclusions: 18 | generated: lax 19 | paths: 20 | - third_party$ 21 | - builtin$ 22 | - examples$ 23 | -------------------------------------------------------------------------------- /api/errors_test.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "testing" 5 | 6 | . "github.com/onsi/gomega" 7 | ) 8 | 9 | func TestUnspecified(t *testing.T) { 10 | RegisterTestingT(t) 11 | 12 | var err error = VPPApiError(-1) 13 | errstr := err.Error() 14 | Expect(errstr).Should(BeEquivalentTo("VPPApiError: Unspecified Error (-1)")) 15 | } 16 | 17 | func TestUnknown(t *testing.T) { 18 | RegisterTestingT(t) 19 | 20 | var err error = VPPApiError(-999) 21 | errstr := err.Error() 22 | Expect(errstr).Should(BeEquivalentTo("VPPApiError: -999")) 23 | } 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.log 3 | *.out 4 | *.test 5 | 6 | .idea/ 7 | 8 | .cache/ 9 | 10 | /bin/ 11 | /dist/ 12 | /govpp 13 | 14 | # cmd 15 | cmd/binapi-generator/binapi-generator 16 | cmd/vpp-proxy/vpp-proxy 17 | cmd/govpp/govpp 18 | 19 | # examples 20 | examples/api-trace/api-trace 21 | examples/multi-vpp/multi-vpp 22 | examples/perf-bench/perf-bench 23 | examples/rpc-service/rpc-service 24 | examples/simple-client/simple-client 25 | examples/stats-client/stats-client 26 | examples/stream-client/stream-client 27 | examples/union-example/union-example 28 | 29 | /govpp -------------------------------------------------------------------------------- /adapter/doc.go: -------------------------------------------------------------------------------- 1 | // Package adapter provides an interface between govpp core and the VPP. It is responsible for sending 2 | // and receiving binary-encoded data to/from VPP via shared memory. 3 | // 4 | // The default adapter being used for connection with real VPP is called vppapiclient. It is based on the 5 | // communication with the vppapiclient VPP library written in C via CGO. 6 | // 7 | // Apart from the vppapiclient adapter, mock adapter is provided for unit/integration testing where the actual 8 | // communication with VPP is not demanded. 9 | package adapter 10 | -------------------------------------------------------------------------------- /core/genericpool/generic_pool.go: -------------------------------------------------------------------------------- 1 | package genericpool 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | type Resettable interface { 8 | Reset() 9 | } 10 | 11 | type Pool[T any] struct { 12 | p sync.Pool 13 | } 14 | 15 | func (p *Pool[T]) Get() T { 16 | return p.p.Get().(T) 17 | } 18 | 19 | func (p *Pool[T]) Put(x T) { 20 | if res, ok := any(x).(Resettable); ok { 21 | res.Reset() 22 | } 23 | p.p.Put(x) 24 | } 25 | 26 | func New[T any](f func() T) *Pool[T] { 27 | return &Pool[T]{ 28 | p: sync.Pool{ 29 | New: func() any { return f() }, 30 | }, 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /extras/go.mod: -------------------------------------------------------------------------------- 1 | module go.fd.io/govpp/extras 2 | 3 | go 1.22 4 | 5 | require ( 6 | github.com/google/gopacket v1.1.17 7 | github.com/pkg/profile v1.7.0 8 | github.com/sirupsen/logrus v1.9.3 9 | go.fd.io/govpp v0.10.0 10 | ) 11 | 12 | require ( 13 | github.com/felixge/fgprof v0.9.3 // indirect 14 | github.com/fsnotify/fsnotify v1.7.0 // indirect 15 | github.com/ftrvxmtrx/fd v0.0.0-20150925145434-c6d800382fff // indirect 16 | github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect 17 | github.com/lunixbochs/struc v0.0.0-20200521075829-a4cb8d33dbbe // indirect 18 | github.com/mitchellh/go-ps v1.0.0 // indirect 19 | golang.org/x/sys v0.16.0 // indirect 20 | ) 21 | -------------------------------------------------------------------------------- /core/control_ping.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "go.fd.io/govpp/api" 5 | "go.fd.io/govpp/binapi/memclnt" 6 | ) 7 | 8 | var ( 9 | msgControlPing api.Message = new(ControlPing) 10 | msgControlPingReply api.Message = new(ControlPingReply) 11 | ) 12 | 13 | // SetControlPing sets the control ping message used by core. 14 | func SetControlPing(m api.Message) { 15 | msgControlPing = m 16 | } 17 | 18 | // SetControlPingReply sets the control ping reply message used by core. 19 | func SetControlPingReply(m api.Message) { 20 | msgControlPingReply = m 21 | } 22 | 23 | type ( 24 | ControlPing = memclnt.ControlPing 25 | ControlPingReply = memclnt.ControlPingReply 26 | ) 27 | -------------------------------------------------------------------------------- /proxy/log.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "io" 5 | "os" 6 | 7 | "github.com/sirupsen/logrus" 8 | ) 9 | 10 | var ( 11 | debug = os.Getenv("DEBUG_GOVPP_PROXY") != "" 12 | 13 | log = logrus.New() 14 | ) 15 | 16 | func init() { 17 | if debug { 18 | log.Level = logrus.DebugLevel 19 | log.Debugf("govpp/proxy: debug mode enabled") 20 | } 21 | } 22 | 23 | // SetLogger sets logger. 24 | func SetLogger(l *logrus.Logger) { 25 | log = l 26 | } 27 | 28 | // SetLogLevel sets log level for logger. 29 | func SetLogLevel(lvl logrus.Level) { 30 | log.Level = lvl 31 | } 32 | 33 | // SetOutput sets log output for logger. 34 | func SetLogOutput(out io.Writer) { 35 | log.Out = out 36 | } 37 | -------------------------------------------------------------------------------- /binapigen/binapigen_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package binapigen 16 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | Here is a list of code examples demonstrating various GoVPP features: 4 | 5 | - [api-trace](api-trace) - trace sent/received messages 6 | - [binapi-types](binapi-types) - using common types from generated code 7 | - [multi-vpp](multi-vpp) - connect to multiple VPP instances 8 | - [perf-bench](perf-bench) - very basic performance test for measuring throughput 9 | - [rpc-service](rpc-service) - effortless way to call VPP API via RPC client 10 | - [simple-client](simple-client) - send and receive VPP API messages using GoVPP API directly 11 | - [stats-client](stats-client) - client for retrieving VPP stats data 12 | - [stream-client](stream-client) - using new stream API to call VPP API 13 | -------------------------------------------------------------------------------- /extras/Makefile: -------------------------------------------------------------------------------- 1 | GO ?= GO111MODULE=on go 2 | 3 | build: extras 4 | 5 | extras: 6 | @echo "=> building extras" 7 | cd libmemif/examples/gopacket && $(GO) build -v 8 | cd libmemif/examples/icmp-responder && $(GO) build -v 9 | cd libmemif/examples/jumbo-frames && $(GO) build -v 10 | cd libmemif/examples/raw-data && $(GO) build -v 11 | cd gomemif/examples/bridge && $(GO) build -v 12 | cd gomemif/examples/icmp_responder_cb && $(GO) build -v 13 | cd gomemif/examples/icmp_responder_poll && $(GO) build -v 14 | 15 | clean: 16 | @echo "=> cleaning extras" 17 | go clean -v ./... 18 | 19 | test-extras: extras 20 | ## Run extras integration tests 21 | @echo "# running extras integration tests" 22 | VPP_REPO=$(VPP_REPO) ./test/run_integration.sh 23 | 24 | .PHONY: build extras clean 25 | -------------------------------------------------------------------------------- /binapi/auto_sdl/auto_sdl_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package auto_sdl 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service auto_sdl. 12 | type RPCService interface { 13 | AutoSdlConfig(ctx context.Context, in *AutoSdlConfig) (*AutoSdlConfigReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) AutoSdlConfig(ctx context.Context, in *AutoSdlConfig) (*AutoSdlConfigReply, error) { 25 | out := new(AutoSdlConfigReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/cdp/cdp_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package cdp 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service cdp. 12 | type RPCService interface { 13 | CdpEnableDisable(ctx context.Context, in *CdpEnableDisable) (*CdpEnableDisableReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) CdpEnableDisable(ctx context.Context, in *CdpEnableDisable) (*CdpEnableDisableReply, error) { 25 | out := new(CdpEnableDisableReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/ct6/ct6_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package ct6 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service ct6. 12 | type RPCService interface { 13 | Ct6EnableDisable(ctx context.Context, in *Ct6EnableDisable) (*Ct6EnableDisableReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) Ct6EnableDisable(ctx context.Context, in *Ct6EnableDisable) (*Ct6EnableDisableReply, error) { 25 | out := new(Ct6EnableDisableReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/mdata/mdata_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package mdata 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service mdata. 12 | type RPCService interface { 13 | MdataEnableDisable(ctx context.Context, in *MdataEnableDisable) (*MdataEnableDisableReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) MdataEnableDisable(ctx context.Context, in *MdataEnableDisable) (*MdataEnableDisableReply, error) { 25 | out := new(MdataEnableDisableReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/npt66/npt66_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package npt66 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service npt66. 12 | type RPCService interface { 13 | Npt66BindingAddDel(ctx context.Context, in *Npt66BindingAddDel) (*Npt66BindingAddDelReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) Npt66BindingAddDel(ctx context.Context, in *Npt66BindingAddDel) (*Npt66BindingAddDelReply, error) { 25 | out := new(Npt66BindingAddDelReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/oddbuf/oddbuf_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package oddbuf 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service oddbuf. 12 | type RPCService interface { 13 | OddbufEnableDisable(ctx context.Context, in *OddbufEnableDisable) (*OddbufEnableDisableReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) OddbufEnableDisable(ctx context.Context, in *OddbufEnableDisable) (*OddbufEnableDisableReply, error) { 25 | out := new(OddbufEnableDisableReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/ping/ping_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package ping 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service ping. 12 | type RPCService interface { 13 | WantPingFinishedEvents(ctx context.Context, in *WantPingFinishedEvents) (*WantPingFinishedEventsReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) WantPingFinishedEvents(ctx context.Context, in *WantPingFinishedEvents) (*WantPingFinishedEventsReply, error) { 25 | out := new(WantPingFinishedEventsReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/gso/gso_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package gso 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service gso. 12 | type RPCService interface { 13 | FeatureGsoEnableDisable(ctx context.Context, in *FeatureGsoEnableDisable) (*FeatureGsoEnableDisableReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) FeatureGsoEnableDisable(ctx context.Context, in *FeatureGsoEnableDisable) (*FeatureGsoEnableDisableReply, error) { 25 | out := new(FeatureGsoEnableDisableReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/rd_cp/rd_cp_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package rd_cp 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service rd_cp. 12 | type RPCService interface { 13 | IP6NdAddressAutoconfig(ctx context.Context, in *IP6NdAddressAutoconfig) (*IP6NdAddressAutoconfigReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) IP6NdAddressAutoconfig(ctx context.Context, in *IP6NdAddressAutoconfig) (*IP6NdAddressAutoconfigReply, error) { 25 | out := new(IP6NdAddressAutoconfigReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/tls_openssl/tls_openssl_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package tls_openssl 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service tls_openssl. 12 | type RPCService interface { 13 | TLSOpensslSetEngine(ctx context.Context, in *TLSOpensslSetEngine) (*TLSOpensslSetEngineReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) TLSOpensslSetEngine(ctx context.Context, in *TLSOpensslSetEngine) (*TLSOpensslSetEngineReply, error) { 25 | out := new(TLSOpensslSetEngineReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/tcp/tcp_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package tcp 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service tcp. 12 | type RPCService interface { 13 | TCPConfigureSrcAddresses(ctx context.Context, in *TCPConfigureSrcAddresses) (*TCPConfigureSrcAddressesReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) TCPConfigureSrcAddresses(ctx context.Context, in *TCPConfigureSrcAddresses) (*TCPConfigureSrcAddressesReply, error) { 25 | out := new(TCPConfigureSrcAddressesReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Dependabot configuration 2 | # 3 | # See docs: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 4 | --- 5 | version: 2 6 | updates: 7 | 8 | # Maintain dependencies for GitHub Actions 9 | - package-ecosystem: "github-actions" 10 | directory: "/" 11 | schedule: 12 | interval: "weekly" 13 | labels: 14 | - "dependencies" 15 | reviewers: 16 | - "FDio/govpp-committers" 17 | groups: 18 | github-deps: 19 | patterns: 20 | - "*" 21 | 22 | # Maintain dependencies for Go modules 23 | - package-ecosystem: "gomod" 24 | directory: "/" 25 | schedule: 26 | interval: "weekly" 27 | labels: 28 | - "dependencies" 29 | reviewers: 30 | - "FDio/govpp-committers" 31 | groups: 32 | go-deps: 33 | patterns: 34 | - "*" 35 | -------------------------------------------------------------------------------- /binapi/tracenode/tracenode_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package tracenode 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service tracenode. 12 | type RPCService interface { 13 | TracenodeEnableDisable(ctx context.Context, in *TracenodeEnableDisable) (*TracenodeEnableDisableReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) TracenodeEnableDisable(ctx context.Context, in *TracenodeEnableDisable) (*TracenodeEnableDisableReply, error) { 25 | out := new(TracenodeEnableDisableReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /gen.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Cisco and/or its affiliates. 2 | // 3 | // SPDX-License-Identifier: Apache-2.0 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at: 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | package govpp 18 | 19 | //go:generate bash -c "docker run -e PKGPREFIX=$(go list)/binapi -v $(go list -f '{{ .Dir }}'):/gen $(docker build . -q --build-arg GOVPP_VERSION=$(go list -m -f '{{ .Version }}' go.fd.io/govpp))" 20 | -------------------------------------------------------------------------------- /binapi/ioam_cache/ioam_cache_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package ioam_cache 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service ioam_cache. 12 | type RPCService interface { 13 | IoamCacheIP6EnableDisable(ctx context.Context, in *IoamCacheIP6EnableDisable) (*IoamCacheIP6EnableDisableReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) IoamCacheIP6EnableDisable(ctx context.Context, in *IoamCacheIP6EnableDisable) (*IoamCacheIP6EnableDisableReply, error) { 25 | out := new(IoamCacheIP6EnableDisableReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/ioam_export/ioam_export_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package ioam_export 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service ioam_export. 12 | type RPCService interface { 13 | IoamExportIP6EnableDisable(ctx context.Context, in *IoamExportIP6EnableDisable) (*IoamExportIP6EnableDisableReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) IoamExportIP6EnableDisable(ctx context.Context, in *IoamExportIP6EnableDisable) (*IoamExportIP6EnableDisableReply, error) { 25 | out := new(IoamExportIP6EnableDisableReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapigen/vppapi/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package vppapi 16 | 17 | import ( 18 | "log" 19 | "os" 20 | "strings" 21 | ) 22 | 23 | var debug = strings.Contains(os.Getenv("DEBUG_GOVPP"), "parser") 24 | 25 | func logf(f string, v ...interface{}) { 26 | if debug { 27 | log.Printf(f, v...) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/performance/binapi_bench_test.go: -------------------------------------------------------------------------------- 1 | package performance 2 | 3 | import ( 4 | "testing" 5 | 6 | "go.fd.io/govpp/binapi/memclnt" 7 | 8 | "go.fd.io/govpp/test/vpptesting" 9 | ) 10 | 11 | func BenchmarkBinapiControlPing(b *testing.B) { 12 | 13 | b.Run("1", func(b *testing.B) { 14 | benchBinapiControlPing(b, 1) 15 | }) 16 | b.Run("10", func(b *testing.B) { 17 | benchBinapiControlPing(b, 10) 18 | }) 19 | b.Run("100", func(b *testing.B) { 20 | benchBinapiControlPing(b, 100) 21 | }) 22 | } 23 | 24 | func benchBinapiControlPing(b *testing.B, repeatN int) { 25 | test := vpptesting.SetupVPP(b) 26 | ctx := test.Context 27 | 28 | c := memclnt.NewServiceClient(test.Conn) 29 | 30 | b.ResetTimer() 31 | for i := 0; i < b.N; i++ { 32 | for r := 0; r < repeatN; r++ { 33 | _, err := c.ControlPing(ctx, &memclnt.ControlPing{}) 34 | if err != nil { 35 | b.Fatalf("getting version failed: %v", err) 36 | } 37 | } 38 | } 39 | b.StopTimer() 40 | } 41 | -------------------------------------------------------------------------------- /binapi/dhcp6_ia_na_client_cp/dhcp6_ia_na_client_cp_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package dhcp6_ia_na_client_cp 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service dhcp6_ia_na_client_cp. 12 | type RPCService interface { 13 | DHCP6ClientEnableDisable(ctx context.Context, in *DHCP6ClientEnableDisable) (*DHCP6ClientEnableDisableReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) DHCP6ClientEnableDisable(ctx context.Context, in *DHCP6ClientEnableDisable) (*DHCP6ClientEnableDisableReply, error) { 25 | out := new(DHCP6ClientEnableDisableReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/crypto_sw_scheduler/crypto_sw_scheduler_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package crypto_sw_scheduler 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service crypto_sw_scheduler. 12 | type RPCService interface { 13 | CryptoSwSchedulerSetWorker(ctx context.Context, in *CryptoSwSchedulerSetWorker) (*CryptoSwSchedulerSetWorkerReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) CryptoSwSchedulerSetWorker(ctx context.Context, in *CryptoSwSchedulerSetWorker) (*CryptoSwSchedulerSetWorkerReply, error) { 25 | out := new(CryptoSwSchedulerSetWorkerReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /binapi/gen.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package binapi 16 | 17 | // To generate bindings for VPP API files in the default system directory, run: 18 | // 19 | // go generate ./binapi 20 | // 21 | //go:generate binapi-generator --input=/usr/share/vpp/api --output-dir=. --gen=rpc 22 | //go:generate binapi-generator --input=/usr/share/vpp/api --output-dir=. --gen=http vpe 23 | -------------------------------------------------------------------------------- /binapi/vxlan_gpe_ioam_export/vxlan_gpe_ioam_export_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package vxlan_gpe_ioam_export 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service vxlan_gpe_ioam_export. 12 | type RPCService interface { 13 | VxlanGpeIoamExportEnableDisable(ctx context.Context, in *VxlanGpeIoamExportEnableDisable) (*VxlanGpeIoamExportEnableDisableReply, error) 14 | } 15 | 16 | type serviceClient struct { 17 | conn api.Connection 18 | } 19 | 20 | func NewServiceClient(conn api.Connection) RPCService { 21 | return &serviceClient{conn} 22 | } 23 | 24 | func (c *serviceClient) VxlanGpeIoamExportEnableDisable(ctx context.Context, in *VxlanGpeIoamExportEnableDisable) (*VxlanGpeIoamExportEnableDisableReply, error) { 25 | out := new(VxlanGpeIoamExportEnableDisableReply) 26 | err := c.conn.Invoke(ctx, in, out) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return out, api.RetvalToVPPApiError(out.Retval) 31 | } 32 | -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Test 3 | on: 4 | # Runs on branch push to master & PRs 5 | push: 6 | branches: 7 | - master 8 | - release/* 9 | pull_request: 10 | paths-ignore: 11 | - 'docs/**' 12 | - '**.md' 13 | # Runs daily at 05:05 14 | schedule: 15 | - cron: '5 5 * * *' 16 | # Allows running manually 17 | workflow_dispatch: 18 | 19 | jobs: 20 | integration: 21 | name: "VPP Integration ${{ matrix.version }}" 22 | runs-on: ubuntu-latest 23 | env: 24 | VPP_REPO: ${{ matrix.version }} 25 | strategy: 26 | fail-fast: false 27 | matrix: 28 | version: 29 | - 'master' 30 | - '2510' 31 | - '2502' 32 | - '2406' 33 | 34 | steps: 35 | - name: "Checkout" 36 | uses: actions/checkout@v6 37 | 38 | - name: "Setup Go" 39 | uses: actions/setup-go@v6 40 | with: 41 | go-version: '1.25' 42 | 43 | - name: "Run Tests" 44 | run: | 45 | make test-integration 46 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Description** 11 | _A clear and concise description of what the bug is.._ 12 | 13 | **How to reproduce** 14 | Steps to reproduce the behavior: 15 | 1. _first.._ 16 | 2. _then.._ 17 | 3. _error.._ 18 | 19 | **Expected Behavior** 20 | _A clear and concise description of what you expected to happen._ 21 | 22 | **Screenshots/Logs** 23 | _If applicable, add screenshots to help explain your problem._ 24 | 25 | **Environment** (please complete the following information) 26 | | Info | Example | Value | 27 | |-----------------------|-----------------------------|-----------| 28 | | OS/arch | _e.g. linux/amd64_ | | 29 | | VPP version | _v24.02-release_ | | 30 | | GoVPP version | _v0.8.0_ | | 31 | 32 | **Additional context** 33 | _Add any other context about the problem here._ 34 | -------------------------------------------------------------------------------- /cmd/govpp/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "github.com/sirupsen/logrus" 19 | ) 20 | 21 | func main() { 22 | Execute() 23 | } 24 | 25 | func Execute() { 26 | cli, err := NewCli() 27 | if err != nil { 28 | logrus.Fatalf("CLI init error: %v", err) 29 | } 30 | root := newRootCmd(cli) 31 | 32 | if err := root.Execute(); err != nil { 33 | logrus.Fatalf("ERROR: %v", err) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /binapigen/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package binapigen 16 | 17 | import ( 18 | "os" 19 | "strings" 20 | 21 | "github.com/sirupsen/logrus" 22 | ) 23 | 24 | var Logger = logrus.New() 25 | 26 | func init() { 27 | if debug := os.Getenv("DEBUG_GOVPP"); strings.Contains(debug, "binapigen") { 28 | Logger.SetLevel(logrus.DebugLevel) 29 | logrus.SetLevel(logrus.DebugLevel) 30 | } 31 | } 32 | 33 | func logf(f string, v ...interface{}) { 34 | Logger.Debugf(f, v...) 35 | } 36 | -------------------------------------------------------------------------------- /extras/gomemif/README.rst: -------------------------------------------------------------------------------- 1 | .. _gomemif_doc: 2 | 3 | Gomemif library 4 | ======================= 5 | 6 | Memif library implemented in Go. The package contains 3 examples: Bridge and ICMP responder in interrupt and polling mode. 7 | 8 | setup and run 9 | ------------- 10 | To Build all examples 11 | 12 | :: 13 | 14 | cd .. && make extras 15 | 16 | To Run ICMP responder in interrupt mode: 17 | 18 | :: 19 | 20 | DBGvpp# create interface memif id 0 master 21 | DBGvpp# set int ip addr memif0/0 192.168.1.2/24 22 | DBGvpp# set int state memif0/0 up 23 | 24 | examples/icmp_responder_cb/icmp_responder_cb 25 | gomemif# start 26 | 27 | DBGvpp# ping 192.168.1.1 28 | 29 | To Run ICMP responder in polling mode: 30 | 31 | :: 32 | 33 | DBGvpp# create interface memif id 0 master 34 | DBGvpp# set int ip addr memif0/0 192.168.1.2/24 35 | DBGvpp# set int state memif0/0 up 36 | 37 | examples/icmp_responder_poll/icmp_responder_poll 38 | gomemif# start 39 | 40 | DBGvpp# ping 192.168.1.1 41 | 42 | To Run Bridge: 43 | 44 | :: 45 | 46 | examples/bridge/bridge 47 | gomemif# start 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /binapi/arping/arping_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package arping 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service arping. 12 | type RPCService interface { 13 | Arping(ctx context.Context, in *Arping) (*ArpingReply, error) 14 | ArpingAcd(ctx context.Context, in *ArpingAcd) (*ArpingAcdReply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) Arping(ctx context.Context, in *Arping) (*ArpingReply, error) { 26 | out := new(ArpingReply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) ArpingAcd(ctx context.Context, in *ArpingAcd) (*ArpingAcdReply, error) { 35 | out := new(ArpingAcdReply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/avf/avf_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package avf 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service avf. 12 | type RPCService interface { 13 | AvfCreate(ctx context.Context, in *AvfCreate) (*AvfCreateReply, error) 14 | AvfDelete(ctx context.Context, in *AvfDelete) (*AvfDeleteReply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) AvfCreate(ctx context.Context, in *AvfCreate) (*AvfCreateReply, error) { 26 | out := new(AvfCreateReply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) AvfDelete(ctx context.Context, in *AvfDelete) (*AvfDeleteReply, error) { 35 | out := new(AvfDeleteReply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/idpf/idpf_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package idpf 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service idpf. 12 | type RPCService interface { 13 | IdpfCreate(ctx context.Context, in *IdpfCreate) (*IdpfCreateReply, error) 14 | IdpfDelete(ctx context.Context, in *IdpfDelete) (*IdpfDeleteReply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) IdpfCreate(ctx context.Context, in *IdpfCreate) (*IdpfCreateReply, error) { 26 | out := new(IdpfCreateReply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) IdpfDelete(ctx context.Context, in *IdpfDelete) (*IdpfDeleteReply, error) { 35 | out := new(IdpfDeleteReply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/pci_types/pci_types.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | // versions: 3 | // binapi-generator: v0.12.0 4 | // VPP: 25.10-release 5 | // source: core/pci_types.api.json 6 | 7 | // Package pci_types contains generated bindings for API file pci_types.api. 8 | // 9 | // Contents: 10 | // - 1 struct 11 | package pci_types 12 | 13 | import ( 14 | api "go.fd.io/govpp/api" 15 | ) 16 | 17 | // This is a compile-time assertion to ensure that this generated file 18 | // is compatible with the GoVPP api package it is being compiled against. 19 | // A compilation error at this line likely means your copy of the 20 | // GoVPP api package needs to be updated. 21 | const _ = api.GoVppAPIPackageIsVersion2 22 | 23 | const ( 24 | APIFile = "pci_types" 25 | APIVersion = "1.0.0" 26 | VersionCrc = 0x5d418665 27 | ) 28 | 29 | // PciAddress defines type 'pci_address'. 30 | type PciAddress struct { 31 | Domain uint16 `binapi:"u16,name=domain" json:"domain,omitempty"` 32 | Bus uint8 `binapi:"u8,name=bus" json:"bus,omitempty"` 33 | Slot uint8 `binapi:"u8,name=slot" json:"slot,omitempty"` 34 | Function uint8 `binapi:"u8,name=function" json:"function,omitempty"` 35 | } 36 | -------------------------------------------------------------------------------- /binapi/af_xdp/af_xdp_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package af_xdp 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service af_xdp. 12 | type RPCService interface { 13 | AfXdpCreateV3(ctx context.Context, in *AfXdpCreateV3) (*AfXdpCreateV3Reply, error) 14 | AfXdpDelete(ctx context.Context, in *AfXdpDelete) (*AfXdpDeleteReply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) AfXdpCreateV3(ctx context.Context, in *AfXdpCreateV3) (*AfXdpCreateV3Reply, error) { 26 | out := new(AfXdpCreateV3Reply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) AfXdpDelete(ctx context.Context, in *AfXdpDelete) (*AfXdpDeleteReply, error) { 35 | out := new(AfXdpDeleteReply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /binapigen/vppapi/integration_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //go:build integration 16 | 17 | package vppapi_test 18 | 19 | import ( 20 | "encoding/json" 21 | "testing" 22 | 23 | "go.fd.io/govpp/binapigen/vppapi" 24 | ) 25 | 26 | func TestParse(t *testing.T) { 27 | files, err := vppapi.Parse() 28 | if err != nil { 29 | t.Fatal(err) 30 | } 31 | 32 | for _, file := range files { 33 | b, err := json.MarshalIndent(file, "\t", " ") 34 | if err != nil { 35 | t.Fatal(err) 36 | } 37 | t.Logf(" - %s:\n%s", file.Name, b) 38 | } 39 | 40 | t.Logf("parsed %d files", len(files)) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/udp_ping/udp_ping_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package udp_ping 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service udp_ping. 12 | type RPCService interface { 13 | UDPPingAddDel(ctx context.Context, in *UDPPingAddDel) (*UDPPingAddDelReply, error) 14 | UDPPingExport(ctx context.Context, in *UDPPingExport) (*UDPPingExportReply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) UDPPingAddDel(ctx context.Context, in *UDPPingAddDel) (*UDPPingAddDelReply, error) { 26 | out := new(UDPPingAddDelReply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) UDPPingExport(ctx context.Context, in *UDPPingExport) (*UDPPingExportReply, error) { 35 | out := new(UDPPingExportReply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/p2p_ethernet/p2p_ethernet_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package p2p_ethernet 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service p2p_ethernet. 12 | type RPCService interface { 13 | P2pEthernetAdd(ctx context.Context, in *P2pEthernetAdd) (*P2pEthernetAddReply, error) 14 | P2pEthernetDel(ctx context.Context, in *P2pEthernetDel) (*P2pEthernetDelReply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) P2pEthernetAdd(ctx context.Context, in *P2pEthernetAdd) (*P2pEthernetAddReply, error) { 26 | out := new(P2pEthernetAddReply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) P2pEthernetDel(ctx context.Context, in *P2pEthernetDel) (*P2pEthernetDelReply, error) { 35 | out := new(P2pEthernetDelReply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/feature/feature_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package feature 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service feature. 12 | type RPCService interface { 13 | FeatureEnableDisable(ctx context.Context, in *FeatureEnableDisable) (*FeatureEnableDisableReply, error) 14 | FeatureIsEnabled(ctx context.Context, in *FeatureIsEnabled) (*FeatureIsEnabledReply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) FeatureEnableDisable(ctx context.Context, in *FeatureEnableDisable) (*FeatureEnableDisableReply, error) { 26 | out := new(FeatureEnableDisableReply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) FeatureIsEnabled(ctx context.Context, in *FeatureIsEnabled) (*FeatureIsEnabledReply, error) { 35 | out := new(FeatureIsEnabledReply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/http_static/http_static_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package http_static 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service http_static. 12 | type RPCService interface { 13 | HTTPStaticEnableV4(ctx context.Context, in *HTTPStaticEnableV4) (*HTTPStaticEnableV4Reply, error) 14 | HTTPStaticEnableV5(ctx context.Context, in *HTTPStaticEnableV5) (*HTTPStaticEnableV5Reply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) HTTPStaticEnableV4(ctx context.Context, in *HTTPStaticEnableV4) (*HTTPStaticEnableV4Reply, error) { 26 | out := new(HTTPStaticEnableV4Reply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) HTTPStaticEnableV5(ctx context.Context, in *HTTPStaticEnableV5) (*HTTPStaticEnableV5Reply, error) { 35 | out := new(HTTPStaticEnableV5Reply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/sr_mobile/sr_mobile_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package sr_mobile 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service sr_mobile. 12 | type RPCService interface { 13 | SrMobileLocalsidAddDel(ctx context.Context, in *SrMobileLocalsidAddDel) (*SrMobileLocalsidAddDelReply, error) 14 | SrMobilePolicyAdd(ctx context.Context, in *SrMobilePolicyAdd) (*SrMobilePolicyAddReply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) SrMobileLocalsidAddDel(ctx context.Context, in *SrMobileLocalsidAddDel) (*SrMobileLocalsidAddDelReply, error) { 26 | out := new(SrMobileLocalsidAddDelReply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) SrMobilePolicyAdd(ctx context.Context, in *SrMobilePolicyAdd) (*SrMobilePolicyAddReply, error) { 35 | out := new(SrMobilePolicyAddReply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/bpf_trace_filter/bpf_trace_filter_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package bpf_trace_filter 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service bpf_trace_filter. 12 | type RPCService interface { 13 | BpfTraceFilterSet(ctx context.Context, in *BpfTraceFilterSet) (*BpfTraceFilterSetReply, error) 14 | BpfTraceFilterSetV2(ctx context.Context, in *BpfTraceFilterSetV2) (*BpfTraceFilterSetV2Reply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) BpfTraceFilterSet(ctx context.Context, in *BpfTraceFilterSet) (*BpfTraceFilterSetReply, error) { 26 | out := new(BpfTraceFilterSetReply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) BpfTraceFilterSetV2(ctx context.Context, in *BpfTraceFilterSetV2) (*BpfTraceFilterSetV2Reply, error) { 35 | out := new(BpfTraceFilterSetV2Reply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/vpe/vpe_http.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package vpe 4 | 5 | import ( 6 | "encoding/json" 7 | "net/http" 8 | ) 9 | 10 | func HTTPHandler(rpc RPCService) http.Handler { 11 | mux := http.NewServeMux() 12 | mux.HandleFunc("/show_version", func(w http.ResponseWriter, req *http.Request) { 13 | var request = new(ShowVersion) 14 | reply, err := rpc.ShowVersion(req.Context(), request) 15 | if err != nil { 16 | http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError) 17 | return 18 | } 19 | rep, err := json.MarshalIndent(reply, "", " ") 20 | if err != nil { 21 | http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError) 22 | return 23 | } 24 | w.Write(rep) 25 | }) 26 | mux.HandleFunc("/show_vpe_system_time", func(w http.ResponseWriter, req *http.Request) { 27 | var request = new(ShowVpeSystemTime) 28 | reply, err := rpc.ShowVpeSystemTime(req.Context(), request) 29 | if err != nil { 30 | http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError) 31 | return 32 | } 33 | rep, err := json.MarshalIndent(reply, "", " ") 34 | if err != nil { 35 | http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError) 36 | return 37 | } 38 | w.Write(rep) 39 | }) 40 | return http.HandlerFunc(mux.ServeHTTP) 41 | } 42 | -------------------------------------------------------------------------------- /binapi/adl/adl_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package adl 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service adl. 12 | type RPCService interface { 13 | AdlAllowlistEnableDisable(ctx context.Context, in *AdlAllowlistEnableDisable) (*AdlAllowlistEnableDisableReply, error) 14 | AdlInterfaceEnableDisable(ctx context.Context, in *AdlInterfaceEnableDisable) (*AdlInterfaceEnableDisableReply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) AdlAllowlistEnableDisable(ctx context.Context, in *AdlAllowlistEnableDisable) (*AdlAllowlistEnableDisableReply, error) { 26 | out := new(AdlAllowlistEnableDisableReply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) AdlInterfaceEnableDisable(ctx context.Context, in *AdlInterfaceEnableDisable) (*AdlInterfaceEnableDisableReply, error) { 35 | out := new(AdlInterfaceEnableDisableReply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /examples/api-trace/README.md: -------------------------------------------------------------------------------- 1 | # API trace example 2 | 3 | The example demonstrates how to use the GoVPP API trace functionality. The trace is bound to a connection. 4 | The `core.Connection` includes the API trace object capable of recording API messages processed during the VPP API 5 | message exchange. Traced messages are called `records`. 6 | 7 | Each record contains information about the API message, its direction, time, and the channel ID. 8 | 9 | The trace is disabled by default. In order to enable it, call `NewTrace`: 10 | 11 | ```go 12 | c, err := govpp.Connect(*sockAddr) 13 | if err != nil { 14 | // handler error 15 | } 16 | size := 10 17 | trace := core.NewTrace(c, size) 18 | defer trace.Close() 19 | ``` 20 | 21 | The code above initializes the new tracer which records a certain number of messages defined by the `size`. 22 | 23 | The following methods are available to call on the trace: 24 | 25 | * `GetRecords() []*Record` returns all records beginning with the initialization of the trace till the point of the 26 | method call. The size also restricts the maximum number of records. All records received after the tracer is full are 27 | discarded. 28 | * `GetRecordsForChannel(chId uint16) []*Record` works the same as the method above, but filters messages per channel. 29 | * `Clear()` resets the tracer and allows to reuse it with (the size remains the same). 30 | * `Close()` closes the tracer. -------------------------------------------------------------------------------- /cmd/binapi-generator/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // The binapi-generator parses VPP API definitions in JSON format and generates Go code. 16 | // 17 | // The VPP API input can be specified using --input= option, where INPUT 18 | // is one of the following: 19 | // 20 | // - path to directory containing `*.api.json` files (these may be nested under core/plugins) 21 | // - path to local VPP repository (uses files under`build-root/install-vpp-native/vpp/share/vpp/api`) 22 | // 23 | // The generated Go code will be placed into directory specified using 24 | // `--output-dir=` option (defaults to `binapi`). 25 | // Each VPP API file will be generated as a separate Go package. 26 | // 27 | // Example: 28 | // 29 | // binapi-generator --input=/usr/share/vpp/api --output-dir=binapi 30 | package main 31 | -------------------------------------------------------------------------------- /adapter/socketclient/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package socketclient is a pure Go implementation of adapter.VppAPI, which uses 16 | // unix domain sockets as the transport for connecting to the VPP binary API. 17 | // 18 | // The current implementation only supports VPP binary API, the VPP stats API 19 | // is not supported and clients still have to use vppapiclient for retrieving stats. 20 | // 21 | // # Requirements 22 | // 23 | // The socketclient connects to unix domain socket defined in VPP configuration. 24 | // 25 | // It is enabled by default at /run/vpp/api.sock by the following config section: 26 | // 27 | // socksvr { 28 | // socket-name default 29 | // } 30 | // 31 | // If you want to use custom socket path: 32 | // 33 | // socksvr { 34 | // socket-name /run/vpp/api.sock 35 | // } 36 | package socketclient 37 | -------------------------------------------------------------------------------- /core/request_handler_test.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "testing" 5 | 6 | . "github.com/onsi/gomega" 7 | 8 | "go.fd.io/govpp/api" 9 | interfaces "go.fd.io/govpp/binapi/interface" 10 | ) 11 | 12 | func TestNotificationMessageAfterUnsubscribe(t *testing.T) { 13 | ctx := setupTest(t) 14 | defer ctx.teardownTest() 15 | 16 | notifMsg := &interfaces.SwInterfaceEvent{} 17 | msgID, err := ctx.conn.GetMessageID(notifMsg) 18 | Expect(err).ShouldNot(HaveOccurred()) 19 | 20 | // Before subscribing, isNotificationMessage should return false 21 | isNotif := ctx.conn.isNotificationMessage(msgID) 22 | Expect(isNotif).Should(BeFalse()) 23 | 24 | // Subscribe to the notification 25 | notifChan := make(chan api.Message, 10) 26 | sub, err := ctx.ch.SubscribeNotification(notifChan, notifMsg) 27 | Expect(err).ShouldNot(HaveOccurred()) 28 | Expect(sub).ShouldNot(BeNil()) 29 | 30 | // After subscribing, isNotificationMessage should return true 31 | isNotif = ctx.conn.isNotificationMessage(msgID) 32 | Expect(isNotif).Should(BeTrue()) 33 | 34 | // Unsubscribe from the notification 35 | err = sub.Unsubscribe() 36 | Expect(err).ShouldNot(HaveOccurred()) 37 | 38 | // After unsubscribing the last (and only) subscription, isNotificationMessage should return false 39 | isNotif = ctx.conn.isNotificationMessage(msgID) 40 | Expect(isNotif).Should(BeFalse(), "isNotificationMessage should return false after unsubscribing from the last subscription") 41 | } 42 | -------------------------------------------------------------------------------- /binapigen/generate.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package binapigen 16 | 17 | const ( 18 | // generatedCodeVersion indicates a version of the generated code. 19 | // It is incremented whenever an incompatibility between the generated code and 20 | // GoVPP api package is introduced; the generated code references 21 | // a constant, api.GoVppAPIPackageIsVersionN (where N is generatedCodeVersion). 22 | generatedCodeVersion = 2 23 | 24 | generatedFilenameSuffix = ".ba.go" 25 | ) 26 | 27 | // library dependencies 28 | const ( 29 | strconvPkg = GoImportPath("strconv") 30 | 31 | govppApiPkg = GoImportPath("go.fd.io/govpp/api") 32 | govppCodecPkg = GoImportPath("go.fd.io/govpp/codec") 33 | ) 34 | 35 | func genCodeGeneratedComment(g *GenFile) { 36 | g.P("// Code generated by GoVPP's binapi-generator. DO NOT EDIT.") 37 | } 38 | -------------------------------------------------------------------------------- /binapi/dhcp6_pd_client_cp/dhcp6_pd_client_cp_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package dhcp6_pd_client_cp 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service dhcp6_pd_client_cp. 12 | type RPCService interface { 13 | DHCP6PdClientEnableDisable(ctx context.Context, in *DHCP6PdClientEnableDisable) (*DHCP6PdClientEnableDisableReply, error) 14 | IP6AddDelAddressUsingPrefix(ctx context.Context, in *IP6AddDelAddressUsingPrefix) (*IP6AddDelAddressUsingPrefixReply, error) 15 | } 16 | 17 | type serviceClient struct { 18 | conn api.Connection 19 | } 20 | 21 | func NewServiceClient(conn api.Connection) RPCService { 22 | return &serviceClient{conn} 23 | } 24 | 25 | func (c *serviceClient) DHCP6PdClientEnableDisable(ctx context.Context, in *DHCP6PdClientEnableDisable) (*DHCP6PdClientEnableDisableReply, error) { 26 | out := new(DHCP6PdClientEnableDisableReply) 27 | err := c.conn.Invoke(ctx, in, out) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return out, api.RetvalToVPPApiError(out.Retval) 32 | } 33 | 34 | func (c *serviceClient) IP6AddDelAddressUsingPrefix(ctx context.Context, in *IP6AddDelAddressUsingPrefix) (*IP6AddDelAddressUsingPrefixReply, error) { 35 | out := new(IP6AddDelAddressUsingPrefixReply) 36 | err := c.conn.Invoke(ctx, in, out) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return out, api.RetvalToVPPApiError(out.Retval) 41 | } 42 | -------------------------------------------------------------------------------- /extras/gomemif/memif/interface_unsafe.go: -------------------------------------------------------------------------------- 1 | /* 2 | *------------------------------------------------------------------ 3 | * Copyright (c) 2020 Cisco and/or its affiliates. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *------------------------------------------------------------------ 16 | */ 17 | 18 | package memif 19 | 20 | import ( 21 | "fmt" 22 | "os" 23 | "syscall" 24 | "unsafe" 25 | ) 26 | 27 | // memfdCreate returns memory file file descriptor (memif.sys_memfd_create) 28 | func memfdCreate() (mfd int, err error) { 29 | p0, err := syscall.BytePtrFromString("memif_region_0") 30 | if err != nil { 31 | return -1, fmt.Errorf("memfdCreate: %s", err) 32 | } 33 | 34 | u_mfd, _, errno := syscall.Syscall(sys_memfd_create, uintptr(unsafe.Pointer(p0)), uintptr(mfd_allow_sealing), uintptr(0)) 35 | if errno != 0 { 36 | return -1, fmt.Errorf("memfdCreate: %s", os.NewSyscallError("memfd_create", errno)) 37 | } 38 | 39 | return int(u_mfd), nil 40 | } 41 | -------------------------------------------------------------------------------- /extras/test/build/Dockerfile.extras: -------------------------------------------------------------------------------- 1 | FROM buildpack-deps:22.04-scm 2 | 3 | # Install gotestsum 4 | ARG GOTESTSUM_VERSION=1.12.0 5 | RUN set -eux; \ 6 | curl -fsSL https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz -o gotestsum.tar.gz; \ 7 | tar -xf gotestsum.tar.gz gotestsum; \ 8 | mv gotestsum /usr/local/bin/gotestsum; \ 9 | rm gotestsum.tar.gz; 10 | 11 | # Install Go 12 | ENV GOLANG_VERSION=1.25.3 13 | 14 | RUN set -eux; \ 15 | dpkgArch="$(dpkg --print-architecture)"; \ 16 | case "${dpkgArch##*-}" in \ 17 | amd64) goRelArch='linux-amd64'; ;; \ 18 | armhf) goRelArch='linux-armv6l'; ;; \ 19 | arm64) goRelArch='linux-arm64'; ;; \ 20 | esac; \ 21 | wget -nv -O go.tgz "https://golang.org/dl/go${GOLANG_VERSION}.${goRelArch}.tar.gz"; \ 22 | tar -C /usr/local -xzf go.tgz; \ 23 | rm go.tgz; 24 | 25 | ENV GOPATH=/go 26 | ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH 27 | 28 | RUN set -eux; \ 29 | mkdir -p "$GOPATH/src" "$GOPATH/bin"; \ 30 | chmod -R 777 "$GOPATH"; 31 | 32 | ARG VPP_REPO=master 33 | 34 | # Install VPP 35 | RUN set -eux; \ 36 | apt-get update; \ 37 | curl -fsSL https://packagecloud.io/install/repositories/fdio/${VPP_REPO}/script.deb.sh | bash; \ 38 | apt-get update && apt-get install -V -y \ 39 | vpp \ 40 | vpp-plugin-core \ 41 | ; \ 42 | rm -rf /var/lib/apt/lists/* 43 | 44 | COPY vpp.conf /etc/vpp/vpp.conf 45 | 46 | WORKDIR /src 47 | 48 | CMD ["/usr/bin/vpp", "-c", "/etc/vpp/vpp.conf"] 49 | -------------------------------------------------------------------------------- /test/build/Dockerfile.integration: -------------------------------------------------------------------------------- 1 | FROM buildpack-deps:22.04-scm 2 | 3 | # Install gotestsum 4 | ARG GOTESTSUM_VERSION=1.12.0 5 | RUN set -eux; \ 6 | curl -fsSL https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz -o gotestsum.tar.gz; \ 7 | tar -xf gotestsum.tar.gz gotestsum; \ 8 | mv gotestsum /usr/local/bin/gotestsum; \ 9 | rm gotestsum.tar.gz; 10 | 11 | # Install Go 12 | ENV GOLANG_VERSION 1.25.3 13 | 14 | RUN set -eux; \ 15 | dpkgArch="$(dpkg --print-architecture)"; \ 16 | case "${dpkgArch##*-}" in \ 17 | amd64) goRelArch='linux-amd64'; ;; \ 18 | armhf) goRelArch='linux-armv6l'; ;; \ 19 | arm64) goRelArch='linux-arm64'; ;; \ 20 | esac; \ 21 | wget -nv -O go.tgz "https://golang.org/dl/go${GOLANG_VERSION}.${goRelArch}.tar.gz"; \ 22 | tar -C /usr/local -xzf go.tgz; \ 23 | rm go.tgz; 24 | 25 | ENV GOPATH /go 26 | ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH 27 | 28 | RUN set -eux; \ 29 | mkdir -p "$GOPATH/src" "$GOPATH/bin"; \ 30 | chmod -R 777 "$GOPATH"; 31 | 32 | ARG VPP_REPO=release 33 | 34 | # Install VPP 35 | RUN set -eux; \ 36 | apt-get update; \ 37 | curl -fsSL https://packagecloud.io/install/repositories/fdio/${VPP_REPO}/script.deb.sh | bash; \ 38 | apt-get update && apt-get install -V -y \ 39 | vpp \ 40 | vpp-plugin-core \ 41 | ; \ 42 | rm -rf /var/lib/apt/lists/* 43 | 44 | COPY vpp.conf /etc/vpp/vpp.conf 45 | 46 | WORKDIR /src 47 | 48 | CMD ["/usr/bin/vpp", "-c", "/etc/vpp/vpp.conf"] 49 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | ARG VPP_VERSION=v25.10 2 | ARG UBUNTU_VERSION=22.04 3 | 4 | FROM ubuntu:${UBUNTU_VERSION} as vppbuild 5 | 6 | RUN set -eux;\ 7 | apt-get update && env DEBIAN_FRONTEND=noninteractive TZ=US/Central apt-get install -y \ 8 | asciidoc \ 9 | ca-certificates \ 10 | git \ 11 | iproute2 \ 12 | iputils-ping \ 13 | make \ 14 | python3 \ 15 | sudo \ 16 | tcpdump \ 17 | rm -rf /var/lib/apt/lists/* 18 | 19 | RUN git clone https://github.com/FDio/vpp.git 20 | 21 | WORKDIR /vpp 22 | 23 | ARG VPP_VERSION 24 | RUN git checkout ${VPP_VERSION} 25 | 26 | RUN set -eux; \ 27 | env DEBIAN_FRONTEND=noninteractive TZ=US/Central UNATTENDED=y make install-dep 28 | RUN set -eux; \ 29 | make pkg-deb \ 30 | ./src/scripts/version > /vpp/VPP_VERSION 31 | 32 | FROM vppbuild as vppinstall 33 | 34 | RUN set -eux; \ 35 | env VPP_INSTALL_SKIP_SYSCTL=false apt install -f -y --no-install-recommends /vpp/build-root/*.deb ; \ 36 | rm -rf /var/lib/apt/lists/*; \ 37 | rm -rf /pkg 38 | 39 | FROM golang:1.25-alpine3.22 as binapi-generator 40 | 41 | ENV GO111MODULE=on 42 | ENV CGO_ENABLED=0 43 | ENV GOBIN=/bin 44 | 45 | ARG GOVPP_VERSION 46 | 47 | COPY . /govpp 48 | 49 | WORKDIR /govpp 50 | 51 | RUN go build -o /bin/binapi-generator ./cmd/binapi-generator 52 | 53 | FROM binapi-generator as gen 54 | 55 | COPY --from=vppinstall /usr/share/vpp/api/ /usr/share/vpp/api/ 56 | COPY --from=vppinstall /vpp/VPP_VERSION /VPP_VERSION 57 | 58 | WORKDIR /gen/binapi 59 | 60 | CMD VPP_VERSION=$(cat /VPP_VERSION) go generate . 61 | -------------------------------------------------------------------------------- /core/log.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "os" 5 | "strings" 6 | 7 | "github.com/sirupsen/logrus" 8 | ) 9 | 10 | const ( 11 | DebugEnvVar = "DEBUG_GOVPP" 12 | 13 | debugOptCore = "core" 14 | debugOptConn = "conn" 15 | debugOptMsgId = "msgid" 16 | debugOptChannels = "channels" 17 | ) 18 | 19 | var ( 20 | debugMap map[string]struct{} 21 | debugOn bool 22 | 23 | log *logrus.Logger 24 | ) 25 | 26 | // init initializes global logger 27 | func init() { 28 | debugMap = initDebugMap(os.Getenv(DebugEnvVar)) 29 | debugOn = isDebugOn(debugOptCore) 30 | 31 | log = logrus.New() 32 | log.Formatter = &logrus.TextFormatter{ 33 | EnvironmentOverrideColors: true, 34 | } 35 | if debugOn { 36 | log.Level = logrus.DebugLevel 37 | log.Debugf("govpp: debug enabled %v", debugMap) 38 | } 39 | } 40 | 41 | func isDebugOn(u string) bool { 42 | _, ok := debugMap[u] 43 | return ok 44 | } 45 | 46 | func initDebugMap(s string) map[string]struct{} { 47 | debugSet := make(map[string]struct{}) 48 | for _, p := range splitString(s) { 49 | key := strings.SplitN(p, "=", 2)[0] // We only need the key 50 | debugSet[key] = struct{}{} 51 | } 52 | return debugSet 53 | } 54 | 55 | func splitString(s string) []string { 56 | return strings.FieldsFunc(s, func(c rune) bool { 57 | return c == ';' || c == ',' 58 | }) 59 | } 60 | 61 | // SetLogger sets global logger to l. 62 | func SetLogger(l *logrus.Logger) { 63 | log = l 64 | } 65 | 66 | // SetLogLevel sets global logger level to lvl. 67 | func SetLogLevel(lvl logrus.Level) { 68 | log.Level = lvl 69 | } 70 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package govpp provides the entry point to govpp functionality. It provides the API for connecting the govpp core 16 | // to VPP either using the default VPP adapter, or using the adapter previously set by SetAdapter function 17 | // (useful mostly just for unit/integration tests with mocked VPP adapter). 18 | // 19 | // To create a connection to VPP, use govpp.Connect function: 20 | // 21 | // conn, err := govpp.Connect() 22 | // if err != nil { 23 | // // handle error! 24 | // } 25 | // defer conn.Disconnect() 26 | // 27 | // Make sure you close the connection after using it. If the connection is not closed, it will leak resources. Please 28 | // note that only one VPP connection is allowed for a single process. 29 | // 30 | // In case you need to mock the connection to VPP (e.g. for testing), use the govpp.SetAdapter function before 31 | // calling govpp.Connect. 32 | // 33 | // Once connected to VPP, use the functions from the api package to communicate with it. 34 | package govpp 35 | -------------------------------------------------------------------------------- /test/integration/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package integration contains tests against running VPP instance. 16 | // The test cases are only executed if env contains TEST=integration. 17 | package integration 18 | 19 | import ( 20 | "fmt" 21 | "net/http" 22 | "os" 23 | "os/exec" 24 | "testing" 25 | 26 | _ "net/http/pprof" 27 | ) 28 | 29 | var ( 30 | // IntegrationTestsActive is set to true if integration tests should run. 31 | IntegrationTestsActive = os.Getenv("TEST") == "integration" 32 | ) 33 | 34 | func TestMain(m *testing.M) { 35 | if IntegrationTestsActive { 36 | go func() { 37 | fmt.Fprintln(os.Stderr, http.ListenAndServe(":6060", nil)) 38 | }() 39 | os.Exit(m.Run()) 40 | } 41 | fmt.Fprintf(os.Stderr, "integration tests are NOT enabled (set TEST='integration' to enable)\n") 42 | os.Exit(0) 43 | } 44 | 45 | func skipTestIfGoNotInstalled(t *testing.T) { 46 | _, err := exec.LookPath("go") 47 | if err != nil { 48 | t.Skipf("`go` command is not available, skipping test") 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /binapi/trace/trace_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package trace 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service trace. 12 | type RPCService interface { 13 | TraceProfileAdd(ctx context.Context, in *TraceProfileAdd) (*TraceProfileAddReply, error) 14 | TraceProfileDel(ctx context.Context, in *TraceProfileDel) (*TraceProfileDelReply, error) 15 | TraceProfileShowConfig(ctx context.Context, in *TraceProfileShowConfig) (*TraceProfileShowConfigReply, error) 16 | } 17 | 18 | type serviceClient struct { 19 | conn api.Connection 20 | } 21 | 22 | func NewServiceClient(conn api.Connection) RPCService { 23 | return &serviceClient{conn} 24 | } 25 | 26 | func (c *serviceClient) TraceProfileAdd(ctx context.Context, in *TraceProfileAdd) (*TraceProfileAddReply, error) { 27 | out := new(TraceProfileAddReply) 28 | err := c.conn.Invoke(ctx, in, out) 29 | if err != nil { 30 | return nil, err 31 | } 32 | return out, api.RetvalToVPPApiError(out.Retval) 33 | } 34 | 35 | func (c *serviceClient) TraceProfileDel(ctx context.Context, in *TraceProfileDel) (*TraceProfileDelReply, error) { 36 | out := new(TraceProfileDelReply) 37 | err := c.conn.Invoke(ctx, in, out) 38 | if err != nil { 39 | return nil, err 40 | } 41 | return out, api.RetvalToVPPApiError(out.Retval) 42 | } 43 | 44 | func (c *serviceClient) TraceProfileShowConfig(ctx context.Context, in *TraceProfileShowConfig) (*TraceProfileShowConfigReply, error) { 45 | out := new(TraceProfileShowConfigReply) 46 | err := c.conn.Invoke(ctx, in, out) 47 | if err != nil { 48 | return nil, err 49 | } 50 | return out, api.RetvalToVPPApiError(out.Retval) 51 | } 52 | -------------------------------------------------------------------------------- /core/stream_test.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "testing" 7 | "time" 8 | 9 | . "github.com/onsi/gomega" 10 | "go.fd.io/govpp/adapter/mock" 11 | ) 12 | 13 | type streamCtx struct { 14 | mockVpp *mock.VppAdapter 15 | conn *Connection 16 | stream *Stream 17 | } 18 | 19 | func setupStreamTest(t *testing.T) *streamCtx { 20 | RegisterTestingT(t) 21 | 22 | ctx := &streamCtx{ 23 | mockVpp: mock.NewVppAdapter(), 24 | } 25 | 26 | var err error 27 | ctx.conn, err = Connect(ctx.mockVpp) 28 | Expect(err).ShouldNot(HaveOccurred()) 29 | 30 | stream, err := ctx.conn.NewStream(context.TODO()) 31 | Expect(err).ShouldNot(HaveOccurred()) 32 | 33 | ctx.stream = stream.(*Stream) 34 | return ctx 35 | } 36 | 37 | func (ctx *streamCtx) teardownTest() { 38 | err := ctx.stream.Close() 39 | Expect(err).ShouldNot(HaveOccurred()) 40 | ctx.conn.Disconnect() 41 | } 42 | 43 | func TestStreamReply(t *testing.T) { 44 | ctx := setupStreamTest(t) 45 | defer ctx.teardownTest() 46 | 47 | ctx.stream.replyTimeout = time.Millisecond 48 | 49 | // mock reply 50 | ctx.mockVpp.MockReply(&ControlPingReply{}) 51 | 52 | // first one request should work 53 | err := ctx.stream.SendMsg(&ControlPing{}) 54 | Expect(err).ShouldNot(HaveOccurred()) 55 | _, err = ctx.stream.RecvMsg() 56 | Expect(err).ShouldNot(HaveOccurred()) 57 | 58 | // no other reply ready - expect timeout 59 | err = ctx.stream.SendMsg(&ControlPing{}) 60 | Expect(err).ShouldNot(HaveOccurred()) 61 | _, err = ctx.stream.RecvMsg() 62 | Expect(err).Should(HaveOccurred()) 63 | Expect(err.Error()).To(HavePrefix("no reply received within the timeout period")) 64 | Expect(errors.Is(err, ErrReplyTimeout)).To(Equal(true)) 65 | } 66 | -------------------------------------------------------------------------------- /api/trace.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package api 16 | 17 | import ( 18 | "time" 19 | ) 20 | 21 | // Trace is the GoVPP utility tool capturing processed API messages. The trace is not operational 22 | // by default. 23 | // Enable trace for a given connection by calling `NewTrace(connection, size)` 24 | type Trace interface { 25 | // GetRecords returns all API messages from all channels captured since the trace 26 | // was initialized or cleared up to the point of the call. 27 | GetRecords() []*Record 28 | 29 | // GetRecordsForChannel returns all API messages recorded by the given channel. 30 | GetRecordsForChannel(chId uint16) []*Record 31 | 32 | // Clear erases messages captured so far. 33 | Clear() 34 | 35 | // Close the tracer and release associated resources 36 | Close() 37 | } 38 | 39 | // Record contains essential information about the traced message, its timestamp and whether 40 | // the message was received or sent 41 | type Record struct { 42 | Message Message 43 | Timestamp time.Time 44 | IsReceived bool 45 | ChannelID uint16 46 | Succeeded bool 47 | } 48 | -------------------------------------------------------------------------------- /binapigen/vppapi/input_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package vppapi 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func Test_runCommandInRepo(t *testing.T) { 22 | type args struct { 23 | repo string 24 | commit string 25 | command string 26 | args []string 27 | } 28 | tests := []struct { 29 | name string 30 | args args 31 | wantErr bool 32 | }{ 33 | { 34 | name: "branch", 35 | args: args{ 36 | repo: "https://github.com/FDio/vpp.git", 37 | commit: "master", 38 | command: "bash", 39 | args: []string{"-exc", "bash ./src/scripts/version; make json-api-files && ls ./build-root/install-vpp-native/vpp/share/vpp/api"}, 40 | }, 41 | wantErr: false, 42 | }, 43 | } 44 | for _, tt := range tests { 45 | t.Run(tt.name, func(t *testing.T) { 46 | //, tt.args.command, tt.args.args... 47 | _, err := cloneRepoLocally(tt.args.repo, tt.args.commit, "", 0) 48 | if (err != nil) != tt.wantErr { 49 | t.Errorf("cloneRepoLocally() error = %v, wantErr %v", err, tt.wantErr) 50 | } 51 | //t.Logf("OUTPUT:") 52 | }) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /binapigen/strings_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package binapigen 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestInitialism(t *testing.T) { 22 | tests := []struct { 23 | name string 24 | input string 25 | expOutput string 26 | }{ 27 | {name: "id", input: "id", expOutput: "ID"}, 28 | {name: "ipv6", input: "is_ipv6", expOutput: "IsIPv6"}, 29 | {name: "ip6", input: "is_ip6", expOutput: "IsIP6"}, 30 | } 31 | for _, test := range tests { 32 | t.Run(test.name, func(t *testing.T) { 33 | output := camelCaseName(test.input) 34 | if output != test.expOutput { 35 | t.Errorf("expected %q, got %q", test.expOutput, output) 36 | } 37 | }) 38 | } 39 | } 40 | 41 | func TestSanitize(t *testing.T) { 42 | tests := []struct { 43 | name string 44 | expected string 45 | }{ 46 | {"interface", "interfaces"}, 47 | } 48 | for _, test := range tests { 49 | t.Run(test.name, func(t *testing.T) { 50 | s := sanitizedName(test.name) 51 | if s != test.expected { 52 | t.Fatalf("expected: %q, got: %q", test.expected, s) 53 | } 54 | }) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /test/integration/examples_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package integration 16 | 17 | import ( 18 | "io/fs" 19 | "os/exec" 20 | "path/filepath" 21 | "testing" 22 | 23 | "go.fd.io/govpp/test/vpptesting" 24 | ) 25 | 26 | func TestExamples(t *testing.T) { 27 | skipTestIfGoNotInstalled(t) 28 | 29 | if err := filepath.WalkDir("./examples", func(path string, d fs.DirEntry, err error) error { 30 | if !d.IsDir() || filepath.Base(d.Name()) == "examples" { 31 | return nil 32 | } 33 | example := filepath.Base(d.Name()) 34 | t.Run(example, func(tt *testing.T) { 35 | runExample(tt, example) 36 | }) 37 | return nil 38 | }); err != nil { 39 | t.Fatalf("walking examples dir error: %v", err) 40 | } 41 | } 42 | 43 | func runExample(t *testing.T, example string) { 44 | vpptesting.SetupVPP(t) 45 | 46 | cmd := exec.Command("go", "run", "./examples/"+example) 47 | t.Logf("executing command '%v'", cmd) 48 | out, err := cmd.CombinedOutput() 49 | if err != nil { 50 | t.Fatalf("example %s failed: command '%s' error: %+v\n%s", example, cmd, err, out) 51 | } 52 | t.Logf("example %s output: %s", example, out) 53 | } 54 | -------------------------------------------------------------------------------- /binapi/crypto/crypto_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package crypto 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service crypto. 12 | type RPCService interface { 13 | CryptoSetAsyncDispatch(ctx context.Context, in *CryptoSetAsyncDispatch) (*CryptoSetAsyncDispatchReply, error) 14 | CryptoSetAsyncDispatchV2(ctx context.Context, in *CryptoSetAsyncDispatchV2) (*CryptoSetAsyncDispatchV2Reply, error) 15 | CryptoSetHandler(ctx context.Context, in *CryptoSetHandler) (*CryptoSetHandlerReply, error) 16 | } 17 | 18 | type serviceClient struct { 19 | conn api.Connection 20 | } 21 | 22 | func NewServiceClient(conn api.Connection) RPCService { 23 | return &serviceClient{conn} 24 | } 25 | 26 | func (c *serviceClient) CryptoSetAsyncDispatch(ctx context.Context, in *CryptoSetAsyncDispatch) (*CryptoSetAsyncDispatchReply, error) { 27 | out := new(CryptoSetAsyncDispatchReply) 28 | err := c.conn.Invoke(ctx, in, out) 29 | if err != nil { 30 | return nil, err 31 | } 32 | return out, api.RetvalToVPPApiError(out.Retval) 33 | } 34 | 35 | func (c *serviceClient) CryptoSetAsyncDispatchV2(ctx context.Context, in *CryptoSetAsyncDispatchV2) (*CryptoSetAsyncDispatchV2Reply, error) { 36 | out := new(CryptoSetAsyncDispatchV2Reply) 37 | err := c.conn.Invoke(ctx, in, out) 38 | if err != nil { 39 | return nil, err 40 | } 41 | return out, api.RetvalToVPPApiError(out.Retval) 42 | } 43 | 44 | func (c *serviceClient) CryptoSetHandler(ctx context.Context, in *CryptoSetHandler) (*CryptoSetHandlerReply, error) { 45 | out := new(CryptoSetHandlerReply) 46 | err := c.conn.Invoke(ctx, in, out) 47 | if err != nil { 48 | return nil, err 49 | } 50 | return out, api.RetvalToVPPApiError(out.Retval) 51 | } 52 | -------------------------------------------------------------------------------- /INFO.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | project: 'GoVPP' 3 | project_creation_date: '2017-04-27' 4 | project_category: 'Integration & Tooling' 5 | lifecycle_state: 'Incubation' 6 | project_lead: &govpp_ptl 7 | name: 'Ondrej Fabry' 8 | email: 'ondrej@fabry.dev' 9 | id: 'ondrej-fabry' 10 | timezone: 'Europe/Bratislava' 11 | primary_contact: *govpp_ptl 12 | issue_tracking: 13 | type: 'github' 14 | url: 'https://github.com/FDio/govpp/issues' 15 | mailing_list: 16 | type: 'groups.io' 17 | url: 'https://lists.fd.io/g/govpp-dev' 18 | tag: '<[sub-project_name]>' 19 | realtime_discussion: 20 | type: 'slack' 21 | server: 'fdio-project.slack.com' 22 | channel: 'govpp' 23 | meetings: 24 | - type: 'zoom' 25 | agenda: 'https://wiki.fd.io/view/GoVPP/Meeting#Agenda' 26 | url: 'https://zoom.us/j/5301185804' 27 | repeats: 'bi-weekly' 28 | day: 'thu' 29 | time: '13:30 UTC' 30 | repositories: 31 | - 'govpp' 32 | committers: 33 | - <<: *govpp_ptl 34 | - name: 'Ondrej Fabry' 35 | company: 'cisco' 36 | email: 'ofabry@cisco.com' 37 | id: 'ondrej-fabry' 38 | - name: 'Jan Medved' 39 | company: 'cisco' 40 | email: 'jmedved@cisco.com' 41 | id: 'jmedved' 42 | - name: 'Rastislav Szabo' 43 | company: 'cisco' 44 | email: 'raszabo@cisco.com' 45 | id: 'raszabo' 46 | - name: 'Vladimir Lavor' 47 | company: 'cisco' 48 | email: 'vlavor@cisco.com' 49 | id: 'vlavor' 50 | - name: 'Nathan Skrzypczak' 51 | company: 'cisco' 52 | email: 'nathan.skrzypczak@gmail.com' 53 | id: 'sknat' 54 | tsc: 55 | # yamllint disable rule:line-length 56 | approval: '' 57 | changes: 58 | - type: 'addition' 59 | name: 'Nathan Skrzypczak' 60 | link: 'https://ircbot.wl.linuxfoundation.org/meetings/fdio-meeting/2022/fd_io_tsc/fdio-meeting-fd_io_tsc.2022-06-16-15.01.html' 61 | -------------------------------------------------------------------------------- /binapi/graph/graph_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package graph 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | ) 12 | 13 | // RPCService defines RPC service graph. 14 | type RPCService interface { 15 | GraphNodeGet(ctx context.Context, in *GraphNodeGet) (RPCService_GraphNodeGetClient, error) 16 | } 17 | 18 | type serviceClient struct { 19 | conn api.Connection 20 | } 21 | 22 | func NewServiceClient(conn api.Connection) RPCService { 23 | return &serviceClient{conn} 24 | } 25 | 26 | func (c *serviceClient) GraphNodeGet(ctx context.Context, in *GraphNodeGet) (RPCService_GraphNodeGetClient, error) { 27 | stream, err := c.conn.NewStream(ctx) 28 | if err != nil { 29 | return nil, err 30 | } 31 | x := &serviceClient_GraphNodeGetClient{stream} 32 | if err := x.Stream.SendMsg(in); err != nil { 33 | return nil, err 34 | } 35 | return x, nil 36 | } 37 | 38 | type RPCService_GraphNodeGetClient interface { 39 | Recv() (*GraphNodeDetails, *GraphNodeGetReply, error) 40 | api.Stream 41 | } 42 | 43 | type serviceClient_GraphNodeGetClient struct { 44 | api.Stream 45 | } 46 | 47 | func (c *serviceClient_GraphNodeGetClient) Recv() (*GraphNodeDetails, *GraphNodeGetReply, error) { 48 | msg, err := c.Stream.RecvMsg() 49 | if err != nil { 50 | return nil, nil, err 51 | } 52 | switch m := msg.(type) { 53 | case *GraphNodeDetails: 54 | return m, nil, nil 55 | case *GraphNodeGetReply: 56 | if err := api.RetvalToVPPApiError(m.Retval); err != nil { 57 | c.Stream.Close() 58 | return nil, m, err 59 | } 60 | err = c.Stream.Close() 61 | if err != nil { 62 | return nil, m, err 63 | } 64 | return nil, m, io.EOF 65 | default: 66 | return nil, nil, fmt.Errorf("unexpected message: %T %v", m, m) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /binapi/sr_mobile_types/sr_mobile_types.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | // versions: 3 | // binapi-generator: v0.12.0 4 | // VPP: 25.10-release 5 | // source: plugins/sr_mobile_types.api.json 6 | 7 | // Package sr_mobile_types contains generated bindings for API file sr_mobile_types.api. 8 | // 9 | // Contents: 10 | // - 1 enum 11 | package sr_mobile_types 12 | 13 | import ( 14 | "strconv" 15 | 16 | api "go.fd.io/govpp/api" 17 | ) 18 | 19 | // This is a compile-time assertion to ensure that this generated file 20 | // is compatible with the GoVPP api package it is being compiled against. 21 | // A compilation error at this line likely means your copy of the 22 | // GoVPP api package needs to be updated. 23 | const _ = api.GoVppAPIPackageIsVersion2 24 | 25 | const ( 26 | APIFile = "sr_mobile_types" 27 | APIVersion = "0.1.0" 28 | VersionCrc = 0x7afa7d45 29 | ) 30 | 31 | // SrMobileNhtype defines enum 'sr_mobile_nhtype'. 32 | type SrMobileNhtype uint8 33 | 34 | const ( 35 | SRV6_NHTYPE_API_NONE SrMobileNhtype = 0 36 | SRV6_NHTYPE_API_IPV4 SrMobileNhtype = 1 37 | SRV6_NHTYPE_API_IPV6 SrMobileNhtype = 2 38 | SRV6_NHTYPE_API_NON_IP SrMobileNhtype = 3 39 | ) 40 | 41 | var ( 42 | SrMobileNhtype_name = map[uint8]string{ 43 | 0: "SRV6_NHTYPE_API_NONE", 44 | 1: "SRV6_NHTYPE_API_IPV4", 45 | 2: "SRV6_NHTYPE_API_IPV6", 46 | 3: "SRV6_NHTYPE_API_NON_IP", 47 | } 48 | SrMobileNhtype_value = map[string]uint8{ 49 | "SRV6_NHTYPE_API_NONE": 0, 50 | "SRV6_NHTYPE_API_IPV4": 1, 51 | "SRV6_NHTYPE_API_IPV6": 2, 52 | "SRV6_NHTYPE_API_NON_IP": 3, 53 | } 54 | ) 55 | 56 | func (x SrMobileNhtype) String() string { 57 | s, ok := SrMobileNhtype_name[uint8(x)] 58 | if ok { 59 | return s 60 | } 61 | return "SrMobileNhtype(" + strconv.Itoa(int(x)) + ")" 62 | } 63 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module go.fd.io/govpp 2 | 3 | go 1.24.0 4 | 5 | require ( 6 | github.com/bennyscetbun/jsongo v1.1.2 7 | github.com/docker/cli v28.5.0+incompatible 8 | github.com/fsnotify/fsnotify v1.9.0 9 | github.com/ftrvxmtrx/fd v0.0.0-20150925145434-c6d800382fff 10 | github.com/gookit/color v1.6.0 11 | github.com/lunixbochs/struc v0.0.0-20200521075829-a4cb8d33dbbe 12 | github.com/mitchellh/go-ps v1.0.0 13 | github.com/moby/term v0.5.2 14 | github.com/olekukonko/tablewriter v1.1.0 15 | github.com/onsi/gomega v1.38.2 16 | github.com/pkg/profile v1.7.0 17 | github.com/sirupsen/logrus v1.9.3 18 | github.com/spf13/cobra v1.10.1 19 | github.com/spf13/pflag v1.0.10 20 | golang.org/x/text v0.29.0 21 | gopkg.in/yaml.v3 v3.0.1 22 | ) 23 | 24 | require ( 25 | github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect 26 | github.com/fatih/color v1.15.0 // indirect 27 | github.com/felixge/fgprof v0.9.3 // indirect 28 | github.com/google/go-cmp v0.7.0 // indirect 29 | github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect 30 | github.com/inconshreveable/mousetrap v1.1.0 // indirect 31 | github.com/kr/pretty v0.1.0 // indirect 32 | github.com/mattn/go-colorable v0.1.13 // indirect 33 | github.com/mattn/go-isatty v0.0.19 // indirect 34 | github.com/mattn/go-runewidth v0.0.16 // indirect 35 | github.com/olekukonko/errors v1.1.0 // indirect 36 | github.com/olekukonko/ll v0.0.9 // indirect 37 | github.com/rivo/uniseg v0.2.0 // indirect 38 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect 39 | go.yaml.in/yaml/v3 v3.0.4 // indirect 40 | golang.org/x/net v0.43.0 // indirect 41 | golang.org/x/sys v0.35.0 // indirect 42 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect 43 | ) 44 | 45 | // Versions v0.5.0 and older use old module path git.fd.io/govpp.git 46 | retract [v0.1.0, v0.5.0] 47 | -------------------------------------------------------------------------------- /binapi/ethernet_types/ethernet_types.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | // versions: 3 | // binapi-generator: v0.12.0 4 | // VPP: 25.10-release 5 | // source: core/ethernet_types.api.json 6 | 7 | // Package ethernet_types contains generated bindings for API file ethernet_types.api. 8 | // 9 | // Contents: 10 | // - 1 alias 11 | package ethernet_types 12 | 13 | import ( 14 | "net" 15 | 16 | api "go.fd.io/govpp/api" 17 | ) 18 | 19 | // This is a compile-time assertion to ensure that this generated file 20 | // is compatible with the GoVPP api package it is being compiled against. 21 | // A compilation error at this line likely means your copy of the 22 | // GoVPP api package needs to be updated. 23 | const _ = api.GoVppAPIPackageIsVersion2 24 | 25 | const ( 26 | APIFile = "ethernet_types" 27 | APIVersion = "1.0.0" 28 | VersionCrc = 0xf24103d6 29 | ) 30 | 31 | // MacAddress defines alias 'mac_address'. 32 | type MacAddress [6]uint8 33 | 34 | func NewMacAddress(mac net.HardwareAddr) MacAddress { 35 | var macaddr MacAddress 36 | copy(macaddr[:], mac[:]) 37 | return macaddr 38 | } 39 | 40 | func ParseMacAddress(s string) (MacAddress, error) { 41 | var macaddr MacAddress 42 | mac, err := net.ParseMAC(s) 43 | if err != nil { 44 | return macaddr, err 45 | } 46 | copy(macaddr[:], mac[:]) 47 | return macaddr, nil 48 | } 49 | 50 | func (x MacAddress) ToMAC() net.HardwareAddr { 51 | return net.HardwareAddr(x[:]) 52 | } 53 | 54 | func (x MacAddress) String() string { 55 | return x.ToMAC().String() 56 | } 57 | 58 | func (x *MacAddress) MarshalText() ([]byte, error) { 59 | return []byte(x.String()), nil 60 | } 61 | 62 | func (x *MacAddress) UnmarshalText(text []byte) error { 63 | mac, err := ParseMacAddress(string(text)) 64 | if err != nil { 65 | return err 66 | } 67 | *x = mac 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /binapi/lacp/lacp_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package lacp 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service lacp. 15 | type RPCService interface { 16 | SwInterfaceLacpDump(ctx context.Context, in *SwInterfaceLacpDump) (RPCService_SwInterfaceLacpDumpClient, error) 17 | } 18 | 19 | type serviceClient struct { 20 | conn api.Connection 21 | } 22 | 23 | func NewServiceClient(conn api.Connection) RPCService { 24 | return &serviceClient{conn} 25 | } 26 | 27 | func (c *serviceClient) SwInterfaceLacpDump(ctx context.Context, in *SwInterfaceLacpDump) (RPCService_SwInterfaceLacpDumpClient, error) { 28 | stream, err := c.conn.NewStream(ctx) 29 | if err != nil { 30 | return nil, err 31 | } 32 | x := &serviceClient_SwInterfaceLacpDumpClient{stream} 33 | if err := x.Stream.SendMsg(in); err != nil { 34 | return nil, err 35 | } 36 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 37 | return nil, err 38 | } 39 | return x, nil 40 | } 41 | 42 | type RPCService_SwInterfaceLacpDumpClient interface { 43 | Recv() (*SwInterfaceLacpDetails, error) 44 | api.Stream 45 | } 46 | 47 | type serviceClient_SwInterfaceLacpDumpClient struct { 48 | api.Stream 49 | } 50 | 51 | func (c *serviceClient_SwInterfaceLacpDumpClient) Recv() (*SwInterfaceLacpDetails, error) { 52 | msg, err := c.Stream.RecvMsg() 53 | if err != nil { 54 | return nil, err 55 | } 56 | switch m := msg.(type) { 57 | case *SwInterfaceLacpDetails: 58 | return m, nil 59 | case *memclnt.ControlPingReply: 60 | err = c.Stream.Close() 61 | if err != nil { 62 | return nil, err 63 | } 64 | return nil, io.EOF 65 | default: 66 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /extras/gomemif/memif/control_channel_unsafe.go: -------------------------------------------------------------------------------- 1 | /* 2 | *------------------------------------------------------------------ 3 | * Copyright (c) 2020 Cisco and/or its affiliates. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *------------------------------------------------------------------ 16 | */ 17 | 18 | package memif 19 | 20 | import ( 21 | "fmt" 22 | "os" 23 | "syscall" 24 | "unsafe" 25 | ) 26 | 27 | // sendMsg sends a control message from contorl channels message queue 28 | func (cc *controlChannel) sendMsg() (err error) { 29 | if len(cc.msgQueue) < 1 { 30 | return nil 31 | } 32 | // Get message buffer 33 | msg := cc.msgQueue[0] 34 | // Dequeue 35 | cc.msgQueue = cc.msgQueue[1:] 36 | 37 | iov := &syscall.Iovec{ 38 | Base: &msg.Buffer.Bytes()[0], 39 | Len: msgSize, 40 | } 41 | 42 | msgh := syscall.Msghdr{ 43 | Iov: iov, 44 | Iovlen: 1, 45 | } 46 | 47 | if msg.Fd > 0 { 48 | oob := syscall.UnixRights(msg.Fd) 49 | msgh.Control = &oob[0] 50 | msgh.Controllen = uint64(syscall.CmsgSpace(4)) 51 | } 52 | 53 | _, _, errno := syscall.Syscall(syscall.SYS_SENDMSG, uintptr(cc.event.Fd), uintptr(unsafe.Pointer(&msgh)), uintptr(0)) 54 | if errno != 0 { 55 | err = os.NewSyscallError("sendmsg", errno) 56 | return fmt.Errorf("SYS_SENDMSG: %s", errno) 57 | } 58 | 59 | return nil 60 | } 61 | -------------------------------------------------------------------------------- /codec/bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package codec_test 16 | 17 | /* 18 | import ( 19 | "testing" 20 | 21 | "go.fd.io/govpp/codec" 22 | ) 23 | 24 | var Data []byte 25 | 26 | func BenchmarkEncodeNew(b *testing.B) { 27 | m := NewTestAllMsg() 28 | c := codec.DefaultCodec 29 | 30 | var err error 31 | var data []byte 32 | 33 | b.ResetTimer() 34 | for i := 0; i < b.N; i++ { 35 | data, err = c.EncodeMsg(m, 100) 36 | if err != nil { 37 | b.Fatalf("expected nil error, got: %v", err) 38 | } 39 | } 40 | Data = data 41 | } 42 | 43 | func BenchmarkEncodeWrapper(b *testing.B) { 44 | m := codec.Wrapper{NewTestAllMsg()} 45 | c := codec.DefaultCodec 46 | 47 | var err error 48 | var data []byte 49 | 50 | b.ResetTimer() 51 | for i := 0; i < b.N; i++ { 52 | data, err = c.EncodeMsg(m, 100) 53 | if err != nil { 54 | b.Fatalf("expected nil error, got: %v", err) 55 | } 56 | } 57 | Data = data 58 | } 59 | 60 | func BenchmarkEncodeHard(b *testing.B) { 61 | m := NewTestAllMsg() 62 | 63 | var err error 64 | var data []byte 65 | 66 | b.ResetTimer() 67 | for i := 0; i < b.N; i++ { 68 | data, err = m.Marshal(nil) 69 | if err != nil { 70 | b.Fatalf("expected nil error, got: %v", err) 71 | } 72 | } 73 | Data = data 74 | } 75 | */ 76 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - 'v*' 9 | pull_request: 10 | workflow_dispatch: # Allows you to run this workflow manually from the Actions tab 11 | 12 | permissions: 13 | contents: write 14 | packages: write 15 | issues: write 16 | 17 | jobs: 18 | goreleaser: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: "Checkout" 22 | uses: actions/checkout@v6 23 | with: 24 | fetch-depth: 0 25 | 26 | - name: "Setup Go" 27 | uses: actions/setup-go@v6 28 | 29 | - name: "Download Syft" 30 | uses: anchore/sbom-action/download-syft@v0 #v0.15.10 31 | 32 | - name: 'Login to GitHub Container Registry' 33 | uses: docker/login-action@v3 34 | with: 35 | registry: ghcr.io 36 | username: ${{github.actor}} 37 | password: ${{secrets.GITHUB_TOKEN}} 38 | 39 | - name: "Print environment" 40 | run: | 41 | env | sort 42 | 43 | - name: "Release Version" 44 | if: success() && startsWith(github.ref, 'refs/tags/v') 45 | uses: goreleaser/goreleaser-action@v6 46 | with: 47 | version: '~> v2' 48 | args: release --clean 49 | env: 50 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 51 | HOSTNAME: github 52 | 53 | - name: "Release Snapshot" 54 | if: success() && !startsWith(github.ref, 'refs/tags/v') 55 | uses: goreleaser/goreleaser-action@v6 56 | with: 57 | version: '~> v2' 58 | args: release --clean --snapshot 59 | env: 60 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 61 | HOSTNAME: github 62 | 63 | - name: "Upload Artifacts" 64 | uses: actions/upload-artifact@v5 65 | with: 66 | name: govpp-artifacts 67 | path: | 68 | dist/* 69 | !dist/govpp-build* 70 | -------------------------------------------------------------------------------- /binapi/dev/dev_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package dev 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service dev. 12 | type RPCService interface { 13 | DevAttach(ctx context.Context, in *DevAttach) (*DevAttachReply, error) 14 | DevCreatePortIf(ctx context.Context, in *DevCreatePortIf) (*DevCreatePortIfReply, error) 15 | DevDetach(ctx context.Context, in *DevDetach) (*DevDetachReply, error) 16 | DevRemovePortIf(ctx context.Context, in *DevRemovePortIf) (*DevRemovePortIfReply, error) 17 | } 18 | 19 | type serviceClient struct { 20 | conn api.Connection 21 | } 22 | 23 | func NewServiceClient(conn api.Connection) RPCService { 24 | return &serviceClient{conn} 25 | } 26 | 27 | func (c *serviceClient) DevAttach(ctx context.Context, in *DevAttach) (*DevAttachReply, error) { 28 | out := new(DevAttachReply) 29 | err := c.conn.Invoke(ctx, in, out) 30 | if err != nil { 31 | return nil, err 32 | } 33 | return out, api.RetvalToVPPApiError(out.Retval) 34 | } 35 | 36 | func (c *serviceClient) DevCreatePortIf(ctx context.Context, in *DevCreatePortIf) (*DevCreatePortIfReply, error) { 37 | out := new(DevCreatePortIfReply) 38 | err := c.conn.Invoke(ctx, in, out) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return out, api.RetvalToVPPApiError(out.Retval) 43 | } 44 | 45 | func (c *serviceClient) DevDetach(ctx context.Context, in *DevDetach) (*DevDetachReply, error) { 46 | out := new(DevDetachReply) 47 | err := c.conn.Invoke(ctx, in, out) 48 | if err != nil { 49 | return nil, err 50 | } 51 | return out, api.RetvalToVPPApiError(out.Retval) 52 | } 53 | 54 | func (c *serviceClient) DevRemovePortIf(ctx context.Context, in *DevRemovePortIf) (*DevRemovePortIfReply, error) { 55 | out := new(DevRemovePortIfReply) 56 | err := c.conn.Invoke(ctx, in, out) 57 | if err != nil { 58 | return nil, err 59 | } 60 | return out, api.RetvalToVPPApiError(out.Retval) 61 | } 62 | -------------------------------------------------------------------------------- /examples/multi-vpp/README.md: -------------------------------------------------------------------------------- 1 | # Multi-VPP example 2 | 3 | This example shows how to use GoVPP client to connect, configure and read stats from multiple VPPs simultaneously. 4 | 5 | # Requirements 6 | 7 | * VPP 19.08 or newer (required for stats client) 8 | * VPP stats enabled 9 | 10 | The example requires two running VPP instances. VPPs can be simply started in the same machine with different startup configs. Note that the default path to binary API and stats sockets are `/run/vpp/api.sock` or `/run/vpp/stats.sock` respectively. The example always uses the default path if none is set. It means that at least one VPP must have the following fields redefined: 11 | 12 | ``` 13 | socksvr { 14 | socket-name /run/custom-vpp-path/api.sock 15 | } 16 | 17 | statseg { 18 | socket-name /run/custom-vpp-path/stats.sock 19 | } 20 | ``` 21 | 22 | And the custom path must be provided to the example. Four flags are available: 23 | ``` 24 | -api-sock-1 string - Path to binary API socket file of the VPP1 (default "/run/vpp/api.sock") 25 | -api-sock-2 string - Path to binary API socket file of the VPP2 (default "/run/vpp/api.sock") 26 | -stats-sock-1 string - Path to stats socket file of the VPP1 (default "/run/vpp/stats.sock") 27 | -stats-sock-2 string - Path to stats socket file of the VPP2 (default "/run/vpp/stats.sock") 28 | ``` 29 | Let's say the VPP1 uses the default config, and the config above belongs to the VPP2. In that case, use the following command: 30 | ``` 31 | sudo ./multi-vpp -api-sock-2=/run/custom-vpp-path/api.sock -stats-sock-2=/run/custom-vpp-path/stats.sock 32 | ``` 33 | 34 | # Running the example 35 | 36 | The example consists of the following steps: 37 | * connects to both VPPs binary API socket and stats socket 38 | * configures example interfaces with IP addresses 39 | * dumps interface data via the binary API 40 | * dumps interface data via socket client 41 | * in case there are no errors, cleans up VPPs in order to be able running the example in a loop 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /codec/marshaler.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package codec 16 | 17 | import ( 18 | "bytes" 19 | "reflect" 20 | 21 | "github.com/lunixbochs/struc" 22 | 23 | "go.fd.io/govpp/api" 24 | ) 25 | 26 | // Marshaler is the interface implemented by the binary API messages that can 27 | // marshal itself into binary form for the wire. 28 | type Marshaler interface { 29 | Size() int 30 | Marshal([]byte) ([]byte, error) 31 | } 32 | 33 | // Unmarshaler is the interface implemented by the binary API messages that can 34 | // unmarshal a binary representation of itself from the wire. 35 | type Unmarshaler interface { 36 | Unmarshal([]byte) error 37 | } 38 | 39 | type Wrapper struct { 40 | api.Message 41 | } 42 | 43 | func (w Wrapper) Size() int { 44 | if size, err := struc.Sizeof(w.Message); err != nil { 45 | return 0 46 | } else { 47 | return size 48 | } 49 | } 50 | 51 | func (w Wrapper) Marshal(b []byte) ([]byte, error) { 52 | buf := new(bytes.Buffer) 53 | if reflect.TypeOf(w.Message).Elem().NumField() > 0 { 54 | if err := struc.Pack(buf, w.Message); err != nil { 55 | return nil, err 56 | } 57 | } 58 | if b != nil { 59 | copy(b, buf.Bytes()) 60 | } 61 | return buf.Bytes(), nil 62 | } 63 | 64 | func (w Wrapper) Unmarshal(data []byte) error { 65 | buf := bytes.NewReader(data) 66 | if err := struc.Unpack(buf, w.Message); err != nil { 67 | return err 68 | } 69 | return nil 70 | } 71 | -------------------------------------------------------------------------------- /binapi/gre/gre_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package gre 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service gre. 12 | type RPCService interface { 13 | GreTunnelAddDel(ctx context.Context, in *GreTunnelAddDel) (*GreTunnelAddDelReply, error) 14 | GreTunnelAddDelV2(ctx context.Context, in *GreTunnelAddDelV2) (*GreTunnelAddDelV2Reply, error) 15 | GreTunnelDump(ctx context.Context, in *GreTunnelDump) (*GreTunnelDumpReply, error) 16 | GreTunnelDumpV2(ctx context.Context, in *GreTunnelDumpV2) (*GreTunnelDumpV2Reply, error) 17 | } 18 | 19 | type serviceClient struct { 20 | conn api.Connection 21 | } 22 | 23 | func NewServiceClient(conn api.Connection) RPCService { 24 | return &serviceClient{conn} 25 | } 26 | 27 | func (c *serviceClient) GreTunnelAddDel(ctx context.Context, in *GreTunnelAddDel) (*GreTunnelAddDelReply, error) { 28 | out := new(GreTunnelAddDelReply) 29 | err := c.conn.Invoke(ctx, in, out) 30 | if err != nil { 31 | return nil, err 32 | } 33 | return out, api.RetvalToVPPApiError(out.Retval) 34 | } 35 | 36 | func (c *serviceClient) GreTunnelAddDelV2(ctx context.Context, in *GreTunnelAddDelV2) (*GreTunnelAddDelV2Reply, error) { 37 | out := new(GreTunnelAddDelV2Reply) 38 | err := c.conn.Invoke(ctx, in, out) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return out, api.RetvalToVPPApiError(out.Retval) 43 | } 44 | 45 | func (c *serviceClient) GreTunnelDump(ctx context.Context, in *GreTunnelDump) (*GreTunnelDumpReply, error) { 46 | out := new(GreTunnelDumpReply) 47 | err := c.conn.Invoke(ctx, in, out) 48 | if err != nil { 49 | return nil, err 50 | } 51 | return out, api.RetvalToVPPApiError(out.Retval) 52 | } 53 | 54 | func (c *serviceClient) GreTunnelDumpV2(ctx context.Context, in *GreTunnelDumpV2) (*GreTunnelDumpV2Reply, error) { 55 | out := new(GreTunnelDumpV2Reply) 56 | err := c.conn.Invoke(ctx, in, out) 57 | if err != nil { 58 | return nil, err 59 | } 60 | return out, api.RetvalToVPPApiError(out.Retval) 61 | } 62 | -------------------------------------------------------------------------------- /test/integration/trace_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package integration 16 | 17 | import ( 18 | "context" 19 | "fmt" 20 | "testing" 21 | 22 | "go.fd.io/govpp/api" 23 | "go.fd.io/govpp/binapi/vpe" 24 | "go.fd.io/govpp/core" 25 | "go.fd.io/govpp/test/vpptesting" 26 | ) 27 | 28 | func TestTrace(t *testing.T) { 29 | test := vpptesting.SetupVPP(t) 30 | 31 | trace := core.NewTrace(test.Conn, 50) 32 | 33 | runTraceRequests(t, test) 34 | 35 | records := trace.GetRecords() 36 | 37 | if len(records) != 2 { 38 | t.Fatalf("expected 2 records, got %d", len(records)) 39 | } 40 | 41 | printTraceRecords(t, records) 42 | } 43 | 44 | func printTraceRecords(t *testing.T, records []*api.Record) { 45 | t.Logf("API trace (records: %d):\n", len(records)) 46 | t.Logf("--------------------\n") 47 | for _, item := range records { 48 | h, m, s := item.Timestamp.Clock() 49 | reply := "" 50 | if item.IsReceived { 51 | reply = "(reply)" 52 | } 53 | fmt.Printf("%dh:%dm:%ds:%dns %s %s\n", h, m, s, 54 | item.Timestamp.Nanosecond(), item.Message.GetMessageName(), reply) 55 | } 56 | t.Logf("--------------------\n") 57 | } 58 | 59 | func runTraceRequests(t *testing.T, test *vpptesting.TestCtx) { 60 | vpeRPC := vpe.NewServiceClient(test.Conn) 61 | 62 | _, err := vpeRPC.ShowVersion(context.Background(), &vpe.ShowVersion{}) 63 | if err != nil { 64 | t.Fatalf("getting version failed: %v", err) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /binapi/dns/dns_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package dns 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service dns. 12 | type RPCService interface { 13 | DNSEnableDisable(ctx context.Context, in *DNSEnableDisable) (*DNSEnableDisableReply, error) 14 | DNSNameServerAddDel(ctx context.Context, in *DNSNameServerAddDel) (*DNSNameServerAddDelReply, error) 15 | DNSResolveIP(ctx context.Context, in *DNSResolveIP) (*DNSResolveIPReply, error) 16 | DNSResolveName(ctx context.Context, in *DNSResolveName) (*DNSResolveNameReply, error) 17 | } 18 | 19 | type serviceClient struct { 20 | conn api.Connection 21 | } 22 | 23 | func NewServiceClient(conn api.Connection) RPCService { 24 | return &serviceClient{conn} 25 | } 26 | 27 | func (c *serviceClient) DNSEnableDisable(ctx context.Context, in *DNSEnableDisable) (*DNSEnableDisableReply, error) { 28 | out := new(DNSEnableDisableReply) 29 | err := c.conn.Invoke(ctx, in, out) 30 | if err != nil { 31 | return nil, err 32 | } 33 | return out, api.RetvalToVPPApiError(out.Retval) 34 | } 35 | 36 | func (c *serviceClient) DNSNameServerAddDel(ctx context.Context, in *DNSNameServerAddDel) (*DNSNameServerAddDelReply, error) { 37 | out := new(DNSNameServerAddDelReply) 38 | err := c.conn.Invoke(ctx, in, out) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return out, api.RetvalToVPPApiError(out.Retval) 43 | } 44 | 45 | func (c *serviceClient) DNSResolveIP(ctx context.Context, in *DNSResolveIP) (*DNSResolveIPReply, error) { 46 | out := new(DNSResolveIPReply) 47 | err := c.conn.Invoke(ctx, in, out) 48 | if err != nil { 49 | return nil, err 50 | } 51 | return out, api.RetvalToVPPApiError(out.Retval) 52 | } 53 | 54 | func (c *serviceClient) DNSResolveName(ctx context.Context, in *DNSResolveName) (*DNSResolveNameReply, error) { 55 | out := new(DNSResolveNameReply) 56 | err := c.conn.Invoke(ctx, in, out) 57 | if err != nil { 58 | return nil, err 59 | } 60 | return out, api.RetvalToVPPApiError(out.Retval) 61 | } 62 | -------------------------------------------------------------------------------- /binapi/syslog/syslog_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package syslog 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service syslog. 12 | type RPCService interface { 13 | SyslogGetFilter(ctx context.Context, in *SyslogGetFilter) (*SyslogGetFilterReply, error) 14 | SyslogGetSender(ctx context.Context, in *SyslogGetSender) (*SyslogGetSenderReply, error) 15 | SyslogSetFilter(ctx context.Context, in *SyslogSetFilter) (*SyslogSetFilterReply, error) 16 | SyslogSetSender(ctx context.Context, in *SyslogSetSender) (*SyslogSetSenderReply, error) 17 | } 18 | 19 | type serviceClient struct { 20 | conn api.Connection 21 | } 22 | 23 | func NewServiceClient(conn api.Connection) RPCService { 24 | return &serviceClient{conn} 25 | } 26 | 27 | func (c *serviceClient) SyslogGetFilter(ctx context.Context, in *SyslogGetFilter) (*SyslogGetFilterReply, error) { 28 | out := new(SyslogGetFilterReply) 29 | err := c.conn.Invoke(ctx, in, out) 30 | if err != nil { 31 | return nil, err 32 | } 33 | return out, api.RetvalToVPPApiError(out.Retval) 34 | } 35 | 36 | func (c *serviceClient) SyslogGetSender(ctx context.Context, in *SyslogGetSender) (*SyslogGetSenderReply, error) { 37 | out := new(SyslogGetSenderReply) 38 | err := c.conn.Invoke(ctx, in, out) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return out, api.RetvalToVPPApiError(out.Retval) 43 | } 44 | 45 | func (c *serviceClient) SyslogSetFilter(ctx context.Context, in *SyslogSetFilter) (*SyslogSetFilterReply, error) { 46 | out := new(SyslogSetFilterReply) 47 | err := c.conn.Invoke(ctx, in, out) 48 | if err != nil { 49 | return nil, err 50 | } 51 | return out, api.RetvalToVPPApiError(out.Retval) 52 | } 53 | 54 | func (c *serviceClient) SyslogSetSender(ctx context.Context, in *SyslogSetSender) (*SyslogSetSenderReply, error) { 55 | out := new(SyslogSetSenderReply) 56 | err := c.conn.Invoke(ctx, in, out) 57 | if err != nil { 58 | return nil, err 59 | } 60 | return out, api.RetvalToVPPApiError(out.Retval) 61 | } 62 | -------------------------------------------------------------------------------- /binapi/teib/teib_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package teib 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service teib. 15 | type RPCService interface { 16 | TeibDump(ctx context.Context, in *TeibDump) (RPCService_TeibDumpClient, error) 17 | TeibEntryAddDel(ctx context.Context, in *TeibEntryAddDel) (*TeibEntryAddDelReply, error) 18 | } 19 | 20 | type serviceClient struct { 21 | conn api.Connection 22 | } 23 | 24 | func NewServiceClient(conn api.Connection) RPCService { 25 | return &serviceClient{conn} 26 | } 27 | 28 | func (c *serviceClient) TeibDump(ctx context.Context, in *TeibDump) (RPCService_TeibDumpClient, error) { 29 | stream, err := c.conn.NewStream(ctx) 30 | if err != nil { 31 | return nil, err 32 | } 33 | x := &serviceClient_TeibDumpClient{stream} 34 | if err := x.Stream.SendMsg(in); err != nil { 35 | return nil, err 36 | } 37 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 38 | return nil, err 39 | } 40 | return x, nil 41 | } 42 | 43 | type RPCService_TeibDumpClient interface { 44 | Recv() (*TeibDetails, error) 45 | api.Stream 46 | } 47 | 48 | type serviceClient_TeibDumpClient struct { 49 | api.Stream 50 | } 51 | 52 | func (c *serviceClient_TeibDumpClient) Recv() (*TeibDetails, error) { 53 | msg, err := c.Stream.RecvMsg() 54 | if err != nil { 55 | return nil, err 56 | } 57 | switch m := msg.(type) { 58 | case *TeibDetails: 59 | return m, nil 60 | case *memclnt.ControlPingReply: 61 | err = c.Stream.Close() 62 | if err != nil { 63 | return nil, err 64 | } 65 | return nil, io.EOF 66 | default: 67 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 68 | } 69 | } 70 | 71 | func (c *serviceClient) TeibEntryAddDel(ctx context.Context, in *TeibEntryAddDel) (*TeibEntryAddDelReply, error) { 72 | out := new(TeibEntryAddDelReply) 73 | err := c.conn.Invoke(ctx, in, out) 74 | if err != nil { 75 | return nil, err 76 | } 77 | return out, api.RetvalToVPPApiError(out.Retval) 78 | } 79 | -------------------------------------------------------------------------------- /test/integration/README.md: -------------------------------------------------------------------------------- 1 | Integration Tests 2 | ================= 3 | 4 | The GoVPP integration testing suite runs each test case against real VPP instance. 5 | 6 | The integration tests cases are grouped by files: 7 | - `binapi` - runs tests for VPP API 8 | - `examples` - run examples as tests 9 | - `stats` - runs tests for VPP Stats 10 | - `trace` - runs tests for VPP API trace 11 | - `*` (*other*) - runs specialized tests 12 | 13 | ## Running Tests 14 | 15 | The recommended way to run the integration tests is to use a self-contained testing environment, which is managed from a helper bash script [`run_integration.sh`](../run_integration.sh). The script will build a special Docker image that includes testing suite and other requirements (e.g. VPP, gotestsum..) and then will run the integration tests inside a container. 16 | 17 | ```shell 18 | make test-integration 19 | ``` 20 | 21 | This will run the tests against latest VPP release by default. To run against specific VPP version, add `VPP_REPO=` where `` is name of VPP repostiroy on packagecloud. 22 | 23 | ```shell 24 | # Run against specific VPP version 25 | make test-integration VPP_REPO=2306 26 | 27 | # Run against VPP master branch 28 | make test-integration VPP_REPO=master 29 | ``` 30 | 31 | The make target above simply runs a helper script which accepts additional arguments that are passed down directly to `go test ...`. 32 | 33 | ```shell 34 | # Usage: 35 | # ./test/integration/run_integration.sh 36 | 37 | # Run with verbose mode 38 | ./test/run_integration.sh -test.v 39 | ``` 40 | 41 | ### Run Specific Test Case 42 | 43 | To run a specific integration test case(s): 44 | 45 | ```shell 46 | ./test/run_integration.sh -test.run="Interfaces" 47 | ``` 48 | 49 | ## Running Tests on your Host 50 | 51 | If the script `run_integration.sh` is not used to run tests and the test cases 52 | are directly used, the tests will try to start/stop VPP instance for each test 53 | case individually. 54 | 55 | > **Warning** 56 | > This method requires VPP to be installed on your host system. 57 | 58 | ```shell 59 | TEST=integration go test ./test/integration 60 | ``` 61 | -------------------------------------------------------------------------------- /docs/RELEASE.md: -------------------------------------------------------------------------------- 1 | # Release 2 | 3 | This document desribes the GoVPP releases. 4 | 5 | ## Versioning 6 | 7 | The GoVPP uses the [Semantic Versioning](https://semver.org/) for the release versions. 8 | 9 | The current MAJOR version of GoVPP is `0`, meaning it's still under development that might occasionally do larger breaking changes. However, we try to avoid this if possible to minimize the user impact. 10 | 11 | ## Release Cycle 12 | 13 | The MINOR releases of GoVPP should be released **approximately 2 weeks after a VPP release** at minimum. Any additional MINOR releases for GoVPP can possibly happen between VPP releases if needed. 14 | 15 | The PATCH releases should be released whenever it is required to publish a fix to users. 16 | 17 | ## Release Tracking 18 | 19 | Each release has its own [milestone](https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/about-milestones) created with a due date of the expected release date. List of milestones can be found here: https://github.com/FDio/govpp/milestones 20 | 21 | Every issue/PR that shoukd be part of a specific release should have milestone set. 22 | 23 | ## Release Process 24 | 25 | 1. Verify the state of `master` branch for the release: 26 | - Check if all issues/PRs that are part of the release milestone are closed 27 | - Check if the generated `binapi` is compatible with the lastest VPP release 28 | 2. Prepare the release in a PR with the following changes: 29 | - Update [CHANGELOG.md](https://github.com/FDio/govpp/blob/master/CHANGELOG.md) with the list of changes for new version 30 | - Update version in [version](https://github.com/FDio/govpp/blob/master/version/version.go) package to `v0.X.0` without any suffix (remove `-dev`) 31 | 3. Once PR merges to master, tag it with `v0.X.0` using annotated, signed tag & push the tag to repository 32 | ```sh 33 | git tag --sign --annotate --message "govpp v0.X.0" v0.X.0 34 | ``` 35 | 6. After the release tag is pushed, begin development of the next release using the following steps: 36 | - Update version in [version](https://github.com/FDio/govpp/blob/master/version/version.go) package to `v0.X+1.0-dev` 37 | -------------------------------------------------------------------------------- /govpp.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package govpp 16 | 17 | import ( 18 | "time" 19 | 20 | "go.fd.io/govpp/adapter" 21 | "go.fd.io/govpp/adapter/socketclient" 22 | "go.fd.io/govpp/core" 23 | "go.fd.io/govpp/internal/version" 24 | ) 25 | 26 | // Connect connects to the VPP API using a new adapter instance created with NewVppAPIAdapter. 27 | // 28 | // This call blocks until VPP is connected, or an error occurs. 29 | // Only one connection attempt will be performed. 30 | func Connect(target string) (*core.Connection, error) { 31 | return core.Connect(NewVppAdapter(target)) 32 | } 33 | 34 | // AsyncConnect asynchronously connects to the VPP API using a new adapter instance 35 | // created with NewVppAPIAdapter. 36 | // 37 | // This call does not block until connection is established, it returns immediately. 38 | // The caller is supposed to watch the returned ConnectionState channel for connection events. 39 | // In case of disconnect, the library will asynchronously try to reconnect. 40 | func AsyncConnect(target string, attempts int, interval time.Duration) (*core.Connection, chan core.ConnectionEvent, error) { 41 | return core.AsyncConnect(NewVppAdapter(target), attempts, interval) 42 | } 43 | 44 | // NewVppAdapter returns new instance of VPP adapter for connecting to VPP API. 45 | var NewVppAdapter = func(target string) adapter.VppAPI { 46 | return socketclient.NewVppClient(target) 47 | } 48 | 49 | // Version returns version of GoVPP. 50 | func Version() string { 51 | return version.Version() 52 | } 53 | -------------------------------------------------------------------------------- /binapi/stn/stn_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package stn 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service stn. 15 | type RPCService interface { 16 | StnAddDelRule(ctx context.Context, in *StnAddDelRule) (*StnAddDelRuleReply, error) 17 | StnRulesDump(ctx context.Context, in *StnRulesDump) (RPCService_StnRulesDumpClient, error) 18 | } 19 | 20 | type serviceClient struct { 21 | conn api.Connection 22 | } 23 | 24 | func NewServiceClient(conn api.Connection) RPCService { 25 | return &serviceClient{conn} 26 | } 27 | 28 | func (c *serviceClient) StnAddDelRule(ctx context.Context, in *StnAddDelRule) (*StnAddDelRuleReply, error) { 29 | out := new(StnAddDelRuleReply) 30 | err := c.conn.Invoke(ctx, in, out) 31 | if err != nil { 32 | return nil, err 33 | } 34 | return out, api.RetvalToVPPApiError(out.Retval) 35 | } 36 | 37 | func (c *serviceClient) StnRulesDump(ctx context.Context, in *StnRulesDump) (RPCService_StnRulesDumpClient, error) { 38 | stream, err := c.conn.NewStream(ctx) 39 | if err != nil { 40 | return nil, err 41 | } 42 | x := &serviceClient_StnRulesDumpClient{stream} 43 | if err := x.Stream.SendMsg(in); err != nil { 44 | return nil, err 45 | } 46 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 47 | return nil, err 48 | } 49 | return x, nil 50 | } 51 | 52 | type RPCService_StnRulesDumpClient interface { 53 | Recv() (*StnRulesDetails, error) 54 | api.Stream 55 | } 56 | 57 | type serviceClient_StnRulesDumpClient struct { 58 | api.Stream 59 | } 60 | 61 | func (c *serviceClient_StnRulesDumpClient) Recv() (*StnRulesDetails, error) { 62 | msg, err := c.Stream.RecvMsg() 63 | if err != nil { 64 | return nil, err 65 | } 66 | switch m := msg.(type) { 67 | case *StnRulesDetails: 68 | return m, nil 69 | case *memclnt.ControlPingReply: 70 | err = c.Stream.Close() 71 | if err != nil { 72 | return nil, err 73 | } 74 | return nil, io.EOF 75 | default: 76 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /binapi/fib/fib_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package fib 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service fib. 15 | type RPCService interface { 16 | FibSourceAdd(ctx context.Context, in *FibSourceAdd) (*FibSourceAddReply, error) 17 | FibSourceDump(ctx context.Context, in *FibSourceDump) (RPCService_FibSourceDumpClient, error) 18 | } 19 | 20 | type serviceClient struct { 21 | conn api.Connection 22 | } 23 | 24 | func NewServiceClient(conn api.Connection) RPCService { 25 | return &serviceClient{conn} 26 | } 27 | 28 | func (c *serviceClient) FibSourceAdd(ctx context.Context, in *FibSourceAdd) (*FibSourceAddReply, error) { 29 | out := new(FibSourceAddReply) 30 | err := c.conn.Invoke(ctx, in, out) 31 | if err != nil { 32 | return nil, err 33 | } 34 | return out, api.RetvalToVPPApiError(out.Retval) 35 | } 36 | 37 | func (c *serviceClient) FibSourceDump(ctx context.Context, in *FibSourceDump) (RPCService_FibSourceDumpClient, error) { 38 | stream, err := c.conn.NewStream(ctx) 39 | if err != nil { 40 | return nil, err 41 | } 42 | x := &serviceClient_FibSourceDumpClient{stream} 43 | if err := x.Stream.SendMsg(in); err != nil { 44 | return nil, err 45 | } 46 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 47 | return nil, err 48 | } 49 | return x, nil 50 | } 51 | 52 | type RPCService_FibSourceDumpClient interface { 53 | Recv() (*FibSourceDetails, error) 54 | api.Stream 55 | } 56 | 57 | type serviceClient_FibSourceDumpClient struct { 58 | api.Stream 59 | } 60 | 61 | func (c *serviceClient_FibSourceDumpClient) Recv() (*FibSourceDetails, error) { 62 | msg, err := c.Stream.RecvMsg() 63 | if err != nil { 64 | return nil, err 65 | } 66 | switch m := msg.(type) { 67 | case *FibSourceDetails: 68 | return m, nil 69 | case *memclnt.ControlPingReply: 70 | err = c.Stream.Close() 71 | if err != nil { 72 | return nil, err 73 | } 74 | return nil, io.EOF 75 | default: 76 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /cmd/govpp/util.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "regexp" 20 | "sort" 21 | "strings" 22 | 23 | "github.com/gookit/color" 24 | "github.com/sirupsen/logrus" 25 | ) 26 | 27 | var ( 28 | clrWhite = color.Style{color.White} 29 | clrDiffMessage = color.Style{color.Cyan} 30 | clrDiffOption = color.Style{color.Blue} 31 | clrDiffFile = color.Style{color.Yellow} 32 | clrDiffVersion = color.Style{color.LightMagenta} 33 | clrDiffNumber = color.Style{color.LightBlue} 34 | ) 35 | 36 | const ( 37 | codeSuffix = "[0m" 38 | codeExpr = `(\\u001b|\033)\[[\d;?]+m` 39 | ) 40 | 41 | var codeRegex = regexp.MustCompile(codeExpr) 42 | 43 | func clearColorCode(str string) string { 44 | if !strings.Contains(str, codeSuffix) { 45 | return str 46 | } 47 | return codeRegex.ReplaceAllString(str, "") 48 | } 49 | 50 | func mapStr(data map[string]string) string { 51 | var str string 52 | for k, v := range data { 53 | if len(str) > 0 { 54 | str += ", " 55 | } 56 | if v == "" { 57 | str += k 58 | } else { 59 | str += fmt.Sprintf("%s: %q", k, v) 60 | } 61 | } 62 | return str 63 | } 64 | 65 | func mapStrOrdered(data map[string]string) string { 66 | var strs []string 67 | for k, v := range data { 68 | var str string 69 | if v == "" { 70 | str = k 71 | } else { 72 | str = fmt.Sprintf("%s: %q", k, v) 73 | } 74 | strs = append(strs, str) 75 | } 76 | sort.Strings(strs) 77 | return strings.Join(strs, ", ") 78 | } 79 | 80 | func must(err error) { 81 | if err != nil { 82 | logrus.Fatal(err) 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /binapi/nsim/nsim_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package nsim 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service nsim. 12 | type RPCService interface { 13 | NsimConfigure(ctx context.Context, in *NsimConfigure) (*NsimConfigureReply, error) 14 | NsimConfigure2(ctx context.Context, in *NsimConfigure2) (*NsimConfigure2Reply, error) 15 | NsimCrossConnectEnableDisable(ctx context.Context, in *NsimCrossConnectEnableDisable) (*NsimCrossConnectEnableDisableReply, error) 16 | NsimOutputFeatureEnableDisable(ctx context.Context, in *NsimOutputFeatureEnableDisable) (*NsimOutputFeatureEnableDisableReply, error) 17 | } 18 | 19 | type serviceClient struct { 20 | conn api.Connection 21 | } 22 | 23 | func NewServiceClient(conn api.Connection) RPCService { 24 | return &serviceClient{conn} 25 | } 26 | 27 | func (c *serviceClient) NsimConfigure(ctx context.Context, in *NsimConfigure) (*NsimConfigureReply, error) { 28 | out := new(NsimConfigureReply) 29 | err := c.conn.Invoke(ctx, in, out) 30 | if err != nil { 31 | return nil, err 32 | } 33 | return out, api.RetvalToVPPApiError(out.Retval) 34 | } 35 | 36 | func (c *serviceClient) NsimConfigure2(ctx context.Context, in *NsimConfigure2) (*NsimConfigure2Reply, error) { 37 | out := new(NsimConfigure2Reply) 38 | err := c.conn.Invoke(ctx, in, out) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return out, api.RetvalToVPPApiError(out.Retval) 43 | } 44 | 45 | func (c *serviceClient) NsimCrossConnectEnableDisable(ctx context.Context, in *NsimCrossConnectEnableDisable) (*NsimCrossConnectEnableDisableReply, error) { 46 | out := new(NsimCrossConnectEnableDisableReply) 47 | err := c.conn.Invoke(ctx, in, out) 48 | if err != nil { 49 | return nil, err 50 | } 51 | return out, api.RetvalToVPPApiError(out.Retval) 52 | } 53 | 54 | func (c *serviceClient) NsimOutputFeatureEnableDisable(ctx context.Context, in *NsimOutputFeatureEnableDisable) (*NsimOutputFeatureEnableDisableReply, error) { 55 | out := new(NsimOutputFeatureEnableDisableReply) 56 | err := c.conn.Invoke(ctx, in, out) 57 | if err != nil { 58 | return nil, err 59 | } 60 | return out, api.RetvalToVPPApiError(out.Retval) 61 | } 62 | -------------------------------------------------------------------------------- /binapi/flow/flow_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package flow 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service flow. 12 | type RPCService interface { 13 | FlowAdd(ctx context.Context, in *FlowAdd) (*FlowAddReply, error) 14 | FlowAddV2(ctx context.Context, in *FlowAddV2) (*FlowAddV2Reply, error) 15 | FlowDel(ctx context.Context, in *FlowDel) (*FlowDelReply, error) 16 | FlowDisable(ctx context.Context, in *FlowDisable) (*FlowDisableReply, error) 17 | FlowEnable(ctx context.Context, in *FlowEnable) (*FlowEnableReply, error) 18 | } 19 | 20 | type serviceClient struct { 21 | conn api.Connection 22 | } 23 | 24 | func NewServiceClient(conn api.Connection) RPCService { 25 | return &serviceClient{conn} 26 | } 27 | 28 | func (c *serviceClient) FlowAdd(ctx context.Context, in *FlowAdd) (*FlowAddReply, error) { 29 | out := new(FlowAddReply) 30 | err := c.conn.Invoke(ctx, in, out) 31 | if err != nil { 32 | return nil, err 33 | } 34 | return out, api.RetvalToVPPApiError(out.Retval) 35 | } 36 | 37 | func (c *serviceClient) FlowAddV2(ctx context.Context, in *FlowAddV2) (*FlowAddV2Reply, error) { 38 | out := new(FlowAddV2Reply) 39 | err := c.conn.Invoke(ctx, in, out) 40 | if err != nil { 41 | return nil, err 42 | } 43 | return out, api.RetvalToVPPApiError(out.Retval) 44 | } 45 | 46 | func (c *serviceClient) FlowDel(ctx context.Context, in *FlowDel) (*FlowDelReply, error) { 47 | out := new(FlowDelReply) 48 | err := c.conn.Invoke(ctx, in, out) 49 | if err != nil { 50 | return nil, err 51 | } 52 | return out, api.RetvalToVPPApiError(out.Retval) 53 | } 54 | 55 | func (c *serviceClient) FlowDisable(ctx context.Context, in *FlowDisable) (*FlowDisableReply, error) { 56 | out := new(FlowDisableReply) 57 | err := c.conn.Invoke(ctx, in, out) 58 | if err != nil { 59 | return nil, err 60 | } 61 | return out, api.RetvalToVPPApiError(out.Retval) 62 | } 63 | 64 | func (c *serviceClient) FlowEnable(ctx context.Context, in *FlowEnable) (*FlowEnableReply, error) { 65 | out := new(FlowEnableReply) 66 | err := c.conn.Invoke(ctx, in, out) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return out, api.RetvalToVPPApiError(out.Retval) 71 | } 72 | -------------------------------------------------------------------------------- /binapi/mss_clamp/mss_clamp_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package mss_clamp 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | ) 12 | 13 | // RPCService defines RPC service mss_clamp. 14 | type RPCService interface { 15 | MssClampEnableDisable(ctx context.Context, in *MssClampEnableDisable) (*MssClampEnableDisableReply, error) 16 | MssClampGet(ctx context.Context, in *MssClampGet) (RPCService_MssClampGetClient, error) 17 | } 18 | 19 | type serviceClient struct { 20 | conn api.Connection 21 | } 22 | 23 | func NewServiceClient(conn api.Connection) RPCService { 24 | return &serviceClient{conn} 25 | } 26 | 27 | func (c *serviceClient) MssClampEnableDisable(ctx context.Context, in *MssClampEnableDisable) (*MssClampEnableDisableReply, error) { 28 | out := new(MssClampEnableDisableReply) 29 | err := c.conn.Invoke(ctx, in, out) 30 | if err != nil { 31 | return nil, err 32 | } 33 | return out, api.RetvalToVPPApiError(out.Retval) 34 | } 35 | 36 | func (c *serviceClient) MssClampGet(ctx context.Context, in *MssClampGet) (RPCService_MssClampGetClient, error) { 37 | stream, err := c.conn.NewStream(ctx) 38 | if err != nil { 39 | return nil, err 40 | } 41 | x := &serviceClient_MssClampGetClient{stream} 42 | if err := x.Stream.SendMsg(in); err != nil { 43 | return nil, err 44 | } 45 | return x, nil 46 | } 47 | 48 | type RPCService_MssClampGetClient interface { 49 | Recv() (*MssClampDetails, *MssClampGetReply, error) 50 | api.Stream 51 | } 52 | 53 | type serviceClient_MssClampGetClient struct { 54 | api.Stream 55 | } 56 | 57 | func (c *serviceClient_MssClampGetClient) Recv() (*MssClampDetails, *MssClampGetReply, error) { 58 | msg, err := c.Stream.RecvMsg() 59 | if err != nil { 60 | return nil, nil, err 61 | } 62 | switch m := msg.(type) { 63 | case *MssClampDetails: 64 | return m, nil, nil 65 | case *MssClampGetReply: 66 | if err := api.RetvalToVPPApiError(m.Retval); err != nil { 67 | c.Stream.Close() 68 | return nil, m, err 69 | } 70 | err = c.Stream.Close() 71 | if err != nil { 72 | return nil, m, err 73 | } 74 | return nil, m, io.EOF 75 | default: 76 | return nil, nil, fmt.Errorf("unexpected message: %T %v", m, m) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /binapi/rdma/rdma_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package rdma 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service rdma. 12 | type RPCService interface { 13 | RdmaCreate(ctx context.Context, in *RdmaCreate) (*RdmaCreateReply, error) 14 | RdmaCreateV2(ctx context.Context, in *RdmaCreateV2) (*RdmaCreateV2Reply, error) 15 | RdmaCreateV3(ctx context.Context, in *RdmaCreateV3) (*RdmaCreateV3Reply, error) 16 | RdmaCreateV4(ctx context.Context, in *RdmaCreateV4) (*RdmaCreateV4Reply, error) 17 | RdmaDelete(ctx context.Context, in *RdmaDelete) (*RdmaDeleteReply, error) 18 | } 19 | 20 | type serviceClient struct { 21 | conn api.Connection 22 | } 23 | 24 | func NewServiceClient(conn api.Connection) RPCService { 25 | return &serviceClient{conn} 26 | } 27 | 28 | func (c *serviceClient) RdmaCreate(ctx context.Context, in *RdmaCreate) (*RdmaCreateReply, error) { 29 | out := new(RdmaCreateReply) 30 | err := c.conn.Invoke(ctx, in, out) 31 | if err != nil { 32 | return nil, err 33 | } 34 | return out, api.RetvalToVPPApiError(out.Retval) 35 | } 36 | 37 | func (c *serviceClient) RdmaCreateV2(ctx context.Context, in *RdmaCreateV2) (*RdmaCreateV2Reply, error) { 38 | out := new(RdmaCreateV2Reply) 39 | err := c.conn.Invoke(ctx, in, out) 40 | if err != nil { 41 | return nil, err 42 | } 43 | return out, api.RetvalToVPPApiError(out.Retval) 44 | } 45 | 46 | func (c *serviceClient) RdmaCreateV3(ctx context.Context, in *RdmaCreateV3) (*RdmaCreateV3Reply, error) { 47 | out := new(RdmaCreateV3Reply) 48 | err := c.conn.Invoke(ctx, in, out) 49 | if err != nil { 50 | return nil, err 51 | } 52 | return out, api.RetvalToVPPApiError(out.Retval) 53 | } 54 | 55 | func (c *serviceClient) RdmaCreateV4(ctx context.Context, in *RdmaCreateV4) (*RdmaCreateV4Reply, error) { 56 | out := new(RdmaCreateV4Reply) 57 | err := c.conn.Invoke(ctx, in, out) 58 | if err != nil { 59 | return nil, err 60 | } 61 | return out, api.RetvalToVPPApiError(out.Retval) 62 | } 63 | 64 | func (c *serviceClient) RdmaDelete(ctx context.Context, in *RdmaDelete) (*RdmaDeleteReply, error) { 65 | out := new(RdmaDeleteReply) 66 | err := c.conn.Invoke(ctx, in, out) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return out, api.RetvalToVPPApiError(out.Retval) 71 | } 72 | -------------------------------------------------------------------------------- /binapi/span/span_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package span 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service span. 15 | type RPCService interface { 16 | SwInterfaceSpanDump(ctx context.Context, in *SwInterfaceSpanDump) (RPCService_SwInterfaceSpanDumpClient, error) 17 | SwInterfaceSpanEnableDisable(ctx context.Context, in *SwInterfaceSpanEnableDisable) (*SwInterfaceSpanEnableDisableReply, error) 18 | } 19 | 20 | type serviceClient struct { 21 | conn api.Connection 22 | } 23 | 24 | func NewServiceClient(conn api.Connection) RPCService { 25 | return &serviceClient{conn} 26 | } 27 | 28 | func (c *serviceClient) SwInterfaceSpanDump(ctx context.Context, in *SwInterfaceSpanDump) (RPCService_SwInterfaceSpanDumpClient, error) { 29 | stream, err := c.conn.NewStream(ctx) 30 | if err != nil { 31 | return nil, err 32 | } 33 | x := &serviceClient_SwInterfaceSpanDumpClient{stream} 34 | if err := x.Stream.SendMsg(in); err != nil { 35 | return nil, err 36 | } 37 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 38 | return nil, err 39 | } 40 | return x, nil 41 | } 42 | 43 | type RPCService_SwInterfaceSpanDumpClient interface { 44 | Recv() (*SwInterfaceSpanDetails, error) 45 | api.Stream 46 | } 47 | 48 | type serviceClient_SwInterfaceSpanDumpClient struct { 49 | api.Stream 50 | } 51 | 52 | func (c *serviceClient_SwInterfaceSpanDumpClient) Recv() (*SwInterfaceSpanDetails, error) { 53 | msg, err := c.Stream.RecvMsg() 54 | if err != nil { 55 | return nil, err 56 | } 57 | switch m := msg.(type) { 58 | case *SwInterfaceSpanDetails: 59 | return m, nil 60 | case *memclnt.ControlPingReply: 61 | err = c.Stream.Close() 62 | if err != nil { 63 | return nil, err 64 | } 65 | return nil, io.EOF 66 | default: 67 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 68 | } 69 | } 70 | 71 | func (c *serviceClient) SwInterfaceSpanEnableDisable(ctx context.Context, in *SwInterfaceSpanEnableDisable) (*SwInterfaceSpanEnableDisableReply, error) { 72 | out := new(SwInterfaceSpanEnableDisableReply) 73 | err := c.conn.Invoke(ctx, in, out) 74 | if err != nil { 75 | return nil, err 76 | } 77 | return out, api.RetvalToVPPApiError(out.Retval) 78 | } 79 | -------------------------------------------------------------------------------- /adapter/vpp_api.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package adapter 16 | 17 | import ( 18 | "errors" 19 | "fmt" 20 | ) 21 | 22 | const ( 23 | // DefaultBinapiSocket defines a default socket file path for VPP binary API. 24 | DefaultBinapiSocket = "/run/vpp/api.sock" 25 | ) 26 | 27 | var ( 28 | // ErrNotImplemented is an error returned when missing implementation. 29 | ErrNotImplemented = errors.New("not implemented for this OS") 30 | ) 31 | 32 | // MsgCallback defines func signature for message callback. 33 | type MsgCallback func(msgID uint16, data []byte) 34 | 35 | // VppAPI provides connection to VPP binary API. 36 | // It is responsible for sending and receiving of binary-encoded messages to/from VPP. 37 | type VppAPI interface { 38 | // Connect connects the process to VPP. 39 | Connect() error 40 | 41 | // Disconnect disconnects the process from VPP. 42 | Disconnect() error 43 | 44 | // GetMsgID returns a runtime message ID for the given message name and CRC. 45 | GetMsgID(msgName string, msgCrc string) (msgID uint16, err error) 46 | 47 | // SendMsg sends a binary-encoded message to VPP. 48 | SendMsg(context uint32, data []byte) error 49 | 50 | // SetMsgCallback sets a callback function that will be called by the adapter whenever a message comes from VPP. 51 | SetMsgCallback(cb MsgCallback) 52 | 53 | // WaitReady waits until adapter is ready. 54 | WaitReady() error 55 | } 56 | 57 | // UnknownMsgError is the error type usually returned by GetMsgID 58 | // method of VppAPI. It describes the name and CRC for the unknown message. 59 | type UnknownMsgError struct { 60 | MsgName string 61 | MsgCrc string 62 | } 63 | 64 | func (u *UnknownMsgError) Error() string { 65 | return fmt.Sprintf("unknown message: %s_%s", u.MsgName, u.MsgCrc) 66 | } 67 | -------------------------------------------------------------------------------- /cmd/govpp/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "bytes" 19 | "fmt" 20 | "path/filepath" 21 | "runtime" 22 | "strings" 23 | 24 | "github.com/gookit/color" 25 | "github.com/sirupsen/logrus" 26 | ) 27 | 28 | const modulePath = "go.fd.io/govpp" 29 | 30 | var ( 31 | logstyleFilename = color.Style{color.LightWhite} 32 | logstyleFilenum = color.Style{color.White} 33 | logstyleFuncname = color.Style{color.LightBlue} 34 | logstyleFuncpkg = color.Style{color.Blue} 35 | ) 36 | 37 | func init() { 38 | formatter := &logFormatter{&logrus.TextFormatter{ 39 | EnvironmentOverrideColors: true, 40 | CallerPrettyfier: func(frame *runtime.Frame) (function string, file string) { 41 | call := strings.TrimPrefix(frame.Function, modulePath) 42 | parts := strings.SplitN(strings.TrimPrefix(call, "/"), ".", 2) 43 | function = fmt.Sprintf("%s.%s()", logstyleFuncpkg.Sprint(parts[0]), logstyleFuncname.Sprint(parts[1])) 44 | _, file = filepath.Split(frame.File) 45 | file = fmt.Sprintf("%s:%s", logstyleFilename.Sprint(file), logstyleFilenum.Sprint(frame.Line)) 46 | return function, file 47 | }, 48 | }} 49 | logrus.SetFormatter(formatter) 50 | } 51 | 52 | type logFormatter struct { 53 | *logrus.TextFormatter 54 | } 55 | 56 | const ( 57 | traceLvlPrefix = "\x1b[37mTRAC" 58 | debugLvlPrefix = "\x1b[37mDEBU" 59 | ) 60 | 61 | func (l *logFormatter) Format(entry *logrus.Entry) ([]byte, error) { 62 | b, err := l.TextFormatter.Format(entry) 63 | if err != nil { 64 | return nil, err 65 | } 66 | //fmt.Printf("LOG: %q\n", string(b)) 67 | if bytes.HasPrefix(b, []byte(traceLvlPrefix)) { 68 | b[2] = '9' 69 | b[3] = '0' 70 | } else if bytes.HasPrefix(b, []byte(debugLvlPrefix)) { 71 | b[2] = '3' 72 | b[3] = '6' 73 | } 74 | return b, nil 75 | } 76 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # GoReleser config 2 | # 3 | # documentation at http://goreleaser.com 4 | --- 5 | version: 2 6 | project_name: govpp 7 | 8 | builds: 9 | - id: govpp-build 10 | main: ./cmd/govpp 11 | binary: govpp 12 | env: 13 | - CGO_ENABLED=0 14 | goos: 15 | - linux 16 | - darwin 17 | goarch: 18 | - amd64 19 | ignore: 20 | - goos: darwin 21 | goarch: "386" 22 | mod_timestamp: '{{ .CommitTimestamp }}' 23 | flags: 24 | - -trimpath 25 | ldflags: 26 | - -s -w 27 | - -X go.fd.io/govpp/version.version=v{{.Version}} 28 | - -X go.fd.io/govpp/version.commit={{.FullCommit}} 29 | - -X go.fd.io/govpp/version.branch={{.Branch}} 30 | - -X go.fd.io/govpp/version.buildStamp={{.Timestamp}} 31 | - -X go.fd.io/govpp/version.buildUser={{if index .Env "USER"}}{{.Env.USER}}{{else}}goreleaser{{end}} 32 | - -X go.fd.io/govpp/version.buildHost={{if index .Env "HOSTNAME"}}{{.Env.HOSTNAME}}{{else}}goreleaser{{end}} 33 | 34 | archives: 35 | - id: govpp-archive 36 | ids: 37 | - govpp-build 38 | formats: [ 'tar.gz' ] 39 | wrap_in_directory: true 40 | files: 41 | - README.md 42 | - docs/* 43 | allow_different_binary_count: true 44 | name_template: "govpp_{{ .Version }}_{{ .Os }}_{{ .Arch }}" 45 | 46 | checksum: 47 | name_template: 'checksums.txt' 48 | 49 | changelog: 50 | sort: asc 51 | filters: 52 | exclude: 53 | - '!^docs:' 54 | - typo 55 | 56 | dockers: 57 | - dockerfile: Dockerfile.govpp 58 | skip_push: auto 59 | image_templates: 60 | - "ghcr.io/fdio/govpp:{{ .Tag }}" 61 | - "{{if not .Prerelease}}ghcr.io/fdio/govpp:v{{ .Major }}.{{ .Minor }}{{end}}" 62 | - "{{if not .Prerelease}}ghcr.io/fdio/govpp:latest{{end}}" 63 | build_flag_templates: 64 | - "--pull" 65 | - "--label=org.opencontainers.image.created={{.Date}}" 66 | - "--label=org.opencontainers.image.name={{.ProjectName}}" 67 | - "--label=org.opencontainers.image.revision={{.FullCommit}}" 68 | - "--label=org.opencontainers.image.version={{.Version}}" 69 | - "--label=org.opencontainers.image.source={{.GitURL}}" 70 | ids: 71 | - govpp-build 72 | 73 | sboms: 74 | - artifacts: archive 75 | 76 | release: 77 | github: 78 | owner: FDio 79 | name: govpp 80 | ids: 81 | - govpp-archive 82 | draft: true 83 | prerelease: auto 84 | name_template: "{{.Tag}}" 85 | -------------------------------------------------------------------------------- /binapi/pipe/pipe_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package pipe 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service pipe. 15 | type RPCService interface { 16 | PipeCreate(ctx context.Context, in *PipeCreate) (*PipeCreateReply, error) 17 | PipeDelete(ctx context.Context, in *PipeDelete) (*PipeDeleteReply, error) 18 | PipeDump(ctx context.Context, in *PipeDump) (RPCService_PipeDumpClient, error) 19 | } 20 | 21 | type serviceClient struct { 22 | conn api.Connection 23 | } 24 | 25 | func NewServiceClient(conn api.Connection) RPCService { 26 | return &serviceClient{conn} 27 | } 28 | 29 | func (c *serviceClient) PipeCreate(ctx context.Context, in *PipeCreate) (*PipeCreateReply, error) { 30 | out := new(PipeCreateReply) 31 | err := c.conn.Invoke(ctx, in, out) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return out, api.RetvalToVPPApiError(out.Retval) 36 | } 37 | 38 | func (c *serviceClient) PipeDelete(ctx context.Context, in *PipeDelete) (*PipeDeleteReply, error) { 39 | out := new(PipeDeleteReply) 40 | err := c.conn.Invoke(ctx, in, out) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return out, api.RetvalToVPPApiError(out.Retval) 45 | } 46 | 47 | func (c *serviceClient) PipeDump(ctx context.Context, in *PipeDump) (RPCService_PipeDumpClient, error) { 48 | stream, err := c.conn.NewStream(ctx) 49 | if err != nil { 50 | return nil, err 51 | } 52 | x := &serviceClient_PipeDumpClient{stream} 53 | if err := x.Stream.SendMsg(in); err != nil { 54 | return nil, err 55 | } 56 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 57 | return nil, err 58 | } 59 | return x, nil 60 | } 61 | 62 | type RPCService_PipeDumpClient interface { 63 | Recv() (*PipeDetails, error) 64 | api.Stream 65 | } 66 | 67 | type serviceClient_PipeDumpClient struct { 68 | api.Stream 69 | } 70 | 71 | func (c *serviceClient_PipeDumpClient) Recv() (*PipeDetails, error) { 72 | msg, err := c.Stream.RecvMsg() 73 | if err != nil { 74 | return nil, err 75 | } 76 | switch m := msg.(type) { 77 | case *PipeDetails: 78 | return m, nil 79 | case *memclnt.ControlPingReply: 80 | err = c.Stream.Close() 81 | if err != nil { 82 | return nil, err 83 | } 84 | return nil, io.EOF 85 | default: 86 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /proxy/proxy.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package proxy 16 | 17 | import ( 18 | "fmt" 19 | "io" 20 | "net" 21 | "net/http" 22 | "net/rpc" 23 | 24 | "go.fd.io/govpp/adapter" 25 | ) 26 | 27 | // Server defines a proxy server that serves client requests to stats and binapi. 28 | type Server struct { 29 | rpc *rpc.Server 30 | 31 | statsRPC *StatsRPC 32 | binapiRPC *BinapiRPC 33 | } 34 | 35 | func NewServer() (*Server, error) { 36 | srv := &Server{ 37 | rpc: rpc.NewServer(), 38 | statsRPC: &StatsRPC{}, 39 | binapiRPC: &BinapiRPC{}, 40 | } 41 | 42 | if err := srv.rpc.Register(srv.statsRPC); err != nil { 43 | return nil, err 44 | } 45 | 46 | if err := srv.rpc.Register(srv.binapiRPC); err != nil { 47 | return nil, err 48 | } 49 | 50 | return srv, nil 51 | } 52 | 53 | func (p *Server) ConnectStats(stats adapter.StatsAPI) error { 54 | return p.statsRPC.connect(stats) 55 | } 56 | 57 | func (p *Server) DisconnectStats() { 58 | p.statsRPC.disconnect() 59 | } 60 | 61 | func (p *Server) ConnectBinapi(binapi adapter.VppAPI) error { 62 | return p.binapiRPC.connect(binapi) 63 | } 64 | 65 | func (p *Server) DisconnectBinapi() { 66 | p.binapiRPC.disconnect() 67 | } 68 | 69 | func (p *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { 70 | p.rpc.ServeHTTP(w, req) 71 | } 72 | 73 | func (p *Server) ServeCodec(codec rpc.ServerCodec) { 74 | p.rpc.ServeCodec(codec) 75 | } 76 | 77 | func (p *Server) ServeConn(conn io.ReadWriteCloser) { 78 | p.rpc.ServeConn(conn) 79 | } 80 | 81 | func (p *Server) ListenAndServe(addr string) error { 82 | p.rpc.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath) 83 | 84 | l, e := net.Listen("tcp", addr) 85 | if e != nil { 86 | return fmt.Errorf("listen failed: %v", e) 87 | } 88 | defer l.Close() 89 | 90 | log.Printf("proxy serving on: %v", addr) 91 | 92 | return http.Serve(l, nil) 93 | } 94 | -------------------------------------------------------------------------------- /binapi/vpe/vpe_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package vpe 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service vpe. 15 | type RPCService interface { 16 | LogDump(ctx context.Context, in *LogDump) (RPCService_LogDumpClient, error) 17 | ShowVersion(ctx context.Context, in *ShowVersion) (*ShowVersionReply, error) 18 | ShowVpeSystemTime(ctx context.Context, in *ShowVpeSystemTime) (*ShowVpeSystemTimeReply, error) 19 | } 20 | 21 | type serviceClient struct { 22 | conn api.Connection 23 | } 24 | 25 | func NewServiceClient(conn api.Connection) RPCService { 26 | return &serviceClient{conn} 27 | } 28 | 29 | func (c *serviceClient) LogDump(ctx context.Context, in *LogDump) (RPCService_LogDumpClient, error) { 30 | stream, err := c.conn.NewStream(ctx) 31 | if err != nil { 32 | return nil, err 33 | } 34 | x := &serviceClient_LogDumpClient{stream} 35 | if err := x.Stream.SendMsg(in); err != nil { 36 | return nil, err 37 | } 38 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 39 | return nil, err 40 | } 41 | return x, nil 42 | } 43 | 44 | type RPCService_LogDumpClient interface { 45 | Recv() (*LogDetails, error) 46 | api.Stream 47 | } 48 | 49 | type serviceClient_LogDumpClient struct { 50 | api.Stream 51 | } 52 | 53 | func (c *serviceClient_LogDumpClient) Recv() (*LogDetails, error) { 54 | msg, err := c.Stream.RecvMsg() 55 | if err != nil { 56 | return nil, err 57 | } 58 | switch m := msg.(type) { 59 | case *LogDetails: 60 | return m, nil 61 | case *memclnt.ControlPingReply: 62 | err = c.Stream.Close() 63 | if err != nil { 64 | return nil, err 65 | } 66 | return nil, io.EOF 67 | default: 68 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 69 | } 70 | } 71 | 72 | func (c *serviceClient) ShowVersion(ctx context.Context, in *ShowVersion) (*ShowVersionReply, error) { 73 | out := new(ShowVersionReply) 74 | err := c.conn.Invoke(ctx, in, out) 75 | if err != nil { 76 | return nil, err 77 | } 78 | return out, api.RetvalToVPPApiError(out.Retval) 79 | } 80 | 81 | func (c *serviceClient) ShowVpeSystemTime(ctx context.Context, in *ShowVpeSystemTime) (*ShowVpeSystemTimeReply, error) { 82 | out := new(ShowVpeSystemTimeReply) 83 | err := c.conn.Invoke(ctx, in, out) 84 | if err != nil { 85 | return nil, err 86 | } 87 | return out, api.RetvalToVPPApiError(out.Retval) 88 | } 89 | -------------------------------------------------------------------------------- /binapi/lldp/lldp_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package lldp 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | ) 12 | 13 | // RPCService defines RPC service lldp. 14 | type RPCService interface { 15 | LldpConfig(ctx context.Context, in *LldpConfig) (*LldpConfigReply, error) 16 | LldpDump(ctx context.Context, in *LldpDump) (RPCService_LldpDumpClient, error) 17 | SwInterfaceSetLldp(ctx context.Context, in *SwInterfaceSetLldp) (*SwInterfaceSetLldpReply, error) 18 | } 19 | 20 | type serviceClient struct { 21 | conn api.Connection 22 | } 23 | 24 | func NewServiceClient(conn api.Connection) RPCService { 25 | return &serviceClient{conn} 26 | } 27 | 28 | func (c *serviceClient) LldpConfig(ctx context.Context, in *LldpConfig) (*LldpConfigReply, error) { 29 | out := new(LldpConfigReply) 30 | err := c.conn.Invoke(ctx, in, out) 31 | if err != nil { 32 | return nil, err 33 | } 34 | return out, api.RetvalToVPPApiError(out.Retval) 35 | } 36 | 37 | func (c *serviceClient) LldpDump(ctx context.Context, in *LldpDump) (RPCService_LldpDumpClient, error) { 38 | stream, err := c.conn.NewStream(ctx) 39 | if err != nil { 40 | return nil, err 41 | } 42 | x := &serviceClient_LldpDumpClient{stream} 43 | if err := x.Stream.SendMsg(in); err != nil { 44 | return nil, err 45 | } 46 | return x, nil 47 | } 48 | 49 | type RPCService_LldpDumpClient interface { 50 | Recv() (*LldpDetails, *LldpDumpReply, error) 51 | api.Stream 52 | } 53 | 54 | type serviceClient_LldpDumpClient struct { 55 | api.Stream 56 | } 57 | 58 | func (c *serviceClient_LldpDumpClient) Recv() (*LldpDetails, *LldpDumpReply, error) { 59 | msg, err := c.Stream.RecvMsg() 60 | if err != nil { 61 | return nil, nil, err 62 | } 63 | switch m := msg.(type) { 64 | case *LldpDetails: 65 | return m, nil, nil 66 | case *LldpDumpReply: 67 | if err := api.RetvalToVPPApiError(m.Retval); err != nil { 68 | c.Stream.Close() 69 | return nil, m, err 70 | } 71 | err = c.Stream.Close() 72 | if err != nil { 73 | return nil, m, err 74 | } 75 | return nil, m, io.EOF 76 | default: 77 | return nil, nil, fmt.Errorf("unexpected message: %T %v", m, m) 78 | } 79 | } 80 | 81 | func (c *serviceClient) SwInterfaceSetLldp(ctx context.Context, in *SwInterfaceSetLldp) (*SwInterfaceSetLldpReply, error) { 82 | out := new(SwInterfaceSetLldpReply) 83 | err := c.conn.Invoke(ctx, in, out) 84 | if err != nil { 85 | return nil, err 86 | } 87 | return out, api.RetvalToVPPApiError(out.Retval) 88 | } 89 | -------------------------------------------------------------------------------- /binapi/sr_pt/sr_pt_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package sr_pt 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service sr_pt. 15 | type RPCService interface { 16 | SrPtIfaceAdd(ctx context.Context, in *SrPtIfaceAdd) (*SrPtIfaceAddReply, error) 17 | SrPtIfaceDel(ctx context.Context, in *SrPtIfaceDel) (*SrPtIfaceDelReply, error) 18 | SrPtIfaceDump(ctx context.Context, in *SrPtIfaceDump) (RPCService_SrPtIfaceDumpClient, error) 19 | } 20 | 21 | type serviceClient struct { 22 | conn api.Connection 23 | } 24 | 25 | func NewServiceClient(conn api.Connection) RPCService { 26 | return &serviceClient{conn} 27 | } 28 | 29 | func (c *serviceClient) SrPtIfaceAdd(ctx context.Context, in *SrPtIfaceAdd) (*SrPtIfaceAddReply, error) { 30 | out := new(SrPtIfaceAddReply) 31 | err := c.conn.Invoke(ctx, in, out) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return out, api.RetvalToVPPApiError(out.Retval) 36 | } 37 | 38 | func (c *serviceClient) SrPtIfaceDel(ctx context.Context, in *SrPtIfaceDel) (*SrPtIfaceDelReply, error) { 39 | out := new(SrPtIfaceDelReply) 40 | err := c.conn.Invoke(ctx, in, out) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return out, api.RetvalToVPPApiError(out.Retval) 45 | } 46 | 47 | func (c *serviceClient) SrPtIfaceDump(ctx context.Context, in *SrPtIfaceDump) (RPCService_SrPtIfaceDumpClient, error) { 48 | stream, err := c.conn.NewStream(ctx) 49 | if err != nil { 50 | return nil, err 51 | } 52 | x := &serviceClient_SrPtIfaceDumpClient{stream} 53 | if err := x.Stream.SendMsg(in); err != nil { 54 | return nil, err 55 | } 56 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 57 | return nil, err 58 | } 59 | return x, nil 60 | } 61 | 62 | type RPCService_SrPtIfaceDumpClient interface { 63 | Recv() (*SrPtIfaceDetails, error) 64 | api.Stream 65 | } 66 | 67 | type serviceClient_SrPtIfaceDumpClient struct { 68 | api.Stream 69 | } 70 | 71 | func (c *serviceClient_SrPtIfaceDumpClient) Recv() (*SrPtIfaceDetails, error) { 72 | msg, err := c.Stream.RecvMsg() 73 | if err != nil { 74 | return nil, err 75 | } 76 | switch m := msg.(type) { 77 | case *SrPtIfaceDetails: 78 | return m, nil 79 | case *memclnt.ControlPingReply: 80 | err = c.Stream.Close() 81 | if err != nil { 82 | return nil, err 83 | } 84 | return nil, io.EOF 85 | default: 86 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /binapi/urpf/urpf_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package urpf 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service urpf. 15 | type RPCService interface { 16 | UrpfInterfaceDump(ctx context.Context, in *UrpfInterfaceDump) (RPCService_UrpfInterfaceDumpClient, error) 17 | UrpfUpdate(ctx context.Context, in *UrpfUpdate) (*UrpfUpdateReply, error) 18 | UrpfUpdateV2(ctx context.Context, in *UrpfUpdateV2) (*UrpfUpdateV2Reply, error) 19 | } 20 | 21 | type serviceClient struct { 22 | conn api.Connection 23 | } 24 | 25 | func NewServiceClient(conn api.Connection) RPCService { 26 | return &serviceClient{conn} 27 | } 28 | 29 | func (c *serviceClient) UrpfInterfaceDump(ctx context.Context, in *UrpfInterfaceDump) (RPCService_UrpfInterfaceDumpClient, error) { 30 | stream, err := c.conn.NewStream(ctx) 31 | if err != nil { 32 | return nil, err 33 | } 34 | x := &serviceClient_UrpfInterfaceDumpClient{stream} 35 | if err := x.Stream.SendMsg(in); err != nil { 36 | return nil, err 37 | } 38 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 39 | return nil, err 40 | } 41 | return x, nil 42 | } 43 | 44 | type RPCService_UrpfInterfaceDumpClient interface { 45 | Recv() (*UrpfInterfaceDetails, error) 46 | api.Stream 47 | } 48 | 49 | type serviceClient_UrpfInterfaceDumpClient struct { 50 | api.Stream 51 | } 52 | 53 | func (c *serviceClient_UrpfInterfaceDumpClient) Recv() (*UrpfInterfaceDetails, error) { 54 | msg, err := c.Stream.RecvMsg() 55 | if err != nil { 56 | return nil, err 57 | } 58 | switch m := msg.(type) { 59 | case *UrpfInterfaceDetails: 60 | return m, nil 61 | case *memclnt.ControlPingReply: 62 | err = c.Stream.Close() 63 | if err != nil { 64 | return nil, err 65 | } 66 | return nil, io.EOF 67 | default: 68 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 69 | } 70 | } 71 | 72 | func (c *serviceClient) UrpfUpdate(ctx context.Context, in *UrpfUpdate) (*UrpfUpdateReply, error) { 73 | out := new(UrpfUpdateReply) 74 | err := c.conn.Invoke(ctx, in, out) 75 | if err != nil { 76 | return nil, err 77 | } 78 | return out, api.RetvalToVPPApiError(out.Retval) 79 | } 80 | 81 | func (c *serviceClient) UrpfUpdateV2(ctx context.Context, in *UrpfUpdateV2) (*UrpfUpdateV2Reply, error) { 82 | out := new(UrpfUpdateV2Reply) 83 | err := c.conn.Invoke(ctx, in, out) 84 | if err != nil { 85 | return nil, err 86 | } 87 | return out, api.RetvalToVPPApiError(out.Retval) 88 | } 89 | -------------------------------------------------------------------------------- /binapi/sr_mpls/sr_mpls_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package sr_mpls 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service sr_mpls. 12 | type RPCService interface { 13 | SrMplsPolicyAdd(ctx context.Context, in *SrMplsPolicyAdd) (*SrMplsPolicyAddReply, error) 14 | SrMplsPolicyAssignEndpointColor(ctx context.Context, in *SrMplsPolicyAssignEndpointColor) (*SrMplsPolicyAssignEndpointColorReply, error) 15 | SrMplsPolicyDel(ctx context.Context, in *SrMplsPolicyDel) (*SrMplsPolicyDelReply, error) 16 | SrMplsPolicyMod(ctx context.Context, in *SrMplsPolicyMod) (*SrMplsPolicyModReply, error) 17 | SrMplsSteeringAddDel(ctx context.Context, in *SrMplsSteeringAddDel) (*SrMplsSteeringAddDelReply, error) 18 | } 19 | 20 | type serviceClient struct { 21 | conn api.Connection 22 | } 23 | 24 | func NewServiceClient(conn api.Connection) RPCService { 25 | return &serviceClient{conn} 26 | } 27 | 28 | func (c *serviceClient) SrMplsPolicyAdd(ctx context.Context, in *SrMplsPolicyAdd) (*SrMplsPolicyAddReply, error) { 29 | out := new(SrMplsPolicyAddReply) 30 | err := c.conn.Invoke(ctx, in, out) 31 | if err != nil { 32 | return nil, err 33 | } 34 | return out, api.RetvalToVPPApiError(out.Retval) 35 | } 36 | 37 | func (c *serviceClient) SrMplsPolicyAssignEndpointColor(ctx context.Context, in *SrMplsPolicyAssignEndpointColor) (*SrMplsPolicyAssignEndpointColorReply, error) { 38 | out := new(SrMplsPolicyAssignEndpointColorReply) 39 | err := c.conn.Invoke(ctx, in, out) 40 | if err != nil { 41 | return nil, err 42 | } 43 | return out, api.RetvalToVPPApiError(out.Retval) 44 | } 45 | 46 | func (c *serviceClient) SrMplsPolicyDel(ctx context.Context, in *SrMplsPolicyDel) (*SrMplsPolicyDelReply, error) { 47 | out := new(SrMplsPolicyDelReply) 48 | err := c.conn.Invoke(ctx, in, out) 49 | if err != nil { 50 | return nil, err 51 | } 52 | return out, api.RetvalToVPPApiError(out.Retval) 53 | } 54 | 55 | func (c *serviceClient) SrMplsPolicyMod(ctx context.Context, in *SrMplsPolicyMod) (*SrMplsPolicyModReply, error) { 56 | out := new(SrMplsPolicyModReply) 57 | err := c.conn.Invoke(ctx, in, out) 58 | if err != nil { 59 | return nil, err 60 | } 61 | return out, api.RetvalToVPPApiError(out.Retval) 62 | } 63 | 64 | func (c *serviceClient) SrMplsSteeringAddDel(ctx context.Context, in *SrMplsSteeringAddDel) (*SrMplsSteeringAddDelReply, error) { 65 | out := new(SrMplsSteeringAddDelReply) 66 | err := c.conn.Invoke(ctx, in, out) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return out, api.RetvalToVPPApiError(out.Retval) 71 | } 72 | -------------------------------------------------------------------------------- /binapi/mactime/mactime_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package mactime 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service mactime. 15 | type RPCService interface { 16 | MactimeAddDelRange(ctx context.Context, in *MactimeAddDelRange) (*MactimeAddDelRangeReply, error) 17 | MactimeDump(ctx context.Context, in *MactimeDump) (RPCService_MactimeDumpClient, error) 18 | MactimeEnableDisable(ctx context.Context, in *MactimeEnableDisable) (*MactimeEnableDisableReply, error) 19 | } 20 | 21 | type serviceClient struct { 22 | conn api.Connection 23 | } 24 | 25 | func NewServiceClient(conn api.Connection) RPCService { 26 | return &serviceClient{conn} 27 | } 28 | 29 | func (c *serviceClient) MactimeAddDelRange(ctx context.Context, in *MactimeAddDelRange) (*MactimeAddDelRangeReply, error) { 30 | out := new(MactimeAddDelRangeReply) 31 | err := c.conn.Invoke(ctx, in, out) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return out, api.RetvalToVPPApiError(out.Retval) 36 | } 37 | 38 | func (c *serviceClient) MactimeDump(ctx context.Context, in *MactimeDump) (RPCService_MactimeDumpClient, error) { 39 | stream, err := c.conn.NewStream(ctx) 40 | if err != nil { 41 | return nil, err 42 | } 43 | x := &serviceClient_MactimeDumpClient{stream} 44 | if err := x.Stream.SendMsg(in); err != nil { 45 | return nil, err 46 | } 47 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 48 | return nil, err 49 | } 50 | return x, nil 51 | } 52 | 53 | type RPCService_MactimeDumpClient interface { 54 | Recv() (*MactimeDetails, error) 55 | api.Stream 56 | } 57 | 58 | type serviceClient_MactimeDumpClient struct { 59 | api.Stream 60 | } 61 | 62 | func (c *serviceClient_MactimeDumpClient) Recv() (*MactimeDetails, error) { 63 | msg, err := c.Stream.RecvMsg() 64 | if err != nil { 65 | return nil, err 66 | } 67 | switch m := msg.(type) { 68 | case *MactimeDetails: 69 | return m, nil 70 | case *memclnt.ControlPingReply: 71 | err = c.Stream.Close() 72 | if err != nil { 73 | return nil, err 74 | } 75 | return nil, io.EOF 76 | default: 77 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 78 | } 79 | } 80 | 81 | func (c *serviceClient) MactimeEnableDisable(ctx context.Context, in *MactimeEnableDisable) (*MactimeEnableDisableReply, error) { 82 | out := new(MactimeEnableDisableReply) 83 | err := c.conn.Invoke(ctx, in, out) 84 | if err != nil { 85 | return nil, err 86 | } 87 | return out, api.RetvalToVPPApiError(out.Retval) 88 | } 89 | -------------------------------------------------------------------------------- /extras/gomemif/memif/memif_unsafe.go: -------------------------------------------------------------------------------- 1 | /* 2 | *------------------------------------------------------------------ 3 | * Copyright (c) 2020 Cisco and/or its affiliates. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *------------------------------------------------------------------ 16 | */ 17 | 18 | package memif 19 | 20 | import ( 21 | "unsafe" 22 | ) 23 | 24 | // readHead reads ring head directly form the shared memory 25 | func (q *Queue) readHead() (head int) { 26 | return (int)(*(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringHeadOffset]))) 27 | // return atomicload16(&q.i.regions[q.region].data[q.offset + descHeadOffset]) 28 | } 29 | 30 | // readTail reads ring tail directly form the shared memory 31 | func (q *Queue) readTail() (tail int) { 32 | return (int)(*(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringTailOffset]))) 33 | // return atomicload16(&q.i.regions[q.region].data[q.offset + descTailOffset]) 34 | } 35 | 36 | // writeHead writes ring head directly to the shared memory 37 | func (q *Queue) writeHead(value int) { 38 | *(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringHeadOffset])) = *(*uint16)(unsafe.Pointer(&value)) 39 | //atomicstore16(&q.i.regions[q.region].data[q.offset + descHeadOffset], value) 40 | } 41 | 42 | // writeTail writes ring tail directly to the shared memory 43 | func (q *Queue) writeTail(value int) { 44 | *(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringTailOffset])) = *(*uint16)(unsafe.Pointer(&value)) 45 | //atomicstore16(&q.i.regions[q.region].data[q.offset + descTailOffset], value) 46 | } 47 | 48 | func (q *Queue) setDescLength(slot int, length int) { 49 | *(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringSize+slot*descSize+descLengthOffset])) = *(*uint16)(unsafe.Pointer(&length)) 50 | } 51 | 52 | // getFlags reads ring flags directly from the shared memory 53 | func (q *Queue) getFlags() int { 54 | return (int)(*(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringFlagsOffset]))) 55 | } 56 | -------------------------------------------------------------------------------- /binapi/pppoe/pppoe_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package pppoe 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service pppoe. 15 | type RPCService interface { 16 | PppoeAddDelCp(ctx context.Context, in *PppoeAddDelCp) (*PppoeAddDelCpReply, error) 17 | PppoeAddDelSession(ctx context.Context, in *PppoeAddDelSession) (*PppoeAddDelSessionReply, error) 18 | PppoeSessionDump(ctx context.Context, in *PppoeSessionDump) (RPCService_PppoeSessionDumpClient, error) 19 | } 20 | 21 | type serviceClient struct { 22 | conn api.Connection 23 | } 24 | 25 | func NewServiceClient(conn api.Connection) RPCService { 26 | return &serviceClient{conn} 27 | } 28 | 29 | func (c *serviceClient) PppoeAddDelCp(ctx context.Context, in *PppoeAddDelCp) (*PppoeAddDelCpReply, error) { 30 | out := new(PppoeAddDelCpReply) 31 | err := c.conn.Invoke(ctx, in, out) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return out, api.RetvalToVPPApiError(out.Retval) 36 | } 37 | 38 | func (c *serviceClient) PppoeAddDelSession(ctx context.Context, in *PppoeAddDelSession) (*PppoeAddDelSessionReply, error) { 39 | out := new(PppoeAddDelSessionReply) 40 | err := c.conn.Invoke(ctx, in, out) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return out, api.RetvalToVPPApiError(out.Retval) 45 | } 46 | 47 | func (c *serviceClient) PppoeSessionDump(ctx context.Context, in *PppoeSessionDump) (RPCService_PppoeSessionDumpClient, error) { 48 | stream, err := c.conn.NewStream(ctx) 49 | if err != nil { 50 | return nil, err 51 | } 52 | x := &serviceClient_PppoeSessionDumpClient{stream} 53 | if err := x.Stream.SendMsg(in); err != nil { 54 | return nil, err 55 | } 56 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 57 | return nil, err 58 | } 59 | return x, nil 60 | } 61 | 62 | type RPCService_PppoeSessionDumpClient interface { 63 | Recv() (*PppoeSessionDetails, error) 64 | api.Stream 65 | } 66 | 67 | type serviceClient_PppoeSessionDumpClient struct { 68 | api.Stream 69 | } 70 | 71 | func (c *serviceClient_PppoeSessionDumpClient) Recv() (*PppoeSessionDetails, error) { 72 | msg, err := c.Stream.RecvMsg() 73 | if err != nil { 74 | return nil, err 75 | } 76 | switch m := msg.(type) { 77 | case *PppoeSessionDetails: 78 | return m, nil 79 | case *memclnt.ControlPingReply: 80 | err = c.Stream.Close() 81 | if err != nil { 82 | return nil, err 83 | } 84 | return nil, io.EOF 85 | default: 86 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /cmd/govpp/options.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "os" 19 | "strings" 20 | 21 | "github.com/gookit/color" 22 | "github.com/sirupsen/logrus" 23 | "github.com/spf13/pflag" 24 | ) 25 | 26 | const ( 27 | defaultLogLevel = logrus.InfoLevel 28 | ) 29 | 30 | type GlobalOptions struct { 31 | Debug bool 32 | LogLevel string 33 | Color string 34 | } 35 | 36 | func (glob *GlobalOptions) InstallFlags(flags *pflag.FlagSet) { 37 | flags.BoolVarP(&glob.Debug, "debug", "D", false, "Enable debug mode") 38 | flags.StringVarP(&glob.LogLevel, "log-level", "L", "", "Set the logging level [trace/debug/info/warn/error]") 39 | flags.StringVar(&glob.Color, "color", "", "Set color mode [auto/always/never]") 40 | } 41 | 42 | func InitOptions(cli Cli, opts *GlobalOptions) { 43 | // override 44 | if opts.Color == "" && os.Getenv("NO_COLOR") != "" { 45 | // https://no-color.org/ 46 | opts.Color = "never" 47 | } 48 | if os.Getenv("DEBUG_GOVPP") != "" || os.Getenv("GOVPP_DEBUG") != "" { 49 | opts.Debug = true 50 | } 51 | if loglvl := os.Getenv("GOVPP_LOGLEVEL"); loglvl != "" { 52 | opts.LogLevel = loglvl 53 | } 54 | 55 | switch strings.ToLower(opts.Color) { 56 | case "auto", "": 57 | if !cli.Out().IsTerminal() { 58 | color.Disable() 59 | } 60 | case "on", "enabled", "always", "1", "true": 61 | color.Enable = true 62 | case "off", "disabled", "never", "0", "false": 63 | color.Disable() 64 | default: 65 | logrus.Fatalf("invalid color mode: %q", opts.Color) 66 | } 67 | 68 | if opts.LogLevel != "" { 69 | if lvl, err := logrus.ParseLevel(opts.LogLevel); err == nil { 70 | logrus.SetLevel(lvl) 71 | if lvl >= logrus.TraceLevel { 72 | logrus.SetReportCaller(true) 73 | } 74 | logrus.Tracef("log level set to: %v", lvl) 75 | } else { 76 | logrus.Fatalf("invalid log level: %v", err) 77 | } 78 | } else if opts.Debug { 79 | logrus.SetLevel(logrus.DebugLevel) 80 | } else { 81 | logrus.SetLevel(defaultLogLevel) 82 | } 83 | 84 | logrus.Tracef("init global options: %+v", opts) 85 | } 86 | -------------------------------------------------------------------------------- /binapi/pvti/pvti_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package pvti 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service pvti. 15 | type RPCService interface { 16 | PvtiInterfaceCreate(ctx context.Context, in *PvtiInterfaceCreate) (*PvtiInterfaceCreateReply, error) 17 | PvtiInterfaceDelete(ctx context.Context, in *PvtiInterfaceDelete) (*PvtiInterfaceDeleteReply, error) 18 | PvtiInterfaceDump(ctx context.Context, in *PvtiInterfaceDump) (RPCService_PvtiInterfaceDumpClient, error) 19 | } 20 | 21 | type serviceClient struct { 22 | conn api.Connection 23 | } 24 | 25 | func NewServiceClient(conn api.Connection) RPCService { 26 | return &serviceClient{conn} 27 | } 28 | 29 | func (c *serviceClient) PvtiInterfaceCreate(ctx context.Context, in *PvtiInterfaceCreate) (*PvtiInterfaceCreateReply, error) { 30 | out := new(PvtiInterfaceCreateReply) 31 | err := c.conn.Invoke(ctx, in, out) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return out, api.RetvalToVPPApiError(out.Retval) 36 | } 37 | 38 | func (c *serviceClient) PvtiInterfaceDelete(ctx context.Context, in *PvtiInterfaceDelete) (*PvtiInterfaceDeleteReply, error) { 39 | out := new(PvtiInterfaceDeleteReply) 40 | err := c.conn.Invoke(ctx, in, out) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return out, api.RetvalToVPPApiError(out.Retval) 45 | } 46 | 47 | func (c *serviceClient) PvtiInterfaceDump(ctx context.Context, in *PvtiInterfaceDump) (RPCService_PvtiInterfaceDumpClient, error) { 48 | stream, err := c.conn.NewStream(ctx) 49 | if err != nil { 50 | return nil, err 51 | } 52 | x := &serviceClient_PvtiInterfaceDumpClient{stream} 53 | if err := x.Stream.SendMsg(in); err != nil { 54 | return nil, err 55 | } 56 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 57 | return nil, err 58 | } 59 | return x, nil 60 | } 61 | 62 | type RPCService_PvtiInterfaceDumpClient interface { 63 | Recv() (*PvtiInterfaceDetails, error) 64 | api.Stream 65 | } 66 | 67 | type serviceClient_PvtiInterfaceDumpClient struct { 68 | api.Stream 69 | } 70 | 71 | func (c *serviceClient_PvtiInterfaceDumpClient) Recv() (*PvtiInterfaceDetails, error) { 72 | msg, err := c.Stream.RecvMsg() 73 | if err != nil { 74 | return nil, err 75 | } 76 | switch m := msg.(type) { 77 | case *PvtiInterfaceDetails: 78 | return m, nil 79 | case *memclnt.ControlPingReply: 80 | err = c.Stream.Close() 81 | if err != nil { 82 | return nil, err 83 | } 84 | return nil, io.EOF 85 | default: 86 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /adapter/mock/mock_stats_adapter.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package mock is an alternative VPP stats adapter aimed for unit/integration testing where the 16 | // actual communication with VPP is not demanded. 17 | 18 | package mock 19 | 20 | import ( 21 | "go.fd.io/govpp/adapter" 22 | ) 23 | 24 | // implements StatsAPI 25 | var _ adapter.StatsAPI = (*StatsAdapter)(nil) 26 | 27 | // StatsAdapter simulates VPP stats socket from which stats can be read 28 | type StatsAdapter struct { 29 | entries []adapter.StatEntry 30 | dir *adapter.StatDir 31 | } 32 | 33 | // NewStatsAdapter returns a new mock stats adapter. 34 | func NewStatsAdapter() *StatsAdapter { 35 | return &StatsAdapter{} 36 | } 37 | 38 | // Connect mocks client connection to the stats API. 39 | func (a *StatsAdapter) Connect() error { 40 | return nil 41 | } 42 | 43 | // Disconnect mocks client connection termination. 44 | func (a *StatsAdapter) Disconnect() error { 45 | return nil 46 | } 47 | 48 | // ListStats mocks name listing for all stats. 49 | func (a *StatsAdapter) ListStats(patterns ...string) ([]adapter.StatIdentifier, error) { 50 | var statNames []adapter.StatIdentifier 51 | for _, stat := range a.entries { 52 | statNames = append(statNames, adapter.StatIdentifier{ 53 | Name: stat.Name, 54 | Index: stat.Index, 55 | }) 56 | } 57 | return statNames, nil 58 | } 59 | 60 | // DumpStats mocks all stat entries dump. 61 | func (a *StatsAdapter) DumpStats(patterns ...string) ([]adapter.StatEntry, error) { 62 | return a.entries, nil 63 | } 64 | 65 | func (a *StatsAdapter) PrepareDir(prefixes ...string) (*adapter.StatDir, error) { 66 | return a.dir, nil 67 | } 68 | 69 | func (a *StatsAdapter) PrepareDirOnIndex(indexes ...uint32) (*adapter.StatDir, error) { 70 | return a.dir, nil 71 | } 72 | 73 | func (a *StatsAdapter) UpdateDir(dir *adapter.StatDir) error { 74 | *dir = *a.dir 75 | return nil 76 | } 77 | 78 | // MockStats sets mocked stat entries to be returned by DumpStats. 79 | func (a *StatsAdapter) MockStats(stats []adapter.StatEntry) { 80 | a.entries = stats 81 | } 82 | 83 | // MockStats sets mocked stat dir to be returned by PrepareDir. 84 | func (a *StatsAdapter) MockDir(dir *adapter.StatDir) { 85 | a.dir = dir 86 | } 87 | -------------------------------------------------------------------------------- /binapi/l3xc/l3xc_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package l3xc 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service l3xc. 15 | type RPCService interface { 16 | L3xcDel(ctx context.Context, in *L3xcDel) (*L3xcDelReply, error) 17 | L3xcDump(ctx context.Context, in *L3xcDump) (RPCService_L3xcDumpClient, error) 18 | L3xcPluginGetVersion(ctx context.Context, in *L3xcPluginGetVersion) (*L3xcPluginGetVersionReply, error) 19 | L3xcUpdate(ctx context.Context, in *L3xcUpdate) (*L3xcUpdateReply, error) 20 | } 21 | 22 | type serviceClient struct { 23 | conn api.Connection 24 | } 25 | 26 | func NewServiceClient(conn api.Connection) RPCService { 27 | return &serviceClient{conn} 28 | } 29 | 30 | func (c *serviceClient) L3xcDel(ctx context.Context, in *L3xcDel) (*L3xcDelReply, error) { 31 | out := new(L3xcDelReply) 32 | err := c.conn.Invoke(ctx, in, out) 33 | if err != nil { 34 | return nil, err 35 | } 36 | return out, api.RetvalToVPPApiError(out.Retval) 37 | } 38 | 39 | func (c *serviceClient) L3xcDump(ctx context.Context, in *L3xcDump) (RPCService_L3xcDumpClient, error) { 40 | stream, err := c.conn.NewStream(ctx) 41 | if err != nil { 42 | return nil, err 43 | } 44 | x := &serviceClient_L3xcDumpClient{stream} 45 | if err := x.Stream.SendMsg(in); err != nil { 46 | return nil, err 47 | } 48 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 49 | return nil, err 50 | } 51 | return x, nil 52 | } 53 | 54 | type RPCService_L3xcDumpClient interface { 55 | Recv() (*L3xcDetails, error) 56 | api.Stream 57 | } 58 | 59 | type serviceClient_L3xcDumpClient struct { 60 | api.Stream 61 | } 62 | 63 | func (c *serviceClient_L3xcDumpClient) Recv() (*L3xcDetails, error) { 64 | msg, err := c.Stream.RecvMsg() 65 | if err != nil { 66 | return nil, err 67 | } 68 | switch m := msg.(type) { 69 | case *L3xcDetails: 70 | return m, nil 71 | case *memclnt.ControlPingReply: 72 | err = c.Stream.Close() 73 | if err != nil { 74 | return nil, err 75 | } 76 | return nil, io.EOF 77 | default: 78 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 79 | } 80 | } 81 | 82 | func (c *serviceClient) L3xcPluginGetVersion(ctx context.Context, in *L3xcPluginGetVersion) (*L3xcPluginGetVersionReply, error) { 83 | out := new(L3xcPluginGetVersionReply) 84 | err := c.conn.Invoke(ctx, in, out) 85 | if err != nil { 86 | return nil, err 87 | } 88 | return out, nil 89 | } 90 | 91 | func (c *serviceClient) L3xcUpdate(ctx context.Context, in *L3xcUpdate) (*L3xcUpdateReply, error) { 92 | out := new(L3xcUpdateReply) 93 | err := c.conn.Invoke(ctx, in, out) 94 | if err != nil { 95 | return nil, err 96 | } 97 | return out, api.RetvalToVPPApiError(out.Retval) 98 | } 99 | -------------------------------------------------------------------------------- /extras/test/run_integration.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # // Copyright (c) 2022 Cisco and/or its affiliates. 3 | # // 4 | # // Licensed under the Apache License, Version 2.0 (the "License"); 5 | # // you may not use this file except in compliance with the License. 6 | # // You may obtain a copy of the License at: 7 | # // 8 | # // http://www.apache.org/licenses/LICENSE-2.0 9 | # // 10 | # // Unless required by applicable law or agreed to in writing, software 11 | # // distributed under the License is distributed on an "AS IS" BASIS, 12 | # // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # // See the License for the specific language governing permissions and 14 | # // limitations under the License. 15 | 16 | set -euo pipefail 17 | 18 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P )" 19 | 20 | args=($*) 21 | 22 | echo "Preparing extras tests.." 23 | 24 | VPP_REPO=${VPP_REPO:-master} 25 | 26 | export CGO_ENABLED=0 27 | export DOCKER_BUILDKIT=1 28 | export GOTESTSUM_FORMAT="${GOTESTSUM_FORMAT:-testname}" 29 | 30 | imgtag="govpp-extras-integration" 31 | 32 | go test -c -o test/extras.test \ 33 | -tags 'osusergo netgo e2e' \ 34 | -ldflags '-w -s -extldflags "-static"' \ 35 | -trimpath \ 36 | "${SCRIPT_DIR}/memif" 37 | 38 | docker build --tag "${imgtag}" \ 39 | -f "${SCRIPT_DIR}"/build/Dockerfile.extras \ 40 | --build-arg VPP_REPO="${VPP_REPO}" \ 41 | "${SCRIPT_DIR}"/build 42 | 43 | vppver=$(docker run --rm -i "${imgtag}" dpkg-query -f '${Version}' -W vpp) 44 | 45 | if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then 46 | echo "**VPP version**: \`${vppver}\`" >> $GITHUB_STEP_SUMMARY 47 | echo "" >> $GITHUB_STEP_SUMMARY 48 | fi 49 | 50 | echo "==========================================================================" 51 | echo " GOVPP EXTRAS INTEGRATION TEST - $(date) " 52 | echo "==========================================================================" 53 | echo "- VPP_REPO: $VPP_REPO" 54 | echo "- VPP version: $vppver" 55 | echo "--------------------------------------------------------------------------" 56 | 57 | if docker run -i --privileged \ 58 | -e CGO_ENABLED=0 \ 59 | -e DEBUG_GOVPP \ 60 | -e GOTESTSUM_FORMAT \ 61 | -e CLICOLOR_FORCE \ 62 | -v "$(cd "${SCRIPT_DIR}/.." && pwd)":/src \ 63 | -w /src \ 64 | "${imgtag}" gotestsum --raw-command -- go tool test2json -t -p extras ./test/extras.test -test.v ${args[@]:-} 65 | then 66 | echo >&2 "-------------------------------------------------------------" 67 | echo >&2 -e " \e[32mPASSED\e[0m (took: ${SECONDS}s)" 68 | echo >&2 "-------------------------------------------------------------" 69 | exit 0 70 | else 71 | res=$? 72 | echo >&2 "-------------------------------------------------------------" 73 | echo >&2 -e " \e[31mFAILED!\e[0m (exit code: $res)" 74 | echo >&2 "-------------------------------------------------------------" 75 | exit $res 76 | fi 77 | -------------------------------------------------------------------------------- /binapi/udp/udp_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package udp 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service udp. 15 | type RPCService interface { 16 | UDPDecapAddDel(ctx context.Context, in *UDPDecapAddDel) (*UDPDecapAddDelReply, error) 17 | UDPEncapAdd(ctx context.Context, in *UDPEncapAdd) (*UDPEncapAddReply, error) 18 | UDPEncapDel(ctx context.Context, in *UDPEncapDel) (*UDPEncapDelReply, error) 19 | UDPEncapDump(ctx context.Context, in *UDPEncapDump) (RPCService_UDPEncapDumpClient, error) 20 | } 21 | 22 | type serviceClient struct { 23 | conn api.Connection 24 | } 25 | 26 | func NewServiceClient(conn api.Connection) RPCService { 27 | return &serviceClient{conn} 28 | } 29 | 30 | func (c *serviceClient) UDPDecapAddDel(ctx context.Context, in *UDPDecapAddDel) (*UDPDecapAddDelReply, error) { 31 | out := new(UDPDecapAddDelReply) 32 | err := c.conn.Invoke(ctx, in, out) 33 | if err != nil { 34 | return nil, err 35 | } 36 | return out, api.RetvalToVPPApiError(out.Retval) 37 | } 38 | 39 | func (c *serviceClient) UDPEncapAdd(ctx context.Context, in *UDPEncapAdd) (*UDPEncapAddReply, error) { 40 | out := new(UDPEncapAddReply) 41 | err := c.conn.Invoke(ctx, in, out) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return out, api.RetvalToVPPApiError(out.Retval) 46 | } 47 | 48 | func (c *serviceClient) UDPEncapDel(ctx context.Context, in *UDPEncapDel) (*UDPEncapDelReply, error) { 49 | out := new(UDPEncapDelReply) 50 | err := c.conn.Invoke(ctx, in, out) 51 | if err != nil { 52 | return nil, err 53 | } 54 | return out, api.RetvalToVPPApiError(out.Retval) 55 | } 56 | 57 | func (c *serviceClient) UDPEncapDump(ctx context.Context, in *UDPEncapDump) (RPCService_UDPEncapDumpClient, error) { 58 | stream, err := c.conn.NewStream(ctx) 59 | if err != nil { 60 | return nil, err 61 | } 62 | x := &serviceClient_UDPEncapDumpClient{stream} 63 | if err := x.Stream.SendMsg(in); err != nil { 64 | return nil, err 65 | } 66 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 67 | return nil, err 68 | } 69 | return x, nil 70 | } 71 | 72 | type RPCService_UDPEncapDumpClient interface { 73 | Recv() (*UDPEncapDetails, error) 74 | api.Stream 75 | } 76 | 77 | type serviceClient_UDPEncapDumpClient struct { 78 | api.Stream 79 | } 80 | 81 | func (c *serviceClient_UDPEncapDumpClient) Recv() (*UDPEncapDetails, error) { 82 | msg, err := c.Stream.RecvMsg() 83 | if err != nil { 84 | return nil, err 85 | } 86 | switch m := msg.(type) { 87 | case *UDPEncapDetails: 88 | return m, nil 89 | case *memclnt.ControlPingReply: 90 | err = c.Stream.Close() 91 | if err != nil { 92 | return nil, err 93 | } 94 | return nil, io.EOF 95 | default: 96 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /adapter/mock/binapi/binapi_reflect.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Cisco and/or its affiliates. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package binapi is a helper package for generic handling of VPP binary 16 | // API messages in the mock adapter and integration tests. 17 | package binapi 18 | 19 | import ( 20 | "reflect" 21 | ) 22 | 23 | const swIfIndexName = "SwIfIndex" 24 | const retvalName = "Retval" 25 | const replySuffix = "_reply" 26 | 27 | // findFieldOfType finds the field specified by its name in provided message defined as reflect.Type data type. 28 | func findFieldOfType(reply reflect.Type, fieldName string) (reflect.StructField, bool) { 29 | for reply.Kind() == reflect.Ptr { 30 | reply = reply.Elem() 31 | } 32 | if reply.Kind() == reflect.Struct { 33 | field, found := reply.FieldByName(fieldName) 34 | return field, found 35 | } 36 | return reflect.StructField{}, false 37 | } 38 | 39 | // findFieldOfValue finds the field specified by its name in provided message defined as reflect.Value data type. 40 | func findFieldOfValue(reply reflect.Value, fieldName string) (reflect.Value, bool) { 41 | if reply.Kind() == reflect.Struct { 42 | field := reply.FieldByName(fieldName) 43 | return field, field.IsValid() 44 | } else if reply.Kind() == reflect.Ptr && reply.Elem().Kind() == reflect.Struct { 45 | field := reply.Elem().FieldByName(fieldName) 46 | return field, field.IsValid() 47 | } 48 | return reflect.Value{}, false 49 | } 50 | 51 | // HasSwIfIdx checks whether provided message has the swIfIndex field. 52 | func HasSwIfIdx(msg reflect.Type) bool { 53 | _, found := findFieldOfType(msg, swIfIndexName) 54 | return found 55 | } 56 | 57 | // SetSwIfIdx sets the swIfIndex field of provided message to provided value. 58 | func SetSwIfIdx(msg reflect.Value, swIfIndex uint32) { 59 | if field, found := findFieldOfValue(msg, swIfIndexName); found { 60 | field.Set(reflect.ValueOf(swIfIndex)) 61 | } 62 | } 63 | 64 | // SetRetval sets the retval field of provided message to provided value. 65 | func SetRetval(msg reflect.Value, retVal int32) { 66 | if field, found := findFieldOfValue(msg, retvalName); found { 67 | field.Set(reflect.ValueOf(retVal)) 68 | } 69 | } 70 | 71 | // ReplyNameFor returns reply message name to the given request message name. 72 | func ReplyNameFor(requestName string) (string, bool) { 73 | return requestName + replySuffix, true 74 | } 75 | -------------------------------------------------------------------------------- /test/run_integration.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # // Copyright (c) 2022 Cisco and/or its affiliates. 3 | # // 4 | # // Licensed under the Apache License, Version 2.0 (the "License"); 5 | # // you may not use this file except in compliance with the License. 6 | # // You may obtain a copy of the License at: 7 | # // 8 | # // http://www.apache.org/licenses/LICENSE-2.0 9 | # // 10 | # // Unless required by applicable law or agreed to in writing, software 11 | # // distributed under the License is distributed on an "AS IS" BASIS, 12 | # // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # // See the License for the specific language governing permissions and 14 | # // limitations under the License. 15 | 16 | set -euo pipefail 17 | 18 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P )" 19 | 20 | args=($*) 21 | 22 | echo "Preparing integration tests.." 23 | 24 | VPP_REPO=${VPP_REPO:-release} 25 | 26 | export CGO_ENABLED=0 27 | export DOCKER_BUILDKIT=1 28 | export GOTESTSUM_FORMAT="${GOTESTSUM_FORMAT:-testname}" 29 | 30 | imgtag="govpp-integration" 31 | 32 | go test -c -o test/integration.test \ 33 | -tags 'osusergo netgo e2e' \ 34 | -ldflags '-w -s -extldflags "-static"' \ 35 | -trimpath \ 36 | "${SCRIPT_DIR}/integration" 37 | 38 | docker build --tag "${imgtag}" \ 39 | -f "${SCRIPT_DIR}"/build/Dockerfile.integration \ 40 | --build-arg VPP_REPO="${VPP_REPO}" \ 41 | "${SCRIPT_DIR}"/build 42 | 43 | vppver=$(docker run --rm -i "${imgtag}" dpkg-query -f '${Version}' -W vpp) 44 | 45 | if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then 46 | echo "**VPP version**: \`${vppver}\`" >> $GITHUB_STEP_SUMMARY 47 | echo "" >> $GITHUB_STEP_SUMMARY 48 | fi 49 | 50 | echo "==========================================================================" 51 | echo " GOVPP INTEGRATION TEST - $(date) " 52 | echo "==========================================================================" 53 | echo "- VPP_REPO: $VPP_REPO" 54 | echo "- VPP version: $vppver" 55 | echo "--------------------------------------------------------------------------" 56 | 57 | if docker run -i --privileged \ 58 | -e TEST=integration \ 59 | -e CGO_ENABLED=0 \ 60 | -e DEBUG_GOVPP \ 61 | -e GOTESTSUM_FORMAT \ 62 | -e CLICOLOR_FORCE \ 63 | -v "$(cd "${SCRIPT_DIR}/.." && pwd)":/src \ 64 | -w /src \ 65 | "${imgtag}" gotestsum --raw-command -- go tool test2json -t -p integration ./test/integration.test -test.v ${args[@]:-} 66 | then 67 | echo >&2 "-------------------------------------------------------------" 68 | echo >&2 -e " \e[32mPASSED\e[0m (took: ${SECONDS}s)" 69 | echo >&2 "-------------------------------------------------------------" 70 | exit 0 71 | else 72 | res=$? 73 | echo >&2 "-------------------------------------------------------------" 74 | echo >&2 -e " \e[31mFAILED!\e[0m (exit code: $res)" 75 | echo >&2 "-------------------------------------------------------------" 76 | exit $res 77 | fi 78 | -------------------------------------------------------------------------------- /binapi/tapv2/tapv2_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package tapv2 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service tapv2. 15 | type RPCService interface { 16 | SwInterfaceTapV2Dump(ctx context.Context, in *SwInterfaceTapV2Dump) (RPCService_SwInterfaceTapV2DumpClient, error) 17 | TapCreateV2(ctx context.Context, in *TapCreateV2) (*TapCreateV2Reply, error) 18 | TapCreateV3(ctx context.Context, in *TapCreateV3) (*TapCreateV3Reply, error) 19 | TapDeleteV2(ctx context.Context, in *TapDeleteV2) (*TapDeleteV2Reply, error) 20 | } 21 | 22 | type serviceClient struct { 23 | conn api.Connection 24 | } 25 | 26 | func NewServiceClient(conn api.Connection) RPCService { 27 | return &serviceClient{conn} 28 | } 29 | 30 | func (c *serviceClient) SwInterfaceTapV2Dump(ctx context.Context, in *SwInterfaceTapV2Dump) (RPCService_SwInterfaceTapV2DumpClient, error) { 31 | stream, err := c.conn.NewStream(ctx) 32 | if err != nil { 33 | return nil, err 34 | } 35 | x := &serviceClient_SwInterfaceTapV2DumpClient{stream} 36 | if err := x.Stream.SendMsg(in); err != nil { 37 | return nil, err 38 | } 39 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 40 | return nil, err 41 | } 42 | return x, nil 43 | } 44 | 45 | type RPCService_SwInterfaceTapV2DumpClient interface { 46 | Recv() (*SwInterfaceTapV2Details, error) 47 | api.Stream 48 | } 49 | 50 | type serviceClient_SwInterfaceTapV2DumpClient struct { 51 | api.Stream 52 | } 53 | 54 | func (c *serviceClient_SwInterfaceTapV2DumpClient) Recv() (*SwInterfaceTapV2Details, error) { 55 | msg, err := c.Stream.RecvMsg() 56 | if err != nil { 57 | return nil, err 58 | } 59 | switch m := msg.(type) { 60 | case *SwInterfaceTapV2Details: 61 | return m, nil 62 | case *memclnt.ControlPingReply: 63 | err = c.Stream.Close() 64 | if err != nil { 65 | return nil, err 66 | } 67 | return nil, io.EOF 68 | default: 69 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 70 | } 71 | } 72 | 73 | func (c *serviceClient) TapCreateV2(ctx context.Context, in *TapCreateV2) (*TapCreateV2Reply, error) { 74 | out := new(TapCreateV2Reply) 75 | err := c.conn.Invoke(ctx, in, out) 76 | if err != nil { 77 | return nil, err 78 | } 79 | return out, api.RetvalToVPPApiError(out.Retval) 80 | } 81 | 82 | func (c *serviceClient) TapCreateV3(ctx context.Context, in *TapCreateV3) (*TapCreateV3Reply, error) { 83 | out := new(TapCreateV3Reply) 84 | err := c.conn.Invoke(ctx, in, out) 85 | if err != nil { 86 | return nil, err 87 | } 88 | return out, api.RetvalToVPPApiError(out.Retval) 89 | } 90 | 91 | func (c *serviceClient) TapDeleteV2(ctx context.Context, in *TapDeleteV2) (*TapDeleteV2Reply, error) { 92 | out := new(TapDeleteV2Reply) 93 | err := c.conn.Invoke(ctx, in, out) 94 | if err != nil { 95 | return nil, err 96 | } 97 | return out, api.RetvalToVPPApiError(out.Retval) 98 | } 99 | -------------------------------------------------------------------------------- /docs/GENERATOR.md: -------------------------------------------------------------------------------- 1 | # Generator 2 | 3 | This document contains information about GoVPP generator which is used for generating Go bindings for VPP binary API. 4 | 5 | ## Installation 6 | 7 | ### Prerequisites 8 | 9 | - Go 1.18+ ([download](https://golang.org/dl)) 10 | 11 | ### Install via Go toolchain 12 | 13 | ```shell 14 | # Latest version (most recent tag) 15 | go install go.fd.io/govpp/cmd/binapi-generator@latest 16 | 17 | # Development version (master branch) 18 | go install go.fd.io/govpp/cmd/binapi-generator@master 19 | ``` 20 | 21 | ### Install from source 22 | 23 | ```sh 24 | # Clone repository 25 | git clone https://github.com/FDio/govpp 26 | cd govpp 27 | 28 | # Install binapi-generator 29 | make install-generator 30 | ``` 31 | 32 | ### Generating binapi 33 | 34 | ### Install vpp binary artifacts 35 | 36 | Build locally, or download from packagecloud. Read more: https://fd.io/docs/vpp/master/gettingstarted/installing 37 | 38 | ### Generate binapi (Go bindings) 39 | 40 | Generating Go bindings for VPP binary API from the JSON files 41 | installed with the vpp binary artifacts - located in `/usr/share/vpp/api/`. 42 | 43 | ```sh 44 | make generate-binapi 45 | INFO[0000] found 110 files in API dir "/usr/share/vpp/api" 46 | INFO[0000] Generating 203 files 47 | ``` 48 | 49 | The generated files will be generated under `binapi` directory. 50 | 51 | ### Generate VPP binary API code (Go bindings) 52 | 53 | Once you have `binapi-generator` installed, you can use it to generate Go bindings for VPP binary API 54 | using VPP APIs in JSON format. The JSON input can be specified as a single file (`input-file` argument), or 55 | as a directory that will be scanned for all `.json` files (`input-dir`). The generated Go bindings will 56 | be placed into `output-dir` (by default current working directory), where each Go package will be placed into 57 | a separated directory, e.g.: 58 | 59 | ```sh 60 | binapi-generator --input-file=acl.api.json --output-dir=binapi 61 | binapi-generator --input-dir=/usr/share/vpp/api/core --output-dir=binapi 62 | ``` 63 | 64 | In Go, [go generate](https://blog.golang.org/generate) tool can be leveraged to ease the code generation 65 | process. It allows specifying generator instructions in any one of the regular (non-generated) `.go` files 66 | that are dependent on generated code using special comments: 67 | 68 | ```go 69 | //go:generate binapi-generator --input-dir=bin_api --output-dir=bin_api 70 | ``` 71 | 72 | ### Tracking down generated go code for a specific binary API 73 | 74 | Golang uses capitalization to indicate exported names, so you'll have 75 | to divide through by binapi-generator transformations. Example: 76 | 77 | ``` 78 | define create_loopback -> type CreateLoopback struct ... 79 | vpp binapi definition govpp exported type definition 80 | ``` 81 | The droids you're looking for will be in a file named 82 | .ba.go. Suggest: 83 | 84 | ``` 85 | find git.fd.io/govpp/binapi -name "*.ba.go" | xargs grep -n GoTypeName 86 | ``` 87 | 88 | Look at the indicated .ba.go file, deduce the package name 89 | and import it. See the example above. 90 | -------------------------------------------------------------------------------- /binapi/pot/pot_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package pot 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service pot. 15 | type RPCService interface { 16 | PotProfileActivate(ctx context.Context, in *PotProfileActivate) (*PotProfileActivateReply, error) 17 | PotProfileAdd(ctx context.Context, in *PotProfileAdd) (*PotProfileAddReply, error) 18 | PotProfileDel(ctx context.Context, in *PotProfileDel) (*PotProfileDelReply, error) 19 | PotProfileShowConfigDump(ctx context.Context, in *PotProfileShowConfigDump) (RPCService_PotProfileShowConfigDumpClient, error) 20 | } 21 | 22 | type serviceClient struct { 23 | conn api.Connection 24 | } 25 | 26 | func NewServiceClient(conn api.Connection) RPCService { 27 | return &serviceClient{conn} 28 | } 29 | 30 | func (c *serviceClient) PotProfileActivate(ctx context.Context, in *PotProfileActivate) (*PotProfileActivateReply, error) { 31 | out := new(PotProfileActivateReply) 32 | err := c.conn.Invoke(ctx, in, out) 33 | if err != nil { 34 | return nil, err 35 | } 36 | return out, api.RetvalToVPPApiError(out.Retval) 37 | } 38 | 39 | func (c *serviceClient) PotProfileAdd(ctx context.Context, in *PotProfileAdd) (*PotProfileAddReply, error) { 40 | out := new(PotProfileAddReply) 41 | err := c.conn.Invoke(ctx, in, out) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return out, api.RetvalToVPPApiError(out.Retval) 46 | } 47 | 48 | func (c *serviceClient) PotProfileDel(ctx context.Context, in *PotProfileDel) (*PotProfileDelReply, error) { 49 | out := new(PotProfileDelReply) 50 | err := c.conn.Invoke(ctx, in, out) 51 | if err != nil { 52 | return nil, err 53 | } 54 | return out, api.RetvalToVPPApiError(out.Retval) 55 | } 56 | 57 | func (c *serviceClient) PotProfileShowConfigDump(ctx context.Context, in *PotProfileShowConfigDump) (RPCService_PotProfileShowConfigDumpClient, error) { 58 | stream, err := c.conn.NewStream(ctx) 59 | if err != nil { 60 | return nil, err 61 | } 62 | x := &serviceClient_PotProfileShowConfigDumpClient{stream} 63 | if err := x.Stream.SendMsg(in); err != nil { 64 | return nil, err 65 | } 66 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 67 | return nil, err 68 | } 69 | return x, nil 70 | } 71 | 72 | type RPCService_PotProfileShowConfigDumpClient interface { 73 | Recv() (*PotProfileShowConfigDetails, error) 74 | api.Stream 75 | } 76 | 77 | type serviceClient_PotProfileShowConfigDumpClient struct { 78 | api.Stream 79 | } 80 | 81 | func (c *serviceClient_PotProfileShowConfigDumpClient) Recv() (*PotProfileShowConfigDetails, error) { 82 | msg, err := c.Stream.RecvMsg() 83 | if err != nil { 84 | return nil, err 85 | } 86 | switch m := msg.(type) { 87 | case *PotProfileShowConfigDetails: 88 | return m, nil 89 | case *memclnt.ControlPingReply: 90 | err = c.Stream.Close() 91 | if err != nil { 92 | return nil, err 93 | } 94 | return nil, io.EOF 95 | default: 96 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /binapi/virtio/virtio_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package virtio 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service virtio. 15 | type RPCService interface { 16 | SwInterfaceVirtioPciDump(ctx context.Context, in *SwInterfaceVirtioPciDump) (RPCService_SwInterfaceVirtioPciDumpClient, error) 17 | VirtioPciCreate(ctx context.Context, in *VirtioPciCreate) (*VirtioPciCreateReply, error) 18 | VirtioPciCreateV2(ctx context.Context, in *VirtioPciCreateV2) (*VirtioPciCreateV2Reply, error) 19 | VirtioPciDelete(ctx context.Context, in *VirtioPciDelete) (*VirtioPciDeleteReply, error) 20 | } 21 | 22 | type serviceClient struct { 23 | conn api.Connection 24 | } 25 | 26 | func NewServiceClient(conn api.Connection) RPCService { 27 | return &serviceClient{conn} 28 | } 29 | 30 | func (c *serviceClient) SwInterfaceVirtioPciDump(ctx context.Context, in *SwInterfaceVirtioPciDump) (RPCService_SwInterfaceVirtioPciDumpClient, error) { 31 | stream, err := c.conn.NewStream(ctx) 32 | if err != nil { 33 | return nil, err 34 | } 35 | x := &serviceClient_SwInterfaceVirtioPciDumpClient{stream} 36 | if err := x.Stream.SendMsg(in); err != nil { 37 | return nil, err 38 | } 39 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 40 | return nil, err 41 | } 42 | return x, nil 43 | } 44 | 45 | type RPCService_SwInterfaceVirtioPciDumpClient interface { 46 | Recv() (*SwInterfaceVirtioPciDetails, error) 47 | api.Stream 48 | } 49 | 50 | type serviceClient_SwInterfaceVirtioPciDumpClient struct { 51 | api.Stream 52 | } 53 | 54 | func (c *serviceClient_SwInterfaceVirtioPciDumpClient) Recv() (*SwInterfaceVirtioPciDetails, error) { 55 | msg, err := c.Stream.RecvMsg() 56 | if err != nil { 57 | return nil, err 58 | } 59 | switch m := msg.(type) { 60 | case *SwInterfaceVirtioPciDetails: 61 | return m, nil 62 | case *memclnt.ControlPingReply: 63 | err = c.Stream.Close() 64 | if err != nil { 65 | return nil, err 66 | } 67 | return nil, io.EOF 68 | default: 69 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 70 | } 71 | } 72 | 73 | func (c *serviceClient) VirtioPciCreate(ctx context.Context, in *VirtioPciCreate) (*VirtioPciCreateReply, error) { 74 | out := new(VirtioPciCreateReply) 75 | err := c.conn.Invoke(ctx, in, out) 76 | if err != nil { 77 | return nil, err 78 | } 79 | return out, api.RetvalToVPPApiError(out.Retval) 80 | } 81 | 82 | func (c *serviceClient) VirtioPciCreateV2(ctx context.Context, in *VirtioPciCreateV2) (*VirtioPciCreateV2Reply, error) { 83 | out := new(VirtioPciCreateV2Reply) 84 | err := c.conn.Invoke(ctx, in, out) 85 | if err != nil { 86 | return nil, err 87 | } 88 | return out, api.RetvalToVPPApiError(out.Retval) 89 | } 90 | 91 | func (c *serviceClient) VirtioPciDelete(ctx context.Context, in *VirtioPciDelete) (*VirtioPciDeleteReply, error) { 92 | out := new(VirtioPciDeleteReply) 93 | err := c.conn.Invoke(ctx, in, out) 94 | if err != nil { 95 | return nil, err 96 | } 97 | return out, api.RetvalToVPPApiError(out.Retval) 98 | } 99 | -------------------------------------------------------------------------------- /binapi/geneve/geneve_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package geneve 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | "io" 9 | 10 | api "go.fd.io/govpp/api" 11 | memclnt "go.fd.io/govpp/binapi/memclnt" 12 | ) 13 | 14 | // RPCService defines RPC service geneve. 15 | type RPCService interface { 16 | GeneveAddDelTunnel(ctx context.Context, in *GeneveAddDelTunnel) (*GeneveAddDelTunnelReply, error) 17 | GeneveAddDelTunnel2(ctx context.Context, in *GeneveAddDelTunnel2) (*GeneveAddDelTunnel2Reply, error) 18 | GeneveTunnelDump(ctx context.Context, in *GeneveTunnelDump) (RPCService_GeneveTunnelDumpClient, error) 19 | SwInterfaceSetGeneveBypass(ctx context.Context, in *SwInterfaceSetGeneveBypass) (*SwInterfaceSetGeneveBypassReply, error) 20 | } 21 | 22 | type serviceClient struct { 23 | conn api.Connection 24 | } 25 | 26 | func NewServiceClient(conn api.Connection) RPCService { 27 | return &serviceClient{conn} 28 | } 29 | 30 | func (c *serviceClient) GeneveAddDelTunnel(ctx context.Context, in *GeneveAddDelTunnel) (*GeneveAddDelTunnelReply, error) { 31 | out := new(GeneveAddDelTunnelReply) 32 | err := c.conn.Invoke(ctx, in, out) 33 | if err != nil { 34 | return nil, err 35 | } 36 | return out, api.RetvalToVPPApiError(out.Retval) 37 | } 38 | 39 | func (c *serviceClient) GeneveAddDelTunnel2(ctx context.Context, in *GeneveAddDelTunnel2) (*GeneveAddDelTunnel2Reply, error) { 40 | out := new(GeneveAddDelTunnel2Reply) 41 | err := c.conn.Invoke(ctx, in, out) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return out, api.RetvalToVPPApiError(out.Retval) 46 | } 47 | 48 | func (c *serviceClient) GeneveTunnelDump(ctx context.Context, in *GeneveTunnelDump) (RPCService_GeneveTunnelDumpClient, error) { 49 | stream, err := c.conn.NewStream(ctx) 50 | if err != nil { 51 | return nil, err 52 | } 53 | x := &serviceClient_GeneveTunnelDumpClient{stream} 54 | if err := x.Stream.SendMsg(in); err != nil { 55 | return nil, err 56 | } 57 | if err = x.Stream.SendMsg(&memclnt.ControlPing{}); err != nil { 58 | return nil, err 59 | } 60 | return x, nil 61 | } 62 | 63 | type RPCService_GeneveTunnelDumpClient interface { 64 | Recv() (*GeneveTunnelDetails, error) 65 | api.Stream 66 | } 67 | 68 | type serviceClient_GeneveTunnelDumpClient struct { 69 | api.Stream 70 | } 71 | 72 | func (c *serviceClient_GeneveTunnelDumpClient) Recv() (*GeneveTunnelDetails, error) { 73 | msg, err := c.Stream.RecvMsg() 74 | if err != nil { 75 | return nil, err 76 | } 77 | switch m := msg.(type) { 78 | case *GeneveTunnelDetails: 79 | return m, nil 80 | case *memclnt.ControlPingReply: 81 | err = c.Stream.Close() 82 | if err != nil { 83 | return nil, err 84 | } 85 | return nil, io.EOF 86 | default: 87 | return nil, fmt.Errorf("unexpected message: %T %v", m, m) 88 | } 89 | } 90 | 91 | func (c *serviceClient) SwInterfaceSetGeneveBypass(ctx context.Context, in *SwInterfaceSetGeneveBypass) (*SwInterfaceSetGeneveBypassReply, error) { 92 | out := new(SwInterfaceSetGeneveBypassReply) 93 | err := c.conn.Invoke(ctx, in, out) 94 | if err != nil { 95 | return nil, err 96 | } 97 | return out, api.RetvalToVPPApiError(out.Retval) 98 | } 99 | -------------------------------------------------------------------------------- /binapi/ioam_vxlan_gpe/ioam_vxlan_gpe_rpc.ba.go: -------------------------------------------------------------------------------- 1 | // Code generated by GoVPP's binapi-generator. DO NOT EDIT. 2 | 3 | package ioam_vxlan_gpe 4 | 5 | import ( 6 | "context" 7 | 8 | api "go.fd.io/govpp/api" 9 | ) 10 | 11 | // RPCService defines RPC service ioam_vxlan_gpe. 12 | type RPCService interface { 13 | VxlanGpeIoamDisable(ctx context.Context, in *VxlanGpeIoamDisable) (*VxlanGpeIoamDisableReply, error) 14 | VxlanGpeIoamEnable(ctx context.Context, in *VxlanGpeIoamEnable) (*VxlanGpeIoamEnableReply, error) 15 | VxlanGpeIoamTransitDisable(ctx context.Context, in *VxlanGpeIoamTransitDisable) (*VxlanGpeIoamTransitDisableReply, error) 16 | VxlanGpeIoamTransitEnable(ctx context.Context, in *VxlanGpeIoamTransitEnable) (*VxlanGpeIoamTransitEnableReply, error) 17 | VxlanGpeIoamVniDisable(ctx context.Context, in *VxlanGpeIoamVniDisable) (*VxlanGpeIoamVniDisableReply, error) 18 | VxlanGpeIoamVniEnable(ctx context.Context, in *VxlanGpeIoamVniEnable) (*VxlanGpeIoamVniEnableReply, error) 19 | } 20 | 21 | type serviceClient struct { 22 | conn api.Connection 23 | } 24 | 25 | func NewServiceClient(conn api.Connection) RPCService { 26 | return &serviceClient{conn} 27 | } 28 | 29 | func (c *serviceClient) VxlanGpeIoamDisable(ctx context.Context, in *VxlanGpeIoamDisable) (*VxlanGpeIoamDisableReply, error) { 30 | out := new(VxlanGpeIoamDisableReply) 31 | err := c.conn.Invoke(ctx, in, out) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return out, api.RetvalToVPPApiError(out.Retval) 36 | } 37 | 38 | func (c *serviceClient) VxlanGpeIoamEnable(ctx context.Context, in *VxlanGpeIoamEnable) (*VxlanGpeIoamEnableReply, error) { 39 | out := new(VxlanGpeIoamEnableReply) 40 | err := c.conn.Invoke(ctx, in, out) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return out, api.RetvalToVPPApiError(out.Retval) 45 | } 46 | 47 | func (c *serviceClient) VxlanGpeIoamTransitDisable(ctx context.Context, in *VxlanGpeIoamTransitDisable) (*VxlanGpeIoamTransitDisableReply, error) { 48 | out := new(VxlanGpeIoamTransitDisableReply) 49 | err := c.conn.Invoke(ctx, in, out) 50 | if err != nil { 51 | return nil, err 52 | } 53 | return out, api.RetvalToVPPApiError(out.Retval) 54 | } 55 | 56 | func (c *serviceClient) VxlanGpeIoamTransitEnable(ctx context.Context, in *VxlanGpeIoamTransitEnable) (*VxlanGpeIoamTransitEnableReply, error) { 57 | out := new(VxlanGpeIoamTransitEnableReply) 58 | err := c.conn.Invoke(ctx, in, out) 59 | if err != nil { 60 | return nil, err 61 | } 62 | return out, api.RetvalToVPPApiError(out.Retval) 63 | } 64 | 65 | func (c *serviceClient) VxlanGpeIoamVniDisable(ctx context.Context, in *VxlanGpeIoamVniDisable) (*VxlanGpeIoamVniDisableReply, error) { 66 | out := new(VxlanGpeIoamVniDisableReply) 67 | err := c.conn.Invoke(ctx, in, out) 68 | if err != nil { 69 | return nil, err 70 | } 71 | return out, api.RetvalToVPPApiError(out.Retval) 72 | } 73 | 74 | func (c *serviceClient) VxlanGpeIoamVniEnable(ctx context.Context, in *VxlanGpeIoamVniEnable) (*VxlanGpeIoamVniEnableReply, error) { 75 | out := new(VxlanGpeIoamVniEnableReply) 76 | err := c.conn.Invoke(ctx, in, out) 77 | if err != nil { 78 | return nil, err 79 | } 80 | return out, api.RetvalToVPPApiError(out.Retval) 81 | } 82 | --------------------------------------------------------------------------------