Sei sulla pagina 1di 3

# This script is created by NSG2 beta1

# <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

$ns queue-limit $n0 $n3 10


#===================================
#
Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n1 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n2 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n3 $udp0
set sink0 [new Agent/LossMonitor]
$ns attach-agent $n2 $sink0
$ns connect $udp0 $sink0
#===================================
#
Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$ns at 1.0 "record"
$ns at 2.0 "$ftp0 start"
$ns at 4.0 "$cbr0 start"
$ns at 36.0 "$ftp0 stop"
$ns at 38.0 "$cbr0 stop"
set file4 [open qm10.out w]
set qmon1 [$ns monitor-queue $n1 $n0 $file4 0.1]
[$ns link $n1 $n0] queue-sample-timeout
set file5 [open qm02.out w]
set qmon2 [$ns monitor-queue $n0 $n2 $file5 0.1]
[$ns link $n0 $n2] queue-sample-timeout
set file6 [open qm30.out w]
set qmon3 [$ns monitor-queue $n3 $n0 $file6 0.1]
[$ns link $n3 $n0] queue-sample-timeout

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

Potrebbero piacerti anche