Added cubby-holes for new projects.
diff --git a/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/ActionUtils.java b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/ActionUtils.java
new file mode 100644
index 0000000..e0553a9
--- /dev/null
+++ b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/ActionUtils.java
@@ -0,0 +1,43 @@
+package org.projectfloodlight.openflow.util;
+
+import java.util.List;
+
+import org.projectfloodlight.openflow.protocol.OFFlowMod;
+import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
+import org.projectfloodlight.openflow.protocol.OFInstructionType;
+import org.projectfloodlight.openflow.protocol.OFVersion;
+import org.projectfloodlight.openflow.protocol.action.OFAction;
+import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
+import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
+
+import com.google.common.collect.ImmutableList;
+
+public class ActionUtils {
+ private ActionUtils() {}
+
+ public static List<OFAction> getActions(OFFlowStatsEntry e) {
+ if(e.getVersion() == OFVersion.OF_10) {
+ return e.getActions();
+ } else {
+ for(OFInstruction i: e.getInstructions()) {
+ if(i.getType() == OFInstructionType.APPLY_ACTIONS) {
+ return ((OFInstructionApplyActions) i).getActions();
+ }
+ }
+ return ImmutableList.of();
+ }
+ }
+
+ public static List<OFAction> getActions(OFFlowMod e) {
+ if(e.getVersion() == OFVersion.OF_10) {
+ return e.getActions();
+ } else {
+ for(OFInstruction i: e.getInstructions()) {
+ if(i.getType() == OFInstructionType.APPLY_ACTIONS) {
+ return ((OFInstructionApplyActions) i).getActions();
+ }
+ }
+ return ImmutableList.of();
+ }
+ }
+}
diff --git a/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/ChannelUtils.java b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/ChannelUtils.java
new file mode 100644
index 0000000..1a1ac6a
--- /dev/null
+++ b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/ChannelUtils.java
@@ -0,0 +1,80 @@
+package org.projectfloodlight.openflow.util;
+
+import java.util.List;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.projectfloodlight.openflow.exceptions.OFParseError;
+import org.projectfloodlight.openflow.protocol.OFMessageReader;
+import org.projectfloodlight.openflow.protocol.Writeable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+/**
+ * Collection of helper functions for reading and writing into ChannelBuffers
+ *
+ * @author capveg
+ */
+
+public class ChannelUtils {
+ private static final Logger logger = LoggerFactory.getLogger(ChannelUtils.class);
+ public static String readFixedLengthString(ChannelBuffer bb, int length) {
+ byte[] dst = new byte[length];
+ bb.readBytes(dst, 0, length);
+ int validLength = 0;
+ for (validLength = 0; validLength < length; validLength++) {
+ if (dst[validLength] == 0)
+ break;
+ }
+ return new String(dst, 0, validLength, Charsets.US_ASCII);
+ }
+
+ public static void writeFixedLengthString(ChannelBuffer bb, String string,
+ int length) {
+ int l = string.length();
+ if (l > length) {
+ throw new IllegalArgumentException("Error writing string: length="
+ + l + " > max Length=" + length);
+ }
+ bb.writeBytes(string.getBytes(Charsets.US_ASCII));
+ if (l < length) {
+ bb.writeZero(length - l);
+ }
+ }
+
+ static public byte[] readBytes(final ChannelBuffer bb, final int length) {
+ byte byteArray[] = new byte[length];
+ bb.readBytes(byteArray);
+ return byteArray;
+ }
+
+ static public void writeBytes(final ChannelBuffer bb,
+ final byte byteArray[]) {
+ bb.writeBytes(byteArray);
+ }
+
+ public static <T> List<T> readList(ChannelBuffer bb, int length, OFMessageReader<T> reader) throws OFParseError {
+ int end = bb.readerIndex() + length;
+ Builder<T> builder = ImmutableList.<T>builder();
+ if(logger.isTraceEnabled())
+ logger.trace("readList(length={}, reader={})", length, reader.getClass());
+ while(bb.readerIndex() < end) {
+ T read = reader.readFrom(bb);
+ if(logger.isTraceEnabled())
+ logger.trace("readList: read={}, left={}", read, end - bb.readerIndex());
+ builder.add(read);
+ }
+ if(bb.readerIndex() != end) {
+ throw new IllegalStateException("Overread length: length="+length + " overread by "+ (bb.readerIndex() - end) + " reader: "+reader);
+ }
+ return builder.build();
+ }
+
+ public static void writeList(ChannelBuffer bb, List<? extends Writeable> writeables) {
+ for(Writeable w: writeables)
+ w.writeTo(bb);
+ }
+}
diff --git a/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/FunnelUtils.java b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/FunnelUtils.java
new file mode 100644
index 0000000..f62d7f9
--- /dev/null
+++ b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/FunnelUtils.java
@@ -0,0 +1,14 @@
+package org.projectfloodlight.openflow.util;
+
+import java.util.List;
+
+import org.projectfloodlight.openflow.types.PrimitiveSinkable;
+
+import com.google.common.hash.PrimitiveSink;
+
+public class FunnelUtils {
+ public static void putList(List<? extends PrimitiveSinkable> sinkables, PrimitiveSink sink) {
+ for(PrimitiveSinkable p: sinkables)
+ p.putTo(sink);
+ }
+}
diff --git a/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/HexString.java b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/HexString.java
new file mode 100644
index 0000000..bcc46f7
--- /dev/null
+++ b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/HexString.java
@@ -0,0 +1,100 @@
+/**
+ * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
+ * University
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ **/
+
+package org.projectfloodlight.openflow.util;
+
+import org.projectfloodlight.openflow.types.U8;
+
+public class HexString {
+ /**
+ * Convert a string of bytes to a ':' separated hex string
+ *
+ * @param bytes
+ * @return "0f:ca:fe:de:ad:be:ef"
+ */
+ public static String toHexString(final byte[] bytes) {
+ int i;
+ String ret = "";
+ String tmp;
+ for (i = 0; i < bytes.length; i++) {
+ if (i > 0)
+ ret += ":";
+ tmp = Integer.toHexString(U8.f(bytes[i]));
+ if (tmp.length() == 1)
+ ret += "0";
+ ret += tmp;
+ }
+ return ret;
+ }
+
+ public static String toHexString(final long val, final int padTo) {
+ char arr[] = Long.toHexString(val).toCharArray();
+ String ret = "";
+ // prepend the right number of leading zeros
+ int i = 0;
+ for (; i < (padTo * 2 - arr.length); i++) {
+ ret += "0";
+ if ((i % 2) != 0)
+ ret += ":";
+ }
+ for (int j = 0; j < arr.length; j++) {
+ ret += arr[j];
+ if ((((i + j) % 2) != 0) && (j < (arr.length - 1)))
+ ret += ":";
+ }
+ return ret;
+ }
+
+ public static String toHexString(final long val) {
+ return toHexString(val, 8);
+ }
+
+ /**
+ * Convert a string of hex values into a string of bytes
+ *
+ * @param values
+ * "0f:ca:fe:de:ad:be:ef"
+ * @return [15, 5 ,2, 5, 17]
+ * @throws NumberFormatException
+ * If the string can not be parsed
+ */
+ public static byte[] fromHexString(final String values) throws NumberFormatException {
+ String[] octets = values.split(":");
+ byte[] ret = new byte[octets.length];
+
+ for (int i = 0; i < octets.length; i++) {
+ if (octets[i].length() > 2)
+ throw new NumberFormatException("Invalid octet length");
+ ret[i] = Integer.valueOf(octets[i], 16).byteValue();
+ }
+ return ret;
+ }
+
+ public static long toLong(String value) throws NumberFormatException {
+ String[] octets = value.split(":");
+ if (octets.length > 8)
+ throw new NumberFormatException("Input string is too big to fit in long: " + value);
+ long l = 0;
+ for (String octet: octets) {
+ if (octet.length() > 2)
+ throw new NumberFormatException("Each colon-separated byte component must consist of 1 or 2 hex digits: " + value);
+ short s = Short.parseShort(octet, 16);
+ l = (l << 8) + s;
+ }
+ return l;
+ }
+}
diff --git a/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/LRULinkedHashMap.java b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/LRULinkedHashMap.java
new file mode 100644
index 0000000..7798e67
--- /dev/null
+++ b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/LRULinkedHashMap.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
+ * University
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ **/
+
+package org.projectfloodlight.openflow.util;
+
+import java.util.LinkedHashMap;
+
+public class LRULinkedHashMap<K, V> extends LinkedHashMap<K, V> {
+ private static final long serialVersionUID = -2964986094089626647L;
+ protected int maximumCapacity;
+
+ public LRULinkedHashMap(final int initialCapacity, final int maximumCapacity) {
+ super(initialCapacity, 0.75f, true);
+ this.maximumCapacity = maximumCapacity;
+ }
+
+ public LRULinkedHashMap(final int maximumCapacity) {
+ super(16, 0.75f, true);
+ this.maximumCapacity = maximumCapacity;
+ }
+
+ @Override
+ protected boolean removeEldestEntry(final java.util.Map.Entry<K, V> eldest) {
+ if (this.size() > maximumCapacity)
+ return true;
+ return false;
+ }
+}
diff --git a/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/LengthCountingPseudoChannelBuffer.java b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/LengthCountingPseudoChannelBuffer.java
new file mode 100644
index 0000000..48362da
--- /dev/null
+++ b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/LengthCountingPseudoChannelBuffer.java
@@ -0,0 +1,673 @@
+package org.projectfloodlight.openflow.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.channels.GatheringByteChannel;
+import java.nio.channels.ScatteringByteChannel;
+import java.nio.charset.Charset;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBufferFactory;
+import org.jboss.netty.buffer.ChannelBufferIndexFinder;
+
+public class LengthCountingPseudoChannelBuffer implements ChannelBuffer {
+
+ int writerIndex = 0;
+ private int markedWriterIndex;
+
+ @Override
+ public ChannelBufferFactory factory() {
+ return null;
+ }
+
+ @Override
+ public int capacity() {
+ return Integer.MAX_VALUE;
+ }
+
+ @Override
+ public ByteOrder order() {
+ return ByteOrder.BIG_ENDIAN;
+ }
+
+ @Override
+ public boolean isDirect() {
+ return true;
+ }
+
+ @Override
+ public int readerIndex() {
+ return 0;
+ }
+
+ @Override
+ public void readerIndex(int readerIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int writerIndex() {
+ return writerIndex;
+ }
+
+ @Override
+ public void writerIndex(int writerIndex) {
+ this.writerIndex = writerIndex;
+ }
+
+ @Override
+ public void setIndex(int readerIndex, int writerIndex) {
+ if(readerIndex != 0)
+ throw new UnsupportedOperationException();
+ this.writerIndex = writerIndex;
+ }
+
+ @Override
+ public int readableBytes() {
+ return writerIndex;
+ }
+
+ @Override
+ public int writableBytes() {
+ return Integer.MAX_VALUE - writerIndex;
+ }
+
+ @Override
+ public boolean readable() {
+ return writerIndex > 0;
+ }
+
+ @Override
+ public boolean writable() {
+ return writerIndex < Integer.MAX_VALUE;
+ }
+
+ @Override
+ public void clear() {
+ writerIndex = 0;
+
+ }
+
+ @Override
+ public void markReaderIndex() {
+ }
+
+ @Override
+ public void resetReaderIndex() {
+ }
+
+ @Override
+ public void markWriterIndex() {
+ markedWriterIndex = writerIndex;
+ }
+
+ @Override
+ public void resetWriterIndex() {
+ writerIndex = markedWriterIndex;
+ }
+
+ @Override
+ public void discardReadBytes() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void ensureWritableBytes(int writableBytes) {
+ if(!((Integer.MAX_VALUE - writableBytes) > writerIndex))
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public byte getByte(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public short getUnsignedByte(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public short getShort(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getUnsignedShort(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getMedium(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getUnsignedMedium(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getInt(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getUnsignedInt(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getLong(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public char getChar(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public float getFloat(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public double getDouble(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getBytes(int index, ChannelBuffer dst) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getBytes(int index, ChannelBuffer dst, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getBytes(int index, byte[] dst) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getBytes(int index, byte[] dst, int dstIndex, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getBytes(int index, ByteBuffer dst) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getBytes(int index, OutputStream out, int length)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getBytes(int index, GatheringByteChannel out, int length)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setByte(int index, int value) {
+ }
+
+ @Override
+ public void setShort(int index, int value) {
+ }
+
+ @Override
+ public void setMedium(int index, int value) {
+ }
+
+ @Override
+ public void setInt(int index, int value) {
+ }
+
+ @Override
+ public void setLong(int index, long value) {
+ }
+
+ @Override
+ public void setChar(int index, int value) {
+ }
+
+ @Override
+ public void setFloat(int index, float value) {
+ }
+
+ @Override
+ public void setDouble(int index, double value) {
+ }
+
+ @Override
+ public void setBytes(int index, ChannelBuffer src) {
+ }
+
+ @Override
+ public void setBytes(int index, ChannelBuffer src, int length) {
+ }
+
+ @Override
+ public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
+ }
+
+ @Override
+ public void setBytes(int index, byte[] src) {
+ }
+
+ @Override
+ public void setBytes(int index, byte[] src, int srcIndex, int length) {
+ }
+
+ @Override
+ public void setBytes(int index, ByteBuffer src) {
+
+ }
+
+ @Override
+ public int setBytes(int index, InputStream in, int length)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int setBytes(int index, ScatteringByteChannel in, int length)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setZero(int index, int length) {
+ }
+
+ @Override
+ public byte readByte() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public short readUnsignedByte() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public short readShort() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int readUnsignedShort() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int readMedium() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int readUnsignedMedium() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int readInt() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long readUnsignedInt() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long readLong() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public char readChar() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public float readFloat() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public double readDouble() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ChannelBuffer readBytes(int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ @Deprecated
+ public ChannelBuffer readBytes(ChannelBufferIndexFinder indexFinder) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ChannelBuffer readSlice(int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ @Deprecated
+ public
+ ChannelBuffer readSlice(ChannelBufferIndexFinder indexFinder) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void readBytes(ChannelBuffer dst) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void readBytes(ChannelBuffer dst, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void readBytes(ChannelBuffer dst, int dstIndex, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void readBytes(byte[] dst) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void readBytes(byte[] dst, int dstIndex, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void readBytes(ByteBuffer dst) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void readBytes(OutputStream out, int length) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int readBytes(GatheringByteChannel out, int length)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void skipBytes(int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ @Deprecated
+ public int skipBytes(ChannelBufferIndexFinder indexFinder) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void writeByte(int value) {
+ writerIndex++;
+ }
+
+ @Override
+ public void writeShort(int value) {
+ writerIndex += 2;
+}
+
+@Override
+public void writeMedium(int value) {
+ writerIndex += 3;
+}
+
+@Override
+public void writeInt(int value) {
+ writerIndex += 4;
+}
+
+@Override
+public void writeLong(long value) {
+ writerIndex += 8;
+}
+
+
+ @Override
+ public void writeChar(int value) {
+ writeShort(value);
+ }
+
+ @Override
+ public void writeFloat(float value) {
+ writeInt(Float.floatToIntBits(value));
+ }
+
+ @Override
+ public void writeDouble(double value) {
+ writeLong(Double.doubleToLongBits(value));
+
+ }
+
+ @Override
+ public void writeBytes(ChannelBuffer src) {
+ writerIndex += src.readableBytes();
+
+ }
+
+ @Override
+ public void writeBytes(ChannelBuffer src, int length) {
+ writerIndex += src.readableBytes();
+
+ }
+
+ @Override
+ public void writeBytes(ChannelBuffer src, int srcIndex, int length) {
+ writerIndex += length;
+ }
+
+ @Override
+ public void writeBytes(byte[] src) {
+ writerIndex += src.length;
+
+ }
+
+ @Override
+ public void writeBytes(byte[] src, int srcIndex, int length) {
+ writerIndex += length;
+ }
+
+ @Override
+ public void writeBytes(ByteBuffer src) {
+ writerIndex += src.remaining();
+
+ }
+
+ @Override
+ public int writeBytes(InputStream in, int length) throws IOException {
+ writerIndex += length;
+ return length;
+ }
+
+ @Override
+ public int writeBytes(ScatteringByteChannel in, int length)
+ throws IOException {
+ writerIndex += length;
+ return length;
+ }
+
+ @Override
+ public void writeZero(int length) {
+ writerIndex += length;
+
+ }
+
+ @Override
+ public int indexOf(int fromIndex, int toIndex, byte value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int indexOf(int fromIndex, int toIndex,
+ ChannelBufferIndexFinder indexFinder) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int bytesBefore(byte value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int bytesBefore(ChannelBufferIndexFinder indexFinder) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int bytesBefore(int length, byte value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int bytesBefore(int length, ChannelBufferIndexFinder indexFinder) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int bytesBefore(int index, int length, byte value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int bytesBefore(int index, int length,
+ ChannelBufferIndexFinder indexFinder) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ChannelBuffer copy() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ChannelBuffer copy(int index, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ChannelBuffer slice() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ChannelBuffer slice(int index, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ChannelBuffer duplicate() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer toByteBuffer() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer toByteBuffer(int index, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer[] toByteBuffers() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer[] toByteBuffers(int index, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasArray() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public byte[] array() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int arrayOffset() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String toString(Charset charset) {
+ return "LengthCountingPseudoChannelBuffer(length="+writerIndex+")";
+ }
+
+ @Override
+ public String toString(int index, int length, Charset charset) {
+ return toString();
+ }
+
+ @Override
+ @Deprecated
+ public String toString(String charsetName) {
+ return toString();
+ }
+
+ @Override
+ @Deprecated
+ public String toString(String charsetName,
+ ChannelBufferIndexFinder terminatorFinder) {
+ return toString();
+ }
+
+ @Override
+ @Deprecated
+ public String toString(int index, int length, String charsetName) {
+ return toString();
+ }
+
+ @Override
+ @Deprecated
+ public
+ String toString(int index, int length, String charsetName,
+ ChannelBufferIndexFinder terminatorFinder) {
+ return toString();
+ }
+
+ @Override
+ public int compareTo(ChannelBuffer buffer) {
+ throw new UnsupportedOperationException();
+
+ }
+
+}
diff --git a/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/MultiplePktInReasonUtil.java b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/MultiplePktInReasonUtil.java
new file mode 100644
index 0000000..a919f62
--- /dev/null
+++ b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/MultiplePktInReasonUtil.java
@@ -0,0 +1,46 @@
+package org.projectfloodlight.openflow.util;
+
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+
+import org.projectfloodlight.openflow.types.U64;
+import org.projectfloodlight.openflow.protocol.OFBsnPktinFlag;
+import org.projectfloodlight.openflow.protocol.OFPacketIn;
+import org.projectfloodlight.openflow.protocol.OFVersion;
+import org.projectfloodlight.openflow.protocol.match.MatchField;
+import org.projectfloodlight.openflow.protocol.match.Match;
+import org.projectfloodlight.openflow.protocol.ver13.OFBsnPktinFlagSerializerVer13;
+import org.projectfloodlight.openflow.types.OFMetadata;
+
+
+public class MultiplePktInReasonUtil {
+ private MultiplePktInReasonUtil() {}
+
+ /**
+ * This function is used in BVS T5/6 to decode the multiple packet in
+ * reasons in Match.MetaData field.
+ * */
+ public static Set<OFBsnPktinFlag> getOFBsnPktinFlags(OFPacketIn pktIn) {
+ if(pktIn.getVersion() != OFVersion.OF_13) {
+ throw new IllegalArgumentException("multiple pkt in reasons are "
+ + "only supported by BVS using "
+ + "openflow 1.3");
+ }
+
+ Match match = pktIn.getMatch();
+ if(match == null) {
+ return ImmutableSet.<OFBsnPktinFlag>of();
+ }
+ OFMetadata metaData = match.get(MatchField.METADATA);
+ if(metaData == null) {
+ return ImmutableSet.<OFBsnPktinFlag>of();
+ }
+ U64 metaDataValue = metaData.getValue();
+ if(metaDataValue == null) {
+ return ImmutableSet.<OFBsnPktinFlag>of();
+ }
+ return OFBsnPktinFlagSerializerVer13.ofWireValue(metaDataValue
+ .getValue());
+ }
+}
diff --git a/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/PrimitiveSinkUtils.java b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/PrimitiveSinkUtils.java
new file mode 100644
index 0000000..28eb3a4
--- /dev/null
+++ b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/PrimitiveSinkUtils.java
@@ -0,0 +1,75 @@
+package org.projectfloodlight.openflow.util;
+
+import java.util.List;
+import java.util.SortedSet;
+
+import javax.annotation.Nullable;
+
+import org.projectfloodlight.openflow.types.PrimitiveSinkable;
+
+import com.google.common.hash.PrimitiveSink;
+
+/** Utility methods for dumping collections into primitive sinks.
+ *
+ * @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
+ */
+public class PrimitiveSinkUtils {
+ private PrimitiveSinkUtils() {}
+
+ /** puts a nullable String into a primitive sink. The entry is prepended by a 'presence'
+ * boolean bit and the string length;
+ *
+ *
+ * @param sink the sink to put the object
+ * @param nullableObj the potentially null string to put in the sink
+ */
+ public static void putNullableStringTo(PrimitiveSink sink,
+ @Nullable CharSequence nullableChars) {
+
+ sink.putBoolean(nullableChars != null);
+ if(nullableChars != null) {
+ sink.putInt(nullableChars.length());
+ sink.putUnencodedChars(nullableChars);
+ }
+ }
+
+ /** puts a nullable element into a primitive sink. The entry is prepended by a 'present' bit.
+ *
+ * @param sink the sink to put the object
+ * @param nullableObj the nullable object
+ */
+ public static void putNullableTo(PrimitiveSink sink,
+ @Nullable PrimitiveSinkable nullableObj) {
+ sink.putBoolean(nullableObj != null);
+ if(nullableObj != null)
+ nullableObj.putTo(sink);
+ }
+
+ /** puts the elements of a sorted set into the {@link PrimitiveSink}. Does not support null
+ * elements. The elements are assumed to be self-delimitating.
+ *
+ * @param sink
+ * @param set
+ */
+ public static void putSortedSetTo(PrimitiveSink sink,
+ SortedSet<? extends PrimitiveSinkable> set) {
+ sink.putInt(set.size());
+ for(PrimitiveSinkable e: set) {
+ e.putTo(sink);
+ }
+ }
+
+ /** puts the elements of a list into the {@link PrimitiveSink}. Does not support null
+ * elements. The elements are assumed to be self-delimitating.
+ *
+ * @param sink
+ * @param set
+ */
+ public static void putListTo(PrimitiveSink sink,
+ List<? extends PrimitiveSinkable> set) {
+ sink.putInt(set.size());
+ for(PrimitiveSinkable e: set) {
+ e.putTo(sink);
+ }
+ }
+}
diff --git a/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/StringByteSerializer.java b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/StringByteSerializer.java
new file mode 100644
index 0000000..6949fb2
--- /dev/null
+++ b/of-save/lib/src/main/java/org/projectfloodlight/openflow/util/StringByteSerializer.java
@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
+ * University
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ **/
+
+package org.projectfloodlight.openflow.util;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+
+public class StringByteSerializer {
+ public static String readFrom(final ChannelBuffer data, final int length) {
+ byte[] stringBytes = new byte[length];
+ data.readBytes(stringBytes);
+ // find the first index of 0
+ int index = 0;
+ for (byte b : stringBytes) {
+ if (0 == b)
+ break;
+ ++index;
+ }
+ return new String(Arrays.copyOf(stringBytes, index), Charset.forName("ascii"));
+ }
+
+ public static void writeTo(final ChannelBuffer data, final int length,
+ final String value) {
+ try {
+ byte[] name = value.getBytes("ASCII");
+ if (name.length < length) {
+ data.writeBytes(name);
+ for (int i = name.length; i < length; ++i) {
+ data.writeByte((byte) 0);
+ }
+ } else {
+ data.writeBytes(name, 0, length - 1);
+ data.writeByte((byte) 0);
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+}