VOL-1622: Free flow_id from resource manager pool if the flow failed to add on the device

Change-Id: I7ec7b58ae0104d16848601f7e9a94a9be83b176e
diff --git a/voltha/adapters/openolt/openolt_flow_mgr.py b/voltha/adapters/openolt/openolt_flow_mgr.py
index dcd1629..0b80e54 100644
--- a/voltha/adapters/openolt/openolt_flow_mgr.py
+++ b/voltha/adapters/openolt/openolt_flow_mgr.py
@@ -1325,6 +1325,14 @@
                 self.log.error('failed to add flow',
                                logical_flow=logical_flow, flow=flow,
                                grpc_error=grpc_e)
+                # If the flow addition failed on the device, immediately
+                # free up the flow_id resource from the pool
+                intf_id = flow.access_intf_id if flow.access_intf_id > 0 else flow.network_intf_id
+                onu_id = flow.onu_id
+                uni_id = flow.uni_id
+                flow_id = flow.flow_id
+                self.resource_mgr.free_flow_id(intf_id, onu_id, uni_id, flow_id)
+
             return False
         else:
             self.register_flow(logical_flow, flow)