VOL-5223:Alarm Mgr has to handle unconfigured MEs responses from ONT during Alarm Audit

Change-Id: I9d15232ab63c839d9d6e16ce342f9b8bbe0a3b21
diff --git a/internal/pkg/avcfg/omci_ani_config.go b/internal/pkg/avcfg/omci_ani_config.go
index 2e73349..8539c71 100755
--- a/internal/pkg/avcfg/omci_ani_config.go
+++ b/internal/pkg/avcfg/omci_ani_config.go
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-//Package avcfg provides anig and vlan configuration functionality
+// Package avcfg provides anig and vlan configuration functionality
 package avcfg
 
 import (
@@ -125,7 +125,7 @@
 	dynamicACL     string
 }
 
-//UniPonAniConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
+// UniPonAniConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
 type UniPonAniConfigFsm struct {
 	deviceID                 string
 	pDeviceHandler           cmn.IdeviceHandler
@@ -160,7 +160,7 @@
 	tcontSetBefore           bool
 }
 
-//NewUniPonAniConfigFsm is the 'constructor' for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
+// NewUniPonAniConfigFsm is the 'constructor' for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
 func NewUniPonAniConfigFsm(ctx context.Context, apDevOmciCC *cmn.OmciCC, apUniPort *cmn.OnuUniPort, apUniTechProf *OnuUniTechProf,
 	apOnuDB *devdb.OnuDeviceDB, aTechProfileID uint8, aTechProfileType string, aRequestEvent cmn.OnuDeviceEvent, aName string,
 	apDeviceHandler cmn.IdeviceHandler, apOnuDeviceEntry cmn.IonuDeviceEntry, aCommChannel chan cmn.Message) *UniPonAniConfigFsm {
@@ -271,14 +271,14 @@
 	return instFsm
 }
 
-//setFsmCompleteChannel sets the requested channel and channel result for transfer on success
+// setFsmCompleteChannel sets the requested channel and channel result for transfer on success
 func (oFsm *UniPonAniConfigFsm) setFsmCompleteChannel(aChSuccess chan<- uint8, aProcStep uint8) {
 	oFsm.chSuccess = aChSuccess
 	oFsm.procStep = aProcStep
 	oFsm.setChanSet(true)
 }
 
-//CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM
+// CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM
 func (oFsm *UniPonAniConfigFsm) CancelProcessing(ctx context.Context) {
 	logger.Info(ctx, "CancelProcessing entered", log.Fields{"device-id": oFsm.deviceID})
 	//early indication about started reset processing
@@ -325,8 +325,8 @@
 	oFsm.pUniTechProf.clearAniSideConfig(ctx, oFsm.pOnuUniPort.UniID, oFsm.techProfileID)
 }
 
-//nolint: gocyclo
-//TODO:visit here for refactoring for gocyclo
+// nolint: gocyclo
+// TODO:visit here for refactoring for gocyclo
 func (oFsm *UniPonAniConfigFsm) prepareAndEnterConfigState(ctx context.Context, aPAFsm *cmn.AdapterFsm) {
 	if aPAFsm != nil && aPAFsm.PFsm != nil {
 		var err error
@@ -459,6 +459,24 @@
 			}
 
 			oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs)
+			if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
+				meParams := me.ParamData{
+					EntityID: loGemPortAttribs.gemPortID,
+					Attributes: me.AttributeValueMap{
+						me.GemPortNetworkCtp_PortId:                              loGemPortAttribs.gemPortID,
+						me.GemPortNetworkCtp_TContPointer:                        oFsm.tcont0ID,
+						me.GemPortNetworkCtp_Direction:                           loGemPortAttribs.direction,
+						me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: loGemPortAttribs.upQueueID,
+						me.GemPortNetworkCtp_PriorityQueuePointerForDownStream:   loGemPortAttribs.downQueueID,
+					},
+				}
+				oFsm.pOnuDB.PutMe(ctx, me.GemPortNetworkCtpClassID, loGemPortAttribs.gemPortID, meParams.Attributes)
+				var meAttributes me.AttributeValueMap //dummy , anyways we are not going to use the values.
+				oFsm.pOnuDB.PutMe(ctx, me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID, loGemPortAttribs.gemPortID, meAttributes)
+
+				oFsm.pOnuDB.PutMe(ctx, me.GemInterworkingTerminationPointClassID, loGemPortAttribs.gemPortID, meAttributes)
+
+			}
 		}
 		if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
 			_ = aPAFsm.PFsm.Event(aniEvStartConfig)
@@ -853,6 +871,8 @@
 	}
 	oFsm.pLastTxMeInstance = meInstance
 	oFsm.mutexPLastTxMeInstance.Unlock()
+	logger.Infow(ctx, "Deleting  GemIWTP at  the ONU DB ", log.Fields{"device-id": oFsm.deviceID, "GEMID": loGemPortID})
+	oFsm.pOnuDB.DeleteMe(me.GemInterworkingTerminationPointClassID, loGemPortID)
 }
 
 func (oFsm *UniPonAniConfigFsm) enterWaitingFlowRem(ctx context.Context, e *fsm.Event) {
@@ -953,7 +973,7 @@
 	}
 	oFsm.pLastTxMeInstance = meInstance
 	oFsm.mutexPLastTxMeInstance.Unlock()
-
+	oFsm.pOnuDB.DeleteMe(me.GemPortNetworkCtpClassID, loGemPortID)
 	// Mark the gem port to be removed for Performance History monitoring
 	OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
 	if OnuMetricsManager != nil {
@@ -1509,6 +1529,7 @@
 			_ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
 			return
 		}
+		oFsm.pOnuDB.PutMe(ctx, me.GemPortNetworkCtpClassID, gemPortAttribs.gemPortID, meParams.Attributes)
 		// Mark the gem port to be added for Performance History monitoring
 		OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
 		if OnuMetricsManager != nil {
@@ -1538,10 +1559,11 @@
 			"SPPtr":     strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
 			"device-id": oFsm.deviceID})
 
+		var meParams me.ParamData
 		//TODO if the port has only downstream direction the isMulticast flag can be removed.
 		if gemPortAttribs.isMulticast {
 
-			meParams := me.ParamData{
+			meParams = me.ParamData{
 				EntityID: gemPortAttribs.multicastGemID,
 				Attributes: me.AttributeValueMap{
 					me.MulticastGemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.multicastGemID,
@@ -1605,7 +1627,7 @@
 			oFsm.mutexPLastTxMeInstance.Unlock()
 
 		} else {
-			meParams := me.ParamData{
+			meParams = me.ParamData{
 				EntityID: gemPortAttribs.gemPortID,
 				Attributes: me.AttributeValueMap{
 					me.GemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.gemPortID, //same as EntityID, see above
@@ -1638,6 +1660,9 @@
 			_ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
 			return
 		}
+		logger.Infow(ctx, "Adding GemIWTP to the ONU DB ", log.Fields{"device-id": oFsm.deviceID, "GEMID": gemPortAttribs.gemPortID})
+		oFsm.pOnuDB.PutMe(ctx, me.GemInterworkingTerminationPointClassID, gemPortAttribs.gemPortID, meParams.Attributes)
+
 	} //for all GemPort's of this T-Cont
 
 	// if Config has been done for all GemPort instances let the FSM proceed
diff --git a/internal/pkg/avcfg/omci_vlan_config.go b/internal/pkg/avcfg/omci_vlan_config.go
index d4bf25a..54be738 100755
--- a/internal/pkg/avcfg/omci_vlan_config.go
+++ b/internal/pkg/avcfg/omci_vlan_config.go
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-//Package avcfg provides anig and vlan configuration functionality
+// Package avcfg provides anig and vlan configuration functionality
 package avcfg
 
 import (
@@ -143,8 +143,9 @@
 	respChan         *chan error
 }
 
-//UniVlanConfigFsm defines the structure for the state machine for configuration of the VLAN related setting via OMCI
-//  builds upon 'VLAN rules' that are derived from multiple flows
+// UniVlanConfigFsm defines the structure for the state machine for configuration of the VLAN related setting via OMCI
+//
+//	builds upon 'VLAN rules' that are derived from multiple flows
 type UniVlanConfigFsm struct {
 	pDeviceHandler              cmn.IdeviceHandler
 	pOnuDeviceEntry             cmn.IonuDeviceEntry
@@ -184,8 +185,9 @@
 	lastFlowToReconcile bool
 }
 
-//NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports
-//  of ONU UNI ports via OMCI
+// NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports
+//
+//	of ONU UNI ports via OMCI
 func NewUniVlanConfigFsm(ctx context.Context, apDeviceHandler cmn.IdeviceHandler, apOnuDeviceEntry cmn.IonuDeviceEntry, apDevOmciCC *cmn.OmciCC, apUniPort *cmn.OnuUniPort,
 	apUniTechProf *OnuUniTechProf, apOnuDB *devdb.OnuDeviceDB, aTechProfileID uint8,
 	aRequestEvent cmn.OnuDeviceEvent, aName string, aCommChannel chan cmn.Message, aAcceptIncrementalEvto bool,
@@ -279,7 +281,7 @@
 	return instFsm
 }
 
-//initUniFlowParams is a simplified form of SetUniFlowParams() used for first flow parameters configuration
+// initUniFlowParams is a simplified form of SetUniFlowParams() used for first flow parameters configuration
 func (oFsm *UniVlanConfigFsm) initUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64,
 	aMatchVlan uint16, aMatchPcp uint8, aSetVlan uint16, aSetPcp uint8, innerCvlan uint16, aMeter *of.OfpMeterConfig, respChan *chan error) error {
 	loRuleParams := cmn.UniVlanRuleParams{
@@ -352,13 +354,13 @@
 	return nil
 }
 
-//CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM
+// CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM
 func (oFsm *UniVlanConfigFsm) CancelProcessing(ctx context.Context) {
-	logger.Debugw(ctx, "CancelProcessing entered", log.Fields{"device-id": oFsm.deviceID})
 	if oFsm == nil {
 		logger.Error(ctx, "no valid UniVlanConfigFsm!")
 		return
 	}
+	logger.Debugw(ctx, "CancelProcessing entered", log.Fields{"device-id": oFsm.deviceID})
 	//mutex protection is required for possible concurrent access to FSM members
 	oFsm.mutexIsAwaitingResponse.Lock()
 	oFsm.isCanceled = true
@@ -382,7 +384,7 @@
 	}
 }
 
-//GetWaitingTpID returns the TpId that the FSM might be waiting for continuation (0 if none)
+// GetWaitingTpID returns the TpId that the FSM might be waiting for continuation (0 if none)
 func (oFsm *UniVlanConfigFsm) GetWaitingTpID(ctx context.Context) uint8 {
 	if oFsm == nil {
 		logger.Error(ctx, "no valid UniVlanConfigFsm!")
@@ -394,7 +396,7 @@
 	return oFsm.TpIDWaitingFor
 }
 
-//SetUniFlowParams verifies on existence of flow parameters to be configured,
+// SetUniFlowParams verifies on existence of flow parameters to be configured,
 // optionally udates the cookie list or appends a new flow if there is space
 // if possible the FSM is trigggerd to start with the processing
 // ignore complexity by now
@@ -784,7 +786,7 @@
 	return delayedCookie, deleteSuccess
 }
 
-//returns flowModified, RuleAppendRequest
+// returns flowModified, RuleAppendRequest
 func (oFsm *UniVlanConfigFsm) reviseFlowConstellation(ctx context.Context, aCookie uint64, aUniVlanRuleParams cmn.UniVlanRuleParams) (bool, bool) {
 	flowEntryMatch := false
 	oFsm.mutexFlowParams.Lock()
@@ -822,7 +824,7 @@
 
 // VOL-3828 flow config sequence workaround ###########  end ##########
 
-//RemoveUniFlowParams verifies on existence of flow cookie,
+// RemoveUniFlowParams verifies on existence of flow cookie,
 // if found removes cookie from flow cookie list and if this is empty
 // initiates removal of the flow related configuration from the ONU (via OMCI)
 func (oFsm *UniVlanConfigFsm) RemoveUniFlowParams(ctx context.Context, aCookie uint64, respChan *chan error) error {
@@ -994,10 +996,12 @@
 	return true
 }
 
-//removeFlowFromParamsSlice removes a flow from stored  uniVlanFlowParamsSlice based on the cookie
-//  it assumes that adding cookies for this flow (including the actual one to delete) was prevented
-//  from the start of the deletion request to avoid to much interference
-//  so when called, there can only be one cookie active for this flow
+// removeFlowFromParamsSlice removes a flow from stored  uniVlanFlowParamsSlice based on the cookie
+//
+//	it assumes that adding cookies for this flow (including the actual one to delete) was prevented
+//	from the start of the deletion request to avoid to much interference
+//	so when called, there can only be one cookie active for this flow
+//
 // requires mutexFlowParams to be locked at call
 func (oFsm *UniVlanConfigFsm) removeFlowFromParamsSlice(ctx context.Context, aCookie uint64, aWasConfigured bool) error {
 	logger.Debugw(ctx, "UniVlanConfigFsm flow removal from ParamsSlice", log.Fields{