Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 1 | # Copyright 2017-present Adtran, Inc. |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 14 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 15 | import json |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 16 | import random |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 17 | import arrow |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 18 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 19 | import structlog |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 20 | from port import AdtnPort |
Chip Boling | 4864696 | 2017-08-20 09:41:18 -0500 | [diff] [blame] | 21 | from twisted.internet import reactor, defer |
Chip Boling | bffef5e | 2018-08-07 14:53:12 -0500 | [diff] [blame] | 22 | from twisted.internet.defer import inlineCallbacks, returnValue |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 23 | from adtran_olt_handler import AdtranOltHandler |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 24 | from net.adtran_rest import RestInvalidResponseCode |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 25 | from codec.olt_config import OltConfig |
| 26 | from onu import Onu |
Chip Boling | bffef5e | 2018-08-07 14:53:12 -0500 | [diff] [blame] | 27 | from voltha.extensions.alarms.onu.onu_los_alarm import OnuLosAlarm |
Chip Boling | bb15b51 | 2018-06-01 11:39:58 -0500 | [diff] [blame] | 28 | from voltha.protos.common_pb2 import AdminState |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 29 | from voltha.protos.device_pb2 import Port |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 30 | from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData |
| 31 | from voltha.protos.bbf_fiber_traffic_descriptor_profile_body_pb2 import TrafficDescriptorProfileData |
| 32 | from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData |
| 33 | from xpon.olt_traffic_descriptor import OltTrafficDescriptor |
| 34 | import resources.adtranolt_platform as platform |
| 35 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 36 | |
Chip Boling | bb15b51 | 2018-06-01 11:39:58 -0500 | [diff] [blame] | 37 | try: |
Chip Boling | bffef5e | 2018-08-07 14:53:12 -0500 | [diff] [blame] | 38 | from voltha.extensions.alarms.onu.onu_discovery_alarm import OnuDiscoveryAlarm |
Chip Boling | bb15b51 | 2018-06-01 11:39:58 -0500 | [diff] [blame] | 39 | except ImportError: |
Chip Boling | bffef5e | 2018-08-07 14:53:12 -0500 | [diff] [blame] | 40 | from voltha.extensions.alarms.onu.onu_discovery_alarm import OnuDiscoveryAlarm |
Chip Boling | bb15b51 | 2018-06-01 11:39:58 -0500 | [diff] [blame] | 41 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 42 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 43 | class PonPort(AdtnPort): |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 44 | """ |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 45 | GPON Port |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 46 | """ |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 47 | MAX_ONUS_SUPPORTED = 128 |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 48 | MAX_DEPLOYMENT_RANGE = 25000 # Meters (OLT-PB maximum) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 49 | |
| 50 | _MCAST_ONU_ID = 253 |
| 51 | _MCAST_ALLOC_BASE = 0x500 |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 52 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 53 | # AutoActivate should be used if xPON configuration is not supported |
| 54 | _SUPPORTED_ACTIVATION_METHODS = ['autodiscovery', 'autoactivate'] |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 55 | _SUPPORTED_AUTHENTICATION_METHODS = ['serial-number'] |
| 56 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 57 | def __init__(self, parent, **kwargs): |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 58 | super(PonPort, self).__init__(parent, **kwargs) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 59 | assert 'pon-id' in kwargs, 'PON ID not found' |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 60 | |
| 61 | self._parent = parent |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 62 | self._pon_id = kwargs['pon-id'] |
| 63 | self.log = structlog.get_logger(device_id=parent.device_id, pon_id=self._pon_id) |
| 64 | self._port_no = kwargs['port_no'] |
Chip Boling | 3eedf46 | 2018-10-17 12:18:28 -0500 | [diff] [blame] | 65 | self._physical_port_name = 'xpon 0/{}'.format(self._pon_id+1) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 66 | self._label = 'pon-{}'.format(self._pon_id) |
| 67 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 68 | self._in_sync = False |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 69 | self._expedite_sync = False |
| 70 | self._expedite_count = 0 |
| 71 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 72 | self._discovery_tick = 20.0 |
| 73 | self._no_onu_discover_tick = self._discovery_tick / 2 |
| 74 | self._discovered_onus = [] # List of serial numbers |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 75 | self._discovery_deferred = None # Specifically for ONU discovery |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 76 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 77 | self._onus = {} # serial_number-base64 -> ONU (allowed list) |
| 78 | self._onu_by_id = {} # onu-id -> ONU |
| 79 | self._mcast_gem_ports = {} # VLAN -> GemPort |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 80 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 81 | self._active_los_alarms = set() # ONU-ID |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 82 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 83 | # xPON configuration |
| 84 | self._activation_method = 'autoactivate' |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 85 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 86 | self._downstream_fec_enable = True |
| 87 | self._upstream_fec_enable = True |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 88 | self._deployment_range = 25000 |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 89 | self._authentication_method = 'serial-number' |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 90 | self._mcast_aes = False |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 91 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 92 | # Statistics |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 93 | self.tx_bip_errors = 0 |
| 94 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 95 | # xPON Configuration (TODO: Move Tcont/GEMPort to ONU eventually) |
| 96 | # TODO: TD may be system-wide, wait for Service Profiles |
| 97 | self._v_ont_anis = {} # Name -> dict |
| 98 | self._ont_anis = {} # Name -> dict |
| 99 | self._tconts = {} # Name -> dict |
| 100 | self._traffic_descriptors = {} # Name -> dict |
| 101 | self._gem_ports = {} # Name -> dict |
| 102 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 103 | def __str__(self): |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 104 | return "PonPort-{}: Admin: {}, Oper: {}, OLT: {}".format(self._label, |
| 105 | self._admin_state, |
| 106 | self._oper_status, |
| 107 | self.olt) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 108 | |
| 109 | def get_port(self): |
| 110 | """ |
| 111 | Get the VOLTHA PORT object for this port |
| 112 | :return: VOLTHA Port object |
| 113 | """ |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 114 | if self._port is None: |
| 115 | self._port = Port(port_no=self._port_no, |
| 116 | label=self._label, |
| 117 | type=Port.PON_OLT, |
Chip Boling | c64c8dc | 2018-04-20 14:42:24 -0500 | [diff] [blame] | 118 | admin_state=self._admin_state, |
| 119 | oper_status=self._oper_status) |
| 120 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 121 | return self._port |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 122 | |
| 123 | @property |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 124 | def pon_id(self): |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 125 | return self._pon_id |
| 126 | |
| 127 | @property |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 128 | def onus(self): |
| 129 | """ |
| 130 | Get a set of all ONUs. While the set is immutable, do not use this method |
| 131 | to get a collection that you will iterate through that my yield the CPU |
| 132 | such as inline callback. ONUs may be deleted at any time and they will |
| 133 | set some references to other objects to NULL during the 'delete' call. |
| 134 | Instead, get a list of ONU-IDs and iterate on these and call the 'onu' |
| 135 | method below (which will return 'None' if the ONU has been deleted. |
| 136 | |
| 137 | :return: (frozenset) collection of ONU objects on this PON |
| 138 | """ |
| 139 | return frozenset(self._onus.values()) |
| 140 | |
| 141 | @property |
| 142 | def onu_ids(self): |
| 143 | return frozenset(self._onu_by_id.keys()) |
| 144 | |
Chip Boling | ef0e2fa | 2017-10-06 14:33:01 -0500 | [diff] [blame] | 145 | def onu(self, onu_id): |
| 146 | return self._onu_by_id.get(onu_id) |
| 147 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 148 | @property |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 149 | def in_service_onus(self): |
| 150 | return len({onu.onu_id for onu in self.onus |
| 151 | if onu.onu_id not in self._active_los_alarms}) |
| 152 | |
| 153 | @property |
| 154 | def closest_onu_distance(self): |
| 155 | distance = -1 |
| 156 | for onu in self.onus: |
| 157 | if onu.fiber_length < distance or distance == -1: |
| 158 | distance = onu.fiber_length |
| 159 | return distance |
| 160 | |
| 161 | @property |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 162 | def downstream_fec_enable(self): |
| 163 | return self._downstream_fec_enable |
| 164 | |
| 165 | @downstream_fec_enable.setter |
| 166 | def downstream_fec_enable(self, value): |
| 167 | assert isinstance(value, bool), 'downstream FEC enabled is a boolean' |
| 168 | |
| 169 | if self._downstream_fec_enable != value: |
| 170 | self._downstream_fec_enable = value |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 171 | if self.state == AdtnPort.State.RUNNING: |
| 172 | self.deferred = self._set_pon_config("downstream-fec-enable", value) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 173 | |
| 174 | @property |
| 175 | def upstream_fec_enable(self): |
| 176 | return self._upstream_fec_enable |
| 177 | |
| 178 | @upstream_fec_enable.setter |
| 179 | def upstream_fec_enable(self, value): |
| 180 | assert isinstance(value, bool), 'upstream FEC enabled is a boolean' |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 181 | if self._upstream_fec_enable != value: |
| 182 | self._upstream_fec_enable = value |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 183 | if self.state == AdtnPort.State.RUNNING: |
| 184 | self.deferred = self._set_pon_config("upstream-fec-enable", value) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 185 | |
| 186 | @property |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 187 | def any_upstream_fec_enabled(self): |
| 188 | for onu in self.onus: |
| 189 | if onu.upstream_fec_enable and onu.enabled: |
| 190 | return True |
| 191 | return False |
| 192 | |
| 193 | @property |
| 194 | def mcast_aes(self): |
| 195 | return self._mcast_aes |
| 196 | |
| 197 | @mcast_aes.setter |
| 198 | def mcast_aes(self, value): |
| 199 | assert isinstance(value, bool), 'MCAST AES is a boolean' |
| 200 | if self._mcast_aes != value: |
| 201 | self._mcast_aes = value |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 202 | if self.state == AdtnPort.State.RUNNING: |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 203 | pass # TODO |
| 204 | |
| 205 | @property |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 206 | def deployment_range(self): |
| 207 | """Maximum deployment range (in meters)""" |
| 208 | return self._deployment_range |
| 209 | |
| 210 | @deployment_range.setter |
| 211 | def deployment_range(self, value): |
| 212 | """Maximum deployment range (in meters)""" |
| 213 | if not 0 <= value <= PonPort.MAX_DEPLOYMENT_RANGE: |
| 214 | raise ValueError('Deployment range should be 0..{} meters'. |
| 215 | format(PonPort.MAX_DEPLOYMENT_RANGE)) |
| 216 | if self._deployment_range != value: |
| 217 | self._deployment_range = value |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 218 | if self.state == AdtnPort.State.RUNNING: |
| 219 | self.deferred = self._set_pon_config("deployment-range", value) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 220 | |
| 221 | @property |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 222 | def discovery_tick(self): |
| 223 | return self._discovery_tick * 10 |
| 224 | |
| 225 | @discovery_tick.setter |
| 226 | def discovery_tick(self, value): |
| 227 | if value < 0: |
| 228 | raise ValueError("Polling interval must be >= 0") |
| 229 | |
| 230 | if self.discovery_tick != value: |
| 231 | self._discovery_tick = value / 10 |
| 232 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 233 | try: |
| 234 | if self._discovery_deferred is not None and \ |
| 235 | not self._discovery_deferred.called: |
| 236 | self._discovery_deferred.cancel() |
| 237 | except: |
| 238 | pass |
| 239 | self._discovery_deferred = None |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 240 | |
| 241 | if self._discovery_tick > 0: |
| 242 | self._discovery_deferred = reactor.callLater(self._discovery_tick, |
| 243 | self._discover_onus) |
| 244 | |
| 245 | @property |
| 246 | def activation_method(self): |
| 247 | return self._activation_method |
| 248 | |
| 249 | @activation_method.setter |
| 250 | def activation_method(self, value): |
| 251 | value = value.lower() |
| 252 | if value not in PonPort._SUPPORTED_ACTIVATION_METHODS: |
| 253 | raise ValueError('Invalid ONU activation method') |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 254 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 255 | self._activation_method = value |
| 256 | |
| 257 | @property |
| 258 | def authentication_method(self): |
| 259 | return self._authentication_method |
| 260 | |
| 261 | @authentication_method.setter |
| 262 | def authentication_method(self, value): |
| 263 | value = value.lower() |
| 264 | if value not in PonPort._SUPPORTED_AUTHENTICATION_METHODS: |
| 265 | raise ValueError('Invalid ONU authentication method') |
| 266 | self._authentication_method = value |
| 267 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 268 | def cancel_deferred(self): |
| 269 | super(PonPort, self).cancel_deferred() |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 270 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 271 | d, self._discovery_deferred = self._discovery_deferred, None |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 272 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 273 | try: |
| 274 | if d is not None and not d.called: |
| 275 | d.cancel() |
| 276 | except Exception as e: |
| 277 | pass |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 278 | |
| 279 | def _update_adapter_agent(self): |
Chip Boling | c64c8dc | 2018-04-20 14:42:24 -0500 | [diff] [blame] | 280 | """ |
| 281 | Update the port status and state in the core |
| 282 | """ |
| 283 | self.log.debug('update-adapter-agent', admin_state=self._admin_state, |
Chip Boling | 3971d24 | 2018-06-06 10:26:34 -0500 | [diff] [blame] | 284 | oper_status=self._oper_status) |
Chip Boling | c64c8dc | 2018-04-20 14:42:24 -0500 | [diff] [blame] | 285 | |
| 286 | # because the core does not provide methods for updating admin |
| 287 | # and oper status per port, we need to copy any existing port |
| 288 | # info so that we don't wipe out the peers |
| 289 | if self._port is not None: |
| 290 | agent_ports = self.adapter_agent.get_ports(self.olt.device_id, Port.PON_OLT) |
| 291 | |
| 292 | agent_port = next((ap for ap in agent_ports if ap.port_no == self._port_no), None) |
| 293 | |
| 294 | # copy current Port info |
| 295 | if agent_port is not None: |
Chip Boling | 3971d24 | 2018-06-06 10:26:34 -0500 | [diff] [blame] | 296 | self._port = agent_port |
Chip Boling | c64c8dc | 2018-04-20 14:42:24 -0500 | [diff] [blame] | 297 | |
| 298 | # set new states |
| 299 | self._port.admin_state = self._admin_state |
| 300 | self._port.oper_status = self._oper_status |
| 301 | |
| 302 | # adapter_agent add_port also does an update of existing port |
| 303 | self.adapter_agent.add_port(self.olt.device_id, self.get_port()) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 304 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 305 | @inlineCallbacks |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 306 | def finish_startup(self): |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 307 | """ |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 308 | Do all startup offline since REST may fail |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 309 | """ |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 310 | if self.state != AdtnPort.State.INITIAL: |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 311 | returnValue('Done') |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 312 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 313 | self.log.debug('final-startup') |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 314 | results = None |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 315 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 316 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 317 | self.deferred = self._get_pon_config() |
| 318 | results = yield self.deferred |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 319 | |
| 320 | except Exception as e: |
| 321 | self.log.exception('initial-GET', e=e) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 322 | self.deferred = reactor.callLater(5, self.finish_startup) |
| 323 | returnValue(self.deferred) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 324 | |
| 325 | # Load config from hardware |
| 326 | |
| 327 | enabled = results.get('enabled', False) |
| 328 | downstream_fec_enable = results.get('downstream-fec-enable', False) |
| 329 | upstream_fec_enable = results.get('upstream-fec-enable', False) |
| 330 | deployment_range = results.get('deployment-range', 25000) |
| 331 | self._in_sync = True |
| 332 | |
| 333 | if enabled != self._enabled: |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 334 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 335 | self.deferred = self._set_pon_config("enabled", True) |
| 336 | yield self.deferred |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 337 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 338 | except Exception as e: |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 339 | self.log.exception('final-startup-enable', e=e) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 340 | self.deferred = reactor.callLater(3, self.finish_startup) |
| 341 | returnValue(self.deferred) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 342 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 343 | if downstream_fec_enable != self._downstream_fec_enable: |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 344 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 345 | self.deferred = self._set_pon_config("downstream-fec-enable", |
| 346 | self._downstream_fec_enable) |
| 347 | yield self.deferred |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 348 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 349 | except Exception as e: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 350 | self.log.warning('final-startup-downstream-FEC', e=e) |
| 351 | self._in_sync = False |
| 352 | # Non-fatal. May have failed due to no SFQ in slot |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 353 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 354 | if upstream_fec_enable != self._upstream_fec_enable: |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 355 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 356 | self.deferred = self._set_pon_config("upstream-fec-enable", |
| 357 | self._upstream_fec_enable) |
| 358 | yield self.deferred |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 359 | |
| 360 | except Exception as e: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 361 | self.log.warning('final-startup-upstream-FEC', e=e) |
| 362 | self._in_sync = False |
| 363 | # Non-fatal. May have failed due to no SFQ in slot |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 364 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 365 | if deployment_range != self._deployment_range: |
| 366 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 367 | self.deferred = self._set_pon_config("deployment-range", |
| 368 | self._deployment_range) |
| 369 | yield self.deferred |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 370 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 371 | except Exception as e: |
| 372 | self.log.warning('final-startup-deployment-range', e=e) |
| 373 | self._in_sync = False |
| 374 | # Non-fatal. May have failed due to no SFQ in slot |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 375 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 376 | if len(self._onus) > 0: |
| 377 | dl = [] |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 378 | for onu_id in self.onu_ids: |
| 379 | onu = self.onu(onu_id) |
| 380 | if onu is not None: |
| 381 | dl.append(onu.restart()) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 382 | yield defer.gatherResults(dl, consumeErrors=True) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 383 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 384 | # Begin to ONU discovery and hardware sync |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 385 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 386 | self._discovery_deferred = reactor.callLater(5, self._discover_onus) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 387 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 388 | # If here, initial settings were successfully written to hardware |
| 389 | |
| 390 | super(PonPort, self).finish_startup() |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 391 | returnValue('Enabled') |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 392 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 393 | def finish_stop(self): |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 394 | # Remove all existing ONUs. They will need to be re-discovered |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 395 | dl = [] |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 396 | onu_ids = frozenset(self._onu_by_id.keys()) |
| 397 | for onu_id in onu_ids: |
| 398 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 399 | dl.append(self.delete_onu(onu_id)) |
| 400 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 401 | except Exception as e: |
| 402 | self.log.exception('onu-cleanup', onu_id=onu_id, e=e) |
| 403 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 404 | dl.append(self._set_pon_config("enabled", False)) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 405 | return defer.gatherResults(dl, consumeErrors=True) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 406 | |
| 407 | @inlineCallbacks |
| 408 | def reset(self): |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 409 | """ |
| 410 | Set the PON Port to a known good state on initial port startup. Actual |
| 411 | PON 'Start' is done elsewhere |
| 412 | """ |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 413 | initial_port_state = AdminState.ENABLED |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 414 | self.log.info('reset', initial_state=initial_port_state) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 415 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 416 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 417 | self.deferred = self._get_pon_config() |
| 418 | results = yield self.deferred |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 419 | enabled = results.get('enabled', False) |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 420 | |
| 421 | except Exception as e: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 422 | self.log.exception('get-config', e=e) |
| 423 | enabled = False |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 424 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 425 | enable = initial_port_state == AdminState.ENABLED |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 426 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 427 | if enable != enabled: |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 428 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 429 | self.deferred = yield self._set_pon_config("enabled", enable) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 430 | except Exception as e: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 431 | self.log.exception('reset-enabled', e=e, enabled=enabled) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 432 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 433 | # TODO: Move to 'set_pon_config' method and also make sure GRPC/Port is ok |
| 434 | self._admin_state = AdminState.ENABLED if enable else AdminState.DISABLED |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 435 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 436 | try: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 437 | # Walk the provisioned ONU list and disable any exiting ONUs |
| 438 | results = yield self._get_onu_config() |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 439 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 440 | if isinstance(results, list) and len(results) > 0: |
| 441 | onu_configs = OltConfig.Pon.Onu.decode(results) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 442 | dl = [] |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 443 | for onu_id in onu_configs.iterkeys(): |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 444 | dl.append(self.delete_onu(onu_id)) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 445 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 446 | try: |
| 447 | if len(dl) > 0: |
| 448 | yield defer.gatherResults(dl, consumeErrors=True) |
| 449 | |
| 450 | except Exception as e: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 451 | self.log.exception('rest-ONU-delete', e=e) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 452 | pass # Non-fatal |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 453 | |
| 454 | except Exception as e: |
| 455 | self.log.exception('onu-delete', e=e) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 456 | |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 457 | returnValue('Reset complete') |
| 458 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 459 | def gem_ids(self, logical_port, flow_vlan, multicast_gems=False): |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 460 | """ |
| 461 | Get all GEM Port IDs used on a given PON |
| 462 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 463 | :param logical_port: (int) Logical port number of ONU. None if for all ONUs |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 464 | on PON, if Multicast, VID for Multicast, or None for all |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 465 | Multicast GEMPorts |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 466 | :param flow_vlan: (int) If not None, this is the ingress tag (c-tag) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 467 | :param multicast_gems: (boolean) Select from available Multicast GEM Ports |
| 468 | :return: (dict) data_gem -> key -> onu-id, value -> tuple(sorted list of GEM Port IDs, onu_vid) |
| 469 | mcast_gem-> key -> mcast-vid, value -> GEM Port IDs |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 470 | """ |
| 471 | gem_ids = {} |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 472 | |
| 473 | if multicast_gems: |
| 474 | # Multicast GEMs belong to the PON, but we may need to register them on |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 475 | # all ONUs. TODO: Rework when BBF MCAST is addressed in VOLTHA v2.O+ |
| 476 | for vlan, gem_port in self._mcast_gem_ports.iteritems(): |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 477 | if logical_port is None or (logical_port == vlan and logical_port in self.olt.multicast_vlans): |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 478 | gem_ids[vlan] = ([gem_port.gem_id], None) |
| 479 | else: |
| 480 | for onu_id, onu in self._onu_by_id.iteritems(): |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 481 | if logical_port is None or logical_port == onu.logical_port: |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 482 | gem_ids[onu_id] = (onu.gem_ids(), flow_vlan) |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 483 | return gem_ids |
| 484 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 485 | def _get_pon_config(self): |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 486 | uri = AdtranOltHandler.GPON_PON_CONFIG_URI.format(self._pon_id) |
| 487 | name = 'pon-get-config-{}'.format(self._pon_id) |
| 488 | return self._parent.rest_client.request('GET', uri, name=name) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 489 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 490 | def _get_onu_config(self, onu_id=None): |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 491 | if onu_id is None: |
| 492 | uri = AdtranOltHandler.GPON_ONU_CONFIG_LIST_URI.format(self._pon_id) |
| 493 | else: |
| 494 | uri = AdtranOltHandler.GPON_ONU_CONFIG_URI.format(self._pon_id, onu_id) |
| 495 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 496 | name = 'pon-get-onu_config-{}-{}'.format(self._pon_id, onu_id) |
| 497 | return self._parent.rest_client.request('GET', uri, name=name) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 498 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 499 | def _set_pon_config(self, leaf, value): |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 500 | data = json.dumps({leaf: value}) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 501 | uri = AdtranOltHandler.GPON_PON_CONFIG_URI.format(self._pon_id) |
| 502 | name = 'pon-set-config-{}-{}-{}'.format(self._pon_id, leaf, str(value)) |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 503 | # If no optics on PON, then PON config fails with status 400, suppress this |
| 504 | suppress_error = len(self.onu_ids) == 0 |
| 505 | return self._parent.rest_client.request('PATCH', uri, data=data, name=name, |
| 506 | suppress_error=suppress_error) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 507 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 508 | def _discover_onus(self): |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 509 | self.log.debug('discovery', state=self._admin_state, in_sync=self._in_sync) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 510 | if self._admin_state == AdminState.ENABLED: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 511 | if self._in_sync: |
| 512 | data = json.dumps({'pon-id': self._pon_id}) |
| 513 | uri = AdtranOltHandler.GPON_PON_DISCOVER_ONU |
| 514 | name = 'pon-discover-onu-{}'.format(self._pon_id) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 515 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 516 | self._discovery_deferred = self._parent.rest_client.request('POST', uri, data, name=name) |
| 517 | self._discovery_deferred.addBoth(self._onu_discovery_init_complete) |
| 518 | else: |
| 519 | self.discovery_deferred = reactor.callLater(0, |
| 520 | self._onu_discovery_init_complete, |
| 521 | None) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 522 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 523 | def _onu_discovery_init_complete(self, _result): |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 524 | """ |
| 525 | This method is called after the REST POST to request ONU discovery is |
| 526 | completed. The results (body) of the post is always empty / 204 NO CONTENT |
| 527 | """ |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 528 | delay = self._no_onu_discover_tick if len(self._onus) == 0 else self._discovery_tick |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 529 | delay += random.uniform(-delay / 10, delay / 10) |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 530 | self._discovery_deferred = reactor.callLater(delay, self._discover_onus) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 531 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 532 | def sync_hardware(self): |
| 533 | if self.state == AdtnPort.State.RUNNING or self.state == AdtnPort.State.STOPPED: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 534 | def read_config(results): |
| 535 | self.log.debug('read-config', results=results) |
| 536 | config = OltConfig.Pon.decode([results]) |
| 537 | assert self.pon_id in config, 'sync-pon-not-found-{}'.format(self.pon_id) |
| 538 | config = config[self.pon_id] |
| 539 | self._in_sync = True |
| 540 | |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 541 | dl = [] |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 542 | |
| 543 | if self.enabled != config.enabled: |
| 544 | self._in_sync = False |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 545 | self._expedite_sync = True |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 546 | dl.append(self._set_pon_config("enabled", self.enabled)) |
| 547 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 548 | elif self.state == AdtnPort.State.RUNNING: |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 549 | if self.deployment_range != config.deployment_range: |
| 550 | self._in_sync = False |
| 551 | self._expedite_sync = True |
| 552 | dl.append(self._set_pon_config("deployment-range", |
| 553 | self.deployment_range)) |
| 554 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 555 | # A little side note: FEC enable/disable cannot be changed and |
| 556 | # will remain in the previous status until an optical module |
| 557 | # is plugged in. |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 558 | if self.downstream_fec_enable != config.downstream_fec_enable: |
| 559 | self._in_sync = False |
| 560 | dl.append(self._set_pon_config("downstream-fec-enable", |
| 561 | self.downstream_fec_enable)) |
| 562 | |
| 563 | if self.upstream_fec_enable != config.upstream_fec_enable: |
| 564 | self._in_sync = False |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 565 | self._expedite_sync = True |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 566 | dl.append(self._set_pon_config("upstream-fec-enable", |
| 567 | self.upstream_fec_enable)) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 568 | defer.gatherResults(dl, consumeErrors=True) |
| 569 | return config.onus |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 570 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 571 | def sync_onus(hw_onus): |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 572 | if self.state == AdtnPort.State.RUNNING: |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 573 | self.log.debug('sync-pon-onu-results', config=hw_onus) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 574 | |
| 575 | # ONU's have their own sync task, extra (should be deleted) are |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 576 | # handled here. |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 577 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 578 | hw_onu_ids = frozenset(hw_onus.keys()) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 579 | my_onu_ids = frozenset(self._onu_by_id.keys()) |
| 580 | |
| 581 | extra_onus = hw_onu_ids - my_onu_ids |
| 582 | dl = [self.delete_onu(onu_id) for onu_id in extra_onus] |
| 583 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 584 | if self.activation_method == "autoactivate": |
| 585 | # Autoactivation of ONUs requires missing ONU detection. If |
| 586 | # not found, create them here but let TCont/GEM-Port restore be |
| 587 | # handle by ONU H/w sync logic. |
| 588 | for onu in [self._onu_by_id[onu_id] for onu_id in my_onu_ids - hw_onu_ids |
| 589 | if self._onu_by_id.get(onu_id) is not None]: |
| 590 | dl.append(onu.create(dict(), dict(), reflow=True)) |
| 591 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 592 | return defer.gatherResults(dl, consumeErrors=True) |
| 593 | |
| 594 | def failure(reason, what): |
| 595 | self.log.error('hardware-sync-{}-failed'.format(what), reason=reason) |
| 596 | self._in_sync = False |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 597 | self._expedite_sync = False |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 598 | |
| 599 | def reschedule(_): |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 600 | # Speed up sequential resync a limited number of times if out of sync. |
| 601 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 602 | delay = self.sync_tick |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 603 | |
| 604 | if self._expedite_sync: |
| 605 | self._expedite_count += 1 |
| 606 | if self._expedite_count < 5: |
| 607 | delay = 1 |
| 608 | else: |
| 609 | self._expedite_count = 0 |
| 610 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 611 | delay += random.uniform(-delay / 10, delay / 10) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 612 | self.sync_deferred = reactor.callLater(delay, self.sync_hardware) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 613 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 614 | self.sync_deferred = self._get_pon_config() |
| 615 | self.sync_deferred.addCallbacks(read_config, failure, errbackArgs=['get-config']) |
| 616 | self.sync_deferred.addCallbacks(sync_onus, failure, errbackArgs=['pon-sync']) |
| 617 | self.sync_deferred.addBoth(reschedule) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 618 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 619 | def process_status_poll(self, status): |
| 620 | """ |
| 621 | Process PON status poll request |
| 622 | |
| 623 | :param status: (OltState.Pon object) results from RESTCONF GET |
| 624 | """ |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 625 | self.log.debug('process-status-poll', status=status) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 626 | |
| 627 | if self._admin_state != AdminState.ENABLED: |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 628 | return |
| 629 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 630 | # Process LOS list |
| 631 | self._process_los_alarms(frozenset(status.ont_los)) |
| 632 | |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 633 | # Get new/missing from the discovered ONU leaf. Stale ONUs from previous |
| 634 | # configs are now cleaned up during h/w re-sync/reflow. |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 635 | |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 636 | new, rediscovered_onus = self._process_status_onu_discovered_list(status.discovered_onu) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 637 | |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 638 | # Process newly discovered ONU list and rediscovered ONUs |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 639 | |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 640 | for serial_number in new | rediscovered_onus: |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 641 | reactor.callLater(0, self.add_onu, serial_number, status) |
| 642 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 643 | # PON Statistics |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 644 | timestamp = arrow.utcnow().float_timestamp |
| 645 | self._process_statistics(status, timestamp) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 646 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 647 | # Process ONU info. Note that newly added ONUs will not be processed |
| 648 | # until the next pass |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 649 | self._update_onu_status(status.onus, timestamp) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 650 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 651 | # Process GEM Port information |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 652 | self._update_gem_status(status.gems, timestamp) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 653 | |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 654 | def _process_statistics(self, status, timestamp): |
| 655 | self.timestamp = timestamp |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 656 | self.rx_packets = status.rx_packets |
| 657 | self.rx_bytes = status.rx_bytes |
| 658 | self.tx_packets = status.tx_packets |
| 659 | self.tx_bytes = status.tx_bytes |
| 660 | self.tx_bip_errors = status.tx_bip_errors |
| 661 | |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 662 | def _update_onu_status(self, onus, timestamp): |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 663 | """ |
| 664 | Process ONU status for this PON |
| 665 | :param onus: (dict) onu_id: ONU State |
| 666 | """ |
| 667 | for onu_id, onu_status in onus.iteritems(): |
| 668 | if onu_id in self._onu_by_id: |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 669 | onu = self._onu_by_id[onu_id] |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 670 | onu.timestamp = timestamp |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 671 | onu.rssi = onu_status.rssi |
| 672 | onu.equalization_delay = onu_status.equalization_delay |
| 673 | onu.equalization_delay = onu_status.equalization_delay |
| 674 | onu.fiber_length = onu_status.fiber_length |
Chip Boling | bb15b51 | 2018-06-01 11:39:58 -0500 | [diff] [blame] | 675 | onu.password = onu_status.reported_password |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 676 | |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 677 | def _update_gem_status(self, gems, timestamp): |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 678 | for gem_id, gem_status in gems.iteritems(): |
| 679 | onu = self._onu_by_id.get(gem_status.onu_id) |
| 680 | if onu is not None: |
| 681 | gem_port = onu.gem_port(gem_status.gem_id) |
| 682 | if gem_port is not None: |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 683 | gem_port.timestamp = timestamp |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 684 | gem_port.rx_packets = gem_status.rx_packets |
| 685 | gem_port.rx_bytes = gem_status.rx_bytes |
| 686 | gem_port.tx_packets = gem_status.tx_packets |
| 687 | gem_port.tx_bytes = gem_status.tx_bytes |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 688 | |
| 689 | def _process_los_alarms(self, ont_los): |
| 690 | """ |
| 691 | Walk current LOS and set/clear LOS as appropriate |
| 692 | :param ont_los: (frozenset) ONU IDs of ONUs in LOS alarm state |
| 693 | """ |
| 694 | cleared_alarms = self._active_los_alarms - ont_los |
| 695 | new_alarms = ont_los - self._active_los_alarms |
| 696 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 697 | if len(cleared_alarms) > 0 or len(new_alarms) > 0: |
| 698 | self.log.info('onu-los', cleared=cleared_alarms, new=new_alarms) |
| 699 | |
| 700 | for onu_id in cleared_alarms: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 701 | self._active_los_alarms.remove(onu_id) |
Chip Boling | bffef5e | 2018-08-07 14:53:12 -0500 | [diff] [blame] | 702 | OnuLosAlarm(self.olt.alarms, onu_id).clear_alarm() |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 703 | |
| 704 | for onu_id in new_alarms: |
| 705 | self._active_los_alarms.add(onu_id) |
Chip Boling | bffef5e | 2018-08-07 14:53:12 -0500 | [diff] [blame] | 706 | OnuLosAlarm(self.olt.alarms, onu_id).raise_alarm() |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 707 | self.delete_onu(onu_id) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 708 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 709 | def _process_status_onu_discovered_list(self, discovered_onus): |
| 710 | """ |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 711 | Look for new ONUs |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 712 | |
| 713 | :param discovered_onus: (frozenset) Set of ONUs currently discovered |
| 714 | """ |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 715 | self.log.debug('discovered-ONUs', list=discovered_onus) |
| 716 | |
| 717 | # Only request discovery if activation is auto-discovery or auto-activate |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 718 | continue_discovery = ['autodiscovery', 'autoactivate'] |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 719 | |
| 720 | if self._activation_method not in continue_discovery: |
| 721 | return set(), set() |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 722 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 723 | my_onus = frozenset(self._onus.keys()) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 724 | |
| 725 | new_onus = discovered_onus - my_onus |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 726 | rediscovered_onus = my_onus & discovered_onus |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 727 | |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 728 | return new_onus, rediscovered_onus |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 729 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 730 | def _get_onu_info(self, serial_number): |
| 731 | """ |
| 732 | Parse through available xPON information for ONU configuration settings |
| 733 | :param serial_number: (string) Decoded (not base64) serial number string |
| 734 | :return: (dict) onu config data or None on lookup failure |
| 735 | """ |
| 736 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 737 | if self.activation_method == "autodiscovery": |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 738 | # if self.authentication_method == 'serial-number': |
| 739 | raise NotImplemented('TODO: Not supported at this time') |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 740 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 741 | elif self.activation_method == "autoactivate": |
| 742 | # TODO: Currently a somewhat copy of the xPON way to do things |
| 743 | # update here with Technology profile info when it becomes available |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 744 | activate_onu, tconts, gem_ports = self.get_device_profile_info(serial_number) |
| 745 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 746 | try: |
| 747 | # TODO: (SEBA) All of this can be greatly simplified once we fully |
| 748 | # deprecate xPON support |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 749 | vont_ani = next(info for _, info in self._v_ont_anis.items() |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 750 | if info.get('expected-serial-number') == serial_number) |
| 751 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 752 | onu_id = vont_ani['onu-id'] |
| 753 | enabled = vont_ani['enabled'] |
| 754 | channel_speed = vont_ani['upstream-channel-speed'] |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 755 | upstream_fec_enabled = self._ont_anis[vont_ani['name']]['upstream-fec'] |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 756 | |
| 757 | except StopIteration: |
| 758 | # Can happen if vont-ani or ont-ani has not yet been configured |
| 759 | self.log.error('no-vont-or-ont-autoactivate') |
| 760 | return None, False |
| 761 | |
| 762 | except Exception as e: |
| 763 | self.log.exception('autoactivate', e=e) |
| 764 | raise |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 765 | else: |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 766 | self.log.debug('unsupported-activation-method', method=self.activation_method) |
| 767 | return None, False |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 768 | |
| 769 | onu_info = { |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 770 | 'device-id': self.olt.device_id, |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 771 | 'serial-number': serial_number, |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 772 | 'pon': self, |
| 773 | 'onu-id': onu_id, |
| 774 | 'enabled': enabled, |
| 775 | 'upstream-channel-speed': channel_speed, |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 776 | 'upstream-fec': upstream_fec_enabled, |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 777 | 'password': Onu.DEFAULT_PASSWORD, |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 778 | 't-conts': tconts, |
| 779 | 'gem-ports': gem_ports, |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 780 | } |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 781 | intf_id = platform.intf_id_to_port_no(self._pon_id, Port.PON_OLT) |
| 782 | |
| 783 | # TODO: Currently only one ONU port and it is hardcoded to port 0 |
| 784 | onu_info['uni-ports'] = [platform.mk_uni_port_num(intf_id, onu_id)] |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 785 | |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 786 | # Hold off ONU activation until at least one GEM Port is defined. |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 787 | self.log.debug('onu-info-tech-profiles', gem_ports=gem_ports) |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 788 | |
Chip Boling | 3971d24 | 2018-06-06 10:26:34 -0500 | [diff] [blame] | 789 | # return onu_info |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 790 | return onu_info, activate_onu |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 791 | |
| 792 | except Exception as e: |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 793 | self.log.exception('get-onu-info-tech-profiles', e=e) |
| 794 | return None, False |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 795 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 796 | @inlineCallbacks |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 797 | def add_onu(self, serial_number_64, status): |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 798 | """ |
| 799 | Add an ONU to the PON |
| 800 | |
| 801 | TODO: This needs major refactoring after xPON is deprecated to be more maintainable |
| 802 | """ |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 803 | serial_number = Onu.serial_number_to_string(serial_number_64) |
| 804 | self.log.info('add-onu', serial_number=serial_number, |
| 805 | serial_number_64=serial_number_64, status=status) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 806 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 807 | # It takes a little while for a new ONU to be removed from the discovery |
| 808 | # list. Return early here so extra ONU IDs are not allocated |
| 809 | if serial_number_64 in self._onus: |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 810 | returnValue('wait-for-fpga') |
| 811 | |
| 812 | onu_info, activate_onu = self._get_onu_info(serial_number) |
| 813 | |
| 814 | if activate_onu: |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 815 | alarm = OnuDiscoveryAlarm(self.olt.alarms, self.pon_id, serial_number) |
| 816 | reactor.callLater(0, alarm.raise_alarm) |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 817 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 818 | if serial_number_64 not in status.onus or onu_info['onu-id'] in self._active_los_alarms: |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 819 | onu = None |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 820 | onu_id = onu_info['onu-id'] |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 821 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 822 | if serial_number_64 in self._onus and onu_id in self._onu_by_id: |
| 823 | # Handles fast entry into this task before FPGA can set/clear results |
| 824 | returnValue('sticky-onu') |
| 825 | |
| 826 | elif (serial_number_64 in self._onus and onu_id not in self._onu_by_id) or \ |
| 827 | (serial_number_64 not in self._onus and onu_id in self._onu_by_id): |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 828 | # May be here due to unmanaged power-cycle on OLT or fiber bounced for a |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 829 | # previously activated ONU. |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 830 | # |
| 831 | # TODO: Track when the ONU was discovered, and if > some maximum amount |
| 832 | # place the ONU (with serial number & ONU ID) on a wait list and |
| 833 | # use that to recover the ONU ID should it show up within a |
| 834 | # reasonable amount of time. Periodically groom the wait list and |
| 835 | # delete state ONUs so we can reclaim the ONU ID. |
| 836 | # |
| 837 | returnValue('waiting-for-fpga') # non-XPON mode will not |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 838 | |
| 839 | elif len(self._onus) >= self.MAX_ONUS_SUPPORTED: |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 840 | self.log.warning('max-onus-provisioned', count=len(self._onus)) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 841 | returnValue('max-onus-reached') |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 842 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 843 | else: |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 844 | # TODO: Make use of upstream_channel_speed variable |
| 845 | onu = Onu(onu_info) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 846 | self._onus[serial_number_64] = onu |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 847 | self._onu_by_id[onu.onu_id] = onu |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 848 | |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 849 | if onu is not None: |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 850 | tconts = onu_info.pop('t-conts') |
| 851 | gem_ports = onu_info.pop('gem-ports') |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 852 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 853 | if activate_onu: |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 854 | _onu_device = self._parent.add_onu_device(self._port_no, # PON ID |
| 855 | onu.onu_id, # ONU ID |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 856 | serial_number, |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 857 | tconts, |
| 858 | gem_ports) |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 859 | try: |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 860 | # Add Multicast to PON on a per-ONU basis until xPON multicast support |
| 861 | # is ready |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 862 | # In xPON/BBF, mcast gems tie back to the channel-pair |
| 863 | # MCAST VLAN IDs stored as a negative value |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 864 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 865 | # for id_or_vid, gem_port in gem_ports.iteritems(): # TODO: Deprecate this when BBF ready |
| 866 | # try: |
| 867 | # if gem_port.multicast: |
| 868 | # self.log.debug('id-or-vid', id_or_vid=id_or_vid) |
| 869 | # vid = self.olt.multicast_vlans[0] if len(self.olt.multicast_vlans) else None |
| 870 | # if vid is not None: |
| 871 | # self.add_mcast_gem_port(gem_port, vid) |
| 872 | # |
| 873 | # except Exception as e: |
| 874 | # self.log.exception('id-or-vid', e=e) |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 875 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 876 | # TODO: Need to clean up TCont and GEM-Port on ONU delete in non-xPON mode |
| 877 | _results = yield onu.create(tconts, gem_ports) |
Chip Boling | ef0e2fa | 2017-10-06 14:33:01 -0500 | [diff] [blame] | 878 | |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 879 | except Exception as e: |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 880 | self.log.exception('add-onu', serial_number=serial_number_64, e=e) |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 881 | # allowable exception. H/w re-sync will recover any issues |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 882 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 883 | @property |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 884 | def get_next_onu_id(self): |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 885 | return self._parent.resource_mgr.get_onu_id(self._pon_id) |
| 886 | # return self._onu_id_pool.get_next() |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 887 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 888 | def release_onu_id(self, onu_id): |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 889 | self._parent.resource_mgr.free_onu_id(self._pon_id, onu_id) |
| 890 | # self._onu_id_pool.release(onu_id) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 891 | |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 892 | @inlineCallbacks |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 893 | def _remove_from_hardware(self, onu_id): |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 894 | uri = AdtranOltHandler.GPON_ONU_CONFIG_URI.format(self._pon_id, onu_id) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 895 | name = 'pon-delete-onu-{}-{}'.format(self._pon_id, onu_id) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 896 | |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 897 | try: |
| 898 | yield self._parent.rest_client.request('DELETE', uri, name=name) |
| 899 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 900 | except RestInvalidResponseCode as e: |
| 901 | if e.code != 404: |
| 902 | self.log.exception('onu-delete', e=e) |
| 903 | |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 904 | except Exception as e: |
| 905 | self.log.exception('onu-hw-delete', onu_id=onu_id, e=e) |
| 906 | |
| 907 | @inlineCallbacks |
| 908 | def delete_onu(self, onu_id): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 909 | onu = self._onu_by_id.get(onu_id) |
| 910 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 911 | # Remove from any local dictionary |
| 912 | if onu_id in self._onu_by_id: |
| 913 | del self._onu_by_id[onu_id] |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 914 | self.release_onu_id(onu.onu_id) |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 915 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 916 | for sn_64 in [onu.serial_number_64 for onu in self.onus if onu.onu_id == onu_id]: |
| 917 | del self._onus[sn_64] |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 918 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 919 | if onu is not None: |
Chip Boling | ef0e2fa | 2017-10-06 14:33:01 -0500 | [diff] [blame] | 920 | proxy = onu.proxy_address |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 921 | try: |
| 922 | onu.delete() |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 923 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 924 | except Exception as e: |
| 925 | self.log.exception('onu-delete', serial_number=onu.serial_number, e=e) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 926 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 927 | else: |
| 928 | try: |
| 929 | yield self._remove_from_hardware(onu_id) |
| 930 | |
| 931 | except Exception as e: |
| 932 | self.log.exception('onu-remove', serial_number=onu.serial_number, e=e) |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 933 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 934 | def add_mcast_gem_port(self, mcast_gem, vlan): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 935 | """ |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 936 | Add any new Multicast GEM Ports to the PON |
| 937 | :param mcast_gem: (GemPort) |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 938 | """ |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 939 | if vlan in self._mcast_gem_ports: |
| 940 | return |
| 941 | |
| 942 | assert len(self._mcast_gem_ports) == 0, 'Only 1 MCAST GEMPort until BBF Support' |
| 943 | assert 1 <= vlan <= 4095, 'Invalid Multicast VLAN ID' |
| 944 | assert len(self.olt.multicast_vlans) == 1, 'Only support 1 MCAST VLAN until BBF Support' |
| 945 | |
| 946 | self._mcast_gem_ports[vlan] = mcast_gem |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame^] | 947 | |
| 948 | # =========================================================================== |
| 949 | # |
| 950 | # Some xPON methods that need refactoring |
| 951 | |
| 952 | @property |
| 953 | def tconts(self): |
| 954 | return self._tconts |
| 955 | |
| 956 | @property |
| 957 | def traffic_descriptors(self): |
| 958 | return self._traffic_descriptors |
| 959 | |
| 960 | @property |
| 961 | def gem_ports(self): |
| 962 | return self._gem_ports |
| 963 | |
| 964 | def get_device_profile_info(self, serial_number): |
| 965 | vont_ani_info = next((info for _, info in self._v_ont_anis.items() |
| 966 | if info.get('expected-serial-number') == serial_number), None) |
| 967 | # New ONU? |
| 968 | activate_onu = vont_ani_info is None |
| 969 | |
| 970 | tconts = list() |
| 971 | gem_ports = list() |
| 972 | |
| 973 | if activate_onu: |
| 974 | onu_id = self.get_next_onu_id |
| 975 | name = 'customer-{}-{}'.format(self.pon_id, onu_id) |
| 976 | vont_ani_info = { |
| 977 | 'name' : name, |
| 978 | 'enabled' : True, |
| 979 | 'description' : '', |
| 980 | 'pon-id' : self.pon_id, |
| 981 | 'onu-id' : onu_id, |
| 982 | 'expected-serial-number' : serial_number, |
| 983 | 'expected-registration-id': '', # TODO: How about this? |
| 984 | 'upstream-channel-speed' : 10000000000, |
| 985 | } |
| 986 | ont_ani_info = { |
| 987 | 'name': name, |
| 988 | 'description': '', |
| 989 | 'enabled': True, |
| 990 | 'upstream-fec': True, |
| 991 | 'mgnt-gemport-aes': False |
| 992 | } |
| 993 | assert name not in self._v_ont_anis |
| 994 | assert name not in self._ont_anis |
| 995 | self._v_ont_anis[name] = vont_ani_info |
| 996 | self._ont_anis[name] = ont_ani_info |
| 997 | |
| 998 | tcont, tc, td = self.create_xpon_tcont(onu_id) |
| 999 | from xpon.olt_tcont import OltTCont |
| 1000 | tc['object'] = OltTCont.create(tc, |
| 1001 | OltTrafficDescriptor.create(tc['td-ref']), |
| 1002 | self.pon_id, onu_id) |
| 1003 | self._tconts[tcont.name] = tc['object'] |
| 1004 | tconts.append(tc) |
| 1005 | |
| 1006 | # Now create the User-Data GEM-Ports |
| 1007 | num_priorities = 1 # TODO: Pull from tech-profile later |
| 1008 | for index in range(0, num_priorities): |
| 1009 | gem_port, gp = self.create_xpon_gem_port(onu_id, index, tcont) |
| 1010 | |
| 1011 | from xpon.olt_gem_port import OltGemPort |
| 1012 | gp['object'] = OltGemPort.create(self, gp, self.pon_id, onu_id) |
| 1013 | self._gem_ports[gem_port.name] = gp['object'] |
| 1014 | gem_ports.append(gp) |
| 1015 | |
| 1016 | return activate_onu, tconts, gem_ports |
| 1017 | |
| 1018 | def create_xpon_gem_port(self, onu_id, index, tcont): |
| 1019 | # gem port creation (this initial one is for untagged ONU data support / EAPOL) |
| 1020 | gem_port = GemportsConfigData() |
| 1021 | gem_port.gemport_id = platform.mk_gemport_id(self.pon_id, onu_id, idx=index) |
| 1022 | gem_port.name = 'gem-{}-{}-{}'.format(self.pon_id, onu_id, gem_port.gemport_id) |
| 1023 | |
| 1024 | gem_port.tcont_ref = tcont.name |
| 1025 | gp = { |
| 1026 | 'name': gem_port.name, |
| 1027 | 'gemport-id': gem_port.gemport_id, |
| 1028 | 'tcont-ref': gem_port.tcont_ref, |
| 1029 | 'encryption': False, |
| 1030 | 'traffic-class': 0, |
| 1031 | 'data': gem_port |
| 1032 | } |
| 1033 | return gem_port, gp |
| 1034 | |
| 1035 | def create_xpon_tcont(self, onu_id): |
| 1036 | """ Create the xPON TCONT Config data """ |
| 1037 | tcont = TcontsConfigData() |
| 1038 | tcont.name = 'tcont-{}-{}-data'.format(self.pon_id, onu_id) |
| 1039 | pon_intf_onu_id = (self.pon_id, onu_id) |
| 1040 | tcont.alloc_id = self._parent.resource_mgr.get_alloc_id(pon_intf_onu_id) |
| 1041 | # TODO: Add release of alloc_id on ONU delete and/or TCONT delete |
| 1042 | |
| 1043 | traffic_desc = TrafficDescriptorProfileData(name='BestEffort', |
| 1044 | fixed_bandwidth=0, |
| 1045 | assured_bandwidth=0, |
| 1046 | maximum_bandwidth=10000000000, |
| 1047 | priority=0, |
| 1048 | weight=0, |
| 1049 | additional_bw_eligibility_indicator=0) |
| 1050 | tc = { |
| 1051 | 'name': tcont.name, |
| 1052 | 'alloc-id': tcont.alloc_id, |
| 1053 | 'pon-id': self.pon_id, |
| 1054 | 'onu-id': onu_id, |
| 1055 | 'td-ref': { # TODO: This should be the TD Name and the TD installed in xpon cache |
| 1056 | 'name': traffic_desc.name, |
| 1057 | 'fixed-bandwidth': traffic_desc.fixed_bandwidth, |
| 1058 | 'assured-bandwidth': traffic_desc.assured_bandwidth, |
| 1059 | 'maximum-bandwidth': traffic_desc.maximum_bandwidth, |
| 1060 | 'priority': traffic_desc.priority, |
| 1061 | 'weight': traffic_desc.weight, |
| 1062 | 'additional-bw-eligibility-indicator': 0, |
| 1063 | 'data': traffic_desc |
| 1064 | }, |
| 1065 | 'data': tcont |
| 1066 | } |
| 1067 | return tcont, tc, traffic_desc |