[VOL-5368] Fix: panic send on closed channel

Change-Id: I34dce020abf6599d76f8eb09ad603e5e4569ee45
Signed-off-by: Abhay Kumar <abhayk@radisys.com>
diff --git a/internal/bbsim/alarmsim/alarmsim.go b/internal/bbsim/alarmsim/alarmsim.go
index adc304b..4b52b3e 100644
--- a/internal/bbsim/alarmsim/alarmsim.go
+++ b/internal/bbsim/alarmsim/alarmsim.go
@@ -224,7 +224,6 @@
 		Type: types.AlarmIndication,
 		Data: alarmIndication,
 	}
-
 	channel <- msg
 
 	return nil
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index a8067cd..04a8632 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -364,7 +364,7 @@
 		}
 	}
 
-	time.Sleep(1 * time.Second) // we need to give the OLT the time to respond to all the pending gRPC request before stopping the server
+	time.Sleep(5 * time.Second) // we need to give the OLT the time to respond to all the pending gRPC request before stopping the server
 	o.StopOltServer()
 
 	// terminate the OLT's processOltMessages go routine
@@ -922,10 +922,12 @@
 }
 
 // GRPC Endpoints
-
 func (o *OltDevice) ActivateOnu(context context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
 
-	pon, _ := o.GetPonById(onu.IntfId)
+	pon, err := o.GetPonById(onu.IntfId)
+	if err != nil {
+		return new(openolt.Empty), err
+	}
 
 	// Enable the resource maps for this ONU
 	olt.AllocIDsLock.Lock()
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index 57b3aa0..95ade6d 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -707,6 +707,17 @@
 func (o *Onu) HandlePowerOnONU() error {
 	intitalState := o.InternalState.Current()
 
+	// Do not send discovery if OLT is in Deleted state
+	oltState := o.PonPort.Olt.InternalState.Current()
+	if oltState == "deleted" {
+		onuLogger.WithFields(log.Fields{
+			"OnuId":  o.ID,
+			"IntfId": o.PonPortID,
+			"OnuSn":  o.Sn(),
+		}).Errorf("Cannot poweron ONU. oltState: %s", oltState)
+		return nil
+	}
+
 	// initialize the ONU
 	if intitalState == OnuStateCreated || intitalState == OnuStateDisabled {
 		if err := o.InternalState.Event(OnuTxInitialize); err != nil {
@@ -1838,7 +1849,15 @@
 		"OnuId":  onu.ID,
 		"OnuSn":  onu.Sn(),
 	}).Debug("Send ONU Re-Discovery")
-	if onu.InternalState.Current() != OnuStateDiscovered {
+	// Do not send discovery if OLT is in Deleted state
+	oltState := onu.PonPort.Olt.InternalState.Current()
+	if oltState == "deleted" {
+		onuLogger.WithFields(log.Fields{
+			"IntfId": onu.PonPortID,
+			"OnuId":  onu.ID,
+			"OnuSn":  onu.Sn(),
+		}).Infof("Skip ONU Re-Discovery. oltState=%s", oltState)
+	} else if onu.InternalState.Current() != OnuStateDiscovered {
 		// ONU Re-Discovery
 		if err := onu.InternalState.Event(OnuTxInitialize); err != nil {
 			log.WithFields(log.Fields{