Vous êtes sur la page 1sur 3

# This script is created by NSG2 beta1

# <http://wushoupong.googlepages.com/nsg>
#===================================
# Simulation parameters setup
#===================================
set val(stop) 40.0 ;# time of simulation end
set dropfile [open pdfg.out w]
puts $dropfile "Title = Number of Packets Dropped @ Link 0-2"
puts $dropfile "title_x = Time in Sec"
puts $dropfile "title_y = Number of Packets"
#===================================
#
Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
#===================================
#
Nodes Definition
#===================================
#Create 3 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
#===================================
#
Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 50Mb 10ms DropTail
$ns queue-limit $n0 $n1 5
$ns duplex-link $n0 $n2 50Mb 10ms DropTail
$ns queue-limit $n0 $n2 5
#===================================
#
Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]

$ns attach-agent $n1 $udp0


#set null0 [new Agent/Null]
set sink0 [new Agent/LossMonitor]
$ns attach-agent $n2 $sink0
$ns connect $udp0 $sink0
#===================================
#
Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 50.0Mb
$ns at 1.0 "record"
$ns at 2.0 "$cbr0 start"
$ns at 35.0 "$cbr0 stop"
set file1 [open qm.out w]
set qmon [$ns monitor-queue $n0 $n2 $file1 0.1]
[$ns link $n0 $n2] queue-sample-timeout
proc record {} {
global qmon sink0 dropfile
#Get an instance of the simulator
set ns [Simulator instance]
set pdrop [$qmon set pdrops_]
#Set the time after which the procedure should be called again
set time 0.5
#Get the current time
set now [$ns now]
#write the drop values in the file for graph
puts $dropfile "$now $pdrop"
#Reset the bytes_ values on the traffic sinks
$qmon set pdrops_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record"
}
#===================================
#
Termination
#===================================
#Define a 'finish' procedure
proc finish {} {

global ns tracefile namfile dropfile


$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
close $dropfile
exec /home/vadiraja/Downloads/XGraph4.30_linux64/bin/xgraph pdfg.out &
exit 0
}
$ns at $val(stop) "finish"
$ns run

Vous aimerez peut-être aussi