NetconfRpcService should be extensible 58/110058/5
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 28 Jan 2024 03:50:14 +0000 (04:50 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 28 Jan 2024 13:50:26 +0000 (14:50 +0100)
We are capturing a good base contract, but the documentation contradicts
the actual implementation.

The difference is that the API says it supports RFC4741/6241, but in
reality we also support RFC6020 and (optionally) RFC5277/6470.

This patch turns to DOMExtensibleService to allow for a baseline service
which potentially has extensions.

Change-Id: I541b9f76c6eecbbf85f593b68cd0ade6c5c286e6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/api/NetconfRpcService.java

index 94be90bcbe67f99345da42a9c50c6a2af3236280..67b1e30f4eac58b9e88377c8a8be3989f61dff02 100644 (file)
@@ -9,19 +9,50 @@ package org.opendaylight.netconf.client.mdsal.api;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.dom.api.DOMExtensibleService;
 import org.opendaylight.mdsal.dom.api.DOMRpcException;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMService;
+import org.opendaylight.mdsal.dom.api.DOMServiceExtension;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.CancelCommit;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.CloseSession;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.Commit;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.CopyConfig;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.DeleteConfig;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.DiscardChanges;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditConfig;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.Get;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.GetConfig;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.KillSession;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.Lock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.Unlock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.Validate;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscription;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.GetSchema;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 
 /**
- * A {@link DOMService} capturing the ability to invoke RPCs which are defined in RFC4741 and in RFC6241.
+ * A {@link DOMService} capturing the ability to invoke NETCONF RPCs through
+ * {@link #invokeNetconf(QName, ContainerNode)}.
  */
-public interface NetconfRpcService extends DOMService {
+public interface NetconfRpcService extends DOMExtensibleService<NetconfRpcService, NetconfRpcService.Extension> {
     /**
-     * Invoke a base RFC4741/RFC6241 RPC, e.g. those in {@link YangConstants#NETCONF_NAMESPACE}.
+     * Invoke a well-known RPC. This method is guaranteed to support the following RPCs:
+     * <ul>
+     *   <li>{@link CloseSession}</li>
+     *   <li>{@link CopyConfig}</li>
+     *   <li>{@link DeleteConfig}</li>
+     *   <li>{@link EditConfig}</li>
+     *   <li>{@link Get}</li>
+     *   <li>{@link GetConfig}</li>
+     *   <li>{@link KillSession}</li>
+     *   <li>{@link Lock}</li>
+     *   <li>{@link Unlock}</li>
+     * </ul>
+     *
+     * <p>
+     * The support for other RPCs is advertized through {@link #getExtensions()}.
      *
      * @param type QName of the RPC to be invoked
      * @param input Input arguments, null if the RPC does not take any.
@@ -29,4 +60,75 @@ public interface NetconfRpcService extends DOMService {
      *         of {@link DOMRpcException} reporting a transport error.
      */
     @NonNull ListenableFuture<? extends DOMRpcResult> invokeNetconf(@NonNull QName type, @NonNull ContainerNode input);
+
+    /**
+     * Extensions to {@link NetconfRpcService} defining additional RPC availability.
+     */
+    // Note: This is not an interface on purpose, to make the set of extensions well-known
+    enum Extension implements DOMServiceExtension<NetconfRpcService, Extension> {
+        /**
+         * This device supports
+         * <a href="https://www.rfc-editor.org/rfc/rfc4741#section-8.3">Candidate Configuration Capability</a>.
+         * The following RPCs are supported:
+         * <ul>
+         *   <li>{@link Commit}</li>
+         *   <li>{@link DiscardChanges}</li>
+         * </ul>
+         */
+        CANDIDATE,
+        /**
+         * This device supports
+         * <a href="https://www.rfc-editor.org/rfc/rfc4741#section-8.4">Confirmed Commit Capability 1.0</a>.
+         * The following RPCs are supported:
+         * <ul>
+         *   <li>{@link Commit}</li>
+         *   <li>{@link DiscardChanges}</li>
+         * </ul>
+         */
+        CONFIRMED_COMMIT_1_0,
+        /**
+         * This device supports
+         * <a href="https://www.rfc-editor.org/rfc/rfc6241#section-8.4">Confirmed Commit Capability 1.1</a>.
+         * The following RPCs are supported:
+         * <ul>
+         *   <li>{@link CancelCommit}</li>
+         *   <li>{@link Commit}</li>
+         *   <li>{@link DiscardChanges}</li>
+         * </ul>
+         */
+        CONFIRMED_COMMIT_1_1,
+        /**
+         * This device supports <a href="https://www.rfc-editor.org/rfc/rfc6022">NETCONF Monitoring</a>. The following
+         * RPCs are supported:
+         * <ul>
+         *   <li>{@link GetSchema}</li>
+         * </ul>
+         */
+        MONITORING,
+        /**
+         * This device supports <a href="https://www.rfc-editor.org/rfc/rfc5277">Event Notifications</a>. The following
+         * RPCs are supported:
+         * <ul>
+         *   <li>{@link CreateSubscription}</li>
+         * </ul>
+         * {@link CreateSubscription} is supported.
+         */
+        NOTIFICATIONS,
+        /**
+         * This device supports <a href="https://www.rfc-editor.org/rfc/rfc4741#section-8.6">Validate Capability</a>.
+         * The following RPCs are supported:
+         * <ul>
+         *   <li>{@link Validate}</li>
+         * </ul>
+         */
+        VALIDATE_1_0,
+        /**
+         * This device supports <a href="https://www.rfc-editor.org/rfc/rfc6241#section-8.6">Validate Capability</a>.
+         * The following RPCs are supported:
+         * <ul>
+         *   <li>{@link Validate}</li>
+         * </ul>
+         */
+        VALIDATE_1_1;
+    }
 }