diff --git a/go.mod b/go.mod index 6fb61df62b..f59b6c2768 100644 --- a/go.mod +++ b/go.mod @@ -53,6 +53,7 @@ require ( github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jhump/protoreflect v1.5.0 + github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect github.com/ligato/cn-infra v2.2.1-0.20191030081411-42c7431fdca1+incompatible github.com/lunixbochs/struc v0.0.0-20190916212049-a5c72983bc42 github.com/mitchellh/go-homedir v0.0.0-20180523094522-3864e76763d9 // indirect @@ -71,7 +72,7 @@ require ( github.com/prometheus/client_golang v0.9.3 github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165 // indirect github.com/satori/go.uuid v0.0.0-20181028125025-b2ce2384e17b // indirect - github.com/sirupsen/logrus v1.2.0 + github.com/sirupsen/logrus v1.4.2 github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.3 github.com/spf13/viper v1.4.0 @@ -83,8 +84,9 @@ require ( github.com/yuin/gopher-lua v0.0.0-20190514113301-1cd887cd7036 // indirect go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/multierr v1.2.0 // indirect + golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 // indirect golang.org/x/net v0.0.0-20190522155817-f3200d17e092 - golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a + golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect google.golang.org/grpc v1.24.0 gotest.tools v2.2.0+incompatible // indirect diff --git a/go.sum b/go.sum index 16df0df71b..db7d3bae07 100644 --- a/go.sum +++ b/go.sum @@ -189,6 +189,8 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -275,6 +277,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg github.com/sirupsen/logrus v1.0.0/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -329,6 +333,8 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3 h1:KYQXGkl6vs02hK7pK4eIbw golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 h1:ULYEB3JvPRE/IfO+9uO7vKV/xzVTO7XPAwm8xbf4w2g= +golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -340,6 +346,7 @@ golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1 golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= @@ -362,6 +369,10 @@ golang.org/x/sys v0.0.0-20190204203706-41f3e6584952 h1:FDfvYgoVsA7TTZSbgiqjAbfPb golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 h1:gSbV7h1NRL2G1xTg/owz62CST1oJBmxy4QpMMregXVQ= +golang.org/x/sys v0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/plugins/configurator/plugin.go b/plugins/configurator/plugin.go index 52f4881f62..b3f6483752 100644 --- a/plugins/configurator/plugin.go +++ b/plugins/configurator/plugin.go @@ -15,12 +15,9 @@ package configurator import ( - "git.fd.io/govpp.git/api" - "github.com/ligato/cn-infra/infra" "github.com/ligato/cn-infra/rpc/grpc" "github.com/ligato/cn-infra/servicelabel" - "github.com/ligato/cn-infra/utils/safeclose" "go.ligato.io/vpp-agent/v2/plugins/govppmux" iflinuxplugin "go.ligato.io/vpp-agent/v2/plugins/linux/ifplugin" @@ -53,9 +50,6 @@ type Plugin struct { Deps configurator configuratorServer - - // Channels - vppChan api.Channel } // Deps - dependencies of Plugin @@ -107,16 +101,11 @@ func (p *Plugin) sendVppNotification(vppNotification *vpp.Notification) { // Close does nothing. func (p *Plugin) Close() error { - return safeclose.Close(p.vppChan) + return nil } // helper method initializes all VPP/Linux plugin handlers func (p *Plugin) initHandlers() (err error) { - // VPP channels - if p.vppChan, err = p.VPP.NewAPIChannel(); err != nil { - return err - } - // VPP Indexes ifIndexes := p.VPPIfPlugin.GetInterfaceIndex() dhcpIndexes := p.VPPIfPlugin.GetDHCPIndex() @@ -128,25 +117,22 @@ func (p *Plugin) initHandlers() (err error) { linuxIfIndexes := p.LinuxIfPlugin.GetInterfaceIndex() // VPP handlers - - // core p.configurator.ifHandler = ifvppcalls.CompatibleInterfaceVppHandler(p.VPP, p.Log) if p.configurator.ifHandler == nil { p.Log.Info("VPP Interface handler is not available, it will be skipped") } - p.configurator.l2Handler = l2vppcalls.CompatibleL2VppHandler(p.vppChan, ifIndexes, bdIndexes, p.Log) + p.configurator.l2Handler = l2vppcalls.CompatibleL2VppHandler(p.VPP, ifIndexes, bdIndexes, p.Log) if p.configurator.l2Handler == nil { p.Log.Info("VPP L2 handler is not available, it will be skipped") } - p.configurator.l3Handler = l3vppcalls.CompatibleL3VppHandler(p.vppChan, ifIndexes, vrfIndexes, p.AddrAlloc, p.Log) + p.configurator.l3Handler = l3vppcalls.CompatibleL3VppHandler(p.VPP, ifIndexes, vrfIndexes, p.AddrAlloc, p.Log) if p.configurator.l3Handler == nil { p.Log.Info("VPP L3 handler is not available, it will be skipped") } - p.configurator.ipsecHandler = ipsecvppcalls.CompatibleIPSecVppHandler(p.vppChan, ifIndexes, p.Log) + p.configurator.ipsecHandler = ipsecvppcalls.CompatibleIPSecVppHandler(p.VPP, ifIndexes, p.Log) if p.configurator.ipsecHandler == nil { p.Log.Info("VPP IPSec handler is not available, it will be skipped") } - // plugins p.configurator.abfHandler = abfvppcalls.CompatibleABFHandler(p.VPP, aclIndexes, ifIndexes, p.Log) if p.configurator.abfHandler == nil { @@ -160,7 +146,7 @@ func (p *Plugin) initHandlers() (err error) { if p.configurator.natHandler == nil { p.Log.Info("VPP NAT handler is not available, it will be skipped") } - p.configurator.puntHandler = puntvppcalls.CompatiblePuntVppHandler(p.vppChan, ifIndexes, p.Log) + p.configurator.puntHandler = puntvppcalls.CompatiblePuntVppHandler(p.VPP, ifIndexes, p.Log) if p.configurator.puntHandler == nil { p.Log.Info("VPP Punt handler is not available, it will be skipped") } diff --git a/plugins/govppmux/client_binapi_test.go b/plugins/govppmux/client_binapi_test.go index 3952443ccc..57f602db94 100644 --- a/plugins/govppmux/client_binapi_test.go +++ b/plugins/govppmux/client_binapi_test.go @@ -21,7 +21,7 @@ import ( "git.fd.io/govpp.git/core" . "github.com/onsi/gomega" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestRequestRetry(t *testing.T) { @@ -72,7 +72,7 @@ func TestRequestRetry(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() retryCfg := retryConfig{test.attempts, test.timeout} diff --git a/plugins/govppmux/client_stats.go b/plugins/govppmux/client_stats.go index b525048064..d9e13bae23 100644 --- a/plugins/govppmux/client_stats.go +++ b/plugins/govppmux/client_stats.go @@ -17,7 +17,6 @@ package govppmux import ( "git.fd.io/govpp.git/adapter" govppapi "git.fd.io/govpp.git/api" - govpp "git.fd.io/govpp.git/core" ) // ListStats returns all stats names @@ -38,7 +37,7 @@ func (p *Plugin) DumpStats(prefixes ...string) ([]adapter.StatEntry, error) { // GetSystemStats retrieves system statistics of the connected VPP instance like Vector rate, Input rate, etc. func (p *Plugin) GetSystemStats(stats *govppapi.SystemStats) error { - if p.statsConn == nil || p.statsConn.(*govpp.StatsConnection) == nil { + if p.statsConn == nil { return nil } return p.statsConn.GetSystemStats(stats) @@ -46,7 +45,7 @@ func (p *Plugin) GetSystemStats(stats *govppapi.SystemStats) error { // GetNodeStats retrieves a list of Node VPP counters (vectors, clocks, ...) func (p *Plugin) GetNodeStats(stats *govppapi.NodeStats) error { - if p.statsConn == nil || p.statsConn.(*govpp.StatsConnection) == nil { + if p.statsConn == nil { return nil } return p.statsConn.GetNodeStats(stats) @@ -54,7 +53,7 @@ func (p *Plugin) GetNodeStats(stats *govppapi.NodeStats) error { // GetInterfaceStats retrieves all counters related to the VPP interfaces func (p *Plugin) GetInterfaceStats(stats *govppapi.InterfaceStats) error { - if p.statsConn == nil || p.statsConn.(*govpp.StatsConnection) == nil { + if p.statsConn == nil { return nil } return p.statsConn.GetInterfaceStats(stats) @@ -62,15 +61,15 @@ func (p *Plugin) GetInterfaceStats(stats *govppapi.InterfaceStats) error { // GetErrorStats retrieves VPP error counters func (p *Plugin) GetErrorStats(stats *govppapi.ErrorStats) error { - if p.statsConn == nil || p.statsConn.(*govpp.StatsConnection) == nil { + if p.statsConn == nil { return nil } return p.statsConn.GetErrorStats(stats) } -// GetErrorStats retrieves VPP error counters +// GetBufferStats retrieves VPP error counters func (p *Plugin) GetBufferStats(stats *govppapi.BufferStats) error { - if p.statsConn == nil || p.statsConn.(*govpp.StatsConnection) == nil { + if p.statsConn == nil { return nil } return p.statsConn.GetBufferStats(stats) diff --git a/plugins/govppmux/config.go b/plugins/govppmux/config.go index 02ad090b3b..1a924333e3 100644 --- a/plugins/govppmux/config.go +++ b/plugins/govppmux/config.go @@ -49,6 +49,9 @@ type Config struct { // Time between connection request resend attempts. Default is 1s. RetryConnectTimeout time.Duration `json:"retry-connect-timeout"` + // Enable VPP proxy. + ProxyEnabled bool `json:"proxy-enabled"` + // Below are options used for VPP connection health checking. HealthCheckProbeInterval time.Duration `json:"health-check-probe-interval"` HealthCheckReplyTimeout time.Duration `json:"health-check-reply-timeout"` @@ -66,6 +69,7 @@ func DefaultConfig() *Config { ReplyTimeout: time.Second, RetryRequestTimeout: 500 * time.Millisecond, RetryConnectTimeout: time.Second, + ProxyEnabled: true, } } diff --git a/plugins/govppmux/govpp.conf b/plugins/govppmux/govpp.conf index a48498bc72..564beca1b9 100644 --- a/plugins/govppmux/govpp.conf +++ b/plugins/govppmux/govpp.conf @@ -32,3 +32,6 @@ retry-connect-count: 3 # Defines time in nanoseconds between VPP connection retries (default is 1 second). retry-connect-timeout: 1s + +# Enable VPP proxy. +proxy-enabled: true \ No newline at end of file diff --git a/plugins/govppmux/plugin_impl_govppmux.go b/plugins/govppmux/plugin_impl_govppmux.go index 7312a49f90..d41559bf0b 100644 --- a/plugins/govppmux/plugin_impl_govppmux.go +++ b/plugins/govppmux/plugin_impl_govppmux.go @@ -16,6 +16,7 @@ package govppmux import ( "context" + "encoding/gob" "fmt" "os" "strings" @@ -25,6 +26,7 @@ import ( "git.fd.io/govpp.git/adapter" govppapi "git.fd.io/govpp.git/api" govpp "git.fd.io/govpp.git/core" + "git.fd.io/govpp.git/proxy" "github.com/ligato/cn-infra/datasync/resync" "github.com/ligato/cn-infra/health/statuscheck" "github.com/ligato/cn-infra/infra" @@ -33,6 +35,8 @@ import ( "github.com/pkg/errors" "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls" + "go.ligato.io/vpp-agent/v2/plugins/vpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi" _ "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp1904" _ "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp1908" @@ -50,14 +54,18 @@ type Plugin struct { config *Config - vppAdapter adapter.VppAPI - vppConn *govpp.Connection - vppConChan chan govpp.ConnectionEvent - lastConnErr error - vppapiChan govppapi.Channel + vpeHandler vppcalls.VppCoreAPI + + binapiVersion vpp.Version + vppConn *govpp.Connection + vppConChan chan govpp.ConnectionEvent + lastConnErr error + vppapiChan govppapi.Channel statsAdapter adapter.StatsAPI - statsConn govppapi.StatsProvider + statsConn *govpp.StatsConnection + + proxy *proxy.Server // infoMu synchonizes access to fields // vppInfo and lastEvent @@ -85,6 +93,7 @@ func (p *Plugin) Init() (err error) { p.Log.Debugf("config: %+v", p.config) + // set GoVPP config govpp.HealthCheckProbeInterval = p.config.HealthCheckProbeInterval govpp.HealthCheckReplyTimeout = p.config.HealthCheckReplyTimeout govpp.HealthCheckThreshold = p.config.HealthCheckThreshold @@ -93,18 +102,12 @@ func (p *Plugin) Init() (err error) { // register REST API handlers p.registerHandlers(p.HTTPHandlers) - if p.vppAdapter == nil { - var address string - useShm := disabledSocketClient || p.config.ConnectViaShm || p.config.ShmPrefix != "" - if useShm { - address = p.config.ShmPrefix - } else { - address = p.config.BinAPISocketPath - } - p.vppAdapter = NewVppAdapter(address, useShm) + var address string + useShm := disabledSocketClient || p.config.ConnectViaShm || p.config.ShmPrefix != "" + if useShm { + address = p.config.ShmPrefix } else { - // this is used for testing purposes - p.Log.Info("Reusing existing vppAdapter") + address = p.config.BinAPISocketPath } // TODO: Async connect & automatic reconnect support is not yet implemented in the agent, @@ -112,14 +115,17 @@ func (p *Plugin) Init() (err error) { startTime := time.Now() p.Log.Debugf("connecting to VPP..") - p.vppConn, p.vppConChan, err = govpp.AsyncConnect(p.vppAdapter, p.config.RetryConnectCount, p.config.RetryConnectTimeout) + vppAdapter := NewVppAdapter(address, useShm) + p.vppConn, p.vppConChan, err = govpp.AsyncConnect(vppAdapter, p.config.RetryConnectCount, p.config.RetryConnectTimeout) if err != nil { return err } - // wait for connection event for { - event := <-p.vppConChan + event, ok := <-p.vppConChan + if !ok { + return errors.Errorf("VPP connection state channel closed") + } if event.State == govpp.Connected { break } else if event.State == govpp.Failed || event.State == govpp.Disconnected { @@ -128,9 +134,8 @@ func (p *Plugin) Init() (err error) { p.Log.Debugf("VPP connection state: %+v", event) } } - - connectDur := time.Since(startTime) - p.Log.Debugf("connection to VPP established (took %s)", connectDur.Round(time.Millisecond)) + took := time.Since(startTime) + p.Log.Debugf("connection to VPP established (took %s)", took.Round(time.Millisecond)) if err := p.updateVPPInfo(); err != nil { return errors.WithMessage(err, "retrieving VPP info failed") @@ -151,6 +156,19 @@ func (p *Plugin) Init() (err error) { p.statsAdapter = nil } + if p.config.ProxyEnabled { + // register binapi messages to gob package (required for proxy) + msgList := binapi.Versions[p.binapiVersion] + for _, msg := range msgList.AllMessages() { + gob.Register(msg) + } + err := p.startProxy(NewVppAdapter(address, useShm), NewStatsAdapter(statsSocket)) + if err != nil { + return err + } + p.Log.Infof("VPP proxy ready") + } + return nil } @@ -185,8 +203,18 @@ func (p *Plugin) Close() error { } }() + if p.proxy != nil { + p.proxy.DisconnectBinapi() + p.proxy.DisconnectStats() + } + return nil } + +func (p *Plugin) Version() vpp.Version { + return p.binapiVersion +} + func (p *Plugin) CheckCompatiblity(msgs ...govppapi.Message) error { p.infoMu.Lock() defer p.infoMu.Unlock() @@ -201,13 +229,12 @@ func (p *Plugin) CheckCompatiblity(msgs ...govppapi.Message) error { } func (p *Plugin) Stats() govppapi.StatsProvider { + if p.statsConn == nil { + return nil + } return p } -func (p *Plugin) StatsConnected() bool { - return p.statsConn != nil -} - // VPPInfo returns information about VPP session. func (p *Plugin) VPPInfo() VPPInfo { p.infoMu.Lock() @@ -238,20 +265,23 @@ func (p *Plugin) updateVPPInfo() (err error) { if err != nil { return err } + p.binapiVersion, err = vpp.FindCompatibleBinapi(p.vppapiChan) + if err != nil { + return err + } - vpeHandler := vppcalls.CompatibleHandler(p) - if vpeHandler == nil { + p.vpeHandler, err = vppcalls.NewHandler(p) + if err != nil { return errors.New("no compatible VPP handler found") } - version, err := vpeHandler.RunCli(ctx, "show version verbose") + version, err := p.vpeHandler.RunCli(ctx, "show version verbose") if err != nil { p.Log.Warnf("RunCli error: %v", err) } else { p.Log.Debugf("vpp# show version verbose\n%s", version) } - - cmdline, err := vpeHandler.RunCli(ctx, "show version cmdline") + cmdline, err := p.vpeHandler.RunCli(ctx, "show version cmdline") if err != nil { p.Log.Warnf("RunCli error: %v", err) } else { @@ -259,11 +289,11 @@ func (p *Plugin) updateVPPInfo() (err error) { p.Log.Debugf("vpp# show version cmdline:\n%s", out) } - ver, err := vpeHandler.GetVersion(ctx) + ver, err := p.vpeHandler.GetVersion(ctx) if err != nil { return err } - session, err := vpeHandler.GetSession(ctx) + session, err := p.vpeHandler.GetSession(ctx) if err != nil { return err } @@ -272,13 +302,13 @@ func (p *Plugin) updateVPPInfo() (err error) { "ClientID": session.ClientIdx, }).Infof("VPP version: %v", ver.Version) - modules, err := vpeHandler.GetModules(ctx) + modules, err := p.vpeHandler.GetModules(ctx) if err != nil { return err } p.Log.Debugf("VPP has %d core modules: %v", len(modules), modules) - plugins, err := vpeHandler.GetPlugins(ctx) + plugins, err := p.vpeHandler.GetPlugins(ctx) if err != nil { return err } @@ -296,6 +326,12 @@ func (p *Plugin) updateVPPInfo() (err error) { } p.infoMu.Unlock() + p.Log.Debugf("listing %d VPP handlers", len(vpp.GetHandlers())) + for name, handler := range vpp.GetHandlers() { + versions := handler.Versions() + p.Log.Debugf("- handler: %-10s has %d versions: %v", name, len(versions), versions) + } + return nil } @@ -305,7 +341,13 @@ func (p *Plugin) handleVPPConnectionEvents(ctx context.Context) { for { select { - case event := <-p.vppConChan: + case event, ok := <-p.vppConChan: + if !ok { + p.lastConnErr = errors.Errorf("VPP connection state channel closed") + p.StatusCheck.ReportStateChange(p.PluginName, statuscheck.Error, p.lastConnErr) + return + } + if event.State == govpp.Connected { if err := p.updateVPPInfo(); err != nil { p.Log.Errorf("updating VPP info failed: %v", err) @@ -341,3 +383,19 @@ func (p *Plugin) handleVPPConnectionEvents(ctx context.Context) { } } } + +func (p *Plugin) startProxy(vppapi adapter.VppAPI, statsapi adapter.StatsAPI) (err error) { + p.Log.Infof("starting VPP proxy") + + p.proxy, err = proxy.NewServer() + if err != nil { + return errors.WithMessage(err, "creating proxy failed") + } + if err = p.proxy.ConnectBinapi(vppapi); err != nil { + return errors.WithMessage(err, "connecting binapi for proxy failed") + } + if err = p.proxy.ConnectStats(statsapi); err != nil { + return errors.WithMessage(err, "connecting stats for proxy failed") + } + return nil +} diff --git a/plugins/govppmux/rest.go b/plugins/govppmux/rest.go index 5ff07fdb29..7e304553fe 100644 --- a/plugins/govppmux/rest.go +++ b/plugins/govppmux/rest.go @@ -15,7 +15,11 @@ package govppmux import ( + "encoding/json" + "fmt" + "io/ioutil" "net/http" + "net/rpc" "github.com/ligato/cn-infra/rpc/rest" "github.com/unrolled/render" @@ -28,6 +32,8 @@ func (p *Plugin) registerHandlers(http rest.HTTPHandlers) { return } http.RegisterHTTPHandler("/govppmux/stats", p.statsHandler, "GET") + http.RegisterHTTPHandler(rpc.DefaultRPCPath, p.proxyHandler, "CONNECT") + http.RegisterHTTPHandler("/vpp/command", p.cliCommandHandler, "POST") } func (p *Plugin) statsHandler(formatter *render.Render) http.HandlerFunc { @@ -37,3 +43,49 @@ func (p *Plugin) statsHandler(formatter *render.Render) http.HandlerFunc { } } } + +func (p *Plugin) proxyHandler(_ *render.Render) http.HandlerFunc { + if !p.config.ProxyEnabled { + return func(w http.ResponseWriter, req *http.Request) { + http.Error(w, "VPP proxy not enabled", http.StatusServiceUnavailable) + } + } + return func(w http.ResponseWriter, req *http.Request) { + p.proxy.ServeHTTP(w, req) + } +} + +func (p *Plugin) cliCommandHandler(formatter *render.Render) http.HandlerFunc { + return func(w http.ResponseWriter, req *http.Request) { + body, err := ioutil.ReadAll(req.Body) + if err != nil { + errMsg := fmt.Sprintf("400 Bad request: failed to parse request body: %v", err) + _ = formatter.JSON(w, http.StatusBadRequest, errMsg) + return + } + var reqParam map[string]string + + if err = json.Unmarshal(body, &reqParam); err != nil { + errMsg := fmt.Sprintf("400 Bad request: failed to unmarshall request body: %v\n", err) + _ = formatter.JSON(w, http.StatusBadRequest, errMsg) + return + } + command, ok := reqParam["vppclicommand"] + if !ok || command == "" { + errMsg := fmt.Sprintf("400 Bad request: vppclicommand parameter missing or empty\n") + _ = formatter.JSON(w, http.StatusBadRequest, errMsg) + return + } + + p.Log.Debugf("VPPCLI command: %v", command) + reply, err := p.vpeHandler.RunCli(req.Context(), command) + if err != nil { + errMsg := fmt.Sprintf("500 Internal server error: sending request failed: %v\n", err) + _ = formatter.JSON(w, http.StatusInternalServerError, errMsg) + return + } + + p.Log.Debugf("VPPCLI response: %s", reply) + _ = formatter.JSON(w, http.StatusOK, reply) + } +} diff --git a/plugins/govppmux/vppcalls/vpp1904/vppcalls_handler.go b/plugins/govppmux/vppcalls/vpp1904/vppcalls_handler.go index 42ed9bdd5a..bb31bc6567 100644 --- a/plugins/govppmux/vppcalls/vpp1904/vppcalls_handler.go +++ b/plugins/govppmux/vppcalls/vpp1904/vppcalls_handler.go @@ -16,32 +16,14 @@ package vpp1904 import ( govppapi "git.fd.io/govpp.git/api" - "go.ligato.io/vpp-agent/v2/plugins/vpp" "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls" + "go.ligato.io/vpp-agent/v2/plugins/vpp" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/memclnt" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vpe" ) -/*var ( - CompatibilityCheck = vpp.MessageCheck( - vpe.AllMessages, - memclnt.AllMessages, - ) -) - -var HandlerVersion = vpp.HandlerVersion{ - Version: vpp1904.Version, - Check: vpp.MessageCheck( - vpe.AllMessages, - memclnt.AllMessages, - ), - NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI { - return NewVpeHandler(c) - }, -}*/ - func init() { msgs := vpp.Messages( vpe.AllMessages, diff --git a/plugins/govppmux/vppcalls/vpp_handler_api.go b/plugins/govppmux/vppcalls/vpp_handler_api.go index f4a2ac9a74..e209b42786 100644 --- a/plugins/govppmux/vppcalls/vpp_handler_api.go +++ b/plugins/govppmux/vppcalls/vpp_handler_api.go @@ -19,6 +19,7 @@ import ( "fmt" govppapi "git.fd.io/govpp.git/api" + "github.com/ligato/cn-infra/logging" "go.ligato.io/vpp-agent/v2/plugins/vpp" ) @@ -87,14 +88,15 @@ func (p PluginInfo) String() string { } var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ - Name: "vppcore", + Name: "core", HandlerAPI: (*VppCoreAPI)(nil), + NewFunc: (*NewHandlerFunc)(nil), }) type NewHandlerFunc func(govppapi.Channel) VppCoreAPI // AddVersion registers vppcalls Handler for the given version. -func AddVersion(version string, msgs []govppapi.Message, h NewHandlerFunc) { +func AddVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { Handler.AddVersion(vpp.HandlerVersion{ Version: version, Check: func(c vpp.Client) error { @@ -107,13 +109,27 @@ func AddVersion(version string, msgs []govppapi.Message, h NewHandlerFunc) { } return h(ch) }, + New: h, }) } -// CompatibleHandler is helper for returning comptabile Handler. +func NewHandler(c vpp.Client) (VppCoreAPI, error) { + v, err := Handler.GetCompatibleVersion(c) + if err != nil { + return nil, err + } + ch, err := c.NewAPIChannel() + if err != nil { + return nil, err + } + return v.New.(NewHandlerFunc)(ch), nil +} + +// CompatibleHandler is helper for returning compatible Handler. func CompatibleHandler(c vpp.Client) VppCoreAPI { - if v := Handler.FindCompatibleVersion(c); v != nil { - return v.NewHandler(c).(VppCoreAPI) + v, err := NewHandler(c) + if err != nil { + logging.Warn(err) } - return nil + return v } diff --git a/plugins/kvscheduler/internal/graph/graph_api.go b/plugins/kvscheduler/internal/graph/graph_api.go index 2f7dd31feb..613a92c523 100644 --- a/plugins/kvscheduler/internal/graph/graph_api.go +++ b/plugins/kvscheduler/internal/graph/graph_api.go @@ -21,8 +21,8 @@ import ( "time" "github.com/golang/protobuf/proto" - "github.com/ligato/cn-infra/idxmap" + . "go.ligato.io/vpp-agent/v2/plugins/kvscheduler/api" "go.ligato.io/vpp-agent/v2/plugins/kvscheduler/internal/utils" ) @@ -144,7 +144,7 @@ type Node interface { // GetLabel returns the label associated with this node. GetLabel() string - // GetKey returns the value associated with the node. + // GetValue returns the value associated with the node. GetValue() proto.Message // GetFlag returns reference to the given flag or nil if the node doesn't have diff --git a/plugins/linux/ifplugin/descriptor/interface.go b/plugins/linux/ifplugin/descriptor/interface.go index 3fb0a643ef..a083538d97 100644 --- a/plugins/linux/ifplugin/descriptor/interface.go +++ b/plugins/linux/ifplugin/descriptor/interface.go @@ -337,7 +337,7 @@ func (d *InterfaceDescriptor) Create(key string, linuxIf *interfaces.Interface) return nil, ErrUnsupportedLinuxInterfaceType } if err != nil { - d.log.Errorf("creating interface failed: %+v", err) + d.log.Errorf("creating %v interface failed: %+v", linuxIf.GetType(), err) return nil, err } diff --git a/plugins/linux/ifplugin/linuxcalls/link_linuxcalls.go b/plugins/linux/ifplugin/linuxcalls/link_linuxcalls.go index 52217fc40e..fbf8d84e4e 100644 --- a/plugins/linux/ifplugin/linuxcalls/link_linuxcalls.go +++ b/plugins/linux/ifplugin/linuxcalls/link_linuxcalls.go @@ -28,7 +28,7 @@ import ( func (h *NetLinkHandler) GetLinkByName(ifName string) (netlink.Link, error) { link, err := netlink.LinkByName(ifName) if err != nil { - return nil, errors.Wrapf(err, "LinkByName %s", ifName) + return nil, errors.Wrapf(err, "LinkByName %q", ifName) } return link, nil } diff --git a/plugins/restapi/handlers.go b/plugins/restapi/handlers.go index 6dd2b652fb..0357c17fe0 100644 --- a/plugins/restapi/handlers.go +++ b/plugins/restapi/handlers.go @@ -27,7 +27,6 @@ import ( "github.com/unrolled/render" "go.ligato.io/vpp-agent/v2/plugins/configurator" - "go.ligato.io/vpp-agent/v2/plugins/govppmux" "go.ligato.io/vpp-agent/v2/plugins/restapi/resturl" interfaces "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/interfaces" ) @@ -241,17 +240,10 @@ func (p *Plugin) registerTelemetryHandlers() { p.HTTPHandlers.RegisterHTTPHandler(resturl.TNodeCount, p.telemetryNodeCountHandler, GET) } -// Registers Tracer handler func (p *Plugin) registerStatsHandler() { - p.HTTPHandlers.RegisterHTTPHandler(resturl.Tracer, p.tracerHandler, GET) p.HTTPHandlers.RegisterHTTPHandler(resturl.ConfiguratorStats, p.configuratorStatsHandler, GET) } -// Registers command handler -func (p *Plugin) registerCommandHandler() { - p.HTTPHandlers.RegisterHTTPHandler(resturl.Command, p.commandHandler, POST) -} - // Registers index page func (p *Plugin) registerIndexHandlers() { r := render.New(render.Options{ @@ -259,7 +251,6 @@ func (p *Plugin) registerIndexHandlers() { Asset: Asset, AssetNames: AssetNames, }) - handlerFunc := func(formatter *render.Render) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { @@ -267,7 +258,7 @@ func (p *Plugin) registerIndexHandlers() { p.logError(r.HTML(w, http.StatusOK, "index", p.index)) } } - p.HTTPHandlers.RegisterHTTPHandler(resturl.Index, handlerFunc, GET) + p.HTTPHandlers.RegisterHTTPHandler("/", handlerFunc, GET) } // registerHTTPHandler is common register method for all handlers @@ -414,19 +405,6 @@ func (p *Plugin) telemetryNodeCountHandler(formatter *render.Render) http.Handle } } -// tracerHandler - returns binary API call trace -func (p *Plugin) tracerHandler(formatter *render.Render) http.HandlerFunc { - return func(w http.ResponseWriter, req *http.Request) { - entries := govppmux.GetStats() - if entries == nil { - p.logError(formatter.JSON(w, http.StatusOK, "VPP api trace is disabled")) - return - } - - p.logError(formatter.JSON(w, http.StatusOK, entries)) - } -} - // configuratorStatsHandler - returns stats for Configurator func (p *Plugin) configuratorStatsHandler(formatter *render.Render) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { diff --git a/plugins/restapi/plugin_restapi.go b/plugins/restapi/plugin_restapi.go index d28c62a188..19afc9ab1c 100644 --- a/plugins/restapi/plugin_restapi.go +++ b/plugins/restapi/plugin_restapi.go @@ -15,23 +15,21 @@ package restapi import ( + "fmt" "net/http" "sync" - "github.com/ligato/cn-infra/servicelabel" - "go.ligato.io/vpp-agent/v2/plugins/linux/nsplugin" - - "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/infra" "github.com/ligato/cn-infra/rpc/rest" access "github.com/ligato/cn-infra/rpc/rest/security/model/access-security" - "github.com/ligato/cn-infra/utils/safeclose" + "github.com/ligato/cn-infra/servicelabel" "go.ligato.io/vpp-agent/v2/plugins/govppmux" vpevppcalls "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls" linuxifplugin "go.ligato.io/vpp-agent/v2/plugins/linux/ifplugin" iflinuxcalls "go.ligato.io/vpp-agent/v2/plugins/linux/ifplugin/linuxcalls" l3linuxcalls "go.ligato.io/vpp-agent/v2/plugins/linux/l3plugin/linuxcalls" + "go.ligato.io/vpp-agent/v2/plugins/linux/nsplugin" "go.ligato.io/vpp-agent/v2/plugins/netalloc" "go.ligato.io/vpp-agent/v2/plugins/restapi/resturl" telemetryvppcalls "go.ligato.io/vpp-agent/v2/plugins/telemetry/vppcalls" @@ -65,9 +63,6 @@ type Plugin struct { // Index page index *index - // Channels - vppChan api.Channel - // Handlers vpeHandler vpevppcalls.VppCoreAPI teleHandler telemetryvppcalls.TelemetryVppAPI @@ -115,11 +110,6 @@ type indexItem struct { // Init initializes the Rest Plugin func (p *Plugin) Init() (err error) { - // VPP channels - if p.vppChan, err = p.VPP.NewAPIChannel(); err != nil { - return err - } - // VPP Indexes ifIndexes := p.VPPIfPlugin.GetInterfaceIndex() bdIndexes := p.VPPL2Plugin.GetBDIndex() @@ -131,9 +121,11 @@ func (p *Plugin) Init() (err error) { linuxIfIndexes := p.LinuxIfPlugin.GetInterfaceIndex() // Initialize VPP handlers - p.vpeHandler = vpevppcalls.CompatibleHandler(p.VPP) - if p.vpeHandler == nil { - p.Log.Info("VPP main handler is not available, it will be skipped") + p.vpeHandler, err = vpevppcalls.NewHandler(p.VPP) + if err != nil { + return fmt.Errorf("VPP core handler error: %w", err) + } else if p.vpeHandler == nil { + p.Log.Info("VPP core handler is not available, it will be skipped") } p.teleHandler = telemetryvppcalls.CompatibleTelemetryHandler(p.VPP) if p.teleHandler == nil { @@ -145,15 +137,15 @@ func (p *Plugin) Init() (err error) { if p.ifHandler == nil { p.Log.Info("VPP Interface handler is not available, it will be skipped") } - p.l2Handler = l2vppcalls.CompatibleL2VppHandler(p.vppChan, ifIndexes, bdIndexes, p.Log) + p.l2Handler = l2vppcalls.CompatibleL2VppHandler(p.VPP, ifIndexes, bdIndexes, p.Log) if p.l2Handler == nil { p.Log.Info("VPP L2 handler is not available, it will be skipped") } - p.l3Handler = l3vppcalls.CompatibleL3VppHandler(p.vppChan, ifIndexes, vrfIndexes, p.AddrAlloc, p.Log) + p.l3Handler = l3vppcalls.CompatibleL3VppHandler(p.VPP, ifIndexes, vrfIndexes, p.AddrAlloc, p.Log) if p.l3Handler == nil { p.Log.Info("VPP L3 handler is not available, it will be skipped") } - p.ipSecHandler = ipsecvppcalls.CompatibleIPSecVppHandler(p.vppChan, ifIndexes, p.Log) + p.ipSecHandler = ipsecvppcalls.CompatibleIPSecVppHandler(p.VPP, ifIndexes, p.Log) if p.ipSecHandler == nil { p.Log.Info("VPP IPSec handler is not available, it will be skipped") } @@ -171,7 +163,7 @@ func (p *Plugin) Init() (err error) { if p.natHandler == nil { p.Log.Infof("NAT handler is not available, it will be skipped") } - p.puntHandler = puntvppcalls.CompatiblePuntVppHandler(p.vppChan, ifIndexes, p.Log) + p.puntHandler = puntvppcalls.CompatiblePuntVppHandler(p.VPP, ifIndexes, p.Log) if p.puntHandler == nil { p.Log.Infof("Punt handler is not available, it will be skipped") } @@ -195,34 +187,28 @@ func (p *Plugin) Init() (err error) { func (p *Plugin) AfterInit() (err error) { // VPP handlers p.registerTelemetryHandlers() - p.registerCommandHandler() - // core p.registerInterfaceHandlers() p.registerL2Handlers() p.registerL3Handlers() p.registerIPSecHandlers() - // plugins p.registerABFHandler() p.registerACLHandlers() p.registerNATHandlers() p.registerPuntHandlers() - // Linux handlers p.registerLinuxInterfaceHandlers() p.registerLinuxL3Handlers() - // Index and stats handlers p.registerIndexHandlers() p.registerStatsHandler() - return nil } // Close is used to clean up resources used by Plugin -func (p *Plugin) Close() (err error) { - return safeclose.Close(p.vppChan) +func (p *Plugin) Close() error { + return nil } // Fill index item lists @@ -259,7 +245,6 @@ func getIndexPageItems() map[string][]indexItem { {Name: "Node count", Path: resturl.TNodeCount}, }, "Stats": { - {Name: "VPP Binary API", Path: resturl.Tracer}, {Name: "Configurator Stats", Path: resturl.ConfiguratorStats}, }, } @@ -272,15 +257,14 @@ func getPermissionsGroups() []*access.PermissionGroup { tracerPg := &access.PermissionGroup{ Name: "stats", Permissions: []*access.PermissionGroup_Permissions{ - newPermission(resturl.Index, GET), - newPermission(resturl.Tracer, GET), + newPermission("/", GET), newPermission(resturl.ConfiguratorStats, GET), }, } telemetryPg := &access.PermissionGroup{ Name: "telemetry", Permissions: []*access.PermissionGroup_Permissions{ - newPermission(resturl.Index, GET), + newPermission("/", GET), newPermission(resturl.Telemetry, GET), newPermission(resturl.TMemory, GET), newPermission(resturl.TRuntime, GET), @@ -290,7 +274,7 @@ func getPermissionsGroups() []*access.PermissionGroup { dumpPg := &access.PermissionGroup{ Name: "dump", Permissions: []*access.PermissionGroup_Permissions{ - newPermission(resturl.Index, GET), + newPermission("/", GET), newPermission(resturl.ABF, GET), newPermission(resturl.ACLIP, GET), newPermission(resturl.ACLMACIP, GET), diff --git a/plugins/restapi/resturl/urls.go b/plugins/restapi/resturl/urls.go index f213f28956..10d13a57f3 100644 --- a/plugins/restapi/resturl/urls.go +++ b/plugins/restapi/resturl/urls.go @@ -107,12 +107,6 @@ const ( PuntSocket = "/dump/vpp/v2/punt/sockets" ) -// Command -const ( - // Command allows to put CLI command to the rest - Command = "/vpp/command" -) - // Telemetry const ( // Telemetry reads various types of metrics data from the VPP @@ -124,16 +118,8 @@ const ( // Stats const ( - // Traced binary API calls - Tracer = "/vpp/binapitrace" // Configurator stats ConfiguratorStats = "/stats/configurator" // Linux interface stats LinuxInterfaceStats = "/stats/linux/interfaces" ) - -// Index -const ( - // Index can be used to get the full index page - Index = "/" -) diff --git a/plugins/telemetry/telemetry.go b/plugins/telemetry/telemetry.go index 14c536eaf8..9bc969d341 100644 --- a/plugins/telemetry/telemetry.go +++ b/plugins/telemetry/telemetry.go @@ -29,6 +29,7 @@ import ( prom "github.com/ligato/cn-infra/rpc/prometheus" "github.com/ligato/cn-infra/rpc/rest" "github.com/ligato/cn-infra/servicelabel" + "github.com/pkg/errors" "github.com/unrolled/render" "go.ligato.io/vpp-agent/v2/pkg/metrics" @@ -125,7 +126,7 @@ func (p *Plugin) Init() error { // Setup stats poller p.statsPollerServer.log = p.Log.NewLogger("stats-poller") if err := p.setupStatsPoller(); err != nil { - return err + return errors.WithMessage(err, "setting up stats poller failed") } if p.HTTPHandlers != nil { @@ -148,15 +149,9 @@ func (p *Plugin) AfterInit() error { } func (p *Plugin) setupStatsPoller() error { - /*vppCh, err := p.VPP.NewAPIChannel() - if err != nil { - return err - } - defer vppCh.Close()*/ - h := vppcalls.CompatibleTelemetryHandler(p.VPP) if h == nil { - return fmt.Errorf("VPP core handler not available") + return fmt.Errorf("VPP telemetry handler unavailable") } p.statsPollerServer.handler = h @@ -175,16 +170,9 @@ func (p *Plugin) Close() error { } func (p *Plugin) startPeriodicUpdates() { - /*vppCh, err := p.VPP.NewAPIChannel() - if err != nil { - p.Log.Errorf("creating channel failed: %v", err) - return - } - defer vppCh.Close()*/ - p.handler = vppcalls.CompatibleTelemetryHandler(p.VPP) if p.handler == nil { - p.Log.Warnf("no compatible telemetry handler, skipping periodic updates") + p.Log.Warnf("VPP telemetry handler unavailable, skipping periodic updates") return } diff --git a/plugins/telemetry/vppcalls/telemetry_handler_api.go b/plugins/telemetry/vppcalls/telemetry_handler_api.go index 7fbd1d869e..8a4e41d792 100644 --- a/plugins/telemetry/vppcalls/telemetry_handler_api.go +++ b/plugins/telemetry/vppcalls/telemetry_handler_api.go @@ -19,13 +19,14 @@ import ( govppapi "git.fd.io/govpp.git/api" log "github.com/ligato/cn-infra/logging" + "go.ligato.io/vpp-agent/v2/plugins/vpp" ) var ( // FallbackToCli defines wether should telemetry handler // fallback to parsing stats from CLI output. - FallbackToCli = true + FallbackToCli = false ) // TelemetryVppAPI provides API for retrieving telemetry data from VPP. @@ -66,7 +67,7 @@ type MemoryThread struct { PageSize uint64 `json:"page_size"` } -// NodeErrorCounterInfo contains node counters info. +// NodeCounterInfo contains node counters info. type NodeCounterInfo struct { Counters []NodeCounter `json:"counters"` } @@ -160,7 +161,7 @@ var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ type NewHandlerFunc func(govppapi.Channel) TelemetryVppAPI // AddHandlerVersion registers vppcalls Handler for the given version. -func AddHandlerVersion(version string, msgs []govppapi.Message, h NewHandlerFunc) { +func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { Handler.AddVersion(vpp.HandlerVersion{ Version: version, Check: func(c vpp.Client) error { @@ -176,49 +177,34 @@ func AddHandlerVersion(version string, msgs []govppapi.Message, h NewHandlerFunc }) } -func CompatibleTelemetryHandler(c vpp.Client) TelemetryVppAPI { +func NewHandler(c vpp.Client) (TelemetryVppAPI, error) { // Prefer using VPP stats API. - if c.StatsConnected() { - return NewTelemetryVppStats(c.Stats()) + if stats := c.Stats(); stats != nil { + return NewTelemetryVppStats(stats), nil } - if !FallbackToCli { - log.Warnf("stats unavailable and fallback to CLI disabled for telemetry") - return nil + v, err := Handler.GetCompatibleVersion(c) + if err != nil { + return nil, err } - - /*ctx := context.TODO() ch, err := c.NewAPIChannel() if err != nil { - log.Warnf("failed to create API channel: %v", err) - return nil + return nil, err } - vpe := vppcalls.CompatibleHandler(c) - info, err := vpe.GetVersion(ctx) - if err != nil { - log.Warnf("retrieving VPP info failed: %v", err) - return nil - } - if ver := info.Release(); ver != "" { - log.Debug("telemetry checking release: ", ver) - if h, ok := Versions[ver]; ok { - if err := ch.CheckCompatiblity(h.Msgs...); err != nil { - log.Debugf("telemetry version %s not compatible: %v", ver, err) - } - log.Debug("telemetry found compatible release: ", ver) - return h.New(ch) - } + return v.New.(NewHandlerFunc)(ch), nil +} + +func CompatibleTelemetryHandler(c vpp.Client) TelemetryVppAPI { + // Prefer using VPP stats API. + if stats := c.Stats(); stats != nil { + return NewTelemetryVppStats(stats) } - for ver, h := range Versions { - if err := ch.CheckCompatiblity(h.Msgs...); err != nil { - log.Debugf("version %s not compatible: %v", ver, err) - continue + if FallbackToCli { + if v := Handler.FindCompatibleVersion(c); v != nil { + log.Info("falling back to parsing CLI output for telemetry") + return v.NewHandler(c).(TelemetryVppAPI) } - log.Debug("found compatible version: ", ver) - return h.New(ch) - }*/ - if v := Handler.FindCompatibleVersion(c); v != nil { - return v.NewHandler(c).(TelemetryVppAPI) + // no compatible version found } - // no compatible version found + log.Warnf("stats connection not available for telemetry") return nil } diff --git a/plugins/telemetry/vppcalls/vpp1904/telemetry_vppcalls_test.go b/plugins/telemetry/vppcalls/vpp1904/telemetry_vppcalls_test.go index cc0631abf8..e89d22a472 100644 --- a/plugins/telemetry/vppcalls/vpp1904/telemetry_vppcalls_test.go +++ b/plugins/telemetry/vppcalls/vpp1904/telemetry_vppcalls_test.go @@ -19,10 +19,11 @@ import ( "testing" . "github.com/onsi/gomega" + "go.ligato.io/vpp-agent/v2/plugins/telemetry/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/telemetry/vppcalls/vpp1904" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestGetBuffers(t *testing.T) { @@ -499,8 +500,8 @@ func TestGetNodeCounters(t *testing.T) { }))*/ } -func testSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.TelemetryVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func testSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.TelemetryVppAPI) { + ctx := vppmock.SetupTestCtx(t) handler := vpp1904.NewTelemetryVppHandler(ctx.MockChannel) return ctx, handler } diff --git a/plugins/telemetry/vppcalls/vpp1908/telemetry_vppcalls_test.go b/plugins/telemetry/vppcalls/vpp1908/telemetry_vppcalls_test.go index 33d928702d..dfbc29d979 100644 --- a/plugins/telemetry/vppcalls/vpp1908/telemetry_vppcalls_test.go +++ b/plugins/telemetry/vppcalls/vpp1908/telemetry_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/telemetry/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/telemetry/vppcalls/vpp1908" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestGetBuffers(t *testing.T) { @@ -521,8 +521,8 @@ func TestGetNodeCounters(t *testing.T) { }))*/ } -func testSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.TelemetryVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func testSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.TelemetryVppAPI) { + ctx := vppmock.SetupTestCtx(t) handler := vpp1908.NewTelemetryVppHandler(ctx.MockChannel) return ctx, handler } diff --git a/plugins/telemetry/vppcalls/vpp2001/telemetry_vppcalls_test.go b/plugins/telemetry/vppcalls/vpp2001/telemetry_vppcalls_test.go index cff3211eb5..d3eeffa6f7 100644 --- a/plugins/telemetry/vppcalls/vpp2001/telemetry_vppcalls_test.go +++ b/plugins/telemetry/vppcalls/vpp2001/telemetry_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/telemetry/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/telemetry/vppcalls/vpp2001" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestGetBuffers(t *testing.T) { @@ -500,8 +500,8 @@ func TestGetNodeCounters(t *testing.T) { })) } -func testSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.TelemetryVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func testSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.TelemetryVppAPI) { + ctx := vppmock.SetupTestCtx(t) handler := vpp2001.NewTelemetryVppHandler(ctx.MockChannel) return ctx, handler } diff --git a/plugins/telemetry/vppcalls/vpp2001_324/telemetry_vppcalls_test.go b/plugins/telemetry/vppcalls/vpp2001_324/telemetry_vppcalls_test.go index 7ee64251c2..d2ab364b8c 100644 --- a/plugins/telemetry/vppcalls/vpp2001_324/telemetry_vppcalls_test.go +++ b/plugins/telemetry/vppcalls/vpp2001_324/telemetry_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/telemetry/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/telemetry/vppcalls/vpp2001_324" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestGetBuffers(t *testing.T) { @@ -500,8 +500,8 @@ func TestGetNodeCounters(t *testing.T) { })) } -func testSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.TelemetryVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func testSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.TelemetryVppAPI) { + ctx := vppmock.SetupTestCtx(t) handler := vpp2001_324.NewTelemetryVppHandler(ctx.MockChannel) return ctx, handler } diff --git a/plugins/vpp/abfplugin/vppcalls/abf_api.go b/plugins/vpp/abfplugin/vppcalls/abf_vppcalls_api.go similarity index 97% rename from plugins/vpp/abfplugin/vppcalls/abf_api.go rename to plugins/vpp/abfplugin/vppcalls/abf_vppcalls_api.go index 3e008e95f4..7053b4dbd8 100644 --- a/plugins/vpp/abfplugin/vppcalls/abf_api.go +++ b/plugins/vpp/abfplugin/vppcalls/abf_vppcalls_api.go @@ -68,7 +68,7 @@ var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ type NewHandlerFunc func(ch govppapi.Channel, aclIdx aclidx.ACLMetadataIndex, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) ABFVppAPI -func AddABFHandlerVersion(version string, msgs []govppapi.Message, h NewHandlerFunc) { +func AddABFHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { Handler.AddVersion(vpp.HandlerVersion{ Version: version, Check: func(c vpp.Client) error { diff --git a/plugins/vpp/abfplugin/vppcalls/vpp1904/abf_vppcalls_test.go b/plugins/vpp/abfplugin/vppcalls/vpp1904/abf_vppcalls_test.go index 9d8c5549dd..5ae553c562 100644 --- a/plugins/vpp/abfplugin/vppcalls/vpp1904/abf_vppcalls_test.go +++ b/plugins/vpp/abfplugin/vppcalls/vpp1904/abf_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/aclplugin/aclidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/abf" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" vpp_abf "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/abf" ) @@ -266,8 +266,8 @@ func TestDetachABFInterfaceIPv6Error(t *testing.T) { Expect(err).ToNot(BeNil()) } -func abfTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.ABFVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func abfTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.ABFVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") aclIdx := aclidx.NewACLIndex(log, "acl-index") ifIdx := ifaceidx.NewIfaceIndex(log, "if-index") diff --git a/plugins/vpp/abfplugin/vppcalls/vpp1908/abf_vppcalls_test.go b/plugins/vpp/abfplugin/vppcalls/vpp1908/abf_vppcalls_test.go index 8a2a55869a..924d392de1 100644 --- a/plugins/vpp/abfplugin/vppcalls/vpp1908/abf_vppcalls_test.go +++ b/plugins/vpp/abfplugin/vppcalls/vpp1908/abf_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/aclplugin/aclidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/abf" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" vpp_abf "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/abf" ) @@ -266,8 +266,8 @@ func TestDetachABFInterfaceIPv6Error(t *testing.T) { Expect(err).ToNot(BeNil()) } -func abfTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.ABFVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func abfTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.ABFVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") aclIdx := aclidx.NewACLIndex(log, "acl-index") ifIdx := ifaceidx.NewIfaceIndex(log, "if-index") diff --git a/plugins/vpp/abfplugin/vppcalls/vpp2001/abf_vppcalls_test.go b/plugins/vpp/abfplugin/vppcalls/vpp2001/abf_vppcalls_test.go index de765c4ae7..775fa1455e 100644 --- a/plugins/vpp/abfplugin/vppcalls/vpp2001/abf_vppcalls_test.go +++ b/plugins/vpp/abfplugin/vppcalls/vpp2001/abf_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/aclplugin/aclidx" vpp_abf "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/abf" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" abf "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/abf" ) @@ -266,8 +266,8 @@ func TestDetachABFInterfaceIPv6Error(t *testing.T) { Expect(err).ToNot(BeNil()) } -func abfTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.ABFVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func abfTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.ABFVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") aclIdx := aclidx.NewACLIndex(log, "acl-index") ifIdx := ifaceidx.NewIfaceIndex(log, "if-index") diff --git a/plugins/vpp/abfplugin/vppcalls/vpp2001_324/abf_vppcalls_test.go b/plugins/vpp/abfplugin/vppcalls/vpp2001_324/abf_vppcalls_test.go index 5f5901482a..198361406e 100644 --- a/plugins/vpp/abfplugin/vppcalls/vpp2001_324/abf_vppcalls_test.go +++ b/plugins/vpp/abfplugin/vppcalls/vpp2001_324/abf_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/aclplugin/aclidx" vpp_abf "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/abf" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" abf "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/abf" ) @@ -266,8 +266,8 @@ func TestDetachABFInterfaceIPv6Error(t *testing.T) { Expect(err).ToNot(BeNil()) } -func abfTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.ABFVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func abfTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.ABFVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") aclIdx := aclidx.NewACLIndex(log, "acl-index") ifIdx := ifaceidx.NewIfaceIndex(log, "if-index") diff --git a/plugins/vpp/aclplugin/vppcalls/acl_vppcalls_api.go b/plugins/vpp/aclplugin/vppcalls/acl_vppcalls_api.go index 375399ac95..7c9dd1d058 100644 --- a/plugins/vpp/aclplugin/vppcalls/acl_vppcalls_api.go +++ b/plugins/vpp/aclplugin/vppcalls/acl_vppcalls_api.go @@ -60,7 +60,7 @@ type ACLVppAPI interface { AddMACIPACL(rules []*acl.ACL_Rule, aclName string) (aclIdx uint32, err error) // ModifyACL modifies ACL (L3/L4) by updating its rules. It uses ACL index to identify ACL. ModifyACL(aclIdx uint32, rules []*acl.ACL_Rule, aclName string) error - // ModifyACL modifies MACIP ACL (L2) by updating its rules. It uses ACL index to identify ACL. + // ModifyMACIPACL modifies MACIP ACL (L2) by updating its rules. It uses ACL index to identify ACL. ModifyMACIPACL(aclIdx uint32, rules []*acl.ACL_Rule, aclName string) error // DeleteACL removes ACL (L3/L4). DeleteACL(aclIdx uint32) error @@ -102,7 +102,7 @@ type ACLVppRead interface { DumpACLInterfaces(indices []uint32) (map[uint32]*acl.ACL_Interfaces, error) // DumpMACIPACLInterfaces dumps all ACLs (L2) for given ACL indexes. Returns map of MACIP ACL indexes with assigned interfaces. DumpMACIPACLInterfaces(indices []uint32) (map[uint32]*acl.ACL_Interfaces, error) - // DumpInterfaceAcls finds interface in VPP and returns its ACL (L3/L4) configuration. + // DumpInterfaceACLs finds interface in VPP and returns its ACL (L3/L4) configuration. DumpInterfaceACLs(ifIdx uint32) ([]*acl.ACL, error) // DumpInterfaceMACIPACLs finds interface in VPP and returns its MACIP ACL (L2) configuration. DumpInterfaceMACIPACLs(ifIdx uint32) ([]*acl.ACL, error) @@ -115,7 +115,7 @@ var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ type NewHandlerFunc func(c vpp.Client, ifIdx ifaceidx.IfaceMetadataIndex) ACLVppAPI -func AddHandlerVersion(version string, msgs []govppapi.Message, h NewHandlerFunc) { +func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { Handler.AddVersion(vpp.HandlerVersion{ Version: version, Check: func(c vpp.Client) error { diff --git a/plugins/vpp/aclplugin/vppcalls/vpp1904/acl_vppcalls_test.go b/plugins/vpp/aclplugin/vppcalls/vpp1904/acl_vppcalls_test.go index 3284ba0bb8..907e33bed0 100644 --- a/plugins/vpp/aclplugin/vppcalls/vpp1904/acl_vppcalls_test.go +++ b/plugins/vpp/aclplugin/vppcalls/vpp1904/acl_vppcalls_test.go @@ -21,7 +21,7 @@ import ( . "github.com/onsi/gomega" acl_api "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/acl" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" acl "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/acl" ) @@ -226,13 +226,13 @@ var aclMACIPrules = []*acl.ACL_Rule{ } type testCtx struct { - *vppcallmock.TestCtx + *vppmock.TestCtx aclHandler *ACLVppHandler ifIndexes ifaceidx.IfaceMetadataIndexRW } func setupACLTest(t *testing.T) *testCtx { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) ifaceIdx := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") aclHandler := NewACLVppHandler(ctx.MockVPPClient, ifaceIdx).(*ACLVppHandler) diff --git a/plugins/vpp/aclplugin/vppcalls/vpp1908/acl_vppcalls_test.go b/plugins/vpp/aclplugin/vppcalls/vpp1908/acl_vppcalls_test.go index 8195eb0ed8..2612540838 100644 --- a/plugins/vpp/aclplugin/vppcalls/vpp1908/acl_vppcalls_test.go +++ b/plugins/vpp/aclplugin/vppcalls/vpp1908/acl_vppcalls_test.go @@ -21,7 +21,7 @@ import ( . "github.com/onsi/gomega" acl_api "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/acl" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" acl "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/acl" ) @@ -226,13 +226,13 @@ var aclMACIPrules = []*acl.ACL_Rule{ } type testCtx struct { - *vppcallmock.TestCtx + *vppmock.TestCtx aclHandler *ACLVppHandler ifIndexes ifaceidx.IfaceMetadataIndexRW } func setupACLTest(t *testing.T) *testCtx { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) ifaceIdx := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") aclHandler := NewACLVppHandler(ctx.MockVPPClient, ifaceIdx).(*ACLVppHandler) diff --git a/plugins/vpp/aclplugin/vppcalls/vpp2001/acl_vppcalls_test.go b/plugins/vpp/aclplugin/vppcalls/vpp2001/acl_vppcalls_test.go index 9b5b80e0b0..9236960252 100644 --- a/plugins/vpp/aclplugin/vppcalls/vpp2001/acl_vppcalls_test.go +++ b/plugins/vpp/aclplugin/vppcalls/vpp2001/acl_vppcalls_test.go @@ -21,7 +21,7 @@ import ( . "github.com/onsi/gomega" vpp_acl "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/acl" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" acl "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/acl" ) @@ -226,13 +226,13 @@ var aclMACIPrules = []*acl.ACL_Rule{ } type testCtx struct { - *vppcallmock.TestCtx + *vppmock.TestCtx aclHandler *ACLVppHandler ifIndexes ifaceidx.IfaceMetadataIndexRW } func setupACLTest(t *testing.T) *testCtx { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) ifaceIdx := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") aclHandler := NewACLVppHandler(ctx.MockVPPClient, ifaceIdx).(*ACLVppHandler) diff --git a/plugins/vpp/aclplugin/vppcalls/vpp2001/vppcalls_handlers.go b/plugins/vpp/aclplugin/vppcalls/vpp2001/vppcalls_handlers.go index dc5c354dbd..76d15bf7bd 100644 --- a/plugins/vpp/aclplugin/vppcalls/vpp2001/vppcalls_handlers.go +++ b/plugins/vpp/aclplugin/vppcalls/vpp2001/vppcalls_handlers.go @@ -16,8 +16,8 @@ package vpp2001 import ( govppapi "git.fd.io/govpp.git/api" - "go.ligato.io/vpp-agent/v2/plugins/vpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp" "go.ligato.io/vpp-agent/v2/plugins/vpp/aclplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/acl" diff --git a/plugins/vpp/aclplugin/vppcalls/vpp2001_324/acl_vppcalls_test.go b/plugins/vpp/aclplugin/vppcalls/vpp2001_324/acl_vppcalls_test.go index 9baa8aedeb..ccd680ae3e 100644 --- a/plugins/vpp/aclplugin/vppcalls/vpp2001_324/acl_vppcalls_test.go +++ b/plugins/vpp/aclplugin/vppcalls/vpp2001_324/acl_vppcalls_test.go @@ -21,7 +21,7 @@ import ( . "github.com/onsi/gomega" vpp_acl "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/acl" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" acl "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/acl" ) @@ -226,13 +226,13 @@ var aclMACIPrules = []*acl.ACL_Rule{ } type testCtx struct { - *vppcallmock.TestCtx + *vppmock.TestCtx aclHandler *ACLVppHandler ifIndexes ifaceidx.IfaceMetadataIndexRW } func setupACLTest(t *testing.T) *testCtx { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) ifaceIdx := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") aclHandler := NewACLVppHandler(ctx.MockVPPClient, ifaceIdx).(*ACLVppHandler) diff --git a/plugins/vpp/binapi/binapi.go b/plugins/vpp/binapi/binapi.go new file mode 100644 index 0000000000..d74de7da8d --- /dev/null +++ b/plugins/vpp/binapi/binapi.go @@ -0,0 +1,51 @@ +// Copyright (c) 2019 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package binapi + +import ( + govppapi "git.fd.io/govpp.git/api" +) + +// Version represents VPP version for generated binapi. +type Version string + +// Versions is a map of all binapi messages for each supported VPP versions. +var Versions = map[Version]MessagesList{} + +// MessagesList aggregates multiple funcs that return messages. +type MessagesList []func() []govppapi.Message + +// Messages is used to initialize message list. +func Messages(funcs ...func() []govppapi.Message) MessagesList { + var list MessagesList + list.Add(funcs...) + return list +} + +// Add adds funcs to message list. +func (list *MessagesList) Add(funcs ...func() []govppapi.Message) { + for _, msgFunc := range funcs { + *list = append(*list, msgFunc) + } +} + +// AllMessages returns messages from message list funcs combined. +func (list *MessagesList) AllMessages() []govppapi.Message { + var msgs []govppapi.Message + for _, msgFunc := range *list { + msgs = append(msgs, msgFunc()...) + } + return msgs +} diff --git a/plugins/vpp/binapi/vpp1904/vpp1904.go b/plugins/vpp/binapi/vpp1904/vpp1904.go index a216f719a7..46a9d4f836 100644 --- a/plugins/vpp/binapi/vpp1904/vpp1904.go +++ b/plugins/vpp/binapi/vpp1904/vpp1904.go @@ -14,8 +14,40 @@ package vpp1904 +import ( + "go.ligato.io/vpp-agent/v2/plugins/vpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/abf" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/acl" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/af_packet" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/bond" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/dhcp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/gre" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/gtpu" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/interfaces" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/ip" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/ipsec" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/l2" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/memclnt" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/memif" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/nat" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/punt" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/span" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/sr" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/stn" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/tapv2" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vmxnet3" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vpe" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vxlan" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vxlan_gpe" +) + // Version is used to identify VPP binapi version -const Version = "19.04" +const Version = "19.04.2" + +func init() { + binapi.Versions[Version] = Messages +} //go:generate -command binapigen binapi-generator --output-dir=. @@ -37,8 +69,35 @@ const Version = "19.04" //go:generate binapigen --input-file=$VPP_API_DIR/core/vxlan_gpe.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/abf.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/acl.api.json +//go:generate binapigen --input-file=$VPP_API_DIR/plugins/gtpu.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/memif.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/nat.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/stn.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/vmxnet3.api.json -//go:generate binapigen --input-file=$VPP_API_DIR/plugins/gtpu.api.json + +// Messages is list of functions that return all messages for this version. +var Messages = vpp.Messages( + af_packet.AllMessages, + bond.AllMessages, + dhcp.AllMessages, + gre.AllMessages, + interfaces.AllMessages, + ip.AllMessages, + ipsec.AllMessages, + l2.AllMessages, + memclnt.AllMessages, + punt.AllMessages, + span.AllMessages, + sr.AllMessages, + tapv2.AllMessages, + vpe.AllMessages, + vxlan.AllMessages, + vxlan_gpe.AllMessages, + abf.AllMessages, + acl.AllMessages, + gtpu.AllMessages, + memif.AllMessages, + nat.AllMessages, + stn.AllMessages, + vmxnet3.AllMessages, +) diff --git a/plugins/vpp/binapi/vpp1908/vpp1908.go b/plugins/vpp/binapi/vpp1908/vpp1908.go index 943b9612ae..530c639b47 100644 --- a/plugins/vpp/binapi/vpp1908/vpp1908.go +++ b/plugins/vpp/binapi/vpp1908/vpp1908.go @@ -14,8 +14,40 @@ package vpp1908 +import ( + "go.ligato.io/vpp-agent/v2/plugins/vpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/abf" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/acl" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/af_packet" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/bond" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/dhcp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/gre" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/gtpu" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/interfaces" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/ip" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/ipsec" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/l2" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/memclnt" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/memif" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/nat" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/punt" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/span" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/sr" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/stn" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/tapv2" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vmxnet3" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vpe" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vxlan" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vxlan_gpe" +) + // Version is used to identify VPP version for binapi -const Version = "19.08" +const Version = "19.08.1" + +func init() { + binapi.Versions[Version] = Messages +} //go:generate -command binapigen binapi-generator --output-dir=. @@ -37,8 +69,35 @@ const Version = "19.08" //go:generate binapigen --input-file=$VPP_API_DIR/core/vxlan_gpe.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/abf.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/acl.api.json +//go:generate binapigen --input-file=$VPP_API_DIR/plugins/gtpu.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/memif.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/nat.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/stn.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/vmxnet3.api.json -//go:generate binapigen --input-file=$VPP_API_DIR/plugins/gtpu.api.json + +// Messages is list of functions that return all messages for this version. +var Messages = vpp.Messages( + af_packet.AllMessages, + bond.AllMessages, + dhcp.AllMessages, + gre.AllMessages, + interfaces.AllMessages, + ip.AllMessages, + ipsec.AllMessages, + l2.AllMessages, + memclnt.AllMessages, + punt.AllMessages, + span.AllMessages, + sr.AllMessages, + tapv2.AllMessages, + vpe.AllMessages, + vxlan.AllMessages, + vxlan_gpe.AllMessages, + abf.AllMessages, + acl.AllMessages, + gtpu.AllMessages, + memif.AllMessages, + nat.AllMessages, + stn.AllMessages, + vmxnet3.AllMessages, +) diff --git a/plugins/vpp/binapi/vpp2001/vpp2001.go b/plugins/vpp/binapi/vpp2001/vpp2001.go index 9288731043..4e15ac1658 100644 --- a/plugins/vpp/binapi/vpp2001/vpp2001.go +++ b/plugins/vpp/binapi/vpp2001/vpp2001.go @@ -14,8 +14,40 @@ package vpp2001 +import ( + "go.ligato.io/vpp-agent/v2/plugins/vpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/abf" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/acl" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/af_packet" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/bond" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/dhcp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/gre" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/gtpu" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/interfaces" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/ip" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/ipsec" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/l2" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/memclnt" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/memif" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/nat" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/punt" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/span" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/sr" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/stn" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/tapv2" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vmxnet3" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vpe" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vxlan" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vxlan_gpe" +) + // Version is used to identify VPP binapi version -const Version = "20.01-rc0+379" +const Version = "20.01-rc0~379" + +func init() { + binapi.Versions[Version] = Messages +} //go:generate -command binapigen binapi-generator --output-dir=. @@ -36,9 +68,36 @@ const Version = "20.01-rc0+379" //go:generate binapigen --input-file=$VPP_API_DIR/core/vxlan_gpe.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/abf.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/acl.api.json +//go:generate binapigen --input-file=$VPP_API_DIR/plugins/gtpu.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/dhcp.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/memif.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/nat.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/stn.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/vmxnet3.api.json -//go:generate binapigen --input-file=$VPP_API_DIR/plugins/gtpu.api.json + +// Messages is list of functions that return all messages for this version. +var Messages = vpp.Messages( + af_packet.AllMessages, + bond.AllMessages, + dhcp.AllMessages, + gre.AllMessages, + interfaces.AllMessages, + ip.AllMessages, + ipsec.AllMessages, + l2.AllMessages, + memclnt.AllMessages, + punt.AllMessages, + span.AllMessages, + sr.AllMessages, + tapv2.AllMessages, + vpe.AllMessages, + vxlan.AllMessages, + vxlan_gpe.AllMessages, + abf.AllMessages, + acl.AllMessages, + gtpu.AllMessages, + memif.AllMessages, + nat.AllMessages, + stn.AllMessages, + vmxnet3.AllMessages, +) diff --git a/plugins/vpp/binapi/vpp2001_324/vpp2001_324.go b/plugins/vpp/binapi/vpp2001_324/vpp2001_324.go index c0929e5862..b3d3fd99eb 100644 --- a/plugins/vpp/binapi/vpp2001_324/vpp2001_324.go +++ b/plugins/vpp/binapi/vpp2001_324/vpp2001_324.go @@ -14,8 +14,40 @@ package vpp2001_324 +import ( + "go.ligato.io/vpp-agent/v2/plugins/vpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/abf" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/acl" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/af_packet" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/bond" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/dhcp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/gre" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/gtpu" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/interfaces" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/ip" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/ipsec" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/l2" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/memclnt" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/memif" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/nat" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/punt" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/span" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/sr" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/stn" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/tapv2" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vmxnet3" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vpe" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vxlan" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vxlan_gpe" +) + // Version is used to identify VPP binapi version -const Version = "20.01-rc0+324" +const Version = "20.01-rc0~324" + +func init() { + binapi.Versions[Version] = Messages +} //go:generate -command binapigen binapi-generator --output-dir=. @@ -37,8 +69,35 @@ const Version = "20.01-rc0+324" //go:generate binapigen --input-file=$VPP_API_DIR/core/vxlan_gpe.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/abf.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/acl.api.json +//go:generate binapigen --input-file=$VPP_API_DIR/plugins/gtpu.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/memif.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/nat.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/stn.api.json //go:generate binapigen --input-file=$VPP_API_DIR/plugins/vmxnet3.api.json -//go:generate binapigen --input-file=$VPP_API_DIR/plugins/gtpu.api.json + +// Messages is list of functions that return all messages for this version. +var Messages = vpp.Messages( + af_packet.AllMessages, + bond.AllMessages, + dhcp.AllMessages, + gre.AllMessages, + interfaces.AllMessages, + ip.AllMessages, + ipsec.AllMessages, + l2.AllMessages, + memclnt.AllMessages, + punt.AllMessages, + span.AllMessages, + sr.AllMessages, + tapv2.AllMessages, + vpe.AllMessages, + vxlan.AllMessages, + vxlan_gpe.AllMessages, + abf.AllMessages, + acl.AllMessages, + gtpu.AllMessages, + memif.AllMessages, + nat.AllMessages, + stn.AllMessages, + vmxnet3.AllMessages, +) diff --git a/plugins/vpp/handlers.go b/plugins/vpp/handlers.go index 71c9ef813d..aeed88760d 100644 --- a/plugins/vpp/handlers.go +++ b/plugins/vpp/handlers.go @@ -22,18 +22,12 @@ import ( "github.com/ligato/cn-infra/logging" ) -// HandlerDesc is a handler descriptor used to describe a handler for registration. -type HandlerDesc struct { - Name string - HandlerAPI interface{} - NewFunc interface{} -} - // HandlerVersion defines handler implementation for specific version used by AddVersion. type HandlerVersion struct { - Version string + Version Version Check func(Client) error NewHandler func(Client, ...interface{}) HandlerAPI + New interface{} } // HandlerAPI is an empty interface representing handler interface. @@ -42,7 +36,11 @@ type HandlerAPI interface{} // Handler is a handler for managing implementations for multiple versions. type Handler struct { desc *HandlerDesc - versions map[string]*HandlerVersion + versions map[Version]*HandlerVersion +} + +func (h *Handler) Name() string { + return h.desc.Name } // AddVersion adds handler version to a list of available versions. @@ -51,6 +49,9 @@ func (h *Handler) AddVersion(hv HandlerVersion) { if _, ok := h.versions[hv.Version]; ok { logging.Warnf("overwritting %s handler version: %s", h.desc.Name, hv.Version) } + if hv.Check == nil { + panic(fmt.Sprintf("Check not defined for %s handler version: %s", h.desc.Name, hv.Version)) + } // TODO: check if given handler version implementes handler API interface /*ht := reflect.TypeOf(h.desc.HandlerAPI).Elem() hc := reflect.TypeOf(hv.New).Out(0) @@ -60,16 +61,6 @@ func (h *Handler) AddVersion(hv HandlerVersion) { h.versions[hv.Version] = &hv } -// Versions returns list of versions from list of available handler versions. -func (h *Handler) Versions() []string { - versions := make([]string, 0, len(h.versions)) - for _, v := range h.versions { - versions = append(versions, v.Version) - } - sort.Strings(versions) - return versions -} - // FindCompatibleVersion iterates over all available handler versions and calls // their Check method to check compatibility. func (h *Handler) FindCompatibleVersion(c Client) *HandlerVersion { @@ -81,47 +72,77 @@ func (h *Handler) FindCompatibleVersion(c Client) *HandlerVersion { } // GetCompatibleVersion iterates over all available handler versions and calls -// // their Check method to check compatibility. +// their Check method to check compatibility. func (h *Handler) GetCompatibleVersion(c Client) (*HandlerVersion, error) { if len(h.versions) == 0 { logging.Debugf("VPP handler %s has no registered versions", h.desc.Name) return nil, ErrNoVersions } + // try compatible binapi version first + if ver, _ := FindCompatibleBinapi(c); ver != "" { + if v, ok := h.versions[ver]; ok { + logging.Debugf("VPP handler %s COMPATIBLE with version: %s", h.desc.Name, v.Version) + return v, nil + } + } + // fallback to checking all registered versions for _, v := range h.versions { if err := v.Check(c); err != nil { if ierr, ok := err.(*govppapi.CompatibilityError); ok { - logging.Debugf("VPP handler %s incompatible with version %s: found %d incompatible messages", + logging.Debugf("VPP handler %s incompatible with %s: %d incompatible messages", h.desc.Name, v.Version, len(ierr.IncompatibleMessages)) } else { - logging.Debugf("VPP handler %s failed check for version %s: \n%v", - h.desc.Name, v.Version, err) + logging.Debugf("VPP handler %s version %s check failed: %v", h.desc.Name, v.Version, err) } continue } - logging.Debugf("VPP handler %s compatible version: %s", h.desc.Name, v.Version) + logging.Debugf("VPP handler %s COMPATIBLE with version: %s", h.desc.Name, v.Version) return v, nil } return nil, ErrIncompatible } +// Versions returns list of versions from list of available handler versions. +func (h *Handler) Versions() []Version { + vs := make([]Version, 0, len(h.versions)) + for _, v := range h.versions { + vs = append(vs, v.Version) + } + sort.Sort(versions(vs)) + return vs +} + +type versions []Version + +func (v versions) Len() int { return len(v) } +func (v versions) Less(i, j int) bool { return v[i] < v[j] } +func (v versions) Swap(i, j int) { v[i], v[j] = v[j], v[i] } + var ( - handlers = map[string]*Handler{} + registeredHandlers = map[string]*Handler{} ) +// HandlerDesc represents a VPP handler's specification. +type HandlerDesc struct { + Name string + HandlerAPI interface{} + NewFunc interface{} +} + // RegisterHandler creates new handler described by handle descriptor. func RegisterHandler(hd HandlerDesc) *Handler { - if _, ok := handlers[hd.Name]; ok { + if _, ok := registeredHandlers[hd.Name]; ok { panic(fmt.Sprintf("VPP handler %s is already registered", hd.Name)) } h := &Handler{ desc: &hd, - versions: make(map[string]*HandlerVersion), + versions: make(map[Version]*HandlerVersion), } - handlers[hd.Name] = h + registeredHandlers[hd.Name] = h return h } // GetHandlers returns map for all registered handlers. func GetHandlers() map[string]*Handler { - return handlers + return registeredHandlers } diff --git a/plugins/vpp/handlers_test.go b/plugins/vpp/handlers_test.go new file mode 100644 index 0000000000..618ef47b2f --- /dev/null +++ b/plugins/vpp/handlers_test.go @@ -0,0 +1,78 @@ +// Copyright (c) 2019 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package vpp_test + +import ( + "testing" + + . "github.com/onsi/gomega" + + "go.ligato.io/vpp-agent/v2/plugins/vpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" +) + +type testHandlerAPI interface { + A() error +} + +type testHandler struct{} + +func (t *testHandler) A() error { + return nil +} + +func TestRegisterHandler(t *testing.T) { + c := vppmock.SetupTestCtx(t) + vpp.ClearRegisteredHandlers() + + handler := vpp.RegisterHandler(vpp.HandlerDesc{ + Name: "handlerA", + HandlerAPI: (*testHandlerAPI)(nil), + }) + + Expect(handler).ToNot(BeNil()) + Expect(handler.Versions()).To(BeEmpty()) + Expect(handler.FindCompatibleVersion(c.MockVPPClient)).To(BeNil()) +} + +func TestRegisterHandlerVersions(t *testing.T) { + c := vppmock.SetupTestCtx(t) + vpp.ClearRegisteredHandlers() + + const ( + version vpp.Version = "19.08-test" + ) + + handler := vpp.RegisterHandler(vpp.HandlerDesc{ + Name: "handlerA", + HandlerAPI: (*testHandlerAPI)(nil), + }) + handler.AddVersion(vpp.HandlerVersion{ + Version: version, + Check: func(client vpp.Client) error { + return nil + }, + NewHandler: func(client vpp.Client, i ...interface{}) vpp.HandlerAPI { + return &testHandler{} + }, + }) + + Expect(handler.Versions()).ToNot(BeEmpty()) + + ver := handler.FindCompatibleVersion(c.MockVPPClient) + Expect(ver).ToNot(BeNil()) + Expect(ver.Version).To(Equal(version)) + Expect(ver.NewHandler(c.MockVPPClient)).To(BeAssignableToTypeOf(&testHandler{})) +} diff --git a/plugins/vpp/ifplugin/vppcalls/interface_handler_api.go b/plugins/vpp/ifplugin/vppcalls/interface_handler_api.go index eeab0e0e20..45dea6849e 100644 --- a/plugins/vpp/ifplugin/vppcalls/interface_handler_api.go +++ b/plugins/vpp/ifplugin/vppcalls/interface_handler_api.go @@ -271,7 +271,7 @@ var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ type NewHandlerFunc func(vpp.Client, logging.Logger) InterfaceVppAPI -// CompatibleVpeHandler is helper for returning comptabile Handler. +// CompatibleInterfaceVppHandler is helper for returning comptabile Handler. func CompatibleInterfaceVppHandler(c vpp.Client, log logging.Logger) InterfaceVppAPI { if v := Handler.FindCompatibleVersion(c); v != nil { return v.NewHandler(c, log).(InterfaceVppAPI) diff --git a/plugins/vpp/ifplugin/vppcalls/vpp1904/admin_vppcalls_test.go b/plugins/vpp/ifplugin/vppcalls/vpp1904/admin_vppcalls_test.go index 406d575eb6..e03d05a192 100644 --- a/plugins/vpp/ifplugin/vppcalls/vpp1904/admin_vppcalls_test.go +++ b/plugins/vpp/ifplugin/vppcalls/vpp1904/admin_vppcalls_test.go @@ -22,7 +22,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/interfaces" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestInterfaceAdminDown(t *testing.T) { @@ -173,8 +173,8 @@ func TestInterfaceRemoveTagRetval(t *testing.T) { Expect(err).ToNot(BeNil()) } -func ifTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.InterfaceVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func ifTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.InterfaceVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifHandler := vpp1904.NewInterfaceVppHandler(ctx.MockVPPClient, log) return ctx, ifHandler diff --git a/plugins/vpp/ifplugin/vppcalls/vpp1904/dump_interface_vppcalls_test.go b/plugins/vpp/ifplugin/vppcalls/vpp1904/dump_interface_vppcalls_test.go index da2e29647c..0cf496fc49 100644 --- a/plugins/vpp/ifplugin/vppcalls/vpp1904/dump_interface_vppcalls_test.go +++ b/plugins/vpp/ifplugin/vppcalls/vpp1904/dump_interface_vppcalls_test.go @@ -29,7 +29,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/tapv2" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vxlan" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" interfaces2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/interfaces" ) @@ -41,7 +41,7 @@ func TestDumpInterfacesVxLan(t *testing.T) { ipv61Parse := net.ParseIP("dead:beef:feed:face:cafe:babe:baad:c0de").To16() ipv62Parse := net.ParseIP("d3ad:beef:feed:face:cafe:babe:baad:c0de").To16() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -102,7 +102,7 @@ func TestDumpInterfacesHost(t *testing.T) { test, ifHandler := ifTestSetup(t) defer test.TeardownTestCtx() - test.MockReplies([]*vppcallmock.HandleReplies{ + test.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -156,7 +156,7 @@ func TestDumpInterfacesMemif(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -228,7 +228,7 @@ func TestDumpInterfacesTap2(t *testing.T) { hwAddr1Parse, err := net.ParseMAC("01:23:45:67:89:ab") Expect(err).To(BeNil()) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -328,7 +328,7 @@ func TestDumpInterfacesRxPlacement(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -446,7 +446,7 @@ func TestDumpInterfacesGtpu(t *testing.T) { ipv61Parse := net.ParseIP("dead:beef:feed:face:cafe:babe:baad:c0de").To16() ipv62Parse := net.ParseIP("d3ad:beef:feed:face:cafe:babe:baad:c0de").To16() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, diff --git a/plugins/vpp/ifplugin/vppcalls/vpp1904/vppcalls_handler.go b/plugins/vpp/ifplugin/vppcalls/vpp1904/vppcalls_handler.go index b5a3cf0f35..fbbcde3fee 100644 --- a/plugins/vpp/ifplugin/vppcalls/vpp1904/vppcalls_handler.go +++ b/plugins/vpp/ifplugin/vppcalls/vpp1904/vppcalls_handler.go @@ -17,8 +17,8 @@ package vpp1904 import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" - "go.ligato.io/vpp-agent/v2/plugins/vpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/af_packet" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/bond" diff --git a/plugins/vpp/ifplugin/vppcalls/vpp1908/admin_vppcalls_test.go b/plugins/vpp/ifplugin/vppcalls/vpp1908/admin_vppcalls_test.go index 43c3866fe4..3d281d22f1 100644 --- a/plugins/vpp/ifplugin/vppcalls/vpp1908/admin_vppcalls_test.go +++ b/plugins/vpp/ifplugin/vppcalls/vpp1908/admin_vppcalls_test.go @@ -22,7 +22,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/interfaces" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestInterfaceAdminDown(t *testing.T) { @@ -173,8 +173,8 @@ func TestInterfaceRemoveTagRetval(t *testing.T) { Expect(err).ToNot(BeNil()) } -func ifTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.InterfaceVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func ifTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.InterfaceVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifHandler := vpp1908.NewInterfaceVppHandler(ctx.MockVPPClient, log) return ctx, ifHandler diff --git a/plugins/vpp/ifplugin/vppcalls/vpp1908/dump_interface_vppcalls_test.go b/plugins/vpp/ifplugin/vppcalls/vpp1908/dump_interface_vppcalls_test.go index 817219cb38..9a444d1e11 100644 --- a/plugins/vpp/ifplugin/vppcalls/vpp1908/dump_interface_vppcalls_test.go +++ b/plugins/vpp/ifplugin/vppcalls/vpp1908/dump_interface_vppcalls_test.go @@ -29,7 +29,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/tapv2" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vxlan" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" interfaces2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/interfaces" ) @@ -41,7 +41,7 @@ func TestDumpInterfacesVxLan(t *testing.T) { ipv61Parse := net.ParseIP("dead:beef:feed:face:cafe:babe:baad:c0de").To16() ipv62Parse := net.ParseIP("d3ad:beef:feed:face:cafe:babe:baad:c0de").To16() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -102,7 +102,7 @@ func TestDumpInterfacesHost(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -156,7 +156,7 @@ func TestDumpInterfacesMemif(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -228,7 +228,7 @@ func TestDumpInterfacesTap2(t *testing.T) { hwAddr1Parse, err := net.ParseMAC("01:23:45:67:89:ab") Expect(err).To(BeNil()) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -328,7 +328,7 @@ func TestDumpInterfacesRxPlacement(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -446,7 +446,7 @@ func TestDumpInterfacesGtpu(t *testing.T) { ipv61Parse := net.ParseIP("dead:beef:feed:face:cafe:babe:baad:c0de").To16() ipv62Parse := net.ParseIP("d3ad:beef:feed:face:cafe:babe:baad:c0de").To16() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, diff --git a/plugins/vpp/ifplugin/vppcalls/vpp1908/vppcalls_handler.go b/plugins/vpp/ifplugin/vppcalls/vpp1908/vppcalls_handler.go index acd3832f7a..351e1db225 100644 --- a/plugins/vpp/ifplugin/vppcalls/vpp1908/vppcalls_handler.go +++ b/plugins/vpp/ifplugin/vppcalls/vpp1908/vppcalls_handler.go @@ -17,8 +17,8 @@ package vpp1908 import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" - "go.ligato.io/vpp-agent/v2/plugins/vpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/af_packet" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/bond" diff --git a/plugins/vpp/ifplugin/vppcalls/vpp2001/admin_vppcalls_test.go b/plugins/vpp/ifplugin/vppcalls/vpp2001/admin_vppcalls_test.go index 2d824a4736..24d7753102 100644 --- a/plugins/vpp/ifplugin/vppcalls/vpp2001/admin_vppcalls_test.go +++ b/plugins/vpp/ifplugin/vppcalls/vpp2001/admin_vppcalls_test.go @@ -22,7 +22,7 @@ import ( vpp_ifs "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/interfaces" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestInterfaceAdminDown(t *testing.T) { @@ -174,8 +174,8 @@ func TestInterfaceRemoveTagRetval(t *testing.T) { Expect(err).ToNot(BeNil()) } -func ifTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.InterfaceVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func ifTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.InterfaceVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifHandler := vpp2001.NewInterfaceVppHandler(ctx.MockVPPClient, log) return ctx, ifHandler diff --git a/plugins/vpp/ifplugin/vppcalls/vpp2001/dump_interface_vppcalls_test.go b/plugins/vpp/ifplugin/vppcalls/vpp2001/dump_interface_vppcalls_test.go index 4f37ce18fb..3d68c738d7 100644 --- a/plugins/vpp/ifplugin/vppcalls/vpp2001/dump_interface_vppcalls_test.go +++ b/plugins/vpp/ifplugin/vppcalls/vpp2001/dump_interface_vppcalls_test.go @@ -30,7 +30,7 @@ import ( vpp_vpe "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vpe" vpp_vxlan "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vxlan" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ifs "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/interfaces" ) @@ -42,7 +42,7 @@ func TestDumpInterfacesVxLan(t *testing.T) { ipv61Parse := net.ParseIP("dead:beef:feed:face:cafe:babe:baad:c0de").To16() ipv62Parse := net.ParseIP("d3ad:beef:feed:face:cafe:babe:baad:c0de").To16() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -103,7 +103,7 @@ func TestDumpInterfacesHost(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -157,7 +157,7 @@ func TestDumpInterfacesMemif(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -229,7 +229,7 @@ func TestDumpInterfacesTap2(t *testing.T) { hwAddr1Parse, err := vpp2001.ParseMAC("01:23:45:67:89:ab") Expect(err).To(BeNil()) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -328,7 +328,7 @@ func TestDumpInterfacesRxPlacement(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -446,7 +446,7 @@ func TestDumpInterfacesGtpu(t *testing.T) { ipv61Parse := net.ParseIP("dead:beef:feed:face:cafe:babe:baad:c0de").To16() ipv62Parse := net.ParseIP("d3ad:beef:feed:face:cafe:babe:baad:c0de").To16() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, diff --git a/plugins/vpp/ifplugin/vppcalls/vpp2001_324/admin_vppcalls_test.go b/plugins/vpp/ifplugin/vppcalls/vpp2001_324/admin_vppcalls_test.go index c070e11011..9e3c9db07e 100644 --- a/plugins/vpp/ifplugin/vppcalls/vpp2001_324/admin_vppcalls_test.go +++ b/plugins/vpp/ifplugin/vppcalls/vpp2001_324/admin_vppcalls_test.go @@ -22,7 +22,7 @@ import ( vpp_ifs "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/interfaces" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestInterfaceAdminDown(t *testing.T) { @@ -174,8 +174,8 @@ func TestInterfaceRemoveTagRetval(t *testing.T) { Expect(err).ToNot(BeNil()) } -func ifTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.InterfaceVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func ifTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.InterfaceVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifHandler := vpp2001_324.NewInterfaceVppHandler(ctx.MockVPPClient, log) return ctx, ifHandler diff --git a/plugins/vpp/ifplugin/vppcalls/vpp2001_324/dump_interface_vppcalls_test.go b/plugins/vpp/ifplugin/vppcalls/vpp2001_324/dump_interface_vppcalls_test.go index 8dc6449bce..e0d4ccd1f8 100644 --- a/plugins/vpp/ifplugin/vppcalls/vpp2001_324/dump_interface_vppcalls_test.go +++ b/plugins/vpp/ifplugin/vppcalls/vpp2001_324/dump_interface_vppcalls_test.go @@ -30,7 +30,7 @@ import ( vpp_vpe "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vpe" vpp_vxlan "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vxlan" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ifs "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/interfaces" ) @@ -42,7 +42,7 @@ func TestDumpInterfacesVxLan(t *testing.T) { ipv61Parse := net.ParseIP("dead:beef:feed:face:cafe:babe:baad:c0de").To16() ipv62Parse := net.ParseIP("d3ad:beef:feed:face:cafe:babe:baad:c0de").To16() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -103,7 +103,7 @@ func TestDumpInterfacesHost(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -157,7 +157,7 @@ func TestDumpInterfacesMemif(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -229,7 +229,7 @@ func TestDumpInterfacesTap2(t *testing.T) { hwAddr1Parse, err := vpp2001_324.ParseMAC("01:23:45:67:89:ab") Expect(err).To(BeNil()) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -328,7 +328,7 @@ func TestDumpInterfacesRxPlacement(t *testing.T) { ctx, ifHandler := ifTestSetup(t) defer ctx.TeardownTestCtx() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, @@ -446,7 +446,7 @@ func TestDumpInterfacesGtpu(t *testing.T) { ipv61Parse := net.ParseIP("dead:beef:feed:face:cafe:babe:baad:c0de").To16() ipv62Parse := net.ParseIP("d3ad:beef:feed:face:cafe:babe:baad:c0de").To16() - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_interfaces.SwInterfaceDump{}).GetMessageName(), Ping: true, diff --git a/plugins/vpp/import_test.go b/plugins/vpp/import_test.go new file mode 100644 index 0000000000..03de6dbf72 --- /dev/null +++ b/plugins/vpp/import_test.go @@ -0,0 +1,50 @@ +// Copyright (c) 2019 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package vpp_test + +import ( + "fmt" + "log" + "reflect" + "testing" + + "git.fd.io/govpp.git/api" + + "go.ligato.io/vpp-agent/v2/plugins/vpp" + + // force import of all vpp plugins + _ "go.ligato.io/vpp-agent/v2/cmd/vpp-agent/app" +) + +func TestVppHandlers(t *testing.T) { + handlers := vpp.GetHandlers() + log.Printf("%d handlers:", len(handlers)) + + for h, handler := range handlers { + log.Printf("- handler: %-10s (%v)", h, handler.Versions()) + } +} + +func TestBinapiMessage(t *testing.T) { + msgTypes := api.GetRegisteredMessageTypes() + log.Printf("%d binapi messages:", len(msgTypes)) + + for msgType := range msgTypes { + typ := msgType.Elem() + msg := reflect.New(typ).Interface().(api.Message) + id := fmt.Sprintf("%s_%s", msg.GetMessageName(), msg.GetCrcString()) + log.Printf("- msg: %s - %s (%v)", typ.String(), typ.PkgPath(), id) + } +} diff --git a/plugins/vpp/ipsecplugin/ipsecplugin.go b/plugins/vpp/ipsecplugin/ipsecplugin.go index 3ab75df335..d1b4fed67d 100644 --- a/plugins/vpp/ipsecplugin/ipsecplugin.go +++ b/plugins/vpp/ipsecplugin/ipsecplugin.go @@ -20,7 +20,6 @@ package ipsecplugin import ( - govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/health/statuscheck" "github.com/ligato/cn-infra/infra" "github.com/pkg/errors" @@ -42,9 +41,6 @@ import ( type IPSecPlugin struct { Deps - // GoVPP - vppCh govppapi.Channel - // handler ipSecHandler vppcalls.IPSecVppAPI @@ -59,20 +55,15 @@ type IPSecPlugin struct { type Deps struct { infra.PluginDeps KVScheduler kvs.KVScheduler - GoVppmux govppmux.API + VPP govppmux.API IfPlugin ifplugin.API StatusCheck statuscheck.PluginStatusWriter // optional } // Init registers IPSec-related descriptors. func (p *IPSecPlugin) Init() (err error) { - // GoVPP channels - if p.vppCh, err = p.GoVppmux.NewAPIChannel(); err != nil { - return errors.Errorf("failed to create GoVPP API channel: %v", err) - } - // init IPSec handler - p.ipSecHandler = vppcalls.CompatibleIPSecVppHandler(p.vppCh, p.IfPlugin.GetInterfaceIndex(), p.Log) + p.ipSecHandler = vppcalls.CompatibleIPSecVppHandler(p.VPP, p.IfPlugin.GetInterfaceIndex(), p.Log) if p.ipSecHandler == nil { return errors.New("ipsecHandler is not available") } diff --git a/plugins/vpp/ipsecplugin/options.go b/plugins/vpp/ipsecplugin/options.go index dc750680ae..59e49ed6e4 100644 --- a/plugins/vpp/ipsecplugin/options.go +++ b/plugins/vpp/ipsecplugin/options.go @@ -32,7 +32,7 @@ func NewPlugin(opts ...Option) *IPSecPlugin { p.PluginName = "vpp-ipsec-plugin" p.StatusCheck = &statuscheck.DefaultPlugin p.KVScheduler = &kvscheduler.DefaultPlugin - p.GoVppmux = &govppmux.DefaultPlugin + p.VPP = &govppmux.DefaultPlugin p.IfPlugin = &ifplugin.DefaultPlugin for _, o := range opts { diff --git a/plugins/vpp/ipsecplugin/vppcalls/ipsec_vppcalls.go b/plugins/vpp/ipsecplugin/vppcalls/ipsec_vppcalls.go index ae5ba4a45f..3de5758a08 100644 --- a/plugins/vpp/ipsecplugin/vppcalls/ipsec_vppcalls.go +++ b/plugins/vpp/ipsecplugin/vppcalls/ipsec_vppcalls.go @@ -17,6 +17,8 @@ package vppcalls import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" + + "go.ligato.io/vpp-agent/v2/plugins/vpp" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" ipsec "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/ipsec" ) @@ -62,19 +64,19 @@ type IPSecVppAPI interface { // AddSPD adds SPD to VPP via binary API AddSPD(spdID uint32) error - // DelSPD deletes SPD from VPP via binary API + // DeleteSPD deletes SPD from VPP via binary API DeleteSPD(spdID uint32) error - // InterfaceAddSPD adds SPD interface assignment to VPP via binary API + // AddSPDInterface adds SPD interface assignment to VPP via binary API AddSPDInterface(spdID uint32, iface *ipsec.SecurityPolicyDatabase_Interface) error - // InterfaceDelSPD deletes SPD interface assignment from VPP via binary API + // DeleteSPDInterface deletes SPD interface assignment from VPP via binary API DeleteSPDInterface(spdID uint32, iface *ipsec.SecurityPolicyDatabase_Interface) error // AddSPDEntry adds SPD policy entry to VPP via binary API AddSPDEntry(spdID, saID uint32, spd *ipsec.SecurityPolicyDatabase_PolicyEntry) error - // DelSPDEntry deletes SPD policy entry from VPP via binary API + // DeleteSPDEntry deletes SPD policy entry from VPP via binary API DeleteSPDEntry(spdID, saID uint32, spd *ipsec.SecurityPolicyDatabase_PolicyEntry) error - // AddSAEntry adds SA to VPP via binary API + // AddSA adds SA to VPP via binary API AddSA(sa *ipsec.SecurityAssociation) error - // DelSAEntry deletes SA from VPP via binary API + // DeleteSA deletes SA from VPP via binary API DeleteSA(sa *ipsec.SecurityAssociation) error } @@ -88,27 +90,36 @@ type IPSecVPPRead interface { DumpIPSecSAWithIndex(saID uint32) (saList []*IPSecSaDetails, err error) } -var Versions = map[string]HandlerVersion{} +var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ + Name: "ipsec", + HandlerAPI: (*IPSecVppAPI)(nil), +}) + +type NewHandlerFunc func(ch govppapi.Channel, ifDdx ifaceidx.IfaceMetadataIndex, log logging.Logger) IPSecVppAPI -type HandlerVersion struct { - Msgs []govppapi.Message - New func(govppapi.Channel, ifaceidx.IfaceMetadataIndex, logging.Logger) IPSecVppAPI +func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { + Handler.AddVersion(vpp.HandlerVersion{ + Version: version, + Check: func(c vpp.Client) error { + ch, err := c.NewAPIChannel() + if err != nil { + return err + } + return ch.CheckCompatiblity(msgs...) + }, + NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI { + ch, err := c.NewAPIChannel() + if err != nil { + return err + } + return h(ch, a[0].(ifaceidx.IfaceMetadataIndex), a[1].(logging.Logger)) + }, + }) } -func CompatibleIPSecVppHandler( - ch govppapi.Channel, idx ifaceidx.IfaceMetadataIndex, log logging.Logger, -) IPSecVppAPI { - if len(Versions) == 0 { - // ipsecplugin is not loaded - return nil - } - for ver, h := range Versions { - log.Debugf("checking compatibility with %s", ver) - if err := ch.CheckCompatiblity(h.Msgs...); err != nil { - continue - } - log.Debug("found compatible version:", ver) - return h.New(ch, idx, log) +func CompatibleIPSecVppHandler(c vpp.Client, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) IPSecVppAPI { + if v := Handler.FindCompatibleVersion(c); v != nil { + return v.NewHandler(c, ifIdx, log).(IPSecVppAPI) } - panic("no compatible version available") + return nil } diff --git a/plugins/vpp/ipsecplugin/vppcalls/vpp1904/ipsec_vppcalls_test.go b/plugins/vpp/ipsecplugin/vppcalls/vpp1904/ipsec_vppcalls_test.go index c6ab34571a..219b65115d 100644 --- a/plugins/vpp/ipsecplugin/vppcalls/vpp1904/ipsec_vppcalls_test.go +++ b/plugins/vpp/ipsecplugin/vppcalls/vpp1904/ipsec_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ipsec2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/ipsec" ) @@ -167,8 +167,8 @@ func TestVppInterfaceDelSPD(t *testing.T) { })) } -func ipSecTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.IPSecVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func ipSecTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.IPSecVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndex := ifaceidx.NewIfaceIndex(log, "ipsec-test-ifidx") ipSecHandler := vpp1904.NewIPSecVppHandler(ctx.MockChannel, ifIndex, log) diff --git a/plugins/vpp/ipsecplugin/vppcalls/vpp1904/vppcalls_handlers.go b/plugins/vpp/ipsecplugin/vppcalls/vpp1904/vppcalls_handlers.go index 6267cdd0f2..45c64d5f2c 100644 --- a/plugins/vpp/ipsecplugin/vppcalls/vpp1904/vppcalls_handlers.go +++ b/plugins/vpp/ipsecplugin/vppcalls/vpp1904/vppcalls_handlers.go @@ -21,6 +21,7 @@ import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/ipsec" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls" @@ -30,12 +31,7 @@ func init() { var msgs []govppapi.Message msgs = append(msgs, ipsec.AllMessages()...) - vppcalls.Versions["vpp1904"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) vppcalls.IPSecVppAPI { - return NewIPSecVppHandler(ch, ifIdx, log) - }, - } + vppcalls.AddHandlerVersion(vpp1904.Version, msgs, NewIPSecVppHandler) } // IPSecVppHandler is accessor for IPSec-related vppcalls methods @@ -45,7 +41,7 @@ type IPSecVppHandler struct { log logging.Logger } -func NewIPSecVppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) *IPSecVppHandler { +func NewIPSecVppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) vppcalls.IPSecVppAPI { return &IPSecVppHandler{ch, ifIdx, log} } diff --git a/plugins/vpp/ipsecplugin/vppcalls/vpp1908/ipsec_vppcalls_test.go b/plugins/vpp/ipsecplugin/vppcalls/vpp1908/ipsec_vppcalls_test.go index 06b0472957..579b08fcee 100644 --- a/plugins/vpp/ipsecplugin/vppcalls/vpp1908/ipsec_vppcalls_test.go +++ b/plugins/vpp/ipsecplugin/vppcalls/vpp1908/ipsec_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ipsec2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/ipsec" ) @@ -167,8 +167,8 @@ func TestVppInterfaceDelSPD(t *testing.T) { })) } -func ipSecTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.IPSecVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func ipSecTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.IPSecVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndex := ifaceidx.NewIfaceIndex(log, "ipsec-test-ifidx") ipSecHandler := vpp1908.NewIPSecVppHandler(ctx.MockChannel, ifIndex, log) diff --git a/plugins/vpp/ipsecplugin/vppcalls/vpp1908/vppcalls_handlers.go b/plugins/vpp/ipsecplugin/vppcalls/vpp1908/vppcalls_handlers.go index 56897aa12c..1015ee4419 100644 --- a/plugins/vpp/ipsecplugin/vppcalls/vpp1908/vppcalls_handlers.go +++ b/plugins/vpp/ipsecplugin/vppcalls/vpp1908/vppcalls_handlers.go @@ -21,6 +21,7 @@ import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/ipsec" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls" @@ -30,12 +31,7 @@ func init() { var msgs []govppapi.Message msgs = append(msgs, ipsec.AllMessages()...) - vppcalls.Versions["vpp1908"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) vppcalls.IPSecVppAPI { - return NewIPSecVppHandler(ch, ifIdx, log) - }, - } + vppcalls.AddHandlerVersion(vpp1908.Version, msgs, NewIPSecVppHandler) } // IPSecVppHandler is accessor for IPSec-related vppcalls methods @@ -45,7 +41,7 @@ type IPSecVppHandler struct { log logging.Logger } -func NewIPSecVppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) *IPSecVppHandler { +func NewIPSecVppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) vppcalls.IPSecVppAPI { return &IPSecVppHandler{ch, ifIdx, log} } diff --git a/plugins/vpp/ipsecplugin/vppcalls/vpp2001/ipsec_vppcalls_test.go b/plugins/vpp/ipsecplugin/vppcalls/vpp2001/ipsec_vppcalls_test.go index abf96917f8..12323a2107 100644 --- a/plugins/vpp/ipsecplugin/vppcalls/vpp2001/ipsec_vppcalls_test.go +++ b/plugins/vpp/ipsecplugin/vppcalls/vpp2001/ipsec_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ipsec "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/ipsec" ) @@ -167,8 +167,8 @@ func TestVppInterfaceDelSPD(t *testing.T) { })) } -func ipSecTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.IPSecVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func ipSecTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.IPSecVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndex := ifaceidx.NewIfaceIndex(log, "ipsec-test-ifidx") ipSecHandler := vpp2001.NewIPSecVppHandler(ctx.MockChannel, ifIndex, log) diff --git a/plugins/vpp/ipsecplugin/vppcalls/vpp2001/vppcalls_handlers.go b/plugins/vpp/ipsecplugin/vppcalls/vpp2001/vppcalls_handlers.go index 528d564741..81a3a3738b 100644 --- a/plugins/vpp/ipsecplugin/vppcalls/vpp2001/vppcalls_handlers.go +++ b/plugins/vpp/ipsecplugin/vppcalls/vpp2001/vppcalls_handlers.go @@ -21,6 +21,7 @@ import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001" vpp_ipsec "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/ipsec" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls" @@ -30,12 +31,7 @@ func init() { var msgs []govppapi.Message msgs = append(msgs, vpp_ipsec.AllMessages()...) - vppcalls.Versions["vpp2001"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) vppcalls.IPSecVppAPI { - return NewIPSecVppHandler(ch, ifIdx, log) - }, - } + vppcalls.AddHandlerVersion(vpp2001.Version, msgs, NewIPSecVppHandler) } // IPSecVppHandler is accessor for IPSec-related vppcalls methods @@ -45,7 +41,7 @@ type IPSecVppHandler struct { log logging.Logger } -func NewIPSecVppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) *IPSecVppHandler { +func NewIPSecVppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) vppcalls.IPSecVppAPI { return &IPSecVppHandler{ch, ifIdx, log} } diff --git a/plugins/vpp/ipsecplugin/vppcalls/vpp2001_324/ipsec_vppcalls_test.go b/plugins/vpp/ipsecplugin/vppcalls/vpp2001_324/ipsec_vppcalls_test.go index fdffd47d73..30a2dbfe32 100644 --- a/plugins/vpp/ipsecplugin/vppcalls/vpp2001_324/ipsec_vppcalls_test.go +++ b/plugins/vpp/ipsecplugin/vppcalls/vpp2001_324/ipsec_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ipsec "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/ipsec" ) @@ -167,8 +167,8 @@ func TestVppInterfaceDelSPD(t *testing.T) { })) } -func ipSecTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.IPSecVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func ipSecTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.IPSecVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndex := ifaceidx.NewIfaceIndex(log, "ipsec-test-ifidx") ipSecHandler := vpp2001.NewIPSecVppHandler(ctx.MockChannel, ifIndex, log) diff --git a/plugins/vpp/ipsecplugin/vppcalls/vpp2001_324/vppcalls_handlers.go b/plugins/vpp/ipsecplugin/vppcalls/vpp2001_324/vppcalls_handlers.go index 560f60b750..c20e1c0eeb 100644 --- a/plugins/vpp/ipsecplugin/vppcalls/vpp2001_324/vppcalls_handlers.go +++ b/plugins/vpp/ipsecplugin/vppcalls/vpp2001_324/vppcalls_handlers.go @@ -22,6 +22,7 @@ import ( "github.com/ligato/cn-infra/logging" vpp_ipsec "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/ipsec" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/ipsecplugin/vppcalls" ) @@ -30,12 +31,7 @@ func init() { var msgs []govppapi.Message msgs = append(msgs, vpp_ipsec.AllMessages()...) - vppcalls.Versions["vpp2001_324"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) vppcalls.IPSecVppAPI { - return NewIPSecVppHandler(ch, ifIdx, log) - }, - } + vppcalls.AddHandlerVersion(vpp2001_324.Version, msgs, NewIPSecVppHandler) } // IPSecVppHandler is accessor for IPSec-related vppcalls methods @@ -45,7 +41,7 @@ type IPSecVppHandler struct { log logging.Logger } -func NewIPSecVppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) *IPSecVppHandler { +func NewIPSecVppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) vppcalls.IPSecVppAPI { return &IPSecVppHandler{ch, ifIdx, log} } diff --git a/plugins/vpp/l2plugin/l2plugin.go b/plugins/vpp/l2plugin/l2plugin.go index 84aa6126cf..4f2275a8be 100644 --- a/plugins/vpp/l2plugin/l2plugin.go +++ b/plugins/vpp/l2plugin/l2plugin.go @@ -20,7 +20,6 @@ package l2plugin import ( - govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/health/statuscheck" "github.com/ligato/cn-infra/infra" "github.com/pkg/errors" @@ -43,9 +42,6 @@ import ( type L2Plugin struct { Deps - // GoVPP - vppCh govppapi.Channel - // handlers l2Handler vppcalls.L2VppAPI @@ -63,20 +59,15 @@ type L2Plugin struct { type Deps struct { infra.PluginDeps KVScheduler kvs.KVScheduler - GoVppmux govppmux.API + VPP govppmux.API IfPlugin ifplugin.API StatusCheck statuscheck.PluginStatusWriter // optional } // Init registers L2-related descriptors. func (p *L2Plugin) Init() (err error) { - // GoVPP channels - if p.vppCh, err = p.GoVppmux.NewAPIChannel(); err != nil { - return errors.Errorf("failed to create GoVPP API channel: %v", err) - } - // init handlers - p.l2Handler = vppcalls.CompatibleL2VppHandler(p.vppCh, p.IfPlugin.GetInterfaceIndex(), p.bdIndex, p.Log) + p.l2Handler = vppcalls.CompatibleL2VppHandler(p.VPP, p.IfPlugin.GetInterfaceIndex(), p.bdIndex, p.Log) if p.l2Handler == nil { return errors.Errorf("could not find compatible L2VppHandler") } @@ -98,7 +89,7 @@ func (p *L2Plugin) Init() (err error) { } // we set l2Handler again here, because bdIndex was nil before - p.l2Handler = vppcalls.CompatibleL2VppHandler(p.vppCh, p.IfPlugin.GetInterfaceIndex(), p.bdIndex, p.Log) + p.l2Handler = vppcalls.CompatibleL2VppHandler(p.VPP, p.IfPlugin.GetInterfaceIndex(), p.bdIndex, p.Log) // init & register descriptors p.bdIfaceDescriptor = descriptor.NewBDInterfaceDescriptor(p.bdIndex, p.l2Handler, p.Log) diff --git a/plugins/vpp/l2plugin/options.go b/plugins/vpp/l2plugin/options.go index c22a33bfb3..915888991a 100644 --- a/plugins/vpp/l2plugin/options.go +++ b/plugins/vpp/l2plugin/options.go @@ -32,7 +32,7 @@ func NewPlugin(opts ...Option) *L2Plugin { p.PluginName = "vpp-l2plugin" p.StatusCheck = &statuscheck.DefaultPlugin p.KVScheduler = &kvscheduler.DefaultPlugin - p.GoVppmux = &govppmux.DefaultPlugin + p.VPP = &govppmux.DefaultPlugin p.IfPlugin = &ifplugin.DefaultPlugin for _, o := range opts { diff --git a/plugins/vpp/l2plugin/vppcalls/l2_vppcalls.go b/plugins/vpp/l2plugin/vppcalls/l2_vppcalls.go index 0fa97dc50f..db51c70cb8 100644 --- a/plugins/vpp/l2plugin/vppcalls/l2_vppcalls.go +++ b/plugins/vpp/l2plugin/vppcalls/l2_vppcalls.go @@ -19,6 +19,7 @@ import ( "github.com/ligato/cn-infra/logging" "go.ligato.io/vpp-agent/v2/pkg/idxvpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" l2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -125,26 +126,40 @@ type XConnectVppRead interface { DumpXConnectPairs() (map[uint32]*XConnectDetails, error) } -var Versions = map[string]HandlerVersion{} - -type HandlerVersion struct { - Msgs []govppapi.Message - New func(govppapi.Channel, ifaceidx.IfaceMetadataIndex, idxvpp.NameToIndex, logging.Logger) L2VppAPI +var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ + Name: "l2", + HandlerAPI: (*L2VppAPI)(nil), +}) + +type NewHandlerFunc func(ch govppapi.Channel, ifDdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger) L2VppAPI + +func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { + Handler.AddVersion(vpp.HandlerVersion{ + Version: version, + Check: func(c vpp.Client) error { + ch, err := c.NewAPIChannel() + if err != nil { + return err + } + return ch.CheckCompatiblity(msgs...) + }, + NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI { + ch, err := c.NewAPIChannel() + if err != nil { + return err + } + var bdIdx idxvpp.NameToIndex + if a[1] != nil { + bdIdx = a[1].(idxvpp.NameToIndex) + } + return h(ch, a[0].(ifaceidx.IfaceMetadataIndex), bdIdx, a[2].(logging.Logger)) + }, + }) } -func CompatibleL2VppHandler( - ch govppapi.Channel, - ifIdx ifaceidx.IfaceMetadataIndex, - bdIdx idxvpp.NameToIndex, - log logging.Logger, -) L2VppAPI { - for ver, h := range Versions { - if err := ch.CheckCompatiblity(h.Msgs...); err != nil { - log.Debugf("version %s not compatible", ver) - continue - } - log.Debug("found compatible version:", ver) - return h.New(ch, ifIdx, bdIdx, log) +func CompatibleL2VppHandler(c vpp.Client, ifIdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger) L2VppAPI { + if v := Handler.FindCompatibleVersion(c); v != nil { + return v.NewHandler(c, ifIdx, bdIdx, log).(L2VppAPI) } - panic("no compatible version available") + return nil } diff --git a/plugins/vpp/l2plugin/vppcalls/vpp1904/bridge_domain_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp1904/bridge_domain_vppcalls_test.go index 88033393e8..a8e9b10314 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp1904/bridge_domain_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp1904/bridge_domain_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -112,8 +112,8 @@ func TestVppDeleteBridgeDomainError(t *testing.T) { Expect(err).Should(HaveOccurred()) } -func bdTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.BridgeDomainVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func bdTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.BridgeDomainVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndex := ifaceidx.NewIfaceIndex(log, "bd-test-ifidx") bdHandler := vpp1904.NewL2VppHandler(ctx.MockChannel, ifIndex, nil, log) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp1904/dump_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp1904/dump_vppcalls_test.go index 2b1f2882be..1606e32a2f 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp1904/dump_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp1904/dump_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2nb "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -106,7 +106,7 @@ func TestDumpBridgeDomains(t *testing.T) { ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 5}) ifIndexes.Put("if2", &ifaceidx.IfaceMetadata{SwIfIndex: 7}) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&l2ba.BdIPMacDump{}).GetMessageName(), Ping: true, @@ -138,7 +138,7 @@ func TestDumpBridgeDomainsWithARP(t *testing.T) { ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 5}) ifIndexes.Put("if3", &ifaceidx.IfaceMetadata{SwIfIndex: 8}) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&l2ba.BdIPMacDump{}).GetMessageName(), Ping: true, diff --git a/plugins/vpp/l2plugin/vppcalls/vpp1904/l2fib_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp1904/l2fib_vppcalls_test.go index 6e80e1b9a9..6ff1557296 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp1904/l2fib_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp1904/l2fib_vppcalls_test.go @@ -25,7 +25,7 @@ import ( l2ba "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/l2" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2nb "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -100,8 +100,8 @@ func TestL2FibDelete(t *testing.T) { } } -func fibTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.FIBVppAPI, ifaceidx.IfaceMetadataIndexRW, idxvpp.NameToIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func fibTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.FIBVppAPI, ifaceidx.IfaceMetadataIndexRW, idxvpp.NameToIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifaceIdx := ifaceidx.NewIfaceIndex(logger, "fib-if-idx") bdIndexes := idxvpp.NewNameToIndex(logger, "fib-bd-idx", nil) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp1904/vppcalls_handler.go b/plugins/vpp/l2plugin/vppcalls/vpp1904/vppcalls_handler.go index e59cc456c2..4bf2b18165 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp1904/vppcalls_handler.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp1904/vppcalls_handler.go @@ -22,20 +22,14 @@ import ( "github.com/ligato/cn-infra/logging" "go.ligato.io/vpp-agent/v2/pkg/idxvpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904" l2ba "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/l2" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" ) func init() { - vppcalls.Versions["vpp1904"] = vppcalls.HandlerVersion{ - Msgs: l2ba.AllMessages(), - New: func(ch govppapi.Channel, - ifIdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger, - ) vppcalls.L2VppAPI { - return NewL2VppHandler(ch, ifIdx, bdIdx, log) - }, - } + vppcalls.AddHandlerVersion(vpp1904.Version, l2ba.AllMessages(), NewL2VppHandler) } type L2VppHandler struct { @@ -46,7 +40,7 @@ type L2VppHandler struct { func NewL2VppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger, -) *L2VppHandler { +) vppcalls.L2VppAPI { return &L2VppHandler{ BridgeDomainVppHandler: newBridgeDomainVppHandler(ch, ifIdx, log), FIBVppHandler: newFIBVppHandler(ch, ifIdx, bdIdx, log), diff --git a/plugins/vpp/l2plugin/vppcalls/vpp1904/xconnect_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp1904/xconnect_vppcalls_test.go index d44c0293f6..4295015fc0 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp1904/xconnect_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp1904/xconnect_vppcalls_test.go @@ -24,7 +24,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) var inTestDataXConnect = []struct { @@ -119,8 +119,8 @@ func TestVppUnsetL2XConnect(t *testing.T) { } } -func xcTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.XConnectVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func xcTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.XConnectVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifaceIdx := ifaceidx.NewIfaceIndex(log, "xc-if-idx") xcHandler := vpp1904.NewL2VppHandler(ctx.MockChannel, ifaceIdx, nil, log) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp1908/bridge_domain_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp1908/bridge_domain_vppcalls_test.go index 7777cc4299..d613c88d5b 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp1908/bridge_domain_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp1908/bridge_domain_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -135,8 +135,8 @@ func TestVppDeleteBridgeDomainError(t *testing.T) { Expect(err).Should(HaveOccurred()) } -func bdTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.BridgeDomainVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func bdTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.BridgeDomainVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndex := ifaceidx.NewIfaceIndex(log, "bd-test-ifidx") bdHandler := vpp1908.NewL2VppHandler(ctx.MockChannel, ifIndex, nil, log) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp1908/dump_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp1908/dump_vppcalls_test.go index 9165b090ac..705d86a19c 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp1908/dump_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp1908/dump_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2nb "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -106,7 +106,7 @@ func TestDumpBridgeDomains(t *testing.T) { ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 5}) ifIndexes.Put("if2", &ifaceidx.IfaceMetadata{SwIfIndex: 7}) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&l2ba.BdIPMacDump{}).GetMessageName(), Ping: true, @@ -138,7 +138,7 @@ func TestDumpBridgeDomainsWithARP(t *testing.T) { ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 5}) ifIndexes.Put("if3", &ifaceidx.IfaceMetadata{SwIfIndex: 8}) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&l2ba.BdIPMacDump{}).GetMessageName(), Ping: true, diff --git a/plugins/vpp/l2plugin/vppcalls/vpp1908/l2fib_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp1908/l2fib_vppcalls_test.go index a036c442ec..1e7e894bde 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp1908/l2fib_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp1908/l2fib_vppcalls_test.go @@ -25,7 +25,7 @@ import ( l2ba "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/l2" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2nb "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -100,8 +100,8 @@ func TestL2FibDelete(t *testing.T) { } } -func fibTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.FIBVppAPI, ifaceidx.IfaceMetadataIndexRW, idxvpp.NameToIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func fibTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.FIBVppAPI, ifaceidx.IfaceMetadataIndexRW, idxvpp.NameToIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifaceIdx := ifaceidx.NewIfaceIndex(logger, "fib-if-idx") bdIndexes := idxvpp.NewNameToIndex(logger, "fib-bd-idx", nil) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp1908/vppcalls_handler.go b/plugins/vpp/l2plugin/vppcalls/vpp1908/vppcalls_handler.go index 6098352950..76b3edfbd4 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp1908/vppcalls_handler.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp1908/vppcalls_handler.go @@ -22,20 +22,14 @@ import ( "github.com/ligato/cn-infra/logging" "go.ligato.io/vpp-agent/v2/pkg/idxvpp" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908" l2ba "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/l2" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" ) func init() { - vppcalls.Versions["vpp1908"] = vppcalls.HandlerVersion{ - Msgs: l2ba.AllMessages(), - New: func(ch govppapi.Channel, - ifIdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger, - ) vppcalls.L2VppAPI { - return NewL2VppHandler(ch, ifIdx, bdIdx, log) - }, - } + vppcalls.AddHandlerVersion(vpp1908.Version, l2ba.AllMessages(), NewL2VppHandler) } type L2VppHandler struct { @@ -46,7 +40,7 @@ type L2VppHandler struct { func NewL2VppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger, -) *L2VppHandler { +) vppcalls.L2VppAPI { return &L2VppHandler{ BridgeDomainVppHandler: newBridgeDomainVppHandler(ch, ifIdx, log), FIBVppHandler: newFIBVppHandler(ch, ifIdx, bdIdx, log), diff --git a/plugins/vpp/l2plugin/vppcalls/vpp1908/xconnect_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp1908/xconnect_vppcalls_test.go index 0cfed9676f..be4b1550c5 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp1908/xconnect_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp1908/xconnect_vppcalls_test.go @@ -24,7 +24,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) var inTestDataXConnect = []struct { @@ -119,8 +119,8 @@ func TestVppUnsetL2XConnect(t *testing.T) { } } -func xcTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.XConnectVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func xcTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.XConnectVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifaceIdx := ifaceidx.NewIfaceIndex(log, "xc-if-idx") xcHandler := vpp1908.NewL2VppHandler(ctx.MockChannel, ifaceIdx, nil, log) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp2001/bridge_domain_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp2001/bridge_domain_vppcalls_test.go index d7001f2e2a..c511efb77e 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp2001/bridge_domain_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp2001/bridge_domain_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -112,8 +112,8 @@ func TestVppDeleteBridgeDomainError(t *testing.T) { Expect(err).Should(HaveOccurred()) } -func bdTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.BridgeDomainVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func bdTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.BridgeDomainVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndex := ifaceidx.NewIfaceIndex(log, "bd-test-ifidx") bdHandler := vpp2001.NewL2VppHandler(ctx.MockChannel, ifIndex, nil, log) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp2001/dump_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp2001/dump_vppcalls_test.go index 92d4a929a9..7de28c4cb0 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp2001/dump_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp2001/dump_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -106,7 +106,7 @@ func TestDumpBridgeDomains(t *testing.T) { ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 5}) ifIndexes.Put("if2", &ifaceidx.IfaceMetadata{SwIfIndex: 7}) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_l2.BdIPMacDump{}).GetMessageName(), Ping: true, @@ -138,7 +138,7 @@ func TestDumpBridgeDomainsWithARP(t *testing.T) { ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 5}) ifIndexes.Put("if3", &ifaceidx.IfaceMetadata{SwIfIndex: 8}) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_l2.BdIPMacDump{}).GetMessageName(), Ping: true, diff --git a/plugins/vpp/l2plugin/vppcalls/vpp2001/l2fib_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp2001/l2fib_vppcalls_test.go index 6b74302276..7dc0ce384e 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp2001/l2fib_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp2001/l2fib_vppcalls_test.go @@ -25,7 +25,7 @@ import ( vpp_l2 "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/l2" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -100,8 +100,8 @@ func TestL2FibDelete(t *testing.T) { } } -func fibTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.FIBVppAPI, ifaceidx.IfaceMetadataIndexRW, idxvpp.NameToIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func fibTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.FIBVppAPI, ifaceidx.IfaceMetadataIndexRW, idxvpp.NameToIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifaceIdx := ifaceidx.NewIfaceIndex(logger, "fib-if-idx") bdIndexes := idxvpp.NewNameToIndex(logger, "fib-bd-idx", nil) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp2001/vppcalls_handler.go b/plugins/vpp/l2plugin/vppcalls/vpp2001/vppcalls_handler.go index 2a4445d33d..59fb4bd1c7 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp2001/vppcalls_handler.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp2001/vppcalls_handler.go @@ -22,20 +22,14 @@ import ( "github.com/ligato/cn-infra/logging" "go.ligato.io/vpp-agent/v2/pkg/idxvpp" - vpp_l2 "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/l2" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001" + l2ba "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/l2" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" ) func init() { - vppcalls.Versions["vpp2001"] = vppcalls.HandlerVersion{ - Msgs: vpp_l2.AllMessages(), - New: func(ch govppapi.Channel, - ifIdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger, - ) vppcalls.L2VppAPI { - return NewL2VppHandler(ch, ifIdx, bdIdx, log) - }, - } + vppcalls.AddHandlerVersion(vpp2001.Version, l2ba.AllMessages(), NewL2VppHandler) } type L2VppHandler struct { @@ -46,7 +40,7 @@ type L2VppHandler struct { func NewL2VppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger, -) *L2VppHandler { +) vppcalls.L2VppAPI { return &L2VppHandler{ BridgeDomainVppHandler: newBridgeDomainVppHandler(ch, ifIdx, log), FIBVppHandler: newFIBVppHandler(ch, ifIdx, bdIdx, log), @@ -104,19 +98,19 @@ func newXConnectVppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataInde } } -func ipToAddress(ipstr string) (addr vpp_l2.Address, err error) { +func ipToAddress(ipstr string) (addr l2ba.Address, err error) { netIP := net.ParseIP(ipstr) if netIP == nil { - return vpp_l2.Address{}, fmt.Errorf("invalid IP: %q", ipstr) + return l2ba.Address{}, fmt.Errorf("invalid IP: %q", ipstr) } if ip4 := netIP.To4(); ip4 == nil { - addr.Af = vpp_l2.ADDRESS_IP6 - var ip6addr vpp_l2.IP6Address + addr.Af = l2ba.ADDRESS_IP6 + var ip6addr l2ba.IP6Address copy(ip6addr[:], netIP.To16()) addr.Un.SetIP6(ip6addr) } else { - addr.Af = vpp_l2.ADDRESS_IP4 - var ip4addr vpp_l2.IP4Address + addr.Af = l2ba.ADDRESS_IP4 + var ip4addr l2ba.IP4Address copy(ip4addr[:], ip4) addr.Un.SetIP4(ip4addr) } diff --git a/plugins/vpp/l2plugin/vppcalls/vpp2001/xconnect_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp2001/xconnect_vppcalls_test.go index 3781041191..84b0c17181 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp2001/xconnect_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp2001/xconnect_vppcalls_test.go @@ -24,7 +24,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) var inTestDataXConnect = []struct { @@ -119,8 +119,8 @@ func TestVppUnsetL2XConnect(t *testing.T) { } } -func xcTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.XConnectVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func xcTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.XConnectVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifaceIdx := ifaceidx.NewIfaceIndex(log, "xc-if-idx") xcHandler := vpp2001.NewL2VppHandler(ctx.MockChannel, ifaceIdx, nil, log) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp2001_324/bridge_domain_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp2001_324/bridge_domain_vppcalls_test.go index 2b0f89624c..a0ac12225a 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp2001_324/bridge_domain_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp2001_324/bridge_domain_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -112,8 +112,8 @@ func TestVppDeleteBridgeDomainError(t *testing.T) { Expect(err).Should(HaveOccurred()) } -func bdTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.BridgeDomainVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func bdTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.BridgeDomainVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndex := ifaceidx.NewIfaceIndex(log, "bd-test-ifidx") bdHandler := vpp2001_324.NewL2VppHandler(ctx.MockChannel, ifIndex, nil, log) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp2001_324/dump_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp2001_324/dump_vppcalls_test.go index 043fd6fc45..ab03e6bd22 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp2001_324/dump_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp2001_324/dump_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -106,7 +106,7 @@ func TestDumpBridgeDomains(t *testing.T) { ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 5}) ifIndexes.Put("if2", &ifaceidx.IfaceMetadata{SwIfIndex: 7}) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_l2.BdIPMacDump{}).GetMessageName(), Ping: true, @@ -138,7 +138,7 @@ func TestDumpBridgeDomainsWithARP(t *testing.T) { ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 5}) ifIndexes.Put("if3", &ifaceidx.IfaceMetadata{SwIfIndex: 8}) - ctx.MockReplies([]*vppcallmock.HandleReplies{ + ctx.MockReplies([]*vppmock.HandleReplies{ { Name: (&vpp_l2.BdIPMacDump{}).GetMessageName(), Ping: true, diff --git a/plugins/vpp/l2plugin/vppcalls/vpp2001_324/l2fib_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp2001_324/l2fib_vppcalls_test.go index bbca0e8e2a..f66d8be136 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp2001_324/l2fib_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp2001_324/l2fib_vppcalls_test.go @@ -25,7 +25,7 @@ import ( vpp_l2 "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/l2" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l2 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l2" ) @@ -100,8 +100,8 @@ func TestL2FibDelete(t *testing.T) { } } -func fibTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.FIBVppAPI, ifaceidx.IfaceMetadataIndexRW, idxvpp.NameToIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func fibTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.FIBVppAPI, ifaceidx.IfaceMetadataIndexRW, idxvpp.NameToIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifaceIdx := ifaceidx.NewIfaceIndex(logger, "fib-if-idx") bdIndexes := idxvpp.NewNameToIndex(logger, "fib-bd-idx", nil) diff --git a/plugins/vpp/l2plugin/vppcalls/vpp2001_324/vppcalls_handler.go b/plugins/vpp/l2plugin/vppcalls/vpp2001_324/vppcalls_handler.go index 3e7aa55746..e43b46eecb 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp2001_324/vppcalls_handler.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp2001_324/vppcalls_handler.go @@ -22,20 +22,14 @@ import ( "github.com/ligato/cn-infra/logging" "go.ligato.io/vpp-agent/v2/pkg/idxvpp" - vpp_l2 "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/l2" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324" + l2ba "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/l2" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" ) func init() { - vppcalls.Versions["vpp2001_324"] = vppcalls.HandlerVersion{ - Msgs: vpp_l2.AllMessages(), - New: func(ch govppapi.Channel, - ifIdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger, - ) vppcalls.L2VppAPI { - return NewL2VppHandler(ch, ifIdx, bdIdx, log) - }, - } + vppcalls.AddHandlerVersion(vpp2001_324.Version, l2ba.AllMessages(), NewL2VppHandler) } type L2VppHandler struct { @@ -46,7 +40,7 @@ type L2VppHandler struct { func NewL2VppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger, -) *L2VppHandler { +) vppcalls.L2VppAPI { return &L2VppHandler{ BridgeDomainVppHandler: newBridgeDomainVppHandler(ch, ifIdx, log), FIBVppHandler: newFIBVppHandler(ch, ifIdx, bdIdx, log), @@ -104,19 +98,19 @@ func newXConnectVppHandler(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataInde } } -func ipToAddress(ipstr string) (addr vpp_l2.Address, err error) { +func ipToAddress(ipstr string) (addr l2ba.Address, err error) { netIP := net.ParseIP(ipstr) if netIP == nil { - return vpp_l2.Address{}, fmt.Errorf("invalid IP: %q", ipstr) + return l2ba.Address{}, fmt.Errorf("invalid IP: %q", ipstr) } if ip4 := netIP.To4(); ip4 == nil { - addr.Af = vpp_l2.ADDRESS_IP6 - var ip6addr vpp_l2.IP6Address + addr.Af = l2ba.ADDRESS_IP6 + var ip6addr l2ba.IP6Address copy(ip6addr[:], netIP.To16()) addr.Un.SetIP6(ip6addr) } else { - addr.Af = vpp_l2.ADDRESS_IP4 - var ip4addr vpp_l2.IP4Address + addr.Af = l2ba.ADDRESS_IP4 + var ip4addr l2ba.IP4Address copy(ip4addr[:], ip4) addr.Un.SetIP4(ip4addr) } diff --git a/plugins/vpp/l2plugin/vppcalls/vpp2001_324/xconnect_vppcalls_test.go b/plugins/vpp/l2plugin/vppcalls/vpp2001_324/xconnect_vppcalls_test.go index 72161fdb3c..b2b19cd6a2 100644 --- a/plugins/vpp/l2plugin/vppcalls/vpp2001_324/xconnect_vppcalls_test.go +++ b/plugins/vpp/l2plugin/vppcalls/vpp2001_324/xconnect_vppcalls_test.go @@ -24,7 +24,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l2plugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) var inTestDataXConnect = []struct { @@ -119,8 +119,8 @@ func TestVppUnsetL2XConnect(t *testing.T) { } } -func xcTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.XConnectVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func xcTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.XConnectVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifaceIdx := ifaceidx.NewIfaceIndex(log, "xc-if-idx") xcHandler := vpp2001_324.NewL2VppHandler(ctx.MockChannel, ifaceIdx, nil, log) diff --git a/plugins/vpp/l3plugin/l3plugin.go b/plugins/vpp/l3plugin/l3plugin.go index cd757cbb9c..052b2dadf1 100644 --- a/plugins/vpp/l3plugin/l3plugin.go +++ b/plugins/vpp/l3plugin/l3plugin.go @@ -65,7 +65,7 @@ type L3Plugin struct { type Deps struct { infra.PluginDeps KVScheduler kvs.KVScheduler - GoVppmux govppmux.API + VPP govppmux.API IfPlugin ifplugin.API AddrAlloc netalloc.AddressAllocator StatusCheck statuscheck.PluginStatusWriter // optional @@ -76,12 +76,12 @@ func (p *L3Plugin) Init() error { var err error // GoVPP channels - if p.vppCh, err = p.GoVppmux.NewAPIChannel(); err != nil { + if p.vppCh, err = p.VPP.NewAPIChannel(); err != nil { return errors.Errorf("failed to create GoVPP API channel: %v", err) } // init handlers - p.l3Handler = vppcalls.CompatibleL3VppHandler(p.vppCh, p.IfPlugin.GetInterfaceIndex(), + p.l3Handler = vppcalls.CompatibleL3VppHandler(p.VPP, p.IfPlugin.GetInterfaceIndex(), p.vrfIndex, p.AddrAlloc, p.Log) if p.l3Handler == nil { return errors.Errorf("could not find compatible L3VppHandler") @@ -100,7 +100,7 @@ func (p *L3Plugin) Init() error { } // set l3 handler again since VRF index was nil before - p.l3Handler = vppcalls.CompatibleL3VppHandler(p.vppCh, p.IfPlugin.GetInterfaceIndex(), + p.l3Handler = vppcalls.CompatibleL3VppHandler(p.VPP, p.IfPlugin.GetInterfaceIndex(), p.vrfIndex, p.AddrAlloc, p.Log) // init & register descriptors diff --git a/plugins/vpp/l3plugin/options.go b/plugins/vpp/l3plugin/options.go index 2f2d1cb63a..4650c8a007 100644 --- a/plugins/vpp/l3plugin/options.go +++ b/plugins/vpp/l3plugin/options.go @@ -33,7 +33,7 @@ func NewPlugin(opts ...Option) *L3Plugin { p.PluginName = "vpp-l3plugin" p.StatusCheck = &statuscheck.DefaultPlugin p.KVScheduler = &kvscheduler.DefaultPlugin - p.GoVppmux = &govppmux.DefaultPlugin + p.VPP = &govppmux.DefaultPlugin p.IfPlugin = &ifplugin.DefaultPlugin p.AddrAlloc = &netalloc.DefaultPlugin diff --git a/plugins/vpp/l3plugin/vppcalls/l3_vppcalls.go b/plugins/vpp/l3plugin/vppcalls/l3_vppcalls.go index fdde02bf53..a949dbcf1a 100644 --- a/plugins/vpp/l3plugin/vppcalls/l3_vppcalls.go +++ b/plugins/vpp/l3plugin/vppcalls/l3_vppcalls.go @@ -18,6 +18,7 @@ import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" "go.ligato.io/vpp-agent/v2/plugins/netalloc" + "go.ligato.io/vpp-agent/v2/plugins/vpp" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vrfidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" @@ -197,28 +198,46 @@ type IPNeighVppAPI interface { GetIPScanNeighbor() (*l3.IPScanNeighbor, error) } -var Versions = map[string]HandlerVersion{} - -type HandlerVersion struct { - Msgs []govppapi.Message - New func(govppapi.Channel, ifaceidx.IfaceMetadataIndex, vrfidx.VRFMetadataIndex, - netalloc.AddressAllocator, logging.Logger) L3VppAPI +var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ + Name: "l3", + HandlerAPI: (*L3VppAPI)(nil), +}) + +type NewHandlerFunc func(ch govppapi.Channel, idx ifaceidx.IfaceMetadataIndex, vrfIdx vrfidx.VRFMetadataIndex, addrAlloc netalloc.AddressAllocator, log logging.Logger) L3VppAPI + +func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { + Handler.AddVersion(vpp.HandlerVersion{ + Version: version, + Check: func(c vpp.Client) error { + ch, err := c.NewAPIChannel() + if err != nil { + return err + } + return ch.CheckCompatiblity(msgs...) + }, + NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI { + ch, err := c.NewAPIChannel() + if err != nil { + return err + } + var vrfIdx vrfidx.VRFMetadataIndex + if a[1] != nil { + vrfIdx = a[1].(vrfidx.VRFMetadataIndex) + } + return h(ch, a[0].(ifaceidx.IfaceMetadataIndex), vrfIdx, a[2].(netalloc.AddressAllocator), a[3].(logging.Logger)) + }, + }) } func CompatibleL3VppHandler( - ch govppapi.Channel, + c vpp.Client, ifIdx ifaceidx.IfaceMetadataIndex, vrfIdx vrfidx.VRFMetadataIndex, addrAlloc netalloc.AddressAllocator, log logging.Logger, ) L3VppAPI { - for ver, h := range Versions { - if err := ch.CheckCompatiblity(h.Msgs...); err != nil { - log.Debugf("version %s not compatible", ver) - continue - } - log.Debug("found compatible version:", ver) - return h.New(ch, ifIdx, vrfIdx, addrAlloc, log) + if v := Handler.FindCompatibleVersion(c); v != nil { + return v.NewHandler(c, ifIdx, vrfIdx, addrAlloc, log).(L3VppAPI) } - panic("no compatible version available") + return nil } diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1904/arp_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1904/arp_vppcalls_test.go index 4111251b71..c0a9c8b7ba 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1904/arp_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1904/arp_vppcalls_test.go @@ -24,7 +24,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -83,8 +83,8 @@ func TestDelArp(t *testing.T) { Expect(err).To(Succeed()) } -func arpTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func arpTestSetup(t *testing.T) (*vppmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") arpHandler := vpp1904.NewArpVppHandler(ctx.MockChannel, ifIndexes, log) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1904/ipneigh_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1904/ipneigh_vppcalls_test.go index a494456763..160ea889a1 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1904/ipneigh_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1904/ipneigh_vppcalls_test.go @@ -19,7 +19,7 @@ import ( . "github.com/onsi/gomega" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -67,7 +67,7 @@ func TestGetIPScanNeighbor(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() ctx.MockVpp.MockReply(&vpe.CliInbandReply{ diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1904/proxyarp_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1904/proxyarp_vppcalls_test.go index 851bc39885..997d7c8e65 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1904/proxyarp_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1904/proxyarp_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) // Test enable/disable proxy arp @@ -64,8 +64,8 @@ func TestProxyArpRange(t *testing.T) { Expect(err).To(Not(BeNil())) } -func pArpTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI, vppcalls.ProxyArpVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func pArpTestSetup(t *testing.T) (*vppmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI, vppcalls.ProxyArpVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") arpHandler := vpp1904.NewArpVppHandler(ctx.MockChannel, ifIndexes, log) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1904/route_dump_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1904/route_dump_test.go index e021b136b5..a2608ee2e3 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1904/route_dump_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1904/route_dump_test.go @@ -23,12 +23,12 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/ip" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) // Test dumping routes func TestDumpStaticRoutes(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") l3handler := NewRouteVppHandler(ctx.MockChannel, ifIndexes, netallock_mock.NewMockNetAlloc(), diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1904/route_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1904/route_vppcalls_test.go index 8661787911..fd109fe387 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1904/route_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1904/route_vppcalls_test.go @@ -26,7 +26,7 @@ import ( ifvpp1904 "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls/vpp1904" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -82,8 +82,8 @@ func TestDeleteRoute(t *testing.T) { Expect(err).To(Not(BeNil())) } -func routeTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifvppcalls.InterfaceVppAPI, vppcalls.RouteVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func routeTestSetup(t *testing.T) (*vppmock.TestCtx, ifvppcalls.InterfaceVppAPI, vppcalls.RouteVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifHandler := ifvpp1904.NewInterfaceVppHandler(ctx.MockVPPClient, log) ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1904/vppcalls_handlers.go b/plugins/vpp/l3plugin/vppcalls/vpp1904/vppcalls_handlers.go index 9c33880559..683994adad 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1904/vppcalls_handlers.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1904/vppcalls_handlers.go @@ -18,21 +18,20 @@ import ( "fmt" "net" - "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vrfidx" - - "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/dhcp" - govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" "github.com/ligato/cn-infra/logging/logrus" vpevppcalls "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp1904" + vpe_vpp1904 "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp1904" "go.ligato.io/vpp-agent/v2/plugins/netalloc" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/dhcp" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/ip" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" + "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vrfidx" ) func init() { @@ -41,14 +40,7 @@ func init() { msgs = append(msgs, vpe.AllMessages()...) msgs = append(msgs, dhcp.AllMessages()...) - vppcalls.Versions["vpp1904"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, vrfIdx vrfidx.VRFMetadataIndex, - addrAlloc netalloc.AddressAllocator, log logging.Logger, - ) vppcalls.L3VppAPI { - return NewL3VppHandler(ch, ifIdx, addrAlloc, log) - }, - } + vppcalls.AddHandlerVersion(vpp1904.Version, msgs, NewL3VppHandler) } type L3VppHandler struct { @@ -61,8 +53,12 @@ type L3VppHandler struct { } func NewL3VppHandler( - ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, addrAlloc netalloc.AddressAllocator, log logging.Logger, -) *L3VppHandler { + ch govppapi.Channel, + ifIdx ifaceidx.IfaceMetadataIndex, + vrfIdx vrfidx.VRFMetadataIndex, + addrAlloc netalloc.AddressAllocator, + log logging.Logger, +) vppcalls.L3VppAPI { return &L3VppHandler{ ArpVppHandler: NewArpVppHandler(ch, ifIdx, log), ProxyArpVppHandler: NewProxyArpVppHandler(ch, ifIdx, log), @@ -160,7 +156,7 @@ func NewIPNeighVppHandler(callsChan govppapi.Channel, log logging.Logger) *IPNei return &IPNeighHandler{ callsChannel: callsChan, log: log, - VppCoreAPI: vpp1904.NewVpeHandler(callsChan), + VppCoreAPI: vpe_vpp1904.NewVpeHandler(callsChan), } } @@ -175,7 +171,7 @@ func NewVrfTableVppHandler(callsChan govppapi.Channel, log logging.Logger) *VrfT } } -// NewVrfTableVppHandler creates new instance of vrf-table vppcalls handler +// NewDHCPProxyHandler creates new instance of vrf-table vppcalls handler func NewDHCPProxyHandler(callsChan govppapi.Channel, log logging.Logger) *DHCPProxyHandler { if log == nil { log = logrus.NewLogger("dhcp-proxy-handler") diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1904/vrf_dump_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1904/vrf_dump_test.go index 238cb9f7c3..bb521477ac 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1904/vrf_dump_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1904/vrf_dump_test.go @@ -21,12 +21,12 @@ import ( . "github.com/onsi/gomega" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/ip" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) func TestDumpVrfTables(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() vthandler := NewVrfTableVppHandler(ctx.MockChannel, logrus.DefaultLogger()) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1904/vrf_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1904/vrf_vppcalls_test.go index 1e4c6d603c..b1b47c3d6c 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1904/vrf_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1904/vrf_vppcalls_test.go @@ -22,7 +22,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/ip" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -130,8 +130,8 @@ func TestDeleteVrfTable(t *testing.T) { Expect(err).To(Not(BeNil())) } -func vrfTableTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.VrfTableVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func vrfTableTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.VrfTableVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") vtHandler := vpp1904.NewVrfTableVppHandler(ctx.MockChannel, log) return ctx, vtHandler diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1908/arp_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1908/arp_vppcalls_test.go index 00642d1c2b..15a6165214 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1908/arp_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1908/arp_vppcalls_test.go @@ -24,7 +24,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -83,8 +83,8 @@ func TestDelArp(t *testing.T) { Expect(err).To(Succeed()) } -func arpTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func arpTestSetup(t *testing.T) (*vppmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") arpHandler := vpp1908.NewArpVppHandler(ctx.MockChannel, ifIndexes, log) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1908/ipneigh_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1908/ipneigh_vppcalls_test.go index 023d0923d0..8c6b2a3fdd 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1908/ipneigh_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1908/ipneigh_vppcalls_test.go @@ -19,7 +19,7 @@ import ( . "github.com/onsi/gomega" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -67,7 +67,7 @@ func TestGetIPScanNeighbor(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() ctx.MockVpp.MockReply(&vpe.CliInbandReply{ diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1908/proxyarp_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1908/proxyarp_vppcalls_test.go index 148c2518d4..36aea45263 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1908/proxyarp_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1908/proxyarp_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) // Test enable/disable proxy arp @@ -64,8 +64,8 @@ func TestProxyArpRange(t *testing.T) { Expect(err).To(Not(BeNil())) } -func pArpTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI, vppcalls.ProxyArpVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func pArpTestSetup(t *testing.T) (*vppmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI, vppcalls.ProxyArpVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") arpHandler := vpp1908.NewArpVppHandler(ctx.MockChannel, ifIndexes, log) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1908/route_dump_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1908/route_dump_test.go index 39906f8d5a..01695ac6ca 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1908/route_dump_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1908/route_dump_test.go @@ -27,12 +27,12 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/ip" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) // Test dumping routes func TestDumpStaticRoutes(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if") vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf") diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1908/route_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1908/route_vppcalls_test.go index 689686e2a1..d3c7535f83 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1908/route_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1908/route_vppcalls_test.go @@ -28,7 +28,7 @@ import ( ifvpp1908 "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls/vpp1908" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -84,8 +84,8 @@ func TestDeleteRoute(t *testing.T) { Expect(err).To(Not(BeNil())) } -func routeTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifvppcalls.InterfaceVppAPI, vppcalls.RouteVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func routeTestSetup(t *testing.T) (*vppmock.TestCtx, ifvppcalls.InterfaceVppAPI, vppcalls.RouteVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifHandler := ifvpp1908.NewInterfaceVppHandler(ctx.MockVPPClient, log) ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if") diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1908/vppcalls_handlers.go b/plugins/vpp/l3plugin/vppcalls/vpp1908/vppcalls_handlers.go index 21efe11aa2..cfd2f56931 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1908/vppcalls_handlers.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1908/vppcalls_handlers.go @@ -18,21 +18,20 @@ import ( "fmt" "net" - "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vrfidx" - - "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/dhcp" - govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" "github.com/ligato/cn-infra/logging/logrus" vpevppcalls "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp1908" + vpe_vpp1908 "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp1908" "go.ligato.io/vpp-agent/v2/plugins/netalloc" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/dhcp" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/ip" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" + "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vrfidx" ) func init() { @@ -41,14 +40,7 @@ func init() { msgs = append(msgs, vpe.AllMessages()...) msgs = append(msgs, dhcp.AllMessages()...) - vppcalls.Versions["vpp1908"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, - vrfIdx vrfidx.VRFMetadataIndex, addrAlloc netalloc.AddressAllocator, log logging.Logger, - ) vppcalls.L3VppAPI { - return NewL3VppHandler(ch, ifIdx, vrfIdx, addrAlloc, log) - }, - } + vppcalls.AddHandlerVersion(vpp1908.Version, msgs, NewL3VppHandler) } type L3VppHandler struct { @@ -61,9 +53,12 @@ type L3VppHandler struct { } func NewL3VppHandler( - ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, vrfIdx vrfidx.VRFMetadataIndex, - addrAlloc netalloc.AddressAllocator, log logging.Logger, -) *L3VppHandler { + ch govppapi.Channel, + ifIdx ifaceidx.IfaceMetadataIndex, + vrfIdx vrfidx.VRFMetadataIndex, + addrAlloc netalloc.AddressAllocator, + log logging.Logger, +) vppcalls.L3VppAPI { return &L3VppHandler{ ArpVppHandler: NewArpVppHandler(ch, ifIdx, log), ProxyArpVppHandler: NewProxyArpVppHandler(ch, ifIdx, log), @@ -163,7 +158,7 @@ func NewIPNeighVppHandler(callsChan govppapi.Channel, log logging.Logger) *IPNei return &IPNeighHandler{ callsChannel: callsChan, log: log, - VppCoreAPI: vpp1908.NewVpeHandler(callsChan), + VppCoreAPI: vpe_vpp1908.NewVpeHandler(callsChan), } } diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1908/vrf_dump_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1908/vrf_dump_test.go index 7178120216..d0713f65d4 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1908/vrf_dump_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1908/vrf_dump_test.go @@ -21,12 +21,12 @@ import ( . "github.com/onsi/gomega" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/ip" "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) func TestDumpVrfTables(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() vthandler := NewVrfTableVppHandler(ctx.MockChannel, logrus.DefaultLogger()) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp1908/vrf_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp1908/vrf_vppcalls_test.go index 1a81a21f6f..4293a33609 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp1908/vrf_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp1908/vrf_vppcalls_test.go @@ -22,7 +22,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/ip" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -130,8 +130,8 @@ func TestDeleteVrfTable(t *testing.T) { Expect(err).To(Not(BeNil())) } -func vrfTableTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.VrfTableVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func vrfTableTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.VrfTableVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") vtHandler := vpp1908.NewVrfTableVppHandler(ctx.MockChannel, log) return ctx, vtHandler diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001/arp_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001/arp_vppcalls_test.go index 5712eda324..1b707a89de 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001/arp_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001/arp_vppcalls_test.go @@ -24,7 +24,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -83,8 +83,8 @@ func TestDelArp(t *testing.T) { Expect(err).To(Succeed()) } -func arpTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func arpTestSetup(t *testing.T) (*vppmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") arpHandler := vpp2001.NewArpVppHandler(ctx.MockChannel, ifIndexes, log) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001/ipneigh_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001/ipneigh_vppcalls_test.go index 85ce5f328e..25aea654a9 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001/ipneigh_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001/ipneigh_vppcalls_test.go @@ -19,7 +19,7 @@ import ( . "github.com/onsi/gomega" vpp_vpe "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -67,7 +67,7 @@ func TestGetIPScanNeighbor(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() ctx.MockVpp.MockReply(&vpp_vpe.CliInbandReply{ diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001/proxyarp_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001/proxyarp_vppcalls_test.go index 196e27b5dc..8c41820461 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001/proxyarp_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001/proxyarp_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) // Test enable/disable proxy arp @@ -64,8 +64,8 @@ func TestProxyArpRange(t *testing.T) { Expect(err).To(Not(BeNil())) } -func pArpTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI, vppcalls.ProxyArpVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func pArpTestSetup(t *testing.T) (*vppmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI, vppcalls.ProxyArpVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") arpHandler := vpp2001.NewArpVppHandler(ctx.MockChannel, ifIndexes, log) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001/route_dump_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001/route_dump_test.go index 97712c2d9f..ec71352499 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001/route_dump_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001/route_dump_test.go @@ -27,12 +27,12 @@ import ( vpp_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/ip" vpp_vpe "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) // Test dumping routes func TestDumpStaticRoutes(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if") vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf") diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001/route_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001/route_vppcalls_test.go index 450d225c3f..0ab4a7393f 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001/route_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001/route_vppcalls_test.go @@ -28,7 +28,7 @@ import ( ifvpp2001_379 "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/vppcalls/vpp2001" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -84,8 +84,8 @@ func TestDeleteRoute(t *testing.T) { Expect(err).To(Not(BeNil())) } -func routeTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifvppcalls.InterfaceVppAPI, vppcalls.RouteVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func routeTestSetup(t *testing.T) (*vppmock.TestCtx, ifvppcalls.InterfaceVppAPI, vppcalls.RouteVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifHandler := ifvpp2001_379.NewInterfaceVppHandler(ctx.MockVPPClient, log) ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if") diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001/vppcalls_handlers.go b/plugins/vpp/l3plugin/vppcalls/vpp2001/vppcalls_handlers.go index 4825187b00..2efcc2ed59 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001/vppcalls_handlers.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001/vppcalls_handlers.go @@ -23,8 +23,9 @@ import ( "github.com/ligato/cn-infra/logging/logrus" corevppcalls "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp2001" + vpe_vpp2001 "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp2001" "go.ligato.io/vpp-agent/v2/plugins/netalloc" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001" vpp_dhcp "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/dhcp" vpp_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/ip" vpp_vpe "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vpe" @@ -39,14 +40,7 @@ func init() { msgs = append(msgs, vpp_vpe.AllMessages()...) msgs = append(msgs, vpp_dhcp.AllMessages()...) - vppcalls.Versions["vpp2001"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, - vrfIdx vrfidx.VRFMetadataIndex, addrAlloc netalloc.AddressAllocator, log logging.Logger, - ) vppcalls.L3VppAPI { - return NewL3VppHandler(ch, ifIdx, vrfIdx, addrAlloc, log) - }, - } + vppcalls.AddHandlerVersion(vpp2001.Version, msgs, NewL3VppHandler) } type L3VppHandler struct { @@ -59,9 +53,12 @@ type L3VppHandler struct { } func NewL3VppHandler( - ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, vrfIdx vrfidx.VRFMetadataIndex, - addrAlloc netalloc.AddressAllocator, log logging.Logger, -) *L3VppHandler { + ch govppapi.Channel, + ifIdx ifaceidx.IfaceMetadataIndex, + vrfIdx vrfidx.VRFMetadataIndex, + addrAlloc netalloc.AddressAllocator, + log logging.Logger, +) vppcalls.L3VppAPI { return &L3VppHandler{ ArpVppHandler: NewArpVppHandler(ch, ifIdx, log), ProxyArpVppHandler: NewProxyArpVppHandler(ch, ifIdx, log), @@ -161,7 +158,7 @@ func NewIPNeighVppHandler(callsChan govppapi.Channel, log logging.Logger) *IPNei return &IPNeighHandler{ callsChannel: callsChan, log: log, - VppCoreAPI: vpp2001.NewVpeHandler(callsChan), + VppCoreAPI: vpe_vpp2001.NewVpeHandler(callsChan), } } diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001/vrf_dump_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001/vrf_dump_test.go index f7bf05eae4..7c252c97a2 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001/vrf_dump_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001/vrf_dump_test.go @@ -21,12 +21,12 @@ import ( . "github.com/onsi/gomega" vpp_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/ip" vpp_vpe "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) func TestDumpVrfTables(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() vthandler := NewVrfTableVppHandler(ctx.MockChannel, logrus.DefaultLogger()) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001/vrf_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001/vrf_vppcalls_test.go index e308f63fb7..db3ed47f68 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001/vrf_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001/vrf_vppcalls_test.go @@ -22,7 +22,7 @@ import ( vpp_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/ip" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -130,8 +130,8 @@ func TestDeleteVrfTable(t *testing.T) { Expect(err).To(Not(BeNil())) } -func vrfTableTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.VrfTableVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func vrfTableTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.VrfTableVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") vtHandler := vpp2001.NewVrfTableVppHandler(ctx.MockChannel, log) return ctx, vtHandler diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/arp_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/arp_vppcalls_test.go index 21a7037c50..a4360aa76f 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/arp_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/arp_vppcalls_test.go @@ -24,7 +24,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -83,8 +83,8 @@ func TestDelArp(t *testing.T) { Expect(err).To(Succeed()) } -func arpTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func arpTestSetup(t *testing.T) (*vppmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") arpHandler := vpp2001_324.NewArpVppHandler(ctx.MockChannel, ifIndexes, log) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/ipneigh_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/ipneigh_vppcalls_test.go index 53d52cd392..47149229cd 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/ipneigh_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/ipneigh_vppcalls_test.go @@ -19,7 +19,7 @@ import ( . "github.com/onsi/gomega" vpp_vpe "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -67,7 +67,7 @@ func TestGetIPScanNeighbor(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() ctx.MockVpp.MockReply(&vpp_vpe.CliInbandReply{ diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/proxyarp_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/proxyarp_vppcalls_test.go index e3dd6beaa7..cb1fc1c2e9 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/proxyarp_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/proxyarp_vppcalls_test.go @@ -23,7 +23,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) // Test enable/disable proxy arp @@ -64,8 +64,8 @@ func TestProxyArpRange(t *testing.T) { Expect(err).To(Not(BeNil())) } -func pArpTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI, vppcalls.ProxyArpVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func pArpTestSetup(t *testing.T) (*vppmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI, vppcalls.ProxyArpVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test") arpHandler := vpp2001_324.NewArpVppHandler(ctx.MockChannel, ifIndexes, log) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/route_dump_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/route_dump_test.go index 605c940e85..d81cf945d4 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/route_dump_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/route_dump_test.go @@ -27,12 +27,12 @@ import ( vpp_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/ip" vpp_vpe "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) // Test dumping routes func TestDumpStaticRoutes(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if") vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf") diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/route_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/route_vppcalls_test.go index f830341037..afc1a6b5f4 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/route_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/route_vppcalls_test.go @@ -28,7 +28,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp2001_324" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vrfidx" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -84,8 +84,8 @@ func TestDeleteRoute(t *testing.T) { Expect(err).To(Not(BeNil())) } -func routeTestSetup(t *testing.T) (*vppcallmock.TestCtx, ifvppcalls.InterfaceVppAPI, vppcalls.RouteVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func routeTestSetup(t *testing.T) (*vppmock.TestCtx, ifvppcalls.InterfaceVppAPI, vppcalls.RouteVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") ifHandler := ifvpp2001_324.NewInterfaceVppHandler(ctx.MockVPPClient, log) ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if") diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vppcalls_handlers.go b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vppcalls_handlers.go index 42097c39a7..60db167b58 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vppcalls_handlers.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vppcalls_handlers.go @@ -18,20 +18,20 @@ import ( "fmt" "net" - "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vrfidx" - govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" "github.com/ligato/cn-infra/logging/logrus" vpevppcalls "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls" - "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp2001_324" + vpe_vpp2001_324 "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp2001_324" "go.ligato.io/vpp-agent/v2/plugins/netalloc" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324" vpp_dhcp "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/dhcp" vpp_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/ip" vpp_vpe "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vpe" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" + "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vrfidx" ) func init() { @@ -40,14 +40,7 @@ func init() { msgs = append(msgs, vpp_vpe.AllMessages()...) msgs = append(msgs, vpp_dhcp.AllMessages()...) - vppcalls.Versions["vpp2001_324"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, - vrfIdx vrfidx.VRFMetadataIndex, addrAlloc netalloc.AddressAllocator, log logging.Logger, - ) vppcalls.L3VppAPI { - return NewL3VppHandler(ch, ifIdx, vrfIdx, addrAlloc, log) - }, - } + vppcalls.AddHandlerVersion(vpp2001_324.Version, msgs, NewL3VppHandler) } type L3VppHandler struct { @@ -60,9 +53,12 @@ type L3VppHandler struct { } func NewL3VppHandler( - ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, vrfIdx vrfidx.VRFMetadataIndex, - addrAlloc netalloc.AddressAllocator, log logging.Logger, -) *L3VppHandler { + ch govppapi.Channel, + ifIdx ifaceidx.IfaceMetadataIndex, + vrfIdx vrfidx.VRFMetadataIndex, + addrAlloc netalloc.AddressAllocator, + log logging.Logger, +) vppcalls.L3VppAPI { return &L3VppHandler{ ArpVppHandler: NewArpVppHandler(ch, ifIdx, log), ProxyArpVppHandler: NewProxyArpVppHandler(ch, ifIdx, log), @@ -162,7 +158,7 @@ func NewIPNeighVppHandler(callsChan govppapi.Channel, log logging.Logger) *IPNei return &IPNeighHandler{ callsChannel: callsChan, log: log, - VppCoreAPI: vpp2001_324.NewVpeHandler(callsChan), + VppCoreAPI: vpe_vpp2001_324.NewVpeHandler(callsChan), } } diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vrf_dump_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vrf_dump_test.go index f5cd1b9f2a..6e59be9610 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vrf_dump_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vrf_dump_test.go @@ -21,12 +21,12 @@ import ( . "github.com/onsi/gomega" vpp_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/ip" vpp_vpe "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/vpe" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) func TestDumpVrfTables(t *testing.T) { - ctx := vppcallmock.SetupTestCtx(t) + ctx := vppmock.SetupTestCtx(t) defer ctx.TeardownTestCtx() vthandler := NewVrfTableVppHandler(ctx.MockChannel, logrus.DefaultLogger()) diff --git a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vrf_vppcalls_test.go b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vrf_vppcalls_test.go index 59fff01068..764bdb2066 100644 --- a/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vrf_vppcalls_test.go +++ b/plugins/vpp/l3plugin/vppcalls/vpp2001_324/vrf_vppcalls_test.go @@ -22,7 +22,7 @@ import ( vpp_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/ip" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/l3plugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" l3 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/l3" ) @@ -130,8 +130,8 @@ func TestDeleteVrfTable(t *testing.T) { Expect(err).To(Not(BeNil())) } -func vrfTableTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.VrfTableVppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func vrfTableTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.VrfTableVppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") vtHandler := vpp2001_324.NewVrfTableVppHandler(ctx.MockChannel, log) return ctx, vtHandler diff --git a/plugins/vpp/natplugin/vppcalls/nat_vppcalls.go b/plugins/vpp/natplugin/vppcalls/nat_vppcalls.go index ade5a8fce8..07d420bd56 100644 --- a/plugins/vpp/natplugin/vppcalls/nat_vppcalls.go +++ b/plugins/vpp/natplugin/vppcalls/nat_vppcalls.go @@ -65,7 +65,7 @@ var handler = vpp.RegisterHandler(vpp.HandlerDesc{ HandlerAPI: (*NatVppAPI)(nil), }) -func AddNatHandlerVersion(version string, msgs []govppapi.Message, +func AddNatHandlerVersion(version vpp.Version, msgs []govppapi.Message, h func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, dhcpIdx idxmap.NamedMapping, log logging.Logger) NatVppAPI, ) { handler.AddVersion(vpp.HandlerVersion{ diff --git a/plugins/vpp/natplugin/vppcalls/vpp1904/dump_nat_vppcalls_test.go b/plugins/vpp/natplugin/vppcalls/vpp1904/dump_nat_vppcalls_test.go index 8c7efceffb..59edc6b046 100644 --- a/plugins/vpp/natplugin/vppcalls/vpp1904/dump_nat_vppcalls_test.go +++ b/plugins/vpp/natplugin/vppcalls/vpp1904/dump_nat_vppcalls_test.go @@ -29,7 +29,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/natplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/natplugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" interfaces "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/interfaces" nat "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/nat" ) @@ -370,8 +370,8 @@ func TestDNATDump(t *testing.T) { Expect(dnat.IdMappings[1].Interface).To(BeEquivalentTo("if1")) } -func natTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.NatVppAPI, ifaceidx.IfaceMetadataIndexRW, idxmap.NamedMappingRW) { - ctx := vppcallmock.SetupTestCtx(t) +func natTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.NatVppAPI, ifaceidx.IfaceMetadataIndexRW, idxmap.NamedMappingRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") swIfIndexes := ifaceidx.NewIfaceIndex(logrus.DefaultLogger(), "test-sw_if_indexes") dhcpIndexes := idxmap_mem.NewNamedMapping(logrus.DefaultLogger(), "test-dhcp_indexes", nil) diff --git a/plugins/vpp/natplugin/vppcalls/vpp1908/dump_nat_vppcalls_test.go b/plugins/vpp/natplugin/vppcalls/vpp1908/dump_nat_vppcalls_test.go index 85bbaa8b4a..a8c13f590c 100644 --- a/plugins/vpp/natplugin/vppcalls/vpp1908/dump_nat_vppcalls_test.go +++ b/plugins/vpp/natplugin/vppcalls/vpp1908/dump_nat_vppcalls_test.go @@ -30,7 +30,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/natplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/natplugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestNat44GlobalConfigDump(t *testing.T) { @@ -358,8 +358,8 @@ func TestDNATDump(t *testing.T) { Expect(dnat.IdMappings[1].Interface).To(BeEquivalentTo("if1")) } -func natTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.NatVppAPI, ifaceidx.IfaceMetadataIndexRW, idxmap.NamedMappingRW) { - ctx := vppcallmock.SetupTestCtx(t) +func natTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.NatVppAPI, ifaceidx.IfaceMetadataIndexRW, idxmap.NamedMappingRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") swIfIndexes := ifaceidx.NewIfaceIndex(logrus.DefaultLogger(), "test-sw_if_indexes") dhcpIndexes := idxmap_mem.NewNamedMapping(logrus.DefaultLogger(), "test-dhcp_indexes", nil) diff --git a/plugins/vpp/natplugin/vppcalls/vpp2001/dump_nat_vppcalls_test.go b/plugins/vpp/natplugin/vppcalls/vpp2001/dump_nat_vppcalls_test.go index 3fc9f87ae6..2d9c8b9488 100644 --- a/plugins/vpp/natplugin/vppcalls/vpp2001/dump_nat_vppcalls_test.go +++ b/plugins/vpp/natplugin/vppcalls/vpp2001/dump_nat_vppcalls_test.go @@ -30,7 +30,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/natplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/natplugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestNat44GlobalConfigDump(t *testing.T) { @@ -358,8 +358,8 @@ func TestDNATDump(t *testing.T) { Expect(dnat.IdMappings[1].Interface).To(BeEquivalentTo("if1")) } -func natTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.NatVppAPI, ifaceidx.IfaceMetadataIndexRW, idxmap.NamedMappingRW) { - ctx := vppcallmock.SetupTestCtx(t) +func natTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.NatVppAPI, ifaceidx.IfaceMetadataIndexRW, idxmap.NamedMappingRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") swIfIndexes := ifaceidx.NewIfaceIndex(logrus.DefaultLogger(), "test-sw_if_indexes") dhcpIndexes := idxmap_mem.NewNamedMapping(logrus.DefaultLogger(), "test-dhcp_indexes", nil) diff --git a/plugins/vpp/natplugin/vppcalls/vpp2001_324/dump_nat_vppcalls_test.go b/plugins/vpp/natplugin/vppcalls/vpp2001_324/dump_nat_vppcalls_test.go index 45eb267eb0..abe3425276 100644 --- a/plugins/vpp/natplugin/vppcalls/vpp2001_324/dump_nat_vppcalls_test.go +++ b/plugins/vpp/natplugin/vppcalls/vpp2001_324/dump_nat_vppcalls_test.go @@ -30,7 +30,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/natplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/natplugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" ) func TestNat44GlobalConfigDump(t *testing.T) { @@ -358,8 +358,8 @@ func TestDNATDump(t *testing.T) { Expect(dnat.IdMappings[1].Interface).To(BeEquivalentTo("if1")) } -func natTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.NatVppAPI, ifaceidx.IfaceMetadataIndexRW, idxmap.NamedMappingRW) { - ctx := vppcallmock.SetupTestCtx(t) +func natTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.NatVppAPI, ifaceidx.IfaceMetadataIndexRW, idxmap.NamedMappingRW) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test-log") swIfIndexes := ifaceidx.NewIfaceIndex(logrus.DefaultLogger(), "test-sw_if_indexes") dhcpIndexes := idxmap_mem.NewNamedMapping(logrus.DefaultLogger(), "test-dhcp_indexes", nil) diff --git a/plugins/vpp/proxy_test.go b/plugins/vpp/proxy_test.go new file mode 100644 index 0000000000..aa75a439e2 --- /dev/null +++ b/plugins/vpp/proxy_test.go @@ -0,0 +1,104 @@ +// Copyright (c) 2019 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build proxy + +package vpp_test + +import ( + "context" + "encoding/gob" + "io" + "log" + "testing" + + "git.fd.io/govpp.git/api" + "git.fd.io/govpp.git/proxy" + + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/interfaces" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/vpe" +) + +func init() { + // this is required for proxy client encoder to work properly + for _, msg := range vpp1908.Messages.AllMessages() { + gob.Register(msg) + } +} + +// This test demonstrates how to use proxy to access VPP binapi and stats +// remotely via vpp-agent HTTP server. Run this test with: +// +// go test -v -tags proxy ./plugins/govppmux/vppcalls +// +func TestProxyClient(t *testing.T) { + // connect to proxy server + client, err := proxy.Connect(":9191") + if err != nil { + log.Fatalln("connecting to proxy failed:", err) + } + + // proxy stats + statsProvider, err := client.NewStatsClient() + if err != nil { + log.Fatalln(err) + } + + var sysStats api.SystemStats + if err := statsProvider.GetSystemStats(&sysStats); err != nil { + log.Fatalln("getting stats failed:", err) + } + log.Printf("SystemStats: %+v", sysStats) + + // proxy binapi + binapiChannel, err := client.NewBinapiClient() + if err != nil { + log.Fatalln(err) + } + + var msgs []api.Message + msgs = append(msgs, interfaces.AllMessages()...) + msgs = append(msgs, vpe.AllMessages()...) + if err := binapiChannel.CheckCompatiblity(msgs...); err != nil { + panic(err) + } + log.Println("compatibility OK!") + + // - using binapi message directly + req := &vpe.CliInband{Cmd: "show version"} + reply := new(vpe.CliInbandReply) + if err := binapiChannel.SendRequest(req).ReceiveReply(reply); err != nil { + log.Fatalln("binapi request failed:", err) + } + log.Printf("VPP version: %+v", reply.Reply) + + // - or using generated rpc service + svc := interfaces.NewServiceClient(binapiChannel) + stream, err := svc.DumpSwInterface(context.Background(), &interfaces.SwInterfaceDump{}) + if err != nil { + log.Fatalln("binapi request failed:", err) + } + log.Printf("dumping interfaces") + for { + iface, err := stream.Recv() + if err == io.EOF { + break + } + if err != nil { + log.Fatalln(err) + } + log.Printf("- interface %d: %v", iface.SwIfIndex, iface.InterfaceName) + } +} diff --git a/plugins/vpp/puntplugin/options.go b/plugins/vpp/puntplugin/options.go index 3e08f95e4f..7242fefb44 100644 --- a/plugins/vpp/puntplugin/options.go +++ b/plugins/vpp/puntplugin/options.go @@ -31,7 +31,7 @@ func NewPlugin(opts ...Option) *PuntPlugin { p.PluginName = "vpp-punt-plugin" p.KVScheduler = &kvscheduler.DefaultPlugin - p.GoVppmux = &govppmux.DefaultPlugin + p.VPP = &govppmux.DefaultPlugin p.IfPlugin = &ifplugin.DefaultPlugin for _, o := range opts { diff --git a/plugins/vpp/puntplugin/puntplugin.go b/plugins/vpp/puntplugin/puntplugin.go index 3d67e1bd99..9a72bd3079 100644 --- a/plugins/vpp/puntplugin/puntplugin.go +++ b/plugins/vpp/puntplugin/puntplugin.go @@ -21,11 +21,9 @@ package puntplugin import ( "strings" - govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/datasync" "github.com/ligato/cn-infra/health/statuscheck" "github.com/ligato/cn-infra/infra" - "github.com/pkg/errors" "go.ligato.io/vpp-agent/v2/pkg/models" "go.ligato.io/vpp-agent/v2/plugins/govppmux" @@ -46,9 +44,6 @@ import ( type PuntPlugin struct { Deps - // GoVPP - vppCh govppapi.Channel - // handler puntHandler vppcalls.PuntVppAPI @@ -62,7 +57,7 @@ type PuntPlugin struct { type Deps struct { infra.PluginDeps KVScheduler kvs.KVScheduler - GoVppmux govppmux.API + VPP govppmux.API IfPlugin ifplugin.API PublishState datasync.KeyProtoValWriter // optional StatusCheck statuscheck.PluginStatusWriter // optional @@ -70,13 +65,8 @@ type Deps struct { // Init registers STN-related descriptors. func (p *PuntPlugin) Init() (err error) { - // GoVPP channels - if p.vppCh, err = p.GoVppmux.NewAPIChannel(); err != nil { - return errors.Errorf("failed to create GoVPP API channel: %v", err) - } - // init punt handler - p.puntHandler = vppcalls.CompatiblePuntVppHandler(p.vppCh, p.IfPlugin.GetInterfaceIndex(), p.Log) + p.puntHandler = vppcalls.CompatiblePuntVppHandler(p.VPP, p.IfPlugin.GetInterfaceIndex(), p.Log) // init and register IP punt redirect p.ipRedirectDescriptor = descriptor.NewIPRedirectDescriptor(p.puntHandler, p.Log) diff --git a/plugins/vpp/puntplugin/vppcalls/punt_vppcalls.go b/plugins/vpp/puntplugin/vppcalls/punt_vppcalls.go index 28b749437a..e03e7e5005 100644 --- a/plugins/vpp/puntplugin/vppcalls/punt_vppcalls.go +++ b/plugins/vpp/puntplugin/vppcalls/punt_vppcalls.go @@ -20,6 +20,7 @@ import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" + "go.ligato.io/vpp-agent/v2/plugins/vpp" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" punt "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/punt" ) @@ -70,7 +71,7 @@ type PuntVppAPI interface { // PuntVPPRead provides read methods for punt type PuntVPPRead interface { - // DumpPuntRegisteredSockets returns all punt socket registrations known to the VPP agent + // DumpRegisteredPuntSockets returns all punt socket registrations known to the VPP agent DumpRegisteredPuntSockets() ([]*PuntDetails, error) // DumpExceptions dumps punt exceptions DumpExceptions() ([]*ExceptionDetails, error) @@ -80,27 +81,36 @@ type PuntVPPRead interface { DumpPuntRedirect() ([]*punt.IPRedirect, error) } -var Versions = map[string]HandlerVersion{} +var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ + Name: "punt", + HandlerAPI: (*PuntVppAPI)(nil), +}) -type HandlerVersion struct { - Msgs []govppapi.Message - New func(govppapi.Channel, ifaceidx.IfaceMetadataIndex, logging.Logger) PuntVppAPI +type NewHandlerFunc func(ch govppapi.Channel, idx ifaceidx.IfaceMetadataIndex, log logging.Logger) PuntVppAPI + +func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { + Handler.AddVersion(vpp.HandlerVersion{ + Version: version, + Check: func(c vpp.Client) error { + ch, err := c.NewAPIChannel() + if err != nil { + return err + } + return ch.CheckCompatiblity(msgs...) + }, + NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI { + ch, err := c.NewAPIChannel() + if err != nil { + return err + } + return h(ch, a[0].(ifaceidx.IfaceMetadataIndex), a[1].(logging.Logger)) + }, + }) } -func CompatiblePuntVppHandler( - ch govppapi.Channel, idx ifaceidx.IfaceMetadataIndex, log logging.Logger, -) PuntVppAPI { - if len(Versions) == 0 { - // puntplugin is not loaded - return nil - } - for ver, h := range Versions { - log.Debugf("checking compatibility with %s", ver) - if err := ch.CheckCompatiblity(h.Msgs...); err != nil { - continue - } - log.Debug("found compatible version:", ver) - return h.New(ch, idx, log) +func CompatiblePuntVppHandler(c vpp.Client, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) PuntVppAPI { + if v := Handler.FindCompatibleVersion(c); v != nil { + return v.NewHandler(c, ifIdx, log).(PuntVppAPI) } - panic("no compatible version available") + return nil } diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1904/punt_vppcalls_test.go b/plugins/vpp/puntplugin/vppcalls/vpp1904/punt_vppcalls_test.go index 72b6472086..5b52ec64b2 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1904/punt_vppcalls_test.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1904/punt_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/puntplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/puntplugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" punt "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/punt" ) @@ -205,8 +205,8 @@ func TestDeleteIPRedirect(t *testing.T) { //Expect(vppMsg.Nh).To(Equal([]uint8(net.ParseIP("10.0.0.1").To4()))) } -func puntTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.PuntVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func puntTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.PuntVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logger, "punt-if-idx") puntHandler := vpp1904.NewPuntVppHandler(ctx.MockChannel, ifIndexes, logrus.DefaultLogger()) diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1904/vppcalls_handler.go b/plugins/vpp/puntplugin/vppcalls/vpp1904/vppcalls_handler.go index 71c21190f5..1e1b5696bd 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1904/vppcalls_handler.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1904/vppcalls_handler.go @@ -21,6 +21,7 @@ import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904" ba_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/ip" ba_punt "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1904/punt" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" @@ -32,12 +33,7 @@ func init() { msgs = append(msgs, ba_ip.AllMessages()...) msgs = append(msgs, ba_punt.AllMessages()...) - vppcalls.Versions["vpp1904"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(channel govppapi.Channel, index ifaceidx.IfaceMetadataIndex, logger logging.Logger) vppcalls.PuntVppAPI { - return NewPuntVppHandler(channel, index, logger) - }, - } + vppcalls.AddHandlerVersion(vpp1904.Version, msgs, NewPuntVppHandler) } // PuntVppHandler is accessor for punt-related vppcalls methods. @@ -50,7 +46,7 @@ type PuntVppHandler struct { // NewPuntVppHandler creates new instance of punt vppcalls handler func NewPuntVppHandler( callsChan govppapi.Channel, ifIndexes ifaceidx.IfaceMetadataIndex, log logging.Logger, -) *PuntVppHandler { +) vppcalls.PuntVppAPI { return &PuntVppHandler{ callsChannel: callsChan, ifIndexes: ifIndexes, diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls_test.go b/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls_test.go index 73618f6ea6..81223af98e 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls_test.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1908/punt_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/puntplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/puntplugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" punt "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/punt" ) @@ -215,8 +215,8 @@ func TestDeleteIPRedirect(t *testing.T) { //Expect(vppMsg.Nh).To(Equal([]uint8(net.ParseIP("10.0.0.1").To4()))) } -func puntTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.PuntVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func puntTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.PuntVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logger, "punt-if-idx") puntHandler := vpp1908.NewPuntVppHandler(ctx.MockChannel, ifIndexes, logrus.DefaultLogger()) diff --git a/plugins/vpp/puntplugin/vppcalls/vpp1908/vppcalls_handler.go b/plugins/vpp/puntplugin/vppcalls/vpp1908/vppcalls_handler.go index 082f6d5167..4ff9169f24 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp1908/vppcalls_handler.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp1908/vppcalls_handler.go @@ -21,6 +21,7 @@ import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908" ba_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/ip" ba_punt "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp1908/punt" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" @@ -32,12 +33,7 @@ func init() { msgs = append(msgs, ba_ip.AllMessages()...) msgs = append(msgs, ba_punt.AllMessages()...) - vppcalls.Versions["vpp1908"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(channel govppapi.Channel, index ifaceidx.IfaceMetadataIndex, logger logging.Logger) vppcalls.PuntVppAPI { - return NewPuntVppHandler(channel, index, logger) - }, - } + vppcalls.AddHandlerVersion(vpp1908.Version, msgs, NewPuntVppHandler) } // PuntVppHandler is accessor for punt-related vppcalls methods. @@ -50,7 +46,7 @@ type PuntVppHandler struct { // NewPuntVppHandler creates new instance of punt vppcalls handler func NewPuntVppHandler( callsChan govppapi.Channel, ifIndexes ifaceidx.IfaceMetadataIndex, log logging.Logger, -) *PuntVppHandler { +) vppcalls.PuntVppAPI { return &PuntVppHandler{ callsChannel: callsChan, ifIndexes: ifIndexes, diff --git a/plugins/vpp/puntplugin/vppcalls/vpp2001/punt_vppcalls_test.go b/plugins/vpp/puntplugin/vppcalls/vpp2001/punt_vppcalls_test.go index a2e298fb55..ba4fa276f8 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp2001/punt_vppcalls_test.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp2001/punt_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/puntplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/puntplugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" punt "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/punt" ) @@ -215,8 +215,8 @@ func TestDeleteIPRedirect(t *testing.T) { //Expect(vppMsg.Nh).To(Equal([]uint8(net.ParseIP("10.0.0.1").To4()))) } -func puntTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.PuntVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func puntTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.PuntVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logger, "punt-if-idx") puntHandler := vpp2001.NewPuntVppHandler(ctx.MockChannel, ifIndexes, logrus.DefaultLogger()) diff --git a/plugins/vpp/puntplugin/vppcalls/vpp2001/vppcalls_handler.go b/plugins/vpp/puntplugin/vppcalls/vpp2001/vppcalls_handler.go index 4639922bbb..dee2d12a0c 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp2001/vppcalls_handler.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp2001/vppcalls_handler.go @@ -21,6 +21,7 @@ import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001" vpp_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/ip" vpp_punt "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001/punt" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" @@ -32,12 +33,7 @@ func init() { msgs = append(msgs, vpp_ip.AllMessages()...) msgs = append(msgs, vpp_punt.AllMessages()...) - vppcalls.Versions["vpp2001"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(channel govppapi.Channel, index ifaceidx.IfaceMetadataIndex, logger logging.Logger) vppcalls.PuntVppAPI { - return NewPuntVppHandler(channel, index, logger) - }, - } + vppcalls.AddHandlerVersion(vpp2001.Version, msgs, NewPuntVppHandler) } // PuntVppHandler is accessor for punt-related vppcalls methods. @@ -50,7 +46,7 @@ type PuntVppHandler struct { // NewPuntVppHandler creates new instance of punt vppcalls handler func NewPuntVppHandler( callsChan govppapi.Channel, ifIndexes ifaceidx.IfaceMetadataIndex, log logging.Logger, -) *PuntVppHandler { +) vppcalls.PuntVppAPI { return &PuntVppHandler{ callsChannel: callsChan, ifIndexes: ifIndexes, diff --git a/plugins/vpp/puntplugin/vppcalls/vpp2001_324/punt_vppcalls_test.go b/plugins/vpp/puntplugin/vppcalls/vpp2001_324/punt_vppcalls_test.go index f6151b75d2..2bf6f5f5eb 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp2001_324/punt_vppcalls_test.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp2001_324/punt_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/puntplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/puntplugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" punt "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/punt" ) @@ -215,8 +215,8 @@ func TestDeleteIPRedirect(t *testing.T) { //Expect(vppMsg.Nh).To(Equal([]uint8(net.ParseIP("10.0.0.1").To4()))) } -func puntTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.PuntVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func puntTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.PuntVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logger, "punt-if-idx") puntHandler := vpp2001_324.NewPuntVppHandler(ctx.MockChannel, ifIndexes, logrus.DefaultLogger()) diff --git a/plugins/vpp/puntplugin/vppcalls/vpp2001_324/vppcalls_handler.go b/plugins/vpp/puntplugin/vppcalls/vpp2001_324/vppcalls_handler.go index edc0c74066..022717b335 100644 --- a/plugins/vpp/puntplugin/vppcalls/vpp2001_324/vppcalls_handler.go +++ b/plugins/vpp/puntplugin/vppcalls/vpp2001_324/vppcalls_handler.go @@ -21,6 +21,7 @@ import ( govppapi "git.fd.io/govpp.git/api" "github.com/ligato/cn-infra/logging" + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324" vpp_ip "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/ip" vpp_punt "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi/vpp2001_324/punt" "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" @@ -32,12 +33,7 @@ func init() { msgs = append(msgs, vpp_ip.AllMessages()...) msgs = append(msgs, vpp_punt.AllMessages()...) - vppcalls.Versions["vpp2001_324"] = vppcalls.HandlerVersion{ - Msgs: msgs, - New: func(channel govppapi.Channel, index ifaceidx.IfaceMetadataIndex, logger logging.Logger) vppcalls.PuntVppAPI { - return NewPuntVppHandler(channel, index, logger) - }, - } + vppcalls.AddHandlerVersion(vpp2001_324.Version, msgs, NewPuntVppHandler) } // PuntVppHandler is accessor for punt-related vppcalls methods. @@ -50,7 +46,7 @@ type PuntVppHandler struct { // NewPuntVppHandler creates new instance of punt vppcalls handler func NewPuntVppHandler( callsChan govppapi.Channel, ifIndexes ifaceidx.IfaceMetadataIndex, log logging.Logger, -) *PuntVppHandler { +) vppcalls.PuntVppAPI { return &PuntVppHandler{ callsChannel: callsChan, ifIndexes: ifIndexes, diff --git a/plugins/vpp/srplugin/vppcalls/api_vppcalls.go b/plugins/vpp/srplugin/vppcalls/api_vppcalls.go index 8d024e2d21..72b1eed201 100644 --- a/plugins/vpp/srplugin/vppcalls/api_vppcalls.go +++ b/plugins/vpp/srplugin/vppcalls/api_vppcalls.go @@ -70,7 +70,7 @@ var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ type NewHandlerFunc func(vpp.Client, ifaceidx.IfaceMetadataIndex, logging.Logger) SRv6VppAPI -func AddHandlerVersion(version string, msgs []govppapi.Message, h NewHandlerFunc) { +func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { Handler.AddVersion(vpp.HandlerVersion{ Version: version, Check: func(c vpp.Client) error { diff --git a/plugins/vpp/srplugin/vppcalls/vpp1904/srv6_test.go b/plugins/vpp/srplugin/vppcalls/vpp1904/srv6_test.go index 295e896206..d2882e7b67 100644 --- a/plugins/vpp/srplugin/vppcalls/vpp1904/srv6_test.go +++ b/plugins/vpp/srplugin/vppcalls/vpp1904/srv6_test.go @@ -28,7 +28,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/srplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/srplugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" srv6 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/srv6" ) @@ -1448,8 +1448,8 @@ func TestRetrievePolicyIndexInfo(t *testing.T) { } } -func setup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.SRv6VppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func setup(t *testing.T) (*vppmock.TestCtx, vppcalls.SRv6VppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test") swIfIndex := ifaceidx.NewIfaceIndex(log, "test") swIfIndex.Put(ifaceA, &ifaceidx.IfaceMetadata{SwIfIndex: swIndexA}) @@ -1457,7 +1457,7 @@ func setup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.SRv6VppAPI) { return ctx, vppCalls } -func teardown(ctx *vppcallmock.TestCtx) { +func teardown(ctx *vppmock.TestCtx) { ctx.TeardownTestCtx() } diff --git a/plugins/vpp/srplugin/vppcalls/vpp1908/srv6_test.go b/plugins/vpp/srplugin/vppcalls/vpp1908/srv6_test.go index 7b41ea3276..eab78a1789 100644 --- a/plugins/vpp/srplugin/vppcalls/vpp1908/srv6_test.go +++ b/plugins/vpp/srplugin/vppcalls/vpp1908/srv6_test.go @@ -28,7 +28,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/srplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/srplugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" srv6 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/srv6" ) @@ -1448,8 +1448,8 @@ func TestRetrievePolicyIndexInfo(t *testing.T) { } } -func setup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.SRv6VppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func setup(t *testing.T) (*vppmock.TestCtx, vppcalls.SRv6VppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test") swIfIndex := ifaceidx.NewIfaceIndex(log, "test") swIfIndex.Put(ifaceA, &ifaceidx.IfaceMetadata{SwIfIndex: swIndexA}) @@ -1457,7 +1457,7 @@ func setup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.SRv6VppAPI) { return ctx, vppCalls } -func teardown(ctx *vppcallmock.TestCtx) { +func teardown(ctx *vppmock.TestCtx) { ctx.TeardownTestCtx() } diff --git a/plugins/vpp/srplugin/vppcalls/vpp2001/srv6_test.go b/plugins/vpp/srplugin/vppcalls/vpp2001/srv6_test.go index 9c477e0384..47bda7adb3 100644 --- a/plugins/vpp/srplugin/vppcalls/vpp2001/srv6_test.go +++ b/plugins/vpp/srplugin/vppcalls/vpp2001/srv6_test.go @@ -28,7 +28,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/srplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/srplugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" srv6 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/srv6" ) @@ -1448,8 +1448,8 @@ func TestRetrievePolicyIndexInfo(t *testing.T) { } } -func setup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.SRv6VppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func setup(t *testing.T) (*vppmock.TestCtx, vppcalls.SRv6VppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test") swIfIndex := ifaceidx.NewIfaceIndex(log, "test") swIfIndex.Put(ifaceA, &ifaceidx.IfaceMetadata{SwIfIndex: swIndexA}) @@ -1457,7 +1457,7 @@ func setup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.SRv6VppAPI) { return ctx, vppCalls } -func teardown(ctx *vppcallmock.TestCtx) { +func teardown(ctx *vppmock.TestCtx) { ctx.TeardownTestCtx() } diff --git a/plugins/vpp/srplugin/vppcalls/vpp2001_324/srv6_test.go b/plugins/vpp/srplugin/vppcalls/vpp2001_324/srv6_test.go index 4193a8079c..32a11d017a 100644 --- a/plugins/vpp/srplugin/vppcalls/vpp2001_324/srv6_test.go +++ b/plugins/vpp/srplugin/vppcalls/vpp2001_324/srv6_test.go @@ -28,7 +28,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/srplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/srplugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" srv6 "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/srv6" ) @@ -1448,8 +1448,8 @@ func TestRetrievePolicyIndexInfo(t *testing.T) { } } -func setup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.SRv6VppAPI) { - ctx := vppcallmock.SetupTestCtx(t) +func setup(t *testing.T) (*vppmock.TestCtx, vppcalls.SRv6VppAPI) { + ctx := vppmock.SetupTestCtx(t) log := logrus.NewLogger("test") swIfIndex := ifaceidx.NewIfaceIndex(log, "test") swIfIndex.Put(ifaceA, &ifaceidx.IfaceMetadata{SwIfIndex: swIndexA}) @@ -1457,7 +1457,7 @@ func setup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.SRv6VppAPI) { return ctx, vppCalls } -func teardown(ctx *vppcallmock.TestCtx) { +func teardown(ctx *vppmock.TestCtx) { ctx.TeardownTestCtx() } diff --git a/plugins/vpp/stnplugin/vppcalls/stn_vppcalls.go b/plugins/vpp/stnplugin/vppcalls/stn_vppcalls.go index 6f6b339a1b..8124a19606 100644 --- a/plugins/vpp/stnplugin/vppcalls/stn_vppcalls.go +++ b/plugins/vpp/stnplugin/vppcalls/stn_vppcalls.go @@ -40,7 +40,7 @@ type StnVppAPI interface { // AddSTNRule calls StnAddDelRule bin API with IsAdd=1 AddSTNRule(stnRule *stn.Rule) error - // DelSTNRule calls StnAddDelRule bin API with IsAdd=0 + // DeleteSTNRule calls StnAddDelRule bin API with IsAdd=0 DeleteSTNRule(stnRule *stn.Rule) error } @@ -57,7 +57,7 @@ var handler = vpp.RegisterHandler(vpp.HandlerDesc{ type NewHandlerFunc func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) StnVppAPI -func AddStnHandlerVersion(version string, msgs []govppapi.Message, h NewHandlerFunc) { +func AddStnHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { handler.AddVersion(vpp.HandlerVersion{ Version: version, Check: func(c vpp.Client) error { diff --git a/plugins/vpp/stnplugin/vppcalls/vpp1904/stn_vppcalls_test.go b/plugins/vpp/stnplugin/vppcalls/vpp1904/stn_vppcalls_test.go index 6b606db489..f57d774e24 100644 --- a/plugins/vpp/stnplugin/vppcalls/vpp1904/stn_vppcalls_test.go +++ b/plugins/vpp/stnplugin/vppcalls/vpp1904/stn_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/stnplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/stnplugin/vppcalls/vpp1904" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" stn "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/stn" ) @@ -142,8 +142,8 @@ func TestDelStnRule(t *testing.T) { Expect(vppMsg.IsAdd).To(BeEquivalentTo(0)) } -func stnTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.StnVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func stnTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.StnVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logger, "stn-if-idx") stnHandler := vpp1904.NewStnVppHandler(ctx.MockChannel, ifIndexes, logrus.DefaultLogger()) diff --git a/plugins/vpp/stnplugin/vppcalls/vpp1908/stn_vppcalls_test.go b/plugins/vpp/stnplugin/vppcalls/vpp1908/stn_vppcalls_test.go index 293eeb9be7..3ca3b4d7e4 100644 --- a/plugins/vpp/stnplugin/vppcalls/vpp1908/stn_vppcalls_test.go +++ b/plugins/vpp/stnplugin/vppcalls/vpp1908/stn_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/stnplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/stnplugin/vppcalls/vpp1908" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" stn "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/stn" ) @@ -142,8 +142,8 @@ func TestDelStnRule(t *testing.T) { Expect(vppMsg.IsAdd).To(BeEquivalentTo(0)) } -func stnTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.StnVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func stnTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.StnVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logger, "stn-if-idx") stnHandler := vpp1908.NewStnVppHandler(ctx.MockChannel, ifIndexes, logrus.DefaultLogger()) diff --git a/plugins/vpp/stnplugin/vppcalls/vpp2001/stn_vppcalls_test.go b/plugins/vpp/stnplugin/vppcalls/vpp2001/stn_vppcalls_test.go index 2a26d64e50..a47f61d792 100644 --- a/plugins/vpp/stnplugin/vppcalls/vpp2001/stn_vppcalls_test.go +++ b/plugins/vpp/stnplugin/vppcalls/vpp2001/stn_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/stnplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/stnplugin/vppcalls/vpp2001" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" stn "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/stn" ) @@ -142,8 +142,8 @@ func TestDelStnRule(t *testing.T) { Expect(vppMsg.IsAdd).To(BeEquivalentTo(0)) } -func stnTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.StnVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func stnTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.StnVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logger, "stn-if-idx") stnHandler := vpp2001.NewStnVppHandler(ctx.MockChannel, ifIndexes, logrus.DefaultLogger()) diff --git a/plugins/vpp/stnplugin/vppcalls/vpp2001_324/stn_vppcalls_test.go b/plugins/vpp/stnplugin/vppcalls/vpp2001_324/stn_vppcalls_test.go index 448ac7f4ad..a7474c20b6 100644 --- a/plugins/vpp/stnplugin/vppcalls/vpp2001_324/stn_vppcalls_test.go +++ b/plugins/vpp/stnplugin/vppcalls/vpp2001_324/stn_vppcalls_test.go @@ -25,7 +25,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/ifplugin/ifaceidx" "go.ligato.io/vpp-agent/v2/plugins/vpp/stnplugin/vppcalls" "go.ligato.io/vpp-agent/v2/plugins/vpp/stnplugin/vppcalls/vpp2001_324" - "go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock" + "go.ligato.io/vpp-agent/v2/plugins/vpp/vppmock" stn "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/stn" ) @@ -142,8 +142,8 @@ func TestDelStnRule(t *testing.T) { Expect(vppMsg.IsAdd).To(BeEquivalentTo(0)) } -func stnTestSetup(t *testing.T) (*vppcallmock.TestCtx, vppcalls.StnVppAPI, ifaceidx.IfaceMetadataIndexRW) { - ctx := vppcallmock.SetupTestCtx(t) +func stnTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.StnVppAPI, ifaceidx.IfaceMetadataIndexRW) { + ctx := vppmock.SetupTestCtx(t) logger := logrus.NewLogger("test-log") ifIndexes := ifaceidx.NewIfaceIndex(logger, "stn-if-idx") stnHandler := vpp2001_324.NewStnVppHandler(ctx.MockChannel, ifIndexes, logrus.DefaultLogger()) diff --git a/plugins/vpp/stnplugin/vppcalls/vpp2001_324/vppcalls_handler.go b/plugins/vpp/stnplugin/vppcalls/vpp2001_324/vppcalls_handler.go index 3180fa41d3..71b333f603 100644 --- a/plugins/vpp/stnplugin/vppcalls/vpp2001_324/vppcalls_handler.go +++ b/plugins/vpp/stnplugin/vppcalls/vpp2001_324/vppcalls_handler.go @@ -24,28 +24,7 @@ import ( "go.ligato.io/vpp-agent/v2/plugins/vpp/stnplugin/vppcalls" ) -/*var HandlerVersion = vpp.HandlerVersion{ - Version: vpp2001_324.Version, - Check: func(c vpp.VPPClient) error { - var msgs []govppapi.Message - msgs = append(msgs, stn.AllMessages()...) - ch, err := c.NewAPIChannel() - if err != nil { - return err - } - return ch.CheckCompatiblity(msgs...) - }, - NewHandler: func(c vpp.VPPClient, a ...interface{}) vpp.HandlerAPI { - ch, err := c.NewAPIChannel() - if err != nil { - return err - } - return NewStnVppHandler(ch, a[0].(ifaceidx.IfaceMetadataIndex), a[1].(logging.Logger)) - }, -}*/ - func init() { - //vppcalls.AddVersion(HandlerVersion) var msgs []govppapi.Message msgs = append(msgs, vpp_stn.AllMessages()...) diff --git a/plugins/vpp/utils.go b/plugins/vpp/utils.go index 179178e02c..6871a24bdf 100644 --- a/plugins/vpp/utils.go +++ b/plugins/vpp/utils.go @@ -14,30 +14,12 @@ package vpp -import govppapi "git.fd.io/govpp.git/api" +import ( + govppapi "git.fd.io/govpp.git/api" -// MessagesList aggregates multiple funcs that return messages. -type MessagesList []func() []govppapi.Message + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi" +) -// Messages is used to initialize message list. -func Messages(funcs ...func() []govppapi.Message) MessagesList { - var list MessagesList - list.Add(funcs...) - return list -} - -// Add adds funcs to message list. -func (list *MessagesList) Add(funcs ...func() []govppapi.Message) { - for _, msgFunc := range funcs { - *list = append(*list, msgFunc) - } -} - -// AllMessages returns messages from message list funcs combined. -func (list *MessagesList) AllMessages() []govppapi.Message { - var msgs []govppapi.Message - for _, msgFunc := range *list { - msgs = append(msgs, msgFunc()...) - } - return msgs +func Messages(funcs ...func() []govppapi.Message) binapi.MessagesList { + return binapi.Messages(funcs...) } diff --git a/plugins/vpp/vpp.go b/plugins/vpp/vpp.go index df8cf1cfd4..48de870b2f 100644 --- a/plugins/vpp/vpp.go +++ b/plugins/vpp/vpp.go @@ -16,39 +16,57 @@ package vpp import ( "errors" + "fmt" govppapi "git.fd.io/govpp.git/api" + "github.com/ligato/cn-infra/logging" + + "go.ligato.io/vpp-agent/v2/plugins/vpp/binapi" ) var ( // ErrIncompatible is an error returned when no compatible handler is found. ErrIncompatible = errors.New("incompatible handler") - // ErrNoVersions is an error returned when no handler versions are found. ErrNoVersions = errors.New("no handler versions") - // ErrPluginDisabled is an error returned when disabled plugin is detected. ErrPluginDisabled = errors.New("plugin not available") ) -// Version defines a VPP version -type Version string - -type APIChannel interface { - govppapi.Channel -} +type Version = binapi.Version // Client provides methods for managing VPP. type Client interface { - govppapi.ChannelProvider + CompatibilityChecker + // NewAPIChannel returns new channel for sending binapi requests. + NewAPIChannel() (govppapi.Channel, error) + // Stats provides access to VPP stats API. + Stats() govppapi.StatsProvider // IsPluginLoaded returns true if the given plugin is currently loaded. IsPluginLoaded(plugin string) bool +} +type CompatibilityChecker interface { + // CheckCompatiblity checks compatibility with given binapi messages. CheckCompatiblity(...govppapi.Message) error +} - // Stats provides access to VPP stats API. - Stats() govppapi.StatsProvider - - StatsConnected() bool +func FindCompatibleBinapi(ch CompatibilityChecker) (binapi.Version, error) { + if len(binapi.Versions) == 0 { + return "", fmt.Errorf("no binapi versions loaded") + } + logging.Debugf("checking compatibility for %d binapi versions", len(binapi.Versions)) + for version, msgList := range binapi.Versions { + msgs := msgList.AllMessages() + if err := ch.CheckCompatiblity(msgs...); err == nil { + logging.Debugf("found compatible binapi version: %v", version) + return version, nil + } else if ierr, ok := err.(*govppapi.CompatibilityError); ok { + logging.Debugf("binapi version %-15v incompatible: %d/%d incompatible messages", version, len(ierr.IncompatibleMessages), len(msgs)) + } else { + logging.Warnf("binapi version %v check failed: %v", version, err) + } + } + return "", fmt.Errorf("no compatible binapi version found") } diff --git a/cmd/vpp-agent/app/app_test.go b/plugins/vpp/vpp_test.go similarity index 64% rename from cmd/vpp-agent/app/app_test.go rename to plugins/vpp/vpp_test.go index 588c7aeaed..254223edf3 100644 --- a/cmd/vpp-agent/app/app_test.go +++ b/plugins/vpp/vpp_test.go @@ -12,23 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -package app +package vpp -import ( - "log" - "strings" - "testing" - - "go.ligato.io/vpp-agent/v2/plugins/vpp" -) - -func TestHandlers(t *testing.T) { - handlers := vpp.GetHandlers() - - log.Printf("listing %d handlers:", len(handlers)) - - for h, handler := range handlers { - versions := strings.Join(handler.Versions(), ", ") - log.Printf(" - %s (%v)", h, versions) - } +func ClearRegisteredHandlers() { + registeredHandlers = map[string]*Handler{} } diff --git a/plugins/vpp/vppcallmock/vppcallmock.go b/plugins/vpp/vppmock/vppmock.go similarity index 95% rename from plugins/vpp/vppcallmock/vppcallmock.go rename to plugins/vpp/vppmock/vppmock.go index 8b32a084d8..2b7070fa03 100644 --- a/plugins/vpp/vppcallmock/vppcallmock.go +++ b/plugins/vpp/vppmock/vppmock.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package vppcallmock +package vppmock import ( "context" @@ -23,11 +23,14 @@ import ( govpp "git.fd.io/govpp.git/core" log "github.com/ligato/cn-infra/logging/logrus" . "github.com/onsi/gomega" + + "go.ligato.io/vpp-agent/v2/plugins/vpp" ) -// TestCtx is helping structure for unit testing. +// TestCtx is a helper for unit testing. // It wraps VppAdapter which is used instead of real VPP. type TestCtx struct { + //*GomegaWithT Context context.Context MockVpp *mock.VppAdapter MockStats *mock.StatsAdapter @@ -40,8 +43,10 @@ type TestCtx struct { // SetupTestCtx sets up all fields of TestCtx structure at the begining of test func SetupTestCtx(t *testing.T) *TestCtx { RegisterTestingT(t) + //g := NewGomegaWithT(t) // TODO: use GomegaWithT ctx := &TestCtx{ + //GomegaWithT: g, Context: context.Background(), MockVpp: mock.NewVppAdapter(), MockStats: mock.NewStatsAdapter(), @@ -205,9 +210,14 @@ func (ctx *TestCtx) MockReplies(dataList []*HandleReplies) { type mockVPPClient struct { *mockedChannel + version vpp.Version unloadedPlugins map[string]bool } +func (m *mockVPPClient) Version() vpp.Version { + return m.version +} + func (m *mockVPPClient) NewAPIChannel() (govppapi.Channel, error) { return m.mockedChannel, nil } @@ -227,7 +237,3 @@ func (m *mockVPPClient) IsPluginLoaded(plugin string) bool { func (m *mockVPPClient) Stats() govppapi.StatsProvider { panic("implement me") } - -func (m *mockVPPClient) StatsConnected() bool { - panic("implement me") -} diff --git a/tests/integration/vpp/020_routes_test.go b/tests/integration/vpp/020_routes_test.go index cc54ac401b..8129a4fbbd 100644 --- a/tests/integration/vpp/020_routes_test.go +++ b/tests/integration/vpp/020_routes_test.go @@ -38,7 +38,7 @@ func TestRoutes(t *testing.T) { vrfIndexes.Put("vrf1-ipv4", &vrfidx.VRFMetadata{Index: 0, Protocol: vpp_l3.VrfTable_IPV4}) vrfIndexes.Put("vrf1-ipv6", &vrfidx.VRFMetadata{Index: 0, Protocol: vpp_l3.VrfTable_IPV6}) - h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppBinapi, ifIndexes, vrfIndexes, + h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppClient, ifIndexes, vrfIndexes, netalloc_mock.NewMockNetAlloc(), logrus.NewLogger("test")) routes, err := h.DumpRoutes() @@ -88,7 +88,7 @@ func TestCRUDIPv4Route(t *testing.T) { vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf") vrfIndexes.Put("vrf1-ipv4-vrf0", &vrfidx.VRFMetadata{Index: vrfMetaIdx, Protocol: vpp_l3.VrfTable_IPV4}) - h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppBinapi, ifIndexes, vrfIndexes, + h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppClient, ifIndexes, vrfIndexes, netalloc_mock.NewMockNetAlloc(), logrus.NewLogger("test")) routes, errx := h.DumpRoutes() @@ -237,7 +237,7 @@ func TestCRUDIPv6Route(t *testing.T) { vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf") vrfIndexes.Put("vrf1-ipv6-vrf0", &vrfidx.VRFMetadata{Index: vrfMetaIdx, Protocol: vpp_l3.VrfTable_IPV6}) - h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppBinapi, ifIndexes, vrfIndexes, + h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppClient, ifIndexes, vrfIndexes, netalloc_mock.NewMockNetAlloc(), logrus.NewLogger("test")) routes, errx := h.DumpRoutes() diff --git a/tests/integration/vpp/030_arp_test.go b/tests/integration/vpp/030_arp_test.go index b60b5320c6..5b5d4e7484 100644 --- a/tests/integration/vpp/030_arp_test.go +++ b/tests/integration/vpp/030_arp_test.go @@ -47,7 +47,7 @@ func TestArp(t *testing.T) { vrfIndexes.Put("vrf1-ipv4", &vrfidx.VRFMetadata{Index: 0, Protocol: vpp_l3.VrfTable_IPV4}) vrfIndexes.Put("vrf1-ipv6", &vrfidx.VRFMetadata{Index: 0, Protocol: vpp_l3.VrfTable_IPV6}) - h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppBinapi, ifIndexes, vrfIndexes, + h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppClient, ifIndexes, vrfIndexes, netalloc_mock.NewMockNetAlloc(), logrus.NewLogger("test")) tests := []struct { diff --git a/tests/integration/vpp/110_srv6_test.go b/tests/integration/vpp/110_srv6_test.go index b10072317d..aa6375ec19 100644 --- a/tests/integration/vpp/110_srv6_test.go +++ b/tests/integration/vpp/110_srv6_test.go @@ -88,7 +88,7 @@ func TestLocalsidCRUD(t *testing.T) { vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf") vrfIndexes.Put("vrf1-ipv4", &vrfidx.VRFMetadata{Index: 0, Protocol: vpp_l3.VrfTable_IPV4}) vrfIndexes.Put("vrf1-ipv6", &vrfidx.VRFMetadata{Index: 0, Protocol: vpp_l3.VrfTable_IPV6}) - l3h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppBinapi, ifIndexes, vrfIndexes, + l3h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppClient, ifIndexes, vrfIndexes, netalloc_mock.NewMockNetAlloc(), logrus.NewLogger("test-l3")) for _, vrfTable := range vrfTables[:4] { Expect(l3h.AddVrfTable(vrfTable)).Should(Succeed(), fmt.Sprintf("fixture setup failed "+ diff --git a/tests/integration/vpp/integration_test.go b/tests/integration/vpp/integration_test.go index c40a142366..d2f2dfc9d6 100644 --- a/tests/integration/vpp/integration_test.go +++ b/tests/integration/vpp/integration_test.go @@ -34,6 +34,7 @@ import ( . "github.com/onsi/gomega" "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls" + "go.ligato.io/vpp-agent/v2/plugins/vpp" ) const ( @@ -68,13 +69,13 @@ const ( type TestCtx struct { t *testing.T Context context.Context - VPP *exec.Cmd + vppCmd *exec.Cmd stderr, stdout *bytes.Buffer Conn *govppcore.Connection StatsConn *govppcore.StatsConnection vppBinapi govppapi.Channel vppStats govppapi.StatsProvider - vpe vppcalls.VppCoreAPI + vpp vppcalls.VppCoreAPI versionInfo *vppcalls.VersionInfo vppClient *vppClient } @@ -224,8 +225,8 @@ func setupVPP(t *testing.T) *TestCtx { t: t, Context: ctx, versionInfo: versionInfo, - vpe: vpeHandler, - VPP: vppCmd, + vpp: vpeHandler, + vppCmd: vppCmd, stderr: &stderr, stdout: &stdout, Conn: conn, @@ -254,14 +255,14 @@ func (ctx *TestCtx) teardownVPP() { ctx.t.Logf("VPP disconnect timeout") } - if err := ctx.VPP.Process.Signal(syscall.SIGTERM); err != nil { + if err := ctx.vppCmd.Process.Signal(syscall.SIGTERM); err != nil { ctx.t.Fatalf("sending SIGTERM to VPP failed: %v", err) } // wait until VPP exits exit := make(chan struct{}) go func() { - if err := ctx.VPP.Wait(); err != nil { + if err := ctx.vppCmd.Wait(); err != nil { ctx.t.Logf("VPP process wait failed: %v", err) } close(exit) @@ -273,7 +274,7 @@ func (ctx *TestCtx) teardownVPP() { case <-time.After(vppExitTimeout): ctx.t.Logf("VPP exit timeout") ctx.t.Logf("sending SIGKILL to VPP..") - if err := ctx.VPP.Process.Signal(syscall.SIGKILL); err != nil { + if err := ctx.vppCmd.Process.Signal(syscall.SIGKILL); err != nil { ctx.t.Fatalf("sending SIGKILL to VPP failed: %v", err) } } @@ -282,9 +283,14 @@ func (ctx *TestCtx) teardownVPP() { type vppClient struct { t *testing.T govppapi.ChannelProvider - ch govppapi.Channel - stats govppapi.StatsProvider - vpp vppcalls.VppCoreAPI + ch govppapi.Channel + stats govppapi.StatsProvider + vpp vppcalls.VppCoreAPI + version vpp.Version +} + +func (m *vppClient) Version() vpp.Version { + return m.version } func (v *vppClient) CheckCompatiblity(msgs ...govppapi.Message) error { @@ -295,10 +301,6 @@ func (v *vppClient) Stats() govppapi.StatsProvider { return v.stats } -func (v *vppClient) StatsConnected() bool { - return v.stats != nil -} - func (v *vppClient) IsPluginLoaded(plugin string) bool { ctx := context.Background() plugins, err := v.vpp.GetPlugins(ctx)