blob: 2d28db8b5e27f1783298b141f33da714f6b73a9a [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
HIGUCHI Yutaf086d8a2013-06-12 15:26:35 -07003import net.onrc.onos.ofcontroller.util.serializers.IPv6Deserializer;
4import net.onrc.onos.ofcontroller.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 /**
28 * Constructor from integer values.
29 *
30 * @param valueHigh the higher (more significant) 64 bits of the address.
31 * @param valueLow the lower (less significant) 64 bits of the address.
32 */
33 public IPv6(long valueHigh, long valueLow) {
34 this.valueHigh = valueHigh;
35 this.valueLow = valueLow;
36 }
37
38 /**
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080039 * Constructor from a string.
40 *
41 * @param value the value to use.
42 */
43 public IPv6(String value) {
44 // TODO: Implement it!
45 this.valueHigh = 0;
46 this.valueLow = 0;
47 }
48
49 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080050 * Get the value of the higher (more significant) 64 bits of the address.
51 *
52 * @return the value of the higher (more significant) 64 bits of the
53 * address.
54 */
55 public long valueHigh() { return valueHigh; }
56
57 /**
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080058 * Set the value of the higher (more significant) 64 bits of the address.
59 *
60 * @param valueHigh the higher (more significant) 64 bits of the address.
61 */
62 public void setValueHigh(long valueHigh) {
63 this.valueHigh = valueHigh;
64 }
65
66 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080067 * Get the value of the lower (less significant) 64 bits of the address.
68 *
69 * @return the value of the lower (less significant) 64 bits of the
70 * address.
71 */
72 public long valueLow() { return valueLow; }
73
74 /**
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080075 * Get the value of the lower (less significant) 64 bits of the address.
76 *
77 * @param valueLow the lower (less significant) 64 bits of the address.
78 */
79 public void setValueLow(long valueLow) {
80 this.valueLow = valueLow;
81 }
82
83 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080084 * Set the value of the IPv6 address.
85 *
86 * @param valueHigh the higher (more significant) 64 bits of the address.
87 * @param valueLow the lower (less significant) 64 bits of the address.
88 */
89 public void setValue(long valueHigh, long valueLow) {
90 this.valueHigh = valueHigh;
91 this.valueLow = valueLow;
92 }
93
94 /**
95 * Convert the IPv6 value to a ':' separated string.
96 *
97 * @return the IPv6 value as a ':' separated string.
98 */
99 @Override
100 public String toString() {
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800101 return HexString.toHexString(this.valueHigh) + ":" +
102 HexString.toHexString(this.valueLow);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800103 }
104}