Fixing BBR

As part of SEBA-927 BBSim expect VOLTHA to send back the OnuId and thus
BBR should behave the same way

Change-Id: I364c665c37385885310d8cfa1639b0f5037ed473
diff --git a/internal/bbr/devices/olt.go b/internal/bbr/devices/olt.go
index a12d8c6..bd35f68 100644
--- a/internal/bbr/devices/olt.go
+++ b/internal/bbr/devices/olt.go
@@ -34,10 +34,11 @@
 )
 
 type OltMock struct {
-	Olt          *devices.OltDevice
-	BBSimIp      string
-	BBSimPort    string
-	BBSimApiPort string
+	LastUsedOnuId map[uint32]uint32
+	Olt           *devices.OltDevice
+	BBSimIp       string
+	BBSimPort     string
+	BBSimApiPort  string
 
 	conn *grpc.ClientConn
 
@@ -55,7 +56,7 @@
 			if err := onu.InternalState.Event("initialize"); err != nil {
 				log.Fatalf("Error initializing ONU: %v", err)
 			}
-			log.Tracef("Created ONU: %s (%d:%d)", onu.Sn(), onu.STag, onu.CTag)
+			log.Debugf("Created ONU: %s (%d:%d)", onu.Sn(), onu.STag, onu.CTag)
 		}
 	}
 
@@ -180,13 +181,19 @@
 		log.WithFields(log.Fields{
 			"IntfId":       onuDiscInd.IntfId,
 			"SerialNumber": common.OnuSnToString(onuDiscInd.SerialNumber),
+			"Err":          err,
 		}).Fatal("Cannot find ONU")
 	}
 
+	// creating and storing ONU IDs
+	id := o.LastUsedOnuId[onuDiscInd.IntfId] + 1
+	o.LastUsedOnuId[onuDiscInd.IntfId] = o.LastUsedOnuId[onuDiscInd.IntfId] + 1
+	onu.SetID(id)
+
 	var pir uint32 = 1000000
 	Onu := openolt.Onu{
 		IntfId:       onu.PonPortID,
-		OnuId:        onu.ID,
+		OnuId:        id,
 		SerialNumber: onu.SerialNumber,
 		Pir:          pir,
 	}
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index 3c6c501..9acee9f 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -143,7 +143,7 @@
 
 		// create ONU devices
 		for j := 0; j < onuPerPon; j++ {
-			delay := time.Duration(olt.Delay * j) * time.Millisecond
+			delay := time.Duration(olt.Delay*j) * time.Millisecond
 			o := CreateONU(&olt, *p, uint32(j+1), sTag, availableCTag, auth, dhcp, delay, isMock)
 			p.Onus = append(p.Onus, o)
 			availableCTag = availableCTag + 1
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index c1ada1c..aef2ba8 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -596,6 +596,11 @@
 }
 
 func (o *Onu) SetID(id uint32) {
+	onuLogger.WithFields(log.Fields{
+		"IntfId":       o.PonPortID,
+		"OnuId":        id,
+		"SerialNumber": o.Sn(),
+	}).Debug("Storing OnuId ")
 	o.ID = id
 }
 
diff --git a/internal/bbsim/devices/onu_test_helpers.go b/internal/bbsim/devices/onu_test_helpers.go
index cb598de..1f70786 100644
--- a/internal/bbsim/devices/onu_test_helpers.go
+++ b/internal/bbsim/devices/onu_test_helpers.go
@@ -130,7 +130,7 @@
 		ID:  1,
 		Olt: &olt,
 	}
-	onu := CreateONU(&olt, pon, 1, 900, 900, false, false, time.Duration(1 * time.Millisecond),true)
+	onu := CreateONU(&olt, pon, 1, 900, 900, false, false, time.Duration(1*time.Millisecond), true)
 	// NOTE we need this in order to create the OnuChannel
 	onu.InternalState.Event("initialize")
 	onu.DiscoveryRetryDelay = 100 * time.Millisecond
diff --git a/internal/bbsim/responders/igmp/igmp.go b/internal/bbsim/responders/igmp/igmp.go
index cfdb079..e5c1ad2 100644
--- a/internal/bbsim/responders/igmp/igmp.go
+++ b/internal/bbsim/responders/igmp/igmp.go
@@ -64,7 +64,13 @@
 	}
 	//Sending IGMP packets
 	if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-		log.Errorf("Fail to send IGMP PktInd indication for ONU: %s, IntfId: %s, SerialNumber: %s,  error: %v", onuId, ponPortId, serialNumber, err)
+		log.WithFields(log.Fields{
+			"OnuId":        onuId,
+			"SerialNumber": serialNumber,
+			"PortNo":       portNo,
+			"IntfId":       ponPortId,
+			"err":          err,
+		}).Error("Fail to send IGMP PktInd indication for ONU")
 		return err
 	}
 	return nil
@@ -109,7 +115,13 @@
 	}
 	//Sending IGMP packets
 	if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-		log.Errorf("Fail to send IGMP PktInd indication for ONU: %s, IntfId: %s, SerialNumber: %s,  error: %v", onuId, ponPortId, serialNumber, err)
+		log.WithFields(log.Fields{
+			"OnuId":        onuId,
+			"SerialNumber": serialNumber,
+			"PortNo":       portNo,
+			"IntfId":       ponPortId,
+			"err":          err,
+		}).Errorf("Fail to send IGMP PktInd indication")
 		return err
 	}
 	return nil
diff --git a/internal/bbsimctl/commands/alarms.go b/internal/bbsimctl/commands/alarms.go
index a1c7113..044d74a 100755
--- a/internal/bbsimctl/commands/alarms.go
+++ b/internal/bbsimctl/commands/alarms.go
@@ -22,8 +22,8 @@
 	"fmt"
 	"github.com/jessevdk/go-flags"
 	pb "github.com/opencord/bbsim/api/bbsim"
-	"github.com/opencord/bbsim/internal/bbsimctl/config"
 	"github.com/opencord/bbsim/internal/bbsim/alarmsim"
+	"github.com/opencord/bbsim/internal/bbsimctl/config"
 	"github.com/opencord/cordctl/pkg/format"
 	log "github.com/sirupsen/logrus"
 	"os"