blob: b5789aa1e8056aeced13d9a79713b84f010f50f1 [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
2# Copyright 2017 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17"""
18Broadcom OpenOMCI OLT/ONU adapter handler.
19"""
20
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050021from __future__ import absolute_import
22import six
Devmalya Paulffc89df2019-07-31 17:43:13 -040023import arrow
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050024import structlog
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050025import json
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050026import random
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050027
28from collections import OrderedDict
29
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050030from twisted.internet import reactor
31from twisted.internet.defer import DeferredQueue, inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050032
33from heartbeat import HeartBeat
Devmalya Paulffc89df2019-07-31 17:43:13 -040034from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent
35from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
36from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
37from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050038
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050039import pyvoltha.common.openflow.utils as fd
40from pyvoltha.common.utils.registry import registry
Matteo Scandolod8d73172019-11-26 12:15:15 -070041from pyvoltha.adapters.common.frameio.frameio import hexify
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050042from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050043from pyvoltha.common.config.config_backend import ConsulStore
44from pyvoltha.common.config.config_backend import EtcdStore
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050045from voltha_protos.logical_device_pb2 import LogicalPort
William Kurkian8235c1e2019-03-05 12:58:28 -050046from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretf4113222019-08-14 19:44:34 -040047from voltha_protos.device_pb2 import Port
Girish Gowdra4c11ddb2020-03-03 11:33:24 -080048from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE, OFPPS_LINK_DOWN, \
Matt Jeanneretf4113222019-08-14 19:44:34 -040049 OFPPF_FIBER, OFPPF_1GB_FD
Matt Jeanneret3bfebff2019-04-12 18:25:03 -040050from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
Girish Gowdrae933cd32019-11-21 21:04:41 +053051 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
52 InterAdapterDeleteTcontMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050053from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050054from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
55from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050056 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050057from omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdrae933cd32019-11-21 21:04:41 +053058from omci.brcm_tp_setup_task import BrcmTpSetupTask
59from omci.brcm_tp_delete_task import BrcmTpDeleteTask
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050060from omci.brcm_uni_lock_task import BrcmUniLockTask
61from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050062from onu_gem_port import OnuGemPort
63from onu_tcont import OnuTCont
64from pon_port import PonPort
Mahir Gunyel5de33fe2020-03-03 22:38:44 -080065from omci.brcm_mcast_task import BrcmMcastTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050066from uni_port import UniPort, UniType
Andrea Campanellacf916ea2020-02-14 10:03:58 +010067from uni_port import RESERVED_TRANSPARENT_VLAN
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050068from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053069from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
70from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050071from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050072
73OP = EntityOperations
74RC = ReasonCodes
75
Mahir Gunyel5de33fe2020-03-03 22:38:44 -080076IS_MULTICAST='is_multicast'
77GEM_PORT_ID = 'gemport_id'
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050078_STARTUP_RETRY_WAIT = 10
Mahir Gunyele9110a32020-02-20 14:56:50 -080079_PATH_SEPERATOR = "/"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050080
81
82class BrcmOpenomciOnuHandler(object):
83
84 def __init__(self, adapter, device_id):
85 self.log = structlog.get_logger(device_id=device_id)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050086 self.log.debug('starting-handler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050087 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050088 self.core_proxy = adapter.core_proxy
89 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050090 self.parent_id = None
91 self.device_id = device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050092 self.proxy_address = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050093 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040094 self.events = None
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050095 self._pm_metrics = None
96 self._pm_metrics_started = False
97 self._test_request = None
98 self._test_request_started = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050099 self._omcc_version = OMCCVersion.Unknown
100 self._total_tcont_count = 0 # From ANI-G ME
101 self._qos_flexibility = 0 # From ONT2_G ME
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800102 self._tp = dict() #tp_id -> technology profile definition in KV Store.
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500103 self._onu_indication = None
104 self._unis = dict() # Port # -> UniPort
105
106 self._pon = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500107 self._pon_port_number = 100
108 self.logical_device_id = None
109
110 self._heartbeat = HeartBeat.create(self, device_id)
111
112 # Set up OpenOMCI environment
113 self._onu_omci_device = None
114 self._dev_info_loaded = False
115 self._deferred = None
116
117 self._in_sync_subscription = None
Matt Jeanneretf4113222019-08-14 19:44:34 -0400118 self._port_state_subscription = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500119 self._connectivity_subscription = None
120 self._capabilities_subscription = None
121
122 self.mac_bridge_service_profile_entity_id = 0x201
123 self.gal_enet_profile_entity_id = 0x1
124
125 self._tp_service_specific_task = dict()
126 self._tech_profile_download_done = dict()
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400127 # Stores information related to queued vlan filter tasks
128 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
129
130 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500131
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800132 self._set_vlan = dict() #uni_id, tp_id -> set_vlan_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500133 # Initialize KV store client
134 self.args = registry('main').get_args()
135 if self.args.backend == 'etcd':
136 host, port = self.args.etcd.split(':', 1)
137 self.kv_client = EtcdStore(host, port,
138 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
139 elif self.args.backend == 'consul':
140 host, port = self.args.consul.split(':', 1)
141 self.kv_client = ConsulStore(host, port,
142 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
143 else:
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500144 self.log.error('invalid-backend')
145 raise Exception("invalid-backend-for-kv-store")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500146
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500147 @property
148 def enabled(self):
149 return self._enabled
150
151 @enabled.setter
152 def enabled(self, value):
153 if self._enabled != value:
154 self._enabled = value
155
156 @property
157 def omci_agent(self):
158 return self.adapter.omci_agent
159
160 @property
161 def omci_cc(self):
162 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
163
164 @property
165 def heartbeat(self):
166 return self._heartbeat
167
168 @property
169 def uni_ports(self):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500170 return list(self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500171
172 def uni_port(self, port_no_or_name):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500173 if isinstance(port_no_or_name, six.string_types):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500174 return next((uni for uni in self.uni_ports
175 if uni.name == port_no_or_name), None)
176
177 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
178 return next((uni for uni in self.uni_ports
Girish Gowdrae933cd32019-11-21 21:04:41 +0530179 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500180
181 @property
182 def pon_port(self):
183 return self._pon
184
Girish Gowdraa73ee452019-12-20 18:52:17 +0530185 @property
186 def onu_omci_device(self):
187 return self._onu_omci_device
188
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500189 def receive_message(self, msg):
190 if self.omci_cc is not None:
191 self.omci_cc.receive_message(msg)
192
Matt Jeanneretc083f462019-03-11 15:02:01 -0400193 def get_ofp_port_info(self, device, port_no):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500194 self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400195 cap = OFPPF_1GB_FD | OFPPF_FIBER
196
Girish Gowdrae933cd32019-11-21 21:04:41 +0530197 hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
198 ((device.parent_port_no >> 8 & 0xff),
199 device.parent_port_no & 0xff,
200 (port_no >> 16) & 0xff,
201 (port_no >> 8) & 0xff,
202 port_no & 0xff))
Matt Jeanneretc083f462019-03-11 15:02:01 -0400203
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400204 uni_port = self.uni_port(int(port_no))
205 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500206 self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port)
Matt Jeanneretf4113222019-08-14 19:44:34 -0400207
208 ofstate = OFPPS_LINK_DOWN
209 if uni_port.operstatus is OperStatus.ACTIVE:
210 ofstate = OFPPS_LIVE
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400211
Matt Jeanneretc083f462019-03-11 15:02:01 -0400212 return PortCapability(
213 port=LogicalPort(
214 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400215 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400216 hw_addr=hw_addr,
217 config=0,
Matt Jeanneretf4113222019-08-14 19:44:34 -0400218 state=ofstate,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400219 curr=cap,
220 advertised=cap,
221 peer=cap,
222 curr_speed=OFPPF_1GB_FD,
223 max_speed=OFPPF_1GB_FD
224 ),
225 device_id=device.id,
226 device_port_no=port_no
227 )
228 )
229
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500230 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500231 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500232 def activate(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700233 self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500234
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500235 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500236 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500237 assert device.proxy_address.device_id
238
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500239 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500240 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500241 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500242 if self.enabled is not True:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700243 self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500244 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500245 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500246 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500247 device.reason = 'activating-onu'
248
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500249 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400250 # pm_metrics requires a logical device id. For now set to just device_id
251 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500252
Matt Jeannereta32441c2019-03-07 05:16:37 -0500253 yield self.core_proxy.device_update(device)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500254 self.log.debug('device-updated', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500255
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700256 yield self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500257
Matteo Scandolod8d73172019-11-26 12:15:15 -0700258 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500259 ############################################################################
Devmalya Paulffc89df2019-07-31 17:43:13 -0400260 # Setup Alarm handler
261 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
262 device.serial_number)
263 ############################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500264 # Setup PM configuration for this device
265 # Pass in ONU specific options
266 kwargs = {
267 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
268 'heartbeat': self.heartbeat,
269 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
270 }
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500271 self.log.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500272 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800273 self.logical_device_id, device.serial_number,
274 grouped=True, freq_override=False, **kwargs)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500275 pm_config = self._pm_metrics.make_proto()
276 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530277 self.log.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500278 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500279
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500280 # Note, ONU ID and UNI intf set in add_uni_port method
Devmalya Paulffc89df2019-07-31 17:43:13 -0400281 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500282 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500283
onkarkundargiaae99712019-09-23 15:02:52 +0530284 # Code to Run OMCI Test Action
285 kwargs_omci_test_action = {
286 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
287 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
288 }
289 serial_number = device.serial_number
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500290 self._test_request = OmciTestRequest(self.core_proxy,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800291 self.omci_agent, self.device_id,
292 AniG, serial_number,
293 self.logical_device_id,
294 exclusive=False,
295 **kwargs_omci_test_action)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500296
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500297 self.enabled = True
298 else:
299 self.log.info('onu-already-activated')
300
301 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400302 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500303 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700304 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500305
306 # first we verify that we got parent reference and proxy info
307 assert device.parent_id
308 assert device.proxy_address.device_id
309
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700310 self.proxy_address = device.proxy_address
311 self.parent_id = device.parent_id
312 self._pon_port_number = device.parent_port_no
313
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500314 if self.enabled is not True:
315 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700316 self.logical_device_id = self.device_id
317 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500318
319 # need to restart state machines on vcore restart. there is no indication to do it for us.
320 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700321 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500322
323 # TODO: this is probably a bit heavy handed
324 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
325 # This may not be necessary when mib resync actually works
326 reactor.callLater(1, self.reboot)
327
328 self.enabled = True
329 else:
330 self.log.info('onu-already-activated')
331
332 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700333 def _init_pon_state(self):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500334 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 -0500335
336 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500337 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700338 self.log.debug('adding-pon-port-to-agent',
339 type=self._pon.get_port().type,
340 admin_state=self._pon.get_port().admin_state,
341 oper_status=self._pon.get_port().oper_status,
342 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500343
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700344 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500345
Matteo Scandolod8d73172019-11-26 12:15:15 -0700346 self.log.debug('added-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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500351
352 # Create and start the OpenOMCI ONU Device Entry for this ONU
353 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500354 self.core_proxy,
355 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500356 support_classes=self.adapter.broadcom_omci,
357 custom_me_map=self.adapter.custom_me_entities())
358 # Port startup
359 if self._pon is not None:
360 self._pon.enabled = True
361
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500362 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700363 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret42dad792020-02-01 09:28:27 -0500364
365 self._deferred.cancel()
366 self._test_request.stop_collector()
367 self._pm_metrics.stop_collector()
368 self.log.debug('removing-openomci-statemachine')
369 self.omci_agent.remove_device(device.id, cleanup=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500370
371 def _create_tconts(self, uni_id, us_scheduler):
372 alloc_id = us_scheduler['alloc_id']
373 q_sched_policy = us_scheduler['q_sched_policy']
374 self.log.debug('create-tcont', us_scheduler=us_scheduler)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800375 # TODO: revisit for multi tconts support
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800376 new_tconts = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500377 tcontdict = dict()
378 tcontdict['alloc-id'] = alloc_id
379 tcontdict['q_sched_policy'] = q_sched_policy
380 tcontdict['uni_id'] = uni_id
381
Matt Jeanneret3789d0d2020-01-19 09:03:42 -0500382 tcont = OnuTCont.create(self, tcont=tcontdict)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500383
384 self._pon.add_tcont(tcont)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800385 new_tconts.append(tcont)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500386 self.log.debug('pon-add-tcont', tcont=tcont)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800387 return new_tconts
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500388
389 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
390 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
391 self.log.debug('create-gemport',
392 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530393 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500394 for gem_port in gem_ports:
395 gemdict = dict()
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800396 if gem_port[IS_MULTICAST] == 'True':
397 gemdict[GEM_PORT_ID] = gem_port['multicast_gem_id']
398 gemdict[IS_MULTICAST] = True
399 else:
400 gemdict[GEM_PORT_ID] = gem_port[GEM_PORT_ID]
401 gemdict[IS_MULTICAST] = False
402
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500403 gemdict['direction'] = direction
404 gemdict['alloc_id_ref'] = alloc_id_ref
405 gemdict['encryption'] = gem_port['aes_encryption']
406 gemdict['discard_config'] = dict()
407 gemdict['discard_config']['max_probability'] = \
408 gem_port['discard_config']['max_probability']
409 gemdict['discard_config']['max_threshold'] = \
410 gem_port['discard_config']['max_threshold']
411 gemdict['discard_config']['min_threshold'] = \
412 gem_port['discard_config']['min_threshold']
413 gemdict['discard_policy'] = gem_port['discard_policy']
414 gemdict['max_q_size'] = gem_port['max_q_size']
415 gemdict['pbit_map'] = gem_port['pbit_map']
416 gemdict['priority_q'] = gem_port['priority_q']
417 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
418 gemdict['weight'] = gem_port['weight']
419 gemdict['uni_id'] = uni_id
420
421 gem_port = OnuGemPort.create(self, gem_port=gemdict)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530422 new_gem_ports.append(gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500423
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800424 self._pon.add_gem_port(gem_port, True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500425
426 self.log.debug('pon-add-gemport', gem_port=gem_port)
427
Girish Gowdrae933cd32019-11-21 21:04:41 +0530428 return new_gem_ports
429
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800430 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400431 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
432 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
433 # or initial-mib-download is not done. Once the tp_task is completed, we execute
434 # such queued vlan-filter tasks
435 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800436 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 -0400437 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800438 uni_id=uni_id, tp_id=tp_id)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800439 for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]:
440 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800441 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
442 match_vlan=filter_info.get("match_vlan"),
443 _set_vlan_vid=filter_info.get("set_vlan_vid"),
444 _set_vlan_pcp=filter_info.get("set_vlan_pcp"),
445 tp_id=filter_info.get("tp_id"))
Girish Gowdraaf98a082020-03-05 16:40:51 -0800446 # Now remove the entry from the dictionary
447 self._queued_vlan_filter_task[uni_id][tp_id].remove(filter_info)
448 self.log.debug("executed-queued-vlan-filter-task",
449 uni_id=uni_id, tp_id=tp_id)
450 # Now delete the key entries once we have handled the queued vlan filter tasks.
451 del self._queued_vlan_filter_task[uni_id]
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400452 except Exception as e:
453 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
454
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500455 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500456 us_scheduler = tp['us_scheduler']
457 alloc_id = us_scheduler['alloc_id']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800458 new_tconts = self._create_tconts(uni_id, us_scheduler)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500459 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800460 new_upstream_gems = self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500461 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800462 new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
463
464 new_gems = []
465 new_gems.extend(new_upstream_gems)
466 new_gems.extend(new_downstream_gems)
467
468 return new_tconts, new_gems
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500469
470 def load_and_configure_tech_profile(self, uni_id, tp_path):
471 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyele9110a32020-02-20 14:56:50 -0800472 tp_id = self.extract_tp_id_from_path(tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500473 if uni_id not in self._tp_service_specific_task:
474 self._tp_service_specific_task[uni_id] = dict()
475
476 if uni_id not in self._tech_profile_download_done:
477 self._tech_profile_download_done[uni_id] = dict()
478
Mahir Gunyele9110a32020-02-20 14:56:50 -0800479 if tp_id not in self._tech_profile_download_done[uni_id]:
480 self._tech_profile_download_done[uni_id][tp_id] = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500481
Mahir Gunyele9110a32020-02-20 14:56:50 -0800482 if not self._tech_profile_download_done[uni_id][tp_id]:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500483 try:
484 if tp_path in self._tp_service_specific_task[uni_id]:
485 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530486 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500487 return
488
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500489 tpstored = self.kv_client[tp_path]
490 tpstring = tpstored.decode('ascii')
491 tp = json.loads(tpstring)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800492 self._tp[tp_id] = tp
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500493 self.log.debug("tp-instance", tp=tp)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800494 tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700495
William Kurkian3a206332019-04-29 11:05:47 -0400496 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500497 def success(_results):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800498 self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500499 if tp_path in self._tp_service_specific_task[uni_id]:
500 del self._tp_service_specific_task[uni_id][tp_path]
Mahir Gunyele9110a32020-02-20 14:56:50 -0800501 self._tech_profile_download_done[uni_id][tp_id] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400502 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800503 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500504 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530505
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800506 # Execute mcast task
507 for gem in gem_ports:
508 self.log.debug("checking-multicast-service-for-gem ", gem=gem)
509 if gem.mcast is True:
510 self.log.info("found-multicast-service-for-gem ", gem=gem, uni_id=uni_id, tp_id=tp_id)
511 reactor.callInThread(self.start_multicast_service, uni_id, tp_path)
512 self.log.debug("started_multicast_service-successfully", tconts=tconts, gems=gem_ports)
513 break
514
William Kurkian3a206332019-04-29 11:05:47 -0400515 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500516 def failure(_reason):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800517 self.log.warn('tech-profile-config-failure-retrying', uni_id=uni_id, tp_id=tp_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530518 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500519 if tp_path in self._tp_service_specific_task[uni_id]:
520 del self._tp_service_specific_task[uni_id][tp_path]
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800521 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500522 reactor.callLater(retry, self.load_and_configure_tech_profile,
523 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500524 yield self.core_proxy.device_reason_update(self.device_id,
525 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500526
Mahir Gunyela982ec32020-02-25 12:30:37 -0800527 self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530528 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
529
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500530 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800531 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500532 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530533 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500534 self._deferred.addCallbacks(success, failure)
535
536 except Exception as e:
537 self.log.exception("error-loading-tech-profile", e=e)
538 else:
539 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530540 # Could be a case where TP exists but new gem-ports are getting added dynamically
541 tpstored = self.kv_client[tp_path]
542 tpstring = tpstored.decode('ascii')
543 tp = json.loads(tpstring)
544 upstream_gems = []
545 downstream_gems = []
546 # Find out the new Gem ports that are getting added afresh.
547 for gp in tp['upstream_gem_port_attribute_list']:
548 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
549 # gem port already exists
550 continue
551 upstream_gems.append(gp)
552 for gp in tp['downstream_gem_port_attribute_list']:
553 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
554 # gem port already exists
555 continue
556 downstream_gems.append(gp)
557
558 us_scheduler = tp['us_scheduler']
559 alloc_id = us_scheduler['alloc_id']
560
561 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
562 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
563 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
564 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
565 new_gems = []
566 new_gems.extend(new_upstream_gems)
567 new_gems.extend(new_downstream_gems)
568
569 def success(_results):
570 self.log.info("new-gem-ports-successfully-installed", result=_results)
571
572 def failure(_reason):
573 self.log.warn('new-gem-port-install-failed--retrying',
574 _reason=_reason)
575 # Remove gem ports from cache. We will re-add them during the retry
576 for gp in new_gems:
577 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
578
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800579 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500580 reactor.callLater(retry, self.load_and_configure_tech_profile,
581 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530582
583 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800584 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530585 self._deferred = \
586 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
587 self._deferred.addCallbacks(success, failure)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800588 def start_multicast_service(self, uni_id, tp_path,retry_count=0):
589 self.log.debug("starting-multicast-service", uni_id=uni_id, tp_path=tp_path)
590 tp_id = self.extract_tp_id_from_path(tp_path)
591 if uni_id in self._set_vlan and tp_id in self._set_vlan[uni_id]:
592 try:
593 tp = self._tp[tp_id]
594 if tp is None:
595 tpstored = self.kv_client[tp_path]
596 tpstring = tpstored.decode('ascii')
597 tp = json.loads(tpstring)
598 if tp is None:
599 self.log.error("cannot-find-tp-to-start-multicast-service", uni_id=uni_id, tp_path=tp_path)
600 return
601 else:
602 self._tp[tp_id] = tp
603
604 self.log.debug("mcast-vlan-learned-before", self._set_vlan[uni_id][tp_id], uni_id=uni_id, tp_id=tp_id)
605 def success(_results):
606 self.log.debug('multicast-success', uni_id=uni_id)
607 self._multicast_task = None
608
609 def failure(_reason):
610 self.log.warn('multicast-failure', _reason=_reason)
611 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
612 reactor.callLater(retry, self.start_multicast_service,
613 uni_id, tp_path)
614
615 self.log.debug('starting-multicast-task', mcast_vlan_id=self._set_vlan[uni_id][tp_id])
616 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
617 for i in range(len(downstream_gem_port_attribute_list)):
618 if IS_MULTICAST in downstream_gem_port_attribute_list[i] and \
619 downstream_gem_port_attribute_list[i][IS_MULTICAST] == 'True':
620 dynamic_access_control_list_table = downstream_gem_port_attribute_list[i]['dynamic_access_control_list'].split("-")
621 static_access_control_list_table = downstream_gem_port_attribute_list[i]['static_access_control_list'].split("-")
622 multicast_gem_id = downstream_gem_port_attribute_list[i]['multicast_gem_id']
623 break
624
625 self._multicast_task = BrcmMcastTask(self.omci_agent, self, self.device_id, uni_id, tp_id,
626 self._set_vlan[uni_id][tp_id],dynamic_access_control_list_table, static_access_control_list_table, multicast_gem_id)
627 self._deferred = self._onu_omci_device.task_runner.queue_task(self._multicast_task)
628 self._deferred.addCallbacks(success, failure)
629 except Exception as e:
630 self.log.exception("error-loading-multicast", e=e)
631 else:
632 if retry_count<30:
633 retry_count = +1
634 self.log.debug("going-to-wait-for-flow-to-learn-mcast-vlan", uni_id=uni_id, tp_id=tp_id, retry=retry_count)
635 reactor.callLater(0.5, self.start_multicast_service, uni_id, tp_path, retry_count)
636 else:
637 self.log.error("mcast-vlan-not-configured-yet-failing-mcast-service-conf", uni_id=uni_id, tp_id=tp_id, retry=retry_count)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530638
639 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
640 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800641 tp_table_id = self.extract_tp_id_from_path(tp_path)
Naga Manjunathe433c712020-01-02 17:27:20 +0530642 if not uni_id in self._tech_profile_download_done:
643 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
644 return
645
Mahir Gunyele9110a32020-02-20 14:56:50 -0800646 if not tp_table_id in self._tech_profile_download_done[uni_id]:
647 self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id)
Naga Manjunathe433c712020-01-02 17:27:20 +0530648 return
649
Mahir Gunyele9110a32020-02-20 14:56:50 -0800650 if self._tech_profile_download_done[uni_id][tp_table_id] is not True:
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800651 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete", uni_id=uni_id,
652 tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530653 return
654
655 if alloc_id is None and gem_port_id is None:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800656 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 +0530657 return
658
659 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
660 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
661 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
662 # this initializer
663 tcont = None
664 self.log.debug("tconts", tconts=list(self.pon_port.tconts.values()))
665 for tc in list(self.pon_port.tconts.values()):
666 if tc.alloc_id == alloc_id:
667 tcont = tc
668 self.pon_port.remove_tcont(tc.alloc_id, False)
669
670 gem_port = None
671 self.log.debug("gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
672 for gp in list(self.pon_port.gem_ports.values()):
673 if gp.gem_id == gem_port_id:
674 gem_port = gp
675 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
676
Girish Gowdrae933cd32019-11-21 21:04:41 +0530677 @inlineCallbacks
678 def success(_results):
679 if gem_port_id:
680 self.log.info("gem-port-delete-done-successfully")
681 if alloc_id:
682 self.log.info("tcont-delete-done-successfully")
683 # The deletion of TCONT marks the complete deletion of tech-profile
684 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800685 del self._tech_profile_download_done[uni_id][tp_table_id]
Girish Gowdrae933cd32019-11-21 21:04:41 +0530686 del self._tp_service_specific_task[uni_id][tp_path]
687 except Exception as ex:
688 self.log.error("del-tp-state-info", e=ex)
689
690 # TODO: There could be multiple TP on the UNI, and also the ONU.
691 # TODO: But the below reason updates for the whole device.
692 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
693
694 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530695 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530696 self.log.warn('tech-profile-delete-failure-retrying',
697 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500698 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
699 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500700 yield self.core_proxy.device_reason_update(self.device_id,
701 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530702
703 self.log.info('deleting-tech-profile-configuration')
704
Girish Gowdraa73ee452019-12-20 18:52:17 +0530705 if tcont is None and gem_port is None:
706 if alloc_id is not None:
707 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
708 if gem_port_id is not None:
709 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
710 return
711
Girish Gowdrae933cd32019-11-21 21:04:41 +0530712 self._tp_service_specific_task[uni_id][tp_path] = \
713 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
714 tcont=tcont, gem_port=gem_port)
715 self._deferred = \
716 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
717 self._deferred.addCallbacks(success, failure)
718 except Exception as e:
719 self.log.exception("failed-to-delete-tp",
720 e=e, uni_id=uni_id, tp_path=tp_path,
721 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500722
723 def update_pm_config(self, device, pm_config):
724 # TODO: This has not been tested
725 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500726 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500727
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800728 def remove_onu_flows(self, device, flows):
729 self.log.debug('remove_onu_flows', device_id=device.id)
730
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800731 # no point in removing omci flows if the device isnt reachable
732 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800733 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800734 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
735 admin=device.admin_state, connect=device.connect_status)
736 return
737
738 for flow in flows:
739 # if incoming flow contains cookie, then remove from ONU
740 if flow.cookie:
741 self.log.debug("remove-flow", device_id=device.id, flow=flow)
742
743 def is_downstream(port):
744 return port == self._pon_port_number
745
746 def is_upstream(port):
747 return not is_downstream(port)
748
749 try:
750 _in_port = fd.get_in_port(flow)
751 assert _in_port is not None
752
753 _out_port = fd.get_out_port(flow) # may be None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800754
755 if is_downstream(_in_port):
756 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
757 device_id=device.id)
758 # extended vlan tagging operation will handle it
759 continue
760 elif is_upstream(_in_port):
761 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
762 if fd.is_dhcp_flow(flow):
763 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
764 return
765
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800766 _vlan_vid = 0
767 # Retrieve the VLAN_VID that needs to be removed from the EVTO rule on the ONU.
768 for action in fd.get_actions(flow):
769 if action.type == fd.SET_FIELD:
770 _field = action.set_field.field.ofb_field
771 assert (action.set_field.field.oxm_class ==
772 OFPXMC_OPENFLOW_BASIC)
773 if _field.type == fd.VLAN_VID:
774 _vlan_vid = _field.vlan_vid & 0xfff
775 self.log.debug('vlan-vid-to-remove',
776 _vlan_vid=_vlan_vid, in_port=_in_port)
777
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800778 uni_port = self.uni_port(_in_port)
779 uni_id = _in_port & 0xF
780 else:
781 raise Exception('port should be 1 or 2 by our convention')
782
783 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
784
785 tp_id = self.get_tp_id_in_flow(flow)
786 # Deleting flow from ONU.
787 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800788 match_vlan=_vlan_vid, tp_id=tp_id)
789 # TODO:Delete TD task.
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800790 except Exception as e:
791 self.log.exception('failed-to-remove-flow', e=e)
792
793 def add_onu_flows(self, device, flows):
794 self.log.debug('function-entry', flows=flows)
795
796 #
797 # We need to proxy through the OLT to get to the ONU
798 # Configuration from here should be using OMCI
799 #
800 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
801
802 # no point in pushing omci flows if the device isnt reachable
803 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800804 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800805 self.log.warn("device-disabled-or-offline-skipping-flow-update",
806 admin=device.admin_state, connect=device.connect_status)
807 return
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800808
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800809 def is_downstream(port):
810 return port == self._pon_port_number
811
812 def is_upstream(port):
813 return not is_downstream(port)
814
815 for flow in flows:
816 # if incoming flow contains cookie, then add to ONU
817 if flow.cookie:
818 _type = None
819 _port = None
820 _vlan_vid = None
821 _udp_dst = None
822 _udp_src = None
823 _ipv4_dst = None
824 _ipv4_src = None
825 _metadata = None
826 _output = None
827 _push_tpid = None
828 _field = None
829 _set_vlan_vid = None
830 _set_vlan_pcp = 0
831 _tunnel_id = None
832 self.log.debug("add-flow", device_id=device.id, flow=flow)
833
834 try:
835 _in_port = fd.get_in_port(flow)
836 assert _in_port is not None
837
838 _out_port = fd.get_out_port(flow) # may be None
839 tp_id = self.get_tp_id_in_flow(flow)
840 if is_downstream(_in_port):
841 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
842 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
843 # uni_port = self.uni_port(_out_port)
844 # uni_id = _out_port & 0xF
845 continue
846 elif is_upstream(_in_port):
847 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
848 uni_port = self.uni_port(_in_port)
849 uni_id = _in_port & 0xF
850 else:
851 raise Exception('port should be 1 or 2 by our convention')
852
853 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
854
855 for field in fd.get_ofb_fields(flow):
856 if field.type == fd.ETH_TYPE:
857 _type = field.eth_type
858 self.log.debug('field-type-eth-type',
859 eth_type=_type)
860
861 elif field.type == fd.IP_PROTO:
862 _proto = field.ip_proto
863 self.log.debug('field-type-ip-proto',
864 ip_proto=_proto)
865
866 elif field.type == fd.IN_PORT:
867 _port = field.port
868 self.log.debug('field-type-in-port',
869 in_port=_port)
870 elif field.type == fd.TUNNEL_ID:
871 self.log.debug('field-type-tunnel-id')
872
873 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100874 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
875 _vlan_vid = RESERVED_TRANSPARENT_VLAN
876 else:
877 _vlan_vid = field.vlan_vid & 0xfff
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800878 self.log.debug('field-type-vlan-vid',
879 vlan=_vlan_vid)
880
881 elif field.type == fd.VLAN_PCP:
882 _vlan_pcp = field.vlan_pcp
883 self.log.debug('field-type-vlan-pcp',
884 pcp=_vlan_pcp)
885
886 elif field.type == fd.UDP_DST:
887 _udp_dst = field.udp_dst
888 self.log.debug('field-type-udp-dst',
889 udp_dst=_udp_dst)
890
891 elif field.type == fd.UDP_SRC:
892 _udp_src = field.udp_src
893 self.log.debug('field-type-udp-src',
894 udp_src=_udp_src)
895
896 elif field.type == fd.IPV4_DST:
897 _ipv4_dst = field.ipv4_dst
898 self.log.debug('field-type-ipv4-dst',
899 ipv4_dst=_ipv4_dst)
900
901 elif field.type == fd.IPV4_SRC:
902 _ipv4_src = field.ipv4_src
903 self.log.debug('field-type-ipv4-src',
904 ipv4_dst=_ipv4_src)
905
906 elif field.type == fd.METADATA:
907 _metadata = field.table_metadata
908 self.log.debug('field-type-metadata',
909 metadata=_metadata)
910
911 else:
912 raise NotImplementedError('field.type={}'.format(
913 field.type))
914
915 for action in fd.get_actions(flow):
916
917 if action.type == fd.OUTPUT:
918 _output = action.output.port
919 self.log.debug('action-type-output',
920 output=_output, in_port=_in_port)
921
922 elif action.type == fd.POP_VLAN:
923 self.log.debug('action-type-pop-vlan',
924 in_port=_in_port)
925
926 elif action.type == fd.PUSH_VLAN:
927 _push_tpid = action.push.ethertype
928 self.log.debug('action-type-push-vlan',
929 push_tpid=_push_tpid, in_port=_in_port)
930 if action.push.ethertype != 0x8100:
931 self.log.error('unhandled-tpid',
932 ethertype=action.push.ethertype)
933
934 elif action.type == fd.SET_FIELD:
935 _field = action.set_field.field.ofb_field
936 assert (action.set_field.field.oxm_class ==
937 OFPXMC_OPENFLOW_BASIC)
938 self.log.debug('action-type-set-field',
939 field=_field, in_port=_in_port)
940 if _field.type == fd.VLAN_VID:
941 _set_vlan_vid = _field.vlan_vid & 0xfff
942 self.log.debug('set-field-type-vlan-vid',
943 vlan_vid=_set_vlan_vid)
944 elif _field.type == fd.VLAN_PCP:
945 _set_vlan_pcp = _field.vlan_pcp
946 self.log.debug('set-field-type-vlan-pcp',
947 vlan_pcp=_set_vlan_pcp)
948 else:
949 self.log.error('unsupported-action-set-field-type',
950 field_type=_field.type)
951 else:
952 self.log.error('unsupported-action-type',
953 action_type=action.type, in_port=_in_port)
954
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800955 if self._set_vlan is not None:
956 if uni_id not in self._set_vlan:
957 self._set_vlan[uni_id] = dict()
958 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
959 self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
960
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100961 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
962 # supported match and action criteria cannot be handled by omci and must be ignored.
963 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
964 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
965 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
966 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800967 _set_vlan_vid=_vlan_vid,
968 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
969 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100970 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
971 _set_vlan_vid=_vlan_vid,
972 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
973 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800974 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100975 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
976 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800977 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
978 _set_vlan_vid=_set_vlan_vid,
979 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
980 tp_id=tp_id)
981
982 except Exception as e:
983 self.log.exception('failed-to-install-flow', e=e, flow=flow)
984
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500985 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
986 # flow decomposition that ultimately comes from onos
987 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700988 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500989
990 #
991 # We need to proxy through the OLT to get to the ONU
992 # Configuration from here should be using OMCI
993 #
994 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
995
996 # no point in pushing omci flows if the device isnt reachable
997 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530998 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500999 self.log.warn("device-disabled-or-offline-skipping-flow-update",
1000 admin=device.admin_state, connect=device.connect_status)
1001 return
1002
1003 def is_downstream(port):
1004 return port == self._pon_port_number
1005
1006 def is_upstream(port):
1007 return not is_downstream(port)
1008
1009 for flow in flows:
1010 _type = None
1011 _port = None
1012 _vlan_vid = None
1013 _udp_dst = None
1014 _udp_src = None
1015 _ipv4_dst = None
1016 _ipv4_src = None
1017 _metadata = None
1018 _output = None
1019 _push_tpid = None
1020 _field = None
1021 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001022 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001023 _tunnel_id = None
1024
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001025 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +05301026 write_metadata = fd.get_write_metadata(flow)
1027 if write_metadata is None:
1028 self.log.error("do-not-process-flow-without-write-metadata")
1029 return
1030
1031 # extract tp id from flow
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001032 tp_id = self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001033 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +05301034
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001035 _in_port = fd.get_in_port(flow)
1036 assert _in_port is not None
1037
1038 _out_port = fd.get_out_port(flow) # may be None
1039
1040 if is_downstream(_in_port):
1041 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
1042 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301043 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001044 elif is_upstream(_in_port):
1045 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
1046 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001047 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001048 else:
1049 raise Exception('port should be 1 or 2 by our convention')
1050
1051 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
1052
1053 for field in fd.get_ofb_fields(flow):
1054 if field.type == fd.ETH_TYPE:
1055 _type = field.eth_type
1056 self.log.debug('field-type-eth-type',
1057 eth_type=_type)
1058
1059 elif field.type == fd.IP_PROTO:
1060 _proto = field.ip_proto
1061 self.log.debug('field-type-ip-proto',
1062 ip_proto=_proto)
1063
1064 elif field.type == fd.IN_PORT:
1065 _port = field.port
1066 self.log.debug('field-type-in-port',
1067 in_port=_port)
1068
1069 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001070 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
1071 _vlan_vid = RESERVED_TRANSPARENT_VLAN
1072 else:
1073 _vlan_vid = field.vlan_vid & 0xfff
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001074 self.log.debug('field-type-vlan-vid',
1075 vlan=_vlan_vid)
1076
1077 elif field.type == fd.VLAN_PCP:
1078 _vlan_pcp = field.vlan_pcp
1079 self.log.debug('field-type-vlan-pcp',
1080 pcp=_vlan_pcp)
1081
1082 elif field.type == fd.UDP_DST:
1083 _udp_dst = field.udp_dst
1084 self.log.debug('field-type-udp-dst',
1085 udp_dst=_udp_dst)
1086
1087 elif field.type == fd.UDP_SRC:
1088 _udp_src = field.udp_src
1089 self.log.debug('field-type-udp-src',
1090 udp_src=_udp_src)
1091
1092 elif field.type == fd.IPV4_DST:
1093 _ipv4_dst = field.ipv4_dst
1094 self.log.debug('field-type-ipv4-dst',
1095 ipv4_dst=_ipv4_dst)
1096
1097 elif field.type == fd.IPV4_SRC:
1098 _ipv4_src = field.ipv4_src
1099 self.log.debug('field-type-ipv4-src',
1100 ipv4_dst=_ipv4_src)
1101
1102 elif field.type == fd.METADATA:
1103 _metadata = field.table_metadata
1104 self.log.debug('field-type-metadata',
1105 metadata=_metadata)
1106
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001107 elif field.type == fd.TUNNEL_ID:
1108 _tunnel_id = field.tunnel_id
1109 self.log.debug('field-type-tunnel-id',
1110 tunnel_id=_tunnel_id)
1111
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001112
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001113 else:
1114 raise NotImplementedError('field.type={}'.format(
1115 field.type))
1116
1117 for action in fd.get_actions(flow):
1118
1119 if action.type == fd.OUTPUT:
1120 _output = action.output.port
1121 self.log.debug('action-type-output',
1122 output=_output, in_port=_in_port)
1123
1124 elif action.type == fd.POP_VLAN:
1125 self.log.debug('action-type-pop-vlan',
1126 in_port=_in_port)
1127
1128 elif action.type == fd.PUSH_VLAN:
1129 _push_tpid = action.push.ethertype
1130 self.log.debug('action-type-push-vlan',
1131 push_tpid=_push_tpid, in_port=_in_port)
1132 if action.push.ethertype != 0x8100:
1133 self.log.error('unhandled-tpid',
1134 ethertype=action.push.ethertype)
1135
1136 elif action.type == fd.SET_FIELD:
1137 _field = action.set_field.field.ofb_field
1138 assert (action.set_field.field.oxm_class ==
1139 OFPXMC_OPENFLOW_BASIC)
1140 self.log.debug('action-type-set-field',
1141 field=_field, in_port=_in_port)
1142 if _field.type == fd.VLAN_VID:
1143 _set_vlan_vid = _field.vlan_vid & 0xfff
1144 self.log.debug('set-field-type-vlan-vid',
1145 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001146 elif _field.type == fd.VLAN_PCP:
1147 _set_vlan_pcp = _field.vlan_pcp
1148 self.log.debug('set-field-type-vlan-pcp',
1149 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001150 else:
1151 self.log.error('unsupported-action-set-field-type',
1152 field_type=_field.type)
1153 else:
1154 self.log.error('unsupported-action-type',
1155 action_type=action.type, in_port=_in_port)
1156
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001157 if self._set_vlan is not None:
1158 if uni_id not in self._set_vlan:
1159 self._set_vlan[uni_id] = dict()
1160 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
1161 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 -04001162 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1163 # supported match and action criteria cannot be handled by omci and must be ignored.
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001164 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
1165 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
1166 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
1167 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001168 _set_vlan_vid=_vlan_vid,
1169 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1170 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001171 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1172 _set_vlan_vid=_vlan_vid,
1173 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1174 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001175 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001176 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
1177 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
1178 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1179 _set_vlan_vid=_set_vlan_vid,
1180 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1181 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001182 except Exception as e:
1183 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1184
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001185 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001186 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1187 self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1188 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001189 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001190 if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and \
1191 self._tech_profile_download_done[uni_id][tp_id] is True:
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001192 @inlineCallbacks
1193 def success(_results):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001194 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id,
1195 set_vlan_pcp=_set_vlan_pcp)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001196 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001197
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001198 @inlineCallbacks
1199 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301200 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 -08001201 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1202 reactor.callLater(retry,
1203 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1204 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1205 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001206 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001207
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001208 self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1209 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001210 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001211 match_vlan, _set_vlan_pcp, add_tag=True,
1212 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001213 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001214 self._deferred.addCallbacks(success, failure)
1215 else:
1216 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001217 uni_id=uni_id, tp_id=tp_id)
1218 if uni_id not in self._queued_vlan_filter_task:
1219 self._queued_vlan_filter_task[uni_id] = dict()
Mahir Gunyela982ec32020-02-25 12:30:37 -08001220 if tp_id not in self._queued_vlan_filter_task[uni_id]:
1221 self._queued_vlan_filter_task[uni_id][tp_id] = []
1222 self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001223 "uni_id": uni_id,
1224 "uni_port": uni_port,
1225 "match_vlan": match_vlan,
1226 "set_vlan_vid": _set_vlan_vid,
1227 "set_vlan_pcp": _set_vlan_pcp,
1228 "tp_id": tp_id})
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001229
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001230 def get_tp_id_in_flow(self, flow):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001231 flow_metadata = fd.get_metadata_from_write_metadata(flow)
1232 tp_id = fd.get_tp_id_from_metadata(flow_metadata)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001233 return tp_id
1234
1235 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001236 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001237 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001238
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001239 @inlineCallbacks
1240 def success(_results):
1241 self.log.info('vlan-untagging-success', _results=_results)
1242 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1243
1244 @inlineCallbacks
1245 def failure(_reason):
1246 self.log.warn('vlan-untagging-failure', _reason=_reason)
1247 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001248 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001249 reactor.callLater(retry,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001250 self._remove_vlan_filter_task, device, uni_id,
1251 add_tag=False, uni_port=uni_port)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001252
1253 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1254 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001255 match_vlan, _set_vlan_pcp, add_tag=False,
1256 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001257 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1258 self._deferred.addCallbacks(success, failure)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001259
Matt Jeannereta32441c2019-03-07 05:16:37 -05001260 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001261 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1262 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001263 try:
1264 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1265 omci_msg = InterAdapterOmciMessage()
1266 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001267 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001268
Matt Jeannereta32441c2019-03-07 05:16:37 -05001269 self.receive_message(omci_msg.message)
1270
1271 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1272 onu_indication = OnuIndication()
1273 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001274 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1275 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1276 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001277
1278 if onu_indication.oper_state == "up":
1279 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301280 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001281 self.update_interface(onu_indication)
1282 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001283 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1284 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001285
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001286 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1287 tech_msg = InterAdapterTechProfileDownloadMessage()
1288 request.body.Unpack(tech_msg)
1289 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1290
1291 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1292
Girish Gowdrae933cd32019-11-21 21:04:41 +05301293 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1294 del_gem_msg = InterAdapterDeleteGemPortMessage()
1295 request.body.Unpack(del_gem_msg)
1296 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1297
1298 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1299 gem_port_id=del_gem_msg.gem_port_id,
1300 tp_path=del_gem_msg.tp_path)
1301
1302 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1303 del_tcont_msg = InterAdapterDeleteTcontMessage()
1304 request.body.Unpack(del_tcont_msg)
1305 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1306
1307 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1308 alloc_id=del_tcont_msg.alloc_id,
1309 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001310 else:
1311 self.log.error("inter-adapter-unhandled-type", request=request)
1312
1313 except Exception as e:
1314 self.log.exception("error-processing-inter-adapter-message", e=e)
1315
1316 # Called each time there is an onu "up" indication from the olt handler
1317 @inlineCallbacks
1318 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001319 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001320 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001321
1322 # Ignore if onu_indication is received for an already running ONU
1323 if self._onu_omci_device is not None and self._onu_omci_device.active:
1324 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1325 return
1326
Matt Jeannereta32441c2019-03-07 05:16:37 -05001327 self._onu_indication = onu_indication
1328
Matt Jeanneretc083f462019-03-11 15:02:01 -04001329 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1330 connect_status=ConnectStatus.REACHABLE)
1331
Matt Jeannereta32441c2019-03-07 05:16:37 -05001332 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001333
1334 self.log.debug('starting-openomci-statemachine')
1335 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001336 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301337 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001338 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001339 self._heartbeat.enabled = True
1340
Matt Jeanneret42dad792020-02-01 09:28:27 -05001341 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001342 @inlineCallbacks
1343 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001344 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001345 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001346
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001347 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001348 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001349 reactor.callLater(0, self._onu_omci_device.stop)
1350
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001351 self._tp = dict()
1352
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001353 # Let TP download happen again
1354 for uni_id in self._tp_service_specific_task:
1355 self._tp_service_specific_task[uni_id].clear()
1356 for uni_id in self._tech_profile_download_done:
1357 self._tech_profile_download_done[uni_id].clear()
1358
Matt Jeanneretf4113222019-08-14 19:44:34 -04001359 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001360 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1361 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1362 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001363 else:
1364 self.log.debug('not-changing-openomci-statemachine')
1365
Matt Jeanneretf4113222019-08-14 19:44:34 -04001366 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001367 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001368 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001369 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001370 yield self.disable_ports(lock_ports=True)
1371 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1372 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001373
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001374 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001375 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001376
William Kurkian3a206332019-04-29 11:05:47 -04001377 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001378 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001379 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001380 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001381 yield self.core_proxy.device_state_update(device.id,
1382 oper_status=OperStatus.ACTIVE,
1383 connect_status=ConnectStatus.REACHABLE)
1384 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1385 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001386 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001387 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001388
William Kurkian3a206332019-04-29 11:05:47 -04001389 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001390 def reboot(self):
1391 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001392 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001393 if device.connect_status != ConnectStatus.REACHABLE:
1394 self.log.error("device-unreachable")
1395 return
1396
William Kurkian3a206332019-04-29 11:05:47 -04001397 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001398 def success(_results):
1399 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001400 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001401
1402 def failure(_reason):
1403 self.log.info('reboot-failure', _reason=_reason)
1404
1405 self._deferred = self._onu_omci_device.reboot()
1406 self._deferred.addCallbacks(success, failure)
1407
William Kurkian3a206332019-04-29 11:05:47 -04001408 @inlineCallbacks
Matt Jeanneretf4113222019-08-14 19:44:34 -04001409 def disable_ports(self, lock_ports=True):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001410 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001411
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001412 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1413 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001414 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001415 if port.mac_bridge_port_num == 1:
1416 port.operstatus = OperStatus.UNKNOWN
1417 self.log.info('disable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001418 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1419 port.operstatus)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001420
1421 if lock_ports is True:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001422 self.lock_ports(lock=True)
1423
William Kurkian3a206332019-04-29 11:05:47 -04001424 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001425 def enable_ports(self):
1426 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001427
Matt Jeanneretf4113222019-08-14 19:44:34 -04001428 self.lock_ports(lock=False)
1429
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001430 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1431 # load on the core
1432 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001433 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001434 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001435 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001436 self.log.info('enable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001437 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1438 port.operstatus)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001439
1440 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1441 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1442 #
1443 # Basically the link state sequence:
1444 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1445 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1446 # 3) a link state up alarm is received for the uni plugged in.
1447 #
1448 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1449 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1450 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1451 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001452 @inlineCallbacks
1453 def port_state_handler(self, _topic, msg):
1454 self.log.info("port-state-change", _topic=_topic, msg=msg)
1455
1456 onu_id = msg['onu_id']
1457 port_no = msg['port_number']
1458 serial_number = msg['serial_number']
1459 port_status = msg['port_status']
1460 uni_port = self.uni_port(int(port_no))
1461
1462 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1463 port_status=port_status)
1464
1465 if port_status is True:
1466 uni_port.operstatus = OperStatus.ACTIVE
1467 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1468 else:
1469 uni_port.operstatus = OperStatus.UNKNOWN
1470 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1471
1472 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 -05001473 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001474
1475 # Called just before openomci state machine is started. These listen for events from selected state machines,
1476 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1477 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001478 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001479
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001480 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001481
1482 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001483 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1484 OnuDeviceEvents.MibDatabaseSyncEvent)
1485 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1486
1487 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001488 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1489 OnuDeviceEvents.OmciCapabilitiesEvent)
1490 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1491
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001492 # TODO: these alarms seem to be unreliable depending on the environment
1493 # 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 -08001494 # topic = OnuDeviceEntry.event_bus_topic(self.device_id,
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001495 # OnuDeviceEvents.PortEvent)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001496 # self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001497
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001498 # Called when the mib is in sync
1499 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001500 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001501 if self._in_sync_subscription is not None:
1502 try:
1503 in_sync = msg[IN_SYNC_KEY]
1504
1505 if in_sync:
1506 # Only call this once
1507 bus = self._onu_omci_device.event_bus
1508 bus.unsubscribe(self._in_sync_subscription)
1509 self._in_sync_subscription = None
1510
1511 # Start up device_info load
1512 self.log.debug('running-mib-sync')
1513 reactor.callLater(0, self._mib_in_sync)
1514
1515 except Exception as e:
1516 self.log.exception('in-sync', e=e)
1517
1518 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001519 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001520 if self._capabilities_subscription is not None:
1521 self.log.debug('capabilities-handler-done')
1522
1523 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1524 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1525 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001526 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001527 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001528 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001529
1530 omci = self._onu_omci_device
1531 in_sync = omci.mib_db_in_sync
1532
Matt Jeanneretc083f462019-03-11 15:02:01 -04001533 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001534 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001535
1536 if not self._dev_info_loaded:
1537 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1538
1539 omci_dev = self._onu_omci_device
1540 config = omci_dev.configuration
1541
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001542 try:
1543
1544 # sort the lists so we get consistent port ordering.
1545 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1546 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1547 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1548 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1549
1550 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001551 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001552 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001553 raise Exception("onu-missing-required-elements")
1554
1555 # Currently logging the ani, pptp, veip, and uni for information purposes.
1556 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1557 # And in some ONU the UNI-G list is incomplete or incorrect...
1558 for entity_id in ani_list:
1559 ani_value = config.ani_g_entities[entity_id]
1560 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1561 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1562 self._total_tcont_count = ani_value.get('total-tcont-count')
1563 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1564
1565 for entity_id in uni_list:
1566 uni_value = config.uni_g_entities[entity_id]
1567 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1568
1569 uni_entities = OrderedDict()
1570 for entity_id in pptp_list:
1571 pptp_value = config.pptp_entities[entity_id]
1572 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1573 uni_entities[entity_id] = UniType.PPTP
1574
1575 for entity_id in veip_list:
1576 veip_value = config.veip_entities[entity_id]
1577 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1578 uni_entities[entity_id] = UniType.VEIP
1579
1580 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001581 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001582 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001583 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001584 uni_id += 1
1585 except AssertionError as e:
1586 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1587
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001588 self._qos_flexibility = config.qos_configuration_flexibility or 0
1589 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1590
1591 if self._unis:
1592 self._dev_info_loaded = True
1593 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001594 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001595 self.log.warn("no-usable-unis")
1596 raise Exception("no-usable-unis")
1597
1598 except Exception as e:
1599 self.log.exception('device-info-load', e=e)
1600 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1601
1602 else:
1603 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1604
1605 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001606 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001607
1608 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001609 def success(_results):
1610 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001611 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301612 oper_status=OperStatus.ACTIVE,
1613 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001614 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001615 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001616 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001617 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001618
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001619 # Start collecting stats from the device after a brief pause
1620 if not self._pm_metrics_started:
1621 self._pm_metrics_started = True
1622 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1623 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1624
1625 # Start test requests after a brief pause
1626 if not self._test_request_started:
1627 self._test_request_started = True
1628 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1629 reactor.callLater(tststart, self._test_request.start_collector)
1630
Matt Jeanneretc083f462019-03-11 15:02:01 -04001631 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001632 def failure(_reason):
1633 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001634 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001635 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001636 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001637
Matt Jeanneretf4113222019-08-14 19:44:34 -04001638 # start by locking all the unis till mib sync and initial mib is downloaded
1639 # this way we can capture the port down/up events when we are ready
1640 self.lock_ports(lock=True)
1641
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001642 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1643 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1644 self.log.info('downloading-initial-mib-configuration')
1645 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1646 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1647 self._deferred.addCallbacks(success, failure)
1648 else:
1649 self.log.info('admin-down-disabling')
1650 self.disable(device)
1651 else:
1652 self.log.info('device-info-not-loaded-skipping-mib-download')
1653
Matt Jeanneretc083f462019-03-11 15:02:01 -04001654 @inlineCallbacks
1655 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001656 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001657
Matt Jeanneretc083f462019-03-11 15:02:01 -04001658 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 -05001659
1660 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1661 uni_name = "uni-{}".format(uni_no)
1662
Girish Gowdrae933cd32019-11-21 21:04:41 +05301663 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001664
1665 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 -04001666 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001667
1668 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1669 uni_port.entity_id = entity_id
1670 uni_port.enabled = True
1671 uni_port.mac_bridge_port_num = mac_bridge_port_num
1672
1673 self.log.debug("created-uni-port", uni=uni_port)
1674
Matt Jeanneretc083f462019-03-11 15:02:01 -04001675 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001676
1677 self._unis[uni_port.port_number] = uni_port
1678
1679 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301680 uni_ports=self.uni_ports,
1681 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001682
Matt Jeanneretc083f462019-03-11 15:02:01 -04001683 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1684 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001685 MAX_PONS_PER_OLT = 256
1686 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001687 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001688
Matt Jeanneretc083f462019-03-11 15:02:01 -04001689 assert intf_id < MAX_PONS_PER_OLT
1690 assert onu_id < MAX_ONUS_PER_PON
1691 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001692 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001693
1694 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001695 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001696 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001697 try:
1698 device = yield self.core_proxy.get_device(self.device_id)
1699 parent_device = yield self.core_proxy.get_device(self.parent_id)
1700 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001701 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001702
1703 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301704 pon_id=self._onu_indication.intf_id,
1705 onu_id=self._onu_indication.onu_id,
1706 registration_id=self.device_id,
1707 device_id=self.device_id,
1708 onu_serial_number=device.serial_number,
1709 olt_serial_number=olt_serial_number,
1710 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001711
Devmalya Paulffc89df2019-07-31 17:43:13 -04001712 self.log.debug("Trying-to-raise-onu-active-event")
1713 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001714 self._onu_indication.intf_id,
1715 device.serial_number,
1716 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301717 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001718 onu_id=self._onu_indication.onu_id).send(True)
1719 except Exception as active_event_error:
1720 self.log.exception('onu-activated-event-error',
1721 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001722
1723 def lock_ports(self, lock=True):
1724
1725 def success(response):
1726 self.log.debug('set-onu-ports-state', lock=lock, response=response)
1727
1728 def failure(response):
1729 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1730
1731 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1732 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1733 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001734
1735 def extract_tp_id_from_path(self, tp_path):
1736 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001737 tp_id = int(tp_path.split(_PATH_SEPERATOR)[1])
1738 return tp_id