Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 2 | |
weibit | cef0986 | 2014-07-11 17:05:16 -0700 | [diff] [blame] | 3 | import java.util.Objects; |
| 4 | |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 5 | import net.onrc.onos.core.util.OnosInstanceId; |
| 6 | |
| 7 | import static com.google.common.base.Preconditions.checkNotNull; |
weibit | cef0986 | 2014-07-11 17:05:16 -0700 | [diff] [blame] | 8 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 9 | /** |
| 10 | * Self-contained Topology event Object |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 11 | * <p/> |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 12 | * TODO: For now the topology event contains one of the following events: |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 13 | * Switch, Port, Link, Host, Switch Mastership. In the future it will contain |
| 14 | * multiple events in a single transaction. |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 15 | * TODO: This class should become immutable after its internals and usage |
| 16 | * are finalized. |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 17 | */ |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 18 | public final class TopologyEvent { |
| 19 | private final SwitchEvent switchEvent; // Set for Switch event |
| 20 | private final PortEvent portEvent; // Set for Port event |
| 21 | private final LinkEvent linkEvent; // Set for Link event |
| 22 | private final HostEvent hostEvent; // Set for Host event |
| 23 | private final MastershipEvent mastershipEvent; // Set for Mastership event |
| 24 | private final OnosInstanceId onosInstanceId; // The ONOS Instance ID |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 27 | * Default constructor for serializer. |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 28 | */ |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 29 | @Deprecated |
| 30 | protected TopologyEvent() { |
| 31 | switchEvent = null; |
| 32 | portEvent = null; |
| 33 | linkEvent = null; |
| 34 | hostEvent = null; |
| 35 | mastershipEvent = null; |
| 36 | onosInstanceId = null; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Constructor for given Switch event. |
| 41 | * |
| 42 | * @param switchEvent the Switch event to use. |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 43 | * @param onosInstanceId the ONOS Instance ID that originates the event. |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 44 | */ |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 45 | TopologyEvent(SwitchEvent switchEvent, OnosInstanceId onosInstanceId) { |
| 46 | this.switchEvent = checkNotNull(switchEvent); |
| 47 | this.portEvent = null; |
| 48 | this.linkEvent = null; |
| 49 | this.hostEvent = null; |
| 50 | this.mastershipEvent = null; |
| 51 | this.onosInstanceId = checkNotNull(onosInstanceId); |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Constructor for given Port event. |
| 56 | * |
| 57 | * @param portEvent the Port event to use. |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 58 | * @param onosInstanceId the ONOS Instance ID that originates the event. |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 59 | */ |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 60 | TopologyEvent(PortEvent portEvent, OnosInstanceId onosInstanceId) { |
| 61 | this.switchEvent = null; |
| 62 | this.portEvent = checkNotNull(portEvent); |
| 63 | this.linkEvent = null; |
| 64 | this.hostEvent = null; |
| 65 | this.mastershipEvent = null; |
| 66 | this.onosInstanceId = checkNotNull(onosInstanceId); |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Constructor for given Link event. |
| 71 | * |
| 72 | * @param linkEvent the Link event to use. |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 73 | * @param onosInstanceId the ONOS Instance ID that originates the event. |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 74 | */ |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 75 | TopologyEvent(LinkEvent linkEvent, OnosInstanceId onosInstanceId) { |
| 76 | this.switchEvent = null; |
| 77 | this.portEvent = null; |
| 78 | this.linkEvent = checkNotNull(linkEvent); |
| 79 | this.hostEvent = null; |
| 80 | this.mastershipEvent = null; |
| 81 | this.onosInstanceId = checkNotNull(onosInstanceId); |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 85 | * Constructor for given Host event. |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 86 | * |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 87 | * @param hostEvent the Host event to use. |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 88 | * @param onosInstanceId the ONOS Instance ID that originates the event. |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 89 | */ |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 90 | TopologyEvent(HostEvent hostEvent, OnosInstanceId onosInstanceId) { |
| 91 | this.switchEvent = null; |
| 92 | this.portEvent = null; |
| 93 | this.linkEvent = null; |
| 94 | this.hostEvent = checkNotNull(hostEvent); |
| 95 | this.mastershipEvent = null; |
| 96 | this.onosInstanceId = checkNotNull(onosInstanceId); |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 100 | * Constructor for given Switch Mastership event. |
| 101 | * |
| 102 | * @param mastershipEvent the Switch Mastership event to use. |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 103 | * @param onosInstanceId the ONOS Instance ID that originates the event. |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 104 | */ |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 105 | TopologyEvent(MastershipEvent mastershipEvent, |
| 106 | OnosInstanceId onosInstanceId) { |
| 107 | this.switchEvent = null; |
| 108 | this.portEvent = null; |
| 109 | this.linkEvent = null; |
| 110 | this.hostEvent = null; |
| 111 | this.mastershipEvent = checkNotNull(mastershipEvent); |
| 112 | this.onosInstanceId = checkNotNull(onosInstanceId); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Gets the Switch event. |
| 117 | * |
| 118 | * @return the Switch event. |
| 119 | */ |
| 120 | public SwitchEvent getSwitchEvent() { |
| 121 | return switchEvent; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Gets the Port event. |
| 126 | * |
| 127 | * @return the Port event. |
| 128 | */ |
| 129 | public PortEvent getPortEvent() { |
| 130 | return portEvent; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Gets the Link event. |
| 135 | * |
| 136 | * @return the Link event. |
| 137 | */ |
| 138 | public LinkEvent getLinkEvent() { |
| 139 | return linkEvent; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Gets the Host event. |
| 144 | * |
| 145 | * @return the Host event. |
| 146 | */ |
| 147 | public HostEvent getHostEvent() { |
| 148 | return hostEvent; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Gets the Mastership event. |
| 153 | * |
| 154 | * @return the Mastership event. |
| 155 | */ |
| 156 | public MastershipEvent getMastershipEvent() { |
| 157 | return mastershipEvent; |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /** |
weibit | cef0986 | 2014-07-11 17:05:16 -0700 | [diff] [blame] | 161 | * Check if all events contained are equal. |
Yuta HIGUCHI | ccab05d | 2014-07-26 22:42:28 -0700 | [diff] [blame] | 162 | * |
| 163 | * @param obj TopologyEvent to compare against |
weibit | cef0986 | 2014-07-11 17:05:16 -0700 | [diff] [blame] | 164 | */ |
| 165 | @Override |
| 166 | public boolean equals(Object obj) { |
| 167 | if (this == obj) { |
| 168 | return true; |
| 169 | } |
| 170 | |
| 171 | if (obj == null) { |
| 172 | return false; |
| 173 | } |
| 174 | |
| 175 | if (getClass() != obj.getClass()) { |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | TopologyEvent other = (TopologyEvent) obj; |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 180 | // TODO: For now the onosInstanceId is not used |
weibit | cef0986 | 2014-07-11 17:05:16 -0700 | [diff] [blame] | 181 | return Objects.equals(switchEvent, other.switchEvent) && |
| 182 | Objects.equals(portEvent, other.portEvent) && |
| 183 | Objects.equals(linkEvent, other.linkEvent) && |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 184 | Objects.equals(hostEvent, other.hostEvent) && |
| 185 | Objects.equals(mastershipEvent, other.mastershipEvent); |
weibit | cef0986 | 2014-07-11 17:05:16 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public int hashCode() { |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 190 | // TODO: For now the onosInstanceId is not used |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 191 | return Objects.hash(switchEvent, portEvent, linkEvent, hostEvent, |
| 192 | mastershipEvent); |
weibit | cef0986 | 2014-07-11 17:05:16 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 196 | * Get the string representation of the event. |
| 197 | * |
| 198 | * @return the string representation of the event. |
| 199 | */ |
| 200 | @Override |
| 201 | public String toString() { |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 202 | // TODO: For now the onosInstanceId is not used |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 203 | if (switchEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 204 | return switchEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 205 | } |
| 206 | if (portEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 207 | return portEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 208 | } |
| 209 | if (linkEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 210 | return linkEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 211 | } |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 212 | if (hostEvent != null) { |
| 213 | return hostEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 214 | } |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 215 | if (mastershipEvent != null) { |
| 216 | return mastershipEvent.toString(); |
| 217 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 218 | return "[Empty TopologyEvent]"; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Get the Topology event ID. |
| 223 | * |
| 224 | * @return the Topology event ID. |
| 225 | */ |
| 226 | public byte[] getID() { |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame^] | 227 | // TODO: For now the onosInstanceId is not used |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 228 | if (switchEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 229 | return switchEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 230 | } |
| 231 | if (portEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 232 | return portEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 233 | } |
| 234 | if (linkEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 235 | return linkEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 236 | } |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 237 | if (hostEvent != null) { |
| 238 | return hostEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 239 | } |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 240 | if (mastershipEvent != null) { |
| 241 | return mastershipEvent.getID(); |
| 242 | } |
Ray Milkey | 9289721 | 2014-07-21 10:33:16 -0700 | [diff] [blame] | 243 | throw new IllegalStateException("Invalid TopologyEvent ID"); |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 244 | } |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 245 | } |