blob: 7dbf9bb80b9b03869aa3100c99ac77a4a18c2a8d [file] [log] [blame]
Yotam Harcholf3f11152013-09-05 16:47:16 -07001package org.projectfloodlight.openflow.types;
2
3import org.jboss.netty.buffer.ChannelBuffer;
4import org.projectfloodlight.openflow.exceptions.OFParseError;
5
6public class IPv6FlowLabel implements OFValueType<IPv6FlowLabel> {
7
8 static final int LENGTH = 4;
9
10 private final int label;
11
Andreas Wundsamb75c4ad2013-09-23 14:45:35 -070012 private final static int NONE_VAL = 0x0;
13 public static final IPv6FlowLabel NONE = new IPv6FlowLabel(NONE_VAL);
14
Yotam Harcholf3f11152013-09-05 16:47:16 -070015 public static final IPv6FlowLabel NO_MASK = IPv6FlowLabel.of(0xFFFFFFFF);
16 public static final IPv6FlowLabel FULL_MASK = IPv6FlowLabel.of(0x0);
17
18 private IPv6FlowLabel(int label) {
19 this.label = label;
20 }
21
22 public static IPv6FlowLabel of(int label) {
Andreas Wundsamb75c4ad2013-09-23 14:45:35 -070023 if(label == NONE_VAL)
24 return NONE;
Yotam Harcholf3f11152013-09-05 16:47:16 -070025 return new IPv6FlowLabel(label);
26 }
27
28 @Override
29 public int getLength() {
30 return LENGTH;
31 }
32
33 @Override
34 public boolean equals(Object obj) {
35 if (!(obj instanceof IPv6FlowLabel))
36 return false;
37 IPv6FlowLabel other = (IPv6FlowLabel)obj;
38 if (other.label != this.label)
39 return false;
40 return true;
41 }
42
43 @Override
44 public int hashCode() {
45 final int prime = 59;
46 int result = 1;
47 result = prime * result + label;
48 return result;
49 }
50
51 @Override
52 public String toString() {
53 return Integer.toHexString(label);
54 }
55
56 public void write4Bytes(ChannelBuffer c) {
57 c.writeInt(this.label);
58 }
59
60 public static IPv6FlowLabel read4Bytes(ChannelBuffer c) throws OFParseError {
61 return IPv6FlowLabel.of((int)(c.readUnsignedInt() & 0xFFFFFFFF));
62 }
63
64 @Override
65 public IPv6FlowLabel applyMask(IPv6FlowLabel mask) {
66 return IPv6FlowLabel.of(this.label & mask.label);
67 }
68
69 public int getIPv6FlowLabelValue() {
70 return label;
71 }
72}