(VOL-4972) enabling pon and onu object get apis in bbsim

Change-Id: I81932e4a8a1370ce83624f1deaf385c2809d568c
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index 96ee5f1..bb5be2e 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -1597,9 +1597,84 @@
 	return new(openolt.Empty), nil
 }
 
-func (o *OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuIndication, error) {
-	oltLogger.Error("GetOnuInfo not implemented")
-	return new(openolt.OnuIndication), nil
+func (o *OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuInfo, error) {
+	pon, err := o.GetPonById(packet.GetIntfId())
+	if err != nil {
+		log.WithFields(log.Fields{
+			"OnuId":  packet.GetOnuId(),
+			"IntfId": packet.GetIntfId(),
+			"err":    err,
+		}).Error("Can't find PonPort")
+		return nil, err
+	}
+	onu, _ := pon.GetOnuById(packet.GetOnuId())
+	if err != nil {
+		log.WithFields(log.Fields{
+			"OnuId":  packet.GetOnuId(),
+			"IntfId": packet.GetIntfId(),
+			"err":    err,
+		}).Error("Can't find Onu")
+		return nil, err
+	}
+
+	resp := new(openolt.OnuInfo)
+	resp.OnuId = packet.GetOnuId()
+	if onu.OperState.Current() == "up" {
+		resp.Losi = openolt.AlarmState_OFF
+		resp.Lofi = openolt.AlarmState_OFF
+		resp.Loami = openolt.AlarmState_OFF
+	} else if onu.OperState.Current() == "down" {
+		resp.Losi = openolt.AlarmState_ON
+		resp.Lofi = openolt.AlarmState_ON
+		resp.Loami = openolt.AlarmState_ON
+	}
+	if onu.InternalState.Current() == OnuStateEnabled {
+		resp.State = openolt.OnuInfo_ACTIVE
+	} else if onu.InternalState.Current() == OnuStateDisabled {
+		resp.State = openolt.OnuInfo_INACTIVE
+	} else if onu.InternalState.Current() == OnuStateCreated || (onu.InternalState.Current() == OnuStateInitialized) {
+		resp.State = openolt.OnuInfo_NOT_CONFIGURED
+	} else {
+		resp.State = openolt.OnuInfo_UNKNOWN
+	}
+	log.WithFields(log.Fields{
+		"OnuId":    packet.GetOnuId(),
+		"IntfId":   packet.GetIntfId(),
+		"response": resp,
+	}).Info("Response for onu info")
+	return resp, nil
+}
+
+func (o *OltDevice) GetPonInterfaceInfo(context context.Context, packet *openolt.Interface) (*openolt.PonIntfInfo, error) {
+	ponPort, err := o.GetPonById(packet.GetIntfId())
+	if err != nil {
+		log.WithFields(log.Fields{
+			"IntfId": packet.GetIntfId(),
+			"err":    err,
+		}).Error("Can't find PonPort")
+		return nil, err
+	}
+	resp := new(openolt.PonIntfInfo)
+	resp.IntfId = packet.GetIntfId()
+	if ponPort.OperState.Current() == "up" {
+		resp.Los = openolt.AlarmState_OFF
+	} else if ponPort.OperState.Current() == "down" {
+		resp.Los = openolt.AlarmState_ON
+	}
+	if ponPort.InternalState.Current() == "enabled" {
+		resp.State = openolt.PonIntfInfo_ACTIVE_WORKING
+	} else if ponPort.InternalState.Current() == "disabled" {
+		resp.State = openolt.PonIntfInfo_INACTIVE
+	} else if ponPort.InternalState.Current() == "created" {
+		resp.State = openolt.PonIntfInfo_ACTIVE_STANDBY
+	} else {
+		resp.State = openolt.PonIntfInfo_UNKNOWN
+	}
+	log.WithFields(log.Fields{
+		"IntfId":   packet.GetIntfId(),
+		"response": resp,
+	}).Info("Response for pon info")
+	return resp, nil
 }
 
 func (o *OltDevice) GetPonIf(context context.Context, packet *openolt.Interface) (*openolt.IntfIndication, error) {
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index ebe08d6..43987f1 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -1838,23 +1838,34 @@
 		"OnuId":  onu.ID,
 		"OnuSn":  onu.Sn(),
 	}).Debug("Send ONU Re-Discovery")
+	if onu.InternalState.Current() != OnuStateDiscovered {
+		// ONU Re-Discovery
+		if err := onu.InternalState.Event(OnuTxInitialize); err != nil {
+			log.WithFields(log.Fields{
+				"IntfId": onu.PonPortID,
+				"OnuSn":  onu.Sn(),
+				"OnuId":  onu.ID,
+			}).Infof("Failed to transition ONU to %s state: %s", OnuStateInitialized, err.Error())
+		}
 
-	// ONU Re-Discovery
-	if err := onu.InternalState.Event(OnuTxInitialize); err != nil {
-		log.WithFields(log.Fields{
-			"IntfId": onu.PonPortID,
-			"OnuSn":  onu.Sn(),
-			"OnuId":  onu.ID,
-		}).Infof("Failed to transition ONU to %s state: %s", OnuStateInitialized, err.Error())
+		if err := onu.InternalState.Event(OnuTxDiscover); err != nil {
+			log.WithFields(log.Fields{
+				"IntfId": onu.PonPortID,
+				"OnuSn":  onu.Sn(),
+				"OnuId":  onu.ID,
+			}).Infof("Failed to transition ONU to %s state: %s", OnuStateDiscovered, err.Error())
+		}
+	} else {
+		//if onu is already discovered dont change the state ut rather fire the indication again (this case happens if voltha misses the indications)
+		msg := bbsim.Message{
+			Type: bbsim.OnuDiscIndication,
+			Data: bbsim.OnuDiscIndicationMessage{
+				OperState: bbsim.UP,
+			},
+		}
+		onu.Channel <- msg
 	}
 
-	if err := onu.InternalState.Event(OnuTxDiscover); err != nil {
-		log.WithFields(log.Fields{
-			"IntfId": onu.PonPortID,
-			"OnuSn":  onu.Sn(),
-			"OnuId":  onu.ID,
-		}).Infof("Failed to transition ONU to %s state: %s", OnuStateDiscovered, err.Error())
-	}
 }
 
 // deprecated, delegate this to the uniPort
diff --git a/internal/bbsim/devices/onu_test_helpers.go b/internal/bbsim/devices/onu_test_helpers.go
index dc03614..29d7f39 100644
--- a/internal/bbsim/devices/onu_test_helpers.go
+++ b/internal/bbsim/devices/onu_test_helpers.go
@@ -147,6 +147,14 @@
 	return nil, errors.New("unimplemented-in-mock-client")
 }
 
+func (s *mockClient) GetOnuInfo(context context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuInfo, error) {
+	return nil, errors.New("unimplemented-in-mock-client")
+}
+
+func (s *mockClient) GetPonInterfaceInfo(context context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.PonIntfInfo, error) {
+	return nil, errors.New("unimplemented-in-mock-client")
+}
+
 // this method creates a fake ONU used in the tests
 func createMockOnu(id uint32, ponPortId uint32) *Onu {
 	o := Onu{