Topology events related modifications:
* Added new class TopologyEvent which encapsulates one of the following
events: Switch event, Port event, Link event, Device event
* Added getID() method to the new TopologyEvent class, and to each
of the concrete topology related events.
* Added default constructors, because they are needed for Kryo-related
deserialization
* Added Kryo registration for the new classes.
Change-Id: I61233b3176a7124bdf9e906da9f5efdc663b3003
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/DeviceEvent.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/DeviceEvent.java
index fa7a761..a4c3450 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/DeviceEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/DeviceEvent.java
@@ -28,6 +28,14 @@
protected List<SwitchPort> attachmentPoints;
protected Set<InetAddress> ipAddresses;
+
+ /**
+ * Default constructor.
+ */
+ public DeviceEvent() {
+ mac = null;
+ }
+
public DeviceEvent(MACAddress mac) {
if (mac == null) {
throw new IllegalArgumentException("Device mac cannot be null");
@@ -78,5 +86,7 @@
.array();
}
-
+ public byte[] getID() {
+ return getDeviceID(mac.toBytes());
+ }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java
index 81f9ba3..c8cf71e 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java
@@ -14,6 +14,14 @@
private final SwitchPort src;
private final SwitchPort dst;
+ /**
+ * Default constructor.
+ */
+ public LinkEvent() {
+ src = null;
+ dst = null;
+ }
+
public LinkEvent(Long src_dpid, Long src_port_no, Long dst_dpid,
Long dst_port_no) {
@@ -44,4 +52,8 @@
.put(PortEvent.getPortID(dst_dpid, dst_port_no)).array();
}
+ public byte[] getID() {
+ return getLinkID(src.getDpid(), src.getNumber(),
+ dst.getDpid(), dst.getNumber());
+ }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java
index e4caee5..b42bf1e 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java
@@ -13,6 +13,14 @@
public final Long dpid;
public final Long number;
+ /**
+ * Default constructor.
+ */
+ public SwitchPort() {
+ dpid = null;
+ number = null;
+ }
+
public SwitchPort(Long dpid, Long number) {
this.dpid = dpid;
this.number = number;
@@ -37,6 +45,13 @@
// TODO Add Hardware Address
// TODO Add Description
+ /**
+ * Default constructor.
+ */
+ public PortEvent() {
+ id = null;
+ }
+
public PortEvent(Long dpid, Long number) {
this.id = new SwitchPort(dpid, number);
}
@@ -67,4 +82,7 @@
.putChar('P').putLong(number).array();
}
+ public byte[] getID() {
+ return getPortID(getDpid(), getNumber());
+ }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchEvent.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchEvent.java
index 58532ae..dce0725 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchEvent.java
@@ -15,6 +15,13 @@
private List<PortEvent> ports;
+ /**
+ * Default constructor.
+ */
+ public SwitchEvent() {
+ dpid = null;
+ }
+
public SwitchEvent(Long dpid) {
this(dpid, new ArrayList<PortEvent>());
}
@@ -51,4 +58,7 @@
.array();
}
+ public byte[] getID() {
+ return getSwitchID(dpid);
+ }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyEvent.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyEvent.java
new file mode 100644
index 0000000..927d266
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyEvent.java
@@ -0,0 +1,92 @@
+package net.onrc.onos.ofcontroller.networkgraph;
+
+/**
+ * Self-contained Topology event Object
+ *
+ * TODO: For now the topology event contains one of the following events:
+ * Switch, Port, Link, Device. In the future it will contain multiple events
+ * in a single transaction.
+ */
+public class TopologyEvent {
+ SwitchEvent switchEvent = null; // Set for Switch event
+ PortEvent portEvent = null; // Set for Port event
+ LinkEvent linkEvent = null; // Set for Link event
+ DeviceEvent deviceEvent = null; // Set for Device event
+
+ /**
+ * Default constructor.
+ */
+ public TopologyEvent() {
+ }
+
+ /**
+ * Constructor for given Switch event.
+ *
+ * @param switchEvent the Switch event to use.
+ */
+ TopologyEvent(SwitchEvent switchEvent) {
+ this.switchEvent = switchEvent;
+ }
+
+ /**
+ * Constructor for given Port event.
+ *
+ * @param portEvent the Port event to use.
+ */
+ TopologyEvent(PortEvent portEvent) {
+ this.portEvent = portEvent;
+ }
+
+ /**
+ * Constructor for given Link event.
+ *
+ * @param linkEvent the Link event to use.
+ */
+ TopologyEvent(LinkEvent linkEvent) {
+ this.linkEvent = linkEvent;
+ }
+
+ /**
+ * Constructor for given Device event.
+ *
+ * @param deviceEvent the Device event to use.
+ */
+ TopologyEvent(DeviceEvent deviceEvent) {
+ this.deviceEvent = deviceEvent;
+ }
+
+ /**
+ * Get the string representation of the event.
+ *
+ * @return the string representation of the event.
+ */
+ @Override
+ public String toString() {
+ if (switchEvent != null)
+ return switchEvent.toString();
+ if (portEvent != null)
+ return portEvent.toString();
+ if (linkEvent != null)
+ return linkEvent.toString();
+ if (deviceEvent != null)
+ return deviceEvent.toString();
+ return null;
+ }
+
+ /**
+ * Get the Topology event ID.
+ *
+ * @return the Topology event ID.
+ */
+ public byte[] getID() {
+ if (switchEvent != null)
+ return switchEvent.getID();
+ if (portEvent != null)
+ return portEvent.getID();
+ if (linkEvent != null)
+ return linkEvent.getID();
+ if (deviceEvent != null)
+ return deviceEvent.getID();
+ return null;
+ }
+}