com.foxsmart.csu
Class CiscoRouter

java.lang.Object
  extended by com.foxsmart.csu.CiscoRouter

public class CiscoRouter
extends java.lang.Object

The CiscoRouter class represents a Cisco Router device and the underlying communication with the router.

This class should be used to obtain retrieve and update a router configuration. Note the default values for the "stop updates on config error", "rollback on config error", and "update NVRAM config" flags when making configuration updates.

Note that this class will not work if the router prompt or the router hostname are set to the empty string or a string with only spaces. (e.g. 'hostname " "' or 'prompt ""').


Field Summary
protected static java.lang.String ACCESS_DENIED
           
protected static char BREAK
           
protected static java.lang.String CONFIGURE_MEMORY
           
protected static java.lang.String CONFIGURE_TERMINAL
           
protected static java.lang.String CR
           
protected static char CR_CHAR
           
static int DEFAULT_NO_DATA_READ_DELAY
          The number of 1/10 second increments that must pass without getting data before we consider a new data read complete.
static int DEFAULT_PROTOCOL_TIMEOUT_SECONDS
          The default operation timeout in seconds.
protected  int defaultNoDataReadDelay
           
protected  java.lang.Integer defaultProtocolTimeout
           
protected static java.lang.String ENABLE_COMMAND
           
protected static java.lang.String END
           
protected static java.util.List<java.lang.String> errorMessages
           
static java.lang.String FOXSMART_PROXY_PASSWORD_KEY
           
static java.lang.String FOXSMART_PROXY_USERNAME_KEY
           
protected static java.lang.String HELP
           
protected  org.apache.commons.logging.Log log
           
protected static java.lang.String NO
           
protected static java.lang.String NO_PASSWORD_SET
           
protected static java.lang.String NO_TERM_LENGTH_COMMAND
           
protected static java.lang.String NO_TERM_WIDTH_COMMAND
           
protected static java.lang.String PASSWORD_PROMPT
           
static java.lang.String PROXY_HOST_KEY
           
static java.lang.String PROXY_PORT_KEY
           
static java.lang.String PROXY_SET_KEY
           
protected static java.lang.String SERVICE_PROMPT_CONFIG
           
protected static java.lang.String SET_CLOCK_COMMAND
           
protected static java.lang.String SHOW_CLOCK_COMMAND
           
protected static java.lang.String SHOW_RUN_CONFIG_COMMAND
           
protected static java.lang.String SHOW_VERSION_COMMAND
           
protected static java.lang.String UNRECOGNIZED_COMMAND
           
protected static java.lang.String USERNAME_PROMPT
           
protected static java.util.List<java.lang.String> warningMessages
           
protected static java.lang.String WRITE_MEMORY
           
 
Constructor Summary
CiscoRouter(java.lang.String hostname, java.lang.String username, java.lang.String password, java.lang.String enablePassword)
          Constructs a Cisco Router object.
 
Method Summary
protected  void checkAccess(boolean enableRequired)
          Checks that we are connected to the router and that we have the proper access to run a command.
protected  void checkForRecognizedCommand(java.lang.String command)
          Checks to see if the command is recognized.
protected  void connect()
          Makes a connection with the router and sets the active protocol handler.
protected  void ensureActiveProtocolNotPresent()
          Checks to ensure an active protocol handler is not present.
protected  void ensureActiveProtocolPresent()
          Checks to ensure an active protocol handler is present and is a supported protocol.
 java.lang.String expectPrompt(java.lang.String match, boolean includeMatch, java.lang.Integer timeout)
          Reads data from the device until the expected string is found.
 ProtocolHandler.Protocol getActiveProtocol()
          Gets the active protocol that is being used while connected to the router.
 ProtocolHandler getActiveProtocolHandler()
          Gets the currently active protocol handler.
 java.lang.String getEnablePassword()
          Gets the enable password.
 boolean getEnablePasswordUsed()
          Gets whether the enable password was used for authentication.
static java.util.List<java.lang.String> getErrorMessageList()
          Returns the list of error messages that don't begin with a "%" character.
static java.util.List<java.lang.String> getGlobalPackagesStatic()
          Gets the global list of configuration packages via a static convenience method.
 boolean getHasEnableAccess()
          Determines whether enable access is available when logged in to the router.
 java.lang.String getHostname()
          Gets the hostname of the router.
 java.lang.String getPassword()
          Gets the standard password.
 boolean getPasswordUsed()
          Gets whether the password was used for authentication.
 java.lang.String getPrompt()
          Gets the router prompt after the login is successful.
 java.util.List<ProtocolHandler> getProtocolHandlers()
          Gets the list of protocol handlers.
 boolean getRollbackOnConfigErrorFlag()
          Gets the "rollback on config error" flag.
 CiscoRouterConfig getRunningConfiguration()
          Gets the router running configuration as a CiscoRouterConfig object.
 java.lang.String getRunningConfigurationAsString()
          Gets the router running configuration as the original IOS string.
 boolean getStopUpdatesOnConfigErrorFlag()
          Gets the "stop updates on config error" flag.
 java.util.Calendar getTime()
          Gets the router date and time.
 Commands getUpdateConfiglet(CiscoRouterConfig ciscoRouterConfig)
          Gets the configlet commands that can be used to update a router configuration based on the passed in new router configuration.
 boolean getUpdateNvRamConfigFlag()
          Gets the "update NVRAM config" flag.
 java.lang.String getUsername()
          Gets the username of the router.
 boolean getUsernameUsed()
          Gets whether the username was used for authentication.
 java.lang.String getVersionInfo()
          Gets the router version information.
static java.util.List<java.lang.String> getWarningMessageList()
          Returns the list of warning messages that begin with a "%" character.
 void login()
          Logs into the router and establishes enable capabilities if an enable password is present.
 void logout()
          Logs out of the router.
protected  void sendCommand(java.lang.String command)
          Sends a command to the router.
protected  void sendCommand(java.lang.String command, boolean containsPassword)
          Sends a command to the router.
 java.lang.String sendCommandWithResults(java.lang.String command)
          Sends a command to the router and returns the results of the command being executed.
 java.lang.String sendCommandWithResults(java.lang.String command, boolean checkForRecognizedCommand)
          Sends a command to the router and returns the results of the command being executed.
protected  com.foxsmart.csu.PromptAndResponse sendConfigCommandWithResults(java.lang.String command, java.lang.String hostname)
          Sends a config command to the router and returns the results of the command being executed.
protected  void setActiveProtocolHandler(ProtocolHandler protocolHandler)
          Sets the active protocol handler.
 void setDefaultNoDataReadDelay(int delay)
          Modifies the default no data read delay in 1/10 seconds for all protocol handlers.
 void setDefaultProtocolTimeout(java.lang.Integer timeout)
          Modifies the default operation protocol timeout value for all protocol handlers.
static void setGlobalPackagesStatic(java.util.List<java.lang.String> globalPackages)
          Sets the global list of configuration packages via a static convenience method.
 void setProtocolHandlers(java.util.List<ProtocolHandler> protocolHandlers)
          Sets the list of protocol handlers to use when connecting to the router in order of preference.
 void setProtocolSupport(boolean useSsh, boolean useTelnet, boolean useHttp, ProtocolHandler.Protocol preferredProtocol)
          Sets the supported protocols for the router.
 void setRollbackOnConfigErrorFlag(boolean rollbackOnConfigErrorFlag)
          Sets the "rollback on config error" flag.
 void setStopUpdatesOnConfigErrorFlag(boolean stopUpdatesOnConfigErrorFlag)
          Sets the "stop updates on config error" flag.
 void setTime(java.util.Calendar calendar)
          Sets the router date and time in Coordinated Universal Time (UTC).
 void setUpdateNvRamConfigFlag(boolean updateNvRamConfigFlag)
          Sets the "update NVRAM config" flag.
protected  void unsupportedProtocolHandler()
          Throws a runtime exception indicating that the active protocol handler does not support the requested operation.
 ConfigUpdateResult writeConfiglet(Commands commands)
          Writes the specified commands to the router.
 ConfigUpdateResult writeConfiglet(java.lang.String configlet)
          Writes the specified configlet commands to the router.
 ConfigUpdateResult writeConfiguration(CiscoRouterConfig newRouterConfig)
          Writes an updated configuration to the router.
 ConfigUpdateResult writeConfigurationAsString(java.lang.String routerConfig)
          Writes an updated configuration as a full IOS configuration string to the router.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected org.apache.commons.logging.Log log

DEFAULT_PROTOCOL_TIMEOUT_SECONDS

public static final int DEFAULT_PROTOCOL_TIMEOUT_SECONDS
The default operation timeout in seconds.

See Also:
Constant Field Values

DEFAULT_NO_DATA_READ_DELAY

public static final int DEFAULT_NO_DATA_READ_DELAY
The number of 1/10 second increments that must pass without getting data before we consider a new data read complete.

See Also:
Constant Field Values

defaultProtocolTimeout

protected java.lang.Integer defaultProtocolTimeout

defaultNoDataReadDelay

protected int defaultNoDataReadDelay

CR

protected static final java.lang.String CR
See Also:
Constant Field Values

CR_CHAR

protected static final char CR_CHAR
See Also:
Constant Field Values

HELP

protected static final java.lang.String HELP
See Also:
Constant Field Values

BREAK

protected static final char BREAK
See Also:
Constant Field Values

USERNAME_PROMPT

protected static final java.lang.String USERNAME_PROMPT
See Also:
Constant Field Values

PASSWORD_PROMPT

protected static final java.lang.String PASSWORD_PROMPT
See Also:
Constant Field Values

NO_PASSWORD_SET

protected static final java.lang.String NO_PASSWORD_SET
See Also:
Constant Field Values

ACCESS_DENIED

protected static final java.lang.String ACCESS_DENIED
See Also:
Constant Field Values

UNRECOGNIZED_COMMAND

protected static final java.lang.String UNRECOGNIZED_COMMAND
See Also:
Constant Field Values

ENABLE_COMMAND

protected static final java.lang.String ENABLE_COMMAND
See Also:
Constant Field Values

NO_TERM_WIDTH_COMMAND

protected static final java.lang.String NO_TERM_WIDTH_COMMAND
See Also:
Constant Field Values

NO_TERM_LENGTH_COMMAND

protected static final java.lang.String NO_TERM_LENGTH_COMMAND
See Also:
Constant Field Values

SHOW_RUN_CONFIG_COMMAND

protected static final java.lang.String SHOW_RUN_CONFIG_COMMAND
See Also:
Constant Field Values

SHOW_VERSION_COMMAND

protected static final java.lang.String SHOW_VERSION_COMMAND
See Also:
Constant Field Values

SHOW_CLOCK_COMMAND

protected static final java.lang.String SHOW_CLOCK_COMMAND
See Also:
Constant Field Values

SET_CLOCK_COMMAND

protected static final java.lang.String SET_CLOCK_COMMAND
See Also:
Constant Field Values

CONFIGURE_TERMINAL

protected static final java.lang.String CONFIGURE_TERMINAL
See Also:
Constant Field Values

CONFIGURE_MEMORY

protected static final java.lang.String CONFIGURE_MEMORY
See Also:
Constant Field Values

WRITE_MEMORY

protected static final java.lang.String WRITE_MEMORY
See Also:
Constant Field Values

SERVICE_PROMPT_CONFIG

protected static final java.lang.String SERVICE_PROMPT_CONFIG
See Also:
Constant Field Values

END

protected static final java.lang.String END
See Also:
Constant Field Values

NO

protected static final java.lang.String NO
See Also:
Constant Field Values

FOXSMART_PROXY_USERNAME_KEY

public static final java.lang.String FOXSMART_PROXY_USERNAME_KEY
See Also:
Constant Field Values

FOXSMART_PROXY_PASSWORD_KEY

public static final java.lang.String FOXSMART_PROXY_PASSWORD_KEY
See Also:
Constant Field Values

PROXY_SET_KEY

public static final java.lang.String PROXY_SET_KEY
See Also:
Constant Field Values

PROXY_HOST_KEY

public static final java.lang.String PROXY_HOST_KEY
See Also:
Constant Field Values

PROXY_PORT_KEY

public static final java.lang.String PROXY_PORT_KEY
See Also:
Constant Field Values

errorMessages

protected static java.util.List<java.lang.String> errorMessages

warningMessages

protected static java.util.List<java.lang.String> warningMessages
Constructor Detail

CiscoRouter

public CiscoRouter(java.lang.String hostname,
                   java.lang.String username,
                   java.lang.String password,
                   java.lang.String enablePassword)
            throws java.lang.Exception
Constructs a Cisco Router object.

Parameters:
hostname - The hostname of the router. This parameter is required.
username - The username that is used to connect to the router. This parameter is required only when aaa new-model is used.
password - The standard password that is used to connect to the router. This parameter is optional when aaa new-model is used and the username has been configured to not require a password.
enablePassword - The enable password to gain extra permissions on the router. This paramter is optional. If an enable password is not provided, router commands that require this access will throw a security exception.
Throws:
java.lang.Exception - if any licensing problems are encountered.
Method Detail

getErrorMessageList

public static java.util.List<java.lang.String> getErrorMessageList()
Returns the list of error messages that don't begin with a "%" character. If any of these messages are received from the router, the config command will be considered an error. To customize which messages are considered errors, modify the contents of this list. Note that any response that starts with a "%" character is automatically considered an error unless it is excluded in the warning message list (see getWarningMessageList method). The returned message from the router need only start with one of these messages for it to be considered a match. Also, a case-insensitive search is performed.

Default contents:

"No such state machine name"

"Invalid encrypted password"

Returns:
The list of error messages.

getWarningMessageList

public static java.util.List<java.lang.String> getWarningMessageList()
Returns the list of warning messages that begin with a "%" character. Normally, any response that starts with a "%" character is considered an error. However, any messages defined in this list will be considered a warning instead. To customize which error messages will be considered warnings, modify the contents of this list. Note that each warning message added should start with a "%" character. The returned message from the router need only start with one of these messages for it to be considered a match. Also, a case-insensitive search is performed.

Default contents:

"% Not all config may be removed and may reappear after reactivating the sub-interface"

Returns:
The list of warning messages.

setProtocolSupport

public void setProtocolSupport(boolean useSsh,
                               boolean useTelnet,
                               boolean useHttp,
                               ProtocolHandler.Protocol preferredProtocol)
                        throws java.lang.Exception
Sets the supported protocols for the router. This can only be performed when not connected to the router.

Parameters:
useSsh - True if the SSH protocol should be used to connect to the router or false if not.
useTelnet - True if the Telnet protocol should be used to connect to the router or false if not.
useHttp - True if the HTTP protocol should be used to connect to the router or false if not.
preferredProtocol - Optionally specifies which protocol (SSH, Telnet, or HTTP) is the preferred protocol for this router. If null is specified, SSH will be the preferred protocol.
Throws:
java.lang.Exception - if a protocol

getProtocolHandlers

public java.util.List<ProtocolHandler> getProtocolHandlers()
Gets the list of protocol handlers.

Returns:
the protocol handlers.

setProtocolHandlers

public void setProtocolHandlers(java.util.List<ProtocolHandler> protocolHandlers)
Sets the list of protocol handlers to use when connecting to the router in order of preference.

Parameters:
protocolHandlers - the list of protocol handlers.

getActiveProtocol

public ProtocolHandler.Protocol getActiveProtocol()
Gets the active protocol that is being used while connected to the router. A runtime exception will be thrown if not connected to the router.

Returns:
the active protocol.

ensureActiveProtocolPresent

protected void ensureActiveProtocolPresent()
                                    throws java.lang.RuntimeException
Checks to ensure an active protocol handler is present and is a supported protocol. An active protocol handler is assigned once a successful login to the router is performed.

Throws:
java.lang.RuntimeException - if an active protocol handler is not present.

ensureActiveProtocolNotPresent

protected void ensureActiveProtocolNotPresent()
                                       throws java.lang.RuntimeException
Checks to ensure an active protocol handler is not present. An active protocol handler is unassigned once we are disconnected from the router.

Throws:
java.lang.RuntimeException - if an active protocol handler is present.

setDefaultProtocolTimeout

public void setDefaultProtocolTimeout(java.lang.Integer timeout)
Modifies the default operation protocol timeout value for all protocol handlers. This can only be done when not connected to the router.

Parameters:
timeout - The default timeout value in seconds to wait for the data to be returned. If null is passed, no timeout will be used. Beware that if an expected match string is not found or if the device doesn't respond, the expect method will not return.

setDefaultNoDataReadDelay

public void setDefaultNoDataReadDelay(int delay)
Modifies the default no data read delay in 1/10 seconds for all protocol handlers. The "no data read delay" is the amount of time that the protocol waits when receiving no data that a data read is considered complete. This can only be done when not connected to the router.

Parameters:
delay - The default no data read delay.

getActiveProtocolHandler

public ProtocolHandler getActiveProtocolHandler()
Gets the currently active protocol handler. The active protocol handler is the one that gets assigned once a connection is made with the router via the logon method. Null is returned if no connection has been made to the router.

Returns:
the active protocol handler.

setActiveProtocolHandler

protected void setActiveProtocolHandler(ProtocolHandler protocolHandler)
Sets the active protocol handler.

Parameters:
protocolHandler - the active protocol handler.

connect

protected void connect()
                throws java.lang.Exception
Makes a connection with the router and sets the active protocol handler.

Throws:
java.net.UnknownHostException - If the hostname cannot be resolved.
java.net.ConnectException - if a connection couldn't be established with the destination device.
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out while waiting for data from the router.
AuthenticationFailedException - when the username and/or password specified did not provide access to the router.
java.lang.Exception - if any other unexpected error occurs.

login

public void login()
           throws java.lang.Exception
Logs into the router and establishes enable capabilities if an enable password is present. If a connection is already made to the router, it will be closed before the new connection is made. Once the router is logged in, it is up to the caller to ensure the logout method is called to close connections and ensure any external processes are exited properly.

Throws:
java.net.UnknownHostException - If the hostname cannot be resolved.
java.net.ConnectException - if a connection couldn't be established with the destination device.
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out while waiting for data from the router.
AuthenticationFailedException - when the username and/or password specified did not provide access to the router.
InvalidEnablePasswordException - when the enable password did not provide enable access.
java.lang.Exception - if any other unexpected error occurs.

logout

public void logout()
            throws java.io.IOException
Logs out of the router. This method does nothing if a connection doesn't currently exist to the router.

Throws:
java.io.IOException - if an I/O error occurs when closing the socket to the router.

getUsernameUsed

public boolean getUsernameUsed()
Gets whether the username was used for authentication.

Returns:
True if the username was used or false if not.

getPasswordUsed

public boolean getPasswordUsed()
Gets whether the password was used for authentication.

Returns:
True if the password was used or false if not.

getEnablePasswordUsed

public boolean getEnablePasswordUsed()
Gets whether the enable password was used for authentication.

Returns:
True if the enable password was used or false if not.

getRunningConfiguration

public CiscoRouterConfig getRunningConfiguration()
                                          throws java.lang.Exception
Gets the router running configuration as a CiscoRouterConfig object. Requires enable access.

Returns:
The router configuration
Throws:
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out while waiting for data from the router.
EnablerAccessRequiredException - if enabler access has not been obtained. The getHasEnableAccess method can be used to determine if enabler access is currently present.
InvalidConfigurationException - if the IOS configuration can not be parsed for any reason.
java.lang.Exception - if any other unexpected error occurs.

getRunningConfigurationAsString

public java.lang.String getRunningConfigurationAsString()
                                                 throws java.lang.Exception
Gets the router running configuration as the original IOS string. Requires enable access.

Returns:
The router configuration as an IOS string.
Throws:
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out while waiting for data from the router.
java.lang.Exception - if any other unexpected error occurs.

writeConfiguration

public ConfigUpdateResult writeConfiguration(CiscoRouterConfig newRouterConfig)
                                      throws java.lang.Exception
Writes an updated configuration to the router. Requires enable access.

Parameters:
newRouterConfig - The new target router configuration.
Returns:
A ConfigUpdateResult object which provides the details of the update.
Throws:
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out while waiting for data from the router.
EnablerAccessRequiredException - if enabler access has not been obtained. The getHasEnableAccess method can be used to determine if enabler access is currently present.
InvalidConfigurationException - if the router configuration is invalid for any reason.
java.lang.Exception - if any other unexpected error occurs.

writeConfigurationAsString

public ConfigUpdateResult writeConfigurationAsString(java.lang.String routerConfig)
                                              throws java.lang.Exception
Writes an updated configuration as a full IOS configuration string to the router. WARNING: the passed in configuration string must be a FULL configuration (i.e. not a configlet) since any supported parts of the router configuration that are not part of the passed in configuration string will be deleted. Requires enable access.

Parameters:
routerConfig - The new target router configuration as a complete IOS string.
Returns:
A ConfigUpdateResult object which provides the details of the update.
Throws:
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out while waiting for data from the router.
EnablerAccessRequiredException - if enabler access has not been obtained. The getHasEnableAccess method can be used to determine if enabler access is currently present.
InvalidConfigurationException - if the router configuration is invalid for any reason.
java.lang.Exception - if any other unexpected error occurs.

getUpdateConfiglet

public Commands getUpdateConfiglet(CiscoRouterConfig ciscoRouterConfig)
                            throws java.lang.Exception
Gets the configlet commands that can be used to update a router configuration based on the passed in new router configuration. To generate the string representation of the configlet, call Command.getConfiglet(commands). Requires enable access.

Parameters:
ciscoRouterConfig - The new target router configuration.
Returns:
The update configlet as a list of Commands.
Throws:
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out while waiting for data from the router.
EnablerAccessRequiredException - if enabler access has not been obtained. The getHasEnableAccess method can be used to determine if enabler access is currently present.
InvalidConfigurationException - if the router configuration is invalid for any reason.
java.lang.Exception - if any other unexpected error occurs.

writeConfiglet

public ConfigUpdateResult writeConfiglet(java.lang.String configlet)
                                  throws java.lang.Exception
Writes the specified configlet commands to the router. Note that no syntactical or logic checking is performed on the configlet (i.e. it is simply sent as is). This method only supports single line commands (i.e. each command is on its own line). If you wish to include multi-line commands (e.g. banner), then use the writeConfiglet method that takes a list of Commands. Note that this method will not perform a rollback if any errors occur during the writing of the configlet. If you require rollback functionality, use the writeConfiguration(CiscoRouterConfig newRouterConfig) method.

Requires enable access.

Parameters:
configlet - The configlet to write to the router.
Returns:
A ConfigUpdateResult object which provides the details of the update.
Throws:
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out reading or writing data from/to the router.
EnablerAccessRequiredException - if enabler access has not been obtained. The getHasEnableAccess method can be used to determine if enabler access is currently present.
InvalidConfigurationException - if the router configuration is invalid for any reason.
java.lang.Exception - if any other unexpected error occurs.

writeConfiglet

public ConfigUpdateResult writeConfiglet(Commands commands)
                                  throws java.lang.Exception
Writes the specified commands to the router. Note that no syntactical or logic checking is performed on the configlet commands (i.e. they are simply sent as is). Requires enable access. Note that this method will not perform a rollback if any errors occur during the writing of the configlet. If you require rollback functionality, use the writeConfiguration(CiscoRouterConfig newRouterConfig) method.

Parameters:
commands - The commands to send to the router.
Returns:
A ConfigUpdateResult object which provides the details of the update.
Throws:
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out reading or writing data from/to the router.
EnablerAccessRequiredException - if enabler access has not been obtained. The getHasEnableAccess method can be used to determine if enabler access is currently present.
InvalidConfigurationException - if the router configuration is invalid for any reason.
java.lang.Exception - if any other unexpected error occurs.

getVersionInfo

public java.lang.String getVersionInfo()
                                throws java.lang.Exception
Gets the router version information. Does not require enable access.

Returns:
The router version information
Throws:
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out while waiting for data from the router.
java.lang.Exception - if any other unexpected error occurs.

getTime

public java.util.Calendar getTime()
                           throws java.lang.Exception
Gets the router date and time. Does not require enable access.

Returns:
The date and time of the router
Throws:
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out while waiting for data from the router.
java.lang.Exception - if any other unexpected error occurs.

setTime

public void setTime(java.util.Calendar calendar)
             throws java.lang.Exception
Sets the router date and time in Coordinated Universal Time (UTC). Requires enable access.

Parameters:
calendar - The new date/time to set
Throws:
java.io.IOException - If the socket could not be opened or there was a problem communicating with the router.
ThreadTimeoutException - if we timed out while waiting for data from the router.
java.lang.Exception - if any other unexpected error occurs.

getPrompt

public java.lang.String getPrompt()
Gets the router prompt after the login is successful. The prompt will be based on the level of access obtained on the router. Typically, the prompt will be the router hostname followed by a '>' symbol for standard access or a '#' symbol for enable access. However, the prompt may be specially configured to anything based on the router configuration.

Returns:
the prompt

checkAccess

protected void checkAccess(boolean enableRequired)
                    throws java.io.IOException,
                           EnablerAccessRequiredException
Checks that we are connected to the router and that we have the proper access to run a command.

Parameters:
enableRequired - If true, enable access is required to run the command. Otherwise, only normal access is required.
Throws:
java.io.IOException - if we are not connected to the router.
EnablerAccessRequiredException - if enabler access is required, but not established.

getHasEnableAccess

public boolean getHasEnableAccess()
Determines whether enable access is available when logged in to the router.

Returns:
True if enable access is available or false if not.

sendCommand

protected void sendCommand(java.lang.String command)
                    throws java.lang.Exception
Sends a command to the router. This method functions the same as calling the write method with the exception that a carriage return is appended. This method is the same as sendCommand(command, false).

Parameters:
command - The command to send to the router.
Throws:
java.lang.Exception - if there was a problem running the command.

sendCommand

protected void sendCommand(java.lang.String command,
                           boolean containsPassword)
                    throws java.lang.Exception
Sends a command to the router. This method functions the same as calling the write method with the exception that a carriage return is appended.

Parameters:
command - The command to send to the router.
containsPassword - true if the command contains a password or false if not. Send true to cause the password to only be logged in "trace" mode.
Throws:
java.lang.Exception - if there was a problem running the command.

sendCommandWithResults

public java.lang.String sendCommandWithResults(java.lang.String command)
                                        throws java.lang.Exception
Sends a command to the router and returns the results of the command being executed. This is the same as calling sendCommandWithResults(commmand, true).

Parameters:
command - The command to send to the router.
Returns:
the command results.
Throws:
ThreadTimeoutException - if we timed out while waiting for data from the router.
java.io.IOException - if there was a problem running the command.
UnrecognizedCommandException - if the command is not recognized by the router. This can be because the command is invalid or because the logged in user does not have the appropriate access.
java.lang.Exception - if the returned data buffer contains unexpected data present or if any other unknown error was encountered.

sendCommandWithResults

public java.lang.String sendCommandWithResults(java.lang.String command,
                                               boolean checkForRecognizedCommand)
                                        throws java.lang.Exception
Sends a command to the router and returns the results of the command being executed.

Parameters:
command - The command to send to the router.
checkForRecognizedCommand - If true, the command to be issued will be checked to see if it is recognized. Otherwise, the command will be sent as is without being checked first.
Returns:
the command results.
Throws:
ThreadTimeoutException - if we timed out while waiting for data from the router.
java.io.IOException - if there was a problem running the command.
UnrecognizedCommandException - if the command is not recognized by the router. This can be because the command is invalid or because the logged in user does not have the appropriate access.
java.lang.Exception - if the returned data buffer contains unexpected data present or if any other unknown error was encountered.

checkForRecognizedCommand

protected void checkForRecognizedCommand(java.lang.String command)
                                  throws java.lang.Exception
Checks to see if the command is recognized. If the command contains any carriage returns (i.e. two commands are really present in the command), then skip the check since the first carriage return would actually execute the command.

Parameters:
command - the command to check.
Throws:
UnrecognizedCommandException - if the command is not recognized by the router. This can be because the command is invalid or because the logged in user does not have the appropriate access.
ThreadTimeoutException - if the expected string was not found within the passed in timeout period.
java.io.IOException - if there was an error reading data from the device or sending data to the device.
java.lang.Exception - if any other unexpected error occurs.

sendConfigCommandWithResults

protected com.foxsmart.csu.PromptAndResponse sendConfigCommandWithResults(java.lang.String command,
                                                                          java.lang.String hostname)
                                                                   throws java.lang.Exception
Sends a config command to the router and returns the results of the command being executed.

Parameters:
command - The command to send to the router.
hostname - The hostname of the router.
Returns:
The results of the command and prompt. The response to the command is in the response portion of the PromptAndResponse object while the prompt is in the command portion.
Throws:
ThreadTimeoutException - if we timed out while waiting for data from the router.
java.lang.Exception - if the returned data buffer contains unexpected data present or if any other unknown error was encountered.
java.io.IOException - if there was a problem running the command.

expectPrompt

public java.lang.String expectPrompt(java.lang.String match,
                                     boolean includeMatch,
                                     java.lang.Integer timeout)
                              throws java.lang.Exception
Reads data from the device until the expected string is found. Once the expected string is found, the data buffer up to the point where the string was found is returned.

Parameters:
match - The string to search for.
includeMatch - If true, the match string is returned in the resulting data string. If false, the match string is not returned as part of the resultant string.
timeout - The timeout value in seconds to wait for the data to be returned. If null is passed, no timeout will be used. Beware that if the expected match string is not found or if the device doesn't respond, this method will not return.
Returns:
the data that was read.
Throws:
ThreadTimeoutException - if the expected string was not found within the passed in timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.

unsupportedProtocolHandler

protected void unsupportedProtocolHandler()
                                   throws java.lang.RuntimeException
Throws a runtime exception indicating that the active protocol handler does not support the requested operation.

Throws:
java.lang.RuntimeException - always.

getHostname

public java.lang.String getHostname()
Gets the hostname of the router.

Returns:
the hostname

getUsername

public java.lang.String getUsername()
Gets the username of the router.

Returns:
the username

getPassword

public java.lang.String getPassword()
Gets the standard password.

Returns:
the standard password.

getEnablePassword

public java.lang.String getEnablePassword()
Gets the enable password.

Returns:
the enable password.

getGlobalPackagesStatic

public static java.util.List<java.lang.String> getGlobalPackagesStatic()
Gets the global list of configuration packages via a static convenience method.

Returns:
the global list of packages.

setGlobalPackagesStatic

public static void setGlobalPackagesStatic(java.util.List<java.lang.String> globalPackages)
Sets the global list of configuration packages via a static convenience method. This list of Java packages will be used when instantiating CiscoRouterConfigComponents within the CiscoRouterConfig hierarchy. When instantiating classes, the global packages will be tried first followed by any component specific packages.

Parameters:
globalPackages - the global list of packages.

setStopUpdatesOnConfigErrorFlag

public void setStopUpdatesOnConfigErrorFlag(boolean stopUpdatesOnConfigErrorFlag)
Sets the "stop updates on config error" flag.

Parameters:
stopUpdatesOnConfigErrorFlag - The "stop updates on config error" flag.

getStopUpdatesOnConfigErrorFlag

public boolean getStopUpdatesOnConfigErrorFlag()
Gets the "stop updates on config error" flag.

Returns:
the "stop updates on config error" flag.

setRollbackOnConfigErrorFlag

public void setRollbackOnConfigErrorFlag(boolean rollbackOnConfigErrorFlag)
Sets the "rollback on config error" flag.

Parameters:
rollbackOnConfigErrorFlag - The "rollback on config error" flag.

getRollbackOnConfigErrorFlag

public boolean getRollbackOnConfigErrorFlag()
Gets the "rollback on config error" flag.

Returns:
the "rollback on config error" flag.

setUpdateNvRamConfigFlag

public void setUpdateNvRamConfigFlag(boolean updateNvRamConfigFlag)
Sets the "update NVRAM config" flag.

Parameters:
updateNvRamConfigFlag - The "update NVRAM config" flag.

getUpdateNvRamConfigFlag

public boolean getUpdateNvRamConfigFlag()
Gets the "update NVRAM config" flag.

Returns:
the "update NVRAM config" flag.


Copyright © 2005-2008 Fox Smart, Inc. All Rights Reserved.