Skip to content
Snippets Groups Projects
Commit 59105bb3 authored by Kuang-Ching Wang's avatar Kuang-Ching Wang
Browse files

Merge pull request #348 from brownsys/ofqueue-structs-msgs

Support for QueueGetConfigRequest & QueueGetConfigReply
parents 00b7a817 6eb8ed93
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,9 @@ import org.apache.thrift.TEnum;
STATS_REQUEST(16),
STATS_REPLY(17),
BARRIER_REQUEST(18),
BARRIER_REPLY(19);
BARRIER_REPLY(19),
QUEUE_GET_CONFIG_REQUEST(20),
QUEUE_GET_CONFIG_REPLY(21);
private final int value;
......@@ -95,6 +97,10 @@ import org.apache.thrift.TEnum;
return BARRIER_REQUEST;
case 19:
return BARRIER_REPLY;
case 20:
return QUEUE_GET_CONFIG_REQUEST;
case 21:
return QUEUE_GET_CONFIG_REPLY;
default:
return null;
}
......
/**
* Copyright 2012, Andrew Ferguson, Brown 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.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;
}
}
/**
* Copyright 2012, Andrew Ferguson, Brown 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.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.clear();
this.queues.addAll(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;
}
}
/**
* Copyright 2012, Andrew Ferguson, Brown 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.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(short portNumber) {
super();
this.type = OFType.QUEUE_GET_CONFIG_REQUEST;
this.length = U16.t(MINIMUM_LENGTH);
this.portNumber = portNumber;
}
public OFQueueGetConfigRequest() {
this((short) 0);
}
/**
* @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;
}
}
/**
* Copyright 2012, Andrew Ferguson, Brown 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.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;
......
......@@ -38,6 +38,8 @@ enum OFMessageType {
STATS_REPLY = 17,
BARRIER_REQUEST = 18,
BARRIER_REPLY = 19,
QUEUE_GET_CONFIG_REQUEST = 20,
QUEUE_GET_CONFIG_REPLY = 21,
}
/**
......
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