Do not reset ONU ID pool on resource manager during OLT post_down handling

Change-Id: I33e618399b1a335f7c83e89668bdd96d4208964e
diff --git a/voltha/adapters/openolt/openolt_device.py b/voltha/adapters/openolt/openolt_device.py
index 53144a5..53cd7d0 100644
--- a/voltha/adapters/openolt/openolt_device.py
+++ b/voltha/adapters/openolt/openolt_device.py
@@ -204,7 +204,16 @@
                     try:
                         pon_intf_id_onu_id = (pon_intf_id, onu_id, uni_id)
                         # Free any PON resources that were reserved for the ONU
-                        self.resource_mgr.free_pon_resources_for_onu(pon_intf_id_onu_id)
+                        # Note: Since the ONU device is not deleted in the voltha core during
+                        # OLT post_down handling, we should not reset the ONU ID pool on the
+                        # resource manager.
+                        # The voltha core is aware of the ONU ID, and we need to ensure that ONU
+                        # IDs are not re-used for new ONUs after OLT comes back. If we reset the
+                        # ONU ID pool during OLT post_down there is a possibility that newer ONUs
+                        # may get the conflicting ONU IDs already assigned for pre-existing ONUs.
+                        # Passing the 'reset_onu_id_pool' as False, ensures that the ONU ID pool
+                        # is not reset during OLT down scenario.
+                        self.resource_mgr.free_pon_resources_for_onu(pon_intf_id_onu_id, False)
                         # Free tech_profile id for ONU
                         self.resource_mgr.remove_tech_profile_id_for_onu(pon_intf_id, onu_id, uni_id)
                         # Free meter_ids for the ONU
diff --git a/voltha/adapters/openolt/openolt_resource_manager.py b/voltha/adapters/openolt/openolt_resource_manager.py
index 8fd4eb9..5ba335e 100644
--- a/voltha/adapters/openolt/openolt_resource_manager.py
+++ b/voltha/adapters/openolt/openolt_resource_manager.py
@@ -315,7 +315,7 @@
         self.resource_mgrs[intf_id].remove_flow_id_info(intf_onu_id,
                                                         flow_id)
 
-    def free_pon_resources_for_onu(self, pon_intf_id_onu_id):
+    def free_pon_resources_for_onu(self, pon_intf_id_onu_id, reset_onu_id_pool=True):
 
         pon_intf_id = pon_intf_id_onu_id[0]
         onu_id = pon_intf_id_onu_id[1]
@@ -341,9 +341,10 @@
             for flow_id in flow_ids:
                 self.free_flow_id(pon_intf_id, onu_id, uni_id, flow_id)
 
-        self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id,
-                                                         PONResourceManager.ONU_ID,
-                                                         onu_id)
+        if reset_onu_id_pool:
+            self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id,
+                                                             PONResourceManager.ONU_ID,
+                                                             onu_id)
 
         # Clear resource map associated with (pon_intf_id, gemport_id) tuple.
         self.resource_mgrs[pon_intf_id].remove_resource_map(pon_intf_id_onu_id)