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