blob: 6d9421a4f33ebd870cf09452a9580f655ab9976b [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
Rich Lane376cafe2013-10-27 21:49:14 -070015 private final static int NONE_VAL = 0;
16 public final static LagId NONE = new LagId(NONE_VAL);
17
xinwuc1b011d2013-09-18 15:24:04 -070018 private LagId(final int rawValue) {
19 this.rawValue = rawValue;
20 }
21
22 public static LagId of(final int raw) {
23 return new LagId(raw);
24 }
25
26 public int getInt() {
27 return rawValue;
28 }
29
Andreas Wundsam85c961f2013-09-29 21:22:12 -070030 @Override
xinwuc1b011d2013-09-18 15:24:04 -070031 public int getLength() {
32 return LENGTH;
33 }
34
35 @Override
36 public int hashCode() {
37 final int prime = 31;
38 int result = 1;
39 result = prime * result + rawValue;
40 return result;
41 }
42
43 @Override
44 public String toString() {
45 return Integer.toString(rawValue);
46 }
47
48 @Override
49 public boolean equals(final Object obj) {
50 if (this == obj)
51 return true;
52 if (obj == null)
53 return false;
54 if (getClass() != obj.getClass())
55 return false;
56 LagId other = (LagId) obj;
57 if (rawValue != other.rawValue)
58 return false;
59 return true;
60 }
61
xinwuc1b011d2013-09-18 15:24:04 -070062 public void write4Bytes(ChannelBuffer c) {
63 c.writeInt(rawValue);
64 }
65
66 public static LagId read4Bytes(ChannelBuffer c) {
67 return LagId.of(c.readInt());
68 }
Andreas Wundsam85c961f2013-09-29 21:22:12 -070069
70 @Override
71 public int compareTo(LagId o) {
72 return UnsignedInts.compare(rawValue, o.rawValue);
73 }
74
75 @Override
76 public LagId applyMask(LagId mask) {
77 return LagId.of(rawValue & mask.rawValue);
78 }
Andreas Wundsam22ba3af2013-10-04 16:00:30 -070079
80 @Override
81 public void putTo(PrimitiveSink sink) {
82 sink.putInt(rawValue);
83 }
xinwuc1b011d2013-09-18 15:24:04 -070084}