Skip to content

Commit

Permalink
fix(): Fixed unnecessary route replace calls (#55)
Browse files Browse the repository at this point in the history
Signed-off-by: Bharath Horatti <[email protected]>
  • Loading branch information
bharath-avesha authored Jun 20, 2024
1 parent e60b99a commit 8c0c75a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
45 changes: 32 additions & 13 deletions pkg/server/slicerouter_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func vl3GetNsmInterfacesInKernel() ([]*sidecar.ConnectionInfo, error) {
intfMap[route.LinkIndex] = route.Dst.String()
}

logger.GlobalLogger.Infof("intf map: %v", intfMap)
logger.GlobalLogger.Debugf("intf map: %v", intfMap)

connList := []*sidecar.ConnectionInfo{}

Expand All @@ -220,7 +220,7 @@ func vl3GetNsmInterfacesInKernel() ([]*sidecar.ConnectionInfo, error) {
continue
}
if len(addrList) != 1 {
logger.GlobalLogger.Infof("More than one address on nsm intf: %v", addrList)
logger.GlobalLogger.Infof("No address or more than one address on nsm intf: %v", addrList)
continue
}

Expand All @@ -239,7 +239,7 @@ func vl3GetNsmInterfacesInKernel() ([]*sidecar.ConnectionInfo, error) {
}
}

logger.GlobalLogger.Infof("Conn list: %v", connList)
logger.GlobalLogger.Debugf("Conn list: %v", connList)

return connList, nil
}
Expand Down Expand Up @@ -301,6 +301,16 @@ func vl3GetRouteInKernel(dstIP string, nsmIP string) (bool, error) {
return false, nil
}

func printSliceRouteMap() {
logger.GlobalLogger.Debugf("Slice Route map:")
remoteSubnetRouteMap.Range(func(key, value any) bool {
nextHopList := value.([]string)
remoteSubnet := key.(string)
logger.GlobalLogger.Debugf("remoteSubnet: %v, nexthop: %v", remoteSubnet, nextHopList)
return true
})
}

func vl3ReconcileRoutesInKernel() error {
// Build a map of existing routes in the vl3
installedRoutes, err := netlink.RouteList(nil, netlink.FAMILY_V4)
Expand All @@ -318,9 +328,9 @@ func vl3ReconcileRoutesInKernel() error {
}
routeMap[route.Dst.String()] = append(routeMap[route.Dst.String()], route)
}
logger.GlobalLogger.Infof("installed Route: %v", installedRoutes)
logger.GlobalLogger.Infof("Route map: %v", routeMap)
logger.GlobalLogger.Infof("Slice Route map: %v", remoteSubnetRouteMap)

logger.GlobalLogger.Debugf("Installed routes map: %v", routeMap)
printSliceRouteMap()

nextHopInfoSlice := []*netlink.NexthopInfo{}
remoteSubnetRouteMap.Range(func(key, value any) bool {
Expand All @@ -343,8 +353,9 @@ func vl3ReconcileRoutesInKernel() error {
return false
}
remoteSubnetRouteMap.Store(remoteSubnet, contructArrayFromNextHop(nextHopInfoSlice))
} else {
logger.GlobalLogger.Debugf("Skipping installing routes since they are already present!")
}
logger.GlobalLogger.Errorf("Skipping installing routes since they are already present!")
return true
})
return nil
Expand Down Expand Up @@ -430,10 +441,10 @@ func sliceRouterInjectRoute(remoteSubnet string, nextHopIPList []string) error {

lastRoutingTableReconcileTime = time.Now()

logger.GlobalLogger.Infof("RT reconciled at: %v", lastRoutingTableReconcileTime)
logger.GlobalLogger.Debugf("RT reconciled at: %v", lastRoutingTableReconcileTime)
}

logger.GlobalLogger.Infof("sliceRouterInjectRoute", "remoteSubnetRouteMap", remoteSubnetRouteMap)
printSliceRouteMap()

if len(nextHopIPList) == 0 {
// Treat this as a signal to delete the route to the remoteSubnet
Expand Down Expand Up @@ -532,10 +543,18 @@ func contains(items []string, s string) bool {
return false
}

func containsRoute(nextHopIpList []netlink.Route, s string) bool {
for _, nextHop := range nextHopIpList {
if nextHop.Gw.String() == s {
return true
func containsRoute(routeList []netlink.Route, s string) bool {
for _, route := range routeList {
if len(route.MultiPath) > 0 {
for _, path := range route.MultiPath {
if path.Gw.String() == s {
return true
}
}
} else {
if route.Gw.String() == s {
return true
}
}
}
return false
Expand Down
14 changes: 5 additions & 9 deletions pkg/server/slicerouter_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,13 @@ func (s *SliceRouterSidecar) UpdateSliceGwConnectionContext(ctx context.Context,
if conContext.GetRemoteSliceGwNsmSubnet() == "" {
return nil, status.Errorf(codes.InvalidArgument, "Invalid Remote Slice Gateway Subnet")
}
// if len(conContext.GetLocalNsmGwPeerIPList()) == 0 {
// return nil, status.Errorf(codes.InvalidArgument, "Invalid Local NSM Gateway Peer IPs")
// }
logger.GlobalLogger.Infof("conContext UpdateSliceGwConnectionContext : %v", conContext)

// Note: Do not check for the validity of the conContext.GetLocalNsmGwPeerIPList() here. It is being
// done in the sliceRouterInjectRoute func.

err := sliceRouterInjectRoute(conContext.GetRemoteSliceGwNsmSubnet(), conContext.GetLocalNsmGwPeerIPList())
if err != nil {
logger.GlobalLogger.Errorf("Failed to add route in slice router: %v", err)
} else {
logger.GlobalLogger.Infof("Added route in slice router: %v via %v",
conContext.GetRemoteSliceGwNsmSubnet(), conContext.GetLocalNsmGwPeerIPList())
}

return &sidecar.SidecarResponse{StatusMsg: "Slice Gw Connection Context Updated Successfully"}, nil
Expand All @@ -74,12 +70,12 @@ func (s *SliceRouterSidecar) GetSliceRouterClientConnectionInfo(ctx context.Cont
if err != nil {
return nil, err
}
logger.GlobalLogger.Infof("Rxed conn list: %v", connInfo)

clientConnInfo := sidecar.ClientConnectionInfo{
Connection: connInfo,
}

logger.GlobalLogger.Infof("sending conn list: %v", clientConnInfo)
logger.GlobalLogger.Debugf("sending conn list: %v", clientConnInfo)

return &clientConnInfo, nil
}
Expand Down

0 comments on commit 8c0c75a

Please sign in to comment.