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