CDRouter Support

How can I automatically restart my router each time I run a test?

knowledge-base version 11.0

Overview

The easiest way to do this is to use a power strip that can be remotely controlled via telnet or HTTP. There are several commercially available products that provide this functionality - we recommend the NP-0801DT or NP-1601DT from Synaccess Networks. The Synaccess units can be controlled via telnet or through a URL. Examples of both are shown below.

The RestartDut and RestartDutDelay testvars in the CDRouter configuration file control the automatic reboot functionality of CDRouter. The RestartDut testvar allows you to enter a command or script that can be executed to power cycle the router under test. If this testvar is commented out, CDRouter will prompt the user to restart the router under test manually. Once power cycled, the router under test will also require a certain amount of time to reboot before it is fully operational. The RestartDutDelay testvar is designed to pause CDRouter for a number of seconds until the router under test is fully booted and operational. The appropriate value of RestartDutDelay is device dependent and must be determined for each individual router. The value of RestartDutDelay should be greater than (power cycle time + reboot time).

Note that multiple scripts or commands can be executed with the RestartDut testvar by separating each command with a semi-colon. Please see this Knowledge Base article for more information.

Controlling the Synaccess unit via telnet expect script

First, make sure that telnet is enabled in System page of the Synaccess web configuration tool.

There are multiple ways of automating the telnet session. One way is to use the expect utility. Here you will find a sample expect TCL script that will power cycle an outlet on a Synaccess NT-0801DT unit. The script would be the same for an NT-1601DT but would allow up to 16 outlets.

Sample powerCycle.tcl script for controlling a Synaccess unit.

# powerCycle.tcl script for Synaccess NP-08
set address [ lindex $argv 0 ]
set outlet [ lindex $argv 1 ]

if { $outlet <= 0 || $outlet > 8 } {
   puts "powerCycle.tcl failure: selected power outlet index was $outlet; must be between 1 and 8."
   exit
}

spawn -console telnet $address
expect {
   "Make sure to set Telnet mode to Local Echo Off" {
      send "rb $outlet\r"
      expect "Outlet-$outlet rebooted."
      send "logout\r"
      send "\r"
      puts "powerCycle.tcl success: outlet $outlet on host $address successfully power cycled."
      exit
   }
   "Unable to connect to remote host" {
      puts "powerCycle.tcl failure: unable to connect to the remote host."            exit
   }
   timeout {
      puts "powerCycle.tcl failure: connection timed out."  
      exit 
   }
}

This script can also be downloaded here. The powerCycle.tcl script has two arguments - the IP address of the Synaccess unit and the number of the outlet to power cycle.

Note: Expect must be installed prior to using this script.

Using the powerCycle.tcl script provided above, CDRouter can be easily configured to control the Synaccess unit and automatically reboot the router under test prior to each test run. To do this, first create or copy powerCycle.tcl to a working directory on the CDRouter host machine. Be sure that the powerCycle.tcl is executable:

chmod 755 powerCycle.tcl

Assuming the Synaccess unit is configured with an IP address of 10.0.0.200, the router under test is plugged into outlet 1, and the path of the powerCycle.tcl script is /home/qateam, the CDRouter configuration file would be modified as follows:

testvar RestartDut "expect /home/qateam/powerCycle.tcl 10.0.0.200 1"
testvar RestartDutDelay 20

Note: An appropriate value for RestartDutDelay testvar must be determined for each router (this value is device dependent). A value of 20 seconds should be appropriate for most routers.

Controlling the Synaccess unit via telnet PHP script

As mentioned above, make sure that telnet is enabled in System page of the Synaccess web configuration tool.

As an alternative method to automate a telnet session, a simple local website could be set up to accept a URL that can fake a telnet session and control the ports of multiple Synaccess units. An example PHP page to accomplish this is available for download here. If using an Apache HTTP server, you can use the virtual host definition found here to help get started.

Once the website is running, you can define config files as follows:

testvar RestartDut                    "curl http://power.lan/10.0.0.22/3/reboot"
testvar RestartDutDelay               30
testvar ShutdownDut                   "curl http://power.lan/10.0.0.22/3/off"

In these examples, power.lan is the URL of the local webserver where the PHP script lives. The IP address (10.0.0.22) is the IP address of the Synaccess unit. The 3 refers to the port on the Synaccess you want to control. Finally, the last part is the command for that port. Options are “on”, “off”, “reboot”, and “state”. Of course, you can modify the power.php script to behave however you want.

Controlling the Synaccess unit via wget.

Crafting a URL to send to the Synaccess units will allow you to toggle the state of an outlet. The format of the URL differs slightly depending on whether you have an older or newer unit.

Older style Synaccess units.

Assuming the Synaccess is configured with an IP address of 192.168.1.16 and the router under test is plugged into outlet 12 on the NP-16, the CDRouter configuration file would be modified as follows:

testvar RestartDut "wget --http-user=admin --http-password=admin http://192.168.1.16/pwrSw12.cgi"
testvar RestartDutDelay 20

Newer style Synaccess units.

Newer versions of the Synaccess have a slightly different URL for modifying the state of an outlet. To toggle outlet 1 on or off use this command:

testvar RestartDut "wget --http-user=admin --http-password=admin http://192.168.1.16/cmd.cgi?rly=0"
testvar RestartDutDelay 20

To reboot outlet 1, use this command:

testvar RestartDut "wget --http-user=admin --http-password=admin http://192.168.1.16/cmd.cgi?rb=0"
testvar RestartDutDelay 20

Note that for newer style NP-16 devices the outlet numbers are indexed from 0 when controlling them via URL. Outlet 1 is controlled using the rly=0 or rb=0 arguments in the commands above, respectively.

Note: For all examples above, an appropriate value for the RestartDutDelay testvar must be determined for each router (this value is device dependent). A value of 20 seconds should be appropriate for most routers.

Contents

×

About CDRouter

CDRouter is made by QA Cafe, a technology company based in Portsmouth, NH.

Get in touch via our Contact page or by following us on your favorite service: