Beruflich Dokumente
Kultur Dokumente
# To create simulator
set ns [ new Simulator ]
set trf [ open 1.tr w ]
$ns trace-all $trf
set namf [ open 1.nam w ]
$ns namtrace-all $namf
#The below code sets the udp0 packets to red and udp1 packets to blue
color
$udp0 set class_ 1
$udp1 set class_ 2
proc finish {} {
global ns namf trf
$ns flush-trace
exec nam 1.nam &
close $trf
close $namf
exit 0
}
# to create simulator
set ns [new Simulator]
set trf [open 2.tr w]
$ns trace-all $trf
set namf [open 2.nam w]
$ns namtrace-all $namf
# The below code is used to set the color and name's to the #nodes.
$ns color 1 "red"
$ns color 2 "green"
# To provide link
$ns duplex-link $n0 $n2 10Mb 10ms DropTail
$ns duplex-link $n1 $n2 10Kb 100ms DropTail
$ns duplex-link $n2 $n3 10Kb 100ms DropTail
# The below code is used assign TCP and UDP agents and traffic
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
#The below code is used to set the packet size of ftp and udp.
$ftp0 set packetSize_ 200
$ftp0 set interval_ 0.01
$cbr1 set packetSize_ 300
$cbr1 set interval_ 0.001
proc finish { } {
global ns namf trf
$ns flush-trace
exec nam 2.nam &
close $namf
close $trf
exit 0
}
# to create simulator
set ns [new Simulator]
set trf [open 3.tr w]
$ns trace-all $trf
set naf [open 3.nam w]
$ns namtrace-all $naf
# To provide link
$ns duplex-link $n0 $n2 5Mb 10ms DropTail
$ns duplex-link $n1 $n2 10Mb 10ms DropTail
$ns duplex-link $n2 $n3 15Mb 10ms DropTail
#The below code is used to connect the tcp agents & sink.
$ns connect $tcp0 $sink4
$ns connect $tcp1 $sink3
proc finish { } {
global ns naf trf
exec nam 3.nam &
close $naf
close $trf
exit 0 }
$ns at 0.3 "$ftp0 start"
$ns at 0.6 "$telnet1 start"
$ns at 10 "finish"
$ns run
PROGRAM 4:
# To create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#The below code is used to set the color and name's to the #nodes
$n0 label "Ping0"
$n1 label "Ping1"
$n2 label "Router"
$n3 label "Ping3"
$n4 label "Ping4"
$n5 label "Ping5"
#The below function is executed when the ping agent receives #a reply
from the destination
Agent/Ping instproc recv {from rtt} { $self instvar node_
puts " The node [$node_ id] received an reply from $from with round
trip time of $rtt"
}
proc finish {} {
global ns naf trf
exec nam 4.nam &
$ns flush-trace
close $trf
close $naf
exit 0
}
# to start sending the ping packets
$ns at 0.2 "$ping0 send"
$ns at 0.4 "$ping0 send"
$ns at 0.6 "$ping0 send"
$ns at 0.8 "$ping0 send"
$ns at 1.0 "finish"
$ns run
PROGRAM 5:
#create Simulator
set ns [new Simulator]
#Finish Procedure
proc Finish {} {
global ns ntrace namfile
#Setup queue between n(2) and n(3) and monitor the queue
$ns queue-limit $n(2) $n(3) 20
$ns simplex-link-op $n(2) $n(3) queuePos 0.5
#Set error model on link n(2) and n(3) and insert the error model
set loss_module [new ErrorModel]
$loss_module ranvar [new RandomVariable/Uniform]
$loss_module drop-target [new Agent/Null]
$ns lossmodel $loss_module $n(2) $n(3)
#Schedule events
$ns at 0.1 "$cbr0 start"
$ns at 1.0 "$ftp0 start"
$ns at 124.0 "$ftp0 stop"
$ns at 124.5 "$cbr0 stop"
$ns at 125.0 "Finish"
#Run Simulation
$ns run
PROGRAM 6:
# Generation of movements
$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 19.0 "$node_(2) setdest 480.0 300.0 5.0"
$ns run