blob: acfafe21542cf242af926b6a6928ceab996c8a6f [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
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500384 success = self._pon.add_tcont(tcont)
385 if success:
386 new_tconts.append(tcont)
387 self.log.debug('pon-add-tcont', tcont=tcont)
388
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800389 return new_tconts
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500390
391 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
392 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
393 self.log.debug('create-gemport',
394 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530395 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500396 for gem_port in gem_ports:
397 gemdict = dict()
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800398 if gem_port[IS_MULTICAST] == 'True':
399 gemdict[GEM_PORT_ID] = gem_port['multicast_gem_id']
400 gemdict[IS_MULTICAST] = True
401 else:
402 gemdict[GEM_PORT_ID] = gem_port[GEM_PORT_ID]
403 gemdict[IS_MULTICAST] = False
404
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500405 gemdict['direction'] = direction
406 gemdict['alloc_id_ref'] = alloc_id_ref
407 gemdict['encryption'] = gem_port['aes_encryption']
408 gemdict['discard_config'] = dict()
409 gemdict['discard_config']['max_probability'] = \
410 gem_port['discard_config']['max_probability']
411 gemdict['discard_config']['max_threshold'] = \
412 gem_port['discard_config']['max_threshold']
413 gemdict['discard_config']['min_threshold'] = \
414 gem_port['discard_config']['min_threshold']
415 gemdict['discard_policy'] = gem_port['discard_policy']
416 gemdict['max_q_size'] = gem_port['max_q_size']
417 gemdict['pbit_map'] = gem_port['pbit_map']
418 gemdict['priority_q'] = gem_port['priority_q']
419 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
420 gemdict['weight'] = gem_port['weight']
421 gemdict['uni_id'] = uni_id
422
423 gem_port = OnuGemPort.create(self, gem_port=gemdict)
424
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500425 success = self._pon.add_gem_port(gem_port, True)
426 if success:
427 new_gem_ports.append(gem_port)
428 self.log.debug('pon-add-gemport', gem_port=gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500429
Girish Gowdrae933cd32019-11-21 21:04:41 +0530430 return new_gem_ports
431
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800432 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400433 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
434 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
435 # or initial-mib-download is not done. Once the tp_task is completed, we execute
436 # such queued vlan-filter tasks
437 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800438 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 -0400439 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800440 uni_id=uni_id, tp_id=tp_id)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800441 for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]:
442 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800443 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
444 match_vlan=filter_info.get("match_vlan"),
445 _set_vlan_vid=filter_info.get("set_vlan_vid"),
446 _set_vlan_pcp=filter_info.get("set_vlan_pcp"),
447 tp_id=filter_info.get("tp_id"))
Girish Gowdraaf98a082020-03-05 16:40:51 -0800448 # Now remove the entry from the dictionary
449 self._queued_vlan_filter_task[uni_id][tp_id].remove(filter_info)
450 self.log.debug("executed-queued-vlan-filter-task",
451 uni_id=uni_id, tp_id=tp_id)
452 # Now delete the key entries once we have handled the queued vlan filter tasks.
453 del self._queued_vlan_filter_task[uni_id]
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400454 except Exception as e:
455 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
456
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500457 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500458 us_scheduler = tp['us_scheduler']
459 alloc_id = us_scheduler['alloc_id']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800460 new_tconts = self._create_tconts(uni_id, us_scheduler)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500461 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800462 new_upstream_gems = self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500463 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800464 new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
465
466 new_gems = []
467 new_gems.extend(new_upstream_gems)
468 new_gems.extend(new_downstream_gems)
469
470 return new_tconts, new_gems
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500471
472 def load_and_configure_tech_profile(self, uni_id, tp_path):
473 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyele9110a32020-02-20 14:56:50 -0800474 tp_id = self.extract_tp_id_from_path(tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500475 if uni_id not in self._tp_service_specific_task:
476 self._tp_service_specific_task[uni_id] = dict()
477
478 if uni_id not in self._tech_profile_download_done:
479 self._tech_profile_download_done[uni_id] = dict()
480
Mahir Gunyele9110a32020-02-20 14:56:50 -0800481 if tp_id not in self._tech_profile_download_done[uni_id]:
482 self._tech_profile_download_done[uni_id][tp_id] = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500483
Mahir Gunyele9110a32020-02-20 14:56:50 -0800484 if not self._tech_profile_download_done[uni_id][tp_id]:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500485 try:
486 if tp_path in self._tp_service_specific_task[uni_id]:
487 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530488 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500489 return
490
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500491 tpstored = self.kv_client[tp_path]
492 tpstring = tpstored.decode('ascii')
493 tp = json.loads(tpstring)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800494 self._tp[tp_id] = tp
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500495 self.log.debug("tp-instance", tp=tp)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800496 tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700497
William Kurkian3a206332019-04-29 11:05:47 -0400498 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500499 def success(_results):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800500 self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500501 if tp_path in self._tp_service_specific_task[uni_id]:
502 del self._tp_service_specific_task[uni_id][tp_path]
Mahir Gunyele9110a32020-02-20 14:56:50 -0800503 self._tech_profile_download_done[uni_id][tp_id] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400504 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800505 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500506 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530507
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800508 # Execute mcast task
509 for gem in gem_ports:
510 self.log.debug("checking-multicast-service-for-gem ", gem=gem)
511 if gem.mcast is True:
512 self.log.info("found-multicast-service-for-gem ", gem=gem, uni_id=uni_id, tp_id=tp_id)
513 reactor.callInThread(self.start_multicast_service, uni_id, tp_path)
514 self.log.debug("started_multicast_service-successfully", tconts=tconts, gems=gem_ports)
515 break
516
William Kurkian3a206332019-04-29 11:05:47 -0400517 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500518 def failure(_reason):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800519 self.log.warn('tech-profile-config-failure-retrying', uni_id=uni_id, tp_id=tp_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530520 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500521 if tp_path in self._tp_service_specific_task[uni_id]:
522 del self._tp_service_specific_task[uni_id][tp_path]
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800523 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500524 reactor.callLater(retry, self.load_and_configure_tech_profile,
525 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500526 yield self.core_proxy.device_reason_update(self.device_id,
527 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500528
Mahir Gunyela982ec32020-02-25 12:30:37 -0800529 self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530530 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
531
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500532 self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
533 self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
534
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500535 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800536 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500537 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530538 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500539 self._deferred.addCallbacks(success, failure)
540
541 except Exception as e:
542 self.log.exception("error-loading-tech-profile", e=e)
543 else:
544 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530545 # Could be a case where TP exists but new gem-ports are getting added dynamically
546 tpstored = self.kv_client[tp_path]
547 tpstring = tpstored.decode('ascii')
548 tp = json.loads(tpstring)
549 upstream_gems = []
550 downstream_gems = []
551 # Find out the new Gem ports that are getting added afresh.
552 for gp in tp['upstream_gem_port_attribute_list']:
553 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
554 # gem port already exists
555 continue
556 upstream_gems.append(gp)
557 for gp in tp['downstream_gem_port_attribute_list']:
558 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
559 # gem port already exists
560 continue
561 downstream_gems.append(gp)
562
563 us_scheduler = tp['us_scheduler']
564 alloc_id = us_scheduler['alloc_id']
565
566 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
567 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
568 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
569 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
570 new_gems = []
571 new_gems.extend(new_upstream_gems)
572 new_gems.extend(new_downstream_gems)
573
574 def success(_results):
575 self.log.info("new-gem-ports-successfully-installed", result=_results)
576
577 def failure(_reason):
578 self.log.warn('new-gem-port-install-failed--retrying',
579 _reason=_reason)
580 # Remove gem ports from cache. We will re-add them during the retry
581 for gp in new_gems:
582 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
583
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800584 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500585 reactor.callLater(retry, self.load_and_configure_tech_profile,
586 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530587
588 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800589 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530590 self._deferred = \
591 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
592 self._deferred.addCallbacks(success, failure)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800593 def start_multicast_service(self, uni_id, tp_path,retry_count=0):
594 self.log.debug("starting-multicast-service", uni_id=uni_id, tp_path=tp_path)
595 tp_id = self.extract_tp_id_from_path(tp_path)
596 if uni_id in self._set_vlan and tp_id in self._set_vlan[uni_id]:
597 try:
598 tp = self._tp[tp_id]
599 if tp is None:
600 tpstored = self.kv_client[tp_path]
601 tpstring = tpstored.decode('ascii')
602 tp = json.loads(tpstring)
603 if tp is None:
604 self.log.error("cannot-find-tp-to-start-multicast-service", uni_id=uni_id, tp_path=tp_path)
605 return
606 else:
607 self._tp[tp_id] = tp
608
609 self.log.debug("mcast-vlan-learned-before", self._set_vlan[uni_id][tp_id], uni_id=uni_id, tp_id=tp_id)
610 def success(_results):
611 self.log.debug('multicast-success', uni_id=uni_id)
612 self._multicast_task = None
613
614 def failure(_reason):
615 self.log.warn('multicast-failure', _reason=_reason)
616 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
617 reactor.callLater(retry, self.start_multicast_service,
618 uni_id, tp_path)
619
620 self.log.debug('starting-multicast-task', mcast_vlan_id=self._set_vlan[uni_id][tp_id])
621 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
622 for i in range(len(downstream_gem_port_attribute_list)):
623 if IS_MULTICAST in downstream_gem_port_attribute_list[i] and \
624 downstream_gem_port_attribute_list[i][IS_MULTICAST] == 'True':
625 dynamic_access_control_list_table = downstream_gem_port_attribute_list[i]['dynamic_access_control_list'].split("-")
626 static_access_control_list_table = downstream_gem_port_attribute_list[i]['static_access_control_list'].split("-")
627 multicast_gem_id = downstream_gem_port_attribute_list[i]['multicast_gem_id']
628 break
629
630 self._multicast_task = BrcmMcastTask(self.omci_agent, self, self.device_id, uni_id, tp_id,
631 self._set_vlan[uni_id][tp_id],dynamic_access_control_list_table, static_access_control_list_table, multicast_gem_id)
632 self._deferred = self._onu_omci_device.task_runner.queue_task(self._multicast_task)
633 self._deferred.addCallbacks(success, failure)
634 except Exception as e:
635 self.log.exception("error-loading-multicast", e=e)
636 else:
637 if retry_count<30:
638 retry_count = +1
639 self.log.debug("going-to-wait-for-flow-to-learn-mcast-vlan", uni_id=uni_id, tp_id=tp_id, retry=retry_count)
640 reactor.callLater(0.5, self.start_multicast_service, uni_id, tp_path, retry_count)
641 else:
642 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 +0530643
644 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
645 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800646 tp_table_id = self.extract_tp_id_from_path(tp_path)
Naga Manjunathe433c712020-01-02 17:27:20 +0530647 if not uni_id in self._tech_profile_download_done:
648 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
649 return
650
Mahir Gunyele9110a32020-02-20 14:56:50 -0800651 if not tp_table_id in self._tech_profile_download_done[uni_id]:
652 self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id)
Naga Manjunathe433c712020-01-02 17:27:20 +0530653 return
654
Mahir Gunyele9110a32020-02-20 14:56:50 -0800655 if self._tech_profile_download_done[uni_id][tp_table_id] is not True:
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800656 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete", uni_id=uni_id,
657 tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530658 return
659
660 if alloc_id is None and gem_port_id is None:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800661 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 +0530662 return
663
664 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
665 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
666 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
667 # this initializer
668 tcont = None
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500669 self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530670 for tc in list(self.pon_port.tconts.values()):
671 if tc.alloc_id == alloc_id:
672 tcont = tc
673 self.pon_port.remove_tcont(tc.alloc_id, False)
674
675 gem_port = None
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500676 self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530677 for gp in list(self.pon_port.gem_ports.values()):
678 if gp.gem_id == gem_port_id:
679 gem_port = gp
680 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
681
Girish Gowdrae933cd32019-11-21 21:04:41 +0530682 @inlineCallbacks
683 def success(_results):
684 if gem_port_id:
685 self.log.info("gem-port-delete-done-successfully")
686 if alloc_id:
687 self.log.info("tcont-delete-done-successfully")
688 # The deletion of TCONT marks the complete deletion of tech-profile
689 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800690 del self._tech_profile_download_done[uni_id][tp_table_id]
Girish Gowdrae933cd32019-11-21 21:04:41 +0530691 del self._tp_service_specific_task[uni_id][tp_path]
692 except Exception as ex:
693 self.log.error("del-tp-state-info", e=ex)
694
695 # TODO: There could be multiple TP on the UNI, and also the ONU.
696 # TODO: But the below reason updates for the whole device.
697 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
698
699 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530700 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530701 self.log.warn('tech-profile-delete-failure-retrying',
702 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500703 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
704 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500705 yield self.core_proxy.device_reason_update(self.device_id,
706 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530707
708 self.log.info('deleting-tech-profile-configuration')
709
Girish Gowdraa73ee452019-12-20 18:52:17 +0530710 if tcont is None and gem_port is None:
711 if alloc_id is not None:
712 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
713 if gem_port_id is not None:
714 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
715 return
716
Girish Gowdrae933cd32019-11-21 21:04:41 +0530717 self._tp_service_specific_task[uni_id][tp_path] = \
718 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
719 tcont=tcont, gem_port=gem_port)
720 self._deferred = \
721 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
722 self._deferred.addCallbacks(success, failure)
723 except Exception as e:
724 self.log.exception("failed-to-delete-tp",
725 e=e, uni_id=uni_id, tp_path=tp_path,
726 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500727
728 def update_pm_config(self, device, pm_config):
729 # TODO: This has not been tested
730 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500731 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500732
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800733 def remove_onu_flows(self, device, flows):
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500734 self.log.debug('remove-onu-flows')
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800735
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800736 # no point in removing omci flows if the device isnt reachable
737 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800738 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800739 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
740 admin=device.admin_state, connect=device.connect_status)
741 return
742
743 for flow in flows:
744 # if incoming flow contains cookie, then remove from ONU
745 if flow.cookie:
746 self.log.debug("remove-flow", device_id=device.id, flow=flow)
747
748 def is_downstream(port):
749 return port == self._pon_port_number
750
751 def is_upstream(port):
752 return not is_downstream(port)
753
754 try:
755 _in_port = fd.get_in_port(flow)
756 assert _in_port is not None
757
758 _out_port = fd.get_out_port(flow) # may be None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800759
760 if is_downstream(_in_port):
761 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
762 device_id=device.id)
763 # extended vlan tagging operation will handle it
764 continue
765 elif is_upstream(_in_port):
766 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
767 if fd.is_dhcp_flow(flow):
768 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
769 return
770
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800771 _vlan_vid = 0
772 # Retrieve the VLAN_VID that needs to be removed from the EVTO rule on the ONU.
773 for action in fd.get_actions(flow):
774 if action.type == fd.SET_FIELD:
775 _field = action.set_field.field.ofb_field
776 assert (action.set_field.field.oxm_class ==
777 OFPXMC_OPENFLOW_BASIC)
778 if _field.type == fd.VLAN_VID:
779 _vlan_vid = _field.vlan_vid & 0xfff
780 self.log.debug('vlan-vid-to-remove',
781 _vlan_vid=_vlan_vid, in_port=_in_port)
782
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800783 uni_port = self.uni_port(_in_port)
784 uni_id = _in_port & 0xF
785 else:
786 raise Exception('port should be 1 or 2 by our convention')
787
788 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
789
790 tp_id = self.get_tp_id_in_flow(flow)
791 # Deleting flow from ONU.
792 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800793 match_vlan=_vlan_vid, tp_id=tp_id)
794 # TODO:Delete TD task.
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800795 except Exception as e:
796 self.log.exception('failed-to-remove-flow', e=e)
797
798 def add_onu_flows(self, device, flows):
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500799 self.log.debug('add-onu-flows')
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800800
801 # no point in pushing omci flows if the device isnt reachable
802 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800803 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800804 self.log.warn("device-disabled-or-offline-skipping-flow-update",
805 admin=device.admin_state, connect=device.connect_status)
806 return
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800807
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800808 def is_downstream(port):
809 return port == self._pon_port_number
810
811 def is_upstream(port):
812 return not is_downstream(port)
813
814 for flow in flows:
815 # if incoming flow contains cookie, then add to ONU
816 if flow.cookie:
817 _type = None
818 _port = None
819 _vlan_vid = None
820 _udp_dst = None
821 _udp_src = None
822 _ipv4_dst = None
823 _ipv4_src = None
824 _metadata = None
825 _output = None
826 _push_tpid = None
827 _field = None
828 _set_vlan_vid = None
829 _set_vlan_pcp = 0
830 _tunnel_id = None
831 self.log.debug("add-flow", device_id=device.id, flow=flow)
832
833 try:
834 _in_port = fd.get_in_port(flow)
835 assert _in_port is not None
836
837 _out_port = fd.get_out_port(flow) # may be None
838 tp_id = self.get_tp_id_in_flow(flow)
839 if is_downstream(_in_port):
840 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
841 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
842 # uni_port = self.uni_port(_out_port)
843 # uni_id = _out_port & 0xF
844 continue
845 elif is_upstream(_in_port):
846 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
847 uni_port = self.uni_port(_in_port)
848 uni_id = _in_port & 0xF
849 else:
850 raise Exception('port should be 1 or 2 by our convention')
851
852 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
853
854 for field in fd.get_ofb_fields(flow):
855 if field.type == fd.ETH_TYPE:
856 _type = field.eth_type
857 self.log.debug('field-type-eth-type',
858 eth_type=_type)
859
860 elif field.type == fd.IP_PROTO:
861 _proto = field.ip_proto
862 self.log.debug('field-type-ip-proto',
863 ip_proto=_proto)
864
865 elif field.type == fd.IN_PORT:
866 _port = field.port
867 self.log.debug('field-type-in-port',
868 in_port=_port)
869 elif field.type == fd.TUNNEL_ID:
870 self.log.debug('field-type-tunnel-id')
871
872 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100873 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
874 _vlan_vid = RESERVED_TRANSPARENT_VLAN
875 else:
876 _vlan_vid = field.vlan_vid & 0xfff
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800877 self.log.debug('field-type-vlan-vid',
878 vlan=_vlan_vid)
879
880 elif field.type == fd.VLAN_PCP:
881 _vlan_pcp = field.vlan_pcp
882 self.log.debug('field-type-vlan-pcp',
883 pcp=_vlan_pcp)
884
885 elif field.type == fd.UDP_DST:
886 _udp_dst = field.udp_dst
887 self.log.debug('field-type-udp-dst',
888 udp_dst=_udp_dst)
889
890 elif field.type == fd.UDP_SRC:
891 _udp_src = field.udp_src
892 self.log.debug('field-type-udp-src',
893 udp_src=_udp_src)
894
895 elif field.type == fd.IPV4_DST:
896 _ipv4_dst = field.ipv4_dst
897 self.log.debug('field-type-ipv4-dst',
898 ipv4_dst=_ipv4_dst)
899
900 elif field.type == fd.IPV4_SRC:
901 _ipv4_src = field.ipv4_src
902 self.log.debug('field-type-ipv4-src',
903 ipv4_dst=_ipv4_src)
904
905 elif field.type == fd.METADATA:
906 _metadata = field.table_metadata
907 self.log.debug('field-type-metadata',
908 metadata=_metadata)
909
910 else:
911 raise NotImplementedError('field.type={}'.format(
912 field.type))
913
914 for action in fd.get_actions(flow):
915
916 if action.type == fd.OUTPUT:
917 _output = action.output.port
918 self.log.debug('action-type-output',
919 output=_output, in_port=_in_port)
920
921 elif action.type == fd.POP_VLAN:
922 self.log.debug('action-type-pop-vlan',
923 in_port=_in_port)
924
925 elif action.type == fd.PUSH_VLAN:
926 _push_tpid = action.push.ethertype
927 self.log.debug('action-type-push-vlan',
928 push_tpid=_push_tpid, in_port=_in_port)
929 if action.push.ethertype != 0x8100:
930 self.log.error('unhandled-tpid',
931 ethertype=action.push.ethertype)
932
933 elif action.type == fd.SET_FIELD:
934 _field = action.set_field.field.ofb_field
935 assert (action.set_field.field.oxm_class ==
936 OFPXMC_OPENFLOW_BASIC)
937 self.log.debug('action-type-set-field',
938 field=_field, in_port=_in_port)
939 if _field.type == fd.VLAN_VID:
940 _set_vlan_vid = _field.vlan_vid & 0xfff
941 self.log.debug('set-field-type-vlan-vid',
942 vlan_vid=_set_vlan_vid)
943 elif _field.type == fd.VLAN_PCP:
944 _set_vlan_pcp = _field.vlan_pcp
945 self.log.debug('set-field-type-vlan-pcp',
946 vlan_pcp=_set_vlan_pcp)
947 else:
948 self.log.error('unsupported-action-set-field-type',
949 field_type=_field.type)
950 else:
951 self.log.error('unsupported-action-type',
952 action_type=action.type, in_port=_in_port)
953
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800954 if self._set_vlan is not None:
955 if uni_id not in self._set_vlan:
956 self._set_vlan[uni_id] = dict()
957 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
958 self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
959
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100960 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
961 # supported match and action criteria cannot be handled by omci and must be ignored.
962 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
963 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
964 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
965 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800966 _set_vlan_vid=_vlan_vid,
967 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
968 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100969 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
970 _set_vlan_vid=_vlan_vid,
971 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
972 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800973 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100974 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
975 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800976 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
977 _set_vlan_vid=_set_vlan_vid,
978 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
979 tp_id=tp_id)
980
981 except Exception as e:
982 self.log.exception('failed-to-install-flow', e=e, flow=flow)
983
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500984 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
985 # flow decomposition that ultimately comes from onos
986 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700987 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500988
989 #
990 # We need to proxy through the OLT to get to the ONU
991 # Configuration from here should be using OMCI
992 #
993 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
994
995 # no point in pushing omci flows if the device isnt reachable
996 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530997 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500998 self.log.warn("device-disabled-or-offline-skipping-flow-update",
999 admin=device.admin_state, connect=device.connect_status)
1000 return
1001
1002 def is_downstream(port):
1003 return port == self._pon_port_number
1004
1005 def is_upstream(port):
1006 return not is_downstream(port)
1007
1008 for flow in flows:
1009 _type = None
1010 _port = None
1011 _vlan_vid = None
1012 _udp_dst = None
1013 _udp_src = None
1014 _ipv4_dst = None
1015 _ipv4_src = None
1016 _metadata = None
1017 _output = None
1018 _push_tpid = None
1019 _field = None
1020 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001021 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001022 _tunnel_id = None
1023
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001024 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +05301025 write_metadata = fd.get_write_metadata(flow)
1026 if write_metadata is None:
1027 self.log.error("do-not-process-flow-without-write-metadata")
1028 return
1029
1030 # extract tp id from flow
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001031 tp_id = self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001032 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +05301033
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001034 _in_port = fd.get_in_port(flow)
1035 assert _in_port is not None
1036
1037 _out_port = fd.get_out_port(flow) # may be None
1038
1039 if is_downstream(_in_port):
1040 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
1041 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301042 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001043 elif is_upstream(_in_port):
1044 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
1045 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001046 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001047 else:
1048 raise Exception('port should be 1 or 2 by our convention')
1049
1050 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
1051
1052 for field in fd.get_ofb_fields(flow):
1053 if field.type == fd.ETH_TYPE:
1054 _type = field.eth_type
1055 self.log.debug('field-type-eth-type',
1056 eth_type=_type)
1057
1058 elif field.type == fd.IP_PROTO:
1059 _proto = field.ip_proto
1060 self.log.debug('field-type-ip-proto',
1061 ip_proto=_proto)
1062
1063 elif field.type == fd.IN_PORT:
1064 _port = field.port
1065 self.log.debug('field-type-in-port',
1066 in_port=_port)
1067
1068 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001069 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
1070 _vlan_vid = RESERVED_TRANSPARENT_VLAN
1071 else:
1072 _vlan_vid = field.vlan_vid & 0xfff
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001073 self.log.debug('field-type-vlan-vid',
1074 vlan=_vlan_vid)
1075
1076 elif field.type == fd.VLAN_PCP:
1077 _vlan_pcp = field.vlan_pcp
1078 self.log.debug('field-type-vlan-pcp',
1079 pcp=_vlan_pcp)
1080
1081 elif field.type == fd.UDP_DST:
1082 _udp_dst = field.udp_dst
1083 self.log.debug('field-type-udp-dst',
1084 udp_dst=_udp_dst)
1085
1086 elif field.type == fd.UDP_SRC:
1087 _udp_src = field.udp_src
1088 self.log.debug('field-type-udp-src',
1089 udp_src=_udp_src)
1090
1091 elif field.type == fd.IPV4_DST:
1092 _ipv4_dst = field.ipv4_dst
1093 self.log.debug('field-type-ipv4-dst',
1094 ipv4_dst=_ipv4_dst)
1095
1096 elif field.type == fd.IPV4_SRC:
1097 _ipv4_src = field.ipv4_src
1098 self.log.debug('field-type-ipv4-src',
1099 ipv4_dst=_ipv4_src)
1100
1101 elif field.type == fd.METADATA:
1102 _metadata = field.table_metadata
1103 self.log.debug('field-type-metadata',
1104 metadata=_metadata)
1105
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001106 elif field.type == fd.TUNNEL_ID:
1107 _tunnel_id = field.tunnel_id
1108 self.log.debug('field-type-tunnel-id',
1109 tunnel_id=_tunnel_id)
1110
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001111
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001112 else:
1113 raise NotImplementedError('field.type={}'.format(
1114 field.type))
1115
1116 for action in fd.get_actions(flow):
1117
1118 if action.type == fd.OUTPUT:
1119 _output = action.output.port
1120 self.log.debug('action-type-output',
1121 output=_output, in_port=_in_port)
1122
1123 elif action.type == fd.POP_VLAN:
1124 self.log.debug('action-type-pop-vlan',
1125 in_port=_in_port)
1126
1127 elif action.type == fd.PUSH_VLAN:
1128 _push_tpid = action.push.ethertype
1129 self.log.debug('action-type-push-vlan',
1130 push_tpid=_push_tpid, in_port=_in_port)
1131 if action.push.ethertype != 0x8100:
1132 self.log.error('unhandled-tpid',
1133 ethertype=action.push.ethertype)
1134
1135 elif action.type == fd.SET_FIELD:
1136 _field = action.set_field.field.ofb_field
1137 assert (action.set_field.field.oxm_class ==
1138 OFPXMC_OPENFLOW_BASIC)
1139 self.log.debug('action-type-set-field',
1140 field=_field, in_port=_in_port)
1141 if _field.type == fd.VLAN_VID:
1142 _set_vlan_vid = _field.vlan_vid & 0xfff
1143 self.log.debug('set-field-type-vlan-vid',
1144 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001145 elif _field.type == fd.VLAN_PCP:
1146 _set_vlan_pcp = _field.vlan_pcp
1147 self.log.debug('set-field-type-vlan-pcp',
1148 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001149 else:
1150 self.log.error('unsupported-action-set-field-type',
1151 field_type=_field.type)
1152 else:
1153 self.log.error('unsupported-action-type',
1154 action_type=action.type, in_port=_in_port)
1155
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001156 if self._set_vlan is not None:
1157 if uni_id not in self._set_vlan:
1158 self._set_vlan[uni_id] = dict()
1159 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
1160 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 -04001161 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1162 # supported match and action criteria cannot be handled by omci and must be ignored.
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001163 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
1164 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
1165 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
1166 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001167 _set_vlan_vid=_vlan_vid,
1168 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1169 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001170 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1171 _set_vlan_vid=_vlan_vid,
1172 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1173 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001174 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001175 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
1176 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
1177 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1178 _set_vlan_vid=_set_vlan_vid,
1179 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1180 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001181 except Exception as e:
1182 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1183
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001184 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001185 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1186 self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1187 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001188 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001189 if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and \
1190 self._tech_profile_download_done[uni_id][tp_id] is True:
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001191 @inlineCallbacks
1192 def success(_results):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001193 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id,
1194 set_vlan_pcp=_set_vlan_pcp)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001195 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001196
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001197 @inlineCallbacks
1198 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301199 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 -08001200 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1201 reactor.callLater(retry,
1202 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1203 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1204 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001205 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001206
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001207 self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1208 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001209 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001210 match_vlan, _set_vlan_pcp, add_tag=True,
1211 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001212 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001213 self._deferred.addCallbacks(success, failure)
1214 else:
1215 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001216 uni_id=uni_id, tp_id=tp_id)
1217 if uni_id not in self._queued_vlan_filter_task:
1218 self._queued_vlan_filter_task[uni_id] = dict()
Mahir Gunyela982ec32020-02-25 12:30:37 -08001219 if tp_id not in self._queued_vlan_filter_task[uni_id]:
1220 self._queued_vlan_filter_task[uni_id][tp_id] = []
1221 self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001222 "uni_id": uni_id,
1223 "uni_port": uni_port,
1224 "match_vlan": match_vlan,
1225 "set_vlan_vid": _set_vlan_vid,
1226 "set_vlan_pcp": _set_vlan_pcp,
1227 "tp_id": tp_id})
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001228
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001229 def get_tp_id_in_flow(self, flow):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001230 flow_metadata = fd.get_metadata_from_write_metadata(flow)
1231 tp_id = fd.get_tp_id_from_metadata(flow_metadata)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001232 return tp_id
1233
1234 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001235 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001236 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001237
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001238 @inlineCallbacks
1239 def success(_results):
1240 self.log.info('vlan-untagging-success', _results=_results)
1241 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1242
1243 @inlineCallbacks
1244 def failure(_reason):
1245 self.log.warn('vlan-untagging-failure', _reason=_reason)
1246 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001247 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001248 reactor.callLater(retry,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001249 self._remove_vlan_filter_task, device, uni_id,
1250 add_tag=False, uni_port=uni_port)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001251
1252 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1253 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001254 match_vlan, _set_vlan_pcp, add_tag=False,
1255 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001256 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1257 self._deferred.addCallbacks(success, failure)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001258
Matt Jeannereta32441c2019-03-07 05:16:37 -05001259 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001260 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1261 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001262 try:
1263 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1264 omci_msg = InterAdapterOmciMessage()
1265 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001266 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001267
Matt Jeannereta32441c2019-03-07 05:16:37 -05001268 self.receive_message(omci_msg.message)
1269
1270 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1271 onu_indication = OnuIndication()
1272 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001273 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1274 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1275 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001276
1277 if onu_indication.oper_state == "up":
1278 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301279 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001280 self.update_interface(onu_indication)
1281 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001282 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1283 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001284
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001285 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1286 tech_msg = InterAdapterTechProfileDownloadMessage()
1287 request.body.Unpack(tech_msg)
1288 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1289
1290 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1291
Girish Gowdrae933cd32019-11-21 21:04:41 +05301292 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1293 del_gem_msg = InterAdapterDeleteGemPortMessage()
1294 request.body.Unpack(del_gem_msg)
1295 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1296
1297 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1298 gem_port_id=del_gem_msg.gem_port_id,
1299 tp_path=del_gem_msg.tp_path)
1300
1301 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1302 del_tcont_msg = InterAdapterDeleteTcontMessage()
1303 request.body.Unpack(del_tcont_msg)
1304 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1305
1306 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1307 alloc_id=del_tcont_msg.alloc_id,
1308 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001309 else:
1310 self.log.error("inter-adapter-unhandled-type", request=request)
1311
1312 except Exception as e:
1313 self.log.exception("error-processing-inter-adapter-message", e=e)
1314
1315 # Called each time there is an onu "up" indication from the olt handler
1316 @inlineCallbacks
1317 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001318 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001319 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001320
1321 # Ignore if onu_indication is received for an already running ONU
1322 if self._onu_omci_device is not None and self._onu_omci_device.active:
1323 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1324 return
1325
Matt Jeannereta32441c2019-03-07 05:16:37 -05001326 self._onu_indication = onu_indication
1327
Matt Jeanneretc083f462019-03-11 15:02:01 -04001328 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1329 connect_status=ConnectStatus.REACHABLE)
1330
Matt Jeannereta32441c2019-03-07 05:16:37 -05001331 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001332
1333 self.log.debug('starting-openomci-statemachine')
1334 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001335 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301336 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001337 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001338 self._heartbeat.enabled = True
1339
Matt Jeanneret42dad792020-02-01 09:28:27 -05001340 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001341 @inlineCallbacks
1342 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001343 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001344 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001345
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001346 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001347 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001348 reactor.callLater(0, self._onu_omci_device.stop)
1349
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001350 self._tp = dict()
1351
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001352 # Let TP download happen again
1353 for uni_id in self._tp_service_specific_task:
1354 self._tp_service_specific_task[uni_id].clear()
1355 for uni_id in self._tech_profile_download_done:
1356 self._tech_profile_download_done[uni_id].clear()
1357
Matt Jeanneretf4113222019-08-14 19:44:34 -04001358 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001359 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1360 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1361 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001362 else:
1363 self.log.debug('not-changing-openomci-statemachine')
1364
Matt Jeanneretf4113222019-08-14 19:44:34 -04001365 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001366 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001367 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001368 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001369 yield self.disable_ports(lock_ports=True)
1370 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1371 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001372
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001373 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001374 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001375
William Kurkian3a206332019-04-29 11:05:47 -04001376 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001377 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001378 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001379 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001380 yield self.core_proxy.device_state_update(device.id,
1381 oper_status=OperStatus.ACTIVE,
1382 connect_status=ConnectStatus.REACHABLE)
1383 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1384 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001385 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001386 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001387
William Kurkian3a206332019-04-29 11:05:47 -04001388 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001389 def reboot(self):
1390 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001391 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001392 if device.connect_status != ConnectStatus.REACHABLE:
1393 self.log.error("device-unreachable")
1394 return
1395
William Kurkian3a206332019-04-29 11:05:47 -04001396 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001397 def success(_results):
1398 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001399 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001400
1401 def failure(_reason):
1402 self.log.info('reboot-failure', _reason=_reason)
1403
1404 self._deferred = self._onu_omci_device.reboot()
1405 self._deferred.addCallbacks(success, failure)
1406
William Kurkian3a206332019-04-29 11:05:47 -04001407 @inlineCallbacks
Matt Jeanneretf4113222019-08-14 19:44:34 -04001408 def disable_ports(self, lock_ports=True):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001409 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001410
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001411 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1412 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001413 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001414 if port.mac_bridge_port_num == 1:
1415 port.operstatus = OperStatus.UNKNOWN
1416 self.log.info('disable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001417 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1418 port.operstatus)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001419
1420 if lock_ports is True:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001421 self.lock_ports(lock=True)
1422
William Kurkian3a206332019-04-29 11:05:47 -04001423 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001424 def enable_ports(self):
1425 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001426
Matt Jeanneretf4113222019-08-14 19:44:34 -04001427 self.lock_ports(lock=False)
1428
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001429 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1430 # load on the core
1431 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001432 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001433 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001434 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001435 self.log.info('enable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001436 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1437 port.operstatus)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001438
1439 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1440 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1441 #
1442 # Basically the link state sequence:
1443 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1444 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1445 # 3) a link state up alarm is received for the uni plugged in.
1446 #
1447 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1448 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1449 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1450 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001451 @inlineCallbacks
1452 def port_state_handler(self, _topic, msg):
1453 self.log.info("port-state-change", _topic=_topic, msg=msg)
1454
1455 onu_id = msg['onu_id']
1456 port_no = msg['port_number']
1457 serial_number = msg['serial_number']
1458 port_status = msg['port_status']
1459 uni_port = self.uni_port(int(port_no))
1460
1461 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1462 port_status=port_status)
1463
1464 if port_status is True:
1465 uni_port.operstatus = OperStatus.ACTIVE
1466 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1467 else:
1468 uni_port.operstatus = OperStatus.UNKNOWN
1469 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1470
1471 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 -05001472 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001473
1474 # Called just before openomci state machine is started. These listen for events from selected state machines,
1475 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1476 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001477 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001478
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001479 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001480
1481 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001482 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1483 OnuDeviceEvents.MibDatabaseSyncEvent)
1484 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1485
1486 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001487 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1488 OnuDeviceEvents.OmciCapabilitiesEvent)
1489 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1490
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001491 # TODO: these alarms seem to be unreliable depending on the environment
1492 # 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 -08001493 # topic = OnuDeviceEntry.event_bus_topic(self.device_id,
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001494 # OnuDeviceEvents.PortEvent)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001495 # self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001496
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001497 # Called when the mib is in sync
1498 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001499 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001500 if self._in_sync_subscription is not None:
1501 try:
1502 in_sync = msg[IN_SYNC_KEY]
1503
1504 if in_sync:
1505 # Only call this once
1506 bus = self._onu_omci_device.event_bus
1507 bus.unsubscribe(self._in_sync_subscription)
1508 self._in_sync_subscription = None
1509
1510 # Start up device_info load
1511 self.log.debug('running-mib-sync')
1512 reactor.callLater(0, self._mib_in_sync)
1513
1514 except Exception as e:
1515 self.log.exception('in-sync', e=e)
1516
1517 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001518 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001519 if self._capabilities_subscription is not None:
1520 self.log.debug('capabilities-handler-done')
1521
1522 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1523 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1524 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001525 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001526 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001527 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001528
1529 omci = self._onu_omci_device
1530 in_sync = omci.mib_db_in_sync
1531
Matt Jeanneretc083f462019-03-11 15:02:01 -04001532 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001533 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001534
1535 if not self._dev_info_loaded:
1536 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1537
1538 omci_dev = self._onu_omci_device
1539 config = omci_dev.configuration
1540
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001541 try:
1542
1543 # sort the lists so we get consistent port ordering.
1544 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1545 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1546 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1547 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1548
1549 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001550 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001551 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001552 raise Exception("onu-missing-required-elements")
1553
1554 # Currently logging the ani, pptp, veip, and uni for information purposes.
1555 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1556 # And in some ONU the UNI-G list is incomplete or incorrect...
1557 for entity_id in ani_list:
1558 ani_value = config.ani_g_entities[entity_id]
1559 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1560 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1561 self._total_tcont_count = ani_value.get('total-tcont-count')
1562 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1563
1564 for entity_id in uni_list:
1565 uni_value = config.uni_g_entities[entity_id]
1566 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1567
1568 uni_entities = OrderedDict()
1569 for entity_id in pptp_list:
1570 pptp_value = config.pptp_entities[entity_id]
1571 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1572 uni_entities[entity_id] = UniType.PPTP
1573
1574 for entity_id in veip_list:
1575 veip_value = config.veip_entities[entity_id]
1576 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1577 uni_entities[entity_id] = UniType.VEIP
1578
1579 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001580 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001581 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001582 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001583 uni_id += 1
1584 except AssertionError as e:
1585 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1586
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001587 self._qos_flexibility = config.qos_configuration_flexibility or 0
1588 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1589
1590 if self._unis:
1591 self._dev_info_loaded = True
1592 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001593 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001594 self.log.warn("no-usable-unis")
1595 raise Exception("no-usable-unis")
1596
1597 except Exception as e:
1598 self.log.exception('device-info-load', e=e)
1599 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1600
1601 else:
1602 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1603
1604 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001605 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001606
1607 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001608 def success(_results):
1609 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001610 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301611 oper_status=OperStatus.ACTIVE,
1612 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001613 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001614 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001615 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001616 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001617
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001618 # Start collecting stats from the device after a brief pause
1619 if not self._pm_metrics_started:
1620 self._pm_metrics_started = True
1621 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1622 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1623
1624 # Start test requests after a brief pause
1625 if not self._test_request_started:
1626 self._test_request_started = True
1627 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1628 reactor.callLater(tststart, self._test_request.start_collector)
1629
Matt Jeanneretc083f462019-03-11 15:02:01 -04001630 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001631 def failure(_reason):
1632 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001633 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001634 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001635 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001636
Matt Jeanneretf4113222019-08-14 19:44:34 -04001637 # start by locking all the unis till mib sync and initial mib is downloaded
1638 # this way we can capture the port down/up events when we are ready
1639 self.lock_ports(lock=True)
1640
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001641 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1642 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1643 self.log.info('downloading-initial-mib-configuration')
1644 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1645 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1646 self._deferred.addCallbacks(success, failure)
1647 else:
1648 self.log.info('admin-down-disabling')
1649 self.disable(device)
1650 else:
1651 self.log.info('device-info-not-loaded-skipping-mib-download')
1652
Matt Jeanneretc083f462019-03-11 15:02:01 -04001653 @inlineCallbacks
1654 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001655 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001656
Matt Jeanneretc083f462019-03-11 15:02:01 -04001657 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 -05001658
1659 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1660 uni_name = "uni-{}".format(uni_no)
1661
Girish Gowdrae933cd32019-11-21 21:04:41 +05301662 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001663
1664 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 -04001665 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001666
1667 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1668 uni_port.entity_id = entity_id
1669 uni_port.enabled = True
1670 uni_port.mac_bridge_port_num = mac_bridge_port_num
1671
1672 self.log.debug("created-uni-port", uni=uni_port)
1673
Matt Jeanneretc083f462019-03-11 15:02:01 -04001674 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001675
1676 self._unis[uni_port.port_number] = uni_port
1677
1678 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301679 uni_ports=self.uni_ports,
1680 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001681
Matt Jeanneretc083f462019-03-11 15:02:01 -04001682 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1683 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001684 MAX_PONS_PER_OLT = 256
1685 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001686 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001687
Matt Jeanneretc083f462019-03-11 15:02:01 -04001688 assert intf_id < MAX_PONS_PER_OLT
1689 assert onu_id < MAX_ONUS_PER_PON
1690 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001691 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001692
1693 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001694 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001695 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001696 try:
1697 device = yield self.core_proxy.get_device(self.device_id)
1698 parent_device = yield self.core_proxy.get_device(self.parent_id)
1699 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001700 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001701
1702 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301703 pon_id=self._onu_indication.intf_id,
1704 onu_id=self._onu_indication.onu_id,
1705 registration_id=self.device_id,
1706 device_id=self.device_id,
1707 onu_serial_number=device.serial_number,
1708 olt_serial_number=olt_serial_number,
1709 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001710
Devmalya Paulffc89df2019-07-31 17:43:13 -04001711 self.log.debug("Trying-to-raise-onu-active-event")
1712 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001713 self._onu_indication.intf_id,
1714 device.serial_number,
1715 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301716 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001717 onu_id=self._onu_indication.onu_id).send(True)
1718 except Exception as active_event_error:
1719 self.log.exception('onu-activated-event-error',
1720 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001721
1722 def lock_ports(self, lock=True):
1723
1724 def success(response):
1725 self.log.debug('set-onu-ports-state', lock=lock, response=response)
1726
1727 def failure(response):
1728 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1729
1730 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1731 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1732 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001733
1734 def extract_tp_id_from_path(self, tp_path):
1735 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001736 tp_id = int(tp_path.split(_PATH_SEPERATOR)[1])
1737 return tp_id