diff --git a/pkg/LinuxCIModule/lci.go b/pkg/LinuxCIModule/lci.go index a72c2288..f62fcc3b 100644 --- a/pkg/LinuxCIModule/lci.go +++ b/pkg/LinuxCIModule/lci.go @@ -226,7 +226,7 @@ func Initialize() { } } ctx = context.Background() - nlink = utils.NewNetlinkWrapper() + nlink = utils.NewNetlinkWrapperWithArgs(false) } // DeInitialize function handles stops functionality diff --git a/pkg/LinuxGeneralModule/lgm.go b/pkg/LinuxGeneralModule/lgm.go index 28d51758..c22c41fe 100644 --- a/pkg/LinuxGeneralModule/lgm.go +++ b/pkg/LinuxGeneralModule/lgm.go @@ -363,7 +363,7 @@ func Initialize() { brTenant = "br-tenant" ipMtu = config.GlobalConfig.LinuxFrr.IPMtu ctx = context.Background() - nlink = utils.NewNetlinkWrapper() + nlink = utils.NewNetlinkWrapperWithArgs(false) // Set up the static configuration parts _, err := nlink.LinkByName(ctx, brTenant) if err != nil { diff --git a/pkg/LinuxVendorModule/intele2000/intelE2000.go b/pkg/LinuxVendorModule/intele2000/intelE2000.go index d9c26674..98a84e72 100644 --- a/pkg/LinuxVendorModule/intele2000/intelE2000.go +++ b/pkg/LinuxVendorModule/intele2000/intelE2000.go @@ -421,7 +421,7 @@ func Initialize() { ipMtu = config.GlobalConfig.LinuxFrr.IPMtu brTenant = "br-tenant" ctx = context.Background() - nlink = utils.NewNetlinkWrapper() + nlink = utils.NewNetlinkWrapperWithArgs(false) } // DeInitialize function handles stops functionality diff --git a/pkg/frr/frr.go b/pkg/frr/frr.go index 19dfb935..c17966f5 100644 --- a/pkg/frr/frr.go +++ b/pkg/frr/frr.go @@ -256,7 +256,7 @@ func Initialize() { subscribeInfradb(&config.GlobalConfig) ctx = context.Background() - Frr = utils.NewFrrWrapper() + Frr = utils.NewFrrWrapperWithArgs("localhost", false) // Make sure IPv4 forwarding is enabled. detail, flag := run([]string{"sysctl", "-w", " net.ipv4.ip_forward=1"}, false) diff --git a/pkg/netlink/netlink_watcher.go b/pkg/netlink/netlink_watcher.go index 4977d6e4..a7b5137c 100644 --- a/pkg/netlink/netlink_watcher.go +++ b/pkg/netlink/netlink_watcher.go @@ -76,6 +76,7 @@ const ( // NexthopStruct TYPE & L2NEXTHOP TYPE & FDBentry VXLAN BRIDGEPORT OTHER + IGNORE ) // rtNNeighbor @@ -167,34 +168,34 @@ type routeCmdInfo struct { } // routes Variable -var routes = make(map[routeKey]RouteStruct) +var routes = make(map[routeKey]*RouteStruct) // Nexthops Variable -var Nexthops = make(map[nexthopKey]NexthopStruct) +var Nexthops = make(map[nexthopKey]*NexthopStruct) // Neighbors Variable var Neighbors = make(map[neighKey]neighStruct) // fDB Variable -var fDB = make(map[fdbKey]FdbEntryStruct) +var fDB = make(map[fdbKey]*FdbEntryStruct) // l2Nexthops Variable -var l2Nexthops = make(map[l2NexthopKey]L2NexthopStruct) +var l2Nexthops = make(map[l2NexthopKey]*L2NexthopStruct) // latestRoutes Variable -var latestRoutes = make(map[routeKey]RouteStruct) +var latestRoutes = make(map[routeKey]*RouteStruct) // latestNexthop Variable -var latestNexthop = make(map[nexthopKey]NexthopStruct) +var latestNexthop = make(map[nexthopKey]*NexthopStruct) // latestNeighbors Variable var latestNeighbors = make(map[neighKey]neighStruct) // latestFDB Variable -var latestFDB = make(map[fdbKey]FdbEntryStruct) +var latestFDB = make(map[fdbKey]*FdbEntryStruct) // latestL2Nexthop Variable -var latestL2Nexthop = make(map[l2NexthopKey]L2NexthopStruct) +var latestL2Nexthop = make(map[l2NexthopKey]*L2NexthopStruct) /*-------------------------------------------------------------------------- ### Route Database Entries @@ -215,7 +216,7 @@ var latestL2Nexthop = make(map[l2NexthopKey]L2NexthopStruct) type RouteStruct struct { Route0 vn.Route Vrf *infradb.Vrf - Nexthops []NexthopStruct + Nexthops []*NexthopStruct Metadata map[interface{}]interface{} NlType string Key routeKey @@ -224,7 +225,7 @@ type RouteStruct struct { // routeList list has route info type routeList struct { - RS []RouteStruct + RS []*RouteStruct } // NexthopStruct contains nexthop structure @@ -237,7 +238,7 @@ type NexthopStruct struct { ID int Scope int Protocol int - RouteRefs []RouteStruct + RouteRefs []*RouteStruct Key nexthopKey Resolved bool Neighbor *neighStruct @@ -265,7 +266,7 @@ type L2NexthopStruct struct { lb *infradb.LogicalBridge bp *infradb.BridgePort ID int - FdbRefs []FdbEntryStruct + FdbRefs []*FdbEntryStruct Resolved bool Type int Metadata map[interface{}]interface{} @@ -279,7 +280,7 @@ type FdbEntryStruct struct { State string lb *infradb.LogicalBridge bp *infradb.BridgePort - Nexthop L2NexthopStruct + Nexthop *L2NexthopStruct Type int Metadata map[interface{}]interface{} Err error @@ -477,7 +478,7 @@ func NHAssignID(key nexthopKey) int { } // NHParse parses the neighbor -func NHParse(v *infradb.Vrf, rc *routeCmdInfo) NexthopStruct { +func NHParse(v *infradb.Vrf, rc routeCmdInfo) *NexthopStruct { var nh NexthopStruct nh.Weight = 1 nh.Vrf = v @@ -513,7 +514,7 @@ func NHParse(v *infradb.Vrf, rc *routeCmdInfo) NexthopStruct { nh.Weight = rc.Weight } nh.Key = nexthopKey{nh.Vrf.Name, nh.nexthop.Gw.String(), nh.nexthop.LinkIndex, nh.Local} - return nh + return &nh } // checkRtype checks the route type @@ -528,7 +529,7 @@ func checkRtype(rType string) bool { } // preFilterRoute pre filter the routes -func preFilterRoute(r RouteStruct) bool { +func preFilterRoute(r *RouteStruct) bool { if checkRtype(r.NlType) && !r.Route0.Dst.IP.IsLoopback() && r.Route0.Dst.IP.String() != "0.0.0.0" { return true } @@ -548,7 +549,7 @@ func checkProto(proto int) bool { } // annotate function annonates the entries -func (route RouteStruct) annotate() RouteStruct { +func (route *RouteStruct) annotate() *RouteStruct { route.Metadata = make(map[interface{}]interface{}) for i := 0; i < len(route.Nexthops); i++ { nexthop := route.Nexthops[i] @@ -587,7 +588,7 @@ func (route RouteStruct) annotate() RouteStruct { } // nolint -func setRouteType(rs RouteStruct, v *infradb.Vrf) string { +func setRouteType(rs *RouteStruct, v *infradb.Vrf) string { if rs.Route0.Type == unix.RTN_UNICAST && rs.Route0.Protocol == unix.RTPROT_KERNEL && rs.Route0.Scope == unix.RT_SCOPE_LINK && len(rs.Nexthops) == 1 { // Connected routes are proto=kernel and scope=link with a netdev as single nexthop return routeTypeConnected @@ -617,7 +618,7 @@ func setRouteType(rs RouteStruct, v *infradb.Vrf) string { // ParseRoute parse the routes // nolint -func ParseRoute(v *infradb.Vrf, Rm []*routeCmdInfo, t int) routeList { +func ParseRoute(v *infradb.Vrf, Rm []routeCmdInfo, t int) routeList { var route routeList for _, Ro := range Rm { if Ro.Type == "" && (Ro.Dev != "" || Ro.Gateway != "") { @@ -705,22 +706,23 @@ func ParseRoute(v *infradb.Vrf, Rm []*routeCmdInfo, t int) routeList { if Ro.Table != 0 { rs.Route0.Table = Ro.Table } - rs.NlType = setRouteType(rs, v) + rs.NlType = setRouteType(&rs, v) rs.Key = routeKey{Table: rs.Route0.Table, Dst: rs.Route0.Dst.String()} - if preFilterRoute(rs) { - route.RS = append(route.RS, rs) + if preFilterRoute(&rs) { + route.RS = append(route.RS, &rs) } } return route } // ParseFdb parse the fdb -func ParseFdb(fdbIP fdbIPStruct) FdbEntryStruct { - var fdbentry = FdbEntryStruct{} +func ParseFdb(fdbIP fdbIPStruct) *FdbEntryStruct { + var fdbentry FdbEntryStruct fdbentry.VlanID = fdbIP.Vlan fdbentry.Mac = fdbIP.Mac fdbentry.Key = fdbKey{fdbIP.Vlan, fdbIP.Mac} fdbentry.State = fdbIP.State + fdbentry.Nexthop = &L2NexthopStruct{} lbs, _ := infradb.GetAllLBs() for _, lb := range lbs { if lb.Spec.VlanID == uint32(fdbentry.VlanID) { @@ -736,14 +738,14 @@ func ParseFdb(fdbIP fdbIPStruct) FdbEntryStruct { } Dev := fdbIP.Ifname dst := fdbIP.Dst - fdbentry.Nexthop = fdbentry.Nexthop.ParseL2NH(fdbentry.VlanID, Dev, dst, fdbentry.lb, fdbentry.bp) + fdbentry.Nexthop.ParseL2NH(fdbentry.VlanID, Dev, dst, fdbentry.lb, fdbentry.bp) fdbentry.Type = fdbentry.Nexthop.Type - return fdbentry + return &fdbentry } // nolint // ParseL2NH parse the l2hn -func (l2n L2NexthopStruct) ParseL2NH(vlanID int, dev string, dst string, LB *infradb.LogicalBridge, BP *infradb.BridgePort) L2NexthopStruct { +func (l2n *L2NexthopStruct) ParseL2NH(vlanID int, dev string, dst string, LB *infradb.LogicalBridge, BP *infradb.BridgePort) { l2n.Dev = dev l2n.VlanID = vlanID l2n.Dst = net.IP(dst) @@ -760,7 +762,6 @@ func (l2n L2NexthopStruct) ParseL2NH(vlanID int, dev string, dst string, LB *inf } else { l2n.Type = None } - return l2n } // L2NHAssignID get nexthop id @@ -776,7 +777,7 @@ func L2NHAssignID(key l2NexthopKey) int { } // addFdbEntry add fdb entries -func addFdbEntry(m FdbEntryStruct) { +func addFdbEntry(m *FdbEntryStruct) { m = addL2Nexthop(m) // TODO // logger.debug(f"Adding {m.format()}.") @@ -784,13 +785,9 @@ func addFdbEntry(m FdbEntryStruct) { } // addL2Nexthop add the l2 nexthop -func addL2Nexthop(m FdbEntryStruct) FdbEntryStruct { - if len(latestL2Nexthop) == 0 { - log.Fatal("netlink: L2Nexthop DB empty\n") - return FdbEntryStruct{} - } +func addL2Nexthop(m *FdbEntryStruct) *FdbEntryStruct { latestNexthops := latestL2Nexthop[m.Nexthop.Key] - if latestL2Nexthop != nil || len(latestL2Nexthop) != 0 { + if !(reflect.ValueOf(latestNexthops).IsZero()) { latestNexthops.FdbRefs = append(latestNexthops.FdbRefs, m) m.Nexthop = latestNexthops } else { @@ -837,6 +834,7 @@ func readLatestNetlinkState() { readRoutes(v) // Viswantha library } m := readFDB() + log.Printf("netlink: len(m) :%v\n", len(m)) for i := 0; i < len(m); i++ { addFdbEntry(m[i]) } @@ -874,10 +872,17 @@ func dumpDBs() { // nolint func neighborAnnotate(neighbor neighStruct) neighStruct { neighbor.Metadata = make(map[interface{}]interface{}) - if strings.HasPrefix(neighbor.Dev, path.Base(neighbor.VrfName)) && neighbor.Protocol != zebraStr { + var phyFlag bool + phyFlag = false + for k := range phyPorts { + if NameIndex[neighbor.Neigh0.LinkIndex] == k { + phyFlag = true + } + } + if strings.HasPrefix(NameIndex[neighbor.Neigh0.LinkIndex], path.Base(neighbor.VrfName)) && neighbor.Protocol != zebraStr { pattern := fmt.Sprintf(`%s-\d+$`, path.Base(neighbor.VrfName)) mustcompile := regexp.MustCompile(pattern) - s := mustcompile.FindStringSubmatch(neighbor.Dev) + s := mustcompile.FindStringSubmatch(NameIndex[neighbor.Neigh0.LinkIndex]) var LB *infradb.LogicalBridge var BP *infradb.BridgePort vID := strings.Split(s[0], "-")[1] @@ -901,12 +906,12 @@ func neighborAnnotate(neighbor neighStruct) neighStruct { if BP != nil { neighbor.Type = SVI neighbor.Metadata["vport_id"] = BP.Metadata.VPort - neighbor.Metadata["vlanID"] = vlanID + neighbor.Metadata["vlanID"] = uint32(vlanID) neighbor.Metadata["portType"] = BP.Spec.Ptype } else { - neighbor.Type = None + neighbor.Type = IGNORE } - } else if strings.HasPrefix(neighbor.Dev, path.Base(neighbor.VrfName)) && neighbor.Protocol == zebraStr { + } else if strings.HasPrefix(NameIndex[neighbor.Neigh0.LinkIndex], path.Base(neighbor.VrfName)) && neighbor.Protocol == zebraStr { pattern := fmt.Sprintf(`%s-\d+$`, path.Base(neighbor.VrfName)) mustcompile := regexp.MustCompile(pattern) s := mustcompile.FindStringSubmatch(neighbor.Dev) @@ -932,7 +937,7 @@ func neighborAnnotate(neighbor neighStruct) neighStruct { neighbor.Metadata["l2_nh"] = fdbEntry.Nexthop neighbor.Type = VXLAN // confirm this later } - } else if path.Base(neighbor.VrfName) == "GRD" && neighbor.Protocol != zebraStr { + } else if path.Base(neighbor.VrfName) == "GRD" && phyFlag && neighbor.Protocol != zebraStr { VRF, _ := infradb.GetVrf("//network.opiproject.org/vrfs/GRD") r, ok := lookupRoute(neighbor.Neigh0.IP, VRF) if ok { @@ -940,10 +945,10 @@ func neighborAnnotate(neighbor neighStruct) neighStruct { neighbor.Type = PHY neighbor.Metadata["vport_id"] = phyPorts[NameIndex[neighbor.Neigh0.LinkIndex]] } else { - neighbor.Type = None + neighbor.Type = IGNORE } } else { - neighbor.Type = None + neighbor.Type = OTHER } } return neighbor @@ -1113,7 +1118,7 @@ func dumpNeighDB() string { } // getProto gets the route protocol -func getProto(n RouteStruct) string { +func getProto(n *RouteStruct) string { for p, i := range rtnProto { if i == int(n.Route0.Protocol) { return p @@ -1133,12 +1138,12 @@ func checkNeigh(nk neighKey) bool { } // tryResolve resolves the neighbor -func tryResolve(nexhthopSt NexthopStruct) NexthopStruct { - if len(nexhthopSt.nexthop.Gw) != 0 { +func tryResolve(nexhthopSt *NexthopStruct) *NexthopStruct { + if !reflect.ValueOf(nexhthopSt.nexthop.Gw).IsZero() { // Nexthops with a gateway IP need resolution of that IP neighborKey := neighKey{Dst: nexhthopSt.nexthop.Gw.String(), VrfName: nexhthopSt.Vrf.Name, Dev: nexhthopSt.nexthop.LinkIndex} ch := checkNeigh(neighborKey) - if ch && latestNeighbors[neighborKey].Neigh0.Type != 0 { + if ch && latestNeighbors[neighborKey].Type != IGNORE { nexhthopSt.Resolved = true nh := latestNeighbors[neighborKey] nexhthopSt.Neighbor = &nh @@ -1162,7 +1167,7 @@ func checkNhDB(nhKey nexthopKey) bool { } // addNexthop adds the nexthop -func addNexthop(nexthop NexthopStruct, r RouteStruct) RouteStruct { +func addNexthop(nexthop *NexthopStruct, r *RouteStruct) *RouteStruct { ch := checkNhDB(nexthop.Key) if ch { NH0 := latestNexthop[nexthop.Key] @@ -1181,7 +1186,7 @@ func addNexthop(nexthop NexthopStruct, r RouteStruct) RouteStruct { } // checkRoute checks the route -func checkRoute(r RouteStruct) bool { +func checkRoute(r *RouteStruct) bool { Rk := r.Key for k := range latestRoutes { if k == Rk { @@ -1192,7 +1197,7 @@ func checkRoute(r RouteStruct) bool { } // deleteNH deletes the neighbor -func deleteNH(nexthop []NexthopStruct) []NexthopStruct { +func deleteNH(nexthop []*NexthopStruct) []*NexthopStruct { index := len(nexthop) if index == 1 { nexthop = append(nexthop[:0], nexthop[1:]...) @@ -1205,7 +1210,7 @@ func deleteNH(nexthop []NexthopStruct) []NexthopStruct { } // addRoute add the route -func addRoute(r RouteStruct) { +func addRoute(r *RouteStruct) { ch := checkRoute(r) if ch { R0 := latestRoutes[r.Key] @@ -1309,7 +1314,7 @@ func getNeighborRoutes() []routeCmdInfo { // []map[string]string{ // on physical and SVI interfaces. var neighborRoutes []routeCmdInfo // []map[string]string for _, N := range latestNeighbors { - if (NameIndex[N.Neigh0.LinkIndex] == "enp0s1f0d1" || NameIndex[N.Neigh0.LinkIndex] == "enp0s1f0d3") && N.Neigh0.State == vn.NUD_REACHABLE { + if N.Type == PHY || N.Type == SVI || N.Type == VXLAN { vrf, _ := infradb.GetVrf(N.VrfName) table := int(*vrf.Metadata.RoutingTable[0]) @@ -1341,7 +1346,7 @@ func readNeighbors(v *infradb.Vrf) { } // preFilterMac filter the mac -func preFilterMac(f FdbEntryStruct) bool { +func preFilterMac(f *FdbEntryStruct) bool { // TODO m.nexthop.dst if f.VlanID != 0 || (f.Nexthop.Dst != nil && !f.Nexthop.Dst.IsUnspecified()) { log.Printf("netlink: %d vlan \n", len(f.Nexthop.Dst.String())) @@ -1352,7 +1357,7 @@ func preFilterMac(f FdbEntryStruct) bool { // cmdProcessRt process the route command func cmdProcessRt(v *infradb.Vrf, r string, t int) routeList { - var RouteData []*routeCmdInfo + var RouteData []routeCmdInfo if len(r) <= 3 { log.Println("netlink: Error in the cmd:", r) var route routeList @@ -1360,7 +1365,7 @@ func cmdProcessRt(v *infradb.Vrf, r string, t int) routeList { } CPs := strings.Split(r[2:len(r)-3], "},{") for i := 0; i < len(CPs); i++ { - var ri *routeCmdInfo + var ri routeCmdInfo log.Println(CPs[i]) err := json.Unmarshal([]byte(fmt.Sprintf("{%v}", CPs[i])), &ri) if err != nil { @@ -1375,7 +1380,7 @@ func cmdProcessRt(v *infradb.Vrf, r string, t int) routeList { // readRouteFromIP reads the routes from ip func readRouteFromIP(v *infradb.Vrf) { var Rl routeList - var rm []*routeCmdInfo + var rm []routeCmdInfo var Rt1 int for _, routeSt := range v.Metadata.RoutingTable { Rt1 = int(*routeSt) @@ -1391,7 +1396,7 @@ func readRouteFromIP(v *infradb.Vrf) { } nl := getNeighborRoutes() // Add extra routes for Resolved neighbors on connected subnets for i := 0; i < len(nl); i++ { - rm = append(rm, &nl[i]) + rm = append(rm, nl[i]) } nr := ParseRoute(v, rm, 0) for _, r := range nr.RS { @@ -1409,6 +1414,98 @@ func notifyAddDel(r interface{}, event string) { EventBus.Publish(event, r) } +func deepEqualN(n1 *NexthopStruct, n2 *NexthopStruct, nc bool) bool { + if !reflect.DeepEqual(n1.Vrf.Name, n2.Vrf.Name) { + return false + } + if !reflect.DeepEqual(n1.Weight, n2.Weight) { + return false + } + if !reflect.DeepEqual(n1.ID, n2.ID) { + return false + } + if !reflect.DeepEqual(n1.nexthop, n2.nexthop) { + return false + } + if !reflect.DeepEqual(n1.Key, n2.Key) { + return false + } + if !reflect.DeepEqual(n1.Local, n2.Local) { + return false + } + if !reflect.DeepEqual(n1.Metadata, n2.Metadata) { + return false + } + if !reflect.DeepEqual(n1.Metric, n2.Metric) { + return false + } + if !reflect.DeepEqual(n1.Scope, n2.Scope) { + return false + } + if !reflect.DeepEqual(n1.Resolved, n2.Resolved) { + return false + } + if !reflect.DeepEqual(n1.Protocol, n2.Protocol) { + return false + } + if !reflect.DeepEqual(n1.NhType, n2.NhType) { + return false + } + if nc { + if len(n1.RouteRefs) != len(n2.RouteRefs) { + return false + } + for i := range n1.RouteRefs { + ret := deepEqualR(n1.RouteRefs[i], n2.RouteRefs[i], false) + if !ret { + return false + } + } + } + /*if !reflect.DeepEqual(N1.Neighbor, N2.Neighbor) { + return false + }*/ + return true +} + +func deepEqualR(r1 *RouteStruct, r2 *RouteStruct, nc bool) bool { + if !reflect.DeepEqual(r1.Vrf.Name, r2.Vrf.Name) { + return false + } + if !reflect.DeepEqual(r1.Route0, r2.Route0) { + return false + } + if !reflect.DeepEqual(r1.Key, r2.Key) { + return false + } + if !reflect.DeepEqual(r1.NlType, r2.NlType) { + return false + } + if !reflect.DeepEqual(r1.Metadata, r2.Metadata) { + return false + } + if nc { + if len(r1.Nexthops) != len(r2.Nexthops) { + return false + } + return deepEqualN(r1.Nexthops[0], r2.Nexthops[0], false) + } + return true +} + +func deepCheck(v1 interface{}, v2 interface{}, event []string) bool { + if strings.HasPrefix(event[1], "route") { + r1 := v1.(*RouteStruct) + r2 := v2.(*RouteStruct) + return deepEqualR(r1, r2, true) + } else if strings.HasPrefix(event[1], "nexthop") { + n1 := v1.(*NexthopStruct) + n2 := v2.(*NexthopStruct) + return deepEqualN(n1, n2, true) + } + return true +} + // nolint func notify_changes(new_db map[interface{}]interface{}, old_db map[interface{}]interface{}, event []string) { DB2 := old_db @@ -1418,23 +1515,23 @@ func notify_changes(new_db map[interface{}]interface{}, old_db map[interface{}]i for k1, v1 := range DB1 { for k2, v2 := range DB2 { if k1 == k2 { - if !reflect.DeepEqual(v1, v2) { + if !deepCheck(v1, v2, event) { // To Avoid in-correct update notification due to race condition in which metadata is nil in new entry and crashing in dcgw module if strings.Contains(event[1], "route") || strings.HasPrefix(event[1], "nexthop") { - var Rv RouteStruct - var Nv NexthopStruct + var rv *RouteStruct + var nv *NexthopStruct if strings.Contains(event[1], "route") { - Rv = v1.(RouteStruct) - if Rv.Vrf.Status.VrfOperStatus == infradb.VrfOperStatusToBeDeleted { - notifyAddDel(Rv, event[2]) + rv = v1.(*RouteStruct) + if rv.Vrf.Status.VrfOperStatus == infradb.VrfOperStatusToBeDeleted { + notifyAddDel(rv, event[2]) delete(new_db, k1) delete(old_db, k2) break } } else if strings.Contains(event[1], "nexthop") { - Nv = v1.(NexthopStruct) - if Nv.Vrf.Status.VrfOperStatus == infradb.VrfOperStatusToBeDeleted { - notifyAddDel(Nv, event[2]) + nv = v1.(*NexthopStruct) + if nv.Vrf.Status.VrfOperStatus == infradb.VrfOperStatusToBeDeleted { + notifyAddDel(nv, event[2]) delete(new_db, k1) delete(old_db, k2) break @@ -1458,10 +1555,10 @@ func notify_changes(new_db map[interface{}]interface{}, old_db map[interface{}]i } // readFDB read the fdb from db -func readFDB() []FdbEntryStruct { +func readFDB() []*FdbEntryStruct { var fdbs []fdbIPStruct - var macs []FdbEntryStruct - var fs FdbEntryStruct + var macs []*FdbEntryStruct + var fs *FdbEntryStruct CP, err := nlink.ReadFDB(ctx) if err != nil || len(CP) == 3 { @@ -1487,7 +1584,7 @@ func readFDB() []FdbEntryStruct { } // lookupRoute check the routes -func lookupRoute(dst net.IP, v *infradb.Vrf) (RouteStruct, bool) { +func lookupRoute(dst net.IP, v *infradb.Vrf) (*RouteStruct, bool) { // FIXME: If the semantic is to return the current entry of the NetlinkDB // routing table, a direct lookup in Linux should only be done as fallback // if there is no match in the DB. @@ -1499,8 +1596,8 @@ func lookupRoute(dst net.IP, v *infradb.Vrf) (RouteStruct, bool) { CP, err = nlink.RouteLookup(ctx, dst.String(), "") } if err != nil { - log.Fatal("netlink : Command error \n", err) - return RouteStruct{}, false + log.Printf("netlink : Command error %v\n", err) + return &RouteStruct{}, false } r := cmdProcessRt(v, CP, int(*v.Metadata.RoutingTable[0])) log.Printf("netlink: %+v\n", r) @@ -1508,7 +1605,7 @@ func lookupRoute(dst net.IP, v *infradb.Vrf) (RouteStruct, bool) { R1 := r.RS[0] // ### Search the latestRoutes DB snapshot if that exists, else // ### the current DB Route table. - var RouteTable map[routeKey]RouteStruct + var RouteTable map[routeKey]*RouteStruct if len(latestRoutes) != 0 { RouteTable = latestRoutes } else { @@ -1524,11 +1621,11 @@ func lookupRoute(dst net.IP, v *infradb.Vrf) (RouteStruct, bool) { } log.Printf("netlink: Failed to lookup route %v in VRF %v", dst, v) - return RouteStruct{}, false + return &RouteStruct{}, false } // nolint -func (nexthop NexthopStruct) annotate() NexthopStruct { +func (nexthop *NexthopStruct) annotate() *NexthopStruct { nexthop.Metadata = make(map[interface{}]interface{}) var phyFlag bool phyFlag = false @@ -1660,7 +1757,7 @@ func (nexthop NexthopStruct) annotate() NexthopStruct { } // nolint -func (l2n L2NexthopStruct) annotate() L2NexthopStruct { +func (l2n *L2NexthopStruct) annotate() *L2NexthopStruct { // Annotate certain L2 Nexthops with additional information from LB and GRD l2n.Metadata = make(map[interface{}]interface{}) LB := l2n.lb @@ -1704,7 +1801,7 @@ func (l2n L2NexthopStruct) annotate() L2NexthopStruct { } // annotate the route -func (fdb FdbEntryStruct) annotate() FdbEntryStruct { +func (fdb *FdbEntryStruct) annotate() *FdbEntryStruct { if fdb.VlanID == 0 { return fdb } @@ -1756,7 +1853,7 @@ func annotateDBEntries() { // installFilterRoute install the route filter func installFilterRoute(routeSt *RouteStruct) bool { - var nh []NexthopStruct + var nh []*NexthopStruct for _, n := range routeSt.Nexthops { if n.Resolved { nh = append(nh, n) @@ -1779,7 +1876,7 @@ func checkNhType(nType int) bool { } // installFilterNH install the neighbor filter -func installFilterNH(nh NexthopStruct) bool { +func installFilterNH(nh *NexthopStruct) bool { check := checkNhType(nh.NhType) keep := check && nh.Resolved && len(nh.RouteRefs) != 0 return keep @@ -1796,7 +1893,7 @@ func checkFdbType(fdbtype int) bool { } // installFilterFDB install fdb filer -func installFilterFDB(fdb FdbEntryStruct) bool { +func installFilterFDB(fdb *FdbEntryStruct) bool { // Drop entries w/o VLAN ID or associated LogicalBridge ... // ... other than with L2 nexthops of type VXLAN and BridgePort ... // ... and VXLAN entries with unresolved underlay nextop. @@ -1808,7 +1905,7 @@ func installFilterFDB(fdb FdbEntryStruct) bool { } // installFilterL2N install the l2 filter -func installFilterL2N(l2n L2NexthopStruct) bool { +func installFilterL2N(l2n *L2NexthopStruct) bool { keep := !(l2n.Type == 0 && l2n.Resolved && len(l2n.FdbRefs) == 0) if !keep { log.Printf("netlink: install_filter fDB: dropping {%+v}", l2n) @@ -1819,7 +1916,7 @@ func installFilterL2N(l2n L2NexthopStruct) bool { // nolint func applyInstallFilters() { for K, r := range latestRoutes { - if !installFilterRoute(&r) { + if !installFilterRoute(r) { // Remove route from its nexthop(s) delete(latestRoutes, K) } @@ -1857,10 +1954,10 @@ func notifyDBChanges() { l2nexthopEventStr = append(l2nexthopEventStr, "l2_nexthop"+s) } type NlDBCopy struct { - RDB map[routeKey]RouteStruct - NDB map[nexthopKey]NexthopStruct - FBDB map[fdbKey]FdbEntryStruct - L2NDB map[l2NexthopKey]L2NexthopStruct + RDB map[routeKey]*RouteStruct + NDB map[nexthopKey]*NexthopStruct + FBDB map[fdbKey]*FdbEntryStruct + L2NDB map[l2NexthopKey]*L2NexthopStruct } latestdb := NlDBCopy{RDB: latestRoutes, NDB: latestNexthop, FBDB: latestFDB, L2NDB: latestL2Nexthop} olddb := NlDBCopy{RDB: routes, NDB: Nexthops, FBDB: fDB, L2NDB: l2Nexthops} @@ -1931,11 +2028,11 @@ func resyncWithKernel() { // DeleteLatestDB deletes the latest db snap func DeleteLatestDB() { - latestRoutes = make(map[routeKey]RouteStruct) + latestRoutes = make(map[routeKey]*RouteStruct) latestNeighbors = make(map[neighKey]neighStruct) - latestNexthop = make(map[nexthopKey]NexthopStruct) - latestFDB = make(map[fdbKey]FdbEntryStruct) - latestL2Nexthop = make(map[l2NexthopKey]L2NexthopStruct) + latestNexthop = make(map[nexthopKey]*NexthopStruct) + latestFDB = make(map[fdbKey]*FdbEntryStruct) + latestL2Nexthop = make(map[l2NexthopKey]*L2NexthopStruct) } // monitorNetlink moniters the netlink @@ -1978,7 +2075,7 @@ func Initialize() { } getlink() ctx = context.Background() - nlink = utils.NewNetlinkWrapper() + nlink = utils.NewNetlinkWrapperWithArgs(false) // stopMonitoring = false stopMonitoring.Store(false) go monitorNetlink() // monitor Thread started diff --git a/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/dcgw.go b/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/dcgw.go index 72045ede..cb1e9ef0 100644 --- a/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/dcgw.go +++ b/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/dcgw.go @@ -101,14 +101,6 @@ var RefCountOp = struct { DECREMENT: 2, } -// ipuDB structure of ipu db port type -var ipuDB = struct { - TRUNK, ACCESS int -}{ - TRUNK: 0, - ACCESS: 1, -} - // IDPool structure maintaining mod ptr pool type IDPool struct { _inUseIDs map[interface{}]uint32 @@ -685,7 +677,7 @@ func _deleteTcamEntry(vrfID uint32, direction int) ([]interface{}, uint32) { FieldValue: map[string][2]interface{}{ "user_meta.cmeta.tcam_prefix": {uint32(tcam), "ternary"}, }, - Priority: int32(1), + Priority: int32(tidx), }, }) } @@ -840,7 +832,7 @@ func (l L3Decoder) getVrfID(route netlink_polling.RouteStruct) uint32 { return 0 } - return *route.Vrf.Spec.Vni + return *route.Vrf.Metadata.RoutingTable[0] } // _l3HostRoute gets the l3 host route @@ -878,7 +870,7 @@ func (l L3Decoder) _l3HostRoute(route netlink_polling.RouteStruct, delete string }, Action: p4client.Action{ ActionName: "linux_networking_control.set_neighbor", - Params: []interface{}{uint16(_p4NexthopID(route.Nexthops[0], dir))}, + Params: []interface{}{uint16(_p4NexthopID(*route.Nexthops[0], dir))}, }, }) } @@ -901,7 +893,7 @@ func (l L3Decoder) _l3HostRoute(route netlink_polling.RouteStruct, delete string Tablename: l3P2PRtHost, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "vrf": {_bigEndian16(vrfID), "exact"}, + "vrf": {bigEndian16(vrfID), "exact"}, "direction": {uint16(Direction.Rx), "exact"}, "dst_ip": {host, "exact"}, }, @@ -909,7 +901,7 @@ func (l L3Decoder) _l3HostRoute(route netlink_polling.RouteStruct, delete string }, Action: p4client.Action{ ActionName: "linux_networking_control.set_p2p_neighbor", - Params: []interface{}{uint16(_p4NexthopID(route.Nexthops[0], Direction.Rx))}, + Params: []interface{}{uint16(_p4NexthopID(*route.Nexthops[0], Direction.Rx))}, }, }) } @@ -937,7 +929,7 @@ func (l L3Decoder) _l3Route(route netlink_polling.RouteStruct, delete string) [] "ipv4_table_lpm_root1": {tIdx, "ternary"}, "dst_ip": {net.ParseIP(addr), "lpm"}, }, - Priority: int32(0), + Priority: int32(1), }, }) } else { @@ -952,11 +944,11 @@ func (l L3Decoder) _l3Route(route netlink_polling.RouteStruct, delete string) [] "ipv4_table_lpm_root1": {tIdx, "ternary"}, "dst_ip": {net.ParseIP(addr), "lpm"}, }, - Priority: int32(0), + Priority: int32(1), }, Action: p4client.Action{ ActionName: "linux_networking_control.set_neighbor", - Params: []interface{}{uint16(_p4NexthopID(route.Nexthops[0], Direction.Rx))}, + Params: []interface{}{uint16(_p4NexthopID(*route.Nexthops[0], Direction.Rx))}, }, }) } @@ -971,7 +963,7 @@ func (l L3Decoder) _l3Route(route netlink_polling.RouteStruct, delete string) [] "ipv4_table_lpm_root2": {tidx, "ternary"}, "dst_ip": {net.ParseIP(addr), "lpm"}, }, - Priority: int32(0), + Priority: int32(1), }, }) } else { @@ -982,11 +974,11 @@ func (l L3Decoder) _l3Route(route netlink_polling.RouteStruct, delete string) [] "ipv4_table_lpm_root2": {tidx, "ternary"}, "dst_ip": {net.ParseIP(addr), "lpm"}, }, - Priority: int32(0), + Priority: int32(1), }, Action: p4client.Action{ ActionName: "linux_networking_control.set_p2p_neighbor", - Params: []interface{}{uint16(_p4NexthopID(route.Nexthops[0], Direction.Rx))}, + Params: []interface{}{uint16(_p4NexthopID(*route.Nexthops[0], Direction.Rx))}, }, }) } @@ -1132,11 +1124,15 @@ func (l L3Decoder) translateAddedNexthop(nexthop netlink_polling.NexthopStruct) case netlink_polling.SVI: var smac, _ = net.ParseMAC(nexthop.Metadata["smac"].(string)) var dmac, _ = net.ParseMAC(nexthop.Metadata["dmac"].(string)) - var vlanID = nexthop.Metadata["vlanID"] - var vport = _toEgressVsi(nexthop.Metadata["egress_vport"].(int)) - var Type = nexthop.Metadata["portType"] + var vlanID = nexthop.Metadata["vlanID"].(uint32) + vp, err := strconv.Atoi(nexthop.Metadata["egress_vport"].(string)) + if err != nil { + panic(err) + } + var vport = _toEgressVsi(vp) + var Type = nexthop.Metadata["portType"].(infradb.BridgePortType) switch Type { - case ipuDB.TRUNK: + case infradb.Trunk: entries = append(entries, p4client.TableEntry{ Tablename: pushMacVlan, @@ -1148,7 +1144,7 @@ func (l L3Decoder) translateAddedNexthop(nexthop netlink_polling.NexthopStruct) }, Action: p4client.Action{ ActionName: "linux_networking_control.update_smac_dmac_vlan", - Params: []interface{}{smac, dmac, 0, 1, vlanID.(uint16)}, + Params: []interface{}{smac, dmac, 0, 1, uint16(vlanID)}, }, }, p4client.TableEntry{ @@ -1166,7 +1162,7 @@ func (l L3Decoder) translateAddedNexthop(nexthop netlink_polling.NexthopStruct) }, }) // } else if Type == ipuDB.ACCESS { - case ipuDB.ACCESS: + case infradb.Access: entries = append(entries, p4client.TableEntry{ Tablename: macMod, TableField: p4client.TableField{ @@ -1287,9 +1283,9 @@ func (l L3Decoder) translateDeletedNexthop(nexthop netlink_polling.NexthopStruct }) // } else if nexthop.NhType == netlink_polling.SVI { case netlink_polling.SVI: - var Type = nexthop.Metadata["portType"] + var Type = nexthop.Metadata["portType"].(infradb.BridgePortType) switch Type { - case ipuDB.TRUNK: + case infradb.Trunk: // if Type == ipuDB.TRUNK { entries = append(entries, p4client.TableEntry{ Tablename: pushMacVlan, @@ -1311,7 +1307,7 @@ func (l L3Decoder) translateDeletedNexthop(nexthop netlink_polling.NexthopStruct }, }) // } else if Type == ipuDB.ACCESS { - case ipuDB.ACCESS: + case infradb.Access: entries = append(entries, p4client.TableEntry{ Tablename: macMod, TableField: p4client.TableField{ @@ -1369,7 +1365,7 @@ func (l L3Decoder) StaticAdditions() []interface{} { }, ) for _, port := range l._grpcPorts { - var peerVsi, err = strconv.Atoi(port.peer["vsi"]) + var peerVsi, err = strconv.ParseInt(port.peer["vsi"], 10, 64) if err != nil { panic(err) } @@ -1386,7 +1382,7 @@ func (l L3Decoder) StaticAdditions() []interface{} { }, Action: p4client.Action{ ActionName: "linux_networking_control.fwd_to_port", - Params: []interface{}{uint32(_toEgressVsi(peerVsi))}, + Params: []interface{}{uint32(_toEgressVsi(int(peerVsi)))}, }, }, p4client.TableEntry{ @@ -1602,7 +1598,7 @@ func (v VxlanDecoder) translateAddedVrf(vrf *infradb.Vrf) []interface{} { if !_isL3vpnEnabled(vrf) { return entries } - var tcamPrefix, err = _getTcamPrefix(*vrf.Spec.Vni, Direction.Rx) + var tcamPrefix, err = _getTcamPrefix(*vrf.Metadata.RoutingTable[0], Direction.Rx) if err != nil { return entries } @@ -1643,7 +1639,7 @@ func (v VxlanDecoder) translateAddedVrf(vrf *infradb.Vrf) []interface{} { }, Action: p4client.Action{ ActionName: "linux_networking_control.pop_vxlan_set_vrf_id", - Params: []interface{}{ModPointer.ignorePtr, uint32(tcamPrefix), uint32(_toEgressVsi(v._defaultVsi)), *vrf.Spec.Vni}, + Params: []interface{}{ModPointer.ignorePtr, uint32(tcamPrefix), uint32(_toEgressVsi(v._defaultVsi)), *vrf.Metadata.RoutingTable[0]}, }, }) return entries @@ -1766,7 +1762,7 @@ func (v VxlanDecoder) translateAddedNexthop(nexthop netlink_polling.NexthopStruc }, Action: p4client.Action{ ActionName: "linux_networking_control.omac_vxlan_imac_push", - Params: []interface{}{smac, dmac, net.IP(srcAddr.(string)), net.IP(dstAddr.(string)), v.vxlanUDPPort, vni.(uint32), innerSmacAddr, innerDmacAddr}, + Params: []interface{}{smac, dmac, net.ParseIP(srcAddr.(string)), net.ParseIP(dstAddr.(string)), v.vxlanUDPPort, vni.(uint32), innerSmacAddr, innerDmacAddr}, }, }, p4client.TableEntry{ @@ -1904,14 +1900,14 @@ func (v VxlanDecoder) translateAddedL2Nexthop(nexthop netlink_polling.L2NexthopS }, Action: p4client.Action{ ActionName: "linux_networking_control.omac_vxlan_push", - Params: []interface{}{srcMac, dstMac, net.IP(srcIP.(string)), net.ParseIP(dstIP.(string)), v.vxlanUDPPort, vni.(uint32)}, + Params: []interface{}{srcMac, dstMac, net.ParseIP(srcIP.(string)), net.ParseIP(dstIP.(string)), v.vxlanUDPPort, vni.(uint32)}, }, }, p4client.TableEntry{ Tablename: l2Nh, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "neighbor": {_bigEndian16(neighbor), "exact"}, + "neighbor": {uint16(neighbor), "exact"}, "bit32_zeros": {uint32(0), "exact"}, }, Priority: int32(0), @@ -1958,7 +1954,7 @@ func (v VxlanDecoder) translateDeletedL2Nexthop(nexthop netlink_polling.L2Nextho Tablename: l2Nh, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "neighbor": {_bigEndian16(neighbor), "exact"}, + "neighbor": {uint16(neighbor), "exact"}, "bit32_zeros": {uint32(0), "exact"}, }, Priority: int32(0), @@ -1982,7 +1978,7 @@ func (v VxlanDecoder) translateAddedFdb(fdb netlink_polling.FdbEntryStruct) []in Tablename: l2Fwd, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "vlan_id": {_bigEndian16(fdb.VlanID), "exact"}, + "vlan_id": {uint16(fdb.VlanID), "exact"}, "da": {mac, "exact"}, "direction": {uint16(dir), "exact"}, }, @@ -2017,7 +2013,7 @@ func (v VxlanDecoder) translateDeletedFdb(fdb netlink_polling.FdbEntryStruct) [] Tablename: l2Fwd, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "vlan_id": {_bigEndian16(fdb.VlanID), "exact"}, + "vlan_id": {uint16(fdb.VlanID), "exact"}, "da": {mac, "exact"}, "direction": {uint16(dir), "exact"}, }, @@ -2103,7 +2099,7 @@ func (p PodDecoder) translateAddedBp(bp *infradb.BridgePort) ([]interface{}, err Tablename: popStag, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "mod_blob_ptr": {modPtrD, "exact"}, + "meta.common.mod_blob_ptr": {modPtrD, "exact"}, }, Priority: int32(0), }, @@ -2129,13 +2125,13 @@ func (p PodDecoder) translateAddedBp(bp *infradb.BridgePort) ([]interface{}, err Tablename: podOutTrunk, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "meta.common.mod_blob_ptr": {modPtrD, "exact"}, + "meta.common.mod_blob_ptr": {modPtr, "exact"}, }, Priority: int32(0), }, Action: p4client.Action{ ActionName: "linux_networking_control.vlan_push_trunk", - Params: []interface{}{0, 0, uint32(vsi)}, + Params: []interface{}{uint16(0), uint16(0), uint32(vsi)}, }, }) for _, vlan := range bp.Spec.LogicalBridges { @@ -2192,7 +2188,7 @@ func (p PodDecoder) translateAddedBp(bp *infradb.BridgePort) ([]interface{}, err log.Printf("intel-e2000: unable to find key %s and error is %v\n", SviObj.Spec.Vrf, err) return entries, err } - tcamPrefix, err := _getTcamPrefix(*VrfObj.Spec.Vni, Direction.Tx) + tcamPrefix, err := _getTcamPrefix(*VrfObj.Metadata.RoutingTable[0], Direction.Tx) if err != nil { return entries, err } @@ -2203,15 +2199,15 @@ func (p PodDecoder) translateAddedBp(bp *infradb.BridgePort) ([]interface{}, err Tablename: portInSviTrunk, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "vsi": {uint16(p._portMuxVsi), "exact"}, - "vid": {uint16(vsi), "exact"}, + "vsi": {uint16(vsi), "exact"}, + "vid": {vid, "exact"}, "da": {sviMac, "exact"}, }, Priority: int32(0), }, Action: p4client.Action{ ActionName: "linux_networking_control.pop_vlan_set_vrf_id", - Params: []interface{}{ignorePtr, uint32(tcamPrefix), uint32(0), uint16(*VrfObj.Spec.Vni)}, + Params: []interface{}{ignorePtr, uint32(tcamPrefix), uint32(0), uint16(*VrfObj.Metadata.RoutingTable[0])}, }, }) } else { @@ -2327,7 +2323,7 @@ func (p PodDecoder) translateAddedBp(bp *infradb.BridgePort) ([]interface{}, err log.Printf("intel-e2000: unable to find key %s and error is %v\n", SviObj.Spec.Vrf, err) return entries, err } - tcamPrefix, err := _getTcamPrefix(*VrfObj.Spec.Vni, Direction.Tx) + tcamPrefix, err := _getTcamPrefix(*VrfObj.Metadata.RoutingTable[0], Direction.Tx) if err != nil { return entries, err } @@ -2344,7 +2340,7 @@ func (p PodDecoder) translateAddedBp(bp *infradb.BridgePort) ([]interface{}, err }, Action: p4client.Action{ ActionName: "linux_networking_control.set_vrf_id_tx", - Params: []interface{}{uint32(tcamPrefix), uint32(0), uint16(*VrfObj.Spec.Vni)}, + Params: []interface{}{uint32(tcamPrefix), uint32(0), uint16(*VrfObj.Metadata.RoutingTable[0])}, }, }) } else { @@ -2387,7 +2383,7 @@ func (p PodDecoder) translateDeletedBp(bp *infradb.BridgePort) ([]interface{}, e Tablename: popStag, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "mod_blob_ptr": {modPtrD, "exact"}, + "meta.common.mod_blob_ptr": {modPtrD, "exact"}, }, Priority: int32(0), }, @@ -2405,7 +2401,7 @@ func (p PodDecoder) translateDeletedBp(bp *infradb.BridgePort) ([]interface{}, e Tablename: podOutTrunk, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "meta.common.mod_blob_ptr": {modPtrD, "exact"}, + "meta.common.mod_blob_ptr": {modPtr, "exact"}, }, Priority: int32(0), }, @@ -2457,8 +2453,8 @@ func (p PodDecoder) translateDeletedBp(bp *infradb.BridgePort) ([]interface{}, e Tablename: portInSviTrunk, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "vsi": {uint16(p._portMuxVsi), "exact"}, - "vid": {uint16(vsi), "exact"}, + "vsi": {uint16(vsi), "exact"}, + "vid": {vid, "exact"}, "da": {sviMac, "exact"}, }, Priority: int32(0), @@ -2596,7 +2592,7 @@ func (p PodDecoder) translateAddedSvi(svi *infradb.Svi) ([]interface{}, error) { log.Printf("intel-e2000: unable to find key %s and error is %v", svi.Spec.Vrf, err) return entries, err } - tcamPrefix, err := _getTcamPrefix(*VrfObj.Spec.Vni, Direction.Tx) + tcamPrefix, err := _getTcamPrefix(*VrfObj.Metadata.RoutingTable[0], Direction.Tx) if err != nil { return entries, err } @@ -2612,7 +2608,7 @@ func (p PodDecoder) translateAddedSvi(svi *infradb.Svi) ([]interface{}, error) { }, Action: p4client.Action{ ActionName: "linux_networking_control.set_vrf_id_tx", - Params: []interface{}{uint32(tcamPrefix), uint32(0), uint16(*VrfObj.Spec.Vni)}, + Params: []interface{}{uint32(tcamPrefix), uint32(0), uint16(*VrfObj.Metadata.RoutingTable[0])}, }, }) } else if PortObj.Spec.Ptype == infradb.Trunk { @@ -2701,7 +2697,7 @@ func (p PodDecoder) translateAddedFdb(fdb netlink_polling.FdbEntryStruct) []inte Tablename: l2Fwd, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "vlan_id": {_bigEndian16(fdb.VlanID), "exact"}, + "vlan_id": {uint16(fdb.VlanID), "exact"}, "da": {fdbMac, "exact"}, "direction": {uint16(dir), "exact"}, }, @@ -2734,7 +2730,7 @@ func (p PodDecoder) translateDeletedFdb(fdb netlink_polling.FdbEntryStruct) []in Tablename: l2Fwd, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "vlan_id": {_bigEndian16(fdb.VlanID), "exact"}, + "vlan_id": {uint16(fdb.VlanID), "exact"}, "da": {fdbMac, "exact"}, "direction": {uint16(dir), "exact"}, }, @@ -2753,25 +2749,27 @@ func (p PodDecoder) translateAddedL2Nexthop(nexthop netlink_polling.L2NexthopStr return entries } var neighbor = nexthop.ID - var portType = nexthop.Metadata["portType"] - var portID = nexthop.Metadata["vport_id"] - - if portType == ipuDB.ACCESS { + var portType = nexthop.Metadata["portType"].(infradb.BridgePortType) + var portID, err = strconv.Atoi(nexthop.Metadata["vport_id"].(string)) + if err != nil { + panic(err) + } + if portType == infradb.Access { entries = append(entries, p4client.TableEntry{ Tablename: l2Nh, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "neighbor": {_bigEndian16(neighbor), "exact"}, + "neighbor": {uint16(neighbor), "exact"}, "bit32_zeros": {uint32(0), "exact"}, }, Priority: int32(0), }, Action: p4client.Action{ ActionName: "linux_networking_control.fwd_to_port", - Params: []interface{}{uint32(_toEgressVsi(portID.(int)))}, + Params: []interface{}{uint32(_toEgressVsi(portID))}, }, }) - } else if portType == ipuDB.TRUNK { + } else if portType == infradb.Trunk { var key []interface{} key = append(key, nexthop.Key.Dev, nexthop.Key.VlanID, nexthop.Key.Dst) @@ -2793,14 +2791,14 @@ func (p PodDecoder) translateAddedL2Nexthop(nexthop netlink_polling.L2NexthopStr Tablename: l2Nh, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "neighbor": {_bigEndian16(neighbor), "exact"}, + "neighbor": {uint16(neighbor), "exact"}, "bit32_zeros": {uint32(0), "exact"}, }, Priority: int32(0), }, Action: p4client.Action{ ActionName: "linux_networking_control.push_vlan", - Params: []interface{}{modPtr, uint32(_toEgressVsi(portID.(int)))}, + Params: []interface{}{modPtr, uint32(_toEgressVsi(portID))}, }, }) } @@ -2821,20 +2819,20 @@ func (p PodDecoder) translateDeletedL2Nexthop(nexthop netlink_polling.L2NexthopS return entries } var neighbor = nexthop.ID - var portType = nexthop.Metadata["portType"] + var portType = nexthop.Metadata["portType"].(infradb.BridgePortType) - if portType == ipuDB.ACCESS { + if portType == infradb.Access { entries = append(entries, p4client.TableEntry{ Tablename: l2Nh, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "neighbor": {_bigEndian16(neighbor), "exact"}, + "neighbor": {uint16(neighbor), "exact"}, "bit32_zeros": {uint32(0), "exact"}, }, Priority: int32(0), }, }) - } else if portType == ipuDB.TRUNK { + } else if portType == infradb.Trunk { var key []interface{} key = append(key, nexthop.Key.Dev, nexthop.Key.VlanID, nexthop.Key.Dst) @@ -2852,7 +2850,7 @@ func (p PodDecoder) translateDeletedL2Nexthop(nexthop netlink_polling.L2NexthopS Tablename: l2Nh, TableField: p4client.TableField{ FieldValue: map[string][2]interface{}{ - "neighbor": {_bigEndian16(neighbor), "exact"}, + "neighbor": {uint16(neighbor), "exact"}, "bit32_zeros": {uint32(0), "exact"}, }, Priority: int32(0), diff --git a/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/p4trans.go b/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/p4trans.go index 149a830f..3faa5751 100644 --- a/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/p4trans.go +++ b/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/p4trans.go @@ -151,8 +151,8 @@ func startSubscriber(eventBus *eb.EventBus, eventType string) { // handleRouteAdded handles the added route func handleRouteAdded(route interface{}) { var entries []interface{} - routeData, _ := route.(nm.RouteStruct) - entries = L3.translateAddedRoute(routeData) + routeData, _ := route.(*nm.RouteStruct) + entries = L3.translateAddedRoute(*routeData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -168,8 +168,8 @@ func handleRouteAdded(route interface{}) { // handleRouteUpdated handles the updated route func handleRouteUpdated(route interface{}) { var entries []interface{} - routeData, _ := route.(nm.RouteStruct) - entries = L3.translateDeletedRoute(routeData) + routeData, _ := route.(*nm.RouteStruct) + entries = L3.translateDeletedRoute(*routeData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { err := p4client.DelEntry(e) @@ -180,7 +180,7 @@ func handleRouteUpdated(route interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = append(entries, L3.translateAddedRoute(routeData)) + entries = L3.translateAddedRoute(*routeData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -196,8 +196,8 @@ func handleRouteUpdated(route interface{}) { // handleRouteDeleted handles the deleted route func handleRouteDeleted(route interface{}) { var entries []interface{} - routeData, _ := route.(nm.RouteStruct) - entries = L3.translateDeletedRoute(routeData) + routeData, _ := route.(*nm.RouteStruct) + entries = L3.translateDeletedRoute(*routeData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -213,9 +213,8 @@ func handleRouteDeleted(route interface{}) { // handleNexthopAdded handles the added nexthop func handleNexthopAdded(nexthop interface{}) { var entries []interface{} - nexthopData, _ := nexthop.(nm.NexthopStruct) - entries = L3.translateAddedNexthop(nexthopData) - + nexthopData, _ := nexthop.(*nm.NexthopStruct) + entries = L3.translateAddedNexthop(*nexthopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -226,7 +225,7 @@ func handleNexthopAdded(nexthop interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Vxlan.translateAddedNexthop(nexthopData) + entries = Vxlan.translateAddedNexthop(*nexthopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -242,8 +241,8 @@ func handleNexthopAdded(nexthop interface{}) { // handleNexthopUpdated handles the updated nexthop func handleNexthopUpdated(nexthop interface{}) { var entries []interface{} - nexthopData, _ := nexthop.(nm.NexthopStruct) - entries = L3.translateDeletedNexthop(nexthopData) + nexthopData, _ := nexthop.(*nm.NexthopStruct) + entries = L3.translateDeletedNexthop(*nexthopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -254,7 +253,7 @@ func handleNexthopUpdated(nexthop interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Vxlan.translateDeletedNexthop(nexthopData) + entries = Vxlan.translateDeletedNexthop(*nexthopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -265,7 +264,7 @@ func handleNexthopUpdated(nexthop interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = L3.translateAddedNexthop(nexthopData) + entries = L3.translateAddedNexthop(*nexthopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -276,7 +275,7 @@ func handleNexthopUpdated(nexthop interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Vxlan.translateAddedNexthop(nexthopData) + entries = Vxlan.translateAddedNexthop(*nexthopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -292,8 +291,8 @@ func handleNexthopUpdated(nexthop interface{}) { // handleNexthopDeleted handles the deleted nexthop func handleNexthopDeleted(nexthop interface{}) { var entries []interface{} - nexthopData, _ := nexthop.(nm.NexthopStruct) - entries = L3.translateDeletedNexthop(nexthopData) + nexthopData, _ := nexthop.(*nm.NexthopStruct) + entries = L3.translateDeletedNexthop(*nexthopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -304,7 +303,7 @@ func handleNexthopDeleted(nexthop interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Vxlan.translateDeletedNexthop(nexthopData) + entries = Vxlan.translateDeletedNexthop(*nexthopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -320,8 +319,8 @@ func handleNexthopDeleted(nexthop interface{}) { // handleFbdEntryAdded handles the added fdb entry func handleFbdEntryAdded(fbdEntry interface{}) { var entries []interface{} - fbdEntryData, _ := fbdEntry.(nm.FdbEntryStruct) - entries = Vxlan.translateAddedFdb(fbdEntryData) + fbdEntryData, _ := fbdEntry.(*nm.FdbEntryStruct) + entries = Vxlan.translateAddedFdb(*fbdEntryData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -332,7 +331,7 @@ func handleFbdEntryAdded(fbdEntry interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Pod.translateAddedFdb(fbdEntryData) + entries = Pod.translateAddedFdb(*fbdEntryData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -348,8 +347,8 @@ func handleFbdEntryAdded(fbdEntry interface{}) { // handleFbdEntryUpdated handles the updated fdb entry func handleFbdEntryUpdated(fdbEntry interface{}) { var entries []interface{} - fbdEntryData, _ := fdbEntry.(nm.FdbEntryStruct) - entries = Vxlan.translateDeletedFdb(fbdEntryData) + fbdEntryData, _ := fdbEntry.(*nm.FdbEntryStruct) + entries = Vxlan.translateDeletedFdb(*fbdEntryData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -360,7 +359,7 @@ func handleFbdEntryUpdated(fdbEntry interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Pod.translateDeletedFdb(fbdEntryData) + entries = Pod.translateDeletedFdb(*fbdEntryData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -372,7 +371,7 @@ func handleFbdEntryUpdated(fdbEntry interface{}) { } } - entries = Vxlan.translateAddedFdb(fbdEntryData) + entries = Vxlan.translateAddedFdb(*fbdEntryData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -383,7 +382,7 @@ func handleFbdEntryUpdated(fdbEntry interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Pod.translateAddedFdb(fbdEntryData) + entries = Pod.translateAddedFdb(*fbdEntryData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -399,8 +398,8 @@ func handleFbdEntryUpdated(fdbEntry interface{}) { // handleFbdEntryDeleted handles the deleted fdb entry func handleFbdEntryDeleted(fdbEntry interface{}) { var entries []interface{} - fbdEntryData, _ := fdbEntry.(nm.FdbEntryStruct) - entries = Vxlan.translateDeletedFdb(fbdEntryData) + fbdEntryData, _ := fdbEntry.(*nm.FdbEntryStruct) + entries = Vxlan.translateDeletedFdb(*fbdEntryData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -411,7 +410,7 @@ func handleFbdEntryDeleted(fdbEntry interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Pod.translateDeletedFdb(fbdEntryData) + entries = Pod.translateDeletedFdb(*fbdEntryData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -427,9 +426,9 @@ func handleFbdEntryDeleted(fdbEntry interface{}) { // handleL2NexthopAdded handles the added l2 nexthop func handleL2NexthopAdded(l2NextHop interface{}) { var entries []interface{} - l2NextHopData, _ := l2NextHop.(nm.L2NexthopStruct) + l2NextHopData, _ := l2NextHop.(*nm.L2NexthopStruct) - entries = Vxlan.translateAddedL2Nexthop(l2NextHopData) + entries = Vxlan.translateAddedL2Nexthop(*l2NextHopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -440,7 +439,7 @@ func handleL2NexthopAdded(l2NextHop interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Pod.translateAddedL2Nexthop(l2NextHopData) + entries = Pod.translateAddedL2Nexthop(*l2NextHopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -456,8 +455,8 @@ func handleL2NexthopAdded(l2NextHop interface{}) { // handleL2NexthopUpdated handles the updated l2 nexthop func handleL2NexthopUpdated(l2NextHop interface{}) { var entries []interface{} - l2NextHopData, _ := l2NextHop.(nm.L2NexthopStruct) - entries = Vxlan.translateDeletedL2Nexthop(l2NextHopData) + l2NextHopData, _ := l2NextHop.(*nm.L2NexthopStruct) + entries = Vxlan.translateDeletedL2Nexthop(*l2NextHopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -468,7 +467,7 @@ func handleL2NexthopUpdated(l2NextHop interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Pod.translateDeletedL2Nexthop(l2NextHopData) + entries = Pod.translateDeletedL2Nexthop(*l2NextHopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) @@ -479,7 +478,7 @@ func handleL2NexthopUpdated(l2NextHop interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Vxlan.translateDeletedL2Nexthop(l2NextHopData) + entries = Vxlan.translateAddedL2Nexthop(*l2NextHopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -490,7 +489,7 @@ func handleL2NexthopUpdated(l2NextHop interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Pod.translateDeletedL2Nexthop(l2NextHopData) + entries = Pod.translateAddedL2Nexthop(*l2NextHopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.AddEntry(e) @@ -506,8 +505,8 @@ func handleL2NexthopUpdated(l2NextHop interface{}) { // handleL2NexthopDeleted handles the deleted l2 nexthop func handleL2NexthopDeleted(l2NextHop interface{}) { var entries []interface{} - l2NextHopData, _ := l2NextHop.(nm.L2NexthopStruct) - entries = Vxlan.translateDeletedL2Nexthop(l2NextHopData) + l2NextHopData, _ := l2NextHop.(*nm.L2NexthopStruct) + entries = Vxlan.translateDeletedL2Nexthop(*l2NextHopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { err := p4client.DelEntry(e) @@ -518,12 +517,12 @@ func handleL2NexthopDeleted(l2NextHop interface{}) { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } - entries = Pod.translateDeletedL2Nexthop(l2NextHopData) + entries = Pod.translateDeletedL2Nexthop(*l2NextHopData) for _, entry := range entries { if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) + er := p4client.DelEntry(e) if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) } } else { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") @@ -963,7 +962,7 @@ func tearDownVrf(vrf *infradb.Vrf) bool { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) } } else { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") @@ -981,7 +980,7 @@ func tearDownLb(lb *infradb.LogicalBridge) bool { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) } } else { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") @@ -1002,7 +1001,7 @@ func tearDownBp(bp *infradb.BridgePort) bool { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) } } else { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") @@ -1023,7 +1022,7 @@ func tearDownSvi(svi *infradb.Svi) bool { if e, ok := entry.(p4client.TableEntry); ok { er := p4client.DelEntry(e) if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) } } else { log.Println("intel-e2000: Entry is not of type p4client.TableEntry")