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 | |
| 7 | /** |
| 8 | * Describes infrastructure device event. |
| 9 | */ |
| 10 | public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { |
| 11 | |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 12 | private final Port port; |
| 13 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 14 | /** |
| 15 | * Type of device events. |
| 16 | */ |
| 17 | public enum Type { |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 18 | /** |
| 19 | * Signifies that a new device has been detected. |
| 20 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 21 | DEVICE_ADDED, |
| 22 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 23 | /** |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 24 | * Signifies that some device attributes have changed; excludes |
| 25 | * availability changes. |
| 26 | */ |
| 27 | DEVICE_UPDATED, |
| 28 | |
| 29 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 30 | * Signifies that a device has been removed. |
| 31 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 32 | DEVICE_REMOVED, |
| 33 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 34 | /** |
| 35 | * Signifies that a device has been administratively suspended. |
| 36 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 37 | DEVICE_SUSPENDED, |
| 38 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Signifies that a device has come online or has gone offline. |
| 41 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 42 | DEVICE_AVAILABILITY_CHANGED, |
| 43 | |
| 44 | /** |
| 45 | * Signifies that the current controller instance relationship has |
| 46 | * changed with respect to a device. |
| 47 | */ |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 48 | 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 |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 67 | * 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] | 68 | * current time. |
| 69 | * |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 70 | * @param type device event type |
| 71 | * @param device event device subject |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 72 | */ |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 73 | public DeviceEvent(Type type, Device device) { |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 74 | 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) { |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 86 | super(type, device); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 87 | this.port = port; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 91 | * 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] | 92 | * |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 93 | * @param type device event type |
| 94 | * @param device event device subject |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 95 | * @param port optional port subject |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 96 | * @param time occurrence time |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 97 | */ |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 98 | public DeviceEvent(Type type, Device device, Port port, long time) { |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 99 | super(type, device, time); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 100 | 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 | */ |
tom | 0efbb1d | 2014-09-09 11:54:28 -0700 | [diff] [blame] | 108 | public Port port() { |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 109 | return port; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | } |