VOL-1489: Use dpid for mac address rather than fake
Also remove uneeded logical device/port functions.
Also fix exception handling in downstream flow
creation for uni count greater than 1. This catches
an assertion thrown by resource manager if uni
ranges are not set
Also cast onu_id and parent_port_no to int types
for proper encoding and lookup in the core
Also fix assertion that always calculated as true.
Change-Id: Ic3fa197a931640e7347db9d9b26e62aa28bf54ae
diff --git a/python/adapters/openolt/openolt_device.py b/python/adapters/openolt/openolt_device.py
index 5d8eb8e..92a3521 100644
--- a/python/adapters/openolt/openolt_device.py
+++ b/python/adapters/openolt/openolt_device.py
@@ -137,65 +137,6 @@
send_event=True, initial='state_null')
self.go_state_init()
- @inlineCallbacks
- def create_logical_device(self, device_info):
- dpid = device_info.device_id
- serial_number = device_info.device_serial_number
-
- if dpid is None: dpid = self.dpid
- if serial_number is None: serial_number = self.serial_number
-
- if dpid == None or dpid == '':
- uri = self.host_and_port.split(":")[0]
- try:
- socket.inet_pton(socket.AF_INET, uri)
- dpid = '00:00:' + self.ip_hex(uri)
- except socket.error:
- # this is not an IP
- dpid = self.stringToMacAddr(uri)
-
- if serial_number == None or serial_number == '':
- serial_number = self.host_and_port
-
- self.log.info('creating-openolt-logical-device', dp_id=dpid, serial_number=serial_number)
-
- mfr_desc = device_info.vendor
- sw_desc = device_info.firmware_version
- hw_desc = device_info.model
- if device_info.hardware_version: hw_desc += '-' + device_info.hardware_version
-
- # Create logical OF device
- ld = LogicalDevice(
- root_device_id=self.device_id,
- switch_features=ofp_switch_features(
- n_buffers=256, # TODO fake for now
- n_tables=2, # TODO ditto
- capabilities=( # TODO and ditto
- OFPC_FLOW_STATS
- | OFPC_TABLE_STATS
- | OFPC_PORT_STATS
- | OFPC_GROUP_STATS
- )
- ),
- desc=ofp_desc(
- serial_num=serial_number
- )
- )
- ld_init = self.adapter_agent.create_logical_device(ld,
- dpid=dpid)
-
- self.logical_device_id = ld_init.id
-
- ##Moved setting serial number outside of the logical_device function
- #device = yield self.adapter_agent.get_device(self.device_id)
- #device.serial_number = serial_number
- #yield self.adapter_agent.update_device(device)
-
- self.dpid = dpid
- self.serial_number = serial_number
-
- self.log.info('created-openolt-logical-device', logical_device_id=ld_init.id)
-
def stringToMacAddr(self, uri):
regex = re.compile('[^a-zA-Z]')
uri = regex.sub('', uri)
@@ -263,17 +204,30 @@
self.log.info('Device connected', device_info=self.device_info)
- # self.create_logical_device(device_info)
- self.logical_device_id = '0'
-
+ # TODO NEW CORE: logical device id is no longer available. use real device id for now
+ self.logical_device_id = self.device_id
+ dpid = self.device_info.device_id
serial_number = self.device_info.device_serial_number
- if serial_number is None:
- serial_number = self.serial_number
- self.device.serial_number = serial_number
-
- self.serial_number = serial_number
-
+
+ if dpid is None: dpid = self.dpid
+ if serial_number is None: serial_number = self.serial_number
+
+ if dpid == None or dpid == '':
+ uri = self.host_and_port.split(":")[0]
+ try:
+ socket.inet_pton(socket.AF_INET, uri)
+ dpid = '00:00:' + self.ip_hex(uri)
+ except socket.error:
+ # this is not an IP
+ dpid = self.stringToMacAddr(uri)
+
+ if serial_number == None or serial_number == '':
+ serial_number = self.host_and_port
+
+ self.log.info('creating-openolt-device', dp_id=dpid, serial_number=serial_number)
+
self.device.root = True
+ self.device.serial_number = serial_number
self.device.vendor = self.device_info.vendor
self.device.model = self.device_info.model
self.device.hardware_version = self.device_info.hardware_version
@@ -282,7 +236,7 @@
# TODO: check for uptime and reboot if too long (VOL-1192)
self.device.connect_status = ConnectStatus.REACHABLE
- self.device.mac_address = "AA:BB:CC:DD:EE:FF"
+ self.device.mac_address = dpid
yield self.core_proxy.device_update(self.device)
self.resource_mgr = self.resource_mgr_class(self.device_id,
@@ -726,7 +680,6 @@
pkt = Ether(msg)
self.log.debug('packet out', egress_port=egress_port,
device_id=self.device_id,
- logical_device_id=self.logical_device_id,
packet=str(pkt).encode("HEX"))
# Find port type
@@ -890,37 +843,6 @@
elif port_type is Port.ETHERNET_UNI:
assert False, 'local UNI management not supported'
- def add_logical_port(self, port_no, intf_id, oper_state):
- self.log.info('adding-logical-port', port_no=port_no)
-
- label = self.port_name(port_no, Port.ETHERNET_NNI)
-
- cap = OFPPF_1GB_FD | OFPPF_FIBER
- curr_speed = OFPPF_1GB_FD
- max_speed = OFPPF_1GB_FD
-
- if oper_state == OperStatus.ACTIVE:
- of_oper_state = OFPPS_LIVE
- else:
- of_oper_state = OFPPS_LINK_DOWN
-
- ofp = ofp_port(
- port_no=port_no,
- hw_addr=mac_str_to_tuple(self._get_mac_form_port_no(port_no)),
- name=label, config=0, state=of_oper_state, curr=cap,
- advertised=cap, peer=cap, curr_speed=curr_speed,
- max_speed=max_speed)
-
- ofp_stats = ofp_port_stats(port_no=port_no)
-
- logical_port = LogicalPort(
- id=label, ofp_port=ofp, device_id=self.device_id,
- device_port_no=port_no, root_port=True,
- ofp_port_stats=ofp_stats)
-
- self.adapter_agent.add_logical_port(self.logical_device_id,
- logical_port)
-
def _get_mac_form_port_no(self, port_no):
mac = ''
for i in range(4):
@@ -941,20 +863,6 @@
yield self.core_proxy.port_created(self.device_id, port)
- def delete_logical_port(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:
- self.log.debug('delete-logical-port',
- onu_device_id=child_device.id,
- logical_port=logical_port)
- self.flow_mgr.clear_flows_and_scheduler_for_logical_port(
- child_device, logical_port)
- self.adapter_agent.delete_logical_port(
- self.logical_device_id, logical_port)
- return
-
@inlineCallbacks
def delete_port(self, child_serial_number):
ports = self.proxy.get('/devices/{}/ports'.format(
@@ -980,7 +888,7 @@
flows_to_remove=[f.id for f in flows_to_remove])
return
- self.log.debug('logical flows update', flows_to_add=flows_to_add,
+ self.log.debug('flows update', flows_to_add=flows_to_add,
flows_to_remove=flows_to_remove)
for flow in flows_to_add:
@@ -1047,8 +955,7 @@
self.log.error('Failure to disable openolt device', error=e)
def delete(self):
- self.log.info('deleting-olt', device_id=self.device_id,
- logical_device_id=self.logical_device_id)
+ self.log.info('deleting-olt', device_id=self.device_id)
# Clears up the data from the resource manager KV store
# for the device
diff --git a/python/adapters/openolt/openolt_flow_mgr.py b/python/adapters/openolt/openolt_flow_mgr.py
index f06dfce..a5dd2fc 100644
--- a/python/adapters/openolt/openolt_flow_mgr.py
+++ b/python/adapters/openolt/openolt_flow_mgr.py
@@ -374,9 +374,13 @@
# intf_id, onu_id, uni_id, port_no, flow, alloc_id, gemport_id,
# vlan_id=vlan_id)
parent_port_no = self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT)
+
+ self.log.debug('get-child-device', intf_id=intf_id, onu_id=onu_id,
+ parent_port_no=parent_port_no, device_id=self.device_id)
+
onu_device = yield self.core_proxy.get_child_device(self.device_id,
- onu_id=onu_id,
- parent_port_no=parent_port_no)
+ onu_id=int(onu_id),
+ parent_port_no=int(parent_port_no))
tp_path = self.get_tp_path(intf_id, uni)
tech_msg = InterAdapterTechProfileDownloadMessage(uni_id=uni_id, path=tp_path)
@@ -689,7 +693,8 @@
# uni_id defaults to 0, so add 1 to it.
special_vlan_downstream_flow = 4090 - intf_id * onu_id * (uni_id+1)
# Assert that we do not generate invalid vlans under no condition
- assert (special_vlan_downstream_flow >= 2, 'invalid-vlan-generated')
+ assert (special_vlan_downstream_flow >= 2), 'invalid-vlan-generated'
+ self.log.warn('generating-special-downstream-vlan-for-bal', special_vlan_downstream_flow=special_vlan_downstream_flow)
downlink_classifier = dict()
downlink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG
@@ -724,19 +729,23 @@
self.log.debug('openolt-agent-flow', downstream_flow=downstream_flow)
- downstream_logical_flow = ofp_flow_stats(
- id=logical_flow.id, cookie=logical_flow.cookie,
- table_id=logical_flow.table_id, priority=logical_flow.priority,
- flags=logical_flow.flags)
+ try:
+ downstream_logical_flow = ofp_flow_stats(
+ id=logical_flow.id, cookie=logical_flow.cookie,
+ table_id=logical_flow.table_id, priority=logical_flow.priority,
+ flags=logical_flow.flags)
- downstream_logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([
- fd.in_port(fd.get_out_port(logical_flow)),
- fd.vlan_vid(special_vlan_downstream_flow | 0x1000)]))
- downstream_logical_flow.match.type = OFPMT_OXM
+ downstream_logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([
+ fd.in_port(fd.get_out_port(logical_flow)),
+ fd.vlan_vid(special_vlan_downstream_flow | 0x1000)]))
+ downstream_logical_flow.match.type = OFPMT_OXM
- downstream_logical_flow.instructions.extend(
- fd.mk_instructions_from_actions([fd.output(
- self.platform.mk_uni_port_num(intf_id, onu_id, uni_id))]))
+ downstream_logical_flow.instructions.extend(
+ fd.mk_instructions_from_actions([fd.output(
+ self.platform.mk_uni_port_num(intf_id, onu_id, uni_id))]))
+ except Exception as e:
+ self.log.exception("unexpected-error-building-downstream-logical-flow", intf_id=intf_id, onu_id=onu_id,
+ uni_id=uni_id, e=e, downstream_flow=downstream_flow)
if self.add_flow_to_device(downstream_flow, downstream_logical_flow):
self.log.debug('added-eapol-openolt-agent-flow', downstream_flow=downstream_flow,
@@ -930,6 +939,8 @@
logical_flow=logical_flow, flow=flow,
grpc_error=grpc_e)
return False
+ except Exception as f:
+ self.log.exception("unexpected-openolt-agent-error", flow=flow, logical_flow=logical_flow, f=f)
else:
# TODO NEW CORE: Should not need. Core keeps track of logical flows. no need to keep track. verify, especially olt reboot!
# self.register_flow(logical_flow, flow)
diff --git a/python/adapters/openolt/openolt_platform.py b/python/adapters/openolt/openolt_platform.py
index a52d653..9f63af0 100644
--- a/python/adapters/openolt/openolt_platform.py
+++ b/python/adapters/openolt/openolt_platform.py
@@ -114,7 +114,7 @@
if intf_type is Port.ETHERNET_NNI:
return (0x1 << 16) | intf_id
elif intf_type is Port.PON_OLT:
- return 0x2 << 28 | intf_id
+ return (0x2 << 28) | intf_id
else:
raise Exception('Invalid port type')