blob: d4461c0d3ba4f1d7561bb01f1d331ad724472172 [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;
4import net.floodlightcontroller.util.serializers.IPv6Serializer;
5
6import org.codehaus.jackson.annotate.JsonProperty;
7import org.codehaus.jackson.map.annotate.JsonSerialize;
8
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08009/**
10 * The class representing an IPv6 address.
11 */
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080012@JsonSerialize(using=IPv6Serializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080013public class IPv6 {
14 private long valueHigh; // The higher (more significant) 64 bits
15 private long valueLow; // The lower (less significant) 64 bits
16
17 /**
18 * Default constructor.
19 */
20 public IPv6() {
21 this.valueHigh = 0;
22 this.valueLow = 0;
23 }
24
25 /**
26 * Constructor from integer values.
27 *
28 * @param valueHigh the higher (more significant) 64 bits of the address.
29 * @param valueLow the lower (less significant) 64 bits of the address.
30 */
31 public IPv6(long valueHigh, long valueLow) {
32 this.valueHigh = valueHigh;
33 this.valueLow = valueLow;
34 }
35
36 /**
37 * Get the value of the higher (more significant) 64 bits of the address.
38 *
39 * @return the value of the higher (more significant) 64 bits of the
40 * address.
41 */
42 public long valueHigh() { return valueHigh; }
43
44 /**
45 * Get the value of the lower (less significant) 64 bits of the address.
46 *
47 * @return the value of the lower (less significant) 64 bits of the
48 * address.
49 */
50 public long valueLow() { return valueLow; }
51
52 /**
53 * Set the value of the IPv6 address.
54 *
55 * @param valueHigh the higher (more significant) 64 bits of the address.
56 * @param valueLow the lower (less significant) 64 bits of the address.
57 */
58 public void setValue(long valueHigh, long valueLow) {
59 this.valueHigh = valueHigh;
60 this.valueLow = valueLow;
61 }
62
63 /**
64 * Convert the IPv6 value to a ':' separated string.
65 *
66 * @return the IPv6 value as a ':' separated string.
67 */
68 @Override
69 public String toString() {
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080070 return HexString.toHexString(this.valueHigh) + ":" +
71 HexString.toHexString(this.valueLow);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080072 }
73}