blob: 79c72fe0c4556f2ea9b671d7fb00bb627af6c424 [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
Devmalya Paule2e5f2b2020-03-08 18:50:33 -040035from pyvoltha.adapters.extensions.events.device_events.onu.onu_disabled_event import OnuDisabledEvent
Devmalya Paulffc89df2019-07-31 17:43:13 -040036from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
37from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
38from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050039
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050040import pyvoltha.common.openflow.utils as fd
41from pyvoltha.common.utils.registry import registry
Matteo Scandolod8d73172019-11-26 12:15:15 -070042from pyvoltha.adapters.common.frameio.frameio import hexify
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050043from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050044from pyvoltha.common.config.config_backend import ConsulStore
45from pyvoltha.common.config.config_backend import EtcdStore
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050046from voltha_protos.logical_device_pb2 import LogicalPort
William Kurkian8235c1e2019-03-05 12:58:28 -050047from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretf4113222019-08-14 19:44:34 -040048from voltha_protos.device_pb2 import Port
Girish Gowdra4c11ddb2020-03-03 11:33:24 -080049from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE, OFPPS_LINK_DOWN, \
Matt Jeanneretf4113222019-08-14 19:44:34 -040050 OFPPF_FIBER, OFPPF_1GB_FD
Matt Jeanneret3bfebff2019-04-12 18:25:03 -040051from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
Girish Gowdrae933cd32019-11-21 21:04:41 +053052 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
53 InterAdapterDeleteTcontMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050054from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050055from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
56from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050057 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050058from omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdrae933cd32019-11-21 21:04:41 +053059from omci.brcm_tp_setup_task import BrcmTpSetupTask
60from omci.brcm_tp_delete_task import BrcmTpDeleteTask
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050061from omci.brcm_uni_lock_task import BrcmUniLockTask
62from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050063from onu_gem_port import OnuGemPort
64from onu_tcont import OnuTCont
65from pon_port import PonPort
Mahir Gunyel5de33fe2020-03-03 22:38:44 -080066from omci.brcm_mcast_task import BrcmMcastTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050067from uni_port import UniPort, UniType
Andrea Campanellacf916ea2020-02-14 10:03:58 +010068from uni_port import RESERVED_TRANSPARENT_VLAN
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050069from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053070from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
71from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050072from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
onkarkundargia1e2af22020-01-27 11:51:43 +053073from voltha_protos.voltha_pb2 import TestResponse
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050074
75OP = EntityOperations
76RC = ReasonCodes
77
Girish Gowdradc98d812020-03-20 13:04:58 -070078IS_MULTICAST = 'is_multicast'
Mahir Gunyel5de33fe2020-03-03 22:38:44 -080079GEM_PORT_ID = 'gemport_id'
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050080_STARTUP_RETRY_WAIT = 10
Mahir Gunyele9110a32020-02-20 14:56:50 -080081_PATH_SEPERATOR = "/"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050082
83
84class BrcmOpenomciOnuHandler(object):
85
86 def __init__(self, adapter, device_id):
87 self.log = structlog.get_logger(device_id=device_id)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050088 self.log.debug('starting-handler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050089 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050090 self.core_proxy = adapter.core_proxy
91 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050092 self.parent_id = None
93 self.device_id = device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050094 self.proxy_address = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050095 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040096 self.events = None
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050097 self._pm_metrics = None
98 self._pm_metrics_started = False
99 self._test_request = None
100 self._test_request_started = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500101 self._omcc_version = OMCCVersion.Unknown
102 self._total_tcont_count = 0 # From ANI-G ME
103 self._qos_flexibility = 0 # From ONT2_G ME
Girish Gowdradc98d812020-03-20 13:04:58 -0700104 self._tp = dict() # tp_id -> technology profile definition in KV Store.
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500105 self._onu_indication = None
106 self._unis = dict() # Port # -> UniPort
107
108 self._pon = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500109 self._pon_port_number = 100
110 self.logical_device_id = None
111
112 self._heartbeat = HeartBeat.create(self, device_id)
113
114 # Set up OpenOMCI environment
115 self._onu_omci_device = None
116 self._dev_info_loaded = False
117 self._deferred = None
118
119 self._in_sync_subscription = None
Matt Jeanneretf4113222019-08-14 19:44:34 -0400120 self._port_state_subscription = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500121 self._connectivity_subscription = None
122 self._capabilities_subscription = None
123
124 self.mac_bridge_service_profile_entity_id = 0x201
125 self.gal_enet_profile_entity_id = 0x1
126
127 self._tp_service_specific_task = dict()
128 self._tech_profile_download_done = dict()
Girish Gowdradc98d812020-03-20 13:04:58 -0700129
130 # When the vlan filter is being removed for a given TP ID on a given UNI,
131 # mark that we are expecting a tp delete to happen for this UNI.
132 # Unless the TP delete is complete to not allow new vlan add tasks to this TP ID
133 self._pending_delete_tp = dict()
134
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400135 # Stores information related to queued vlan filter tasks
136 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
137
138 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500139
Girish Gowdradc98d812020-03-20 13:04:58 -0700140 self._set_vlan = dict() # uni_id, tp_id -> set_vlan_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500141 # Initialize KV store client
142 self.args = registry('main').get_args()
143 if self.args.backend == 'etcd':
144 host, port = self.args.etcd.split(':', 1)
145 self.kv_client = EtcdStore(host, port,
146 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
147 elif self.args.backend == 'consul':
148 host, port = self.args.consul.split(':', 1)
149 self.kv_client = ConsulStore(host, port,
150 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
151 else:
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500152 self.log.error('invalid-backend')
153 raise Exception("invalid-backend-for-kv-store")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500154
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500155 @property
156 def enabled(self):
157 return self._enabled
158
159 @enabled.setter
160 def enabled(self, value):
161 if self._enabled != value:
162 self._enabled = value
163
164 @property
165 def omci_agent(self):
166 return self.adapter.omci_agent
167
168 @property
169 def omci_cc(self):
170 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
171
172 @property
173 def heartbeat(self):
174 return self._heartbeat
175
176 @property
177 def uni_ports(self):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500178 return list(self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500179
180 def uni_port(self, port_no_or_name):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500181 if isinstance(port_no_or_name, six.string_types):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500182 return next((uni for uni in self.uni_ports
183 if uni.name == port_no_or_name), None)
184
185 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
186 return next((uni for uni in self.uni_ports
Girish Gowdrae933cd32019-11-21 21:04:41 +0530187 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500188
189 @property
190 def pon_port(self):
191 return self._pon
192
Girish Gowdraa73ee452019-12-20 18:52:17 +0530193 @property
194 def onu_omci_device(self):
195 return self._onu_omci_device
196
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500197 def receive_message(self, msg):
198 if self.omci_cc is not None:
199 self.omci_cc.receive_message(msg)
200
Matt Jeanneretc083f462019-03-11 15:02:01 -0400201 def get_ofp_port_info(self, device, port_no):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500202 self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400203 cap = OFPPF_1GB_FD | OFPPF_FIBER
204
Girish Gowdrae933cd32019-11-21 21:04:41 +0530205 hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
206 ((device.parent_port_no >> 8 & 0xff),
207 device.parent_port_no & 0xff,
208 (port_no >> 16) & 0xff,
209 (port_no >> 8) & 0xff,
210 port_no & 0xff))
Matt Jeanneretc083f462019-03-11 15:02:01 -0400211
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400212 uni_port = self.uni_port(int(port_no))
213 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500214 self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port)
Matt Jeanneretf4113222019-08-14 19:44:34 -0400215
216 ofstate = OFPPS_LINK_DOWN
217 if uni_port.operstatus is OperStatus.ACTIVE:
218 ofstate = OFPPS_LIVE
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400219
Matt Jeanneretc083f462019-03-11 15:02:01 -0400220 return PortCapability(
221 port=LogicalPort(
222 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400223 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400224 hw_addr=hw_addr,
225 config=0,
Matt Jeanneretf4113222019-08-14 19:44:34 -0400226 state=ofstate,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400227 curr=cap,
228 advertised=cap,
229 peer=cap,
230 curr_speed=OFPPF_1GB_FD,
231 max_speed=OFPPF_1GB_FD
232 ),
233 device_id=device.id,
234 device_port_no=port_no
235 )
236 )
237
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500238 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500239 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500240 def activate(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700241 self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500242
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500243 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500244 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500245 assert device.proxy_address.device_id
246
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500247 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500248 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500249 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500250 if self.enabled is not True:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700251 self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500252 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500253 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500254 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500255 device.reason = 'activating-onu'
256
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500257 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400258 # pm_metrics requires a logical device id. For now set to just device_id
259 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500260
Matt Jeannereta32441c2019-03-07 05:16:37 -0500261 yield self.core_proxy.device_update(device)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500262 self.log.debug('device-updated', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500263
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700264 yield self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500265
Matteo Scandolod8d73172019-11-26 12:15:15 -0700266 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500267 ############################################################################
Devmalya Paulffc89df2019-07-31 17:43:13 -0400268 # Setup Alarm handler
269 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
270 device.serial_number)
271 ############################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500272 # Setup PM configuration for this device
273 # Pass in ONU specific options
274 kwargs = {
275 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
276 'heartbeat': self.heartbeat,
277 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
278 }
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500279 self.log.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500280 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800281 self.logical_device_id, device.serial_number,
282 grouped=True, freq_override=False, **kwargs)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500283 pm_config = self._pm_metrics.make_proto()
284 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530285 self.log.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500286 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500287
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500288 # Note, ONU ID and UNI intf set in add_uni_port method
Devmalya Paulffc89df2019-07-31 17:43:13 -0400289 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500290 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500291
onkarkundargiaae99712019-09-23 15:02:52 +0530292 # Code to Run OMCI Test Action
293 kwargs_omci_test_action = {
294 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
295 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
296 }
297 serial_number = device.serial_number
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500298 self._test_request = OmciTestRequest(self.core_proxy,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800299 self.omci_agent, self.device_id,
300 AniG, serial_number,
301 self.logical_device_id,
302 exclusive=False,
303 **kwargs_omci_test_action)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500304
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500305 self.enabled = True
306 else:
307 self.log.info('onu-already-activated')
308
309 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400310 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500311 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700312 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500313
314 # first we verify that we got parent reference and proxy info
315 assert device.parent_id
316 assert device.proxy_address.device_id
317
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700318 self.proxy_address = device.proxy_address
319 self.parent_id = device.parent_id
320 self._pon_port_number = device.parent_port_no
321
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500322 if self.enabled is not True:
323 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700324 self.logical_device_id = self.device_id
325 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500326
327 # need to restart state machines on vcore restart. there is no indication to do it for us.
328 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700329 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500330
331 # TODO: this is probably a bit heavy handed
332 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
333 # This may not be necessary when mib resync actually works
334 reactor.callLater(1, self.reboot)
335
336 self.enabled = True
337 else:
338 self.log.info('onu-already-activated')
339
340 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700341 def _init_pon_state(self):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500342 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 -0500343
344 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500345 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700346 self.log.debug('adding-pon-port-to-agent',
347 type=self._pon.get_port().type,
348 admin_state=self._pon.get_port().admin_state,
349 oper_status=self._pon.get_port().oper_status,
350 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500351
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700352 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500353
Matteo Scandolod8d73172019-11-26 12:15:15 -0700354 self.log.debug('added-pon-port-to-agent',
355 type=self._pon.get_port().type,
356 admin_state=self._pon.get_port().admin_state,
357 oper_status=self._pon.get_port().oper_status,
358 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500359
360 # Create and start the OpenOMCI ONU Device Entry for this ONU
361 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500362 self.core_proxy,
363 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500364 support_classes=self.adapter.broadcom_omci,
365 custom_me_map=self.adapter.custom_me_entities())
366 # Port startup
367 if self._pon is not None:
368 self._pon.enabled = True
369
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500370 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700371 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret42dad792020-02-01 09:28:27 -0500372
373 self._deferred.cancel()
374 self._test_request.stop_collector()
375 self._pm_metrics.stop_collector()
376 self.log.debug('removing-openomci-statemachine')
377 self.omci_agent.remove_device(device.id, cleanup=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500378
379 def _create_tconts(self, uni_id, us_scheduler):
380 alloc_id = us_scheduler['alloc_id']
381 q_sched_policy = us_scheduler['q_sched_policy']
382 self.log.debug('create-tcont', us_scheduler=us_scheduler)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800383 # TODO: revisit for multi tconts support
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800384 new_tconts = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500385 tcontdict = dict()
386 tcontdict['alloc-id'] = alloc_id
387 tcontdict['q_sched_policy'] = q_sched_policy
388 tcontdict['uni_id'] = uni_id
389
Matt Jeanneret3789d0d2020-01-19 09:03:42 -0500390 tcont = OnuTCont.create(self, tcont=tcontdict)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500391
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500392 success = self._pon.add_tcont(tcont)
393 if success:
394 new_tconts.append(tcont)
395 self.log.debug('pon-add-tcont', tcont=tcont)
396
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800397 return new_tconts
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500398
399 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
400 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
401 self.log.debug('create-gemport',
402 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530403 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500404 for gem_port in gem_ports:
405 gemdict = dict()
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800406 if gem_port[IS_MULTICAST] == 'True':
407 gemdict[GEM_PORT_ID] = gem_port['multicast_gem_id']
408 gemdict[IS_MULTICAST] = True
409 else:
410 gemdict[GEM_PORT_ID] = gem_port[GEM_PORT_ID]
411 gemdict[IS_MULTICAST] = False
412
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500413 gemdict['direction'] = direction
414 gemdict['alloc_id_ref'] = alloc_id_ref
415 gemdict['encryption'] = gem_port['aes_encryption']
416 gemdict['discard_config'] = dict()
417 gemdict['discard_config']['max_probability'] = \
418 gem_port['discard_config']['max_probability']
419 gemdict['discard_config']['max_threshold'] = \
420 gem_port['discard_config']['max_threshold']
421 gemdict['discard_config']['min_threshold'] = \
422 gem_port['discard_config']['min_threshold']
423 gemdict['discard_policy'] = gem_port['discard_policy']
424 gemdict['max_q_size'] = gem_port['max_q_size']
425 gemdict['pbit_map'] = gem_port['pbit_map']
426 gemdict['priority_q'] = gem_port['priority_q']
427 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
428 gemdict['weight'] = gem_port['weight']
429 gemdict['uni_id'] = uni_id
430
431 gem_port = OnuGemPort.create(self, gem_port=gemdict)
432
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500433 success = self._pon.add_gem_port(gem_port, True)
434 if success:
435 new_gem_ports.append(gem_port)
436 self.log.debug('pon-add-gemport', gem_port=gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500437
Girish Gowdrae933cd32019-11-21 21:04:41 +0530438 return new_gem_ports
439
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800440 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400441 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
442 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
443 # or initial-mib-download is not done. Once the tp_task is completed, we execute
444 # such queued vlan-filter tasks
445 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800446 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 -0400447 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800448 uni_id=uni_id, tp_id=tp_id)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800449 for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]:
450 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800451 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
452 match_vlan=filter_info.get("match_vlan"),
453 _set_vlan_vid=filter_info.get("set_vlan_vid"),
454 _set_vlan_pcp=filter_info.get("set_vlan_pcp"),
455 tp_id=filter_info.get("tp_id"))
Girish Gowdraaf98a082020-03-05 16:40:51 -0800456 # Now remove the entry from the dictionary
457 self._queued_vlan_filter_task[uni_id][tp_id].remove(filter_info)
458 self.log.debug("executed-queued-vlan-filter-task",
459 uni_id=uni_id, tp_id=tp_id)
460 # Now delete the key entries once we have handled the queued vlan filter tasks.
461 del self._queued_vlan_filter_task[uni_id]
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400462 except Exception as e:
463 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
464
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500465 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500466 us_scheduler = tp['us_scheduler']
467 alloc_id = us_scheduler['alloc_id']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800468 new_tconts = self._create_tconts(uni_id, us_scheduler)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500469 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800470 new_upstream_gems = self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500471 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800472 new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
473
474 new_gems = []
475 new_gems.extend(new_upstream_gems)
476 new_gems.extend(new_downstream_gems)
477
478 return new_tconts, new_gems
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500479
480 def load_and_configure_tech_profile(self, uni_id, tp_path):
481 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyele9110a32020-02-20 14:56:50 -0800482 tp_id = self.extract_tp_id_from_path(tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500483 if uni_id not in self._tp_service_specific_task:
484 self._tp_service_specific_task[uni_id] = dict()
485
486 if uni_id not in self._tech_profile_download_done:
487 self._tech_profile_download_done[uni_id] = dict()
488
Mahir Gunyele9110a32020-02-20 14:56:50 -0800489 if tp_id not in self._tech_profile_download_done[uni_id]:
490 self._tech_profile_download_done[uni_id][tp_id] = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500491
Mahir Gunyele9110a32020-02-20 14:56:50 -0800492 if not self._tech_profile_download_done[uni_id][tp_id]:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500493 try:
494 if tp_path in self._tp_service_specific_task[uni_id]:
495 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530496 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500497 return
498
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500499 tpstored = self.kv_client[tp_path]
500 tpstring = tpstored.decode('ascii')
501 tp = json.loads(tpstring)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800502 self._tp[tp_id] = tp
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500503 self.log.debug("tp-instance", tp=tp)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800504 tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700505
William Kurkian3a206332019-04-29 11:05:47 -0400506 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500507 def success(_results):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800508 self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500509 if tp_path in self._tp_service_specific_task[uni_id]:
510 del self._tp_service_specific_task[uni_id][tp_path]
Mahir Gunyele9110a32020-02-20 14:56:50 -0800511 self._tech_profile_download_done[uni_id][tp_id] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400512 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800513 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500514 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530515
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800516 # Execute mcast task
517 for gem in gem_ports:
Girish Gowdradc98d812020-03-20 13:04:58 -0700518 self.log.debug("checking-multicast-service-for-gem ", gem=gem)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800519 if gem.mcast is True:
Girish Gowdradc98d812020-03-20 13:04:58 -0700520 self.log.info("found-multicast-service-for-gem ", gem=gem, uni_id=uni_id, tp_id=tp_id)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800521 reactor.callInThread(self.start_multicast_service, uni_id, tp_path)
522 self.log.debug("started_multicast_service-successfully", tconts=tconts, gems=gem_ports)
523 break
524
William Kurkian3a206332019-04-29 11:05:47 -0400525 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500526 def failure(_reason):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800527 self.log.warn('tech-profile-config-failure-retrying', uni_id=uni_id, tp_id=tp_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530528 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500529 if tp_path in self._tp_service_specific_task[uni_id]:
530 del self._tp_service_specific_task[uni_id][tp_path]
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800531 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500532 reactor.callLater(retry, self.load_and_configure_tech_profile,
533 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500534 yield self.core_proxy.device_reason_update(self.device_id,
535 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500536
Mahir Gunyela982ec32020-02-25 12:30:37 -0800537 self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530538 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
539
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500540 self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
541 self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
542
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500543 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800544 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500545 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530546 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500547 self._deferred.addCallbacks(success, failure)
548
549 except Exception as e:
550 self.log.exception("error-loading-tech-profile", e=e)
551 else:
Girish Gowdradc98d812020-03-20 13:04:58 -0700552 # There is an active tech-profile task ongoing on this UNI port. So, reschedule this task
553 # after a short interval
554 if uni_id in self._tp_service_specific_task and len(self._tp_service_specific_task[uni_id]):
555 self.log.debug("active-tp-tasks-in-progress-for-uni--scheduling-this-task-for-later",
556 uni_id=uni_id, tp_path=tp_path)
557 reactor.callLater(0.2, self.load_and_configure_tech_profile,
558 uni_id, tp_path)
559 return
560
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500561 self.log.info("tech-profile-config-already-done")
Girish Gowdradc98d812020-03-20 13:04:58 -0700562
Girish Gowdrae933cd32019-11-21 21:04:41 +0530563 # Could be a case where TP exists but new gem-ports are getting added dynamically
564 tpstored = self.kv_client[tp_path]
565 tpstring = tpstored.decode('ascii')
566 tp = json.loads(tpstring)
567 upstream_gems = []
568 downstream_gems = []
569 # Find out the new Gem ports that are getting added afresh.
570 for gp in tp['upstream_gem_port_attribute_list']:
571 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
572 # gem port already exists
573 continue
574 upstream_gems.append(gp)
575 for gp in tp['downstream_gem_port_attribute_list']:
576 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
577 # gem port already exists
578 continue
579 downstream_gems.append(gp)
580
581 us_scheduler = tp['us_scheduler']
582 alloc_id = us_scheduler['alloc_id']
583
584 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
585 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
586 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
587 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
588 new_gems = []
589 new_gems.extend(new_upstream_gems)
590 new_gems.extend(new_downstream_gems)
591
592 def success(_results):
593 self.log.info("new-gem-ports-successfully-installed", result=_results)
594
595 def failure(_reason):
596 self.log.warn('new-gem-port-install-failed--retrying',
597 _reason=_reason)
598 # Remove gem ports from cache. We will re-add them during the retry
599 for gp in new_gems:
600 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
601
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800602 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500603 reactor.callLater(retry, self.load_and_configure_tech_profile,
604 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530605
606 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800607 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530608 self._deferred = \
609 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
610 self._deferred.addCallbacks(success, failure)
Girish Gowdradc98d812020-03-20 13:04:58 -0700611
612 def start_multicast_service(self, uni_id, tp_path, retry_count=0):
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800613 self.log.debug("starting-multicast-service", uni_id=uni_id, tp_path=tp_path)
614 tp_id = self.extract_tp_id_from_path(tp_path)
615 if uni_id in self._set_vlan and tp_id in self._set_vlan[uni_id]:
616 try:
617 tp = self._tp[tp_id]
618 if tp is None:
619 tpstored = self.kv_client[tp_path]
620 tpstring = tpstored.decode('ascii')
621 tp = json.loads(tpstring)
622 if tp is None:
623 self.log.error("cannot-find-tp-to-start-multicast-service", uni_id=uni_id, tp_path=tp_path)
624 return
625 else:
626 self._tp[tp_id] = tp
627
628 self.log.debug("mcast-vlan-learned-before", self._set_vlan[uni_id][tp_id], uni_id=uni_id, tp_id=tp_id)
Girish Gowdradc98d812020-03-20 13:04:58 -0700629
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800630 def success(_results):
631 self.log.debug('multicast-success', uni_id=uni_id)
632 self._multicast_task = None
633
634 def failure(_reason):
635 self.log.warn('multicast-failure', _reason=_reason)
Girish Gowdradc98d812020-03-20 13:04:58 -0700636 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800637 reactor.callLater(retry, self.start_multicast_service,
Girish Gowdradc98d812020-03-20 13:04:58 -0700638 uni_id, tp_path)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800639
640 self.log.debug('starting-multicast-task', mcast_vlan_id=self._set_vlan[uni_id][tp_id])
641 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
642 for i in range(len(downstream_gem_port_attribute_list)):
643 if IS_MULTICAST in downstream_gem_port_attribute_list[i] and \
644 downstream_gem_port_attribute_list[i][IS_MULTICAST] == 'True':
Girish Gowdradc98d812020-03-20 13:04:58 -0700645 dynamic_access_control_list_table = downstream_gem_port_attribute_list[i][
646 'dynamic_access_control_list'].split("-")
647 static_access_control_list_table = downstream_gem_port_attribute_list[i][
648 'static_access_control_list'].split("-")
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800649 multicast_gem_id = downstream_gem_port_attribute_list[i]['multicast_gem_id']
650 break
651
652 self._multicast_task = BrcmMcastTask(self.omci_agent, self, self.device_id, uni_id, tp_id,
Girish Gowdradc98d812020-03-20 13:04:58 -0700653 self._set_vlan[uni_id][tp_id], dynamic_access_control_list_table,
654 static_access_control_list_table, multicast_gem_id)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800655 self._deferred = self._onu_omci_device.task_runner.queue_task(self._multicast_task)
656 self._deferred.addCallbacks(success, failure)
657 except Exception as e:
658 self.log.exception("error-loading-multicast", e=e)
659 else:
Girish Gowdradc98d812020-03-20 13:04:58 -0700660 if retry_count < 30:
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800661 retry_count = +1
Girish Gowdradc98d812020-03-20 13:04:58 -0700662 self.log.debug("going-to-wait-for-flow-to-learn-mcast-vlan", uni_id=uni_id, tp_id=tp_id,
663 retry=retry_count)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800664 reactor.callLater(0.5, self.start_multicast_service, uni_id, tp_path, retry_count)
665 else:
Girish Gowdradc98d812020-03-20 13:04:58 -0700666 self.log.error("mcast-vlan-not-configured-yet-failing-mcast-service-conf", uni_id=uni_id, tp_id=tp_id,
667 retry=retry_count)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530668
669 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
670 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800671 tp_table_id = self.extract_tp_id_from_path(tp_path)
Naga Manjunathe433c712020-01-02 17:27:20 +0530672 if not uni_id in self._tech_profile_download_done:
673 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
674 return
675
Mahir Gunyele9110a32020-02-20 14:56:50 -0800676 if not tp_table_id in self._tech_profile_download_done[uni_id]:
677 self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id)
Naga Manjunathe433c712020-01-02 17:27:20 +0530678 return
679
Mahir Gunyele9110a32020-02-20 14:56:50 -0800680 if self._tech_profile_download_done[uni_id][tp_table_id] is not True:
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800681 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete", uni_id=uni_id,
682 tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530683 return
684
685 if alloc_id is None and gem_port_id is None:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800686 self.log.error("alloc-id-and-gem-port-id-are-none", uni_id=uni_id, tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530687 return
688
689 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
690 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
691 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
692 # this initializer
693 tcont = None
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500694 self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530695 for tc in list(self.pon_port.tconts.values()):
696 if tc.alloc_id == alloc_id:
697 tcont = tc
698 self.pon_port.remove_tcont(tc.alloc_id, False)
699
700 gem_port = None
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500701 self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530702 for gp in list(self.pon_port.gem_ports.values()):
703 if gp.gem_id == gem_port_id:
704 gem_port = gp
705 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
706
Girish Gowdrae933cd32019-11-21 21:04:41 +0530707 @inlineCallbacks
708 def success(_results):
709 if gem_port_id:
710 self.log.info("gem-port-delete-done-successfully")
711 if alloc_id:
712 self.log.info("tcont-delete-done-successfully")
713 # The deletion of TCONT marks the complete deletion of tech-profile
714 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800715 del self._tech_profile_download_done[uni_id][tp_table_id]
Girish Gowdradc98d812020-03-20 13:04:58 -0700716 self.log.debug("tp-profile-download-flag-cleared", uni_id=uni_id, tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530717 del self._tp_service_specific_task[uni_id][tp_path]
Girish Gowdradc98d812020-03-20 13:04:58 -0700718 self.log.debug("tp-service-specific-task-cleared", uni_id=uni_id, tp_id=tp_table_id)
719 del self._pending_delete_tp[uni_id][tp_table_id]
720 self.log.debug("pending-delete-tp-task-flag-cleared", uni_id=uni_id, tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530721 except Exception as ex:
722 self.log.error("del-tp-state-info", e=ex)
723
724 # TODO: There could be multiple TP on the UNI, and also the ONU.
725 # TODO: But the below reason updates for the whole device.
726 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
727
728 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530729 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530730 self.log.warn('tech-profile-delete-failure-retrying',
731 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500732 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
733 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500734 yield self.core_proxy.device_reason_update(self.device_id,
735 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530736
737 self.log.info('deleting-tech-profile-configuration')
738
Girish Gowdraa73ee452019-12-20 18:52:17 +0530739 if tcont is None and gem_port is None:
740 if alloc_id is not None:
741 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
742 if gem_port_id is not None:
743 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
744 return
745
Girish Gowdrae933cd32019-11-21 21:04:41 +0530746 self._tp_service_specific_task[uni_id][tp_path] = \
747 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
748 tcont=tcont, gem_port=gem_port)
749 self._deferred = \
750 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
751 self._deferred.addCallbacks(success, failure)
752 except Exception as e:
753 self.log.exception("failed-to-delete-tp",
754 e=e, uni_id=uni_id, tp_path=tp_path,
755 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500756
757 def update_pm_config(self, device, pm_config):
758 # TODO: This has not been tested
759 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500760 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500761
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800762 def remove_onu_flows(self, device, flows):
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500763 self.log.debug('remove-onu-flows')
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800764
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800765 # no point in removing omci flows if the device isnt reachable
766 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800767 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800768 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
769 admin=device.admin_state, connect=device.connect_status)
770 return
771
772 for flow in flows:
773 # if incoming flow contains cookie, then remove from ONU
774 if flow.cookie:
775 self.log.debug("remove-flow", device_id=device.id, flow=flow)
776
777 def is_downstream(port):
778 return port == self._pon_port_number
779
780 def is_upstream(port):
781 return not is_downstream(port)
782
783 try:
784 _in_port = fd.get_in_port(flow)
785 assert _in_port is not None
786
787 _out_port = fd.get_out_port(flow) # may be None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800788
789 if is_downstream(_in_port):
790 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
791 device_id=device.id)
792 # extended vlan tagging operation will handle it
793 continue
794 elif is_upstream(_in_port):
795 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
796 if fd.is_dhcp_flow(flow):
797 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
798 return
799
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800800 _vlan_vid = 0
801 # Retrieve the VLAN_VID that needs to be removed from the EVTO rule on the ONU.
802 for action in fd.get_actions(flow):
803 if action.type == fd.SET_FIELD:
804 _field = action.set_field.field.ofb_field
805 assert (action.set_field.field.oxm_class ==
806 OFPXMC_OPENFLOW_BASIC)
807 if _field.type == fd.VLAN_VID:
808 _vlan_vid = _field.vlan_vid & 0xfff
809 self.log.debug('vlan-vid-to-remove',
810 _vlan_vid=_vlan_vid, in_port=_in_port)
811
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800812 uni_port = self.uni_port(_in_port)
813 uni_id = _in_port & 0xF
814 else:
815 raise Exception('port should be 1 or 2 by our convention')
816
817 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
818
819 tp_id = self.get_tp_id_in_flow(flow)
Girish Gowdradc98d812020-03-20 13:04:58 -0700820 # The vlan filter remove should be followed by a TP deleted for that TP ID.
821 # Use this information to re-schedule any vlan filter add tasks for the same TP ID again.
822 # First check if the TP download was done, before we access that TP delete is necessary
823 if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and \
824 self._tech_profile_download_done[uni_id][tp_id] is True:
825 if uni_id not in self._pending_delete_tp:
826 self._pending_delete_tp[uni_id] = dict()
827 self._pending_delete_tp[uni_id][tp_id] = True
828 else:
829 self._pending_delete_tp[uni_id][tp_id] = True
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800830 # Deleting flow from ONU.
831 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800832 match_vlan=_vlan_vid, tp_id=tp_id)
Girish Gowdradc98d812020-03-20 13:04:58 -0700833
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800834 # TODO:Delete TD task.
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800835 except Exception as e:
836 self.log.exception('failed-to-remove-flow', e=e)
837
838 def add_onu_flows(self, device, flows):
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500839 self.log.debug('add-onu-flows')
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800840
841 # no point in pushing omci flows if the device isnt reachable
842 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800843 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800844 self.log.warn("device-disabled-or-offline-skipping-flow-update",
845 admin=device.admin_state, connect=device.connect_status)
846 return
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800847
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800848 def is_downstream(port):
849 return port == self._pon_port_number
850
851 def is_upstream(port):
852 return not is_downstream(port)
853
854 for flow in flows:
855 # if incoming flow contains cookie, then add to ONU
856 if flow.cookie:
857 _type = None
858 _port = None
859 _vlan_vid = None
860 _udp_dst = None
861 _udp_src = None
862 _ipv4_dst = None
863 _ipv4_src = None
864 _metadata = None
865 _output = None
866 _push_tpid = None
867 _field = None
868 _set_vlan_vid = None
869 _set_vlan_pcp = 0
870 _tunnel_id = None
871 self.log.debug("add-flow", device_id=device.id, flow=flow)
872
873 try:
874 _in_port = fd.get_in_port(flow)
875 assert _in_port is not None
876
877 _out_port = fd.get_out_port(flow) # may be None
878 tp_id = self.get_tp_id_in_flow(flow)
879 if is_downstream(_in_port):
880 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
881 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
882 # uni_port = self.uni_port(_out_port)
883 # uni_id = _out_port & 0xF
884 continue
885 elif is_upstream(_in_port):
886 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
887 uni_port = self.uni_port(_in_port)
888 uni_id = _in_port & 0xF
889 else:
890 raise Exception('port should be 1 or 2 by our convention')
891
892 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
893
894 for field in fd.get_ofb_fields(flow):
895 if field.type == fd.ETH_TYPE:
896 _type = field.eth_type
897 self.log.debug('field-type-eth-type',
898 eth_type=_type)
899
900 elif field.type == fd.IP_PROTO:
901 _proto = field.ip_proto
902 self.log.debug('field-type-ip-proto',
903 ip_proto=_proto)
904
905 elif field.type == fd.IN_PORT:
906 _port = field.port
907 self.log.debug('field-type-in-port',
908 in_port=_port)
909 elif field.type == fd.TUNNEL_ID:
910 self.log.debug('field-type-tunnel-id')
911
912 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100913 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
914 _vlan_vid = RESERVED_TRANSPARENT_VLAN
915 else:
916 _vlan_vid = field.vlan_vid & 0xfff
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800917 self.log.debug('field-type-vlan-vid',
918 vlan=_vlan_vid)
919
920 elif field.type == fd.VLAN_PCP:
921 _vlan_pcp = field.vlan_pcp
922 self.log.debug('field-type-vlan-pcp',
923 pcp=_vlan_pcp)
924
925 elif field.type == fd.UDP_DST:
926 _udp_dst = field.udp_dst
927 self.log.debug('field-type-udp-dst',
928 udp_dst=_udp_dst)
929
930 elif field.type == fd.UDP_SRC:
931 _udp_src = field.udp_src
932 self.log.debug('field-type-udp-src',
933 udp_src=_udp_src)
934
935 elif field.type == fd.IPV4_DST:
936 _ipv4_dst = field.ipv4_dst
937 self.log.debug('field-type-ipv4-dst',
938 ipv4_dst=_ipv4_dst)
939
940 elif field.type == fd.IPV4_SRC:
941 _ipv4_src = field.ipv4_src
942 self.log.debug('field-type-ipv4-src',
943 ipv4_dst=_ipv4_src)
944
945 elif field.type == fd.METADATA:
946 _metadata = field.table_metadata
947 self.log.debug('field-type-metadata',
948 metadata=_metadata)
949
950 else:
951 raise NotImplementedError('field.type={}'.format(
952 field.type))
953
954 for action in fd.get_actions(flow):
955
956 if action.type == fd.OUTPUT:
957 _output = action.output.port
958 self.log.debug('action-type-output',
959 output=_output, in_port=_in_port)
960
961 elif action.type == fd.POP_VLAN:
962 self.log.debug('action-type-pop-vlan',
963 in_port=_in_port)
964
965 elif action.type == fd.PUSH_VLAN:
966 _push_tpid = action.push.ethertype
967 self.log.debug('action-type-push-vlan',
968 push_tpid=_push_tpid, in_port=_in_port)
969 if action.push.ethertype != 0x8100:
970 self.log.error('unhandled-tpid',
971 ethertype=action.push.ethertype)
972
973 elif action.type == fd.SET_FIELD:
974 _field = action.set_field.field.ofb_field
975 assert (action.set_field.field.oxm_class ==
976 OFPXMC_OPENFLOW_BASIC)
977 self.log.debug('action-type-set-field',
978 field=_field, in_port=_in_port)
979 if _field.type == fd.VLAN_VID:
980 _set_vlan_vid = _field.vlan_vid & 0xfff
981 self.log.debug('set-field-type-vlan-vid',
982 vlan_vid=_set_vlan_vid)
983 elif _field.type == fd.VLAN_PCP:
984 _set_vlan_pcp = _field.vlan_pcp
985 self.log.debug('set-field-type-vlan-pcp',
986 vlan_pcp=_set_vlan_pcp)
987 else:
988 self.log.error('unsupported-action-set-field-type',
989 field_type=_field.type)
990 else:
991 self.log.error('unsupported-action-type',
992 action_type=action.type, in_port=_in_port)
993
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800994 if self._set_vlan is not None:
995 if uni_id not in self._set_vlan:
996 self._set_vlan[uni_id] = dict()
997 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
998 self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
999
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001000 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1001 # supported match and action criteria cannot be handled by omci and must be ignored.
1002 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
1003 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
1004 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
1005 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001006 _set_vlan_vid=_vlan_vid,
1007 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1008 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001009 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1010 _set_vlan_vid=_vlan_vid,
1011 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1012 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001013 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001014 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
1015 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001016 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1017 _set_vlan_vid=_set_vlan_vid,
1018 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1019 tp_id=tp_id)
1020
1021 except Exception as e:
1022 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1023
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001024 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
1025 # flow decomposition that ultimately comes from onos
1026 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001027 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001028
1029 #
1030 # We need to proxy through the OLT to get to the ONU
1031 # Configuration from here should be using OMCI
1032 #
1033 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
1034
1035 # no point in pushing omci flows if the device isnt reachable
1036 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +05301037 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001038 self.log.warn("device-disabled-or-offline-skipping-flow-update",
1039 admin=device.admin_state, connect=device.connect_status)
1040 return
1041
1042 def is_downstream(port):
1043 return port == self._pon_port_number
1044
1045 def is_upstream(port):
1046 return not is_downstream(port)
1047
1048 for flow in flows:
1049 _type = None
1050 _port = None
1051 _vlan_vid = None
1052 _udp_dst = None
1053 _udp_src = None
1054 _ipv4_dst = None
1055 _ipv4_src = None
1056 _metadata = None
1057 _output = None
1058 _push_tpid = None
1059 _field = None
1060 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001061 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001062 _tunnel_id = None
1063
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001064 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +05301065 write_metadata = fd.get_write_metadata(flow)
1066 if write_metadata is None:
1067 self.log.error("do-not-process-flow-without-write-metadata")
1068 return
1069
1070 # extract tp id from flow
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001071 tp_id = self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001072 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +05301073
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001074 _in_port = fd.get_in_port(flow)
1075 assert _in_port is not None
1076
1077 _out_port = fd.get_out_port(flow) # may be None
1078
1079 if is_downstream(_in_port):
1080 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
1081 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301082 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001083 elif is_upstream(_in_port):
1084 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
1085 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001086 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001087 else:
1088 raise Exception('port should be 1 or 2 by our convention')
1089
1090 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
1091
1092 for field in fd.get_ofb_fields(flow):
1093 if field.type == fd.ETH_TYPE:
1094 _type = field.eth_type
1095 self.log.debug('field-type-eth-type',
1096 eth_type=_type)
1097
1098 elif field.type == fd.IP_PROTO:
1099 _proto = field.ip_proto
1100 self.log.debug('field-type-ip-proto',
1101 ip_proto=_proto)
1102
1103 elif field.type == fd.IN_PORT:
1104 _port = field.port
1105 self.log.debug('field-type-in-port',
1106 in_port=_port)
1107
1108 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001109 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
1110 _vlan_vid = RESERVED_TRANSPARENT_VLAN
1111 else:
1112 _vlan_vid = field.vlan_vid & 0xfff
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001113 self.log.debug('field-type-vlan-vid',
1114 vlan=_vlan_vid)
1115
1116 elif field.type == fd.VLAN_PCP:
1117 _vlan_pcp = field.vlan_pcp
1118 self.log.debug('field-type-vlan-pcp',
1119 pcp=_vlan_pcp)
1120
1121 elif field.type == fd.UDP_DST:
1122 _udp_dst = field.udp_dst
1123 self.log.debug('field-type-udp-dst',
1124 udp_dst=_udp_dst)
1125
1126 elif field.type == fd.UDP_SRC:
1127 _udp_src = field.udp_src
1128 self.log.debug('field-type-udp-src',
1129 udp_src=_udp_src)
1130
1131 elif field.type == fd.IPV4_DST:
1132 _ipv4_dst = field.ipv4_dst
1133 self.log.debug('field-type-ipv4-dst',
1134 ipv4_dst=_ipv4_dst)
1135
1136 elif field.type == fd.IPV4_SRC:
1137 _ipv4_src = field.ipv4_src
1138 self.log.debug('field-type-ipv4-src',
1139 ipv4_dst=_ipv4_src)
1140
1141 elif field.type == fd.METADATA:
1142 _metadata = field.table_metadata
1143 self.log.debug('field-type-metadata',
1144 metadata=_metadata)
1145
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001146 elif field.type == fd.TUNNEL_ID:
1147 _tunnel_id = field.tunnel_id
1148 self.log.debug('field-type-tunnel-id',
1149 tunnel_id=_tunnel_id)
1150
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001151
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001152 else:
1153 raise NotImplementedError('field.type={}'.format(
1154 field.type))
1155
1156 for action in fd.get_actions(flow):
1157
1158 if action.type == fd.OUTPUT:
1159 _output = action.output.port
1160 self.log.debug('action-type-output',
1161 output=_output, in_port=_in_port)
1162
1163 elif action.type == fd.POP_VLAN:
1164 self.log.debug('action-type-pop-vlan',
1165 in_port=_in_port)
1166
1167 elif action.type == fd.PUSH_VLAN:
1168 _push_tpid = action.push.ethertype
1169 self.log.debug('action-type-push-vlan',
1170 push_tpid=_push_tpid, in_port=_in_port)
1171 if action.push.ethertype != 0x8100:
1172 self.log.error('unhandled-tpid',
1173 ethertype=action.push.ethertype)
1174
1175 elif action.type == fd.SET_FIELD:
1176 _field = action.set_field.field.ofb_field
1177 assert (action.set_field.field.oxm_class ==
1178 OFPXMC_OPENFLOW_BASIC)
1179 self.log.debug('action-type-set-field',
1180 field=_field, in_port=_in_port)
1181 if _field.type == fd.VLAN_VID:
1182 _set_vlan_vid = _field.vlan_vid & 0xfff
1183 self.log.debug('set-field-type-vlan-vid',
1184 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001185 elif _field.type == fd.VLAN_PCP:
1186 _set_vlan_pcp = _field.vlan_pcp
1187 self.log.debug('set-field-type-vlan-pcp',
1188 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001189 else:
1190 self.log.error('unsupported-action-set-field-type',
1191 field_type=_field.type)
1192 else:
1193 self.log.error('unsupported-action-type',
1194 action_type=action.type, in_port=_in_port)
1195
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001196 if self._set_vlan is not None:
1197 if uni_id not in self._set_vlan:
1198 self._set_vlan[uni_id] = dict()
1199 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
1200 self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
Matt Jeanneret810148b2019-09-29 12:44:01 -04001201 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1202 # supported match and action criteria cannot be handled by omci and must be ignored.
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001203 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
1204 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
1205 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
1206 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001207 _set_vlan_vid=_vlan_vid,
1208 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1209 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001210 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1211 _set_vlan_vid=_vlan_vid,
1212 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1213 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001214 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001215 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
1216 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
1217 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1218 _set_vlan_vid=_set_vlan_vid,
1219 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1220 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001221 except Exception as e:
1222 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1223
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001224 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001225 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
Girish Gowdradc98d812020-03-20 13:04:58 -07001226 if uni_id in self._pending_delete_tp and tp_id in self._pending_delete_tp[uni_id] and \
1227 self._pending_delete_tp[uni_id][tp_id] is True:
1228 self.log.debug("pending-del-tp--scheduling-add-vlan-filter-task-for-later")
1229 reactor.callLater(0.2, self._add_vlan_filter_task, device, uni_id, uni_port, match_vlan,
1230 _set_vlan_vid, _set_vlan_pcp, tp_id)
1231 return
1232
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001233 self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1234 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001235 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001236 if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and \
1237 self._tech_profile_download_done[uni_id][tp_id] is True:
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001238 @inlineCallbacks
1239 def success(_results):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001240 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id,
1241 set_vlan_pcp=_set_vlan_pcp)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001242 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001243
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001244 @inlineCallbacks
1245 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301246 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001247 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1248 reactor.callLater(retry,
1249 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1250 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1251 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001252 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001253
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001254 self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1255 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001256 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001257 match_vlan, _set_vlan_pcp, add_tag=True,
1258 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001259 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001260 self._deferred.addCallbacks(success, failure)
1261 else:
1262 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001263 uni_id=uni_id, tp_id=tp_id)
1264 if uni_id not in self._queued_vlan_filter_task:
1265 self._queued_vlan_filter_task[uni_id] = dict()
Mahir Gunyela982ec32020-02-25 12:30:37 -08001266 if tp_id not in self._queued_vlan_filter_task[uni_id]:
1267 self._queued_vlan_filter_task[uni_id][tp_id] = []
1268 self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001269 "uni_id": uni_id,
1270 "uni_port": uni_port,
1271 "match_vlan": match_vlan,
1272 "set_vlan_vid": _set_vlan_vid,
1273 "set_vlan_pcp": _set_vlan_pcp,
1274 "tp_id": tp_id})
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001275
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001276 def get_tp_id_in_flow(self, flow):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001277 flow_metadata = fd.get_metadata_from_write_metadata(flow)
1278 tp_id = fd.get_tp_id_from_metadata(flow_metadata)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001279 return tp_id
1280
1281 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001282 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001283 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001284
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001285 @inlineCallbacks
1286 def success(_results):
1287 self.log.info('vlan-untagging-success', _results=_results)
1288 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1289
1290 @inlineCallbacks
1291 def failure(_reason):
1292 self.log.warn('vlan-untagging-failure', _reason=_reason)
1293 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001294 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001295 reactor.callLater(retry,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001296 self._remove_vlan_filter_task, device, uni_id,
1297 add_tag=False, uni_port=uni_port)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001298
1299 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1300 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001301 match_vlan, _set_vlan_pcp, add_tag=False,
1302 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001303 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1304 self._deferred.addCallbacks(success, failure)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001305
Matt Jeannereta32441c2019-03-07 05:16:37 -05001306 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001307 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1308 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeanneret2101f3d2020-03-12 10:13:06 -04001309
1310 if not self.enabled:
1311 self.log.warn('device-not-activated')
1312 reactor.callLater(0.5, self.process_inter_adapter_message, request)
1313 return
1314
Matt Jeannereta32441c2019-03-07 05:16:37 -05001315 try:
1316 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1317 omci_msg = InterAdapterOmciMessage()
1318 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001319 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001320
Matt Jeannereta32441c2019-03-07 05:16:37 -05001321 self.receive_message(omci_msg.message)
1322
1323 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1324 onu_indication = OnuIndication()
1325 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001326 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1327 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1328 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001329
1330 if onu_indication.oper_state == "up":
1331 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301332 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001333 self.update_interface(onu_indication)
1334 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001335 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1336 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001337
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001338 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1339 tech_msg = InterAdapterTechProfileDownloadMessage()
1340 request.body.Unpack(tech_msg)
1341 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1342
1343 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1344
Girish Gowdrae933cd32019-11-21 21:04:41 +05301345 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1346 del_gem_msg = InterAdapterDeleteGemPortMessage()
1347 request.body.Unpack(del_gem_msg)
1348 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1349
1350 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1351 gem_port_id=del_gem_msg.gem_port_id,
1352 tp_path=del_gem_msg.tp_path)
1353
1354 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1355 del_tcont_msg = InterAdapterDeleteTcontMessage()
1356 request.body.Unpack(del_tcont_msg)
1357 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1358
1359 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1360 alloc_id=del_tcont_msg.alloc_id,
1361 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001362 else:
1363 self.log.error("inter-adapter-unhandled-type", request=request)
1364
1365 except Exception as e:
1366 self.log.exception("error-processing-inter-adapter-message", e=e)
1367
1368 # Called each time there is an onu "up" indication from the olt handler
1369 @inlineCallbacks
1370 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001371 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001372 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001373
1374 # Ignore if onu_indication is received for an already running ONU
1375 if self._onu_omci_device is not None and self._onu_omci_device.active:
1376 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1377 return
1378
Matt Jeannereta32441c2019-03-07 05:16:37 -05001379 self._onu_indication = onu_indication
1380
Matt Jeanneretc083f462019-03-11 15:02:01 -04001381 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1382 connect_status=ConnectStatus.REACHABLE)
1383
Matt Jeannereta32441c2019-03-07 05:16:37 -05001384 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001385
1386 self.log.debug('starting-openomci-statemachine')
1387 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001388 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301389 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001390 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001391 self._heartbeat.enabled = True
1392
Matt Jeanneret42dad792020-02-01 09:28:27 -05001393 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001394 @inlineCallbacks
1395 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001396 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001397 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001398
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001399 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001400 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001401 reactor.callLater(0, self._onu_omci_device.stop)
1402
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001403 self._tp = dict()
1404
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001405 # Let TP download happen again
1406 for uni_id in self._tp_service_specific_task:
1407 self._tp_service_specific_task[uni_id].clear()
1408 for uni_id in self._tech_profile_download_done:
1409 self._tech_profile_download_done[uni_id].clear()
1410
Matt Jeanneretf4113222019-08-14 19:44:34 -04001411 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001412 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1413 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1414 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001415 else:
1416 self.log.debug('not-changing-openomci-statemachine')
1417
Matt Jeanneretf4113222019-08-14 19:44:34 -04001418 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001419 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001420 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001421 try:
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001422 yield self.disable_ports(lock_ports=True, device_disabled=True)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001423 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1424 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001425 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001426 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001427
William Kurkian3a206332019-04-29 11:05:47 -04001428 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001429 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001430 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001431 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001432 yield self.core_proxy.device_state_update(device.id,
1433 oper_status=OperStatus.ACTIVE,
1434 connect_status=ConnectStatus.REACHABLE)
1435 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1436 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001437 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001438 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001439
William Kurkian3a206332019-04-29 11:05:47 -04001440 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001441 def reboot(self):
1442 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001443 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001444 if device.connect_status != ConnectStatus.REACHABLE:
1445 self.log.error("device-unreachable")
1446 return
1447
William Kurkian3a206332019-04-29 11:05:47 -04001448 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001449 def success(_results):
1450 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001451 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001452
1453 def failure(_reason):
1454 self.log.info('reboot-failure', _reason=_reason)
1455
1456 self._deferred = self._onu_omci_device.reboot()
1457 self._deferred.addCallbacks(success, failure)
1458
William Kurkian3a206332019-04-29 11:05:47 -04001459 @inlineCallbacks
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001460 def disable_ports(self, lock_ports=True, device_disabled=False):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001461 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001462
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001463 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1464 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001465 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001466 if port.mac_bridge_port_num == 1:
1467 port.operstatus = OperStatus.UNKNOWN
1468 self.log.info('disable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001469 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1470 port.operstatus)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001471
1472 if lock_ports is True:
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001473 self.lock_ports(lock=True, device_disabled=device_disabled)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001474
William Kurkian3a206332019-04-29 11:05:47 -04001475 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001476 def enable_ports(self):
1477 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001478
Matt Jeanneretf4113222019-08-14 19:44:34 -04001479 self.lock_ports(lock=False)
1480
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001481 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1482 # load on the core
1483 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001484 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001485 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001486 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001487 self.log.info('enable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001488 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1489 port.operstatus)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001490
1491 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1492 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1493 #
1494 # Basically the link state sequence:
1495 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1496 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1497 # 3) a link state up alarm is received for the uni plugged in.
1498 #
1499 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1500 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1501 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1502 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001503 @inlineCallbacks
1504 def port_state_handler(self, _topic, msg):
1505 self.log.info("port-state-change", _topic=_topic, msg=msg)
1506
1507 onu_id = msg['onu_id']
1508 port_no = msg['port_number']
1509 serial_number = msg['serial_number']
1510 port_status = msg['port_status']
1511 uni_port = self.uni_port(int(port_no))
1512
1513 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1514 port_status=port_status)
1515
1516 if port_status is True:
1517 uni_port.operstatus = OperStatus.ACTIVE
1518 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1519 else:
1520 uni_port.operstatus = OperStatus.UNKNOWN
1521 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1522
1523 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 -05001524 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001525
1526 # Called just before openomci state machine is started. These listen for events from selected state machines,
1527 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1528 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001529 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001530
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001531 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001532
1533 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001534 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1535 OnuDeviceEvents.MibDatabaseSyncEvent)
1536 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1537
1538 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001539 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1540 OnuDeviceEvents.OmciCapabilitiesEvent)
1541 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1542
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001543 # TODO: these alarms seem to be unreliable depending on the environment
1544 # Listen for UNI link state alarms and set the oper_state based on that rather than assuming all UNI are up
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001545 # topic = OnuDeviceEntry.event_bus_topic(self.device_id,
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001546 # OnuDeviceEvents.PortEvent)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001547 # self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001548
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001549 # Called when the mib is in sync
1550 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001551 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001552 if self._in_sync_subscription is not None:
1553 try:
1554 in_sync = msg[IN_SYNC_KEY]
1555
1556 if in_sync:
1557 # Only call this once
1558 bus = self._onu_omci_device.event_bus
1559 bus.unsubscribe(self._in_sync_subscription)
1560 self._in_sync_subscription = None
1561
1562 # Start up device_info load
1563 self.log.debug('running-mib-sync')
1564 reactor.callLater(0, self._mib_in_sync)
1565
1566 except Exception as e:
1567 self.log.exception('in-sync', e=e)
1568
1569 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001570 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001571 if self._capabilities_subscription is not None:
1572 self.log.debug('capabilities-handler-done')
1573
1574 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1575 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1576 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001577 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001578 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001579 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001580
1581 omci = self._onu_omci_device
1582 in_sync = omci.mib_db_in_sync
1583
Matt Jeanneretc083f462019-03-11 15:02:01 -04001584 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001585 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001586
1587 if not self._dev_info_loaded:
1588 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1589
1590 omci_dev = self._onu_omci_device
1591 config = omci_dev.configuration
1592
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001593 try:
1594
1595 # sort the lists so we get consistent port ordering.
1596 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1597 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1598 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1599 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1600
1601 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001602 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001603 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001604 raise Exception("onu-missing-required-elements")
1605
1606 # Currently logging the ani, pptp, veip, and uni for information purposes.
1607 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1608 # And in some ONU the UNI-G list is incomplete or incorrect...
1609 for entity_id in ani_list:
1610 ani_value = config.ani_g_entities[entity_id]
1611 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1612 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1613 self._total_tcont_count = ani_value.get('total-tcont-count')
1614 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1615
1616 for entity_id in uni_list:
1617 uni_value = config.uni_g_entities[entity_id]
1618 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1619
1620 uni_entities = OrderedDict()
1621 for entity_id in pptp_list:
1622 pptp_value = config.pptp_entities[entity_id]
1623 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1624 uni_entities[entity_id] = UniType.PPTP
1625
1626 for entity_id in veip_list:
1627 veip_value = config.veip_entities[entity_id]
1628 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1629 uni_entities[entity_id] = UniType.VEIP
1630
1631 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001632 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001633 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001634 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001635 uni_id += 1
1636 except AssertionError as e:
1637 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1638
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001639 self._qos_flexibility = config.qos_configuration_flexibility or 0
1640 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1641
1642 if self._unis:
1643 self._dev_info_loaded = True
1644 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001645 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001646 self.log.warn("no-usable-unis")
1647 raise Exception("no-usable-unis")
1648
1649 except Exception as e:
1650 self.log.exception('device-info-load', e=e)
1651 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1652
1653 else:
1654 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1655
1656 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001657 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001658
1659 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001660 def success(_results):
1661 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001662 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301663 oper_status=OperStatus.ACTIVE,
1664 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001665 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001666 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001667 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001668 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001669
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001670 # Start collecting stats from the device after a brief pause
1671 if not self._pm_metrics_started:
1672 self._pm_metrics_started = True
1673 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1674 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1675
1676 # Start test requests after a brief pause
1677 if not self._test_request_started:
1678 self._test_request_started = True
1679 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1680 reactor.callLater(tststart, self._test_request.start_collector)
1681
Matt Jeanneretc083f462019-03-11 15:02:01 -04001682 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001683 def failure(_reason):
1684 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001685 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001686 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001687 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001688
Matt Jeanneretf4113222019-08-14 19:44:34 -04001689 # start by locking all the unis till mib sync and initial mib is downloaded
1690 # this way we can capture the port down/up events when we are ready
1691 self.lock_ports(lock=True)
1692
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001693 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1694 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1695 self.log.info('downloading-initial-mib-configuration')
1696 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1697 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1698 self._deferred.addCallbacks(success, failure)
1699 else:
1700 self.log.info('admin-down-disabling')
1701 self.disable(device)
1702 else:
1703 self.log.info('device-info-not-loaded-skipping-mib-download')
1704
Matt Jeanneretc083f462019-03-11 15:02:01 -04001705 @inlineCallbacks
1706 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001707 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001708
Matt Jeanneretc083f462019-03-11 15:02:01 -04001709 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 -05001710
1711 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1712 uni_name = "uni-{}".format(uni_no)
1713
Girish Gowdrae933cd32019-11-21 21:04:41 +05301714 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001715
1716 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 -04001717 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001718
1719 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1720 uni_port.entity_id = entity_id
1721 uni_port.enabled = True
1722 uni_port.mac_bridge_port_num = mac_bridge_port_num
1723
1724 self.log.debug("created-uni-port", uni=uni_port)
1725
Matt Jeanneretc083f462019-03-11 15:02:01 -04001726 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001727
1728 self._unis[uni_port.port_number] = uni_port
1729
1730 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301731 uni_ports=self.uni_ports,
1732 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001733
Matt Jeanneretc083f462019-03-11 15:02:01 -04001734 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1735 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001736 MAX_PONS_PER_OLT = 256
1737 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001738 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001739
Matt Jeanneretc083f462019-03-11 15:02:01 -04001740 assert intf_id < MAX_PONS_PER_OLT
1741 assert onu_id < MAX_ONUS_PER_PON
1742 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001743 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001744
1745 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001746 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001747 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001748 try:
1749 device = yield self.core_proxy.get_device(self.device_id)
1750 parent_device = yield self.core_proxy.get_device(self.parent_id)
1751 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001752 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001753
1754 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301755 pon_id=self._onu_indication.intf_id,
1756 onu_id=self._onu_indication.onu_id,
1757 registration_id=self.device_id,
1758 device_id=self.device_id,
1759 onu_serial_number=device.serial_number,
1760 olt_serial_number=olt_serial_number,
1761 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001762
Devmalya Paulffc89df2019-07-31 17:43:13 -04001763 self.log.debug("Trying-to-raise-onu-active-event")
1764 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001765 self._onu_indication.intf_id,
1766 device.serial_number,
1767 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301768 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001769 onu_id=self._onu_indication.onu_id).send(True)
1770 except Exception as active_event_error:
1771 self.log.exception('onu-activated-event-error',
1772 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001773
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001774 @inlineCallbacks
1775 def onu_disabled_event(self):
1776 self.log.debug('onu-disabled-event')
1777 try:
1778 device = yield self.core_proxy.get_device(self.device_id)
1779 parent_device = yield self.core_proxy.get_device(self.parent_id)
1780 olt_serial_number = parent_device.serial_number
1781 raised_ts = arrow.utcnow().timestamp
1782
1783 self.log.debug("onu-indication-context-data",
1784 pon_id=self._onu_indication.intf_id,
1785 onu_id=self._onu_indication.onu_id,
1786 registration_id=self.device_id,
1787 device_id=self.device_id,
1788 onu_serial_number=device.serial_number,
1789 olt_serial_number=olt_serial_number,
1790 raised_ts=raised_ts)
1791
1792 self.log.debug("Trying-to-raise-onu-disabled-event")
1793 OnuDisabledEvent(self.events, self.device_id,
Girish Gowdradc98d812020-03-20 13:04:58 -07001794 self._onu_indication.intf_id,
1795 device.serial_number,
1796 str(self.device_id),
1797 olt_serial_number, raised_ts,
1798 onu_id=self._onu_indication.onu_id).send(True)
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001799 except Exception as active_event_error:
1800 self.log.exception('onu-disabled-event-error',
1801 errmsg=active_event_error.message)
1802
1803 def lock_ports(self, lock=True, device_disabled=False):
Matt Jeanneretf4113222019-08-14 19:44:34 -04001804
1805 def success(response):
1806 self.log.debug('set-onu-ports-state', lock=lock, response=response)
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001807 if device_disabled:
1808 self.onu_disabled_event()
Matt Jeanneretf4113222019-08-14 19:44:34 -04001809
1810 def failure(response):
1811 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1812
1813 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1814 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1815 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001816
1817 def extract_tp_id_from_path(self, tp_path):
1818 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001819 tp_id = int(tp_path.split(_PATH_SEPERATOR)[1])
1820 return tp_id
onkarkundargia1e2af22020-01-27 11:51:43 +05301821
1822 def start_omci_test_action(self, device, uuid):
1823 """
1824
1825 :param device:
1826 :return:
1827 """
1828 # Code to Run OMCI Test Action
1829 self.log.info('Omci-test-action-request-On', request=device.id)
1830 kwargs_omci_test_action = {
1831 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
1832 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
1833 }
1834 serial_number = device.serial_number
1835 if device.connect_status != ConnectStatus.REACHABLE or device.admin_state != AdminState.ENABLED:
1836 return (TestResponse(result=TestResponse.FAILURE))
1837 test_request = OmciTestRequest(self.core_proxy,
1838 self.omci_agent, self.device_id, AniG,
1839 serial_number,
1840 self.logical_device_id, exclusive=False,
1841 uuid=uuid,
1842 **kwargs_omci_test_action)
1843 test_request.perform_test_omci()
1844 return (TestResponse(result=TestResponse.SUCCESS))