Replace calls to adapter_agent with platform/cache calls
- Remove dead code in openolt_data_model
Change-Id: I7d1cecf8dec6d47ca038302c2b45cfae99418cba
diff --git a/voltha/adapters/openolt/openolt_data_model.py b/voltha/adapters/openolt/openolt_data_model.py
index 5bad88d..e232a69 100644
--- a/voltha/adapters/openolt/openolt_data_model.py
+++ b/voltha/adapters/openolt/openolt_data_model.py
@@ -17,7 +17,6 @@
import structlog
import socket
from scapy.layers.l2 import Ether
-import voltha.core.flow_decomposer as fd
from voltha.adapters.openolt.openolt_utils import OpenoltUtils
from voltha.protos.device_pb2 import Port, Device
from voltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \
@@ -166,15 +165,8 @@
def olt_nni_intf_id(self):
if self.nni_intf_id is not None:
return self.nni_intf_id
-
- port_list = self.adapter_agent.get_ports(self.device.id,
- Port.ETHERNET_NNI)
- logical_port = self.adapter_agent.get_logical_port(
- self.logical_device_id, port_list[0].label)
- self.nni_intf_id = self.platform.intf_id_from_nni_port_num(
- logical_port.ofp_port.port_no)
- self.log.debug("nni-intf-d ", nni_intf_id=self.nni_intf_id)
- return self.nni_intf_id
+ else:
+ raise ValueError
def onu_create(self, intf_id, onu_id, serial_number):
onu_device = self.adapter_agent.get_child_device(
@@ -223,11 +215,6 @@
except Exception as e:
self.log.error('adapter_agent error', error=e)
- ofp_port_name = self.__get_uni_ofp_port_name(onu_device)
- if ofp_port_name is None:
- self.log.exception("uni-ofp-port-not-found")
- return
-
try:
self.__delete_logical_port(onu_device)
except Exception as e:
@@ -407,67 +394,6 @@
self._onu_gemport_ids[gem] = onu_info
# #######################################################################
- # Flow decomposer utility functions
- #
- # Flow related functions that are used by the OpenOLT flow decomposer.
- # These are all prefixed with _ to denote that they will likely be removed
- # once OpenOLT adapter transitions back to using core's flow decomposer.
- # #######################################################################
-
- def _flow_extract_info(self, flow, flow_direction):
- uni_port_no = None
- child_device_id = None
- if flow_direction == "upstream":
- for field in fd.get_ofb_fields(flow):
- if field.type == fd.IN_PORT:
- is_uni, child_device_id = self.__is_uni_port(field.port)
- if is_uni:
- uni_port_no = field.port
- elif flow_direction == "downstream":
- for field in fd.get_ofb_fields(flow):
- if field.type == fd.METADATA:
- uni_port = field.table_metadata & 0xFFFFFFFF
- is_uni, child_device_id = self.__is_uni_port(uni_port)
- if is_uni:
- uni_port_no = field.port
-
- if uni_port_no is None:
- for action in fd.get_actions(flow):
- if action.type == fd.OUTPUT:
- is_uni, child_device_id = \
- self.__is_uni_port(action.output.port)
- if is_uni:
- uni_port_no = action.output.port
-
- if child_device_id:
- child_device = self.adapter_agent.get_device(child_device_id)
- pon_intf = child_device.proxy_address.channel_id
- onu_id = child_device.proxy_address.onu_id
- uni_id = self.platform.uni_id_from_port_num(uni_port_no) \
- if uni_port_no is not None else None
- else:
- raise ValueError
-
- return pon_intf, onu_id, uni_id
-
- def _get_ofp_port_name(self, intf_id, onu_id, uni_id):
- parent_port_no = self.platform.intf_id_to_port_no(intf_id,
- Port.PON_OLT)
- child_device = self.adapter_agent.get_child_device(
- self.device.id, parent_port_no=parent_port_no, onu_id=onu_id)
- if child_device is None:
- self.log.error("could-not-find-child-device",
- parent_port_no=intf_id, onu_id=onu_id)
- return (None, None)
- ports = self.adapter_agent.get_ports(child_device.id,
- Port.ETHERNET_UNI)
- logical_port = self.adapter_agent.get_logical_port(
- self.logical_device_id, ports[uni_id].label)
- ofp_port_name = (logical_port.ofp_port.name,
- logical_port.ofp_port.port_no)
- return ofp_port_name
-
- # #######################################################################
# Methods used by Alarm and Statistics Manager (TODO - re-visit)
# #######################################################################
@@ -623,23 +549,3 @@
self.adapter_agent.add_port(self.device.id, port)
return port_no, label
-
- def __get_uni_ofp_port_name(self, child_device):
- logical_ports = self.proxy.get('/logical_devices/{}/ports'.format(
- self.logical_device_id))
- for logical_port in logical_ports:
- if logical_port.device_id == child_device.id:
- return logical_port.ofp_port.name
- return None
-
- def __is_uni_port(self, port_no):
- try:
- port = self.adapter_agent.get_logical_port(
- self.logical_device_id, 'uni-{}'.format(port_no))
- if port is not None:
- return (not port.root_port), port.device_id
- else:
- return False, None
- except Exception as e:
- self.log.error("error-retrieving-port", e=e)
- return False, None
diff --git a/voltha/adapters/openolt/openolt_flow_mgr.py b/voltha/adapters/openolt/openolt_flow_mgr.py
index fdef71a..1150d9a 100644
--- a/voltha/adapters/openolt/openolt_flow_mgr.py
+++ b/voltha/adapters/openolt/openolt_flow_mgr.py
@@ -234,7 +234,7 @@
def _clear_flow_id_from_rm(self, flow, flow_id, flow_direction):
try:
pon_intf, onu_id, uni_id \
- = self.data_model._flow_extract_info(flow, flow_direction)
+ = self.platform.flow_extract_info(flow, flow_direction)
except ValueError:
self.log.error("failure extracting pon_intf, onu_id, uni_id info \
from flow")
@@ -318,8 +318,8 @@
ofp_port_name):
# Remove the TP instance associated with the ONU
if ofp_port_name is None:
- ofp_port_name, ofp_port_no \
- = self.data_model._get_ofp_port_name(intf_id, onu_id, uni_id)
+ ofp_port_name = self.data_model.serial_number(intf_id, onu_id)
+
tp_id = self.resource_mgr.get_tech_profile_id_for_onu(intf_id, onu_id,
uni_id)
tp_path = self.get_tp_path(intf_id, ofp_port_name, tp_id)
@@ -368,12 +368,8 @@
self.add_eapol_flow(intf_id, onu_id, uni_id, port_no,
flow, alloc_id, gemport_id,
vlan_id=vlan_id)
- (ofp_port_name, ofp_port_no) \
- = self.data_model._get_ofp_port_name(intf_id, onu_id,
- uni_id)
- if ofp_port_name is None:
- self.log.error("port-name-not-found")
- return
+ ofp_port_name = self.data_model.serial_number(intf_id,
+ onu_id)
tp_id = self.resource_mgr.get_tech_profile_id_for_onu(
intf_id, onu_id, uni_id)
tp_path = self.get_tp_path(intf_id, ofp_port_name, tp_id)
@@ -415,11 +411,10 @@
return alloc_id, gem_port_ids
try:
- (ofp_port_name, ofp_port_no) \
- = self.data_model._get_ofp_port_name(intf_id, onu_id, uni_id)
- if ofp_port_name is None:
- self.log.error("port-name-not-found")
- return alloc_id, gem_port_ids
+ ofp_port_name = self.data_model.serial_number(intf_id, onu_id)
+ ofp_port_no = self.platform.mk_uni_port_num(intf_id,
+ onu_id, uni_id)
+
# FIXME: If table id is <= 63 using 64 as table id
if table_id < DEFAULT_TECH_PROFILE_TABLE_ID:
table_id = DEFAULT_TECH_PROFILE_TABLE_ID
@@ -466,7 +461,7 @@
gem_port_ids.append(
tech_profile_instance.upstream_gem_port_attribute_list[i].
gemport_id)
- except BaseException as e:
+ except Exception as e:
self.log.exception(exception=e)
# Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV
diff --git a/voltha/adapters/openolt/openolt_platform.py b/voltha/adapters/openolt/openolt_platform.py
index ec37a0d..14142d9 100644
--- a/voltha/adapters/openolt/openolt_platform.py
+++ b/voltha/adapters/openolt/openolt_platform.py
@@ -16,6 +16,7 @@
from voltha.protos.device_pb2 import Port
import voltha.protos.device_pb2 as dev_pb2
+import voltha.core.flow_decomposer as fd
"""
Encoding of identifiers
@@ -99,6 +100,9 @@
def intf_id_from_uni_port_num(self, port_num):
return (port_num >> 11) & 0xF
+ def onu_id_from_uni_port_num(self, port_num):
+ return (port_num >> 4) & 0x7F
+
def intf_id_from_pon_port_no(self, port_no):
return port_no & 0xF
@@ -147,3 +151,31 @@
# NNI interface
return True
return False
+
+ def flow_extract_info(self, flow, flow_direction):
+ uni_port_no = None
+ if flow_direction == "upstream":
+ for field in fd.get_ofb_fields(flow):
+ if field.type == fd.IN_PORT:
+ uni_port_no = field.port
+ break
+ elif flow_direction == "downstream":
+ for field in fd.get_ofb_fields(flow):
+ if field.type == fd.METADATA:
+ uni_port_no = field.table_metadata & 0xFFFFFFFF
+ break
+
+ if uni_port_no is None:
+ for action in fd.get_actions(flow):
+ if action.type == fd.OUTPUT:
+ uni_port_no = action.output.port
+ break
+
+ if uni_port_no is None:
+ raise ValueError
+
+ pon_intf = self.platform.intf_id_from_uni_port_num(uni_port_no)
+ onu_id = self.platform.onu_id_from_uni_port_num(uni_port_no)
+ uni_id = self.platform.uni_id_from_port_num(uni_port_no)
+
+ return pon_intf, onu_id, uni_id