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