Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.device; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 17 | |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 18 | import org.onlab.util.Tools; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | import org.onosproject.net.Device; |
| 21 | import org.onosproject.net.Port; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 22 | |
Pavlin Radoslavov | 156c2ff | 2014-10-22 22:00:15 -0700 | [diff] [blame] | 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 24 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 25 | /** |
| 26 | * Describes infrastructure device event. |
| 27 | */ |
| 28 | public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { |
| 29 | |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 30 | private final Port port; |
| 31 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Type of device events. |
| 34 | */ |
| 35 | public enum Type { |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Signifies that a new device has been detected. |
| 38 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 39 | DEVICE_ADDED, |
| 40 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 41 | /** |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 42 | * Signifies that some device attributes have changed; excludes |
| 43 | * availability changes. |
| 44 | */ |
| 45 | DEVICE_UPDATED, |
| 46 | |
| 47 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 48 | * Signifies that a device has been removed. |
| 49 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 50 | DEVICE_REMOVED, |
| 51 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 52 | /** |
| 53 | * Signifies that a device has been administratively suspended. |
| 54 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 55 | DEVICE_SUSPENDED, |
| 56 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 57 | /** |
| 58 | * Signifies that a device has come online or has gone offline. |
| 59 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 60 | DEVICE_AVAILABILITY_CHANGED, |
| 61 | |
| 62 | /** |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 63 | * Signifies that a port has been added. |
| 64 | */ |
| 65 | PORT_ADDED, |
| 66 | |
| 67 | /** |
| 68 | * Signifies that a port has been updated. |
| 69 | */ |
| 70 | PORT_UPDATED, |
| 71 | |
| 72 | /** |
| 73 | * Signifies that a port has been removed. |
| 74 | */ |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 75 | PORT_REMOVED, |
| 76 | |
Thomas Vachuska | cb5016f | 2015-05-18 14:11:43 -0700 | [diff] [blame] | 77 | /** |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 78 | * Signifies that port statistics has been updated. |
| 79 | */ |
| 80 | PORT_STATS_UPDATED |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 84 | * 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] | 85 | * current time. |
| 86 | * |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 87 | * @param type device event type |
| 88 | * @param device event device subject |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 89 | */ |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 90 | public DeviceEvent(Type type, Device device) { |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 91 | this(type, device, null); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Creates an event of a given type and for the specified device, port |
| 96 | * and the current time. |
| 97 | * |
| 98 | * @param type device event type |
| 99 | * @param device event device subject |
| 100 | * @param port optional port subject |
| 101 | */ |
| 102 | public DeviceEvent(Type type, Device device, Port port) { |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 103 | super(type, device); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 104 | this.port = port; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 108 | * 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] | 109 | * |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 110 | * @param type device event type |
| 111 | * @param device event device subject |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 112 | * @param port optional port subject |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 113 | * @param time occurrence time |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 114 | */ |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 115 | public DeviceEvent(Type type, Device device, Port port, long time) { |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 116 | super(type, device, time); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 117 | this.port = port; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Returns the port subject. |
| 122 | * |
| 123 | * @return port subject or null if the event is not port specific. |
| 124 | */ |
tom | 0efbb1d | 2014-09-09 11:54:28 -0700 | [diff] [blame] | 125 | public Port port() { |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 126 | return port; |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Pavlin Radoslavov | 156c2ff | 2014-10-22 22:00:15 -0700 | [diff] [blame] | 129 | @Override |
| 130 | public String toString() { |
| 131 | if (port == null) { |
| 132 | return super.toString(); |
| 133 | } |
Yuta HIGUCHI | b87ef95 | 2014-10-28 23:34:23 -0700 | [diff] [blame] | 134 | return toStringHelper(this) |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 135 | .add("time", Tools.defaultOffsetDataTime(time())) |
Yuta HIGUCHI | b87ef95 | 2014-10-28 23:34:23 -0700 | [diff] [blame] | 136 | .add("type", type()) |
| 137 | .add("subject", subject()) |
| 138 | .add("port", port) |
| 139 | .toString(); |
Pavlin Radoslavov | 156c2ff | 2014-10-22 22:00:15 -0700 | [diff] [blame] | 140 | } |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 141 | } |