blob: eda4502b33e41fff3c298e82fe02cda9666fc4fe [file] [log] [blame]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08001package net.floodlightcontroller.util;
2
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08003import org.openflow.util.HexString;
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -08004import net.floodlightcontroller.util.serializers.IPv6Deserializer;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08005import net.floodlightcontroller.util.serializers.IPv6Serializer;
6
7import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -08008import org.codehaus.jackson.map.annotate.JsonDeserialize;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08009import org.codehaus.jackson.map.annotate.JsonSerialize;
10
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080011/**
12 * The class representing an IPv6 address.
13 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080014@JsonDeserialize(using=IPv6Deserializer.class)
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080015@JsonSerialize(using=IPv6Serializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080016public 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 Radoslavov2013cbb2013-02-26 10:15:18 -080040 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080051 * 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 Radoslavov2013cbb2013-02-26 10:15:18 -080059 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080068 * 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 Radoslavov2013cbb2013-02-26 10:15:18 -080076 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080085 * 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 Radoslavovad008e02013-02-21 18:42:42 -0800102 return HexString.toHexString(this.valueHigh) + ":" +
103 HexString.toHexString(this.valueLow);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800104 }
105}