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