Skip to content

Commit

Permalink
Retrieve cmdline (config) after conencting to VPP (#1381)
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Fabry <[email protected]>
  • Loading branch information
ondrej-fabry authored Jun 7, 2019
1 parent de2c4f5 commit bacb59e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 50 deletions.
118 changes: 71 additions & 47 deletions plugins/govppmux/plugin_impl_govppmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package govppmux

import (
"context"
"fmt"
"os"
"strings"
"sync"
"time"

Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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")
}

Expand Down Expand Up @@ -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.
//
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion plugins/govppmux/vppcalls/vpp1901/vpe_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion plugins/govppmux/vppcalls/vpp1904/vpe_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion plugins/govppmux/vppcalls/vpp1908/vpe_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bacb59e

Please sign in to comment.