blob: 23cd83d0335bb16f31fd5af6fcc550921d174602 [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
Girish Gowdraa73ee452019-12-20 18:52:17 +053074 self._tp_id = tp_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050075 self._results = None
76 self._local_deferred = None
77 self._config = self._device.configuration
78
Matt Jeanneret810148b2019-09-29 12:44:01 -040079 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050091 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 Jeanneret810148b2019-09-29 12:44:01 -0400116 ################################################################################
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 Jeanneret31509ec2019-12-20 14:57:53 -0500125
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500126 # Delete bridge ani side vlan filter
Girish Gowdraa73ee452019-12-20 18:52:17 +0530127 eid = self._mac_bridge_port_ani_entity_id + self._uni_port.entity_id + self._tp_id # Entity ID
Matt Jeanneret2e5c6f12019-12-13 07:06:06 -0500128 msg = VlanTaggingFilterDataFrame(eid)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500129 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 Jeanneret810148b2019-09-29 12:44:01 -0400135 ################################################################################
136 # Create Extended VLAN Tagging Operation config (UNI-side)
137 #
Matt Jeanneret31509ec2019-12-20 14:57:53 -0500138 # 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 Jeanneret810148b2019-09-29 12:44:01 -0400142 # References:
Matt Jeanneret810148b2019-09-29 12:44:01 -0400143 # - PPTP Ethernet or VEIP UNI
144 #
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500145
Matt Jeanneret31509ec2019-12-20 14:57:53 -0500146
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 Jeanneret810148b2019-09-29 12:44:01 -0400187 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 Scac56952020-01-16 15:50:08 -0500206 # Onu-Transparent
Matt Jeanneret810148b2019-09-29 12:44:01 -0400207 if self._set_vlan_id == RESERVED_TRANSPARENT_VLAN:
Harsh Awasthib10a7082019-08-26 02:17:33 -0400208 # Transparently send any single tagged packet.
Chaitrashree G Scac56952020-01-16 15:50:08 -0500209 # 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 Awasthib10a7082019-08-26 02:17:33 -0400211 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500229 )
Chaitrashree G Scac56952020-01-16 15:50:08 -0500230
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 Awasthib10a7082019-08-26 02:17:33 -0400242 else:
Chaitrashree G Scac56952020-01-16 15:50:08 -0500243 # 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 Awasthib10a7082019-08-26 02:17:33 -0400256 # Update uni side extended vlan filter
257 # filter for untagged
Harsh Awasthib10a7082019-08-26 02:17:33 -0400258 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 Scac56952020-01-16 15:50:08 -0500278 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
279 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
280 attributes=attributes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500281 )
Chaitrashree G Scac56952020-01-16 15:50:08 -0500282
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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500322
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 Jeannerete8fc53e2019-04-13 15:58:33 -0400345 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500346 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 Awasthib10a7082019-08-26 02:17:33 -0400355