Starting BBSim API Server
Adding SerialNumber to GetDeviceInfo response (it's now required by
VOLTHA)

Change-Id: If726b5c313b6a424f54682aef68c001f6de51b57
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index 8435af1..2c3486e 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -4,7 +4,7 @@
 	"context"
 	"errors"
 	"fmt"
-	"gerrit.opencord.org/bbsim/api"
+	"gerrit.opencord.org/bbsim/api/openolt"
 	"github.com/looplab/fsm"
 	log "github.com/sirupsen/logrus"
 	"google.golang.org/grpc"
@@ -12,20 +12,30 @@
 	"sync"
 )
 
+var logger = log.WithFields(log.Fields{
+	"module": "OLT",
+})
+
 func init() {
 	//log.SetReportCaller(true)
 	log.SetLevel(log.DebugLevel)
 }
 
+var olt = OltDevice{}
+
+func GetOLT() OltDevice  {
+	return olt
+}
+
 func CreateOLT(seq int, nni int, pon int, onuPerPon int) OltDevice {
-	log.WithFields(log.Fields{
+	logger.WithFields(log.Fields{
 		"ID": seq,
 		"NumNni":nni,
 		"NumPon":pon,
 		"NumOnuPerPon":onuPerPon,
 	}).Debug("CreateOLT")
 
-	olt := OltDevice{
+	olt = OltDevice{
 		ID: seq,
 		NumNni:nni,
 		NumPon:pon,
@@ -86,15 +96,15 @@
 func newOltServer(o OltDevice) error {
 	// TODO make configurable
 	address :=  "0.0.0.0:50060"
-	log.Debugf("OLT Listening on: %v", address)
 	lis, err := net.Listen("tcp", address)
 	if err != nil {
-		log.Fatalf("failed to listen: %v", err)
+		logger.Fatalf("OLT failed to listen: %v", err)
 	}
 	grpcServer := grpc.NewServer()
 	openolt.RegisterOpenoltServer(grpcServer, o)
 
 	go grpcServer.Serve(lis)
+	logger.Debugf("OLT Listening on: %v", address)
 
 	return nil
 }
@@ -103,6 +113,8 @@
 
 func (o OltDevice) Enable (stream openolt.Openolt_EnableIndicationServer) error {
 
+	logger.Debug("Enable OLT called")
+
 	wg := sync.WaitGroup{}
 	wg.Add(1)
 
@@ -178,7 +190,7 @@
 }
 
 func (o OltDevice) stateChange(e *fsm.Event) {
-	log.WithFields(log.Fields{
+	logger.WithFields(log.Fields{
 		"oltId": o.ID,
 		"dstState": e.Dst,
 		"srcState": e.Src,
@@ -188,10 +200,10 @@
 func (o OltDevice) sendOltIndication(msg OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
 	data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}}
 	if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-		log.Error("Failed to send Indication_OltInd: %v", err)
+		logger.Error("Failed to send Indication_OltInd: %v", err)
 	}
 
-	log.WithFields(log.Fields{
+	logger.WithFields(log.Fields{
 		"OperState": msg.OperState,
 	}).Debug("Sent Indication_OltInd")
 }
@@ -206,10 +218,10 @@
 	}}
 
 	if err := stream.Send(&openolt.Indication{Data: operData}); err != nil {
-		log.Error("Failed to send Indication_IntfOperInd for NNI: %v", err)
+		logger.Error("Failed to send Indication_IntfOperInd for NNI: %v", err)
 	}
 
-	log.WithFields(log.Fields{
+	logger.WithFields(log.Fields{
 		"Type": nni.Type,
 		"IntfId": nni.ID,
 		"OperState": nni.OperState.String(),
@@ -225,10 +237,10 @@
 	}}
 
 	if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
-		log.Error("Failed to send Indication_IntfInd: %v", err)
+		logger.Error("Failed to send Indication_IntfInd: %v", err)
 	}
 
-	log.WithFields(log.Fields{
+	logger.WithFields(log.Fields{
 		"IntfId": pon.ID,
 		"OperState": pon.OperState.String(),
 	}).Debug("Sent Indication_IntfInd")
@@ -240,10 +252,10 @@
 	}}
 
 	if err := stream.Send(&openolt.Indication{Data: operData}); err != nil {
-		log.Error("Failed to send Indication_IntfOperInd for PON: %v", err)
+		logger.Error("Failed to send Indication_IntfOperInd for PON: %v", err)
 	}
 
-	log.WithFields(log.Fields{
+	logger.WithFields(log.Fields{
 		"Type": pon.Type,
 		"IntfId": pon.ID,
 		"OperState": pon.OperState.String(),
@@ -251,12 +263,12 @@
 }
 
 func (o OltDevice) oltChannels(stream openolt.Openolt_EnableIndicationServer) {
-
+	logger.Debug("Started OLT Indication Channel")
 	for message := range o.channel {
 
 		_msg, _ok := message.(Message)
 		if _ok {
-			log.WithFields(log.Fields{
+			logger.WithFields(log.Fields{
 				"oltId": o.ID,
 				"messageType": _msg.Type,
 			}).Debug("Received message")
@@ -283,10 +295,10 @@
 				onu.InternalState.Event("enable")
 				onu.sendOnuIndication(msg, stream)
 			default:
-				log.Warnf("Received unkown message data %v for type %v", _msg.Data, _msg.Type)
+				logger.Warnf("Received unkown message data %v for type %v", _msg.Data, _msg.Type)
 			}
 		} else {
-			log.Warnf("Received unkown message %v", message)
+			logger.Warnf("Received unkown message %v", message)
 		}
 
 	}
@@ -295,7 +307,7 @@
 // GRPC Endpoints
 
 func (o OltDevice) ActivateOnu(context context.Context, onu *openolt.Onu) (*openolt.Empty, error)  {
-	log.WithFields(log.Fields{
+	logger.WithFields(log.Fields{
 		"onuSerialNumber": onu.SerialNumber,
 	}).Info("Received ActivateOnu call from VOLTHA")
 	msg := Message{
@@ -311,58 +323,58 @@
 }
 
 func (o OltDevice) DeactivateOnu(context.Context, *openolt.Onu) (*openolt.Empty, error)  {
-	log.Error("DeactivateOnu not implemented")
+	logger.Error("DeactivateOnu not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) DeleteOnu(context.Context, *openolt.Onu) (*openolt.Empty, error)  {
-	log.Error("DeleteOnu not implemented")
+	logger.Error("DeleteOnu not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error)  {
-	log.Error("DisableOlt not implemented")
+	logger.Error("DisableOlt not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) DisablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error)  {
-	log.Error("DisablePonIf not implemented")
+	logger.Error("DisablePonIf not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) EnableIndication(_ *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error  {
-	log.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA")
+	logger.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA")
 	o.Enable(stream)
 	return nil
 }
 
 func (o OltDevice) EnablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error)  {
-	log.Error("EnablePonIf not implemented")
+	logger.Error("EnablePonIf not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) FlowAdd(context.Context, *openolt.Flow) (*openolt.Empty, error)  {
-	log.Error("FlowAdd not implemented")
+	logger.Error("FlowAdd not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) FlowRemove(context.Context, *openolt.Flow) (*openolt.Empty, error)  {
-	log.Error("FlowRemove not implemented")
+	logger.Error("FlowRemove not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error)  {
-	log.Error("HeartbeatCheck not implemented")
+	logger.Error("HeartbeatCheck not implemented")
 	return new(openolt.Heartbeat) , nil
 }
 
 func (o OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error)  {
 
-	log.WithField("oltId", o.ID).Info("OLT receives GetDeviceInfo call from VOLTHA")
+	logger.WithField("oltId", o.ID).Info("OLT receives GetDeviceInfo call from VOLTHA")
 	devinfo := new(openolt.DeviceInfo)
 	devinfo.Vendor = "BBSim"
 	devinfo.Model = "asfvolt16"
-	devinfo.HardwareVersion = ""
+	devinfo.HardwareVersion = "emulated"
 	devinfo.FirmwareVersion = ""
 	devinfo.Technology = "xgspon"
 	devinfo.PonPorts = 1
@@ -374,56 +386,57 @@
 	devinfo.GemportIdEnd = 65535
 	devinfo.FlowIdStart = 1
 	devinfo.FlowIdEnd = 16383
+	devinfo.DeviceSerialNumber = fmt.Sprintf("BBSIM_OLT_%d", o.ID)
 
 	return devinfo, nil
 }
 
 func (o OltDevice) OmciMsgOut(context.Context, *openolt.OmciMsg) (*openolt.Empty, error)  {
-	log.Error("OmciMsgOut not implemented")
+	logger.Error("OmciMsgOut not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) OnuPacketOut(context.Context, *openolt.OnuPacket) (*openolt.Empty, error)  {
-	log.Error("OnuPacketOut not implemented")
+	logger.Error("OnuPacketOut not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error)  {
-	log.Error("Reboot not implemented")
+	logger.Error("Reboot not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
-	log.Error("ReenableOlt not implemented")
+	logger.Error("ReenableOlt not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) UplinkPacketOut(context context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
-	log.Error("UplinkPacketOut not implemented")
+	logger.Error("UplinkPacketOut not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error)  {
-	log.Error("CollectStatistics not implemented")
+	logger.Error("CollectStatistics not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) CreateTconts(context context.Context, packet *openolt.Tconts) (*openolt.Empty, error) {
-	log.Error("CreateTconts not implemented")
+	logger.Error("CreateTconts not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) RemoveTconts(context context.Context, packet *openolt.Tconts) (*openolt.Empty, error) {
-	log.Error("RemoveTconts not implemented")
+	logger.Error("RemoveTconts not implemented")
 	return new(openolt.Empty) , nil
 }
 
 func (o OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuIndication, error) {
-	log.Error("GetOnuInfo not implemented")
+	logger.Error("GetOnuInfo not implemented")
 	return new(openolt.OnuIndication) , nil
 }
 
 func (o OltDevice) GetPonIf(context context.Context, packet *openolt.Interface) (*openolt.IntfIndication, error) {
-	log.Error("GetPonIf not implemented")
+	logger.Error("GetPonIf not implemented")
 	return new(openolt.IntfIndication) , nil
 }
\ No newline at end of file