From 2d1dcbe2b61adeea9bb611308105d5cea83a1e1e Mon Sep 17 00:00:00 2001 From: hedi bouattour Date: Tue, 28 Nov 2023 17:11:01 +0000 Subject: [PATCH] agent: memif and vcl fixes --- calico-vpp-agent/cni/cni_pod_test.go | 2 +- calico-vpp-agent/cni/network_vpp.go | 25 ++++++++++++++++------ calico-vpp-agent/cni/network_vpp_routes.go | 10 ++++++--- calico-vpp-agent/cni/storage/storage.go | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/calico-vpp-agent/cni/cni_pod_test.go b/calico-vpp-agent/cni/cni_pod_test.go index 6981f7c4..9bc02675 100644 --- a/calico-vpp-agent/cni/cni_pod_test.go +++ b/calico-vpp-agent/cni/cni_pod_test.go @@ -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)") diff --git a/calico-vpp-agent/cni/network_vpp.go b/calico-vpp-agent/cni/network_vpp.go index 57b50a19..a0730419 100644 --- a/calico-vpp-agent/cni/network_vpp.go +++ b/calico-vpp-agent/cni/network_vpp.go @@ -210,16 +210,23 @@ func (s *Server) AddVppInterface(podSpec *storage.LocalPodSpec, doHostSideConf b goto err } } else { + pblswIfIndex, _ := podSpec.GetParamsForIfType(podSpec.PortFilteredIfType) 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) if err != nil { goto err } } else { s.log.Warn("No default if type for pod") } + if pblswIfIndex != types.InvalidID { + err = s.CreateVRFRoutesToPod(podSpec, stack) + if err != nil { + goto err + } + } } swIfIndex, isL3 = podSpec.GetParamsForIfType(podSpec.PortFilteredIfType) @@ -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") diff --git a/calico-vpp-agent/cni/network_vpp_routes.go b/calico-vpp-agent/cni/network_vpp_routes.go index c27bb742..b58322cc 100644 --- a/calico-vpp-agent/cni/network_vpp_routes.go +++ b/calico-vpp-agent/cni/network_vpp_routes.go @@ -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 != "" { @@ -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, @@ -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 != "" { @@ -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, @@ -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()) } } } diff --git a/calico-vpp-agent/cni/storage/storage.go b/calico-vpp-agent/cni/storage/storage.go index 0b57e56a..b81345ae 100644 --- a/calico-vpp-agent/cni/storage/storage.go +++ b/calico-vpp-agent/cni/storage/storage.go @@ -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 }