diff --git a/os_clients/ubuntu/supportedPaths.go b/os_clients/ubuntu/supportedPaths.go index 934a30de3a51591f30673a6f015ce7b83aa1384f..f199c22a39f0c678c7b5812f52583dfadcf53919 100644 --- a/os_clients/ubuntu/supportedPaths.go +++ b/os_clients/ubuntu/supportedPaths.go @@ -104,6 +104,7 @@ func walkThroughConfig(config ygot.ValidatedGoStruct) error { } } } + if networkInstances := conf.NetworkInstances; networkInstances != nil { if networkInstanceMap := networkInstances.NetworkInstance; networkInstanceMap != nil { for _, networkInstance := range networkInstanceMap { @@ -117,6 +118,7 @@ func walkThroughConfig(config ygot.ValidatedGoStruct) error { } } } + return nil } @@ -153,6 +155,7 @@ func generateSubinterface(subintf *gnmitargetygot.OpenconfigInterfaces_Interface if len(errs) != 0 { return fmt.Errorf("encountered %v errors during address adding \n%v", len(errs), errs) } + return nil } @@ -175,12 +178,43 @@ func generateProtocol(protocol *gnmitargetygot.OpenconfigNetworkInstance_Network return err } - nextHop := net.ParseIP(hop.GetConfig().GetIndex()) + _ = ipnet + + nextHop, ok := hop.GetConfig().GetNextHop().(*gnmitargetygot.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop_Config_NextHop_Union_String) + if !ok { + return fmt.Errorf("only string union is supported for nextHop") + } + + nextHopParsed := net.ParseIP(nextHop.String) + + if nextHop == nil { + return fmt.Errorf("failed parsing ip") + } + + route := &netlink.Route{ + LinkIndex: link.Attrs().Index, + Dst: ipnet, + Gw: nextHopParsed, + } + + //if route.Dst != nil { + + // fmt.Println("Route GW: ", route.Gw.String()) + // fmt.Println("Route Src: ", route.Src.String()) + // fmt.Println("Route Dst: ", route.Dst.String()) + // err != netlink.RouteAdd(route) - route := netlink.Route{LinkIndex: link.Attrs().Index, Dst: ipnet, Src: nextHop} - netlink.RouteAdd(&route) + //} + fmt.Println("Route GW: ", route.Gw.String()) + fmt.Println("Route Src: ", route.Src.String()) + fmt.Println("Route Dst: ", route.Dst.String()) + + if err := netlink.RouteReplace(route); err != nil { + return err + } } } + return nil } @@ -190,8 +224,8 @@ func CIDRToIPNet(s string) (*net.IPNet, error) { return nil, err } ipnet.IP = ip - return ipnet, nil + return ipnet, nil } func filterKeys(path *gnmi.Path) []map[string]string { @@ -201,5 +235,6 @@ func filterKeys(path *gnmi.Path) []map[string]string { keyMap = append(keyMap, key) } } + return keyMap }