Network simulation using NS2 wired simulation example with analysis

Dear Technocrats,

In this post I am giving the procedure to run and understand the analysis of tcl scripting for network simulation. If you have not installed NS2, first follow these steps for installation

After successful installation, next step is to write a tcl script and save it with a name. I saved it with the name simple.tcl

*****************************  simple.tcl**************************************

set ns [new Simulator]

set tracefile [open ABEStrace.tr w]
$ns trace-all $tracefile

set namfile [open ABESanimation.nam w]
$ns namtrace-all $namfile

set n0 [$ns node]
set n1 [$ns node]

$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link-op $n0 $n1 orient right

set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns attach-agent $n0 $tcp
$ns attach-agent $n1 $sink
$ns connect $tcp $sink

set ftp [ new Application/FTP]
$ftp attach-agent $tcp

$ns at 0.5 "$ftp start"
$ns at 4.0 "$ftp stop"

proc finish {} {
    global ns tracefile namfile
    exec nam ABESanimation.nam &
    $ns flush-trace
    close $tracefile
    close $namfile
}
$ns at 4.0 "finish"
$ns run

 *********************************End of file ************************************

Below are the steps to run wired simulation.
After successfully installing NS2 on your system, you just type

$ ns simple.tcl

The progam will run accordingly. As my program name is simple.tcl, so its running procedure is shown as:


This is the network animation output of the tcl script having one tcp connection in wired environment.

For anylysis of pdr and through put etc you need to look at trace file as a result of simulation outcome. Trace file looks like this:

+ 0.5 0 1 tcp 40 ------- 0 0.0 1.0 0 0
- 0.5 0 1 tcp 40 ------- 0 0.0 1.0 0 0
r 0.51032 0 1 tcp 40 ------- 0 0.0 1.0 0 0
+ 0.51032 1 0 ack 40 ------- 0 1.0 0.0 0 1
- 0.51032 1 0 ack 40 ------- 0 1.0 0.0 0 1
r 0.52064 1 0 ack 40 ------- 0 1.0 0.0 0 1
+ 0.52064 0 1 tcp 1040 ------- 0 0.0 1.0 1 2

These values are in row-column format, having its specific meaning. Now This file can be analyzed using awk. Awk is an post scripting language for analysis of trace files. The performance analysis( I did for pdr) of a simulated network in ns2 comes as shown:



No comments:

Post a Comment