[VOL-3038] Configuration of tech profiles 1t1gem
version: 0.1.11-dev124

Signed-off-by: mpagenko <michael.pagenkopf@adtran.com>
Change-Id: Iae456e0eb057c885e5d094a3dbb13c8ab7284537
diff --git a/internal/pkg/onuadaptercore/onu_uni_tp.go b/internal/pkg/onuadaptercore/onu_uni_tp.go
index 1539b9a..0ab7984 100644
--- a/internal/pkg/onuadaptercore/onu_uni_tp.go
+++ b/internal/pkg/onuadaptercore/onu_uni_tp.go
@@ -20,8 +20,11 @@
 import (
 	"context"
 	"encoding/json"
+	"strconv"
+	"strings"
 	"sync"
 
+	"github.com/looplab/fsm"
 	"github.com/opencord/voltha-lib-go/v3/pkg/db"
 	"github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
 	"github.com/opencord/voltha-lib-go/v3/pkg/log"
@@ -49,9 +52,39 @@
 	persAdminState string
 	persOperState  string
 	persUniTpPath  map[uint32]string
-	persUniTpData  map[uint32]tp.TechProfile
 }
 
+type tTechProfileIndication struct {
+	techProfileType string
+	techProfileID   uint16
+}
+
+type tcontParamStruct struct {
+	allocID     uint16
+	schedPolicy uint8
+}
+type gemPortParamStruct struct {
+	gemPortID       uint16
+	direction       uint8
+	gemPortEncState uint8
+	usedPbitMap     uint8
+	ponOmciCC       bool
+	discardPolicy   string
+	//could also be a queue specific paramter, not used that way here
+	maxQueueSize     uint16
+	queueSchedPolicy string
+	queueWeight      uint8
+}
+
+//refers to one tcont and its properties and all assigned GemPorts and their properties
+type tcontGemList struct {
+	tcontParams      tcontParamStruct
+	mapGemPortParams map[uint16]*gemPortParamStruct
+}
+
+//refers to all tcont and their Tcont/GemPort Parameters
+type tMapPonAniConfig map[uint16]*tcontGemList
+
 //OnuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
 type OnuUniTechProf struct {
 	deviceID           string
@@ -59,6 +92,10 @@
 	tpProcMutex        sync.RWMutex
 	sOnuPersistentData onuPersistentData
 	techProfileKVStore *db.Backend
+	chTpProcessingStep chan uint8
+	mapUniTpIndication map[uint32]*tTechProfileIndication //use pointer values to ease assignments to the map
+	mapPonAniConfig    map[uint32]*tMapPonAniConfig       //per UNI: use pointer values to ease assignments to the map
+	pAniConfigFsm      *UniPonAniConfigFsm
 }
 
 //NewOnuUniTechProf returns the instance of a OnuUniTechProf
@@ -70,7 +107,9 @@
 	onuTP.baseDeviceHandler = aDeviceHandler
 	onuTP.tpProcMutex = sync.RWMutex{}
 	onuTP.sOnuPersistentData.persUniTpPath = make(map[uint32]string)
-	onuTP.sOnuPersistentData.persUniTpData = make(map[uint32]tp.TechProfile)
+	onuTP.chTpProcessingStep = make(chan uint8)
+	onuTP.mapUniTpIndication = make(map[uint32]*tTechProfileIndication)
+	onuTP.mapPonAniConfig = make(map[uint32]*tMapPonAniConfig)
 
 	onuTP.techProfileKVStore = aDeviceHandler.SetBackend(cBasePathTechProfileKVStore)
 	if onuTP.techProfileKVStore == nil {
@@ -132,72 +171,342 @@
 	return true
 }
 
-func (onuTP *OnuUniTechProf) configureUniTp(aUniID uint32, aPathString string, wg *sync.WaitGroup) {
-	defer wg.Done()
+func (onuTP *OnuUniTechProf) waitForTpCompletion(cancel context.CancelFunc, wg *sync.WaitGroup) {
+	defer cancel() //ensure termination of context (may be pro forma)
+	wg.Wait()
+	logger.Debug("some TechProfile Processing completed")
+	onuTP.tpProcMutex.Unlock() //allow further TP related processing
+}
+
+// configureUniTp checks existing tp resources to delete and starts the corresponding OMCI configuation of the UNI port
+// all possibly blocking processing must be run in background to allow for deadline supervision!
+// but take care on sequential background processing when needed (logical dependencies)
+//   use waitForTimeoutOrCompletion(ctx, processingStep) for internal synchronisation
+func (onuTP *OnuUniTechProf) configureUniTp(ctx context.Context,
+	aUniID uint32, aPathString string, wg *sync.WaitGroup) {
+	defer wg.Done() //always decrement the waitGroup on return
 	logger.Debugw("configure the Uni according to TpPath", log.Fields{
 		"deviceID": onuTP.deviceID, "uniID": aUniID, "path": aPathString})
 
-	//TODO!!!
-	// reaction on existing tp, deletion of tp, start the corresponding OMCI configuation of the UNI port
-
 	if onuTP.techProfileKVStore == nil {
 		logger.Debug("techProfileKVStore not set - abort")
 		return
 	}
 
-	Value, err := onuTP.techProfileKVStore.Get(context.TODO(), aPathString)
-	if err == nil {
-		if Value != nil {
-			logger.Debugw("tech-profile read",
-				log.Fields{"Key": Value.Key, "Value": Value.Value})
-			tpTmpBytes, _ := kvstore.ToByte(Value.Value)
+	//ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
+	var pCurrentUniPort *OnuUniPort
+	for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
+		// only if this port is validated for operState transfer
+		if uniPort.uniId == uint8(aUniID) {
+			pCurrentUniPort = uniPort
+			break //found - end search loop
+		}
+	}
+	if pCurrentUniPort == nil {
+		logger.Errorw("TechProfile configuration aborted: requested uniID not found in PortDB",
+			log.Fields{"device-id": onuTP.deviceID, "uniID": aUniID})
+		return
+	}
 
-			var tpInst tp.TechProfile
-			if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
-				logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst",
-					log.Fields{"error": err, "device-id": onuTP.deviceID})
-			} else {
-				logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst})
-				onuTP.sOnuPersistentData.persUniTpData[aUniID] = tpInst
+	var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpProcessingStep
 
-				// access examples
-				logger.Debugw("TechProf - name",
-					log.Fields{"onuTP.sOnuPersistentData.persUniTpData[aUniID].Name": onuTP.sOnuPersistentData.persUniTpData[aUniID].Name})
-				//
-				logger.Debugw("TechProf - instance_control.max_gem_payload_size",
-					log.Fields{"onuTP.sOnuPersistentData.persUniTpData[aUniID].InstanceCtrl.MaxGemPayloadSize": onuTP.sOnuPersistentData.persUniTpData[aUniID].InstanceCtrl.MaxGemPayloadSize})
-				//
-				logger.Debugw("TechProf - downstream_gem_port_attribute_list.discard_config.max_threshold",
-					log.Fields{"onuTP.sOnuPersistentData.persUniTpData[aUniID].DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold": onuTP.sOnuPersistentData.persUniTpData[aUniID].DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
+	//according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
+	//  in case the KVPath has changed for the given UNI,
+	//  as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
+	//  (ANI) configuration of this port has to be removed first
+	//  (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
+	//  existence of configuration can be detected based on tp stored TCONT's
+	//TODO!!!:
+	/* if tcontMap  not empty {
+		go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
+		if !onuTP.waitForTimeoutOrCompletion(ctx, processingStep) {
+			//timeout or error detected
+			return
+		}
+		clear tcontMap
+	}
+
+	processingStep++
+	*/
+	go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, aPathString, processingStep)
+	if !onuTP.waitForTimeoutOrCompletion(ctx, processingStep) {
+		//timeout or error detected
+		logger.Debugw("tech-profile related configuration aborted on read",
+			log.Fields{"device-id": onuTP.deviceID, "UniId": aUniID})
+		return
+	}
+
+	processingStep++
+	if valuePA, existPA := onuTP.mapPonAniConfig[aUniID]; existPA {
+		if _, existTG := (*valuePA)[0]; existTG {
+			//Config data for this uni and and at least TCont Index 0 exist
+			go onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, pCurrentUniPort, processingStep)
+			if !onuTP.waitForTimeoutOrCompletion(ctx, processingStep) {
+				//timeout or error detected
+				logger.Debugw("tech-profile related configuration aborted on set",
+					log.Fields{"device-id": onuTP.deviceID, "UniId": aUniID})
+				//this issue here means that the AniConfigFsm has not finished succesfully
+				//which requires to reset it to allow for new usage, e.g. also on a different UNI
+				//(without that it would be reset on device down indication latest)
+				onuTP.pAniConfigFsm.pAdaptFsm.pFsm.Event("reset")
+				return
 			}
 		} else {
-			logger.Debugw("No tech-profile found", log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
+			// strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
+			logger.Debugw("no Tcont/Gem data for this UNI found - abort", log.Fields{
+				"deviceID": onuTP.deviceID, "uniID": aUniID})
 		}
 	} else {
-		logger.Errorw("kvstore-get failed for path",
-			log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
+		logger.Debugw("no PonAni data for this UNI found - abort", log.Fields{
+			"deviceID": onuTP.deviceID, "uniID": aUniID})
 	}
 }
 
-func (onuTP *OnuUniTechProf) updateOnuTpPathKvStore(wg *sync.WaitGroup) {
+func (onuTP *OnuUniTechProf) updateOnuTpPathKvStore(ctx context.Context, wg *sync.WaitGroup) {
 	defer wg.Done()
 	logger.Debugw("this would update the ONU's TpPath in KVStore", log.Fields{
 		"deviceID": onuTP.deviceID})
 	//TODO!!!
-	//make use of onuTP.sOnuPersistentData to store the TpPath to KVStore
+	//make use of onuTP.sOnuPersistentData to store the TpPath to KVStore - as background routine
+	/*
+		var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpProcessingStep
+		go onuTp.storePersistentData(ctx, processingStep)
+		if !onuTP.waitForTimeoutOrCompletion(ctx, processingStep) {
+			//timeout or error detected
+			return
+		}
+	*/
 }
 
-// deleteTpRessource removes ressources from the ONU's specified Uni
-func (onuTP *OnuUniTechProf) deleteTpRessource(aUniID uint32, aPathString string,
-	aRessource resourceEntry, aEntryID uint32, wg *sync.WaitGroup) {
+// deleteTpResource removes Resources from the ONU's specified Uni
+func (onuTP *OnuUniTechProf) deleteTpResource(ctx context.Context,
+	aUniID uint32, 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{
-		"deviceID": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "ressource": aRessource})
+		"deviceID": onuTP.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 chTpProcessingStep
+		go onuTp.deleteAniResource(ctx, processingStep)
+		if !onuTP.waitForTimeoutOrCompletion(ctx, processingStep) {
+			//timeout or error detected
+			return
+		}
+	*/
 }
 
-func (onuTP *OnuUniTechProf) waitForTpCompletion(wg *sync.WaitGroup) {
-	wg.Wait()
-	logger.Debug("some TechProfile Processing completed")
-	onuTP.tpProcMutex.Unlock() //allow further TP related processing
+/* internal methods *********************/
+func (onuTP *OnuUniTechProf) readAniSideConfigFromTechProfile(
+	ctx context.Context, aUniID uint32, aPathString string, aProcessingStep uint8) {
+	var tpInst tp.TechProfile
+
+	//store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
+	//pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
+	subStringSlice := strings.Split(aPathString, "/")
+	if len(subStringSlice) <= 2 {
+		logger.Errorw("invalid path name format",
+			log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
+		onuTP.chTpProcessingStep <- 0 //error indication
+		return
+	}
+
+	//just some logical check to avoid unexpected behavior
+	//at this point it is assumed that a new TechProfile is assigned to the UNI
+	//expectation is that no TPIndication entry exists here, if yes,
+	//  then we throw a warning and remove it (and the possible ANIConfig) simply
+	//  note that the ONU config state may be ambivalent in such a case
+	//  also note, that the PonAniConfig map is not checked additionally
+	//    consistency to TPIndication is assumed
+	if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP {
+		logger.Warnw("Some active profile entry at reading new TechProfile",
+			log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
+				"UniId": aUniID, "wrongProfile": onuTP.mapUniTpIndication[aUniID].techProfileID})
+		//delete on the mapUniTpIndication map not needed, just overwritten later
+		//delete on the PonAniConfig map should be safe, even if not existing
+		delete(onuTP.mapPonAniConfig, aUniID)
+	} else {
+		// this is normal processing
+		onuTP.mapUniTpIndication[aUniID] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
+	}
+
+	onuTP.mapUniTpIndication[aUniID].techProfileType = subStringSlice[0]
+	profID, err := strconv.ParseUint(subStringSlice[1], 10, 32)
+	if err != nil {
+		logger.Errorw("invalid ProfileId from path",
+			log.Fields{"ParseErr": err})
+		onuTP.chTpProcessingStep <- 0 //error indication
+		return
+	}
+
+	//note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
+	onuTP.mapUniTpIndication[aUniID].techProfileID = uint16(profID)
+	logger.Debugw("tech-profile path indications",
+		log.Fields{"device-id": onuTP.deviceID, "UniId": aUniID,
+			"profType": onuTP.mapUniTpIndication[aUniID].techProfileType,
+			"profID":   onuTP.mapUniTpIndication[aUniID].techProfileID})
+
+	Value, err := onuTP.techProfileKVStore.Get(context.TODO(), aPathString)
+	if err == nil {
+		if Value != nil {
+			logger.Debugw("tech-profile read",
+				log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
+			tpTmpBytes, _ := kvstore.ToByte(Value.Value)
+
+			if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
+				logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst",
+					log.Fields{"error": err, "device-id": onuTP.deviceID})
+				onuTP.chTpProcessingStep <- 0 //error indication
+				return
+			}
+			logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst})
+			// access examples
+			logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name,
+				"MaxGemPayloadSize":                tpInst.InstanceCtrl.MaxGemPayloadSize,
+				"DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
+		} else {
+			logger.Errorw("No tech-profile found",
+				log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
+			onuTP.chTpProcessingStep <- 0 //error indication
+			return
+		}
+	} else {
+		logger.Errorw("kvstore-get failed for path",
+			log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
+		onuTP.chTpProcessingStep <- 0 //error indication
+		return
+	}
+
+	//for first start assume a 1Tcont1Gem profile, later extend for multi GemPerTcont and MultiTcontMultiGem
+	localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
+	localMapGemPortParams[0] = &gemPortParamStruct{}
+	localMapPonAniConfig := make(map[uint16]*tcontGemList)
+	localMapPonAniConfig[0] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
+	onuTP.mapPonAniConfig[aUniID] = (*tMapPonAniConfig)(&localMapPonAniConfig)
+
+	//get the relevant values from the profile and store to mapPonAniConfig
+	(*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
+	//maybe tCont scheduling not (yet) needed - just to basicaly have it for future
+	//  (would only be relevant in case of ONU-2G QOS configuration flexibility)
+	if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
+		(*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
+	} else {
+		// default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
+		(*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.schedPolicy = 2 //for G.988 WRR
+	}
+	for pos, content := range tpInst.UpstreamGemPortAttributeList {
+		if pos == 1 {
+			logger.Debugw("PonAniConfig abort GemPortList - still only one Gemport supported",
+				log.Fields{"device-id": onuTP.deviceID})
+			break
+		}
+		// a downstream GemPort should always exist (only downstream for MC)
+		(*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortID = uint16(content.GemportID)
+		// direction can be correlated later with Downstream list, for now just assume bidirectional (upstream never exists alone)
+		(*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].direction = 3 //as defined in G.988
+		if content.AesEncryption == "True" {
+			(*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortEncState = 1
+		} else {
+			(*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortEncState = 0
+		}
+
+		(*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].discardPolicy = content.DiscardPolicy
+		(*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].queueSchedPolicy = content.SchedulingPolicy
+		//'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
+		(*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].queueWeight = uint8(content.Weight)
+	}
+	//TODO!! MC (downstream) GemPorts can be set using DownstreamGemPortAttributeList seperately
+
+	//logger does not simply output the given structures, just give some example debug values
+	logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
+		"device-id":       onuTP.deviceID,
+		"AllocId":         (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.allocID,
+		"GemPort":         (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[0].gemPortID,
+		"QueueScheduling": (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[0].queueSchedPolicy})
+
+	onuTP.chTpProcessingStep <- aProcessingStep //done
+}
+
+func (onuTP *OnuUniTechProf) setAniSideConfigFromTechProfile(
+	ctx context.Context, aUniID uint32, apCurrentUniPort *OnuUniPort, aProcessingStep uint8) {
+
+	//OMCI transfer of ANI data acc. to mapPonAniConfig
+	// also the FSM's are running in background,
+	//   hence we have to make sure they indicate 'success' success on chTpProcessingStep with aProcessingStep
+	if onuTP.pAniConfigFsm == nil {
+		onuTP.createAniConfigFsm(aUniID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
+	} else { //AniConfigFsm already init
+		onuTP.runAniConfigFsm(aProcessingStep)
+	}
+}
+
+func (onuTP *OnuUniTechProf) waitForTimeoutOrCompletion(
+	ctx context.Context, aProcessingStep uint8) bool {
+	select {
+	case <-ctx.Done():
+		logger.Warnw("processing not completed in-time: force release of TpProcMutex!",
+			log.Fields{"deviceID": onuTP.deviceID, "error": ctx.Err()})
+		return false
+	case rxStep := <-onuTP.chTpProcessingStep:
+		if rxStep == aProcessingStep {
+			return true
+		}
+		//all other values are not accepted - including 0 for error indication
+		logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!",
+			log.Fields{"deviceID": onuTP.deviceID,
+				"wantedStep": aProcessingStep, "haveStep": rxStep})
+		return false
+	}
+}
+
+// createUniLockFsm initialises and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
+func (onuTP *OnuUniTechProf) createAniConfigFsm(aUniID uint32,
+	apCurrentUniPort *OnuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) {
+	logger.Debugw("createAniConfigFsm", log.Fields{"deviceID": onuTP.deviceID})
+	chAniConfigFsm := make(chan Message, 2048)
+	pDevEntry := onuTP.baseDeviceHandler.GetOnuDeviceEntry(true)
+	if pDevEntry == nil {
+		logger.Errorw("No valid OnuDevice - aborting", log.Fields{"deviceID": onuTP.deviceID})
+		return
+	}
+	pAniCfgFsm := NewUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
+		pDevEntry.pOnuDB, onuTP.mapUniTpIndication[aUniID].techProfileID, devEvent,
+		"AniConfigFsm", onuTP.deviceID, chAniConfigFsm)
+	if pAniCfgFsm != nil {
+		onuTP.pAniConfigFsm = pAniCfgFsm
+		onuTP.runAniConfigFsm(aProcessingStep)
+	} else {
+		logger.Errorw("AniConfigFSM could not be created - abort!!", log.Fields{"deviceID": onuTP.deviceID})
+	}
+}
+
+// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for  ANI side configuration
+func (onuTP *OnuUniTechProf) runAniConfigFsm(aProcessingStep uint8) {
+	/*  Uni related ANI config procedure -
+	 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
+	 */
+	var pACStatemachine *fsm.FSM
+	pACStatemachine = onuTP.pAniConfigFsm.pAdaptFsm.pFsm
+	if pACStatemachine != nil {
+		if pACStatemachine.Is("disabled") {
+			//FSM init requirement to get informed abou FSM completion! (otherwise timeout of the TechProf config)
+			onuTP.pAniConfigFsm.SetFsmCompleteChannel(onuTP.chTpProcessingStep, aProcessingStep)
+			if err := pACStatemachine.Event("start"); err != nil {
+				logger.Warnw("AniConfigFSM: can't start", log.Fields{"err": err})
+				// maybe try a FSM reset and then again ... - TODO!!!
+			} else {
+				/***** AniConfigFSM started */
+				logger.Debugw("AniConfigFSM started", log.Fields{
+					"state": pACStatemachine.Current(), "deviceID": onuTP.deviceID})
+			}
+		} else {
+			logger.Warnw("wrong state of AniConfigFSM - want: disabled", log.Fields{
+				"have": pACStatemachine.Current(), "deviceID": onuTP.deviceID})
+			// maybe try a FSM reset and then again ... - TODO!!!
+		}
+	} else {
+		logger.Errorw("AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"deviceID": onuTP.deviceID})
+		// maybe try a FSM reset and then again ... - TODO!!!
+	}
 }