blob: c3cf3aa2dc1c423cceb80a9d902d20dd7a6f8640 [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
HIGUCHI Yutaf086d8a2013-06-12 15:26:35 -07003import net.onrc.onos.ofcontroller.util.serializers.DpidDeserializer;
4import net.onrc.onos.ofcontroller.util.serializers.DpidSerializer;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08005
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -08006import org.codehaus.jackson.map.annotate.JsonDeserialize;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08007import org.codehaus.jackson.map.annotate.JsonSerialize;
HIGUCHI Yuta858c1ea2013-06-14 13:10:06 -07008import org.openflow.util.HexString;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08009
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080010/**
11 * The class representing a network switch DPID.
12 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080013@JsonDeserialize(using=DpidDeserializer.class)
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080014@JsonSerialize(using=DpidSerializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080015public class Dpid {
16 static public long UNKNOWN = 0;
17
18 private long value;
19
20 /**
21 * Default constructor.
22 */
23 public Dpid() {
24 this.value = Dpid.UNKNOWN;
25 }
26
27 /**
28 * Constructor from a long value.
29 *
30 * @param value the value to use.
31 */
32 public Dpid(long value) {
33 this.value = value;
34 }
35
36 /**
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080037 * Constructor from a string.
38 *
39 * @param value the value to use.
40 */
41 public Dpid(String value) {
42 this.value = HexString.toLong(value);
43 }
44
45 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080046 * Get the value of the DPID.
47 *
48 * @return the value of the DPID.
49 */
50 public long value() { return value; }
51
52 /**
53 * Set the value of the DPID.
54 *
55 * @param value the value to set.
56 */
57 public void setValue(long value) {
58 this.value = value;
59 }
60
61 /**
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080062 * Convert the DPID value to a ':' separated hexadecimal string.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080063 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080064 * @return the DPID value as a ':' separated hexadecimal string.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080065 */
66 @Override
67 public String toString() {
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080068 return HexString.toHexString(this.value);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080069 }
70}