How to Execute Ns2 Program in Ubuntu

         Let’s discuss about the required processes to execute the program based on network simulator 2 packages in Ubuntu.

Phase: I

          Firstly, we have to create the Ns2 main file in the project workspace location with the file extension .tcl.

  • Ns2 program code for random position allocation to nodes

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

     set xx [expr {int(rand()*$val(x))}]

     set yy [expr {int(rand()*$val(y))}]

     $node_($i) set X_ $xx

     $node_($i) set Y_ $yy

     set nodeXpos($i) $xx

     set nodeYpos($i) $yy

     set nodeZpos($i) 0.0                     

}

  • Ns2 program code for packet transmission

$ns attach-agent $node_($j) $udp

$ns attach-agent $node_($i) $null

$ns connect $udp $null

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set packetSize_ 512

$cbr set interval_ 0.1

Phase: II

        Through the implementation of below mentioned commands in window terminal, we have to execute the Ns2 main file program in Ubuntu.

cd /home/research/Desktop/ns2_program_simulation

./ns Program.tcl

Execution of Ns2 Program in Ubuntu

In addition, we have highlighted the result which is acquired through the execution of Ns2 program in Ubuntu.

Result of Ns2 Program in Ubuntu

          Eventually, we hope that you have acquired the appropriate steps to execute the Ns2 program over this article. Towards the end, we just wanted to say one thing that we are ready to assist you at any time.