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