11. Polling the LossMonitor proc record {sink} { global fthrput fpcklost #Get an instance of the simulator set ns [Simulator instance] #Set the time for polling set time 0.25 #How many bytes have been received by the traffic set bw1 [$sink set bytes_] set lpkts [$sink set nlost_] set now [$ns now] puts $fthrput "$now [expr $bw1/$time*8]" puts $fpcklost "$now $lpkts" #Reset the bytes_ values on the traffic sinks $sink set bytes_ 0 $sink set nlost_ 0 #Re-schedule the record function $ns at [expr $now+$time] "record sink" }
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23. We can visualize the trace/nam files Network animator screenshots of an ad-hoc network simulation (courtesy of S. Shah)