I'm trying to use WFQ scheduling algorithm on NS2 (ver. 2.35)
I added the following implementation to NS2:
https://www.cse.iitb.ac.in/~varsha/allpapers/packet-scheduling/sim_code/ns2_packet_scheduling/src/
and wrote a simple dumbbell topology to test it:
set ns [new Simulator]
set nf [open trace.nam w]
$ns namtrace-all $nf
set tf [open trace.tr w]
$ns trace-all $tf
proc finish {} {
global ns tf nf
$ns flush-trace
close $tf
close $nf
exec nam trace.nam &
exit 0
}
Simulator instproc get-link { node1 node2 } {
$self instvar link_
set id1 [$node1 id]
set id2 [$node2 id]
return $link_($id1:$id2)
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set R1 [$ns node]
set R2 [$ns node]
$ns duplex-link $n0 $R1 10Mb 1ms DropTail
$ns duplex-link $n2 $R1 10Mb 1ms DropTail
$ns duplex-link $R1 $R2 1Mb 3ms WFQ
$ns duplex-link $R2 $n1 10Mb 1ms DropTail
$ns duplex-link $R2 $n3 10Mb 1ms DropTail
set l [$ns get-link $R1 $R2]
set q [$l queue]
$q buckets 6
$q bandwidth 100
$q blimit 10000
$q mask 0
$q quantum 0 .40
$q quantum 1 .60
$ns queue-limit $R1 $R2 10
$ns duplex-link-op $R1 $n0 orient left-up
$ns duplex-link-op $n1 $R2 orient left-down
$ns duplex-link-op $R1 $R2 orient right
$ns duplex-link-op $n2 $R1 orient right-up
$ns duplex-link-op $R2 $n3 orient right-down
$ns duplex-link-op $R1 $R2 queuePos 0.5
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set tcpsink0 [new Agent/TCPSink]
$ns attach-agent $n1 $tcpsink0
set udpsink0 [new Agent/Null]
$ns attach-agent $n3 $udpsink0
set udp0 [new Agent/UDP]
$udp0 set class_ 6
$ns attach-agent $n2 $udp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set cbr [new Application/Traffic/CBR]
$cbr set packetSize_ 500
$cbr set rate_ 1Mb
$cbr attach-agent $udp0
$ns connect $udp0 $udpsink0
$ns connect $tcp0 $tcpsink0
$ns at 0.1 "$ftp0 start"
$ns at 0.1 "$cbr start"
$ns at 300.0 "$ftp0 stop"
$ns at 300.0 "$cbr stop"
$ns at 305.0 "finish"
$ns run
But after running simulation I get
No active flow
No active flow
No active flow
Floating point exception (core dumped)
While the implementaion example (here ) works (it only gives No active flow messages but not the Floating point exception (core dumped) )
Related
I have a very simple script to ping a host and find out the duration of the ping
use 5.010;
use Net::Ping;
my $p = Net::Ping->new();
my ($ret, $duration, $ip) = $p->ping('google.com');
say $ret;
say $duration;
say $ip;
For some reason this keeps timing out ($ret returns 0 and $duration returns 5 seconds)
What is the reason for this?
I have something like the following curl code:
foreach my $value ('1', ..., '5') {
my $count = 1;
print "\nValue: $value\n\t";
my $start = `curl -m 10 -s "http://SITE/?value=$value" -c cookie.txt`;
my $end1 = `curl -m 10 -s "http://SITE2" -b cookie.txt`;
if($end1 ne "") {print ". "}; else print "$count ";
my $end2 = `curl -m 10 -s "http://SITE3" -b cookie.txt`;
if($end2 ne "") {print ". "}; else print "$count ";
my $end3 = `curl -m 10 -s "http://SITE4" -b cookie.txt`;
if($end3 ne "") {print ". "}; else print "$count ";
$count++;
}
So from value 1 to 5, it visits a website and stores the cookie value in cookie.txt. Then it visits 3 different websites using the stored cookies in cookie.txt. Once it visits these sites, it prints current count (or . if the request timed out after 10 seconds).
An example output for this would be:
Value: 1
1 1 1 2 . 2 3 3 3 4 . . . 5 5
Value: 2
. . 1 2 2 2 3 3 3 4 . 4 5 5 .
Would it be possible to format the output to look like:
Value: 1
Site2: 1 2 3 4 .
Site3: 1 . 3 . 5
Site4: 1 2 3 . 5
Value: 2
Site2: . 2 3 4 5
Site3: . 2 3 . 5
Site4: 1 2 3 4 .
The issue I have is that in the loop, I would only like to run $start once per loop. With the way I want it formatted, it would have to be run once per site (3 times).
Your requirement is a bit confusing, but this will give you the output you're seeking:
my #sites = qw( SITE2 SITE3 SITE4 );
foreach my $value ('1'..'5') {
print "\nValue: $value\n";
my $start = `curl -m 10 -s "http://SITE/?value=$value" -c cookie.txt`;
for my $site (#sites) {
print "\t$site ";
for (1..5) { # assuming you want to fetch each url 5x
my $end = `curl -m 10 -s "http://$site" -b cookie.txt`;
print $end eq '' ? '. ' : $_.' ';
}
print "\n";
}
}
Please turn on use strict; and use warnings.
If you did, you'd find:
foreach my $value ('1', ..., '5') {
print $value,"\n";
}
Is a syntax error. Which is not a good start. Perhaps you want:
foreach my $value ( 1..5) {
print $value,"\n";
}
Likewise you've to a $count variable that you never change, because you scope it locally within your loop (via my) and set it to 1 each iteration. And then increment it right at the end, just before it drifts out of scope.
This script works every time from command line but very rarely from cron job. I can run it like this: ./chort.pl
But it dies very frequently (not always) with "wrong values" message while calling it from cron:
*/2 10-18 * * 1-5 /path/to/chort.pl >> /tmp/chort.pl 2>&1
When it dies, than the $res is empty. print "*$res*\n"; prints **. So , it seems, that there is a problem with getting of webpage while calling from cron.
Here a snippet:
sub getLSEVal
{
my $fourWayKey = shift;
my $url = "http://pat.to.url";
my $res;
timeout 280 => sub {
$res = get $url ;
return (-2, -2, -2 );
};
print $res;
$res =~ /Price\| High \| Low .*?<tr class="odd">.*?<td>(.*?)<\/td>.*?<td>(.*?)<\/td>.*?<td>(.*?)<\/td>/msig;
my $c = $1;
my $h = $2;
my $l = $3;
print "$1 $2 $3\n";
die ("wrong values") if $c !~ /\d+\.?\d*/ or $h !~ /\d+\.?\d*/ or $l !~ /\d+\.?\d*/;
return ($c, $h, $l);
}
You probably need to use LWP::UserAgent, which allows you a higher level of control. LWP::Simple sometimes is too abstract to know what is happening when a problem appears.
Given the following command and its output:
ssh -q $server 'df -hP /raj*
Size Used Avail Capacity Mounted On
200G 154G 44G 79% /raj_day
200G 154G 44G 49% /raj1_day
200G 154G 44G 39% /raj2_day
I would like to convert into Tabular format so presentation should be good. Also, want to display Capacity in sorting order. Any tips for me in perl?
My Script as follows...
#############################################
#!/usr/local/bin/perl
# Use either -h or -k flag or leave it blank for default (-k)
# -h for human-readable size output
# -k for 1k-block output
$flag = "-h";
#df = `df $flag`;
print "Content-type: text/htmln\n";
print "<table border=2>\n";
print "<tr>\n";
print "<td><b>Filesystem</b></td>\n";
if ($flag eq "-h") {
print "<td><b>Size</b></td>\n";
}
else {
print "<td><b>1k-blocks</b></td>\n";
}
print "<td><b>Used</b></td>\n";
print "<td><b>Avail</b></td>\n";
print "<td><b>Capacity</b></td>\n";
print "<td><b>Mounted on</b></td>\n";
print "</tr>\n";
foreach $line (#df) {
next if ($line =~ /Filesystem/);
($fsystem,$blocks,$used,$avail,$capacity,$mounted) = split(/s+/,$line);
print "fsystem is $fsystem\n";
print "blocks is $blocks\n";
print "used is $used\n";
print "avail is $avail\n";
print "capacity is $capacity\n";
print "mounted is $mounted\n";
($number,$sign) = split(/%/,$capacity);
if ($number < 60) {
print "<tr bgcolor=green>\n";
}
elsif (($number >= 60) && ($number < 90)) {
print "<tr bgcolor=yellow>\n";
}
else {
print "<tr bgcolor=red>\n";
}
#
print "<td>$fsystem</td>\n";
print "<td>$blocks</td>\n";
print "<td>$used</td>\n";
print "<td>$avail</td>\n";
print "<td>$capacity</td>\n";
print "<td>$mounted</td>\n";
print "</tr>\n";
}
print "</table>\n";
OUTPUT AS FOLLOWS
Content-type: text/htmln
Filesystem Size Used
Avail Capacity Mounted
on fsystem is /dev/ blocks is da3 95G
33G 58G 36% /
used is avail is capacity is mounted is fsystem is tmpf blocks is
499M 88K 499M 1% /dev/ used is hm
avail is capacity is mounted is fsystem is /dev/ blocks is da1
124M 39M 79M 33% /boot
used is avail is capacity is mounted is
Like daxim already pointed out: It's a stupid idea to parse the output of df, but if I had to hack down a small script it would probably look like this:
df -B M -P /path1 /path2 /path3 | sed -e '1d' | sort -k 4,4 -r -h | column -t
Here is the loop in bash:
while [ $# -ge 1 ]; do
case $1 in
-a)
shift
NUM_AGENTS=$1
;;
-h)
shift
HOST_NAME=$1
;;
-t)
shift
TIME_STAGGER=$1
;;
-un)
shift
USER_NAME=$1
;;
-pw)
shift
USER_PASS=$1
;;
-p)
shift
TARGET_PAGE=$1
;;
-s)
shift
COMMON_SID=$1
;;
esac
shift
done
How can i convert this in perl so that the argument would populate the values in the command line
php loadAgent_curl.php $NUM_AGENTS $HOST_NAME $procStartTime $i $TARGET_PAGE $reqlogfile $resplogfile $USER_NAME $USER_PASS $execDelay $COMMON_SID &
------- appended to question:
this certainly helps, and i really appreciate it, is there any way to access these parameters outside the getOptions ? here is rest of the bash script: my $i="0";
my $startTime=date +%s;
startTime=$[$startTime+$NUM_AGENTS+10]
my $PWD=pwd;
my $logdir="\$PWD/load-logs";
system(mkdir $logdir/$startTime);
my $reqlogfile="$logdir/$startTime/req.log";
my $resplogfile="$logdir/$startTime/resp.log";
print "\n";
print "##################\n";
print "LAUNCHING REQUESTS\n";
print " HOST NAME : \$HOST_NAME\n ";
print " TARGET PAGE : \$TARGET_PAGE\n ";
print " # AGENTS : \$NUM_AGENTS\n ";
print " EXECUTION TIME : \$startTime (with random stagger between 0 and \$TIME_STAGGER seconds)\n ";
print " REQ LOG FILE : $reqlogfile\n ";
print " RESP LOG FILE : $resplogfile\n ";
print "##################\n";
print "\n";
#
#
highestStart=$startTime
$startTime += $ARGV[0] + 5;
my $dTime = localtime( $startTime );
print "\n##################\nLAUNCHING REQUESTS\n
COUNT: $ARGV[0]\n
DELAY: | 1 \n
The scripts will fire at : $dTime\n##################\n\n";
while ( $ARGV[0] > $i )
{
$i++;
system("php avtestTimed.php $ARGV[0] $ARGV[2] $startTime");
print "RUN system('php avtestTimed.php $ARGV[0] $ARGV[2] $startTime'); \n";
sleep 1;
}
#
#
while [ $NUM_AGENTS -gt "$i" ]
do
i=$[$i+1]
execDelay=$((RANDOM % $TIME_STAGGER))"."$((RANDOM % 100))
procStartTime=$[$startTime]
procStartTime=$[$startTime+$execDelay]
if [ $procStartTime -gt $highestStart ]
then
highestStart=$procStartTime
fi
echo "STATUS: Queueing request $i with a delay of $execDelay seconds"
echo " '--> COMMAND: php loadAgent_curl.php $NUM_AGENTS $HOST_NAME $procStartTime $i $TARGET_PAGE $reqlogfile $resplogfile $USER_NAME $USER_PASS $execDelay $COMMON_SID"
php loadAgent_curl.php $NUM_AGENTS $HOST_NAME $procStartTime $i $TARGET_PAGE $reqlogfile $resplogfile $USER_NAME $USER_PASS $execDelay $COMMON_SID &
sleep 1
done
echo "STATUS: Waiting for queued requests to be ready"
while [ date +%s -lt $startTime ]
do
sleep 1
done
#
echo "STATUS: Waiting for last request to issue"
while [ date +%s -lt $highestStart ]
do
sleep 1
done
#
echo "STATUS: Last response issued"
#
echo "STATUS: Waiting for response log file to be created"
while [ ! -e "$resplogfile" ]
do
sleep 1
done
#
while [ wc -l "$resplogfile"| awk '{print $1'} -lt $NUM_AGENTS ]
do
#echo "(wc -l "$resplogfile"| awk '{print $1'} of $NUM_AGENTS responses recorded)"
sleep 1
done
echo "STATUS: FINISHED"
while true; do
read -p "Do you wish to view the request log? [y/n]" yn
case $yn in
[Yy]* ) cat $reqlogfile; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
while true; do
read -p "Do you wish to view the response log? [y/n]" yn
case $yn in
[Yy]* ) cat $resplogfile; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
Getopt::Long library is a standard Perl way to process command line options.
Something like this will work. Not tested - caveat emptor!
Please note that since your PHP parameters are a mix between command line options AND some unidentified variables, I have designed the first example so that ALL the possible options should be stored in %args hash (e.g. your program should use $args{procStartTime} instead of $procStartTime). This allowed me to make it very short and generic.
If this is hard to read/understand, I also have a second example that's more straightforward but less generic
use Getopt::Long;
my #php_arg_order = qw(a h procStartTime i p reqlogfile
resplogfile un pw execDelay s);
my %args = map {$_ => ""} #php_arg_order;
$args{procStartTime} = "something";
$args{reqlogfile} = "a.log";
# More defaults for variables NOT passed in via command line.
# Populate them all in %args as above.
# Now load actual command line parameters.
GetOptions(\%args, map { "$_=s" } #php_arg_order) or die "Unknown parameter!\n";
system(join(" ",
"php", "loadAgent_curl.php",map { $args{$_} } #php_arg_order}, "&"));
A second, less advanced but more direct option is:
use Getopt::Long;
my %args = ();
# Now load actual command line parameters.
GetOptions(\%args,
"NUM_AGENTS|a=s"
,"HOST_NAME|h=s"
,"USER_NAME|un=s"
# ... the rest of options
# The "XXX|x" notaion allows using alias "-x" parameter
# but stores in $args{XXX} instead for better readability
) or die "Unknown parameter!\n";
system("php loadAgent_curl.php $args{NUM_AGENTS} $args{HOST_NAME} $procStartTime $i $args{TARGET_PAGE} $reqlogfile $resplogfile $args{USER_NAME} $args{USER_PASS} $execDelay $args{COMMON_SID} &");