VOL-1580: Support reporting ONU Registration ID as part of ONU Activation Indication

Change-Id: I553daf21f467215ac676a4c92a4ce0eaa0e016cf
diff --git a/agent/common/core.h b/agent/common/core.h
index 22ef8a9..7f8bfe4 100644
--- a/agent/common/core.h
+++ b/agent/common/core.h
@@ -25,6 +25,8 @@
 #include "state.h"
 
 #define COLLECTION_PERIOD 15
+#define BAL_DYNAMIC_LIST_BUFFER_SIZE (32 * 1024)
+#define MAX_REGID_LENGTH  36
 
 extern State state;
 
diff --git a/agent/src/indications.cc b/agent/src/indications.cc
index 30a04ab..789702f 100644
--- a/agent/src/indications.cc
+++ b/agent/src/indications.cc
@@ -51,6 +51,57 @@
     return "unknown";
 }
 
+std::string getOnuRegistrationId(uint32_t intf_id, uint32_t onu_id){
+    bcmbal_subscriber_terminal_key key;
+    bcmbal_subscriber_terminal_cfg sub_term_obj = {};
+    uint8_t  *list_mem;// to fetch config details for ONU
+    bcmos_errno err = BCM_ERR_OK;
+
+    key.sub_term_id =onu_id;
+    key.intf_id = intf_id;
+    BCM_LOG(INFO, openolt_log_id,"Processing subscriber terminal cfg get for: %d",key.intf_id);
+
+    BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, key);
+
+    BCMBAL_CFG_PROP_GET(&sub_term_obj, subscriber_terminal, all_properties);
+    char *reg_id = (char*)malloc(sizeof(char)*MAX_REGID_LENGTH);
+    memset(reg_id, '\0', MAX_REGID_LENGTH);
+
+    //set memory to use for variable-sized lists
+    list_mem = (uint8_t*)malloc(BAL_DYNAMIC_LIST_BUFFER_SIZE);
+
+    if (list_mem == NULL)
+    {
+       BCM_LOG(ERROR,openolt_log_id,"Memory allocation failed while handling subscriber terminal \
+               cfg get subscriber_terminal_id(%d), Interface ID(%d)",key.sub_term_id, key.intf_id);
+       return reg_id;
+    }
+
+    memset(list_mem, 0, BAL_DYNAMIC_LIST_BUFFER_SIZE);
+    BCMBAL_CFG_LIST_BUF_SET(&sub_term_obj, subscriber_terminal, list_mem, BAL_DYNAMIC_LIST_BUFFER_SIZE);
+
+    //call API
+    err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &sub_term_obj.hdr);
+
+    if (err != BCM_ERR_OK)
+    {
+        BCM_LOG(ERROR,openolt_log_id, "Failed to get information from BAL subscriber_terminal_id(%d), Interface ID(%d)",
+                key.sub_term_id, key.intf_id);
+        free(list_mem);
+        return reg_id;
+    }
+
+    BCM_LOG(INFO,openolt_log_id, "Get Subscriber cfg sent to OLT for Subscriber Id(%d) on Interface(%d)",
+            key.sub_term_id, key.intf_id);
+
+    for (int i=0; i<MAX_REGID_LENGTH ; i++){
+        reg_id[i]=sub_term_obj.data.registration_id.arr[i];
+    }
+
+    free(list_mem);
+    return reg_id;
+}
+
 bcmos_errno OltOperIndication(bcmbal_obj *obj) {
     openolt::Indication ind;
     openolt::OltIndication* olt_ind = new openolt::OltIndication;
@@ -299,6 +350,11 @@
     } else {
         onu_ind->set_admin_state("down");
     }
+    const std::string  reg_id = getOnuRegistrationId(key->intf_id,key->sub_term_id);
+    onu_ind->set_registration_id(reg_id);
+
+    BCM_LOG(INFO, openolt_log_id, "onu indication, intf_id %d, onu_id %d, oper state %s, admin_state %s,registration id %s\n",
+        onu_ind->intf_id(), onu_ind->onu_id(),onu_ind->oper_state().c_str(), onu_ind->admin_state().c_str(),onu_ind->registration_id().c_str());
 
     ind.set_allocated_onu_ind(onu_ind);
 
@@ -328,11 +384,12 @@
     } else {
         onu_ind->set_admin_state("down");
     }
-
+    const std::string  reg_id = getOnuRegistrationId(key->intf_id,key->sub_term_id);
+    onu_ind->set_registration_id(reg_id);
     ind.set_allocated_onu_ind(onu_ind);
 
-    BCM_LOG(INFO, openolt_log_id, "onu oper state indication, intf_id %d, onu_id %d, old oper state %d, new oper state %s, admin_state %s\n",
-        key->intf_id, key->sub_term_id, data->old_oper_status, onu_ind->oper_state().c_str(), onu_ind->admin_state().c_str());
+    BCM_LOG(INFO, openolt_log_id, "onu oper state indication, intf_id %d, onu_id %d, old oper state %d, new oper state %s, admin_state %s registraion_id %s\n",
+        key->intf_id, key->sub_term_id, data->old_oper_status, onu_ind->oper_state().c_str(), onu_ind->admin_state().c_str(),onu_ind->registration_id().c_str());
 
     oltIndQ.push(ind);
     return BCM_ERR_OK;
diff --git a/protos/openolt.proto b/protos/openolt.proto
index 6be8983..ccc2d05 100644
--- a/protos/openolt.proto
+++ b/protos/openolt.proto
@@ -220,6 +220,7 @@
     string oper_state = 3;      // up, down
     string admin_state = 5;     // up, down
     SerialNumber serial_number = 4;
+    bytes registration_id = 6; // reg_id of onu
 }
 
 message IntfOperIndication {