blob: 07bd42608baf7ac63e32010469ac96cdd2976212 [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
Pavlin Radoslavov156c2ff2014-10-22 22:00:15 -07007import static com.google.common.base.MoreObjects.toStringHelper;
8
tome33cc1a2014-08-25 21:59:41 -07009/**
10 * Describes infrastructure device event.
11 */
12public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> {
13
tom29df6f42014-09-05 08:14:14 -070014 private final Port port;
15
tome33cc1a2014-08-25 21:59:41 -070016 /**
17 * Type of device events.
18 */
19 public enum Type {
tom64b7aac2014-08-26 00:18:21 -070020 /**
21 * Signifies that a new device has been detected.
22 */
tome33cc1a2014-08-25 21:59:41 -070023 DEVICE_ADDED,
24
tom64b7aac2014-08-26 00:18:21 -070025 /**
tome5ec3fd2014-09-04 15:18:06 -070026 * Signifies that some device attributes have changed; excludes
27 * availability changes.
28 */
29 DEVICE_UPDATED,
30
31 /**
tom64b7aac2014-08-26 00:18:21 -070032 * Signifies that a device has been removed.
33 */
tome33cc1a2014-08-25 21:59:41 -070034 DEVICE_REMOVED,
35
tom64b7aac2014-08-26 00:18:21 -070036 /**
37 * Signifies that a device has been administratively suspended.
38 */
tome33cc1a2014-08-25 21:59:41 -070039 DEVICE_SUSPENDED,
40
tom64b7aac2014-08-26 00:18:21 -070041 /**
42 * Signifies that a device has come online or has gone offline.
43 */
tome33cc1a2014-08-25 21:59:41 -070044 DEVICE_AVAILABILITY_CHANGED,
45
46 /**
47 * Signifies that the current controller instance relationship has
48 * changed with respect to a device.
49 */
tom29df6f42014-09-05 08:14:14 -070050 DEVICE_MASTERSHIP_CHANGED,
51
52 /**
53 * Signifies that a port has been added.
54 */
55 PORT_ADDED,
56
57 /**
58 * Signifies that a port has been updated.
59 */
60 PORT_UPDATED,
61
62 /**
63 * Signifies that a port has been removed.
64 */
65 PORT_REMOVED
tome33cc1a2014-08-25 21:59:41 -070066 }
67
68 /**
tom64b7aac2014-08-26 00:18:21 -070069 * Creates an event of a given type and for the specified device and the
tome33cc1a2014-08-25 21:59:41 -070070 * current time.
71 *
tom64b7aac2014-08-26 00:18:21 -070072 * @param type device event type
73 * @param device event device subject
tome33cc1a2014-08-25 21:59:41 -070074 */
tom64b7aac2014-08-26 00:18:21 -070075 public DeviceEvent(Type type, Device device) {
tom29df6f42014-09-05 08:14:14 -070076 this(type, device, null);
77 }
78
79 /**
80 * Creates an event of a given type and for the specified device, port
81 * and the current time.
82 *
83 * @param type device event type
84 * @param device event device subject
85 * @param port optional port subject
86 */
87 public DeviceEvent(Type type, Device device, Port port) {
tom64b7aac2014-08-26 00:18:21 -070088 super(type, device);
tom29df6f42014-09-05 08:14:14 -070089 this.port = port;
tome33cc1a2014-08-25 21:59:41 -070090 }
91
92 /**
tom64b7aac2014-08-26 00:18:21 -070093 * Creates an event of a given type and for the specified device and time.
tome33cc1a2014-08-25 21:59:41 -070094 *
tom64b7aac2014-08-26 00:18:21 -070095 * @param type device event type
96 * @param device event device subject
tom29df6f42014-09-05 08:14:14 -070097 * @param port optional port subject
tom64b7aac2014-08-26 00:18:21 -070098 * @param time occurrence time
tome33cc1a2014-08-25 21:59:41 -070099 */
tom29df6f42014-09-05 08:14:14 -0700100 public DeviceEvent(Type type, Device device, Port port, long time) {
tom64b7aac2014-08-26 00:18:21 -0700101 super(type, device, time);
tom29df6f42014-09-05 08:14:14 -0700102 this.port = port;
103 }
104
105 /**
106 * Returns the port subject.
107 *
108 * @return port subject or null if the event is not port specific.
109 */
tom0efbb1d2014-09-09 11:54:28 -0700110 public Port port() {
tom29df6f42014-09-05 08:14:14 -0700111 return port;
tome33cc1a2014-08-25 21:59:41 -0700112 }
113
Pavlin Radoslavov156c2ff2014-10-22 22:00:15 -0700114 @Override
115 public String toString() {
116 if (port == null) {
117 return super.toString();
118 }
119 return toStringHelper(this).add("time", time()).add("type", type())
120 .add("subject", subject()).add("port", port).toString();
121 }
tome33cc1a2014-08-25 21:59:41 -0700122}