blob: 258924775df05c5c5172d66984a661a148bc86b0 [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
Matt Jeanneret810148b2019-09-29 12:44:01 -040044 def __init__(self, omci_agent, handler, uni_port, set_vlan_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
52 :param priority: (int) OpenOMCI Task priority (0..255) 255 is the highest
53 """
54
Matt Jeanneret810148b2019-09-29 12:44:01 -040055 self.log = structlog.get_logger(device_id=handler.device_id, uni_port=uni_port.port_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050056
57 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 Jeanneret810148b2019-09-29 12:44:01 -040062 self._device = omci_agent.get_device(handler.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050063 self._uni_port = uni_port
64 self._set_vlan_id = set_vlan_id
65 self._results = None
66 self._local_deferred = None
67 self._config = self._device.configuration
68
Matt Jeanneret810148b2019-09-29 12:44:01 -040069 self._input_tpid = DEFAULT_TPID
70 self._output_tpid = DEFAULT_TPID
71
72 self._mac_bridge_service_profile_entity_id = \
73 handler.mac_bridge_service_profile_entity_id
74 self._ieee_mapper_service_profile_entity_id = \
75 handler.pon_port.ieee_mapper_service_profile_entity_id
76 self._mac_bridge_port_ani_entity_id = \
77 handler.pon_port.mac_bridge_port_ani_entity_id
78 self._gal_enet_profile_entity_id = \
79 handler.gal_enet_profile_entity_id
80
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050081 def cancel_deferred(self):
82 super(BrcmVlanFilterTask, self).cancel_deferred()
83
84 d, self._local_deferred = self._local_deferred, None
85 try:
86 if d is not None and not d.called:
87 d.cancel()
88 except:
89 pass
90
91 def start(self):
92 """
93 Start Vlan Tagging Task
94 """
95 super(BrcmVlanFilterTask, self).start()
96 self._local_deferred = reactor.callLater(0, self.perform_vlan_tagging)
97
98 @inlineCallbacks
99 def perform_vlan_tagging(self):
100 """
101 Perform the vlan tagging
102 """
103 self.log.info('setting-vlan-tagging')
104
105 try:
Matt Jeanneret810148b2019-09-29 12:44:01 -0400106 ################################################################################
107 # VLAN Tagging Filter config
108 #
109 # EntityID will be referenced by:
110 # - Nothing
111 # References:
112 # - MacBridgePortConfigurationData for the ANI/PON side
113 #
114
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500115 # Delete bridge ani side vlan filter
Matt Jeanneret810148b2019-09-29 12:44:01 -0400116 # TODO: check if its in our local mib first before blindly deleting
117 msg = VlanTaggingFilterDataFrame(self._mac_bridge_port_ani_entity_id + self._uni_port.mac_bridge_port_num)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500118 frame = msg.delete()
119 self.log.debug('openomci-msg', omci_msg=msg)
120 self.strobe_watchdog()
121 results = yield self._device.omci_cc.send(frame)
122 self.check_status_and_state(results, 'flow-delete-vlan-tagging-filter-data')
123
124 # Re-Create bridge ani side vlan filter
Matt Jeanneret810148b2019-09-29 12:44:01 -0400125 # TODO: check if its in our local mib first before blindly recreating
126 forward_operation = 0x10 # VID investigation
127 # When the PUSH VLAN is RESERVED_VLAN (4095), let ONU be transparent
128 if self._set_vlan_id == RESERVED_TRANSPARENT_VLAN:
129 forward_operation = 0x00 # no investigation, ONU transparent
130
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500131 msg = VlanTaggingFilterDataFrame(
Matt Jeanneret810148b2019-09-29 12:44:01 -0400132 self._mac_bridge_port_ani_entity_id + self._uni_port.mac_bridge_port_num, # Entity ID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500133 vlan_tcis=[self._set_vlan_id], # VLAN IDs
Harsh Awasthib10a7082019-08-26 02:17:33 -0400134 forward_operation=forward_operation
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500135 )
136 frame = msg.create()
137 self.log.debug('openomci-msg', omci_msg=msg)
138 self.strobe_watchdog()
139 results = yield self._device.omci_cc.send(frame)
140 self.check_status_and_state(results, 'flow-create-vlan-tagging-filter-data')
141
Matt Jeanneret810148b2019-09-29 12:44:01 -0400142 ################################################################################
143 # Create Extended VLAN Tagging Operation config (UNI-side)
144 #
145 # EntityID relates to the VLAN TCIS
146 # References:
147 # - VLAN TCIS from previously created VLAN Tagging filter data
148 # - PPTP Ethernet or VEIP UNI
149 #
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500150
Matt Jeanneret810148b2019-09-29 12:44:01 -0400151 attributes = dict(
152 # Specifies the TPIDs in use and that operations in the downstream direction are
153 # inverse to the operations in the upstream direction
154 input_tpid=self._input_tpid, # input TPID
155 output_tpid=self._output_tpid, # output TPID
156 downstream_mode=0, # inverse of upstream
157 )
158
159 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
160 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
161 attributes=attributes
162 )
163
164 frame = msg.set()
165 self.log.debug('openomci-msg', omci_msg=msg)
166 self.strobe_watchdog()
167 results = yield self._device.omci_cc.send(frame)
168 self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data')
169
170 if self._set_vlan_id == RESERVED_TRANSPARENT_VLAN:
Harsh Awasthib10a7082019-08-26 02:17:33 -0400171 # Transparently send any single tagged packet.
172 # Any other specific rules will take priority over this
173 attributes = dict(
174 received_frame_vlan_tagging_operation_table=
175 VlanTaggingOperation(
176 filter_outer_priority=15,
177 filter_outer_vid=4096,
178 filter_outer_tpid_de=0,
179 filter_inner_priority=14,
180 filter_inner_vid=4096,
181 filter_inner_tpid_de=0,
182 filter_ether_type=0,
183 treatment_tags_to_remove=0,
184 treatment_outer_priority=15,
185 treatment_outer_vid=0,
186 treatment_outer_tpid_de=0,
187 treatment_inner_priority=15,
188 treatment_inner_vid=0,
189 treatment_inner_tpid_de=4
190 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500191 )
Harsh Awasthib10a7082019-08-26 02:17:33 -0400192 else:
193 # Update uni side extended vlan filter
194 # filter for untagged
Harsh Awasthib10a7082019-08-26 02:17:33 -0400195 attributes = dict(
196 received_frame_vlan_tagging_operation_table=
197 VlanTaggingOperation(
198 filter_outer_priority=15,
199 filter_outer_vid=4096,
200 filter_outer_tpid_de=0,
201 filter_inner_priority=15,
202 filter_inner_vid=4096,
203 filter_inner_tpid_de=0,
204 filter_ether_type=0,
205 treatment_tags_to_remove=0,
206 treatment_outer_priority=15,
207 treatment_outer_vid=0,
208 treatment_outer_tpid_de=0,
209 treatment_inner_priority=0,
210 treatment_inner_vid=self._set_vlan_id,
211 treatment_inner_tpid_de=4
212 )
213 )
214
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500215 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
Matt Jeanneret810148b2019-09-29 12:44:01 -0400216 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
217 attributes=attributes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500218 )
Matt Jeanneret810148b2019-09-29 12:44:01 -0400219
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500220 frame = msg.set()
221 self.log.debug('openomci-msg', omci_msg=msg)
222 self.strobe_watchdog()
223 results = yield self._device.omci_cc.send(frame)
Matt Jeanneret810148b2019-09-29 12:44:01 -0400224 self.check_status_and_state(results, 'set-evto-table')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500225
226 # Update uni side extended vlan filter
227 # filter for vlan 0
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500228 attributes = dict(
229 received_frame_vlan_tagging_operation_table=
230 VlanTaggingOperation(
231 filter_outer_priority=15, # This entry is not a double-tag rule
232 filter_outer_vid=4096, # Do not filter on the outer VID value
233 filter_outer_tpid_de=0, # Do not filter on the outer TPID field
234
235 filter_inner_priority=8, # Filter on inner vlan
236 filter_inner_vid=0x0, # Look for vlan 0
237 filter_inner_tpid_de=0, # Do not filter on inner TPID field
238 filter_ether_type=0, # Do not filter on EtherType
239
240 treatment_tags_to_remove=1,
241 treatment_outer_priority=15,
242 treatment_outer_vid=0,
243 treatment_outer_tpid_de=0,
244
245 treatment_inner_priority=8, # Add an inner tag and insert this value as the priority
246 treatment_inner_vid=self._set_vlan_id, # use this value as the VID in the inner VLAN tag
247 treatment_inner_tpid_de=4, # set TPID
248 )
249 )
250 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
Matt Jeanneret810148b2019-09-29 12:44:01 -0400251 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500252 attributes=attributes # See above
253 )
254 frame = msg.set()
255 self.log.debug('openomci-msg', omci_msg=msg)
256 self.strobe_watchdog()
257 results = yield self._device.omci_cc.send(frame)
Matt Jeanneret810148b2019-09-29 12:44:01 -0400258 self.check_status_and_state(results, 'set-evto-table-zero-tagged')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500259
260 self.deferred.callback(self)
261
262 except Exception as e:
263 self.log.exception('setting-vlan-tagging', e=e)
264 self.deferred.errback(failure.Failure(e))
265
266 def check_status_and_state(self, results, operation=''):
267 """
268 Check the results of an OMCI response. An exception is thrown
269 if the task was cancelled or an error was detected.
270
271 :param results: (OmciFrame) OMCI Response frame
272 :param operation: (str) what operation was being performed
273 :return: True if successful, False if the entity existed (already created)
274 """
275
276 omci_msg = results.fields['omci_message'].fields
277 status = omci_msg['success_code']
278 error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
279 failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
280 unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
281
Matt Jeannerete8fc53e2019-04-13 15:58:33 -0400282 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500283 status=status, error_mask=error_mask,
284 failed_mask=failed_mask, unsupported_mask=unsupported_mask)
285
286 if status == RC.Success:
287 self.strobe_watchdog()
288 return True
289
290 elif status == RC.InstanceExists:
291 return False
Harsh Awasthib10a7082019-08-26 02:17:33 -0400292