[VOL-3628] ATT scenario subscriber add/remove: synchronized flow and tech profile handling + correction clear persistent data

Signed-off-by: mpagenko <michael.pagenkopf@adtran.com>
Change-Id: Id77ba0e8b537b49663439f86b0d84734dba6cf23
diff --git a/internal/pkg/onuadaptercore/onu_uni_tp.go b/internal/pkg/onuadaptercore/onu_uni_tp.go
index 97b4dbd..2e19274 100644
--- a/internal/pkg/onuadaptercore/onu_uni_tp.go
+++ b/internal/pkg/onuadaptercore/onu_uni_tp.go
@@ -54,6 +54,7 @@
 	techProfileType       string
 	techProfileID         uint16
 	techProfileConfigDone bool
+	techProfileToDelete   bool
 }
 
 type tcontParamStruct struct {
@@ -297,6 +298,7 @@
 	//note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
 	onuTP.mapUniTpIndication[aUniID].techProfileID = uint16(profID)
 	onuTP.mapUniTpIndication[aUniID].techProfileConfigDone = false
+	onuTP.mapUniTpIndication[aUniID].techProfileToDelete = false
 	logger.Debugw("tech-profile path indications",
 		log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
 			"profType": onuTP.mapUniTpIndication[aUniID].techProfileType,
@@ -569,9 +571,23 @@
 		if onuTP.mapUniTpIndication[aUniID].techProfileID == aTpID {
 			onuTP.mutexTPState.Lock()
 			defer onuTP.mutexTPState.Unlock()
+			if onuTP.mapUniTpIndication[aUniID].techProfileToDelete {
+				logger.Debugw("TechProfile not relevant for requested flow config - waiting on delete",
+					log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
+				return false //still waiting for removal of this techProfile first
+			}
 			return onuTP.mapUniTpIndication[aUniID].techProfileConfigDone
 		}
 	}
 	//for all other constellations indicate false = Config not done
 	return false
 }
+
+// setProfileToDelete sets the requested techProfile toDelete state (if possible)
+func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aState bool) {
+	if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP {
+		onuTP.mutexTPState.Lock()
+		onuTP.mapUniTpIndication[aUniID].techProfileToDelete = aState
+		onuTP.mutexTPState.Unlock()
+	} //else: the state is just ignored (does not exist)
+}