SEBA-506 BBSIM - omci handler for new TP flows
BBSim changed the way to get GemPortID.

Change-Id: Ie8a2d7c4b41204f71da7a3fa97e90cfea10295fc
diff --git a/core/core_server.go b/core/core_server.go
index 170c152..50a2224 100644
--- a/core/core_server.go
+++ b/core/core_server.go
@@ -433,7 +433,7 @@
 		case msg := <- s.eapolIn:
 			intfid := msg.IntfId
 			onuid := msg.OnuId
-			gemid, err := getGemPortID(intfid, onuid)
+			gemid, err := s.getGemPortID(intfid, onuid)
 			if err != nil {
 				logger.Error("Failed to getGemPortID intfid:%d onuid:%d", intfid, onuid)
 				continue
@@ -449,7 +449,7 @@
 		case msg := <- s.dhcpIn:	//TODO: We should put omciIn, eapolIn, dhcpIn toghether
 			intfid := msg.IntfId
 			onuid := msg.OnuId
-			gemid, err := getGemPortID(intfid, onuid)
+			gemid, err := s.getGemPortID(intfid, onuid)
 			bytes := msg.Byte
 			pkt := gopacket.NewPacket(bytes, layers.LayerTypeEthernet, gopacket.Default)
 
@@ -593,13 +593,18 @@
 	return true
 }
 
-func getGemPortID(intfid uint32, onuid uint32) (uint32, error) {
+func (s *Server) getGemPortID(intfid uint32, onuid uint32) (uint32, error) {
 	logger.Debug("getGemPortID(intfid:%d, onuid:%d)", intfid, onuid)
 	gemportid, err := omci.GetGemPortId(intfid, onuid)
 	if err != nil {
-		logger.Error("%s", err)
+		logger.Warn("Failed to getGemPortID from OMCI lib: %s", err)
+	}
+	onu, err := s.GetOnuByID(onuid)
+	if err != nil {
+		logger.Error("Failed to getGemPortID: %s", err)
 		return 0, err
 	}
+	gemportid = onu.GemportID
 	return uint32(gemportid), nil
 }
 
diff --git a/core/grpc_service.go b/core/grpc_service.go
index 5f927d9..7a66fc0 100644
--- a/core/grpc_service.go
+++ b/core/grpc_service.go
@@ -142,12 +142,13 @@
 }
 
 func (s *Server) FlowAdd(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
-	logger.Debug("OLT %d receives FlowAdd() IntfID:%d OnuID:%d EType:%x:.", s.Olt.ID, flow.AccessIntfId, flow.OnuId, flow.Classifier.EthType)
+	logger.Debug("OLT %d receives FlowAdd() IntfID:%d OnuID:%d EType:%x GemPortID:%d", s.Olt.ID, flow.AccessIntfId, flow.OnuId, flow.Classifier.EthType, flow.GemportId)
 	onu, err := s.GetOnuByID(uint32(flow.OnuId))
 
 	if err == nil {
 		intfid := onu.IntfID
 		onuid := onu.OnuID
+		onu.GemportID = uint16(flow.GemportId)
 
 		utils.LoggerWithOnu(onu).WithFields(log.Fields{
 			"olt":   s.Olt.ID,
@@ -156,11 +157,10 @@
 
 		if flow.Classifier.EthType == uint32(layers.EthernetTypeEAPOL) {
 			omcistate := omci.GetOnuOmciState(onu.IntfID, onu.OnuID)
-			if omcistate == omci.DONE {
-				s.updateOnuIntState(intfid, onuid, device.ONU_OMCIACTIVE)
-			} else {
-				logger.Error("FlowAdd() OMCI state %d is not \"DONE\"", omci.GetOnuOmciState(onu.OnuID, onu.IntfID))
+			if omcistate != omci.DONE {
+				logger.Warn("FlowAdd() OMCI state %d is not \"DONE\"", omci.GetOnuOmciState(onu.OnuID, onu.IntfID))
 			}
+			s.updateOnuIntState(intfid, onuid, device.ONU_OMCIACTIVE)
 		}
 	}
 	return new(openolt.Empty), nil
diff --git a/device/device_onu.go b/device/device_onu.go
index 79a4be2..c8e0c4d 100644
--- a/device/device_onu.go
+++ b/device/device_onu.go
@@ -38,6 +38,7 @@
 	OperState     string
 	SerialNumber  *openolt.SerialNumber
 	OnuID         uint32
+	GemportID     uint16
 	mu            *sync.Mutex
 }
 
@@ -58,6 +59,7 @@
 		onu.SerialNumber = new(openolt.SerialNumber)
 		onu.SerialNumber.VendorId = []byte("BBSM")
 		onu.SerialNumber.VendorSpecific = NewSN(oltid, intfid, uint32(i))
+		onu.GemportID = 0
 		onus = append(onus, &onu)
 	}
 	return onus