blob: 85ebe031ef1fff804e25b73531856e951c01b9e1 [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -08002
3/**
4 * Self-contained Topology event Object
Ray Milkey269ffb92014-04-03 14:43:30 -07005 * <p/>
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -08006 * 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 */
10public class TopologyEvent {
Ray Milkey269ffb92014-04-03 14:43:30 -070011 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
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080015
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 Radoslavov87dcc262014-02-19 21:13:23 -080027 TopologyEvent(SwitchEvent switchEvent) {
Ray Milkey269ffb92014-04-03 14:43:30 -070028 this.switchEvent = switchEvent;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080029 }
30
31 /**
32 * Constructor for given Port event.
33 *
34 * @param portEvent the Port event to use.
35 */
Pavlin Radoslavov87dcc262014-02-19 21:13:23 -080036 TopologyEvent(PortEvent portEvent) {
Ray Milkey269ffb92014-04-03 14:43:30 -070037 this.portEvent = portEvent;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080038 }
39
40 /**
41 * Constructor for given Link event.
42 *
43 * @param linkEvent the Link event to use.
44 */
Pavlin Radoslavov87dcc262014-02-19 21:13:23 -080045 TopologyEvent(LinkEvent linkEvent) {
Ray Milkey269ffb92014-04-03 14:43:30 -070046 this.linkEvent = linkEvent;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080047 }
48
49 /**
50 * Constructor for given Device event.
51 *
52 * @param deviceEvent the Device event to use.
53 */
Pavlin Radoslavov87dcc262014-02-19 21:13:23 -080054 TopologyEvent(DeviceEvent deviceEvent) {
Ray Milkey269ffb92014-04-03 14:43:30 -070055 this.deviceEvent = deviceEvent;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080056 }
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() {
Ray Milkeyb29e6262014-04-09 16:02:14 -070065 if (switchEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -070066 return switchEvent.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -070067 }
68 if (portEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -070069 return portEvent.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -070070 }
71 if (linkEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -070072 return linkEvent.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -070073 }
74 if (deviceEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -070075 return deviceEvent.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -070076 }
Ray Milkey269ffb92014-04-03 14:43:30 -070077 return "[Empty TopologyEvent]";
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080078 }
79
80 /**
81 * Get the Topology event ID.
82 *
83 * @return the Topology event ID.
84 */
85 public byte[] getID() {
Ray Milkeyb29e6262014-04-09 16:02:14 -070086 if (switchEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -070087 return switchEvent.getID();
Ray Milkeyb29e6262014-04-09 16:02:14 -070088 }
89 if (portEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -070090 return portEvent.getID();
Ray Milkeyb29e6262014-04-09 16:02:14 -070091 }
92 if (linkEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -070093 return linkEvent.getID();
Ray Milkeyb29e6262014-04-09 16:02:14 -070094 }
95 if (deviceEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -070096 return deviceEvent.getID();
Ray Milkeyb29e6262014-04-09 16:02:14 -070097 }
Ray Milkey269ffb92014-04-03 14:43:30 -070098 return null;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080099 }
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -0800100}