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

Support for VPP 19.08-rc0 #1357

Merged
merged 10 commits into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 129 additions & 0 deletions plugins/govppmux/vppcalls/vpp1908/vpe_vppcalls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// 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 vpp1908

import (
"bytes"
"strings"

govppapi "git.fd.io/govpp.git/api"

"github.com/ligato/vpp-agent/plugins/govppmux/vppcalls"
"github.com/ligato/vpp-agent/plugins/vpp/binapi/vpp1908/memclnt"
"github.com/ligato/vpp-agent/plugins/vpp/binapi/vpp1908/vpe"
)

func init() {
var msgs []govppapi.Message
msgs = append(msgs, vpe.Messages...)
msgs = append(msgs, memclnt.Messages...)

vppcalls.Versions["vpp1904"] = vppcalls.HandlerVersion{
Msgs: msgs,
New: func(ch govppapi.Channel) vppcalls.VpeVppAPI {
return NewVpeHandler(ch)
},
}
}

type VpeHandler struct {
ch govppapi.Channel
}

func NewVpeHandler(ch govppapi.Channel) *VpeHandler {
return &VpeHandler{ch}
}

// Ping pings the VPP.
func (h *VpeHandler) Ping() error {
req := &vpe.ControlPing{}
reply := &vpe.ControlPingReply{}

return h.ch.SendRequest(req).ReceiveReply(reply)
}

// GetVersionInfo retrieves version info
func (h *VpeHandler) GetVersionInfo() (*vppcalls.VersionInfo, error) {
req := &vpe.ShowVersion{}
reply := &vpe.ShowVersionReply{}

if err := h.ch.SendRequest(req).ReceiveReply(reply); err != nil {
return nil, err
}

info := &vppcalls.VersionInfo{
Program: reply.Program,
Version: reply.Version,
BuildDate: reply.BuildDate,
BuildDirectory: reply.BuildDirectory,
}

return info, nil
}

// GetVpeInfo retrieves vpe information.
func (h *VpeHandler) GetVpeInfo() (*vppcalls.VpeInfo, error) {
req := &vpe.ControlPing{}
reply := &vpe.ControlPingReply{}

if err := h.ch.SendRequest(req).ReceiveReply(reply); err != nil {
return nil, err
}

info := &vppcalls.VpeInfo{
PID: reply.VpePID,
ClientIdx: reply.ClientIndex,
}

{
req := &memclnt.APIVersions{}
reply := &memclnt.APIVersionsReply{}

if err := h.ch.SendRequest(req).ReceiveReply(reply); err != nil {
return nil, err
}

for _, v := range reply.APIVersions {
name := string(cleanBytes(v.Name))
name = strings.TrimSuffix(name, ".api")
info.ModuleVersions = append(info.ModuleVersions, vppcalls.ModuleVersion{
Name: name,
Major: v.Major,
Minor: v.Minor,
Patch: v.Patch,
})
}
}

return info, nil
}

// RunCli executes CLI command and returns output
func (h *VpeHandler) RunCli(cmd string) (string, error) {
req := &vpe.CliInband{
Cmd: cmd,
}
reply := &vpe.CliInbandReply{}

if err := h.ch.SendRequest(req).ReceiveReply(reply); err != nil {
return "", err
}

return reply.Reply, nil
}

func cleanBytes(b []byte) []byte {
return bytes.SplitN(b, []byte{0x00}, 2)[0]
}
1 change: 1 addition & 0 deletions plugins/vpp/abfplugin/abfplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

_ "github.com/ligato/vpp-agent/plugins/vpp/abfplugin/vppcalls/vpp1901"
_ "github.com/ligato/vpp-agent/plugins/vpp/abfplugin/vppcalls/vpp1904"
_ "github.com/ligato/vpp-agent/plugins/vpp/abfplugin/vppcalls/vpp1908"
)

// ABFPlugin is a plugin that manages ACL-based forwarding.
Expand Down
154 changes: 154 additions & 0 deletions plugins/vpp/abfplugin/vppcalls/vpp1908/abf_vppcalls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// 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 vpp1908

import (
"fmt"
"net"

vpp_abf "github.com/ligato/vpp-agent/api/models/vpp/abf"

"github.com/go-errors/errors"
"github.com/ligato/vpp-agent/plugins/vpp/binapi/vpp1908/abf"
)

// GetAbfVersion retrieves version of the VPP ABF plugin
func (h *ABFVppHandler) GetAbfVersion() (ver string, err error) {
req := &abf.AbfPluginGetVersion{}
reply := &abf.AbfPluginGetVersionReply{}

if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil {
return "", err
}

return fmt.Sprintf("%d.%d", reply.Major, reply.Minor), nil
}

// AddAbfPolicy creates new ABF entry together with a list of forwarding paths
func (h *ABFVppHandler) AddAbfPolicy(policyID, aclID uint32, abfPaths []*vpp_abf.ABF_ForwardingPath) error {
if err := h.abfAddDelPolicy(policyID, aclID, abfPaths, true); err != nil {
return errors.Errorf("failed to add ABF policy %d (ACL: %v): %v", policyID, aclID, err)
}
return nil
}

// DeleteAbfPolicy removes existing ABF entry
func (h *ABFVppHandler) DeleteAbfPolicy(policyID uint32, abfPaths []*vpp_abf.ABF_ForwardingPath) error {
if err := h.abfAddDelPolicy(policyID, 0, abfPaths, false); err != nil {
return errors.Errorf("failed to delete ABF policy %d: %v", policyID, err)
}
return nil
}

// AbfAttachInterfaceIPv4 attaches IPv4 interface to the ABF
func (h *ABFVppHandler) AbfAttachInterfaceIPv4(policyID, ifIdx, priority uint32) error {
if err := h.abfAttachDetachInterface(policyID, ifIdx, priority, true, false); err != nil {
return errors.Errorf("failed to attach IPv4 interface %d to ABF policy %d: %v", ifIdx, policyID, err)
}
return nil
}

// AbfDetachInterfaceIPv4 detaches IPV4 interface from the ABF
func (h *ABFVppHandler) AbfDetachInterfaceIPv4(policyID, ifIdx, priority uint32) error {
if err := h.abfAttachDetachInterface(policyID, ifIdx, priority, false, false); err != nil {
return errors.Errorf("failed to detach IPv4 interface %d from ABF policy %d: %v", ifIdx, policyID, err)
}
return nil
}

// AbfAttachInterfaceIPv6 attaches IPv6 interface to the ABF
func (h *ABFVppHandler) AbfAttachInterfaceIPv6(policyID, ifIdx, priority uint32) error {
if err := h.abfAttachDetachInterface(policyID, ifIdx, priority, true, true); err != nil {
return errors.Errorf("failed to attach IPv6 interface %d to ABF policy %d: %v", ifIdx, policyID, err)
}
return nil
}

// AbfDetachInterfaceIPv6 detaches IPv6 interface from the ABF
func (h *ABFVppHandler) AbfDetachInterfaceIPv6(policyID, ifIdx, priority uint32) error {
if err := h.abfAttachDetachInterface(policyID, ifIdx, priority, false, true); err != nil {
return errors.Errorf("failed to detach IPv6 interface %d from ABF policy %d: %v", ifIdx, policyID, err)
}
return nil
}

func (h *ABFVppHandler) abfAttachDetachInterface(policyID, ifIdx, priority uint32, isAdd, isIPv6 bool) error {
req := &abf.AbfItfAttachAddDel{
IsAdd: boolToUint(isAdd),
Attach: abf.AbfItfAttach{
PolicyID: policyID,
SwIfIndex: ifIdx,
Priority: priority,
IsIPv6: boolToUint(isIPv6),
},
}
reply := &abf.AbfItfAttachAddDelReply{}

return h.callsChannel.SendRequest(req).ReceiveReply(reply)
}

func (h *ABFVppHandler) abfAddDelPolicy(policyID, aclID uint32, abfPaths []*vpp_abf.ABF_ForwardingPath, isAdd bool) error {
req := &abf.AbfPolicyAddDel{
IsAdd: boolToUint(isAdd),
Policy: abf.AbfPolicy{
PolicyID: policyID,
ACLIndex: aclID,
Paths: h.toFibPaths(abfPaths),
NPaths: uint8(len(abfPaths)),
},
}
reply := &abf.AbfPolicyAddDelReply{}

return h.callsChannel.SendRequest(req).ReceiveReply(reply)
}

func (h *ABFVppHandler) toFibPaths(abfPaths []*vpp_abf.ABF_ForwardingPath) (fibPaths []abf.FibPath) {
for _, abfPath := range abfPaths {
// fib path interface
ifData, exists := h.ifIndexes.LookupByName(abfPath.InterfaceName)
if !exists {
continue
}

fibPath := abf.FibPath{
SwIfIndex: ifData.SwIfIndex,
Weight: uint8(abfPath.Weight),
Preference: uint8(abfPath.Preference),
IsDvr: boolToUint(abfPath.Dvr),
}

// next hop IP
nextHop := net.ParseIP(abfPath.NextHopIp)
if nextHop.To4() == nil {
nextHop = nextHop.To16()
fibPath.Afi = 1
} else {
nextHop = nextHop.To4()
fibPath.Afi = 0
}
fibPath.NextHop = nextHop

fibPaths = append(fibPaths, fibPath)
}

return fibPaths
}

func boolToUint(input bool) uint8 {
if input {
return 1
}
return 0
}
Loading