From bacb59ebebc8067cb9c5c3b7885e252997033549 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Fri, 7 Jun 2019 13:33:17 +0200 Subject: [PATCH] Retrieve cmdline (config) after conencting to VPP (#1381) Signed-off-by: Ondrej Fabry --- plugins/govppmux/plugin_impl_govppmux.go | 118 +++++++++++------- .../govppmux/vppcalls/vpp1901/vpe_vppcalls.go | 3 +- .../govppmux/vppcalls/vpp1904/vpe_vppcalls.go | 3 +- .../govppmux/vppcalls/vpp1908/vpe_vppcalls.go | 3 +- 4 files changed, 77 insertions(+), 50 deletions(-) diff --git a/plugins/govppmux/plugin_impl_govppmux.go b/plugins/govppmux/plugin_impl_govppmux.go index c21c7957cc..7c20502635 100644 --- a/plugins/govppmux/plugin_impl_govppmux.go +++ b/plugins/govppmux/plugin_impl_govppmux.go @@ -16,7 +16,9 @@ package govppmux import ( "context" + "fmt" "os" + "strings" "sync" "time" @@ -26,6 +28,7 @@ import ( "github.com/ligato/cn-infra/datasync/resync" "github.com/ligato/cn-infra/health/statuscheck" "github.com/ligato/cn-infra/infra" + "github.com/ligato/cn-infra/logging" "github.com/ligato/cn-infra/logging/measure" "github.com/ligato/cn-infra/logging/measure/model/apitrace" "github.com/pkg/errors" @@ -162,9 +165,9 @@ func (p *Plugin) Init() error { // TODO: Async connect & automatic reconnect support is not yet implemented in the agent, // so synchronously wait until connected to VPP. + startTime := time.Now() p.Log.Debugf("connecting to VPP..") - startTime := time.Now() p.vppConn, p.vppConChan, err = govpp.AsyncConnect(p.vppAdapter, p.config.RetryConnectCount, p.config.RetryConnectTimeout) if err != nil { return err @@ -182,10 +185,10 @@ func (p *Plugin) Init() error { } } - vppConnectTime := time.Since(startTime) - p.Log.Debugf("connection to VPP established (took %s)", vppConnectTime.Round(time.Millisecond)) + connectDur := time.Since(startTime) + p.Log.Debugf("connection to VPP established (took %s)", connectDur.Round(time.Millisecond)) - if err := p.updateVPPInfo(p.vppConn); err != nil { + if err := p.updateVPPInfo(); err != nil { return errors.WithMessage(err, "retrieving VPP info failed") } @@ -241,6 +244,69 @@ func (p *Plugin) Close() error { return nil } +// VPPInfo returns information about VPP session. +func (p *Plugin) VPPInfo() (VPPInfo, error) { + p.infoMu.Lock() + defer p.infoMu.Unlock() + return p.vppInfo, nil +} + +func (p *Plugin) updateVPPInfo() error { + if p.vppConn == nil { + return fmt.Errorf("VPP connection is nil") + } + + vppAPIChan, err := p.vppConn.NewAPIChannel() + if err != nil { + return err + } + defer vppAPIChan.Close() + + vpeHandler := vppcalls.CompatibleVpeHandler(vppAPIChan) + + version, err := vpeHandler.RunCli("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("show version cmdline") + if err != nil { + p.Log.Warnf("RunCli error: %v", err) + } else { + out := strings.Replace(cmdline, "\n", "", -1) + p.Log.Debugf("vpp# show version cmdline:\n%s", out) + } + + ver, err := vpeHandler.GetVersionInfo() + if err != nil { + return err + } + + p.Log.Infof("VPP version: %v", ver.Version) + + vpe, err := vpeHandler.GetVpeInfo() + if err != nil { + return err + } + + p.Log.WithFields(logging.Fields{ + "PID": vpe.PID, + "ClientID": vpe.ClientIdx, + }).Debugf("loaded %d VPP modules: %v", len(vpe.ModuleVersions), vpe.ModuleVersions) + + p.infoMu.Lock() + p.vppInfo = VPPInfo{ + Connected: true, + VersionInfo: *ver, + VpeInfo: *vpe, + } + p.infoMu.Unlock() + + return nil +} + // NewAPIChannel returns a new API channel for communication with VPP via govpp core. // It uses default buffer sizes for the request and reply Go channels. // @@ -349,7 +415,7 @@ func (p *Plugin) handleVPPConnectionEvents(ctx context.Context) { select { case event := <-p.vppConChan: if event.State == govpp.Connected { - if err := p.updateVPPInfo(p.vppConn); err != nil { + if err := p.updateVPPInfo(); err != nil { p.Log.Errorf("updating VPP info failed: %v", err) } @@ -383,45 +449,3 @@ func (p *Plugin) handleVPPConnectionEvents(ctx context.Context) { } } } - -// VPPInfo returns information about VPP session. -func (p *Plugin) VPPInfo() (VPPInfo, error) { - p.infoMu.Lock() - defer p.infoMu.Unlock() - return p.vppInfo, nil -} - -func (p *Plugin) updateVPPInfo(provider govppapi.ChannelProvider) error { - vppAPIChan, err := provider.NewAPIChannel() - if err != nil { - return err - } - defer vppAPIChan.Close() - - vpeHandler := vppcalls.CompatibleVpeHandler(vppAPIChan) - - ver, err := vpeHandler.GetVersionInfo() - if err != nil { - return err - } - - p.Log.Infof("VPP version: %v", ver.Version) - - vpe, err := vpeHandler.GetVpeInfo() - if err != nil { - return err - } - - p.Log.Debugf("VPP session details: PID=%d ClientIdx=%d", vpe.PID, vpe.ClientIdx) - p.Log.Debugf("loaded %d VPP modules: %v", len(vpe.ModuleVersions), vpe.ModuleVersions) - - p.infoMu.Lock() - p.vppInfo = VPPInfo{ - Connected: true, - VersionInfo: *ver, - VpeInfo: *vpe, - } - p.infoMu.Unlock() - - return nil -} diff --git a/plugins/govppmux/vppcalls/vpp1901/vpe_vppcalls.go b/plugins/govppmux/vppcalls/vpp1901/vpe_vppcalls.go index f19b188ca6..688e78e2e7 100644 --- a/plugins/govppmux/vppcalls/vpp1901/vpe_vppcalls.go +++ b/plugins/govppmux/vppcalls/vpp1901/vpe_vppcalls.go @@ -19,6 +19,7 @@ import ( "strings" govppapi "git.fd.io/govpp.git/api" + "github.com/pkg/errors" "github.com/ligato/vpp-agent/plugins/govppmux/vppcalls" "github.com/ligato/vpp-agent/plugins/vpp/binapi/vpp1901/memclnt" @@ -118,7 +119,7 @@ func (h *VpeHandler) RunCli(cmd string) (string, error) { reply := &vpe.CliInbandReply{} if err := h.ch.SendRequest(req).ReceiveReply(reply); err != nil { - return "", err + return "", errors.Wrapf(err, "running VPP CLI command '%s' failed", cmd) } return reply.Reply, nil diff --git a/plugins/govppmux/vppcalls/vpp1904/vpe_vppcalls.go b/plugins/govppmux/vppcalls/vpp1904/vpe_vppcalls.go index 07377f618d..09050d19f4 100644 --- a/plugins/govppmux/vppcalls/vpp1904/vpe_vppcalls.go +++ b/plugins/govppmux/vppcalls/vpp1904/vpe_vppcalls.go @@ -19,6 +19,7 @@ import ( "strings" govppapi "git.fd.io/govpp.git/api" + "github.com/pkg/errors" "github.com/ligato/vpp-agent/plugins/govppmux/vppcalls" "github.com/ligato/vpp-agent/plugins/vpp/binapi/vpp1904/memclnt" @@ -118,7 +119,7 @@ func (h *VpeHandler) RunCli(cmd string) (string, error) { reply := &vpe.CliInbandReply{} if err := h.ch.SendRequest(req).ReceiveReply(reply); err != nil { - return "", err + return "", errors.Wrapf(err, "running VPP CLI command '%s' failed", cmd) } return reply.Reply, nil diff --git a/plugins/govppmux/vppcalls/vpp1908/vpe_vppcalls.go b/plugins/govppmux/vppcalls/vpp1908/vpe_vppcalls.go index b392e724ec..9a589c42cc 100644 --- a/plugins/govppmux/vppcalls/vpp1908/vpe_vppcalls.go +++ b/plugins/govppmux/vppcalls/vpp1908/vpe_vppcalls.go @@ -19,6 +19,7 @@ import ( "strings" govppapi "git.fd.io/govpp.git/api" + "github.com/pkg/errors" "github.com/ligato/vpp-agent/plugins/govppmux/vppcalls" "github.com/ligato/vpp-agent/plugins/vpp/binapi/vpp1908/memclnt" @@ -118,7 +119,7 @@ func (h *VpeHandler) RunCli(cmd string) (string, error) { reply := &vpe.CliInbandReply{} if err := h.ch.SendRequest(req).ReceiveReply(reply); err != nil { - return "", err + return "", errors.Wrapf(err, "running VPP CLI command '%s' failed", cmd) } return reply.Reply, nil