diff --git a/src/main/java/org/openflow/vendor/openflow/OFOpenFlowVendorData.java b/src/main/java/org/openflow/vendor/openflow/OFOpenFlowVendorData.java new file mode 100644 index 0000000000000000000000000000000000000000..1300f9bc0de02be73af1640c9a32e93633bcddde --- /dev/null +++ b/src/main/java/org/openflow/vendor/openflow/OFOpenFlowVendorData.java @@ -0,0 +1,83 @@ + +package org.openflow.vendor.openflow; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.openflow.protocol.vendor.OFVendorData; + +/** + * Base class for vendor data corresponding to extensions to OpenFlow 1.0. + * Based on org.openflow.vendor.nicira + * + * @author Andrew Ferguson (adf@cs.brown.edu) + */ +public class OFOpenFlowVendorData implements OFVendorData { + + public static final int OF_VENDOR_ID = 0x000026e1; + + /** + * The value of the integer data type at the beginning of the vendor data + */ + protected int dataType; + + /** + * Construct empty (i.e. unspecified data type) OpenFlow vendor data. + */ + public OFOpenFlowVendorData() { + } + + /** + * Construct OpenFlow vendor data with the specified data type + * @param dataType the data type value at the beginning of the vendor data. + */ + public OFOpenFlowVendorData(int dataType) { + this.dataType = dataType; + } + + /** + * Get the data type value at the beginning of the vendor data + * @return the integer data type value + */ + public int getDataType() { + return dataType; + } + + /** + * Set the data type value + * @param dataType the integer data type value at the beginning of the + * vendor data. + */ + public void setDataType(int dataType) { + this.dataType = dataType; + } + + /** + * Get the length of the vendor data. This implementation will normally + * be the superclass for another class that will override this to return + * the overall vendor data length. This implementation just returns the + * length of the part that includes the 4-byte integer data type value + * at the beginning of the vendor data. + */ + @Override + public int getLength() { + return 4; + } + + /** + * Read the vendor data from the ChannelBuffer + * @param data the channel buffer from which we're deserializing + * @param length the length to the end of the enclosing message + */ + @Override + public void readFrom(ChannelBuffer data, int length) { + dataType = data.readInt(); + } + + /** + * Write the vendor data to the ChannelBuffer + * @param data the channel buffer to which we're serializing + */ + @Override + public void writeTo(ChannelBuffer data) { + data.writeInt(dataType); + } +} diff --git a/src/main/java/org/openflow/vendor/openflow/OFOpenFlowVendorExtensions.java b/src/main/java/org/openflow/vendor/openflow/OFOpenFlowVendorExtensions.java new file mode 100644 index 0000000000000000000000000000000000000000..4698315ca8083095c04995ef0d26ee235d4379ae --- /dev/null +++ b/src/main/java/org/openflow/vendor/openflow/OFOpenFlowVendorExtensions.java @@ -0,0 +1,31 @@ +package org.openflow.vendor.openflow; + +import org.openflow.protocol.vendor.OFBasicVendorDataType; +import org.openflow.protocol.vendor.OFBasicVendorId; +import org.openflow.protocol.vendor.OFVendorId; + +public class OFOpenFlowVendorExtensions { + private static boolean initialized = false; + + public static synchronized void initialize() { + if (initialized) + return; + + // Configure openflowj to be able to parse the OpenFlow extensions. + OFBasicVendorId openflowVendorId = + new OFBasicVendorId(OFOpenFlowVendorData.OF_VENDOR_ID, 4); + OFVendorId.registerVendorId(openflowVendorId); + + OFBasicVendorDataType queueModifyVendorData = + new OFBasicVendorDataType(OFQueueModifyVendorData.OFP_EXT_QUEUE_MODIFY, + OFQueueModifyVendorData.getInstantiable()); + openflowVendorId.registerVendorDataType(queueModifyVendorData); + + OFBasicVendorDataType queueDeleteVendorData = + new OFBasicVendorDataType(OFQueueDeleteVendorData.OFP_EXT_QUEUE_DELETE, + OFQueueModifyVendorData.getInstantiable()); + openflowVendorId.registerVendorDataType(queueDeleteVendorData); + + initialized = true; + } +} diff --git a/src/main/java/org/openflow/vendor/openflow/OFQueueDeleteVendorData.java b/src/main/java/org/openflow/vendor/openflow/OFQueueDeleteVendorData.java new file mode 100644 index 0000000000000000000000000000000000000000..6a0dbd3299171ec318095d8b1a779692f6b8b15c --- /dev/null +++ b/src/main/java/org/openflow/vendor/openflow/OFQueueDeleteVendorData.java @@ -0,0 +1,32 @@ +package org.openflow.vendor.openflow; + +import org.openflow.protocol.Instantiable; +import org.openflow.protocol.vendor.OFVendorData; + +/** + * Class that represents the vendor data in the queue delete request + * + * @author Andrew Ferguson (adf@cs.brown.edu) + */ +public class OFQueueDeleteVendorData { + + protected static Instantiable<OFVendorData> instantiable = + new Instantiable<OFVendorData>() { + public OFVendorData instantiate() { + return new OFQueueModifyVendorData(); + } + }; + + /** + * @return a subclass of Instantiable<OFVendorData> that instantiates + * an instance of OFQueueDeleteVendorData. + */ + public static Instantiable<OFVendorData> getInstantiable() { + return instantiable; + } + + /** + * The data type value for a queue delete request + */ + public static final int OFP_EXT_QUEUE_DELETE = 1; +} diff --git a/src/main/java/org/openflow/vendor/openflow/OFQueueModifyVendorData.java b/src/main/java/org/openflow/vendor/openflow/OFQueueModifyVendorData.java new file mode 100644 index 0000000000000000000000000000000000000000..3d53560f357c84f224c09bf5e8c3da572105c81a --- /dev/null +++ b/src/main/java/org/openflow/vendor/openflow/OFQueueModifyVendorData.java @@ -0,0 +1,32 @@ +package org.openflow.vendor.openflow; + +import org.openflow.protocol.Instantiable; +import org.openflow.protocol.vendor.OFVendorData; + +/** + * Class that represents the vendor data in the queue modify request + * + * @author Andrew Ferguson (adf@cs.brown.edu) + */ +public class OFQueueModifyVendorData extends OFQueueVendorData { + + protected static Instantiable<OFVendorData> instantiable = + new Instantiable<OFVendorData>() { + public OFVendorData instantiate() { + return new OFQueueModifyVendorData(); + } + }; + + /** + * @return a subclass of Instantiable<OFVendorData> that instantiates + * an instance of OFQueueModifyVendorData. + */ + public static Instantiable<OFVendorData> getInstantiable() { + return instantiable; + } + + /** + * The data type value for a queue modify request + */ + public static final int OFP_EXT_QUEUE_MODIFY = 0; +} diff --git a/src/main/java/org/openflow/vendor/openflow/OFQueueVendorData.java b/src/main/java/org/openflow/vendor/openflow/OFQueueVendorData.java new file mode 100644 index 0000000000000000000000000000000000000000..abc95302cf07aa78a39ae794ec0a8d6d896c6a9c --- /dev/null +++ b/src/main/java/org/openflow/vendor/openflow/OFQueueVendorData.java @@ -0,0 +1,99 @@ +package org.openflow.vendor.openflow; + +import java.util.ArrayList; +import java.util.List; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.openflow.protocol.OFPacketQueue; + +/** + * Class that represents the vendor data in a queue modify or delete request + * + * @author Andrew Ferguson (adf@cs.brown.edu) + */ +public class OFQueueVendorData extends OFOpenFlowVendorData { + public static int MINIMUM_LENGTH = 24; + + protected short portNumber; + protected List<OFPacketQueue> queues = new ArrayList<OFPacketQueue>(); + + /** + * @return the portNumber + */ + public short getPortNumber() { + return portNumber; + } + + /** + * @param port the port on which the queue is + */ + public void setPortNumber(short portNumber) { + this.portNumber = portNumber; + } + + + /** + * @return the queues + */ + public List<OFPacketQueue> getQueues() { + return queues; + } + + /** + * @param queues the queues to modify or delete + */ + public void setQueues(List<OFPacketQueue> queues) { + this.queues = queues; + } + + /** + * @return the total length of the queue modify or delete msg + */ + @Override + public int getLength() { + int queuesLength = 0; + + for (OFPacketQueue queue : queues) { + queuesLength += queue.getLength(); + } + + return MINIMUM_LENGTH + queuesLength; + } + + /** + * Read the queue message data from the ChannelBuffer + * @param data the channel buffer from which we're deserializing + * @param length the length to the end of the enclosing message + */ + public void readFrom(ChannelBuffer data, int length) { + super.readFrom(data, length); + portNumber = data.readShort(); + data.readInt(); // pad + data.readShort(); // pad + + int availLength = (length - MINIMUM_LENGTH); + this.queues.clear(); + + while (availLength > 0) { + OFPacketQueue queue = new OFPacketQueue(); + queue.readFrom(data); + queues.add(queue); + availLength -= queue.getLength(); + } + } + + /** + * Write the queue message data to the ChannelBuffer + * @param data the channel buffer to which we're serializing + */ + public void writeTo(ChannelBuffer data) { + super.writeTo(data); + data.writeShort(this.portNumber); + data.writeInt(0); // pad + data.writeShort(0); // pad + + for (OFPacketQueue queue : queues) { + queue.writeTo(data); + } + } +}