Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.networkgraph; |
| 2 | |
| 3 | /** |
| 4 | * Self-contained Topology event Object |
| 5 | * |
| 6 | * TODO: For now the topology event contains one of the following events: |
| 7 | * Switch, Port, Link, Device. In the future it will contain multiple events |
| 8 | * in a single transaction. |
| 9 | */ |
| 10 | public class TopologyEvent { |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 11 | public static final String NOBODY = ""; |
| 12 | String originID = NOBODY; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 13 | SwitchEvent switchEvent = null; // Set for Switch event |
| 14 | PortEvent portEvent = null; // Set for Port event |
| 15 | LinkEvent linkEvent = null; // Set for Link event |
| 16 | DeviceEvent deviceEvent = null; // Set for Device event |
| 17 | |
| 18 | /** |
| 19 | * Default constructor. |
| 20 | */ |
| 21 | public TopologyEvent() { |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Constructor for given Switch event. |
| 26 | * |
| 27 | * @param switchEvent the Switch event to use. |
| 28 | */ |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 29 | TopologyEvent(SwitchEvent switchEvent, String originID) { |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 30 | this.switchEvent = switchEvent; |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 31 | setOriginID(originID); |
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 | */ |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 39 | TopologyEvent(PortEvent portEvent, String originID) { |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 40 | this.portEvent = portEvent; |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 41 | setOriginID(originID); |
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 | */ |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 49 | TopologyEvent(LinkEvent linkEvent, String originID) { |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 50 | this.linkEvent = linkEvent; |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 51 | setOriginID(originID); |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Constructor for given Device event. |
| 56 | * |
| 57 | * @param deviceEvent the Device event to use. |
| 58 | */ |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 59 | TopologyEvent(DeviceEvent deviceEvent, String originID) { |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 60 | this.deviceEvent = deviceEvent; |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 61 | setOriginID(originID); |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get the string representation of the event. |
| 66 | * |
| 67 | * @return the string representation of the event. |
| 68 | */ |
| 69 | @Override |
| 70 | public String toString() { |
| 71 | if (switchEvent != null) |
| 72 | return switchEvent.toString(); |
| 73 | if (portEvent != null) |
| 74 | return portEvent.toString(); |
| 75 | if (linkEvent != null) |
| 76 | return linkEvent.toString(); |
| 77 | if (deviceEvent != null) |
| 78 | return deviceEvent.toString(); |
Yuta HIGUCHI | 1a8029a | 2014-02-18 12:49:28 -0800 | [diff] [blame] | 79 | return "[Empty TopologyEvent]"; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Get the Topology event ID. |
| 84 | * |
| 85 | * @return the Topology event ID. |
| 86 | */ |
| 87 | public byte[] getID() { |
| 88 | if (switchEvent != null) |
| 89 | return switchEvent.getID(); |
| 90 | if (portEvent != null) |
| 91 | return portEvent.getID(); |
| 92 | if (linkEvent != null) |
| 93 | return linkEvent.getID(); |
| 94 | if (deviceEvent != null) |
| 95 | return deviceEvent.getID(); |
| 96 | return null; |
| 97 | } |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 98 | |
| 99 | public String getOriginID() { |
| 100 | return originID; |
| 101 | } |
| 102 | |
| 103 | void setOriginID(String originID) { |
| 104 | if (originID != null) { |
| 105 | this.originID = originID; |
| 106 | } else { |
| 107 | this.originID = NOBODY; |
| 108 | } |
| 109 | } |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 110 | } |