0% found this document useful (0 votes)
14 views3 pages

Lab 1

Uploaded by

Maha Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Lab 1

Uploaded by

Maha Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Implement three nodes point – to – point network with duplex links


between them. Set the queue size, vary the bandwidth and find the
number of packets dropped.

set ns [ new Simulator ]

set tf [ open abc.tr w ]


$ns trace-all $tf

set nf [ open exp1.nam w ]


$ns namtrace-all $nf

# The below code is used to create the nodes.


set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

#This is used to give color to the packets.


$ns color 1 "red"
$ns color 2 "blue"
$n0 label "Source/udp0"
$n1 label "Source/udp1"
$n2 label "Router"
$n3 label "Destination/Null"

#Vary the below Bandwidth and see the number of packetsdropped.


$ns duplex-link $n0 $n2 100Mb 300ms DropTail
$ns duplex-link $n1 $n2 10Mb 300ms DropTail
$ns duplex-link $n2 $n3 1Mb 300ms DropTail

#The below code is used to set the queue size b/w the nodes
$ns set queue-limit $n0 $n2 1
$ns set queue-limit $n1 $n2 1
$ns set queue-limit $n2 $n3 1

#The below code is used to attach an UDP agent to n0, UDP


#agent to n1 and null agent to n3.
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0

set null3 [new Agent/Null]


$ns attach-agent $n3 $null3
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1

#The below code sets the udp0 packets to red and udp1
#packets to blue color
$udp0 set class_ 1
$udp1 set class_ 2

#The below code is used to connect the agents.


$ns connect $udp0 $null3
$ns connect $udp1 $null3

#The below code is used to set the packet size to 500


$cbr1 set packetSize_ 500Mb

#The below code is used to set the interval of the


packets, #i.e., Data rate of the packets. if the data rate is
high #then packets drops are high.

$cbr1 set interval_ 0.005


proc finish { } {
global ns nf tf
$ns flush-trace
exec nam exp1.nam &
close $tf
close $nf
exit 0
}
$ns at 0.1 "$cbr0 start"
$ns at 0.1 "$cbr1 start"
$ns at 10.0 "finish"
$ns run

awk script
BEGIN{
#include<stdio.h>
count=0;
}
{
if($1=="d") #d stands for the packets drops. count+
+
}
END{
printf("The Total no of Packets Dropped due to Congestion :%d\n\n", count)
}

You might also like