blob: 1648723092fbde60456356345a18fcf13584f9fd [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Jonathan Hart23701d12014-04-03 10:45:48 -07003import net.onrc.onos.core.util.serializers.IPv6Deserializer;
4import net.onrc.onos.core.util.serializers.IPv6Serializer;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08005
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -08006import org.codehaus.jackson.map.annotate.JsonDeserialize;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08007import org.codehaus.jackson.map.annotate.JsonSerialize;
HIGUCHI Yuta858c1ea2013-06-14 13:10:06 -07008import org.openflow.util.HexString;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08009
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080010/**
11 * The class representing an IPv6 address.
12 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080013@JsonDeserialize(using=IPv6Deserializer.class)
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080014@JsonSerialize(using=IPv6Serializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080015public 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 Radoslavov1bc2c472013-07-17 18:11:37 -070028 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080038 * 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 Radoslavov2013cbb2013-02-26 10:15:18 -080049 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080060 * 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 Radoslavov2013cbb2013-02-26 10:15:18 -080068 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080077 * 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 Radoslavov2013cbb2013-02-26 10:15:18 -080085 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080094 * 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 Radoslavovad008e02013-02-21 18:42:42 -0800111 return HexString.toHexString(this.valueHigh) + ":" +
112 HexString.toHexString(this.valueLow);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800113 }
114}