Wan1-0.tcl setup: set p0 [new Agent/Ping] $ns attach-agent $n1 $p0 set p1 [new Agent/Ping] $ns attach-agent $n2 $p1 #Connect the two agents $ns connect $p0 $p1 #get the ping process going ... #$ns at 2 "$p0 send #can call startPingProcess which does a ping every interval #or have the recv schedule doPing .... startPingProcess $ns $p0 .5 Output: ping1.out and a single summary stat sent to standard out Standout out message: Ping: total sent: 397; total dropped: 11; loss rate: 2.770780856423174 This is created by the doPingStats tcl method that is called at the end of the simulation The main tcl script should do the following: $ns at $printtime "doPingStats" Ping1.out (format: timestamp RTT sequence#) 0.052683690666666672 52.7 1 Use getAvgPingRTT.script to obtain the mean RTT
Packet Flow
N2 ----------- n0 ------------ N1
Ping p1 (server) Ping p0 (client)
Tcl code
-recv if (hdr->ret == 1) sprintf(out, "%s recv %d %d %3.1f", tclobjectname recv nodeID, snum, timestamp tcl.eval(out); --recv if { [expr $lastPingReceived + 1] != $snum } { //loss, output to ping1.out: puts $pingtrace "[$ns now] 0 $lastPingReceived } if { [expr $lastPingReceived + 1] == $snum } { puts $pingtrace "[$ns now] $rtt $lastPingReceived" }
}; class PingAgent : public Agent { public: PingAgent(); virtual int command(int argc, const char*const* argv); virtual void recv(Packet*, Handler*); int lastSentSnum;
// Store the current time in the 'send_time' field hdr->send_time = Scheduler::instance().clock(); // Send the packet lastSentSnum++; hdr->snum = lastSentSnum; #ifdef TRACEPING printf("\nPING(%f):send snum : %d", Scheduler::instance().clock(),lastSentSnum); #endif send(pkt, 0); // return TCL_OK, so the calling function knows that // the command has been processed return (TCL_OK); Copyright 2010 Jim Martin }
$mypinger send $ns at [expr [$ns now] + $myinterval + [uniform .001 .009]] "doPing $ns $mypinger $myinterval" } $ns at 0.0 "doPing $ns $pinger $interval" }
10