- Run ns-2
- ns-2 General
- ns-2 Topology/Traffic
- Tcl General
- Tcl Command
- Tcl Keyword
You should write an otcl script to run ns-2.
- run ns in text mode
$ns tcl/ex/mcast.tcl
- Edit tcl file
simple.tcl:
set ns [new Simulator]
$ns at 1 "puts \"Hello World!\""
$ns at 1.5 "exit"
$ns run
[prompt]$ns simple.tcl
Hello World!
- run ns with nam
- (run XWin32 in Windows, it may be very difficult to run Cygwin X server)
- run Cygwin
- $export DISPLAY=TRINITY:0.0 (TRINITY -> local host name, should be UPPER CASE LETTER!!)
- $ns tcl/ex/nam-example.tcl
- NAM : node/link position/color, tracing
- scheduling event : $ns at time event
$ns at 0.1 "$cbr start"
- flush-trace : dump the traces on the respective files
- How to work with trace files: awk, grep, perl, tcl script
- How to plot: gnuplot, xgraph
- define node : set n0 [$ns node]
- define link : $ns duplex-link $n0 $n2 10Mb 10ms DropTail
- define queue : $ns queue-limit $n0 $n2 20 (default value : 50)
- setup a UDP connection : set udp [new Agent/UDP]; $ns attach-agent $n1 $udp
- setup a CBR over UDP connection : set cbr [new Application/Traffic/CBR];
$cbr attach-agent $udp; $cbr set packetSize_ 1000; $cbr set rate_ 0.01Mb; $cbr set random_ false
- # : commented line
- create a file and assign a pointer to it : set file_p [open filename w]
- exec : execution of a unix command
- Simulator : Simulator class
- set : assign a value to a variable
set a 43 ; a = 43
set x $a ; x = a
- expr : mathematical operation
set x [expr $a + $b]; x = a + b
- puts : printing an output
puts "[expr 1.0/60.0]"
puts $file_p "text" ; writing to a file
- exit 0 : ends the application and the number 0 means a clean exit.
-
if { expression } {
-execute some commands-
} else {
-execute some commands-
}
-
for {set i 0} {$i < 5} { incr i } {
- execute some commands -
}
-
proc procname { par1 par2 ... } {
global var1 var2
-commands-
return $something
}
- Class : used to declare a class
- new : instantiation of a class
- instproc : the methods of the classes are declared by
- init : constructor of the class
- self : a pointer to the object itself
- instvar : to declare the instance variable,
The data members of a specific class are only defined within the member functions of the class.
This is unlike C++ in which the data members of the class are specfied in advance, and typically in header files.
Class data members are created or references using the instvar directive.
- -superclass : used for declaring that a class inherits from another one
- global : used to tell we are using the variables declared outside the procedures
For every simulator,
- how to install
- how to run (run and analyze a typical example)
- how to write a simulation
- how to analyze
- That's all !!
ns for beginners, chap.9ºÎÅÍ