blob: 397fac56d6c41966e3410336e5aa2e5e57e514a6 [file] [log] [blame]
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -08001package 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 */
10public class TopologyEvent {
Yuta HIGUCHI170229f2014-02-17 15:47:54 -080011 public static final String NOBODY = "";
12 String originID = NOBODY;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080013 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 HIGUCHI170229f2014-02-17 15:47:54 -080029 TopologyEvent(SwitchEvent switchEvent, String originID) {
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080030 this.switchEvent = switchEvent;
Yuta HIGUCHI170229f2014-02-17 15:47:54 -080031 setOriginID(originID);
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080032 }
33
34 /**
35 * Constructor for given Port event.
36 *
37 * @param portEvent the Port event to use.
38 */
Yuta HIGUCHI170229f2014-02-17 15:47:54 -080039 TopologyEvent(PortEvent portEvent, String originID) {
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080040 this.portEvent = portEvent;
Yuta HIGUCHI170229f2014-02-17 15:47:54 -080041 setOriginID(originID);
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080042 }
43
44 /**
45 * Constructor for given Link event.
46 *
47 * @param linkEvent the Link event to use.
48 */
Yuta HIGUCHI170229f2014-02-17 15:47:54 -080049 TopologyEvent(LinkEvent linkEvent, String originID) {
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080050 this.linkEvent = linkEvent;
Yuta HIGUCHI170229f2014-02-17 15:47:54 -080051 setOriginID(originID);
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080052 }
53
54 /**
55 * Constructor for given Device event.
56 *
57 * @param deviceEvent the Device event to use.
58 */
Yuta HIGUCHI170229f2014-02-17 15:47:54 -080059 TopologyEvent(DeviceEvent deviceEvent, String originID) {
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080060 this.deviceEvent = deviceEvent;
Yuta HIGUCHI170229f2014-02-17 15:47:54 -080061 setOriginID(originID);
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080062 }
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();
79 return null;
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 HIGUCHI170229f2014-02-17 15:47:54 -080098
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 Radoslavov45ec04b2014-02-14 23:29:33 -0800110}