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