Move ID byte[] generation code to Event object
Change-Id: Iaf8812d8fa8d99f085dd4d4217a8ab6454608c2a
diff --git a/src/main/java/net/onrc/onos/datastore/topology/RCDevice.java b/src/main/java/net/onrc/onos/datastore/topology/RCDevice.java
index a431490..8d696ed 100644
--- a/src/main/java/net/onrc/onos/datastore/topology/RCDevice.java
+++ b/src/main/java/net/onrc/onos/datastore/topology/RCDevice.java
@@ -21,6 +21,7 @@
import net.onrc.onos.datastore.topology.RCLink.STATUS;
import net.onrc.onos.datastore.utils.ByteArrayComparator;
import net.onrc.onos.datastore.utils.ByteArrayUtil;
+import net.onrc.onos.ofcontroller.networkgraph.DeviceEvent;
public class RCDevice extends RCObject {
@SuppressWarnings("unused")
@@ -53,8 +54,7 @@
// Assuming mac is unique cluster-wide
public static byte[] getDeviceID(final byte[] mac) {
- return ByteBuffer.allocate(2 + mac.length).putChar('D').put(mac)
- .array();
+ return DeviceEvent.getDeviceID(mac);
}
public static StringBuilder keysToSB(Collection<byte[]> keys) {
diff --git a/src/main/java/net/onrc/onos/datastore/topology/RCLink.java b/src/main/java/net/onrc/onos/datastore/topology/RCLink.java
index caf446d..9ce8857 100644
--- a/src/main/java/net/onrc/onos/datastore/topology/RCLink.java
+++ b/src/main/java/net/onrc/onos/datastore/topology/RCLink.java
@@ -15,6 +15,8 @@
import edu.stanford.ramcloud.JRamCloud;
import net.onrc.onos.datastore.RCObject;
import net.onrc.onos.datastore.RCTable;
+import net.onrc.onos.ofcontroller.networkgraph.LinkEvent;
+import net.onrc.onos.ofcontroller.networkgraph.PortEvent;
public class RCLink extends RCObject {
@SuppressWarnings("unused")
@@ -77,13 +79,10 @@
private final SwitchPort dst;
private STATUS status;
- public static final int LINKID_BYTES = 2 + RCPort.PORTID_BYTES * 2;
-
public static byte[] getLinkID(Long src_dpid, Long src_port_no,
Long dst_dpid, Long dst_port_no) {
- return ByteBuffer.allocate(LINKID_BYTES).putChar('L')
- .put(RCPort.getPortID(src_dpid, src_port_no))
- .put(RCPort.getPortID(dst_dpid, dst_port_no)).array();
+ return LinkEvent.getLinkID(src_dpid, src_port_no, dst_dpid,
+ dst_port_no);
}
public static StringBuilder keysToSB(Collection<byte[]> keys) {
@@ -118,7 +117,7 @@
throw new IllegalArgumentException("Invalid Link key");
}
long src_port_pair[] = RCPort.getPortPairFromKey(keyBuf.slice());
- keyBuf.position(2 + RCPort.PORTID_BYTES);
+ keyBuf.position(2 + PortEvent.PORTID_BYTES);
long dst_port_pair[] = RCPort.getPortPairFromKey(keyBuf.slice());
tuple[0] = src_port_pair[0];
diff --git a/src/main/java/net/onrc/onos/datastore/topology/RCPort.java b/src/main/java/net/onrc/onos/datastore/topology/RCPort.java
index b1f3bef..c3cdf86 100644
--- a/src/main/java/net/onrc/onos/datastore/topology/RCPort.java
+++ b/src/main/java/net/onrc/onos/datastore/topology/RCPort.java
@@ -21,6 +21,7 @@
import net.onrc.onos.datastore.RCTable;
import net.onrc.onos.datastore.utils.ByteArrayComparator;
import net.onrc.onos.datastore.utils.ByteArrayUtil;
+import net.onrc.onos.ofcontroller.networkgraph.PortEvent;
public class RCPort extends RCObject {
private static final Logger log = LoggerFactory.getLogger(RCPort.class);
@@ -69,17 +70,8 @@
@Deprecated
transient boolean isDeviceIdsModified;
- public static final int PORTID_BYTES = RCSwitch.SWITCHID_BYTES + 2 + 8;
-
public static byte[] getPortID(Long dpid, Long number) {
- if (dpid == null) {
- throw new IllegalArgumentException("dpid cannot be null");
- }
- if (number == null) {
- throw new IllegalArgumentException("number cannot be null");
- }
- return ByteBuffer.allocate(PORTID_BYTES).putChar('S').putLong(dpid)
- .putChar('P').putLong(number).array();
+ return PortEvent.getPortID(dpid, number);
}
public static StringBuilder keysToSB(Collection<byte[]> keys) {
diff --git a/src/main/java/net/onrc/onos/datastore/topology/RCSwitch.java b/src/main/java/net/onrc/onos/datastore/topology/RCSwitch.java
index 3b00084..a0dd037 100644
--- a/src/main/java/net/onrc/onos/datastore/topology/RCSwitch.java
+++ b/src/main/java/net/onrc/onos/datastore/topology/RCSwitch.java
@@ -14,6 +14,7 @@
import net.onrc.onos.datastore.RCObject;
import net.onrc.onos.datastore.RCTable;
import net.onrc.onos.datastore.utils.ByteArrayComparator;
+import net.onrc.onos.ofcontroller.networkgraph.SwitchEvent;
import org.openflow.util.HexString;
import org.slf4j.Logger;
@@ -70,14 +71,8 @@
@Deprecated
transient private boolean isPortIdsModified;
- public static final int SWITCHID_BYTES = 2 + 8;
-
public static byte[] getSwitchID(Long dpid) {
- if (dpid == null) {
- throw new IllegalArgumentException("dpid cannot be null");
- }
- return ByteBuffer.allocate(SWITCHID_BYTES).putChar('S').putLong(dpid)
- .array();
+ return SwitchEvent.getSwitchID(dpid);
}
public static StringBuilder keysToSB(Collection<byte[]> keys) {
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 014fc43..fa7a761 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/DeviceEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/DeviceEvent.java
@@ -1,6 +1,7 @@
package net.onrc.onos.ofcontroller.networkgraph;
import java.net.InetAddress;
+import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -71,5 +72,11 @@
return "[DeviceEvent " + mac + " attachmentPoints:" + attachmentPoints + " ipAddr:" + ipAddresses + "]";
}
+ // Assuming mac is unique cluster-wide
+ public static byte[] getDeviceID(final byte[] mac) {
+ return ByteBuffer.allocate(2 + mac.length).putChar('D').put(mac)
+ .array();
+ }
+
}
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 d9342aa..81f9ba3 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java
@@ -1,5 +1,7 @@
package net.onrc.onos.ofcontroller.networkgraph;
+import java.nio.ByteBuffer;
+
import net.onrc.onos.ofcontroller.networkgraph.PortEvent.SwitchPort;
/**
@@ -33,4 +35,13 @@
return "[LinkEvent " + src + "->" + dst + "]";
}
+ public static final int LINKID_BYTES = 2 + PortEvent.PORTID_BYTES * 2;
+
+ public static byte[] getLinkID(Long src_dpid, Long src_port_no,
+ Long dst_dpid, Long dst_port_no) {
+ return ByteBuffer.allocate(LinkEvent.LINKID_BYTES).putChar('L')
+ .put(PortEvent.getPortID(src_dpid, src_port_no))
+ .put(PortEvent.getPortID(dst_dpid, dst_port_no)).array();
+ }
+
}
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 addd695..e4caee5 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java
@@ -1,5 +1,7 @@
package net.onrc.onos.ofcontroller.networkgraph;
+import java.nio.ByteBuffer;
+
/**
* Self-contained Port event Object
*
@@ -52,4 +54,17 @@
return "[PortEvent 0x" + Long.toHexString(id.dpid) + "@" + id.number + "]";
}
+ public static final int PORTID_BYTES = SwitchEvent.SWITCHID_BYTES + 2 + 8;
+
+ public static byte[] getPortID(Long dpid, Long number) {
+ if (dpid == null) {
+ throw new IllegalArgumentException("dpid cannot be null");
+ }
+ if (number == null) {
+ throw new IllegalArgumentException("number cannot be null");
+ }
+ return ByteBuffer.allocate(PortEvent.PORTID_BYTES).putChar('S').putLong(dpid)
+ .putChar('P').putLong(number).array();
+ }
+
}
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 959a7d9..58532ae 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchEvent.java
@@ -1,5 +1,6 @@
package net.onrc.onos.ofcontroller.networkgraph;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
@@ -40,4 +41,14 @@
return "[SwitchEvent 0x" + Long.toHexString(dpid) + "]";
}
+ public static final int SWITCHID_BYTES = 2 + 8;
+
+ public static byte[] getSwitchID(Long dpid) {
+ if (dpid == null) {
+ throw new IllegalArgumentException("dpid cannot be null");
+ }
+ return ByteBuffer.allocate(SwitchEvent.SWITCHID_BYTES).putChar('S').putLong(dpid)
+ .array();
+ }
+
}