Package com.tailf.ned

Class NedCliBase

Object
com.tailf.ned.NedConnectionBase
com.tailf.ned.NedCliBase
Direct Known Subclasses:
NedCliBaseTemplate

public abstract class NedCliBase extends NedConnectionBase
This class is used for connections between the NCS and CLI based NEDs. A NedCli instance must be combined with a YANG data model that models the data and CLI commands used for talking to the device.
  • Constructor Details

    • NedCliBase

      public NedCliBase()
  • Method Details

    • prepare

      public abstract void prepare(NedWorker w, String data) throws Exception
      Is invoked by NCS to take the configuration to a new state. The Ned may choose to apply the changes directly to the device, preferably to a candidate configuration, but if the device lacks candidate support it may choose to apply the changes directly to the running config (typically the case on IOS like boxes). If the configuration changes are later aborted, or reverted, the NCS will provide the necessary commands for restoring the configuration to its previous state. The device should invoke the w.prepareResponse() when the operation is completed. initialize (prepare transaction) / \ / uninitialize (undo preparations) v prepare (send data to device) / \ v v abort | commit(send confirmed commit (ios would do noop)) / \ v v revert | persist (send confirming commit)
      Parameters:
      w - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      data - is the CLI commands for transforming the configuration to a new state. The commands are generated using the YANG data model in combination with the tailf: extensions to guide the mapping.
      Throws:
      Exception
    • prepareDry

      public abstract void prepareDry(NedWorker w, String data) throws Exception
      Is invoked by NCS to tell the NED what actions it should take towards the device if it should do a prepare. The NED should invoke the method prepareDryResponse() when the operation is completed. If no changes needs to be done just answer prepareDryResponse(data) If an error is detected answer this through a call to error() in NedWorker w.
      Parameters:
      w - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      data - is the CLI commands for transforming the configuration to a new state. The commands are generated using the YANG data model in combination with the tailf: extensions to guide the mapping.
      Throws:
      Exception
    • abort

      public abstract void abort(NedWorker w, String data) throws Exception
      Is invoked by NCS to abort the configuration to the state before the previous prepare() invocation. The NCS has calculated the commands needed to reach that state from the current state. The instance may choose to use there commands, or use some other mechanism to reach the same state. When the operation is completed it should invoke the w.abortResponse() method in the NedWorker.
      Parameters:
      w - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      data - is the commands for taking the config back to the previous state. The commands are generated using the YANG data model in combination with the tailf: extensions to guide the mapping.
      Throws:
      Exception
    • revert

      public abstract void revert(NedWorker w, String data) throws Exception
      Is invoked by NCS to undo the changes introduced in the last commit operation (communicated to the NED in the prepare method invocation). The difference between abort() and revert() is that revert() is invoked after commit() (but before persist), whereas abort() is invoked before commit(). Once the configuration has been made persistent by persist() it can no longer be restored to any previous (potentially saved) state. When the revert operation has been completed the w.revertResponse() method should be called.
      Parameters:
      w - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      data - is the commands for taking the config back to the previous state.
      Throws:
      Exception
    • show

      public abstract void show(NedWorker w, String toptag) throws Exception
      Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.
      Parameters:
      w - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      toptag - is the top level tag indicating which part of the config should be extracted.
      Throws:
      Exception
    • showPartial

      @Deprecated public void showPartial(NedWorker w, String[] cmdpaths) throws Exception
      Deprecated.
      Use the method showPartial(NedWorker,ConfPath[],String[]) instead. Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.
      Parameters:
      w - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      cmdpaths - are cmd paths to filter the various parts of the configuration tree that should be extracted.
      Throws:
      Exception
    • showPartial

      public void showPartial(NedWorker w, ConfPath[] paths) throws Exception
      Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.
      Parameters:
      w - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      paths - are paths to filter the various parts of the configuration tree that should be extracted.
      Throws:
      Exception
    • showPartial

      public void showPartial(NedWorker w, ConfPath[] paths, String[] cmdpaths) throws Exception
      Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.
      Parameters:
      w - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      paths - are paths to filter the various parts of the configuration tree that should be extracted.
      cmdpaths - are cmd paths to filter the various parts of the configuration tree that should be extracted.
      Throws:
      Exception
    • showOffline

      public void showOffline(NedWorker w, String toptag, String data) throws Exception
      Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.
      Parameters:
      w - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      toptag - is the top level tag indicating which part of the config should be extracted.
      data - is the CLI commands in native format.
      Throws:
      Exception
    • isConnection

      public abstract boolean isConnection(String deviceId, InetAddress ip, int port, String proto, String ruser, String pass, String secpass, String keydir, boolean trace, int connectTimeout, int readTimeout, int writeTimeout)
      Used by the connection pool to find a matching connection. If the current connection is has the same parameters it should return true, otherwise false.
      Parameters:
      deviceId - name of device
      ip - address to connect to device
      port - port to connect to
      proto - ssh or telnet
      ruser - name of user to connect as
      pass - password to use when connecting
      secpass - secondary password to use when entering config mode, set to empty string if not configured in the authgroup
      trace - indicates if raw trace messages should be generated or not
      connectTimeout - in milliseconds
      readTimeout - in milliseconds
      writeTimeout - in milliseconds
    • newConnection

      public abstract NedCliBase newConnection(String deviceId, InetAddress ip, int port, String proto, String ruser, String pass, String secpass, String publicKeyDir, boolean trace, int connectTimeout, int readTimeout, int writeTimeout, NedMux mux, NedWorker w)
      Establish a new connection to a device and send response to NCS with information about the device. This information is set by using the setConnectionData() method. A new instance representing the new connection should be returned. That instance will then be used for further communication with the device. Different worker instances may be used for that communication and the instance cannot assume that the worker used in this invocation will be the same used for the invocations of the prepare, abort, revert, persist, show, etc methods.
      Parameters:
      deviceId - name of device
      ip - address to connect to device
      port - port to connect to
      proto - ssh or telnet
      ruser - name of user to connect as
      pass - password to use when connecting
      secpass - secondary password to use when entering config mode, set to empty string if not configured in the authgroup
      publicKeyDir - directory to read public keys. null if password is given
      trace - indicates if raw trace messages should be generated or not
      connectTimeout - in milliseconds
      readTimeout - in milliseconds
      writeTimeout - in milliseconds
      mux -
      w - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      Returns:
      the connection instance
    • initNoConnect

      public NedCliBase initNoConnect(String device_id, NedMux mux, NedWorker worker) throws NedWorker.NotEnoughDataException
      Make a new instance of Ned object without establishing a connection towards the device. The NED should use previously stored information about the device to initialize its state if needed or throw NedWorker.NotEnoughDataException. It should then send the information about the device using the setConnectionData() method. A new instance representing the new connection should be returned. That instance can only be used for invoking prepareDry() callback and not for actual communication with the device. close() callback will be invoked before destroying the NED instance, so the implementation of the close() callback should handle cleanup both for instances created with newConnection() and instanced created with initNoConnect()
      Parameters:
      device_id - name of device
      mux -
      worker - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages.
      Returns:
      the NED instance
      Throws:
      NedWorker.NotEnoughDataException