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

agent: memif and vcl fixes #662

Merged
merged 2 commits into from
Dec 7, 2023
Merged
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: 1 addition & 1 deletion calico-vpp-agent/cni/cni_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ var _ = Describe("Pod-related functionality of CNI", func() {
pblClientStr, err := vpp.RunCli("sh pbl client")
Expect(err).ToNot(HaveOccurred(), "failed to get PBL configuration")
pblClientStr = strings.ToLower(pblClientStr)
Expect(pblClientStr).To(ContainSubstring(fmt.Sprintf("pbl-client: %s clone:1", ipAddress)),
Expect(pblClientStr).To(ContainSubstring(fmt.Sprintf("pbl-client: %s clone:", ipAddress)),
"PBL doesn't clone the main interface traffic")
Expect(strings.Count(pblClientStr, "pbl-client")).To(Equal(2),
"got some missing pbl clients (one for main interface and one for memif)")
Expand Down
25 changes: 18 additions & 7 deletions calico-vpp-agent/cni/network_vpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,23 @@ func (s *Server) AddVppInterface(podSpec *storage.LocalPodSpec, doHostSideConf b
goto err
}
} else {
pblswIfIndex, _ := podSpec.GetParamsForIfType(podSpec.PortFilteredIfType)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If might be worth adding a

pblswIfIndex, pblIsL3 := podSpec.GetParamsForIfType(podSpec.PortFilteredIfType)
swIfIndex, isL3 = podSpec.GetParamsForIfType(podSpec.DefaultIfType)

at the beginning of the /* Routes */ section

swIfIndex, isL3 = podSpec.GetParamsForIfType(podSpec.DefaultIfType)
if swIfIndex != types.InvalidID {
s.log.Infof("pod(add) Default routes to swIfIndex=%d isL3=%t", swIfIndex, isL3)
err = s.RoutePodInterface(podSpec, stack, swIfIndex, isL3)
err = s.RoutePodInterface(podSpec, stack, swIfIndex, isL3, pblswIfIndex != types.InvalidID)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a inPodVRF it might be better to have two functions :

  • AddRouteNetworkVRFtoPodInterface()
  • AddRoutePodVRFtoPodInterface()

if err != nil {
goto err
}
} else {
s.log.Warn("No default if type for pod")
}
if pblswIfIndex != types.InvalidID {
err = s.CreateVRFRoutesToPod(podSpec, stack)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe CreateVRFRoutesToPod -> AddRouteNetworkVRFToPodVRF

if err != nil {
goto err
}
}
}

swIfIndex, isL3 = podSpec.GetParamsForIfType(podSpec.PortFilteredIfType)
Expand Down Expand Up @@ -327,17 +334,21 @@ func (s *Server) DelVppInterface(podSpec *storage.LocalPodSpec) {
s.RemovePuntRoutes(podSpec, podSpec.TunTapSwIfIndex)
}
} else {
swIfIndex, _ := podSpec.GetParamsForIfType(podSpec.PortFilteredIfType)
if swIfIndex != types.InvalidID {
s.log.Infof("pod(del) PBL routes to %d", swIfIndex)
s.UnroutePblPortsPodInterface(podSpec, swIfIndex)
pblswIfIndex, _ := podSpec.GetParamsForIfType(podSpec.PortFilteredIfType)
if pblswIfIndex != types.InvalidID {
s.DeleteVRFRoutesToPod(podSpec)
}
swIfIndex, _ = podSpec.GetParamsForIfType(podSpec.DefaultIfType)
swIfIndex, _ := podSpec.GetParamsForIfType(podSpec.DefaultIfType)
if swIfIndex != types.InvalidID {
s.log.Infof("pod(del) default routes to %d", swIfIndex)
s.UnroutePodInterface(podSpec, swIfIndex)
s.UnroutePodInterface(podSpec, swIfIndex, pblswIfIndex != types.InvalidID)
}
}
pblswIfIndex, _ := podSpec.GetParamsForIfType(podSpec.PortFilteredIfType)
if pblswIfIndex != types.InvalidID {
s.log.Infof("pod(del) PBL routes to %d", pblswIfIndex)
s.UnroutePblPortsPodInterface(podSpec, pblswIfIndex)
}

/* RPF */
s.log.Infof("pod(del) RPF VRF")
Expand Down
10 changes: 7 additions & 3 deletions calico-vpp-agent/cni/network_vpp_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/projectcalico/vpp-dataplane/v3/vpplink/types"
)

func (s *Server) RoutePodInterface(podSpec *storage.LocalPodSpec, stack *vpplink.CleanupStack, swIfIndex uint32, isL3 bool) error {
func (s *Server) RoutePodInterface(podSpec *storage.LocalPodSpec, stack *vpplink.CleanupStack, swIfIndex uint32, isL3 bool, inPodVrf bool) error {
for _, containerIP := range podSpec.GetContainerIps() {
var table uint32
if podSpec.NetworkName != "" {
Expand All @@ -39,6 +39,8 @@ func (s *Server) RoutePodInterface(podSpec *storage.LocalPodSpec, stack *vpplink
} else {
table = value.(*watchers.NetworkDefinition).VRF.Tables[idx]
}
} else if inPodVrf {
table = podSpec.GetVrfId(vpplink.IpFamilyFromIPNet(containerIP))
}
route := types.Route{
Dst: containerIP,
Expand Down Expand Up @@ -69,7 +71,7 @@ func (s *Server) RoutePodInterface(podSpec *storage.LocalPodSpec, stack *vpplink
return nil
}

func (s *Server) UnroutePodInterface(podSpec *storage.LocalPodSpec, swIfIndex uint32) {
func (s *Server) UnroutePodInterface(podSpec *storage.LocalPodSpec, swIfIndex uint32, inPodVrf bool) {
for _, containerIP := range podSpec.GetContainerIps() {
var table uint32
if podSpec.NetworkName != "" {
Expand All @@ -83,6 +85,8 @@ func (s *Server) UnroutePodInterface(podSpec *storage.LocalPodSpec, swIfIndex ui
} else {
table = value.(*watchers.NetworkDefinition).VRF.Tables[idx]
}
} else if inPodVrf {
table = podSpec.GetVrfId(vpplink.IpFamilyFromIPNet(containerIP))
}
route := types.Route{
Dst: containerIP,
Expand Down Expand Up @@ -147,7 +151,7 @@ func (s *Server) RoutePblPortsPodInterface(podSpec *storage.LocalPodSpec, stack
HardwareAddr: common.ContainerSideMacAddress,
})
if err != nil {
return errors.Wrapf(err, "Cannot adding neighbor if[%d] %s", swIfIndex, containerIP.IP.String())
return errors.Wrapf(err, "Cannot add neighbor if[%d] %s", swIfIndex, containerIP.IP.String())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion calico-vpp-agent/cni/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (ps *LocalPodSpec) GetParamsForIfType(ifType VppInterfaceType) (swIfIndex u
if !*config.GetCalicoVppFeatureGates().MemifEnabled {
return types.InvalidID, true
}
return ps.MemifSwIfIndex, *ps.IfSpec.IsL3
return ps.MemifSwIfIndex, *ps.PBLMemifSpec.IsL3
default:
return types.InvalidID, true
}
Expand Down
Loading