blob: def5947ef5c15d2820cd145b7a3604e522bd7393 [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
Yotam Harcholff8f85e2013-08-21 10:02:23 -070012 public static final IPv6FlowLabel NO_MASK = IPv6FlowLabel.of(0xFFFFFFFF);
13 public static final IPv6FlowLabel FULL_MASK = IPv6FlowLabel.of(0x0);
Yotam Harcholc2813602013-08-20 12:14:22 -070014
Yotam Harchold7b84202013-07-26 16:08:10 -070015 private IPv6FlowLabel(int label) {
16 this.label = label;
17 }
18
19 public static IPv6FlowLabel of(int label) {
20 return new IPv6FlowLabel(label);
21 }
22
23 @Override
24 public int getLength() {
25 return LENGTH;
26 }
27
28 @Override
29 public boolean equals(Object obj) {
30 if (!(obj instanceof IPv6FlowLabel))
31 return false;
32 IPv6FlowLabel other = (IPv6FlowLabel)obj;
33 if (other.label != this.label)
34 return false;
35 return true;
36 }
37
38 @Override
39 public int hashCode() {
40 final int prime = 59;
41 int result = 1;
42 result = prime * result + label;
43 return result;
44 }
45
46 @Override
47 public String toString() {
48 return Integer.toHexString(label);
49 }
50
51 public void write4Bytes(ChannelBuffer c) {
52 c.writeInt(this.label);
53 }
54
55 public static IPv6FlowLabel read4Bytes(ChannelBuffer c) throws OFParseError {
56 return IPv6FlowLabel.of((int)(c.readUnsignedInt() & 0xFFFFFFFF));
57 }
58
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070059 @Override
60 public IPv6FlowLabel applyMask(IPv6FlowLabel mask) {
61 return IPv6FlowLabel.of(this.label & mask.label);
62 }
63
64 public int getIPv6FlowLabelValue() {
65 return label;
66 }
Yotam Harchold7b84202013-07-26 16:08:10 -070067}