blob: 0d6ec4d81b3da9299fa2fb5c0d42ae82f68b2b01 [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 Jeanneret2e3cb8d2019-11-16 09:22:41 -050021from __future__ import absolute_import
22import six
Devmalya Paulffc89df2019-07-31 17:43:13 -040023import arrow
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050024import structlog
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050025import json
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050026import random
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050027
28from collections import OrderedDict
29
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050030from twisted.internet import reactor
31from twisted.internet.defer import DeferredQueue, inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050032
33from heartbeat import HeartBeat
Devmalya Paulffc89df2019-07-31 17:43:13 -040034from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent
35from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
36from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
37from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050038
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050039import pyvoltha.common.openflow.utils as fd
40from pyvoltha.common.utils.registry import registry
Matteo Scandolod8d73172019-11-26 12:15:15 -070041from pyvoltha.adapters.common.frameio.frameio import hexify
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050042from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050043from pyvoltha.common.config.config_backend import ConsulStore
44from pyvoltha.common.config.config_backend import EtcdStore
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050045from voltha_protos.logical_device_pb2 import LogicalPort
William Kurkian8235c1e2019-03-05 12:58:28 -050046from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretf4113222019-08-14 19:44:34 -040047from voltha_protos.device_pb2 import Port
48from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE,OFPPS_LINK_DOWN,\
49 OFPPF_FIBER, OFPPF_1GB_FD
Matt Jeanneret3bfebff2019-04-12 18:25:03 -040050from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
Girish Gowdrae933cd32019-11-21 21:04:41 +053051 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
52 InterAdapterDeleteTcontMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050053from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050054from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
55from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050056 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050057from omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdrae933cd32019-11-21 21:04:41 +053058from omci.brcm_tp_setup_task import BrcmTpSetupTask
59from omci.brcm_tp_delete_task import BrcmTpDeleteTask
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050060from omci.brcm_uni_lock_task import BrcmUniLockTask
61from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050062from onu_gem_port import OnuGemPort
63from onu_tcont import OnuTCont
64from pon_port import PonPort
65from uni_port import UniPort, UniType
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050066from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053067from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
68from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050069from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050070
71OP = EntityOperations
72RC = ReasonCodes
73
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050074_STARTUP_RETRY_WAIT = 10
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050075
76
77class BrcmOpenomciOnuHandler(object):
78
79 def __init__(self, adapter, device_id):
80 self.log = structlog.get_logger(device_id=device_id)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050081 self.log.debug('starting-handler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050082 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050083 self.core_proxy = adapter.core_proxy
84 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050085 self.parent_id = None
86 self.device_id = device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050087 self.proxy_address = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050088 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040089 self.events = None
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050090 self._pm_metrics = None
91 self._pm_metrics_started = False
92 self._test_request = None
93 self._test_request_started = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050094 self._omcc_version = OMCCVersion.Unknown
95 self._total_tcont_count = 0 # From ANI-G ME
96 self._qos_flexibility = 0 # From ONT2_G ME
97
98 self._onu_indication = None
99 self._unis = dict() # Port # -> UniPort
100
101 self._pon = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500102 self._pon_port_number = 100
103 self.logical_device_id = None
104
105 self._heartbeat = HeartBeat.create(self, device_id)
106
107 # Set up OpenOMCI environment
108 self._onu_omci_device = None
109 self._dev_info_loaded = False
110 self._deferred = None
111
112 self._in_sync_subscription = None
Matt Jeanneretf4113222019-08-14 19:44:34 -0400113 self._port_state_subscription = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500114 self._connectivity_subscription = None
115 self._capabilities_subscription = None
116
117 self.mac_bridge_service_profile_entity_id = 0x201
118 self.gal_enet_profile_entity_id = 0x1
119
120 self._tp_service_specific_task = dict()
121 self._tech_profile_download_done = dict()
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400122 # Stores information related to queued vlan filter tasks
123 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
124
125 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500126
127 # Initialize KV store client
128 self.args = registry('main').get_args()
129 if self.args.backend == 'etcd':
130 host, port = self.args.etcd.split(':', 1)
131 self.kv_client = EtcdStore(host, port,
132 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
133 elif self.args.backend == 'consul':
134 host, port = self.args.consul.split(':', 1)
135 self.kv_client = ConsulStore(host, port,
136 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
137 else:
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500138 self.log.error('invalid-backend')
139 raise Exception("invalid-backend-for-kv-store")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500140
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500141 @property
142 def enabled(self):
143 return self._enabled
144
145 @enabled.setter
146 def enabled(self, value):
147 if self._enabled != value:
148 self._enabled = value
149
150 @property
151 def omci_agent(self):
152 return self.adapter.omci_agent
153
154 @property
155 def omci_cc(self):
156 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
157
158 @property
159 def heartbeat(self):
160 return self._heartbeat
161
162 @property
163 def uni_ports(self):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500164 return list(self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500165
166 def uni_port(self, port_no_or_name):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500167 if isinstance(port_no_or_name, six.string_types):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500168 return next((uni for uni in self.uni_ports
169 if uni.name == port_no_or_name), None)
170
171 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
172 return next((uni for uni in self.uni_ports
Girish Gowdrae933cd32019-11-21 21:04:41 +0530173 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500174
175 @property
176 def pon_port(self):
177 return self._pon
178
Girish Gowdraa73ee452019-12-20 18:52:17 +0530179 @property
180 def onu_omci_device(self):
181 return self._onu_omci_device
182
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500183 def receive_message(self, msg):
184 if self.omci_cc is not None:
185 self.omci_cc.receive_message(msg)
186
Matt Jeanneretc083f462019-03-11 15:02:01 -0400187 def get_ofp_port_info(self, device, port_no):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500188 self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400189 cap = OFPPF_1GB_FD | OFPPF_FIBER
190
Girish Gowdrae933cd32019-11-21 21:04:41 +0530191 hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
192 ((device.parent_port_no >> 8 & 0xff),
193 device.parent_port_no & 0xff,
194 (port_no >> 16) & 0xff,
195 (port_no >> 8) & 0xff,
196 port_no & 0xff))
Matt Jeanneretc083f462019-03-11 15:02:01 -0400197
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400198 uni_port = self.uni_port(int(port_no))
199 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500200 self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port)
Matt Jeanneretf4113222019-08-14 19:44:34 -0400201
202 ofstate = OFPPS_LINK_DOWN
203 if uni_port.operstatus is OperStatus.ACTIVE:
204 ofstate = OFPPS_LIVE
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400205
Matt Jeanneretc083f462019-03-11 15:02:01 -0400206 return PortCapability(
207 port=LogicalPort(
208 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400209 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400210 hw_addr=hw_addr,
211 config=0,
Matt Jeanneretf4113222019-08-14 19:44:34 -0400212 state=ofstate,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400213 curr=cap,
214 advertised=cap,
215 peer=cap,
216 curr_speed=OFPPF_1GB_FD,
217 max_speed=OFPPF_1GB_FD
218 ),
219 device_id=device.id,
220 device_port_no=port_no
221 )
222 )
223
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500224 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500225 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500226 def activate(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700227 self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500228
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500229 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500230 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500231 assert device.proxy_address.device_id
232
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500233 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500234 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500235 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500236 if self.enabled is not True:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700237 self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500238 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500239 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500240 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500241 device.reason = 'activating-onu'
242
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500243 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400244 # pm_metrics requires a logical device id. For now set to just device_id
245 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500246
Matt Jeannereta32441c2019-03-07 05:16:37 -0500247 yield self.core_proxy.device_update(device)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500248 self.log.debug('device-updated', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500249
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700250 yield self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500251
Matteo Scandolod8d73172019-11-26 12:15:15 -0700252 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500253 ############################################################################
Devmalya Paulffc89df2019-07-31 17:43:13 -0400254 # Setup Alarm handler
255 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
256 device.serial_number)
257 ############################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500258 # Setup PM configuration for this device
259 # Pass in ONU specific options
260 kwargs = {
261 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
262 'heartbeat': self.heartbeat,
263 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
264 }
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500265 self.log.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500266 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Yongjie Zhang8f891ad2019-07-03 15:32:38 -0400267 self.logical_device_id, device.serial_number,
268 grouped=True, freq_override=False, **kwargs)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500269 pm_config = self._pm_metrics.make_proto()
270 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530271 self.log.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500272 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500273
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500274 # Note, ONU ID and UNI intf set in add_uni_port method
Devmalya Paulffc89df2019-07-31 17:43:13 -0400275 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500276 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500277
onkarkundargiaae99712019-09-23 15:02:52 +0530278 # Code to Run OMCI Test Action
279 kwargs_omci_test_action = {
280 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
281 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
282 }
283 serial_number = device.serial_number
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500284 self._test_request = OmciTestRequest(self.core_proxy,
onkarkundargiaae99712019-09-23 15:02:52 +0530285 self.omci_agent, self.device_id,
286 AniG, serial_number,
287 self.logical_device_id,
288 exclusive=False,
289 **kwargs_omci_test_action)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500290
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500291 self.enabled = True
292 else:
293 self.log.info('onu-already-activated')
294
295 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400296 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500297 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700298 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500299
300 # first we verify that we got parent reference and proxy info
301 assert device.parent_id
302 assert device.proxy_address.device_id
303
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700304 self.proxy_address = device.proxy_address
305 self.parent_id = device.parent_id
306 self._pon_port_number = device.parent_port_no
307
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500308 if self.enabled is not True:
309 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700310 self.logical_device_id = self.device_id
311 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500312
313 # need to restart state machines on vcore restart. there is no indication to do it for us.
314 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700315 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500316
317 # TODO: this is probably a bit heavy handed
318 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
319 # This may not be necessary when mib resync actually works
320 reactor.callLater(1, self.reboot)
321
322 self.enabled = True
323 else:
324 self.log.info('onu-already-activated')
325
326 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700327 def _init_pon_state(self):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500328 self.log.debug('init-pon-state', device_id=self.device_id, device_logical_id=self.logical_device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500329
330 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500331 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700332 self.log.debug('adding-pon-port-to-agent',
333 type=self._pon.get_port().type,
334 admin_state=self._pon.get_port().admin_state,
335 oper_status=self._pon.get_port().oper_status,
336 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500337
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700338 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500339
Matteo Scandolod8d73172019-11-26 12:15:15 -0700340 self.log.debug('added-pon-port-to-agent',
341 type=self._pon.get_port().type,
342 admin_state=self._pon.get_port().admin_state,
343 oper_status=self._pon.get_port().oper_status,
344 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500345
346 # Create and start the OpenOMCI ONU Device Entry for this ONU
347 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500348 self.core_proxy,
349 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500350 support_classes=self.adapter.broadcom_omci,
351 custom_me_map=self.adapter.custom_me_entities())
352 # Port startup
353 if self._pon is not None:
354 self._pon.enabled = True
355
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500356 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700357 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret42dad792020-02-01 09:28:27 -0500358
359 self._deferred.cancel()
360 self._test_request.stop_collector()
361 self._pm_metrics.stop_collector()
362 self.log.debug('removing-openomci-statemachine')
363 self.omci_agent.remove_device(device.id, cleanup=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500364
365 def _create_tconts(self, uni_id, us_scheduler):
366 alloc_id = us_scheduler['alloc_id']
367 q_sched_policy = us_scheduler['q_sched_policy']
368 self.log.debug('create-tcont', us_scheduler=us_scheduler)
369
370 tcontdict = dict()
371 tcontdict['alloc-id'] = alloc_id
372 tcontdict['q_sched_policy'] = q_sched_policy
373 tcontdict['uni_id'] = uni_id
374
Matt Jeanneret3789d0d2020-01-19 09:03:42 -0500375 tcont = OnuTCont.create(self, tcont=tcontdict)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500376
377 self._pon.add_tcont(tcont)
378
379 self.log.debug('pon-add-tcont', tcont=tcont)
380
381 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
382 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
383 self.log.debug('create-gemport',
384 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530385 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500386 for gem_port in gem_ports:
387 gemdict = dict()
388 gemdict['gemport_id'] = gem_port['gemport_id']
389 gemdict['direction'] = direction
390 gemdict['alloc_id_ref'] = alloc_id_ref
391 gemdict['encryption'] = gem_port['aes_encryption']
392 gemdict['discard_config'] = dict()
393 gemdict['discard_config']['max_probability'] = \
394 gem_port['discard_config']['max_probability']
395 gemdict['discard_config']['max_threshold'] = \
396 gem_port['discard_config']['max_threshold']
397 gemdict['discard_config']['min_threshold'] = \
398 gem_port['discard_config']['min_threshold']
399 gemdict['discard_policy'] = gem_port['discard_policy']
400 gemdict['max_q_size'] = gem_port['max_q_size']
401 gemdict['pbit_map'] = gem_port['pbit_map']
402 gemdict['priority_q'] = gem_port['priority_q']
403 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
404 gemdict['weight'] = gem_port['weight']
405 gemdict['uni_id'] = uni_id
406
407 gem_port = OnuGemPort.create(self, gem_port=gemdict)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530408 new_gem_ports.append(gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500409
410 self._pon.add_gem_port(gem_port)
411
412 self.log.debug('pon-add-gemport', gem_port=gem_port)
413
Girish Gowdrae933cd32019-11-21 21:04:41 +0530414 return new_gem_ports
415
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800416 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400417 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
418 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
419 # or initial-mib-download is not done. Once the tp_task is completed, we execute
420 # such queued vlan-filter tasks
421 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800422 if uni_id in self._queued_vlan_filter_task and tp_id in self._queued_vlan_filter_task[uni_id]:
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400423 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800424 uni_id=uni_id, tp_id=tp_id)
425 filter_info = self._queued_vlan_filter_task[uni_id][tp_id]
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400426 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800427 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
428 match_vlan = filter_info.get("match_vlan"),
429 _set_vlan_vid= filter_info.get("set_vlan_vid"),
430 _set_vlan_pcp = filter_info.get("set_vlan_pcp"),
431 tp_id = filter_info.get("tp_id"))
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400432 # Now remove the entry from the dictionary
433 self._queued_vlan_filter_task[uni_id].clear()
434 self.log.debug("executed-queued-vlan-filter-task",
435 uni_id=uni_id)
436 except Exception as e:
437 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
438
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500439 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500440 us_scheduler = tp['us_scheduler']
441 alloc_id = us_scheduler['alloc_id']
442 self._create_tconts(uni_id, us_scheduler)
443 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
444 self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
445 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
446 self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
447
448 def load_and_configure_tech_profile(self, uni_id, tp_path):
449 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800450 tp_id = int ( tp_path.split ( "/" )[1] )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500451 if uni_id not in self._tp_service_specific_task:
452 self._tp_service_specific_task[uni_id] = dict()
453
454 if uni_id not in self._tech_profile_download_done:
455 self._tech_profile_download_done[uni_id] = dict()
456
457 if tp_path not in self._tech_profile_download_done[uni_id]:
458 self._tech_profile_download_done[uni_id][tp_path] = False
459
460 if not self._tech_profile_download_done[uni_id][tp_path]:
461 try:
462 if tp_path in self._tp_service_specific_task[uni_id]:
463 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530464 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500465 return
466
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500467 tpstored = self.kv_client[tp_path]
468 tpstring = tpstored.decode('ascii')
469 tp = json.loads(tpstring)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530470
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500471 self.log.debug("tp-instance", tp=tp)
472 self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700473
William Kurkian3a206332019-04-29 11:05:47 -0400474 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500475 def success(_results):
476 self.log.info("tech-profile-config-done-successfully")
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._tech_profile_download_done[uni_id][tp_path] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400480 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800481 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500482 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530483
William Kurkian3a206332019-04-29 11:05:47 -0400484 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500485 def failure(_reason):
486 self.log.warn('tech-profile-config-failure-retrying',
Girish Gowdrae933cd32019-11-21 21:04:41 +0530487 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500488 if tp_path in self._tp_service_specific_task[uni_id]:
489 del self._tp_service_specific_task[uni_id][tp_path]
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500490 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
491 reactor.callLater(retry, self.load_and_configure_tech_profile,
492 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500493 yield self.core_proxy.device_reason_update(self.device_id,
494 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500495
496 self.log.info('downloading-tech-profile-configuration')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530497 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
498 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
499 # due to additional tasks on different UNIs. So, it we cannot use the pon_port after
500 # this initializer
501 tconts = []
502 for tcont in list(self.pon_port.tconts.values()):
503 if tcont.uni_id is not None and tcont.uni_id != uni_id:
504 continue
505 tconts.append(tcont)
506
507 gem_ports = []
508 for gem_port in list(self.pon_port.gem_ports.values()):
509 if gem_port.uni_id is not None and gem_port.uni_id != uni_id:
510 continue
511 gem_ports.append(gem_port)
512
513 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
514
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500515 self._tp_service_specific_task[uni_id][tp_path] = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530516 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, int(tp_path.split("/")[1]))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500517 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530518 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500519 self._deferred.addCallbacks(success, failure)
520
521 except Exception as e:
522 self.log.exception("error-loading-tech-profile", e=e)
523 else:
524 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530525 # Could be a case where TP exists but new gem-ports are getting added dynamically
526 tpstored = self.kv_client[tp_path]
527 tpstring = tpstored.decode('ascii')
528 tp = json.loads(tpstring)
529 upstream_gems = []
530 downstream_gems = []
531 # Find out the new Gem ports that are getting added afresh.
532 for gp in tp['upstream_gem_port_attribute_list']:
533 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
534 # gem port already exists
535 continue
536 upstream_gems.append(gp)
537 for gp in tp['downstream_gem_port_attribute_list']:
538 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
539 # gem port already exists
540 continue
541 downstream_gems.append(gp)
542
543 us_scheduler = tp['us_scheduler']
544 alloc_id = us_scheduler['alloc_id']
545
546 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
547 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
548 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
549 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
550 new_gems = []
551 new_gems.extend(new_upstream_gems)
552 new_gems.extend(new_downstream_gems)
553
554 def success(_results):
555 self.log.info("new-gem-ports-successfully-installed", result=_results)
556
557 def failure(_reason):
558 self.log.warn('new-gem-port-install-failed--retrying',
559 _reason=_reason)
560 # Remove gem ports from cache. We will re-add them during the retry
561 for gp in new_gems:
562 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
563
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500564 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
565 reactor.callLater(retry, self.load_and_configure_tech_profile,
566 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530567
568 self._tp_service_specific_task[uni_id][tp_path] = \
569 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, int(tp_path.split("/")[1]))
570 self._deferred = \
571 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
572 self._deferred.addCallbacks(success, failure)
573
574 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
575 try:
Naga Manjunathe433c712020-01-02 17:27:20 +0530576 if not uni_id in self._tech_profile_download_done:
577 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
578 return
579
580 if not tp_path in self._tech_profile_download_done[uni_id]:
581 self.log.warn("tp-path-is-not-present", tp_path=tp_path)
582 return
583
Girish Gowdrae933cd32019-11-21 21:04:41 +0530584 if self._tech_profile_download_done[uni_id][tp_path] is not True:
585 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete")
586 return
587
588 if alloc_id is None and gem_port_id is None:
589 self.log.error("alloc-id-and-gem-port-id-are-none")
590 return
591
592 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
593 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
594 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
595 # this initializer
596 tcont = None
597 self.log.debug("tconts", tconts=list(self.pon_port.tconts.values()))
598 for tc in list(self.pon_port.tconts.values()):
599 if tc.alloc_id == alloc_id:
600 tcont = tc
601 self.pon_port.remove_tcont(tc.alloc_id, False)
602
603 gem_port = None
604 self.log.debug("gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
605 for gp in list(self.pon_port.gem_ports.values()):
606 if gp.gem_id == gem_port_id:
607 gem_port = gp
608 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
609
610 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
611 # We need the TP Table ID
612 tp_table_id = int(tp_path.split("/")[1])
613
614 @inlineCallbacks
615 def success(_results):
616 if gem_port_id:
617 self.log.info("gem-port-delete-done-successfully")
618 if alloc_id:
619 self.log.info("tcont-delete-done-successfully")
620 # The deletion of TCONT marks the complete deletion of tech-profile
621 try:
622 del self._tech_profile_download_done[uni_id][tp_path]
623 del self._tp_service_specific_task[uni_id][tp_path]
624 except Exception as ex:
625 self.log.error("del-tp-state-info", e=ex)
626
627 # TODO: There could be multiple TP on the UNI, and also the ONU.
628 # TODO: But the below reason updates for the whole device.
629 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
630
631 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530632 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530633 self.log.warn('tech-profile-delete-failure-retrying',
634 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500635 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
636 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500637 yield self.core_proxy.device_reason_update(self.device_id,
638 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530639
640 self.log.info('deleting-tech-profile-configuration')
641
Girish Gowdraa73ee452019-12-20 18:52:17 +0530642 if tcont is None and gem_port is None:
643 if alloc_id is not None:
644 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
645 if gem_port_id is not None:
646 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
647 return
648
Girish Gowdrae933cd32019-11-21 21:04:41 +0530649 self._tp_service_specific_task[uni_id][tp_path] = \
650 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
651 tcont=tcont, gem_port=gem_port)
652 self._deferred = \
653 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
654 self._deferred.addCallbacks(success, failure)
655 except Exception as e:
656 self.log.exception("failed-to-delete-tp",
657 e=e, uni_id=uni_id, tp_path=tp_path,
658 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500659
660 def update_pm_config(self, device, pm_config):
661 # TODO: This has not been tested
662 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500663 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500664
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800665 def remove_onu_flows(self, device, flows):
666 self.log.debug('remove_onu_flows', device_id=device.id)
667
668
669 # no point in removing omci flows if the device isnt reachable
670 if device.connect_status != ConnectStatus.REACHABLE or \
671 device.admin_state != AdminState.ENABLED:
672 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
673 admin=device.admin_state, connect=device.connect_status)
674 return
675
676 for flow in flows:
677 # if incoming flow contains cookie, then remove from ONU
678 if flow.cookie:
679 self.log.debug("remove-flow", device_id=device.id, flow=flow)
680
681 def is_downstream(port):
682 return port == self._pon_port_number
683
684 def is_upstream(port):
685 return not is_downstream(port)
686
687 try:
688 _in_port = fd.get_in_port(flow)
689 assert _in_port is not None
690
691 _out_port = fd.get_out_port(flow) # may be None
692 _vlan_vid = fd.get_default_vlan(flow)
693
694 if is_downstream(_in_port):
695 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
696 device_id=device.id)
697 # extended vlan tagging operation will handle it
698 continue
699 elif is_upstream(_in_port):
700 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
701 if fd.is_dhcp_flow(flow):
702 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
703 return
704
705 uni_port = self.uni_port(_in_port)
706 uni_id = _in_port & 0xF
707 else:
708 raise Exception('port should be 1 or 2 by our convention')
709
710 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
711
712 tp_id = self.get_tp_id_in_flow(flow)
713 # Deleting flow from ONU.
714 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
715 match_vlan=_vlan_vid, tp_id=tp_id)
716 #TODO:Delete TD task.
717 except Exception as e:
718 self.log.exception('failed-to-remove-flow', e=e)
719
720 def add_onu_flows(self, device, flows):
721 self.log.debug('function-entry', flows=flows)
722
723 #
724 # We need to proxy through the OLT to get to the ONU
725 # Configuration from here should be using OMCI
726 #
727 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
728
729 # no point in pushing omci flows if the device isnt reachable
730 if device.connect_status != ConnectStatus.REACHABLE or \
731 device.admin_state != AdminState.ENABLED:
732 self.log.warn("device-disabled-or-offline-skipping-flow-update",
733 admin=device.admin_state, connect=device.connect_status)
734 return
735 def is_downstream(port):
736 return port == self._pon_port_number
737
738 def is_upstream(port):
739 return not is_downstream(port)
740
741 for flow in flows:
742 # if incoming flow contains cookie, then add to ONU
743 if flow.cookie:
744 _type = None
745 _port = None
746 _vlan_vid = None
747 _udp_dst = None
748 _udp_src = None
749 _ipv4_dst = None
750 _ipv4_src = None
751 _metadata = None
752 _output = None
753 _push_tpid = None
754 _field = None
755 _set_vlan_vid = None
756 _set_vlan_pcp = 0
757 _tunnel_id = None
758 self.log.debug("add-flow", device_id=device.id, flow=flow)
759
760 try:
761 _in_port = fd.get_in_port(flow)
762 assert _in_port is not None
763
764 _out_port = fd.get_out_port(flow) # may be None
765 tp_id = self.get_tp_id_in_flow(flow)
766 if is_downstream(_in_port):
767 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
768 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
769 # uni_port = self.uni_port(_out_port)
770 # uni_id = _out_port & 0xF
771 continue
772 elif is_upstream(_in_port):
773 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
774 uni_port = self.uni_port(_in_port)
775 uni_id = _in_port & 0xF
776 else:
777 raise Exception('port should be 1 or 2 by our convention')
778
779 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
780
781 for field in fd.get_ofb_fields(flow):
782 if field.type == fd.ETH_TYPE:
783 _type = field.eth_type
784 self.log.debug('field-type-eth-type',
785 eth_type=_type)
786
787 elif field.type == fd.IP_PROTO:
788 _proto = field.ip_proto
789 self.log.debug('field-type-ip-proto',
790 ip_proto=_proto)
791
792 elif field.type == fd.IN_PORT:
793 _port = field.port
794 self.log.debug('field-type-in-port',
795 in_port=_port)
796 elif field.type == fd.TUNNEL_ID:
797 self.log.debug('field-type-tunnel-id')
798
799 elif field.type == fd.VLAN_VID:
800 _vlan_vid = field.vlan_vid & 0xfff
801 self.log.debug('field-type-vlan-vid',
802 vlan=_vlan_vid)
803
804 elif field.type == fd.VLAN_PCP:
805 _vlan_pcp = field.vlan_pcp
806 self.log.debug('field-type-vlan-pcp',
807 pcp=_vlan_pcp)
808
809 elif field.type == fd.UDP_DST:
810 _udp_dst = field.udp_dst
811 self.log.debug('field-type-udp-dst',
812 udp_dst=_udp_dst)
813
814 elif field.type == fd.UDP_SRC:
815 _udp_src = field.udp_src
816 self.log.debug('field-type-udp-src',
817 udp_src=_udp_src)
818
819 elif field.type == fd.IPV4_DST:
820 _ipv4_dst = field.ipv4_dst
821 self.log.debug('field-type-ipv4-dst',
822 ipv4_dst=_ipv4_dst)
823
824 elif field.type == fd.IPV4_SRC:
825 _ipv4_src = field.ipv4_src
826 self.log.debug('field-type-ipv4-src',
827 ipv4_dst=_ipv4_src)
828
829 elif field.type == fd.METADATA:
830 _metadata = field.table_metadata
831 self.log.debug('field-type-metadata',
832 metadata=_metadata)
833
834 else:
835 raise NotImplementedError('field.type={}'.format(
836 field.type))
837
838 for action in fd.get_actions(flow):
839
840 if action.type == fd.OUTPUT:
841 _output = action.output.port
842 self.log.debug('action-type-output',
843 output=_output, in_port=_in_port)
844
845 elif action.type == fd.POP_VLAN:
846 self.log.debug('action-type-pop-vlan',
847 in_port=_in_port)
848
849 elif action.type == fd.PUSH_VLAN:
850 _push_tpid = action.push.ethertype
851 self.log.debug('action-type-push-vlan',
852 push_tpid=_push_tpid, in_port=_in_port)
853 if action.push.ethertype != 0x8100:
854 self.log.error('unhandled-tpid',
855 ethertype=action.push.ethertype)
856
857 elif action.type == fd.SET_FIELD:
858 _field = action.set_field.field.ofb_field
859 assert (action.set_field.field.oxm_class ==
860 OFPXMC_OPENFLOW_BASIC)
861 self.log.debug('action-type-set-field',
862 field=_field, in_port=_in_port)
863 if _field.type == fd.VLAN_VID:
864 _set_vlan_vid = _field.vlan_vid & 0xfff
865 self.log.debug('set-field-type-vlan-vid',
866 vlan_vid=_set_vlan_vid)
867 elif _field.type == fd.VLAN_PCP:
868 _set_vlan_pcp = _field.vlan_pcp
869 self.log.debug('set-field-type-vlan-pcp',
870 vlan_pcp=_set_vlan_pcp)
871 else:
872 self.log.error('unsupported-action-set-field-type',
873 field_type=_field.type)
874 else:
875 self.log.error('unsupported-action-type',
876 action_type=action.type, in_port=_in_port)
877
878 if type is not None and _vlan_vid is None:
879 self.log.warn('ignoring-flow-with-ethType', ethType=_type)
880 elif _set_vlan_vid is None or _set_vlan_vid == 0:
881 self.log.warn('ignorning-flow-that-does-not-set-vlanid')
882 else:
883 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, set_vlan_vid=_set_vlan_vid, vlan_vid=_vlan_vid,tp_id=tp_id)
884 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
885 _set_vlan_vid=_set_vlan_vid,
886 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
887 tp_id=tp_id)
888
889 except Exception as e:
890 self.log.exception('failed-to-install-flow', e=e, flow=flow)
891
892
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500893 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
894 # flow decomposition that ultimately comes from onos
895 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700896 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500897
898 #
899 # We need to proxy through the OLT to get to the ONU
900 # Configuration from here should be using OMCI
901 #
902 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
903
904 # no point in pushing omci flows if the device isnt reachable
905 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530906 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500907 self.log.warn("device-disabled-or-offline-skipping-flow-update",
908 admin=device.admin_state, connect=device.connect_status)
909 return
910
911 def is_downstream(port):
912 return port == self._pon_port_number
913
914 def is_upstream(port):
915 return not is_downstream(port)
916
917 for flow in flows:
918 _type = None
919 _port = None
920 _vlan_vid = None
921 _udp_dst = None
922 _udp_src = None
923 _ipv4_dst = None
924 _ipv4_src = None
925 _metadata = None
926 _output = None
927 _push_tpid = None
928 _field = None
929 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800930 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400931 _tunnel_id = None
932
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500933 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530934 write_metadata = fd.get_write_metadata(flow)
935 if write_metadata is None:
936 self.log.error("do-not-process-flow-without-write-metadata")
937 return
938
939 # extract tp id from flow
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800940 tp_id= self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500941 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +0530942
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500943 _in_port = fd.get_in_port(flow)
944 assert _in_port is not None
945
946 _out_port = fd.get_out_port(flow) # may be None
947
948 if is_downstream(_in_port):
949 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
950 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530951 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500952 elif is_upstream(_in_port):
953 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
954 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400955 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500956 else:
957 raise Exception('port should be 1 or 2 by our convention')
958
959 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
960
961 for field in fd.get_ofb_fields(flow):
962 if field.type == fd.ETH_TYPE:
963 _type = field.eth_type
964 self.log.debug('field-type-eth-type',
965 eth_type=_type)
966
967 elif field.type == fd.IP_PROTO:
968 _proto = field.ip_proto
969 self.log.debug('field-type-ip-proto',
970 ip_proto=_proto)
971
972 elif field.type == fd.IN_PORT:
973 _port = field.port
974 self.log.debug('field-type-in-port',
975 in_port=_port)
976
977 elif field.type == fd.VLAN_VID:
978 _vlan_vid = field.vlan_vid & 0xfff
979 self.log.debug('field-type-vlan-vid',
980 vlan=_vlan_vid)
981
982 elif field.type == fd.VLAN_PCP:
983 _vlan_pcp = field.vlan_pcp
984 self.log.debug('field-type-vlan-pcp',
985 pcp=_vlan_pcp)
986
987 elif field.type == fd.UDP_DST:
988 _udp_dst = field.udp_dst
989 self.log.debug('field-type-udp-dst',
990 udp_dst=_udp_dst)
991
992 elif field.type == fd.UDP_SRC:
993 _udp_src = field.udp_src
994 self.log.debug('field-type-udp-src',
995 udp_src=_udp_src)
996
997 elif field.type == fd.IPV4_DST:
998 _ipv4_dst = field.ipv4_dst
999 self.log.debug('field-type-ipv4-dst',
1000 ipv4_dst=_ipv4_dst)
1001
1002 elif field.type == fd.IPV4_SRC:
1003 _ipv4_src = field.ipv4_src
1004 self.log.debug('field-type-ipv4-src',
1005 ipv4_dst=_ipv4_src)
1006
1007 elif field.type == fd.METADATA:
1008 _metadata = field.table_metadata
1009 self.log.debug('field-type-metadata',
1010 metadata=_metadata)
1011
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001012 elif field.type == fd.TUNNEL_ID:
1013 _tunnel_id = field.tunnel_id
1014 self.log.debug('field-type-tunnel-id',
1015 tunnel_id=_tunnel_id)
1016
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001017 else:
1018 raise NotImplementedError('field.type={}'.format(
1019 field.type))
1020
1021 for action in fd.get_actions(flow):
1022
1023 if action.type == fd.OUTPUT:
1024 _output = action.output.port
1025 self.log.debug('action-type-output',
1026 output=_output, in_port=_in_port)
1027
1028 elif action.type == fd.POP_VLAN:
1029 self.log.debug('action-type-pop-vlan',
1030 in_port=_in_port)
1031
1032 elif action.type == fd.PUSH_VLAN:
1033 _push_tpid = action.push.ethertype
1034 self.log.debug('action-type-push-vlan',
1035 push_tpid=_push_tpid, in_port=_in_port)
1036 if action.push.ethertype != 0x8100:
1037 self.log.error('unhandled-tpid',
1038 ethertype=action.push.ethertype)
1039
1040 elif action.type == fd.SET_FIELD:
1041 _field = action.set_field.field.ofb_field
1042 assert (action.set_field.field.oxm_class ==
1043 OFPXMC_OPENFLOW_BASIC)
1044 self.log.debug('action-type-set-field',
1045 field=_field, in_port=_in_port)
1046 if _field.type == fd.VLAN_VID:
1047 _set_vlan_vid = _field.vlan_vid & 0xfff
1048 self.log.debug('set-field-type-vlan-vid',
1049 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001050 elif _field.type == fd.VLAN_PCP:
1051 _set_vlan_pcp = _field.vlan_pcp
1052 self.log.debug('set-field-type-vlan-pcp',
1053 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001054 else:
1055 self.log.error('unsupported-action-set-field-type',
1056 field_type=_field.type)
1057 else:
1058 self.log.error('unsupported-action-type',
1059 action_type=action.type, in_port=_in_port)
1060
Matt Jeanneret810148b2019-09-29 12:44:01 -04001061 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1062 # supported match and action criteria cannot be handled by omci and must be ignored.
1063 if _set_vlan_vid is None or _set_vlan_vid == 0:
1064 self.log.warn('ignoring-flow-that-does-not-set-vlanid')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001065 else:
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001066 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid, set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
1067 self._add_vlan_filter_task(device, uni_id,
1068 uni_port=uni_port, match_vlan=_vlan_vid,
1069 _set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001070 except Exception as e:
1071 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1072
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001073 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
1074 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1075 self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan, vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001076 assert uni_port is not None
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001077 if uni_id in self._tech_profile_download_done and self._tech_profile_download_done[uni_id] != {}:
1078 @inlineCallbacks
1079 def success(_results):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001080 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id, set_vlan_pcp=_set_vlan_pcp)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001081 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001082
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001083 @inlineCallbacks
1084 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301085 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001086 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001087 reactor.callLater(retry,
1088 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1089 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1090 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001091 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001092
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001093 self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan, vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
1094 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
1095 match_vlan, _set_vlan_pcp, add_tag=True,
1096 tp_id=tp_id)
1097 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001098 self._deferred.addCallbacks(success, failure)
1099 else:
1100 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001101 uni_id=uni_id, tp_id=tp_id)
1102 if uni_id not in self._queued_vlan_filter_task:
1103 self._queued_vlan_filter_task[uni_id] = dict()
1104 self._queued_vlan_filter_task[uni_id][tp_id] = {"device": device,
1105 "uni_id": uni_id,
1106 "uni_port": uni_port,
1107 "match_vlan": match_vlan,
1108 "set_vlan_vid": _set_vlan_vid,
1109 "set_vlan_pcp": _set_vlan_pcp,
1110 "tp_id": tp_id}
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001111
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001112 def get_tp_id_in_flow(self, flow):
1113 flow_metadata = fd.get_metadata_from_write_metadata ( flow )
1114 tp_id = fd.get_tp_id_from_metadata ( flow_metadata )
1115 return tp_id
1116
1117 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
1118 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1119 assert uni_port is not None
1120 @inlineCallbacks
1121 def success(_results):
1122 self.log.info('vlan-untagging-success', _results=_results)
1123 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1124
1125 @inlineCallbacks
1126 def failure(_reason):
1127 self.log.warn('vlan-untagging-failure', _reason=_reason)
1128 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
1129 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
1130 reactor.callLater(retry,
1131 self._remove_vlan_filter_task, device, uni_id,
1132 add_tag=False, uni_port=uni_port)
1133
1134 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1135 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
1136 match_vlan, _set_vlan_pcp, add_tag=False,
1137 tp_id=tp_id)
1138 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1139 self._deferred.addCallbacks(success, failure)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001140 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001141 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1142 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001143 try:
1144 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1145 omci_msg = InterAdapterOmciMessage()
1146 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001147 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001148
Matt Jeannereta32441c2019-03-07 05:16:37 -05001149 self.receive_message(omci_msg.message)
1150
1151 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1152 onu_indication = OnuIndication()
1153 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001154 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1155 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1156 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001157
1158 if onu_indication.oper_state == "up":
1159 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301160 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001161 self.update_interface(onu_indication)
1162 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001163 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1164 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001165
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001166 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1167 tech_msg = InterAdapterTechProfileDownloadMessage()
1168 request.body.Unpack(tech_msg)
1169 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1170
1171 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1172
Girish Gowdrae933cd32019-11-21 21:04:41 +05301173 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1174 del_gem_msg = InterAdapterDeleteGemPortMessage()
1175 request.body.Unpack(del_gem_msg)
1176 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1177
1178 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1179 gem_port_id=del_gem_msg.gem_port_id,
1180 tp_path=del_gem_msg.tp_path)
1181
1182 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1183 del_tcont_msg = InterAdapterDeleteTcontMessage()
1184 request.body.Unpack(del_tcont_msg)
1185 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1186
1187 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1188 alloc_id=del_tcont_msg.alloc_id,
1189 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001190 else:
1191 self.log.error("inter-adapter-unhandled-type", request=request)
1192
1193 except Exception as e:
1194 self.log.exception("error-processing-inter-adapter-message", e=e)
1195
1196 # Called each time there is an onu "up" indication from the olt handler
1197 @inlineCallbacks
1198 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001199 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -07001200 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001201
1202 # Ignore if onu_indication is received for an already running ONU
1203 if self._onu_omci_device is not None and self._onu_omci_device.active:
1204 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1205 return
1206
Matt Jeannereta32441c2019-03-07 05:16:37 -05001207 self._onu_indication = onu_indication
1208
Matt Jeanneretc083f462019-03-11 15:02:01 -04001209 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1210 connect_status=ConnectStatus.REACHABLE)
1211
Matt Jeannereta32441c2019-03-07 05:16:37 -05001212 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001213
1214 self.log.debug('starting-openomci-statemachine')
1215 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001216 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301217 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001218 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001219 self._heartbeat.enabled = True
1220
Matt Jeanneret42dad792020-02-01 09:28:27 -05001221 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001222 @inlineCallbacks
1223 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001224 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -07001225 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001226
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001227 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001228 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001229 reactor.callLater(0, self._onu_omci_device.stop)
1230
1231 # Let TP download happen again
1232 for uni_id in self._tp_service_specific_task:
1233 self._tp_service_specific_task[uni_id].clear()
1234 for uni_id in self._tech_profile_download_done:
1235 self._tech_profile_download_done[uni_id].clear()
1236
Matt Jeanneretf4113222019-08-14 19:44:34 -04001237 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001238 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1239 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1240 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001241 else:
1242 self.log.debug('not-changing-openomci-statemachine')
1243
Matt Jeanneretf4113222019-08-14 19:44:34 -04001244 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001245 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001246 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001247 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001248 yield self.disable_ports(lock_ports=True)
1249 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1250 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001251
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001252 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001253 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001254
William Kurkian3a206332019-04-29 11:05:47 -04001255 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001256 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001257 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001258 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001259 yield self.core_proxy.device_state_update(device.id,
1260 oper_status=OperStatus.ACTIVE,
1261 connect_status=ConnectStatus.REACHABLE)
1262 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1263 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001264 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001265 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001266
William Kurkian3a206332019-04-29 11:05:47 -04001267 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001268 def reboot(self):
1269 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001270 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001271 if device.connect_status != ConnectStatus.REACHABLE:
1272 self.log.error("device-unreachable")
1273 return
1274
William Kurkian3a206332019-04-29 11:05:47 -04001275 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001276 def success(_results):
1277 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001278 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001279
1280 def failure(_reason):
1281 self.log.info('reboot-failure', _reason=_reason)
1282
1283 self._deferred = self._onu_omci_device.reboot()
1284 self._deferred.addCallbacks(success, failure)
1285
William Kurkian3a206332019-04-29 11:05:47 -04001286 @inlineCallbacks
Matt Jeanneretf4113222019-08-14 19:44:34 -04001287 def disable_ports(self, lock_ports=True):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001288 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001289
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001290 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1291 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001292 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001293 if port.mac_bridge_port_num == 1:
1294 port.operstatus = OperStatus.UNKNOWN
1295 self.log.info('disable-port', device_id=self.device_id, port=port)
1296 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, port.operstatus)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001297
1298 if lock_ports is True:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001299 self.lock_ports(lock=True)
1300
William Kurkian3a206332019-04-29 11:05:47 -04001301 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001302 def enable_ports(self):
1303 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001304
Matt Jeanneretf4113222019-08-14 19:44:34 -04001305 self.lock_ports(lock=False)
1306
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001307 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1308 # load on the core
1309 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001310 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001311 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001312 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001313 self.log.info('enable-port', device_id=self.device_id, port=port)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001314 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, port.operstatus)
1315
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001316
1317 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1318 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1319 #
1320 # Basically the link state sequence:
1321 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1322 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1323 # 3) a link state up alarm is received for the uni plugged in.
1324 #
1325 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1326 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1327 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1328 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001329 @inlineCallbacks
1330 def port_state_handler(self, _topic, msg):
1331 self.log.info("port-state-change", _topic=_topic, msg=msg)
1332
1333 onu_id = msg['onu_id']
1334 port_no = msg['port_number']
1335 serial_number = msg['serial_number']
1336 port_status = msg['port_status']
1337 uni_port = self.uni_port(int(port_no))
1338
1339 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1340 port_status=port_status)
1341
1342 if port_status is True:
1343 uni_port.operstatus = OperStatus.ACTIVE
1344 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1345 else:
1346 uni_port.operstatus = OperStatus.UNKNOWN
1347 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1348
1349 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, uni_port.port_number, uni_port.operstatus)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001350 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001351
1352 # Called just before openomci state machine is started. These listen for events from selected state machines,
1353 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1354 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001355 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001356
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001357 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001358
1359 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001360 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1361 OnuDeviceEvents.MibDatabaseSyncEvent)
1362 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1363
1364 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001365 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1366 OnuDeviceEvents.OmciCapabilitiesEvent)
1367 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1368
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001369 # TODO: these alarms seem to be unreliable depending on the environment
1370 # Listen for UNI link state alarms and set the oper_state based on that rather than assuming all UNI are up
1371 #topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1372 # OnuDeviceEvents.PortEvent)
1373 #self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
1374
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001375 # Called when the mib is in sync
1376 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001377 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001378 if self._in_sync_subscription is not None:
1379 try:
1380 in_sync = msg[IN_SYNC_KEY]
1381
1382 if in_sync:
1383 # Only call this once
1384 bus = self._onu_omci_device.event_bus
1385 bus.unsubscribe(self._in_sync_subscription)
1386 self._in_sync_subscription = None
1387
1388 # Start up device_info load
1389 self.log.debug('running-mib-sync')
1390 reactor.callLater(0, self._mib_in_sync)
1391
1392 except Exception as e:
1393 self.log.exception('in-sync', e=e)
1394
1395 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001396 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001397 if self._capabilities_subscription is not None:
1398 self.log.debug('capabilities-handler-done')
1399
1400 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1401 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1402 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001403 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001404 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001405 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001406
1407 omci = self._onu_omci_device
1408 in_sync = omci.mib_db_in_sync
1409
Matt Jeanneretc083f462019-03-11 15:02:01 -04001410 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001411 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001412
1413 if not self._dev_info_loaded:
1414 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1415
1416 omci_dev = self._onu_omci_device
1417 config = omci_dev.configuration
1418
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001419 try:
1420
1421 # sort the lists so we get consistent port ordering.
1422 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1423 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1424 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1425 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1426
1427 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001428 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001429 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001430 raise Exception("onu-missing-required-elements")
1431
1432 # Currently logging the ani, pptp, veip, and uni for information purposes.
1433 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1434 # And in some ONU the UNI-G list is incomplete or incorrect...
1435 for entity_id in ani_list:
1436 ani_value = config.ani_g_entities[entity_id]
1437 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1438 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1439 self._total_tcont_count = ani_value.get('total-tcont-count')
1440 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1441
1442 for entity_id in uni_list:
1443 uni_value = config.uni_g_entities[entity_id]
1444 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1445
1446 uni_entities = OrderedDict()
1447 for entity_id in pptp_list:
1448 pptp_value = config.pptp_entities[entity_id]
1449 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1450 uni_entities[entity_id] = UniType.PPTP
1451
1452 for entity_id in veip_list:
1453 veip_value = config.veip_entities[entity_id]
1454 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1455 uni_entities[entity_id] = UniType.VEIP
1456
1457 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001458 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001459 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001460 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001461 uni_id += 1
1462 except AssertionError as e:
1463 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1464
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001465 self._qos_flexibility = config.qos_configuration_flexibility or 0
1466 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1467
1468 if self._unis:
1469 self._dev_info_loaded = True
1470 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001471 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001472 self.log.warn("no-usable-unis")
1473 raise Exception("no-usable-unis")
1474
1475 except Exception as e:
1476 self.log.exception('device-info-load', e=e)
1477 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1478
1479 else:
1480 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1481
1482 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001483 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001484
1485 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001486 def success(_results):
1487 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001488 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301489 oper_status=OperStatus.ACTIVE,
1490 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001491 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001492 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001493 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001494 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001495
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001496 # Start collecting stats from the device after a brief pause
1497 if not self._pm_metrics_started:
1498 self._pm_metrics_started = True
1499 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1500 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1501
1502 # Start test requests after a brief pause
1503 if not self._test_request_started:
1504 self._test_request_started = True
1505 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1506 reactor.callLater(tststart, self._test_request.start_collector)
1507
Matt Jeanneretc083f462019-03-11 15:02:01 -04001508 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001509 def failure(_reason):
1510 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001511 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
1512 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001513 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001514
Matt Jeanneretf4113222019-08-14 19:44:34 -04001515 # start by locking all the unis till mib sync and initial mib is downloaded
1516 # this way we can capture the port down/up events when we are ready
1517 self.lock_ports(lock=True)
1518
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001519 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1520 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1521 self.log.info('downloading-initial-mib-configuration')
1522 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1523 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1524 self._deferred.addCallbacks(success, failure)
1525 else:
1526 self.log.info('admin-down-disabling')
1527 self.disable(device)
1528 else:
1529 self.log.info('device-info-not-loaded-skipping-mib-download')
1530
Matt Jeanneretc083f462019-03-11 15:02:01 -04001531 @inlineCallbacks
1532 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001533 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001534
Matt Jeanneretc083f462019-03-11 15:02:01 -04001535 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 -05001536
1537 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1538 uni_name = "uni-{}".format(uni_no)
1539
Girish Gowdrae933cd32019-11-21 21:04:41 +05301540 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001541
1542 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 -04001543 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001544
1545 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1546 uni_port.entity_id = entity_id
1547 uni_port.enabled = True
1548 uni_port.mac_bridge_port_num = mac_bridge_port_num
1549
1550 self.log.debug("created-uni-port", uni=uni_port)
1551
Matt Jeanneretc083f462019-03-11 15:02:01 -04001552 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001553
1554 self._unis[uni_port.port_number] = uni_port
1555
1556 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301557 uni_ports=self.uni_ports,
1558 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001559
Matt Jeanneretc083f462019-03-11 15:02:01 -04001560 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1561 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001562 MAX_PONS_PER_OLT = 256
1563 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001564 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001565
Matt Jeanneretc083f462019-03-11 15:02:01 -04001566 assert intf_id < MAX_PONS_PER_OLT
1567 assert onu_id < MAX_ONUS_PER_PON
1568 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001569 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001570
1571 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001572 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001573 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001574 try:
1575 device = yield self.core_proxy.get_device(self.device_id)
1576 parent_device = yield self.core_proxy.get_device(self.parent_id)
1577 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001578 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001579
1580 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301581 pon_id=self._onu_indication.intf_id,
1582 onu_id=self._onu_indication.onu_id,
1583 registration_id=self.device_id,
1584 device_id=self.device_id,
1585 onu_serial_number=device.serial_number,
1586 olt_serial_number=olt_serial_number,
1587 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001588
Devmalya Paulffc89df2019-07-31 17:43:13 -04001589 self.log.debug("Trying-to-raise-onu-active-event")
1590 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001591 self._onu_indication.intf_id,
1592 device.serial_number,
1593 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301594 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001595 onu_id=self._onu_indication.onu_id).send(True)
1596 except Exception as active_event_error:
1597 self.log.exception('onu-activated-event-error',
1598 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001599
1600 def lock_ports(self, lock=True):
1601
1602 def success(response):
1603 self.log.debug('set-onu-ports-state', lock=lock, response=response)
1604
1605 def failure(response):
1606 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1607
1608 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1609 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1610 self._deferred.addCallbacks(success, failure)