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 | /** |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 28 | * Copy constructor. |
| 29 | * |
| 30 | * @param other the object to copy from. |
| 31 | */ |
| 32 | public IPv6(IPv6 other) { |
| 33 | this.valueHigh = other.valueHigh; |
| 34 | this.valueLow = other.valueLow; |
| 35 | } |
| 36 | |
| 37 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 38 | * Constructor from integer values. |
| 39 | * |
| 40 | * @param valueHigh the higher (more significant) 64 bits of the address. |
| 41 | * @param valueLow the lower (less significant) 64 bits of the address. |
| 42 | */ |
| 43 | public IPv6(long valueHigh, long valueLow) { |
| 44 | this.valueHigh = valueHigh; |
| 45 | this.valueLow = valueLow; |
| 46 | } |
| 47 | |
| 48 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 49 | * Constructor from a string. |
| 50 | * |
| 51 | * @param value the value to use. |
| 52 | */ |
| 53 | public IPv6(String value) { |
| 54 | // TODO: Implement it! |
| 55 | this.valueHigh = 0; |
| 56 | this.valueLow = 0; |
| 57 | } |
| 58 | |
| 59 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 60 | * Get the value of the higher (more significant) 64 bits of the address. |
| 61 | * |
| 62 | * @return the value of the higher (more significant) 64 bits of the |
| 63 | * address. |
| 64 | */ |
| 65 | public long valueHigh() { return valueHigh; } |
| 66 | |
| 67 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 68 | * Set the value of the higher (more significant) 64 bits of the address. |
| 69 | * |
| 70 | * @param valueHigh the higher (more significant) 64 bits of the address. |
| 71 | */ |
| 72 | public void setValueHigh(long valueHigh) { |
| 73 | this.valueHigh = valueHigh; |
| 74 | } |
| 75 | |
| 76 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 77 | * Get the value of the lower (less significant) 64 bits of the address. |
| 78 | * |
| 79 | * @return the value of the lower (less significant) 64 bits of the |
| 80 | * address. |
| 81 | */ |
| 82 | public long valueLow() { return valueLow; } |
| 83 | |
| 84 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 85 | * Get the value of the lower (less significant) 64 bits of the address. |
| 86 | * |
| 87 | * @param valueLow the lower (less significant) 64 bits of the address. |
| 88 | */ |
| 89 | public void setValueLow(long valueLow) { |
| 90 | this.valueLow = valueLow; |
| 91 | } |
| 92 | |
| 93 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 94 | * Set the value of the IPv6 address. |
| 95 | * |
| 96 | * @param valueHigh the higher (more significant) 64 bits of the address. |
| 97 | * @param valueLow the lower (less significant) 64 bits of the address. |
| 98 | */ |
| 99 | public void setValue(long valueHigh, long valueLow) { |
| 100 | this.valueHigh = valueHigh; |
| 101 | this.valueLow = valueLow; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Convert the IPv6 value to a ':' separated string. |
| 106 | * |
| 107 | * @return the IPv6 value as a ':' separated string. |
| 108 | */ |
| 109 | @Override |
| 110 | public String toString() { |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 111 | return HexString.toHexString(this.valueHigh) + ":" + |
| 112 | HexString.toHexString(this.valueLow); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 113 | } |
| 114 | } |