blob: 2eaa4458840270ef9600bb30bac324f726909892 [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 Kurkian8b1690c2019-03-04 16:53:22 -050028from voltha_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
William Kurkian8b1690c2019-03-04 16:53:22 -050033from voltha_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
William Kurkian8b1690c2019-03-04 16:53:22 -050038from voltha_protos.common_pb2 import AdminState, OperStatus, ConnectStatus
William Kurkian8b1690c2019-03-04 16:53:22 -050039from voltha_protos.device_pb2 import Port, Device
Matt Jeannerete33a7092019-03-12 21:54:14 -040040from voltha_protos.inter_container_pb2 import SwitchCapability, PortCapability, \
41 InterAdapterMessageType, InterAdapterOmciMessage
William Kurkian8b1690c2019-03-04 16:53:22 -050042from voltha_protos.logical_device_pb2 import LogicalDevice, LogicalPort
William Kurkian6f436d02019-02-06 16:25:01 -050043
Matt Jeanneret9fd36df2019-02-14 19:14:36 -050044
William Kurkian6f436d02019-02-06 16:25:01 -050045class OpenoltDevice(object):
46 """
47 OpenoltDevice state machine:
48
49 null ----> init ------> connected -----> up -----> down
50 ^ ^ | ^ | |
51 | | | | | |
52 | +-------------+ +---------+ |
53 | |
54 +-----------------------------------------+
55 """
56 # pylint: disable=too-many-instance-attributes
57 # pylint: disable=R0904
58 states = [
59 'state_null',
60 'state_init',
61 'state_connected',
62 'state_up',
63 'state_down']
64
65 transitions = [
66 {'trigger': 'go_state_init',
67 'source': ['state_null', 'state_connected', 'state_down'],
68 'dest': 'state_init',
69 'before': 'do_state_init',
70 'after': 'post_init'},
71 {'trigger': 'go_state_connected',
72 'source': 'state_init',
73 'dest': 'state_connected',
74 'before': 'do_state_connected'},
75 {'trigger': 'go_state_up',
76 'source': ['state_connected', 'state_down'],
77 'dest': 'state_up',
78 'before': 'do_state_up'},
79 {'trigger': 'go_state_down',
80 'source': ['state_up'],
81 'dest': 'state_down',
82 'before': 'do_state_down',
83 'after': 'post_down'}]
84
85 def __init__(self, **kwargs):
86 super(OpenoltDevice, self).__init__()
87
Matt Jeanneretbad3d982019-03-11 16:06:10 -040088 self.core_proxy = kwargs['core_proxy']
Matt Jeanneret7906d232019-02-14 14:57:38 -050089 self.adapter_proxy = kwargs['adapter_proxy']
William Kurkian6f436d02019-02-06 16:25:01 -050090 self.device_num = kwargs['device_num']
serkant.uluderyadcfc74d2019-03-17 23:41:42 -070091 self.device = kwargs['device']
William Kurkian6f436d02019-02-06 16:25:01 -050092
93 self.platform_class = kwargs['support_classes']['platform']
94 self.resource_mgr_class = kwargs['support_classes']['resource_mgr']
95 self.flow_mgr_class = kwargs['support_classes']['flow_mgr']
96 self.alarm_mgr_class = kwargs['support_classes']['alarm_mgr']
97 self.stats_mgr_class = kwargs['support_classes']['stats_mgr']
98 self.bw_mgr_class = kwargs['support_classes']['bw_mgr']
Matt Jeanneret7906d232019-02-14 14:57:38 -050099
Matt Jeanneretb428b952019-03-07 05:14:17 -0500100 self.seen_discovery_indications = []
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)
serkant.uluderyadcfc74d2019-03-17 23:41:42 -0700104 self.device_id = self.device.id
105 self.host_and_port = self.device.host_and_port
106 self.extra_args = self.device.extra_args
Matt Jeannerete33a7092019-03-12 21:54:14 -0400107 self.device_info = None
William Kurkian6f436d02019-02-06 16:25:01 -0500108 self.log = structlog.get_logger(id=self.device_id,
109 ip=self.host_and_port)
Matt Jeanneret6e315092019-02-20 10:42:57 -0500110
William Kurkian6f436d02019-02-06 16:25:01 -0500111 self.log.info('openolt-device-init')
112
113 # default device id and device serial number. If device_info provides better results, they will be updated
114 self.dpid = kwargs.get('dp_id')
115 self.serial_number = self.host_and_port # FIXME
116
117 # Device already set in the event of reconciliation
118 if not is_reconciliation:
119 self.log.info('updating-device')
120 # It is a new device
121 # Update device
serkant.uluderyadcfc74d2019-03-17 23:41:42 -0700122 self.device.root = True
123 self.device.connect_status = ConnectStatus.UNREACHABLE
124 self.device.oper_status = OperStatus.ACTIVATING
William Kurkian6f436d02019-02-06 16:25:01 -0500125
William Kurkian6f436d02019-02-06 16:25:01 -0500126 # Initialize the OLT state machine
127 self.machine = Machine(model=self, states=OpenoltDevice.states,
128 transitions=OpenoltDevice.transitions,
129 send_event=True, initial='state_null')
130 self.go_state_init()
131
William Kurkian6f436d02019-02-06 16:25:01 -0500132 def stringToMacAddr(self, uri):
133 regex = re.compile('[^a-zA-Z]')
134 uri = regex.sub('', uri)
135
136 l = len(uri)
137 if l > 6:
138 uri = uri[0:6]
139 else:
140 uri = uri + uri[0:6 - l]
141
William Kurkian6f436d02019-02-06 16:25:01 -0500142 return ":".join([hex(ord(x))[-2:] for x in uri])
143
144 def do_state_init(self, event):
145 # Initialize gRPC
Matt Jeanneret7906d232019-02-14 14:57:38 -0500146 self.log.debug("grpc-host-port", self.host_and_port)
William Kurkian6f436d02019-02-06 16:25:01 -0500147 self.channel = grpc.insecure_channel(self.host_and_port)
148 self.channel_ready_future = grpc.channel_ready_future(self.channel)
149
150 self.log.info('openolt-device-created', device_id=self.device_id)
151
152 def post_init(self, event):
153 self.log.debug('post_init')
154
155 # We have reached init state, starting the indications thread
156
157 # Catch RuntimeError exception
158 try:
159 # Start indications thread
160 self.indications_thread_handle = threading.Thread(
161 target=self.indications_thread)
162 # Old getter/setter API for daemon; use it directly as a
163 # property instead. The Jinkins error will happon on the reason of
164 # Exception in thread Thread-1 (most likely raised # during
165 # interpreter shutdown)
Matt Jeanneret7906d232019-02-14 14:57:38 -0500166 self.log.debug('starting indications thread')
William Kurkian6f436d02019-02-06 16:25:01 -0500167 self.indications_thread_handle.setDaemon(True)
168 self.indications_thread_handle.start()
169 except Exception as e:
170 self.log.exception('post_init failed', e=e)
171
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500172 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500173 def do_state_connected(self, event):
174 self.log.debug("do_state_connected")
William Kurkian27522582019-02-25 14:24:32 -0500175
William Kurkian6f436d02019-02-06 16:25:01 -0500176 self.stub = openolt_pb2_grpc.OpenoltStub(self.channel)
177
William Kurkianfefd4642019-02-07 15:30:03 -0500178 delay = 1
179 while True:
180 try:
Matt Jeannerete33a7092019-03-12 21:54:14 -0400181 self.device_info = self.stub.GetDeviceInfo(openolt_pb2.Empty())
William Kurkianfefd4642019-02-07 15:30:03 -0500182 break
183 except Exception as e:
184 reraise = True
185 if delay > 120:
186 self.log.error("gRPC failure too many times")
187 else:
188 self.log.warn("gRPC failure, retry in %ds: %s"
189 % (delay, repr(e)))
190 time.sleep(delay)
191 delay += delay
192 reraise = False
193
194 if reraise:
195 raise
196
Matt Jeannerete33a7092019-03-12 21:54:14 -0400197 self.log.info('Device connected', device_info=self.device_info)
William Kurkian6f436d02019-02-06 16:25:01 -0500198
Matt Jeanneretaa360912019-04-22 16:23:12 -0400199 # TODO NEW CORE: logical device id is no longer available. use real device id for now
200 self.logical_device_id = self.device_id
201 dpid = self.device_info.device_id
Matt Jeannerete33a7092019-03-12 21:54:14 -0400202 serial_number = self.device_info.device_serial_number
Matt Jeanneretaa360912019-04-22 16:23:12 -0400203
204 if dpid is None: dpid = self.dpid
205 if serial_number is None: serial_number = self.serial_number
206
207 if dpid == None or dpid == '':
208 uri = self.host_and_port.split(":")[0]
209 try:
210 socket.inet_pton(socket.AF_INET, uri)
211 dpid = '00:00:' + self.ip_hex(uri)
212 except socket.error:
213 # this is not an IP
214 dpid = self.stringToMacAddr(uri)
215
216 if serial_number == None or serial_number == '':
217 serial_number = self.host_and_port
218
219 self.log.info('creating-openolt-device', dp_id=dpid, serial_number=serial_number)
220
serkant.uluderyadcfc74d2019-03-17 23:41:42 -0700221 self.device.root = True
Matt Jeanneretaa360912019-04-22 16:23:12 -0400222 self.device.serial_number = serial_number
serkant.uluderyadcfc74d2019-03-17 23:41:42 -0700223 self.device.vendor = self.device_info.vendor
224 self.device.model = self.device_info.model
225 self.device.hardware_version = self.device_info.hardware_version
226 self.device.firmware_version = self.device_info.firmware_version
William Kurkian27522582019-02-25 14:24:32 -0500227
228 # TODO: check for uptime and reboot if too long (VOL-1192)
229
serkant.uluderyadcfc74d2019-03-17 23:41:42 -0700230 self.device.connect_status = ConnectStatus.REACHABLE
Matt Jeanneretaa360912019-04-22 16:23:12 -0400231 self.device.mac_address = dpid
serkant.uluderyadcfc74d2019-03-17 23:41:42 -0700232 yield self.core_proxy.device_update(self.device)
Matt Jeanneret7906d232019-02-14 14:57:38 -0500233
William Kurkian6f436d02019-02-06 16:25:01 -0500234 self.resource_mgr = self.resource_mgr_class(self.device_id,
235 self.host_and_port,
236 self.extra_args,
Matt Jeannerete33a7092019-03-12 21:54:14 -0400237 self.device_info)
William Kurkian6f436d02019-02-06 16:25:01 -0500238 self.platform = self.platform_class(self.log, self.resource_mgr)
Matt Jeanneret9dbce8c2019-03-23 14:35:00 -0400239 self.flow_mgr = self.flow_mgr_class(self.core_proxy, self.adapter_proxy, self.log,
William Kurkian6f436d02019-02-06 16:25:01 -0500240 self.stub, self.device_id,
241 self.logical_device_id,
242 self.platform, self.resource_mgr)
serkant.uluderyadcfc74d2019-03-17 23:41:42 -0700243
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400244 self.alarm_mgr = self.alarm_mgr_class(self.log, self.core_proxy,
William Kurkian6f436d02019-02-06 16:25:01 -0500245 self.device_id,
246 self.logical_device_id,
serkant.uluderyadcfc74d2019-03-17 23:41:42 -0700247 self.platform,
248 self.serial_number)
Matt Jeanneret7906d232019-02-14 14:57:38 -0500249 self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform)
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400250 self.bw_mgr = self.bw_mgr_class(self.log, self.core_proxy)
William Kurkian27522582019-02-25 14:24:32 -0500251
252 self.connected = True
Matt Jeanneret6e315092019-02-20 10:42:57 -0500253
254 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500255 def do_state_up(self, event):
256 self.log.debug("do_state_up")
257
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400258 yield self.core_proxy.device_state_update(self.device_id,
Matt Jeanneret9fd36df2019-02-14 19:14:36 -0500259 connect_status=ConnectStatus.REACHABLE,
260 oper_status=OperStatus.ACTIVE)
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500261 self.log.debug("done_state_up")
William Kurkian6f436d02019-02-06 16:25:01 -0500262
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500263 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500264 def do_state_down(self, event):
265 self.log.debug("do_state_down")
Arun Arora2e63b1e2019-04-03 12:15:19 +0000266 yield self.core_proxy.device_state_update(self.device_id,
267 connect_status=ConnectStatus.UNREACHABLE,
268 oper_status=OperStatus.UNKNOWN)
269 self.log.debug("done_state_down")
William Kurkian6f436d02019-02-06 16:25:01 -0500270
271 # def post_up(self, event):
272 # self.log.debug('post-up')
273 # self.flow_mgr.reseed_flows()
274
275 def post_down(self, event):
276 self.log.debug('post_down')
277 self.flow_mgr.reset_flows()
278
279 def indications_thread(self):
280 self.log.debug('starting-indications-thread')
281 self.log.debug('connecting to olt', device_id=self.device_id)
282 self.channel_ready_future.result() # blocking call
283 self.log.info('connected to olt', device_id=self.device_id)
284 self.go_state_connected()
285
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500286 # TODO: thread timing issue. stub isnt ready yet from above go_state_connected (which doesnt block)
William Kurkian27522582019-02-25 14:24:32 -0500287 # Don't continue until connected is done
288 while (not self.connected):
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500289 time.sleep(0.5)
290
William Kurkian6f436d02019-02-06 16:25:01 -0500291 self.indications = self.stub.EnableIndication(openolt_pb2.Empty())
292
293 while True:
294 try:
295 # get the next indication from olt
296 ind = next(self.indications)
297 except Exception as e:
298 self.log.warn('gRPC connection lost', error=e)
299 reactor.callFromThread(self.go_state_down)
300 reactor.callFromThread(self.go_state_init)
301 break
302 else:
303 self.log.debug("rx indication", indication=ind)
304
305 # indication handlers run in the main event loop
306 if ind.HasField('olt_ind'):
307 reactor.callFromThread(self.olt_indication, ind.olt_ind)
308 elif ind.HasField('intf_ind'):
309 reactor.callFromThread(self.intf_indication, ind.intf_ind)
310 elif ind.HasField('intf_oper_ind'):
311 reactor.callFromThread(self.intf_oper_indication,
312 ind.intf_oper_ind)
313 elif ind.HasField('onu_disc_ind'):
314 reactor.callFromThread(self.onu_discovery_indication,
315 ind.onu_disc_ind)
316 elif ind.HasField('onu_ind'):
317 reactor.callFromThread(self.onu_indication, ind.onu_ind)
318 elif ind.HasField('omci_ind'):
319 reactor.callFromThread(self.omci_indication, ind.omci_ind)
320 elif ind.HasField('pkt_ind'):
321 reactor.callFromThread(self.packet_indication, ind.pkt_ind)
322 elif ind.HasField('port_stats'):
323 reactor.callFromThread(
324 self.stats_mgr.port_statistics_indication,
325 ind.port_stats)
326 elif ind.HasField('flow_stats'):
327 reactor.callFromThread(
328 self.stats_mgr.flow_statistics_indication,
329 ind.flow_stats)
330 elif ind.HasField('alarm_ind'):
331 reactor.callFromThread(self.alarm_mgr.process_alarms,
332 ind.alarm_ind)
333 else:
334 self.log.warn('unknown indication type')
335
336 def olt_indication(self, olt_indication):
337 if olt_indication.oper_state == "up":
338 self.go_state_up()
339 elif olt_indication.oper_state == "down":
340 self.go_state_down()
341
342 def intf_indication(self, intf_indication):
343 self.log.debug("intf indication", intf_id=intf_indication.intf_id,
344 oper_state=intf_indication.oper_state)
345
346 if intf_indication.oper_state == "up":
347 oper_status = OperStatus.ACTIVE
348 else:
349 oper_status = OperStatus.DISCOVERED
350
351 # add_port update the port if it exists
352 self.add_port(intf_indication.intf_id, Port.PON_OLT, oper_status)
353
354 def intf_oper_indication(self, intf_oper_indication):
355 self.log.debug("Received interface oper state change indication",
356 intf_id=intf_oper_indication.intf_id,
357 type=intf_oper_indication.type,
358 oper_state=intf_oper_indication.oper_state)
359
360 if intf_oper_indication.oper_state == "up":
361 oper_state = OperStatus.ACTIVE
362 else:
363 oper_state = OperStatus.DISCOVERED
364
365 if intf_oper_indication.type == "nni":
366
367 # add_(logical_)port update the port if it exists
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500368 self.add_port(intf_oper_indication.intf_id,
369 Port.ETHERNET_NNI, oper_state)
Matt Jeanneret6e315092019-02-20 10:42:57 -0500370
William Kurkian6f436d02019-02-06 16:25:01 -0500371 elif intf_oper_indication.type == "pon":
372 # FIXME - handle PON oper state change
373 pass
374
Matt Jeanneret6e315092019-02-20 10:42:57 -0500375 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500376 def onu_discovery_indication(self, onu_disc_indication):
377 intf_id = onu_disc_indication.intf_id
378 serial_number = onu_disc_indication.serial_number
379
380 serial_number_str = self.stringify_serial_number(serial_number)
381
382 self.log.debug("onu discovery indication", intf_id=intf_id,
383 serial_number=serial_number_str)
384
Matt Jeanneretb428b952019-03-07 05:14:17 -0500385 if serial_number_str in self.seen_discovery_indications:
386 self.log.debug("skipping-seen-onu-discovery-indication", intf_id=intf_id,
387 serial_number=serial_number_str)
388 return
389 else:
390 self.seen_discovery_indications.append(serial_number_str)
391
William Kurkian6f436d02019-02-06 16:25:01 -0500392 # Post ONU Discover alarm 20180809_0805
393 try:
394 OnuDiscoveryAlarm(self.alarm_mgr.alarms, pon_id=intf_id,
395 serial_number=serial_number_str).raise_alarm()
396 except Exception as disc_alarm_error:
397 self.log.exception("onu-discovery-alarm-error",
398 errmsg=disc_alarm_error.message)
399 # continue for now.
400
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400401 onu_device = yield self.core_proxy.get_child_device(
Matt Jeanneret5ba87e32019-02-28 11:35:49 -0500402 self.device_id,
403 serial_number=serial_number_str)
William Kurkian6f436d02019-02-06 16:25:01 -0500404
405 if onu_device is None:
406 try:
407 onu_id = self.resource_mgr.get_onu_id(intf_id)
408 if onu_id is None:
409 raise Exception("onu-id-unavailable")
410
411 self.add_onu_device(
412 intf_id,
413 self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT),
414 onu_id, serial_number)
415 self.activate_onu(intf_id, onu_id, serial_number,
416 serial_number_str)
417 except Exception as e:
418 self.log.exception('onu-activation-failed', e=e)
419
420 else:
421 if onu_device.connect_status != ConnectStatus.REACHABLE:
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400422 yield self.core_proxy.device_state_update(onu_device.id, connect_status=ConnectStatus.REACHABLE)
William Kurkian6f436d02019-02-06 16:25:01 -0500423
424 onu_id = onu_device.proxy_address.onu_id
425 if onu_device.oper_status == OperStatus.DISCOVERED \
426 or onu_device.oper_status == OperStatus.ACTIVATING:
427 self.log.debug("ignore onu discovery indication, \
428 the onu has been discovered and should be \
429 activating shorlty", intf_id=intf_id,
430 onu_id=onu_id, state=onu_device.oper_status)
431 elif onu_device.oper_status == OperStatus.ACTIVE:
432 self.log.warn("onu discovery indication whereas onu is \
433 supposed to be active",
434 intf_id=intf_id, onu_id=onu_id,
435 state=onu_device.oper_status)
436 elif onu_device.oper_status == OperStatus.UNKNOWN:
437 self.log.info("onu in unknown state, recovering from olt \
438 reboot probably, activate onu", intf_id=intf_id,
439 onu_id=onu_id, serial_number=serial_number_str)
440
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400441 yield self.core_proxy.device_state_update(onu_device.id, oper_status=OperStatus.DISCOVERED)
Matt Jeanneretb428b952019-03-07 05:14:17 -0500442
William Kurkian6f436d02019-02-06 16:25:01 -0500443 try:
444 self.activate_onu(intf_id, onu_id, serial_number,
445 serial_number_str)
446 except Exception as e:
447 self.log.error('onu-activation-error',
448 serial_number=serial_number_str, error=e)
449 else:
450 self.log.warn('unexpected state', onu_id=onu_id,
451 onu_device_oper_state=onu_device.oper_status)
452
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500453 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500454 def onu_indication(self, onu_indication):
455 self.log.debug("onu indication", intf_id=onu_indication.intf_id,
456 onu_id=onu_indication.onu_id,
457 serial_number=onu_indication.serial_number,
458 oper_state=onu_indication.oper_state,
459 admin_state=onu_indication.admin_state)
460 try:
461 serial_number_str = self.stringify_serial_number(
462 onu_indication.serial_number)
463 except Exception as e:
464 serial_number_str = None
465
466 if serial_number_str is not None:
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400467 onu_device = yield self.core_proxy.get_child_device(
William Kurkian6f436d02019-02-06 16:25:01 -0500468 self.device_id,
469 serial_number=serial_number_str)
470 else:
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400471 onu_device = yield self.core_proxy.get_child_device(
William Kurkian6f436d02019-02-06 16:25:01 -0500472 self.device_id,
473 parent_port_no=self.platform.intf_id_to_port_no(
474 onu_indication.intf_id, Port.PON_OLT),
475 onu_id=onu_indication.onu_id)
476
477 if onu_device is None:
478 self.log.error('onu not found', intf_id=onu_indication.intf_id,
479 onu_id=onu_indication.onu_id)
480 return
481
482 if self.platform.intf_id_from_pon_port_no(onu_device.parent_port_no) \
483 != onu_indication.intf_id:
484 self.log.warn('ONU-is-on-a-different-intf-id-now',
485 previous_intf_id=self.platform.intf_id_from_pon_port_no(
486 onu_device.parent_port_no),
487 current_intf_id=onu_indication.intf_id)
488 # FIXME - handle intf_id mismatch (ONU move?)
489
490 if onu_device.proxy_address.onu_id != onu_indication.onu_id:
491 # FIXME - handle onu id mismatch
492 self.log.warn('ONU-id-mismatch, can happen if both voltha and '
493 'the olt rebooted',
494 expected_onu_id=onu_device.proxy_address.onu_id,
495 received_onu_id=onu_indication.onu_id)
496
497 # Admin state
498 if onu_indication.admin_state == 'down':
499 if onu_indication.oper_state != 'down':
500 self.log.error('ONU-admin-state-down-and-oper-status-not-down',
501 oper_state=onu_indication.oper_state)
502 # Forcing the oper state change code to execute
503 onu_indication.oper_state = 'down'
504
505 # Port and logical port update is taken care of by oper state block
506
507 elif onu_indication.admin_state == 'up':
508 pass
509
510 else:
511 self.log.warn('Invalid-or-not-implemented-admin-state',
512 received_admin_state=onu_indication.admin_state)
513
514 self.log.debug('admin-state-dealt-with')
515
William Kurkian6f436d02019-02-06 16:25:01 -0500516 # Operating state
517 if onu_indication.oper_state == 'down':
518
519 if onu_device.connect_status != ConnectStatus.UNREACHABLE:
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400520 yield self.core_proxy.device_state_update(onu_device.id, connect_status=ConnectStatus.UNREACHABLE)
William Kurkian6f436d02019-02-06 16:25:01 -0500521
522 # Move to discovered state
523 self.log.debug('onu-oper-state-is-down')
524
525 if onu_device.oper_status != OperStatus.DISCOVERED:
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400526 yield self.core_proxy.device_state_update(onu_device.id, oper_status=OperStatus.DISCOVERED)
William Kurkian6f436d02019-02-06 16:25:01 -0500527
Matt Jeanneretb428b952019-03-07 05:14:17 -0500528 self.log.debug('inter-adapter-send-onu-ind', onu_indication=onu_indication)
529
530 # TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference
531 yield self.adapter_proxy.send_inter_adapter_message(
532 msg=onu_indication,
533 type=InterAdapterMessageType.ONU_IND_REQUEST,
534 from_adapter="openolt",
535 to_adapter=onu_device.type,
536 to_device_id=onu_device.id
537 )
William Kurkian6f436d02019-02-06 16:25:01 -0500538
539 elif onu_indication.oper_state == 'up':
540
541 if onu_device.connect_status != ConnectStatus.REACHABLE:
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400542 yield self.core_proxy.device_state_update(onu_device.id, connect_status=ConnectStatus.REACHABLE)
William Kurkian6f436d02019-02-06 16:25:01 -0500543
544 if onu_device.oper_status != OperStatus.DISCOVERED:
545 self.log.debug("ignore onu indication",
546 intf_id=onu_indication.intf_id,
547 onu_id=onu_indication.onu_id,
548 state=onu_device.oper_status,
549 msg_oper_state=onu_indication.oper_state)
550 return
551
Matt Jeanneretb428b952019-03-07 05:14:17 -0500552 self.log.debug('inter-adapter-send-onu-ind', onu_indication=onu_indication)
William Kurkian6f436d02019-02-06 16:25:01 -0500553
Matt Jeanneretb428b952019-03-07 05:14:17 -0500554 # TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference
555 yield self.adapter_proxy.send_inter_adapter_message(
556 msg=onu_indication,
557 type=InterAdapterMessageType.ONU_IND_REQUEST,
558 from_adapter="openolt",
559 to_adapter=onu_device.type,
560 to_device_id=onu_device.id
561 )
William Kurkian6f436d02019-02-06 16:25:01 -0500562
563 else:
564 self.log.warn('Not-implemented-or-invalid-value-of-oper-state',
565 oper_state=onu_indication.oper_state)
William Kurkian23047b92019-05-01 11:02:35 -0400566 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500567 def onu_ports_down(self, onu_device, oper_state):
William Kurkian23047b92019-05-01 11:02:35 -0400568 pass
William Kurkian6f436d02019-02-06 16:25:01 -0500569 # Set port oper state to Discovered
570 # add port will update port if it exists
William Kurkian23047b92019-05-01 11:02:35 -0400571 # yield self.core_proxy.add_port(
William Kurkian6f436d02019-02-06 16:25:01 -0500572 # self.device_id,
573 # Port(
574 # port_no=uni_no,
575 # label=uni_name,
576 # type=Port.ETHERNET_UNI,
577 # admin_state=onu_device.admin_state,
578 # oper_status=oper_state))
579 # TODO this should be downning ports in onu adatper
580
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500581 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500582 def omci_indication(self, omci_indication):
583
584 self.log.debug("omci indication", intf_id=omci_indication.intf_id,
585 onu_id=omci_indication.onu_id)
586
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400587 onu_device = yield self.core_proxy.get_child_device(
William Kurkian6f436d02019-02-06 16:25:01 -0500588 self.device_id, onu_id=omci_indication.onu_id,
589 parent_port_no=self.platform.intf_id_to_port_no(
590 omci_indication.intf_id, Port.PON_OLT), )
591
Matt Jeanneretb428b952019-03-07 05:14:17 -0500592 omci_msg = InterAdapterOmciMessage(message=omci_indication.pkt)
593
594 self.log.debug('inter-adapter-send-omci', omci_msg=omci_msg)
595
596 # TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference
597 yield self.adapter_proxy.send_inter_adapter_message(
598 msg=omci_msg,
599 type=InterAdapterMessageType.OMCI_REQUEST,
600 from_adapter="openolt",
601 to_adapter=onu_device.type,
602 to_device_id=onu_device.id
603 )
William Kurkian6f436d02019-02-06 16:25:01 -0500604
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500605 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500606 def packet_indication(self, pkt_indication):
607
608 self.log.debug("packet indication",
609 intf_type=pkt_indication.intf_type,
610 intf_id=pkt_indication.intf_id,
611 port_no=pkt_indication.port_no,
612 cookie=pkt_indication.cookie,
613 gemport_id=pkt_indication.gemport_id,
614 flow_id=pkt_indication.flow_id)
615
616 if pkt_indication.intf_type == "pon":
617 if pkt_indication.port_no:
Matt Jeannereta591ab82019-04-13 15:54:28 -0400618 port_num = pkt_indication.port_no
William Kurkian6f436d02019-02-06 16:25:01 -0500619 else: # TODO Remove this else block after openolt device has been fully rolled out with cookie protobuf change
620 try:
621 onu_id_uni_id = self.resource_mgr.get_onu_uni_from_ponport_gemport(pkt_indication.intf_id,
622 pkt_indication.gemport_id)
623 onu_id = int(onu_id_uni_id[0])
624 uni_id = int(onu_id_uni_id[1])
625 self.log.debug("packet indication-kv", onu_id=onu_id, uni_id=uni_id)
626 if onu_id is None:
627 raise Exception("onu-id-none")
628 if uni_id is None:
629 raise Exception("uni-id-none")
Matt Jeannereta591ab82019-04-13 15:54:28 -0400630 port_num = self.platform.mk_uni_port_num(pkt_indication.intf_id, onu_id, uni_id)
William Kurkian6f436d02019-02-06 16:25:01 -0500631 except Exception as e:
632 self.log.error("no-onu-reference-for-gem",
633 gemport_id=pkt_indication.gemport_id, e=e)
634 return
635
636
637 elif pkt_indication.intf_type == "nni":
Matt Jeannereta591ab82019-04-13 15:54:28 -0400638 port_num = self.platform.intf_id_to_port_no(
William Kurkian6f436d02019-02-06 16:25:01 -0500639 pkt_indication.intf_id,
640 Port.ETHERNET_NNI)
641
642 pkt = Ether(pkt_indication.pkt)
643
644 self.log.debug("packet indication",
Matt Jeannereta591ab82019-04-13 15:54:28 -0400645 device_id=self.device_id,
646 port_num=port_num)
William Kurkian6f436d02019-02-06 16:25:01 -0500647
Matt Jeannereta591ab82019-04-13 15:54:28 -0400648 yield self.core_proxy.send_packet_in(
649 device_id=self.device_id,
650 port=port_num,
William Kurkian6f436d02019-02-06 16:25:01 -0500651 packet=str(pkt))
652
653 def packet_out(self, egress_port, msg):
654 pkt = Ether(msg)
655 self.log.debug('packet out', egress_port=egress_port,
656 device_id=self.device_id,
William Kurkian6f436d02019-02-06 16:25:01 -0500657 packet=str(pkt).encode("HEX"))
658
659 # Find port type
660 egress_port_type = self.platform.intf_id_to_port_type_name(egress_port)
661 if egress_port_type == Port.ETHERNET_UNI:
662
663 if pkt.haslayer(Dot1Q):
664 outer_shim = pkt.getlayer(Dot1Q)
665 if isinstance(outer_shim.payload, Dot1Q):
666 # If double tag, remove the outer tag
667 payload = (
668 Ether(src=pkt.src, dst=pkt.dst, type=outer_shim.type) /
669 outer_shim.payload
670 )
671 else:
672 payload = pkt
673 else:
674 payload = pkt
675
676 send_pkt = binascii.unhexlify(str(payload).encode("HEX"))
677
678 self.log.debug(
679 'sending-packet-to-ONU', egress_port=egress_port,
680 intf_id=self.platform.intf_id_from_uni_port_num(egress_port),
681 onu_id=self.platform.onu_id_from_port_num(egress_port),
682 uni_id=self.platform.uni_id_from_port_num(egress_port),
683 port_no=egress_port,
684 packet=str(payload).encode("HEX"))
685
686 onu_pkt = openolt_pb2.OnuPacket(
687 intf_id=self.platform.intf_id_from_uni_port_num(egress_port),
688 onu_id=self.platform.onu_id_from_port_num(egress_port),
689 port_no=egress_port,
690 pkt=send_pkt)
691
692 self.stub.OnuPacketOut(onu_pkt)
693
694 elif egress_port_type == Port.ETHERNET_NNI:
695 self.log.debug('sending-packet-to-uplink', egress_port=egress_port,
696 packet=str(pkt).encode("HEX"))
697
698 send_pkt = binascii.unhexlify(str(pkt).encode("HEX"))
699
700 uplink_pkt = openolt_pb2.UplinkPacket(
701 intf_id=self.platform.intf_id_from_nni_port_num(egress_port),
702 pkt=send_pkt)
703
704 self.stub.UplinkPacketOut(uplink_pkt)
705
706 else:
707 self.log.warn('Packet-out-to-this-interface-type-not-implemented',
708 egress_port=egress_port,
709 port_type=egress_port_type)
710
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500711 @inlineCallbacks
Matt Jeanneretb428b952019-03-07 05:14:17 -0500712 def process_inter_adapter_message(self, request):
713 self.log.debug('process-inter-adapter-message', msg=request)
714 try:
715 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
716 omci_msg = InterAdapterOmciMessage()
717 request.body.Unpack(omci_msg)
718 self.log.debug('inter-adapter-recv-omci', omci_msg=omci_msg)
719
720 onu_device_id = request.header.to_device_id
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400721 onu_device = yield self.core_proxy.get_device(onu_device_id)
Matt Jeanneretb428b952019-03-07 05:14:17 -0500722 self.send_proxied_message(onu_device, omci_msg.message)
723
724 else:
725 self.log.error("inter-adapter-unhandled-type", request=request)
726
727 except Exception as e:
728 self.log.exception("error-processing-inter-adapter-message", e=e)
729
730 def send_proxied_message(self, onu_device, msg):
731
William Kurkian6f436d02019-02-06 16:25:01 -0500732 if onu_device.connect_status != ConnectStatus.REACHABLE:
733 self.log.debug('ONU is not reachable, cannot send OMCI',
734 serial_number=onu_device.serial_number,
735 intf_id=onu_device.proxy_address.channel_id,
736 onu_id=onu_device.proxy_address.onu_id)
737 return
Matt Jeanneretb428b952019-03-07 05:14:17 -0500738
739 omci = openolt_pb2.OmciMsg(intf_id=onu_device.proxy_address.channel_id,
740 onu_id=onu_device.proxy_address.onu_id, pkt=str(msg))
William Kurkian6f436d02019-02-06 16:25:01 -0500741 self.stub.OmciMsgOut(omci)
742
Matt Jeanneretb428b952019-03-07 05:14:17 -0500743 self.log.debug("omci-message-sent", intf_id=onu_device.proxy_address.channel_id,
744 onu_id=onu_device.proxy_address.onu_id, pkt=str(msg))
745
Matt Jeanneret6e315092019-02-20 10:42:57 -0500746 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500747 def add_onu_device(self, intf_id, port_no, onu_id, serial_number):
Matt Jeanneret5ba87e32019-02-28 11:35:49 -0500748 self.log.info("adding-onu", port_no=port_no, onu_id=onu_id,
William Kurkian6f436d02019-02-06 16:25:01 -0500749 serial_number=serial_number)
750
William Kurkian6f436d02019-02-06 16:25:01 -0500751 serial_number_str = self.stringify_serial_number(serial_number)
752
Matt Jeanneretb428b952019-03-07 05:14:17 -0500753 # TODO NEW CORE dont hardcode child device type. find some way of determining by vendor in serial number
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400754 yield self.core_proxy.child_device_detected(
Matt Jeanneret6e315092019-02-20 10:42:57 -0500755 parent_device_id=self.device_id,
756 parent_port_no=port_no,
757 child_device_type='brcm_openomci_onu',
Matt Jeanneret5ba87e32019-02-28 11:35:49 -0500758 channel_id=intf_id,
759 vendor_id=serial_number.vendor_id,
760 serial_number=serial_number_str,
761 onu_id=onu_id
William Kurkian6f436d02019-02-06 16:25:01 -0500762 )
763
Matt Jeanneret5ba87e32019-02-28 11:35:49 -0500764 self.log.debug("onu-added", onu_id=onu_id, port_no=port_no, serial_number=serial_number_str)
765
Matt Jeannerete33a7092019-03-12 21:54:14 -0400766 def get_ofp_device_info(self, device):
767 self.log.info('get_ofp_device_info', device_id=device.id)
768
769 mfr_desc = self.device_info.vendor
770 sw_desc = self.device_info.firmware_version
771 hw_desc = self.device_info.model
772 if self.device_info.hardware_version: hw_desc += '-' + self.device_info.hardware_version
773
774 return SwitchCapability(
775 desc=ofp_desc(
776 hw_desc=hw_desc,
777 sw_desc=sw_desc,
778 serial_num=device.serial_number
779 ),
780 switch_features=ofp_switch_features(
781 n_buffers=256, # Max packets buffered at once # TODO fake for now
782 n_tables=2, # Number of tables supported by datapath # TODO fake for now
783 capabilities=( #Bitmap of support "ofp_capabilities" # TODO fake for now
784 OFPC_FLOW_STATS
785 | OFPC_TABLE_STATS
786 | OFPC_PORT_STATS
787 | OFPC_GROUP_STATS
788 )
789 )
790 )
791
792 def get_ofp_port_info(self, device, port_no):
793 self.log.info('get_ofp_port_info', port_no=port_no, device_id=device.id)
794 cap = OFPPF_1GB_FD | OFPPF_FIBER
795 return PortCapability(
796 port=LogicalPort(
797 ofp_port=ofp_port(
798 hw_addr=mac_str_to_tuple(self._get_mac_form_port_no(port_no)),
799 config=0,
800 state=OFPPS_LIVE,
801 curr=cap,
802 advertised=cap,
803 peer=cap,
804 curr_speed=OFPPF_1GB_FD,
805 max_speed=OFPPF_1GB_FD
806 ),
807 device_id=device.id,
808 device_port_no=port_no
809 )
810 )
811
William Kurkian6f436d02019-02-06 16:25:01 -0500812 def port_name(self, port_no, port_type, intf_id=None, serial_number=None):
813 if port_type is Port.ETHERNET_NNI:
814 return "nni-" + str(port_no)
815 elif port_type is Port.PON_OLT:
816 return "pon" + str(intf_id)
817 elif port_type is Port.ETHERNET_UNI:
818 assert False, 'local UNI management not supported'
819
William Kurkian6f436d02019-02-06 16:25:01 -0500820 def _get_mac_form_port_no(self, port_no):
821 mac = ''
822 for i in range(4):
823 mac = ':%02x' % ((port_no >> (i * 8)) & 0xff) + mac
824 return '00:00' + mac
825
William Kurkian92bd7122019-02-14 15:26:59 -0500826 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500827 def add_port(self, intf_id, port_type, oper_status):
828 port_no = self.platform.intf_id_to_port_no(intf_id, port_type)
829
830 label = self.port_name(port_no, port_type, intf_id)
831
832 self.log.debug('adding-port', port_no=port_no, label=label,
833 port_type=port_type)
834
835 port = Port(port_no=port_no, label=label, type=port_type,
836 admin_state=AdminState.ENABLED, oper_status=oper_status)
837
Matt Jeanneretbad3d982019-03-11 16:06:10 -0400838 yield self.core_proxy.port_created(self.device_id, port)
William Kurkian6f436d02019-02-06 16:25:01 -0500839
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500840 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500841 def delete_port(self, child_serial_number):
842 ports = self.proxy.get('/devices/{}/ports'.format(
843 self.device_id))
844 for port in ports:
845 if port.label == child_serial_number:
846 self.log.debug('delete-port',
847 onu_serial_number=child_serial_number,
848 port=port)
William Kurkian23047b92019-05-01 11:02:35 -0400849 yield self.core_proxy.port_removed(self.device_id, port)
William Kurkian6f436d02019-02-06 16:25:01 -0500850 return
William Kurkian23047b92019-05-01 11:02:35 -0400851
Matt Jeanneret9dbce8c2019-03-23 14:35:00 -0400852 def update_flow_table(self, flow_changes):
William Kurkian6f436d02019-02-06 16:25:01 -0500853
Matt Jeanneret9dbce8c2019-03-23 14:35:00 -0400854 self.log.debug("update_flow_table", flow_changes=flow_changes)
855
856 flows_to_add = flow_changes.to_add.items
857 flows_to_remove = flow_changes.to_remove.items
858
William Kurkian6f436d02019-02-06 16:25:01 -0500859 if not self.is_state_up():
860 self.log.info('The OLT is not up, we cannot update flows',
861 flows_to_add=[f.id for f in flows_to_add],
862 flows_to_remove=[f.id for f in flows_to_remove])
863 return
864
Matt Jeanneretaa360912019-04-22 16:23:12 -0400865 self.log.debug('flows update', flows_to_add=flows_to_add,
William Kurkian6f436d02019-02-06 16:25:01 -0500866 flows_to_remove=flows_to_remove)
867
868 for flow in flows_to_add:
869
870 try:
871 self.flow_mgr.add_flow(flow)
872 except Exception as e:
873 self.log.error('failed to add flow', flow=flow, e=e)
874
875 for flow in flows_to_remove:
876
877 try:
878 self.flow_mgr.remove_flow(flow)
879 except Exception as e:
880 self.log.error('failed to remove flow', flow=flow, e=e)
881
Matt Jeanneret9dbce8c2019-03-23 14:35:00 -0400882 # TODO NEW CORE: Core keeps track of logical flows. no need to keep track. verify, especially olt reboot!
883 #self.flow_mgr.repush_all_different_flows()
William Kurkian23047b92019-05-01 11:02:35 -0400884
William Kurkian6f436d02019-02-06 16:25:01 -0500885 # There has to be a better way to do this
886 def ip_hex(self, ip):
887 octets = ip.split(".")
888 hex_ip = []
889 for octet in octets:
890 octet_hex = hex(int(octet))
891 octet_hex = octet_hex.split('0x')[1]
892 octet_hex = octet_hex.rjust(2, '0')
893 hex_ip.append(octet_hex)
894 return ":".join(hex_ip)
895
896 def stringify_vendor_specific(self, vendor_specific):
897 return ''.join(str(i) for i in [
898 hex(ord(vendor_specific[0]) >> 4 & 0x0f)[2:],
899 hex(ord(vendor_specific[0]) & 0x0f)[2:],
900 hex(ord(vendor_specific[1]) >> 4 & 0x0f)[2:],
901 hex(ord(vendor_specific[1]) & 0x0f)[2:],
902 hex(ord(vendor_specific[2]) >> 4 & 0x0f)[2:],
903 hex(ord(vendor_specific[2]) & 0x0f)[2:],
904 hex(ord(vendor_specific[3]) >> 4 & 0x0f)[2:],
905 hex(ord(vendor_specific[3]) & 0x0f)[2:]])
906
907 def stringify_serial_number(self, serial_number):
908 return ''.join([serial_number.vendor_id,
909 self.stringify_vendor_specific(
910 serial_number.vendor_specific)])
911
912 def destringify_serial_number(self, serial_number_str):
913 serial_number = openolt_pb2.SerialNumber(
914 vendor_id=serial_number_str[:4].encode('utf-8'),
915 vendor_specific=binascii.unhexlify(serial_number_str[4:]))
916 return serial_number
917
918 def disable(self):
919 self.log.debug('sending-deactivate-olt-message',
920 device_id=self.device_id)
921
922 try:
923 # Send grpc call
924 self.stub.DisableOlt(openolt_pb2.Empty())
925 # The resulting indication will bring the OLT down
926 # self.go_state_down()
927 self.log.info('openolt device disabled')
928 except Exception as e:
929 self.log.error('Failure to disable openolt device', error=e)
930
931 def delete(self):
Matt Jeanneretaa360912019-04-22 16:23:12 -0400932 self.log.info('deleting-olt', device_id=self.device_id)
William Kurkian6f436d02019-02-06 16:25:01 -0500933
934 # Clears up the data from the resource manager KV store
935 # for the device
936 del self.resource_mgr
937
938 try:
939 # Rebooting to reset the state
940 self.reboot()
941 # Removing logical device
William Kurkian6f436d02019-02-06 16:25:01 -0500942 except Exception as e:
943 self.log.error('Failure to delete openolt device', error=e)
944 raise e
945 else:
946 self.log.info('successfully-deleted-olt', device_id=self.device_id)
947
948 def reenable(self):
949 self.log.debug('reenabling-olt', device_id=self.device_id)
950
951 try:
952 self.stub.ReenableOlt(openolt_pb2.Empty())
953
William Kurkian6f436d02019-02-06 16:25:01 -0500954 except Exception as e:
955 self.log.error('Failure to reenable openolt device', error=e)
956 else:
957 self.log.info('openolt device reenabled')
958
959 def activate_onu(self, intf_id, onu_id, serial_number,
960 serial_number_str):
961 pir = self.bw_mgr.pir(serial_number_str)
962 self.log.debug("activating-onu", intf_id=intf_id, onu_id=onu_id,
963 serial_number_str=serial_number_str,
964 serial_number=serial_number, pir=pir)
965 onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id,
966 serial_number=serial_number, pir=pir)
967 self.stub.ActivateOnu(onu)
968 self.log.info('onu-activated', serial_number=serial_number_str)
969
Matt Jeanneretd2f155b2019-02-22 13:49:09 -0500970 @inlineCallbacks
William Kurkian6f436d02019-02-06 16:25:01 -0500971 def delete_child_device(self, child_device):
972 self.log.debug('sending-deactivate-onu',
973 olt_device_id=self.device_id,
974 onu_device=child_device,
975 onu_serial_number=child_device.serial_number)
976 try:
William Kurkian23047b92019-05-01 11:02:35 -0400977 yield self.core_proxy.child_device_removed(self.device_id,
William Kurkian6f436d02019-02-06 16:25:01 -0500978 child_device.id,
979 child_device)
980 except Exception as e:
William Kurkian23047b92019-05-01 11:02:35 -0400981 self.log.error('core_proxy error', error=e)
William Kurkian6f436d02019-02-06 16:25:01 -0500982 try:
983 self.delete_logical_port(child_device)
984 except Exception as e:
985 self.log.error('logical_port delete error', error=e)
986 try:
987 self.delete_port(child_device.serial_number)
988 except Exception as e:
989 self.log.error('port delete error', error=e)
990 serial_number = self.destringify_serial_number(
991 child_device.serial_number)
992 # TODO FIXME - For each uni.
993 # TODO FIXME - Flows are not deleted
994 uni_id = 0 # FIXME
995 self.flow_mgr.delete_tech_profile_instance(
Matt Jeanneret7906d232019-02-14 14:57:38 -0500996 child_device.proxy_address.channel_id,
997 child_device.proxy_address.onu_id,
998 uni_id
William Kurkian6f436d02019-02-06 16:25:01 -0500999 )
1000 pon_intf_id_onu_id = (child_device.proxy_address.channel_id,
1001 child_device.proxy_address.onu_id,
1002 uni_id)
1003 # Free any PON resources that were reserved for the ONU
1004 self.resource_mgr.free_pon_resources_for_onu(pon_intf_id_onu_id)
1005
1006 onu = openolt_pb2.Onu(intf_id=child_device.proxy_address.channel_id,
1007 onu_id=child_device.proxy_address.onu_id,
1008 serial_number=serial_number)
1009 self.stub.DeleteOnu(onu)
1010
1011 def reboot(self):
1012 self.log.debug('rebooting openolt device', device_id=self.device_id)
1013 try:
1014 self.stub.Reboot(openolt_pb2.Empty())
1015 except Exception as e:
1016 self.log.error('something went wrong with the reboot', error=e)
1017 else:
1018 self.log.info('device rebooted')
1019
1020 def trigger_statistics_collection(self):
1021 try:
1022 self.stub.CollectStatistics(openolt_pb2.Empty())
1023 except Exception as e:
1024 self.log.error('Error while triggering statistics collection',
1025 error=e)
1026 else:
1027 self.log.info('statistics requested')
1028
1029 def simulate_alarm(self, alarm):
1030 self.alarm_mgr.simulate_alarm(alarm)