blob: 20ec8e8ca4b3e7cc4a687838c7b7711bd3492c0b [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
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 Jeanneret810148b2019-09-29 12:44:01 -040016
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050017from __future__ import absolute_import
Matt Jeanneret810148b2019-09-29 12:44:01 -040018import structlog
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050019from pyvoltha.adapters.extensions.omci.tasks.task import Task
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050020from twisted.internet import reactor
21from twisted.internet.defer import inlineCallbacks, failure, returnValue
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050022from pyvoltha.adapters.extensions.omci.omci_defs import ReasonCodes, EntityOperations
Matt Jeanneret810148b2019-09-29 12:44:01 -040023from pyvoltha.adapters.extensions.omci.omci_me import \
24 VlanTaggingOperation, VlanTaggingFilterDataFrame, ExtendedVlanTaggingOperationConfigurationDataFrame
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050025from uni_port import UniType
26from pon_port import DEFAULT_TPID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050027
28RC = ReasonCodes
29OP = EntityOperations
Matt Jeanneret810148b2019-09-29 12:44:01 -040030RESERVED_TRANSPARENT_VLAN = 4095
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050031
32
33class BrcmVlanFilterException(Exception):
34 pass
35
36
37class 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 Jeanneret810148b2019-09-29 12:44:01 -040042 name = "Broadcom VLAN Filter/Tagging Task"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050043
Mahir Gunyeld680cb62020-02-18 10:28:12 -080044 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050047 """
48 Class initialization
49
50 :param omci_agent: (OmciAdapterAgent) OMCI Adapter agent
Matt Jeanneret810148b2019-09-29 12:44:01 -040051 :param handler: (BrcmOpenomciOnuHandler) ONU Device Handler Instance
52 :param uni_port: (UniPort) Object instance representing the uni port and its settings
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050053 :param set_vlan_id: (int) VLAN to filter for and set
Girish Gowdraa73ee452019-12-20 18:52:17 +053054 :param tp_id: (int) TP ID for the flow
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050055 :param priority: (int) OpenOMCI Task priority (0..255) 255 is the highest
56 """
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050057 super(BrcmVlanFilterTask, self).__init__(BrcmVlanFilterTask.name,
58 omci_agent,
Matt Jeanneret810148b2019-09-29 12:44:01 -040059 handler.device_id,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050060 priority=priority,
61 exclusive=True)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050062
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 Jeanneret810148b2019-09-29 12:44:01 -040071 self._device = omci_agent.get_device(handler.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050072 self._uni_port = uni_port
73 self._set_vlan_id = set_vlan_id
Mahir Gunyela982ec32020-02-25 12:30:37 -080074 self._set_vlan_pcp = set_vlan_pcp
75 self._match_vlan = match_vlan
76 self._add_tag = add_tag
Girish Gowdraa73ee452019-12-20 18:52:17 +053077 self._tp_id = tp_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050078 self._results = None
79 self._local_deferred = None
80 self._config = self._device.configuration
81
Matt Jeanneret810148b2019-09-29 12:44:01 -040082 self._input_tpid = DEFAULT_TPID
83 self._output_tpid = DEFAULT_TPID
84
85 self._mac_bridge_service_profile_entity_id = \
86 handler.mac_bridge_service_profile_entity_id
87 self._ieee_mapper_service_profile_entity_id = \
88 handler.pon_port.ieee_mapper_service_profile_entity_id
89 self._mac_bridge_port_ani_entity_id = \
90 handler.pon_port.mac_bridge_port_ani_entity_id
91 self._gal_enet_profile_entity_id = \
92 handler.gal_enet_profile_entity_id
93
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050094 def cancel_deferred(self):
95 super(BrcmVlanFilterTask, self).cancel_deferred()
96
97 d, self._local_deferred = self._local_deferred, None
98 try:
99 if d is not None and not d.called:
100 d.cancel()
101 except:
102 pass
103
104 def start(self):
105 """
106 Start Vlan Tagging Task
107 """
108 super(BrcmVlanFilterTask, self).start()
109 self._local_deferred = reactor.callLater(0, self.perform_vlan_tagging)
110
111 @inlineCallbacks
112 def perform_vlan_tagging(self):
113 """
114 Perform the vlan tagging
115 """
Mahir Gunyela982ec32020-02-25 12:30:37 -0800116 self.log.debug('vlan-filter-tagging-task', device_id=self._device._device_id, uni_port=self._uni_port, set_vlan_id=self._set_vlan_id, \
117 set_vlan_pcp=self._set_vlan_pcp, match_vlan=self._match_vlan, tp_id=self._tp_id, add_tag=self._add_tag)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500118
119 try:
Mahir Gunyela982ec32020-02-25 12:30:37 -0800120 if self._add_tag:
121 ################################################################################
122 # VLAN Tagging Filter config
123 #
124 # EntityID will be referenced by:
125 # - Nothing
126 # References:
127 # - MacBridgePortConfigurationData for the ANI/PON side
128 #
Matt Jeanneret810148b2019-09-29 12:44:01 -0400129
Matt Jeanneret31509ec2019-12-20 14:57:53 -0500130
Mahir Gunyela982ec32020-02-25 12:30:37 -0800131 # Delete bridge ani side vlan filter
132 eid = self._mac_bridge_port_ani_entity_id + self._uni_port.entity_id + self._tp_id # Entity ID
133 msg = VlanTaggingFilterDataFrame(eid)
134 frame = msg.delete()
135 self.log.debug('openomci-msg', omci_msg=msg)
136 self.strobe_watchdog()
137 results = yield self._device.omci_cc.send(frame)
138 self.check_status_and_state(results, 'flow-delete-vlan-tagging-filter-data')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500139
Mahir Gunyela982ec32020-02-25 12:30:37 -0800140 ################################################################################
141 # Create Extended VLAN Tagging Operation config (UNI-side)
142 #
143 # EntityID relates to the VLAN TCIS later used int vlan filter task. This only
144 # sets up the inital MIB entry as it relates to port config, it does not set vlan
145 # that is saved for the vlan filter task
146 #
147 # References:
148 # - PPTP Ethernet or VEIP UNI
149 #
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500150
Matt Jeanneret31509ec2019-12-20 14:57:53 -0500151
Mahir Gunyela982ec32020-02-25 12:30:37 -0800152 # Delete uni side evto
153 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
154 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num,
155 )
156 frame = msg.delete()
157 self.log.debug('openomci-msg', omci_msg=msg)
158 results = yield self._device.omci_cc.send(frame)
159 self.check_status_and_state(results, 'delete-extended-vlan-tagging-operation-configuration-data')
Matt Jeanneret31509ec2019-12-20 14:57:53 -0500160
161
Mahir Gunyela982ec32020-02-25 12:30:37 -0800162 # Re-Create uni side evto
163 # default to PPTP
Matt Jeanneret31509ec2019-12-20 14:57:53 -0500164 association_type = 2
Mahir Gunyela982ec32020-02-25 12:30:37 -0800165 if self._uni_port.type.value == UniType.VEIP.value:
166 association_type = 10
167 elif self._uni_port.type.value == UniType.PPTP.value:
168 association_type = 2
Matt Jeanneret31509ec2019-12-20 14:57:53 -0500169
Harsh Awasthib10a7082019-08-26 02:17:33 -0400170 attributes = dict(
Mahir Gunyela982ec32020-02-25 12:30:37 -0800171 association_type=association_type, # Assoc Type, PPTP/VEIP Ethernet UNI
172 associated_me_pointer=self._uni_port.entity_id, # Assoc ME, PPTP/VEIP Entity Id
173
174 # See VOL-1311 - Need to set table during create to avoid exception
175 # trying to read back table during post-create-read-missing-attributes
176 # But, because this is a R/W attribute. Some ONU may not accept the
177 # value during create. It is repeated again in a set below.
178 input_tpid=self._input_tpid, # input TPID
179 output_tpid=self._output_tpid, # output TPID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500180 )
Chaitrashree G Scac56952020-01-16 15:50:08 -0500181
182 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
183 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
184 attributes=attributes
185 )
186
Chaitrashree G Scac56952020-01-16 15:50:08 -0500187 frame = msg.create()
188 self.log.debug('openomci-msg', omci_msg=msg)
Chaitrashree G Scac56952020-01-16 15:50:08 -0500189 results = yield self._device.omci_cc.send(frame)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800190 self.check_status_and_state(results, 'create-extended-vlan-tagging-operation-configuration-data')
191
Harsh Awasthib10a7082019-08-26 02:17:33 -0400192 attributes = dict(
Mahir Gunyela982ec32020-02-25 12:30:37 -0800193 # Specifies the TPIDs in use and that operations in the downstream direction are
194 # inverse to the operations in the upstream direction
195 input_tpid=self._input_tpid, # input TPID
196 output_tpid=self._output_tpid, # output TPID
197 downstream_mode=0, # inverse of upstream
Harsh Awasthib10a7082019-08-26 02:17:33 -0400198 )
199
Chaitrashree G Scac56952020-01-16 15:50:08 -0500200 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
201 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
202 attributes=attributes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500203 )
Chaitrashree G Scac56952020-01-16 15:50:08 -0500204
205 frame = msg.set()
206 self.log.debug('openomci-msg', omci_msg=msg)
207 self.strobe_watchdog()
208 results = yield self._device.omci_cc.send(frame)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800209 self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data')
Chaitrashree G Scac56952020-01-16 15:50:08 -0500210
Mahir Gunyela982ec32020-02-25 12:30:37 -0800211 # Onu-Transparent
212 if self._set_vlan_id == RESERVED_TRANSPARENT_VLAN:
213 # Transparently send any single tagged packet.
214 # As the onu is to be transparent, no need to create VlanTaggingFilterData ME.
215 # Any other specific rules will take priority over this, so not setting any other vlan specific rules
216 attributes = dict(
217 received_frame_vlan_tagging_operation_table=
218 VlanTaggingOperation(
219 filter_outer_priority=15,
220 filter_outer_vid=4096,
221 filter_outer_tpid_de=0,
222 filter_inner_priority=14,
223 filter_inner_vid=4096,
224 filter_inner_tpid_de=0,
225 filter_ether_type=0,
226 treatment_tags_to_remove=0,
227 treatment_outer_priority=15,
228 treatment_outer_vid=0,
229 treatment_outer_tpid_de=0,
230 treatment_inner_priority=15,
231 treatment_inner_vid=0,
232 treatment_inner_tpid_de=4
233 )
Chaitrashree G Scac56952020-01-16 15:50:08 -0500234 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500235
Mahir Gunyela982ec32020-02-25 12:30:37 -0800236 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
237 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
238 attributes=attributes
239 )
240
241 frame = msg.set()
242 self.log.debug('openomci-msg', omci_msg=msg)
243 self.strobe_watchdog()
244 results = yield self._device.omci_cc.send(frame)
245 self.check_status_and_state(results, 'set-evto-table-transparent-vlan')
246
247 else:
248 # Re-Create bridge ani side vlan filter
249 forward_operation = 0x10 # VID investigation
250
251 msg = VlanTaggingFilterDataFrame(
252 eid,
253 vlan_tcis=[self._set_vlan_id], # VLAN IDs
254 forward_operation=forward_operation
255 )
256 frame = msg.create()
257 self.log.debug('openomci-msg', omci_msg=msg)
258 self.strobe_watchdog()
259 results = yield self._device.omci_cc.send(frame)
260 self.check_status_and_state(results, 'flow-create-vlan-tagging-filter-data')
261 # Update uni side extended vlan filter
262 # filter for untagged
263 attributes = dict(
264 received_frame_vlan_tagging_operation_table=
265 VlanTaggingOperation(
266 filter_outer_priority=15,
267 filter_outer_vid=4096,
268 filter_outer_tpid_de=0,
269 filter_inner_priority=15,
270 filter_inner_vid=4096,
271 filter_inner_tpid_de=0,
272 filter_ether_type=0,
273 treatment_tags_to_remove=0,
274 treatment_outer_priority=15,
275 treatment_outer_vid=0,
276 treatment_outer_tpid_de=0,
277 treatment_inner_priority=0,
278 treatment_inner_vid=self._set_vlan_id,
279 treatment_inner_tpid_de=4
280 )
281 )
282
283 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
284 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
285 attributes=attributes
286 )
287
288 frame = msg.set()
289 self.log.debug('openomci-msg', omci_msg=msg)
290 self.strobe_watchdog()
291 results = yield self._device.omci_cc.send(frame)
292 self.check_status_and_state(results, 'set-evto-table-untagged')
293
294 # Update uni side extended vlan filter
295 # filter for vlan 0
296 attributes = dict(
297 received_frame_vlan_tagging_operation_table=
298 VlanTaggingOperation(
299 filter_outer_priority=15, # This entry is not a double-tag rule
300 filter_outer_vid=4096, # Do not filter on the outer VID value
301 filter_outer_tpid_de=0, # Do not filter on the outer TPID field
302
303 filter_inner_priority=8, # Filter on inner vlan
304 filter_inner_vid=0x0, # Look for vlan 0
305 filter_inner_tpid_de=0, # Do not filter on inner TPID field
306 filter_ether_type=0, # Do not filter on EtherType
307
308 treatment_tags_to_remove=1,
309 treatment_outer_priority=15,
310 treatment_outer_vid=0,
311 treatment_outer_tpid_de=0,
312
313 treatment_inner_priority=8, # Add an inner tag and insert this value as the priority
314 treatment_inner_vid=self._set_vlan_id, # use this value as the VID in the inner VLAN tag
315 treatment_inner_tpid_de=4, # set TPID
316 )
317 )
318 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
319 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
320 attributes=attributes # See above
321 )
322 frame = msg.set()
323 self.log.debug('openomci-msg', omci_msg=msg)
324 self.strobe_watchdog()
325 results = yield self._device.omci_cc.send(frame)
326 self.check_status_and_state(results, 'set-evto-table-zero-tagged')
327
328 else: #addTag = False
329 #TODO: needs to be implemented - future task.
330 self.log.debug('removing-vlan-filter-tag', uni_port=self._uni_port, match_vlan=self._match_vlan, )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500331 self.deferred.callback(self)
332
333 except Exception as e:
334 self.log.exception('setting-vlan-tagging', e=e)
335 self.deferred.errback(failure.Failure(e))
336
337 def check_status_and_state(self, results, operation=''):
338 """
339 Check the results of an OMCI response. An exception is thrown
340 if the task was cancelled or an error was detected.
341
342 :param results: (OmciFrame) OMCI Response frame
343 :param operation: (str) what operation was being performed
344 :return: True if successful, False if the entity existed (already created)
345 """
346
347 omci_msg = results.fields['omci_message'].fields
348 status = omci_msg['success_code']
349 error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
350 failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
351 unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
352
Matt Jeannerete8fc53e2019-04-13 15:58:33 -0400353 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500354 status=status, error_mask=error_mask,
355 failed_mask=failed_mask, unsupported_mask=unsupported_mask)
356
357 if status == RC.Success:
358 self.strobe_watchdog()
359 return True
360
361 elif status == RC.InstanceExists:
362 return False
Harsh Awasthib10a7082019-08-26 02:17:33 -0400363