blob: e1cc587b080aeccad16f196e2988d701398f18d9 [file] [log] [blame]
Shad Ansari2825d012018-02-22 23:57:46 +00001#
2# Copyright 2018 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#
Shad Ansari2825d012018-02-22 23:57:46 +000016import threading
Shad Ansari94250fc2018-07-04 06:52:11 +000017import binascii
Shad Ansari2825d012018-02-22 23:57:46 +000018import grpc
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -080019import socket
20import re
Shad Ansari94250fc2018-07-04 06:52:11 +000021import structlog
Shad Ansari06019382019-02-07 22:56:16 -080022import time
Shad Ansari15928d12018-04-17 02:42:13 +000023from twisted.internet import reactor
Shad Ansari0346f0d2018-04-26 06:54:09 +000024from scapy.layers.l2 import Ether, Dot1Q
Shad Ansari3cd9bf22018-07-25 19:29:39 +000025from transitions import Machine
Shad Ansari15928d12018-04-17 02:42:13 +000026
Shad Ansari2825d012018-02-22 23:57:46 +000027from voltha.protos.device_pb2 import Port, Device
28from voltha.protos.common_pb2 import OperStatus, AdminState, ConnectStatus
29from voltha.protos.logical_device_pb2 import LogicalDevice
Shad Ansarif9d2d102018-06-13 02:15:26 +000030from voltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \
31 OFPPS_LINK_DOWN, OFPPF_1GB_FD, OFPC_GROUP_STATS, OFPC_PORT_STATS, \
Nicolas Palpacuere7359fc2018-06-15 14:10:48 -040032 OFPC_TABLE_STATS, OFPC_FLOW_STATS, ofp_switch_features, ofp_port, \
Jonathan Hart05845412018-07-19 09:55:43 -070033 ofp_port_stats, ofp_desc
Shad Ansarif9d2d102018-06-13 02:15:26 +000034from voltha.protos.logical_device_pb2 import LogicalPort
Shad Ansari2825d012018-02-22 23:57:46 +000035from voltha.core.logical_device_agent import mac_str_to_tuple
36from voltha.registry import registry
37from voltha.adapters.openolt.protos import openolt_pb2_grpc, openolt_pb2
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -040038from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData
39from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData
Shad Ansari2825d012018-02-22 23:57:46 +000040
mzadig384783a2018-08-09 08:52:40 -040041from voltha.extensions.alarms.onu.onu_discovery_alarm import OnuDiscoveryAlarm
Shad Ansarif9d2d102018-06-13 02:15:26 +000042
43
Shad Ansari2825d012018-02-22 23:57:46 +000044class OpenoltDevice(object):
Shad Ansari94250fc2018-07-04 06:52:11 +000045 """
46 OpenoltDevice state machine:
Shad Ansari2825d012018-02-22 23:57:46 +000047
Shad Ansari94250fc2018-07-04 06:52:11 +000048 null ----> init ------> connected -----> up -----> down
49 ^ ^ | ^ | |
50 | | | | | |
51 | +-------------+ +---------+ |
52 | |
53 +-----------------------------------------+
54 """
55 # pylint: disable=too-many-instance-attributes
56 # pylint: disable=R0904
57 states = [
58 'state_null',
59 'state_init',
60 'state_connected',
61 'state_up',
62 'state_down']
63
Shad Ansari22efe832018-05-19 05:37:03 +000064 transitions = [
Shad Ansari0e7ad962018-09-28 01:42:26 +000065 {'trigger': 'go_state_init',
66 'source': ['state_null', 'state_connected', 'state_down'],
67 'dest': 'state_init',
68 'before': 'do_state_init',
69 'after': 'post_init'},
70 {'trigger': 'go_state_connected',
71 'source': 'state_init',
72 'dest': 'state_connected',
73 'before': 'do_state_connected'},
74 {'trigger': 'go_state_up',
75 'source': ['state_connected', 'state_down'],
76 'dest': 'state_up',
77 'before': 'do_state_up'},
78 {'trigger': 'go_state_down',
79 'source': ['state_up'],
80 'dest': 'state_down',
81 'before': 'do_state_down',
82 'after': 'post_down'}]
Shad Ansari22efe832018-05-19 05:37:03 +000083
Shad Ansari2825d012018-02-22 23:57:46 +000084 def __init__(self, **kwargs):
85 super(OpenoltDevice, self).__init__()
86
Shad Ansari7c73c1a2019-02-04 15:39:47 -080087 self.admin_state = "up"
88
Shad Ansari2825d012018-02-22 23:57:46 +000089 self.adapter_agent = kwargs['adapter_agent']
Shad Ansari5dbc9c82018-05-10 03:29:31 +000090 self.device_num = kwargs['device_num']
Shad Ansari2825d012018-02-22 23:57:46 +000091 device = kwargs['device']
Shad Ansaricd20a6d2018-10-02 14:36:33 +000092
93 self.platform_class = kwargs['support_classes']['platform']
Girish Gowdru1e77ea02018-09-24 09:10:35 -070094 self.resource_mgr_class = kwargs['support_classes']['resource_mgr']
Shad Ansaricd20a6d2018-10-02 14:36:33 +000095 self.flow_mgr_class = kwargs['support_classes']['flow_mgr']
96 self.alarm_mgr_class = kwargs['support_classes']['alarm_mgr']
97 self.stats_mgr_class = kwargs['support_classes']['stats_mgr']
98 self.bw_mgr_class = kwargs['support_classes']['bw_mgr']
99
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400100 is_reconciliation = kwargs.get('reconciliation', False)
Shad Ansari2825d012018-02-22 23:57:46 +0000101 self.device_id = device.id
102 self.host_and_port = device.host_and_port
Girish Gowdru141ced82018-09-17 20:19:14 -0700103 self.extra_args = device.extra_args
Shad Ansarif9d2d102018-06-13 02:15:26 +0000104 self.log = structlog.get_logger(id=self.device_id,
105 ip=self.host_and_port)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400106 self.proxy = registry('core').get_proxy('/')
Shad Ansari2825d012018-02-22 23:57:46 +0000107
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800108 self.log.info('openolt-device-init')
109
Craig Lutgen109d4072018-12-11 17:01:16 -0600110 # default device id and device serial number. If device_info provides better results, they will be updated
111 self.dpid = kwargs.get('dp_id')
112 self.serial_number = self.host_and_port # FIXME
113
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400114 # Device already set in the event of reconciliation
115 if not is_reconciliation:
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800116 self.log.info('updating-device')
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400117 # It is a new device
118 # Update device
119 device.root = True
Shad Ansari94250fc2018-07-04 06:52:11 +0000120 device.connect_status = ConnectStatus.UNREACHABLE
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400121 device.oper_status = OperStatus.ACTIVATING
122 self.adapter_agent.update_device(device)
Shad Ansari2825d012018-02-22 23:57:46 +0000123
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800124 self.logical_device_id = None
Shad Ansaric4085df2019-02-13 16:47:07 -0800125 # If logical device does exist use it, else create one after connecting
126 # to device
Craig Lutgen109d4072018-12-11 17:01:16 -0600127 if device.parent_id:
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400128 # logical device already exists
129 self.logical_device_id = device.parent_id
130 if is_reconciliation:
131 self.adapter_agent.reconcile_logical_device(
132 self.logical_device_id)
Shad Ansaric4085df2019-02-13 16:47:07 -0800133 else:
134 self.logical_device_id = None
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400135
Shad Ansari94250fc2018-07-04 06:52:11 +0000136 # Initialize the OLT state machine
137 self.machine = Machine(model=self, states=OpenoltDevice.states,
138 transitions=OpenoltDevice.transitions,
139 send_event=True, initial='state_null')
Shad Ansaric4085df2019-02-13 16:47:07 -0800140
141 self.device_info = None
142
Shad Ansari94250fc2018-07-04 06:52:11 +0000143 self.go_state_init()
144
Craig Lutgen109d4072018-12-11 17:01:16 -0600145 def create_logical_device(self, device_info):
146 dpid = device_info.device_id
147 serial_number = device_info.device_serial_number
148
149 if dpid is None: dpid = self.dpid
150 if serial_number is None: serial_number = self.serial_number
151
Matt Jeanneretcc9f59b2018-12-17 15:58:20 -0500152 if dpid == None or dpid == '':
Craig Lutgen109d4072018-12-11 17:01:16 -0600153 uri = self.host_and_port.split(":")[0]
154 try:
155 socket.inet_pton(socket.AF_INET, uri)
156 dpid = '00:00:' + self.ip_hex(uri)
157 except socket.error:
158 # this is not an IP
159 dpid = self.stringToMacAddr(uri)
160
Matt Jeanneretcc9f59b2018-12-17 15:58:20 -0500161 if serial_number == None or serial_number == '':
162 serial_number = self.host_and_port
163
Craig Lutgen109d4072018-12-11 17:01:16 -0600164 self.log.info('creating-openolt-logical-device', dp_id=dpid, serial_number=serial_number)
165
166 mfr_desc = device_info.vendor
167 sw_desc = device_info.firmware_version
168 hw_desc = device_info.model
169 if device_info.hardware_version: hw_desc += '-' + device_info.hardware_version
170
171 # Create logical OF device
172 ld = LogicalDevice(
173 root_device_id=self.device_id,
174 switch_features=ofp_switch_features(
175 n_buffers=256, # TODO fake for now
176 n_tables=2, # TODO ditto
177 capabilities=( # TODO and ditto
178 OFPC_FLOW_STATS
179 | OFPC_TABLE_STATS
180 | OFPC_PORT_STATS
181 | OFPC_GROUP_STATS
182 )
183 ),
184 desc=ofp_desc(
Craig Lutgen109d4072018-12-11 17:01:16 -0600185 serial_num=serial_number
186 )
187 )
188 ld_init = self.adapter_agent.create_logical_device(ld,
189 dpid=dpid)
190
Craig Lutgen109d4072018-12-11 17:01:16 -0600191 device = self.adapter_agent.get_device(self.device_id)
192 device.serial_number = serial_number
193 self.adapter_agent.update_device(device)
194
195 self.dpid = dpid
196 self.serial_number = serial_number
197
198 self.log.info('created-openolt-logical-device', logical_device_id=ld_init.id)
199
Shad Ansaric4085df2019-02-13 16:47:07 -0800200 return ld_init.id
201
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800202 def stringToMacAddr(self, uri):
203 regex = re.compile('[^a-zA-Z]')
204 uri = regex.sub('', uri)
205
206 l = len(uri)
207 if l > 6:
208 uri = uri[0:6]
209 else:
210 uri = uri + uri[0:6 - l]
211
212 print uri
213
214 return ":".join([hex(ord(x))[-2:] for x in uri])
215
Shad Ansari94250fc2018-07-04 06:52:11 +0000216 def do_state_init(self, event):
Shad Ansari2825d012018-02-22 23:57:46 +0000217 # Initialize gRPC
218 self.channel = grpc.insecure_channel(self.host_and_port)
Shad Ansari8f1b2532018-04-21 07:51:39 +0000219 self.channel_ready_future = grpc.channel_ready_future(self.channel)
nick47b74372018-05-25 18:22:49 -0400220
Nicolas Palpacuer7183a3b2018-09-10 17:16:49 -0400221 self.log.info('openolt-device-created', device_id=self.device_id)
222
223 def post_init(self, event):
224 self.log.debug('post_init')
225
226 # We have reached init state, starting the indications thread
227
jasonhuang5f3e63b2018-07-27 01:32:48 +0800228 # Catch RuntimeError exception
229 try:
230 # Start indications thread
231 self.indications_thread_handle = threading.Thread(
232 target=self.indications_thread)
Shad Ansarif9521ad2018-09-08 10:46:43 +0000233 # Old getter/setter API for daemon; use it directly as a
jasonhuang5f3e63b2018-07-27 01:32:48 +0800234 # property instead. The Jinkins error will happon on the reason of
Shad Ansarif9521ad2018-09-08 10:46:43 +0000235 # Exception in thread Thread-1 (most likely raised # during
jasonhuang5f3e63b2018-07-27 01:32:48 +0800236 # interpreter shutdown)
237 self.indications_thread_handle.setDaemon(True)
238 self.indications_thread_handle.start()
Shad Ansarif9521ad2018-09-08 10:46:43 +0000239 except Exception as e:
Nicolas Palpacuer7183a3b2018-09-10 17:16:49 -0400240 self.log.exception('post_init failed', e=e)
Shad Ansari94250fc2018-07-04 06:52:11 +0000241
242 def do_state_connected(self, event):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400243 self.log.debug("do_state_connected")
244
Shad Ansari94250fc2018-07-04 06:52:11 +0000245 device = self.adapter_agent.get_device(self.device_id)
Shad Ansari94250fc2018-07-04 06:52:11 +0000246
Shad Ansaric4085df2019-02-13 16:47:07 -0800247 if self.logical_device_id is None:
248 # first time connect to olt
249 self.logical_device_id = self.create_logical_device(
250 self.device_info)
251 else:
252 # reconnect to olt (e.g. olt reboot)
253 # TODO - Update logical device with new device_info
254 pass
Craig Lutgen109d4072018-12-11 17:01:16 -0600255
256 device.serial_number = self.serial_number
257
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700258 self.resource_mgr = self.resource_mgr_class(self.device_id,
Shad Ansari78de2be2018-10-12 22:13:54 +0000259 self.host_and_port,
260 self.extra_args,
Shad Ansaric4085df2019-02-13 16:47:07 -0800261 self.device_info)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000262 self.platform = self.platform_class(self.log, self.resource_mgr)
Girish Gowdruab836e92018-10-25 01:17:57 -0700263 self.flow_mgr = self.flow_mgr_class(self.adapter_agent, self.log,
264 self.stub, self.device_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000265 self.logical_device_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700266 self.platform, self.resource_mgr)
267
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000268 self.alarm_mgr = self.alarm_mgr_class(self.log, self.adapter_agent,
269 self.device_id,
270 self.logical_device_id,
271 self.platform)
272 self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform)
273 self.bw_mgr = self.bw_mgr_class(self.log, self.proxy)
274
Shad Ansaric4085df2019-02-13 16:47:07 -0800275 device.vendor = self.device_info.vendor
276 device.model = self.device_info.model
277 device.hardware_version = self.device_info.hardware_version
278 device.firmware_version = self.device_info.firmware_version
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700279
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700280 # TODO: check for uptime and reboot if too long (VOL-1192)
281
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400282 device.connect_status = ConnectStatus.REACHABLE
283 self.adapter_agent.update_device(device)
284
Shad Ansari94250fc2018-07-04 06:52:11 +0000285 def do_state_up(self, event):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400286 self.log.debug("do_state_up")
287
Shad Ansari94250fc2018-07-04 06:52:11 +0000288 device = self.adapter_agent.get_device(self.device_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000289
Shad Ansari94250fc2018-07-04 06:52:11 +0000290 # Update phys OF device
291 device.parent_id = self.logical_device_id
292 device.oper_status = OperStatus.ACTIVE
293 self.adapter_agent.update_device(device)
nick47b74372018-05-25 18:22:49 -0400294
Shad Ansari94250fc2018-07-04 06:52:11 +0000295 def do_state_down(self, event):
296 self.log.debug("do_state_down")
297 oper_state = OperStatus.UNKNOWN
298 connect_state = ConnectStatus.UNREACHABLE
Nicolas Palpacuerd35d9bb2018-06-20 17:06:31 -0400299
Shad Ansari94250fc2018-07-04 06:52:11 +0000300 # Propagating to the children
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400301
Shad Ansari94250fc2018-07-04 06:52:11 +0000302 # Children ports
303 child_devices = self.adapter_agent.get_child_devices(self.device_id)
304 for onu_device in child_devices:
Shad Ansari0e7ad962018-09-28 01:42:26 +0000305 onu_adapter_agent = \
306 registry('adapter_loader').get_agent(onu_device.adapter)
307 onu_adapter_agent.update_interface(onu_device,
308 {'oper_state': 'down'})
Craig Lutgenabd9c842018-11-15 23:58:27 +0000309 self.onu_ports_down(onu_device, oper_state)
310
Shad Ansari94250fc2018-07-04 06:52:11 +0000311 # Children devices
312 self.adapter_agent.update_child_devices_state(
313 self.device_id, oper_status=oper_state,
314 connect_status=connect_state)
315 # Device Ports
316 device_ports = self.adapter_agent.get_ports(self.device_id,
317 Port.ETHERNET_NNI)
318 logical_ports_ids = [port.label for port in device_ports]
319 device_ports += self.adapter_agent.get_ports(self.device_id,
320 Port.PON_OLT)
321
322 for port in device_ports:
323 port.oper_status = oper_state
324 self.adapter_agent.add_port(self.device_id, port)
325
326 # Device logical port
327 for logical_port_id in logical_ports_ids:
328 logical_port = self.adapter_agent.get_logical_port(
329 self.logical_device_id, logical_port_id)
330 logical_port.ofp_port.state = OFPPS_LINK_DOWN
331 self.adapter_agent.update_logical_port(self.logical_device_id,
332 logical_port)
333
334 # Device
335 device = self.adapter_agent.get_device(self.device_id)
336 device.oper_status = oper_state
337 device.connect_status = connect_state
338
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400339 reactor.callLater(2, self.adapter_agent.update_device, device)
340
341 # def post_up(self, event):
342 # self.log.debug('post-up')
343 # self.flow_mgr.reseed_flows()
344
345 def post_down(self, event):
346 self.log.debug('post_down')
347 self.flow_mgr.reset_flows()
348
Shad Ansari94250fc2018-07-04 06:52:11 +0000349 def indications_thread(self):
nick47b74372018-05-25 18:22:49 -0400350 self.log.debug('starting-indications-thread')
Shad Ansari94250fc2018-07-04 06:52:11 +0000351 self.log.debug('connecting to olt', device_id=self.device_id)
Shad Ansaric4085df2019-02-13 16:47:07 -0800352
353 self.stub = openolt_pb2_grpc.OpenoltStub(self.channel)
354
355 timeout = 60*60
356 delay = 1
357 exponential_back_off = False
358 while True:
359 try:
360 self.device_info = self.stub.GetDeviceInfo(openolt_pb2.Empty())
361 break
362 except Exception as e:
363 if delay > timeout:
364 self.log.error("timed out connecting to olt")
365 return
366 else:
367 self.log.warn("retry connecting to olt in %ds: %s"
368 % (delay, repr(e)))
369 time.sleep(delay)
370 if exponential_back_off:
371 delay += delay
372 else:
373 delay += 1
374
375 self.log.info('connected to olt', device_info=self.device_info)
376
Shad Ansari94250fc2018-07-04 06:52:11 +0000377 self.go_state_connected()
Shad Ansari2dda4f32018-05-17 07:16:07 +0000378
Shad Ansari15928d12018-04-17 02:42:13 +0000379 self.indications = self.stub.EnableIndication(openolt_pb2.Empty())
Shad Ansari2dda4f32018-05-17 07:16:07 +0000380
Shad Ansari94250fc2018-07-04 06:52:11 +0000381 while True:
nick47b74372018-05-25 18:22:49 -0400382 try:
383 # get the next indication from olt
384 ind = next(self.indications)
385 except Exception as e:
Shad Ansari94250fc2018-07-04 06:52:11 +0000386 self.log.warn('gRPC connection lost', error=e)
387 reactor.callFromThread(self.go_state_down)
388 reactor.callFromThread(self.go_state_init)
389 break
nick47b74372018-05-25 18:22:49 -0400390 else:
391 self.log.debug("rx indication", indication=ind)
Shad Ansari5dbc9c82018-05-10 03:29:31 +0000392
Shad Ansari7c73c1a2019-02-04 15:39:47 -0800393 if self.admin_state is "down":
394 if ind.HasField('intf_oper_ind') \
395 and (ind.intf_oper_ind.type == "nni"):
396 self.log.warn('olt is admin down, allow nni ind',
397 admin_state=self.admin_state,
398 indications=ind)
399 else:
400 self.log.warn('olt is admin down, ignore indication',
401 admin_state=self.admin_state,
402 indications=ind)
403 continue
404
nick47b74372018-05-25 18:22:49 -0400405 # indication handlers run in the main event loop
406 if ind.HasField('olt_ind'):
407 reactor.callFromThread(self.olt_indication, ind.olt_ind)
408 elif ind.HasField('intf_ind'):
409 reactor.callFromThread(self.intf_indication, ind.intf_ind)
410 elif ind.HasField('intf_oper_ind'):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000411 reactor.callFromThread(self.intf_oper_indication,
412 ind.intf_oper_ind)
nick47b74372018-05-25 18:22:49 -0400413 elif ind.HasField('onu_disc_ind'):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000414 reactor.callFromThread(self.onu_discovery_indication,
415 ind.onu_disc_ind)
nick47b74372018-05-25 18:22:49 -0400416 elif ind.HasField('onu_ind'):
417 reactor.callFromThread(self.onu_indication, ind.onu_ind)
418 elif ind.HasField('omci_ind'):
419 reactor.callFromThread(self.omci_indication, ind.omci_ind)
420 elif ind.HasField('pkt_ind'):
421 reactor.callFromThread(self.packet_indication, ind.pkt_ind)
Nicolas Palpacuer33f1a822018-06-13 12:36:36 -0400422 elif ind.HasField('port_stats'):
Nicolas Palpacuere761c902018-07-05 16:30:52 -0400423 reactor.callFromThread(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700424 self.stats_mgr.port_statistics_indication,
425 ind.port_stats)
Nicolas Palpacuer33f1a822018-06-13 12:36:36 -0400426 elif ind.HasField('flow_stats'):
Nicolas Palpacuere761c902018-07-05 16:30:52 -0400427 reactor.callFromThread(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700428 self.stats_mgr.flow_statistics_indication,
429 ind.flow_stats)
Shad Ansari905b8402018-07-03 00:04:50 +0000430 elif ind.HasField('alarm_ind'):
Nicolas Palpacuer16138de2018-07-03 14:35:18 -0400431 reactor.callFromThread(self.alarm_mgr.process_alarms,
432 ind.alarm_ind)
Nicolas Palpacuer33f1a822018-06-13 12:36:36 -0400433 else:
434 self.log.warn('unknown indication type')
nick47b74372018-05-25 18:22:49 -0400435
Shad Ansari2825d012018-02-22 23:57:46 +0000436 def olt_indication(self, olt_indication):
Shad Ansari7c73c1a2019-02-04 15:39:47 -0800437 '''
438 if self.admin_state is "up":
439 if olt_indication.oper_state == "up":
440 self.go_state_up()
441 elif olt_indication.oper_state == "down":
442 self.go_state_down()
443 '''
Shad Ansari22efe832018-05-19 05:37:03 +0000444 if olt_indication.oper_state == "up":
Shad Ansari94250fc2018-07-04 06:52:11 +0000445 self.go_state_up()
Shad Ansari22efe832018-05-19 05:37:03 +0000446 elif olt_indication.oper_state == "down":
Shad Ansari94250fc2018-07-04 06:52:11 +0000447 self.go_state_down()
Shad Ansari2825d012018-02-22 23:57:46 +0000448
449 def intf_indication(self, intf_indication):
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400450 self.log.debug("intf indication", intf_id=intf_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000451 oper_state=intf_indication.oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000452
453 if intf_indication.oper_state == "up":
454 oper_status = OperStatus.ACTIVE
455 else:
456 oper_status = OperStatus.DISCOVERED
457
nick47b74372018-05-25 18:22:49 -0400458 # add_port update the port if it exists
Shad Ansari2825d012018-02-22 23:57:46 +0000459 self.add_port(intf_indication.intf_id, Port.PON_OLT, oper_status)
460
461 def intf_oper_indication(self, intf_oper_indication):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000462 self.log.debug("Received interface oper state change indication",
463 intf_id=intf_oper_indication.intf_id,
464 type=intf_oper_indication.type,
465 oper_state=intf_oper_indication.oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000466
467 if intf_oper_indication.oper_state == "up":
468 oper_state = OperStatus.ACTIVE
469 else:
470 oper_state = OperStatus.DISCOVERED
471
472 if intf_oper_indication.type == "nni":
473
Nicolas Palpacuercf735ac2018-06-06 11:12:53 -0400474 # add_(logical_)port update the port if it exists
Shad Ansarif9d2d102018-06-13 02:15:26 +0000475 port_no, label = self.add_port(intf_oper_indication.intf_id,
476 Port.ETHERNET_NNI, oper_state)
Nicolas Palpacuercf735ac2018-06-06 11:12:53 -0400477 self.log.debug("int_oper_indication", port_no=port_no, label=label)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000478 self.add_logical_port(port_no, intf_oper_indication.intf_id,
479 oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000480
481 elif intf_oper_indication.type == "pon":
482 # FIXME - handle PON oper state change
483 pass
484
485 def onu_discovery_indication(self, onu_disc_indication):
Shad Ansari803900a2018-05-02 06:26:00 +0000486 intf_id = onu_disc_indication.intf_id
Shad Ansarif9d2d102018-06-13 02:15:26 +0000487 serial_number = onu_disc_indication.serial_number
Shad Ansari2825d012018-02-22 23:57:46 +0000488
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400489 serial_number_str = self.stringify_serial_number(serial_number)
Shad Ansari803900a2018-05-02 06:26:00 +0000490
Shad Ansarif9d2d102018-06-13 02:15:26 +0000491 self.log.debug("onu discovery indication", intf_id=intf_id,
492 serial_number=serial_number_str)
Nicolas Palpacuer36a93442018-05-23 17:38:57 -0400493
mzadig384783a2018-08-09 08:52:40 -0400494 # Post ONU Discover alarm 20180809_0805
495 try:
Nicolas Palpacuere9bf83c2018-08-16 14:53:14 -0400496 OnuDiscoveryAlarm(self.alarm_mgr.alarms, pon_id=intf_id,
497 serial_number=serial_number_str).raise_alarm()
mzadig384783a2018-08-09 08:52:40 -0400498 except Exception as disc_alarm_error:
Nicolas Palpacuere9bf83c2018-08-16 14:53:14 -0400499 self.log.exception("onu-discovery-alarm-error",
500 errmsg=disc_alarm_error.message)
mzadig384783a2018-08-09 08:52:40 -0400501 # continue for now.
502
Shad Ansarif9d2d102018-06-13 02:15:26 +0000503 onu_device = self.adapter_agent.get_child_device(
504 self.device_id,
505 serial_number=serial_number_str)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400506
507 if onu_device is None:
Shad Ansari15928d12018-04-17 02:42:13 +0000508 try:
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700509 onu_id = self.resource_mgr.get_onu_id(intf_id)
510 if onu_id is None:
511 raise Exception("onu-id-unavailable")
512
Shad Ansarif9d2d102018-06-13 02:15:26 +0000513 self.add_onu_device(
514 intf_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000515 self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT),
Shad Ansarif9d2d102018-06-13 02:15:26 +0000516 onu_id, serial_number)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400517 self.activate_onu(intf_id, onu_id, serial_number,
Girish Gowdruab836e92018-10-25 01:17:57 -0700518 serial_number_str)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400519 except Exception as e:
520 self.log.exception('onu-activation-failed', e=e)
521
Shad Ansari2825d012018-02-22 23:57:46 +0000522 else:
nick47b74372018-05-25 18:22:49 -0400523 if onu_device.connect_status != ConnectStatus.REACHABLE:
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700524 onu_device.connect_status = ConnectStatus.REACHABLE
525 self.adapter_agent.update_device(onu_device)
nick47b74372018-05-25 18:22:49 -0400526
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400527 onu_id = onu_device.proxy_address.onu_id
Shad Ansarif9d2d102018-06-13 02:15:26 +0000528 if onu_device.oper_status == OperStatus.DISCOVERED \
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700529 or onu_device.oper_status == OperStatus.ACTIVATING:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000530 self.log.debug("ignore onu discovery indication, \
531 the onu has been discovered and should be \
532 activating shorlty", intf_id=intf_id,
533 onu_id=onu_id, state=onu_device.oper_status)
534 elif onu_device.oper_status == OperStatus.ACTIVE:
535 self.log.warn("onu discovery indication whereas onu is \
536 supposed to be active",
537 intf_id=intf_id, onu_id=onu_id,
538 state=onu_device.oper_status)
nick47b74372018-05-25 18:22:49 -0400539 elif onu_device.oper_status == OperStatus.UNKNOWN:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000540 self.log.info("onu in unknown state, recovering from olt \
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400541 reboot probably, activate onu", intf_id=intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000542 onu_id=onu_id, serial_number=serial_number_str)
nick47b74372018-05-25 18:22:49 -0400543
544 onu_device.oper_status = OperStatus.DISCOVERED
545 self.adapter_agent.update_device(onu_device)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400546 try:
547 self.activate_onu(intf_id, onu_id, serial_number,
Girish Gowdruab836e92018-10-25 01:17:57 -0700548 serial_number_str)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400549 except Exception as e:
550 self.log.error('onu-activation-error',
551 serial_number=serial_number_str, error=e)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400552 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000553 self.log.warn('unexpected state', onu_id=onu_id,
554 onu_device_oper_state=onu_device.oper_status)
Shad Ansari2825d012018-02-22 23:57:46 +0000555
Shad Ansari2825d012018-02-22 23:57:46 +0000556 def onu_indication(self, onu_indication):
Shad Ansaria0b37892018-06-12 21:34:30 +0000557 self.log.debug("onu indication", intf_id=onu_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000558 onu_id=onu_indication.onu_id,
559 serial_number=onu_indication.serial_number,
560 oper_state=onu_indication.oper_state,
561 admin_state=onu_indication.admin_state)
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400562 try:
563 serial_number_str = self.stringify_serial_number(
564 onu_indication.serial_number)
Shad Ansari94250fc2018-07-04 06:52:11 +0000565 except Exception as e:
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400566 serial_number_str = None
Shad Ansari94250fc2018-07-04 06:52:11 +0000567
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400568 if serial_number_str is not None:
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400569 onu_device = self.adapter_agent.get_child_device(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700570 self.device_id,
571 serial_number=serial_number_str)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000572 else:
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400573 onu_device = self.adapter_agent.get_child_device(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700574 self.device_id,
575 parent_port_no=self.platform.intf_id_to_port_no(
576 onu_indication.intf_id, Port.PON_OLT),
577 onu_id=onu_indication.onu_id)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400578
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400579 if onu_device is None:
Shad Ansaria0b37892018-06-12 21:34:30 +0000580 self.log.error('onu not found', intf_id=onu_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000581 onu_id=onu_indication.onu_id)
Shad Ansari803900a2018-05-02 06:26:00 +0000582 return
583
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000584 if self.platform.intf_id_from_pon_port_no(onu_device.parent_port_no) \
Shad Ansarif9521ad2018-09-08 10:46:43 +0000585 != onu_indication.intf_id:
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400586 self.log.warn('ONU-is-on-a-different-intf-id-now',
Keita NISHIMOTO11bb10d2018-10-11 07:17:35 +0900587 previous_intf_id=self.platform.intf_id_from_pon_port_no(
588 onu_device.parent_port_no),
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400589 current_intf_id=onu_indication.intf_id)
590 # FIXME - handle intf_id mismatch (ONU move?)
Shad Ansari2825d012018-02-22 23:57:46 +0000591
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400592 if onu_device.proxy_address.onu_id != onu_indication.onu_id:
593 # FIXME - handle onu id mismatch
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400594 self.log.warn('ONU-id-mismatch, can happen if both voltha and '
595 'the olt rebooted',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000596 expected_onu_id=onu_device.proxy_address.onu_id,
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400597 received_onu_id=onu_indication.onu_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000598
Shad Ansarif9d2d102018-06-13 02:15:26 +0000599 # Admin state
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400600 if onu_indication.admin_state == 'down':
601 if onu_indication.oper_state != 'down':
Shad Ansarif9d2d102018-06-13 02:15:26 +0000602 self.log.error('ONU-admin-state-down-and-oper-status-not-down',
603 oper_state=onu_indication.oper_state)
604 # Forcing the oper state change code to execute
605 onu_indication.oper_state = 'down'
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400606
Shad Ansarif9d2d102018-06-13 02:15:26 +0000607 # Port and logical port update is taken care of by oper state block
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400608
609 elif onu_indication.admin_state == 'up':
Nicolas Palpacuer921f8cf2018-08-14 18:23:09 -0400610 pass
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400611
612 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000613 self.log.warn('Invalid-or-not-implemented-admin-state',
614 received_admin_state=onu_indication.admin_state)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400615
616 self.log.debug('admin-state-dealt-with')
617
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400618 onu_adapter_agent = \
619 registry('adapter_loader').get_agent(onu_device.adapter)
620 if onu_adapter_agent is None:
621 self.log.error('onu_adapter_agent-could-not-be-retrieved',
622 onu_device=onu_device)
623 return
624
Shad Ansarif9d2d102018-06-13 02:15:26 +0000625 # Operating state
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400626 if onu_indication.oper_state == 'down':
Nicolas Palpacuer4ea3a652018-08-22 10:33:17 -0400627
628 if onu_device.connect_status != ConnectStatus.UNREACHABLE:
629 onu_device.connect_status = ConnectStatus.UNREACHABLE
630 self.adapter_agent.update_device(onu_device)
631
Shad Ansarif9d2d102018-06-13 02:15:26 +0000632 # Move to discovered state
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400633 self.log.debug('onu-oper-state-is-down')
634
635 if onu_device.oper_status != OperStatus.DISCOVERED:
636 onu_device.oper_status = OperStatus.DISCOVERED
637 self.adapter_agent.update_device(onu_device)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000638 # Set port oper state to Discovered
Craig Lutgenabd9c842018-11-15 23:58:27 +0000639 self.onu_ports_down(onu_device, OperStatus.DISCOVERED)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400640
Shad Ansari0e7ad962018-09-28 01:42:26 +0000641 onu_adapter_agent.update_interface(onu_device,
642 {'oper_state': 'down'})
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400643
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400644 elif onu_indication.oper_state == 'up':
645
Nicolas Palpacuer2824a992018-08-20 18:07:41 -0400646 if onu_device.connect_status != ConnectStatus.REACHABLE:
647 onu_device.connect_status = ConnectStatus.REACHABLE
648 self.adapter_agent.update_device(onu_device)
649
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400650 if onu_device.oper_status != OperStatus.DISCOVERED:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000651 self.log.debug("ignore onu indication",
652 intf_id=onu_indication.intf_id,
653 onu_id=onu_indication.onu_id,
654 state=onu_device.oper_status,
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400655 msg_oper_state=onu_indication.oper_state)
656 return
657
Shad Ansarif9d2d102018-06-13 02:15:26 +0000658 # Device was in Discovered state, setting it to active
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400659
Shad Ansarif9d2d102018-06-13 02:15:26 +0000660 # Prepare onu configuration
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400661
Shad Ansari0e7ad962018-09-28 01:42:26 +0000662 onu_adapter_agent.create_interface(onu_device, onu_indication)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400663
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400664 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000665 self.log.warn('Not-implemented-or-invalid-value-of-oper-state',
666 oper_state=onu_indication.oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000667
Craig Lutgenabd9c842018-11-15 23:58:27 +0000668 def onu_ports_down(self, onu_device, oper_state):
nick47b74372018-05-25 18:22:49 -0400669 # Set port oper state to Discovered
670 # add port will update port if it exists
Craig Lutgenabd9c842018-11-15 23:58:27 +0000671 # self.adapter_agent.add_port(
672 # self.device_id,
673 # Port(
674 # port_no=uni_no,
675 # label=uni_name,
676 # type=Port.ETHERNET_UNI,
677 # admin_state=onu_device.admin_state,
678 # oper_status=oper_state))
679 # TODO this should be downning ports in onu adatper
nick47b74372018-05-25 18:22:49 -0400680
681 # Disable logical port
nick47b74372018-05-25 18:22:49 -0400682 onu_ports = self.proxy.get('devices/{}/ports'.format(onu_device.id))
nick47b74372018-05-25 18:22:49 -0400683 for onu_port in onu_ports:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000684 self.log.debug('onu-ports-down', onu_port=onu_port)
685 onu_port_id = onu_port.label
686 try:
687 onu_logical_port = self.adapter_agent.get_logical_port(
688 logical_device_id=self.logical_device_id, port_id=onu_port_id)
689 onu_logical_port.ofp_port.state = OFPPS_LINK_DOWN
690 self.adapter_agent.update_logical_port(
691 logical_device_id=self.logical_device_id,
692 port=onu_logical_port)
693 self.log.debug('cascading-oper-state-to-port-and-logical-port')
694 except KeyError as e:
695 self.log.error('matching-onu-port-label-invalid',
696 onu_id=onu_device.id, olt_id=self.device_id,
697 onu_ports=onu_ports, onu_port_id=onu_port_id,
698 error=e)
nick47b74372018-05-25 18:22:49 -0400699
Shad Ansari2825d012018-02-22 23:57:46 +0000700 def omci_indication(self, omci_indication):
701
702 self.log.debug("omci indication", intf_id=omci_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000703 onu_id=omci_indication.onu_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000704
Shad Ansarif9d2d102018-06-13 02:15:26 +0000705 onu_device = self.adapter_agent.get_child_device(
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400706 self.device_id, onu_id=omci_indication.onu_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000707 parent_port_no=self.platform.intf_id_to_port_no(
Girish Gowdru141ced82018-09-17 20:19:14 -0700708 omci_indication.intf_id, Port.PON_OLT), )
Shad Ansari0efa6512018-04-28 06:42:54 +0000709
710 self.adapter_agent.receive_proxied_message(onu_device.proxy_address,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000711 omci_indication.pkt)
Shad Ansari2825d012018-02-22 23:57:46 +0000712
Shad Ansari42db7342018-04-25 21:39:46 +0000713 def packet_indication(self, pkt_indication):
714
Shad Ansari0ff82622018-09-30 09:32:04 +0000715 self.log.debug("packet indication",
716 intf_type=pkt_indication.intf_type,
717 intf_id=pkt_indication.intf_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000718 port_no=pkt_indication.port_no,
719 cookie=pkt_indication.cookie,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000720 gemport_id=pkt_indication.gemport_id,
721 flow_id=pkt_indication.flow_id)
Shad Ansari42db7342018-04-25 21:39:46 +0000722
Shad Ansari0ff82622018-09-30 09:32:04 +0000723 if pkt_indication.intf_type == "pon":
Craig Lutgenabd9c842018-11-15 23:58:27 +0000724 if pkt_indication.port_no:
725 logical_port_num = pkt_indication.port_no
726 else: # TODO Remove this else block after openolt device has been fully rolled out with cookie protobuf change
727 try:
728 onu_id_uni_id = self.resource_mgr.get_onu_uni_from_ponport_gemport(pkt_indication.intf_id,
729 pkt_indication.gemport_id)
730 onu_id = int(onu_id_uni_id[0])
731 uni_id = int(onu_id_uni_id[1])
732 self.log.debug("packet indication-kv", onu_id=onu_id, uni_id=uni_id)
733 if onu_id is None:
734 raise Exception("onu-id-none")
735 if uni_id is None:
736 raise Exception("uni-id-none")
737 logical_port_num = self.platform.mk_uni_port_num(pkt_indication.intf_id, onu_id, uni_id)
738 except Exception as e:
739 self.log.error("no-onu-reference-for-gem",
740 gemport_id=pkt_indication.gemport_id, e=e)
741 return
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700742
Craig Lutgenabd9c842018-11-15 23:58:27 +0000743
Shad Ansari0ff82622018-09-30 09:32:04 +0000744 elif pkt_indication.intf_type == "nni":
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000745 logical_port_num = self.platform.intf_id_to_port_no(
Shad Ansari0ff82622018-09-30 09:32:04 +0000746 pkt_indication.intf_id,
747 Port.ETHERNET_NNI)
Shad Ansari42db7342018-04-25 21:39:46 +0000748
749 pkt = Ether(pkt_indication.pkt)
Shad Ansari0ff82622018-09-30 09:32:04 +0000750
751 self.log.debug("packet indication",
752 logical_device_id=self.logical_device_id,
753 logical_port_no=logical_port_num)
754
755 self.adapter_agent.send_packet_in(
756 logical_device_id=self.logical_device_id,
757 logical_port_no=logical_port_num,
758 packet=str(pkt))
Shad Ansari42db7342018-04-25 21:39:46 +0000759
760 def packet_out(self, egress_port, msg):
Shad Ansari0346f0d2018-04-26 06:54:09 +0000761 pkt = Ether(msg)
Saurav Dasf87d6552018-09-26 17:05:42 -0700762 self.log.debug('packet out', egress_port=egress_port,
763 device_id=self.device_id,
764 logical_device_id=self.logical_device_id,
765 packet=str(pkt).encode("HEX"))
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400766
767 # Find port type
Craig Lutgenabd9c842018-11-15 23:58:27 +0000768 egress_port_type = self.platform.intf_id_to_port_type_name(egress_port)
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400769 if egress_port_type == Port.ETHERNET_UNI:
770
771 if pkt.haslayer(Dot1Q):
772 outer_shim = pkt.getlayer(Dot1Q)
773 if isinstance(outer_shim.payload, Dot1Q):
774 # If double tag, remove the outer tag
775 payload = (
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700776 Ether(src=pkt.src, dst=pkt.dst, type=outer_shim.type) /
777 outer_shim.payload
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400778 )
779 else:
780 payload = pkt
Shad Ansari0346f0d2018-04-26 06:54:09 +0000781 else:
782 payload = pkt
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400783
784 send_pkt = binascii.unhexlify(str(payload).encode("HEX"))
785
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400786 self.log.debug(
Shad Ansarif9d2d102018-06-13 02:15:26 +0000787 'sending-packet-to-ONU', egress_port=egress_port,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000788 intf_id=self.platform.intf_id_from_uni_port_num(egress_port),
789 onu_id=self.platform.onu_id_from_port_num(egress_port),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000790 uni_id=self.platform.uni_id_from_port_num(egress_port),
791 port_no=egress_port,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000792 packet=str(payload).encode("HEX"))
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400793
Shad Ansarif9d2d102018-06-13 02:15:26 +0000794 onu_pkt = openolt_pb2.OnuPacket(
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000795 intf_id=self.platform.intf_id_from_uni_port_num(egress_port),
796 onu_id=self.platform.onu_id_from_port_num(egress_port),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000797 port_no=egress_port,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000798 pkt=send_pkt)
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400799
800 self.stub.OnuPacketOut(onu_pkt)
801
802 elif egress_port_type == Port.ETHERNET_NNI:
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400803 self.log.debug('sending-packet-to-uplink', egress_port=egress_port,
Shad Ansarif9521ad2018-09-08 10:46:43 +0000804 packet=str(pkt).encode("HEX"))
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400805
806 send_pkt = binascii.unhexlify(str(pkt).encode("HEX"))
807
Shad Ansarif9d2d102018-06-13 02:15:26 +0000808 uplink_pkt = openolt_pb2.UplinkPacket(
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000809 intf_id=self.platform.intf_id_from_nni_port_num(egress_port),
Shad Ansarif9d2d102018-06-13 02:15:26 +0000810 pkt=send_pkt)
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400811
812 self.stub.UplinkPacketOut(uplink_pkt)
813
Shad Ansari0346f0d2018-04-26 06:54:09 +0000814 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000815 self.log.warn('Packet-out-to-this-interface-type-not-implemented',
816 egress_port=egress_port,
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400817 port_type=egress_port_type)
Shad Ansari42db7342018-04-25 21:39:46 +0000818
Shad Ansari2825d012018-02-22 23:57:46 +0000819 def send_proxied_message(self, proxy_address, msg):
Shad Ansarif9521ad2018-09-08 10:46:43 +0000820 onu_device = self.adapter_agent.get_child_device(
Girish Gowdru141ced82018-09-17 20:19:14 -0700821 self.device_id, onu_id=proxy_address.onu_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000822 parent_port_no=self.platform.intf_id_to_port_no(
Girish Gowdru141ced82018-09-17 20:19:14 -0700823 proxy_address.channel_id, Port.PON_OLT)
824 )
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400825 if onu_device.connect_status != ConnectStatus.REACHABLE:
826 self.log.debug('ONU is not reachable, cannot send OMCI',
827 serial_number=onu_device.serial_number,
828 intf_id=onu_device.proxy_address.channel_id,
829 onu_id=onu_device.proxy_address.onu_id)
830 return
Shad Ansarif9d2d102018-06-13 02:15:26 +0000831 omci = openolt_pb2.OmciMsg(intf_id=proxy_address.channel_id,
832 onu_id=proxy_address.onu_id, pkt=str(msg))
Shad Ansari2825d012018-02-22 23:57:46 +0000833 self.stub.OmciMsgOut(omci)
834
835 def add_onu_device(self, intf_id, port_no, onu_id, serial_number):
Shad Ansari2825d012018-02-22 23:57:46 +0000836 self.log.info("Adding ONU", port_no=port_no, onu_id=onu_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000837 serial_number=serial_number)
Shad Ansari2825d012018-02-22 23:57:46 +0000838
839 # NOTE - channel_id of onu is set to intf_id
Shad Ansari0efa6512018-04-28 06:42:54 +0000840 proxy_address = Device.ProxyAddress(device_id=self.device_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000841 channel_id=intf_id, onu_id=onu_id,
842 onu_session_id=onu_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000843
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400844 self.log.debug("Adding ONU", proxy_address=proxy_address)
Shad Ansari2825d012018-02-22 23:57:46 +0000845
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400846 serial_number_str = self.stringify_serial_number(serial_number)
Shad Ansari2825d012018-02-22 23:57:46 +0000847
Shad Ansarif9d2d102018-06-13 02:15:26 +0000848 self.adapter_agent.add_onu_device(
849 parent_device_id=self.device_id, parent_port_no=port_no,
850 vendor_id=serial_number.vendor_id, proxy_address=proxy_address,
851 root=True, serial_number=serial_number_str,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000852 admin_state=AdminState.ENABLED#, **{'vlan':4091} # magic still maps to brcm_openomci_onu.pon_port.BRDCM_DEFAULT_VLAN
853 )
Shad Ansari2825d012018-02-22 23:57:46 +0000854
Shad Ansari1fd9eb22018-05-15 05:13:49 +0000855 def port_name(self, port_no, port_type, intf_id=None, serial_number=None):
Shad Ansari2825d012018-02-22 23:57:46 +0000856 if port_type is Port.ETHERNET_NNI:
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400857 return "nni-" + str(port_no)
Shad Ansari2825d012018-02-22 23:57:46 +0000858 elif port_type is Port.PON_OLT:
Shad Ansari4a232ca2018-05-05 05:24:17 +0000859 return "pon" + str(intf_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000860 elif port_type is Port.ETHERNET_UNI:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000861 assert False, 'local UNI management not supported'
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400862
Nicolas Palpacuercf735ac2018-06-06 11:12:53 -0400863 def add_logical_port(self, port_no, intf_id, oper_state):
Shad Ansari2825d012018-02-22 23:57:46 +0000864 self.log.info('adding-logical-port', port_no=port_no)
865
866 label = self.port_name(port_no, Port.ETHERNET_NNI)
867
868 cap = OFPPF_1GB_FD | OFPPF_FIBER
869 curr_speed = OFPPF_1GB_FD
870 max_speed = OFPPF_1GB_FD
871
Nicolas Palpacuercf735ac2018-06-06 11:12:53 -0400872 if oper_state == OperStatus.ACTIVE:
873 of_oper_state = OFPPS_LIVE
874 else:
875 of_oper_state = OFPPS_LINK_DOWN
876
Shad Ansarif9d2d102018-06-13 02:15:26 +0000877 ofp = ofp_port(
878 port_no=port_no,
Nicolas Palpacuer5780e152018-09-05 17:25:42 -0400879 hw_addr=mac_str_to_tuple(self._get_mac_form_port_no(port_no)),
Shad Ansarif9d2d102018-06-13 02:15:26 +0000880 name=label, config=0, state=of_oper_state, curr=cap,
881 advertised=cap, peer=cap, curr_speed=curr_speed,
882 max_speed=max_speed)
Shad Ansari2825d012018-02-22 23:57:46 +0000883
Nicolas Palpacuere7359fc2018-06-15 14:10:48 -0400884 ofp_stats = ofp_port_stats(port_no=port_no)
885
Shad Ansarif9d2d102018-06-13 02:15:26 +0000886 logical_port = LogicalPort(
887 id=label, ofp_port=ofp, device_id=self.device_id,
Nicolas Palpacuere7359fc2018-06-15 14:10:48 -0400888 device_port_no=port_no, root_port=True,
889 ofp_port_stats=ofp_stats)
Shad Ansari2825d012018-02-22 23:57:46 +0000890
Shad Ansarif9d2d102018-06-13 02:15:26 +0000891 self.adapter_agent.add_logical_port(self.logical_device_id,
892 logical_port)
Shad Ansari2825d012018-02-22 23:57:46 +0000893
Nicolas Palpacuer5780e152018-09-05 17:25:42 -0400894 def _get_mac_form_port_no(self, port_no):
895 mac = ''
896 for i in range(4):
897 mac = ':%02x' % ((port_no >> (i * 8)) & 0xff) + mac
898 return '00:00' + mac
899
Shad Ansari2825d012018-02-22 23:57:46 +0000900 def add_port(self, intf_id, port_type, oper_status):
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000901 port_no = self.platform.intf_id_to_port_no(intf_id, port_type)
Shad Ansari2825d012018-02-22 23:57:46 +0000902
Shad Ansari4a232ca2018-05-05 05:24:17 +0000903 label = self.port_name(port_no, port_type, intf_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000904
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400905 self.log.debug('adding-port', port_no=port_no, label=label,
Shad Ansarif9521ad2018-09-08 10:46:43 +0000906 port_type=port_type)
Shad Ansari0efa6512018-04-28 06:42:54 +0000907
908 port = Port(port_no=port_no, label=label, type=port_type,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000909 admin_state=AdminState.ENABLED, oper_status=oper_status)
Shad Ansari0efa6512018-04-28 06:42:54 +0000910
Shad Ansari2825d012018-02-22 23:57:46 +0000911 self.adapter_agent.add_port(self.device_id, port)
Shad Ansari0efa6512018-04-28 06:42:54 +0000912
Shad Ansari2825d012018-02-22 23:57:46 +0000913 return port_no, label
914
Girish Gowdruab836e92018-10-25 01:17:57 -0700915 def delete_logical_port(self, child_device):
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -0400916 logical_ports = self.proxy.get('/logical_devices/{}/ports'.format(
917 self.logical_device_id))
918 for logical_port in logical_ports:
Girish Gowdruab836e92018-10-25 01:17:57 -0700919 if logical_port.device_id == child_device.id:
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -0400920 self.log.debug('delete-logical-port',
Girish Gowdruab836e92018-10-25 01:17:57 -0700921 onu_device_id=child_device.id,
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -0400922 logical_port=logical_port)
Girish Gowdruab836e92018-10-25 01:17:57 -0700923 self.flow_mgr.clear_flows_and_scheduler_for_logical_port(
924 child_device, logical_port)
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -0400925 self.adapter_agent.delete_logical_port(
926 self.logical_device_id, logical_port)
927 return
Shad Ansarif9521ad2018-09-08 10:46:43 +0000928
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -0400929 def delete_port(self, child_serial_number):
930 ports = self.proxy.get('/devices/{}/ports'.format(
931 self.device_id))
932 for port in ports:
933 if port.label == child_serial_number:
934 self.log.debug('delete-port',
935 onu_serial_number=child_serial_number,
936 port=port)
937 self.adapter_agent.delete_port(self.device_id, port)
938 return
939
Shad Ansari2825d012018-02-22 23:57:46 +0000940 def update_flow_table(self, flows):
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400941 self.log.debug('No updates here now, all is done in logical flows '
942 'update')
Shad Ansari5df91f62018-07-25 23:59:46 +0000943
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400944 def update_logical_flows(self, flows_to_add, flows_to_remove,
945 device_rules_map):
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400946 if not self.is_state_up():
947 self.log.info('The OLT is not up, we cannot update flows',
948 flows_to_add=[f.id for f in flows_to_add],
949 flows_to_remove=[f.id for f in flows_to_remove])
950 return
951
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400952 try:
953 self.flow_mgr.update_children_flows(device_rules_map)
954 except Exception as e:
955 self.log.error('Error updating children flows', error=e)
Shad Ansari2825d012018-02-22 23:57:46 +0000956
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400957 self.log.debug('logical flows update', flows_to_add=flows_to_add,
Shad Ansarif9521ad2018-09-08 10:46:43 +0000958 flows_to_remove=flows_to_remove)
Shad Ansari2825d012018-02-22 23:57:46 +0000959
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400960 for flow in flows_to_add:
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400961
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400962 try:
963 self.flow_mgr.add_flow(flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400964 except Exception as e:
965 self.log.error('failed to add flow', flow=flow, e=e)
966
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400967 for flow in flows_to_remove:
968
969 try:
970 self.flow_mgr.remove_flow(flow)
971 except Exception as e:
972 self.log.error('failed to remove flow', flow=flow, e=e)
973
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400974 self.flow_mgr.repush_all_different_flows()
975
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400976 # There has to be a better way to do this
Shad Ansari89b09d52018-05-21 07:28:14 +0000977 def ip_hex(self, ip):
978 octets = ip.split(".")
979 hex_ip = []
980 for octet in octets:
981 octet_hex = hex(int(octet))
982 octet_hex = octet_hex.split('0x')[1]
983 octet_hex = octet_hex.rjust(2, '0')
984 hex_ip.append(octet_hex)
985 return ":".join(hex_ip)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400986
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400987 def stringify_vendor_specific(self, vendor_specific):
988 return ''.join(str(i) for i in [
989 hex(ord(vendor_specific[0]) >> 4 & 0x0f)[2:],
990 hex(ord(vendor_specific[0]) & 0x0f)[2:],
991 hex(ord(vendor_specific[1]) >> 4 & 0x0f)[2:],
992 hex(ord(vendor_specific[1]) & 0x0f)[2:],
993 hex(ord(vendor_specific[2]) >> 4 & 0x0f)[2:],
994 hex(ord(vendor_specific[2]) & 0x0f)[2:],
995 hex(ord(vendor_specific[3]) >> 4 & 0x0f)[2:],
996 hex(ord(vendor_specific[3]) & 0x0f)[2:]])
997
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400998 def stringify_serial_number(self, serial_number):
999 return ''.join([serial_number.vendor_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +00001000 self.stringify_vendor_specific(
1001 serial_number.vendor_specific)])
Jonathan Davis0f917a22018-05-30 14:39:45 -04001002
Nicolas Palpacuer131790b2018-08-20 09:59:34 -04001003 def destringify_serial_number(self, serial_number_str):
1004 serial_number = openolt_pb2.SerialNumber(
1005 vendor_id=serial_number_str[:4].encode('utf-8'),
1006 vendor_specific=binascii.unhexlify(serial_number_str[4:]))
1007 return serial_number
1008
Jonathan Davis0f917a22018-05-30 14:39:45 -04001009 def disable(self):
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001010 self.log.debug('sending-deactivate-olt-message',
Shad Ansarif9521ad2018-09-08 10:46:43 +00001011 device_id=self.device_id)
Jonathan Davis0f917a22018-05-30 14:39:45 -04001012
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001013 try:
1014 # Send grpc call
1015 self.stub.DisableOlt(openolt_pb2.Empty())
Shad Ansari7c73c1a2019-02-04 15:39:47 -08001016 self.admin_state = "down"
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001017 self.log.info('openolt device disabled')
1018 except Exception as e:
1019 self.log.error('Failure to disable openolt device', error=e)
Jonathan Davis0f917a22018-05-30 14:39:45 -04001020
Jonathan Davis0f917a22018-05-30 14:39:45 -04001021 def delete(self):
Nicolas Palpacuer0d44e682018-08-06 10:30:26 -04001022 self.log.info('deleting-olt', device_id=self.device_id,
1023 logical_device_id=self.logical_device_id)
1024
Girish Gowdru1e77ea02018-09-24 09:10:35 -07001025 # Clears up the data from the resource manager KV store
1026 # for the device
1027 del self.resource_mgr
1028
Nicolas Palpacuer0d44e682018-08-06 10:30:26 -04001029 try:
1030 # Rebooting to reset the state
1031 self.reboot()
1032 # Removing logical device
Saurav Dasf87d6552018-09-26 17:05:42 -07001033 ld = self.adapter_agent.get_logical_device(self.logical_device_id)
1034 self.adapter_agent.delete_logical_device(ld)
Nicolas Palpacuer0d44e682018-08-06 10:30:26 -04001035 except Exception as e:
1036 self.log.error('Failure to delete openolt device', error=e)
1037 raise e
1038 else:
1039 self.log.info('successfully-deleted-olt', device_id=self.device_id)
Jonathan Davis0f917a22018-05-30 14:39:45 -04001040
Jonathan Davis0f917a22018-05-30 14:39:45 -04001041 def reenable(self):
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001042 self.log.debug('reenabling-olt', device_id=self.device_id)
Jonathan Davis0f917a22018-05-30 14:39:45 -04001043
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001044 try:
1045 self.stub.ReenableOlt(openolt_pb2.Empty())
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001046 except Exception as e:
1047 self.log.error('Failure to reenable openolt device', error=e)
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -04001048 else:
1049 self.log.info('openolt device reenabled')
Shad Ansari7c73c1a2019-02-04 15:39:47 -08001050 self.admin_state = "up"
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -04001051
Nicolas Palpacuer131790b2018-08-20 09:59:34 -04001052 def activate_onu(self, intf_id, onu_id, serial_number,
Girish Gowdruab836e92018-10-25 01:17:57 -07001053 serial_number_str):
Nicolas Palpacuer131790b2018-08-20 09:59:34 -04001054 pir = self.bw_mgr.pir(serial_number_str)
1055 self.log.debug("activating-onu", intf_id=intf_id, onu_id=onu_id,
Shad Ansarif9521ad2018-09-08 10:46:43 +00001056 serial_number_str=serial_number_str,
Girish Gowdruab836e92018-10-25 01:17:57 -07001057 serial_number=serial_number, pir=pir)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -04001058 onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id,
Girish Gowdruab836e92018-10-25 01:17:57 -07001059 serial_number=serial_number, pir=pir)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -04001060 self.stub.ActivateOnu(onu)
1061 self.log.info('onu-activated', serial_number=serial_number_str)
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001062
Jonathan Davisb45bb372018-07-19 15:05:15 -04001063 def delete_child_device(self, child_device):
1064 self.log.debug('sending-deactivate-onu',
1065 olt_device_id=self.device_id,
1066 onu_device=child_device,
1067 onu_serial_number=child_device.serial_number)
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -04001068 try:
1069 self.adapter_agent.delete_child_device(self.device_id,
Shad Ansarif9521ad2018-09-08 10:46:43 +00001070 child_device.id,
1071 child_device)
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -04001072 except Exception as e:
1073 self.log.error('adapter_agent error', error=e)
1074 try:
Girish Gowdruab836e92018-10-25 01:17:57 -07001075 self.delete_logical_port(child_device)
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -04001076 except Exception as e:
1077 self.log.error('logical_port delete error', error=e)
1078 try:
1079 self.delete_port(child_device.serial_number)
1080 except Exception as e:
1081 self.log.error('port delete error', error=e)
Shad Ansarif9521ad2018-09-08 10:46:43 +00001082 serial_number = self.destringify_serial_number(
1083 child_device.serial_number)
Craig Lutgenabd9c842018-11-15 23:58:27 +00001084 # TODO FIXME - For each uni.
1085 # TODO FIXME - Flows are not deleted
1086 uni_id = 0 # FIXME
Girish Gowdrub761bc12018-11-29 02:22:18 -08001087 self.flow_mgr.delete_tech_profile_instance(
1088 child_device.proxy_address.channel_id,
1089 child_device.proxy_address.onu_id,
1090 uni_id
1091 )
Girish Gowdru1e77ea02018-09-24 09:10:35 -07001092 pon_intf_id_onu_id = (child_device.proxy_address.channel_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +00001093 child_device.proxy_address.onu_id,
1094 uni_id)
Girish Gowdru1e77ea02018-09-24 09:10:35 -07001095 # Free any PON resources that were reserved for the ONU
1096 self.resource_mgr.free_pon_resources_for_onu(pon_intf_id_onu_id)
1097
Jonathan Davisb45bb372018-07-19 15:05:15 -04001098 onu = openolt_pb2.Onu(intf_id=child_device.proxy_address.channel_id,
1099 onu_id=child_device.proxy_address.onu_id,
Girish Gowdrub761bc12018-11-29 02:22:18 -08001100 serial_number=serial_number)
Shad Ansari3cd9bf22018-07-25 19:29:39 +00001101 self.stub.DeleteOnu(onu)
Nicolas Palpacuerfd365ac2018-08-02 11:37:37 -04001102
1103 def reboot(self):
Shad Ansarif9521ad2018-09-08 10:46:43 +00001104 self.log.debug('rebooting openolt device', device_id=self.device_id)
Nicolas Palpacuerfd365ac2018-08-02 11:37:37 -04001105 try:
1106 self.stub.Reboot(openolt_pb2.Empty())
1107 except Exception as e:
1108 self.log.error('something went wrong with the reboot', error=e)
1109 else:
1110 self.log.info('device rebooted')
1111
Nicolas Palpacuer30027f42018-09-06 15:55:54 -04001112 def trigger_statistics_collection(self):
1113 try:
1114 self.stub.CollectStatistics(openolt_pb2.Empty())
1115 except Exception as e:
1116 self.log.error('Error while triggering statistics collection',
1117 error=e)
1118 else:
1119 self.log.info('statistics requested')
Scott Bakerd3190952018-09-04 15:47:28 -07001120
1121 def simulate_alarm(self, alarm):
1122 self.alarm_mgr.simulate_alarm(alarm)