NS2

From HPCC Wiki
Jump to navigation Jump to search

Running NS2 is a four step process.

Prepare a Tcl script for NS2 like the example (ex.tcl) shown below. This example has 2 nodes with 1 link and uses UDP agent with the CBR traffic generator.

set ns [new Simulator]
set tr [open trace.out w]
$ns trace-all $tr

proc finish {} {
        global ns tr
        $ns flush-trace
        close $tr
        exit 0
}

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

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

set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
$ns connect $udp0 $null0  

$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"

$ns run

Create a SLURM batch submit script like the one shown here:

#!/bin/bash
#SBATCH --partition production
#SBATCH --job-name NS2-job
#SBATCH --nodes=1
#SBATCH --ntasks=1


# You must explictly change to your working
# directory in SLURM

cd $HOME/my_NS2_wrk

/share/apps/ns2/ns-allinone-2.31/ns-2.31/ns ./ex.tcl

Submit the job with:

qsub submit

Graph the result. At the HPC Center, 'nam' files can be produced, but cannot be run because they require a graphical environment for execution. Trace Graph is a free network trace file analyzer developed for NS2 trace processing. Trace Graph can support any trace format if converted to its own or NS2 trace format. Supported NS2 trace file formats include:

wired,satellite,wireless,new trace,wired-wireless. 

For more information on Trace Graph look here [1].

Users graphing results in Trace Graph must use Linux with X window system and allow X11 forwarding.