Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [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 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 21 | import json |
| 22 | import ast |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 23 | import structlog |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 24 | |
| 25 | from collections import OrderedDict |
| 26 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 27 | from twisted.internet import reactor, task |
| 28 | from twisted.internet.defer import DeferredQueue, inlineCallbacks, returnValue, TimeoutError |
| 29 | |
Scott Baker | c474bb9 | 2018-10-12 16:19:18 -0700 | [diff] [blame] | 30 | from heartbeat import HeartBeat |
| 31 | from voltha.extensions.kpi.onu.onu_pm_metrics import OnuPmMetrics |
| 32 | from voltha.extensions.kpi.onu.onu_omci_pm import OnuOmciPmMetrics |
Chip Boling | 3186eb5 | 2018-11-02 14:28:01 -0500 | [diff] [blame] | 33 | from voltha.extensions.alarms.adapter_alarms import AdapterAlarms |
Scott Baker | c474bb9 | 2018-10-12 16:19:18 -0700 | [diff] [blame] | 34 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 35 | from common.utils.indexpool import IndexPool |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 36 | import voltha.core.flow_decomposer as fd |
| 37 | from voltha.registry import registry |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 38 | from voltha.core.config.config_backend import ConsulStore |
| 39 | from voltha.core.config.config_backend import EtcdStore |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 40 | from voltha.protos import third_party |
Matt Jeanneret | f444840 | 2018-09-25 12:51:19 -0400 | [diff] [blame] | 41 | from voltha.protos.common_pb2 import OperStatus, ConnectStatus, AdminState |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 42 | from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 43 | from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData |
| 44 | from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData |
| 45 | from voltha.extensions.omci.onu_configuration import OMCCVersion |
| 46 | from voltha.extensions.omci.onu_device_entry import OnuDeviceEvents, \ |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 47 | OnuDeviceEntry, IN_SYNC_KEY |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 48 | from voltha.adapters.brcm_openomci_onu.omci.brcm_mib_download_task import BrcmMibDownloadTask |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 49 | from voltha.adapters.brcm_openomci_onu.omci.brcm_tp_service_specific_task import BrcmTpServiceSpecificTask |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 50 | from voltha.adapters.brcm_openomci_onu.omci.brcm_uni_lock_task import BrcmUniLockTask |
Matt Jeanneret | f444840 | 2018-09-25 12:51:19 -0400 | [diff] [blame] | 51 | from voltha.adapters.brcm_openomci_onu.omci.brcm_vlan_filter_task import BrcmVlanFilterTask |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 52 | from voltha.adapters.brcm_openomci_onu.onu_gem_port import * |
| 53 | from voltha.adapters.brcm_openomci_onu.onu_tcont import * |
| 54 | from voltha.adapters.brcm_openomci_onu.pon_port import * |
| 55 | from voltha.adapters.brcm_openomci_onu.uni_port import * |
| 56 | from voltha.adapters.brcm_openomci_onu.onu_traffic_descriptor import * |
Girish Gowdru | 36ef069 | 2018-11-27 02:51:51 -0800 | [diff] [blame] | 57 | from common.tech_profile.tech_profile import TechProfile |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 58 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 59 | OP = EntityOperations |
| 60 | RC = ReasonCodes |
| 61 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 62 | _ = third_party |
| 63 | log = structlog.get_logger() |
| 64 | |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 65 | _STARTUP_RETRY_WAIT = 20 |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 66 | |
| 67 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 68 | class BrcmOpenomciOnuHandler(object): |
| 69 | |
| 70 | def __init__(self, adapter, device_id): |
| 71 | self.log = structlog.get_logger(device_id=device_id) |
| 72 | self.log.debug('function-entry') |
| 73 | self.adapter = adapter |
| 74 | self.adapter_agent = adapter.adapter_agent |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 75 | self.parent_adapter = None |
| 76 | self.parent_id = None |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 77 | self.device_id = device_id |
| 78 | self.incoming_messages = DeferredQueue() |
| 79 | self.event_messages = DeferredQueue() |
| 80 | self.proxy_address = None |
| 81 | self.tx_id = 0 |
| 82 | self._enabled = False |
Chip Boling | 3186eb5 | 2018-11-02 14:28:01 -0500 | [diff] [blame] | 83 | self.alarms = None |
Scott Baker | c474bb9 | 2018-10-12 16:19:18 -0700 | [diff] [blame] | 84 | self.pm_metrics = None |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 85 | self._omcc_version = OMCCVersion.Unknown |
| 86 | self._total_tcont_count = 0 # From ANI-G ME |
| 87 | self._qos_flexibility = 0 # From ONT2_G ME |
| 88 | |
| 89 | self._onu_indication = None |
| 90 | self._unis = dict() # Port # -> UniPort |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 91 | |
| 92 | self._pon = None |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 93 | # TODO: probably shouldnt be hardcoded, determine from olt maybe? |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 94 | self._pon_port_number = 100 |
| 95 | self.logical_device_id = None |
| 96 | |
Scott Baker | c474bb9 | 2018-10-12 16:19:18 -0700 | [diff] [blame] | 97 | self._heartbeat = HeartBeat.create(self, device_id) |
| 98 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 99 | # Set up OpenOMCI environment |
| 100 | self._onu_omci_device = None |
| 101 | self._dev_info_loaded = False |
| 102 | self._deferred = None |
| 103 | |
| 104 | self._in_sync_subscription = None |
| 105 | self._connectivity_subscription = None |
| 106 | self._capabilities_subscription = None |
| 107 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 108 | self.mac_bridge_service_profile_entity_id = 0x201 |
| 109 | self.gal_enet_profile_entity_id = 0x1 |
| 110 | |
| 111 | self._tp_service_specific_task = dict() |
| 112 | self._tech_profile_download_done = dict() |
| 113 | |
| 114 | # Initialize KV store client |
| 115 | self.args = registry('main').get_args() |
| 116 | if self.args.backend == 'etcd': |
| 117 | host, port = self.args.etcd.split(':', 1) |
Girish Gowdru | 36ef069 | 2018-11-27 02:51:51 -0800 | [diff] [blame] | 118 | self.kv_client = EtcdStore(host, port, |
| 119 | TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 120 | elif self.args.backend == 'consul': |
| 121 | host, port = self.args.consul.split(':', 1) |
Girish Gowdru | 36ef069 | 2018-11-27 02:51:51 -0800 | [diff] [blame] | 122 | self.kv_client = ConsulStore(host, port, |
| 123 | TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 124 | else: |
| 125 | self.log.error('Invalid-backend') |
| 126 | raise Exception("Invalid-backend-for-kv-store") |
| 127 | |
| 128 | # Handle received ONU event messages |
| 129 | reactor.callLater(0, self.handle_onu_events) |
| 130 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 131 | @property |
| 132 | def enabled(self): |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 133 | return self._enabled |
| 134 | |
| 135 | @enabled.setter |
| 136 | def enabled(self, value): |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 137 | if self._enabled != value: |
| 138 | self._enabled = value |
| 139 | |
| 140 | @property |
| 141 | def omci_agent(self): |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 142 | return self.adapter.omci_agent |
| 143 | |
| 144 | @property |
| 145 | def omci_cc(self): |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 146 | return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None |
| 147 | |
| 148 | @property |
Scott Baker | c474bb9 | 2018-10-12 16:19:18 -0700 | [diff] [blame] | 149 | def heartbeat(self): |
| 150 | return self._heartbeat |
| 151 | |
| 152 | @property |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 153 | def uni_ports(self): |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 154 | return self._unis.values() |
| 155 | |
| 156 | def uni_port(self, port_no_or_name): |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 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' |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 162 | return next((uni for uni in self.uni_ports |
| 163 | if uni.logical_port_number == port_no_or_name), None) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 164 | |
| 165 | @property |
| 166 | def pon_port(self): |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 167 | return self._pon |
| 168 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 169 | def receive_message(self, msg): |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 170 | if self.omci_cc is not None: |
| 171 | self.omci_cc.receive_message(msg) |
| 172 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 173 | # Called once when the adapter creates the device/onu instance |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 174 | def activate(self, device): |
| 175 | self.log.debug('function-entry', device=device) |
| 176 | |
| 177 | # first we verify that we got parent reference and proxy info |
| 178 | assert device.parent_id |
| 179 | assert device.proxy_address.device_id |
| 180 | |
| 181 | # register for proxied messages right away |
| 182 | self.proxy_address = device.proxy_address |
| 183 | self.adapter_agent.register_for_proxied_messages(device.proxy_address) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 184 | self.parent_id = device.parent_id |
| 185 | parent_device = self.adapter_agent.get_device(self.parent_id) |
| 186 | if parent_device.type == 'openolt': |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 187 | self.parent_adapter = registry('adapter_loader'). \ |
| 188 | get_agent(parent_device.adapter).adapter |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 189 | |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 190 | if self.enabled is not True: |
| 191 | self.log.info('activating-new-onu') |
| 192 | # populate what we know. rest comes later after mib sync |
Gamze Abaka | 53cc0a2 | 2019-01-31 12:06:11 +0000 | [diff] [blame] | 193 | device.root = False |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 194 | device.vendor = 'Broadcom' |
| 195 | device.connect_status = ConnectStatus.REACHABLE |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 196 | device.oper_status = OperStatus.DISCOVERED |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 197 | device.reason = 'activating-onu' |
Scott Baker | c474bb9 | 2018-10-12 16:19:18 -0700 | [diff] [blame] | 198 | |
| 199 | # pm_metrics requires a logical device id |
| 200 | parent_device = self.adapter_agent.get_device(device.parent_id) |
| 201 | self.logical_device_id = parent_device.parent_id |
| 202 | assert self.logical_device_id, 'Invalid logical device ID' |
| 203 | |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 204 | self.adapter_agent.update_device(device) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 205 | |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 206 | self.log.debug('set-device-discovered') |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 207 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 208 | self._init_pon_state(device) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 209 | |
Scott Baker | c474bb9 | 2018-10-12 16:19:18 -0700 | [diff] [blame] | 210 | ############################################################################ |
| 211 | # Setup PM configuration for this device |
| 212 | # Pass in ONU specific options |
| 213 | kwargs = { |
| 214 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 215 | 'heartbeat': self.heartbeat, |
| 216 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 217 | } |
| 218 | self.pm_metrics = OnuPmMetrics(self.adapter_agent, self.device_id, |
| 219 | self.logical_device_id, grouped=True, |
| 220 | freq_override=False, **kwargs) |
| 221 | pm_config = self.pm_metrics.make_proto() |
| 222 | self._onu_omci_device.set_pm_config(self.pm_metrics.omci_pm.openomci_interval_pm) |
| 223 | self.log.info("initial-pm-config", pm_config=pm_config) |
| 224 | self.adapter_agent.update_device_pm_config(pm_config, init=True) |
| 225 | |
Chip Boling | 3186eb5 | 2018-11-02 14:28:01 -0500 | [diff] [blame] | 226 | ############################################################################ |
| 227 | # Setup Alarm handler |
| 228 | self.alarms = AdapterAlarms(self.adapter_agent, device.id, self.logical_device_id) |
| 229 | # Note, ONU ID and UNI intf set in add_uni_port method |
| 230 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.alarms, |
| 231 | ani_ports=[self._pon]) |
Chip Boling | 91911df | 2019-03-15 14:34:26 -0500 | [diff] [blame] | 232 | |
| 233 | # Start collecting stats from the device after a brief pause |
| 234 | reactor.callLater(10, self.pm_metrics.start_collector) |
| 235 | |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 236 | self.enabled = True |
| 237 | else: |
| 238 | self.log.info('onu-already-activated') |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 239 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 240 | # Called once when the adapter needs to re-create device. usually on vcore restart |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 241 | def reconcile(self, device): |
| 242 | self.log.debug('function-entry', device=device) |
| 243 | |
| 244 | # first we verify that we got parent reference and proxy info |
| 245 | assert device.parent_id |
| 246 | assert device.proxy_address.device_id |
| 247 | |
| 248 | # register for proxied messages right away |
| 249 | self.proxy_address = device.proxy_address |
| 250 | self.adapter_agent.register_for_proxied_messages(device.proxy_address) |
| 251 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 252 | if self.enabled is not True: |
| 253 | self.log.info('reconciling-broadcom-onu-device') |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 254 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 255 | self._init_pon_state(device) |
| 256 | |
| 257 | # need to restart state machines on vcore restart. there is no indication to do it for us. |
| 258 | self._onu_omci_device.start() |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 259 | device.reason = "restarting-openomci" |
| 260 | self.adapter_agent.update_device(device) |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 261 | |
| 262 | # TODO: this is probably a bit heavy handed |
| 263 | # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away |
| 264 | # This may not be necessary when mib resync actually works |
| 265 | reactor.callLater(1, self.reboot) |
| 266 | |
| 267 | self.enabled = True |
| 268 | else: |
| 269 | self.log.info('onu-already-activated') |
| 270 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 271 | @inlineCallbacks |
| 272 | def handle_onu_events(self): |
| 273 | event_msg = yield self.event_messages.get() |
| 274 | try: |
| 275 | if event_msg['event'] == 'download_tech_profile': |
| 276 | tp_path = event_msg['event_data'] |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 277 | uni_id = event_msg['uni_id'] |
| 278 | self.load_and_configure_tech_profile(uni_id, tp_path) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 279 | |
| 280 | except Exception as e: |
| 281 | self.log.error("exception-handling-onu-event", e=e) |
| 282 | |
| 283 | # Handle next event |
| 284 | reactor.callLater(0, self.handle_onu_events) |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 285 | |
| 286 | def _init_pon_state(self, device): |
| 287 | self.log.debug('function-entry', device=device) |
| 288 | |
| 289 | self._pon = PonPort.create(self, self._pon_port_number) |
| 290 | self.adapter_agent.add_port(device.id, self._pon.get_port()) |
| 291 | |
| 292 | self.log.debug('added-pon-port-to-agent', pon=self._pon) |
| 293 | |
| 294 | parent_device = self.adapter_agent.get_device(device.parent_id) |
| 295 | self.logical_device_id = parent_device.parent_id |
| 296 | |
| 297 | self.adapter_agent.update_device(device) |
| 298 | |
| 299 | # Create and start the OpenOMCI ONU Device Entry for this ONU |
| 300 | self._onu_omci_device = self.omci_agent.add_device(self.device_id, |
| 301 | self.adapter_agent, |
Craig Lutgen | 2eabc86 | 2018-10-18 22:14:14 +0000 | [diff] [blame] | 302 | support_classes=self.adapter.broadcom_omci, |
| 303 | custom_me_map=self.adapter.custom_me_entities()) |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 304 | # Port startup |
| 305 | if self._pon is not None: |
| 306 | self._pon.enabled = True |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 307 | |
| 308 | # TODO: move to UniPort |
| 309 | def update_logical_port(self, logical_device_id, port_id, state): |
| 310 | try: |
| 311 | self.log.info('updating-logical-port', logical_port_id=port_id, |
| 312 | logical_device_id=logical_device_id, state=state) |
| 313 | logical_port = self.adapter_agent.get_logical_port(logical_device_id, |
| 314 | port_id) |
| 315 | logical_port.ofp_port.state = state |
| 316 | self.adapter_agent.update_logical_port(logical_device_id, |
| 317 | logical_port) |
| 318 | except Exception as e: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 319 | self.log.exception("exception-updating-port", e=e) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 320 | |
| 321 | def delete(self, device): |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 322 | self.log.info('delete-onu', device=device) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 323 | if self.parent_adapter: |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 324 | try: |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 325 | self.parent_adapter.delete_child_device(self.parent_id, device) |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 326 | except AttributeError: |
| 327 | self.log.debug('parent-device-delete-child-not-implemented') |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 328 | else: |
| 329 | self.log.debug("parent-adapter-not-available") |
| 330 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 331 | def _create_tconts(self, uni_id, us_scheduler): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 332 | alloc_id = us_scheduler['alloc_id'] |
| 333 | q_sched_policy = us_scheduler['q_sched_policy'] |
| 334 | self.log.debug('create-tcont', us_scheduler=us_scheduler) |
| 335 | |
| 336 | tcontdict = dict() |
| 337 | tcontdict['alloc-id'] = alloc_id |
| 338 | tcontdict['q_sched_policy'] = q_sched_policy |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 339 | tcontdict['uni_id'] = uni_id |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 340 | |
| 341 | # TODO: Not sure what to do with any of this... |
| 342 | tddata = dict() |
| 343 | tddata['name'] = 'not-sure-td-profile' |
| 344 | tddata['fixed-bandwidth'] = "not-sure-fixed" |
| 345 | tddata['assured-bandwidth'] = "not-sure-assured" |
| 346 | tddata['maximum-bandwidth'] = "not-sure-max" |
| 347 | tddata['additional-bw-eligibility-indicator'] = "not-sure-additional" |
| 348 | |
| 349 | td = OnuTrafficDescriptor.create(tddata) |
| 350 | tcont = OnuTCont.create(self, tcont=tcontdict, td=td) |
| 351 | |
| 352 | self._pon.add_tcont(tcont) |
| 353 | |
| 354 | self.log.debug('pon-add-tcont', tcont=tcont) |
| 355 | |
| 356 | # Called when there is an olt up indication, providing the gem port id chosen by the olt handler |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 357 | def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 358 | self.log.debug('create-gemport', |
| 359 | gem_ports=gem_ports, direction=direction) |
| 360 | |
| 361 | for gem_port in gem_ports: |
| 362 | gemdict = dict() |
| 363 | gemdict['gemport_id'] = gem_port['gemport_id'] |
| 364 | gemdict['direction'] = direction |
| 365 | gemdict['alloc_id_ref'] = alloc_id_ref |
| 366 | gemdict['encryption'] = gem_port['aes_encryption'] |
| 367 | gemdict['discard_config'] = dict() |
| 368 | gemdict['discard_config']['max_probability'] = \ |
| 369 | gem_port['discard_config']['max_probability'] |
| 370 | gemdict['discard_config']['max_threshold'] = \ |
| 371 | gem_port['discard_config']['max_threshold'] |
| 372 | gemdict['discard_config']['min_threshold'] = \ |
| 373 | gem_port['discard_config']['min_threshold'] |
| 374 | gemdict['discard_policy'] = gem_port['discard_policy'] |
| 375 | gemdict['max_q_size'] = gem_port['max_q_size'] |
| 376 | gemdict['pbit_map'] = gem_port['pbit_map'] |
| 377 | gemdict['priority_q'] = gem_port['priority_q'] |
| 378 | gemdict['scheduling_policy'] = gem_port['scheduling_policy'] |
| 379 | gemdict['weight'] = gem_port['weight'] |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 380 | gemdict['uni_id'] = uni_id |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 381 | |
Matt Jeanneret | 49b764b | 2019-01-22 17:50:36 -0500 | [diff] [blame] | 382 | gem_port = OnuGemPort.create(self, gem_port=gemdict) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 383 | |
| 384 | self._pon.add_gem_port(gem_port) |
| 385 | |
| 386 | self.log.debug('pon-add-gemport', gem_port=gem_port) |
| 387 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 388 | def _do_tech_profile_configuration(self, uni_id, tp): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 389 | us_scheduler = tp['us_scheduler'] |
| 390 | alloc_id = us_scheduler['alloc_id'] |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 391 | self._create_tconts(uni_id, us_scheduler) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 392 | upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list'] |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 393 | self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM") |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 394 | downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list'] |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 395 | self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM") |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 396 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 397 | def load_and_configure_tech_profile(self, uni_id, tp_path): |
Craig Lutgen | ad13937 | 2018-12-17 16:02:42 -0600 | [diff] [blame] | 398 | self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 399 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 400 | if uni_id not in self._tp_service_specific_task: |
| 401 | self._tp_service_specific_task[uni_id] = dict() |
| 402 | |
| 403 | if uni_id not in self._tech_profile_download_done: |
| 404 | self._tech_profile_download_done[uni_id] = dict() |
| 405 | |
| 406 | if tp_path not in self._tech_profile_download_done[uni_id]: |
| 407 | self._tech_profile_download_done[uni_id][tp_path] = False |
| 408 | |
| 409 | if not self._tech_profile_download_done[uni_id][tp_path]: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 410 | try: |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 411 | if tp_path in self._tp_service_specific_task[uni_id]: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 412 | self.log.info("tech-profile-config-already-in-progress", |
| 413 | tp_path=tp_path) |
| 414 | return |
| 415 | |
| 416 | tp = self.kv_client[tp_path] |
| 417 | tp = ast.literal_eval(tp) |
| 418 | self.log.debug("tp-instance", tp=tp) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 419 | self._do_tech_profile_configuration(uni_id, tp) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 420 | |
| 421 | def success(_results): |
| 422 | self.log.info("tech-profile-config-done-successfully") |
| 423 | device = self.adapter_agent.get_device(self.device_id) |
| 424 | device.reason = 'tech-profile-config-download-success' |
| 425 | self.adapter_agent.update_device(device) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 426 | if tp_path in self._tp_service_specific_task[uni_id]: |
| 427 | del self._tp_service_specific_task[uni_id][tp_path] |
| 428 | self._tech_profile_download_done[uni_id][tp_path] = True |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 429 | |
| 430 | def failure(_reason): |
| 431 | self.log.warn('tech-profile-config-failure-retrying', |
| 432 | _reason=_reason) |
| 433 | device = self.adapter_agent.get_device(self.device_id) |
| 434 | device.reason = 'tech-profile-config-download-failure-retrying' |
| 435 | self.adapter_agent.update_device(device) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 436 | if tp_path in self._tp_service_specific_task[uni_id]: |
| 437 | del self._tp_service_specific_task[uni_id][tp_path] |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 438 | self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile, |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 439 | uni_id, tp_path) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 440 | |
| 441 | self.log.info('downloading-tech-profile-configuration') |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 442 | self._tp_service_specific_task[uni_id][tp_path] = \ |
| 443 | BrcmTpServiceSpecificTask(self.omci_agent, self, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 444 | self._deferred = \ |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 445 | self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path]) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 446 | self._deferred.addCallbacks(success, failure) |
| 447 | |
| 448 | except Exception as e: |
| 449 | self.log.exception("error-loading-tech-profile", e=e) |
| 450 | else: |
| 451 | self.log.info("tech-profile-config-already-done") |
| 452 | |
Scott Baker | c474bb9 | 2018-10-12 16:19:18 -0700 | [diff] [blame] | 453 | def update_pm_config(self, device, pm_config): |
| 454 | # TODO: This has not been tested |
| 455 | self.log.info('update_pm_config', pm_config=pm_config) |
| 456 | self.pm_metrics.update(pm_config) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 457 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 458 | # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from |
| 459 | # flow decomposition that ultimately comes from onos |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 460 | def update_flow_table(self, device, flows): |
| 461 | self.log.debug('function-entry', device=device, flows=flows) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 462 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 463 | # |
| 464 | # We need to proxy through the OLT to get to the ONU |
| 465 | # Configuration from here should be using OMCI |
| 466 | # |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 467 | # self.log.info('bulk-flow-update', device_id=device.id, flows=flows) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 468 | |
Matt Jeanneret | 1c90e50 | 2018-11-12 17:38:42 -0500 | [diff] [blame] | 469 | # no point in pushing omci flows if the device isnt reachable |
| 470 | if device.connect_status != ConnectStatus.REACHABLE or \ |
| 471 | device.admin_state != AdminState.ENABLED: |
| 472 | self.log.warn("device-disabled-or-offline-skipping-flow-update", |
| 473 | admin=device.admin_state, connect=device.connect_status) |
| 474 | return |
| 475 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 476 | def is_downstream(port): |
| 477 | return port == self._pon_port_number |
| 478 | |
| 479 | def is_upstream(port): |
| 480 | return not is_downstream(port) |
| 481 | |
| 482 | for flow in flows: |
| 483 | _type = None |
| 484 | _port = None |
| 485 | _vlan_vid = None |
| 486 | _udp_dst = None |
| 487 | _udp_src = None |
| 488 | _ipv4_dst = None |
| 489 | _ipv4_src = None |
| 490 | _metadata = None |
| 491 | _output = None |
| 492 | _push_tpid = None |
| 493 | _field = None |
| 494 | _set_vlan_vid = None |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 495 | self.log.debug('bulk-flow-update', device_id=device.id, flow=flow) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 496 | try: |
| 497 | _in_port = fd.get_in_port(flow) |
| 498 | assert _in_port is not None |
| 499 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 500 | _out_port = fd.get_out_port(flow) # may be None |
| 501 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 502 | if is_downstream(_in_port): |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 503 | self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port) |
| 504 | uni_port = self.uni_port(_out_port) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 505 | elif is_upstream(_in_port): |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 506 | self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port) |
| 507 | uni_port = self.uni_port(_in_port) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 508 | else: |
| 509 | raise Exception('port should be 1 or 2 by our convention') |
| 510 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 511 | self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port)) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 512 | |
| 513 | for field in fd.get_ofb_fields(flow): |
| 514 | if field.type == fd.ETH_TYPE: |
| 515 | _type = field.eth_type |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 516 | self.log.debug('field-type-eth-type', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 517 | eth_type=_type) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 518 | |
| 519 | elif field.type == fd.IP_PROTO: |
| 520 | _proto = field.ip_proto |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 521 | self.log.debug('field-type-ip-proto', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 522 | ip_proto=_proto) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 523 | |
| 524 | elif field.type == fd.IN_PORT: |
| 525 | _port = field.port |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 526 | self.log.debug('field-type-in-port', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 527 | in_port=_port) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 528 | |
| 529 | elif field.type == fd.VLAN_VID: |
| 530 | _vlan_vid = field.vlan_vid & 0xfff |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 531 | self.log.debug('field-type-vlan-vid', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 532 | vlan=_vlan_vid) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 533 | |
| 534 | elif field.type == fd.VLAN_PCP: |
| 535 | _vlan_pcp = field.vlan_pcp |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 536 | self.log.debug('field-type-vlan-pcp', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 537 | pcp=_vlan_pcp) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 538 | |
| 539 | elif field.type == fd.UDP_DST: |
| 540 | _udp_dst = field.udp_dst |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 541 | self.log.debug('field-type-udp-dst', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 542 | udp_dst=_udp_dst) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 543 | |
| 544 | elif field.type == fd.UDP_SRC: |
| 545 | _udp_src = field.udp_src |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 546 | self.log.debug('field-type-udp-src', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 547 | udp_src=_udp_src) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 548 | |
| 549 | elif field.type == fd.IPV4_DST: |
| 550 | _ipv4_dst = field.ipv4_dst |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 551 | self.log.debug('field-type-ipv4-dst', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 552 | ipv4_dst=_ipv4_dst) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 553 | |
| 554 | elif field.type == fd.IPV4_SRC: |
| 555 | _ipv4_src = field.ipv4_src |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 556 | self.log.debug('field-type-ipv4-src', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 557 | ipv4_dst=_ipv4_src) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 558 | |
| 559 | elif field.type == fd.METADATA: |
| 560 | _metadata = field.table_metadata |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 561 | self.log.debug('field-type-metadata', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 562 | metadata=_metadata) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 563 | |
| 564 | else: |
| 565 | raise NotImplementedError('field.type={}'.format( |
| 566 | field.type)) |
| 567 | |
| 568 | for action in fd.get_actions(flow): |
| 569 | |
| 570 | if action.type == fd.OUTPUT: |
| 571 | _output = action.output.port |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 572 | self.log.debug('action-type-output', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 573 | output=_output, in_port=_in_port) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 574 | |
| 575 | elif action.type == fd.POP_VLAN: |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 576 | self.log.debug('action-type-pop-vlan', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 577 | in_port=_in_port) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 578 | |
| 579 | elif action.type == fd.PUSH_VLAN: |
| 580 | _push_tpid = action.push.ethertype |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 581 | self.log.debug('action-type-push-vlan', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 582 | push_tpid=_push_tpid, in_port=_in_port) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 583 | if action.push.ethertype != 0x8100: |
| 584 | self.log.error('unhandled-tpid', |
| 585 | ethertype=action.push.ethertype) |
| 586 | |
| 587 | elif action.type == fd.SET_FIELD: |
| 588 | _field = action.set_field.field.ofb_field |
| 589 | assert (action.set_field.field.oxm_class == |
| 590 | OFPXMC_OPENFLOW_BASIC) |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 591 | self.log.debug('action-type-set-field', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 592 | field=_field, in_port=_in_port) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 593 | if _field.type == fd.VLAN_VID: |
| 594 | _set_vlan_vid = _field.vlan_vid & 0xfff |
Zack Williams | 8d811fd | 2018-11-22 09:23:23 -0700 | [diff] [blame] | 595 | self.log.debug('set-field-type-vlan-vid', |
| 596 | vlan_vid=_set_vlan_vid) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 597 | else: |
| 598 | self.log.error('unsupported-action-set-field-type', |
| 599 | field_type=_field.type) |
| 600 | else: |
| 601 | self.log.error('unsupported-action-type', |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 602 | action_type=action.type, in_port=_in_port) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 603 | |
Matt Jeanneret | f444840 | 2018-09-25 12:51:19 -0400 | [diff] [blame] | 604 | # TODO: We only set vlan omci flows. Handle omci matching ethertypes at some point in another task |
Nicolas Palpacuer | 6093c1a | 2018-08-27 15:03:24 -0400 | [diff] [blame] | 605 | if _type is not None: |
Matt Jeanneret | f444840 | 2018-09-25 12:51:19 -0400 | [diff] [blame] | 606 | self.log.warn('ignoring-flow-with-ethType', ethType=_type) |
| 607 | elif _set_vlan_vid is None or _set_vlan_vid == 0: |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 608 | self.log.warn('ignoring-flow-that-does-not-set-vlanid') |
Matt Jeanneret | f444840 | 2018-09-25 12:51:19 -0400 | [diff] [blame] | 609 | else: |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 610 | self.log.warn('set-vlanid', uni_id=uni_port.port_number, set_vlan_vid=_set_vlan_vid) |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 611 | self._do_vlan_filter_task(device, flow.cookie, add_tag=True, |
| 612 | uni_port=uni_port, _set_vlan_vid=_set_vlan_vid) |
Saurav Das | 6c53996 | 2018-09-13 14:17:41 -0700 | [diff] [blame] | 613 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 614 | except Exception as e: |
| 615 | self.log.exception('failed-to-install-flow', e=e, flow=flow) |
| 616 | |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 617 | def add_onu_flows(self, device, flows): |
| 618 | self.log.debug('function-entry', device=device, flows=flows) |
Matt Jeanneret | 1c90e50 | 2018-11-12 17:38:42 -0500 | [diff] [blame] | 619 | |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 620 | # |
| 621 | # We need to proxy through the OLT to get to the ONU |
| 622 | # Configuration from here should be using OMCI |
| 623 | # |
| 624 | # self.log.info('bulk-flow-update', device_id=device.id, flows=flows) |
| 625 | |
| 626 | # no point in pushing omci flows if the device isnt reachable |
| 627 | if device.connect_status != ConnectStatus.REACHABLE or \ |
| 628 | device.admin_state != AdminState.ENABLED: |
| 629 | self.log.warn("device-disabled-or-offline-skipping-flow-update", |
| 630 | admin=device.admin_state, connect=device.connect_status) |
| 631 | return |
| 632 | |
| 633 | for flow in flows: |
| 634 | # if incoming flow contains cookie, then add to ONU |
| 635 | if flow.cookie: |
| 636 | _type = None |
| 637 | _port = None |
| 638 | _vlan_vid = None |
| 639 | _udp_dst = None |
| 640 | _udp_src = None |
| 641 | _ipv4_dst = None |
| 642 | _ipv4_src = None |
| 643 | _metadata = None |
| 644 | _output = None |
| 645 | _push_tpid = None |
| 646 | _field = None |
| 647 | _set_vlan_vid = None |
| 648 | self.log.debug("add-flow", device_id=device.id, flow=flow) |
| 649 | |
| 650 | def is_downstream(port): |
| 651 | return port == self._pon_port_number |
| 652 | |
| 653 | def is_upstream(port): |
| 654 | return not is_downstream(port) |
| 655 | |
| 656 | try: |
| 657 | _in_port = fd.get_in_port(flow) |
| 658 | assert _in_port is not None |
| 659 | |
| 660 | _out_port = fd.get_out_port(flow) # may be None |
| 661 | |
| 662 | if is_downstream(_in_port): |
| 663 | self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port) |
| 664 | uni_port = self.uni_port(_out_port) |
| 665 | elif is_upstream(_in_port): |
| 666 | self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port) |
| 667 | uni_port = self.uni_port(_in_port) |
| 668 | else: |
| 669 | raise Exception('port should be 1 or 2 by our convention') |
| 670 | |
| 671 | self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port)) |
| 672 | |
| 673 | for field in fd.get_ofb_fields(flow): |
| 674 | if field.type == fd.ETH_TYPE: |
| 675 | _type = field.eth_type |
| 676 | self.log.debug('field-type-eth-type', |
| 677 | eth_type=_type) |
| 678 | |
| 679 | elif field.type == fd.IP_PROTO: |
| 680 | _proto = field.ip_proto |
| 681 | self.log.debug('field-type-ip-proto', |
| 682 | ip_proto=_proto) |
| 683 | |
| 684 | elif field.type == fd.IN_PORT: |
| 685 | _port = field.port |
| 686 | self.log.debug('field-type-in-port', |
| 687 | in_port=_port) |
| 688 | |
| 689 | elif field.type == fd.VLAN_VID: |
| 690 | _vlan_vid = field.vlan_vid & 0xfff |
| 691 | self.log.debug('field-type-vlan-vid', |
| 692 | vlan=_vlan_vid) |
| 693 | |
| 694 | elif field.type == fd.VLAN_PCP: |
| 695 | _vlan_pcp = field.vlan_pcp |
| 696 | self.log.debug('field-type-vlan-pcp', |
| 697 | pcp=_vlan_pcp) |
| 698 | |
| 699 | elif field.type == fd.UDP_DST: |
| 700 | _udp_dst = field.udp_dst |
| 701 | self.log.debug('field-type-udp-dst', |
| 702 | udp_dst=_udp_dst) |
| 703 | |
| 704 | elif field.type == fd.UDP_SRC: |
| 705 | _udp_src = field.udp_src |
| 706 | self.log.debug('field-type-udp-src', |
| 707 | udp_src=_udp_src) |
| 708 | |
| 709 | elif field.type == fd.IPV4_DST: |
| 710 | _ipv4_dst = field.ipv4_dst |
| 711 | self.log.debug('field-type-ipv4-dst', |
| 712 | ipv4_dst=_ipv4_dst) |
| 713 | |
| 714 | elif field.type == fd.IPV4_SRC: |
| 715 | _ipv4_src = field.ipv4_src |
| 716 | self.log.debug('field-type-ipv4-src', |
| 717 | ipv4_dst=_ipv4_src) |
| 718 | |
| 719 | elif field.type == fd.METADATA: |
| 720 | _metadata = field.table_metadata |
| 721 | self.log.debug('field-type-metadata', |
| 722 | metadata=_metadata) |
| 723 | |
| 724 | else: |
| 725 | raise NotImplementedError('field.type={}'.format( |
| 726 | field.type)) |
| 727 | |
| 728 | for action in fd.get_actions(flow): |
| 729 | |
| 730 | if action.type == fd.OUTPUT: |
| 731 | _output = action.output.port |
| 732 | self.log.debug('action-type-output', |
| 733 | output=_output, in_port=_in_port) |
| 734 | |
| 735 | elif action.type == fd.POP_VLAN: |
| 736 | self.log.debug('action-type-pop-vlan', |
| 737 | in_port=_in_port) |
| 738 | |
| 739 | elif action.type == fd.PUSH_VLAN: |
| 740 | _push_tpid = action.push.ethertype |
| 741 | self.log.debug('action-type-push-vlan', |
| 742 | push_tpid=_push_tpid, in_port=_in_port) |
| 743 | if action.push.ethertype != 0x8100: |
| 744 | self.log.error('unhandled-tpid', |
| 745 | ethertype=action.push.ethertype) |
| 746 | |
| 747 | elif action.type == fd.SET_FIELD: |
| 748 | _field = action.set_field.field.ofb_field |
| 749 | assert (action.set_field.field.oxm_class == |
| 750 | OFPXMC_OPENFLOW_BASIC) |
| 751 | self.log.debug('action-type-set-field', |
| 752 | field=_field, in_port=_in_port) |
| 753 | if _field.type == fd.VLAN_VID: |
| 754 | _set_vlan_vid = _field.vlan_vid & 0xfff |
| 755 | self.log.debug('set-field-type-vlan-vid', |
| 756 | vlan_vid=_set_vlan_vid) |
| 757 | else: |
| 758 | self.log.error('unsupported-action-set-field-type', |
| 759 | field_type=_field.type) |
| 760 | else: |
| 761 | self.log.error('unsupported-action-type', |
| 762 | action_type=action.type, in_port=_in_port) |
| 763 | |
| 764 | # TODO: We only set vlan omci flows. Handle omci matching ethertypes at some point in another task |
| 765 | if _type is not None: |
| 766 | self.log.warn('ignoring-flow-with-ethType', ethType=_type) |
| 767 | elif _set_vlan_vid is None or _set_vlan_vid == 0: |
| 768 | self.log.warn('ignoring-flow-that-does-not-set-vlanid') |
| 769 | else: |
| 770 | self.log.warn('set-vlanid', uni_id=uni_port.port_number, set_vlan_vid=_set_vlan_vid) |
| 771 | self._do_vlan_filter_task(device, flow.cookie, add_tag=True, |
| 772 | uni_port=uni_port, _set_vlan_vid=_set_vlan_vid) |
| 773 | |
| 774 | except Exception as e: |
| 775 | self.log.exception('failed-to-install-flow', e=e, flow=flow) |
| 776 | |
| 777 | def remove_onu_flows(self, device, flows): |
| 778 | self.log.debug('function-entry', device=device, flows=flows) |
| 779 | |
| 780 | # no point in removing omci flows if the device isnt reachable |
| 781 | if device.connect_status != ConnectStatus.REACHABLE or \ |
| 782 | device.admin_state != AdminState.ENABLED: |
| 783 | self.log.warn("device-disabled-or-offline-skipping-remove-flow", |
| 784 | admin=device.admin_state, connect=device.connect_status) |
| 785 | return |
| 786 | |
| 787 | for flow in flows: |
| 788 | # if incoming flow contains cookie, then remove from ONU |
| 789 | if flow.cookie: |
| 790 | self.log.debug("remove-flow", device_id=device.id, flow=flow) |
| 791 | |
| 792 | def is_downstream(port): |
| 793 | return port == self._pon_port_number |
| 794 | |
| 795 | def is_upstream(port): |
| 796 | return not is_downstream(port) |
| 797 | |
| 798 | try: |
| 799 | _in_port = fd.get_in_port(flow) |
| 800 | assert _in_port is not None |
| 801 | |
| 802 | _out_port = fd.get_out_port(flow) # may be None |
| 803 | |
| 804 | if is_downstream(_in_port): |
| 805 | self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port) |
| 806 | uni_port = self.uni_port(_out_port) |
| 807 | elif is_upstream(_in_port): |
| 808 | self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port) |
| 809 | uni_port = self.uni_port(_in_port) |
| 810 | else: |
| 811 | raise Exception('port should be 1 or 2 by our convention') |
| 812 | |
| 813 | self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port)) |
| 814 | |
| 815 | # Deleting flow from ONU. |
| 816 | self._do_vlan_filter_task(device, flow.cookie, add_tag=False, uni_port=uni_port) |
| 817 | except Exception as e: |
| 818 | self.log.exception('failed-to-remove-flow', e=e) |
| 819 | |
| 820 | def _do_vlan_filter_task(self, device, flow_cookie, add_tag=True, uni_port=None, _set_vlan_vid=None): |
| 821 | task_name = 'removing-vlan-tag' |
| 822 | if add_tag: |
| 823 | assert uni_port is not None |
| 824 | task_name = 'setting-vlan-tag' |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 825 | |
Matt Jeanneret | f444840 | 2018-09-25 12:51:19 -0400 | [diff] [blame] | 826 | def success(_results): |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 827 | if add_tag: |
| 828 | self.log.info('vlan-tagging-success', _results=_results) |
| 829 | device.reason = 'omci-flows-pushed' |
| 830 | self.log.debug('Flow-addition-success', cookie=flow_cookie) |
| 831 | else: |
| 832 | self.log.info('vlan-untagging-success', _results=_results) |
| 833 | device.reason = 'omci-flows-deleted' |
| 834 | self.log.debug('Flow-removal-success', cookie=flow_cookie) |
| 835 | |
Matt Jeanneret | f444840 | 2018-09-25 12:51:19 -0400 | [diff] [blame] | 836 | self._vlan_filter_task = None |
| 837 | |
| 838 | def failure(_reason): |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 839 | if add_tag: |
| 840 | self.log.warn('vlan-tagging-failure', _reason=_reason) |
| 841 | device.reason = 'omci-flows-addition-failed-retrying' |
| 842 | self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT, |
| 843 | self._do_vlan_filter_task, device, flow_cookie, |
| 844 | add_tag=True, uni_port=uni_port, |
| 845 | _set_vlan_vid=_set_vlan_vid) |
| 846 | else: |
| 847 | self.log.warn('vlan-untagging-failure', _reason=_reason) |
| 848 | device.reason = 'omci-flows-deletion-failed-retrying' |
| 849 | self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT, |
| 850 | self._do_vlan_filter_task, device, flow_cookie, |
| 851 | add_tag=False) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 852 | |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 853 | self.log.info(task_name) |
| 854 | self._vlan_filter_task = BrcmVlanFilterTask(self.omci_agent, self.device_id, uni_port, _set_vlan_vid, |
| 855 | add_tag=add_tag) |
Matt Jeanneret | f444840 | 2018-09-25 12:51:19 -0400 | [diff] [blame] | 856 | self._deferred = self._onu_omci_device.task_runner.queue_task(self._vlan_filter_task) |
| 857 | self._deferred.addCallbacks(success, failure) |
| 858 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 859 | def get_tx_id(self): |
| 860 | self.log.debug('function-entry') |
| 861 | self.tx_id += 1 |
| 862 | return self.tx_id |
| 863 | |
Matt Jeanneret | 04ba4fd | 2018-08-16 15:32:21 -0400 | [diff] [blame] | 864 | # TODO: Actually conform to or create a proper interface. |
| 865 | # this and the other functions called from the olt arent very clear. |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 866 | # Called each time there is an onu "up" indication from the olt handler |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 867 | def create_interface(self, data): |
| 868 | self.log.debug('function-entry', data=data) |
| 869 | self._onu_indication = data |
| 870 | |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 871 | onu_device = self.adapter_agent.get_device(self.device_id) |
| 872 | |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 873 | self.log.debug('starting-openomci-statemachine') |
| 874 | self._subscribe_to_events() |
| 875 | reactor.callLater(1, self._onu_omci_device.start) |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 876 | onu_device.reason = "starting-openomci" |
| 877 | self.adapter_agent.update_device(onu_device) |
Scott Baker | c474bb9 | 2018-10-12 16:19:18 -0700 | [diff] [blame] | 878 | self._heartbeat.enabled = True |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 879 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 880 | # Currently called each time there is an onu "down" indication from the olt handler |
| 881 | # TODO: possibly other reasons to "update" from the olt? |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 882 | def update_interface(self, data): |
| 883 | self.log.debug('function-entry', data=data) |
Nicolas Palpacuer | 08cc818 | 2018-08-22 10:22:19 -0400 | [diff] [blame] | 884 | oper_state = data.get('oper_state', None) |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 885 | |
| 886 | onu_device = self.adapter_agent.get_device(self.device_id) |
| 887 | |
Nicolas Palpacuer | 08cc818 | 2018-08-22 10:22:19 -0400 | [diff] [blame] | 888 | if oper_state == 'down': |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 889 | self.log.debug('stopping-openomci-statemachine') |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 890 | reactor.callLater(0, self._onu_omci_device.stop) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 891 | |
| 892 | # Let TP download happen again |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 893 | for uni_id in self._tp_service_specific_task: |
| 894 | self._tp_service_specific_task[uni_id].clear() |
| 895 | for uni_id in self._tech_profile_download_done: |
| 896 | self._tech_profile_download_done[uni_id].clear() |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 897 | |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 898 | self.disable_ports(onu_device) |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 899 | onu_device.reason = "stopping-openomci" |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 900 | onu_device.connect_status = ConnectStatus.UNREACHABLE |
| 901 | onu_device.oper_status = OperStatus.DISCOVERED |
| 902 | self.adapter_agent.update_device(onu_device) |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 903 | else: |
| 904 | self.log.debug('not-changing-openomci-statemachine') |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 905 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 906 | # Not currently called by olt or anything else |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 907 | def remove_interface(self, data): |
| 908 | self.log.debug('function-entry', data=data) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 909 | |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 910 | onu_device = self.adapter_agent.get_device(self.device_id) |
| 911 | |
| 912 | self.log.debug('stopping-openomci-statemachine') |
| 913 | reactor.callLater(0, self._onu_omci_device.stop) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 914 | |
| 915 | # Let TP download happen again |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 916 | for uni_id in self._tp_service_specific_task: |
| 917 | self._tp_service_specific_task[uni_id].clear() |
| 918 | for uni_id in self._tech_profile_download_done: |
| 919 | self._tech_profile_download_done[uni_id].clear() |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 920 | |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 921 | self.disable_ports(onu_device) |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 922 | onu_device.reason = "stopping-openomci" |
| 923 | self.adapter_agent.update_device(onu_device) |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 924 | |
| 925 | # TODO: im sure there is more to do here |
| 926 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 927 | # Not currently called. Would be called presumably from the olt handler |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 928 | def remove_gemport(self, data): |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 929 | self.log.debug('remove-gemport', data=data) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 930 | gem_port = GemportsConfigData() |
| 931 | gem_port.CopyFrom(data) |
| 932 | device = self.adapter_agent.get_device(self.device_id) |
| 933 | if device.connect_status != ConnectStatus.REACHABLE: |
| 934 | self.log.error('device-unreachable') |
Matt Jeanneret | 1c90e50 | 2018-11-12 17:38:42 -0500 | [diff] [blame] | 935 | return |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 936 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 937 | # Not currently called. Would be called presumably from the olt handler |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 938 | def remove_tcont(self, tcont_data, traffic_descriptor_data): |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 939 | self.log.debug('remove-tcont', tcont_data=tcont_data, traffic_descriptor_data=traffic_descriptor_data) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 940 | device = self.adapter_agent.get_device(self.device_id) |
| 941 | if device.connect_status != ConnectStatus.REACHABLE: |
| 942 | self.log.error('device-unreachable') |
Matt Jeanneret | 1c90e50 | 2018-11-12 17:38:42 -0500 | [diff] [blame] | 943 | return |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 944 | |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 945 | # TODO: Create some omci task that encompases this what intended |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 946 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 947 | # Not currently called. Would be called presumably from the olt handler |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 948 | def create_multicast_gemport(self, data): |
| 949 | self.log.debug('function-entry', data=data) |
| 950 | |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 951 | # TODO: create objects and populate for later omci calls |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 952 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 953 | def disable(self, device): |
| 954 | self.log.debug('function-entry', device=device) |
| 955 | try: |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 956 | self.log.info('sending-uni-lock-towards-device', device=device) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 957 | |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 958 | def stop_anyway(reason): |
| 959 | # proceed with disable regardless if we could reach the onu. for example onu is unplugged |
| 960 | self.log.debug('stopping-openomci-statemachine') |
| 961 | reactor.callLater(0, self._onu_omci_device.stop) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 962 | |
| 963 | # Let TP download happen again |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 964 | for uni_id in self._tp_service_specific_task: |
| 965 | self._tp_service_specific_task[uni_id].clear() |
| 966 | for uni_id in self._tech_profile_download_done: |
| 967 | self._tech_profile_download_done[uni_id].clear() |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 968 | |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 969 | self.disable_ports(device) |
| 970 | device.oper_status = OperStatus.UNKNOWN |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 971 | device.reason = "omci-admin-lock" |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 972 | self.adapter_agent.update_device(device) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 973 | |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 974 | # lock all the unis |
| 975 | task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=True) |
| 976 | self._deferred = self._onu_omci_device.task_runner.queue_task(task) |
| 977 | self._deferred.addCallbacks(stop_anyway, stop_anyway) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 978 | except Exception as e: |
| 979 | log.exception('exception-in-onu-disable', exception=e) |
| 980 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 981 | def reenable(self, device): |
| 982 | self.log.debug('function-entry', device=device) |
| 983 | try: |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 984 | # Start up OpenOMCI state machines for this device |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 985 | # this will ultimately resync mib and unlock unis on successful redownloading the mib |
| 986 | self.log.debug('restarting-openomci-statemachine') |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 987 | self._subscribe_to_events() |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 988 | device.reason = "restarting-openomci" |
| 989 | self.adapter_agent.update_device(device) |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 990 | reactor.callLater(1, self._onu_omci_device.start) |
Scott Baker | c474bb9 | 2018-10-12 16:19:18 -0700 | [diff] [blame] | 991 | self._heartbeat.enabled = True |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 992 | except Exception as e: |
| 993 | log.exception('exception-in-onu-reenable', exception=e) |
| 994 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 995 | def reboot(self): |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 996 | self.log.info('reboot-device') |
| 997 | device = self.adapter_agent.get_device(self.device_id) |
| 998 | if device.connect_status != ConnectStatus.REACHABLE: |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 999 | self.log.error("device-unreachable") |
Matt Jeanneret | 1c90e50 | 2018-11-12 17:38:42 -0500 | [diff] [blame] | 1000 | return |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1001 | |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 1002 | def success(_results): |
| 1003 | self.log.info('reboot-success', _results=_results) |
| 1004 | self.disable_ports(device) |
| 1005 | device.connect_status = ConnectStatus.UNREACHABLE |
| 1006 | device.oper_status = OperStatus.DISCOVERED |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1007 | device.reason = "rebooting" |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 1008 | self.adapter_agent.update_device(device) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1009 | |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 1010 | def failure(_reason): |
| 1011 | self.log.info('reboot-failure', _reason=_reason) |
| 1012 | |
| 1013 | self._deferred = self._onu_omci_device.reboot() |
| 1014 | self._deferred.addCallbacks(success, failure) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1015 | |
| 1016 | def disable_ports(self, onu_device): |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 1017 | self.log.info('disable-ports', device_id=self.device_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1018 | onu_device=onu_device) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1019 | |
| 1020 | # Disable all ports on that device |
| 1021 | self.adapter_agent.disable_all_ports(self.device_id) |
| 1022 | |
| 1023 | parent_device = self.adapter_agent.get_device(onu_device.parent_id) |
| 1024 | assert parent_device |
| 1025 | logical_device_id = parent_device.parent_id |
| 1026 | assert logical_device_id |
| 1027 | ports = self.adapter_agent.get_ports(onu_device.id, Port.ETHERNET_UNI) |
| 1028 | for port in ports: |
| 1029 | port_id = 'uni-{}'.format(port.port_no) |
| 1030 | # TODO: move to UniPort |
| 1031 | self.update_logical_port(logical_device_id, port_id, OFPPS_LINK_DOWN) |
| 1032 | |
| 1033 | def enable_ports(self, onu_device): |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 1034 | self.log.info('enable-ports', device_id=self.device_id, onu_device=onu_device) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1035 | |
| 1036 | # Disable all ports on that device |
| 1037 | self.adapter_agent.enable_all_ports(self.device_id) |
| 1038 | |
| 1039 | parent_device = self.adapter_agent.get_device(onu_device.parent_id) |
| 1040 | assert parent_device |
| 1041 | logical_device_id = parent_device.parent_id |
| 1042 | assert logical_device_id |
| 1043 | ports = self.adapter_agent.get_ports(onu_device.id, Port.ETHERNET_UNI) |
| 1044 | for port in ports: |
| 1045 | port_id = 'uni-{}'.format(port.port_no) |
| 1046 | # TODO: move to UniPort |
| 1047 | self.update_logical_port(logical_device_id, port_id, OFPPS_LIVE) |
| 1048 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 1049 | # Called just before openomci state machine is started. These listen for events from selected state machines, |
| 1050 | # most importantly, mib in sync. Which ultimately leads to downloading the mib |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1051 | def _subscribe_to_events(self): |
| 1052 | self.log.debug('function-entry') |
| 1053 | |
| 1054 | # OMCI MIB Database sync status |
| 1055 | bus = self._onu_omci_device.event_bus |
| 1056 | topic = OnuDeviceEntry.event_bus_topic(self.device_id, |
| 1057 | OnuDeviceEvents.MibDatabaseSyncEvent) |
| 1058 | self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler) |
| 1059 | |
| 1060 | # OMCI Capabilities |
| 1061 | bus = self._onu_omci_device.event_bus |
| 1062 | topic = OnuDeviceEntry.event_bus_topic(self.device_id, |
| 1063 | OnuDeviceEvents.OmciCapabilitiesEvent) |
| 1064 | self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler) |
| 1065 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 1066 | # Called when the mib is in sync |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1067 | def in_sync_handler(self, _topic, msg): |
| 1068 | self.log.debug('function-entry', _topic=_topic, msg=msg) |
| 1069 | if self._in_sync_subscription is not None: |
| 1070 | try: |
| 1071 | in_sync = msg[IN_SYNC_KEY] |
| 1072 | |
| 1073 | if in_sync: |
| 1074 | # Only call this once |
| 1075 | bus = self._onu_omci_device.event_bus |
| 1076 | bus.unsubscribe(self._in_sync_subscription) |
| 1077 | self._in_sync_subscription = None |
| 1078 | |
| 1079 | # Start up device_info load |
| 1080 | self.log.debug('running-mib-sync') |
| 1081 | reactor.callLater(0, self._mib_in_sync) |
| 1082 | |
| 1083 | except Exception as e: |
| 1084 | self.log.exception('in-sync', e=e) |
| 1085 | |
| 1086 | def capabilties_handler(self, _topic, _msg): |
| 1087 | self.log.debug('function-entry', _topic=_topic, msg=_msg) |
| 1088 | if self._capabilities_subscription is not None: |
| 1089 | self.log.debug('capabilities-handler-done') |
| 1090 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 1091 | # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU. |
| 1092 | # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP |
| 1093 | # Implement your own MibDownloadTask if you wish to setup something different by default |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1094 | def _mib_in_sync(self): |
| 1095 | self.log.debug('function-entry') |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1096 | |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 1097 | omci = self._onu_omci_device |
| 1098 | in_sync = omci.mib_db_in_sync |
| 1099 | |
Matt Jeanneret | 6da5579 | 2018-08-08 16:44:18 -0400 | [diff] [blame] | 1100 | device = self.adapter_agent.get_device(self.device_id) |
| 1101 | device.reason = 'discovery-mibsync-complete' |
| 1102 | self.adapter_agent.update_device(device) |
| 1103 | |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 1104 | if not self._dev_info_loaded: |
| 1105 | self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1106 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1107 | omci_dev = self._onu_omci_device |
| 1108 | config = omci_dev.configuration |
| 1109 | |
Matt Jeanneret | 54c8266 | 2018-08-23 11:21:19 -0400 | [diff] [blame] | 1110 | # TODO: run this sooner somehow. shouldnt have to wait for mib sync to push an initial download |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1111 | # In Sync, we can register logical ports now. Ideally this could occur on |
| 1112 | # the first time we received a successful (no timeout) OMCI Rx response. |
| 1113 | try: |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1114 | |
Matt Jeanneret | f78f6aa | 2018-11-01 11:20:17 -0400 | [diff] [blame] | 1115 | # sort the lists so we get consistent port ordering. |
| 1116 | ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else [] |
| 1117 | uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else [] |
| 1118 | pptp_list = sorted(config.pptp_entities) if config.pptp_entities else [] |
| 1119 | veip_list = sorted(config.veip_entities) if config.veip_entities else [] |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1120 | |
Matt Jeanneret | f16726d | 2018-11-16 11:14:00 -0500 | [diff] [blame] | 1121 | if ani_list is None or (pptp_list is None and veip_list is None): |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1122 | device.reason = 'onu-missing-required-elements' |
Matt Jeanneret | f78f6aa | 2018-11-01 11:20:17 -0400 | [diff] [blame] | 1123 | self.log.warn("no-ani-or-unis") |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1124 | self.adapter_agent.update_device(device) |
| 1125 | raise Exception("onu-missing-required-elements") |
| 1126 | |
Matt Jeanneret | f78f6aa | 2018-11-01 11:20:17 -0400 | [diff] [blame] | 1127 | # Currently logging the ani, pptp, veip, and uni for information purposes. |
| 1128 | # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks. |
Matt Jeanneret | f16726d | 2018-11-16 11:14:00 -0500 | [diff] [blame] | 1129 | # And in some ONU the UNI-G list is incomplete or incorrect... |
Matt Jeanneret | f78f6aa | 2018-11-01 11:20:17 -0400 | [diff] [blame] | 1130 | for entity_id in ani_list: |
| 1131 | ani_value = config.ani_g_entities[entity_id] |
| 1132 | self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value) |
| 1133 | # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..? |
| 1134 | self._total_tcont_count = ani_value.get('total-tcont-count') |
| 1135 | self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1136 | |
Matt Jeanneret | f78f6aa | 2018-11-01 11:20:17 -0400 | [diff] [blame] | 1137 | for entity_id in uni_list: |
| 1138 | uni_value = config.uni_g_entities[entity_id] |
| 1139 | self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value) |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1140 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1141 | uni_entities = OrderedDict() |
Matt Jeanneret | f16726d | 2018-11-16 11:14:00 -0500 | [diff] [blame] | 1142 | for entity_id in pptp_list: |
| 1143 | pptp_value = config.pptp_entities[entity_id] |
| 1144 | self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1145 | uni_entities[entity_id] = UniType.PPTP |
Matt Jeanneret | f16726d | 2018-11-16 11:14:00 -0500 | [diff] [blame] | 1146 | |
| 1147 | for entity_id in veip_list: |
| 1148 | veip_value = config.veip_entities[entity_id] |
| 1149 | self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1150 | uni_entities[entity_id] = UniType.VEIP |
| 1151 | |
| 1152 | uni_id = 0 |
| 1153 | for entity_id, uni_type in uni_entities.iteritems(): |
| 1154 | try: |
| 1155 | self._add_uni_port(entity_id, uni_id, uni_type) |
| 1156 | uni_id += 1 |
| 1157 | except AssertionError as e: |
| 1158 | self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e) |
| 1159 | |
| 1160 | multi_uni = len(self._unis) > 1 |
| 1161 | for uni_port in self._unis.itervalues(): |
| 1162 | uni_port.add_logical_port(uni_port.port_number, multi_uni) |
| 1163 | |
| 1164 | self.adapter_agent.update_device(device) |
Matt Jeanneret | f78f6aa | 2018-11-01 11:20:17 -0400 | [diff] [blame] | 1165 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1166 | self._qos_flexibility = config.qos_configuration_flexibility or 0 |
| 1167 | self._omcc_version = config.omcc_version or OMCCVersion.Unknown |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1168 | |
Matt Jeanneret | f78f6aa | 2018-11-01 11:20:17 -0400 | [diff] [blame] | 1169 | if self._unis: |
| 1170 | self._dev_info_loaded = True |
| 1171 | else: |
| 1172 | device.reason = 'no-usable-unis' |
| 1173 | self.adapter_agent.update_device(device) |
| 1174 | self.log.warn("no-usable-unis") |
| 1175 | raise Exception("no-usable-unis") |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1176 | |
Matt Jeanneret | e6a7033 | 2018-07-20 16:11:25 -0400 | [diff] [blame] | 1177 | except Exception as e: |
| 1178 | self.log.exception('device-info-load', e=e) |
| 1179 | self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync) |
| 1180 | |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 1181 | else: |
| 1182 | self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded) |
| 1183 | |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1184 | if self._dev_info_loaded: |
| 1185 | if device.admin_state == AdminState.ENABLED: |
| 1186 | def success(_results): |
| 1187 | self.log.info('mib-download-success', _results=_results) |
| 1188 | device = self.adapter_agent.get_device(self.device_id) |
| 1189 | device.reason = 'initial-mib-downloaded' |
| 1190 | device.oper_status = OperStatus.ACTIVE |
| 1191 | device.connect_status = ConnectStatus.REACHABLE |
| 1192 | self.enable_ports(device) |
| 1193 | self.adapter_agent.update_device(device) |
| 1194 | self._mib_download_task = None |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 1195 | |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1196 | def failure(_reason): |
Matt Jeanneret | f444840 | 2018-09-25 12:51:19 -0400 | [diff] [blame] | 1197 | self.log.warn('mib-download-failure-retrying', _reason=_reason) |
| 1198 | device.reason = 'initial-mib-download-failure-retrying' |
| 1199 | self.adapter_agent.update_device(device) |
| 1200 | self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync) |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1201 | |
| 1202 | # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set |
| 1203 | # the device to active/reachable. This then opens up the handler to openflow pushes from outside |
| 1204 | self.log.info('downloading-initial-mib-configuration') |
Matt Jeanneret | 04ba4fd | 2018-08-16 15:32:21 -0400 | [diff] [blame] | 1205 | self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self) |
| 1206 | self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task) |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1207 | self._deferred.addCallbacks(success, failure) |
| 1208 | else: |
| 1209 | self.log.info('admin-down-disabling') |
| 1210 | self.disable(device) |
Matt Jeanneret | 04ba4fd | 2018-08-16 15:32:21 -0400 | [diff] [blame] | 1211 | else: |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1212 | self.log.info('device-info-not-loaded-skipping-mib-download') |
| 1213 | |
| 1214 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1215 | def _add_uni_port(self, entity_id, uni_id, uni_type=UniType.PPTP): |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1216 | self.log.debug('function-entry') |
| 1217 | |
| 1218 | device = self.adapter_agent.get_device(self.device_id) |
| 1219 | parent_device = self.adapter_agent.get_device(device.parent_id) |
| 1220 | |
| 1221 | parent_adapter_agent = registry('adapter_loader').get_agent(parent_device.adapter) |
| 1222 | if parent_adapter_agent is None: |
Matt Jeanneret | f78f6aa | 2018-11-01 11:20:17 -0400 | [diff] [blame] | 1223 | self.log.error('parent-adapter-could-not-be-retrieved') |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1224 | |
| 1225 | # TODO: This knowledge is locked away in openolt. and it assumes one onu equals one uni... |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 1226 | parent_device = self.adapter_agent.get_device(device.parent_id) |
| 1227 | parent_adapter = parent_adapter_agent.adapter.devices[parent_device.id] |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1228 | uni_no = parent_adapter.platform.mk_uni_port_num( |
| 1229 | self._onu_indication.intf_id, self._onu_indication.onu_id, uni_id) |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1230 | |
| 1231 | # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1232 | uni_name = "uni-{}".format(uni_no) |
| 1233 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1234 | mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1235 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1236 | self.log.debug('uni-port-inputs', uni_no=uni_no, uni_id=uni_id, uni_name=uni_name, uni_type=uni_type, |
Matt Jeanneret | f78f6aa | 2018-11-01 11:20:17 -0400 | [diff] [blame] | 1237 | entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num) |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1238 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1239 | uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type) |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1240 | uni_port.entity_id = entity_id |
| 1241 | uni_port.enabled = True |
| 1242 | uni_port.mac_bridge_port_num = mac_bridge_port_num |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1243 | |
| 1244 | self.log.debug("created-uni-port", uni=uni_port) |
| 1245 | |
| 1246 | self.adapter_agent.add_port(device.id, uni_port.get_port()) |
| 1247 | parent_adapter_agent.add_port(device.parent_id, uni_port.get_port()) |
| 1248 | |
| 1249 | self._unis[uni_port.port_number] = uni_port |
| 1250 | |
Chip Boling | 3186eb5 | 2018-11-02 14:28:01 -0500 | [diff] [blame] | 1251 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id, |
| 1252 | uni_ports=self._unis.values()) |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1253 | # TODO: this should be in the PonPortclass |
| 1254 | pon_port = self._pon.get_port() |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1255 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1256 | # Delete reference to my own UNI as peer from parent. |
| 1257 | # TODO why is this here, add_port_reference_to_parent already prunes duplicates |
| 1258 | me_as_peer = Port.PeerPort(device_id=device.parent_id, port_no=uni_port.port_number) |
| 1259 | partial_pon_port = Port(port_no=pon_port.port_no, label=pon_port.label, |
| 1260 | type=pon_port.type, admin_state=pon_port.admin_state, |
| 1261 | oper_status=pon_port.oper_status, |
| 1262 | peers=[me_as_peer]) # only list myself as a peer to avoid deleting all other UNIs from parent |
| 1263 | self.adapter_agent.delete_port_reference_from_parent(self.device_id, partial_pon_port) |
| 1264 | |
| 1265 | pon_port.peers.extend([me_as_peer]) |
Matt Jeanneret | 94f8d29 | 2018-08-31 12:49:27 -0400 | [diff] [blame] | 1266 | |
| 1267 | self._pon._port = pon_port |
| 1268 | |
| 1269 | self.adapter_agent.add_port_reference_to_parent(self.device_id, |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 1270 | pon_port) |