How do I Run an Ns2 Program

Guys, are you trying to know about the process of running the program based on network simulator 2 in Ubuntu? Then, no worries you are at the right platform. Now take a look at this article to know the required processes.

Ns2 Program Code in Ubuntu

As the first process, we have to write the Ns2 program code in the main simulation script file as mentioned below.

  • Node creation

      for {set i 0} {$i < $val(nn) } { incr i } {

            set node_($i) [$ns node]    


  • Changing node location dynamically

      global ns val node_

      set time 1.0

      set now [$ns now]

      for {set i 0} {$i< $val(nn)-1 } {incr i} {

            set xx [expr rand()*1000]

            set yy [expr rand()*1000]     

           $ns at $now “$node_($i) setdest $xx $yy $val(Speed)”                    


Run Ns2 Program in Ubuntu

To run the Ns2 program in Ubuntu, we have to implement the commands that are highlighted in the following.

cd /home/research/Desktop/NS2_program

./ns program.tcl

Run Ns2 Program in Ubuntu

As the final note, we have highlighted the result gained through running the Ns2 program.

To this end, we hope that we have provided the required processes run network simulator 2 program. Ping us to aid more.