[VOL-3819] Reporting correct serial number via OMCI Get Onu-g message

Change-Id: I91151ab1890ac70d4e1ad9b6b6ce2c4509822828
diff --git a/VERSION b/VERSION
index bc80560..ec802c6 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.5.0
+1.5.1-dev
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index 822ec6b..36fbb3e 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -650,7 +650,7 @@
 	case omci.MibUploadNextRequestType:
 		responsePkt, _ = omcilib.CreateMibUploadNextResponse(omciPkt, omciMsg)
 	case omci.GetRequestType:
-		responsePkt, _ = omcilib.CreateGetResponse(omciPkt, omciMsg)
+		responsePkt, _ = omcilib.CreateGetResponse(omciPkt, omciMsg, o.SerialNumber)
 	case omci.SetRequestType:
 		responsePkt, _ = omcilib.CreateSetResponse(omciPkt, omciMsg)
 
@@ -721,7 +721,6 @@
 				}).Error("send-TestResult-indication-failed")
 			}
 		}
-
 	default:
 		log.WithFields(log.Fields{
 			"omciMsgType":  omciMsg.MessageType,
diff --git a/internal/common/omci/get.go b/internal/common/omci/get.go
index 64a7968..78aa98e 100644
--- a/internal/common/omci/get.go
+++ b/internal/common/omci/get.go
@@ -23,6 +23,7 @@
 	"github.com/google/gopacket"
 	"github.com/opencord/omci-lib-go"
 	me "github.com/opencord/omci-lib-go/generated"
+	"github.com/opencord/voltha-protos/v4/go/openolt"
 	log "github.com/sirupsen/logrus"
 	"strconv"
 )
@@ -43,7 +44,7 @@
 	return msgObj, nil
 }
 
-func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI) ([]byte, error) {
+func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, onuSn *openolt.SerialNumber) ([]byte, error) {
 
 	msgObj, err := ParseGetRequest(omciPkt)
 
@@ -62,7 +63,7 @@
 	case me.Onu2GClassID:
 		response = createOnu2gResponse(msgObj.AttributeMask, msgObj.EntityInstance)
 	case me.OnuGClassID:
-		response = createOnugResponse(msgObj.AttributeMask, msgObj.EntityInstance)
+		response = createOnugResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuSn)
 	case me.SoftwareImageClassID:
 		response = createSoftwareImageResponse(msgObj.AttributeMask, msgObj.EntityInstance)
 	case me.IpHostConfigDataClassID:
@@ -139,17 +140,15 @@
 	}
 }
 
-func createOnugResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
-	return &omci.GetResponse{
-		MeBasePacket: omci.MeBasePacket{
-			EntityClass:    me.OnuGClassID,
-			EntityInstance: entityID,
-		},
+func createOnugResponse(attributeMask uint16, entityID uint16, onuSn *openolt.SerialNumber) *omci.GetResponse {
+
+	managedEntity, meErr := me.NewOnuG(me.ParamData{
+		EntityID: entityID,
 		Attributes: me.AttributeValueMap{
 			"ManagedEntityId":         entityID,
 			"VendorId":                toOctets("BBSM", 4),
 			"Version":                 toOctets("v0.0.1", 14),
-			"SerialNumber":            toOctets("QkJTTQAKAAE=", 8),
+			"SerialNumber":            append(onuSn.VendorId, onuSn.VendorSpecific...),
 			"TrafficManagementOption": 0,
 			"Deprecated":              0,
 			"BatteryBackup":           0,
@@ -161,9 +160,33 @@
 			"CredentialsStatus":       0,
 			"ExtendedTcLayerOptions":  0,
 		},
-		Result:        me.Success,
-		AttributeMask: attributeMask,
+	})
+
+	if meErr.GetError() != nil {
+		omciLogger.Errorf("NewOnu2G %v", meErr.Error())
+		return nil
 	}
+
+	return &omci.GetResponse{
+		MeBasePacket: omci.MeBasePacket{
+			EntityClass: me.OnuGClassID,
+		},
+		Attributes:    managedEntity.GetAttributeValueMap(),
+		AttributeMask: attributeMask,
+		Result:        me.Success,
+	}
+
+	//return &omci.GetResponse{
+	//	MeBasePacket: omci.MeBasePacket{
+	//		EntityClass:    me.OnuGClassID,
+	//		EntityInstance: entityID,
+	//	},
+	//	Attributes: me.AttributeValueMap{
+	//
+	//	},
+	//	Result:        me.Success,
+	//	AttributeMask: attributeMask,
+	//}
 }
 
 func createSoftwareImageResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse {
diff --git a/internal/common/omci/get_test.go b/internal/common/omci/get_test.go
index 0ab6d04..7ba494b 100644
--- a/internal/common/omci/get_test.go
+++ b/internal/common/omci/get_test.go
@@ -17,9 +17,12 @@
 package omci
 
 import (
+	"encoding/hex"
+	"fmt"
 	"github.com/google/gopacket"
 	"github.com/opencord/omci-lib-go"
 	me "github.com/opencord/omci-lib-go/generated"
+	"github.com/opencord/voltha-protos/v4/go/openolt"
 	"gotest.tools/assert"
 	"testing"
 )
@@ -73,7 +76,11 @@
 }
 
 func TestCreateOnugResponse(t *testing.T) {
-	response := createOnugResponse(40960, 1)
+	sn := &openolt.SerialNumber{
+		VendorId:       []byte("BBSM"),
+		VendorSpecific: []byte{0, byte(1 % 256), byte(1), byte(1)},
+	}
+	response := createOnugResponse(40960, 1, sn)
 	data, _ := serialize(omci.GetResponseType, response, 1)
 
 	omciMsg, omciPkt := omciBytesToMsg(t, data)
@@ -83,4 +90,9 @@
 	getResponseLayer := omciToGetResponse(t, omciPkt)
 
 	assert.Equal(t, getResponseLayer.Result, me.Success)
+	snBytes := (getResponseLayer.Attributes["SerialNumber"]).([]byte)
+	snVendorPart := fmt.Sprintf("%s", snBytes[:4])
+	snNumberPart := hex.EncodeToString(snBytes[4:])
+	serialNumber := snVendorPart + snNumberPart
+	assert.Equal(t, serialNumber, "BBSM00010101")
 }