[VOL-1686][BAL3.0 Brigade]NNI activation failure

Change-Id: I97ef794eb898f5856b95e7321ed46f487764bfc7
diff --git a/agent/common/core.h b/agent/common/core.h
index f19e3aa..47666ac 100644
--- a/agent/common/core.h
+++ b/agent/common/core.h
@@ -63,6 +63,7 @@
 uint32_t GetPortNum_(uint32_t flow_id);
 int get_status_bcm_cli_quit(void);
 uint16_t get_dev_id(void); 
+Status pushOltOperInd(uint32_t intf_id, const char *type, const char *state);
 
 void stats_collection();
 #endif
diff --git a/agent/common/main.cc b/agent/common/main.cc
index 0454337..47fd117 100644
--- a/agent/common/main.cc
+++ b/agent/common/main.cc
@@ -50,16 +50,22 @@
     for (int i = 0; i < NumPonIf_(); i++) {
         status = EnablePonIf_(i);
         if (!status.ok()) {
-            // FIXME - raise alarm to report error in enabling PON
+            // raise alarm to report error in enabling PON
+            pushOltOperInd(i, "pon", "down");
         }
+        else
+            pushOltOperInd(i, "pon", "up");
     }
     sleep(2);
     // Enable all NNI interfaces.
     for (int i = 0; i < NumNniIf_(); i++) {
         status = EnableUplinkIf_(i);
         if (!status.ok()) {
-            // FIXME - raise alarm to report error in enabling PON
+            // raise alarm to report error in enabling PON
+            pushOltOperInd(i, "nni", "down");
         }
+        else
+            pushOltOperInd(i, "nni", "up");
     }
 
     RunServer();
diff --git a/agent/src/core.cc b/agent/src/core.cc
index fde14a4..999601e 100644
--- a/agent/src/core.cc
+++ b/agent/src/core.cc
@@ -312,7 +312,7 @@
     return queue_map.count(key) > 0 ? true: false;
 }
 
-char* openolt_read_sysinfo(char* field_name, char* field_val)
+char* openolt_read_sysinfo(const char* field_name, char* field_val)
 {
    FILE *fp;
    /* Prepare the command*/
@@ -455,6 +455,19 @@
     return Status::OK;
 }
 
+Status pushOltOperInd(uint32_t intf_id, const char *type, const char *state)
+{
+	 openolt::Indication ind;
+	 openolt::IntfOperIndication* intf_oper_ind = new openolt::IntfOperIndication;
+
+	 intf_oper_ind->set_type(type);
+	 intf_oper_ind->set_intf_id(intf_id);
+	 intf_oper_ind->set_oper_state(state);
+	 ind.set_allocated_intf_oper_ind(intf_oper_ind);
+	 oltIndQ.push(ind);
+    return Status::OK;
+}
+
 #define CLI_HOST_PROMPT_FORMAT "BCM.%u> "
 
 /* Build CLI prompt */
@@ -651,12 +664,8 @@
     Status status = DisableUplinkIf_(nni_intf_id);
     if (status.ok()) {
         state.deactivate();
-        openolt::Indication ind;
-        openolt::OltIndication* olt_ind = new openolt::OltIndication;
-        olt_ind->set_oper_state("down");
-        ind.set_allocated_olt_ind(olt_ind);
         BCM_LOG(INFO, openolt_log_id, "Disable OLT, add an extra indication\n");
-        oltIndQ.push(ind);
+        pushOltOperInd(nni_intf_id, "nni", "up");
     }
     return status;
 
@@ -666,12 +675,8 @@
     Status status = EnableUplinkIf_(0);
     if (status.ok()) {
         state.activate();
-        openolt::Indication ind;
-        openolt::OltIndication* olt_ind = new openolt::OltIndication;
-        olt_ind->set_oper_state("up");
-        ind.set_allocated_olt_ind(olt_ind);
         BCM_LOG(INFO, openolt_log_id, "Reenable OLT, add an extra indication\n");
-        oltIndQ.push(ind);
+        pushOltOperInd(0, "nni", "up");
     }
     return status;
 }
diff --git a/agent/src/indications.cc b/agent/src/indications.cc
index ad71cee..eb7570f 100644
--- a/agent/src/indications.cc
+++ b/agent/src/indications.cc
@@ -59,6 +59,9 @@
        ((state == BCMOLT_RESULT_SUCCESS) ? BCMOS_TRUE : BCMOS_FALSE)
 #define ONU_RANGING_STATE_IF_DOWN(state) \
        ((state != BCMOLT_RESULT_SUCCESS) ? BCMOS_TRUE : BCMOS_FALSE)
+#define SET_OPER_STATE(indication,state) \
+       (INTERFACE_STATE_IF_UP(state)) ? indication->set_oper_state("up") : \
+       indication->set_oper_state("down")
 
 std::string bcmbal_to_grpc_intf_type(bcmolt_interface_type intf_type)
 {
@@ -159,10 +162,7 @@
                         &((bcmolt_pon_interface_state_change_completed*)msg)->data;
 
                     intf_ind->set_intf_id(key->pon_ni);
-				        if (INTERFACE_STATE_IF_UP(data->new_state))
-                        intf_ind->set_oper_state("up");
-                    if (INTERFACE_STATE_IF_DOWN(data->new_state))
-                        intf_ind->set_oper_state("down");
+                    SET_OPER_STATE(intf_ind, data->new_state);
                     ind.set_allocated_intf_ind(intf_ind);
                     break;
                 }
@@ -180,10 +180,7 @@
                         &((bcmolt_nni_interface_state_change *)msg)->data;
 
                     intf_ind->set_intf_id(key->id);
-				        if (INTERFACE_STATE_IF_UP(data->new_state))
-                        intf_ind->set_oper_state("up");
-                    if (INTERFACE_STATE_IF_DOWN(data->new_state))
-                        intf_ind->set_oper_state("down");
+                    SET_OPER_STATE(intf_ind, data->new_state);
                     ind.set_allocated_intf_ind(intf_ind);
                     break;
                 }
@@ -207,11 +204,7 @@
                     bcmolt_pon_interface_state_change_completed_data *data = &((bcmolt_pon_interface_state_change_completed*)msg)->data;
                     intf_oper_ind->set_intf_id(key->pon_ni);
                     intf_oper_ind->set_type(bcmbal_to_grpc_intf_type(BCMOLT_INTERFACE_TYPE_PON));
-			           if (INTERFACE_STATE_IF_UP(data->new_state))
-                        intf_oper_ind->set_oper_state("up");
-                    if (INTERFACE_STATE_IF_DOWN(data->new_state))
-                        intf_oper_ind->set_oper_state("down");
-
+                    SET_OPER_STATE(intf_oper_ind, data->new_state);
                     BCM_LOG(INFO, openolt_log_id, "intf oper state indication, intf_type %s, intf_id %d, oper_state %s\n",
                         intf_oper_ind->type().c_str(), key->pon_ni, intf_oper_ind->oper_state().c_str());
                     ind.set_allocated_intf_oper_ind(intf_oper_ind);
@@ -228,12 +221,7 @@
                     bcmolt_interface_type intf_type = BCMOLT_INTERFACE_TYPE_NNI;
                     intf_oper_ind->set_intf_id(key->id);
                     intf_oper_ind->set_type(bcmbal_to_grpc_intf_type(BCMOLT_INTERFACE_TYPE_NNI));
-
-                    if (INTERFACE_STATE_IF_UP(data->new_state))
-                        intf_oper_ind->set_oper_state("up");
-                    if (INTERFACE_STATE_IF_DOWN(data->new_state))
-                        intf_oper_ind->set_oper_state("down");
-                    
+                    SET_OPER_STATE(intf_oper_ind, data->new_state);           
                     BCM_LOG(INFO, openolt_log_id, "intf oper state indication, intf_type %s, intf_id %d, oper_state %s\n",
                         intf_oper_ind->type().c_str(), key->id, intf_oper_ind->oper_state().c_str());
                     ind.set_allocated_intf_oper_ind(intf_oper_ind);
@@ -361,17 +349,17 @@
                     bcmolt_onu_key *key = &((bcmolt_onu_ranging_completed*)msg)->key;
                     bcmolt_onu_ranging_completed_data *data = &((bcmolt_onu_ranging_completed*)msg)->data;
 
-                    BCM_LOG(INFO, openolt_log_id, "onu indication, pon_ni %d, onu_id %d, onu_state %s\n", 
-                        key->pon_ni, key->onu_id, (data->status==BCMOLT_RESULT_SUCCESS)?"up":"down");
-
                     onu_ind->set_intf_id(key->pon_ni);
                     onu_ind->set_onu_id(key->onu_id);
                     if (ONU_RANGING_STATE_IF_UP(data->status))
                         onu_ind->set_oper_state("up");
                     if (ONU_RANGING_STATE_IF_DOWN(data->status))
                         onu_ind->set_oper_state("down");
-
+                    (key->onu_id)?onu_ind->set_admin_state("up"):onu_ind->set_admin_state("down");
                     ind.set_allocated_onu_ind(onu_ind);
+                    BCM_LOG(INFO, openolt_log_id, "onu indication, pon_ni %d, onu_id %d, onu_state %s, onu_admin %s\n", 
+                        key->pon_ni, key->onu_id, (data->status==BCMOLT_RESULT_SUCCESS)?"up":"down",
+                        (key->onu_id)?"up":"down");
                 }
             }
     }
@@ -797,14 +785,6 @@
         return Status(grpc::StatusCode::INTERNAL, 
             "PON Interface operations state change indication subscribe failed");
 
-    rx_cfg.obj_type = BCMOLT_OBJ_ID_PON_INTERFACE;
-    rx_cfg.rx_cb = IfIndication;
-    rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
-    rx_cfg.subgroup = bcmolt_pon_interface_auto_subgroup_state_change_completed;
-    rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
-    if(rc != BCM_ERR_OK)
-        return Status(grpc::StatusCode::INTERNAL, "PON Interface indication subscribe failed");
-
     rx_cfg.obj_type = BCMOLT_OBJ_ID_NNI_INTERFACE;
     rx_cfg.rx_cb = IfOperIndication;
     rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
@@ -814,14 +794,6 @@
         return Status(grpc::StatusCode::INTERNAL, 
             "NNI Interface operations state change indication subscribe failed");
 
-    rx_cfg.obj_type = BCMOLT_OBJ_ID_NNI_INTERFACE;
-    rx_cfg.rx_cb = IfIndication;
-    rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
-    rx_cfg.subgroup = bcmolt_nni_interface_auto_subgroup_state_change;
-    rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
-    if(rc != BCM_ERR_OK)
-        return Status(grpc::StatusCode::INTERNAL, "NNI Interface indication subscribe failed");
-
     rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
     rx_cfg.rx_cb = OnuAlarmIndication;
     rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
@@ -864,15 +836,6 @@
         return Status(grpc::StatusCode::INTERNAL, "onu indication subscribe failed");
 
     rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
-    rx_cfg.rx_cb = OnuOperIndication;
-    rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
-    rx_cfg.subgroup = bcmolt_onu_auto_subgroup_state_change;
-    rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
-    if(rc != BCM_ERR_OK)
-        return Status(grpc::StatusCode::INTERNAL, 
-            "onu operational state change indication subscribe failed");
-
-    rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
     rx_cfg.rx_cb = OnuStartupFailureIndication;
     rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
     rx_cfg.subgroup = bcmolt_onu_auto_subgroup_sufi;