Friday, April 17, 2015

Finding Round Trip Time in NS2

1. Create two ping agents and attach them to the nodes between   which the Round Trip Time is to be calculated.

              set p0 [new Agent/Ping]
             $ns attach-agent $n0 $p0
             set p1 [new Agent/Ping]
             $ns attach-agent $n2 $p1
             #Connect the two agents
             $ns connect $p0 $p1

2. When ping packet is received the recv{} procedure is called 
           Agent/Ping instproc recv {from rtt} {
           $self instvar node_
           puts "node [$node_ id] received ping answer from \
           $from with round-trip-time $rtt ms."
         }
     
     The member variable 'node_' of the base class 'Agent' is used to get the node id for the node to which the agent is attached and the variable rtt gives the Round Trip Time. 

No comments:

Post a Comment