Correction on .1pMapper create and improvement PPPTEthUni/VEIP handling

Signed-off-by: mpagenko <michael.pagenkopf@adtran.com>
Change-Id: I370b8cd7c95d33e8fc5fbfb271ae31192fd1aee9
diff --git a/VERSION b/VERSION
index 49a2f78..a571453 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.1.0-dev153
+1.1.0-dev154
diff --git a/internal/pkg/onuadaptercore/device_handler.go b/internal/pkg/onuadaptercore/device_handler.go
index b0908f0..a4da535 100644
--- a/internal/pkg/onuadaptercore/device_handler.go
+++ b/internal/pkg/onuadaptercore/device_handler.go
@@ -1526,19 +1526,21 @@
 		return
 	}
 	i := uint8(0) //UNI Port limit: see MaxUnisPerOnu (by now 16) (OMCI supports max 255 p.b.)
-	if unigInstKeys := pDevEntry.pOnuDB.getSortedInstKeys(ctx, me.UniGClassID); len(unigInstKeys) > 0 {
-		for _, mgmtEntityID := range unigInstKeys {
-			logger.Debugw(ctx, "Add UNI port for stored UniG instance:", log.Fields{
-				"device-id": dh.deviceID, "UnigMe EntityID": mgmtEntityID})
+	if pptpInstKeys := pDevEntry.pOnuDB.getSortedInstKeys(
+		ctx, me.PhysicalPathTerminationPointEthernetUniClassID); len(pptpInstKeys) > 0 {
+		for _, mgmtEntityID := range pptpInstKeys {
+			logger.Debugw(ctx, "Add PPTPEthUni port for MIB-stored instance:", log.Fields{
+				"device-id": dh.deviceID, "PPTPEthUni EntityID": mgmtEntityID})
 			dh.addUniPort(ctx, mgmtEntityID, i, uniPPTP)
 			i++
 		}
 	} else {
 		logger.Debugw(ctx, "No UniG instances found", log.Fields{"device-id": dh.deviceID})
 	}
-	if veipInstKeys := pDevEntry.pOnuDB.getSortedInstKeys(ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 {
+	if veipInstKeys := pDevEntry.pOnuDB.getSortedInstKeys(
+		ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 {
 		for _, mgmtEntityID := range veipInstKeys {
-			logger.Debugw(ctx, "Add VEIP acc. to stored VEIP instance:", log.Fields{
+			logger.Debugw(ctx, "Add VEIP for MIB-stored instance:", log.Fields{
 				"device-id": dh.deviceID, "VEIP EntityID": mgmtEntityID})
 			dh.addUniPort(ctx, mgmtEntityID, i, uniVEIP)
 			i++
diff --git a/internal/pkg/onuadaptercore/omci_ani_config.go b/internal/pkg/onuadaptercore/omci_ani_config.go
index e04f8c7..fdd7830 100644
--- a/internal/pkg/onuadaptercore/omci_ani_config.go
+++ b/internal/pkg/onuadaptercore/omci_ani_config.go
@@ -562,10 +562,14 @@
 				"device-id": oFsm.deviceID})
 		} else {
 			// The null pointer 0xFFFF specifies that frames with the associated priority are to be discarded.
+			// setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
+			// but except for processing effort does not really harm - left to keep changes low
 			meParams.Attributes[meAttribute] = 0xffff
 		}
 	}
 	// The TP type value 0 also indicates bridging mapping, and the TP pointer should be set to 0xFFFF
+	// setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
+	// but except for processing effort does not really harm - left to keep changes low
 	meParams.Attributes["TpPointer"] = 0xffff
 
 	if !foundIwPtr {
diff --git a/internal/pkg/onuadaptercore/omci_cc.go b/internal/pkg/onuadaptercore/omci_cc.go
index 8d6d4ef..c8ad45f 100644
--- a/internal/pkg/onuadaptercore/omci_cc.go
+++ b/internal/pkg/onuadaptercore/omci_cc.go
@@ -1187,8 +1187,19 @@
 		"SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(aInstID), 16)})
 
 	meParams := me.ParamData{
-		EntityID:   aInstID,
-		Attributes: me.AttributeValueMap{},
+		EntityID: aInstID,
+		Attributes: me.AttributeValueMap{
+			//workaround for unsuitable omci-lib default values, cmp VOL-3729
+			"TpPointer":                          0xFFFF,
+			"InterworkTpPointerForPBitPriority0": 0xFFFF,
+			"InterworkTpPointerForPBitPriority1": 0xFFFF,
+			"InterworkTpPointerForPBitPriority2": 0xFFFF,
+			"InterworkTpPointerForPBitPriority3": 0xFFFF,
+			"InterworkTpPointerForPBitPriority4": 0xFFFF,
+			"InterworkTpPointerForPBitPriority5": 0xFFFF,
+			"InterworkTpPointerForPBitPriority6": 0xFFFF,
+			"InterworkTpPointerForPBitPriority7": 0xFFFF,
+		},
 	}
 	meInstance, omciErr := me.NewIeee8021PMapperServiceProfile(meParams)
 	if omciErr.GetError() == nil {
diff --git a/internal/pkg/onuadaptercore/uniportadmin.go b/internal/pkg/onuadaptercore/uniportadmin.go
index 7f361c9..d05843a 100644
--- a/internal/pkg/onuadaptercore/uniportadmin.go
+++ b/internal/pkg/onuadaptercore/uniportadmin.go
@@ -211,7 +211,7 @@
 }
 
 func (oFsm *lockStateFsm) enterSettingUnisState(ctx context.Context, e *fsm.Event) {
-	logger.Debugw(ctx, "LockStateFSM - starting PPTP config loop", log.Fields{
+	logger.Debugw(ctx, "LockStateFSM - starting UniTP adminState loop", log.Fields{
 		"in state": e.FSM.Current(), "device-id": oFsm.deviceID, "LockState": oFsm.adminState})
 	go oFsm.performUniPortAdminSet(ctx)
 }
@@ -348,36 +348,41 @@
 	requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState}
 
 	for uniNo, uniPort := range oFsm.pOmciCC.pBaseDeviceHandler.uniEntityMap {
-		logger.Debugw(ctx, "Setting PPTP admin state", log.Fields{
-			"device-id": oFsm.deviceID, "for PortNo": uniNo})
+		// only unlock the UniPort in case it is defined for usage (R2.6 limit only one port),
+		// compare also limitation for logical voltha port in dh.enableUniPortStateUpdate()
+		if (omciAdminState == 1) || (1<<uniPort.uniID)&activeUniPortStateUpdateMask == (1<<uniPort.uniID) {
+			var meInstance *me.ManagedEntity
+			if uniPort.portType == uniPPTP {
+				logger.Debugw(ctx, "Setting PPTP admin state", log.Fields{
+					"device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState})
+				meInstance = oFsm.pOmciCC.sendSetPptpEthUniLS(log.WithSpanFromContext(context.TODO(), ctx), uniPort.entityID, ConstDefaultOmciTimeout,
+					true, requestedAttributes, oFsm.pAdaptFsm.commChan)
+				oFsm.pLastTxMeInstance = meInstance
+			} else if uniPort.portType == uniVEIP {
+				logger.Debugw(ctx, "Setting VEIP admin state", log.Fields{
+					"device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState})
+				meInstance = oFsm.pOmciCC.sendSetVeipLS(log.WithSpanFromContext(context.TODO(), ctx), uniPort.entityID, ConstDefaultOmciTimeout,
+					true, requestedAttributes, oFsm.pAdaptFsm.commChan)
+				oFsm.pLastTxMeInstance = meInstance
+			} else {
+				logger.Warnw(ctx, "Unsupported UniTP type - skip",
+					log.Fields{"device-id": oFsm.deviceID, "Port": uniNo})
+				continue
+			}
 
-		var meInstance *me.ManagedEntity
-		if uniPort.portType == uniPPTP {
-			meInstance = oFsm.pOmciCC.sendSetPptpEthUniLS(log.WithSpanFromContext(context.TODO(), ctx), uniPort.entityID, ConstDefaultOmciTimeout,
-				true, requestedAttributes, oFsm.pAdaptFsm.commChan)
-			oFsm.pLastTxMeInstance = meInstance
-		} else if uniPort.portType == uniVEIP {
-			meInstance = oFsm.pOmciCC.sendSetVeipLS(log.WithSpanFromContext(context.TODO(), ctx), uniPort.entityID, ConstDefaultOmciTimeout,
-				true, requestedAttributes, oFsm.pAdaptFsm.commChan)
-			oFsm.pLastTxMeInstance = meInstance
-		} else {
-			logger.Warnw(ctx, "Unsupported PPTP type - skip",
-				log.Fields{"device-id": oFsm.deviceID, "Port": uniNo})
-			continue
-		}
-
-		//verify response
-		err := oFsm.waitforOmciResponse(ctx, meInstance)
-		if err != nil {
-			logger.Errorw(ctx, "PPTP Admin State set failed, aborting LockState set!",
-				log.Fields{"device-id": oFsm.deviceID, "Port": uniNo})
-			_ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset)
-			return
+			//verify response
+			err := oFsm.waitforOmciResponse(ctx, meInstance)
+			if err != nil {
+				logger.Errorw(ctx, "UniTP Admin State set failed, aborting LockState set!",
+					log.Fields{"device-id": oFsm.deviceID, "Port": uniNo})
+				_ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset)
+				return
+			}
 		}
 	} //for all UNI ports
 	// if Config has been done for all UNI related instances let the FSM proceed
 	// while we did not check here, if there is some port at all - !?
-	logger.Infow(ctx, "PPTP config loop finished", log.Fields{"device-id": oFsm.deviceID})
+	logger.Infow(ctx, "UniTP adminState loop finished", log.Fields{"device-id": oFsm.deviceID})
 	_ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp)
 }