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