Merge "Fixing BBR"
diff --git a/Makefile b/Makefile
index 2cf851e..61f6c53 100644
--- a/Makefile
+++ b/Makefile
@@ -74,9 +74,9 @@
 	gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml
 
 test-bbr: build-bbr docker-build # @HELP Validate that BBSim and BBR are working together
-	DOCKER_RUN_ARGS="-auth -dhcp" make docker-run
+	DOCKER_RUN_ARGS="-auth -dhcp -pon 2 -onu 2" make docker-run
 	sleep 5
-	./bbr
+	./bbr -pon 2 -onu 2
 	docker rm -f bbsim
 
 fmt:
diff --git a/cmd/bbr/bbr.go b/cmd/bbr/bbr.go
index 4c83789..c5a373d 100644
--- a/cmd/bbr/bbr.go
+++ b/cmd/bbr/bbr.go
@@ -64,6 +64,8 @@
 		"NumOnuPerPon": options.Olt.OnusPonPort,
 		"BBSimIp":      options.BBSimIp,
 		"BBSimPort":    options.BBSimPort,
+		"LogLevel":     options.BBR.LogLevel,
+		"TotalOnus":    options.Olt.PonPorts * options.Olt.OnusPonPort,
 	}).Info("BroadBand Reflector is on")
 
 	// create the OLT device
@@ -80,6 +82,9 @@
 		options.BBSim.ControlledActivation,
 		true,
 	)
+
+	onuIdMap := make(map[uint32]uint32, options.Olt.PonPorts)
+
 	oltMock := bbrdevices.OltMock{
 		Olt:           olt,
 		TargetOnus:    int(options.Olt.PonPorts * options.Olt.OnusPonPort),
@@ -87,6 +92,7 @@
 		BBSimIp:       options.BBSimIp,
 		BBSimPort:     options.BBSimPort,
 		BBSimApiPort:  options.BBSimApiPort,
+		LastUsedOnuId: onuIdMap,
 	}
 
 	// start the enable sequence
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 aebd0f1..a45ec8a 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -595,6 +595,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"