2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.api.capability;
10 import static java.util.Objects.requireNonNull;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.netconf.api.CapabilityURN;
17 * Enumeration of all simple
18 * <a href="https://www.iana.org/assignments/netconf-capability-urns/netconf-capability-urns.xhtml#netconf-capability-urns-1">
19 * NETCONF capabilities,</a>
20 * i.e. those which do not have any additional parameters.
22 public enum SimpleCapability implements Capability {
24 * The base NETCONF capability, as defined in
25 * <a href="https://www.rfc-editor.org/rfc/rfc4741.html#section-8.1">RFC4741, section 8.1</a>.
26 * @deprecated This capability identifies legacy NETCONF devices and has been superseded by {@link #BASE_1_1}, just
27 * as RFC6241 obsoletes RFC4741.
30 BASE(":base:1.0", CapabilityURN.BASE),
32 * The base NETCONF capability, as defined in
33 * <a href="https://www.rfc-editor.org/rfc/rfc6241.html#section-8.1">RFC6241, section 8.1</a>.
35 BASE_1_1(":base:1.1", CapabilityURN.BASE_1_1),
37 * The Candidate Configuration Capability, as defined in
38 * <a href="https://www.rfc-editor.org/rfc/rfc6241.html#section-8.3">RFC6241, section 8.3</a>.
40 CANDIDATE(":candidate", CapabilityURN.CANDIDATE),
42 * The Candidate Configuration Capability, as defined in
43 * <a href="https://www.rfc-editor.org/rfc/rfc4741.html#section-8.3">RFC4741, section 8.3</a>.
44 * @deprecated This capability is superseded by {@link #CONFIRMED_COMMIT_1_1}.
47 CONFIRMED_COMMIT(":confirmed-commit", CapabilityURN.CONFIRMED_COMMIT),
49 * The Rollback-on-Error Capability, as defined in
50 * <a href="https://www.rfc-editor.org/rfc/rfc6241.html#section-8.4">RFC6241, section 8.4</a>.
52 CONFIRMED_COMMIT_1_1(":confirmed-commit:1.1", CapabilityURN.CONFIRMED_COMMIT_1_1),
54 * The Interleave Capability, as defined in
55 * <a href="https://www.rfc-editor.org/rfc/rfc5277.html#section-6">RFC5277, section 6</a>.
57 INTERLEAVE(":interleave", CapabilityURN.INTERLEAVE),
59 * The Validate Capability, as defined in
60 * <a href="https://www.rfc-editor.org/rfc/rfc5277.html#section-3.1">RFC5277, section 3.1</a>.
62 NOTIFICATION(":notification", CapabilityURN.NOTIFICATION),
64 * The Partial Locking Capability, as defined in
65 * <a href="https://www.rfc-editor.org/rfc/rfc5717.html#section-2">RFC5715, section 2</a>.
67 PARTIAL_LOCK(":partial-lock", CapabilityURN.PARTIAL_LOCK),
69 * The Rollback-on-Error Capability, as defined in
70 * <a href="https://www.rfc-editor.org/rfc/rfc6241.html#section-8.5">RFC6241, section 8.5</a>.
72 ROLLBACK_ON_ERROR(":rollback-on-error", CapabilityURN.ROLLBACK_ON_ERROR),
74 * The Distinct Startup Capability, as defined in
75 * <a href="https://www.rfc-editor.org/rfc/rfc6241.html#section-8.7">RFC6241, section 8.7</a>.
77 STARTUP(":startup", CapabilityURN.STARTUP),
79 * The Time Capability, as defined in
80 * <a href="https://www.rfc-editor.org/rfc/rfc7758.html#section-4">RFC7758, section 4</a>.
82 TIME(":time:1.0", CapabilityURN.TIME),
84 * The URL Capability, as defined in
85 * <a href="https://www.rfc-editor.org/rfc/rfc6241.html#section-8.8">RFC6241, section 8.8</a>.
87 URL(":url", CapabilityURN.URL),
89 * The Validate Capability, as defined in
90 * <a href="https://www.rfc-editor.org/rfc/rfc4741.html#section-8.6">RFC4741, section 8.6</a>.
91 * @deprecated This capability is superseded by {@link #VALIDATE_1_1}.
94 VALIDATE(":validate", CapabilityURN.VALIDATE),
96 * The Validate Capability, as defined in
97 * <a href="https://www.rfc-editor.org/rfc/rfc6241.html#section-8.6">RFC6241, section 8.6</a>.
99 VALIDATE_1_1(":validate:1.1", CapabilityURN.VALIDATE_1_1),
101 * The XPath Capability, as defined in
102 * <a href="https://www.rfc-editor.org/rfc/rfc6241.html#section-8.9">RFC6241, section 8.9</a>.
104 XPATH(":xpath", CapabilityURN.XPATH),
106 * The YANG Module Library Capability, as defined in
107 * <a href="hhttps://www.rfc-editor.org/rfc/rfc7950.html#section-5.6.4">RFC7950, section 5.6.4</a> and further
108 * specified by <a href="https://www.rfc-editor.org/rfc/rfc7895">RFC7895</a>. Note this applies to NETCONF endpoints
109 * which DO NOT support Network Management Datastore Architecture as specified by
110 * <a href="https://www.rfc-editor.org/rfc/rfc8342">RFC8342</a>.
112 YANG_LIBRARY(":yang-library", CapabilityURN.YANG_LIBRARY),
114 * The YANG Library Capability, as defined in
115 * <a href="https://www.rfc-editor.org/rfc/rfc8526.html#section-2">RFC8526, section 2</a> and further specified
116 * by <a href="https://www.rfc-editor.org/rfc/rfc8525">RFC8525</a>. Note this applies to NETCONF endpoints
117 * which DO support Network Management Datastore Architecture as specified by
118 * <a href="https://www.rfc-editor.org/rfc/rfc8342">RFC8342</a>.
120 YANG_LIBRARY_1_1(":yang-library:1.1", CapabilityURN.YANG_LIBRARY_1_1),
122 * The With-defaults Capability, as defined in
123 * <a href="https://www.rfc-editor.org/rfc/rfc6243.html#section-4">RFC6243, section 4</a>.
125 WITH_DEFAULTS(":with-defaults", CapabilityURN.WITH_DEFAULTS),
127 * The With-defaults Capability, as augmented by
128 * <a href="https://www.rfc-editor.org/rfc/rfc8526#section-3.1.1.2">RFC8526, section 3.1.1.2</a>.
130 WITH_OPERATIONAL_DEFAULTS(":with-operational-defaults", CapabilityURN.WITH_OPERATIONAL_DEFAULTS),
132 * The Writable-Running Capability, as defined in
133 * <a href="https://www.rfc-editor.org/rfc/rfc6241.html#section-8.2">RFC6241, section 8.2</a>.
135 WRITABLE_RUNNING(":writable-running", CapabilityURN.WRITABLE_RUNNING);
137 private final @NonNull String capabilityName;
138 private final @NonNull String urn;
139 private final @NonNull URI uri;
141 SimpleCapability(final String capabilityName, final String urn) {
142 this.capabilityName = requireNonNull(capabilityName);
143 this.urn = requireNonNull(urn);
144 uri = URI.create(urn);
147 public @NonNull String capabilityName() {
148 return capabilityName;
152 public String urn() {
162 * Try to match a capability URN to a {@link SimpleCapability}.
164 * @param urn URN to match
165 * @return A {@link SimpleCapability}
166 * @throws IllegalArgumentException if {@code urn} is {@code null}
168 public static @NonNull SimpleCapability ofURN(final String urn) {
169 final var capability = forURN(urn);
170 if (capability == null) {
171 throw new IllegalArgumentException(urn + " does not match a known protocol capability");
177 * Match a capability URN to a {@link SimpleCapability}.
179 * @param urn URN to match
180 * @return A {@link SimpleCapability}, or {@code null} the URN does not match a known protocol capability
181 * @throws NullPointerException if {@code urn} is {@code null}
183 public static SimpleCapability forURN(final String urn) {
184 return switch (urn) {
185 case CapabilityURN.BASE -> BASE;
186 case CapabilityURN.BASE_1_1 -> BASE_1_1;
187 case CapabilityURN.CANDIDATE -> CANDIDATE;
188 case CapabilityURN.CONFIRMED_COMMIT -> CONFIRMED_COMMIT;
189 case CapabilityURN.CONFIRMED_COMMIT_1_1 -> CONFIRMED_COMMIT_1_1;
190 case CapabilityURN.INTERLEAVE -> INTERLEAVE;
191 case CapabilityURN.NOTIFICATION -> NOTIFICATION;
192 case CapabilityURN.PARTIAL_LOCK -> PARTIAL_LOCK;
193 case CapabilityURN.ROLLBACK_ON_ERROR -> ROLLBACK_ON_ERROR;
194 case CapabilityURN.STARTUP -> STARTUP;
195 case CapabilityURN.TIME -> TIME;
196 case CapabilityURN.URL -> URL;
197 case CapabilityURN.VALIDATE -> VALIDATE;
198 case CapabilityURN.VALIDATE_1_1 -> VALIDATE_1_1;
199 case CapabilityURN.WITH_DEFAULTS -> WITH_DEFAULTS;
200 case CapabilityURN.WITH_OPERATIONAL_DEFAULTS -> WITH_OPERATIONAL_DEFAULTS;
201 case CapabilityURN.WRITABLE_RUNNING -> WRITABLE_RUNNING;
202 case CapabilityURN.XPATH -> XPATH;
203 case CapabilityURN.YANG_LIBRARY -> YANG_LIBRARY;
204 case CapabilityURN.YANG_LIBRARY_1_1 -> YANG_LIBRARY_1_1;