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 java.util.ArrayList;
20 import java.util.List;
22 import org.jboss.netty.buffer.ChannelBuffer;
23 import org.openflow.util.U16;
26 * Represents ofp_packet_queue
27 * @author Andrew Ferguson (adf@cs.brown.edu)
29 public class OFPacketQueue {
30 public static int MINIMUM_LENGTH = 8;
32 protected int queueId;
33 protected short length;
34 protected List<OFQueueProp> properties = new ArrayList<OFQueueProp>();
36 public OFPacketQueue() {
38 this.length = U16.t(MINIMUM_LENGTH);
41 public OFPacketQueue(int queueId) {
42 this.queueId = queueId;
43 this.length = U16.t(MINIMUM_LENGTH);
49 public long getQueueId() {
54 * @param queueId the queueId to set
56 public void setQueueId(int queueId) {
57 this.queueId = queueId;
61 * @return the queue's properties
63 public List<OFQueueProp> getProperties() {
68 * @param properties the properties to set
70 public void setProperties(List<OFQueueProp> properties) {
71 this.properties = properties;
73 this.length = U16.t(MINIMUM_LENGTH);
74 for (OFQueueProp prop : properties) {
75 this.length += prop.getLength();
82 public short getLength() {
86 public void readFrom(ChannelBuffer data) {
87 this.queueId = data.readInt();
88 this.length = data.readShort();
89 data.readShort(); // pad
91 int availLength = (this.length - MINIMUM_LENGTH);
92 this.properties.clear();
94 while (availLength > 0) {
95 OFQueueProp prop = new OFQueueProp();
98 availLength -= prop.getLength();
102 public void writeTo(ChannelBuffer data) {
103 data.writeInt(queueId);
104 data.writeShort(length);
105 data.writeShort(0); // pad
107 for (OFQueueProp prop : properties) {
113 public int hashCode() {
114 final int prime = 359;
115 int result = super.hashCode();
116 result = prime * result + queueId;
117 result = prime * result + length;
118 result = prime * result + properties.hashCode();
123 public boolean equals(Object obj) {
127 if (!super.equals(obj)) {
130 if (!(obj instanceof OFPacketQueue)) {
133 OFPacketQueue other = (OFPacketQueue) obj;
134 if (queueId != other.queueId) {
137 if (! properties.equals(other.properties)) {