#Create Simulator
set ns [new Simulator]
#Open Trace file and NAM file
set ntrace [open prog1.tr w]
$ns trace-all $ntrace
set namfile [open prog1.nam w] CN Program
$ns namtrace-all $namfile set ns [new Simulator]
#Finish Procedure set nf [open lab1.nam w]
proc Finish {} { $ns namtrace-all $nf
global ns ntrace namfile set tf [open lab1.tr w]
#Dump all the trace data and close the $ns trace-all $tf
files proc finish { } {
$ns flush-trace global ns nf tf
close $ntrace $ns flush-trace
close $namfile close $nf
#Execute the nam animation file close $tf
exec nam prog1.nam & exec nam lab1.nam &
#Show the number of packets dropped exit 0
exec echo "The number of packet drops }
is " & set n0 [$ns node]
exec grep -c "^d" prog1.tr & set n1 [$ns node]
exit 0 set n2 [$ns node]
} set n3 [$ns node]
#Create 3 nodes $ns duplex-link $n0 $n2 200Mb
set n0 [$ns node] 10ms DropTail
set n1 [$ns node] $ns duplex-link $n1 $n2 100Mb 5ms
set n2 [$ns node] DropTail
#Label the nodes $ns duplex-link $n2 $n3 1Mb
$n0 label "TCP Source" 1000ms DropTail
$n2 label "Sink" $ns queue-limit $n0 $n2 10
#Set the color $ns queue-limit $n1 $n2 10
$ns color 1 blue set udp0 [new Agent/UDP]
#Create Links between nodes $ns attach-agent $n0 $udp0
#You need to modify the bandwidth to set cbr0 [new
observe the variation in packet drop Application/Traffic/CBR]
$ns duplex-link $n0 $n1 1Mb 10ms $cbr0 set packetSize_ 500
DropTail $cbr0 set interval_ 0.005
$ns duplex-link $n1 $n2 1Mb 10ms $cbr0 attach-agent $udp0
DropTail set udp1 [new Agent/UDP]
#Make the Link Orientation $ns attach-agent $n1 $udp1
$ns duplex-link-op $n0 $n1 orient right set cbr1 [new
$ns duplex-link-op $n1 $n2 orient right Application/Traffic/CBR]
#Set Queue Size $cbr1 attach-agent $udp1
#You can modify the queue length as set udp2 [new Agent/UDP]
well to observe the variation in packet $ns attach-agent $n2 $udp2
drop set cbr2 [new
$ns queue-limit $n0 $n1 10 Application/Traffic/CBR]
$ns queue-limit $n1 $n2 10 $cbr2 attach-agent $udp2
#Set up a Transport layer connection. set null0 [new Agent/Null]
set tcp0 [new Agent/TCP] $ns attach-agent $n3 $null0
$ns attach-agent $n0 $tcp0 $ns connect $udp0 $null0
set sink0 [new Agent/TCPSink] $ns connect $udp1 $null0
$ns attach-agent $n2 $sink0 $ns at 0.1 "$cbr0 start"
$ns connect $tcp0 $sink0 $ns at 0.2 "$cbr1 start"
#Set up an Application layer Traffic $ns at 1.0 "finish"
set cbr0 [new Application/Traffic/CBR] $ns run
$cbr0 set type_ CBR BEGIN
$cbr0 set packetSize_ 100 {c
$cbr0 set rate_ 1Mb =0;
$cbr0 set random_ false }{i
$cbr0 attach-agent $tcp0 f($1=="d")
$tcp0 set class_ 1 {c
#Schedule Events ++;
$ns at 0.0 "$cbr0 start" printf("%s\t%s\n",$5,$11);
$ns at 5.0 "Finish" }}E
#Run the Simulation ND{ printf("The number of packets
$ns run dropped = %d\n",c);
}