* Misc. fixes/updates to the TopologyElement implementation.
* Add missing TopologyElement related registrations to the Kryo serializer.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyElement.java b/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyElement.java
index 6809125..dfc799f 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyElement.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyElement.java
@@ -1,5 +1,8 @@
package net.onrc.onos.ofcontroller.topology;
+import java.util.Map;
+import java.util.TreeMap;
+
/**
* Class for storing information about a Topology Element: Switch, Port or
* Link.
@@ -8,7 +11,8 @@
/**
* The Element Type.
*/
- enum Type {
+ public enum Type {
+ ELEMENT_UNKNOWN, // Unknown element
ELEMENT_SWITCH, // Network Switch
ELEMENT_PORT, // Switch Port
ELEMENT_LINK // Unidirectional Link between Switch Ports
@@ -20,6 +24,16 @@
private long toSwitchDpid = 0; // The Neighbor Switch DPID
private int toSwitchPort = 0; // The Neighbor Switch Port
+ // All (known) ports for a Switch
+ private Map<Integer, Integer> switchPorts = new TreeMap<Integer, Integer>();
+
+ /**
+ * Default constructor.
+ */
+ public TopologyElement() {
+ elementType = Type.ELEMENT_UNKNOWN;
+ }
+
/**
* Constructor to create a Topology Element for a Switch.
*
@@ -61,27 +75,121 @@
}
/**
+ * Get the Element type.
+ *
+ * @return the Element type.
+ */
+ public TopologyElement.Type getType() {
+ return elementType;
+ }
+
+ /**
+ * Get the Switch Ports.
+ *
+ * NOTE: Applies for Type.ELEMENT_SWITCH
+ *
+ * @return the collection of Switch Ports.
+ */
+ public Map<Integer, Integer> getSwitchPorts() {
+ return switchPorts;
+ }
+
+ /**
+ * Add a Switch Port.
+ *
+ * NOTE: Applies for Type.ELEMENT_SWITCH
+ *
+ * @param switchPort the Switch Port to add.
+ */
+ public void addSwitchPort(int switchPort) {
+ switchPorts.put(switchPort, switchPort);
+ }
+
+ /**
+ * Get the Switch DPID.
+ *
+ * NOTE: Applies for Type.ELEMENT_SWITCH and Type.ELEMENT_PORT
+ *
+ * @return the Switch DPID.
+ */
+ public long getSwitch() {
+ return fromSwitchDpid;
+ }
+
+ /**
+ * Get the Switch Port.
+ *
+ * NOTE: Applies for Type.ELEMENT_PORT
+ *
+ * @return the Switch Port.
+ */
+ public int getSwitchPort() {
+ return fromSwitchPort;
+ }
+
+ /**
+ * Get the Switch DPID the Link begins from.
+ *
+ * NOTE: Applies for Type.ELEMENT_LINK
+ */
+ public long getFromSwitch() {
+ return fromSwitchDpid;
+ }
+
+ /**
+ * Get the Switch Port the Link begins from.
+ *
+ * NOTE: Applies for Type.ELEMENT_LINK
+ */
+ public int getFromPort() {
+ return fromSwitchPort;
+ }
+
+ /**
+ * Get the Switch DPID the Link ends to.
+ *
+ * NOTE: Applies for Type.ELEMENT_LINK
+ */
+ public long getToSwitch() {
+ return toSwitchDpid;
+ }
+
+ /**
+ * Get the Switch Port the Link ends to.
+ *
+ * NOTE: Applies for Type.ELEMENT_LINK
+ */
+ public int getToPort() {
+ return toSwitchPort;
+ }
+
+ /**
* Get the Topology Element ID.
*
* The Topology Element ID has the following format:
- * - Switch: "Switch=<Dpid>"
- * Example: "Switch=00:00:00:00:00:00:00:01"
- * - Switch Port: "Port=<Dpid>/<PortId>"
- * Example: "Port=00:00:00:00:00:00:00:01/1"
- * - Link: "Link=<FromDpid>/<FromPortId>/<ToDpid>/<ToPortId>"
- * Example: "Link=00:00:00:00:00:00:00:01/1/00:00:00:00:00:00:00:02/1"
+ * - Switch: "Switch=<HexLongDpid>"
+ * Example: "Switch=101"
+ * - Switch Port: "Port=<HexLongDpid>/<IntPortId>"
+ * Example: "Port=102/1"
+ * - Link: "Link=<FromHexLongDpid>/<FromIntPortId>/<ToHexLongDpid>/<ToIntPortId>"
+ * Example: "Link=101/2/103/4"
+ *
+ * NOTE: The Topology Element ID has no syntax meaning. It is used only to
+ * uniquely identify a topology element.
*
* @return the Topology Element ID.
*/
public String elementId() {
switch (elementType) {
case ELEMENT_SWITCH:
- return "Switch=" + fromSwitchDpid;
+ return "Switch=" + Long.toHexString(fromSwitchDpid);
case ELEMENT_PORT:
- return "Port=" + fromSwitchDpid + "/" + fromSwitchPort;
+ return "Port=" +
+ Long.toHexString(fromSwitchDpid) + "/" + fromSwitchPort;
case ELEMENT_LINK:
- return "Link=" + fromSwitchDpid + "/" + fromSwitchPort +
- toSwitchDpid + "/" + toSwitchPort;
+ return "Link=" +
+ Long.toHexString(fromSwitchDpid) + "/" + fromSwitchPort + "/" +
+ Long.toHexString(toSwitchDpid) + "/" + toSwitchPort;
}
assert(false);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java b/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java
index e0da7a8..507cb99 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java
@@ -1,6 +1,7 @@
package net.onrc.onos.ofcontroller.util.serializers;
import java.util.ArrayList;
+import java.util.TreeMap;
import com.esotericsoftware.kryo2.Kryo;
@@ -124,6 +125,8 @@
// Topology-related classes
kryo.register(TopologyElement.class);
+ kryo.register(TopologyElement.Type.class);
+ kryo.register(TreeMap.class);
return kryo;
}