blob: 94b555bf015741bf8146ac004f69b8834aafcbc2 [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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050026
27from collections import OrderedDict
28
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050029from twisted.internet import reactor
30from twisted.internet.defer import DeferredQueue, inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050031
32from heartbeat import HeartBeat
Devmalya Paulffc89df2019-07-31 17:43:13 -040033from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent
34from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
35from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
36from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050037
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050038import pyvoltha.common.openflow.utils as fd
39from pyvoltha.common.utils.registry import registry
Matteo Scandolod8d73172019-11-26 12:15:15 -070040from pyvoltha.adapters.common.frameio.frameio import hexify
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050041from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050042from pyvoltha.common.config.config_backend import ConsulStore
43from pyvoltha.common.config.config_backend import EtcdStore
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050044from voltha_protos.logical_device_pb2 import LogicalPort
William Kurkian8235c1e2019-03-05 12:58:28 -050045from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretc083f462019-03-11 15:02:01 -040046from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE, OFPPF_FIBER, OFPPF_1GB_FD
Matt Jeanneret3bfebff2019-04-12 18:25:03 -040047from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
Girish Gowdrae933cd32019-11-21 21:04:41 +053048 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
49 InterAdapterDeleteTcontMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050050from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050051from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
52from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050053 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050054from omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdrae933cd32019-11-21 21:04:41 +053055from omci.brcm_tp_setup_task import BrcmTpSetupTask
56from omci.brcm_tp_delete_task import BrcmTpDeleteTask
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050057from omci.brcm_uni_lock_task import BrcmUniLockTask
58from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050059from onu_gem_port import OnuGemPort
60from onu_tcont import OnuTCont
61from pon_port import PonPort
62from uni_port import UniPort, UniType
63from onu_traffic_descriptor import OnuTrafficDescriptor
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050064from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053065from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
66from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050067from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050068
69OP = EntityOperations
70RC = ReasonCodes
71
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050072_STARTUP_RETRY_WAIT = 20
73
74
75class BrcmOpenomciOnuHandler(object):
76
77 def __init__(self, adapter, device_id):
78 self.log = structlog.get_logger(device_id=device_id)
Matteo Scandolod8d73172019-11-26 12:15:15 -070079 self.log.debug('BrcmOpenomciOnuHandler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050080 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050081 self.core_proxy = adapter.core_proxy
82 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050083 self.parent_adapter = None
84 self.parent_id = None
85 self.device_id = device_id
86 self.incoming_messages = DeferredQueue()
87 self.event_messages = DeferredQueue()
88 self.proxy_address = None
89 self.tx_id = 0
90 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040091 self.events = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050092 self.pm_metrics = None
93 self._omcc_version = OMCCVersion.Unknown
94 self._total_tcont_count = 0 # From ANI-G ME
95 self._qos_flexibility = 0 # From ONT2_G ME
96
97 self._onu_indication = None
98 self._unis = dict() # Port # -> UniPort
99
100 self._pon = None
101 # TODO: probably shouldnt be hardcoded, determine from olt maybe?
102 self._pon_port_number = 100
103 self.logical_device_id = None
104
105 self._heartbeat = HeartBeat.create(self, device_id)
106
107 # Set up OpenOMCI environment
108 self._onu_omci_device = None
109 self._dev_info_loaded = False
110 self._deferred = None
111
112 self._in_sync_subscription = None
113 self._connectivity_subscription = None
114 self._capabilities_subscription = None
115
116 self.mac_bridge_service_profile_entity_id = 0x201
117 self.gal_enet_profile_entity_id = 0x1
118
119 self._tp_service_specific_task = dict()
120 self._tech_profile_download_done = dict()
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400121 # Stores information related to queued vlan filter tasks
122 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
123
124 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500125
126 # Initialize KV store client
127 self.args = registry('main').get_args()
128 if self.args.backend == 'etcd':
129 host, port = self.args.etcd.split(':', 1)
130 self.kv_client = EtcdStore(host, port,
131 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
132 elif self.args.backend == 'consul':
133 host, port = self.args.consul.split(':', 1)
134 self.kv_client = ConsulStore(host, port,
135 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
136 else:
137 self.log.error('Invalid-backend')
138 raise Exception("Invalid-backend-for-kv-store")
139
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500140 @property
141 def enabled(self):
142 return self._enabled
143
144 @enabled.setter
145 def enabled(self, value):
146 if self._enabled != value:
147 self._enabled = value
148
149 @property
150 def omci_agent(self):
151 return self.adapter.omci_agent
152
153 @property
154 def omci_cc(self):
155 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
156
157 @property
158 def heartbeat(self):
159 return self._heartbeat
160
161 @property
162 def uni_ports(self):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500163 return list(self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500164
165 def uni_port(self, port_no_or_name):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500166 if isinstance(port_no_or_name, six.string_types):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500167 return next((uni for uni in self.uni_ports
168 if uni.name == port_no_or_name), None)
169
170 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
171 return next((uni for uni in self.uni_ports
Girish Gowdrae933cd32019-11-21 21:04:41 +0530172 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500173
174 @property
175 def pon_port(self):
176 return self._pon
177
Girish Gowdraa73ee452019-12-20 18:52:17 +0530178 @property
179 def onu_omci_device(self):
180 return self._onu_omci_device
181
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500182 def receive_message(self, msg):
183 if self.omci_cc is not None:
184 self.omci_cc.receive_message(msg)
185
Matt Jeanneretc083f462019-03-11 15:02:01 -0400186 def get_ofp_port_info(self, device, port_no):
187 self.log.info('get_ofp_port_info', port_no=port_no, device_id=device.id)
188 cap = OFPPF_1GB_FD | OFPPF_FIBER
189
Girish Gowdrae933cd32019-11-21 21:04:41 +0530190 hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
191 ((device.parent_port_no >> 8 & 0xff),
192 device.parent_port_no & 0xff,
193 (port_no >> 16) & 0xff,
194 (port_no >> 8) & 0xff,
195 port_no & 0xff))
Matt Jeanneretc083f462019-03-11 15:02:01 -0400196
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400197 uni_port = self.uni_port(int(port_no))
198 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
199 self.log.debug('ofp_port_name', port_no=port_no, name=name)
200
Matt Jeanneretc083f462019-03-11 15:02:01 -0400201 return PortCapability(
202 port=LogicalPort(
203 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400204 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400205 hw_addr=hw_addr,
206 config=0,
207 state=OFPPS_LIVE,
208 curr=cap,
209 advertised=cap,
210 peer=cap,
211 curr_speed=OFPPF_1GB_FD,
212 max_speed=OFPPF_1GB_FD
213 ),
214 device_id=device.id,
215 device_port_no=port_no
216 )
217 )
218
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500219 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500220 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500221 def activate(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700222 self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500223
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500224 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500225 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500226 assert device.proxy_address.device_id
227
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500228 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500229 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500230 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500231 if self.enabled is not True:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700232 self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500233 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500234 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500235 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500236 device.reason = 'activating-onu'
237
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500238 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400239 # pm_metrics requires a logical device id. For now set to just device_id
240 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500241
Matt Jeannereta32441c2019-03-07 05:16:37 -0500242 yield self.core_proxy.device_update(device)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700243 self.log.debug('device updated', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500244
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700245 yield self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500246
Matteo Scandolod8d73172019-11-26 12:15:15 -0700247 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500248 ############################################################################
Devmalya Paulffc89df2019-07-31 17:43:13 -0400249 # Setup Alarm handler
250 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
251 device.serial_number)
252 ############################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500253 # Setup PM configuration for this device
254 # Pass in ONU specific options
255 kwargs = {
256 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
257 'heartbeat': self.heartbeat,
258 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
259 }
Matteo Scandolod8d73172019-11-26 12:15:15 -0700260 self.log.debug('create-OnuPmMetrics', device_id=device.id, serial_number=device.serial_number)
Devmalya Paulffc89df2019-07-31 17:43:13 -0400261 self.pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Yongjie Zhang8f891ad2019-07-03 15:32:38 -0400262 self.logical_device_id, device.serial_number,
263 grouped=True, freq_override=False, **kwargs)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500264 pm_config = self.pm_metrics.make_proto()
265 self._onu_omci_device.set_pm_config(self.pm_metrics.omci_pm.openomci_interval_pm)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530266 self.log.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500267 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500268
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500269 # Note, ONU ID and UNI intf set in add_uni_port method
Devmalya Paulffc89df2019-07-31 17:43:13 -0400270 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500271 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500272
Girish Gowdrae933cd32019-11-21 21:04:41 +0530273 # Start collecting stats from the device after a brief pause
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500274 reactor.callLater(10, self.pm_metrics.start_collector)
275
onkarkundargiaae99712019-09-23 15:02:52 +0530276 # Code to Run OMCI Test Action
277 kwargs_omci_test_action = {
278 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
279 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
280 }
281 serial_number = device.serial_number
282 test_request = OmciTestRequest(self.core_proxy,
283 self.omci_agent, self.device_id,
284 AniG, serial_number,
285 self.logical_device_id,
286 exclusive=False,
287 **kwargs_omci_test_action)
288 reactor.callLater(60, test_request.start_collector)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500289 self.enabled = True
290 else:
291 self.log.info('onu-already-activated')
292
293 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400294 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500295 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700296 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500297
298 # first we verify that we got parent reference and proxy info
299 assert device.parent_id
300 assert device.proxy_address.device_id
301
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700302 self.proxy_address = device.proxy_address
303 self.parent_id = device.parent_id
304 self._pon_port_number = device.parent_port_no
305
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500306 if self.enabled is not True:
307 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700308 self.logical_device_id = self.device_id
309 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500310
311 # need to restart state machines on vcore restart. there is no indication to do it for us.
312 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700313 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500314
315 # TODO: this is probably a bit heavy handed
316 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
317 # This may not be necessary when mib resync actually works
318 reactor.callLater(1, self.reboot)
319
320 self.enabled = True
321 else:
322 self.log.info('onu-already-activated')
323
324 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700325 def _init_pon_state(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700326 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 -0500327
328 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500329 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700330 self.log.debug('adding-pon-port-to-agent',
331 type=self._pon.get_port().type,
332 admin_state=self._pon.get_port().admin_state,
333 oper_status=self._pon.get_port().oper_status,
334 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500335
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700336 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500337
Matteo Scandolod8d73172019-11-26 12:15:15 -0700338 self.log.debug('added-pon-port-to-agent',
339 type=self._pon.get_port().type,
340 admin_state=self._pon.get_port().admin_state,
341 oper_status=self._pon.get_port().oper_status,
342 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500343
344 # Create and start the OpenOMCI ONU Device Entry for this ONU
345 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500346 self.core_proxy,
347 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500348 support_classes=self.adapter.broadcom_omci,
349 custom_me_map=self.adapter.custom_me_entities())
350 # Port startup
351 if self._pon is not None:
352 self._pon.enabled = True
353
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500354 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700355 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500356 if self.parent_adapter:
357 try:
358 self.parent_adapter.delete_child_device(self.parent_id, device)
359 except AttributeError:
360 self.log.debug('parent-device-delete-child-not-implemented')
361 else:
362 self.log.debug("parent-adapter-not-available")
363
364 def _create_tconts(self, uni_id, us_scheduler):
365 alloc_id = us_scheduler['alloc_id']
366 q_sched_policy = us_scheduler['q_sched_policy']
367 self.log.debug('create-tcont', us_scheduler=us_scheduler)
368
369 tcontdict = dict()
370 tcontdict['alloc-id'] = alloc_id
371 tcontdict['q_sched_policy'] = q_sched_policy
372 tcontdict['uni_id'] = uni_id
373
374 # TODO: Not sure what to do with any of this...
375 tddata = dict()
376 tddata['name'] = 'not-sure-td-profile'
377 tddata['fixed-bandwidth'] = "not-sure-fixed"
378 tddata['assured-bandwidth'] = "not-sure-assured"
379 tddata['maximum-bandwidth'] = "not-sure-max"
380 tddata['additional-bw-eligibility-indicator'] = "not-sure-additional"
381
382 td = OnuTrafficDescriptor.create(tddata)
383 tcont = OnuTCont.create(self, tcont=tcontdict, td=td)
384
385 self._pon.add_tcont(tcont)
386
387 self.log.debug('pon-add-tcont', tcont=tcont)
388
389 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
390 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
391 self.log.debug('create-gemport',
392 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530393 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500394 for gem_port in gem_ports:
395 gemdict = dict()
396 gemdict['gemport_id'] = gem_port['gemport_id']
397 gemdict['direction'] = direction
398 gemdict['alloc_id_ref'] = alloc_id_ref
399 gemdict['encryption'] = gem_port['aes_encryption']
400 gemdict['discard_config'] = dict()
401 gemdict['discard_config']['max_probability'] = \
402 gem_port['discard_config']['max_probability']
403 gemdict['discard_config']['max_threshold'] = \
404 gem_port['discard_config']['max_threshold']
405 gemdict['discard_config']['min_threshold'] = \
406 gem_port['discard_config']['min_threshold']
407 gemdict['discard_policy'] = gem_port['discard_policy']
408 gemdict['max_q_size'] = gem_port['max_q_size']
409 gemdict['pbit_map'] = gem_port['pbit_map']
410 gemdict['priority_q'] = gem_port['priority_q']
411 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
412 gemdict['weight'] = gem_port['weight']
413 gemdict['uni_id'] = uni_id
414
415 gem_port = OnuGemPort.create(self, gem_port=gemdict)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530416 new_gem_ports.append(gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500417
418 self._pon.add_gem_port(gem_port)
419
420 self.log.debug('pon-add-gemport', gem_port=gem_port)
421
Girish Gowdrae933cd32019-11-21 21:04:41 +0530422 return new_gem_ports
423
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400424 def _execute_queued_vlan_filter_tasks(self, uni_id):
425 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
426 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
427 # or initial-mib-download is not done. Once the tp_task is completed, we execute
428 # such queued vlan-filter tasks
429 try:
430 if uni_id in self._queued_vlan_filter_task:
431 self.log.info("executing-queued-vlan-filter-task",
432 uni_id=uni_id)
433 filter_info = self._queued_vlan_filter_task[uni_id]
434 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Girish Gowdraa73ee452019-12-20 18:52:17 +0530435 uni_id, filter_info.get("uni_port"), filter_info.get("set_vlan_vid"),
436 filter_info.get("tp_id"))
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400437 # Now remove the entry from the dictionary
438 self._queued_vlan_filter_task[uni_id].clear()
439 self.log.debug("executed-queued-vlan-filter-task",
440 uni_id=uni_id)
441 except Exception as e:
442 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
443
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500444 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500445 us_scheduler = tp['us_scheduler']
446 alloc_id = us_scheduler['alloc_id']
447 self._create_tconts(uni_id, us_scheduler)
448 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
449 self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
450 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
451 self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
452
453 def load_and_configure_tech_profile(self, uni_id, tp_path):
454 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
455
456 if uni_id not in self._tp_service_specific_task:
457 self._tp_service_specific_task[uni_id] = dict()
458
459 if uni_id not in self._tech_profile_download_done:
460 self._tech_profile_download_done[uni_id] = dict()
461
462 if tp_path not in self._tech_profile_download_done[uni_id]:
463 self._tech_profile_download_done[uni_id][tp_path] = False
464
465 if not self._tech_profile_download_done[uni_id][tp_path]:
466 try:
467 if tp_path in self._tp_service_specific_task[uni_id]:
468 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530469 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500470 return
471
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500472 tpstored = self.kv_client[tp_path]
473 tpstring = tpstored.decode('ascii')
474 tp = json.loads(tpstring)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530475
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500476 self.log.debug("tp-instance", tp=tp)
477 self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700478
William Kurkian3a206332019-04-29 11:05:47 -0400479 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500480 def success(_results):
481 self.log.info("tech-profile-config-done-successfully")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700482 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500483 if tp_path in self._tp_service_specific_task[uni_id]:
484 del self._tp_service_specific_task[uni_id][tp_path]
485 self._tech_profile_download_done[uni_id][tp_path] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400486 # Now execute any vlan filter tasks that were queued for later
487 self._execute_queued_vlan_filter_tasks(uni_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530488
William Kurkian3a206332019-04-29 11:05:47 -0400489 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500490 def failure(_reason):
491 self.log.warn('tech-profile-config-failure-retrying',
Girish Gowdrae933cd32019-11-21 21:04:41 +0530492 _reason=_reason)
493 yield self.core_proxy.device_reason_update(self.device_id,
494 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500495 if tp_path in self._tp_service_specific_task[uni_id]:
496 del self._tp_service_specific_task[uni_id][tp_path]
497 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
498 uni_id, tp_path)
499
500 self.log.info('downloading-tech-profile-configuration')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530501 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
502 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
503 # due to additional tasks on different UNIs. So, it we cannot use the pon_port after
504 # this initializer
505 tconts = []
506 for tcont in list(self.pon_port.tconts.values()):
507 if tcont.uni_id is not None and tcont.uni_id != uni_id:
508 continue
509 tconts.append(tcont)
510
511 gem_ports = []
512 for gem_port in list(self.pon_port.gem_ports.values()):
513 if gem_port.uni_id is not None and gem_port.uni_id != uni_id:
514 continue
515 gem_ports.append(gem_port)
516
517 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
518
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500519 self._tp_service_specific_task[uni_id][tp_path] = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530520 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, int(tp_path.split("/")[1]))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500521 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530522 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500523 self._deferred.addCallbacks(success, failure)
524
525 except Exception as e:
526 self.log.exception("error-loading-tech-profile", e=e)
527 else:
528 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530529 # Could be a case where TP exists but new gem-ports are getting added dynamically
530 tpstored = self.kv_client[tp_path]
531 tpstring = tpstored.decode('ascii')
532 tp = json.loads(tpstring)
533 upstream_gems = []
534 downstream_gems = []
535 # Find out the new Gem ports that are getting added afresh.
536 for gp in tp['upstream_gem_port_attribute_list']:
537 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
538 # gem port already exists
539 continue
540 upstream_gems.append(gp)
541 for gp in tp['downstream_gem_port_attribute_list']:
542 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
543 # gem port already exists
544 continue
545 downstream_gems.append(gp)
546
547 us_scheduler = tp['us_scheduler']
548 alloc_id = us_scheduler['alloc_id']
549
550 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
551 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
552 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
553 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
554 new_gems = []
555 new_gems.extend(new_upstream_gems)
556 new_gems.extend(new_downstream_gems)
557
558 def success(_results):
559 self.log.info("new-gem-ports-successfully-installed", result=_results)
560
561 def failure(_reason):
562 self.log.warn('new-gem-port-install-failed--retrying',
563 _reason=_reason)
564 # Remove gem ports from cache. We will re-add them during the retry
565 for gp in new_gems:
566 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
567
568 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
569 uni_id, tp_path)
570
571 self._tp_service_specific_task[uni_id][tp_path] = \
572 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, int(tp_path.split("/")[1]))
573 self._deferred = \
574 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
575 self._deferred.addCallbacks(success, failure)
576
577 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
578 try:
Naga Manjunathe433c712020-01-02 17:27:20 +0530579 if not uni_id in self._tech_profile_download_done:
580 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
581 return
582
583 if not tp_path in self._tech_profile_download_done[uni_id]:
584 self.log.warn("tp-path-is-not-present", tp_path=tp_path)
585 return
586
Girish Gowdrae933cd32019-11-21 21:04:41 +0530587 if self._tech_profile_download_done[uni_id][tp_path] is not True:
588 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete")
589 return
590
591 if alloc_id is None and gem_port_id is None:
592 self.log.error("alloc-id-and-gem-port-id-are-none")
593 return
594
595 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
596 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
597 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
598 # this initializer
599 tcont = None
600 self.log.debug("tconts", tconts=list(self.pon_port.tconts.values()))
601 for tc in list(self.pon_port.tconts.values()):
602 if tc.alloc_id == alloc_id:
603 tcont = tc
604 self.pon_port.remove_tcont(tc.alloc_id, False)
605
606 gem_port = None
607 self.log.debug("gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
608 for gp in list(self.pon_port.gem_ports.values()):
609 if gp.gem_id == gem_port_id:
610 gem_port = gp
611 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
612
613 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
614 # We need the TP Table ID
615 tp_table_id = int(tp_path.split("/")[1])
616
617 @inlineCallbacks
618 def success(_results):
619 if gem_port_id:
620 self.log.info("gem-port-delete-done-successfully")
621 if alloc_id:
622 self.log.info("tcont-delete-done-successfully")
623 # The deletion of TCONT marks the complete deletion of tech-profile
624 try:
625 del self._tech_profile_download_done[uni_id][tp_path]
626 del self._tp_service_specific_task[uni_id][tp_path]
627 except Exception as ex:
628 self.log.error("del-tp-state-info", e=ex)
629
630 # TODO: There could be multiple TP on the UNI, and also the ONU.
631 # TODO: But the below reason updates for the whole device.
632 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
633
634 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530635 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530636 self.log.warn('tech-profile-delete-failure-retrying',
637 _reason=_reason)
638 yield self.core_proxy.device_reason_update(self.device_id,
639 'tech-profile-config-delete-failure-retrying')
640 self._deferred = \
641 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
642 self._deferred.addCallbacks(success, failure)
643
644 self.log.info('deleting-tech-profile-configuration')
645
Girish Gowdraa73ee452019-12-20 18:52:17 +0530646 if tcont is None and gem_port is None:
647 if alloc_id is not None:
648 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
649 if gem_port_id is not None:
650 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
651 return
652
Girish Gowdrae933cd32019-11-21 21:04:41 +0530653 self._tp_service_specific_task[uni_id][tp_path] = \
654 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
655 tcont=tcont, gem_port=gem_port)
656 self._deferred = \
657 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
658 self._deferred.addCallbacks(success, failure)
659 except Exception as e:
660 self.log.exception("failed-to-delete-tp",
661 e=e, uni_id=uni_id, tp_path=tp_path,
662 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500663
664 def update_pm_config(self, device, pm_config):
665 # TODO: This has not been tested
666 self.log.info('update_pm_config', pm_config=pm_config)
667 self.pm_metrics.update(pm_config)
668
669 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
670 # flow decomposition that ultimately comes from onos
671 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700672 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500673
674 #
675 # We need to proxy through the OLT to get to the ONU
676 # Configuration from here should be using OMCI
677 #
678 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
679
680 # no point in pushing omci flows if the device isnt reachable
681 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530682 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500683 self.log.warn("device-disabled-or-offline-skipping-flow-update",
684 admin=device.admin_state, connect=device.connect_status)
685 return
686
687 def is_downstream(port):
688 return port == self._pon_port_number
689
690 def is_upstream(port):
691 return not is_downstream(port)
692
693 for flow in flows:
694 _type = None
695 _port = None
696 _vlan_vid = None
697 _udp_dst = None
698 _udp_src = None
699 _ipv4_dst = None
700 _ipv4_src = None
701 _metadata = None
702 _output = None
703 _push_tpid = None
704 _field = None
705 _set_vlan_vid = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400706 _tunnel_id = None
707
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500708 self.log.debug('bulk-flow-update', device_id=device.id, flow=flow)
709 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530710 write_metadata = fd.get_write_metadata(flow)
711 if write_metadata is None:
712 self.log.error("do-not-process-flow-without-write-metadata")
713 return
714
715 # extract tp id from flow
716 tp_id = (write_metadata >> 32) & 0xFFFF
717 self.log.info("tp-id-in-flow", tp_id=tp_id)
718
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500719 _in_port = fd.get_in_port(flow)
720 assert _in_port is not None
721
722 _out_port = fd.get_out_port(flow) # may be None
723
724 if is_downstream(_in_port):
725 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
726 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530727 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500728 elif is_upstream(_in_port):
729 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
730 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400731 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500732 else:
733 raise Exception('port should be 1 or 2 by our convention')
734
735 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
736
737 for field in fd.get_ofb_fields(flow):
738 if field.type == fd.ETH_TYPE:
739 _type = field.eth_type
740 self.log.debug('field-type-eth-type',
741 eth_type=_type)
742
743 elif field.type == fd.IP_PROTO:
744 _proto = field.ip_proto
745 self.log.debug('field-type-ip-proto',
746 ip_proto=_proto)
747
748 elif field.type == fd.IN_PORT:
749 _port = field.port
750 self.log.debug('field-type-in-port',
751 in_port=_port)
752
753 elif field.type == fd.VLAN_VID:
754 _vlan_vid = field.vlan_vid & 0xfff
755 self.log.debug('field-type-vlan-vid',
756 vlan=_vlan_vid)
757
758 elif field.type == fd.VLAN_PCP:
759 _vlan_pcp = field.vlan_pcp
760 self.log.debug('field-type-vlan-pcp',
761 pcp=_vlan_pcp)
762
763 elif field.type == fd.UDP_DST:
764 _udp_dst = field.udp_dst
765 self.log.debug('field-type-udp-dst',
766 udp_dst=_udp_dst)
767
768 elif field.type == fd.UDP_SRC:
769 _udp_src = field.udp_src
770 self.log.debug('field-type-udp-src',
771 udp_src=_udp_src)
772
773 elif field.type == fd.IPV4_DST:
774 _ipv4_dst = field.ipv4_dst
775 self.log.debug('field-type-ipv4-dst',
776 ipv4_dst=_ipv4_dst)
777
778 elif field.type == fd.IPV4_SRC:
779 _ipv4_src = field.ipv4_src
780 self.log.debug('field-type-ipv4-src',
781 ipv4_dst=_ipv4_src)
782
783 elif field.type == fd.METADATA:
784 _metadata = field.table_metadata
785 self.log.debug('field-type-metadata',
786 metadata=_metadata)
787
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400788 elif field.type == fd.TUNNEL_ID:
789 _tunnel_id = field.tunnel_id
790 self.log.debug('field-type-tunnel-id',
791 tunnel_id=_tunnel_id)
792
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500793 else:
794 raise NotImplementedError('field.type={}'.format(
795 field.type))
796
797 for action in fd.get_actions(flow):
798
799 if action.type == fd.OUTPUT:
800 _output = action.output.port
801 self.log.debug('action-type-output',
802 output=_output, in_port=_in_port)
803
804 elif action.type == fd.POP_VLAN:
805 self.log.debug('action-type-pop-vlan',
806 in_port=_in_port)
807
808 elif action.type == fd.PUSH_VLAN:
809 _push_tpid = action.push.ethertype
810 self.log.debug('action-type-push-vlan',
811 push_tpid=_push_tpid, in_port=_in_port)
812 if action.push.ethertype != 0x8100:
813 self.log.error('unhandled-tpid',
814 ethertype=action.push.ethertype)
815
816 elif action.type == fd.SET_FIELD:
817 _field = action.set_field.field.ofb_field
818 assert (action.set_field.field.oxm_class ==
819 OFPXMC_OPENFLOW_BASIC)
820 self.log.debug('action-type-set-field',
821 field=_field, in_port=_in_port)
822 if _field.type == fd.VLAN_VID:
823 _set_vlan_vid = _field.vlan_vid & 0xfff
824 self.log.debug('set-field-type-vlan-vid',
825 vlan_vid=_set_vlan_vid)
826 else:
827 self.log.error('unsupported-action-set-field-type',
828 field_type=_field.type)
829 else:
830 self.log.error('unsupported-action-type',
831 action_type=action.type, in_port=_in_port)
832
Matt Jeanneret810148b2019-09-29 12:44:01 -0400833 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
834 # supported match and action criteria cannot be handled by omci and must be ignored.
835 if _set_vlan_vid is None or _set_vlan_vid == 0:
836 self.log.warn('ignoring-flow-that-does-not-set-vlanid')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500837 else:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530838 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
839 self._add_vlan_filter_task(device, uni_id, uni_port, _set_vlan_vid, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500840 except Exception as e:
841 self.log.exception('failed-to-install-flow', e=e, flow=flow)
842
Girish Gowdraa73ee452019-12-20 18:52:17 +0530843 def _add_vlan_filter_task(self, device, uni_id, uni_port, _set_vlan_vid, tp_id):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500844 assert uni_port is not None
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400845 if uni_id in self._tech_profile_download_done and self._tech_profile_download_done[uni_id] != {}:
846 @inlineCallbacks
847 def success(_results):
Girish Gowdraa73ee452019-12-20 18:52:17 +0530848 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700849 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400850 self._vlan_filter_task = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500851
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400852 @inlineCallbacks
853 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +0530854 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700855 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400856 self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530857 self._add_vlan_filter_task, device, uni_port.port_number,
Girish Gowdraa73ee452019-12-20 18:52:17 +0530858 uni_port, _set_vlan_vid, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500859
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400860 self.log.info('setting-vlan-tag')
Girish Gowdraa73ee452019-12-20 18:52:17 +0530861 self._vlan_filter_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid, tp_id)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400862 self._deferred = self._onu_omci_device.task_runner.queue_task(self._vlan_filter_task)
863 self._deferred.addCallbacks(success, failure)
864 else:
865 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
866 uni_id=uni_id)
Matt Jeanneret810148b2019-09-29 12:44:01 -0400867 self._queued_vlan_filter_task[uni_id] = {"device": device,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530868 "uni_id": uni_id,
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400869 "uni_port": uni_port,
Girish Gowdraa73ee452019-12-20 18:52:17 +0530870 "set_vlan_vid": _set_vlan_vid,
871 "tp_id": tp_id}
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500872
873 def get_tx_id(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700874 self.log.debug('get-tx-id')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500875 self.tx_id += 1
876 return self.tx_id
877
Matt Jeannereta32441c2019-03-07 05:16:37 -0500878 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700879 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
880 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500881 try:
882 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
883 omci_msg = InterAdapterOmciMessage()
884 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700885 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500886
Matt Jeannereta32441c2019-03-07 05:16:37 -0500887 self.receive_message(omci_msg.message)
888
889 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
890 onu_indication = OnuIndication()
891 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700892 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
893 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
894 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500895
896 if onu_indication.oper_state == "up":
897 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530898 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -0500899 self.update_interface(onu_indication)
900 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700901 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
902 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500903
Matt Jeanneret3bfebff2019-04-12 18:25:03 -0400904 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
905 tech_msg = InterAdapterTechProfileDownloadMessage()
906 request.body.Unpack(tech_msg)
907 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
908
909 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
910
Girish Gowdrae933cd32019-11-21 21:04:41 +0530911 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
912 del_gem_msg = InterAdapterDeleteGemPortMessage()
913 request.body.Unpack(del_gem_msg)
914 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
915
916 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
917 gem_port_id=del_gem_msg.gem_port_id,
918 tp_path=del_gem_msg.tp_path)
919
920 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
921 del_tcont_msg = InterAdapterDeleteTcontMessage()
922 request.body.Unpack(del_tcont_msg)
923 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
924
925 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
926 alloc_id=del_tcont_msg.alloc_id,
927 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500928 else:
929 self.log.error("inter-adapter-unhandled-type", request=request)
930
931 except Exception as e:
932 self.log.exception("error-processing-inter-adapter-message", e=e)
933
934 # Called each time there is an onu "up" indication from the olt handler
935 @inlineCallbacks
936 def create_interface(self, onu_indication):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700937 self.log.debug('create-interface', onu_id=onu_indication.onu_id,
938 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500939 self._onu_indication = onu_indication
940
Matt Jeanneretc083f462019-03-11 15:02:01 -0400941 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
942 connect_status=ConnectStatus.REACHABLE)
943
Matt Jeannereta32441c2019-03-07 05:16:37 -0500944 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500945
946 self.log.debug('starting-openomci-statemachine')
947 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500948 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +0530949 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700950 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500951 self._heartbeat.enabled = True
952
953 # Currently called each time there is an onu "down" indication from the olt handler
954 # TODO: possibly other reasons to "update" from the olt?
Matt Jeannereta32441c2019-03-07 05:16:37 -0500955 @inlineCallbacks
956 def update_interface(self, onu_indication):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700957 self.log.debug('update-interface', onu_id=onu_indication.onu_id,
958 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500959
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -0400960 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500961 self.log.debug('stopping-openomci-statemachine')
962 reactor.callLater(0, self._onu_omci_device.stop)
963
964 # Let TP download happen again
965 for uni_id in self._tp_service_specific_task:
966 self._tp_service_specific_task[uni_id].clear()
967 for uni_id in self._tech_profile_download_done:
968 self._tech_profile_download_done[uni_id].clear()
969
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700970 self.disable_ports()
971 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
972 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
973 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500974 else:
975 self.log.debug('not-changing-openomci-statemachine')
976
977 # Not currently called by olt or anything else
William Kurkian3a206332019-04-29 11:05:47 -0400978 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500979 def remove_interface(self, data):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700980 self.log.debug('remove-interface', data=data)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500981
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500982 self.log.debug('stopping-openomci-statemachine')
983 reactor.callLater(0, self._onu_omci_device.stop)
984
985 # Let TP download happen again
986 for uni_id in self._tp_service_specific_task:
987 self._tp_service_specific_task[uni_id].clear()
988 for uni_id in self._tech_profile_download_done:
989 self._tech_profile_download_done[uni_id].clear()
990
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700991 self.disable_ports()
992 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500993
994 # TODO: im sure there is more to do here
995
996 # Not currently called. Would be called presumably from the olt handler
William Kurkian3a206332019-04-29 11:05:47 -0400997 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500998 def remove_gemport(self, data):
999 self.log.debug('remove-gemport', data=data)
William Kurkian3a206332019-04-29 11:05:47 -04001000 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001001 if device.connect_status != ConnectStatus.REACHABLE:
1002 self.log.error('device-unreachable')
1003 return
1004
1005 # Not currently called. Would be called presumably from the olt handler
William Kurkian3a206332019-04-29 11:05:47 -04001006 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001007 def remove_tcont(self, tcont_data, traffic_descriptor_data):
1008 self.log.debug('remove-tcont', tcont_data=tcont_data, traffic_descriptor_data=traffic_descriptor_data)
William Kurkian3a206332019-04-29 11:05:47 -04001009 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001010 if device.connect_status != ConnectStatus.REACHABLE:
1011 self.log.error('device-unreachable')
1012 return
1013
1014 # TODO: Create some omci task that encompases this what intended
1015
1016 # Not currently called. Would be called presumably from the olt handler
1017 def create_multicast_gemport(self, data):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001018 self.log.debug('create-multicast-gem-port', data=data)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001019
1020 # TODO: create objects and populate for later omci calls
1021
1022 def disable(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001023 self.log.debug('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001024 try:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001025 self.log.info('sending-uni-lock-towards-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001026
Matt Jeanneret80766692019-05-03 09:58:38 -04001027 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001028 def stop_anyway(reason):
1029 # proceed with disable regardless if we could reach the onu. for example onu is unplugged
1030 self.log.debug('stopping-openomci-statemachine')
1031 reactor.callLater(0, self._onu_omci_device.stop)
1032
Girish Gowdrae933cd32019-11-21 21:04:41 +05301033 # Note: The tech-profile states should not be cleared here.
1034 # They will be cleared if a DELETE_TCONT_REQ was triggered from openolt-adapter
1035 # as a result of all flow references for the TCONT being removed OR as a result
1036 # 'update_interface' call with oper_state as "down".
1037
1038 # for uni_id in self._tp_service_specific_task:
1039 # self._tp_service_specific_task[uni_id].clear()
1040 # for uni_id in self._tech_profile_download_done:
1041 # self._tech_profile_download_done[uni_id].clear()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001042
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001043 self.disable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001044 device.oper_status = OperStatus.UNKNOWN
1045 device.reason = "omci-admin-lock"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -04001046 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001047
1048 # lock all the unis
1049 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=True)
1050 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1051 self._deferred.addCallbacks(stop_anyway, stop_anyway)
1052 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001053 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001054
William Kurkian3a206332019-04-29 11:05:47 -04001055 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001056 def reenable(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001057 self.log.debug('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001058 try:
1059 # Start up OpenOMCI state machines for this device
1060 # this will ultimately resync mib and unlock unis on successful redownloading the mib
1061 self.log.debug('restarting-openomci-statemachine')
1062 self._subscribe_to_events()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001063 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
serkant.uluderya2cb65f72019-09-30 14:01:51 -07001064 reactor.callLater(1, self._onu_omci_device.start, device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001065 self._heartbeat.enabled = True
1066 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001067 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001068
William Kurkian3a206332019-04-29 11:05:47 -04001069 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001070 def reboot(self):
1071 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001072 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001073 if device.connect_status != ConnectStatus.REACHABLE:
1074 self.log.error("device-unreachable")
1075 return
1076
William Kurkian3a206332019-04-29 11:05:47 -04001077 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001078 def success(_results):
1079 self.log.info('reboot-success', _results=_results)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001080 self.disable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001081 device.connect_status = ConnectStatus.UNREACHABLE
1082 device.oper_status = OperStatus.DISCOVERED
1083 device.reason = "rebooting"
Matt Jeannereta8fd85f2019-05-01 12:16:45 -04001084 yield self.core_proxy.device_update(device)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001085
1086 def failure(_reason):
1087 self.log.info('reboot-failure', _reason=_reason)
1088
1089 self._deferred = self._onu_omci_device.reboot()
1090 self._deferred.addCallbacks(success, failure)
1091
William Kurkian3a206332019-04-29 11:05:47 -04001092 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001093 def disable_ports(self):
1094 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001095
1096 # Disable all ports on that device
Matt Jeanneret80766692019-05-03 09:58:38 -04001097 yield self.core_proxy.ports_state_update(self.device_id, OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001098
William Kurkian3a206332019-04-29 11:05:47 -04001099 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001100 def enable_ports(self):
1101 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001102
Matt Jeanneret80766692019-05-03 09:58:38 -04001103 # Enable all ports on that device
1104 yield self.core_proxy.ports_state_update(self.device_id, OperStatus.ACTIVE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001105
1106 # Called just before openomci state machine is started. These listen for events from selected state machines,
1107 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1108 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001109 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001110
1111 # OMCI MIB Database sync status
1112 bus = self._onu_omci_device.event_bus
1113 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1114 OnuDeviceEvents.MibDatabaseSyncEvent)
1115 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1116
1117 # OMCI Capabilities
1118 bus = self._onu_omci_device.event_bus
1119 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1120 OnuDeviceEvents.OmciCapabilitiesEvent)
1121 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1122
1123 # Called when the mib is in sync
1124 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001125 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001126 if self._in_sync_subscription is not None:
1127 try:
1128 in_sync = msg[IN_SYNC_KEY]
1129
1130 if in_sync:
1131 # Only call this once
1132 bus = self._onu_omci_device.event_bus
1133 bus.unsubscribe(self._in_sync_subscription)
1134 self._in_sync_subscription = None
1135
1136 # Start up device_info load
1137 self.log.debug('running-mib-sync')
1138 reactor.callLater(0, self._mib_in_sync)
1139
1140 except Exception as e:
1141 self.log.exception('in-sync', e=e)
1142
1143 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001144 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001145 if self._capabilities_subscription is not None:
1146 self.log.debug('capabilities-handler-done')
1147
1148 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1149 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1150 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001151 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001152 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001153 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001154
1155 omci = self._onu_omci_device
1156 in_sync = omci.mib_db_in_sync
1157
Matt Jeanneretc083f462019-03-11 15:02:01 -04001158 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001159 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001160
1161 if not self._dev_info_loaded:
1162 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1163
1164 omci_dev = self._onu_omci_device
1165 config = omci_dev.configuration
1166
1167 # TODO: run this sooner somehow. shouldnt have to wait for mib sync to push an initial download
1168 # In Sync, we can register logical ports now. Ideally this could occur on
1169 # the first time we received a successful (no timeout) OMCI Rx response.
1170 try:
1171
1172 # sort the lists so we get consistent port ordering.
1173 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1174 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1175 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1176 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1177
1178 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001179 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001180 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001181 raise Exception("onu-missing-required-elements")
1182
1183 # Currently logging the ani, pptp, veip, and uni for information purposes.
1184 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1185 # And in some ONU the UNI-G list is incomplete or incorrect...
1186 for entity_id in ani_list:
1187 ani_value = config.ani_g_entities[entity_id]
1188 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1189 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1190 self._total_tcont_count = ani_value.get('total-tcont-count')
1191 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1192
1193 for entity_id in uni_list:
1194 uni_value = config.uni_g_entities[entity_id]
1195 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1196
1197 uni_entities = OrderedDict()
1198 for entity_id in pptp_list:
1199 pptp_value = config.pptp_entities[entity_id]
1200 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1201 uni_entities[entity_id] = UniType.PPTP
1202
1203 for entity_id in veip_list:
1204 veip_value = config.veip_entities[entity_id]
1205 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1206 uni_entities[entity_id] = UniType.VEIP
1207
1208 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001209 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001210 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001211 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001212 uni_id += 1
1213 except AssertionError as e:
1214 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1215
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001216 self._qos_flexibility = config.qos_configuration_flexibility or 0
1217 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1218
1219 if self._unis:
1220 self._dev_info_loaded = True
1221 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001222 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001223 self.log.warn("no-usable-unis")
1224 raise Exception("no-usable-unis")
1225
1226 except Exception as e:
1227 self.log.exception('device-info-load', e=e)
1228 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1229
1230 else:
1231 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1232
1233 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001234 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001235
1236 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001237 def success(_results):
1238 self.log.info('mib-download-success', _results=_results)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001239 yield self.enable_ports()
Matt Jeanneretc083f462019-03-11 15:02:01 -04001240 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301241 oper_status=OperStatus.ACTIVE,
1242 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001243 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001244 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001245 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001246
Matt Jeanneretc083f462019-03-11 15:02:01 -04001247 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001248 def failure(_reason):
1249 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001250 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001251 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1252
1253 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1254 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1255 self.log.info('downloading-initial-mib-configuration')
1256 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1257 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1258 self._deferred.addCallbacks(success, failure)
1259 else:
1260 self.log.info('admin-down-disabling')
1261 self.disable(device)
1262 else:
1263 self.log.info('device-info-not-loaded-skipping-mib-download')
1264
Matt Jeanneretc083f462019-03-11 15:02:01 -04001265 @inlineCallbacks
1266 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001267 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001268
Matt Jeanneretc083f462019-03-11 15:02:01 -04001269 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 -05001270
1271 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1272 uni_name = "uni-{}".format(uni_no)
1273
Girish Gowdrae933cd32019-11-21 21:04:41 +05301274 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001275
1276 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 -04001277 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001278
1279 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1280 uni_port.entity_id = entity_id
1281 uni_port.enabled = True
1282 uni_port.mac_bridge_port_num = mac_bridge_port_num
1283
1284 self.log.debug("created-uni-port", uni=uni_port)
1285
Matt Jeanneretc083f462019-03-11 15:02:01 -04001286 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001287
1288 self._unis[uni_port.port_number] = uni_port
1289
1290 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301291 uni_ports=self.uni_ports,
1292 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001293
Matt Jeanneretc083f462019-03-11 15:02:01 -04001294 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1295 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001296 MAX_PONS_PER_OLT = 256
1297 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001298 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001299
Matt Jeanneretc083f462019-03-11 15:02:01 -04001300 assert intf_id < MAX_PONS_PER_OLT
1301 assert onu_id < MAX_ONUS_PER_PON
1302 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001303 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001304
1305 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001306 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001307 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001308 try:
1309 device = yield self.core_proxy.get_device(self.device_id)
1310 parent_device = yield self.core_proxy.get_device(self.parent_id)
1311 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001312 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001313
1314 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301315 pon_id=self._onu_indication.intf_id,
1316 onu_id=self._onu_indication.onu_id,
1317 registration_id=self.device_id,
1318 device_id=self.device_id,
1319 onu_serial_number=device.serial_number,
1320 olt_serial_number=olt_serial_number,
1321 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001322
Devmalya Paulffc89df2019-07-31 17:43:13 -04001323 self.log.debug("Trying-to-raise-onu-active-event")
1324 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001325 self._onu_indication.intf_id,
1326 device.serial_number,
1327 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301328 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001329 onu_id=self._onu_indication.onu_id).send(True)
1330 except Exception as active_event_error:
1331 self.log.exception('onu-activated-event-error',
1332 errmsg=active_event_error.message)