blob: 84cd5cb02343283dc8bdddedb6719e14a3331d3a [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
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 */
10public 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 Radoslavov87dcc262014-02-19 21:13:23 -080027 TopologyEvent(SwitchEvent switchEvent) {
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080028 this.switchEvent = switchEvent;
29 }
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) {
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080037 this.portEvent = portEvent;
38 }
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) {
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080046 this.linkEvent = linkEvent;
47 }
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) {
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080055 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 HIGUCHI1a8029a2014-02-18 12:49:28 -080073 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() {
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 Radoslavov45ec04b2014-02-14 23:29:33 -080092}