blob: b7f7f6780afc95391c8c57ea5c81fe24fe7e3f54 [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
7import com.google.common.primitives.UnsignedInts;
8
xinwuc1b011d2013-09-18 15:24:04 -07009@Immutable
Andreas Wundsam85c961f2013-09-29 21:22:12 -070010public class LagId implements OFValueType<LagId> {
xinwuc1b011d2013-09-18 15:24:04 -070011 static final int LENGTH = 4;
12 private final int rawValue;
13
xinwuc1b011d2013-09-18 15:24:04 -070014 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 Wundsam85c961f2013-09-29 21:22:12 -070026 @Override
xinwuc1b011d2013-09-18 15:24:04 -070027 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
xinwuc1b011d2013-09-18 15:24:04 -070058 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 Wundsam85c961f2013-09-29 21:22:12 -070065
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 }
xinwuc1b011d2013-09-18 15:24:04 -070075}