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