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