What is ns2?
- NS is fairly easy to use once you get to know the simulator; it is quite difficult for a first time user, because there are few user-friendly manuals.
- Ns2 codes are defining using tcl programming languages.
NS2 Code
- The network simulator is a bank of different network and protocol objects. Each of which is defined by using the languages like C++ and OTcl.
What is the use of OTcl in TCL:
- Very easy to use and it is available in free.
- Helps us to specify the protocols and their applications
- Tcl is compatible with many platforms and it is flexible for integration
- Allows fast development
- By using the OTcl we can describe different network topologies.
What is the use of NAM:
- When we will run the above program in ns then we can visualize the network in the NAM
- Sample code for give position to the nodes in nam
$ns duplex-link-op $n0 $n2 orient-right-down $ns duplex-link-op $n1 $n2 orient-right-up $ns simplex-link-op $n2 $n3 orient-right $ns simplex-link-op $n3 $n2 orient-left $ns duplex-link-op $n3 $n4 orient-right-up $ns duplex-link-op $n3 $n5 orient-right-down
Scheduling event role in ns:
In ns the tcl script defines how to schedule the events or in other words at what time which event will occur and stop
$ns at 0.1 "cbr start" $ns at 1.0 "ftp start" $ns at 124.0 "ftp stop" $ns at 124.5 "cbr stop"
This is the sample code for scheduling events.
Sample code:
This is the code for Delays and initial transmission times created at random.
# Create a random generator for starting the ftp and for bottleneck link delays set rng [new RNG] $rng seed 0 # paratmers for random variables for delays set RVdly [new RandomVariable/Uniform] $RVdly set min_ 1 $RVdly set max_ 5 $RVdly use-rng $rng # 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 #We define two random parameters for each connections for {set i 1} {$i<=$NumbSrc} { incr i } { set startT($i) [expr [$RVstart value]] set dly($i) [expr [$RVdly value]] puts $param "dly($i) $dly($i) ms" puts $param "startT($i) $startT($i) sec" }
Journal Support for NS2 Projects: