VOL-769 Multiple PON ports can be used concurrently with the Openolt adapter
intf_id specified for all flows and logical port number to intf_id translation function fixed

Change-Id: I3f8ab5c7ce00f6194f9bd0ddad159335f8bbd1e6
diff --git a/voltha/adapters/openolt/openolt_device.py b/voltha/adapters/openolt/openolt_device.py
index 4736a9f..ea8d96e 100644
--- a/voltha/adapters/openolt/openolt_device.py
+++ b/voltha/adapters/openolt/openolt_device.py
@@ -201,10 +201,10 @@
         intf_id = onu_disc_indication.intf_id
         serial_number=onu_disc_indication.serial_number
 
-        self.log.debug("onu discovery indication", intf_id=intf_id, serial_number=serial_number)
-
         serial_number_str = self.stringify_serial_number(serial_number)
 
+        self.log.debug("onu discovery indication", intf_id=intf_id, serial_number=serial_number_str)
+
         onu_device = self.adapter_agent.get_child_device(self.device_id, serial_number=serial_number_str)
 
         if onu_device is None:
@@ -214,7 +214,7 @@
                         platform.intf_id_to_port_no(intf_id, Port.PON_OLT),
                         onu_id, serial_number)
                 self.log.info("activate-onu", intf_id=intf_id, onu_id=onu_id,
-                        serial_number=serial_number)
+                        serial_number=serial_number_str)
                 onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id,serial_number=serial_number)
                 self.stub.ActivateOnu(onu)
             except Exception as e:
@@ -222,8 +222,8 @@
 
         else:
             onu_id = onu_device.proxy_address.onu_id
-            if onu_device.oper_status == OperStatus.DISCOVERED:
-                self.log.info("ignore onu discovery indication, the onu has been discovered and should be \
+            if onu_device.oper_status == OperStatus.DISCOVERED or onu_device.oper_status == OperStatus.ACTIVATING:
+                self.log.debug("ignore onu discovery indication, the onu has been discovered and should be \
                               activating shorlty", intf_id=intf_id, onu_id=onu_id, state=onu_device.oper_status)
             elif onu_device.oper_status== OperStatus.ACTIVE:
                 self.log.warn("onu discovery indication whereas onu is supposed to be active",
@@ -258,9 +258,9 @@
             self.log.warn('onu-device-is-none-invalid-message')
             return
 
-        if platform.intf_id_from_port_num(onu_device.parent_port_no) != onu_indication.intf_id:
+        if platform.intf_id_from_pon_port_no(onu_device.parent_port_no) != onu_indication.intf_id:
             self.log.warn('ONU-is-on-a-different-intf-id-now',
-                          previous_intf_id=platform.intf_id_from_port_num(onu_device.parent_port_no),
+                          previous_intf_id=platform.intf_id_from_pon_port_no(onu_device.parent_port_no),
                           current_intf_id=onu_indication.intf_id)
             # FIXME - handle intf_id mismatch (ONU move?)
 
@@ -460,7 +460,7 @@
 
         send_pkt = binascii.unhexlify(str(payload).encode("HEX"))
 
-        onu_pkt = openolt_pb2.OnuPacket(intf_id=platform.intf_id_from_port_num(egress_port),
+        onu_pkt = openolt_pb2.OnuPacket(intf_id=platform.intf_id_from_pon_port_no(egress_port),
                 onu_id=platform.onu_id_from_port_num(egress_port), pkt=send_pkt)
 
         self.stub.OnuPacketOut(onu_pkt)
diff --git a/voltha/adapters/openolt/openolt_flow_mgr.py b/voltha/adapters/openolt/openolt_flow_mgr.py
index 2c63df8..367525e 100644
--- a/voltha/adapters/openolt/openolt_flow_mgr.py
+++ b/voltha/adapters/openolt/openolt_flow_mgr.py
@@ -125,7 +125,7 @@
 
         # FIXME - Why ignore downstream flows?
         if is_down_stream is False:
-            intf_id = platform.intf_id_from_port_num(classifier_info['in_port'])
+            intf_id = platform.intf_id_from_uni_port_num(classifier_info['in_port'])
             onu_id = platform.onu_id_from_port_num(classifier_info['in_port'])
             self.divide_and_add_flow(intf_id, onu_id, classifier_info, action_info)
         #else:
@@ -186,8 +186,9 @@
 
         flow = openolt_pb2.Flow(
                 onu_id=onu_id, flow_id=flow_id, flow_type="upstream",
-                gemport_id=gemport_id, classifier=self.mk_classifier(uplink_classifier),
-                action=self.mk_action(uplink_action))
+                access_intf_id=intf_id, gemport_id=gemport_id,
+                classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action))
+
 
         self.stub.FlowAdd(flow)
 
@@ -216,8 +217,8 @@
 
         upstream_flow = openolt_pb2.Flow(
                 onu_id=onu_id, flow_id=flow_id, flow_type="upstream",
-                gemport_id=gemport_id, classifier=self.mk_classifier(classifier),
-                action=self.mk_action(action))
+                access_intf_id=intf_id, gemport_id=gemport_id,
+                classifier=self.mk_classifier(classifier), action=self.mk_action(action))
 
         self.stub.FlowAdd(upstream_flow)
 
@@ -242,8 +243,8 @@
 
         upstream_flow = openolt_pb2.Flow(
                 onu_id=onu_id, flow_id=uplink_flow_id, flow_type="upstream",
-                gemport_id=gemport_id, classifier=self.mk_classifier(uplink_classifier),
-                action=self.mk_action(uplink_action))
+                access_intf_id=intf_id,gemport_id=gemport_id,
+                classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action))
 
         self.stub.FlowAdd(upstream_flow)
 
@@ -254,8 +255,9 @@
 
         downstream_flow = openolt_pb2.Flow(
                 onu_id=onu_id, flow_id=downlink_flow_id, flow_type="downstream",
-                gemport_id=gemport_id, classifier=self.mk_classifier(downlink_classifier),
-                action=self.mk_action(downlink_action))
+                access_intf_id=intf_id, gemport_id=gemport_id,
+                classifier=self.mk_classifier(downlink_classifier), action=self.mk_action(downlink_action))
+
 
         self.stub.FlowAdd(downstream_flow)
 
diff --git a/voltha/adapters/openolt/openolt_platform.py b/voltha/adapters/openolt/openolt_platform.py
index 841daaf..d289ccb 100644
--- a/voltha/adapters/openolt/openolt_platform.py
+++ b/voltha/adapters/openolt/openolt_platform.py
@@ -112,9 +112,12 @@
 def onu_id_from_port_num(port_num):
     return (port_num >> 4) & 0x7F
 
-def intf_id_from_port_num(port_num):
+def intf_id_from_uni_port_num(port_num):
     return (port_num >> 11) & 0xF
 
+def intf_id_from_pon_port_no(port_no):
+    return port_no & 0xF
+
 def intf_id_to_port_no(intf_id, intf_type):
     if intf_type is Port.ETHERNET_NNI:
         # FIXME - Remove hardcoded '129'