blob: 4f3dd20675644908c8e4c7b168b7188d51d6204b [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 Milkey269ffb92014-04-03 14:43:30 -070065 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();
73 return "[Empty TopologyEvent]";
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080074 }
75
76 /**
77 * Get the Topology event ID.
78 *
79 * @return the Topology event ID.
80 */
81 public byte[] getID() {
Ray Milkey269ffb92014-04-03 14:43:30 -070082 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;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080091 }
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080092}