blob: 5af6bea4d5f6cf9afd8582625766f29bfffc6ad0 [file] [log] [blame]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08001package net.floodlightcontroller.util;
2
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08003import org.openflow.util.HexString;
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -08004import net.floodlightcontroller.util.serializers.DpidDeserializer;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08005import net.floodlightcontroller.util.serializers.DpidSerializer;
6
7import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -08008import org.codehaus.jackson.map.annotate.JsonDeserialize;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08009import org.codehaus.jackson.map.annotate.JsonSerialize;
10
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080011/**
12 * The class representing a network switch DPID.
13 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080014@JsonDeserialize(using=DpidDeserializer.class)
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080015@JsonSerialize(using=DpidSerializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080016public class Dpid {
17 static public long UNKNOWN = 0;
18
19 private long value;
20
21 /**
22 * Default constructor.
23 */
24 public Dpid() {
25 this.value = Dpid.UNKNOWN;
26 }
27
28 /**
29 * Constructor from a long value.
30 *
31 * @param value the value to use.
32 */
33 public Dpid(long value) {
34 this.value = value;
35 }
36
37 /**
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080038 * Constructor from a string.
39 *
40 * @param value the value to use.
41 */
42 public Dpid(String value) {
43 this.value = HexString.toLong(value);
44 }
45
46 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080047 * Get the value of the DPID.
48 *
49 * @return the value of the DPID.
50 */
51 public long value() { return value; }
52
53 /**
54 * Set the value of the DPID.
55 *
56 * @param value the value to set.
57 */
58 public void setValue(long value) {
59 this.value = value;
60 }
61
62 /**
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080063 * Convert the DPID value to a ':' separated hexadecimal string.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080064 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080065 * @return the DPID value as a ':' separated hexadecimal string.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080066 */
67 @Override
68 public String toString() {
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080069 return HexString.toHexString(this.value);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080070 }
71}