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