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