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 | 99c388e | 2018-11-20 09:33:57 -0600 | [diff] [blame] | 28 | from voltha.extensions.alarms.onu.onu_discovery_alarm import OnuDiscoveryAlarm |
Chip Boling | bb15b51 | 2018-06-01 11:39:58 -0500 | [diff] [blame] | 29 | from voltha.protos.common_pb2 import AdminState |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 30 | from voltha.protos.device_pb2 import Port |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 31 | from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData |
| 32 | from voltha.protos.bbf_fiber_traffic_descriptor_profile_body_pb2 import TrafficDescriptorProfileData |
| 33 | from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData |
| 34 | from xpon.olt_traffic_descriptor import OltTrafficDescriptor |
| 35 | import resources.adtranolt_platform as platform |
| 36 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 37 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 38 | class PonPort(AdtnPort): |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 39 | """ |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 40 | GPON Port |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 41 | """ |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 42 | MAX_ONUS_SUPPORTED = 128 |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 43 | MAX_DEPLOYMENT_RANGE = 25000 # Meters (OLT-PB maximum) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 44 | |
| 45 | _MCAST_ONU_ID = 253 |
| 46 | _MCAST_ALLOC_BASE = 0x500 |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 47 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 48 | # AutoActivate should be used if xPON configuration is not supported |
| 49 | _SUPPORTED_ACTIVATION_METHODS = ['autodiscovery', 'autoactivate'] |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 50 | _SUPPORTED_AUTHENTICATION_METHODS = ['serial-number'] |
| 51 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 52 | def __init__(self, parent, **kwargs): |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 53 | super(PonPort, self).__init__(parent, **kwargs) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 54 | assert 'pon-id' in kwargs, 'PON ID not found' |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 55 | |
| 56 | self._parent = parent |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 57 | self._pon_id = kwargs['pon-id'] |
| 58 | self.log = structlog.get_logger(device_id=parent.device_id, pon_id=self._pon_id) |
| 59 | self._port_no = kwargs['port_no'] |
Chip Boling | 3eedf46 | 2018-10-17 12:18:28 -0500 | [diff] [blame] | 60 | self._physical_port_name = 'xpon 0/{}'.format(self._pon_id+1) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 61 | self._label = 'pon-{}'.format(self._pon_id) |
| 62 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 63 | self._in_sync = False |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 64 | self._expedite_sync = False |
| 65 | self._expedite_count = 0 |
| 66 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 67 | self._discovery_tick = 20.0 |
| 68 | self._no_onu_discover_tick = self._discovery_tick / 2 |
| 69 | self._discovered_onus = [] # List of serial numbers |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 70 | self._discovery_deferred = None # Specifically for ONU discovery |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 71 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 72 | self._onus = {} # serial_number-base64 -> ONU |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 73 | self._onu_by_id = {} # onu-id -> ONU |
| 74 | self._mcast_gem_ports = {} # VLAN -> GemPort |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 75 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 76 | self._active_los_alarms = set() # ONU-ID |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 77 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 78 | # xPON configuration |
| 79 | self._activation_method = 'autoactivate' |
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._downstream_fec_enable = True |
| 82 | self._upstream_fec_enable = True |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 83 | self._deployment_range = 25000 |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 84 | self._authentication_method = 'serial-number' |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 85 | self._mcast_aes = False |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 86 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 87 | # Statistics |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 88 | self.tx_bip_errors = 0 |
| 89 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 90 | def __str__(self): |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 91 | return "PonPort-{}: Admin: {}, Oper: {}, OLT: {}".format(self._label, |
| 92 | self._admin_state, |
| 93 | self._oper_status, |
| 94 | self.olt) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 95 | |
| 96 | def get_port(self): |
| 97 | """ |
| 98 | Get the VOLTHA PORT object for this port |
| 99 | :return: VOLTHA Port object |
| 100 | """ |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 101 | if self._port is None: |
| 102 | self._port = Port(port_no=self._port_no, |
| 103 | label=self._label, |
| 104 | type=Port.PON_OLT, |
Chip Boling | c64c8dc | 2018-04-20 14:42:24 -0500 | [diff] [blame] | 105 | admin_state=self._admin_state, |
| 106 | oper_status=self._oper_status) |
| 107 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 108 | return self._port |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 109 | |
| 110 | @property |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 111 | def pon_id(self): |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 112 | return self._pon_id |
| 113 | |
| 114 | @property |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 115 | def onus(self): |
| 116 | """ |
| 117 | Get a set of all ONUs. While the set is immutable, do not use this method |
| 118 | to get a collection that you will iterate through that my yield the CPU |
| 119 | such as inline callback. ONUs may be deleted at any time and they will |
| 120 | set some references to other objects to NULL during the 'delete' call. |
| 121 | Instead, get a list of ONU-IDs and iterate on these and call the 'onu' |
| 122 | method below (which will return 'None' if the ONU has been deleted. |
| 123 | |
| 124 | :return: (frozenset) collection of ONU objects on this PON |
| 125 | """ |
| 126 | return frozenset(self._onus.values()) |
| 127 | |
| 128 | @property |
| 129 | def onu_ids(self): |
| 130 | return frozenset(self._onu_by_id.keys()) |
| 131 | |
Chip Boling | ef0e2fa | 2017-10-06 14:33:01 -0500 | [diff] [blame] | 132 | def onu(self, onu_id): |
| 133 | return self._onu_by_id.get(onu_id) |
| 134 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 135 | @property |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 136 | def in_service_onus(self): |
| 137 | return len({onu.onu_id for onu in self.onus |
| 138 | if onu.onu_id not in self._active_los_alarms}) |
| 139 | |
| 140 | @property |
| 141 | def closest_onu_distance(self): |
| 142 | distance = -1 |
| 143 | for onu in self.onus: |
| 144 | if onu.fiber_length < distance or distance == -1: |
| 145 | distance = onu.fiber_length |
| 146 | return distance |
| 147 | |
| 148 | @property |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 149 | def downstream_fec_enable(self): |
| 150 | return self._downstream_fec_enable |
| 151 | |
| 152 | @downstream_fec_enable.setter |
| 153 | def downstream_fec_enable(self, value): |
| 154 | assert isinstance(value, bool), 'downstream FEC enabled is a boolean' |
| 155 | |
| 156 | if self._downstream_fec_enable != value: |
| 157 | self._downstream_fec_enable = value |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 158 | if self.state == AdtnPort.State.RUNNING: |
| 159 | self.deferred = self._set_pon_config("downstream-fec-enable", value) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 160 | |
| 161 | @property |
| 162 | def upstream_fec_enable(self): |
| 163 | return self._upstream_fec_enable |
| 164 | |
| 165 | @upstream_fec_enable.setter |
| 166 | def upstream_fec_enable(self, value): |
| 167 | assert isinstance(value, bool), 'upstream FEC enabled is a boolean' |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 168 | if self._upstream_fec_enable != value: |
| 169 | self._upstream_fec_enable = value |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 170 | if self.state == AdtnPort.State.RUNNING: |
| 171 | self.deferred = self._set_pon_config("upstream-fec-enable", value) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 172 | |
| 173 | @property |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 174 | def any_upstream_fec_enabled(self): |
| 175 | for onu in self.onus: |
| 176 | if onu.upstream_fec_enable and onu.enabled: |
| 177 | return True |
| 178 | return False |
| 179 | |
| 180 | @property |
| 181 | def mcast_aes(self): |
| 182 | return self._mcast_aes |
| 183 | |
| 184 | @mcast_aes.setter |
| 185 | def mcast_aes(self, value): |
| 186 | assert isinstance(value, bool), 'MCAST AES is a boolean' |
| 187 | if self._mcast_aes != value: |
| 188 | self._mcast_aes = value |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 189 | if self.state == AdtnPort.State.RUNNING: |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 190 | pass # TODO |
| 191 | |
| 192 | @property |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 193 | def deployment_range(self): |
| 194 | """Maximum deployment range (in meters)""" |
| 195 | return self._deployment_range |
| 196 | |
| 197 | @deployment_range.setter |
| 198 | def deployment_range(self, value): |
| 199 | """Maximum deployment range (in meters)""" |
| 200 | if not 0 <= value <= PonPort.MAX_DEPLOYMENT_RANGE: |
| 201 | raise ValueError('Deployment range should be 0..{} meters'. |
| 202 | format(PonPort.MAX_DEPLOYMENT_RANGE)) |
| 203 | if self._deployment_range != value: |
| 204 | self._deployment_range = value |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 205 | if self.state == AdtnPort.State.RUNNING: |
| 206 | self.deferred = self._set_pon_config("deployment-range", value) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 207 | |
| 208 | @property |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 209 | def discovery_tick(self): |
| 210 | return self._discovery_tick * 10 |
| 211 | |
| 212 | @discovery_tick.setter |
| 213 | def discovery_tick(self, value): |
| 214 | if value < 0: |
| 215 | raise ValueError("Polling interval must be >= 0") |
| 216 | |
| 217 | if self.discovery_tick != value: |
| 218 | self._discovery_tick = value / 10 |
| 219 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 220 | try: |
| 221 | if self._discovery_deferred is not None and \ |
| 222 | not self._discovery_deferred.called: |
| 223 | self._discovery_deferred.cancel() |
| 224 | except: |
| 225 | pass |
| 226 | self._discovery_deferred = None |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 227 | |
| 228 | if self._discovery_tick > 0: |
| 229 | self._discovery_deferred = reactor.callLater(self._discovery_tick, |
| 230 | self._discover_onus) |
| 231 | |
| 232 | @property |
| 233 | def activation_method(self): |
| 234 | return self._activation_method |
| 235 | |
| 236 | @activation_method.setter |
| 237 | def activation_method(self, value): |
| 238 | value = value.lower() |
| 239 | if value not in PonPort._SUPPORTED_ACTIVATION_METHODS: |
| 240 | raise ValueError('Invalid ONU activation method') |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 241 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 242 | self._activation_method = value |
| 243 | |
| 244 | @property |
| 245 | def authentication_method(self): |
| 246 | return self._authentication_method |
| 247 | |
| 248 | @authentication_method.setter |
| 249 | def authentication_method(self, value): |
| 250 | value = value.lower() |
| 251 | if value not in PonPort._SUPPORTED_AUTHENTICATION_METHODS: |
| 252 | raise ValueError('Invalid ONU authentication method') |
| 253 | self._authentication_method = value |
| 254 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 255 | def cancel_deferred(self): |
| 256 | super(PonPort, self).cancel_deferred() |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 257 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 258 | d, self._discovery_deferred = self._discovery_deferred, None |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 259 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 260 | try: |
| 261 | if d is not None and not d.called: |
| 262 | d.cancel() |
| 263 | except Exception as e: |
| 264 | pass |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 265 | |
| 266 | def _update_adapter_agent(self): |
Chip Boling | c64c8dc | 2018-04-20 14:42:24 -0500 | [diff] [blame] | 267 | """ |
| 268 | Update the port status and state in the core |
| 269 | """ |
| 270 | self.log.debug('update-adapter-agent', admin_state=self._admin_state, |
Chip Boling | 3971d24 | 2018-06-06 10:26:34 -0500 | [diff] [blame] | 271 | oper_status=self._oper_status) |
Chip Boling | c64c8dc | 2018-04-20 14:42:24 -0500 | [diff] [blame] | 272 | |
| 273 | # because the core does not provide methods for updating admin |
| 274 | # and oper status per port, we need to copy any existing port |
| 275 | # info so that we don't wipe out the peers |
| 276 | if self._port is not None: |
| 277 | agent_ports = self.adapter_agent.get_ports(self.olt.device_id, Port.PON_OLT) |
| 278 | |
| 279 | agent_port = next((ap for ap in agent_ports if ap.port_no == self._port_no), None) |
| 280 | |
| 281 | # copy current Port info |
| 282 | if agent_port is not None: |
Chip Boling | 3971d24 | 2018-06-06 10:26:34 -0500 | [diff] [blame] | 283 | self._port = agent_port |
Chip Boling | c64c8dc | 2018-04-20 14:42:24 -0500 | [diff] [blame] | 284 | |
| 285 | # set new states |
| 286 | self._port.admin_state = self._admin_state |
| 287 | self._port.oper_status = self._oper_status |
| 288 | |
| 289 | # adapter_agent add_port also does an update of existing port |
| 290 | self.adapter_agent.add_port(self.olt.device_id, self.get_port()) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 291 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 292 | @inlineCallbacks |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 293 | def finish_startup(self): |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 294 | """ |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 295 | Do all startup offline since REST may fail |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 296 | """ |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 297 | if self.state != AdtnPort.State.INITIAL: |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 298 | returnValue('Done') |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 299 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 300 | self.log.debug('final-startup') |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 301 | results = None |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 302 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 303 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 304 | self.deferred = self._get_pon_config() |
| 305 | results = yield self.deferred |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 306 | |
| 307 | except Exception as e: |
| 308 | self.log.exception('initial-GET', e=e) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 309 | self.deferred = reactor.callLater(5, self.finish_startup) |
| 310 | returnValue(self.deferred) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 311 | |
| 312 | # Load config from hardware |
| 313 | |
| 314 | enabled = results.get('enabled', False) |
| 315 | downstream_fec_enable = results.get('downstream-fec-enable', False) |
| 316 | upstream_fec_enable = results.get('upstream-fec-enable', False) |
| 317 | deployment_range = results.get('deployment-range', 25000) |
| 318 | self._in_sync = True |
| 319 | |
| 320 | if enabled != self._enabled: |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 321 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 322 | self.deferred = self._set_pon_config("enabled", True) |
| 323 | yield self.deferred |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 324 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 325 | except Exception as e: |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 326 | self.log.exception('final-startup-enable', e=e) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 327 | self.deferred = reactor.callLater(3, self.finish_startup) |
| 328 | returnValue(self.deferred) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 329 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 330 | if downstream_fec_enable != self._downstream_fec_enable: |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 331 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 332 | self.deferred = self._set_pon_config("downstream-fec-enable", |
| 333 | self._downstream_fec_enable) |
| 334 | yield self.deferred |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 335 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 336 | except Exception as e: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 337 | self.log.warning('final-startup-downstream-FEC', e=e) |
| 338 | self._in_sync = False |
| 339 | # Non-fatal. May have failed due to no SFQ in slot |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 340 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 341 | if upstream_fec_enable != self._upstream_fec_enable: |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 342 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 343 | self.deferred = self._set_pon_config("upstream-fec-enable", |
| 344 | self._upstream_fec_enable) |
| 345 | yield self.deferred |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 346 | |
| 347 | except Exception as e: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 348 | self.log.warning('final-startup-upstream-FEC', e=e) |
| 349 | self._in_sync = False |
| 350 | # Non-fatal. May have failed due to no SFQ in slot |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 351 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 352 | if deployment_range != self._deployment_range: |
| 353 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 354 | self.deferred = self._set_pon_config("deployment-range", |
| 355 | self._deployment_range) |
| 356 | yield self.deferred |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 357 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 358 | except Exception as e: |
| 359 | self.log.warning('final-startup-deployment-range', e=e) |
| 360 | self._in_sync = False |
| 361 | # Non-fatal. May have failed due to no SFQ in slot |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 362 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 363 | if len(self._onus) > 0: |
| 364 | dl = [] |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 365 | for onu_id in self.onu_ids: |
| 366 | onu = self.onu(onu_id) |
| 367 | if onu is not None: |
| 368 | dl.append(onu.restart()) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 369 | yield defer.gatherResults(dl, consumeErrors=True) |
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 | # Begin to ONU discovery and hardware sync |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 372 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 373 | self._discovery_deferred = reactor.callLater(5, self._discover_onus) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 374 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 375 | # If here, initial settings were successfully written to hardware |
| 376 | |
| 377 | super(PonPort, self).finish_startup() |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 378 | returnValue('Enabled') |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 379 | |
Chip Boling | 9fef0fd | 2018-12-11 09:43:59 -0600 | [diff] [blame] | 380 | @inlineCallbacks |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 381 | def finish_stop(self): |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 382 | # Remove all existing ONUs. They will need to be re-discovered |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 383 | dl = [] |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 384 | onu_ids = frozenset(self._onu_by_id.keys()) |
| 385 | for onu_id in onu_ids: |
| 386 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 387 | dl.append(self.delete_onu(onu_id)) |
| 388 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 389 | except Exception as e: |
| 390 | self.log.exception('onu-cleanup', onu_id=onu_id, e=e) |
| 391 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 392 | dl.append(self._set_pon_config("enabled", False)) |
Chip Boling | 9fef0fd | 2018-12-11 09:43:59 -0600 | [diff] [blame] | 393 | results = yield defer.gatherResults(dl, consumeErrors=True) |
| 394 | returnValue(results) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 395 | |
| 396 | @inlineCallbacks |
| 397 | def reset(self): |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 398 | """ |
| 399 | Set the PON Port to a known good state on initial port startup. Actual |
| 400 | PON 'Start' is done elsewhere |
| 401 | """ |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 402 | initial_port_state = AdminState.ENABLED |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 403 | self.log.info('reset', initial_state=initial_port_state) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 404 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 405 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 406 | self.deferred = self._get_pon_config() |
| 407 | results = yield self.deferred |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 408 | enabled = results.get('enabled', False) |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 409 | |
| 410 | except Exception as e: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 411 | self.log.exception('get-config', e=e) |
| 412 | enabled = False |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 413 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 414 | enable = initial_port_state == AdminState.ENABLED |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 415 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 416 | if enable != enabled: |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 417 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 418 | self.deferred = yield self._set_pon_config("enabled", enable) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 419 | except Exception as e: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 420 | self.log.exception('reset-enabled', e=e, enabled=enabled) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 421 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 422 | # TODO: Move to 'set_pon_config' method and also make sure GRPC/Port is ok |
| 423 | self._admin_state = AdminState.ENABLED if enable else AdminState.DISABLED |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 424 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 425 | try: |
Chip Boling | 99c388e | 2018-11-20 09:33:57 -0600 | [diff] [blame] | 426 | # Walk the provisioned ONU list and disable any existing ONUs |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 427 | results = yield self._get_onu_config() |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 428 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 429 | if isinstance(results, list) and len(results) > 0: |
| 430 | onu_configs = OltConfig.Pon.Onu.decode(results) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 431 | dl = [] |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 432 | for onu_id in onu_configs.iterkeys(): |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 433 | dl.append(self.delete_onu(onu_id)) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 434 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 435 | try: |
| 436 | if len(dl) > 0: |
| 437 | yield defer.gatherResults(dl, consumeErrors=True) |
| 438 | |
| 439 | except Exception as e: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 440 | self.log.exception('rest-ONU-delete', e=e) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 441 | pass # Non-fatal |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 442 | |
| 443 | except Exception as e: |
| 444 | self.log.exception('onu-delete', e=e) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 445 | |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 446 | returnValue('Reset complete') |
| 447 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 448 | def gem_ids(self, logical_port, flow_vlan, multicast_gems=False): |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 449 | """ |
| 450 | Get all GEM Port IDs used on a given PON |
| 451 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 452 | :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] | 453 | on PON, if Multicast, VID for Multicast, or None for all |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 454 | Multicast GEMPorts |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 455 | :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] | 456 | :param multicast_gems: (boolean) Select from available Multicast GEM Ports |
| 457 | :return: (dict) data_gem -> key -> onu-id, value -> tuple(sorted list of GEM Port IDs, onu_vid) |
| 458 | mcast_gem-> key -> mcast-vid, value -> GEM Port IDs |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 459 | """ |
| 460 | gem_ids = {} |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 461 | |
| 462 | if multicast_gems: |
| 463 | # 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] | 464 | # all ONUs. TODO: Rework when BBF MCAST is addressed in VOLTHA v2.O+ |
| 465 | for vlan, gem_port in self._mcast_gem_ports.iteritems(): |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 466 | 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] | 467 | gem_ids[vlan] = ([gem_port.gem_id], None) |
| 468 | else: |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 469 | raise NotImplemented('TODO: This is deprecated') |
| 470 | # for onu_id, onu in self._onu_by_id.iteritems(): |
| 471 | # if logical_port is None or logical_port == onu.logical_port: |
| 472 | # gem_ids[onu_id] = (onu.gem_ids(), flow_vlan) |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 473 | return gem_ids |
| 474 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 475 | def _get_pon_config(self): |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 476 | uri = AdtranOltHandler.GPON_PON_CONFIG_URI.format(self._pon_id) |
| 477 | name = 'pon-get-config-{}'.format(self._pon_id) |
| 478 | return self._parent.rest_client.request('GET', uri, name=name) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 479 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 480 | def _get_onu_config(self, onu_id=None): |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 481 | if onu_id is None: |
| 482 | uri = AdtranOltHandler.GPON_ONU_CONFIG_LIST_URI.format(self._pon_id) |
| 483 | else: |
| 484 | uri = AdtranOltHandler.GPON_ONU_CONFIG_URI.format(self._pon_id, onu_id) |
| 485 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 486 | name = 'pon-get-onu_config-{}-{}'.format(self._pon_id, onu_id) |
| 487 | return self._parent.rest_client.request('GET', uri, name=name) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 488 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 489 | def _set_pon_config(self, leaf, value): |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 490 | data = json.dumps({leaf: value}) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 491 | uri = AdtranOltHandler.GPON_PON_CONFIG_URI.format(self._pon_id) |
| 492 | name = 'pon-set-config-{}-{}-{}'.format(self._pon_id, leaf, str(value)) |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 493 | # If no optics on PON, then PON config fails with status 400, suppress this |
| 494 | suppress_error = len(self.onu_ids) == 0 |
| 495 | return self._parent.rest_client.request('PATCH', uri, data=data, name=name, |
| 496 | suppress_error=suppress_error) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 497 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 498 | def _discover_onus(self): |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 499 | 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] | 500 | if self._admin_state == AdminState.ENABLED: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 501 | if self._in_sync: |
| 502 | data = json.dumps({'pon-id': self._pon_id}) |
| 503 | uri = AdtranOltHandler.GPON_PON_DISCOVER_ONU |
| 504 | name = 'pon-discover-onu-{}'.format(self._pon_id) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 505 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 506 | self._discovery_deferred = self._parent.rest_client.request('POST', uri, data, name=name) |
| 507 | self._discovery_deferred.addBoth(self._onu_discovery_init_complete) |
| 508 | else: |
| 509 | self.discovery_deferred = reactor.callLater(0, |
| 510 | self._onu_discovery_init_complete, |
| 511 | None) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 512 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 513 | def _onu_discovery_init_complete(self, _result): |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 514 | """ |
| 515 | This method is called after the REST POST to request ONU discovery is |
| 516 | completed. The results (body) of the post is always empty / 204 NO CONTENT |
| 517 | """ |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 518 | 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] | 519 | delay += random.uniform(-delay / 10, delay / 10) |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 520 | self._discovery_deferred = reactor.callLater(delay, self._discover_onus) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 521 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 522 | def sync_hardware(self): |
| 523 | if self.state == AdtnPort.State.RUNNING or self.state == AdtnPort.State.STOPPED: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 524 | def read_config(results): |
| 525 | self.log.debug('read-config', results=results) |
| 526 | config = OltConfig.Pon.decode([results]) |
| 527 | assert self.pon_id in config, 'sync-pon-not-found-{}'.format(self.pon_id) |
| 528 | config = config[self.pon_id] |
| 529 | self._in_sync = True |
| 530 | |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 531 | dl = [] |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 532 | |
| 533 | if self.enabled != config.enabled: |
| 534 | self._in_sync = False |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 535 | self._expedite_sync = True |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 536 | dl.append(self._set_pon_config("enabled", self.enabled)) |
| 537 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 538 | elif self.state == AdtnPort.State.RUNNING: |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 539 | if self.deployment_range != config.deployment_range: |
| 540 | self._in_sync = False |
| 541 | self._expedite_sync = True |
| 542 | dl.append(self._set_pon_config("deployment-range", |
| 543 | self.deployment_range)) |
| 544 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 545 | # A little side note: FEC enable/disable cannot be changed and |
| 546 | # will remain in the previous status until an optical module |
| 547 | # is plugged in. |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 548 | if self.downstream_fec_enable != config.downstream_fec_enable: |
| 549 | self._in_sync = False |
| 550 | dl.append(self._set_pon_config("downstream-fec-enable", |
| 551 | self.downstream_fec_enable)) |
| 552 | |
| 553 | if self.upstream_fec_enable != config.upstream_fec_enable: |
| 554 | self._in_sync = False |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 555 | self._expedite_sync = True |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 556 | dl.append(self._set_pon_config("upstream-fec-enable", |
| 557 | self.upstream_fec_enable)) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 558 | defer.gatherResults(dl, consumeErrors=True) |
| 559 | return config.onus |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 560 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 561 | def sync_onus(hw_onus): |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 562 | if self.state == AdtnPort.State.RUNNING: |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 563 | self.log.debug('sync-pon-onu-results', config=hw_onus) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 564 | |
| 565 | # ONU's have their own sync task, extra (should be deleted) are |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 566 | # handled here. |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 567 | hw_onu_ids = frozenset(hw_onus.keys()) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 568 | my_onu_ids = frozenset(self._onu_by_id.keys()) |
| 569 | |
| 570 | extra_onus = hw_onu_ids - my_onu_ids |
Chip Boling | 99c388e | 2018-11-20 09:33:57 -0600 | [diff] [blame] | 571 | dl = [self.delete_onu(onu_id, hw_only=True) for onu_id in extra_onus] |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 572 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 573 | if self.activation_method == "autoactivate": |
| 574 | # Autoactivation of ONUs requires missing ONU detection. If |
Chip Boling | 99c388e | 2018-11-20 09:33:57 -0600 | [diff] [blame] | 575 | # not found, create them here but let the TCont/GEM-Port restore |
| 576 | # be handle by ONU H/w sync logic. |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 577 | for onu in [self._onu_by_id[onu_id] for onu_id in my_onu_ids - hw_onu_ids |
| 578 | if self._onu_by_id.get(onu_id) is not None]: |
Chip Boling | cadafd9 | 2018-12-20 14:42:22 -0600 | [diff] [blame] | 579 | dl.append(onu.create(reflow=True)) |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 580 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 581 | return defer.gatherResults(dl, consumeErrors=True) |
| 582 | |
| 583 | def failure(reason, what): |
| 584 | self.log.error('hardware-sync-{}-failed'.format(what), reason=reason) |
| 585 | self._in_sync = False |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 586 | self._expedite_sync = False |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 587 | |
| 588 | def reschedule(_): |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 589 | # Speed up sequential resync a limited number of times if out of sync. |
| 590 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 591 | delay = self.sync_tick |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 592 | |
| 593 | if self._expedite_sync: |
| 594 | self._expedite_count += 1 |
| 595 | if self._expedite_count < 5: |
| 596 | delay = 1 |
| 597 | else: |
| 598 | self._expedite_count = 0 |
| 599 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 600 | delay += random.uniform(-delay / 10, delay / 10) |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 601 | self.sync_deferred = reactor.callLater(delay, self.sync_hardware) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 602 | |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 603 | self.sync_deferred = self._get_pon_config() |
| 604 | self.sync_deferred.addCallbacks(read_config, failure, errbackArgs=['get-config']) |
| 605 | self.sync_deferred.addCallbacks(sync_onus, failure, errbackArgs=['pon-sync']) |
| 606 | self.sync_deferred.addBoth(reschedule) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 607 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 608 | def process_status_poll(self, status): |
| 609 | """ |
| 610 | Process PON status poll request |
| 611 | |
| 612 | :param status: (OltState.Pon object) results from RESTCONF GET |
| 613 | """ |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 614 | self.log.debug('process-status-poll', status=status) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 615 | |
| 616 | if self._admin_state != AdminState.ENABLED: |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 617 | return |
| 618 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 619 | # Process LOS list |
| 620 | self._process_los_alarms(frozenset(status.ont_los)) |
| 621 | |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 622 | # Get new/missing from the discovered ONU leaf. Stale ONUs from previous |
| 623 | # configs are now cleaned up during h/w re-sync/reflow. |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 624 | new, rediscovered_onus = self._process_status_onu_discovered_list(status.discovered_onu) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 625 | |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 626 | # Process newly discovered ONU list and rediscovered ONUs |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 627 | for serial_number in new | rediscovered_onus: |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 628 | reactor.callLater(0, self.add_onu, serial_number, status) |
| 629 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 630 | # PON Statistics |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 631 | timestamp = arrow.utcnow().float_timestamp |
| 632 | self._process_statistics(status, timestamp) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 633 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 634 | # Process ONU info. Note that newly added ONUs will not be processed |
| 635 | # until the next pass |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 636 | self._update_onu_status(status.onus, timestamp) |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 637 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 638 | # Process GEM Port information |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 639 | self._update_gem_status(status.gems, timestamp) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 640 | |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 641 | def _process_statistics(self, status, timestamp): |
| 642 | self.timestamp = timestamp |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 643 | self.rx_packets = status.rx_packets |
| 644 | self.rx_bytes = status.rx_bytes |
| 645 | self.tx_packets = status.tx_packets |
| 646 | self.tx_bytes = status.tx_bytes |
| 647 | self.tx_bip_errors = status.tx_bip_errors |
| 648 | |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 649 | def _update_onu_status(self, onus, timestamp): |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 650 | """ |
| 651 | Process ONU status for this PON |
| 652 | :param onus: (dict) onu_id: ONU State |
| 653 | """ |
| 654 | for onu_id, onu_status in onus.iteritems(): |
| 655 | if onu_id in self._onu_by_id: |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 656 | onu = self._onu_by_id[onu_id] |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 657 | onu.timestamp = timestamp |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 658 | onu.rssi = onu_status.rssi |
| 659 | onu.equalization_delay = onu_status.equalization_delay |
| 660 | onu.equalization_delay = onu_status.equalization_delay |
| 661 | onu.fiber_length = onu_status.fiber_length |
Chip Boling | bb15b51 | 2018-06-01 11:39:58 -0500 | [diff] [blame] | 662 | onu.password = onu_status.reported_password |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 663 | |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 664 | def _update_gem_status(self, gems, timestamp): |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 665 | for gem_id, gem_status in gems.iteritems(): |
| 666 | onu = self._onu_by_id.get(gem_status.onu_id) |
| 667 | if onu is not None: |
| 668 | gem_port = onu.gem_port(gem_status.gem_id) |
| 669 | if gem_port is not None: |
Chip Boling | c045138 | 2018-08-24 14:21:53 -0500 | [diff] [blame] | 670 | gem_port.timestamp = timestamp |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 671 | gem_port.rx_packets = gem_status.rx_packets |
| 672 | gem_port.rx_bytes = gem_status.rx_bytes |
| 673 | gem_port.tx_packets = gem_status.tx_packets |
| 674 | gem_port.tx_bytes = gem_status.tx_bytes |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 675 | |
| 676 | def _process_los_alarms(self, ont_los): |
| 677 | """ |
| 678 | Walk current LOS and set/clear LOS as appropriate |
| 679 | :param ont_los: (frozenset) ONU IDs of ONUs in LOS alarm state |
| 680 | """ |
| 681 | cleared_alarms = self._active_los_alarms - ont_los |
| 682 | new_alarms = ont_los - self._active_los_alarms |
| 683 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 684 | if len(cleared_alarms) > 0 or len(new_alarms) > 0: |
| 685 | self.log.info('onu-los', cleared=cleared_alarms, new=new_alarms) |
| 686 | |
| 687 | for onu_id in cleared_alarms: |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 688 | self._active_los_alarms.remove(onu_id) |
Chip Boling | 99c388e | 2018-11-20 09:33:57 -0600 | [diff] [blame] | 689 | OnuLosAlarm(self.olt.alarms, onu_id, self.port_no).clear_alarm() |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 690 | |
| 691 | for onu_id in new_alarms: |
| 692 | self._active_los_alarms.add(onu_id) |
Chip Boling | 99c388e | 2018-11-20 09:33:57 -0600 | [diff] [blame] | 693 | OnuLosAlarm(self.olt.alarms, onu_id, self.port_no).raise_alarm() |
| 694 | reactor.callLater(0, self.delete_onu, onu_id) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 695 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 696 | def _process_status_onu_discovered_list(self, discovered_onus): |
| 697 | """ |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 698 | Look for new ONUs |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 699 | |
| 700 | :param discovered_onus: (frozenset) Set of ONUs currently discovered |
| 701 | """ |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 702 | self.log.debug('discovered-ONUs', list=discovered_onus) |
| 703 | |
| 704 | # Only request discovery if activation is auto-discovery or auto-activate |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 705 | continue_discovery = ['autodiscovery', 'autoactivate'] |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 706 | |
| 707 | if self._activation_method not in continue_discovery: |
| 708 | return set(), set() |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 709 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 710 | my_onus = frozenset(self._onus.keys()) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 711 | |
| 712 | new_onus = discovered_onus - my_onus |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 713 | rediscovered_onus = my_onus & discovered_onus |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 714 | |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 715 | return new_onus, rediscovered_onus |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 716 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 717 | def _get_onu_info(self, serial_number): |
| 718 | """ |
| 719 | Parse through available xPON information for ONU configuration settings |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 720 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 721 | :param serial_number: (string) Decoded (not base64) serial number string |
| 722 | :return: (dict) onu config data or None on lookup failure |
| 723 | """ |
| 724 | try: |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 725 | if self.activation_method == "autodiscovery": |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 726 | # if self.authentication_method == 'serial-number': |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 727 | raise NotImplemented('autodiscovery: Not supported at this time') |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 728 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 729 | elif self.activation_method == "autoactivate": |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 730 | onu_id = self.get_next_onu_id |
| 731 | enabled = True |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 732 | upstream_fec_enabled = True |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 733 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 734 | else: |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 735 | self.log.error('unsupported-activation-method', method=self.activation_method) |
| 736 | return None |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 737 | |
| 738 | onu_info = { |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 739 | 'device-id': self.olt.device_id, |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 740 | 'serial-number': serial_number, |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 741 | 'pon': self, |
| 742 | 'onu-id': onu_id, |
| 743 | 'enabled': enabled, |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 744 | 'upstream-fec': upstream_fec_enabled, |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 745 | 'password': Onu.DEFAULT_PASSWORD, |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 746 | } |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 747 | pon_id = self.olt.pon_id_to_port_number(self._pon_id) |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 748 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 749 | # TODO: Currently only one UNI port and it is hardcoded to port 0 |
| 750 | onu_info['uni-ports'] = [platform.mk_uni_port_num(pon_id, onu_id)] |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 751 | |
Chip Boling | 3971d24 | 2018-06-06 10:26:34 -0500 | [diff] [blame] | 752 | # return onu_info |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 753 | return onu_info |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 754 | |
| 755 | except Exception as e: |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 756 | self.log.exception('get-onu-info-tech-profiles', e=e) |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 757 | return None |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 758 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 759 | @inlineCallbacks |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 760 | def add_onu(self, serial_number_64, status): |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 761 | """ |
| 762 | Add an ONU to the PON |
| 763 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 764 | :param serial_number_64: (str) base-64 encoded serial number |
| 765 | :param status: (dict) OLT PON status. Used to detect if ONU is already provisioned |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 766 | """ |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 767 | serial_number = Onu.serial_number_to_string(serial_number_64) |
| 768 | self.log.info('add-onu', serial_number=serial_number, |
| 769 | serial_number_64=serial_number_64, status=status) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 770 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 771 | # It takes a little while for a new ONU to be removed from the discovery |
| 772 | # list. Return early here so extra ONU IDs are not allocated |
| 773 | if serial_number_64 in self._onus: |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 774 | returnValue('wait-for-fpga') |
| 775 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 776 | if serial_number_64 in status.onus: |
| 777 | # Handles fast entry into this task before FPGA can clear results of ONU delete |
| 778 | returnValue('sticky-onu') |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 779 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 780 | # At our limit? TODO: Retrieve from device resource manager if available |
| 781 | if len(self._onus) >= self.MAX_ONUS_SUPPORTED: |
| 782 | self.log.warning('max-onus-provisioned', count=len(self._onus)) |
| 783 | returnValue('max-onus-reached') |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 784 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 785 | onu_info = self._get_onu_info(serial_number) |
| 786 | onu_id = onu_info['onu-id'] |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 787 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 788 | if onu_id is None: |
| 789 | self.log.warning('no-onu-ids-available', serial_number=serial_number, |
| 790 | serial_number_64=serial_number_64) |
| 791 | returnValue('no-ids-available') |
Chip Boling | ab8863d | 2018-03-22 14:50:31 -0500 | [diff] [blame] | 792 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 793 | # TODO: Is the best before or after creation in parent device? |
| 794 | alarm = OnuDiscoveryAlarm(self.olt.alarms, self.pon_id, serial_number) |
| 795 | reactor.callLater(0, alarm.raise_alarm) |
Chip Boling | db61c6a | 2017-09-27 12:36:45 -0500 | [diff] [blame] | 796 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 797 | # Have the core create the ONU device |
Chip Boling | cadafd9 | 2018-12-20 14:42:22 -0600 | [diff] [blame] | 798 | self._parent.add_onu_device(self.pon_id, onu_id, serial_number) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 799 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 800 | try: |
Chip Boling | cadafd9 | 2018-12-20 14:42:22 -0600 | [diff] [blame] | 801 | onu = Onu(onu_info) |
| 802 | self._onus[serial_number_64] = onu |
| 803 | self._onu_by_id[onu.onu_id] = onu |
| 804 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 805 | # Add Multicast to PON on a per-ONU basis |
| 806 | # |
| 807 | # for id_or_vid, gem_port in gem_ports.iteritems(): |
| 808 | # try: |
| 809 | # if gem_port.multicast: |
| 810 | # self.log.debug('id-or-vid', id_or_vid=id_or_vid) |
| 811 | # vid = self.olt.multicast_vlans[0] if len(self.olt.multicast_vlans) else None |
| 812 | # if vid is not None: |
| 813 | # self.add_mcast_gem_port(gem_port, vid) |
| 814 | # |
| 815 | # except Exception as e: |
| 816 | # self.log.exception('id-or-vid', e=e) |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 817 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 818 | _results = yield onu.create() |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 819 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 820 | except Exception as e: |
| 821 | self.log.warning('add-onu', serial_number=serial_number_64, e=e) |
| 822 | # allowable exception. H/w re-sync will recover/fix any issues |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 823 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 824 | @property |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 825 | def get_next_onu_id(self): |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 826 | return self._parent.resource_mgr.get_onu_id(self._pon_id) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 827 | |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 828 | def release_onu_id(self, onu_id): |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 829 | self._parent.resource_mgr.free_onu_id(self._pon_id, onu_id) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 830 | |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 831 | @inlineCallbacks |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 832 | def _remove_from_hardware(self, onu_id): |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 833 | uri = AdtranOltHandler.GPON_ONU_CONFIG_URI.format(self._pon_id, onu_id) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 834 | name = 'pon-delete-onu-{}-{}'.format(self._pon_id, onu_id) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 835 | |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 836 | try: |
| 837 | yield self._parent.rest_client.request('DELETE', uri, name=name) |
| 838 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 839 | except RestInvalidResponseCode as e: |
| 840 | if e.code != 404: |
| 841 | self.log.exception('onu-delete', e=e) |
| 842 | |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 843 | except Exception as e: |
| 844 | self.log.exception('onu-hw-delete', onu_id=onu_id, e=e) |
| 845 | |
| 846 | @inlineCallbacks |
Chip Boling | 99c388e | 2018-11-20 09:33:57 -0600 | [diff] [blame] | 847 | def delete_onu(self, onu_id, hw_only=False): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 848 | onu = self._onu_by_id.get(onu_id) |
| 849 | |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 850 | # Remove from any local dictionary |
| 851 | if onu_id in self._onu_by_id: |
| 852 | del self._onu_by_id[onu_id] |
Chip Boling | ff3087f | 2017-10-12 09:26:29 -0500 | [diff] [blame] | 853 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 854 | if onu is not None: |
Chip Boling | cadafd9 | 2018-12-20 14:42:22 -0600 | [diff] [blame] | 855 | if onu.serial_number_64 in self._onus: |
| 856 | del self._onus[onu.serial_number_64] |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 857 | try: |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 858 | proxy_address = onu.proxy_address |
| 859 | onu.delete() # Remove from hardware |
Chip Boling | 9fef0fd | 2018-12-11 09:43:59 -0600 | [diff] [blame] | 860 | |
Chip Boling | 99c388e | 2018-11-20 09:33:57 -0600 | [diff] [blame] | 861 | # And removal from VOLTHA adapter agent |
| 862 | if not hw_only: |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 863 | self._parent.delete_child_device(proxy_address) |
Chip Boling | 99c388e | 2018-11-20 09:33:57 -0600 | [diff] [blame] | 864 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 865 | except Exception as e: |
| 866 | self.log.exception('onu-delete', serial_number=onu.serial_number, e=e) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 867 | else: |
| 868 | try: |
| 869 | yield self._remove_from_hardware(onu_id) |
| 870 | |
| 871 | except Exception as e: |
Chip Boling | 99c388e | 2018-11-20 09:33:57 -0600 | [diff] [blame] | 872 | self.log.debug('onu-remove', serial_number=onu.serial_number, e=e) |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 873 | |
Chip Boling | cadafd9 | 2018-12-20 14:42:22 -0600 | [diff] [blame] | 874 | # Remove from LOS list if needed TODO: Should a 'clear' alarm be sent as well ? |
Chip Boling | 9fef0fd | 2018-12-11 09:43:59 -0600 | [diff] [blame] | 875 | if onu is not None and onu.id in self._active_los_alarms: |
Chip Boling | 4912e78 | 2018-11-09 16:33:40 -0600 | [diff] [blame] | 876 | self._active_los_alarms.remove(onu.id) |
| 877 | |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 878 | def add_mcast_gem_port(self, mcast_gem, vlan): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 879 | """ |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 880 | Add any new Multicast GEM Ports to the PON |
| 881 | :param mcast_gem: (GemPort) |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 882 | """ |
Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 883 | if vlan in self._mcast_gem_ports: |
| 884 | return |
| 885 | |
| 886 | assert len(self._mcast_gem_ports) == 0, 'Only 1 MCAST GEMPort until BBF Support' |
| 887 | assert 1 <= vlan <= 4095, 'Invalid Multicast VLAN ID' |
| 888 | assert len(self.olt.multicast_vlans) == 1, 'Only support 1 MCAST VLAN until BBF Support' |
| 889 | |
| 890 | self._mcast_gem_ports[vlan] = mcast_gem |