blob: eaa3176c012d26109c4bb5c387a9fe6e42a92e50 [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
17import structlog
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050018from pyvoltha.adapters.extensions.omci.tasks.task import Task
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050019from twisted.internet import reactor
20from twisted.internet.defer import inlineCallbacks, failure, returnValue
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050021from pyvoltha.adapters.extensions.omci.omci_defs import ReasonCodes, EntityOperations
Matt Jeanneret810148b2019-09-29 12:44:01 -040022from pyvoltha.adapters.extensions.omci.omci_me import \
23 VlanTaggingOperation, VlanTaggingFilterDataFrame, ExtendedVlanTaggingOperationConfigurationDataFrame
24from adapters.brcm_openomci_onu.uni_port import UniType
25from adapters.brcm_openomci_onu.pon_port import DEFAULT_TPID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050026
27RC = ReasonCodes
28OP = EntityOperations
Matt Jeanneret810148b2019-09-29 12:44:01 -040029RESERVED_TRANSPARENT_VLAN = 4095
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050030
31
32class BrcmVlanFilterException(Exception):
33 pass
34
35
36class BrcmVlanFilterTask(Task):
37 """
38 Apply Vlan Tagging Filter Data and Extended VLAN Tagging Operation Configuration on an ANI and UNI
39 """
40 task_priority = 200
Matt Jeanneret810148b2019-09-29 12:44:01 -040041 name = "Broadcom VLAN Filter/Tagging Task"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050042
Matt Jeanneret810148b2019-09-29 12:44:01 -040043 def __init__(self, omci_agent, handler, uni_port, set_vlan_id, priority=task_priority):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050044 """
45 Class initialization
46
47 :param omci_agent: (OmciAdapterAgent) OMCI Adapter agent
Matt Jeanneret810148b2019-09-29 12:44:01 -040048 :param handler: (BrcmOpenomciOnuHandler) ONU Device Handler Instance
49 :param uni_port: (UniPort) Object instance representing the uni port and its settings
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050050 :param set_vlan_id: (int) VLAN to filter for and set
51 :param priority: (int) OpenOMCI Task priority (0..255) 255 is the highest
52 """
53
Matt Jeanneret810148b2019-09-29 12:44:01 -040054 self.log = structlog.get_logger(device_id=handler.device_id, uni_port=uni_port.port_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050055
56 super(BrcmVlanFilterTask, self).__init__(BrcmVlanFilterTask.name,
57 omci_agent,
Matt Jeanneret810148b2019-09-29 12:44:01 -040058 handler.device_id,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050059 priority=priority,
60 exclusive=True)
Matt Jeanneret810148b2019-09-29 12:44:01 -040061 self._device = omci_agent.get_device(handler.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050062 self._uni_port = uni_port
63 self._set_vlan_id = set_vlan_id
64 self._results = None
65 self._local_deferred = None
66 self._config = self._device.configuration
67
Matt Jeanneret810148b2019-09-29 12:44:01 -040068 self._input_tpid = DEFAULT_TPID
69 self._output_tpid = DEFAULT_TPID
70
71 self._mac_bridge_service_profile_entity_id = \
72 handler.mac_bridge_service_profile_entity_id
73 self._ieee_mapper_service_profile_entity_id = \
74 handler.pon_port.ieee_mapper_service_profile_entity_id
75 self._mac_bridge_port_ani_entity_id = \
76 handler.pon_port.mac_bridge_port_ani_entity_id
77 self._gal_enet_profile_entity_id = \
78 handler.gal_enet_profile_entity_id
79
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050080 def cancel_deferred(self):
81 super(BrcmVlanFilterTask, self).cancel_deferred()
82
83 d, self._local_deferred = self._local_deferred, None
84 try:
85 if d is not None and not d.called:
86 d.cancel()
87 except:
88 pass
89
90 def start(self):
91 """
92 Start Vlan Tagging Task
93 """
94 super(BrcmVlanFilterTask, self).start()
95 self._local_deferred = reactor.callLater(0, self.perform_vlan_tagging)
96
97 @inlineCallbacks
98 def perform_vlan_tagging(self):
99 """
100 Perform the vlan tagging
101 """
102 self.log.info('setting-vlan-tagging')
103
104 try:
Matt Jeanneret810148b2019-09-29 12:44:01 -0400105 ################################################################################
106 # VLAN Tagging Filter config
107 #
108 # EntityID will be referenced by:
109 # - Nothing
110 # References:
111 # - MacBridgePortConfigurationData for the ANI/PON side
112 #
113
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500114 # Delete bridge ani side vlan filter
Matt Jeanneret810148b2019-09-29 12:44:01 -0400115 # TODO: check if its in our local mib first before blindly deleting
116 msg = VlanTaggingFilterDataFrame(self._mac_bridge_port_ani_entity_id + self._uni_port.mac_bridge_port_num)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500117 frame = msg.delete()
118 self.log.debug('openomci-msg', omci_msg=msg)
119 self.strobe_watchdog()
120 results = yield self._device.omci_cc.send(frame)
121 self.check_status_and_state(results, 'flow-delete-vlan-tagging-filter-data')
122
123 # Re-Create bridge ani side vlan filter
Matt Jeanneret810148b2019-09-29 12:44:01 -0400124 # TODO: check if its in our local mib first before blindly recreating
125 forward_operation = 0x10 # VID investigation
126 # When the PUSH VLAN is RESERVED_VLAN (4095), let ONU be transparent
127 if self._set_vlan_id == RESERVED_TRANSPARENT_VLAN:
128 forward_operation = 0x00 # no investigation, ONU transparent
129
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500130 msg = VlanTaggingFilterDataFrame(
Matt Jeanneret810148b2019-09-29 12:44:01 -0400131 self._mac_bridge_port_ani_entity_id + self._uni_port.mac_bridge_port_num, # Entity ID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500132 vlan_tcis=[self._set_vlan_id], # VLAN IDs
Harsh Awasthib10a7082019-08-26 02:17:33 -0400133 forward_operation=forward_operation
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500134 )
135 frame = msg.create()
136 self.log.debug('openomci-msg', omci_msg=msg)
137 self.strobe_watchdog()
138 results = yield self._device.omci_cc.send(frame)
139 self.check_status_and_state(results, 'flow-create-vlan-tagging-filter-data')
140
Matt Jeanneret810148b2019-09-29 12:44:01 -0400141 ################################################################################
142 # Create Extended VLAN Tagging Operation config (UNI-side)
143 #
144 # EntityID relates to the VLAN TCIS
145 # References:
146 # - VLAN TCIS from previously created VLAN Tagging filter data
147 # - PPTP Ethernet or VEIP UNI
148 #
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500149
Matt Jeanneret810148b2019-09-29 12:44:01 -0400150 attributes = dict(
151 # Specifies the TPIDs in use and that operations in the downstream direction are
152 # inverse to the operations in the upstream direction
153 input_tpid=self._input_tpid, # input TPID
154 output_tpid=self._output_tpid, # output TPID
155 downstream_mode=0, # inverse of upstream
156 )
157
158 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
159 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
160 attributes=attributes
161 )
162
163 frame = msg.set()
164 self.log.debug('openomci-msg', omci_msg=msg)
165 self.strobe_watchdog()
166 results = yield self._device.omci_cc.send(frame)
167 self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data')
168
169 if self._set_vlan_id == RESERVED_TRANSPARENT_VLAN:
Harsh Awasthib10a7082019-08-26 02:17:33 -0400170 # Transparently send any single tagged packet.
171 # Any other specific rules will take priority over this
172 attributes = dict(
173 received_frame_vlan_tagging_operation_table=
174 VlanTaggingOperation(
175 filter_outer_priority=15,
176 filter_outer_vid=4096,
177 filter_outer_tpid_de=0,
178 filter_inner_priority=14,
179 filter_inner_vid=4096,
180 filter_inner_tpid_de=0,
181 filter_ether_type=0,
182 treatment_tags_to_remove=0,
183 treatment_outer_priority=15,
184 treatment_outer_vid=0,
185 treatment_outer_tpid_de=0,
186 treatment_inner_priority=15,
187 treatment_inner_vid=0,
188 treatment_inner_tpid_de=4
189 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500190 )
Harsh Awasthib10a7082019-08-26 02:17:33 -0400191 else:
192 # Update uni side extended vlan filter
193 # filter for untagged
Harsh Awasthib10a7082019-08-26 02:17:33 -0400194 attributes = dict(
195 received_frame_vlan_tagging_operation_table=
196 VlanTaggingOperation(
197 filter_outer_priority=15,
198 filter_outer_vid=4096,
199 filter_outer_tpid_de=0,
200 filter_inner_priority=15,
201 filter_inner_vid=4096,
202 filter_inner_tpid_de=0,
203 filter_ether_type=0,
204 treatment_tags_to_remove=0,
205 treatment_outer_priority=15,
206 treatment_outer_vid=0,
207 treatment_outer_tpid_de=0,
208 treatment_inner_priority=0,
209 treatment_inner_vid=self._set_vlan_id,
210 treatment_inner_tpid_de=4
211 )
212 )
213
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500214 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
Matt Jeanneret810148b2019-09-29 12:44:01 -0400215 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
216 attributes=attributes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500217 )
Matt Jeanneret810148b2019-09-29 12:44:01 -0400218
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500219 frame = msg.set()
220 self.log.debug('openomci-msg', omci_msg=msg)
221 self.strobe_watchdog()
222 results = yield self._device.omci_cc.send(frame)
Matt Jeanneret810148b2019-09-29 12:44:01 -0400223 self.check_status_and_state(results, 'set-evto-table')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500224
225 # Update uni side extended vlan filter
226 # filter for vlan 0
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500227 attributes = dict(
228 received_frame_vlan_tagging_operation_table=
229 VlanTaggingOperation(
230 filter_outer_priority=15, # This entry is not a double-tag rule
231 filter_outer_vid=4096, # Do not filter on the outer VID value
232 filter_outer_tpid_de=0, # Do not filter on the outer TPID field
233
234 filter_inner_priority=8, # Filter on inner vlan
235 filter_inner_vid=0x0, # Look for vlan 0
236 filter_inner_tpid_de=0, # Do not filter on inner TPID field
237 filter_ether_type=0, # Do not filter on EtherType
238
239 treatment_tags_to_remove=1,
240 treatment_outer_priority=15,
241 treatment_outer_vid=0,
242 treatment_outer_tpid_de=0,
243
244 treatment_inner_priority=8, # Add an inner tag and insert this value as the priority
245 treatment_inner_vid=self._set_vlan_id, # use this value as the VID in the inner VLAN tag
246 treatment_inner_tpid_de=4, # set TPID
247 )
248 )
249 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
Matt Jeanneret810148b2019-09-29 12:44:01 -0400250 self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500251 attributes=attributes # See above
252 )
253 frame = msg.set()
254 self.log.debug('openomci-msg', omci_msg=msg)
255 self.strobe_watchdog()
256 results = yield self._device.omci_cc.send(frame)
Matt Jeanneret810148b2019-09-29 12:44:01 -0400257 self.check_status_and_state(results, 'set-evto-table-zero-tagged')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500258
259 self.deferred.callback(self)
260
261 except Exception as e:
262 self.log.exception('setting-vlan-tagging', e=e)
263 self.deferred.errback(failure.Failure(e))
264
265 def check_status_and_state(self, results, operation=''):
266 """
267 Check the results of an OMCI response. An exception is thrown
268 if the task was cancelled or an error was detected.
269
270 :param results: (OmciFrame) OMCI Response frame
271 :param operation: (str) what operation was being performed
272 :return: True if successful, False if the entity existed (already created)
273 """
274
275 omci_msg = results.fields['omci_message'].fields
276 status = omci_msg['success_code']
277 error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
278 failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
279 unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
280
Matt Jeannerete8fc53e2019-04-13 15:58:33 -0400281 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500282 status=status, error_mask=error_mask,
283 failed_mask=failed_mask, unsupported_mask=unsupported_mask)
284
285 if status == RC.Success:
286 self.strobe_watchdog()
287 return True
288
289 elif status == RC.InstanceExists:
290 return False
Harsh Awasthib10a7082019-08-26 02:17:33 -0400291