[VOL-5255] Use all uplink interfaces not only interface 0 at OLT

Raising a new MR after addressing review comments from the original MR.
Link to original MR:
https://gerrit.opencord.org/c/openolt/+/34962
https://gerrit.opencord.org/c/openolt/+/35151

Change-Id: I1231ef0943d6656f1ea0be96a1b2e55c716d9ba6
Signed-off-by: Sridhar Ravindra <sridhar.ravindra@radisys.com>
diff --git a/agent/Makefile.in b/agent/Makefile.in
index d0986f0..a3d2c9e 100644
--- a/agent/Makefile.in
+++ b/agent/Makefile.in
@@ -52,7 +52,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.4.10
+OPENOLT_PROTO_VER ?= v5.6.4
 
 # Variables used for Inband build
 INBAND = "n"
@@ -159,6 +159,7 @@
 			cp download/Makefile.onl $(ONL_DIR)/Makefile; \
 			install -m 755 download/build-onl.sh $(ONL_DIR)/OpenNetworkLinux; \
 			cp download/disable-certificate-validation*.patch $(ONL_DIR)/OpenNetworkLinux; \
+			cp download/debian_stretch_mirror.patch $(ONL_DIR)/OpenNetworkLinux; \
 			if [ "$(OPENOLTDEVICE)" = "rlt-3200g-w" ] || [ "$(OPENOLTDEVICE)" = "rlt-1600g-w" ] || [ "$(OPENOLTDEVICE)" = "rlt-1600x-w" ]; \
 			then \
 				cp $(TOP_DIR)/device/$(OPENOLTDEVICE)/update_kernel_options.sh $(ONL_DIR)/OpenNetworkLinux/.; \
diff --git a/agent/common/main.cc b/agent/common/main.cc
index 8e0aba8..910475f 100644
--- a/agent/common/main.cc
+++ b/agent/common/main.cc
@@ -140,26 +140,15 @@
     }
     sleep(2);
     // Enable all NNI interfaces.
-#if 0
     for (int i = 0; i < NumNniIf_(); i++) {
-        status = EnableUplinkIf_(i);
+        uint32_t nni_speed = GetNniSpeed_(i);
+        status = SetStateUplinkIf_(i, true);
         if (!status.ok()) {
             // raise alarm to report error in enabling PON
-            pushOltOperInd(i, "nni", "down");
+            pushOltOperInd(i, "nni", "down", nni_speed);
         }
         else
-            pushOltOperInd(i, "nni", "up");
-    }
-#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", nni_speed);
-    }
-    else{
-        pushOltOperInd(0, "nni", "up", nni_speed);
+            pushOltOperInd(i, "nni", "up", nni_speed);
     }
 
     for (int i = 1; i < argc; ++i) {
diff --git a/agent/download/Makefile.onl b/agent/download/Makefile.onl
index fdf5cca..d5eb095 100644
--- a/agent/download/Makefile.onl
+++ b/agent/download/Makefile.onl
@@ -19,13 +19,13 @@
 
 onl-4.14:
 	if [ $(INBAND) = y ]; then \
-	    cd OpenNetworkLinux && git checkout -B $@ $(COMMIT_ID) && git pull origin pull/822/head -ff -q --no-edit && git apply disable-certificate-validation-v$(COMMIT_ID).patch && git apply inband-$(COMMIT_ID).patch && docker/tools/onlbuilder --non-interactive -8 -c ./build-onl.sh; \
+	    cd OpenNetworkLinux && git checkout -B $@ $(COMMIT_ID) && git pull origin pull/822/head -ff -q --no-edit && git apply inband-$(COMMIT_ID).patch && docker/tools/onlbuilder --non-interactive -8 -c ./build-onl.sh; \
 	else \
-	cd OpenNetworkLinux && git stash && git checkout -B $@ $(COMMIT_ID) && git pull origin pull/822/head -ff -q --no-edit && git apply disable-certificate-validation-v$(COMMIT_ID).patch && docker/tools/onlbuilder --non-interactive -8 -c ./build-onl.sh; \
+	cd OpenNetworkLinux && git stash && git checkout -B $@ $(COMMIT_ID) && git pull origin pull/822/head -ff -q --no-edit && docker/tools/onlbuilder --non-interactive -8 -c ./build-onl.sh; \
 	fi;
 onl-4.19:
 	if [ "$(BOARD)" = "rlt-3200g-w" ] || [ "$(BOARD)" = "rlt-1600g-w" ] || [ "$(BOARD)" = "rlt-1600x-w" ]; then \
-		cd OpenNetworkLinux && git stash && git checkout -B $@ $(RLT_COMMIT_ID) && git apply disable-certificate-validation-v$(RLT_COMMIT_ID).patch && bash update_kernel_options.sh && docker/tools/onlbuilder --non-interactive -9 -c ./build-onl.sh; \
+		cd OpenNetworkLinux && git stash && git checkout -B $@ $(RLT_COMMIT_ID) && bash update_kernel_options.sh && git apply debian_stretch_mirror.patch && docker/tools/onlbuilder --non-interactive -9 -c ./build-onl.sh; \
 	else \
-		cd OpenNetworkLinux && git stash && git checkout -B $@ $(COMMIT_ID) && git pull origin pull/822/head -ff -q --no-edit && git apply disable-certificate-validation-v$(COMMIT_ID).patch && docker/tools/onlbuilder --non-interactive -9 -c ./build-onl.sh; \
+		cd OpenNetworkLinux && git stash && git checkout -B $@ $(COMMIT_ID) && git pull origin pull/822/head -ff -q --no-edit && git apply debian_stretch_mirror.patch && docker/tools/onlbuilder --non-interactive -9 -c ./build-onl.sh; \
 	fi;
diff --git a/agent/download/debian_stretch_mirror.patch b/agent/download/debian_stretch_mirror.patch
new file mode 100644
index 0000000..b9be94a
--- /dev/null
+++ b/agent/download/debian_stretch_mirror.patch
@@ -0,0 +1,13 @@
+diff --git a/tools/onlrfs.py b/tools/onlrfs.py
+index a9a4cb5d..051259d0 100755
+--- a/tools/onlrfs.py
++++ b/tools/onlrfs.py
+@@ -302,7 +302,7 @@ class OnlRfsBuilder(object):
+ 
+     DEFAULTS = dict(
+         DEBIAN_SUITE='wheezy',
+-        DEBIAN_MIRROR='mirrors.kernel.org/debian/',
++        DEBIAN_MIRROR='archive.debian.org/debian/',
+         APT_CACHE='127.0.0.1:3142/'
+         )
+
diff --git a/agent/src/core_api_handler.cc b/agent/src/core_api_handler.cc
index 5553c9a..d8f2ae4 100644
--- a/agent/src/core_api_handler.cc
+++ b/agent/src/core_api_handler.cc
@@ -70,7 +70,7 @@
                           uint32_t priority, ::tech_profile::SchedulingPolicy sched_policy,
                           ::tech_profile::TrafficShapingInfo traffic_shaping_info, uint32_t tech_profile_id);
 static bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, int alloc_id, std::string direction, int tech_profile_id);
-static bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \
+static bcmos_errno CreateQueue(std::string direction, uint32_t nni_intf_id, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \
                                bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id);
 static bcmos_errno RemoveQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \
                                bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id);
@@ -209,6 +209,7 @@
     device_info->set_hardware_version("");
     device_info->set_firmware_version(firmware_version);
     device_info->set_pon_ports(num_of_pon_ports);
+    device_info->set_nni_ports(num_of_nni_ports);
 
     char serial_number[OPENOLT_FIELD_LEN];
     memset(serial_number, '\0', OPENOLT_FIELD_LEN);
@@ -1627,7 +1628,7 @@
         intf_id = network_intf_id;
     }
 
-    OPENOLT_LOG(INFO, openolt_log_id, "received flow add. voltha_flow_id=%lu, symmetric_voltha_flow_id=%lu, replication=%d\n", voltha_flow_id, symmetric_voltha_flow_id, replicate_flow)
+    OPENOLT_LOG(INFO, openolt_log_id, "received flow add. voltha_flow_id=%lu, symmetric_voltha_flow_id=%lu, network_intf_id=%d, replication=%d\n", voltha_flow_id, symmetric_voltha_flow_id, network_intf_id, replicate_flow);
     // This is the case of voltha_flow_id (not symmetric_voltha_flow_id)
     if (is_voltha_flow_installed(voltha_flow_id)) {
         OPENOLT_LOG(INFO, openolt_log_id, "voltha_flow_id=%lu, already installed\n", voltha_flow_id);
@@ -2078,8 +2079,8 @@
                 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.priority_to_queue.tm_qmp_id, tm_qmp_id);
                 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.priority_to_queue.tm_q_set_id, tm_q_set_id);
 
-                OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, q_set_id = %d, sched_id = %d, intf_type %s\n", \
-                        upstream.c_str(), tm_q_set_id, tm_val.sched_id, \
+                OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, q_set_id = %d, tm_qmp_id = %d, sched_id = %d, intf_type %s\n", \
+                        upstream.c_str(), tm_q_set_id, tm_qmp_id, tm_val.sched_id, \
                         GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type));
             }
         }
@@ -2836,13 +2837,13 @@
     return BCM_ERR_OK;
 }
 
-bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id,
+bcmos_errno CreateQueue(std::string direction, uint32_t nni_intf_id, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id,
                         bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id) {
     bcmos_errno err;
     bcmolt_tm_queue_cfg cfg;
     bcmolt_tm_queue_key key = { };
-    OPENOLT_LOG(INFO, openolt_log_id, "creating %s queue. access_intf_id = %d, onu_id = %d, uni_id = %d \
-gemport_id = %d, tech_profile_id = %d\n", direction.c_str(), access_intf_id, onu_id, uni_id, gemport_id, tech_profile_id);
+    OPENOLT_LOG(INFO, openolt_log_id, "creating %s queue. access_intf_id = %d, nni_intf_id = %d, onu_id = %d, uni_id = %d \
+gemport_id = %d, tech_profile_id = %d\n", direction.c_str(), access_intf_id, nni_intf_id, onu_id, uni_id, gemport_id, tech_profile_id);
 
     key.sched_id = (direction == upstream) ? get_default_tm_sched_id(nni_intf_id, direction) : \
         get_tm_sched_id(access_intf_id, onu_id, uni_id, direction, tech_profile_id);
@@ -2910,6 +2911,7 @@
 
 Status CreateTrafficQueues_(const ::tech_profile::TrafficQueues *traffic_queues) {
     uint32_t intf_id = traffic_queues->intf_id();
+    uint32_t nni_intf_id = traffic_queues->network_intf_id();
     uint32_t onu_id = traffic_queues->onu_id();
     uint32_t uni_id = traffic_queues->uni_id();
     uint32_t tech_profile_id = traffic_queues->tech_profile_id();
@@ -2918,6 +2920,7 @@
     bcmos_errno err;
     bcmolt_egress_qos_type qos_type = get_qos_type(intf_id, onu_id, uni_id, traffic_queues->traffic_queues_size());
 
+    OPENOLT_LOG(DEBUG, openolt_log_id, "Create traffic queues nni_intf_id %d, intf_id %d\n", nni_intf_id, intf_id);
     if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) {
         uint32_t queues_priority_q[traffic_queues->traffic_queues_size()] = {0};
         std::string queues_pbit_map[traffic_queues->traffic_queues_size()];
@@ -2960,7 +2963,7 @@
             return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported");
 	}
 
-        err = CreateQueue(direction, intf_id, onu_id, uni_id, qos_type, traffic_queue.priority(), traffic_queue.gemport_id(), tech_profile_id);
+        err = CreateQueue(direction, nni_intf_id, intf_id, onu_id, uni_id, qos_type, traffic_queue.priority(), traffic_queue.gemport_id(), tech_profile_id);
 
         // If the queue exists already, lets not return failure and break the loop.
         if (err && err != BCM_ERR_ALREADY) {
@@ -3039,6 +3042,7 @@
 
 Status RemoveTrafficQueues_(const ::tech_profile::TrafficQueues *traffic_queues) {
     uint32_t intf_id = traffic_queues->intf_id();
+    uint32_t nni_intf_id = traffic_queues->network_intf_id();
     uint32_t onu_id = traffic_queues->onu_id();
     uint32_t uni_id = traffic_queues->uni_id();
     uint32_t port_no = traffic_queues->port_no();
@@ -3049,6 +3053,8 @@
     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;
 
+    OPENOLT_LOG(DEBUG, openolt_log_id, "Remove Traffic Queues for nni_intf_id %d, intf_id %d\n", nni_intf_id, intf_id);
+    
     for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) {
         ::tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i);
 
diff --git a/agent/src/indications.cc b/agent/src/indications.cc
index 11648dd..f24dca9 100644
--- a/agent/src/indications.cc
+++ b/agent/src/indications.cc
@@ -36,7 +36,6 @@
 using grpc::Status;
 
 bool subscribed = false;
-uint32_t nni_intf_id = 0;
 #define current_device 0
 
 static void OmciIndication(bcmolt_devid olt, bcmolt_msg *msg);
diff --git a/agent/src/indications.h b/agent/src/indications.h
index 0a7c953..75fef02 100644
--- a/agent/src/indications.h
+++ b/agent/src/indications.h
@@ -28,6 +28,5 @@
 extern grpc::Status SubscribeIndication();
 extern dev_log_id openolt_log_id;
 extern dev_log_id omci_log_id;
-extern uint32_t nni_intf_id;
 
 #endif