blob: 4642318bbd9cf1e0d40d7ec3188b1b56c63d9185 [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
174 try:
175 ################################################################################
176 # TCONTS
177 #
178 # EntityID will be referenced by:
179 # - GemPortNetworkCtp
180 # References:
181 # - ONU created TCONT (created on ONU startup)
182
Girish Gowdrae933cd32019-11-21 21:04:41 +0530183 # Setup 8021p mapper and ani mac bridge port, if it does not exist
184 # Querying just 8021p mapper ME should be enough since we create and
185 # delete 8021pMapper and ANI Mac Bridge Port together.
186 ieee_8021p_mapper_exists = False
187 ieee_8021p_mapper = self._onu_device.query_mib(Ieee8021pMapperServiceProfile.class_id)
188 for k, v in ieee_8021p_mapper.items():
189 if not isinstance(v, dict):
190 continue
191 if k == (self._ieee_mapper_service_profile_entity_id +
192 self._uni_port.mac_bridge_port_num + self._tp_table_id):
193 ieee_8021p_mapper_exists = True
194
195 if ieee_8021p_mapper_exists is False:
196 self.log.info("setting-up-8021pmapper-ani-mac-bridge-port")
197 yield self._setup__8021p_mapper__ani_mac_bridge_port()
Girish Gowdra322cca12020-08-09 15:55:54 -0700198 else:
199 # If IEEE8021pMapper ME existed already, then we need to re-build the
200 # inter-working-tp-pointers for different gem-entity-ids. Delete the old one
201 self.log.info("delete-and-recreate-8021pmapper-ani-mac-bridge-port")
202 yield self._delete_and_recreate__8021p_mapper__ani_mac_bridge_port()
Girish Gowdrae933cd32019-11-21 21:04:41 +0530203
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500204 tcont_idents = self._onu_device.query_mib(Tcont.class_id)
205 self.log.debug('tcont-idents', tcont_idents=tcont_idents)
206
Girish Gowdraacb65b02020-07-12 20:35:47 -0700207 # There can be only one tcont that can be installed per tech-profile download task
208 # Each tech-profile represents a single tcont and associated gemports
209 assert len(self._tconts) == 1
Girish Gowdra7c1240c2020-07-15 15:06:42 -0700210
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500211 for tcont in self._tconts:
212 self.log.debug('tcont-loop', tcont=tcont)
213
214 if tcont.entity_id is None:
215 free_entity_id = None
216 for k, v in tcont_idents.items():
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500217 if not isinstance(v, dict):
218 continue
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500219 alloc_check = v.get('attributes', {}).get('alloc_id', 0)
Girish Gowdraba4b1812020-07-17 12:21:26 -0700220 if alloc_check == tcont.alloc_id:
221 # If any Tcont entity already refers to the alloc-id we want to use,
222 # lets choose that Tcont entity.
223 # This Tcont will be re-added to ONU and that is fine. The ONU reports that
224 # the entity already exists, which is not an error.
225 free_entity_id = k
226 self.log.debug("tcont-entity-already-exists-on-onu-for-this-alloc-id",
227 tcont_entity_id=k, alloc_id=tcont.alloc_id)
228 break
229 elif alloc_check == 0xFF or alloc_check == 0xFFFF:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500230 free_entity_id = k
231 break
232
233 self.log.debug('tcont-loop-free', free_entity_id=free_entity_id, alloc_id=tcont.alloc_id)
234
235 if free_entity_id is None:
236 self.log.error('no-available-tconts')
237 break
238
239 # Also assign entity id within tcont object
240 results = yield tcont.add_to_hardware(omci_cc, free_entity_id)
241 self.check_status_and_state(results, 'new-tcont-added')
Girish Gowdraacb65b02020-07-12 20:35:47 -0700242 # There is only tcont to be added per tech-profile download procedure
243 # So, there is no issue of overwriting the 'tcont_entity_id'
244 tcont_entity_id = free_entity_id
245
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500246 else:
Matt Jeanneret4195d7d2020-01-12 16:58:18 -0500247 self.log.debug('tcont-already-assigned', tcont_entity_id=tcont.entity_id, alloc_id=tcont.alloc_id)
Girish Gowdra7c1240c2020-07-15 15:06:42 -0700248 tcont_entity_id = tcont.entity_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500249
250 ################################################################################
251 # GEMS (GemPortNetworkCtp and GemInterworkingTp)
252 #
253 # For both of these MEs, the entity_id is the GEM Port ID. The entity id of the
254 # GemInterworkingTp ME could be different since it has an attribute to specify
255 # the GemPortNetworkCtp entity id.
256 #
257 # for the GemPortNetworkCtp ME
258 #
259 # GemPortNetworkCtp
260 # EntityID will be referenced by:
261 # - GemInterworkingTp
262 # References:
263 # - TCONT
264 # - Hardcoded upstream TM Entity ID
265 # - (Possibly in Future) Upstream Traffic descriptor profile pointer
266 #
267 # GemInterworkingTp
268 # EntityID will be referenced by:
269 # - Ieee8021pMapperServiceProfile
270 # References:
271 # - GemPortNetworkCtp
272 # - Ieee8021pMapperServiceProfile
273 # - GalEthernetProfile
274 #
275
276 onu_g = self._onu_device.query_mib(OntG.class_id)
277 # If the traffic management option attribute in the ONU-G ME is 0
278 # (priority controlled) or 2 (priority and rate controlled), this
279 # pointer specifies the priority queue ME serving this GEM port
280 # network CTP. If the traffic management option attribute is 1
281 # (rate controlled), this attribute redundantly points to the
282 # T-CONT serving this GEM port network CTP.
283 traffic_mgmt_opt = \
284 onu_g.get('attributes', {}).get('traffic_management_options', 0)
285 self.log.debug("traffic-mgmt-option", traffic_mgmt_opt=traffic_mgmt_opt)
286
287 prior_q = self._onu_device.query_mib(PriorityQueueG.class_id)
288 for k, v in prior_q.items():
289 self.log.debug("prior-q", k=k, v=v)
290
291 try:
292 _ = iter(v)
293 except TypeError:
294 continue
295
Girish Gowdraacb65b02020-07-12 20:35:47 -0700296 # Parse PQ MEs only with relevant information
297 if 'instance_id' in v and 'related_port' in v['attributes']:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500298 related_port = v['attributes']['related_port']
aishwaryarana0180594ce2019-07-26 15:31:14 -0500299 pq_to_related_port[k] = related_port
Girish Gowdraacb65b02020-07-12 20:35:47 -0700300 # If the MSB is set, it represents an Upstream PQ referencing the TCONT
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500301 if v['instance_id'] & 0b1000000000000000:
Girish Gowdraacb65b02020-07-12 20:35:47 -0700302 # If it references the TCONT ME we have just installed
303 if tcont_entity_id == (related_port & 0xffff0000) >> 16:
304 if tcont_entity_id not in self.tcont_me_to_queue_map:
305 self.log.debug("prior-q-related-port-and-tcont-me",
306 related_port=related_port,
307 tcont_me=tcont_entity_id)
308 self.tcont_me_to_queue_map[tcont_entity_id] = list()
309 # Store the PQ into the list which is referenced by TCONT ME we have provisioned
310 self.tcont_me_to_queue_map[tcont_entity_id].append(k)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500311
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500312 else:
Girish Gowdraacb65b02020-07-12 20:35:47 -0700313 # This represents the PQ pointing to the UNI Port ME (Downstream PQ)
314 if self._uni_port.entity_id == (related_port & 0xffff0000) >> 16:
315 if self._uni_port.entity_id not in self.uni_port_to_queue_map:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500316 self.log.debug("prior-q-related-port-and-uni-port-me",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530317 related_port=related_port,
Girish Gowdraacb65b02020-07-12 20:35:47 -0700318 uni_port_me=self._uni_port.entity_id)
319 self.uni_port_to_queue_map[self._uni_port.entity_id] = list()
320 # Store the PQ into the list which is referenced by UNI Port ME we have provisioned
321 self.uni_port_to_queue_map[self._uni_port.entity_id].append(k)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500322
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500323 self.log.debug("ul-prior-q", ul_prior_q=self.tcont_me_to_queue_map)
324 self.log.debug("dl-prior-q", dl_prior_q=self.uni_port_to_queue_map)
325
326 for gem_port in self._gem_ports:
327 # TODO: Traffic descriptor will be available after meter bands are available
328 tcont = gem_port.tcont
329 if tcont is None:
330 self.log.error('unknown-tcont-reference', gem_id=gem_port.gem_id)
331 continue
332
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500333 if gem_port.direction == "upstream" or \
334 gem_port.direction == "bi-directional":
335
336 # Sort the priority queue list in order of priority.
337 # 0 is highest priority and 0x0fff is lowest.
338 self.tcont_me_to_queue_map[tcont.entity_id].sort()
339 self.uni_port_to_queue_map[self._uni_port.entity_id].sort()
aishwaryarana0180594ce2019-07-26 15:31:14 -0500340 # Get the priority queue by indexing the priority value of the gemport.
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500341 # The self.tcont_me_to_queue_map and self.uni_port_to_queue_map
342 # have priority queue entities ordered in descending order
343 # of priority
aishwaryarana0180594ce2019-07-26 15:31:14 -0500344
345 ul_prior_q_entity_id = \
346 self.tcont_me_to_queue_map[tcont.entity_id][gem_port.priority_q]
347 dl_prior_q_entity_id = \
348 self.uni_port_to_queue_map[self._uni_port.entity_id][gem_port.priority_q]
349
350 pq_attributes = dict()
351 pq_attributes["pq_entity_id"] = ul_prior_q_entity_id
352 pq_attributes["weight"] = gem_port.weight
353 pq_attributes["scheduling_policy"] = gem_port.scheduling_policy
354 pq_attributes["priority_q"] = gem_port.priority_q
355 gem_pq_associativity[gem_port.entity_id] = pq_attributes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500356
357 assert ul_prior_q_entity_id is not None and \
358 dl_prior_q_entity_id is not None
359
Matt Jeanneret4195d7d2020-01-12 16:58:18 -0500360 existing = self._onu_device.query_mib(GemPortNetworkCtp.class_id, gem_port.entity_id)
361 self.log.debug('looking-for-gemport-before-create', existing=existing,
362 class_id=GemPortNetworkCtp.class_id,
363 entity_id=gem_port.entity_id)
364 if existing:
365 results = yield gem_port.remove_from_hardware(omci_cc)
366 self.check_status_and_state(results, 'remove-existing-gem-port')
367
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500368 results = yield gem_port.add_to_hardware(omci_cc,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530369 tcont.entity_id,
370 self._ieee_mapper_service_profile_entity_id +
371 self._uni_port.mac_bridge_port_num +
372 self._tp_table_id,
373 self._gal_enet_profile_entity_id,
374 ul_prior_q_entity_id, dl_prior_q_entity_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500375 self.check_status_and_state(results, 'assign-gem-port')
376 elif gem_port.direction == "downstream":
377 # Downstream is inverse of upstream
378 # TODO: could also be a case of multicast. Not supported for now
379 self.log.debug("skipping-downstream-gem", gem_port=gem_port)
380 pass
381
382 ################################################################################
aishwaryarana0180594ce2019-07-26 15:31:14 -0500383 # Update the PriorityQeue Attributes for the PQ Associated with Gemport
384 #
385 # Entityt ID was created prior to this call. This is a set
386 #
387 #
388
389 ont2g = self._onu_device.query_mib(Ont2G.class_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530390 qos_config_flexibility_ie = ont2g.get(0, {}).get('attributes', {}). \
391 get('qos_configuration_flexibility', None)
aishwaryarana0180594ce2019-07-26 15:31:14 -0500392 self.log.debug("qos_config_flexibility",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530393 qos_config_flexibility=qos_config_flexibility_ie)
aishwaryarana0180594ce2019-07-26 15:31:14 -0500394
395 if qos_config_flexibility_ie & 0b100000:
396 is_related_ports_configurable = True
397
398 for k, v in gem_pq_associativity.items():
399 if v["scheduling_policy"] == "WRR":
400 self.log.debug("updating-pq-weight")
401 msg = PriorityQueueFrame(v["pq_entity_id"], weight=v["weight"])
402 frame = msg.set()
403 results = yield omci_cc.send(frame)
404 self.check_status_and_state(results, 'set-priority-queues-weight')
405 elif v["scheduling_policy"] == "StrictPriority" and \
406 is_related_ports_configurable:
407 self.log.debug("updating-pq-priority")
408 related_port = pq_to_related_port[v["pq_entity_id"]]
409 related_port = related_port & 0xffff0000
Girish Gowdrae933cd32019-11-21 21:04:41 +0530410 related_port = related_port | v['priority_q'] # Set priority
aishwaryarana0180594ce2019-07-26 15:31:14 -0500411 msg = PriorityQueueFrame(v["pq_entity_id"], related_port=related_port)
412 frame = msg.set()
413 results = yield omci_cc.send(frame)
414 self.check_status_and_state(results, 'set-priority-queues-priority')
415
aishwaryarana0180594ce2019-07-26 15:31:14 -0500416 ################################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500417 # Update the IEEE 802.1p Mapper Service Profile config
418 #
419 # EntityID was created prior to this call. This is a set
420 #
421 # References:
422 # - Gem Interwork TPs are set here
423 #
424
425 gem_entity_ids = [OmciNullPointer] * 8
426 for gem_port in self._gem_ports:
427 self.log.debug("tp-gem-port", entity_id=gem_port.entity_id, uni_id=gem_port.uni_id)
428
429 if gem_port.direction == "upstream" or \
430 gem_port.direction == "bi-directional":
431 for i, p in enumerate(reversed(gem_port.pbit_map)):
432 if p == '1':
433 gem_entity_ids[i] = gem_port.entity_id
434 elif gem_port.direction == "downstream":
435 # Downstream gem port p-bit mapper is inverse of upstream
436 # TODO: Could also be a case of multicast. Not supported for now
437 pass
438
439 msg = Ieee8021pMapperServiceProfileFrame(
Girish Gowdrae933cd32019-11-21 21:04:41 +0530440 (self._ieee_mapper_service_profile_entity_id +
441 self._uni_port.mac_bridge_port_num + self._tp_table_id),
442 # 802.1p mapper Service Mapper Profile ID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500443 interwork_tp_pointers=gem_entity_ids # Interworking TP IDs
444 )
445 frame = msg.set()
446 self.log.debug('openomci-msg', omci_msg=msg)
447 results = yield omci_cc.send(frame)
448 self.check_status_and_state(results, 'set-8021p-mapper-service-profile-ul')
449
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500450 self.deferred.callback("tech-profile-download-success")
451
452 except TimeoutError as e:
Matt Jeanneret810148b2019-09-29 12:44:01 -0400453 self.log.warn('rx-timeout-tech-profile', e=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500454 self.deferred.errback(failure.Failure(e))
455
456 except Exception as e:
Matt Jeanneret810148b2019-09-29 12:44:01 -0400457 self.log.exception('omci-setup-tech-profile', e=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500458 self.deferred.errback(failure.Failure(e))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530459
460 @inlineCallbacks
461 def _setup__8021p_mapper__ani_mac_bridge_port(self):
462
463 omci_cc = self._onu_device.omci_cc
464
465 try:
466 ################################################################################
467 # PON Specific #
468 ################################################################################
469 # IEEE 802.1 Mapper Service config - One per tech-profile per UNI
470 #
471 # EntityID will be referenced by:
472 # - MAC Bridge Port Configuration Data for the PON port and TP ID
473 # References:
474 # - Nothing at this point. When a GEM port is created, this entity will
475 # be updated to reference the GEM Interworking TP
476
477 msg = Ieee8021pMapperServiceProfileFrame(
478 self._ieee_mapper_service_profile_entity_id +
479 self._uni_port.mac_bridge_port_num +
480 self._tp_table_id
481 )
482 frame = msg.create()
483 self.log.debug('openomci-msg', omci_msg=msg)
484 results = yield omci_cc.send(frame)
485 self.check_status_and_state(results, 'create-8021p-mapper-service-profile')
486
487 ################################################################################
488 # Create MAC Bridge Port Configuration Data for the PON port via IEEE 802.1
489 # mapper service and this per TechProfile. Upon receipt by the ONU, the ONU will create an instance
490 # of the following before returning the response.
491 #
492 # - MAC bridge port designation data
493 # - MAC bridge port filter table data
494 # - MAC bridge port bridge table data
495 #
496 # EntityID will be referenced by:
497 # - Implicitly by the VLAN tagging filter data
498 # References:
499 # - MAC Bridge Service Profile (the bridge)
500 # - IEEE 802.1p mapper service profile for PON port
501
502 # TODO: magic. make a static variable for tp_type
503 msg = MacBridgePortConfigurationDataFrame(
Matt Jeanneret2e5c6f12019-12-13 07:06:06 -0500504 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 +0530505 bridge_id_pointer=(
506 self._mac_bridge_service_profile_entity_id +
507 self._uni_port.mac_bridge_port_num),
508 # Bridge Entity ID
509 port_num=0xff, # Port ID - unique number within the bridge
510 tp_type=3, # TP Type (IEEE 802.1p mapper service)
511 tp_pointer=(
512 self._ieee_mapper_service_profile_entity_id +
513 self._uni_port.mac_bridge_port_num +
514 self._tp_table_id
515 )
516 # TP ID, 8021p mapper ID
517 )
518 frame = msg.create()
519 self.log.debug('openomci-msg', omci_msg=msg)
520 results = yield omci_cc.send(frame)
521 self.check_status_and_state(results, 'create-mac-bridge-port-configuration-data-8021p-mapper')
522
523 except TimeoutError as e:
524 self.log.warn('rx-timeout-8021p-ani-port-setup', e=e)
525 raise
526
527 except Exception as e:
528 self.log.exception('omci-setup-8021p-ani-port-setup', e=e)
529 raise
Girish Gowdra322cca12020-08-09 15:55:54 -0700530
531 @inlineCallbacks
532 def _delete_and_recreate__8021p_mapper__ani_mac_bridge_port(self):
533
534 omci_cc = self._onu_device.omci_cc
535
536 try:
537
538 # First clean up the Gem Ports references by the old 8021pMapper
539 ieee_8021p_mapper = self._onu_device.query_mib(Ieee8021pMapperServiceProfile.class_id)
540 for k, v in ieee_8021p_mapper.items():
541 if not isinstance(v, dict):
542 continue
543 # Check the entity-id of the instance matches what we expect
544 # for this Uni/TechProfileId
545 if k == (self._ieee_mapper_service_profile_entity_id +
546 self._uni_port.mac_bridge_port_num + self._tp_table_id):
547 for i in range(8):
548 gem_entity_id = v.get('attributes', {}). \
549 get('interwork_tp_pointer_for_p_bit_priority_' + str(i), OmciNullPointer)
550 if gem_entity_id is not OmciNullPointer:
551 self.log.debug('remove-from-hardware', gem_id=gem_entity_id)
552 try:
553 msg = GemInterworkingTpFrame(gem_entity_id)
554 frame = msg.delete()
555 self.log.debug('openomci-msg', omci_msg=msg)
556 results = yield omci_cc.send(frame)
557 self.check_status_and_state(results, 'delete-gem-port-network-ctp')
558 except Exception as e:
559 self.log.exception('interworking-delete', e=e)
560 raise
561
562 try:
563 msg = GemPortNetworkCtpFrame(gem_entity_id)
564 frame = msg.delete()
565 self.log.debug('openomci-msg', omci_msg=msg)
566 results = yield omci_cc.send(frame)
567 self.check_status_and_state(results, 'delete-gem-interworking-tp')
568 except Exception as e:
569 self.log.exception('gemport-delete', e=e)
570 raise
571 break
572
573 # Then delete 8021pMapper ME
574 msg = Ieee8021pMapperServiceProfileFrame(
575 self._ieee_mapper_service_profile_entity_id +
576 self._uni_port.mac_bridge_port_num +
577 self._tp_table_id
578 )
579 frame = msg.delete()
580 self.log.debug('openomci-msg', omci_msg=msg)
581 results = yield omci_cc.send(frame)
582 self.check_status_and_state(results, 'delete-8021p-mapper-service-profile')
583
584 # Then delete ANI Mac Bridge port
585 msg = MacBridgePortConfigurationDataFrame(
586 self._mac_bridge_port_ani_entity_id + self._uni_port.entity_id + self._tp_table_id # Entity ID
587 )
588 frame = msg.delete()
589 self.log.debug('openomci-msg', omci_msg=msg)
590 results = yield omci_cc.send(frame)
591 self.check_status_and_state(results, 'delete-mac-bridge-port-configuration-data')
592
593 # TODO: We need not delete the TCONT as TCONTs are pre-created. We should possibly
594 # unset the TCONTs alloc-id from a valid value to 0xffff.
595 # But this was not causing issues in my test. A separate Jira is necessary for this.
596 yield self._setup__8021p_mapper__ani_mac_bridge_port()
597
598 except TimeoutError as e:
599 self.log.warn('rx-timeout-8021p-ani-port-delete', e=e)
600 raise
601
602 except Exception as e:
603 self.log.exception('omci-setup-8021p-ani-port-delete', e=e)
604 raise
605