What is Ns2 Code

Let us have a glance over this article which is about the description of source code based on network simulator 2.

Ns2 Code for Wireless Simulation

Here, we have described about the source code based on Ns2 in main simulation script file that is stored with the file extension .tcl.

  • Wireless node creation

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

            set networksimulatornode_($i) [$networksimulator node]    

      }

  • Dynamical change in wireless node location

      set now [$networksimulator now]

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

            set xxval [expr rand()*500]

            set yyval [expr rand()*500]  

           $networksimulator at $now “$networksimulatornode_($i) setdest $xxval $yyval $val(mobilitySpeed)”            

      }

 Ns2 Code for Wired Simulation

In addition, we have described about the network simulator code for wired simulation in the following.

  • Creation of trace and Nam objects

set nt [open test1.tr w]

$ns trace-all $nt

set nf [open test1.nam w]

$ns namtrace-all $nf

  • Network creation

set totalNodes 3

for {set i 0} {$i < $totalNodes} {incr i} {

set node_($i) [$ns node]

}

  • Duplex link creation

$ns duplex-link $node_($router) $node_($client) 2Mb 50ms DropTail

$ns duplex-link-op $node_($router) $node_($client) orient right

Moreover, you guys can reach us at any time to increase a whole heap about the source code based on network simulator 2.