[SEBA-843] Storing PortNo in the ONU Device struct so that it can be passed with the packetIndications

Change-Id: I28e0bf5721d11fc52d70c6072a6cf70586ba5f98
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index 864a88e..c3a62ff 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -50,17 +50,17 @@
 	apiDoneChannel  *chan bool
 	nniPktInChannel chan *bbsim.PacketMsg
 
-	Pons []PonPort
-	Nnis []NniPort
+	Pons []*PonPort
+	Nnis []*NniPort
 
 	// OLT Attributes
 	OperState *fsm.FSM
 }
 
-var olt = OltDevice{}
+var olt OltDevice
 
-func GetOLT() OltDevice {
-	return olt
+func GetOLT() *OltDevice {
+	return &olt
 }
 
 func CreateOLT(seq int, nni int, pon int, onuPerPon int, sTag int, cTagInit int, oltDoneChannel *chan bool, apiDoneChannel *chan bool, group *sync.WaitGroup) OltDevice {
@@ -80,8 +80,8 @@
 		NumNni:          nni,
 		NumPon:          pon,
 		NumOnuPerPon:    onuPerPon,
-		Pons:            []PonPort{},
-		Nnis:            []NniPort{},
+		Pons:            []*PonPort{},
+		Nnis:            []*NniPort{},
 		channel:         make(chan Message),
 		oltDoneChannel:  oltDoneChannel,
 		apiDoneChannel:  apiDoneChannel,
@@ -110,7 +110,7 @@
 		oltLogger.Fatalf("Couldn't create NNI Port: %v", err)
 	}
 
-	olt.Nnis = append(olt.Nnis, nniPort)
+	olt.Nnis = append(olt.Nnis, &nniPort)
 
 	// create PON ports
 	availableCTag := cTagInit
@@ -120,6 +120,7 @@
 			ID:     uint32(i),
 			Type:   "pon",
 			Olt:    olt,
+			Onus:   []*Onu{},
 		}
 		p.OperState = getOperStateFSM(func(e *fsm.Event) {
 			oltLogger.WithFields(log.Fields{
@@ -129,13 +130,12 @@
 
 		// create ONU devices
 		for j := 0; j < onuPerPon; j++ {
-			//o := CreateONU(olt, p, uint32(onuId))
 			o := CreateONU(olt, p, uint32(j+1), sTag, availableCTag)
 			p.Onus = append(p.Onus, o)
 			availableCTag = availableCTag + 1
 		}
 
-		olt.Pons = append(olt.Pons, p)
+		olt.Pons = append(olt.Pons, &p)
 	}
 
 	newOltServer(olt)
@@ -246,7 +246,7 @@
 func (o OltDevice) getPonById(id uint32) (*PonPort, error) {
 	for _, pon := range o.Pons {
 		if pon.ID == id {
-			return &pon, nil
+			return pon, nil
 		}
 	}
 	return nil, errors.New(fmt.Sprintf("Cannot find PonPort with id %d in OLT %d", id, o.ID))
@@ -255,7 +255,7 @@
 func (o OltDevice) getNniById(id uint32) (*NniPort, error) {
 	for _, nni := range o.Nnis {
 		if nni.ID == id {
-			return &nni, nil
+			return nni, nil
 		}
 	}
 	return nil, errors.New(fmt.Sprintf("Cannot find NniPort with id %d in OLT %d", id, o.ID))
@@ -375,7 +375,7 @@
 				"IntfType": "nni",
 				"IntfId":   nniId,
 				"Pkt":      message.Pkt.Data(),
-			}).Info("Can't find Dst MacAddress in packet")
+			}).Error("Can't find Dst MacAddress in packet")
 			return
 		}
 
@@ -386,7 +386,7 @@
 				"IntfId":     nniId,
 				"Pkt":        message.Pkt.Data(),
 				"MacAddress": onuMac.String(),
-			}).Info("Can't find ONU with MacAddress")
+			}).Error("Can't find ONU with MacAddress")
 			return
 		}
 
@@ -421,7 +421,7 @@
 	for _, pon := range o.Pons {
 		for _, onu := range pon.Onus {
 			if onu.Sn() == serialNumber {
-				return &onu, nil
+				return onu, nil
 			}
 		}
 	}
@@ -436,7 +436,7 @@
 	for _, pon := range o.Pons {
 		for _, onu := range pon.Onus {
 			if onu.HwAddress.String() == mac.String() {
-				return &onu, nil
+				return onu, nil
 			}
 		}
 	}
@@ -531,8 +531,22 @@
 			"FlowId": flow.FlowId,
 		}).Debugf("This is an OLT flow")
 	} else {
-		pon, _ := o.getPonById(uint32(flow.AccessIntfId))
-		onu, _ := pon.getOnuById(uint32(flow.OnuId))
+		pon, err := o.getPonById(uint32(flow.AccessIntfId))
+		if err != nil {
+			oltLogger.WithFields(log.Fields{
+				"OnuId":  flow.OnuId,
+				"IntfId": flow.AccessIntfId,
+				"err":    err,
+			}).Error("Can't find PonPort")
+		}
+		onu, err := pon.getOnuById(uint32(flow.OnuId))
+		if err != nil {
+			oltLogger.WithFields(log.Fields{
+				"OnuId":  flow.OnuId,
+				"IntfId": flow.AccessIntfId,
+				"err":    err,
+			}).Error("Can't find Onu")
+		}
 
 		msg := Message{
 			Type: FlowUpdate,
@@ -606,8 +620,22 @@
 }
 
 func (o OltDevice) OnuPacketOut(ctx context.Context, onuPkt *openolt.OnuPacket) (*openolt.Empty, error) {
-	pon, _ := o.getPonById(onuPkt.IntfId)
-	onu, _ := pon.getOnuById(onuPkt.OnuId)
+	pon, err := o.getPonById(onuPkt.IntfId)
+	if err != nil {
+		oltLogger.WithFields(log.Fields{
+			"OnuId":  onuPkt.OnuId,
+			"IntfId": onuPkt.IntfId,
+			"err":    err,
+		}).Error("Can't find PonPort")
+	}
+	onu, err := pon.getOnuById(onuPkt.OnuId)
+	if err != nil {
+		oltLogger.WithFields(log.Fields{
+			"OnuId":  onuPkt.OnuId,
+			"IntfId": onuPkt.IntfId,
+			"err":    err,
+		}).Error("Can't find Onu")
+	}
 
 	oltLogger.WithFields(log.Fields{
 		"IntfId": onu.PonPortID,