[VOL-3322] Support 1t4gem tech profile
[VOL-3323] Support 1t8gem tech profile
[VOL-3381] Support device restart w/o OLT-trigger: save/restore/delete ONU/TP-data in kv-store
[VOL-3402] Support usage of MIB-upload data during tech profile configuration

Signed-off-by: Holger Hildebrandt <holger.hildebrandt@adtran.com>
Change-Id: If1fb83fe509e8cb0c7300146111bf83d6e458fe5
diff --git a/internal/pkg/onuadaptercore/device_handler.go b/internal/pkg/onuadaptercore/device_handler.go
index a580530..d1cb6f3 100644
--- a/internal/pkg/onuadaptercore/device_handler.go
+++ b/internal/pkg/onuadaptercore/device_handler.go
@@ -325,7 +325,7 @@
 				go dh.pOnuTP.configureUniTp(dctx, techProfMsg.UniId, techProfMsg.Path, &wg)
 				go dh.pOnuTP.updateOnuTpPathKvStore(dctx, &wg)
 				//the wait.. function is responsible for tpProcMutex.Unlock()
-				err := dh.pOnuTP.waitForTpCompletion(cancel, &wg) //wait for background process to finish and collet their result
+				err := dh.pOnuTP.waitForTpCompletion(cancel, &wg) //wait for background process to finish and collect their result
 				return err
 			}
 			// no change, nothing really to do
@@ -475,6 +475,24 @@
 	}
 }
 
+func (dh *DeviceHandler) ReconcileDevice(device *voltha.Device) error {
+	logger.Debugw("reconcile-device", log.Fields{"DeviceId": device.Id, "SerialNumber": device.SerialNumber})
+	if err := dh.pOnuTP.restoreFromOnuTpPathKvStore(context.TODO()); err != nil {
+		return err
+	}
+	// TODO: further actions - init PON, metrics, reload DB ...
+	return nil
+}
+
+func (dh *DeviceHandler) DeleteDevice(device *voltha.Device) error {
+	logger.Debugw("delete-device", log.Fields{"DeviceId": device.Id, "SerialNumber": device.SerialNumber})
+	if err := dh.pOnuTP.deleteOnuTpPathKvStore(context.TODO()); err != nil {
+		return err
+	}
+	// TODO: further actions - stop metrics and FSMs, remove device ...
+	return nil
+}
+
 //  DeviceHandler methods that implement the adapters interface requests## end #########
 // #####################################################################################
 
@@ -1039,11 +1057,9 @@
 			//set internal state anyway - as it was done
 			dh.deviceReason = "discovery-mibsync-complete"
 
-			pDevEntry := dh.GetOnuDeviceEntry(false)
-			unigMap, ok := pDevEntry.pOnuDB.meDb[me.UniGClassID]
-			unigInstKeys := pDevEntry.pOnuDB.GetSortedInstKeys(unigMap)
 			i := uint8(0) //UNI Port limit: see MaxUnisPerOnu (by now 16) (OMCI supports max 255 p.b.)
-			if ok {
+			pDevEntry := dh.GetOnuDeviceEntry(false)
+			if unigInstKeys := pDevEntry.pOnuDB.GetSortedInstKeys(me.UniGClassID); len(unigInstKeys) > 0 {
 				for _, mgmtEntityId := range unigInstKeys {
 					logger.Debugw("Add UNI port for stored UniG instance:", log.Fields{
 						"deviceId": dh.deviceID, "UnigMe EntityID": mgmtEntityId})
@@ -1053,9 +1069,7 @@
 			} else {
 				logger.Debugw("No UniG instances found", log.Fields{"deviceId": dh.deviceID})
 			}
-			veipMap, ok := pDevEntry.pOnuDB.meDb[me.VirtualEthernetInterfacePointClassID]
-			veipInstKeys := pDevEntry.pOnuDB.GetSortedInstKeys(veipMap)
-			if ok {
+			if veipInstKeys := pDevEntry.pOnuDB.GetSortedInstKeys(me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 {
 				for _, mgmtEntityId := range veipInstKeys {
 					logger.Debugw("Add VEIP acc. to stored VEIP instance:", log.Fields{
 						"deviceId": dh.deviceID, "VEIP EntityID": mgmtEntityId})