blob: 10e2ebcaa4e2c15c4113043f7b771e3733ef01c8 [file] [log] [blame]
xinwuc1b011d2013-09-18 15:24:04 -07001package org.projectfloodlight.openflow.types;
2
xinwu32034432013-09-18 17:17:50 -07003import javax.annotation.concurrent.Immutable;
xinwuc1b011d2013-09-18 15:24:04 -07004
Andreas Wundsam85c961f2013-09-29 21:22:12 -07005import org.jboss.netty.buffer.ChannelBuffer;
6
7import com.google.common.primitives.UnsignedInts;
8
xinwuc1b011d2013-09-18 15:24:04 -07009@Immutable
10public class VRF implements OFValueType<VRF> {
11 static final int LENGTH = 4;
12 private final int rawValue;
13
14 public static final VRF NO_MASK = VRF.of(0xFFFFFFFF);
15 public static final VRF FULL_MASK = VRF.of(0x00000000);
16
17 private VRF(final int rawValue) {
18 this.rawValue = rawValue;
19 }
20
21 public static VRF of(final int raw) {
22 return new VRF(raw);
23 }
24
25 public int getInt() {
26 return rawValue;
27 }
28
29 @Override
30 public int getLength() {
31 return LENGTH;
32 }
33
34 @Override
35 public int hashCode() {
36 final int prime = 31;
37 int result = 1;
38 result = prime * result + rawValue;
39 return result;
40 }
41
42 @Override
43 public boolean equals(Object obj) {
44 if (this == obj)
45 return true;
46 if (obj == null)
47 return false;
48 if (getClass() != obj.getClass())
49 return false;
50 VRF other = (VRF) obj;
51 if (rawValue != other.rawValue)
52 return false;
53 return true;
54 }
55
56 @Override
57 public String toString() {
58 return Integer.toString(rawValue);
59 }
60
61 public void write4Bytes(ChannelBuffer c) {
62 c.writeInt(rawValue);
63 }
64
65 public static VRF read4Bytes(ChannelBuffer c) {
66 return VRF.of(c.readInt());
67 }
68
69 @Override
70 public VRF applyMask(VRF mask) {
71 return VRF.of(this.rawValue & mask.rawValue);
72 }
Andreas Wundsam85c961f2013-09-29 21:22:12 -070073
74 @Override
75 public int compareTo(VRF o) {
76 return UnsignedInts.compare(rawValue, o.rawValue);
77 }
xinwuc1b011d2013-09-18 15:24:04 -070078}