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