tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.device; |
| 2 | |
| 3 | import org.onlab.onos.event.AbstractEvent; |
| 4 | import org.onlab.onos.net.Device; |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 5 | import org.onlab.onos.net.Port; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 6 | |
Pavlin Radoslavov | 156c2ff | 2014-10-22 22:00:15 -0700 | [diff] [blame] | 7 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 8 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 9 | /** |
| 10 | * Describes infrastructure device event. |
| 11 | */ |
| 12 | public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { |
| 13 | |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 14 | private final Port port; |
| 15 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 16 | /** |
| 17 | * Type of device events. |
| 18 | */ |
| 19 | public enum Type { |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 20 | /** |
| 21 | * Signifies that a new device has been detected. |
| 22 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 23 | DEVICE_ADDED, |
| 24 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 25 | /** |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 26 | * Signifies that some device attributes have changed; excludes |
| 27 | * availability changes. |
| 28 | */ |
| 29 | DEVICE_UPDATED, |
| 30 | |
| 31 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 32 | * Signifies that a device has been removed. |
| 33 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 34 | DEVICE_REMOVED, |
| 35 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Signifies that a device has been administratively suspended. |
| 38 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 39 | DEVICE_SUSPENDED, |
| 40 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 41 | /** |
| 42 | * Signifies that a device has come online or has gone offline. |
| 43 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 44 | DEVICE_AVAILABILITY_CHANGED, |
| 45 | |
| 46 | /** |
| 47 | * Signifies that the current controller instance relationship has |
| 48 | * changed with respect to a device. |
| 49 | */ |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 50 | 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 |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 69 | * Creates an event of a given type and for the specified device and the |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 70 | * current time. |
| 71 | * |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 72 | * @param type device event type |
| 73 | * @param device event device subject |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 74 | */ |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 75 | public DeviceEvent(Type type, Device device) { |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 76 | 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) { |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 88 | super(type, device); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 89 | this.port = port; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 93 | * Creates an event of a given type and for the specified device and time. |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 94 | * |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 95 | * @param type device event type |
| 96 | * @param device event device subject |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 97 | * @param port optional port subject |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 98 | * @param time occurrence time |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 99 | */ |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 100 | public DeviceEvent(Type type, Device device, Port port, long time) { |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 101 | super(type, device, time); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 102 | 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 | */ |
tom | 0efbb1d | 2014-09-09 11:54:28 -0700 | [diff] [blame] | 110 | public Port port() { |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 111 | return port; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Pavlin Radoslavov | 156c2ff | 2014-10-22 22:00:15 -0700 | [diff] [blame] | 114 | @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 | } |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 122 | } |