VOL-4447: Alloc Cfg Complete Indication and Gem Cfg Complete Indication
should wait only when ONU is active.
- In case of GPON tech, Gem Cfg Complete Indication should wait only when
  ONU is in ACTIVE state
- In case of all PON tech Alloc Cfg Complete Indication should wait only
  when ONU is in ACTIVE state
- Enhanced some logs to dump BAL error text in case of failure
- Since the Alloc/Gem Cfg Complete Indications arrive only when ONU is
  in ACTIVE state, the SCALE_AND_PERF compile time flag is removed around
  this code section where wait is required on Cfg Complete Indication
  as in openolt-scale test runs the ONU never goes to ACTIVE state
- Enhanced/Fixed unit tests

Change-Id: I572e41f18e4342ce07e865e0bbea2d42f5edb8db
diff --git a/agent/src/core_api_handler.cc b/agent/src/core_api_handler.cc
index e72fc36..b32781e 100644
--- a/agent/src/core_api_handler.cc
+++ b/agent/src/core_api_handler.cc
@@ -556,7 +556,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get onu_id, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get onu_id, err = %s (%d)\n", flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.onu_id;
@@ -567,7 +567,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get flow_type, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get flow_type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.key.flow_type;
@@ -579,7 +579,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get svc_port_id, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get svc_port_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.svc_port_id;
@@ -591,7 +591,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get priority, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get priority, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.priority;
@@ -603,7 +603,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get cookie, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get cookie, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.cookie;
@@ -615,7 +615,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get ingress intf_type, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get ingress intf_type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.ingress_intf.intf_type;
@@ -627,7 +627,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress intf_type, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress intf_type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.egress_intf.intf_type;
@@ -639,7 +639,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get ingress intf_id, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get ingress intf_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.ingress_intf.intf_id;
@@ -651,7 +651,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress intf_id, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress intf_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.egress_intf.intf_id;
@@ -663,7 +663,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier o_vid, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier o_vid, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.classifier.o_vid;
@@ -675,7 +675,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier o_pbits, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier o_pbits, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.classifier.o_pbits;
@@ -687,7 +687,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier i_vid, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier i_vid, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.classifier.i_vid;
@@ -699,7 +699,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier i_pbits, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier i_pbits, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.classifier.i_pbits;
@@ -711,7 +711,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier ether_type, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier ether_type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.classifier.ether_type;
@@ -723,7 +723,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier ip_proto, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier ip_proto, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.classifier.ip_proto;
@@ -735,7 +735,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier src_port, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier src_port, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.classifier.src_port;
@@ -747,7 +747,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier dst_port, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier dst_port, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.classifier.dst_port;
@@ -759,7 +759,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier pkt_tag_type, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier pkt_tag_type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.classifier.pkt_tag_type;
@@ -771,7 +771,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos type, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.egress_qos.type;
@@ -783,7 +783,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos queue_id, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos queue_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             switch (flow_cfg.data.egress_qos.type) {
@@ -807,7 +807,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos tm_sched_id, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos tm_sched_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.egress_qos.tm_sched.id;
@@ -819,7 +819,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action cmds_bitmask, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action cmds_bitmask, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.action.cmds_bitmask;
@@ -831,7 +831,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action o_vid, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action o_vid, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.action.o_vid;
@@ -843,7 +843,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action o_pbits, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action o_pbits, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.action.o_pbits;
@@ -855,7 +855,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action i_vid, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action i_vid, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.action.i_vid;
@@ -867,7 +867,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action i_pbits, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action i_pbits, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.action.i_pbits;
@@ -879,7 +879,7 @@
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             #endif
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get state, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get state, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.state;
@@ -887,7 +887,7 @@
             BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, group_id);
             err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
             if (err) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get group_id, err = %s\n",bcmos_strerror(err));
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get group_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
                 return err;
             }
             return flow_cfg.data.group_id;
@@ -1130,7 +1130,7 @@
 
     err = bcmolt_cfg_set(dev_id, &interface_obj.hdr);
     if (err != BCM_ERR_OK) {
-        OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable discovery of onu, PON interface %d, err %d\n", intf_id, err);
+        OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable discovery of onu, PON interface %d, err = %s (%d(\n", intf_id, interface_obj.hdr.hdr.err_text, err);
         return bcm_to_grpc_err(err, "Failed to disable discovery of onu");
     }
 
@@ -1213,7 +1213,7 @@
         }
         err = bcmolt_cfg_set(dev_id, &onu_cfg.hdr);
         if (err != BCM_ERR_OK) {
-            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to configure ONU %d on PON %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err));
+            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to configure ONU %d on PON %d, err = %s (%d)\n", onu_id, intf_id, onu_cfg.hdr.hdr.err_text, err);
             return bcm_to_grpc_err(err, "Failed to configure ONU");
         }
     }
@@ -1232,7 +1232,7 @@
         BCMOLT_FIELD_SET(&gem_cfg.data, itupon_gem_cfg_data, encryption_mode, encryption_mode);
         err = bcmolt_cfg_set(dev_id, &gem_cfg.hdr);
         if(err != BCM_ERR_OK) {
-                OPENOLT_LOG(ERROR, openolt_log_id, "failed to configure omci gem_port encryption mode = %d\n", onu_id);
+                OPENOLT_LOG(ERROR, openolt_log_id, "failed to configure omci gem_port encryption mode = %d, err = %s (%d)\n", onu_id, gem_cfg.hdr.hdr.err_text, err);
                 return bcm_to_grpc_err(err, "Access_Control set ITU PON OMCI Gem port failed");
         }
     }
@@ -1268,16 +1268,7 @@
     onu_key.pon_ni = intf_id;
     BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
     BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state);
-    #ifdef TEST_MODE
-    // It is impossible to mock the setting of onu_cfg.data.onu_state because
-    // the actual bcmolt_cfg_get passes the address of onu_cfg.hdr and we cannot
-    // set the onu_cfg.data.onu_state. So a new stub function is created and address
-    // of onu_cfg is passed. This is one-of case where we need to add test specific
-    // code in production code.
-    err = bcmolt_cfg_get__onu_state_stub(dev_id, &onu_cfg);
-    #else
     err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr);
-    #endif
     onu_state = onu_cfg.data.onu_state;
     if (err == BCM_ERR_OK) {
         switch (onu_state) {
@@ -1293,6 +1284,9 @@
                 OPENOLT_LOG(INFO, openolt_log_id, "Deactivated ONU, onu_id %d on PON %d\n", onu_id, intf_id);
                 break;
         }
+    } else {
+        OPENOLT_LOG(ERROR, openolt_log_id, "Failed to deactivate ONU %d on PON %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err));
+        return bcm_to_grpc_err(err, "Failed to get onu config");
     }
 
     return Status::OK;
@@ -1302,14 +1296,18 @@
     const char *vendor_id, const char *vendor_specific) {
     bcmos_errno err = BCM_ERR_OK;
     bcmolt_onu_state onu_state;
+    Status st;
 
     OPENOLT_LOG(INFO, openolt_log_id,  "DeleteOnu ONU %d on PON %d : vendor id %s, vendor specific %s\n",
         onu_id, intf_id, vendor_id, vendor_specific_to_str(vendor_specific).c_str());
 
     // Need to deactivate before removing it (BAL rules)
-    DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific);
+    st = DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific);
+    if (st.error_code() != grpc::StatusCode::OK) {
+        return st;
+    }
 
-    err = get_onu_status((bcmolt_interface)intf_id, onu_id, &onu_state);
+    err = get_onu_state((bcmolt_interface)intf_id, onu_id, &onu_state);
     if (err == BCM_ERR_OK) {
         if (onu_state != BCMOLT_ONU_STATE_INACTIVE) {
             OPENOLT_LOG(INFO, openolt_log_id, "waiting for onu deactivate complete response: intf_id=%d, onu_id=%d\n",
@@ -1345,7 +1343,7 @@
     err = bcmolt_cfg_clear(dev_id, &cfg_obj.hdr);
     if (err != BCM_ERR_OK)
     {
-       OPENOLT_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL onu_id %d, Interface ID %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err));
+        OPENOLT_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL onu_id %d, Interface ID %d, err = %s (%d)\n", onu_id, intf_id, cfg_obj.hdr.hdr.err_text, err);
         return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
     }
 
@@ -1626,6 +1624,7 @@
                                 action, priority, cookie, group_id, tech_profile_id, enable_encryption);
             if (st.error_code() != grpc::StatusCode::OK && st.error_code() != grpc::StatusCode::ALREADY_EXISTS) {
                 OPENOLT_LOG(ERROR, openolt_log_id, "failed to install device flow=%u for voltha flow=%lu", flow_id, voltha_flow_id);
+                free_flow_id(flow_id);
                 return st;
             }
 
@@ -1656,6 +1655,8 @@
                             FlowRemove_(flow_id, flow_type);
                         }
                     }
+                    // Note: We should not free the flow_ids here because the symmetric flow is already using that flow id.  
+                    // A call from voltha adapter should invoke a flow remove and then the flow ids would be freed in the process in this particular case
                     return st;
                 }
             }
@@ -2264,7 +2265,7 @@
 
     bcmos_errno err = bcmolt_cfg_clear(dev_id, &cfg.hdr);
     if (err) {
-        OPENOLT_LOG(ERROR, openolt_log_id, "Error while removing %s flow, flow_id=%d, err = %s\n", flow_type.c_str(), flow_id, bcmos_strerror(err));
+        OPENOLT_LOG(ERROR, openolt_log_id, "Error while removing %s flow, flow_id=%d, err = %s (%d)\n", flow_type.c_str(), flow_id, cfg.hdr.hdr.err_text, err);
         return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
     }
 
@@ -2307,7 +2308,7 @@
     err = bcmolt_cfg_get(dev_id, &tm_sched_cfg.hdr);
     #endif
     if (err) {
-        OPENOLT_LOG(ERROR, openolt_log_id, "cfg: Failed to query TM scheduler, err = %s\n",bcmos_strerror(err));
+        OPENOLT_LOG(ERROR, openolt_log_id, "cfg: Failed to query TM scheduler, err = %s (%d)\n", tm_sched_cfg.hdr.hdr.err_text, err);
         return err;
     }
     else if (tm_sched_cfg.data.state == BCMOLT_CONFIG_STATE_CONFIGURED) {
@@ -2404,8 +2405,8 @@
         err = bcmolt_cfg_set(dev_id, &tm_sched_cfg.hdr);
         if (err) {
             OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create downstream subscriber scheduler, id %d, \
-intf_id %d, onu_id %d, uni_id %d, port_no %u, err = %s\n", tm_sched_key.id, intf_id, onu_id, uni_id, \
-port_no, bcmos_strerror(err));
+intf_id %d, onu_id %d, uni_id %d, port_no %u, err = %s (%d)\n", tm_sched_key.id, intf_id, onu_id, uni_id, \
+port_no, tm_sched_cfg.hdr.hdr.err_text, err);
             return err;
         }
         OPENOLT_LOG(INFO, openolt_log_id, "Create downstream subscriber sched, id %d, intf_id %d, onu_id %d, \
@@ -2525,18 +2526,29 @@
         err = bcmolt_cfg_set(dev_id, &cfg.hdr);
         if (err) {
             OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create upstream bandwidth allocation, intf_id %d, onu_id %d, uni_id %d,\
-port_no %u, alloc_id %d, err = %s (%s)\n", intf_id, onu_id,uni_id,port_no,alloc_id, bcmos_strerror(err), cfg.hdr.hdr.err_text);
+port_no %u, alloc_id %d, err = %s (%d)\n", intf_id, onu_id,uni_id,port_no,alloc_id, cfg.hdr.hdr.err_text, err);
             return err;
         }
-#ifndef SCALE_AND_PERF
-        err = wait_for_alloc_action(intf_id, alloc_id, ALLOC_OBJECT_CREATE);
-        if (err) {
-            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create upstream bandwidth allocation, intf_id %d, onu_id %d, uni_id %d,\
+        bcmolt_onu_state onu_state;
+        err = get_onu_state((bcmolt_interface)intf_id, (bcmolt_onu_id)onu_id, &onu_state);
+        if (err == BCM_ERR_OK) {
+            if (onu_state == BCMOLT_ONU_STATE_ACTIVE) {
+                err = wait_for_alloc_action(intf_id, alloc_id, ALLOC_OBJECT_CREATE);
+                if (err) {
+                    OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create upstream bandwidth allocation, intf_id %d, onu_id %d, uni_id %d,\
 port_no %u, alloc_id %d, err = %s\n", intf_id, onu_id,uni_id,port_no,alloc_id, bcmos_strerror(err));
+                    return err;
+                }
+            }
+            else {
+                OPENOLT_LOG(INFO, openolt_log_id, "onu not active, not waiting for alloc cfg complete, onu_state = %d, intf = %d, onu=%d\n",
+                    onu_state, intf_id, onu_id);
+            }
+        } else {
+            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch onu status, intf_id = %d, onu_id = %d, err = %s\n",
+                intf_id, onu_id, bcmos_strerror(err));
             return err;
         }
-#endif
-
         OPENOLT_LOG(INFO, openolt_log_id, "create upstream bandwidth allocation success, intf_id %d, onu_id %d, uni_id %d,\
 port_no %u, alloc_id %d\n", intf_id, onu_id,uni_id,port_no,alloc_id);
 
@@ -2589,8 +2601,7 @@
 bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, int alloc_id, std::string direction, int tech_profile_id) {
 
     bcmos_errno err;
-    bcmolt_interface_state state;
-    bcmolt_status los_status;
+    bcmolt_onu_state onu_state;
     uint16_t sched_id;
 
     if (direction == upstream) {
@@ -2603,36 +2614,31 @@
         BCMOLT_CFG_INIT(&cfg, itupon_alloc, key);
         err = bcmolt_cfg_clear(dev_id, &cfg.hdr);
         if (err) {
-            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler, direction = %s, intf_id %d, alloc_id %d, err = %s\n",
-                direction.c_str(), intf_id, alloc_id, bcmos_strerror(err));
+            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler, direction = %s, intf_id %d, alloc_id %d, err = %s (%d)\n",
+                direction.c_str(), intf_id, alloc_id, cfg.hdr.hdr.err_text, err);
             return err;
         }
 
-        err = get_pon_interface_status((bcmolt_interface)intf_id, &state, &los_status);
+        err = get_onu_state((bcmolt_interface)intf_id, (bcmolt_onu_id)onu_id, &onu_state);
         if (err == BCM_ERR_OK) {
-            if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING && los_status == BCMOLT_STATUS_OFF) {
-#ifndef SCALE_AND_PERF
-                OPENOLT_LOG(INFO, openolt_log_id, "PON interface: %d is enabled and LoS status is OFF, waiting for alloc cfg clear response\n",
-                    intf_id);
+            if (onu_state == BCMOLT_ONU_STATE_ACTIVE) {
+                // Wait for gem cfg complete indication only if ONU state is ACTIVE
+                OPENOLT_LOG(INFO, openolt_log_id, "onu state is active waiting for alloc cfg complete indication intf = %d onu = %d\n",
+                    intf_id, onu_id);
                 err = wait_for_alloc_action(intf_id, alloc_id, ALLOC_OBJECT_DELETE);
                 if (err) {
                     OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler, direction = %s, intf_id %d, alloc_id %d, err = %s\n",
                         direction.c_str(), intf_id, alloc_id, bcmos_strerror(err));
                     return err;
                 }
-#endif
             }
-            else if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING && los_status == BCMOLT_STATUS_ON) {
-                OPENOLT_LOG(INFO, openolt_log_id, "PON interface: %d is enabled but LoS status is ON, not waiting for alloc cfg clear response\n",
-                    intf_id);
-            }
-            else if (state == BCMOLT_INTERFACE_STATE_INACTIVE) {
-                OPENOLT_LOG(INFO, openolt_log_id, "PON interface: %d is disabled, not waiting for alloc cfg clear response\n",
-                    intf_id);
+            else {
+                OPENOLT_LOG(INFO, openolt_log_id, "onu not active, not waiting for alloc cfg complete, onu_state = %d, intf = %d, onu=%d\n",
+                    onu_state, intf_id, onu_id);
             }
         } else {
-            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch PON interface status, intf_id = %d, err = %s\n",
-                intf_id, bcmos_strerror(err));
+            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch onu status, intf_id = %d, onu_id = %d, err = %s\n",
+                intf_id, onu_id, bcmos_strerror(err));
             return err;
         }
     } else if (direction == downstream) {
@@ -2651,7 +2657,7 @@
         err = bcmolt_cfg_clear(dev_id, &(cfg.hdr));
         if (err) {
             OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler, direction = %s, sched_id %d, \
-intf_id %d, onu_id %d, tech_profile_id %d, err = %s\n", direction.c_str(), key.id, intf_id, onu_id, tech_profile_id, bcmos_strerror(err));
+intf_id %d, onu_id %d, tech_profile_id %d, err = %s (%d)\n", direction.c_str(), key.id, intf_id, onu_id, tech_profile_id, cfg.hdr.hdr.err_text, err);
             return err;
         }
     }
@@ -2818,8 +2824,8 @@
     err = bcmolt_cfg_set(dev_id, &cfg.hdr);
     if (err) {
         OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create subscriber tm queue, direction = %s, queue_id %d, \
-sched_id %d, tm_q_set_id %d, intf_id %d, onu_id %d, uni_id %d, tech_profile_id %d, err = %s\n", \
-            direction.c_str(), key.id, key.sched_id, key.tm_q_set_id, access_intf_id, onu_id, uni_id, tech_profile_id, bcmos_strerror(err));
+sched_id %d, tm_q_set_id %d, intf_id %d, onu_id %d, uni_id %d, tech_profile_id %d, err = %s (%d)\n", \
+            direction.c_str(), key.id, key.sched_id, key.tm_q_set_id, access_intf_id, onu_id, uni_id, tech_profile_id, cfg.hdr.hdr.err_text, err);
         return err;
     }
 
@@ -2918,7 +2924,8 @@
         Status st = remove_gem_port(access_intf_id, onu_id, uni_id, gemport_id, board_technology);
         if (st.error_code() != grpc::StatusCode::OK) {
             OPENOLT_LOG(ERROR, openolt_log_id, "failed to remove gemport=%d, access_intf=%d, onu_id=%d\n", gemport_id, access_intf_id, onu_id);
-            return BCM_ERR_INTERNAL;
+            // We should further cleanup proceed, do not return error yet..
+            // return BCM_ERR_INTERNAL;
         }
         if (direction == upstream) {
             // Remove the pon-gem to onu-uni mapping
@@ -2959,8 +2966,8 @@
     err = bcmolt_cfg_clear(dev_id, &(cfg.hdr));
     if (err) {
         OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove queue, direction = %s, queue_id %d, sched_id %d, \
-tm_q_set_id %d, intf_id %d, onu_id %d, uni_id %d, err = %s\n",
-                direction.c_str(), key.id, key.sched_id, key.tm_q_set_id, access_intf_id, onu_id, uni_id, bcmos_strerror(err));
+tm_q_set_id %d, intf_id %d, onu_id %d, uni_id %d, err = %s (%d)\n",
+                direction.c_str(), key.id, key.sched_id, key.tm_q_set_id, access_intf_id, onu_id, uni_id, cfg.hdr.hdr.err_text, err);
         return err;
     }
 
@@ -2980,6 +2987,7 @@
     std::string direction;
     bcmos_errno err;
     bcmolt_egress_qos_type qos_type = get_qos_type(intf_id, onu_id, uni_id, traffic_queues->traffic_queues_size());
+    Status ret_code = Status::OK;
 
     for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) {
         ::tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i);
@@ -2991,7 +2999,8 @@
         err = RemoveQueue(direction, intf_id, onu_id, uni_id, qos_type, traffic_queue.priority(), traffic_queue.gemport_id(), tech_profile_id);
         if (err) {
             OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove queue, err = %s\n",bcmos_strerror(err));
-            return bcm_to_grpc_err(err, "Failed to remove queue");
+            ret_code = bcm_to_grpc_err(err, "Failed to remove one or more queues");
+            // Do not return here. We should continue to remove the remaining queues and its associated gem ports
         }
     }
 
@@ -3009,7 +3018,7 @@
         }
     }
     clear_qos_type(intf_id, onu_id, uni_id);
-    return Status::OK;
+    return ret_code;
 }
 
 Status PerformGroupOperation_(const ::openolt::Group *group_cfg) {
diff --git a/agent/src/core_utils.cc b/agent/src/core_utils.cc
index 2aad9fd..9081498 100644
--- a/agent/src/core_utils.cc
+++ b/agent/src/core_utils.cc
@@ -848,7 +848,7 @@
     }
 }
 
-bcmos_errno get_onu_status(bcmolt_interface pon_ni, int onu_id, bcmolt_onu_state *onu_state) {
+bcmos_errno get_onu_state(bcmolt_interface pon_ni, int onu_id, bcmolt_onu_state *onu_state) {
     bcmos_errno err;
     bcmolt_onu_cfg onu_cfg;
     bcmolt_onu_key onu_key;
@@ -856,18 +856,8 @@
     onu_key.onu_id = onu_id;
 
     BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
-    BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state);
-    BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, itu);
-    #ifdef TEST_MODE
-    // It is impossible to mock the setting of onu_cfg.data.onu_state because
-    // the actual bcmolt_cfg_get passes the address of onu_cfg.hdr and we cannot
-    // set the onu_cfg.data.onu_state. So a new stub function is created and address
-    // of onu_cfg is passed. This is one-of case where we need to add test specific
-    // code in production code.
-    err = bcmolt_cfg_get__onu_state_stub(dev_id, &onu_cfg);
-    #else
+    BCMOLT_MSG_FIELD_GET(&onu_cfg, onu_state);
     err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr);
-    #endif
     *onu_state = onu_cfg.data.onu_state;
     return err;
 }
@@ -971,6 +961,7 @@
     bcmolt_itupon_gem_cfg cfg; /* declare main API struct */
     bcmolt_itupon_gem_key key = {}; /* declare key */
     bcmolt_gem_port_configuration configuration = {};
+    bcmolt_onu_state onu_state;
 
     key.pon_ni = intf_id;
     key.gem_port_id = gemport_id;
@@ -1007,15 +998,19 @@
         return bcm_to_grpc_err(err, "Access_Control set ITU PON Gem port failed");
     }
 
-#ifndef SCALE_AND_PERF
     if (board_technology == "GPON") {
-        err = wait_for_gem_action(intf_id, gemport_id, GEM_OBJECT_CREATE);
-        if (err) {
-            OPENOLT_LOG(ERROR, openolt_log_id, "failed to install gem_port = %d err = %s\n", gemport_id, bcmos_strerror(err));
-            return bcm_to_grpc_err(err, "Access_Control set ITU PON Gem port failed");
+        // Wait for gem cfg complete indication only if ONU state is ACTIVE
+        err = get_onu_state((bcmolt_interface)intf_id, (bcmolt_onu_id)onu_id, &onu_state);
+        if (err == BCM_ERR_OK) {
+            if (onu_state == BCMOLT_ONU_STATE_ACTIVE) {
+                err = wait_for_gem_action(intf_id, gemport_id, GEM_OBJECT_CREATE);
+                if (err) {
+                    OPENOLT_LOG(ERROR, openolt_log_id, "failed to install gem_port = %d err = %s\n", gemport_id, bcmos_strerror(err));
+                    return bcm_to_grpc_err(err, "Access_Control set ITU PON Gem port failed");
+                }
+            }
         }
     }
-#endif
 
     OPENOLT_LOG(INFO, openolt_log_id, "gem port installed successfully = %d\n", gemport_id);
 
@@ -1028,6 +1023,7 @@
 
 Status remove_gem_port(int32_t intf_id, int32_t onu_id, int32_t uni_id, int32_t gemport_id, std::string board_technology) {
     gemport_status_map_key_tuple gem_status_key(intf_id, onu_id, uni_id, gemport_id);
+    bcmolt_onu_state onu_state;
 
     bcmos_fastlock_lock(&data_lock);
     std::map<gemport_status_map_key_tuple, bool>::const_iterator it = gemport_status_map.find(gem_status_key);
@@ -1044,8 +1040,6 @@
         .gem_port_id = (bcmolt_gem_port_id)gemport_id
     };
     bcmos_errno err;
-    bcmolt_interface_state state;
-    bcmolt_status los_status;
 
     BCMOLT_CFG_INIT(&gem_cfg, itupon_gem, key);
     err = bcmolt_cfg_clear(dev_id, &gem_cfg.hdr);
@@ -1056,31 +1050,28 @@
     }
 
     if (board_technology == "GPON") {
-        err = get_pon_interface_status((bcmolt_interface)intf_id, &state, &los_status);
+        err = get_onu_state((bcmolt_interface)intf_id, (bcmolt_onu_id)onu_id, &onu_state);
         if (err == BCM_ERR_OK) {
-            if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING && los_status == BCMOLT_STATUS_OFF) {
+            if (onu_state == BCMOLT_ONU_STATE_ACTIVE) {
 #ifndef SCALE_AND_PERF
-                OPENOLT_LOG(INFO, openolt_log_id, "PON interface: %d is enabled and LoS status is OFF, waiting for gem cfg clear response\n",
-                    intf_id);
+                OPENOLT_LOG(INFO, openolt_log_id, "onu state is active waiting for gem cfg complete indication intf = %d onu = %d\n",
+                    intf_id, onu_id);
                 err = wait_for_gem_action(intf_id, gemport_id, GEM_OBJECT_DELETE);
                 if (err) {
-                    OPENOLT_LOG(ERROR, openolt_log_id, "failed to remove gem_port = %d err = %s\n", gemport_id, bcmos_strerror(err));
-                    return bcm_to_grpc_err(err, "Access_Control clear ITU PON Gem port failed");
+                    OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove gem, intf_id %d, gemport_id %d, err = %s\n",
+                        intf_id, gemport_id, bcmos_strerror(err));
+                    return bcm_to_grpc_err(err, "failed to remove gem");
                 }
 #endif
             }
-            else if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING && los_status == BCMOLT_STATUS_ON) {
-                OPENOLT_LOG(INFO, openolt_log_id, "PON interface: %d is enabled but LoS status is ON, not waiting for gem cfg clear response\n",
-                    intf_id);
-            }
-            else if (state == BCMOLT_INTERFACE_STATE_INACTIVE) {
-                OPENOLT_LOG(INFO, openolt_log_id, "PON interface: %d is disabled, not waiting for gem cfg clear response\n",
-                    intf_id);
+            else {
+                OPENOLT_LOG(INFO, openolt_log_id, "onu not active, not waiting for gem cfg complete, onu_state = %d, intf = %d, gemport_id = %d, onu=%d\n",
+                    onu_state, intf_id, gemport_id, onu_id);
             }
         } else {
-            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch PON interface status, intf_id = %d, err = %s\n",
-                intf_id, bcmos_strerror(err));
-            return bcm_to_grpc_err(err, "Access_Control clear ITU PON Gem port failed");
+            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch onu status, intf_id = %d, onu_id = %d, err = %s\n",
+                intf_id, onu_id, bcmos_strerror(err));
+            return bcm_to_grpc_err(err, "failed to get onu state");
         }
     }
 
@@ -1108,7 +1099,7 @@
     BCMOLT_MSG_FIELD_GET(&cfg, encryption_mode);
     err = bcmolt_cfg_get(dev_id, &cfg.hdr);
     if (err != BCM_ERR_OK) {
-        OPENOLT_LOG(ERROR, openolt_log_id, "GEM port get encryption_mode failed\n");
+        OPENOLT_LOG(ERROR, openolt_log_id, "GEM port get encryption_mode failed err = %s (%d)\n", cfg.hdr.hdr.err_text, err);
         return bcm_to_grpc_err(err, "GEM port get encryption_mode failed");
     }
 
@@ -1252,7 +1243,7 @@
 
     err = bcmolt_cfg_set(dev_id, &cfg.hdr);
     if (err != BCM_ERR_OK) {
-        OPENOLT_LOG(ERROR, openolt_log_id, "Access_Control set configuration failed, Error %d\n", err);
+        OPENOLT_LOG(ERROR, openolt_log_id, "Access_Control set configuration failed, err = %s (%d)\n", cfg.hdr.hdr.err_text, err);
         // Free the acl_id
         free_acl_id(acl_id);
         return bcm_to_grpc_err(err, "Access_Control set configuration failed");
@@ -1282,7 +1273,7 @@
     BCMOLT_FIELD_SET_PRESENT(&cfg.data, access_control_cfg_data, state);
     err = bcmolt_cfg_get(dev_id, &cfg.hdr);
     if (err != BCM_ERR_OK) {
-        OPENOLT_LOG(ERROR, openolt_log_id, "Access_Control get state failed\n");
+        OPENOLT_LOG(ERROR, openolt_log_id, "Access_Control get state failed, err = %s (%d)\n", cfg.hdr.hdr.err_text, err);
         return bcm_to_grpc_err(err, "Access_Control get state failed");
     }
 
@@ -1294,8 +1285,8 @@
         err = bcmolt_cfg_clear(dev_id, &cfg.hdr);
         if (err != BCM_ERR_OK) {
             // Should we free acl_id here ? We should ideally never land here..
-            OPENOLT_LOG(ERROR, openolt_log_id, "Error %d while removing Access_Control rule ID %d\n",
-                err, acl_id);
+            OPENOLT_LOG(ERROR, openolt_log_id, "Error %d while removing Access_Control rule ID err = %s (%d)\n",
+                acl_id, cfg.hdr.hdr.err_text, err);
             return Status(grpc::StatusCode::INTERNAL, "Failed to remove Access_Control");
         }
     }
@@ -1593,7 +1584,7 @@
     err = bcmolt_cfg_get(dev_id, &pon_cfg.hdr);
     #endif
         if (err != BCM_ERR_OK) {
-            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve ONU maximum logical distance for PON %d, err = %s (%d)\n", intf_id, bcmos_strerror(err), err);
+            OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve ONU maximum logical distance for PON %d, err = %s (%d)\n", intf_id, pon_cfg.hdr.hdr.err_text, err);
             return err;
         }
         *mld = pon_distance.max_log_distance;
diff --git a/agent/src/core_utils.h b/agent/src/core_utils.h
index e9ad817..7ff318e 100644
--- a/agent/src/core_utils.h
+++ b/agent/src/core_utils.h
@@ -88,7 +88,7 @@
 int get_status_bcm_cli_quit(void);
 bcmos_errno bcmolt_apiend_cli_init();
 bcmos_errno get_pon_interface_status(bcmolt_interface pon_ni, bcmolt_interface_state *state, bcmolt_status *los_status);
-bcmos_errno get_onu_status(bcmolt_interface pon_ni, int onu_id, bcmolt_onu_state *onu_state);
+bcmos_errno get_onu_state(bcmolt_interface pon_ni, int onu_id, bcmolt_onu_state *onu_state);
 bcmos_errno bcmolt_cfg_get_mult_retry(bcmolt_oltid olt, bcmolt_cfg *cfg);
 unsigned NumNniIf_();
 unsigned NumPonIf_();
diff --git a/agent/src/indications.cc b/agent/src/indications.cc
index 5261222..ad2d5ff 100644
--- a/agent/src/indications.cc
+++ b/agent/src/indications.cc
@@ -1451,7 +1451,6 @@
     if(rc != BCM_ERR_OK)
         return Status(grpc::StatusCode::INTERNAL, "Packet indication subscribe failed");
 
-#ifndef SCALE_AND_PERF
     rx_cfg.obj_type = BCMOLT_OBJ_ID_ITUPON_ALLOC;
     rx_cfg.rx_cb = ItuPonAllocConfigCompletedInd;
     rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
@@ -1467,7 +1466,6 @@
     rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
     if(rc != BCM_ERR_OK)
         return Status(grpc::StatusCode::INTERNAL, "ITU PON Gem Configuration Complete Indication subscribe failed");
-#endif
 
     rx_cfg.obj_type = BCMOLT_OBJ_ID_GROUP;
     rx_cfg.rx_cb = GroupIndication;
diff --git a/agent/test/src/test_core.cc b/agent/test/src/test_core.cc
index 58e7073..393c315 100644
--- a/agent/test/src/test_core.cc
+++ b/agent/test/src/test_core.cc
@@ -1045,15 +1045,24 @@
 
 // Test 1 - DeactivateOnu success case
 TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) {
-    bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
     bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
 
-    bcmolt_onu_cfg onu_cfg;
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
     bcmolt_onu_key onu_key;
-    BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
-    onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
-                     .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
+
 
     ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
 
@@ -1063,15 +1072,23 @@
 
 // Test 2 - DeactivateOnu failure case
 TEST_F(TestDeactivateOnu, DeactivateOnuFailure) {
-    bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
     bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
 
-    bcmolt_onu_cfg onu_cfg;
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
     bcmolt_onu_key onu_key;
-    BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
-    onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
-                     .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
 
     ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
 
@@ -1122,17 +1139,24 @@
 
 // Test 1 - DeleteOnu success case
 TEST_F(TestDeleteOnu, DeleteOnuSuccess) {
-    bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
     bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
     bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
 
-    bcmolt_onu_cfg onu_cfg;
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
     bcmolt_onu_key onu_key;
-    BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
-    onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
-                     .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
 
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
     ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
     ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
 
@@ -1146,16 +1170,25 @@
 
 // Test 2 - DeleteOnu failure case - BAL Clear ONU fails
 TEST_F(TestDeleteOnu, DeleteOnuFailureClearOnuFail) {
-    bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
     bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
     bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL;
 
-    bcmolt_onu_cfg onu_cfg;
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
     bcmolt_onu_key onu_key;
-    BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
-    onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
-                     .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
+
 
     ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
     ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
@@ -1171,15 +1204,23 @@
 
 // Test 3 - DeleteOnu failure case - onu deactivation fails
 TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationFail) {
-    bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
     bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
 
-    bcmolt_onu_cfg onu_cfg;
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
     bcmolt_onu_key onu_key;
-    BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
-    onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
-                     .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
 
     ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
 
@@ -1194,15 +1235,23 @@
 
 // Test 4 - DeleteOnu failure case - onu deactivation timesout
 TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationTimeout) {
-    bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
     bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
 
-    bcmolt_onu_cfg onu_cfg;
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
     bcmolt_onu_key onu_key;
-    BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
-    onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
-                     .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
 
     ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
 
@@ -1214,16 +1263,24 @@
 
 // Test 5 - DeleteOnu success case - Onu is Inactive so won't wait for onu deactivation response
 TEST_F(TestDeleteOnu, DeleteOnuSuccessDontwaitforDeactivationResp) {
-    bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
     bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
     bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
 
-    bcmolt_onu_cfg onu_cfg;
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
     bcmolt_onu_key onu_key;
-    BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
-    onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
-                     .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
 
     ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
     ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
@@ -1238,12 +1295,22 @@
 TEST_F(TestDeleteOnu, DeleteOnuFailureFetchOnuStatusFailed) {
     bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
 
-    bcmolt_onu_cfg onu_cfg;
+    bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
+    bcmolt_onu_cfg onu_cfg_out;
     bcmolt_onu_key onu_key;
-    BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
-    onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
-                     .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
+
 
     future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
 
@@ -1999,6 +2066,20 @@
     bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
     ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
 
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
+    bcmolt_onu_key onu_key;
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
+
     future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
     future<int> push_alloc_cfg_complt = \
                 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
@@ -2021,6 +2102,70 @@
     bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
     ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
 
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
+    bcmolt_onu_key onu_key;
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
+
+    Status status = CreateTrafficSchedulers_(traffic_scheds);
+    ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 2A - CreateTrafficSchedulers-Upstream success case(ONU not in ACTIVE state)
+TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccessOnuNotInActive) {
+    scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+    scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+    traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+    traffic_sched->set_allocated_scheduler(scheduler);
+    traffic_shaping_info->set_cir(64000);
+    traffic_shaping_info->set_pir(128000);
+    traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+    bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+    ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
+    bcmolt_onu_key onu_key;
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
+
+    Status status = CreateTrafficSchedulers_(traffic_scheds);
+    ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2B - CreateTrafficSchedulers-Upstream failure case. cfg-get failure
+TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamCfgGetFailure) {
+    scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+    scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+    traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+    traffic_sched->set_allocated_scheduler(scheduler);
+    traffic_shaping_info->set_cir(64000);
+    traffic_shaping_info->set_pir(128000);
+    traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+    bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+    bcmos_errno olt_cfg_get_res = BCM_ERR_INTERNAL;
+    ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+    ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
+
     Status status = CreateTrafficSchedulers_(traffic_scheds);
     ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
 }
@@ -2038,6 +2183,20 @@
     bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
     ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
 
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
+    bcmolt_onu_key onu_key;
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
+
     future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
     future<int> push_alloc_cfg_complt = \
                 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
@@ -2061,6 +2220,20 @@
     bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
     ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
 
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
+    bcmolt_onu_key onu_key;
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
+
     future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
     future<int> push_alloc_cfg_complt = \
                 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
@@ -2410,14 +2583,22 @@
     bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
     ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
 
-    bcmolt_pon_interface_key pon_key;
-    bcmolt_pon_interface_cfg pon_cfg;
-    pon_key.pon_ni = pon_id;
-    BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
-    pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
-    bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
-                     .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
+    bcmolt_onu_key onu_key;
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
+
 
     future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
     future<int> push_alloc_cfg_complt = \
@@ -2434,15 +2615,21 @@
     bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
     ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
 
-    bcmolt_pon_interface_key pon_key;
-    bcmolt_pon_interface_cfg pon_cfg;
-    pon_key.pon_ni = pon_id;
-    BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
-    pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
-    bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
-                     .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
+    bcmolt_onu_key onu_key;
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
 
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
     future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
     future<int> push_alloc_cfg_complt = \
     async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
@@ -2452,20 +2639,28 @@
     ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
 }
 
-// Test 3 - RemoveTrafficSchedulers-Upstream success case(PON disable case - Don't wait for alloc object delete response)
+// Test 3 - RemoveTrafficSchedulers-Upstream success case(ONU case - Don't wait for alloc object delete response)
 TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) {
     traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
     bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
     ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
 
-    bcmolt_pon_interface_key pon_key;
-    bcmolt_pon_interface_cfg pon_cfg;
-    pon_key.pon_ni = pon_id;
-    BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
-    pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
-    bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
-                     .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+    bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+    bcmolt_onu_cfg onu_cfg_out;
+    bcmolt_onu_key onu_key;
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
+
 
     future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
 
@@ -2479,14 +2674,21 @@
     bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
     ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
 
-    bcmolt_pon_interface_key pon_key;
-    bcmolt_pon_interface_cfg pon_cfg;
-    pon_key.pon_ni = pon_id;
-    BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
-    pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
-    bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
-    EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
-                     .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+    bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
+    bcmolt_onu_cfg onu_cfg_out;
+    bcmolt_onu_key onu_key;
+    onu_key.pon_ni = 0;
+    onu_key.onu_id = 1;
+
+    BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
+
+    EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+                                                                   bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
+                                                                   o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
+                                                                   memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
+                                                                   return onu_cfg_get_res;
+                                                               }
+    ));
 
     future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);