Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

sequence Command

#Create a simulator object set ns [new Simulator]

#Define different colors $ns color 1 Grey


for data flows (for NAM) $ns color 2 Red
$ns color 3 Green
$ns color 4 Black
#Open the NAM trace file set nf [open out.nam w]
$ns namtrace-all $nf

#Define a 'finish' proc finish {} {


procedure global ns nf
$ns flush-trace
#Close the NAM trace file
close $nf
#Execute NAM on the trace file
exec nam out.nam &
exit 0
}
#Create four 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]
set n6 [$ns node]

#Create links between the $ns duplex-link $n0 $n2 2Mb 10ms DropTail
nodes $ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 4Mb 10ms DropTail
$ns duplex-link $n4 $n2 2Mb 10ms DropTail
$ns duplex-link $n5 $n2 2Mb 10ms DropTail
$ns duplex-link $n3 $n6 1Mb 10ms DropTail
#Set Queue Size of link $ns queue-limit $n2 $n3 20
(n2-n3) to 10 $ns queue-limit $n3 $n6 20

#Monitor the queue for $ns duplex-link-op $n2 $n3 queuePos 0.5
link (n2-n3). (for NAM) $ns duplex-link-op $n3 $n6 queuePos 0.5

#Give node position (for $ns duplex-link-op $n0 $n2 orient right-down
NAM) $ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n4 $n2 orient left-down
$ns duplex-link-op $n5 $n2 orient left-up
$ns duplex-link-op $n3 $n6 orient right

#Setup a TCP1 connection


Set attach tcp1 in node n0 set tcp1 [new Agent/TCP]
<source> $tcp1 set class_ 2
$ns attach-agent $n0 $tcp1
Set sink1 node n3 set sink1 [new Agent/TCPSink]
$ns attach-agent $n3 $sink1
<sinkdestination of tcp>
Set connection tcp1 to $ns connect $tcp1 $sink1
sink1 $tcp1 set fid_ 1

#Setup a FTP1 over TCP set ftp1 [new Application/FTP]


connection n0 to n3 $ftp1 attach-agent $tcp1
$ftp1 set type_ FTP
#Setup a UDP connection
udp attach with n1
<source> set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1

Set null for n3 set nullA [new Agent/Null]


<nulldestination of udp> $ns attach-agent $n3 $nullA

Udp1 connection to nullA $ns connect $udp1 $nullA


$udp1 set fid_ 2

Setup a CBR over UDP set cbr1 [new Application/Traffic/CBR]


connection $cbr1 attach-agent $udp1
$cbr1 set type_ CBR
$cbr1 set packet_size_ 1000
$cbr1 set rate_ 1mb
$cbr1 set random_ false

#Schedule events for the $ns at 0.1 "$cbr1 start"


CBR and FTP agents $ns at 0.5 "$ftp1 start"
$ns at 4.5 "$ftp1 stop"
$ns at 5.0 "$cbr1 stop"

#Detach tcp and sink $ns at 5.1 "$ns detach-agent $n0 $tcp1 ; $ns
agents (not really detach-agent $n3 $sink1"
necessary)

puts "CBR packet size = [$cbr1 set


#Print CBR packet size and packet_size_]"
interval puts "CBR interval = [$cbr1 set interval_]"

#Call the finish procedure $ns at 5.2 "finish"


after 5.2 seconds

#Run the simulation $ns run

You might also like