e4aeeeed43ff63b852ca801d79bb7cf86a3d0ec7
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / queue / OFPQueuePropertyMinRate.java
1 package org.openflow.codec.protocol.queue;
2
3 import org.openflow.codec.io.IDataBuffer;
4 import org.openflow.codec.util.U16;
5
6 /**
7  * Corresponds to the struct ofp_queue_prop_min_rate OpenFlow structure
8  *
9  * @author David Erickson (daviderickson@cs.stanford.edu)
10  */
11 public class OFPQueuePropertyMinRate extends OFPQueueProperty {
12     public static int MINIMUM_LENGTH = 16;
13
14     protected short rate;
15
16     /**
17      *
18      */
19     public OFPQueuePropertyMinRate() {
20         super();
21         this.type = OFPQueuePropertyType.MIN_RATE;
22         this.length = U16.t(MINIMUM_LENGTH);
23     }
24
25     /**
26      * @return the rate
27      */
28     public short getRate() {
29         return rate;
30     }
31
32     /**
33      * @param rate
34      *            the rate to set
35      */
36     public OFPQueuePropertyMinRate setRate(short rate) {
37         this.rate = rate;
38         return this;
39     }
40
41     @Override
42     public void readFrom(IDataBuffer data) {
43         super.readFrom(data);
44         this.rate = data.getShort();
45         data.getInt(); // pad
46         data.getShort(); // pad
47     }
48
49     @Override
50     public void writeTo(IDataBuffer data) {
51         super.writeTo(data);
52         data.putShort(this.rate);
53         data.putInt(0); // pad
54         data.putShort((short) 0); // pad
55     }
56
57     @Override
58     public int hashCode() {
59         final int prime = 3259;
60         int result = super.hashCode();
61         result = prime * result + rate;
62         return result;
63     }
64
65     @Override
66     public boolean equals(Object obj) {
67         if (this == obj)
68             return true;
69         if (!super.equals(obj))
70             return false;
71         if (!(obj instanceof OFPQueuePropertyMinRate))
72             return false;
73         OFPQueuePropertyMinRate other = (OFPQueuePropertyMinRate) obj;
74         if (rate != other.rate)
75             return false;
76         return true;
77     }
78
79     /*
80      * (non-Javadoc)
81      *
82      * @see java.lang.Object#toString()
83      */
84     @Override
85     public String toString() {
86         return "OFPQueuePropertyMinRate [type=" + type + ", rate=" + U16.f(rate) + "]";
87     }
88
89 }