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 | |
| 5 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 6 | /** |
| 7 | * Self-contained Topology event Object |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 8 | * <p/> |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 9 | * TODO: For now the topology event contains one of the following events: |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 10 | * Switch, Port, Link, Host. In the future it will contain multiple events |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 11 | * in a single transaction. |
| 12 | */ |
| 13 | public class TopologyEvent { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 14 | SwitchEvent switchEvent = null; // Set for Switch event |
| 15 | PortEvent portEvent = null; // Set for Port event |
| 16 | LinkEvent linkEvent = null; // Set for Link event |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 17 | HostEvent hostEvent = null; // Set for Host event |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 18 | |
| 19 | /** |
| 20 | * Default constructor. |
| 21 | */ |
| 22 | public TopologyEvent() { |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Constructor for given Switch event. |
| 27 | * |
| 28 | * @param switchEvent the Switch event to use. |
| 29 | */ |
Pavlin Radoslavov | 87dcc26 | 2014-02-19 21:13:23 -0800 | [diff] [blame] | 30 | TopologyEvent(SwitchEvent switchEvent) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 31 | this.switchEvent = switchEvent; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Constructor for given Port event. |
| 36 | * |
| 37 | * @param portEvent the Port event to use. |
| 38 | */ |
Pavlin Radoslavov | 87dcc26 | 2014-02-19 21:13:23 -0800 | [diff] [blame] | 39 | TopologyEvent(PortEvent portEvent) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 40 | this.portEvent = portEvent; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Constructor for given Link event. |
| 45 | * |
| 46 | * @param linkEvent the Link event to use. |
| 47 | */ |
Pavlin Radoslavov | 87dcc26 | 2014-02-19 21:13:23 -0800 | [diff] [blame] | 48 | TopologyEvent(LinkEvent linkEvent) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 49 | this.linkEvent = linkEvent; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /** |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 53 | * Constructor for given Host event. |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 54 | * |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 55 | * @param hostEvent the Host event to use. |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 56 | */ |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 57 | TopologyEvent(HostEvent hostEvent) { |
| 58 | this.hostEvent = hostEvent; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
weibit | cef0986 | 2014-07-11 17:05:16 -0700 | [diff] [blame] | 62 | * Check if all events contained are equal. |
Yuta HIGUCHI | ccab05d | 2014-07-26 22:42:28 -0700 | [diff] [blame] | 63 | * |
| 64 | * @param obj TopologyEvent to compare against |
weibit | cef0986 | 2014-07-11 17:05:16 -0700 | [diff] [blame] | 65 | */ |
| 66 | @Override |
| 67 | public boolean equals(Object obj) { |
| 68 | if (this == obj) { |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | if (obj == null) { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | if (getClass() != obj.getClass()) { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | TopologyEvent other = (TopologyEvent) obj; |
| 81 | return Objects.equals(switchEvent, other.switchEvent) && |
| 82 | Objects.equals(portEvent, other.portEvent) && |
| 83 | Objects.equals(linkEvent, other.linkEvent) && |
| 84 | Objects.equals(hostEvent, other.hostEvent); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public int hashCode() { |
| 89 | return Objects.hash(switchEvent, portEvent, linkEvent, hostEvent); |
| 90 | } |
| 91 | |
| 92 | /** |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 93 | * Get the string representation of the event. |
| 94 | * |
| 95 | * @return the string representation of the event. |
| 96 | */ |
| 97 | @Override |
| 98 | public String toString() { |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 99 | if (switchEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 100 | return switchEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 101 | } |
| 102 | if (portEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 103 | return portEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 104 | } |
| 105 | if (linkEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 106 | return linkEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 107 | } |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 108 | if (hostEvent != null) { |
| 109 | return hostEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 110 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 111 | return "[Empty TopologyEvent]"; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Get the Topology event ID. |
| 116 | * |
| 117 | * @return the Topology event ID. |
| 118 | */ |
| 119 | public byte[] getID() { |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 120 | if (switchEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 121 | return switchEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 122 | } |
| 123 | if (portEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 124 | return portEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 125 | } |
| 126 | if (linkEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 127 | return linkEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 128 | } |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 129 | if (hostEvent != null) { |
| 130 | return hostEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 131 | } |
Ray Milkey | 9289721 | 2014-07-21 10:33:16 -0700 | [diff] [blame] | 132 | throw new IllegalStateException("Invalid TopologyEvent ID"); |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 133 | } |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 134 | } |