Skip to content

Commit

Permalink
agent: memif and vcl fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hedibouattour committed Nov 28, 2023
1 parent 145a5cd commit 96e55f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
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)
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)
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

0 comments on commit 96e55f0

Please sign in to comment.