blob: da4de57a5478c577c455b710907f0035254669f5 [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
2# Copyright 2017 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17"""
18Broadcom OpenOMCI OLT/ONU adapter handler.
19"""
20
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050021from __future__ import absolute_import
22import six
Devmalya Paulffc89df2019-07-31 17:43:13 -040023import arrow
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050024import structlog
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050025import json
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050026import random
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050027
28from collections import OrderedDict
29
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050030from twisted.internet import reactor
31from twisted.internet.defer import DeferredQueue, inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050032
33from heartbeat import HeartBeat
Devmalya Paulffc89df2019-07-31 17:43:13 -040034from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent
Devmalya Paule2e5f2b2020-03-08 18:50:33 -040035from pyvoltha.adapters.extensions.events.device_events.onu.onu_disabled_event import OnuDisabledEvent
Devmalya Paulffc89df2019-07-31 17:43:13 -040036from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
37from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
38from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050039
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050040import pyvoltha.common.openflow.utils as fd
41from pyvoltha.common.utils.registry import registry
Matteo Scandolod8d73172019-11-26 12:15:15 -070042from pyvoltha.adapters.common.frameio.frameio import hexify
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050043from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050044from pyvoltha.common.config.config_backend import ConsulStore
45from pyvoltha.common.config.config_backend import EtcdStore
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050046from voltha_protos.logical_device_pb2 import LogicalPort
William Kurkian8235c1e2019-03-05 12:58:28 -050047from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretf4113222019-08-14 19:44:34 -040048from voltha_protos.device_pb2 import Port
Girish Gowdra4c11ddb2020-03-03 11:33:24 -080049from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE, OFPPS_LINK_DOWN, \
Matt Jeanneretf4113222019-08-14 19:44:34 -040050 OFPPF_FIBER, OFPPF_1GB_FD
Matt Jeanneret3bfebff2019-04-12 18:25:03 -040051from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
Girish Gowdrae933cd32019-11-21 21:04:41 +053052 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
53 InterAdapterDeleteTcontMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050054from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050055from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
56from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050057 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050058from omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdrae933cd32019-11-21 21:04:41 +053059from omci.brcm_tp_setup_task import BrcmTpSetupTask
60from omci.brcm_tp_delete_task import BrcmTpDeleteTask
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050061from omci.brcm_uni_lock_task import BrcmUniLockTask
62from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050063from onu_gem_port import OnuGemPort
64from onu_tcont import OnuTCont
65from pon_port import PonPort
Mahir Gunyel5de33fe2020-03-03 22:38:44 -080066from omci.brcm_mcast_task import BrcmMcastTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050067from uni_port import UniPort, UniType
Andrea Campanellacf916ea2020-02-14 10:03:58 +010068from uni_port import RESERVED_TRANSPARENT_VLAN
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050069from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053070from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
71from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050072from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
onkarkundargia1e2af22020-01-27 11:51:43 +053073from voltha_protos.voltha_pb2 import TestResponse
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050074
75OP = EntityOperations
76RC = ReasonCodes
77
Mahir Gunyel5de33fe2020-03-03 22:38:44 -080078IS_MULTICAST='is_multicast'
79GEM_PORT_ID = 'gemport_id'
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050080_STARTUP_RETRY_WAIT = 10
Mahir Gunyele9110a32020-02-20 14:56:50 -080081_PATH_SEPERATOR = "/"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050082
83
84class BrcmOpenomciOnuHandler(object):
85
86 def __init__(self, adapter, device_id):
87 self.log = structlog.get_logger(device_id=device_id)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050088 self.log.debug('starting-handler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050089 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050090 self.core_proxy = adapter.core_proxy
91 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050092 self.parent_id = None
93 self.device_id = device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050094 self.proxy_address = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050095 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040096 self.events = None
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050097 self._pm_metrics = None
98 self._pm_metrics_started = False
99 self._test_request = None
100 self._test_request_started = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500101 self._omcc_version = OMCCVersion.Unknown
102 self._total_tcont_count = 0 # From ANI-G ME
103 self._qos_flexibility = 0 # From ONT2_G ME
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800104 self._tp = dict() #tp_id -> technology profile definition in KV Store.
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500105 self._onu_indication = None
106 self._unis = dict() # Port # -> UniPort
107
108 self._pon = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500109 self._pon_port_number = 100
110 self.logical_device_id = None
111
112 self._heartbeat = HeartBeat.create(self, device_id)
113
114 # Set up OpenOMCI environment
115 self._onu_omci_device = None
116 self._dev_info_loaded = False
117 self._deferred = None
118
119 self._in_sync_subscription = None
Matt Jeanneretf4113222019-08-14 19:44:34 -0400120 self._port_state_subscription = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500121 self._connectivity_subscription = None
122 self._capabilities_subscription = None
123
124 self.mac_bridge_service_profile_entity_id = 0x201
125 self.gal_enet_profile_entity_id = 0x1
126
127 self._tp_service_specific_task = dict()
128 self._tech_profile_download_done = dict()
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400129 # Stores information related to queued vlan filter tasks
130 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
131
132 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500133
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800134 self._set_vlan = dict() #uni_id, tp_id -> set_vlan_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500135 # Initialize KV store client
136 self.args = registry('main').get_args()
137 if self.args.backend == 'etcd':
138 host, port = self.args.etcd.split(':', 1)
139 self.kv_client = EtcdStore(host, port,
140 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
141 elif self.args.backend == 'consul':
142 host, port = self.args.consul.split(':', 1)
143 self.kv_client = ConsulStore(host, port,
144 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
145 else:
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500146 self.log.error('invalid-backend')
147 raise Exception("invalid-backend-for-kv-store")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500148
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500149 @property
150 def enabled(self):
151 return self._enabled
152
153 @enabled.setter
154 def enabled(self, value):
155 if self._enabled != value:
156 self._enabled = value
157
158 @property
159 def omci_agent(self):
160 return self.adapter.omci_agent
161
162 @property
163 def omci_cc(self):
164 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
165
166 @property
167 def heartbeat(self):
168 return self._heartbeat
169
170 @property
171 def uni_ports(self):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500172 return list(self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500173
174 def uni_port(self, port_no_or_name):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500175 if isinstance(port_no_or_name, six.string_types):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500176 return next((uni for uni in self.uni_ports
177 if uni.name == port_no_or_name), None)
178
179 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
180 return next((uni for uni in self.uni_ports
Girish Gowdrae933cd32019-11-21 21:04:41 +0530181 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500182
183 @property
184 def pon_port(self):
185 return self._pon
186
Girish Gowdraa73ee452019-12-20 18:52:17 +0530187 @property
188 def onu_omci_device(self):
189 return self._onu_omci_device
190
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500191 def receive_message(self, msg):
192 if self.omci_cc is not None:
193 self.omci_cc.receive_message(msg)
194
Matt Jeanneretc083f462019-03-11 15:02:01 -0400195 def get_ofp_port_info(self, device, port_no):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500196 self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400197 cap = OFPPF_1GB_FD | OFPPF_FIBER
198
Girish Gowdrae933cd32019-11-21 21:04:41 +0530199 hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
200 ((device.parent_port_no >> 8 & 0xff),
201 device.parent_port_no & 0xff,
202 (port_no >> 16) & 0xff,
203 (port_no >> 8) & 0xff,
204 port_no & 0xff))
Matt Jeanneretc083f462019-03-11 15:02:01 -0400205
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400206 uni_port = self.uni_port(int(port_no))
207 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500208 self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port)
Matt Jeanneretf4113222019-08-14 19:44:34 -0400209
210 ofstate = OFPPS_LINK_DOWN
211 if uni_port.operstatus is OperStatus.ACTIVE:
212 ofstate = OFPPS_LIVE
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400213
Matt Jeanneretc083f462019-03-11 15:02:01 -0400214 return PortCapability(
215 port=LogicalPort(
216 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400217 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400218 hw_addr=hw_addr,
219 config=0,
Matt Jeanneretf4113222019-08-14 19:44:34 -0400220 state=ofstate,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400221 curr=cap,
222 advertised=cap,
223 peer=cap,
224 curr_speed=OFPPF_1GB_FD,
225 max_speed=OFPPF_1GB_FD
226 ),
227 device_id=device.id,
228 device_port_no=port_no
229 )
230 )
231
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500232 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500233 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500234 def activate(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700235 self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500236
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500237 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500238 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500239 assert device.proxy_address.device_id
240
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500241 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500242 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500243 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500244 if self.enabled is not True:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700245 self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500246 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500247 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500248 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500249 device.reason = 'activating-onu'
250
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500251 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400252 # pm_metrics requires a logical device id. For now set to just device_id
253 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500254
Matt Jeannereta32441c2019-03-07 05:16:37 -0500255 yield self.core_proxy.device_update(device)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500256 self.log.debug('device-updated', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500257
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700258 yield self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500259
Matteo Scandolod8d73172019-11-26 12:15:15 -0700260 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500261 ############################################################################
Devmalya Paulffc89df2019-07-31 17:43:13 -0400262 # Setup Alarm handler
263 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
264 device.serial_number)
265 ############################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500266 # Setup PM configuration for this device
267 # Pass in ONU specific options
268 kwargs = {
269 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
270 'heartbeat': self.heartbeat,
271 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
272 }
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500273 self.log.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500274 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800275 self.logical_device_id, device.serial_number,
276 grouped=True, freq_override=False, **kwargs)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500277 pm_config = self._pm_metrics.make_proto()
278 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530279 self.log.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500280 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500281
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500282 # Note, ONU ID and UNI intf set in add_uni_port method
Devmalya Paulffc89df2019-07-31 17:43:13 -0400283 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500284 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500285
onkarkundargiaae99712019-09-23 15:02:52 +0530286 # Code to Run OMCI Test Action
287 kwargs_omci_test_action = {
288 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
289 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
290 }
291 serial_number = device.serial_number
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500292 self._test_request = OmciTestRequest(self.core_proxy,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800293 self.omci_agent, self.device_id,
294 AniG, serial_number,
295 self.logical_device_id,
296 exclusive=False,
297 **kwargs_omci_test_action)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500298
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500299 self.enabled = True
300 else:
301 self.log.info('onu-already-activated')
302
303 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400304 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500305 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700306 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500307
308 # first we verify that we got parent reference and proxy info
309 assert device.parent_id
310 assert device.proxy_address.device_id
311
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700312 self.proxy_address = device.proxy_address
313 self.parent_id = device.parent_id
314 self._pon_port_number = device.parent_port_no
315
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500316 if self.enabled is not True:
317 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700318 self.logical_device_id = self.device_id
319 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500320
321 # need to restart state machines on vcore restart. there is no indication to do it for us.
322 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700323 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500324
325 # TODO: this is probably a bit heavy handed
326 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
327 # This may not be necessary when mib resync actually works
328 reactor.callLater(1, self.reboot)
329
330 self.enabled = True
331 else:
332 self.log.info('onu-already-activated')
333
334 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700335 def _init_pon_state(self):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500336 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 -0500337
338 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500339 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700340 self.log.debug('adding-pon-port-to-agent',
341 type=self._pon.get_port().type,
342 admin_state=self._pon.get_port().admin_state,
343 oper_status=self._pon.get_port().oper_status,
344 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500345
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700346 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500347
Matteo Scandolod8d73172019-11-26 12:15:15 -0700348 self.log.debug('added-pon-port-to-agent',
349 type=self._pon.get_port().type,
350 admin_state=self._pon.get_port().admin_state,
351 oper_status=self._pon.get_port().oper_status,
352 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500353
354 # Create and start the OpenOMCI ONU Device Entry for this ONU
355 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500356 self.core_proxy,
357 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500358 support_classes=self.adapter.broadcom_omci,
359 custom_me_map=self.adapter.custom_me_entities())
360 # Port startup
361 if self._pon is not None:
362 self._pon.enabled = True
363
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500364 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700365 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret42dad792020-02-01 09:28:27 -0500366
367 self._deferred.cancel()
368 self._test_request.stop_collector()
369 self._pm_metrics.stop_collector()
370 self.log.debug('removing-openomci-statemachine')
371 self.omci_agent.remove_device(device.id, cleanup=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500372
373 def _create_tconts(self, uni_id, us_scheduler):
374 alloc_id = us_scheduler['alloc_id']
375 q_sched_policy = us_scheduler['q_sched_policy']
376 self.log.debug('create-tcont', us_scheduler=us_scheduler)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800377 # TODO: revisit for multi tconts support
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800378 new_tconts = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500379 tcontdict = dict()
380 tcontdict['alloc-id'] = alloc_id
381 tcontdict['q_sched_policy'] = q_sched_policy
382 tcontdict['uni_id'] = uni_id
383
Matt Jeanneret3789d0d2020-01-19 09:03:42 -0500384 tcont = OnuTCont.create(self, tcont=tcontdict)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500385
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500386 success = self._pon.add_tcont(tcont)
387 if success:
388 new_tconts.append(tcont)
389 self.log.debug('pon-add-tcont', tcont=tcont)
390
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800391 return new_tconts
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500392
393 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
394 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
395 self.log.debug('create-gemport',
396 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530397 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500398 for gem_port in gem_ports:
399 gemdict = dict()
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800400 if gem_port[IS_MULTICAST] == 'True':
401 gemdict[GEM_PORT_ID] = gem_port['multicast_gem_id']
402 gemdict[IS_MULTICAST] = True
403 else:
404 gemdict[GEM_PORT_ID] = gem_port[GEM_PORT_ID]
405 gemdict[IS_MULTICAST] = False
406
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500407 gemdict['direction'] = direction
408 gemdict['alloc_id_ref'] = alloc_id_ref
409 gemdict['encryption'] = gem_port['aes_encryption']
410 gemdict['discard_config'] = dict()
411 gemdict['discard_config']['max_probability'] = \
412 gem_port['discard_config']['max_probability']
413 gemdict['discard_config']['max_threshold'] = \
414 gem_port['discard_config']['max_threshold']
415 gemdict['discard_config']['min_threshold'] = \
416 gem_port['discard_config']['min_threshold']
417 gemdict['discard_policy'] = gem_port['discard_policy']
418 gemdict['max_q_size'] = gem_port['max_q_size']
419 gemdict['pbit_map'] = gem_port['pbit_map']
420 gemdict['priority_q'] = gem_port['priority_q']
421 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
422 gemdict['weight'] = gem_port['weight']
423 gemdict['uni_id'] = uni_id
424
425 gem_port = OnuGemPort.create(self, gem_port=gemdict)
426
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500427 success = self._pon.add_gem_port(gem_port, True)
428 if success:
429 new_gem_ports.append(gem_port)
430 self.log.debug('pon-add-gemport', gem_port=gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500431
Girish Gowdrae933cd32019-11-21 21:04:41 +0530432 return new_gem_ports
433
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800434 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400435 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
436 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
437 # or initial-mib-download is not done. Once the tp_task is completed, we execute
438 # such queued vlan-filter tasks
439 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800440 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 -0400441 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800442 uni_id=uni_id, tp_id=tp_id)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800443 for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]:
444 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800445 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
446 match_vlan=filter_info.get("match_vlan"),
447 _set_vlan_vid=filter_info.get("set_vlan_vid"),
448 _set_vlan_pcp=filter_info.get("set_vlan_pcp"),
449 tp_id=filter_info.get("tp_id"))
Girish Gowdraaf98a082020-03-05 16:40:51 -0800450 # Now remove the entry from the dictionary
451 self._queued_vlan_filter_task[uni_id][tp_id].remove(filter_info)
452 self.log.debug("executed-queued-vlan-filter-task",
453 uni_id=uni_id, tp_id=tp_id)
454 # Now delete the key entries once we have handled the queued vlan filter tasks.
455 del self._queued_vlan_filter_task[uni_id]
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400456 except Exception as e:
457 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
458
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500459 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500460 us_scheduler = tp['us_scheduler']
461 alloc_id = us_scheduler['alloc_id']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800462 new_tconts = self._create_tconts(uni_id, us_scheduler)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500463 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800464 new_upstream_gems = self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500465 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800466 new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
467
468 new_gems = []
469 new_gems.extend(new_upstream_gems)
470 new_gems.extend(new_downstream_gems)
471
472 return new_tconts, new_gems
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500473
474 def load_and_configure_tech_profile(self, uni_id, tp_path):
475 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyele9110a32020-02-20 14:56:50 -0800476 tp_id = self.extract_tp_id_from_path(tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500477 if uni_id not in self._tp_service_specific_task:
478 self._tp_service_specific_task[uni_id] = dict()
479
480 if uni_id not in self._tech_profile_download_done:
481 self._tech_profile_download_done[uni_id] = dict()
482
Mahir Gunyele9110a32020-02-20 14:56:50 -0800483 if tp_id not in self._tech_profile_download_done[uni_id]:
484 self._tech_profile_download_done[uni_id][tp_id] = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500485
Mahir Gunyele9110a32020-02-20 14:56:50 -0800486 if not self._tech_profile_download_done[uni_id][tp_id]:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500487 try:
488 if tp_path in self._tp_service_specific_task[uni_id]:
489 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530490 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500491 return
492
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500493 tpstored = self.kv_client[tp_path]
494 tpstring = tpstored.decode('ascii')
495 tp = json.loads(tpstring)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800496 self._tp[tp_id] = tp
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500497 self.log.debug("tp-instance", tp=tp)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800498 tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700499
William Kurkian3a206332019-04-29 11:05:47 -0400500 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500501 def success(_results):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800502 self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500503 if tp_path in self._tp_service_specific_task[uni_id]:
504 del self._tp_service_specific_task[uni_id][tp_path]
Mahir Gunyele9110a32020-02-20 14:56:50 -0800505 self._tech_profile_download_done[uni_id][tp_id] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400506 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800507 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500508 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530509
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800510 # Execute mcast task
511 for gem in gem_ports:
512 self.log.debug("checking-multicast-service-for-gem ", gem=gem)
513 if gem.mcast is True:
514 self.log.info("found-multicast-service-for-gem ", gem=gem, uni_id=uni_id, tp_id=tp_id)
515 reactor.callInThread(self.start_multicast_service, uni_id, tp_path)
516 self.log.debug("started_multicast_service-successfully", tconts=tconts, gems=gem_ports)
517 break
518
William Kurkian3a206332019-04-29 11:05:47 -0400519 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500520 def failure(_reason):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800521 self.log.warn('tech-profile-config-failure-retrying', uni_id=uni_id, tp_id=tp_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530522 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500523 if tp_path in self._tp_service_specific_task[uni_id]:
524 del self._tp_service_specific_task[uni_id][tp_path]
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800525 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500526 reactor.callLater(retry, self.load_and_configure_tech_profile,
527 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500528 yield self.core_proxy.device_reason_update(self.device_id,
529 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500530
Mahir Gunyela982ec32020-02-25 12:30:37 -0800531 self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530532 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
533
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500534 self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
535 self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
536
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500537 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800538 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500539 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530540 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500541 self._deferred.addCallbacks(success, failure)
542
543 except Exception as e:
544 self.log.exception("error-loading-tech-profile", e=e)
545 else:
546 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530547 # Could be a case where TP exists but new gem-ports are getting added dynamically
548 tpstored = self.kv_client[tp_path]
549 tpstring = tpstored.decode('ascii')
550 tp = json.loads(tpstring)
551 upstream_gems = []
552 downstream_gems = []
553 # Find out the new Gem ports that are getting added afresh.
554 for gp in tp['upstream_gem_port_attribute_list']:
555 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
556 # gem port already exists
557 continue
558 upstream_gems.append(gp)
559 for gp in tp['downstream_gem_port_attribute_list']:
560 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
561 # gem port already exists
562 continue
563 downstream_gems.append(gp)
564
565 us_scheduler = tp['us_scheduler']
566 alloc_id = us_scheduler['alloc_id']
567
568 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
569 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
570 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
571 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
572 new_gems = []
573 new_gems.extend(new_upstream_gems)
574 new_gems.extend(new_downstream_gems)
575
576 def success(_results):
577 self.log.info("new-gem-ports-successfully-installed", result=_results)
578
579 def failure(_reason):
580 self.log.warn('new-gem-port-install-failed--retrying',
581 _reason=_reason)
582 # Remove gem ports from cache. We will re-add them during the retry
583 for gp in new_gems:
584 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
585
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800586 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500587 reactor.callLater(retry, self.load_and_configure_tech_profile,
588 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530589
590 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800591 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530592 self._deferred = \
593 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
594 self._deferred.addCallbacks(success, failure)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800595 def start_multicast_service(self, uni_id, tp_path,retry_count=0):
596 self.log.debug("starting-multicast-service", uni_id=uni_id, tp_path=tp_path)
597 tp_id = self.extract_tp_id_from_path(tp_path)
598 if uni_id in self._set_vlan and tp_id in self._set_vlan[uni_id]:
599 try:
600 tp = self._tp[tp_id]
601 if tp is None:
602 tpstored = self.kv_client[tp_path]
603 tpstring = tpstored.decode('ascii')
604 tp = json.loads(tpstring)
605 if tp is None:
606 self.log.error("cannot-find-tp-to-start-multicast-service", uni_id=uni_id, tp_path=tp_path)
607 return
608 else:
609 self._tp[tp_id] = tp
610
611 self.log.debug("mcast-vlan-learned-before", self._set_vlan[uni_id][tp_id], uni_id=uni_id, tp_id=tp_id)
612 def success(_results):
613 self.log.debug('multicast-success', uni_id=uni_id)
614 self._multicast_task = None
615
616 def failure(_reason):
617 self.log.warn('multicast-failure', _reason=_reason)
618 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
619 reactor.callLater(retry, self.start_multicast_service,
620 uni_id, tp_path)
621
622 self.log.debug('starting-multicast-task', mcast_vlan_id=self._set_vlan[uni_id][tp_id])
623 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
624 for i in range(len(downstream_gem_port_attribute_list)):
625 if IS_MULTICAST in downstream_gem_port_attribute_list[i] and \
626 downstream_gem_port_attribute_list[i][IS_MULTICAST] == 'True':
627 dynamic_access_control_list_table = downstream_gem_port_attribute_list[i]['dynamic_access_control_list'].split("-")
628 static_access_control_list_table = downstream_gem_port_attribute_list[i]['static_access_control_list'].split("-")
629 multicast_gem_id = downstream_gem_port_attribute_list[i]['multicast_gem_id']
630 break
631
632 self._multicast_task = BrcmMcastTask(self.omci_agent, self, self.device_id, uni_id, tp_id,
633 self._set_vlan[uni_id][tp_id],dynamic_access_control_list_table, static_access_control_list_table, multicast_gem_id)
634 self._deferred = self._onu_omci_device.task_runner.queue_task(self._multicast_task)
635 self._deferred.addCallbacks(success, failure)
636 except Exception as e:
637 self.log.exception("error-loading-multicast", e=e)
638 else:
639 if retry_count<30:
640 retry_count = +1
641 self.log.debug("going-to-wait-for-flow-to-learn-mcast-vlan", uni_id=uni_id, tp_id=tp_id, retry=retry_count)
642 reactor.callLater(0.5, self.start_multicast_service, uni_id, tp_path, retry_count)
643 else:
644 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 +0530645
646 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
647 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800648 tp_table_id = self.extract_tp_id_from_path(tp_path)
Naga Manjunathe433c712020-01-02 17:27:20 +0530649 if not uni_id in self._tech_profile_download_done:
650 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
651 return
652
Mahir Gunyele9110a32020-02-20 14:56:50 -0800653 if not tp_table_id in self._tech_profile_download_done[uni_id]:
654 self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id)
Naga Manjunathe433c712020-01-02 17:27:20 +0530655 return
656
Mahir Gunyele9110a32020-02-20 14:56:50 -0800657 if self._tech_profile_download_done[uni_id][tp_table_id] is not True:
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800658 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete", uni_id=uni_id,
659 tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530660 return
661
662 if alloc_id is None and gem_port_id is None:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800663 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 +0530664 return
665
666 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
667 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
668 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
669 # this initializer
670 tcont = None
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500671 self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530672 for tc in list(self.pon_port.tconts.values()):
673 if tc.alloc_id == alloc_id:
674 tcont = tc
675 self.pon_port.remove_tcont(tc.alloc_id, False)
676
677 gem_port = None
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500678 self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530679 for gp in list(self.pon_port.gem_ports.values()):
680 if gp.gem_id == gem_port_id:
681 gem_port = gp
682 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
683
Girish Gowdrae933cd32019-11-21 21:04:41 +0530684 @inlineCallbacks
685 def success(_results):
686 if gem_port_id:
687 self.log.info("gem-port-delete-done-successfully")
688 if alloc_id:
689 self.log.info("tcont-delete-done-successfully")
690 # The deletion of TCONT marks the complete deletion of tech-profile
691 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800692 del self._tech_profile_download_done[uni_id][tp_table_id]
Girish Gowdrae933cd32019-11-21 21:04:41 +0530693 del self._tp_service_specific_task[uni_id][tp_path]
694 except Exception as ex:
695 self.log.error("del-tp-state-info", e=ex)
696
697 # TODO: There could be multiple TP on the UNI, and also the ONU.
698 # TODO: But the below reason updates for the whole device.
699 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
700
701 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530702 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530703 self.log.warn('tech-profile-delete-failure-retrying',
704 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500705 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
706 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500707 yield self.core_proxy.device_reason_update(self.device_id,
708 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530709
710 self.log.info('deleting-tech-profile-configuration')
711
Girish Gowdraa73ee452019-12-20 18:52:17 +0530712 if tcont is None and gem_port is None:
713 if alloc_id is not None:
714 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
715 if gem_port_id is not None:
716 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
717 return
718
Girish Gowdrae933cd32019-11-21 21:04:41 +0530719 self._tp_service_specific_task[uni_id][tp_path] = \
720 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
721 tcont=tcont, gem_port=gem_port)
722 self._deferred = \
723 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
724 self._deferred.addCallbacks(success, failure)
725 except Exception as e:
726 self.log.exception("failed-to-delete-tp",
727 e=e, uni_id=uni_id, tp_path=tp_path,
728 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500729
730 def update_pm_config(self, device, pm_config):
731 # TODO: This has not been tested
732 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500733 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500734
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800735 def remove_onu_flows(self, device, flows):
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500736 self.log.debug('remove-onu-flows')
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800737
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800738 # no point in removing omci flows if the device isnt reachable
739 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800740 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800741 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
742 admin=device.admin_state, connect=device.connect_status)
743 return
744
745 for flow in flows:
746 # if incoming flow contains cookie, then remove from ONU
747 if flow.cookie:
748 self.log.debug("remove-flow", device_id=device.id, flow=flow)
749
750 def is_downstream(port):
751 return port == self._pon_port_number
752
753 def is_upstream(port):
754 return not is_downstream(port)
755
756 try:
757 _in_port = fd.get_in_port(flow)
758 assert _in_port is not None
759
760 _out_port = fd.get_out_port(flow) # may be None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800761
762 if is_downstream(_in_port):
763 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
764 device_id=device.id)
765 # extended vlan tagging operation will handle it
766 continue
767 elif is_upstream(_in_port):
768 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
769 if fd.is_dhcp_flow(flow):
770 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
771 return
772
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800773 _vlan_vid = 0
774 # Retrieve the VLAN_VID that needs to be removed from the EVTO rule on the ONU.
775 for action in fd.get_actions(flow):
776 if action.type == fd.SET_FIELD:
777 _field = action.set_field.field.ofb_field
778 assert (action.set_field.field.oxm_class ==
779 OFPXMC_OPENFLOW_BASIC)
780 if _field.type == fd.VLAN_VID:
781 _vlan_vid = _field.vlan_vid & 0xfff
782 self.log.debug('vlan-vid-to-remove',
783 _vlan_vid=_vlan_vid, in_port=_in_port)
784
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800785 uni_port = self.uni_port(_in_port)
786 uni_id = _in_port & 0xF
787 else:
788 raise Exception('port should be 1 or 2 by our convention')
789
790 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
791
792 tp_id = self.get_tp_id_in_flow(flow)
793 # Deleting flow from ONU.
794 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800795 match_vlan=_vlan_vid, tp_id=tp_id)
796 # TODO:Delete TD task.
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800797 except Exception as e:
798 self.log.exception('failed-to-remove-flow', e=e)
799
800 def add_onu_flows(self, device, flows):
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500801 self.log.debug('add-onu-flows')
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800802
803 # no point in pushing omci flows if the device isnt reachable
804 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800805 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800806 self.log.warn("device-disabled-or-offline-skipping-flow-update",
807 admin=device.admin_state, connect=device.connect_status)
808 return
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800809
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800810 def is_downstream(port):
811 return port == self._pon_port_number
812
813 def is_upstream(port):
814 return not is_downstream(port)
815
816 for flow in flows:
817 # if incoming flow contains cookie, then add to ONU
818 if flow.cookie:
819 _type = None
820 _port = None
821 _vlan_vid = None
822 _udp_dst = None
823 _udp_src = None
824 _ipv4_dst = None
825 _ipv4_src = None
826 _metadata = None
827 _output = None
828 _push_tpid = None
829 _field = None
830 _set_vlan_vid = None
831 _set_vlan_pcp = 0
832 _tunnel_id = None
833 self.log.debug("add-flow", device_id=device.id, flow=flow)
834
835 try:
836 _in_port = fd.get_in_port(flow)
837 assert _in_port is not None
838
839 _out_port = fd.get_out_port(flow) # may be None
840 tp_id = self.get_tp_id_in_flow(flow)
841 if is_downstream(_in_port):
842 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
843 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
844 # uni_port = self.uni_port(_out_port)
845 # uni_id = _out_port & 0xF
846 continue
847 elif is_upstream(_in_port):
848 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
849 uni_port = self.uni_port(_in_port)
850 uni_id = _in_port & 0xF
851 else:
852 raise Exception('port should be 1 or 2 by our convention')
853
854 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
855
856 for field in fd.get_ofb_fields(flow):
857 if field.type == fd.ETH_TYPE:
858 _type = field.eth_type
859 self.log.debug('field-type-eth-type',
860 eth_type=_type)
861
862 elif field.type == fd.IP_PROTO:
863 _proto = field.ip_proto
864 self.log.debug('field-type-ip-proto',
865 ip_proto=_proto)
866
867 elif field.type == fd.IN_PORT:
868 _port = field.port
869 self.log.debug('field-type-in-port',
870 in_port=_port)
871 elif field.type == fd.TUNNEL_ID:
872 self.log.debug('field-type-tunnel-id')
873
874 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100875 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
876 _vlan_vid = RESERVED_TRANSPARENT_VLAN
877 else:
878 _vlan_vid = field.vlan_vid & 0xfff
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800879 self.log.debug('field-type-vlan-vid',
880 vlan=_vlan_vid)
881
882 elif field.type == fd.VLAN_PCP:
883 _vlan_pcp = field.vlan_pcp
884 self.log.debug('field-type-vlan-pcp',
885 pcp=_vlan_pcp)
886
887 elif field.type == fd.UDP_DST:
888 _udp_dst = field.udp_dst
889 self.log.debug('field-type-udp-dst',
890 udp_dst=_udp_dst)
891
892 elif field.type == fd.UDP_SRC:
893 _udp_src = field.udp_src
894 self.log.debug('field-type-udp-src',
895 udp_src=_udp_src)
896
897 elif field.type == fd.IPV4_DST:
898 _ipv4_dst = field.ipv4_dst
899 self.log.debug('field-type-ipv4-dst',
900 ipv4_dst=_ipv4_dst)
901
902 elif field.type == fd.IPV4_SRC:
903 _ipv4_src = field.ipv4_src
904 self.log.debug('field-type-ipv4-src',
905 ipv4_dst=_ipv4_src)
906
907 elif field.type == fd.METADATA:
908 _metadata = field.table_metadata
909 self.log.debug('field-type-metadata',
910 metadata=_metadata)
911
912 else:
913 raise NotImplementedError('field.type={}'.format(
914 field.type))
915
916 for action in fd.get_actions(flow):
917
918 if action.type == fd.OUTPUT:
919 _output = action.output.port
920 self.log.debug('action-type-output',
921 output=_output, in_port=_in_port)
922
923 elif action.type == fd.POP_VLAN:
924 self.log.debug('action-type-pop-vlan',
925 in_port=_in_port)
926
927 elif action.type == fd.PUSH_VLAN:
928 _push_tpid = action.push.ethertype
929 self.log.debug('action-type-push-vlan',
930 push_tpid=_push_tpid, in_port=_in_port)
931 if action.push.ethertype != 0x8100:
932 self.log.error('unhandled-tpid',
933 ethertype=action.push.ethertype)
934
935 elif action.type == fd.SET_FIELD:
936 _field = action.set_field.field.ofb_field
937 assert (action.set_field.field.oxm_class ==
938 OFPXMC_OPENFLOW_BASIC)
939 self.log.debug('action-type-set-field',
940 field=_field, in_port=_in_port)
941 if _field.type == fd.VLAN_VID:
942 _set_vlan_vid = _field.vlan_vid & 0xfff
943 self.log.debug('set-field-type-vlan-vid',
944 vlan_vid=_set_vlan_vid)
945 elif _field.type == fd.VLAN_PCP:
946 _set_vlan_pcp = _field.vlan_pcp
947 self.log.debug('set-field-type-vlan-pcp',
948 vlan_pcp=_set_vlan_pcp)
949 else:
950 self.log.error('unsupported-action-set-field-type',
951 field_type=_field.type)
952 else:
953 self.log.error('unsupported-action-type',
954 action_type=action.type, in_port=_in_port)
955
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800956 if self._set_vlan is not None:
957 if uni_id not in self._set_vlan:
958 self._set_vlan[uni_id] = dict()
959 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
960 self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
961
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100962 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
963 # supported match and action criteria cannot be handled by omci and must be ignored.
964 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
965 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
966 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
967 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800968 _set_vlan_vid=_vlan_vid,
969 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
970 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100971 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
972 _set_vlan_vid=_vlan_vid,
973 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
974 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800975 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100976 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
977 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800978 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
979 _set_vlan_vid=_set_vlan_vid,
980 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
981 tp_id=tp_id)
982
983 except Exception as e:
984 self.log.exception('failed-to-install-flow', e=e, flow=flow)
985
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500986 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
987 # flow decomposition that ultimately comes from onos
988 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700989 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500990
991 #
992 # We need to proxy through the OLT to get to the ONU
993 # Configuration from here should be using OMCI
994 #
995 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
996
997 # no point in pushing omci flows if the device isnt reachable
998 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530999 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001000 self.log.warn("device-disabled-or-offline-skipping-flow-update",
1001 admin=device.admin_state, connect=device.connect_status)
1002 return
1003
1004 def is_downstream(port):
1005 return port == self._pon_port_number
1006
1007 def is_upstream(port):
1008 return not is_downstream(port)
1009
1010 for flow in flows:
1011 _type = None
1012 _port = None
1013 _vlan_vid = None
1014 _udp_dst = None
1015 _udp_src = None
1016 _ipv4_dst = None
1017 _ipv4_src = None
1018 _metadata = None
1019 _output = None
1020 _push_tpid = None
1021 _field = None
1022 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001023 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001024 _tunnel_id = None
1025
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001026 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +05301027 write_metadata = fd.get_write_metadata(flow)
1028 if write_metadata is None:
1029 self.log.error("do-not-process-flow-without-write-metadata")
1030 return
1031
1032 # extract tp id from flow
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001033 tp_id = self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001034 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +05301035
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001036 _in_port = fd.get_in_port(flow)
1037 assert _in_port is not None
1038
1039 _out_port = fd.get_out_port(flow) # may be None
1040
1041 if is_downstream(_in_port):
1042 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
1043 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301044 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001045 elif is_upstream(_in_port):
1046 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
1047 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001048 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001049 else:
1050 raise Exception('port should be 1 or 2 by our convention')
1051
1052 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
1053
1054 for field in fd.get_ofb_fields(flow):
1055 if field.type == fd.ETH_TYPE:
1056 _type = field.eth_type
1057 self.log.debug('field-type-eth-type',
1058 eth_type=_type)
1059
1060 elif field.type == fd.IP_PROTO:
1061 _proto = field.ip_proto
1062 self.log.debug('field-type-ip-proto',
1063 ip_proto=_proto)
1064
1065 elif field.type == fd.IN_PORT:
1066 _port = field.port
1067 self.log.debug('field-type-in-port',
1068 in_port=_port)
1069
1070 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001071 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
1072 _vlan_vid = RESERVED_TRANSPARENT_VLAN
1073 else:
1074 _vlan_vid = field.vlan_vid & 0xfff
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001075 self.log.debug('field-type-vlan-vid',
1076 vlan=_vlan_vid)
1077
1078 elif field.type == fd.VLAN_PCP:
1079 _vlan_pcp = field.vlan_pcp
1080 self.log.debug('field-type-vlan-pcp',
1081 pcp=_vlan_pcp)
1082
1083 elif field.type == fd.UDP_DST:
1084 _udp_dst = field.udp_dst
1085 self.log.debug('field-type-udp-dst',
1086 udp_dst=_udp_dst)
1087
1088 elif field.type == fd.UDP_SRC:
1089 _udp_src = field.udp_src
1090 self.log.debug('field-type-udp-src',
1091 udp_src=_udp_src)
1092
1093 elif field.type == fd.IPV4_DST:
1094 _ipv4_dst = field.ipv4_dst
1095 self.log.debug('field-type-ipv4-dst',
1096 ipv4_dst=_ipv4_dst)
1097
1098 elif field.type == fd.IPV4_SRC:
1099 _ipv4_src = field.ipv4_src
1100 self.log.debug('field-type-ipv4-src',
1101 ipv4_dst=_ipv4_src)
1102
1103 elif field.type == fd.METADATA:
1104 _metadata = field.table_metadata
1105 self.log.debug('field-type-metadata',
1106 metadata=_metadata)
1107
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001108 elif field.type == fd.TUNNEL_ID:
1109 _tunnel_id = field.tunnel_id
1110 self.log.debug('field-type-tunnel-id',
1111 tunnel_id=_tunnel_id)
1112
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001113
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001114 else:
1115 raise NotImplementedError('field.type={}'.format(
1116 field.type))
1117
1118 for action in fd.get_actions(flow):
1119
1120 if action.type == fd.OUTPUT:
1121 _output = action.output.port
1122 self.log.debug('action-type-output',
1123 output=_output, in_port=_in_port)
1124
1125 elif action.type == fd.POP_VLAN:
1126 self.log.debug('action-type-pop-vlan',
1127 in_port=_in_port)
1128
1129 elif action.type == fd.PUSH_VLAN:
1130 _push_tpid = action.push.ethertype
1131 self.log.debug('action-type-push-vlan',
1132 push_tpid=_push_tpid, in_port=_in_port)
1133 if action.push.ethertype != 0x8100:
1134 self.log.error('unhandled-tpid',
1135 ethertype=action.push.ethertype)
1136
1137 elif action.type == fd.SET_FIELD:
1138 _field = action.set_field.field.ofb_field
1139 assert (action.set_field.field.oxm_class ==
1140 OFPXMC_OPENFLOW_BASIC)
1141 self.log.debug('action-type-set-field',
1142 field=_field, in_port=_in_port)
1143 if _field.type == fd.VLAN_VID:
1144 _set_vlan_vid = _field.vlan_vid & 0xfff
1145 self.log.debug('set-field-type-vlan-vid',
1146 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001147 elif _field.type == fd.VLAN_PCP:
1148 _set_vlan_pcp = _field.vlan_pcp
1149 self.log.debug('set-field-type-vlan-pcp',
1150 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001151 else:
1152 self.log.error('unsupported-action-set-field-type',
1153 field_type=_field.type)
1154 else:
1155 self.log.error('unsupported-action-type',
1156 action_type=action.type, in_port=_in_port)
1157
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001158 if self._set_vlan is not None:
1159 if uni_id not in self._set_vlan:
1160 self._set_vlan[uni_id] = dict()
1161 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
1162 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 -04001163 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1164 # supported match and action criteria cannot be handled by omci and must be ignored.
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001165 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
1166 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
1167 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
1168 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001169 _set_vlan_vid=_vlan_vid,
1170 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1171 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001172 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1173 _set_vlan_vid=_vlan_vid,
1174 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1175 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001176 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001177 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
1178 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
1179 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1180 _set_vlan_vid=_set_vlan_vid,
1181 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1182 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001183 except Exception as e:
1184 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1185
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001186 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001187 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1188 self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1189 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001190 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001191 if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and \
1192 self._tech_profile_download_done[uni_id][tp_id] is True:
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001193 @inlineCallbacks
1194 def success(_results):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001195 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id,
1196 set_vlan_pcp=_set_vlan_pcp)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001197 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001198
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001199 @inlineCallbacks
1200 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301201 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 -08001202 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1203 reactor.callLater(retry,
1204 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1205 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1206 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001207 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001208
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001209 self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1210 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001211 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001212 match_vlan, _set_vlan_pcp, add_tag=True,
1213 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001214 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001215 self._deferred.addCallbacks(success, failure)
1216 else:
1217 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001218 uni_id=uni_id, tp_id=tp_id)
1219 if uni_id not in self._queued_vlan_filter_task:
1220 self._queued_vlan_filter_task[uni_id] = dict()
Mahir Gunyela982ec32020-02-25 12:30:37 -08001221 if tp_id not in self._queued_vlan_filter_task[uni_id]:
1222 self._queued_vlan_filter_task[uni_id][tp_id] = []
1223 self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001224 "uni_id": uni_id,
1225 "uni_port": uni_port,
1226 "match_vlan": match_vlan,
1227 "set_vlan_vid": _set_vlan_vid,
1228 "set_vlan_pcp": _set_vlan_pcp,
1229 "tp_id": tp_id})
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001230
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001231 def get_tp_id_in_flow(self, flow):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001232 flow_metadata = fd.get_metadata_from_write_metadata(flow)
1233 tp_id = fd.get_tp_id_from_metadata(flow_metadata)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001234 return tp_id
1235
1236 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001237 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001238 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001239
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001240 @inlineCallbacks
1241 def success(_results):
1242 self.log.info('vlan-untagging-success', _results=_results)
1243 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1244
1245 @inlineCallbacks
1246 def failure(_reason):
1247 self.log.warn('vlan-untagging-failure', _reason=_reason)
1248 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001249 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001250 reactor.callLater(retry,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001251 self._remove_vlan_filter_task, device, uni_id,
1252 add_tag=False, uni_port=uni_port)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001253
1254 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1255 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001256 match_vlan, _set_vlan_pcp, add_tag=False,
1257 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001258 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1259 self._deferred.addCallbacks(success, failure)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001260
Matt Jeannereta32441c2019-03-07 05:16:37 -05001261 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001262 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1263 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeanneret2101f3d2020-03-12 10:13:06 -04001264
1265 if not self.enabled:
1266 self.log.warn('device-not-activated')
1267 reactor.callLater(0.5, self.process_inter_adapter_message, request)
1268 return
1269
Matt Jeannereta32441c2019-03-07 05:16:37 -05001270 try:
1271 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1272 omci_msg = InterAdapterOmciMessage()
1273 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001274 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001275
Matt Jeannereta32441c2019-03-07 05:16:37 -05001276 self.receive_message(omci_msg.message)
1277
1278 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1279 onu_indication = OnuIndication()
1280 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001281 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1282 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1283 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001284
1285 if onu_indication.oper_state == "up":
1286 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301287 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001288 self.update_interface(onu_indication)
1289 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001290 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1291 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001292
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001293 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1294 tech_msg = InterAdapterTechProfileDownloadMessage()
1295 request.body.Unpack(tech_msg)
1296 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1297
1298 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1299
Girish Gowdrae933cd32019-11-21 21:04:41 +05301300 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1301 del_gem_msg = InterAdapterDeleteGemPortMessage()
1302 request.body.Unpack(del_gem_msg)
1303 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1304
1305 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1306 gem_port_id=del_gem_msg.gem_port_id,
1307 tp_path=del_gem_msg.tp_path)
1308
1309 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1310 del_tcont_msg = InterAdapterDeleteTcontMessage()
1311 request.body.Unpack(del_tcont_msg)
1312 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1313
1314 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1315 alloc_id=del_tcont_msg.alloc_id,
1316 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001317 else:
1318 self.log.error("inter-adapter-unhandled-type", request=request)
1319
1320 except Exception as e:
1321 self.log.exception("error-processing-inter-adapter-message", e=e)
1322
1323 # Called each time there is an onu "up" indication from the olt handler
1324 @inlineCallbacks
1325 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001326 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001327 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001328
1329 # Ignore if onu_indication is received for an already running ONU
1330 if self._onu_omci_device is not None and self._onu_omci_device.active:
1331 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1332 return
1333
Matt Jeannereta32441c2019-03-07 05:16:37 -05001334 self._onu_indication = onu_indication
1335
Matt Jeanneretc083f462019-03-11 15:02:01 -04001336 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1337 connect_status=ConnectStatus.REACHABLE)
1338
Matt Jeannereta32441c2019-03-07 05:16:37 -05001339 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001340
1341 self.log.debug('starting-openomci-statemachine')
1342 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001343 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301344 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001345 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001346 self._heartbeat.enabled = True
1347
Matt Jeanneret42dad792020-02-01 09:28:27 -05001348 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001349 @inlineCallbacks
1350 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001351 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001352 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001353
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001354 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001355 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001356 reactor.callLater(0, self._onu_omci_device.stop)
1357
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001358 self._tp = dict()
1359
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001360 # Let TP download happen again
1361 for uni_id in self._tp_service_specific_task:
1362 self._tp_service_specific_task[uni_id].clear()
1363 for uni_id in self._tech_profile_download_done:
1364 self._tech_profile_download_done[uni_id].clear()
1365
Matt Jeanneretf4113222019-08-14 19:44:34 -04001366 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001367 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1368 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1369 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001370 else:
1371 self.log.debug('not-changing-openomci-statemachine')
1372
Matt Jeanneretf4113222019-08-14 19:44:34 -04001373 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001374 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001375 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001376 try:
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001377 yield self.disable_ports(lock_ports=True, device_disabled=True)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001378 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1379 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001380 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001381 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001382
William Kurkian3a206332019-04-29 11:05:47 -04001383 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001384 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001385 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001386 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001387 yield self.core_proxy.device_state_update(device.id,
1388 oper_status=OperStatus.ACTIVE,
1389 connect_status=ConnectStatus.REACHABLE)
1390 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1391 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001392 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001393 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001394
William Kurkian3a206332019-04-29 11:05:47 -04001395 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001396 def reboot(self):
1397 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001398 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001399 if device.connect_status != ConnectStatus.REACHABLE:
1400 self.log.error("device-unreachable")
1401 return
1402
William Kurkian3a206332019-04-29 11:05:47 -04001403 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001404 def success(_results):
1405 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001406 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001407
1408 def failure(_reason):
1409 self.log.info('reboot-failure', _reason=_reason)
1410
1411 self._deferred = self._onu_omci_device.reboot()
1412 self._deferred.addCallbacks(success, failure)
1413
William Kurkian3a206332019-04-29 11:05:47 -04001414 @inlineCallbacks
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001415 def disable_ports(self, lock_ports=True, device_disabled=False):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001416 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001417
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001418 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1419 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001420 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001421 if port.mac_bridge_port_num == 1:
1422 port.operstatus = OperStatus.UNKNOWN
1423 self.log.info('disable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001424 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1425 port.operstatus)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001426
1427 if lock_ports is True:
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001428 self.lock_ports(lock=True, device_disabled=device_disabled)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001429
William Kurkian3a206332019-04-29 11:05:47 -04001430 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001431 def enable_ports(self):
1432 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001433
Matt Jeanneretf4113222019-08-14 19:44:34 -04001434 self.lock_ports(lock=False)
1435
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001436 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1437 # load on the core
1438 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001439 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001440 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001441 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001442 self.log.info('enable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001443 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1444 port.operstatus)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001445
1446 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1447 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1448 #
1449 # Basically the link state sequence:
1450 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1451 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1452 # 3) a link state up alarm is received for the uni plugged in.
1453 #
1454 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1455 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1456 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1457 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001458 @inlineCallbacks
1459 def port_state_handler(self, _topic, msg):
1460 self.log.info("port-state-change", _topic=_topic, msg=msg)
1461
1462 onu_id = msg['onu_id']
1463 port_no = msg['port_number']
1464 serial_number = msg['serial_number']
1465 port_status = msg['port_status']
1466 uni_port = self.uni_port(int(port_no))
1467
1468 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1469 port_status=port_status)
1470
1471 if port_status is True:
1472 uni_port.operstatus = OperStatus.ACTIVE
1473 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1474 else:
1475 uni_port.operstatus = OperStatus.UNKNOWN
1476 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1477
1478 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 -05001479 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001480
1481 # Called just before openomci state machine is started. These listen for events from selected state machines,
1482 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1483 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001484 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001485
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001486 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001487
1488 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001489 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1490 OnuDeviceEvents.MibDatabaseSyncEvent)
1491 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1492
1493 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001494 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1495 OnuDeviceEvents.OmciCapabilitiesEvent)
1496 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1497
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001498 # TODO: these alarms seem to be unreliable depending on the environment
1499 # 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 -08001500 # topic = OnuDeviceEntry.event_bus_topic(self.device_id,
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001501 # OnuDeviceEvents.PortEvent)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001502 # self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001503
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001504 # Called when the mib is in sync
1505 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001506 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001507 if self._in_sync_subscription is not None:
1508 try:
1509 in_sync = msg[IN_SYNC_KEY]
1510
1511 if in_sync:
1512 # Only call this once
1513 bus = self._onu_omci_device.event_bus
1514 bus.unsubscribe(self._in_sync_subscription)
1515 self._in_sync_subscription = None
1516
1517 # Start up device_info load
1518 self.log.debug('running-mib-sync')
1519 reactor.callLater(0, self._mib_in_sync)
1520
1521 except Exception as e:
1522 self.log.exception('in-sync', e=e)
1523
1524 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001525 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001526 if self._capabilities_subscription is not None:
1527 self.log.debug('capabilities-handler-done')
1528
1529 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1530 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1531 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001532 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001533 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001534 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001535
1536 omci = self._onu_omci_device
1537 in_sync = omci.mib_db_in_sync
1538
Matt Jeanneretc083f462019-03-11 15:02:01 -04001539 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001540 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001541
1542 if not self._dev_info_loaded:
1543 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1544
1545 omci_dev = self._onu_omci_device
1546 config = omci_dev.configuration
1547
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001548 try:
1549
1550 # sort the lists so we get consistent port ordering.
1551 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1552 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1553 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1554 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1555
1556 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001557 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001558 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001559 raise Exception("onu-missing-required-elements")
1560
1561 # Currently logging the ani, pptp, veip, and uni for information purposes.
1562 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1563 # And in some ONU the UNI-G list is incomplete or incorrect...
1564 for entity_id in ani_list:
1565 ani_value = config.ani_g_entities[entity_id]
1566 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1567 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1568 self._total_tcont_count = ani_value.get('total-tcont-count')
1569 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1570
1571 for entity_id in uni_list:
1572 uni_value = config.uni_g_entities[entity_id]
1573 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1574
1575 uni_entities = OrderedDict()
1576 for entity_id in pptp_list:
1577 pptp_value = config.pptp_entities[entity_id]
1578 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1579 uni_entities[entity_id] = UniType.PPTP
1580
1581 for entity_id in veip_list:
1582 veip_value = config.veip_entities[entity_id]
1583 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1584 uni_entities[entity_id] = UniType.VEIP
1585
1586 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001587 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001588 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001589 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001590 uni_id += 1
1591 except AssertionError as e:
1592 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1593
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001594 self._qos_flexibility = config.qos_configuration_flexibility or 0
1595 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1596
1597 if self._unis:
1598 self._dev_info_loaded = True
1599 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001600 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001601 self.log.warn("no-usable-unis")
1602 raise Exception("no-usable-unis")
1603
1604 except Exception as e:
1605 self.log.exception('device-info-load', e=e)
1606 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1607
1608 else:
1609 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1610
1611 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001612 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001613
1614 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001615 def success(_results):
1616 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001617 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301618 oper_status=OperStatus.ACTIVE,
1619 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001620 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001621 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001622 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001623 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001624
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001625 # Start collecting stats from the device after a brief pause
1626 if not self._pm_metrics_started:
1627 self._pm_metrics_started = True
1628 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1629 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1630
1631 # Start test requests after a brief pause
1632 if not self._test_request_started:
1633 self._test_request_started = True
1634 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1635 reactor.callLater(tststart, self._test_request.start_collector)
1636
Matt Jeanneretc083f462019-03-11 15:02:01 -04001637 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001638 def failure(_reason):
1639 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001640 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001641 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001642 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001643
Matt Jeanneretf4113222019-08-14 19:44:34 -04001644 # start by locking all the unis till mib sync and initial mib is downloaded
1645 # this way we can capture the port down/up events when we are ready
1646 self.lock_ports(lock=True)
1647
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001648 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1649 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1650 self.log.info('downloading-initial-mib-configuration')
1651 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1652 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1653 self._deferred.addCallbacks(success, failure)
1654 else:
1655 self.log.info('admin-down-disabling')
1656 self.disable(device)
1657 else:
1658 self.log.info('device-info-not-loaded-skipping-mib-download')
1659
Matt Jeanneretc083f462019-03-11 15:02:01 -04001660 @inlineCallbacks
1661 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001662 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001663
Matt Jeanneretc083f462019-03-11 15:02:01 -04001664 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 -05001665
1666 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1667 uni_name = "uni-{}".format(uni_no)
1668
Girish Gowdrae933cd32019-11-21 21:04:41 +05301669 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001670
1671 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 -04001672 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001673
1674 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1675 uni_port.entity_id = entity_id
1676 uni_port.enabled = True
1677 uni_port.mac_bridge_port_num = mac_bridge_port_num
1678
1679 self.log.debug("created-uni-port", uni=uni_port)
1680
Matt Jeanneretc083f462019-03-11 15:02:01 -04001681 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001682
1683 self._unis[uni_port.port_number] = uni_port
1684
1685 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301686 uni_ports=self.uni_ports,
1687 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001688
Matt Jeanneretc083f462019-03-11 15:02:01 -04001689 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1690 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001691 MAX_PONS_PER_OLT = 256
1692 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001693 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001694
Matt Jeanneretc083f462019-03-11 15:02:01 -04001695 assert intf_id < MAX_PONS_PER_OLT
1696 assert onu_id < MAX_ONUS_PER_PON
1697 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001698 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001699
1700 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001701 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001702 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001703 try:
1704 device = yield self.core_proxy.get_device(self.device_id)
1705 parent_device = yield self.core_proxy.get_device(self.parent_id)
1706 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001707 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001708
1709 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301710 pon_id=self._onu_indication.intf_id,
1711 onu_id=self._onu_indication.onu_id,
1712 registration_id=self.device_id,
1713 device_id=self.device_id,
1714 onu_serial_number=device.serial_number,
1715 olt_serial_number=olt_serial_number,
1716 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001717
Devmalya Paulffc89df2019-07-31 17:43:13 -04001718 self.log.debug("Trying-to-raise-onu-active-event")
1719 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001720 self._onu_indication.intf_id,
1721 device.serial_number,
1722 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301723 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001724 onu_id=self._onu_indication.onu_id).send(True)
1725 except Exception as active_event_error:
1726 self.log.exception('onu-activated-event-error',
1727 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001728
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001729 @inlineCallbacks
1730 def onu_disabled_event(self):
1731 self.log.debug('onu-disabled-event')
1732 try:
1733 device = yield self.core_proxy.get_device(self.device_id)
1734 parent_device = yield self.core_proxy.get_device(self.parent_id)
1735 olt_serial_number = parent_device.serial_number
1736 raised_ts = arrow.utcnow().timestamp
1737
1738 self.log.debug("onu-indication-context-data",
1739 pon_id=self._onu_indication.intf_id,
1740 onu_id=self._onu_indication.onu_id,
1741 registration_id=self.device_id,
1742 device_id=self.device_id,
1743 onu_serial_number=device.serial_number,
1744 olt_serial_number=olt_serial_number,
1745 raised_ts=raised_ts)
1746
1747 self.log.debug("Trying-to-raise-onu-disabled-event")
1748 OnuDisabledEvent(self.events, self.device_id,
1749 self._onu_indication.intf_id,
1750 device.serial_number,
1751 str(self.device_id),
1752 olt_serial_number, raised_ts,
1753 onu_id=self._onu_indication.onu_id).send(True)
1754 except Exception as active_event_error:
1755 self.log.exception('onu-disabled-event-error',
1756 errmsg=active_event_error.message)
1757
1758 def lock_ports(self, lock=True, device_disabled=False):
Matt Jeanneretf4113222019-08-14 19:44:34 -04001759
1760 def success(response):
1761 self.log.debug('set-onu-ports-state', lock=lock, response=response)
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001762 if device_disabled:
1763 self.onu_disabled_event()
Matt Jeanneretf4113222019-08-14 19:44:34 -04001764
1765 def failure(response):
1766 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1767
1768 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1769 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1770 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001771
1772 def extract_tp_id_from_path(self, tp_path):
1773 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001774 tp_id = int(tp_path.split(_PATH_SEPERATOR)[1])
1775 return tp_id
onkarkundargia1e2af22020-01-27 11:51:43 +05301776
1777 def start_omci_test_action(self, device, uuid):
1778 """
1779
1780 :param device:
1781 :return:
1782 """
1783 # Code to Run OMCI Test Action
1784 self.log.info('Omci-test-action-request-On', request=device.id)
1785 kwargs_omci_test_action = {
1786 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
1787 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
1788 }
1789 serial_number = device.serial_number
1790 if device.connect_status != ConnectStatus.REACHABLE or device.admin_state != AdminState.ENABLED:
1791 return (TestResponse(result=TestResponse.FAILURE))
1792 test_request = OmciTestRequest(self.core_proxy,
1793 self.omci_agent, self.device_id, AniG,
1794 serial_number,
1795 self.logical_device_id, exclusive=False,
1796 uuid=uuid,
1797 **kwargs_omci_test_action)
1798 test_request.perform_test_omci()
1799 return (TestResponse(result=TestResponse.SUCCESS))