blob: 7d314e82461d19a9faf9cbb9b7d96f56ad39150e [file] [log] [blame]
tomc1a38d32014-08-25 23:01:32 -07001package org.onlab.onos.net.provider;
tom0eb04ca2014-08-25 14:34:51 -07002
tom64b7aac2014-08-26 00:18:21 -07003import java.util.Objects;
4
tomeadbb462014-09-07 16:10:19 -07005import static com.google.common.base.MoreObjects.toStringHelper;
tom64b7aac2014-08-26 00:18:21 -07006
tom0eb04ca2014-08-25 14:34:51 -07007/**
8 * Notion of provider identity.
9 */
10public class ProviderId {
11
tom7e02cda2014-09-18 12:05:46 -070012 private final String scheme;
tom0eb04ca2014-08-25 14:34:51 -070013 private final String id;
toma5368862014-10-01 12:35:48 -070014 private final boolean ancillary;
tom0eb04ca2014-08-25 14:34:51 -070015
tom64b7aac2014-08-26 00:18:21 -070016 /**
17 * Creates a new provider identifier from the specified string.
18 * The providers are expected to follow the reverse DNS convention, e.g.
19 * {@code org.onlab.onos.provider.of.device}
20 *
tom7e02cda2014-09-18 12:05:46 -070021 * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp"
22 * @param id string identifier
tom64b7aac2014-08-26 00:18:21 -070023 */
tom7e02cda2014-09-18 12:05:46 -070024 public ProviderId(String scheme, String id) {
toma5368862014-10-01 12:35:48 -070025 this(scheme, id, false);
26 }
27
28 /**
29 * Creates a new provider identifier from the specified string.
30 * The providers are expected to follow the reverse DNS convention, e.g.
31 * {@code org.onlab.onos.provider.of.device}
32 *
33 * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp"
34 * @param id string identifier
35 * @param ancillary ancillary provider indicator
36 */
37 public ProviderId(String scheme, String id, boolean ancillary) {
tom7e02cda2014-09-18 12:05:46 -070038 this.scheme = scheme;
tom0eb04ca2014-08-25 14:34:51 -070039 this.id = id;
toma5368862014-10-01 12:35:48 -070040 this.ancillary = ancillary;
tom0eb04ca2014-08-25 14:34:51 -070041 }
42
tom7e02cda2014-09-18 12:05:46 -070043 /**
44 * Returns the device URI scheme to which this provider is bound.
45 *
46 * @return device URI scheme
47 */
48 public String scheme() {
49 return scheme;
50 }
51
Yuta HIGUCHIc7052012014-09-22 19:11:00 -070052 /**
toma5368862014-10-01 12:35:48 -070053 * Indicates whether the provider id belongs to an ancillary provider.
54 *
55 * @return true for ancillary; false for primary provider
56 */
57 public boolean isAncillary() {
58 return ancillary;
59 }
60
61 /**
Yuta HIGUCHIc7052012014-09-22 19:11:00 -070062 * Returns the device URI scheme specific id portion.
63 *
64 * @return id
65 */
66 public String id() {
67 return id;
68 }
69
tom0eb04ca2014-08-25 14:34:51 -070070 @Override
tom64b7aac2014-08-26 00:18:21 -070071 public int hashCode() {
tom7e02cda2014-09-18 12:05:46 -070072 return Objects.hash(scheme, id);
tom0eb04ca2014-08-25 14:34:51 -070073 }
74
75 @Override
tom64b7aac2014-08-26 00:18:21 -070076 public boolean equals(Object obj) {
77 if (this == obj) {
78 return true;
79 }
tomfc9a4ff2014-09-22 18:22:47 -070080 if (obj instanceof ProviderId) {
81 final ProviderId other = (ProviderId) obj;
82 return Objects.equals(this.scheme, other.scheme) &&
toma5368862014-10-01 12:35:48 -070083 Objects.equals(this.id, other.id) &&
84 this.ancillary == other.ancillary;
tom64b7aac2014-08-26 00:18:21 -070085 }
tomfc9a4ff2014-09-22 18:22:47 -070086 return false;
tom0eb04ca2014-08-25 14:34:51 -070087 }
88
89 @Override
90 public String toString() {
toma5368862014-10-01 12:35:48 -070091 return toStringHelper(this).add("scheme", scheme).add("id", id)
92 .add("ancillary", ancillary).toString();
tom0eb04ca2014-08-25 14:34:51 -070093 }
tom64b7aac2014-08-26 00:18:21 -070094
tom0eb04ca2014-08-25 14:34:51 -070095}