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