Eliminate tab character from datastore package
Change-Id: I6eea92ce72268c4ca90f1bd24bdccf7edf4cbb7f
diff --git a/src/main/java/net/onrc/onos/datastore/topology/KVDevice.java b/src/main/java/net/onrc/onos/datastore/topology/KVDevice.java
index 105f6f7..e076c14 100644
--- a/src/main/java/net/onrc/onos/datastore/topology/KVDevice.java
+++ b/src/main/java/net/onrc/onos/datastore/topology/KVDevice.java
@@ -32,18 +32,18 @@
private static final Logger log = LoggerFactory.getLogger(KVDevice.class);
private static final ThreadLocal<Kryo> deviceKryo = new ThreadLocal<Kryo>() {
- @Override
- protected Kryo initialValue() {
- Kryo kryo = new Kryo();
- kryo.setRegistrationRequired(true);
- kryo.setReferences(false);
- kryo.register(byte[].class);
- kryo.register(byte[][].class);
- kryo.register(HashMap.class);
- // TODO check if we should explicitly specify EnumSerializer
- kryo.register(STATUS.class);
- return kryo;
- }
+ @Override
+ protected Kryo initialValue() {
+ Kryo kryo = new Kryo();
+ kryo.setRegistrationRequired(true);
+ kryo.setReferences(false);
+ kryo.register(byte[].class);
+ kryo.register(byte[][].class);
+ kryo.register(HashMap.class);
+ // TODO check if we should explicitly specify EnumSerializer
+ kryo.register(STATUS.class);
+ return kryo;
+ }
};
public static final String GLOBAL_DEVICE_TABLE_NAME = "G:Device";
@@ -58,25 +58,25 @@
// Assuming mac is unique cluster-wide
public static byte[] getDeviceID(final byte[] mac) {
- return DeviceEvent.getDeviceID(mac).array();
+ return DeviceEvent.getDeviceID(mac).array();
}
public static byte[] getMacFromKey(final byte[] key) {
- ByteBuffer keyBuf = ByteBuffer.wrap(key);
- if (keyBuf.getChar() != 'D') {
- throw new IllegalArgumentException("Invalid Device key");
- }
- byte[] mac = new byte[keyBuf.remaining()];
- keyBuf.get(mac);
- return mac;
+ ByteBuffer keyBuf = ByteBuffer.wrap(key);
+ if (keyBuf.getChar() != 'D') {
+ throw new IllegalArgumentException("Invalid Device key");
+ }
+ byte[] mac = new byte[keyBuf.remaining()];
+ keyBuf.get(mac);
+ return mac;
}
public KVDevice(final byte[] mac) {
- super(DataStoreClient.getClient().getTable(GLOBAL_DEVICE_TABLE_NAME), getDeviceID(mac));
+ super(DataStoreClient.getClient().getTable(GLOBAL_DEVICE_TABLE_NAME), getDeviceID(mac));
- this.mac = mac;
- this.portIds = new TreeSet<>(ByteArrayComparator.BYTEARRAY_COMPARATOR);
- this.isPortIdsModified = true;
+ this.mac = mac;
+ this.portIds = new TreeSet<>(ByteArrayComparator.BYTEARRAY_COMPARATOR);
+ this.isPortIdsModified = true;
}
/**
@@ -87,62 +87,62 @@
* @return
*/
public static KVDevice createFromKey(final byte[] key) {
- return new KVDevice(getMacFromKey(key));
+ return new KVDevice(getMacFromKey(key));
}
public static Iterable<KVDevice> getAllDevices() {
- return new DeviceEnumerator();
+ return new DeviceEnumerator();
}
public static class DeviceEnumerator implements Iterable<KVDevice> {
- @Override
- public Iterator<KVDevice> iterator() {
- return new DeviceIterator();
- }
+ @Override
+ public Iterator<KVDevice> iterator() {
+ return new DeviceIterator();
+ }
}
public static class DeviceIterator extends AbstractObjectIterator<KVDevice> {
- public DeviceIterator() {
- super(DataStoreClient.getClient().getTable(GLOBAL_DEVICE_TABLE_NAME));
- }
+ public DeviceIterator() {
+ super(DataStoreClient.getClient().getTable(GLOBAL_DEVICE_TABLE_NAME));
+ }
- @Override
- public KVDevice next() {
- IKVEntry o = enumerator.next();
- KVDevice e = KVDevice.createFromKey(o.getKey());
- e.deserialize(o.getValue(), o.getVersion());
- return e;
- }
+ @Override
+ public KVDevice next() {
+ IKVEntry o = enumerator.next();
+ KVDevice e = KVDevice.createFromKey(o.getKey());
+ e.deserialize(o.getValue(), o.getVersion());
+ return e;
+ }
}
public byte[] getMac() {
- // TODO may need to clone() to be sure this object will be immutable.
- return mac;
+ // TODO may need to clone() to be sure this object will be immutable.
+ return mac;
}
public byte[] getId() {
- return getKey();
+ return getKey();
}
public void addPortId(final byte[] portId) {
- // TODO: Should we copy portId, or reference is OK.
- isPortIdsModified |= portIds.add(portId);
+ // TODO: Should we copy portId, or reference is OK.
+ isPortIdsModified |= portIds.add(portId);
}
public void removePortId(final byte[] portId) {
- isPortIdsModified |= portIds.remove(portId);
+ isPortIdsModified |= portIds.remove(portId);
}
public void emptyPortIds() {
- portIds.clear();
- this.isPortIdsModified = true;
+ portIds.clear();
+ this.isPortIdsModified = true;
}
public void addAllToPortIds(final Collection<byte[]> portIds) {
- // TODO: Should we copy portId, or reference is OK.
- isPortIdsModified |= this.portIds.addAll(portIds);
+ // TODO: Should we copy portId, or reference is OK.
+ isPortIdsModified |= this.portIds.addAll(portIds);
}
/**
@@ -150,53 +150,53 @@
* @return Unmodifiable Set view of all the PortIds;
*/
public Set<byte[]> getAllPortIds() {
- return Collections.unmodifiableSet(portIds);
+ return Collections.unmodifiableSet(portIds);
}
@Override
public byte[] serialize() {
- Map<Object, Object> map = getPropertyMap();
+ Map<Object, Object> map = getPropertyMap();
- map.put(PROP_MAC, mac);
- if (isPortIdsModified) {
- byte[][] portIdArray = new byte[portIds.size()][];
- map.put(PROP_PORT_IDS, portIds.toArray(portIdArray));
- isPortIdsModified = false;
- }
+ map.put(PROP_MAC, mac);
+ if (isPortIdsModified) {
+ byte[][] portIdArray = new byte[portIds.size()][];
+ map.put(PROP_PORT_IDS, portIds.toArray(portIdArray));
+ isPortIdsModified = false;
+ }
- return serializePropertyMap(deviceKryo.get(), map);
+ return serializePropertyMap(deviceKryo.get(), map);
}
@Override
protected boolean deserialize(final byte[] bytes) {
- boolean success = deserializePropertyMap(deviceKryo.get(), bytes);
- if (!success) {
- log.error("Deserializing Link: " + this + " failed.");
- return false;
- }
- Map<Object, Object> map = this.getPropertyMap();
+ boolean success = deserializePropertyMap(deviceKryo.get(), bytes);
+ if (!success) {
+ log.error("Deserializing Link: " + this + " failed.");
+ return false;
+ }
+ Map<Object, Object> map = this.getPropertyMap();
- if (this.portIds == null) {
- this.portIds = new TreeSet<>(
- ByteArrayComparator.BYTEARRAY_COMPARATOR);
- }
- byte[][] portIdArray = (byte[][]) map.get(PROP_PORT_IDS);
- if (portIdArray != null) {
- this.portIds.clear();
- this.portIds.addAll(Arrays.asList(portIdArray));
- isPortIdsModified = false;
- } else {
- // trigger write on next serialize
- isPortIdsModified = true;
- }
+ if (this.portIds == null) {
+ this.portIds = new TreeSet<>(
+ ByteArrayComparator.BYTEARRAY_COMPARATOR);
+ }
+ byte[][] portIdArray = (byte[][]) map.get(PROP_PORT_IDS);
+ if (portIdArray != null) {
+ this.portIds.clear();
+ this.portIds.addAll(Arrays.asList(portIdArray));
+ isPortIdsModified = false;
+ } else {
+ // trigger write on next serialize
+ isPortIdsModified = true;
+ }
- return success;
+ return success;
}
@Override
public String toString() {
- // TODO output all properties?
- return "[" + this.getClass().getSimpleName()
- + " " + ByteArrayUtil.toHexStringBuffer(mac, ":") + "]";
+ // TODO output all properties?
+ return "[" + this.getClass().getSimpleName()
+ + " " + ByteArrayUtil.toHexStringBuffer(mac, ":") + "]";
}
}
diff --git a/src/main/java/net/onrc/onos/datastore/topology/KVLink.java b/src/main/java/net/onrc/onos/datastore/topology/KVLink.java
index c9273ae..5fbf070 100644
--- a/src/main/java/net/onrc/onos/datastore/topology/KVLink.java
+++ b/src/main/java/net/onrc/onos/datastore/topology/KVLink.java
@@ -26,41 +26,41 @@
private static final Logger log = LoggerFactory.getLogger(KVLink.class);
private static final ThreadLocal<Kryo> linkKryo = new ThreadLocal<Kryo>() {
- @Override
- protected Kryo initialValue() {
- Kryo kryo = new Kryo();
- kryo.setRegistrationRequired(true);
- kryo.setReferences(false);
- kryo.register(byte[].class);
- kryo.register(byte[][].class);
- kryo.register(HashMap.class);
- // TODO check if we should explicitly specify EnumSerializer
- kryo.register(STATUS.class);
- return kryo;
- }
+ @Override
+ protected Kryo initialValue() {
+ Kryo kryo = new Kryo();
+ kryo.setRegistrationRequired(true);
+ kryo.setReferences(false);
+ kryo.register(byte[].class);
+ kryo.register(byte[][].class);
+ kryo.register(HashMap.class);
+ // TODO check if we should explicitly specify EnumSerializer
+ kryo.register(STATUS.class);
+ return kryo;
+ }
};
public static class SwitchPort {
- public final Long dpid;
- public final Long number;
+ public final Long dpid;
+ public final Long number;
- public SwitchPort(final Long dpid, final Long number) {
- this.dpid = dpid;
- this.number = number;
- }
+ public SwitchPort(final Long dpid, final Long number) {
+ this.dpid = dpid;
+ this.number = number;
+ }
- public byte[] getPortID() {
- return KVPort.getPortID(dpid, number);
- }
+ public byte[] getPortID() {
+ return KVPort.getPortID(dpid, number);
+ }
- public byte[] getSwitchID() {
- return KVSwitch.getSwitchID(dpid);
- }
+ public byte[] getSwitchID() {
+ return KVSwitch.getSwitchID(dpid);
+ }
- @Override
- public String toString() {
- return "(" + Long.toHexString(dpid) + "@" + number + ")";
- }
+ @Override
+ public String toString() {
+ return "(" + Long.toHexString(dpid) + "@" + number + ")";
+ }
}
@@ -68,7 +68,7 @@
// must not re-order enum members, ordinal will be sent over wire
public enum STATUS {
- INACTIVE, ACTIVE;
+ INACTIVE, ACTIVE;
}
private final SwitchPort src;
@@ -76,40 +76,40 @@
private STATUS status;
public static byte[] getLinkID(final Long src_dpid, final Long src_port_no,
- final Long dst_dpid, final Long dst_port_no) {
- return LinkEvent.getLinkID(src_dpid, src_port_no, dst_dpid,
- dst_port_no).array();
+ final Long dst_dpid, final Long dst_port_no) {
+ return LinkEvent.getLinkID(src_dpid, src_port_no, dst_dpid,
+ dst_port_no).array();
}
public static long[] getLinkTupleFromKey(final byte[] key) {
- return getLinkTupleFromKey(ByteBuffer.wrap(key));
+ return getLinkTupleFromKey(ByteBuffer.wrap(key));
}
public static long[] getLinkTupleFromKey(final ByteBuffer keyBuf) {
- long[] tuple = new long[4];
- if (keyBuf.getChar() != 'L') {
- throw new IllegalArgumentException("Invalid Link key");
- }
- long[] src_port_pair = KVPort.getPortPairFromKey(keyBuf.slice());
- keyBuf.position(2 + PortEvent.PORTID_BYTES);
- long[] dst_port_pair = KVPort.getPortPairFromKey(keyBuf.slice());
+ long[] tuple = new long[4];
+ if (keyBuf.getChar() != 'L') {
+ throw new IllegalArgumentException("Invalid Link key");
+ }
+ long[] src_port_pair = KVPort.getPortPairFromKey(keyBuf.slice());
+ keyBuf.position(2 + PortEvent.PORTID_BYTES);
+ long[] dst_port_pair = KVPort.getPortPairFromKey(keyBuf.slice());
- tuple[0] = src_port_pair[0];
- tuple[1] = src_port_pair[1];
- tuple[2] = dst_port_pair[0];
- tuple[3] = dst_port_pair[1];
+ tuple[0] = src_port_pair[0];
+ tuple[1] = src_port_pair[1];
+ tuple[2] = dst_port_pair[0];
+ tuple[3] = dst_port_pair[1];
- return tuple;
+ return tuple;
}
public KVLink(final Long src_dpid, final Long src_port_no,
- final Long dst_dpid, final Long dst_port_no) {
- super(DataStoreClient.getClient().getTable(GLOBAL_LINK_TABLE_NAME), getLinkID(src_dpid,
- src_port_no, dst_dpid, dst_port_no));
+ final Long dst_dpid, final Long dst_port_no) {
+ super(DataStoreClient.getClient().getTable(GLOBAL_LINK_TABLE_NAME), getLinkID(src_dpid,
+ src_port_no, dst_dpid, dst_port_no));
- src = new SwitchPort(src_dpid, src_port_no);
- dst = new SwitchPort(dst_dpid, dst_port_no);
- status = STATUS.INACTIVE;
+ src = new SwitchPort(src_dpid, src_port_no);
+ dst = new SwitchPort(dst_dpid, dst_port_no);
+ status = STATUS.INACTIVE;
}
/**
@@ -120,98 +120,98 @@
* @return KVLink instance
*/
public static KVLink createFromKey(final byte[] key) {
- long[] linkTuple = getLinkTupleFromKey(key);
- return new KVLink(linkTuple[0], linkTuple[1], linkTuple[2],
- linkTuple[3]);
+ long[] linkTuple = getLinkTupleFromKey(key);
+ return new KVLink(linkTuple[0], linkTuple[1], linkTuple[2],
+ linkTuple[3]);
}
public static Iterable<KVLink> getAllLinks() {
- return new LinkEnumerator();
+ return new LinkEnumerator();
}
public static class LinkEnumerator implements Iterable<KVLink> {
- @Override
- public Iterator<KVLink> iterator() {
- return new LinkIterator();
- }
+ @Override
+ public Iterator<KVLink> iterator() {
+ return new LinkIterator();
+ }
}
public static class LinkIterator extends AbstractObjectIterator<KVLink> {
- public LinkIterator() {
- super(DataStoreClient.getClient().getTable(GLOBAL_LINK_TABLE_NAME));
- }
+ public LinkIterator() {
+ super(DataStoreClient.getClient().getTable(GLOBAL_LINK_TABLE_NAME));
+ }
- @Override
- public KVLink next() {
- IKVEntry o = enumerator.next();
- KVLink e = KVLink.createFromKey(o.getKey());
- e.deserialize(o.getValue(), o.getVersion());
- return e;
- }
+ @Override
+ public KVLink next() {
+ IKVEntry o = enumerator.next();
+ KVLink e = KVLink.createFromKey(o.getKey());
+ e.deserialize(o.getValue(), o.getVersion());
+ return e;
+ }
}
public STATUS getStatus() {
- return status;
+ return status;
}
public void setStatus(final STATUS status) {
- this.status = status;
+ this.status = status;
}
public SwitchPort getSrc() {
- return src;
+ return src;
}
public SwitchPort getDst() {
- return dst;
+ return dst;
}
public byte[] getId() {
- return getKey();
+ return getKey();
}
@Override
public byte[] serialize() {
- Map<Object, Object> map = getPropertyMap();
+ Map<Object, Object> map = getPropertyMap();
- LinkProperty.Builder link = LinkProperty.newBuilder();
- link.setSrcSwId(ByteString.copyFrom(src.getSwitchID()));
- link.setSrcPortId(ByteString.copyFrom(src.getPortID()));
- link.setDstSwId(ByteString.copyFrom(dst.getSwitchID()));
- link.setDstPortId(ByteString.copyFrom(dst.getPortID()));
- link.setStatus(status.ordinal());
+ LinkProperty.Builder link = LinkProperty.newBuilder();
+ link.setSrcSwId(ByteString.copyFrom(src.getSwitchID()));
+ link.setSrcPortId(ByteString.copyFrom(src.getPortID()));
+ link.setDstSwId(ByteString.copyFrom(dst.getSwitchID()));
+ link.setDstPortId(ByteString.copyFrom(dst.getPortID()));
+ link.setStatus(status.ordinal());
- if (!map.isEmpty()) {
- byte[] propMaps = serializePropertyMap(linkKryo.get(), map);
- link.setValue(ByteString.copyFrom(propMaps));
- }
+ if (!map.isEmpty()) {
+ byte[] propMaps = serializePropertyMap(linkKryo.get(), map);
+ link.setValue(ByteString.copyFrom(propMaps));
+ }
- return link.build().toByteArray();
+ return link.build().toByteArray();
}
@Override
protected boolean deserialize(final byte[] bytes) {
- try {
- boolean success = true;
+ try {
+ boolean success = true;
- LinkProperty link = LinkProperty.parseFrom(bytes);
- byte[] props = link.getValue().toByteArray();
- success &= deserializePropertyMap(linkKryo.get(), props);
- this.status = STATUS.values()[link.getStatus()];
+ LinkProperty link = LinkProperty.parseFrom(bytes);
+ byte[] props = link.getValue().toByteArray();
+ success &= deserializePropertyMap(linkKryo.get(), props);
+ this.status = STATUS.values()[link.getStatus()];
- return success;
- } catch (InvalidProtocolBufferException e) {
- log.error("Deserializing Link: " + this + " failed.", e);
- return false;
- }
+ return success;
+ } catch (InvalidProtocolBufferException e) {
+ log.error("Deserializing Link: " + this + " failed.", e);
+ return false;
+ }
}
@Override
public String toString() {
- // TODO output all properties?
- return "[" + this.getClass().getSimpleName()
- + " " + src + "->" + dst + " STATUS:" + status + "]";
+ // TODO output all properties?
+ return "[" + this.getClass().getSimpleName()
+ + " " + src + "->" + dst + " STATUS:" + status + "]";
}
}
diff --git a/src/main/java/net/onrc/onos/datastore/topology/KVPort.java b/src/main/java/net/onrc/onos/datastore/topology/KVPort.java
index 3b66864..452bf94 100644
--- a/src/main/java/net/onrc/onos/datastore/topology/KVPort.java
+++ b/src/main/java/net/onrc/onos/datastore/topology/KVPort.java
@@ -30,25 +30,25 @@
private static final Logger log = LoggerFactory.getLogger(KVPort.class);
private static final ThreadLocal<Kryo> portKryo = new ThreadLocal<Kryo>() {
- @Override
- protected Kryo initialValue() {
- Kryo kryo = new Kryo();
- kryo.setRegistrationRequired(true);
- kryo.setReferences(false);
- kryo.register(byte[].class);
- kryo.register(byte[][].class);
- kryo.register(HashMap.class);
- // TODO check if we should explicitly specify EnumSerializer
- kryo.register(STATUS.class);
- return kryo;
- }
+ @Override
+ protected Kryo initialValue() {
+ Kryo kryo = new Kryo();
+ kryo.setRegistrationRequired(true);
+ kryo.setReferences(false);
+ kryo.register(byte[].class);
+ kryo.register(byte[][].class);
+ kryo.register(HashMap.class);
+ // TODO check if we should explicitly specify EnumSerializer
+ kryo.register(STATUS.class);
+ return kryo;
+ }
};
public static final String GLOBAL_PORT_TABLE_NAME = "G:Port";
// must not re-order enum members, ordinal will be sent over wire
public enum STATUS {
- INACTIVE, ACTIVE;
+ INACTIVE, ACTIVE;
}
private final Long dpid;
@@ -57,49 +57,49 @@
private STATUS status;
public static byte[] getPortID(final Long dpid, final Long number) {
- return PortEvent.getPortID(dpid, number).array();
+ return PortEvent.getPortID(dpid, number).array();
}
public static long[] getPortPairFromKey(final byte[] key) {
- return getPortPairFromKey(ByteBuffer.wrap(key));
+ return getPortPairFromKey(ByteBuffer.wrap(key));
}
public static long[] getPortPairFromKey(final ByteBuffer keyBuf) {
- long[] pair = new long[2];
- if (keyBuf.getChar() != 'S') {
- throw new IllegalArgumentException("Invalid Port key:" + keyBuf
- + " "
- + ByteArrayUtil.toHexStringBuffer(keyBuf.array(), ":"));
- }
- pair[0] = keyBuf.getLong();
- if (keyBuf.getChar() != 'P') {
- throw new IllegalArgumentException("Invalid Port key:" + keyBuf
- + " "
- + ByteArrayUtil.toHexStringBuffer(keyBuf.array(), ":"));
- }
- pair[1] = keyBuf.getLong();
- return pair;
+ long[] pair = new long[2];
+ if (keyBuf.getChar() != 'S') {
+ throw new IllegalArgumentException("Invalid Port key:" + keyBuf
+ + " "
+ + ByteArrayUtil.toHexStringBuffer(keyBuf.array(), ":"));
+ }
+ pair[0] = keyBuf.getLong();
+ if (keyBuf.getChar() != 'P') {
+ throw new IllegalArgumentException("Invalid Port key:" + keyBuf
+ + " "
+ + ByteArrayUtil.toHexStringBuffer(keyBuf.array(), ":"));
+ }
+ pair[1] = keyBuf.getLong();
+ return pair;
}
public static long getDpidFromKey(final byte[] key) {
- return getPortPairFromKey(key)[0];
+ return getPortPairFromKey(key)[0];
}
public static long getNumberFromKey(final byte[] key) {
- return getPortPairFromKey(key)[1];
+ return getPortPairFromKey(key)[1];
}
// FIXME specify DPID,number here, or Should caller specify the key it self?
// In other words, should layer above have the control of the ID?
public KVPort(final Long dpid, final Long number) {
- super(DataStoreClient.getClient().getTable(GLOBAL_PORT_TABLE_NAME), getPortID(dpid, number));
+ super(DataStoreClient.getClient().getTable(GLOBAL_PORT_TABLE_NAME), getPortID(dpid, number));
- // TODO Auto-generated constructor stub
+ // TODO Auto-generated constructor stub
- this.dpid = dpid;
- this.number = number;
- this.status = STATUS.INACTIVE;
+ this.dpid = dpid;
+ this.number = number;
+ this.status = STATUS.INACTIVE;
}
/**
@@ -110,96 +110,96 @@
* @return KVPort instance
*/
public static KVPort createFromKey(final byte[] key) {
- long[] pair = getPortPairFromKey(key);
- return new KVPort(pair[0], pair[1]);
+ long[] pair = getPortPairFromKey(key);
+ return new KVPort(pair[0], pair[1]);
}
public static Iterable<KVPort> getAllPorts() {
- return new PortEnumerator();
+ return new PortEnumerator();
}
public static class PortEnumerator implements Iterable<KVPort> {
- @Override
- public Iterator<KVPort> iterator() {
- return new PortIterator();
- }
+ @Override
+ public Iterator<KVPort> iterator() {
+ return new PortIterator();
+ }
}
public static class PortIterator extends AbstractObjectIterator<KVPort> {
- public PortIterator() {
- super(DataStoreClient.getClient().getTable(GLOBAL_PORT_TABLE_NAME));
- }
+ public PortIterator() {
+ super(DataStoreClient.getClient().getTable(GLOBAL_PORT_TABLE_NAME));
+ }
- @Override
- public KVPort next() {
- IKVEntry o = enumerator.next();
- KVPort e = KVPort.createFromKey(o.getKey());
- e.deserialize(o.getValue(), o.getVersion());
- return e;
- }
+ @Override
+ public KVPort next() {
+ IKVEntry o = enumerator.next();
+ KVPort e = KVPort.createFromKey(o.getKey());
+ e.deserialize(o.getValue(), o.getVersion());
+ return e;
+ }
}
public STATUS getStatus() {
- return status;
+ return status;
}
public void setStatus(final STATUS status) {
- this.status = status;
+ this.status = status;
}
public Long getDpid() {
- return dpid;
+ return dpid;
}
public Long getNumber() {
- return number;
+ return number;
}
public byte[] getId() {
- return getKey();
+ return getKey();
}
@Override
public byte[] serialize() {
- Map<Object, Object> map = getPropertyMap();
+ Map<Object, Object> map = getPropertyMap();
- PortProperty.Builder port = PortProperty.newBuilder();
- port.setDpid(dpid);
- port.setNumber(number);
- port.setStatus(status.ordinal());
+ PortProperty.Builder port = PortProperty.newBuilder();
+ port.setDpid(dpid);
+ port.setNumber(number);
+ port.setStatus(status.ordinal());
- if (!map.isEmpty()) {
- byte[] propMaps = serializePropertyMap(portKryo.get(), map);
- port.setValue(ByteString.copyFrom(propMaps));
- }
+ if (!map.isEmpty()) {
+ byte[] propMaps = serializePropertyMap(portKryo.get(), map);
+ port.setValue(ByteString.copyFrom(propMaps));
+ }
- return port.build().toByteArray();
+ return port.build().toByteArray();
}
@Override
protected boolean deserialize(final byte[] bytes) {
- try {
- boolean success = true;
+ try {
+ boolean success = true;
- PortProperty port = PortProperty.parseFrom(bytes);
- byte[] props = port.getValue().toByteArray();
- success &= deserializePropertyMap(portKryo.get(), props);
- this.status = STATUS.values()[port.getStatus()];
+ PortProperty port = PortProperty.parseFrom(bytes);
+ byte[] props = port.getValue().toByteArray();
+ success &= deserializePropertyMap(portKryo.get(), props);
+ this.status = STATUS.values()[port.getStatus()];
- return success;
- } catch (InvalidProtocolBufferException e) {
- log.error("Deserializing Port: " + this + " failed.", e);
- return false;
- }
+ return success;
+ } catch (InvalidProtocolBufferException e) {
+ log.error("Deserializing Port: " + this + " failed.", e);
+ return false;
+ }
}
@Override
public String toString() {
- // TODO output all properties?
- return "[" + this.getClass().getSimpleName()
- + " 0x" + Long.toHexString(dpid) + "@" + number
- + " STATUS:" + status + "]";
+ // TODO output all properties?
+ return "[" + this.getClass().getSimpleName()
+ + " 0x" + Long.toHexString(dpid) + "@" + number
+ + " STATUS:" + status + "]";
}
}
diff --git a/src/main/java/net/onrc/onos/datastore/topology/KVSwitch.java b/src/main/java/net/onrc/onos/datastore/topology/KVSwitch.java
index e915160..5f1c8fd 100644
--- a/src/main/java/net/onrc/onos/datastore/topology/KVSwitch.java
+++ b/src/main/java/net/onrc/onos/datastore/topology/KVSwitch.java
@@ -29,52 +29,52 @@
private static final Logger log = LoggerFactory.getLogger(KVSwitch.class);
private static final ThreadLocal<Kryo> switchKryo = new ThreadLocal<Kryo>() {
- @Override
- protected Kryo initialValue() {
- Kryo kryo = new Kryo();
- kryo.setRegistrationRequired(true);
- kryo.setReferences(false);
- kryo.register(byte[].class);
- kryo.register(byte[][].class);
- kryo.register(HashMap.class);
- // TODO check if we should explicitly specify EnumSerializer
- kryo.register(STATUS.class);
- return kryo;
- }
+ @Override
+ protected Kryo initialValue() {
+ Kryo kryo = new Kryo();
+ kryo.setRegistrationRequired(true);
+ kryo.setReferences(false);
+ kryo.register(byte[].class);
+ kryo.register(byte[][].class);
+ kryo.register(HashMap.class);
+ // TODO check if we should explicitly specify EnumSerializer
+ kryo.register(STATUS.class);
+ return kryo;
+ }
};
public static final String GLOBAL_SWITCH_TABLE_NAME = "G:Switch";
// must not re-order enum members, ordinal will be sent over wire
public enum STATUS {
- INACTIVE, ACTIVE;
+ INACTIVE, ACTIVE;
}
private final Long dpid;
private STATUS status;
public static byte[] getSwitchID(final Long dpid) {
- return SwitchEvent.getSwitchID(dpid).array();
+ return SwitchEvent.getSwitchID(dpid).array();
}
public static long getDpidFromKey(final byte[] key) {
- return getDpidFromKey(ByteBuffer.wrap(key));
+ return getDpidFromKey(ByteBuffer.wrap(key));
}
public static long getDpidFromKey(final ByteBuffer keyBuf) {
- if (keyBuf.getChar() != 'S') {
- throw new IllegalArgumentException("Invalid Switch key");
- }
- return keyBuf.getLong();
+ if (keyBuf.getChar() != 'S') {
+ throw new IllegalArgumentException("Invalid Switch key");
+ }
+ return keyBuf.getLong();
}
// FIXME specify DPID here, or Should caller specify the key it self?
// In other words, should layer above have the control of the ID?
public KVSwitch(final Long dpid) {
- super(DataStoreClient.getClient().getTable(GLOBAL_SWITCH_TABLE_NAME), getSwitchID(dpid));
+ super(DataStoreClient.getClient().getTable(GLOBAL_SWITCH_TABLE_NAME), getSwitchID(dpid));
- this.dpid = dpid;
- this.status = STATUS.INACTIVE;
+ this.dpid = dpid;
+ this.status = STATUS.INACTIVE;
}
/**
@@ -85,90 +85,90 @@
* @return KVSwitch instance
*/
public static KVSwitch createFromKey(final byte[] key) {
- return new KVSwitch(getDpidFromKey(key));
+ return new KVSwitch(getDpidFromKey(key));
}
public static Iterable<KVSwitch> getAllSwitches() {
- return new SwitchEnumerator();
+ return new SwitchEnumerator();
}
public static class SwitchEnumerator implements Iterable<KVSwitch> {
- @Override
- public Iterator<KVSwitch> iterator() {
- return new SwitchIterator();
- }
+ @Override
+ public Iterator<KVSwitch> iterator() {
+ return new SwitchIterator();
+ }
}
public static class SwitchIterator extends AbstractObjectIterator<KVSwitch> {
- public SwitchIterator() {
- super(DataStoreClient.getClient().getTable(GLOBAL_SWITCH_TABLE_NAME));
- }
+ public SwitchIterator() {
+ super(DataStoreClient.getClient().getTable(GLOBAL_SWITCH_TABLE_NAME));
+ }
- @Override
- public KVSwitch next() {
- IKVEntry o = enumerator.next();
- KVSwitch e = KVSwitch.createFromKey(o.getKey());
- e.deserialize(o.getValue(), o.getVersion());
- return e;
- }
+ @Override
+ public KVSwitch next() {
+ IKVEntry o = enumerator.next();
+ KVSwitch e = KVSwitch.createFromKey(o.getKey());
+ e.deserialize(o.getValue(), o.getVersion());
+ return e;
+ }
}
public STATUS getStatus() {
- return status;
+ return status;
}
public void setStatus(final STATUS status) {
- this.status = status;
+ this.status = status;
}
public Long getDpid() {
- return dpid;
+ return dpid;
}
public byte[] getId() {
- return getKey();
+ return getKey();
}
@Override
public byte[] serialize() {
- Map<Object, Object> map = getPropertyMap();
+ Map<Object, Object> map = getPropertyMap();
- SwitchProperty.Builder sw = SwitchProperty.newBuilder();
- sw.setDpid(dpid);
- sw.setStatus(status.ordinal());
+ SwitchProperty.Builder sw = SwitchProperty.newBuilder();
+ sw.setDpid(dpid);
+ sw.setStatus(status.ordinal());
- if (!map.isEmpty()) {
- byte[] propMaps = serializePropertyMap(switchKryo.get(), map);
- sw.setValue(ByteString.copyFrom(propMaps));
- }
+ if (!map.isEmpty()) {
+ byte[] propMaps = serializePropertyMap(switchKryo.get(), map);
+ sw.setValue(ByteString.copyFrom(propMaps));
+ }
- return sw.build().toByteArray();
+ return sw.build().toByteArray();
}
@Override
protected boolean deserialize(final byte[] bytes) {
- try {
- boolean success = true;
+ try {
+ boolean success = true;
- SwitchProperty sw = SwitchProperty.parseFrom(bytes);
- byte[] props = sw.getValue().toByteArray();
- success &= deserializePropertyMap(switchKryo.get(), props);
- this.status = STATUS.values()[sw.getStatus()];
+ SwitchProperty sw = SwitchProperty.parseFrom(bytes);
+ byte[] props = sw.getValue().toByteArray();
+ success &= deserializePropertyMap(switchKryo.get(), props);
+ this.status = STATUS.values()[sw.getStatus()];
- return success;
- } catch (InvalidProtocolBufferException e) {
- log.error("Deserializing Switch: " + this + " failed.", e);
- return false;
- }
+ return success;
+ } catch (InvalidProtocolBufferException e) {
+ log.error("Deserializing Switch: " + this + " failed.", e);
+ return false;
+ }
}
@Override
public String toString() {
- // TODO output all properties?
- return "[" + this.getClass().getSimpleName()
- + " 0x" + Long.toHexString(dpid) + " STATUS:" + status + "]";
+ // TODO output all properties?
+ return "[" + this.getClass().getSimpleName()
+ + " 0x" + Long.toHexString(dpid) + " STATUS:" + status + "]";
}
}