The classic performance analysis network:
NS script to construct this network:
# ####################################################################
# Create bottleneck and dest nodes
set n2 [$ns node]
set n3 [$ns node]
# ####################################################################
# Create bottleneck link (between bottleneck nodes n2-n3)
$ns duplex-link $n2 $n3 0.7Mb 20ms DropTail
# ####################################################################
# Set Queue Size of bottleneck link (n2-n3)
$ns queue-limit $n2 $n3 100
# ####################################################################
# Set number of sources
set NumbSrc 3
# ####################################################################
# Use a for-loop to create $NumbSrc source nodes
for {set j 1} {$j<=$NumbSrc} { incr j } {
set S($j) [$ns node]
}
# ####################################################################
# This part is used to start the sources at random times
# ####################################################################
# Create a random generator for starting the ftp and
# for bottleneck link delays
set rng [new RNG]
$rng seed 2
# ####################################################################
# parameters for random variables for begenning of ftp connections
set RVstart [new RandomVariable/Uniform]
$RVstart set min_ 0
$RVstart set max_ 7
$RVstart use-rng $rng
# ####################################################################
# Define RANDOM starting times for each connection
# And set (possible random) delay for connection from sources to Node 0
for {set i 1} {$i<=$NumbSrc} { incr i } {
set startT($i) [expr [$RVstart value]]
set dly($i) 1
puts "startT($i) $startT($i) sec"
puts $param "startT($i) $startT($i) sec"
}
# ####################################################################
# Create links between source and bottleneck
# 1. Select the delay from each source to bottleneck node
# 2. Set queue size (#packets)
for {set j 1} {$j<=$NumbSrc} { incr j } {
$ns duplex-link $S($j) $n2 10Mb $dly($j)ms DropTail
$ns queue-limit $S($j) $n2 20
}
# ####################################################################
# Orient the links
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $S(1) $n2 orient right-down
$ns duplex-link-op $S(2) $n2 orient right
$ns duplex-link-op $S(3) $n2 orient right-up
# ####################################################################
# Create TCP Sources
for {set j 1} {$j<=$NumbSrc} { incr j } {
set tcp_src($j) [new Agent/TCP/Reno]
$tcp_src($j) set window_ 8000
}
# ####################################################################
# Color the packets
$tcp_src(1) set fid_ 1
$ns color 1 red
$tcp_src(2) set fid_ 2
$ns color 2 yellow
$tcp_src(3) set fid_ 3
$ns color 3 blue
# ####################################################################
# Create TCP Destinations
for {set j 1} {$j<=$NumbSrc} { incr j } {
set tcp_snk($j) [new Agent/TCPSink]
}
# ####################################################################
# Schedule START events for the FTP agents:
for {set i 1} {$i<=$NumbSrc} { incr i } {
$ns at $startT($i) "$ftp($i) start"
$ns at $SimDuration "$ftp($i) stop"
}
|
# ####################################################################
# plotWindow(tcpSource file k): Write CWND of k tcpSources in file
proc plotWindow {tcpSource file k} {
global ns NumbSrc
set time 0.03
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
if {$k == 1} {
puts -nonewline $file "$now \t $cwnd \t"
} else {
if {$k < $NumbSrc } {
puts -nonewline $file "$cwnd \t"
}
}
if { $k == $NumbSrc } {
puts -nonewline $file "$cwnd \n"
}
if { $k == $NumbSrc } {
puts -nonewline $file "$cwnd \n"
}
$ns at [expr $now+$time] "plotWindow $tcpSource $file $k"
}
Usage:
# ####################################################################
# Start plotWindow() for all tcp sources
for {set j 1} {$j<=$NumbSrc} { incr j } {
$ns at 0.1 "plotWindow $tcp_src($j) $windowVsTime $j"
}
|
TIME Win_flow1 Win_flow2 Win_flow3 .... Win_flowN |
plot "windowFile" using 1:2 t "Flow 1" w lines 1, \
"windowFile" using 1:3 t "Flow 2" w lines 2, \
"windowFile" using 1:4 t "Flow 3" w lines 3
|
# #################################################################### # Monitor avg queue length of link ($n2,$n3) set qfile [$ns monitor-queue $n2 $n3 [open queue.tr w] 0.05] [$ns link $n2 $n3] queue-sample-timeout; |
plot "queue.tr" using 1:5 t "Queue Length" w lines 1
NOTES:
# #################################################################### # Usage: # # perl throughput |
Example:
r 0.005749 2 0 tcp 40 ------- 1 2.0 1.0 0 0
...
r 0.026206 0 1 tcp 40 ------- 1 2.0 1.0 0 0
2.0 1.0
You need these as input parameters for the "throughput" script.
throughput trace-file 1 2.0 1.0 0.5 > plotdata
Time Throughput (in MBytes/sec)
that you can use gnuplot to plot the trend:
gnuplot
gnuplot> plot "plotdata" using 1:2 title "TCP throughput" with lines 1
(The Perl script is here: click here )
# ########################################################################
# throughput-filter: PERL utility for reducing the trace-file size #
# #
# Usage: #
# #
# When you open the trace-file in NS, use this command: #
# #
# set file1 [open "| perl thruput-filter destNode > trace-file" w] #
# ########################################################################
# #############################################################
# Get node that receives packets
$tonode=$ARGV[0];
# ########################################################################
# <STDIN> is the standard input stream, already opened !
while (<STDIN>) {
# Tokenize line using space as separator
$line=$_;
@x = split(' ');
# checking if the event (column 0) corresponds to a reception
if ($x[0] eq 'r')
{
# checking if the destination corresponds to node in arg
if ($x[3] eq $tonode)
{
print STDOUT $line
}
}
}
exit(0);
|
set file1 [open "| perl thruput-filter destNode > trace-file" w]
# #################################################################### # Create RED links between bottleneck nodes $ns duplex-link $n2 $n3 0.7Mb 20ms RED |
# #################################################################### # Monitor avg queue length of RED link ($n2,$n3) in file "red-queue.tr" set traceq [open red-queue.tr w] - open a trace file for RED set redq [[$ns link $n2 $n3] queue] - get the RED queue $redq trace curq_ - Tell the RED queue to trace changes to its variable curq_ (current Q len) $redq trace ave_ - Tell the RED queue to trace changes to its variable ave_ (average Q len) $redq attach $traceq - Send the trace data to file "traceq" |
The output of the "traceq" file will look like this:
Trace
code Time Value (unit = #packets)
--------------------------------------
a 0.106137 0.00569799
Q 0.106137 1 <--- first packet arrives
a 0.148626 0.00556923
Q 0.148626 0 <--- first packet departed
a 0.1491 0.00553749
a 0.155392 0.00550594
a 0.155865 0.0111726
Q 0.155865 1 <--- second packet arrives
....
NOTE: The default buffer unit in RED queue is #packets
You can change it to operate in "byte" mode: click here
grep a red-queue.tr > ave.tr grep Q red-queue.tr > cur.tr |
plot "ave.tr" using 2:3 t "Average Qlength" w lines 1, \
"cur.tr" using 2:3 t "Current Qlength" w lines 2
|
plot "data" using 1:2 title "Flow 1" with lines 1 |
Make a line plot with color 1 using columns 1 and 2 from file "data" |
plot "data" using 1:2 title "Flow 1" with lines 1 \
"data" using 1:3 t "Flow 2" w lines 2
|
Make a plot containing 2 line plots. First, a line plot with color 1 using columns 1 and 2 from file "data" and second with color 2 using columns 1 and 3 from file "data" |
load "gnuplot-script" |
Execute the stored commands inside the file "gnuplot-script" |
set out "plot.ps" set size 0.7, 0.7 set terminal postscript portrait color replot set terminal x11 set size 1,1 |
These commands first changes the output to the file "plot.ps.
Then changes the size and the terminal to a "color postscript device" and
replot the figure (the figure will now be saved as a postscript file).
The last 2 command reset the terminal back to the X-window display and resize to normal. |
set out "plot.ps" set size 0.7, 0.7 set terminal postscript portrait mono replot set terminal x11 set size 1,1 |
Same, now with mono-color |
set out "plot.ps"
load "gp-color-ps" or load "gp-mono-ps"
Average throughputs:
Average throughputs: