Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Improve VPP handler versions and add VPP proxy support #1593

Merged
merged 11 commits into from
Jan 8, 2020
5 changes: 1 addition & 4 deletions cmd/vpp-agent/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package app

import (
"log"
"strings"
"testing"

"go.ligato.io/vpp-agent/v2/plugins/vpp"
Expand All @@ -26,9 +25,7 @@ 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)
log.Printf(" - %s (%v)", h, handler.Versions())
}
}
24 changes: 5 additions & 19 deletions plugins/configurator/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -53,9 +50,6 @@ type Plugin struct {
Deps

configurator configuratorServer

// Channels
vppChan api.Channel
}

// Deps - dependencies of Plugin
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/govppmux/client_binapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}
Expand Down
7 changes: 7 additions & 0 deletions plugins/govppmux/plugin_impl_govppmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ 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/govppmux/vppcalls/vpp1904"
_ "go.ligato.io/vpp-agent/v2/plugins/govppmux/vppcalls/vpp1908"
Expand Down Expand Up @@ -296,6 +297,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
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/govppmux/vppcalls/vpp_handler_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ func (p PluginInfo) String() string {
}

var Handler = vpp.RegisterHandler(vpp.HandlerDesc{
Name: "vppcore",
Name: "core",
HandlerAPI: (*VppCoreAPI)(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 {
Expand Down
27 changes: 8 additions & 19 deletions plugins/restapi/plugin_restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ import (
"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"
Expand Down Expand Up @@ -65,9 +62,6 @@ type Plugin struct {
// Index page
index *index

// Channels
vppChan api.Channel

// Handlers
vpeHandler vpevppcalls.VppCoreAPI
teleHandler telemetryvppcalls.TelemetryVppAPI
Expand Down Expand Up @@ -115,11 +109,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()
Expand All @@ -145,15 +134,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")
}
Expand All @@ -171,7 +160,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")
}
Expand Down Expand Up @@ -221,8 +210,8 @@ func (p *Plugin) AfterInit() (err error) {
}

// 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
Expand Down
51 changes: 11 additions & 40 deletions plugins/telemetry/vppcalls/telemetry_handler_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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{
ondrej-fabry marked this conversation as resolved.
Show resolved Hide resolved
Version: version,
Check: func(c vpp.Client) error {
Expand All @@ -181,44 +182,14 @@ func CompatibleTelemetryHandler(c vpp.Client) TelemetryVppAPI {
if c.StatsConnected() {
return NewTelemetryVppStats(c.Stats())
}
if !FallbackToCli {
log.Warnf("stats unavailable and fallback to CLI disabled for telemetry")
return nil
}

/*ctx := context.TODO()
ch, err := c.NewAPIChannel()
if err != nil {
log.Warnf("failed to create API channel: %v", err)
return nil
}
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)
if FallbackToCli {
if v := Handler.FindCompatibleVersion(c); v != nil {
log.Debugf("falling back to parsing CLI output for telemetry")
return v.NewHandler(c).(TelemetryVppAPI)
}
// no compatible version found
return nil
ondrej-fabry marked this conversation as resolved.
Show resolved Hide resolved
}
for ver, h := range Versions {
if err := ch.CheckCompatiblity(h.Msgs...); err != nil {
log.Debugf("version %s not compatible: %v", ver, err)
continue
}
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
log.Warnf("stats connection not available for telemetry")
return nil
}
7 changes: 4 additions & 3 deletions plugins/telemetry/vppcalls/vpp1904/telemetry_vppcalls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions plugins/telemetry/vppcalls/vpp1908/telemetry_vppcalls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions plugins/telemetry/vppcalls/vpp2001/telemetry_vppcalls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Loading