Saturday, August 3, 2013

How To Execute The NAM File in NS-2


How To Execute The NAM File in NS-2

Before Executing the NAM File we need to run & execute the tcl file for your program

Step 1:

root@AMDI ns-allinone-2.28]# vi first.tcl

Note: Here vi  is Text Editor and Tcl is Script language for NS2

After Opening text Editor Type a basic program I started a small program called My First Program in NS2

set ns [new Simulator]
$ns at 1 "puts \" My first program in NS2 \""
$ns at 1.5 "exit"

Press Esc and Press WQ and Finally run the program

$ns run

Execute the script using the ns command.

[root@AMDI ns-allinone-2.28]# ns first.tcl

After Executing the TCL File then we can execute the NAM Output

Step 2:

starting nam Execution part with the  following command 

[root@AMDI ns-allinone-2.28]# nam first.tcl

where ‘first.tcl’ is the name of a nam trace file that was generated by ns,

Sample Output for NAM like this :

How To Execute The NAM File in NS-2

Example Code

set ns [new Simulator] -- create a simulator object
set nf [open out.nam w] -- nam trace
$ns namtrace-all $nf
proc finish {} {
        global ns nf
        $ns flush-trace
        close $nf
        exec nam out.nam &
        exit 0
}
$ns at 3.0 "finish"
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns run

What is NAM in NS-2

NAM provides a visual interpretation of the network topology created. The application was developed as part of the VINT project. Its features are as follows. Figure  displays the NAM application and its components.
  • · Provides a visual interpretation of the network created
  • · Can be executed directly from a Tcl script
  • · Controls include play, stop ff, rw, pause, a display speed controller and a packet monitor facility.
  • · Presents information such as throughput, number packets on each link.
  • · Provides a drag and drop interface for creating topologies.
What is NAM in NS-2

How To Execute The NAM File in NS-2


No comments:

Post a Comment

Linux Tips and tricks,Online Linux Helpers