blob: 7be75185dce5ab6c8b61eca4f5d7129ac1887f7e [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
Devmalya Paul7e0be4a2019-05-08 05:18:04 -040030from pyvoltha.adapters.extensions.alarms.onu.onu_active_alarm import OnuActiveAlarm
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050031from pyvoltha.adapters.extensions.kpi.onu.onu_pm_metrics import OnuPmMetrics
32from pyvoltha.adapters.extensions.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
33from pyvoltha.adapters.extensions.alarms.adapter_alarms import AdapterAlarms
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050034
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050035import pyvoltha.common.openflow.utils as fd
36from pyvoltha.common.utils.registry import registry
37from pyvoltha.common.config.config_backend import ConsulStore
38from pyvoltha.common.config.config_backend import EtcdStore
William Kurkian8235c1e2019-03-05 12:58:28 -050039from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretc083f462019-03-11 15:02:01 -040040from 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 -040041from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
42 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050043from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050044from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
45from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050046 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050047from omci.brcm_mib_download_task import BrcmMibDownloadTask
48from omci.brcm_tp_service_specific_task import BrcmTpServiceSpecificTask
49from omci.brcm_uni_lock_task import BrcmUniLockTask
50from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
51from onu_gem_port import *
52from onu_tcont import *
53from pon_port import *
54from uni_port import *
55from onu_traffic_descriptor import *
56from pyvoltha.common.tech_profile.tech_profile import TechProfile
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050057
58OP = EntityOperations
59RC = ReasonCodes
60
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050061log = structlog.get_logger()
62
63_STARTUP_RETRY_WAIT = 20
64
65
66class BrcmOpenomciOnuHandler(object):
67
68 def __init__(self, adapter, device_id):
69 self.log = structlog.get_logger(device_id=device_id)
70 self.log.debug('function-entry')
71 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050072 self.core_proxy = adapter.core_proxy
73 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050074 self.parent_adapter = None
75 self.parent_id = None
76 self.device_id = device_id
77 self.incoming_messages = DeferredQueue()
78 self.event_messages = DeferredQueue()
79 self.proxy_address = None
80 self.tx_id = 0
81 self._enabled = False
82 self.alarms = None
83 self.pm_metrics = None
84 self._omcc_version = OMCCVersion.Unknown
85 self._total_tcont_count = 0 # From ANI-G ME
86 self._qos_flexibility = 0 # From ONT2_G ME
87
88 self._onu_indication = None
89 self._unis = dict() # Port # -> UniPort
90
91 self._pon = None
92 # TODO: probably shouldnt be hardcoded, determine from olt maybe?
93 self._pon_port_number = 100
94 self.logical_device_id = None
95
96 self._heartbeat = HeartBeat.create(self, device_id)
97
98 # Set up OpenOMCI environment
99 self._onu_omci_device = None
100 self._dev_info_loaded = False
101 self._deferred = None
102
103 self._in_sync_subscription = None
104 self._connectivity_subscription = None
105 self._capabilities_subscription = None
106
107 self.mac_bridge_service_profile_entity_id = 0x201
108 self.gal_enet_profile_entity_id = 0x1
109
110 self._tp_service_specific_task = dict()
111 self._tech_profile_download_done = dict()
112
113 # Initialize KV store client
114 self.args = registry('main').get_args()
115 if self.args.backend == 'etcd':
116 host, port = self.args.etcd.split(':', 1)
117 self.kv_client = EtcdStore(host, port,
118 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
119 elif self.args.backend == 'consul':
120 host, port = self.args.consul.split(':', 1)
121 self.kv_client = ConsulStore(host, port,
122 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
123 else:
124 self.log.error('Invalid-backend')
125 raise Exception("Invalid-backend-for-kv-store")
126
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500127 @property
128 def enabled(self):
129 return self._enabled
130
131 @enabled.setter
132 def enabled(self, value):
133 if self._enabled != value:
134 self._enabled = value
135
136 @property
137 def omci_agent(self):
138 return self.adapter.omci_agent
139
140 @property
141 def omci_cc(self):
142 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
143
144 @property
145 def heartbeat(self):
146 return self._heartbeat
147
148 @property
149 def uni_ports(self):
150 return self._unis.values()
151
152 def uni_port(self, port_no_or_name):
153 if isinstance(port_no_or_name, (str, unicode)):
154 return next((uni for uni in self.uni_ports
155 if uni.name == port_no_or_name), None)
156
157 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
158 return next((uni for uni in self.uni_ports
Matt Jeanneret3bfebff2019-04-12 18:25:03 -0400159 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500160
161 @property
162 def pon_port(self):
163 return self._pon
164
165 def receive_message(self, msg):
166 if self.omci_cc is not None:
167 self.omci_cc.receive_message(msg)
168
Matt Jeanneretc083f462019-03-11 15:02:01 -0400169 def get_ofp_port_info(self, device, port_no):
170 self.log.info('get_ofp_port_info', port_no=port_no, device_id=device.id)
171 cap = OFPPF_1GB_FD | OFPPF_FIBER
172
173 hw_addr=mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
174 ((device.parent_port_no >> 8 & 0xff),
175 device.parent_port_no & 0xff,
176 (port_no >> 16) & 0xff,
177 (port_no >> 8) & 0xff,
178 port_no & 0xff))
179
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400180 uni_port = self.uni_port(int(port_no))
181 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
182 self.log.debug('ofp_port_name', port_no=port_no, name=name)
183
Matt Jeanneretc083f462019-03-11 15:02:01 -0400184 return PortCapability(
185 port=LogicalPort(
186 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400187 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400188 hw_addr=hw_addr,
189 config=0,
190 state=OFPPS_LIVE,
191 curr=cap,
192 advertised=cap,
193 peer=cap,
194 curr_speed=OFPPF_1GB_FD,
195 max_speed=OFPPF_1GB_FD
196 ),
197 device_id=device.id,
198 device_port_no=port_no
199 )
200 )
201
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500202 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500203 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500204 def activate(self, device):
205 self.log.debug('function-entry', device=device)
206
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500207 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500208 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500209 assert device.proxy_address.device_id
210
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500211 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500212 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500213 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500214 if self.enabled is not True:
215 self.log.info('activating-new-onu')
216 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500217 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500218 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500219 device.reason = 'activating-onu'
220
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500221 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400222 # pm_metrics requires a logical device id. For now set to just device_id
223 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500224
Matt Jeannereta32441c2019-03-07 05:16:37 -0500225 yield self.core_proxy.device_update(device)
Mahir Gunyel0e1588a2019-06-27 06:12:47 -0700226 #We commented out the line below because it is now being done in openolt-adapter,
227 #in onuDiscovery step. Line can be removed after tests.
228 #yield self.core_proxy.device_state_update(device.id, oper_status=OperStatus.DISCOVERED,
229 # connect_status=ConnectStatus.REACHABLE)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500230
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500231
Mahir Gunyel0e1588a2019-06-27 06:12:47 -0700232 self.log.debug('device updated', device=device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500233
Devmalya Paul7e0be4a2019-05-08 05:18:04 -0400234 yield self._init_pon_state(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500235
Mahir Gunyel0e1588a2019-06-27 06:12:47 -0700236 self.log.debug('pon state initialized', device=device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500237 ############################################################################
238 # Setup PM configuration for this device
239 # Pass in ONU specific options
240 kwargs = {
241 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
242 'heartbeat': self.heartbeat,
243 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
244 }
Yongjie Zhang8f891ad2019-07-03 15:32:38 -0400245 self.log.debug('create-OnuPmMetrics', serial_number=device.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500246 self.pm_metrics = OnuPmMetrics(self.core_proxy, self.device_id,
Yongjie Zhang8f891ad2019-07-03 15:32:38 -0400247 self.logical_device_id, device.serial_number,
248 grouped=True, freq_override=False, **kwargs)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500249 pm_config = self.pm_metrics.make_proto()
250 self._onu_omci_device.set_pm_config(self.pm_metrics.omci_pm.openomci_interval_pm)
251 self.log.info("initial-pm-config", pm_config=pm_config)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500252 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500253
254 ############################################################################
255 # Setup Alarm handler
Yongjie Zhang8f891ad2019-07-03 15:32:38 -0400256 self.alarms = AdapterAlarms(self.core_proxy, device.id, self.logical_device_id,
257 device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500258 # Note, ONU ID and UNI intf set in add_uni_port method
259 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.alarms,
260 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500261
262 #Start collecting stats from the device after a brief pause
263 reactor.callLater(10, self.pm_metrics.start_collector)
264
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500265 self.enabled = True
266 else:
267 self.log.info('onu-already-activated')
268
269 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400270 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500271 def reconcile(self, device):
272 self.log.debug('function-entry', device=device)
273
274 # first we verify that we got parent reference and proxy info
275 assert device.parent_id
276 assert device.proxy_address.device_id
277
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500278 if self.enabled is not True:
279 self.log.info('reconciling-broadcom-onu-device')
280
281 self._init_pon_state(device)
282
283 # need to restart state machines on vcore restart. there is no indication to do it for us.
284 self._onu_omci_device.start()
285 device.reason = "restarting-openomci"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400286 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500287
288 # TODO: this is probably a bit heavy handed
289 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
290 # This may not be necessary when mib resync actually works
291 reactor.callLater(1, self.reboot)
292
293 self.enabled = True
294 else:
295 self.log.info('onu-already-activated')
296
297 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500298 def _init_pon_state(self, device):
299 self.log.debug('function-entry', device=device)
300
301 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500302 self._pon.add_peer(self.parent_id, self._pon_port_number)
303 self.log.debug('adding-pon-port-to-agent', pon=self._pon.get_port())
304
Matt Jeannereta32441c2019-03-07 05:16:37 -0500305 yield self.core_proxy.port_created(device.id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500306
Matt Jeanneret0c287892019-02-28 11:48:00 -0500307 self.log.debug('added-pon-port-to-agent', pon=self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500308
309 # Create and start the OpenOMCI ONU Device Entry for this ONU
310 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500311 self.core_proxy,
312 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500313 support_classes=self.adapter.broadcom_omci,
314 custom_me_map=self.adapter.custom_me_entities())
315 # Port startup
316 if self._pon is not None:
317 self._pon.enabled = True
318
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500319 def delete(self, device):
320 self.log.info('delete-onu', device=device)
321 if self.parent_adapter:
322 try:
323 self.parent_adapter.delete_child_device(self.parent_id, device)
324 except AttributeError:
325 self.log.debug('parent-device-delete-child-not-implemented')
326 else:
327 self.log.debug("parent-adapter-not-available")
328
329 def _create_tconts(self, uni_id, us_scheduler):
330 alloc_id = us_scheduler['alloc_id']
331 q_sched_policy = us_scheduler['q_sched_policy']
332 self.log.debug('create-tcont', us_scheduler=us_scheduler)
333
334 tcontdict = dict()
335 tcontdict['alloc-id'] = alloc_id
336 tcontdict['q_sched_policy'] = q_sched_policy
337 tcontdict['uni_id'] = uni_id
338
339 # TODO: Not sure what to do with any of this...
340 tddata = dict()
341 tddata['name'] = 'not-sure-td-profile'
342 tddata['fixed-bandwidth'] = "not-sure-fixed"
343 tddata['assured-bandwidth'] = "not-sure-assured"
344 tddata['maximum-bandwidth'] = "not-sure-max"
345 tddata['additional-bw-eligibility-indicator'] = "not-sure-additional"
346
347 td = OnuTrafficDescriptor.create(tddata)
348 tcont = OnuTCont.create(self, tcont=tcontdict, td=td)
349
350 self._pon.add_tcont(tcont)
351
352 self.log.debug('pon-add-tcont', tcont=tcont)
353
354 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
355 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
356 self.log.debug('create-gemport',
357 gem_ports=gem_ports, direction=direction)
358
359 for gem_port in gem_ports:
360 gemdict = dict()
361 gemdict['gemport_id'] = gem_port['gemport_id']
362 gemdict['direction'] = direction
363 gemdict['alloc_id_ref'] = alloc_id_ref
364 gemdict['encryption'] = gem_port['aes_encryption']
365 gemdict['discard_config'] = dict()
366 gemdict['discard_config']['max_probability'] = \
367 gem_port['discard_config']['max_probability']
368 gemdict['discard_config']['max_threshold'] = \
369 gem_port['discard_config']['max_threshold']
370 gemdict['discard_config']['min_threshold'] = \
371 gem_port['discard_config']['min_threshold']
372 gemdict['discard_policy'] = gem_port['discard_policy']
373 gemdict['max_q_size'] = gem_port['max_q_size']
374 gemdict['pbit_map'] = gem_port['pbit_map']
375 gemdict['priority_q'] = gem_port['priority_q']
376 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
377 gemdict['weight'] = gem_port['weight']
378 gemdict['uni_id'] = uni_id
379
380 gem_port = OnuGemPort.create(self, gem_port=gemdict)
381
382 self._pon.add_gem_port(gem_port)
383
384 self.log.debug('pon-add-gemport', gem_port=gem_port)
385
386 def _do_tech_profile_configuration(self, uni_id, tp):
387 num_of_tconts = tp['num_of_tconts']
388 us_scheduler = tp['us_scheduler']
389 alloc_id = us_scheduler['alloc_id']
390 self._create_tconts(uni_id, us_scheduler)
391 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
392 self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
393 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
394 self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
395
396 def load_and_configure_tech_profile(self, uni_id, tp_path):
397 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
398
399 if uni_id not in self._tp_service_specific_task:
400 self._tp_service_specific_task[uni_id] = dict()
401
402 if uni_id not in self._tech_profile_download_done:
403 self._tech_profile_download_done[uni_id] = dict()
404
405 if tp_path not in self._tech_profile_download_done[uni_id]:
406 self._tech_profile_download_done[uni_id][tp_path] = False
407
408 if not self._tech_profile_download_done[uni_id][tp_path]:
409 try:
410 if tp_path in self._tp_service_specific_task[uni_id]:
411 self.log.info("tech-profile-config-already-in-progress",
412 tp_path=tp_path)
413 return
414
415 tp = self.kv_client[tp_path]
416 tp = ast.literal_eval(tp)
417 self.log.debug("tp-instance", tp=tp)
418 self._do_tech_profile_configuration(uni_id, tp)
William Kurkian3a206332019-04-29 11:05:47 -0400419
420 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500421 def success(_results):
422 self.log.info("tech-profile-config-done-successfully")
William Kurkian3a206332019-04-29 11:05:47 -0400423 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500424 device.reason = 'tech-profile-config-download-success'
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400425 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500426 if tp_path in self._tp_service_specific_task[uni_id]:
427 del self._tp_service_specific_task[uni_id][tp_path]
428 self._tech_profile_download_done[uni_id][tp_path] = True
429
William Kurkian3a206332019-04-29 11:05:47 -0400430 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500431 def failure(_reason):
432 self.log.warn('tech-profile-config-failure-retrying',
433 _reason=_reason)
William Kurkian3a206332019-04-29 11:05:47 -0400434 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500435 device.reason = 'tech-profile-config-download-failure-retrying'
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400436 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500437 if tp_path in self._tp_service_specific_task[uni_id]:
438 del self._tp_service_specific_task[uni_id][tp_path]
439 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
440 uni_id, tp_path)
441
442 self.log.info('downloading-tech-profile-configuration')
443 self._tp_service_specific_task[uni_id][tp_path] = \
444 BrcmTpServiceSpecificTask(self.omci_agent, self, uni_id)
445 self._deferred = \
446 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
447 self._deferred.addCallbacks(success, failure)
448
449 except Exception as e:
450 self.log.exception("error-loading-tech-profile", e=e)
451 else:
452 self.log.info("tech-profile-config-already-done")
453
454 def update_pm_config(self, device, pm_config):
455 # TODO: This has not been tested
456 self.log.info('update_pm_config', pm_config=pm_config)
457 self.pm_metrics.update(pm_config)
458
459 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
460 # flow decomposition that ultimately comes from onos
461 def update_flow_table(self, device, flows):
462 self.log.debug('function-entry', device=device, flows=flows)
463
464 #
465 # We need to proxy through the OLT to get to the ONU
466 # Configuration from here should be using OMCI
467 #
468 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
469
470 # no point in pushing omci flows if the device isnt reachable
471 if device.connect_status != ConnectStatus.REACHABLE or \
472 device.admin_state != AdminState.ENABLED:
473 self.log.warn("device-disabled-or-offline-skipping-flow-update",
474 admin=device.admin_state, connect=device.connect_status)
475 return
476
477 def is_downstream(port):
478 return port == self._pon_port_number
479
480 def is_upstream(port):
481 return not is_downstream(port)
482
483 for flow in flows:
484 _type = None
485 _port = None
486 _vlan_vid = None
487 _udp_dst = None
488 _udp_src = None
489 _ipv4_dst = None
490 _ipv4_src = None
491 _metadata = None
492 _output = None
493 _push_tpid = None
494 _field = None
495 _set_vlan_vid = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400496 _tunnel_id = None
497
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500498 self.log.debug('bulk-flow-update', device_id=device.id, flow=flow)
499 try:
500 _in_port = fd.get_in_port(flow)
501 assert _in_port is not None
502
503 _out_port = fd.get_out_port(flow) # may be None
504
505 if is_downstream(_in_port):
506 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
507 uni_port = self.uni_port(_out_port)
508 elif is_upstream(_in_port):
509 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
510 uni_port = self.uni_port(_in_port)
511 else:
512 raise Exception('port should be 1 or 2 by our convention')
513
514 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
515
516 for field in fd.get_ofb_fields(flow):
517 if field.type == fd.ETH_TYPE:
518 _type = field.eth_type
519 self.log.debug('field-type-eth-type',
520 eth_type=_type)
521
522 elif field.type == fd.IP_PROTO:
523 _proto = field.ip_proto
524 self.log.debug('field-type-ip-proto',
525 ip_proto=_proto)
526
527 elif field.type == fd.IN_PORT:
528 _port = field.port
529 self.log.debug('field-type-in-port',
530 in_port=_port)
531
532 elif field.type == fd.VLAN_VID:
533 _vlan_vid = field.vlan_vid & 0xfff
534 self.log.debug('field-type-vlan-vid',
535 vlan=_vlan_vid)
536
537 elif field.type == fd.VLAN_PCP:
538 _vlan_pcp = field.vlan_pcp
539 self.log.debug('field-type-vlan-pcp',
540 pcp=_vlan_pcp)
541
542 elif field.type == fd.UDP_DST:
543 _udp_dst = field.udp_dst
544 self.log.debug('field-type-udp-dst',
545 udp_dst=_udp_dst)
546
547 elif field.type == fd.UDP_SRC:
548 _udp_src = field.udp_src
549 self.log.debug('field-type-udp-src',
550 udp_src=_udp_src)
551
552 elif field.type == fd.IPV4_DST:
553 _ipv4_dst = field.ipv4_dst
554 self.log.debug('field-type-ipv4-dst',
555 ipv4_dst=_ipv4_dst)
556
557 elif field.type == fd.IPV4_SRC:
558 _ipv4_src = field.ipv4_src
559 self.log.debug('field-type-ipv4-src',
560 ipv4_dst=_ipv4_src)
561
562 elif field.type == fd.METADATA:
563 _metadata = field.table_metadata
564 self.log.debug('field-type-metadata',
565 metadata=_metadata)
566
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400567 elif field.type == fd.TUNNEL_ID:
568 _tunnel_id = field.tunnel_id
569 self.log.debug('field-type-tunnel-id',
570 tunnel_id=_tunnel_id)
571
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500572 else:
573 raise NotImplementedError('field.type={}'.format(
574 field.type))
575
576 for action in fd.get_actions(flow):
577
578 if action.type == fd.OUTPUT:
579 _output = action.output.port
580 self.log.debug('action-type-output',
581 output=_output, in_port=_in_port)
582
583 elif action.type == fd.POP_VLAN:
584 self.log.debug('action-type-pop-vlan',
585 in_port=_in_port)
586
587 elif action.type == fd.PUSH_VLAN:
588 _push_tpid = action.push.ethertype
589 self.log.debug('action-type-push-vlan',
590 push_tpid=_push_tpid, in_port=_in_port)
591 if action.push.ethertype != 0x8100:
592 self.log.error('unhandled-tpid',
593 ethertype=action.push.ethertype)
594
595 elif action.type == fd.SET_FIELD:
596 _field = action.set_field.field.ofb_field
597 assert (action.set_field.field.oxm_class ==
598 OFPXMC_OPENFLOW_BASIC)
599 self.log.debug('action-type-set-field',
600 field=_field, in_port=_in_port)
601 if _field.type == fd.VLAN_VID:
602 _set_vlan_vid = _field.vlan_vid & 0xfff
603 self.log.debug('set-field-type-vlan-vid',
604 vlan_vid=_set_vlan_vid)
605 else:
606 self.log.error('unsupported-action-set-field-type',
607 field_type=_field.type)
608 else:
609 self.log.error('unsupported-action-type',
610 action_type=action.type, in_port=_in_port)
611
612 # TODO: We only set vlan omci flows. Handle omci matching ethertypes at some point in another task
613 if _type is not None:
614 self.log.warn('ignoring-flow-with-ethType', ethType=_type)
615 elif _set_vlan_vid is None or _set_vlan_vid == 0:
616 self.log.warn('ignorning-flow-that-does-not-set-vlanid')
617 else:
618 self.log.warn('set-vlanid', uni_id=uni_port.port_number, set_vlan_vid=_set_vlan_vid)
619 self._add_vlan_filter_task(device, uni_port, _set_vlan_vid)
620
621 except Exception as e:
622 self.log.exception('failed-to-install-flow', e=e, flow=flow)
623
624
625 def _add_vlan_filter_task(self, device, uni_port, _set_vlan_vid):
626 assert uni_port is not None
627
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400628 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500629 def success(_results):
630 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid)
631 device.reason = 'omci-flows-pushed'
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400632 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500633 self._vlan_filter_task = None
634
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400635 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500636 def failure(_reason):
637 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid)
638 device.reason = 'omci-flows-failed-retrying'
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400639 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500640 self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT,
641 self._add_vlan_filter_task, device, uni_port, _set_vlan_vid)
642
643 self.log.info('setting-vlan-tag')
644 self._vlan_filter_task = BrcmVlanFilterTask(self.omci_agent, self.device_id, uni_port, _set_vlan_vid)
645 self._deferred = self._onu_omci_device.task_runner.queue_task(self._vlan_filter_task)
646 self._deferred.addCallbacks(success, failure)
647
648 def get_tx_id(self):
649 self.log.debug('function-entry')
650 self.tx_id += 1
651 return self.tx_id
652
Matt Jeannereta32441c2019-03-07 05:16:37 -0500653 def process_inter_adapter_message(self, request):
654 self.log.debug('process-inter-adapter-message', msg=request)
655 try:
656 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
657 omci_msg = InterAdapterOmciMessage()
658 request.body.Unpack(omci_msg)
659 self.log.debug('inter-adapter-recv-omci', omci_msg=omci_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500660
Matt Jeannereta32441c2019-03-07 05:16:37 -0500661 self.receive_message(omci_msg.message)
662
663 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
664 onu_indication = OnuIndication()
665 request.body.Unpack(onu_indication)
666 self.log.debug('inter-adapter-recv-onu-ind', onu_indication=onu_indication)
667
668 if onu_indication.oper_state == "up":
669 self.create_interface(onu_indication)
670 elif onu_indication.oper_state == "down":
671 self.update_interface(onu_indication)
672 else:
673 self.log.error("unknown-onu-indication", onu_indication=onu_indication)
674
Matt Jeanneret3bfebff2019-04-12 18:25:03 -0400675 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
676 tech_msg = InterAdapterTechProfileDownloadMessage()
677 request.body.Unpack(tech_msg)
678 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
679
680 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
681
Matt Jeannereta32441c2019-03-07 05:16:37 -0500682 else:
683 self.log.error("inter-adapter-unhandled-type", request=request)
684
685 except Exception as e:
686 self.log.exception("error-processing-inter-adapter-message", e=e)
687
688 # Called each time there is an onu "up" indication from the olt handler
689 @inlineCallbacks
690 def create_interface(self, onu_indication):
691 self.log.debug('function-entry', onu_indication=onu_indication)
692 self._onu_indication = onu_indication
693
Matt Jeanneretc083f462019-03-11 15:02:01 -0400694 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
695 connect_status=ConnectStatus.REACHABLE)
696
Matt Jeannereta32441c2019-03-07 05:16:37 -0500697 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500698
699 self.log.debug('starting-openomci-statemachine')
700 self._subscribe_to_events()
701 reactor.callLater(1, self._onu_omci_device.start)
702 onu_device.reason = "starting-openomci"
Matt Jeannereta32441c2019-03-07 05:16:37 -0500703 yield self.core_proxy.device_update(onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500704 self._heartbeat.enabled = True
705
706 # Currently called each time there is an onu "down" indication from the olt handler
707 # TODO: possibly other reasons to "update" from the olt?
Matt Jeannereta32441c2019-03-07 05:16:37 -0500708 @inlineCallbacks
709 def update_interface(self, onu_indication):
710 self.log.debug('function-entry', onu_indication=onu_indication)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500711
Matt Jeannereta32441c2019-03-07 05:16:37 -0500712 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500713
Matt Jeannereta32441c2019-03-07 05:16:37 -0500714 if onu_indication.oper_state == 'down':
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500715 self.log.debug('stopping-openomci-statemachine')
716 reactor.callLater(0, self._onu_omci_device.stop)
717
718 # Let TP download happen again
719 for uni_id in self._tp_service_specific_task:
720 self._tp_service_specific_task[uni_id].clear()
721 for uni_id in self._tech_profile_download_done:
722 self._tech_profile_download_done[uni_id].clear()
723
724 self.disable_ports(onu_device)
725 onu_device.reason = "stopping-openomci"
Chaitrashree G S01257fa2019-05-24 06:49:49 -0400726 yield self.core_proxy.device_update(onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500727 onu_device.connect_status = ConnectStatus.UNREACHABLE
728 onu_device.oper_status = OperStatus.DISCOVERED
Chaitrashree G S01257fa2019-05-24 06:49:49 -0400729 yield self.core_proxy.device_state_update(self.device_id, onu_device.oper_status,onu_device.connect_status)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500730 else:
731 self.log.debug('not-changing-openomci-statemachine')
732
733 # Not currently called by olt or anything else
William Kurkian3a206332019-04-29 11:05:47 -0400734 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500735 def remove_interface(self, data):
736 self.log.debug('function-entry', data=data)
737
William Kurkian3a206332019-04-29 11:05:47 -0400738 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500739
740 self.log.debug('stopping-openomci-statemachine')
741 reactor.callLater(0, self._onu_omci_device.stop)
742
743 # Let TP download happen again
744 for uni_id in self._tp_service_specific_task:
745 self._tp_service_specific_task[uni_id].clear()
746 for uni_id in self._tech_profile_download_done:
747 self._tech_profile_download_done[uni_id].clear()
748
749 self.disable_ports(onu_device)
750 onu_device.reason = "stopping-openomci"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400751 yield self.core_proxy.device_update(onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500752
753 # TODO: im sure there is more to do here
754
755 # Not currently called. Would be called presumably from the olt handler
William Kurkian3a206332019-04-29 11:05:47 -0400756 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500757 def remove_gemport(self, data):
758 self.log.debug('remove-gemport', data=data)
William Kurkian3a206332019-04-29 11:05:47 -0400759 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500760 if device.connect_status != ConnectStatus.REACHABLE:
761 self.log.error('device-unreachable')
762 return
763
764 # Not currently called. Would be called presumably from the olt handler
William Kurkian3a206332019-04-29 11:05:47 -0400765 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500766 def remove_tcont(self, tcont_data, traffic_descriptor_data):
767 self.log.debug('remove-tcont', tcont_data=tcont_data, traffic_descriptor_data=traffic_descriptor_data)
William Kurkian3a206332019-04-29 11:05:47 -0400768 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500769 if device.connect_status != ConnectStatus.REACHABLE:
770 self.log.error('device-unreachable')
771 return
772
773 # TODO: Create some omci task that encompases this what intended
774
775 # Not currently called. Would be called presumably from the olt handler
776 def create_multicast_gemport(self, data):
777 self.log.debug('function-entry', data=data)
778
779 # TODO: create objects and populate for later omci calls
780
781 def disable(self, device):
782 self.log.debug('function-entry', device=device)
783 try:
784 self.log.info('sending-uni-lock-towards-device', device=device)
785
Matt Jeanneret80766692019-05-03 09:58:38 -0400786 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500787 def stop_anyway(reason):
788 # proceed with disable regardless if we could reach the onu. for example onu is unplugged
789 self.log.debug('stopping-openomci-statemachine')
790 reactor.callLater(0, self._onu_omci_device.stop)
791
792 # Let TP download happen again
793 for uni_id in self._tp_service_specific_task:
794 self._tp_service_specific_task[uni_id].clear()
795 for uni_id in self._tech_profile_download_done:
796 self._tech_profile_download_done[uni_id].clear()
797
798 self.disable_ports(device)
799 device.oper_status = OperStatus.UNKNOWN
800 device.reason = "omci-admin-lock"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400801 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500802
803 # lock all the unis
804 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=True)
805 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
806 self._deferred.addCallbacks(stop_anyway, stop_anyway)
807 except Exception as e:
808 log.exception('exception-in-onu-disable', exception=e)
809
William Kurkian3a206332019-04-29 11:05:47 -0400810 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500811 def reenable(self, device):
812 self.log.debug('function-entry', device=device)
813 try:
814 # Start up OpenOMCI state machines for this device
815 # this will ultimately resync mib and unlock unis on successful redownloading the mib
816 self.log.debug('restarting-openomci-statemachine')
817 self._subscribe_to_events()
818 device.reason = "restarting-openomci"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400819 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500820 reactor.callLater(1, self._onu_omci_device.start)
821 self._heartbeat.enabled = True
822 except Exception as e:
823 log.exception('exception-in-onu-reenable', exception=e)
824
William Kurkian3a206332019-04-29 11:05:47 -0400825 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500826 def reboot(self):
827 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -0400828 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500829 if device.connect_status != ConnectStatus.REACHABLE:
830 self.log.error("device-unreachable")
831 return
832
William Kurkian3a206332019-04-29 11:05:47 -0400833 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500834 def success(_results):
835 self.log.info('reboot-success', _results=_results)
836 self.disable_ports(device)
837 device.connect_status = ConnectStatus.UNREACHABLE
838 device.oper_status = OperStatus.DISCOVERED
839 device.reason = "rebooting"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400840 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500841
842 def failure(_reason):
843 self.log.info('reboot-failure', _reason=_reason)
844
845 self._deferred = self._onu_omci_device.reboot()
846 self._deferred.addCallbacks(success, failure)
847
William Kurkian3a206332019-04-29 11:05:47 -0400848 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500849 def disable_ports(self, onu_device):
Matt Jeanneret80766692019-05-03 09:58:38 -0400850 self.log.info('disable-ports', device_id=self.device_id, onu_device=onu_device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500851
852 # Disable all ports on that device
Matt Jeanneret80766692019-05-03 09:58:38 -0400853 yield self.core_proxy.ports_state_update(self.device_id, OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500854
William Kurkian3a206332019-04-29 11:05:47 -0400855 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500856 def enable_ports(self, onu_device):
857 self.log.info('enable-ports', device_id=self.device_id, onu_device=onu_device)
858
Matt Jeanneret80766692019-05-03 09:58:38 -0400859 # Enable all ports on that device
860 yield self.core_proxy.ports_state_update(self.device_id, OperStatus.ACTIVE)
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:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -0400993 if device.admin_state == AdminState.PREPROVISIONED or 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'
Chaitrashree G S01257fa2019-05-24 06:49:49 -04001000 yield self.enable_ports(device)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001001 yield self.core_proxy.device_state_update(device.id,
1002 oper_status=OperStatus.ACTIVE, connect_status=ConnectStatus.REACHABLE)
1003 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001004 self._mib_download_task = None
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001005 yield self.onu_active_alarm()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001006
Matt Jeanneretc083f462019-03-11 15:02:01 -04001007 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001008 def failure(_reason):
1009 self.log.warn('mib-download-failure-retrying', _reason=_reason)
1010 device.reason = 'initial-mib-download-failure-retrying'
Matt Jeanneretc083f462019-03-11 15:02:01 -04001011 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001012 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1013
1014 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1015 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1016 self.log.info('downloading-initial-mib-configuration')
1017 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1018 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1019 self._deferred.addCallbacks(success, failure)
1020 else:
1021 self.log.info('admin-down-disabling')
1022 self.disable(device)
1023 else:
1024 self.log.info('device-info-not-loaded-skipping-mib-download')
1025
Matt Jeanneretc083f462019-03-11 15:02:01 -04001026 @inlineCallbacks
1027 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001028 self.log.debug('function-entry')
1029
Matt Jeanneretc083f462019-03-11 15:02:01 -04001030 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 -05001031
1032 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1033 uni_name = "uni-{}".format(uni_no)
1034
1035 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
1036
1037 self.log.debug('uni-port-inputs', uni_no=uni_no, uni_id=uni_id, uni_name=uni_name, uni_type=uni_type,
Yongjie Zhang286099c2019-08-06 13:39:07 -04001038 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001039
1040 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1041 uni_port.entity_id = entity_id
1042 uni_port.enabled = True
1043 uni_port.mac_bridge_port_num = mac_bridge_port_num
1044
1045 self.log.debug("created-uni-port", uni=uni_port)
1046
Matt Jeanneretc083f462019-03-11 15:02:01 -04001047 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001048
1049 self._unis[uni_port.port_number] = uni_port
1050
1051 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Yongjie Zhang286099c2019-08-06 13:39:07 -04001052 uni_ports=self._unis.values(), serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001053
Matt Jeanneretc083f462019-03-11 15:02:01 -04001054 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1055 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
1056 MAX_PONS_PER_OLT = 16
Mahir Gunyel0e1588a2019-06-27 06:12:47 -07001057 MAX_ONUS_PER_PON = 128
Matt Jeanneretc083f462019-03-11 15:02:01 -04001058 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001059
Matt Jeanneretc083f462019-03-11 15:02:01 -04001060 assert intf_id < MAX_PONS_PER_OLT
1061 assert onu_id < MAX_ONUS_PER_PON
1062 assert uni_id < MAX_UNIS_PER_ONU
Matt Jeanneret3b7db442019-04-22 16:29:48 -04001063 return intf_id << 11 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001064
1065 @inlineCallbacks
1066 def onu_active_alarm(self):
1067 self.log.debug('function-entry')
1068 try:
1069 device = yield self.core_proxy.get_device(self.device_id)
1070 parent_device = yield self.core_proxy.get_device(self.parent_id)
1071 olt_serial_number = parent_device.serial_number
1072
1073 self.log.debug("onu-indication-context-data",
1074 pon_id=self._onu_indication.intf_id,
1075 registration_id=self.device_id,
1076 device_id=self.device_id,
1077 onu_serial_number=device.serial_number,
1078 olt_serial_number=olt_serial_number)
1079
1080 self.log.debug("Trying to raise alarm")
1081 OnuActiveAlarm(self.alarms, self.device_id,
1082 self._onu_indication.intf_id,
1083 device.serial_number,
1084 str(self.device_id),
1085 olt_serial_number).raise_alarm()
1086 except Exception as active_alarm_error:
1087 self.log.exception('onu-activated-alarm-error',
1088 errmsg=active_alarm_error.message)
1089