blob: cd7fc62631eaf3c34b432fe401e569c09c186840 [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
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400179 uni_port = self.uni_port(int(port_no))
180 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
181 self.log.debug('ofp_port_name', port_no=port_no, name=name)
182
Matt Jeanneretc083f462019-03-11 15:02:01 -0400183 return PortCapability(
184 port=LogicalPort(
185 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400186 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400187 hw_addr=hw_addr,
188 config=0,
189 state=OFPPS_LIVE,
190 curr=cap,
191 advertised=cap,
192 peer=cap,
193 curr_speed=OFPPF_1GB_FD,
194 max_speed=OFPPF_1GB_FD
195 ),
196 device_id=device.id,
197 device_port_no=port_no
198 )
199 )
200
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500201 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500202 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500203 def activate(self, device):
204 self.log.debug('function-entry', device=device)
205
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500206 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500207 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500208 assert device.proxy_address.device_id
209
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500210 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500211 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500212 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500213 if self.enabled is not True:
214 self.log.info('activating-new-onu')
215 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500216 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500217 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500218 device.reason = 'activating-onu'
219
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500220 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400221 # pm_metrics requires a logical device id. For now set to just device_id
222 self.logical_device_id = self.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
William Kurkian3a206332019-04-29 11:05:47 -0400261 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500262 def reconcile(self, device):
263 self.log.debug('function-entry', device=device)
264
265 # first we verify that we got parent reference and proxy info
266 assert device.parent_id
267 assert device.proxy_address.device_id
268
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500269 if self.enabled is not True:
270 self.log.info('reconciling-broadcom-onu-device')
271
272 self._init_pon_state(device)
273
274 # need to restart state machines on vcore restart. there is no indication to do it for us.
275 self._onu_omci_device.start()
276 device.reason = "restarting-openomci"
William Kurkian3a206332019-04-29 11:05:47 -0400277 yield self.core_proxy.update_device(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500278
279 # TODO: this is probably a bit heavy handed
280 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
281 # This may not be necessary when mib resync actually works
282 reactor.callLater(1, self.reboot)
283
284 self.enabled = True
285 else:
286 self.log.info('onu-already-activated')
287
288 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500289 def _init_pon_state(self, device):
290 self.log.debug('function-entry', device=device)
291
292 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500293 self._pon.add_peer(self.parent_id, self._pon_port_number)
294 self.log.debug('adding-pon-port-to-agent', pon=self._pon.get_port())
295
Matt Jeannereta32441c2019-03-07 05:16:37 -0500296 yield self.core_proxy.port_created(device.id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500297
Matt Jeanneret0c287892019-02-28 11:48:00 -0500298 self.log.debug('added-pon-port-to-agent', pon=self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500299
300 # Create and start the OpenOMCI ONU Device Entry for this ONU
301 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500302 self.core_proxy,
303 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500304 support_classes=self.adapter.broadcom_omci,
305 custom_me_map=self.adapter.custom_me_entities())
306 # Port startup
307 if self._pon is not None:
308 self._pon.enabled = True
309
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500310 def delete(self, device):
311 self.log.info('delete-onu', device=device)
312 if self.parent_adapter:
313 try:
314 self.parent_adapter.delete_child_device(self.parent_id, device)
315 except AttributeError:
316 self.log.debug('parent-device-delete-child-not-implemented')
317 else:
318 self.log.debug("parent-adapter-not-available")
319
320 def _create_tconts(self, uni_id, us_scheduler):
321 alloc_id = us_scheduler['alloc_id']
322 q_sched_policy = us_scheduler['q_sched_policy']
323 self.log.debug('create-tcont', us_scheduler=us_scheduler)
324
325 tcontdict = dict()
326 tcontdict['alloc-id'] = alloc_id
327 tcontdict['q_sched_policy'] = q_sched_policy
328 tcontdict['uni_id'] = uni_id
329
330 # TODO: Not sure what to do with any of this...
331 tddata = dict()
332 tddata['name'] = 'not-sure-td-profile'
333 tddata['fixed-bandwidth'] = "not-sure-fixed"
334 tddata['assured-bandwidth'] = "not-sure-assured"
335 tddata['maximum-bandwidth'] = "not-sure-max"
336 tddata['additional-bw-eligibility-indicator'] = "not-sure-additional"
337
338 td = OnuTrafficDescriptor.create(tddata)
339 tcont = OnuTCont.create(self, tcont=tcontdict, td=td)
340
341 self._pon.add_tcont(tcont)
342
343 self.log.debug('pon-add-tcont', tcont=tcont)
344
345 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
346 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
347 self.log.debug('create-gemport',
348 gem_ports=gem_ports, direction=direction)
349
350 for gem_port in gem_ports:
351 gemdict = dict()
352 gemdict['gemport_id'] = gem_port['gemport_id']
353 gemdict['direction'] = direction
354 gemdict['alloc_id_ref'] = alloc_id_ref
355 gemdict['encryption'] = gem_port['aes_encryption']
356 gemdict['discard_config'] = dict()
357 gemdict['discard_config']['max_probability'] = \
358 gem_port['discard_config']['max_probability']
359 gemdict['discard_config']['max_threshold'] = \
360 gem_port['discard_config']['max_threshold']
361 gemdict['discard_config']['min_threshold'] = \
362 gem_port['discard_config']['min_threshold']
363 gemdict['discard_policy'] = gem_port['discard_policy']
364 gemdict['max_q_size'] = gem_port['max_q_size']
365 gemdict['pbit_map'] = gem_port['pbit_map']
366 gemdict['priority_q'] = gem_port['priority_q']
367 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
368 gemdict['weight'] = gem_port['weight']
369 gemdict['uni_id'] = uni_id
370
371 gem_port = OnuGemPort.create(self, gem_port=gemdict)
372
373 self._pon.add_gem_port(gem_port)
374
375 self.log.debug('pon-add-gemport', gem_port=gem_port)
376
377 def _do_tech_profile_configuration(self, uni_id, tp):
378 num_of_tconts = tp['num_of_tconts']
379 us_scheduler = tp['us_scheduler']
380 alloc_id = us_scheduler['alloc_id']
381 self._create_tconts(uni_id, us_scheduler)
382 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
383 self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
384 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
385 self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
386
387 def load_and_configure_tech_profile(self, uni_id, tp_path):
388 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
389
390 if uni_id not in self._tp_service_specific_task:
391 self._tp_service_specific_task[uni_id] = dict()
392
393 if uni_id not in self._tech_profile_download_done:
394 self._tech_profile_download_done[uni_id] = dict()
395
396 if tp_path not in self._tech_profile_download_done[uni_id]:
397 self._tech_profile_download_done[uni_id][tp_path] = False
398
399 if not self._tech_profile_download_done[uni_id][tp_path]:
400 try:
401 if tp_path in self._tp_service_specific_task[uni_id]:
402 self.log.info("tech-profile-config-already-in-progress",
403 tp_path=tp_path)
404 return
405
406 tp = self.kv_client[tp_path]
407 tp = ast.literal_eval(tp)
408 self.log.debug("tp-instance", tp=tp)
409 self._do_tech_profile_configuration(uni_id, tp)
William Kurkian3a206332019-04-29 11:05:47 -0400410
411 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500412 def success(_results):
413 self.log.info("tech-profile-config-done-successfully")
William Kurkian3a206332019-04-29 11:05:47 -0400414 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500415 device.reason = 'tech-profile-config-download-success'
William Kurkian3a206332019-04-29 11:05:47 -0400416 yield self.core_proxy.update_device(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500417 if tp_path in self._tp_service_specific_task[uni_id]:
418 del self._tp_service_specific_task[uni_id][tp_path]
419 self._tech_profile_download_done[uni_id][tp_path] = True
420
William Kurkian3a206332019-04-29 11:05:47 -0400421 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500422 def failure(_reason):
423 self.log.warn('tech-profile-config-failure-retrying',
424 _reason=_reason)
William Kurkian3a206332019-04-29 11:05:47 -0400425 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500426 device.reason = 'tech-profile-config-download-failure-retrying'
William Kurkian3a206332019-04-29 11:05:47 -0400427 yield self.core_proxy.update_device(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500428 if tp_path in self._tp_service_specific_task[uni_id]:
429 del self._tp_service_specific_task[uni_id][tp_path]
430 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
431 uni_id, tp_path)
432
433 self.log.info('downloading-tech-profile-configuration')
434 self._tp_service_specific_task[uni_id][tp_path] = \
435 BrcmTpServiceSpecificTask(self.omci_agent, self, uni_id)
436 self._deferred = \
437 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
438 self._deferred.addCallbacks(success, failure)
439
440 except Exception as e:
441 self.log.exception("error-loading-tech-profile", e=e)
442 else:
443 self.log.info("tech-profile-config-already-done")
444
445 def update_pm_config(self, device, pm_config):
446 # TODO: This has not been tested
447 self.log.info('update_pm_config', pm_config=pm_config)
448 self.pm_metrics.update(pm_config)
449
450 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
451 # flow decomposition that ultimately comes from onos
452 def update_flow_table(self, device, flows):
453 self.log.debug('function-entry', device=device, flows=flows)
454
455 #
456 # We need to proxy through the OLT to get to the ONU
457 # Configuration from here should be using OMCI
458 #
459 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
460
461 # no point in pushing omci flows if the device isnt reachable
462 if device.connect_status != ConnectStatus.REACHABLE or \
463 device.admin_state != AdminState.ENABLED:
464 self.log.warn("device-disabled-or-offline-skipping-flow-update",
465 admin=device.admin_state, connect=device.connect_status)
466 return
467
468 def is_downstream(port):
469 return port == self._pon_port_number
470
471 def is_upstream(port):
472 return not is_downstream(port)
473
474 for flow in flows:
475 _type = None
476 _port = None
477 _vlan_vid = None
478 _udp_dst = None
479 _udp_src = None
480 _ipv4_dst = None
481 _ipv4_src = None
482 _metadata = None
483 _output = None
484 _push_tpid = None
485 _field = None
486 _set_vlan_vid = None
487 self.log.debug('bulk-flow-update', device_id=device.id, flow=flow)
488 try:
489 _in_port = fd.get_in_port(flow)
490 assert _in_port is not None
491
492 _out_port = fd.get_out_port(flow) # may be None
493
494 if is_downstream(_in_port):
495 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
496 uni_port = self.uni_port(_out_port)
497 elif is_upstream(_in_port):
498 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
499 uni_port = self.uni_port(_in_port)
500 else:
501 raise Exception('port should be 1 or 2 by our convention')
502
503 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
504
505 for field in fd.get_ofb_fields(flow):
506 if field.type == fd.ETH_TYPE:
507 _type = field.eth_type
508 self.log.debug('field-type-eth-type',
509 eth_type=_type)
510
511 elif field.type == fd.IP_PROTO:
512 _proto = field.ip_proto
513 self.log.debug('field-type-ip-proto',
514 ip_proto=_proto)
515
516 elif field.type == fd.IN_PORT:
517 _port = field.port
518 self.log.debug('field-type-in-port',
519 in_port=_port)
520
521 elif field.type == fd.VLAN_VID:
522 _vlan_vid = field.vlan_vid & 0xfff
523 self.log.debug('field-type-vlan-vid',
524 vlan=_vlan_vid)
525
526 elif field.type == fd.VLAN_PCP:
527 _vlan_pcp = field.vlan_pcp
528 self.log.debug('field-type-vlan-pcp',
529 pcp=_vlan_pcp)
530
531 elif field.type == fd.UDP_DST:
532 _udp_dst = field.udp_dst
533 self.log.debug('field-type-udp-dst',
534 udp_dst=_udp_dst)
535
536 elif field.type == fd.UDP_SRC:
537 _udp_src = field.udp_src
538 self.log.debug('field-type-udp-src',
539 udp_src=_udp_src)
540
541 elif field.type == fd.IPV4_DST:
542 _ipv4_dst = field.ipv4_dst
543 self.log.debug('field-type-ipv4-dst',
544 ipv4_dst=_ipv4_dst)
545
546 elif field.type == fd.IPV4_SRC:
547 _ipv4_src = field.ipv4_src
548 self.log.debug('field-type-ipv4-src',
549 ipv4_dst=_ipv4_src)
550
551 elif field.type == fd.METADATA:
552 _metadata = field.table_metadata
553 self.log.debug('field-type-metadata',
554 metadata=_metadata)
555
556 else:
557 raise NotImplementedError('field.type={}'.format(
558 field.type))
559
560 for action in fd.get_actions(flow):
561
562 if action.type == fd.OUTPUT:
563 _output = action.output.port
564 self.log.debug('action-type-output',
565 output=_output, in_port=_in_port)
566
567 elif action.type == fd.POP_VLAN:
568 self.log.debug('action-type-pop-vlan',
569 in_port=_in_port)
570
571 elif action.type == fd.PUSH_VLAN:
572 _push_tpid = action.push.ethertype
573 self.log.debug('action-type-push-vlan',
574 push_tpid=_push_tpid, in_port=_in_port)
575 if action.push.ethertype != 0x8100:
576 self.log.error('unhandled-tpid',
577 ethertype=action.push.ethertype)
578
579 elif action.type == fd.SET_FIELD:
580 _field = action.set_field.field.ofb_field
581 assert (action.set_field.field.oxm_class ==
582 OFPXMC_OPENFLOW_BASIC)
583 self.log.debug('action-type-set-field',
584 field=_field, in_port=_in_port)
585 if _field.type == fd.VLAN_VID:
586 _set_vlan_vid = _field.vlan_vid & 0xfff
587 self.log.debug('set-field-type-vlan-vid',
588 vlan_vid=_set_vlan_vid)
589 else:
590 self.log.error('unsupported-action-set-field-type',
591 field_type=_field.type)
592 else:
593 self.log.error('unsupported-action-type',
594 action_type=action.type, in_port=_in_port)
595
596 # TODO: We only set vlan omci flows. Handle omci matching ethertypes at some point in another task
597 if _type is not None:
598 self.log.warn('ignoring-flow-with-ethType', ethType=_type)
599 elif _set_vlan_vid is None or _set_vlan_vid == 0:
600 self.log.warn('ignorning-flow-that-does-not-set-vlanid')
601 else:
602 self.log.warn('set-vlanid', uni_id=uni_port.port_number, set_vlan_vid=_set_vlan_vid)
603 self._add_vlan_filter_task(device, uni_port, _set_vlan_vid)
604
605 except Exception as e:
606 self.log.exception('failed-to-install-flow', e=e, flow=flow)
607
608
609 def _add_vlan_filter_task(self, device, uni_port, _set_vlan_vid):
610 assert uni_port is not None
611
612 def success(_results):
613 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid)
614 device.reason = 'omci-flows-pushed'
615 self._vlan_filter_task = None
616
617 def failure(_reason):
618 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid)
619 device.reason = 'omci-flows-failed-retrying'
620 self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT,
621 self._add_vlan_filter_task, device, uni_port, _set_vlan_vid)
622
623 self.log.info('setting-vlan-tag')
624 self._vlan_filter_task = BrcmVlanFilterTask(self.omci_agent, self.device_id, uni_port, _set_vlan_vid)
625 self._deferred = self._onu_omci_device.task_runner.queue_task(self._vlan_filter_task)
626 self._deferred.addCallbacks(success, failure)
627
628 def get_tx_id(self):
629 self.log.debug('function-entry')
630 self.tx_id += 1
631 return self.tx_id
632
Matt Jeannereta32441c2019-03-07 05:16:37 -0500633 def process_inter_adapter_message(self, request):
634 self.log.debug('process-inter-adapter-message', msg=request)
635 try:
636 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
637 omci_msg = InterAdapterOmciMessage()
638 request.body.Unpack(omci_msg)
639 self.log.debug('inter-adapter-recv-omci', omci_msg=omci_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500640
Matt Jeannereta32441c2019-03-07 05:16:37 -0500641 self.receive_message(omci_msg.message)
642
643 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
644 onu_indication = OnuIndication()
645 request.body.Unpack(onu_indication)
646 self.log.debug('inter-adapter-recv-onu-ind', onu_indication=onu_indication)
647
648 if onu_indication.oper_state == "up":
649 self.create_interface(onu_indication)
650 elif onu_indication.oper_state == "down":
651 self.update_interface(onu_indication)
652 else:
653 self.log.error("unknown-onu-indication", onu_indication=onu_indication)
654
Matt Jeanneret3bfebff2019-04-12 18:25:03 -0400655 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
656 tech_msg = InterAdapterTechProfileDownloadMessage()
657 request.body.Unpack(tech_msg)
658 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
659
660 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
661
Matt Jeannereta32441c2019-03-07 05:16:37 -0500662 else:
663 self.log.error("inter-adapter-unhandled-type", request=request)
664
665 except Exception as e:
666 self.log.exception("error-processing-inter-adapter-message", e=e)
667
668 # Called each time there is an onu "up" indication from the olt handler
669 @inlineCallbacks
670 def create_interface(self, onu_indication):
671 self.log.debug('function-entry', onu_indication=onu_indication)
672 self._onu_indication = onu_indication
673
Matt Jeanneretc083f462019-03-11 15:02:01 -0400674 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
675 connect_status=ConnectStatus.REACHABLE)
676
Matt Jeannereta32441c2019-03-07 05:16:37 -0500677 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500678
679 self.log.debug('starting-openomci-statemachine')
680 self._subscribe_to_events()
681 reactor.callLater(1, self._onu_omci_device.start)
682 onu_device.reason = "starting-openomci"
Matt Jeannereta32441c2019-03-07 05:16:37 -0500683 yield self.core_proxy.device_update(onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500684 self._heartbeat.enabled = True
685
686 # Currently called each time there is an onu "down" indication from the olt handler
687 # TODO: possibly other reasons to "update" from the olt?
Matt Jeannereta32441c2019-03-07 05:16:37 -0500688 @inlineCallbacks
689 def update_interface(self, onu_indication):
690 self.log.debug('function-entry', onu_indication=onu_indication)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500691
Matt Jeannereta32441c2019-03-07 05:16:37 -0500692 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500693
Matt Jeannereta32441c2019-03-07 05:16:37 -0500694 if onu_indication.oper_state == 'down':
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500695 self.log.debug('stopping-openomci-statemachine')
696 reactor.callLater(0, self._onu_omci_device.stop)
697
698 # Let TP download happen again
699 for uni_id in self._tp_service_specific_task:
700 self._tp_service_specific_task[uni_id].clear()
701 for uni_id in self._tech_profile_download_done:
702 self._tech_profile_download_done[uni_id].clear()
703
704 self.disable_ports(onu_device)
705 onu_device.reason = "stopping-openomci"
706 onu_device.connect_status = ConnectStatus.UNREACHABLE
707 onu_device.oper_status = OperStatus.DISCOVERED
William Kurkian3a206332019-04-29 11:05:47 -0400708 yield self.core_proxy.update_device(onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500709 else:
710 self.log.debug('not-changing-openomci-statemachine')
711
712 # Not currently called by olt or anything else
William Kurkian3a206332019-04-29 11:05:47 -0400713 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500714 def remove_interface(self, data):
715 self.log.debug('function-entry', data=data)
716
William Kurkian3a206332019-04-29 11:05:47 -0400717 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500718
719 self.log.debug('stopping-openomci-statemachine')
720 reactor.callLater(0, self._onu_omci_device.stop)
721
722 # Let TP download happen again
723 for uni_id in self._tp_service_specific_task:
724 self._tp_service_specific_task[uni_id].clear()
725 for uni_id in self._tech_profile_download_done:
726 self._tech_profile_download_done[uni_id].clear()
727
728 self.disable_ports(onu_device)
729 onu_device.reason = "stopping-openomci"
William Kurkian3a206332019-04-29 11:05:47 -0400730 yield self.core_proxy.update_device(onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500731
732 # TODO: im sure there is more to do here
733
734 # Not currently called. Would be called presumably from the olt handler
William Kurkian3a206332019-04-29 11:05:47 -0400735 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500736 def remove_gemport(self, data):
737 self.log.debug('remove-gemport', data=data)
William Kurkian3a206332019-04-29 11:05:47 -0400738 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500739 if device.connect_status != ConnectStatus.REACHABLE:
740 self.log.error('device-unreachable')
741 return
742
743 # Not currently called. Would be called presumably from the olt handler
William Kurkian3a206332019-04-29 11:05:47 -0400744 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500745 def remove_tcont(self, tcont_data, traffic_descriptor_data):
746 self.log.debug('remove-tcont', tcont_data=tcont_data, traffic_descriptor_data=traffic_descriptor_data)
William Kurkian3a206332019-04-29 11:05:47 -0400747 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500748 if device.connect_status != ConnectStatus.REACHABLE:
749 self.log.error('device-unreachable')
750 return
751
752 # TODO: Create some omci task that encompases this what intended
753
754 # Not currently called. Would be called presumably from the olt handler
755 def create_multicast_gemport(self, data):
756 self.log.debug('function-entry', data=data)
757
758 # TODO: create objects and populate for later omci calls
759
William Kurkian3a206332019-04-29 11:05:47 -0400760 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500761 def disable(self, device):
762 self.log.debug('function-entry', device=device)
763 try:
764 self.log.info('sending-uni-lock-towards-device', device=device)
765
766 def stop_anyway(reason):
767 # proceed with disable regardless if we could reach the onu. for example onu is unplugged
768 self.log.debug('stopping-openomci-statemachine')
769 reactor.callLater(0, self._onu_omci_device.stop)
770
771 # Let TP download happen again
772 for uni_id in self._tp_service_specific_task:
773 self._tp_service_specific_task[uni_id].clear()
774 for uni_id in self._tech_profile_download_done:
775 self._tech_profile_download_done[uni_id].clear()
776
777 self.disable_ports(device)
778 device.oper_status = OperStatus.UNKNOWN
779 device.reason = "omci-admin-lock"
William Kurkian3a206332019-04-29 11:05:47 -0400780 yield self.core_proxy.update_device(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500781
782 # lock all the unis
783 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=True)
784 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
785 self._deferred.addCallbacks(stop_anyway, stop_anyway)
786 except Exception as e:
787 log.exception('exception-in-onu-disable', exception=e)
788
William Kurkian3a206332019-04-29 11:05:47 -0400789 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500790 def reenable(self, device):
791 self.log.debug('function-entry', device=device)
792 try:
793 # Start up OpenOMCI state machines for this device
794 # this will ultimately resync mib and unlock unis on successful redownloading the mib
795 self.log.debug('restarting-openomci-statemachine')
796 self._subscribe_to_events()
797 device.reason = "restarting-openomci"
William Kurkian3a206332019-04-29 11:05:47 -0400798 yield self.core_proxy.update_device(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500799 reactor.callLater(1, self._onu_omci_device.start)
800 self._heartbeat.enabled = True
801 except Exception as e:
802 log.exception('exception-in-onu-reenable', exception=e)
803
William Kurkian3a206332019-04-29 11:05:47 -0400804 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500805 def reboot(self):
806 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -0400807 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500808 if device.connect_status != ConnectStatus.REACHABLE:
809 self.log.error("device-unreachable")
810 return
811
William Kurkian3a206332019-04-29 11:05:47 -0400812 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500813 def success(_results):
814 self.log.info('reboot-success', _results=_results)
815 self.disable_ports(device)
816 device.connect_status = ConnectStatus.UNREACHABLE
817 device.oper_status = OperStatus.DISCOVERED
818 device.reason = "rebooting"
William Kurkian3a206332019-04-29 11:05:47 -0400819 yield self.core_proxy.update_device(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500820
821 def failure(_reason):
822 self.log.info('reboot-failure', _reason=_reason)
823
824 self._deferred = self._onu_omci_device.reboot()
825 self._deferred.addCallbacks(success, failure)
826
William Kurkian3a206332019-04-29 11:05:47 -0400827 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500828 def disable_ports(self, onu_device):
829 self.log.info('disable-ports', device_id=self.device_id,
830 onu_device=onu_device)
831
832 # Disable all ports on that device
William Kurkian3a206332019-04-29 11:05:47 -0400833 yield self.core_proxy.disable_all_ports(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500834
William Kurkian3a206332019-04-29 11:05:47 -0400835 parent_device = yield self.core_proxy.get_device(onu_device.parent_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500836 assert parent_device
837 logical_device_id = parent_device.parent_id
838 assert logical_device_id
William Kurkian3a206332019-04-29 11:05:47 -0400839 ports = yield self.core_proxy.get_ports(onu_device.id, Port.ETHERNET_UNI)
840 #TODO this should all be handled by the core
841 #for port in ports:
842 # port_id = 'uni-{}'.format(port.port_no)
843 # self.update_logical_port(logical_device_id, port_id, OFPPS_LINK_DOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500844
William Kurkian3a206332019-04-29 11:05:47 -0400845 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500846 def enable_ports(self, onu_device):
847 self.log.info('enable-ports', device_id=self.device_id, onu_device=onu_device)
848
849 # Disable all ports on that device
William Kurkian3a206332019-04-29 11:05:47 -0400850 self.core_proxy.enable_all_ports(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500851
William Kurkian3a206332019-04-29 11:05:47 -0400852 parent_device = yield self.core_proxy.get_device(onu_device.parent_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500853 assert parent_device
854 logical_device_id = parent_device.parent_id
855 assert logical_device_id
William Kurkian3a206332019-04-29 11:05:47 -0400856 ports = yield self.core_proxy.get_ports(onu_device.id, Port.ETHERNET_UNI)
857 #TODO this should be handled by the core
858 #for port in ports:
859 # port_id = 'uni-{}'.format(port.port_no)
860 # self.update_logical_port(logical_device_id, port_id, OFPPS_LIVE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500861
862 # Called just before openomci state machine is started. These listen for events from selected state machines,
863 # most importantly, mib in sync. Which ultimately leads to downloading the mib
864 def _subscribe_to_events(self):
865 self.log.debug('function-entry')
866
867 # OMCI MIB Database sync status
868 bus = self._onu_omci_device.event_bus
869 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
870 OnuDeviceEvents.MibDatabaseSyncEvent)
871 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
872
873 # OMCI Capabilities
874 bus = self._onu_omci_device.event_bus
875 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
876 OnuDeviceEvents.OmciCapabilitiesEvent)
877 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
878
879 # Called when the mib is in sync
880 def in_sync_handler(self, _topic, msg):
881 self.log.debug('function-entry', _topic=_topic, msg=msg)
882 if self._in_sync_subscription is not None:
883 try:
884 in_sync = msg[IN_SYNC_KEY]
885
886 if in_sync:
887 # Only call this once
888 bus = self._onu_omci_device.event_bus
889 bus.unsubscribe(self._in_sync_subscription)
890 self._in_sync_subscription = None
891
892 # Start up device_info load
893 self.log.debug('running-mib-sync')
894 reactor.callLater(0, self._mib_in_sync)
895
896 except Exception as e:
897 self.log.exception('in-sync', e=e)
898
899 def capabilties_handler(self, _topic, _msg):
900 self.log.debug('function-entry', _topic=_topic, msg=_msg)
901 if self._capabilities_subscription is not None:
902 self.log.debug('capabilities-handler-done')
903
904 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
905 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
906 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -0400907 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500908 def _mib_in_sync(self):
909 self.log.debug('function-entry')
910
911 omci = self._onu_omci_device
912 in_sync = omci.mib_db_in_sync
913
Matt Jeanneretc083f462019-03-11 15:02:01 -0400914 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500915 device.reason = 'discovery-mibsync-complete'
Matt Jeanneretc083f462019-03-11 15:02:01 -0400916 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500917
918 if not self._dev_info_loaded:
919 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
920
921 omci_dev = self._onu_omci_device
922 config = omci_dev.configuration
923
924 # TODO: run this sooner somehow. shouldnt have to wait for mib sync to push an initial download
925 # In Sync, we can register logical ports now. Ideally this could occur on
926 # the first time we received a successful (no timeout) OMCI Rx response.
927 try:
928
929 # sort the lists so we get consistent port ordering.
930 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
931 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
932 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
933 veip_list = sorted(config.veip_entities) if config.veip_entities else []
934
935 if ani_list is None or (pptp_list is None and veip_list is None):
936 device.reason = 'onu-missing-required-elements'
937 self.log.warn("no-ani-or-unis")
Matt Jeanneretc083f462019-03-11 15:02:01 -0400938 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500939 raise Exception("onu-missing-required-elements")
940
941 # Currently logging the ani, pptp, veip, and uni for information purposes.
942 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
943 # And in some ONU the UNI-G list is incomplete or incorrect...
944 for entity_id in ani_list:
945 ani_value = config.ani_g_entities[entity_id]
946 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
947 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
948 self._total_tcont_count = ani_value.get('total-tcont-count')
949 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
950
951 for entity_id in uni_list:
952 uni_value = config.uni_g_entities[entity_id]
953 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
954
955 uni_entities = OrderedDict()
956 for entity_id in pptp_list:
957 pptp_value = config.pptp_entities[entity_id]
958 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
959 uni_entities[entity_id] = UniType.PPTP
960
961 for entity_id in veip_list:
962 veip_value = config.veip_entities[entity_id]
963 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
964 uni_entities[entity_id] = UniType.VEIP
965
966 uni_id = 0
967 for entity_id, uni_type in uni_entities.iteritems():
968 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -0400969 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500970 uni_id += 1
971 except AssertionError as e:
972 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
973
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500974 self._qos_flexibility = config.qos_configuration_flexibility or 0
975 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
976
977 if self._unis:
978 self._dev_info_loaded = True
979 else:
980 device.reason = 'no-usable-unis'
Matt Jeanneretc083f462019-03-11 15:02:01 -0400981 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500982 self.log.warn("no-usable-unis")
983 raise Exception("no-usable-unis")
984
985 except Exception as e:
986 self.log.exception('device-info-load', e=e)
987 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
988
989 else:
990 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
991
992 if self._dev_info_loaded:
993 if device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -0400994
995 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500996 def success(_results):
997 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400998 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500999 device.reason = 'initial-mib-downloaded'
Matt Jeanneretc083f462019-03-11 15:02:01 -04001000 yield self.core_proxy.device_state_update(device.id,
1001 oper_status=OperStatus.ACTIVE, connect_status=ConnectStatus.REACHABLE)
1002 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001003 self._mib_download_task = None
1004
Matt Jeanneretc083f462019-03-11 15:02:01 -04001005 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001006 def failure(_reason):
1007 self.log.warn('mib-download-failure-retrying', _reason=_reason)
1008 device.reason = 'initial-mib-download-failure-retrying'
Matt Jeanneretc083f462019-03-11 15:02:01 -04001009 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001010 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1011
1012 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1013 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1014 self.log.info('downloading-initial-mib-configuration')
1015 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1016 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1017 self._deferred.addCallbacks(success, failure)
1018 else:
1019 self.log.info('admin-down-disabling')
1020 self.disable(device)
1021 else:
1022 self.log.info('device-info-not-loaded-skipping-mib-download')
1023
Matt Jeanneretc083f462019-03-11 15:02:01 -04001024 @inlineCallbacks
1025 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001026 self.log.debug('function-entry')
1027
Matt Jeanneretc083f462019-03-11 15:02:01 -04001028 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 -05001029
1030 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1031 uni_name = "uni-{}".format(uni_no)
1032
1033 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
1034
1035 self.log.debug('uni-port-inputs', uni_no=uni_no, uni_id=uni_id, uni_name=uni_name, uni_type=uni_type,
1036 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num)
1037
1038 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1039 uni_port.entity_id = entity_id
1040 uni_port.enabled = True
1041 uni_port.mac_bridge_port_num = mac_bridge_port_num
1042
1043 self.log.debug("created-uni-port", uni=uni_port)
1044
Matt Jeanneretc083f462019-03-11 15:02:01 -04001045 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001046
1047 self._unis[uni_port.port_number] = uni_port
1048
1049 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
1050 uni_ports=self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001051
Matt Jeanneretc083f462019-03-11 15:02:01 -04001052 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1053 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
1054 MAX_PONS_PER_OLT = 16
1055 MAX_ONUS_PER_PON = 32
1056 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001057
Matt Jeanneretc083f462019-03-11 15:02:01 -04001058 assert intf_id < MAX_PONS_PER_OLT
1059 assert onu_id < MAX_ONUS_PER_PON
1060 assert uni_id < MAX_UNIS_PER_ONU
Matt Jeanneret3b7db442019-04-22 16:29:48 -04001061 return intf_id << 11 | onu_id << 4 | uni_id