[VOL-3380] Functional area specific logging

Change-Id: I67414da013d8fc82827fcdb69d4f8a34040625d3
diff --git a/internal/pkg/core/common.go b/internal/pkg/core/common.go
new file mode 100755
index 0000000..c18ae16
--- /dev/null
+++ b/internal/pkg/core/common.go
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//Package core provides the utility for onu devices, flows and statistics
+package core
+
+import (
+	"github.com/opencord/voltha-lib-go/v7/pkg/log"
+)
+
+var logger log.CLogger
+
+func init() {
+	// Setup this package so that it's log level can be modified at run time
+	var err error
+	logger, err = log.RegisterPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "core"})
+	if err != nil {
+		panic(err)
+	}
+}
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
new file mode 100755
index 0000000..22f08f8
--- /dev/null
+++ b/internal/pkg/core/device_handler.go
@@ -0,0 +1,4000 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//Package core provides the utility for onu devices, flows and statistics
+package core
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"strconv"
+	"sync"
+	"time"
+
+	"github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config"
+	"github.com/opencord/voltha-protos/v5/go/openolt"
+	"github.com/opencord/voltha-protos/v5/go/tech_profile"
+
+	"github.com/gogo/protobuf/proto"
+	"github.com/looplab/fsm"
+	me "github.com/opencord/omci-lib-go/generated"
+	"github.com/opencord/voltha-lib-go/v7/pkg/db"
+	"github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
+	flow "github.com/opencord/voltha-lib-go/v7/pkg/flows"
+	vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
+	"github.com/opencord/voltha-lib-go/v7/pkg/log"
+	almgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/almgr"
+	avcfg "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/avcfg"
+	cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
+	mib "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/mib"
+	otst "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/omcitst"
+	pmmgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/pmmgr"
+	"github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg"
+	uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt"
+	vc "github.com/opencord/voltha-protos/v5/go/common"
+	"github.com/opencord/voltha-protos/v5/go/extension"
+	ic "github.com/opencord/voltha-protos/v5/go/inter_container"
+	of "github.com/opencord/voltha-protos/v5/go/openflow_13"
+	oop "github.com/opencord/voltha-protos/v5/go/openolt"
+	"github.com/opencord/voltha-protos/v5/go/voltha"
+)
+
+// Constants for timeouts
+const (
+	cTimeOutRemoveUpgrade = 1 //for usage in seconds
+)
+
+const (
+	// events of Device FSM
+	devEvDeviceInit       = "devEvDeviceInit"
+	devEvGrpcConnected    = "devEvGrpcConnected"
+	devEvGrpcDisconnected = "devEvGrpcDisconnected"
+	devEvDeviceUpInd      = "devEvDeviceUpInd"
+	devEvDeviceDownInd    = "devEvDeviceDownInd"
+)
+const (
+	// states of Device FSM
+	devStNull      = "devStNull"
+	devStDown      = "devStDown"
+	devStInit      = "devStInit"
+	devStConnected = "devStConnected"
+	devStUp        = "devStUp"
+)
+
+//Event category and subcategory definitions - same as defiend for OLT in eventmgr.go  - should be done more centrally
+const (
+	pon = voltha.EventSubCategory_PON
+	//olt           = voltha.EventSubCategory_OLT
+	//ont           = voltha.EventSubCategory_ONT
+	//onu           = voltha.EventSubCategory_ONU
+	//nni           = voltha.EventSubCategory_NNI
+	//service       = voltha.EventCategory_SERVICE
+	//security      = voltha.EventCategory_SECURITY
+	equipment = voltha.EventCategory_EQUIPMENT
+	//processing    = voltha.EventCategory_PROCESSING
+	//environment   = voltha.EventCategory_ENVIRONMENT
+	//communication = voltha.EventCategory_COMMUNICATION
+)
+
+const (
+	cEventObjectType = "ONU"
+)
+const (
+	cOnuActivatedEvent = "ONU_ACTIVATED"
+)
+
+type omciIdleCheckStruct struct {
+	omciIdleCheckFunc func(*deviceHandler, context.Context, cmn.UsedOmciConfigFsms, string) bool
+	omciIdleState     string
+}
+
+var fsmOmciIdleStateFuncMap = map[cmn.UsedOmciConfigFsms]omciIdleCheckStruct{
+	cmn.CUploadFsm:        {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibUlFsmIdleState},
+	cmn.CDownloadFsm:      {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibDlFsmIdleState},
+	cmn.CUniLockFsm:       {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState},
+	cmn.CUniUnLockFsm:     {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState},
+	cmn.CAniConfigFsm:     {(*deviceHandler).isAniConfigFsmInOmciIdleState, avcfg.CAniFsmIdleState},
+	cmn.CUniVlanConfigFsm: {(*deviceHandler).isUniVlanConfigFsmInOmciIdleState, avcfg.CVlanFsmIdleState},
+	cmn.CL2PmFsm:          {(*deviceHandler).isFsmInOmciIdleStateDefault, pmmgr.CL2PmFsmIdleState},
+	cmn.COnuUpgradeFsm:    {(*deviceHandler).isFsmInOmciIdleStateDefault, swupg.COnuUpgradeFsmIdleState},
+}
+
+const (
+	cNoReconciling = iota
+	cOnuConfigReconciling
+	cSkipOnuConfigReconciling
+)
+
+//deviceHandler will interact with the ONU ? device.
+type deviceHandler struct {
+	DeviceID         string
+	DeviceType       string
+	adminState       string
+	device           *voltha.Device
+	logicalDeviceID  string
+	ProxyAddressID   string
+	ProxyAddressType string
+	parentID         string
+	ponPortNumber    uint32
+
+	coreClient *vgrpc.Client
+	EventProxy eventif.EventProxy
+
+	pmConfigs *voltha.PmConfigs
+	config    *config.AdapterFlags
+
+	pOpenOnuAc      *OpenONUAC
+	pDeviceStateFsm *fsm.FSM
+	//pPonPort        *voltha.Port
+	deviceEntrySet    chan bool //channel for DeviceEntry set event
+	pOnuOmciDevice    *mib.OnuDeviceEntry
+	pOnuTP            *avcfg.OnuUniTechProf
+	pOnuMetricsMgr    *pmmgr.OnuMetricsManager
+	pAlarmMgr         *almgr.OnuAlarmManager
+	pSelfTestHdlr     *otst.SelfTestControlBlock
+	exitChannel       chan int
+	lockDevice        sync.RWMutex
+	pOnuIndication    *oop.OnuIndication
+	deviceReason      uint8
+	mutexDeviceReason sync.RWMutex
+	pLockStateFsm     *uniprt.LockStateFsm
+	pUnlockStateFsm   *uniprt.LockStateFsm
+
+	//flowMgr       *OpenOltFlowMgr
+	//eventMgr      *OpenOltEventMgr
+	//resourceMgr   *rsrcMgr.OpenOltResourceMgr
+
+	//discOnus sync.Map
+	//onus     sync.Map
+	//portStats          *OpenOltStatisticsMgr
+	collectorIsRunning          bool
+	mutexCollectorFlag          sync.RWMutex
+	stopCollector               chan bool
+	alarmManagerIsRunning       bool
+	mutextAlarmManagerFlag      sync.RWMutex
+	stopAlarmManager            chan bool
+	stopHeartbeatCheck          chan bool
+	uniEntityMap                cmn.OnuUniPortMap
+	mutexKvStoreContext         sync.Mutex
+	lockVlanConfig              sync.RWMutex
+	lockVlanAdd                 sync.RWMutex
+	UniVlanConfigFsmMap         map[uint8]*avcfg.UniVlanConfigFsm
+	lockUpgradeFsm              sync.RWMutex
+	pOnuUpradeFsm               *swupg.OnuUpgradeFsm
+	reconciling                 uint8
+	mutexReconcilingFlag        sync.RWMutex
+	chReconcilingFinished       chan bool //channel to indicate that reconciling has been finished
+	mutexReadyForOmciConfig     sync.RWMutex
+	readyForOmciConfig          bool
+	deletionInProgress          bool
+	mutexDeletionInProgressFlag sync.RWMutex
+	pLastUpgradeImageState      *voltha.ImageState
+	upgradeFsmChan              chan struct{}
+}
+
+//newDeviceHandler creates a new device handler
+func newDeviceHandler(ctx context.Context, cc *vgrpc.Client, ep eventif.EventProxy, device *voltha.Device, adapter *OpenONUAC) *deviceHandler {
+	var dh deviceHandler
+	dh.coreClient = cc
+	dh.EventProxy = ep
+	dh.config = adapter.config
+	cloned := (proto.Clone(device)).(*voltha.Device)
+	dh.DeviceID = cloned.Id
+	dh.DeviceType = cloned.Type
+	dh.adminState = "up"
+	dh.device = cloned
+	dh.pOpenOnuAc = adapter
+	dh.exitChannel = make(chan int, 1)
+	dh.lockDevice = sync.RWMutex{}
+	dh.deviceEntrySet = make(chan bool, 1)
+	dh.collectorIsRunning = false
+	dh.stopCollector = make(chan bool, 2)
+	dh.alarmManagerIsRunning = false
+	dh.stopAlarmManager = make(chan bool, 2)
+	dh.stopHeartbeatCheck = make(chan bool, 2)
+	//dh.metrics = pmmetrics.NewPmMetrics(cloned.Id, pmmetrics.Frequency(150), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames))
+	//TODO initialize the support classes.
+	dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort)
+	dh.lockVlanConfig = sync.RWMutex{}
+	dh.lockVlanAdd = sync.RWMutex{}
+	dh.lockUpgradeFsm = sync.RWMutex{}
+	dh.UniVlanConfigFsmMap = make(map[uint8]*avcfg.UniVlanConfigFsm)
+	dh.reconciling = cNoReconciling
+	dh.chReconcilingFinished = make(chan bool)
+	dh.readyForOmciConfig = false
+	dh.deletionInProgress = false
+	dh.pLastUpgradeImageState = &voltha.ImageState{
+		DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN,
+		Reason:        voltha.ImageState_UNKNOWN_ERROR,
+		ImageState:    voltha.ImageState_IMAGE_UNKNOWN,
+	}
+	dh.upgradeFsmChan = make(chan struct{})
+
+	if dh.device.PmConfigs != nil { // can happen after onu adapter restart
+		dh.pmConfigs = cloned.PmConfigs
+	} /* else {
+		// will be populated when onu_metrics_mananger is initialized.
+	}*/
+
+	// Device related state machine
+	dh.pDeviceStateFsm = fsm.NewFSM(
+		devStNull,
+		fsm.Events{
+			{Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit},
+			{Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected},
+			{Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit},
+			{Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp},
+			{Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown},
+		},
+		fsm.Callbacks{
+			"before_event":                      func(e *fsm.Event) { dh.logStateChange(ctx, e) },
+			("before_" + devEvDeviceInit):       func(e *fsm.Event) { dh.doStateInit(ctx, e) },
+			("after_" + devEvDeviceInit):        func(e *fsm.Event) { dh.postInit(ctx, e) },
+			("before_" + devEvGrpcConnected):    func(e *fsm.Event) { dh.doStateConnected(ctx, e) },
+			("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(ctx, e) },
+			("after_" + devEvGrpcDisconnected):  func(e *fsm.Event) { dh.postInit(ctx, e) },
+			("before_" + devEvDeviceUpInd):      func(e *fsm.Event) { dh.doStateUp(ctx, e) },
+			("before_" + devEvDeviceDownInd):    func(e *fsm.Event) { dh.doStateDown(ctx, e) },
+		},
+	)
+
+	return &dh
+}
+
+// start save the device to the data model
+func (dh *deviceHandler) start(ctx context.Context) {
+	logger.Debugw(ctx, "starting-device-handler", log.Fields{"device": dh.device, "device-id": dh.DeviceID})
+	// Add the initial device to the local model
+	logger.Debug(ctx, "device-handler-started")
+}
+
+/*
+// stop stops the device dh.  Not much to do for now
+func (dh *deviceHandler) stop(ctx context.Context) {
+	logger.Debug("stopping-device-handler")
+	dh.exitChannel <- 1
+}
+*/
+
+// ##########################################################################################
+// deviceHandler methods that implement the adapters interface requests ##### begin #########
+
+//adoptOrReconcileDevice adopts the ONU device
+func (dh *deviceHandler) adoptOrReconcileDevice(ctx context.Context, device *voltha.Device) {
+	logger.Debugw(ctx, "adopt_or_reconcile_device", log.Fields{"device-id": device.Id, "Address": device.GetHostAndPort()})
+
+	logger.Debugw(ctx, "Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())})
+	if dh.pDeviceStateFsm.Is(devStNull) {
+		if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil {
+			logger.Errorw(ctx, "Device FSM: Can't go to state DeviceInit", log.Fields{"err": err})
+		}
+		logger.Debugw(ctx, "Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())})
+		// device.PmConfigs is not nil in cases when adapter restarts. We should not re-set the core again.
+		if device.PmConfigs == nil {
+			// Now, set the initial PM configuration for that device
+			if err := dh.updatePMConfigInCore(ctx, dh.pmConfigs); err != nil {
+				logger.Errorw(ctx, "error updating pm config to core", log.Fields{"device-id": dh.DeviceID, "err": err})
+			}
+		}
+	} else {
+		logger.Debugw(ctx, "AdoptOrReconcileDevice: Agent/device init already done", log.Fields{"device-id": device.Id})
+	}
+
+}
+
+func (dh *deviceHandler) handleOMCIIndication(ctx context.Context, msg *ic.OmciMessage) error {
+	/* msg print moved symmetrically to omci_cc, if wanted here as additional debug, than perhaps only based on additional debug setting!
+	//assuming omci message content is hex coded!
+	// with restricted output of 16(?) bytes would be ...omciMsg.Message[:16]
+	logger.Debugw(ctx, "inter-adapter-recv-omci", log.Fields{
+		"device-id": dh.DeviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)})
+	*/
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry != nil {
+		if pDevEntry.PDevOmciCC != nil {
+			return pDevEntry.PDevOmciCC.ReceiveMessage(log.WithSpanFromContext(context.TODO(), ctx), msg.Message)
+		}
+		logger.Debugw(ctx, "omciCC not ready to receive omci messages - incoming omci message ignored", log.Fields{"rxMsg": msg.Message})
+	}
+	logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
+	return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
+}
+
+func (dh *deviceHandler) handleTechProfileDownloadRequest(ctx context.Context, techProfMsg *ic.TechProfileDownloadMessage) error {
+	logger.Infow(ctx, "tech-profile-download-request", log.Fields{"device-id": dh.DeviceID})
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
+	}
+	if dh.pOnuTP == nil {
+		//should normally not happen ...
+		logger.Errorw(ctx, "onuTechProf instance not set up for DLMsg request - ignoring request",
+			log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("techProfile DLMsg request while onuTechProf instance not setup: %s", dh.DeviceID)
+	}
+	if !dh.IsReadyForOmciConfig() {
+		logger.Errorw(ctx, "TechProf-set rejected: improper device state", log.Fields{"device-id": dh.DeviceID,
+			"device-state": dh.GetDeviceReasonString()})
+		return fmt.Errorf("improper device state %s on device %s", dh.GetDeviceReasonString(), dh.DeviceID)
+	}
+	//previous state test here was just this one, now extended for more states to reject the SetRequest:
+	// at least 'mib-downloaded' should be reached for processing of this specific ONU configuration
+	//  if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock")
+
+	// we have to lock access to TechProfile processing based on different messageType calls or
+	// even to fast subsequent calls of the same messageType as well as OnuKVStore processing due
+	// to possible concurrent access by flow processing
+	dh.pOnuTP.LockTpProcMutex()
+	defer dh.pOnuTP.UnlockTpProcMutex()
+
+	if techProfMsg.UniId > 255 {
+		return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
+			techProfMsg.UniId, dh.DeviceID))
+	}
+	uniID := uint8(techProfMsg.UniId)
+	tpID, err := cmn.GetTpIDFromTpPath(techProfMsg.TpInstancePath)
+	if err != nil {
+		logger.Errorw(ctx, "error-parsing-tpid-from-tppath", log.Fields{"err": err, "tp-path": techProfMsg.TpInstancePath})
+		return err
+	}
+	logger.Debugw(ctx, "unmarshal-techprof-msg-body", log.Fields{"uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID})
+
+	if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, uint8(tpID), techProfMsg.TpInstancePath); bTpModify {
+
+		switch tpInst := techProfMsg.TechTpInstance.(type) {
+		case *ic.TechProfileDownloadMessage_TpInstance:
+			logger.Debugw(ctx, "onu-uni-tp-path-modified", log.Fields{"uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID})
+			//	if there has been some change for some uni TechProfilePath
+			//in order to allow concurrent calls to other dh instances we do not wait for execution here
+			//but doing so we can not indicate problems to the caller (who does what with that then?)
+			//by now we just assume straightforward successful execution
+			//TODO!!! Generally: In this scheme it would be good to have some means to indicate
+			//  possible problems to the caller later autonomously
+
+			// deadline context to ensure completion of background routines waited for
+			//20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
+			deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
+			dctx, cancel := context.WithDeadline(context.Background(), deadline)
+
+			dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID)
+
+			var wg sync.WaitGroup
+			wg.Add(1) // for the 1 go routine to finish
+			// attention: deadline completion check and wg.Done is to be done in both routines
+			go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniID, techProfMsg.TpInstancePath, *tpInst.TpInstance, &wg)
+			dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwld") //wait for background process to finish
+			if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil {
+				logger.Errorw(ctx, "error-processing-tp", log.Fields{"device-id": dh.DeviceID, "err": tpErr, "tp-path": techProfMsg.TpInstancePath})
+				return tpErr
+			}
+			deadline = time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
+			dctx2, cancel2 := context.WithDeadline(context.Background(), deadline)
+			pDevEntry.ResetKvProcessingErrorIndication()
+			wg.Add(1) // for the 1 go routine to finish
+			go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg)
+			dh.waitForCompletion(ctx, cancel2, &wg, "TechProfDwld") //wait for background process to finish
+			if kvErr := pDevEntry.GetKvProcessingErrorIndication(); kvErr != nil {
+				logger.Errorw(ctx, "error-updating-KV", log.Fields{"device-id": dh.DeviceID, "err": kvErr, "tp-path": techProfMsg.TpInstancePath})
+				return kvErr
+			}
+			return nil
+		default:
+			logger.Errorw(ctx, "unsupported-tp-instance-type", log.Fields{"tp-path": techProfMsg.TpInstancePath})
+			return fmt.Errorf("unsupported-tp-instance-type--tp-id-%v", techProfMsg.TpInstancePath)
+		}
+	}
+	// no change, nothing really to do - return success
+	logger.Debugw(ctx, "onu-uni-tp-path-not-modified", log.Fields{"uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID})
+	return nil
+}
+
+func (dh *deviceHandler) handleDeleteGemPortRequest(ctx context.Context, delGemPortMsg *ic.DeleteGemPortMessage) error {
+	logger.Infow(ctx, "delete-gem-port-request", log.Fields{"device-id": dh.DeviceID})
+
+	if dh.pOnuTP == nil {
+		//should normally not happen ...
+		logger.Warnw(ctx, "onuTechProf instance not set up for DelGem request - ignoring request",
+			log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("techProfile DelGem request while onuTechProf instance not setup: %s", dh.DeviceID)
+	}
+	//compare TECH_PROFILE_DOWNLOAD_REQUEST
+	dh.pOnuTP.LockTpProcMutex()
+	defer dh.pOnuTP.UnlockTpProcMutex()
+
+	if delGemPortMsg.UniId > 255 {
+		return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
+			delGemPortMsg.UniId, dh.DeviceID))
+	}
+	uniID := uint8(delGemPortMsg.UniId)
+	tpID, err := cmn.GetTpIDFromTpPath(delGemPortMsg.TpInstancePath)
+	if err != nil {
+		logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{"err": err, "tp-path": delGemPortMsg.TpInstancePath})
+		return err
+	}
+	logger.Infow(ctx, "delete-gem-port-request", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "gem": delGemPortMsg.GemPortId})
+	//a removal of some GemPort would never remove the complete TechProfile entry (done on T-Cont)
+
+	return dh.deleteTechProfileResource(ctx, uniID, tpID, delGemPortMsg.TpInstancePath,
+		avcfg.CResourceGemPort, delGemPortMsg.GemPortId)
+
+}
+
+func (dh *deviceHandler) handleDeleteTcontRequest(ctx context.Context, delTcontMsg *ic.DeleteTcontMessage) error {
+	logger.Infow(ctx, "delete-tcont-request", log.Fields{"device-id": dh.DeviceID})
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
+	}
+	if dh.pOnuTP == nil {
+		//should normally not happen ...
+		logger.Warnw(ctx, "onuTechProf instance not set up for DelTcont request - ignoring request",
+			log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("techProfile DelTcont request while onuTechProf instance not setup: %s", dh.DeviceID)
+	}
+
+	//compare TECH_PROFILE_DOWNLOAD_REQUEST
+	dh.pOnuTP.LockTpProcMutex()
+	defer dh.pOnuTP.UnlockTpProcMutex()
+
+	if delTcontMsg.UniId > 255 {
+		return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
+			delTcontMsg.UniId, dh.DeviceID))
+	}
+	uniID := uint8(delTcontMsg.UniId)
+	tpPath := delTcontMsg.TpInstancePath
+	tpID, err := cmn.GetTpIDFromTpPath(tpPath)
+	if err != nil {
+		logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{"err": err, "tp-path": tpPath})
+		return err
+	}
+	logger.Infow(ctx, "delete-tcont-request", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "tcont": delTcontMsg.AllocId})
+
+	pDevEntry.FreeTcont(ctx, uint16(delTcontMsg.AllocId))
+
+	return dh.deleteTechProfileResource(ctx, uniID, tpID, delTcontMsg.TpInstancePath,
+		avcfg.CResourceTcont, delTcontMsg.AllocId)
+
+}
+
+func (dh *deviceHandler) deleteTechProfileResource(ctx context.Context,
+	uniID uint8, tpID uint8, pathString string, resource avcfg.ResourceEntry, entryID uint32) error {
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
+	}
+	var resourceName string
+	if avcfg.CResourceGemPort == resource {
+		resourceName = "Gem"
+	} else {
+		resourceName = "Tcont"
+	}
+
+	// deadline context to ensure completion of background routines waited for
+	deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
+	dctx, cancel := context.WithDeadline(context.Background(), deadline)
+
+	dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID)
+
+	var wg sync.WaitGroup
+	wg.Add(1) // for the 1 go routine to finish
+	go dh.pOnuTP.DeleteTpResource(log.WithSpanFromContext(dctx, ctx), uniID, tpID, pathString,
+		resource, entryID, &wg)
+	dh.waitForCompletion(ctx, cancel, &wg, resourceName+"Delete") //wait for background process to finish
+	if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); err != nil {
+		logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
+		return err
+	}
+
+	if dh.pOnuTP.IsTechProfileConfigCleared(ctx, uniID, tpID) {
+		logger.Debugw(ctx, "techProfile-config-cleared", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID})
+		if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, tpID, ""); bTpModify {
+			pDevEntry.ResetKvProcessingErrorIndication()
+			var wg2 sync.WaitGroup
+			dctx2, cancel2 := context.WithDeadline(context.Background(), deadline)
+			wg2.Add(1)
+			// Removal of the gem id mapping represents the removal of the tech profile
+			logger.Infow(ctx, "remove-techProfile-indication-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID})
+			go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg2)
+			dh.waitForCompletion(ctx, cancel2, &wg2, "TechProfileDeleteOn"+resourceName) //wait for background process to finish
+			if err := pDevEntry.GetKvProcessingErrorIndication(); err != nil {
+				logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
+				return err
+			}
+		}
+	}
+	logger.Debugw(ctx, "delete-tech-profile-resource-completed", log.Fields{"device-id": dh.DeviceID,
+		"uni-id": uniID, "tpID": tpID, "resource-type": resourceName, "resource-id": entryID})
+	return nil
+}
+
+//FlowUpdateIncremental removes and/or adds the flow changes on a given device
+func (dh *deviceHandler) FlowUpdateIncremental(ctx context.Context,
+	apOfFlowChanges *of.FlowChanges,
+	apOfGroupChanges *of.FlowGroupChanges, apFlowMetaData *voltha.FlowMetadata) error {
+	logger.Debugw(ctx, "FlowUpdateIncremental started", log.Fields{"device-id": dh.DeviceID, "metadata": apFlowMetaData})
+	var retError error = nil
+	//Remove flows (always remove flows first - remove old and add new with same cookie may be part of the same request)
+	if apOfFlowChanges.ToRemove != nil {
+		for _, flowItem := range apOfFlowChanges.ToRemove.Items {
+			if flowItem.GetCookie() == 0 {
+				logger.Warnw(ctx, "flow-remove no cookie: ignore and continuing on checking further flows", log.Fields{
+					"device-id": dh.DeviceID})
+				retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.DeviceID)
+				continue
+			}
+			flowInPort := flow.GetInPort(flowItem)
+			if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) {
+				logger.Warnw(ctx, "flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID})
+				retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.DeviceID)
+				continue
+				//return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID)
+			} else if flowInPort == dh.ponPortNumber {
+				//this is some downstream flow, not regarded as error, just ignored
+				logger.Debugw(ctx, "flow-remove for downstream: ignore and continuing on checking further flows", log.Fields{
+					"device-id": dh.DeviceID, "inPort": flowInPort})
+				continue
+			} else {
+				// this is the relevant upstream flow
+				var loUniPort *cmn.OnuUniPort
+				if uniPort, exist := dh.uniEntityMap[flowInPort]; exist {
+					loUniPort = uniPort
+				} else {
+					logger.Warnw(ctx, "flow-remove inPort not found in UniPorts: ignore and continuing on checking further flows",
+						log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort})
+					retError = fmt.Errorf("flow-remove inPort not found in UniPorts, inPort %d, device-id %s",
+						flowInPort, dh.DeviceID)
+					continue
+				}
+				flowOutPort := flow.GetOutPort(flowItem)
+				logger.Debugw(ctx, "flow-remove port indications", log.Fields{
+					"device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort,
+					"uniPortName": loUniPort.Name})
+				err := dh.removeFlowItemFromUniPort(ctx, flowItem, loUniPort)
+				//try next flow after processing error
+				if err != nil {
+					logger.Warnw(ctx, "flow-remove processing error: continuing on checking further flows",
+						log.Fields{"device-id": dh.DeviceID, "error": err})
+					retError = err
+					continue
+					//return err
+				} else { // if last setting succeeds, overwrite possibly previously set error
+					retError = nil
+				}
+			}
+		}
+	}
+	if apOfFlowChanges.ToAdd != nil {
+		for _, flowItem := range apOfFlowChanges.ToAdd.Items {
+			if flowItem.GetCookie() == 0 {
+				logger.Debugw(ctx, "incremental flow-add no cookie: ignore and continuing on checking further flows", log.Fields{
+					"device-id": dh.DeviceID})
+				retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.DeviceID)
+				continue
+			}
+			flowInPort := flow.GetInPort(flowItem)
+			if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) {
+				logger.Warnw(ctx, "flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID})
+				retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.DeviceID)
+				continue
+				//return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID)
+			} else if flowInPort == dh.ponPortNumber {
+				//this is some downstream flow
+				logger.Debugw(ctx, "flow-add for downstream: ignore and continuing on checking further flows", log.Fields{
+					"device-id": dh.DeviceID, "inPort": flowInPort})
+				continue
+			} else {
+				// this is the relevant upstream flow
+				var loUniPort *cmn.OnuUniPort
+				if uniPort, exist := dh.uniEntityMap[flowInPort]; exist {
+					loUniPort = uniPort
+				} else {
+					logger.Warnw(ctx, "flow-add inPort not found in UniPorts: ignore and continuing on checking further flows",
+						log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort})
+					retError = fmt.Errorf("flow-add inPort not found in UniPorts, inPort %d, device-id %s",
+						flowInPort, dh.DeviceID)
+					continue
+					//return fmt.Errorf("flow-parameter inPort %d not found in internal UniPorts", flowInPort)
+				}
+				// let's still assume that we receive the flow-add only in some 'active' device state (as so far observed)
+				// if not, we just throw some error here to have an indication about that, if we really need to support that
+				//   then we would need to create some means to activate the internal stored flows
+				//   after the device gets active automatically (and still with its dependency to the TechProfile)
+				// for state checking compare also code here: processInterAdapterTechProfileDownloadReqMessage
+				// also abort for the other still possible flows here
+				if !dh.IsReadyForOmciConfig() {
+					logger.Errorw(ctx, "flow-add rejected: improper device state", log.Fields{"device-id": dh.DeviceID,
+						"last device-reason": dh.GetDeviceReasonString()})
+					return fmt.Errorf("improper device state on device %s", dh.DeviceID)
+				}
+
+				flowOutPort := flow.GetOutPort(flowItem)
+				logger.Debugw(ctx, "flow-add port indications", log.Fields{
+					"device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort,
+					"uniPortName": loUniPort.Name})
+				err := dh.addFlowItemToUniPort(ctx, flowItem, loUniPort, apFlowMetaData)
+				//try next flow after processing error
+				if err != nil {
+					logger.Warnw(ctx, "flow-add processing error: continuing on checking further flows",
+						log.Fields{"device-id": dh.DeviceID, "error": err})
+					retError = err
+					continue
+					//return err
+				} else { // if last setting succeeds, overwrite possibly previously set error
+					retError = nil
+				}
+			}
+		}
+	}
+	return retError
+}
+
+//disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI)
+//following are the expected device states after this activity:
+//Device Admin-State : down (on rwCore), Port-State: UNKNOWN, Conn-State: REACHABLE, Reason: omci-admin-lock
+// (Conn-State: REACHABLE might conflict with some previous ONU Down indication - maybe to be resolved later)
+func (dh *deviceHandler) disableDevice(ctx context.Context, device *voltha.Device) {
+	logger.Debugw(ctx, "disable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
+
+	//admin-lock reason can also be used uniquely for setting the DeviceState accordingly
+	//note that disableDevice sequences in some 'ONU active' state may yield also
+	// "tech...delete-success" or "omci-flow-deleted" according to further received requests in the end
+	// - inblock state checking to prevent possibly unneeded processing (on command repitition)
+	if dh.getDeviceReason() != cmn.DrOmciAdminLock {
+		//disable-device shall be just a UNi/ONU-G related admin state setting
+		//all other configurations/FSM's shall not be impacted and shall execute as required by the system
+
+		if dh.IsReadyForOmciConfig() {
+			// disable UNI ports/ONU
+			// *** should generate UniDisableStateDone event - used to disable the port(s) on success
+			if dh.pLockStateFsm == nil {
+				dh.createUniLockFsm(ctx, true, cmn.UniDisableStateDone)
+			} else { //LockStateFSM already init
+				dh.pLockStateFsm.SetSuccessEvent(cmn.UniDisableStateDone)
+				dh.runUniLockFsm(ctx, true)
+			}
+		} else {
+			logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
+				"OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID})
+			if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
+				DeviceId:   dh.DeviceID,
+				ConnStatus: voltha.ConnectStatus_REACHABLE,
+				OperStatus: voltha.OperStatus_UNKNOWN,
+			}); err != nil {
+				//TODO with VOL-3045/VOL-3046: return the error and stop further processing
+				logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
+			}
+			// DeviceReason to update acc.to modified py code as per beginning of Sept 2020
+
+			//TODO with VOL-3045/VOL-3046: catch and return error, valid for all occurrences in the codebase
+			_ = dh.deviceReasonUpdate(ctx, cmn.DrOmciAdminLock, true)
+		}
+	}
+}
+
+//reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI)
+func (dh *deviceHandler) reEnableDevice(ctx context.Context, device *voltha.Device) {
+	logger.Debugw(ctx, "reenable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
+
+	//setting readyForOmciConfig here is just a workaround for BBSIM testing in the sequence
+	//  OnuSoftReboot-disable-enable, because BBSIM does not generate a new OnuIndication-Up event after SoftReboot
+	//  which is the assumption for real ONU's, where the ready-state is then set according to the following MibUpload/Download
+	//  for real ONU's that should have nearly no influence
+	//  Note that for real ONU's there is anyway a problematic situation with following sequence:
+	//		OnuIndication-Dw (or not active at all) (- disable) - enable: here already the LockFsm may run into timeout (no OmciResponse)
+	//      but that anyway is hopefully resolved by some OnuIndication-Up event (maybe to be tested)
+	//      one could also argue, that a device-enable should also enable attempts for specific omci configuration
+	dh.SetReadyForOmciConfig(true) //needed to allow subsequent flow/techProf config (on BBSIM)
+
+	// enable ONU/UNI ports
+	// *** should generate cmn.UniEnableStateDone event - used to disable the port(s) on success
+	if dh.pUnlockStateFsm == nil {
+		dh.createUniLockFsm(ctx, false, cmn.UniEnableStateDone)
+	} else { //UnlockStateFSM already init
+		dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniEnableStateDone)
+		dh.runUniLockFsm(ctx, false)
+	}
+}
+
+func (dh *deviceHandler) reconcileDeviceOnuInd(ctx context.Context) {
+	logger.Debugw(ctx, "reconciling - simulate onu indication", log.Fields{"device-id": dh.DeviceID})
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return
+	}
+	if err := pDevEntry.RestoreDataFromOnuKvStore(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
+		if err == fmt.Errorf("no-ONU-data-found") {
+			logger.Debugw(ctx, "no persistent data found - abort reconciling", log.Fields{"device-id": dh.DeviceID})
+		} else {
+			logger.Errorw(ctx, "reconciling - restoring OnuTp-data failed - abort", log.Fields{"err": err, "device-id": dh.DeviceID})
+		}
+		dh.StopReconciling(ctx, false)
+		return
+	}
+	var onuIndication oop.OnuIndication
+	pDevEntry.MutexPersOnuConfig.RLock()
+	onuIndication.IntfId = pDevEntry.SOnuPersistentData.PersIntfID
+	onuIndication.OnuId = pDevEntry.SOnuPersistentData.PersOnuID
+	onuIndication.OperState = pDevEntry.SOnuPersistentData.PersOperState
+	onuIndication.AdminState = pDevEntry.SOnuPersistentData.PersAdminState
+	pDevEntry.MutexPersOnuConfig.RUnlock()
+	_ = dh.createInterface(ctx, &onuIndication)
+}
+
+func (dh *deviceHandler) ReconcileDeviceTechProf(ctx context.Context) {
+	logger.Debugw(ctx, "reconciling - trigger tech profile config", log.Fields{"device-id": dh.DeviceID})
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		if !dh.IsSkipOnuConfigReconciling() {
+			dh.StopReconciling(ctx, false)
+		}
+		return
+	}
+	dh.pOnuTP.LockTpProcMutex()
+	defer dh.pOnuTP.UnlockTpProcMutex()
+
+	pDevEntry.MutexPersOnuConfig.RLock()
+	persMutexLock := true
+	if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 {
+		pDevEntry.MutexPersOnuConfig.RUnlock()
+		logger.Debugw(ctx, "reconciling - no uni-configs have been stored before adapter restart - terminate reconcilement",
+			log.Fields{"device-id": dh.DeviceID})
+		if !dh.IsSkipOnuConfigReconciling() {
+			dh.StopReconciling(ctx, true)
+		}
+		return
+	}
+	flowsFound := false
+	techProfsFound := false
+	techProfInstLoadFailed := false
+outerLoop:
+	for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig {
+		//TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support
+		if len(uniData.PersTpPathMap) == 0 {
+			logger.Debugw(ctx, "reconciling - no TPs stored for uniID",
+				log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
+			continue
+		}
+		//release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of
+		//  OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI
+		//  frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap
+		pDevEntry.MutexPersOnuConfig.RUnlock()
+		persMutexLock = false
+		techProfsFound = true // set to true if we found TP once for any UNI port
+		for tpID := range uniData.PersTpPathMap {
+			// Request the TpInstance again from the openolt adapter in case of reconcile
+			iaTechTpInst, err := dh.getTechProfileInstanceFromParentAdapter(ctx,
+				dh.device.ProxyAddress.AdapterEndpoint,
+				&ic.TechProfileInstanceRequestMessage{
+					DeviceId:       dh.device.Id,
+					TpInstancePath: uniData.PersTpPathMap[tpID],
+					ParentDeviceId: dh.parentID,
+					ParentPonPort:  dh.device.ParentPortNo,
+					OnuId:          dh.device.ProxyAddress.OnuId,
+					UniId:          uint32(uniData.PersUniID),
+				})
+			if err != nil || iaTechTpInst == nil {
+				logger.Errorw(ctx, "error fetching tp instance",
+					log.Fields{"tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID, "err": err})
+				techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure
+				break outerLoop
+			}
+			var tpInst tech_profile.TechProfileInstance
+			switch techTpInst := iaTechTpInst.TechTpInstance.(type) {
+			case *ic.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON
+				tpInst = *techTpInst.TpInstance
+				logger.Debugw(ctx, "received-tp-instance-successfully-after-reconcile", log.Fields{
+					"tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
+			default: // do not support epon or other tech
+				logger.Errorw(ctx, "unsupported-tech-profile", log.Fields{
+					"tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
+				techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure
+				break outerLoop
+			}
+
+			// deadline context to ensure completion of background routines waited for
+			//20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
+			deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
+			dctx, cancel := context.WithDeadline(ctx, deadline)
+
+			dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID)
+			var wg sync.WaitGroup
+			wg.Add(1) // for the 1 go routine to finish
+			go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniData.PersUniID, uniData.PersTpPathMap[tpID], tpInst, &wg)
+			dh.waitForCompletion(ctx, cancel, &wg, "TechProfReconcile") //wait for background process to finish
+			if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniData.PersUniID, tpID); err != nil {
+				logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
+				techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure
+				break outerLoop
+			}
+		} // for all TpPath entries for this UNI
+		if len(uniData.PersFlowParams) != 0 {
+			flowsFound = true
+		}
+		pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData
+		persMutexLock = true
+	} // for all UNI entries from SOnuPersistentData
+	if persMutexLock { // if loop was left with MutexPersOnuConfig still set
+		pDevEntry.MutexPersOnuConfig.RUnlock()
+	}
+
+	//had to move techProf/flow result evaluation into separate function due to SCA complexity limit
+	dh.updateReconcileStates(ctx, techProfsFound, techProfInstLoadFailed, flowsFound)
+}
+
+func (dh *deviceHandler) updateReconcileStates(ctx context.Context,
+	abTechProfsFound bool, abTechProfInstLoadFailed bool, abFlowsFound bool) {
+	if !abTechProfsFound {
+		logger.Debugw(ctx, "reconciling - no TPs have been stored before adapter restart - terminate reconcilement",
+			log.Fields{"device-id": dh.DeviceID})
+		if !dh.IsSkipOnuConfigReconciling() {
+			dh.StopReconciling(ctx, true)
+		}
+		return
+	}
+	if abTechProfInstLoadFailed {
+		dh.SetDeviceReason(cmn.DrTechProfileConfigDownloadFailed)
+		dh.StopReconciling(ctx, false)
+		return
+	} else if dh.IsSkipOnuConfigReconciling() {
+		dh.SetDeviceReason(cmn.DrTechProfileConfigDownloadSuccess)
+	}
+	if !abFlowsFound {
+		logger.Debugw(ctx, "reconciling - no flows have been stored before adapter restart - terminate reconcilement",
+			log.Fields{"device-id": dh.DeviceID})
+		if !dh.IsSkipOnuConfigReconciling() {
+			dh.StopReconciling(ctx, true)
+		}
+	}
+}
+
+func (dh *deviceHandler) ReconcileDeviceFlowConfig(ctx context.Context) {
+	logger.Debugw(ctx, "reconciling - trigger flow config", log.Fields{"device-id": dh.DeviceID})
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		if !dh.IsSkipOnuConfigReconciling() {
+			dh.StopReconciling(ctx, false)
+		}
+		return
+	}
+
+	pDevEntry.MutexPersOnuConfig.RLock()
+	if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 {
+		pDevEntry.MutexPersOnuConfig.RUnlock()
+		logger.Debugw(ctx, "reconciling - no uni-configs have been stored before adapter restart - terminate reconcilement",
+			log.Fields{"device-id": dh.DeviceID})
+		if !dh.IsSkipOnuConfigReconciling() {
+			dh.StopReconciling(ctx, true)
+		}
+		return
+	}
+	flowsFound := false
+	for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig {
+		//TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support
+		if len(uniData.PersFlowParams) == 0 {
+			logger.Debugw(ctx, "reconciling - no flows stored for uniID",
+				log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
+			continue
+		}
+		if len(uniData.PersTpPathMap) == 0 {
+			logger.Warnw(ctx, "reconciling - flows but no TPs stored for uniID",
+				log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
+			// It doesn't make sense to configure any flows if no TPs are available
+			continue
+		}
+		//release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of
+		//  OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI
+		//  frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap
+		pDevEntry.MutexPersOnuConfig.RUnlock()
+
+		var uniPort *cmn.OnuUniPort
+		var exist bool
+		uniNo := mkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), uint32(uniData.PersUniID))
+		if uniPort, exist = dh.uniEntityMap[uniNo]; !exist {
+			logger.Errorw(ctx, "reconciling - OnuUniPort data not found  - terminate reconcilement",
+				log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID})
+			if !dh.IsSkipOnuConfigReconciling() {
+				dh.StopReconciling(ctx, false)
+			}
+			return
+		}
+		flowsFound = true
+		lastFlowToReconcile := false
+		flowsProcessed := 0
+		pDevEntry.SetReconcilingFlows(true)
+		for _, flowData := range uniData.PersFlowParams {
+			logger.Debugw(ctx, "reconciling - add flow with cookie slice", log.Fields{
+				"device-id": dh.DeviceID, "uni-id": uniData.PersUniID, "cookies": flowData.CookieSlice})
+			if flowsProcessed == len(uniData.PersFlowParams)-1 {
+				lastFlowToReconcile = true
+			}
+			//the slice can be passed 'by value' here, - which internally passes its reference copy
+			dh.lockVlanConfig.Lock()
+			if _, exist = dh.UniVlanConfigFsmMap[uniData.PersUniID]; exist {
+				if err := dh.UniVlanConfigFsmMap[uniData.PersUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID,
+					flowData.CookieSlice, uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid),
+					uint8(flowData.VlanRuleParams.SetPcp), lastFlowToReconcile, flowData.Meter); err != nil {
+					logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
+				}
+			} else {
+				if err := dh.createVlanFilterFsm(ctx, uniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice,
+					uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid),
+					uint8(flowData.VlanRuleParams.SetPcp), cmn.OmciVlanFilterAddDone, lastFlowToReconcile, flowData.Meter); err != nil {
+					logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
+				}
+			}
+			dh.lockVlanConfig.Unlock()
+			flowsProcessed++
+		} //for all flows of this UNI
+		logger.Debugw(ctx, "reconciling - flows processed", log.Fields{
+			"device-id": dh.DeviceID, "uni-id": uniData.PersUniID, "flowsProcessed": flowsProcessed,
+			"NumUniFlows":       dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows,
+			"ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow})
+		// this can't be used as global finished reconciling flag because
+		// assumes is getting called before the state machines for the last flow is completed,
+		// while this is not guaranteed.
+		//dh.SetReconcilingFlows(false)
+		pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData
+	} // for all UNI entries from SOnuPersistentData
+	pDevEntry.MutexPersOnuConfig.RUnlock()
+
+	if !flowsFound {
+		logger.Debugw(ctx, "reconciling - no flows have been stored before adapter restart - terminate reconcilement",
+			log.Fields{"device-id": dh.DeviceID})
+		if !dh.IsSkipOnuConfigReconciling() {
+			dh.StopReconciling(ctx, true)
+		}
+		return
+	}
+	if dh.IsSkipOnuConfigReconciling() {
+		dh.SetDeviceReason(cmn.DrOmciFlowsPushed)
+	}
+}
+
+func (dh *deviceHandler) reconcileEnd(ctx context.Context) {
+	logger.Debugw(ctx, "reconciling - completed!", log.Fields{"device-id": dh.DeviceID})
+	dh.StopReconciling(ctx, true)
+}
+
+func (dh *deviceHandler) deleteDevicePersistencyData(ctx context.Context) error {
+	logger.Debugw(ctx, "delete device persistency data", log.Fields{"device-id": dh.DeviceID})
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+	if pDevEntry == nil {
+		//IfDevEntry does not exist here, no problem - no persistent data should have been stored
+		logger.Debugw(ctx, "OnuDevice does not exist - nothing to delete", log.Fields{"device-id": dh.DeviceID})
+		return nil
+	}
+
+	// deadline context to ensure completion of background routines waited for
+	//20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
+	deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
+	dctx, cancel := context.WithDeadline(ctx, deadline)
+
+	pDevEntry.ResetKvProcessingErrorIndication()
+
+	var wg sync.WaitGroup
+	wg.Add(1) // for the 1 go routine to finish
+	go pDevEntry.DeleteDataFromOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg)
+	dh.waitForCompletion(ctx, cancel, &wg, "DeleteDevice") //wait for background process to finish
+
+	// TODO: further actions - stop metrics and FSMs, remove device ...
+	return pDevEntry.GetKvProcessingErrorIndication()
+}
+
+//func (dh *deviceHandler) rebootDevice(ctx context.Context, device *voltha.Device) error {
+// before this change here return like this was used:
+// 		return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber)
+//was and is called in background - error return does not make sense
+func (dh *deviceHandler) rebootDevice(ctx context.Context, aCheckDeviceState bool, device *voltha.Device) {
+	logger.Infow(ctx, "reboot-device", log.Fields{"device-id": dh.DeviceID, "SerialNumber": dh.device.SerialNumber})
+	if aCheckDeviceState && device.ConnectStatus != voltha.ConnectStatus_REACHABLE {
+		logger.Errorw(ctx, "device-unreachable", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
+		return
+	}
+	if err := dh.pOnuOmciDevice.Reboot(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
+		//TODO with VOL-3045/VOL-3046: return the error and stop further processing
+		logger.Errorw(ctx, "error-rebooting-device", log.Fields{"device-id": dh.DeviceID, "error": err})
+		return
+	}
+
+	//transfer the possibly modified logical uni port state
+	dh.DisableUniPortStateUpdate(ctx)
+
+	logger.Debugw(ctx, "call DeviceStateUpdate upon reboot", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
+		"OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID})
+	if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
+		DeviceId:   dh.DeviceID,
+		ConnStatus: voltha.ConnectStatus_REACHABLE,
+		OperStatus: voltha.OperStatus_DISCOVERED,
+	}); err != nil {
+		//TODO with VOL-3045/VOL-3046: return the error and stop further processing
+		logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
+		return
+	}
+	if err := dh.deviceReasonUpdate(ctx, cmn.DrRebooting, true); err != nil {
+		return
+	}
+	dh.SetReadyForOmciConfig(false)
+	//no specific activity to synchronize any internal FSM to the 'rebooted' state is explicitly done here
+	//  the expectation ids for a real device, that it will be synced with the expected following 'down' indication
+	//  as BBSIM does not support this testing requires explicite disable/enable device calls in which sequence also
+	//  all other FSM's should be synchronized again
+}
+
+//doOnuSwUpgrade initiates the SW download transfer to the ONU and on success activates the (inactive) image
+//  used only for old - R2.7 style - upgrade API
+func (dh *deviceHandler) doOnuSwUpgrade(ctx context.Context, apImageDsc *voltha.ImageDownload,
+	apDownloadManager *swupg.AdapterDownloadManager) error {
+	logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{
+		"device-id": dh.DeviceID, "image-name": (*apImageDsc).Name})
+
+	var err error
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("start Onu SW upgrade rejected: no valid OnuDevice for device-id: %s", dh.DeviceID)
+	}
+
+	if dh.IsReadyForOmciConfig() {
+		var inactiveImageID uint16
+		if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil {
+			dh.lockUpgradeFsm.Lock()
+			defer dh.lockUpgradeFsm.Unlock()
+			if dh.pOnuUpradeFsm == nil {
+				err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
+				if err == nil {
+					if err = dh.pOnuUpradeFsm.SetDownloadParams(ctx, inactiveImageID, apImageDsc, apDownloadManager); err != nil {
+						logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{
+							"device-id": dh.DeviceID, "error": err})
+					}
+				} else {
+					logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
+						"device-id": dh.DeviceID, "error": err})
+				}
+			} else { //OnuSw upgrade already running - restart (with possible abort of running)
+				logger.Debugw(ctx, "Onu SW upgrade already running - abort", log.Fields{"device-id": dh.DeviceID})
+				dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort
+				//no effort spent anymore for the old API to automatically cancel and restart the download
+				//  like done for the new API
+				logger.Debugw(ctx, "Onu SW upgrade already running - abort", log.Fields{"device-id": dh.DeviceID})
+				dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort
+				//no effort spent anymore for the old API to automatically cancel and restart the download
+				//  like done for the new API
+			}
+		} else {
+			logger.Errorw(ctx, "start Onu SW upgrade rejected: no inactive image", log.Fields{
+				"device-id": dh.DeviceID, "error": err})
+		}
+	} else {
+		logger.Errorw(ctx, "start Onu SW upgrade rejected: no active OMCI connection", log.Fields{"device-id": dh.DeviceID})
+		err = fmt.Errorf("start Onu SW upgrade rejected: no active OMCI connection for device-id: %s", dh.DeviceID)
+	}
+	return err
+}
+
+//onuSwUpgradeAfterDownload initiates the SW download transfer to the ONU with activate and commit options
+// after the OnuImage has been downloaded to the adapter, called in background
+func (dh *deviceHandler) onuSwUpgradeAfterDownload(ctx context.Context, apImageRequest *voltha.DeviceImageDownloadRequest,
+	apDownloadManager *swupg.FileDownloadManager, aImageIdentifier string) {
+
+	var err error
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
+		return
+	}
+
+	var inactiveImageID uint16
+	if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil {
+		logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{
+			"device-id": dh.DeviceID, "image-version": apImageRequest.Image.Version, "to onu-image": inactiveImageID})
+
+		dh.lockUpgradeFsm.RLock()
+		lopOnuUpradeFsm := dh.pOnuUpradeFsm
+		//lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm()
+		dh.lockUpgradeFsm.RUnlock()
+		if lopOnuUpradeFsm != nil {
+			//OnuSw upgrade already running on this device (e.g. with activate/commit not yet set)
+			// abort the current processing, running upgrades are always aborted by newer request
+			logger.Debugw(ctx, "Onu SW upgrade already running - abort previous activity", log.Fields{"device-id": dh.DeviceID})
+			//flush the remove upgradeFsmChan channel
+			select {
+			case <-dh.upgradeFsmChan:
+				logger.Debug(ctx, "flushed-upgrade-fsm-channel")
+			default:
+			}
+			lopOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort
+			select {
+			case <-time.After(cTimeOutRemoveUpgrade * time.Second):
+				logger.Errorw(ctx, "could not remove Upgrade FSM in time, aborting", log.Fields{"device-id": dh.DeviceID})
+				//should not appear, can't proceed with new upgrade, perhaps operator can retry manually later
+				return
+			case <-dh.upgradeFsmChan:
+				logger.Debugw(ctx, "recent Upgrade FSM removed, proceed with new request", log.Fields{"device-id": dh.DeviceID})
+			}
+		}
+
+		//here it can be assumed that no running upgrade processing exists (anymore)
+		//OmciOnuSwUpgradeDone could be used to create some Kafka event with information on upgrade completion,
+		//  but none yet defined
+		err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
+		if err == nil {
+			if err = dh.pOnuUpradeFsm.SetDownloadParamsAfterDownload(ctx, inactiveImageID,
+				apImageRequest, apDownloadManager, aImageIdentifier); err != nil {
+				logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{
+					"device-id": dh.DeviceID, "error": err})
+				return
+			}
+		} else {
+			logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
+				"device-id": dh.DeviceID, "error": err})
+		}
+		return
+	}
+	logger.Errorw(ctx, "start Onu SW upgrade rejected: no inactive image", log.Fields{
+		"device-id": dh.DeviceID, "error": err})
+}
+
+//onuSwActivateRequest ensures activation of the requested image with commit options
+func (dh *deviceHandler) onuSwActivateRequest(ctx context.Context,
+	aVersion string, aCommitRequest bool) (*voltha.ImageState, error) {
+	var err error
+	//SW activation for the ONU image may have two use cases, one of them is selected here according to following prioritization:
+	//  1.) activation of the image for a started upgrade process (in case the running upgrade runs on the requested image)
+	//  2.) activation of the inactive image
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "Onu image activation rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
+		return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID)
+	}
+	dh.lockUpgradeFsm.RLock()
+	if dh.pOnuUpradeFsm != nil {
+		dh.lockUpgradeFsm.RUnlock()
+		onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID)
+		if getErr != nil || onuVolthaDevice == nil {
+			logger.Errorw(ctx, "Failed to fetch Onu device for image activation", log.Fields{"device-id": dh.DeviceID, "err": getErr})
+			return nil, fmt.Errorf("could not fetch device for device-id: %s", dh.DeviceID)
+		}
+		//  use the OnuVendor identification from this device for the internal unique name
+		imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU
+		// 1.) check a started upgrade process and relay the activation request to it
+		if err = dh.pOnuUpradeFsm.SetActivationParamsRunning(ctx, imageIdentifier, aCommitRequest); err != nil {
+			//if some ONU upgrade is ongoing we do not accept some explicit ONU image-version related activation
+			logger.Errorw(ctx, "onu upgrade fsm did not accept activation while running", log.Fields{
+				"device-id": dh.DeviceID, "error": err})
+			return nil, fmt.Errorf("activation not accepted for this version for device-id: %s", dh.DeviceID)
+		}
+		logger.Debugw(ctx, "image activation acknowledged by onu upgrade processing", log.Fields{
+			"device-id": dh.DeviceID, "image-id": imageIdentifier})
+		pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
+		return pImageStates, nil
+	} //else
+	dh.lockUpgradeFsm.RUnlock()
+
+	// 2.) check if requested image-version equals the inactive one and start its activation
+	//   (image version is not [yet] checked - would be possible, but with increased effort ...)
+	var inactiveImageID uint16
+	if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err != nil || inactiveImageID > 1 {
+		logger.Errorw(ctx, "get inactive image failed", log.Fields{
+			"device-id": dh.DeviceID, "err": err, "image-id": inactiveImageID})
+		return nil, fmt.Errorf("no valid inactive image found for device-id: %s", dh.DeviceID)
+	}
+	err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
+	if err == nil {
+		if err = dh.pOnuUpradeFsm.SetActivationParamsStart(ctx, aVersion,
+			inactiveImageID, aCommitRequest); err != nil {
+			logger.Errorw(ctx, "onu upgrade fsm did not accept activation to start", log.Fields{
+				"device-id": dh.DeviceID, "error": err})
+			return nil, fmt.Errorf("activation to start from scratch not accepted for device-id: %s", dh.DeviceID)
+		}
+		logger.Debugw(ctx, "inactive image activation acknowledged by onu upgrade", log.Fields{
+			"device-id": dh.DeviceID, "image-version": aVersion})
+		pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
+		return pImageStates, nil
+	} //else
+	logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
+		"device-id": dh.DeviceID, "error": err})
+	return nil, fmt.Errorf("could not start upgradeFsm for device-id: %s", dh.DeviceID)
+}
+
+//onuSwCommitRequest ensures commitment of the requested image
+func (dh *deviceHandler) onuSwCommitRequest(ctx context.Context,
+	aVersion string) (*voltha.ImageState, error) {
+	var err error
+	//SW commitment for the ONU image may have two use cases, one of them is selected here according to following prioritization:
+	//  1.) commitment of the image for a started upgrade process (in case the running upgrade runs on the requested image)
+	//  2.) commitment of the active image
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "Onu image commitment rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
+		return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID)
+	}
+	dh.lockUpgradeFsm.RLock()
+	if dh.pOnuUpradeFsm != nil {
+		dh.lockUpgradeFsm.RUnlock()
+		onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID)
+		if getErr != nil || onuVolthaDevice == nil {
+			logger.Errorw(ctx, "Failed to fetch Onu device for image commitment", log.Fields{"device-id": dh.DeviceID, "err": getErr})
+			return nil, fmt.Errorf("could not fetch device for device-id: %s", dh.DeviceID)
+		}
+		//  use the OnuVendor identification from this device for the internal unique name
+		imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU
+		// 1.) check a started upgrade process and relay the commitment request to it
+		// the running upgrade may be based either on the imageIdentifier (started from download)
+		//   or on the imageVersion (started from pure activation)
+		if err = dh.pOnuUpradeFsm.SetCommitmentParamsRunning(ctx, imageIdentifier, aVersion); err != nil {
+			//if some ONU upgrade is ongoing we do not accept some explicit different ONU image-version related commitment
+			logger.Errorw(ctx, "onu upgrade fsm did not accept commitment while running", log.Fields{
+				"device-id": dh.DeviceID, "error": err})
+			return nil, fmt.Errorf("commitment not accepted for this version for device-id: %s", dh.DeviceID)
+		}
+		logger.Debugw(ctx, "image commitment acknowledged by onu upgrade processing", log.Fields{
+			"device-id": dh.DeviceID, "image-id": imageIdentifier})
+		pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
+		return pImageStates, nil
+	} //else
+	dh.lockUpgradeFsm.RUnlock()
+
+	// 2.) use the active image to directly commit
+	var activeImageID uint16
+	if activeImageID, err = pDevEntry.GetActiveImageMeID(ctx); err != nil || activeImageID > 1 {
+		logger.Errorw(ctx, "get active image failed", log.Fields{
+			"device-id": dh.DeviceID, "err": err, "image-id": activeImageID})
+		return nil, fmt.Errorf("no valid active image found for device-id: %s", dh.DeviceID)
+	}
+	err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
+	if err == nil {
+		if err = dh.pOnuUpradeFsm.SetCommitmentParamsStart(ctx, aVersion, activeImageID); err != nil {
+			logger.Errorw(ctx, "onu upgrade fsm did not accept commitment to start", log.Fields{
+				"device-id": dh.DeviceID, "error": err})
+			return nil, fmt.Errorf("commitment to start from scratch not accepted for device-id: %s", dh.DeviceID)
+		}
+		logger.Debugw(ctx, "active image commitment acknowledged by onu upgrade", log.Fields{
+			"device-id": dh.DeviceID, "image-version": aVersion})
+		pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
+		return pImageStates, nil
+	} //else
+	logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
+		"device-id": dh.DeviceID, "error": err})
+	return nil, fmt.Errorf("could not start upgradeFsm for device-id: %s", dh.DeviceID)
+}
+
+func (dh *deviceHandler) requestOnuSwUpgradeState(ctx context.Context, aImageIdentifier string,
+	aVersion string) *voltha.ImageState {
+	var pImageState *voltha.ImageState
+	dh.lockUpgradeFsm.RLock()
+	defer dh.lockUpgradeFsm.RUnlock()
+	if dh.pOnuUpradeFsm != nil {
+		pImageState = dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion)
+	} else { //use the last stored ImageState (if the requested Imageversion coincides)
+		if aVersion == dh.pLastUpgradeImageState.Version {
+			pImageState = dh.pLastUpgradeImageState
+		} else { //state request for an image version different from last processed image version
+			pImageState = &voltha.ImageState{
+				Version: aVersion,
+				//we cannot state something concerning this version
+				DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN,
+				Reason:        voltha.ImageState_NO_ERROR,
+				ImageState:    voltha.ImageState_IMAGE_UNKNOWN,
+			}
+		}
+	}
+	return pImageState
+}
+
+func (dh *deviceHandler) cancelOnuSwUpgrade(ctx context.Context, aImageIdentifier string,
+	aVersion string, pDeviceImageState *voltha.DeviceImageState) {
+	pDeviceImageState.DeviceId = dh.DeviceID
+	pDeviceImageState.ImageState.Version = aVersion
+	dh.lockUpgradeFsm.RLock()
+	if dh.pOnuUpradeFsm != nil {
+		if aVersion == dh.pOnuUpradeFsm.GetImageVersion(ctx) {
+			// so then we cancel the upgrade operation
+			// but before we still request the actual ImageState (which should not change with the cancellation)
+			pDeviceImageState.ImageState.ImageState = dh.pOnuUpradeFsm.GetSpecificImageState(ctx)
+			dh.lockUpgradeFsm.RUnlock()
+			pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_CANCELLED
+			pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST
+			dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort
+		} else { //nothing to cancel, states unknown
+			dh.lockUpgradeFsm.RUnlock()
+			pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
+			pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
+			pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
+		}
+	} else {
+		// if no upgrade is ongoing, nothing is canceled and accordingly the states of the requested image are unknown
+		// reset also the dh handler LastUpgradeImageState (not relevant anymore/cleared)
+		(*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
+		(*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR
+		(*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN
+		(*dh.pLastUpgradeImageState).Version = "" //reset to 'no (relevant) upgrade done' (like initial state)
+		dh.lockUpgradeFsm.RUnlock()
+		pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
+		pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
+		pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
+		//an abort request to a not active upgrade processing can be used to reset the device upgrade states completely
+	}
+}
+
+func (dh *deviceHandler) getOnuImages(ctx context.Context) (*voltha.OnuImages, error) {
+
+	var onuImageStatus *swupg.OnuImageStatus
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+	if pDevEntry != nil {
+		onuImageStatus = swupg.NewOnuImageStatus(dh, pDevEntry)
+		pDevEntry.MutexOnuImageStatus.Lock()
+		pDevEntry.POnuImageStatus = onuImageStatus
+		pDevEntry.MutexOnuImageStatus.Unlock()
+
+	} else {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return nil, fmt.Errorf("no-valid-OnuDevice-aborting")
+	}
+	images, err := onuImageStatus.GetOnuImageStatus(ctx)
+	pDevEntry.MutexOnuImageStatus.Lock()
+	pDevEntry.POnuImageStatus = nil
+	pDevEntry.MutexOnuImageStatus.Unlock()
+	return images, err
+}
+
+//  deviceHandler methods that implement the adapters interface requests## end #########
+// #####################################################################################
+
+// ################  to be updated acc. needs of ONU Device ########################
+// deviceHandler StateMachine related state transition methods ##### begin #########
+
+func (dh *deviceHandler) logStateChange(ctx context.Context, e *fsm.Event) {
+	logger.Debugw(ctx, "Device FSM: ", log.Fields{"event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst), "device-id": dh.DeviceID})
+}
+
+// doStateInit provides the device update to the core
+func (dh *deviceHandler) doStateInit(ctx context.Context, e *fsm.Event) {
+
+	logger.Debug(ctx, "doStateInit-started")
+	var err error
+
+	// populate what we know.  rest comes later after mib sync
+	dh.device.Root = false
+	dh.device.Vendor = "OpenONU"
+	dh.device.Model = "go"
+	dh.device.Reason = cmn.DeviceReasonMap[cmn.DrActivatingOnu]
+	dh.SetDeviceReason(cmn.DrActivatingOnu)
+
+	dh.logicalDeviceID = dh.DeviceID // really needed - what for ??? //TODO!!!
+
+	if !dh.IsReconciling() {
+		logger.Infow(ctx, "DeviceUpdate", log.Fields{"deviceReason": dh.device.Reason, "device-id": dh.DeviceID})
+		if err := dh.updateDeviceInCore(ctx, dh.device); err != nil {
+			logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err})
+		}
+		//TODO Need to Update Device Reason To CORE as part of device update userstory
+	} else {
+		logger.Debugw(ctx, "reconciling - don't notify core about DeviceUpdate",
+			log.Fields{"device-id": dh.DeviceID})
+	}
+
+	dh.parentID = dh.device.ParentId
+	dh.ponPortNumber = dh.device.ParentPortNo
+
+	// store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!!
+	dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId()
+	dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType()
+	logger.Debugw(ctx, "device-updated", log.Fields{"device-id": dh.DeviceID, "proxyAddressID": dh.ProxyAddressID,
+		"proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber,
+		"ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber})
+
+	/*
+		self._pon = PonPort.create(self, self._pon_port_number)
+		self._pon.add_peer(self.parent_id, self._pon_port_number)
+		self.logger.debug('adding-pon-port-to-agent',
+				   type=self._pon.get_port().type,
+				   admin_state=self._pon.get_port().admin_state,
+				   oper_status=self._pon.get_port().oper_status,
+				   )
+	*/
+	if !dh.IsReconciling() {
+		logger.Debugw(ctx, "adding-pon-port", log.Fields{"device-id": dh.DeviceID, "ponPortNo": dh.ponPortNumber})
+		var ponPortNo uint32 = 1
+		if dh.ponPortNumber != 0 {
+			ponPortNo = dh.ponPortNumber
+		}
+
+		pPonPort := &voltha.Port{
+			DeviceId:   dh.DeviceID,
+			PortNo:     ponPortNo,
+			Label:      fmt.Sprintf("pon-%d", ponPortNo),
+			Type:       voltha.Port_PON_ONU,
+			OperStatus: voltha.OperStatus_ACTIVE,
+			Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device  is OLT
+				PortNo: ponPortNo}}, // Peer port is parent's port number
+		}
+		if err = dh.CreatePortInCore(ctx, pPonPort); err != nil {
+			logger.Fatalf(ctx, "Device FSM: PortCreated-failed-%s", err)
+			e.Cancel(err)
+			return
+		}
+	} else {
+		logger.Debugw(ctx, "reconciling - pon-port already added", log.Fields{"device-id": dh.DeviceID})
+	}
+	logger.Debug(ctx, "doStateInit-done")
+}
+
+// postInit setups the DeviceEntry for the conerned device
+func (dh *deviceHandler) postInit(ctx context.Context, e *fsm.Event) {
+
+	logger.Debug(ctx, "postInit-started")
+	var err error
+	/*
+		dh.Client = oop.NewOpenoltClient(dh.clientCon)
+		dh.pTransitionMap.Handle(ctx, GrpcConnected)
+		return nil
+	*/
+	if err = dh.addOnuDeviceEntry(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
+		logger.Fatalf(ctx, "Device FSM: addOnuDeviceEntry-failed-%s", err)
+		e.Cancel(err)
+		return
+	}
+
+	if dh.IsReconciling() {
+		go dh.reconcileDeviceOnuInd(ctx)
+		// reconcilement will be continued after mib download is done
+	}
+
+	/*
+			############################################################################
+			# Setup Alarm handler
+			self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
+										device.serial_number)
+			############################################################################
+			# Setup PM configuration for this device
+			# Pass in ONU specific options
+			kwargs = {
+				OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
+				'heartbeat': self.heartbeat,
+				OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
+			}
+			self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
+			self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
+										   self.logical_device_id, device.serial_number,
+										   grouped=True, freq_override=False, **kwargs)
+			pm_config = self._pm_metrics.make_proto()
+			self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
+			self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
+			yield self.core_proxy.device_pm_config_update(pm_config, init=True)
+
+			# Note, ONU ID and UNI intf set in add_uni_port method
+			self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
+																	  ani_ports=[self._pon])
+
+			# Code to Run OMCI Test Action
+			kwargs_omci_test_action = {
+				OmciTestRequest.DEFAULT_FREQUENCY_KEY:
+					OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
+			}
+			serial_number = device.serial_number
+			self._test_request = OmciTestRequest(self.core_proxy,
+										   self.omci_agent, self.device_id,
+										   AniG, serial_number,
+										   self.logical_device_id,
+										   exclusive=False,
+										   **kwargs_omci_test_action)
+
+			self.Enabled = True
+		else:
+			self.logger.info('onu-already-activated')
+	*/
+
+	logger.Debug(ctx, "postInit-done")
+}
+
+// doStateConnected get the device info and update to voltha core
+// for comparison of the original method (not that easy to uncomment): compare here:
+//  voltha-openolt-adapter/adaptercore/device_handler.go
+//  -> this one obviously initiates all communication interfaces of the device ...?
+func (dh *deviceHandler) doStateConnected(ctx context.Context, e *fsm.Event) {
+
+	logger.Debug(ctx, "doStateConnected-started")
+	err := errors.New("device FSM: function not implemented yet")
+	e.Cancel(err)
+	logger.Debug(ctx, "doStateConnected-done")
+}
+
+// doStateUp handle the onu up indication and update to voltha core
+func (dh *deviceHandler) doStateUp(ctx context.Context, e *fsm.Event) {
+
+	logger.Debug(ctx, "doStateUp-started")
+	err := errors.New("device FSM: function not implemented yet")
+	e.Cancel(err)
+	logger.Debug(ctx, "doStateUp-done")
+
+	/*
+		// Synchronous call to update device state - this method is run in its own go routine
+		if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE,
+			voltha.OperStatus_ACTIVE); err != nil {
+			logger.Errorw("Failed to update device with OLT UP indication", log.Fields{"device-id": dh.device.Id, "error": err})
+			return err
+		}
+		return nil
+	*/
+}
+
+// doStateDown handle the onu down indication
+func (dh *deviceHandler) doStateDown(ctx context.Context, e *fsm.Event) {
+
+	logger.Debug(ctx, "doStateDown-started")
+	var err error
+
+	device := dh.device
+	if device == nil {
+		/*TODO: needs to handle error scenarios */
+		logger.Errorw(ctx, "Failed to fetch handler device", log.Fields{"device-id": dh.DeviceID})
+		e.Cancel(err)
+		return
+	}
+
+	cloned := proto.Clone(device).(*voltha.Device)
+	logger.Debugw(ctx, "do-state-down", log.Fields{"ClonedDeviceID": cloned.Id})
+	/*
+		// Update the all ports state on that device to disable
+		if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil {
+			logger.Errorw("updating-ports-failed", log.Fields{"device-id": device.Id, "error": er})
+			return er
+		}
+
+		//Update the device oper state and connection status
+		cloned.OperStatus = voltha.OperStatus_UNKNOWN
+		cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE
+		dh.device = cloned
+
+		if er := dh.coreProxy.DeviceStateUpdate(ctx, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil {
+			logger.Errorw("error-updating-device-state", log.Fields{"device-id": device.Id, "error": er})
+			return er
+		}
+
+		//get the child device for the parent device
+		onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id)
+		if err != nil {
+			logger.Errorw("failed to get child devices information", log.Fields{"device-id": dh.device.Id, "error": err})
+			return err
+		}
+		for _, onuDevice := range onuDevices.Items {
+
+			// Update onu state as down in onu adapter
+			onuInd := oop.OnuIndication{}
+			onuInd.OperState = "down"
+			er := dh.adapterProxy.SendInterAdapterMessage(ctx, &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST,
+				"openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
+			if er != nil {
+				logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd,
+					"From Adapter": "openolt", "DevieType": onuDevice.Type, "device-id": onuDevice.Id})
+				//Do not return here and continue to process other ONUs
+			}
+		}
+		// * Discovered ONUs entries need to be cleared , since after OLT
+		//   is up, it starts sending discovery indications again* /
+		dh.discOnus = sync.Map{}
+		logger.Debugw("do-state-down-end", log.Fields{"device-id": device.Id})
+		return nil
+	*/
+	err = errors.New("device FSM: function not implemented yet")
+	e.Cancel(err)
+	logger.Debug(ctx, "doStateDown-done")
+}
+
+// deviceHandler StateMachine related state transition methods ##### end #########
+// #################################################################################
+
+// ###################################################
+// deviceHandler utility methods ##### begin #########
+
+//GetOnuDeviceEntry gets the ONU device entry and may wait until its value is defined
+func (dh *deviceHandler) GetOnuDeviceEntry(ctx context.Context, aWait bool) *mib.OnuDeviceEntry {
+	dh.lockDevice.RLock()
+	pOnuDeviceEntry := dh.pOnuOmciDevice
+	if aWait && pOnuDeviceEntry == nil {
+		//keep the read sema short to allow for subsequent write
+		dh.lockDevice.RUnlock()
+		logger.Debugw(ctx, "Waiting for DeviceEntry to be set ...", log.Fields{"device-id": dh.DeviceID})
+		// based on concurrent processing the deviceEntry setup may not yet be finished at his point
+		// so it might be needed to wait here for that event with some timeout
+		select {
+		case <-time.After(60 * time.Second): //timer may be discussed ...
+			logger.Errorw(ctx, "No valid DeviceEntry set after maxTime", log.Fields{"device-id": dh.DeviceID})
+			return nil
+		case <-dh.deviceEntrySet:
+			logger.Debugw(ctx, "devicEntry ready now - continue", log.Fields{"device-id": dh.DeviceID})
+			// if written now, we can return the written value without sema
+			return dh.pOnuOmciDevice
+		}
+	}
+	dh.lockDevice.RUnlock()
+	return pOnuDeviceEntry
+}
+
+//setDeviceHandlerEntries sets the ONU device entry within the handler
+func (dh *deviceHandler) setDeviceHandlerEntries(apDeviceEntry *mib.OnuDeviceEntry, apOnuTp *avcfg.OnuUniTechProf,
+	apOnuMetricsMgr *pmmgr.OnuMetricsManager, apOnuAlarmMgr *almgr.OnuAlarmManager, apSelfTestHdlr *otst.SelfTestControlBlock) {
+	dh.lockDevice.Lock()
+	defer dh.lockDevice.Unlock()
+	dh.pOnuOmciDevice = apDeviceEntry
+	dh.pOnuTP = apOnuTp
+	dh.pOnuMetricsMgr = apOnuMetricsMgr
+	dh.pAlarmMgr = apOnuAlarmMgr
+	dh.pSelfTestHdlr = apSelfTestHdlr
+}
+
+//addOnuDeviceEntry creates a new ONU device or returns the existing
+func (dh *deviceHandler) addOnuDeviceEntry(ctx context.Context) error {
+	logger.Debugw(ctx, "adding-deviceEntry", log.Fields{"device-id": dh.DeviceID})
+
+	deviceEntry := dh.GetOnuDeviceEntry(ctx, false)
+	if deviceEntry == nil {
+		/* costum_me_map in python code seems always to be None,
+		   we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/
+		/* also no 'clock' argument - usage open ...*/
+		/* and no alarm_db yet (oo.alarm_db)  */
+		deviceEntry = mib.NewOnuDeviceEntry(ctx, dh.coreClient, dh, dh.pOpenOnuAc)
+		onuTechProfProc := avcfg.NewOnuUniTechProf(ctx, dh, deviceEntry)
+		onuMetricsMgr := pmmgr.NewOnuMetricsManager(ctx, dh, deviceEntry)
+		onuAlarmManager := almgr.NewAlarmManager(ctx, dh, deviceEntry)
+		selfTestHdlr := otst.NewSelfTestMsgHandlerCb(ctx, dh, deviceEntry)
+		//error treatment possible //TODO!!!
+		dh.setDeviceHandlerEntries(deviceEntry, onuTechProfProc, onuMetricsMgr, onuAlarmManager, selfTestHdlr)
+		// fire deviceEntry ready event to spread to possibly waiting processing
+		dh.deviceEntrySet <- true
+		logger.Debugw(ctx, "onuDeviceEntry-added", log.Fields{"device-id": dh.DeviceID})
+	} else {
+		logger.Debugw(ctx, "onuDeviceEntry-add: Device already exists", log.Fields{"device-id": dh.DeviceID})
+	}
+	// might be updated with some error handling !!!
+	return nil
+}
+
+func (dh *deviceHandler) createInterface(ctx context.Context, onuind *oop.OnuIndication) error {
+	logger.Debugw(ctx, "create_interface-started", log.Fields{"OnuId": onuind.GetOnuId(),
+		"OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()})
+
+	dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient...
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
+	}
+	if !dh.IsReconciling() {
+		if err := dh.StorePersistentData(ctx); err != nil {
+			logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts",
+				log.Fields{"device-id": dh.DeviceID, "err": err})
+		}
+		logger.Debugw(ctx, "call DeviceStateUpdate upon create interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
+			"OperStatus": voltha.OperStatus_ACTIVATING, "device-id": dh.DeviceID})
+
+		if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
+			DeviceId:   dh.DeviceID,
+			OperStatus: voltha.OperStatus_ACTIVATING,
+			ConnStatus: voltha.ConnectStatus_REACHABLE,
+		}); err != nil {
+			//TODO with VOL-3045/VOL-3046: return the error and stop further processing
+			logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
+		}
+	} else {
+		logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVATING",
+			log.Fields{"device-id": dh.DeviceID})
+
+		pDevEntry.MutexPersOnuConfig.RLock()
+		if !pDevEntry.SOnuPersistentData.PersUniUnlockDone {
+			pDevEntry.MutexPersOnuConfig.RUnlock()
+			logger.Debugw(ctx, "reconciling - uni-ports were not unlocked before adapter restart - resume with a normal start-up",
+				log.Fields{"device-id": dh.DeviceID})
+			dh.StopReconciling(ctx, true)
+		} else {
+			pDevEntry.MutexPersOnuConfig.RUnlock()
+		}
+	}
+	// It does not look to me as if makes sense to work with the real core device here, (not the stored clone)?
+	// in this code the GetDevice would just make a check if the DeviceID's Device still exists in core
+	// in python code it looks as the started onu_omci_device might have been updated with some new instance state of the core device
+	// but I would not know why, and the go code anyway does not work with the device directly anymore in the mib.OnuDeviceEntry
+	// so let's just try to keep it simple ...
+	/*
+			device, err := dh.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx), dh.device.Id, dh.device.Id)
+		    if err != nil || device == nil {
+					//TODO: needs to handle error scenarios
+				logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err})
+				return errors.New("Voltha Device not found")
+			}
+	*/
+
+	if err := pDevEntry.Start(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
+		return err
+	}
+
+	_ = dh.deviceReasonUpdate(ctx, cmn.DrStartingOpenomci, !dh.IsReconciling())
+
+	/* this might be a good time for Omci Verify message?  */
+	verifyExec := make(chan bool)
+	omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx),
+		dh.device.Id, pDevEntry.PDevOmciCC,
+		true, true) //exclusive and allowFailure (anyway not yet checked)
+	omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec)
+
+	/* 	give the handler some time here to wait for the OMCi verification result
+	after Timeout start and try MibUpload FSM anyway
+	(to prevent stopping on just not supported OMCI verification from ONU) */
+	select {
+	case <-time.After(pDevEntry.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second):
+		logger.Warn(ctx, "omci start-verification timed out (continue normal)")
+	case testresult := <-verifyExec:
+		logger.Infow(ctx, "Omci start verification done", log.Fields{"result": testresult})
+	}
+
+	/* In py code it looks earlier (on activate ..)
+			# Code to Run OMCI Test Action
+			kwargs_omci_test_action = {
+				OmciTestRequest.DEFAULT_FREQUENCY_KEY:
+					OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
+			}
+			serial_number = device.serial_number
+			self._test_request = OmciTestRequest(self.core_proxy,
+											self.omci_agent, self.device_id,
+											AniG, serial_number,
+											self.logical_device_id,
+											exclusive=False,
+											**kwargs_omci_test_action)
+	...
+	                    # Start test requests after a brief pause
+	                    if not self._test_request_started:
+	                        self._test_request_started = True
+	                        tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
+	                        reactor.callLater(tststart, self._test_request.start_collector)
+
+	*/
+	/* which is then: in omci_test_request.py : */
+	/*
+	   def start_collector(self, callback=None):
+	       """
+	               Start the collection loop for an adapter if the frequency > 0
+
+	               :param callback: (callable) Function to call to collect PM data
+	       """
+	       self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq)
+	       if callback is None:
+	           callback = self.perform_test_omci
+
+	       if self.lc is None:
+	           self.lc = LoopingCall(callback)
+
+	       if self.default_freq > 0:
+	           self.lc.start(interval=self.default_freq / 10)
+
+	   def perform_test_omci(self):
+	       """
+	       Perform the initial test request
+	       """
+	       ani_g_entities = self._device.configuration.ani_g_entities
+	       ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \
+	                                                     is not None else None
+	       self._entity_id = ani_g_entities_ids[0]
+	       self.logger.info('perform-test', entity_class=self._entity_class,
+	                     entity_id=self._entity_id)
+	       try:
+	           frame = MEFrame(self._entity_class, self._entity_id, []).test()
+	           result = yield self._device.omci_cc.send(frame)
+	           if not result.fields['omci_message'].fields['success_code']:
+	               self.logger.info('Self-Test Submitted Successfully',
+	                             code=result.fields[
+	                                 'omci_message'].fields['success_code'])
+	           else:
+	               raise TestFailure('Test Failure: {}'.format(
+	                   result.fields['omci_message'].fields['success_code']))
+	       except TimeoutError as e:
+	           self.deferred.errback(failure.Failure(e))
+
+	       except Exception as e:
+	           self.logger.exception('perform-test-Error', e=e,
+	                              class_id=self._entity_class,
+	                              entity_id=self._entity_id)
+	           self.deferred.errback(failure.Failure(e))
+
+	*/
+
+	// PM related heartbeat??? !!!TODO....
+	//self._heartbeat.Enabled = True
+
+	/* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors
+	 * 	 within the MibUpload are not notified in the OnuIndication response, this might be acceptable here,
+	 *   as further OltAdapter processing may rely on the deviceReason event 'MibUploadDone' as a result of the FSM processing
+	 *   otherwise some processing synchronization would be required - cmp. e.g TechProfile processing
+	 */
+	//call MibUploadFSM - transition up to state UlStInSync
+	pMibUlFsm := pDevEntry.PMibUploadFsm.PFsm
+	if pMibUlFsm != nil {
+		if pMibUlFsm.Is(mib.UlStDisabled) {
+			if err := pMibUlFsm.Event(mib.UlEvStart); err != nil {
+				logger.Errorw(ctx, "MibSyncFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err})
+				return fmt.Errorf("can't go to state starting: %s", dh.DeviceID)
+			}
+			logger.Debugw(ctx, "MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())})
+			//Determine ONU status and start/re-start MIB Synchronization tasks
+			//Determine if this ONU has ever synchronized
+			if pDevEntry.IsNewOnu() {
+				if err := pMibUlFsm.Event(mib.UlEvResetMib); err != nil {
+					logger.Errorw(ctx, "MibSyncFsm: Can't go to state resetting_mib", log.Fields{"device-id": dh.DeviceID, "err": err})
+					return fmt.Errorf("can't go to state resetting_mib: %s", dh.DeviceID)
+				}
+			} else {
+				if err := pMibUlFsm.Event(mib.UlEvExamineMds); err != nil {
+					logger.Errorw(ctx, "MibSyncFsm: Can't go to state examine_mds", log.Fields{"device-id": dh.DeviceID, "err": err})
+					return fmt.Errorf("can't go to examine_mds: %s", dh.DeviceID)
+				}
+				logger.Debugw(ctx, "state of MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())})
+			}
+		} else {
+			logger.Errorw(ctx, "wrong state of MibSyncFsm - want: disabled", log.Fields{"have": string(pMibUlFsm.Current()),
+				"device-id": dh.DeviceID})
+			return fmt.Errorf("wrong state of MibSyncFsm: %s", dh.DeviceID)
+		}
+	} else {
+		logger.Errorw(ctx, "MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("can't execute MibSync: %s", dh.DeviceID)
+	}
+	return nil
+}
+
+func (dh *deviceHandler) updateInterface(ctx context.Context, onuind *oop.OnuIndication) error {
+	//state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down')
+	// (but note that the deviceReason may also have changed to e.g. TechProf*Delete_Success in between)
+	if dh.getDeviceReason() != cmn.DrStoppingOpenomci {
+		logger.Debugw(ctx, "updateInterface-started - stopping-device", log.Fields{"device-id": dh.DeviceID})
+
+		//stop all running FSM processing - make use of the DH-state as mirrored in the deviceReason
+		//here no conflict with aborted FSM's should arise as a complete OMCI initialization is assumed on ONU-Up
+		//but that might change with some simple MDS check on ONU-Up treatment -> attention!!!
+		if err := dh.resetFsms(ctx, true); err != nil {
+			logger.Errorw(ctx, "error-updateInterface at FSM stop",
+				log.Fields{"device-id": dh.DeviceID, "error": err})
+			// abort: system behavior is just unstable ...
+			return err
+		}
+		//all stored persistent data are not valid anymore (loosing knowledge about the connected ONU)
+		_ = dh.deleteDevicePersistencyData(ctx) //ignore possible errors here and continue, hope is that data is synchronized with new ONU-Up
+
+		//deviceEntry stop without omciCC reset here, regarding the OMCI_CC still valid for this ONU
+		// - in contrary to disableDevice - compare with processUniDisableStateDoneEvent
+		//stop the device entry which resets the attached omciCC
+		pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+		if pDevEntry == nil {
+			logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
+			return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
+		}
+		_ = pDevEntry.Stop(log.WithSpanFromContext(context.TODO(), ctx), false)
+
+		//TODO!!! remove existing traffic profiles
+		/* from py code, if TP's exist, remove them - not yet implemented
+		self._tp = dict()
+		# Let TP download happen again
+		for uni_id in self._tp_service_specific_task:
+			self._tp_service_specific_task[uni_id].clear()
+		for uni_id in self._tech_profile_download_done:
+			self._tech_profile_download_done[uni_id].clear()
+		*/
+
+		dh.DisableUniPortStateUpdate(ctx)
+
+		dh.SetReadyForOmciConfig(false)
+
+		if err := dh.deviceReasonUpdate(ctx, cmn.DrStoppingOpenomci, true); err != nil {
+			// abort: system behavior is just unstable ...
+			return err
+		}
+		logger.Debugw(ctx, "call DeviceStateUpdate upon update interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_UNREACHABLE,
+			"OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID})
+		if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
+			DeviceId:   dh.DeviceID,
+			ConnStatus: voltha.ConnectStatus_UNREACHABLE,
+			OperStatus: voltha.OperStatus_DISCOVERED,
+		}); err != nil {
+			//TODO with VOL-3045/VOL-3046: return the error and stop further processing
+			logger.Errorw(ctx, "error-updating-device-state unreachable-discovered",
+				log.Fields{"device-id": dh.DeviceID, "error": err})
+			// abort: system behavior is just unstable ...
+			return err
+		}
+	} else {
+		logger.Debugw(ctx, "updateInterface - device already stopped", log.Fields{"device-id": dh.DeviceID})
+	}
+	return nil
+}
+
+func (dh *deviceHandler) resetFsms(ctx context.Context, includingMibSyncFsm bool) error {
+	//all possible FSM's are stopped or reset here to ensure their transition to 'disabled'
+	//it is not sufficient to stop/reset the latest running FSM as done in previous versions
+	//  as after down/up procedures all FSM's might be active/ongoing (in theory)
+	//  and using the stop/reset event should never harm
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
+	}
+	if pDevEntry.PDevOmciCC != nil {
+		pDevEntry.PDevOmciCC.CancelRequestMonitoring(ctx)
+	}
+	pDevEntry.MutexOnuImageStatus.RLock()
+	if pDevEntry.POnuImageStatus != nil {
+		pDevEntry.POnuImageStatus.CancelProcessing(ctx)
+	}
+	pDevEntry.MutexOnuImageStatus.RUnlock()
+
+	if includingMibSyncFsm {
+		pDevEntry.CancelProcessing(ctx)
+	}
+	//MibDownload may run
+	pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm
+	if pMibDlFsm != nil {
+		_ = pMibDlFsm.Event(mib.DlEvReset)
+	}
+	//port lock/unlock FSM's may be active
+	if dh.pUnlockStateFsm != nil {
+		_ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
+	}
+	if dh.pLockStateFsm != nil {
+		_ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
+	}
+	//techProfile related PonAniConfigFsm FSM may be active
+	if dh.pOnuTP != nil {
+		// should always be the case here
+		// FSM  stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
+		if dh.pOnuTP.PAniConfigFsm != nil {
+			for uniTP := range dh.pOnuTP.PAniConfigFsm {
+				dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(ctx)
+			}
+		}
+		for _, uniPort := range dh.uniEntityMap {
+			// reset the possibly existing VlanConfigFsm
+			dh.lockVlanConfig.RLock()
+			if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.UniID]; exist {
+				//VlanFilterFsm exists and was already started
+				dh.lockVlanConfig.RUnlock()
+				//reset of all Fsm is always accompanied by global persistency data removal
+				//  no need to remove specific data
+				pVlanFilterFsm.RequestClearPersistency(false)
+				//ensure the FSM processing is stopped in case waiting for some response
+				pVlanFilterFsm.CancelProcessing(ctx)
+			} else {
+				dh.lockVlanConfig.RUnlock()
+			}
+		}
+	}
+	if dh.GetCollectorIsRunning() {
+		// Stop collector routine
+		dh.stopCollector <- true
+	}
+	if dh.GetAlarmManagerIsRunning(ctx) {
+		dh.stopAlarmManager <- true
+	}
+	if dh.pSelfTestHdlr.GetSelfTestHandlerIsRunning() {
+		dh.pSelfTestHdlr.StopSelfTestModule <- true
+	}
+
+	//reset a possibly running upgrade FSM
+	//  (note the Upgrade FSM may stay alive e.g. in state UpgradeStWaitForCommit to endure the ONU reboot)
+	dh.lockUpgradeFsm.RLock()
+	lopOnuUpradeFsm := dh.pOnuUpradeFsm
+	//lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm()
+	dh.lockUpgradeFsm.RUnlock()
+	if lopOnuUpradeFsm != nil {
+		lopOnuUpradeFsm.CancelProcessing(ctx, false, voltha.ImageState_CANCELLED_ON_ONU_STATE) //conditional cancel
+	}
+
+	logger.Infow(ctx, "resetFsms done", log.Fields{"device-id": dh.DeviceID})
+	return nil
+}
+
+func (dh *deviceHandler) processMibDatabaseSyncEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
+	logger.Debugw(ctx, "MibInSync event received, adding uni ports and locking the ONU interfaces", log.Fields{"device-id": dh.DeviceID})
+
+	// store persistent data collected during MIB upload processing
+	if err := dh.StorePersistentData(ctx); err != nil {
+		logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts",
+			log.Fields{"device-id": dh.DeviceID, "err": err})
+	}
+	_ = dh.deviceReasonUpdate(ctx, cmn.DrDiscoveryMibsyncComplete, !dh.IsReconciling())
+	dh.AddAllUniPorts(ctx)
+
+	/* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here */
+	/* 201117: build_dt-berlin-pod-openonugo_1T8GEM_voltha_DT_openonugo_master_test runs into error TC
+	 *    'Test Disable ONUs and OLT Then Delete ONUs and OLT for DT' with Sercom ONU, which obviously needs
+	 *    disable/enable toggling here to allow traffic
+	 *    but moreover it might be useful for tracking the interface operState changes if this will be implemented,
+	 *    like the py comment says:
+	 *      # start by locking all the unis till mib sync and initial mib is downloaded
+	 *      # this way we can capture the port down/up events when we are ready
+	 */
+
+	// Init Uni Ports to Admin locked state
+	// *** should generate UniLockStateDone event *****
+	if dh.pLockStateFsm == nil {
+		dh.createUniLockFsm(ctx, true, cmn.UniLockStateDone)
+	} else { //LockStateFSM already init
+		dh.pLockStateFsm.SetSuccessEvent(cmn.UniLockStateDone)
+		dh.runUniLockFsm(ctx, true)
+	}
+}
+
+func (dh *deviceHandler) processUniLockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
+	logger.Infow(ctx, "UniLockStateDone event: Starting MIB download", log.Fields{"device-id": dh.DeviceID})
+	/*  Mib download procedure -
+	***** should run over 'downloaded' state and generate MibDownloadDone event *****
+	 */
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return
+	}
+	pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm
+	if pMibDlFsm != nil {
+		if pMibDlFsm.Is(mib.DlStDisabled) {
+			if err := pMibDlFsm.Event(mib.DlEvStart); err != nil {
+				logger.Errorw(ctx, "MibDownloadFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err})
+				// maybe try a FSM reset and then again ... - TODO!!!
+			} else {
+				logger.Debugw(ctx, "MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())})
+				// maybe use more specific states here for the specific download steps ...
+				if err := pMibDlFsm.Event(mib.DlEvCreateGal); err != nil {
+					logger.Errorw(ctx, "MibDownloadFsm: Can't start CreateGal", log.Fields{"device-id": dh.DeviceID, "err": err})
+				} else {
+					logger.Debugw(ctx, "state of MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())})
+					//Begin MIB data download (running autonomously)
+				}
+			}
+		} else {
+			logger.Errorw(ctx, "wrong state of MibDownloadFsm - want: disabled", log.Fields{"have": string(pMibDlFsm.Current()),
+				"device-id": dh.DeviceID})
+			// maybe try a FSM reset and then again ... - TODO!!!
+		}
+		/***** Mib download started */
+	} else {
+		logger.Errorw(ctx, "MibDownloadFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
+	}
+}
+
+func (dh *deviceHandler) processMibDownloadDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
+	logger.Debugw(ctx, "MibDownloadDone event received, unlocking the ONU interfaces", log.Fields{"device-id": dh.DeviceID})
+	//initiate DevStateUpdate
+	if !dh.IsReconciling() {
+		logger.Debugw(ctx, "call DeviceStateUpdate upon mib-download done", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
+			"OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID})
+		//we allow a possible OnuSw image commit only in the normal startup, not at reconciling
+		// in case of adapter restart connected to an ONU upgrade I would not rely on the image quality
+		// maybe some 'forced' commitment can be done in this situation from system management (or upgrade restarted)
+		dh.checkOnOnuImageCommit(ctx)
+		if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
+			DeviceId:   dh.DeviceID,
+			ConnStatus: voltha.ConnectStatus_REACHABLE,
+			OperStatus: voltha.OperStatus_ACTIVE,
+		}); err != nil {
+			//TODO with VOL-3045/VOL-3046: return the error and stop further processing
+			logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
+		} else {
+			logger.Debugw(ctx, "dev state updated to 'Oper.Active'", log.Fields{"device-id": dh.DeviceID})
+		}
+	} else {
+		logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVE",
+			log.Fields{"device-id": dh.DeviceID})
+	}
+	_ = dh.deviceReasonUpdate(ctx, cmn.DrInitialMibDownloaded, !dh.IsReconciling())
+
+	if !dh.GetCollectorIsRunning() {
+		// Start PM collector routine
+		go dh.StartCollector(ctx)
+	}
+	if !dh.GetAlarmManagerIsRunning(ctx) {
+		go dh.StartAlarmManager(ctx)
+	}
+
+	// Initialize classical L2 PM Interval Counters
+	if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventInit); err != nil {
+		// There is no way we should be landing here, but if we do then
+		// there is nothing much we can do about this other than log error
+		logger.Errorw(ctx, "error starting l2 pm fsm", log.Fields{"device-id": dh.device.Id, "err": err})
+	}
+
+	dh.SetReadyForOmciConfig(true)
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return
+	}
+	pDevEntry.MutexPersOnuConfig.RLock()
+	if dh.IsReconciling() && pDevEntry.SOnuPersistentData.PersUniDisableDone {
+		pDevEntry.MutexPersOnuConfig.RUnlock()
+		logger.Debugw(ctx, "reconciling - uni-ports were disabled by admin before adapter restart - keep the ports locked",
+			log.Fields{"device-id": dh.DeviceID})
+		go dh.ReconcileDeviceTechProf(ctx)
+		// reconcilement will be continued after ani config is done
+	} else {
+		pDevEntry.MutexPersOnuConfig.RUnlock()
+		// *** should generate UniUnlockStateDone event *****
+		if dh.pUnlockStateFsm == nil {
+			dh.createUniLockFsm(ctx, false, cmn.UniUnlockStateDone)
+		} else { //UnlockStateFSM already init
+			dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniUnlockStateDone)
+			dh.runUniLockFsm(ctx, false)
+		}
+	}
+}
+
+func (dh *deviceHandler) processUniUnlockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
+	dh.EnableUniPortStateUpdate(ctx) //cmp python yield self.enable_ports()
+
+	if !dh.IsReconciling() {
+		logger.Infow(ctx, "UniUnlockStateDone event: Sending OnuUp event", log.Fields{"device-id": dh.DeviceID})
+		raisedTs := time.Now().Unix()
+		go dh.sendOnuOperStateEvent(ctx, voltha.OperStatus_ACTIVE, dh.DeviceID, raisedTs) //cmp python onu_active_event
+		pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+		if pDevEntry == nil {
+			logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+			return
+		}
+		pDevEntry.MutexPersOnuConfig.Lock()
+		pDevEntry.SOnuPersistentData.PersUniUnlockDone = true
+		pDevEntry.MutexPersOnuConfig.Unlock()
+		if err := dh.StorePersistentData(ctx); err != nil {
+			logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
+				log.Fields{"device-id": dh.DeviceID, "err": err})
+		}
+	} else {
+		logger.Debugw(ctx, "reconciling - don't notify core that onu went to active but trigger tech profile config",
+			log.Fields{"device-id": dh.DeviceID})
+		go dh.ReconcileDeviceTechProf(ctx)
+		// reconcilement will be continued after ani config is done
+	}
+}
+
+func (dh *deviceHandler) processUniDisableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
+	logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
+		"OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID})
+
+	if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
+		DeviceId:   dh.DeviceID,
+		ConnStatus: voltha.ConnectStatus_REACHABLE,
+		OperStatus: voltha.OperStatus_UNKNOWN,
+	}); err != nil {
+		//TODO with VOL-3045/VOL-3046: return the error and stop further processing
+		logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
+	}
+
+	logger.Debugw(ctx, "DeviceReasonUpdate upon disable", log.Fields{"reason": cmn.DeviceReasonMap[cmn.DrOmciAdminLock], "device-id": dh.DeviceID})
+	// DeviceReason to update acc.to modified py code as per beginning of Sept 2020
+	_ = dh.deviceReasonUpdate(ctx, cmn.DrOmciAdminLock, true)
+
+	//transfer the modified logical uni port state
+	dh.DisableUniPortStateUpdate(ctx)
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return
+	}
+	pDevEntry.MutexPersOnuConfig.Lock()
+	pDevEntry.SOnuPersistentData.PersUniDisableDone = true
+	pDevEntry.MutexPersOnuConfig.Unlock()
+	if err := dh.StorePersistentData(ctx); err != nil {
+		logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
+			log.Fields{"device-id": dh.DeviceID, "err": err})
+	}
+}
+
+func (dh *deviceHandler) processUniEnableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
+	logger.Debugw(ctx, "DeviceStateUpdate upon re-enable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
+		"OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID})
+	if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
+		DeviceId:   dh.DeviceID,
+		ConnStatus: voltha.ConnectStatus_REACHABLE,
+		OperStatus: voltha.OperStatus_ACTIVE,
+	}); err != nil {
+		//TODO with VOL-3045/VOL-3046: return the error and stop further processing
+		logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
+	}
+
+	logger.Debugw(ctx, "DeviceReasonUpdate upon re-enable", log.Fields{
+		"reason": cmn.DeviceReasonMap[cmn.DrOnuReenabled], "device-id": dh.DeviceID})
+	// DeviceReason to update acc.to modified py code as per beginning of Sept 2020
+	_ = dh.deviceReasonUpdate(ctx, cmn.DrOnuReenabled, true)
+
+	//transfer the modified logical uni port state
+	dh.EnableUniPortStateUpdate(ctx)
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return
+	}
+	pDevEntry.MutexPersOnuConfig.Lock()
+	pDevEntry.SOnuPersistentData.PersUniDisableDone = false
+	pDevEntry.MutexPersOnuConfig.Unlock()
+	if err := dh.StorePersistentData(ctx); err != nil {
+		logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
+			log.Fields{"device-id": dh.DeviceID, "err": err})
+	}
+}
+
+func (dh *deviceHandler) processOmciAniConfigDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
+	if devEvent == cmn.OmciAniConfigDone {
+		logger.Debugw(ctx, "OmciAniConfigDone event received", log.Fields{"device-id": dh.DeviceID})
+		// attention: the device reason update is done based on ONU-UNI-Port related activity
+		//  - which may cause some inconsistency
+		if dh.getDeviceReason() != cmn.DrTechProfileConfigDownloadSuccess {
+			// which may be the case from some previous actvity even on this UNI Port (but also other UNI ports)
+			_ = dh.deviceReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, !dh.IsReconciling())
+		}
+		if dh.IsReconciling() {
+			go dh.ReconcileDeviceFlowConfig(ctx)
+		}
+	} else { // should be the OmciAniResourceRemoved block
+		logger.Debugw(ctx, "OmciAniResourceRemoved event received", log.Fields{"device-id": dh.DeviceID})
+		// attention: the device reason update is done based on ONU-UNI-Port related activity
+		//  - which may cause some inconsistency
+		if dh.getDeviceReason() != cmn.DrTechProfileConfigDeleteSuccess {
+			// which may be the case from some previous actvity even on this ONU port (but also other UNI ports)
+			_ = dh.deviceReasonUpdate(ctx, cmn.DrTechProfileConfigDeleteSuccess, true)
+		}
+	}
+}
+
+func (dh *deviceHandler) processOmciVlanFilterDoneEvent(ctx context.Context, aDevEvent cmn.OnuDeviceEvent) {
+	logger.Debugw(ctx, "OmciVlanFilterDone event received",
+		log.Fields{"device-id": dh.DeviceID, "event": aDevEvent})
+	// attention: the device reason update is done based on ONU-UNI-Port related activity
+	//  - which may cause some inconsistency
+
+	if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterAddDoneNoKvStore {
+		if dh.getDeviceReason() != cmn.DrOmciFlowsPushed {
+			// which may be the case from some previous actvity on another UNI Port of the ONU
+			// or even some previous flow add activity on the same port
+			_ = dh.deviceReasonUpdate(ctx, cmn.DrOmciFlowsPushed, !dh.IsReconciling())
+			if dh.IsReconciling() {
+				go dh.reconcileEnd(ctx)
+			}
+		}
+	} else {
+		if dh.getDeviceReason() != cmn.DrOmciFlowsDeleted {
+			//not relevant for reconcile
+			_ = dh.deviceReasonUpdate(ctx, cmn.DrOmciFlowsDeleted, true)
+		}
+	}
+
+	if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterRemDone {
+		//events that request KvStore write
+		if err := dh.StorePersistentData(ctx); err != nil {
+			logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
+				log.Fields{"device-id": dh.DeviceID, "err": err})
+		}
+	} else {
+		logger.Debugw(ctx, "OmciVlanFilter*Done* - write to KvStore not requested",
+			log.Fields{"device-id": dh.DeviceID})
+	}
+}
+
+//DeviceProcStatusUpdate evaluates possible processing events and initiates according next activities
+func (dh *deviceHandler) DeviceProcStatusUpdate(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
+	switch devEvent {
+	case cmn.MibDatabaseSync:
+		{
+			dh.processMibDatabaseSyncEvent(ctx, devEvent)
+		}
+	case cmn.UniLockStateDone:
+		{
+			dh.processUniLockStateDoneEvent(ctx, devEvent)
+		}
+	case cmn.MibDownloadDone:
+		{
+			dh.processMibDownloadDoneEvent(ctx, devEvent)
+		}
+	case cmn.UniUnlockStateDone:
+		{
+			dh.processUniUnlockStateDoneEvent(ctx, devEvent)
+		}
+	case cmn.UniEnableStateDone:
+		{
+			dh.processUniEnableStateDoneEvent(ctx, devEvent)
+		}
+	case cmn.UniDisableStateDone:
+		{
+			dh.processUniDisableStateDoneEvent(ctx, devEvent)
+		}
+	case cmn.OmciAniConfigDone, cmn.OmciAniResourceRemoved:
+		{
+			dh.processOmciAniConfigDoneEvent(ctx, devEvent)
+		}
+	case cmn.OmciVlanFilterAddDone, cmn.OmciVlanFilterAddDoneNoKvStore, cmn.OmciVlanFilterRemDone, cmn.OmciVlanFilterRemDoneNoKvStore:
+		{
+			dh.processOmciVlanFilterDoneEvent(ctx, devEvent)
+		}
+	default:
+		{
+			logger.Debugw(ctx, "unhandled-device-event", log.Fields{"device-id": dh.DeviceID, "event": devEvent})
+		}
+	} //switch
+}
+
+func (dh *deviceHandler) addUniPort(ctx context.Context, aUniInstNo uint16, aUniID uint8, aPortType cmn.UniPortType) {
+	// parameters are IntfId, OnuId, uniId
+	uniNo := mkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(),
+		uint32(aUniID))
+	if _, present := dh.uniEntityMap[uniNo]; present {
+		logger.Warnw(ctx, "OnuUniPort-add: Port already exists", log.Fields{"for InstanceId": aUniInstNo})
+	} else {
+		//with arguments aUniID, a_portNo, aPortType
+		pUniPort := cmn.NewOnuUniPort(ctx, aUniID, uniNo, aUniInstNo, aPortType)
+		if pUniPort == nil {
+			logger.Warnw(ctx, "OnuUniPort-add: Could not create Port", log.Fields{"for InstanceId": aUniInstNo})
+		} else {
+			//store UniPort with the System-PortNumber key
+			dh.uniEntityMap[uniNo] = pUniPort
+			if !dh.IsReconciling() {
+				// create announce the UniPort to the core as VOLTHA Port object
+				if err := pUniPort.CreateVolthaPort(ctx, dh); err == nil {
+					logger.Infow(ctx, "OnuUniPort-added", log.Fields{"for PortNo": uniNo})
+				} //error logging already within UniPort method
+			} else {
+				logger.Debugw(ctx, "reconciling - OnuUniPort already added", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID})
+			}
+		}
+	}
+}
+
+func (dh *deviceHandler) AddAllUniPorts(ctx context.Context) {
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return
+	}
+	i := uint8(0) //UNI Port limit: see MaxUnisPerOnu (by now 16) (OMCI supports max 255 p.b.)
+	if pptpInstKeys := pDevEntry.GetOnuDB().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, cmn.UniPPTP)
+			i++
+		}
+	} else {
+		logger.Debugw(ctx, "No PPTP instances found", log.Fields{"device-id": dh.DeviceID})
+	}
+	if veipInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(
+		ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 {
+		for _, mgmtEntityID := range veipInstKeys {
+			logger.Debugw(ctx, "Add VEIP for MIB-stored instance:", log.Fields{
+				"device-id": dh.DeviceID, "VEIP EntityID": mgmtEntityID})
+			dh.addUniPort(ctx, mgmtEntityID, i, cmn.UniVEIP)
+			i++
+		}
+	} else {
+		logger.Debugw(ctx, "No VEIP instances found", log.Fields{"device-id": dh.DeviceID})
+	}
+	if potsInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(
+		ctx, me.PhysicalPathTerminationPointPotsUniClassID); len(potsInstKeys) > 0 {
+		for _, mgmtEntityID := range potsInstKeys {
+			logger.Debugw(ctx, "Add PPTP Pots UNI for MIB-stored instance:", log.Fields{
+				"device-id": dh.DeviceID, "PPTP Pots UNI EntityID": mgmtEntityID})
+			dh.addUniPort(ctx, mgmtEntityID, i, cmn.UniPPTPPots)
+			i++
+		}
+	} else {
+		logger.Debugw(ctx, "No PPTP Pots UNI instances found", log.Fields{"device-id": dh.DeviceID})
+	}
+	if i == 0 {
+		logger.Warnw(ctx, "No UniG instances found", log.Fields{"device-id": dh.DeviceID})
+	}
+}
+
+// EnableUniPortStateUpdate enables UniPortState and update core port state accordingly
+func (dh *deviceHandler) EnableUniPortStateUpdate(ctx context.Context) {
+	//  py code was updated 2003xx to activate the real ONU UNI ports per OMCI (VEIP or PPTP)
+	//    but towards core only the first port active state is signaled
+	//    with following remark:
+	//       # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
+	//       #  load on the core
+
+	// lock_ports(false) as done in py code here is shifted to separate call from device event processing
+
+	for uniNo, uniPort := range dh.uniEntityMap {
+		// only if this port is validated for operState transfer
+		if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) {
+			logger.Infow(ctx, "OnuUniPort-forced-OperState-ACTIVE", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID})
+			uniPort.SetOperState(vc.OperStatus_ACTIVE)
+			if !dh.IsReconciling() {
+				//maybe also use getter functions on uniPort - perhaps later ...
+				go func(port *cmn.OnuUniPort) {
+					if err := dh.updatePortStateInCore(ctx, &ic.PortState{
+						DeviceId:   dh.DeviceID,
+						PortType:   voltha.Port_ETHERNET_UNI,
+						PortNo:     port.PortNo,
+						OperStatus: port.OperState,
+					}); err != nil {
+						logger.Errorw(ctx, "port-state-update-failed", log.Fields{"error": err, "port-no": uniPort.PortNo, "device-id": dh.DeviceID})
+					}
+				}(uniPort)
+			} else {
+				logger.Debugw(ctx, "reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.DeviceID})
+			}
+		}
+	}
+}
+
+// Disable UniPortState and update core port state accordingly
+func (dh *deviceHandler) DisableUniPortStateUpdate(ctx context.Context) {
+	// compare EnableUniPortStateUpdate() above
+	//   -> use current restriction to operate only on first UNI port as inherited from actual Py code
+	for uniNo, uniPort := range dh.uniEntityMap {
+		// only if this port is validated for operState transfer
+
+		if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) {
+			logger.Infow(ctx, "OnuUniPort-forced-OperState-UNKNOWN", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID})
+			uniPort.SetOperState(vc.OperStatus_UNKNOWN)
+			if !dh.IsReconciling() {
+				//maybe also use getter functions on uniPort - perhaps later ...
+				go func(port *cmn.OnuUniPort) {
+					if err := dh.updatePortStateInCore(ctx, &ic.PortState{
+						DeviceId:   dh.DeviceID,
+						PortType:   voltha.Port_ETHERNET_UNI,
+						PortNo:     port.PortNo,
+						OperStatus: port.OperState,
+					}); err != nil {
+						logger.Errorw(ctx, "port-state-update-failed", log.Fields{"error": err, "port-no": uniPort.PortNo, "device-id": dh.DeviceID})
+					}
+				}(uniPort)
+			} else {
+				logger.Debugw(ctx, "reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.DeviceID})
+			}
+
+		}
+	}
+}
+
+// ONU_Active/Inactive announcement on system KAFKA bus
+// tried to re-use procedure of oltUpDownIndication from openolt_eventmgr.go with used values from Py code
+func (dh *deviceHandler) sendOnuOperStateEvent(ctx context.Context, aOperState vc.OperStatus_Types, aDeviceID string, raisedTs int64) {
+	var de voltha.DeviceEvent
+	eventContext := make(map[string]string)
+	//Populating event context
+	//  assume giving ParentId in GetDevice twice really gives the ParentDevice (there is no GetParentDevice()...)
+	parentDevice, err := dh.getDeviceFromCore(ctx, dh.parentID)
+	if err != nil || parentDevice == nil {
+		logger.Errorw(ctx, "Failed to fetch parent device for OnuEvent",
+			log.Fields{"parentID": dh.parentID, "err": err})
+		return //TODO with VOL-3045: rw-core is unresponsive: report error and/or perform self-initiated onu-reset?
+	}
+	oltSerialNumber := parentDevice.SerialNumber
+
+	eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10)
+	eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10)
+	eventContext["serial-number"] = dh.device.SerialNumber
+	eventContext["olt-serial-number"] = oltSerialNumber
+	eventContext["device-id"] = aDeviceID
+	eventContext["registration-id"] = aDeviceID //py: string(device_id)??
+	eventContext["num-of-unis"] = strconv.Itoa(len(dh.uniEntityMap))
+	if deviceEntry := dh.GetOnuDeviceEntry(ctx, false); deviceEntry != nil {
+		deviceEntry.MutexPersOnuConfig.RLock()
+		eventContext["equipment-id"] = deviceEntry.SOnuPersistentData.PersEquipmentID
+		deviceEntry.MutexPersOnuConfig.RUnlock()
+		eventContext["software-version"] = deviceEntry.GetActiveImageVersion(ctx)
+		deviceEntry.MutexPersOnuConfig.RLock()
+		eventContext["vendor"] = deviceEntry.SOnuPersistentData.PersVendorID
+		deviceEntry.MutexPersOnuConfig.RUnlock()
+		eventContext["inactive-software-version"] = deviceEntry.GetInactiveImageVersion(ctx)
+		logger.Debugw(ctx, "prepare ONU_ACTIVATED event",
+			log.Fields{"device-id": aDeviceID, "EventContext": eventContext})
+	} else {
+		logger.Errorw(ctx, "Failed to fetch device-entry. ONU_ACTIVATED event is not sent",
+			log.Fields{"device-id": aDeviceID})
+		return
+	}
+
+	/* Populating device event body */
+	de.Context = eventContext
+	de.ResourceId = aDeviceID
+	if aOperState == voltha.OperStatus_ACTIVE {
+		de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT")
+		de.Description = fmt.Sprintf("%s Event - %s - %s",
+			cEventObjectType, cOnuActivatedEvent, "Raised")
+	} else {
+		de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT")
+		de.Description = fmt.Sprintf("%s Event - %s - %s",
+			cEventObjectType, cOnuActivatedEvent, "Cleared")
+	}
+	/* Send event to KAFKA */
+	if err := dh.EventProxy.SendDeviceEvent(ctx, &de, equipment, pon, raisedTs); err != nil {
+		logger.Warnw(ctx, "could not send ONU_ACTIVATED event",
+			log.Fields{"device-id": aDeviceID, "error": err})
+	}
+	logger.Debugw(ctx, "ctx, ONU_ACTIVATED event sent to KAFKA",
+		log.Fields{"device-id": aDeviceID, "with-EventName": de.DeviceEventName})
+}
+
+// createUniLockFsm initializes and runs the UniLock FSM to transfer the OMCI related commands for port lock/unlock
+func (dh *deviceHandler) createUniLockFsm(ctx context.Context, aAdminState bool, devEvent cmn.OnuDeviceEvent) {
+	chLSFsm := make(chan cmn.Message, 2048)
+	var sFsmName string
+	if aAdminState {
+		logger.Debugw(ctx, "createLockStateFSM", log.Fields{"device-id": dh.DeviceID})
+		sFsmName = "LockStateFSM"
+	} else {
+		logger.Debugw(ctx, "createUnlockStateFSM", log.Fields{"device-id": dh.DeviceID})
+		sFsmName = "UnLockStateFSM"
+	}
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
+		return
+	}
+	pLSFsm := uniprt.NewLockStateFsm(ctx, aAdminState, devEvent, sFsmName, dh, pDevEntry, chLSFsm)
+	if pLSFsm != nil {
+		if aAdminState {
+			dh.pLockStateFsm = pLSFsm
+		} else {
+			dh.pUnlockStateFsm = pLSFsm
+		}
+		dh.runUniLockFsm(ctx, aAdminState)
+	} else {
+		logger.Errorw(ctx, "LockStateFSM could not be created - abort!!", log.Fields{"device-id": dh.DeviceID})
+	}
+}
+
+// runUniLockFsm starts the UniLock FSM to transfer the OMCI related commands for port lock/unlock
+func (dh *deviceHandler) runUniLockFsm(ctx context.Context, aAdminState bool) {
+	/*  Uni Port lock/unlock procedure -
+	 ***** should run via 'adminDone' state and generate the argument requested event *****
+	 */
+	var pLSStatemachine *fsm.FSM
+	if aAdminState {
+		pLSStatemachine = dh.pLockStateFsm.PAdaptFsm.PFsm
+		//make sure the opposite FSM is not running and if so, terminate it as not relevant anymore
+		if (dh.pUnlockStateFsm != nil) &&
+			(dh.pUnlockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) {
+			_ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
+		}
+	} else {
+		pLSStatemachine = dh.pUnlockStateFsm.PAdaptFsm.PFsm
+		//make sure the opposite FSM is not running and if so, terminate it as not relevant anymore
+		if (dh.pLockStateFsm != nil) &&
+			(dh.pLockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) {
+			_ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
+		}
+	}
+	if pLSStatemachine != nil {
+		if pLSStatemachine.Is(uniprt.UniStDisabled) {
+			if err := pLSStatemachine.Event(uniprt.UniEvStart); err != nil {
+				logger.Warnw(ctx, "LockStateFSM: can't start", log.Fields{"err": err})
+				// maybe try a FSM reset and then again ... - TODO!!!
+			} else {
+				/***** LockStateFSM started */
+				logger.Debugw(ctx, "LockStateFSM started", log.Fields{
+					"state": pLSStatemachine.Current(), "device-id": dh.DeviceID})
+			}
+		} else {
+			logger.Warnw(ctx, "wrong state of LockStateFSM - want: disabled", log.Fields{
+				"have": pLSStatemachine.Current(), "device-id": dh.DeviceID})
+			// maybe try a FSM reset and then again ... - TODO!!!
+		}
+	} else {
+		logger.Errorw(ctx, "LockStateFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
+		// maybe try a FSM reset and then again ... - TODO!!!
+	}
+}
+
+// createOnuUpgradeFsm initializes and runs the Onu Software upgrade FSM
+func (dh *deviceHandler) createOnuUpgradeFsm(ctx context.Context, apDevEntry *mib.OnuDeviceEntry, aDevEvent cmn.OnuDeviceEvent) error {
+	//in here lockUpgradeFsm is already locked
+	chUpgradeFsm := make(chan cmn.Message, 2048)
+	var sFsmName = "OnuSwUpgradeFSM"
+	logger.Debugw(ctx, "create OnuSwUpgradeFSM", log.Fields{"device-id": dh.DeviceID})
+	if apDevEntry.PDevOmciCC == nil {
+		logger.Errorw(ctx, "no valid OnuDevice or omciCC - abort", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf(fmt.Sprintf("no valid omciCC - abort for device-id: %s", dh.device.Id))
+	}
+	dh.pOnuUpradeFsm = swupg.NewOnuUpgradeFsm(ctx, dh, apDevEntry, apDevEntry.GetOnuDB(), aDevEvent,
+		sFsmName, chUpgradeFsm)
+	if dh.pOnuUpradeFsm != nil {
+		pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm
+		if pUpgradeStatemachine != nil {
+			if pUpgradeStatemachine.Is(swupg.UpgradeStDisabled) {
+				if err := pUpgradeStatemachine.Event(swupg.UpgradeEvStart); err != nil {
+					logger.Errorw(ctx, "OnuSwUpgradeFSM: can't start", log.Fields{"err": err})
+					// maybe try a FSM reset and then again ... - TODO!!!
+					return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s", dh.device.Id))
+				}
+				/***** LockStateFSM started */
+				//reset the last stored upgrade states
+				(*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_STARTED //already with updated state
+				(*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR
+				(*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN
+				logger.Debugw(ctx, "OnuSwUpgradeFSM started", log.Fields{
+					"state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID})
+			} else {
+				logger.Errorw(ctx, "wrong state of OnuSwUpgradeFSM to start - want: disabled", log.Fields{
+					"have": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID})
+				// maybe try a FSM reset and then again ... - TODO!!!
+				return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s, wrong internal state", dh.device.Id))
+			}
+		} else {
+			logger.Errorw(ctx, "OnuSwUpgradeFSM internal FSM invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
+			// maybe try a FSM reset and then again ... - TODO!!!
+			return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM internal FSM could not be created for device-id: %s", dh.device.Id))
+		}
+	} else {
+		logger.Errorw(ctx, "OnuSwUpgradeFSM could not be created  - abort", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be created - abort for device-id: %s", dh.device.Id))
+	}
+	return nil
+}
+
+// RemoveOnuUpgradeFsm clears the Onu Software upgrade FSM
+func (dh *deviceHandler) RemoveOnuUpgradeFsm(ctx context.Context, apImageState *voltha.ImageState) {
+	logger.Debugw(ctx, "remove OnuSwUpgradeFSM StateMachine", log.Fields{
+		"device-id": dh.DeviceID})
+	dh.lockUpgradeFsm.Lock()
+	dh.pOnuUpradeFsm = nil //resource clearing is left to garbage collector
+	dh.pLastUpgradeImageState = apImageState
+	dh.lockUpgradeFsm.Unlock()
+	//signal upgradeFsm removed using non-blocking channel send
+	select {
+	case dh.upgradeFsmChan <- struct{}{}:
+	default:
+		logger.Debugw(ctx, "removed-UpgradeFsm signal not send on upgradeFsmChan (no receiver)", log.Fields{
+			"device-id": dh.DeviceID})
+	}
+}
+
+// checkOnOnuImageCommit verifies if the ONU is in some upgrade state that allows for image commit and if tries to commit
+func (dh *deviceHandler) checkOnOnuImageCommit(ctx context.Context) {
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice -aborting checkOnOnuImageCommit", log.Fields{"device-id": dh.DeviceID})
+		return
+	}
+
+	dh.lockUpgradeFsm.RLock()
+	defer dh.lockUpgradeFsm.RUnlock()
+	if dh.pOnuUpradeFsm != nil {
+		pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm
+		if pUpgradeStatemachine != nil {
+			// commit is only processed in case out upgrade FSM indicates the according state (for automatic commit)
+			//  (some manual forced commit could do without)
+			UpgradeState := pUpgradeStatemachine.Current()
+			if (UpgradeState == swupg.UpgradeStWaitForCommit) ||
+				(UpgradeState == swupg.UpgradeStRequestingActivate) {
+				// also include UpgradeStRequestingActivate as it may be left in case the ActivateResponse just got lost
+				// here no need to update the upgrade image state to activated as the state will be immediately be set to committing
+				if pDevEntry.IsImageToBeCommitted(ctx, dh.pOnuUpradeFsm.InactiveImageMeID) {
+					activeImageID, errImg := pDevEntry.GetActiveImageMeID(ctx)
+					if errImg != nil {
+						logger.Errorw(ctx, "OnuSwUpgradeFSM abort - could not get active image after reboot",
+							log.Fields{"device-id": dh.DeviceID})
+						dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort
+						return
+					}
+					if activeImageID == dh.pOnuUpradeFsm.InactiveImageMeID {
+						if (UpgradeState == swupg.UpgradeStRequestingActivate) && !dh.pOnuUpradeFsm.GetCommitFlag(ctx) {
+							// if FSM was waiting on activateResponse, new image is active, but FSM shall not commit, then:
+							if err := pUpgradeStatemachine.Event(swupg.UpgradeEvActivationDone); err != nil {
+								logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call activate-done event", log.Fields{"err": err})
+								return
+							}
+							logger.Debugw(ctx, "OnuSwUpgradeFSM activate-done after reboot", log.Fields{
+								"state": UpgradeState, "device-id": dh.DeviceID})
+						} else {
+							//FSM in waitForCommit or (UpgradeStRequestingActivate [lost ActivateResp] and commit allowed)
+							if err := pUpgradeStatemachine.Event(swupg.UpgradeEvCommitSw); err != nil {
+								logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call commit event", log.Fields{"err": err})
+								return
+							}
+							logger.Debugw(ctx, "OnuSwUpgradeFSM commit image requested", log.Fields{
+								"state": UpgradeState, "device-id": dh.DeviceID})
+						}
+					} else {
+						logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit/on ActivateResponse, but load did not start with expected image Id",
+							log.Fields{"device-id": dh.DeviceID})
+						dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort
+						return
+					}
+				} else {
+					logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit, but nothing to commit on ONU - abort upgrade",
+						log.Fields{"device-id": dh.DeviceID})
+					dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort
+					return
+				}
+			} else {
+				//upgrade FSM is active but not waiting for commit: maybe because commit flag is not set
+				// upgrade FSM is to be informed if the current active image is the one that was used in upgrade for the download
+				if activeImageID, err := pDevEntry.GetActiveImageMeID(ctx); err == nil {
+					if dh.pOnuUpradeFsm.InactiveImageMeID == activeImageID {
+						logger.Debugw(ctx, "OnuSwUpgradeFSM image state set to activated", log.Fields{
+							"state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID})
+						dh.pOnuUpradeFsm.SetImageStateActive(ctx)
+					}
+				}
+			}
+		}
+	} else {
+		logger.Debugw(ctx, "no ONU image to be committed", log.Fields{"device-id": dh.DeviceID})
+	}
+}
+
+//SetBackend provides a DB backend for the specified path on the existing KV client
+func (dh *deviceHandler) SetBackend(ctx context.Context, aBasePathKvStore string) *db.Backend {
+
+	logger.Debugw(ctx, "SetKVStoreBackend", log.Fields{"IpTarget": dh.pOpenOnuAc.KVStoreAddress,
+		"BasePathKvStore": aBasePathKvStore, "device-id": dh.DeviceID})
+	// kvbackend := db.NewBackend(ctx, dh.pOpenOnuAc.KVStoreType, dh.pOpenOnuAc.KVStoreAddress, dh.pOpenOnuAc.KVStoreTimeout, aBasePathKvStore)
+	kvbackend := &db.Backend{
+		Client:    dh.pOpenOnuAc.kvClient,
+		StoreType: dh.pOpenOnuAc.KVStoreType,
+		/* address config update acc. to [VOL-2736] */
+		Address:    dh.pOpenOnuAc.KVStoreAddress,
+		Timeout:    dh.pOpenOnuAc.KVStoreTimeout,
+		PathPrefix: aBasePathKvStore}
+
+	return kvbackend
+}
+func (dh *deviceHandler) getFlowOfbFields(ctx context.Context, apFlowItem *of.OfpFlowStats, loMatchVlan *uint16,
+	loAddPcp *uint8, loIPProto *uint32) {
+
+	for _, field := range flow.GetOfbFields(apFlowItem) {
+		switch field.Type {
+		case of.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE:
+			{
+				logger.Debugw(ctx, "flow type EthType", log.Fields{"device-id": dh.DeviceID,
+					"EthType": strconv.FormatInt(int64(field.GetEthType()), 16)})
+			}
+		/* TT related temporary workaround - should not be needed anymore
+		case of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO:
+			{
+				*loIPProto = field.GetIpProto()
+				logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.DeviceID,
+					"IpProto": strconv.FormatInt(int64(*loIPProto), 16)})
+				if *loIPProto == 2 {
+					// some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow
+					// avoids installing invalid EVTOCD rule
+					logger.Debugw("flow type IpProto 2: TT workaround: ignore flow",
+						log.Fields{"device-id": dh.DeviceID})
+					return
+				}
+			}
+		*/
+		case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID:
+			{
+				*loMatchVlan = uint16(field.GetVlanVid())
+				loMatchVlanMask := uint16(field.GetVlanVidMask())
+				if !(*loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) &&
+					loMatchVlanMask == uint16(of.OfpVlanId_OFPVID_PRESENT)) {
+					*loMatchVlan = *loMatchVlan & 0xFFF // not transparent: copy only ID bits
+				}
+				logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
+					"VID": strconv.FormatInt(int64(*loMatchVlan), 16)})
+			}
+		case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP:
+			{
+				*loAddPcp = uint8(field.GetVlanPcp())
+				logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
+					"PCP": loAddPcp})
+			}
+		case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST:
+			{
+				logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
+					"UDP-DST": strconv.FormatInt(int64(field.GetUdpDst()), 16)})
+			}
+		case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC:
+			{
+				logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
+					"UDP-SRC": strconv.FormatInt(int64(field.GetUdpSrc()), 16)})
+			}
+		case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_DST:
+			{
+				logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
+					"IPv4-DST": field.GetIpv4Dst()})
+			}
+		case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_SRC:
+			{
+				logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
+					"IPv4-SRC": field.GetIpv4Src()})
+			}
+		case of.OxmOfbFieldTypes_OFPXMT_OFB_METADATA:
+			{
+				logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
+					"Metadata": field.GetTableMetadata()})
+			}
+			/*
+				default:
+					{
+						//all other entires ignored
+					}
+			*/
+		}
+	} //for all OfbFields
+}
+
+func (dh *deviceHandler) getFlowActions(ctx context.Context, apFlowItem *of.OfpFlowStats, loSetPcp *uint8, loSetVlan *uint16) {
+	for _, action := range flow.GetActions(apFlowItem) {
+		switch action.Type {
+		/* not used:
+		case of.OfpActionType_OFPAT_OUTPUT:
+			{
+				logger.Debugw("flow action type", log.Fields{"device-id": dh.DeviceID,
+					"Output": action.GetOutput()})
+			}
+		*/
+		case of.OfpActionType_OFPAT_PUSH_VLAN:
+			{
+				logger.Debugw(ctx, "flow action type", log.Fields{"device-id": dh.DeviceID,
+					"PushEthType": strconv.FormatInt(int64(action.GetPush().Ethertype), 16)})
+			}
+		case of.OfpActionType_OFPAT_SET_FIELD:
+			{
+				pActionSetField := action.GetSetField()
+				if pActionSetField.Field.OxmClass != of.OfpOxmClass_OFPXMC_OPENFLOW_BASIC {
+					logger.Warnw(ctx, "flow action SetField invalid OxmClass (ignored)", log.Fields{"device-id": dh.DeviceID,
+						"OxcmClass": pActionSetField.Field.OxmClass})
+				}
+				if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID {
+					*loSetVlan = uint16(pActionSetField.Field.GetOfbField().GetVlanVid())
+					logger.Debugw(ctx, "flow Set VLAN from SetField action", log.Fields{"device-id": dh.DeviceID,
+						"SetVlan": strconv.FormatInt(int64(*loSetVlan), 16)})
+				} else if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP {
+					*loSetPcp = uint8(pActionSetField.Field.GetOfbField().GetVlanPcp())
+					logger.Debugw(ctx, "flow Set PCP from SetField action", log.Fields{"device-id": dh.DeviceID,
+						"SetPcp": *loSetPcp})
+				} else {
+					logger.Warnw(ctx, "flow action SetField invalid FieldType", log.Fields{"device-id": dh.DeviceID,
+						"Type": pActionSetField.Field.GetOfbField().Type})
+				}
+			}
+			/*
+				default:
+					{
+						//all other entires ignored
+					}
+			*/
+		}
+	} //for all Actions
+}
+
+//addFlowItemToUniPort parses the actual flow item to add it to the UniPort
+func (dh *deviceHandler) addFlowItemToUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort,
+	apFlowMetaData *voltha.FlowMetadata) error {
+	var loSetVlan uint16 = uint16(of.OfpVlanId_OFPVID_NONE)      //noValidEntry
+	var loMatchVlan uint16 = uint16(of.OfpVlanId_OFPVID_PRESENT) //reserved VLANID entry
+	var loAddPcp, loSetPcp uint8
+	var loIPProto uint32
+	/* the TechProfileId is part of the flow Metadata - compare also comment within
+	 * OLT-Adapter:openolt_flowmgr.go
+	 *     Metadata 8 bytes:
+	 *	   Most Significant 2 Bytes = Inner VLAN
+	 *	   Next 2 Bytes = Tech Profile ID(TPID)
+	 *	   Least Significant 4 Bytes = Port ID
+	 *     Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all
+	 *     subscriber related flows.
+	 */
+
+	metadata := flow.GetMetadataFromWriteMetadataAction(ctx, apFlowItem)
+	if metadata == 0 {
+		logger.Debugw(ctx, "flow-add invalid metadata - abort",
+			log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("flow-add invalid metadata: %s", dh.DeviceID)
+	}
+	loTpID := uint8(flow.GetTechProfileIDFromWriteMetaData(ctx, metadata))
+	loCookie := apFlowItem.GetCookie()
+	loCookieSlice := []uint64{loCookie}
+	logger.Debugw(ctx, "flow-add base indications", log.Fields{"device-id": dh.DeviceID,
+		"TechProf-Id": loTpID, "cookie": loCookie})
+
+	dh.getFlowOfbFields(ctx, apFlowItem, &loMatchVlan, &loAddPcp, &loIPProto)
+	/* TT related temporary workaround - should not be needed anymore
+	if loIPProto == 2 {
+		// some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow
+		// avoids installing invalid EVTOCD rule
+		logger.Debugw("flow-add type IpProto 2: TT workaround: ignore flow",
+			log.Fields{"device-id": dh.DeviceID})
+		return nil
+	}
+	*/
+	dh.getFlowActions(ctx, apFlowItem, &loSetPcp, &loSetVlan)
+
+	if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) {
+		logger.Errorw(ctx, "flow-add aborted - SetVlanId undefined, but MatchVid set", log.Fields{
+			"device-id": dh.DeviceID, "UniPort": apUniPort.PortNo,
+			"set_vid":   strconv.FormatInt(int64(loSetVlan), 16),
+			"match_vid": strconv.FormatInt(int64(loMatchVlan), 16)})
+		//TODO!!: Use DeviceId within the error response to rwCore
+		//  likewise also in other error response cases to calling components as requested in [VOL-3458]
+		return fmt.Errorf("flow-add Set/Match VlanId inconsistent: %s", dh.DeviceID)
+	}
+	if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) {
+		logger.Debugw(ctx, "flow-add vlan-any/copy", log.Fields{"device-id": dh.DeviceID})
+		loSetVlan = loMatchVlan //both 'transparent' (copy any)
+	} else {
+		//looks like OMCI value 4097 (copyFromOuter - for Uni double tagged) is not supported here
+		if loSetVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) {
+			// not set to transparent
+			loSetVlan &= 0x0FFF //mask VID bits as prerequisite for vlanConfigFsm
+		}
+		logger.Debugw(ctx, "flow-add vlan-set", log.Fields{"device-id": dh.DeviceID})
+	}
+
+	var meter *voltha.OfpMeterConfig
+	if apFlowMetaData != nil {
+		meter = apFlowMetaData.Meters[0]
+	}
+	//mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities
+	//  must be set including the execution of createVlanFilterFsm() to avoid unintended creation of FSM's
+	//  when different rules are requested concurrently for the same uni
+	//  (also vlan persistency data does not support multiple FSM's on the same UNI correctly!)
+	dh.lockVlanAdd.Lock()     //prevent multiple add activities to start in parallel
+	dh.lockVlanConfig.RLock() //read protection on UniVlanConfigFsmMap (removeFlowItemFromUniPort)
+	logger.Debugw(ctx, "flow-add got lock", log.Fields{"device-id": dh.DeviceID, "tpID": loTpID, "uniID": apUniPort.UniID})
+	if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist {
+		//SetUniFlowParams() may block on some rule that is suspended-to-add
+		//  in order to allow for according flow removal lockVlanConfig may only be used with RLock here
+		err := dh.UniVlanConfigFsmMap[apUniPort.UniID].SetUniFlowParams(ctx, loTpID, loCookieSlice,
+			loMatchVlan, loSetVlan, loSetPcp, false, meter)
+		dh.lockVlanConfig.RUnlock()
+		dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing
+		return err
+	}
+	dh.lockVlanConfig.RUnlock()
+	dh.lockVlanConfig.Lock() //createVlanFilterFsm should always be a non-blocking operation and requires r+w lock
+	err := dh.createVlanFilterFsm(ctx, apUniPort, loTpID, loCookieSlice,
+		loMatchVlan, loSetVlan, loSetPcp, cmn.OmciVlanFilterAddDone, false, meter)
+	dh.lockVlanConfig.Unlock()
+	dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing
+	return err
+}
+
+//removeFlowItemFromUniPort parses the actual flow item to remove it from the UniPort
+func (dh *deviceHandler) removeFlowItemFromUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort) error {
+	//optimization and assumption: the flow cookie uniquely identifies the flow and with that the internal rule
+	//hence only the cookie is used here to find the relevant flow and possibly remove the rule
+	//no extra check is done on the rule parameters
+	//accordingly the removal is done only once - for the first found flow with that cookie, even though
+	// at flow creation is not assured, that the same cookie is not configured for different flows - just assumed
+	//additionally it is assumed here, that removal can only be done for one cookie per flow in a sequence (different
+	// from addFlow - where at reconcilement multiple cookies per flow ) can be configured in one sequence)
+	// - some possible 'delete-all' sequence would have to be implemented separately (where the cookies are don't care anyway)
+	loCookie := apFlowItem.GetCookie()
+	logger.Debugw(ctx, "flow-remove base indications", log.Fields{"device-id": dh.DeviceID, "cookie": loCookie})
+
+	/* TT related temporary workaround - should not be needed anymore
+	for _, field := range flow.GetOfbFields(apFlowItem) {
+		if field.Type == of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO {
+			loIPProto := field.GetIpProto()
+			logger.Debugw(ctx, "flow type IpProto", log.Fields{"device-id": dh.DeviceID,
+				"IpProto": strconv.FormatInt(int64(loIPProto), 16)})
+			if loIPProto == 2 {
+				// some workaround for TT workflow on proto == 2 (IGMP trap) -> the flow was not added, no need to remove
+				logger.Debugw(ctx, "flow-remove type IpProto 2: TT workaround: ignore flow",
+					log.Fields{"device-id": dh.DeviceID})
+				return nil
+			}
+		}
+	} //for all OfbFields
+	*/
+
+	//mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities
+	dh.lockVlanConfig.RLock()
+	defer dh.lockVlanConfig.RUnlock()
+	logger.Debugw(ctx, "flow-remove got RLock", log.Fields{"device-id": dh.DeviceID, "uniID": apUniPort.UniID})
+	if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist {
+		return dh.UniVlanConfigFsmMap[apUniPort.UniID].RemoveUniFlowParams(ctx, loCookie)
+	}
+	logger.Debugw(ctx, "flow-remove called, but no flow is configured (no VlanConfigFsm, flow already removed) ",
+		log.Fields{"device-id": dh.DeviceID})
+	//but as we regard the flow as not existing = removed we respond just ok
+	// and treat the reason accordingly (which in the normal removal procedure is initiated by the FSM)
+	go dh.DeviceProcStatusUpdate(ctx, cmn.OmciVlanFilterRemDone)
+
+	return nil
+}
+
+// createVlanFilterFsm initializes and runs the VlanFilter FSM to transfer OMCI related VLAN config
+// if this function is called from possibly concurrent processes it must be mutex-protected from the caller!
+// precondition: dh.lockVlanConfig is locked by the caller!
+func (dh *deviceHandler) createVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8, aCookieSlice []uint64,
+	aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8, aDevEvent cmn.OnuDeviceEvent, lastFlowToReconcile bool, aMeter *voltha.OfpMeterConfig) error {
+	chVlanFilterFsm := make(chan cmn.Message, 2048)
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("no valid OnuDevice for device-id %x - aborting", dh.DeviceID)
+	}
+
+	pVlanFilterFsm := avcfg.NewUniVlanConfigFsm(ctx, dh, pDevEntry, pDevEntry.PDevOmciCC, apUniPort, dh.pOnuTP,
+		pDevEntry.GetOnuDB(), aTpID, aDevEvent, "UniVlanConfigFsm", chVlanFilterFsm,
+		dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp, lastFlowToReconcile, aMeter)
+	if pVlanFilterFsm != nil {
+		//dh.lockVlanConfig is locked (by caller) throughout the state transition to 'starting'
+		// to prevent unintended (ignored) events to be sent there (from parallel processing)
+		dh.UniVlanConfigFsmMap[apUniPort.UniID] = pVlanFilterFsm
+		pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm
+		if pVlanFilterStatemachine != nil {
+			if pVlanFilterStatemachine.Is(avcfg.VlanStDisabled) {
+				if err := pVlanFilterStatemachine.Event(avcfg.VlanEvStart); err != nil {
+					logger.Warnw(ctx, "UniVlanConfigFsm: can't start", log.Fields{"err": err})
+					return fmt.Errorf("can't start UniVlanConfigFsm for device-id %x", dh.DeviceID)
+				}
+				/***** UniVlanConfigFsm started */
+				logger.Debugw(ctx, "UniVlanConfigFsm started", log.Fields{
+					"state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
+					"UniPort": apUniPort.PortNo})
+			} else {
+				logger.Warnw(ctx, "wrong state of UniVlanConfigFsm - want: disabled", log.Fields{
+					"have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID})
+				return fmt.Errorf("uniVlanConfigFsm not in expected disabled state for device-id %x", dh.DeviceID)
+			}
+		} else {
+			logger.Errorw(ctx, "UniVlanConfigFsm StateMachine invalid - cannot be executed!!", log.Fields{
+				"device-id": dh.DeviceID})
+			return fmt.Errorf("uniVlanConfigFsm invalid for device-id %x", dh.DeviceID)
+		}
+	} else {
+		logger.Errorw(ctx, "UniVlanConfigFsm could not be created - abort!!", log.Fields{
+			"device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
+		return fmt.Errorf("uniVlanConfigFsm could not be created for device-id %x", dh.DeviceID)
+	}
+	return nil
+}
+
+//VerifyVlanConfigRequest checks on existence of a given uniPort
+// and starts verification of flow config based on that
+func (dh *deviceHandler) VerifyVlanConfigRequest(ctx context.Context, aUniID uint8, aTpID uint8) {
+	//ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
+	var pCurrentUniPort *cmn.OnuUniPort
+	for _, uniPort := range dh.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.Debugw(ctx, "VerifyVlanConfig aborted: requested uniID not found in PortDB",
+			log.Fields{"device-id": dh.DeviceID, "uni-id": aUniID})
+		return
+	}
+	dh.VerifyUniVlanConfigRequest(ctx, pCurrentUniPort, aTpID)
+}
+
+//VerifyUniVlanConfigRequest checks on existence of flow configuration and starts it accordingly
+func (dh *deviceHandler) VerifyUniVlanConfigRequest(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8) {
+	//TODO!! verify and start pending flow configuration
+	//some pending config request my exist in case the UniVlanConfig FSM was already started - with internal data -
+	//but execution was set to 'on hold' as first the TechProfile config had to be applied
+
+	dh.lockVlanConfig.RLock()
+	if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist {
+		dh.lockVlanConfig.RUnlock()
+		//VlanFilterFsm exists and was already started (assumed to wait for TechProfile execution here)
+		pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm
+		if pVlanFilterStatemachine != nil {
+			//if this was an event of the TP processing that was waited for in the VlanFilterFsm
+			if pVlanFilterFsm.GetWaitingTpID() == aTpID {
+				if pVlanFilterStatemachine.Is(avcfg.VlanStWaitingTechProf) {
+					if err := pVlanFilterStatemachine.Event(avcfg.VlanEvContinueConfig); err != nil {
+						logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err,
+							"device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
+					} else {
+						/***** UniVlanConfigFsm continued */
+						logger.Debugw(ctx, "UniVlanConfigFsm continued", log.Fields{
+							"state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
+							"UniPort": apUniPort.PortNo})
+					}
+				} else if pVlanFilterStatemachine.Is(avcfg.VlanStIncrFlowWaitTP) {
+					if err := pVlanFilterStatemachine.Event(avcfg.VlanEvIncrFlowConfig); err != nil {
+						logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err,
+							"device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
+					} else {
+						/***** UniVlanConfigFsm continued */
+						logger.Debugw(ctx, "UniVlanConfigFsm continued with incremental flow", log.Fields{
+							"state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
+							"UniPort": apUniPort.PortNo})
+					}
+				} else {
+					logger.Debugw(ctx, "no state of UniVlanConfigFsm to be continued", log.Fields{
+						"have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
+						"UniPort": apUniPort.PortNo})
+				}
+			} else {
+				logger.Debugw(ctx, "TechProfile Ready event for TpId that was not waited for in the VlanConfigFsm - continue waiting", log.Fields{
+					"state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
+					"UniPort": apUniPort.PortNo, "techprofile-id (done)": aTpID})
+			}
+		} else {
+			logger.Debugw(ctx, "UniVlanConfigFsm StateMachine does not exist, no flow processing", log.Fields{
+				"device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
+		}
+	} else {
+		dh.lockVlanConfig.RUnlock()
+	}
+}
+
+//RemoveVlanFilterFsm deletes the stored pointer to the VlanConfigFsm
+// intention is to provide this method to be called from VlanConfigFsm itself, when resources (and methods!) are cleaned up
+func (dh *deviceHandler) RemoveVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort) {
+	logger.Debugw(ctx, "remove UniVlanConfigFsm StateMachine", log.Fields{
+		"device-id": dh.DeviceID, "uniPort": apUniPort.PortNo})
+	//save to do, even if entry dows not exist
+	dh.lockVlanConfig.Lock()
+	delete(dh.UniVlanConfigFsmMap, apUniPort.UniID)
+	dh.lockVlanConfig.Unlock()
+}
+
+//startWritingOnuDataToKvStore initiates the KVStore write of ONU persistent data
+func (dh *deviceHandler) startWritingOnuDataToKvStore(ctx context.Context, aPDevEntry *mib.OnuDeviceEntry) error {
+	dh.mutexKvStoreContext.Lock()         //this write routine may (could) be called with the same context,
+	defer dh.mutexKvStoreContext.Unlock() //this write routine may (could) be called with the same context,
+	// obviously then parallel processing on the cancel must be avoided
+	// deadline context to ensure completion of background routines waited for
+	//20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
+	deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
+	dctx, cancel := context.WithDeadline(context.Background(), deadline)
+
+	aPDevEntry.ResetKvProcessingErrorIndication()
+	var wg sync.WaitGroup
+	wg.Add(1) // for the 1 go routine to finish
+
+	go aPDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg)
+	dh.waitForCompletion(ctx, cancel, &wg, "UpdateKvStore") //wait for background process to finish
+
+	return aPDevEntry.GetKvProcessingErrorIndication()
+}
+
+//StorePersUniFlowConfig updates local storage of OnuUniFlowConfig and writes it into kv-store afterwards to have it
+//available for potential reconcilement
+func (dh *deviceHandler) StorePersUniFlowConfig(ctx context.Context, aUniID uint8,
+	aUniVlanFlowParams *[]cmn.UniVlanFlowParams, aWriteToKvStore bool) error {
+
+	if dh.IsReconciling() {
+		logger.Debugw(ctx, "reconciling - don't store persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID})
+		return nil
+	}
+	logger.Debugw(ctx, "Store or clear persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID})
+
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
+	}
+	pDevEntry.UpdateOnuUniFlowConfig(aUniID, aUniVlanFlowParams)
+
+	if aWriteToKvStore {
+		return dh.startWritingOnuDataToKvStore(ctx, pDevEntry)
+	}
+	return nil
+}
+
+func (dh *deviceHandler) waitForCompletion(ctx context.Context, cancel context.CancelFunc, wg *sync.WaitGroup, aCallerIdent string) {
+	defer cancel() //ensure termination of context (may be pro forma)
+	wg.Wait()
+	logger.Debugw(ctx, "WaitGroup processing completed", log.Fields{
+		"device-id": dh.DeviceID, "called from": aCallerIdent})
+}
+
+func (dh *deviceHandler) deviceReasonUpdate(ctx context.Context, deviceReason uint8, notifyCore bool) error {
+
+	dh.SetDeviceReason(deviceReason)
+	if notifyCore {
+		//TODO with VOL-3045/VOL-3046: return the error and stop further processing at calling position
+		if err := dh.updateDeviceReasonInCore(ctx, &ic.DeviceReason{
+			DeviceId: dh.DeviceID,
+			Reason:   cmn.DeviceReasonMap[deviceReason],
+		}); err != nil {
+			logger.Errorf(ctx, "DeviceReasonUpdate error: %s",
+				log.Fields{"device-id": dh.DeviceID, "error": err}, cmn.DeviceReasonMap[deviceReason])
+			return err
+		}
+		logger.Infof(ctx, "DeviceReasonUpdate success: %s - device-id: %s", cmn.DeviceReasonMap[deviceReason], dh.DeviceID)
+		return nil
+	}
+	logger.Infof(ctx, "Don't notify core about DeviceReasonUpdate: %s - device-id: %s", cmn.DeviceReasonMap[deviceReason], dh.DeviceID)
+	return nil
+}
+
+func (dh *deviceHandler) StorePersistentData(ctx context.Context) error {
+	pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
+	if pDevEntry == nil {
+		logger.Warnw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
+		return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
+	}
+	return dh.startWritingOnuDataToKvStore(ctx, pDevEntry)
+}
+
+// getUniPortMEEntityID takes uniPortNo as the input and returns the Entity ID corresponding to this UNI-G ME Instance
+// nolint: unused
+func (dh *deviceHandler) getUniPortMEEntityID(uniPortNo uint32) (uint16, error) {
+	dh.lockDevice.RLock()
+	defer dh.lockDevice.RUnlock()
+	if uniPort, ok := dh.uniEntityMap[uniPortNo]; ok {
+		return uniPort.EntityID, nil
+	}
+	return 0, errors.New("error-fetching-uni-port")
+}
+
+// updatePmConfig updates the pm metrics config.
+func (dh *deviceHandler) updatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
+	var errorsList []error
+	logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": dh.device.Id, "new-pm-configs": pmConfigs, "old-pm-config": dh.pmConfigs})
+
+	errorsList = append(dh.handleGlobalPmConfigUpdates(ctx, pmConfigs), errorsList...)
+	errorsList = append(dh.handleGroupPmConfigUpdates(ctx, pmConfigs), errorsList...)
+	errorsList = append(dh.handleStandalonePmConfigUpdates(ctx, pmConfigs), errorsList...)
+
+	// Note that if more than one pm config field is updated in a given call, it is possible that partial pm config is handled
+	// successfully.
+	// TODO: Although it is possible to revert to old config in case of partial failure, the code becomes quite complex. Needs more investigation
+	// Is it possible the rw-core reverts to old config on partial failure but adapter retains a partial new config?
+	if len(errorsList) > 0 {
+		logger.Errorw(ctx, "one-or-more-pm-config-failed", log.Fields{"device-id": dh.DeviceID, "pmConfig": dh.pmConfigs})
+		return fmt.Errorf("errors-handling-one-or-more-pm-config, errors:%v", errorsList)
+	}
+	logger.Infow(ctx, "pm-config-updated", log.Fields{"device-id": dh.DeviceID, "pmConfig": dh.pmConfigs})
+	return nil
+}
+
+func (dh *deviceHandler) handleGlobalPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error {
+	var err error
+	var errorsList []error
+	logger.Infow(ctx, "handling-global-pm-config-params - start", log.Fields{"device-id": dh.device.Id})
+
+	if pmConfigs.DefaultFreq != dh.pmConfigs.DefaultFreq {
+		if err = dh.pOnuMetricsMgr.UpdateDefaultFrequency(ctx, pmConfigs); err != nil {
+			errorsList = append(errorsList, err)
+		}
+	}
+	logger.Infow(ctx, "handling-global-pm-config-params - done", log.Fields{"device-id": dh.device.Id})
+
+	return errorsList
+}
+
+func (dh *deviceHandler) handleGroupPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error {
+	var err error
+	var errorsList []error
+	logger.Debugw(ctx, "handling-group-pm-config-params - start", log.Fields{"device-id": dh.device.Id})
+	// Check if group metric related config is updated
+	for _, v := range pmConfigs.Groups {
+		dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock()
+		m, ok := dh.pOnuMetricsMgr.GroupMetricMap[v.GroupName]
+		dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock()
+
+		if ok && m.Frequency != v.GroupFreq {
+			if err = dh.pOnuMetricsMgr.UpdateGroupFreq(ctx, v.GroupName, pmConfigs); err != nil {
+				errorsList = append(errorsList, err)
+			}
+		}
+		if ok && m.Enabled != v.Enabled {
+			if err = dh.pOnuMetricsMgr.UpdateGroupSupport(ctx, v.GroupName, pmConfigs); err != nil {
+				errorsList = append(errorsList, err)
+			}
+		}
+	}
+	logger.Debugw(ctx, "handling-group-pm-config-params - done", log.Fields{"device-id": dh.device.Id})
+	return errorsList
+}
+
+func (dh *deviceHandler) handleStandalonePmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error {
+	var err error
+	var errorsList []error
+	logger.Debugw(ctx, "handling-individual-pm-config-params - start", log.Fields{"device-id": dh.device.Id})
+	// Check if standalone metric related config is updated
+	for _, v := range pmConfigs.Metrics {
+		dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock()
+		m, ok := dh.pOnuMetricsMgr.StandaloneMetricMap[v.Name]
+		dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock()
+
+		if ok && m.Frequency != v.SampleFreq {
+			if err = dh.pOnuMetricsMgr.UpdateMetricFreq(ctx, v.Name, pmConfigs); err != nil {
+				errorsList = append(errorsList, err)
+			}
+		}
+		if ok && m.Enabled != v.Enabled {
+			if err = dh.pOnuMetricsMgr.UpdateMetricSupport(ctx, v.Name, pmConfigs); err != nil {
+				errorsList = append(errorsList, err)
+			}
+		}
+	}
+	logger.Debugw(ctx, "handling-individual-pm-config-params - done", log.Fields{"device-id": dh.device.Id})
+	return errorsList
+}
+
+// nolint: gocyclo
+func (dh *deviceHandler) StartCollector(ctx context.Context) {
+	logger.Debugf(ctx, "startingCollector")
+
+	// Start routine to process OMCI GET Responses
+	go dh.pOnuMetricsMgr.ProcessOmciMessages(ctx)
+	// Create Extended Frame PM ME
+	go dh.pOnuMetricsMgr.CreateEthernetFrameExtendedPMME(ctx)
+	// Initialize the next metric collection time.
+	// Normally done when the onu_metrics_manager is initialized the first time, but needed again later when ONU is
+	// reset like onu rebooted.
+	dh.pOnuMetricsMgr.InitializeMetricCollectionTime(ctx)
+	dh.setCollectorIsRunning(true)
+	for {
+		select {
+		case <-dh.stopCollector:
+			dh.setCollectorIsRunning(false)
+			logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id})
+			// Stop the L2 PM FSM
+			go func() {
+				if dh.pOnuMetricsMgr.PAdaptFsm != nil && dh.pOnuMetricsMgr.PAdaptFsm.PFsm != nil {
+					if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventStop); err != nil {
+						logger.Errorw(ctx, "error calling event", log.Fields{"device-id": dh.DeviceID, "err": err})
+					}
+				} else {
+					logger.Errorw(ctx, "metrics manager fsm not initialized", log.Fields{"device-id": dh.DeviceID})
+				}
+			}()
+			if dh.pOnuMetricsMgr.GetOmciProcessingStatus() {
+				dh.pOnuMetricsMgr.StopProcessingOmciResponses <- true // Stop the OMCI GET response processing routine
+			}
+			if dh.pOnuMetricsMgr.GetTickGenerationStatus() {
+				dh.pOnuMetricsMgr.StopTicks <- true
+			}
+
+			return
+		case <-time.After(time.Duration(pmmgr.FrequencyGranularity) * time.Second): // Check every FrequencyGranularity to see if it is time for collecting metrics
+			if !dh.pmConfigs.FreqOverride { // If FreqOverride is false, then NextGlobalMetricCollectionTime applies
+				// If the current time is eqaul to or greater than the NextGlobalMetricCollectionTime, collect the group and standalone metrics
+				if time.Now().Equal(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) || time.Now().After(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) {
+					go dh.pOnuMetricsMgr.CollectAllGroupAndStandaloneMetrics(ctx)
+					// Update the next metric collection time.
+					dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime = time.Now().Add(time.Duration(dh.pmConfigs.DefaultFreq) * time.Second)
+				}
+			} else {
+				if dh.pmConfigs.Grouped { // metrics are managed as a group
+					// parse through the group and standalone metrics to see it is time to collect their metrics
+					dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() // Rlock as we are reading GroupMetricMap and StandaloneMetricMap
+
+					for n, g := range dh.pOnuMetricsMgr.GroupMetricMap {
+						// If the group is enabled AND (current time is equal to OR after NextCollectionInterval, collect the group metric)
+						// Since the L2 PM counters are collected in a separate FSM, we should avoid those counters in the check.
+						if g.Enabled && !g.IsL2PMCounter && (time.Now().Equal(g.NextCollectionInterval) || time.Now().After(g.NextCollectionInterval)) {
+							go dh.pOnuMetricsMgr.CollectGroupMetric(ctx, n)
+						}
+					}
+					for n, m := range dh.pOnuMetricsMgr.StandaloneMetricMap {
+						// If the standalone is enabled AND (current time is equal to OR after NextCollectionInterval, collect the metric)
+						if m.Enabled && (time.Now().Equal(m.NextCollectionInterval) || time.Now().After(m.NextCollectionInterval)) {
+							go dh.pOnuMetricsMgr.CollectStandaloneMetric(ctx, n)
+						}
+					}
+					dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock()
+
+					// parse through the group and update the next metric collection time
+					dh.pOnuMetricsMgr.OnuMetricsManagerLock.Lock() // Lock as we are writing the next metric collection time
+					for _, g := range dh.pOnuMetricsMgr.GroupMetricMap {
+						// If group enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp
+						// Since the L2 PM counters are collected and managed in a separate FSM, we should avoid those counters in the check.
+						if g.Enabled && !g.IsL2PMCounter && (g.NextCollectionInterval.Before(time.Now()) || g.NextCollectionInterval.Equal(time.Now())) {
+							g.NextCollectionInterval = time.Now().Add(time.Duration(g.Frequency) * time.Second)
+						}
+					}
+					// parse through the standalone metrics and update the next metric collection time
+					for _, m := range dh.pOnuMetricsMgr.StandaloneMetricMap {
+						// If standalone metrics enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp
+						if m.Enabled && (m.NextCollectionInterval.Before(time.Now()) || m.NextCollectionInterval.Equal(time.Now())) {
+							m.NextCollectionInterval = time.Now().Add(time.Duration(m.Frequency) * time.Second)
+						}
+					}
+					dh.pOnuMetricsMgr.OnuMetricsManagerLock.Unlock()
+				} /* else { // metrics are not managed as a group
+					// TODO: We currently do not have standalone metrics. When available, add code here to fetch the metric.
+				} */
+			}
+		}
+	}
+}
+
+func (dh *deviceHandler) GetUniPortStatus(ctx context.Context, uniInfo *extension.GetOnuUniInfoRequest) *extension.SingleGetValueResponse {
+
+	portStatus := uniprt.NewUniPortStatus(dh, dh.pOnuOmciDevice.PDevOmciCC)
+	return portStatus.GetUniPortStatus(ctx, uniInfo.UniIndex)
+}
+
+func (dh *deviceHandler) getOnuOMCICounters(ctx context.Context, onuInfo *extension.GetOmciEthernetFrameExtendedPmRequest) *extension.SingleGetValueResponse {
+	if dh.pOnuMetricsMgr == nil {
+		return &extension.SingleGetValueResponse{
+			Response: &extension.GetValueResponse{
+				Status:    extension.GetValueResponse_ERROR,
+				ErrReason: extension.GetValueResponse_INTERNAL_ERROR,
+			},
+		}
+	}
+	resp := dh.pOnuMetricsMgr.CollectEthernetFrameExtendedPMCounters(ctx)
+	return resp
+}
+
+func (dh *deviceHandler) isFsmInOmciIdleState(ctx context.Context, PFsm *fsm.FSM, wantedState string) bool {
+	if PFsm == nil {
+		return true //FSM not active - so there is no activity on omci
+	}
+	return PFsm.Current() == wantedState
+}
+
+func (dh *deviceHandler) isFsmInOmciIdleStateDefault(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, wantedState string) bool {
+	var PFsm *fsm.FSM
+	//note/TODO!!: might be that access to all these specific FSM; pointers need a semaphore protection as well, cmp lockUpgradeFsm
+	switch omciFsm {
+	case cmn.CUploadFsm:
+		{
+			PFsm = dh.pOnuOmciDevice.PMibUploadFsm.PFsm
+		}
+	case cmn.CDownloadFsm:
+		{
+			PFsm = dh.pOnuOmciDevice.PMibDownloadFsm.PFsm
+		}
+	case cmn.CUniLockFsm:
+		{
+			PFsm = dh.pLockStateFsm.PAdaptFsm.PFsm
+		}
+	case cmn.CUniUnLockFsm:
+		{
+			PFsm = dh.pUnlockStateFsm.PAdaptFsm.PFsm
+		}
+	case cmn.CL2PmFsm:
+		{
+			if dh.pOnuMetricsMgr != nil && dh.pOnuMetricsMgr.PAdaptFsm != nil {
+				PFsm = dh.pOnuMetricsMgr.PAdaptFsm.PFsm
+			} else {
+				return true //FSM not active - so there is no activity on omci
+			}
+		}
+	case cmn.COnuUpgradeFsm:
+		{
+			dh.lockUpgradeFsm.RLock()
+			defer dh.lockUpgradeFsm.RUnlock()
+			PFsm = dh.pOnuUpradeFsm.PAdaptFsm.PFsm
+		}
+	default:
+		{
+			logger.Errorw(ctx, "invalid stateMachine selected for idle check", log.Fields{
+				"device-id": dh.DeviceID, "selectedFsm number": omciFsm})
+			return false //logical error in FSM check, do not not indicate 'idle' - we can't be sure
+		}
+	}
+	return dh.isFsmInOmciIdleState(ctx, PFsm, wantedState)
+}
+
+func (dh *deviceHandler) isAniConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool {
+	for _, v := range dh.pOnuTP.PAniConfigFsm {
+		if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) {
+			return false
+		}
+	}
+	return true
+}
+
+func (dh *deviceHandler) isUniVlanConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool {
+	dh.lockVlanConfig.RLock()
+	defer dh.lockVlanConfig.RUnlock()
+	for _, v := range dh.UniVlanConfigFsmMap {
+		if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) {
+			return false
+		}
+	}
+	return true //FSM not active - so there is no activity on omci
+}
+
+func (dh *deviceHandler) checkUserServiceExists(ctx context.Context) bool {
+	dh.lockVlanConfig.RLock()
+	defer dh.lockVlanConfig.RUnlock()
+	for _, v := range dh.UniVlanConfigFsmMap {
+		if v.PAdaptFsm.PFsm != nil {
+			if v.PAdaptFsm.PFsm.Is(avcfg.CVlanFsmConfiguredState) {
+				return true //there is at least one VLAN FSM with some active configuration
+			}
+		}
+	}
+	return false //there is no VLAN FSM with some active configuration
+}
+
+func (dh *deviceHandler) CheckAuditStartCondition(ctx context.Context, callingFsm cmn.UsedOmciConfigFsms) bool {
+	for fsmName, fsmStruct := range fsmOmciIdleStateFuncMap {
+		if fsmName != callingFsm && !fsmStruct.omciIdleCheckFunc(dh, ctx, fsmName, fsmStruct.omciIdleState) {
+			return false
+		}
+	}
+	// a further check is done to identify, if at least some data traffic related configuration exists
+	// so that a user of this ONU could be 'online' (otherwise it makes no sense to check the MDS [with the intention to keep the user service up])
+	return dh.checkUserServiceExists(ctx)
+}
+
+func (dh *deviceHandler) PrepareReconcilingWithActiveAdapter(ctx context.Context) {
+	logger.Debugw(ctx, "prepare to reconcile the ONU with adapter using persistency data", log.Fields{"device-id": dh.device.Id})
+	if err := dh.resetFsms(ctx, false); err != nil {
+		logger.Errorw(ctx, "reset of FSMs failed!", log.Fields{"device-id": dh.DeviceID, "error": err})
+		// TODO: fatal error reset ONU, delete deviceHandler!
+		return
+	}
+	dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort)
+	dh.StartReconciling(ctx, false)
+}
+
+func (dh *deviceHandler) setCollectorIsRunning(flagValue bool) {
+	dh.mutexCollectorFlag.Lock()
+	dh.collectorIsRunning = flagValue
+	dh.mutexCollectorFlag.Unlock()
+}
+
+func (dh *deviceHandler) GetCollectorIsRunning() bool {
+	dh.mutexCollectorFlag.RLock()
+	flagValue := dh.collectorIsRunning
+	dh.mutexCollectorFlag.RUnlock()
+	return flagValue
+}
+
+func (dh *deviceHandler) setAlarmManagerIsRunning(flagValue bool) {
+	dh.mutextAlarmManagerFlag.Lock()
+	dh.alarmManagerIsRunning = flagValue
+	dh.mutextAlarmManagerFlag.Unlock()
+}
+
+func (dh *deviceHandler) GetAlarmManagerIsRunning(ctx context.Context) bool {
+	dh.mutextAlarmManagerFlag.RLock()
+	flagValue := dh.alarmManagerIsRunning
+	logger.Debugw(ctx, "alarm-manager-is-running", log.Fields{"flag": dh.alarmManagerIsRunning})
+	dh.mutextAlarmManagerFlag.RUnlock()
+	return flagValue
+}
+
+func (dh *deviceHandler) StartAlarmManager(ctx context.Context) {
+	logger.Debugf(ctx, "startingAlarmManager")
+
+	// Start routine to process OMCI GET Responses
+	go dh.pAlarmMgr.StartOMCIAlarmMessageProcessing(ctx)
+	dh.setAlarmManagerIsRunning(true)
+	if stop := <-dh.stopAlarmManager; stop {
+		logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id})
+		dh.setAlarmManagerIsRunning(false)
+		go func() {
+			if dh.pAlarmMgr.AlarmSyncFsm != nil && dh.pAlarmMgr.AlarmSyncFsm.PFsm != nil {
+				_ = dh.pAlarmMgr.AlarmSyncFsm.PFsm.Event(almgr.AsEvStop)
+			}
+		}()
+		dh.pAlarmMgr.StopProcessingOmciMessages <- true // Stop the OMCI routines if any(This will stop the fsms also)
+		dh.pAlarmMgr.StopAlarmAuditTimer <- struct{}{}
+		logger.Debugw(ctx, "sent-all-stop-signals-to-alarm-manager", log.Fields{"device-id": dh.device.Id})
+	}
+}
+
+func (dh *deviceHandler) StartReconciling(ctx context.Context, skipOnuConfig bool) {
+	logger.Debugw(ctx, "start reconciling", log.Fields{"skipOnuConfig": skipOnuConfig, "device-id": dh.DeviceID})
+
+	connectStatus := voltha.ConnectStatus_UNREACHABLE
+	operState := voltha.OperStatus_UNKNOWN
+
+	if !dh.IsReconciling() {
+		go func() {
+			logger.Debugw(ctx, "wait for channel signal or timeout",
+				log.Fields{"timeout": dh.pOpenOnuAc.maxTimeoutReconciling, "device-id": dh.DeviceID})
+			select {
+			case success := <-dh.chReconcilingFinished:
+				if success {
+					if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
+						logger.Errorw(ctx, "No valid OnuDevice - aborting Core DeviceStateUpdate",
+							log.Fields{"device-id": dh.DeviceID})
+					} else {
+						if onuDevEntry.SOnuPersistentData.PersOperState == "up" {
+							connectStatus = voltha.ConnectStatus_REACHABLE
+							if !onuDevEntry.SOnuPersistentData.PersUniDisableDone {
+								if onuDevEntry.SOnuPersistentData.PersUniUnlockDone {
+									operState = voltha.OperStatus_ACTIVE
+								} else {
+									operState = voltha.OperStatus_ACTIVATING
+								}
+							}
+						} else if onuDevEntry.SOnuPersistentData.PersOperState == "down" ||
+							onuDevEntry.SOnuPersistentData.PersOperState == "unknown" ||
+							onuDevEntry.SOnuPersistentData.PersOperState == "" {
+							operState = voltha.OperStatus_DISCOVERED
+						}
+
+						logger.Debugw(ctx, "Core DeviceStateUpdate", log.Fields{"connectStatus": connectStatus, "operState": operState})
+					}
+					logger.Debugw(ctx, "reconciling has been finished in time",
+						log.Fields{"device-id": dh.DeviceID})
+					if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
+						DeviceId:   dh.DeviceID,
+						ConnStatus: connectStatus,
+						OperStatus: operState,
+					}); err != nil {
+						logger.Errorw(ctx, "unable to update device state to core",
+							log.Fields{"device-id": dh.DeviceID, "Err": err})
+					}
+				} else {
+					logger.Errorw(ctx, "wait for reconciling aborted",
+						log.Fields{"device-id": dh.DeviceID})
+
+					if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
+						logger.Errorw(ctx, "No valid OnuDevice",
+							log.Fields{"device-id": dh.DeviceID})
+					} else if onuDevEntry.SOnuPersistentData.PersOperState == "up" {
+						connectStatus = voltha.ConnectStatus_REACHABLE
+					}
+
+					dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileCanceled, connectStatus)
+				}
+			case <-time.After(dh.pOpenOnuAc.maxTimeoutReconciling):
+				logger.Errorw(ctx, "timeout waiting for reconciling to be finished!",
+					log.Fields{"device-id": dh.DeviceID})
+
+				if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
+					logger.Errorw(ctx, "No valid OnuDevice",
+						log.Fields{"device-id": dh.DeviceID})
+				} else if onuDevEntry.SOnuPersistentData.PersOperState == "up" {
+					connectStatus = voltha.ConnectStatus_REACHABLE
+				}
+
+				dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileMaxTimeout, connectStatus)
+
+			}
+			dh.mutexReconcilingFlag.Lock()
+			dh.reconciling = cNoReconciling
+			dh.mutexReconcilingFlag.Unlock()
+		}()
+	}
+	dh.mutexReconcilingFlag.Lock()
+	if skipOnuConfig {
+		dh.reconciling = cSkipOnuConfigReconciling
+	} else {
+		dh.reconciling = cOnuConfigReconciling
+	}
+	dh.mutexReconcilingFlag.Unlock()
+}
+
+func (dh *deviceHandler) StopReconciling(ctx context.Context, success bool) {
+	logger.Debugw(ctx, "stop reconciling", log.Fields{"device-id": dh.DeviceID, "success": success})
+	if dh.IsReconciling() {
+		dh.chReconcilingFinished <- success
+	} else {
+		logger.Infow(ctx, "reconciling is not running", log.Fields{"device-id": dh.DeviceID})
+	}
+}
+
+func (dh *deviceHandler) IsReconciling() bool {
+	dh.mutexReconcilingFlag.RLock()
+	defer dh.mutexReconcilingFlag.RUnlock()
+	return dh.reconciling != cNoReconciling
+}
+
+func (dh *deviceHandler) IsSkipOnuConfigReconciling() bool {
+	dh.mutexReconcilingFlag.RLock()
+	defer dh.mutexReconcilingFlag.RUnlock()
+	return dh.reconciling == cSkipOnuConfigReconciling
+}
+
+func (dh *deviceHandler) SetDeviceReason(value uint8) {
+	dh.mutexDeviceReason.Lock()
+	dh.deviceReason = value
+	dh.mutexDeviceReason.Unlock()
+}
+
+func (dh *deviceHandler) getDeviceReason() uint8 {
+	dh.mutexDeviceReason.RLock()
+	value := dh.deviceReason
+	dh.mutexDeviceReason.RUnlock()
+	return value
+}
+
+func (dh *deviceHandler) GetDeviceReasonString() string {
+	return cmn.DeviceReasonMap[dh.getDeviceReason()]
+}
+
+func (dh *deviceHandler) SetReadyForOmciConfig(flagValue bool) {
+	dh.mutexReadyForOmciConfig.Lock()
+	dh.readyForOmciConfig = flagValue
+	dh.mutexReadyForOmciConfig.Unlock()
+}
+func (dh *deviceHandler) IsReadyForOmciConfig() bool {
+	dh.mutexReadyForOmciConfig.RLock()
+	flagValue := dh.readyForOmciConfig
+	dh.mutexReadyForOmciConfig.RUnlock()
+	return flagValue
+}
+
+func (dh *deviceHandler) deviceReconcileFailedUpdate(ctx context.Context, deviceReason uint8, connectStatus voltha.ConnectStatus_Types) {
+	if err := dh.deviceReasonUpdate(ctx, deviceReason, true); err != nil {
+		logger.Errorw(ctx, "unable to update device reason to core",
+			log.Fields{"device-id": dh.DeviceID, "Err": err})
+	}
+
+	logger.Debugw(ctx, "Core DeviceStateUpdate", log.Fields{"connectStatus": connectStatus, "operState": voltha.OperStatus_RECONCILING_FAILED})
+	if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
+		DeviceId:   dh.DeviceID,
+		ConnStatus: connectStatus,
+		OperStatus: voltha.OperStatus_RECONCILING_FAILED,
+	}); err != nil {
+		logger.Errorw(ctx, "unable to update device state to core",
+			log.Fields{"device-id": dh.DeviceID, "Err": err})
+	}
+}
+
+/*
+Helper functions to communicate with Core
+*/
+
+func (dh *deviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) {
+	cClient, err := dh.coreClient.GetCoreServiceClient()
+	if err != nil || cClient == nil {
+		return nil, err
+	}
+	subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
+	defer cancel()
+	logger.Debugw(subCtx, "get-device-from-core", log.Fields{"device-id": deviceID})
+	return cClient.GetDevice(subCtx, &vc.ID{Id: deviceID})
+}
+
+func (dh *deviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ic.DeviceStateFilter) error {
+	cClient, err := dh.coreClient.GetCoreServiceClient()
+	if err != nil || cClient == nil {
+		return err
+	}
+	subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
+	defer cancel()
+	_, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter)
+	logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-state": deviceStateFilter, "error": err})
+	return err
+}
+
+func (dh *deviceHandler) updatePMConfigInCore(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
+	cClient, err := dh.coreClient.GetCoreServiceClient()
+	if err != nil || cClient == nil {
+		return err
+	}
+	subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
+	defer cancel()
+	_, err = cClient.DevicePMConfigUpdate(subCtx, pmConfigs)
+	logger.Debugw(subCtx, "pmconfig-updated-in-core", log.Fields{"pm-configs": pmConfigs, "error": err})
+	return err
+}
+
+func (dh *deviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error {
+	cClient, err := dh.coreClient.GetCoreServiceClient()
+	if err != nil || cClient == nil {
+		return err
+	}
+	subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
+	defer cancel()
+	_, err = cClient.DeviceUpdate(subCtx, device)
+	logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-id": device.Id, "error": err})
+	return err
+}
+
+func (dh *deviceHandler) CreatePortInCore(ctx context.Context, port *voltha.Port) error {
+	cClient, err := dh.coreClient.GetCoreServiceClient()
+	if err != nil || cClient == nil {
+		return err
+	}
+	subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
+	defer cancel()
+	_, err = cClient.PortCreated(subCtx, port)
+	logger.Debugw(subCtx, "port-created-in-core", log.Fields{"port": port, "error": err})
+	return err
+}
+
+func (dh *deviceHandler) updatePortStateInCore(ctx context.Context, portState *ic.PortState) error {
+	cClient, err := dh.coreClient.GetCoreServiceClient()
+	if err != nil || cClient == nil {
+		return err
+	}
+	subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
+	defer cancel()
+	_, err = cClient.PortStateUpdate(subCtx, portState)
+	logger.Debugw(subCtx, "port-state-updated-in-core", log.Fields{"port-state": portState, "error": err})
+	return err
+}
+
+func (dh *deviceHandler) updateDeviceReasonInCore(ctx context.Context, reason *ic.DeviceReason) error {
+	cClient, err := dh.coreClient.GetCoreServiceClient()
+	if err != nil || cClient == nil {
+		return err
+	}
+	subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
+	defer cancel()
+	_, err = cClient.DeviceReasonUpdate(subCtx, reason)
+	logger.Debugw(subCtx, "device-reason-updated-in-core", log.Fields{"reason": reason, "error": err})
+	return err
+}
+
+/*
+Helper functions to communicate with parent adapter
+*/
+
+func (dh *deviceHandler) getTechProfileInstanceFromParentAdapter(ctx context.Context, parentEndpoint string,
+	request *ic.TechProfileInstanceRequestMessage) (*ic.TechProfileDownloadMessage, error) {
+	pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint)
+	if err != nil || pgClient == nil {
+		return nil, err
+	}
+	subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm)
+	defer cancel()
+	logger.Debugw(subCtx, "get-tech-profile-instance", log.Fields{"request": request, "parent-endpoint": parentEndpoint})
+	return pgClient.GetTechProfileInstance(subCtx, request)
+}
+
+func (dh *deviceHandler) SendOMCIRequest(ctx context.Context, parentEndpoint string, request *ic.OmciMessage) error {
+	pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint)
+	if err != nil || pgClient == nil {
+		return err
+	}
+	subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm)
+	defer cancel()
+	logger.Debugw(subCtx, "send-omci-request", log.Fields{"request": request, "parent-endpoint": parentEndpoint})
+	_, err = pgClient.ProxyOmciRequest(subCtx, request)
+	if err != nil {
+		logger.Errorw(ctx, "omci-failure", log.Fields{"request": request, "error": err, "request-parent": request.ParentDeviceId, "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress})
+	}
+	return err
+}
+
+// GetDeviceID - TODO: add comment
+func (dh *deviceHandler) GetDeviceID() string {
+	return dh.DeviceID
+}
+
+// GetProxyAddressID - TODO: add comment
+func (dh *deviceHandler) GetProxyAddressID() string {
+	return dh.device.ProxyAddress.GetDeviceId()
+}
+
+// GetProxyAddressType - TODO: add comment
+func (dh *deviceHandler) GetProxyAddressType() string {
+	return dh.device.ProxyAddress.GetDeviceType()
+}
+
+// GetProxyAddress - TODO: add comment
+func (dh *deviceHandler) GetProxyAddress() *voltha.Device_ProxyAddress {
+	return dh.device.ProxyAddress
+}
+
+// GetEventProxy - TODO: add comment
+func (dh *deviceHandler) GetEventProxy() eventif.EventProxy {
+	return dh.EventProxy
+}
+
+// GetOmciTimeout - TODO: add comment
+func (dh *deviceHandler) GetOmciTimeout() int {
+	return dh.pOpenOnuAc.omciTimeout
+}
+
+// GetAlarmAuditInterval - TODO: add comment
+func (dh *deviceHandler) GetAlarmAuditInterval() time.Duration {
+	return dh.pOpenOnuAc.alarmAuditInterval
+}
+
+// GetDlToOnuTimeout4M - TODO: add comment
+func (dh *deviceHandler) GetDlToOnuTimeout4M() time.Duration {
+	return dh.pOpenOnuAc.dlToOnuTimeout4M
+}
+
+// GetUniEntityMap - TODO: add comment
+func (dh *deviceHandler) GetUniEntityMap() *cmn.OnuUniPortMap {
+	return &dh.uniEntityMap
+}
+
+// GetPonPortNumber - TODO: add comment
+func (dh *deviceHandler) GetPonPortNumber() *uint32 {
+	return &dh.ponPortNumber
+}
+
+// GetUniVlanConfigFsm - TODO: add comment
+func (dh *deviceHandler) GetUniVlanConfigFsm(uniID uint8) cmn.IuniVlanConfigFsm {
+	return dh.UniVlanConfigFsmMap[uniID]
+}
+
+// GetOnuAlarmManager - TODO: add comment
+func (dh *deviceHandler) GetOnuAlarmManager() cmn.IonuAlarmManager {
+	return dh.pAlarmMgr
+}
+
+// GetOnuMetricsManager - TODO: add comment
+func (dh *deviceHandler) GetOnuMetricsManager() cmn.IonuMetricsManager {
+	return dh.pOnuMetricsMgr
+}
+
+// GetOnuTP - TODO: add comment
+func (dh *deviceHandler) GetOnuTP() cmn.IonuUniTechProf {
+	return dh.pOnuTP
+}
+
+// GetBackendPathPrefix - TODO: add comment
+func (dh *deviceHandler) GetBackendPathPrefix() string {
+	return dh.pOpenOnuAc.cm.Backend.PathPrefix
+}
+
+// GetOnuIndication - TODO: add comment
+func (dh *deviceHandler) GetOnuIndication() *openolt.OnuIndication {
+	return dh.pOnuIndication
+}
+
+// RLockMutexDeletionInProgressFlag - TODO: add comment
+func (dh *deviceHandler) RLockMutexDeletionInProgressFlag() {
+	dh.mutexDeletionInProgressFlag.RLock()
+}
+
+// RUnlockMutexDeletionInProgressFlag - TODO: add comment
+func (dh *deviceHandler) RUnlockMutexDeletionInProgressFlag() {
+	dh.mutexDeletionInProgressFlag.RUnlock()
+}
+
+// GetDeletionInProgress - TODO: add comment
+func (dh *deviceHandler) GetDeletionInProgress() bool {
+	return dh.deletionInProgress
+}
+
+// GetPmConfigs - TODO: add comment
+func (dh *deviceHandler) GetPmConfigs() *voltha.PmConfigs {
+	return dh.pmConfigs
+}
+
+// GetDeviceType - TODO: add comment
+func (dh *deviceHandler) GetDeviceType() string {
+	return dh.DeviceType
+}
+
+// GetLogicalDeviceID - TODO: add comment
+func (dh *deviceHandler) GetLogicalDeviceID() string {
+	return dh.logicalDeviceID
+}
+
+// GetDevice - TODO: add comment
+func (dh *deviceHandler) GetDevice() *voltha.Device {
+	return dh.device
+}
+
+// GetMetricsEnabled - TODO: add comment
+func (dh *deviceHandler) GetMetricsEnabled() bool {
+	return dh.pOpenOnuAc.MetricsEnabled
+}
+
+// InitPmConfigs - TODO: add comment
+func (dh *deviceHandler) InitPmConfigs() {
+	dh.pmConfigs = &voltha.PmConfigs{}
+}
+
+// GetUniPortMask - TODO: add comment
+func (dh *deviceHandler) GetUniPortMask() int {
+	return dh.pOpenOnuAc.config.UniPortMask
+}
diff --git a/internal/pkg/core/openonu.go b/internal/pkg/core/openonu.go
new file mode 100755
index 0000000..a7ad35c
--- /dev/null
+++ b/internal/pkg/core/openonu.go
@@ -0,0 +1,1177 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//Package core provides the utility for onu devices, flows and statistics
+package core
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"sync"
+	"time"
+
+	vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
+	"github.com/opencord/voltha-protos/v5/go/adapter_services"
+
+	conf "github.com/opencord/voltha-lib-go/v7/pkg/config"
+	"github.com/opencord/voltha-protos/v5/go/common"
+	"google.golang.org/grpc"
+
+	"github.com/golang/protobuf/ptypes/empty"
+	"github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
+	"github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
+	"github.com/opencord/voltha-lib-go/v7/pkg/log"
+	"github.com/opencord/voltha-protos/v5/go/extension"
+	ic "github.com/opencord/voltha-protos/v5/go/inter_container"
+	"github.com/opencord/voltha-protos/v5/go/voltha"
+
+	cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
+	"github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config"
+	"github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg"
+	uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt"
+)
+
+//OpenONUAC structure holds the ONU core information
+type OpenONUAC struct {
+	deviceHandlers              map[string]*deviceHandler
+	deviceHandlersCreateChan    map[string]chan bool //channels for deviceHandler create events
+	mutexDeviceHandlersMap      sync.RWMutex
+	coreClient                  *vgrpc.Client
+	parentAdapterClients        map[string]*vgrpc.Client
+	lockParentAdapterClients    sync.RWMutex
+	eventProxy                  eventif.EventProxy
+	kvClient                    kvstore.Client
+	cm                          *conf.ConfigManager
+	config                      *config.AdapterFlags
+	numOnus                     int
+	KVStoreAddress              string
+	KVStoreType                 string
+	KVStoreTimeout              time.Duration
+	mibTemplatesGenerated       map[string]bool
+	mutexMibTemplateGenerated   sync.RWMutex
+	exitChannel                 chan int
+	HeartbeatCheckInterval      time.Duration
+	HeartbeatFailReportInterval time.Duration
+	AcceptIncrementalEvto       bool
+	//GrpcTimeoutInterval         time.Duration
+	pSupportedFsms             *cmn.OmciDeviceFsms
+	maxTimeoutInterAdapterComm time.Duration
+	maxTimeoutReconciling      time.Duration
+	pDownloadManager           *swupg.AdapterDownloadManager
+	pFileManager               *swupg.FileDownloadManager //let coexist 'old and new' DownloadManager as long as 'old' does not get obsolete
+	MetricsEnabled             bool
+	mibAuditInterval           time.Duration
+	omciTimeout                int // in seconds
+	alarmAuditInterval         time.Duration
+	dlToOnuTimeout4M           time.Duration
+	rpcTimeout                 time.Duration
+}
+
+//NewOpenONUAC returns a new instance of OpenONU_AC
+func NewOpenONUAC(ctx context.Context, coreClient *vgrpc.Client, eventProxy eventif.EventProxy,
+	kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC {
+	var openOnuAc OpenONUAC
+	openOnuAc.exitChannel = make(chan int, 1)
+	openOnuAc.deviceHandlers = make(map[string]*deviceHandler)
+	openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool)
+	openOnuAc.parentAdapterClients = make(map[string]*vgrpc.Client)
+	openOnuAc.mutexDeviceHandlersMap = sync.RWMutex{}
+	openOnuAc.config = cfg
+	openOnuAc.cm = cm
+	openOnuAc.coreClient = coreClient
+	openOnuAc.numOnus = cfg.OnuNumber
+	openOnuAc.eventProxy = eventProxy
+	openOnuAc.kvClient = kvClient
+	openOnuAc.KVStoreAddress = cfg.KVStoreAddress
+	openOnuAc.KVStoreType = cfg.KVStoreType
+	openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout
+	openOnuAc.mibTemplatesGenerated = make(map[string]bool)
+	openOnuAc.mutexMibTemplateGenerated = sync.RWMutex{}
+	openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
+	openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
+	openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto
+	openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm
+	openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling
+	//openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
+	openOnuAc.MetricsEnabled = cfg.MetricsEnabled
+	openOnuAc.mibAuditInterval = cfg.MibAuditInterval
+	// since consumers of OMCI timeout value everywhere in code is in "int seconds", do this useful conversion
+	openOnuAc.omciTimeout = int(cfg.OmciTimeout.Seconds())
+	openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval
+	openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB
+	openOnuAc.rpcTimeout = cfg.RPCTimeout
+
+	openOnuAc.pSupportedFsms = &cmn.OmciDeviceFsms{
+		"mib-synchronizer": {
+			//mibSyncFsm,        // Implements the MIB synchronization state machine
+			DatabaseClass: mibDbVolatileDictImpl, // Implements volatile ME MIB database
+			//true,                  // Advertise events on OpenOMCI event bus
+			AuditInterval: openOnuAc.mibAuditInterval, // Time to wait between MIB audits.  0 to disable audits.
+			// map[string]func() error{
+			// 	"mib-upload":    onuDeviceEntry.MibUploadTask,
+			// 	"mib-template":  onuDeviceEntry.MibTemplateTask,
+			// 	"get-mds":       onuDeviceEntry.GetMdsTask,
+			// 	"mib-audit":     onuDeviceEntry.GetMdsTask,
+			// 	"mib-resync":    onuDeviceEntry.MibResyncTask,
+			// 	"mib-reconcile": onuDeviceEntry.MibReconcileTask,
+			// },
+		},
+	}
+
+	openOnuAc.pDownloadManager = swupg.NewAdapterDownloadManager(ctx)
+	openOnuAc.pFileManager = swupg.NewFileDownloadManager(ctx)
+	openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout)
+
+	return &openOnuAc
+}
+
+//Start starts (logs) the adapter
+func (oo *OpenONUAC) Start(ctx context.Context) error {
+	logger.Info(ctx, "starting-openonu-adapter")
+
+	return nil
+}
+
+/*
+//stop terminates the session
+func (oo *OpenONUAC) stop(ctx context.Context) error {
+	logger.Info(ctx,"stopping-device-manager")
+	oo.exitChannel <- 1
+	logger.Info(ctx,"device-manager-stopped")
+	return nil
+}
+*/
+
+func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) {
+	oo.mutexDeviceHandlersMap.Lock()
+	defer oo.mutexDeviceHandlersMap.Unlock()
+	if _, exist := oo.deviceHandlers[agent.DeviceID]; !exist {
+		oo.deviceHandlers[agent.DeviceID] = agent
+		oo.deviceHandlers[agent.DeviceID].start(ctx)
+		if _, exist := oo.deviceHandlersCreateChan[agent.DeviceID]; exist {
+			logger.Debugw(ctx, "deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.DeviceID})
+			oo.deviceHandlersCreateChan[agent.DeviceID] <- true
+		}
+	}
+}
+
+func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) {
+	oo.mutexDeviceHandlersMap.Lock()
+	defer oo.mutexDeviceHandlersMap.Unlock()
+	delete(oo.deviceHandlers, agent.DeviceID)
+	delete(oo.deviceHandlersCreateChan, agent.DeviceID)
+}
+
+//getDeviceHandler gets the ONU deviceHandler and may wait until it is created
+func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) *deviceHandler {
+	oo.mutexDeviceHandlersMap.Lock()
+	agent, ok := oo.deviceHandlers[deviceID]
+	if aWait && !ok {
+		logger.Infow(ctx, "Race condition: deviceHandler not present - wait for creation or timeout",
+			log.Fields{"device-id": deviceID})
+		if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist {
+			oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1)
+		}
+		deviceCreateChan := oo.deviceHandlersCreateChan[deviceID]
+		//keep the read sema short to allow for subsequent write
+		oo.mutexDeviceHandlersMap.Unlock()
+		// based on concurrent processing the deviceHandler creation may not yet be finished at his point
+		// so it might be needed to wait here for that event with some timeout
+		select {
+		case <-time.After(1 * time.Second): //timer may be discussed ...
+			logger.Warnw(ctx, "No valid deviceHandler created after max WaitTime", log.Fields{"device-id": deviceID})
+			return nil
+		case <-deviceCreateChan:
+			logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID})
+			oo.mutexDeviceHandlersMap.RLock()
+			defer oo.mutexDeviceHandlersMap.RUnlock()
+			return oo.deviceHandlers[deviceID]
+		}
+	}
+	oo.mutexDeviceHandlersMap.Unlock()
+	return agent
+}
+
+// GetHealthStatus is used as a service readiness validation as a grpc connection
+func (oo *OpenONUAC) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*voltha.HealthStatus, error) {
+	return &voltha.HealthStatus{State: voltha.HealthStatus_HEALTHY}, nil
+}
+
+// AdoptDevice creates a new device handler if not present already and then adopts the device
+func (oo *OpenONUAC) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
+	if device == nil {
+		logger.Warn(ctx, "voltha-device-is-nil")
+		return nil, errors.New("nil-device")
+	}
+	logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
+	var handler *deviceHandler
+	if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
+		handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo)
+		oo.addDeviceHandlerToMap(ctx, handler)
+
+		// Setup the grpc communication with the parent adapter
+		if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil {
+			// TODO: Cleanup on failure needed
+			return nil, err
+		}
+
+		go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), device)
+	}
+	return &empty.Empty{}, nil
+}
+
+//ReconcileDevice is called once when the adapter needs to re-create device - usually on core restart
+func (oo *OpenONUAC) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
+	if device == nil {
+		logger.Warn(ctx, "reconcile-device-voltha-device-is-nil")
+		return nil, errors.New("nil-device")
+	}
+	logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id})
+	var handler *deviceHandler
+	if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
+		handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo)
+		oo.addDeviceHandlerToMap(ctx, handler)
+		handler.device = device
+		if err := handler.updateDeviceStateInCore(log.WithSpanFromContext(context.Background(), ctx), &ic.DeviceStateFilter{
+			DeviceId:   device.Id,
+			OperStatus: voltha.OperStatus_RECONCILING,
+			ConnStatus: device.ConnectStatus,
+		}); err != nil {
+			return nil, fmt.Errorf("not able to update device state to reconciling. Err : %s", err.Error())
+		}
+		// Setup the grpc communication with the parent adapter
+		if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil {
+			// TODO: Cleanup on failure needed
+			return nil, err
+		}
+
+		handler.StartReconciling(log.WithSpanFromContext(context.Background(), ctx), false)
+		go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), handler.device)
+		// reconcilement will be continued after onu-device entry is added
+	} else {
+		return nil, fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id))
+	}
+	return &empty.Empty{}, nil
+}
+
+//DisableDevice disables the given device
+func (oo *OpenONUAC) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
+	logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
+	if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
+		go handler.disableDevice(log.WithSpanFromContext(context.Background(), ctx), device)
+		return &empty.Empty{}, nil
+	}
+	logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id})
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
+}
+
+//ReEnableDevice enables the onu device after disable
+func (oo *OpenONUAC) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
+	logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
+	if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
+		go handler.reEnableDevice(log.WithSpanFromContext(context.Background(), ctx), device)
+		return &empty.Empty{}, nil
+	}
+	logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id})
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
+}
+
+//RebootDevice reboots the given device
+func (oo *OpenONUAC) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
+	logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
+	if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
+		go handler.rebootDevice(log.WithSpanFromContext(context.Background(), ctx), true, device) //reboot request with device checking
+		return &empty.Empty{}, nil
+	}
+	logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id})
+	return nil, fmt.Errorf("handler-not-found-for-device: %s", device.Id)
+}
+
+// DeleteDevice deletes the given device
+func (oo *OpenONUAC) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
+	nctx := log.WithSpanFromContext(context.Background(), ctx)
+
+	logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber, "ctx": ctx, "nctx": nctx})
+	if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
+		var errorsList []error
+
+		handler.mutexDeletionInProgressFlag.Lock()
+		handler.deletionInProgress = true
+		handler.mutexDeletionInProgressFlag.Unlock()
+
+		if err := handler.deleteDevicePersistencyData(ctx); err != nil {
+			errorsList = append(errorsList, err)
+		}
+
+		// Stop PM, Alarm and Self Test event handler routines
+		if handler.GetCollectorIsRunning() {
+			handler.stopCollector <- true
+			logger.Debugw(ctx, "sent stop signal to metric collector routine", log.Fields{"device-id": device.Id})
+
+		}
+		if handler.GetAlarmManagerIsRunning(ctx) {
+			handler.stopAlarmManager <- true
+			logger.Debugw(ctx, "sent stop signal to alarm manager", log.Fields{"device-id": device.Id})
+		}
+		if handler.pSelfTestHdlr.GetSelfTestHandlerIsRunning() {
+			handler.pSelfTestHdlr.StopSelfTestModule <- true
+			logger.Debugw(ctx, "sent stop signal to self test handler module", log.Fields{"device-id": device.Id})
+		}
+
+		// Clear PM data on the KV store
+		if handler.pOnuMetricsMgr != nil {
+			if err := handler.pOnuMetricsMgr.ClearAllPmData(ctx); err != nil {
+				errorsList = append(errorsList, err)
+			}
+		}
+
+		//don't leave any garbage - even in error case
+		oo.deleteDeviceHandlerToMap(handler)
+		if len(errorsList) > 0 {
+			logger.Errorw(ctx, "one-or-more-error-during-device-delete", log.Fields{"device-id": device.Id})
+			return nil, fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", errorsList)
+		}
+		return &empty.Empty{}, nil
+	}
+	logger.Warnw(ctx, "no handler found for device-deletion", log.Fields{"device-id": device.Id})
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
+}
+
+//UpdateFlowsIncrementally updates (add/remove) the flows on a given device
+func (oo *OpenONUAC) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ic.IncrementalFlows) (*empty.Empty, error) {
+	logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": incrFlows.Device.Id})
+
+	//flow config is relayed to handler even if the device might be in some 'inactive' state
+	// let the handler or related FSM's decide, what to do with the modified flow state info
+	// at least the flow-remove must be done in respect to internal data, while OMCI activity might not be needed here
+
+	// For now, there is no support for group changes (as in the actual Py-adapter code)
+	//   but processing is continued for flowUpdate possibly also set in the request
+	if incrFlows.Groups.ToAdd != nil && incrFlows.Groups.ToAdd.Items != nil {
+		logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
+	}
+	if incrFlows.Groups.ToRemove != nil && incrFlows.Groups.ToRemove.Items != nil {
+		logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
+	}
+	if incrFlows.Groups.ToUpdate != nil && incrFlows.Groups.ToUpdate.Items != nil {
+		logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id})
+	}
+
+	if handler := oo.getDeviceHandler(ctx, incrFlows.Device.Id, false); handler != nil {
+		if err := handler.FlowUpdateIncremental(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil {
+			return nil, err
+		}
+		return &empty.Empty{}, nil
+	}
+	logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": incrFlows.Device.Id})
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", incrFlows.Device.Id))
+}
+
+//UpdatePmConfig returns PmConfigs nil or error
+func (oo *OpenONUAC) UpdatePmConfig(ctx context.Context, configs *ic.PmConfigsInfo) (*empty.Empty, error) {
+	logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": configs.DeviceId})
+	if handler := oo.getDeviceHandler(ctx, configs.DeviceId, false); handler != nil {
+		if err := handler.updatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs); err != nil {
+			return nil, err
+		}
+		return &empty.Empty{}, nil
+	}
+	logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": configs.DeviceId})
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", configs.DeviceId))
+}
+
+//DownloadImage requests downloading some image according to indications as given in request
+//The ImageDownload needs to be called `request`due to library reflection requirements
+func (oo *OpenONUAC) DownloadImage(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
+	ctx = log.WithSpanFromContext(context.Background(), ctx)
+	if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
+		if !oo.pDownloadManager.ImageExists(ctx, imageInfo.Image) {
+			logger.Debugw(ctx, "start image download", log.Fields{"image-description": imageInfo.Image})
+			// Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems
+			// the download itself is later done in background
+			if err := oo.pDownloadManager.StartDownload(ctx, imageInfo.Image); err != nil {
+				return nil, err
+			}
+			return imageInfo.Image, nil
+		}
+		// image already exists
+		logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageInfo.Image})
+		return imageInfo.Image, nil
+	}
+
+	return nil, errors.New("invalid image definition")
+}
+
+//ActivateImageUpdate requests downloading some Onu Software image to the INU via OMCI
+//  according to indications as given in request and on success activate the image on the ONU
+//The ImageDownload needs to be called `request`due to library reflection requirements
+func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
+	if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" {
+		if oo.pDownloadManager.ImageLocallyDownloaded(ctx, imageInfo.Image) {
+			if handler := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil {
+				logger.Debugw(ctx, "image download on omci requested", log.Fields{
+					"image-description": imageInfo.Image, "device-id": imageInfo.Device.Id})
+				if err := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); err != nil {
+					return nil, err
+				}
+				return imageInfo.Image, nil
+			}
+			logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id})
+			return nil, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", imageInfo.Device.Id))
+		}
+		logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": imageInfo.Image})
+		return nil, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", imageInfo.Device.Id))
+	}
+	return nil, errors.New("invalid image definition")
+}
+
+//GetSingleValue handles the core request to retrieve uni status
+func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
+	logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request})
+
+	if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil {
+		switch reqType := request.GetRequest().GetRequest().(type) {
+		case *extension.GetValueRequest_UniInfo:
+			return handler.GetUniPortStatus(ctx, reqType.UniInfo), nil
+		case *extension.GetValueRequest_OnuOpticalInfo:
+			CommChan := make(chan cmn.Message)
+			respChan := make(chan extension.SingleGetValueResponse)
+			// Initiate the self test request
+			if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, CommChan, respChan); err != nil {
+				return &extension.SingleGetValueResponse{
+					Response: &extension.GetValueResponse{
+						Status:    extension.GetValueResponse_ERROR,
+						ErrReason: extension.GetValueResponse_INTERNAL_ERROR,
+					},
+				}, err
+			}
+			// The timeout handling is already implemented in omci_self_test_handler module
+			resp := <-respChan
+			return &resp, nil
+		case *extension.GetValueRequest_OnuInfo:
+			return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil
+		default:
+			return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil
+
+		}
+	}
+	logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
+	return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil
+}
+
+//if update >= 4.3.0
+// Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same
+//   as defined in the adapter interface file. That sounds strange and the effects were strange as well.
+//   The reason for that was never finally investigated.
+//   To be on the safe side argument names are left here always as defined in iAdapter.go .
+
+// DownloadOnuImage downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s)
+//   if the image is not yet present on the adapter it has to be automatically downloaded
+func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
+	if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" {
+		loResponse := voltha.DeviceImageResponse{}
+		imageIdentifier := (*request).Image.Version
+		downloadedToAdapter := false
+		firstDevice := true
+		var vendorID string
+		for _, pCommonID := range (*request).DeviceId {
+			vendorIDMatch := true
+			loDeviceID := (*pCommonID).Id
+			loDeviceImageState := voltha.DeviceImageState{}
+			loDeviceImageState.DeviceId = loDeviceID
+			loImageState := voltha.ImageState{}
+			loDeviceImageState.ImageState = &loImageState
+			loDeviceImageState.ImageState.Version = (*request).Image.Version
+
+			handler := oo.getDeviceHandler(ctx, loDeviceID, false)
+			if handler == nil {
+				//cannot start ONU download for requested device
+				logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID})
+				loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
+				loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
+				loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
+				loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
+				continue
+			}
+
+			onuVolthaDevice, err := handler.getDeviceFromCore(ctx, loDeviceID)
+			if err != nil || onuVolthaDevice == nil {
+				logger.Warnw(ctx, "Failed to fetch Onu device for image download",
+					log.Fields{"device-id": loDeviceID, "err": err})
+				loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
+				loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE'
+				loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
+			} else {
+				if firstDevice {
+					//start/verify download of the image to the adapter based on first found device only
+					//  use the OnuVendor identification from first given device
+					firstDevice = false
+					vendorID = onuVolthaDevice.VendorId
+					imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
+					logger.Debugw(ctx, "download request for file", log.Fields{"image-id": imageIdentifier})
+
+					if !oo.pFileManager.ImageExists(ctx, imageIdentifier) {
+						logger.Debugw(ctx, "start image download", log.Fields{"image-description": request})
+						// Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems
+						// the download itself is later done in background
+						if err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil {
+							downloadedToAdapter = true
+						}
+						//else: treat any error here as 'INVALID_URL' (even though it might as well be some issue on local FS, eg. 'INSUFFICIENT_SPACE')
+						// otherwise a more sophisticated error evaluation is needed
+					} else {
+						// image already exists
+						downloadedToAdapter = true
+						logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageIdentifier})
+						// note: If the image (with vendorId+name) has already been downloaded before from some other
+						//   valid URL, the current URL is just ignored. If the operators want to ensure that the new URL
+						//   is really used, then they first have to use the 'abort' API to remove the existing image!
+						//   (abort API can be used also after some successful download to just remove the image from adapter)
+					}
+				} else {
+					//for all following devices verify the matching vendorID
+					if onuVolthaDevice.VendorId != vendorID {
+						logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
+							log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
+						vendorIDMatch = false
+					}
+				}
+				if downloadedToAdapter && vendorIDMatch {
+					// start the ONU download activity for each possible device
+					// assumption here is, that the concerned device was already created (automatic start after device creation not supported)
+					if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
+						logger.Debugw(ctx, "image download on omci requested", log.Fields{
+							"image-id": imageIdentifier, "device-id": loDeviceID})
+						//onu upgrade handling called in background without immediate error evaluation here
+						//  as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
+						//  state/progress/success of the request has to be verified using the Get_onu_image_status() API
+						go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier)
+						loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED
+						loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
+						loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
+					} else {
+						//cannot start ONU download for requested device
+						logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID})
+						loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
+						loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE'
+						loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
+					}
+				} else {
+					loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
+					if !downloadedToAdapter {
+						loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL
+					} else { //only logical option is !vendorIDMatch
+						loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
+					}
+					loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
+				}
+			}
+
+			// start the ONU download activity for each possible device
+			logger.Debugw(ctx, "image download on omci requested", log.Fields{
+				"image-id": imageIdentifier, "device-id": loDeviceID})
+			//onu upgrade handling called in background without immediate error evaluation here
+			//  as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
+			//  state/progress/success of the request has to be verified using the Get_onu_image_status() API
+			go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier)
+			loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED
+			loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
+			loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
+			loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
+		}
+		pImageResp := &loResponse
+		return pImageResp, nil
+	}
+	return nil, errors.New("invalid image download parameters")
+}
+
+// GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment
+//   status for the requested image
+func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
+	if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
+		loResponse := voltha.DeviceImageResponse{}
+		imageIdentifier := (*in).Version
+		var vendorIDSet bool
+		firstDevice := true
+		var vendorID string
+		for _, pCommonID := range (*in).DeviceId {
+			loDeviceID := (*pCommonID).Id
+			pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID}
+			handler := oo.getDeviceHandler(ctx, loDeviceID, false)
+			if handler == nil {
+				//cannot get the handler
+				logger.Warnw(ctx, "no handler found for image status request ", log.Fields{"device-id": loDeviceID})
+				pDeviceImageState.DeviceId = loDeviceID
+				pDeviceImageState.ImageState.Version = (*in).Version
+				pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
+				pDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
+				pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
+				loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
+				continue
+			}
+			onuVolthaDevice, err := handler.getDeviceFromCore(ctx, loDeviceID)
+			if err != nil || onuVolthaDevice == nil {
+				logger.Warnw(ctx, "Failed to fetch Onu device to get image status",
+					log.Fields{"device-id": loDeviceID, "err": err})
+				pImageState := &voltha.ImageState{
+					Version:       (*in).Version,
+					DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible
+					Reason:        voltha.ImageState_UNKNOWN_ERROR,    //something like "DEVICE_NOT_EXISTS" would be better (proto def)
+					ImageState:    voltha.ImageState_IMAGE_UNKNOWN,
+				}
+				pDeviceImageState.ImageState = pImageState
+			} else {
+				if firstDevice {
+					//start/verify download of the image to the adapter based on first found device only
+					//  use the OnuVendor identification from first given device
+					firstDevice = false
+					vendorID = onuVolthaDevice.VendorId
+					imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
+					vendorIDSet = true
+					logger.Debugw(ctx, "status request for image", log.Fields{"image-id": imageIdentifier})
+				} else {
+					//for all following devices verify the matching vendorID
+					if onuVolthaDevice.VendorId != vendorID {
+						logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
+							log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
+					} else {
+						vendorIDSet = true
+					}
+				}
+				if !vendorIDSet {
+					pImageState := &voltha.ImageState{
+						Version:       (*in).Version,
+						DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried
+						Reason:        voltha.ImageState_VENDOR_DEVICE_MISMATCH,
+						ImageState:    voltha.ImageState_IMAGE_UNKNOWN,
+					}
+					pDeviceImageState.ImageState = pImageState
+				} else {
+					logger.Debugw(ctx, "image status request for", log.Fields{
+						"image-id": imageIdentifier, "device-id": loDeviceID})
+					//status request is called synchronously to collect the indications for all concerned devices
+					pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version)
+				}
+			}
+			loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
+		}
+		pImageResp := &loResponse
+		return pImageResp, nil
+	}
+	return nil, errors.New("invalid image status request parameters")
+}
+
+// AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step)
+func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
+	if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
+		loResponse := voltha.DeviceImageResponse{}
+		imageIdentifier := (*in).Version
+		firstDevice := true
+		var vendorID string
+		for _, pCommonID := range (*in).DeviceId {
+			loDeviceID := (*pCommonID).Id
+			pDeviceImageState := &voltha.DeviceImageState{}
+			loImageState := voltha.ImageState{}
+			pDeviceImageState.ImageState = &loImageState
+
+			handler := oo.getDeviceHandler(ctx, loDeviceID, false)
+			if handler == nil {
+				//cannot start ONU download for requested device
+				logger.Warnw(ctx, "no handler found for aborting upgrade ", log.Fields{"device-id": loDeviceID})
+				pDeviceImageState.DeviceId = loDeviceID
+				pDeviceImageState.ImageState.Version = (*in).Version
+				//nolint:misspell
+				pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_CANCELLED
+				//nolint:misspell
+				pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST
+				pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
+				loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
+				continue
+			}
+			onuVolthaDevice, err := handler.getDeviceFromCore(ctx, loDeviceID)
+			if err != nil || onuVolthaDevice == nil {
+				logger.Warnw(ctx, "Failed to fetch Onu device to abort its download",
+					log.Fields{"device-id": loDeviceID, "err": err})
+				continue //try the work with next deviceId
+			}
+
+			if firstDevice {
+				//start/verify download of the image to the adapter based on first found device only
+				//  use the OnuVendor identification from first given device
+				firstDevice = false
+				vendorID = onuVolthaDevice.VendorId
+				imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
+				logger.Debugw(ctx, "abort request for file", log.Fields{"image-id": imageIdentifier})
+			} else {
+				//for all following devices verify the matching vendorID
+				if onuVolthaDevice.VendorId != vendorID {
+					logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
+						log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
+					continue //try the work with next deviceId
+				}
+			}
+
+			// cancel the ONU upgrade activity for each possible device
+			logger.Debugw(ctx, "image upgrade abort requested", log.Fields{
+				"image-id": imageIdentifier, "device-id": loDeviceID})
+			//upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices
+			handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState)
+			loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
+		}
+		if !firstDevice {
+			//if at least one valid device was found cancel also a possibly running download to adapter and remove the image
+			//  this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes
+			oo.pFileManager.CancelDownload(ctx, imageIdentifier)
+		}
+		pImageResp := &loResponse
+		return pImageResp, nil
+	}
+	return nil, errors.New("invalid image upgrade abort parameters")
+}
+
+// GetOnuImages retrieves the ONU SW image status information via OMCI
+func (oo *OpenONUAC) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) {
+	logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": id.Id})
+	if handler := oo.getDeviceHandler(ctx, id.Id, false); handler != nil {
+		images, err := handler.getOnuImages(ctx)
+		if err == nil {
+			return images, nil
+		}
+		return nil, fmt.Errorf(fmt.Sprintf("%s-%s", err, id.Id))
+	}
+	logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": id.Id})
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", id.Id))
+}
+
+// ActivateOnuImage initiates the activation of the image for the requested ONU(s)
+//  precondition: image downloaded and not yet activated or image refers to current inactive image
+func (oo *OpenONUAC) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
+	if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
+		loResponse := voltha.DeviceImageResponse{}
+		imageIdentifier := (*in).Version
+		//let the deviceHandler find the adequate way of requesting the image activation
+		for _, pCommonID := range (*in).DeviceId {
+			loDeviceID := (*pCommonID).Id
+			loDeviceImageState := voltha.DeviceImageState{}
+			loDeviceImageState.DeviceId = loDeviceID
+			loImageState := voltha.ImageState{}
+			loDeviceImageState.ImageState = &loImageState
+			loDeviceImageState.ImageState.Version = imageIdentifier
+			//compared to download procedure the vendorID (from device) is secondary here
+			//   and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
+			// start image activation activity for each possible device
+			// assumption here is, that the concerned device was already created (automatic start after device creation not supported)
+			if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
+				logger.Debugw(ctx, "onu image activation requested", log.Fields{
+					"image-id": imageIdentifier, "device-id": loDeviceID})
+				//onu activation handling called in background without immediate error evaluation here
+				//  as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
+				//  state/progress/success of the request has to be verified using the Get_onu_image_status() API
+				if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil {
+					loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
+					loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
+					loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
+				} else {
+					loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
+					loDeviceImageState.ImageState.Reason = pImageStates.Reason
+					loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
+				}
+			} else {
+				//cannot start SW activation for requested device
+				logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID})
+				loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
+				loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
+				loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
+			}
+			loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
+		}
+		pImageResp := &loResponse
+		return pImageResp, nil
+	}
+	return nil, errors.New("invalid image activation parameters")
+}
+
+// CommitOnuImage enforces the commitment of the image for the requested ONU(s)
+//  precondition: image activated and not yet committed
+func (oo *OpenONUAC) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
+	if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
+		loResponse := voltha.DeviceImageResponse{}
+		imageIdentifier := (*in).Version
+		//let the deviceHandler find the adequate way of requesting the image activation
+		for _, pCommonID := range (*in).DeviceId {
+			loDeviceID := (*pCommonID).Id
+			loDeviceImageState := voltha.DeviceImageState{}
+			loDeviceImageState.DeviceId = loDeviceID
+			loImageState := voltha.ImageState{}
+			loDeviceImageState.ImageState = &loImageState
+			loDeviceImageState.ImageState.Version = imageIdentifier
+			//compared to download procedure the vendorID (from device) is secondary here
+			//   and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
+			// start image activation activity for each possible device
+			// assumption here is, that the concerned device was already created (automatic start after device creation not supported)
+			if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
+				logger.Debugw(ctx, "onu image commitment requested", log.Fields{
+					"image-id": imageIdentifier, "device-id": loDeviceID})
+				//onu commitment handling called in background without immediate error evaluation here
+				//  as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
+				//  state/progress/success of the request has to be verified using the Get_onu_image_status() API
+				if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil {
+					loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
+					loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //can be multiple reasons here
+					loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
+				} else {
+					loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
+					loDeviceImageState.ImageState.Reason = pImageStates.Reason
+					loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
+				}
+			} else {
+				//cannot start SW commitment for requested device
+				logger.Warnw(ctx, "no handler found for image commitment", log.Fields{"device-id": loDeviceID})
+				loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
+				loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
+				loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
+			}
+			loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
+		}
+		pImageResp := &loResponse
+		return pImageResp, nil
+	}
+	return nil, errors.New("invalid image commitment parameters")
+}
+
+// Adapter interface required methods ################ end #########
+// #################################################################
+
+/*
+ *
+ * ONU inter adapter service
+ *
+ */
+
+// OnuIndication is part of the ONU Inter-adapter service API.
+func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ic.OnuIndicationMessage) (*empty.Empty, error) {
+	logger.Debugw(ctx, "onu-indication", log.Fields{"onu-indication": onuInd})
+
+	if onuInd == nil || onuInd.OnuIndication == nil {
+		return nil, fmt.Errorf("invalid-onu-indication-%v", onuInd)
+	}
+
+	onuIndication := onuInd.OnuIndication
+	onuOperstate := onuIndication.GetOperState()
+	waitForDhInstPresent := false
+	if onuOperstate == "up" {
+		//Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core,
+		//ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding
+		//ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of
+		//Adopt_device() arrived and DeviceHandler instance was created
+		waitForDhInstPresent = true
+	}
+	if handler := oo.getDeviceHandler(ctx, onuInd.DeviceId, waitForDhInstPresent); handler != nil {
+		logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": onuInd.DeviceId,
+			"OnuId":      onuIndication.GetOnuId(),
+			"AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate,
+			"SNR": onuIndication.GetSerialNumber()})
+
+		if onuOperstate == "up" {
+			if err := handler.createInterface(ctx, onuIndication); err != nil {
+				return nil, err
+			}
+			return &empty.Empty{}, nil
+		} else if (onuOperstate == "down") || (onuOperstate == "unreachable") {
+			return nil, handler.updateInterface(ctx, onuIndication)
+		} else {
+			logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()})
+			return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId)
+		}
+	}
+	logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{
+		"msgToDeviceId": onuInd.DeviceId})
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", onuInd.DeviceId))
+}
+
+// OmciIndication is part of the ONU Inter-adapter service API.
+func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ic.OmciMessage) (*empty.Empty, error) {
+	logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId})
+
+	if handler := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil {
+		if err := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); err != nil {
+			return nil, err
+		}
+		return &empty.Empty{}, nil
+	}
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", msg.ChildDeviceId))
+}
+
+// DownloadTechProfile is part of the ONU Inter-adapter service API.
+func (oo *OpenONUAC) DownloadTechProfile(ctx context.Context, tProfile *ic.TechProfileDownloadMessage) (*empty.Empty, error) {
+	logger.Debugw(ctx, "download-tech-profile", log.Fields{"uni-id": tProfile.UniId})
+
+	if handler := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil {
+		if err := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); err != nil {
+			return nil, err
+		}
+		return &empty.Empty{}, nil
+	}
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", tProfile.DeviceId))
+}
+
+// DeleteGemPort is part of the ONU Inter-adapter service API.
+func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ic.DeleteGemPortMessage) (*empty.Empty, error) {
+	logger.Debugw(ctx, "delete-gem-port", log.Fields{"device-id": gPort.DeviceId, "uni-id": gPort.UniId})
+
+	if handler := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil {
+		if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil {
+			return nil, err
+		}
+		return &empty.Empty{}, nil
+	}
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", gPort.DeviceId))
+}
+
+// DeleteTCont is part of the ONU Inter-adapter service API.
+func (oo *OpenONUAC) DeleteTCont(ctx context.Context, tConf *ic.DeleteTcontMessage) (*empty.Empty, error) {
+	logger.Debugw(ctx, "delete-tcont", log.Fields{"tconf": tConf})
+
+	if handler := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil {
+		if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); err != nil {
+			return nil, err
+		}
+		return &empty.Empty{}, nil
+	}
+	return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", tConf.DeviceId))
+}
+
+/*
+ * Parent GRPC clients
+ */
+
+func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error {
+	logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint})
+	oo.lockParentAdapterClients.Lock()
+	defer oo.lockParentAdapterClients.Unlock()
+	if _, ok := oo.parentAdapterClients[endpoint]; ok {
+		return nil
+	}
+
+	childClient, err := vgrpc.NewClient(endpoint,
+		oo.oltAdapterRestarted,
+		vgrpc.ActivityCheck(true))
+
+	if err != nil {
+		return err
+	}
+
+	oo.parentAdapterClients[endpoint] = childClient
+
+	go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), setAndTestAdapterServiceHandler)
+
+	// Wait until we have a connection to the child adapter.
+	// Unlimited retries or until context expires
+	subCtx := log.WithSpanFromContext(context.TODO(), ctx)
+	backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0)
+	for {
+		client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient()
+		if err == nil && client != nil {
+			logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint})
+			break
+		}
+		logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint})
+		// Backoff
+		if err = backoff.Backoff(subCtx); err != nil {
+			logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint})
+			break
+		}
+	}
+	return nil
+}
+
+func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (adapter_services.OltInterAdapterServiceClient, error) {
+	// First check from cache
+	oo.lockParentAdapterClients.RLock()
+	if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
+		oo.lockParentAdapterClients.RUnlock()
+		return pgClient.GetOltInterAdapterServiceClient()
+	}
+	oo.lockParentAdapterClients.RUnlock()
+
+	// Set the parent connection - can occur on restarts
+	ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout)
+	err := oo.setupParentInterAdapterClient(ctx, endpoint)
+	cancel()
+	if err != nil {
+		return nil, err
+	}
+
+	// Get the parent client now
+	oo.lockParentAdapterClients.RLock()
+	defer oo.lockParentAdapterClients.RUnlock()
+	if pgClient, ok := oo.parentAdapterClients[endpoint]; ok {
+		return pgClient.GetOltInterAdapterServiceClient()
+	}
+
+	return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint)
+}
+
+// TODO:  Any action the adapter needs to do following an olt adapter restart?
+func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error {
+	logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint})
+	return nil
+}
+
+// setAndTestAdapterServiceHandler is used to test whether the remote gRPC service is up
+func setAndTestAdapterServiceHandler(ctx context.Context, conn *grpc.ClientConn) interface{} {
+	svc := adapter_services.NewOltInterAdapterServiceClient(conn)
+	if h, err := svc.GetHealthStatus(ctx, &empty.Empty{}); err != nil || h.State != voltha.HealthStatus_HEALTHY {
+		return nil
+	}
+	return svc
+}
+
+/*
+ *
+ * Unimplemented APIs
+ *
+ */
+
+//GetOfpDeviceInfo returns OFP information for the given device.  Method not implemented as per [VOL-3202].
+// OF port info is now to be delivered within UniPort create cmp changes in onu_uni_port.go::CreateVolthaPort()
+//
+func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//SimulateAlarm is unimplemented
+func (oo *OpenONUAC) SimulateAlarm(context.Context, *ic.SimulateAlarmMessage) (*common.OperationResp, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//SetExtValue is unimplemented
+func (oo *OpenONUAC) SetExtValue(context.Context, *ic.SetExtValueMessage) (*empty.Empty, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//SetSingleValue is unimplemented
+func (oo *OpenONUAC) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//StartOmciTest not implemented
+func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ic.OMCITest) (*voltha.TestResponse, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//SuppressEvent unimplemented
+func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//UnSuppressEvent  unimplemented
+func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//GetImageDownloadStatus is unimplemented
+func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//CancelImageDownload is unimplemented
+func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//RevertImageUpdate is unimplemented
+func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) {
+	return nil, errors.New("unImplemented")
+}
+
+// UpdateFlowsBulk is unimplemented
+func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ic.BulkFlows) (*empty.Empty, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//SelfTestDevice unimplented
+func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
+	return nil, errors.New("unImplemented")
+}
+
+//SendPacketOut sends packet out to the device
+func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ic.PacketOut) (*empty.Empty, error) {
+	return nil, errors.New("unImplemented")
+}
+
+// EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code
+func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
+	return nil, errors.New("unImplemented")
+}
+
+// DisablePort to Disable pon/nni interface  - seems not to be used/required according to python code
+func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
+	return nil, errors.New("unImplemented")
+}
+
+// GetExtValue - unimplemented
+func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ic.GetExtValueMessage) (*voltha.ReturnValues, error) {
+	return nil, errors.New("unImplemented")
+}
+
+// ChildDeviceLost - unimplemented
+func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) {
+	return nil, errors.New("unImplemented")
+}
+
+// GetSupportedFsms - TODO: add comment
+func (oo *OpenONUAC) GetSupportedFsms() *cmn.OmciDeviceFsms {
+	return oo.pSupportedFsms
+}
+
+// LockMutexMibTemplateGenerated - TODO: add comment
+func (oo *OpenONUAC) LockMutexMibTemplateGenerated() {
+	oo.mutexMibTemplateGenerated.Lock()
+}
+
+// UnlockMutexMibTemplateGenerated - TODO: add comment
+func (oo *OpenONUAC) UnlockMutexMibTemplateGenerated() {
+	oo.mutexMibTemplateGenerated.Unlock()
+}
+
+// GetMibTemplatesGenerated - TODO: add comment
+func (oo *OpenONUAC) GetMibTemplatesGenerated(mibTemplatePath string) (value bool, exist bool) {
+	value, exist = oo.mibTemplatesGenerated[mibTemplatePath]
+	return value, exist
+}
+
+// SetMibTemplatesGenerated - TODO: add comment
+func (oo *OpenONUAC) SetMibTemplatesGenerated(mibTemplatePath string, value bool) {
+	oo.mibTemplatesGenerated[mibTemplatePath] = value
+}
+
+// RLockMutexDeviceHandlersMap - TODO: add comment
+func (oo *OpenONUAC) RLockMutexDeviceHandlersMap() {
+	oo.mutexDeviceHandlersMap.RLock()
+}
+
+// RUnlockMutexDeviceHandlersMap - TODO: add comment
+func (oo *OpenONUAC) RUnlockMutexDeviceHandlersMap() {
+	oo.mutexDeviceHandlersMap.RUnlock()
+}
+
+// GetDeviceHandler - TODO: add comment
+func (oo *OpenONUAC) GetDeviceHandler(deviceID string) (value cmn.IdeviceHandler, exist bool) {
+	value, exist = oo.deviceHandlers[deviceID]
+	return value, exist
+}
diff --git a/internal/pkg/core/openonuimpl.go b/internal/pkg/core/openonuimpl.go
new file mode 100755
index 0000000..8017d48
--- /dev/null
+++ b/internal/pkg/core/openonuimpl.go
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//Package core provides the utility for onu devices, flows and statistics
+package core
+
+import (
+	"context"
+	"errors"
+)
+
+/*
+OpenOmciAgentDefaults = {
+    'mib-synchronizer': {
+        'state-machine': MibSynchronizer,  # Implements the MIB synchronization state machine
+        'database': MibDbVolatileDict,     # Implements volatile ME MIB database
+        # 'database': MibDbExternal,         # Implements persistent ME MIB database
+        'advertise-events': True,          # Advertise events on OpenOMCI event bus
+        'audit-delay': 60,                 # Time to wait between MIB audits.  0 to disable audits.
+        'tasks': {
+            'mib-upload': MibUploadTask,
+            'mib-template': MibTemplateTask,
+            'get-mds': GetMdsTask,
+            'mib-audit': GetMdsTask,
+            'mib-resync': MibResyncTask,
+            'mib-reconcile': MibReconcileTask
+        }
+    },
+    'omci-capabilities': {
+        'state-machine': OnuOmciCapabilities,   # Implements OMCI capabilities state machine
+        'advertise-events': False,              # Advertise events on OpenOMCI event bus
+        'tasks': {
+            'get-capabilities': OnuCapabilitiesTask # Get supported ME and Commands
+        }
+    },
+    'performance-intervals': {
+        'state-machine': PerformanceIntervals,  # Implements PM Intervals State machine
+        'advertise-events': False,              # Advertise events on OpenOMCI event bus
+        'tasks': {
+            'sync-time': SyncTimeTask,
+            'collect-data': IntervalDataTask,
+            'create-pm': OmciCreatePMRequest,
+            'delete-pm': OmciDeletePMRequest,
+        },
+    },
+    'alarm-synchronizer': {
+        'state-machine': AlarmSynchronizer,    # Implements the Alarm sync state machine
+        'database': AlarmDbExternal,           # For any State storage needs
+        'advertise-events': True,              # Advertise events on OpenOMCI event bus
+        'tasks': {
+            'alarm-resync': AlarmResyncTask
+        }
+     },
+    'image_downloader': {
+        'state-machine': ImageDownloadeSTM,
+        'advertise-event': True,
+        'tasks': {
+            'download-file': FileDownloadTask
+        }
+    },
+    'image_upgrader': {
+        'state-machine': OmciSoftwareImageDownloadSTM,
+        'advertise-event': True,
+        'tasks': {
+            'omci_upgrade_task': OmciSwImageUpgradeTask
+        }
+    }
+    # 'image_activator': {
+    #     'state-machine': OmciSoftwareImageActivateSTM,
+    #     'advertise-event': True,
+    # }
+}
+*/
+
+//suppose global methods per adapter ...
+func mibDbVolatileDictImpl(ctx context.Context) error {
+	logger.Debug(ctx, "MibVolatileDict-called")
+	return errors.New("not_implemented")
+}
+
+/*
+func alarmDbDictImpl() error {
+	logger.Debug("AlarmDb-called")
+	return errors.New("not_implemented")
+}
+*/
diff --git a/internal/pkg/core/platform.go b/internal/pkg/core/platform.go
new file mode 100755
index 0000000..9430e92
--- /dev/null
+++ b/internal/pkg/core/platform.go
@@ -0,0 +1,291 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//Package core provides the utility for onu devices, flows and statistics
+package core
+
+import "context"
+
+//Attention: this file is more or less a coopy of file olt_platform.go from the voltha-openolt-adapter
+// which includes system wide definitions and thus normally should be stored more centrally (within some voltha libs)!!
+
+/*=====================================================================
+
+@TODO: Looks like this Flow id concept below is not used anywhere
+       Propose to remove the below documentation of Flow Id on confirmation
+       of the same
+
+Flow id
+
+    Identifies a flow within a single OLT
+    Flow Id is unique per OLT
+    Multiple GEM ports can map to same flow id
+
+     13    11              4      0
+    +--------+--------------+------+
+    | pon id |    onu id    | Flow |
+    |        |              | idx  |
+    +--------+--------------+------+
+
+    14 bits = 16384 flows (per OLT).
+
+    pon id = 4 bits = 16 PON ports
+    onu id = 7 bits = 128 ONUss per PON port
+    Flow index = 3 bits = 4 bi-directional flows per ONU
+                        = 8 uni-directional flows per ONU
+
+
+Logical (OF) UNI port number
+
+    OpenFlow port number corresponding to PON UNI
+
+     20        12              4      0
+    +--+--------+--------------+------+
+    |0 | pon id |    onu id    |uni id|
+    +--+--------+--------------+------+
+
+    pon id = 8 bits = 256 PON ports
+    onu id = 8 bits = 256 ONUs per PON port
+
+Logical (OF) NNI port number
+
+    OpenFlow port number corresponding to PON NNI
+
+     20                             0
+    +--+----------------------------+
+    |1 |                    intf_id |
+    +--+----------------------------+
+
+    No overlap with UNI port number space
+
+
+PON OLT (OF) port number
+
+    OpenFlow port number corresponding to PON OLT ports
+
+     31     28                                 0
+    +--------+------------------------~~~------+
+    |  0x2   |          pon intf id            |
+    +--------+------------------------~~~------+
+*/
+
+const (
+	// Number of bits for the physical UNI of the ONUs
+	bitsForUniID = 4
+	// Number of bits for the ONU ID
+	bitsForONUID = 8
+	// Number of bits for PON ID
+	bitsForPONID = 8
+	/*
+		// Number of bits to differentiate between UNI and NNI Logical Port
+		bitsForUNINNIDiff = 1
+	*/
+	//maxOnusPerPon is Max number of ONUs on any PON port
+	maxOnusPerPon = (1 << bitsForONUID)
+	//maxPonsPerOlt is Max number of PON ports on any OLT
+	maxPonsPerOlt = (1 << bitsForPONID)
+	//maxUnisPerOnu is the Max number of UNI ports on any ONU
+	maxUnisPerOnu = (1 << bitsForUniID)
+	/*
+		//Bit position where the differentiation bit is located
+		nniUniDiffPos = (bitsForUniID + bitsForONUID + bitsForPONID)
+		//Bit position where the marker for PON port type of OF port is present
+		ponIntfMarkerPos = 28
+		//Value of marker used to distinguish PON port type of OF port
+		ponIntfMarkerValue = 0x2
+		// Number of bits for NNI ID
+		bitsforNNIID = 20
+		// minNniIntPortNum is used to store start range of nni port number (1 << 20) 1048576
+		minNniIntPortNum = (1 << bitsforNNIID)
+		// maxNniPortNum is used to store the maximum range of nni port number ((1 << 21)-1) 2097151
+		maxNniPortNum = ((1 << (bitsforNNIID + 1)) - 1)
+	*/
+)
+
+/*
+//MinUpstreamPortID value
+var minUpstreamPortID = 0xfffd
+
+//MaxUpstreamPortID value
+var maxUpstreamPortID = 0xfffffffd
+
+var controllerPorts = []uint32{0xfffd, 0x7ffffffd, 0xfffffffd}
+*/
+
+//mkUniPortNum returns new UNIportNum based on intfID, onuID and uniID
+func mkUniPortNum(ctx context.Context, intfID, onuID, uniID uint32) uint32 {
+	//extended for checks available in the python onu adapter:!!
+	var limit = int(intfID)
+	if limit > maxPonsPerOlt {
+		logger.Warn(ctx, "Warning: exceeded the MAX pons per OLT")
+	}
+	limit = int(onuID)
+	if limit > maxOnusPerPon {
+		logger.Warn(ctx, "Warning: exceeded the MAX ONUS per PON")
+	}
+	limit = int(uniID)
+	if limit > maxUnisPerOnu {
+		logger.Warn(ctx, "Warning: exceeded the MAX UNIS per ONU")
+	}
+	return (intfID << (bitsForUniID + bitsForONUID)) | (onuID << bitsForUniID) | uniID
+}
+
+/*
+//onuIDFromPortNum returns ONUID derived from portNumber
+func onuIDFromPortNum(portNum uint32) uint32 {
+	return (portNum >> bitsForUniID) & (maxOnusPerPon - 1)
+}
+
+//intfIDFromUniPortNum returns IntfID derived from portNum
+func intfIDFromUniPortNum(portNum uint32) uint32 {
+	return (portNum >> (bitsForUniID + bitsForONUID)) & (maxPonsPerOlt - 1)
+}
+
+//uniIDFromPortNum return UniID derived from portNum
+func uniIDFromPortNum(portNum uint32) uint32 {
+	return (portNum) & (maxUnisPerOnu - 1)
+}
+
+//intfIDToPortNo returns portId derived from intftype, intfId and portType
+func intfIDToPortNo(intfID uint32, intfType voltha.Port_PortType) uint32 {
+	if (intfType) == voltha.Port_ETHERNET_NNI {
+		return (1 << nniUniDiffPos) | intfID
+	}
+	if (intfType) == voltha.Port_PON_OLT {
+		return (ponIntfMarkerValue << ponIntfMarkerPos) | intfID
+	}
+	return 0
+}
+
+//portNoToIntfID returns portnumber derived from interfaceID
+func portNoToIntfID(portno uint32, intfType voltha.Port_PortType) uint32 {
+	if (intfType) == voltha.Port_ETHERNET_NNI {
+		return (1 << nniUniDiffPos) ^ portno
+	}
+	if (intfType) == voltha.Port_PON_OLT {
+		return (ponIntfMarkerValue << ponIntfMarkerPos) ^ portno
+	}
+	return 0
+}
+
+//intfIDFromNniPortNum returns Intf ID derived from portNum
+func intfIDFromNniPortNum(portNum uint32) (uint32, error) {
+	if portNum < minNniIntPortNum || portNum > maxNniPortNum {
+		logger.Errorw(ctx,"NNIPortNumber is not in valid range", log.Fields{"portNum": portNum})
+		return uint32(0), errors.New("invalid-port-range") //olterrors.ErrInvalidPortRange
+	}
+	return (portNum & 0xFFFF), nil
+}
+
+//intfIDToPortTypeName returns port type derived from the intfId
+func intfIDToPortTypeName(intfID uint32) voltha.Port_PortType {
+	if ((ponIntfMarkerValue << ponIntfMarkerPos) ^ intfID) < maxPonsPerOlt {
+		return voltha.Port_PON_OLT
+	}
+	if (intfID & (1 << nniUniDiffPos)) == (1 << nniUniDiffPos) {
+		return voltha.Port_ETHERNET_NNI
+	}
+	return voltha.Port_ETHERNET_UNI
+}
+
+//extractAccessFromFlow returns AccessDevice information
+func extractAccessFromFlow(inPort, outPort uint32) (uint32, uint32, uint32, uint32) {
+	if isUpstream(outPort) {
+		return inPort, intfIDFromUniPortNum(inPort), onuIDFromPortNum(inPort), uniIDFromPortNum(inPort)
+	}
+	return outPort, intfIDFromUniPortNum(outPort), onuIDFromPortNum(outPort), uniIDFromPortNum(outPort)
+}
+
+//isUpstream returns true for Upstream and false for downstream
+func isUpstream(outPort uint32) bool {
+	for _, port := range controllerPorts {
+		if port == outPort {
+			return true
+		}
+	}
+	return (outPort & (1 << nniUniDiffPos)) == (1 << nniUniDiffPos)
+}
+
+//isControllerBoundFlow returns true/false
+func isControllerBoundFlow(outPort uint32) bool {
+	for _, port := range controllerPorts {
+		if port == outPort {
+			return true
+		}
+	}
+	return false
+}
+
+//onuIDFromUniPortNum returns onuId from give portNum information.
+func onuIDFromUniPortNum(portNum uint32) uint32 {
+	return (portNum >> bitsForUniID) & (maxOnusPerPon - 1)
+}
+
+//flowExtractInfo fetches uniport from the flow, based on which it gets and returns ponInf, onuID, uniID, inPort and ethType
+func flowExtractInfo(flow *ofp.OfpFlowStats, flowDirection string) (uint32, uint32, uint32, uint32, uint32, uint32, error) {
+	var uniPortNo uint32
+	var ponIntf uint32
+	var onuID uint32
+	var uniID uint32
+	var inPort uint32
+	var ethType uint32
+
+	if flowDirection == "upstream" {
+		if uniPortNo = flows.GetChildPortFromTunnelId(flow); uniPortNo == 0 {
+			for _, field := range flows.GetOfbFields(flow) {
+				if field.GetType() == flows.IN_PORT {
+					uniPortNo = field.GetPort()
+					break
+				}
+			}
+		}
+	} else if flowDirection == "downstream" {
+		if uniPortNo = flows.GetChildPortFromTunnelId(flow); uniPortNo == 0 {
+			for _, field := range flows.GetOfbFields(flow) {
+				if field.GetType() == flows.METADATA {
+					for _, action := range flows.GetActions(flow) {
+						if action.Type == flows.OUTPUT {
+							if out := action.GetOutput(); out != nil {
+								uniPortNo = out.GetPort()
+							}
+							break
+						}
+					}
+				} else if field.GetType() == flows.IN_PORT {
+					inPort = field.GetPort()
+				} else if field.GetType() == flows.ETH_TYPE {
+					ethType = field.GetEthType()
+				}
+			}
+		}
+	}
+
+	if uniPortNo == 0 {
+		return 0, 0, 0, 0, 0, 0, errors.New("notFound: pon-interface (flowDirection)")
+		// olterrors.NewErrNotFound("pon-interface", log.Fields{"flow-direction": flowDirection}, nil)
+	}
+
+	ponIntf = intfIDFromUniPortNum(uniPortNo)
+	onuID = onuIDFromUniPortNum(uniPortNo)
+	uniID = uniIDFromPortNum(uniPortNo)
+
+	logger.Debugw(ctx,"flow extract info result",
+		log.Fields{"uniPortNo": uniPortNo, "ponIntf": ponIntf,
+			"onuID": onuID, "uniID": uniID, "inPort": inPort, "ethType": ethType})
+
+	return uniPortNo, ponIntf, onuID, uniID, inPort, ethType, nil
+}
+*/