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