blob: 06a07d1d56a6fbc8aa3410d5a8b9208f8483d322 [file] [log] [blame]
William Kurkian6f436d02019-02-06 16:25:01 -05001#
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#
16import threading
17import binascii
18import grpc
19import socket
20import re
21import structlog
William Kurkianfefd4642019-02-07 15:30:03 -050022import time
William Kurkian6f436d02019-02-06 16:25:01 -050023from twisted.internet import reactor
William Kurkian92bd7122019-02-14 15:26:59 -050024from twisted.internet.defer import inlineCallbacks, returnValue
William Kurkian6f436d02019-02-06 16:25:01 -050025from scapy.layers.l2 import Ether, Dot1Q
26from transitions import Machine
27
William Kurkian44cd7bb2019-02-11 16:39:12 -050028from pyvoltha.protos import openolt_pb2_grpc, openolt_pb2
William Kurkian6f436d02019-02-06 16:25:01 -050029
William Kurkian44cd7bb2019-02-11 16:39:12 -050030from pyvoltha.adapters.extensions.alarms.onu.onu_discovery_alarm import OnuDiscoveryAlarm
William Kurkian6f436d02019-02-06 16:25:01 -050031
William Kurkian44cd7bb2019-02-11 16:39:12 -050032from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
33from pyvoltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \
William Kurkian6f436d02019-02-06 16:25:01 -050034 OFPPS_LINK_DOWN, OFPPF_1GB_FD, \
35 OFPC_GROUP_STATS, OFPC_PORT_STATS, OFPC_TABLE_STATS, OFPC_FLOW_STATS, \
36 ofp_switch_features, ofp_port, ofp_port_stats, ofp_desc
William Kurkian44cd7bb2019-02-11 16:39:12 -050037from pyvoltha.common.utils.registry import registry
38from pyvoltha.protos import third_party
39from pyvoltha.protos.common_pb2 import AdminState, OperStatus, ConnectStatus
40from pyvoltha.protos.common_pb2 import LogLevel
41from pyvoltha.protos.device_pb2 import Port, Device
William Kurkian6f436d02019-02-06 16:25:01 -050042
William Kurkian44cd7bb2019-02-11 16:39:12 -050043from pyvoltha.protos.logical_device_pb2 import LogicalDevice, LogicalPort
William Kurkian6f436d02019-02-06 16:25:01 -050044
Matt Jeanneret9fd36df2019-02-14 19:14:36 -050045
William Kurkian6f436d02019-02-06 16:25:01 -050046class OpenoltDevice(object):
47 """
48 OpenoltDevice state machine:
49
50 null ----> init ------> connected -----> up -----> down
51 ^ ^ | ^ | |
52 | | | | | |
53 | +-------------+ +---------+ |
54 | |
55 +-----------------------------------------+
56 """
57 # pylint: disable=too-many-instance-attributes
58 # pylint: disable=R0904
59 states = [
60 'state_null',
61 'state_init',
62 'state_connected',
63 'state_up',
64 'state_down']
65
66 transitions = [
67 {'trigger': 'go_state_init',
68 'source': ['state_null', 'state_connected', 'state_down'],
69 'dest': 'state_init',
70 'before': 'do_state_init',
71 'after': 'post_init'},
72 {'trigger': 'go_state_connected',
73 'source': 'state_init',
74 'dest': 'state_connected',
75 'before': 'do_state_connected'},
76 {'trigger': 'go_state_up',
77 'source': ['state_connected', 'state_down'],
78 'dest': 'state_up',
79 'before': 'do_state_up'},
80 {'trigger': 'go_state_down',
81 'source': ['state_up'],
82 'dest': 'state_down',
83 'before': 'do_state_down',
84 'after': 'post_down'}]
85
86 def __init__(self, **kwargs):
87 super(OpenoltDevice, self).__init__()
88
Matt Jeanneret7906d232019-02-14 14:57:38 -050089 self.adapter_proxy = kwargs['adapter_proxy']
William Kurkian6f436d02019-02-06 16:25:01 -050090 self.adapter_agent = kwargs['adapter_agent']
91 self.device_num = kwargs['device_num']
92 device = kwargs['device']
93
94 self.platform_class = kwargs['support_classes']['platform']
95 self.resource_mgr_class = kwargs['support_classes']['resource_mgr']
96 self.flow_mgr_class = kwargs['support_classes']['flow_mgr']
97 self.alarm_mgr_class = kwargs['support_classes']['alarm_mgr']
98 self.stats_mgr_class = kwargs['support_classes']['stats_mgr']
99 self.bw_mgr_class = kwargs['support_classes']['bw_mgr']
Matt Jeanneret7906d232019-02-14 14:57:38 -0500100
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500101 self.stub = None
William Kurkian27522582019-02-25 14:24:32 -0500102 self.connected = False
William Kurkian6f436d02019-02-06 16:25:01 -0500103 is_reconciliation = kwargs.get('reconciliation', False)
104 self.device_id = device.id
105 self.host_and_port = device.host_and_port
106 self.extra_args = device.extra_args
107 self.log = structlog.get_logger(id=self.device_id,
108 ip=self.host_and_port)
Matt Jeanneret6e315092019-02-20 10:42:57 -0500109
William Kurkian6f436d02019-02-06 16:25:01 -0500110 self.log.info('openolt-device-init')
111
112 # default device id and device serial number. If device_info provides better results, they will be updated
113 self.dpid = kwargs.get('dp_id')
114 self.serial_number = self.host_and_port # FIXME
115
116 # Device already set in the event of reconciliation
117 if not is_reconciliation:
118 self.log.info('updating-device')
119 # It is a new device
120 # Update device
121 device.root = True
122 device.connect_status = ConnectStatus.UNREACHABLE
123 device.oper_status = OperStatus.ACTIVATING
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500124 # TODO NEW CORE. need to move this, cant have a constructor be a generator (yield)
125 #self.adapter_agent.device_update(device)
William Kurkian6f436d02019-02-06 16:25:01 -0500126
127 # If logical device does exist use it, else create one after connecting to device
128 if device.parent_id:
129 # logical device already exists
130 self.logical_device_id = device.parent_id
131 if is_reconciliation:
132 self.adapter_agent.reconcile_logical_device(
133 self.logical_device_id)
134
135 # 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')
139 self.go_state_init()
140
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500141 @inlineCallbacks
Matt Jeanneret9fd36df2019-02-14 19:14:36 -0500142 def create_logical_device(self, device_info):
William Kurkian6f436d02019-02-06 16:25:01 -0500143 dpid = device_info.device_id
144 serial_number = device_info.device_serial_number
145
146 if dpid is None: dpid = self.dpid
147 if serial_number is None: serial_number = self.serial_number
148
149 if dpid == None or dpid == '':
150 uri = self.host_and_port.split(":")[0]
151 try:
152 socket.inet_pton(socket.AF_INET, uri)
153 dpid = '00:00:' + self.ip_hex(uri)
154 except socket.error:
155 # this is not an IP
156 dpid = self.stringToMacAddr(uri)
157
158 if serial_number == None or serial_number == '':
159 serial_number = self.host_and_port
160
161 self.log.info('creating-openolt-logical-device', dp_id=dpid, serial_number=serial_number)
162
163 mfr_desc = device_info.vendor
164 sw_desc = device_info.firmware_version
165 hw_desc = device_info.model
166 if device_info.hardware_version: hw_desc += '-' + device_info.hardware_version
William Kurkian92bd7122019-02-14 15:26:59 -0500167
William Kurkian6f436d02019-02-06 16:25:01 -0500168 # Create logical OF device
169 ld = LogicalDevice(
170 root_device_id=self.device_id,
171 switch_features=ofp_switch_features(
172 n_buffers=256, # TODO fake for now
173 n_tables=2, # TODO ditto
174 capabilities=( # TODO and ditto
175 OFPC_FLOW_STATS
176 | OFPC_TABLE_STATS
177 | OFPC_PORT_STATS
178 | OFPC_GROUP_STATS
179 )
180 ),
181 desc=ofp_desc(
182 serial_num=serial_number
183 )
184 )
185 ld_init = self.adapter_agent.create_logical_device(ld,
William Kurkian92bd7122019-02-14 15:26:59 -0500186 dpid=dpid)
187
William Kurkian6f436d02019-02-06 16:25:01 -0500188 self.logical_device_id = ld_init.id
189
William Kurkian27522582019-02-25 14:24:32 -0500190 ##Moved setting serial number outside of the logical_device function
191 #device = yield self.adapter_agent.get_device(self.device_id)
192 #device.serial_number = serial_number
193 #yield self.adapter_agent.update_device(device)
William Kurkian6f436d02019-02-06 16:25:01 -0500194
195 self.dpid = dpid
196 self.serial_number = serial_number
197
198 self.log.info('created-openolt-logical-device', logical_device_id=ld_init.id)
199
200 def stringToMacAddr(self, uri):
201 regex = re.compile('[^a-zA-Z]')
202 uri = regex.sub('', uri)
203
204 l = len(uri)
205 if l > 6:
206 uri = uri[0:6]
207 else:
208 uri = uri + uri[0:6 - l]
209
William Kurkian6f436d02019-02-06 16:25:01 -0500210 return ":".join([hex(ord(x))[-2:] for x in uri])
211
212 def do_state_init(self, event):
213 # Initialize gRPC
Matt Jeanneret7906d232019-02-14 14:57:38 -0500214 self.log.debug("grpc-host-port", self.host_and_port)
William Kurkian6f436d02019-02-06 16:25:01 -0500215 self.channel = grpc.insecure_channel(self.host_and_port)
216 self.channel_ready_future = grpc.channel_ready_future(self.channel)
217
218 self.log.info('openolt-device-created', device_id=self.device_id)
219
220 def post_init(self, event):
221 self.log.debug('post_init')
222
223 # We have reached init state, starting the indications thread
224
225 # Catch RuntimeError exception
226 try:
227 # Start indications thread
228 self.indications_thread_handle = threading.Thread(
229 target=self.indications_thread)
230 # Old getter/setter API for daemon; use it directly as a
231 # property instead. The Jinkins error will happon on the reason of
232 # Exception in thread Thread-1 (most likely raised # during
233 # interpreter shutdown)
Matt Jeanneret7906d232019-02-14 14:57:38 -0500234 self.log.debug('starting indications thread')
William Kurkian6f436d02019-02-06 16:25:01 -0500235 self.indications_thread_handle.setDaemon(True)
236 self.indications_thread_handle.start()
237 except Exception as e:
238 self.log.exception('post_init failed', e=e)
239
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500240 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500241 def do_state_connected(self, event):
242 self.log.debug("do_state_connected")
William Kurkian27522582019-02-25 14:24:32 -0500243
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500244 device = yield self.adapter_agent.get_device(self.device_id)
William Kurkian6f436d02019-02-06 16:25:01 -0500245
William Kurkian27522582019-02-25 14:24:32 -0500246
William Kurkian6f436d02019-02-06 16:25:01 -0500247 self.stub = openolt_pb2_grpc.OpenoltStub(self.channel)
248
William Kurkianfefd4642019-02-07 15:30:03 -0500249 delay = 1
250 while True:
251 try:
252 device_info = self.stub.GetDeviceInfo(openolt_pb2.Empty())
253 break
254 except Exception as e:
255 reraise = True
256 if delay > 120:
257 self.log.error("gRPC failure too many times")
258 else:
259 self.log.warn("gRPC failure, retry in %ds: %s"
260 % (delay, repr(e)))
261 time.sleep(delay)
262 delay += delay
263 reraise = False
264
265 if reraise:
266 raise
267
William Kurkian6f436d02019-02-06 16:25:01 -0500268 self.log.info('Device connected', device_info=device_info)
269
Matt Jeanneret7906d232019-02-14 14:57:38 -0500270 # self.create_logical_device(device_info)
271 self.logical_device_id = 0
William Kurkian27522582019-02-25 14:24:32 -0500272
273 serial_number = device_info.device_serial_number
274 if serial_number is None:
275 serial_number = self.serial_number
276 device.serial_number = serial_number
277
278 self.serial_number = serial_number
279
Matt Jeanneret5ba87e32019-02-28 11:35:49 -0500280 device.root = True
William Kurkian27522582019-02-25 14:24:32 -0500281 device.vendor = device_info.vendor
282 device.model = device_info.model
283 device.hardware_version = device_info.hardware_version
284 device.firmware_version = device_info.firmware_version
285
286 # TODO: check for uptime and reboot if too long (VOL-1192)
287
288 device.connect_status = ConnectStatus.REACHABLE
289 device.mac_address = "AA:BB:CC:DD:EE:FF"
290 yield self.adapter_agent.device_update(device)
291
Matt Jeanneret7906d232019-02-14 14:57:38 -0500292
William Kurkian6f436d02019-02-06 16:25:01 -0500293 self.resource_mgr = self.resource_mgr_class(self.device_id,
294 self.host_and_port,
295 self.extra_args,
296 device_info)
297 self.platform = self.platform_class(self.log, self.resource_mgr)
298 self.flow_mgr = self.flow_mgr_class(self.adapter_agent, self.log,
299 self.stub, self.device_id,
300 self.logical_device_id,
301 self.platform, self.resource_mgr)
302
303 self.alarm_mgr = self.alarm_mgr_class(self.log, self.adapter_agent,
304 self.device_id,
305 self.logical_device_id,
306 self.platform)
Matt Jeanneret7906d232019-02-14 14:57:38 -0500307 self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform)
William Kurkian92bd7122019-02-14 15:26:59 -0500308 self.bw_mgr = self.bw_mgr_class(self.log, self.adapter_agent)
William Kurkian27522582019-02-25 14:24:32 -0500309
310 self.connected = True
Matt Jeanneret6e315092019-02-20 10:42:57 -0500311
312 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500313 def do_state_up(self, event):
314 self.log.debug("do_state_up")
315
Matt Jeanneret6e315092019-02-20 10:42:57 -0500316 yield self.adapter_agent.device_state_update(self.device_id,
Matt Jeanneret9fd36df2019-02-14 19:14:36 -0500317 connect_status=ConnectStatus.REACHABLE,
318 oper_status=OperStatus.ACTIVE)
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500319 self.log.debug("done_state_up")
William Kurkian6f436d02019-02-06 16:25:01 -0500320
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500321 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500322 def do_state_down(self, event):
323 self.log.debug("do_state_down")
324 oper_state = OperStatus.UNKNOWN
325 connect_state = ConnectStatus.UNREACHABLE
326
327 # Propagating to the children
328
329 # Children ports
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500330 child_devices = yield self.adapter_agent.get_child_devices(self.device_id)
William Kurkian6f436d02019-02-06 16:25:01 -0500331 for onu_device in child_devices:
332 onu_adapter_agent = \
333 registry('adapter_loader').get_agent(onu_device.adapter)
334 onu_adapter_agent.update_interface(onu_device,
335 {'oper_state': 'down'})
336 self.onu_ports_down(onu_device, oper_state)
337
338 # Children devices
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500339 yield self.adapter_agent.update_child_devices_state(
William Kurkian6f436d02019-02-06 16:25:01 -0500340 self.device_id, oper_status=oper_state,
341 connect_status=connect_state)
342 # Device Ports
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500343 device_ports = yield self.adapter_agent.get_ports(self.device_id,
William Kurkian6f436d02019-02-06 16:25:01 -0500344 Port.ETHERNET_NNI)
345 logical_ports_ids = [port.label for port in device_ports]
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500346 device_ports += yield self.adapter_agent.get_ports(self.device_id,
William Kurkian6f436d02019-02-06 16:25:01 -0500347 Port.PON_OLT)
348
349 for port in device_ports:
350 port.oper_status = oper_state
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500351 yield self.adapter_agent.add_port(self.device_id, port)
William Kurkian6f436d02019-02-06 16:25:01 -0500352
353 # Device logical port
354 for logical_port_id in logical_ports_ids:
355 logical_port = self.adapter_agent.get_logical_port(
356 self.logical_device_id, logical_port_id)
357 logical_port.ofp_port.state = OFPPS_LINK_DOWN
358 self.adapter_agent.update_logical_port(self.logical_device_id,
359 logical_port)
360
361 # Device
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500362 device = yield self.adapter_agent.get_device(self.device_id)
William Kurkian6f436d02019-02-06 16:25:01 -0500363 device.oper_status = oper_state
364 device.connect_status = connect_state
365
William Kurkianfefd4642019-02-07 15:30:03 -0500366 reactor.callLater(2, self.adapter_agent.device_update, device)
William Kurkian6f436d02019-02-06 16:25:01 -0500367
368 # def post_up(self, event):
369 # self.log.debug('post-up')
370 # self.flow_mgr.reseed_flows()
371
372 def post_down(self, event):
373 self.log.debug('post_down')
374 self.flow_mgr.reset_flows()
375
376 def indications_thread(self):
377 self.log.debug('starting-indications-thread')
378 self.log.debug('connecting to olt', device_id=self.device_id)
379 self.channel_ready_future.result() # blocking call
380 self.log.info('connected to olt', device_id=self.device_id)
381 self.go_state_connected()
382
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500383 # TODO: thread timing issue. stub isnt ready yet from above go_state_connected (which doesnt block)
William Kurkian27522582019-02-25 14:24:32 -0500384 # Don't continue until connected is done
385 while (not self.connected):
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500386 time.sleep(0.5)
387
William Kurkian6f436d02019-02-06 16:25:01 -0500388 self.indications = self.stub.EnableIndication(openolt_pb2.Empty())
389
390 while True:
391 try:
392 # get the next indication from olt
393 ind = next(self.indications)
394 except Exception as e:
395 self.log.warn('gRPC connection lost', error=e)
396 reactor.callFromThread(self.go_state_down)
397 reactor.callFromThread(self.go_state_init)
398 break
399 else:
400 self.log.debug("rx indication", indication=ind)
401
402 # indication handlers run in the main event loop
403 if ind.HasField('olt_ind'):
404 reactor.callFromThread(self.olt_indication, ind.olt_ind)
405 elif ind.HasField('intf_ind'):
406 reactor.callFromThread(self.intf_indication, ind.intf_ind)
407 elif ind.HasField('intf_oper_ind'):
408 reactor.callFromThread(self.intf_oper_indication,
409 ind.intf_oper_ind)
410 elif ind.HasField('onu_disc_ind'):
411 reactor.callFromThread(self.onu_discovery_indication,
412 ind.onu_disc_ind)
413 elif ind.HasField('onu_ind'):
414 reactor.callFromThread(self.onu_indication, ind.onu_ind)
415 elif ind.HasField('omci_ind'):
416 reactor.callFromThread(self.omci_indication, ind.omci_ind)
417 elif ind.HasField('pkt_ind'):
418 reactor.callFromThread(self.packet_indication, ind.pkt_ind)
419 elif ind.HasField('port_stats'):
420 reactor.callFromThread(
421 self.stats_mgr.port_statistics_indication,
422 ind.port_stats)
423 elif ind.HasField('flow_stats'):
424 reactor.callFromThread(
425 self.stats_mgr.flow_statistics_indication,
426 ind.flow_stats)
427 elif ind.HasField('alarm_ind'):
428 reactor.callFromThread(self.alarm_mgr.process_alarms,
429 ind.alarm_ind)
430 else:
431 self.log.warn('unknown indication type')
432
433 def olt_indication(self, olt_indication):
434 if olt_indication.oper_state == "up":
435 self.go_state_up()
436 elif olt_indication.oper_state == "down":
437 self.go_state_down()
438
439 def intf_indication(self, intf_indication):
440 self.log.debug("intf indication", intf_id=intf_indication.intf_id,
441 oper_state=intf_indication.oper_state)
442
443 if intf_indication.oper_state == "up":
444 oper_status = OperStatus.ACTIVE
445 else:
446 oper_status = OperStatus.DISCOVERED
447
448 # add_port update the port if it exists
449 self.add_port(intf_indication.intf_id, Port.PON_OLT, oper_status)
450
451 def intf_oper_indication(self, intf_oper_indication):
452 self.log.debug("Received interface oper state change indication",
453 intf_id=intf_oper_indication.intf_id,
454 type=intf_oper_indication.type,
455 oper_state=intf_oper_indication.oper_state)
456
457 if intf_oper_indication.oper_state == "up":
458 oper_state = OperStatus.ACTIVE
459 else:
460 oper_state = OperStatus.DISCOVERED
461
462 if intf_oper_indication.type == "nni":
463
464 # add_(logical_)port update the port if it exists
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500465 self.add_port(intf_oper_indication.intf_id,
466 Port.ETHERNET_NNI, oper_state)
Matt Jeanneret6e315092019-02-20 10:42:57 -0500467
468 # TODO NEW CORE: Is this needed anymore, or does the new core synthesize this
469 #self.add_logical_port(port_no, intf_oper_indication.intf_id,
470 # oper_state)
William Kurkian6f436d02019-02-06 16:25:01 -0500471
472 elif intf_oper_indication.type == "pon":
473 # FIXME - handle PON oper state change
474 pass
475
Matt Jeanneret6e315092019-02-20 10:42:57 -0500476 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500477 def onu_discovery_indication(self, onu_disc_indication):
478 intf_id = onu_disc_indication.intf_id
479 serial_number = onu_disc_indication.serial_number
480
481 serial_number_str = self.stringify_serial_number(serial_number)
482
483 self.log.debug("onu discovery indication", intf_id=intf_id,
484 serial_number=serial_number_str)
485
486 # Post ONU Discover alarm 20180809_0805
487 try:
488 OnuDiscoveryAlarm(self.alarm_mgr.alarms, pon_id=intf_id,
489 serial_number=serial_number_str).raise_alarm()
490 except Exception as disc_alarm_error:
491 self.log.exception("onu-discovery-alarm-error",
492 errmsg=disc_alarm_error.message)
493 # continue for now.
494
Matt Jeanneret5ba87e32019-02-28 11:35:49 -0500495 onu_device = yield self.adapter_agent.get_child_device(
496 self.device_id,
497 serial_number=serial_number_str)
William Kurkian6f436d02019-02-06 16:25:01 -0500498
499 if onu_device is None:
500 try:
501 onu_id = self.resource_mgr.get_onu_id(intf_id)
502 if onu_id is None:
503 raise Exception("onu-id-unavailable")
504
505 self.add_onu_device(
506 intf_id,
507 self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT),
508 onu_id, serial_number)
509 self.activate_onu(intf_id, onu_id, serial_number,
510 serial_number_str)
511 except Exception as e:
512 self.log.exception('onu-activation-failed', e=e)
513
514 else:
515 if onu_device.connect_status != ConnectStatus.REACHABLE:
516 onu_device.connect_status = ConnectStatus.REACHABLE
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500517 yield self.adapter_agent.device_update(onu_device)
William Kurkian6f436d02019-02-06 16:25:01 -0500518
519 onu_id = onu_device.proxy_address.onu_id
520 if onu_device.oper_status == OperStatus.DISCOVERED \
521 or onu_device.oper_status == OperStatus.ACTIVATING:
522 self.log.debug("ignore onu discovery indication, \
523 the onu has been discovered and should be \
524 activating shorlty", intf_id=intf_id,
525 onu_id=onu_id, state=onu_device.oper_status)
526 elif onu_device.oper_status == OperStatus.ACTIVE:
527 self.log.warn("onu discovery indication whereas onu is \
528 supposed to be active",
529 intf_id=intf_id, onu_id=onu_id,
530 state=onu_device.oper_status)
531 elif onu_device.oper_status == OperStatus.UNKNOWN:
532 self.log.info("onu in unknown state, recovering from olt \
533 reboot probably, activate onu", intf_id=intf_id,
534 onu_id=onu_id, serial_number=serial_number_str)
535
536 onu_device.oper_status = OperStatus.DISCOVERED
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500537 yield self.adapter_agent.device_update(onu_device)
William Kurkian6f436d02019-02-06 16:25:01 -0500538 try:
539 self.activate_onu(intf_id, onu_id, serial_number,
540 serial_number_str)
541 except Exception as e:
542 self.log.error('onu-activation-error',
543 serial_number=serial_number_str, error=e)
544 else:
545 self.log.warn('unexpected state', onu_id=onu_id,
546 onu_device_oper_state=onu_device.oper_status)
547
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500548 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500549 def onu_indication(self, onu_indication):
550 self.log.debug("onu indication", intf_id=onu_indication.intf_id,
551 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)
555 try:
556 serial_number_str = self.stringify_serial_number(
557 onu_indication.serial_number)
558 except Exception as e:
559 serial_number_str = None
560
561 if serial_number_str is not None:
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500562 onu_device = yield self.adapter_agent.get_child_device(
William Kurkian6f436d02019-02-06 16:25:01 -0500563 self.device_id,
564 serial_number=serial_number_str)
565 else:
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500566 onu_device = yield self.adapter_agent.get_child_device(
William Kurkian6f436d02019-02-06 16:25:01 -0500567 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)
571
572 if onu_device is None:
573 self.log.error('onu not found', intf_id=onu_indication.intf_id,
574 onu_id=onu_indication.onu_id)
575 return
576
577 if self.platform.intf_id_from_pon_port_no(onu_device.parent_port_no) \
578 != onu_indication.intf_id:
579 self.log.warn('ONU-is-on-a-different-intf-id-now',
580 previous_intf_id=self.platform.intf_id_from_pon_port_no(
581 onu_device.parent_port_no),
582 current_intf_id=onu_indication.intf_id)
583 # FIXME - handle intf_id mismatch (ONU move?)
584
585 if onu_device.proxy_address.onu_id != onu_indication.onu_id:
586 # FIXME - handle onu id mismatch
587 self.log.warn('ONU-id-mismatch, can happen if both voltha and '
588 'the olt rebooted',
589 expected_onu_id=onu_device.proxy_address.onu_id,
590 received_onu_id=onu_indication.onu_id)
591
592 # Admin state
593 if onu_indication.admin_state == 'down':
594 if onu_indication.oper_state != 'down':
595 self.log.error('ONU-admin-state-down-and-oper-status-not-down',
596 oper_state=onu_indication.oper_state)
597 # Forcing the oper state change code to execute
598 onu_indication.oper_state = 'down'
599
600 # Port and logical port update is taken care of by oper state block
601
602 elif onu_indication.admin_state == 'up':
603 pass
604
605 else:
606 self.log.warn('Invalid-or-not-implemented-admin-state',
607 received_admin_state=onu_indication.admin_state)
608
609 self.log.debug('admin-state-dealt-with')
610
611 onu_adapter_agent = \
612 registry('adapter_loader').get_agent(onu_device.adapter)
613 if onu_adapter_agent is None:
614 self.log.error('onu_adapter_agent-could-not-be-retrieved',
615 onu_device=onu_device)
616 return
617
618 # Operating state
619 if onu_indication.oper_state == 'down':
620
621 if onu_device.connect_status != ConnectStatus.UNREACHABLE:
622 onu_device.connect_status = ConnectStatus.UNREACHABLE
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500623 yield self.adapter_agent.device_update(onu_device)
William Kurkian6f436d02019-02-06 16:25:01 -0500624
625 # Move to discovered state
626 self.log.debug('onu-oper-state-is-down')
627
628 if onu_device.oper_status != OperStatus.DISCOVERED:
629 onu_device.oper_status = OperStatus.DISCOVERED
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500630 yield self.adapter_agent.device_update(onu_device)
William Kurkian6f436d02019-02-06 16:25:01 -0500631 # Set port oper state to Discovered
632 self.onu_ports_down(onu_device, OperStatus.DISCOVERED)
633
634 onu_adapter_agent.update_interface(onu_device,
635 {'oper_state': 'down'})
636
637 elif onu_indication.oper_state == 'up':
638
639 if onu_device.connect_status != ConnectStatus.REACHABLE:
640 onu_device.connect_status = ConnectStatus.REACHABLE
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500641 yield self.adapter_agent.device_update(onu_device)
William Kurkian6f436d02019-02-06 16:25:01 -0500642
643 if onu_device.oper_status != OperStatus.DISCOVERED:
644 self.log.debug("ignore onu indication",
645 intf_id=onu_indication.intf_id,
646 onu_id=onu_indication.onu_id,
647 state=onu_device.oper_status,
648 msg_oper_state=onu_indication.oper_state)
649 return
650
651 # Device was in Discovered state, setting it to active
652
653 # Prepare onu configuration
654
655 onu_adapter_agent.create_interface(onu_device, onu_indication)
656
657 else:
658 self.log.warn('Not-implemented-or-invalid-value-of-oper-state',
659 oper_state=onu_indication.oper_state)
660
661 def onu_ports_down(self, onu_device, oper_state):
662 # Set port oper state to Discovered
663 # add port will update port if it exists
664 # self.adapter_agent.add_port(
665 # self.device_id,
666 # Port(
667 # port_no=uni_no,
668 # label=uni_name,
669 # type=Port.ETHERNET_UNI,
670 # admin_state=onu_device.admin_state,
671 # oper_status=oper_state))
672 # TODO this should be downning ports in onu adatper
673
674 # Disable logical port
675 onu_ports = self.proxy.get('devices/{}/ports'.format(onu_device.id))
676 for onu_port in onu_ports:
677 self.log.debug('onu-ports-down', onu_port=onu_port)
678 onu_port_id = onu_port.label
679 try:
680 onu_logical_port = self.adapter_agent.get_logical_port(
681 logical_device_id=self.logical_device_id, port_id=onu_port_id)
682 onu_logical_port.ofp_port.state = OFPPS_LINK_DOWN
683 self.adapter_agent.update_logical_port(
684 logical_device_id=self.logical_device_id,
685 port=onu_logical_port)
686 self.log.debug('cascading-oper-state-to-port-and-logical-port')
687 except KeyError as e:
688 self.log.error('matching-onu-port-label-invalid',
689 onu_id=onu_device.id, olt_id=self.device_id,
690 onu_ports=onu_ports, onu_port_id=onu_port_id,
691 error=e)
692
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500693 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500694 def omci_indication(self, omci_indication):
695
696 self.log.debug("omci indication", intf_id=omci_indication.intf_id,
697 onu_id=omci_indication.onu_id)
698
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500699 onu_device = yield self.adapter_agent.get_child_device(
William Kurkian6f436d02019-02-06 16:25:01 -0500700 self.device_id, onu_id=omci_indication.onu_id,
701 parent_port_no=self.platform.intf_id_to_port_no(
702 omci_indication.intf_id, Port.PON_OLT), )
703
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500704 yield self.adapter_agent.receive_proxied_message(onu_device.proxy_address,
William Kurkian6f436d02019-02-06 16:25:01 -0500705 omci_indication.pkt)
706
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500707 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500708 def packet_indication(self, pkt_indication):
709
710 self.log.debug("packet indication",
711 intf_type=pkt_indication.intf_type,
712 intf_id=pkt_indication.intf_id,
713 port_no=pkt_indication.port_no,
714 cookie=pkt_indication.cookie,
715 gemport_id=pkt_indication.gemport_id,
716 flow_id=pkt_indication.flow_id)
717
718 if pkt_indication.intf_type == "pon":
719 if pkt_indication.port_no:
720 logical_port_num = pkt_indication.port_no
721 else: # TODO Remove this else block after openolt device has been fully rolled out with cookie protobuf change
722 try:
723 onu_id_uni_id = self.resource_mgr.get_onu_uni_from_ponport_gemport(pkt_indication.intf_id,
724 pkt_indication.gemport_id)
725 onu_id = int(onu_id_uni_id[0])
726 uni_id = int(onu_id_uni_id[1])
727 self.log.debug("packet indication-kv", onu_id=onu_id, uni_id=uni_id)
728 if onu_id is None:
729 raise Exception("onu-id-none")
730 if uni_id is None:
731 raise Exception("uni-id-none")
732 logical_port_num = self.platform.mk_uni_port_num(pkt_indication.intf_id, onu_id, uni_id)
733 except Exception as e:
734 self.log.error("no-onu-reference-for-gem",
735 gemport_id=pkt_indication.gemport_id, e=e)
736 return
737
738
739 elif pkt_indication.intf_type == "nni":
740 logical_port_num = self.platform.intf_id_to_port_no(
741 pkt_indication.intf_id,
742 Port.ETHERNET_NNI)
743
744 pkt = Ether(pkt_indication.pkt)
745
746 self.log.debug("packet indication",
747 logical_device_id=self.logical_device_id,
748 logical_port_no=logical_port_num)
749
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500750 yield self.adapter_agent.send_packet_in(
William Kurkian6f436d02019-02-06 16:25:01 -0500751 logical_device_id=self.logical_device_id,
752 logical_port_no=logical_port_num,
753 packet=str(pkt))
754
755 def packet_out(self, egress_port, msg):
756 pkt = Ether(msg)
757 self.log.debug('packet out', egress_port=egress_port,
758 device_id=self.device_id,
759 logical_device_id=self.logical_device_id,
760 packet=str(pkt).encode("HEX"))
761
762 # Find port type
763 egress_port_type = self.platform.intf_id_to_port_type_name(egress_port)
764 if egress_port_type == Port.ETHERNET_UNI:
765
766 if pkt.haslayer(Dot1Q):
767 outer_shim = pkt.getlayer(Dot1Q)
768 if isinstance(outer_shim.payload, Dot1Q):
769 # If double tag, remove the outer tag
770 payload = (
771 Ether(src=pkt.src, dst=pkt.dst, type=outer_shim.type) /
772 outer_shim.payload
773 )
774 else:
775 payload = pkt
776 else:
777 payload = pkt
778
779 send_pkt = binascii.unhexlify(str(payload).encode("HEX"))
780
781 self.log.debug(
782 'sending-packet-to-ONU', egress_port=egress_port,
783 intf_id=self.platform.intf_id_from_uni_port_num(egress_port),
784 onu_id=self.platform.onu_id_from_port_num(egress_port),
785 uni_id=self.platform.uni_id_from_port_num(egress_port),
786 port_no=egress_port,
787 packet=str(payload).encode("HEX"))
788
789 onu_pkt = openolt_pb2.OnuPacket(
790 intf_id=self.platform.intf_id_from_uni_port_num(egress_port),
791 onu_id=self.platform.onu_id_from_port_num(egress_port),
792 port_no=egress_port,
793 pkt=send_pkt)
794
795 self.stub.OnuPacketOut(onu_pkt)
796
797 elif egress_port_type == Port.ETHERNET_NNI:
798 self.log.debug('sending-packet-to-uplink', egress_port=egress_port,
799 packet=str(pkt).encode("HEX"))
800
801 send_pkt = binascii.unhexlify(str(pkt).encode("HEX"))
802
803 uplink_pkt = openolt_pb2.UplinkPacket(
804 intf_id=self.platform.intf_id_from_nni_port_num(egress_port),
805 pkt=send_pkt)
806
807 self.stub.UplinkPacketOut(uplink_pkt)
808
809 else:
810 self.log.warn('Packet-out-to-this-interface-type-not-implemented',
811 egress_port=egress_port,
812 port_type=egress_port_type)
813
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500814 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500815 def send_proxied_message(self, proxy_address, msg):
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500816 onu_device = yield self.adapter_agent.get_child_device(
William Kurkian6f436d02019-02-06 16:25:01 -0500817 self.device_id, onu_id=proxy_address.onu_id,
818 parent_port_no=self.platform.intf_id_to_port_no(
819 proxy_address.channel_id, Port.PON_OLT)
820 )
821 if onu_device.connect_status != ConnectStatus.REACHABLE:
822 self.log.debug('ONU is not reachable, cannot send OMCI',
823 serial_number=onu_device.serial_number,
824 intf_id=onu_device.proxy_address.channel_id,
825 onu_id=onu_device.proxy_address.onu_id)
826 return
827 omci = openolt_pb2.OmciMsg(intf_id=proxy_address.channel_id,
828 onu_id=proxy_address.onu_id, pkt=str(msg))
829 self.stub.OmciMsgOut(omci)
830
Matt Jeanneret6e315092019-02-20 10:42:57 -0500831 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500832 def add_onu_device(self, intf_id, port_no, onu_id, serial_number):
Matt Jeanneret5ba87e32019-02-28 11:35:49 -0500833 self.log.info("adding-onu", port_no=port_no, onu_id=onu_id,
William Kurkian6f436d02019-02-06 16:25:01 -0500834 serial_number=serial_number)
835
William Kurkian6f436d02019-02-06 16:25:01 -0500836 serial_number_str = self.stringify_serial_number(serial_number)
837
Matt Jeanneret6e315092019-02-20 10:42:57 -0500838 yield self.adapter_agent.child_device_detected(
839 parent_device_id=self.device_id,
840 parent_port_no=port_no,
841 child_device_type='brcm_openomci_onu',
Matt Jeanneret5ba87e32019-02-28 11:35:49 -0500842 channel_id=intf_id,
843 vendor_id=serial_number.vendor_id,
844 serial_number=serial_number_str,
845 onu_id=onu_id
William Kurkian6f436d02019-02-06 16:25:01 -0500846 )
847
Matt Jeanneret5ba87e32019-02-28 11:35:49 -0500848 self.log.debug("onu-added", onu_id=onu_id, port_no=port_no, serial_number=serial_number_str)
849
William Kurkian6f436d02019-02-06 16:25:01 -0500850 def port_name(self, port_no, port_type, intf_id=None, serial_number=None):
851 if port_type is Port.ETHERNET_NNI:
852 return "nni-" + str(port_no)
853 elif port_type is Port.PON_OLT:
854 return "pon" + str(intf_id)
855 elif port_type is Port.ETHERNET_UNI:
856 assert False, 'local UNI management not supported'
857
858 def add_logical_port(self, port_no, intf_id, oper_state):
859 self.log.info('adding-logical-port', port_no=port_no)
860
861 label = self.port_name(port_no, Port.ETHERNET_NNI)
862
863 cap = OFPPF_1GB_FD | OFPPF_FIBER
864 curr_speed = OFPPF_1GB_FD
865 max_speed = OFPPF_1GB_FD
866
867 if oper_state == OperStatus.ACTIVE:
868 of_oper_state = OFPPS_LIVE
869 else:
870 of_oper_state = OFPPS_LINK_DOWN
871
872 ofp = ofp_port(
873 port_no=port_no,
874 hw_addr=mac_str_to_tuple(self._get_mac_form_port_no(port_no)),
875 name=label, config=0, state=of_oper_state, curr=cap,
876 advertised=cap, peer=cap, curr_speed=curr_speed,
877 max_speed=max_speed)
878
879 ofp_stats = ofp_port_stats(port_no=port_no)
880
881 logical_port = LogicalPort(
882 id=label, ofp_port=ofp, device_id=self.device_id,
883 device_port_no=port_no, root_port=True,
884 ofp_port_stats=ofp_stats)
885
886 self.adapter_agent.add_logical_port(self.logical_device_id,
887 logical_port)
888
889 def _get_mac_form_port_no(self, port_no):
890 mac = ''
891 for i in range(4):
892 mac = ':%02x' % ((port_no >> (i * 8)) & 0xff) + mac
893 return '00:00' + mac
894
William Kurkian92bd7122019-02-14 15:26:59 -0500895 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500896 def add_port(self, intf_id, port_type, oper_status):
897 port_no = self.platform.intf_id_to_port_no(intf_id, port_type)
898
899 label = self.port_name(port_no, port_type, intf_id)
900
901 self.log.debug('adding-port', port_no=port_no, label=label,
902 port_type=port_type)
903
904 port = Port(port_no=port_no, label=label, type=port_type,
905 admin_state=AdminState.ENABLED, oper_status=oper_status)
906
Matt Jeanneret9fd36df2019-02-14 19:14:36 -0500907 yield self.adapter_agent.port_created(self.device_id, port)
William Kurkian6f436d02019-02-06 16:25:01 -0500908
909 def delete_logical_port(self, child_device):
910 logical_ports = self.proxy.get('/logical_devices/{}/ports'.format(
911 self.logical_device_id))
912 for logical_port in logical_ports:
913 if logical_port.device_id == child_device.id:
914 self.log.debug('delete-logical-port',
915 onu_device_id=child_device.id,
916 logical_port=logical_port)
917 self.flow_mgr.clear_flows_and_scheduler_for_logical_port(
918 child_device, logical_port)
919 self.adapter_agent.delete_logical_port(
920 self.logical_device_id, logical_port)
921 return
922
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500923 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500924 def delete_port(self, child_serial_number):
925 ports = self.proxy.get('/devices/{}/ports'.format(
926 self.device_id))
927 for port in ports:
928 if port.label == child_serial_number:
929 self.log.debug('delete-port',
930 onu_serial_number=child_serial_number,
931 port=port)
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500932 yield self.adapter_agent.delete_port(self.device_id, port)
William Kurkian6f436d02019-02-06 16:25:01 -0500933 return
934
935 def update_flow_table(self, flows):
936 self.log.debug('No updates here now, all is done in logical flows '
937 'update')
938
939 def update_logical_flows(self, flows_to_add, flows_to_remove,
940 device_rules_map):
941 if not self.is_state_up():
942 self.log.info('The OLT is not up, we cannot update flows',
943 flows_to_add=[f.id for f in flows_to_add],
944 flows_to_remove=[f.id for f in flows_to_remove])
945 return
946
947 try:
948 self.flow_mgr.update_children_flows(device_rules_map)
949 except Exception as e:
950 self.log.error('Error updating children flows', error=e)
951
952 self.log.debug('logical flows update', flows_to_add=flows_to_add,
953 flows_to_remove=flows_to_remove)
954
955 for flow in flows_to_add:
956
957 try:
958 self.flow_mgr.add_flow(flow)
959 except Exception as e:
960 self.log.error('failed to add flow', flow=flow, e=e)
961
962 for flow in flows_to_remove:
963
964 try:
965 self.flow_mgr.remove_flow(flow)
966 except Exception as e:
967 self.log.error('failed to remove flow', flow=flow, e=e)
968
969 self.flow_mgr.repush_all_different_flows()
970
971 # There has to be a better way to do this
972 def ip_hex(self, ip):
973 octets = ip.split(".")
974 hex_ip = []
975 for octet in octets:
976 octet_hex = hex(int(octet))
977 octet_hex = octet_hex.split('0x')[1]
978 octet_hex = octet_hex.rjust(2, '0')
979 hex_ip.append(octet_hex)
980 return ":".join(hex_ip)
981
982 def stringify_vendor_specific(self, vendor_specific):
983 return ''.join(str(i) for i in [
984 hex(ord(vendor_specific[0]) >> 4 & 0x0f)[2:],
985 hex(ord(vendor_specific[0]) & 0x0f)[2:],
986 hex(ord(vendor_specific[1]) >> 4 & 0x0f)[2:],
987 hex(ord(vendor_specific[1]) & 0x0f)[2:],
988 hex(ord(vendor_specific[2]) >> 4 & 0x0f)[2:],
989 hex(ord(vendor_specific[2]) & 0x0f)[2:],
990 hex(ord(vendor_specific[3]) >> 4 & 0x0f)[2:],
991 hex(ord(vendor_specific[3]) & 0x0f)[2:]])
992
993 def stringify_serial_number(self, serial_number):
994 return ''.join([serial_number.vendor_id,
995 self.stringify_vendor_specific(
996 serial_number.vendor_specific)])
997
998 def destringify_serial_number(self, serial_number_str):
999 serial_number = openolt_pb2.SerialNumber(
1000 vendor_id=serial_number_str[:4].encode('utf-8'),
1001 vendor_specific=binascii.unhexlify(serial_number_str[4:]))
1002 return serial_number
1003
1004 def disable(self):
1005 self.log.debug('sending-deactivate-olt-message',
1006 device_id=self.device_id)
1007
1008 try:
1009 # Send grpc call
1010 self.stub.DisableOlt(openolt_pb2.Empty())
1011 # The resulting indication will bring the OLT down
1012 # self.go_state_down()
1013 self.log.info('openolt device disabled')
1014 except Exception as e:
1015 self.log.error('Failure to disable openolt device', error=e)
1016
1017 def delete(self):
1018 self.log.info('deleting-olt', device_id=self.device_id,
1019 logical_device_id=self.logical_device_id)
1020
1021 # Clears up the data from the resource manager KV store
1022 # for the device
1023 del self.resource_mgr
1024
1025 try:
1026 # Rebooting to reset the state
1027 self.reboot()
1028 # Removing logical device
1029 ld = self.adapter_agent.get_logical_device(self.logical_device_id)
1030 self.adapter_agent.delete_logical_device(ld)
1031 except Exception as e:
1032 self.log.error('Failure to delete openolt device', error=e)
1033 raise e
1034 else:
1035 self.log.info('successfully-deleted-olt', device_id=self.device_id)
1036
1037 def reenable(self):
1038 self.log.debug('reenabling-olt', device_id=self.device_id)
1039
1040 try:
1041 self.stub.ReenableOlt(openolt_pb2.Empty())
1042
William Kurkian6f436d02019-02-06 16:25:01 -05001043 except Exception as e:
1044 self.log.error('Failure to reenable openolt device', error=e)
1045 else:
1046 self.log.info('openolt device reenabled')
1047
1048 def activate_onu(self, intf_id, onu_id, serial_number,
1049 serial_number_str):
1050 pir = self.bw_mgr.pir(serial_number_str)
1051 self.log.debug("activating-onu", intf_id=intf_id, onu_id=onu_id,
1052 serial_number_str=serial_number_str,
1053 serial_number=serial_number, pir=pir)
1054 onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id,
1055 serial_number=serial_number, pir=pir)
1056 self.stub.ActivateOnu(onu)
1057 self.log.info('onu-activated', serial_number=serial_number_str)
1058
Matt Jeanneretd2f155b2019-02-22 13:49:09 -05001059 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -05001060 def delete_child_device(self, child_device):
1061 self.log.debug('sending-deactivate-onu',
1062 olt_device_id=self.device_id,
1063 onu_device=child_device,
1064 onu_serial_number=child_device.serial_number)
1065 try:
Matt Jeanneretd2f155b2019-02-22 13:49:09 -05001066 yield self.adapter_agent.delete_child_device(self.device_id,
William Kurkian6f436d02019-02-06 16:25:01 -05001067 child_device.id,
1068 child_device)
1069 except Exception as e:
1070 self.log.error('adapter_agent error', error=e)
1071 try:
1072 self.delete_logical_port(child_device)
1073 except Exception as e:
1074 self.log.error('logical_port delete error', error=e)
1075 try:
1076 self.delete_port(child_device.serial_number)
1077 except Exception as e:
1078 self.log.error('port delete error', error=e)
1079 serial_number = self.destringify_serial_number(
1080 child_device.serial_number)
1081 # TODO FIXME - For each uni.
1082 # TODO FIXME - Flows are not deleted
1083 uni_id = 0 # FIXME
1084 self.flow_mgr.delete_tech_profile_instance(
Matt Jeanneret7906d232019-02-14 14:57:38 -05001085 child_device.proxy_address.channel_id,
1086 child_device.proxy_address.onu_id,
1087 uni_id
William Kurkian6f436d02019-02-06 16:25:01 -05001088 )
1089 pon_intf_id_onu_id = (child_device.proxy_address.channel_id,
1090 child_device.proxy_address.onu_id,
1091 uni_id)
1092 # Free any PON resources that were reserved for the ONU
1093 self.resource_mgr.free_pon_resources_for_onu(pon_intf_id_onu_id)
1094
1095 onu = openolt_pb2.Onu(intf_id=child_device.proxy_address.channel_id,
1096 onu_id=child_device.proxy_address.onu_id,
1097 serial_number=serial_number)
1098 self.stub.DeleteOnu(onu)
1099
1100 def reboot(self):
1101 self.log.debug('rebooting openolt device', device_id=self.device_id)
1102 try:
1103 self.stub.Reboot(openolt_pb2.Empty())
1104 except Exception as e:
1105 self.log.error('something went wrong with the reboot', error=e)
1106 else:
1107 self.log.info('device rebooted')
1108
1109 def trigger_statistics_collection(self):
1110 try:
1111 self.stub.CollectStatistics(openolt_pb2.Empty())
1112 except Exception as e:
1113 self.log.error('Error while triggering statistics collection',
1114 error=e)
1115 else:
1116 self.log.info('statistics requested')
1117
1118 def simulate_alarm(self, alarm):
1119 self.alarm_mgr.simulate_alarm(alarm)