HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.util; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 2 | |
HIGUCHI Yuta | f086d8a | 2013-06-12 15:26:35 -0700 | [diff] [blame] | 3 | import net.onrc.onos.ofcontroller.util.serializers.IPv6Deserializer; |
| 4 | import net.onrc.onos.ofcontroller.util.serializers.IPv6Serializer; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 5 | |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 6 | import org.codehaus.jackson.map.annotate.JsonDeserialize; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 7 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
HIGUCHI Yuta | 858c1ea | 2013-06-14 13:10:06 -0700 | [diff] [blame^] | 8 | import org.openflow.util.HexString; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 9 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 10 | /** |
| 11 | * The class representing an IPv6 address. |
| 12 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 13 | @JsonDeserialize(using=IPv6Deserializer.class) |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 14 | @JsonSerialize(using=IPv6Serializer.class) |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 15 | public class IPv6 { |
| 16 | private long valueHigh; // The higher (more significant) 64 bits |
| 17 | private long valueLow; // The lower (less significant) 64 bits |
| 18 | |
| 19 | /** |
| 20 | * Default constructor. |
| 21 | */ |
| 22 | public IPv6() { |
| 23 | this.valueHigh = 0; |
| 24 | this.valueLow = 0; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Constructor from integer values. |
| 29 | * |
| 30 | * @param valueHigh the higher (more significant) 64 bits of the address. |
| 31 | * @param valueLow the lower (less significant) 64 bits of the address. |
| 32 | */ |
| 33 | public IPv6(long valueHigh, long valueLow) { |
| 34 | this.valueHigh = valueHigh; |
| 35 | this.valueLow = valueLow; |
| 36 | } |
| 37 | |
| 38 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 39 | * Constructor from a string. |
| 40 | * |
| 41 | * @param value the value to use. |
| 42 | */ |
| 43 | public IPv6(String value) { |
| 44 | // TODO: Implement it! |
| 45 | this.valueHigh = 0; |
| 46 | this.valueLow = 0; |
| 47 | } |
| 48 | |
| 49 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 50 | * Get the value of the higher (more significant) 64 bits of the address. |
| 51 | * |
| 52 | * @return the value of the higher (more significant) 64 bits of the |
| 53 | * address. |
| 54 | */ |
| 55 | public long valueHigh() { return valueHigh; } |
| 56 | |
| 57 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 58 | * Set the value of the higher (more significant) 64 bits of the address. |
| 59 | * |
| 60 | * @param valueHigh the higher (more significant) 64 bits of the address. |
| 61 | */ |
| 62 | public void setValueHigh(long valueHigh) { |
| 63 | this.valueHigh = valueHigh; |
| 64 | } |
| 65 | |
| 66 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 67 | * Get the value of the lower (less significant) 64 bits of the address. |
| 68 | * |
| 69 | * @return the value of the lower (less significant) 64 bits of the |
| 70 | * address. |
| 71 | */ |
| 72 | public long valueLow() { return valueLow; } |
| 73 | |
| 74 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 75 | * Get the value of the lower (less significant) 64 bits of the address. |
| 76 | * |
| 77 | * @param valueLow the lower (less significant) 64 bits of the address. |
| 78 | */ |
| 79 | public void setValueLow(long valueLow) { |
| 80 | this.valueLow = valueLow; |
| 81 | } |
| 82 | |
| 83 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 84 | * Set the value of the IPv6 address. |
| 85 | * |
| 86 | * @param valueHigh the higher (more significant) 64 bits of the address. |
| 87 | * @param valueLow the lower (less significant) 64 bits of the address. |
| 88 | */ |
| 89 | public void setValue(long valueHigh, long valueLow) { |
| 90 | this.valueHigh = valueHigh; |
| 91 | this.valueLow = valueLow; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Convert the IPv6 value to a ':' separated string. |
| 96 | * |
| 97 | * @return the IPv6 value as a ':' separated string. |
| 98 | */ |
| 99 | @Override |
| 100 | public String toString() { |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 101 | return HexString.toHexString(this.valueHigh) + ":" + |
| 102 | HexString.toHexString(this.valueLow); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 103 | } |
| 104 | } |