blob: ac6489e1d239b800aebcb0163563feb8473c090d [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
Shad Ansari2825d012018-02-22 23:57:46 +000038
mzadig384783a2018-08-09 08:52:40 -040039from voltha.extensions.alarms.onu.onu_discovery_alarm import OnuDiscoveryAlarm
Shad Ansarif9d2d102018-06-13 02:15:26 +000040
41
Shad Ansari2825d012018-02-22 23:57:46 +000042class OpenoltDevice(object):
Shad Ansari94250fc2018-07-04 06:52:11 +000043 """
44 OpenoltDevice state machine:
Shad Ansari2825d012018-02-22 23:57:46 +000045
Shad Ansari94250fc2018-07-04 06:52:11 +000046 null ----> init ------> connected -----> up -----> down
47 ^ ^ | ^ | |
48 | | | | | |
49 | +-------------+ +---------+ |
50 | |
51 +-----------------------------------------+
52 """
53 # pylint: disable=too-many-instance-attributes
54 # pylint: disable=R0904
55 states = [
56 'state_null',
57 'state_init',
58 'state_connected',
59 'state_up',
60 'state_down']
61
Shad Ansari22efe832018-05-19 05:37:03 +000062 transitions = [
Shad Ansari0e7ad962018-09-28 01:42:26 +000063 {'trigger': 'go_state_init',
64 'source': ['state_null', 'state_connected', 'state_down'],
65 'dest': 'state_init',
66 'before': 'do_state_init',
67 'after': 'post_init'},
68 {'trigger': 'go_state_connected',
69 'source': 'state_init',
70 'dest': 'state_connected',
71 'before': 'do_state_connected'},
72 {'trigger': 'go_state_up',
73 'source': ['state_connected', 'state_down'],
74 'dest': 'state_up',
75 'before': 'do_state_up'},
76 {'trigger': 'go_state_down',
77 'source': ['state_up'],
78 'dest': 'state_down',
79 'before': 'do_state_down',
80 'after': 'post_down'}]
Shad Ansari22efe832018-05-19 05:37:03 +000081
Shad Ansari2825d012018-02-22 23:57:46 +000082 def __init__(self, **kwargs):
83 super(OpenoltDevice, self).__init__()
84
Shad Ansari7c73c1a2019-02-04 15:39:47 -080085 self.admin_state = "up"
86
Shad Ansari2825d012018-02-22 23:57:46 +000087 self.adapter_agent = kwargs['adapter_agent']
Shad Ansari5dbc9c82018-05-10 03:29:31 +000088 self.device_num = kwargs['device_num']
Shad Ansari2825d012018-02-22 23:57:46 +000089 device = kwargs['device']
Shad Ansaricd20a6d2018-10-02 14:36:33 +000090
91 self.platform_class = kwargs['support_classes']['platform']
Girish Gowdru1e77ea02018-09-24 09:10:35 -070092 self.resource_mgr_class = kwargs['support_classes']['resource_mgr']
Shad Ansaricd20a6d2018-10-02 14:36:33 +000093 self.flow_mgr_class = kwargs['support_classes']['flow_mgr']
94 self.alarm_mgr_class = kwargs['support_classes']['alarm_mgr']
95 self.stats_mgr_class = kwargs['support_classes']['stats_mgr']
96 self.bw_mgr_class = kwargs['support_classes']['bw_mgr']
97
Nicolas Palpacuer253461f2018-06-01 12:01:45 -040098 is_reconciliation = kwargs.get('reconciliation', False)
Shad Ansari2825d012018-02-22 23:57:46 +000099 self.device_id = device.id
100 self.host_and_port = device.host_and_port
Girish Gowdru141ced82018-09-17 20:19:14 -0700101 self.extra_args = device.extra_args
Shad Ansarif9d2d102018-06-13 02:15:26 +0000102 self.log = structlog.get_logger(id=self.device_id,
103 ip=self.host_and_port)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400104 self.proxy = registry('core').get_proxy('/')
Shad Ansari2825d012018-02-22 23:57:46 +0000105
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800106 self.log.info('openolt-device-init')
107
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400108 # Device already set in the event of reconciliation
109 if not is_reconciliation:
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800110 self.log.info('updating-device')
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400111 # It is a new device
112 # Update device
113 device.root = True
Shad Ansari94250fc2018-07-04 06:52:11 +0000114 device.connect_status = ConnectStatus.UNREACHABLE
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400115 device.oper_status = OperStatus.ACTIVATING
116 self.adapter_agent.update_device(device)
Shad Ansari2825d012018-02-22 23:57:46 +0000117
Shad Ansaric4085df2019-02-13 16:47:07 -0800118 # If logical device does exist use it, else create one after connecting
119 # to device
Craig Lutgen109d4072018-12-11 17:01:16 -0600120 if device.parent_id:
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400121 # logical device already exists
122 self.logical_device_id = device.parent_id
123 if is_reconciliation:
124 self.adapter_agent.reconcile_logical_device(
125 self.logical_device_id)
Shad Ansaric4085df2019-02-13 16:47:07 -0800126 else:
127 self.logical_device_id = None
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400128
Shad Ansari94250fc2018-07-04 06:52:11 +0000129 # Initialize the OLT state machine
130 self.machine = Machine(model=self, states=OpenoltDevice.states,
131 transitions=OpenoltDevice.transitions,
132 send_event=True, initial='state_null')
Shad Ansaric4085df2019-02-13 16:47:07 -0800133
134 self.device_info = None
135
Shad Ansari94250fc2018-07-04 06:52:11 +0000136 self.go_state_init()
137
Craig Lutgen109d4072018-12-11 17:01:16 -0600138 def create_logical_device(self, device_info):
139 dpid = device_info.device_id
140 serial_number = device_info.device_serial_number
141
Shad Ansari25299be2019-02-13 22:02:39 -0800142 if dpid is None or dpid == '':
Craig Lutgen109d4072018-12-11 17:01:16 -0600143 uri = self.host_and_port.split(":")[0]
144 try:
145 socket.inet_pton(socket.AF_INET, uri)
146 dpid = '00:00:' + self.ip_hex(uri)
147 except socket.error:
148 # this is not an IP
Shad Ansari25299be2019-02-13 22:02:39 -0800149 dpid = self.string_to_mac(uri)
Craig Lutgen109d4072018-12-11 17:01:16 -0600150
Shad Ansari25299be2019-02-13 22:02:39 -0800151 if serial_number is None or serial_number == '':
Matt Jeanneretcc9f59b2018-12-17 15:58:20 -0500152 serial_number = self.host_and_port
153
Shad Ansari25299be2019-02-13 22:02:39 -0800154 self.log.info('creating-openolt-logical-device', dp_id=dpid,
155 serial_number=serial_number)
Craig Lutgen109d4072018-12-11 17:01:16 -0600156
Craig Lutgen109d4072018-12-11 17:01:16 -0600157 hw_desc = device_info.model
Shad Ansari25299be2019-02-13 22:02:39 -0800158 if device_info.hardware_version:
159 hw_desc += '-' + device_info.hardware_version
Craig Lutgen109d4072018-12-11 17:01:16 -0600160
161 # Create logical OF device
162 ld = LogicalDevice(
163 root_device_id=self.device_id,
164 switch_features=ofp_switch_features(
165 n_buffers=256, # TODO fake for now
166 n_tables=2, # TODO ditto
167 capabilities=( # TODO and ditto
168 OFPC_FLOW_STATS
169 | OFPC_TABLE_STATS
170 | OFPC_PORT_STATS
171 | OFPC_GROUP_STATS
172 )
173 ),
174 desc=ofp_desc(
Craig Lutgen109d4072018-12-11 17:01:16 -0600175 serial_num=serial_number
176 )
177 )
178 ld_init = self.adapter_agent.create_logical_device(ld,
179 dpid=dpid)
180
Craig Lutgen109d4072018-12-11 17:01:16 -0600181 device = self.adapter_agent.get_device(self.device_id)
182 device.serial_number = serial_number
183 self.adapter_agent.update_device(device)
184
Shad Ansari25299be2019-02-13 22:02:39 -0800185 self.log.info('created-openolt-logical-device',
186 logical_device_id=ld_init.id)
Craig Lutgen109d4072018-12-11 17:01:16 -0600187
Shad Ansaric4085df2019-02-13 16:47:07 -0800188 return ld_init.id
189
Shad Ansari25299be2019-02-13 22:02:39 -0800190 def string_to_mac(self, uri):
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800191 regex = re.compile('[^a-zA-Z]')
192 uri = regex.sub('', uri)
193
Shad Ansari25299be2019-02-13 22:02:39 -0800194 length = len(uri)
195 if length > 6:
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800196 uri = uri[0:6]
197 else:
Shad Ansari25299be2019-02-13 22:02:39 -0800198 uri = uri + uri[0:6 - length]
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800199
200 print uri
201
202 return ":".join([hex(ord(x))[-2:] for x in uri])
203
Shad Ansari94250fc2018-07-04 06:52:11 +0000204 def do_state_init(self, event):
Shad Ansari2825d012018-02-22 23:57:46 +0000205 # Initialize gRPC
206 self.channel = grpc.insecure_channel(self.host_and_port)
Shad Ansari8f1b2532018-04-21 07:51:39 +0000207 self.channel_ready_future = grpc.channel_ready_future(self.channel)
nick47b74372018-05-25 18:22:49 -0400208
Nicolas Palpacuer7183a3b2018-09-10 17:16:49 -0400209 self.log.info('openolt-device-created', device_id=self.device_id)
210
211 def post_init(self, event):
212 self.log.debug('post_init')
213
214 # We have reached init state, starting the indications thread
215
jasonhuang5f3e63b2018-07-27 01:32:48 +0800216 # Catch RuntimeError exception
217 try:
218 # Start indications thread
219 self.indications_thread_handle = threading.Thread(
220 target=self.indications_thread)
Shad Ansarif9521ad2018-09-08 10:46:43 +0000221 # Old getter/setter API for daemon; use it directly as a
jasonhuang5f3e63b2018-07-27 01:32:48 +0800222 # property instead. The Jinkins error will happon on the reason of
Shad Ansarif9521ad2018-09-08 10:46:43 +0000223 # Exception in thread Thread-1 (most likely raised # during
jasonhuang5f3e63b2018-07-27 01:32:48 +0800224 # interpreter shutdown)
225 self.indications_thread_handle.setDaemon(True)
226 self.indications_thread_handle.start()
Shad Ansarif9521ad2018-09-08 10:46:43 +0000227 except Exception as e:
Nicolas Palpacuer7183a3b2018-09-10 17:16:49 -0400228 self.log.exception('post_init failed', e=e)
Shad Ansari94250fc2018-07-04 06:52:11 +0000229
230 def do_state_connected(self, event):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400231 self.log.debug("do_state_connected")
232
Shad Ansarif34da592019-02-13 23:05:35 -0800233 # Check that device_info was successfully retrieved
234 assert(self.device_info is not None
235 and self.device_info.device_serial_number is not None
236 and self.device_info.device_serial_number != '')
237
Shad Ansari94250fc2018-07-04 06:52:11 +0000238 device = self.adapter_agent.get_device(self.device_id)
Shad Ansari94250fc2018-07-04 06:52:11 +0000239
Shad Ansaric4085df2019-02-13 16:47:07 -0800240 if self.logical_device_id is None:
241 # first time connect to olt
242 self.logical_device_id = self.create_logical_device(
243 self.device_info)
244 else:
245 # reconnect to olt (e.g. olt reboot)
246 # TODO - Update logical device with new device_info
247 pass
Craig Lutgen109d4072018-12-11 17:01:16 -0600248
Shad Ansarif34da592019-02-13 23:05:35 -0800249 device.serial_number = self.device_info.device_serial_number
Craig Lutgen109d4072018-12-11 17:01:16 -0600250
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700251 self.resource_mgr = self.resource_mgr_class(self.device_id,
Shad Ansari78de2be2018-10-12 22:13:54 +0000252 self.host_and_port,
253 self.extra_args,
Shad Ansaric4085df2019-02-13 16:47:07 -0800254 self.device_info)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000255 self.platform = self.platform_class(self.log, self.resource_mgr)
Girish Gowdruab836e92018-10-25 01:17:57 -0700256 self.flow_mgr = self.flow_mgr_class(self.adapter_agent, self.log,
257 self.stub, self.device_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000258 self.logical_device_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700259 self.platform, self.resource_mgr)
260
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000261 self.alarm_mgr = self.alarm_mgr_class(self.log, self.adapter_agent,
262 self.device_id,
263 self.logical_device_id,
264 self.platform)
265 self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform)
266 self.bw_mgr = self.bw_mgr_class(self.log, self.proxy)
267
Shad Ansaric4085df2019-02-13 16:47:07 -0800268 device.vendor = self.device_info.vendor
269 device.model = self.device_info.model
270 device.hardware_version = self.device_info.hardware_version
271 device.firmware_version = self.device_info.firmware_version
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700272
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700273 # TODO: check for uptime and reboot if too long (VOL-1192)
274
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400275 device.connect_status = ConnectStatus.REACHABLE
276 self.adapter_agent.update_device(device)
277
Shad Ansari94250fc2018-07-04 06:52:11 +0000278 def do_state_up(self, event):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400279 self.log.debug("do_state_up")
280
Shad Ansari94250fc2018-07-04 06:52:11 +0000281 device = self.adapter_agent.get_device(self.device_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000282
Shad Ansari94250fc2018-07-04 06:52:11 +0000283 # Update phys OF device
284 device.parent_id = self.logical_device_id
285 device.oper_status = OperStatus.ACTIVE
286 self.adapter_agent.update_device(device)
nick47b74372018-05-25 18:22:49 -0400287
Shad Ansari94250fc2018-07-04 06:52:11 +0000288 def do_state_down(self, event):
289 self.log.debug("do_state_down")
290 oper_state = OperStatus.UNKNOWN
291 connect_state = ConnectStatus.UNREACHABLE
Nicolas Palpacuerd35d9bb2018-06-20 17:06:31 -0400292
Shad Ansari94250fc2018-07-04 06:52:11 +0000293 # Propagating to the children
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400294
Shad Ansari94250fc2018-07-04 06:52:11 +0000295 # Children ports
296 child_devices = self.adapter_agent.get_child_devices(self.device_id)
297 for onu_device in child_devices:
Shad Ansari0e7ad962018-09-28 01:42:26 +0000298 onu_adapter_agent = \
299 registry('adapter_loader').get_agent(onu_device.adapter)
300 onu_adapter_agent.update_interface(onu_device,
301 {'oper_state': 'down'})
Craig Lutgenabd9c842018-11-15 23:58:27 +0000302 self.onu_ports_down(onu_device, oper_state)
303
Shad Ansari94250fc2018-07-04 06:52:11 +0000304 # Children devices
305 self.adapter_agent.update_child_devices_state(
306 self.device_id, oper_status=oper_state,
307 connect_status=connect_state)
308 # Device Ports
309 device_ports = self.adapter_agent.get_ports(self.device_id,
310 Port.ETHERNET_NNI)
311 logical_ports_ids = [port.label for port in device_ports]
312 device_ports += self.adapter_agent.get_ports(self.device_id,
313 Port.PON_OLT)
314
315 for port in device_ports:
316 port.oper_status = oper_state
317 self.adapter_agent.add_port(self.device_id, port)
318
319 # Device logical port
320 for logical_port_id in logical_ports_ids:
321 logical_port = self.adapter_agent.get_logical_port(
322 self.logical_device_id, logical_port_id)
323 logical_port.ofp_port.state = OFPPS_LINK_DOWN
324 self.adapter_agent.update_logical_port(self.logical_device_id,
325 logical_port)
326
327 # Device
328 device = self.adapter_agent.get_device(self.device_id)
329 device.oper_status = oper_state
330 device.connect_status = connect_state
331
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400332 reactor.callLater(2, self.adapter_agent.update_device, device)
333
334 # def post_up(self, event):
335 # self.log.debug('post-up')
336 # self.flow_mgr.reseed_flows()
337
338 def post_down(self, event):
339 self.log.debug('post_down')
340 self.flow_mgr.reset_flows()
341
Shad Ansari94250fc2018-07-04 06:52:11 +0000342 def indications_thread(self):
nick47b74372018-05-25 18:22:49 -0400343 self.log.debug('starting-indications-thread')
Shad Ansari94250fc2018-07-04 06:52:11 +0000344 self.log.debug('connecting to olt', device_id=self.device_id)
Shad Ansaric4085df2019-02-13 16:47:07 -0800345
346 self.stub = openolt_pb2_grpc.OpenoltStub(self.channel)
347
348 timeout = 60*60
349 delay = 1
350 exponential_back_off = False
351 while True:
352 try:
353 self.device_info = self.stub.GetDeviceInfo(openolt_pb2.Empty())
354 break
355 except Exception as e:
356 if delay > timeout:
357 self.log.error("timed out connecting to olt")
358 return
359 else:
360 self.log.warn("retry connecting to olt in %ds: %s"
361 % (delay, repr(e)))
362 time.sleep(delay)
363 if exponential_back_off:
364 delay += delay
365 else:
366 delay += 1
367
368 self.log.info('connected to olt', device_info=self.device_info)
369
Shad Ansari94250fc2018-07-04 06:52:11 +0000370 self.go_state_connected()
Shad Ansari2dda4f32018-05-17 07:16:07 +0000371
Shad Ansari15928d12018-04-17 02:42:13 +0000372 self.indications = self.stub.EnableIndication(openolt_pb2.Empty())
Shad Ansari2dda4f32018-05-17 07:16:07 +0000373
Shad Ansari94250fc2018-07-04 06:52:11 +0000374 while True:
nick47b74372018-05-25 18:22:49 -0400375 try:
376 # get the next indication from olt
377 ind = next(self.indications)
378 except Exception as e:
Shad Ansari94250fc2018-07-04 06:52:11 +0000379 self.log.warn('gRPC connection lost', error=e)
380 reactor.callFromThread(self.go_state_down)
381 reactor.callFromThread(self.go_state_init)
382 break
nick47b74372018-05-25 18:22:49 -0400383 else:
384 self.log.debug("rx indication", indication=ind)
Shad Ansari5dbc9c82018-05-10 03:29:31 +0000385
Shad Ansari7c73c1a2019-02-04 15:39:47 -0800386 if self.admin_state is "down":
387 if ind.HasField('intf_oper_ind') \
388 and (ind.intf_oper_ind.type == "nni"):
389 self.log.warn('olt is admin down, allow nni ind',
390 admin_state=self.admin_state,
391 indications=ind)
392 else:
393 self.log.warn('olt is admin down, ignore indication',
394 admin_state=self.admin_state,
395 indications=ind)
396 continue
397
nick47b74372018-05-25 18:22:49 -0400398 # indication handlers run in the main event loop
399 if ind.HasField('olt_ind'):
400 reactor.callFromThread(self.olt_indication, ind.olt_ind)
401 elif ind.HasField('intf_ind'):
402 reactor.callFromThread(self.intf_indication, ind.intf_ind)
403 elif ind.HasField('intf_oper_ind'):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000404 reactor.callFromThread(self.intf_oper_indication,
405 ind.intf_oper_ind)
nick47b74372018-05-25 18:22:49 -0400406 elif ind.HasField('onu_disc_ind'):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000407 reactor.callFromThread(self.onu_discovery_indication,
408 ind.onu_disc_ind)
nick47b74372018-05-25 18:22:49 -0400409 elif ind.HasField('onu_ind'):
410 reactor.callFromThread(self.onu_indication, ind.onu_ind)
411 elif ind.HasField('omci_ind'):
412 reactor.callFromThread(self.omci_indication, ind.omci_ind)
413 elif ind.HasField('pkt_ind'):
414 reactor.callFromThread(self.packet_indication, ind.pkt_ind)
Nicolas Palpacuer33f1a822018-06-13 12:36:36 -0400415 elif ind.HasField('port_stats'):
Nicolas Palpacuere761c902018-07-05 16:30:52 -0400416 reactor.callFromThread(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700417 self.stats_mgr.port_statistics_indication,
418 ind.port_stats)
Nicolas Palpacuer33f1a822018-06-13 12:36:36 -0400419 elif ind.HasField('flow_stats'):
Nicolas Palpacuere761c902018-07-05 16:30:52 -0400420 reactor.callFromThread(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700421 self.stats_mgr.flow_statistics_indication,
422 ind.flow_stats)
Shad Ansari905b8402018-07-03 00:04:50 +0000423 elif ind.HasField('alarm_ind'):
Nicolas Palpacuer16138de2018-07-03 14:35:18 -0400424 reactor.callFromThread(self.alarm_mgr.process_alarms,
425 ind.alarm_ind)
Nicolas Palpacuer33f1a822018-06-13 12:36:36 -0400426 else:
427 self.log.warn('unknown indication type')
nick47b74372018-05-25 18:22:49 -0400428
Shad Ansari2825d012018-02-22 23:57:46 +0000429 def olt_indication(self, olt_indication):
Shad Ansari7c73c1a2019-02-04 15:39:47 -0800430 '''
431 if self.admin_state is "up":
432 if olt_indication.oper_state == "up":
433 self.go_state_up()
434 elif olt_indication.oper_state == "down":
435 self.go_state_down()
436 '''
Shad Ansari22efe832018-05-19 05:37:03 +0000437 if olt_indication.oper_state == "up":
Shad Ansari94250fc2018-07-04 06:52:11 +0000438 self.go_state_up()
Shad Ansari22efe832018-05-19 05:37:03 +0000439 elif olt_indication.oper_state == "down":
Shad Ansari94250fc2018-07-04 06:52:11 +0000440 self.go_state_down()
Shad Ansari2825d012018-02-22 23:57:46 +0000441
442 def intf_indication(self, intf_indication):
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400443 self.log.debug("intf indication", intf_id=intf_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000444 oper_state=intf_indication.oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000445
446 if intf_indication.oper_state == "up":
447 oper_status = OperStatus.ACTIVE
448 else:
449 oper_status = OperStatus.DISCOVERED
450
nick47b74372018-05-25 18:22:49 -0400451 # add_port update the port if it exists
Shad Ansari2825d012018-02-22 23:57:46 +0000452 self.add_port(intf_indication.intf_id, Port.PON_OLT, oper_status)
453
454 def intf_oper_indication(self, intf_oper_indication):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000455 self.log.debug("Received interface oper state change indication",
456 intf_id=intf_oper_indication.intf_id,
457 type=intf_oper_indication.type,
458 oper_state=intf_oper_indication.oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000459
460 if intf_oper_indication.oper_state == "up":
461 oper_state = OperStatus.ACTIVE
462 else:
463 oper_state = OperStatus.DISCOVERED
464
465 if intf_oper_indication.type == "nni":
466
Nicolas Palpacuercf735ac2018-06-06 11:12:53 -0400467 # add_(logical_)port update the port if it exists
Shad Ansarif9d2d102018-06-13 02:15:26 +0000468 port_no, label = self.add_port(intf_oper_indication.intf_id,
469 Port.ETHERNET_NNI, oper_state)
Nicolas Palpacuercf735ac2018-06-06 11:12:53 -0400470 self.log.debug("int_oper_indication", port_no=port_no, label=label)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000471 self.add_logical_port(port_no, intf_oper_indication.intf_id,
472 oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000473
474 elif intf_oper_indication.type == "pon":
475 # FIXME - handle PON oper state change
476 pass
477
478 def onu_discovery_indication(self, onu_disc_indication):
Shad Ansari803900a2018-05-02 06:26:00 +0000479 intf_id = onu_disc_indication.intf_id
Shad Ansarif9d2d102018-06-13 02:15:26 +0000480 serial_number = onu_disc_indication.serial_number
Shad Ansari2825d012018-02-22 23:57:46 +0000481
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400482 serial_number_str = self.stringify_serial_number(serial_number)
Shad Ansari803900a2018-05-02 06:26:00 +0000483
Shad Ansarif9d2d102018-06-13 02:15:26 +0000484 self.log.debug("onu discovery indication", intf_id=intf_id,
485 serial_number=serial_number_str)
Nicolas Palpacuer36a93442018-05-23 17:38:57 -0400486
mzadig384783a2018-08-09 08:52:40 -0400487 # Post ONU Discover alarm 20180809_0805
488 try:
Nicolas Palpacuere9bf83c2018-08-16 14:53:14 -0400489 OnuDiscoveryAlarm(self.alarm_mgr.alarms, pon_id=intf_id,
490 serial_number=serial_number_str).raise_alarm()
mzadig384783a2018-08-09 08:52:40 -0400491 except Exception as disc_alarm_error:
Nicolas Palpacuere9bf83c2018-08-16 14:53:14 -0400492 self.log.exception("onu-discovery-alarm-error",
493 errmsg=disc_alarm_error.message)
mzadig384783a2018-08-09 08:52:40 -0400494 # continue for now.
495
Shad Ansarif9d2d102018-06-13 02:15:26 +0000496 onu_device = self.adapter_agent.get_child_device(
497 self.device_id,
498 serial_number=serial_number_str)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400499
500 if onu_device is None:
Shad Ansari15928d12018-04-17 02:42:13 +0000501 try:
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700502 onu_id = self.resource_mgr.get_onu_id(intf_id)
503 if onu_id is None:
504 raise Exception("onu-id-unavailable")
505
Shad Ansarif9d2d102018-06-13 02:15:26 +0000506 self.add_onu_device(
507 intf_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000508 self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT),
Shad Ansarif9d2d102018-06-13 02:15:26 +0000509 onu_id, serial_number)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400510 self.activate_onu(intf_id, onu_id, serial_number,
Girish Gowdruab836e92018-10-25 01:17:57 -0700511 serial_number_str)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400512 except Exception as e:
513 self.log.exception('onu-activation-failed', e=e)
514
Shad Ansari2825d012018-02-22 23:57:46 +0000515 else:
nick47b74372018-05-25 18:22:49 -0400516 if onu_device.connect_status != ConnectStatus.REACHABLE:
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700517 onu_device.connect_status = ConnectStatus.REACHABLE
518 self.adapter_agent.update_device(onu_device)
nick47b74372018-05-25 18:22:49 -0400519
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400520 onu_id = onu_device.proxy_address.onu_id
Shad Ansarif9d2d102018-06-13 02:15:26 +0000521 if onu_device.oper_status == OperStatus.DISCOVERED \
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700522 or onu_device.oper_status == OperStatus.ACTIVATING:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000523 self.log.debug("ignore onu discovery indication, \
524 the onu has been discovered and should be \
525 activating shorlty", intf_id=intf_id,
526 onu_id=onu_id, state=onu_device.oper_status)
527 elif onu_device.oper_status == OperStatus.ACTIVE:
528 self.log.warn("onu discovery indication whereas onu is \
529 supposed to be active",
530 intf_id=intf_id, onu_id=onu_id,
531 state=onu_device.oper_status)
nick47b74372018-05-25 18:22:49 -0400532 elif onu_device.oper_status == OperStatus.UNKNOWN:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000533 self.log.info("onu in unknown state, recovering from olt \
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400534 reboot probably, activate onu", intf_id=intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000535 onu_id=onu_id, serial_number=serial_number_str)
nick47b74372018-05-25 18:22:49 -0400536
537 onu_device.oper_status = OperStatus.DISCOVERED
538 self.adapter_agent.update_device(onu_device)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400539 try:
540 self.activate_onu(intf_id, onu_id, serial_number,
Girish Gowdruab836e92018-10-25 01:17:57 -0700541 serial_number_str)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400542 except Exception as e:
543 self.log.error('onu-activation-error',
544 serial_number=serial_number_str, error=e)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400545 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000546 self.log.warn('unexpected state', onu_id=onu_id,
547 onu_device_oper_state=onu_device.oper_status)
Shad Ansari2825d012018-02-22 23:57:46 +0000548
Shad Ansari2825d012018-02-22 23:57:46 +0000549 def onu_indication(self, onu_indication):
Shad Ansaria0b37892018-06-12 21:34:30 +0000550 self.log.debug("onu indication", intf_id=onu_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000551 onu_id=onu_indication.onu_id,
552 serial_number=onu_indication.serial_number,
553 oper_state=onu_indication.oper_state,
554 admin_state=onu_indication.admin_state)
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400555 try:
556 serial_number_str = self.stringify_serial_number(
557 onu_indication.serial_number)
Shad Ansari25299be2019-02-13 22:02:39 -0800558 except: # noqa: E722
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400559 serial_number_str = None
Shad Ansari94250fc2018-07-04 06:52:11 +0000560
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400561 if serial_number_str is not None:
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400562 onu_device = self.adapter_agent.get_child_device(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700563 self.device_id,
564 serial_number=serial_number_str)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000565 else:
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400566 onu_device = self.adapter_agent.get_child_device(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700567 self.device_id,
568 parent_port_no=self.platform.intf_id_to_port_no(
569 onu_indication.intf_id, Port.PON_OLT),
570 onu_id=onu_indication.onu_id)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400571
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400572 if onu_device is None:
Shad Ansaria0b37892018-06-12 21:34:30 +0000573 self.log.error('onu not found', intf_id=onu_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000574 onu_id=onu_indication.onu_id)
Shad Ansari803900a2018-05-02 06:26:00 +0000575 return
576
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000577 if self.platform.intf_id_from_pon_port_no(onu_device.parent_port_no) \
Shad Ansarif9521ad2018-09-08 10:46:43 +0000578 != onu_indication.intf_id:
Shad Ansari25299be2019-02-13 22:02:39 -0800579 self.log.warn(
580 'ONU-is-on-a-different-intf-id-now',
581 previous_intf_id=self.platform.intf_id_from_pon_port_no(
582 onu_device.parent_port_no),
583 current_intf_id=onu_indication.intf_id)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400584 # FIXME - handle intf_id mismatch (ONU move?)
Shad Ansari2825d012018-02-22 23:57:46 +0000585
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400586 if onu_device.proxy_address.onu_id != onu_indication.onu_id:
587 # FIXME - handle onu id mismatch
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400588 self.log.warn('ONU-id-mismatch, can happen if both voltha and '
589 'the olt rebooted',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000590 expected_onu_id=onu_device.proxy_address.onu_id,
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400591 received_onu_id=onu_indication.onu_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000592
Shad Ansarif9d2d102018-06-13 02:15:26 +0000593 # Admin state
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400594 if onu_indication.admin_state == 'down':
595 if onu_indication.oper_state != 'down':
Shad Ansarif9d2d102018-06-13 02:15:26 +0000596 self.log.error('ONU-admin-state-down-and-oper-status-not-down',
597 oper_state=onu_indication.oper_state)
598 # Forcing the oper state change code to execute
599 onu_indication.oper_state = 'down'
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400600
Shad Ansarif9d2d102018-06-13 02:15:26 +0000601 # Port and logical port update is taken care of by oper state block
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400602
603 elif onu_indication.admin_state == 'up':
Nicolas Palpacuer921f8cf2018-08-14 18:23:09 -0400604 pass
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400605
606 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000607 self.log.warn('Invalid-or-not-implemented-admin-state',
608 received_admin_state=onu_indication.admin_state)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400609
610 self.log.debug('admin-state-dealt-with')
611
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400612 onu_adapter_agent = \
613 registry('adapter_loader').get_agent(onu_device.adapter)
614 if onu_adapter_agent is None:
615 self.log.error('onu_adapter_agent-could-not-be-retrieved',
616 onu_device=onu_device)
617 return
618
Shad Ansarif9d2d102018-06-13 02:15:26 +0000619 # Operating state
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400620 if onu_indication.oper_state == 'down':
Nicolas Palpacuer4ea3a652018-08-22 10:33:17 -0400621
622 if onu_device.connect_status != ConnectStatus.UNREACHABLE:
623 onu_device.connect_status = ConnectStatus.UNREACHABLE
624 self.adapter_agent.update_device(onu_device)
625
Shad Ansarif9d2d102018-06-13 02:15:26 +0000626 # Move to discovered state
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400627 self.log.debug('onu-oper-state-is-down')
628
629 if onu_device.oper_status != OperStatus.DISCOVERED:
630 onu_device.oper_status = OperStatus.DISCOVERED
631 self.adapter_agent.update_device(onu_device)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000632 # Set port oper state to Discovered
Craig Lutgenabd9c842018-11-15 23:58:27 +0000633 self.onu_ports_down(onu_device, OperStatus.DISCOVERED)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400634
Shad Ansari0e7ad962018-09-28 01:42:26 +0000635 onu_adapter_agent.update_interface(onu_device,
636 {'oper_state': 'down'})
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400637
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400638 elif onu_indication.oper_state == 'up':
639
Nicolas Palpacuer2824a992018-08-20 18:07:41 -0400640 if onu_device.connect_status != ConnectStatus.REACHABLE:
641 onu_device.connect_status = ConnectStatus.REACHABLE
642 self.adapter_agent.update_device(onu_device)
643
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400644 if onu_device.oper_status != OperStatus.DISCOVERED:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000645 self.log.debug("ignore onu indication",
646 intf_id=onu_indication.intf_id,
647 onu_id=onu_indication.onu_id,
648 state=onu_device.oper_status,
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400649 msg_oper_state=onu_indication.oper_state)
650 return
651
Shad Ansarif9d2d102018-06-13 02:15:26 +0000652 # Device was in Discovered state, setting it to active
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400653
Shad Ansarif9d2d102018-06-13 02:15:26 +0000654 # Prepare onu configuration
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400655
Shad Ansari0e7ad962018-09-28 01:42:26 +0000656 onu_adapter_agent.create_interface(onu_device, onu_indication)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400657
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400658 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000659 self.log.warn('Not-implemented-or-invalid-value-of-oper-state',
660 oper_state=onu_indication.oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000661
Craig Lutgenabd9c842018-11-15 23:58:27 +0000662 def onu_ports_down(self, onu_device, oper_state):
nick47b74372018-05-25 18:22:49 -0400663 # Set port oper state to Discovered
664 # add port will update port if it exists
Craig Lutgenabd9c842018-11-15 23:58:27 +0000665 # self.adapter_agent.add_port(
666 # self.device_id,
667 # Port(
668 # port_no=uni_no,
669 # label=uni_name,
670 # type=Port.ETHERNET_UNI,
671 # admin_state=onu_device.admin_state,
672 # oper_status=oper_state))
673 # TODO this should be downning ports in onu adatper
nick47b74372018-05-25 18:22:49 -0400674
675 # Disable logical port
nick47b74372018-05-25 18:22:49 -0400676 onu_ports = self.proxy.get('devices/{}/ports'.format(onu_device.id))
nick47b74372018-05-25 18:22:49 -0400677 for onu_port in onu_ports:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000678 self.log.debug('onu-ports-down', onu_port=onu_port)
679 onu_port_id = onu_port.label
680 try:
681 onu_logical_port = self.adapter_agent.get_logical_port(
Shad Ansari25299be2019-02-13 22:02:39 -0800682 logical_device_id=self.logical_device_id,
683 port_id=onu_port_id)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000684 onu_logical_port.ofp_port.state = OFPPS_LINK_DOWN
685 self.adapter_agent.update_logical_port(
686 logical_device_id=self.logical_device_id,
687 port=onu_logical_port)
688 self.log.debug('cascading-oper-state-to-port-and-logical-port')
689 except KeyError as e:
690 self.log.error('matching-onu-port-label-invalid',
691 onu_id=onu_device.id, olt_id=self.device_id,
692 onu_ports=onu_ports, onu_port_id=onu_port_id,
693 error=e)
nick47b74372018-05-25 18:22:49 -0400694
Shad Ansari2825d012018-02-22 23:57:46 +0000695 def omci_indication(self, omci_indication):
696
697 self.log.debug("omci indication", intf_id=omci_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000698 onu_id=omci_indication.onu_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000699
Shad Ansarif9d2d102018-06-13 02:15:26 +0000700 onu_device = self.adapter_agent.get_child_device(
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400701 self.device_id, onu_id=omci_indication.onu_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000702 parent_port_no=self.platform.intf_id_to_port_no(
Girish Gowdru141ced82018-09-17 20:19:14 -0700703 omci_indication.intf_id, Port.PON_OLT), )
Shad Ansari0efa6512018-04-28 06:42:54 +0000704
705 self.adapter_agent.receive_proxied_message(onu_device.proxy_address,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000706 omci_indication.pkt)
Shad Ansari2825d012018-02-22 23:57:46 +0000707
Shad Ansari42db7342018-04-25 21:39:46 +0000708 def packet_indication(self, pkt_indication):
709
Shad Ansari0ff82622018-09-30 09:32:04 +0000710 self.log.debug("packet indication",
711 intf_type=pkt_indication.intf_type,
712 intf_id=pkt_indication.intf_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000713 port_no=pkt_indication.port_no,
714 cookie=pkt_indication.cookie,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000715 gemport_id=pkt_indication.gemport_id,
716 flow_id=pkt_indication.flow_id)
Shad Ansari42db7342018-04-25 21:39:46 +0000717
Shad Ansari0ff82622018-09-30 09:32:04 +0000718 if pkt_indication.intf_type == "pon":
Craig Lutgenabd9c842018-11-15 23:58:27 +0000719 if pkt_indication.port_no:
720 logical_port_num = pkt_indication.port_no
Shad Ansari25299be2019-02-13 22:02:39 -0800721 else:
722 # TODO Remove this else block after openolt device has been
723 # fully rolled out with cookie protobuf change
Craig Lutgenabd9c842018-11-15 23:58:27 +0000724 try:
Shad Ansari25299be2019-02-13 22:02:39 -0800725 onu_id_uni_id = self.resource_mgr. \
726 get_onu_uni_from_ponport_gemport(
727 pkt_indication.intf_id, pkt_indication.gemport_id)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000728 onu_id = int(onu_id_uni_id[0])
729 uni_id = int(onu_id_uni_id[1])
Shad Ansari25299be2019-02-13 22:02:39 -0800730 self.log.debug("packet indication-kv", onu_id=onu_id,
731 uni_id=uni_id)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000732 if onu_id is None:
733 raise Exception("onu-id-none")
734 if uni_id is None:
735 raise Exception("uni-id-none")
Shad Ansari25299be2019-02-13 22:02:39 -0800736 logical_port_num = self.platform.mk_uni_port_num(
737 pkt_indication.intf_id, onu_id, uni_id)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000738 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
Shad Ansari0ff82622018-09-30 09:32:04 +0000743 elif pkt_indication.intf_type == "nni":
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000744 logical_port_num = self.platform.intf_id_to_port_no(
Shad Ansari0ff82622018-09-30 09:32:04 +0000745 pkt_indication.intf_id,
746 Port.ETHERNET_NNI)
Shad Ansari42db7342018-04-25 21:39:46 +0000747
748 pkt = Ether(pkt_indication.pkt)
Shad Ansari0ff82622018-09-30 09:32:04 +0000749
750 self.log.debug("packet indication",
751 logical_device_id=self.logical_device_id,
752 logical_port_no=logical_port_num)
753
754 self.adapter_agent.send_packet_in(
755 logical_device_id=self.logical_device_id,
756 logical_port_no=logical_port_num,
757 packet=str(pkt))
Shad Ansari42db7342018-04-25 21:39:46 +0000758
759 def packet_out(self, egress_port, msg):
Shad Ansari0346f0d2018-04-26 06:54:09 +0000760 pkt = Ether(msg)
Saurav Dasf87d6552018-09-26 17:05:42 -0700761 self.log.debug('packet out', egress_port=egress_port,
762 device_id=self.device_id,
763 logical_device_id=self.logical_device_id,
764 packet=str(pkt).encode("HEX"))
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400765
766 # Find port type
Craig Lutgenabd9c842018-11-15 23:58:27 +0000767 egress_port_type = self.platform.intf_id_to_port_type_name(egress_port)
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400768 if egress_port_type == Port.ETHERNET_UNI:
769
770 if pkt.haslayer(Dot1Q):
771 outer_shim = pkt.getlayer(Dot1Q)
772 if isinstance(outer_shim.payload, Dot1Q):
773 # If double tag, remove the outer tag
774 payload = (
Shad Ansari25299be2019-02-13 22:02:39 -0800775 Ether(src=pkt.src, dst=pkt.dst,
776 type=outer_shim.type) /
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700777 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,
Shad Ansari25299be2019-02-13 22:02:39 -0800852 admin_state=AdminState.ENABLED
Craig Lutgenabd9c842018-11-15 23:58:27 +0000853 )
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)