blob: 1fb8e4303929ff459a76bed2ba76acbf0259d522 [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
Devmalya Paulffc89df2019-07-31 17:43:13 -040022import arrow
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050023import structlog
24
25from collections import OrderedDict
26
27from twisted.internet import reactor, task
28from twisted.internet.defer import DeferredQueue, inlineCallbacks, returnValue, TimeoutError
29
30from heartbeat import HeartBeat
Devmalya Paulffc89df2019-07-31 17:43:13 -040031from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent
32from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
33from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
34from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050035
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050036import pyvoltha.common.openflow.utils as fd
37from pyvoltha.common.utils.registry import registry
38from pyvoltha.common.config.config_backend import ConsulStore
39from pyvoltha.common.config.config_backend import EtcdStore
William Kurkian8235c1e2019-03-05 12:58:28 -050040from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretc083f462019-03-11 15:02:01 -040041from 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 -040042from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
43 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050044from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050045from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
46from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050047 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050048from omci.brcm_mib_download_task import BrcmMibDownloadTask
49from omci.brcm_tp_service_specific_task import BrcmTpServiceSpecificTask
50from omci.brcm_uni_lock_task import BrcmUniLockTask
51from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
52from onu_gem_port import *
53from onu_tcont import *
54from pon_port import *
55from uni_port import *
56from onu_traffic_descriptor import *
57from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053058from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
59from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050060
61OP = EntityOperations
62RC = ReasonCodes
63
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050064log = structlog.get_logger()
65
66_STARTUP_RETRY_WAIT = 20
67
68
69class BrcmOpenomciOnuHandler(object):
70
71 def __init__(self, adapter, device_id):
72 self.log = structlog.get_logger(device_id=device_id)
73 self.log.debug('function-entry')
74 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050075 self.core_proxy = adapter.core_proxy
76 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050077 self.parent_adapter = None
78 self.parent_id = None
79 self.device_id = device_id
80 self.incoming_messages = DeferredQueue()
81 self.event_messages = DeferredQueue()
82 self.proxy_address = None
83 self.tx_id = 0
84 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040085 self.events = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050086 self.pm_metrics = None
87 self._omcc_version = OMCCVersion.Unknown
88 self._total_tcont_count = 0 # From ANI-G ME
89 self._qos_flexibility = 0 # From ONT2_G ME
90
91 self._onu_indication = None
92 self._unis = dict() # Port # -> UniPort
93
94 self._pon = None
95 # TODO: probably shouldnt be hardcoded, determine from olt maybe?
96 self._pon_port_number = 100
97 self.logical_device_id = None
98
99 self._heartbeat = HeartBeat.create(self, device_id)
100
101 # Set up OpenOMCI environment
102 self._onu_omci_device = None
103 self._dev_info_loaded = False
104 self._deferred = None
105
106 self._in_sync_subscription = None
107 self._connectivity_subscription = None
108 self._capabilities_subscription = None
109
110 self.mac_bridge_service_profile_entity_id = 0x201
111 self.gal_enet_profile_entity_id = 0x1
112
113 self._tp_service_specific_task = dict()
114 self._tech_profile_download_done = dict()
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400115 # Stores information related to queued vlan filter tasks
116 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
117
118 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500119
120 # Initialize KV store client
121 self.args = registry('main').get_args()
122 if self.args.backend == 'etcd':
123 host, port = self.args.etcd.split(':', 1)
124 self.kv_client = EtcdStore(host, port,
125 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
126 elif self.args.backend == 'consul':
127 host, port = self.args.consul.split(':', 1)
128 self.kv_client = ConsulStore(host, port,
129 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
130 else:
131 self.log.error('Invalid-backend')
132 raise Exception("Invalid-backend-for-kv-store")
133
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500134 @property
135 def enabled(self):
136 return self._enabled
137
138 @enabled.setter
139 def enabled(self, value):
140 if self._enabled != value:
141 self._enabled = value
142
143 @property
144 def omci_agent(self):
145 return self.adapter.omci_agent
146
147 @property
148 def omci_cc(self):
149 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
150
151 @property
152 def heartbeat(self):
153 return self._heartbeat
154
155 @property
156 def uni_ports(self):
157 return self._unis.values()
158
159 def uni_port(self, port_no_or_name):
160 if isinstance(port_no_or_name, (str, unicode)):
161 return next((uni for uni in self.uni_ports
162 if uni.name == port_no_or_name), None)
163
164 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
165 return next((uni for uni in self.uni_ports
Matt Jeanneret3bfebff2019-04-12 18:25:03 -0400166 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500167
168 @property
169 def pon_port(self):
170 return self._pon
171
172 def receive_message(self, msg):
173 if self.omci_cc is not None:
174 self.omci_cc.receive_message(msg)
175
Matt Jeanneretc083f462019-03-11 15:02:01 -0400176 def get_ofp_port_info(self, device, port_no):
177 self.log.info('get_ofp_port_info', port_no=port_no, device_id=device.id)
178 cap = OFPPF_1GB_FD | OFPPF_FIBER
179
180 hw_addr=mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
181 ((device.parent_port_no >> 8 & 0xff),
182 device.parent_port_no & 0xff,
183 (port_no >> 16) & 0xff,
184 (port_no >> 8) & 0xff,
185 port_no & 0xff))
186
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400187 uni_port = self.uni_port(int(port_no))
188 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
189 self.log.debug('ofp_port_name', port_no=port_no, name=name)
190
Matt Jeanneretc083f462019-03-11 15:02:01 -0400191 return PortCapability(
192 port=LogicalPort(
193 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400194 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400195 hw_addr=hw_addr,
196 config=0,
197 state=OFPPS_LIVE,
198 curr=cap,
199 advertised=cap,
200 peer=cap,
201 curr_speed=OFPPF_1GB_FD,
202 max_speed=OFPPF_1GB_FD
203 ),
204 device_id=device.id,
205 device_port_no=port_no
206 )
207 )
208
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500209 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500210 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500211 def activate(self, device):
212 self.log.debug('function-entry', device=device)
213
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500214 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500215 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500216 assert device.proxy_address.device_id
217
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500218 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500219 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500220 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500221 if self.enabled is not True:
222 self.log.info('activating-new-onu')
223 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500224 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500225 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500226 device.reason = 'activating-onu'
227
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500228 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400229 # pm_metrics requires a logical device id. For now set to just device_id
230 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500231
Matt Jeannereta32441c2019-03-07 05:16:37 -0500232 yield self.core_proxy.device_update(device)
Mahir Gunyel0e1588a2019-06-27 06:12:47 -0700233 #We commented out the line below because it is now being done in openolt-adapter,
234 #in onuDiscovery step. Line can be removed after tests.
235 #yield self.core_proxy.device_state_update(device.id, oper_status=OperStatus.DISCOVERED,
236 # connect_status=ConnectStatus.REACHABLE)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500237
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500238
Mahir Gunyel0e1588a2019-06-27 06:12:47 -0700239 self.log.debug('device updated', device=device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500240
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700241 yield self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500242
Mahir Gunyel0e1588a2019-06-27 06:12:47 -0700243 self.log.debug('pon state initialized', device=device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500244 ############################################################################
Devmalya Paulffc89df2019-07-31 17:43:13 -0400245 # Setup Alarm handler
246 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
247 device.serial_number)
248 ############################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500249 # Setup PM configuration for this device
250 # Pass in ONU specific options
251 kwargs = {
252 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
253 'heartbeat': self.heartbeat,
254 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
255 }
Yongjie Zhang8f891ad2019-07-03 15:32:38 -0400256 self.log.debug('create-OnuPmMetrics', serial_number=device.serial_number)
Devmalya Paulffc89df2019-07-31 17:43:13 -0400257 self.pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Yongjie Zhang8f891ad2019-07-03 15:32:38 -0400258 self.logical_device_id, device.serial_number,
259 grouped=True, freq_override=False, **kwargs)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500260 pm_config = self.pm_metrics.make_proto()
261 self._onu_omci_device.set_pm_config(self.pm_metrics.omci_pm.openomci_interval_pm)
262 self.log.info("initial-pm-config", pm_config=pm_config)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500263 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500264
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500265 # Note, ONU ID and UNI intf set in add_uni_port method
Devmalya Paulffc89df2019-07-31 17:43:13 -0400266 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500267 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500268
269 #Start collecting stats from the device after a brief pause
270 reactor.callLater(10, self.pm_metrics.start_collector)
271
onkarkundargiaae99712019-09-23 15:02:52 +0530272 # Code to Run OMCI Test Action
273 kwargs_omci_test_action = {
274 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
275 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
276 }
277 serial_number = device.serial_number
278 test_request = OmciTestRequest(self.core_proxy,
279 self.omci_agent, self.device_id,
280 AniG, serial_number,
281 self.logical_device_id,
282 exclusive=False,
283 **kwargs_omci_test_action)
284 reactor.callLater(60, test_request.start_collector)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500285 self.enabled = True
286 else:
287 self.log.info('onu-already-activated')
288
289 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400290 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500291 def reconcile(self, device):
292 self.log.debug('function-entry', device=device)
293
294 # first we verify that we got parent reference and proxy info
295 assert device.parent_id
296 assert device.proxy_address.device_id
297
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700298 self.proxy_address = device.proxy_address
299 self.parent_id = device.parent_id
300 self._pon_port_number = device.parent_port_no
301
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500302 if self.enabled is not True:
303 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700304 self.logical_device_id = self.device_id
305 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500306
307 # need to restart state machines on vcore restart. there is no indication to do it for us.
308 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700309 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500310
311 # TODO: this is probably a bit heavy handed
312 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
313 # This may not be necessary when mib resync actually works
314 reactor.callLater(1, self.reboot)
315
316 self.enabled = True
317 else:
318 self.log.info('onu-already-activated')
319
320 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700321 def _init_pon_state(self):
322 self.log.debug('function-entry', deviceId=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500323
324 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500325 self._pon.add_peer(self.parent_id, self._pon_port_number)
326 self.log.debug('adding-pon-port-to-agent', pon=self._pon.get_port())
327
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700328 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500329
Matt Jeanneret0c287892019-02-28 11:48:00 -0500330 self.log.debug('added-pon-port-to-agent', pon=self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500331
332 # Create and start the OpenOMCI ONU Device Entry for this ONU
333 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500334 self.core_proxy,
335 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500336 support_classes=self.adapter.broadcom_omci,
337 custom_me_map=self.adapter.custom_me_entities())
338 # Port startup
339 if self._pon is not None:
340 self._pon.enabled = True
341
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500342 def delete(self, device):
343 self.log.info('delete-onu', device=device)
344 if self.parent_adapter:
345 try:
346 self.parent_adapter.delete_child_device(self.parent_id, device)
347 except AttributeError:
348 self.log.debug('parent-device-delete-child-not-implemented')
349 else:
350 self.log.debug("parent-adapter-not-available")
351
352 def _create_tconts(self, uni_id, us_scheduler):
353 alloc_id = us_scheduler['alloc_id']
354 q_sched_policy = us_scheduler['q_sched_policy']
355 self.log.debug('create-tcont', us_scheduler=us_scheduler)
356
357 tcontdict = dict()
358 tcontdict['alloc-id'] = alloc_id
359 tcontdict['q_sched_policy'] = q_sched_policy
360 tcontdict['uni_id'] = uni_id
361
362 # TODO: Not sure what to do with any of this...
363 tddata = dict()
364 tddata['name'] = 'not-sure-td-profile'
365 tddata['fixed-bandwidth'] = "not-sure-fixed"
366 tddata['assured-bandwidth'] = "not-sure-assured"
367 tddata['maximum-bandwidth'] = "not-sure-max"
368 tddata['additional-bw-eligibility-indicator'] = "not-sure-additional"
369
370 td = OnuTrafficDescriptor.create(tddata)
371 tcont = OnuTCont.create(self, tcont=tcontdict, td=td)
372
373 self._pon.add_tcont(tcont)
374
375 self.log.debug('pon-add-tcont', tcont=tcont)
376
377 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
378 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
379 self.log.debug('create-gemport',
380 gem_ports=gem_ports, direction=direction)
381
382 for gem_port in gem_ports:
383 gemdict = dict()
384 gemdict['gemport_id'] = gem_port['gemport_id']
385 gemdict['direction'] = direction
386 gemdict['alloc_id_ref'] = alloc_id_ref
387 gemdict['encryption'] = gem_port['aes_encryption']
388 gemdict['discard_config'] = dict()
389 gemdict['discard_config']['max_probability'] = \
390 gem_port['discard_config']['max_probability']
391 gemdict['discard_config']['max_threshold'] = \
392 gem_port['discard_config']['max_threshold']
393 gemdict['discard_config']['min_threshold'] = \
394 gem_port['discard_config']['min_threshold']
395 gemdict['discard_policy'] = gem_port['discard_policy']
396 gemdict['max_q_size'] = gem_port['max_q_size']
397 gemdict['pbit_map'] = gem_port['pbit_map']
398 gemdict['priority_q'] = gem_port['priority_q']
399 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
400 gemdict['weight'] = gem_port['weight']
401 gemdict['uni_id'] = uni_id
402
403 gem_port = OnuGemPort.create(self, gem_port=gemdict)
404
405 self._pon.add_gem_port(gem_port)
406
407 self.log.debug('pon-add-gemport', gem_port=gem_port)
408
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400409 def _execute_queued_vlan_filter_tasks(self, uni_id):
410 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
411 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
412 # or initial-mib-download is not done. Once the tp_task is completed, we execute
413 # such queued vlan-filter tasks
414 try:
415 if uni_id in self._queued_vlan_filter_task:
416 self.log.info("executing-queued-vlan-filter-task",
417 uni_id=uni_id)
418 filter_info = self._queued_vlan_filter_task[uni_id]
419 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
420 uni_id, filter_info.get("uni_port"), filter_info.get("set_vlan_vid"))
421 # Now remove the entry from the dictionary
422 self._queued_vlan_filter_task[uni_id].clear()
423 self.log.debug("executed-queued-vlan-filter-task",
424 uni_id=uni_id)
425 except Exception as e:
426 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
427
428
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500429 def _do_tech_profile_configuration(self, uni_id, tp):
430 num_of_tconts = tp['num_of_tconts']
431 us_scheduler = tp['us_scheduler']
432 alloc_id = us_scheduler['alloc_id']
433 self._create_tconts(uni_id, us_scheduler)
434 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
435 self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
436 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
437 self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
438
439 def load_and_configure_tech_profile(self, uni_id, tp_path):
440 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
441
442 if uni_id not in self._tp_service_specific_task:
443 self._tp_service_specific_task[uni_id] = dict()
444
445 if uni_id not in self._tech_profile_download_done:
446 self._tech_profile_download_done[uni_id] = dict()
447
448 if tp_path not in self._tech_profile_download_done[uni_id]:
449 self._tech_profile_download_done[uni_id][tp_path] = False
450
451 if not self._tech_profile_download_done[uni_id][tp_path]:
452 try:
453 if tp_path in self._tp_service_specific_task[uni_id]:
454 self.log.info("tech-profile-config-already-in-progress",
455 tp_path=tp_path)
456 return
457
458 tp = self.kv_client[tp_path]
459 tp = ast.literal_eval(tp)
460 self.log.debug("tp-instance", tp=tp)
461 self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700462
William Kurkian3a206332019-04-29 11:05:47 -0400463 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500464 def success(_results):
465 self.log.info("tech-profile-config-done-successfully")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700466 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500467 if tp_path in self._tp_service_specific_task[uni_id]:
468 del self._tp_service_specific_task[uni_id][tp_path]
469 self._tech_profile_download_done[uni_id][tp_path] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400470 # Now execute any vlan filter tasks that were queued for later
471 self._execute_queued_vlan_filter_tasks(uni_id)
William Kurkian3a206332019-04-29 11:05:47 -0400472 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500473 def failure(_reason):
474 self.log.warn('tech-profile-config-failure-retrying',
475 _reason=_reason)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700476 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500477 if tp_path in self._tp_service_specific_task[uni_id]:
478 del self._tp_service_specific_task[uni_id][tp_path]
479 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
480 uni_id, tp_path)
481
482 self.log.info('downloading-tech-profile-configuration')
483 self._tp_service_specific_task[uni_id][tp_path] = \
484 BrcmTpServiceSpecificTask(self.omci_agent, self, uni_id)
485 self._deferred = \
486 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
487 self._deferred.addCallbacks(success, failure)
488
489 except Exception as e:
490 self.log.exception("error-loading-tech-profile", e=e)
491 else:
492 self.log.info("tech-profile-config-already-done")
493
494 def update_pm_config(self, device, pm_config):
495 # TODO: This has not been tested
496 self.log.info('update_pm_config', pm_config=pm_config)
497 self.pm_metrics.update(pm_config)
498
499 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
500 # flow decomposition that ultimately comes from onos
501 def update_flow_table(self, device, flows):
502 self.log.debug('function-entry', device=device, flows=flows)
503
504 #
505 # We need to proxy through the OLT to get to the ONU
506 # Configuration from here should be using OMCI
507 #
508 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
509
510 # no point in pushing omci flows if the device isnt reachable
511 if device.connect_status != ConnectStatus.REACHABLE or \
512 device.admin_state != AdminState.ENABLED:
513 self.log.warn("device-disabled-or-offline-skipping-flow-update",
514 admin=device.admin_state, connect=device.connect_status)
515 return
516
517 def is_downstream(port):
518 return port == self._pon_port_number
519
520 def is_upstream(port):
521 return not is_downstream(port)
522
523 for flow in flows:
524 _type = None
525 _port = None
526 _vlan_vid = None
527 _udp_dst = None
528 _udp_src = None
529 _ipv4_dst = None
530 _ipv4_src = None
531 _metadata = None
532 _output = None
533 _push_tpid = None
534 _field = None
535 _set_vlan_vid = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400536 _tunnel_id = None
537
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500538 self.log.debug('bulk-flow-update', device_id=device.id, flow=flow)
539 try:
540 _in_port = fd.get_in_port(flow)
541 assert _in_port is not None
542
543 _out_port = fd.get_out_port(flow) # may be None
544
545 if is_downstream(_in_port):
546 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
547 uni_port = self.uni_port(_out_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400548 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500549 elif is_upstream(_in_port):
550 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
551 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400552 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500553 else:
554 raise Exception('port should be 1 or 2 by our convention')
555
556 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
557
558 for field in fd.get_ofb_fields(flow):
559 if field.type == fd.ETH_TYPE:
560 _type = field.eth_type
561 self.log.debug('field-type-eth-type',
562 eth_type=_type)
563
564 elif field.type == fd.IP_PROTO:
565 _proto = field.ip_proto
566 self.log.debug('field-type-ip-proto',
567 ip_proto=_proto)
568
569 elif field.type == fd.IN_PORT:
570 _port = field.port
571 self.log.debug('field-type-in-port',
572 in_port=_port)
573
574 elif field.type == fd.VLAN_VID:
575 _vlan_vid = field.vlan_vid & 0xfff
576 self.log.debug('field-type-vlan-vid',
577 vlan=_vlan_vid)
578
579 elif field.type == fd.VLAN_PCP:
580 _vlan_pcp = field.vlan_pcp
581 self.log.debug('field-type-vlan-pcp',
582 pcp=_vlan_pcp)
583
584 elif field.type == fd.UDP_DST:
585 _udp_dst = field.udp_dst
586 self.log.debug('field-type-udp-dst',
587 udp_dst=_udp_dst)
588
589 elif field.type == fd.UDP_SRC:
590 _udp_src = field.udp_src
591 self.log.debug('field-type-udp-src',
592 udp_src=_udp_src)
593
594 elif field.type == fd.IPV4_DST:
595 _ipv4_dst = field.ipv4_dst
596 self.log.debug('field-type-ipv4-dst',
597 ipv4_dst=_ipv4_dst)
598
599 elif field.type == fd.IPV4_SRC:
600 _ipv4_src = field.ipv4_src
601 self.log.debug('field-type-ipv4-src',
602 ipv4_dst=_ipv4_src)
603
604 elif field.type == fd.METADATA:
605 _metadata = field.table_metadata
606 self.log.debug('field-type-metadata',
607 metadata=_metadata)
608
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400609 elif field.type == fd.TUNNEL_ID:
610 _tunnel_id = field.tunnel_id
611 self.log.debug('field-type-tunnel-id',
612 tunnel_id=_tunnel_id)
613
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500614 else:
615 raise NotImplementedError('field.type={}'.format(
616 field.type))
617
618 for action in fd.get_actions(flow):
619
620 if action.type == fd.OUTPUT:
621 _output = action.output.port
622 self.log.debug('action-type-output',
623 output=_output, in_port=_in_port)
624
625 elif action.type == fd.POP_VLAN:
626 self.log.debug('action-type-pop-vlan',
627 in_port=_in_port)
628
629 elif action.type == fd.PUSH_VLAN:
630 _push_tpid = action.push.ethertype
631 self.log.debug('action-type-push-vlan',
632 push_tpid=_push_tpid, in_port=_in_port)
633 if action.push.ethertype != 0x8100:
634 self.log.error('unhandled-tpid',
635 ethertype=action.push.ethertype)
636
637 elif action.type == fd.SET_FIELD:
638 _field = action.set_field.field.ofb_field
639 assert (action.set_field.field.oxm_class ==
640 OFPXMC_OPENFLOW_BASIC)
641 self.log.debug('action-type-set-field',
642 field=_field, in_port=_in_port)
643 if _field.type == fd.VLAN_VID:
644 _set_vlan_vid = _field.vlan_vid & 0xfff
645 self.log.debug('set-field-type-vlan-vid',
646 vlan_vid=_set_vlan_vid)
647 else:
648 self.log.error('unsupported-action-set-field-type',
649 field_type=_field.type)
650 else:
651 self.log.error('unsupported-action-type',
652 action_type=action.type, in_port=_in_port)
653
654 # TODO: We only set vlan omci flows. Handle omci matching ethertypes at some point in another task
655 if _type is not None:
656 self.log.warn('ignoring-flow-with-ethType', ethType=_type)
657 elif _set_vlan_vid is None or _set_vlan_vid == 0:
658 self.log.warn('ignorning-flow-that-does-not-set-vlanid')
659 else:
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400660 self.log.warn('set-vlanid', uni_id=uni_id, uni_port=uni_port, set_vlan_vid=_set_vlan_vid)
661 self._add_vlan_filter_task(device, uni_id, uni_port, _set_vlan_vid)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500662 except Exception as e:
663 self.log.exception('failed-to-install-flow', e=e, flow=flow)
664
665
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400666
667 def _add_vlan_filter_task(self, device,uni_id, uni_port, _set_vlan_vid):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500668 assert uni_port is not None
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400669 if uni_id in self._tech_profile_download_done and self._tech_profile_download_done[uni_id] != {}:
670 @inlineCallbacks
671 def success(_results):
672 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700673 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400674 self._vlan_filter_task = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500675
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400676 @inlineCallbacks
677 def failure(_reason):
678 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700679 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400680 self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT,
681 self._add_vlan_filter_task, device,uni_port.port_number, uni_port, _set_vlan_vid)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500682
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400683 self.log.info('setting-vlan-tag')
684 self._vlan_filter_task = BrcmVlanFilterTask(self.omci_agent, self.device_id, uni_port, _set_vlan_vid)
685 self._deferred = self._onu_omci_device.task_runner.queue_task(self._vlan_filter_task)
686 self._deferred.addCallbacks(success, failure)
687 else:
688 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
689 uni_id=uni_id)
690 self._queued_vlan_filter_task[uni_id] = {"device": device, \
691 "uni_id":uni_id,
692 "uni_port": uni_port,
693 "set_vlan_vid": _set_vlan_vid}
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500694
695 def get_tx_id(self):
696 self.log.debug('function-entry')
697 self.tx_id += 1
698 return self.tx_id
699
Matt Jeannereta32441c2019-03-07 05:16:37 -0500700 def process_inter_adapter_message(self, request):
701 self.log.debug('process-inter-adapter-message', msg=request)
702 try:
703 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
704 omci_msg = InterAdapterOmciMessage()
705 request.body.Unpack(omci_msg)
706 self.log.debug('inter-adapter-recv-omci', omci_msg=omci_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500707
Matt Jeannereta32441c2019-03-07 05:16:37 -0500708 self.receive_message(omci_msg.message)
709
710 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
711 onu_indication = OnuIndication()
712 request.body.Unpack(onu_indication)
713 self.log.debug('inter-adapter-recv-onu-ind', onu_indication=onu_indication)
714
715 if onu_indication.oper_state == "up":
716 self.create_interface(onu_indication)
717 elif onu_indication.oper_state == "down":
718 self.update_interface(onu_indication)
719 else:
720 self.log.error("unknown-onu-indication", onu_indication=onu_indication)
721
Matt Jeanneret3bfebff2019-04-12 18:25:03 -0400722 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
723 tech_msg = InterAdapterTechProfileDownloadMessage()
724 request.body.Unpack(tech_msg)
725 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
726
727 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
728
Matt Jeannereta32441c2019-03-07 05:16:37 -0500729 else:
730 self.log.error("inter-adapter-unhandled-type", request=request)
731
732 except Exception as e:
733 self.log.exception("error-processing-inter-adapter-message", e=e)
734
735 # Called each time there is an onu "up" indication from the olt handler
736 @inlineCallbacks
737 def create_interface(self, onu_indication):
738 self.log.debug('function-entry', onu_indication=onu_indication)
739 self._onu_indication = onu_indication
740
Matt Jeanneretc083f462019-03-11 15:02:01 -0400741 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
742 connect_status=ConnectStatus.REACHABLE)
743
Matt Jeannereta32441c2019-03-07 05:16:37 -0500744 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500745
746 self.log.debug('starting-openomci-statemachine')
747 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500748 onu_device.reason = "starting-openomci"
Mahir Gunyelfe6ac432019-09-04 10:17:14 -0700749 reactor.callLater(1, self._onu_omci_device.start,onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700750 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500751 self._heartbeat.enabled = True
752
753 # Currently called each time there is an onu "down" indication from the olt handler
754 # TODO: possibly other reasons to "update" from the olt?
Matt Jeannereta32441c2019-03-07 05:16:37 -0500755 @inlineCallbacks
756 def update_interface(self, onu_indication):
757 self.log.debug('function-entry', onu_indication=onu_indication)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500758
Matt Jeannereta32441c2019-03-07 05:16:37 -0500759 if onu_indication.oper_state == 'down':
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500760 self.log.debug('stopping-openomci-statemachine')
761 reactor.callLater(0, self._onu_omci_device.stop)
762
763 # Let TP download happen again
764 for uni_id in self._tp_service_specific_task:
765 self._tp_service_specific_task[uni_id].clear()
766 for uni_id in self._tech_profile_download_done:
767 self._tech_profile_download_done[uni_id].clear()
768
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700769 self.disable_ports()
770 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
771 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
772 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500773 else:
774 self.log.debug('not-changing-openomci-statemachine')
775
776 # Not currently called by olt or anything else
William Kurkian3a206332019-04-29 11:05:47 -0400777 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500778 def remove_interface(self, data):
779 self.log.debug('function-entry', data=data)
780
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500781 self.log.debug('stopping-openomci-statemachine')
782 reactor.callLater(0, self._onu_omci_device.stop)
783
784 # Let TP download happen again
785 for uni_id in self._tp_service_specific_task:
786 self._tp_service_specific_task[uni_id].clear()
787 for uni_id in self._tech_profile_download_done:
788 self._tech_profile_download_done[uni_id].clear()
789
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700790 self.disable_ports()
791 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500792
793 # TODO: im sure there is more to do here
794
795 # Not currently called. Would be called presumably from the olt handler
William Kurkian3a206332019-04-29 11:05:47 -0400796 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500797 def remove_gemport(self, data):
798 self.log.debug('remove-gemport', data=data)
William Kurkian3a206332019-04-29 11:05:47 -0400799 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500800 if device.connect_status != ConnectStatus.REACHABLE:
801 self.log.error('device-unreachable')
802 return
803
804 # Not currently called. Would be called presumably from the olt handler
William Kurkian3a206332019-04-29 11:05:47 -0400805 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500806 def remove_tcont(self, tcont_data, traffic_descriptor_data):
807 self.log.debug('remove-tcont', tcont_data=tcont_data, traffic_descriptor_data=traffic_descriptor_data)
William Kurkian3a206332019-04-29 11:05:47 -0400808 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500809 if device.connect_status != ConnectStatus.REACHABLE:
810 self.log.error('device-unreachable')
811 return
812
813 # TODO: Create some omci task that encompases this what intended
814
815 # Not currently called. Would be called presumably from the olt handler
816 def create_multicast_gemport(self, data):
817 self.log.debug('function-entry', data=data)
818
819 # TODO: create objects and populate for later omci calls
820
821 def disable(self, device):
822 self.log.debug('function-entry', device=device)
823 try:
824 self.log.info('sending-uni-lock-towards-device', device=device)
825
Matt Jeanneret80766692019-05-03 09:58:38 -0400826 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500827 def stop_anyway(reason):
828 # proceed with disable regardless if we could reach the onu. for example onu is unplugged
829 self.log.debug('stopping-openomci-statemachine')
830 reactor.callLater(0, self._onu_omci_device.stop)
831
832 # Let TP download happen again
833 for uni_id in self._tp_service_specific_task:
834 self._tp_service_specific_task[uni_id].clear()
835 for uni_id in self._tech_profile_download_done:
836 self._tech_profile_download_done[uni_id].clear()
837
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700838 self.disable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500839 device.oper_status = OperStatus.UNKNOWN
840 device.reason = "omci-admin-lock"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400841 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500842
843 # lock all the unis
844 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=True)
845 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
846 self._deferred.addCallbacks(stop_anyway, stop_anyway)
847 except Exception as e:
848 log.exception('exception-in-onu-disable', exception=e)
849
William Kurkian3a206332019-04-29 11:05:47 -0400850 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500851 def reenable(self, device):
852 self.log.debug('function-entry', device=device)
853 try:
854 # Start up OpenOMCI state machines for this device
855 # this will ultimately resync mib and unlock unis on successful redownloading the mib
856 self.log.debug('restarting-openomci-statemachine')
857 self._subscribe_to_events()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700858 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
serkant.uluderya2cb65f72019-09-30 14:01:51 -0700859 reactor.callLater(1, self._onu_omci_device.start, device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500860 self._heartbeat.enabled = True
861 except Exception as e:
862 log.exception('exception-in-onu-reenable', exception=e)
863
William Kurkian3a206332019-04-29 11:05:47 -0400864 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500865 def reboot(self):
866 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -0400867 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500868 if device.connect_status != ConnectStatus.REACHABLE:
869 self.log.error("device-unreachable")
870 return
871
William Kurkian3a206332019-04-29 11:05:47 -0400872 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500873 def success(_results):
874 self.log.info('reboot-success', _results=_results)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700875 self.disable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500876 device.connect_status = ConnectStatus.UNREACHABLE
877 device.oper_status = OperStatus.DISCOVERED
878 device.reason = "rebooting"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -0400879 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500880
881 def failure(_reason):
882 self.log.info('reboot-failure', _reason=_reason)
883
884 self._deferred = self._onu_omci_device.reboot()
885 self._deferred.addCallbacks(success, failure)
886
William Kurkian3a206332019-04-29 11:05:47 -0400887 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700888 def disable_ports(self):
889 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500890
891 # Disable all ports on that device
Matt Jeanneret80766692019-05-03 09:58:38 -0400892 yield self.core_proxy.ports_state_update(self.device_id, OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500893
William Kurkian3a206332019-04-29 11:05:47 -0400894 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700895 def enable_ports(self):
896 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500897
Matt Jeanneret80766692019-05-03 09:58:38 -0400898 # Enable all ports on that device
899 yield self.core_proxy.ports_state_update(self.device_id, OperStatus.ACTIVE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500900
901 # Called just before openomci state machine is started. These listen for events from selected state machines,
902 # most importantly, mib in sync. Which ultimately leads to downloading the mib
903 def _subscribe_to_events(self):
904 self.log.debug('function-entry')
905
906 # OMCI MIB Database sync status
907 bus = self._onu_omci_device.event_bus
908 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
909 OnuDeviceEvents.MibDatabaseSyncEvent)
910 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
911
912 # OMCI Capabilities
913 bus = self._onu_omci_device.event_bus
914 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
915 OnuDeviceEvents.OmciCapabilitiesEvent)
916 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
917
918 # Called when the mib is in sync
919 def in_sync_handler(self, _topic, msg):
920 self.log.debug('function-entry', _topic=_topic, msg=msg)
921 if self._in_sync_subscription is not None:
922 try:
923 in_sync = msg[IN_SYNC_KEY]
924
925 if in_sync:
926 # Only call this once
927 bus = self._onu_omci_device.event_bus
928 bus.unsubscribe(self._in_sync_subscription)
929 self._in_sync_subscription = None
930
931 # Start up device_info load
932 self.log.debug('running-mib-sync')
933 reactor.callLater(0, self._mib_in_sync)
934
935 except Exception as e:
936 self.log.exception('in-sync', e=e)
937
938 def capabilties_handler(self, _topic, _msg):
939 self.log.debug('function-entry', _topic=_topic, msg=_msg)
940 if self._capabilities_subscription is not None:
941 self.log.debug('capabilities-handler-done')
942
943 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
944 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
945 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -0400946 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500947 def _mib_in_sync(self):
948 self.log.debug('function-entry')
949
950 omci = self._onu_omci_device
951 in_sync = omci.mib_db_in_sync
952
Matt Jeanneretc083f462019-03-11 15:02:01 -0400953 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700954 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500955
956 if not self._dev_info_loaded:
957 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
958
959 omci_dev = self._onu_omci_device
960 config = omci_dev.configuration
961
962 # TODO: run this sooner somehow. shouldnt have to wait for mib sync to push an initial download
963 # In Sync, we can register logical ports now. Ideally this could occur on
964 # the first time we received a successful (no timeout) OMCI Rx response.
965 try:
966
967 # sort the lists so we get consistent port ordering.
968 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
969 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
970 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
971 veip_list = sorted(config.veip_entities) if config.veip_entities else []
972
973 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500974 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700975 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500976 raise Exception("onu-missing-required-elements")
977
978 # Currently logging the ani, pptp, veip, and uni for information purposes.
979 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
980 # And in some ONU the UNI-G list is incomplete or incorrect...
981 for entity_id in ani_list:
982 ani_value = config.ani_g_entities[entity_id]
983 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
984 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
985 self._total_tcont_count = ani_value.get('total-tcont-count')
986 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
987
988 for entity_id in uni_list:
989 uni_value = config.uni_g_entities[entity_id]
990 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
991
992 uni_entities = OrderedDict()
993 for entity_id in pptp_list:
994 pptp_value = config.pptp_entities[entity_id]
995 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
996 uni_entities[entity_id] = UniType.PPTP
997
998 for entity_id in veip_list:
999 veip_value = config.veip_entities[entity_id]
1000 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1001 uni_entities[entity_id] = UniType.VEIP
1002
1003 uni_id = 0
1004 for entity_id, uni_type in uni_entities.iteritems():
1005 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001006 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001007 uni_id += 1
1008 except AssertionError as e:
1009 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1010
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001011 self._qos_flexibility = config.qos_configuration_flexibility or 0
1012 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1013
1014 if self._unis:
1015 self._dev_info_loaded = True
1016 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001017 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001018 self.log.warn("no-usable-unis")
1019 raise Exception("no-usable-unis")
1020
1021 except Exception as e:
1022 self.log.exception('device-info-load', e=e)
1023 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1024
1025 else:
1026 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1027
1028 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001029 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001030
1031 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001032 def success(_results):
1033 self.log.info('mib-download-success', _results=_results)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001034 yield self.enable_ports()
Matt Jeanneretc083f462019-03-11 15:02:01 -04001035 yield self.core_proxy.device_state_update(device.id,
1036 oper_status=OperStatus.ACTIVE, connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001037 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001038 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001039 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001040
Matt Jeanneretc083f462019-03-11 15:02:01 -04001041 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001042 def failure(_reason):
1043 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001044 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001045 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1046
1047 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1048 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1049 self.log.info('downloading-initial-mib-configuration')
1050 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1051 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1052 self._deferred.addCallbacks(success, failure)
1053 else:
1054 self.log.info('admin-down-disabling')
1055 self.disable(device)
1056 else:
1057 self.log.info('device-info-not-loaded-skipping-mib-download')
1058
Matt Jeanneretc083f462019-03-11 15:02:01 -04001059 @inlineCallbacks
1060 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001061 self.log.debug('function-entry')
1062
Matt Jeanneretc083f462019-03-11 15:02:01 -04001063 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 -05001064
1065 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1066 uni_name = "uni-{}".format(uni_no)
1067
1068 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
1069
1070 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 -04001071 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001072
1073 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1074 uni_port.entity_id = entity_id
1075 uni_port.enabled = True
1076 uni_port.mac_bridge_port_num = mac_bridge_port_num
1077
1078 self.log.debug("created-uni-port", uni=uni_port)
1079
Matt Jeanneretc083f462019-03-11 15:02:01 -04001080 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001081
1082 self._unis[uni_port.port_number] = uni_port
1083
1084 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Yongjie Zhang286099c2019-08-06 13:39:07 -04001085 uni_ports=self._unis.values(), serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001086
Matt Jeanneretc083f462019-03-11 15:02:01 -04001087 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1088 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
1089 MAX_PONS_PER_OLT = 16
Mahir Gunyel0e1588a2019-06-27 06:12:47 -07001090 MAX_ONUS_PER_PON = 128
Matt Jeanneretc083f462019-03-11 15:02:01 -04001091 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001092
Matt Jeanneretc083f462019-03-11 15:02:01 -04001093 assert intf_id < MAX_PONS_PER_OLT
1094 assert onu_id < MAX_ONUS_PER_PON
1095 assert uni_id < MAX_UNIS_PER_ONU
Matt Jeanneret3b7db442019-04-22 16:29:48 -04001096 return intf_id << 11 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001097
1098 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001099 def onu_active_event(self):
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001100 self.log.debug('function-entry')
1101 try:
1102 device = yield self.core_proxy.get_device(self.device_id)
1103 parent_device = yield self.core_proxy.get_device(self.parent_id)
1104 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001105 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001106
1107 self.log.debug("onu-indication-context-data",
1108 pon_id=self._onu_indication.intf_id,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001109 onu_id=self._onu_indication.onu_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001110 registration_id=self.device_id,
1111 device_id=self.device_id,
1112 onu_serial_number=device.serial_number,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001113 olt_serial_number=olt_serial_number,
1114 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001115
Devmalya Paulffc89df2019-07-31 17:43:13 -04001116 self.log.debug("Trying-to-raise-onu-active-event")
1117 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001118 self._onu_indication.intf_id,
1119 device.serial_number,
1120 str(self.device_id),
Devmalya Paulffc89df2019-07-31 17:43:13 -04001121 olt_serial_number,raised_ts,
1122 onu_id=self._onu_indication.onu_id).send(True)
1123 except Exception as active_event_error:
1124 self.log.exception('onu-activated-event-error',
1125 errmsg=active_event_error.message)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001126