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 | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 16 | |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 17 | from __future__ import absolute_import |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 18 | import structlog |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 19 | from pyvoltha.adapters.extensions.omci.tasks.task import Task |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 20 | from twisted.internet import reactor |
| 21 | from twisted.internet.defer import inlineCallbacks, failure, returnValue |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 22 | from pyvoltha.adapters.extensions.omci.omci_defs import ReasonCodes, EntityOperations |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 23 | from pyvoltha.adapters.extensions.omci.omci_me import \ |
| 24 | VlanTaggingOperation, VlanTaggingFilterDataFrame, ExtendedVlanTaggingOperationConfigurationDataFrame |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 25 | from uni_port import UniType |
| 26 | from pon_port import DEFAULT_TPID |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 27 | |
| 28 | RC = ReasonCodes |
| 29 | OP = EntityOperations |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 30 | RESERVED_TRANSPARENT_VLAN = 4095 |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 31 | |
| 32 | |
| 33 | class BrcmVlanFilterException(Exception): |
| 34 | pass |
| 35 | |
| 36 | |
| 37 | class BrcmVlanFilterTask(Task): |
| 38 | """ |
| 39 | Apply Vlan Tagging Filter Data and Extended VLAN Tagging Operation Configuration on an ANI and UNI |
| 40 | """ |
| 41 | task_priority = 200 |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 42 | name = "Broadcom VLAN Filter/Tagging Task" |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 43 | |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 44 | def __init__(self, omci_agent, handler, uni_port, set_vlan_id, tp_id, priority=task_priority): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 45 | """ |
| 46 | Class initialization |
| 47 | |
| 48 | :param omci_agent: (OmciAdapterAgent) OMCI Adapter agent |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 49 | :param handler: (BrcmOpenomciOnuHandler) ONU Device Handler Instance |
| 50 | :param uni_port: (UniPort) Object instance representing the uni port and its settings |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 51 | :param set_vlan_id: (int) VLAN to filter for and set |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 52 | :param tp_id: (int) TP ID for the flow |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 53 | :param priority: (int) OpenOMCI Task priority (0..255) 255 is the highest |
| 54 | """ |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 55 | super(BrcmVlanFilterTask, self).__init__(BrcmVlanFilterTask.name, |
| 56 | omci_agent, |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 57 | handler.device_id, |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 58 | priority=priority, |
| 59 | exclusive=True) |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 60 | |
| 61 | self.log = structlog.get_logger(device_id=handler.device_id, |
| 62 | name=BrcmVlanFilterTask.name, |
| 63 | task_id=self._task_id, |
| 64 | entity_id=uni_port.entity_id, |
| 65 | uni_id=uni_port.uni_id, |
| 66 | uni_port=uni_port.port_number, |
| 67 | set_vlan_id=set_vlan_id) |
| 68 | |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 69 | self._device = omci_agent.get_device(handler.device_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 70 | self._uni_port = uni_port |
| 71 | self._set_vlan_id = set_vlan_id |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 72 | self._tp_id = tp_id |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 73 | self._results = None |
| 74 | self._local_deferred = None |
| 75 | self._config = self._device.configuration |
| 76 | |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 77 | self._input_tpid = DEFAULT_TPID |
| 78 | self._output_tpid = DEFAULT_TPID |
| 79 | |
| 80 | self._mac_bridge_service_profile_entity_id = \ |
| 81 | handler.mac_bridge_service_profile_entity_id |
| 82 | self._ieee_mapper_service_profile_entity_id = \ |
| 83 | handler.pon_port.ieee_mapper_service_profile_entity_id |
| 84 | self._mac_bridge_port_ani_entity_id = \ |
| 85 | handler.pon_port.mac_bridge_port_ani_entity_id |
| 86 | self._gal_enet_profile_entity_id = \ |
| 87 | handler.gal_enet_profile_entity_id |
| 88 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 89 | def cancel_deferred(self): |
| 90 | super(BrcmVlanFilterTask, self).cancel_deferred() |
| 91 | |
| 92 | d, self._local_deferred = self._local_deferred, None |
| 93 | try: |
| 94 | if d is not None and not d.called: |
| 95 | d.cancel() |
| 96 | except: |
| 97 | pass |
| 98 | |
| 99 | def start(self): |
| 100 | """ |
| 101 | Start Vlan Tagging Task |
| 102 | """ |
| 103 | super(BrcmVlanFilterTask, self).start() |
| 104 | self._local_deferred = reactor.callLater(0, self.perform_vlan_tagging) |
| 105 | |
| 106 | @inlineCallbacks |
| 107 | def perform_vlan_tagging(self): |
| 108 | """ |
| 109 | Perform the vlan tagging |
| 110 | """ |
| 111 | self.log.info('setting-vlan-tagging') |
| 112 | |
| 113 | try: |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 114 | ################################################################################ |
| 115 | # VLAN Tagging Filter config |
| 116 | # |
| 117 | # EntityID will be referenced by: |
| 118 | # - Nothing |
| 119 | # References: |
| 120 | # - MacBridgePortConfigurationData for the ANI/PON side |
| 121 | # |
| 122 | |
Matt Jeanneret | 31509ec | 2019-12-20 14:57:53 -0500 | [diff] [blame] | 123 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 124 | # Delete bridge ani side vlan filter |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 125 | eid = self._mac_bridge_port_ani_entity_id + self._uni_port.entity_id + self._tp_id # Entity ID |
Matt Jeanneret | 2e5c6f1 | 2019-12-13 07:06:06 -0500 | [diff] [blame] | 126 | msg = VlanTaggingFilterDataFrame(eid) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 127 | frame = msg.delete() |
| 128 | self.log.debug('openomci-msg', omci_msg=msg) |
| 129 | self.strobe_watchdog() |
| 130 | results = yield self._device.omci_cc.send(frame) |
| 131 | self.check_status_and_state(results, 'flow-delete-vlan-tagging-filter-data') |
| 132 | |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 133 | ################################################################################ |
| 134 | # Create Extended VLAN Tagging Operation config (UNI-side) |
| 135 | # |
Matt Jeanneret | 31509ec | 2019-12-20 14:57:53 -0500 | [diff] [blame] | 136 | # EntityID relates to the VLAN TCIS later used int vlan filter task. This only |
| 137 | # sets up the inital MIB entry as it relates to port config, it does not set vlan |
| 138 | # that is saved for the vlan filter task |
| 139 | # |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 140 | # References: |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 141 | # - PPTP Ethernet or VEIP UNI |
| 142 | # |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 143 | |
Matt Jeanneret | 31509ec | 2019-12-20 14:57:53 -0500 | [diff] [blame] | 144 | |
| 145 | # Delete uni side evto |
| 146 | msg = ExtendedVlanTaggingOperationConfigurationDataFrame( |
| 147 | self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, |
| 148 | ) |
| 149 | frame = msg.delete() |
| 150 | self.log.debug('openomci-msg', omci_msg=msg) |
| 151 | results = yield self._device.omci_cc.send(frame) |
| 152 | self.check_status_and_state(results, 'delete-extended-vlan-tagging-operation-configuration-data') |
| 153 | |
| 154 | |
| 155 | # Re-Create uni side evto |
| 156 | # default to PPTP |
| 157 | association_type = 2 |
| 158 | if self._uni_port.type.value == UniType.VEIP.value: |
| 159 | association_type = 10 |
| 160 | elif self._uni_port.type.value == UniType.PPTP.value: |
| 161 | association_type = 2 |
| 162 | |
| 163 | attributes = dict( |
| 164 | association_type=association_type, # Assoc Type, PPTP/VEIP Ethernet UNI |
| 165 | associated_me_pointer=self._uni_port.entity_id, # Assoc ME, PPTP/VEIP Entity Id |
| 166 | |
| 167 | # See VOL-1311 - Need to set table during create to avoid exception |
| 168 | # trying to read back table during post-create-read-missing-attributes |
| 169 | # But, because this is a R/W attribute. Some ONU may not accept the |
| 170 | # value during create. It is repeated again in a set below. |
| 171 | input_tpid=self._input_tpid, # input TPID |
| 172 | output_tpid=self._output_tpid, # output TPID |
| 173 | ) |
| 174 | |
| 175 | msg = ExtendedVlanTaggingOperationConfigurationDataFrame( |
| 176 | self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID |
| 177 | attributes=attributes |
| 178 | ) |
| 179 | |
| 180 | frame = msg.create() |
| 181 | self.log.debug('openomci-msg', omci_msg=msg) |
| 182 | results = yield self._device.omci_cc.send(frame) |
| 183 | self.check_status_and_state(results, 'create-extended-vlan-tagging-operation-configuration-data') |
| 184 | |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 185 | attributes = dict( |
| 186 | # Specifies the TPIDs in use and that operations in the downstream direction are |
| 187 | # inverse to the operations in the upstream direction |
| 188 | input_tpid=self._input_tpid, # input TPID |
| 189 | output_tpid=self._output_tpid, # output TPID |
| 190 | downstream_mode=0, # inverse of upstream |
| 191 | ) |
| 192 | |
| 193 | msg = ExtendedVlanTaggingOperationConfigurationDataFrame( |
| 194 | self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID |
| 195 | attributes=attributes |
| 196 | ) |
| 197 | |
| 198 | frame = msg.set() |
| 199 | self.log.debug('openomci-msg', omci_msg=msg) |
| 200 | self.strobe_watchdog() |
| 201 | results = yield self._device.omci_cc.send(frame) |
| 202 | self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data') |
| 203 | |
Chaitrashree G S | cac5695 | 2020-01-16 15:50:08 -0500 | [diff] [blame] | 204 | # Onu-Transparent |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 205 | if self._set_vlan_id == RESERVED_TRANSPARENT_VLAN: |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 206 | # Transparently send any single tagged packet. |
Chaitrashree G S | cac5695 | 2020-01-16 15:50:08 -0500 | [diff] [blame] | 207 | # As the onu is to be transparent, no need to create VlanTaggingFilterData ME. |
| 208 | # Any other specific rules will take priority over this, so not setting any other vlan specific rules |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 209 | attributes = dict( |
| 210 | received_frame_vlan_tagging_operation_table= |
| 211 | VlanTaggingOperation( |
| 212 | filter_outer_priority=15, |
| 213 | filter_outer_vid=4096, |
| 214 | filter_outer_tpid_de=0, |
| 215 | filter_inner_priority=14, |
| 216 | filter_inner_vid=4096, |
| 217 | filter_inner_tpid_de=0, |
| 218 | filter_ether_type=0, |
| 219 | treatment_tags_to_remove=0, |
| 220 | treatment_outer_priority=15, |
| 221 | treatment_outer_vid=0, |
| 222 | treatment_outer_tpid_de=0, |
| 223 | treatment_inner_priority=15, |
| 224 | treatment_inner_vid=0, |
| 225 | treatment_inner_tpid_de=4 |
| 226 | ) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 227 | ) |
Chaitrashree G S | cac5695 | 2020-01-16 15:50:08 -0500 | [diff] [blame] | 228 | |
| 229 | msg = ExtendedVlanTaggingOperationConfigurationDataFrame( |
| 230 | self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID |
| 231 | attributes=attributes |
| 232 | ) |
| 233 | |
| 234 | frame = msg.set() |
| 235 | self.log.debug('openomci-msg', omci_msg=msg) |
| 236 | self.strobe_watchdog() |
| 237 | results = yield self._device.omci_cc.send(frame) |
| 238 | self.check_status_and_state(results, 'set-evto-table-transparent-vlan') |
| 239 | |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 240 | else: |
Chaitrashree G S | cac5695 | 2020-01-16 15:50:08 -0500 | [diff] [blame] | 241 | # Re-Create bridge ani side vlan filter |
| 242 | forward_operation = 0x10 # VID investigation |
| 243 | |
| 244 | msg = VlanTaggingFilterDataFrame( |
| 245 | eid, |
| 246 | vlan_tcis=[self._set_vlan_id], # VLAN IDs |
| 247 | forward_operation=forward_operation |
| 248 | ) |
| 249 | frame = msg.create() |
| 250 | self.log.debug('openomci-msg', omci_msg=msg) |
| 251 | self.strobe_watchdog() |
| 252 | results = yield self._device.omci_cc.send(frame) |
| 253 | self.check_status_and_state(results, 'flow-create-vlan-tagging-filter-data') |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 254 | # Update uni side extended vlan filter |
| 255 | # filter for untagged |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 256 | attributes = dict( |
| 257 | received_frame_vlan_tagging_operation_table= |
| 258 | VlanTaggingOperation( |
| 259 | filter_outer_priority=15, |
| 260 | filter_outer_vid=4096, |
| 261 | filter_outer_tpid_de=0, |
| 262 | filter_inner_priority=15, |
| 263 | filter_inner_vid=4096, |
| 264 | filter_inner_tpid_de=0, |
| 265 | filter_ether_type=0, |
| 266 | treatment_tags_to_remove=0, |
| 267 | treatment_outer_priority=15, |
| 268 | treatment_outer_vid=0, |
| 269 | treatment_outer_tpid_de=0, |
| 270 | treatment_inner_priority=0, |
| 271 | treatment_inner_vid=self._set_vlan_id, |
| 272 | treatment_inner_tpid_de=4 |
| 273 | ) |
| 274 | ) |
| 275 | |
Chaitrashree G S | cac5695 | 2020-01-16 15:50:08 -0500 | [diff] [blame] | 276 | msg = ExtendedVlanTaggingOperationConfigurationDataFrame( |
| 277 | self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID |
| 278 | attributes=attributes |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 279 | ) |
Chaitrashree G S | cac5695 | 2020-01-16 15:50:08 -0500 | [diff] [blame] | 280 | |
| 281 | frame = msg.set() |
| 282 | self.log.debug('openomci-msg', omci_msg=msg) |
| 283 | self.strobe_watchdog() |
| 284 | results = yield self._device.omci_cc.send(frame) |
| 285 | self.check_status_and_state(results, 'set-evto-table-untagged') |
| 286 | |
| 287 | # Update uni side extended vlan filter |
| 288 | # filter for vlan 0 |
| 289 | attributes = dict( |
| 290 | received_frame_vlan_tagging_operation_table= |
| 291 | VlanTaggingOperation( |
| 292 | filter_outer_priority=15, # This entry is not a double-tag rule |
| 293 | filter_outer_vid=4096, # Do not filter on the outer VID value |
| 294 | filter_outer_tpid_de=0, # Do not filter on the outer TPID field |
| 295 | |
| 296 | filter_inner_priority=8, # Filter on inner vlan |
| 297 | filter_inner_vid=0x0, # Look for vlan 0 |
| 298 | filter_inner_tpid_de=0, # Do not filter on inner TPID field |
| 299 | filter_ether_type=0, # Do not filter on EtherType |
| 300 | |
| 301 | treatment_tags_to_remove=1, |
| 302 | treatment_outer_priority=15, |
| 303 | treatment_outer_vid=0, |
| 304 | treatment_outer_tpid_de=0, |
| 305 | |
| 306 | treatment_inner_priority=8, # Add an inner tag and insert this value as the priority |
| 307 | treatment_inner_vid=self._set_vlan_id, # use this value as the VID in the inner VLAN tag |
| 308 | treatment_inner_tpid_de=4, # set TPID |
| 309 | ) |
| 310 | ) |
| 311 | msg = ExtendedVlanTaggingOperationConfigurationDataFrame( |
| 312 | self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID |
| 313 | attributes=attributes # See above |
| 314 | ) |
| 315 | frame = msg.set() |
| 316 | self.log.debug('openomci-msg', omci_msg=msg) |
| 317 | self.strobe_watchdog() |
| 318 | results = yield self._device.omci_cc.send(frame) |
| 319 | self.check_status_and_state(results, 'set-evto-table-zero-tagged') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 320 | |
| 321 | self.deferred.callback(self) |
| 322 | |
| 323 | except Exception as e: |
| 324 | self.log.exception('setting-vlan-tagging', e=e) |
| 325 | self.deferred.errback(failure.Failure(e)) |
| 326 | |
| 327 | def check_status_and_state(self, results, operation=''): |
| 328 | """ |
| 329 | Check the results of an OMCI response. An exception is thrown |
| 330 | if the task was cancelled or an error was detected. |
| 331 | |
| 332 | :param results: (OmciFrame) OMCI Response frame |
| 333 | :param operation: (str) what operation was being performed |
| 334 | :return: True if successful, False if the entity existed (already created) |
| 335 | """ |
| 336 | |
| 337 | omci_msg = results.fields['omci_message'].fields |
| 338 | status = omci_msg['success_code'] |
| 339 | error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a') |
| 340 | failed_mask = omci_msg.get('failed_attributes_mask', 'n/a') |
| 341 | unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a') |
| 342 | |
Matt Jeanneret | e8fc53e | 2019-04-13 15:58:33 -0400 | [diff] [blame] | 343 | self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg, |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 344 | status=status, error_mask=error_mask, |
| 345 | failed_mask=failed_mask, unsupported_mask=unsupported_mask) |
| 346 | |
| 347 | if status == RC.Success: |
| 348 | self.strobe_watchdog() |
| 349 | return True |
| 350 | |
| 351 | elif status == RC.InstanceExists: |
| 352 | return False |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 353 | |