blob: 9d9b57321c565f7e50712b134dd009fa53e4eeaa [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -08002
weibitcef09862014-07-11 17:05:16 -07003import java.util.Objects;
4
5
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -08006/**
7 * Self-contained Topology event Object
Ray Milkey269ffb92014-04-03 14:43:30 -07008 * <p/>
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -08009 * TODO: For now the topology event contains one of the following events:
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070010 * Switch, Port, Link, Host. In the future it will contain multiple events
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080011 * in a single transaction.
12 */
13public class TopologyEvent {
Ray Milkey269ffb92014-04-03 14:43:30 -070014 SwitchEvent switchEvent = null; // Set for Switch event
15 PortEvent portEvent = null; // Set for Port event
16 LinkEvent linkEvent = null; // Set for Link event
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070017 HostEvent hostEvent = null; // Set for Host event
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080018
19 /**
20 * Default constructor.
21 */
22 public TopologyEvent() {
23 }
24
25 /**
26 * Constructor for given Switch event.
27 *
28 * @param switchEvent the Switch event to use.
29 */
Pavlin Radoslavov87dcc262014-02-19 21:13:23 -080030 TopologyEvent(SwitchEvent switchEvent) {
Ray Milkey269ffb92014-04-03 14:43:30 -070031 this.switchEvent = switchEvent;
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 */
Pavlin Radoslavov87dcc262014-02-19 21:13:23 -080039 TopologyEvent(PortEvent portEvent) {
Ray Milkey269ffb92014-04-03 14:43:30 -070040 this.portEvent = portEvent;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080041 }
42
43 /**
44 * Constructor for given Link event.
45 *
46 * @param linkEvent the Link event to use.
47 */
Pavlin Radoslavov87dcc262014-02-19 21:13:23 -080048 TopologyEvent(LinkEvent linkEvent) {
Ray Milkey269ffb92014-04-03 14:43:30 -070049 this.linkEvent = linkEvent;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080050 }
51
52 /**
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070053 * Constructor for given Host event.
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080054 *
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070055 * @param hostEvent the Host event to use.
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080056 */
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070057 TopologyEvent(HostEvent hostEvent) {
58 this.hostEvent = hostEvent;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080059 }
60
61 /**
weibitcef09862014-07-11 17:05:16 -070062 * Check if all events contained are equal.
63 * @param object.
64 */
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70
71 if (obj == null) {
72 return false;
73 }
74
75 if (getClass() != obj.getClass()) {
76 return false;
77 }
78
79 TopologyEvent other = (TopologyEvent) obj;
80 return Objects.equals(switchEvent, other.switchEvent) &&
81 Objects.equals(portEvent, other.portEvent) &&
82 Objects.equals(linkEvent, other.linkEvent) &&
83 Objects.equals(hostEvent, other.hostEvent);
84 }
85
86 @Override
87 public int hashCode() {
88 return Objects.hash(switchEvent, portEvent, linkEvent, hostEvent);
89 }
90
91 /**
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080092 * Get the string representation of the event.
93 *
94 * @return the string representation of the event.
95 */
96 @Override
97 public String toString() {
Ray Milkeyb29e6262014-04-09 16:02:14 -070098 if (switchEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -070099 return switchEvent.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700100 }
101 if (portEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700102 return portEvent.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700103 }
104 if (linkEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700105 return linkEvent.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700106 }
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700107 if (hostEvent != null) {
108 return hostEvent.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700109 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700110 return "[Empty TopologyEvent]";
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -0800111 }
112
113 /**
114 * Get the Topology event ID.
115 *
116 * @return the Topology event ID.
117 */
118 public byte[] getID() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700119 if (switchEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700120 return switchEvent.getID();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700121 }
122 if (portEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700123 return portEvent.getID();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700124 }
125 if (linkEvent != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700126 return linkEvent.getID();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700127 }
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700128 if (hostEvent != null) {
129 return hostEvent.getID();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700130 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700131 return null;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -0800132 }
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -0800133}