Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [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 | */ |
| 16 | package org.onosproject.iptopology.api.device; |
| 17 | |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 18 | import org.onlab.util.Tools; |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | import org.onosproject.iptopology.api.DeviceIntf; |
| 21 | import org.onosproject.iptopology.api.DevicePrefix; |
| 22 | import org.onosproject.iptopology.api.IpDevice; |
| 23 | |
| 24 | |
| 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | |
| 27 | /** |
| 28 | * Describes ip device event. |
| 29 | */ |
| 30 | public class IpDeviceEvent extends AbstractEvent<IpDeviceEvent.Type, IpDevice> { |
| 31 | |
| 32 | private final DeviceIntf devInterface; |
| 33 | private final DevicePrefix devicePrefix; |
| 34 | |
| 35 | /** |
| 36 | * Type of device events. |
| 37 | */ |
| 38 | public enum Type { |
| 39 | /** |
| 40 | * Signifies that a new device has been detected. |
| 41 | */ |
| 42 | DEVICE_ADDED, |
| 43 | |
| 44 | /** |
| 45 | * Signifies that some device attributes have changed; excludes |
| 46 | * availability changes. |
| 47 | */ |
| 48 | DEVICE_UPDATED, |
| 49 | |
| 50 | /** |
| 51 | * Signifies that a device has been removed. |
| 52 | */ |
| 53 | DEVICE_REMOVED, |
| 54 | |
| 55 | /** |
| 56 | * Signifies that an interface has been added. |
| 57 | */ |
| 58 | INTERFACE_ADDED, |
| 59 | |
| 60 | /** |
| 61 | * Signifies that an interface has been updated. |
| 62 | */ |
| 63 | INTERFACE_UPDATED, |
| 64 | |
| 65 | /** |
| 66 | * Signifies that an interface has been removed. |
| 67 | */ |
| 68 | INTERFACE_REMOVED, |
| 69 | |
| 70 | /** |
| 71 | * Signifies that a prefix has been added. |
| 72 | */ |
| 73 | PREFIX_ADDED, |
| 74 | |
| 75 | /** |
| 76 | * Signifies that a prefix has been updated. |
| 77 | */ |
| 78 | PREFIX_UPDATED, |
| 79 | |
| 80 | /** |
| 81 | * Signifies that a prefix has been removed. |
| 82 | */ |
| 83 | PREFIX_REMOVED, |
| 84 | |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Creates an event of a given type and for the specified ip device. |
| 89 | * |
| 90 | * @param type device event type |
| 91 | * @param device event device subject |
| 92 | */ |
| 93 | public IpDeviceEvent(Type type, IpDevice device) { |
| 94 | this(type, device, null, null); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Creates an event of a given type and for the specified device and interface. |
| 99 | * |
| 100 | * @param type device event type |
| 101 | * @param device event device subject |
| 102 | * @param devInterface optional interface subject |
| 103 | */ |
| 104 | public IpDeviceEvent(Type type, IpDevice device, DeviceIntf devInterface) { |
| 105 | this(type, device, devInterface, null); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Creates an event of a given type and for the specified device and interface. |
| 110 | * |
| 111 | * @param type device event type |
| 112 | * @param device event device subject |
| 113 | * @param devicePrefix optional prefix subject |
| 114 | */ |
| 115 | public IpDeviceEvent(Type type, IpDevice device, DevicePrefix devicePrefix) { |
| 116 | this(type, device, null, devicePrefix); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | /** |
| 121 | * Creates an event of a given type and for the specified device, interface and prefix. |
| 122 | * |
| 123 | * @param type device event type |
| 124 | * @param device event device subject |
| 125 | * @param devInterface optional interface subject |
| 126 | * @param devicePrefix optional prefix subject |
| 127 | */ |
| 128 | public IpDeviceEvent(Type type, IpDevice device, DeviceIntf devInterface, DevicePrefix devicePrefix) { |
| 129 | super(type, device); |
| 130 | this.devInterface = devInterface; |
| 131 | this.devicePrefix = devicePrefix; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | /** |
| 136 | * Creates an event of a given type and for the specified device, interface and time. |
| 137 | * |
| 138 | * @param type device event type |
| 139 | * @param device event device subject |
| 140 | * @param devInterface optional interface subject |
| 141 | * @param devicePrefix optional prefix subject |
| 142 | * @param time occurrence time |
| 143 | */ |
| 144 | |
| 145 | public IpDeviceEvent(Type type, IpDevice device, DeviceIntf devInterface, DevicePrefix devicePrefix, long time) { |
| 146 | super(type, device, time); |
| 147 | this.devInterface = devInterface; |
| 148 | this.devicePrefix = devicePrefix; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | /** |
| 153 | * Returns the interface subject. |
| 154 | * |
| 155 | * @return interface subject or null if the event is not interface specific. |
| 156 | */ |
| 157 | public DeviceIntf deviceInterface() { |
| 158 | return devInterface; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Returns the prefix subject. |
| 163 | * |
| 164 | * @return prefix subject or null if the event is not prefix specific. |
| 165 | */ |
| 166 | public DevicePrefix prefix() { |
| 167 | return devicePrefix; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public String toString() { |
| 172 | if (devInterface == null || devicePrefix == null) { |
| 173 | return super.toString(); |
| 174 | } |
| 175 | return toStringHelper(this) |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 176 | .add("time", Tools.defaultOffsetDataTime(time())) |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 177 | .add("type", type()) |
| 178 | .add("subject", subject()) |
| 179 | .add("interface", devInterface) |
| 180 | .add("prefix", devicePrefix) |
| 181 | .toString(); |
| 182 | } |
| 183 | } |