xinwu | c1b011d | 2013-09-18 15:24:04 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.types; |
| 2 | |
| 3 | import org.jboss.netty.buffer.ChannelBuffer; |
xinwu | 3203443 | 2013-09-18 17:17:50 -0700 | [diff] [blame] | 4 | import javax.annotation.concurrent.Immutable; |
xinwu | c1b011d | 2013-09-18 15:24:04 -0700 | [diff] [blame] | 5 | |
| 6 | @Immutable |
| 7 | public 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 | } |