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 |
Girish Gowdra | 5b49934 | 2020-06-16 14:45:51 -0700 | [diff] [blame] | 22 | |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 23 | import json |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 24 | import random |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 25 | from collections import OrderedDict |
| 26 | |
Girish Gowdra | 5b49934 | 2020-06-16 14:45:51 -0700 | [diff] [blame] | 27 | import arrow |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 28 | import pyvoltha.common.openflow.utils as fd |
Girish Gowdra | 5b49934 | 2020-06-16 14:45:51 -0700 | [diff] [blame] | 29 | import six |
| 30 | import structlog |
| 31 | from heartbeat import HeartBeat |
| 32 | from omci.brcm_mcast_task import BrcmMcastTask |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 33 | from omci.brcm_mib_download_task import BrcmMibDownloadTask |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 34 | from omci.brcm_tp_delete_task import BrcmTpDeleteTask |
Girish Gowdra | 5b49934 | 2020-06-16 14:45:51 -0700 | [diff] [blame] | 35 | from omci.brcm_tp_setup_task import BrcmTpSetupTask |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 36 | from omci.brcm_uni_lock_task import BrcmUniLockTask |
| 37 | from omci.brcm_vlan_filter_task import BrcmVlanFilterTask |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 38 | from onu_gem_port import OnuGemPort |
| 39 | from onu_tcont import OnuTCont |
| 40 | from pon_port import PonPort |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 41 | from tp_state import TpState |
Girish Gowdra | 5b49934 | 2020-06-16 14:45:51 -0700 | [diff] [blame] | 42 | from pyvoltha.adapters.common.frameio.frameio import hexify |
| 43 | from pyvoltha.adapters.common.kvstore.twisted_etcd_store import TwistedEtcdStore |
| 44 | from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents |
| 45 | from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent |
| 46 | from pyvoltha.adapters.extensions.events.device_events.onu.onu_deleted_event import OnuDeletedEvent |
| 47 | from pyvoltha.adapters.extensions.events.device_events.onu.onu_disabled_event import OnuDisabledEvent |
| 48 | from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics |
| 49 | from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 50 | from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes |
Girish Gowdra | 5b49934 | 2020-06-16 14:45:51 -0700 | [diff] [blame] | 51 | from pyvoltha.adapters.extensions.omci.omci_entities import AniG, Tcont, MacBridgeServiceProfile |
| 52 | from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \ |
| 53 | OnuDeviceEntry, IN_SYNC_KEY |
| 54 | from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest |
| 55 | from pyvoltha.common.tech_profile.tech_profile import TechProfile |
| 56 | from pyvoltha.common.utils.registry import registry |
| 57 | from twisted.internet import reactor |
| 58 | from twisted.internet.defer import inlineCallbacks, returnValue |
| 59 | from uni_port import RESERVED_TRANSPARENT_VLAN |
| 60 | from uni_port import UniPort, UniType |
| 61 | from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState |
| 62 | from voltha_protos.device_pb2 import Port |
| 63 | from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \ |
| 64 | InterAdapterOmciMessage, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \ |
| 65 | InterAdapterDeleteTcontMessage |
| 66 | from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC |
| 67 | from voltha_protos.openolt_pb2 import OnuIndication |
onkarkundargi | a1e2af2 | 2020-01-27 11:51:43 +0530 | [diff] [blame] | 68 | from voltha_protos.voltha_pb2 import TestResponse |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 69 | |
| 70 | OP = EntityOperations |
| 71 | RC = ReasonCodes |
| 72 | |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 73 | IS_MULTICAST = 'is_multicast' |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 74 | GEM_PORT_ID = 'gemport_id' |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 75 | _STARTUP_RETRY_WAIT = 10 |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 76 | _PATH_SEPERATOR = "/" |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 77 | |
| 78 | |
| 79 | class BrcmOpenomciOnuHandler(object): |
| 80 | |
| 81 | def __init__(self, adapter, device_id): |
| 82 | self.log = structlog.get_logger(device_id=device_id) |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 83 | self.log.debug('starting-handler') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 84 | self.adapter = adapter |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 85 | self.core_proxy = adapter.core_proxy |
| 86 | self.adapter_proxy = adapter.adapter_proxy |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 87 | self.parent_id = None |
| 88 | self.device_id = device_id |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 89 | self.proxy_address = None |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 90 | self._enabled = False |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame] | 91 | self._is_device_active_and_reachable = False |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 92 | self.events = None |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 93 | self._pm_metrics = None |
| 94 | self._pm_metrics_started = False |
| 95 | self._test_request = None |
| 96 | self._test_request_started = False |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 97 | self._tp = dict() # tp_id -> technology profile definition in KV Store. |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 98 | self._reconciling = False |
kesavand | 86a0fcf | 2020-08-25 08:25:28 +0530 | [diff] [blame^] | 99 | self.olt_serial_number = "" |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 100 | |
| 101 | # Persisted onu configuration needed in case of reconciliation. |
| 102 | self._onu_persisted_state = { |
| 103 | 'onu_id': None, |
| 104 | 'intf_id': None, |
| 105 | 'serial_number': None, |
| 106 | 'admin_state': None, |
| 107 | 'oper_state': None, |
| 108 | 'uni_config': list() |
| 109 | } |
| 110 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 111 | self._unis = dict() # Port # -> UniPort |
| 112 | |
| 113 | self._pon = None |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 114 | self._pon_port_number = 100 |
| 115 | self.logical_device_id = None |
| 116 | |
| 117 | self._heartbeat = HeartBeat.create(self, device_id) |
| 118 | |
| 119 | # Set up OpenOMCI environment |
| 120 | self._onu_omci_device = None |
| 121 | self._dev_info_loaded = False |
| 122 | self._deferred = None |
| 123 | |
| 124 | self._in_sync_subscription = None |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 125 | self._port_state_subscription = None |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 126 | self._connectivity_subscription = None |
| 127 | self._capabilities_subscription = None |
| 128 | |
| 129 | self.mac_bridge_service_profile_entity_id = 0x201 |
| 130 | self.gal_enet_profile_entity_id = 0x1 |
| 131 | |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 132 | # Stores information related to queued vlan filter tasks |
| 133 | # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 134 | self._queued_vlan_filter_task = dict() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 135 | |
Girish Gowdra | 6dd965a | 2020-08-13 19:13:33 -0700 | [diff] [blame] | 136 | self._multicast_task = None |
| 137 | |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 138 | self._set_vlan = dict() # uni_id, tp_id -> set_vlan_id |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 139 | self._tp_state_map_per_uni = dict() # uni_id -> {dictionary tp_id->TpState} |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 140 | |
| 141 | # Paths from kv store |
| 142 | ONU_PATH = 'service/voltha/openonu' |
| 143 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 144 | # Initialize KV store client |
| 145 | self.args = registry('main').get_args() |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 146 | host, port = self.args.etcd.split(':', 1) |
| 147 | self.tp_kv_client = TwistedEtcdStore(host, port, TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX) |
| 148 | self.onu_kv_client = TwistedEtcdStore(host, port, ONU_PATH) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 149 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 150 | @property |
| 151 | def enabled(self): |
| 152 | return self._enabled |
| 153 | |
| 154 | @enabled.setter |
| 155 | def enabled(self, value): |
| 156 | if self._enabled != value: |
| 157 | self._enabled = value |
| 158 | |
| 159 | @property |
| 160 | def omci_agent(self): |
| 161 | return self.adapter.omci_agent |
| 162 | |
| 163 | @property |
| 164 | def omci_cc(self): |
| 165 | return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None |
| 166 | |
| 167 | @property |
| 168 | def heartbeat(self): |
| 169 | return self._heartbeat |
| 170 | |
| 171 | @property |
| 172 | def uni_ports(self): |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 173 | return list(self._unis.values()) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 174 | |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame] | 175 | @property |
| 176 | def is_device_active_and_reachable(self): |
| 177 | return self._is_device_active_and_reachable |
| 178 | |
| 179 | @is_device_active_and_reachable.setter |
| 180 | def is_device_active_and_reachable(self, value): |
| 181 | self._is_device_active_and_reachable = value |
| 182 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 183 | def uni_port(self, port_no_or_name): |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 184 | if isinstance(port_no_or_name, six.string_types): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 185 | return next((uni for uni in self.uni_ports |
| 186 | if uni.name == port_no_or_name), None) |
| 187 | |
| 188 | assert isinstance(port_no_or_name, int), 'Invalid parameter type' |
| 189 | return next((uni for uni in self.uni_ports |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 190 | if uni.port_number == port_no_or_name), None) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 191 | |
| 192 | @property |
| 193 | def pon_port(self): |
| 194 | return self._pon |
| 195 | |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 196 | @property |
| 197 | def onu_omci_device(self): |
| 198 | return self._onu_omci_device |
| 199 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 200 | def receive_message(self, msg): |
| 201 | if self.omci_cc is not None: |
| 202 | self.omci_cc.receive_message(msg) |
| 203 | |
| 204 | # Called once when the adapter creates the device/onu instance |
Matt Jeanneret | 84e56f6 | 2019-02-26 10:48:09 -0500 | [diff] [blame] | 205 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 206 | def activate(self, device): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 207 | 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] | 208 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 209 | assert device.parent_id |
Matt Jeanneret | 0c28789 | 2019-02-28 11:48:00 -0500 | [diff] [blame] | 210 | assert device.parent_port_no |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 211 | assert device.proxy_address.device_id |
| 212 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 213 | self.proxy_address = device.proxy_address |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 214 | self.parent_id = device.parent_id |
Matt Jeanneret | 0c28789 | 2019-02-28 11:48:00 -0500 | [diff] [blame] | 215 | self._pon_port_number = device.parent_port_no |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 216 | if self.enabled is not True: |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 217 | 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] | 218 | # populate what we know. rest comes later after mib sync |
Matt Jeanneret | 0c28789 | 2019-02-28 11:48:00 -0500 | [diff] [blame] | 219 | device.root = False |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 220 | device.vendor = 'OpenONU' |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 221 | device.reason = 'activating-onu' |
| 222 | |
Matt Jeanneret | 84e56f6 | 2019-02-26 10:48:09 -0500 | [diff] [blame] | 223 | # 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] | 224 | # pm_metrics requires a logical device id. For now set to just device_id |
| 225 | self.logical_device_id = self.device_id |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 226 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 227 | self._onu_persisted_state['serial_number'] = device.serial_number |
| 228 | try: |
| 229 | self.log.debug('updating-onu-state', device_id=self.device_id, |
| 230 | onu_persisted_state=self._onu_persisted_state) |
| 231 | yield self.onu_kv_client.set(self.device_id, json.dumps(self._onu_persisted_state)) |
| 232 | except Exception as e: |
| 233 | self.log.error('could-not-store-onu-state', device_id=self.device_id, |
| 234 | onu_persisted_state=self._onu_persisted_state, e=e) |
| 235 | # if we cannot write to storage we can proceed, for now. |
| 236 | # later onu indications from the olt will have another chance |
| 237 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 238 | yield self.core_proxy.device_update(device) |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 239 | 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] | 240 | |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 241 | yield self._init_pon_state() |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 242 | 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] | 243 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 244 | yield self._init_metrics() |
| 245 | self.log.debug('metrics initialized', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 246 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 247 | self.enabled = True |
| 248 | else: |
| 249 | self.log.info('onu-already-activated') |
| 250 | |
| 251 | # 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] | 252 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 253 | def reconcile(self, device): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 254 | 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] | 255 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 256 | if self._reconciling: |
| 257 | self.log.debug('already-running-reconcile-device', device_id=device.id, serial_number=device.serial_number) |
| 258 | return |
| 259 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 260 | # first we verify that we got parent reference and proxy info |
| 261 | assert device.parent_id |
| 262 | assert device.proxy_address.device_id |
| 263 | |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 264 | self.proxy_address = device.proxy_address |
| 265 | self.parent_id = device.parent_id |
| 266 | self._pon_port_number = device.parent_port_no |
| 267 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 268 | if self.enabled is not True: |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 269 | self._reconciling = True |
| 270 | self.log.info('reconciling-openonu-device') |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 271 | self.logical_device_id = self.device_id |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 272 | |
| 273 | try: |
| 274 | query_data = yield self.onu_kv_client.get(device.id) |
| 275 | self._onu_persisted_state = json.loads(query_data) |
| 276 | self.log.debug('restored-onu-state', device_id=self.device_id, |
| 277 | onu_persisted_state=self._onu_persisted_state) |
| 278 | except Exception as e: |
| 279 | self.log.error('no-stored-onu-state', device_id=device.id, e=e) |
| 280 | # there is nothing we can do without data. flag the device as UNKNOWN and cannot reconcile |
| 281 | # likely it will take manual steps to delete/re-add this onu |
| 282 | yield self.core_proxy.device_reason_update(self.device_id, "cannot-reconcile") |
| 283 | yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN) |
| 284 | return |
| 285 | |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 286 | self._init_pon_state() |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 287 | 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] | 288 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 289 | self._init_metrics() |
| 290 | self.log.debug('metrics initialized', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 291 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 292 | self._subscribe_to_events() |
| 293 | # need to restart omci start machines and reload mib database. once db is loaded we can finish reconcile |
| 294 | self._onu_omci_device.start(device) |
| 295 | self._heartbeat.enabled = True |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 296 | |
| 297 | self.enabled = True |
| 298 | else: |
| 299 | self.log.info('onu-already-activated') |
| 300 | |
| 301 | @inlineCallbacks |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 302 | def _init_pon_state(self): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 303 | 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] | 304 | |
| 305 | self._pon = PonPort.create(self, self._pon_port_number) |
Matt Jeanneret | 0c28789 | 2019-02-28 11:48:00 -0500 | [diff] [blame] | 306 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 307 | self.log.debug('adding-pon-port-to-agent', |
| 308 | type=self._pon.get_port().type, |
| 309 | admin_state=self._pon.get_port().admin_state, |
| 310 | oper_status=self._pon.get_port().oper_status, |
| 311 | ) |
Matt Jeanneret | 0c28789 | 2019-02-28 11:48:00 -0500 | [diff] [blame] | 312 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 313 | if not self._reconciling: |
| 314 | 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] | 315 | |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 316 | self.log.debug('added-pon-port-to-agent', |
| 317 | type=self._pon.get_port().type, |
| 318 | admin_state=self._pon.get_port().admin_state, |
| 319 | oper_status=self._pon.get_port().oper_status, |
| 320 | ) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 321 | |
| 322 | # Create and start the OpenOMCI ONU Device Entry for this ONU |
| 323 | self._onu_omci_device = self.omci_agent.add_device(self.device_id, |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 324 | self.core_proxy, |
| 325 | self.adapter_proxy, |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 326 | support_classes=self.adapter.broadcom_omci, |
| 327 | custom_me_map=self.adapter.custom_me_entities()) |
| 328 | # Port startup |
| 329 | if self._pon is not None: |
| 330 | self._pon.enabled = True |
| 331 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 332 | @inlineCallbacks |
| 333 | def _init_metrics(self): |
| 334 | self.log.debug('init-metrics', device_id=self.device_id, device_logical_id=self.logical_device_id) |
| 335 | |
| 336 | serial_number = self._onu_persisted_state.get('serial_number') |
| 337 | |
| 338 | ############################################################################ |
| 339 | # Setup Alarm handler |
| 340 | self.events = AdapterEvents(self.core_proxy, self.device_id, self.logical_device_id, |
| 341 | serial_number) |
| 342 | ############################################################################ |
| 343 | # Setup PM configuration for this device |
| 344 | # Pass in ONU specific options |
| 345 | kwargs = { |
| 346 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 347 | 'heartbeat': self.heartbeat, |
| 348 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 349 | } |
| 350 | self.log.debug('create-pm-metrics', device_id=self.device_id, serial_number=serial_number) |
| 351 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
| 352 | self.logical_device_id, serial_number, |
| 353 | grouped=True, freq_override=False, **kwargs) |
| 354 | pm_config = self._pm_metrics.make_proto() |
| 355 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
| 356 | self.log.debug("initial-pm-config", device_id=self.device_id, serial_number=serial_number) |
| 357 | |
| 358 | if not self._reconciling: |
| 359 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
| 360 | |
| 361 | # Note, ONU ID and UNI intf set in add_uni_port method |
| 362 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events, |
| 363 | ani_ports=[self._pon]) |
| 364 | |
| 365 | # Code to Run OMCI Test Action |
| 366 | kwargs_omci_test_action = { |
| 367 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 368 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 369 | } |
| 370 | self._test_request = OmciTestRequest(self.core_proxy, |
| 371 | self.omci_agent, self.device_id, |
| 372 | AniG, serial_number, |
| 373 | self.logical_device_id, |
| 374 | exclusive=False, |
| 375 | **kwargs_omci_test_action) |
| 376 | |
| 377 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 378 | def delete(self, device): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 379 | self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number) |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 380 | try: |
| 381 | yield self.onu_kv_client.delete(device.id) |
| 382 | except Exception as e: |
| 383 | self.log.error('could-not-delete-onu-state', device_id=device.id, e=e) |
| 384 | |
Devmalya Paul | 1e1b172 | 2020-05-07 02:51:15 -0400 | [diff] [blame] | 385 | try: |
| 386 | self._deferred.cancel() |
| 387 | self._test_request.stop_collector() |
| 388 | self._pm_metrics.stop_collector() |
| 389 | self.log.debug('removing-openomci-statemachine') |
| 390 | self.omci_agent.remove_device(device.id, cleanup=True) |
| 391 | yield self.onu_deleted_event() |
| 392 | except Exception as e: |
| 393 | self.log.error('could-not-delete-onu', device_id=device.id, e=e) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 394 | |
| 395 | def _create_tconts(self, uni_id, us_scheduler): |
| 396 | alloc_id = us_scheduler['alloc_id'] |
| 397 | q_sched_policy = us_scheduler['q_sched_policy'] |
| 398 | self.log.debug('create-tcont', us_scheduler=us_scheduler) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 399 | # TODO: revisit for multi tconts support |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 400 | new_tconts = [] |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 401 | tcontdict = dict() |
| 402 | tcontdict['alloc-id'] = alloc_id |
| 403 | tcontdict['q_sched_policy'] = q_sched_policy |
| 404 | tcontdict['uni_id'] = uni_id |
| 405 | |
Matt Jeanneret | 3789d0d | 2020-01-19 09:03:42 -0500 | [diff] [blame] | 406 | tcont = OnuTCont.create(self, tcont=tcontdict) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 407 | |
Girish Gowdra | 7c1240c | 2020-07-15 15:06:42 -0700 | [diff] [blame] | 408 | success = self._pon.add_tcont(tcont, True) |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame] | 409 | if success: |
| 410 | new_tconts.append(tcont) |
| 411 | self.log.debug('pon-add-tcont', tcont=tcont) |
| 412 | |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 413 | return new_tconts |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 414 | |
| 415 | # Called when there is an olt up indication, providing the gem port id chosen by the olt handler |
| 416 | def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction): |
| 417 | self.log.debug('create-gemport', |
| 418 | gem_ports=gem_ports, direction=direction) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 419 | new_gem_ports = [] |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 420 | for gem_port in gem_ports: |
| 421 | gemdict = dict() |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 422 | if gem_port[IS_MULTICAST] == 'True': |
| 423 | gemdict[GEM_PORT_ID] = gem_port['multicast_gem_id'] |
| 424 | gemdict[IS_MULTICAST] = True |
| 425 | else: |
| 426 | gemdict[GEM_PORT_ID] = gem_port[GEM_PORT_ID] |
| 427 | gemdict[IS_MULTICAST] = False |
| 428 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 429 | gemdict['direction'] = direction |
| 430 | gemdict['alloc_id_ref'] = alloc_id_ref |
| 431 | gemdict['encryption'] = gem_port['aes_encryption'] |
| 432 | gemdict['discard_config'] = dict() |
| 433 | gemdict['discard_config']['max_probability'] = \ |
| 434 | gem_port['discard_config']['max_probability'] |
| 435 | gemdict['discard_config']['max_threshold'] = \ |
| 436 | gem_port['discard_config']['max_threshold'] |
| 437 | gemdict['discard_config']['min_threshold'] = \ |
| 438 | gem_port['discard_config']['min_threshold'] |
| 439 | gemdict['discard_policy'] = gem_port['discard_policy'] |
| 440 | gemdict['max_q_size'] = gem_port['max_q_size'] |
| 441 | gemdict['pbit_map'] = gem_port['pbit_map'] |
| 442 | gemdict['priority_q'] = gem_port['priority_q'] |
| 443 | gemdict['scheduling_policy'] = gem_port['scheduling_policy'] |
| 444 | gemdict['weight'] = gem_port['weight'] |
| 445 | gemdict['uni_id'] = uni_id |
| 446 | |
| 447 | gem_port = OnuGemPort.create(self, gem_port=gemdict) |
| 448 | |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame] | 449 | success = self._pon.add_gem_port(gem_port, True) |
| 450 | if success: |
| 451 | new_gem_ports.append(gem_port) |
| 452 | self.log.debug('pon-add-gemport', gem_port=gem_port) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 453 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 454 | return new_gem_ports |
| 455 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 456 | def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id): |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 457 | # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter |
| 458 | # task is scheduled even before tp task. So we queue vlan-filter task if tp_task |
| 459 | # or initial-mib-download is not done. Once the tp_task is completed, we execute |
| 460 | # such queued vlan-filter tasks |
| 461 | try: |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 462 | 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] | 463 | self.log.info("executing-queued-vlan-filter-task", |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 464 | uni_id=uni_id, tp_id=tp_id) |
Mahir Gunyel | a982ec3 | 2020-02-25 12:30:37 -0800 | [diff] [blame] | 465 | for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]: |
| 466 | reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"), |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 467 | uni_id=uni_id, uni_port=filter_info.get("uni_port"), |
| 468 | match_vlan=filter_info.get("match_vlan"), |
| 469 | _set_vlan_vid=filter_info.get("set_vlan_vid"), |
| 470 | _set_vlan_pcp=filter_info.get("set_vlan_pcp"), |
| 471 | tp_id=filter_info.get("tp_id")) |
Girish Gowdra | af98a08 | 2020-03-05 16:40:51 -0800 | [diff] [blame] | 472 | # Now remove the entry from the dictionary |
Girish Gowdra | af98a08 | 2020-03-05 16:40:51 -0800 | [diff] [blame] | 473 | self.log.debug("executed-queued-vlan-filter-task", |
| 474 | uni_id=uni_id, tp_id=tp_id) |
Girish Gowdra | a63eda8 | 2020-05-12 13:40:04 -0700 | [diff] [blame] | 475 | |
| 476 | # Now delete the key entry for the tp_id once we have handled the |
| 477 | # queued vlan filter tasks for that tp_id |
| 478 | del self._queued_vlan_filter_task[uni_id][tp_id] |
| 479 | # If the queued vlan filter tasks for all the tp_ids on a given |
| 480 | # uni_id is handled, then delete the uni_id key |
| 481 | if len(self._queued_vlan_filter_task[uni_id]) == 0: |
| 482 | del self._queued_vlan_filter_task[uni_id] |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 483 | except Exception as e: |
| 484 | self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e) |
| 485 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 486 | def _do_tech_profile_configuration(self, uni_id, tp): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 487 | us_scheduler = tp['us_scheduler'] |
| 488 | alloc_id = us_scheduler['alloc_id'] |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 489 | new_tconts = self._create_tconts(uni_id, us_scheduler) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 490 | upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list'] |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 491 | 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] | 492 | downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list'] |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 493 | new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM") |
| 494 | |
| 495 | new_gems = [] |
| 496 | new_gems.extend(new_upstream_gems) |
| 497 | new_gems.extend(new_downstream_gems) |
| 498 | |
| 499 | return new_tconts, new_gems |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 500 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 501 | @inlineCallbacks |
Girish Gowdra | b3895a0 | 2020-06-12 15:34:20 -0700 | [diff] [blame] | 502 | def _get_tp_instance_from_kv_store(self, tp_path): |
| 503 | _max_tp_load_retry_count = 5 |
| 504 | _curr_retry_cnt = 0 |
| 505 | _tp_instance = None |
| 506 | while _curr_retry_cnt < _max_tp_load_retry_count: |
| 507 | _curr_retry_cnt += 1 |
| 508 | try: |
| 509 | _tp_instance = yield self.tp_kv_client.get(tp_path) |
| 510 | except Exception as e: |
| 511 | pass |
| 512 | if _tp_instance is None: |
| 513 | self.log.error("failed-to-load-tp--retrying", retry_cnt=_curr_retry_cnt) |
| 514 | continue |
| 515 | # if we have got a valid tp instance, break from loop |
| 516 | break |
| 517 | |
| 518 | returnValue(_tp_instance) |
| 519 | |
| 520 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 521 | def load_and_configure_tech_profile(self, uni_id, tp_path): |
| 522 | 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] | 523 | tp_id = self.extract_tp_id_from_path(tp_path) |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 524 | if tp_id not in self._tp_state_map_per_uni[uni_id]: |
| 525 | self._tp_state_map_per_uni[uni_id][tp_id] = TpState(self, uni_id, tp_path) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 526 | |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 527 | if not self._tp_state_map_per_uni[uni_id][tp_id].tp_setup_done: |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 528 | try: |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 529 | if self._tp_state_map_per_uni[uni_id][tp_id].tp_task_ref is not None: |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 530 | self.log.info("tech-profile-config-already-in-progress", |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 531 | tp_path=tp_path) |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 532 | returnValue(None) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 533 | |
Girish Gowdra | b3895a0 | 2020-06-12 15:34:20 -0700 | [diff] [blame] | 534 | if tp_path in self._tp: |
| 535 | tp = self._tp[tp_path] |
| 536 | else: |
| 537 | tpstored = yield self._get_tp_instance_from_kv_store(tp_path) |
| 538 | if tpstored is None: |
| 539 | self.log.error("failed-to-load-tp-instance", tp_path=tp_path) |
| 540 | returnValue(None) |
| 541 | tpstring = tpstored.decode('ascii') |
| 542 | tp = json.loads(tpstring) |
| 543 | self._tp[tp_id] = tp |
| 544 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 545 | self.log.debug("tp-instance", tp=tp) |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 546 | tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp) |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 547 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 548 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 549 | def success(_results): |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 550 | self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id) |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 551 | if tp_id in self._tp_state_map_per_uni[uni_id]: |
| 552 | self._tp_state_map_per_uni[uni_id][tp_id].tp_task_ref = None |
| 553 | self._tp_state_map_per_uni[uni_id][tp_id].tp_setup_done = True |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 554 | # Now execute any vlan filter tasks that were queued for later |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 555 | reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 556 | 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] | 557 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 558 | # Execute mcast task |
| 559 | for gem in gem_ports: |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 560 | self.log.debug("checking-multicast-service-for-gem ", gem=gem) |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 561 | if gem.mcast is True: |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 562 | self.log.info("found-multicast-service-for-gem ", gem=gem, uni_id=uni_id, tp_id=tp_id) |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 563 | reactor.callInThread(self.start_multicast_service, uni_id, tp_path) |
| 564 | self.log.debug("started_multicast_service-successfully", tconts=tconts, gems=gem_ports) |
| 565 | break |
| 566 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 567 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 568 | def failure(_reason): |
Mahir Gunyel | 5afa954 | 2020-02-23 22:54:04 -0800 | [diff] [blame] | 569 | 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] | 570 | _reason=_reason) |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 571 | if tp_id in self._tp_state_map_per_uni[uni_id]: |
| 572 | self._tp_state_map_per_uni[uni_id][tp_id].tp_task_ref = None |
| 573 | retry = random.randint(1, 5) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 574 | reactor.callLater(retry, self.load_and_configure_tech_profile, |
| 575 | uni_id, tp_path) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 576 | yield self.core_proxy.device_reason_update(self.device_id, |
| 577 | 'tech-profile-config-download-failure-retrying') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 578 | |
Mahir Gunyel | a982ec3 | 2020-02-25 12:30:37 -0800 | [diff] [blame] | 579 | 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] | 580 | self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports) |
| 581 | |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame] | 582 | self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values())) |
| 583 | self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values())) |
| 584 | |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 585 | self._tp_state_map_per_uni[uni_id][tp_id].tp_task_ref = \ |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 586 | BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 587 | self._deferred = \ |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 588 | self._onu_omci_device.task_runner.queue_task(self._tp_state_map_per_uni[uni_id][tp_id]. |
| 589 | tp_task_ref) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 590 | self._deferred.addCallbacks(success, failure) |
| 591 | |
| 592 | except Exception as e: |
| 593 | self.log.exception("error-loading-tech-profile", e=e) |
| 594 | else: |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 595 | # There is an active tech-profile task ongoing on this UNI port. So, reschedule this task |
| 596 | # after a short interval |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 597 | for tpid in self._tp_state_map_per_uni[uni_id]: |
| 598 | if self._tp_state_map_per_uni[uni_id][tpid].tp_task_ref is not None: |
| 599 | self.log.debug("active-tp-tasks-in-progress-for-uni--scheduling-this-task-for-later", |
| 600 | uni_id=uni_id, tp_id=tpid) |
| 601 | retry = random.randint(1, 5) |
| 602 | reactor.callLater(retry, self.load_and_configure_tech_profile, |
| 603 | uni_id, tp_path) |
| 604 | return |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 605 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 606 | self.log.info("tech-profile-config-already-done") |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 607 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 608 | # Could be a case where TP exists but new gem-ports are getting added dynamically |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 609 | tpstored = yield self.tp_kv_client.get(tp_path) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 610 | tpstring = tpstored.decode('ascii') |
| 611 | tp = json.loads(tpstring) |
| 612 | upstream_gems = [] |
| 613 | downstream_gems = [] |
| 614 | # Find out the new Gem ports that are getting added afresh. |
| 615 | for gp in tp['upstream_gem_port_attribute_list']: |
| 616 | if self.pon_port.gem_port(gp['gemport_id'], "upstream"): |
| 617 | # gem port already exists |
| 618 | continue |
| 619 | upstream_gems.append(gp) |
| 620 | for gp in tp['downstream_gem_port_attribute_list']: |
| 621 | if self.pon_port.gem_port(gp['gemport_id'], "downstream"): |
| 622 | # gem port already exists |
| 623 | continue |
| 624 | downstream_gems.append(gp) |
| 625 | |
| 626 | us_scheduler = tp['us_scheduler'] |
| 627 | alloc_id = us_scheduler['alloc_id'] |
| 628 | |
| 629 | if len(upstream_gems) > 0 or len(downstream_gems) > 0: |
| 630 | self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems) |
| 631 | new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM") |
| 632 | new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM") |
| 633 | new_gems = [] |
| 634 | new_gems.extend(new_upstream_gems) |
| 635 | new_gems.extend(new_downstream_gems) |
| 636 | |
| 637 | def success(_results): |
| 638 | self.log.info("new-gem-ports-successfully-installed", result=_results) |
Girish Gowdra | 865776d | 2020-08-12 14:59:03 -0700 | [diff] [blame] | 639 | if tp_id in self._tp_state_map_per_uni[uni_id]: |
| 640 | self._tp_state_map_per_uni[uni_id][tp_id].tp_task_ref = None |
Girish Gowdra | 6dd965a | 2020-08-13 19:13:33 -0700 | [diff] [blame] | 641 | # Execute mcast task |
| 642 | for gem in downstream_gems: |
| 643 | self.log.debug("checking-multicast-service-for-gem ", gem=gem) |
| 644 | if gem.mcast: |
| 645 | self.log.info("found-multicast-service-for-gem ", gem=gem, uni_id=uni_id, tp_id=tp_id) |
| 646 | reactor.callInThread(self.start_multicast_service, uni_id, tp_path) |
| 647 | self.log.debug("started_multicast_service-successfully", gem=gem) |
| 648 | break |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 649 | |
| 650 | def failure(_reason): |
| 651 | self.log.warn('new-gem-port-install-failed--retrying', |
| 652 | _reason=_reason) |
Girish Gowdra | 865776d | 2020-08-12 14:59:03 -0700 | [diff] [blame] | 653 | if tp_id in self._tp_state_map_per_uni[uni_id]: |
| 654 | self._tp_state_map_per_uni[uni_id][tp_id].tp_task_ref = None |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 655 | # Remove gem ports from cache. We will re-add them during the retry |
| 656 | for gp in new_gems: |
| 657 | self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False) |
| 658 | |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 659 | retry = random.randint(1, 5) |
Matt Jeanneret | 04ebe8f | 2020-01-26 01:05:23 -0500 | [diff] [blame] | 660 | reactor.callLater(retry, self.load_and_configure_tech_profile, |
| 661 | uni_id, tp_path) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 662 | |
Girish Gowdra | 8777c85 | 2020-07-23 12:00:23 -0700 | [diff] [blame] | 663 | if self._pon.get_tcont(alloc_id) is None: |
| 664 | self.log.error("no-valid-tcont-reference-for-tp-id--not-installing-gem", alloc_id=alloc_id, tp_id=tp_id) |
| 665 | return |
| 666 | |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 667 | self._tp_state_map_per_uni[uni_id][tp_id].tp_task_ref = \ |
Girish Gowdra | 8777c85 | 2020-07-23 12:00:23 -0700 | [diff] [blame] | 668 | BrcmTpSetupTask(self.omci_agent, self, uni_id, [self._pon.get_tcont(alloc_id)], new_gems, tp_id) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 669 | self._deferred = \ |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 670 | self._onu_omci_device.task_runner.queue_task(self._tp_state_map_per_uni[uni_id][tp_id]. |
| 671 | tp_task_ref) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 672 | self._deferred.addCallbacks(success, failure) |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 673 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 674 | @inlineCallbacks |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 675 | def start_multicast_service(self, uni_id, tp_path, retry_count=0): |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 676 | self.log.debug("starting-multicast-service", uni_id=uni_id, tp_path=tp_path) |
| 677 | tp_id = self.extract_tp_id_from_path(tp_path) |
| 678 | if uni_id in self._set_vlan and tp_id in self._set_vlan[uni_id]: |
| 679 | try: |
| 680 | tp = self._tp[tp_id] |
| 681 | if tp is None: |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 682 | tpstored = yield self.tp_kv_client.get(tp_path) |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 683 | tpstring = tpstored.decode('ascii') |
| 684 | tp = json.loads(tpstring) |
| 685 | if tp is None: |
| 686 | self.log.error("cannot-find-tp-to-start-multicast-service", uni_id=uni_id, tp_path=tp_path) |
| 687 | return |
| 688 | else: |
| 689 | self._tp[tp_id] = tp |
| 690 | |
| 691 | self.log.debug("mcast-vlan-learned-before", self._set_vlan[uni_id][tp_id], uni_id=uni_id, tp_id=tp_id) |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 692 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 693 | def success(_results): |
| 694 | self.log.debug('multicast-success', uni_id=uni_id) |
| 695 | self._multicast_task = None |
| 696 | |
| 697 | def failure(_reason): |
| 698 | self.log.warn('multicast-failure', _reason=_reason) |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 699 | retry = random.randint(1, 5) |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 700 | reactor.callLater(retry, self.start_multicast_service, |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 701 | uni_id, tp_path) |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 702 | |
| 703 | self.log.debug('starting-multicast-task', mcast_vlan_id=self._set_vlan[uni_id][tp_id]) |
| 704 | downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list'] |
| 705 | for i in range(len(downstream_gem_port_attribute_list)): |
| 706 | if IS_MULTICAST in downstream_gem_port_attribute_list[i] and \ |
| 707 | downstream_gem_port_attribute_list[i][IS_MULTICAST] == 'True': |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 708 | dynamic_access_control_list_table = downstream_gem_port_attribute_list[i][ |
| 709 | 'dynamic_access_control_list'].split("-") |
| 710 | static_access_control_list_table = downstream_gem_port_attribute_list[i][ |
| 711 | 'static_access_control_list'].split("-") |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 712 | multicast_gem_id = downstream_gem_port_attribute_list[i]['multicast_gem_id'] |
Girish Gowdra | 6dd965a | 2020-08-13 19:13:33 -0700 | [diff] [blame] | 713 | self._multicast_task = BrcmMcastTask(self.omci_agent, self, self.device_id, uni_id, tp_id, |
| 714 | self._set_vlan[uni_id][tp_id], |
| 715 | dynamic_access_control_list_table, |
| 716 | static_access_control_list_table, multicast_gem_id) |
| 717 | self._deferred = self._onu_omci_device.task_runner.queue_task(self._multicast_task) |
| 718 | self._deferred.addCallbacks(success, failure) |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 719 | break |
| 720 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 721 | except Exception as e: |
| 722 | self.log.exception("error-loading-multicast", e=e) |
| 723 | else: |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 724 | if retry_count < 30: |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 725 | retry_count = +1 |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 726 | self.log.debug("going-to-wait-for-flow-to-learn-mcast-vlan", uni_id=uni_id, tp_id=tp_id, |
| 727 | retry=retry_count) |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 728 | reactor.callLater(0.5, self.start_multicast_service, uni_id, tp_path, retry_count) |
| 729 | else: |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 730 | self.log.error("mcast-vlan-not-configured-yet-failing-mcast-service-conf", uni_id=uni_id, tp_id=tp_id, |
| 731 | retry=retry_count) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 732 | |
Girish Gowdra | ba4b181 | 2020-07-17 12:21:26 -0700 | [diff] [blame] | 733 | def _clear_alloc_id_gem_port_from_internal_cache(self, alloc_id=None, gem_port_id=None): |
| 734 | tcont = None |
| 735 | gem_port = None |
| 736 | if alloc_id is not None: |
| 737 | self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values())) |
| 738 | for tc in list(self.pon_port.tconts.values()): |
| 739 | if tc.alloc_id == alloc_id: |
| 740 | self.log.info("removing-tcont-from-internal-cache", |
| 741 | alloc_id=alloc_id) |
| 742 | tcont = tc |
| 743 | self.pon_port.remove_tcont(tc.alloc_id, False) |
| 744 | |
| 745 | if gem_port_id is not None: |
| 746 | self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values())) |
| 747 | for gp in list(self.pon_port.gem_ports.values()): |
| 748 | if gp.gem_id == gem_port_id: |
| 749 | self.log.info("removing-gem-from-internal-cache", |
| 750 | gem_port_id=gem_port_id, direction=gp.direction) |
| 751 | gem_port = gp |
| 752 | self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False) |
| 753 | |
| 754 | return tcont, gem_port |
| 755 | |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 756 | def _tcont_delete_complete(self, uni_id, tp_id): |
| 757 | if not self._tp_state_map_per_uni[uni_id][tp_id].is_all_pon_resource_delete_complete(): |
| 758 | self.log.info("waiting-for-gem-port-delete-to-complete-before-clearing-tp-states") |
| 759 | retry = random.randint(1, 5) |
| 760 | reactor.callLater(retry, self._tcont_delete_complete, uni_id, tp_id) |
| 761 | return |
| 762 | self.log.info("tp-delete-complete") |
| 763 | # Clear TP states |
| 764 | self._tp_state_map_per_uni[uni_id][tp_id].reset_tp_state() |
| 765 | del self._tp_state_map_per_uni[uni_id][tp_id] |
| 766 | |
| 767 | def delete_tech_profile(self, uni_id, tp_path, tcont=None, gem_port=None): |
| 768 | alloc_id = None |
| 769 | gem_port_id = None |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 770 | try: |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 771 | tp_table_id = self.extract_tp_id_from_path(tp_path) |
Girish Gowdra | ba4b181 | 2020-07-17 12:21:26 -0700 | [diff] [blame] | 772 | # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are |
| 773 | # relevant to this task's UNI. It won't change. But, the underlying pon_port may change |
| 774 | # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter |
| 775 | # this initializer |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 776 | alloc_id = tcont.alloc_id if tcont is not None else None |
| 777 | gem_port_id = gem_port.gem_id if gem_port is not None else None |
| 778 | self._clear_alloc_id_gem_port_from_internal_cache(alloc_id, gem_port_id) |
Girish Gowdra | ba4b181 | 2020-07-17 12:21:26 -0700 | [diff] [blame] | 779 | |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 780 | if tp_table_id not in self._tp_state_map_per_uni[uni_id]: |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 781 | 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] | 782 | return |
| 783 | |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 784 | if self._tp_state_map_per_uni[uni_id][tp_table_id].tp_setup_done is not True: |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 785 | self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete", uni_id=uni_id, |
| 786 | tp_id=tp_table_id) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 787 | return |
| 788 | |
| 789 | if alloc_id is None and gem_port_id is None: |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 790 | 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] | 791 | return |
| 792 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 793 | @inlineCallbacks |
| 794 | def success(_results): |
| 795 | if gem_port_id: |
| 796 | self.log.info("gem-port-delete-done-successfully") |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 797 | self._tp_state_map_per_uni[uni_id][tp_table_id].pon_resource_delete_complete(TpState.GEM_ID, |
| 798 | gem_port_id) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 799 | if alloc_id: |
| 800 | self.log.info("tcont-delete-done-successfully") |
| 801 | # The deletion of TCONT marks the complete deletion of tech-profile |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 802 | self._tp_state_map_per_uni[uni_id][tp_table_id].pon_resource_delete_complete(TpState.ALLOC_ID, |
| 803 | alloc_id) |
| 804 | self._tcont_delete_complete(uni_id, tp_table_id) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 805 | |
| 806 | # TODO: There could be multiple TP on the UNI, and also the ONU. |
| 807 | # TODO: But the below reason updates for the whole device. |
| 808 | yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success') |
| 809 | |
| 810 | @inlineCallbacks |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 811 | def failure(_reason): |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 812 | self.log.warn('tech-profile-delete-failure-retrying', |
| 813 | _reason=_reason) |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 814 | retry = random.randint(1, 5) |
| 815 | _tcont = self._tp_state_map_per_uni[uni_id][tp_table_id].get_queued_resource_for_delete(TpState.ALLOC_ID, alloc_id) |
| 816 | _gem_port = self._tp_state_map_per_uni[uni_id][tp_table_id].get_queued_resource_for_delete(TpState.GEM_ID, gem_port_id) |
| 817 | reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, _tcont, _gem_port) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 818 | yield self.core_proxy.device_reason_update(self.device_id, |
| 819 | 'tech-profile-config-delete-failure-retrying') |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 820 | |
| 821 | self.log.info('deleting-tech-profile-configuration') |
| 822 | |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 823 | if tcont is None and gem_port is None: |
| 824 | if alloc_id is not None: |
| 825 | self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id) |
| 826 | if gem_port_id is not None: |
| 827 | self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id) |
| 828 | return |
| 829 | |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 830 | self._tp_state_map_per_uni[uni_id][tp_table_id].tp_task_ref = \ |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 831 | BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id, |
| 832 | tcont=tcont, gem_port=gem_port) |
| 833 | self._deferred = \ |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 834 | self._onu_omci_device.task_runner.queue_task(self._tp_state_map_per_uni[uni_id][tp_table_id]. |
| 835 | tp_task_ref) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 836 | self._deferred.addCallbacks(success, failure) |
| 837 | except Exception as e: |
| 838 | self.log.exception("failed-to-delete-tp", |
| 839 | e=e, uni_id=uni_id, tp_path=tp_path, |
| 840 | alloc_id=alloc_id, gem_port_id=gem_port_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 841 | |
Rohan Agrawal | f0f8c29 | 2020-06-01 09:30:55 +0000 | [diff] [blame] | 842 | def update_pm_config(self, device, pm_configs): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 843 | # TODO: This has not been tested |
Rohan Agrawal | f0f8c29 | 2020-06-01 09:30:55 +0000 | [diff] [blame] | 844 | self.log.info('update_pm_config', pm_configs=pm_configs) |
| 845 | self._pm_metrics.update(pm_configs) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 846 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 847 | def remove_onu_flows(self, device, flows): |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame] | 848 | self.log.debug('remove-onu-flows') |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 849 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 850 | # no point in removing omci flows if the device isnt reachable |
| 851 | if device.connect_status != ConnectStatus.REACHABLE or \ |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 852 | device.admin_state != AdminState.ENABLED: |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 853 | self.log.warn("device-disabled-or-offline-skipping-remove-flow", |
| 854 | admin=device.admin_state, connect=device.connect_status) |
| 855 | return |
| 856 | |
| 857 | for flow in flows: |
| 858 | # if incoming flow contains cookie, then remove from ONU |
| 859 | if flow.cookie: |
| 860 | self.log.debug("remove-flow", device_id=device.id, flow=flow) |
| 861 | |
| 862 | def is_downstream(port): |
| 863 | return port == self._pon_port_number |
| 864 | |
| 865 | def is_upstream(port): |
| 866 | return not is_downstream(port) |
| 867 | |
| 868 | try: |
| 869 | _in_port = fd.get_in_port(flow) |
| 870 | assert _in_port is not None |
| 871 | |
| 872 | _out_port = fd.get_out_port(flow) # may be None |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 873 | |
| 874 | if is_downstream(_in_port): |
| 875 | self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port, |
| 876 | device_id=device.id) |
| 877 | # extended vlan tagging operation will handle it |
| 878 | continue |
| 879 | elif is_upstream(_in_port): |
| 880 | self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port) |
| 881 | if fd.is_dhcp_flow(flow): |
| 882 | self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id) |
| 883 | return |
| 884 | |
Mahir Gunyel | 45610b4 | 2020-03-16 17:29:01 -0700 | [diff] [blame] | 885 | _match_vlan_vid = None |
| 886 | for field in fd.get_ofb_fields(flow): |
| 887 | if field.type == fd.VLAN_VID: |
| 888 | if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN: |
| 889 | _match_vlan_vid = RESERVED_TRANSPARENT_VLAN |
| 890 | else: |
| 891 | _match_vlan_vid = field.vlan_vid & 0xfff |
| 892 | self.log.debug('field-type-vlan-vid', |
| 893 | vlan=_match_vlan_vid) |
| 894 | |
| 895 | _set_vlan_vid = None |
| 896 | _set_vlan_pcp = None |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 897 | # Retrieve the VLAN_VID that needs to be removed from the EVTO rule on the ONU. |
| 898 | for action in fd.get_actions(flow): |
| 899 | if action.type == fd.SET_FIELD: |
| 900 | _field = action.set_field.field.ofb_field |
| 901 | assert (action.set_field.field.oxm_class == |
| 902 | OFPXMC_OPENFLOW_BASIC) |
| 903 | if _field.type == fd.VLAN_VID: |
Mahir Gunyel | 45610b4 | 2020-03-16 17:29:01 -0700 | [diff] [blame] | 904 | _set_vlan_vid = _field.vlan_vid & 0xfff |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 905 | self.log.debug('vlan-vid-to-remove', |
Mahir Gunyel | 45610b4 | 2020-03-16 17:29:01 -0700 | [diff] [blame] | 906 | _vlan_vid=_set_vlan_vid, in_port=_in_port) |
| 907 | elif _field.type == fd.VLAN_PCP: |
| 908 | _set_vlan_pcp = _field.vlan_pcp |
| 909 | self.log.debug('set-field-type-vlan-pcp', |
| 910 | vlan_pcp=_set_vlan_pcp) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 911 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 912 | uni_port = self.uni_port(_in_port) |
| 913 | uni_id = _in_port & 0xF |
| 914 | else: |
| 915 | raise Exception('port should be 1 or 2 by our convention') |
| 916 | |
| 917 | self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port)) |
| 918 | |
| 919 | tp_id = self.get_tp_id_in_flow(flow) |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 920 | # The vlan filter remove should be followed by a TP deleted for that TP ID. |
| 921 | # Use this information to re-schedule any vlan filter add tasks for the same TP ID again. |
| 922 | # First check if the TP download was done, before we access that TP delete is necessary |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 923 | if tp_id in self._tp_state_map_per_uni[uni_id] and \ |
| 924 | self._tp_state_map_per_uni[uni_id][tp_id].tp_setup_done is True: |
| 925 | self._tp_state_map_per_uni[uni_id][tp_id].is_tp_delete_pending = True |
| 926 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 927 | # Deleting flow from ONU. |
Mahir Gunyel | 45610b4 | 2020-03-16 17:29:01 -0700 | [diff] [blame] | 928 | self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, |
| 929 | _set_vlan_pcp=_set_vlan_pcp, |
| 930 | _set_vlan_vid=_set_vlan_vid, |
| 931 | match_vlan=_match_vlan_vid, |
| 932 | tp_id=tp_id) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 933 | # TODO:Delete TD task. |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 934 | except Exception as e: |
| 935 | self.log.exception('failed-to-remove-flow', e=e) |
| 936 | |
| 937 | def add_onu_flows(self, device, flows): |
Matt Jeanneret | 2ca384f | 2020-03-06 13:49:31 -0500 | [diff] [blame] | 938 | self.log.debug('add-onu-flows') |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 939 | |
| 940 | # no point in pushing omci flows if the device isnt reachable |
| 941 | if device.connect_status != ConnectStatus.REACHABLE or \ |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 942 | device.admin_state != AdminState.ENABLED: |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 943 | self.log.warn("device-disabled-or-offline-skipping-flow-update", |
| 944 | admin=device.admin_state, connect=device.connect_status) |
| 945 | return |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 946 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 947 | def is_downstream(port): |
| 948 | return port == self._pon_port_number |
| 949 | |
| 950 | def is_upstream(port): |
| 951 | return not is_downstream(port) |
| 952 | |
| 953 | for flow in flows: |
| 954 | # if incoming flow contains cookie, then add to ONU |
| 955 | if flow.cookie: |
| 956 | _type = None |
| 957 | _port = None |
| 958 | _vlan_vid = None |
| 959 | _udp_dst = None |
| 960 | _udp_src = None |
| 961 | _ipv4_dst = None |
| 962 | _ipv4_src = None |
| 963 | _metadata = None |
| 964 | _output = None |
| 965 | _push_tpid = None |
| 966 | _field = None |
| 967 | _set_vlan_vid = None |
Mahir Gunyel | 45610b4 | 2020-03-16 17:29:01 -0700 | [diff] [blame] | 968 | _set_vlan_pcp = None |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 969 | _tunnel_id = None |
Girish Gowdra | 6a73ad6 | 2020-06-11 13:40:16 -0700 | [diff] [blame] | 970 | _proto = -1 |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 971 | self.log.debug("add-flow", device_id=device.id, flow=flow) |
| 972 | |
| 973 | try: |
| 974 | _in_port = fd.get_in_port(flow) |
| 975 | assert _in_port is not None |
| 976 | |
| 977 | _out_port = fd.get_out_port(flow) # may be None |
| 978 | tp_id = self.get_tp_id_in_flow(flow) |
| 979 | if is_downstream(_in_port): |
| 980 | self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port) |
| 981 | # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow |
| 982 | # uni_port = self.uni_port(_out_port) |
| 983 | # uni_id = _out_port & 0xF |
| 984 | continue |
| 985 | elif is_upstream(_in_port): |
| 986 | self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port) |
| 987 | uni_port = self.uni_port(_in_port) |
| 988 | uni_id = _in_port & 0xF |
| 989 | else: |
| 990 | raise Exception('port should be 1 or 2 by our convention') |
| 991 | |
| 992 | self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port)) |
| 993 | |
| 994 | for field in fd.get_ofb_fields(flow): |
| 995 | if field.type == fd.ETH_TYPE: |
| 996 | _type = field.eth_type |
| 997 | self.log.debug('field-type-eth-type', |
| 998 | eth_type=_type) |
| 999 | |
| 1000 | elif field.type == fd.IP_PROTO: |
| 1001 | _proto = field.ip_proto |
Girish Gowdra | 6a73ad6 | 2020-06-11 13:40:16 -0700 | [diff] [blame] | 1002 | if _proto == 2: |
| 1003 | # Workaround for TT workflow - avoids installing invalid EVTO rule |
| 1004 | self.log.debug("igmp-trap-flow") |
| 1005 | break |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1006 | self.log.debug('field-type-ip-proto', |
| 1007 | ip_proto=_proto) |
| 1008 | |
| 1009 | elif field.type == fd.IN_PORT: |
| 1010 | _port = field.port |
| 1011 | self.log.debug('field-type-in-port', |
| 1012 | in_port=_port) |
| 1013 | elif field.type == fd.TUNNEL_ID: |
| 1014 | self.log.debug('field-type-tunnel-id') |
| 1015 | |
| 1016 | elif field.type == fd.VLAN_VID: |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1017 | if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN: |
| 1018 | _vlan_vid = RESERVED_TRANSPARENT_VLAN |
| 1019 | else: |
| 1020 | _vlan_vid = field.vlan_vid & 0xfff |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1021 | self.log.debug('field-type-vlan-vid', |
| 1022 | vlan=_vlan_vid) |
| 1023 | |
| 1024 | elif field.type == fd.VLAN_PCP: |
| 1025 | _vlan_pcp = field.vlan_pcp |
| 1026 | self.log.debug('field-type-vlan-pcp', |
| 1027 | pcp=_vlan_pcp) |
| 1028 | |
| 1029 | elif field.type == fd.UDP_DST: |
| 1030 | _udp_dst = field.udp_dst |
| 1031 | self.log.debug('field-type-udp-dst', |
| 1032 | udp_dst=_udp_dst) |
| 1033 | |
| 1034 | elif field.type == fd.UDP_SRC: |
| 1035 | _udp_src = field.udp_src |
| 1036 | self.log.debug('field-type-udp-src', |
| 1037 | udp_src=_udp_src) |
| 1038 | |
| 1039 | elif field.type == fd.IPV4_DST: |
| 1040 | _ipv4_dst = field.ipv4_dst |
| 1041 | self.log.debug('field-type-ipv4-dst', |
| 1042 | ipv4_dst=_ipv4_dst) |
| 1043 | |
| 1044 | elif field.type == fd.IPV4_SRC: |
| 1045 | _ipv4_src = field.ipv4_src |
| 1046 | self.log.debug('field-type-ipv4-src', |
| 1047 | ipv4_dst=_ipv4_src) |
| 1048 | |
| 1049 | elif field.type == fd.METADATA: |
| 1050 | _metadata = field.table_metadata |
| 1051 | self.log.debug('field-type-metadata', |
| 1052 | metadata=_metadata) |
| 1053 | |
| 1054 | else: |
| 1055 | raise NotImplementedError('field.type={}'.format( |
| 1056 | field.type)) |
| 1057 | |
Girish Gowdra | 6a73ad6 | 2020-06-11 13:40:16 -0700 | [diff] [blame] | 1058 | if _proto == 2: |
| 1059 | # Workaround for TT workflow - avoids installing invalid EVTO rule |
| 1060 | self.log.warn("skipping-igmp-trap-flow") |
| 1061 | continue |
| 1062 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1063 | for action in fd.get_actions(flow): |
| 1064 | |
| 1065 | if action.type == fd.OUTPUT: |
| 1066 | _output = action.output.port |
| 1067 | self.log.debug('action-type-output', |
| 1068 | output=_output, in_port=_in_port) |
| 1069 | |
| 1070 | elif action.type == fd.POP_VLAN: |
| 1071 | self.log.debug('action-type-pop-vlan', |
| 1072 | in_port=_in_port) |
| 1073 | |
| 1074 | elif action.type == fd.PUSH_VLAN: |
| 1075 | _push_tpid = action.push.ethertype |
| 1076 | self.log.debug('action-type-push-vlan', |
| 1077 | push_tpid=_push_tpid, in_port=_in_port) |
| 1078 | if action.push.ethertype != 0x8100: |
| 1079 | self.log.error('unhandled-tpid', |
| 1080 | ethertype=action.push.ethertype) |
| 1081 | |
| 1082 | elif action.type == fd.SET_FIELD: |
| 1083 | _field = action.set_field.field.ofb_field |
| 1084 | assert (action.set_field.field.oxm_class == |
| 1085 | OFPXMC_OPENFLOW_BASIC) |
| 1086 | self.log.debug('action-type-set-field', |
| 1087 | field=_field, in_port=_in_port) |
| 1088 | if _field.type == fd.VLAN_VID: |
| 1089 | _set_vlan_vid = _field.vlan_vid & 0xfff |
| 1090 | self.log.debug('set-field-type-vlan-vid', |
| 1091 | vlan_vid=_set_vlan_vid) |
| 1092 | elif _field.type == fd.VLAN_PCP: |
| 1093 | _set_vlan_pcp = _field.vlan_pcp |
| 1094 | self.log.debug('set-field-type-vlan-pcp', |
| 1095 | vlan_pcp=_set_vlan_pcp) |
| 1096 | else: |
| 1097 | self.log.error('unsupported-action-set-field-type', |
| 1098 | field_type=_field.type) |
| 1099 | else: |
| 1100 | self.log.error('unsupported-action-type', |
| 1101 | action_type=action.type, in_port=_in_port) |
| 1102 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 1103 | if self._set_vlan is not None: |
| 1104 | if uni_id not in self._set_vlan: |
| 1105 | self._set_vlan[uni_id] = dict() |
| 1106 | self._set_vlan[uni_id][tp_id] = _set_vlan_vid |
| 1107 | self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id) |
| 1108 | |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1109 | # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow |
| 1110 | # supported match and action criteria cannot be handled by omci and must be ignored. |
| 1111 | if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN: |
| 1112 | self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid) |
| 1113 | elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN: |
| 1114 | 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] | 1115 | _set_vlan_vid=_vlan_vid, |
| 1116 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 1117 | tp_id=tp_id) |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1118 | self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port, |
| 1119 | _set_vlan_vid=_vlan_vid, |
| 1120 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 1121 | tp_id=tp_id) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1122 | else: |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1123 | self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid, |
| 1124 | 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] | 1125 | self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port, |
| 1126 | _set_vlan_vid=_set_vlan_vid, |
| 1127 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 1128 | tp_id=tp_id) |
| 1129 | |
| 1130 | except Exception as e: |
| 1131 | self.log.exception('failed-to-install-flow', e=e, flow=flow) |
| 1132 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1133 | # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from |
| 1134 | # flow decomposition that ultimately comes from onos |
| 1135 | def update_flow_table(self, device, flows): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1136 | 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] | 1137 | |
| 1138 | # |
| 1139 | # We need to proxy through the OLT to get to the ONU |
| 1140 | # Configuration from here should be using OMCI |
| 1141 | # |
| 1142 | # self.log.info('bulk-flow-update', device_id=device.id, flows=flows) |
| 1143 | |
| 1144 | # no point in pushing omci flows if the device isnt reachable |
| 1145 | if device.connect_status != ConnectStatus.REACHABLE or \ |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1146 | device.admin_state != AdminState.ENABLED: |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1147 | self.log.warn("device-disabled-or-offline-skipping-flow-update", |
| 1148 | admin=device.admin_state, connect=device.connect_status) |
| 1149 | return |
| 1150 | |
| 1151 | def is_downstream(port): |
| 1152 | return port == self._pon_port_number |
| 1153 | |
| 1154 | def is_upstream(port): |
| 1155 | return not is_downstream(port) |
| 1156 | |
| 1157 | for flow in flows: |
| 1158 | _type = None |
| 1159 | _port = None |
| 1160 | _vlan_vid = None |
| 1161 | _udp_dst = None |
| 1162 | _udp_src = None |
| 1163 | _ipv4_dst = None |
| 1164 | _ipv4_src = None |
| 1165 | _metadata = None |
| 1166 | _output = None |
| 1167 | _push_tpid = None |
| 1168 | _field = None |
| 1169 | _set_vlan_vid = None |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1170 | _set_vlan_pcp = None |
Matt Jeanneret | ef06d0d | 2019-04-27 17:36:53 -0400 | [diff] [blame] | 1171 | _tunnel_id = None |
| 1172 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1173 | try: |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 1174 | write_metadata = fd.get_write_metadata(flow) |
| 1175 | if write_metadata is None: |
| 1176 | self.log.error("do-not-process-flow-without-write-metadata") |
| 1177 | return |
| 1178 | |
| 1179 | # extract tp id from flow |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1180 | tp_id = self.get_tp_id_in_flow(flow) |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 1181 | self.log.debug("tp-id-in-flow", tp_id=tp_id) |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 1182 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1183 | _in_port = fd.get_in_port(flow) |
| 1184 | assert _in_port is not None |
| 1185 | |
| 1186 | _out_port = fd.get_out_port(flow) # may be None |
| 1187 | |
| 1188 | if is_downstream(_in_port): |
| 1189 | self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port) |
| 1190 | uni_port = self.uni_port(_out_port) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1191 | uni_id = _out_port & 0xF |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1192 | elif is_upstream(_in_port): |
| 1193 | self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port) |
| 1194 | uni_port = self.uni_port(_in_port) |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 1195 | uni_id = _in_port & 0xF |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1196 | else: |
| 1197 | raise Exception('port should be 1 or 2 by our convention') |
| 1198 | |
| 1199 | self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port)) |
| 1200 | |
| 1201 | for field in fd.get_ofb_fields(flow): |
| 1202 | if field.type == fd.ETH_TYPE: |
| 1203 | _type = field.eth_type |
| 1204 | self.log.debug('field-type-eth-type', |
| 1205 | eth_type=_type) |
| 1206 | |
| 1207 | elif field.type == fd.IP_PROTO: |
| 1208 | _proto = field.ip_proto |
| 1209 | self.log.debug('field-type-ip-proto', |
| 1210 | ip_proto=_proto) |
| 1211 | |
| 1212 | elif field.type == fd.IN_PORT: |
| 1213 | _port = field.port |
| 1214 | self.log.debug('field-type-in-port', |
| 1215 | in_port=_port) |
| 1216 | |
| 1217 | elif field.type == fd.VLAN_VID: |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1218 | if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN: |
| 1219 | _vlan_vid = RESERVED_TRANSPARENT_VLAN |
| 1220 | else: |
| 1221 | _vlan_vid = field.vlan_vid & 0xfff |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1222 | self.log.debug('field-type-vlan-vid', |
| 1223 | vlan=_vlan_vid) |
| 1224 | |
| 1225 | elif field.type == fd.VLAN_PCP: |
| 1226 | _vlan_pcp = field.vlan_pcp |
| 1227 | self.log.debug('field-type-vlan-pcp', |
| 1228 | pcp=_vlan_pcp) |
| 1229 | |
| 1230 | elif field.type == fd.UDP_DST: |
| 1231 | _udp_dst = field.udp_dst |
| 1232 | self.log.debug('field-type-udp-dst', |
| 1233 | udp_dst=_udp_dst) |
| 1234 | |
| 1235 | elif field.type == fd.UDP_SRC: |
| 1236 | _udp_src = field.udp_src |
| 1237 | self.log.debug('field-type-udp-src', |
| 1238 | udp_src=_udp_src) |
| 1239 | |
| 1240 | elif field.type == fd.IPV4_DST: |
| 1241 | _ipv4_dst = field.ipv4_dst |
| 1242 | self.log.debug('field-type-ipv4-dst', |
| 1243 | ipv4_dst=_ipv4_dst) |
| 1244 | |
| 1245 | elif field.type == fd.IPV4_SRC: |
| 1246 | _ipv4_src = field.ipv4_src |
| 1247 | self.log.debug('field-type-ipv4-src', |
| 1248 | ipv4_dst=_ipv4_src) |
| 1249 | |
| 1250 | elif field.type == fd.METADATA: |
| 1251 | _metadata = field.table_metadata |
| 1252 | self.log.debug('field-type-metadata', |
| 1253 | metadata=_metadata) |
| 1254 | |
Matt Jeanneret | ef06d0d | 2019-04-27 17:36:53 -0400 | [diff] [blame] | 1255 | elif field.type == fd.TUNNEL_ID: |
| 1256 | _tunnel_id = field.tunnel_id |
| 1257 | self.log.debug('field-type-tunnel-id', |
| 1258 | tunnel_id=_tunnel_id) |
| 1259 | |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1260 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1261 | else: |
| 1262 | raise NotImplementedError('field.type={}'.format( |
| 1263 | field.type)) |
| 1264 | |
| 1265 | for action in fd.get_actions(flow): |
| 1266 | |
| 1267 | if action.type == fd.OUTPUT: |
| 1268 | _output = action.output.port |
| 1269 | self.log.debug('action-type-output', |
| 1270 | output=_output, in_port=_in_port) |
| 1271 | |
| 1272 | elif action.type == fd.POP_VLAN: |
| 1273 | self.log.debug('action-type-pop-vlan', |
| 1274 | in_port=_in_port) |
| 1275 | |
| 1276 | elif action.type == fd.PUSH_VLAN: |
| 1277 | _push_tpid = action.push.ethertype |
| 1278 | self.log.debug('action-type-push-vlan', |
| 1279 | push_tpid=_push_tpid, in_port=_in_port) |
| 1280 | if action.push.ethertype != 0x8100: |
| 1281 | self.log.error('unhandled-tpid', |
| 1282 | ethertype=action.push.ethertype) |
| 1283 | |
| 1284 | elif action.type == fd.SET_FIELD: |
| 1285 | _field = action.set_field.field.ofb_field |
| 1286 | assert (action.set_field.field.oxm_class == |
| 1287 | OFPXMC_OPENFLOW_BASIC) |
| 1288 | self.log.debug('action-type-set-field', |
| 1289 | field=_field, in_port=_in_port) |
| 1290 | if _field.type == fd.VLAN_VID: |
| 1291 | _set_vlan_vid = _field.vlan_vid & 0xfff |
| 1292 | self.log.debug('set-field-type-vlan-vid', |
| 1293 | vlan_vid=_set_vlan_vid) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1294 | elif _field.type == fd.VLAN_PCP: |
| 1295 | _set_vlan_pcp = _field.vlan_pcp |
| 1296 | self.log.debug('set-field-type-vlan-pcp', |
| 1297 | vlan_pcp=_set_vlan_pcp) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1298 | else: |
| 1299 | self.log.error('unsupported-action-set-field-type', |
| 1300 | field_type=_field.type) |
| 1301 | else: |
| 1302 | self.log.error('unsupported-action-type', |
| 1303 | action_type=action.type, in_port=_in_port) |
| 1304 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 1305 | if self._set_vlan is not None: |
| 1306 | if uni_id not in self._set_vlan: |
| 1307 | self._set_vlan[uni_id] = dict() |
| 1308 | self._set_vlan[uni_id][tp_id] = _set_vlan_vid |
| 1309 | 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] | 1310 | # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow |
| 1311 | # 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] | 1312 | if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN: |
| 1313 | self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid) |
| 1314 | elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN: |
| 1315 | 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] | 1316 | _set_vlan_vid=_vlan_vid, |
| 1317 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 1318 | tp_id=tp_id) |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1319 | self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port, |
| 1320 | _set_vlan_vid=_vlan_vid, |
| 1321 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 1322 | tp_id=tp_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1323 | else: |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 1324 | self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid, |
| 1325 | set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type) |
| 1326 | self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port, |
| 1327 | _set_vlan_vid=_set_vlan_vid, |
| 1328 | _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid, |
| 1329 | tp_id=tp_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1330 | except Exception as e: |
| 1331 | self.log.exception('failed-to-install-flow', e=e, flow=flow) |
| 1332 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1333 | 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] | 1334 | _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0): |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1335 | if tp_id in self._tp_state_map_per_uni[uni_id] and \ |
| 1336 | self._tp_state_map_per_uni[uni_id][tp_id].is_tp_delete_pending is True: |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 1337 | self.log.debug("pending-del-tp--scheduling-add-vlan-filter-task-for-later") |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1338 | retry = random.randint(1, 5) |
| 1339 | reactor.callLater(retry, self._add_vlan_filter_task, device, uni_id, uni_port, match_vlan, |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 1340 | _set_vlan_vid, _set_vlan_pcp, tp_id) |
| 1341 | return |
| 1342 | |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1343 | self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan, |
| 1344 | vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1345 | assert uni_port is not None |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1346 | if tp_id in self._tp_state_map_per_uni[uni_id] and \ |
| 1347 | self._tp_state_map_per_uni[uni_id][tp_id].tp_setup_done is True: |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 1348 | @inlineCallbacks |
| 1349 | def success(_results): |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1350 | self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id, |
| 1351 | set_vlan_pcp=_set_vlan_pcp) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 1352 | 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] | 1353 | |
Chaitrashree G S | 8fb9678 | 2019-08-19 00:10:49 -0400 | [diff] [blame] | 1354 | @inlineCallbacks |
| 1355 | def failure(_reason): |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 1356 | self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id) |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1357 | retry = random.randint(1, 5) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1358 | reactor.callLater(retry, |
| 1359 | self._add_vlan_filter_task, device, uni_id, uni_port=uni_port, |
| 1360 | match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid, |
| 1361 | _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id) |
Matt Jeanneret | d84c907 | 2020-01-31 06:33:27 -0500 | [diff] [blame] | 1362 | 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] | 1363 | |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1364 | self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan, |
| 1365 | vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1366 | 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] | 1367 | match_vlan, _set_vlan_pcp, add_tag=True, |
| 1368 | tp_id=tp_id) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1369 | 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] | 1370 | self._deferred.addCallbacks(success, failure) |
| 1371 | else: |
| 1372 | 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] | 1373 | uni_id=uni_id, tp_id=tp_id) |
| 1374 | if uni_id not in self._queued_vlan_filter_task: |
| 1375 | self._queued_vlan_filter_task[uni_id] = dict() |
Mahir Gunyel | a982ec3 | 2020-02-25 12:30:37 -0800 | [diff] [blame] | 1376 | if tp_id not in self._queued_vlan_filter_task[uni_id]: |
| 1377 | self._queued_vlan_filter_task[uni_id][tp_id] = [] |
| 1378 | self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1379 | "uni_id": uni_id, |
| 1380 | "uni_port": uni_port, |
| 1381 | "match_vlan": match_vlan, |
| 1382 | "set_vlan_vid": _set_vlan_vid, |
| 1383 | "set_vlan_pcp": _set_vlan_pcp, |
| 1384 | "tp_id": tp_id}) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1385 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1386 | def get_tp_id_in_flow(self, flow): |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1387 | flow_metadata = fd.get_metadata_from_write_metadata(flow) |
| 1388 | tp_id = fd.get_tp_id_from_metadata(flow_metadata) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1389 | return tp_id |
| 1390 | |
| 1391 | 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] | 1392 | _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0): |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1393 | assert uni_port is not None |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1394 | |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1395 | @inlineCallbacks |
| 1396 | def success(_results): |
| 1397 | self.log.info('vlan-untagging-success', _results=_results) |
| 1398 | yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted') |
| 1399 | |
| 1400 | @inlineCallbacks |
| 1401 | def failure(_reason): |
| 1402 | self.log.warn('vlan-untagging-failure', _reason=_reason) |
| 1403 | yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying') |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1404 | retry = random.randint(1, 5) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1405 | reactor.callLater(retry, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1406 | self._remove_vlan_filter_task, device, uni_id, |
ozgecanetsia | ce4e37f | 2020-07-20 10:16:00 +0300 | [diff] [blame] | 1407 | uni_port=uni_port, match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid, |
| 1408 | _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1409 | |
| 1410 | self.log.info("remove_vlan_filter_task", tp_id=tp_id) |
| 1411 | 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] | 1412 | match_vlan, _set_vlan_pcp, add_tag=False, |
| 1413 | tp_id=tp_id) |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1414 | self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task) |
| 1415 | self._deferred.addCallbacks(success, failure) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1416 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1417 | @inlineCallbacks |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1418 | def process_inter_adapter_message(self, request): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1419 | self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic, |
| 1420 | to_topic=request.header.to_topic, to_device_id=request.header.to_device_id) |
Matt Jeanneret | 2101f3d | 2020-03-12 10:13:06 -0400 | [diff] [blame] | 1421 | |
| 1422 | if not self.enabled: |
| 1423 | self.log.warn('device-not-activated') |
| 1424 | reactor.callLater(0.5, self.process_inter_adapter_message, request) |
| 1425 | return |
| 1426 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1427 | try: |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1428 | |
| 1429 | update_onu_state = False |
| 1430 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1431 | if request.header.type == InterAdapterMessageType.OMCI_REQUEST: |
| 1432 | omci_msg = InterAdapterOmciMessage() |
| 1433 | request.body.Unpack(omci_msg) |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1434 | 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] | 1435 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1436 | self.receive_message(omci_msg.message) |
| 1437 | |
| 1438 | elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST: |
| 1439 | onu_indication = OnuIndication() |
| 1440 | request.body.Unpack(onu_indication) |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1441 | self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id, |
| 1442 | oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state, |
| 1443 | serial_number=onu_indication.serial_number) |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1444 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1445 | update_onu_state = True |
| 1446 | self._onu_persisted_state['onu_id'] = onu_indication.onu_id |
| 1447 | self._onu_persisted_state['intf_id'] = onu_indication.intf_id |
| 1448 | self._onu_persisted_state['admin_state'] = onu_indication.admin_state |
Mahir Gunyel | 45610b4 | 2020-03-16 17:29:01 -0700 | [diff] [blame] | 1449 | self._onu_persisted_state['oper_state'] = onu_indication.oper_state |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1450 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1451 | if onu_indication.oper_state == "up": |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1452 | yield self.create_interface(onu_indication) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1453 | elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable": |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1454 | yield self.update_interface(onu_indication) |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1455 | else: |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1456 | self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id, |
| 1457 | serial_number=onu_indication.serial_number) |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1458 | |
Matt Jeanneret | 3bfebff | 2019-04-12 18:25:03 -0400 | [diff] [blame] | 1459 | elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST: |
| 1460 | tech_msg = InterAdapterTechProfileDownloadMessage() |
| 1461 | request.body.Unpack(tech_msg) |
| 1462 | self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg) |
| 1463 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1464 | update_onu_state = self._update_onu_persisted_state(tech_msg.uni_id, tp_path=tech_msg.path) |
| 1465 | yield self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path) |
Matt Jeanneret | 3bfebff | 2019-04-12 18:25:03 -0400 | [diff] [blame] | 1466 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1467 | elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST: |
| 1468 | del_gem_msg = InterAdapterDeleteGemPortMessage() |
| 1469 | request.body.Unpack(del_gem_msg) |
| 1470 | self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg) |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1471 | tp_id = self.extract_tp_id_from_path(del_gem_msg.tp_path) |
| 1472 | uni_id = del_gem_msg.uni_id |
| 1473 | gem_port = self._pon.get_gem_port(del_gem_msg.gem_port_id) |
| 1474 | self._tp_state_map_per_uni[uni_id][tp_id].queue_pending_delete_pon_resource(TpState.GEM_ID, |
| 1475 | gem_port) |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame] | 1476 | if self.is_device_active_and_reachable: |
| 1477 | self.delete_tech_profile(uni_id=del_gem_msg.uni_id, |
| 1478 | gem_port=gem_port, |
| 1479 | tp_path=del_gem_msg.tp_path) |
| 1480 | else: |
| 1481 | self.log.debug("device-unreachable--clearing-gem-id-from-local-cache") |
| 1482 | if tp_id in self._tp_state_map_per_uni[uni_id]: |
| 1483 | self._tp_state_map_per_uni[uni_id][tp_id].pon_resource_delete_complete(TpState.GEM_ID, |
| 1484 | gem_port.gem_id) |
| 1485 | self._clear_alloc_id_gem_port_from_internal_cache(None, gem_port.gem_id) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1486 | |
| 1487 | elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST: |
| 1488 | del_tcont_msg = InterAdapterDeleteTcontMessage() |
| 1489 | request.body.Unpack(del_tcont_msg) |
| 1490 | self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg) |
| 1491 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1492 | # Removal of the tcont/alloc id mapping represents the removal of the tech profile |
| 1493 | update_onu_state = self._update_onu_persisted_state(del_tcont_msg.uni_id, tp_path=None) |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1494 | tp_id = self.extract_tp_id_from_path(del_tcont_msg.tp_path) |
| 1495 | uni_id = del_tcont_msg.uni_id |
| 1496 | tcont = self._pon.get_tcont(del_tcont_msg.alloc_id) |
| 1497 | self._tp_state_map_per_uni[uni_id][tp_id].queue_pending_delete_pon_resource(TpState.ALLOC_ID, |
| 1498 | tcont) |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame] | 1499 | if self.is_device_active_and_reachable: |
| 1500 | self.delete_tech_profile(uni_id=del_tcont_msg.uni_id, |
| 1501 | tcont=tcont, |
| 1502 | tp_path=del_tcont_msg.tp_path) |
| 1503 | else: |
| 1504 | self.log.debug("device-unreachable--clearing-tcont-from-local-cache") |
| 1505 | if tp_id in self._tp_state_map_per_uni[uni_id]: |
| 1506 | self._tp_state_map_per_uni[uni_id][tp_id].pon_resource_delete_complete(TpState.ALLOC_ID, |
| 1507 | tcont.alloc_id) |
| 1508 | self._tp_state_map_per_uni[uni_id][tp_id].tp_setup_done = False |
| 1509 | self._clear_alloc_id_gem_port_from_internal_cache(tcont.alloc_id, None) |
| 1510 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1511 | else: |
| 1512 | self.log.error("inter-adapter-unhandled-type", request=request) |
| 1513 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1514 | if update_onu_state: |
| 1515 | try: |
| 1516 | self.log.debug('updating-onu-state', device_id=self.device_id, |
| 1517 | onu_persisted_state=self._onu_persisted_state) |
| 1518 | yield self.onu_kv_client.set(self.device_id, json.dumps(self._onu_persisted_state)) |
| 1519 | except Exception as e: |
| 1520 | self.log.error('could-not-store-onu-state', device_id=self.device_id, |
| 1521 | onu_persisted_state=self._onu_persisted_state, e=e) |
| 1522 | # at this point omci is started and/or indications being processed |
| 1523 | # later indications may have a chance to write this state out again |
| 1524 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1525 | except Exception as e: |
| 1526 | self.log.exception("error-processing-inter-adapter-message", e=e) |
| 1527 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1528 | def _update_onu_persisted_state(self, uni_id, tp_path): |
| 1529 | # persist the uni and tech profile path for later reconciliation. update only if changed |
| 1530 | update_onu_state = False |
| 1531 | found = False |
| 1532 | for entry in self._onu_persisted_state.get('uni_config', list()): |
| 1533 | if entry.get('uni_id') == uni_id: |
| 1534 | found = True |
| 1535 | if entry.get('tp_path') != tp_path: |
| 1536 | update_onu_state = True |
| 1537 | entry['tp_path'] = tp_path |
| 1538 | |
| 1539 | if not found: |
| 1540 | update_onu_state = True |
| 1541 | uni_tp = { |
| 1542 | 'uni_id': uni_id, |
| 1543 | 'tp_path': tp_path |
| 1544 | } |
| 1545 | self._onu_persisted_state['uni_config'].append(uni_tp) |
| 1546 | |
| 1547 | return update_onu_state |
| 1548 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1549 | # Called each time there is an onu "up" indication from the olt handler |
| 1550 | @inlineCallbacks |
| 1551 | def create_interface(self, onu_indication): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 1552 | self.log.info('create-interface', onu_id=onu_indication.onu_id, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1553 | serial_number=onu_indication.serial_number) |
Amit Ghosh | 028eb20 | 2020-02-17 13:34:00 +0000 | [diff] [blame] | 1554 | |
| 1555 | # Ignore if onu_indication is received for an already running ONU |
| 1556 | if self._onu_omci_device is not None and self._onu_omci_device.active: |
| 1557 | self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication) |
| 1558 | return |
| 1559 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1560 | yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING, |
| 1561 | connect_status=ConnectStatus.REACHABLE) |
| 1562 | |
Matt Jeanneret | a32441c | 2019-03-07 05:16:37 -0500 | [diff] [blame] | 1563 | onu_device = yield self.core_proxy.get_device(self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1564 | |
| 1565 | self.log.debug('starting-openomci-statemachine') |
| 1566 | self._subscribe_to_events() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1567 | onu_device.reason = "starting-openomci" |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1568 | reactor.callLater(1, self._onu_omci_device.start, onu_device) |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1569 | 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] | 1570 | self._heartbeat.enabled = True |
| 1571 | |
Matt Jeanneret | 42dad79 | 2020-02-01 09:28:27 -0500 | [diff] [blame] | 1572 | # 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] | 1573 | @inlineCallbacks |
| 1574 | def update_interface(self, onu_indication): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 1575 | self.log.info('update-interface', onu_id=onu_indication.onu_id, |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1576 | serial_number=onu_indication.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1577 | |
Chaitrashree G S | d73fb9b | 2019-09-09 20:27:30 -0400 | [diff] [blame] | 1578 | if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable": |
Mahir Gunyel | d680cb6 | 2020-02-18 10:28:12 -0800 | [diff] [blame] | 1579 | self.log.debug('stopping-openomci-statemachine', device_id=self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1580 | reactor.callLater(0, self._onu_omci_device.stop) |
| 1581 | |
Mahir Gunyel | 5de33fe | 2020-03-03 22:38:44 -0800 | [diff] [blame] | 1582 | self._tp = dict() |
| 1583 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1584 | # Let TP download happen again |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1585 | for uni_id in self._tp_state_map_per_uni: |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame] | 1586 | for tp_id in self._tp_state_map_per_uni[uni_id]: |
| 1587 | self._tp_state_map_per_uni[uni_id][tp_id].tp_setup_done = False |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1588 | |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1589 | yield self.disable_ports(lock_ports=False) |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1590 | yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci") |
| 1591 | yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED, |
| 1592 | connect_status=ConnectStatus.UNREACHABLE) |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame] | 1593 | self.is_device_active_and_reachable = False |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1594 | else: |
| 1595 | self.log.debug('not-changing-openomci-statemachine') |
| 1596 | |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1597 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1598 | def disable(self, device): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 1599 | 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] | 1600 | try: |
Devmalya Paul | e2e5f2b | 2020-03-08 18:50:33 -0400 | [diff] [blame] | 1601 | yield self.disable_ports(lock_ports=True, device_disabled=True) |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1602 | yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock") |
| 1603 | yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN) |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame] | 1604 | self.is_device_active_and_reachable = False |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1605 | except Exception as e: |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1606 | self.log.exception('exception-in-onu-disable', exception=e) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1607 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1608 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1609 | def reenable(self, device): |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 1610 | 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] | 1611 | try: |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1612 | yield self.core_proxy.device_state_update(device.id, |
| 1613 | oper_status=OperStatus.ACTIVE, |
| 1614 | connect_status=ConnectStatus.REACHABLE) |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame] | 1615 | self.is_device_active_and_reachable = True |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1616 | yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled') |
| 1617 | yield self.enable_ports() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1618 | except Exception as e: |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1619 | self.log.exception('exception-in-onu-reenable', exception=e) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1620 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1621 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1622 | def reboot(self): |
| 1623 | self.log.info('reboot-device') |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1624 | device = yield self.core_proxy.get_device(self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1625 | if device.connect_status != ConnectStatus.REACHABLE: |
| 1626 | self.log.error("device-unreachable") |
| 1627 | return |
| 1628 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1629 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1630 | def success(_results): |
| 1631 | self.log.info('reboot-success', _results=_results) |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1632 | yield self.core_proxy.device_reason_update(self.device_id, 'rebooting') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1633 | |
| 1634 | def failure(_reason): |
| 1635 | self.log.info('reboot-failure', _reason=_reason) |
| 1636 | |
| 1637 | self._deferred = self._onu_omci_device.reboot() |
| 1638 | self._deferred.addCallbacks(success, failure) |
| 1639 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1640 | @inlineCallbacks |
Devmalya Paul | e2e5f2b | 2020-03-08 18:50:33 -0400 | [diff] [blame] | 1641 | def disable_ports(self, lock_ports=True, device_disabled=False): |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1642 | self.log.info('disable-ports', device_id=self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1643 | |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1644 | # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 1645 | # load on the core |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1646 | for port in self.uni_ports: |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1647 | if port.mac_bridge_port_num == 1: |
| 1648 | port.operstatus = OperStatus.UNKNOWN |
| 1649 | self.log.info('disable-port', device_id=self.device_id, port=port) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1650 | yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, |
| 1651 | port.operstatus) |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1652 | |
| 1653 | if lock_ports is True: |
Devmalya Paul | e2e5f2b | 2020-03-08 18:50:33 -0400 | [diff] [blame] | 1654 | self.lock_ports(lock=True, device_disabled=device_disabled) |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1655 | |
William Kurkian | 3a20633 | 2019-04-29 11:05:47 -0400 | [diff] [blame] | 1656 | @inlineCallbacks |
Mahir Gunyel | 0e6882a | 2019-10-16 17:02:39 -0700 | [diff] [blame] | 1657 | def enable_ports(self): |
| 1658 | self.log.info('enable-ports', device_id=self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1659 | |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1660 | self.lock_ports(lock=False) |
| 1661 | |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1662 | # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 1663 | # load on the core |
| 1664 | # 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] | 1665 | for port in self.uni_ports: |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1666 | if port.mac_bridge_port_num == 1: |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1667 | port.operstatus = OperStatus.ACTIVE |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1668 | self.log.info('enable-port', device_id=self.device_id, port=port) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1669 | yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, |
| 1670 | port.operstatus) |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1671 | |
| 1672 | # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core, |
| 1673 | # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup. |
| 1674 | # |
| 1675 | # Basically the link state sequence: |
| 1676 | # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet) |
| 1677 | # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in |
| 1678 | # 3) a link state up alarm is received for the uni plugged in. |
| 1679 | # |
| 1680 | # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession |
| 1681 | # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity |
| 1682 | # would have a ripple effect through the core to the controller as well. And is it really worth it? |
| 1683 | ''' |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 1684 | @inlineCallbacks |
| 1685 | def port_state_handler(self, _topic, msg): |
| 1686 | self.log.info("port-state-change", _topic=_topic, msg=msg) |
| 1687 | |
| 1688 | onu_id = msg['onu_id'] |
| 1689 | port_no = msg['port_number'] |
| 1690 | serial_number = msg['serial_number'] |
| 1691 | port_status = msg['port_status'] |
| 1692 | uni_port = self.uni_port(int(port_no)) |
| 1693 | |
| 1694 | self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number, |
| 1695 | port_status=port_status) |
| 1696 | |
| 1697 | if port_status is True: |
| 1698 | uni_port.operstatus = OperStatus.ACTIVE |
| 1699 | self.log.info('link-up', device_id=self.device_id, port=uni_port) |
| 1700 | else: |
| 1701 | uni_port.operstatus = OperStatus.UNKNOWN |
| 1702 | self.log.info('link-down', device_id=self.device_id, port=uni_port) |
| 1703 | |
| 1704 | 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] | 1705 | ''' |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1706 | |
| 1707 | # Called just before openomci state machine is started. These listen for events from selected state machines, |
| 1708 | # most importantly, mib in sync. Which ultimately leads to downloading the mib |
| 1709 | def _subscribe_to_events(self): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1710 | self.log.debug('subscribe-to-events') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1711 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1712 | bus = self._onu_omci_device.event_bus |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1713 | |
| 1714 | # OMCI MIB Database sync status |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1715 | topic = OnuDeviceEntry.event_bus_topic(self.device_id, |
| 1716 | OnuDeviceEvents.MibDatabaseSyncEvent) |
| 1717 | self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler) |
| 1718 | |
| 1719 | # OMCI Capabilities |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1720 | topic = OnuDeviceEntry.event_bus_topic(self.device_id, |
| 1721 | OnuDeviceEvents.OmciCapabilitiesEvent) |
| 1722 | self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler) |
| 1723 | |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1724 | # TODO: these alarms seem to be unreliable depending on the environment |
| 1725 | # 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] | 1726 | # topic = OnuDeviceEntry.event_bus_topic(self.device_id, |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1727 | # OnuDeviceEvents.PortEvent) |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 1728 | # self._port_state_subscription = bus.subscribe(topic, self.port_state_handler) |
Matt Jeanneret | fc6cdef | 2020-02-14 10:14:36 -0500 | [diff] [blame] | 1729 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1730 | # Called when the mib is in sync |
| 1731 | def in_sync_handler(self, _topic, msg): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1732 | self.log.debug('in-sync-handler', _topic=_topic, msg=msg) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1733 | if self._in_sync_subscription is not None: |
| 1734 | try: |
| 1735 | in_sync = msg[IN_SYNC_KEY] |
| 1736 | |
| 1737 | if in_sync: |
| 1738 | # Only call this once |
| 1739 | bus = self._onu_omci_device.event_bus |
| 1740 | bus.unsubscribe(self._in_sync_subscription) |
| 1741 | self._in_sync_subscription = None |
| 1742 | |
| 1743 | # Start up device_info load |
| 1744 | self.log.debug('running-mib-sync') |
| 1745 | reactor.callLater(0, self._mib_in_sync) |
| 1746 | |
| 1747 | except Exception as e: |
| 1748 | self.log.exception('in-sync', e=e) |
| 1749 | |
| 1750 | def capabilties_handler(self, _topic, _msg): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1751 | self.log.debug('capabilities-handler', _topic=_topic, msg=_msg) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1752 | if self._capabilities_subscription is not None: |
| 1753 | self.log.debug('capabilities-handler-done') |
| 1754 | |
| 1755 | # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU. |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1756 | @inlineCallbacks |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1757 | def _mib_in_sync(self): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 1758 | self.log.debug('mib-in-sync') |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1759 | device = yield self.core_proxy.get_device(self.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1760 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1761 | # only notify core if this is a new device. otherwise do not have reconcile generating |
| 1762 | # a lot of needless message churn |
| 1763 | if not self._reconciling: |
| 1764 | 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] | 1765 | |
| 1766 | if self._dev_info_loaded: |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1767 | self.log.debug('device-info-already-loaded') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1768 | else: |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1769 | # new onu or adapter was restarted. fill up our local data |
| 1770 | yield self._load_device_data(device) |
| 1771 | |
| 1772 | if self._check_mib_downloaded(): |
| 1773 | self.log.debug('mib-already-downloaded') |
| 1774 | if not self._reconciling: |
| 1775 | yield self.core_proxy.device_state_update(device.id, |
| 1776 | oper_status=OperStatus.ACTIVE, |
| 1777 | connect_status=ConnectStatus.REACHABLE) |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame] | 1778 | self.is_device_active_and_reachable = True |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1779 | yield self.enable_ports() |
| 1780 | else: |
| 1781 | self._download_mib(device) |
| 1782 | |
| 1783 | if self._reconciling: |
| 1784 | yield self._restore_tech_profile() |
| 1785 | self._start_monitoring() |
| 1786 | self._reconciling = False |
| 1787 | self.log.debug('reconcile-finished') |
| 1788 | |
| 1789 | def _download_mib(self, device): |
| 1790 | self.log.debug('downloading-initial-mib-configuration') |
| 1791 | |
| 1792 | @inlineCallbacks |
| 1793 | def success(_results): |
| 1794 | self.log.debug('mib-download-success', _results=_results) |
| 1795 | yield self.core_proxy.device_state_update(device.id, |
| 1796 | oper_status=OperStatus.ACTIVE, |
| 1797 | connect_status=ConnectStatus.REACHABLE) |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame] | 1798 | self.is_device_active_and_reachable = True |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1799 | yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded') |
| 1800 | self._mib_download_task = None |
| 1801 | yield self.enable_ports() |
| 1802 | yield self.onu_active_event() |
| 1803 | self._start_monitoring() |
| 1804 | |
| 1805 | @inlineCallbacks |
| 1806 | def failure(_reason): |
| 1807 | self.log.warn('mib-download-failure-retrying', _reason=_reason) |
| 1808 | retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 1809 | reactor.callLater(retry, self._mib_in_sync) |
| 1810 | yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying') |
| 1811 | |
| 1812 | # start by locking all the unis till mib sync and initial mib is downloaded |
| 1813 | # this way we can capture the port down/up events when we are ready |
| 1814 | self.lock_ports(lock=True) |
| 1815 | |
| 1816 | # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set |
| 1817 | # the device to active/reachable. This then opens up the handler to openflow pushes from outside |
| 1818 | self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self) |
| 1819 | self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task) |
| 1820 | self._deferred.addCallbacks(success, failure) |
| 1821 | |
| 1822 | def _start_monitoring(self): |
| 1823 | self.log.debug('starting-monitoring') |
| 1824 | |
| 1825 | # Start collecting stats from the device after a brief pause |
| 1826 | if not self._pm_metrics_started: |
| 1827 | self._pm_metrics_started = True |
Rohan Agrawal | 36a4e44 | 2020-06-29 11:10:32 +0000 | [diff] [blame] | 1828 | pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, self._pm_metrics.max_skew)) |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1829 | reactor.callLater(pmstart, self._pm_metrics.start_collector) |
| 1830 | |
| 1831 | # Start test requests after a brief pause |
| 1832 | if not self._test_request_started: |
| 1833 | self._test_request_started = True |
| 1834 | tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 1835 | reactor.callLater(tststart, self._test_request.start_collector) |
| 1836 | |
| 1837 | def _check_mib_downloaded(self): |
| 1838 | self.log.debug('checking-mib-downloaded') |
| 1839 | results = False |
| 1840 | |
| 1841 | mac_bridges = self.onu_omci_device.query_mib(MacBridgeServiceProfile.class_id) |
| 1842 | self.log.debug('mac-bridges', mac_bridges=mac_bridges) |
| 1843 | |
| 1844 | for k, v in mac_bridges.items(): |
| 1845 | if not isinstance(v, dict): |
| 1846 | continue |
| 1847 | # found at least one mac bridge, good enough to say its done, break out |
| 1848 | self.log.debug('found-mac-bridge-mib-download-has-been-done', omci_key=k, omci_value=v) |
| 1849 | results = True |
| 1850 | break |
| 1851 | |
| 1852 | return results |
| 1853 | |
| 1854 | @inlineCallbacks |
| 1855 | def _load_device_data(self, device): |
| 1856 | self.log.debug('loading-device-data-from-mib', device_id=device.id) |
| 1857 | |
| 1858 | omci_dev = self._onu_omci_device |
| 1859 | config = omci_dev.configuration |
| 1860 | |
| 1861 | try: |
| 1862 | # sort the lists so we get consistent port ordering. |
| 1863 | ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else [] |
| 1864 | uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else [] |
| 1865 | pptp_list = sorted(config.pptp_entities) if config.pptp_entities else [] |
| 1866 | veip_list = sorted(config.veip_entities) if config.veip_entities else [] |
| 1867 | |
| 1868 | if ani_list is None or (pptp_list is None and veip_list is None): |
| 1869 | yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements') |
| 1870 | raise Exception("onu-missing-required-elements") |
| 1871 | |
| 1872 | # Currently logging the ani, pptp, veip, and uni for information purposes. |
| 1873 | # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks. |
| 1874 | # And in some ONU the UNI-G list is incomplete or incorrect... |
| 1875 | for entity_id in ani_list: |
| 1876 | ani_value = config.ani_g_entities[entity_id] |
| 1877 | self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value) |
| 1878 | |
| 1879 | for entity_id in uni_list: |
| 1880 | uni_value = config.uni_g_entities[entity_id] |
| 1881 | self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value) |
| 1882 | |
| 1883 | uni_entities = OrderedDict() |
| 1884 | for entity_id in pptp_list: |
| 1885 | pptp_value = config.pptp_entities[entity_id] |
| 1886 | self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value) |
| 1887 | uni_entities[entity_id] = UniType.PPTP |
| 1888 | |
| 1889 | for entity_id in veip_list: |
| 1890 | veip_value = config.veip_entities[entity_id] |
| 1891 | self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value) |
| 1892 | uni_entities[entity_id] = UniType.VEIP |
| 1893 | |
| 1894 | uni_id = 0 |
| 1895 | for entity_id, uni_type in uni_entities.items(): |
| 1896 | yield self._add_uni_port(device, entity_id, uni_id, uni_type) |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1897 | self._tp_state_map_per_uni[uni_id] = dict() |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1898 | uni_id += 1 |
| 1899 | |
| 1900 | if self._unis: |
| 1901 | self._dev_info_loaded = True |
| 1902 | else: |
| 1903 | yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis') |
| 1904 | raise Exception("no-usable-unis") |
| 1905 | |
| 1906 | except Exception as e: |
| 1907 | self.log.exception('device-info-load', e=e) |
| 1908 | self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1909 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1910 | @inlineCallbacks |
| 1911 | def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP): |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1912 | self.log.debug('add-uni-port', entity_id=entity_id, uni_id=uni_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1913 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1914 | intf_id = self._onu_persisted_state.get('intf_id') |
| 1915 | onu_id = self._onu_persisted_state.get('onu_id') |
| 1916 | uni_no = self.mk_uni_port_num(intf_id, onu_id, uni_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1917 | |
| 1918 | # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff |
| 1919 | uni_name = "uni-{}".format(uni_no) |
| 1920 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1921 | 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] | 1922 | |
| 1923 | 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] | 1924 | 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] | 1925 | |
Girish Gowdra | 5b49934 | 2020-06-16 14:45:51 -0700 | [diff] [blame] | 1926 | uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, |
| 1927 | device.parent_port_no, device.serial_number, |
| 1928 | uni_type,) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1929 | uni_port.entity_id = entity_id |
| 1930 | uni_port.enabled = True |
| 1931 | uni_port.mac_bridge_port_num = mac_bridge_port_num |
| 1932 | |
| 1933 | self.log.debug("created-uni-port", uni=uni_port) |
| 1934 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1935 | if not self._reconciling: |
| 1936 | yield self.core_proxy.port_created(device.id, uni_port.get_port()) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1937 | |
| 1938 | self._unis[uni_port.port_number] = uni_port |
| 1939 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1940 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=onu_id, |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 1941 | uni_ports=self.uni_ports, |
| 1942 | serial_number=device.serial_number) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1943 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1944 | @inlineCallbacks |
| 1945 | def _restore_tech_profile(self): |
| 1946 | self.log.debug("reconcile-restoring-tech-profile-tcont-gem-config") |
| 1947 | |
| 1948 | # for every uni that has tech profile config reload all its tcont/alloc_id and gem from the tp path |
| 1949 | for entry in self._onu_persisted_state.get('uni_config', list()): |
| 1950 | uni_id = entry.get('uni_id') |
| 1951 | tp_path = entry.get('tp_path') |
| 1952 | if tp_path: |
| 1953 | tpstored = yield self.tp_kv_client.get(tp_path) |
| 1954 | tpstring = tpstored.decode('ascii') |
| 1955 | tp = json.loads(tpstring) |
| 1956 | |
| 1957 | self.log.debug("restoring-tp-instance", tp=tp) |
| 1958 | |
| 1959 | # re-run tech profile config that stores gem and tconts in the self._pon object |
| 1960 | # this does not actually re-run the omci, just rebuilds our local data store |
| 1961 | self._do_tech_profile_configuration(uni_id, tp) |
| 1962 | |
| 1963 | tp_id = self.extract_tp_id_from_path(tp_path) |
| 1964 | |
| 1965 | # rebuild cache dicts so tp updates and deletes dont get KeyErrors |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1966 | if uni_id not in self._tp_state_map_per_uni: |
| 1967 | self._tp_state_map_per_uni[uni_id] = dict() |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1968 | |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1969 | if tp_id not in self._tp_state_map_per_uni[uni_id]: |
| 1970 | self._tp_state_map_per_uni[uni_id][tp_id] = TpState(self, uni_id, tp_path) |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1971 | |
Girish Gowdra | c511745 | 2020-08-03 11:20:53 -0700 | [diff] [blame] | 1972 | self._tp_state_map_per_uni[uni_id][tp_id].tp_setup_done = True |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 1973 | else: |
| 1974 | self.log.debug("no-assigned-tp-instance", uni_id=uni_id) |
| 1975 | |
| 1976 | # for every loaded tcont from tp check the mib database for its entity_id |
| 1977 | # needed for later tp deletes/adds |
| 1978 | tcont_idents = self.onu_omci_device.query_mib(Tcont.class_id) |
| 1979 | self.log.debug('tcont-idents', tcont_idents=tcont_idents) |
| 1980 | |
| 1981 | for k, v in tcont_idents.items(): |
| 1982 | if not isinstance(v, dict): |
| 1983 | continue |
| 1984 | alloc_check = v.get('attributes', {}).get('alloc_id', 0) |
| 1985 | tcont = self._pon.tconts.get(alloc_check) |
| 1986 | if tcont: |
| 1987 | tcont.entity_id = k |
| 1988 | self.log.debug('reassigning-tcont-entity-id', entity_id=tcont.entity_id, |
| 1989 | alloc_id=tcont.alloc_id) |
| 1990 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1991 | # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly. |
| 1992 | def mk_uni_port_num(self, intf_id, onu_id, uni_id): |
Amit Ghosh | 65400f1 | 2019-11-21 12:04:12 +0000 | [diff] [blame] | 1993 | MAX_PONS_PER_OLT = 256 |
| 1994 | MAX_ONUS_PER_PON = 256 |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1995 | MAX_UNIS_PER_ONU = 16 |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1996 | |
Matt Jeanneret | c083f46 | 2019-03-11 15:02:01 -0400 | [diff] [blame] | 1997 | assert intf_id < MAX_PONS_PER_OLT |
| 1998 | assert onu_id < MAX_ONUS_PER_PON |
| 1999 | assert uni_id < MAX_UNIS_PER_ONU |
Amit Ghosh | 65400f1 | 2019-11-21 12:04:12 +0000 | [diff] [blame] | 2000 | return intf_id << 12 | onu_id << 4 | uni_id |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 2001 | |
| 2002 | @inlineCallbacks |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 2003 | def onu_active_event(self): |
Matteo Scandolo | d8d7317 | 2019-11-26 12:15:15 -0700 | [diff] [blame] | 2004 | self.log.debug('onu-active-event') |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 2005 | try: |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 2006 | # TODO: this is expensive for just getting the olt serial number. replace with direct api call |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 2007 | parent_device = yield self.core_proxy.get_device(self.parent_id) |
| 2008 | olt_serial_number = parent_device.serial_number |
kesavand | 86a0fcf | 2020-08-25 08:25:28 +0530 | [diff] [blame^] | 2009 | self.olt_serial_number = olt_serial_number |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 2010 | raised_ts = arrow.utcnow().timestamp |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 2011 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 2012 | intf_id = self._onu_persisted_state.get('intf_id') |
| 2013 | onu_id = self._onu_persisted_state.get('onu_id') |
| 2014 | onu_serial = self._onu_persisted_state.get('serial_number') |
| 2015 | |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 2016 | self.log.debug("onu-indication-context-data", |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 2017 | pon_id=intf_id, |
| 2018 | onu_id=onu_id, |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 2019 | registration_id=self.device_id, |
| 2020 | device_id=self.device_id, |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 2021 | onu_serial_number=onu_serial, |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 2022 | olt_serial_number=olt_serial_number, |
| 2023 | raised_ts=raised_ts) |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 2024 | |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 2025 | self.log.debug("Trying-to-raise-onu-active-event") |
| 2026 | OnuActiveEvent(self.events, self.device_id, |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 2027 | intf_id, |
| 2028 | onu_serial, |
Devmalya Paul | 7e0be4a | 2019-05-08 05:18:04 -0400 | [diff] [blame] | 2029 | str(self.device_id), |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 2030 | olt_serial_number, raised_ts, |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 2031 | onu_id=onu_id).send(True) |
Devmalya Paul | ffc89df | 2019-07-31 17:43:13 -0400 | [diff] [blame] | 2032 | except Exception as active_event_error: |
| 2033 | self.log.exception('onu-activated-event-error', |
Devmalya Paul | 1e1b172 | 2020-05-07 02:51:15 -0400 | [diff] [blame] | 2034 | errmsg=active_event_error) |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 2035 | |
Devmalya Paul | e2e5f2b | 2020-03-08 18:50:33 -0400 | [diff] [blame] | 2036 | @inlineCallbacks |
| 2037 | def onu_disabled_event(self): |
| 2038 | self.log.debug('onu-disabled-event') |
| 2039 | try: |
| 2040 | device = yield self.core_proxy.get_device(self.device_id) |
| 2041 | parent_device = yield self.core_proxy.get_device(self.parent_id) |
| 2042 | olt_serial_number = parent_device.serial_number |
| 2043 | raised_ts = arrow.utcnow().timestamp |
Devmalya Paul | 1e1b172 | 2020-05-07 02:51:15 -0400 | [diff] [blame] | 2044 | intf_id = self._onu_persisted_state.get('intf_id') |
| 2045 | onu_id = self._onu_persisted_state.get('onu_id') |
| 2046 | onu_serial = self._onu_persisted_state.get('serial_number') |
Devmalya Paul | e2e5f2b | 2020-03-08 18:50:33 -0400 | [diff] [blame] | 2047 | |
| 2048 | self.log.debug("onu-indication-context-data", |
Devmalya Paul | 1e1b172 | 2020-05-07 02:51:15 -0400 | [diff] [blame] | 2049 | pon_id=intf_id, |
| 2050 | onu_id=onu_id, |
Devmalya Paul | e2e5f2b | 2020-03-08 18:50:33 -0400 | [diff] [blame] | 2051 | registration_id=self.device_id, |
| 2052 | device_id=self.device_id, |
Devmalya Paul | 1e1b172 | 2020-05-07 02:51:15 -0400 | [diff] [blame] | 2053 | onu_serial_number=onu_serial, |
Devmalya Paul | e2e5f2b | 2020-03-08 18:50:33 -0400 | [diff] [blame] | 2054 | olt_serial_number=olt_serial_number, |
| 2055 | raised_ts=raised_ts) |
| 2056 | |
| 2057 | self.log.debug("Trying-to-raise-onu-disabled-event") |
| 2058 | OnuDisabledEvent(self.events, self.device_id, |
Devmalya Paul | 1e1b172 | 2020-05-07 02:51:15 -0400 | [diff] [blame] | 2059 | intf_id, |
Girish Gowdra | dc98d81 | 2020-03-20 13:04:58 -0700 | [diff] [blame] | 2060 | device.serial_number, |
| 2061 | str(self.device_id), |
| 2062 | olt_serial_number, raised_ts, |
Devmalya Paul | 1e1b172 | 2020-05-07 02:51:15 -0400 | [diff] [blame] | 2063 | onu_id=onu_id).send(True) |
| 2064 | except Exception as disable_event_error: |
Devmalya Paul | e2e5f2b | 2020-03-08 18:50:33 -0400 | [diff] [blame] | 2065 | self.log.exception('onu-disabled-event-error', |
Devmalya Paul | 1e1b172 | 2020-05-07 02:51:15 -0400 | [diff] [blame] | 2066 | errmsg=disable_event_error) |
| 2067 | |
| 2068 | @inlineCallbacks |
| 2069 | def onu_deleted_event(self): |
| 2070 | self.log.debug('onu-deleted-event') |
| 2071 | try: |
| 2072 | device = yield self.core_proxy.get_device(self.device_id) |
kesavand | 86a0fcf | 2020-08-25 08:25:28 +0530 | [diff] [blame^] | 2073 | olt_serial_number = self.olt_serial_number |
Devmalya Paul | 1e1b172 | 2020-05-07 02:51:15 -0400 | [diff] [blame] | 2074 | raised_ts = arrow.utcnow().timestamp |
| 2075 | intf_id = self._onu_persisted_state.get('intf_id') |
| 2076 | onu_id = self._onu_persisted_state.get('onu_id') |
| 2077 | serial_number = self._onu_persisted_state.get('serial_number') |
| 2078 | |
| 2079 | self.log.debug("onu-deleted-event-context-data", |
| 2080 | pon_id=intf_id, |
| 2081 | onu_id=onu_id, |
| 2082 | registration_id=self.device_id, |
| 2083 | device_id=self.device_id, |
| 2084 | onu_serial_number=serial_number, |
| 2085 | olt_serial_number=olt_serial_number, |
| 2086 | raised_ts=raised_ts) |
| 2087 | |
| 2088 | OnuDeletedEvent(self.events, self.device_id, |
| 2089 | intf_id, |
| 2090 | serial_number, |
| 2091 | str(self.device_id), |
| 2092 | olt_serial_number, raised_ts, |
| 2093 | onu_id=onu_id).send(True) |
| 2094 | except Exception as deleted_event_error: |
| 2095 | self.log.exception('onu-deleted-event-error', |
| 2096 | errmsg=deleted_event_error) |
Devmalya Paul | e2e5f2b | 2020-03-08 18:50:33 -0400 | [diff] [blame] | 2097 | |
| 2098 | def lock_ports(self, lock=True, device_disabled=False): |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 2099 | |
| 2100 | def success(response): |
| 2101 | self.log.debug('set-onu-ports-state', lock=lock, response=response) |
Devmalya Paul | e2e5f2b | 2020-03-08 18:50:33 -0400 | [diff] [blame] | 2102 | if device_disabled: |
| 2103 | self.onu_disabled_event() |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 2104 | |
| 2105 | def failure(response): |
| 2106 | self.log.error('cannot-set-onu-ports-state', lock=lock, response=response) |
| 2107 | |
| 2108 | task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock) |
| 2109 | self._deferred = self._onu_omci_device.task_runner.queue_task(task) |
| 2110 | self._deferred.addCallbacks(success, failure) |
Mahir Gunyel | e9110a3 | 2020-02-20 14:56:50 -0800 | [diff] [blame] | 2111 | |
| 2112 | def extract_tp_id_from_path(self, tp_path): |
| 2113 | # tp_path is of the format <technology>/<table_id>/<uni_port_name> |
Girish Gowdra | 4c11ddb | 2020-03-03 11:33:24 -0800 | [diff] [blame] | 2114 | tp_id = int(tp_path.split(_PATH_SEPERATOR)[1]) |
| 2115 | return tp_id |
onkarkundargi | a1e2af2 | 2020-01-27 11:51:43 +0530 | [diff] [blame] | 2116 | |
| 2117 | def start_omci_test_action(self, device, uuid): |
| 2118 | """ |
| 2119 | |
| 2120 | :param device: |
| 2121 | :return: |
| 2122 | """ |
| 2123 | # Code to Run OMCI Test Action |
| 2124 | self.log.info('Omci-test-action-request-On', request=device.id) |
| 2125 | kwargs_omci_test_action = { |
| 2126 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 2127 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 2128 | } |
| 2129 | serial_number = device.serial_number |
| 2130 | if device.connect_status != ConnectStatus.REACHABLE or device.admin_state != AdminState.ENABLED: |
| 2131 | return (TestResponse(result=TestResponse.FAILURE)) |
| 2132 | test_request = OmciTestRequest(self.core_proxy, |
| 2133 | self.omci_agent, self.device_id, AniG, |
| 2134 | serial_number, |
| 2135 | self.logical_device_id, exclusive=False, |
| 2136 | uuid=uuid, |
| 2137 | **kwargs_omci_test_action) |
| 2138 | test_request.perform_test_omci() |
| 2139 | return (TestResponse(result=TestResponse.SUCCESS)) |