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