Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
# <http://wushoupong.googlepages.com/nsg>
#===================================
# Simulation parameters setup
#===================================
set val(stop) 40 ;# time of simulation end
#===================================
#
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
set file2 [open ptcpfg.out w]
puts $file2 "Title = Number of TCP Packets Sent"
puts $file2 "title_x = Time in Sec"
puts $file2 "title_y = Number of Packets"
set file3 [open pudpfg.out w]
puts $file3 "Title = Number of UDP Packets Sent"
puts $file3 "title_x = Time in Sec"
puts $file3 "title_y = Number of Packets"
#===================================
#
Nodes Definition
#===================================
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#===================================
#
Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 20Mb 10ms DropTail
$ns queue-limit $n0 $n1 10
$ns duplex-link $n0 $n2 20Mb 10ms DropTail
$ns queue-limit $n0 $n2 10
$ns duplex-link $n0 $n3 20Mb 10ms DropTail
proc record {} {
global qmon1 qmon2 qmon3 file2 file3
#Get an instance of the simulator
set ns [Simulator instance]
set parr10 [$qmon1 set parrivals_]
//set parr20 [$qmon2 set parrivals_]
set parr30 [$qmon3 set parrivals_]
#Set the time after which the procedure should be called again
set time 0.5
#Get the current time
set now [$ns now]
#write it to the files
puts $file2 "$now $parr10"
puts $file3 "$now $parr30"
#Reset the bytes_ values on the traffic sinks
$qmon1 set parrivals_ 0
$qmon2 set parrivals_ 0
$qmon3 set parrivals_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record"
}
#===================================
#
Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile file2 file3
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
close $file2
close $file3
exec /home/vadiraja/Downloads/XGraph4.30_linux64/bin/xgraph ptcpfg.out &
exec /home/vadiraja/Downloads/XGraph4.30_linux64/bin/xgraph pudpfg.out &
exit 0
}
$ns at $val(stop) "finish"
$ns run