tom | 9ccd781 | 2014-08-25 22:43:19 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.of.controller.impl.util; |
alshabib | 1f44e8e | 2014-08-14 15:19:57 -0700 | [diff] [blame] | 2 | |
| 3 | import org.projectfloodlight.openflow.util.HexString; |
| 4 | |
| 5 | /** |
| 6 | * The class representing a network switch DPID. |
| 7 | * This class is immutable. |
| 8 | */ |
| 9 | public final class Dpid { |
| 10 | private static final long UNKNOWN = 0; |
| 11 | private final long value; |
| 12 | |
| 13 | /** |
| 14 | * Default constructor. |
| 15 | */ |
| 16 | public Dpid() { |
| 17 | this.value = Dpid.UNKNOWN; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Constructor from a long value. |
| 22 | * |
| 23 | * @param value the value to use. |
| 24 | */ |
| 25 | public Dpid(long value) { |
| 26 | this.value = value; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Constructor from a string. |
| 31 | * |
| 32 | * @param value the value to use. |
| 33 | */ |
| 34 | public Dpid(String value) { |
| 35 | this.value = HexString.toLong(value); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Get the value of the DPID. |
| 40 | * |
| 41 | * @return the value of the DPID. |
| 42 | */ |
| 43 | public long value() { |
| 44 | return value; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Convert the DPID value to a ':' separated hexadecimal string. |
| 49 | * |
| 50 | * @return the DPID value as a ':' separated hexadecimal string. |
| 51 | */ |
| 52 | @Override |
| 53 | public String toString() { |
| 54 | return HexString.toHexString(this.value); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public boolean equals(Object other) { |
| 59 | if (!(other instanceof Dpid)) { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | Dpid otherDpid = (Dpid) other; |
| 64 | |
| 65 | return value == otherDpid.value; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int hashCode() { |
| 70 | int hash = 17; |
| 71 | hash += 31 * hash + (int) (value ^ value >>> 32); |
| 72 | return hash; |
| 73 | } |
| 74 | } |