Package com.tailf.ned

Class NedCliBaseTemplate


public class NedCliBaseTemplate extends NedCliBase
This class implements NED CLI template
  • Field Details

    • device_id

      public String device_id
    • connection

      public SSHConnection connection
    • session

      public CliSession session
    • ip

      public InetAddress ip
    • port

      public int port
    • proto

      public String proto
    • ruser

      public String ruser
    • pass

      public String pass
    • secpass

      public String secpass
    • trace

      public boolean trace
    • tracer

      public NedTracer tracer
    • connectTimeout

      public int connectTimeout
    • readTimeout

      public int readTimeout
    • writeTimeout

      public int writeTimeout
    • mux

      public NedMux mux
    • LOGGER

      public static org.apache.logging.log4j.Logger LOGGER
  • Constructor Details

    • NedCliBaseTemplate

      public NedCliBaseTemplate()
    • NedCliBaseTemplate

      public NedCliBaseTemplate(String device_id, InetAddress ip, int port, String proto, String ruser, String pass, String secpass, boolean trace, int connectTimeout, int readTimeout, int writeTimeout, NedMux mux, NedWorker worker)
  • Method Details

    • setupSSH

      public void setupSSH(NedWorker worker) throws Exception
      Throws:
      Exception
    • setupTelnet

      public void setupTelnet(NedWorker worker) throws Exception
      Throws:
      Exception
    • trace

      public void trace(NedWorker worker, String msg, String direction)
    • handshake

      public void handshake(NedWorker worker) throws Exception
      Throws:
      Exception
    • reconnect

      public void reconnect(NedWorker worker)
      Description copied from class: NedConnectionBase
      Used for resuming a connection found in the connection pool.
      Specified by:
      reconnect in class NedConnectionBase
      Parameters:
      worker - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, 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.
    • device_id

      public String device_id()
      Description copied from class: NedConnectionBase
      The device_id is originally provided by NCS to properly identify the device. It is the name used for the device by NCS in the list of devices.
      Specified by:
      device_id in class NedConnectionBase
    • type

      public String type()
      Description copied from class: NedConnectionBase
      The type is one of "cli" and "generic". This information is sent to NCS when the NedMux is started to let NCS know how to communicate with each device.
      Specified by:
      type in class NedConnectionBase
    • modules

      public String[] modules()
      Description copied from class: NedConnectionBase
      Which YANG modules are covered by the class instance. This information is defined by the setConnectionData() call and is sent to NCS after initiating a new connection, or when re-establishing a connection. The modules() method is not actually used.
      Specified by:
      modules in class NedConnectionBase
    • identity

      public String identity()
      Description copied from class: NedConnectionBase
      This should return the a unique (among registered NedConnection classes) identity. It will be used by NCS when creating new connections to control which of the registered NedConnection classes to use.
      Overrides:
      identity in class NedConnectionBase
    • applyConfig

      public void applyConfig(NedWorker worker, int cmd, String data) throws NedException, IOException, SSHSessionException, NedCliBaseTemplate.ApplyException
      Throws:
      NedException
      IOException
      SSHSessionException
      NedCliBaseTemplate.ApplyException
    • prepare

      public void prepare(NedWorker worker, String data) throws Exception
      Description copied from class: NedCliBase
      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)
      Specified by:
      prepare in class NedCliBase
      Parameters:
      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. 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 void prepareDry(NedWorker worker, String data) throws Exception
      Description copied from class: NedCliBase
      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.
      Specified by:
      prepareDry in class NedCliBase
      Parameters:
      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. 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 void abort(NedWorker worker, String data) throws Exception
      Description copied from class: NedCliBase
      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.
      Specified by:
      abort in class NedCliBase
      Parameters:
      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. 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 void revert(NedWorker worker, String data) throws Exception
      Description copied from class: NedCliBase
      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.
      Specified by:
      revert in class NedCliBase
      Parameters:
      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. 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
    • commit

      public void commit(NedWorker worker, int timeout) throws Exception
      Description copied from class: NedConnectionBase
      This indicates that the current set of operations should be committed to the running configuration. When completed the w.commitResponse() method should be invoked. Devices that does not support commit() should invoke the w.commitResponse() method without delay. On error invoke the w.error(NedCmd.COMMIT, Error, Reason) method.
      Specified by:
      commit in class NedConnectionBase
      Parameters:
      worker - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, 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.
      timeout - If the commit operation does not complete within 'timeout' seconds the operation should be aborted.
      Throws:
      Exception
    • persist

      public void persist(NedWorker worker) throws Exception
      Description copied from class: NedConnectionBase
      This method is invoked when the currently committed change set should be made permanent. This corresponds to copying the running configuration to the startup configuration, on a running/startup device, or issuing the confirming commit operation on a device that supports that. When completed the w.persistResponse() should be invoked. On error invoke the w.error(NedCmd.PERSIST,Error, Reason) method.
      Specified by:
      persist in class NedConnectionBase
      Parameters:
      worker - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, 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.
      Throws:
      Exception
    • close

      public void close(NedWorker worker) throws NedException, IOException
      Description copied from class: NedConnectionBase
      This method is invoked when the connection is terminated. It is not invoked when placing the connection in the connection pool. No response is required, but trace messages may be generated during the close down.
      Specified by:
      close in class NedConnectionBase
      Parameters:
      worker - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, 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.
      Throws:
      NedException
      IOException
    • close

      public void close()
      Description copied from class: NedConnectionBase
      This method is invoked when a connection close is forced and no NedWorker is involved. This typically occurs when a connection is removed from the connection pool. No response or trace messages can be sent during the operation.
      Specified by:
      close in class NedConnectionBase
    • isAlive

      public boolean isAlive()
      Overrides:
      isAlive in class NedConnectionBase
    • getTransId

      public void getTransId(NedWorker worker) throws Exception
      Description copied from class: NedConnectionBase
      When this method is invoked the NED should produce a transaction id that must be changed if any changes has been made to the configuration since the last time the transaction id was requested. The transaction id can either be requested from the system, or calculated by the callback, for example by calculating an MD5 checksum of the configuration text. The method should indicate its return status by invoking the method w.error() or w.getTransIdResponse() The method should be implemented if the NED claimed a NedWorker.TransactionIdMode which is not NONE in setConnectionData().
      Specified by:
      getTransId in class NedConnectionBase
      Parameters:
      worker - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, 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.
      Throws:
      Exception
    • show

      public void show(NedWorker worker, String toptag) throws Exception
      Description copied from class: NedCliBase
      Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.
      Specified by:
      show in class NedCliBase
      Parameters:
      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. 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
    • isConnection

      public boolean isConnection(String device_id, InetAddress ip, int port, String proto, String ruser, String pass, String secpass, String keydir, boolean trace, int connectTimeout, int readTimeout, int writeTimeout)
      Description copied from class: NedCliBase
      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.
      Specified by:
      isConnection in class NedCliBase
      Parameters:
      device_id - 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
    • command

      public void command(NedWorker worker, String cmdname, ConfXMLParam[] p) throws Exception
      Description copied from class: NedConnectionBase
      This is for any optional commands on the device that are not part of the yang files config data, but is modeled as tailf:actions or rpcs in the device yang files.
      Specified by:
      command in class NedConnectionBase
      Parameters:
      worker - The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, 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.
      cmdname - Name of the command (path to action?)
      Throws:
      Exception
    • newConnection

      public NedCliBase newConnection(String device_id, 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 worker)
      Description copied from class: NedCliBase
      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.
      Specified by:
      newConnection in class NedCliBase
      Parameters:
      device_id - 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
      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. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
      Returns:
      the connection instance
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • string_quote

      public String string_quote(String aText)
    • string_dequote

      public String string_dequote(String aText)