blob: 0e05a5107f222e051f103eeb05cebb494860b92c [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
2# Copyright 2017 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17"""
18Broadcom OpenOMCI OLT/ONU adapter handler.
19"""
20
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050021from __future__ import absolute_import
22import six
Devmalya Paulffc89df2019-07-31 17:43:13 -040023import arrow
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050024import structlog
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050025import json
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050026import random
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050027
28from collections import OrderedDict
29
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050030from twisted.internet import reactor
31from twisted.internet.defer import DeferredQueue, inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050032
33from heartbeat import HeartBeat
Devmalya Paulffc89df2019-07-31 17:43:13 -040034from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent
Devmalya Paule2e5f2b2020-03-08 18:50:33 -040035from pyvoltha.adapters.extensions.events.device_events.onu.onu_disabled_event import OnuDisabledEvent
Devmalya Paulffc89df2019-07-31 17:43:13 -040036from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
37from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
38from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050039
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050040import pyvoltha.common.openflow.utils as fd
41from pyvoltha.common.utils.registry import registry
Matteo Scandolod8d73172019-11-26 12:15:15 -070042from pyvoltha.adapters.common.frameio.frameio import hexify
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050043from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050044from pyvoltha.common.config.config_backend import ConsulStore
45from pyvoltha.common.config.config_backend import EtcdStore
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050046from voltha_protos.logical_device_pb2 import LogicalPort
William Kurkian8235c1e2019-03-05 12:58:28 -050047from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretf4113222019-08-14 19:44:34 -040048from voltha_protos.device_pb2 import Port
Girish Gowdra4c11ddb2020-03-03 11:33:24 -080049from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE, OFPPS_LINK_DOWN, \
Matt Jeanneretf4113222019-08-14 19:44:34 -040050 OFPPF_FIBER, OFPPF_1GB_FD
Matt Jeanneret3bfebff2019-04-12 18:25:03 -040051from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
Girish Gowdrae933cd32019-11-21 21:04:41 +053052 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
53 InterAdapterDeleteTcontMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050054from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050055from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
56from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050057 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050058from omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdrae933cd32019-11-21 21:04:41 +053059from omci.brcm_tp_setup_task import BrcmTpSetupTask
60from omci.brcm_tp_delete_task import BrcmTpDeleteTask
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050061from omci.brcm_uni_lock_task import BrcmUniLockTask
62from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050063from onu_gem_port import OnuGemPort
64from onu_tcont import OnuTCont
65from pon_port import PonPort
Mahir Gunyel5de33fe2020-03-03 22:38:44 -080066from omci.brcm_mcast_task import BrcmMcastTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050067from uni_port import UniPort, UniType
Andrea Campanellacf916ea2020-02-14 10:03:58 +010068from uni_port import RESERVED_TRANSPARENT_VLAN
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050069from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053070from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
71from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050072from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050073
74OP = EntityOperations
75RC = ReasonCodes
76
Mahir Gunyel5de33fe2020-03-03 22:38:44 -080077IS_MULTICAST='is_multicast'
78GEM_PORT_ID = 'gemport_id'
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050079_STARTUP_RETRY_WAIT = 10
Mahir Gunyele9110a32020-02-20 14:56:50 -080080_PATH_SEPERATOR = "/"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050081
82
83class BrcmOpenomciOnuHandler(object):
84
85 def __init__(self, adapter, device_id):
86 self.log = structlog.get_logger(device_id=device_id)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050087 self.log.debug('starting-handler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050088 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050089 self.core_proxy = adapter.core_proxy
90 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050091 self.parent_id = None
92 self.device_id = device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050093 self.proxy_address = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050094 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040095 self.events = None
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050096 self._pm_metrics = None
97 self._pm_metrics_started = False
98 self._test_request = None
99 self._test_request_started = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500100 self._omcc_version = OMCCVersion.Unknown
101 self._total_tcont_count = 0 # From ANI-G ME
102 self._qos_flexibility = 0 # From ONT2_G ME
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800103 self._tp = dict() #tp_id -> technology profile definition in KV Store.
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500104 self._onu_indication = None
105 self._unis = dict() # Port # -> UniPort
106
107 self._pon = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500108 self._pon_port_number = 100
109 self.logical_device_id = None
110
111 self._heartbeat = HeartBeat.create(self, device_id)
112
113 # Set up OpenOMCI environment
114 self._onu_omci_device = None
115 self._dev_info_loaded = False
116 self._deferred = None
117
118 self._in_sync_subscription = None
Matt Jeanneretf4113222019-08-14 19:44:34 -0400119 self._port_state_subscription = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500120 self._connectivity_subscription = None
121 self._capabilities_subscription = None
122
123 self.mac_bridge_service_profile_entity_id = 0x201
124 self.gal_enet_profile_entity_id = 0x1
125
126 self._tp_service_specific_task = dict()
127 self._tech_profile_download_done = dict()
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400128 # Stores information related to queued vlan filter tasks
129 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
130
131 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500132
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800133 self._set_vlan = dict() #uni_id, tp_id -> set_vlan_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500134 # Initialize KV store client
135 self.args = registry('main').get_args()
136 if self.args.backend == 'etcd':
137 host, port = self.args.etcd.split(':', 1)
138 self.kv_client = EtcdStore(host, port,
139 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
140 elif self.args.backend == 'consul':
141 host, port = self.args.consul.split(':', 1)
142 self.kv_client = ConsulStore(host, port,
143 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
144 else:
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500145 self.log.error('invalid-backend')
146 raise Exception("invalid-backend-for-kv-store")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500147
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500148 @property
149 def enabled(self):
150 return self._enabled
151
152 @enabled.setter
153 def enabled(self, value):
154 if self._enabled != value:
155 self._enabled = value
156
157 @property
158 def omci_agent(self):
159 return self.adapter.omci_agent
160
161 @property
162 def omci_cc(self):
163 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
164
165 @property
166 def heartbeat(self):
167 return self._heartbeat
168
169 @property
170 def uni_ports(self):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500171 return list(self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500172
173 def uni_port(self, port_no_or_name):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500174 if isinstance(port_no_or_name, six.string_types):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500175 return next((uni for uni in self.uni_ports
176 if uni.name == port_no_or_name), None)
177
178 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
179 return next((uni for uni in self.uni_ports
Girish Gowdrae933cd32019-11-21 21:04:41 +0530180 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500181
182 @property
183 def pon_port(self):
184 return self._pon
185
Girish Gowdraa73ee452019-12-20 18:52:17 +0530186 @property
187 def onu_omci_device(self):
188 return self._onu_omci_device
189
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500190 def receive_message(self, msg):
191 if self.omci_cc is not None:
192 self.omci_cc.receive_message(msg)
193
Matt Jeanneretc083f462019-03-11 15:02:01 -0400194 def get_ofp_port_info(self, device, port_no):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500195 self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400196 cap = OFPPF_1GB_FD | OFPPF_FIBER
197
Girish Gowdrae933cd32019-11-21 21:04:41 +0530198 hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
199 ((device.parent_port_no >> 8 & 0xff),
200 device.parent_port_no & 0xff,
201 (port_no >> 16) & 0xff,
202 (port_no >> 8) & 0xff,
203 port_no & 0xff))
Matt Jeanneretc083f462019-03-11 15:02:01 -0400204
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400205 uni_port = self.uni_port(int(port_no))
206 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500207 self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port)
Matt Jeanneretf4113222019-08-14 19:44:34 -0400208
209 ofstate = OFPPS_LINK_DOWN
210 if uni_port.operstatus is OperStatus.ACTIVE:
211 ofstate = OFPPS_LIVE
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400212
Matt Jeanneretc083f462019-03-11 15:02:01 -0400213 return PortCapability(
214 port=LogicalPort(
215 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400216 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400217 hw_addr=hw_addr,
218 config=0,
Matt Jeanneretf4113222019-08-14 19:44:34 -0400219 state=ofstate,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400220 curr=cap,
221 advertised=cap,
222 peer=cap,
223 curr_speed=OFPPF_1GB_FD,
224 max_speed=OFPPF_1GB_FD
225 ),
226 device_id=device.id,
227 device_port_no=port_no
228 )
229 )
230
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500231 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500232 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500233 def activate(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700234 self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500235
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500236 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500237 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500238 assert device.proxy_address.device_id
239
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500240 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500241 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500242 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500243 if self.enabled is not True:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700244 self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500245 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500246 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500247 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500248 device.reason = 'activating-onu'
249
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500250 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400251 # pm_metrics requires a logical device id. For now set to just device_id
252 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500253
Matt Jeannereta32441c2019-03-07 05:16:37 -0500254 yield self.core_proxy.device_update(device)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500255 self.log.debug('device-updated', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500256
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700257 yield self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500258
Matteo Scandolod8d73172019-11-26 12:15:15 -0700259 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500260 ############################################################################
Devmalya Paulffc89df2019-07-31 17:43:13 -0400261 # Setup Alarm handler
262 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
263 device.serial_number)
264 ############################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500265 # Setup PM configuration for this device
266 # Pass in ONU specific options
267 kwargs = {
268 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
269 'heartbeat': self.heartbeat,
270 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
271 }
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500272 self.log.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500273 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800274 self.logical_device_id, device.serial_number,
275 grouped=True, freq_override=False, **kwargs)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500276 pm_config = self._pm_metrics.make_proto()
277 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530278 self.log.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500279 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500280
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500281 # Note, ONU ID and UNI intf set in add_uni_port method
Devmalya Paulffc89df2019-07-31 17:43:13 -0400282 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500283 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500284
onkarkundargiaae99712019-09-23 15:02:52 +0530285 # Code to Run OMCI Test Action
286 kwargs_omci_test_action = {
287 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
288 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
289 }
290 serial_number = device.serial_number
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500291 self._test_request = OmciTestRequest(self.core_proxy,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800292 self.omci_agent, self.device_id,
293 AniG, serial_number,
294 self.logical_device_id,
295 exclusive=False,
296 **kwargs_omci_test_action)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500297
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500298 self.enabled = True
299 else:
300 self.log.info('onu-already-activated')
301
302 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400303 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500304 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700305 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500306
307 # first we verify that we got parent reference and proxy info
308 assert device.parent_id
309 assert device.proxy_address.device_id
310
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700311 self.proxy_address = device.proxy_address
312 self.parent_id = device.parent_id
313 self._pon_port_number = device.parent_port_no
314
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500315 if self.enabled is not True:
316 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700317 self.logical_device_id = self.device_id
318 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500319
320 # need to restart state machines on vcore restart. there is no indication to do it for us.
321 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700322 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500323
324 # TODO: this is probably a bit heavy handed
325 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
326 # This may not be necessary when mib resync actually works
327 reactor.callLater(1, self.reboot)
328
329 self.enabled = True
330 else:
331 self.log.info('onu-already-activated')
332
333 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700334 def _init_pon_state(self):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500335 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 -0500336
337 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500338 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700339 self.log.debug('adding-pon-port-to-agent',
340 type=self._pon.get_port().type,
341 admin_state=self._pon.get_port().admin_state,
342 oper_status=self._pon.get_port().oper_status,
343 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500344
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700345 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500346
Matteo Scandolod8d73172019-11-26 12:15:15 -0700347 self.log.debug('added-pon-port-to-agent',
348 type=self._pon.get_port().type,
349 admin_state=self._pon.get_port().admin_state,
350 oper_status=self._pon.get_port().oper_status,
351 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500352
353 # Create and start the OpenOMCI ONU Device Entry for this ONU
354 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500355 self.core_proxy,
356 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500357 support_classes=self.adapter.broadcom_omci,
358 custom_me_map=self.adapter.custom_me_entities())
359 # Port startup
360 if self._pon is not None:
361 self._pon.enabled = True
362
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500363 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700364 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret42dad792020-02-01 09:28:27 -0500365
366 self._deferred.cancel()
367 self._test_request.stop_collector()
368 self._pm_metrics.stop_collector()
369 self.log.debug('removing-openomci-statemachine')
370 self.omci_agent.remove_device(device.id, cleanup=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500371
372 def _create_tconts(self, uni_id, us_scheduler):
373 alloc_id = us_scheduler['alloc_id']
374 q_sched_policy = us_scheduler['q_sched_policy']
375 self.log.debug('create-tcont', us_scheduler=us_scheduler)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800376 # TODO: revisit for multi tconts support
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800377 new_tconts = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500378 tcontdict = dict()
379 tcontdict['alloc-id'] = alloc_id
380 tcontdict['q_sched_policy'] = q_sched_policy
381 tcontdict['uni_id'] = uni_id
382
Matt Jeanneret3789d0d2020-01-19 09:03:42 -0500383 tcont = OnuTCont.create(self, tcont=tcontdict)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500384
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500385 success = self._pon.add_tcont(tcont)
386 if success:
387 new_tconts.append(tcont)
388 self.log.debug('pon-add-tcont', tcont=tcont)
389
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800390 return new_tconts
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500391
392 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
393 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
394 self.log.debug('create-gemport',
395 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530396 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500397 for gem_port in gem_ports:
398 gemdict = dict()
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800399 if gem_port[IS_MULTICAST] == 'True':
400 gemdict[GEM_PORT_ID] = gem_port['multicast_gem_id']
401 gemdict[IS_MULTICAST] = True
402 else:
403 gemdict[GEM_PORT_ID] = gem_port[GEM_PORT_ID]
404 gemdict[IS_MULTICAST] = False
405
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500406 gemdict['direction'] = direction
407 gemdict['alloc_id_ref'] = alloc_id_ref
408 gemdict['encryption'] = gem_port['aes_encryption']
409 gemdict['discard_config'] = dict()
410 gemdict['discard_config']['max_probability'] = \
411 gem_port['discard_config']['max_probability']
412 gemdict['discard_config']['max_threshold'] = \
413 gem_port['discard_config']['max_threshold']
414 gemdict['discard_config']['min_threshold'] = \
415 gem_port['discard_config']['min_threshold']
416 gemdict['discard_policy'] = gem_port['discard_policy']
417 gemdict['max_q_size'] = gem_port['max_q_size']
418 gemdict['pbit_map'] = gem_port['pbit_map']
419 gemdict['priority_q'] = gem_port['priority_q']
420 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
421 gemdict['weight'] = gem_port['weight']
422 gemdict['uni_id'] = uni_id
423
424 gem_port = OnuGemPort.create(self, gem_port=gemdict)
425
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500426 success = self._pon.add_gem_port(gem_port, True)
427 if success:
428 new_gem_ports.append(gem_port)
429 self.log.debug('pon-add-gemport', gem_port=gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500430
Girish Gowdrae933cd32019-11-21 21:04:41 +0530431 return new_gem_ports
432
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800433 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400434 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
435 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
436 # or initial-mib-download is not done. Once the tp_task is completed, we execute
437 # such queued vlan-filter tasks
438 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800439 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 -0400440 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800441 uni_id=uni_id, tp_id=tp_id)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800442 for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]:
443 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800444 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
445 match_vlan=filter_info.get("match_vlan"),
446 _set_vlan_vid=filter_info.get("set_vlan_vid"),
447 _set_vlan_pcp=filter_info.get("set_vlan_pcp"),
448 tp_id=filter_info.get("tp_id"))
Girish Gowdraaf98a082020-03-05 16:40:51 -0800449 # Now remove the entry from the dictionary
450 self._queued_vlan_filter_task[uni_id][tp_id].remove(filter_info)
451 self.log.debug("executed-queued-vlan-filter-task",
452 uni_id=uni_id, tp_id=tp_id)
453 # Now delete the key entries once we have handled the queued vlan filter tasks.
454 del self._queued_vlan_filter_task[uni_id]
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400455 except Exception as e:
456 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
457
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500458 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500459 us_scheduler = tp['us_scheduler']
460 alloc_id = us_scheduler['alloc_id']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800461 new_tconts = self._create_tconts(uni_id, us_scheduler)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500462 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800463 new_upstream_gems = self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500464 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800465 new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
466
467 new_gems = []
468 new_gems.extend(new_upstream_gems)
469 new_gems.extend(new_downstream_gems)
470
471 return new_tconts, new_gems
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500472
473 def load_and_configure_tech_profile(self, uni_id, tp_path):
474 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyele9110a32020-02-20 14:56:50 -0800475 tp_id = self.extract_tp_id_from_path(tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500476 if uni_id not in self._tp_service_specific_task:
477 self._tp_service_specific_task[uni_id] = dict()
478
479 if uni_id not in self._tech_profile_download_done:
480 self._tech_profile_download_done[uni_id] = dict()
481
Mahir Gunyele9110a32020-02-20 14:56:50 -0800482 if tp_id not in self._tech_profile_download_done[uni_id]:
483 self._tech_profile_download_done[uni_id][tp_id] = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500484
Mahir Gunyele9110a32020-02-20 14:56:50 -0800485 if not self._tech_profile_download_done[uni_id][tp_id]:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500486 try:
487 if tp_path in self._tp_service_specific_task[uni_id]:
488 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530489 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500490 return
491
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500492 tpstored = self.kv_client[tp_path]
493 tpstring = tpstored.decode('ascii')
494 tp = json.loads(tpstring)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800495 self._tp[tp_id] = tp
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500496 self.log.debug("tp-instance", tp=tp)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800497 tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700498
William Kurkian3a206332019-04-29 11:05:47 -0400499 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500500 def success(_results):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800501 self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500502 if tp_path in self._tp_service_specific_task[uni_id]:
503 del self._tp_service_specific_task[uni_id][tp_path]
Mahir Gunyele9110a32020-02-20 14:56:50 -0800504 self._tech_profile_download_done[uni_id][tp_id] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400505 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800506 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500507 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530508
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800509 # Execute mcast task
510 for gem in gem_ports:
511 self.log.debug("checking-multicast-service-for-gem ", gem=gem)
512 if gem.mcast is True:
513 self.log.info("found-multicast-service-for-gem ", gem=gem, uni_id=uni_id, tp_id=tp_id)
514 reactor.callInThread(self.start_multicast_service, uni_id, tp_path)
515 self.log.debug("started_multicast_service-successfully", tconts=tconts, gems=gem_ports)
516 break
517
William Kurkian3a206332019-04-29 11:05:47 -0400518 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500519 def failure(_reason):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800520 self.log.warn('tech-profile-config-failure-retrying', uni_id=uni_id, tp_id=tp_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530521 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500522 if tp_path in self._tp_service_specific_task[uni_id]:
523 del self._tp_service_specific_task[uni_id][tp_path]
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800524 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500525 reactor.callLater(retry, self.load_and_configure_tech_profile,
526 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500527 yield self.core_proxy.device_reason_update(self.device_id,
528 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500529
Mahir Gunyela982ec32020-02-25 12:30:37 -0800530 self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530531 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
532
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500533 self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
534 self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
535
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500536 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800537 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500538 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530539 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500540 self._deferred.addCallbacks(success, failure)
541
542 except Exception as e:
543 self.log.exception("error-loading-tech-profile", e=e)
544 else:
545 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530546 # Could be a case where TP exists but new gem-ports are getting added dynamically
547 tpstored = self.kv_client[tp_path]
548 tpstring = tpstored.decode('ascii')
549 tp = json.loads(tpstring)
550 upstream_gems = []
551 downstream_gems = []
552 # Find out the new Gem ports that are getting added afresh.
553 for gp in tp['upstream_gem_port_attribute_list']:
554 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
555 # gem port already exists
556 continue
557 upstream_gems.append(gp)
558 for gp in tp['downstream_gem_port_attribute_list']:
559 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
560 # gem port already exists
561 continue
562 downstream_gems.append(gp)
563
564 us_scheduler = tp['us_scheduler']
565 alloc_id = us_scheduler['alloc_id']
566
567 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
568 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
569 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
570 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
571 new_gems = []
572 new_gems.extend(new_upstream_gems)
573 new_gems.extend(new_downstream_gems)
574
575 def success(_results):
576 self.log.info("new-gem-ports-successfully-installed", result=_results)
577
578 def failure(_reason):
579 self.log.warn('new-gem-port-install-failed--retrying',
580 _reason=_reason)
581 # Remove gem ports from cache. We will re-add them during the retry
582 for gp in new_gems:
583 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
584
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800585 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500586 reactor.callLater(retry, self.load_and_configure_tech_profile,
587 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530588
589 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800590 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530591 self._deferred = \
592 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
593 self._deferred.addCallbacks(success, failure)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800594 def start_multicast_service(self, uni_id, tp_path,retry_count=0):
595 self.log.debug("starting-multicast-service", uni_id=uni_id, tp_path=tp_path)
596 tp_id = self.extract_tp_id_from_path(tp_path)
597 if uni_id in self._set_vlan and tp_id in self._set_vlan[uni_id]:
598 try:
599 tp = self._tp[tp_id]
600 if tp is None:
601 tpstored = self.kv_client[tp_path]
602 tpstring = tpstored.decode('ascii')
603 tp = json.loads(tpstring)
604 if tp is None:
605 self.log.error("cannot-find-tp-to-start-multicast-service", uni_id=uni_id, tp_path=tp_path)
606 return
607 else:
608 self._tp[tp_id] = tp
609
610 self.log.debug("mcast-vlan-learned-before", self._set_vlan[uni_id][tp_id], uni_id=uni_id, tp_id=tp_id)
611 def success(_results):
612 self.log.debug('multicast-success', uni_id=uni_id)
613 self._multicast_task = None
614
615 def failure(_reason):
616 self.log.warn('multicast-failure', _reason=_reason)
617 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
618 reactor.callLater(retry, self.start_multicast_service,
619 uni_id, tp_path)
620
621 self.log.debug('starting-multicast-task', mcast_vlan_id=self._set_vlan[uni_id][tp_id])
622 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
623 for i in range(len(downstream_gem_port_attribute_list)):
624 if IS_MULTICAST in downstream_gem_port_attribute_list[i] and \
625 downstream_gem_port_attribute_list[i][IS_MULTICAST] == 'True':
626 dynamic_access_control_list_table = downstream_gem_port_attribute_list[i]['dynamic_access_control_list'].split("-")
627 static_access_control_list_table = downstream_gem_port_attribute_list[i]['static_access_control_list'].split("-")
628 multicast_gem_id = downstream_gem_port_attribute_list[i]['multicast_gem_id']
629 break
630
631 self._multicast_task = BrcmMcastTask(self.omci_agent, self, self.device_id, uni_id, tp_id,
632 self._set_vlan[uni_id][tp_id],dynamic_access_control_list_table, static_access_control_list_table, multicast_gem_id)
633 self._deferred = self._onu_omci_device.task_runner.queue_task(self._multicast_task)
634 self._deferred.addCallbacks(success, failure)
635 except Exception as e:
636 self.log.exception("error-loading-multicast", e=e)
637 else:
638 if retry_count<30:
639 retry_count = +1
640 self.log.debug("going-to-wait-for-flow-to-learn-mcast-vlan", uni_id=uni_id, tp_id=tp_id, retry=retry_count)
641 reactor.callLater(0.5, self.start_multicast_service, uni_id, tp_path, retry_count)
642 else:
643 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 +0530644
645 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
646 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800647 tp_table_id = self.extract_tp_id_from_path(tp_path)
Naga Manjunathe433c712020-01-02 17:27:20 +0530648 if not uni_id in self._tech_profile_download_done:
649 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
650 return
651
Mahir Gunyele9110a32020-02-20 14:56:50 -0800652 if not tp_table_id in self._tech_profile_download_done[uni_id]:
653 self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id)
Naga Manjunathe433c712020-01-02 17:27:20 +0530654 return
655
Mahir Gunyele9110a32020-02-20 14:56:50 -0800656 if self._tech_profile_download_done[uni_id][tp_table_id] is not True:
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800657 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete", uni_id=uni_id,
658 tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530659 return
660
661 if alloc_id is None and gem_port_id is None:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800662 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 +0530663 return
664
665 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
666 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
667 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
668 # this initializer
669 tcont = None
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500670 self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530671 for tc in list(self.pon_port.tconts.values()):
672 if tc.alloc_id == alloc_id:
673 tcont = tc
674 self.pon_port.remove_tcont(tc.alloc_id, False)
675
676 gem_port = None
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500677 self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530678 for gp in list(self.pon_port.gem_ports.values()):
679 if gp.gem_id == gem_port_id:
680 gem_port = gp
681 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
682
Girish Gowdrae933cd32019-11-21 21:04:41 +0530683 @inlineCallbacks
684 def success(_results):
685 if gem_port_id:
686 self.log.info("gem-port-delete-done-successfully")
687 if alloc_id:
688 self.log.info("tcont-delete-done-successfully")
689 # The deletion of TCONT marks the complete deletion of tech-profile
690 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800691 del self._tech_profile_download_done[uni_id][tp_table_id]
Girish Gowdrae933cd32019-11-21 21:04:41 +0530692 del self._tp_service_specific_task[uni_id][tp_path]
693 except Exception as ex:
694 self.log.error("del-tp-state-info", e=ex)
695
696 # TODO: There could be multiple TP on the UNI, and also the ONU.
697 # TODO: But the below reason updates for the whole device.
698 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
699
700 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530701 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530702 self.log.warn('tech-profile-delete-failure-retrying',
703 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500704 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
705 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500706 yield self.core_proxy.device_reason_update(self.device_id,
707 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530708
709 self.log.info('deleting-tech-profile-configuration')
710
Girish Gowdraa73ee452019-12-20 18:52:17 +0530711 if tcont is None and gem_port is None:
712 if alloc_id is not None:
713 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
714 if gem_port_id is not None:
715 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
716 return
717
Girish Gowdrae933cd32019-11-21 21:04:41 +0530718 self._tp_service_specific_task[uni_id][tp_path] = \
719 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
720 tcont=tcont, gem_port=gem_port)
721 self._deferred = \
722 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
723 self._deferred.addCallbacks(success, failure)
724 except Exception as e:
725 self.log.exception("failed-to-delete-tp",
726 e=e, uni_id=uni_id, tp_path=tp_path,
727 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500728
729 def update_pm_config(self, device, pm_config):
730 # TODO: This has not been tested
731 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500732 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500733
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800734 def remove_onu_flows(self, device, flows):
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500735 self.log.debug('remove-onu-flows')
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800736
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800737 # no point in removing omci flows if the device isnt reachable
738 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800739 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800740 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
741 admin=device.admin_state, connect=device.connect_status)
742 return
743
744 for flow in flows:
745 # if incoming flow contains cookie, then remove from ONU
746 if flow.cookie:
747 self.log.debug("remove-flow", device_id=device.id, flow=flow)
748
749 def is_downstream(port):
750 return port == self._pon_port_number
751
752 def is_upstream(port):
753 return not is_downstream(port)
754
755 try:
756 _in_port = fd.get_in_port(flow)
757 assert _in_port is not None
758
759 _out_port = fd.get_out_port(flow) # may be None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800760
761 if is_downstream(_in_port):
762 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
763 device_id=device.id)
764 # extended vlan tagging operation will handle it
765 continue
766 elif is_upstream(_in_port):
767 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
768 if fd.is_dhcp_flow(flow):
769 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
770 return
771
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800772 _vlan_vid = 0
773 # Retrieve the VLAN_VID that needs to be removed from the EVTO rule on the ONU.
774 for action in fd.get_actions(flow):
775 if action.type == fd.SET_FIELD:
776 _field = action.set_field.field.ofb_field
777 assert (action.set_field.field.oxm_class ==
778 OFPXMC_OPENFLOW_BASIC)
779 if _field.type == fd.VLAN_VID:
780 _vlan_vid = _field.vlan_vid & 0xfff
781 self.log.debug('vlan-vid-to-remove',
782 _vlan_vid=_vlan_vid, in_port=_in_port)
783
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800784 uni_port = self.uni_port(_in_port)
785 uni_id = _in_port & 0xF
786 else:
787 raise Exception('port should be 1 or 2 by our convention')
788
789 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
790
791 tp_id = self.get_tp_id_in_flow(flow)
792 # Deleting flow from ONU.
793 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800794 match_vlan=_vlan_vid, tp_id=tp_id)
795 # TODO:Delete TD task.
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800796 except Exception as e:
797 self.log.exception('failed-to-remove-flow', e=e)
798
799 def add_onu_flows(self, device, flows):
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500800 self.log.debug('add-onu-flows')
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800801
802 # no point in pushing omci flows if the device isnt reachable
803 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800804 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800805 self.log.warn("device-disabled-or-offline-skipping-flow-update",
806 admin=device.admin_state, connect=device.connect_status)
807 return
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800808
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800809 def is_downstream(port):
810 return port == self._pon_port_number
811
812 def is_upstream(port):
813 return not is_downstream(port)
814
815 for flow in flows:
816 # if incoming flow contains cookie, then add to ONU
817 if flow.cookie:
818 _type = None
819 _port = None
820 _vlan_vid = None
821 _udp_dst = None
822 _udp_src = None
823 _ipv4_dst = None
824 _ipv4_src = None
825 _metadata = None
826 _output = None
827 _push_tpid = None
828 _field = None
829 _set_vlan_vid = None
830 _set_vlan_pcp = 0
831 _tunnel_id = None
832 self.log.debug("add-flow", device_id=device.id, flow=flow)
833
834 try:
835 _in_port = fd.get_in_port(flow)
836 assert _in_port is not None
837
838 _out_port = fd.get_out_port(flow) # may be None
839 tp_id = self.get_tp_id_in_flow(flow)
840 if is_downstream(_in_port):
841 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
842 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
843 # uni_port = self.uni_port(_out_port)
844 # uni_id = _out_port & 0xF
845 continue
846 elif is_upstream(_in_port):
847 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
848 uni_port = self.uni_port(_in_port)
849 uni_id = _in_port & 0xF
850 else:
851 raise Exception('port should be 1 or 2 by our convention')
852
853 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
854
855 for field in fd.get_ofb_fields(flow):
856 if field.type == fd.ETH_TYPE:
857 _type = field.eth_type
858 self.log.debug('field-type-eth-type',
859 eth_type=_type)
860
861 elif field.type == fd.IP_PROTO:
862 _proto = field.ip_proto
863 self.log.debug('field-type-ip-proto',
864 ip_proto=_proto)
865
866 elif field.type == fd.IN_PORT:
867 _port = field.port
868 self.log.debug('field-type-in-port',
869 in_port=_port)
870 elif field.type == fd.TUNNEL_ID:
871 self.log.debug('field-type-tunnel-id')
872
873 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100874 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
875 _vlan_vid = RESERVED_TRANSPARENT_VLAN
876 else:
877 _vlan_vid = field.vlan_vid & 0xfff
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800878 self.log.debug('field-type-vlan-vid',
879 vlan=_vlan_vid)
880
881 elif field.type == fd.VLAN_PCP:
882 _vlan_pcp = field.vlan_pcp
883 self.log.debug('field-type-vlan-pcp',
884 pcp=_vlan_pcp)
885
886 elif field.type == fd.UDP_DST:
887 _udp_dst = field.udp_dst
888 self.log.debug('field-type-udp-dst',
889 udp_dst=_udp_dst)
890
891 elif field.type == fd.UDP_SRC:
892 _udp_src = field.udp_src
893 self.log.debug('field-type-udp-src',
894 udp_src=_udp_src)
895
896 elif field.type == fd.IPV4_DST:
897 _ipv4_dst = field.ipv4_dst
898 self.log.debug('field-type-ipv4-dst',
899 ipv4_dst=_ipv4_dst)
900
901 elif field.type == fd.IPV4_SRC:
902 _ipv4_src = field.ipv4_src
903 self.log.debug('field-type-ipv4-src',
904 ipv4_dst=_ipv4_src)
905
906 elif field.type == fd.METADATA:
907 _metadata = field.table_metadata
908 self.log.debug('field-type-metadata',
909 metadata=_metadata)
910
911 else:
912 raise NotImplementedError('field.type={}'.format(
913 field.type))
914
915 for action in fd.get_actions(flow):
916
917 if action.type == fd.OUTPUT:
918 _output = action.output.port
919 self.log.debug('action-type-output',
920 output=_output, in_port=_in_port)
921
922 elif action.type == fd.POP_VLAN:
923 self.log.debug('action-type-pop-vlan',
924 in_port=_in_port)
925
926 elif action.type == fd.PUSH_VLAN:
927 _push_tpid = action.push.ethertype
928 self.log.debug('action-type-push-vlan',
929 push_tpid=_push_tpid, in_port=_in_port)
930 if action.push.ethertype != 0x8100:
931 self.log.error('unhandled-tpid',
932 ethertype=action.push.ethertype)
933
934 elif action.type == fd.SET_FIELD:
935 _field = action.set_field.field.ofb_field
936 assert (action.set_field.field.oxm_class ==
937 OFPXMC_OPENFLOW_BASIC)
938 self.log.debug('action-type-set-field',
939 field=_field, in_port=_in_port)
940 if _field.type == fd.VLAN_VID:
941 _set_vlan_vid = _field.vlan_vid & 0xfff
942 self.log.debug('set-field-type-vlan-vid',
943 vlan_vid=_set_vlan_vid)
944 elif _field.type == fd.VLAN_PCP:
945 _set_vlan_pcp = _field.vlan_pcp
946 self.log.debug('set-field-type-vlan-pcp',
947 vlan_pcp=_set_vlan_pcp)
948 else:
949 self.log.error('unsupported-action-set-field-type',
950 field_type=_field.type)
951 else:
952 self.log.error('unsupported-action-type',
953 action_type=action.type, in_port=_in_port)
954
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800955 if self._set_vlan is not None:
956 if uni_id not in self._set_vlan:
957 self._set_vlan[uni_id] = dict()
958 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
959 self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
960
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100961 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
962 # supported match and action criteria cannot be handled by omci and must be ignored.
963 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
964 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
965 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
966 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800967 _set_vlan_vid=_vlan_vid,
968 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
969 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100970 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
971 _set_vlan_vid=_vlan_vid,
972 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
973 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800974 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100975 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
976 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800977 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
978 _set_vlan_vid=_set_vlan_vid,
979 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
980 tp_id=tp_id)
981
982 except Exception as e:
983 self.log.exception('failed-to-install-flow', e=e, flow=flow)
984
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500985 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
986 # flow decomposition that ultimately comes from onos
987 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700988 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500989
990 #
991 # We need to proxy through the OLT to get to the ONU
992 # Configuration from here should be using OMCI
993 #
994 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
995
996 # no point in pushing omci flows if the device isnt reachable
997 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530998 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500999 self.log.warn("device-disabled-or-offline-skipping-flow-update",
1000 admin=device.admin_state, connect=device.connect_status)
1001 return
1002
1003 def is_downstream(port):
1004 return port == self._pon_port_number
1005
1006 def is_upstream(port):
1007 return not is_downstream(port)
1008
1009 for flow in flows:
1010 _type = None
1011 _port = None
1012 _vlan_vid = None
1013 _udp_dst = None
1014 _udp_src = None
1015 _ipv4_dst = None
1016 _ipv4_src = None
1017 _metadata = None
1018 _output = None
1019 _push_tpid = None
1020 _field = None
1021 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001022 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001023 _tunnel_id = None
1024
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001025 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +05301026 write_metadata = fd.get_write_metadata(flow)
1027 if write_metadata is None:
1028 self.log.error("do-not-process-flow-without-write-metadata")
1029 return
1030
1031 # extract tp id from flow
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001032 tp_id = self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001033 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +05301034
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001035 _in_port = fd.get_in_port(flow)
1036 assert _in_port is not None
1037
1038 _out_port = fd.get_out_port(flow) # may be None
1039
1040 if is_downstream(_in_port):
1041 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
1042 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301043 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001044 elif is_upstream(_in_port):
1045 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
1046 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001047 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001048 else:
1049 raise Exception('port should be 1 or 2 by our convention')
1050
1051 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
1052
1053 for field in fd.get_ofb_fields(flow):
1054 if field.type == fd.ETH_TYPE:
1055 _type = field.eth_type
1056 self.log.debug('field-type-eth-type',
1057 eth_type=_type)
1058
1059 elif field.type == fd.IP_PROTO:
1060 _proto = field.ip_proto
1061 self.log.debug('field-type-ip-proto',
1062 ip_proto=_proto)
1063
1064 elif field.type == fd.IN_PORT:
1065 _port = field.port
1066 self.log.debug('field-type-in-port',
1067 in_port=_port)
1068
1069 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001070 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
1071 _vlan_vid = RESERVED_TRANSPARENT_VLAN
1072 else:
1073 _vlan_vid = field.vlan_vid & 0xfff
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001074 self.log.debug('field-type-vlan-vid',
1075 vlan=_vlan_vid)
1076
1077 elif field.type == fd.VLAN_PCP:
1078 _vlan_pcp = field.vlan_pcp
1079 self.log.debug('field-type-vlan-pcp',
1080 pcp=_vlan_pcp)
1081
1082 elif field.type == fd.UDP_DST:
1083 _udp_dst = field.udp_dst
1084 self.log.debug('field-type-udp-dst',
1085 udp_dst=_udp_dst)
1086
1087 elif field.type == fd.UDP_SRC:
1088 _udp_src = field.udp_src
1089 self.log.debug('field-type-udp-src',
1090 udp_src=_udp_src)
1091
1092 elif field.type == fd.IPV4_DST:
1093 _ipv4_dst = field.ipv4_dst
1094 self.log.debug('field-type-ipv4-dst',
1095 ipv4_dst=_ipv4_dst)
1096
1097 elif field.type == fd.IPV4_SRC:
1098 _ipv4_src = field.ipv4_src
1099 self.log.debug('field-type-ipv4-src',
1100 ipv4_dst=_ipv4_src)
1101
1102 elif field.type == fd.METADATA:
1103 _metadata = field.table_metadata
1104 self.log.debug('field-type-metadata',
1105 metadata=_metadata)
1106
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001107 elif field.type == fd.TUNNEL_ID:
1108 _tunnel_id = field.tunnel_id
1109 self.log.debug('field-type-tunnel-id',
1110 tunnel_id=_tunnel_id)
1111
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001112
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001113 else:
1114 raise NotImplementedError('field.type={}'.format(
1115 field.type))
1116
1117 for action in fd.get_actions(flow):
1118
1119 if action.type == fd.OUTPUT:
1120 _output = action.output.port
1121 self.log.debug('action-type-output',
1122 output=_output, in_port=_in_port)
1123
1124 elif action.type == fd.POP_VLAN:
1125 self.log.debug('action-type-pop-vlan',
1126 in_port=_in_port)
1127
1128 elif action.type == fd.PUSH_VLAN:
1129 _push_tpid = action.push.ethertype
1130 self.log.debug('action-type-push-vlan',
1131 push_tpid=_push_tpid, in_port=_in_port)
1132 if action.push.ethertype != 0x8100:
1133 self.log.error('unhandled-tpid',
1134 ethertype=action.push.ethertype)
1135
1136 elif action.type == fd.SET_FIELD:
1137 _field = action.set_field.field.ofb_field
1138 assert (action.set_field.field.oxm_class ==
1139 OFPXMC_OPENFLOW_BASIC)
1140 self.log.debug('action-type-set-field',
1141 field=_field, in_port=_in_port)
1142 if _field.type == fd.VLAN_VID:
1143 _set_vlan_vid = _field.vlan_vid & 0xfff
1144 self.log.debug('set-field-type-vlan-vid',
1145 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001146 elif _field.type == fd.VLAN_PCP:
1147 _set_vlan_pcp = _field.vlan_pcp
1148 self.log.debug('set-field-type-vlan-pcp',
1149 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001150 else:
1151 self.log.error('unsupported-action-set-field-type',
1152 field_type=_field.type)
1153 else:
1154 self.log.error('unsupported-action-type',
1155 action_type=action.type, in_port=_in_port)
1156
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001157 if self._set_vlan is not None:
1158 if uni_id not in self._set_vlan:
1159 self._set_vlan[uni_id] = dict()
1160 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
1161 self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
Matt Jeanneret810148b2019-09-29 12:44:01 -04001162 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1163 # supported match and action criteria cannot be handled by omci and must be ignored.
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001164 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
1165 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
1166 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
1167 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001168 _set_vlan_vid=_vlan_vid,
1169 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1170 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001171 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1172 _set_vlan_vid=_vlan_vid,
1173 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1174 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001175 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001176 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
1177 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
1178 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1179 _set_vlan_vid=_set_vlan_vid,
1180 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1181 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001182 except Exception as e:
1183 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1184
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001185 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001186 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1187 self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1188 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001189 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001190 if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and \
1191 self._tech_profile_download_done[uni_id][tp_id] is True:
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001192 @inlineCallbacks
1193 def success(_results):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001194 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id,
1195 set_vlan_pcp=_set_vlan_pcp)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001196 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001197
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001198 @inlineCallbacks
1199 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301200 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001201 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1202 reactor.callLater(retry,
1203 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1204 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1205 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001206 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001207
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001208 self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1209 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001210 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001211 match_vlan, _set_vlan_pcp, add_tag=True,
1212 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001213 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001214 self._deferred.addCallbacks(success, failure)
1215 else:
1216 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001217 uni_id=uni_id, tp_id=tp_id)
1218 if uni_id not in self._queued_vlan_filter_task:
1219 self._queued_vlan_filter_task[uni_id] = dict()
Mahir Gunyela982ec32020-02-25 12:30:37 -08001220 if tp_id not in self._queued_vlan_filter_task[uni_id]:
1221 self._queued_vlan_filter_task[uni_id][tp_id] = []
1222 self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001223 "uni_id": uni_id,
1224 "uni_port": uni_port,
1225 "match_vlan": match_vlan,
1226 "set_vlan_vid": _set_vlan_vid,
1227 "set_vlan_pcp": _set_vlan_pcp,
1228 "tp_id": tp_id})
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001229
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001230 def get_tp_id_in_flow(self, flow):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001231 flow_metadata = fd.get_metadata_from_write_metadata(flow)
1232 tp_id = fd.get_tp_id_from_metadata(flow_metadata)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001233 return tp_id
1234
1235 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001236 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001237 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001238
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001239 @inlineCallbacks
1240 def success(_results):
1241 self.log.info('vlan-untagging-success', _results=_results)
1242 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1243
1244 @inlineCallbacks
1245 def failure(_reason):
1246 self.log.warn('vlan-untagging-failure', _reason=_reason)
1247 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001248 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001249 reactor.callLater(retry,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001250 self._remove_vlan_filter_task, device, uni_id,
1251 add_tag=False, uni_port=uni_port)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001252
1253 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1254 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001255 match_vlan, _set_vlan_pcp, add_tag=False,
1256 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001257 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1258 self._deferred.addCallbacks(success, failure)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001259
Matt Jeannereta32441c2019-03-07 05:16:37 -05001260 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001261 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1262 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeanneret2101f3d2020-03-12 10:13:06 -04001263
1264 if not self.enabled:
1265 self.log.warn('device-not-activated')
1266 reactor.callLater(0.5, self.process_inter_adapter_message, request)
1267 return
1268
Matt Jeannereta32441c2019-03-07 05:16:37 -05001269 try:
1270 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1271 omci_msg = InterAdapterOmciMessage()
1272 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001273 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001274
Matt Jeannereta32441c2019-03-07 05:16:37 -05001275 self.receive_message(omci_msg.message)
1276
1277 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1278 onu_indication = OnuIndication()
1279 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001280 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1281 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1282 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001283
1284 if onu_indication.oper_state == "up":
1285 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301286 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001287 self.update_interface(onu_indication)
1288 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001289 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1290 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001291
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001292 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1293 tech_msg = InterAdapterTechProfileDownloadMessage()
1294 request.body.Unpack(tech_msg)
1295 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1296
1297 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1298
Girish Gowdrae933cd32019-11-21 21:04:41 +05301299 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1300 del_gem_msg = InterAdapterDeleteGemPortMessage()
1301 request.body.Unpack(del_gem_msg)
1302 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1303
1304 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1305 gem_port_id=del_gem_msg.gem_port_id,
1306 tp_path=del_gem_msg.tp_path)
1307
1308 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1309 del_tcont_msg = InterAdapterDeleteTcontMessage()
1310 request.body.Unpack(del_tcont_msg)
1311 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1312
1313 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1314 alloc_id=del_tcont_msg.alloc_id,
1315 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001316 else:
1317 self.log.error("inter-adapter-unhandled-type", request=request)
1318
1319 except Exception as e:
1320 self.log.exception("error-processing-inter-adapter-message", e=e)
1321
1322 # Called each time there is an onu "up" indication from the olt handler
1323 @inlineCallbacks
1324 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001325 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001326 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001327
1328 # Ignore if onu_indication is received for an already running ONU
1329 if self._onu_omci_device is not None and self._onu_omci_device.active:
1330 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1331 return
1332
Matt Jeannereta32441c2019-03-07 05:16:37 -05001333 self._onu_indication = onu_indication
1334
Matt Jeanneretc083f462019-03-11 15:02:01 -04001335 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1336 connect_status=ConnectStatus.REACHABLE)
1337
Matt Jeannereta32441c2019-03-07 05:16:37 -05001338 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001339
1340 self.log.debug('starting-openomci-statemachine')
1341 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001342 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301343 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001344 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001345 self._heartbeat.enabled = True
1346
Matt Jeanneret42dad792020-02-01 09:28:27 -05001347 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001348 @inlineCallbacks
1349 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001350 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001351 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001352
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001353 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001354 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001355 reactor.callLater(0, self._onu_omci_device.stop)
1356
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001357 self._tp = dict()
1358
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001359 # Let TP download happen again
1360 for uni_id in self._tp_service_specific_task:
1361 self._tp_service_specific_task[uni_id].clear()
1362 for uni_id in self._tech_profile_download_done:
1363 self._tech_profile_download_done[uni_id].clear()
1364
Matt Jeanneretf4113222019-08-14 19:44:34 -04001365 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001366 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1367 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1368 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001369 else:
1370 self.log.debug('not-changing-openomci-statemachine')
1371
Matt Jeanneretf4113222019-08-14 19:44:34 -04001372 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001373 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001374 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001375 try:
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001376 yield self.disable_ports(lock_ports=True, device_disabled=True)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001377 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1378 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001379 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001380 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001381
William Kurkian3a206332019-04-29 11:05:47 -04001382 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001383 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001384 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001385 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001386 yield self.core_proxy.device_state_update(device.id,
1387 oper_status=OperStatus.ACTIVE,
1388 connect_status=ConnectStatus.REACHABLE)
1389 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1390 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001391 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001392 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001393
William Kurkian3a206332019-04-29 11:05:47 -04001394 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001395 def reboot(self):
1396 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001397 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001398 if device.connect_status != ConnectStatus.REACHABLE:
1399 self.log.error("device-unreachable")
1400 return
1401
William Kurkian3a206332019-04-29 11:05:47 -04001402 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001403 def success(_results):
1404 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001405 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001406
1407 def failure(_reason):
1408 self.log.info('reboot-failure', _reason=_reason)
1409
1410 self._deferred = self._onu_omci_device.reboot()
1411 self._deferred.addCallbacks(success, failure)
1412
William Kurkian3a206332019-04-29 11:05:47 -04001413 @inlineCallbacks
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001414 def disable_ports(self, lock_ports=True, device_disabled=False):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001415 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001416
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001417 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1418 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001419 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001420 if port.mac_bridge_port_num == 1:
1421 port.operstatus = OperStatus.UNKNOWN
1422 self.log.info('disable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001423 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1424 port.operstatus)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001425
1426 if lock_ports is True:
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001427 self.lock_ports(lock=True, device_disabled=device_disabled)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001428
William Kurkian3a206332019-04-29 11:05:47 -04001429 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001430 def enable_ports(self):
1431 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001432
Matt Jeanneretf4113222019-08-14 19:44:34 -04001433 self.lock_ports(lock=False)
1434
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001435 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1436 # load on the core
1437 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001438 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001439 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001440 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001441 self.log.info('enable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001442 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1443 port.operstatus)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001444
1445 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1446 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1447 #
1448 # Basically the link state sequence:
1449 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1450 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1451 # 3) a link state up alarm is received for the uni plugged in.
1452 #
1453 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1454 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1455 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1456 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001457 @inlineCallbacks
1458 def port_state_handler(self, _topic, msg):
1459 self.log.info("port-state-change", _topic=_topic, msg=msg)
1460
1461 onu_id = msg['onu_id']
1462 port_no = msg['port_number']
1463 serial_number = msg['serial_number']
1464 port_status = msg['port_status']
1465 uni_port = self.uni_port(int(port_no))
1466
1467 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1468 port_status=port_status)
1469
1470 if port_status is True:
1471 uni_port.operstatus = OperStatus.ACTIVE
1472 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1473 else:
1474 uni_port.operstatus = OperStatus.UNKNOWN
1475 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1476
1477 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 -05001478 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001479
1480 # Called just before openomci state machine is started. These listen for events from selected state machines,
1481 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1482 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001483 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001484
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001485 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001486
1487 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001488 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1489 OnuDeviceEvents.MibDatabaseSyncEvent)
1490 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1491
1492 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001493 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1494 OnuDeviceEvents.OmciCapabilitiesEvent)
1495 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1496
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001497 # TODO: these alarms seem to be unreliable depending on the environment
1498 # 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 -08001499 # topic = OnuDeviceEntry.event_bus_topic(self.device_id,
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001500 # OnuDeviceEvents.PortEvent)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001501 # self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001502
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001503 # Called when the mib is in sync
1504 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001505 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001506 if self._in_sync_subscription is not None:
1507 try:
1508 in_sync = msg[IN_SYNC_KEY]
1509
1510 if in_sync:
1511 # Only call this once
1512 bus = self._onu_omci_device.event_bus
1513 bus.unsubscribe(self._in_sync_subscription)
1514 self._in_sync_subscription = None
1515
1516 # Start up device_info load
1517 self.log.debug('running-mib-sync')
1518 reactor.callLater(0, self._mib_in_sync)
1519
1520 except Exception as e:
1521 self.log.exception('in-sync', e=e)
1522
1523 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001524 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001525 if self._capabilities_subscription is not None:
1526 self.log.debug('capabilities-handler-done')
1527
1528 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1529 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1530 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001531 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001532 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001533 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001534
1535 omci = self._onu_omci_device
1536 in_sync = omci.mib_db_in_sync
1537
Matt Jeanneretc083f462019-03-11 15:02:01 -04001538 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001539 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001540
1541 if not self._dev_info_loaded:
1542 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1543
1544 omci_dev = self._onu_omci_device
1545 config = omci_dev.configuration
1546
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001547 try:
1548
1549 # sort the lists so we get consistent port ordering.
1550 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1551 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1552 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1553 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1554
1555 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001556 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001557 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001558 raise Exception("onu-missing-required-elements")
1559
1560 # Currently logging the ani, pptp, veip, and uni for information purposes.
1561 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1562 # And in some ONU the UNI-G list is incomplete or incorrect...
1563 for entity_id in ani_list:
1564 ani_value = config.ani_g_entities[entity_id]
1565 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1566 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1567 self._total_tcont_count = ani_value.get('total-tcont-count')
1568 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1569
1570 for entity_id in uni_list:
1571 uni_value = config.uni_g_entities[entity_id]
1572 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1573
1574 uni_entities = OrderedDict()
1575 for entity_id in pptp_list:
1576 pptp_value = config.pptp_entities[entity_id]
1577 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1578 uni_entities[entity_id] = UniType.PPTP
1579
1580 for entity_id in veip_list:
1581 veip_value = config.veip_entities[entity_id]
1582 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1583 uni_entities[entity_id] = UniType.VEIP
1584
1585 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001586 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001587 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001588 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001589 uni_id += 1
1590 except AssertionError as e:
1591 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1592
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001593 self._qos_flexibility = config.qos_configuration_flexibility or 0
1594 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1595
1596 if self._unis:
1597 self._dev_info_loaded = True
1598 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001599 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001600 self.log.warn("no-usable-unis")
1601 raise Exception("no-usable-unis")
1602
1603 except Exception as e:
1604 self.log.exception('device-info-load', e=e)
1605 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1606
1607 else:
1608 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1609
1610 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001611 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001612
1613 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001614 def success(_results):
1615 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001616 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301617 oper_status=OperStatus.ACTIVE,
1618 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001619 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001620 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001621 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001622 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001623
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001624 # Start collecting stats from the device after a brief pause
1625 if not self._pm_metrics_started:
1626 self._pm_metrics_started = True
1627 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1628 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1629
1630 # Start test requests after a brief pause
1631 if not self._test_request_started:
1632 self._test_request_started = True
1633 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1634 reactor.callLater(tststart, self._test_request.start_collector)
1635
Matt Jeanneretc083f462019-03-11 15:02:01 -04001636 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001637 def failure(_reason):
1638 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001639 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001640 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001641 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001642
Matt Jeanneretf4113222019-08-14 19:44:34 -04001643 # start by locking all the unis till mib sync and initial mib is downloaded
1644 # this way we can capture the port down/up events when we are ready
1645 self.lock_ports(lock=True)
1646
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001647 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1648 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1649 self.log.info('downloading-initial-mib-configuration')
1650 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1651 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1652 self._deferred.addCallbacks(success, failure)
1653 else:
1654 self.log.info('admin-down-disabling')
1655 self.disable(device)
1656 else:
1657 self.log.info('device-info-not-loaded-skipping-mib-download')
1658
Matt Jeanneretc083f462019-03-11 15:02:01 -04001659 @inlineCallbacks
1660 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001661 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001662
Matt Jeanneretc083f462019-03-11 15:02:01 -04001663 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 -05001664
1665 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1666 uni_name = "uni-{}".format(uni_no)
1667
Girish Gowdrae933cd32019-11-21 21:04:41 +05301668 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001669
1670 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 -04001671 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001672
1673 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1674 uni_port.entity_id = entity_id
1675 uni_port.enabled = True
1676 uni_port.mac_bridge_port_num = mac_bridge_port_num
1677
1678 self.log.debug("created-uni-port", uni=uni_port)
1679
Matt Jeanneretc083f462019-03-11 15:02:01 -04001680 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001681
1682 self._unis[uni_port.port_number] = uni_port
1683
1684 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301685 uni_ports=self.uni_ports,
1686 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001687
Matt Jeanneretc083f462019-03-11 15:02:01 -04001688 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1689 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001690 MAX_PONS_PER_OLT = 256
1691 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001692 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001693
Matt Jeanneretc083f462019-03-11 15:02:01 -04001694 assert intf_id < MAX_PONS_PER_OLT
1695 assert onu_id < MAX_ONUS_PER_PON
1696 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001697 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001698
1699 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001700 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001701 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001702 try:
1703 device = yield self.core_proxy.get_device(self.device_id)
1704 parent_device = yield self.core_proxy.get_device(self.parent_id)
1705 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001706 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001707
1708 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301709 pon_id=self._onu_indication.intf_id,
1710 onu_id=self._onu_indication.onu_id,
1711 registration_id=self.device_id,
1712 device_id=self.device_id,
1713 onu_serial_number=device.serial_number,
1714 olt_serial_number=olt_serial_number,
1715 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001716
Devmalya Paulffc89df2019-07-31 17:43:13 -04001717 self.log.debug("Trying-to-raise-onu-active-event")
1718 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001719 self._onu_indication.intf_id,
1720 device.serial_number,
1721 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301722 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001723 onu_id=self._onu_indication.onu_id).send(True)
1724 except Exception as active_event_error:
1725 self.log.exception('onu-activated-event-error',
1726 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001727
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001728 @inlineCallbacks
1729 def onu_disabled_event(self):
1730 self.log.debug('onu-disabled-event')
1731 try:
1732 device = yield self.core_proxy.get_device(self.device_id)
1733 parent_device = yield self.core_proxy.get_device(self.parent_id)
1734 olt_serial_number = parent_device.serial_number
1735 raised_ts = arrow.utcnow().timestamp
1736
1737 self.log.debug("onu-indication-context-data",
1738 pon_id=self._onu_indication.intf_id,
1739 onu_id=self._onu_indication.onu_id,
1740 registration_id=self.device_id,
1741 device_id=self.device_id,
1742 onu_serial_number=device.serial_number,
1743 olt_serial_number=olt_serial_number,
1744 raised_ts=raised_ts)
1745
1746 self.log.debug("Trying-to-raise-onu-disabled-event")
1747 OnuDisabledEvent(self.events, self.device_id,
1748 self._onu_indication.intf_id,
1749 device.serial_number,
1750 str(self.device_id),
1751 olt_serial_number, raised_ts,
1752 onu_id=self._onu_indication.onu_id).send(True)
1753 except Exception as active_event_error:
1754 self.log.exception('onu-disabled-event-error',
1755 errmsg=active_event_error.message)
1756
1757 def lock_ports(self, lock=True, device_disabled=False):
Matt Jeanneretf4113222019-08-14 19:44:34 -04001758
1759 def success(response):
1760 self.log.debug('set-onu-ports-state', lock=lock, response=response)
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001761 if device_disabled:
1762 self.onu_disabled_event()
Matt Jeanneretf4113222019-08-14 19:44:34 -04001763
1764 def failure(response):
1765 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1766
1767 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1768 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1769 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001770
1771 def extract_tp_id_from_path(self, tp_path):
1772 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001773 tp_id = int(tp_path.split(_PATH_SEPERATOR)[1])
1774 return tp_id