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

Govpp templates (interfaces) #403

Draft
wants to merge 2 commits into
base: govpp-templates
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ vpplink/binapi/.cherries-cache
calico-vpp-agent/version
vpp-manager/images/ubuntu/version
test/scripts/.buildlogs

.idea/*
11 changes: 11 additions & 0 deletions .idea/modules.xml

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

16 changes: 16 additions & 0 deletions .idea/vpp-dataplane.iml

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

5 changes: 3 additions & 2 deletions calico-vpp-agent/cni/cni_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cni
import (
"context"
"fmt"
types2 "git.fd.io/govpp.git/api/v0"
"net"
"os"
"sync"
Expand Down Expand Up @@ -229,8 +230,8 @@ func (s *Server) fetchBufferConfig() {

numRxQueues := config.TapNumRxQueues
numTxQueues := config.TapNumTxQueues
rxQueueSize := vpplink.DefaultIntTo(config.TapRxQueueSize, vpplink.DEFAULT_QUEUE_SIZE)
txQueueSize := vpplink.DefaultIntTo(config.TapTxQueueSize, vpplink.DEFAULT_QUEUE_SIZE)
rxQueueSize := vpplink.DefaultIntTo(config.TapRxQueueSize, types2.DefaultQueueSize)
txQueueSize := vpplink.DefaultIntTo(config.TapTxQueueSize, types2.DefaultQueueSize)
s.buffersNeededPerTap = uint64(rxQueueSize*numRxQueues + txQueueSize*numTxQueues)
}

Expand Down
29 changes: 18 additions & 11 deletions calico-vpp-agent/cni/pod_interface/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/cni/storage"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/config"
"github.com/projectcalico/vpp-dataplane/vpplink"
"github.com/projectcalico/vpp-dataplane/vpplink/types"
"github.com/sirupsen/logrus"

types2 "git.fd.io/govpp.git/api/v0"
)

type PodInterfaceDriverData struct {
Expand All @@ -32,15 +33,17 @@ type PodInterfaceDriverData struct {
}

func (i *PodInterfaceDriverData) SpreadTxQueuesOnWorkers(swIfIndex uint32, numTxQueues int) (err error) {
iface := types2.Interface{SwIfIndex: swIfIndex}

// set first tx queue for main worker
err = i.vpp.SetInterfaceTxPlacement(swIfIndex, 0 /* queue */, 0 /* worker */)
err = i.vpp.SetInterfaceTxPlacement(&iface, 0 /* queue */, 0 /* worker */)
if err != nil {
return err
}
// share tx queues between the rest of workers
if i.NDataThreads > 0 {
for txq := 1; txq < numTxQueues; txq++ {
err = i.vpp.SetInterfaceTxPlacement(swIfIndex, txq, (txq-1)%(i.NDataThreads)+1)
err = i.vpp.SetInterfaceTxPlacement(&iface, txq, (txq-1)%(i.NDataThreads)+1)
if err != nil {
return err
}
Expand All @@ -50,10 +53,11 @@ func (i *PodInterfaceDriverData) SpreadTxQueuesOnWorkers(swIfIndex uint32, numTx
}

func (i *PodInterfaceDriverData) SpreadRxQueuesOnWorkers(swIfIndex uint32) {
iface := types2.Interface{SwIfIndex: swIfIndex}
if i.NDataThreads > 0 {
for queue := 0; queue < config.TapNumRxQueues; queue++ {
worker := (int(swIfIndex)*config.TapNumRxQueues + queue) % i.NDataThreads
err := i.vpp.SetInterfaceRxPlacement(swIfIndex, queue, worker, false /* main */)
err := i.vpp.SetInterfaceRxPlacement(&iface, queue, worker, false /* main */)
if err != nil {
i.log.Warnf("failed to set if[%d] queue%d worker%d (tot workers %d): %v", swIfIndex, queue, worker, i.NDataThreads, err)
}
Expand Down Expand Up @@ -105,42 +109,45 @@ func (i *PodInterfaceDriverData) DoPodIfNatConfiguration(podSpec *storage.LocalP
}

func (i *PodInterfaceDriverData) UndoPodInterfaceConfiguration(swIfIndex uint32) {
err := i.vpp.InterfaceAdminDown(swIfIndex)
iface := types2.Interface{SwIfIndex: swIfIndex}
err := i.vpp.InterfaceAdminDown(&iface)
if err != nil {
i.log.Errorf("InterfaceAdminDown errored %s", err)
}
}

func (i *PodInterfaceDriverData) DoPodInterfaceConfiguration(podSpec *storage.LocalPodSpec, stack *vpplink.CleanupStack, swIfIndex uint32, isL3 bool) (err error) {
i.SpreadRxQueuesOnWorkers(swIfIndex)
iface := types2.Interface{SwIfIndex: swIfIndex}
i.SpreadRxQueuesOnWorkers(iface.SwIfIndex)

for _, ipFamily := range vpplink.IpFamilies {
vrfId := podSpec.GetVrfId(ipFamily)
err = i.vpp.SetInterfaceVRF(swIfIndex, vrfId, ipFamily.IsIp6)
err = i.vpp.SetInterfaceVRF(&iface, vrfId, ipFamily.IsIp6)
if err != nil {
return errors.Wrapf(err, "error setting vpp if[%d] in pod vrf", swIfIndex)
}
}

if !isL3 {
/* L2 */
err = i.vpp.SetPromiscOn(swIfIndex)
err = i.vpp.SetPromiscOn(&iface)
if err != nil {
return errors.Wrapf(err, "Error setting memif promisc")
}
}

err = i.vpp.SetInterfaceMtu(swIfIndex, vpplink.MAX_MTU)
err = i.vpp.SetInterfaceMtu(&iface, types2.MaxMtu)
if err != nil {
return errors.Wrapf(err, "Error setting MTU on pod interface")
}

err = i.vpp.InterfaceAdminUp(swIfIndex)
err = i.vpp.InterfaceAdminUp(&iface)
if err != nil {
return errors.Wrapf(err, "error setting new pod if up")
}

err = i.vpp.SetInterfaceRxMode(swIfIndex, types.AllQueues, config.TapRxMode)
// TODO: is this configurable variable or not ?
err = i.vpp.SetInterfaceRxMode(&iface, types2.AllQueues, config.TapRxMode)
if err != nil {
return errors.Wrapf(err, "error SetInterfaceRxMode on pod if interface")
}
Expand Down
13 changes: 9 additions & 4 deletions calico-vpp-agent/cni/pod_interface/loopback.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/common"
"github.com/projectcalico/vpp-dataplane/vpplink"
"github.com/sirupsen/logrus"

types2 "git.fd.io/govpp.git/api/v0"
)

type LoopbackPodInterfaceDriver struct {
Expand All @@ -43,11 +45,12 @@ func (i *LoopbackPodInterfaceDriver) CreateInterface(podSpec *storage.LocalPodSp
} else {
stack.Push(i.vpp.DeleteLoopback, swIfIndex)
}
podSpec.LoopbackSwIfIndex = swIfIndex
iface := types2.Interface{SwIfIndex: swIfIndex}
podSpec.LoopbackSwIfIndex = iface.SwIfIndex

for _, ipFamily := range vpplink.IpFamilies {
vrfId := podSpec.GetVrfId(ipFamily)
err = i.vpp.SetInterfaceVRF(swIfIndex, vrfId, ipFamily.IsIp6)
err = i.vpp.SetInterfaceVRF(&iface, vrfId, ipFamily.IsIp6)
if err != nil {
return errors.Wrapf(err, "Error setting loopback %d in per pod vrf", swIfIndex)
}
Expand All @@ -59,7 +62,7 @@ func (i *LoopbackPodInterfaceDriver) CreateInterface(podSpec *storage.LocalPodSp
}

for _, containerIP := range podSpec.GetContainerIps() {
err = i.vpp.AddInterfaceAddress(swIfIndex, containerIP)
err = i.vpp.AddInterfaceAddress(&iface, containerIP)
if err != nil {
return errors.Wrapf(err, "Error adding address %s to pod loopback interface", containerIP)
}
Expand All @@ -71,7 +74,9 @@ func (i *LoopbackPodInterfaceDriver) CreateInterface(podSpec *storage.LocalPodSp
func (i *LoopbackPodInterfaceDriver) DeleteInterface(podSpec *storage.LocalPodSpec) {
i.UndoPodIfNatConfiguration(podSpec.LoopbackSwIfIndex)

err := i.vpp.DeleteLoopback(podSpec.LoopbackSwIfIndex)
iface := types2.Interface{SwIfIndex: podSpec.LoopbackSwIfIndex}

err := i.vpp.DeleteLoopback(&iface)
if err != nil {
i.log.Errorf("Error deleting Loopback %s", err)
}
Expand Down
9 changes: 6 additions & 3 deletions calico-vpp-agent/cni/pod_interface/memif.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/projectcalico/vpp-dataplane/vpplink"
"github.com/projectcalico/vpp-dataplane/vpplink/types"
"github.com/sirupsen/logrus"

types2 "git.fd.io/govpp.git/api/v0"
)

type MemifPodInterfaceDriver struct {
Expand Down Expand Up @@ -65,15 +67,16 @@ func (i *MemifPodInterfaceDriver) CreateInterface(podSpec *storage.LocalPodSpec,
} else {
stack.Push(i.vpp.DeleteMemif, memif.SwIfIndex)
}
podSpec.MemifSwIfIndex = memif.SwIfIndex
iface := types2.Interface{SwIfIndex: memif.SwIfIndex}
podSpec.MemifSwIfIndex = iface.SwIfIndex

err = i.vpp.SetInterfaceTag(memif.SwIfIndex, podSpec.GetInterfaceTag(i.name))
err = i.vpp.SetInterfaceTag(&iface, podSpec.GetInterfaceTag(i.name))
if err != nil {
return err
}

if config.PodGSOEnabled {
err = i.vpp.EnableGSOFeature(memif.SwIfIndex)
err = i.vpp.EnableGSOFeature(&iface)
if err != nil {
return errors.Wrap(err, "Error enabling GSO on memif")
}
Expand Down
14 changes: 8 additions & 6 deletions calico-vpp-agent/cni/pod_interface/tuntap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package pod_interface

import (
"fmt"
types2 "git.fd.io/govpp.git/api/v0"
"io"
"net"
"os"
Expand All @@ -31,7 +32,6 @@ import (
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/cni/storage"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/config"
"github.com/projectcalico/vpp-dataplane/vpplink"
"github.com/projectcalico/vpp-dataplane/vpplink/types"
)

type TunTapPodInterfaceDriver struct {
Expand Down Expand Up @@ -85,8 +85,8 @@ func (i *TunTapPodInterfaceDriver) CreateInterface(podSpec *storage.LocalPodSpec
}
i.log.Debugf("Determined pod MTU: %d", podMtu)

tun := &types.TapV2{
GenericVppInterface: types.GenericVppInterface{
tun := &types2.TapInterface{
Interface: types2.Interface{
NumRxQueues: config.TapNumRxQueues,
NumTxQueues: config.TapNumTxQueues,
RxQueueSize: config.TapRxQueueSize,
Expand All @@ -99,11 +99,11 @@ func (i *TunTapPodInterfaceDriver) CreateInterface(podSpec *storage.LocalPodSpec
}

if podSpec.TunTapIsL3 {
tun.Flags |= types.TapFlagTun
tun.Flags |= types2.TapFlagTun
}

if config.PodGSOEnabled {
tun.Flags |= types.TapFlagGSO | types.TapGROCoalesce
tun.Flags |= types2.TapFlagGSO | types2.TapGROCoalesce
}

i.log.Debugf("Add request pod MTU: %d, computed %d", podSpec.Mtu, tun.HostMtu)
Expand Down Expand Up @@ -149,7 +149,9 @@ func (i *TunTapPodInterfaceDriver) DeleteInterface(podSpec *storage.LocalPodSpec
i.UndoPodInterfaceConfiguration(podSpec.TunTapSwIfIndex)
i.UndoPodIfNatConfiguration(podSpec.TunTapSwIfIndex)

err := i.vpp.DelTap(podSpec.TunTapSwIfIndex)
iface := types2.Interface{SwIfIndex: podSpec.TunTapSwIfIndex}

err := i.vpp.DelTap(&iface)
if err != nil {
i.log.Warnf("Error deleting tun[%d] %s", podSpec.TunTapSwIfIndex, err)
}
Expand Down
6 changes: 5 additions & 1 deletion calico-vpp-agent/cni/pod_interface/vcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/projectcalico/vpp-dataplane/vpplink"
"github.com/projectcalico/vpp-dataplane/vpplink/types"
"github.com/sirupsen/logrus"

types2 "git.fd.io/govpp.git/api/v0"
)

const (
Expand Down Expand Up @@ -75,7 +77,9 @@ func (i *VclPodInterfaceDriver) CreateInterface(podSpec *storage.LocalPodSpec, s
stack.Push(i.vpp.DelSessionAppNamespace, appNamespace)
}

err = i.vpp.InterfaceAdminUp(podSpec.LoopbackSwIfIndex)
iface := types2.Interface{SwIfIndex: podSpec.LoopbackSwIfIndex}

err = i.vpp.InterfaceAdminUp(&iface)
if err != nil {
return err
}
Expand Down
11 changes: 6 additions & 5 deletions calico-vpp-agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package config

import (
"fmt"
types2 "git.fd.io/govpp.git/api/v0"
"io/ioutil"
"net"
"os"
Expand All @@ -25,7 +26,6 @@ import (
"time"

"github.com/pkg/errors"
"github.com/projectcalico/vpp-dataplane/vpplink/types"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -67,7 +67,7 @@ const (
DefaultVXLANPort = 4789
DefaultWireguardPort = 51820

defaultRxMode = types.Adaptative
defaultRxMode = types2.Adaptative
)

var (
Expand Down Expand Up @@ -315,13 +315,14 @@ func LoadConfig(log *logrus.Logger) (err error) {
ServiceCIDRs = append(ServiceCIDRs, serviceCIDR)
}

// TODO: To/From String these are duplicates again
switch getEnvValue(TapRxModeEnvVar) {
case "interrupt":
TapRxMode = types.Interrupt
TapRxMode = types2.Interrupt
case "polling":
TapRxMode = types.Polling
TapRxMode = types2.Polling
case "adaptive":
TapRxMode = types.Adaptative
TapRxMode = types2.Adaptative
default:
TapRxMode = defaultRxMode
}
Expand Down
Loading