[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ns] Using integrator with flow monitoring
Hi NS-USERS,
I am trying to use an integrator to obtain the value "sum_" in my
simulation. The problem is I am not certain if my syntax is correct or not,
because the value I get for sum_ is zero, which should not be the case. I
have included the script below, but I'll briefly introduce the simulation
first.
I am simulating a lan with poisson agents attached to 3 of the 5 nodes, and
a sink node connected to the 5th lannode using a duplex link. I am
attempting to calculate the delay using the sum_ obtained from
[get-pkts-integrator], but the value I get is incorrect.
Is there something I am missing?
Please provide any advice you can as I am approaching a deadline and I need
to get this fixed.
Thanks
ID
Script---------
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
set f [open cslan.out w]
$ns trace-all $f
# Color Packets for Nam
$ns color 1 Blue
$ns color 2 Red
#$ns color 3 Yellow
#$ns color 4 Green
#$ns color 5 Black
# Set random number generator seed
set seed 1234567
ns-random $seed
# Simulation end time
set startDump 0.0
set intDump 0.2
set endTime 10.0
# Set some physical parameters
set NumNodes 5;
set LinkRate 10e6; #Bps
set LinkDelay 1e-6;
set PacketSize 1000; #bits
set normalizedArrivalrate 0.9
set BitsPerByte 8
#Create the nodes
for {set i 0} {$i < $NumNodes} {incr i} {
set node($i) [$ns node]
lappend nodelist $node($i)
}
#Create srcnode and sinknode
set sinknode [$ns node]
#Create LAN
set lan_ [$ns make-lan $nodelist $LinkRate $LinkDelay LL Queue/DropTail
Mac/802_3 Channel]
#Create a duplex link between sinknode and lannode node(4)
$ns duplex-link $sinknode $node(4) $LinkRate $LinkDelay DropTail
$ns duplex-link-op $sinknode $node(4) orient left
$ns duplex-link-op $sinknode $node(4) queuePos 0.5
# Create agents for all the nodes
for {set i 0} {$i < $NumNodes} {incr i} {
set src($i) [new Agent/UDP]
set sink($i) [new Agent/Null]
#$src($i) set class_ [expr $i + 1] ;#Marks Flow id
$ns attach-agent $node($i) $src($i)
$ns attach-agent $sinknode $sink($i)
$ns connect $src($i) $sink($i)
}
$src(0) set class_ 1
$src(1) set class_ 2
set pps [expr $normalizedArrivalrate /$NumNodes * $LinkRate / $PacketSize]
puts [expr ${PacketSize} / $BitsPerByte]
puts [expr $normalizedArrivalrate /$NumNodes * $LinkRate / $PacketSize]
# Create Poisson arrivals at source nodes
for {set i 0} {$i < $NumNodes} {incr i} {
set e($i) [new Application/Traffic/Poisson]
$e($i) attach-agent $src($i)
$e($i) set packetSize_ [expr ${PacketSize} / $BitsPerByte]
$e($i) set meanArrivalrate_ [expr $normalizedArrivalrate /$NumNodes *
$LinkRate / $PacketSize]
}
#-----------------Flow Monitoring-----
set flow_file [open cs_flow.out w]; # create file for monitoring flows
set fmon [$ns makeflowmon Fid]
$fmon attach $flow_file
set llink1 [$ns link $node(4) $sinknode]
$ns attach-fmon $llink1 $fmon 0; # from Source to lanNode 1
#$fmon dump ;#dumps all traces to flow file
set pktsInt_ [new Integrator]
$fmon set-pkts-integrator $pktsInt_
set finteg [$fmon get-pkts-integrator]
proc flowdump { link flwmon ffile interval } {
global ns pps finteg
$ns at [expr [$ns now] + $interval] "flowdump $link $flwmon $ffile
$interval"
$flwmon dump
puts "[$finteg set sum_]"
set delay [expr [$finteg set sum_] / $interval / $pps]
#set delay [expr [$integ set sum_] / [[$link link] set bandwidth_]]
#puts $ffile [format "FID= %d PKTarrv= %d" [$fm set flowid_] [$fm set
parrivals_]]
puts "[$ns now] delay = $delay"
}
#Define a 'finish' procedure
proc finish {} {
global ns nf f flow_file
$ns flush-trace
#Close the trace file
close $nf
close $f
close $flow_file
#Execute nam on the trace file
exec nam out.nam &
exit 0
}
$ns at $startDump "flowdump $llink1 $fmon $flow_file $intDump"
# Schedule the start of traffic flow
for {set i 0} {$i < [expr $NumNodes-2]} {incr i} {
$ns at 0.0 "$e($i) start"
$ns at $endTime "$e($i) stop"
}
#$ns at 0.0 "$e start"
#$ns at $endTime "$e stop"
#Call the finish procedure after 10 seconds of simulation time
$ns at $endTime "finish"
#Run the simulation
$ns run
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp