Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 2 | |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 3 | import org.openflow.util.HexString; |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 4 | import net.floodlightcontroller.util.serializers.DpidDeserializer; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 5 | import net.floodlightcontroller.util.serializers.DpidSerializer; |
| 6 | |
| 7 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 8 | import org.codehaus.jackson.map.annotate.JsonDeserialize; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 9 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
| 10 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 11 | /** |
| 12 | * The class representing a network switch DPID. |
| 13 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 14 | @JsonDeserialize(using=DpidDeserializer.class) |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 15 | @JsonSerialize(using=DpidSerializer.class) |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 16 | public 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 38 | * 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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 47 | * 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 Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 63 | * Convert the DPID value to a ':' separated hexadecimal string. |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 64 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 65 | * @return the DPID value as a ':' separated hexadecimal string. |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 66 | */ |
| 67 | @Override |
| 68 | public String toString() { |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 69 | return HexString.toHexString(this.value); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 70 | } |
| 71 | } |