blob: d49e4e2bf504a3f8eebcc475c05cf03fb3ace5f2 [file] [log] [blame]
Yotam Harchold7b84202013-07-26 16:08:10 -07001package org.openflow.types;
2
3import org.jboss.netty.buffer.ChannelBuffer;
4import org.openflow.exceptions.OFParseError;
5
Yotam Harchol5c9d6f42013-08-01 11:09:20 -07006public class IPv6FlowLabel implements OFValueType<IPv6FlowLabel> {
Yotam Harchold7b84202013-07-26 16:08:10 -07007
8 static final int LENGTH = 4;
9
10 private final int label;
11
12 private IPv6FlowLabel(int label) {
13 this.label = label;
14 }
15
16 public static IPv6FlowLabel of(int label) {
17 return new IPv6FlowLabel(label);
18 }
19
20 @Override
21 public int getLength() {
22 return LENGTH;
23 }
24
25 @Override
26 public boolean equals(Object obj) {
27 if (!(obj instanceof IPv6FlowLabel))
28 return false;
29 IPv6FlowLabel other = (IPv6FlowLabel)obj;
30 if (other.label != this.label)
31 return false;
32 return true;
33 }
34
35 @Override
36 public int hashCode() {
37 final int prime = 59;
38 int result = 1;
39 result = prime * result + label;
40 return result;
41 }
42
43 @Override
44 public String toString() {
45 return Integer.toHexString(label);
46 }
47
48 public void write4Bytes(ChannelBuffer c) {
49 c.writeInt(this.label);
50 }
51
52 public static IPv6FlowLabel read4Bytes(ChannelBuffer c) throws OFParseError {
53 return IPv6FlowLabel.of((int)(c.readUnsignedInt() & 0xFFFFFFFF));
54 }
55
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070056 @Override
57 public IPv6FlowLabel applyMask(IPv6FlowLabel mask) {
58 return IPv6FlowLabel.of(this.label & mask.label);
59 }
60
61 public int getIPv6FlowLabelValue() {
62 return label;
63 }
Yotam Harchold7b84202013-07-26 16:08:10 -070064}