Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 1 | package org.openflow.types; |
| 2 | |
| 3 | import org.jboss.netty.buffer.ChannelBuffer; |
| 4 | import org.openflow.exceptions.OFParseError; |
| 5 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 6 | public class IPv6FlowLabel implements OFValueType<IPv6FlowLabel> { |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 7 | |
| 8 | static final int LENGTH = 4; |
| 9 | |
| 10 | private final int label; |
| 11 | |
Yotam Harchol | ff8f85e | 2013-08-21 10:02:23 -0700 | [diff] [blame] | 12 | public static final IPv6FlowLabel NO_MASK = IPv6FlowLabel.of(0xFFFFFFFF); |
| 13 | public static final IPv6FlowLabel FULL_MASK = IPv6FlowLabel.of(0x0); |
Yotam Harchol | c281360 | 2013-08-20 12:14:22 -0700 | [diff] [blame] | 14 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 15 | 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 Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 59 | @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 Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 67 | } |