blob: 0a3377709beb5667c22a9b21453575aca0e22367 [file] [log] [blame]
tome33cc1a2014-08-25 21:59:41 -07001package org.onlab.onos.net.device;
2
3import org.onlab.onos.event.AbstractEvent;
4import org.onlab.onos.net.Device;
tom29df6f42014-09-05 08:14:14 -07005import org.onlab.onos.net.Port;
tome33cc1a2014-08-25 21:59:41 -07006
7/**
8 * Describes infrastructure device event.
9 */
10public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> {
11
tom29df6f42014-09-05 08:14:14 -070012 private final Port port;
13
tome33cc1a2014-08-25 21:59:41 -070014 /**
15 * Type of device events.
16 */
17 public enum Type {
tom64b7aac2014-08-26 00:18:21 -070018 /**
19 * Signifies that a new device has been detected.
20 */
tome33cc1a2014-08-25 21:59:41 -070021 DEVICE_ADDED,
22
tom64b7aac2014-08-26 00:18:21 -070023 /**
tome5ec3fd2014-09-04 15:18:06 -070024 * Signifies that some device attributes have changed; excludes
25 * availability changes.
26 */
27 DEVICE_UPDATED,
28
29 /**
tom64b7aac2014-08-26 00:18:21 -070030 * Signifies that a device has been removed.
31 */
tome33cc1a2014-08-25 21:59:41 -070032 DEVICE_REMOVED,
33
tom64b7aac2014-08-26 00:18:21 -070034 /**
35 * Signifies that a device has been administratively suspended.
36 */
tome33cc1a2014-08-25 21:59:41 -070037 DEVICE_SUSPENDED,
38
tom64b7aac2014-08-26 00:18:21 -070039 /**
40 * Signifies that a device has come online or has gone offline.
41 */
tome33cc1a2014-08-25 21:59:41 -070042 DEVICE_AVAILABILITY_CHANGED,
43
44 /**
45 * Signifies that the current controller instance relationship has
46 * changed with respect to a device.
47 */
tom29df6f42014-09-05 08:14:14 -070048 DEVICE_MASTERSHIP_CHANGED,
49
50 /**
51 * Signifies that a port has been added.
52 */
53 PORT_ADDED,
54
55 /**
56 * Signifies that a port has been updated.
57 */
58 PORT_UPDATED,
59
60 /**
61 * Signifies that a port has been removed.
62 */
63 PORT_REMOVED
tome33cc1a2014-08-25 21:59:41 -070064 }
65
66 /**
tom64b7aac2014-08-26 00:18:21 -070067 * Creates an event of a given type and for the specified device and the
tome33cc1a2014-08-25 21:59:41 -070068 * current time.
69 *
tom64b7aac2014-08-26 00:18:21 -070070 * @param type device event type
71 * @param device event device subject
tome33cc1a2014-08-25 21:59:41 -070072 */
tom64b7aac2014-08-26 00:18:21 -070073 public DeviceEvent(Type type, Device device) {
tom29df6f42014-09-05 08:14:14 -070074 this(type, device, null);
75 }
76
77 /**
78 * Creates an event of a given type and for the specified device, port
79 * and the current time.
80 *
81 * @param type device event type
82 * @param device event device subject
83 * @param port optional port subject
84 */
85 public DeviceEvent(Type type, Device device, Port port) {
tom64b7aac2014-08-26 00:18:21 -070086 super(type, device);
tom29df6f42014-09-05 08:14:14 -070087 this.port = port;
tome33cc1a2014-08-25 21:59:41 -070088 }
89
90 /**
tom64b7aac2014-08-26 00:18:21 -070091 * Creates an event of a given type and for the specified device and time.
tome33cc1a2014-08-25 21:59:41 -070092 *
tom64b7aac2014-08-26 00:18:21 -070093 * @param type device event type
94 * @param device event device subject
tom29df6f42014-09-05 08:14:14 -070095 * @param port optional port subject
tom64b7aac2014-08-26 00:18:21 -070096 * @param time occurrence time
tome33cc1a2014-08-25 21:59:41 -070097 */
tom29df6f42014-09-05 08:14:14 -070098 public DeviceEvent(Type type, Device device, Port port, long time) {
tom64b7aac2014-08-26 00:18:21 -070099 super(type, device, time);
tom29df6f42014-09-05 08:14:14 -0700100 this.port = port;
101 }
102
103 /**
104 * Returns the port subject.
105 *
106 * @return port subject or null if the event is not port specific.
107 */
tom0efbb1d2014-09-09 11:54:28 -0700108 public Port port() {
tom29df6f42014-09-05 08:14:14 -0700109 return port;
tome33cc1a2014-08-25 21:59:41 -0700110 }
111
112}