Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.util; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 2 | |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 3 | import net.onrc.onos.core.util.serializers.IPv6Deserializer; |
| 4 | import net.onrc.onos.core.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 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 13 | @JsonDeserialize(using = IPv6Deserializer.class) |
| 14 | @JsonSerialize(using = IPv6Serializer.class) |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 15 | public class IPv6 { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 16 | private long valueHigh; // The higher (more significant) 64 bits |
| 17 | private long valueLow; // The lower (less significant) 64 bits |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 18 | |
| 19 | /** |
| 20 | * Default constructor. |
| 21 | */ |
| 22 | public IPv6() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 23 | this.valueHigh = 0; |
| 24 | this.valueLow = 0; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 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) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 33 | this.valueHigh = other.valueHigh; |
| 34 | this.valueLow = other.valueLow; |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 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. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 41 | * @param valueLow the lower (less significant) 64 bits of the address. |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 42 | */ |
| 43 | public IPv6(long valueHigh, long valueLow) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 44 | this.valueHigh = valueHigh; |
| 45 | this.valueLow = valueLow; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 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) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 54 | // TODO: Implement it! |
| 55 | this.valueHigh = 0; |
| 56 | this.valueLow = 0; |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 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 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 65 | public long valueHigh() { |
| 66 | return valueHigh; |
| 67 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 68 | |
| 69 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 70 | * Set the value of the higher (more significant) 64 bits of the address. |
| 71 | * |
| 72 | * @param valueHigh the higher (more significant) 64 bits of the address. |
| 73 | */ |
| 74 | public void setValueHigh(long valueHigh) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 75 | this.valueHigh = valueHigh; |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 79 | * Get the value of the lower (less significant) 64 bits of the address. |
| 80 | * |
| 81 | * @return the value of the lower (less significant) 64 bits of the |
| 82 | * address. |
| 83 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 84 | public long valueLow() { |
| 85 | return valueLow; |
| 86 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 87 | |
| 88 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 89 | * Get the value of the lower (less significant) 64 bits of the address. |
| 90 | * |
| 91 | * @param valueLow the lower (less significant) 64 bits of the address. |
| 92 | */ |
| 93 | public void setValueLow(long valueLow) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 94 | this.valueLow = valueLow; |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 98 | * Set the value of the IPv6 address. |
| 99 | * |
| 100 | * @param valueHigh the higher (more significant) 64 bits of the address. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 101 | * @param valueLow the lower (less significant) 64 bits of the address. |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 102 | */ |
| 103 | public void setValue(long valueHigh, long valueLow) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 104 | this.valueHigh = valueHigh; |
| 105 | this.valueLow = valueLow; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Convert the IPv6 value to a ':' separated string. |
| 110 | * |
| 111 | * @return the IPv6 value as a ':' separated string. |
| 112 | */ |
| 113 | @Override |
| 114 | public String toString() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 115 | return HexString.toHexString(this.valueHigh) + ":" + |
| 116 | HexString.toHexString(this.valueLow); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 117 | } |
| 118 | } |