[VOL-3604] flow/techProfile handling after ONU reboot/down/disable must be revised -> version 0.1.13-dev137

Signed-off-by: mpagenko <michael.pagenkopf@adtran.com>
Change-Id: I8bd846170d62f15c3a83ce6b10911707e0cd6176
diff --git a/internal/pkg/onuadaptercore/onu_device_entry.go b/internal/pkg/onuadaptercore/onu_device_entry.go
index 27c0865..ad683b0 100644
--- a/internal/pkg/onuadaptercore/onu_device_entry.go
+++ b/internal/pkg/onuadaptercore/onu_device_entry.go
@@ -118,29 +118,33 @@
 	// Events of interest to Device Adapters and OpenOMCI State Machines
 
 	// DeviceStatusInit - default start state
-	DeviceStatusInit OnuDeviceEvent = 0
+	DeviceStatusInit OnuDeviceEvent = iota
 	// MibDatabaseSync - MIB database sync (upload done)
-	MibDatabaseSync OnuDeviceEvent = 1
+	MibDatabaseSync
 	// OmciCapabilitiesDone - OMCI ME and message type capabilities known
-	OmciCapabilitiesDone OnuDeviceEvent = 2
+	OmciCapabilitiesDone
 	// MibDownloadDone - // MIB download done
-	MibDownloadDone OnuDeviceEvent = 3
+	MibDownloadDone
 	// UniLockStateDone - Uni ports admin set to lock
-	UniLockStateDone OnuDeviceEvent = 4
+	UniLockStateDone
 	// UniUnlockStateDone - Uni ports admin set to unlock
-	UniUnlockStateDone OnuDeviceEvent = 5
+	UniUnlockStateDone
 	// UniDisableStateDone - Uni ports admin set to lock based on device disable
-	UniDisableStateDone OnuDeviceEvent = 6
+	UniDisableStateDone
 	// UniEnableStateDone - Uni ports admin set to unlock based on device re-enable
-	UniEnableStateDone OnuDeviceEvent = 7
+	UniEnableStateDone
 	// PortLinkUp - Port link state change
-	PortLinkUp OnuDeviceEvent = 8
+	PortLinkUp
 	// PortLinkDw - Port link state change
-	PortLinkDw OnuDeviceEvent = 9
+	PortLinkDw
 	// OmciAniConfigDone -  AniSide config according to TechProfile done
-	OmciAniConfigDone OnuDeviceEvent = 10
-	// OmciVlanFilterDone - Omci Vlan config according to flowConfig done
-	OmciVlanFilterDone OnuDeviceEvent = 11
+	OmciAniConfigDone
+	// OmciAniResourceRemoved - AniSide TechProfile related resource (Gem/TCont) removed
+	OmciAniResourceRemoved // needs to be the successor of OmciAniConfigDone!
+	// OmciVlanFilterAddDone - Omci Vlan config done according to flow-add
+	OmciVlanFilterAddDone
+	// OmciVlanFilterRemDone - Omci Vlan config done according to flow-remove
+	OmciVlanFilterRemDone // needs to be the successor of OmciVlanFilterAddDone!
 	// Add other events here as needed (alarms separate???)
 )
 
@@ -646,8 +650,28 @@
 				return true
 			}
 			//entry already exists
-			logger.Debugw("UniTp path already exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
-			return false
+			if aPathString == "" {
+				//no active TechProfile
+				logger.Debugw("UniTp path has already been removed - no AniSide config to be removed", log.Fields{
+					"device-id": oo.deviceID, "uniID": aUniID})
+				// attention 201105: this block is at the moment entered for each of subsequent GemPortDeletes and TContDelete
+				//   as the path is already cleared with the first GemPort - this will probably change with the upcoming real
+				//   TechProfile removal (still TODO), but anyway the reasonUpdate initiated here should not harm overall behavior
+				go oo.baseDeviceHandler.deviceProcStatusUpdate(OmciAniResourceRemoved)
+				// no flow config pending on 'remove' so far
+			} else {
+				//the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here
+				//was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU
+				//  (as here the TechProfile has not been removed with the disable-device before the new enable-device)
+				logger.Debugw("UniTp path already exists - TechProfile supposed to be active", log.Fields{
+					"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString})
+				//no deviceReason update (deviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario
+				//  (during which the flows are removed/re-assigned but the techProf is left active)
+				//and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it
+				//  (should not be the case, but should not harm or be more robust ...)
+				go oo.baseDeviceHandler.VerifyVlanConfigRequest(aUniID)
+			}
+			return false //indicate 'no change' - nothing more to do, TechProf inter-adapter message is return with success anyway here
 		}
 	}
 	//no entry exists for uniId
@@ -664,25 +688,6 @@
 	return true
 }
 
-// deleteTpResource removes Resources from the ONU's specified Uni
-func (oo *OnuDeviceEntry) deleteTpResource(ctx context.Context,
-	aUniID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
-	wg *sync.WaitGroup) {
-	defer wg.Done()
-	logger.Debugw("this would remove TP resources from ONU's UNI", log.Fields{
-		"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource})
-	//TODO!!!
-	//delete the given resource from ONU OMCI config and data base - as background routine
-	/*
-		var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
-		go onuTp.deleteAniResource(ctx, processingStep)
-		if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
-			//timeout or error detected
-			return
-		}
-	*/
-}
-
 func (oo *OnuDeviceEntry) updateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]uniVlanFlowParams) {
 
 	for k, v := range oo.sOnuPersistentData.PersUniConfig {