KEMBAR78
Simulation of Congestion Control Algorithim | PDF | Transmission Control Protocol | Routing
0% found this document useful (0 votes)
35 views13 pages

Simulation of Congestion Control Algorithim

The document outlines the simulation of TCP/UDP performance and routing algorithms using the NS2 simulation tool. It details the creation of nodes, links, and agents for both TCP and UDP connections, as well as the implementation of congestion control and routing protocols. The simulation aims to analyze the performance of these protocols under various network conditions and configurations.

Uploaded by

aar55721
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)
35 views13 pages

Simulation of Congestion Control Algorithim

The document outlines the simulation of TCP/UDP performance and routing algorithms using the NS2 simulation tool. It details the creation of nodes, links, and agents for both TCP and UDP connections, as well as the implementation of congestion control and routing protocols. The simulation aims to analyze the performance of these protocols under various network conditions and configurations.

Uploaded by

aar55721
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/ 13

Simulation of congestion control algorithim:

# Create a simulator object

set ns [new Simulator]

# Create NAM and trace output files

set nf [open out.nam w]

$ns namtrace-all $nf

set tr [open out.tr w]

$ns trace-all $tr

# Define the finish procedure

proc finish {} {

global ns nf tr

$ns flush-trace

close $tr

close $nf

exec nam out.nam &

exit 0

# Create nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]


# Create links

$ns duplex-link $n0 $n1 10Mb 10ms DropTail

$ns duplex-link $n1 $n3 10Mb 10ms DropTail

$ns duplex-link $n2 $n1 10Mb 10ms DropTail

# Set link orientations for NAM visualization

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

$ns duplex-link-op $n1 $n3 orient right

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

# TCP connection from n0 to n3

set tcp [new Agent/TCP]

$ns attach-agent $n0 $tcp

set ftp [new Application/FTP]

$ftp attach-agent $tcp

set sink [new Agent/TCPSink]

$ns attach-agent $n3 $sink

$ns connect $tcp $sink

# UDP connection from n2 to n3

set udp [new Agent/UDP]

$ns attach-agent $n2 $udp

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp


set null [new Agent/Null]

$ns attach-agent $n3 $null

$ns connect $udp $null

# Simulate a link failure and recovery

$ns rtmodel-at 1.0 down $n1 $n3

$ns rtmodel-at 2.0 up $n1 $n3

# Use Link State routing protocol

$ns rtproto LS

# Start applications

$ns at 0.0 "$ftp start"

$ns at 0.0 "$cbr start"

# End simulation

$ns at 5.0 "finish"

# Run simulation

$ns run

Ex.No:8

Aim :

STUDY OF TCP/UDP PERFORMANCE USING SIMULATION TOOL


To study the performance of TCP/UDP using Simulation Tool (NS2)

Algorithm

1. Create 4 nodes (n0, n1, n2, n3).

2. The duplex links between n0 and n2, and n1 and n2 have 2 Mbps of
bandwidth and 10

ms of delay.

3. The duplex link between n2 and n3 has 1.7 Mbps of bandwidth and 20
ms of delay.

4. Each node uses a DropTail queue, of which the maximum size is 10.

5. A "tcp" agent is attached to n0, and a connection is established to a tcp


"sink" agent

attached to n3.

6. As default, the maximum size of a packet that a "tcp" agent can


generate is 1KByte.

7. A tcp "sink" agent generates and sends ACK packets to the sender (tcp
agent) and

frees the received packets.

8. A "udp" agent that is attached to n1 is connected to a "null" agent


attached to n3.

9. A "null" agent just frees the packets received.

10. A "ftp" and a "cbr" traffic generator are attached to "tcp" and "udp"
agents

respectively, and the "cbr" is configured to generate 1 KByte packets at


the rate of 1

Mbps.

11. The "cbr" is set to start at 0.1 sec and stop at 4.5 sec, and "ftp" is set
to start at 1.0 sec

and stop at 4.0 sec

Program

#Create a simulator object

set ns [new Simulator]

#Define different colors for data flows (for NAM)


$ns color 1 Blue

$ns color 2 Red

#Open the NAM trace file

set nf [open out.nam w]

$ns namtrace-all $nf

#Define a 'finish' procedure

proc finish {} {

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]

#Create links between the nodes

$ns duplex-link $n0 $n2 2Mb 10ms DropTail

$ns duplex-link $n1 $n2 2Mb 10ms DropTail

$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

#Set Queue Size of link (n2-n3) to 10

$ns queue-limit $n2 $n3 10

#Give node position (for NAM)

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

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


$ns duplex-link-op $n2 $n3 orient right

#Monitor the queue for link (n2-n3). (for NAM)

$ns duplex-link-op $n2 $n3 queuePos 0.5

#Setup a TCP connection

set tcp [new Agent/TCP]

$tcp set class_ 2

$ns attach-agent $n0 $tcp

set sink [new Agent/TCPSink]

$ns attach-agent $n3 $sink

$ns connect $tcp $sink

$tcp set fid_ 1

#Setup a FTP over TCP connection

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp set type_ FTP

#Setup a UDP connection

set udp [new Agent/UDP]

$ns attach-agent $n1 $udp

set null [new Agent/Null]

$ns attach-agent $n3 $null

$ns connect $udp $null

$udp set fid_ 2

#Setup a CBR over UDP connection

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set type_ CBR

$cbr set packet_size_ 1000

$cbr set rate_ 1mb

$cbr set random_ false


#Schedule events for the CBR and FTP agents

$ns at 0.1 "$cbr start"

$ns at 1.0 "$ftp start"

$ns at 4.0 "$ftp stop"

$ns at 4.5 "$cbr stop"

#Detach tcp and sink agents (not really necessary)

$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"

#Call the finish procedure after 5 seconds of simulation time

$ns at 5.0 "finish"

#Print CBR packet size and interval

puts "CBR packet size = [$cbr set packet_size_]"

puts "CBR interval = [$cbr set interval_]"

#Run the simulation

$ns run

Output

Result:

Thus studied the performance of TCP/UDP using Simulation Tool (NS2)

Ex.No.9a

Aim:

SIMULATION OF DISTANCE VECTOR ROUTING ALGORITHM

To perform Simulation of Distance Vector Routing algorithm.

ALGORITHM:

1. Create a simulator object

2. Define different colors for different data flows


3. Open a nam trace file and define finish procedure then close the trace
file, and execute

nam on trace file.

4. Create n number of nodes using for loop

5. Create duplex links between the nodes

6. Setup UDP Connection between n(0) and n(5)

7. Setup another UDP connection between n(1) and n(5)

8. Apply CBR Traffic over both UDP connections

9. Choose distance vector routing protocol to transmit data from sender to


receiver.

10. Schedule events and run the program.

Program (Distance Vector Protocol)

set ns [new Simulator]

set nr [open thro.tr w]

$ns trace-all $nr

set nf [open thro.nam w]

$ns namtrace-all $nf

proc finish { } {

global ns nr nf

$ns flush-trace

close $nf

close $nr

exec nam thro.nam &

exit 0

for { set i 0 } { $i < 12} { incr i 1 } {

set n($i) [$ns node]}

for {set i 0} {$i < 8} {incr i} {

$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }

$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail


$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail

$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail

$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail

$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail

$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail

set udp0 [new Agent/UDP]

$ns attach-agent $n(0) $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

set null0 [new Agent/Null]

$ns attach-agent $n(5) $null0

$ns connect $udp0 $null0

set udp1 [new Agent/UDP]

$ns attach-agent $n(1) $udp1

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 500

$cbr1 set interval_ 0.005

$cbr1 attach-agent $udp1

set null0 [new Agent/Null]

$ns attach-agent $n(5) $null0

$ns connect $udp1 $null0

$ns rtproto DV

$ns rtmodel-at 10.0 down $n(11) $n(5)

$ns rtmodel-at 15.0 down $n(7) $n(6)

$ns rtmodel-at 30.0 up $n(11) $n(5)

$ns rtmodel-at 20.0 up $n(7) $n(6)

$udp0 set fid_ 1


$udp1 set fid_ 2

$ns color 1 Red

$ns color 2 Green

$ns at 1.0 "$cbr0 start"

$ns at 2.0 "$cbr1 start"

$ns at 45 "finish"

$ns run
Ex.No.9b

Aim:

SIMULATION OF LINK STATE ROUTING ALGORITHM

To perform Simulation of Link State Routing algorithm.

Algorithm:

1. Create a simulator object

2. Define different colors for different data flows

3. Open a nam trace file and define finish procedure then close the
trace file, and execute nam

on trace file.

4. Create n number of nodes using for loop

5. Create duplex links between the nodes

6. Setup UDP Connection between n(0) and n(5)

7. Setup another UDP connection between n(1) and n(5)

8. Apply CBR Traffic over both UDP connections

9. Choose Link state routing protocol to transmit data from sender


to receiver.

10. Schedule events and run the program.

Program (Link State Protocol)

set ns [new Simulator]

set nr [open link.tr w]


$ns trace-all $nr

set nf [open link.nam w]

$ns namtrace-all $nf

proc finish { } {

global ns nr nf

$ns flush-trace

close $nf

close $nr

exec nam link.nam &

exit 0

for { set i 0 } { $i < 12} { incr i 1 } {

set n($i) [$ns node]}

for {set i 0} {$i < 8} {incr i} {

4931_Grace College of Engineering,Thoothukudi

$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }

$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail

$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail

$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail

$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail

$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail

$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail

set udp0 [new Agent/UDP]

$ns attach-agent $n(0) $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

set null0 [new Agent/Null]


$ns attach-agent $n(5) $null0

$ns connect $udp0 $null0

set udp1 [new Agent/UDP]

$ns attach-agent $n(1) $udp1

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 500

$cbr1 set interval_ 0.005

$cbr1 attach-agent $udp1

set null0 [new Agent/Null]

$ns attach-agent $n(5) $null0

$ns connect $udp1 $null0

$ns rtproto LS

$ns rtmodel-at 10.0 down $n(11) $n(5)

$ns rtmodel-at 15.0 down $n(7) $n(6)

$ns rtmodel-at 30.0 up $n(11) $n(5)

$ns rtmodel-at 20.0 up $n(7) $n(6)

$udp0 set fid_ 1

$udp1 set fid_ 2

$ns color 1 Red

$ns color 2 Green

$ns at 1.0 "$cbr0 start"

$ns at 2.0 "$cbr1 start"

$ns at 45 "finish"

$ns run

You might also like