blob: 7ba382b6bb825963274a69101f3fbc5f917e9db6 [file] [log] [blame]
Zsolt Haraszti66862032016-11-28 14:28:39 -08001#
Zsolt Haraszti3eb27a52017-01-03 21:56:48 -08002# Copyright 2017 the original author or authors.
Zsolt Haraszti66862032016-11-28 14:28:39 -08003#
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#
16
17"""
18Agent to play gateway between CORE and an individual adapter.
19"""
20from uuid import uuid4
Stephane Barbarie52198b92017-03-02 13:44:46 -050021import arrow
22import re
Zsolt Haraszti66862032016-11-28 14:28:39 -080023
24import structlog
Zsolt Harasztief05ad22017-01-07 22:08:06 -080025from google.protobuf.json_format import MessageToJson
Zsolt Haraszti8925d1f2016-12-21 00:45:19 -080026from scapy.packet import Packet
Zsolt Haraszti66862032016-11-28 14:28:39 -080027from twisted.internet.defer import inlineCallbacks, returnValue
28from zope.interface import implementer
29
Zsolt Haraszti89a27302016-12-08 16:53:06 -080030from common.event_bus import EventBusClient
Zsolt Harasztief05ad22017-01-07 22:08:06 -080031from common.frameio.frameio import hexify
Zsolt Haraszti66862032016-11-28 14:28:39 -080032from voltha.adapters.interface import IAdapterAgent
33from voltha.protos import third_party
34from voltha.protos.device_pb2 import Device, Port
Stephane Barbariecc6b2e62017-03-02 14:35:55 -050035from voltha.protos.events_pb2 import KpiEvent, AlarmEvent, AlarmEventType, \
36 AlarmEventSeverity, AlarmEventState, AlarmEventCategory
Sergio Slobodriana2eb52b2017-03-07 12:24:46 -050037from voltha.protos.device_pb2 import Device, Port, PmConfigs
38from voltha.protos.events_pb2 import KpiEvent
Zsolt Haraszti66862032016-11-28 14:28:39 -080039from voltha.protos.voltha_pb2 import DeviceGroup, LogicalDevice, \
Khen Nursimulud068d812017-03-06 11:44:18 -050040 LogicalPort, AdminState, OperStatus
Zsolt Haraszti66862032016-11-28 14:28:39 -080041from voltha.registry import registry
Zsolt Haraszti656ecc62016-12-28 15:08:23 -080042from voltha.core.flow_decomposer import OUTPUT
Sergio Slobodriana2eb52b2017-03-07 12:24:46 -050043import sys
Zsolt Haraszti66862032016-11-28 14:28:39 -080044
45
Zsolt Haraszti66862032016-11-28 14:28:39 -080046@implementer(IAdapterAgent)
47class AdapterAgent(object):
48 """
49 Gate-keeper between CORE and device adapters.
50
51 On one side it interacts with Core's internal model and update/dispatch
52 mechanisms.
53
54 On the other side, it interacts with the adapters standard interface as
55 defined in
56 """
57
58 def __init__(self, adapter_name, adapter_cls):
59 self.adapter_name = adapter_name
60 self.adapter_cls = adapter_cls
61 self.core = registry('core')
62 self.adapter = None
63 self.adapter_node_proxy = None
64 self.root_proxy = self.core.get_proxy('/')
Zsolt Haraszti89a27302016-12-08 16:53:06 -080065 self._rx_event_subscriptions = {}
66 self._tx_event_subscriptions = {}
67 self.event_bus = EventBusClient()
Khen Nursimulud068d812017-03-06 11:44:18 -050068 self.packet_out_subscription = None
Zsolt Haraszti89a27302016-12-08 16:53:06 -080069 self.log = structlog.get_logger(adapter_name=adapter_name)
Zsolt Haraszti66862032016-11-28 14:28:39 -080070
71 @inlineCallbacks
72 def start(self):
Zsolt Haraszti89a27302016-12-08 16:53:06 -080073 self.log.debug('starting')
Zsolt Haraszti66862032016-11-28 14:28:39 -080074 config = self._get_adapter_config() # this may be None
Zsolt Haraszti89a27302016-12-08 16:53:06 -080075 try:
76 adapter = self.adapter_cls(self, config)
77 yield adapter.start()
Zsolt Haraszti656ecc62016-12-28 15:08:23 -080078 self.adapter = adapter
79 self.adapter_node_proxy = self._update_adapter_node()
80 self._update_device_types()
Zsolt Haraszti89a27302016-12-08 16:53:06 -080081 except Exception, e:
82 self.log.exception(e)
Zsolt Haraszti89a27302016-12-08 16:53:06 -080083 self.log.info('started')
Zsolt Haraszti66862032016-11-28 14:28:39 -080084 returnValue(self)
85
86 @inlineCallbacks
87 def stop(self):
Zsolt Haraszti89a27302016-12-08 16:53:06 -080088 self.log.debug('stopping')
Zsolt Haraszti66862032016-11-28 14:28:39 -080089 if self.adapter is not None:
90 yield self.adapter.stop()
91 self.adapter = None
Zsolt Haraszti89a27302016-12-08 16:53:06 -080092 self.log.info('stopped')
Zsolt Haraszti66862032016-11-28 14:28:39 -080093
94 def _get_adapter_config(self):
95 """
96 Opportunistically load persisted adapter configuration.
97 Return None if no configuration exists yet.
98 """
99 proxy = self.core.get_proxy('/')
100 try:
101 config = proxy.get('/adapters/' + self.adapter_name)
102 return config
103 except KeyError:
104 return None
105
106 def _update_adapter_node(self):
107 """
108 Creates or updates the adapter node object based on self
109 description from the adapter.
110 """
111
112 adapter_desc = self.adapter.adapter_descriptor()
113 assert adapter_desc.id == self.adapter_name
114 path = self._make_up_to_date(
115 '/adapters', self.adapter_name, adapter_desc)
116 return self.core.get_proxy(path)
117
118 def _update_device_types(self):
119 """
120 Make sure device types are registered in Core
121 """
122 device_types = self.adapter.device_types()
123 for device_type in device_types.items:
124 key = device_type.id
125 self._make_up_to_date('/device_types', key, device_type)
126
127 def _make_up_to_date(self, container_path, key, data):
128 full_path = container_path + '/' + str(key)
129 root_proxy = self.core.get_proxy('/')
130 try:
131 root_proxy.get(full_path)
132 root_proxy.update(full_path, data)
133 except KeyError:
134 root_proxy.add(container_path, data)
135 return full_path
136
Khen Nursimulud068d812017-03-06 11:44:18 -0500137 def _remove_node(self, container_path, key):
138 """
139 Remove a node from the data model
140 :param container_path: path to node
141 :param key: node
142 :return: None
143 """
144 full_path = container_path + '/' + str(key)
145 root_proxy = self.core.get_proxy('/')
146 try:
147 root_proxy.get(full_path)
148 root_proxy.remove(full_path)
149 except KeyError:
150 # Node does not exist
151 pass
152
Zsolt Haraszti66862032016-11-28 14:28:39 -0800153 # ~~~~~~~~~~~~~~~~~~~~~ Core-Facing Service ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154
155 def adopt_device(self, device):
156 return self.adapter.adopt_device(device)
157
158 def abandon_device(self, device):
159 return self.adapter.abandon_device(device)
160
Khen Nursimulud068d812017-03-06 11:44:18 -0500161 def disable_device(self, device):
162 return self.adapter.disable_device(device)
163
164 def reenable_device(self, device):
165 return self.adapter.reenable_device(device)
166
167 def reboot_device(self, device):
168 return self.adapter.reboot_device(device)
169
170 def delete_device(self, device):
171 return self.adapter.delete_device(device)
172
173 def get_device_details(self, device):
174 return self.adapter.get_device_details(device)
Zsolt Haraszti66862032016-11-28 14:28:39 -0800175
Zsolt Harasztic5c5d102016-12-07 21:12:27 -0800176 def update_flows_bulk(self, device, flows, groups):
177 return self.adapter.update_flows_bulk(device, flows, groups)
178
179 def update_flows_incrementally(self, device, flow_changes, group_changes):
180 return self.update_flows_incrementally(
181 device, flow_changes, group_changes)
182
Sergio Slobodriana2eb52b2017-03-07 12:24:46 -0500183 #def update_pm_collection(self, device, pm_collection_config):
184 # return self.adapter.update_pm_collection(device, pm_collection_config)
185
186
Zsolt Haraszti66862032016-11-28 14:28:39 -0800187 # ~~~~~~~~~~~~~~~~~~~ Adapter-Facing Service ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
188
189 def get_device(self, device_id):
190 return self.root_proxy.get('/devices/{}'.format(device_id))
191
192 def add_device(self, device):
193 assert isinstance(device, Device)
194 self._make_up_to_date('/devices', device.id, device)
195
alshabibbe8ca2e2017-02-01 18:28:57 -0800196 # Ultimately, assign devices to device grpups.
197 # see https://jira.opencord.org/browse/CORD-838
Zsolt Haraszti66862032016-11-28 14:28:39 -0800198
199 dg = DeviceGroup(id='1')
200 self._make_up_to_date('/device_groups', dg.id, dg)
201
202 # add device to device group
alshabibbe8ca2e2017-02-01 18:28:57 -0800203 # see https://jira.opencord.org/browse/CORD-838
Zsolt Haraszti66862032016-11-28 14:28:39 -0800204
205 def update_device(self, device):
206 assert isinstance(device, Device)
207
208 # we run the update through the device_agent so that the change
209 # does not loop back to the adapter unnecessarily
210 device_agent = self.core.get_device_agent(device.id)
211 device_agent.update_device(device)
212
Zsolt Haraszti66862032016-11-28 14:28:39 -0800213 def add_port(self, device_id, port):
214 assert isinstance(port, Port)
215
216 # for referential integrity, add/augment references
217 port.device_id = device_id
218 me_as_peer = Port.PeerPort(device_id=device_id, port_no=port.port_no)
219 for peer in port.peers:
220 peer_port_path = '/devices/{}/ports/{}'.format(
221 peer.device_id, peer.port_no)
222 peer_port = self.root_proxy.get(peer_port_path)
223 if me_as_peer not in peer_port.peers:
224 new = peer_port.peers.add()
225 new.CopyFrom(me_as_peer)
226 self.root_proxy.update(peer_port_path, peer_port)
227
228 self._make_up_to_date('/devices/{}/ports'.format(device_id),
229 port.port_no, port)
230
Khen Nursimulud068d812017-03-06 11:44:18 -0500231 def disable_all_ports(self, device_id):
232 """
233 Disable all ports on that device, i.e. change the admin status to
234 disable and operational status to UNKNOWN
235 :param device_id: device id
236 :return: None
237 """
238
239 # get all device ports
240 ports = self.root_proxy.get('/devices/{}/ports'.format(device_id))
241 for port in ports:
242 port.admin_state = AdminState.DISABLED
243 port.oper_status = OperStatus.UNKNOWN
244 self._make_up_to_date('/devices/{}/ports'.format(device_id),
245 port.port_no, port)
246
247 def reenable_all_ports(self, device_id):
248 """
249 Re-enable all ports on that device, i.e. change the admin status to
250 enabled and operational status to ACTIVE
251 :param device_id: device id
252 :return: None
253 """
254
255 # get all device ports
256 ports = self.root_proxy.get('/devices/{}/ports'.format(device_id))
257 for port in ports:
258 port.admin_state = AdminState.ENABLED
259 port.oper_status = OperStatus.ACTIVE
260 self._make_up_to_date('/devices/{}/ports'.format(device_id),
261 port.port_no, port)
262
263 def delete_all_peer_references(self, device_id):
264 """
265 Remove all peer port references for that device
266 :param device_id: device_id of device
267 :return: None
268 """
269 ports = self.root_proxy.get('/devices/{}/ports'.format(device_id))
270 for port in ports:
271 port_path = '/devices/{}/ports/{}'.format(device_id, port.port_no)
272 for peer in port.peers:
273 port.peers.remove(peer)
274 self.root_proxy.update(port_path, port)
275
276 def delete_port_reference_from_parent(self, device_id, port):
277 """
278 Delete the port reference from the parent device
279 :param device_id: id of device containing the port
280 :param port: port to remove
281 :return: None
282 """
283 assert isinstance(port, Port)
284 self.log.info('delete-port-reference', device_id=device_id, port=port)
285
286 # for referential integrity, remove references
287 me_as_peer = Port.PeerPort(device_id=device_id, port_no=port.port_no)
288 for peer in port.peers:
289 peer_port_path = '/devices/{}/ports/{}'.format(
290 peer.device_id, peer.port_no)
291 peer_port = self.root_proxy.get(peer_port_path)
292 if me_as_peer in peer_port.peers:
293 peer_port.peers.remove(me_as_peer)
294 self.root_proxy.update(peer_port_path, peer_port)
295
Zsolt Harasztid036b7e2016-12-23 15:36:01 -0800296 def _find_first_available_id(self):
297 logical_devices = self.root_proxy.get('/logical_devices')
298 existing_ids = set(ld.id for ld in logical_devices)
299 existing_datapath_ids = set(ld.datapath_id for ld in logical_devices)
300 i = 1
301 while True:
302 if i not in existing_datapath_ids and str(i) not in existing_ids:
303 return i
304 i += 1
305
Zsolt Haraszti656ecc62016-12-28 15:08:23 -0800306 def get_logical_device(self, logical_device_id):
307 return self.root_proxy.get('/logical_devices/{}'.format(
308 logical_device_id))
309
Khen Nursimulud068d812017-03-06 11:44:18 -0500310 def get_logical_port(self, logical_device_id, port_id):
311 return self.root_proxy.get('/logical_devices/{}/ports/{}'.format(
312 logical_device_id, port_id))
313
Zsolt Haraszti66862032016-11-28 14:28:39 -0800314 def create_logical_device(self, logical_device):
315 assert isinstance(logical_device, LogicalDevice)
Zsolt Harasztid036b7e2016-12-23 15:36:01 -0800316
317 if not logical_device.id:
318 id = self._find_first_available_id()
319 logical_device.id = str(id)
320 logical_device.datapath_id = id
321
Zsolt Haraszti66862032016-11-28 14:28:39 -0800322 self._make_up_to_date('/logical_devices',
323 logical_device.id, logical_device)
324
Khen Nursimulud068d812017-03-06 11:44:18 -0500325 # Keep a reference to the packet out subscription as it will be
326 # referred during removal
327 self.packet_out_subscription = self.event_bus.subscribe(
Zsolt Haraszti656ecc62016-12-28 15:08:23 -0800328 topic='packet-out:{}'.format(logical_device.id),
329 callback=lambda _, p: self.receive_packet_out(logical_device.id, p)
330 )
331
Zsolt Harasztid036b7e2016-12-23 15:36:01 -0800332 return logical_device
333
Khen Nursimulud068d812017-03-06 11:44:18 -0500334
335 def delete_logical_device(self, logical_device):
336 """
337 This will remove the logical device as well as all logical ports
338 associated with it
339 :param logical_device: The logical device to remove
340 :return: None
341 """
342 assert isinstance(logical_device, LogicalDevice)
343
344 # Remove packet out subscription
345 self.event_bus.unsubscribe(self.packet_out_subscription)
346
347 # Remove node from the data model - this will trigger the logical
348 # device 'remove callbacks' as well as logical ports 'remove
349 # callbacks' if present
350 self._remove_node('/logical_devices', logical_device.id)
351
352
Zsolt Haraszti656ecc62016-12-28 15:08:23 -0800353 def receive_packet_out(self, logical_device_id, ofp_packet_out):
354
355 def get_port_out(opo):
356 for action in opo.actions:
357 if action.type == OUTPUT:
358 return action.output.port
359
360 out_port = get_port_out(ofp_packet_out)
361 frame = ofp_packet_out.data
362 self.adapter.receive_packet_out(logical_device_id, out_port, frame)
363
Zsolt Haraszti66862032016-11-28 14:28:39 -0800364 def add_logical_port(self, logical_device_id, port):
365 assert isinstance(port, LogicalPort)
366 self._make_up_to_date(
367 '/logical_devices/{}/ports'.format(logical_device_id),
368 port.id, port)
369
Khen Nursimulud068d812017-03-06 11:44:18 -0500370 def delete_logical_port(self, logical_device_id, port):
371 assert isinstance(port, LogicalPort)
372 self._remove_node('/logical_devices/{}/ports'.format(
373 logical_device_id), port.id)
374
375 def update_logical_port(self, logical_device_id, port):
376 assert isinstance(port, LogicalPort)
377 self.log.debug('update-logical-port',
378 logical_device_id=logical_device_id,
379 port=port)
380
381 self._make_up_to_date(
382 '/logical_devices/{}/ports'.format(logical_device_id),
383 port.id, port)
384
Zsolt Haraszti66862032016-11-28 14:28:39 -0800385 def child_device_detected(self,
386 parent_device_id,
387 parent_port_no,
388 child_device_type,
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800389 proxy_address,
390 **kw):
Zsolt Haraszti66862032016-11-28 14:28:39 -0800391 # we create new ONU device objects and insert them into the config
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800392 # TODO should we auto-enable the freshly created device? Probably.
Zsolt Haraszti66862032016-11-28 14:28:39 -0800393 device = Device(
394 id=uuid4().hex[:12],
395 type=child_device_type,
396 parent_id=parent_device_id,
397 parent_port_no=parent_port_no,
398 admin_state=AdminState.ENABLED,
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800399 proxy_address=proxy_address,
400 **kw
Zsolt Haraszti66862032016-11-28 14:28:39 -0800401 )
402 self._make_up_to_date(
403 '/devices', device.id, device)
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800404
405 topic = self._gen_tx_proxy_address_topic(proxy_address)
406 self._tx_event_subscriptions[topic] = self.event_bus.subscribe(
407 topic, lambda t, m: self._send_proxied_message(proxy_address, m))
408
Khen Nursimulud068d812017-03-06 11:44:18 -0500409 def remove_all_logical_ports(self, logical_device_id):
410 """ Remove all logical ports from a given logical device"""
411 ports = self.root_proxy.get('/logical_devices/{}/ports')
412 for port in ports:
413 self._remove_node('/logical_devices/{}/ports', port.id)
414
415 def delete_all_child_devices(self, parent_device_id):
416 """ Remove all ONUs from a given OLT """
417 devices = self.root_proxy.get('/devices')
418 children_ids = set(d.id for d in devices if d.parent_id == parent_device_id)
419 self.log.debug('devices-to-delete',
420 parent_id=parent_device_id,
421 children_ids=children_ids)
422 for child_id in children_ids:
423 self._remove_node('/devices', child_id)
424
425 def reenable_all_child_devices(self, parent_device_id):
426 """ Re-enable all ONUs from a given OLT """
427 devices = self.root_proxy.get('/devices')
428 children_ids = set(d.id for d in devices if d.parent_id == parent_device_id)
429 self.log.debug('devices-to-reenable',
430 parent_id=parent_device_id,
431 children_ids=children_ids)
432 for child_id in children_ids:
433 device = self.get_device(child_id)
434 device.admin_state = AdminState.ENABLED
435 self._make_up_to_date(
436 '/devices', device.id, device)
437
438 def disable_all_child_devices(self, parent_device_id):
439 """ Disable all ONUs from a given OLT """
440 devices = self.root_proxy.get('/devices')
441 children_ids = set(d.id for d in devices if d.parent_id == parent_device_id)
442 self.log.debug('devices-to-disable',
443 parent_id=parent_device_id,
444 children_ids=children_ids)
445 for child_id in children_ids:
446 # Change the admin state pf the device to DISABLE
447 device = self.get_device(child_id)
448 device.admin_state = AdminState.DISABLED
449 self._make_up_to_date(
450 '/devices', device.id, device)
451
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800452 def _gen_rx_proxy_address_topic(self, proxy_address):
453 """Generate unique topic name specific to this proxy address for rx"""
Zsolt Harasztief05ad22017-01-07 22:08:06 -0800454 topic = 'rx:' + MessageToJson(proxy_address)
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800455 return topic
456
457 def _gen_tx_proxy_address_topic(self, proxy_address):
458 """Generate unique topic name specific to this proxy address for tx"""
Zsolt Harasztief05ad22017-01-07 22:08:06 -0800459 topic = 'tx:' + MessageToJson(proxy_address)
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800460 return topic
461
462 def register_for_proxied_messages(self, proxy_address):
463 topic = self._gen_rx_proxy_address_topic(proxy_address)
464 self._rx_event_subscriptions[topic] = self.event_bus.subscribe(
Stephane Barbariecc6b2e62017-03-02 14:35:55 -0500465 topic,
466 lambda t, m: self._receive_proxied_message(proxy_address, m))
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800467
Khen Nursimulud068d812017-03-06 11:44:18 -0500468 def unregister_for_proxied_messages(self, proxy_address):
469 topic = self._gen_rx_proxy_address_topic(proxy_address)
470 self.event_bus.unsubscribe(self._rx_event_subscriptions[topic])
471 del self._rx_event_subscriptions[topic]
472
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800473 def _receive_proxied_message(self, proxy_address, msg):
474 self.adapter.receive_proxied_message(proxy_address, msg)
475
476 def send_proxied_message(self, proxy_address, msg):
477 topic = self._gen_tx_proxy_address_topic(proxy_address)
478 self.event_bus.publish(topic, msg)
479
480 def _send_proxied_message(self, proxy_address, msg):
481 self.adapter.send_proxied_message(proxy_address, msg)
482
483 def receive_proxied_message(self, proxy_address, msg):
484 topic = self._gen_rx_proxy_address_topic(proxy_address)
485 self.event_bus.publish(topic, msg)
Zsolt Haraszti8925d1f2016-12-21 00:45:19 -0800486
487 # ~~~~~~~~~~~~~~~~~~ Handling packet-in and packet-out ~~~~~~~~~~~~~~~~~~~~
488
489 def send_packet_in(self, logical_device_id, logical_port_no, packet):
490 self.log.debug('send-packet-in', logical_device_id=logical_device_id,
Zsolt Harasztief05ad22017-01-07 22:08:06 -0800491 logical_port_no=logical_port_no, packet=hexify(packet))
Zsolt Haraszti8925d1f2016-12-21 00:45:19 -0800492
493 if isinstance(packet, Packet):
494 packet = str(packet)
495
496 topic = 'packet-in:' + logical_device_id
497 self.event_bus.publish(topic, (logical_port_no, packet))
Zsolt Haraszti749b0952017-01-18 09:02:35 -0800498
499 # ~~~~~~~~~~~~~~~~~~~ Handling KPI metric submissions ~~~~~~~~~~~~~~~~~~~~~
Zsolt Harasztic5f740b2017-01-18 09:53:17 -0800500
Zsolt Haraszti749b0952017-01-18 09:02:35 -0800501 def submit_kpis(self, kpi_event_msg):
502 try:
503 assert isinstance(kpi_event_msg, KpiEvent)
504 self.event_bus.publish('kpis', kpi_event_msg)
505 except Exception as e:
506 self.log.exception('failed-kpi-submission',
507 type=type(kpi_event_msg))
Stephane Barbarie52198b92017-03-02 13:44:46 -0500508
509 # ~~~~~~~~~~~~~~~~~~~ Handle alarm submissions ~~~~~~~~~~~~~~~~~~~~~
510
Stephane Barbariecc6b2e62017-03-02 14:35:55 -0500511 def create_alarm(self, id=None, resource_id=None, description=None,
512 raised_ts=0, changed_ts=0,
513 type=AlarmEventType.EQUIPMENT,
Stephane Barbariebf3e10c2017-03-03 10:15:58 -0500514 category=AlarmEventCategory.PON,
Stephane Barbariecc6b2e62017-03-02 14:35:55 -0500515 severity=AlarmEventSeverity.MINOR,
516 state=AlarmEventState.RAISED,
Stephane Barbarie52198b92017-03-02 13:44:46 -0500517 context=None):
518
519 # Construct the ID if it is not provided
520 if id == None:
521 id = 'voltha.{}.{}'.format(self.adapter_name, resource_id)
522
523 return AlarmEvent(
524 id=id,
525 resource_id=resource_id,
526 type=type,
527 category=category,
528 severity=severity,
529 state=state,
530 description=description,
531 reported_ts=arrow.utcnow().timestamp,
532 raised_ts=raised_ts,
533 changed_ts=changed_ts,
534 context=context
535 )
536
537 def submit_alarm(self, alarm_event_msg):
538 try:
539 assert isinstance(alarm_event_msg, AlarmEvent)
540 self.event_bus.publish('alarms', alarm_event_msg)
541
542 except Exception as e:
543 self.log.exception('failed-alarm-submission',
544 type=type(alarm_event_msg))