[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] Running multiple simulations



Hi all,
For weeks now I have been trying to run the tcl script shown below but I get 
the wrong results.
I am trying to obtain the delay resulting from a poisson arrival process 
between 2 nodes using various arrival rates.  I used a 'for' loop in trying 
to get the delay for each arrival rate.  My result came out as follows:

For AR 0.1, 100 delay = 0.054190325330596215
For AR 0.2, 100 delay = 0.054190325330596215
For AR 0.3, 100 delay = 0.054190325330596215
For AR 0.4, 100 delay = 0.054190325330596215
For AR 0.5, 100 delay = 0.054190325330596215
For AR 0.6, 100 delay = 0.054190325330596215
For AR 0.7, 100 delay = 0.054190325330596215
For AR 0.8, 100 delay = 0.054190325330596215
For AR 0.9, 100 delay = 0.054190325330596215

As you can see, all the results are the same which is obviously wrong.  
Please take a look at the tcl script and advise me on the best way to go 
about this.
Thanks

TCL Script:
####### Poisson simulation - using multiple Arrival Rates ###############

#Create a simulator object
set ns [new Simulator]

#Open the trace file
set nf [open poisson3.out w]
$ns trace-all $nf

#Define a 'finish' procedure
proc finish {} {
        global ns nf
        $ns flush-trace
	#Close the trace file
        close $nf
        exit 0
}

#Define finish procedure to flush traces
proc finish1 {} {
        global ns nf
        $ns flush-trace
	#Close the trace file
        #close $nf
        #exit 0
}

# Define the pseudo-random number-generator (PRNG)
# Set random number generator seed, seeds may be changed, i.e. student nos.
set seed(0) 1234567
set seed(1) 5259140
set seed(2) 9541978
set seed(3) 5551212
set seed(4) 0
set MAX_AR 9

ns-random $seed(0)


# Simulation end time
set endTime 100.0

# Set some physical parameters
set LinkRate 1e6; #Bps
set PacketSize 1000; #bits
#set normalizedArrivalrate 0.2
set BitsPerByte 8

#-----------Multiple Arrival Rates--------
set normalizedArrivalrate(0) 0.1
set normalizedArrivalrate(1) 0.2
set normalizedArrivalrate(2) 0.3
set normalizedArrivalrate(3) 0.4
set normalizedArrivalrate(4) 0.5
set normalizedArrivalrate(5) 0.6
set normalizedArrivalrate(6) 0.7
set normalizedArrivalrate(7) 0.8
set normalizedArrivalrate(8) 0.9


#Create two nodes
set n0 [$ns node]
set n1 [$ns node]

#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 $LinkRate 0ms DropTail

set src [new Agent/UDP]
set sink [new Agent/UDP]

$ns attach-agent $n0 $src
$ns attach-agent $n1 $sink

$ns connect $src $sink

proc dump { link interval ar } {
        global ns integ pps
        $ns at [expr [$ns now] + $interval] "dump $link $interval"
        set delay [expr [$integ set sum_] / $interval / $pps ]
#        set delay [expr [$integ set sum_] / [[$link link] set bandwidth_]]
        puts "For AR $ar, [$ns now] delay = $delay"
}

for {set i 0} {$i < $MAX_AR} {incr i} {

	set pps [expr $normalizedArrivalrate($i) * $LinkRate / $PacketSize]
	set e [new Application/Traffic/Poisson]
	$e attach-agent $src

	$e set packetSize_ [expr ${PacketSize} / $BitsPerByte]
	$e set meanArrivalrate_ [expr $normalizedArrivalrate($i) * $LinkRate / 
$PacketSize]

	set qmon [$ns monitor-queue $n0 $n1 ""]
	set integ [$qmon get-pkts-integrator]

	$ns at 0.0 "$e start"

	if { $i == 8 } {
		$ns at $endTime "dump [$ns link $n0 $n1] $endTime 
$normalizedArrivalrate($i)"
		$ns at $endTime "$e stop"
		$ns at $endTime "finish"
	} else {
		$ns at $endTime "dump [$ns link $n0 $n1] $endTime 
$normalizedArrivalrate($i)"
		$ns at $endTime "$e stop"
		#$ns at $endTime "$n0 reset"
		#$ns at $endTime "$qmon reset"
		#$ns at $endTime "$integ reset"
		$ns at $endTime "finish1"
	      }

}

#Run the simulation
$ns run
-------------




-------------------------------
Idara D. Uko
Electrical Engineering & MGT V
McMaster University
Hamilton, ON.
-------------------------------

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp