blob: 82d1db5cc039067d9f4810d20858f1c17297a54f [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08003import org.openflow.util.HexString;
HIGUCHI Yutaf086d8a2013-06-12 15:26:35 -07004
5import net.onrc.onos.ofcontroller.util.serializers.IPv6Deserializer;
6import net.onrc.onos.ofcontroller.util.serializers.IPv6Serializer;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08007
8import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -08009import org.codehaus.jackson.map.annotate.JsonDeserialize;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080010import org.codehaus.jackson.map.annotate.JsonSerialize;
11
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080012/**
13 * The class representing an IPv6 address.
14 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080015@JsonDeserialize(using=IPv6Deserializer.class)
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080016@JsonSerialize(using=IPv6Serializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080017public 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 Radoslavov2013cbb2013-02-26 10:15:18 -080041 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080052 * 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 Radoslavov2013cbb2013-02-26 10:15:18 -080060 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080069 * 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 Radoslavov2013cbb2013-02-26 10:15:18 -080077 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080086 * 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 Radoslavovad008e02013-02-21 18:42:42 -0800103 return HexString.toHexString(this.valueHigh) + ":" +
104 HexString.toHexString(this.valueLow);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800105 }
106}