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