Stu2 - W7IY

Appendix C - Controlling the Emulator via the Network

On the Windows Client

Load Runner calls an external batch file (switch.bat) with two parameters; latency and bandwidth, as follows:

switch.bat 10 1544

This represents 10ms and 1544 kbps. The batch file (switch.bat) pipes the parameters to netcat, which sends the data over the network to the server on port 7890. Modify switch.bat with the proper IP address and port. Allow about 2 seconds before the next test starts.

On the Server

Make sure the IO::Socket perl module exists. Verify the path and file names in server.pl, then run the script. Server.pl opens a socket waiting for the data from the Windows client. When data is received, a simple sanity check is run against the values. Latency must be between 0 and 1000 seconds. Bandwidth must be between 0 and 10000 kbps. Latency is expressed in terms of total round trip time.

The data is logged (with date/time stamp) to /root/script.log and passed to the queuing script, shaper3, which is a bash script. The queuing script divides the latency by 2 and sets the input/output delay. Bash uses $1 and $2 for the command line arguments. To divide the latency by two, use the expression:

z=`expr $1 / 2`

Note the backticks. Also, make sure this runs in a secure environment. There are no security checks. (e.g. Authentication, encryption, etc.)

Scripts

switch.bat

echo %1 %2 | nc -w 1 192.168.10.20 -p 7890

server.pl

#!/usr/bin/perl -w

# Server to pass latency and bw changes to the shaper script 


use IO::Socket;
use Time::localtime;

my $sock = new IO::Socket::INET(
                   LocalHost => '192.168.10.20',
                   LocalPort => 7890,
                   Proto     => 'tcp',
                   Listen    => SOMAXCONN,
                   Reuse     => 1);
$sock or die "no socket :$!";
my($new_sock, $c_addr, $buf);
while (($new_sock, $c_addr) = $sock->accept()) {
    my ($client_port, $c_ip) =
                     sockaddr_in($c_addr);
    my $client_ipnum = inet_ntoa($c_ip);
    my $client_host =
             gethostbyaddr($c_ip, AF_INET);
    print "got a connection from: $client_host",
          " [$client_ipnum]\n";
    while (defined ($buf = <$new_sock>)) {
	#print $buf;
	my @parms = split(/ /, $buf);

	# sanity check
	# 0 < Latency < 1000 and 64 < BW < 10000
	# Defaults are latency=0 and BW=10000
	if ($parms[0] < 0 || $parms[0] > 1000) { $parms[0] = "0"; }	
	if ($parms[1] < 64 || $parms[1] > 10000) { $parms[1] = "10000"; }

	# Print the results to the screen
        print "latency: $parms[0] bw: $parms[1]\n";

	# Log the change
	open(LOG, ">>/root/script.log") or die "Can't open file.\n";
	$tm = localtime;
	($day,$month,$year,$hrs,$min,$sec)=($tm->mday,$tm->mon,$tm->year,$tm->hour,$tm->min,$tm->sec);
	$year=$year+1900;
	$month=$month+1;
	$stamp = "$year-$month-$day,$hrs:$min:$sec";
	print LOG "$stamp,$parms[0],$parms[1]\n";
	close(LOG);

	# run the shell script
	system "/root/test @parms";

    }
}
close(LOG);

shaper3

#!/bin/bash
lat=`expr $1 / 2`
bw=$2
# Rest of script goes here