Skip to content
Snippets Groups Projects
Commit 45e54979 authored by Andrew Ferguson's avatar Andrew Ferguson
Browse files

initial version of OF queue structures and msgs

parent 57285679
No related branches found
No related tags found
No related merge requests found
package org.openflow.protocol;
import java.util.ArrayList;
import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.util.U16;
/**
* Represents ofp_packet_queue
* @author Andrew Ferguson (adf@cs.brown.edu)
*/
public class OFPacketQueue {
public static int MINIMUM_LENGTH = 8;
protected int queueId;
protected short length;
protected List<OFQueueProp> properties = new ArrayList<OFQueueProp>();
public OFPacketQueue() {
this.queueId = -1;
this.length = -1;
}
public OFPacketQueue(int queueId) {
this.queueId = queueId;
this.length = U16.t(MINIMUM_LENGTH);
}
/**
* @return the queueId
*/
public long getQueueId() {
return queueId;
}
/**
* @param queueId the queueId to set
*/
public void setQueueId(int queueId) {
this.queueId = queueId;
}
/**
* @return the queue's properties
*/
public List<OFQueueProp> getProperties() {
return properties;
}
/**
* @param properties the properties to set
*/
public void setProperties(List<OFQueueProp> properties) {
this.properties = properties;
this.length = U16.t(MINIMUM_LENGTH);
for (OFQueueProp prop : properties) {
this.length += prop.getLength();
}
}
/**
* @return the length
*/
public short getLength() {
return length;
}
public void readFrom(ChannelBuffer data) {
this.queueId = data.readInt();
this.length = data.readShort();
data.readShort(); // pad
int availLength = (this.length - MINIMUM_LENGTH);
this.properties.clear();
while (availLength > 0) {
OFQueueProp prop = new OFQueueProp();
prop.readFrom(data);
properties.add(prop);
availLength -= prop.getLength();
}
}
public void writeTo(ChannelBuffer data) {
data.writeInt(queueId);
data.writeShort(length);
data.writeShort(0); // pad
for (OFQueueProp prop : properties) {
prop.writeTo(data);
}
}
@Override
public int hashCode() {
final int prime = 359;
int result = super.hashCode();
result = prime * result + queueId;
result = prime * result + length;
result = prime * result + properties.hashCode();
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof OFPacketQueue)) {
return false;
}
OFPacketQueue other = (OFPacketQueue) obj;
if (queueId != other.queueId) {
return false;
}
if (! properties.equals(other.properties)) {
return false;
}
return true;
}
}
package org.openflow.protocol;
import java.util.ArrayList;
import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.util.U16;
/**
* Represents an ofp_queue_get_config_request message
* @author Andrew Ferguson (adf@cs.brown.edu)
*/
public class OFQueueGetConfigReply extends OFMessage {
public static int MINIMUM_LENGTH = 16;
protected short portNumber;
protected List<OFPacketQueue> queues = new ArrayList<OFPacketQueue>();
public OFQueueGetConfigReply() {
super();
this.type = OFType.QUEUE_GET_CONFIG_REPLY;
this.length = U16.t(MINIMUM_LENGTH);
}
/**
* @return the portNumber
*/
public short getPortNumber() {
return portNumber;
}
/**
* @param portNumber the portNumber to set
*/
public void setPortNumber(short portNumber) {
this.portNumber = portNumber;
}
/**
* @return the port's queues
*/
public List<OFPacketQueue> getQueues() {
return queues;
}
/**
* @param queues the queues to set
*/
public void setQueues(List<OFPacketQueue> queues) {
this.queues = queues;
}
@Override
public void readFrom(ChannelBuffer data) {
super.readFrom(data);
this.portNumber = data.readShort();
data.readInt(); // pad
data.readShort(); // pad
int availLength = (this.length - MINIMUM_LENGTH);
this.queues.clear();
while (availLength > 0) {
OFPacketQueue queue = new OFPacketQueue();
queue.readFrom(data);
queues.add(queue);
availLength -= queue.getLength();
}
}
@Override
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);
}
}
@Override
public int hashCode() {
final int prime = 349;
int result = super.hashCode();
result = prime * result + portNumber;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof OFQueueGetConfigReply)) {
return false;
}
OFQueueGetConfigReply other = (OFQueueGetConfigReply) obj;
if (portNumber != other.portNumber) {
return false;
}
return true;
}
}
package org.openflow.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.util.U16;
/**
* Represents an ofp_queue_get_config_request message
* @author Andrew Ferguson (adf@cs.brown.edu)
*/
public class OFQueueGetConfigRequest extends OFMessage {
public static int MINIMUM_LENGTH = 12;
protected short portNumber;
public OFQueueGetConfigRequest() {
super();
this.type = OFType.QUEUE_GET_CONFIG_REQUEST;
this.length = U16.t(MINIMUM_LENGTH);
}
/**
* @return the portNumber
*/
public short getPortNumber() {
return portNumber;
}
/**
* @param portNumber the portNumber to set
*/
public void setPortNumber(short portNumber) {
this.portNumber = portNumber;
}
@Override
public void readFrom(ChannelBuffer data) {
super.readFrom(data);
this.portNumber = data.readShort();
data.readShort(); // pad
}
@Override
public void writeTo(ChannelBuffer data) {
super.writeTo(data);
data.writeShort(this.portNumber);
data.writeShort(0); // pad
}
@Override
public int hashCode() {
final int prime = 347;
int result = super.hashCode();
result = prime * result + portNumber;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof OFQueueGetConfigRequest)) {
return false;
}
OFQueueGetConfigRequest other = (OFQueueGetConfigRequest) obj;
if (portNumber != other.portNumber) {
return false;
}
return true;
}
}
package org.openflow.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.util.U16;
public class OFQueueProp {
private int NONE_MINIMUM_LENGTH = 8;
private int MIN_RATE_MINIMUM_LENGTH = 16;
public enum OFQueuePropType {
OFPQT_NONE (0),
OFPQT_MIN_RATE (1);
protected int value;
private OFQueuePropType(int value) {
this.value = value;
}
/**
* @return the value
*/
public int getValue() {
return value;
}
public static OFQueuePropType fromShort(short x) {
switch (x) {
case 0:
return OFPQT_NONE;
case 1:
return OFPQT_MIN_RATE;
}
return null;
}
}
protected OFQueuePropType type;
protected short length;
protected short rate = -1; // not valid unless type == OFPQT_MIN_RATE
public OFQueueProp() {
this.type = OFQueuePropType.OFPQT_NONE;
this.length = U16.t(NONE_MINIMUM_LENGTH);
}
/**
* @return the type
*/
public OFQueuePropType getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(OFQueuePropType type) {
this.type = type;
switch (type) {
case OFPQT_NONE:
this.length = U16.t(NONE_MINIMUM_LENGTH);
break;
case OFPQT_MIN_RATE:
this.length = U16.t(MIN_RATE_MINIMUM_LENGTH);
break;
}
}
/**
* @return the rate
*/
public short getRate() {
return rate;
}
/**
* @param rate the rate to set
*/
public void setRate(short rate) {
this.rate = rate;
}
/**
* @return the length
*/
public short getLength() {
return length;
}
public void readFrom(ChannelBuffer data) {
this.type = OFQueuePropType.fromShort(data.readShort());
this.length = data.readShort();
data.readInt(); // pad
if (this.type == OFQueuePropType.OFPQT_MIN_RATE) {
assert(this.length == MIN_RATE_MINIMUM_LENGTH);
this.rate = data.readShort();
data.readInt(); // pad
data.readShort(); // pad
} else {
assert(this.length == NONE_MINIMUM_LENGTH);
}
}
public void writeTo(ChannelBuffer data) {
data.writeShort(this.type.getValue());
data.writeShort(this.length);
data.writeInt(0); // pad
if (this.type == OFQueuePropType.OFPQT_MIN_RATE) {
data.writeShort(this.rate);
data.writeInt(0); // pad
data.writeShort(0); // pad
}
}
@Override
public int hashCode() {
final int prime = 353;
int result = super.hashCode();
result = prime * result + type.getValue();
result = prime * result + rate;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof OFQueueProp)) {
return false;
}
OFQueueProp other = (OFQueueProp) obj;
if (type != other.type) {
return false;
}
if (type == OFQueuePropType.OFPQT_MIN_RATE) {
if (rate != other.rate) {
return false;
}
}
return true;
}
}
......@@ -127,7 +127,17 @@ public enum OFType {
@Override
public OFMessage instantiate() {
return new OFBarrierReply();
}});
}}),
QUEUE_GET_CONFIG_REQUEST (20, OFQueueGetConfigRequest.class, new Instantiable<OFMessage>() {
@Override
public OFMessage instantiate() {
return new OFQueueGetConfigRequest();
}}),
QUEUE_GET_CONFIG_REPLY (21, OFQueueGetConfigReply.class, new Instantiable<OFMessage>() {
@Override
public OFMessage instantiate() {
return new OFQueueGetConfigReply();
}});
static OFType[] mapping;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment