blob: 3f4f3502aa2ab7509ec601ec889959944291c49f [file] [log] [blame]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08001package net.floodlightcontroller.util;
2
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08003import net.floodlightcontroller.util.serializers.IPv4Serializer;
4
5import org.codehaus.jackson.annotate.JsonProperty;
6import org.codehaus.jackson.map.annotate.JsonSerialize;
7
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08008/**
9 * The class representing an IPv4 address.
10 */
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080011@JsonSerialize(using=IPv4Serializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080012public class IPv4 {
13 private int value;
14
15 /**
16 * Default constructor.
17 */
18 public IPv4() {
19 this.value = 0;
20 }
21
22 /**
23 * Constructor from an integer value.
24 *
25 * @param value the value to use.
26 */
27 public IPv4(int value) {
28 this.value = value;
29 }
30
31 /**
32 * Get the value of the IPv4 address.
33 *
34 * @return the value of the IPv4 address.
35 */
36 public int value() { return value; }
37
38 /**
39 * Set the value of the IPv4 address.
40 *
41 * @param value the value to set.
42 */
43 public void setValue(int value) {
44 this.value = value;
45 }
46
47 /**
48 * Convert the IPv4 value to a '.' separated string.
49 *
50 * @return the IPv4 value as a '.' separated string.
51 */
52 @Override
53 public String toString() {
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080054 return ((this.value >> 24) & 0xFF) + "." +
55 ((this.value >> 16) & 0xFF) + "." +
56 ((this.value >> 8) & 0xFF) + "." +
57 (this.value & 0xFF);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080058 }
59}