blob: 76c7011ab637a21e34a054111b57a96d5174a6d5 [file] [log] [blame]
xinwuc1b011d2013-09-18 15:24:04 -07001package org.projectfloodlight.openflow.types;
2
3import org.jboss.netty.buffer.ChannelBuffer;
4import org.projectfloodlight.openflow.annotations.Immutable;
5
6@Immutable
7public class LagId implements OFValueType<LagId> {
8 static final int LENGTH = 4;
9 private final int rawValue;
10
11 public static final LagId NO_ClassId = LagId.of(0xFFFFFFFF);
12 public static final LagId FULL_MASK = LagId.of(0x00000000);
13
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
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 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
58 @Override
59 public LagId applyMask(LagId mask) {
60 return LagId.of(this.rawValue & mask.rawValue);
61 }
62
63 public void write4Bytes(ChannelBuffer c) {
64 c.writeInt(rawValue);
65 }
66
67 public static LagId read4Bytes(ChannelBuffer c) {
68 return LagId.of(c.readInt());
69 }
70}