qacafe - ip test solutions
Knowledge Base > Basic Configuration > How can I automatically restart my router each time I run a test in buddy or BuddyWeb?

How can I automatically restart my router each time I run a test in buddy or BuddyWeb?

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-08 from Synaccess Networks and the iP-415 from Dataprobe.

The Synaccess NP-08 can be controlled via telnet using the simple expect/tcl script below. See Example 1 for more information. The Dataprobe iP-415 can be controlled via HTTP using a single wget command. See Example 2 for more information.

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.

Sample powerCycle.tcl script for controlling the Synaccess NP-08

# 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 NP-08 power strip and the number of the outlet to power cycle.

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

Example 1: Sample configuration file using the Synaccess NP-08

Using the powerCycle.tcl script provided above, CDRouter can be easily configured to control the Synaccess NP-08 power strip 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 NP-08 is configured with an IP address of 10.0.0.200, the router under test is plugged into outlet 1 on the NP-08, 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.

Example 2: Sample configuration file using the Dataprobe iP-415

Assuming the iP-415 is configured with an IP address of 192.168.1.6 and the router under test is plugged into outlet 4 on the iP-415, the CDRouter configuration file would be modified as follows:

testvar RestartDut "wget -q -O /dev/null --http-user=admin
                    --http-passwd=PASS http://192.168.1.6 http://192.168.1.6         
                    http://192.168.1.6/C4 http://192.168.1.6/L"

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.