diff --git a/cmd/main.go b/cmd/main.go index fc66ef48..f9b6973a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -14,12 +14,11 @@ import ( "net" "net/http" "os" + "os/signal" "path/filepath" + "syscall" "time" - "github.com/spf13/cobra" - "github.com/spf13/viper" - pc "github.com/opiproject/opi-api/inventory/v1/gen/go" pe "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go" "github.com/opiproject/opi-evpn-bridge/pkg/bridge" @@ -31,6 +30,8 @@ import ( "github.com/opiproject/opi-evpn-bridge/pkg/utils" "github.com/opiproject/opi-evpn-bridge/pkg/vrf" "github.com/opiproject/opi-smbios-bridge/pkg/inventory" + "github.com/spf13/cobra" + "github.com/spf13/viper" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" @@ -40,7 +41,6 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" ci_linux "github.com/opiproject/opi-evpn-bridge/pkg/LinuxCIModule" gen_linux "github.com/opiproject/opi-evpn-bridge/pkg/LinuxGeneralModule" - intel_e2000_linux "github.com/opiproject/opi-evpn-bridge/pkg/LinuxVendorModule/intele2000" frr "github.com/opiproject/opi-evpn-bridge/pkg/frr" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" ) @@ -61,14 +61,10 @@ var rootCmd = &cobra.Command{ go runGatewayServer(config.GlobalConfig.GRPCPort, config.GlobalConfig.HTTPPort) switch config.GlobalConfig.Buildenv { - case "intel_e2000": - gen_linux.Init() - intel_e2000_linux.Init() - frr.Init() case "ci": - gen_linux.Init() - ci_linux.Init() - frr.Init() + gen_linux.Initialize() + ci_linux.Initialize() + frr.Initialize() default: log.Panic(" ERROR: Could not find Build env ") } @@ -77,8 +73,8 @@ var rootCmd = &cobra.Command{ if err := createGrdVrf(); err != nil { log.Panicf("Error: %v", err) } - runGrpcServer(config.GlobalConfig.GRPCPort, config.GlobalConfig.TLSFiles) + }, } @@ -118,6 +114,25 @@ func setupLogger(filename string) { log.SetOutput(logger.Writer()) } +func cleanUp() { + log.Println("Defer function called") + if err := infradb.DeleteAllResources(); err != nil { + log.Println("Failed to delete all the resources: ", err) + } + switch config.GlobalConfig.Buildenv { + case "ci": + gen_linux.DeInitialize() + ci_linux.DeInitialize() + frr.DeInitialize() + default: + log.Panic(" ERROR: Could not find Build env ") + } + + if err := infradb.Close(); err != nil { + log.Println("Failed to close infradb") + } +} + // main function func main() { // setup file and console logger @@ -129,26 +144,48 @@ func main() { log.Panicf("Error in initialize(): %v", err) } + sigChan := make(chan os.Signal, 1) + // Notify sigChan on SIGINT or SIGTERM. + signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) + + // This goroutine executes a blocking receive for signals. + // When it gets one it will then exit the program. + go func() { + sig := <-sigChan + switch sig { + case syscall.SIGINT: + cleanUp() + fmt.Println("Received SIGINT, shutting down.") + case syscall.SIGTERM: + cleanUp() + fmt.Println("Received SIGTERM, shutting down.") + default: + fmt.Println("Received unknown signal.") + } + // Perform any cleanup tasks here. + // ... + + // Exit the program. + os.Exit(0) + }() + // start the main cmd if err := rootCmd.Execute(); err != nil { log.Panicf("Error in Execute(): %v", err) } - - defer func() { - if err := infradb.Close(); err != nil { - log.Panicf("Error in close(): %v", err) - } - }() + defer cleanUp() } // 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 { diff --git a/config-intel-e2000.yaml b/config-intel-e2000.yaml deleted file mode 100644 index ef677360..00000000 --- a/config-intel-e2000.yaml +++ /dev/null @@ -1,32 +0,0 @@ -grpcport: 50151 -httpport: 8082 -tlsfiles: -database: redis -dbaddress: 127.0.0.1:6379 -buildenv: intel_e2000 -tracer: false -subscribers: - - name: "lvm" - priority: 2 - events: ["vrf", "bridge-port"] - - name: "lgm" - priority: 1 - events: ["vrf", "svi", "logical-bridge"] - - name: "frr" - priority: 3 - events: ["vrf", "svi"] - - name: "intel_e2000" - priority: 4 - events: ["vrf"] -grpc: - server_addresses: - - 0.0.0.0 - server_port: 51703 - num_threads: 10 - static_external_macs: [] -linuxfrr: - enabled: true - defaultvtep: "vxlan-vtep" - portmux: "enp0s1f0d5" - vrfmux: "enp0s1f0d4" - ipmtu: 2962 diff --git a/config.yaml b/config.yaml index 937d5b68..bea7a5cc 100644 --- a/config.yaml +++ b/config.yaml @@ -25,3 +25,4 @@ linuxfrr: enabled: true defaultvtep: "vxlan-vtep" ipmtu: 1500 + localas: 65000 diff --git a/go.sum b/go.sum index 86d99c9a..52ddca77 100644 --- a/go.sum +++ b/go.sum @@ -79,13 +79,11 @@ github.com/alexkohler/prealloc v1.0.0 h1:Hbq0/3fJPQhNkN0dR95AVrr6R7tou91y0uHG5pO github.com/alexkohler/prealloc v1.0.0/go.mod h1:VetnK3dIgFBBKmg0YnD9F9x6Icjd+9cvfHR56wJVlKE= github.com/alingse/asasalint v0.0.11 h1:SFwnQXJ49Kx/1GghOFz1XGqHYKp21Kq1nHad/0WQRnw= github.com/alingse/asasalint v0.0.11/go.mod h1:nCaoMhw7a9kSJObvQyVzNTPBDbNpdocqrSP7t/cW5+I= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/ashanbrown/forbidigo v1.6.0 h1:D3aewfM37Yb3pxHujIPSpTf6oQk9sc9WZi8gerOIVIY= github.com/ashanbrown/forbidigo v1.6.0/go.mod h1:Y8j9jy9ZYAEHXdu723cUlraTqbzjKF1MUyfOKL+AjcU= github.com/ashanbrown/makezero v1.1.1 h1:iCQ87C0V0vSyO+M9E/FZYbu65auqH0lnsOkf5FcB28s= github.com/ashanbrown/makezero v1.1.1/go.mod h1:i1bJLCRSCHOcOa9Y6MyF2FTfMZMFdHvxKHxgO5Z1axI= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= -github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -521,7 +519,6 @@ github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 h1:TCg2WBOl github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727/go.mod h1:rlzQ04UMyJXu/aOvhd8qT+hvDrFpiwqp8MRXDY9szc0= github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 h1:M8mH9eK4OUR4lu7Gd+PU1fV2/qnDNfzT635KRSObncs= github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567/go.mod h1:DWNGW8A4Y+GyBgPuaQJuWiy0XYftx4Xm/y5Jqk9I6VQ= -github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= @@ -658,22 +655,16 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0= -go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= -go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 h1:tIqheXEFWAZ7O8A7m+J0aPTmpJN3YQ7qetUAdkkkKpk= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0/go.mod h1:nUeKExfxAQVbiVFn32YXpXZZHZ61Cc3s3Rn1pDBGAb0= -go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= -go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= -go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= -go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= @@ -788,8 +779,6 @@ golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -881,8 +870,6 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -891,8 +878,7 @@ golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= -golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= +golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1068,8 +1054,6 @@ google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU= -google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0= google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= diff --git a/pkg/LinuxCIModule/lci.go b/pkg/LinuxCIModule/lci.go index f52eadb7..f73f964d 100644 --- a/pkg/LinuxCIModule/lci.go +++ b/pkg/LinuxCIModule/lci.go @@ -39,11 +39,24 @@ func (h *ModulelciHandler) HandleEvent(eventType string, objectData *eventbus.Ob } // handlebp handle the bridge port functionality +// +//gocognit:ignore func handlebp(objectData *eventbus.ObjectData) { var comp common.Component BP, err := infradb.GetBP(objectData.Name) if err != nil { log.Printf("LCI : GetBP error: %s\n", err) + comp.Name = lciComp + comp.CompStatus = common.ComponentStatusError + if comp.Timer == 0 { + comp.Timer = 2 * time.Second + } else { + comp.Timer *= 2 + } + err := infradb.UpdateBPStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) + if err != nil { + log.Printf("error in updating bp status: %s\n", err) + } return } if objectData.ResourceVersion != BP.ResourceVersion { @@ -202,8 +215,8 @@ func tearDownBp(bp *infradb.BridgePort) bool { var ctx context.Context var nlink utils.Netlink -// Init initializes the config and subscribers -func Init() { +// Initialize initializes the config and subscribers +func Initialize() { eb := eventbus.EBus for _, subscriberConfig := range config.GlobalConfig.Subscribers { if subscriberConfig.Name == "lci" { @@ -213,5 +226,12 @@ func Init() { } } ctx = context.Background() - nlink = utils.NewNetlinkWrapper() + nlink = utils.NewNetlinkWrapperWithArgs(config.GlobalConfig.Tracer) +} + +// DeInitialize function handles stops functionality +func DeInitialize() { + // Unsubscribe to InfraDB notifications + eb := eventbus.EBus + eb.UnsubscribeModule("lci") } diff --git a/pkg/LinuxGeneralModule/lgm.go b/pkg/LinuxGeneralModule/lgm.go index 8c0c19e5..5140bd05 100644 --- a/pkg/LinuxGeneralModule/lgm.go +++ b/pkg/LinuxGeneralModule/lgm.go @@ -15,7 +15,6 @@ import ( "os/exec" "reflect" "strconv" - "strings" "time" "github.com/opiproject/opi-evpn-bridge/pkg/config" @@ -86,11 +85,24 @@ func (h *ModulelgmHandler) HandleEvent(eventType string, objectData *eventbus.Ob } // handleLB handles the logical Bridge +// +//gocognit:ignore func handleLB(objectData *eventbus.ObjectData) { var comp common.Component lb, err := infradb.GetLB(objectData.Name) if err != nil { log.Printf("LGM: GetLB error: %s %s\n", err, objectData.Name) + comp.Name = lgmComp + comp.CompStatus = common.ComponentStatusError + if comp.Timer == 0 { + comp.Timer = 2 * time.Second + } else { + comp.Timer *= 2 + } + err := infradb.UpdateLBStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) + if err != nil { + log.Printf("error in updating lb status: %s\n", err) + } return } if objectData.ResourceVersion != lb.ResourceVersion { @@ -158,11 +170,24 @@ func handleLB(objectData *eventbus.ObjectData) { } // handlesvi handles the svi functionality +// +//gocognit:ignore func handlesvi(objectData *eventbus.ObjectData) { var comp common.Component svi, err := infradb.GetSvi(objectData.Name) if err != nil { log.Printf("LGM: GetSvi error: %s %s\n", err, objectData.Name) + comp.Name = lgmComp + 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 } if objectData.ResourceVersion != svi.ResourceVersion { @@ -229,11 +254,24 @@ func handlesvi(objectData *eventbus.ObjectData) { } // handlevrf handles the vrf functionality +// +//gocognit:ignore func handlevrf(objectData *eventbus.ObjectData) { var comp common.Component vrf, err := infradb.GetVrf(objectData.Name) if err != nil { log.Printf("LGM: GetVRF error: %s %s\n", err, objectData.Name) + comp.Name = lgmComp + 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 } if objectData.ResourceVersion != vrf.ResourceVersion { @@ -300,9 +338,6 @@ func handlevrf(objectData *eventbus.ObjectData) { } } -// defaultVtep variable string -var defaultVtep string - // ipMtu variable int var ipMtu int @@ -315,8 +350,8 @@ var ctx context.Context // nlink variable wrapper var nlink utils.Netlink -// Init initializes the config, logger and subscribers -func Init() { +// Initialize initializes the config, logger and subscribers +func Initialize() { eb := eventbus.EBus for _, subscriberConfig := range config.GlobalConfig.Subscribers { if subscriberConfig.Name == lgmComp { @@ -326,10 +361,9 @@ func Init() { } } brTenant = "br-tenant" - defaultVtep = config.GlobalConfig.LinuxFrr.DefaultVtep ipMtu = config.GlobalConfig.LinuxFrr.IPMtu ctx = context.Background() - nlink = utils.NewNetlinkWrapper() + nlink = utils.NewNetlinkWrapperWithArgs(config.GlobalConfig.Tracer) // Set up the static configuration parts _, err := nlink.LinkByName(ctx, brTenant) if err != nil { @@ -337,6 +371,15 @@ func Init() { } } +// DeInitialize function handles stops functionality +func DeInitialize() { + eb := eventbus.EBus + err := TearDownTenantBridge() + if err != nil { + log.Printf("LGM: Failed to tear down br-tenant: %v\n", err) + } + eb.UnsubscribeModule("lgm") +} func setUpTenantBridge() { brTenantMtu := ipMtu + 20 vlanfiltering := true @@ -376,10 +419,6 @@ func setUpBridge(lb *infradb.LogicalBridge) bool { log.Printf("LGM: Failed to get link information for %s: %v\n", brTenant, err) return false } - if reflect.ValueOf(lb.Spec.VtepIP).IsZero() { - tmpVtepIP := getIPAddress(defaultVtep) - lb.Spec.VtepIP = &tmpVtepIP - } vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: link, MTU: ipMtu}, VxlanId: int(*lb.Spec.Vni), Port: 4789, Learning: false, SrcAddr: lb.Spec.VtepIP.IP} if err := nlink.LinkAdd(ctx, vxlan); err != nil { log.Printf("LGM: Failed to create Vxlan linki %s: %v\n", link, err) @@ -415,10 +454,7 @@ func setUpBridge(lb *infradb.LogicalBridge) bool { //nolint:funlen,gocognit func setUpVrf(vrf *infradb.Vrf) (string, bool) { IPMtu := fmt.Sprintf("%+v", ipMtu) - Ifname := strings.Split(vrf.Name, "/") - ifwlen := len(Ifname) - vrf.Name = Ifname[ifwlen-1] - if vrf.Name == "GRD" { + if path.Base(vrf.Name) == "GRD" { vrf.Metadata.RoutingTable = make([]*uint32, 2) vrf.Metadata.RoutingTable[0] = new(uint32) vrf.Metadata.RoutingTable[1] = new(uint32) @@ -452,18 +488,12 @@ func setUpVrf(vrf *infradb.Vrf) (string, bool) { log.Printf(" LGM: VTEP IP not found: %+v\n", vrf.Spec.VtepIP) return "", false } - } else { - // Pick the IP of interface default VTEP interface - // log.Printf("LGM: VTEP iP %+v\n",getIPAddress(defaultVtep)) - tmpVtepIP := getIPAddress(defaultVtep) - vrf.Spec.VtepIP = &tmpVtepIP - vtip = fmt.Sprintf("%+v", vrf.Spec.VtepIP.IP) } log.Printf("setUpVrf: %s %d\n", vtip, routingTable) // Create the vrf interface for the specified routing table and add loopback address linkAdderr := nlink.LinkAdd(ctx, &netlink.Vrf{ - LinkAttrs: netlink.LinkAttrs{Name: vrf.Name}, + LinkAttrs: netlink.LinkAttrs{Name: path.Base(vrf.Name)}, Table: routingTable, }) if linkAdderr != nil { @@ -473,7 +503,7 @@ func setUpVrf(vrf *infradb.Vrf) (string, bool) { log.Printf("LGM: vrf link %s Added with table id %d\n", vrf.Name, routingTable) - link, linkErr := nlink.LinkByName(ctx, vrf.Name) + link, linkErr := nlink.LinkByName(ctx, path.Base(vrf.Name)) if linkErr != nil { log.Printf("LGM : Link %s not found\n", vrf.Name) return "", false @@ -526,10 +556,10 @@ func setUpVrf(vrf *infradb.Vrf) (string, bool) { // Create bridge for external VXLAN under vrf // Linux apparently creates a deterministic MAC address for a bridge type link with a given // name. We need to assign a true random MAC address to avoid collisions when pairing two - // intel e2000 servers. + // servers. brErr := nlink.LinkAdd(ctx, &netlink.Bridge{ - LinkAttrs: netlink.LinkAttrs{Name: brStr + vrf.Name}, + LinkAttrs: netlink.LinkAttrs{Name: brStr + path.Base(vrf.Name)}, }) if brErr != nil { log.Printf("LGM : Error in added bridge port\n") @@ -540,7 +570,7 @@ func setUpVrf(vrf *infradb.Vrf) (string, bool) { rmac := fmt.Sprintf("%+v", GenerateMac()) // str(macaddress.MAC(b'\x00'+random.randbytes(5))).replace("-", ":") hw, _ := net.ParseMAC(rmac) - linkBr, brErr := nlink.LinkByName(ctx, brStr+vrf.Name) + linkBr, brErr := nlink.LinkByName(ctx, brStr+path.Base(vrf.Name)) if brErr != nil { log.Printf("LGM : Error in getting the br-%s\n", vrf.Name) return "", false @@ -557,7 +587,7 @@ func setUpVrf(vrf *infradb.Vrf) (string, bool) { return "", false } - linkMaster, errMaster := nlink.LinkByName(ctx, vrf.Name) + linkMaster, errMaster := nlink.LinkByName(ctx, path.Base(vrf.Name)) if errMaster != nil { log.Printf("LGM : Error in getting the %s\n", vrf.Name) return "", false @@ -580,7 +610,7 @@ func setUpVrf(vrf *infradb.Vrf) (string, bool) { SrcVtep := vrf.Spec.VtepIP.IP vxlanErr := nlink.LinkAdd(ctx, &netlink.Vxlan{ - LinkAttrs: netlink.LinkAttrs{Name: vxlanStr + vrf.Name, MTU: ipMtu}, VxlanId: int(*vrf.Spec.Vni), SrcAddr: SrcVtep, Learning: false, Proxy: true, Port: 4789}) + LinkAttrs: netlink.LinkAttrs{Name: vxlanStr + path.Base(vrf.Name), MTU: ipMtu}, VxlanId: int(*vrf.Spec.Vni), SrcAddr: SrcVtep, Learning: false, Proxy: true, Port: 4789}) if vxlanErr != nil { log.Printf("LGM : Error in added vxlan port\n") return "", false @@ -588,7 +618,7 @@ func setUpVrf(vrf *infradb.Vrf) (string, bool) { log.Printf("LGM : link added vxlan-%s type vxlan id %d local %s dstport 4789 nolearning proxy\n", vrf.Name, *vrf.Spec.Vni, vtip) - linkVxlan, vxlanErr := nlink.LinkByName(ctx, vxlanStr+vrf.Name) + linkVxlan, vxlanErr := nlink.LinkByName(ctx, vxlanStr+path.Base(vrf.Name)) if vxlanErr != nil { log.Printf("LGM : Error in getting the %s\n", vxlanStr+vrf.Name) return "", false @@ -734,54 +764,21 @@ func NetMaskToInt(mask int) (netmaskint [4]int64) { return netmaskint } -// getIPAddress gets the ip address from link -func getIPAddress(dev string) net.IPNet { - link, err := nlink.LinkByName(ctx, dev) - if err != nil { - log.Printf("LGM: Error in LinkByName %+v\n", err) - return net.IPNet{ - IP: net.ParseIP("0.0.0.0"), - } - } - - addrs, err := nlink.AddrList(ctx, link, netlink.FAMILY_V4) // ip address show - if err != nil { - log.Printf("LGM: Error in AddrList\n") - return net.IPNet{ - IP: net.ParseIP("0.0.0.0"), - } - } - var address = &net.IPNet{ - IP: net.IPv4(127, 0, 0, 0), - Mask: net.CIDRMask(8, 32)} - var addr = &netlink.Addr{IPNet: address} - var validIps []netlink.Addr - for index := 0; index < len(addrs); index++ { - if !addr.Equal(addrs[index]) { - validIps = append(validIps, addrs[index]) - } - } - return *validIps[0].IPNet -} - // tearDownVrf tears down the vrf func tearDownVrf(vrf *infradb.Vrf) bool { - Ifname := strings.Split(vrf.Name, "/") - ifwlen := len(Ifname) - vrf.Name = Ifname[ifwlen-1] - link, err1 := nlink.LinkByName(ctx, vrf.Name) + link, err1 := nlink.LinkByName(ctx, path.Base(vrf.Name)) if err1 != nil { log.Printf("LGM : Link %s not found %+v\n", vrf.Name, err1) return true } - if vrf.Name == "GRD" { + if path.Base(vrf.Name) == "GRD" { return true } routingTable := *vrf.Metadata.RoutingTable[0] // Delete the Linux networking artefacts in reverse order if !reflect.ValueOf(vrf.Spec.Vni).IsZero() { - linkVxlan, linkErr := nlink.LinkByName(ctx, vxlanStr+vrf.Name) + linkVxlan, linkErr := nlink.LinkByName(ctx, vxlanStr+path.Base(vrf.Name)) if linkErr != nil { log.Printf("LGM : Link vxlan-%s not found %+v\n", vrf.Name, linkErr) return false @@ -793,7 +790,7 @@ func tearDownVrf(vrf *infradb.Vrf) bool { } log.Printf("LGM : Delete vxlan-%s\n", vrf.Name) - linkBr, linkbrErr := nlink.LinkByName(ctx, brStr+vrf.Name) + linkBr, linkbrErr := nlink.LinkByName(ctx, brStr+path.Base(vrf.Name)) if linkbrErr != nil { log.Printf("LGM : Link br-%s not found %+v\n", vrf.Name, linkbrErr) return false @@ -878,3 +875,19 @@ func tearDownBridge(lb *infradb.LogicalBridge) bool { } return true } + +// TearDownTenantBridge tears down the bridge +func TearDownTenantBridge() error { + Intf, err := nlink.LinkByName(ctx, brTenant) + if err != nil { + log.Printf("LGM: Failed to get br-tenant %s: %v\n", Intf, err) + return err + } + if err = nlink.LinkDel(ctx, Intf); err != nil { + log.Printf("LGM : Failed to delete br-tenant %s: %v\n", Intf, err) + return err + } + log.Printf("LGM: Executed ip link delete %s", brTenant) + + return nil +} diff --git a/pkg/LinuxVendorModule/intele2000/intelE2000.go b/pkg/LinuxVendorModule/intele2000/intelE2000.go deleted file mode 100644 index a1119e67..00000000 --- a/pkg/LinuxVendorModule/intele2000/intelE2000.go +++ /dev/null @@ -1,399 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries. -// Copyright (C) 2023 Nordix Foundation. - -// Package intele2000 handles intel e2000 vendor specific tasks -package intele2000 - -import ( - "context" - "fmt" - - "log" - "math" - "net" - "os/exec" - "path" - "strconv" - "strings" - "time" - - "github.com/opiproject/opi-evpn-bridge/pkg/config" - "github.com/opiproject/opi-evpn-bridge/pkg/infradb" - "github.com/opiproject/opi-evpn-bridge/pkg/infradb/common" - "github.com/opiproject/opi-evpn-bridge/pkg/infradb/subscriberframework/eventbus" - "github.com/opiproject/opi-evpn-bridge/pkg/utils" - "github.com/vishvananda/netlink" -) - -// portMux variable of type string -var portMux string - -// vrfMux variable of type string -var vrfMux string - -// ModulelvmHandler empty interface -type ModulelvmHandler struct{} - -// lvmComp empty interface -const lvmComp string = "lvm" - -// run runs the command -func run(cmd []string, flag bool) (string, int) { - var out []byte - var err error - out, err = exec.Command(cmd[0], cmd[1:]...).CombinedOutput() //nolint:gosec - if err != nil { - if flag { - panic(fmt.Sprintf("LVM: Command %s': exit code %s;", out, err.Error())) - } - log.Printf("LVM: Command %s': exit code %s;\n", out, err) - return "Error", -1 - } - output := string(out) - return output, 0 -} - -// HandleEvent handles the events -func (h *ModulelvmHandler) HandleEvent(eventType string, objectData *eventbus.ObjectData) { - switch eventType { - case "vrf": - log.Printf("LVM recevied %s %s\n", eventType, objectData.Name) - handlevrf(objectData) - case "bridge-port": - log.Printf("LVM recevied %s %s\n", eventType, objectData.Name) - handlebp(objectData) - default: - log.Printf("error: Unknown event type %s\n", eventType) - } -} - -// handlebp handles the bridge port functionality -func handlebp(objectData *eventbus.ObjectData) { - var comp common.Component - bp, err := infradb.GetBP(objectData.Name) - if err != nil { - log.Printf("LVM : GetBP error: %s\n", err) - return - } - if objectData.ResourceVersion != bp.ResourceVersion { - log.Printf("LVM: Mismatch in resoruce version %+v\n and bp resource version %+v\n", objectData.ResourceVersion, bp.ResourceVersion) - comp.Name = lvmComp - comp.CompStatus = common.ComponentStatusError - if comp.Timer == 0 { - comp.Timer = 2 * time.Second - } else { - comp.Timer *= 2 - } - err := infradb.UpdateBPStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) - if err != nil { - log.Printf("error in updating bp status: %s\n", err) - } - return - } - if len(bp.Status.Components) != 0 { - for i := 0; i < len(bp.Status.Components); i++ { - if bp.Status.Components[i].Name == lvmComp { - comp = bp.Status.Components[i] - } - } - } - if bp.Status.BPOperStatus != infradb.BridgePortOperStatusToBeDeleted { - status := setUpBp(bp) - comp.Name = lvmComp - if status { - comp.Details = "" - comp.CompStatus = common.ComponentStatusSuccess - comp.Timer = 0 - } else { - if comp.Timer == 0 { - comp.Timer = 2 * time.Second - } else { - comp.Timer *= 2 - } - comp.CompStatus = common.ComponentStatusError - } - log.Printf("LVM: %+v \n", comp) - err := infradb.UpdateBPStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, bp.Metadata, comp) - if err != nil { - log.Printf("error updaing bp status %s\n", err) - } - } else { - status := tearDownBp(bp) - comp.Name = lvmComp - if status { - comp.CompStatus = common.ComponentStatusSuccess - comp.Timer = 0 - } else { - if comp.Timer == 0 { - comp.Timer = 2 * time.Second - } else { - comp.Timer *= 2 - } - comp.CompStatus = common.ComponentStatusError - } - log.Printf("LVM: %+v \n", comp) - err := infradb.UpdateBPStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) - if err != nil { - log.Printf("error updaing bp status %s\n", err) - } - } -} - -// MactoVport converts mac address to vport -func MactoVport(mac *net.HardwareAddr) int { - byte0 := int((*mac)[0]) - byte1 := int((*mac)[1]) - return (byte0 << 8) + byte1 -} - -// setUpBp sets up a bridge port -func setUpBp(bp *infradb.BridgePort) bool { - MacAddress := fmt.Sprintf("%+v", *bp.Spec.MacAddress) - vportID := MactoVport(bp.Spec.MacAddress) - link := fmt.Sprintf("vport-%+v", vportID) - vport := fmt.Sprintf("%+v", vportID) - bp.Metadata.VPort = vport - muxIntf, err := nlink.LinkByName(ctx, portMux) - if err != nil { - log.Printf("Failed to get link information for %s, error is %v\n", portMux, err) - return false - } - vlanLink := &netlink.Vlan{LinkAttrs: netlink.LinkAttrs{Name: link, ParentIndex: muxIntf.Attrs().Index}, VlanId: vportID, VlanProtocol: netlink.VLAN_PROTOCOL_8021AD} - if err = nlink.LinkAdd(ctx, vlanLink); err != nil { - log.Printf("Failed to add VLAN sub-interface %s: %v\n", link, err) - return false - } - log.Printf("LVM: Executed ip link add link %s name %s type vlan protocol 802.1ad id %s\n", portMux, link, vport) - brIntf, err := nlink.LinkByName(ctx, brTenant) - if err != nil { - log.Printf("Failed to get link information for %s: %v\n", brTenant, err) - return false - } - if err = nlink.LinkSetMaster(ctx, vlanLink, brIntf); err != nil { - log.Printf("Failed to set master for %s: %v\n", brIntf, err) - return false - } - if err = nlink.LinkSetUp(ctx, vlanLink); err != nil { - log.Printf("Failed to set up link for %v: %s\n", vlanLink, err) - return false - } - if err = nlink.LinkSetMTU(ctx, vlanLink, ipMtu); err != nil { - log.Printf("Failed to set MTU for %v: %s\n", vlanLink, err) - return false - } - log.Printf("LVM: Executed ip link set %s master %s up mtu %d \n", link, brTenant, ipMtu) - for _, vlan := range bp.Spec.LogicalBridges { - BrObj, err := infradb.GetLB(vlan) - if err != nil { - log.Printf("LVM: unable to find key %s and error is %v", vlan, err) - return false - } - if BrObj.Spec.VlanID > math.MaxUint16 { - log.Printf("LVM : VlanID %v value passed in Logical Bridge create is greater than 16 bit value\n", BrObj.Spec.VlanID) - return false - } - //TODO: Update opi-api to change vlanid to uint16 in LogiclaBridge - vid := uint16(BrObj.Spec.VlanID) - if err = nlink.BridgeVlanAdd(ctx, vlanLink, vid, false, false, false, false); err != nil { - log.Printf("Failed to add VLAN %d to bridge interface %s: %v\n", vportID, link, err) - return false - } - log.Printf("LVM: Executed bridge vlan add dev %s vid %d \n", link, vid) - } - if err = nlink.BridgeFdbAdd(ctx, link, MacAddress); err != nil { - log.Printf("LVM: Error in executing command %s %s with error %s\n", "bridge fdb add", link, err) - return false - } - log.Printf("LVM: Executed bridge fdb add %s dev %s master static extern_learn\n", MacAddress, link) - return true -} - -// tearDownBp tears down the bridge port -func tearDownBp(bp *infradb.BridgePort) bool { - vportID := MactoVport(bp.Spec.MacAddress) - link := fmt.Sprintf("vport-%+v", vportID) - Intf, err := nlink.LinkByName(ctx, link) - if err != nil { - log.Printf("Failed to get link %v: %s\n", link, err) - return true - } - if err = nlink.LinkDel(ctx, Intf); err != nil { - log.Printf("Failed to delete link %v: %s\n", link, err) - return false - } - log.Printf(" LVM: Executed ip link delete %v\n", link) - return true -} - -// handlevrf handles the vrf functionality -func handlevrf(objectData *eventbus.ObjectData) { - var comp common.Component - vrf, err := infradb.GetVrf(objectData.Name) - if err != nil { - log.Printf("LVM : GetVrf error: %s\n", err) - return - } - if objectData.ResourceVersion != vrf.ResourceVersion { - log.Printf("LVM: Mismatch in resoruce version %+v\n and vrf resource version %+v\n", objectData.ResourceVersion, vrf.ResourceVersion) - comp.Name = lvmComp - 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 updaing vrf status %s\n", err) - } - return - } - if len(vrf.Status.Components) != 0 { - for i := 0; i < len(vrf.Status.Components); i++ { - if vrf.Status.Components[i].Name == lvmComp { - comp = vrf.Status.Components[i] - } - } - } - if vrf.Status.VrfOperStatus != infradb.VrfOperStatusToBeDeleted { - statusUpdate := setUpVrf(vrf) - comp.Name = lvmComp - if statusUpdate { - comp.Details = "" - comp.CompStatus = common.ComponentStatusSuccess - comp.Timer = 0 - } else { - if comp.Timer == 0 { - comp.Timer = 2 * time.Second - } else { - comp.Timer *= 2 - } - comp.CompStatus = common.ComponentStatusError - } - err := infradb.UpdateVrfStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) - if err != nil { - log.Printf("error updaing vrf status %s\n", err) - } - } else { - comp.Name = lvmComp - if tearDownVrf(vrf) { - comp.CompStatus = common.ComponentStatusSuccess - } else { - if comp.Timer == 0 { - comp.Timer = 2 * time.Second - } else { - comp.Timer *= 2 - } - comp.CompStatus = common.ComponentStatusError - } - err := infradb.UpdateVrfStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) - if err != nil { - log.Printf("error updaing vrf status %s\n", err) - } - } -} - -// disableRpFilter disables the RP filter -func disableRpFilter(iface string) { - // Work-around for the observation that sometimes the sysctl -w command did not take effect. - rpFilterDisabled := false - for i := 0; i < 3; i++ { - rpDisable := fmt.Sprintf("net.ipv4.conf.%s.rp_filter=0", iface) - run([]string{"sysctl", "-w", rpDisable}, false) - time.Sleep(2 * time.Millisecond) - rpDisable = fmt.Sprintf("net.ipv4.conf.%s.rp_filter", iface) - CP, err := run([]string{"sysctl", "-n", rpDisable}, false) - if err == 0 && strings.HasPrefix(CP, "0") { - rpFilterDisabled = true - log.Printf("LVM: rpFilterDisabled: %+v\n", rpFilterDisabled) - break - } - } - if !rpFilterDisabled { - log.Printf("Failed to disable rp_filtering on interface %s\n", iface) - } -} - -// setUpVrf sets up a vrf -func setUpVrf(vrf *infradb.Vrf) bool { - log.Printf("LVM configure linux function \n") - vlanIntf := fmt.Sprintf("rep-%+v", path.Base(vrf.Name)) - if path.Base(vrf.Name) == "GRD" { - disableRpFilter("rep-" + path.Base(vrf.Name)) - return true - } - muxIntf, err := nlink.LinkByName(ctx, vrfMux) - if err != nil { - log.Printf("Failed to get link information for %s, error is %v\n", vrfMux, err) - return false - } - vlanLink := &netlink.Vlan{LinkAttrs: netlink.LinkAttrs{Name: vlanIntf, ParentIndex: muxIntf.Attrs().Index}, VlanId: int(*vrf.Metadata.RoutingTable[0])} - if err = nlink.LinkAdd(ctx, vlanLink); err != nil { - log.Printf("Failed to add VLAN sub-interface %s: %v\n", vlanIntf, err) - return false - } - log.Printf(" LVM: Executed ip link add link %s name rep-%s type vlan id %s\n", vrfMux, path.Base(vrf.Name), strconv.Itoa(int(*vrf.Metadata.RoutingTable[0]))) - vrfIntf, err := nlink.LinkByName(ctx, path.Base(vrf.Name)) - if err != nil { - log.Printf("Failed to get link information for %s: %v\n", path.Base(vrf.Name), err) - return false - } - if err = nlink.LinkSetMaster(ctx, vlanLink, vrfIntf); err != nil { - log.Printf("Failed to set master for %v: %s\n", vlanIntf, err) - return false - } - if err = nlink.LinkSetUp(ctx, vlanLink); err != nil { - log.Printf("Failed to set up link for %v: %s\n", vlanLink, err) - return false - } - if err = nlink.LinkSetMTU(ctx, vlanLink, ipMtu); err != nil { - log.Printf("Failed to set MTU for %v: %s\n", vlanLink, err) - return false - } - log.Printf(" LVM: Executed ip link set rep-%s master %s up mtu %d\n", path.Base(vrf.Name), path.Base(vrf.Name), ipMtu) - disableRpFilter("rep-" + path.Base(vrf.Name)) - return true -} - -// tearDownVrf tears down a vrf -func tearDownVrf(vrf *infradb.Vrf) bool { - vlanIntf := fmt.Sprintf("rep-%+v", path.Base(vrf.Name)) - if path.Base(vrf.Name) == "GRD" { - return true - } - Intf, err := nlink.LinkByName(ctx, vlanIntf) - if err != nil { - log.Printf("Failed to get link %v: %s\n", vlanIntf, err) - return true - } - if err = nlink.LinkDel(ctx, Intf); err != nil { - log.Printf("Failed to delete link %v: %s\n", vlanIntf, err) - return false - } - log.Printf(" LVM: Executed ip link delete rep-%s\n", path.Base(vrf.Name)) - return true -} - -var ipMtu int -var brTenant string -var ctx context.Context -var nlink utils.Netlink - -// Init function initialize config -func Init() { - eb := eventbus.EBus - for _, subscriberConfig := range config.GlobalConfig.Subscribers { - if subscriberConfig.Name == lvmComp { - for _, eventType := range subscriberConfig.Events { - eb.StartSubscriber(subscriberConfig.Name, eventType, subscriberConfig.Priority, &ModulelvmHandler{}) - } - } - } - portMux = config.GlobalConfig.LinuxFrr.PortMux - vrfMux = config.GlobalConfig.LinuxFrr.VrfMux - ipMtu = config.GlobalConfig.LinuxFrr.IPMtu - brTenant = "br-tenant" - ctx = context.Background() - nlink = utils.NewNetlinkWrapper() -} diff --git a/pkg/bridge/bridge_test.go b/pkg/bridge/bridge_test.go index deb2bdab..8fbb2828 100644 --- a/pkg/bridge/bridge_test.go +++ b/pkg/bridge/bridge_test.go @@ -120,6 +120,14 @@ func Test_CreateLogicalBridge(t *testing.T) { out: &pb.LogicalBridge{ Spec: &pb.LogicalBridgeSpec{ VlanId: 11, + VtepIpPrefix: &pc.IPPrefix{ + Addr: &pc.IPAddress{ + Af: pc.IpAf_IP_AF_INET, + V4OrV6: &pc.IPAddress_V4Addr{ + V4Addr: 0, + }, + }, + }, }, Status: &pb.LogicalBridgeStatus{ OperStatus: pb.LBOperStatus_LB_OPER_STATUS_DOWN, diff --git a/pkg/config/config.go b/pkg/config/config.go index 435063eb..7cae4e6d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -26,8 +26,6 @@ type SubscriberConfig struct { type P4FilesConfig struct { P4infoFile string `yaml:"p4infofile"` BinFile string `yaml:"binfile"` - ConfFile string `yaml:"conffile"` - SdePath string `yaml:"sdepath"` } // RepresentorsConfig Representors config structure @@ -43,7 +41,6 @@ type RepresentorsConfig struct { // P4Config p4 config structure type P4Config struct { Enabled bool `yaml:"enabled"` - Driver string `yaml:"driver"` Representors map[string]interface{} `yaml:"representors"` Config P4FilesConfig `yaml:"config"` } @@ -64,6 +61,7 @@ type LinuxFrrConfig struct { PortMux string `yaml:"portmux"` VrfMux string `yaml:"vrfmux"` IPMtu int `yaml:"ipmtu"` + LocalAs int `yaml:"localas"` } // NetlinkConfig netlink config structure diff --git a/pkg/frr/frr.go b/pkg/frr/frr.go index 3ea9f568..70fe534d 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 } @@ -221,6 +245,8 @@ func run(cmd []string, flag bool) (string, int) { var defaultVtep, portMux, vrfMux string +var localas int + // var brTenant int // subscribeInfradb function handles the infradb subscriptions @@ -241,14 +267,15 @@ var ctx context.Context // Frr variable of type utils wrapper var Frr utils.Frr -// Init function handles init functionality -func Init() { +// Initialize function handles init functionality +func Initialize() { frrEnabled := config.GlobalConfig.LinuxFrr.Enabled if !frrEnabled { log.Println("FRR Module disabled") return } defaultVtep = config.GlobalConfig.LinuxFrr.DefaultVtep + localas = config.GlobalConfig.LinuxFrr.LocalAs portMux = config.GlobalConfig.LinuxFrr.PortMux vrfMux = config.GlobalConfig.LinuxFrr.VrfMux log.Printf(" frr vtep: %+v port-mux %+v vrf-mux: +%v", defaultVtep, portMux, vrfMux) @@ -256,7 +283,7 @@ func Init() { subscribeInfradb(&config.GlobalConfig) ctx = context.Background() - Frr = utils.NewFrrWrapper() + 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) @@ -265,6 +292,18 @@ func Init() { } } +// DeInitialize function handles stops functionality +func DeInitialize() { + frrEnabled := config.GlobalConfig.LinuxFrr.Enabled + if !frrEnabled { + log.Println("FRR Module disabled") + return + } + // Unsubscribe to InfraDB notifications + eb := eventbus.EBus + eb.UnsubscribeModule(frrComp) +} + // routingTableBusy function checks the routing table /*func routingTableBusy(table uint32) bool { cp, err := run([]string{"ip", "route", "show", "table", strconv.Itoa(int(table))}, false) @@ -320,15 +359,12 @@ type BgpVrfCmd struct { // setUpVrf sets up the vrf func setUpVrf(vrf *infradb.Vrf) (string, bool) { // This function must not be executed for the vrf representing the GRD - Ifname := strings.Split(vrf.Name, "/") - ifwlen := len(Ifname) - vrf.Name = Ifname[ifwlen-1] - if vrf.Name == "GRD" { + if path.Base(vrf.Name) == "GRD" { return "", true } if !reflect.ValueOf(vrf.Spec.Vni).IsZero() { // Configure the vrf in FRR and set up BGP EVPN for it - vrfName := fmt.Sprintf("vrf %s", vrf.Name) + vrfName := fmt.Sprintf("vrf %s", path.Base(vrf.Name)) vniID := fmt.Sprintf("vni %s", strconv.Itoa(int(*vrf.Spec.Vni))) _, err := Frr.FrrZebraCmd(ctx, fmt.Sprintf("configure terminal\n %s\n %s\n exit-vrf\n exit", vrfName, vniID)) // fmt.Printf("FrrZebraCmd: %v:%v", data, err) @@ -343,12 +379,12 @@ func setUpVrf(vrf *infradb.Vrf) (string, bool) { } else { LbiP = fmt.Sprintf("%+v", vrf.Spec.LoopbackIP.IP) } - _, err = Frr.FrrBgpCmd(ctx, fmt.Sprintf("configure terminal\n router bgp 65000 vrf %s\n bgp router-id %s\n no bgp ebgp-requires-policy\n no bgp hard-administrative-reset\n no bgp graceful-restart notification\n address-family ipv4 unicast\n redistribute connected\n redistribute static\n exit-address-family\n address-family l2vpn evpn\n advertise ipv4 unicast\n exit-address-family\n exit", vrf.Name, LbiP)) + _, err = Frr.FrrBgpCmd(ctx, fmt.Sprintf("configure terminal\n router bgp %+v vrf %s\n bgp router-id %s\n no bgp ebgp-requires-policy\n no bgp hard-administrative-reset\n no bgp graceful-restart notification\n address-family ipv4 unicast\n redistribute connected\n redistribute static\n exit-address-family\n address-family l2vpn evpn\n advertise ipv4 unicast\n exit-address-family\n exit", localas, path.Base(vrf.Name), LbiP)) if err != nil { return "", false } - log.Printf("FRR: Executed config t bgpVrfName router bgp 65000 vrf %s bgp_route_id %s no bgp ebgp-requires-policy exit-vrf exit\n", vrf.Name, LbiP) + log.Printf("FRR: Executed config t bgpVrfName router bgp %+v vrf %s bgp_route_id %s no bgp ebgp-requires-policy exit-vrf exit\n", localas, vrf.Name, LbiP) // Update the vrf with attributes from FRR cmd := fmt.Sprintf("show bgp l2vpn evpn vni %d json", *vrf.Spec.Vni) cp, err := Frr.FrrBgpCmd(ctx, cmd) @@ -371,7 +407,7 @@ func setUpVrf(vrf *infradb.Vrf) (string, bool) { if err1 != nil { log.Printf("error-%v", err) } - cmd = fmt.Sprintf("show bgp vrf %s json", vrf.Name) + cmd = fmt.Sprintf("show bgp vrf %s json", path.Base(vrf.Name)) cp, err = Frr.FrrBgpCmd(ctx, cmd) if err != nil { log.Printf("error-%v", err) @@ -416,7 +452,7 @@ func setUpSvi(svi *infradb.Svi) bool { // gwIP := fmt.Sprintf("%s", svi.Spec.GatewayIPs[0].IP.To4()) gwIP := string(svi.Spec.GatewayIPs[0].IP.To4()) RemoteAs := fmt.Sprintf("%d", *svi.Spec.RemoteAs) - bgpVrfName := fmt.Sprintf("router bgp 65000 vrf %s\n", path.Base(svi.Spec.Vrf)) + bgpVrfName := fmt.Sprintf("router bgp %+v vrf %s\n", localas, path.Base(svi.Spec.Vrf)) neighlink := fmt.Sprintf("neighbor %s peer-group\n", linkSvi) neighlinkRe := fmt.Sprintf("neighbor %s remote-as %s\n", linkSvi, RemoteAs) neighlinkGw := fmt.Sprintf("neighbor %s update-source %s\n", linkSvi, gwIP) @@ -445,14 +481,14 @@ func tearDownSvi(svi *infradb.Svi) bool { } linkSvi := fmt.Sprintf("%+v-%+v", path.Base(svi.Spec.Vrf), BrObj.Spec.VlanID) if svi.Spec.EnableBgp && !reflect.ValueOf(svi.Spec.GatewayIPs).IsZero() { - bgpVrfName := fmt.Sprintf("router bgp 65000 vrf %s", path.Base(svi.Spec.Vrf)) + bgpVrfName := fmt.Sprintf("router bgp %+v vrf %s", localas, path.Base(svi.Spec.Vrf)) noNeigh := fmt.Sprintf("no neighbor %s peer-group", linkSvi) data, err := Frr.FrrBgpCmd(ctx, fmt.Sprintf("configure terminal\n %s\n %s\n exit", bgpVrfName, noNeigh)) if err != nil || checkFrrResult(data, false) { log.Printf("FRR: Error in conf Delete vrf/VNI command %s\n", data) return false } - log.Printf("FRR: Executed vtysh -c conf t -c router bgp 65000 vrf %s -c no neighbor %s peer-group -c exit\n", path.Base(svi.Spec.Vrf), linkSvi) + log.Printf("FRR: Executed vtysh -c conf t -c router bgp %+v vrf %s -c no neighbor %s peer-group -c exit\n", localas, path.Base(svi.Spec.Vrf), linkSvi) return true } return true @@ -461,14 +497,11 @@ func tearDownSvi(svi *infradb.Svi) bool { // tearDownVrf tears down vrf func tearDownVrf(vrf *infradb.Vrf) bool { // This function must not be executed for the vrf representing the GRD - Ifname := strings.Split(vrf.Name, "/") - ifwlen := len(Ifname) - vrf.Name = Ifname[ifwlen-1] - if vrf.Name == "GRD" { + if path.Base(vrf.Name) == "GRD" { return true } - data, err := Frr.FrrZebraCmd(ctx, fmt.Sprintf("show vrf %s vni\n", vrf.Name)) + data, err := Frr.FrrZebraCmd(ctx, fmt.Sprintf("show vrf %s vni\n", path.Base(vrf.Name))) if err != nil { log.Printf("tearDownVrf : failed to run the command") } @@ -479,8 +512,8 @@ func tearDownVrf(vrf *infradb.Vrf) bool { // Clean up FRR last if !reflect.ValueOf(vrf.Spec.Vni).IsZero() { log.Printf("FRR Deleted event") - delCmd1 := fmt.Sprintf("no router bgp 65000 vrf %s", vrf.Name) - delCmd2 := fmt.Sprintf("no vrf %s", vrf.Name) + delCmd1 := fmt.Sprintf("no router bgp %+v vrf %s", localas, path.Base(vrf.Name)) + delCmd2 := fmt.Sprintf("no vrf %s", path.Base(vrf.Name)) _, err = Frr.FrrBgpCmd(ctx, fmt.Sprintf("configure terminal\n %s\n exit\n", delCmd1)) if err != nil { return false diff --git a/pkg/infradb/bridge.go b/pkg/infradb/bridge.go index becdca15..1a3d7e44 100644 --- a/pkg/infradb/bridge.go +++ b/pkg/infradb/bridge.go @@ -14,8 +14,10 @@ import ( "net" pb "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go" + "github.com/opiproject/opi-evpn-bridge/pkg/config" "github.com/opiproject/opi-evpn-bridge/pkg/infradb/common" "github.com/opiproject/opi-evpn-bridge/pkg/infradb/subscriberframework/eventbus" + "github.com/opiproject/opi-evpn-bridge/pkg/utils" ) // LogicalBridgeOperStatus operational Status for Logical Bridges @@ -73,6 +75,9 @@ func NewLogicalBridge(in *pb.LogicalBridge) (*LogicalBridge, error) { vtepip := make(net.IP, 4) binary.BigEndian.PutUint32(vtepip, in.Spec.VtepIpPrefix.Addr.GetV4Addr()) vip = &net.IPNet{IP: vtepip, Mask: net.CIDRMask(int(in.Spec.VtepIpPrefix.Len), 32)} + } else { + tmpVtepIP := utils.GetIPAddress(config.GlobalConfig.LinuxFrr.DefaultVtep) + vip = &tmpVtepIP } subscribers := eventbus.EBus.GetSubscribers("logical-bridge") diff --git a/pkg/infradb/infradb.go b/pkg/infradb/infradb.go index 284ffc3e..664db24d 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" @@ -1210,6 +1211,80 @@ func GetAllSvis() ([]*Svi, error) { return svis, nil } +// 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) + if err != nil { + 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) + 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() + for _, lb := range lbs { + err := DeleteLB(lb.Name) + if err != nil { + 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 +} + // UpdateSvi updates a svi infradb object func UpdateSvi(svi *Svi) error { globalLock.Lock() diff --git a/pkg/infradb/subscriberframework/eventbus/eventbus.go b/pkg/infradb/subscriberframework/eventbus/eventbus.go index 2d8a23d8..47384474 100644 --- a/pkg/infradb/subscriberframework/eventbus/eventbus.go +++ b/pkg/infradb/subscriberframework/eventbus/eventbus.go @@ -66,6 +66,7 @@ func (e *EventBus) StartSubscriber(moduleName, eventType string, priority int, e subscriber.Ch <- "error: no event handler found" } case <-subscriber.Quit: + log.Printf("\nSubscriber %s quit \n", subscriber.Name) close(subscriber.Ch) return } @@ -115,6 +116,7 @@ func (e *EventBus) GetSubscribers(eventType string) []*Subscriber { return e.subscribers[eventType] } +// subscriberExist checks if the subscriber exist func (e *EventBus) subscriberExist(eventType string, moduleName string) bool { subList := e.GetSubscribers(eventType) if len(subList) != 0 { @@ -127,6 +129,24 @@ func (e *EventBus) subscriberExist(eventType string, moduleName string) bool { return false } +// UnsubscribeModule unsubs the whole module +func (e *EventBus) UnsubscribeModule(moduleName string) bool { + for eventName, subs := range e.subscribers { + if len(subs) != 0 { + for i, sub := range subs { + if sub.Name == moduleName { + sub.Quit <- true + e.subscribers[eventName] = append(subs[:i], subs[i+1:]...) + e.eventHandlers[moduleName+"."+eventName] = nil + log.Printf("\n Module %s is unsubscribed for event %s", sub.Name, eventName) + } + } + } + } + log.Printf("\nSubscriber %s is unsubscribed for all events\n", moduleName) + return false +} + // Publish api notifies the subscribers with certain eventType func (e *EventBus) Publish(objectData *ObjectData, subscriber *Subscriber) { e.publishL.RLock() diff --git a/pkg/infradb/vrf.go b/pkg/infradb/vrf.go index 6e099996..0d0665ea 100644 --- a/pkg/infradb/vrf.go +++ b/pkg/infradb/vrf.go @@ -14,8 +14,10 @@ import ( // "time" pb "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go" + "github.com/opiproject/opi-evpn-bridge/pkg/config" "github.com/opiproject/opi-evpn-bridge/pkg/infradb/common" "github.com/opiproject/opi-evpn-bridge/pkg/infradb/subscriberframework/eventbus" + "github.com/opiproject/opi-evpn-bridge/pkg/utils" ) // VrfOperStatus operational Status for VRFs @@ -133,6 +135,9 @@ func NewVrf(in *pb.Vrf) (*Vrf, error) { vtepip := make(net.IP, 4) binary.BigEndian.PutUint32(vtepip, in.Spec.VtepIpPrefix.Addr.GetV4Addr()) vip = &net.IPNet{IP: vtepip, Mask: net.CIDRMask(int(in.Spec.VtepIpPrefix.Len), 32)} + } else { + tmpVtepIP := utils.GetIPAddress(config.GlobalConfig.LinuxFrr.DefaultVtep) + vip = &tmpVtepIP } subscribers := eventbus.EBus.GetSubscribers("vrf") diff --git a/pkg/utils/helpers.go b/pkg/utils/helpers.go index 1a9a5950..246f19bf 100644 --- a/pkg/utils/helpers.go +++ b/pkg/utils/helpers.go @@ -5,8 +5,12 @@ package utils import ( + "context" + "log" + "net" "regexp" + "github.com/vishvananda/netlink" "go.einride.tech/aip/fieldmask" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/fieldmaskpb" @@ -28,3 +32,35 @@ func ValidateMacAddress(b []byte) error { } return nil } + +// GetIPAddress gets the ip address from link +func GetIPAddress(dev string) net.IPNet { + nlink := NewNetlinkWrapper() + ctx := context.Background() + link, err := nlink.LinkByName(ctx, dev) + if err != nil { + log.Printf("Error in LinkByName %+v\n", err) + return net.IPNet{ + IP: net.ParseIP("0.0.0.0"), + } + } + + addrs, err := nlink.AddrList(ctx, link, netlink.FAMILY_V4) // ip address show + if err != nil { + log.Printf("Error in AddrList\n") + return net.IPNet{ + IP: net.ParseIP("0.0.0.0"), + } + } + var address = &net.IPNet{ + IP: net.IPv4(127, 0, 0, 0), + Mask: net.CIDRMask(8, 32)} + var addr = &netlink.Addr{IPNet: address} + var validIps []netlink.Addr + for index := 0; index < len(addrs); index++ { + if !addr.Equal(addrs[index]) { + validIps = append(validIps, addrs[index]) + } + } + return *validIps[0].IPNet +} diff --git a/pkg/vrf/vrf_test.go b/pkg/vrf/vrf_test.go index 2d94b31c..d4c9e733 100644 --- a/pkg/vrf/vrf_test.go +++ b/pkg/vrf/vrf_test.go @@ -138,6 +138,14 @@ func Test_CreateVrf(t *testing.T) { }, Len: 24, }, + VtepIpPrefix: &pc.IPPrefix{ + Addr: &pc.IPAddress{ + Af: pc.IpAf_IP_AF_INET, + V4OrV6: &pc.IPAddress_V4Addr{ + V4Addr: 0, + }, + }, + }, }, Status: &pb.VrfStatus{ OperStatus: pb.VRFOperStatus_VRF_OPER_STATUS_DOWN, diff --git a/testscript/auto_create_100_vrfs.sh b/testscript/auto_create_100_vrfs.sh deleted file mode 100755 index dd303554..00000000 --- a/testscript/auto_create_100_vrfs.sh +++ /dev/null @@ -1,45 +0,0 @@ -#/bin/bash - -<< com -{ - set -e - while true - do - sleep 1 - # Since this is run as a subshell (instead of an external command), - # the parent pid is $$, not $PPID. - ip -br l | grep br- | wc -l - # kill -9 $(pidof opi-evpn-bridge_12022024) - done -} & - -com - -i=0 -while [ $i -lt 100 ] -do - ./godpu evpn create-vrf --name brown$i --vni `expr $i + 100` --loopback 10.121.11.`expr $i + 10`/32 --vtep 110.1.41.51/32 --addr localhost:50151 - i=`expr $i + 1` -# sleep 0.1 -done -sleep 40 - -j=0 - -while [ $j -lt 100 ] -do - ./godpu evpn get-vrf --name brown$j - #sleep 0.5 - j=`expr $j + 1` -done - -sleep 30 -x=0 - -while [ $x -lt 100 ] -do - ./godpu evpn delete-vrf --name brown$x - #sleep 0.5 - x=`expr $x + 1` -done - diff --git a/testscript/auto_create_delete_vrf_nosleep.sh b/testscript/auto_create_delete_vrf_nosleep.sh deleted file mode 100755 index 44db2a96..00000000 --- a/testscript/auto_create_delete_vrf_nosleep.sh +++ /dev/null @@ -1,31 +0,0 @@ -#/bin/bash - -a=0 -while [ $a -lt 2 ] -do -i=0 -while [ $i -lt 1 ] -do - ./godpu evpn create-vrf --name yellow$a --vni `expr $a + 301` --loopback 10.11.17.`expr $i + $a + 10`/32 --vtep 110.1.41.5/32 --addr localhost:50151 - i=`expr $i + 1` -done -sleep 0.5 - -j=0 - -while [ $j -lt 1 ] -do - ./godpu evpn get-vrf --name yellow$a - j=`expr $j + 1` -done - -x=0 - -while [ $x -lt 1 ] -do - ./godpu evpn delete-vrf --name yellow$a - x=`expr $x + 1` -done -a=`expr $a + 1` - -done