blob: bcd4fc489000e07f96317f4f90c18f72b74f1abc [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])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500256
257 #Start collecting stats from the device after a brief pause
258 reactor.callLater(10, self.pm_metrics.start_collector)
259
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500260 self.enabled = True
261 else:
262 self.log.info('onu-already-activated')
263
264 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400265 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500266 def reconcile(self, device):
267 self.log.debug('function-entry', device=device)
268
269 # first we verify that we got parent reference and proxy info
270 assert device.parent_id
271 assert device.proxy_address.device_id
272
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500273 if self.enabled is not True:
274 self.log.info('reconciling-broadcom-onu-device')
275
276 self._init_pon_state(device)
277
278 # need to restart state machines on vcore restart. there is no indication to do it for us.
279 self._onu_omci_device.start()
280 device.reason = "restarting-openomci"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400281 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500282
283 # TODO: this is probably a bit heavy handed
284 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
285 # This may not be necessary when mib resync actually works
286 reactor.callLater(1, self.reboot)
287
288 self.enabled = True
289 else:
290 self.log.info('onu-already-activated')
291
292 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500293 def _init_pon_state(self, device):
294 self.log.debug('function-entry', device=device)
295
296 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500297 self._pon.add_peer(self.parent_id, self._pon_port_number)
298 self.log.debug('adding-pon-port-to-agent', pon=self._pon.get_port())
299
Matt Jeannereta32441c2019-03-07 05:16:37 -0500300 yield self.core_proxy.port_created(device.id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500301
Matt Jeanneret0c287892019-02-28 11:48:00 -0500302 self.log.debug('added-pon-port-to-agent', pon=self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500303
304 # Create and start the OpenOMCI ONU Device Entry for this ONU
305 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500306 self.core_proxy,
307 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500308 support_classes=self.adapter.broadcom_omci,
309 custom_me_map=self.adapter.custom_me_entities())
310 # Port startup
311 if self._pon is not None:
312 self._pon.enabled = True
313
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500314 def delete(self, device):
315 self.log.info('delete-onu', device=device)
316 if self.parent_adapter:
317 try:
318 self.parent_adapter.delete_child_device(self.parent_id, device)
319 except AttributeError:
320 self.log.debug('parent-device-delete-child-not-implemented')
321 else:
322 self.log.debug("parent-adapter-not-available")
323
324 def _create_tconts(self, uni_id, us_scheduler):
325 alloc_id = us_scheduler['alloc_id']
326 q_sched_policy = us_scheduler['q_sched_policy']
327 self.log.debug('create-tcont', us_scheduler=us_scheduler)
328
329 tcontdict = dict()
330 tcontdict['alloc-id'] = alloc_id
331 tcontdict['q_sched_policy'] = q_sched_policy
332 tcontdict['uni_id'] = uni_id
333
334 # TODO: Not sure what to do with any of this...
335 tddata = dict()
336 tddata['name'] = 'not-sure-td-profile'
337 tddata['fixed-bandwidth'] = "not-sure-fixed"
338 tddata['assured-bandwidth'] = "not-sure-assured"
339 tddata['maximum-bandwidth'] = "not-sure-max"
340 tddata['additional-bw-eligibility-indicator'] = "not-sure-additional"
341
342 td = OnuTrafficDescriptor.create(tddata)
343 tcont = OnuTCont.create(self, tcont=tcontdict, td=td)
344
345 self._pon.add_tcont(tcont)
346
347 self.log.debug('pon-add-tcont', tcont=tcont)
348
349 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
350 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
351 self.log.debug('create-gemport',
352 gem_ports=gem_ports, direction=direction)
353
354 for gem_port in gem_ports:
355 gemdict = dict()
356 gemdict['gemport_id'] = gem_port['gemport_id']
357 gemdict['direction'] = direction
358 gemdict['alloc_id_ref'] = alloc_id_ref
359 gemdict['encryption'] = gem_port['aes_encryption']
360 gemdict['discard_config'] = dict()
361 gemdict['discard_config']['max_probability'] = \
362 gem_port['discard_config']['max_probability']
363 gemdict['discard_config']['max_threshold'] = \
364 gem_port['discard_config']['max_threshold']
365 gemdict['discard_config']['min_threshold'] = \
366 gem_port['discard_config']['min_threshold']
367 gemdict['discard_policy'] = gem_port['discard_policy']
368 gemdict['max_q_size'] = gem_port['max_q_size']
369 gemdict['pbit_map'] = gem_port['pbit_map']
370 gemdict['priority_q'] = gem_port['priority_q']
371 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
372 gemdict['weight'] = gem_port['weight']
373 gemdict['uni_id'] = uni_id
374
375 gem_port = OnuGemPort.create(self, gem_port=gemdict)
376
377 self._pon.add_gem_port(gem_port)
378
379 self.log.debug('pon-add-gemport', gem_port=gem_port)
380
381 def _do_tech_profile_configuration(self, uni_id, tp):
382 num_of_tconts = tp['num_of_tconts']
383 us_scheduler = tp['us_scheduler']
384 alloc_id = us_scheduler['alloc_id']
385 self._create_tconts(uni_id, us_scheduler)
386 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
387 self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
388 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
389 self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
390
391 def load_and_configure_tech_profile(self, uni_id, tp_path):
392 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
393
394 if uni_id not in self._tp_service_specific_task:
395 self._tp_service_specific_task[uni_id] = dict()
396
397 if uni_id not in self._tech_profile_download_done:
398 self._tech_profile_download_done[uni_id] = dict()
399
400 if tp_path not in self._tech_profile_download_done[uni_id]:
401 self._tech_profile_download_done[uni_id][tp_path] = False
402
403 if not self._tech_profile_download_done[uni_id][tp_path]:
404 try:
405 if tp_path in self._tp_service_specific_task[uni_id]:
406 self.log.info("tech-profile-config-already-in-progress",
407 tp_path=tp_path)
408 return
409
410 tp = self.kv_client[tp_path]
411 tp = ast.literal_eval(tp)
412 self.log.debug("tp-instance", tp=tp)
413 self._do_tech_profile_configuration(uni_id, tp)
William Kurkian3a206332019-04-29 11:05:47 -0400414
415 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500416 def success(_results):
417 self.log.info("tech-profile-config-done-successfully")
William Kurkian3a206332019-04-29 11:05:47 -0400418 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500419 device.reason = 'tech-profile-config-download-success'
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400420 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500421 if tp_path in self._tp_service_specific_task[uni_id]:
422 del self._tp_service_specific_task[uni_id][tp_path]
423 self._tech_profile_download_done[uni_id][tp_path] = True
424
William Kurkian3a206332019-04-29 11:05:47 -0400425 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500426 def failure(_reason):
427 self.log.warn('tech-profile-config-failure-retrying',
428 _reason=_reason)
William Kurkian3a206332019-04-29 11:05:47 -0400429 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500430 device.reason = 'tech-profile-config-download-failure-retrying'
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400431 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500432 if tp_path in self._tp_service_specific_task[uni_id]:
433 del self._tp_service_specific_task[uni_id][tp_path]
434 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
435 uni_id, tp_path)
436
437 self.log.info('downloading-tech-profile-configuration')
438 self._tp_service_specific_task[uni_id][tp_path] = \
439 BrcmTpServiceSpecificTask(self.omci_agent, self, uni_id)
440 self._deferred = \
441 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
442 self._deferred.addCallbacks(success, failure)
443
444 except Exception as e:
445 self.log.exception("error-loading-tech-profile", e=e)
446 else:
447 self.log.info("tech-profile-config-already-done")
448
449 def update_pm_config(self, device, pm_config):
450 # TODO: This has not been tested
451 self.log.info('update_pm_config', pm_config=pm_config)
452 self.pm_metrics.update(pm_config)
453
454 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
455 # flow decomposition that ultimately comes from onos
456 def update_flow_table(self, device, flows):
457 self.log.debug('function-entry', device=device, flows=flows)
458
459 #
460 # We need to proxy through the OLT to get to the ONU
461 # Configuration from here should be using OMCI
462 #
463 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
464
465 # no point in pushing omci flows if the device isnt reachable
466 if device.connect_status != ConnectStatus.REACHABLE or \
467 device.admin_state != AdminState.ENABLED:
468 self.log.warn("device-disabled-or-offline-skipping-flow-update",
469 admin=device.admin_state, connect=device.connect_status)
470 return
471
472 def is_downstream(port):
473 return port == self._pon_port_number
474
475 def is_upstream(port):
476 return not is_downstream(port)
477
478 for flow in flows:
479 _type = None
480 _port = None
481 _vlan_vid = None
482 _udp_dst = None
483 _udp_src = None
484 _ipv4_dst = None
485 _ipv4_src = None
486 _metadata = None
487 _output = None
488 _push_tpid = None
489 _field = None
490 _set_vlan_vid = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400491 _tunnel_id = None
492
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500493 self.log.debug('bulk-flow-update', device_id=device.id, flow=flow)
494 try:
495 _in_port = fd.get_in_port(flow)
496 assert _in_port is not None
497
498 _out_port = fd.get_out_port(flow) # may be None
499
500 if is_downstream(_in_port):
501 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
502 uni_port = self.uni_port(_out_port)
503 elif is_upstream(_in_port):
504 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
505 uni_port = self.uni_port(_in_port)
506 else:
507 raise Exception('port should be 1 or 2 by our convention')
508
509 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
510
511 for field in fd.get_ofb_fields(flow):
512 if field.type == fd.ETH_TYPE:
513 _type = field.eth_type
514 self.log.debug('field-type-eth-type',
515 eth_type=_type)
516
517 elif field.type == fd.IP_PROTO:
518 _proto = field.ip_proto
519 self.log.debug('field-type-ip-proto',
520 ip_proto=_proto)
521
522 elif field.type == fd.IN_PORT:
523 _port = field.port
524 self.log.debug('field-type-in-port',
525 in_port=_port)
526
527 elif field.type == fd.VLAN_VID:
528 _vlan_vid = field.vlan_vid & 0xfff
529 self.log.debug('field-type-vlan-vid',
530 vlan=_vlan_vid)
531
532 elif field.type == fd.VLAN_PCP:
533 _vlan_pcp = field.vlan_pcp
534 self.log.debug('field-type-vlan-pcp',
535 pcp=_vlan_pcp)
536
537 elif field.type == fd.UDP_DST:
538 _udp_dst = field.udp_dst
539 self.log.debug('field-type-udp-dst',
540 udp_dst=_udp_dst)
541
542 elif field.type == fd.UDP_SRC:
543 _udp_src = field.udp_src
544 self.log.debug('field-type-udp-src',
545 udp_src=_udp_src)
546
547 elif field.type == fd.IPV4_DST:
548 _ipv4_dst = field.ipv4_dst
549 self.log.debug('field-type-ipv4-dst',
550 ipv4_dst=_ipv4_dst)
551
552 elif field.type == fd.IPV4_SRC:
553 _ipv4_src = field.ipv4_src
554 self.log.debug('field-type-ipv4-src',
555 ipv4_dst=_ipv4_src)
556
557 elif field.type == fd.METADATA:
558 _metadata = field.table_metadata
559 self.log.debug('field-type-metadata',
560 metadata=_metadata)
561
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400562 elif field.type == fd.TUNNEL_ID:
563 _tunnel_id = field.tunnel_id
564 self.log.debug('field-type-tunnel-id',
565 tunnel_id=_tunnel_id)
566
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500567 else:
568 raise NotImplementedError('field.type={}'.format(
569 field.type))
570
571 for action in fd.get_actions(flow):
572
573 if action.type == fd.OUTPUT:
574 _output = action.output.port
575 self.log.debug('action-type-output',
576 output=_output, in_port=_in_port)
577
578 elif action.type == fd.POP_VLAN:
579 self.log.debug('action-type-pop-vlan',
580 in_port=_in_port)
581
582 elif action.type == fd.PUSH_VLAN:
583 _push_tpid = action.push.ethertype
584 self.log.debug('action-type-push-vlan',
585 push_tpid=_push_tpid, in_port=_in_port)
586 if action.push.ethertype != 0x8100:
587 self.log.error('unhandled-tpid',
588 ethertype=action.push.ethertype)
589
590 elif action.type == fd.SET_FIELD:
591 _field = action.set_field.field.ofb_field
592 assert (action.set_field.field.oxm_class ==
593 OFPXMC_OPENFLOW_BASIC)
594 self.log.debug('action-type-set-field',
595 field=_field, in_port=_in_port)
596 if _field.type == fd.VLAN_VID:
597 _set_vlan_vid = _field.vlan_vid & 0xfff
598 self.log.debug('set-field-type-vlan-vid',
599 vlan_vid=_set_vlan_vid)
600 else:
601 self.log.error('unsupported-action-set-field-type',
602 field_type=_field.type)
603 else:
604 self.log.error('unsupported-action-type',
605 action_type=action.type, in_port=_in_port)
606
607 # TODO: We only set vlan omci flows. Handle omci matching ethertypes at some point in another task
608 if _type is not None:
609 self.log.warn('ignoring-flow-with-ethType', ethType=_type)
610 elif _set_vlan_vid is None or _set_vlan_vid == 0:
611 self.log.warn('ignorning-flow-that-does-not-set-vlanid')
612 else:
613 self.log.warn('set-vlanid', uni_id=uni_port.port_number, set_vlan_vid=_set_vlan_vid)
614 self._add_vlan_filter_task(device, uni_port, _set_vlan_vid)
615
616 except Exception as e:
617 self.log.exception('failed-to-install-flow', e=e, flow=flow)
618
619
620 def _add_vlan_filter_task(self, device, uni_port, _set_vlan_vid):
621 assert uni_port is not None
622
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400623 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500624 def success(_results):
625 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid)
626 device.reason = 'omci-flows-pushed'
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400627 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500628 self._vlan_filter_task = None
629
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400630 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500631 def failure(_reason):
632 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid)
633 device.reason = 'omci-flows-failed-retrying'
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400634 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500635 self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT,
636 self._add_vlan_filter_task, device, uni_port, _set_vlan_vid)
637
638 self.log.info('setting-vlan-tag')
639 self._vlan_filter_task = BrcmVlanFilterTask(self.omci_agent, self.device_id, uni_port, _set_vlan_vid)
640 self._deferred = self._onu_omci_device.task_runner.queue_task(self._vlan_filter_task)
641 self._deferred.addCallbacks(success, failure)
642
643 def get_tx_id(self):
644 self.log.debug('function-entry')
645 self.tx_id += 1
646 return self.tx_id
647
Matt Jeannereta32441c2019-03-07 05:16:37 -0500648 def process_inter_adapter_message(self, request):
649 self.log.debug('process-inter-adapter-message', msg=request)
650 try:
651 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
652 omci_msg = InterAdapterOmciMessage()
653 request.body.Unpack(omci_msg)
654 self.log.debug('inter-adapter-recv-omci', omci_msg=omci_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500655
Matt Jeannereta32441c2019-03-07 05:16:37 -0500656 self.receive_message(omci_msg.message)
657
658 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
659 onu_indication = OnuIndication()
660 request.body.Unpack(onu_indication)
661 self.log.debug('inter-adapter-recv-onu-ind', onu_indication=onu_indication)
662
663 if onu_indication.oper_state == "up":
664 self.create_interface(onu_indication)
665 elif onu_indication.oper_state == "down":
666 self.update_interface(onu_indication)
667 else:
668 self.log.error("unknown-onu-indication", onu_indication=onu_indication)
669
Matt Jeanneret3bfebff2019-04-12 18:25:03 -0400670 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
671 tech_msg = InterAdapterTechProfileDownloadMessage()
672 request.body.Unpack(tech_msg)
673 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
674
675 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
676
Matt Jeannereta32441c2019-03-07 05:16:37 -0500677 else:
678 self.log.error("inter-adapter-unhandled-type", request=request)
679
680 except Exception as e:
681 self.log.exception("error-processing-inter-adapter-message", e=e)
682
683 # Called each time there is an onu "up" indication from the olt handler
684 @inlineCallbacks
685 def create_interface(self, onu_indication):
686 self.log.debug('function-entry', onu_indication=onu_indication)
687 self._onu_indication = onu_indication
688
Matt Jeanneretc083f462019-03-11 15:02:01 -0400689 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
690 connect_status=ConnectStatus.REACHABLE)
691
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
694 self.log.debug('starting-openomci-statemachine')
695 self._subscribe_to_events()
696 reactor.callLater(1, self._onu_omci_device.start)
697 onu_device.reason = "starting-openomci"
Matt Jeannereta32441c2019-03-07 05:16:37 -0500698 yield self.core_proxy.device_update(onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500699 self._heartbeat.enabled = True
700
701 # Currently called each time there is an onu "down" indication from the olt handler
702 # TODO: possibly other reasons to "update" from the olt?
Matt Jeannereta32441c2019-03-07 05:16:37 -0500703 @inlineCallbacks
704 def update_interface(self, onu_indication):
705 self.log.debug('function-entry', onu_indication=onu_indication)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500706
Matt Jeannereta32441c2019-03-07 05:16:37 -0500707 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500708
Matt Jeannereta32441c2019-03-07 05:16:37 -0500709 if onu_indication.oper_state == 'down':
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500710 self.log.debug('stopping-openomci-statemachine')
711 reactor.callLater(0, self._onu_omci_device.stop)
712
713 # Let TP download happen again
714 for uni_id in self._tp_service_specific_task:
715 self._tp_service_specific_task[uni_id].clear()
716 for uni_id in self._tech_profile_download_done:
717 self._tech_profile_download_done[uni_id].clear()
718
719 self.disable_ports(onu_device)
720 onu_device.reason = "stopping-openomci"
721 onu_device.connect_status = ConnectStatus.UNREACHABLE
722 onu_device.oper_status = OperStatus.DISCOVERED
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400723 yield self.core_proxy.device_update(onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500724 else:
725 self.log.debug('not-changing-openomci-statemachine')
726
727 # Not currently called by olt or anything else
William Kurkian3a206332019-04-29 11:05:47 -0400728 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500729 def remove_interface(self, data):
730 self.log.debug('function-entry', data=data)
731
William Kurkian3a206332019-04-29 11:05:47 -0400732 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500733
734 self.log.debug('stopping-openomci-statemachine')
735 reactor.callLater(0, self._onu_omci_device.stop)
736
737 # Let TP download happen again
738 for uni_id in self._tp_service_specific_task:
739 self._tp_service_specific_task[uni_id].clear()
740 for uni_id in self._tech_profile_download_done:
741 self._tech_profile_download_done[uni_id].clear()
742
743 self.disable_ports(onu_device)
744 onu_device.reason = "stopping-openomci"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400745 yield self.core_proxy.device_update(onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500746
747 # TODO: im sure there is more to do here
748
749 # Not currently called. Would be called presumably from the olt handler
William Kurkian3a206332019-04-29 11:05:47 -0400750 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500751 def remove_gemport(self, data):
752 self.log.debug('remove-gemport', data=data)
William Kurkian3a206332019-04-29 11:05:47 -0400753 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500754 if device.connect_status != ConnectStatus.REACHABLE:
755 self.log.error('device-unreachable')
756 return
757
758 # Not currently called. Would be called presumably from the olt handler
William Kurkian3a206332019-04-29 11:05:47 -0400759 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500760 def remove_tcont(self, tcont_data, traffic_descriptor_data):
761 self.log.debug('remove-tcont', tcont_data=tcont_data, traffic_descriptor_data=traffic_descriptor_data)
William Kurkian3a206332019-04-29 11:05:47 -0400762 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500763 if device.connect_status != ConnectStatus.REACHABLE:
764 self.log.error('device-unreachable')
765 return
766
767 # TODO: Create some omci task that encompases this what intended
768
769 # Not currently called. Would be called presumably from the olt handler
770 def create_multicast_gemport(self, data):
771 self.log.debug('function-entry', data=data)
772
773 # TODO: create objects and populate for later omci calls
774
775 def disable(self, device):
776 self.log.debug('function-entry', device=device)
777 try:
778 self.log.info('sending-uni-lock-towards-device', device=device)
779
Matt Jeanneret80766692019-05-03 09:58:38 -0400780 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500781 def stop_anyway(reason):
782 # proceed with disable regardless if we could reach the onu. for example onu is unplugged
783 self.log.debug('stopping-openomci-statemachine')
784 reactor.callLater(0, self._onu_omci_device.stop)
785
786 # Let TP download happen again
787 for uni_id in self._tp_service_specific_task:
788 self._tp_service_specific_task[uni_id].clear()
789 for uni_id in self._tech_profile_download_done:
790 self._tech_profile_download_done[uni_id].clear()
791
792 self.disable_ports(device)
793 device.oper_status = OperStatus.UNKNOWN
794 device.reason = "omci-admin-lock"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400795 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500796
797 # lock all the unis
798 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=True)
799 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
800 self._deferred.addCallbacks(stop_anyway, stop_anyway)
801 except Exception as e:
802 log.exception('exception-in-onu-disable', exception=e)
803
William Kurkian3a206332019-04-29 11:05:47 -0400804 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500805 def reenable(self, device):
806 self.log.debug('function-entry', device=device)
807 try:
808 # Start up OpenOMCI state machines for this device
809 # this will ultimately resync mib and unlock unis on successful redownloading the mib
810 self.log.debug('restarting-openomci-statemachine')
811 self._subscribe_to_events()
812 device.reason = "restarting-openomci"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400813 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500814 reactor.callLater(1, self._onu_omci_device.start)
815 self._heartbeat.enabled = True
816 except Exception as e:
817 log.exception('exception-in-onu-reenable', exception=e)
818
William Kurkian3a206332019-04-29 11:05:47 -0400819 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500820 def reboot(self):
821 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -0400822 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500823 if device.connect_status != ConnectStatus.REACHABLE:
824 self.log.error("device-unreachable")
825 return
826
William Kurkian3a206332019-04-29 11:05:47 -0400827 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500828 def success(_results):
829 self.log.info('reboot-success', _results=_results)
830 self.disable_ports(device)
831 device.connect_status = ConnectStatus.UNREACHABLE
832 device.oper_status = OperStatus.DISCOVERED
833 device.reason = "rebooting"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400834 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500835
836 def failure(_reason):
837 self.log.info('reboot-failure', _reason=_reason)
838
839 self._deferred = self._onu_omci_device.reboot()
840 self._deferred.addCallbacks(success, failure)
841
William Kurkian3a206332019-04-29 11:05:47 -0400842 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500843 def disable_ports(self, onu_device):
Matt Jeanneret80766692019-05-03 09:58:38 -0400844 self.log.info('disable-ports', device_id=self.device_id, onu_device=onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500845
846 # Disable all ports on that device
Matt Jeanneret80766692019-05-03 09:58:38 -0400847 yield self.core_proxy.ports_state_update(self.device_id, OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500848
William Kurkian3a206332019-04-29 11:05:47 -0400849 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500850 def enable_ports(self, onu_device):
851 self.log.info('enable-ports', device_id=self.device_id, onu_device=onu_device)
852
Matt Jeanneret80766692019-05-03 09:58:38 -0400853 # Enable all ports on that device
854 yield self.core_proxy.ports_state_update(self.device_id, OperStatus.ACTIVE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500855
856 # Called just before openomci state machine is started. These listen for events from selected state machines,
857 # most importantly, mib in sync. Which ultimately leads to downloading the mib
858 def _subscribe_to_events(self):
859 self.log.debug('function-entry')
860
861 # OMCI MIB Database sync status
862 bus = self._onu_omci_device.event_bus
863 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
864 OnuDeviceEvents.MibDatabaseSyncEvent)
865 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
866
867 # OMCI Capabilities
868 bus = self._onu_omci_device.event_bus
869 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
870 OnuDeviceEvents.OmciCapabilitiesEvent)
871 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
872
873 # Called when the mib is in sync
874 def in_sync_handler(self, _topic, msg):
875 self.log.debug('function-entry', _topic=_topic, msg=msg)
876 if self._in_sync_subscription is not None:
877 try:
878 in_sync = msg[IN_SYNC_KEY]
879
880 if in_sync:
881 # Only call this once
882 bus = self._onu_omci_device.event_bus
883 bus.unsubscribe(self._in_sync_subscription)
884 self._in_sync_subscription = None
885
886 # Start up device_info load
887 self.log.debug('running-mib-sync')
888 reactor.callLater(0, self._mib_in_sync)
889
890 except Exception as e:
891 self.log.exception('in-sync', e=e)
892
893 def capabilties_handler(self, _topic, _msg):
894 self.log.debug('function-entry', _topic=_topic, msg=_msg)
895 if self._capabilities_subscription is not None:
896 self.log.debug('capabilities-handler-done')
897
898 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
899 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
900 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -0400901 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500902 def _mib_in_sync(self):
903 self.log.debug('function-entry')
904
905 omci = self._onu_omci_device
906 in_sync = omci.mib_db_in_sync
907
Matt Jeanneretc083f462019-03-11 15:02:01 -0400908 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500909 device.reason = 'discovery-mibsync-complete'
Matt Jeanneretc083f462019-03-11 15:02:01 -0400910 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500911
912 if not self._dev_info_loaded:
913 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
914
915 omci_dev = self._onu_omci_device
916 config = omci_dev.configuration
917
918 # TODO: run this sooner somehow. shouldnt have to wait for mib sync to push an initial download
919 # In Sync, we can register logical ports now. Ideally this could occur on
920 # the first time we received a successful (no timeout) OMCI Rx response.
921 try:
922
923 # sort the lists so we get consistent port ordering.
924 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
925 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
926 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
927 veip_list = sorted(config.veip_entities) if config.veip_entities else []
928
929 if ani_list is None or (pptp_list is None and veip_list is None):
930 device.reason = 'onu-missing-required-elements'
931 self.log.warn("no-ani-or-unis")
Matt Jeanneretc083f462019-03-11 15:02:01 -0400932 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500933 raise Exception("onu-missing-required-elements")
934
935 # Currently logging the ani, pptp, veip, and uni for information purposes.
936 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
937 # And in some ONU the UNI-G list is incomplete or incorrect...
938 for entity_id in ani_list:
939 ani_value = config.ani_g_entities[entity_id]
940 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
941 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
942 self._total_tcont_count = ani_value.get('total-tcont-count')
943 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
944
945 for entity_id in uni_list:
946 uni_value = config.uni_g_entities[entity_id]
947 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
948
949 uni_entities = OrderedDict()
950 for entity_id in pptp_list:
951 pptp_value = config.pptp_entities[entity_id]
952 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
953 uni_entities[entity_id] = UniType.PPTP
954
955 for entity_id in veip_list:
956 veip_value = config.veip_entities[entity_id]
957 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
958 uni_entities[entity_id] = UniType.VEIP
959
960 uni_id = 0
961 for entity_id, uni_type in uni_entities.iteritems():
962 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -0400963 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500964 uni_id += 1
965 except AssertionError as e:
966 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
967
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500968 self._qos_flexibility = config.qos_configuration_flexibility or 0
969 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
970
971 if self._unis:
972 self._dev_info_loaded = True
973 else:
974 device.reason = 'no-usable-unis'
Matt Jeanneretc083f462019-03-11 15:02:01 -0400975 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500976 self.log.warn("no-usable-unis")
977 raise Exception("no-usable-unis")
978
979 except Exception as e:
980 self.log.exception('device-info-load', e=e)
981 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
982
983 else:
984 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
985
986 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -0400987 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -0400988
989 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500990 def success(_results):
991 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400992 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500993 device.reason = 'initial-mib-downloaded'
Matt Jeanneretc083f462019-03-11 15:02:01 -0400994 yield self.core_proxy.device_state_update(device.id,
995 oper_status=OperStatus.ACTIVE, connect_status=ConnectStatus.REACHABLE)
996 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500997 self._mib_download_task = None
998
Matt Jeanneretc083f462019-03-11 15:02:01 -0400999 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001000 def failure(_reason):
1001 self.log.warn('mib-download-failure-retrying', _reason=_reason)
1002 device.reason = 'initial-mib-download-failure-retrying'
Matt Jeanneretc083f462019-03-11 15:02:01 -04001003 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001004 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1005
1006 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1007 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1008 self.log.info('downloading-initial-mib-configuration')
1009 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1010 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1011 self._deferred.addCallbacks(success, failure)
1012 else:
1013 self.log.info('admin-down-disabling')
1014 self.disable(device)
1015 else:
1016 self.log.info('device-info-not-loaded-skipping-mib-download')
1017
Matt Jeanneretc083f462019-03-11 15:02:01 -04001018 @inlineCallbacks
1019 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001020 self.log.debug('function-entry')
1021
Matt Jeanneretc083f462019-03-11 15:02:01 -04001022 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 -05001023
1024 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1025 uni_name = "uni-{}".format(uni_no)
1026
1027 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
1028
1029 self.log.debug('uni-port-inputs', uni_no=uni_no, uni_id=uni_id, uni_name=uni_name, uni_type=uni_type,
1030 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num)
1031
1032 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1033 uni_port.entity_id = entity_id
1034 uni_port.enabled = True
1035 uni_port.mac_bridge_port_num = mac_bridge_port_num
1036
1037 self.log.debug("created-uni-port", uni=uni_port)
1038
Matt Jeanneretc083f462019-03-11 15:02:01 -04001039 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001040
1041 self._unis[uni_port.port_number] = uni_port
1042
1043 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
1044 uni_ports=self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001045
Matt Jeanneretc083f462019-03-11 15:02:01 -04001046 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1047 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
1048 MAX_PONS_PER_OLT = 16
1049 MAX_ONUS_PER_PON = 32
1050 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001051
Matt Jeanneretc083f462019-03-11 15:02:01 -04001052 assert intf_id < MAX_PONS_PER_OLT
1053 assert onu_id < MAX_ONUS_PER_PON
1054 assert uni_id < MAX_UNIS_PER_ONU
Matt Jeanneret3b7db442019-04-22 16:29:48 -04001055 return intf_id << 11 | onu_id << 4 | uni_id