blob: a58a870020a876c70120f708b98554024327d0b2 [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
2# Copyright 2017 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#
16
17"""
18Broadcom OpenOMCI OLT/ONU adapter handler.
19"""
20
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050021import ast
22import structlog
23
24from collections import OrderedDict
25
26from twisted.internet import reactor, task
27from twisted.internet.defer import DeferredQueue, inlineCallbacks, returnValue, TimeoutError
28
29from heartbeat import HeartBeat
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050030from pyvoltha.adapters.extensions.kpi.onu.onu_pm_metrics import OnuPmMetrics
31from pyvoltha.adapters.extensions.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
32from pyvoltha.adapters.extensions.alarms.adapter_alarms import AdapterAlarms
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050033
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050034import pyvoltha.common.openflow.utils as fd
35from pyvoltha.common.utils.registry import registry
36from pyvoltha.common.config.config_backend import ConsulStore
37from pyvoltha.common.config.config_backend import EtcdStore
William Kurkian8235c1e2019-03-05 12:58:28 -050038from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretc083f462019-03-11 15:02:01 -040039from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE, OFPPF_FIBER, OFPPF_1GB_FD
40from voltha_protos.inter_container_pb2 import InterAdapterMessageType, InterAdapterOmciMessage, PortCapability
Matt Jeannereta32441c2019-03-07 05:16:37 -050041from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050042from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
43from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050044 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050045from omci.brcm_mib_download_task import BrcmMibDownloadTask
46from omci.brcm_tp_service_specific_task import BrcmTpServiceSpecificTask
47from omci.brcm_uni_lock_task import BrcmUniLockTask
48from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
49from onu_gem_port import *
50from onu_tcont import *
51from pon_port import *
52from uni_port import *
53from onu_traffic_descriptor import *
54from pyvoltha.common.tech_profile.tech_profile import TechProfile
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050055
56OP = EntityOperations
57RC = ReasonCodes
58
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050059log = structlog.get_logger()
60
61_STARTUP_RETRY_WAIT = 20
62
63
64class BrcmOpenomciOnuHandler(object):
65
66 def __init__(self, adapter, device_id):
67 self.log = structlog.get_logger(device_id=device_id)
68 self.log.debug('function-entry')
69 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050070 self.core_proxy = adapter.core_proxy
71 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050072 self.parent_adapter = None
73 self.parent_id = None
74 self.device_id = device_id
75 self.incoming_messages = DeferredQueue()
76 self.event_messages = DeferredQueue()
77 self.proxy_address = None
78 self.tx_id = 0
79 self._enabled = False
80 self.alarms = None
81 self.pm_metrics = None
82 self._omcc_version = OMCCVersion.Unknown
83 self._total_tcont_count = 0 # From ANI-G ME
84 self._qos_flexibility = 0 # From ONT2_G ME
85
86 self._onu_indication = None
87 self._unis = dict() # Port # -> UniPort
88
89 self._pon = None
90 # TODO: probably shouldnt be hardcoded, determine from olt maybe?
91 self._pon_port_number = 100
92 self.logical_device_id = None
93
94 self._heartbeat = HeartBeat.create(self, device_id)
95
96 # Set up OpenOMCI environment
97 self._onu_omci_device = None
98 self._dev_info_loaded = False
99 self._deferred = None
100
101 self._in_sync_subscription = None
102 self._connectivity_subscription = None
103 self._capabilities_subscription = None
104
105 self.mac_bridge_service_profile_entity_id = 0x201
106 self.gal_enet_profile_entity_id = 0x1
107
108 self._tp_service_specific_task = dict()
109 self._tech_profile_download_done = dict()
110
111 # Initialize KV store client
112 self.args = registry('main').get_args()
113 if self.args.backend == 'etcd':
114 host, port = self.args.etcd.split(':', 1)
115 self.kv_client = EtcdStore(host, port,
116 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
117 elif self.args.backend == 'consul':
118 host, port = self.args.consul.split(':', 1)
119 self.kv_client = ConsulStore(host, port,
120 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
121 else:
122 self.log.error('Invalid-backend')
123 raise Exception("Invalid-backend-for-kv-store")
124
125 # Handle received ONU event messages
126 reactor.callLater(0, self.handle_onu_events)
127
128 @property
129 def enabled(self):
130 return self._enabled
131
132 @enabled.setter
133 def enabled(self, value):
134 if self._enabled != value:
135 self._enabled = value
136
137 @property
138 def omci_agent(self):
139 return self.adapter.omci_agent
140
141 @property
142 def omci_cc(self):
143 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
144
145 @property
146 def heartbeat(self):
147 return self._heartbeat
148
149 @property
150 def uni_ports(self):
151 return self._unis.values()
152
153 def uni_port(self, port_no_or_name):
154 if isinstance(port_no_or_name, (str, unicode)):
155 return next((uni for uni in self.uni_ports
156 if uni.name == port_no_or_name), None)
157
158 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
159 return next((uni for uni in self.uni_ports
160 if uni.logical_port_number == port_no_or_name), None)
161
162 @property
163 def pon_port(self):
164 return self._pon
165
166 def receive_message(self, msg):
167 if self.omci_cc is not None:
168 self.omci_cc.receive_message(msg)
169
Matt Jeanneretc083f462019-03-11 15:02:01 -0400170 def get_ofp_port_info(self, device, port_no):
171 self.log.info('get_ofp_port_info', port_no=port_no, device_id=device.id)
172 cap = OFPPF_1GB_FD | OFPPF_FIBER
173
174 hw_addr=mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
175 ((device.parent_port_no >> 8 & 0xff),
176 device.parent_port_no & 0xff,
177 (port_no >> 16) & 0xff,
178 (port_no >> 8) & 0xff,
179 port_no & 0xff))
180
181 return PortCapability(
182 port=LogicalPort(
183 ofp_port=ofp_port(
184 hw_addr=hw_addr,
185 config=0,
186 state=OFPPS_LIVE,
187 curr=cap,
188 advertised=cap,
189 peer=cap,
190 curr_speed=OFPPF_1GB_FD,
191 max_speed=OFPPF_1GB_FD
192 ),
193 device_id=device.id,
194 device_port_no=port_no
195 )
196 )
197
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500198 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500199 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500200 def activate(self, device):
201 self.log.debug('function-entry', device=device)
202
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500203 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500204 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500205 assert device.proxy_address.device_id
206
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500207 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500208 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500209 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500210
211 if self.enabled is not True:
212 self.log.info('activating-new-onu')
213 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500214 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500215 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500216 device.reason = 'activating-onu'
217
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500218 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500219 # pm_metrics requires a logical device id
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500220 #parent_device = yield self.adapter_agent.get_device(device.parent_id)
221 #self.logical_device_id = parent_device.parent_id
222 #assert self.logical_device_id, 'Invalid logical device ID'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500223
Matt Jeannereta32441c2019-03-07 05:16:37 -0500224 yield self.core_proxy.device_update(device)
225
226 yield self.core_proxy.device_state_update(device.id, oper_status=OperStatus.DISCOVERED,
227 connect_status=ConnectStatus.REACHABLE)
228
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500229
230 self.log.debug('set-device-discovered')
231
232 self._init_pon_state(device)
233
234 ############################################################################
235 # Setup PM configuration for this device
236 # Pass in ONU specific options
237 kwargs = {
238 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
239 'heartbeat': self.heartbeat,
240 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
241 }
Matt Jeannereta32441c2019-03-07 05:16:37 -0500242 self.pm_metrics = OnuPmMetrics(self.core_proxy, self.device_id,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500243 self.logical_device_id, grouped=True,
244 freq_override=False, **kwargs)
245 pm_config = self.pm_metrics.make_proto()
246 self._onu_omci_device.set_pm_config(self.pm_metrics.omci_pm.openomci_interval_pm)
247 self.log.info("initial-pm-config", pm_config=pm_config)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500248 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500249
250 ############################################################################
251 # Setup Alarm handler
Matt Jeannereta32441c2019-03-07 05:16:37 -0500252 self.alarms = AdapterAlarms(self.core_proxy, device.id, self.logical_device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500253 # Note, ONU ID and UNI intf set in add_uni_port method
254 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.alarms,
255 ani_ports=[self._pon])
256 self.enabled = True
257 else:
258 self.log.info('onu-already-activated')
259
260 # Called once when the adapter needs to re-create device. usually on vcore restart
261 def reconcile(self, device):
262 self.log.debug('function-entry', device=device)
263
264 # first we verify that we got parent reference and proxy info
265 assert device.parent_id
266 assert device.proxy_address.device_id
267
268 # register for proxied messages right away
269 self.proxy_address = device.proxy_address
270 self.adapter_agent.register_for_proxied_messages(device.proxy_address)
271
272 if self.enabled is not True:
273 self.log.info('reconciling-broadcom-onu-device')
274
275 self._init_pon_state(device)
276
277 # need to restart state machines on vcore restart. there is no indication to do it for us.
278 self._onu_omci_device.start()
279 device.reason = "restarting-openomci"
280 self.adapter_agent.update_device(device)
281
282 # TODO: this is probably a bit heavy handed
283 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
284 # This may not be necessary when mib resync actually works
285 reactor.callLater(1, self.reboot)
286
287 self.enabled = True
288 else:
289 self.log.info('onu-already-activated')
290
291 @inlineCallbacks
292 def handle_onu_events(self):
293 event_msg = yield self.event_messages.get()
294 try:
295 if event_msg['event'] == 'download_tech_profile':
296 tp_path = event_msg['event_data']
297 uni_id = event_msg['uni_id']
298 self.load_and_configure_tech_profile(uni_id, tp_path)
299
300 except Exception as e:
301 self.log.error("exception-handling-onu-event", e=e)
302
303 # Handle next event
304 reactor.callLater(0, self.handle_onu_events)
305
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500306 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500307 def _init_pon_state(self, device):
308 self.log.debug('function-entry', device=device)
309
310 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500311 self._pon.add_peer(self.parent_id, self._pon_port_number)
312 self.log.debug('adding-pon-port-to-agent', pon=self._pon.get_port())
313
Matt Jeannereta32441c2019-03-07 05:16:37 -0500314 yield self.core_proxy.port_created(device.id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500315
Matt Jeanneret0c287892019-02-28 11:48:00 -0500316 self.log.debug('added-pon-port-to-agent', pon=self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500317
318 # Create and start the OpenOMCI ONU Device Entry for this ONU
319 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500320 self.core_proxy,
321 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500322 support_classes=self.adapter.broadcom_omci,
323 custom_me_map=self.adapter.custom_me_entities())
324 # Port startup
325 if self._pon is not None:
326 self._pon.enabled = True
327
328 # TODO: move to UniPort
329 def update_logical_port(self, logical_device_id, port_id, state):
330 try:
331 self.log.info('updating-logical-port', logical_port_id=port_id,
332 logical_device_id=logical_device_id, state=state)
333 logical_port = self.adapter_agent.get_logical_port(logical_device_id,
334 port_id)
335 logical_port.ofp_port.state = state
336 self.adapter_agent.update_logical_port(logical_device_id,
337 logical_port)
338 except Exception as e:
339 self.log.exception("exception-updating-port", e=e)
340
341 def delete(self, device):
342 self.log.info('delete-onu', device=device)
343 if self.parent_adapter:
344 try:
345 self.parent_adapter.delete_child_device(self.parent_id, device)
346 except AttributeError:
347 self.log.debug('parent-device-delete-child-not-implemented')
348 else:
349 self.log.debug("parent-adapter-not-available")
350
351 def _create_tconts(self, uni_id, us_scheduler):
352 alloc_id = us_scheduler['alloc_id']
353 q_sched_policy = us_scheduler['q_sched_policy']
354 self.log.debug('create-tcont', us_scheduler=us_scheduler)
355
356 tcontdict = dict()
357 tcontdict['alloc-id'] = alloc_id
358 tcontdict['q_sched_policy'] = q_sched_policy
359 tcontdict['uni_id'] = uni_id
360
361 # TODO: Not sure what to do with any of this...
362 tddata = dict()
363 tddata['name'] = 'not-sure-td-profile'
364 tddata['fixed-bandwidth'] = "not-sure-fixed"
365 tddata['assured-bandwidth'] = "not-sure-assured"
366 tddata['maximum-bandwidth'] = "not-sure-max"
367 tddata['additional-bw-eligibility-indicator'] = "not-sure-additional"
368
369 td = OnuTrafficDescriptor.create(tddata)
370 tcont = OnuTCont.create(self, tcont=tcontdict, td=td)
371
372 self._pon.add_tcont(tcont)
373
374 self.log.debug('pon-add-tcont', tcont=tcont)
375
376 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
377 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
378 self.log.debug('create-gemport',
379 gem_ports=gem_ports, direction=direction)
380
381 for gem_port in gem_ports:
382 gemdict = dict()
383 gemdict['gemport_id'] = gem_port['gemport_id']
384 gemdict['direction'] = direction
385 gemdict['alloc_id_ref'] = alloc_id_ref
386 gemdict['encryption'] = gem_port['aes_encryption']
387 gemdict['discard_config'] = dict()
388 gemdict['discard_config']['max_probability'] = \
389 gem_port['discard_config']['max_probability']
390 gemdict['discard_config']['max_threshold'] = \
391 gem_port['discard_config']['max_threshold']
392 gemdict['discard_config']['min_threshold'] = \
393 gem_port['discard_config']['min_threshold']
394 gemdict['discard_policy'] = gem_port['discard_policy']
395 gemdict['max_q_size'] = gem_port['max_q_size']
396 gemdict['pbit_map'] = gem_port['pbit_map']
397 gemdict['priority_q'] = gem_port['priority_q']
398 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
399 gemdict['weight'] = gem_port['weight']
400 gemdict['uni_id'] = uni_id
401
402 gem_port = OnuGemPort.create(self, gem_port=gemdict)
403
404 self._pon.add_gem_port(gem_port)
405
406 self.log.debug('pon-add-gemport', gem_port=gem_port)
407
408 def _do_tech_profile_configuration(self, uni_id, tp):
409 num_of_tconts = tp['num_of_tconts']
410 us_scheduler = tp['us_scheduler']
411 alloc_id = us_scheduler['alloc_id']
412 self._create_tconts(uni_id, us_scheduler)
413 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
414 self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
415 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
416 self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
417
418 def load_and_configure_tech_profile(self, uni_id, tp_path):
419 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
420
421 if uni_id not in self._tp_service_specific_task:
422 self._tp_service_specific_task[uni_id] = dict()
423
424 if uni_id not in self._tech_profile_download_done:
425 self._tech_profile_download_done[uni_id] = dict()
426
427 if tp_path not in self._tech_profile_download_done[uni_id]:
428 self._tech_profile_download_done[uni_id][tp_path] = False
429
430 if not self._tech_profile_download_done[uni_id][tp_path]:
431 try:
432 if tp_path in self._tp_service_specific_task[uni_id]:
433 self.log.info("tech-profile-config-already-in-progress",
434 tp_path=tp_path)
435 return
436
437 tp = self.kv_client[tp_path]
438 tp = ast.literal_eval(tp)
439 self.log.debug("tp-instance", tp=tp)
440 self._do_tech_profile_configuration(uni_id, tp)
441
442 def success(_results):
443 self.log.info("tech-profile-config-done-successfully")
444 device = self.adapter_agent.get_device(self.device_id)
445 device.reason = 'tech-profile-config-download-success'
446 self.adapter_agent.update_device(device)
447 if tp_path in self._tp_service_specific_task[uni_id]:
448 del self._tp_service_specific_task[uni_id][tp_path]
449 self._tech_profile_download_done[uni_id][tp_path] = True
450
451 def failure(_reason):
452 self.log.warn('tech-profile-config-failure-retrying',
453 _reason=_reason)
454 device = self.adapter_agent.get_device(self.device_id)
455 device.reason = 'tech-profile-config-download-failure-retrying'
456 self.adapter_agent.update_device(device)
457 if tp_path in self._tp_service_specific_task[uni_id]:
458 del self._tp_service_specific_task[uni_id][tp_path]
459 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
460 uni_id, tp_path)
461
462 self.log.info('downloading-tech-profile-configuration')
463 self._tp_service_specific_task[uni_id][tp_path] = \
464 BrcmTpServiceSpecificTask(self.omci_agent, self, uni_id)
465 self._deferred = \
466 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
467 self._deferred.addCallbacks(success, failure)
468
469 except Exception as e:
470 self.log.exception("error-loading-tech-profile", e=e)
471 else:
472 self.log.info("tech-profile-config-already-done")
473
474 def update_pm_config(self, device, pm_config):
475 # TODO: This has not been tested
476 self.log.info('update_pm_config', pm_config=pm_config)
477 self.pm_metrics.update(pm_config)
478
479 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
480 # flow decomposition that ultimately comes from onos
481 def update_flow_table(self, device, flows):
482 self.log.debug('function-entry', device=device, flows=flows)
483
484 #
485 # We need to proxy through the OLT to get to the ONU
486 # Configuration from here should be using OMCI
487 #
488 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
489
490 # no point in pushing omci flows if the device isnt reachable
491 if device.connect_status != ConnectStatus.REACHABLE or \
492 device.admin_state != AdminState.ENABLED:
493 self.log.warn("device-disabled-or-offline-skipping-flow-update",
494 admin=device.admin_state, connect=device.connect_status)
495 return
496
497 def is_downstream(port):
498 return port == self._pon_port_number
499
500 def is_upstream(port):
501 return not is_downstream(port)
502
503 for flow in flows:
504 _type = None
505 _port = None
506 _vlan_vid = None
507 _udp_dst = None
508 _udp_src = None
509 _ipv4_dst = None
510 _ipv4_src = None
511 _metadata = None
512 _output = None
513 _push_tpid = None
514 _field = None
515 _set_vlan_vid = None
516 self.log.debug('bulk-flow-update', device_id=device.id, flow=flow)
517 try:
518 _in_port = fd.get_in_port(flow)
519 assert _in_port is not None
520
521 _out_port = fd.get_out_port(flow) # may be None
522
523 if is_downstream(_in_port):
524 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
525 uni_port = self.uni_port(_out_port)
526 elif is_upstream(_in_port):
527 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
528 uni_port = self.uni_port(_in_port)
529 else:
530 raise Exception('port should be 1 or 2 by our convention')
531
532 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
533
534 for field in fd.get_ofb_fields(flow):
535 if field.type == fd.ETH_TYPE:
536 _type = field.eth_type
537 self.log.debug('field-type-eth-type',
538 eth_type=_type)
539
540 elif field.type == fd.IP_PROTO:
541 _proto = field.ip_proto
542 self.log.debug('field-type-ip-proto',
543 ip_proto=_proto)
544
545 elif field.type == fd.IN_PORT:
546 _port = field.port
547 self.log.debug('field-type-in-port',
548 in_port=_port)
549
550 elif field.type == fd.VLAN_VID:
551 _vlan_vid = field.vlan_vid & 0xfff
552 self.log.debug('field-type-vlan-vid',
553 vlan=_vlan_vid)
554
555 elif field.type == fd.VLAN_PCP:
556 _vlan_pcp = field.vlan_pcp
557 self.log.debug('field-type-vlan-pcp',
558 pcp=_vlan_pcp)
559
560 elif field.type == fd.UDP_DST:
561 _udp_dst = field.udp_dst
562 self.log.debug('field-type-udp-dst',
563 udp_dst=_udp_dst)
564
565 elif field.type == fd.UDP_SRC:
566 _udp_src = field.udp_src
567 self.log.debug('field-type-udp-src',
568 udp_src=_udp_src)
569
570 elif field.type == fd.IPV4_DST:
571 _ipv4_dst = field.ipv4_dst
572 self.log.debug('field-type-ipv4-dst',
573 ipv4_dst=_ipv4_dst)
574
575 elif field.type == fd.IPV4_SRC:
576 _ipv4_src = field.ipv4_src
577 self.log.debug('field-type-ipv4-src',
578 ipv4_dst=_ipv4_src)
579
580 elif field.type == fd.METADATA:
581 _metadata = field.table_metadata
582 self.log.debug('field-type-metadata',
583 metadata=_metadata)
584
585 else:
586 raise NotImplementedError('field.type={}'.format(
587 field.type))
588
589 for action in fd.get_actions(flow):
590
591 if action.type == fd.OUTPUT:
592 _output = action.output.port
593 self.log.debug('action-type-output',
594 output=_output, in_port=_in_port)
595
596 elif action.type == fd.POP_VLAN:
597 self.log.debug('action-type-pop-vlan',
598 in_port=_in_port)
599
600 elif action.type == fd.PUSH_VLAN:
601 _push_tpid = action.push.ethertype
602 self.log.debug('action-type-push-vlan',
603 push_tpid=_push_tpid, in_port=_in_port)
604 if action.push.ethertype != 0x8100:
605 self.log.error('unhandled-tpid',
606 ethertype=action.push.ethertype)
607
608 elif action.type == fd.SET_FIELD:
609 _field = action.set_field.field.ofb_field
610 assert (action.set_field.field.oxm_class ==
611 OFPXMC_OPENFLOW_BASIC)
612 self.log.debug('action-type-set-field',
613 field=_field, in_port=_in_port)
614 if _field.type == fd.VLAN_VID:
615 _set_vlan_vid = _field.vlan_vid & 0xfff
616 self.log.debug('set-field-type-vlan-vid',
617 vlan_vid=_set_vlan_vid)
618 else:
619 self.log.error('unsupported-action-set-field-type',
620 field_type=_field.type)
621 else:
622 self.log.error('unsupported-action-type',
623 action_type=action.type, in_port=_in_port)
624
625 # TODO: We only set vlan omci flows. Handle omci matching ethertypes at some point in another task
626 if _type is not None:
627 self.log.warn('ignoring-flow-with-ethType', ethType=_type)
628 elif _set_vlan_vid is None or _set_vlan_vid == 0:
629 self.log.warn('ignorning-flow-that-does-not-set-vlanid')
630 else:
631 self.log.warn('set-vlanid', uni_id=uni_port.port_number, set_vlan_vid=_set_vlan_vid)
632 self._add_vlan_filter_task(device, uni_port, _set_vlan_vid)
633
634 except Exception as e:
635 self.log.exception('failed-to-install-flow', e=e, flow=flow)
636
637
638 def _add_vlan_filter_task(self, device, uni_port, _set_vlan_vid):
639 assert uni_port is not None
640
641 def success(_results):
642 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid)
643 device.reason = 'omci-flows-pushed'
644 self._vlan_filter_task = None
645
646 def failure(_reason):
647 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid)
648 device.reason = 'omci-flows-failed-retrying'
649 self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT,
650 self._add_vlan_filter_task, device, uni_port, _set_vlan_vid)
651
652 self.log.info('setting-vlan-tag')
653 self._vlan_filter_task = BrcmVlanFilterTask(self.omci_agent, self.device_id, uni_port, _set_vlan_vid)
654 self._deferred = self._onu_omci_device.task_runner.queue_task(self._vlan_filter_task)
655 self._deferred.addCallbacks(success, failure)
656
657 def get_tx_id(self):
658 self.log.debug('function-entry')
659 self.tx_id += 1
660 return self.tx_id
661
Matt Jeannereta32441c2019-03-07 05:16:37 -0500662 def process_inter_adapter_message(self, request):
663 self.log.debug('process-inter-adapter-message', msg=request)
664 try:
665 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
666 omci_msg = InterAdapterOmciMessage()
667 request.body.Unpack(omci_msg)
668 self.log.debug('inter-adapter-recv-omci', omci_msg=omci_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500669
Matt Jeannereta32441c2019-03-07 05:16:37 -0500670 self.receive_message(omci_msg.message)
671
672 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
673 onu_indication = OnuIndication()
674 request.body.Unpack(onu_indication)
675 self.log.debug('inter-adapter-recv-onu-ind', onu_indication=onu_indication)
676
677 if onu_indication.oper_state == "up":
678 self.create_interface(onu_indication)
679 elif onu_indication.oper_state == "down":
680 self.update_interface(onu_indication)
681 else:
682 self.log.error("unknown-onu-indication", onu_indication=onu_indication)
683
684 else:
685 self.log.error("inter-adapter-unhandled-type", request=request)
686
687 except Exception as e:
688 self.log.exception("error-processing-inter-adapter-message", e=e)
689
690 # Called each time there is an onu "up" indication from the olt handler
691 @inlineCallbacks
692 def create_interface(self, onu_indication):
693 self.log.debug('function-entry', onu_indication=onu_indication)
694 self._onu_indication = onu_indication
695
Matt Jeanneretc083f462019-03-11 15:02:01 -0400696 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
697 connect_status=ConnectStatus.REACHABLE)
698
Matt Jeannereta32441c2019-03-07 05:16:37 -0500699 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500700
701 self.log.debug('starting-openomci-statemachine')
702 self._subscribe_to_events()
703 reactor.callLater(1, self._onu_omci_device.start)
704 onu_device.reason = "starting-openomci"
Matt Jeannereta32441c2019-03-07 05:16:37 -0500705 yield self.core_proxy.device_update(onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500706 self._heartbeat.enabled = True
707
708 # Currently called each time there is an onu "down" indication from the olt handler
709 # TODO: possibly other reasons to "update" from the olt?
Matt Jeannereta32441c2019-03-07 05:16:37 -0500710 @inlineCallbacks
711 def update_interface(self, onu_indication):
712 self.log.debug('function-entry', onu_indication=onu_indication)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500713
Matt Jeannereta32441c2019-03-07 05:16:37 -0500714 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500715
Matt Jeannereta32441c2019-03-07 05:16:37 -0500716 if onu_indication.oper_state == 'down':
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500717 self.log.debug('stopping-openomci-statemachine')
718 reactor.callLater(0, self._onu_omci_device.stop)
719
720 # Let TP download happen again
721 for uni_id in self._tp_service_specific_task:
722 self._tp_service_specific_task[uni_id].clear()
723 for uni_id in self._tech_profile_download_done:
724 self._tech_profile_download_done[uni_id].clear()
725
726 self.disable_ports(onu_device)
727 onu_device.reason = "stopping-openomci"
728 onu_device.connect_status = ConnectStatus.UNREACHABLE
729 onu_device.oper_status = OperStatus.DISCOVERED
730 self.adapter_agent.update_device(onu_device)
731 else:
732 self.log.debug('not-changing-openomci-statemachine')
733
734 # Not currently called by olt or anything else
735 def remove_interface(self, data):
736 self.log.debug('function-entry', data=data)
737
738 onu_device = self.adapter_agent.get_device(self.device_id)
739
740 self.log.debug('stopping-openomci-statemachine')
741 reactor.callLater(0, self._onu_omci_device.stop)
742
743 # Let TP download happen again
744 for uni_id in self._tp_service_specific_task:
745 self._tp_service_specific_task[uni_id].clear()
746 for uni_id in self._tech_profile_download_done:
747 self._tech_profile_download_done[uni_id].clear()
748
749 self.disable_ports(onu_device)
750 onu_device.reason = "stopping-openomci"
751 self.adapter_agent.update_device(onu_device)
752
753 # TODO: im sure there is more to do here
754
755 # Not currently called. Would be called presumably from the olt handler
756 def remove_gemport(self, data):
757 self.log.debug('remove-gemport', data=data)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500758 device = self.adapter_agent.get_device(self.device_id)
759 if device.connect_status != ConnectStatus.REACHABLE:
760 self.log.error('device-unreachable')
761 return
762
763 # Not currently called. Would be called presumably from the olt handler
764 def remove_tcont(self, tcont_data, traffic_descriptor_data):
765 self.log.debug('remove-tcont', tcont_data=tcont_data, traffic_descriptor_data=traffic_descriptor_data)
766 device = self.adapter_agent.get_device(self.device_id)
767 if device.connect_status != ConnectStatus.REACHABLE:
768 self.log.error('device-unreachable')
769 return
770
771 # TODO: Create some omci task that encompases this what intended
772
773 # Not currently called. Would be called presumably from the olt handler
774 def create_multicast_gemport(self, data):
775 self.log.debug('function-entry', data=data)
776
777 # TODO: create objects and populate for later omci calls
778
779 def disable(self, device):
780 self.log.debug('function-entry', device=device)
781 try:
782 self.log.info('sending-uni-lock-towards-device', device=device)
783
784 def stop_anyway(reason):
785 # proceed with disable regardless if we could reach the onu. for example onu is unplugged
786 self.log.debug('stopping-openomci-statemachine')
787 reactor.callLater(0, self._onu_omci_device.stop)
788
789 # Let TP download happen again
790 for uni_id in self._tp_service_specific_task:
791 self._tp_service_specific_task[uni_id].clear()
792 for uni_id in self._tech_profile_download_done:
793 self._tech_profile_download_done[uni_id].clear()
794
795 self.disable_ports(device)
796 device.oper_status = OperStatus.UNKNOWN
797 device.reason = "omci-admin-lock"
798 self.adapter_agent.update_device(device)
799
800 # lock all the unis
801 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=True)
802 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
803 self._deferred.addCallbacks(stop_anyway, stop_anyway)
804 except Exception as e:
805 log.exception('exception-in-onu-disable', exception=e)
806
807 def reenable(self, device):
808 self.log.debug('function-entry', device=device)
809 try:
810 # Start up OpenOMCI state machines for this device
811 # this will ultimately resync mib and unlock unis on successful redownloading the mib
812 self.log.debug('restarting-openomci-statemachine')
813 self._subscribe_to_events()
814 device.reason = "restarting-openomci"
815 self.adapter_agent.update_device(device)
816 reactor.callLater(1, self._onu_omci_device.start)
817 self._heartbeat.enabled = True
818 except Exception as e:
819 log.exception('exception-in-onu-reenable', exception=e)
820
821 def reboot(self):
822 self.log.info('reboot-device')
823 device = self.adapter_agent.get_device(self.device_id)
824 if device.connect_status != ConnectStatus.REACHABLE:
825 self.log.error("device-unreachable")
826 return
827
828 def success(_results):
829 self.log.info('reboot-success', _results=_results)
830 self.disable_ports(device)
831 device.connect_status = ConnectStatus.UNREACHABLE
832 device.oper_status = OperStatus.DISCOVERED
833 device.reason = "rebooting"
834 self.adapter_agent.update_device(device)
835
836 def failure(_reason):
837 self.log.info('reboot-failure', _reason=_reason)
838
839 self._deferred = self._onu_omci_device.reboot()
840 self._deferred.addCallbacks(success, failure)
841
842 def disable_ports(self, onu_device):
843 self.log.info('disable-ports', device_id=self.device_id,
844 onu_device=onu_device)
845
846 # Disable all ports on that device
847 self.adapter_agent.disable_all_ports(self.device_id)
848
849 parent_device = self.adapter_agent.get_device(onu_device.parent_id)
850 assert parent_device
851 logical_device_id = parent_device.parent_id
852 assert logical_device_id
853 ports = self.adapter_agent.get_ports(onu_device.id, Port.ETHERNET_UNI)
854 for port in ports:
855 port_id = 'uni-{}'.format(port.port_no)
856 # TODO: move to UniPort
857 self.update_logical_port(logical_device_id, port_id, OFPPS_LINK_DOWN)
858
859 def enable_ports(self, onu_device):
860 self.log.info('enable-ports', device_id=self.device_id, onu_device=onu_device)
861
862 # Disable all ports on that device
863 self.adapter_agent.enable_all_ports(self.device_id)
864
865 parent_device = self.adapter_agent.get_device(onu_device.parent_id)
866 assert parent_device
867 logical_device_id = parent_device.parent_id
868 assert logical_device_id
869 ports = self.adapter_agent.get_ports(onu_device.id, Port.ETHERNET_UNI)
870 for port in ports:
871 port_id = 'uni-{}'.format(port.port_no)
872 # TODO: move to UniPort
873 self.update_logical_port(logical_device_id, port_id, OFPPS_LIVE)
874
875 # Called just before openomci state machine is started. These listen for events from selected state machines,
876 # most importantly, mib in sync. Which ultimately leads to downloading the mib
877 def _subscribe_to_events(self):
878 self.log.debug('function-entry')
879
880 # OMCI MIB Database sync status
881 bus = self._onu_omci_device.event_bus
882 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
883 OnuDeviceEvents.MibDatabaseSyncEvent)
884 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
885
886 # OMCI Capabilities
887 bus = self._onu_omci_device.event_bus
888 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
889 OnuDeviceEvents.OmciCapabilitiesEvent)
890 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
891
892 # Called when the mib is in sync
893 def in_sync_handler(self, _topic, msg):
894 self.log.debug('function-entry', _topic=_topic, msg=msg)
895 if self._in_sync_subscription is not None:
896 try:
897 in_sync = msg[IN_SYNC_KEY]
898
899 if in_sync:
900 # Only call this once
901 bus = self._onu_omci_device.event_bus
902 bus.unsubscribe(self._in_sync_subscription)
903 self._in_sync_subscription = None
904
905 # Start up device_info load
906 self.log.debug('running-mib-sync')
907 reactor.callLater(0, self._mib_in_sync)
908
909 except Exception as e:
910 self.log.exception('in-sync', e=e)
911
912 def capabilties_handler(self, _topic, _msg):
913 self.log.debug('function-entry', _topic=_topic, msg=_msg)
914 if self._capabilities_subscription is not None:
915 self.log.debug('capabilities-handler-done')
916
917 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
918 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
919 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -0400920 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500921 def _mib_in_sync(self):
922 self.log.debug('function-entry')
923
924 omci = self._onu_omci_device
925 in_sync = omci.mib_db_in_sync
926
Matt Jeanneretc083f462019-03-11 15:02:01 -0400927 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500928 device.reason = 'discovery-mibsync-complete'
Matt Jeanneretc083f462019-03-11 15:02:01 -0400929 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500930
931 if not self._dev_info_loaded:
932 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
933
934 omci_dev = self._onu_omci_device
935 config = omci_dev.configuration
936
937 # TODO: run this sooner somehow. shouldnt have to wait for mib sync to push an initial download
938 # In Sync, we can register logical ports now. Ideally this could occur on
939 # the first time we received a successful (no timeout) OMCI Rx response.
940 try:
941
942 # sort the lists so we get consistent port ordering.
943 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
944 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
945 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
946 veip_list = sorted(config.veip_entities) if config.veip_entities else []
947
948 if ani_list is None or (pptp_list is None and veip_list is None):
949 device.reason = 'onu-missing-required-elements'
950 self.log.warn("no-ani-or-unis")
Matt Jeanneretc083f462019-03-11 15:02:01 -0400951 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500952 raise Exception("onu-missing-required-elements")
953
954 # Currently logging the ani, pptp, veip, and uni for information purposes.
955 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
956 # And in some ONU the UNI-G list is incomplete or incorrect...
957 for entity_id in ani_list:
958 ani_value = config.ani_g_entities[entity_id]
959 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
960 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
961 self._total_tcont_count = ani_value.get('total-tcont-count')
962 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
963
964 for entity_id in uni_list:
965 uni_value = config.uni_g_entities[entity_id]
966 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
967
968 uni_entities = OrderedDict()
969 for entity_id in pptp_list:
970 pptp_value = config.pptp_entities[entity_id]
971 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
972 uni_entities[entity_id] = UniType.PPTP
973
974 for entity_id in veip_list:
975 veip_value = config.veip_entities[entity_id]
976 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
977 uni_entities[entity_id] = UniType.VEIP
978
979 uni_id = 0
980 for entity_id, uni_type in uni_entities.iteritems():
981 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -0400982 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500983 uni_id += 1
984 except AssertionError as e:
985 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
986
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500987 self._qos_flexibility = config.qos_configuration_flexibility or 0
988 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
989
990 if self._unis:
991 self._dev_info_loaded = True
992 else:
993 device.reason = 'no-usable-unis'
Matt Jeanneretc083f462019-03-11 15:02:01 -0400994 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500995 self.log.warn("no-usable-unis")
996 raise Exception("no-usable-unis")
997
998 except Exception as e:
999 self.log.exception('device-info-load', e=e)
1000 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1001
1002 else:
1003 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1004
1005 if self._dev_info_loaded:
1006 if device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001007
1008 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001009 def success(_results):
1010 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001011 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001012 device.reason = 'initial-mib-downloaded'
Matt Jeanneretc083f462019-03-11 15:02:01 -04001013 yield self.core_proxy.device_state_update(device.id,
1014 oper_status=OperStatus.ACTIVE, connect_status=ConnectStatus.REACHABLE)
1015 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001016 self._mib_download_task = None
1017
Matt Jeanneretc083f462019-03-11 15:02:01 -04001018 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001019 def failure(_reason):
1020 self.log.warn('mib-download-failure-retrying', _reason=_reason)
1021 device.reason = 'initial-mib-download-failure-retrying'
Matt Jeanneretc083f462019-03-11 15:02:01 -04001022 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001023 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1024
1025 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1026 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1027 self.log.info('downloading-initial-mib-configuration')
1028 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1029 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1030 self._deferred.addCallbacks(success, failure)
1031 else:
1032 self.log.info('admin-down-disabling')
1033 self.disable(device)
1034 else:
1035 self.log.info('device-info-not-loaded-skipping-mib-download')
1036
Matt Jeanneretc083f462019-03-11 15:02:01 -04001037 @inlineCallbacks
1038 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001039 self.log.debug('function-entry')
1040
Matt Jeanneretc083f462019-03-11 15:02:01 -04001041 uni_no = self.mk_uni_port_num(self._onu_indication.intf_id, self._onu_indication.onu_id, uni_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001042
1043 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1044 uni_name = "uni-{}".format(uni_no)
1045
1046 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
1047
1048 self.log.debug('uni-port-inputs', uni_no=uni_no, uni_id=uni_id, uni_name=uni_name, uni_type=uni_type,
1049 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num)
1050
1051 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1052 uni_port.entity_id = entity_id
1053 uni_port.enabled = True
1054 uni_port.mac_bridge_port_num = mac_bridge_port_num
1055
1056 self.log.debug("created-uni-port", uni=uni_port)
1057
Matt Jeanneretc083f462019-03-11 15:02:01 -04001058 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001059
1060 self._unis[uni_port.port_number] = uni_port
1061
1062 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
1063 uni_ports=self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001064
Matt Jeanneretc083f462019-03-11 15:02:01 -04001065 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1066 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
1067 MAX_PONS_PER_OLT = 16
1068 MAX_ONUS_PER_PON = 32
1069 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001070
Matt Jeanneretc083f462019-03-11 15:02:01 -04001071 assert intf_id < MAX_PONS_PER_OLT
1072 assert onu_id < MAX_ONUS_PER_PON
1073 assert uni_id < MAX_UNIS_PER_ONU
1074 return intf_id << 11 | onu_id << 4 | uni_id