[ns] Agent/LossMonitor on node gives no reading?
Mark C.B.
cb.mark at gmail.com
Thu Jan 24 05:28:54 PST 2008
Hi First of all apologies am sending this again, the lovely people at the
domain company have broken my domain name.
If you replied before thanks and would you be able to reply again. If anyone
can help please as I still cannot solve it.
Thanks
Hi would anyone be able to help me, i think i have created a Sink
Agent/LossMonitor monitor the nodes however the results come back as always
0.
If anyone can see where i have gone wrong I would be extremely grateful if
you could show me how/where I went wrong.
Thanking you,
Mark
#Create a simulator object
set ns [new Simulator]
#Open a trace file
set f0 [open out0.tr w]
set f1 [open out1.tr w]
set f2 [open out2.tr w]
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf f0 f1 f2
$ns flush-trace
close $nf
close $f0
close $f1
close $f2
#Call nam to display the results
puts "running nam..."
exec nam -f dynamic-nam.conf out.nam &
#Call xgraph to display the results
puts "running xgraph..."
exec xgraph out0.tr out1.tr out2.tr -geometry 800x400 &
exit 0
}
#Define a procedure which periodically records the bandwidth received by the
#three traffic sinks sink0/1/2 and writes it to the three files f0/1/2.
proc record {} {
global sink0 sink1 sink2 f0 f1 f2
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.1
#How many bytes have been received by the traffic sinks?
set bw0 [$sink0 set bytes_]
set bw1 [$sink1 set bytes_]
set bw2 [$sink2 set bytes_]
#Get the current time
set now [$ns now]
#Calculate the bandwidth (in MBit/s) and write it to the files
puts $f0 "$now [expr $bw0/$time*8/1000000]"
puts $f1 "$now [expr $bw1/$time*8/1000000]"
puts $f2 "$now [expr $bw2/$time*8/1000000]"
puts "$now $bw0"
#Reset the bytes_ values on the traffic sinks
$sink0 set bytes_ 0
$sink1 set bytes_ 0
$sink2 set bytes_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record"
}
#Create three nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
#Connect the nodes with two links
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
#Define a 'recv' function for the class 'Agent/Ping'
Agent/Ping instproc recv {from rtt} {
$self instvar node_
#puts "node [$node_ id] received ping answer from \
# $from with round-trip-time $rtt ms."
}
#Create three traffic sinks and attach them to the node n4
set sink0 [new Agent/LossMonitor]
set sink1 [new Agent/LossMonitor]
set sink2 [new Agent/LossMonitor]
$ns attach-agent $n0 $sink0
$ns attach-agent $n1 $sink1
$ns attach-agent $n2 $sink2
#Create two ping agents and attach them to the nodes n0 and n2
Agent/Ping set packetSize_ 400
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
#Schedule events
$ns at 0.0 "record"
$ns at 0.2 "$p0 send"
$ns at 0.4 "$p1 send"
$ns at 0.6 "$p0 send"
$ns at 0.6 "$p1 send"
$ns at 1.0 "finish"
#Run the simulation
$ns run
More information about the Ns-users
mailing list