blob: 9e16b89e4e61ed1d8c0c8a38857f39151dca3168 [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 Gowdrae933cd32019-11-21 21:04:41 +053021 Ieee8021pMapperServiceProfileFrame, MacBridgePortConfigurationDataFrame
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050022from pyvoltha.adapters.extensions.omci.tasks.task import Task
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050023from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
Matt Jeanneret4195d7d2020-01-12 16:58:18 -050024from pyvoltha.adapters.extensions.omci.omci_entities import OntG, Tcont, PriorityQueueG, Ieee8021pMapperServiceProfile, \
25 GemPortNetworkCtp
aishwaryarana0180594ce2019-07-26 15:31:14 -050026
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050027OP = EntityOperations
28RC = ReasonCodes
29
Girish Gowdrae933cd32019-11-21 21:04:41 +053030SETUP_TP_TASK_PRIORITY = 240
31
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050032
33class TechProfileDownloadFailure(Exception):
34 """
35 This error is raised by default when the download fails
36 """
37
38
39class TechProfileResourcesFailure(Exception):
40 """
41 This error is raised by when one or more resources required is not available
42 """
43
44
Girish Gowdrae933cd32019-11-21 21:04:41 +053045class BrcmTpSetupTask(Task):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050046 """
47 OpenOMCI Tech-Profile Download Task
48
49 """
50
51 name = "Broadcom Tech-Profile Download Task"
52
Girish Gowdrae933cd32019-11-21 21:04:41 +053053 def __init__(self, omci_agent, handler, uni_id, tconts, gem_ports, tp_table_id):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050054 """
55 Class initialization
56
57 :param omci_agent: (OmciAdapterAgent) OMCI Adapter agent
Matt Jeanneret810148b2019-09-29 12:44:01 -040058 :param handler: (BrcmOpenomciOnuHandler) ONU Device Handler Instance
59 :param uni_id: (int) numeric id of the uni port on the onu device, starts at 0
Girish Gowdrae933cd32019-11-21 21:04:41 +053060 :param tp_table_id: (int) Technology Profile Table-ID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050061 """
Girish Gowdrae933cd32019-11-21 21:04:41 +053062 super(BrcmTpSetupTask, self).__init__(BrcmTpSetupTask.name,
63 omci_agent,
64 handler.device_id,
65 priority=SETUP_TP_TASK_PRIORITY,
66 exclusive=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050067
Matt Jeanneret08a8e862019-12-20 14:02:32 -050068 self.log = structlog.get_logger(device_id=handler.device_id,
69 name=BrcmTpSetupTask.name,
70 task_id=self._task_id,
71 tconts=tconts,
72 gem_ports=gem_ports,
73 uni_id=uni_id,
74 tp_table_id=tp_table_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050075
76 self._onu_device = omci_agent.get_device(handler.device_id)
77 self._local_deferred = None
78
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050079 self._uni_port = handler.uni_ports[uni_id]
80 assert self._uni_port.uni_id == uni_id
81
Girish Gowdrae933cd32019-11-21 21:04:41 +053082 # Tech Profile Table ID
83 self._tp_table_id = tp_table_id
84
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050085 # Entity IDs. IDs with values can probably be most anything for most ONUs,
86 # IDs set to None are discovered/set
87
88 self._mac_bridge_service_profile_entity_id = \
89 handler.mac_bridge_service_profile_entity_id
90 self._ieee_mapper_service_profile_entity_id = \
91 handler.pon_port.ieee_mapper_service_profile_entity_id
92 self._mac_bridge_port_ani_entity_id = \
93 handler.pon_port.mac_bridge_port_ani_entity_id
94 self._gal_enet_profile_entity_id = \
95 handler.gal_enet_profile_entity_id
96
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050097 self._tconts = []
Girish Gowdrae933cd32019-11-21 21:04:41 +053098 for t in tconts:
99 self._tconts.append(t)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500100
101 self._gem_ports = []
Girish Gowdrae933cd32019-11-21 21:04:41 +0530102 for g in gem_ports:
103 self._gem_ports.append(g)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500104
105 self.tcont_me_to_queue_map = dict()
106 self.uni_port_to_queue_map = dict()
107
108 def cancel_deferred(self):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530109 super(BrcmTpSetupTask, self).cancel_deferred()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500110
111 d, self._local_deferred = self._local_deferred, None
112 try:
113 if d is not None and not d.called:
114 d.cancel()
115 except:
116 pass
117
118 def start(self):
119 """
120 Start the Tech-Profile Download
121 """
Girish Gowdrae933cd32019-11-21 21:04:41 +0530122 super(BrcmTpSetupTask, self).start()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500123 self._local_deferred = reactor.callLater(0, self.perform_service_specific_steps)
124
125 def stop(self):
126 """
127 Shutdown Tech-Profile download tasks
128 """
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500129 self.cancel_deferred()
Girish Gowdrae933cd32019-11-21 21:04:41 +0530130 super(BrcmTpSetupTask, self).stop()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500131
132 def check_status_and_state(self, results, operation=''):
133 """
134 Check the results of an OMCI response. An exception is thrown
135 if the task was cancelled or an error was detected.
136
137 :param results: (OmciFrame) OMCI Response frame
138 :param operation: (str) what operation was being performed
139 :return: True if successful, False if the entity existed (already created)
140 """
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500141
142 omci_msg = results.fields['omci_message'].fields
143 status = omci_msg['success_code']
144 error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
145 failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
146 unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
147
Matt Jeannerete8fc53e2019-04-13 15:58:33 -0400148 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg, status=status, error_mask=error_mask,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500149 failed_mask=failed_mask, unsupported_mask=unsupported_mask)
150
151 if status == RC.Success:
152 self.strobe_watchdog()
153 return True
154
155 elif status == RC.InstanceExists:
156 return False
157
158 raise TechProfileDownloadFailure(
Girish Gowdrae933cd32019-11-21 21:04:41 +0530159 '{} failed with a status of {}, error_mask: {}, failed_mask: {}, '
160 'unsupported_mask: {}'.format(operation, status, error_mask, failed_mask, unsupported_mask))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500161
162 @inlineCallbacks
163 def perform_service_specific_steps(self):
Mahir Gunyela982ec32020-02-25 12:30:37 -0800164 self.log.info('starting-tech-profile-setup', uni_id=self._uni_port.uni_id,
Girish Gowdraacb65b02020-07-12 20:35:47 -0700165 tconts=self._tconts, gem_ports=self._gem_ports, tp_table_id=self._tp_table_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500166
167 omci_cc = self._onu_device.omci_cc
aishwaryarana0180594ce2019-07-26 15:31:14 -0500168 gem_pq_associativity = dict()
169 pq_to_related_port = dict()
170 is_related_ports_configurable = False
Girish Gowdraacb65b02020-07-12 20:35:47 -0700171 tcont_entity_id = 0
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500172
173 try:
174 ################################################################################
175 # TCONTS
176 #
177 # EntityID will be referenced by:
178 # - GemPortNetworkCtp
179 # References:
180 # - ONU created TCONT (created on ONU startup)
181
Girish Gowdrae933cd32019-11-21 21:04:41 +0530182 # Setup 8021p mapper and ani mac bridge port, if it does not exist
183 # Querying just 8021p mapper ME should be enough since we create and
184 # delete 8021pMapper and ANI Mac Bridge Port together.
185 ieee_8021p_mapper_exists = False
186 ieee_8021p_mapper = self._onu_device.query_mib(Ieee8021pMapperServiceProfile.class_id)
187 for k, v in ieee_8021p_mapper.items():
188 if not isinstance(v, dict):
189 continue
190 if k == (self._ieee_mapper_service_profile_entity_id +
191 self._uni_port.mac_bridge_port_num + self._tp_table_id):
192 ieee_8021p_mapper_exists = True
193
194 if ieee_8021p_mapper_exists is False:
195 self.log.info("setting-up-8021pmapper-ani-mac-bridge-port")
196 yield self._setup__8021p_mapper__ani_mac_bridge_port()
197
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500198 tcont_idents = self._onu_device.query_mib(Tcont.class_id)
199 self.log.debug('tcont-idents', tcont_idents=tcont_idents)
200
Girish Gowdraacb65b02020-07-12 20:35:47 -0700201 # There can be only one tcont that can be installed per tech-profile download task
202 # Each tech-profile represents a single tcont and associated gemports
203 assert len(self._tconts) == 1
Girish Gowdra7c1240c2020-07-15 15:06:42 -0700204
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500205 for tcont in self._tconts:
206 self.log.debug('tcont-loop', tcont=tcont)
207
208 if tcont.entity_id is None:
209 free_entity_id = None
210 for k, v in tcont_idents.items():
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500211 if not isinstance(v, dict):
212 continue
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500213 alloc_check = v.get('attributes', {}).get('alloc_id', 0)
Girish Gowdraba4b1812020-07-17 12:21:26 -0700214 if alloc_check == tcont.alloc_id:
215 # If any Tcont entity already refers to the alloc-id we want to use,
216 # lets choose that Tcont entity.
217 # This Tcont will be re-added to ONU and that is fine. The ONU reports that
218 # the entity already exists, which is not an error.
219 free_entity_id = k
220 self.log.debug("tcont-entity-already-exists-on-onu-for-this-alloc-id",
221 tcont_entity_id=k, alloc_id=tcont.alloc_id)
222 break
223 elif alloc_check == 0xFF or alloc_check == 0xFFFF:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500224 free_entity_id = k
225 break
226
227 self.log.debug('tcont-loop-free', free_entity_id=free_entity_id, alloc_id=tcont.alloc_id)
228
229 if free_entity_id is None:
230 self.log.error('no-available-tconts')
231 break
232
233 # Also assign entity id within tcont object
234 results = yield tcont.add_to_hardware(omci_cc, free_entity_id)
235 self.check_status_and_state(results, 'new-tcont-added')
Girish Gowdraacb65b02020-07-12 20:35:47 -0700236 # There is only tcont to be added per tech-profile download procedure
237 # So, there is no issue of overwriting the 'tcont_entity_id'
238 tcont_entity_id = free_entity_id
239
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500240 else:
Matt Jeanneret4195d7d2020-01-12 16:58:18 -0500241 self.log.debug('tcont-already-assigned', tcont_entity_id=tcont.entity_id, alloc_id=tcont.alloc_id)
Girish Gowdra7c1240c2020-07-15 15:06:42 -0700242 tcont_entity_id = tcont.entity_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500243
244 ################################################################################
245 # GEMS (GemPortNetworkCtp and GemInterworkingTp)
246 #
247 # For both of these MEs, the entity_id is the GEM Port ID. The entity id of the
248 # GemInterworkingTp ME could be different since it has an attribute to specify
249 # the GemPortNetworkCtp entity id.
250 #
251 # for the GemPortNetworkCtp ME
252 #
253 # GemPortNetworkCtp
254 # EntityID will be referenced by:
255 # - GemInterworkingTp
256 # References:
257 # - TCONT
258 # - Hardcoded upstream TM Entity ID
259 # - (Possibly in Future) Upstream Traffic descriptor profile pointer
260 #
261 # GemInterworkingTp
262 # EntityID will be referenced by:
263 # - Ieee8021pMapperServiceProfile
264 # References:
265 # - GemPortNetworkCtp
266 # - Ieee8021pMapperServiceProfile
267 # - GalEthernetProfile
268 #
269
270 onu_g = self._onu_device.query_mib(OntG.class_id)
271 # If the traffic management option attribute in the ONU-G ME is 0
272 # (priority controlled) or 2 (priority and rate controlled), this
273 # pointer specifies the priority queue ME serving this GEM port
274 # network CTP. If the traffic management option attribute is 1
275 # (rate controlled), this attribute redundantly points to the
276 # T-CONT serving this GEM port network CTP.
277 traffic_mgmt_opt = \
278 onu_g.get('attributes', {}).get('traffic_management_options', 0)
279 self.log.debug("traffic-mgmt-option", traffic_mgmt_opt=traffic_mgmt_opt)
280
281 prior_q = self._onu_device.query_mib(PriorityQueueG.class_id)
282 for k, v in prior_q.items():
283 self.log.debug("prior-q", k=k, v=v)
284
285 try:
286 _ = iter(v)
287 except TypeError:
288 continue
289
Girish Gowdraacb65b02020-07-12 20:35:47 -0700290 # Parse PQ MEs only with relevant information
291 if 'instance_id' in v and 'related_port' in v['attributes']:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500292 related_port = v['attributes']['related_port']
aishwaryarana0180594ce2019-07-26 15:31:14 -0500293 pq_to_related_port[k] = related_port
Girish Gowdraacb65b02020-07-12 20:35:47 -0700294 # If the MSB is set, it represents an Upstream PQ referencing the TCONT
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500295 if v['instance_id'] & 0b1000000000000000:
Girish Gowdraacb65b02020-07-12 20:35:47 -0700296 # If it references the TCONT ME we have just installed
297 if tcont_entity_id == (related_port & 0xffff0000) >> 16:
298 if tcont_entity_id not in self.tcont_me_to_queue_map:
299 self.log.debug("prior-q-related-port-and-tcont-me",
300 related_port=related_port,
301 tcont_me=tcont_entity_id)
302 self.tcont_me_to_queue_map[tcont_entity_id] = list()
303 # Store the PQ into the list which is referenced by TCONT ME we have provisioned
304 self.tcont_me_to_queue_map[tcont_entity_id].append(k)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500305
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500306 else:
Girish Gowdraacb65b02020-07-12 20:35:47 -0700307 # This represents the PQ pointing to the UNI Port ME (Downstream PQ)
308 if self._uni_port.entity_id == (related_port & 0xffff0000) >> 16:
309 if self._uni_port.entity_id not in self.uni_port_to_queue_map:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500310 self.log.debug("prior-q-related-port-and-uni-port-me",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530311 related_port=related_port,
Girish Gowdraacb65b02020-07-12 20:35:47 -0700312 uni_port_me=self._uni_port.entity_id)
313 self.uni_port_to_queue_map[self._uni_port.entity_id] = list()
314 # Store the PQ into the list which is referenced by UNI Port ME we have provisioned
315 self.uni_port_to_queue_map[self._uni_port.entity_id].append(k)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500316
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500317 self.log.debug("ul-prior-q", ul_prior_q=self.tcont_me_to_queue_map)
318 self.log.debug("dl-prior-q", dl_prior_q=self.uni_port_to_queue_map)
319
320 for gem_port in self._gem_ports:
321 # TODO: Traffic descriptor will be available after meter bands are available
322 tcont = gem_port.tcont
323 if tcont is None:
324 self.log.error('unknown-tcont-reference', gem_id=gem_port.gem_id)
325 continue
326
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500327 if gem_port.direction == "upstream" or \
328 gem_port.direction == "bi-directional":
329
330 # Sort the priority queue list in order of priority.
331 # 0 is highest priority and 0x0fff is lowest.
332 self.tcont_me_to_queue_map[tcont.entity_id].sort()
333 self.uni_port_to_queue_map[self._uni_port.entity_id].sort()
aishwaryarana0180594ce2019-07-26 15:31:14 -0500334 # Get the priority queue by indexing the priority value of the gemport.
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500335 # The self.tcont_me_to_queue_map and self.uni_port_to_queue_map
336 # have priority queue entities ordered in descending order
337 # of priority
aishwaryarana0180594ce2019-07-26 15:31:14 -0500338
339 ul_prior_q_entity_id = \
340 self.tcont_me_to_queue_map[tcont.entity_id][gem_port.priority_q]
341 dl_prior_q_entity_id = \
342 self.uni_port_to_queue_map[self._uni_port.entity_id][gem_port.priority_q]
343
344 pq_attributes = dict()
345 pq_attributes["pq_entity_id"] = ul_prior_q_entity_id
346 pq_attributes["weight"] = gem_port.weight
347 pq_attributes["scheduling_policy"] = gem_port.scheduling_policy
348 pq_attributes["priority_q"] = gem_port.priority_q
349 gem_pq_associativity[gem_port.entity_id] = pq_attributes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500350
351 assert ul_prior_q_entity_id is not None and \
352 dl_prior_q_entity_id is not None
353
Matt Jeanneret4195d7d2020-01-12 16:58:18 -0500354 existing = self._onu_device.query_mib(GemPortNetworkCtp.class_id, gem_port.entity_id)
355 self.log.debug('looking-for-gemport-before-create', existing=existing,
356 class_id=GemPortNetworkCtp.class_id,
357 entity_id=gem_port.entity_id)
358 if existing:
359 results = yield gem_port.remove_from_hardware(omci_cc)
360 self.check_status_and_state(results, 'remove-existing-gem-port')
361
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500362 results = yield gem_port.add_to_hardware(omci_cc,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530363 tcont.entity_id,
364 self._ieee_mapper_service_profile_entity_id +
365 self._uni_port.mac_bridge_port_num +
366 self._tp_table_id,
367 self._gal_enet_profile_entity_id,
368 ul_prior_q_entity_id, dl_prior_q_entity_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500369 self.check_status_and_state(results, 'assign-gem-port')
370 elif gem_port.direction == "downstream":
371 # Downstream is inverse of upstream
372 # TODO: could also be a case of multicast. Not supported for now
373 self.log.debug("skipping-downstream-gem", gem_port=gem_port)
374 pass
375
376 ################################################################################
aishwaryarana0180594ce2019-07-26 15:31:14 -0500377 # Update the PriorityQeue Attributes for the PQ Associated with Gemport
378 #
379 # Entityt ID was created prior to this call. This is a set
380 #
381 #
382
383 ont2g = self._onu_device.query_mib(Ont2G.class_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530384 qos_config_flexibility_ie = ont2g.get(0, {}).get('attributes', {}). \
385 get('qos_configuration_flexibility', None)
aishwaryarana0180594ce2019-07-26 15:31:14 -0500386 self.log.debug("qos_config_flexibility",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530387 qos_config_flexibility=qos_config_flexibility_ie)
aishwaryarana0180594ce2019-07-26 15:31:14 -0500388
389 if qos_config_flexibility_ie & 0b100000:
390 is_related_ports_configurable = True
391
392 for k, v in gem_pq_associativity.items():
393 if v["scheduling_policy"] == "WRR":
394 self.log.debug("updating-pq-weight")
395 msg = PriorityQueueFrame(v["pq_entity_id"], weight=v["weight"])
396 frame = msg.set()
397 results = yield omci_cc.send(frame)
398 self.check_status_and_state(results, 'set-priority-queues-weight')
399 elif v["scheduling_policy"] == "StrictPriority" and \
400 is_related_ports_configurable:
401 self.log.debug("updating-pq-priority")
402 related_port = pq_to_related_port[v["pq_entity_id"]]
403 related_port = related_port & 0xffff0000
Girish Gowdrae933cd32019-11-21 21:04:41 +0530404 related_port = related_port | v['priority_q'] # Set priority
aishwaryarana0180594ce2019-07-26 15:31:14 -0500405 msg = PriorityQueueFrame(v["pq_entity_id"], related_port=related_port)
406 frame = msg.set()
407 results = yield omci_cc.send(frame)
408 self.check_status_and_state(results, 'set-priority-queues-priority')
409
aishwaryarana0180594ce2019-07-26 15:31:14 -0500410 ################################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500411 # Update the IEEE 802.1p Mapper Service Profile config
412 #
413 # EntityID was created prior to this call. This is a set
414 #
415 # References:
416 # - Gem Interwork TPs are set here
417 #
418
419 gem_entity_ids = [OmciNullPointer] * 8
Girish Gowdrae933cd32019-11-21 21:04:41 +0530420 # If IEEE8021pMapper ME existed already, then we need to re-build the
421 # inter-working-tp-pointers for different gem-entity-ids.
422 if ieee_8021p_mapper_exists:
423 self.log.debug("rebuilding-interworking-tp-pointers")
424 for k, v in ieee_8021p_mapper.items():
425 if not isinstance(v, dict):
426 continue
427 # Check the entity-id of the instance matches what we expect
428 # for this Uni/TechProfileId
429 if k == (self._ieee_mapper_service_profile_entity_id +
430 self._uni_port.mac_bridge_port_num + self._tp_table_id):
431 for i in range(len(gem_entity_ids)):
432 gem_entity_ids[i] = v.get('attributes', {}). \
433 get('interwork_tp_pointer_for_p_bit_priority_' + str(i), OmciNullPointer)
434 self.log.debug("interworking-tp-pointers-rebuilt-after-query-from-onu",
435 i_w_tp_ptr=gem_entity_ids)
436
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500437 for gem_port in self._gem_ports:
438 self.log.debug("tp-gem-port", entity_id=gem_port.entity_id, uni_id=gem_port.uni_id)
439
440 if gem_port.direction == "upstream" or \
441 gem_port.direction == "bi-directional":
442 for i, p in enumerate(reversed(gem_port.pbit_map)):
443 if p == '1':
444 gem_entity_ids[i] = gem_port.entity_id
445 elif gem_port.direction == "downstream":
446 # Downstream gem port p-bit mapper is inverse of upstream
447 # TODO: Could also be a case of multicast. Not supported for now
448 pass
449
450 msg = Ieee8021pMapperServiceProfileFrame(
Girish Gowdrae933cd32019-11-21 21:04:41 +0530451 (self._ieee_mapper_service_profile_entity_id +
452 self._uni_port.mac_bridge_port_num + self._tp_table_id),
453 # 802.1p mapper Service Mapper Profile ID
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500454 interwork_tp_pointers=gem_entity_ids # Interworking TP IDs
455 )
456 frame = msg.set()
457 self.log.debug('openomci-msg', omci_msg=msg)
458 results = yield omci_cc.send(frame)
459 self.check_status_and_state(results, 'set-8021p-mapper-service-profile-ul')
460
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500461 self.deferred.callback("tech-profile-download-success")
462
463 except TimeoutError as e:
Matt Jeanneret810148b2019-09-29 12:44:01 -0400464 self.log.warn('rx-timeout-tech-profile', e=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500465 self.deferred.errback(failure.Failure(e))
466
467 except Exception as e:
Matt Jeanneret810148b2019-09-29 12:44:01 -0400468 self.log.exception('omci-setup-tech-profile', e=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500469 self.deferred.errback(failure.Failure(e))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530470
471 @inlineCallbacks
472 def _setup__8021p_mapper__ani_mac_bridge_port(self):
473
474 omci_cc = self._onu_device.omci_cc
475
476 try:
477 ################################################################################
478 # PON Specific #
479 ################################################################################
480 # IEEE 802.1 Mapper Service config - One per tech-profile per UNI
481 #
482 # EntityID will be referenced by:
483 # - MAC Bridge Port Configuration Data for the PON port and TP ID
484 # References:
485 # - Nothing at this point. When a GEM port is created, this entity will
486 # be updated to reference the GEM Interworking TP
487
488 msg = Ieee8021pMapperServiceProfileFrame(
489 self._ieee_mapper_service_profile_entity_id +
490 self._uni_port.mac_bridge_port_num +
491 self._tp_table_id
492 )
493 frame = msg.create()
494 self.log.debug('openomci-msg', omci_msg=msg)
495 results = yield omci_cc.send(frame)
496 self.check_status_and_state(results, 'create-8021p-mapper-service-profile')
497
498 ################################################################################
499 # Create MAC Bridge Port Configuration Data for the PON port via IEEE 802.1
500 # mapper service and this per TechProfile. Upon receipt by the ONU, the ONU will create an instance
501 # of the following before returning the response.
502 #
503 # - MAC bridge port designation data
504 # - MAC bridge port filter table data
505 # - MAC bridge port bridge table data
506 #
507 # EntityID will be referenced by:
508 # - Implicitly by the VLAN tagging filter data
509 # References:
510 # - MAC Bridge Service Profile (the bridge)
511 # - IEEE 802.1p mapper service profile for PON port
512
513 # TODO: magic. make a static variable for tp_type
514 msg = MacBridgePortConfigurationDataFrame(
Matt Jeanneret2e5c6f12019-12-13 07:06:06 -0500515 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 +0530516 bridge_id_pointer=(
517 self._mac_bridge_service_profile_entity_id +
518 self._uni_port.mac_bridge_port_num),
519 # Bridge Entity ID
520 port_num=0xff, # Port ID - unique number within the bridge
521 tp_type=3, # TP Type (IEEE 802.1p mapper service)
522 tp_pointer=(
523 self._ieee_mapper_service_profile_entity_id +
524 self._uni_port.mac_bridge_port_num +
525 self._tp_table_id
526 )
527 # TP ID, 8021p mapper ID
528 )
529 frame = msg.create()
530 self.log.debug('openomci-msg', omci_msg=msg)
531 results = yield omci_cc.send(frame)
532 self.check_status_and_state(results, 'create-mac-bridge-port-configuration-data-8021p-mapper')
533
534 except TimeoutError as e:
535 self.log.warn('rx-timeout-8021p-ani-port-setup', e=e)
536 raise
537
538 except Exception as e:
539 self.log.exception('omci-setup-8021p-ani-port-setup', e=e)
540 raise