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