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