blob: 1942293a0c3488fbd60e4589876aab6c763e647f [file] [log] [blame]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08001package net.floodlightcontroller.util;
2
3import net.floodlightcontroller.util.IPv6;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08004import net.floodlightcontroller.util.serializers.IPv6NetSerializer;
5
6import org.codehaus.jackson.annotate.JsonProperty;
7import org.codehaus.jackson.map.annotate.JsonSerialize;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08008
9/**
10 * The class representing an IPv6 network address.
11 */
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080012@JsonSerialize(using=IPv6NetSerializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080013public class IPv6Net {
14 private IPv6 address; // The IPv6 address
15 private short prefixLen; // The prefix length
16
17 /**
18 * Default constructor.
19 */
20 public IPv6Net() {
21 this.prefixLen = 0;
22 }
23
24 /**
25 * Constructor for a given address and prefix length.
26 *
27 * @param address the address to use.
28 * @param prefixLen the prefix length to use.
29 */
30 public IPv6Net(IPv6 address, short prefixLen) {
31 this.address = address;
32 this.prefixLen = prefixLen;
33 }
34
35 /**
36 * Get the address value of the IPv6Net address.
37 *
38 * @return the address value of the IPv6Net address.
39 */
40 public IPv6 address() { return address; }
41
42 /**
43 * Get the prefix length value of the IPv6Net address.
44 *
45 * @return the prefix length value of the IPv6Net address.
46 */
47 public short prefixLen() { return prefixLen; }
48
49 /**
50 * Set the value of the IPv6Net address.
51 *
52 * @param address the address to use.
53 * @param prefixLen the prefix length to use.
54 */
55 public void setValue(IPv6 address, short prefixLen) {
56 this.address = address;
57 this.prefixLen = prefixLen;
58 }
59
60 /**
61 * Convert the IPv6Net value to an "address/prefixLen" string.
62 *
63 * @return the IPv6Net value as an "address/prefixLen" string.
64 */
65 @Override
66 public String toString() {
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080067 return this.address.toString() + "/" + this.prefixLen;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080068 }
69}