[VOL-3774] Remove hardcording of NNI port speed

Change-Id: I1c1e50403ac0faabed31ed11be2b59a863c62cb9
diff --git a/BUILDING.md b/BUILDING.md
index 261eb59..8f6d0fc 100644
--- a/BUILDING.md
+++ b/BUILDING.md
@@ -186,7 +186,7 @@
 make OPENOLTDEVICE=asfvolt16 OPENOLT_PROTO_VER=master
 ```
 
-By default, the `OPENOLT_PROTO_VER` defaults to git tag *v5.1.0* of the
+By default, the `OPENOLT_PROTO_VER` defaults to git tag *v5.2.1* of the
 [voltha-protos](https://gerrit.opencord.org/gitweb?p=voltha-protos.git;a=summary)
 repo.
 
@@ -323,7 +323,7 @@
 make OPENOLTDEVICE=rlt-3200g-w OPENOLT_PROTO_VER=master
 ```
 
-By default, the `OPENOLT_PROTO_VER` defaults to git tag *v5.1.0* of the
+By default, the `OPENOLT_PROTO_VER` defaults to git tag *v5.2.1* of the
 [voltha-protos](https://gerrit.opencord.org/gitweb?p=voltha-protos.git;a=summary)
 repo.
 
diff --git a/Makefile b/Makefile
index 6abcae2..70c5cc6 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@
 
 ## Variables
 OPENOLTDEVICE     ?= sim
-OPENOLT_PROTO_VER ?= v5.1.0
+OPENOLT_PROTO_VER ?= v5.2.1
 
 DOCKER                     ?= docker
 DOCKER_REGISTRY            ?=
diff --git a/VERSION b/VERSION
index 0f44168..7c69a55 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.6.4
+3.7.0
diff --git a/agent/Makefile.in b/agent/Makefile.in
index 648c621..abcc0cc 100644
--- a/agent/Makefile.in
+++ b/agent/Makefile.in
@@ -48,7 +48,7 @@
 # This specifies the GIT tag in https://github.com/opencord/voltha-protos
 # repo that we need to refer to, to pick the right version of
 # openolt.proto and tech_profile.proto
-OPENOLT_PROTO_VER ?= v5.1.0
+OPENOLT_PROTO_VER ?= v5.2.1
 
 # Variables used for Inband build
 INBAND = "n"
diff --git a/agent/common/core.h b/agent/common/core.h
index 09ff890..6dba610 100644
--- a/agent/common/core.h
+++ b/agent/common/core.h
@@ -212,6 +212,7 @@
 Status EnablePonIf_(uint32_t intf_id);
 Status DisablePonIf_(uint32_t intf_id);
 Status SetStateUplinkIf_(uint32_t intf_id, bool set_state);
+uint32_t GetNniSpeed_(uint32_t intf_id);
 unsigned NumNniIf_();
 unsigned NumPonIf_();
 Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt);
@@ -246,7 +247,7 @@
 Status GetPonRxPower_(uint32_t intf_id, uint32_t onu_id, openolt::PonRxPowerData* response);
 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);
+Status pushOltOperInd(uint32_t intf_id, const char *type, const char *state, uint32_t speed);
 uint64_t get_flow_status(uint16_t flow_id, uint16_t flow_type, uint16_t data_id);
 
 void stats_collection();
diff --git a/agent/common/main.cc b/agent/common/main.cc
index 549bd59..ce55e4d 100644
--- a/agent/common/main.cc
+++ b/agent/common/main.cc
@@ -112,10 +112,10 @@
         status = EnablePonIf_(i);
         if (!status.ok()) {
             // raise alarm to report error in enabling PON
-            pushOltOperInd(i, "pon", "down");
+            pushOltOperInd(i, "pon", "down", 0 /*Speed will be ignored in the adapter for PONs*/ );
         }
         else
-            pushOltOperInd(i, "pon", "up");
+            pushOltOperInd(i, "pon", "up", 0 /*Speed will be ignored in the adapter for PONs*/);
     }
     sleep(2);
     // Enable all NNI interfaces.
@@ -131,13 +131,15 @@
     }
 #endif
     //only for nni-65536 mapping to intf_id 0
+    uint32_t nni_speed = GetNniSpeed_(0);
     status = SetStateUplinkIf_(0, true);
     if (!status.ok()) {
         // raise alarm to report error in enabling NNI
-        pushOltOperInd(0, "nni", "down");
+        pushOltOperInd(0, "nni", "down", nni_speed);
     }
-    else
-        pushOltOperInd(0, "nni", "up");
+    else{
+        pushOltOperInd(0, "nni", "up", nni_speed);
+    }
 
     for (int i = 1; i < argc; ++i) {
        if(strcmp(argv[i-1], "--interface") == 0 || (strcmp(argv[i-1], "--intf") == 0)) {
diff --git a/agent/src/core_api_handler.cc b/agent/src/core_api_handler.cc
index 2bdefaf..0e0bb62 100644
--- a/agent/src/core_api_handler.cc
+++ b/agent/src/core_api_handler.cc
@@ -1105,6 +1105,19 @@
     return Status::OK;
 }
 
+uint32_t GetNniSpeed_(uint32_t intf_id) {
+    bcmos_errno err = BCM_ERR_OK;
+
+    uint32_t speed;
+    err = get_nni_interface_speed((bcmolt_interface)intf_id, &speed);
+    if (err != BCM_ERR_OK) {
+        OPENOLT_LOG(WARNING, openolt_log_id, "Failed to read speed of NNI interface: %d\n", intf_id);
+        return 0; //This will cause the adapter to use the default speed value
+    }
+
+    return speed;
+}
+
 Status DisablePonIf_(uint32_t intf_id) {
     bcmos_errno err;
     bcmolt_pon_interface_cfg interface_obj;
diff --git a/agent/src/core_utils.cc b/agent/src/core_utils.cc
index df0b7a1..af3f7ad 100644
--- a/agent/src/core_utils.cc
+++ b/agent/src/core_utils.cc
@@ -778,7 +778,7 @@
    return field_val;
 }
 
-Status pushOltOperInd(uint32_t intf_id, const char *type, const char *state)
+Status pushOltOperInd(uint32_t intf_id, const char *type, const char *state, uint32_t speed)
 {
     ::openolt::Indication ind;
     ::openolt::IntfOperIndication* intf_oper_ind = new ::openolt::IntfOperIndication;
@@ -786,6 +786,7 @@
     intf_oper_ind->set_type(type);
     intf_oper_ind->set_intf_id(intf_id);
     intf_oper_ind->set_oper_state(state);
+    intf_oper_ind->set_speed(speed);
     ind.set_allocated_intf_oper_ind(intf_oper_ind);
     oltIndQ.push(ind);
     return Status::OK;
@@ -998,6 +999,20 @@
     return err;
 }
 
+bcmos_errno get_nni_interface_speed(bcmolt_interface id, uint32_t *speed)
+{
+    bcmos_errno err;
+    bcmolt_nni_interface_key nni_key;
+    bcmolt_nni_interface_cfg nni_cfg;
+    nni_key.id = id;
+
+    BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
+    BCMOLT_FIELD_SET_PRESENT(&nni_cfg.data, nni_interface_cfg_data, speed);
+    err = bcmolt_cfg_get(dev_id, &nni_cfg.hdr);
+    *speed = nni_cfg.data.speed;
+    return err;
+}
+
 Status install_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);
 
diff --git a/agent/src/core_utils.h b/agent/src/core_utils.h
index 72ae3bb..344ce5e 100644
--- a/agent/src/core_utils.h
+++ b/agent/src/core_utils.h
@@ -93,6 +93,7 @@
 unsigned NumNniIf_();
 unsigned NumPonIf_();
 bcmos_errno get_nni_interface_status(bcmolt_interface id, bcmolt_interface_state *state);
+bcmos_errno get_nni_interface_speed(bcmolt_interface id, uint32_t *speed);
 Status install_gem_port(int32_t intf_id, int32_t onu_id, int32_t uni_id, int32_t gemport_id, std::string board_technology);
 Status remove_gem_port(int32_t intf_id, int32_t onu_id, int32_t uni_id, int32_t gemport_id, std::string board_technology);
 Status enable_encryption_for_gem_port(int32_t intf_id, int32_t gemport_id, std::string board_technology);
diff --git a/agent/test/Makefile b/agent/test/Makefile
index 26e984a..5897ad3 100644
--- a/agent/test/Makefile
+++ b/agent/test/Makefile
@@ -21,7 +21,7 @@
 TOP_DIR=`pwd`
 OPENOLTDEVICE ?= sim
 
-OPENOLT_PROTO_VER ?= v5.1.0
+OPENOLT_PROTO_VER ?= v5.2.1
 
 ########################################################################
 ##
diff --git a/protos/Makefile b/protos/Makefile
index e56d45e..27ea254 100644
--- a/protos/Makefile
+++ b/protos/Makefile
@@ -19,7 +19,7 @@
 # This specifies the GIT tag in https://github.com/opencord/voltha-protos
 # repo that we need to refer to, to pick the right version of
 # openolt.proto, ext_config.proto and tech_profile.proto
-OPENOLT_PROTO_VER ?= v5.1.0
+OPENOLT_PROTO_VER ?= v5.2.1
 
 CXX ?= g++
 CPPFLAGS += `pkg-config --cflags protobuf grpc` -I googleapis/gens -I./