blob: f541b6128ed1ecb03da0ac96c334f0fb9da554fa [file] [log] [blame]
Rob Vaterlausb10ae552013-09-23 14:39:39 -07001package org.projectfloodlight.openflow.types;
2
3import org.jboss.netty.buffer.ChannelBuffer;
4import org.projectfloodlight.openflow.annotations.Immutable;
5import org.projectfloodlight.openflow.exceptions.OFParseError;
6
Andreas Wundsam85c961f2013-09-29 21:22:12 -07007import com.google.common.primitives.UnsignedInts;
8
Rob Vaterlausb10ae552013-09-23 14:39:39 -07009/**
10 * Abstraction of a buffer id in OpenFlow. Immutable.
11 *
12 * @author Rob Vaterlaus <rob.vaterlaus@bigswitch.com>
13 */
14@Immutable
Andreas Wundsam85c961f2013-09-29 21:22:12 -070015public class OFBufferId implements Comparable<OFBufferId> {
Rob Vaterlausb10ae552013-09-23 14:39:39 -070016 public static final OFBufferId NO_BUFFER = new OFBufferId(0xFFFFFFFF);
17
18 private final int rawValue;
19
20 private OFBufferId(int rawValue) {
21 this.rawValue = rawValue;
22 }
23
24 public static OFBufferId of(final int rawValue) {
25 if (rawValue == NO_BUFFER.getInt())
26 return NO_BUFFER;
27 return new OFBufferId(rawValue);
28 }
29
30 public int getInt() {
31 return rawValue;
32 }
33
34 @Override
35 public String toString() {
36 return Long.toString(U32.f(rawValue));
37 }
38
Rob Vaterlausb10ae552013-09-23 14:39:39 -070039 @Override
40 public int hashCode() {
41 final int prime = 31;
42 int result = 1;
43 result = prime * result + rawValue;
44 return result;
45 }
46
47 @Override
48 public boolean equals(Object obj) {
49 if (this == obj)
50 return true;
51 if (obj == null)
52 return false;
53 if (getClass() != obj.getClass())
54 return false;
55 OFBufferId other = (OFBufferId) obj;
56 if (rawValue != other.rawValue)
57 return false;
58 return true;
59 }
Andreas Wundsam85c961f2013-09-29 21:22:12 -070060
61 @Override
62 public int compareTo(OFBufferId o) {
63 return UnsignedInts.compare(rawValue, o.rawValue);
64 }
Rob Vaterlausb10ae552013-09-23 14:39:39 -070065}