0% found this document useful (0 votes)
111 views2 pages

NS2 Program

This document simulates a three node point-to-point network with duplex links between nodes. It varies the bandwidth and queue size to analyze network traffic and find the number of packets dropped with increased traffic. The simulation creates three nodes, connects them with duplex links of 1Mb bandwidth and 10ms delay, sets the queue size to 10, generates CBR traffic at 1Mb between nodes, and runs the simulation for 5 seconds. It finds that 8 packets were dropped.

Uploaded by

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

NS2 Program

This document simulates a three node point-to-point network with duplex links between nodes. It varies the bandwidth and queue size to analyze network traffic and find the number of packets dropped with increased traffic. The simulation creates three nodes, connects them with duplex links of 1Mb bandwidth and 10ms delay, sets the queue size to 10, generates CBR traffic at 1Mb between nodes, and runs the simulation for 5 seconds. It finds that 8 packets were dropped.

Uploaded by

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

Simulate a three nodes point � to � point network with duplex links between them.

Set the queue size and vary the bandwidth and find the number of packets dropped.
Outcome :
� Creation of nodes & generation of traffic in a network
� Analyze the network traffic by varying queue size and bandwidth.
� Find the number of packets dropped with increased network traffic.

#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]
$ns namtrace-all $namfile

#Finish Procedure
proc Finish {} {
global ns ntrace namfile

#Dump all the trace data and close the files


$ns flush-trace
close $ntrace
close $namfile

#Execute the nam animation file


exec nam prog1.nam &

#Show the number of packets dropped


exec echo "The number of packet drops is " &
exec grep -c "^d" prog1.tr &
exit 0
}

#Create 3 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]

#Label the nodes


$n0 label "TCP Source"
$n2 label "Sink"

#Set the color


$ns color 1 blue

#Create Links between nodes


#You need to modify the bandwidth to observe the variation in packet drop
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail

#Make the Link Orientation


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right

#Set Queue Size


#You can modify the queue length as well to observe the variation in packet drop
$ns queue-limit $n0 $n1 10
$ns queue-limit $n1 $n2 10

#Set up a Transport layer connection.


set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n2 $sink0
$ns connect $tcp0 $sink0

#Set up an Application layer Traffic


set cbr0 [new Application/Traffic/CBR]
$cbr0 set type_ CBR
$cbr0 set packetSize_ 100
$cbr0 set rate_ 1Mb
$cbr0 set random_ false
$cbr0 attach-agent $tcp0

$tcp0 set class_ 1

#Schedule Events
$ns at 0.0 "$cbr0 start"
$ns at 5.0 "Finish"

#Run the Simulation


$ns run

Output:
The number of Packets Dropped is 8

You might also like