blob: 2046d7143118e8c073e7938ab134bb6408162b90 [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
Andreas Wundsam22ba3af2013-10-04 16:00:30 -07007import com.google.common.hash.PrimitiveSink;
Andreas Wundsam85c961f2013-09-29 21:22:12 -07008import com.google.common.primitives.UnsignedInts;
9
xinwuc1b011d2013-09-18 15:24:04 -070010@Immutable
Andreas Wundsam85c961f2013-09-29 21:22:12 -070011public class LagId implements OFValueType<LagId> {
xinwuc1b011d2013-09-18 15:24:04 -070012 static final int LENGTH = 4;
13 private final int rawValue;
14
xinwuc1b011d2013-09-18 15:24:04 -070015 private LagId(final int rawValue) {
16 this.rawValue = rawValue;
17 }
18
19 public static LagId of(final int raw) {
20 return new LagId(raw);
21 }
22
23 public int getInt() {
24 return rawValue;
25 }
26
Andreas Wundsam85c961f2013-09-29 21:22:12 -070027 @Override
xinwuc1b011d2013-09-18 15:24:04 -070028 public int getLength() {
29 return LENGTH;
30 }
31
32 @Override
33 public int hashCode() {
34 final int prime = 31;
35 int result = 1;
36 result = prime * result + rawValue;
37 return result;
38 }
39
40 @Override
41 public String toString() {
42 return Integer.toString(rawValue);
43 }
44
45 @Override
46 public boolean equals(final 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 LagId other = (LagId) obj;
54 if (rawValue != other.rawValue)
55 return false;
56 return true;
57 }
58
xinwuc1b011d2013-09-18 15:24:04 -070059 public void write4Bytes(ChannelBuffer c) {
60 c.writeInt(rawValue);
61 }
62
63 public static LagId read4Bytes(ChannelBuffer c) {
64 return LagId.of(c.readInt());
65 }
Andreas Wundsam85c961f2013-09-29 21:22:12 -070066
67 @Override
68 public int compareTo(LagId o) {
69 return UnsignedInts.compare(rawValue, o.rawValue);
70 }
71
72 @Override
73 public LagId applyMask(LagId mask) {
74 return LagId.of(rawValue & mask.rawValue);
75 }
Andreas Wundsam22ba3af2013-10-04 16:00:30 -070076
77 @Override
78 public void putTo(PrimitiveSink sink) {
79 sink.putInt(rawValue);
80 }
xinwuc1b011d2013-09-18 15:24:04 -070081}