Professional Documents
Culture Documents
Lecture 2
n1 n0 n0 n2 n1 n2 n3
n3
#Open the NAMtrace file set nf [open out.nam w] #Setup an FTP over TCP connection $ns namtrace-all $nf
set ftp [new Application/FTP] $ftp attach-agent $tcp #Open the Trace file $ftp set type_ FTP
cbr
close $nf #Setup a CBR over UDP connection #Close the Trace file set cbr [new Application/Traffic/CBR] close $tf $cbr attach-agent $udp #Execute $cbr set type_ CBR NAM on the trace file nam out.nam $cbr set exec packet_size_ 1000 & $cbr set exit rate_ 01mb $cbr set random_ false }
0 0.1 1.0
4.0 4.5
sec
sink n2 n3 null 3
To create agents or traffic sources, a user should know the class names these objects (Agent/TCP, Agnet/TCPSink, Application/FTP and so on). Remember to look at look at the /tcl/libs/ns-default.tcl file.
This file contains the default configurable parameter value settings for available network objects.
Hint: a good indicator of what kind of network objects are available in NS and what are their configurable parameters.
cbr ftp ftp tcp n0 cbr upd n1 4 sink n2 n3 null
0 0.1 1.0 4.0 4.5 sec
Tracing
Besides the NAM trace ns2 can provide an ASCII trace file.
About Awk
AWK is a tool that allows simple data manipulation on trace files.
To run use:
awk -f Average.awk out.tr
END { for (packet_id=0; packet_id<=highest_packet_id; packet_id++ ) { start = start_time[packet_id]; end = end_time[packet_id]; packet_duration = end - start; if ( start < end ) printf("%f %f\n", start, packet_duration); } }
if ( packet_id > highest_packet_id ) highest_packet_id = packet_id; if ( start_time[packet_id] == 0 ) start_time[packet_id] = time; if ( flow_id == 2 && action != "d" ) { if ( event == "r" ) { end_time[packet_id] = time; } } else { end_time[packet_id] = -1; } }
Remember . . .
#plotdelay.plot set term png medium #000000 set output "cbr-delay.png" set ylabel "End-to-End delay(sec)" set xlabel "Start transmission time(sec)" set xrang [0:5] set xtics 0, 0.5, 5 set yrang [0:0.1] set ytics 0, 0.01, 0.1 set title "CBR end-to-end delay" plot "cbr-delay" title "CBR" with linespoints lt -1 pt 8
gnuplot>load plotdelay.plot
xgraph
xgraph cbr-delay
10
if(node_1==2 && node_2==3 && type=="cbr" && action=="r") { dif=seq_no-old_seq_no; if(dif==0) dif=1; jitter[i]=(time-old_time)/dif; seq[i]=seq_no; i=i+1; old_seq_no=seq_no; old_time=time; } } 11
13
14
15
In /ns-2.34/tcl/lib: ns-lib.tcl:
The actial simulator class, most of its member function definitions are here default values for configurable parameters for various network components, configure the parameter in otcl which actually take effect through C++ Packet header initialization & implementation, where you register your own packet type
ns-default.tcl:
ns-packet.tcl:
16
You will develop NS2 modules in one the following file types:
File type
C++ code Header definitions Tcl code
Example
What you would like to do is to incorporate these files into NS2 how?
17
Working assumption...
Assume that we wanted to build a multimedia application that runs over a UDP connection. Lets say that this application implements a "five rate media scaling" which can respond to network congestion to some extent by changing encoding and transmission policy pairs associated with scale parameter values
18
21
Example
1. Look for
Tcl code
Example
myDir/myfile.tcl \
To one line below
-I. /myWorks \
To one line below
23