Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2017 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | """ |
| 18 | Broadcom OpenOMCI OLT/ONU adapter handler. |
| 19 | """ |
| 20 | |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 21 | from __future__ import absolute_import |
| 22 | import six |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 23 | import arrow |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 24 | import structlog |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 25 | import json |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 26 | import random |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 27 | |
| 28 | from collections import OrderedDict |
| 29 | |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 30 | from twisted.internet import reactor |
| 31 | from twisted.internet.defer import DeferredQueue, inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 32 | |
| 33 | from heartbeat import HeartBeat |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 34 | from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent |
| 35 | from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics |
| 36 | from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics |
| 37 | from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 38 | |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 39 | import pyvoltha.common.openflow.utils as fd |
| 40 | from pyvoltha.common.utils.registry import registry |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 41 | from pyvoltha.adapters.common.frameio.frameio import hexify |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 42 | from pyvoltha.common.utils.nethelpers import mac_str_to_tuple |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 43 | from pyvoltha.common.config.config_backend import ConsulStore |
| 44 | from pyvoltha.common.config.config_backend import EtcdStore |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 45 | from voltha_protos.logical_device_pb2 import LogicalPort |
William Kurkian | 8235c1e | 2019-03-05 12:58:28 -0500 | [diff] [blame] | 46 | from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 47 | from voltha_protos.device_pb2 import Port |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 48 | from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE, OFPPS_LINK_DOWN, \ |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 49 | OFPPF_FIBER, OFPPF_1GB_FD |
Matt Jeanneret | 3bfebff | 2019-04-12 18:25:03 -0400 | [diff] [blame] | 50 | from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \ |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 51 | InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \ |
| 52 | InterAdapterDeleteTcontMessage |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 53 | from voltha_protos.openolt_pb2 import OnuIndication |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 54 | from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion |
| 55 | from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \ |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 56 | OnuDeviceEntry, IN_SYNC_KEY |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 57 | from omci.brcm_mib_download_task import BrcmMibDownloadTask |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 58 | from omci.brcm_tp_setup_task import BrcmTpSetupTask |
| 59 | from omci.brcm_tp_delete_task import BrcmTpDeleteTask |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 60 | from omci.brcm_uni_lock_task import BrcmUniLockTask |
| 61 | from omci.brcm_vlan_filter_task import BrcmVlanFilterTask |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 62 | from onu_gem_port import OnuGemPort |
| 63 | from onu_tcont import OnuTCont |
| 64 | from pon_port import PonPort |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 65 | from omci.brcm_mcast_task import BrcmMcastTask |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 66 | from uni_port import UniPort, UniType |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 67 | from uni_port import RESERVED_TRANSPARENT_VLAN |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 68 | from pyvoltha.common.tech_profile.tech_profile import TechProfile |
onkarkundargi | aae9971 | 2019-09-23 15:02:52 +0530 | [diff] [blame] | 69 | from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest |
| 70 | from pyvoltha.adapters.extensions.omci.omci_entities import AniG |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 71 | from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 72 | |
| 73 | OP = EntityOperations |
| 74 | RC = ReasonCodes |
| 75 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 76 | IS_MULTICAST='is_multicast' |
| 77 | GEM_PORT_ID = 'gemport_id' |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 78 | _STARTUP_RETRY_WAIT = 10 |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 79 | _PATH_SEPERATOR = "/" |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 80 | |
| 81 | |
| 82 | class BrcmOpenomciOnuHandler(object): |
| 83 | |
| 84 | def __init__(self, adapter, device_id): |
| 85 | self.log = structlog.get_logger(device_id=device_id) |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 86 | self.log.debug('starting-handler') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 87 | self.adapter = adapter |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 88 | self.core_proxy = adapter.core_proxy |
| 89 | self.adapter_proxy = adapter.adapter_proxy |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 90 | self.parent_id = None |
| 91 | self.device_id = device_id |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 92 | self.proxy_address = None |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 93 | self._enabled = False |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 94 | self.events = None |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 95 | self._pm_metrics = None |
| 96 | self._pm_metrics_started = False |
| 97 | self._test_request = None |
| 98 | self._test_request_started = False |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 99 | self._omcc_version = OMCCVersion.Unknown |
| 100 | self._total_tcont_count = 0 # From ANI-G ME |
| 101 | self._qos_flexibility = 0 # From ONT2_G ME |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 102 | self._tp = dict() #tp_id -> technology profile definition in KV Store. |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 103 | self._onu_indication = None |
| 104 | self._unis = dict() # Port # -> UniPort |
| 105 | |
| 106 | self._pon = None |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 107 | self._pon_port_number = 100 |
| 108 | self.logical_device_id = None |
| 109 | |
| 110 | self._heartbeat = HeartBeat.create(self, device_id) |
| 111 | |
| 112 | # Set up OpenOMCI environment |
| 113 | self._onu_omci_device = None |
| 114 | self._dev_info_loaded = False |
| 115 | self._deferred = None |
| 116 | |
| 117 | self._in_sync_subscription = None |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 118 | self._port_state_subscription = None |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 119 | self._connectivity_subscription = None |
| 120 | self._capabilities_subscription = None |
| 121 | |
| 122 | self.mac_bridge_service_profile_entity_id = 0x201 |
| 123 | self.gal_enet_profile_entity_id = 0x1 |
| 124 | |
| 125 | self._tp_service_specific_task = dict() |
| 126 | self._tech_profile_download_done = dict() |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 127 | # Stores information related to queued vlan filter tasks |
| 128 | # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id |
| 129 | |
| 130 | self._queued_vlan_filter_task = dict() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 131 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 132 | self._set_vlan = dict() #uni_id, tp_id -> set_vlan_id |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 133 | # Initialize KV store client |
| 134 | self.args = registry('main').get_args() |
| 135 | if self.args.backend == 'etcd': |
| 136 | host, port = self.args.etcd.split(':', 1) |
| 137 | self.kv_client = EtcdStore(host, port, |
| 138 | TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX) |
| 139 | elif self.args.backend == 'consul': |
| 140 | host, port = self.args.consul.split(':', 1) |
| 141 | self.kv_client = ConsulStore(host, port, |
| 142 | TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX) |
| 143 | else: |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 144 | self.log.error('invalid-backend') |
| 145 | raise Exception("invalid-backend-for-kv-store") |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 146 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 147 | @property |
| 148 | def enabled(self): |
| 149 | return self._enabled |
| 150 | |
| 151 | @enabled.setter |
| 152 | def enabled(self, value): |
| 153 | if self._enabled != value: |
| 154 | self._enabled = value |
| 155 | |
| 156 | @property |
| 157 | def omci_agent(self): |
| 158 | return self.adapter.omci_agent |
| 159 | |
| 160 | @property |
| 161 | def omci_cc(self): |
| 162 | return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None |
| 163 | |
| 164 | @property |
| 165 | def heartbeat(self): |
| 166 | return self._heartbeat |
| 167 | |
| 168 | @property |
| 169 | def uni_ports(self): |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 170 | return list(self._unis.values()) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 171 | |
| 172 | def uni_port(self, port_no_or_name): |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 173 | if isinstance(port_no_or_name, six.string_types): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 174 | return next((uni for uni in self.uni_ports |
| 175 | if uni.name == port_no_or_name), None) |
| 176 | |
| 177 | assert isinstance(port_no_or_name, int), 'Invalid parameter type' |
| 178 | return next((uni for uni in self.uni_ports |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 179 | if uni.port_number == port_no_or_name), None) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 180 | |
| 181 | @property |
| 182 | def pon_port(self): |
| 183 | return self._pon |
| 184 | |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 185 | @property |
| 186 | def onu_omci_device(self): |
| 187 | return self._onu_omci_device |
| 188 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 189 | def receive_message(self, msg): |
| 190 | if self.omci_cc is not None: |
| 191 | self.omci_cc.receive_message(msg) |
| 192 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 193 | def get_ofp_port_info(self, device, port_no): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 194 | self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id) |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 195 | cap = OFPPF_1GB_FD | OFPPF_FIBER |
| 196 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 197 | hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' % |
| 198 | ((device.parent_port_no >> 8 & 0xff), |
| 199 | device.parent_port_no & 0xff, |
| 200 | (port_no >> 16) & 0xff, |
| 201 | (port_no >> 8) & 0xff, |
| 202 | port_no & 0xff)) |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 203 | |
Matt Jeanneret | 3b7db44 | 2019-04-22 16:29:48 -0400 | [diff] [blame] | 204 | uni_port = self.uni_port(int(port_no)) |
| 205 | name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num) |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 206 | self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port) |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 207 | |
| 208 | ofstate = OFPPS_LINK_DOWN |
| 209 | if uni_port.operstatus is OperStatus.ACTIVE: |
| 210 | ofstate = OFPPS_LIVE |
Matt Jeanneret | 3b7db44 | 2019-04-22 16:29:48 -0400 | [diff] [blame] | 211 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 212 | return PortCapability( |
| 213 | port=LogicalPort( |
| 214 | ofp_port=ofp_port( |
Matt Jeanneret | 3b7db44 | 2019-04-22 16:29:48 -0400 | [diff] [blame] | 215 | name=name, |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 216 | hw_addr=hw_addr, |
| 217 | config=0, |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 218 | state=ofstate, |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 219 | curr=cap, |
| 220 | advertised=cap, |
| 221 | peer=cap, |
| 222 | curr_speed=OFPPF_1GB_FD, |
| 223 | max_speed=OFPPF_1GB_FD |
| 224 | ), |
| 225 | device_id=device.id, |
| 226 | device_port_no=port_no |
| 227 | ) |
| 228 | ) |
| 229 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 230 | # Called once when the adapter creates the device/onu instance |
Matt Jeanneret | 84e56f6 | 2019-02-26 10:48:09 -0500 | [diff] [blame] | 231 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 232 | def activate(self, device): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 233 | self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 234 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 235 | assert device.parent_id |
Matt Jeanneret | 0c28789 | 2019-02-28 11:48:00 -0500 | [diff] [blame] | 236 | assert device.parent_port_no |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 237 | assert device.proxy_address.device_id |
| 238 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 239 | self.proxy_address = device.proxy_address |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 240 | self.parent_id = device.parent_id |
Matt Jeanneret | 0c28789 | 2019-02-28 11:48:00 -0500 | [diff] [blame] | 241 | self._pon_port_number = device.parent_port_no |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 242 | if self.enabled is not True: |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 243 | self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 244 | # populate what we know. rest comes later after mib sync |
Matt Jeanneret | 0c28789 | 2019-02-28 11:48:00 -0500 | [diff] [blame] | 245 | device.root = False |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 246 | device.vendor = 'OpenONU' |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 247 | device.reason = 'activating-onu' |
| 248 | |
Matt Jeanneret | 84e56f6 | 2019-02-26 10:48:09 -0500 | [diff] [blame] | 249 | # TODO NEW CORE: Need to either get logical device id from core or use regular device id |
Matt Jeanneret | 3b7db44 | 2019-04-22 16:29:48 -0400 | [diff] [blame] | 250 | # pm_metrics requires a logical device id. For now set to just device_id |
| 251 | self.logical_device_id = self.device_id |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 252 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 253 | yield self.core_proxy.device_update(device) |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 254 | self.log.debug('device-updated', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 255 | |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 256 | yield self._init_pon_state() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 257 | |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 258 | self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 259 | ############################################################################ |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 260 | # Setup Alarm handler |
| 261 | self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id, |
| 262 | device.serial_number) |
| 263 | ############################################################################ |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 264 | # Setup PM configuration for this device |
| 265 | # Pass in ONU specific options |
| 266 | kwargs = { |
| 267 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 268 | 'heartbeat': self.heartbeat, |
| 269 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 270 | } |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 271 | self.log.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 272 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 273 | self.logical_device_id, device.serial_number, |
| 274 | grouped=True, freq_override=False, **kwargs) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 275 | pm_config = self._pm_metrics.make_proto() |
| 276 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 277 | self.log.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 278 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 279 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 280 | # Note, ONU ID and UNI intf set in add_uni_port method |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 281 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events, |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 282 | ani_ports=[self._pon]) |
aishwaryarana01 | a98d9fe | 2019-05-08 12:09:06 -0500 | [diff] [blame] | 283 | |
onkarkundargi | aae9971 | 2019-09-23 15:02:52 +0530 | [diff] [blame] | 284 | # Code to Run OMCI Test Action |
| 285 | kwargs_omci_test_action = { |
| 286 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 287 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 288 | } |
| 289 | serial_number = device.serial_number |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 290 | self._test_request = OmciTestRequest(self.core_proxy, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 291 | self.omci_agent, self.device_id, |
| 292 | AniG, serial_number, |
| 293 | self.logical_device_id, |
| 294 | exclusive=False, |
| 295 | **kwargs_omci_test_action) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 296 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 297 | self.enabled = True |
| 298 | else: |
| 299 | self.log.info('onu-already-activated') |
| 300 | |
| 301 | # Called once when the adapter needs to re-create device. usually on vcore restart |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 302 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 303 | def reconcile(self, device): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 304 | self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 305 | |
| 306 | # first we verify that we got parent reference and proxy info |
| 307 | assert device.parent_id |
| 308 | assert device.proxy_address.device_id |
| 309 | |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 310 | self.proxy_address = device.proxy_address |
| 311 | self.parent_id = device.parent_id |
| 312 | self._pon_port_number = device.parent_port_no |
| 313 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 314 | if self.enabled is not True: |
| 315 | self.log.info('reconciling-broadcom-onu-device') |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 316 | self.logical_device_id = self.device_id |
| 317 | self._init_pon_state() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 318 | |
| 319 | # need to restart state machines on vcore restart. there is no indication to do it for us. |
| 320 | self._onu_omci_device.start() |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 321 | yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci") |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 322 | |
| 323 | # TODO: this is probably a bit heavy handed |
| 324 | # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away |
| 325 | # This may not be necessary when mib resync actually works |
| 326 | reactor.callLater(1, self.reboot) |
| 327 | |
| 328 | self.enabled = True |
| 329 | else: |
| 330 | self.log.info('onu-already-activated') |
| 331 | |
| 332 | @inlineCallbacks |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 333 | def _init_pon_state(self): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 334 | self.log.debug('init-pon-state', device_id=self.device_id, device_logical_id=self.logical_device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 335 | |
| 336 | self._pon = PonPort.create(self, self._pon_port_number) |
Matt Jeanneret | 0c28789 | 2019-02-28 11:48:00 -0500 | [diff] [blame] | 337 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 338 | self.log.debug('adding-pon-port-to-agent', |
| 339 | type=self._pon.get_port().type, |
| 340 | admin_state=self._pon.get_port().admin_state, |
| 341 | oper_status=self._pon.get_port().oper_status, |
| 342 | ) |
Matt Jeanneret | 0c28789 | 2019-02-28 11:48:00 -0500 | [diff] [blame] | 343 | |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 344 | yield self.core_proxy.port_created(self.device_id, self._pon.get_port()) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 345 | |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 346 | self.log.debug('added-pon-port-to-agent', |
| 347 | type=self._pon.get_port().type, |
| 348 | admin_state=self._pon.get_port().admin_state, |
| 349 | oper_status=self._pon.get_port().oper_status, |
| 350 | ) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 351 | |
| 352 | # Create and start the OpenOMCI ONU Device Entry for this ONU |
| 353 | self._onu_omci_device = self.omci_agent.add_device(self.device_id, |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 354 | self.core_proxy, |
| 355 | self.adapter_proxy, |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 356 | support_classes=self.adapter.broadcom_omci, |
| 357 | custom_me_map=self.adapter.custom_me_entities()) |
| 358 | # Port startup |
| 359 | if self._pon is not None: |
| 360 | self._pon.enabled = True |
| 361 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 362 | def delete(self, device): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 363 | self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | 42dad79 | 2020-02-01 09:28:27 -0500 | [diff] [blame] | 364 | |
| 365 | self._deferred.cancel() |
| 366 | self._test_request.stop_collector() |
| 367 | self._pm_metrics.stop_collector() |
| 368 | self.log.debug('removing-openomci-statemachine') |
| 369 | self.omci_agent.remove_device(device.id, cleanup=True) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 370 | |
| 371 | def _create_tconts(self, uni_id, us_scheduler): |
| 372 | alloc_id = us_scheduler['alloc_id'] |
| 373 | q_sched_policy = us_scheduler['q_sched_policy'] |
| 374 | self.log.debug('create-tcont', us_scheduler=us_scheduler) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 375 | # TODO: revisit for multi tconts support |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 376 | new_tconts = [] |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 377 | tcontdict = dict() |
| 378 | tcontdict['alloc-id'] = alloc_id |
| 379 | tcontdict['q_sched_policy'] = q_sched_policy |
| 380 | tcontdict['uni_id'] = uni_id |
| 381 | |
Matt Jeanneret | 3789d0d | 2020-01-19 09:03:42 -0500 | [diff] [blame] | 382 | tcont = OnuTCont.create(self, tcont=tcontdict) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 383 | |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame^] | 384 | success = self._pon.add_tcont(tcont) |
| 385 | if success: |
| 386 | new_tconts.append(tcont) |
| 387 | self.log.debug('pon-add-tcont', tcont=tcont) |
| 388 | |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 389 | return new_tconts |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 390 | |
| 391 | # Called when there is an olt up indication, providing the gem port id chosen by the olt handler |
| 392 | def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction): |
| 393 | self.log.debug('create-gemport', |
| 394 | gem_ports=gem_ports, direction=direction) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 395 | new_gem_ports = [] |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 396 | for gem_port in gem_ports: |
| 397 | gemdict = dict() |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 398 | if gem_port[IS_MULTICAST] == 'True': |
| 399 | gemdict[GEM_PORT_ID] = gem_port['multicast_gem_id'] |
| 400 | gemdict[IS_MULTICAST] = True |
| 401 | else: |
| 402 | gemdict[GEM_PORT_ID] = gem_port[GEM_PORT_ID] |
| 403 | gemdict[IS_MULTICAST] = False |
| 404 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 405 | gemdict['direction'] = direction |
| 406 | gemdict['alloc_id_ref'] = alloc_id_ref |
| 407 | gemdict['encryption'] = gem_port['aes_encryption'] |
| 408 | gemdict['discard_config'] = dict() |
| 409 | gemdict['discard_config']['max_probability'] = \ |
| 410 | gem_port['discard_config']['max_probability'] |
| 411 | gemdict['discard_config']['max_threshold'] = \ |
| 412 | gem_port['discard_config']['max_threshold'] |
| 413 | gemdict['discard_config']['min_threshold'] = \ |
| 414 | gem_port['discard_config']['min_threshold'] |
| 415 | gemdict['discard_policy'] = gem_port['discard_policy'] |
| 416 | gemdict['max_q_size'] = gem_port['max_q_size'] |
| 417 | gemdict['pbit_map'] = gem_port['pbit_map'] |
| 418 | gemdict['priority_q'] = gem_port['priority_q'] |
| 419 | gemdict['scheduling_policy'] = gem_port['scheduling_policy'] |
| 420 | gemdict['weight'] = gem_port['weight'] |
| 421 | gemdict['uni_id'] = uni_id |
| 422 | |
| 423 | gem_port = OnuGemPort.create(self, gem_port=gemdict) |
| 424 | |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame^] | 425 | success = self._pon.add_gem_port(gem_port, True) |
| 426 | if success: |
| 427 | new_gem_ports.append(gem_port) |
| 428 | self.log.debug('pon-add-gemport', gem_port=gem_port) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 429 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 430 | return new_gem_ports |
| 431 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 432 | def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id): |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 433 | # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter |
| 434 | # task is scheduled even before tp task. So we queue vlan-filter task if tp_task |
| 435 | # or initial-mib-download is not done. Once the tp_task is completed, we execute |
| 436 | # such queued vlan-filter tasks |
| 437 | try: |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 438 | if uni_id in self._queued_vlan_filter_task and tp_id in self._queued_vlan_filter_task[uni_id]: |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 439 | self.log.info("executing-queued-vlan-filter-task", |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 440 | uni_id=uni_id, tp_id=tp_id) |
Mahir Gunyel | a982ec3 | 2020-02-25 12:30:37 -0800 | [diff] [blame] | 441 | for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]: |
| 442 | reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"), |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 443 | uni_id=uni_id, uni_port=filter_info.get("uni_port"), |
| 444 | match_vlan=filter_info.get("match_vlan"), |
| 445 | _set_vlan_vid=filter_info.get("set_vlan_vid"), |
| 446 | _set_vlan_pcp=filter_info.get("set_vlan_pcp"), |
| 447 | tp_id=filter_info.get("tp_id")) |
Girish Gowdra | af98a08 | 2020-03-05 16:40:51 -0800 | [diff] [blame] | 448 | # Now remove the entry from the dictionary |
| 449 | self._queued_vlan_filter_task[uni_id][tp_id].remove(filter_info) |
| 450 | self.log.debug("executed-queued-vlan-filter-task", |
| 451 | uni_id=uni_id, tp_id=tp_id) |
| 452 | # Now delete the key entries once we have handled the queued vlan filter tasks. |
| 453 | del self._queued_vlan_filter_task[uni_id] |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 454 | except Exception as e: |
| 455 | self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e) |
| 456 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 457 | def _do_tech_profile_configuration(self, uni_id, tp): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 458 | us_scheduler = tp['us_scheduler'] |
| 459 | alloc_id = us_scheduler['alloc_id'] |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 460 | new_tconts = self._create_tconts(uni_id, us_scheduler) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 461 | upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list'] |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 462 | new_upstream_gems = self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM") |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 463 | downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list'] |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 464 | new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM") |
| 465 | |
| 466 | new_gems = [] |
| 467 | new_gems.extend(new_upstream_gems) |
| 468 | new_gems.extend(new_downstream_gems) |
| 469 | |
| 470 | return new_tconts, new_gems |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 471 | |
| 472 | def load_and_configure_tech_profile(self, uni_id, tp_path): |
| 473 | self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path) |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 474 | tp_id = self.extract_tp_id_from_path(tp_path) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 475 | if uni_id not in self._tp_service_specific_task: |
| 476 | self._tp_service_specific_task[uni_id] = dict() |
| 477 | |
| 478 | if uni_id not in self._tech_profile_download_done: |
| 479 | self._tech_profile_download_done[uni_id] = dict() |
| 480 | |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 481 | if tp_id not in self._tech_profile_download_done[uni_id]: |
| 482 | self._tech_profile_download_done[uni_id][tp_id] = False |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 483 | |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 484 | if not self._tech_profile_download_done[uni_id][tp_id]: |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 485 | try: |
| 486 | if tp_path in self._tp_service_specific_task[uni_id]: |
| 487 | self.log.info("tech-profile-config-already-in-progress", |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 488 | tp_path=tp_path) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 489 | return |
| 490 | |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 491 | tpstored = self.kv_client[tp_path] |
| 492 | tpstring = tpstored.decode('ascii') |
| 493 | tp = json.loads(tpstring) |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 494 | self._tp[tp_id] = tp |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 495 | self.log.debug("tp-instance", tp=tp) |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 496 | tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp) |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 497 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 498 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 499 | def success(_results): |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 500 | self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 501 | if tp_path in self._tp_service_specific_task[uni_id]: |
| 502 | del self._tp_service_specific_task[uni_id][tp_path] |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 503 | self._tech_profile_download_done[uni_id][tp_id] = True |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 504 | # Now execute any vlan filter tasks that were queued for later |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 505 | reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 506 | yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success') |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 507 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 508 | # Execute mcast task |
| 509 | for gem in gem_ports: |
| 510 | self.log.debug("checking-multicast-service-for-gem ", gem=gem) |
| 511 | if gem.mcast is True: |
| 512 | self.log.info("found-multicast-service-for-gem ", gem=gem, uni_id=uni_id, tp_id=tp_id) |
| 513 | reactor.callInThread(self.start_multicast_service, uni_id, tp_path) |
| 514 | self.log.debug("started_multicast_service-successfully", tconts=tconts, gems=gem_ports) |
| 515 | break |
| 516 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 517 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 518 | def failure(_reason): |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 519 | self.log.warn('tech-profile-config-failure-retrying', uni_id=uni_id, tp_id=tp_id, |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 520 | _reason=_reason) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 521 | if tp_path in self._tp_service_specific_task[uni_id]: |
| 522 | del self._tp_service_specific_task[uni_id][tp_path] |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 523 | retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 524 | reactor.callLater(retry, self.load_and_configure_tech_profile, |
| 525 | uni_id, tp_path) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 526 | yield self.core_proxy.device_reason_update(self.device_id, |
| 527 | 'tech-profile-config-download-failure-retrying') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 528 | |
Mahir Gunyel | a982ec3 | 2020-02-25 12:30:37 -0800 | [diff] [blame] | 529 | self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 530 | self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports) |
| 531 | |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame^] | 532 | self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values())) |
| 533 | self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values())) |
| 534 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 535 | self._tp_service_specific_task[uni_id][tp_path] = \ |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 536 | BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 537 | self._deferred = \ |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 538 | self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path]) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 539 | self._deferred.addCallbacks(success, failure) |
| 540 | |
| 541 | except Exception as e: |
| 542 | self.log.exception("error-loading-tech-profile", e=e) |
| 543 | else: |
| 544 | self.log.info("tech-profile-config-already-done") |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 545 | # Could be a case where TP exists but new gem-ports are getting added dynamically |
| 546 | tpstored = self.kv_client[tp_path] |
| 547 | tpstring = tpstored.decode('ascii') |
| 548 | tp = json.loads(tpstring) |
| 549 | upstream_gems = [] |
| 550 | downstream_gems = [] |
| 551 | # Find out the new Gem ports that are getting added afresh. |
| 552 | for gp in tp['upstream_gem_port_attribute_list']: |
| 553 | if self.pon_port.gem_port(gp['gemport_id'], "upstream"): |
| 554 | # gem port already exists |
| 555 | continue |
| 556 | upstream_gems.append(gp) |
| 557 | for gp in tp['downstream_gem_port_attribute_list']: |
| 558 | if self.pon_port.gem_port(gp['gemport_id'], "downstream"): |
| 559 | # gem port already exists |
| 560 | continue |
| 561 | downstream_gems.append(gp) |
| 562 | |
| 563 | us_scheduler = tp['us_scheduler'] |
| 564 | alloc_id = us_scheduler['alloc_id'] |
| 565 | |
| 566 | if len(upstream_gems) > 0 or len(downstream_gems) > 0: |
| 567 | self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems) |
| 568 | new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM") |
| 569 | new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM") |
| 570 | new_gems = [] |
| 571 | new_gems.extend(new_upstream_gems) |
| 572 | new_gems.extend(new_downstream_gems) |
| 573 | |
| 574 | def success(_results): |
| 575 | self.log.info("new-gem-ports-successfully-installed", result=_results) |
| 576 | |
| 577 | def failure(_reason): |
| 578 | self.log.warn('new-gem-port-install-failed--retrying', |
| 579 | _reason=_reason) |
| 580 | # Remove gem ports from cache. We will re-add them during the retry |
| 581 | for gp in new_gems: |
| 582 | self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False) |
| 583 | |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 584 | retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 585 | reactor.callLater(retry, self.load_and_configure_tech_profile, |
| 586 | uni_id, tp_path) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 587 | |
| 588 | self._tp_service_specific_task[uni_id][tp_path] = \ |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 589 | BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 590 | self._deferred = \ |
| 591 | self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path]) |
| 592 | self._deferred.addCallbacks(success, failure) |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 593 | def start_multicast_service(self, uni_id, tp_path,retry_count=0): |
| 594 | self.log.debug("starting-multicast-service", uni_id=uni_id, tp_path=tp_path) |
| 595 | tp_id = self.extract_tp_id_from_path(tp_path) |
| 596 | if uni_id in self._set_vlan and tp_id in self._set_vlan[uni_id]: |
| 597 | try: |
| 598 | tp = self._tp[tp_id] |
| 599 | if tp is None: |
| 600 | tpstored = self.kv_client[tp_path] |
| 601 | tpstring = tpstored.decode('ascii') |
| 602 | tp = json.loads(tpstring) |
| 603 | if tp is None: |
| 604 | self.log.error("cannot-find-tp-to-start-multicast-service", uni_id=uni_id, tp_path=tp_path) |
| 605 | return |
| 606 | else: |
| 607 | self._tp[tp_id] = tp |
| 608 | |
| 609 | self.log.debug("mcast-vlan-learned-before", self._set_vlan[uni_id][tp_id], uni_id=uni_id, tp_id=tp_id) |
| 610 | def success(_results): |
| 611 | self.log.debug('multicast-success', uni_id=uni_id) |
| 612 | self._multicast_task = None |
| 613 | |
| 614 | def failure(_reason): |
| 615 | self.log.warn('multicast-failure', _reason=_reason) |
| 616 | retry = _STARTUP_RETRY_WAIT * (random.randint(1,5)) |
| 617 | reactor.callLater(retry, self.start_multicast_service, |
| 618 | uni_id, tp_path) |
| 619 | |
| 620 | self.log.debug('starting-multicast-task', mcast_vlan_id=self._set_vlan[uni_id][tp_id]) |
| 621 | downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list'] |
| 622 | for i in range(len(downstream_gem_port_attribute_list)): |
| 623 | if IS_MULTICAST in downstream_gem_port_attribute_list[i] and \ |
| 624 | downstream_gem_port_attribute_list[i][IS_MULTICAST] == 'True': |
| 625 | dynamic_access_control_list_table = downstream_gem_port_attribute_list[i]['dynamic_access_control_list'].split("-") |
| 626 | static_access_control_list_table = downstream_gem_port_attribute_list[i]['static_access_control_list'].split("-") |
| 627 | multicast_gem_id = downstream_gem_port_attribute_list[i]['multicast_gem_id'] |
| 628 | break |
| 629 | |
| 630 | self._multicast_task = BrcmMcastTask(self.omci_agent, self, self.device_id, uni_id, tp_id, |
| 631 | self._set_vlan[uni_id][tp_id],dynamic_access_control_list_table, static_access_control_list_table, multicast_gem_id) |
| 632 | self._deferred = self._onu_omci_device.task_runner.queue_task(self._multicast_task) |
| 633 | self._deferred.addCallbacks(success, failure) |
| 634 | except Exception as e: |
| 635 | self.log.exception("error-loading-multicast", e=e) |
| 636 | else: |
| 637 | if retry_count<30: |
| 638 | retry_count = +1 |
| 639 | self.log.debug("going-to-wait-for-flow-to-learn-mcast-vlan", uni_id=uni_id, tp_id=tp_id, retry=retry_count) |
| 640 | reactor.callLater(0.5, self.start_multicast_service, uni_id, tp_path, retry_count) |
| 641 | else: |
| 642 | self.log.error("mcast-vlan-not-configured-yet-failing-mcast-service-conf", uni_id=uni_id, tp_id=tp_id, retry=retry_count) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 643 | |
| 644 | def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None): |
| 645 | try: |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 646 | tp_table_id = self.extract_tp_id_from_path(tp_path) |
Naga Manjunath | e433c71 | 2020-01-02 17:27:20 +0530 | [diff] [blame] | 647 | if not uni_id in self._tech_profile_download_done: |
| 648 | self.log.warn("tp-key-is-not-present", uni_id=uni_id) |
| 649 | return |
| 650 | |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 651 | if not tp_table_id in self._tech_profile_download_done[uni_id]: |
| 652 | self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id) |
Naga Manjunath | e433c71 | 2020-01-02 17:27:20 +0530 | [diff] [blame] | 653 | return |
| 654 | |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 655 | if self._tech_profile_download_done[uni_id][tp_table_id] is not True: |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 656 | self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete", uni_id=uni_id, |
| 657 | tp_id=tp_table_id) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 658 | return |
| 659 | |
| 660 | if alloc_id is None and gem_port_id is None: |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 661 | self.log.error("alloc-id-and-gem-port-id-are-none", uni_id=uni_id, tp_id=tp_table_id) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 662 | return |
| 663 | |
| 664 | # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are |
| 665 | # relevant to this task's UNI. It won't change. But, the underlying pon_port may change |
| 666 | # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter |
| 667 | # this initializer |
| 668 | tcont = None |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame^] | 669 | self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values())) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 670 | for tc in list(self.pon_port.tconts.values()): |
| 671 | if tc.alloc_id == alloc_id: |
| 672 | tcont = tc |
| 673 | self.pon_port.remove_tcont(tc.alloc_id, False) |
| 674 | |
| 675 | gem_port = None |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame^] | 676 | self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values())) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 677 | for gp in list(self.pon_port.gem_ports.values()): |
| 678 | if gp.gem_id == gem_port_id: |
| 679 | gem_port = gp |
| 680 | self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False) |
| 681 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 682 | @inlineCallbacks |
| 683 | def success(_results): |
| 684 | if gem_port_id: |
| 685 | self.log.info("gem-port-delete-done-successfully") |
| 686 | if alloc_id: |
| 687 | self.log.info("tcont-delete-done-successfully") |
| 688 | # The deletion of TCONT marks the complete deletion of tech-profile |
| 689 | try: |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 690 | del self._tech_profile_download_done[uni_id][tp_table_id] |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 691 | del self._tp_service_specific_task[uni_id][tp_path] |
| 692 | except Exception as ex: |
| 693 | self.log.error("del-tp-state-info", e=ex) |
| 694 | |
| 695 | # TODO: There could be multiple TP on the UNI, and also the ONU. |
| 696 | # TODO: But the below reason updates for the whole device. |
| 697 | yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success') |
| 698 | |
| 699 | @inlineCallbacks |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 700 | def failure(_reason): |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 701 | self.log.warn('tech-profile-delete-failure-retrying', |
| 702 | _reason=_reason) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 703 | retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 704 | reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 705 | yield self.core_proxy.device_reason_update(self.device_id, |
| 706 | 'tech-profile-config-delete-failure-retrying') |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 707 | |
| 708 | self.log.info('deleting-tech-profile-configuration') |
| 709 | |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 710 | if tcont is None and gem_port is None: |
| 711 | if alloc_id is not None: |
| 712 | self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id) |
| 713 | if gem_port_id is not None: |
| 714 | self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id) |
| 715 | return |
| 716 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 717 | self._tp_service_specific_task[uni_id][tp_path] = \ |
| 718 | BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id, |
| 719 | tcont=tcont, gem_port=gem_port) |
| 720 | self._deferred = \ |
| 721 | self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path]) |
| 722 | self._deferred.addCallbacks(success, failure) |
| 723 | except Exception as e: |
| 724 | self.log.exception("failed-to-delete-tp", |
| 725 | e=e, uni_id=uni_id, tp_path=tp_path, |
| 726 | alloc_id=alloc_id, gem_port_id=gem_port_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 727 | |
| 728 | def update_pm_config(self, device, pm_config): |
| 729 | # TODO: This has not been tested |
| 730 | self.log.info('update_pm_config', pm_config=pm_config) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 731 | self._pm_metrics.update(pm_config) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 732 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 733 | def remove_onu_flows(self, device, flows): |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame^] | 734 | self.log.debug('remove-onu-flows') |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 735 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 736 | # no point in removing omci flows if the device isnt reachable |
| 737 | if device.connect_status != ConnectStatus.REACHABLE or \ |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 738 | device.admin_state != AdminState.ENABLED: |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 739 | self.log.warn("device-disabled-or-offline-skipping-remove-flow", |
| 740 | admin=device.admin_state, connect=device.connect_status) |
| 741 | return |
| 742 | |
| 743 | for flow in flows: |
| 744 | # if incoming flow contains cookie, then remove from ONU |
| 745 | if flow.cookie: |
| 746 | self.log.debug("remove-flow", device_id=device.id, flow=flow) |
| 747 | |
| 748 | def is_downstream(port): |
| 749 | return port == self._pon_port_number |
| 750 | |
| 751 | def is_upstream(port): |
| 752 | return not is_downstream(port) |
| 753 | |
| 754 | try: |
| 755 | _in_port = fd.get_in_port(flow) |
| 756 | assert _in_port is not None |
| 757 | |
| 758 | _out_port = fd.get_out_port(flow) # may be None |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 759 | |
| 760 | if is_downstream(_in_port): |
| 761 | self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port, |
| 762 | device_id=device.id) |
| 763 | # extended vlan tagging operation will handle it |
| 764 | continue |
| 765 | elif is_upstream(_in_port): |
| 766 | self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port) |
| 767 | if fd.is_dhcp_flow(flow): |
| 768 | self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id) |
| 769 | return |
| 770 | |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 771 | _vlan_vid = 0 |
| 772 | # Retrieve the VLAN_VID that needs to be removed from the EVTO rule on the ONU. |
| 773 | for action in fd.get_actions(flow): |
| 774 | if action.type == fd.SET_FIELD: |
| 775 | _field = action.set_field.field.ofb_field |
| 776 | assert (action.set_field.field.oxm_class == |
| 777 | OFPXMC_OPENFLOW_BASIC) |
| 778 | if _field.type == fd.VLAN_VID: |
| 779 | _vlan_vid = _field.vlan_vid & 0xfff |
| 780 | self.log.debug('vlan-vid-to-remove', |
| 781 | _vlan_vid=_vlan_vid, in_port=_in_port) |
| 782 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 783 | uni_port = self.uni_port(_in_port) |
| 784 | uni_id = _in_port & 0xF |
| 785 | else: |
| 786 | raise Exception('port should be 1 or 2 by our convention') |
| 787 | |
| 788 | self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port)) |
| 789 | |
| 790 | tp_id = self.get_tp_id_in_flow(flow) |
| 791 | # Deleting flow from ONU. |
| 792 | self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 793 | match_vlan=_vlan_vid, tp_id=tp_id) |
| 794 | # TODO:Delete TD task. |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 795 | except Exception as e: |
| 796 | self.log.exception('failed-to-remove-flow', e=e) |
| 797 | |
| 798 | def add_onu_flows(self, device, flows): |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame^] | 799 | self.log.debug('add-onu-flows') |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 800 | |
| 801 | # no point in pushing omci flows if the device isnt reachable |
| 802 | if device.connect_status != ConnectStatus.REACHABLE or \ |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 803 | device.admin_state != AdminState.ENABLED: |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 804 | self.log.warn("device-disabled-or-offline-skipping-flow-update", |
| 805 | admin=device.admin_state, connect=device.connect_status) |
| 806 | return |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 807 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 808 | def is_downstream(port): |
| 809 | return port == self._pon_port_number |
| 810 | |
| 811 | def is_upstream(port): |
| 812 | return not is_downstream(port) |
| 813 | |
| 814 | for flow in flows: |
| 815 | # if incoming flow contains cookie, then add to ONU |
| 816 | if flow.cookie: |
| 817 | _type = None |
| 818 | _port = None |
| 819 | _vlan_vid = None |
| 820 | _udp_dst = None |
| 821 | _udp_src = None |
| 822 | _ipv4_dst = None |
| 823 | _ipv4_src = None |
| 824 | _metadata = None |
| 825 | _output = None |
| 826 | _push_tpid = None |
| 827 | _field = None |
| 828 | _set_vlan_vid = None |
| 829 | _set_vlan_pcp = 0 |
| 830 | _tunnel_id = None |
| 831 | self.log.debug("add-flow", device_id=device.id, flow=flow) |
| 832 | |
| 833 | try: |
| 834 | _in_port = fd.get_in_port(flow) |
| 835 | assert _in_port is not None |
| 836 | |
| 837 | _out_port = fd.get_out_port(flow) # may be None |
| 838 | tp_id = self.get_tp_id_in_flow(flow) |
| 839 | if is_downstream(_in_port): |
| 840 | self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port) |
| 841 | # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow |
| 842 | # uni_port = self.uni_port(_out_port) |
| 843 | # uni_id = _out_port & 0xF |
| 844 | continue |
| 845 | elif is_upstream(_in_port): |
| 846 | self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port) |
| 847 | uni_port = self.uni_port(_in_port) |
| 848 | uni_id = _in_port & 0xF |
| 849 | else: |
| 850 | raise Exception('port should be 1 or 2 by our convention') |
| 851 | |
| 852 | self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port)) |
| 853 | |
| 854 | for field in fd.get_ofb_fields(flow): |
| 855 | if field.type == fd.ETH_TYPE: |
| 856 | _type = field.eth_type |
| 857 | self.log.debug('field-type-eth-type', |
| 858 | eth_type=_type) |
| 859 | |
| 860 | elif field.type == fd.IP_PROTO: |
| 861 | _proto = field.ip_proto |
| 862 | self.log.debug('field-type-ip-proto', |
| 863 | ip_proto=_proto) |
| 864 | |
| 865 | elif field.type == fd.IN_PORT: |
| 866 | _port = field.port |
| 867 | self.log.debug('field-type-in-port', |
| 868 | in_port=_port) |
| 869 | elif field.type == fd.TUNNEL_ID: |
| 870 | self.log.debug('field-type-tunnel-id') |
| 871 | |
| 872 | elif field.type == fd.VLAN_VID: |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 873 | if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN: |
| 874 | _vlan_vid = RESERVED_TRANSPARENT_VLAN |
| 875 | else: |
| 876 | _vlan_vid = field.vlan_vid & 0xfff |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 877 | self.log.debug('field-type-vlan-vid', |
| 878 | vlan=_vlan_vid) |
| 879 | |
| 880 | elif field.type == fd.VLAN_PCP: |
| 881 | _vlan_pcp = field.vlan_pcp |
| 882 | self.log.debug('field-type-vlan-pcp', |
| 883 | pcp=_vlan_pcp) |
| 884 | |
| 885 | elif field.type == fd.UDP_DST: |
| 886 | _udp_dst = field.udp_dst |
| 887 | self.log.debug('field-type-udp-dst', |
| 888 | udp_dst=_udp_dst) |
| 889 | |
| 890 | elif field.type == fd.UDP_SRC: |
| 891 | _udp_src = field.udp_src |
| 892 | self.log.debug('field-type-udp-src', |
| 893 | udp_src=_udp_src) |
| 894 | |
| 895 | elif field.type == fd.IPV4_DST: |
| 896 | _ipv4_dst = field.ipv4_dst |
| 897 | self.log.debug('field-type-ipv4-dst', |
| 898 | ipv4_dst=_ipv4_dst) |
| 899 | |
| 900 | elif field.type == fd.IPV4_SRC: |
| 901 | _ipv4_src = field.ipv4_src |
| 902 | self.log.debug('field-type-ipv4-src', |
| 903 | ipv4_dst=_ipv4_src) |
| 904 | |
| 905 | elif field.type == fd.METADATA: |
| 906 | _metadata = field.table_metadata |
| 907 | self.log.debug('field-type-metadata', |
| 908 | metadata=_metadata) |
| 909 | |
| 910 | else: |
| 911 | raise NotImplementedError('field.type={}'.format( |
| 912 | field.type)) |
| 913 | |
| 914 | for action in fd.get_actions(flow): |
| 915 | |
| 916 | if action.type == fd.OUTPUT: |
| 917 | _output = action.output.port |
| 918 | self.log.debug('action-type-output', |
| 919 | output=_output, in_port=_in_port) |
| 920 | |
| 921 | elif action.type == fd.POP_VLAN: |
| 922 | self.log.debug('action-type-pop-vlan', |
| 923 | in_port=_in_port) |
| 924 | |
| 925 | elif action.type == fd.PUSH_VLAN: |
| 926 | _push_tpid = action.push.ethertype |
| 927 | self.log.debug('action-type-push-vlan', |
| 928 | push_tpid=_push_tpid, in_port=_in_port) |
| 929 | if action.push.ethertype != 0x8100: |
| 930 | self.log.error('unhandled-tpid', |
| 931 | ethertype=action.push.ethertype) |
| 932 | |
| 933 | elif action.type == fd.SET_FIELD: |
| 934 | _field = action.set_field.field.ofb_field |
| 935 | assert (action.set_field.field.oxm_class == |
| 936 | OFPXMC_OPENFLOW_BASIC) |
| 937 | self.log.debug('action-type-set-field', |
| 938 | field=_field, in_port=_in_port) |
| 939 | if _field.type == fd.VLAN_VID: |
| 940 | _set_vlan_vid = _field.vlan_vid & 0xfff |
| 941 | self.log.debug('set-field-type-vlan-vid', |
| 942 | vlan_vid=_set_vlan_vid) |
| 943 | elif _field.type == fd.VLAN_PCP: |
| 944 | _set_vlan_pcp = _field.vlan_pcp |
| 945 | self.log.debug('set-field-type-vlan-pcp', |
| 946 | vlan_pcp=_set_vlan_pcp) |
| 947 | else: |
| 948 | self.log.error('unsupported-action-set-field-type', |
| 949 | field_type=_field.type) |
| 950 | else: |
| 951 | self.log.error('unsupported-action-type', |
| 952 | action_type=action.type, in_port=_in_port) |
| 953 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 954 | if self._set_vlan is not None: |
| 955 | if uni_id not in self._set_vlan: |
| 956 | self._set_vlan[uni_id] = dict() |
| 957 | self._set_vlan[uni_id][tp_id] = _set_vlan_vid |
| 958 | self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id) |
| 959 | |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 960 | # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow |
| 961 | # supported match and action criteria cannot be handled by omci and must be ignored. |
| 962 | if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN: |
| 963 | self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid) |
| 964 | elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN: |
| 965 | self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 966 | _set_vlan_vid=_vlan_vid, |
| 967 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 968 | tp_id=tp_id) |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 969 | self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port, |
| 970 | _set_vlan_vid=_vlan_vid, |
| 971 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 972 | tp_id=tp_id) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 973 | else: |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 974 | self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid, |
| 975 | set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 976 | self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port, |
| 977 | _set_vlan_vid=_set_vlan_vid, |
| 978 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 979 | tp_id=tp_id) |
| 980 | |
| 981 | except Exception as e: |
| 982 | self.log.exception('failed-to-install-flow', e=e, flow=flow) |
| 983 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 984 | # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from |
| 985 | # flow decomposition that ultimately comes from onos |
| 986 | def update_flow_table(self, device, flows): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 987 | self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 988 | |
| 989 | # |
| 990 | # We need to proxy through the OLT to get to the ONU |
| 991 | # Configuration from here should be using OMCI |
| 992 | # |
| 993 | # self.log.info('bulk-flow-update', device_id=device.id, flows=flows) |
| 994 | |
| 995 | # no point in pushing omci flows if the device isnt reachable |
| 996 | if device.connect_status != ConnectStatus.REACHABLE or \ |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 997 | device.admin_state != AdminState.ENABLED: |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 998 | self.log.warn("device-disabled-or-offline-skipping-flow-update", |
| 999 | admin=device.admin_state, connect=device.connect_status) |
| 1000 | return |
| 1001 | |
| 1002 | def is_downstream(port): |
| 1003 | return port == self._pon_port_number |
| 1004 | |
| 1005 | def is_upstream(port): |
| 1006 | return not is_downstream(port) |
| 1007 | |
| 1008 | for flow in flows: |
| 1009 | _type = None |
| 1010 | _port = None |
| 1011 | _vlan_vid = None |
| 1012 | _udp_dst = None |
| 1013 | _udp_src = None |
| 1014 | _ipv4_dst = None |
| 1015 | _ipv4_src = None |
| 1016 | _metadata = None |
| 1017 | _output = None |
| 1018 | _push_tpid = None |
| 1019 | _field = None |
| 1020 | _set_vlan_vid = None |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1021 | _set_vlan_pcp = None |
Matt Jeanneret | ef06d0d | 2019-04-27 17:36:53 -0400 | [diff] [blame] | 1022 | _tunnel_id = None |
| 1023 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1024 | try: |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 1025 | write_metadata = fd.get_write_metadata(flow) |
| 1026 | if write_metadata is None: |
| 1027 | self.log.error("do-not-process-flow-without-write-metadata") |
| 1028 | return |
| 1029 | |
| 1030 | # extract tp id from flow |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1031 | tp_id = self.get_tp_id_in_flow(flow) |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 1032 | self.log.debug("tp-id-in-flow", tp_id=tp_id) |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 1033 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1034 | _in_port = fd.get_in_port(flow) |
| 1035 | assert _in_port is not None |
| 1036 | |
| 1037 | _out_port = fd.get_out_port(flow) # may be None |
| 1038 | |
| 1039 | if is_downstream(_in_port): |
| 1040 | self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port) |
| 1041 | uni_port = self.uni_port(_out_port) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1042 | uni_id = _out_port & 0xF |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1043 | elif is_upstream(_in_port): |
| 1044 | self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port) |
| 1045 | uni_port = self.uni_port(_in_port) |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 1046 | uni_id = _in_port & 0xF |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1047 | else: |
| 1048 | raise Exception('port should be 1 or 2 by our convention') |
| 1049 | |
| 1050 | self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port)) |
| 1051 | |
| 1052 | for field in fd.get_ofb_fields(flow): |
| 1053 | if field.type == fd.ETH_TYPE: |
| 1054 | _type = field.eth_type |
| 1055 | self.log.debug('field-type-eth-type', |
| 1056 | eth_type=_type) |
| 1057 | |
| 1058 | elif field.type == fd.IP_PROTO: |
| 1059 | _proto = field.ip_proto |
| 1060 | self.log.debug('field-type-ip-proto', |
| 1061 | ip_proto=_proto) |
| 1062 | |
| 1063 | elif field.type == fd.IN_PORT: |
| 1064 | _port = field.port |
| 1065 | self.log.debug('field-type-in-port', |
| 1066 | in_port=_port) |
| 1067 | |
| 1068 | elif field.type == fd.VLAN_VID: |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1069 | if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN: |
| 1070 | _vlan_vid = RESERVED_TRANSPARENT_VLAN |
| 1071 | else: |
| 1072 | _vlan_vid = field.vlan_vid & 0xfff |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1073 | self.log.debug('field-type-vlan-vid', |
| 1074 | vlan=_vlan_vid) |
| 1075 | |
| 1076 | elif field.type == fd.VLAN_PCP: |
| 1077 | _vlan_pcp = field.vlan_pcp |
| 1078 | self.log.debug('field-type-vlan-pcp', |
| 1079 | pcp=_vlan_pcp) |
| 1080 | |
| 1081 | elif field.type == fd.UDP_DST: |
| 1082 | _udp_dst = field.udp_dst |
| 1083 | self.log.debug('field-type-udp-dst', |
| 1084 | udp_dst=_udp_dst) |
| 1085 | |
| 1086 | elif field.type == fd.UDP_SRC: |
| 1087 | _udp_src = field.udp_src |
| 1088 | self.log.debug('field-type-udp-src', |
| 1089 | udp_src=_udp_src) |
| 1090 | |
| 1091 | elif field.type == fd.IPV4_DST: |
| 1092 | _ipv4_dst = field.ipv4_dst |
| 1093 | self.log.debug('field-type-ipv4-dst', |
| 1094 | ipv4_dst=_ipv4_dst) |
| 1095 | |
| 1096 | elif field.type == fd.IPV4_SRC: |
| 1097 | _ipv4_src = field.ipv4_src |
| 1098 | self.log.debug('field-type-ipv4-src', |
| 1099 | ipv4_dst=_ipv4_src) |
| 1100 | |
| 1101 | elif field.type == fd.METADATA: |
| 1102 | _metadata = field.table_metadata |
| 1103 | self.log.debug('field-type-metadata', |
| 1104 | metadata=_metadata) |
| 1105 | |
Matt Jeanneret | ef06d0d | 2019-04-27 17:36:53 -0400 | [diff] [blame] | 1106 | elif field.type == fd.TUNNEL_ID: |
| 1107 | _tunnel_id = field.tunnel_id |
| 1108 | self.log.debug('field-type-tunnel-id', |
| 1109 | tunnel_id=_tunnel_id) |
| 1110 | |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1111 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1112 | else: |
| 1113 | raise NotImplementedError('field.type={}'.format( |
| 1114 | field.type)) |
| 1115 | |
| 1116 | for action in fd.get_actions(flow): |
| 1117 | |
| 1118 | if action.type == fd.OUTPUT: |
| 1119 | _output = action.output.port |
| 1120 | self.log.debug('action-type-output', |
| 1121 | output=_output, in_port=_in_port) |
| 1122 | |
| 1123 | elif action.type == fd.POP_VLAN: |
| 1124 | self.log.debug('action-type-pop-vlan', |
| 1125 | in_port=_in_port) |
| 1126 | |
| 1127 | elif action.type == fd.PUSH_VLAN: |
| 1128 | _push_tpid = action.push.ethertype |
| 1129 | self.log.debug('action-type-push-vlan', |
| 1130 | push_tpid=_push_tpid, in_port=_in_port) |
| 1131 | if action.push.ethertype != 0x8100: |
| 1132 | self.log.error('unhandled-tpid', |
| 1133 | ethertype=action.push.ethertype) |
| 1134 | |
| 1135 | elif action.type == fd.SET_FIELD: |
| 1136 | _field = action.set_field.field.ofb_field |
| 1137 | assert (action.set_field.field.oxm_class == |
| 1138 | OFPXMC_OPENFLOW_BASIC) |
| 1139 | self.log.debug('action-type-set-field', |
| 1140 | field=_field, in_port=_in_port) |
| 1141 | if _field.type == fd.VLAN_VID: |
| 1142 | _set_vlan_vid = _field.vlan_vid & 0xfff |
| 1143 | self.log.debug('set-field-type-vlan-vid', |
| 1144 | vlan_vid=_set_vlan_vid) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1145 | elif _field.type == fd.VLAN_PCP: |
| 1146 | _set_vlan_pcp = _field.vlan_pcp |
| 1147 | self.log.debug('set-field-type-vlan-pcp', |
| 1148 | vlan_pcp=_set_vlan_pcp) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1149 | else: |
| 1150 | self.log.error('unsupported-action-set-field-type', |
| 1151 | field_type=_field.type) |
| 1152 | else: |
| 1153 | self.log.error('unsupported-action-type', |
| 1154 | action_type=action.type, in_port=_in_port) |
| 1155 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 1156 | if self._set_vlan is not None: |
| 1157 | if uni_id not in self._set_vlan: |
| 1158 | self._set_vlan[uni_id] = dict() |
| 1159 | self._set_vlan[uni_id][tp_id] = _set_vlan_vid |
| 1160 | self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id) |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 1161 | # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow |
| 1162 | # supported match and action criteria cannot be handled by omci and must be ignored. |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1163 | if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN: |
| 1164 | self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid) |
| 1165 | elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN: |
| 1166 | self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1167 | _set_vlan_vid=_vlan_vid, |
| 1168 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 1169 | tp_id=tp_id) |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1170 | self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port, |
| 1171 | _set_vlan_vid=_vlan_vid, |
| 1172 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 1173 | tp_id=tp_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1174 | else: |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1175 | self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid, |
| 1176 | set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type) |
| 1177 | self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port, |
| 1178 | _set_vlan_vid=_set_vlan_vid, |
| 1179 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 1180 | tp_id=tp_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1181 | except Exception as e: |
| 1182 | self.log.exception('failed-to-install-flow', e=e, flow=flow) |
| 1183 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1184 | def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1185 | _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0): |
| 1186 | self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan, |
| 1187 | vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1188 | assert uni_port is not None |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1189 | if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and \ |
| 1190 | self._tech_profile_download_done[uni_id][tp_id] is True: |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 1191 | @inlineCallbacks |
| 1192 | def success(_results): |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1193 | self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id, |
| 1194 | set_vlan_pcp=_set_vlan_pcp) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 1195 | yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1196 | |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 1197 | @inlineCallbacks |
| 1198 | def failure(_reason): |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 1199 | self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1200 | retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 1201 | reactor.callLater(retry, |
| 1202 | self._add_vlan_filter_task, device, uni_id, uni_port=uni_port, |
| 1203 | match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid, |
| 1204 | _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 1205 | yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1206 | |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1207 | self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan, |
| 1208 | vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1209 | vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1210 | match_vlan, _set_vlan_pcp, add_tag=True, |
| 1211 | tp_id=tp_id) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1212 | self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task) |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 1213 | self._deferred.addCallbacks(success, failure) |
| 1214 | else: |
| 1215 | self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache', |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1216 | uni_id=uni_id, tp_id=tp_id) |
| 1217 | if uni_id not in self._queued_vlan_filter_task: |
| 1218 | self._queued_vlan_filter_task[uni_id] = dict() |
Mahir Gunyel | a982ec3 | 2020-02-25 12:30:37 -0800 | [diff] [blame] | 1219 | if tp_id not in self._queued_vlan_filter_task[uni_id]: |
| 1220 | self._queued_vlan_filter_task[uni_id][tp_id] = [] |
| 1221 | self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1222 | "uni_id": uni_id, |
| 1223 | "uni_port": uni_port, |
| 1224 | "match_vlan": match_vlan, |
| 1225 | "set_vlan_vid": _set_vlan_vid, |
| 1226 | "set_vlan_pcp": _set_vlan_pcp, |
| 1227 | "tp_id": tp_id}) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1228 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1229 | def get_tp_id_in_flow(self, flow): |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1230 | flow_metadata = fd.get_metadata_from_write_metadata(flow) |
| 1231 | tp_id = fd.get_tp_id_from_metadata(flow_metadata) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1232 | return tp_id |
| 1233 | |
| 1234 | def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1235 | _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0): |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1236 | assert uni_port is not None |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1237 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1238 | @inlineCallbacks |
| 1239 | def success(_results): |
| 1240 | self.log.info('vlan-untagging-success', _results=_results) |
| 1241 | yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted') |
| 1242 | |
| 1243 | @inlineCallbacks |
| 1244 | def failure(_reason): |
| 1245 | self.log.warn('vlan-untagging-failure', _reason=_reason) |
| 1246 | yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying') |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1247 | retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1248 | reactor.callLater(retry, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1249 | self._remove_vlan_filter_task, device, uni_id, |
| 1250 | add_tag=False, uni_port=uni_port) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1251 | |
| 1252 | self.log.info("remove_vlan_filter_task", tp_id=tp_id) |
| 1253 | vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1254 | match_vlan, _set_vlan_pcp, add_tag=False, |
| 1255 | tp_id=tp_id) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1256 | self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task) |
| 1257 | self._deferred.addCallbacks(success, failure) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1258 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1259 | def process_inter_adapter_message(self, request): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1260 | self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic, |
| 1261 | to_topic=request.header.to_topic, to_device_id=request.header.to_device_id) |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1262 | try: |
| 1263 | if request.header.type == InterAdapterMessageType.OMCI_REQUEST: |
| 1264 | omci_msg = InterAdapterOmciMessage() |
| 1265 | request.body.Unpack(omci_msg) |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1266 | self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message)) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1267 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1268 | self.receive_message(omci_msg.message) |
| 1269 | |
| 1270 | elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST: |
| 1271 | onu_indication = OnuIndication() |
| 1272 | request.body.Unpack(onu_indication) |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1273 | self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id, |
| 1274 | oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state, |
| 1275 | serial_number=onu_indication.serial_number) |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1276 | |
| 1277 | if onu_indication.oper_state == "up": |
| 1278 | self.create_interface(onu_indication) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1279 | elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable": |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1280 | self.update_interface(onu_indication) |
| 1281 | else: |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1282 | self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id, |
| 1283 | serial_number=onu_indication.serial_number) |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1284 | |
Matt Jeanneret | 3bfebff | 2019-04-12 18:25:03 -0400 | [diff] [blame] | 1285 | elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST: |
| 1286 | tech_msg = InterAdapterTechProfileDownloadMessage() |
| 1287 | request.body.Unpack(tech_msg) |
| 1288 | self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg) |
| 1289 | |
| 1290 | self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path) |
| 1291 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1292 | elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST: |
| 1293 | del_gem_msg = InterAdapterDeleteGemPortMessage() |
| 1294 | request.body.Unpack(del_gem_msg) |
| 1295 | self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg) |
| 1296 | |
| 1297 | self.delete_tech_profile(uni_id=del_gem_msg.uni_id, |
| 1298 | gem_port_id=del_gem_msg.gem_port_id, |
| 1299 | tp_path=del_gem_msg.tp_path) |
| 1300 | |
| 1301 | elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST: |
| 1302 | del_tcont_msg = InterAdapterDeleteTcontMessage() |
| 1303 | request.body.Unpack(del_tcont_msg) |
| 1304 | self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg) |
| 1305 | |
| 1306 | self.delete_tech_profile(uni_id=del_tcont_msg.uni_id, |
| 1307 | alloc_id=del_tcont_msg.alloc_id, |
| 1308 | tp_path=del_tcont_msg.tp_path) |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1309 | else: |
| 1310 | self.log.error("inter-adapter-unhandled-type", request=request) |
| 1311 | |
| 1312 | except Exception as e: |
| 1313 | self.log.exception("error-processing-inter-adapter-message", e=e) |
| 1314 | |
| 1315 | # Called each time there is an onu "up" indication from the olt handler |
| 1316 | @inlineCallbacks |
| 1317 | def create_interface(self, onu_indication): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 1318 | self.log.info('create-interface', onu_id=onu_indication.onu_id, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1319 | serial_number=onu_indication.serial_number) |
Amit Ghosh | 028eb20 | 2020-02-17 13:34:00 +0000 | [diff] [blame] | 1320 | |
| 1321 | # Ignore if onu_indication is received for an already running ONU |
| 1322 | if self._onu_omci_device is not None and self._onu_omci_device.active: |
| 1323 | self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication) |
| 1324 | return |
| 1325 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1326 | self._onu_indication = onu_indication |
| 1327 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1328 | yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING, |
| 1329 | connect_status=ConnectStatus.REACHABLE) |
| 1330 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1331 | onu_device = yield self.core_proxy.get_device(self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1332 | |
| 1333 | self.log.debug('starting-openomci-statemachine') |
| 1334 | self._subscribe_to_events() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1335 | onu_device.reason = "starting-openomci" |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1336 | reactor.callLater(1, self._onu_omci_device.start, onu_device) |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1337 | yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1338 | self._heartbeat.enabled = True |
| 1339 | |
Matt Jeanneret | 42dad79 | 2020-02-01 09:28:27 -0500 | [diff] [blame] | 1340 | # Called each time there is an onu "down" indication from the olt handler |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1341 | @inlineCallbacks |
| 1342 | def update_interface(self, onu_indication): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 1343 | self.log.info('update-interface', onu_id=onu_indication.onu_id, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1344 | serial_number=onu_indication.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1345 | |
Chaitrashree G S | d73fb9b | 2019-09-09 20:27:30 -0400 | [diff] [blame] | 1346 | if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable": |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1347 | self.log.debug('stopping-openomci-statemachine', device_id=self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1348 | reactor.callLater(0, self._onu_omci_device.stop) |
| 1349 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 1350 | self._tp = dict() |
| 1351 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1352 | # Let TP download happen again |
| 1353 | for uni_id in self._tp_service_specific_task: |
| 1354 | self._tp_service_specific_task[uni_id].clear() |
| 1355 | for uni_id in self._tech_profile_download_done: |
| 1356 | self._tech_profile_download_done[uni_id].clear() |
| 1357 | |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1358 | yield self.disable_ports(lock_ports=False) |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1359 | yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci") |
| 1360 | yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED, |
| 1361 | connect_status=ConnectStatus.UNREACHABLE) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1362 | else: |
| 1363 | self.log.debug('not-changing-openomci-statemachine') |
| 1364 | |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1365 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1366 | def disable(self, device): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 1367 | self.log.info('disable', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1368 | try: |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1369 | yield self.disable_ports(lock_ports=True) |
| 1370 | yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock") |
| 1371 | yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1372 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1373 | except Exception as e: |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1374 | self.log.exception('exception-in-onu-disable', exception=e) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1375 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1376 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1377 | def reenable(self, device): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 1378 | self.log.info('reenable', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1379 | try: |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1380 | yield self.core_proxy.device_state_update(device.id, |
| 1381 | oper_status=OperStatus.ACTIVE, |
| 1382 | connect_status=ConnectStatus.REACHABLE) |
| 1383 | yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled') |
| 1384 | yield self.enable_ports() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1385 | except Exception as e: |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1386 | self.log.exception('exception-in-onu-reenable', exception=e) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1387 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1388 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1389 | def reboot(self): |
| 1390 | self.log.info('reboot-device') |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1391 | device = yield self.core_proxy.get_device(self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1392 | if device.connect_status != ConnectStatus.REACHABLE: |
| 1393 | self.log.error("device-unreachable") |
| 1394 | return |
| 1395 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1396 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1397 | def success(_results): |
| 1398 | self.log.info('reboot-success', _results=_results) |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1399 | yield self.core_proxy.device_reason_update(self.device_id, 'rebooting') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1400 | |
| 1401 | def failure(_reason): |
| 1402 | self.log.info('reboot-failure', _reason=_reason) |
| 1403 | |
| 1404 | self._deferred = self._onu_omci_device.reboot() |
| 1405 | self._deferred.addCallbacks(success, failure) |
| 1406 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1407 | @inlineCallbacks |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1408 | def disable_ports(self, lock_ports=True): |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1409 | self.log.info('disable-ports', device_id=self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1410 | |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1411 | # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 1412 | # load on the core |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1413 | for port in self.uni_ports: |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1414 | if port.mac_bridge_port_num == 1: |
| 1415 | port.operstatus = OperStatus.UNKNOWN |
| 1416 | self.log.info('disable-port', device_id=self.device_id, port=port) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1417 | yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, |
| 1418 | port.operstatus) |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1419 | |
| 1420 | if lock_ports is True: |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1421 | self.lock_ports(lock=True) |
| 1422 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1423 | @inlineCallbacks |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1424 | def enable_ports(self): |
| 1425 | self.log.info('enable-ports', device_id=self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1426 | |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1427 | self.lock_ports(lock=False) |
| 1428 | |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1429 | # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 1430 | # load on the core |
| 1431 | # Given by default all unis are initially active according to omci alarming, we must mimic this. |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1432 | for port in self.uni_ports: |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1433 | if port.mac_bridge_port_num == 1: |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1434 | port.operstatus = OperStatus.ACTIVE |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1435 | self.log.info('enable-port', device_id=self.device_id, port=port) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1436 | yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, |
| 1437 | port.operstatus) |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1438 | |
| 1439 | # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core, |
| 1440 | # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup. |
| 1441 | # |
| 1442 | # Basically the link state sequence: |
| 1443 | # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet) |
| 1444 | # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in |
| 1445 | # 3) a link state up alarm is received for the uni plugged in. |
| 1446 | # |
| 1447 | # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession |
| 1448 | # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity |
| 1449 | # would have a ripple effect through the core to the controller as well. And is it really worth it? |
| 1450 | ''' |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1451 | @inlineCallbacks |
| 1452 | def port_state_handler(self, _topic, msg): |
| 1453 | self.log.info("port-state-change", _topic=_topic, msg=msg) |
| 1454 | |
| 1455 | onu_id = msg['onu_id'] |
| 1456 | port_no = msg['port_number'] |
| 1457 | serial_number = msg['serial_number'] |
| 1458 | port_status = msg['port_status'] |
| 1459 | uni_port = self.uni_port(int(port_no)) |
| 1460 | |
| 1461 | self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number, |
| 1462 | port_status=port_status) |
| 1463 | |
| 1464 | if port_status is True: |
| 1465 | uni_port.operstatus = OperStatus.ACTIVE |
| 1466 | self.log.info('link-up', device_id=self.device_id, port=uni_port) |
| 1467 | else: |
| 1468 | uni_port.operstatus = OperStatus.UNKNOWN |
| 1469 | self.log.info('link-down', device_id=self.device_id, port=uni_port) |
| 1470 | |
| 1471 | yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, uni_port.port_number, uni_port.operstatus) |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1472 | ''' |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1473 | |
| 1474 | # Called just before openomci state machine is started. These listen for events from selected state machines, |
| 1475 | # most importantly, mib in sync. Which ultimately leads to downloading the mib |
| 1476 | def _subscribe_to_events(self): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1477 | self.log.debug('subscribe-to-events') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1478 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1479 | bus = self._onu_omci_device.event_bus |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1480 | |
| 1481 | # OMCI MIB Database sync status |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1482 | topic = OnuDeviceEntry.event_bus_topic(self.device_id, |
| 1483 | OnuDeviceEvents.MibDatabaseSyncEvent) |
| 1484 | self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler) |
| 1485 | |
| 1486 | # OMCI Capabilities |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1487 | topic = OnuDeviceEntry.event_bus_topic(self.device_id, |
| 1488 | OnuDeviceEvents.OmciCapabilitiesEvent) |
| 1489 | self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler) |
| 1490 | |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1491 | # TODO: these alarms seem to be unreliable depending on the environment |
| 1492 | # Listen for UNI link state alarms and set the oper_state based on that rather than assuming all UNI are up |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1493 | # topic = OnuDeviceEntry.event_bus_topic(self.device_id, |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1494 | # OnuDeviceEvents.PortEvent) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1495 | # self._port_state_subscription = bus.subscribe(topic, self.port_state_handler) |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1496 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1497 | # Called when the mib is in sync |
| 1498 | def in_sync_handler(self, _topic, msg): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1499 | self.log.debug('in-sync-handler', _topic=_topic, msg=msg) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1500 | if self._in_sync_subscription is not None: |
| 1501 | try: |
| 1502 | in_sync = msg[IN_SYNC_KEY] |
| 1503 | |
| 1504 | if in_sync: |
| 1505 | # Only call this once |
| 1506 | bus = self._onu_omci_device.event_bus |
| 1507 | bus.unsubscribe(self._in_sync_subscription) |
| 1508 | self._in_sync_subscription = None |
| 1509 | |
| 1510 | # Start up device_info load |
| 1511 | self.log.debug('running-mib-sync') |
| 1512 | reactor.callLater(0, self._mib_in_sync) |
| 1513 | |
| 1514 | except Exception as e: |
| 1515 | self.log.exception('in-sync', e=e) |
| 1516 | |
| 1517 | def capabilties_handler(self, _topic, _msg): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1518 | self.log.debug('capabilities-handler', _topic=_topic, msg=_msg) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1519 | if self._capabilities_subscription is not None: |
| 1520 | self.log.debug('capabilities-handler-done') |
| 1521 | |
| 1522 | # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU. |
| 1523 | # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP |
| 1524 | # Implement your own MibDownloadTask if you wish to setup something different by default |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1525 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1526 | def _mib_in_sync(self): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1527 | self.log.debug('mib-in-sync') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1528 | |
| 1529 | omci = self._onu_omci_device |
| 1530 | in_sync = omci.mib_db_in_sync |
| 1531 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1532 | device = yield self.core_proxy.get_device(self.device_id) |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1533 | yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1534 | |
| 1535 | if not self._dev_info_loaded: |
| 1536 | self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded) |
| 1537 | |
| 1538 | omci_dev = self._onu_omci_device |
| 1539 | config = omci_dev.configuration |
| 1540 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1541 | try: |
| 1542 | |
| 1543 | # sort the lists so we get consistent port ordering. |
| 1544 | ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else [] |
| 1545 | uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else [] |
| 1546 | pptp_list = sorted(config.pptp_entities) if config.pptp_entities else [] |
| 1547 | veip_list = sorted(config.veip_entities) if config.veip_entities else [] |
| 1548 | |
| 1549 | if ani_list is None or (pptp_list is None and veip_list is None): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1550 | self.log.warn("no-ani-or-unis") |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1551 | yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1552 | raise Exception("onu-missing-required-elements") |
| 1553 | |
| 1554 | # Currently logging the ani, pptp, veip, and uni for information purposes. |
| 1555 | # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks. |
| 1556 | # And in some ONU the UNI-G list is incomplete or incorrect... |
| 1557 | for entity_id in ani_list: |
| 1558 | ani_value = config.ani_g_entities[entity_id] |
| 1559 | self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value) |
| 1560 | # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..? |
| 1561 | self._total_tcont_count = ani_value.get('total-tcont-count') |
| 1562 | self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count) |
| 1563 | |
| 1564 | for entity_id in uni_list: |
| 1565 | uni_value = config.uni_g_entities[entity_id] |
| 1566 | self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value) |
| 1567 | |
| 1568 | uni_entities = OrderedDict() |
| 1569 | for entity_id in pptp_list: |
| 1570 | pptp_value = config.pptp_entities[entity_id] |
| 1571 | self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value) |
| 1572 | uni_entities[entity_id] = UniType.PPTP |
| 1573 | |
| 1574 | for entity_id in veip_list: |
| 1575 | veip_value = config.veip_entities[entity_id] |
| 1576 | self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value) |
| 1577 | uni_entities[entity_id] = UniType.VEIP |
| 1578 | |
| 1579 | uni_id = 0 |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 1580 | for entity_id, uni_type in uni_entities.items(): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1581 | try: |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1582 | yield self._add_uni_port(device, entity_id, uni_id, uni_type) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1583 | uni_id += 1 |
| 1584 | except AssertionError as e: |
| 1585 | self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e) |
| 1586 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1587 | self._qos_flexibility = config.qos_configuration_flexibility or 0 |
| 1588 | self._omcc_version = config.omcc_version or OMCCVersion.Unknown |
| 1589 | |
| 1590 | if self._unis: |
| 1591 | self._dev_info_loaded = True |
| 1592 | else: |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1593 | yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1594 | self.log.warn("no-usable-unis") |
| 1595 | raise Exception("no-usable-unis") |
| 1596 | |
| 1597 | except Exception as e: |
| 1598 | self.log.exception('device-info-load', e=e) |
| 1599 | self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync) |
| 1600 | |
| 1601 | else: |
| 1602 | self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded) |
| 1603 | |
| 1604 | if self._dev_info_loaded: |
Matt Jeanneret | ad9a0f1 | 2019-05-09 14:05:49 -0400 | [diff] [blame] | 1605 | if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED: |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1606 | |
| 1607 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1608 | def success(_results): |
| 1609 | self.log.info('mib-download-success', _results=_results) |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1610 | yield self.core_proxy.device_state_update(device.id, |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1611 | oper_status=OperStatus.ACTIVE, |
| 1612 | connect_status=ConnectStatus.REACHABLE) |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1613 | yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded') |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1614 | yield self.enable_ports() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1615 | self._mib_download_task = None |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 1616 | yield self.onu_active_event() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1617 | |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 1618 | # Start collecting stats from the device after a brief pause |
| 1619 | if not self._pm_metrics_started: |
| 1620 | self._pm_metrics_started = True |
| 1621 | pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 1622 | reactor.callLater(pmstart, self._pm_metrics.start_collector) |
| 1623 | |
| 1624 | # Start test requests after a brief pause |
| 1625 | if not self._test_request_started: |
| 1626 | self._test_request_started = True |
| 1627 | tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 1628 | reactor.callLater(tststart, self._test_request.start_collector) |
| 1629 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1630 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1631 | def failure(_reason): |
| 1632 | self.log.warn('mib-download-failure-retrying', _reason=_reason) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1633 | retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 1634 | reactor.callLater(retry, self._mib_in_sync) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 1635 | yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1636 | |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1637 | # start by locking all the unis till mib sync and initial mib is downloaded |
| 1638 | # this way we can capture the port down/up events when we are ready |
| 1639 | self.lock_ports(lock=True) |
| 1640 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1641 | # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set |
| 1642 | # the device to active/reachable. This then opens up the handler to openflow pushes from outside |
| 1643 | self.log.info('downloading-initial-mib-configuration') |
| 1644 | self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self) |
| 1645 | self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task) |
| 1646 | self._deferred.addCallbacks(success, failure) |
| 1647 | else: |
| 1648 | self.log.info('admin-down-disabling') |
| 1649 | self.disable(device) |
| 1650 | else: |
| 1651 | self.log.info('device-info-not-loaded-skipping-mib-download') |
| 1652 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1653 | @inlineCallbacks |
| 1654 | def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1655 | self.log.debug('add-uni-port') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1656 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1657 | uni_no = self.mk_uni_port_num(self._onu_indication.intf_id, self._onu_indication.onu_id, uni_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1658 | |
| 1659 | # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff |
| 1660 | uni_name = "uni-{}".format(uni_no) |
| 1661 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1662 | mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1663 | |
| 1664 | self.log.debug('uni-port-inputs', uni_no=uni_no, uni_id=uni_id, uni_name=uni_name, uni_type=uni_type, |
Yongjie Zhang | 286099c | 2019-08-06 13:39:07 -0400 | [diff] [blame] | 1665 | entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1666 | |
| 1667 | uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type) |
| 1668 | uni_port.entity_id = entity_id |
| 1669 | uni_port.enabled = True |
| 1670 | uni_port.mac_bridge_port_num = mac_bridge_port_num |
| 1671 | |
| 1672 | self.log.debug("created-uni-port", uni=uni_port) |
| 1673 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1674 | yield self.core_proxy.port_created(device.id, uni_port.get_port()) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1675 | |
| 1676 | self._unis[uni_port.port_number] = uni_port |
| 1677 | |
| 1678 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id, |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1679 | uni_ports=self.uni_ports, |
| 1680 | serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1681 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1682 | # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly. |
| 1683 | def mk_uni_port_num(self, intf_id, onu_id, uni_id): |
Amit Ghosh | 65400f1 | 2019-11-21 12:04:12 +0000 | [diff] [blame] | 1684 | MAX_PONS_PER_OLT = 256 |
| 1685 | MAX_ONUS_PER_PON = 256 |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1686 | MAX_UNIS_PER_ONU = 16 |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1687 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1688 | assert intf_id < MAX_PONS_PER_OLT |
| 1689 | assert onu_id < MAX_ONUS_PER_PON |
| 1690 | assert uni_id < MAX_UNIS_PER_ONU |
Amit Ghosh | 65400f1 | 2019-11-21 12:04:12 +0000 | [diff] [blame] | 1691 | return intf_id << 12 | onu_id << 4 | uni_id |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 1692 | |
| 1693 | @inlineCallbacks |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 1694 | def onu_active_event(self): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1695 | self.log.debug('onu-active-event') |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 1696 | try: |
| 1697 | device = yield self.core_proxy.get_device(self.device_id) |
| 1698 | parent_device = yield self.core_proxy.get_device(self.parent_id) |
| 1699 | olt_serial_number = parent_device.serial_number |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 1700 | raised_ts = arrow.utcnow().timestamp |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 1701 | |
| 1702 | self.log.debug("onu-indication-context-data", |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1703 | pon_id=self._onu_indication.intf_id, |
| 1704 | onu_id=self._onu_indication.onu_id, |
| 1705 | registration_id=self.device_id, |
| 1706 | device_id=self.device_id, |
| 1707 | onu_serial_number=device.serial_number, |
| 1708 | olt_serial_number=olt_serial_number, |
| 1709 | raised_ts=raised_ts) |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 1710 | |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 1711 | self.log.debug("Trying-to-raise-onu-active-event") |
| 1712 | OnuActiveEvent(self.events, self.device_id, |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 1713 | self._onu_indication.intf_id, |
| 1714 | device.serial_number, |
| 1715 | str(self.device_id), |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1716 | olt_serial_number, raised_ts, |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 1717 | onu_id=self._onu_indication.onu_id).send(True) |
| 1718 | except Exception as active_event_error: |
| 1719 | self.log.exception('onu-activated-event-error', |
| 1720 | errmsg=active_event_error.message) |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1721 | |
| 1722 | def lock_ports(self, lock=True): |
| 1723 | |
| 1724 | def success(response): |
| 1725 | self.log.debug('set-onu-ports-state', lock=lock, response=response) |
| 1726 | |
| 1727 | def failure(response): |
| 1728 | self.log.error('cannot-set-onu-ports-state', lock=lock, response=response) |
| 1729 | |
| 1730 | task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock) |
| 1731 | self._deferred = self._onu_omci_device.task_runner.queue_task(task) |
| 1732 | self._deferred.addCallbacks(success, failure) |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 1733 | |
| 1734 | def extract_tp_id_from_path(self, tp_path): |
| 1735 | # tp_path is of the format <technology>/<table_id>/<uni_port_name> |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1736 | tp_id = int(tp_path.split(_PATH_SEPERATOR)[1]) |
| 1737 | return tp_id |