blob: f05b293c8225dc2e70f850d8277f5b73d416a772 [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 Jeanneretf4113222019-08-14 19:44:34 -040046from voltha_protos.device_pb2 import Port
47from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE,OFPPS_LINK_DOWN,\
48 OFPPF_FIBER, OFPPF_1GB_FD
Matt Jeanneret3bfebff2019-04-12 18:25:03 -040049from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
Girish Gowdrae933cd32019-11-21 21:04:41 +053050 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
51 InterAdapterDeleteTcontMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050052from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050053from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
54from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050055 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050056from omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdrae933cd32019-11-21 21:04:41 +053057from omci.brcm_tp_setup_task import BrcmTpSetupTask
58from omci.brcm_tp_delete_task import BrcmTpDeleteTask
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050059from omci.brcm_uni_lock_task import BrcmUniLockTask
60from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050061from onu_gem_port import OnuGemPort
62from onu_tcont import OnuTCont
63from pon_port import PonPort
64from uni_port import UniPort, UniType
65from onu_traffic_descriptor import OnuTrafficDescriptor
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050066from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053067from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
68from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050069from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050070
71OP = EntityOperations
72RC = ReasonCodes
73
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050074_STARTUP_RETRY_WAIT = 20
75
76
77class BrcmOpenomciOnuHandler(object):
78
79 def __init__(self, adapter, device_id):
80 self.log = structlog.get_logger(device_id=device_id)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050081 self.log.debug('starting-handler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050082 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050083 self.core_proxy = adapter.core_proxy
84 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050085 self.parent_adapter = None
86 self.parent_id = None
87 self.device_id = device_id
88 self.incoming_messages = DeferredQueue()
89 self.event_messages = DeferredQueue()
90 self.proxy_address = None
91 self.tx_id = 0
92 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040093 self.events = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050094 self.pm_metrics = None
95 self._omcc_version = OMCCVersion.Unknown
96 self._total_tcont_count = 0 # From ANI-G ME
97 self._qos_flexibility = 0 # From ONT2_G ME
98
99 self._onu_indication = None
100 self._unis = dict() # Port # -> UniPort
101
102 self._pon = None
103 # TODO: probably shouldnt be hardcoded, determine from olt maybe?
104 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)
Devmalya Paulffc89df2019-07-31 17:43:13 -0400268 self.pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Yongjie Zhang8f891ad2019-07-03 15:32:38 -0400269 self.logical_device_id, device.serial_number,
270 grouped=True, freq_override=False, **kwargs)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -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
Girish Gowdrae933cd32019-11-21 21:04:41 +0530280 # Start collecting stats from the device after a brief pause
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500281 reactor.callLater(10, self.pm_metrics.start_collector)
282
onkarkundargiaae99712019-09-23 15:02:52 +0530283 # Code to Run OMCI Test Action
284 kwargs_omci_test_action = {
285 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
286 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
287 }
288 serial_number = device.serial_number
289 test_request = OmciTestRequest(self.core_proxy,
290 self.omci_agent, self.device_id,
291 AniG, serial_number,
292 self.logical_device_id,
293 exclusive=False,
294 **kwargs_omci_test_action)
295 reactor.callLater(60, test_request.start_collector)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500296 self.enabled = True
297 else:
298 self.log.info('onu-already-activated')
299
300 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400301 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500302 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700303 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500304
305 # first we verify that we got parent reference and proxy info
306 assert device.parent_id
307 assert device.proxy_address.device_id
308
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700309 self.proxy_address = device.proxy_address
310 self.parent_id = device.parent_id
311 self._pon_port_number = device.parent_port_no
312
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500313 if self.enabled is not True:
314 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700315 self.logical_device_id = self.device_id
316 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500317
318 # need to restart state machines on vcore restart. there is no indication to do it for us.
319 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700320 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500321
322 # TODO: this is probably a bit heavy handed
323 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
324 # This may not be necessary when mib resync actually works
325 reactor.callLater(1, self.reboot)
326
327 self.enabled = True
328 else:
329 self.log.info('onu-already-activated')
330
331 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700332 def _init_pon_state(self):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500333 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 -0500334
335 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500336 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700337 self.log.debug('adding-pon-port-to-agent',
338 type=self._pon.get_port().type,
339 admin_state=self._pon.get_port().admin_state,
340 oper_status=self._pon.get_port().oper_status,
341 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500342
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700343 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500344
Matteo Scandolod8d73172019-11-26 12:15:15 -0700345 self.log.debug('added-pon-port-to-agent',
346 type=self._pon.get_port().type,
347 admin_state=self._pon.get_port().admin_state,
348 oper_status=self._pon.get_port().oper_status,
349 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500350
351 # Create and start the OpenOMCI ONU Device Entry for this ONU
352 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500353 self.core_proxy,
354 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500355 support_classes=self.adapter.broadcom_omci,
356 custom_me_map=self.adapter.custom_me_entities())
357 # Port startup
358 if self._pon is not None:
359 self._pon.enabled = True
360
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500361 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700362 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500363 if self.parent_adapter:
364 try:
365 self.parent_adapter.delete_child_device(self.parent_id, device)
366 except AttributeError:
367 self.log.debug('parent-device-delete-child-not-implemented')
368 else:
369 self.log.debug("parent-adapter-not-available")
370
371 def _create_tconts(self, uni_id, us_scheduler):
372 alloc_id = us_scheduler['alloc_id']
373 q_sched_policy = us_scheduler['q_sched_policy']
374 self.log.debug('create-tcont', us_scheduler=us_scheduler)
375
376 tcontdict = dict()
377 tcontdict['alloc-id'] = alloc_id
378 tcontdict['q_sched_policy'] = q_sched_policy
379 tcontdict['uni_id'] = uni_id
380
381 # TODO: Not sure what to do with any of this...
382 tddata = dict()
383 tddata['name'] = 'not-sure-td-profile'
384 tddata['fixed-bandwidth'] = "not-sure-fixed"
385 tddata['assured-bandwidth'] = "not-sure-assured"
386 tddata['maximum-bandwidth'] = "not-sure-max"
387 tddata['additional-bw-eligibility-indicator'] = "not-sure-additional"
388
389 td = OnuTrafficDescriptor.create(tddata)
390 tcont = OnuTCont.create(self, tcont=tcontdict, td=td)
391
392 self._pon.add_tcont(tcont)
393
394 self.log.debug('pon-add-tcont', tcont=tcont)
395
396 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
397 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
398 self.log.debug('create-gemport',
399 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530400 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500401 for gem_port in gem_ports:
402 gemdict = dict()
403 gemdict['gemport_id'] = gem_port['gemport_id']
404 gemdict['direction'] = direction
405 gemdict['alloc_id_ref'] = alloc_id_ref
406 gemdict['encryption'] = gem_port['aes_encryption']
407 gemdict['discard_config'] = dict()
408 gemdict['discard_config']['max_probability'] = \
409 gem_port['discard_config']['max_probability']
410 gemdict['discard_config']['max_threshold'] = \
411 gem_port['discard_config']['max_threshold']
412 gemdict['discard_config']['min_threshold'] = \
413 gem_port['discard_config']['min_threshold']
414 gemdict['discard_policy'] = gem_port['discard_policy']
415 gemdict['max_q_size'] = gem_port['max_q_size']
416 gemdict['pbit_map'] = gem_port['pbit_map']
417 gemdict['priority_q'] = gem_port['priority_q']
418 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
419 gemdict['weight'] = gem_port['weight']
420 gemdict['uni_id'] = uni_id
421
422 gem_port = OnuGemPort.create(self, gem_port=gemdict)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530423 new_gem_ports.append(gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500424
425 self._pon.add_gem_port(gem_port)
426
427 self.log.debug('pon-add-gemport', gem_port=gem_port)
428
Girish Gowdrae933cd32019-11-21 21:04:41 +0530429 return new_gem_ports
430
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400431 def _execute_queued_vlan_filter_tasks(self, uni_id):
432 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
433 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
434 # or initial-mib-download is not done. Once the tp_task is completed, we execute
435 # such queued vlan-filter tasks
436 try:
437 if uni_id in self._queued_vlan_filter_task:
438 self.log.info("executing-queued-vlan-filter-task",
439 uni_id=uni_id)
440 filter_info = self._queued_vlan_filter_task[uni_id]
441 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Girish Gowdraa73ee452019-12-20 18:52:17 +0530442 uni_id, filter_info.get("uni_port"), filter_info.get("set_vlan_vid"),
443 filter_info.get("tp_id"))
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400444 # Now remove the entry from the dictionary
445 self._queued_vlan_filter_task[uni_id].clear()
446 self.log.debug("executed-queued-vlan-filter-task",
447 uni_id=uni_id)
448 except Exception as e:
449 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
450
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500451 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500452 us_scheduler = tp['us_scheduler']
453 alloc_id = us_scheduler['alloc_id']
454 self._create_tconts(uni_id, us_scheduler)
455 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
456 self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
457 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
458 self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
459
460 def load_and_configure_tech_profile(self, uni_id, tp_path):
461 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
462
463 if uni_id not in self._tp_service_specific_task:
464 self._tp_service_specific_task[uni_id] = dict()
465
466 if uni_id not in self._tech_profile_download_done:
467 self._tech_profile_download_done[uni_id] = dict()
468
469 if tp_path not in self._tech_profile_download_done[uni_id]:
470 self._tech_profile_download_done[uni_id][tp_path] = False
471
472 if not self._tech_profile_download_done[uni_id][tp_path]:
473 try:
474 if tp_path in self._tp_service_specific_task[uni_id]:
475 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530476 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500477 return
478
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500479 tpstored = self.kv_client[tp_path]
480 tpstring = tpstored.decode('ascii')
481 tp = json.loads(tpstring)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530482
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500483 self.log.debug("tp-instance", tp=tp)
484 self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700485
William Kurkian3a206332019-04-29 11:05:47 -0400486 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500487 def success(_results):
488 self.log.info("tech-profile-config-done-successfully")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700489 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500490 if tp_path in self._tp_service_specific_task[uni_id]:
491 del self._tp_service_specific_task[uni_id][tp_path]
492 self._tech_profile_download_done[uni_id][tp_path] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400493 # Now execute any vlan filter tasks that were queued for later
494 self._execute_queued_vlan_filter_tasks(uni_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530495
William Kurkian3a206332019-04-29 11:05:47 -0400496 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500497 def failure(_reason):
498 self.log.warn('tech-profile-config-failure-retrying',
Girish Gowdrae933cd32019-11-21 21:04:41 +0530499 _reason=_reason)
500 yield self.core_proxy.device_reason_update(self.device_id,
501 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500502 if tp_path in self._tp_service_specific_task[uni_id]:
503 del self._tp_service_specific_task[uni_id][tp_path]
504 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
505 uni_id, tp_path)
506
507 self.log.info('downloading-tech-profile-configuration')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530508 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
509 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
510 # due to additional tasks on different UNIs. So, it we cannot use the pon_port after
511 # this initializer
512 tconts = []
513 for tcont in list(self.pon_port.tconts.values()):
514 if tcont.uni_id is not None and tcont.uni_id != uni_id:
515 continue
516 tconts.append(tcont)
517
518 gem_ports = []
519 for gem_port in list(self.pon_port.gem_ports.values()):
520 if gem_port.uni_id is not None and gem_port.uni_id != uni_id:
521 continue
522 gem_ports.append(gem_port)
523
524 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
525
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500526 self._tp_service_specific_task[uni_id][tp_path] = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530527 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, int(tp_path.split("/")[1]))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500528 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530529 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500530 self._deferred.addCallbacks(success, failure)
531
532 except Exception as e:
533 self.log.exception("error-loading-tech-profile", e=e)
534 else:
535 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530536 # Could be a case where TP exists but new gem-ports are getting added dynamically
537 tpstored = self.kv_client[tp_path]
538 tpstring = tpstored.decode('ascii')
539 tp = json.loads(tpstring)
540 upstream_gems = []
541 downstream_gems = []
542 # Find out the new Gem ports that are getting added afresh.
543 for gp in tp['upstream_gem_port_attribute_list']:
544 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
545 # gem port already exists
546 continue
547 upstream_gems.append(gp)
548 for gp in tp['downstream_gem_port_attribute_list']:
549 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
550 # gem port already exists
551 continue
552 downstream_gems.append(gp)
553
554 us_scheduler = tp['us_scheduler']
555 alloc_id = us_scheduler['alloc_id']
556
557 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
558 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
559 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
560 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
561 new_gems = []
562 new_gems.extend(new_upstream_gems)
563 new_gems.extend(new_downstream_gems)
564
565 def success(_results):
566 self.log.info("new-gem-ports-successfully-installed", result=_results)
567
568 def failure(_reason):
569 self.log.warn('new-gem-port-install-failed--retrying',
570 _reason=_reason)
571 # Remove gem ports from cache. We will re-add them during the retry
572 for gp in new_gems:
573 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
574
575 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
576 uni_id, tp_path)
577
578 self._tp_service_specific_task[uni_id][tp_path] = \
579 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, int(tp_path.split("/")[1]))
580 self._deferred = \
581 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
582 self._deferred.addCallbacks(success, failure)
583
584 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
585 try:
Naga Manjunathe433c712020-01-02 17:27:20 +0530586 if not uni_id in self._tech_profile_download_done:
587 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
588 return
589
590 if not tp_path in self._tech_profile_download_done[uni_id]:
591 self.log.warn("tp-path-is-not-present", tp_path=tp_path)
592 return
593
Girish Gowdrae933cd32019-11-21 21:04:41 +0530594 if self._tech_profile_download_done[uni_id][tp_path] is not True:
595 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete")
596 return
597
598 if alloc_id is None and gem_port_id is None:
599 self.log.error("alloc-id-and-gem-port-id-are-none")
600 return
601
602 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
603 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
604 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
605 # this initializer
606 tcont = None
607 self.log.debug("tconts", tconts=list(self.pon_port.tconts.values()))
608 for tc in list(self.pon_port.tconts.values()):
609 if tc.alloc_id == alloc_id:
610 tcont = tc
611 self.pon_port.remove_tcont(tc.alloc_id, False)
612
613 gem_port = None
614 self.log.debug("gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
615 for gp in list(self.pon_port.gem_ports.values()):
616 if gp.gem_id == gem_port_id:
617 gem_port = gp
618 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
619
620 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
621 # We need the TP Table ID
622 tp_table_id = int(tp_path.split("/")[1])
623
624 @inlineCallbacks
625 def success(_results):
626 if gem_port_id:
627 self.log.info("gem-port-delete-done-successfully")
628 if alloc_id:
629 self.log.info("tcont-delete-done-successfully")
630 # The deletion of TCONT marks the complete deletion of tech-profile
631 try:
632 del self._tech_profile_download_done[uni_id][tp_path]
633 del self._tp_service_specific_task[uni_id][tp_path]
634 except Exception as ex:
635 self.log.error("del-tp-state-info", e=ex)
636
637 # TODO: There could be multiple TP on the UNI, and also the ONU.
638 # TODO: But the below reason updates for the whole device.
639 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
640
641 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530642 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530643 self.log.warn('tech-profile-delete-failure-retrying',
644 _reason=_reason)
645 yield self.core_proxy.device_reason_update(self.device_id,
646 'tech-profile-config-delete-failure-retrying')
647 self._deferred = \
648 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
649 self._deferred.addCallbacks(success, failure)
650
651 self.log.info('deleting-tech-profile-configuration')
652
Girish Gowdraa73ee452019-12-20 18:52:17 +0530653 if tcont is None and gem_port is None:
654 if alloc_id is not None:
655 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
656 if gem_port_id is not None:
657 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
658 return
659
Girish Gowdrae933cd32019-11-21 21:04:41 +0530660 self._tp_service_specific_task[uni_id][tp_path] = \
661 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
662 tcont=tcont, gem_port=gem_port)
663 self._deferred = \
664 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
665 self._deferred.addCallbacks(success, failure)
666 except Exception as e:
667 self.log.exception("failed-to-delete-tp",
668 e=e, uni_id=uni_id, tp_path=tp_path,
669 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500670
671 def update_pm_config(self, device, pm_config):
672 # TODO: This has not been tested
673 self.log.info('update_pm_config', pm_config=pm_config)
674 self.pm_metrics.update(pm_config)
675
676 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
677 # flow decomposition that ultimately comes from onos
678 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700679 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500680
681 #
682 # We need to proxy through the OLT to get to the ONU
683 # Configuration from here should be using OMCI
684 #
685 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
686
687 # no point in pushing omci flows if the device isnt reachable
688 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530689 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500690 self.log.warn("device-disabled-or-offline-skipping-flow-update",
691 admin=device.admin_state, connect=device.connect_status)
692 return
693
694 def is_downstream(port):
695 return port == self._pon_port_number
696
697 def is_upstream(port):
698 return not is_downstream(port)
699
700 for flow in flows:
701 _type = None
702 _port = None
703 _vlan_vid = None
704 _udp_dst = None
705 _udp_src = None
706 _ipv4_dst = None
707 _ipv4_src = None
708 _metadata = None
709 _output = None
710 _push_tpid = None
711 _field = None
712 _set_vlan_vid = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400713 _tunnel_id = None
714
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500715 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530716 write_metadata = fd.get_write_metadata(flow)
717 if write_metadata is None:
718 self.log.error("do-not-process-flow-without-write-metadata")
719 return
720
721 # extract tp id from flow
722 tp_id = (write_metadata >> 32) & 0xFFFF
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500723 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +0530724
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500725 _in_port = fd.get_in_port(flow)
726 assert _in_port is not None
727
728 _out_port = fd.get_out_port(flow) # may be None
729
730 if is_downstream(_in_port):
731 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
732 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530733 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500734 elif is_upstream(_in_port):
735 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
736 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400737 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500738 else:
739 raise Exception('port should be 1 or 2 by our convention')
740
741 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
742
743 for field in fd.get_ofb_fields(flow):
744 if field.type == fd.ETH_TYPE:
745 _type = field.eth_type
746 self.log.debug('field-type-eth-type',
747 eth_type=_type)
748
749 elif field.type == fd.IP_PROTO:
750 _proto = field.ip_proto
751 self.log.debug('field-type-ip-proto',
752 ip_proto=_proto)
753
754 elif field.type == fd.IN_PORT:
755 _port = field.port
756 self.log.debug('field-type-in-port',
757 in_port=_port)
758
759 elif field.type == fd.VLAN_VID:
760 _vlan_vid = field.vlan_vid & 0xfff
761 self.log.debug('field-type-vlan-vid',
762 vlan=_vlan_vid)
763
764 elif field.type == fd.VLAN_PCP:
765 _vlan_pcp = field.vlan_pcp
766 self.log.debug('field-type-vlan-pcp',
767 pcp=_vlan_pcp)
768
769 elif field.type == fd.UDP_DST:
770 _udp_dst = field.udp_dst
771 self.log.debug('field-type-udp-dst',
772 udp_dst=_udp_dst)
773
774 elif field.type == fd.UDP_SRC:
775 _udp_src = field.udp_src
776 self.log.debug('field-type-udp-src',
777 udp_src=_udp_src)
778
779 elif field.type == fd.IPV4_DST:
780 _ipv4_dst = field.ipv4_dst
781 self.log.debug('field-type-ipv4-dst',
782 ipv4_dst=_ipv4_dst)
783
784 elif field.type == fd.IPV4_SRC:
785 _ipv4_src = field.ipv4_src
786 self.log.debug('field-type-ipv4-src',
787 ipv4_dst=_ipv4_src)
788
789 elif field.type == fd.METADATA:
790 _metadata = field.table_metadata
791 self.log.debug('field-type-metadata',
792 metadata=_metadata)
793
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400794 elif field.type == fd.TUNNEL_ID:
795 _tunnel_id = field.tunnel_id
796 self.log.debug('field-type-tunnel-id',
797 tunnel_id=_tunnel_id)
798
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500799 else:
800 raise NotImplementedError('field.type={}'.format(
801 field.type))
802
803 for action in fd.get_actions(flow):
804
805 if action.type == fd.OUTPUT:
806 _output = action.output.port
807 self.log.debug('action-type-output',
808 output=_output, in_port=_in_port)
809
810 elif action.type == fd.POP_VLAN:
811 self.log.debug('action-type-pop-vlan',
812 in_port=_in_port)
813
814 elif action.type == fd.PUSH_VLAN:
815 _push_tpid = action.push.ethertype
816 self.log.debug('action-type-push-vlan',
817 push_tpid=_push_tpid, in_port=_in_port)
818 if action.push.ethertype != 0x8100:
819 self.log.error('unhandled-tpid',
820 ethertype=action.push.ethertype)
821
822 elif action.type == fd.SET_FIELD:
823 _field = action.set_field.field.ofb_field
824 assert (action.set_field.field.oxm_class ==
825 OFPXMC_OPENFLOW_BASIC)
826 self.log.debug('action-type-set-field',
827 field=_field, in_port=_in_port)
828 if _field.type == fd.VLAN_VID:
829 _set_vlan_vid = _field.vlan_vid & 0xfff
830 self.log.debug('set-field-type-vlan-vid',
831 vlan_vid=_set_vlan_vid)
832 else:
833 self.log.error('unsupported-action-set-field-type',
834 field_type=_field.type)
835 else:
836 self.log.error('unsupported-action-type',
837 action_type=action.type, in_port=_in_port)
838
Matt Jeanneret810148b2019-09-29 12:44:01 -0400839 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
840 # supported match and action criteria cannot be handled by omci and must be ignored.
841 if _set_vlan_vid is None or _set_vlan_vid == 0:
842 self.log.warn('ignoring-flow-that-does-not-set-vlanid')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500843 else:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530844 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
845 self._add_vlan_filter_task(device, uni_id, uni_port, _set_vlan_vid, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500846 except Exception as e:
847 self.log.exception('failed-to-install-flow', e=e, flow=flow)
848
Girish Gowdraa73ee452019-12-20 18:52:17 +0530849 def _add_vlan_filter_task(self, device, uni_id, uni_port, _set_vlan_vid, tp_id):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500850 assert uni_port is not None
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400851 if uni_id in self._tech_profile_download_done and self._tech_profile_download_done[uni_id] != {}:
852 @inlineCallbacks
853 def success(_results):
Girish Gowdraa73ee452019-12-20 18:52:17 +0530854 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 -0700855 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400856 self._vlan_filter_task = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500857
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400858 @inlineCallbacks
859 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +0530860 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 -0700861 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400862 self._vlan_filter_task = reactor.callLater(_STARTUP_RETRY_WAIT,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530863 self._add_vlan_filter_task, device, uni_port.port_number,
Girish Gowdraa73ee452019-12-20 18:52:17 +0530864 uni_port, _set_vlan_vid, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500865
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400866 self.log.info('setting-vlan-tag')
Girish Gowdraa73ee452019-12-20 18:52:17 +0530867 self._vlan_filter_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid, tp_id)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400868 self._deferred = self._onu_omci_device.task_runner.queue_task(self._vlan_filter_task)
869 self._deferred.addCallbacks(success, failure)
870 else:
871 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
872 uni_id=uni_id)
Matt Jeanneret810148b2019-09-29 12:44:01 -0400873 self._queued_vlan_filter_task[uni_id] = {"device": device,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530874 "uni_id": uni_id,
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400875 "uni_port": uni_port,
Girish Gowdraa73ee452019-12-20 18:52:17 +0530876 "set_vlan_vid": _set_vlan_vid,
877 "tp_id": tp_id}
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500878
879 def get_tx_id(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700880 self.log.debug('get-tx-id')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500881 self.tx_id += 1
882 return self.tx_id
883
Matt Jeannereta32441c2019-03-07 05:16:37 -0500884 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700885 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
886 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500887 try:
888 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
889 omci_msg = InterAdapterOmciMessage()
890 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700891 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500892
Matt Jeannereta32441c2019-03-07 05:16:37 -0500893 self.receive_message(omci_msg.message)
894
895 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
896 onu_indication = OnuIndication()
897 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700898 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
899 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
900 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500901
902 if onu_indication.oper_state == "up":
903 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530904 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -0500905 self.update_interface(onu_indication)
906 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700907 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
908 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500909
Matt Jeanneret3bfebff2019-04-12 18:25:03 -0400910 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
911 tech_msg = InterAdapterTechProfileDownloadMessage()
912 request.body.Unpack(tech_msg)
913 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
914
915 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
916
Girish Gowdrae933cd32019-11-21 21:04:41 +0530917 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
918 del_gem_msg = InterAdapterDeleteGemPortMessage()
919 request.body.Unpack(del_gem_msg)
920 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
921
922 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
923 gem_port_id=del_gem_msg.gem_port_id,
924 tp_path=del_gem_msg.tp_path)
925
926 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
927 del_tcont_msg = InterAdapterDeleteTcontMessage()
928 request.body.Unpack(del_tcont_msg)
929 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
930
931 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
932 alloc_id=del_tcont_msg.alloc_id,
933 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500934 else:
935 self.log.error("inter-adapter-unhandled-type", request=request)
936
937 except Exception as e:
938 self.log.exception("error-processing-inter-adapter-message", e=e)
939
940 # Called each time there is an onu "up" indication from the olt handler
941 @inlineCallbacks
942 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500943 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -0700944 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500945 self._onu_indication = onu_indication
946
Matt Jeanneretc083f462019-03-11 15:02:01 -0400947 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
948 connect_status=ConnectStatus.REACHABLE)
949
Matt Jeannereta32441c2019-03-07 05:16:37 -0500950 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500951
952 self.log.debug('starting-openomci-statemachine')
953 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500954 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +0530955 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700956 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500957 self._heartbeat.enabled = True
958
959 # Currently called each time there is an onu "down" indication from the olt handler
960 # TODO: possibly other reasons to "update" from the olt?
Matt Jeannereta32441c2019-03-07 05:16:37 -0500961 @inlineCallbacks
962 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500963 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -0700964 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500965
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -0400966 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500967 self.log.debug('stopping-openomci-statemachine')
968 reactor.callLater(0, self._onu_omci_device.stop)
969
970 # Let TP download happen again
971 for uni_id in self._tp_service_specific_task:
972 self._tp_service_specific_task[uni_id].clear()
973 for uni_id in self._tech_profile_download_done:
974 self._tech_profile_download_done[uni_id].clear()
975
Matt Jeanneretf4113222019-08-14 19:44:34 -0400976 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700977 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
978 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
979 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500980 else:
981 self.log.debug('not-changing-openomci-statemachine')
982
983 # Not currently called by olt or anything else
William Kurkian3a206332019-04-29 11:05:47 -0400984 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500985 def remove_interface(self, data):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500986 self.log.info('remove-interface', data=data)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500987
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500988 self.log.debug('stopping-openomci-statemachine')
989 reactor.callLater(0, self._onu_omci_device.stop)
990
991 # Let TP download happen again
992 for uni_id in self._tp_service_specific_task:
993 self._tp_service_specific_task[uni_id].clear()
994 for uni_id in self._tech_profile_download_done:
995 self._tech_profile_download_done[uni_id].clear()
996
Matt Jeanneretf4113222019-08-14 19:44:34 -0400997 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700998 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500999
Matt Jeanneretf4113222019-08-14 19:44:34 -04001000 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001001 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001002 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001003 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001004 yield self.disable_ports(lock_ports=True)
1005 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1006 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001007
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001008 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001009 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001010
William Kurkian3a206332019-04-29 11:05:47 -04001011 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001012 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001013 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001014 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001015 yield self.core_proxy.device_state_update(device.id,
1016 oper_status=OperStatus.ACTIVE,
1017 connect_status=ConnectStatus.REACHABLE)
1018 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1019 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001020 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001021 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001022
William Kurkian3a206332019-04-29 11:05:47 -04001023 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001024 def reboot(self):
1025 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001026 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001027 if device.connect_status != ConnectStatus.REACHABLE:
1028 self.log.error("device-unreachable")
1029 return
1030
William Kurkian3a206332019-04-29 11:05:47 -04001031 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001032 def success(_results):
1033 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001034 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001035
1036 def failure(_reason):
1037 self.log.info('reboot-failure', _reason=_reason)
1038
1039 self._deferred = self._onu_omci_device.reboot()
1040 self._deferred.addCallbacks(success, failure)
1041
William Kurkian3a206332019-04-29 11:05:47 -04001042 @inlineCallbacks
Matt Jeanneretf4113222019-08-14 19:44:34 -04001043 def disable_ports(self, lock_ports=True):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001044 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001045
Matt Jeanneretf4113222019-08-14 19:44:34 -04001046 bus = self._onu_omci_device.event_bus
1047 bus.unsubscribe(self._port_state_subscription)
1048 self._port_state_subscription = None
1049
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001050 # Disable all ports on that device
Matt Jeanneretf4113222019-08-14 19:44:34 -04001051 for port in self.uni_ports:
1052 port.operstatus = OperStatus.UNKNOWN
1053 self.log.info('disable-port', device_id=self.device_id, port=port)
1054
1055 if lock_ports is True:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001056 self.lock_ports(lock=True)
1057
Matt Jeanneret80766692019-05-03 09:58:38 -04001058 yield self.core_proxy.ports_state_update(self.device_id, OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001059
William Kurkian3a206332019-04-29 11:05:47 -04001060 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001061 def enable_ports(self):
1062 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001063
Matt Jeanneretf4113222019-08-14 19:44:34 -04001064 # Listen for UNI link state alarms and set the oper_state based on that rather than assuming all UNI are up
Matt Jeanneretf4113222019-08-14 19:44:34 -04001065 bus = self._onu_omci_device.event_bus
1066 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1067 OnuDeviceEvents.PortEvent)
1068 self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001069 self.lock_ports(lock=False)
1070
1071 # TODO: Currently the only VEIP capable ONU i can test with does not send UNI link state alarms
1072 # or set operational-state per OMCI spec. So i have know way of "knowing" if the port is up.
1073 # Given this i assume its always up for now. Maybe a software upgrade will fix my onu...
1074 for port in self.uni_ports:
1075 if port.type.value == UniType.VEIP.value:
1076 port.operstatus = OperStatus.ACTIVE
1077 self.log.warn('force-showing-veip-link-up', device_id=self.device_id, port=port)
1078 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, port.operstatus)
1079
1080 @inlineCallbacks
1081 def port_state_handler(self, _topic, msg):
1082 self.log.info("port-state-change", _topic=_topic, msg=msg)
1083
1084 onu_id = msg['onu_id']
1085 port_no = msg['port_number']
1086 serial_number = msg['serial_number']
1087 port_status = msg['port_status']
1088 uni_port = self.uni_port(int(port_no))
1089
1090 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1091 port_status=port_status)
1092
1093 if port_status is True:
1094 uni_port.operstatus = OperStatus.ACTIVE
1095 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1096 else:
1097 uni_port.operstatus = OperStatus.UNKNOWN
1098 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1099
1100 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, uni_port.port_number, uni_port.operstatus)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001101
1102 # Called just before openomci state machine is started. These listen for events from selected state machines,
1103 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1104 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001105 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001106
1107 # OMCI MIB Database sync status
1108 bus = self._onu_omci_device.event_bus
1109 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1110 OnuDeviceEvents.MibDatabaseSyncEvent)
1111 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1112
1113 # OMCI Capabilities
1114 bus = self._onu_omci_device.event_bus
1115 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1116 OnuDeviceEvents.OmciCapabilitiesEvent)
1117 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1118
1119 # Called when the mib is in sync
1120 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001121 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001122 if self._in_sync_subscription is not None:
1123 try:
1124 in_sync = msg[IN_SYNC_KEY]
1125
1126 if in_sync:
1127 # Only call this once
1128 bus = self._onu_omci_device.event_bus
1129 bus.unsubscribe(self._in_sync_subscription)
1130 self._in_sync_subscription = None
1131
1132 # Start up device_info load
1133 self.log.debug('running-mib-sync')
1134 reactor.callLater(0, self._mib_in_sync)
1135
1136 except Exception as e:
1137 self.log.exception('in-sync', e=e)
1138
1139 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001140 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001141 if self._capabilities_subscription is not None:
1142 self.log.debug('capabilities-handler-done')
1143
1144 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1145 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1146 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001147 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001148 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001149 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001150
1151 omci = self._onu_omci_device
1152 in_sync = omci.mib_db_in_sync
1153
Matt Jeanneretc083f462019-03-11 15:02:01 -04001154 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001155 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001156
1157 if not self._dev_info_loaded:
1158 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1159
1160 omci_dev = self._onu_omci_device
1161 config = omci_dev.configuration
1162
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001163 try:
1164
1165 # sort the lists so we get consistent port ordering.
1166 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1167 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1168 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1169 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1170
1171 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001172 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001173 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001174 raise Exception("onu-missing-required-elements")
1175
1176 # Currently logging the ani, pptp, veip, and uni for information purposes.
1177 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1178 # And in some ONU the UNI-G list is incomplete or incorrect...
1179 for entity_id in ani_list:
1180 ani_value = config.ani_g_entities[entity_id]
1181 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1182 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1183 self._total_tcont_count = ani_value.get('total-tcont-count')
1184 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1185
1186 for entity_id in uni_list:
1187 uni_value = config.uni_g_entities[entity_id]
1188 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1189
1190 uni_entities = OrderedDict()
1191 for entity_id in pptp_list:
1192 pptp_value = config.pptp_entities[entity_id]
1193 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1194 uni_entities[entity_id] = UniType.PPTP
1195
1196 for entity_id in veip_list:
1197 veip_value = config.veip_entities[entity_id]
1198 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1199 uni_entities[entity_id] = UniType.VEIP
1200
1201 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001202 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001203 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001204 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001205 uni_id += 1
1206 except AssertionError as e:
1207 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1208
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001209 self._qos_flexibility = config.qos_configuration_flexibility or 0
1210 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1211
1212 if self._unis:
1213 self._dev_info_loaded = True
1214 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001215 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001216 self.log.warn("no-usable-unis")
1217 raise Exception("no-usable-unis")
1218
1219 except Exception as e:
1220 self.log.exception('device-info-load', e=e)
1221 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1222
1223 else:
1224 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1225
1226 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001227 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001228
1229 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001230 def success(_results):
1231 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001232 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301233 oper_status=OperStatus.ACTIVE,
1234 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001235 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001236 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001237 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001238 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001239
Matt Jeanneretc083f462019-03-11 15:02:01 -04001240 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001241 def failure(_reason):
1242 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001243 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001244 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1245
Matt Jeanneretf4113222019-08-14 19:44:34 -04001246 # start by locking all the unis till mib sync and initial mib is downloaded
1247 # this way we can capture the port down/up events when we are ready
1248 self.lock_ports(lock=True)
1249
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001250 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1251 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1252 self.log.info('downloading-initial-mib-configuration')
1253 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1254 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1255 self._deferred.addCallbacks(success, failure)
1256 else:
1257 self.log.info('admin-down-disabling')
1258 self.disable(device)
1259 else:
1260 self.log.info('device-info-not-loaded-skipping-mib-download')
1261
Matt Jeanneretc083f462019-03-11 15:02:01 -04001262 @inlineCallbacks
1263 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001264 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001265
Matt Jeanneretc083f462019-03-11 15:02:01 -04001266 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 -05001267
1268 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1269 uni_name = "uni-{}".format(uni_no)
1270
Girish Gowdrae933cd32019-11-21 21:04:41 +05301271 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001272
1273 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 -04001274 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001275
1276 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1277 uni_port.entity_id = entity_id
1278 uni_port.enabled = True
1279 uni_port.mac_bridge_port_num = mac_bridge_port_num
1280
1281 self.log.debug("created-uni-port", uni=uni_port)
1282
Matt Jeanneretc083f462019-03-11 15:02:01 -04001283 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001284
1285 self._unis[uni_port.port_number] = uni_port
1286
1287 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301288 uni_ports=self.uni_ports,
1289 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001290
Matt Jeanneretc083f462019-03-11 15:02:01 -04001291 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1292 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001293 MAX_PONS_PER_OLT = 256
1294 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001295 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001296
Matt Jeanneretc083f462019-03-11 15:02:01 -04001297 assert intf_id < MAX_PONS_PER_OLT
1298 assert onu_id < MAX_ONUS_PER_PON
1299 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001300 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001301
1302 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001303 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001304 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001305 try:
1306 device = yield self.core_proxy.get_device(self.device_id)
1307 parent_device = yield self.core_proxy.get_device(self.parent_id)
1308 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001309 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001310
1311 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301312 pon_id=self._onu_indication.intf_id,
1313 onu_id=self._onu_indication.onu_id,
1314 registration_id=self.device_id,
1315 device_id=self.device_id,
1316 onu_serial_number=device.serial_number,
1317 olt_serial_number=olt_serial_number,
1318 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001319
Devmalya Paulffc89df2019-07-31 17:43:13 -04001320 self.log.debug("Trying-to-raise-onu-active-event")
1321 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001322 self._onu_indication.intf_id,
1323 device.serial_number,
1324 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301325 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001326 onu_id=self._onu_indication.onu_id).send(True)
1327 except Exception as active_event_error:
1328 self.log.exception('onu-activated-event-error',
1329 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001330
1331 def lock_ports(self, lock=True):
1332
1333 def success(response):
1334 self.log.debug('set-onu-ports-state', lock=lock, response=response)
1335
1336 def failure(response):
1337 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1338
1339 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1340 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1341 self._deferred.addCallbacks(success, failure)