blob: 7f76b4d77fe0e62cd0b2b99c062fb1ed2aba491d [file] [log] [blame]
Rob Vaterlausb10ae552013-09-23 14:39:39 -07001package org.projectfloodlight.openflow.types;
2
Rob Vaterlausb10ae552013-09-23 14:39:39 -07003import org.projectfloodlight.openflow.annotations.Immutable;
Rob Vaterlausb10ae552013-09-23 14:39:39 -07004
Andreas Wundsam22ba3af2013-10-04 16:00:30 -07005import com.google.common.hash.PrimitiveSink;
Andreas Wundsam85c961f2013-09-29 21:22:12 -07006import com.google.common.primitives.UnsignedInts;
7
Rob Vaterlausb10ae552013-09-23 14:39:39 -07008/**
9 * Abstraction of a buffer id in OpenFlow. Immutable.
10 *
11 * @author Rob Vaterlaus <rob.vaterlaus@bigswitch.com>
12 */
13@Immutable
Andreas Wundsam22ba3af2013-10-04 16:00:30 -070014public class OFBufferId implements Comparable<OFBufferId>, PrimitiveSinkable {
Rob Vaterlausb10ae552013-09-23 14:39:39 -070015 public static final OFBufferId NO_BUFFER = new OFBufferId(0xFFFFFFFF);
16
17 private final int rawValue;
18
19 private OFBufferId(int rawValue) {
20 this.rawValue = rawValue;
21 }
22
23 public static OFBufferId of(final int rawValue) {
24 if (rawValue == NO_BUFFER.getInt())
25 return NO_BUFFER;
26 return new OFBufferId(rawValue);
27 }
28
29 public int getInt() {
30 return rawValue;
31 }
32
33 @Override
34 public String toString() {
35 return Long.toString(U32.f(rawValue));
36 }
37
Rob Vaterlausb10ae552013-09-23 14:39:39 -070038 @Override
39 public int hashCode() {
40 final int prime = 31;
41 int result = 1;
42 result = prime * result + rawValue;
43 return result;
44 }
45
46 @Override
47 public boolean equals(Object obj) {
48 if (this == obj)
49 return true;
50 if (obj == null)
51 return false;
52 if (getClass() != obj.getClass())
53 return false;
54 OFBufferId other = (OFBufferId) obj;
55 if (rawValue != other.rawValue)
56 return false;
57 return true;
58 }
Andreas Wundsam85c961f2013-09-29 21:22:12 -070059
60 @Override
61 public int compareTo(OFBufferId o) {
62 return UnsignedInts.compare(rawValue, o.rawValue);
63 }
Andreas Wundsam22ba3af2013-10-04 16:00:30 -070064
65 @Override
66 public void putTo(PrimitiveSink sink) {
67 sink.putInt(rawValue);
68 }
Rob Vaterlausb10ae552013-09-23 14:39:39 -070069}