[SEBA-873] add reboot olt support

Change-Id: I1570d05313661a6d66e1596b9f9a1a1cc17d1a73
diff --git a/cmd/bbsim/bbsim.go b/cmd/bbsim/bbsim.go
index 74bda32..23221c6 100644
--- a/cmd/bbsim/bbsim.go
+++ b/cmd/bbsim/bbsim.go
@@ -37,7 +37,7 @@
 	"google.golang.org/grpc/reflection"
 )
 
-func startApiServer(channel chan bool, group *sync.WaitGroup) {
+func startApiServer(apiDoneChannel chan bool, group *sync.WaitGroup) {
 	// TODO make configurable
 	address := "0.0.0.0:50070"
 	log.Debugf("APIServer listening on: %v", address)
@@ -51,11 +51,11 @@
 	reflection.Register(grpcServer)
 
 	go grpcServer.Serve(lis)
-	go startApiRestServer(channel, group, address)
+	go startApiRestServer(apiDoneChannel, group, address)
 
 	select {
-	case <-channel:
-		// if the api channel is closed, stop the gRPC server
+	case <-apiDoneChannel:
+		// if the API channel is closed, stop the gRPC server
 		grpcServer.Stop()
 		log.Warnf("Stopping API gRPC server")
 	}
@@ -64,7 +64,7 @@
 }
 
 // startApiRestServer method starts the REST server (grpc gateway) for BBSim.
-func startApiRestServer(channel chan bool, group *sync.WaitGroup, grpcAddress string) {
+func startApiRestServer(apiDoneChannel chan bool, group *sync.WaitGroup, grpcAddress string) {
 	ctx := context.Background()
 	ctx, cancel := context.WithCancel(ctx)
 	defer cancel()
@@ -91,7 +91,7 @@
 	}()
 
 	select {
-	case <-channel:
+	case <-apiDoneChannel:
 		log.Warnf("Stopping API REST server")
 		s.Shutdown(ctx)
 	}
@@ -100,7 +100,7 @@
 }
 
 // This server aims to provide compatibility with the previous BBSim version. It is deprecated and will be removed in the future.
-func startLegacyApiServer(channel chan bool, group *sync.WaitGroup) {
+func startLegacyApiServer(apiDoneChannel chan bool, group *sync.WaitGroup) {
 	// TODO make configurable
 	grpcAddress := "0.0.0.0:50072"
 	restAddress := "0.0.0.0:50073"
@@ -116,11 +116,11 @@
 
 	go apiserver.Serve(listener)
 	// Start rest gateway for BBSim server
-	go api.StartRestGatewayService(channel, group, grpcAddress, restAddress)
+	go api.StartRestGatewayService(apiDoneChannel, group, grpcAddress, restAddress)
 
 	select {
-	case <-channel:
-		// if the olt channel is closed, stop the gRPC server
+	case <-apiDoneChannel:
+		// if the API channel is closed, stop the gRPC server
 		log.Warnf("Stopping legacy API gRPC server")
 		apiserver.Stop()
 		break
@@ -157,43 +157,37 @@
 	}).Info("BroadBand Simulator is on")
 
 	// control channels, they are only closed when the goroutine needs to be terminated
-	oltDoneChannel := make(chan bool)
 	apiDoneChannel := make(chan bool)
 
-	sigs := make(chan os.Signal, 1)
-	// stop API and OLT servers on SIGTERM
-	signal.Notify(sigs, syscall.SIGTERM)
-
-	go func() {
-		<-sigs
-		// TODO check when these servers should be shutdown
-		close(apiDoneChannel)
-		close(oltDoneChannel)
-	}()
-
-	wg := sync.WaitGroup{}
-	wg.Add(5)
-
-	olt := devices.CreateOLT(
+	devices.CreateOLT(
 		options.OltID,
 		options.NumNniPerOlt,
 		options.NumPonPerOlt,
 		options.NumOnuPerPon,
 		options.STag,
 		options.CTagInit,
-		&oltDoneChannel,
-		&apiDoneChannel,
 		options.Auth,
 		options.Dhcp,
 		options.Delay,
 		false,
 	)
 
-	go devices.StartOlt(olt, &wg)
 	log.Debugf("Created OLT with id: %d", options.OltID)
+
+	sigs := make(chan os.Signal, 1)
+	// stop API servers on SIGTERM
+	signal.Notify(sigs, syscall.SIGTERM)
+
+	go func() {
+		<-sigs
+		close(apiDoneChannel)
+	}()
+
+	wg := sync.WaitGroup{}
+	wg.Add(4)
+
 	go startApiServer(apiDoneChannel, &wg)
 	go startLegacyApiServer(apiDoneChannel, &wg)
-
 	log.Debugf("Started APIService")
 
 	wg.Wait()