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