blob: c11515907c0d61b50b263fc21deae1c731b2929b [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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500117 # Delete bridge ani side vlan filter
Matt Jeanneret810148b2019-09-29 12:44:01 -0400118 # TODO: check if its in our local mib first before blindly deleting
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
127 # Re-Create bridge ani side vlan filter
Matt Jeanneret810148b2019-09-29 12:44:01 -0400128 # 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500134 msg = VlanTaggingFilterDataFrame(
Matt Jeanneret2e5c6f12019-12-13 07:06:06 -0500135 eid,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500136 vlan_tcis=[self._set_vlan_id], # VLAN IDs
Harsh Awasthib10a7082019-08-26 02:17:33 -0400137 forward_operation=forward_operation
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500138 )
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 Jeanneret810148b2019-09-29 12:44:01 -0400145 ################################################################################
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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500153
Matt Jeanneret810148b2019-09-29 12:44:01 -0400154 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 Awasthib10a7082019-08-26 02:17:33 -0400174 # 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500194 )
Harsh Awasthib10a7082019-08-26 02:17:33 -0400195 else:
196 # Update uni side extended vlan filter
197 # filter for untagged
Harsh Awasthib10a7082019-08-26 02:17:33 -0400198 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500218 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
Matt Jeanneret810148b2019-09-29 12:44:01 -0400219 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
220 attributes=attributes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500221 )
Matt Jeanneret810148b2019-09-29 12:44:01 -0400222
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500223 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 Jeanneret810148b2019-09-29 12:44:01 -0400227 self.check_status_and_state(results, 'set-evto-table')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500228
229 # Update uni side extended vlan filter
230 # filter for vlan 0
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500231 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 Jeanneret810148b2019-09-29 12:44:01 -0400254 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500255 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 Jeanneret810148b2019-09-29 12:44:01 -0400261 self.check_status_and_state(results, 'set-evto-table-zero-tagged')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500262
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 Jeannerete8fc53e2019-04-13 15:58:33 -0400285 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500286 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 Awasthib10a7082019-08-26 02:17:33 -0400295