blob: dde57678a62e2a80315d0ec0a8bae41fba29f0f2 [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
2# Copyright 2017 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17"""
18Broadcom OpenOMCI OLT/ONU adapter handler.
19"""
20
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050021from __future__ import absolute_import
22import six
Devmalya Paulffc89df2019-07-31 17:43:13 -040023import arrow
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050024import structlog
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050025import json
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050026import random
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050027
28from collections import OrderedDict
29
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050030from twisted.internet import reactor
31from twisted.internet.defer import DeferredQueue, inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050032
33from heartbeat import HeartBeat
Devmalya Paulffc89df2019-07-31 17:43:13 -040034from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent
35from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
36from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
37from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050038
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050039import pyvoltha.common.openflow.utils as fd
40from pyvoltha.common.utils.registry import registry
Matteo Scandolod8d73172019-11-26 12:15:15 -070041from pyvoltha.adapters.common.frameio.frameio import hexify
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050042from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050043from pyvoltha.common.config.config_backend import ConsulStore
44from pyvoltha.common.config.config_backend import EtcdStore
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050045from voltha_protos.logical_device_pb2 import LogicalPort
William Kurkian8235c1e2019-03-05 12:58:28 -050046from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretf4113222019-08-14 19:44:34 -040047from voltha_protos.device_pb2 import Port
Girish Gowdra4c11ddb2020-03-03 11:33:24 -080048from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE, OFPPS_LINK_DOWN, \
Matt Jeanneretf4113222019-08-14 19:44:34 -040049 OFPPF_FIBER, OFPPF_1GB_FD
Matt Jeanneret3bfebff2019-04-12 18:25:03 -040050from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
Girish Gowdrae933cd32019-11-21 21:04:41 +053051 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
52 InterAdapterDeleteTcontMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050053from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050054from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
55from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050056 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050057from omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdrae933cd32019-11-21 21:04:41 +053058from omci.brcm_tp_setup_task import BrcmTpSetupTask
59from omci.brcm_tp_delete_task import BrcmTpDeleteTask
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050060from omci.brcm_uni_lock_task import BrcmUniLockTask
61from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050062from onu_gem_port import OnuGemPort
63from onu_tcont import OnuTCont
64from pon_port import PonPort
65from uni_port import UniPort, UniType
Andrea Campanellacf916ea2020-02-14 10:03:58 +010066from uni_port import RESERVED_TRANSPARENT_VLAN
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050067from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053068from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
69from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050070from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050071
72OP = EntityOperations
73RC = ReasonCodes
74
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050075_STARTUP_RETRY_WAIT = 10
Mahir Gunyele9110a32020-02-20 14:56:50 -080076_PATH_SEPERATOR = "/"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050077
78
79class BrcmOpenomciOnuHandler(object):
80
81 def __init__(self, adapter, device_id):
82 self.log = structlog.get_logger(device_id=device_id)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050083 self.log.debug('starting-handler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050084 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050085 self.core_proxy = adapter.core_proxy
86 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050087 self.parent_id = None
88 self.device_id = device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050089 self.proxy_address = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050090 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040091 self.events = None
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050092 self._pm_metrics = None
93 self._pm_metrics_started = False
94 self._test_request = None
95 self._test_request_started = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050096 self._omcc_version = OMCCVersion.Unknown
97 self._total_tcont_count = 0 # From ANI-G ME
98 self._qos_flexibility = 0 # From ONT2_G ME
99
100 self._onu_indication = None
101 self._unis = dict() # Port # -> UniPort
102
103 self._pon = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500104 self._pon_port_number = 100
105 self.logical_device_id = None
106
107 self._heartbeat = HeartBeat.create(self, device_id)
108
109 # Set up OpenOMCI environment
110 self._onu_omci_device = None
111 self._dev_info_loaded = False
112 self._deferred = None
113
114 self._in_sync_subscription = None
Matt Jeanneretf4113222019-08-14 19:44:34 -0400115 self._port_state_subscription = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500116 self._connectivity_subscription = None
117 self._capabilities_subscription = None
118
119 self.mac_bridge_service_profile_entity_id = 0x201
120 self.gal_enet_profile_entity_id = 0x1
121
122 self._tp_service_specific_task = dict()
123 self._tech_profile_download_done = dict()
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400124 # Stores information related to queued vlan filter tasks
125 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
126
127 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500128
129 # Initialize KV store client
130 self.args = registry('main').get_args()
131 if self.args.backend == 'etcd':
132 host, port = self.args.etcd.split(':', 1)
133 self.kv_client = EtcdStore(host, port,
134 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
135 elif self.args.backend == 'consul':
136 host, port = self.args.consul.split(':', 1)
137 self.kv_client = ConsulStore(host, port,
138 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
139 else:
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500140 self.log.error('invalid-backend')
141 raise Exception("invalid-backend-for-kv-store")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500142
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500143 @property
144 def enabled(self):
145 return self._enabled
146
147 @enabled.setter
148 def enabled(self, value):
149 if self._enabled != value:
150 self._enabled = value
151
152 @property
153 def omci_agent(self):
154 return self.adapter.omci_agent
155
156 @property
157 def omci_cc(self):
158 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
159
160 @property
161 def heartbeat(self):
162 return self._heartbeat
163
164 @property
165 def uni_ports(self):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500166 return list(self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500167
168 def uni_port(self, port_no_or_name):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500169 if isinstance(port_no_or_name, six.string_types):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500170 return next((uni for uni in self.uni_ports
171 if uni.name == port_no_or_name), None)
172
173 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
174 return next((uni for uni in self.uni_ports
Girish Gowdrae933cd32019-11-21 21:04:41 +0530175 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500176
177 @property
178 def pon_port(self):
179 return self._pon
180
Girish Gowdraa73ee452019-12-20 18:52:17 +0530181 @property
182 def onu_omci_device(self):
183 return self._onu_omci_device
184
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500185 def receive_message(self, msg):
186 if self.omci_cc is not None:
187 self.omci_cc.receive_message(msg)
188
Matt Jeanneretc083f462019-03-11 15:02:01 -0400189 def get_ofp_port_info(self, device, port_no):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500190 self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400191 cap = OFPPF_1GB_FD | OFPPF_FIBER
192
Girish Gowdrae933cd32019-11-21 21:04:41 +0530193 hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
194 ((device.parent_port_no >> 8 & 0xff),
195 device.parent_port_no & 0xff,
196 (port_no >> 16) & 0xff,
197 (port_no >> 8) & 0xff,
198 port_no & 0xff))
Matt Jeanneretc083f462019-03-11 15:02:01 -0400199
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400200 uni_port = self.uni_port(int(port_no))
201 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500202 self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port)
Matt Jeanneretf4113222019-08-14 19:44:34 -0400203
204 ofstate = OFPPS_LINK_DOWN
205 if uni_port.operstatus is OperStatus.ACTIVE:
206 ofstate = OFPPS_LIVE
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400207
Matt Jeanneretc083f462019-03-11 15:02:01 -0400208 return PortCapability(
209 port=LogicalPort(
210 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400211 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400212 hw_addr=hw_addr,
213 config=0,
Matt Jeanneretf4113222019-08-14 19:44:34 -0400214 state=ofstate,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400215 curr=cap,
216 advertised=cap,
217 peer=cap,
218 curr_speed=OFPPF_1GB_FD,
219 max_speed=OFPPF_1GB_FD
220 ),
221 device_id=device.id,
222 device_port_no=port_no
223 )
224 )
225
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500226 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500227 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500228 def activate(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700229 self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500230
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500231 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500232 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500233 assert device.proxy_address.device_id
234
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500235 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500236 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500237 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500238 if self.enabled is not True:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700239 self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500240 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500241 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500242 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500243 device.reason = 'activating-onu'
244
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500245 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400246 # pm_metrics requires a logical device id. For now set to just device_id
247 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500248
Matt Jeannereta32441c2019-03-07 05:16:37 -0500249 yield self.core_proxy.device_update(device)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500250 self.log.debug('device-updated', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500251
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700252 yield self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500253
Matteo Scandolod8d73172019-11-26 12:15:15 -0700254 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500255 ############################################################################
Devmalya Paulffc89df2019-07-31 17:43:13 -0400256 # Setup Alarm handler
257 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
258 device.serial_number)
259 ############################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500260 # Setup PM configuration for this device
261 # Pass in ONU specific options
262 kwargs = {
263 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
264 'heartbeat': self.heartbeat,
265 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
266 }
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500267 self.log.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500268 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800269 self.logical_device_id, device.serial_number,
270 grouped=True, freq_override=False, **kwargs)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500271 pm_config = self._pm_metrics.make_proto()
272 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530273 self.log.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500274 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500275
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500276 # Note, ONU ID and UNI intf set in add_uni_port method
Devmalya Paulffc89df2019-07-31 17:43:13 -0400277 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500278 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500279
onkarkundargiaae99712019-09-23 15:02:52 +0530280 # Code to Run OMCI Test Action
281 kwargs_omci_test_action = {
282 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
283 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
284 }
285 serial_number = device.serial_number
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500286 self._test_request = OmciTestRequest(self.core_proxy,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800287 self.omci_agent, self.device_id,
288 AniG, serial_number,
289 self.logical_device_id,
290 exclusive=False,
291 **kwargs_omci_test_action)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500292
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500293 self.enabled = True
294 else:
295 self.log.info('onu-already-activated')
296
297 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400298 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500299 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700300 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500301
302 # first we verify that we got parent reference and proxy info
303 assert device.parent_id
304 assert device.proxy_address.device_id
305
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700306 self.proxy_address = device.proxy_address
307 self.parent_id = device.parent_id
308 self._pon_port_number = device.parent_port_no
309
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500310 if self.enabled is not True:
311 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700312 self.logical_device_id = self.device_id
313 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500314
315 # need to restart state machines on vcore restart. there is no indication to do it for us.
316 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700317 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500318
319 # TODO: this is probably a bit heavy handed
320 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
321 # This may not be necessary when mib resync actually works
322 reactor.callLater(1, self.reboot)
323
324 self.enabled = True
325 else:
326 self.log.info('onu-already-activated')
327
328 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700329 def _init_pon_state(self):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500330 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 -0500331
332 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500333 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700334 self.log.debug('adding-pon-port-to-agent',
335 type=self._pon.get_port().type,
336 admin_state=self._pon.get_port().admin_state,
337 oper_status=self._pon.get_port().oper_status,
338 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500339
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700340 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500341
Matteo Scandolod8d73172019-11-26 12:15:15 -0700342 self.log.debug('added-pon-port-to-agent',
343 type=self._pon.get_port().type,
344 admin_state=self._pon.get_port().admin_state,
345 oper_status=self._pon.get_port().oper_status,
346 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500347
348 # Create and start the OpenOMCI ONU Device Entry for this ONU
349 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500350 self.core_proxy,
351 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500352 support_classes=self.adapter.broadcom_omci,
353 custom_me_map=self.adapter.custom_me_entities())
354 # Port startup
355 if self._pon is not None:
356 self._pon.enabled = True
357
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500358 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700359 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret42dad792020-02-01 09:28:27 -0500360
361 self._deferred.cancel()
362 self._test_request.stop_collector()
363 self._pm_metrics.stop_collector()
364 self.log.debug('removing-openomci-statemachine')
365 self.omci_agent.remove_device(device.id, cleanup=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500366
367 def _create_tconts(self, uni_id, us_scheduler):
368 alloc_id = us_scheduler['alloc_id']
369 q_sched_policy = us_scheduler['q_sched_policy']
370 self.log.debug('create-tcont', us_scheduler=us_scheduler)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800371 # TODO: revisit for multi tconts support
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800372 new_tconts = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500373 tcontdict = dict()
374 tcontdict['alloc-id'] = alloc_id
375 tcontdict['q_sched_policy'] = q_sched_policy
376 tcontdict['uni_id'] = uni_id
377
Matt Jeanneret3789d0d2020-01-19 09:03:42 -0500378 tcont = OnuTCont.create(self, tcont=tcontdict)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500379
380 self._pon.add_tcont(tcont)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800381 new_tconts.append(tcont)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500382 self.log.debug('pon-add-tcont', tcont=tcont)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800383 return new_tconts
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500384
385 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
386 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
387 self.log.debug('create-gemport',
388 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530389 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500390 for gem_port in gem_ports:
391 gemdict = dict()
392 gemdict['gemport_id'] = gem_port['gemport_id']
393 gemdict['direction'] = direction
394 gemdict['alloc_id_ref'] = alloc_id_ref
395 gemdict['encryption'] = gem_port['aes_encryption']
396 gemdict['discard_config'] = dict()
397 gemdict['discard_config']['max_probability'] = \
398 gem_port['discard_config']['max_probability']
399 gemdict['discard_config']['max_threshold'] = \
400 gem_port['discard_config']['max_threshold']
401 gemdict['discard_config']['min_threshold'] = \
402 gem_port['discard_config']['min_threshold']
403 gemdict['discard_policy'] = gem_port['discard_policy']
404 gemdict['max_q_size'] = gem_port['max_q_size']
405 gemdict['pbit_map'] = gem_port['pbit_map']
406 gemdict['priority_q'] = gem_port['priority_q']
407 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
408 gemdict['weight'] = gem_port['weight']
409 gemdict['uni_id'] = uni_id
410
411 gem_port = OnuGemPort.create(self, gem_port=gemdict)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530412 new_gem_ports.append(gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500413
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800414 self._pon.add_gem_port(gem_port, True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500415
416 self.log.debug('pon-add-gemport', gem_port=gem_port)
417
Girish Gowdrae933cd32019-11-21 21:04:41 +0530418 return new_gem_ports
419
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800420 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400421 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
422 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
423 # or initial-mib-download is not done. Once the tp_task is completed, we execute
424 # such queued vlan-filter tasks
425 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800426 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 -0400427 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800428 uni_id=uni_id, tp_id=tp_id)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800429 for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]:
430 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800431 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
432 match_vlan=filter_info.get("match_vlan"),
433 _set_vlan_vid=filter_info.get("set_vlan_vid"),
434 _set_vlan_pcp=filter_info.get("set_vlan_pcp"),
435 tp_id=filter_info.get("tp_id"))
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400436 # Now remove the entry from the dictionary
Mahir Gunyela982ec32020-02-25 12:30:37 -0800437 self._queued_vlan_filter_task[uni_id][tp_id].remove(filter_info)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400438 self.log.debug("executed-queued-vlan-filter-task",
Mahir Gunyela982ec32020-02-25 12:30:37 -0800439 uni_id=uni_id, tp_id=tp_id)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400440 except Exception as e:
441 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
442
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500443 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500444 us_scheduler = tp['us_scheduler']
445 alloc_id = us_scheduler['alloc_id']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800446 new_tconts = self._create_tconts(uni_id, us_scheduler)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500447 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800448 new_upstream_gems = self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500449 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800450 new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
451
452 new_gems = []
453 new_gems.extend(new_upstream_gems)
454 new_gems.extend(new_downstream_gems)
455
456 return new_tconts, new_gems
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500457
458 def load_and_configure_tech_profile(self, uni_id, tp_path):
459 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyele9110a32020-02-20 14:56:50 -0800460 tp_id = self.extract_tp_id_from_path(tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500461 if uni_id not in self._tp_service_specific_task:
462 self._tp_service_specific_task[uni_id] = dict()
463
464 if uni_id not in self._tech_profile_download_done:
465 self._tech_profile_download_done[uni_id] = dict()
466
Mahir Gunyele9110a32020-02-20 14:56:50 -0800467 if tp_id not in self._tech_profile_download_done[uni_id]:
468 self._tech_profile_download_done[uni_id][tp_id] = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500469
Mahir Gunyele9110a32020-02-20 14:56:50 -0800470 if not self._tech_profile_download_done[uni_id][tp_id]:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500471 try:
472 if tp_path in self._tp_service_specific_task[uni_id]:
473 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530474 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500475 return
476
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500477 tpstored = self.kv_client[tp_path]
478 tpstring = tpstored.decode('ascii')
479 tp = json.loads(tpstring)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530480
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500481 self.log.debug("tp-instance", tp=tp)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800482 tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700483
William Kurkian3a206332019-04-29 11:05:47 -0400484 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500485 def success(_results):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800486 self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500487 if tp_path in self._tp_service_specific_task[uni_id]:
488 del self._tp_service_specific_task[uni_id][tp_path]
Mahir Gunyele9110a32020-02-20 14:56:50 -0800489 self._tech_profile_download_done[uni_id][tp_id] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400490 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800491 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500492 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530493
William Kurkian3a206332019-04-29 11:05:47 -0400494 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500495 def failure(_reason):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800496 self.log.warn('tech-profile-config-failure-retrying', uni_id=uni_id, tp_id=tp_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530497 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500498 if tp_path in self._tp_service_specific_task[uni_id]:
499 del self._tp_service_specific_task[uni_id][tp_path]
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800500 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500501 reactor.callLater(retry, self.load_and_configure_tech_profile,
502 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500503 yield self.core_proxy.device_reason_update(self.device_id,
504 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500505
Mahir Gunyela982ec32020-02-25 12:30:37 -0800506 self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530507 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
508
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500509 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800510 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500511 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530512 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500513 self._deferred.addCallbacks(success, failure)
514
515 except Exception as e:
516 self.log.exception("error-loading-tech-profile", e=e)
517 else:
518 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530519 # Could be a case where TP exists but new gem-ports are getting added dynamically
520 tpstored = self.kv_client[tp_path]
521 tpstring = tpstored.decode('ascii')
522 tp = json.loads(tpstring)
523 upstream_gems = []
524 downstream_gems = []
525 # Find out the new Gem ports that are getting added afresh.
526 for gp in tp['upstream_gem_port_attribute_list']:
527 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
528 # gem port already exists
529 continue
530 upstream_gems.append(gp)
531 for gp in tp['downstream_gem_port_attribute_list']:
532 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
533 # gem port already exists
534 continue
535 downstream_gems.append(gp)
536
537 us_scheduler = tp['us_scheduler']
538 alloc_id = us_scheduler['alloc_id']
539
540 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
541 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
542 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
543 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
544 new_gems = []
545 new_gems.extend(new_upstream_gems)
546 new_gems.extend(new_downstream_gems)
547
548 def success(_results):
549 self.log.info("new-gem-ports-successfully-installed", result=_results)
550
551 def failure(_reason):
552 self.log.warn('new-gem-port-install-failed--retrying',
553 _reason=_reason)
554 # Remove gem ports from cache. We will re-add them during the retry
555 for gp in new_gems:
556 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
557
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800558 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500559 reactor.callLater(retry, self.load_and_configure_tech_profile,
560 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530561
562 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800563 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530564 self._deferred = \
565 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
566 self._deferred.addCallbacks(success, failure)
567
568 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
569 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800570 tp_table_id = self.extract_tp_id_from_path(tp_path)
Naga Manjunathe433c712020-01-02 17:27:20 +0530571 if not uni_id in self._tech_profile_download_done:
572 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
573 return
574
Mahir Gunyele9110a32020-02-20 14:56:50 -0800575 if not tp_table_id in self._tech_profile_download_done[uni_id]:
576 self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id)
Naga Manjunathe433c712020-01-02 17:27:20 +0530577 return
578
Mahir Gunyele9110a32020-02-20 14:56:50 -0800579 if self._tech_profile_download_done[uni_id][tp_table_id] is not True:
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800580 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete", uni_id=uni_id,
581 tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530582 return
583
584 if alloc_id is None and gem_port_id is None:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800585 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 +0530586 return
587
588 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
589 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
590 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
591 # this initializer
592 tcont = None
593 self.log.debug("tconts", tconts=list(self.pon_port.tconts.values()))
594 for tc in list(self.pon_port.tconts.values()):
595 if tc.alloc_id == alloc_id:
596 tcont = tc
597 self.pon_port.remove_tcont(tc.alloc_id, False)
598
599 gem_port = None
600 self.log.debug("gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
601 for gp in list(self.pon_port.gem_ports.values()):
602 if gp.gem_id == gem_port_id:
603 gem_port = gp
604 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
605
Girish Gowdrae933cd32019-11-21 21:04:41 +0530606 @inlineCallbacks
607 def success(_results):
608 if gem_port_id:
609 self.log.info("gem-port-delete-done-successfully")
610 if alloc_id:
611 self.log.info("tcont-delete-done-successfully")
612 # The deletion of TCONT marks the complete deletion of tech-profile
613 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800614 del self._tech_profile_download_done[uni_id][tp_table_id]
Girish Gowdrae933cd32019-11-21 21:04:41 +0530615 del self._tp_service_specific_task[uni_id][tp_path]
616 except Exception as ex:
617 self.log.error("del-tp-state-info", e=ex)
618
619 # TODO: There could be multiple TP on the UNI, and also the ONU.
620 # TODO: But the below reason updates for the whole device.
621 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
622
623 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530624 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530625 self.log.warn('tech-profile-delete-failure-retrying',
626 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500627 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
628 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500629 yield self.core_proxy.device_reason_update(self.device_id,
630 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530631
632 self.log.info('deleting-tech-profile-configuration')
633
Girish Gowdraa73ee452019-12-20 18:52:17 +0530634 if tcont is None and gem_port is None:
635 if alloc_id is not None:
636 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
637 if gem_port_id is not None:
638 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
639 return
640
Girish Gowdrae933cd32019-11-21 21:04:41 +0530641 self._tp_service_specific_task[uni_id][tp_path] = \
642 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
643 tcont=tcont, gem_port=gem_port)
644 self._deferred = \
645 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
646 self._deferred.addCallbacks(success, failure)
647 except Exception as e:
648 self.log.exception("failed-to-delete-tp",
649 e=e, uni_id=uni_id, tp_path=tp_path,
650 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500651
652 def update_pm_config(self, device, pm_config):
653 # TODO: This has not been tested
654 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500655 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500656
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800657 def remove_onu_flows(self, device, flows):
658 self.log.debug('remove_onu_flows', device_id=device.id)
659
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800660 # no point in removing omci flows if the device isnt reachable
661 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800662 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800663 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
664 admin=device.admin_state, connect=device.connect_status)
665 return
666
667 for flow in flows:
668 # if incoming flow contains cookie, then remove from ONU
669 if flow.cookie:
670 self.log.debug("remove-flow", device_id=device.id, flow=flow)
671
672 def is_downstream(port):
673 return port == self._pon_port_number
674
675 def is_upstream(port):
676 return not is_downstream(port)
677
678 try:
679 _in_port = fd.get_in_port(flow)
680 assert _in_port is not None
681
682 _out_port = fd.get_out_port(flow) # may be None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800683
684 if is_downstream(_in_port):
685 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
686 device_id=device.id)
687 # extended vlan tagging operation will handle it
688 continue
689 elif is_upstream(_in_port):
690 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
691 if fd.is_dhcp_flow(flow):
692 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
693 return
694
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800695 _vlan_vid = 0
696 # Retrieve the VLAN_VID that needs to be removed from the EVTO rule on the ONU.
697 for action in fd.get_actions(flow):
698 if action.type == fd.SET_FIELD:
699 _field = action.set_field.field.ofb_field
700 assert (action.set_field.field.oxm_class ==
701 OFPXMC_OPENFLOW_BASIC)
702 if _field.type == fd.VLAN_VID:
703 _vlan_vid = _field.vlan_vid & 0xfff
704 self.log.debug('vlan-vid-to-remove',
705 _vlan_vid=_vlan_vid, in_port=_in_port)
706
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800707 uni_port = self.uni_port(_in_port)
708 uni_id = _in_port & 0xF
709 else:
710 raise Exception('port should be 1 or 2 by our convention')
711
712 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
713
714 tp_id = self.get_tp_id_in_flow(flow)
715 # Deleting flow from ONU.
716 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800717 match_vlan=_vlan_vid, tp_id=tp_id)
718 # TODO:Delete TD task.
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800719 except Exception as e:
720 self.log.exception('failed-to-remove-flow', e=e)
721
722 def add_onu_flows(self, device, flows):
723 self.log.debug('function-entry', flows=flows)
724
725 #
726 # We need to proxy through the OLT to get to the ONU
727 # Configuration from here should be using OMCI
728 #
729 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
730
731 # no point in pushing omci flows if the device isnt reachable
732 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800733 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800734 self.log.warn("device-disabled-or-offline-skipping-flow-update",
735 admin=device.admin_state, connect=device.connect_status)
736 return
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800737
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800738 def is_downstream(port):
739 return port == self._pon_port_number
740
741 def is_upstream(port):
742 return not is_downstream(port)
743
744 for flow in flows:
745 # if incoming flow contains cookie, then add to ONU
746 if flow.cookie:
747 _type = None
748 _port = None
749 _vlan_vid = None
750 _udp_dst = None
751 _udp_src = None
752 _ipv4_dst = None
753 _ipv4_src = None
754 _metadata = None
755 _output = None
756 _push_tpid = None
757 _field = None
758 _set_vlan_vid = None
759 _set_vlan_pcp = 0
760 _tunnel_id = None
761 self.log.debug("add-flow", device_id=device.id, flow=flow)
762
763 try:
764 _in_port = fd.get_in_port(flow)
765 assert _in_port is not None
766
767 _out_port = fd.get_out_port(flow) # may be None
768 tp_id = self.get_tp_id_in_flow(flow)
769 if is_downstream(_in_port):
770 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
771 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
772 # uni_port = self.uni_port(_out_port)
773 # uni_id = _out_port & 0xF
774 continue
775 elif is_upstream(_in_port):
776 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
777 uni_port = self.uni_port(_in_port)
778 uni_id = _in_port & 0xF
779 else:
780 raise Exception('port should be 1 or 2 by our convention')
781
782 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
783
784 for field in fd.get_ofb_fields(flow):
785 if field.type == fd.ETH_TYPE:
786 _type = field.eth_type
787 self.log.debug('field-type-eth-type',
788 eth_type=_type)
789
790 elif field.type == fd.IP_PROTO:
791 _proto = field.ip_proto
792 self.log.debug('field-type-ip-proto',
793 ip_proto=_proto)
794
795 elif field.type == fd.IN_PORT:
796 _port = field.port
797 self.log.debug('field-type-in-port',
798 in_port=_port)
799 elif field.type == fd.TUNNEL_ID:
800 self.log.debug('field-type-tunnel-id')
801
802 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100803 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
804 _vlan_vid = RESERVED_TRANSPARENT_VLAN
805 else:
806 _vlan_vid = field.vlan_vid & 0xfff
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800807 self.log.debug('field-type-vlan-vid',
808 vlan=_vlan_vid)
809
810 elif field.type == fd.VLAN_PCP:
811 _vlan_pcp = field.vlan_pcp
812 self.log.debug('field-type-vlan-pcp',
813 pcp=_vlan_pcp)
814
815 elif field.type == fd.UDP_DST:
816 _udp_dst = field.udp_dst
817 self.log.debug('field-type-udp-dst',
818 udp_dst=_udp_dst)
819
820 elif field.type == fd.UDP_SRC:
821 _udp_src = field.udp_src
822 self.log.debug('field-type-udp-src',
823 udp_src=_udp_src)
824
825 elif field.type == fd.IPV4_DST:
826 _ipv4_dst = field.ipv4_dst
827 self.log.debug('field-type-ipv4-dst',
828 ipv4_dst=_ipv4_dst)
829
830 elif field.type == fd.IPV4_SRC:
831 _ipv4_src = field.ipv4_src
832 self.log.debug('field-type-ipv4-src',
833 ipv4_dst=_ipv4_src)
834
835 elif field.type == fd.METADATA:
836 _metadata = field.table_metadata
837 self.log.debug('field-type-metadata',
838 metadata=_metadata)
839
840 else:
841 raise NotImplementedError('field.type={}'.format(
842 field.type))
843
844 for action in fd.get_actions(flow):
845
846 if action.type == fd.OUTPUT:
847 _output = action.output.port
848 self.log.debug('action-type-output',
849 output=_output, in_port=_in_port)
850
851 elif action.type == fd.POP_VLAN:
852 self.log.debug('action-type-pop-vlan',
853 in_port=_in_port)
854
855 elif action.type == fd.PUSH_VLAN:
856 _push_tpid = action.push.ethertype
857 self.log.debug('action-type-push-vlan',
858 push_tpid=_push_tpid, in_port=_in_port)
859 if action.push.ethertype != 0x8100:
860 self.log.error('unhandled-tpid',
861 ethertype=action.push.ethertype)
862
863 elif action.type == fd.SET_FIELD:
864 _field = action.set_field.field.ofb_field
865 assert (action.set_field.field.oxm_class ==
866 OFPXMC_OPENFLOW_BASIC)
867 self.log.debug('action-type-set-field',
868 field=_field, in_port=_in_port)
869 if _field.type == fd.VLAN_VID:
870 _set_vlan_vid = _field.vlan_vid & 0xfff
871 self.log.debug('set-field-type-vlan-vid',
872 vlan_vid=_set_vlan_vid)
873 elif _field.type == fd.VLAN_PCP:
874 _set_vlan_pcp = _field.vlan_pcp
875 self.log.debug('set-field-type-vlan-pcp',
876 vlan_pcp=_set_vlan_pcp)
877 else:
878 self.log.error('unsupported-action-set-field-type',
879 field_type=_field.type)
880 else:
881 self.log.error('unsupported-action-type',
882 action_type=action.type, in_port=_in_port)
883
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100884 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
885 # supported match and action criteria cannot be handled by omci and must be ignored.
886 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
887 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
888 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
889 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800890 _set_vlan_vid=_vlan_vid,
891 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
892 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100893 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
894 _set_vlan_vid=_vlan_vid,
895 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
896 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800897 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100898 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
899 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800900 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
901 _set_vlan_vid=_set_vlan_vid,
902 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
903 tp_id=tp_id)
904
905 except Exception as e:
906 self.log.exception('failed-to-install-flow', e=e, flow=flow)
907
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500908 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
909 # flow decomposition that ultimately comes from onos
910 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700911 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500912
913 #
914 # We need to proxy through the OLT to get to the ONU
915 # Configuration from here should be using OMCI
916 #
917 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
918
919 # no point in pushing omci flows if the device isnt reachable
920 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530921 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500922 self.log.warn("device-disabled-or-offline-skipping-flow-update",
923 admin=device.admin_state, connect=device.connect_status)
924 return
925
926 def is_downstream(port):
927 return port == self._pon_port_number
928
929 def is_upstream(port):
930 return not is_downstream(port)
931
932 for flow in flows:
933 _type = None
934 _port = None
935 _vlan_vid = None
936 _udp_dst = None
937 _udp_src = None
938 _ipv4_dst = None
939 _ipv4_src = None
940 _metadata = None
941 _output = None
942 _push_tpid = None
943 _field = None
944 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800945 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400946 _tunnel_id = None
947
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500948 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530949 write_metadata = fd.get_write_metadata(flow)
950 if write_metadata is None:
951 self.log.error("do-not-process-flow-without-write-metadata")
952 return
953
954 # extract tp id from flow
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800955 tp_id = self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500956 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +0530957
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500958 _in_port = fd.get_in_port(flow)
959 assert _in_port is not None
960
961 _out_port = fd.get_out_port(flow) # may be None
962
963 if is_downstream(_in_port):
964 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
965 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530966 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500967 elif is_upstream(_in_port):
968 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
969 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400970 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500971 else:
972 raise Exception('port should be 1 or 2 by our convention')
973
974 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
975
976 for field in fd.get_ofb_fields(flow):
977 if field.type == fd.ETH_TYPE:
978 _type = field.eth_type
979 self.log.debug('field-type-eth-type',
980 eth_type=_type)
981
982 elif field.type == fd.IP_PROTO:
983 _proto = field.ip_proto
984 self.log.debug('field-type-ip-proto',
985 ip_proto=_proto)
986
987 elif field.type == fd.IN_PORT:
988 _port = field.port
989 self.log.debug('field-type-in-port',
990 in_port=_port)
991
992 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100993 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
994 _vlan_vid = RESERVED_TRANSPARENT_VLAN
995 else:
996 _vlan_vid = field.vlan_vid & 0xfff
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500997 self.log.debug('field-type-vlan-vid',
998 vlan=_vlan_vid)
999
1000 elif field.type == fd.VLAN_PCP:
1001 _vlan_pcp = field.vlan_pcp
1002 self.log.debug('field-type-vlan-pcp',
1003 pcp=_vlan_pcp)
1004
1005 elif field.type == fd.UDP_DST:
1006 _udp_dst = field.udp_dst
1007 self.log.debug('field-type-udp-dst',
1008 udp_dst=_udp_dst)
1009
1010 elif field.type == fd.UDP_SRC:
1011 _udp_src = field.udp_src
1012 self.log.debug('field-type-udp-src',
1013 udp_src=_udp_src)
1014
1015 elif field.type == fd.IPV4_DST:
1016 _ipv4_dst = field.ipv4_dst
1017 self.log.debug('field-type-ipv4-dst',
1018 ipv4_dst=_ipv4_dst)
1019
1020 elif field.type == fd.IPV4_SRC:
1021 _ipv4_src = field.ipv4_src
1022 self.log.debug('field-type-ipv4-src',
1023 ipv4_dst=_ipv4_src)
1024
1025 elif field.type == fd.METADATA:
1026 _metadata = field.table_metadata
1027 self.log.debug('field-type-metadata',
1028 metadata=_metadata)
1029
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001030 elif field.type == fd.TUNNEL_ID:
1031 _tunnel_id = field.tunnel_id
1032 self.log.debug('field-type-tunnel-id',
1033 tunnel_id=_tunnel_id)
1034
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001035
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001036 else:
1037 raise NotImplementedError('field.type={}'.format(
1038 field.type))
1039
1040 for action in fd.get_actions(flow):
1041
1042 if action.type == fd.OUTPUT:
1043 _output = action.output.port
1044 self.log.debug('action-type-output',
1045 output=_output, in_port=_in_port)
1046
1047 elif action.type == fd.POP_VLAN:
1048 self.log.debug('action-type-pop-vlan',
1049 in_port=_in_port)
1050
1051 elif action.type == fd.PUSH_VLAN:
1052 _push_tpid = action.push.ethertype
1053 self.log.debug('action-type-push-vlan',
1054 push_tpid=_push_tpid, in_port=_in_port)
1055 if action.push.ethertype != 0x8100:
1056 self.log.error('unhandled-tpid',
1057 ethertype=action.push.ethertype)
1058
1059 elif action.type == fd.SET_FIELD:
1060 _field = action.set_field.field.ofb_field
1061 assert (action.set_field.field.oxm_class ==
1062 OFPXMC_OPENFLOW_BASIC)
1063 self.log.debug('action-type-set-field',
1064 field=_field, in_port=_in_port)
1065 if _field.type == fd.VLAN_VID:
1066 _set_vlan_vid = _field.vlan_vid & 0xfff
1067 self.log.debug('set-field-type-vlan-vid',
1068 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001069 elif _field.type == fd.VLAN_PCP:
1070 _set_vlan_pcp = _field.vlan_pcp
1071 self.log.debug('set-field-type-vlan-pcp',
1072 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001073 else:
1074 self.log.error('unsupported-action-set-field-type',
1075 field_type=_field.type)
1076 else:
1077 self.log.error('unsupported-action-type',
1078 action_type=action.type, in_port=_in_port)
1079
Matt Jeanneret810148b2019-09-29 12:44:01 -04001080 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1081 # supported match and action criteria cannot be handled by omci and must be ignored.
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001082 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
1083 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
1084 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
1085 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001086 _set_vlan_vid=_vlan_vid,
1087 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1088 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001089 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1090 _set_vlan_vid=_vlan_vid,
1091 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1092 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001093 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001094 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
1095 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
1096 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1097 _set_vlan_vid=_set_vlan_vid,
1098 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1099 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001100 except Exception as e:
1101 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1102
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001103 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001104 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1105 self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1106 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001107 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001108 if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and \
1109 self._tech_profile_download_done[uni_id][tp_id] is True:
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001110 @inlineCallbacks
1111 def success(_results):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001112 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id,
1113 set_vlan_pcp=_set_vlan_pcp)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001114 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001115
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001116 @inlineCallbacks
1117 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301118 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 -08001119 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1120 reactor.callLater(retry,
1121 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1122 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1123 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001124 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001125
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001126 self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1127 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001128 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001129 match_vlan, _set_vlan_pcp, add_tag=True,
1130 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001131 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001132 self._deferred.addCallbacks(success, failure)
1133 else:
1134 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001135 uni_id=uni_id, tp_id=tp_id)
1136 if uni_id not in self._queued_vlan_filter_task:
1137 self._queued_vlan_filter_task[uni_id] = dict()
Mahir Gunyela982ec32020-02-25 12:30:37 -08001138 if tp_id not in self._queued_vlan_filter_task[uni_id]:
1139 self._queued_vlan_filter_task[uni_id][tp_id] = []
1140 self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001141 "uni_id": uni_id,
1142 "uni_port": uni_port,
1143 "match_vlan": match_vlan,
1144 "set_vlan_vid": _set_vlan_vid,
1145 "set_vlan_pcp": _set_vlan_pcp,
1146 "tp_id": tp_id})
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001147
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001148 def get_tp_id_in_flow(self, flow):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001149 flow_metadata = fd.get_metadata_from_write_metadata(flow)
1150 tp_id = fd.get_tp_id_from_metadata(flow_metadata)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001151 return tp_id
1152
1153 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001154 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001155 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001156
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001157 @inlineCallbacks
1158 def success(_results):
1159 self.log.info('vlan-untagging-success', _results=_results)
1160 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1161
1162 @inlineCallbacks
1163 def failure(_reason):
1164 self.log.warn('vlan-untagging-failure', _reason=_reason)
1165 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001166 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001167 reactor.callLater(retry,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001168 self._remove_vlan_filter_task, device, uni_id,
1169 add_tag=False, uni_port=uni_port)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001170
1171 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1172 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001173 match_vlan, _set_vlan_pcp, add_tag=False,
1174 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001175 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1176 self._deferred.addCallbacks(success, failure)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001177
Matt Jeannereta32441c2019-03-07 05:16:37 -05001178 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001179 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1180 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001181 try:
1182 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1183 omci_msg = InterAdapterOmciMessage()
1184 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001185 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001186
Matt Jeannereta32441c2019-03-07 05:16:37 -05001187 self.receive_message(omci_msg.message)
1188
1189 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1190 onu_indication = OnuIndication()
1191 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001192 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1193 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1194 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001195
1196 if onu_indication.oper_state == "up":
1197 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301198 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001199 self.update_interface(onu_indication)
1200 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001201 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1202 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001203
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001204 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1205 tech_msg = InterAdapterTechProfileDownloadMessage()
1206 request.body.Unpack(tech_msg)
1207 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1208
1209 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1210
Girish Gowdrae933cd32019-11-21 21:04:41 +05301211 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1212 del_gem_msg = InterAdapterDeleteGemPortMessage()
1213 request.body.Unpack(del_gem_msg)
1214 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1215
1216 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1217 gem_port_id=del_gem_msg.gem_port_id,
1218 tp_path=del_gem_msg.tp_path)
1219
1220 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1221 del_tcont_msg = InterAdapterDeleteTcontMessage()
1222 request.body.Unpack(del_tcont_msg)
1223 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1224
1225 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1226 alloc_id=del_tcont_msg.alloc_id,
1227 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001228 else:
1229 self.log.error("inter-adapter-unhandled-type", request=request)
1230
1231 except Exception as e:
1232 self.log.exception("error-processing-inter-adapter-message", e=e)
1233
1234 # Called each time there is an onu "up" indication from the olt handler
1235 @inlineCallbacks
1236 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001237 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001238 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001239
1240 # Ignore if onu_indication is received for an already running ONU
1241 if self._onu_omci_device is not None and self._onu_omci_device.active:
1242 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1243 return
1244
Matt Jeannereta32441c2019-03-07 05:16:37 -05001245 self._onu_indication = onu_indication
1246
Matt Jeanneretc083f462019-03-11 15:02:01 -04001247 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1248 connect_status=ConnectStatus.REACHABLE)
1249
Matt Jeannereta32441c2019-03-07 05:16:37 -05001250 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001251
1252 self.log.debug('starting-openomci-statemachine')
1253 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001254 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301255 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001256 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001257 self._heartbeat.enabled = True
1258
Matt Jeanneret42dad792020-02-01 09:28:27 -05001259 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001260 @inlineCallbacks
1261 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001262 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001263 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001264
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001265 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001266 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001267 reactor.callLater(0, self._onu_omci_device.stop)
1268
1269 # Let TP download happen again
1270 for uni_id in self._tp_service_specific_task:
1271 self._tp_service_specific_task[uni_id].clear()
1272 for uni_id in self._tech_profile_download_done:
1273 self._tech_profile_download_done[uni_id].clear()
1274
Matt Jeanneretf4113222019-08-14 19:44:34 -04001275 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001276 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1277 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1278 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001279 else:
1280 self.log.debug('not-changing-openomci-statemachine')
1281
Matt Jeanneretf4113222019-08-14 19:44:34 -04001282 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001283 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001284 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001285 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001286 yield self.disable_ports(lock_ports=True)
1287 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1288 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001289
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001290 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001291 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001292
William Kurkian3a206332019-04-29 11:05:47 -04001293 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001294 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001295 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001296 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001297 yield self.core_proxy.device_state_update(device.id,
1298 oper_status=OperStatus.ACTIVE,
1299 connect_status=ConnectStatus.REACHABLE)
1300 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1301 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001302 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001303 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001304
William Kurkian3a206332019-04-29 11:05:47 -04001305 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001306 def reboot(self):
1307 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001308 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001309 if device.connect_status != ConnectStatus.REACHABLE:
1310 self.log.error("device-unreachable")
1311 return
1312
William Kurkian3a206332019-04-29 11:05:47 -04001313 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001314 def success(_results):
1315 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001316 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001317
1318 def failure(_reason):
1319 self.log.info('reboot-failure', _reason=_reason)
1320
1321 self._deferred = self._onu_omci_device.reboot()
1322 self._deferred.addCallbacks(success, failure)
1323
William Kurkian3a206332019-04-29 11:05:47 -04001324 @inlineCallbacks
Matt Jeanneretf4113222019-08-14 19:44:34 -04001325 def disable_ports(self, lock_ports=True):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001326 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001327
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001328 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1329 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001330 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001331 if port.mac_bridge_port_num == 1:
1332 port.operstatus = OperStatus.UNKNOWN
1333 self.log.info('disable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001334 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1335 port.operstatus)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001336
1337 if lock_ports is True:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001338 self.lock_ports(lock=True)
1339
William Kurkian3a206332019-04-29 11:05:47 -04001340 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001341 def enable_ports(self):
1342 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001343
Matt Jeanneretf4113222019-08-14 19:44:34 -04001344 self.lock_ports(lock=False)
1345
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001346 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1347 # load on the core
1348 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001349 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001350 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001351 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001352 self.log.info('enable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001353 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1354 port.operstatus)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001355
1356 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1357 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1358 #
1359 # Basically the link state sequence:
1360 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1361 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1362 # 3) a link state up alarm is received for the uni plugged in.
1363 #
1364 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1365 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1366 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1367 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001368 @inlineCallbacks
1369 def port_state_handler(self, _topic, msg):
1370 self.log.info("port-state-change", _topic=_topic, msg=msg)
1371
1372 onu_id = msg['onu_id']
1373 port_no = msg['port_number']
1374 serial_number = msg['serial_number']
1375 port_status = msg['port_status']
1376 uni_port = self.uni_port(int(port_no))
1377
1378 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1379 port_status=port_status)
1380
1381 if port_status is True:
1382 uni_port.operstatus = OperStatus.ACTIVE
1383 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1384 else:
1385 uni_port.operstatus = OperStatus.UNKNOWN
1386 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1387
1388 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 -05001389 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001390
1391 # Called just before openomci state machine is started. These listen for events from selected state machines,
1392 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1393 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001394 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001395
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001396 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001397
1398 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001399 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1400 OnuDeviceEvents.MibDatabaseSyncEvent)
1401 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1402
1403 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001404 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1405 OnuDeviceEvents.OmciCapabilitiesEvent)
1406 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1407
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001408 # TODO: these alarms seem to be unreliable depending on the environment
1409 # 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 -08001410 # topic = OnuDeviceEntry.event_bus_topic(self.device_id,
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001411 # OnuDeviceEvents.PortEvent)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001412 # self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001413
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001414 # Called when the mib is in sync
1415 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001416 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001417 if self._in_sync_subscription is not None:
1418 try:
1419 in_sync = msg[IN_SYNC_KEY]
1420
1421 if in_sync:
1422 # Only call this once
1423 bus = self._onu_omci_device.event_bus
1424 bus.unsubscribe(self._in_sync_subscription)
1425 self._in_sync_subscription = None
1426
1427 # Start up device_info load
1428 self.log.debug('running-mib-sync')
1429 reactor.callLater(0, self._mib_in_sync)
1430
1431 except Exception as e:
1432 self.log.exception('in-sync', e=e)
1433
1434 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001435 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001436 if self._capabilities_subscription is not None:
1437 self.log.debug('capabilities-handler-done')
1438
1439 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1440 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1441 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001442 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001443 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001444 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001445
1446 omci = self._onu_omci_device
1447 in_sync = omci.mib_db_in_sync
1448
Matt Jeanneretc083f462019-03-11 15:02:01 -04001449 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001450 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001451
1452 if not self._dev_info_loaded:
1453 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1454
1455 omci_dev = self._onu_omci_device
1456 config = omci_dev.configuration
1457
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001458 try:
1459
1460 # sort the lists so we get consistent port ordering.
1461 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1462 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1463 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1464 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1465
1466 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001467 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001468 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001469 raise Exception("onu-missing-required-elements")
1470
1471 # Currently logging the ani, pptp, veip, and uni for information purposes.
1472 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1473 # And in some ONU the UNI-G list is incomplete or incorrect...
1474 for entity_id in ani_list:
1475 ani_value = config.ani_g_entities[entity_id]
1476 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1477 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1478 self._total_tcont_count = ani_value.get('total-tcont-count')
1479 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1480
1481 for entity_id in uni_list:
1482 uni_value = config.uni_g_entities[entity_id]
1483 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1484
1485 uni_entities = OrderedDict()
1486 for entity_id in pptp_list:
1487 pptp_value = config.pptp_entities[entity_id]
1488 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1489 uni_entities[entity_id] = UniType.PPTP
1490
1491 for entity_id in veip_list:
1492 veip_value = config.veip_entities[entity_id]
1493 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1494 uni_entities[entity_id] = UniType.VEIP
1495
1496 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001497 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001498 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001499 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001500 uni_id += 1
1501 except AssertionError as e:
1502 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1503
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001504 self._qos_flexibility = config.qos_configuration_flexibility or 0
1505 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1506
1507 if self._unis:
1508 self._dev_info_loaded = True
1509 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001510 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001511 self.log.warn("no-usable-unis")
1512 raise Exception("no-usable-unis")
1513
1514 except Exception as e:
1515 self.log.exception('device-info-load', e=e)
1516 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1517
1518 else:
1519 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1520
1521 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001522 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001523
1524 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001525 def success(_results):
1526 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001527 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301528 oper_status=OperStatus.ACTIVE,
1529 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001530 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001531 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001532 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001533 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001534
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001535 # Start collecting stats from the device after a brief pause
1536 if not self._pm_metrics_started:
1537 self._pm_metrics_started = True
1538 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1539 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1540
1541 # Start test requests after a brief pause
1542 if not self._test_request_started:
1543 self._test_request_started = True
1544 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1545 reactor.callLater(tststart, self._test_request.start_collector)
1546
Matt Jeanneretc083f462019-03-11 15:02:01 -04001547 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001548 def failure(_reason):
1549 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001550 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001551 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001552 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001553
Matt Jeanneretf4113222019-08-14 19:44:34 -04001554 # start by locking all the unis till mib sync and initial mib is downloaded
1555 # this way we can capture the port down/up events when we are ready
1556 self.lock_ports(lock=True)
1557
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001558 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1559 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1560 self.log.info('downloading-initial-mib-configuration')
1561 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1562 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1563 self._deferred.addCallbacks(success, failure)
1564 else:
1565 self.log.info('admin-down-disabling')
1566 self.disable(device)
1567 else:
1568 self.log.info('device-info-not-loaded-skipping-mib-download')
1569
Matt Jeanneretc083f462019-03-11 15:02:01 -04001570 @inlineCallbacks
1571 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001572 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001573
Matt Jeanneretc083f462019-03-11 15:02:01 -04001574 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 -05001575
1576 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1577 uni_name = "uni-{}".format(uni_no)
1578
Girish Gowdrae933cd32019-11-21 21:04:41 +05301579 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001580
1581 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 -04001582 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001583
1584 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1585 uni_port.entity_id = entity_id
1586 uni_port.enabled = True
1587 uni_port.mac_bridge_port_num = mac_bridge_port_num
1588
1589 self.log.debug("created-uni-port", uni=uni_port)
1590
Matt Jeanneretc083f462019-03-11 15:02:01 -04001591 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001592
1593 self._unis[uni_port.port_number] = uni_port
1594
1595 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301596 uni_ports=self.uni_ports,
1597 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001598
Matt Jeanneretc083f462019-03-11 15:02:01 -04001599 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1600 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001601 MAX_PONS_PER_OLT = 256
1602 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001603 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001604
Matt Jeanneretc083f462019-03-11 15:02:01 -04001605 assert intf_id < MAX_PONS_PER_OLT
1606 assert onu_id < MAX_ONUS_PER_PON
1607 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001608 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001609
1610 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001611 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001612 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001613 try:
1614 device = yield self.core_proxy.get_device(self.device_id)
1615 parent_device = yield self.core_proxy.get_device(self.parent_id)
1616 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001617 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001618
1619 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301620 pon_id=self._onu_indication.intf_id,
1621 onu_id=self._onu_indication.onu_id,
1622 registration_id=self.device_id,
1623 device_id=self.device_id,
1624 onu_serial_number=device.serial_number,
1625 olt_serial_number=olt_serial_number,
1626 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001627
Devmalya Paulffc89df2019-07-31 17:43:13 -04001628 self.log.debug("Trying-to-raise-onu-active-event")
1629 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001630 self._onu_indication.intf_id,
1631 device.serial_number,
1632 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301633 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001634 onu_id=self._onu_indication.onu_id).send(True)
1635 except Exception as active_event_error:
1636 self.log.exception('onu-activated-event-error',
1637 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001638
1639 def lock_ports(self, lock=True):
1640
1641 def success(response):
1642 self.log.debug('set-onu-ports-state', lock=lock, response=response)
1643
1644 def failure(response):
1645 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1646
1647 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1648 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1649 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001650
1651 def extract_tp_id_from_path(self, tp_path):
1652 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001653 tp_id = int(tp_path.split(_PATH_SEPERATOR)[1])
1654 return tp_id