xinwu | c1b011d | 2013-09-18 15:24:04 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.types; |
| 2 | |
xinwu | 3203443 | 2013-09-18 17:17:50 -0700 | [diff] [blame] | 3 | import javax.annotation.concurrent.Immutable; |
xinwu | c1b011d | 2013-09-18 15:24:04 -0700 | [diff] [blame] | 4 | |
Andreas Wundsam | 85c961f | 2013-09-29 21:22:12 -0700 | [diff] [blame] | 5 | import org.jboss.netty.buffer.ChannelBuffer; |
| 6 | |
| 7 | import com.google.common.primitives.UnsignedInts; |
| 8 | |
xinwu | c1b011d | 2013-09-18 15:24:04 -0700 | [diff] [blame] | 9 | @Immutable |
Andreas Wundsam | 85c961f | 2013-09-29 21:22:12 -0700 | [diff] [blame] | 10 | public class LagId implements OFValueType<LagId> { |
xinwu | c1b011d | 2013-09-18 15:24:04 -0700 | [diff] [blame] | 11 | static final int LENGTH = 4; |
| 12 | private final int rawValue; |
| 13 | |
xinwu | c1b011d | 2013-09-18 15:24:04 -0700 | [diff] [blame] | 14 | private LagId(final int rawValue) { |
| 15 | this.rawValue = rawValue; |
| 16 | } |
| 17 | |
| 18 | public static LagId of(final int raw) { |
| 19 | return new LagId(raw); |
| 20 | } |
| 21 | |
| 22 | public int getInt() { |
| 23 | return rawValue; |
| 24 | } |
| 25 | |
Andreas Wundsam | 85c961f | 2013-09-29 21:22:12 -0700 | [diff] [blame] | 26 | @Override |
xinwu | c1b011d | 2013-09-18 15:24:04 -0700 | [diff] [blame] | 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 String toString() { |
| 41 | return Integer.toString(rawValue); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public boolean equals(final Object obj) { |
| 46 | if (this == obj) |
| 47 | return true; |
| 48 | if (obj == null) |
| 49 | return false; |
| 50 | if (getClass() != obj.getClass()) |
| 51 | return false; |
| 52 | LagId other = (LagId) obj; |
| 53 | if (rawValue != other.rawValue) |
| 54 | return false; |
| 55 | return true; |
| 56 | } |
| 57 | |
xinwu | c1b011d | 2013-09-18 15:24:04 -0700 | [diff] [blame] | 58 | public void write4Bytes(ChannelBuffer c) { |
| 59 | c.writeInt(rawValue); |
| 60 | } |
| 61 | |
| 62 | public static LagId read4Bytes(ChannelBuffer c) { |
| 63 | return LagId.of(c.readInt()); |
| 64 | } |
Andreas Wundsam | 85c961f | 2013-09-29 21:22:12 -0700 | [diff] [blame] | 65 | |
| 66 | @Override |
| 67 | public int compareTo(LagId o) { |
| 68 | return UnsignedInts.compare(rawValue, o.rawValue); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public LagId applyMask(LagId mask) { |
| 73 | return LagId.of(rawValue & mask.rawValue); |
| 74 | } |
xinwu | c1b011d | 2013-09-18 15:24:04 -0700 | [diff] [blame] | 75 | } |