VOL-3202: Report UNI port capability as part of port-created RPC

Change-Id: I91a1ac60775fbe0ba1bbab287cb4c8bccc74df2e
diff --git a/python/adapters/brcm_openomci_onu/brcm_openomci_onu_adapter.py b/python/adapters/brcm_openomci_onu/brcm_openomci_onu_adapter.py
index b1bca58..c261501 100644
--- a/python/adapters/brcm_openomci_onu/brcm_openomci_onu_adapter.py
+++ b/python/adapters/brcm_openomci_onu/brcm_openomci_onu_adapter.py
@@ -273,11 +273,6 @@
         else:
             self.log.error("device-not-found")
 
-    def get_ofp_port_info(self, device, port_no):
-        ofp_port_info = self.devices_handlers[device.id].get_ofp_port_info(device, port_no)
-        self.log.debug('get-ofp-port-info', device_id=device.id,
-                  port_name=ofp_port_info.port.ofp_port.name, port_no=ofp_port_info.port.device_port_no)
-        return ofp_port_info
 
     def process_inter_adapter_message(self, msg, max_retry=0, current_retry=0):
         # Unpack the header to know which device needs to handle this message
diff --git a/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py b/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
index 1eecd7a..4fe1546 100644
--- a/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
+++ b/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
@@ -19,56 +19,51 @@
 """
 
 from __future__ import absolute_import
-import six
-import arrow
-import structlog
+
 import json
 import random
-
 from collections import OrderedDict
 
-from twisted.internet import reactor
-from twisted.internet.defer import inlineCallbacks, returnValue
-
-from heartbeat import HeartBeat
-from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent
-from pyvoltha.adapters.extensions.events.device_events.onu.onu_disabled_event import OnuDisabledEvent
-from pyvoltha.adapters.extensions.events.device_events.onu.onu_deleted_event import OnuDeletedEvent
-from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
-from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
-from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
-
+import arrow
 import pyvoltha.common.openflow.utils as fd
-from pyvoltha.common.utils.registry import registry
-from pyvoltha.adapters.common.frameio.frameio import hexify
-from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
-from pyvoltha.adapters.common.kvstore.twisted_etcd_store import TwistedEtcdStore
-from voltha_protos.logical_device_pb2 import LogicalPort
-from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
-from voltha_protos.device_pb2 import Port
-from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE, OFPPS_LINK_DOWN, \
-    OFPPF_FIBER, OFPPF_1GB_FD
-from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
-    InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
-    InterAdapterDeleteTcontMessage
-from voltha_protos.openolt_pb2 import OnuIndication
-from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
-    OnuDeviceEntry, IN_SYNC_KEY
+import six
+import structlog
+from heartbeat import HeartBeat
+from omci.brcm_mcast_task import BrcmMcastTask
 from omci.brcm_mib_download_task import BrcmMibDownloadTask
-from omci.brcm_tp_setup_task import BrcmTpSetupTask
 from omci.brcm_tp_delete_task import BrcmTpDeleteTask
+from omci.brcm_tp_setup_task import BrcmTpSetupTask
 from omci.brcm_uni_lock_task import BrcmUniLockTask
 from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
 from onu_gem_port import OnuGemPort
 from onu_tcont import OnuTCont
 from pon_port import PonPort
-from omci.brcm_mcast_task import BrcmMcastTask
-from uni_port import UniPort, UniType
-from uni_port import RESERVED_TRANSPARENT_VLAN
-from pyvoltha.common.tech_profile.tech_profile import TechProfile
-from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
-from pyvoltha.adapters.extensions.omci.omci_entities import AniG, Tcont, MacBridgeServiceProfile
+from pyvoltha.adapters.common.frameio.frameio import hexify
+from pyvoltha.adapters.common.kvstore.twisted_etcd_store import TwistedEtcdStore
+from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
+from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent
+from pyvoltha.adapters.extensions.events.device_events.onu.onu_deleted_event import OnuDeletedEvent
+from pyvoltha.adapters.extensions.events.device_events.onu.onu_disabled_event import OnuDisabledEvent
+from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
+from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
 from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
+from pyvoltha.adapters.extensions.omci.omci_entities import AniG, Tcont, MacBridgeServiceProfile
+from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
+    OnuDeviceEntry, IN_SYNC_KEY
+from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
+from pyvoltha.common.tech_profile.tech_profile import TechProfile
+from pyvoltha.common.utils.registry import registry
+from twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, returnValue
+from uni_port import RESERVED_TRANSPARENT_VLAN
+from uni_port import UniPort, UniType
+from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
+from voltha_protos.device_pb2 import Port
+from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
+    InterAdapterOmciMessage, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
+    InterAdapterDeleteTcontMessage
+from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC
+from voltha_protos.openolt_pb2 import OnuIndication
 from voltha_protos.voltha_pb2 import TestResponse
 
 OP = EntityOperations
@@ -200,43 +195,6 @@
         if self.omci_cc is not None:
             self.omci_cc.receive_message(msg)
 
-    def get_ofp_port_info(self, device, port_no):
-        self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id)
-        cap = OFPPF_1GB_FD | OFPPF_FIBER
-
-        hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
-                                   ((device.parent_port_no >> 8 & 0xff),
-                                    device.parent_port_no & 0xff,
-                                    (port_no >> 16) & 0xff,
-                                    (port_no >> 8) & 0xff,
-                                    port_no & 0xff))
-
-        uni_port = self.uni_port(int(port_no))
-        name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
-        self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port)
-
-        ofstate = OFPPS_LINK_DOWN
-        if uni_port.operstatus is OperStatus.ACTIVE:
-            ofstate = OFPPS_LIVE
-
-        return PortCapability(
-            port=LogicalPort(
-                ofp_port=ofp_port(
-                    name=name,
-                    hw_addr=hw_addr,
-                    config=0,
-                    state=ofstate,
-                    curr=cap,
-                    advertised=cap,
-                    peer=cap,
-                    curr_speed=OFPPF_1GB_FD,
-                    max_speed=OFPPF_1GB_FD
-                ),
-                device_id=device.id,
-                device_port_no=port_no
-            )
-        )
-
     # Called once when the adapter creates the device/onu instance
     @inlineCallbacks
     def activate(self, device):
@@ -1869,7 +1827,9 @@
         self.log.debug('uni-port-inputs', uni_no=uni_no, uni_id=uni_id, uni_name=uni_name, uni_type=uni_type,
                        entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
 
-        uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
+        uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name,
+                                  device.parent_port_no, device.serial_number,
+                                  uni_type,)
         uni_port.entity_id = entity_id
         uni_port.enabled = True
         uni_port.mac_bridge_port_num = mac_bridge_port_num
diff --git a/python/adapters/brcm_openomci_onu/uni_port.py b/python/adapters/brcm_openomci_onu/uni_port.py
index 7094022..7bab7ca 100644
--- a/python/adapters/brcm_openomci_onu/uni_port.py
+++ b/python/adapters/brcm_openomci_onu/uni_port.py
@@ -16,8 +16,11 @@
 from __future__ import absolute_import
 import structlog
 from enum import Enum
+from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
 from voltha_protos.common_pb2 import OperStatus, AdminState
 from voltha_protos.device_pb2 import Port
+from voltha_protos.openflow_13_pb2 import OFPPF_1GB_FD, OFPPF_FIBER, OFPPS_LINK_DOWN, OFPPS_LIVE, ofp_port
+
 
 class UniType(Enum):
     """
@@ -27,14 +30,17 @@
     VEIP = 'VirtualEthernetInterfacePoint'
     # TODO: Add others as they become supported
 
+
 # ReservedVlan Transparent Vlan (Masked Vlan, VLAN_ANY in ONOS Flows)
 
 RESERVED_TRANSPARENT_VLAN = 4096
 
+
 class UniPort(object):
     """Wraps southbound-port(s) support for ONU"""
 
     def __init__(self, handler, name, uni_id, port_no, ofp_port_no,
+                 parent_port_no, device_serial_number,
                  type=UniType.PPTP):
         self.log = structlog.get_logger(device_id=handler.device_id,
                                         port_no=port_no)
@@ -48,13 +54,15 @@
         self._mac_bridge_port_num = 0
         self._type = type
         self._uni_id = uni_id
+        self._parent_port_no = parent_port_no
+        self._serial_num = device_serial_number
 
         self._admin_state = AdminState.DISABLED
         self._oper_status = OperStatus.DISCOVERED
 
     def __str__(self):
         return "UniPort - name: {}, port_number: {}, admin_state: {}, oper_state: {}, entity_id: {}, " \
-               "mac_bridge_port_num: {}, type: {}, ofp_port: {}"\
+               "mac_bridge_port_num: {}, type: {}, ofp_port: {}" \
             .format(self.name, self.port_number, self.adminstate, self.operstatus, self.entity_id,
                     self._mac_bridge_port_num, self.type, self._ofp_port_no)
 
@@ -62,8 +70,10 @@
         return str(self)
 
     @staticmethod
-    def create(handler, name, uni_id, port_no, ofp_port_no, type):
-        port = UniPort(handler, name, uni_id, port_no, ofp_port_no, type)
+    def create(handler, name, uni_id, port_no, ofp_port_no,
+               parent_port_no, device_serial_number, type):
+        port = UniPort(handler, name, uni_id, port_no, ofp_port_no,
+                       parent_port_no, device_serial_number, type)
         return port
 
     def _start(self):
@@ -124,7 +134,6 @@
         """
         return self._uni_id
 
-
     @property
     def mac_bridge_port_num(self):
         """
@@ -165,18 +174,59 @@
         """
         return self._type
 
+    @property
+    def parent_port_no(self):
+        """
+        Parent port number for this ONU - will be the PON port of the OLT
+        where this ONU is connected
+        """
+        return self._parent_port_no
+
+    @property
+    def serial_number(self):
+        """
+        Serial number of the ONU
+        """
+        return self._serial_num
+
     def get_port(self):
         """
         Get the VOLTHA PORT object for this port
         :return: VOLTHA Port object
         """
+
+        cap = OFPPF_1GB_FD | OFPPF_FIBER
+
+        hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
+                                   ((self.parent_port_no >> 8 & 0xff),
+                                    self.parent_port_no & 0xff,
+                                    (self.port_number >> 16) & 0xff,
+                                    (self.port_number >> 8) & 0xff,
+                                    self.port_number & 0xff))
+
+        name = self.serial_number + '-' + str(self.mac_bridge_port_num)
+
+        ofstate = OFPPS_LINK_DOWN
+        if self.operstatus is OperStatus.ACTIVE:
+            ofstate = OFPPS_LIVE
+
         self._port = Port(port_no=self.port_number,
                           label=self.port_id_name(),
                           type=Port.ETHERNET_UNI,
                           admin_state=self._admin_state,
-                          oper_status=self._oper_status)
+                          oper_status=self._oper_status,
+                          ofp_port=ofp_port(
+                              name=name,
+                              hw_addr=hw_addr,
+                              config=0,
+                              state=ofstate,
+                              curr=cap,
+                              advertised=cap,
+                              peer=cap,
+                              curr_speed=OFPPF_1GB_FD,
+                              max_speed=OFPPF_1GB_FD
+                          ))
         return self._port
 
     def port_id_name(self):
         return 'uni-{}'.format(self._port_number)
-
diff --git a/python/requirements.txt b/python/requirements.txt
index 5edec1a..e90a615 100644
--- a/python/requirements.txt
+++ b/python/requirements.txt
@@ -1,2 +1,2 @@
-voltha-protos==3.3.2
-pyvoltha==2.4.6
+voltha-protos==3.3.9
+pyvoltha==2.4.7