blob: 38a86b58382efa28ac18f92f50599689e854c79d [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 */
Ray Milkey269ffb92014-04-03 14:43:30 -070013@JsonDeserialize(using = IPv6Deserializer.class)
14@JsonSerialize(using = IPv6Serializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080015public class IPv6 {
Ray Milkey269ffb92014-04-03 14:43:30 -070016 private long valueHigh; // The higher (more significant) 64 bits
17 private long valueLow; // The lower (less significant) 64 bits
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080018
19 /**
20 * Default constructor.
21 */
22 public IPv6() {
Ray Milkey269ffb92014-04-03 14:43:30 -070023 this.valueHigh = 0;
24 this.valueLow = 0;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080025 }
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) {
Ray Milkey269ffb92014-04-03 14:43:30 -070033 this.valueHigh = other.valueHigh;
34 this.valueLow = other.valueLow;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070035 }
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.
Ray Milkey269ffb92014-04-03 14:43:30 -070041 * @param valueLow the lower (less significant) 64 bits of the address.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080042 */
43 public IPv6(long valueHigh, long valueLow) {
Ray Milkey269ffb92014-04-03 14:43:30 -070044 this.valueHigh = valueHigh;
45 this.valueLow = valueLow;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080046 }
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) {
Ray Milkey269ffb92014-04-03 14:43:30 -070054 // TODO: Implement it!
55 this.valueHigh = 0;
56 this.valueLow = 0;
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080057 }
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 */
Ray Milkey269ffb92014-04-03 14:43:30 -070065 public long valueHigh() {
66 return valueHigh;
67 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080068
69 /**
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080070 * Set the value of the higher (more significant) 64 bits of the address.
71 *
72 * @param valueHigh the higher (more significant) 64 bits of the address.
73 */
74 public void setValueHigh(long valueHigh) {
Ray Milkey269ffb92014-04-03 14:43:30 -070075 this.valueHigh = valueHigh;
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080076 }
77
78 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080079 * Get the value of the lower (less significant) 64 bits of the address.
80 *
81 * @return the value of the lower (less significant) 64 bits of the
82 * address.
83 */
Ray Milkey269ffb92014-04-03 14:43:30 -070084 public long valueLow() {
85 return valueLow;
86 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080087
88 /**
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080089 * Get the value of the lower (less significant) 64 bits of the address.
90 *
91 * @param valueLow the lower (less significant) 64 bits of the address.
92 */
93 public void setValueLow(long valueLow) {
Ray Milkey269ffb92014-04-03 14:43:30 -070094 this.valueLow = valueLow;
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080095 }
96
97 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080098 * Set the value of the IPv6 address.
99 *
100 * @param valueHigh the higher (more significant) 64 bits of the address.
Ray Milkey269ffb92014-04-03 14:43:30 -0700101 * @param valueLow the lower (less significant) 64 bits of the address.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800102 */
103 public void setValue(long valueHigh, long valueLow) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700104 this.valueHigh = valueHigh;
105 this.valueLow = valueLow;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800106 }
107
108 /**
109 * Convert the IPv6 value to a ':' separated string.
110 *
111 * @return the IPv6 value as a ':' separated string.
112 */
113 @Override
114 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700115 return HexString.toHexString(this.valueHigh) + ":" +
116 HexString.toHexString(this.valueLow);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800117 }
118}