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. |
| 63 | * @param object. |
| 64 | */ |
| 65 | @Override |
| 66 | public boolean equals(Object obj) { |
| 67 | if (this == obj) { |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | if (obj == null) { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | if (getClass() != obj.getClass()) { |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | TopologyEvent other = (TopologyEvent) obj; |
| 80 | return Objects.equals(switchEvent, other.switchEvent) && |
| 81 | Objects.equals(portEvent, other.portEvent) && |
| 82 | Objects.equals(linkEvent, other.linkEvent) && |
| 83 | Objects.equals(hostEvent, other.hostEvent); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public int hashCode() { |
| 88 | return Objects.hash(switchEvent, portEvent, linkEvent, hostEvent); |
| 89 | } |
| 90 | |
| 91 | /** |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 92 | * Get the string representation of the event. |
| 93 | * |
| 94 | * @return the string representation of the event. |
| 95 | */ |
| 96 | @Override |
| 97 | public String toString() { |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 98 | if (switchEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 99 | return switchEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 100 | } |
| 101 | if (portEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 102 | return portEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 103 | } |
| 104 | if (linkEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 105 | return linkEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 106 | } |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 107 | if (hostEvent != null) { |
| 108 | return hostEvent.toString(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 109 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 110 | return "[Empty TopologyEvent]"; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Get the Topology event ID. |
| 115 | * |
| 116 | * @return the Topology event ID. |
| 117 | */ |
| 118 | public byte[] getID() { |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 119 | if (switchEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 120 | return switchEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 121 | } |
| 122 | if (portEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 123 | return portEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 124 | } |
| 125 | if (linkEvent != null) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 126 | return linkEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 127 | } |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 128 | if (hostEvent != null) { |
| 129 | return hostEvent.getID(); |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 130 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 131 | return null; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 132 | } |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 133 | } |