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 | |
| 6 | public class IPv6FlowLabel implements OFValueType { |
| 7 | |
| 8 | static final int LENGTH = 4; |
| 9 | |
| 10 | private final int label; |
| 11 | |
| 12 | private IPv6FlowLabel(int label) { |
| 13 | this.label = label; |
| 14 | } |
| 15 | |
| 16 | public static IPv6FlowLabel of(int label) { |
| 17 | return new IPv6FlowLabel(label); |
| 18 | } |
| 19 | |
| 20 | @Override |
| 21 | public int getLength() { |
| 22 | return LENGTH; |
| 23 | } |
| 24 | |
| 25 | @Override |
| 26 | public boolean equals(Object obj) { |
| 27 | if (!(obj instanceof IPv6FlowLabel)) |
| 28 | return false; |
| 29 | IPv6FlowLabel other = (IPv6FlowLabel)obj; |
| 30 | if (other.label != this.label) |
| 31 | return false; |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public int hashCode() { |
| 37 | final int prime = 59; |
| 38 | int result = 1; |
| 39 | result = prime * result + label; |
| 40 | return result; |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public String toString() { |
| 45 | return Integer.toHexString(label); |
| 46 | } |
| 47 | |
| 48 | public void write4Bytes(ChannelBuffer c) { |
| 49 | c.writeInt(this.label); |
| 50 | } |
| 51 | |
| 52 | public static IPv6FlowLabel read4Bytes(ChannelBuffer c) throws OFParseError { |
| 53 | return IPv6FlowLabel.of((int)(c.readUnsignedInt() & 0xFFFFFFFF)); |
| 54 | } |
| 55 | |
| 56 | } |