pcpuCommandService
pcpuCommandService - execute Linux commands on a port's CPU
SYNOPSIS
pcpuCommandService sub-command options
DESCRIPTION
Most intelligent Ixia ports runs the Linux Operating system. Any Linux command may be remotely executed by TCL programming. The port command's isValidFeature sub-command may be used to determine if a given port runs Linux. Use the following sequence:
if [port isValidFeature $chas $card $port portFeatureIxRouter] {
... port runs Linux ...
}
Refer to Issue Port CPU Command for an overview of this command. Commands may be sent to a set of ports and executed simultaneously. Different commands may be executed on different ports. The result of each port's command execution may be individually retrieved.
The add sub-command is used to build a list of commands for multiple ports. The execute command causes all commands in the list to be sent to the affected ports and executed simultaneously. The result of all command execution is available by traversing through the list using the getFirst and getNext sub-commands. All Standard Options are read-only and only valid after a getFirst/getNext call.
STANDARD OPTIONS
cardID
Read-only. The card associated with the command.
chassisID
Read-only. The chassis associated with the command.
command
Read-only. The executed command.
error
Read-only. After command execution, the first 1024 characters that were sent to the standard error stream.
input
Read-only. Optional text to be used as the standard input stream for the command to be executed.
output
Read-only. After command execution, the first 1024 characters that were sent to the standard output stream.
portID
Read-only. The port associated with the command.
result
Read-only. After command execution, the return code from the command. Normally, `0' indicates a successful command execution and non-zero indicates an error.
COMMANDS
The pcpuCommandService command is invoked with the following sub-commands. If no sub-command is specified, returns a list of all sub-commands available.
pcpuCommandService addchasID cardID portID command [input]
Adds a command to the indicated port. The same command may be entered multiple times; commands are executed in the order that the add sub-command was used.
command is the text of the command to be executed, which must use an absolute path. For example, `/bin/ls'. No filename expansion is performed on the command. For example, `/bin/ls /bin/ix*' finds no matches. This, and the restriction on absolute path, may be avoided by executing the command through a bash shell, as in:
pcpuCommandService add 1 1 1 "/bin/bash -c `ls -l /bin/ix*'"
The input argument is optional, and if present, is used as the standard input stream for the command. For example, the following echos `hello world' to the commands standard output stream.
set command "/bin/cat"
set input "hello world\n"
pcpuCommandService add 1 1 1 $command $input
Specific errors are:
- No connection to a chassis
- Invalid port specification
- The port is owned by another user
- The port does not support Linux
pcpuCommandService cget option
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the pcpuCommandService command.
pcpuCommandService del chasID cardID portID
Removes all commands for the indicated port. Specific errors are:
- No connection to a chassis
- Invalid port specification
- The port is owned by another user
- The port does not support Linux
pcpuCommandService execute
All commands for all ports are sent to the ports for execution. The results of the commands' execution is available in the Standard Options after calls to getFirst and getNext. Specific errors are:
- Communications error with one or more ports
pcpuCommandService getFirst
+
Access the first command in the list. The command's results are available in the standard options. Specific errors are:
- There are no commands in the list
pcpuCommandService getNext
Access the next command in the list. The command's results are available in the standard options. Specific errors are:
- There are no more commands in the list
pcpuCommandService setDefault
Sets default values for all configuration options and clears all commands from the list.
EXAMPLES
package require IxTclHal
set host localhost
set username user
# Assume card 1 is a card that supports Linux
set card 1
# Commands to execute on ports
# Odd ports will echo a command from standard input
set oddCmd "/bin/cat"
set oddInput "hello there\n"
# Even ports will execute a command through bash
# This allows PATH lookup and filename expansion
set evenCmd "/bin/bash -c 'ls -l /bin/ix*'"
# If this is a UNIX system, connect through TCL Server
if [isUNIX] {
if [ixConnectToTclServer $host] {
ixPuts "Could not connect to $host"
return 1
}
}
# Connect to the chassis
if [ixConnectToChassis $host] {
ixPuts $::ixErrorInfo
return 1
}
# Get the chassis ID
set chas [ixGetChassisID $host]
# Make sure that this card supports Linux
if {[port isValidFeature $chas $card 1 portFeatureIxRouter] == 0} {
ixPuts "$chas:$card does not have a local CPU"
return 1
}
# Get the number of ports on the card
if [card get $chas $card] {
ixPuts $::ixErrorInfo
return 1
}
set portCount [card cget -portCount]
# Delete any previous list of commands
pcpuCommandService setDefault
# For all the ports
for {set i 1} {$i <= $portCount} {incr i 1} {
# For the odd ports
if [expr $i & 1] {
if [pcpuCommandService add $chas $card $i $oddCmd \
$oddInput] {
ixPuts $::ixErrorInfo
return 1
}
} else {
# for the even ports
if [pcpuCommandService add $chas $card $i $evenCmd ] {
ixPuts $::ixErrorInfo
return 1
}
}
}
# Do the commands
if [pcpuCommandService execute] {
ixPuts $::ixErrorInfo
return 1
}
# Retreive and print the results
for {set next [pcpuCommandService getFirst]} \
{$next != $::TCL_ERROR} \
{set next [pcpuCommandService getNext]} {
set chassis [pcpuCommandService cget -chassisID]
set card [pcpuCommandService cget -cardID]
set port [pcpuCommandService cget -portID]
set command [pcpuCommandService cget -command]
set output [pcpuCommandService cget -output]
set result [pcpuCommandService cget -result]
ixPuts -nonewline "$chassis:$card:$port, "
ixPuts "cmd: $command, result: $result, output: $output"
}