Implement a 3 node point to point duplex link Set queue size, vary the bandwidth and note the
no. of packets received and dropped.
#create the simulator
set ns [new Simulator]
set nf [open prog1.nam w]
$ns namtrace-all $nf
set nd [open prog1.tr w]
$ns trace-all $nd
proc finish { } {
global ns nf nd
$ns flush-trace
close $nf
close $nd
exec nam prog1.nam &
exec awk -f 3n.awk prog1.tr &
exit 0
}
# create 3 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 756Kb 10ms DropTail
$ns queue-limit $n1 $n2 5
# Set up UDP Connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set sink [new Agent/Null]
$ns attach-agent $n2 $sink
$ns connect $udp0 $sink
$ns at 0.2 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"
$ns run
—-----------------------------------------------------AWK FILE—-------------------------------------
BEGIN{
dcount=0;
rcount=0;
}
{
event =$1;
if(event =="d")
{
dcount++
}
if(event =="r")
{
rcount++
}
}
END{
printf("The no.of packets dropped:%d\n", dcount)
printf("The no.of packets dropped:%d\n", rcount)
}