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 | |
Andreas Wundsam | b75c4ad | 2013-09-23 14:45:35 -0700 | [diff] [blame] | 12 | private final static int NONE_VAL = 0x0; |
| 13 | public static final IPv6FlowLabel NONE = new IPv6FlowLabel(NONE_VAL); |
| 14 | |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 15 | 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 Wundsam | b75c4ad | 2013-09-23 14:45:35 -0700 | [diff] [blame] | 23 | if(label == NONE_VAL) |
| 24 | return NONE; |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 25 | 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 | } |