2 * Copyright 2012, Andrew Ferguson, Brown University
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may
5 * not use this file except in compliance with the License. You may obtain
6 * a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
17 package org.openflow.protocol;
19 import org.jboss.netty.buffer.ChannelBuffer;
20 import org.openflow.util.U16;
22 public class OFQueueProp {
23 private int NONE_MINIMUM_LENGTH = 8;
24 private int RATE_MINIMUM_LENGTH = 16;
26 public enum OFQueuePropType {
33 private OFQueuePropType(int value) {
40 public int getValue() {
44 public static OFQueuePropType fromShort(short x) {
49 return OFPQT_MIN_RATE;
51 return OFPQT_MAX_RATE;
57 protected OFQueuePropType type;
58 protected short length;
59 protected short rate = -1; // not valid if type == OFPQT_NONE
61 public OFQueueProp() {
62 this.type = OFQueuePropType.OFPQT_NONE;
63 this.length = U16.t(NONE_MINIMUM_LENGTH);
69 public OFQueuePropType getType() {
74 * @param type the type to set
76 public void setType(OFQueuePropType type) {
81 this.length = U16.t(NONE_MINIMUM_LENGTH);
84 this.length = U16.t(RATE_MINIMUM_LENGTH);
87 this.length = U16.t(RATE_MINIMUM_LENGTH);
95 public short getRate() {
100 * @param rate the rate to set
102 public void setRate(short rate) {
109 public short getLength() {
113 public void readFrom(ChannelBuffer data) {
114 this.type = OFQueuePropType.fromShort(data.readShort());
115 this.length = data.readShort();
116 data.readInt(); // pad
118 if (this.type == OFQueuePropType.OFPQT_MIN_RATE ||
119 this.type == OFQueuePropType.OFPQT_MAX_RATE) {
120 assert(this.length == RATE_MINIMUM_LENGTH);
122 this.rate = data.readShort();
123 data.readInt(); // pad
124 data.readShort(); // pad
126 assert(this.length == NONE_MINIMUM_LENGTH);
130 public void writeTo(ChannelBuffer data) {
131 data.writeShort(this.type.getValue());
132 data.writeShort(this.length);
133 data.writeInt(0); // pad
135 if (this.type == OFQueuePropType.OFPQT_MIN_RATE ||
136 this.type == OFQueuePropType.OFPQT_MAX_RATE) {
137 data.writeShort(this.rate);
138 data.writeInt(0); // pad
139 data.writeShort(0); // pad
144 public int hashCode() {
145 final int prime = 353;
146 int result = super.hashCode();
147 result = prime * result + type.getValue();
148 result = prime * result + rate;
153 public boolean equals(Object obj) {
157 if (!super.equals(obj)) {
160 if (!(obj instanceof OFQueueProp)) {
163 OFQueueProp other = (OFQueueProp) obj;
164 if (type != other.type) {
167 if (type == OFQueuePropType.OFPQT_MIN_RATE ||
168 type == OFQueuePropType.OFPQT_MAX_RATE) {
169 if (rate != other.rate) {