blob: dec84242ab8e8f3ce51c9b99345f8158e6d24e32 [file] [log] [blame]
tom9ccd7812014-08-25 22:43:19 -07001package org.onlab.onos.of.controller.impl.util;
tom0eb04ca2014-08-25 14:34:51 -07002
3import org.projectfloodlight.openflow.util.HexString;
4
5/**
6 * The class representing a network switch DPID.
7 * This class is immutable.
8 */
9public 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}