0% found this document useful (0 votes)
5 views8 pages

ACN Lab 4

The document details a simulation executed in NS-2, demonstrating the interaction between TCP and UDP traffic over a network with four nodes and specific link configurations. It outlines the setup, execution, and observations of the simulation, highlighting congestion dynamics, traffic visualization, and the impact of link characteristics on performance. The conclusion emphasizes the importance of network configurations and suggests future simulations to explore larger topologies and QoS techniques.

Uploaded by

Abdur Rahman
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)
5 views8 pages

ACN Lab 4

The document details a simulation executed in NS-2, demonstrating the interaction between TCP and UDP traffic over a network with four nodes and specific link configurations. It outlines the setup, execution, and observations of the simulation, highlighting congestion dynamics, traffic visualization, and the impact of link characteristics on performance. The conclusion emphasizes the importance of network configurations and suggests future simulations to explore larger topologies and QoS techniques.

Uploaded by

Abdur Rahman
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/ 8

Title: Execution of simple scenario in NS-2 Simulation

MIS No:
1. 712422001
2. 712422017

Source Code of the Work:

#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_]"

# Open trace file


set tracefile [open "out.tr" w]

# Enable packet trace


$ns trace-all $tracefile

#Run the simulation


$ns run

Snapshot of Execution:

Screenshot 1: Initial Traffic (Only UDP active at 0.2s)


• Description: Red CBR packets flowing from n1 to n3 via n2.

Screenshot 2: Combined Traffic (TCP and UDP active at 2.0s)


• Description: Both blue (FTP) and red (CBR) packets flowing, with
congestion visible at the n2-n3 link.
Observation:
Network Topology
• Nodes: Four nodes (n0, n1, n2, n3) are created in the simulation.
• Links:
o n0 to n2: 2 Mbps bandwidth, 10 ms delay.
o n1 to n2: 2 Mbps bandwidth, 10 ms delay.
o n2 to n3: 1.7 Mbps bandwidth, 20 ms delay with a queue size limit
of 10 packets.
Connections and Traffic
1. TCP Connection:
o Between n0 and n3.
o An FTP application is used to generate traffic over this connection.
o Scheduled to start at 1.0s and stop at 4.0s.
2. UDP Connection:
o Between n1 and n3.
o A CBR (Constant Bit Rate) traffic source is used to generate traffic.
o Scheduled to start at 0.1s and stop at 4.5s.

Procedure
1. Setup:
o The simulation was scripted in NS-2 with specific node positions
and link configurations.
o NAM trace file (out.nam) was generated to visualize the network.
2. Execution:
o The simulation ran for 5 seconds, with events scheduled for
starting/stopping traffic flows and queue monitoring.
o NAM was used to observe the animation.

Observations
Network Behavior
1. Traffic Visualization in NAM:
o The TCP (FTP) traffic from n0 to n3 was represented with a blue
color.
o The UDP (CBR) traffic from n1 to n3 was represented with a red
color.
2. Queue Dynamics on Link (n2-n3):
o The queue size of the link between n2 and n3 was limited to 10
packets.
o Packet drops were observed when the queue reached its capacity,
which was caused by the combined TCP and UDP traffic exceeding
the link's capacity.
3. Data Flow:
o UDP (CBR) traffic began first at 0.1s, followed by TCP (FTP)
traffic at 1.0s.
o FTP stopped at 4.0s, and CBR stopped at 4.5s, allowing
observation of independent and overlapping traffic flows.
4. Delay and Bandwidth Impact:
o The link with 20 ms delay and 1.7 Mbps bandwidth (n2 to n3)
created a bottleneck, impacting both TCP and UDP traffic.

Conclusion
This simulation demonstrated the interaction between TCP and UDP traffic over
a shared bottleneck link. Key takeaways include:
1. Congestion Dynamics: The limited queue size on the n2-n3 link resulted
in packet drops.
2. TCP vs. UDP Behaviour: TCP adjusted to congestion via
retransmissions, while UDP continuously sent packets, leading to higher
packet loss for UDP traffic.
3. Importance of Configurations: Link bandwidth, delay, and queue size
significantly impact overall network performance.
Future simulations could include larger topologies, varying traffic types, or
implementing Quality of Service (QoS) techniques for better traffic
management.

You might also like