blob: afaecbea0af5a9bab359209608468e943faab96e [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/**
tomdb6c3f82014-10-01 21:30:17 -07008 * External identity of a {@link org.onlab.onos.net.provider.Provider} family.
9 * It also carriers two designations of external characteristics, the URI
10 * scheme and primary/ancillary indicator.
11 * <p/>
12 * The device URI scheme is used to determine applicability of a provider to
13 * operations on a specific device. The ancillary indicator serves to designate
14 * a provider as a primary or ancillary.
15 *
16 * A {@link org.onlab.onos.net.provider.ProviderRegistry} uses this designation
17 * to permit only one primary provider per device URI scheme. Multiple
18 * ancillary providers can register with the same device URI scheme however.
tom0eb04ca2014-08-25 14:34:51 -070019 */
20public class ProviderId {
21
tom7e02cda2014-09-18 12:05:46 -070022 private final String scheme;
tom0eb04ca2014-08-25 14:34:51 -070023 private final String id;
toma5368862014-10-01 12:35:48 -070024 private final boolean ancillary;
tom0eb04ca2014-08-25 14:34:51 -070025
tom64b7aac2014-08-26 00:18:21 -070026 /**
tomdb6c3f82014-10-01 21:30:17 -070027 * Creates a new primary provider identifier from the specified string.
tom64b7aac2014-08-26 00:18:21 -070028 * The providers are expected to follow the reverse DNS convention, e.g.
29 * {@code org.onlab.onos.provider.of.device}
30 *
tomdb6c3f82014-10-01 21:30:17 -070031 * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp"
32 * @param id string identifier
tom64b7aac2014-08-26 00:18:21 -070033 */
tom7e02cda2014-09-18 12:05:46 -070034 public ProviderId(String scheme, String id) {
toma5368862014-10-01 12:35:48 -070035 this(scheme, id, false);
36 }
37
38 /**
39 * Creates a new provider identifier from the specified string.
40 * The providers are expected to follow the reverse DNS convention, e.g.
41 * {@code org.onlab.onos.provider.of.device}
42 *
43 * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp"
44 * @param id string identifier
45 * @param ancillary ancillary provider indicator
46 */
47 public ProviderId(String scheme, String id, boolean ancillary) {
tom7e02cda2014-09-18 12:05:46 -070048 this.scheme = scheme;
tom0eb04ca2014-08-25 14:34:51 -070049 this.id = id;
toma5368862014-10-01 12:35:48 -070050 this.ancillary = ancillary;
tom0eb04ca2014-08-25 14:34:51 -070051 }
52
tom7e02cda2014-09-18 12:05:46 -070053 /**
54 * Returns the device URI scheme to which this provider is bound.
55 *
56 * @return device URI scheme
57 */
58 public String scheme() {
59 return scheme;
60 }
61
Yuta HIGUCHIc7052012014-09-22 19:11:00 -070062 /**
63 * Returns the device URI scheme specific id portion.
64 *
65 * @return id
66 */
67 public String id() {
68 return id;
69 }
70
tomdb6c3f82014-10-01 21:30:17 -070071 /**
72 * Indicates whether this identifier designates an ancillary providers.
73 *
74 * @return true if the provider is ancillary; false if primary
75 */
76 public boolean isAncillary() {
77 return ancillary;
78 }
79
tom0eb04ca2014-08-25 14:34:51 -070080 @Override
tom64b7aac2014-08-26 00:18:21 -070081 public int hashCode() {
tom7e02cda2014-09-18 12:05:46 -070082 return Objects.hash(scheme, id);
tom0eb04ca2014-08-25 14:34:51 -070083 }
84
85 @Override
tom64b7aac2014-08-26 00:18:21 -070086 public boolean equals(Object obj) {
87 if (this == obj) {
88 return true;
89 }
tomfc9a4ff2014-09-22 18:22:47 -070090 if (obj instanceof ProviderId) {
91 final ProviderId other = (ProviderId) obj;
92 return Objects.equals(this.scheme, other.scheme) &&
toma5368862014-10-01 12:35:48 -070093 Objects.equals(this.id, other.id) &&
94 this.ancillary == other.ancillary;
tom64b7aac2014-08-26 00:18:21 -070095 }
tomfc9a4ff2014-09-22 18:22:47 -070096 return false;
tom0eb04ca2014-08-25 14:34:51 -070097 }
98
99 @Override
100 public String toString() {
toma5368862014-10-01 12:35:48 -0700101 return toStringHelper(this).add("scheme", scheme).add("id", id)
102 .add("ancillary", ancillary).toString();
tom0eb04ca2014-08-25 14:34:51 -0700103 }
tom64b7aac2014-08-26 00:18:21 -0700104
tom0eb04ca2014-08-25 14:34:51 -0700105}