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