VOL-4125: Respond with success/failure to flow insertion according the
          operation result in adapter
VOL-4323: Support serialization of flow messages (execute a flow to
          completion before picking up another flow)

Change-Id: I934fc68b103042971109923491a3f27aaf885328
diff --git a/internal/pkg/core/openonu.go b/internal/pkg/core/openonu.go
index c14655e..f0d9ecc 100755
--- a/internal/pkg/core/openonu.go
+++ b/internal/pkg/core/openonu.go
@@ -79,6 +79,7 @@
 	alarmAuditInterval         time.Duration
 	dlToOnuTimeout4M           time.Duration
 	rpcTimeout                 time.Duration
+	maxConcurrentFlowsPerUni   int
 }
 
 //NewOpenONUAC returns a new instance of OpenONU_AC
@@ -114,6 +115,7 @@
 	openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval
 	openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB
 	openOnuAc.rpcTimeout = cfg.RPCTimeout
+	openOnuAc.maxConcurrentFlowsPerUni = cfg.MaxConcurrentFlowsPerUni
 
 	openOnuAc.pSupportedFsms = &cmn.OmciDeviceFsms{
 		"mib-synchronizer": {
@@ -331,6 +333,12 @@
 			handler.pSelfTestHdlr.StopSelfTestModule <- true
 			logger.Debugw(ctx, "sent stop signal to self test handler module", log.Fields{"device-id": device.Id})
 		}
+		for _, uni := range handler.uniEntityMap {
+			if handler.GetFlowMonitoringIsRunning(uni.UniID) {
+				handler.stopFlowMonitoringRoutine[uni.UniID] <- true
+				logger.Debugw(ctx, "sent stop signal to self flow monitoring routine", log.Fields{"device-id": device.Id})
+			}
+		}
 
 		// Clear PM data on the KV store
 		if handler.pOnuMetricsMgr != nil {