Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2018 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 16 | from __future__ import absolute_import |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 17 | import structlog |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 18 | from twisted.internet import reactor |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 19 | from twisted.internet.defer import inlineCallbacks, TimeoutError, failure |
| 20 | from pyvoltha.adapters.extensions.omci.omci_me import Ont2G, OmciNullPointer, PriorityQueueFrame, \ |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame^] | 21 | Ieee8021pMapperServiceProfileFrame, MacBridgePortConfigurationDataFrame, GemInterworkingTpFrame, \ |
| 22 | GemPortNetworkCtpFrame |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 23 | from pyvoltha.adapters.extensions.omci.tasks.task import Task |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 24 | from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes |
Matt Jeanneret | 4195d7d | 2020-01-12 16:58:18 -0500 | [diff] [blame] | 25 | from pyvoltha.adapters.extensions.omci.omci_entities import OntG, Tcont, PriorityQueueG, Ieee8021pMapperServiceProfile, \ |
| 26 | GemPortNetworkCtp |
aishwaryarana01 | 80594ce | 2019-07-26 15:31:14 -0500 | [diff] [blame] | 27 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 28 | OP = EntityOperations |
| 29 | RC = ReasonCodes |
| 30 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 31 | SETUP_TP_TASK_PRIORITY = 240 |
| 32 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 33 | |
| 34 | class TechProfileDownloadFailure(Exception): |
| 35 | """ |
| 36 | This error is raised by default when the download fails |
| 37 | """ |
| 38 | |
| 39 | |
| 40 | class TechProfileResourcesFailure(Exception): |
| 41 | """ |
| 42 | This error is raised by when one or more resources required is not available |
| 43 | """ |
| 44 | |
| 45 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 46 | class BrcmTpSetupTask(Task): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 47 | """ |
| 48 | OpenOMCI Tech-Profile Download Task |
| 49 | |
| 50 | """ |
| 51 | |
| 52 | name = "Broadcom Tech-Profile Download Task" |
| 53 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 54 | def __init__(self, omci_agent, handler, uni_id, tconts, gem_ports, tp_table_id): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 55 | """ |
| 56 | Class initialization |
| 57 | |
| 58 | :param omci_agent: (OmciAdapterAgent) OMCI Adapter agent |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 59 | :param handler: (BrcmOpenomciOnuHandler) ONU Device Handler Instance |
| 60 | :param uni_id: (int) numeric id of the uni port on the onu device, starts at 0 |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 61 | :param tp_table_id: (int) Technology Profile Table-ID |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 62 | """ |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 63 | super(BrcmTpSetupTask, self).__init__(BrcmTpSetupTask.name, |
| 64 | omci_agent, |
| 65 | handler.device_id, |
| 66 | priority=SETUP_TP_TASK_PRIORITY, |
| 67 | exclusive=True) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 68 | |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 69 | self.log = structlog.get_logger(device_id=handler.device_id, |
| 70 | name=BrcmTpSetupTask.name, |
| 71 | task_id=self._task_id, |
| 72 | tconts=tconts, |
| 73 | gem_ports=gem_ports, |
| 74 | uni_id=uni_id, |
| 75 | tp_table_id=tp_table_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 76 | |
| 77 | self._onu_device = omci_agent.get_device(handler.device_id) |
| 78 | self._local_deferred = None |
| 79 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 80 | self._uni_port = handler.uni_ports[uni_id] |
| 81 | assert self._uni_port.uni_id == uni_id |
| 82 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 83 | # Tech Profile Table ID |
| 84 | self._tp_table_id = tp_table_id |
| 85 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 86 | # Entity IDs. IDs with values can probably be most anything for most ONUs, |
| 87 | # IDs set to None are discovered/set |
| 88 | |
| 89 | self._mac_bridge_service_profile_entity_id = \ |
| 90 | handler.mac_bridge_service_profile_entity_id |
| 91 | self._ieee_mapper_service_profile_entity_id = \ |
| 92 | handler.pon_port.ieee_mapper_service_profile_entity_id |
| 93 | self._mac_bridge_port_ani_entity_id = \ |
| 94 | handler.pon_port.mac_bridge_port_ani_entity_id |
| 95 | self._gal_enet_profile_entity_id = \ |
| 96 | handler.gal_enet_profile_entity_id |
| 97 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 98 | self._tconts = [] |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 99 | for t in tconts: |
| 100 | self._tconts.append(t) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 101 | |
| 102 | self._gem_ports = [] |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 103 | for g in gem_ports: |
| 104 | self._gem_ports.append(g) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 105 | |
| 106 | self.tcont_me_to_queue_map = dict() |
| 107 | self.uni_port_to_queue_map = dict() |
| 108 | |
| 109 | def cancel_deferred(self): |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 110 | super(BrcmTpSetupTask, self).cancel_deferred() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 111 | |
| 112 | d, self._local_deferred = self._local_deferred, None |
| 113 | try: |
| 114 | if d is not None and not d.called: |
| 115 | d.cancel() |
| 116 | except: |
| 117 | pass |
| 118 | |
| 119 | def start(self): |
| 120 | """ |
| 121 | Start the Tech-Profile Download |
| 122 | """ |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 123 | super(BrcmTpSetupTask, self).start() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 124 | self._local_deferred = reactor.callLater(0, self.perform_service_specific_steps) |
| 125 | |
| 126 | def stop(self): |
| 127 | """ |
| 128 | Shutdown Tech-Profile download tasks |
| 129 | """ |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 130 | self.cancel_deferred() |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 131 | super(BrcmTpSetupTask, self).stop() |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 132 | |
| 133 | def check_status_and_state(self, results, operation=''): |
| 134 | """ |
| 135 | Check the results of an OMCI response. An exception is thrown |
| 136 | if the task was cancelled or an error was detected. |
| 137 | |
| 138 | :param results: (OmciFrame) OMCI Response frame |
| 139 | :param operation: (str) what operation was being performed |
| 140 | :return: True if successful, False if the entity existed (already created) |
| 141 | """ |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 142 | |
| 143 | omci_msg = results.fields['omci_message'].fields |
| 144 | status = omci_msg['success_code'] |
| 145 | error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a') |
| 146 | failed_mask = omci_msg.get('failed_attributes_mask', 'n/a') |
| 147 | unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a') |
| 148 | |
Matt Jeanneret | e8fc53e | 2019-04-13 15:58:33 -0400 | [diff] [blame] | 149 | self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg, status=status, error_mask=error_mask, |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 150 | failed_mask=failed_mask, unsupported_mask=unsupported_mask) |
| 151 | |
| 152 | if status == RC.Success: |
| 153 | self.strobe_watchdog() |
| 154 | return True |
| 155 | |
| 156 | elif status == RC.InstanceExists: |
| 157 | return False |
| 158 | |
| 159 | raise TechProfileDownloadFailure( |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 160 | '{} failed with a status of {}, error_mask: {}, failed_mask: {}, ' |
| 161 | 'unsupported_mask: {}'.format(operation, status, error_mask, failed_mask, unsupported_mask)) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 162 | |
| 163 | @inlineCallbacks |
| 164 | def perform_service_specific_steps(self): |
Mahir Gunyel | a982ec3 | 2020-02-25 12:30:37 -0800 | [diff] [blame] | 165 | self.log.info('starting-tech-profile-setup', uni_id=self._uni_port.uni_id, |
Girish Gowdra | acb65b0 | 2020-07-12 20:35:47 -0700 | [diff] [blame] | 166 | tconts=self._tconts, gem_ports=self._gem_ports, tp_table_id=self._tp_table_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 167 | |
| 168 | omci_cc = self._onu_device.omci_cc |
aishwaryarana01 | 80594ce | 2019-07-26 15:31:14 -0500 | [diff] [blame] | 169 | gem_pq_associativity = dict() |
| 170 | pq_to_related_port = dict() |
| 171 | is_related_ports_configurable = False |
Girish Gowdra | acb65b0 | 2020-07-12 20:35:47 -0700 | [diff] [blame] | 172 | tcont_entity_id = 0 |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 173 | |
| 174 | try: |
| 175 | ################################################################################ |
| 176 | # TCONTS |
| 177 | # |
| 178 | # EntityID will be referenced by: |
| 179 | # - GemPortNetworkCtp |
| 180 | # References: |
| 181 | # - ONU created TCONT (created on ONU startup) |
| 182 | |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 183 | # Setup 8021p mapper and ani mac bridge port, if it does not exist |
| 184 | # Querying just 8021p mapper ME should be enough since we create and |
| 185 | # delete 8021pMapper and ANI Mac Bridge Port together. |
| 186 | ieee_8021p_mapper_exists = False |
| 187 | ieee_8021p_mapper = self._onu_device.query_mib(Ieee8021pMapperServiceProfile.class_id) |
| 188 | for k, v in ieee_8021p_mapper.items(): |
| 189 | if not isinstance(v, dict): |
| 190 | continue |
| 191 | if k == (self._ieee_mapper_service_profile_entity_id + |
| 192 | self._uni_port.mac_bridge_port_num + self._tp_table_id): |
| 193 | ieee_8021p_mapper_exists = True |
| 194 | |
| 195 | if ieee_8021p_mapper_exists is False: |
| 196 | self.log.info("setting-up-8021pmapper-ani-mac-bridge-port") |
| 197 | yield self._setup__8021p_mapper__ani_mac_bridge_port() |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame^] | 198 | else: |
| 199 | # If IEEE8021pMapper ME existed already, then we need to re-build the |
| 200 | # inter-working-tp-pointers for different gem-entity-ids. Delete the old one |
| 201 | self.log.info("delete-and-recreate-8021pmapper-ani-mac-bridge-port") |
| 202 | yield self._delete_and_recreate__8021p_mapper__ani_mac_bridge_port() |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 203 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 204 | tcont_idents = self._onu_device.query_mib(Tcont.class_id) |
| 205 | self.log.debug('tcont-idents', tcont_idents=tcont_idents) |
| 206 | |
Girish Gowdra | acb65b0 | 2020-07-12 20:35:47 -0700 | [diff] [blame] | 207 | # There can be only one tcont that can be installed per tech-profile download task |
| 208 | # Each tech-profile represents a single tcont and associated gemports |
| 209 | assert len(self._tconts) == 1 |
Girish Gowdra | 7c1240c | 2020-07-15 15:06:42 -0700 | [diff] [blame] | 210 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 211 | for tcont in self._tconts: |
| 212 | self.log.debug('tcont-loop', tcont=tcont) |
| 213 | |
| 214 | if tcont.entity_id is None: |
| 215 | free_entity_id = None |
| 216 | for k, v in tcont_idents.items(): |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 217 | if not isinstance(v, dict): |
| 218 | continue |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 219 | alloc_check = v.get('attributes', {}).get('alloc_id', 0) |
Girish Gowdra | ba4b181 | 2020-07-17 12:21:26 -0700 | [diff] [blame] | 220 | if alloc_check == tcont.alloc_id: |
| 221 | # If any Tcont entity already refers to the alloc-id we want to use, |
| 222 | # lets choose that Tcont entity. |
| 223 | # This Tcont will be re-added to ONU and that is fine. The ONU reports that |
| 224 | # the entity already exists, which is not an error. |
| 225 | free_entity_id = k |
| 226 | self.log.debug("tcont-entity-already-exists-on-onu-for-this-alloc-id", |
| 227 | tcont_entity_id=k, alloc_id=tcont.alloc_id) |
| 228 | break |
| 229 | elif alloc_check == 0xFF or alloc_check == 0xFFFF: |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 230 | free_entity_id = k |
| 231 | break |
| 232 | |
| 233 | self.log.debug('tcont-loop-free', free_entity_id=free_entity_id, alloc_id=tcont.alloc_id) |
| 234 | |
| 235 | if free_entity_id is None: |
| 236 | self.log.error('no-available-tconts') |
| 237 | break |
| 238 | |
| 239 | # Also assign entity id within tcont object |
| 240 | results = yield tcont.add_to_hardware(omci_cc, free_entity_id) |
| 241 | self.check_status_and_state(results, 'new-tcont-added') |
Girish Gowdra | acb65b0 | 2020-07-12 20:35:47 -0700 | [diff] [blame] | 242 | # There is only tcont to be added per tech-profile download procedure |
| 243 | # So, there is no issue of overwriting the 'tcont_entity_id' |
| 244 | tcont_entity_id = free_entity_id |
| 245 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 246 | else: |
Matt Jeanneret | 4195d7d | 2020-01-12 16:58:18 -0500 | [diff] [blame] | 247 | self.log.debug('tcont-already-assigned', tcont_entity_id=tcont.entity_id, alloc_id=tcont.alloc_id) |
Girish Gowdra | 7c1240c | 2020-07-15 15:06:42 -0700 | [diff] [blame] | 248 | tcont_entity_id = tcont.entity_id |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 249 | |
| 250 | ################################################################################ |
| 251 | # GEMS (GemPortNetworkCtp and GemInterworkingTp) |
| 252 | # |
| 253 | # For both of these MEs, the entity_id is the GEM Port ID. The entity id of the |
| 254 | # GemInterworkingTp ME could be different since it has an attribute to specify |
| 255 | # the GemPortNetworkCtp entity id. |
| 256 | # |
| 257 | # for the GemPortNetworkCtp ME |
| 258 | # |
| 259 | # GemPortNetworkCtp |
| 260 | # EntityID will be referenced by: |
| 261 | # - GemInterworkingTp |
| 262 | # References: |
| 263 | # - TCONT |
| 264 | # - Hardcoded upstream TM Entity ID |
| 265 | # - (Possibly in Future) Upstream Traffic descriptor profile pointer |
| 266 | # |
| 267 | # GemInterworkingTp |
| 268 | # EntityID will be referenced by: |
| 269 | # - Ieee8021pMapperServiceProfile |
| 270 | # References: |
| 271 | # - GemPortNetworkCtp |
| 272 | # - Ieee8021pMapperServiceProfile |
| 273 | # - GalEthernetProfile |
| 274 | # |
| 275 | |
| 276 | onu_g = self._onu_device.query_mib(OntG.class_id) |
| 277 | # If the traffic management option attribute in the ONU-G ME is 0 |
| 278 | # (priority controlled) or 2 (priority and rate controlled), this |
| 279 | # pointer specifies the priority queue ME serving this GEM port |
| 280 | # network CTP. If the traffic management option attribute is 1 |
| 281 | # (rate controlled), this attribute redundantly points to the |
| 282 | # T-CONT serving this GEM port network CTP. |
| 283 | traffic_mgmt_opt = \ |
| 284 | onu_g.get('attributes', {}).get('traffic_management_options', 0) |
| 285 | self.log.debug("traffic-mgmt-option", traffic_mgmt_opt=traffic_mgmt_opt) |
| 286 | |
| 287 | prior_q = self._onu_device.query_mib(PriorityQueueG.class_id) |
| 288 | for k, v in prior_q.items(): |
| 289 | self.log.debug("prior-q", k=k, v=v) |
| 290 | |
| 291 | try: |
| 292 | _ = iter(v) |
| 293 | except TypeError: |
| 294 | continue |
| 295 | |
Girish Gowdra | acb65b0 | 2020-07-12 20:35:47 -0700 | [diff] [blame] | 296 | # Parse PQ MEs only with relevant information |
| 297 | if 'instance_id' in v and 'related_port' in v['attributes']: |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 298 | related_port = v['attributes']['related_port'] |
aishwaryarana01 | 80594ce | 2019-07-26 15:31:14 -0500 | [diff] [blame] | 299 | pq_to_related_port[k] = related_port |
Girish Gowdra | acb65b0 | 2020-07-12 20:35:47 -0700 | [diff] [blame] | 300 | # If the MSB is set, it represents an Upstream PQ referencing the TCONT |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 301 | if v['instance_id'] & 0b1000000000000000: |
Girish Gowdra | acb65b0 | 2020-07-12 20:35:47 -0700 | [diff] [blame] | 302 | # If it references the TCONT ME we have just installed |
| 303 | if tcont_entity_id == (related_port & 0xffff0000) >> 16: |
| 304 | if tcont_entity_id not in self.tcont_me_to_queue_map: |
| 305 | self.log.debug("prior-q-related-port-and-tcont-me", |
| 306 | related_port=related_port, |
| 307 | tcont_me=tcont_entity_id) |
| 308 | self.tcont_me_to_queue_map[tcont_entity_id] = list() |
| 309 | # Store the PQ into the list which is referenced by TCONT ME we have provisioned |
| 310 | self.tcont_me_to_queue_map[tcont_entity_id].append(k) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 311 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 312 | else: |
Girish Gowdra | acb65b0 | 2020-07-12 20:35:47 -0700 | [diff] [blame] | 313 | # This represents the PQ pointing to the UNI Port ME (Downstream PQ) |
| 314 | if self._uni_port.entity_id == (related_port & 0xffff0000) >> 16: |
| 315 | if self._uni_port.entity_id not in self.uni_port_to_queue_map: |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 316 | self.log.debug("prior-q-related-port-and-uni-port-me", |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 317 | related_port=related_port, |
Girish Gowdra | acb65b0 | 2020-07-12 20:35:47 -0700 | [diff] [blame] | 318 | uni_port_me=self._uni_port.entity_id) |
| 319 | self.uni_port_to_queue_map[self._uni_port.entity_id] = list() |
| 320 | # Store the PQ into the list which is referenced by UNI Port ME we have provisioned |
| 321 | self.uni_port_to_queue_map[self._uni_port.entity_id].append(k) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 322 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 323 | self.log.debug("ul-prior-q", ul_prior_q=self.tcont_me_to_queue_map) |
| 324 | self.log.debug("dl-prior-q", dl_prior_q=self.uni_port_to_queue_map) |
| 325 | |
| 326 | for gem_port in self._gem_ports: |
| 327 | # TODO: Traffic descriptor will be available after meter bands are available |
| 328 | tcont = gem_port.tcont |
| 329 | if tcont is None: |
| 330 | self.log.error('unknown-tcont-reference', gem_id=gem_port.gem_id) |
| 331 | continue |
| 332 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 333 | if gem_port.direction == "upstream" or \ |
| 334 | gem_port.direction == "bi-directional": |
| 335 | |
| 336 | # Sort the priority queue list in order of priority. |
| 337 | # 0 is highest priority and 0x0fff is lowest. |
| 338 | self.tcont_me_to_queue_map[tcont.entity_id].sort() |
| 339 | self.uni_port_to_queue_map[self._uni_port.entity_id].sort() |
aishwaryarana01 | 80594ce | 2019-07-26 15:31:14 -0500 | [diff] [blame] | 340 | # Get the priority queue by indexing the priority value of the gemport. |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 341 | # The self.tcont_me_to_queue_map and self.uni_port_to_queue_map |
| 342 | # have priority queue entities ordered in descending order |
| 343 | # of priority |
aishwaryarana01 | 80594ce | 2019-07-26 15:31:14 -0500 | [diff] [blame] | 344 | |
| 345 | ul_prior_q_entity_id = \ |
| 346 | self.tcont_me_to_queue_map[tcont.entity_id][gem_port.priority_q] |
| 347 | dl_prior_q_entity_id = \ |
| 348 | self.uni_port_to_queue_map[self._uni_port.entity_id][gem_port.priority_q] |
| 349 | |
| 350 | pq_attributes = dict() |
| 351 | pq_attributes["pq_entity_id"] = ul_prior_q_entity_id |
| 352 | pq_attributes["weight"] = gem_port.weight |
| 353 | pq_attributes["scheduling_policy"] = gem_port.scheduling_policy |
| 354 | pq_attributes["priority_q"] = gem_port.priority_q |
| 355 | gem_pq_associativity[gem_port.entity_id] = pq_attributes |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 356 | |
| 357 | assert ul_prior_q_entity_id is not None and \ |
| 358 | dl_prior_q_entity_id is not None |
| 359 | |
Matt Jeanneret | 4195d7d | 2020-01-12 16:58:18 -0500 | [diff] [blame] | 360 | existing = self._onu_device.query_mib(GemPortNetworkCtp.class_id, gem_port.entity_id) |
| 361 | self.log.debug('looking-for-gemport-before-create', existing=existing, |
| 362 | class_id=GemPortNetworkCtp.class_id, |
| 363 | entity_id=gem_port.entity_id) |
| 364 | if existing: |
| 365 | results = yield gem_port.remove_from_hardware(omci_cc) |
| 366 | self.check_status_and_state(results, 'remove-existing-gem-port') |
| 367 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 368 | results = yield gem_port.add_to_hardware(omci_cc, |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 369 | tcont.entity_id, |
| 370 | self._ieee_mapper_service_profile_entity_id + |
| 371 | self._uni_port.mac_bridge_port_num + |
| 372 | self._tp_table_id, |
| 373 | self._gal_enet_profile_entity_id, |
| 374 | ul_prior_q_entity_id, dl_prior_q_entity_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 375 | self.check_status_and_state(results, 'assign-gem-port') |
| 376 | elif gem_port.direction == "downstream": |
| 377 | # Downstream is inverse of upstream |
| 378 | # TODO: could also be a case of multicast. Not supported for now |
| 379 | self.log.debug("skipping-downstream-gem", gem_port=gem_port) |
| 380 | pass |
| 381 | |
| 382 | ################################################################################ |
aishwaryarana01 | 80594ce | 2019-07-26 15:31:14 -0500 | [diff] [blame] | 383 | # Update the PriorityQeue Attributes for the PQ Associated with Gemport |
| 384 | # |
| 385 | # Entityt ID was created prior to this call. This is a set |
| 386 | # |
| 387 | # |
| 388 | |
| 389 | ont2g = self._onu_device.query_mib(Ont2G.class_id) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 390 | qos_config_flexibility_ie = ont2g.get(0, {}).get('attributes', {}). \ |
| 391 | get('qos_configuration_flexibility', None) |
aishwaryarana01 | 80594ce | 2019-07-26 15:31:14 -0500 | [diff] [blame] | 392 | self.log.debug("qos_config_flexibility", |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 393 | qos_config_flexibility=qos_config_flexibility_ie) |
aishwaryarana01 | 80594ce | 2019-07-26 15:31:14 -0500 | [diff] [blame] | 394 | |
| 395 | if qos_config_flexibility_ie & 0b100000: |
| 396 | is_related_ports_configurable = True |
| 397 | |
| 398 | for k, v in gem_pq_associativity.items(): |
| 399 | if v["scheduling_policy"] == "WRR": |
| 400 | self.log.debug("updating-pq-weight") |
| 401 | msg = PriorityQueueFrame(v["pq_entity_id"], weight=v["weight"]) |
| 402 | frame = msg.set() |
| 403 | results = yield omci_cc.send(frame) |
| 404 | self.check_status_and_state(results, 'set-priority-queues-weight') |
| 405 | elif v["scheduling_policy"] == "StrictPriority" and \ |
| 406 | is_related_ports_configurable: |
| 407 | self.log.debug("updating-pq-priority") |
| 408 | related_port = pq_to_related_port[v["pq_entity_id"]] |
| 409 | related_port = related_port & 0xffff0000 |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 410 | related_port = related_port | v['priority_q'] # Set priority |
aishwaryarana01 | 80594ce | 2019-07-26 15:31:14 -0500 | [diff] [blame] | 411 | msg = PriorityQueueFrame(v["pq_entity_id"], related_port=related_port) |
| 412 | frame = msg.set() |
| 413 | results = yield omci_cc.send(frame) |
| 414 | self.check_status_and_state(results, 'set-priority-queues-priority') |
| 415 | |
aishwaryarana01 | 80594ce | 2019-07-26 15:31:14 -0500 | [diff] [blame] | 416 | ################################################################################ |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 417 | # Update the IEEE 802.1p Mapper Service Profile config |
| 418 | # |
| 419 | # EntityID was created prior to this call. This is a set |
| 420 | # |
| 421 | # References: |
| 422 | # - Gem Interwork TPs are set here |
| 423 | # |
| 424 | |
| 425 | gem_entity_ids = [OmciNullPointer] * 8 |
| 426 | for gem_port in self._gem_ports: |
| 427 | self.log.debug("tp-gem-port", entity_id=gem_port.entity_id, uni_id=gem_port.uni_id) |
| 428 | |
| 429 | if gem_port.direction == "upstream" or \ |
| 430 | gem_port.direction == "bi-directional": |
| 431 | for i, p in enumerate(reversed(gem_port.pbit_map)): |
| 432 | if p == '1': |
| 433 | gem_entity_ids[i] = gem_port.entity_id |
| 434 | elif gem_port.direction == "downstream": |
| 435 | # Downstream gem port p-bit mapper is inverse of upstream |
| 436 | # TODO: Could also be a case of multicast. Not supported for now |
| 437 | pass |
| 438 | |
| 439 | msg = Ieee8021pMapperServiceProfileFrame( |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 440 | (self._ieee_mapper_service_profile_entity_id + |
| 441 | self._uni_port.mac_bridge_port_num + self._tp_table_id), |
| 442 | # 802.1p mapper Service Mapper Profile ID |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 443 | interwork_tp_pointers=gem_entity_ids # Interworking TP IDs |
| 444 | ) |
| 445 | frame = msg.set() |
| 446 | self.log.debug('openomci-msg', omci_msg=msg) |
| 447 | results = yield omci_cc.send(frame) |
| 448 | self.check_status_and_state(results, 'set-8021p-mapper-service-profile-ul') |
| 449 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 450 | self.deferred.callback("tech-profile-download-success") |
| 451 | |
| 452 | except TimeoutError as e: |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 453 | self.log.warn('rx-timeout-tech-profile', e=e) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 454 | self.deferred.errback(failure.Failure(e)) |
| 455 | |
| 456 | except Exception as e: |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 457 | self.log.exception('omci-setup-tech-profile', e=e) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 458 | self.deferred.errback(failure.Failure(e)) |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 459 | |
| 460 | @inlineCallbacks |
| 461 | def _setup__8021p_mapper__ani_mac_bridge_port(self): |
| 462 | |
| 463 | omci_cc = self._onu_device.omci_cc |
| 464 | |
| 465 | try: |
| 466 | ################################################################################ |
| 467 | # PON Specific # |
| 468 | ################################################################################ |
| 469 | # IEEE 802.1 Mapper Service config - One per tech-profile per UNI |
| 470 | # |
| 471 | # EntityID will be referenced by: |
| 472 | # - MAC Bridge Port Configuration Data for the PON port and TP ID |
| 473 | # References: |
| 474 | # - Nothing at this point. When a GEM port is created, this entity will |
| 475 | # be updated to reference the GEM Interworking TP |
| 476 | |
| 477 | msg = Ieee8021pMapperServiceProfileFrame( |
| 478 | self._ieee_mapper_service_profile_entity_id + |
| 479 | self._uni_port.mac_bridge_port_num + |
| 480 | self._tp_table_id |
| 481 | ) |
| 482 | frame = msg.create() |
| 483 | self.log.debug('openomci-msg', omci_msg=msg) |
| 484 | results = yield omci_cc.send(frame) |
| 485 | self.check_status_and_state(results, 'create-8021p-mapper-service-profile') |
| 486 | |
| 487 | ################################################################################ |
| 488 | # Create MAC Bridge Port Configuration Data for the PON port via IEEE 802.1 |
| 489 | # mapper service and this per TechProfile. Upon receipt by the ONU, the ONU will create an instance |
| 490 | # of the following before returning the response. |
| 491 | # |
| 492 | # - MAC bridge port designation data |
| 493 | # - MAC bridge port filter table data |
| 494 | # - MAC bridge port bridge table data |
| 495 | # |
| 496 | # EntityID will be referenced by: |
| 497 | # - Implicitly by the VLAN tagging filter data |
| 498 | # References: |
| 499 | # - MAC Bridge Service Profile (the bridge) |
| 500 | # - IEEE 802.1p mapper service profile for PON port |
| 501 | |
| 502 | # TODO: magic. make a static variable for tp_type |
| 503 | msg = MacBridgePortConfigurationDataFrame( |
Matt Jeanneret | 2e5c6f1 | 2019-12-13 07:06:06 -0500 | [diff] [blame] | 504 | self._mac_bridge_port_ani_entity_id + self._uni_port.entity_id + self._tp_table_id, # Entity ID |
Girish Gowdra | e933cd3 | 2019-11-21 21:04:41 +0530 | [diff] [blame] | 505 | bridge_id_pointer=( |
| 506 | self._mac_bridge_service_profile_entity_id + |
| 507 | self._uni_port.mac_bridge_port_num), |
| 508 | # Bridge Entity ID |
| 509 | port_num=0xff, # Port ID - unique number within the bridge |
| 510 | tp_type=3, # TP Type (IEEE 802.1p mapper service) |
| 511 | tp_pointer=( |
| 512 | self._ieee_mapper_service_profile_entity_id + |
| 513 | self._uni_port.mac_bridge_port_num + |
| 514 | self._tp_table_id |
| 515 | ) |
| 516 | # TP ID, 8021p mapper ID |
| 517 | ) |
| 518 | frame = msg.create() |
| 519 | self.log.debug('openomci-msg', omci_msg=msg) |
| 520 | results = yield omci_cc.send(frame) |
| 521 | self.check_status_and_state(results, 'create-mac-bridge-port-configuration-data-8021p-mapper') |
| 522 | |
| 523 | except TimeoutError as e: |
| 524 | self.log.warn('rx-timeout-8021p-ani-port-setup', e=e) |
| 525 | raise |
| 526 | |
| 527 | except Exception as e: |
| 528 | self.log.exception('omci-setup-8021p-ani-port-setup', e=e) |
| 529 | raise |
Girish Gowdra | 322cca1 | 2020-08-09 15:55:54 -0700 | [diff] [blame^] | 530 | |
| 531 | @inlineCallbacks |
| 532 | def _delete_and_recreate__8021p_mapper__ani_mac_bridge_port(self): |
| 533 | |
| 534 | omci_cc = self._onu_device.omci_cc |
| 535 | |
| 536 | try: |
| 537 | |
| 538 | # First clean up the Gem Ports references by the old 8021pMapper |
| 539 | ieee_8021p_mapper = self._onu_device.query_mib(Ieee8021pMapperServiceProfile.class_id) |
| 540 | for k, v in ieee_8021p_mapper.items(): |
| 541 | if not isinstance(v, dict): |
| 542 | continue |
| 543 | # Check the entity-id of the instance matches what we expect |
| 544 | # for this Uni/TechProfileId |
| 545 | if k == (self._ieee_mapper_service_profile_entity_id + |
| 546 | self._uni_port.mac_bridge_port_num + self._tp_table_id): |
| 547 | for i in range(8): |
| 548 | gem_entity_id = v.get('attributes', {}). \ |
| 549 | get('interwork_tp_pointer_for_p_bit_priority_' + str(i), OmciNullPointer) |
| 550 | if gem_entity_id is not OmciNullPointer: |
| 551 | self.log.debug('remove-from-hardware', gem_id=gem_entity_id) |
| 552 | try: |
| 553 | msg = GemInterworkingTpFrame(gem_entity_id) |
| 554 | frame = msg.delete() |
| 555 | self.log.debug('openomci-msg', omci_msg=msg) |
| 556 | results = yield omci_cc.send(frame) |
| 557 | self.check_status_and_state(results, 'delete-gem-port-network-ctp') |
| 558 | except Exception as e: |
| 559 | self.log.exception('interworking-delete', e=e) |
| 560 | raise |
| 561 | |
| 562 | try: |
| 563 | msg = GemPortNetworkCtpFrame(gem_entity_id) |
| 564 | frame = msg.delete() |
| 565 | self.log.debug('openomci-msg', omci_msg=msg) |
| 566 | results = yield omci_cc.send(frame) |
| 567 | self.check_status_and_state(results, 'delete-gem-interworking-tp') |
| 568 | except Exception as e: |
| 569 | self.log.exception('gemport-delete', e=e) |
| 570 | raise |
| 571 | break |
| 572 | |
| 573 | # Then delete 8021pMapper ME |
| 574 | msg = Ieee8021pMapperServiceProfileFrame( |
| 575 | self._ieee_mapper_service_profile_entity_id + |
| 576 | self._uni_port.mac_bridge_port_num + |
| 577 | self._tp_table_id |
| 578 | ) |
| 579 | frame = msg.delete() |
| 580 | self.log.debug('openomci-msg', omci_msg=msg) |
| 581 | results = yield omci_cc.send(frame) |
| 582 | self.check_status_and_state(results, 'delete-8021p-mapper-service-profile') |
| 583 | |
| 584 | # Then delete ANI Mac Bridge port |
| 585 | msg = MacBridgePortConfigurationDataFrame( |
| 586 | self._mac_bridge_port_ani_entity_id + self._uni_port.entity_id + self._tp_table_id # Entity ID |
| 587 | ) |
| 588 | frame = msg.delete() |
| 589 | self.log.debug('openomci-msg', omci_msg=msg) |
| 590 | results = yield omci_cc.send(frame) |
| 591 | self.check_status_and_state(results, 'delete-mac-bridge-port-configuration-data') |
| 592 | |
| 593 | # TODO: We need not delete the TCONT as TCONTs are pre-created. We should possibly |
| 594 | # unset the TCONTs alloc-id from a valid value to 0xffff. |
| 595 | # But this was not causing issues in my test. A separate Jira is necessary for this. |
| 596 | yield self._setup__8021p_mapper__ani_mac_bridge_port() |
| 597 | |
| 598 | except TimeoutError as e: |
| 599 | self.log.warn('rx-timeout-8021p-ani-port-delete', e=e) |
| 600 | raise |
| 601 | |
| 602 | except Exception as e: |
| 603 | self.log.exception('omci-setup-8021p-ani-port-delete', e=e) |
| 604 | raise |
| 605 | |