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 { |
| 11 | SwitchEvent switchEvent = null; // Set for Switch event |
| 12 | PortEvent portEvent = null; // Set for Port event |
| 13 | LinkEvent linkEvent = null; // Set for Link event |
| 14 | DeviceEvent deviceEvent = null; // Set for Device event |
| 15 | |
| 16 | /** |
| 17 | * Default constructor. |
| 18 | */ |
| 19 | public TopologyEvent() { |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Constructor for given Switch event. |
| 24 | * |
| 25 | * @param switchEvent the Switch event to use. |
| 26 | */ |
Pavlin Radoslavov | 87dcc26 | 2014-02-19 21:13:23 -0800 | [diff] [blame] | 27 | TopologyEvent(SwitchEvent switchEvent) { |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 28 | this.switchEvent = switchEvent; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Constructor for given Port event. |
| 33 | * |
| 34 | * @param portEvent the Port event to use. |
| 35 | */ |
Pavlin Radoslavov | 87dcc26 | 2014-02-19 21:13:23 -0800 | [diff] [blame] | 36 | TopologyEvent(PortEvent portEvent) { |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 37 | this.portEvent = portEvent; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Constructor for given Link event. |
| 42 | * |
| 43 | * @param linkEvent the Link event to use. |
| 44 | */ |
Pavlin Radoslavov | 87dcc26 | 2014-02-19 21:13:23 -0800 | [diff] [blame] | 45 | TopologyEvent(LinkEvent linkEvent) { |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 46 | this.linkEvent = linkEvent; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Constructor for given Device event. |
| 51 | * |
| 52 | * @param deviceEvent the Device event to use. |
| 53 | */ |
Pavlin Radoslavov | 87dcc26 | 2014-02-19 21:13:23 -0800 | [diff] [blame] | 54 | TopologyEvent(DeviceEvent deviceEvent) { |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 55 | this.deviceEvent = deviceEvent; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Get the string representation of the event. |
| 60 | * |
| 61 | * @return the string representation of the event. |
| 62 | */ |
| 63 | @Override |
| 64 | public String toString() { |
| 65 | if (switchEvent != null) |
| 66 | return switchEvent.toString(); |
| 67 | if (portEvent != null) |
| 68 | return portEvent.toString(); |
| 69 | if (linkEvent != null) |
| 70 | return linkEvent.toString(); |
| 71 | if (deviceEvent != null) |
| 72 | return deviceEvent.toString(); |
Yuta HIGUCHI | 1a8029a | 2014-02-18 12:49:28 -0800 | [diff] [blame] | 73 | return "[Empty TopologyEvent]"; |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Get the Topology event ID. |
| 78 | * |
| 79 | * @return the Topology event ID. |
| 80 | */ |
| 81 | public byte[] getID() { |
| 82 | if (switchEvent != null) |
| 83 | return switchEvent.getID(); |
| 84 | if (portEvent != null) |
| 85 | return portEvent.getID(); |
| 86 | if (linkEvent != null) |
| 87 | return linkEvent.getID(); |
| 88 | if (deviceEvent != null) |
| 89 | return deviceEvent.getID(); |
| 90 | return null; |
| 91 | } |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 92 | } |