Skip to content
Snippets Groups Projects
main.go 3.95 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
    	RtdtMan "code.fbi.h-da.de/danet/gosdn/applications/rtdt-manager/rtdt-manager"
    
    	//"code.fbi.h-da.de/danet/gosdn/applications/rtdt-manager/sdnconfig"
    
    	venv "code.fbi.h-da.de/danet/gosdn/applications/rtdt-manager/venv"
    
    	// Global stop channel, should be passed to all venvs and App
    	stopChan := make(chan os.Signal, 1)
    	signal.Notify(stopChan, os.Interrupt, syscall.SIGTERM)
    	var wg sync.WaitGroup
    
    	var address string
    
    	var withTwin bool
    
    	flag.StringVar(&address, "address", "172.100.0.5:55055", "Address of the gosdn controller")
    	flag.StringVar(&address, "a", "172.100.0.5:55055", "Address of the gosdn controller (shorthand)")
    	flag.StringVar(&pass, "password", "TestPassword", "Password for admin user")
    	flag.StringVar(&pass, "p", "TestPassword", "Password for admin user (shorthand)")
    	flag.StringVar(&user, "user", "admin", "Username")
    	flag.StringVar(&user, "u", "admin", "Username (shorthand)")
    
    	flag.BoolVar(&withTwin, "with-twin", false, "Whether to start a twin")
    
    	flag.StringVar(&clabConfigName, "clabfile", "data/clab.yaml", "Containerlab file with basic gosdn environment")
    	flag.StringVar(&clabConfigName, "c", "data/clab.yaml", "Containerlab file with basic gosdn environment (shorthand)")
    
    	flag.BoolVar(&benchmark, "benchmark", false, "Run performance tests (measure propagation delay)")
    	flag.BoolVar(&benchmark, "b", false, "Run performance tests (measure propagation delay)")
    
    	flag.StringVar(&sdnConfigPath, "sdnconfig", "applications/rtdt-manager/data/sample_venv_sdnconfig.json", "SdnConfig file (json)")
    
    
    	flag.Usage = func() {
    		fmt.Println("--address, -a: Address of the gosdn controller (realnet)")
    		fmt.Println("--user, -u: User to log into realnet as")
    		fmt.Println("--password, -p: Password for the user to log into realnet as")
    		fmt.Println("--topology, -t: Topology .yaml file to use to generate realnet and twins")
    
    		fmt.Println("--with-twin: Whether to start the containerlab virtual environment for the twin")
    
    		fmt.Println("--sdnconfig: Path to the sdnconfig .json file that contains information about network elements and links")
    
    	// sdnConfig := sdnconfig.NewSdnConfig()
    	// sdnConfig.LoadSdnConfig(sdnConfigPath)
    
    	realnet = venv.NewVEnv("realnet-test", clabConfigName, user, pass, &wg)
    
    	if realnet == nil {
    		fmt.Println("ERROR: Couldn't deploy the physical network")
    		return
    
    		fmt.Println("Successfully deployed physical network")
    
    	err = realnet.DeriveTopologyFromClabData()
    	if err != nil {
    		fmt.Printf("Error occured while trying to construct topology in realnet: %v\n", err)
    		return
    	}
    
    	err = realnet.UploadClabConfig()
    	if err != nil {
    		fmt.Printf("Error: Couldnt upload clab config: %v\n", err)
    	}
    
    	err = realnet.RetrieveClabConfig()
    	if err != nil {
    		fmt.Printf("Error: Couldn't retrieve clab config: %v\n", err)
    	}
    
    	err = realnet.CreateDevices()
    	if err != nil {
    		fmt.Printf("Error: Couldn't create devices!")
    		return
    	}
    
    	err = realnet.UploadTopology()
    	if err != nil {
    		fmt.Printf("Error occured while trying to upload realnet topology to DB: %v\n", err)
    		return
    	}
    
    	// Register realnet with a new rtdt-manager
    
    	rtdtMan := RtdtMan.NewRtdtManager(realnet, &wg, &stopChan)
    
    	if rtdtMan == nil {
    		fmt.Println("Couldn't initialize rtdt-manager, quitting!")
    		return
    	}
    
    	err = rtdtMan.InitEventSystem()
    
    		fmt.Printf("Error occured while initializing event system: %v\n", err)
    
    	// Do performance tests of realnet before starting twin
    	if benchmark {
    		fmt.Println("Now doing performance measurements of gosdn's propagation delay ")
    
    	if withTwin {
    
    		rtdtMan.LaunchTwin("172.101.0.0/16", "2001:db9::/64", "TEST-TWIN")
    
    	if err := rtdtMan.Run(); err != nil {
    		fmt.Println("Program exited with errors: %w", err)