blob: f3812dd2d888ee986bb48e4f19dba24b8080410b [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 Wundsam85c961f2013-09-29 21:22:12 -07005import com.google.common.primitives.UnsignedInts;
6
Rob Vaterlausb10ae552013-09-23 14:39:39 -07007/**
8 * Abstraction of a buffer id in OpenFlow. Immutable.
9 *
10 * @author Rob Vaterlaus <rob.vaterlaus@bigswitch.com>
11 */
12@Immutable
Andreas Wundsam85c961f2013-09-29 21:22:12 -070013public class OFBufferId implements Comparable<OFBufferId> {
Rob Vaterlausb10ae552013-09-23 14:39:39 -070014 public static final OFBufferId NO_BUFFER = new OFBufferId(0xFFFFFFFF);
15
16 private final int rawValue;
17
18 private OFBufferId(int rawValue) {
19 this.rawValue = rawValue;
20 }
21
22 public static OFBufferId of(final int rawValue) {
23 if (rawValue == NO_BUFFER.getInt())
24 return NO_BUFFER;
25 return new OFBufferId(rawValue);
26 }
27
28 public int getInt() {
29 return rawValue;
30 }
31
32 @Override
33 public String toString() {
34 return Long.toString(U32.f(rawValue));
35 }
36
Rob Vaterlausb10ae552013-09-23 14:39:39 -070037 @Override
38 public int hashCode() {
39 final int prime = 31;
40 int result = 1;
41 result = prime * result + rawValue;
42 return result;
43 }
44
45 @Override
46 public boolean equals(Object obj) {
47 if (this == obj)
48 return true;
49 if (obj == null)
50 return false;
51 if (getClass() != obj.getClass())
52 return false;
53 OFBufferId other = (OFBufferId) obj;
54 if (rawValue != other.rawValue)
55 return false;
56 return true;
57 }
Andreas Wundsam85c961f2013-09-29 21:22:12 -070058
59 @Override
60 public int compareTo(OFBufferId o) {
61 return UnsignedInts.compare(rawValue, o.rawValue);
62 }
Rob Vaterlausb10ae552013-09-23 14:39:39 -070063}