blob: f64ccb86a7a7897187463edb003f76c7e61a74ba [file] [log] [blame]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08001package net.floodlightcontroller.util;
2
3import net.floodlightcontroller.util.IPv4;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08004import net.floodlightcontroller.util.serializers.IPv4NetSerializer;
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 IPv4 network address.
11 */
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080012@JsonSerialize(using=IPv4NetSerializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080013public class IPv4Net {
14 private IPv4 address; // The IPv4 address
15 private short prefixLen; // The prefix length
16
17 /**
18 * Default constructor.
19 */
20 public IPv4Net() {
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 IPv4Net(IPv4 address, short prefixLen) {
31 this.address = address;
32 this.prefixLen = prefixLen;
33 }
34
35 /**
36 * Get the address value of the IPv4Net address.
37 *
38 * @return the address value of the IPv4Net address.
39 */
40 public IPv4 address() { return address; }
41
42 /**
43 * Get the prefix length value of the IPv4Net address.
44 *
45 * @return the prefix length value of the IPv4Net address.
46 */
47 public short prefixLen() { return prefixLen; }
48
49 /**
50 * Set the value of the IPv4Net address.
51 *
52 * @param address the address to use.
53 * @param prefixLen the prefix length to use.
54 */
55 public void setValue(IPv4 address, short prefixLen) {
56 this.address = address;
57 this.prefixLen = prefixLen;
58 }
59
60 /**
61 * Convert the IPv4Net value to an "address/prefixLen" string.
62 *
63 * @return the IPv4Net 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}