Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 2 | |
| 3 | import net.floodlightcontroller.util.IPv4; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 4 | import net.floodlightcontroller.util.serializers.IPv4NetSerializer; |
| 5 | |
| 6 | import org.codehaus.jackson.annotate.JsonProperty; |
| 7 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * The class representing an IPv4 network address. |
| 11 | */ |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 12 | @JsonSerialize(using=IPv4NetSerializer.class) |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 13 | public 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 Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 67 | return this.address.toString() + "/" + this.prefixLen; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 68 | } |
| 69 | } |