blob: 5ca6bd2ae093cc3da98a1592f36c40139c964b41 [file] [log] [blame]
Matt Jeannerete6a70332018-07-20 16:11:25 -04001#
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
Girish Gowdruab836e92018-10-25 01:17:57 -070021import json
22import ast
Matt Jeannerete6a70332018-07-20 16:11:25 -040023import structlog
Craig Lutgenabd9c842018-11-15 23:58:27 +000024
25from collections import OrderedDict
26
Matt Jeannerete6a70332018-07-20 16:11:25 -040027from twisted.internet import reactor, task
28from twisted.internet.defer import DeferredQueue, inlineCallbacks, returnValue, TimeoutError
29
Scott Bakerc474bb92018-10-12 16:19:18 -070030from heartbeat import HeartBeat
31from voltha.extensions.kpi.onu.onu_pm_metrics import OnuPmMetrics
32from voltha.extensions.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
Chip Boling3186eb52018-11-02 14:28:01 -050033from voltha.extensions.alarms.adapter_alarms import AdapterAlarms
Scott Bakerc474bb92018-10-12 16:19:18 -070034
Matt Jeannerete6a70332018-07-20 16:11:25 -040035from common.utils.indexpool import IndexPool
Matt Jeannerete6a70332018-07-20 16:11:25 -040036import voltha.core.flow_decomposer as fd
37from voltha.registry import registry
Girish Gowdruab836e92018-10-25 01:17:57 -070038from voltha.core.config.config_backend import ConsulStore
39from voltha.core.config.config_backend import EtcdStore
Matt Jeannerete6a70332018-07-20 16:11:25 -040040from voltha.protos import third_party
Matt Jeanneretf4448402018-09-25 12:51:19 -040041from voltha.protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeannerete6a70332018-07-20 16:11:25 -040042from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port
Matt Jeannerete6a70332018-07-20 16:11:25 -040043from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData
44from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData
45from voltha.extensions.omci.onu_configuration import OMCCVersion
46from voltha.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Girish Gowdruab836e92018-10-25 01:17:57 -070047 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeannerete6a70332018-07-20 16:11:25 -040048from voltha.adapters.brcm_openomci_onu.omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdruab836e92018-10-25 01:17:57 -070049from voltha.adapters.brcm_openomci_onu.omci.brcm_tp_service_specific_task import BrcmTpServiceSpecificTask
Matt Jeanneret6da55792018-08-08 16:44:18 -040050from voltha.adapters.brcm_openomci_onu.omci.brcm_uni_lock_task import BrcmUniLockTask
Matt Jeanneretf4448402018-09-25 12:51:19 -040051from voltha.adapters.brcm_openomci_onu.omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeannerete6a70332018-07-20 16:11:25 -040052from voltha.adapters.brcm_openomci_onu.onu_gem_port import *
53from voltha.adapters.brcm_openomci_onu.onu_tcont import *
54from voltha.adapters.brcm_openomci_onu.pon_port import *
55from voltha.adapters.brcm_openomci_onu.uni_port import *
56from voltha.adapters.brcm_openomci_onu.onu_traffic_descriptor import *
Girish Gowdru36ef0692018-11-27 02:51:51 -080057from common.tech_profile.tech_profile import TechProfile
Matt Jeannerete6a70332018-07-20 16:11:25 -040058
Matt Jeannerete6a70332018-07-20 16:11:25 -040059OP = EntityOperations
60RC = ReasonCodes
61
Matt Jeannerete6a70332018-07-20 16:11:25 -040062_ = third_party
63log = structlog.get_logger()
64
Matt Jeanneret94f8d292018-08-31 12:49:27 -040065_STARTUP_RETRY_WAIT = 20
Matt Jeannerete6a70332018-07-20 16:11:25 -040066
67
Matt Jeannerete6a70332018-07-20 16:11:25 -040068class BrcmOpenomciOnuHandler(object):
69
70 def __init__(self, adapter, device_id):
71 self.log = structlog.get_logger(device_id=device_id)
72 self.log.debug('function-entry')
73 self.adapter = adapter
74 self.adapter_agent = adapter.adapter_agent
Girish Gowdru1e77ea02018-09-24 09:10:35 -070075 self.parent_adapter = None
76 self.parent_id = None
Matt Jeannerete6a70332018-07-20 16:11:25 -040077 self.device_id = device_id
78 self.incoming_messages = DeferredQueue()
79 self.event_messages = DeferredQueue()
80 self.proxy_address = None
81 self.tx_id = 0
82 self._enabled = False
Chip Boling3186eb52018-11-02 14:28:01 -050083 self.alarms = None
Scott Bakerc474bb92018-10-12 16:19:18 -070084 self.pm_metrics = None
Matt Jeannerete6a70332018-07-20 16:11:25 -040085 self._omcc_version = OMCCVersion.Unknown
86 self._total_tcont_count = 0 # From ANI-G ME
87 self._qos_flexibility = 0 # From ONT2_G ME
88
89 self._onu_indication = None
90 self._unis = dict() # Port # -> UniPort
Matt Jeannerete6a70332018-07-20 16:11:25 -040091
92 self._pon = None
Girish Gowdruab836e92018-10-25 01:17:57 -070093 # TODO: probably shouldnt be hardcoded, determine from olt maybe?
Matt Jeannerete6a70332018-07-20 16:11:25 -040094 self._pon_port_number = 100
95 self.logical_device_id = None
96
Scott Bakerc474bb92018-10-12 16:19:18 -070097 self._heartbeat = HeartBeat.create(self, device_id)
98
Matt Jeannerete6a70332018-07-20 16:11:25 -040099 # Set up OpenOMCI environment
100 self._onu_omci_device = None
101 self._dev_info_loaded = False
102 self._deferred = None
103
104 self._in_sync_subscription = None
105 self._connectivity_subscription = None
106 self._capabilities_subscription = None
107
Girish Gowdruab836e92018-10-25 01:17:57 -0700108 self.mac_bridge_service_profile_entity_id = 0x201
109 self.gal_enet_profile_entity_id = 0x1
110
111 self._tp_service_specific_task = dict()
112 self._tech_profile_download_done = dict()
113
114 # Initialize KV store client
115 self.args = registry('main').get_args()
116 if self.args.backend == 'etcd':
117 host, port = self.args.etcd.split(':', 1)
Girish Gowdru36ef0692018-11-27 02:51:51 -0800118 self.kv_client = EtcdStore(host, port,
119 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
Girish Gowdruab836e92018-10-25 01:17:57 -0700120 elif self.args.backend == 'consul':
121 host, port = self.args.consul.split(':', 1)
Girish Gowdru36ef0692018-11-27 02:51:51 -0800122 self.kv_client = ConsulStore(host, port,
123 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
Girish Gowdruab836e92018-10-25 01:17:57 -0700124 else:
125 self.log.error('Invalid-backend')
126 raise Exception("Invalid-backend-for-kv-store")
127
128 # Handle received ONU event messages
129 reactor.callLater(0, self.handle_onu_events)
130
Matt Jeannerete6a70332018-07-20 16:11:25 -0400131 @property
132 def enabled(self):
Matt Jeannerete6a70332018-07-20 16:11:25 -0400133 return self._enabled
134
135 @enabled.setter
136 def enabled(self, value):
Matt Jeannerete6a70332018-07-20 16:11:25 -0400137 if self._enabled != value:
138 self._enabled = value
139
140 @property
141 def omci_agent(self):
Matt Jeannerete6a70332018-07-20 16:11:25 -0400142 return self.adapter.omci_agent
143
144 @property
145 def omci_cc(self):
Matt Jeannerete6a70332018-07-20 16:11:25 -0400146 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
147
148 @property
Scott Bakerc474bb92018-10-12 16:19:18 -0700149 def heartbeat(self):
150 return self._heartbeat
151
152 @property
Matt Jeannerete6a70332018-07-20 16:11:25 -0400153 def uni_ports(self):
Matt Jeannerete6a70332018-07-20 16:11:25 -0400154 return self._unis.values()
155
156 def uni_port(self, port_no_or_name):
Matt Jeannerete6a70332018-07-20 16:11:25 -0400157 if isinstance(port_no_or_name, (str, unicode)):
158 return next((uni for uni in self.uni_ports
159 if uni.name == port_no_or_name), None)
160
161 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
Craig Lutgenabd9c842018-11-15 23:58:27 +0000162 return next((uni for uni in self.uni_ports
163 if uni.logical_port_number == port_no_or_name), None)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400164
165 @property
166 def pon_port(self):
Matt Jeannerete6a70332018-07-20 16:11:25 -0400167 return self._pon
168
Matt Jeannerete6a70332018-07-20 16:11:25 -0400169 def receive_message(self, msg):
Matt Jeannerete6a70332018-07-20 16:11:25 -0400170 if self.omci_cc is not None:
171 self.omci_cc.receive_message(msg)
172
Matt Jeanneret54c82662018-08-23 11:21:19 -0400173 # Called once when the adapter creates the device/onu instance
Matt Jeannerete6a70332018-07-20 16:11:25 -0400174 def activate(self, device):
175 self.log.debug('function-entry', device=device)
176
177 # first we verify that we got parent reference and proxy info
178 assert device.parent_id
179 assert device.proxy_address.device_id
180
181 # register for proxied messages right away
182 self.proxy_address = device.proxy_address
183 self.adapter_agent.register_for_proxied_messages(device.proxy_address)
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700184 self.parent_id = device.parent_id
185 parent_device = self.adapter_agent.get_device(self.parent_id)
186 if parent_device.type == 'openolt':
Girish Gowdruab836e92018-10-25 01:17:57 -0700187 self.parent_adapter = registry('adapter_loader'). \
188 get_agent(parent_device.adapter).adapter
Matt Jeannerete6a70332018-07-20 16:11:25 -0400189
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400190 if self.enabled is not True:
191 self.log.info('activating-new-onu')
192 # populate what we know. rest comes later after mib sync
Gamze Abaka53cc0a22019-01-31 12:06:11 +0000193 device.root = False
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400194 device.vendor = 'Broadcom'
195 device.connect_status = ConnectStatus.REACHABLE
Matt Jeanneret6da55792018-08-08 16:44:18 -0400196 device.oper_status = OperStatus.DISCOVERED
Matt Jeanneret94f8d292018-08-31 12:49:27 -0400197 device.reason = 'activating-onu'
Scott Bakerc474bb92018-10-12 16:19:18 -0700198
199 # pm_metrics requires a logical device id
200 parent_device = self.adapter_agent.get_device(device.parent_id)
201 self.logical_device_id = parent_device.parent_id
202 assert self.logical_device_id, 'Invalid logical device ID'
203
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400204 self.adapter_agent.update_device(device)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400205
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400206 self.log.debug('set-device-discovered')
Matt Jeannerete6a70332018-07-20 16:11:25 -0400207
Matt Jeanneret54c82662018-08-23 11:21:19 -0400208 self._init_pon_state(device)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400209
Scott Bakerc474bb92018-10-12 16:19:18 -0700210 ############################################################################
211 # Setup PM configuration for this device
212 # Pass in ONU specific options
213 kwargs = {
214 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
215 'heartbeat': self.heartbeat,
216 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
217 }
218 self.pm_metrics = OnuPmMetrics(self.adapter_agent, self.device_id,
219 self.logical_device_id, grouped=True,
220 freq_override=False, **kwargs)
221 pm_config = self.pm_metrics.make_proto()
222 self._onu_omci_device.set_pm_config(self.pm_metrics.omci_pm.openomci_interval_pm)
223 self.log.info("initial-pm-config", pm_config=pm_config)
224 self.adapter_agent.update_device_pm_config(pm_config, init=True)
225
Chip Boling3186eb52018-11-02 14:28:01 -0500226 ############################################################################
227 # Setup Alarm handler
228 self.alarms = AdapterAlarms(self.adapter_agent, device.id, self.logical_device_id)
229 # Note, ONU ID and UNI intf set in add_uni_port method
230 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.alarms,
231 ani_ports=[self._pon])
Chip Boling91911df2019-03-15 14:34:26 -0500232
233 # Start collecting stats from the device after a brief pause
234 reactor.callLater(10, self.pm_metrics.start_collector)
235
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400236 self.enabled = True
237 else:
238 self.log.info('onu-already-activated')
Matt Jeannerete6a70332018-07-20 16:11:25 -0400239
Matt Jeanneret54c82662018-08-23 11:21:19 -0400240 # Called once when the adapter needs to re-create device. usually on vcore restart
Matt Jeannerete6a70332018-07-20 16:11:25 -0400241 def reconcile(self, device):
242 self.log.debug('function-entry', device=device)
243
244 # first we verify that we got parent reference and proxy info
245 assert device.parent_id
246 assert device.proxy_address.device_id
247
248 # register for proxied messages right away
249 self.proxy_address = device.proxy_address
250 self.adapter_agent.register_for_proxied_messages(device.proxy_address)
251
Matt Jeanneret54c82662018-08-23 11:21:19 -0400252 if self.enabled is not True:
253 self.log.info('reconciling-broadcom-onu-device')
Matt Jeannerete6a70332018-07-20 16:11:25 -0400254
Matt Jeanneret54c82662018-08-23 11:21:19 -0400255 self._init_pon_state(device)
256
257 # need to restart state machines on vcore restart. there is no indication to do it for us.
258 self._onu_omci_device.start()
Matt Jeanneret94f8d292018-08-31 12:49:27 -0400259 device.reason = "restarting-openomci"
260 self.adapter_agent.update_device(device)
Matt Jeanneret54c82662018-08-23 11:21:19 -0400261
262 # TODO: this is probably a bit heavy handed
263 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
264 # This may not be necessary when mib resync actually works
265 reactor.callLater(1, self.reboot)
266
267 self.enabled = True
268 else:
269 self.log.info('onu-already-activated')
270
Girish Gowdruab836e92018-10-25 01:17:57 -0700271 @inlineCallbacks
272 def handle_onu_events(self):
273 event_msg = yield self.event_messages.get()
274 try:
275 if event_msg['event'] == 'download_tech_profile':
276 tp_path = event_msg['event_data']
Craig Lutgenabd9c842018-11-15 23:58:27 +0000277 uni_id = event_msg['uni_id']
278 self.load_and_configure_tech_profile(uni_id, tp_path)
Girish Gowdruab836e92018-10-25 01:17:57 -0700279
280 except Exception as e:
281 self.log.error("exception-handling-onu-event", e=e)
282
283 # Handle next event
284 reactor.callLater(0, self.handle_onu_events)
Matt Jeanneret54c82662018-08-23 11:21:19 -0400285
286 def _init_pon_state(self, device):
287 self.log.debug('function-entry', device=device)
288
289 self._pon = PonPort.create(self, self._pon_port_number)
290 self.adapter_agent.add_port(device.id, self._pon.get_port())
291
292 self.log.debug('added-pon-port-to-agent', pon=self._pon)
293
294 parent_device = self.adapter_agent.get_device(device.parent_id)
295 self.logical_device_id = parent_device.parent_id
296
297 self.adapter_agent.update_device(device)
298
299 # Create and start the OpenOMCI ONU Device Entry for this ONU
300 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
301 self.adapter_agent,
Craig Lutgen2eabc862018-10-18 22:14:14 +0000302 support_classes=self.adapter.broadcom_omci,
303 custom_me_map=self.adapter.custom_me_entities())
Matt Jeanneret54c82662018-08-23 11:21:19 -0400304 # Port startup
305 if self._pon is not None:
306 self._pon.enabled = True
Matt Jeannerete6a70332018-07-20 16:11:25 -0400307
308 # TODO: move to UniPort
309 def update_logical_port(self, logical_device_id, port_id, state):
310 try:
311 self.log.info('updating-logical-port', logical_port_id=port_id,
312 logical_device_id=logical_device_id, state=state)
313 logical_port = self.adapter_agent.get_logical_port(logical_device_id,
314 port_id)
315 logical_port.ofp_port.state = state
316 self.adapter_agent.update_logical_port(logical_device_id,
317 logical_port)
318 except Exception as e:
Girish Gowdruab836e92018-10-25 01:17:57 -0700319 self.log.exception("exception-updating-port", e=e)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400320
321 def delete(self, device):
Matt Jeanneret6da55792018-08-08 16:44:18 -0400322 self.log.info('delete-onu', device=device)
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700323 if self.parent_adapter:
Matt Jeanneret6da55792018-08-08 16:44:18 -0400324 try:
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700325 self.parent_adapter.delete_child_device(self.parent_id, device)
Matt Jeanneret6da55792018-08-08 16:44:18 -0400326 except AttributeError:
327 self.log.debug('parent-device-delete-child-not-implemented')
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700328 else:
329 self.log.debug("parent-adapter-not-available")
330
Craig Lutgenabd9c842018-11-15 23:58:27 +0000331 def _create_tconts(self, uni_id, us_scheduler):
Girish Gowdruab836e92018-10-25 01:17:57 -0700332 alloc_id = us_scheduler['alloc_id']
333 q_sched_policy = us_scheduler['q_sched_policy']
334 self.log.debug('create-tcont', us_scheduler=us_scheduler)
335
336 tcontdict = dict()
337 tcontdict['alloc-id'] = alloc_id
338 tcontdict['q_sched_policy'] = q_sched_policy
Craig Lutgenabd9c842018-11-15 23:58:27 +0000339 tcontdict['uni_id'] = uni_id
Girish Gowdruab836e92018-10-25 01:17:57 -0700340
341 # TODO: Not sure what to do with any of this...
342 tddata = dict()
343 tddata['name'] = 'not-sure-td-profile'
344 tddata['fixed-bandwidth'] = "not-sure-fixed"
345 tddata['assured-bandwidth'] = "not-sure-assured"
346 tddata['maximum-bandwidth'] = "not-sure-max"
347 tddata['additional-bw-eligibility-indicator'] = "not-sure-additional"
348
349 td = OnuTrafficDescriptor.create(tddata)
350 tcont = OnuTCont.create(self, tcont=tcontdict, td=td)
351
352 self._pon.add_tcont(tcont)
353
354 self.log.debug('pon-add-tcont', tcont=tcont)
355
356 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
Craig Lutgenabd9c842018-11-15 23:58:27 +0000357 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
Girish Gowdruab836e92018-10-25 01:17:57 -0700358 self.log.debug('create-gemport',
359 gem_ports=gem_ports, direction=direction)
360
361 for gem_port in gem_ports:
362 gemdict = dict()
363 gemdict['gemport_id'] = gem_port['gemport_id']
364 gemdict['direction'] = direction
365 gemdict['alloc_id_ref'] = alloc_id_ref
366 gemdict['encryption'] = gem_port['aes_encryption']
367 gemdict['discard_config'] = dict()
368 gemdict['discard_config']['max_probability'] = \
369 gem_port['discard_config']['max_probability']
370 gemdict['discard_config']['max_threshold'] = \
371 gem_port['discard_config']['max_threshold']
372 gemdict['discard_config']['min_threshold'] = \
373 gem_port['discard_config']['min_threshold']
374 gemdict['discard_policy'] = gem_port['discard_policy']
375 gemdict['max_q_size'] = gem_port['max_q_size']
376 gemdict['pbit_map'] = gem_port['pbit_map']
377 gemdict['priority_q'] = gem_port['priority_q']
378 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
379 gemdict['weight'] = gem_port['weight']
Craig Lutgenabd9c842018-11-15 23:58:27 +0000380 gemdict['uni_id'] = uni_id
Girish Gowdruab836e92018-10-25 01:17:57 -0700381
Matt Jeanneret49b764b2019-01-22 17:50:36 -0500382 gem_port = OnuGemPort.create(self, gem_port=gemdict)
Girish Gowdruab836e92018-10-25 01:17:57 -0700383
384 self._pon.add_gem_port(gem_port)
385
386 self.log.debug('pon-add-gemport', gem_port=gem_port)
387
Craig Lutgenabd9c842018-11-15 23:58:27 +0000388 def _do_tech_profile_configuration(self, uni_id, tp):
Girish Gowdruab836e92018-10-25 01:17:57 -0700389 us_scheduler = tp['us_scheduler']
390 alloc_id = us_scheduler['alloc_id']
Craig Lutgenabd9c842018-11-15 23:58:27 +0000391 self._create_tconts(uni_id, us_scheduler)
Girish Gowdruab836e92018-10-25 01:17:57 -0700392 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
Craig Lutgenabd9c842018-11-15 23:58:27 +0000393 self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
Girish Gowdruab836e92018-10-25 01:17:57 -0700394 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
Craig Lutgenabd9c842018-11-15 23:58:27 +0000395 self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
Girish Gowdruab836e92018-10-25 01:17:57 -0700396
Craig Lutgenabd9c842018-11-15 23:58:27 +0000397 def load_and_configure_tech_profile(self, uni_id, tp_path):
Craig Lutgenad139372018-12-17 16:02:42 -0600398 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Girish Gowdruab836e92018-10-25 01:17:57 -0700399
Craig Lutgenabd9c842018-11-15 23:58:27 +0000400 if uni_id not in self._tp_service_specific_task:
401 self._tp_service_specific_task[uni_id] = dict()
402
403 if uni_id not in self._tech_profile_download_done:
404 self._tech_profile_download_done[uni_id] = dict()
405
406 if tp_path not in self._tech_profile_download_done[uni_id]:
407 self._tech_profile_download_done[uni_id][tp_path] = False
408
409 if not self._tech_profile_download_done[uni_id][tp_path]:
Girish Gowdruab836e92018-10-25 01:17:57 -0700410 try:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000411 if tp_path in self._tp_service_specific_task[uni_id]:
Girish Gowdruab836e92018-10-25 01:17:57 -0700412 self.log.info("tech-profile-config-already-in-progress",
413 tp_path=tp_path)
414 return
415
416 tp = self.kv_client[tp_path]
417 tp = ast.literal_eval(tp)
418 self.log.debug("tp-instance", tp=tp)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000419 self._do_tech_profile_configuration(uni_id, tp)
Girish Gowdruab836e92018-10-25 01:17:57 -0700420
421 def success(_results):
422 self.log.info("tech-profile-config-done-successfully")
423 device = self.adapter_agent.get_device(self.device_id)
424 device.reason = 'tech-profile-config-download-success'
425 self.adapter_agent.update_device(device)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000426 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
Girish Gowdruab836e92018-10-25 01:17:57 -0700429
430 def failure(_reason):
431 self.log.warn('tech-profile-config-failure-retrying',
432 _reason=_reason)
433 device = self.adapter_agent.get_device(self.device_id)
434 device.reason = 'tech-profile-config-download-failure-retrying'
435 self.adapter_agent.update_device(device)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000436 if tp_path in self._tp_service_specific_task[uni_id]:
437 del self._tp_service_specific_task[uni_id][tp_path]
Girish Gowdruab836e92018-10-25 01:17:57 -0700438 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000439 uni_id, tp_path)
Girish Gowdruab836e92018-10-25 01:17:57 -0700440
441 self.log.info('downloading-tech-profile-configuration')
Craig Lutgenabd9c842018-11-15 23:58:27 +0000442 self._tp_service_specific_task[uni_id][tp_path] = \
443 BrcmTpServiceSpecificTask(self.omci_agent, self, uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700444 self._deferred = \
Craig Lutgenabd9c842018-11-15 23:58:27 +0000445 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Girish Gowdruab836e92018-10-25 01:17:57 -0700446 self._deferred.addCallbacks(success, failure)
447
448 except Exception as e:
449 self.log.exception("error-loading-tech-profile", e=e)
450 else:
451 self.log.info("tech-profile-config-already-done")
452
Scott Bakerc474bb92018-10-12 16:19:18 -0700453 def update_pm_config(self, device, pm_config):
454 # TODO: This has not been tested
455 self.log.info('update_pm_config', pm_config=pm_config)
456 self.pm_metrics.update(pm_config)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400457
Matt Jeanneret54c82662018-08-23 11:21:19 -0400458 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
459 # flow decomposition that ultimately comes from onos
Matt Jeannerete6a70332018-07-20 16:11:25 -0400460 def update_flow_table(self, device, flows):
461 self.log.debug('function-entry', device=device, flows=flows)
Girish Gowdruab836e92018-10-25 01:17:57 -0700462
Matt Jeannerete6a70332018-07-20 16:11:25 -0400463 #
464 # We need to proxy through the OLT to get to the ONU
465 # Configuration from here should be using OMCI
466 #
Girish Gowdruab836e92018-10-25 01:17:57 -0700467 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400468
Matt Jeanneret1c90e502018-11-12 17:38:42 -0500469 # no point in pushing omci flows if the device isnt reachable
470 if device.connect_status != ConnectStatus.REACHABLE or \
471 device.admin_state != AdminState.ENABLED:
472 self.log.warn("device-disabled-or-offline-skipping-flow-update",
473 admin=device.admin_state, connect=device.connect_status)
474 return
475
Matt Jeannerete6a70332018-07-20 16:11:25 -0400476 def is_downstream(port):
477 return port == self._pon_port_number
478
479 def is_upstream(port):
480 return not is_downstream(port)
481
482 for flow in flows:
483 _type = None
484 _port = None
485 _vlan_vid = None
486 _udp_dst = None
487 _udp_src = None
488 _ipv4_dst = None
489 _ipv4_src = None
490 _metadata = None
491 _output = None
492 _push_tpid = None
493 _field = None
494 _set_vlan_vid = None
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400495 self.log.debug('bulk-flow-update', device_id=device.id, flow=flow)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400496 try:
497 _in_port = fd.get_in_port(flow)
498 assert _in_port is not None
499
Craig Lutgenabd9c842018-11-15 23:58:27 +0000500 _out_port = fd.get_out_port(flow) # may be None
501
Matt Jeannerete6a70332018-07-20 16:11:25 -0400502 if is_downstream(_in_port):
Craig Lutgenabd9c842018-11-15 23:58:27 +0000503 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
504 uni_port = self.uni_port(_out_port)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400505 elif is_upstream(_in_port):
Craig Lutgenabd9c842018-11-15 23:58:27 +0000506 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
507 uni_port = self.uni_port(_in_port)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400508 else:
509 raise Exception('port should be 1 or 2 by our convention')
510
Craig Lutgenabd9c842018-11-15 23:58:27 +0000511 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
Matt Jeannerete6a70332018-07-20 16:11:25 -0400512
513 for field in fd.get_ofb_fields(flow):
514 if field.type == fd.ETH_TYPE:
515 _type = field.eth_type
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400516 self.log.debug('field-type-eth-type',
Girish Gowdruab836e92018-10-25 01:17:57 -0700517 eth_type=_type)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400518
519 elif field.type == fd.IP_PROTO:
520 _proto = field.ip_proto
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400521 self.log.debug('field-type-ip-proto',
Girish Gowdruab836e92018-10-25 01:17:57 -0700522 ip_proto=_proto)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400523
524 elif field.type == fd.IN_PORT:
525 _port = field.port
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400526 self.log.debug('field-type-in-port',
Girish Gowdruab836e92018-10-25 01:17:57 -0700527 in_port=_port)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400528
529 elif field.type == fd.VLAN_VID:
530 _vlan_vid = field.vlan_vid & 0xfff
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400531 self.log.debug('field-type-vlan-vid',
Girish Gowdruab836e92018-10-25 01:17:57 -0700532 vlan=_vlan_vid)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400533
534 elif field.type == fd.VLAN_PCP:
535 _vlan_pcp = field.vlan_pcp
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400536 self.log.debug('field-type-vlan-pcp',
Girish Gowdruab836e92018-10-25 01:17:57 -0700537 pcp=_vlan_pcp)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400538
539 elif field.type == fd.UDP_DST:
540 _udp_dst = field.udp_dst
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400541 self.log.debug('field-type-udp-dst',
Girish Gowdruab836e92018-10-25 01:17:57 -0700542 udp_dst=_udp_dst)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400543
544 elif field.type == fd.UDP_SRC:
545 _udp_src = field.udp_src
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400546 self.log.debug('field-type-udp-src',
Girish Gowdruab836e92018-10-25 01:17:57 -0700547 udp_src=_udp_src)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400548
549 elif field.type == fd.IPV4_DST:
550 _ipv4_dst = field.ipv4_dst
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400551 self.log.debug('field-type-ipv4-dst',
Girish Gowdruab836e92018-10-25 01:17:57 -0700552 ipv4_dst=_ipv4_dst)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400553
554 elif field.type == fd.IPV4_SRC:
555 _ipv4_src = field.ipv4_src
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400556 self.log.debug('field-type-ipv4-src',
Girish Gowdruab836e92018-10-25 01:17:57 -0700557 ipv4_dst=_ipv4_src)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400558
559 elif field.type == fd.METADATA:
560 _metadata = field.table_metadata
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400561 self.log.debug('field-type-metadata',
Girish Gowdruab836e92018-10-25 01:17:57 -0700562 metadata=_metadata)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400563
564 else:
565 raise NotImplementedError('field.type={}'.format(
566 field.type))
567
568 for action in fd.get_actions(flow):
569
570 if action.type == fd.OUTPUT:
571 _output = action.output.port
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400572 self.log.debug('action-type-output',
Girish Gowdruab836e92018-10-25 01:17:57 -0700573 output=_output, in_port=_in_port)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400574
575 elif action.type == fd.POP_VLAN:
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400576 self.log.debug('action-type-pop-vlan',
Girish Gowdruab836e92018-10-25 01:17:57 -0700577 in_port=_in_port)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400578
579 elif action.type == fd.PUSH_VLAN:
580 _push_tpid = action.push.ethertype
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400581 self.log.debug('action-type-push-vlan',
Girish Gowdruab836e92018-10-25 01:17:57 -0700582 push_tpid=_push_tpid, in_port=_in_port)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400583 if action.push.ethertype != 0x8100:
584 self.log.error('unhandled-tpid',
585 ethertype=action.push.ethertype)
586
587 elif action.type == fd.SET_FIELD:
588 _field = action.set_field.field.ofb_field
589 assert (action.set_field.field.oxm_class ==
590 OFPXMC_OPENFLOW_BASIC)
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400591 self.log.debug('action-type-set-field',
Girish Gowdruab836e92018-10-25 01:17:57 -0700592 field=_field, in_port=_in_port)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400593 if _field.type == fd.VLAN_VID:
594 _set_vlan_vid = _field.vlan_vid & 0xfff
Zack Williams8d811fd2018-11-22 09:23:23 -0700595 self.log.debug('set-field-type-vlan-vid',
596 vlan_vid=_set_vlan_vid)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400597 else:
598 self.log.error('unsupported-action-set-field-type',
599 field_type=_field.type)
600 else:
601 self.log.error('unsupported-action-type',
Girish Gowdruab836e92018-10-25 01:17:57 -0700602 action_type=action.type, in_port=_in_port)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400603
Matt Jeanneretf4448402018-09-25 12:51:19 -0400604 # TODO: We only set vlan omci flows. Handle omci matching ethertypes at some point in another task
Nicolas Palpacuer6093c1a2018-08-27 15:03:24 -0400605 if _type is not None:
Matt Jeanneretf4448402018-09-25 12:51:19 -0400606 self.log.warn('ignoring-flow-with-ethType', ethType=_type)
607 elif _set_vlan_vid is None or _set_vlan_vid == 0:
Thiyagarajan Subramani3b62d6c2019-02-15 08:48:01 -0800608 self.log.warn('ignoring-flow-that-does-not-set-vlanid')
Matt Jeanneretf4448402018-09-25 12:51:19 -0400609 else:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000610 self.log.warn('set-vlanid', uni_id=uni_port.port_number, set_vlan_vid=_set_vlan_vid)
Thiyagarajan Subramani3b62d6c2019-02-15 08:48:01 -0800611 self._do_vlan_filter_task(device, flow.cookie, add_tag=True,
612 uni_port=uni_port, _set_vlan_vid=_set_vlan_vid)
Saurav Das6c539962018-09-13 14:17:41 -0700613
Matt Jeannerete6a70332018-07-20 16:11:25 -0400614 except Exception as e:
615 self.log.exception('failed-to-install-flow', e=e, flow=flow)
616
Thiyagarajan Subramani3b62d6c2019-02-15 08:48:01 -0800617 def add_onu_flows(self, device, flows):
618 self.log.debug('function-entry', device=device, flows=flows)
Matt Jeanneret1c90e502018-11-12 17:38:42 -0500619
Thiyagarajan Subramani3b62d6c2019-02-15 08:48:01 -0800620 #
621 # We need to proxy through the OLT to get to the ONU
622 # Configuration from here should be using OMCI
623 #
624 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
625
626 # no point in pushing omci flows if the device isnt reachable
627 if device.connect_status != ConnectStatus.REACHABLE or \
628 device.admin_state != AdminState.ENABLED:
629 self.log.warn("device-disabled-or-offline-skipping-flow-update",
630 admin=device.admin_state, connect=device.connect_status)
631 return
632
633 for flow in flows:
634 # if incoming flow contains cookie, then add to ONU
635 if flow.cookie:
636 _type = None
637 _port = None
638 _vlan_vid = None
639 _udp_dst = None
640 _udp_src = None
641 _ipv4_dst = None
642 _ipv4_src = None
643 _metadata = None
644 _output = None
645 _push_tpid = None
646 _field = None
647 _set_vlan_vid = None
648 self.log.debug("add-flow", device_id=device.id, flow=flow)
649
650 def is_downstream(port):
651 return port == self._pon_port_number
652
653 def is_upstream(port):
654 return not is_downstream(port)
655
656 try:
657 _in_port = fd.get_in_port(flow)
658 assert _in_port is not None
659
660 _out_port = fd.get_out_port(flow) # may be None
661
662 if is_downstream(_in_port):
663 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
664 uni_port = self.uni_port(_out_port)
665 elif is_upstream(_in_port):
666 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
667 uni_port = self.uni_port(_in_port)
668 else:
669 raise Exception('port should be 1 or 2 by our convention')
670
671 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
672
673 for field in fd.get_ofb_fields(flow):
674 if field.type == fd.ETH_TYPE:
675 _type = field.eth_type
676 self.log.debug('field-type-eth-type',
677 eth_type=_type)
678
679 elif field.type == fd.IP_PROTO:
680 _proto = field.ip_proto
681 self.log.debug('field-type-ip-proto',
682 ip_proto=_proto)
683
684 elif field.type == fd.IN_PORT:
685 _port = field.port
686 self.log.debug('field-type-in-port',
687 in_port=_port)
688
689 elif field.type == fd.VLAN_VID:
690 _vlan_vid = field.vlan_vid & 0xfff
691 self.log.debug('field-type-vlan-vid',
692 vlan=_vlan_vid)
693
694 elif field.type == fd.VLAN_PCP:
695 _vlan_pcp = field.vlan_pcp
696 self.log.debug('field-type-vlan-pcp',
697 pcp=_vlan_pcp)
698
699 elif field.type == fd.UDP_DST:
700 _udp_dst = field.udp_dst
701 self.log.debug('field-type-udp-dst',
702 udp_dst=_udp_dst)
703
704 elif field.type == fd.UDP_SRC:
705 _udp_src = field.udp_src
706 self.log.debug('field-type-udp-src',
707 udp_src=_udp_src)
708
709 elif field.type == fd.IPV4_DST:
710 _ipv4_dst = field.ipv4_dst
711 self.log.debug('field-type-ipv4-dst',
712 ipv4_dst=_ipv4_dst)
713
714 elif field.type == fd.IPV4_SRC:
715 _ipv4_src = field.ipv4_src
716 self.log.debug('field-type-ipv4-src',
717 ipv4_dst=_ipv4_src)
718
719 elif field.type == fd.METADATA:
720 _metadata = field.table_metadata
721 self.log.debug('field-type-metadata',
722 metadata=_metadata)
723
724 else:
725 raise NotImplementedError('field.type={}'.format(
726 field.type))
727
728 for action in fd.get_actions(flow):
729
730 if action.type == fd.OUTPUT:
731 _output = action.output.port
732 self.log.debug('action-type-output',
733 output=_output, in_port=_in_port)
734
735 elif action.type == fd.POP_VLAN:
736 self.log.debug('action-type-pop-vlan',
737 in_port=_in_port)
738
739 elif action.type == fd.PUSH_VLAN:
740 _push_tpid = action.push.ethertype
741 self.log.debug('action-type-push-vlan',
742 push_tpid=_push_tpid, in_port=_in_port)
743 if action.push.ethertype != 0x8100:
744 self.log.error('unhandled-tpid',
745 ethertype=action.push.ethertype)
746
747 elif action.type == fd.SET_FIELD:
748 _field = action.set_field.field.ofb_field
749 assert (action.set_field.field.oxm_class ==
750 OFPXMC_OPENFLOW_BASIC)
751 self.log.debug('action-type-set-field',
752 field=_field, in_port=_in_port)
753 if _field.type == fd.VLAN_VID:
754 _set_vlan_vid = _field.vlan_vid & 0xfff
755 self.log.debug('set-field-type-vlan-vid',
756 vlan_vid=_set_vlan_vid)
757 else:
758 self.log.error('unsupported-action-set-field-type',
759 field_type=_field.type)
760 else:
761 self.log.error('unsupported-action-type',
762 action_type=action.type, in_port=_in_port)
763
764 # TODO: We only set vlan omci flows. Handle omci matching ethertypes at some point in another task
765 if _type is not None:
766 self.log.warn('ignoring-flow-with-ethType', ethType=_type)
767 elif _set_vlan_vid is None or _set_vlan_vid == 0:
768 self.log.warn('ignoring-flow-that-does-not-set-vlanid')
769 else:
770 self.log.warn('set-vlanid', uni_id=uni_port.port_number, set_vlan_vid=_set_vlan_vid)
771 self._do_vlan_filter_task(device, flow.cookie, add_tag=True,
772 uni_port=uni_port, _set_vlan_vid=_set_vlan_vid)
773
774 except Exception as e:
775 self.log.exception('failed-to-install-flow', e=e, flow=flow)
776
777 def remove_onu_flows(self, device, flows):
778 self.log.debug('function-entry', device=device, flows=flows)
779
780 # no point in removing omci flows if the device isnt reachable
781 if device.connect_status != ConnectStatus.REACHABLE or \
782 device.admin_state != AdminState.ENABLED:
783 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
784 admin=device.admin_state, connect=device.connect_status)
785 return
786
787 for flow in flows:
788 # if incoming flow contains cookie, then remove from ONU
789 if flow.cookie:
790 self.log.debug("remove-flow", device_id=device.id, flow=flow)
791
792 def is_downstream(port):
793 return port == self._pon_port_number
794
795 def is_upstream(port):
796 return not is_downstream(port)
797
798 try:
799 _in_port = fd.get_in_port(flow)
800 assert _in_port is not None
801
802 _out_port = fd.get_out_port(flow) # may be None
803
804 if is_downstream(_in_port):
805 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
806 uni_port = self.uni_port(_out_port)
807 elif is_upstream(_in_port):
808 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
809 uni_port = self.uni_port(_in_port)
810 else:
811 raise Exception('port should be 1 or 2 by our convention')
812
813 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
814
815 # Deleting flow from ONU.
816 self._do_vlan_filter_task(device, flow.cookie, add_tag=False, uni_port=uni_port)
817 except Exception as e:
818 self.log.exception('failed-to-remove-flow', e=e)
819
820 def _do_vlan_filter_task(self, device, flow_cookie, add_tag=True, uni_port=None, _set_vlan_vid=None):
821 task_name = 'removing-vlan-tag'
822 if add_tag:
823 assert uni_port is not None
824 task_name = 'setting-vlan-tag'
Craig Lutgenabd9c842018-11-15 23:58:27 +0000825
Matt Jeanneretf4448402018-09-25 12:51:19 -0400826 def success(_results):
Thiyagarajan Subramani3b62d6c2019-02-15 08:48:01 -0800827 if add_tag:
828 self.log.info('vlan-tagging-success', _results=_results)
829 device.reason = 'omci-flows-pushed'
830 self.log.debug('Flow-addition-success', cookie=flow_cookie)
831 else:
832 self.log.info('vlan-untagging-success', _results=_results)
833 device.reason = 'omci-flows-deleted'
834 self.log.debug('Flow-removal-success', cookie=flow_cookie)
835
Matt Jeanneretf4448402018-09-25 12:51:19 -0400836 self._vlan_filter_task = None
837
838 def failure(_reason):
Thiyagarajan Subramani3b62d6c2019-02-15 08:48:01 -0800839 if add_tag:
840 self.log.warn('vlan-tagging-failure', _reason=_reason)
841 device.reason = 'omci-flows-addition-failed-retrying'
842 self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT,
843 self._do_vlan_filter_task, device, flow_cookie,
844 add_tag=True, uni_port=uni_port,
845 _set_vlan_vid=_set_vlan_vid)
846 else:
847 self.log.warn('vlan-untagging-failure', _reason=_reason)
848 device.reason = 'omci-flows-deletion-failed-retrying'
849 self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT,
850 self._do_vlan_filter_task, device, flow_cookie,
851 add_tag=False)
Girish Gowdruab836e92018-10-25 01:17:57 -0700852
Thiyagarajan Subramani3b62d6c2019-02-15 08:48:01 -0800853 self.log.info(task_name)
854 self._vlan_filter_task = BrcmVlanFilterTask(self.omci_agent, self.device_id, uni_port, _set_vlan_vid,
855 add_tag=add_tag)
Matt Jeanneretf4448402018-09-25 12:51:19 -0400856 self._deferred = self._onu_omci_device.task_runner.queue_task(self._vlan_filter_task)
857 self._deferred.addCallbacks(success, failure)
858
Matt Jeannerete6a70332018-07-20 16:11:25 -0400859 def get_tx_id(self):
860 self.log.debug('function-entry')
861 self.tx_id += 1
862 return self.tx_id
863
Matt Jeanneret04ba4fd2018-08-16 15:32:21 -0400864 # TODO: Actually conform to or create a proper interface.
865 # this and the other functions called from the olt arent very clear.
Matt Jeanneret54c82662018-08-23 11:21:19 -0400866 # Called each time there is an onu "up" indication from the olt handler
Matt Jeannerete6a70332018-07-20 16:11:25 -0400867 def create_interface(self, data):
868 self.log.debug('function-entry', data=data)
869 self._onu_indication = data
870
Matt Jeanneret94f8d292018-08-31 12:49:27 -0400871 onu_device = self.adapter_agent.get_device(self.device_id)
872
Matt Jeanneret6da55792018-08-08 16:44:18 -0400873 self.log.debug('starting-openomci-statemachine')
874 self._subscribe_to_events()
875 reactor.callLater(1, self._onu_omci_device.start)
Matt Jeanneret94f8d292018-08-31 12:49:27 -0400876 onu_device.reason = "starting-openomci"
877 self.adapter_agent.update_device(onu_device)
Scott Bakerc474bb92018-10-12 16:19:18 -0700878 self._heartbeat.enabled = True
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400879
Matt Jeanneret54c82662018-08-23 11:21:19 -0400880 # Currently called each time there is an onu "down" indication from the olt handler
881 # TODO: possibly other reasons to "update" from the olt?
Matt Jeannerete6a70332018-07-20 16:11:25 -0400882 def update_interface(self, data):
883 self.log.debug('function-entry', data=data)
Nicolas Palpacuer08cc8182018-08-22 10:22:19 -0400884 oper_state = data.get('oper_state', None)
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400885
886 onu_device = self.adapter_agent.get_device(self.device_id)
887
Nicolas Palpacuer08cc8182018-08-22 10:22:19 -0400888 if oper_state == 'down':
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400889 self.log.debug('stopping-openomci-statemachine')
Matt Jeanneret6da55792018-08-08 16:44:18 -0400890 reactor.callLater(0, self._onu_omci_device.stop)
Girish Gowdruab836e92018-10-25 01:17:57 -0700891
892 # Let TP download happen again
Girish Gowdrub761bc12018-11-29 02:22:18 -0800893 for uni_id in self._tp_service_specific_task:
894 self._tp_service_specific_task[uni_id].clear()
895 for uni_id in self._tech_profile_download_done:
896 self._tech_profile_download_done[uni_id].clear()
Girish Gowdruab836e92018-10-25 01:17:57 -0700897
Matt Jeanneret6da55792018-08-08 16:44:18 -0400898 self.disable_ports(onu_device)
Matt Jeanneret94f8d292018-08-31 12:49:27 -0400899 onu_device.reason = "stopping-openomci"
Matt Jeanneret6da55792018-08-08 16:44:18 -0400900 onu_device.connect_status = ConnectStatus.UNREACHABLE
901 onu_device.oper_status = OperStatus.DISCOVERED
902 self.adapter_agent.update_device(onu_device)
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400903 else:
904 self.log.debug('not-changing-openomci-statemachine')
Matt Jeannerete6a70332018-07-20 16:11:25 -0400905
Matt Jeanneret54c82662018-08-23 11:21:19 -0400906 # Not currently called by olt or anything else
Matt Jeannerete6a70332018-07-20 16:11:25 -0400907 def remove_interface(self, data):
908 self.log.debug('function-entry', data=data)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400909
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400910 onu_device = self.adapter_agent.get_device(self.device_id)
911
912 self.log.debug('stopping-openomci-statemachine')
913 reactor.callLater(0, self._onu_omci_device.stop)
Girish Gowdruab836e92018-10-25 01:17:57 -0700914
915 # Let TP download happen again
Girish Gowdrub761bc12018-11-29 02:22:18 -0800916 for uni_id in self._tp_service_specific_task:
917 self._tp_service_specific_task[uni_id].clear()
918 for uni_id in self._tech_profile_download_done:
919 self._tech_profile_download_done[uni_id].clear()
Girish Gowdruab836e92018-10-25 01:17:57 -0700920
Matt Jeanneret6da55792018-08-08 16:44:18 -0400921 self.disable_ports(onu_device)
Matt Jeanneret94f8d292018-08-31 12:49:27 -0400922 onu_device.reason = "stopping-openomci"
923 self.adapter_agent.update_device(onu_device)
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400924
925 # TODO: im sure there is more to do here
926
Matt Jeanneret54c82662018-08-23 11:21:19 -0400927 # Not currently called. Would be called presumably from the olt handler
Matt Jeannerete6a70332018-07-20 16:11:25 -0400928 def remove_gemport(self, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400929 self.log.debug('remove-gemport', data=data)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400930 gem_port = GemportsConfigData()
931 gem_port.CopyFrom(data)
932 device = self.adapter_agent.get_device(self.device_id)
933 if device.connect_status != ConnectStatus.REACHABLE:
934 self.log.error('device-unreachable')
Matt Jeanneret1c90e502018-11-12 17:38:42 -0500935 return
Matt Jeannerete6a70332018-07-20 16:11:25 -0400936
Matt Jeanneret54c82662018-08-23 11:21:19 -0400937 # Not currently called. Would be called presumably from the olt handler
Matt Jeannerete6a70332018-07-20 16:11:25 -0400938 def remove_tcont(self, tcont_data, traffic_descriptor_data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400939 self.log.debug('remove-tcont', tcont_data=tcont_data, traffic_descriptor_data=traffic_descriptor_data)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400940 device = self.adapter_agent.get_device(self.device_id)
941 if device.connect_status != ConnectStatus.REACHABLE:
942 self.log.error('device-unreachable')
Matt Jeanneret1c90e502018-11-12 17:38:42 -0500943 return
Matt Jeannerete6a70332018-07-20 16:11:25 -0400944
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400945 # TODO: Create some omci task that encompases this what intended
Matt Jeannerete6a70332018-07-20 16:11:25 -0400946
Matt Jeanneret54c82662018-08-23 11:21:19 -0400947 # Not currently called. Would be called presumably from the olt handler
Matt Jeannerete6a70332018-07-20 16:11:25 -0400948 def create_multicast_gemport(self, data):
949 self.log.debug('function-entry', data=data)
950
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400951 # TODO: create objects and populate for later omci calls
Matt Jeannerete6a70332018-07-20 16:11:25 -0400952
Matt Jeannerete6a70332018-07-20 16:11:25 -0400953 def disable(self, device):
954 self.log.debug('function-entry', device=device)
955 try:
Matt Jeanneret6da55792018-08-08 16:44:18 -0400956 self.log.info('sending-uni-lock-towards-device', device=device)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400957
Matt Jeanneret6da55792018-08-08 16:44:18 -0400958 def stop_anyway(reason):
959 # proceed with disable regardless if we could reach the onu. for example onu is unplugged
960 self.log.debug('stopping-openomci-statemachine')
961 reactor.callLater(0, self._onu_omci_device.stop)
Girish Gowdruab836e92018-10-25 01:17:57 -0700962
963 # Let TP download happen again
Girish Gowdrub761bc12018-11-29 02:22:18 -0800964 for uni_id in self._tp_service_specific_task:
965 self._tp_service_specific_task[uni_id].clear()
966 for uni_id in self._tech_profile_download_done:
967 self._tech_profile_download_done[uni_id].clear()
Girish Gowdruab836e92018-10-25 01:17:57 -0700968
Matt Jeanneret6da55792018-08-08 16:44:18 -0400969 self.disable_ports(device)
970 device.oper_status = OperStatus.UNKNOWN
Matt Jeanneret94f8d292018-08-31 12:49:27 -0400971 device.reason = "omci-admin-lock"
Matt Jeanneret6da55792018-08-08 16:44:18 -0400972 self.adapter_agent.update_device(device)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400973
Matt Jeanneret6da55792018-08-08 16:44:18 -0400974 # lock all the unis
975 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=True)
976 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
977 self._deferred.addCallbacks(stop_anyway, stop_anyway)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400978 except Exception as e:
979 log.exception('exception-in-onu-disable', exception=e)
980
Matt Jeannerete6a70332018-07-20 16:11:25 -0400981 def reenable(self, device):
982 self.log.debug('function-entry', device=device)
983 try:
Matt Jeannerete6a70332018-07-20 16:11:25 -0400984 # Start up OpenOMCI state machines for this device
Matt Jeanneret6da55792018-08-08 16:44:18 -0400985 # this will ultimately resync mib and unlock unis on successful redownloading the mib
986 self.log.debug('restarting-openomci-statemachine')
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400987 self._subscribe_to_events()
Matt Jeanneret94f8d292018-08-31 12:49:27 -0400988 device.reason = "restarting-openomci"
989 self.adapter_agent.update_device(device)
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400990 reactor.callLater(1, self._onu_omci_device.start)
Scott Bakerc474bb92018-10-12 16:19:18 -0700991 self._heartbeat.enabled = True
Matt Jeannerete6a70332018-07-20 16:11:25 -0400992 except Exception as e:
993 log.exception('exception-in-onu-reenable', exception=e)
994
Matt Jeannerete6a70332018-07-20 16:11:25 -0400995 def reboot(self):
Matt Jeannerete6a70332018-07-20 16:11:25 -0400996 self.log.info('reboot-device')
997 device = self.adapter_agent.get_device(self.device_id)
998 if device.connect_status != ConnectStatus.REACHABLE:
Matt Jeanneret54c82662018-08-23 11:21:19 -0400999 self.log.error("device-unreachable")
Matt Jeanneret1c90e502018-11-12 17:38:42 -05001000 return
Matt Jeannerete6a70332018-07-20 16:11:25 -04001001
Matt Jeanneret6da55792018-08-08 16:44:18 -04001002 def success(_results):
1003 self.log.info('reboot-success', _results=_results)
1004 self.disable_ports(device)
1005 device.connect_status = ConnectStatus.UNREACHABLE
1006 device.oper_status = OperStatus.DISCOVERED
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001007 device.reason = "rebooting"
Matt Jeanneret6da55792018-08-08 16:44:18 -04001008 self.adapter_agent.update_device(device)
Matt Jeannerete6a70332018-07-20 16:11:25 -04001009
Matt Jeanneret6da55792018-08-08 16:44:18 -04001010 def failure(_reason):
1011 self.log.info('reboot-failure', _reason=_reason)
1012
1013 self._deferred = self._onu_omci_device.reboot()
1014 self._deferred.addCallbacks(success, failure)
Matt Jeannerete6a70332018-07-20 16:11:25 -04001015
1016 def disable_ports(self, onu_device):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -04001017 self.log.info('disable-ports', device_id=self.device_id,
Girish Gowdruab836e92018-10-25 01:17:57 -07001018 onu_device=onu_device)
Matt Jeannerete6a70332018-07-20 16:11:25 -04001019
1020 # Disable all ports on that device
1021 self.adapter_agent.disable_all_ports(self.device_id)
1022
1023 parent_device = self.adapter_agent.get_device(onu_device.parent_id)
1024 assert parent_device
1025 logical_device_id = parent_device.parent_id
1026 assert logical_device_id
1027 ports = self.adapter_agent.get_ports(onu_device.id, Port.ETHERNET_UNI)
1028 for port in ports:
1029 port_id = 'uni-{}'.format(port.port_no)
1030 # TODO: move to UniPort
1031 self.update_logical_port(logical_device_id, port_id, OFPPS_LINK_DOWN)
1032
1033 def enable_ports(self, onu_device):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -04001034 self.log.info('enable-ports', device_id=self.device_id, onu_device=onu_device)
Matt Jeannerete6a70332018-07-20 16:11:25 -04001035
1036 # Disable all ports on that device
1037 self.adapter_agent.enable_all_ports(self.device_id)
1038
1039 parent_device = self.adapter_agent.get_device(onu_device.parent_id)
1040 assert parent_device
1041 logical_device_id = parent_device.parent_id
1042 assert logical_device_id
1043 ports = self.adapter_agent.get_ports(onu_device.id, Port.ETHERNET_UNI)
1044 for port in ports:
1045 port_id = 'uni-{}'.format(port.port_no)
1046 # TODO: move to UniPort
1047 self.update_logical_port(logical_device_id, port_id, OFPPS_LIVE)
1048
Matt Jeanneret54c82662018-08-23 11:21:19 -04001049 # Called just before openomci state machine is started. These listen for events from selected state machines,
1050 # most importantly, mib in sync. Which ultimately leads to downloading the mib
Matt Jeannerete6a70332018-07-20 16:11:25 -04001051 def _subscribe_to_events(self):
1052 self.log.debug('function-entry')
1053
1054 # OMCI MIB Database sync status
1055 bus = self._onu_omci_device.event_bus
1056 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1057 OnuDeviceEvents.MibDatabaseSyncEvent)
1058 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1059
1060 # OMCI Capabilities
1061 bus = self._onu_omci_device.event_bus
1062 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1063 OnuDeviceEvents.OmciCapabilitiesEvent)
1064 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1065
Matt Jeanneret54c82662018-08-23 11:21:19 -04001066 # Called when the mib is in sync
Matt Jeannerete6a70332018-07-20 16:11:25 -04001067 def in_sync_handler(self, _topic, msg):
1068 self.log.debug('function-entry', _topic=_topic, msg=msg)
1069 if self._in_sync_subscription is not None:
1070 try:
1071 in_sync = msg[IN_SYNC_KEY]
1072
1073 if in_sync:
1074 # Only call this once
1075 bus = self._onu_omci_device.event_bus
1076 bus.unsubscribe(self._in_sync_subscription)
1077 self._in_sync_subscription = None
1078
1079 # Start up device_info load
1080 self.log.debug('running-mib-sync')
1081 reactor.callLater(0, self._mib_in_sync)
1082
1083 except Exception as e:
1084 self.log.exception('in-sync', e=e)
1085
1086 def capabilties_handler(self, _topic, _msg):
1087 self.log.debug('function-entry', _topic=_topic, msg=_msg)
1088 if self._capabilities_subscription is not None:
1089 self.log.debug('capabilities-handler-done')
1090
Matt Jeanneret54c82662018-08-23 11:21:19 -04001091 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1092 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1093 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeannerete6a70332018-07-20 16:11:25 -04001094 def _mib_in_sync(self):
1095 self.log.debug('function-entry')
Matt Jeannerete6a70332018-07-20 16:11:25 -04001096
Matt Jeanneret12cd5d02018-08-07 15:30:19 -04001097 omci = self._onu_omci_device
1098 in_sync = omci.mib_db_in_sync
1099
Matt Jeanneret6da55792018-08-08 16:44:18 -04001100 device = self.adapter_agent.get_device(self.device_id)
1101 device.reason = 'discovery-mibsync-complete'
1102 self.adapter_agent.update_device(device)
1103
Matt Jeanneret12cd5d02018-08-07 15:30:19 -04001104 if not self._dev_info_loaded:
1105 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
Matt Jeannerete6a70332018-07-20 16:11:25 -04001106
Matt Jeannerete6a70332018-07-20 16:11:25 -04001107 omci_dev = self._onu_omci_device
1108 config = omci_dev.configuration
1109
Matt Jeanneret54c82662018-08-23 11:21:19 -04001110 # TODO: run this sooner somehow. shouldnt have to wait for mib sync to push an initial download
Matt Jeannerete6a70332018-07-20 16:11:25 -04001111 # In Sync, we can register logical ports now. Ideally this could occur on
1112 # the first time we received a successful (no timeout) OMCI Rx response.
1113 try:
Matt Jeannerete6a70332018-07-20 16:11:25 -04001114
Matt Jeanneretf78f6aa2018-11-01 11:20:17 -04001115 # sort the lists so we get consistent port ordering.
1116 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1117 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1118 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1119 veip_list = sorted(config.veip_entities) if config.veip_entities else []
Matt Jeannerete6a70332018-07-20 16:11:25 -04001120
Matt Jeanneretf16726d2018-11-16 11:14:00 -05001121 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001122 device.reason = 'onu-missing-required-elements'
Matt Jeanneretf78f6aa2018-11-01 11:20:17 -04001123 self.log.warn("no-ani-or-unis")
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001124 self.adapter_agent.update_device(device)
1125 raise Exception("onu-missing-required-elements")
1126
Matt Jeanneretf78f6aa2018-11-01 11:20:17 -04001127 # Currently logging the ani, pptp, veip, and uni for information purposes.
1128 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
Matt Jeanneretf16726d2018-11-16 11:14:00 -05001129 # And in some ONU the UNI-G list is incomplete or incorrect...
Matt Jeanneretf78f6aa2018-11-01 11:20:17 -04001130 for entity_id in ani_list:
1131 ani_value = config.ani_g_entities[entity_id]
1132 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1133 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1134 self._total_tcont_count = ani_value.get('total-tcont-count')
1135 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
Matt Jeannerete6a70332018-07-20 16:11:25 -04001136
Matt Jeanneretf78f6aa2018-11-01 11:20:17 -04001137 for entity_id in uni_list:
1138 uni_value = config.uni_g_entities[entity_id]
1139 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
Matt Jeannerete6a70332018-07-20 16:11:25 -04001140
Craig Lutgenabd9c842018-11-15 23:58:27 +00001141 uni_entities = OrderedDict()
Matt Jeanneretf16726d2018-11-16 11:14:00 -05001142 for entity_id in pptp_list:
1143 pptp_value = config.pptp_entities[entity_id]
1144 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
Craig Lutgenabd9c842018-11-15 23:58:27 +00001145 uni_entities[entity_id] = UniType.PPTP
Matt Jeanneretf16726d2018-11-16 11:14:00 -05001146
1147 for entity_id in veip_list:
1148 veip_value = config.veip_entities[entity_id]
1149 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
Craig Lutgenabd9c842018-11-15 23:58:27 +00001150 uni_entities[entity_id] = UniType.VEIP
1151
1152 uni_id = 0
1153 for entity_id, uni_type in uni_entities.iteritems():
1154 try:
1155 self._add_uni_port(entity_id, uni_id, uni_type)
1156 uni_id += 1
1157 except AssertionError as e:
1158 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1159
1160 multi_uni = len(self._unis) > 1
1161 for uni_port in self._unis.itervalues():
1162 uni_port.add_logical_port(uni_port.port_number, multi_uni)
1163
1164 self.adapter_agent.update_device(device)
Matt Jeanneretf78f6aa2018-11-01 11:20:17 -04001165
Matt Jeannerete6a70332018-07-20 16:11:25 -04001166 self._qos_flexibility = config.qos_configuration_flexibility or 0
1167 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
Matt Jeannerete6a70332018-07-20 16:11:25 -04001168
Matt Jeanneretf78f6aa2018-11-01 11:20:17 -04001169 if self._unis:
1170 self._dev_info_loaded = True
1171 else:
1172 device.reason = 'no-usable-unis'
1173 self.adapter_agent.update_device(device)
1174 self.log.warn("no-usable-unis")
1175 raise Exception("no-usable-unis")
Matt Jeannerete6a70332018-07-20 16:11:25 -04001176
Matt Jeannerete6a70332018-07-20 16:11:25 -04001177 except Exception as e:
1178 self.log.exception('device-info-load', e=e)
1179 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1180
Matt Jeanneret12cd5d02018-08-07 15:30:19 -04001181 else:
1182 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1183
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001184 if self._dev_info_loaded:
1185 if device.admin_state == AdminState.ENABLED:
1186 def success(_results):
1187 self.log.info('mib-download-success', _results=_results)
1188 device = self.adapter_agent.get_device(self.device_id)
1189 device.reason = 'initial-mib-downloaded'
1190 device.oper_status = OperStatus.ACTIVE
1191 device.connect_status = ConnectStatus.REACHABLE
1192 self.enable_ports(device)
1193 self.adapter_agent.update_device(device)
1194 self._mib_download_task = None
Matt Jeanneret12cd5d02018-08-07 15:30:19 -04001195
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001196 def failure(_reason):
Matt Jeanneretf4448402018-09-25 12:51:19 -04001197 self.log.warn('mib-download-failure-retrying', _reason=_reason)
1198 device.reason = 'initial-mib-download-failure-retrying'
1199 self.adapter_agent.update_device(device)
1200 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001201
1202 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1203 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1204 self.log.info('downloading-initial-mib-configuration')
Matt Jeanneret04ba4fd2018-08-16 15:32:21 -04001205 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1206 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001207 self._deferred.addCallbacks(success, failure)
1208 else:
1209 self.log.info('admin-down-disabling')
1210 self.disable(device)
Matt Jeanneret04ba4fd2018-08-16 15:32:21 -04001211 else:
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001212 self.log.info('device-info-not-loaded-skipping-mib-download')
1213
1214
Craig Lutgenabd9c842018-11-15 23:58:27 +00001215 def _add_uni_port(self, entity_id, uni_id, uni_type=UniType.PPTP):
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001216 self.log.debug('function-entry')
1217
1218 device = self.adapter_agent.get_device(self.device_id)
1219 parent_device = self.adapter_agent.get_device(device.parent_id)
1220
1221 parent_adapter_agent = registry('adapter_loader').get_agent(parent_device.adapter)
1222 if parent_adapter_agent is None:
Matt Jeanneretf78f6aa2018-11-01 11:20:17 -04001223 self.log.error('parent-adapter-could-not-be-retrieved')
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001224
1225 # TODO: This knowledge is locked away in openolt. and it assumes one onu equals one uni...
Shad Ansaricd20a6d2018-10-02 14:36:33 +00001226 parent_device = self.adapter_agent.get_device(device.parent_id)
1227 parent_adapter = parent_adapter_agent.adapter.devices[parent_device.id]
Craig Lutgenabd9c842018-11-15 23:58:27 +00001228 uni_no = parent_adapter.platform.mk_uni_port_num(
1229 self._onu_indication.intf_id, self._onu_indication.onu_id, uni_id)
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001230
1231 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001232 uni_name = "uni-{}".format(uni_no)
1233
Craig Lutgenabd9c842018-11-15 23:58:27 +00001234 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001235
Craig Lutgenabd9c842018-11-15 23:58:27 +00001236 self.log.debug('uni-port-inputs', uni_no=uni_no, uni_id=uni_id, uni_name=uni_name, uni_type=uni_type,
Matt Jeanneretf78f6aa2018-11-01 11:20:17 -04001237 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num)
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001238
Craig Lutgenabd9c842018-11-15 23:58:27 +00001239 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001240 uni_port.entity_id = entity_id
1241 uni_port.enabled = True
1242 uni_port.mac_bridge_port_num = mac_bridge_port_num
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001243
1244 self.log.debug("created-uni-port", uni=uni_port)
1245
1246 self.adapter_agent.add_port(device.id, uni_port.get_port())
1247 parent_adapter_agent.add_port(device.parent_id, uni_port.get_port())
1248
1249 self._unis[uni_port.port_number] = uni_port
1250
Chip Boling3186eb52018-11-02 14:28:01 -05001251 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
1252 uni_ports=self._unis.values())
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001253 # TODO: this should be in the PonPortclass
1254 pon_port = self._pon.get_port()
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001255
Craig Lutgenabd9c842018-11-15 23:58:27 +00001256 # Delete reference to my own UNI as peer from parent.
1257 # TODO why is this here, add_port_reference_to_parent already prunes duplicates
1258 me_as_peer = Port.PeerPort(device_id=device.parent_id, port_no=uni_port.port_number)
1259 partial_pon_port = Port(port_no=pon_port.port_no, label=pon_port.label,
1260 type=pon_port.type, admin_state=pon_port.admin_state,
1261 oper_status=pon_port.oper_status,
1262 peers=[me_as_peer]) # only list myself as a peer to avoid deleting all other UNIs from parent
1263 self.adapter_agent.delete_port_reference_from_parent(self.device_id, partial_pon_port)
1264
1265 pon_port.peers.extend([me_as_peer])
Matt Jeanneret94f8d292018-08-31 12:49:27 -04001266
1267 self._pon._port = pon_port
1268
1269 self.adapter_agent.add_port_reference_to_parent(self.device_id,
Girish Gowdrub761bc12018-11-29 02:22:18 -08001270 pon_port)