Skip to content

Commit

Permalink
Support for VPP 23.06 (ligato#1932)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Béreš <daniel.beres@pantheon.tech>
Co-authored-by: Daniel Beres <daniel.beres@pantheon.tech>
  • Loading branch information
Giluerre and Giluerre authored Jun 21, 2023
1 parent a5dcb5a commit 6c38360
Show file tree
Hide file tree
Showing 254 changed files with 81,679 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ['2210', '2202']
version: ['2306', '2210', '2202']

steps:
- name: "Checkout"
Expand All @@ -34,7 +34,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ['2210', '2202']
version: ['2306', '2210', '2202']

steps:
- name: "Checkout"
Expand Down
1 change: 1 addition & 0 deletions plugins/govppmux/plugin_impl_govppmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (

_ "go.ligato.io/vpp-agent/v3/plugins/govppmux/vppcalls/vpp2202"
_ "go.ligato.io/vpp-agent/v3/plugins/govppmux/vppcalls/vpp2210"
_ "go.ligato.io/vpp-agent/v3/plugins/govppmux/vppcalls/vpp2306"
)

var (
Expand Down
170 changes: 170 additions & 0 deletions plugins/govppmux/vppcalls/vpp2306/vpe_vppcalls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// Copyright (c) 2022 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 vpp2306

import (
"context"
"fmt"
"strings"

"github.com/pkg/errors"
"go.fd.io/govpp/api"

"go.ligato.io/vpp-agent/v3/plugins/govppmux/vppcalls"
"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2306/memclnt"
"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2306/vlib"
"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2306/vpe"
)

// Ping sends VPP control ping.
func (h *VpeHandler) Ping(ctx context.Context) error {
_, err := h.memclnt.ControlPing(ctx, new(memclnt.ControlPing))
return err
}

// GetVersion retrieves version info from VPP.
func (h *VpeHandler) GetVersion(ctx context.Context) (*vppcalls.VersionInfo, error) {
version, err := h.vpe.ShowVersion(ctx, new(vpe.ShowVersion))
if err != nil {
return nil, err
}
info := &vppcalls.VersionInfo{
Program: strings.TrimRight(version.Program, "\x00"),
Version: strings.TrimRight(version.Version, "\x00"),
BuildDate: strings.TrimRight(version.BuildDate, "\x00"),
BuildDirectory: strings.TrimRight(version.BuildDirectory, "\x00"),
}
return info, nil
}

// GetSession retrieves session info from VPP.
func (h *VpeHandler) GetSession(ctx context.Context) (*vppcalls.SessionInfo, error) {
pong, err := h.memclnt.ControlPing(ctx, new(memclnt.ControlPing))
if err != nil {
return nil, err
}
info := &vppcalls.SessionInfo{
PID: pong.VpePID,
ClientIdx: pong.ClientIndex,
}

systime, err := h.vpe.ShowVpeSystemTime(ctx, new(vpe.ShowVpeSystemTime))
if err != nil {
// TODO: log returned error as warning?
} else {
info.Uptime = float64(systime.VpeSystemTime)
}
return info, nil
}

// GetModules retrieves module info from VPP.
func (h *VpeHandler) GetModules(ctx context.Context) ([]vppcalls.APIModule, error) {
versions, err := h.memclnt.APIVersions(ctx, new(memclnt.APIVersions))
if err != nil {
return nil, err
}
var modules []vppcalls.APIModule
for _, v := range versions.APIVersions {
modules = append(modules, vppcalls.APIModule{
Name: strings.TrimSuffix(strings.TrimRight(v.Name, "\x00"), ".api"),
Major: v.Major,
Minor: v.Minor,
Patch: v.Patch,
})
}
return modules, nil
}

func (h *VpeHandler) GetPlugins(ctx context.Context) ([]vppcalls.PluginInfo, error) {
const (
pluginPathPrefix = "Plugin path is:"
pluginNameSuffix = "_plugin.so"
)

out, err := h.RunCli(ctx, "show plugins")
if err != nil {
return nil, err
}

lines := strings.Split(out, "\n")
if len(lines) == 0 {
return nil, fmt.Errorf("empty output for 'show plugins'")
}
pluginPathLine := strings.TrimSpace(lines[0])
if !strings.HasPrefix(pluginPathLine, pluginPathPrefix) {
return nil, fmt.Errorf("unexpected output for 'show plugins'")
}
pluginPath := strings.TrimSpace(strings.TrimPrefix(pluginPathLine, pluginPathPrefix))
if len(pluginPath) == 0 {
return nil, fmt.Errorf("plugin path not found in output for 'show plugins'")
}

var plugins []vppcalls.PluginInfo
for _, line := range lines {
fields := strings.Fields(line)
if len(fields) < 3 {
continue
}
var i int
if _, err := fmt.Sscanf(fields[0], "%d.", &i); err != nil {
continue
}
if i <= 0 {
continue
}
plugin := vppcalls.PluginInfo{
Name: strings.TrimSuffix(fields[1], pluginNameSuffix),
Path: fields[1],
Version: fields[2],
Description: strings.Join(fields[3:], " "),
}
plugins = append(plugins, plugin)
}

return plugins, nil
}

func (h *VpeHandler) GetThreads(ctx context.Context) ([]vppcalls.ThreadInfo, error) {
resp, err := h.vlib.ShowThreads(ctx, &vlib.ShowThreads{})
if err != nil {
return nil, err
}
threads := make([]vppcalls.ThreadInfo, len(resp.ThreadData))
for i, thread := range resp.ThreadData {
threads[i] = vppcalls.ThreadInfo{
Name: thread.Name,
ID: thread.ID,
Type: thread.Type,
PID: thread.PID,
Core: thread.Core,
CPUID: thread.CPUID,
CPUSocket: thread.CPUSocket,
}
}
return threads, nil
}

// RunCli sends CLI command to VPP and returns response.
func (h *VpeHandler) RunCli(ctx context.Context, cmd string) (string, error) {
reply, err := h.vlib.CliInband(ctx, &vlib.CliInband{
Cmd: cmd,
})
if err != nil {
return "", errors.Wrapf(err, "VPP CLI command '%s' failed", cmd)
} else if err = api.RetvalToVPPApiError(reply.Retval); err != nil {
return "", err
}
return reply.Reply, nil
}
47 changes: 47 additions & 0 deletions plugins/govppmux/vppcalls/vpp2306/vppcalls_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2022 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 vpp2306

import (
"go.ligato.io/vpp-agent/v3/plugins/govppmux/vppcalls"
"go.ligato.io/vpp-agent/v3/plugins/vpp"
"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2306"
"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2306/memclnt"
"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2306/vlib"
"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2306/vpe"
)

func init() {
msgs := vpp.Messages(
vpe.AllMessages,
memclnt.AllMessages,
vlib.AllMessages,
)
vppcalls.AddVersion(vpp2306.Version, msgs.AllMessages(), NewVpeHandler)
}

type VpeHandler struct {
memclnt memclnt.RPCService
vlib vlib.RPCService
vpe vpe.RPCService
}

func NewVpeHandler(c vpp.Client) vppcalls.VppCoreAPI {
return &VpeHandler{
memclnt: memclnt.NewServiceClient(c),
vlib: vlib.NewServiceClient(c),
vpe: vpe.NewServiceClient(c),
}
}
1 change: 1 addition & 0 deletions plugins/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (

_ "go.ligato.io/vpp-agent/v3/plugins/telemetry/vppcalls/vpp2202"
_ "go.ligato.io/vpp-agent/v3/plugins/telemetry/vppcalls/vpp2210"
_ "go.ligato.io/vpp-agent/v3/plugins/telemetry/vppcalls/vpp2306"
)

var debug = os.Getenv("DEBUG_TELEMETRY") != ""
Expand Down
Loading

0 comments on commit 6c38360

Please sign in to comment.