[VOL-3800] : Random ping failures seen on alpha and iskratel ONUs during sanity test
- Process gem port deletes after any active flow deletes are completed.
  On certain models of ONUs it is seen that if flow deletes and gem port
  deletes are interleaved with each other and it leaves some stale configuration
  on the ONUs. As a result any further datapath related flow configuration
  will not work predictabily - there are some invalid packet taggings.

  Since during tech profile add, we setup the gemport, tcont before
  adding the flows, it is reasonable to remove flows before deleting
  the tech profile.

Change-Id: I62dbbf046f2ea5f9df5416f99060093b930bd448
diff --git a/internal/pkg/onuadaptercore/device_handler.go b/internal/pkg/onuadaptercore/device_handler.go
index bc8a185..a9683dd 100644
--- a/internal/pkg/onuadaptercore/device_handler.go
+++ b/internal/pkg/onuadaptercore/device_handler.go
@@ -2414,6 +2414,35 @@
 	delete(dh.UniVlanConfigFsmMap, apUniPort.uniID)
 }
 
+//ProcessPendingTpDelete processes any pending TP delete (if available)
+func (dh *deviceHandler) ProcessPendingTpDelete(ctx context.Context, apUniPort *onuUniPort, aTpID uint8) {
+	logger.Debugw(ctx, "enter processing pending tp delete", log.Fields{"device-id": dh.deviceID, "tpID": aTpID})
+	if apUniPort == nil {
+		logger.Errorw(ctx, "uni port is nil", log.Fields{"device-id": dh.deviceID})
+		return
+	}
+	k := uniTP{uniID: apUniPort.uniID, tpID: aTpID}
+	if pAniConfigFsm, ok := dh.pOnuTP.pAniConfigFsm[k]; pAniConfigFsm != nil && ok {
+		pAniConfigStatemachine := pAniConfigFsm.pAdaptFsm.pFsm
+		if pAniConfigStatemachine != nil {
+			//If the gem port delete was waiting on flow remove, indicate event that flow remove is done
+			if pAniConfigStatemachine.Is(aniStWaitingFlowRem) {
+				logger.Debugw(ctx, "ani fsm in aniStWaitingFlowRem state - handling aniEvFlowRemDone event",
+					log.Fields{"device-id": dh.deviceID, "tpID": aTpID})
+				if err := pAniConfigStatemachine.Event(aniEvFlowRemDone); err != nil {
+					logger.Warnw(ctx, "AniConfigFsm: can't continue processing", log.Fields{"err": err,
+						"device-id": dh.deviceID, "UniPort": apUniPort.portNo, "tpID": aTpID})
+					return
+				}
+			} else {
+				logger.Debugw(ctx, "ani fsm not in aniStWaitingFlowRem state", log.Fields{"device-id": dh.deviceID, "tpID": aTpID})
+				return
+			}
+		}
+		return
+	}
+}
+
 //storePersUniFlowConfig updates local storage of OnuUniFlowConfig and writes it into kv-store afterwards to have it
 //available for potential reconcilement