blob: 7c0a9ef1c96a26ec83acc0fd7cb5fb69a42dadaa [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 Jeanneret2e3cb8d2019-11-16 09:22:41 -050016from __future__ import absolute_import
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050017import structlog
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050018from twisted.internet import reactor
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050019from twisted.internet.defer import inlineCallbacks, TimeoutError, failure
20from pyvoltha.adapters.extensions.omci.omci_me import Ont2G, OmciNullPointer, PriorityQueueFrame, \
Girish Gowdra322cca12020-08-09 15:55:54 -070021 Ieee8021pMapperServiceProfileFrame, MacBridgePortConfigurationDataFrame, GemInterworkingTpFrame, \
22 GemPortNetworkCtpFrame
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050023from pyvoltha.adapters.extensions.omci.tasks.task import Task
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050024from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
Matt Jeanneret4195d7d2020-01-12 16:58:18 -050025from pyvoltha.adapters.extensions.omci.omci_entities import OntG, Tcont, PriorityQueueG, Ieee8021pMapperServiceProfile, \
26 GemPortNetworkCtp
aishwaryarana0180594ce2019-07-26 15:31:14 -050027
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050028OP = EntityOperations
29RC = ReasonCodes
30
Girish Gowdrae933cd32019-11-21 21:04:41 +053031SETUP_TP_TASK_PRIORITY = 240
32
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050033
34class TechProfileDownloadFailure(Exception):
35 """
36 This error is raised by default when the download fails
37 """
38
39
40class TechProfileResourcesFailure(Exception):
41 """
42 This error is raised by when one or more resources required is not available
43 """
44
45
Girish Gowdrae933cd32019-11-21 21:04:41 +053046class BrcmTpSetupTask(Task):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050047 """
48 OpenOMCI Tech-Profile Download Task
49
50 """
51
52 name = "Broadcom Tech-Profile Download Task"
53
Girish Gowdrae933cd32019-11-21 21:04:41 +053054 def __init__(self, omci_agent, handler, uni_id, tconts, gem_ports, tp_table_id):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050055 """
56 Class initialization
57
58 :param omci_agent: (OmciAdapterAgent) OMCI Adapter agent
Matt Jeanneret810148b2019-09-29 12:44:01 -040059 :param handler: (BrcmOpenomciOnuHandler) ONU Device Handler Instance
60 :param uni_id: (int) numeric id of the uni port on the onu device, starts at 0
Girish Gowdrae933cd32019-11-21 21:04:41 +053061 :param tp_table_id: (int) Technology Profile Table-ID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050062 """
Girish Gowdrae933cd32019-11-21 21:04:41 +053063 super(BrcmTpSetupTask, self).__init__(BrcmTpSetupTask.name,
64 omci_agent,
65 handler.device_id,
66 priority=SETUP_TP_TASK_PRIORITY,
67 exclusive=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050068
Matt Jeanneret08a8e862019-12-20 14:02:32 -050069 self.log = structlog.get_logger(device_id=handler.device_id,
70 name=BrcmTpSetupTask.name,
71 task_id=self._task_id,
72 tconts=tconts,
73 gem_ports=gem_ports,
74 uni_id=uni_id,
75 tp_table_id=tp_table_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050076
77 self._onu_device = omci_agent.get_device(handler.device_id)
78 self._local_deferred = None
79
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050080 self._uni_port = handler.uni_ports[uni_id]
81 assert self._uni_port.uni_id == uni_id
82
Girish Gowdrae933cd32019-11-21 21:04:41 +053083 # Tech Profile Table ID
84 self._tp_table_id = tp_table_id
85
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050086 # Entity IDs. IDs with values can probably be most anything for most ONUs,
87 # IDs set to None are discovered/set
88
89 self._mac_bridge_service_profile_entity_id = \
90 handler.mac_bridge_service_profile_entity_id
91 self._ieee_mapper_service_profile_entity_id = \
92 handler.pon_port.ieee_mapper_service_profile_entity_id
93 self._mac_bridge_port_ani_entity_id = \
94 handler.pon_port.mac_bridge_port_ani_entity_id
95 self._gal_enet_profile_entity_id = \
96 handler.gal_enet_profile_entity_id
97
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050098 self._tconts = []
Girish Gowdrae933cd32019-11-21 21:04:41 +053099 for t in tconts:
100 self._tconts.append(t)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500101
102 self._gem_ports = []
Girish Gowdrae933cd32019-11-21 21:04:41 +0530103 for g in gem_ports:
104 self._gem_ports.append(g)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500105
106 self.tcont_me_to_queue_map = dict()
107 self.uni_port_to_queue_map = dict()
108
109 def cancel_deferred(self):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530110 super(BrcmTpSetupTask, self).cancel_deferred()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500111
112 d, self._local_deferred = self._local_deferred, None
113 try:
114 if d is not None and not d.called:
115 d.cancel()
116 except:
117 pass
118
119 def start(self):
120 """
121 Start the Tech-Profile Download
122 """
Girish Gowdrae933cd32019-11-21 21:04:41 +0530123 super(BrcmTpSetupTask, self).start()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500124 self._local_deferred = reactor.callLater(0, self.perform_service_specific_steps)
125
126 def stop(self):
127 """
128 Shutdown Tech-Profile download tasks
129 """
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500130 self.cancel_deferred()
Girish Gowdrae933cd32019-11-21 21:04:41 +0530131 super(BrcmTpSetupTask, self).stop()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500132
133 def check_status_and_state(self, results, operation=''):
134 """
135 Check the results of an OMCI response. An exception is thrown
136 if the task was cancelled or an error was detected.
137
138 :param results: (OmciFrame) OMCI Response frame
139 :param operation: (str) what operation was being performed
140 :return: True if successful, False if the entity existed (already created)
141 """
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500142
143 omci_msg = results.fields['omci_message'].fields
144 status = omci_msg['success_code']
145 error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
146 failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
147 unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
148
Matt Jeannerete8fc53e2019-04-13 15:58:33 -0400149 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg, status=status, error_mask=error_mask,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500150 failed_mask=failed_mask, unsupported_mask=unsupported_mask)
151
152 if status == RC.Success:
153 self.strobe_watchdog()
154 return True
155
156 elif status == RC.InstanceExists:
157 return False
158
159 raise TechProfileDownloadFailure(
Girish Gowdrae933cd32019-11-21 21:04:41 +0530160 '{} failed with a status of {}, error_mask: {}, failed_mask: {}, '
161 'unsupported_mask: {}'.format(operation, status, error_mask, failed_mask, unsupported_mask))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500162
163 @inlineCallbacks
164 def perform_service_specific_steps(self):
Mahir Gunyela982ec32020-02-25 12:30:37 -0800165 self.log.info('starting-tech-profile-setup', uni_id=self._uni_port.uni_id,
Girish Gowdraacb65b02020-07-12 20:35:47 -0700166 tconts=self._tconts, gem_ports=self._gem_ports, tp_table_id=self._tp_table_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500167
168 omci_cc = self._onu_device.omci_cc
aishwaryarana0180594ce2019-07-26 15:31:14 -0500169 gem_pq_associativity = dict()
170 pq_to_related_port = dict()
171 is_related_ports_configurable = False
Girish Gowdraacb65b02020-07-12 20:35:47 -0700172 tcont_entity_id = 0
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500173
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700174 # We will setup mcast gem port and associated configuration as part of BrcmMcastTask
175 # In this OMCI task we work only on bidirectional gem ports
176 bidirectional_gem_ports = self._get_bidirectional_gem_list()
177 # If we are not setting up any bidirectional gem port, immediately return success
178 if len(bidirectional_gem_ports) == 0:
179 self.log.info("no-bidirectional-gem-list-found")
180 self.deferred.callback("tech-profile-download-success")
181 return
182
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500183 try:
184 ################################################################################
185 # TCONTS
186 #
187 # EntityID will be referenced by:
188 # - GemPortNetworkCtp
189 # References:
190 # - ONU created TCONT (created on ONU startup)
191
Girish Gowdrae933cd32019-11-21 21:04:41 +0530192 # Setup 8021p mapper and ani mac bridge port, if it does not exist
193 # Querying just 8021p mapper ME should be enough since we create and
194 # delete 8021pMapper and ANI Mac Bridge Port together.
195 ieee_8021p_mapper_exists = False
196 ieee_8021p_mapper = self._onu_device.query_mib(Ieee8021pMapperServiceProfile.class_id)
197 for k, v in ieee_8021p_mapper.items():
198 if not isinstance(v, dict):
199 continue
200 if k == (self._ieee_mapper_service_profile_entity_id +
201 self._uni_port.mac_bridge_port_num + self._tp_table_id):
202 ieee_8021p_mapper_exists = True
203
204 if ieee_8021p_mapper_exists is False:
205 self.log.info("setting-up-8021pmapper-ani-mac-bridge-port")
206 yield self._setup__8021p_mapper__ani_mac_bridge_port()
Girish Gowdra322cca12020-08-09 15:55:54 -0700207 else:
208 # If IEEE8021pMapper ME existed already, then we need to re-build the
209 # inter-working-tp-pointers for different gem-entity-ids. Delete the old one
210 self.log.info("delete-and-recreate-8021pmapper-ani-mac-bridge-port")
211 yield self._delete_and_recreate__8021p_mapper__ani_mac_bridge_port()
Girish Gowdrae933cd32019-11-21 21:04:41 +0530212
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500213 tcont_idents = self._onu_device.query_mib(Tcont.class_id)
214 self.log.debug('tcont-idents', tcont_idents=tcont_idents)
215
Girish Gowdraacb65b02020-07-12 20:35:47 -0700216 # There can be only one tcont that can be installed per tech-profile download task
217 # Each tech-profile represents a single tcont and associated gemports
218 assert len(self._tconts) == 1
Girish Gowdra7c1240c2020-07-15 15:06:42 -0700219
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500220 for tcont in self._tconts:
221 self.log.debug('tcont-loop', tcont=tcont)
222
223 if tcont.entity_id is None:
224 free_entity_id = None
225 for k, v in tcont_idents.items():
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500226 if not isinstance(v, dict):
227 continue
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500228 alloc_check = v.get('attributes', {}).get('alloc_id', 0)
Girish Gowdraba4b1812020-07-17 12:21:26 -0700229 if alloc_check == tcont.alloc_id:
230 # If any Tcont entity already refers to the alloc-id we want to use,
231 # lets choose that Tcont entity.
232 # This Tcont will be re-added to ONU and that is fine. The ONU reports that
233 # the entity already exists, which is not an error.
234 free_entity_id = k
235 self.log.debug("tcont-entity-already-exists-on-onu-for-this-alloc-id",
236 tcont_entity_id=k, alloc_id=tcont.alloc_id)
237 break
238 elif alloc_check == 0xFF or alloc_check == 0xFFFF:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500239 free_entity_id = k
240 break
241
242 self.log.debug('tcont-loop-free', free_entity_id=free_entity_id, alloc_id=tcont.alloc_id)
243
244 if free_entity_id is None:
245 self.log.error('no-available-tconts')
246 break
247
248 # Also assign entity id within tcont object
249 results = yield tcont.add_to_hardware(omci_cc, free_entity_id)
250 self.check_status_and_state(results, 'new-tcont-added')
Girish Gowdraacb65b02020-07-12 20:35:47 -0700251 # There is only tcont to be added per tech-profile download procedure
252 # So, there is no issue of overwriting the 'tcont_entity_id'
253 tcont_entity_id = free_entity_id
254
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500255 else:
Matt Jeanneret4195d7d2020-01-12 16:58:18 -0500256 self.log.debug('tcont-already-assigned', tcont_entity_id=tcont.entity_id, alloc_id=tcont.alloc_id)
Girish Gowdra7c1240c2020-07-15 15:06:42 -0700257 tcont_entity_id = tcont.entity_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500258
259 ################################################################################
260 # GEMS (GemPortNetworkCtp and GemInterworkingTp)
261 #
262 # For both of these MEs, the entity_id is the GEM Port ID. The entity id of the
263 # GemInterworkingTp ME could be different since it has an attribute to specify
264 # the GemPortNetworkCtp entity id.
265 #
266 # for the GemPortNetworkCtp ME
267 #
268 # GemPortNetworkCtp
269 # EntityID will be referenced by:
270 # - GemInterworkingTp
271 # References:
272 # - TCONT
273 # - Hardcoded upstream TM Entity ID
274 # - (Possibly in Future) Upstream Traffic descriptor profile pointer
275 #
276 # GemInterworkingTp
277 # EntityID will be referenced by:
278 # - Ieee8021pMapperServiceProfile
279 # References:
280 # - GemPortNetworkCtp
281 # - Ieee8021pMapperServiceProfile
282 # - GalEthernetProfile
283 #
284
285 onu_g = self._onu_device.query_mib(OntG.class_id)
286 # If the traffic management option attribute in the ONU-G ME is 0
287 # (priority controlled) or 2 (priority and rate controlled), this
288 # pointer specifies the priority queue ME serving this GEM port
289 # network CTP. If the traffic management option attribute is 1
290 # (rate controlled), this attribute redundantly points to the
291 # T-CONT serving this GEM port network CTP.
292 traffic_mgmt_opt = \
293 onu_g.get('attributes', {}).get('traffic_management_options', 0)
294 self.log.debug("traffic-mgmt-option", traffic_mgmt_opt=traffic_mgmt_opt)
295
296 prior_q = self._onu_device.query_mib(PriorityQueueG.class_id)
297 for k, v in prior_q.items():
298 self.log.debug("prior-q", k=k, v=v)
299
300 try:
301 _ = iter(v)
302 except TypeError:
303 continue
304
Girish Gowdraacb65b02020-07-12 20:35:47 -0700305 # Parse PQ MEs only with relevant information
306 if 'instance_id' in v and 'related_port' in v['attributes']:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500307 related_port = v['attributes']['related_port']
aishwaryarana0180594ce2019-07-26 15:31:14 -0500308 pq_to_related_port[k] = related_port
Girish Gowdraacb65b02020-07-12 20:35:47 -0700309 # If the MSB is set, it represents an Upstream PQ referencing the TCONT
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500310 if v['instance_id'] & 0b1000000000000000:
Girish Gowdraacb65b02020-07-12 20:35:47 -0700311 # If it references the TCONT ME we have just installed
312 if tcont_entity_id == (related_port & 0xffff0000) >> 16:
313 if tcont_entity_id not in self.tcont_me_to_queue_map:
314 self.log.debug("prior-q-related-port-and-tcont-me",
315 related_port=related_port,
316 tcont_me=tcont_entity_id)
317 self.tcont_me_to_queue_map[tcont_entity_id] = list()
318 # Store the PQ into the list which is referenced by TCONT ME we have provisioned
319 self.tcont_me_to_queue_map[tcont_entity_id].append(k)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500320
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500321 else:
Girish Gowdraacb65b02020-07-12 20:35:47 -0700322 # This represents the PQ pointing to the UNI Port ME (Downstream PQ)
323 if self._uni_port.entity_id == (related_port & 0xffff0000) >> 16:
324 if self._uni_port.entity_id not in self.uni_port_to_queue_map:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500325 self.log.debug("prior-q-related-port-and-uni-port-me",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530326 related_port=related_port,
Girish Gowdraacb65b02020-07-12 20:35:47 -0700327 uni_port_me=self._uni_port.entity_id)
328 self.uni_port_to_queue_map[self._uni_port.entity_id] = list()
329 # Store the PQ into the list which is referenced by UNI Port ME we have provisioned
330 self.uni_port_to_queue_map[self._uni_port.entity_id].append(k)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500331
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500332 self.log.debug("ul-prior-q", ul_prior_q=self.tcont_me_to_queue_map)
333 self.log.debug("dl-prior-q", dl_prior_q=self.uni_port_to_queue_map)
334
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700335 for gem_port in bidirectional_gem_ports:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500336 # TODO: Traffic descriptor will be available after meter bands are available
337 tcont = gem_port.tcont
338 if tcont is None:
339 self.log.error('unknown-tcont-reference', gem_id=gem_port.gem_id)
340 continue
341
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700342 # Sort the priority queue list in order of priority.
343 # 0 is highest priority and 0x0fff is lowest.
344 self.tcont_me_to_queue_map[tcont.entity_id].sort()
345 self.uni_port_to_queue_map[self._uni_port.entity_id].sort()
346 # Get the priority queue by indexing the priority value of the gemport.
347 # The self.tcont_me_to_queue_map and self.uni_port_to_queue_map
348 # have priority queue entities ordered in descending order
349 # of priority
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500350
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700351 ul_prior_q_entity_id = \
352 self.tcont_me_to_queue_map[tcont.entity_id][gem_port.priority_q]
353 dl_prior_q_entity_id = \
354 self.uni_port_to_queue_map[self._uni_port.entity_id][gem_port.priority_q]
aishwaryarana0180594ce2019-07-26 15:31:14 -0500355
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700356 pq_attributes = dict()
357 pq_attributes["pq_entity_id"] = ul_prior_q_entity_id
358 pq_attributes["weight"] = gem_port.weight
359 pq_attributes["scheduling_policy"] = gem_port.scheduling_policy
360 pq_attributes["priority_q"] = gem_port.priority_q
361 gem_pq_associativity[gem_port.entity_id] = pq_attributes
aishwaryarana0180594ce2019-07-26 15:31:14 -0500362
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700363 assert ul_prior_q_entity_id is not None and \
364 dl_prior_q_entity_id is not None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500365
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700366 existing = self._onu_device.query_mib(GemPortNetworkCtp.class_id, gem_port.entity_id)
367 self.log.debug('looking-for-gemport-before-create', existing=existing,
368 class_id=GemPortNetworkCtp.class_id,
369 entity_id=gem_port.entity_id)
370 if existing:
371 results = yield gem_port.remove_from_hardware(omci_cc)
372 self.check_status_and_state(results, 'remove-existing-gem-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500373
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700374 results = yield gem_port.add_to_hardware(omci_cc,
375 tcont.entity_id,
376 self._ieee_mapper_service_profile_entity_id +
377 self._uni_port.mac_bridge_port_num +
378 self._tp_table_id,
379 self._gal_enet_profile_entity_id,
380 ul_prior_q_entity_id, dl_prior_q_entity_id)
381 self.check_status_and_state(results, 'assign-gem-port')
Matt Jeanneret4195d7d2020-01-12 16:58:18 -0500382
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500383
384 ################################################################################
aishwaryarana0180594ce2019-07-26 15:31:14 -0500385 # Update the PriorityQeue Attributes for the PQ Associated with Gemport
386 #
387 # Entityt ID was created prior to this call. This is a set
388 #
389 #
390
391 ont2g = self._onu_device.query_mib(Ont2G.class_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530392 qos_config_flexibility_ie = ont2g.get(0, {}).get('attributes', {}). \
393 get('qos_configuration_flexibility', None)
aishwaryarana0180594ce2019-07-26 15:31:14 -0500394 self.log.debug("qos_config_flexibility",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530395 qos_config_flexibility=qos_config_flexibility_ie)
aishwaryarana0180594ce2019-07-26 15:31:14 -0500396
397 if qos_config_flexibility_ie & 0b100000:
398 is_related_ports_configurable = True
399
400 for k, v in gem_pq_associativity.items():
401 if v["scheduling_policy"] == "WRR":
402 self.log.debug("updating-pq-weight")
403 msg = PriorityQueueFrame(v["pq_entity_id"], weight=v["weight"])
404 frame = msg.set()
405 results = yield omci_cc.send(frame)
406 self.check_status_and_state(results, 'set-priority-queues-weight')
407 elif v["scheduling_policy"] == "StrictPriority" and \
408 is_related_ports_configurable:
409 self.log.debug("updating-pq-priority")
410 related_port = pq_to_related_port[v["pq_entity_id"]]
411 related_port = related_port & 0xffff0000
Girish Gowdrae933cd32019-11-21 21:04:41 +0530412 related_port = related_port | v['priority_q'] # Set priority
aishwaryarana0180594ce2019-07-26 15:31:14 -0500413 msg = PriorityQueueFrame(v["pq_entity_id"], related_port=related_port)
414 frame = msg.set()
415 results = yield omci_cc.send(frame)
416 self.check_status_and_state(results, 'set-priority-queues-priority')
417
aishwaryarana0180594ce2019-07-26 15:31:14 -0500418 ################################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500419 # Update the IEEE 802.1p Mapper Service Profile config
420 #
421 # EntityID was created prior to this call. This is a set
422 #
423 # References:
424 # - Gem Interwork TPs are set here
425 #
426
427 gem_entity_ids = [OmciNullPointer] * 8
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700428 for gem_port in bidirectional_gem_ports:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500429 self.log.debug("tp-gem-port", entity_id=gem_port.entity_id, uni_id=gem_port.uni_id)
430
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700431 for i, p in enumerate(reversed(gem_port.pbit_map)):
432 if p == '1':
433 gem_entity_ids[i] = gem_port.entity_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500434
435 msg = Ieee8021pMapperServiceProfileFrame(
Girish Gowdrae933cd32019-11-21 21:04:41 +0530436 (self._ieee_mapper_service_profile_entity_id +
437 self._uni_port.mac_bridge_port_num + self._tp_table_id),
438 # 802.1p mapper Service Mapper Profile ID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500439 interwork_tp_pointers=gem_entity_ids # Interworking TP IDs
440 )
441 frame = msg.set()
442 self.log.debug('openomci-msg', omci_msg=msg)
443 results = yield omci_cc.send(frame)
444 self.check_status_and_state(results, 'set-8021p-mapper-service-profile-ul')
445
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500446 self.deferred.callback("tech-profile-download-success")
447
448 except TimeoutError as e:
Matt Jeanneret810148b2019-09-29 12:44:01 -0400449 self.log.warn('rx-timeout-tech-profile', e=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500450 self.deferred.errback(failure.Failure(e))
451
452 except Exception as e:
Matt Jeanneret810148b2019-09-29 12:44:01 -0400453 self.log.exception('omci-setup-tech-profile', e=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500454 self.deferred.errback(failure.Failure(e))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530455
456 @inlineCallbacks
457 def _setup__8021p_mapper__ani_mac_bridge_port(self):
458
459 omci_cc = self._onu_device.omci_cc
460
461 try:
462 ################################################################################
463 # PON Specific #
464 ################################################################################
465 # IEEE 802.1 Mapper Service config - One per tech-profile per UNI
466 #
467 # EntityID will be referenced by:
468 # - MAC Bridge Port Configuration Data for the PON port and TP ID
469 # References:
470 # - Nothing at this point. When a GEM port is created, this entity will
471 # be updated to reference the GEM Interworking TP
472
473 msg = Ieee8021pMapperServiceProfileFrame(
474 self._ieee_mapper_service_profile_entity_id +
475 self._uni_port.mac_bridge_port_num +
476 self._tp_table_id
477 )
478 frame = msg.create()
479 self.log.debug('openomci-msg', omci_msg=msg)
480 results = yield omci_cc.send(frame)
481 self.check_status_and_state(results, 'create-8021p-mapper-service-profile')
482
483 ################################################################################
484 # Create MAC Bridge Port Configuration Data for the PON port via IEEE 802.1
485 # mapper service and this per TechProfile. Upon receipt by the ONU, the ONU will create an instance
486 # of the following before returning the response.
487 #
488 # - MAC bridge port designation data
489 # - MAC bridge port filter table data
490 # - MAC bridge port bridge table data
491 #
492 # EntityID will be referenced by:
493 # - Implicitly by the VLAN tagging filter data
494 # References:
495 # - MAC Bridge Service Profile (the bridge)
496 # - IEEE 802.1p mapper service profile for PON port
497
498 # TODO: magic. make a static variable for tp_type
499 msg = MacBridgePortConfigurationDataFrame(
Matt Jeanneret2e5c6f12019-12-13 07:06:06 -0500500 self._mac_bridge_port_ani_entity_id + self._uni_port.entity_id + self._tp_table_id, # Entity ID
Girish Gowdrae933cd32019-11-21 21:04:41 +0530501 bridge_id_pointer=(
502 self._mac_bridge_service_profile_entity_id +
503 self._uni_port.mac_bridge_port_num),
504 # Bridge Entity ID
505 port_num=0xff, # Port ID - unique number within the bridge
506 tp_type=3, # TP Type (IEEE 802.1p mapper service)
507 tp_pointer=(
508 self._ieee_mapper_service_profile_entity_id +
509 self._uni_port.mac_bridge_port_num +
510 self._tp_table_id
511 )
512 # TP ID, 8021p mapper ID
513 )
514 frame = msg.create()
515 self.log.debug('openomci-msg', omci_msg=msg)
516 results = yield omci_cc.send(frame)
517 self.check_status_and_state(results, 'create-mac-bridge-port-configuration-data-8021p-mapper')
518
519 except TimeoutError as e:
520 self.log.warn('rx-timeout-8021p-ani-port-setup', e=e)
521 raise
522
523 except Exception as e:
524 self.log.exception('omci-setup-8021p-ani-port-setup', e=e)
525 raise
Girish Gowdra322cca12020-08-09 15:55:54 -0700526
Girish Gowdra6dd965a2020-08-13 19:13:33 -0700527 def _get_bidirectional_gem_list(self):
528 gem_ports = list()
529 for gem in self._gem_ports:
530 # The assumption here is anything which is not multicast gem is a bidirectional gem
531 # We also filter in gem_port with direction "upstream" as "upstream" gem_port
532 # characteristics are good enough to setup the bi-directional gem_ports.
533 # Note that this may be an issue if gem_port characteristics are not symmetric
534 # in both directions, but we have not encountered such a situation so far.
535 if not gem.mcast and gem.direction == "upstream":
536 gem_ports.append(gem)
537 self.log.debug("bidirectional ports", gem_ports=gem_ports)
538 return gem_ports
539
Girish Gowdra322cca12020-08-09 15:55:54 -0700540 @inlineCallbacks
541 def _delete_and_recreate__8021p_mapper__ani_mac_bridge_port(self):
542
543 omci_cc = self._onu_device.omci_cc
544
545 try:
Girish Gowdra322cca12020-08-09 15:55:54 -0700546 # First clean up the Gem Ports references by the old 8021pMapper
547 ieee_8021p_mapper = self._onu_device.query_mib(Ieee8021pMapperServiceProfile.class_id)
548 for k, v in ieee_8021p_mapper.items():
549 if not isinstance(v, dict):
550 continue
551 # Check the entity-id of the instance matches what we expect
552 # for this Uni/TechProfileId
553 if k == (self._ieee_mapper_service_profile_entity_id +
554 self._uni_port.mac_bridge_port_num + self._tp_table_id):
555 for i in range(8):
556 gem_entity_id = v.get('attributes', {}). \
557 get('interwork_tp_pointer_for_p_bit_priority_' + str(i), OmciNullPointer)
558 if gem_entity_id is not OmciNullPointer:
559 self.log.debug('remove-from-hardware', gem_id=gem_entity_id)
560 try:
561 msg = GemInterworkingTpFrame(gem_entity_id)
562 frame = msg.delete()
563 self.log.debug('openomci-msg', omci_msg=msg)
564 results = yield omci_cc.send(frame)
565 self.check_status_and_state(results, 'delete-gem-port-network-ctp')
566 except Exception as e:
567 self.log.exception('interworking-delete', e=e)
568 raise
569
570 try:
571 msg = GemPortNetworkCtpFrame(gem_entity_id)
572 frame = msg.delete()
573 self.log.debug('openomci-msg', omci_msg=msg)
574 results = yield omci_cc.send(frame)
575 self.check_status_and_state(results, 'delete-gem-interworking-tp')
576 except Exception as e:
577 self.log.exception('gemport-delete', e=e)
578 raise
579 break
580
581 # Then delete 8021pMapper ME
582 msg = Ieee8021pMapperServiceProfileFrame(
583 self._ieee_mapper_service_profile_entity_id +
584 self._uni_port.mac_bridge_port_num +
585 self._tp_table_id
586 )
587 frame = msg.delete()
588 self.log.debug('openomci-msg', omci_msg=msg)
589 results = yield omci_cc.send(frame)
590 self.check_status_and_state(results, 'delete-8021p-mapper-service-profile')
591
592 # Then delete ANI Mac Bridge port
593 msg = MacBridgePortConfigurationDataFrame(
594 self._mac_bridge_port_ani_entity_id + self._uni_port.entity_id + self._tp_table_id # Entity ID
595 )
596 frame = msg.delete()
597 self.log.debug('openomci-msg', omci_msg=msg)
598 results = yield omci_cc.send(frame)
599 self.check_status_and_state(results, 'delete-mac-bridge-port-configuration-data')
600
601 # TODO: We need not delete the TCONT as TCONTs are pre-created. We should possibly
602 # unset the TCONTs alloc-id from a valid value to 0xffff.
603 # But this was not causing issues in my test. A separate Jira is necessary for this.
604 yield self._setup__8021p_mapper__ani_mac_bridge_port()
605
606 except TimeoutError as e:
607 self.log.warn('rx-timeout-8021p-ani-port-delete', e=e)
608 raise
609
610 except Exception as e:
611 self.log.exception('omci-setup-8021p-ani-port-delete', e=e)
612 raise
613