SEBA-355 prevent multiple flow retries of same flow

Change-Id: Ia3949f7262c2ebfd25b74338d1f634bdf7e9ef6c
diff --git a/voltha/adapters/bbsimolt/bbsimolt_flow_mgr.py b/voltha/adapters/bbsimolt/bbsimolt_flow_mgr.py
index 4ac8acc..e1f21a8 100644
--- a/voltha/adapters/bbsimolt/bbsimolt_flow_mgr.py
+++ b/voltha/adapters/bbsimolt/bbsimolt_flow_mgr.py
@@ -55,6 +55,7 @@
             '/devices/{}/flows'.format(self.device_id))
         self.root_proxy = registry('core').get_proxy('/')
         self.platform = BBSimOltPlatform(self.log)
+        self.retry_add_flow_list = []
 
     def add_flow(self, flow):
         self.log.debug('add flow', flow=flow)
@@ -168,6 +169,12 @@
         self.divide_and_add_flow(intf_id, onu_id, classifier_info,
                                  action_info, flow)
 
+    def retry_add_flow(self, flow):
+        self.log.debug("retry-add-flow")
+        if flow.id in self.retry_add_flow_list:
+            self.retry_add_flow_list.remove(flow.id)
+        self.add_flow(flow)
+
     def remove_flow(self, flow):
         self.log.debug('trying to remove flows from logical flow :',
                        logical_flow=flow)
@@ -603,7 +610,11 @@
         if len(next_flows) == 0:
             self.log.warning('no next flow found, it may be a timing issue',
                              flow=flow, number_of_flows=len(flows))
-            reactor.callLater(5, self.add_flow, flow)
+            if flow.id in self.retry_add_flow_list:
+                self.log.debug('flow is already in retry list', flow_id=flow.id)
+            else:
+                self.retry_add_flow_list.append(flow.id)
+                reactor.callLater(5, self.retry_add_flow, flow)
             return None
 
         next_flows.sort(key=lambda f: f.priority, reverse=True)
diff --git a/voltha/adapters/openolt/openolt_flow_mgr.py b/voltha/adapters/openolt/openolt_flow_mgr.py
index 3b08edc..c372cf5 100644
--- a/voltha/adapters/openolt/openolt_flow_mgr.py
+++ b/voltha/adapters/openolt/openolt_flow_mgr.py
@@ -86,6 +86,7 @@
         self.resource_mgr = resource_mgr
         self.tech_profile = dict()
         self._populate_tech_profile_per_pon_port()
+        self.retry_add_flow_list = []
 
     def add_flow(self, flow):
         self.log.debug('add flow', flow=flow)
@@ -258,6 +259,12 @@
             self.log.error("invalid-info", uni_port_no=uni_port_no,
                            child_device_id=child_device_id)
 
+    def retry_add_flow(self, flow):
+        self.log.debug("retry-add-flow")
+        if flow.id in self.retry_add_flow_list:
+            self.retry_add_flow_list.remove(flow.id)
+        self.add_flow(flow)
+
     def remove_flow(self, flow):
         self.log.debug('trying to remove flows from logical flow :',
                        logical_flow=flow)
@@ -919,7 +926,11 @@
         if len(next_flows) == 0:
             self.log.warning('no next flow found, it may be a timing issue',
                              flow=flow, number_of_flows=len(flows))
-            reactor.callLater(5, self.add_flow, flow)
+            if flow.id in self.retry_add_flow_list:
+                self.log.debug('flow is already in retry list', flow_id=flow.id)
+            else:
+                self.retry_add_flow_list.append(flow.id)
+                reactor.callLater(5, self.retry_add_flow, flow)
             return None
 
         next_flows.sort(key=lambda f: f.priority, reverse=True)