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 | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 117 | # Delete bridge ani side vlan filter |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 118 | # TODO: check if its in our local mib first before blindly deleting |
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 | |
| 127 | # Re-Create bridge ani side vlan filter |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 128 | # TODO: check if its in our local mib first before blindly recreating |
| 129 | forward_operation = 0x10 # VID investigation |
| 130 | # When the PUSH VLAN is RESERVED_VLAN (4095), let ONU be transparent |
| 131 | if self._set_vlan_id == RESERVED_TRANSPARENT_VLAN: |
| 132 | forward_operation = 0x00 # no investigation, ONU transparent |
| 133 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 134 | msg = VlanTaggingFilterDataFrame( |
Matt Jeanneret | 2e5c6f1 | 2019-12-13 07:06:06 -0500 | [diff] [blame] | 135 | eid, |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 136 | vlan_tcis=[self._set_vlan_id], # VLAN IDs |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 137 | forward_operation=forward_operation |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 138 | ) |
| 139 | frame = msg.create() |
| 140 | self.log.debug('openomci-msg', omci_msg=msg) |
| 141 | self.strobe_watchdog() |
| 142 | results = yield self._device.omci_cc.send(frame) |
| 143 | self.check_status_and_state(results, 'flow-create-vlan-tagging-filter-data') |
| 144 | |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 145 | ################################################################################ |
| 146 | # Create Extended VLAN Tagging Operation config (UNI-side) |
| 147 | # |
| 148 | # EntityID relates to the VLAN TCIS |
| 149 | # References: |
| 150 | # - VLAN TCIS from previously created VLAN Tagging filter data |
| 151 | # - PPTP Ethernet or VEIP UNI |
| 152 | # |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 153 | |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 154 | attributes = dict( |
| 155 | # Specifies the TPIDs in use and that operations in the downstream direction are |
| 156 | # inverse to the operations in the upstream direction |
| 157 | input_tpid=self._input_tpid, # input TPID |
| 158 | output_tpid=self._output_tpid, # output TPID |
| 159 | downstream_mode=0, # inverse of upstream |
| 160 | ) |
| 161 | |
| 162 | msg = ExtendedVlanTaggingOperationConfigurationDataFrame( |
| 163 | self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID |
| 164 | attributes=attributes |
| 165 | ) |
| 166 | |
| 167 | frame = msg.set() |
| 168 | self.log.debug('openomci-msg', omci_msg=msg) |
| 169 | self.strobe_watchdog() |
| 170 | results = yield self._device.omci_cc.send(frame) |
| 171 | self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data') |
| 172 | |
| 173 | if self._set_vlan_id == RESERVED_TRANSPARENT_VLAN: |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 174 | # Transparently send any single tagged packet. |
| 175 | # Any other specific rules will take priority over this |
| 176 | attributes = dict( |
| 177 | received_frame_vlan_tagging_operation_table= |
| 178 | VlanTaggingOperation( |
| 179 | filter_outer_priority=15, |
| 180 | filter_outer_vid=4096, |
| 181 | filter_outer_tpid_de=0, |
| 182 | filter_inner_priority=14, |
| 183 | filter_inner_vid=4096, |
| 184 | filter_inner_tpid_de=0, |
| 185 | filter_ether_type=0, |
| 186 | treatment_tags_to_remove=0, |
| 187 | treatment_outer_priority=15, |
| 188 | treatment_outer_vid=0, |
| 189 | treatment_outer_tpid_de=0, |
| 190 | treatment_inner_priority=15, |
| 191 | treatment_inner_vid=0, |
| 192 | treatment_inner_tpid_de=4 |
| 193 | ) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 194 | ) |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 195 | else: |
| 196 | # Update uni side extended vlan filter |
| 197 | # filter for untagged |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 198 | attributes = dict( |
| 199 | received_frame_vlan_tagging_operation_table= |
| 200 | VlanTaggingOperation( |
| 201 | filter_outer_priority=15, |
| 202 | filter_outer_vid=4096, |
| 203 | filter_outer_tpid_de=0, |
| 204 | filter_inner_priority=15, |
| 205 | filter_inner_vid=4096, |
| 206 | filter_inner_tpid_de=0, |
| 207 | filter_ether_type=0, |
| 208 | treatment_tags_to_remove=0, |
| 209 | treatment_outer_priority=15, |
| 210 | treatment_outer_vid=0, |
| 211 | treatment_outer_tpid_de=0, |
| 212 | treatment_inner_priority=0, |
| 213 | treatment_inner_vid=self._set_vlan_id, |
| 214 | treatment_inner_tpid_de=4 |
| 215 | ) |
| 216 | ) |
| 217 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 218 | msg = ExtendedVlanTaggingOperationConfigurationDataFrame( |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 219 | self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID |
| 220 | attributes=attributes |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 221 | ) |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 222 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 223 | frame = msg.set() |
| 224 | self.log.debug('openomci-msg', omci_msg=msg) |
| 225 | self.strobe_watchdog() |
| 226 | results = yield self._device.omci_cc.send(frame) |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 227 | self.check_status_and_state(results, 'set-evto-table') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 228 | |
| 229 | # Update uni side extended vlan filter |
| 230 | # filter for vlan 0 |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 231 | attributes = dict( |
| 232 | received_frame_vlan_tagging_operation_table= |
| 233 | VlanTaggingOperation( |
| 234 | filter_outer_priority=15, # This entry is not a double-tag rule |
| 235 | filter_outer_vid=4096, # Do not filter on the outer VID value |
| 236 | filter_outer_tpid_de=0, # Do not filter on the outer TPID field |
| 237 | |
| 238 | filter_inner_priority=8, # Filter on inner vlan |
| 239 | filter_inner_vid=0x0, # Look for vlan 0 |
| 240 | filter_inner_tpid_de=0, # Do not filter on inner TPID field |
| 241 | filter_ether_type=0, # Do not filter on EtherType |
| 242 | |
| 243 | treatment_tags_to_remove=1, |
| 244 | treatment_outer_priority=15, |
| 245 | treatment_outer_vid=0, |
| 246 | treatment_outer_tpid_de=0, |
| 247 | |
| 248 | treatment_inner_priority=8, # Add an inner tag and insert this value as the priority |
| 249 | treatment_inner_vid=self._set_vlan_id, # use this value as the VID in the inner VLAN tag |
| 250 | treatment_inner_tpid_de=4, # set TPID |
| 251 | ) |
| 252 | ) |
| 253 | msg = ExtendedVlanTaggingOperationConfigurationDataFrame( |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 254 | self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 255 | attributes=attributes # See above |
| 256 | ) |
| 257 | frame = msg.set() |
| 258 | self.log.debug('openomci-msg', omci_msg=msg) |
| 259 | self.strobe_watchdog() |
| 260 | results = yield self._device.omci_cc.send(frame) |
Matt Jeanneret | 810148b | 2019-09-29 12:44:01 -0400 | [diff] [blame] | 261 | self.check_status_and_state(results, 'set-evto-table-zero-tagged') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 262 | |
| 263 | self.deferred.callback(self) |
| 264 | |
| 265 | except Exception as e: |
| 266 | self.log.exception('setting-vlan-tagging', e=e) |
| 267 | self.deferred.errback(failure.Failure(e)) |
| 268 | |
| 269 | def check_status_and_state(self, results, operation=''): |
| 270 | """ |
| 271 | Check the results of an OMCI response. An exception is thrown |
| 272 | if the task was cancelled or an error was detected. |
| 273 | |
| 274 | :param results: (OmciFrame) OMCI Response frame |
| 275 | :param operation: (str) what operation was being performed |
| 276 | :return: True if successful, False if the entity existed (already created) |
| 277 | """ |
| 278 | |
| 279 | omci_msg = results.fields['omci_message'].fields |
| 280 | status = omci_msg['success_code'] |
| 281 | error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a') |
| 282 | failed_mask = omci_msg.get('failed_attributes_mask', 'n/a') |
| 283 | unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a') |
| 284 | |
Matt Jeanneret | e8fc53e | 2019-04-13 15:58:33 -0400 | [diff] [blame] | 285 | self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg, |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 286 | status=status, error_mask=error_mask, |
| 287 | failed_mask=failed_mask, unsupported_mask=unsupported_mask) |
| 288 | |
| 289 | if status == RC.Success: |
| 290 | self.strobe_watchdog() |
| 291 | return True |
| 292 | |
| 293 | elif status == RC.InstanceExists: |
| 294 | return False |
Harsh Awasthi | b10a708 | 2019-08-26 02:17:33 -0400 | [diff] [blame] | 295 | |