blob: deee94744e973ceeb1b92a92942bec52e45fa427 [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 """
55
Matt Jeanneret810148b2019-09-29 12:44:01 -040056 self.log = structlog.get_logger(device_id=handler.device_id, uni_port=uni_port.port_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050057
58 super(BrcmVlanFilterTask, self).__init__(BrcmVlanFilterTask.name,
59 omci_agent,
Matt Jeanneret810148b2019-09-29 12:44:01 -040060 handler.device_id,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050061 priority=priority,
62 exclusive=True)
Matt Jeanneret810148b2019-09-29 12:44:01 -040063 self._device = omci_agent.get_device(handler.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050064 self._uni_port = uni_port
65 self._set_vlan_id = set_vlan_id
Girish Gowdraa73ee452019-12-20 18:52:17 +053066 self._tp_id = tp_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050067 self._results = None
68 self._local_deferred = None
69 self._config = self._device.configuration
70
Matt Jeanneret810148b2019-09-29 12:44:01 -040071 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050083 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 Jeanneret810148b2019-09-29 12:44:01 -0400108 ################################################################################
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 Jeanneret31509ec2019-12-20 14:57:53 -0500117
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500118 # Delete bridge ani side vlan filter
Girish Gowdraa73ee452019-12-20 18:52:17 +0530119 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 -0500120 msg = VlanTaggingFilterDataFrame(eid)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500121 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 Jeanneret810148b2019-09-29 12:44:01 -0400127 ################################################################################
128 # Create Extended VLAN Tagging Operation config (UNI-side)
129 #
Matt Jeanneret31509ec2019-12-20 14:57:53 -0500130 # 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 Jeanneret810148b2019-09-29 12:44:01 -0400134 # References:
Matt Jeanneret810148b2019-09-29 12:44:01 -0400135 # - PPTP Ethernet or VEIP UNI
136 #
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500137
Matt Jeanneret31509ec2019-12-20 14:57:53 -0500138
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 Jeanneret810148b2019-09-29 12:44:01 -0400179 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 Scac56952020-01-16 15:50:08 -0500198 # Onu-Transparent
Matt Jeanneret810148b2019-09-29 12:44:01 -0400199 if self._set_vlan_id == RESERVED_TRANSPARENT_VLAN:
Harsh Awasthib10a7082019-08-26 02:17:33 -0400200 # Transparently send any single tagged packet.
Chaitrashree G Scac56952020-01-16 15:50:08 -0500201 # 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 Awasthib10a7082019-08-26 02:17:33 -0400203 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500221 )
Chaitrashree G Scac56952020-01-16 15:50:08 -0500222
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 Awasthib10a7082019-08-26 02:17:33 -0400234 else:
Chaitrashree G Scac56952020-01-16 15:50:08 -0500235 # 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 Awasthib10a7082019-08-26 02:17:33 -0400248 # Update uni side extended vlan filter
249 # filter for untagged
Harsh Awasthib10a7082019-08-26 02:17:33 -0400250 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 Scac56952020-01-16 15:50:08 -0500270 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
271 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
272 attributes=attributes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500273 )
Chaitrashree G Scac56952020-01-16 15:50:08 -0500274
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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500314
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 Jeannerete8fc53e2019-04-13 15:58:33 -0400337 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500338 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 Awasthib10a7082019-08-26 02:17:33 -0400347