blob: ce8a4f6bafe682129874022aa7970e8d96af82a0 [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08003import org.openflow.util.HexString;
HIGUCHI Yutaf086d8a2013-06-12 15:26:35 -07004
5import net.onrc.onos.ofcontroller.util.serializers.DpidDeserializer;
6import net.onrc.onos.ofcontroller.util.serializers.DpidSerializer;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08007
8import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -08009import org.codehaus.jackson.map.annotate.JsonDeserialize;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080010import org.codehaus.jackson.map.annotate.JsonSerialize;
11
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080012/**
13 * The class representing a network switch DPID.
14 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080015@JsonDeserialize(using=DpidDeserializer.class)
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080016@JsonSerialize(using=DpidSerializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080017public class Dpid {
18 static public long UNKNOWN = 0;
19
20 private long value;
21
22 /**
23 * Default constructor.
24 */
25 public Dpid() {
26 this.value = Dpid.UNKNOWN;
27 }
28
29 /**
30 * Constructor from a long value.
31 *
32 * @param value the value to use.
33 */
34 public Dpid(long value) {
35 this.value = value;
36 }
37
38 /**
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080039 * Constructor from a string.
40 *
41 * @param value the value to use.
42 */
43 public Dpid(String value) {
44 this.value = HexString.toLong(value);
45 }
46
47 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080048 * Get the value of the DPID.
49 *
50 * @return the value of the DPID.
51 */
52 public long value() { return value; }
53
54 /**
55 * Set the value of the DPID.
56 *
57 * @param value the value to set.
58 */
59 public void setValue(long value) {
60 this.value = value;
61 }
62
63 /**
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080064 * Convert the DPID value to a ':' separated hexadecimal string.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080065 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080066 * @return the DPID value as a ':' separated hexadecimal string.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080067 */
68 @Override
69 public String toString() {
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080070 return HexString.toHexString(this.value);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080071 }
72}