Class AbstractNetconfSession

  • All Implemented Interfaces:
    NetconfSession
    Direct Known Subclasses:
    NetconfSessionAdapter

    public abstract class AbstractNetconfSession
    extends java.lang.Object
    implements NetconfSession
    Abstract netconf session implements methods common for different implementations of netconf session.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addDeviceOutputListener​(NetconfDeviceOutputEventListener listener)
      Add a listener to the underlying stream handler implementation.
      java.util.concurrent.CompletableFuture<java.lang.CharSequence> asyncGet()
      Retrieves running configuration and device state.
      java.util.concurrent.CompletableFuture<java.lang.CharSequence> asyncGetConfig​(DatastoreId datastore)
      Retrieves the specified configuration.
      protected boolean checkReply​(java.lang.String reply)
      Checks errors in reply from the session.
      boolean close()
      Closes the Netconf session with the device.
      boolean commit()
      Commits the candidate configuration the running configuration.
      boolean copyConfig​(java.lang.String netconfTargetConfig, java.lang.String newConfiguration)
      Copies the new configuration, an Url or a complete configuration xml tree to the target configuration.
      boolean copyConfig​(DatastoreId netconfTargetConfig, java.lang.String newConfiguration)
      Copies the new configuration, an Url or a complete configuration xml tree to the target configuration.
      boolean copyConfig​(DatastoreId destination, DatastoreId source)
      Copies the configuration between configuration datastores.
      boolean deleteConfig​(DatastoreId netconfTargetConfig)
      Deletes part of the specified configuration based on the filterSchema.
      java.lang.String doWrappedRpc​(java.lang.String request)
      Executes an synchronous RPC to the server and wrap the request in RPC header.
      boolean editConfig​(java.lang.String newConfiguration)
      Retrieves part of the specified configuration based on the filterSchema.
      boolean editConfig​(DatastoreId netconfTargetConfig, java.lang.String mode, java.lang.String newConfiguration)
      Retrieves part of the specified configuration based on the filterSchema.
      abstract void endSubscription()
      Ends subscription to the device's notifications.
      protected java.util.concurrent.CompletableFuture<java.lang.CharSequence> executeRpc​(java.lang.String rpcString)  
      java.lang.String get​(java.lang.String request)
      Retrieves the requested configuration, different from get-config.
      java.lang.String get​(java.lang.String filterSchema, java.lang.String withDefaultsMode)
      Retrieves the requested data.
      java.lang.String getConfig​(DatastoreId netconfTargetConfig)
      Retrieves the specified configuration.
      java.lang.String getConfig​(DatastoreId netconfTargetConfig, java.lang.String configurationFilterSchema)
      Retrieves part of the specified configuration based on the filterSchema.
      abstract java.util.Set<java.lang.String> getDeviceCapabilitiesSet()
      Gets the capabilities of the remote Netconf device associated to this session.
      abstract java.lang.String getSessionId()
      Gets the session ID of the Netconf session.
      boolean lock​(DatastoreId datastore)
      Locks the specified configuration.
      void removeDeviceOutputListener​(NetconfDeviceOutputEventListener listener)
      Remove a listener from the underlying stream handler implementation.
      abstract java.util.concurrent.CompletableFuture<java.lang.String> request​(java.lang.String request)
      Executes an asynchronous RPC to the server and obtains a future to be completed.
      abstract java.lang.String requestSync​(java.lang.String request)
      Executes an synchronous RPC to the server.
      abstract java.util.concurrent.CompletableFuture<java.lang.String> rpc​(java.lang.String request)
      Executes an asynchronous RPC request to the server and obtains a future for it's response.
      void startSubscription()
      Starts subscription to the device's notifications.
      abstract void startSubscription​(java.lang.String filterSchema)
      Starts subscription to the device's notifications.
      boolean unlock​(DatastoreId datastore)
      Unlocks the specified configuration.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractNetconfSession

        public AbstractNetconfSession()
    • Method Detail

      • request

        public abstract java.util.concurrent.CompletableFuture<java.lang.String> request​(java.lang.String request)
                                                                                  throws NetconfException
        Description copied from interface: NetconfSession
        Executes an asynchronous RPC to the server and obtains a future to be completed. The caller must ensure that the message-id in any request is unique for the session
        Specified by:
        request in interface NetconfSession
        Parameters:
        request - the XML containing the RPC for the server.
        Returns:
        Server response or ERROR
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • rpc

        public abstract java.util.concurrent.CompletableFuture<java.lang.String> rpc​(java.lang.String request)
                                                                              throws NetconfException
        Description copied from interface: NetconfSession
        Executes an asynchronous RPC request to the server and obtains a future for it's response.
        Specified by:
        rpc in interface NetconfSession
        Parameters:
        request - the XML containing the RPC request for the server.
        Returns:
        Server response or ERROR
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • executeRpc

        protected java.util.concurrent.CompletableFuture<java.lang.CharSequence> executeRpc​(java.lang.String rpcString)
                                                                                     throws NetconfException
        Throws:
        NetconfException
      • asyncGetConfig

        public java.util.concurrent.CompletableFuture<java.lang.CharSequence> asyncGetConfig​(DatastoreId datastore)
                                                                                      throws NetconfException
        Description copied from interface: NetconfSession
        Retrieves the specified configuration.
        Specified by:
        asyncGetConfig in interface NetconfSession
        Parameters:
        datastore - to retrieve configuration from
        Returns:
        specified configuration
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • asyncGet

        public java.util.concurrent.CompletableFuture<java.lang.CharSequence> asyncGet()
                                                                                throws NetconfException
        Description copied from interface: NetconfSession
        Retrieves running configuration and device state.
        Specified by:
        asyncGet in interface NetconfSession
        Returns:
        running configuration and device state
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • get

        public java.lang.String get​(java.lang.String request)
                             throws NetconfException
        Description copied from interface: NetconfSession
        Retrieves the requested configuration, different from get-config.
        Specified by:
        get in interface NetconfSession
        Parameters:
        request - the XML containing the request to the server.
        Returns:
        device running configuration
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • get

        public java.lang.String get​(java.lang.String filterSchema,
                                    java.lang.String withDefaultsMode)
                             throws NetconfException
        Description copied from interface: NetconfSession
        Retrieves the requested data.
        Specified by:
        get in interface NetconfSession
        Parameters:
        filterSchema - XML subtrees to include in the reply
        withDefaultsMode - with-defaults mode
        Returns:
        Server response
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • doWrappedRpc

        public java.lang.String doWrappedRpc​(java.lang.String request)
                                      throws NetconfException
        Description copied from interface: NetconfSession
        Executes an synchronous RPC to the server and wrap the request in RPC header.
        Specified by:
        doWrappedRpc in interface NetconfSession
        Parameters:
        request - the XML containing the request to the server.
        Returns:
        Server response or ERROR
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • requestSync

        public abstract java.lang.String requestSync​(java.lang.String request)
                                              throws NetconfException
        Description copied from interface: NetconfSession
        Executes an synchronous RPC to the server.
        Specified by:
        requestSync in interface NetconfSession
        Parameters:
        request - the XML containing the RPC for the server.
        Returns:
        Server response or ERROR
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • getConfig

        public java.lang.String getConfig​(DatastoreId netconfTargetConfig)
                                   throws NetconfException
        Description copied from interface: NetconfSession
        Retrieves the specified configuration.
        Specified by:
        getConfig in interface NetconfSession
        Parameters:
        netconfTargetConfig - the type of configuration to retrieve.
        Returns:
        specified configuration.
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • getConfig

        public java.lang.String getConfig​(DatastoreId netconfTargetConfig,
                                          java.lang.String configurationFilterSchema)
                                   throws NetconfException
        Description copied from interface: NetconfSession
        Retrieves part of the specified configuration based on the filterSchema.
        Specified by:
        getConfig in interface NetconfSession
        Parameters:
        netconfTargetConfig - the type of configuration to retrieve.
        configurationFilterSchema - XML schema to filter the configuration elements we are interested in
        Returns:
        device running configuration.
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • editConfig

        public boolean editConfig​(java.lang.String newConfiguration)
                           throws NetconfException
        Description copied from interface: NetconfSession
        Retrieves part of the specified configuration based on the filterSchema.
        Specified by:
        editConfig in interface NetconfSession
        Parameters:
        newConfiguration - configuration to set
        Returns:
        true if the configuration was edited correctly
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • editConfig

        public boolean editConfig​(DatastoreId netconfTargetConfig,
                                  java.lang.String mode,
                                  java.lang.String newConfiguration)
                           throws NetconfException
        Description copied from interface: NetconfSession
        Retrieves part of the specified configuration based on the filterSchema.
        Specified by:
        editConfig in interface NetconfSession
        Parameters:
        netconfTargetConfig - the targetConfiguration to change
        mode - default-operation mode
        newConfiguration - configuration to set
        Returns:
        true if the configuration was edited correctly
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • copyConfig

        public boolean copyConfig​(DatastoreId destination,
                                  DatastoreId source)
                           throws NetconfException
        Description copied from interface: NetconfSession
        Copies the configuration between configuration datastores.

        The target configuration can't be the running one

        Specified by:
        copyConfig in interface NetconfSession
        Parameters:
        destination - configuration datastore
        source - configuration datastore
        Returns:
        true if the configuration was copied correctly
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • copyConfig

        public boolean copyConfig​(DatastoreId netconfTargetConfig,
                                  java.lang.String newConfiguration)
                           throws NetconfException
        Description copied from interface: NetconfSession
        Copies the new configuration, an Url or a complete configuration xml tree to the target configuration. The target configuration can't be the running one
        Specified by:
        copyConfig in interface NetconfSession
        Parameters:
        netconfTargetConfig - the type of configuration to retrieve.
        newConfiguration - configuration XML to set or URL tag to the configuration
        Returns:
        true if the configuration was copied correctly
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • copyConfig

        public boolean copyConfig​(java.lang.String netconfTargetConfig,
                                  java.lang.String newConfiguration)
                           throws NetconfException
        Description copied from interface: NetconfSession
        Copies the new configuration, an Url or a complete configuration xml tree to the target configuration. The target configuration can't be the running one
        Specified by:
        copyConfig in interface NetconfSession
        Parameters:
        netconfTargetConfig - the type of configuration to retrieve.
        newConfiguration - configuration to set
        Returns:
        true if the configuration was copied correctly
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • deleteConfig

        public boolean deleteConfig​(DatastoreId netconfTargetConfig)
                             throws NetconfException
        Description copied from interface: NetconfSession
        Deletes part of the specified configuration based on the filterSchema.
        Specified by:
        deleteConfig in interface NetconfSession
        Parameters:
        netconfTargetConfig - the name of the configuration to delete
        Returns:
        true if the configuration was copied correctly
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • startSubscription

        public abstract void startSubscription​(java.lang.String filterSchema)
                                        throws NetconfException
        Description copied from interface: NetconfSession
        Starts subscription to the device's notifications.
        Specified by:
        startSubscription in interface NetconfSession
        Parameters:
        filterSchema - XML subtrees to indicate specific notification
        Throws:
        NetconfException - when there is a problem starting the subscription
      • lock

        public boolean lock​(DatastoreId datastore)
                     throws NetconfException
        Description copied from interface: NetconfSession
        Locks the specified configuration.
        Specified by:
        lock in interface NetconfSession
        Parameters:
        datastore - configuration datastore to be locked
        Returns:
        true if successful.
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • unlock

        public boolean unlock​(DatastoreId datastore)
                       throws NetconfException
        Description copied from interface: NetconfSession
        Unlocks the specified configuration.
        Specified by:
        unlock in interface NetconfSession
        Parameters:
        datastore - configuration datastore to be unlocked
        Returns:
        true if successful.
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • commit

        public boolean commit()
                       throws NetconfException
        Description copied from interface: NetconfSession
        Commits the candidate configuration the running configuration.
        Specified by:
        commit in interface NetconfSession
        Returns:
        true if successful.
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • close

        public boolean close()
                      throws NetconfException
        Description copied from interface: NetconfSession
        Closes the Netconf session with the device. the first time it tries gracefully, then kills it forcefully
        Specified by:
        close in interface NetconfSession
        Returns:
        true if closed
        Throws:
        NetconfException - when there is a problem in the communication process on the underlying connection
      • getSessionId

        public abstract java.lang.String getSessionId()
        Description copied from interface: NetconfSession
        Gets the session ID of the Netconf session.
        Specified by:
        getSessionId in interface NetconfSession
        Returns:
        Session ID as a string.
      • getDeviceCapabilitiesSet

        public abstract java.util.Set<java.lang.String> getDeviceCapabilitiesSet()
        Description copied from interface: NetconfSession
        Gets the capabilities of the remote Netconf device associated to this session.
        Specified by:
        getDeviceCapabilitiesSet in interface NetconfSession
        Returns:
        Network capabilities as strings in a Set.
      • checkReply

        @Beta
        protected boolean checkReply​(java.lang.String reply)
        Checks errors in reply from the session.
        Parameters:
        reply - reply string
        Returns:
        true if no error, else false