diff --git a/cmd/main.go b/cmd/main.go index 058bf379..1773e0d5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -44,6 +44,7 @@ import ( intel_e2000_linux "github.com/opiproject/opi-evpn-bridge/pkg/LinuxVendorModule/intele2000" frr "github.com/opiproject/opi-evpn-bridge/pkg/frr" netlink "github.com/opiproject/opi-evpn-bridge/pkg/netlink" + "github.com/opiproject/opi-evpn-bridge/pkg/vendor_plugins/intel-e2000/p4runtime/p4driverapi" ipu_vendor "github.com/opiproject/opi-evpn-bridge/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" ) @@ -73,7 +74,7 @@ var rootCmd = &cobra.Command{ intel_e2000_linux.Initialize() frr.Initialize() ipu_vendor.Initialize() - netlink.DeInitialize() + case "ci": gen_linux.Initialize() ci_linux.Initialize() @@ -91,7 +92,6 @@ var rootCmd = &cobra.Command{ netlink.Initialize() default: } - runGrpcServer(config.GlobalConfig.GRPCPort, config.GlobalConfig.TLSFiles) }, @@ -135,9 +135,6 @@ func setupLogger(filename string) { func cleanUp() { log.Println("Defer function called") - if err := deleteGrdVrf(); err != nil { - log.Println("Failed to delete GRD vrf") - } if err := infradb.DeleteAllResources(); err != nil { log.Println("Failed to delete all the resources: ", err) } @@ -146,7 +143,10 @@ func cleanUp() { gen_linux.DeInitialize() intel_e2000_linux.DeInitialize() frr.DeInitialize() + netlink.DeInitialize() ipu_vendor.DeInitialize() + close(p4driverapi.StopCh) + case "ci": gen_linux.DeInitialize() ci_linux.DeInitialize() @@ -205,12 +205,14 @@ func main() { // runGrpcServer start the grpc server for all the components func runGrpcServer(grpcPort uint16, tlsFiles string) { - tp := utils.InitTracerProvider("opi-evpn-bridge") - defer func() { - if err := tp.Shutdown(context.Background()); err != nil { - log.Panicf("Tracer Provider Shutdown: %v", err) - } - }() + if config.GlobalConfig.Tracer { + tp := utils.InitTracerProvider("opi-evpn-bridge") + defer func() { + if err := tp.Shutdown(context.Background()); err != nil { + log.Panicf("Tracer Provider Shutdown: %v", err) + } + }() + } lis, err := net.Listen("tcp", fmt.Sprintf(":%d", grpcPort)) if err != nil { @@ -313,16 +315,3 @@ func createGrdVrf() error { return nil } - -// deleteGrdVrf creates the grd vrf with vni 0 -func deleteGrdVrf() error { - log.Printf("DeleteGrdVrf(): deleted GRD VRF object\n") - - err := infradb.DeleteVrf("//network.opiproject.org/vrfs/GRD") - if err != nil { - log.Printf("CreateGrdVrf(): Error in deleting GRD VRF object %+v\n", err) - return err - } - - return nil -} diff --git a/config-intel-e2000.yaml b/config-intel-e2000.yaml index 7a73549d..5fa81f22 100644 --- a/config-intel-e2000.yaml +++ b/config-intel-e2000.yaml @@ -4,6 +4,7 @@ tlsfiles: database: redis dbaddress: 127.0.0.1:6379 buildenv: intel_e2000 +tracer: false subscribers: - name: "lvm" priority: 2 diff --git a/config.yaml b/config.yaml index 56ea77ff..c4c3305f 100644 --- a/config.yaml +++ b/config.yaml @@ -4,6 +4,7 @@ tlsfiles: database: redis dbaddress: 127.0.0.1:6379 buildenv: ci +tracer: false subscribers: - name: "lgm" priority: 1 diff --git a/pkg/LinuxCIModule/lci.go b/pkg/LinuxCIModule/lci.go index f62fcc3b..f73f964d 100644 --- a/pkg/LinuxCIModule/lci.go +++ b/pkg/LinuxCIModule/lci.go @@ -226,7 +226,7 @@ func Initialize() { } } ctx = context.Background() - nlink = utils.NewNetlinkWrapperWithArgs(false) + nlink = utils.NewNetlinkWrapperWithArgs(config.GlobalConfig.Tracer) } // DeInitialize function handles stops functionality diff --git a/pkg/LinuxGeneralModule/lgm.go b/pkg/LinuxGeneralModule/lgm.go index c22c41fe..e44ee1d9 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.NewNetlinkWrapperWithArgs(false) + nlink = utils.NewNetlinkWrapperWithArgs(config.GlobalConfig.Tracer) // 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 98a84e72..32c42db2 100644 --- a/pkg/LinuxVendorModule/intele2000/intelE2000.go +++ b/pkg/LinuxVendorModule/intele2000/intelE2000.go @@ -391,7 +391,7 @@ func tearDownVrf(vrf *infradb.Vrf) bool { Intf, err := nlink.LinkByName(ctx, vlanIntf) if err != nil { log.Printf("Failed to get link %v: %s\n", vlanIntf, err) - return true + return false } if err = nlink.LinkDel(ctx, Intf); err != nil { log.Printf("Failed to delete link %v: %s\n", vlanIntf, err) @@ -421,7 +421,7 @@ func Initialize() { ipMtu = config.GlobalConfig.LinuxFrr.IPMtu brTenant = "br-tenant" ctx = context.Background() - nlink = utils.NewNetlinkWrapperWithArgs(false) + nlink = utils.NewNetlinkWrapperWithArgs(config.GlobalConfig.Tracer) } // DeInitialize function handles stops functionality diff --git a/pkg/config/config.go b/pkg/config/config.go index ff771826..bd975192 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -82,6 +82,7 @@ type Config struct { Database string `yaml:"database"` DBAddress string `yaml:"dbaddress"` Buildenv string `yaml:"buildenv"` + Tracer bool `yaml:"tracer"` Subscribers []SubscriberConfig `yaml:"subscribers"` LinuxFrr LinuxFrrConfig `yaml:"linuxfrr"` Netlink NetlinkConfig `yaml:"netlink"` diff --git a/pkg/frr/frr.go b/pkg/frr/frr.go index c17966f5..29477fe9 100644 --- a/pkg/frr/frr.go +++ b/pkg/frr/frr.go @@ -48,11 +48,24 @@ func (h *ModulefrrHandler) HandleEvent(eventType string, objectData *eventbus.Ob } // handlesvi handles the svi functionality +// +//nolint:funlen,gocognit func handlesvi(objectData *eventbus.ObjectData) { var comp common.Component svi, err := infradb.GetSvi(objectData.Name) if err != nil { log.Printf("GetSvi error: %s %s\n", err, objectData.Name) + comp.Name = frrComp + comp.CompStatus = common.ComponentStatusError + if comp.Timer == 0 { + comp.Timer = 2 * time.Second + } else { + comp.Timer *= 2 + } + err := infradb.UpdateSviStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) + if err != nil { + log.Printf("error in updating svi status: %s\n", err) + } return } @@ -127,6 +140,17 @@ func handlevrf(objectData *eventbus.ObjectData) { vrf, err := infradb.GetVrf(objectData.Name) if err != nil { log.Printf("GetVRF error: %s %s\n", err, objectData.Name) + comp.Name = frrComp + comp.CompStatus = common.ComponentStatusError + if comp.Timer == 0 { // wait timer is 2 powerof natural numbers ex : 1,2,3... + comp.Timer = 2 * time.Second + } else { + comp.Timer *= 2 + } + err := infradb.UpdateVrfStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) + if err != nil { + log.Printf("error in updating vrf status: %s\n", err) + } return } @@ -256,7 +280,7 @@ func Initialize() { subscribeInfradb(&config.GlobalConfig) ctx = context.Background() - Frr = utils.NewFrrWrapperWithArgs("localhost", false) + Frr = utils.NewFrrWrapperWithArgs("localhost", config.GlobalConfig.Tracer) // Make sure IPv4 forwarding is enabled. detail, flag := run([]string{"sysctl", "-w", " net.ipv4.ip_forward=1"}, false) diff --git a/pkg/infradb/infradb.go b/pkg/infradb/infradb.go index e113a79e..1f913d8b 100644 --- a/pkg/infradb/infradb.go +++ b/pkg/infradb/infradb.go @@ -9,6 +9,7 @@ import ( "errors" "log" "sync" + "time" "github.com/opiproject/opi-evpn-bridge/pkg/infradb/common" "github.com/opiproject/opi-evpn-bridge/pkg/infradb/subscriberframework/eventbus" @@ -1217,6 +1218,24 @@ func GetAllSvis() ([]*Svi, error) { // DeleteAllResources deletes all components from infradb func DeleteAllResources() error { + duration := 10 * time.Second + bps, _ := GetAllBPs() + for _, bp := range bps { + err := DeleteBP(bp.Name) + if err != nil { + return err + } + } + startTime := time.Now() + for { + b, _ := GetAllBPs() + if len(b) == 0 { + break + } + if time.Since(startTime) > duration { + return errors.New("failed to delete BridgePorts") + } + } svis, _ := GetAllSvis() for _, svi := range svis { err := DeleteSvi(svi.Name) @@ -1224,7 +1243,16 @@ func DeleteAllResources() error { return err } } - + startTime = time.Now() + for { + s, _ := GetAllSvis() + if len(s) == 0 { + break + } + if time.Since(startTime) > duration { + return errors.New("failed to delete svis") + } + } vrfs, _ := GetAllVrfs() for _, vrf := range vrfs { err := DeleteVrf(vrf.Name) @@ -1232,12 +1260,14 @@ func DeleteAllResources() error { return err } } - - bps, _ := GetAllBPs() - for _, bp := range bps { - err := DeleteBP(bp.Name) - if err != nil { - return err + startTime = time.Now() + for { + v, _ := GetAllVrfs() + if len(v) == 0 { + break + } + if time.Since(startTime) > duration { + return errors.New("failed to delete vrfs") } } lbs, _ := GetAllLBs() @@ -1247,6 +1277,16 @@ func DeleteAllResources() error { return err } } + startTime = time.Now() + for { + l, _ := GetAllLBs() + if len(l) == 0 { + break + } + if time.Since(startTime) > duration { + return errors.New("failed to delete LogicalBridges") + } + } return nil } diff --git a/pkg/netlink/netlink_watcher.go b/pkg/netlink/netlink_watcher.go index a7b5137c..5f25f834 100644 --- a/pkg/netlink/netlink_watcher.go +++ b/pkg/netlink/netlink_watcher.go @@ -834,7 +834,6 @@ 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]) } @@ -1236,7 +1235,6 @@ func cmdProcessNb(nb string, v string) neighList { CPs := strings.Split(nb[2:len(nb)-3], "},{") for i := 0; i < len(CPs); i++ { var ni neighIPStruct - log.Println(CPs[i]) err := json.Unmarshal([]byte(fmt.Sprintf("{%v}", CPs[i])), &ni) if err != nil { log.Println("netlink: error-", err) @@ -1349,7 +1347,6 @@ func readNeighbors(v *infradb.Vrf) { 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())) return true } return false @@ -1360,16 +1357,15 @@ func cmdProcessRt(v *infradb.Vrf, r string, t int) routeList { var RouteData []routeCmdInfo if len(r) <= 3 { log.Println("netlink: Error in the cmd:", r) - var route routeList - return route + return routeList{} } CPs := strings.Split(r[2:len(r)-3], "},{") for i := 0; i < len(CPs); i++ { var ri routeCmdInfo - log.Println(CPs[i]) err := json.Unmarshal([]byte(fmt.Sprintf("{%v}", CPs[i])), &ri) if err != nil { log.Println("error-", err) + return routeList{} } RouteData = append(RouteData, ri) } @@ -1600,7 +1596,6 @@ func lookupRoute(dst net.IP, v *infradb.Vrf) (*RouteStruct, bool) { return &RouteStruct{}, false } r := cmdProcessRt(v, CP, int(*v.Metadata.RoutingTable[0])) - log.Printf("netlink: %+v\n", r) if len(r.RS) != 0 { R1 := r.RS[0] // ### Search the latestRoutes DB snapshot if that exists, else @@ -1717,20 +1712,24 @@ func (nexthop *NexthopStruct) annotate() *NexthopStruct { nexthop.Metadata["vni"] = *nexthop.Vrf.Spec.Vni if nexthop.Neighbor != nil { nexthop.Metadata["inner_dmac"] = nexthop.Neighbor.Neigh0.HardwareAddr.String() - G, _ := infradb.GetVrf("//network.opiproject.org/vrfs/GRD") - r, ok := lookupRoute(nexthop.nexthop.Gw, G) - if ok { - // For now pick the first physical nexthop (no ECMP yet) - phyNh := r.Nexthops[0] - link, _ := vn.LinkByName(NameIndex[phyNh.nexthop.LinkIndex]) - nexthop.Metadata["phy_smac"] = link.Attrs().HardwareAddr.String() - nexthop.Metadata["egress_vport"] = phyPorts[NameIndex[phyNh.nexthop.LinkIndex]] - if phyNh.Neighbor != nil { - nexthop.Metadata["phy_dmac"] = phyNh.Neighbor.Neigh0.HardwareAddr.String() - } else { - // The VXLAN nexthop can only be installed when the phy_nexthops are Resolved. - nexthop.Resolved = false + G, err := infradb.GetVrf("//network.opiproject.org/vrfs/GRD") + if err == nil { + r, ok := lookupRoute(nexthop.nexthop.Gw, G) + if ok { + // For now pick the first physical nexthop (no ECMP yet) + phyNh := r.Nexthops[0] + link, _ := vn.LinkByName(NameIndex[phyNh.nexthop.LinkIndex]) + nexthop.Metadata["phy_smac"] = link.Attrs().HardwareAddr.String() + nexthop.Metadata["egress_vport"] = phyPorts[NameIndex[phyNh.nexthop.LinkIndex]] + if phyNh.Neighbor != nil { + nexthop.Metadata["phy_dmac"] = phyNh.Neighbor.Neigh0.HardwareAddr.String() + } else { + // The VXLAN nexthop can only be installed when the phy_nexthops are Resolved. + nexthop.Resolved = false + } } + } else { + log.Printf("netlink: No GRD found :%v\n", err) } } else { nexthop.Resolved = false @@ -1898,18 +1897,12 @@ func installFilterFDB(fdb *FdbEntryStruct) bool { // ... other than with L2 nexthops of type VXLAN and BridgePort ... // ... and VXLAN entries with unresolved underlay nextop. keep := fdb.VlanID != 0 && fdb.lb != nil && checkFdbType(fdb.Type) && fdb.Nexthop.Resolved - if !keep { - log.Printf("netlink: install_filter: dropping {%v}", fdb) - } return keep } // installFilterL2N install the l2 filter 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) - } return keep } @@ -2038,25 +2031,24 @@ func DeleteLatestDB() { // monitorNetlink moniters the netlink func monitorNetlink() { for !stopMonitoring.Load().(bool) { - log.Printf("netlink: Polling netlink databases.") resyncWithKernel() - log.Printf("netlink: Polling netlink databases completed.") time.Sleep(time.Duration(pollInterval) * time.Second) } log.Printf("netlink: Stopped periodic polling. Waiting for Infra DB cleanup to finish") time.Sleep(2 * time.Second) log.Printf("netlink: One final netlink poll to identify what's still left.") - resyncWithKernel() // Inform subscribers to delete configuration for any still remaining Netlink DB objects. log.Printf("netlink: Delete any residual objects in DB") for _, r := range routes { - notifyAddDel(r, "RouteDeleted") + notifyAddDel(r, RouteDeleted) } + for _, nexthop := range Nexthops { - notifyAddDel(nexthop, "NexthopDeleted") + notifyAddDel(nexthop, NexthopDeleted) } + for _, m := range fDB { - notifyAddDel(m, "fdb_entry_deleted") + notifyAddDel(m, FdbEntryDeleted) } log.Printf("netlink: DB cleanup completed.") } @@ -2075,7 +2067,7 @@ func Initialize() { } getlink() ctx = context.Background() - nlink = utils.NewNetlinkWrapperWithArgs(false) + nlink = utils.NewNetlinkWrapperWithArgs(config.GlobalConfig.Tracer) // stopMonitoring = false stopMonitoring.Store(false) go monitorNetlink() // monitor Thread started diff --git a/pkg/vendor_plugins/intel-e2000/p4runtime/p4driverapi/p4ctl.go b/pkg/vendor_plugins/intel-e2000/p4runtime/p4driverapi/p4ctl.go index d4ee046f..91547008 100644 --- a/pkg/vendor_plugins/intel-e2000/p4runtime/p4driverapi/p4ctl.go +++ b/pkg/vendor_plugins/intel-e2000/p4runtime/p4driverapi/p4ctl.go @@ -24,7 +24,6 @@ import ( p4_v1 "github.com/p4lang/p4runtime/go/p4/v1" "github.com/antoninbas/p4runtime-go-client/pkg/client" - "github.com/antoninbas/p4runtime-go-client/pkg/signals" ) const ( @@ -237,12 +236,18 @@ func AddEntry(entry TableEntry) error { return P4RtC.InsertTableEntry(Ctx, entryP) } -/*// encodeMac encodes the mac from string -func encodeMac(macAddrString string) []byte { - str := strings.Replace(macAddrString, ":", "", -1) - decoded, _ := hex.DecodeString(str) - return decoded -}*/ +/* +// encodeMac encodes the mac from string + + func encodeMac(macAddrString string) []byte { + str := strings.Replace(macAddrString, ":", "", -1) + decoded, _ := hex.DecodeString(str) + return decoded + } +*/ + +// StopCh is used to when to stop the p4rtc when a terminate signal is generated +var StopCh = make(chan struct{}) // NewP4RuntimeClient get the p4 runtime client func NewP4RuntimeClient(binPath string, p4infoPath string, conn *grpc.ClientConn) error { @@ -255,8 +260,6 @@ func NewP4RuntimeClient(binPath string, p4infoPath string, conn *grpc.ClientConn } logr.Infof("intel-e2000: P4Runtime server version is %s", resp.P4RuntimeApiVersion) - stopCh := signals.RegisterSignalHandlers() - electionID := &p4_v1.Uint128{High: 0, Low: 1} P4RtC = client.NewClient(c, defaultDeviceID, electionID) @@ -264,7 +267,7 @@ func NewP4RuntimeClient(binPath string, p4infoPath string, conn *grpc.ClientConn errs := make(chan error, 1) go func() { - errs <- P4RtC.Run(stopCh, arbitrationCh, nil) + errs <- P4RtC.Run(StopCh, arbitrationCh, nil) }() waitCh := make(chan struct{}) diff --git a/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/p4trans.go b/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/p4trans.go index 3faa5751..0a9c222f 100644 --- a/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/p4trans.go +++ b/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation/p4trans.go @@ -114,7 +114,7 @@ func startSubscriber(eventBus *eb.EventBus, eventType string) { for { select { case event := <-subscriber.Ch: - log.Printf("intel-e2000: Subscriber for %s received event: %s\n", eventType, event) + log.Printf("intel-e2000: Subscriber for %s received event\n", eventType) switch eventType { case "route_added": handleRouteAdded(event) @@ -152,15 +152,17 @@ func startSubscriber(eventBus *eb.EventBus, eventType string) { func handleRouteAdded(route interface{}) { var entries []interface{} routeData, _ := route.(*nm.RouteStruct) - entries = L3.translateAddedRoute(*routeData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + if routeData != nil { + entries = L3.translateAddedRoute(*routeData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Printf("intel-e2000: Entry is not of type p4client.TableEntry:- %v\n", e) } - } else { - log.Printf("intel-e2000: Entry is not of type p4client.TableEntry:- %v\n", e) } } } @@ -169,26 +171,28 @@ func handleRouteAdded(route interface{}) { func handleRouteUpdated(route interface{}) { var entries []interface{} routeData, _ := route.(*nm.RouteStruct) - entries = L3.translateDeletedRoute(*routeData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - err := p4client.DelEntry(e) - if err != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, err) + if routeData != nil { + entries = L3.translateDeletedRoute(*routeData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + err := p4client.DelEntry(e) + if err != nil { + log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, err) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = L3.translateAddedRoute(*routeData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + entries = L3.translateAddedRoute(*routeData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } } @@ -197,15 +201,17 @@ func handleRouteUpdated(route interface{}) { func handleRouteDeleted(route interface{}) { var entries []interface{} routeData, _ := route.(*nm.RouteStruct) - entries = L3.translateDeletedRoute(*routeData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + if routeData != nil { + entries = L3.translateDeletedRoute(*routeData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } } @@ -214,76 +220,82 @@ func handleRouteDeleted(route interface{}) { func handleNexthopAdded(nexthop interface{}) { var entries []interface{} nexthopData, _ := nexthop.(*nm.NexthopStruct) - entries = L3.translateAddedNexthop(*nexthopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + if nexthopData != nil { + entries = L3.translateAddedNexthop(*nexthopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Vxlan.translateAddedNexthop(*nexthopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + entries = Vxlan.translateAddedNexthop(*nexthopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } } // handleNexthopUpdated handles the updated nexthop +// +//gocognit:ignore func handleNexthopUpdated(nexthop interface{}) { var entries []interface{} nexthopData, _ := nexthop.(*nm.NexthopStruct) - entries = L3.translateDeletedNexthop(*nexthopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + if nexthopData != nil { + entries = L3.translateDeletedNexthop(*nexthopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Vxlan.translateDeletedNexthop(*nexthopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + entries = Vxlan.translateDeletedNexthop(*nexthopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = L3.translateAddedNexthop(*nexthopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + entries = L3.translateAddedNexthop(*nexthopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Vxlan.translateAddedNexthop(*nexthopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + entries = Vxlan.translateAddedNexthop(*nexthopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } } @@ -292,26 +304,28 @@ func handleNexthopUpdated(nexthop interface{}) { func handleNexthopDeleted(nexthop interface{}) { var entries []interface{} nexthopData, _ := nexthop.(*nm.NexthopStruct) - entries = L3.translateDeletedNexthop(*nexthopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + if nexthopData != nil { + entries = L3.translateDeletedNexthop(*nexthopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Vxlan.translateDeletedNexthop(*nexthopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + entries = Vxlan.translateDeletedNexthop(*nexthopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } } @@ -320,77 +334,83 @@ func handleNexthopDeleted(nexthop interface{}) { func handleFbdEntryAdded(fbdEntry interface{}) { var entries []interface{} fbdEntryData, _ := fbdEntry.(*nm.FdbEntryStruct) - entries = Vxlan.translateAddedFdb(*fbdEntryData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + if fbdEntryData != nil { + entries = Vxlan.translateAddedFdb(*fbdEntryData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Pod.translateAddedFdb(*fbdEntryData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + entries = Pod.translateAddedFdb(*fbdEntryData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } } // handleFbdEntryUpdated handles the updated fdb entry +// +//gocognit:ignore func handleFbdEntryUpdated(fdbEntry interface{}) { var entries []interface{} fbdEntryData, _ := fdbEntry.(*nm.FdbEntryStruct) - entries = Vxlan.translateDeletedFdb(*fbdEntryData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + if fbdEntryData != nil { + entries = Vxlan.translateDeletedFdb(*fbdEntryData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Pod.translateDeletedFdb(*fbdEntryData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + entries = Pod.translateDeletedFdb(*fbdEntryData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Vxlan.translateAddedFdb(*fbdEntryData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + entries = Vxlan.translateAddedFdb(*fbdEntryData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Pod.translateAddedFdb(*fbdEntryData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + entries = Pod.translateAddedFdb(*fbdEntryData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } } @@ -399,26 +419,28 @@ func handleFbdEntryUpdated(fdbEntry interface{}) { func handleFbdEntryDeleted(fdbEntry interface{}) { var entries []interface{} fbdEntryData, _ := fdbEntry.(*nm.FdbEntryStruct) - entries = Vxlan.translateDeletedFdb(*fbdEntryData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + if fbdEntryData != nil { + entries = Vxlan.translateDeletedFdb(*fbdEntryData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Pod.translateDeletedFdb(*fbdEntryData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + entries = Pod.translateDeletedFdb(*fbdEntryData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } } @@ -427,77 +449,82 @@ func handleFbdEntryDeleted(fdbEntry interface{}) { func handleL2NexthopAdded(l2NextHop interface{}) { var entries []interface{} l2NextHopData, _ := l2NextHop.(*nm.L2NexthopStruct) - - entries = Vxlan.translateAddedL2Nexthop(*l2NextHopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + if l2NextHopData != nil { + entries = Vxlan.translateAddedL2Nexthop(*l2NextHopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Pod.translateAddedL2Nexthop(*l2NextHopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + entries = Pod.translateAddedL2Nexthop(*l2NextHopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } } // handleL2NexthopUpdated handles the updated l2 nexthop +// +//gocognit:ignore func handleL2NexthopUpdated(l2NextHop interface{}) { var entries []interface{} l2NextHopData, _ := l2NextHop.(*nm.L2NexthopStruct) - entries = Vxlan.translateDeletedL2Nexthop(*l2NextHopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + if l2NextHopData != nil { + entries = Vxlan.translateDeletedL2Nexthop(*l2NextHopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Pod.translateDeletedL2Nexthop(*l2NextHopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + entries = Pod.translateDeletedL2Nexthop(*l2NextHopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Vxlan.translateAddedL2Nexthop(*l2NextHopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + entries = Vxlan.translateAddedL2Nexthop(*l2NextHopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Pod.translateAddedL2Nexthop(*l2NextHopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.AddEntry(e) - if er != nil { - log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + entries = Pod.translateAddedL2Nexthop(*l2NextHopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.AddEntry(e) + if er != nil { + log.Printf("intel-e2000: error adding entry for %v error %v\n", e.Tablename, er) + } + } else { + log.Println("iintel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("iintel-e2000: Entry is not of type p4client.TableEntry") } } } @@ -506,26 +533,28 @@ func handleL2NexthopUpdated(l2NextHop interface{}) { func handleL2NexthopDeleted(l2NextHop interface{}) { var entries []interface{} l2NextHopData, _ := l2NextHop.(*nm.L2NexthopStruct) - entries = Vxlan.translateDeletedL2Nexthop(*l2NextHopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - err := p4client.DelEntry(e) - if err != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, err) + if l2NextHopData != nil { + entries = Vxlan.translateDeletedL2Nexthop(*l2NextHopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + err := p4client.DelEntry(e) + if err != nil { + log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, err) + } + } else { + log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } - } - entries = Pod.translateDeletedL2Nexthop(*l2NextHopData) - for _, entry := range entries { - if e, ok := entry.(p4client.TableEntry); ok { - er := p4client.DelEntry(e) - if er != nil { - log.Printf("intel-e2000: error deleting entry for %v error %v\n", e.Tablename, er) + entries = Pod.translateDeletedL2Nexthop(*l2NextHopData) + for _, entry := range entries { + if e, ok := entry.(p4client.TableEntry); ok { + er := p4client.DelEntry(e) + if er != nil { + 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") } - } else { - log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } } @@ -1109,9 +1138,6 @@ func Initialize() { // DeInitialize function handles stops functionality func DeInitialize() { - // unsubscriber all the events - nm.EventBus.Unsubscribe() - L3entries := L3.StaticDeletions() for _, entry := range L3entries { if e, ok := entry.(p4client.TableEntry); ok { @@ -1134,4 +1160,7 @@ func DeInitialize() { log.Println("intel-e2000: Entry is not of type p4client.TableEntry") } } + + // unsubscriber all the events + nm.EventBus.Unsubscribe() }