blob: 0b8ec621f772a86c5dc3cfbafc582bc8cb251680 [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
Shad Ansari25299be2019-02-13 22:02:39 -0800108 # default device id and device serial number. If device_info provides
109 # better results, they will be updated
Craig Lutgen109d4072018-12-11 17:01:16 -0600110 self.dpid = kwargs.get('dp_id')
111 self.serial_number = self.host_and_port # FIXME
112
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400113 # Device already set in the event of reconciliation
114 if not is_reconciliation:
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800115 self.log.info('updating-device')
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400116 # It is a new device
117 # Update device
118 device.root = True
Shad Ansari94250fc2018-07-04 06:52:11 +0000119 device.connect_status = ConnectStatus.UNREACHABLE
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400120 device.oper_status = OperStatus.ACTIVATING
121 self.adapter_agent.update_device(device)
Shad Ansari2825d012018-02-22 23:57:46 +0000122
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800123 self.logical_device_id = None
Shad Ansaric4085df2019-02-13 16:47:07 -0800124 # If logical device does exist use it, else create one after connecting
125 # to device
Craig Lutgen109d4072018-12-11 17:01:16 -0600126 if device.parent_id:
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400127 # logical device already exists
128 self.logical_device_id = device.parent_id
129 if is_reconciliation:
130 self.adapter_agent.reconcile_logical_device(
131 self.logical_device_id)
Shad Ansaric4085df2019-02-13 16:47:07 -0800132 else:
133 self.logical_device_id = None
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400134
Shad Ansari94250fc2018-07-04 06:52:11 +0000135 # Initialize the OLT state machine
136 self.machine = Machine(model=self, states=OpenoltDevice.states,
137 transitions=OpenoltDevice.transitions,
138 send_event=True, initial='state_null')
Shad Ansaric4085df2019-02-13 16:47:07 -0800139
140 self.device_info = None
141
Shad Ansari94250fc2018-07-04 06:52:11 +0000142 self.go_state_init()
143
Craig Lutgen109d4072018-12-11 17:01:16 -0600144 def create_logical_device(self, device_info):
145 dpid = device_info.device_id
146 serial_number = device_info.device_serial_number
147
Shad Ansari25299be2019-02-13 22:02:39 -0800148 if dpid is None:
149 dpid = self.dpid
150 if serial_number is None:
151 serial_number = self.serial_number
Craig Lutgen109d4072018-12-11 17:01:16 -0600152
Shad Ansari25299be2019-02-13 22:02:39 -0800153 if dpid is None or dpid == '':
Craig Lutgen109d4072018-12-11 17:01:16 -0600154 uri = self.host_and_port.split(":")[0]
155 try:
156 socket.inet_pton(socket.AF_INET, uri)
157 dpid = '00:00:' + self.ip_hex(uri)
158 except socket.error:
159 # this is not an IP
Shad Ansari25299be2019-02-13 22:02:39 -0800160 dpid = self.string_to_mac(uri)
Craig Lutgen109d4072018-12-11 17:01:16 -0600161
Shad Ansari25299be2019-02-13 22:02:39 -0800162 if serial_number is None or serial_number == '':
Matt Jeanneretcc9f59b2018-12-17 15:58:20 -0500163 serial_number = self.host_and_port
164
Shad Ansari25299be2019-02-13 22:02:39 -0800165 self.log.info('creating-openolt-logical-device', dp_id=dpid,
166 serial_number=serial_number)
Craig Lutgen109d4072018-12-11 17:01:16 -0600167
Craig Lutgen109d4072018-12-11 17:01:16 -0600168 hw_desc = device_info.model
Shad Ansari25299be2019-02-13 22:02:39 -0800169 if device_info.hardware_version:
170 hw_desc += '-' + device_info.hardware_version
Craig Lutgen109d4072018-12-11 17:01:16 -0600171
172 # Create logical OF device
173 ld = LogicalDevice(
174 root_device_id=self.device_id,
175 switch_features=ofp_switch_features(
176 n_buffers=256, # TODO fake for now
177 n_tables=2, # TODO ditto
178 capabilities=( # TODO and ditto
179 OFPC_FLOW_STATS
180 | OFPC_TABLE_STATS
181 | OFPC_PORT_STATS
182 | OFPC_GROUP_STATS
183 )
184 ),
185 desc=ofp_desc(
Craig Lutgen109d4072018-12-11 17:01:16 -0600186 serial_num=serial_number
187 )
188 )
189 ld_init = self.adapter_agent.create_logical_device(ld,
190 dpid=dpid)
191
Craig Lutgen109d4072018-12-11 17:01:16 -0600192 device = self.adapter_agent.get_device(self.device_id)
193 device.serial_number = serial_number
194 self.adapter_agent.update_device(device)
195
196 self.dpid = dpid
197 self.serial_number = serial_number
198
Shad Ansari25299be2019-02-13 22:02:39 -0800199 self.log.info('created-openolt-logical-device',
200 logical_device_id=ld_init.id)
Craig Lutgen109d4072018-12-11 17:01:16 -0600201
Shad Ansaric4085df2019-02-13 16:47:07 -0800202 return ld_init.id
203
Shad Ansari25299be2019-02-13 22:02:39 -0800204 def string_to_mac(self, uri):
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800205 regex = re.compile('[^a-zA-Z]')
206 uri = regex.sub('', uri)
207
Shad Ansari25299be2019-02-13 22:02:39 -0800208 length = len(uri)
209 if length > 6:
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800210 uri = uri[0:6]
211 else:
Shad Ansari25299be2019-02-13 22:02:39 -0800212 uri = uri + uri[0:6 - length]
Matteo Scandolobf5ae0c2018-11-15 18:12:54 -0800213
214 print uri
215
216 return ":".join([hex(ord(x))[-2:] for x in uri])
217
Shad Ansari94250fc2018-07-04 06:52:11 +0000218 def do_state_init(self, event):
Shad Ansari2825d012018-02-22 23:57:46 +0000219 # Initialize gRPC
220 self.channel = grpc.insecure_channel(self.host_and_port)
Shad Ansari8f1b2532018-04-21 07:51:39 +0000221 self.channel_ready_future = grpc.channel_ready_future(self.channel)
nick47b74372018-05-25 18:22:49 -0400222
Nicolas Palpacuer7183a3b2018-09-10 17:16:49 -0400223 self.log.info('openolt-device-created', device_id=self.device_id)
224
225 def post_init(self, event):
226 self.log.debug('post_init')
227
228 # We have reached init state, starting the indications thread
229
jasonhuang5f3e63b2018-07-27 01:32:48 +0800230 # Catch RuntimeError exception
231 try:
232 # Start indications thread
233 self.indications_thread_handle = threading.Thread(
234 target=self.indications_thread)
Shad Ansarif9521ad2018-09-08 10:46:43 +0000235 # Old getter/setter API for daemon; use it directly as a
jasonhuang5f3e63b2018-07-27 01:32:48 +0800236 # property instead. The Jinkins error will happon on the reason of
Shad Ansarif9521ad2018-09-08 10:46:43 +0000237 # Exception in thread Thread-1 (most likely raised # during
jasonhuang5f3e63b2018-07-27 01:32:48 +0800238 # interpreter shutdown)
239 self.indications_thread_handle.setDaemon(True)
240 self.indications_thread_handle.start()
Shad Ansarif9521ad2018-09-08 10:46:43 +0000241 except Exception as e:
Nicolas Palpacuer7183a3b2018-09-10 17:16:49 -0400242 self.log.exception('post_init failed', e=e)
Shad Ansari94250fc2018-07-04 06:52:11 +0000243
244 def do_state_connected(self, event):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400245 self.log.debug("do_state_connected")
246
Shad Ansari94250fc2018-07-04 06:52:11 +0000247 device = self.adapter_agent.get_device(self.device_id)
Shad Ansari94250fc2018-07-04 06:52:11 +0000248
Shad Ansaric4085df2019-02-13 16:47:07 -0800249 if self.logical_device_id is None:
250 # first time connect to olt
251 self.logical_device_id = self.create_logical_device(
252 self.device_info)
253 else:
254 # reconnect to olt (e.g. olt reboot)
255 # TODO - Update logical device with new device_info
256 pass
Craig Lutgen109d4072018-12-11 17:01:16 -0600257
258 device.serial_number = self.serial_number
259
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700260 self.resource_mgr = self.resource_mgr_class(self.device_id,
Shad Ansari78de2be2018-10-12 22:13:54 +0000261 self.host_and_port,
262 self.extra_args,
Shad Ansaric4085df2019-02-13 16:47:07 -0800263 self.device_info)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000264 self.platform = self.platform_class(self.log, self.resource_mgr)
Girish Gowdruab836e92018-10-25 01:17:57 -0700265 self.flow_mgr = self.flow_mgr_class(self.adapter_agent, self.log,
266 self.stub, self.device_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000267 self.logical_device_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700268 self.platform, self.resource_mgr)
269
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000270 self.alarm_mgr = self.alarm_mgr_class(self.log, self.adapter_agent,
271 self.device_id,
272 self.logical_device_id,
273 self.platform)
274 self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform)
275 self.bw_mgr = self.bw_mgr_class(self.log, self.proxy)
276
Shad Ansaric4085df2019-02-13 16:47:07 -0800277 device.vendor = self.device_info.vendor
278 device.model = self.device_info.model
279 device.hardware_version = self.device_info.hardware_version
280 device.firmware_version = self.device_info.firmware_version
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700281
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700282 # TODO: check for uptime and reboot if too long (VOL-1192)
283
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400284 device.connect_status = ConnectStatus.REACHABLE
285 self.adapter_agent.update_device(device)
286
Shad Ansari94250fc2018-07-04 06:52:11 +0000287 def do_state_up(self, event):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400288 self.log.debug("do_state_up")
289
Shad Ansari94250fc2018-07-04 06:52:11 +0000290 device = self.adapter_agent.get_device(self.device_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000291
Shad Ansari94250fc2018-07-04 06:52:11 +0000292 # Update phys OF device
293 device.parent_id = self.logical_device_id
294 device.oper_status = OperStatus.ACTIVE
295 self.adapter_agent.update_device(device)
nick47b74372018-05-25 18:22:49 -0400296
Shad Ansari94250fc2018-07-04 06:52:11 +0000297 def do_state_down(self, event):
298 self.log.debug("do_state_down")
299 oper_state = OperStatus.UNKNOWN
300 connect_state = ConnectStatus.UNREACHABLE
Nicolas Palpacuerd35d9bb2018-06-20 17:06:31 -0400301
Shad Ansari94250fc2018-07-04 06:52:11 +0000302 # Propagating to the children
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400303
Shad Ansari94250fc2018-07-04 06:52:11 +0000304 # Children ports
305 child_devices = self.adapter_agent.get_child_devices(self.device_id)
306 for onu_device in child_devices:
Shad Ansari0e7ad962018-09-28 01:42:26 +0000307 onu_adapter_agent = \
308 registry('adapter_loader').get_agent(onu_device.adapter)
309 onu_adapter_agent.update_interface(onu_device,
310 {'oper_state': 'down'})
Craig Lutgenabd9c842018-11-15 23:58:27 +0000311 self.onu_ports_down(onu_device, oper_state)
312
Shad Ansari94250fc2018-07-04 06:52:11 +0000313 # Children devices
314 self.adapter_agent.update_child_devices_state(
315 self.device_id, oper_status=oper_state,
316 connect_status=connect_state)
317 # Device Ports
318 device_ports = self.adapter_agent.get_ports(self.device_id,
319 Port.ETHERNET_NNI)
320 logical_ports_ids = [port.label for port in device_ports]
321 device_ports += self.adapter_agent.get_ports(self.device_id,
322 Port.PON_OLT)
323
324 for port in device_ports:
325 port.oper_status = oper_state
326 self.adapter_agent.add_port(self.device_id, port)
327
328 # Device logical port
329 for logical_port_id in logical_ports_ids:
330 logical_port = self.adapter_agent.get_logical_port(
331 self.logical_device_id, logical_port_id)
332 logical_port.ofp_port.state = OFPPS_LINK_DOWN
333 self.adapter_agent.update_logical_port(self.logical_device_id,
334 logical_port)
335
336 # Device
337 device = self.adapter_agent.get_device(self.device_id)
338 device.oper_status = oper_state
339 device.connect_status = connect_state
340
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400341 reactor.callLater(2, self.adapter_agent.update_device, device)
342
343 # def post_up(self, event):
344 # self.log.debug('post-up')
345 # self.flow_mgr.reseed_flows()
346
347 def post_down(self, event):
348 self.log.debug('post_down')
349 self.flow_mgr.reset_flows()
350
Shad Ansari94250fc2018-07-04 06:52:11 +0000351 def indications_thread(self):
nick47b74372018-05-25 18:22:49 -0400352 self.log.debug('starting-indications-thread')
Shad Ansari94250fc2018-07-04 06:52:11 +0000353 self.log.debug('connecting to olt', device_id=self.device_id)
Shad Ansaric4085df2019-02-13 16:47:07 -0800354
355 self.stub = openolt_pb2_grpc.OpenoltStub(self.channel)
356
357 timeout = 60*60
358 delay = 1
359 exponential_back_off = False
360 while True:
361 try:
362 self.device_info = self.stub.GetDeviceInfo(openolt_pb2.Empty())
363 break
364 except Exception as e:
365 if delay > timeout:
366 self.log.error("timed out connecting to olt")
367 return
368 else:
369 self.log.warn("retry connecting to olt in %ds: %s"
370 % (delay, repr(e)))
371 time.sleep(delay)
372 if exponential_back_off:
373 delay += delay
374 else:
375 delay += 1
376
377 self.log.info('connected to olt', device_info=self.device_info)
378
Shad Ansari94250fc2018-07-04 06:52:11 +0000379 self.go_state_connected()
Shad Ansari2dda4f32018-05-17 07:16:07 +0000380
Shad Ansari15928d12018-04-17 02:42:13 +0000381 self.indications = self.stub.EnableIndication(openolt_pb2.Empty())
Shad Ansari2dda4f32018-05-17 07:16:07 +0000382
Shad Ansari94250fc2018-07-04 06:52:11 +0000383 while True:
nick47b74372018-05-25 18:22:49 -0400384 try:
385 # get the next indication from olt
386 ind = next(self.indications)
387 except Exception as e:
Shad Ansari94250fc2018-07-04 06:52:11 +0000388 self.log.warn('gRPC connection lost', error=e)
389 reactor.callFromThread(self.go_state_down)
390 reactor.callFromThread(self.go_state_init)
391 break
nick47b74372018-05-25 18:22:49 -0400392 else:
393 self.log.debug("rx indication", indication=ind)
Shad Ansari5dbc9c82018-05-10 03:29:31 +0000394
Shad Ansari7c73c1a2019-02-04 15:39:47 -0800395 if self.admin_state is "down":
396 if ind.HasField('intf_oper_ind') \
397 and (ind.intf_oper_ind.type == "nni"):
398 self.log.warn('olt is admin down, allow nni ind',
399 admin_state=self.admin_state,
400 indications=ind)
401 else:
402 self.log.warn('olt is admin down, ignore indication',
403 admin_state=self.admin_state,
404 indications=ind)
405 continue
406
nick47b74372018-05-25 18:22:49 -0400407 # indication handlers run in the main event loop
408 if ind.HasField('olt_ind'):
409 reactor.callFromThread(self.olt_indication, ind.olt_ind)
410 elif ind.HasField('intf_ind'):
411 reactor.callFromThread(self.intf_indication, ind.intf_ind)
412 elif ind.HasField('intf_oper_ind'):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000413 reactor.callFromThread(self.intf_oper_indication,
414 ind.intf_oper_ind)
nick47b74372018-05-25 18:22:49 -0400415 elif ind.HasField('onu_disc_ind'):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000416 reactor.callFromThread(self.onu_discovery_indication,
417 ind.onu_disc_ind)
nick47b74372018-05-25 18:22:49 -0400418 elif ind.HasField('onu_ind'):
419 reactor.callFromThread(self.onu_indication, ind.onu_ind)
420 elif ind.HasField('omci_ind'):
421 reactor.callFromThread(self.omci_indication, ind.omci_ind)
422 elif ind.HasField('pkt_ind'):
423 reactor.callFromThread(self.packet_indication, ind.pkt_ind)
Nicolas Palpacuer33f1a822018-06-13 12:36:36 -0400424 elif ind.HasField('port_stats'):
Nicolas Palpacuere761c902018-07-05 16:30:52 -0400425 reactor.callFromThread(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700426 self.stats_mgr.port_statistics_indication,
427 ind.port_stats)
Nicolas Palpacuer33f1a822018-06-13 12:36:36 -0400428 elif ind.HasField('flow_stats'):
Nicolas Palpacuere761c902018-07-05 16:30:52 -0400429 reactor.callFromThread(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700430 self.stats_mgr.flow_statistics_indication,
431 ind.flow_stats)
Shad Ansari905b8402018-07-03 00:04:50 +0000432 elif ind.HasField('alarm_ind'):
Nicolas Palpacuer16138de2018-07-03 14:35:18 -0400433 reactor.callFromThread(self.alarm_mgr.process_alarms,
434 ind.alarm_ind)
Nicolas Palpacuer33f1a822018-06-13 12:36:36 -0400435 else:
436 self.log.warn('unknown indication type')
nick47b74372018-05-25 18:22:49 -0400437
Shad Ansari2825d012018-02-22 23:57:46 +0000438 def olt_indication(self, olt_indication):
Shad Ansari7c73c1a2019-02-04 15:39:47 -0800439 '''
440 if self.admin_state is "up":
441 if olt_indication.oper_state == "up":
442 self.go_state_up()
443 elif olt_indication.oper_state == "down":
444 self.go_state_down()
445 '''
Shad Ansari22efe832018-05-19 05:37:03 +0000446 if olt_indication.oper_state == "up":
Shad Ansari94250fc2018-07-04 06:52:11 +0000447 self.go_state_up()
Shad Ansari22efe832018-05-19 05:37:03 +0000448 elif olt_indication.oper_state == "down":
Shad Ansari94250fc2018-07-04 06:52:11 +0000449 self.go_state_down()
Shad Ansari2825d012018-02-22 23:57:46 +0000450
451 def intf_indication(self, intf_indication):
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400452 self.log.debug("intf indication", intf_id=intf_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000453 oper_state=intf_indication.oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000454
455 if intf_indication.oper_state == "up":
456 oper_status = OperStatus.ACTIVE
457 else:
458 oper_status = OperStatus.DISCOVERED
459
nick47b74372018-05-25 18:22:49 -0400460 # add_port update the port if it exists
Shad Ansari2825d012018-02-22 23:57:46 +0000461 self.add_port(intf_indication.intf_id, Port.PON_OLT, oper_status)
462
463 def intf_oper_indication(self, intf_oper_indication):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000464 self.log.debug("Received interface oper state change indication",
465 intf_id=intf_oper_indication.intf_id,
466 type=intf_oper_indication.type,
467 oper_state=intf_oper_indication.oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000468
469 if intf_oper_indication.oper_state == "up":
470 oper_state = OperStatus.ACTIVE
471 else:
472 oper_state = OperStatus.DISCOVERED
473
474 if intf_oper_indication.type == "nni":
475
Nicolas Palpacuercf735ac2018-06-06 11:12:53 -0400476 # add_(logical_)port update the port if it exists
Shad Ansarif9d2d102018-06-13 02:15:26 +0000477 port_no, label = self.add_port(intf_oper_indication.intf_id,
478 Port.ETHERNET_NNI, oper_state)
Nicolas Palpacuercf735ac2018-06-06 11:12:53 -0400479 self.log.debug("int_oper_indication", port_no=port_no, label=label)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000480 self.add_logical_port(port_no, intf_oper_indication.intf_id,
481 oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000482
483 elif intf_oper_indication.type == "pon":
484 # FIXME - handle PON oper state change
485 pass
486
487 def onu_discovery_indication(self, onu_disc_indication):
Shad Ansari803900a2018-05-02 06:26:00 +0000488 intf_id = onu_disc_indication.intf_id
Shad Ansarif9d2d102018-06-13 02:15:26 +0000489 serial_number = onu_disc_indication.serial_number
Shad Ansari2825d012018-02-22 23:57:46 +0000490
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400491 serial_number_str = self.stringify_serial_number(serial_number)
Shad Ansari803900a2018-05-02 06:26:00 +0000492
Shad Ansarif9d2d102018-06-13 02:15:26 +0000493 self.log.debug("onu discovery indication", intf_id=intf_id,
494 serial_number=serial_number_str)
Nicolas Palpacuer36a93442018-05-23 17:38:57 -0400495
mzadig384783a2018-08-09 08:52:40 -0400496 # Post ONU Discover alarm 20180809_0805
497 try:
Nicolas Palpacuere9bf83c2018-08-16 14:53:14 -0400498 OnuDiscoveryAlarm(self.alarm_mgr.alarms, pon_id=intf_id,
499 serial_number=serial_number_str).raise_alarm()
mzadig384783a2018-08-09 08:52:40 -0400500 except Exception as disc_alarm_error:
Nicolas Palpacuere9bf83c2018-08-16 14:53:14 -0400501 self.log.exception("onu-discovery-alarm-error",
502 errmsg=disc_alarm_error.message)
mzadig384783a2018-08-09 08:52:40 -0400503 # continue for now.
504
Shad Ansarif9d2d102018-06-13 02:15:26 +0000505 onu_device = self.adapter_agent.get_child_device(
506 self.device_id,
507 serial_number=serial_number_str)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400508
509 if onu_device is None:
Shad Ansari15928d12018-04-17 02:42:13 +0000510 try:
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700511 onu_id = self.resource_mgr.get_onu_id(intf_id)
512 if onu_id is None:
513 raise Exception("onu-id-unavailable")
514
Shad Ansarif9d2d102018-06-13 02:15:26 +0000515 self.add_onu_device(
516 intf_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000517 self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT),
Shad Ansarif9d2d102018-06-13 02:15:26 +0000518 onu_id, serial_number)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400519 self.activate_onu(intf_id, onu_id, serial_number,
Girish Gowdruab836e92018-10-25 01:17:57 -0700520 serial_number_str)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400521 except Exception as e:
522 self.log.exception('onu-activation-failed', e=e)
523
Shad Ansari2825d012018-02-22 23:57:46 +0000524 else:
nick47b74372018-05-25 18:22:49 -0400525 if onu_device.connect_status != ConnectStatus.REACHABLE:
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700526 onu_device.connect_status = ConnectStatus.REACHABLE
527 self.adapter_agent.update_device(onu_device)
nick47b74372018-05-25 18:22:49 -0400528
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400529 onu_id = onu_device.proxy_address.onu_id
Shad Ansarif9d2d102018-06-13 02:15:26 +0000530 if onu_device.oper_status == OperStatus.DISCOVERED \
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700531 or onu_device.oper_status == OperStatus.ACTIVATING:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000532 self.log.debug("ignore onu discovery indication, \
533 the onu has been discovered and should be \
534 activating shorlty", intf_id=intf_id,
535 onu_id=onu_id, state=onu_device.oper_status)
536 elif onu_device.oper_status == OperStatus.ACTIVE:
537 self.log.warn("onu discovery indication whereas onu is \
538 supposed to be active",
539 intf_id=intf_id, onu_id=onu_id,
540 state=onu_device.oper_status)
nick47b74372018-05-25 18:22:49 -0400541 elif onu_device.oper_status == OperStatus.UNKNOWN:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000542 self.log.info("onu in unknown state, recovering from olt \
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400543 reboot probably, activate onu", intf_id=intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000544 onu_id=onu_id, serial_number=serial_number_str)
nick47b74372018-05-25 18:22:49 -0400545
546 onu_device.oper_status = OperStatus.DISCOVERED
547 self.adapter_agent.update_device(onu_device)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400548 try:
549 self.activate_onu(intf_id, onu_id, serial_number,
Girish Gowdruab836e92018-10-25 01:17:57 -0700550 serial_number_str)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400551 except Exception as e:
552 self.log.error('onu-activation-error',
553 serial_number=serial_number_str, error=e)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400554 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000555 self.log.warn('unexpected state', onu_id=onu_id,
556 onu_device_oper_state=onu_device.oper_status)
Shad Ansari2825d012018-02-22 23:57:46 +0000557
Shad Ansari2825d012018-02-22 23:57:46 +0000558 def onu_indication(self, onu_indication):
Shad Ansaria0b37892018-06-12 21:34:30 +0000559 self.log.debug("onu indication", intf_id=onu_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000560 onu_id=onu_indication.onu_id,
561 serial_number=onu_indication.serial_number,
562 oper_state=onu_indication.oper_state,
563 admin_state=onu_indication.admin_state)
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400564 try:
565 serial_number_str = self.stringify_serial_number(
566 onu_indication.serial_number)
Shad Ansari25299be2019-02-13 22:02:39 -0800567 except: # noqa: E722
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400568 serial_number_str = None
Shad Ansari94250fc2018-07-04 06:52:11 +0000569
Nicolas Palpacuer28cc2662018-06-22 16:30:18 -0400570 if serial_number_str is not None:
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400571 onu_device = self.adapter_agent.get_child_device(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700572 self.device_id,
573 serial_number=serial_number_str)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000574 else:
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400575 onu_device = self.adapter_agent.get_child_device(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700576 self.device_id,
577 parent_port_no=self.platform.intf_id_to_port_no(
578 onu_indication.intf_id, Port.PON_OLT),
579 onu_id=onu_indication.onu_id)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400580
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400581 if onu_device is None:
Shad Ansaria0b37892018-06-12 21:34:30 +0000582 self.log.error('onu not found', intf_id=onu_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000583 onu_id=onu_indication.onu_id)
Shad Ansari803900a2018-05-02 06:26:00 +0000584 return
585
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000586 if self.platform.intf_id_from_pon_port_no(onu_device.parent_port_no) \
Shad Ansarif9521ad2018-09-08 10:46:43 +0000587 != onu_indication.intf_id:
Shad Ansari25299be2019-02-13 22:02:39 -0800588 self.log.warn(
589 'ONU-is-on-a-different-intf-id-now',
590 previous_intf_id=self.platform.intf_id_from_pon_port_no(
591 onu_device.parent_port_no),
592 current_intf_id=onu_indication.intf_id)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400593 # FIXME - handle intf_id mismatch (ONU move?)
Shad Ansari2825d012018-02-22 23:57:46 +0000594
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400595 if onu_device.proxy_address.onu_id != onu_indication.onu_id:
596 # FIXME - handle onu id mismatch
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400597 self.log.warn('ONU-id-mismatch, can happen if both voltha and '
598 'the olt rebooted',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000599 expected_onu_id=onu_device.proxy_address.onu_id,
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400600 received_onu_id=onu_indication.onu_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000601
Shad Ansarif9d2d102018-06-13 02:15:26 +0000602 # Admin state
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400603 if onu_indication.admin_state == 'down':
604 if onu_indication.oper_state != 'down':
Shad Ansarif9d2d102018-06-13 02:15:26 +0000605 self.log.error('ONU-admin-state-down-and-oper-status-not-down',
606 oper_state=onu_indication.oper_state)
607 # Forcing the oper state change code to execute
608 onu_indication.oper_state = 'down'
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400609
Shad Ansarif9d2d102018-06-13 02:15:26 +0000610 # Port and logical port update is taken care of by oper state block
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400611
612 elif onu_indication.admin_state == 'up':
Nicolas Palpacuer921f8cf2018-08-14 18:23:09 -0400613 pass
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400614
615 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000616 self.log.warn('Invalid-or-not-implemented-admin-state',
617 received_admin_state=onu_indication.admin_state)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400618
619 self.log.debug('admin-state-dealt-with')
620
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400621 onu_adapter_agent = \
622 registry('adapter_loader').get_agent(onu_device.adapter)
623 if onu_adapter_agent is None:
624 self.log.error('onu_adapter_agent-could-not-be-retrieved',
625 onu_device=onu_device)
626 return
627
Shad Ansarif9d2d102018-06-13 02:15:26 +0000628 # Operating state
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400629 if onu_indication.oper_state == 'down':
Nicolas Palpacuer4ea3a652018-08-22 10:33:17 -0400630
631 if onu_device.connect_status != ConnectStatus.UNREACHABLE:
632 onu_device.connect_status = ConnectStatus.UNREACHABLE
633 self.adapter_agent.update_device(onu_device)
634
Shad Ansarif9d2d102018-06-13 02:15:26 +0000635 # Move to discovered state
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400636 self.log.debug('onu-oper-state-is-down')
637
638 if onu_device.oper_status != OperStatus.DISCOVERED:
639 onu_device.oper_status = OperStatus.DISCOVERED
640 self.adapter_agent.update_device(onu_device)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000641 # Set port oper state to Discovered
Craig Lutgenabd9c842018-11-15 23:58:27 +0000642 self.onu_ports_down(onu_device, OperStatus.DISCOVERED)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400643
Shad Ansari0e7ad962018-09-28 01:42:26 +0000644 onu_adapter_agent.update_interface(onu_device,
645 {'oper_state': 'down'})
Matt Jeanneret12cd5d02018-08-07 15:30:19 -0400646
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400647 elif onu_indication.oper_state == 'up':
648
Nicolas Palpacuer2824a992018-08-20 18:07:41 -0400649 if onu_device.connect_status != ConnectStatus.REACHABLE:
650 onu_device.connect_status = ConnectStatus.REACHABLE
651 self.adapter_agent.update_device(onu_device)
652
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400653 if onu_device.oper_status != OperStatus.DISCOVERED:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000654 self.log.debug("ignore onu indication",
655 intf_id=onu_indication.intf_id,
656 onu_id=onu_indication.onu_id,
657 state=onu_device.oper_status,
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400658 msg_oper_state=onu_indication.oper_state)
659 return
660
Shad Ansarif9d2d102018-06-13 02:15:26 +0000661 # Device was in Discovered state, setting it to active
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400662
Shad Ansarif9d2d102018-06-13 02:15:26 +0000663 # Prepare onu configuration
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400664
Shad Ansari0e7ad962018-09-28 01:42:26 +0000665 onu_adapter_agent.create_interface(onu_device, onu_indication)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400666
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400667 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000668 self.log.warn('Not-implemented-or-invalid-value-of-oper-state',
669 oper_state=onu_indication.oper_state)
Shad Ansari2825d012018-02-22 23:57:46 +0000670
Craig Lutgenabd9c842018-11-15 23:58:27 +0000671 def onu_ports_down(self, onu_device, oper_state):
nick47b74372018-05-25 18:22:49 -0400672 # Set port oper state to Discovered
673 # add port will update port if it exists
Craig Lutgenabd9c842018-11-15 23:58:27 +0000674 # self.adapter_agent.add_port(
675 # self.device_id,
676 # Port(
677 # port_no=uni_no,
678 # label=uni_name,
679 # type=Port.ETHERNET_UNI,
680 # admin_state=onu_device.admin_state,
681 # oper_status=oper_state))
682 # TODO this should be downning ports in onu adatper
nick47b74372018-05-25 18:22:49 -0400683
684 # Disable logical port
nick47b74372018-05-25 18:22:49 -0400685 onu_ports = self.proxy.get('devices/{}/ports'.format(onu_device.id))
nick47b74372018-05-25 18:22:49 -0400686 for onu_port in onu_ports:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000687 self.log.debug('onu-ports-down', onu_port=onu_port)
688 onu_port_id = onu_port.label
689 try:
690 onu_logical_port = self.adapter_agent.get_logical_port(
Shad Ansari25299be2019-02-13 22:02:39 -0800691 logical_device_id=self.logical_device_id,
692 port_id=onu_port_id)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000693 onu_logical_port.ofp_port.state = OFPPS_LINK_DOWN
694 self.adapter_agent.update_logical_port(
695 logical_device_id=self.logical_device_id,
696 port=onu_logical_port)
697 self.log.debug('cascading-oper-state-to-port-and-logical-port')
698 except KeyError as e:
699 self.log.error('matching-onu-port-label-invalid',
700 onu_id=onu_device.id, olt_id=self.device_id,
701 onu_ports=onu_ports, onu_port_id=onu_port_id,
702 error=e)
nick47b74372018-05-25 18:22:49 -0400703
Shad Ansari2825d012018-02-22 23:57:46 +0000704 def omci_indication(self, omci_indication):
705
706 self.log.debug("omci indication", intf_id=omci_indication.intf_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000707 onu_id=omci_indication.onu_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000708
Shad Ansarif9d2d102018-06-13 02:15:26 +0000709 onu_device = self.adapter_agent.get_child_device(
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400710 self.device_id, onu_id=omci_indication.onu_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000711 parent_port_no=self.platform.intf_id_to_port_no(
Girish Gowdru141ced82018-09-17 20:19:14 -0700712 omci_indication.intf_id, Port.PON_OLT), )
Shad Ansari0efa6512018-04-28 06:42:54 +0000713
714 self.adapter_agent.receive_proxied_message(onu_device.proxy_address,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000715 omci_indication.pkt)
Shad Ansari2825d012018-02-22 23:57:46 +0000716
Shad Ansari42db7342018-04-25 21:39:46 +0000717 def packet_indication(self, pkt_indication):
718
Shad Ansari0ff82622018-09-30 09:32:04 +0000719 self.log.debug("packet indication",
720 intf_type=pkt_indication.intf_type,
721 intf_id=pkt_indication.intf_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000722 port_no=pkt_indication.port_no,
723 cookie=pkt_indication.cookie,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000724 gemport_id=pkt_indication.gemport_id,
725 flow_id=pkt_indication.flow_id)
Shad Ansari42db7342018-04-25 21:39:46 +0000726
Shad Ansari0ff82622018-09-30 09:32:04 +0000727 if pkt_indication.intf_type == "pon":
Craig Lutgenabd9c842018-11-15 23:58:27 +0000728 if pkt_indication.port_no:
729 logical_port_num = pkt_indication.port_no
Shad Ansari25299be2019-02-13 22:02:39 -0800730 else:
731 # TODO Remove this else block after openolt device has been
732 # fully rolled out with cookie protobuf change
Craig Lutgenabd9c842018-11-15 23:58:27 +0000733 try:
Shad Ansari25299be2019-02-13 22:02:39 -0800734 onu_id_uni_id = self.resource_mgr. \
735 get_onu_uni_from_ponport_gemport(
736 pkt_indication.intf_id, pkt_indication.gemport_id)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000737 onu_id = int(onu_id_uni_id[0])
738 uni_id = int(onu_id_uni_id[1])
Shad Ansari25299be2019-02-13 22:02:39 -0800739 self.log.debug("packet indication-kv", onu_id=onu_id,
740 uni_id=uni_id)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000741 if onu_id is None:
742 raise Exception("onu-id-none")
743 if uni_id is None:
744 raise Exception("uni-id-none")
Shad Ansari25299be2019-02-13 22:02:39 -0800745 logical_port_num = self.platform.mk_uni_port_num(
746 pkt_indication.intf_id, onu_id, uni_id)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000747 except Exception as e:
748 self.log.error("no-onu-reference-for-gem",
749 gemport_id=pkt_indication.gemport_id, e=e)
750 return
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700751
Shad Ansari0ff82622018-09-30 09:32:04 +0000752 elif pkt_indication.intf_type == "nni":
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000753 logical_port_num = self.platform.intf_id_to_port_no(
Shad Ansari0ff82622018-09-30 09:32:04 +0000754 pkt_indication.intf_id,
755 Port.ETHERNET_NNI)
Shad Ansari42db7342018-04-25 21:39:46 +0000756
757 pkt = Ether(pkt_indication.pkt)
Shad Ansari0ff82622018-09-30 09:32:04 +0000758
759 self.log.debug("packet indication",
760 logical_device_id=self.logical_device_id,
761 logical_port_no=logical_port_num)
762
763 self.adapter_agent.send_packet_in(
764 logical_device_id=self.logical_device_id,
765 logical_port_no=logical_port_num,
766 packet=str(pkt))
Shad Ansari42db7342018-04-25 21:39:46 +0000767
768 def packet_out(self, egress_port, msg):
Shad Ansari0346f0d2018-04-26 06:54:09 +0000769 pkt = Ether(msg)
Saurav Dasf87d6552018-09-26 17:05:42 -0700770 self.log.debug('packet out', egress_port=egress_port,
771 device_id=self.device_id,
772 logical_device_id=self.logical_device_id,
773 packet=str(pkt).encode("HEX"))
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400774
775 # Find port type
Craig Lutgenabd9c842018-11-15 23:58:27 +0000776 egress_port_type = self.platform.intf_id_to_port_type_name(egress_port)
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400777 if egress_port_type == Port.ETHERNET_UNI:
778
779 if pkt.haslayer(Dot1Q):
780 outer_shim = pkt.getlayer(Dot1Q)
781 if isinstance(outer_shim.payload, Dot1Q):
782 # If double tag, remove the outer tag
783 payload = (
Shad Ansari25299be2019-02-13 22:02:39 -0800784 Ether(src=pkt.src, dst=pkt.dst,
785 type=outer_shim.type) /
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700786 outer_shim.payload
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400787 )
788 else:
789 payload = pkt
Shad Ansari0346f0d2018-04-26 06:54:09 +0000790 else:
791 payload = pkt
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400792
793 send_pkt = binascii.unhexlify(str(payload).encode("HEX"))
794
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400795 self.log.debug(
Shad Ansarif9d2d102018-06-13 02:15:26 +0000796 'sending-packet-to-ONU', egress_port=egress_port,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000797 intf_id=self.platform.intf_id_from_uni_port_num(egress_port),
798 onu_id=self.platform.onu_id_from_port_num(egress_port),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000799 uni_id=self.platform.uni_id_from_port_num(egress_port),
800 port_no=egress_port,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000801 packet=str(payload).encode("HEX"))
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400802
Shad Ansarif9d2d102018-06-13 02:15:26 +0000803 onu_pkt = openolt_pb2.OnuPacket(
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000804 intf_id=self.platform.intf_id_from_uni_port_num(egress_port),
805 onu_id=self.platform.onu_id_from_port_num(egress_port),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000806 port_no=egress_port,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000807 pkt=send_pkt)
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400808
809 self.stub.OnuPacketOut(onu_pkt)
810
811 elif egress_port_type == Port.ETHERNET_NNI:
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400812 self.log.debug('sending-packet-to-uplink', egress_port=egress_port,
Shad Ansarif9521ad2018-09-08 10:46:43 +0000813 packet=str(pkt).encode("HEX"))
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400814
815 send_pkt = binascii.unhexlify(str(pkt).encode("HEX"))
816
Shad Ansarif9d2d102018-06-13 02:15:26 +0000817 uplink_pkt = openolt_pb2.UplinkPacket(
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000818 intf_id=self.platform.intf_id_from_nni_port_num(egress_port),
Shad Ansarif9d2d102018-06-13 02:15:26 +0000819 pkt=send_pkt)
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400820
821 self.stub.UplinkPacketOut(uplink_pkt)
822
Shad Ansari0346f0d2018-04-26 06:54:09 +0000823 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000824 self.log.warn('Packet-out-to-this-interface-type-not-implemented',
825 egress_port=egress_port,
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400826 port_type=egress_port_type)
Shad Ansari42db7342018-04-25 21:39:46 +0000827
Shad Ansari2825d012018-02-22 23:57:46 +0000828 def send_proxied_message(self, proxy_address, msg):
Shad Ansarif9521ad2018-09-08 10:46:43 +0000829 onu_device = self.adapter_agent.get_child_device(
Girish Gowdru141ced82018-09-17 20:19:14 -0700830 self.device_id, onu_id=proxy_address.onu_id,
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000831 parent_port_no=self.platform.intf_id_to_port_no(
Girish Gowdru141ced82018-09-17 20:19:14 -0700832 proxy_address.channel_id, Port.PON_OLT)
833 )
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400834 if onu_device.connect_status != ConnectStatus.REACHABLE:
835 self.log.debug('ONU is not reachable, cannot send OMCI',
836 serial_number=onu_device.serial_number,
837 intf_id=onu_device.proxy_address.channel_id,
838 onu_id=onu_device.proxy_address.onu_id)
839 return
Shad Ansarif9d2d102018-06-13 02:15:26 +0000840 omci = openolt_pb2.OmciMsg(intf_id=proxy_address.channel_id,
841 onu_id=proxy_address.onu_id, pkt=str(msg))
Shad Ansari2825d012018-02-22 23:57:46 +0000842 self.stub.OmciMsgOut(omci)
843
844 def add_onu_device(self, intf_id, port_no, onu_id, serial_number):
Shad Ansari2825d012018-02-22 23:57:46 +0000845 self.log.info("Adding ONU", port_no=port_no, onu_id=onu_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000846 serial_number=serial_number)
Shad Ansari2825d012018-02-22 23:57:46 +0000847
848 # NOTE - channel_id of onu is set to intf_id
Shad Ansari0efa6512018-04-28 06:42:54 +0000849 proxy_address = Device.ProxyAddress(device_id=self.device_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000850 channel_id=intf_id, onu_id=onu_id,
851 onu_session_id=onu_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000852
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400853 self.log.debug("Adding ONU", proxy_address=proxy_address)
Shad Ansari2825d012018-02-22 23:57:46 +0000854
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400855 serial_number_str = self.stringify_serial_number(serial_number)
Shad Ansari2825d012018-02-22 23:57:46 +0000856
Shad Ansarif9d2d102018-06-13 02:15:26 +0000857 self.adapter_agent.add_onu_device(
858 parent_device_id=self.device_id, parent_port_no=port_no,
859 vendor_id=serial_number.vendor_id, proxy_address=proxy_address,
860 root=True, serial_number=serial_number_str,
Shad Ansari25299be2019-02-13 22:02:39 -0800861 admin_state=AdminState.ENABLED
Craig Lutgenabd9c842018-11-15 23:58:27 +0000862 )
Shad Ansari2825d012018-02-22 23:57:46 +0000863
Shad Ansari1fd9eb22018-05-15 05:13:49 +0000864 def port_name(self, port_no, port_type, intf_id=None, serial_number=None):
Shad Ansari2825d012018-02-22 23:57:46 +0000865 if port_type is Port.ETHERNET_NNI:
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400866 return "nni-" + str(port_no)
Shad Ansari2825d012018-02-22 23:57:46 +0000867 elif port_type is Port.PON_OLT:
Shad Ansari4a232ca2018-05-05 05:24:17 +0000868 return "pon" + str(intf_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000869 elif port_type is Port.ETHERNET_UNI:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000870 assert False, 'local UNI management not supported'
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400871
Nicolas Palpacuercf735ac2018-06-06 11:12:53 -0400872 def add_logical_port(self, port_no, intf_id, oper_state):
Shad Ansari2825d012018-02-22 23:57:46 +0000873 self.log.info('adding-logical-port', port_no=port_no)
874
875 label = self.port_name(port_no, Port.ETHERNET_NNI)
876
877 cap = OFPPF_1GB_FD | OFPPF_FIBER
878 curr_speed = OFPPF_1GB_FD
879 max_speed = OFPPF_1GB_FD
880
Nicolas Palpacuercf735ac2018-06-06 11:12:53 -0400881 if oper_state == OperStatus.ACTIVE:
882 of_oper_state = OFPPS_LIVE
883 else:
884 of_oper_state = OFPPS_LINK_DOWN
885
Shad Ansarif9d2d102018-06-13 02:15:26 +0000886 ofp = ofp_port(
887 port_no=port_no,
Nicolas Palpacuer5780e152018-09-05 17:25:42 -0400888 hw_addr=mac_str_to_tuple(self._get_mac_form_port_no(port_no)),
Shad Ansarif9d2d102018-06-13 02:15:26 +0000889 name=label, config=0, state=of_oper_state, curr=cap,
890 advertised=cap, peer=cap, curr_speed=curr_speed,
891 max_speed=max_speed)
Shad Ansari2825d012018-02-22 23:57:46 +0000892
Nicolas Palpacuere7359fc2018-06-15 14:10:48 -0400893 ofp_stats = ofp_port_stats(port_no=port_no)
894
Shad Ansarif9d2d102018-06-13 02:15:26 +0000895 logical_port = LogicalPort(
896 id=label, ofp_port=ofp, device_id=self.device_id,
Nicolas Palpacuere7359fc2018-06-15 14:10:48 -0400897 device_port_no=port_no, root_port=True,
898 ofp_port_stats=ofp_stats)
Shad Ansari2825d012018-02-22 23:57:46 +0000899
Shad Ansarif9d2d102018-06-13 02:15:26 +0000900 self.adapter_agent.add_logical_port(self.logical_device_id,
901 logical_port)
Shad Ansari2825d012018-02-22 23:57:46 +0000902
Nicolas Palpacuer5780e152018-09-05 17:25:42 -0400903 def _get_mac_form_port_no(self, port_no):
904 mac = ''
905 for i in range(4):
906 mac = ':%02x' % ((port_no >> (i * 8)) & 0xff) + mac
907 return '00:00' + mac
908
Shad Ansari2825d012018-02-22 23:57:46 +0000909 def add_port(self, intf_id, port_type, oper_status):
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000910 port_no = self.platform.intf_id_to_port_no(intf_id, port_type)
Shad Ansari2825d012018-02-22 23:57:46 +0000911
Shad Ansari4a232ca2018-05-05 05:24:17 +0000912 label = self.port_name(port_no, port_type, intf_id)
Shad Ansari2825d012018-02-22 23:57:46 +0000913
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400914 self.log.debug('adding-port', port_no=port_no, label=label,
Shad Ansarif9521ad2018-09-08 10:46:43 +0000915 port_type=port_type)
Shad Ansari0efa6512018-04-28 06:42:54 +0000916
917 port = Port(port_no=port_no, label=label, type=port_type,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000918 admin_state=AdminState.ENABLED, oper_status=oper_status)
Shad Ansari0efa6512018-04-28 06:42:54 +0000919
Shad Ansari2825d012018-02-22 23:57:46 +0000920 self.adapter_agent.add_port(self.device_id, port)
Shad Ansari0efa6512018-04-28 06:42:54 +0000921
Shad Ansari2825d012018-02-22 23:57:46 +0000922 return port_no, label
923
Girish Gowdruab836e92018-10-25 01:17:57 -0700924 def delete_logical_port(self, child_device):
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -0400925 logical_ports = self.proxy.get('/logical_devices/{}/ports'.format(
926 self.logical_device_id))
927 for logical_port in logical_ports:
Girish Gowdruab836e92018-10-25 01:17:57 -0700928 if logical_port.device_id == child_device.id:
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -0400929 self.log.debug('delete-logical-port',
Girish Gowdruab836e92018-10-25 01:17:57 -0700930 onu_device_id=child_device.id,
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -0400931 logical_port=logical_port)
Girish Gowdruab836e92018-10-25 01:17:57 -0700932 self.flow_mgr.clear_flows_and_scheduler_for_logical_port(
933 child_device, logical_port)
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -0400934 self.adapter_agent.delete_logical_port(
935 self.logical_device_id, logical_port)
936 return
Shad Ansarif9521ad2018-09-08 10:46:43 +0000937
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -0400938 def delete_port(self, child_serial_number):
939 ports = self.proxy.get('/devices/{}/ports'.format(
940 self.device_id))
941 for port in ports:
942 if port.label == child_serial_number:
943 self.log.debug('delete-port',
944 onu_serial_number=child_serial_number,
945 port=port)
946 self.adapter_agent.delete_port(self.device_id, port)
947 return
948
Shad Ansari2825d012018-02-22 23:57:46 +0000949 def update_flow_table(self, flows):
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400950 self.log.debug('No updates here now, all is done in logical flows '
951 'update')
Shad Ansari5df91f62018-07-25 23:59:46 +0000952
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400953 def update_logical_flows(self, flows_to_add, flows_to_remove,
954 device_rules_map):
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400955 if not self.is_state_up():
956 self.log.info('The OLT is not up, we cannot update flows',
957 flows_to_add=[f.id for f in flows_to_add],
958 flows_to_remove=[f.id for f in flows_to_remove])
959 return
960
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400961 try:
962 self.flow_mgr.update_children_flows(device_rules_map)
963 except Exception as e:
964 self.log.error('Error updating children flows', error=e)
Shad Ansari2825d012018-02-22 23:57:46 +0000965
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400966 self.log.debug('logical flows update', flows_to_add=flows_to_add,
Shad Ansarif9521ad2018-09-08 10:46:43 +0000967 flows_to_remove=flows_to_remove)
Shad Ansari2825d012018-02-22 23:57:46 +0000968
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400969 for flow in flows_to_add:
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400970
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400971 try:
972 self.flow_mgr.add_flow(flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400973 except Exception as e:
974 self.log.error('failed to add flow', flow=flow, e=e)
975
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400976 for flow in flows_to_remove:
977
978 try:
979 self.flow_mgr.remove_flow(flow)
980 except Exception as e:
981 self.log.error('failed to remove flow', flow=flow, e=e)
982
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400983 self.flow_mgr.repush_all_different_flows()
984
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400985 # There has to be a better way to do this
Shad Ansari89b09d52018-05-21 07:28:14 +0000986 def ip_hex(self, ip):
987 octets = ip.split(".")
988 hex_ip = []
989 for octet in octets:
990 octet_hex = hex(int(octet))
991 octet_hex = octet_hex.split('0x')[1]
992 octet_hex = octet_hex.rjust(2, '0')
993 hex_ip.append(octet_hex)
994 return ":".join(hex_ip)
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -0400995
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400996 def stringify_vendor_specific(self, vendor_specific):
997 return ''.join(str(i) for i in [
998 hex(ord(vendor_specific[0]) >> 4 & 0x0f)[2:],
999 hex(ord(vendor_specific[0]) & 0x0f)[2:],
1000 hex(ord(vendor_specific[1]) >> 4 & 0x0f)[2:],
1001 hex(ord(vendor_specific[1]) & 0x0f)[2:],
1002 hex(ord(vendor_specific[2]) >> 4 & 0x0f)[2:],
1003 hex(ord(vendor_specific[2]) & 0x0f)[2:],
1004 hex(ord(vendor_specific[3]) >> 4 & 0x0f)[2:],
1005 hex(ord(vendor_specific[3]) & 0x0f)[2:]])
1006
Nicolas Palpacuer65de6a42018-05-22 17:28:29 -04001007 def stringify_serial_number(self, serial_number):
1008 return ''.join([serial_number.vendor_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +00001009 self.stringify_vendor_specific(
1010 serial_number.vendor_specific)])
Jonathan Davis0f917a22018-05-30 14:39:45 -04001011
Nicolas Palpacuer131790b2018-08-20 09:59:34 -04001012 def destringify_serial_number(self, serial_number_str):
1013 serial_number = openolt_pb2.SerialNumber(
1014 vendor_id=serial_number_str[:4].encode('utf-8'),
1015 vendor_specific=binascii.unhexlify(serial_number_str[4:]))
1016 return serial_number
1017
Jonathan Davis0f917a22018-05-30 14:39:45 -04001018 def disable(self):
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001019 self.log.debug('sending-deactivate-olt-message',
Shad Ansarif9521ad2018-09-08 10:46:43 +00001020 device_id=self.device_id)
Jonathan Davis0f917a22018-05-30 14:39:45 -04001021
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001022 try:
1023 # Send grpc call
1024 self.stub.DisableOlt(openolt_pb2.Empty())
Shad Ansari7c73c1a2019-02-04 15:39:47 -08001025 self.admin_state = "down"
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001026 self.log.info('openolt device disabled')
1027 except Exception as e:
1028 self.log.error('Failure to disable openolt device', error=e)
Jonathan Davis0f917a22018-05-30 14:39:45 -04001029
Jonathan Davis0f917a22018-05-30 14:39:45 -04001030 def delete(self):
Nicolas Palpacuer0d44e682018-08-06 10:30:26 -04001031 self.log.info('deleting-olt', device_id=self.device_id,
1032 logical_device_id=self.logical_device_id)
1033
Girish Gowdru1e77ea02018-09-24 09:10:35 -07001034 # Clears up the data from the resource manager KV store
1035 # for the device
1036 del self.resource_mgr
1037
Nicolas Palpacuer0d44e682018-08-06 10:30:26 -04001038 try:
1039 # Rebooting to reset the state
1040 self.reboot()
1041 # Removing logical device
Saurav Dasf87d6552018-09-26 17:05:42 -07001042 ld = self.adapter_agent.get_logical_device(self.logical_device_id)
1043 self.adapter_agent.delete_logical_device(ld)
Nicolas Palpacuer0d44e682018-08-06 10:30:26 -04001044 except Exception as e:
1045 self.log.error('Failure to delete openolt device', error=e)
1046 raise e
1047 else:
1048 self.log.info('successfully-deleted-olt', device_id=self.device_id)
Jonathan Davis0f917a22018-05-30 14:39:45 -04001049
Jonathan Davis0f917a22018-05-30 14:39:45 -04001050 def reenable(self):
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001051 self.log.debug('reenabling-olt', device_id=self.device_id)
Jonathan Davis0f917a22018-05-30 14:39:45 -04001052
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001053 try:
1054 self.stub.ReenableOlt(openolt_pb2.Empty())
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001055 except Exception as e:
1056 self.log.error('Failure to reenable openolt device', error=e)
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -04001057 else:
1058 self.log.info('openolt device reenabled')
Shad Ansari7c73c1a2019-02-04 15:39:47 -08001059 self.admin_state = "up"
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -04001060
Nicolas Palpacuer131790b2018-08-20 09:59:34 -04001061 def activate_onu(self, intf_id, onu_id, serial_number,
Girish Gowdruab836e92018-10-25 01:17:57 -07001062 serial_number_str):
Nicolas Palpacuer131790b2018-08-20 09:59:34 -04001063 pir = self.bw_mgr.pir(serial_number_str)
1064 self.log.debug("activating-onu", intf_id=intf_id, onu_id=onu_id,
Shad Ansarif9521ad2018-09-08 10:46:43 +00001065 serial_number_str=serial_number_str,
Girish Gowdruab836e92018-10-25 01:17:57 -07001066 serial_number=serial_number, pir=pir)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -04001067 onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id,
Girish Gowdruab836e92018-10-25 01:17:57 -07001068 serial_number=serial_number, pir=pir)
Nicolas Palpacuer131790b2018-08-20 09:59:34 -04001069 self.stub.ActivateOnu(onu)
1070 self.log.info('onu-activated', serial_number=serial_number_str)
Nicolas Palpacuer62dbb9c2018-08-02 15:03:35 -04001071
Jonathan Davisb45bb372018-07-19 15:05:15 -04001072 def delete_child_device(self, child_device):
1073 self.log.debug('sending-deactivate-onu',
1074 olt_device_id=self.device_id,
1075 onu_device=child_device,
1076 onu_serial_number=child_device.serial_number)
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -04001077 try:
1078 self.adapter_agent.delete_child_device(self.device_id,
Shad Ansarif9521ad2018-09-08 10:46:43 +00001079 child_device.id,
1080 child_device)
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -04001081 except Exception as e:
1082 self.log.error('adapter_agent error', error=e)
1083 try:
Girish Gowdruab836e92018-10-25 01:17:57 -07001084 self.delete_logical_port(child_device)
Nicolas Palpacuer3bd62092018-08-15 09:42:53 -04001085 except Exception as e:
1086 self.log.error('logical_port delete error', error=e)
1087 try:
1088 self.delete_port(child_device.serial_number)
1089 except Exception as e:
1090 self.log.error('port delete error', error=e)
Shad Ansarif9521ad2018-09-08 10:46:43 +00001091 serial_number = self.destringify_serial_number(
1092 child_device.serial_number)
Craig Lutgenabd9c842018-11-15 23:58:27 +00001093 # TODO FIXME - For each uni.
1094 # TODO FIXME - Flows are not deleted
1095 uni_id = 0 # FIXME
Girish Gowdrub761bc12018-11-29 02:22:18 -08001096 self.flow_mgr.delete_tech_profile_instance(
1097 child_device.proxy_address.channel_id,
1098 child_device.proxy_address.onu_id,
1099 uni_id
1100 )
Girish Gowdru1e77ea02018-09-24 09:10:35 -07001101 pon_intf_id_onu_id = (child_device.proxy_address.channel_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +00001102 child_device.proxy_address.onu_id,
1103 uni_id)
Girish Gowdru1e77ea02018-09-24 09:10:35 -07001104 # Free any PON resources that were reserved for the ONU
1105 self.resource_mgr.free_pon_resources_for_onu(pon_intf_id_onu_id)
1106
Jonathan Davisb45bb372018-07-19 15:05:15 -04001107 onu = openolt_pb2.Onu(intf_id=child_device.proxy_address.channel_id,
1108 onu_id=child_device.proxy_address.onu_id,
Girish Gowdrub761bc12018-11-29 02:22:18 -08001109 serial_number=serial_number)
Shad Ansari3cd9bf22018-07-25 19:29:39 +00001110 self.stub.DeleteOnu(onu)
Nicolas Palpacuerfd365ac2018-08-02 11:37:37 -04001111
1112 def reboot(self):
Shad Ansarif9521ad2018-09-08 10:46:43 +00001113 self.log.debug('rebooting openolt device', device_id=self.device_id)
Nicolas Palpacuerfd365ac2018-08-02 11:37:37 -04001114 try:
1115 self.stub.Reboot(openolt_pb2.Empty())
1116 except Exception as e:
1117 self.log.error('something went wrong with the reboot', error=e)
1118 else:
1119 self.log.info('device rebooted')
1120
Nicolas Palpacuer30027f42018-09-06 15:55:54 -04001121 def trigger_statistics_collection(self):
1122 try:
1123 self.stub.CollectStatistics(openolt_pb2.Empty())
1124 except Exception as e:
1125 self.log.error('Error while triggering statistics collection',
1126 error=e)
1127 else:
1128 self.log.info('statistics requested')
Scott Bakerd3190952018-09-04 15:47:28 -07001129
1130 def simulate_alarm(self, alarm):
1131 self.alarm_mgr.simulate_alarm(alarm)