Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.types; |
| 2 | |
| 3 | import org.jboss.netty.buffer.ChannelBuffer; |
| 4 | import org.projectfloodlight.openflow.exceptions.OFParseError; |
| 5 | |
| 6 | public class IPv6FlowLabel implements OFValueType<IPv6FlowLabel> { |
| 7 | |
| 8 | static final int LENGTH = 4; |
| 9 | |
| 10 | private final int label; |
| 11 | |
| 12 | public static final IPv6FlowLabel NO_MASK = IPv6FlowLabel.of(0xFFFFFFFF); |
| 13 | public static final IPv6FlowLabel FULL_MASK = IPv6FlowLabel.of(0x0); |
| 14 | |
| 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 | |
| 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 | } |
| 67 | } |