0% found this document useful (0 votes)
112 views6 pages

Computer Networks Lab DA 3 - TCP and UDP Protcol Simulation With TCL Aryaman Kolhe 20BBS0122

The document summarizes simulations of computer networks using TCP and UDP protocols in NS2: 1) A 4-node point-to-point network is simulated with TCP between nodes 0-3 and UDP between nodes 1-3. The number of packets sent by TCP and UDP are determined by changing parameters. 2) A 4-node ring network is simulated with applications over TCP from nodes 0-2 and UDP from nodes 1-0 by varying parameters. Packet transmissions are visualized between the times specified for each simulation.

Uploaded by

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

Computer Networks Lab DA 3 - TCP and UDP Protcol Simulation With TCL Aryaman Kolhe 20BBS0122

The document summarizes simulations of computer networks using TCP and UDP protocols in NS2: 1) A 4-node point-to-point network is simulated with TCP between nodes 0-3 and UDP between nodes 1-3. The number of packets sent by TCP and UDP are determined by changing parameters. 2) A 4-node ring network is simulated with applications over TCP from nodes 0-2 and UDP from nodes 1-0 by varying parameters. Packet transmissions are visualized between the times specified for each simulation.

Uploaded by

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

Computer Networks Lab DA 3 – TCP and UDP protcol simulation with TCL

Aryaman Kolhe
20BBS0122
Question 1

Simulate a four node point-to-point network with the links connected as follows: n0-n2, nl
n2 and n2-n3. Apply TCP agent between n0-n3 and UDP between nl-n3. Apply relevant
applications over TCP and UDP agents changing the parameter and determine the number of
packets sent by TCP/ UDP.

Code

set ns [new Simulator]


# simulator object gets instantiated

set tracefile [open out.tr w]


# namtrace - network animator. tracefile - info in file (written with awk script)

$ns trace-all $tracefile

# Opening namtrace file


set nf [open out.nam w]
# w - write mode
$ns namtrace-all $nf

set n0 [$ns node]


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

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


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

### Transport Layer


set tcp1 [new Agent/ TCP]
$ns attach-agent $n0 $tcp1
set tcpsink1 [new Agent/ TCPSink]
$ns attach-agent $n3 $tcpsink1
$ns connect $tcp1 $tcpsink1

set udp1 [new Agent/ UDP]


$ns attach-agent $n1 $udp1
set udpsink1 [new Agent/ Null]
$ns attach-agent $n3 $udpsink1
$ns connect $udp1 $udpsink1

$ns color 1 Blue


$tcp1 set fid_ 1

### Application Layer


set ftp [new Application/ FTP]
$ftp attach-agent $tcp1

set cbr [new Application/ Traffic/ CBR]


$cbr attach-agent $udp1

# connecting upper to lower layer

proc finish {} {
# follow this spacing
global ns tracefile nf
$ns flush-trace
# flushes the previous outputs ?
close $nf
close $tracefile
exec nam out.nam &
exit 0
}

$ns at 1.0 "$ftp start"


$ns at 4.0 "$ftp stop"

$ns at 1.0 "$cbr start"


$ns at 4.0 "$cbr stop"

# Start time = 1, stop at 4 and finish procedure at 5 seconds

# ns2 is an event simulator, where events can be timed


$ns at 5.0 "finish"

$ns run
# to execute the program

Output
The simulation starts at 0 seconds. From 1 second onwards, packets are sent from node 0 to
node 3 (blue) via the TCP protocol. Simultaneously, from 1 second onwards, packets are
sent from node 1 to node 3 (black).
At 1.1 seconds – (Packets are starting to be transferred)

The blue spec in the above image denotes the acknowledgement sent back to node 0 (via
TCP).

We also see some packet loss since they are colliding at node 2.
Question 2

Simulate a four node ring network. Apply relevant applications over TCP and UDP
agents changing the parameter.

Code

# What we are doing. From 1.0 to 2.5 seconds, we are transferring packets from node 0 to
node 2 via the TCP protocol.
# From 2.6 to 4.0 seconds, we are transferring packets from node 1 to node 0 via the UDP
protocol.

set ns [new Simulator]


# simulator object gets instantiated

set tracefile [open out.tr w]


# namtrace - network animator. tracefile - info in file (written with awk script)

$ns trace-all $tracefile

# Opening namtrace file


set nf [open out.nam w]
# w - write mode
$ns namtrace-all $nf

set n0 [$ns node]


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

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


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

### Transport Layer


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

set udp1 [new Agent/ UDP]


$ns attach-agent $n1 $udp1
set udpsink1 [new Agent/ Null]
$ns attach-agent $n0 $udpsink1
$ns connect $udp1 $udpsink1

$ns color 1 Blue


$tcp1 set fid_ 1

### Application Layer


set ftp [new Application/ FTP]
$ftp attach-agent $tcp1

set cbr [new Application/ Traffic/ CBR]


$cbr attach-agent $udp1

# connecting upper to lower layer

proc finish {} {
# follow this spacing
global ns tracefile nf
$ns flush-trace
# flushes the previous outputs ?
close $nf
close $tracefile
exec nam out.nam &
exit 0
}

$ns at 1.0 "$ftp start"


$ns at 2.5 "$ftp stop"

$ns at 2.6 "$cbr start"


$ns at 4.0 "$cbr stop"

# ns2 is an event simulator, where events can be timed


$ns at 5.0 "finish"

$ns run
# to execute the program

Output
What we are doing. From 1.0 to 2.5 seconds, we are transferring packets from node 0 to
node 2 via the TCP protocol. From 2.6 to 4.0 seconds, we are transferring packets from node
1 to node 0 via the UDP protocol.
From node 0 to node 2 (TCP) at 1.22 seconds

From node 1 to node 0 (UDP) at 3.10 seconds

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy