VOL-1204 Removing reference to 128, clean port translation

Change-Id: I4a8d1bd1916de566de82f798a56154a4fc1d5b99
diff --git a/src/core.cc b/src/core.cc
index 458c93e..d756297 100644
--- a/src/core.cc
+++ b/src/core.cc
@@ -640,7 +640,7 @@
         return bcm_to_grpc_err(err, "flow add failed");
     }
 
-    register_new_flow(key);
+    // register_new_flow(key);
 
     return Status::OK;
 }
diff --git a/src/stats_collection.cc b/src/stats_collection.cc
index 5e23d11..559b2c1 100644
--- a/src/stats_collection.cc
+++ b/src/stats_collection.cc
@@ -5,6 +5,7 @@
 #include <openolt.grpc.pb.h>
 #include "indications.h"
 #include "core.h"
+#include "translation.h"
 
 extern "C"
 {
@@ -57,17 +58,13 @@
 }
 #endif
 
-openolt::PortStatistics* collectPortStatistics(int intf_id, bcmbal_intf_type intf_type) {
+openolt::PortStatistics* collectPortStatistics(bcmbal_interface_key key) {
 
     bcmos_errno err;
     bcmbal_interface_stat stat;     /**< declare main API struct */
-    bcmbal_interface_key key = { }; /**< declare key */
     bcmos_bool clear_on_read = false;
 
     openolt::PortStatistics* port_stats = get_default_port_statistics();
-    // build key
-    key.intf_id = (bcmbal_intf_id) intf_id;
-    key.intf_type = intf_type;
 
     /* init the API struct */
     BCMBAL_STAT_INIT(&stat, interface, key);
@@ -97,10 +94,15 @@
 
     } else {
         std::cout << "ERROR: Failed to retrieve port statistics"
-                  << " intf_id:" << intf_id
-                  << " intf_type:" << intf_type << std::endl;
+                  << " intf_id:" << key.intf_id
+                  << " intf_type:" << key.intf_type << std::endl;
     }
 
+    port_stats->set_intf_id(interface_key_to_port_no(key));
+    time_t now;
+    time(&now);
+    port_stats->set_timestamp((int)now);
+
     return port_stats;
 
 }
@@ -146,7 +148,7 @@
 #endif
 
 
-void* stats_collection() {
+void stats_collection() {
 
     if (!state.is_connected()) {
         std::cout << "Voltha is not connected, do not collect stats" << std::endl;
@@ -157,7 +159,6 @@
         return;
     }
 
-    time_t now;
 
     std::cout << "Collecting statistics" << std::endl;
 
@@ -165,22 +166,24 @@
 
     //Uplink ports
     for (int i = 0; i < 4; i++) {
-        openolt::PortStatistics* port_stats = collectPortStatistics(i, BCMBAL_INTF_TYPE_NNI);
-        //FIXME Use clean port translation
-        port_stats->set_intf_id(128 + i);
-        time(&now);
-        port_stats->set_timestamp((int)now);
+        bcmbal_interface_key nni_interface;
+        nni_interface.intf_type = BCMBAL_INTF_TYPE_NNI;
+        nni_interface.intf_id = i;
+
+        openolt::PortStatistics* port_stats = collectPortStatistics(nni_interface);
+
         openolt::Indication ind;
         ind.set_allocated_port_stats(port_stats);
         oltIndQ.push(ind);
     }
     //Pon ports
     for (int i = 0; i < 16; i++) {
-        openolt::PortStatistics* port_stats = collectPortStatistics(i, BCMBAL_INTF_TYPE_PON);
-        //FIXME Use clean port translation
-        port_stats->set_intf_id((0x2 << 28) + i);
-        time(&now);
-        port_stats->set_timestamp((int)now);
+        bcmbal_interface_key pon_interface;
+        pon_interface.intf_type = BCMBAL_INTF_TYPE_PON;
+        pon_interface.intf_id = i;
+
+        openolt::PortStatistics* port_stats = collectPortStatistics(pon_interface);
+
         openolt::Indication ind;
         ind.set_allocated_port_stats(port_stats);
         oltIndQ.push(ind);
@@ -221,11 +224,11 @@
 }
 
 /* Storing flow keys, temporary */
-void register_new_flow(bcmbal_flow_key key) {
-    for (int i = 0; i < FLOWS_COUNT; i++) {
-        if (flows_keys[i].flow_id == 0) {
-            flows_keys[i] = key;
-            break;
-        }
-    }
-}
+// void register_new_flow(bcmbal_flow_key key) {
+//     for (int i = 0; i < FLOWS_COUNT; i++) {
+//         if (flows_keys[i].flow_id == 0) {
+//             flows_keys[i] = key;
+//             break;
+//         }
+//     }
+// }
diff --git a/src/stats_collection.h b/src/stats_collection.h
index fe3c27a..09b70f1 100644
--- a/src/stats_collection.h
+++ b/src/stats_collection.h
@@ -11,12 +11,12 @@
 void init_stats();
 void stop_collecting_statistics();
 openolt::PortStatistics* get_default_port_statistics();
-openolt::PortStatistics* collectPortStatistics(int intf_id, bcmbal_intf_type intf_type);
+openolt::PortStatistics* collectPortStatistics(bcmbal_interface_key key);
 #if 0
 openolt::FlowStatistics* get_default_flow_statistics();
 openolt::FlowStatistics* collectFlowStatistics(bcmbal_flow_id flow_id, bcmbal_flow_type flow_type);
-#endif
 void register_new_flow(bcmbal_flow_key key);
+#endif
 
 
 #endif
diff --git a/src/translation.cc b/src/translation.cc
index 55daa4c..88f0a03 100644
--- a/src/translation.cc
+++ b/src/translation.cc
@@ -2,10 +2,10 @@
 
 int interface_key_to_port_no(bcmbal_interface_key key) {
     if (key.intf_type == BCMBAL_INTF_TYPE_NNI) {
-        return 128 + key.intf_id;
+        return (0x1 << 15) + key.intf_id;
     }
     if (key.intf_type == BCMBAL_INTF_TYPE_PON) {
-        return (0x2 << 28) + 1;
+        return (0x2 << 28) + key.intf_id;
     }
     return key.intf_id;
 }