set file1 [open out.tr w] $ns trace-all file1 |
Open file "out.tr" for writing the trace data from ALL queues.
NOTE: The trace-all command can appear anywhere... |
For more details: click here
set file1 [open out.tr w] $ns trace-queue $n2 $n3 file1 |
Open file "out.tr" for writing the trace data from queue $n2 <-> $n3.
NOTE: The trace-queue command must (ofcourse) appear after the definition of the link !!! |
To make this NS simulation output trace data, add the following:
Add the following line in the main program to open the trace file
and tell NS to dump trace data into the tracefile:
# +++++++++++++++++++++++++++++++++ # Open Data trace file set tracefile [open out.trace w] $ns trace-all $tracefile |
Add the following line in the "finish" procedure to close the trace file
upon termination:
# ++++++++++++++++++++++++++++ close tracefile global tracefile close $tracefile |
Make sure that /usr/local/sim/ns/bin is in your PATH.
+ 0.1 0 2 tcp 40 ------- 1 0.0 4.0 0 0 - 0.1 0 2 tcp 40 ------- 1 0.0 4.0 0 0 r 0.11016 0 2 tcp 40 ------- 1 0.0 4.0 0 0 + 0.11016 2 3 tcp 40 ------- 1 0.0 4.0 0 0 - 0.11016 2 3 tcp 40 ------- 1 0.0 4.0 0 0 r 0.311227 2 3 tcp 40 ------- 1 0.0 4.0 0 0 + 0.311227 3 4 tcp 40 ------- 1 0.0 4.0 0 0 - 0.311227 3 4 tcp 40 ------- 1 0.0 4.0 0 0 .... |
|
r 0.88136 3 4 tcp 592 ------- 1 0.0 4.0 1 2 ^ ^ ^^^ ***
Use grep to select the desired events (processing lines)
grep " 0 2 tcp " out.tr > output |
Obtains all TCP events between node 0 and 2 |
grep "^r" out.tr > output |
Get all lines that begins with "r" (receive events) |
grep "^r" trace-file | grep " 0 2 tcp " > output |
Get all lines that begins with "r" and containing " 0 2 tcp " |
Use gawk to process columns (after selecting the desired lines)
BEGIN { s=0; FS = " "} { nl++ } { s=s+$c } END \ {print "sum = " s "; N = " nl "; Avg = " s/nl}
BEGIN { FS = " "} { nl++ } {d=$c-t}{s2=s2+d*d} END \ {print "sum^2 = " s2 "; N = " nl "; Standard Dev = " sqrt(s2/nl) }
UNIX>> gawk -v c=1 -f Average.gawk data-file sum = 7; N = 4; Avg = 1.75 |
Computes the average for column 1 values in the "data-file" |
UNIX>> gawk -v t=1.75 -v c=1 -f Std.gawk data-file sum^2 = 0.75; N = 4; Standard Dev = 0.433013 |
Computes the standard deviation fro column 1 values in the "data-file". (Note that we must enter the average t=1.75 explicitly) |
Usage:
column -t " " 1 3 < data-file 1 3 2 4 2 4 2 4 |
Extracts columns 1 and 3 from "data-file" (First column is numbered as 1) |
The following PERL script compute the average TCP traffic received by a certain node:
Usage:
perl throughput TRACE-File destNode \ srcNode.port# destNode.port# TimeSlice perl throughput out.tr 4 0.0 4.0 1 Sample output:You can use "gnuplot" to make a graph of the throughput |
This program knows the column data format in a trace file.
It will look in column 1 to find the receive events ("r") and in column 5 for "tcp" streams. Using column 2 (time), it can calculate how much data is received in certain interval. The "destNode", "srcNode.port#" and "destNode.port#" will identify the TCP connection for the script. The script computes the amount of data received by that TCP connection for every "TimeSlice" sec interval |
DEMO:
perl throughput out.tr 4 0.0 4.0 1 > plotdata
gnuplot
gnuplot> plot "plotdata" using 1:2 title "TCP throughput" with lines 1
Filtering is done when the trace file is opened in the TCL script.
Instead of opening the file, we open a pipe.
set file1 [open "| grep \"tcp\" > out.tr" w] |
The "out.tr" output file will only contain lines that has the word "tcp" in them |
set file1 [open qm.out w] set qmon [$ns monitor-queue $n2 $n3 $file1 0.1] [$ns link $n2 $n3] queue-sample-timeout Sample output: Time Link Cur Queue #Pkt #bytes size A D L A D L ======================================================== 0 2 3 0 0 0 0 0 0 0 0 0.10000000000000001 2 3 0.0 0.0 0 0 0 0 0 0 0.20000000000000001 2 3 0.0 0.0 1 0 1 1000 0 1000 0.30000000000000004 2 3 0.0 0.0 1 0 1 1000 0 1000 0.40000000000000002 2 3 0.0 0.0 1 0 1 1000 0 1000 0.5 2 3 0.0 0.0 1 0 1 1000 0 1000 0.59999999999999998 2 3 0.0 0.0 1 0 1 1000 0 1000 0.69999999999999996 2 3 0.0 0.0 1 0 1 1000 0 1000 0.79999999999999993 2 3 0.0 0.0 1 0 1 1000 0 1000 0.89999999999999991 2 3 0.0 0.0 1 0 1 1000 0 1000 0.99999999999999989 2 3 0.0 0.0 2 0 2 2000 0 2000 1.0999999999999999 2 3 0.0 0.0 3 1 2 2040 40 2000 |
Open the file "qm.out" for queue monitoring
link ($n2,$n3)
Write queue statistics every 0.1 sec |
NOTE: This command works for ALL queues.
NOTE: The average queue length data is NOT available in general (currect queue length IS available). Avg. queue length data is only available for RED queues.