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; |
| 4 | import net.floodlightcontroller.util.serializers.DpidSerializer; |
| 5 | |
| 6 | import org.codehaus.jackson.annotate.JsonProperty; |
| 7 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
| 8 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 9 | /** |
| 10 | * The class representing a network switch DPID. |
| 11 | */ |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 12 | @JsonSerialize(using=DpidSerializer.class) |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 13 | public class Dpid { |
| 14 | static public long UNKNOWN = 0; |
| 15 | |
| 16 | private long value; |
| 17 | |
| 18 | /** |
| 19 | * Default constructor. |
| 20 | */ |
| 21 | public Dpid() { |
| 22 | this.value = Dpid.UNKNOWN; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Constructor from a long value. |
| 27 | * |
| 28 | * @param value the value to use. |
| 29 | */ |
| 30 | public Dpid(long value) { |
| 31 | this.value = value; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get the value of the DPID. |
| 36 | * |
| 37 | * @return the value of the DPID. |
| 38 | */ |
| 39 | public long value() { return value; } |
| 40 | |
| 41 | /** |
| 42 | * Set the value of the DPID. |
| 43 | * |
| 44 | * @param value the value to set. |
| 45 | */ |
| 46 | public void setValue(long value) { |
| 47 | this.value = value; |
| 48 | } |
| 49 | |
| 50 | /** |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 51 | * Convert the DPID value to a ':' separated hexadecimal string. |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 52 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 53 | * @return the DPID value as a ':' separated hexadecimal string. |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 54 | */ |
| 55 | @Override |
| 56 | public String toString() { |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 57 | return HexString.toHexString(this.value); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 58 | } |
| 59 | } |