Flip before returning ByteBuffer

Change-Id: I7350e24f20d5686a8c6c43291d963070fe7da792
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 e9ba12e..628b9d4 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/DeviceEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/DeviceEvent.java
@@ -82,7 +82,7 @@
 
     // Assuming mac is unique cluster-wide
     public static ByteBuffer getDeviceID(final byte[] mac) {
-	return ByteBuffer.allocate(2 + mac.length).putChar('D').put(mac);
+	return (ByteBuffer) ByteBuffer.allocate(2 + mac.length).putChar('D').put(mac).flip();
     }
 
     public byte[] getID() {
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 4d060de..5fd3b82 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java
@@ -52,9 +52,9 @@
 
     public static ByteBuffer getLinkID(Long src_dpid, Long src_port_no,
 	    Long dst_dpid, Long dst_port_no) {
-	return ByteBuffer.allocate(LinkEvent.LINKID_BYTES).putChar('L')
+	return (ByteBuffer) ByteBuffer.allocate(LinkEvent.LINKID_BYTES).putChar('L')
 		.put(PortEvent.getPortID(src_dpid, src_port_no))
-		.put(PortEvent.getPortID(dst_dpid, dst_port_no));
+		.put(PortEvent.getPortID(dst_dpid, dst_port_no)).flip();
     }
 
     public byte[] getID() {
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 b926037..4bd3ea1 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java
@@ -109,8 +109,8 @@
 	if (number == null) {
 	    throw new IllegalArgumentException("number cannot be null");
 	}
-	return ByteBuffer.allocate(PortEvent.PORTID_BYTES).putChar('S').putLong(dpid)
-		.putChar('P').putLong(number);
+	return (ByteBuffer) ByteBuffer.allocate(PortEvent.PORTID_BYTES).putChar('S').putLong(dpid)
+		.putChar('P').putLong(number).flip();
     }
 
     public byte[] getID() {
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 5aa7008..84b9360 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchEvent.java
@@ -37,7 +37,7 @@
 	if (dpid == null) {
 	    throw new IllegalArgumentException("dpid cannot be null");
 	}
-	return ByteBuffer.allocate(SwitchEvent.SWITCHID_BYTES).putChar('S').putLong(dpid);
+	return (ByteBuffer) ByteBuffer.allocate(SwitchEvent.SWITCHID_BYTES).putChar('S').putLong(dpid).flip();
     }
 
     public byte[] getID() {