Initial opendaylight infrastructure commit!!
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / queue / OFQueueProperty.java
1 package org.openflow.protocol.queue;
2
3 import java.nio.ByteBuffer;
4
5 import org.openflow.util.U16;
6
7 /**
8  * Corresponds to the struct ofp_queue_prop_header OpenFlow structure
9  *
10  * @author David Erickson (daviderickson@cs.stanford.edu)
11  */
12 public class OFQueueProperty implements Cloneable {
13     public static int MINIMUM_LENGTH = 8;
14
15     protected OFQueuePropertyType type;
16     protected short length;
17
18     /**
19      * @return the type
20      */
21     public OFQueuePropertyType getType() {
22         return type;
23     }
24
25     /**
26      * @param type the type to set
27      */
28     public void setType(OFQueuePropertyType type) {
29         this.type = type;
30     }
31
32     /**
33      * @return the length
34      */
35     public short getLength() {
36         return length;
37     }
38
39     /**
40      * Returns the unsigned length
41      *
42      * @return the length
43      */
44     public int getLengthU() {
45         return U16.f(length);
46     }
47
48     /**
49      * @param length the length to set
50      */
51     public void setLength(short length) {
52         this.length = length;
53     }
54
55     public void readFrom(ByteBuffer data) {
56         this.type = OFQueuePropertyType.valueOf(data.getShort());
57         this.length = data.getShort();
58         data.getInt(); // pad
59     }
60
61     public void writeTo(ByteBuffer data) {
62         data.putShort(this.type.getTypeValue());
63         data.putShort(this.length);
64         data.putInt(0); // pad
65     }
66
67     @Override
68     public int hashCode() {
69         final int prime = 2777;
70         int result = 1;
71         result = prime * result + length;
72         result = prime * result + ((type == null) ? 0 : type.hashCode());
73         return result;
74     }
75
76     @Override
77     public boolean equals(Object obj) {
78         if (this == obj)
79             return true;
80         if (obj == null)
81             return false;
82         if (!(obj instanceof OFQueueProperty))
83             return false;
84         OFQueueProperty other = (OFQueueProperty) obj;
85         if (length != other.length)
86             return false;
87         if (type != other.type)
88             return false;
89         return true;
90     }
91
92     @Override
93     protected OFQueueProperty clone() {
94         try {
95             return (OFQueueProperty) super.clone();
96         } catch (CloneNotSupportedException e) {
97             throw new RuntimeException(e);
98         }
99     }
100 }