VOL-4013: Delivery of correct ONU pm-data for UNI_Status

Change-Id: I286c10ef08f8dfd1273aef094cbce60ecc4ab879
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index a8d67d6..466f383 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -749,7 +749,8 @@
 	case omci.MibUploadNextRequestType:
 		responsePkt, _ = omcilib.CreateMibUploadNextResponse(msg.OmciPkt, msg.OmciMsg, o.MibDataSync)
 	case omci.GetRequestType:
-		responsePkt, _ = omcilib.CreateGetResponse(msg.OmciPkt, msg.OmciMsg, o.SerialNumber, o.MibDataSync, o.ActiveImageEntityId, o.CommittedImageEntityId)
+		onuDown := o.OperState.Current() == "down"
+		responsePkt, _ = omcilib.CreateGetResponse(msg.OmciPkt, msg.OmciMsg, o.SerialNumber, o.MibDataSync, o.ActiveImageEntityId, o.CommittedImageEntityId, onuDown)
 	case omci.SetRequestType:
 		success := true
 		msgObj, _ := omcilib.ParseSetRequest(msg.OmciPkt)
@@ -767,6 +768,23 @@
 				raiseOMCIAlarm := false
 				if adminState == 1 {
 					raiseOMCIAlarm = true
+					// set the OperState to disabled
+					if err := o.OperState.Event(OnuTxDisable); err != nil {
+						onuLogger.WithFields(log.Fields{
+							"OnuId":  o.ID,
+							"IntfId": o.PonPortID,
+							"OnuSn":  o.Sn(),
+						}).Errorf("Cannot change ONU OperState to down: %s", err.Error())
+					}
+				} else {
+					// set the OperState to enabled
+					if err := o.OperState.Event(OnuTxEnable); err != nil {
+						onuLogger.WithFields(log.Fields{
+							"OnuId":  o.ID,
+							"IntfId": o.PonPortID,
+							"OnuSn":  o.Sn(),
+						}).Errorf("Cannot change ONU OperState to up: %s", err.Error())
+					}
 				}
 				msg := bbsim.Message{
 					Type: bbsim.UniStatusAlarm,
diff --git a/internal/common/omci/get.go b/internal/common/omci/get.go
index 4b02bda..67a65ff 100644
--- a/internal/common/omci/get.go
+++ b/internal/common/omci/get.go
@@ -45,7 +45,7 @@
 	return msgObj, nil
 }
 
-func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, onuSn *openolt.SerialNumber, mds uint8, activeImageEntityId uint16, committedImageEntityId uint16) ([]byte, error) {
+func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, onuSn *openolt.SerialNumber, mds uint8, activeImageEntityId uint16, committedImageEntityId uint16, onuDown bool) ([]byte, error) {
 
 	msgObj, err := ParseGetRequest(omciPkt)
 
@@ -70,9 +70,9 @@
 	case me.IpHostConfigDataClassID:
 		response = createIpHostResponse(msgObj.AttributeMask, msgObj.EntityInstance)
 	case me.UniGClassID:
-		response = createUnigResponse(msgObj.AttributeMask, msgObj.EntityInstance)
+		response = createUnigResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
 	case me.PhysicalPathTerminationPointEthernetUniClassID:
-		response = createPptpResponse(msgObj.AttributeMask, msgObj.EntityInstance)
+		response = createPptpResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
 	case me.AniGClassID:
 		response = createAnigResponse(msgObj.AttributeMask, msgObj.EntityInstance)
 	case me.OnuDataClassID:
@@ -260,13 +260,18 @@
 	}
 }
 
-func createUnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
+func createUnigResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
+	// Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
+	omciAdminState := 1
+	if !onuDown {
+		omciAdminState = 0
+	}
 	managedEntity, meErr := me.NewUniG(me.ParamData{
 		EntityID: entityID,
 		Attributes: me.AttributeValueMap{
 			"ManagedEntityId":             entityID,
 			"Deprecated":                  0,
-			"AdministrativeState":         0,
+			"AdministrativeState":         omciAdminState,
 			"ManagementCapability":        0,
 			"NonOmciManagementIdentifier": 1,
 			"RelayAgentOptions":           1,
@@ -289,7 +294,14 @@
 	}
 }
 
-func createPptpResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
+func createPptpResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
+	// Valid values for oper_state are 0 (enabled) and 1 (disabled)
+	// Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
+	onuAdminState := 1
+	if !onuDown {
+		onuAdminState = 0
+	}
+	onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state
 	managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{
 		EntityID: entityID,
 		Attributes: me.AttributeValueMap{
@@ -298,8 +310,8 @@
 			"SensedType":                    0,
 			"AutoDetectionConfiguration":    0,
 			"EthernetLoopbackConfiguration": 0,
-			"AdministrativeState":           0,
-			"OperationalState":              0,
+			"AdministrativeState":           onuAdminState,
+			"OperationalState":              onuOperState,
 			"ConfigurationInd":              0,
 			"MaxFrameSize":                  0,
 			"DteOrDceInd":                   0,