You are on page 1of 62

Computer Networks Laboratory

13MCA38

REVA INSTITUTE OF
TECHNOLOGY AND MANAGEMENT
Kattigenahalli, Jala Hobli, Yelahanka, Bangalore 560 064

Department of Master of Computer


Applications
III Semester MCA

Laboratory Manual
Computer Networks Laboratory
13MCA38
Department of MCA, EWIT, Banglore-64

Computer Networks Laboratory

13MCA38

Subject Code:13MCA38

I.A Marks: 50

Hours/Week: 3

Exam Marks: 50

Total Hours: 42

Exam Hours: 3
Particulars of the Experiments Performed
CONTENTS

Sl.
No.

Page
No.

Programs
Write a TCL Script to Simulate the network described below
Consider a small network with five nodes n0,n1,n2,n3 and n4 forming a star

topology. The node n4 is at the center. Node n0 is a TCP Source, which


transmits pockets to n3(a TCP Sink) through the node n4. Node n1 is another Traffic
Source and sends UDP packets to Node n2 through n4. The duration of the simulation
time is 10 Seconds
Setting up a local area network with ns2
In this exercise you will be simulating a CSMA/CD based LAN with ns2. Consider the LAN
with seven nodes to be an isolated one i.e. not connected to the Internet. Node # 0 in the
LAN act as a UDP traffic source, and node # 6 is the destination node. Assume CBR
traffic to be flowing between the nodes. The
simulation lasts for 25 seconds. In Ethernet a packet is broadcasted in the

shared medium, and only the destination node accepts the packet. Other nodes simply drop
it. What should be the number of hops a packet from node #0 to node # 6 travel?

Additional Task:
Suppose the above LAN is to be connected to the Internet. Add node # 7 into the
network so that it act as the gateway. Connect node # 0 and # 7 with a 1
3

Mb wired link. Move the UDP source to node # 7.


Write a TCL Script to simulate a File Transfer With NS2
Consider a Client and Server. The Server is running a FTP Application (Over TCP). The
Client sends a request to download s file of size 10 MB from server. Write a script to
simulate this scenario. Let node #0 be the server and node #1 be the client. TCP packet
size is 1500B. Assume typical values for other parameters.
Note: This simulation require transfer of a fixed size file. Therefore, time required for the
transfer would be constant for a given bandwidth of a link. To verify this, determine the
time that would roughly be required for the transfer.

Department of MCA, EWIT, Banglore-64

Computer Networks Laboratory

13MCA38

Then look at the bottom of the trace file and verify whether there is any
transmission beyond the time calculated.
To verify that the client has downloaded the entire file, plot the "Bytes Received " curve for
node #1. The y-axis is in Kbits. Convert it to MB and verify whether it approximates the
specified file size. TCP headers would effectively increase the count of received bytes at
node # 1.
4. Simulating link errors
Consider the following network diagram

04

Here node # 2 act as a router. Any traffic to or from the LAN passes through it. Consider
node #1 running a FTP server, and node # 5 is downloading a file of size 4 MB. However,
the link between node # 2 and # 3 is fault. It drops packets with a fixed probability of 0.2.
Implement a link error model to reflect this. It may be noted here that the file download time
will be more than the we had in exercise # 2 of experiment # 1. Try different values of the
simulation time to ensure that the file has been entirely transferred. Is the plot of bytes
received a linear curve or non-linear? Why?Presence of link errors cause one or more
packets to be retransmitted. Verify this from the "Packet Retransmissions" plot.

05

Measuring Network Performances Bottleneck in the network

Department of MCA, EWIT, Banglore-64

Computer Networks Laboratory

13MCA38

Consider a dumbbell topology with eight nodes as shown as in the following figure.

Consider nodes# 2 and 3 to be two routers connecting two different networks. When the
bandwidth of the link 2-3 is much lower than the sum of bandwidths of the other links in
the network, it act as a
bottleneck. Assume node # 0 running a FTP application (over TCP) and sending data to
node # 6. Node # 1 is sending CBR data node # 7. Assume all the links except 2-3 has a
bandwidth of 1 Mb, propagation delay of 10ms and queue type as DropTail. (All are duplex
links).
Tasks:
The link 2-3 has a propagation delay of 10 ms. Vary it's bandwidth from 0.5 Mb to 2.5 Mb
in steps of 0.25Mb.
Compute the throughput for node # 3 in each case
Plot the throughput vs. bandwidth data in the "Custom Plot" section below Based on the
above plots, suggest what should be the recommended bandwidth of the link 2-3. Now, plot
the end-to-end delay between nodes 0 and 6 for the above chosen values of link 2-3
bandwidth. Revisit your previous answer (i.e. optimum bandwidth of link 2-3)based on
these graphs. Measuring Network Performances

Department of MCA, EWIT, Banglore-64

Computer Networks Laboratory

13MCA38

Write a TCL script to simulate the following scenario with ns2 simulator. Consider six
nodes, (as shown in the figure below) moving within a flat topology of 700m x 700m. The
initial positions of nodes are 0 (150,300) ,1 (300,500),2 (500,500),3 (300,100),4(500,100)
and 5(650,300) respectively.A TCP connection is initiated between node 0 (source) and
node 5 (destination) through node 3 and node 4 i.e the route is 0-3-4-5. At time t = 3
seconds the FTP application runs over it. After time t=4.0 sec, node 3 (300,100) moves
towards node 1
6

(300,500) with a speed of 5.0m/secand after some time the path break, then the data transmit
with a new path via node 1 and node 2
i.e the new route 0-1-2-5.The simulation lasts for 60 secs. In the above said case
both the route has equal cost
Use DSR as the routing protocol and the IEEE 802.11 MAC protocol. Now
Analyze the trace file and determine when the use of second route
commence, and Plot the number of packets received by each node over
the entire time duration of the simulation
Simulate a network which will create congestion in the network. With the trace

file created identfy the points at which congestion occurs by writing sed / awk scripts. Also
write a mechanism to correct/control the congestion.

08
9

Simulate a wired network and demonstrate Distance Vector Routing algorithm .


Bandwidth sharing between TCP and UDP
Consider the dumbbell topology from our previous exercise:

Department of MCA, EWIT, Banglore-64

Computer Networks Laboratory

13MCA38

Node # 0 is a TCP source, and the corresponding sink is at node # 6. Node # 1 is a UDP
source (CBR traffic) with a null agent attached to node # 7. These two traffic flows through
the common link 2-3. The aim of this exercise is to examine how TCP and UDP share the
bandwidth between themselves when the rate of CBR traffic is changed.
Set the TCP packet size to 1460 B. The UDP and CBR packet sizes are 1500 B. All the
links in the network have same bandwidths (say, 4 Mb), delay and queue types.

Part 1:
Set the initial rate of CBR traffic to 0.5 Mb. Run the simulation, and plot the "Bytes
Received" by node #s 4 and 5 (sinks for TCP and UDP traffic)
Now, increment the rate up to 4 Mb, the link bandwidth, in steps of 0.5 Mb. Run the
simulation and plot the graphs again.
How does the graphs change after each run? In particular, what's the nature of the
graphs when the rate of CBR traffic is 50% of the bandwidth?
Part 2: Behaviour of UDP
Reduce the bandwidth of the link 2-3 to say, 2 Mb. Repeat the above steps and observe
the graphs in this case.From the graphs plotted observe how UDP occupies a larger
portion of the bandwidth. How does the behaviour change for other variations of TCP
(Newreno, Vegas)?

Department of MCA, EWIT, Banglore-64

Computer Networks Laboratory

13MCA38

INSTRUCTIONS TO COMPILE AND EXECUTE PROGRAMS


01 Type the program in any editor and save it with .tcl extention 02 To
compile the program use ns filename.tcl
03
To construct the graph use xgraph filename.tr
04
05

Department of MCA, EWIT, Banglore-64

Computer Networks Laboratory


1.

13MCA38

Write a TCL Script to Simulate the network described below

Consider a small network with five nodes n0,n1,n2,n3 and n4 forming a star topology. The node n4 is at
the center. Node n0 is a TCP Source, which transmits pockets to n3(a TCP Sink) through the node n4.
Node n1 is another Traffic Source and sends UDP packets to Node n2 through n4. The duration of the
simulation time is 10 Seconds
set val(stop) 10.0 ;#time of simulation end
#Create a ns simulator
set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
#Open the NS trace file set
tracefile [open p1.tr w] $ns
trace-all $tracefile #Open the
NAM trace file
set namfile [open p1.nam w] $ns
namtrace-all $namfile #Create 5
nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
#Create labels for nodes $n0
label "Tcp Source" $n3 label
"Tcp_Destination" $n1 label
"Udp Source " $n2 label "Udp
Destination"
#Give shapes to nodes
$n0 shape square
$n3 shape square
$n4 shape circle

Department of MCA, EWIT, Banglore-64

Computer Networks Laboratory

13MCA38

$n1 shape hexagon $n2


shape hexagon #Give
colors to nodes $n0
color green
$n3 color red $n1
color green $n2
color red $n4
color black
#Create links between nodes
$ns duplex-link $n0 $n4 100.0Mb 40ms DropTail
$ns queue-limit $n0 $n4 5 ; # default queue limit is 50 $ns
duplex-link $n4 $n3 100.0Mb 40ms DropTail
$ns queue-limit $n4 $n3 5
$ns duplex-link $n1 $n4 100.0Mb 40ms DropTail $ns
queue-limit $n1 $n4 5
$ns duplex-link $n4 $n2 100.0Mb 40ms DropTail $ns
queue-limit $n4 $n2 5
$ns duplex-link-op $n4 $n2 queuePos 0.5 ; # give reading when queue content is 50% $ns
duplex-link-op $n4 $n0 queuePos 0.5
#Give node position (for NAM)
$ns duplex-link-op $n4 $n0 orient left-down $ns
duplex-link-op $n1 $n4 orient left-up $ns duplexlink-op $n3 $n4 orient left-down $ns duplex-link-op
$n2 $n4 orient right-down
#Setup a TCP connection set
tcp0 [new Agent/TCP] $ns
attach-agent $n0 $tcp0
set sink3 [new Agent/TCPSink]
$ns attach-agent $n3 $sink3 $ns
connect $tcp0 $sink3 $tcp0 set
packetSize_ 1000

Department of MCA, EWIT, Banglore-64

Computer Networks Laboratory

13MCA38

#Setup a UDP connection set


udp1 [new Agent/UDP] $ns
attach-agent $n1 $udp1 set
null2 [new Agent/Null] $ns
attach-agent $n2 $null2 $ns
connect $udp1 $null2 $udp1 set
packetSize_ 1000
#Assign

flow-id

$tcp0 set fid_ 1


$udp1 set fid_ 2
#Setup a CBR Application over TCP connection set
cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $tcp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 3.0Mb $cbr0
set random_ null $ns at 0.01
"$cbr0 start" $ns at 9.9 "$cbr0
stop"
#Setup a CBR Application over UDP connection set
cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 1000
$cbr1 set rate_ 2.0Mb $cbr1
set random_ null $ns at 0.1
"$cbr1 start" $ns at 9.0 "$cbr1
stop"
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile

Department of MCA, EWIT, Banglore-64

10

Computer Networks Laboratory

13MCA38

$ns flush-trace close


$tracefile close
$namfile exec nam
p1.nam & exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at
$val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt" $ns
run

OUTPUT

Department of MCA, EWIT, Banglore-64

11

Computer Networks Laboratory

13MCA38

2.Setting up a local area network with ns2


In this exercise you will be simulating a CSMA/CD based LAN with ns2. Consider the LAN with seven
nodes to be an isolated one i.e. not connected to the Internet. Node # 0 in the LAN act as a UDP traffic
source, and node # 6 is the destination node. Assume CBR traffic to be flowing between the nodes. The
simulation lasts for 25 seconds. In Ethernet a packet is broadcasted in the shared medium, and only the
destination node accepts the packet. Other nodes simply drop it. What should be the number of hops a
packet from node #0 to node # 6 travel?

Additional Task:
Suppose the above LAN is to be connected to the Internet. Add node # 7 into the network so that it act
as the gateway. Connect node # 0 and # 7 with a 1 Mb wired link. Move the UDP source to node # 7.

Program
set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
set ntrace [open prg2.tr w] $ns
trace-all $ntrace
set namfile [open prg2.nam w] $ns
namtrace-all $namfile
proc finish { } {
global ns ntrace namfile
$ns flush-trace
close $ntrace
close $namfile
exec nam prg2.nam &
exit 0
}

Department of MCA, EWIT, Banglore-64

12

Computer Networks Laboratory

13MCA38

for { set i 0 } {$i < 7 } { incr i } { set n($i)


[$ns node]
}
$n(0) label "Udp Source " #X
$n(6) label "Udp Sink"
set lan [$ns newLan "$n(0) $n(1) $n(2) $n(3) $n(4) $n(5) $n(6)" 0.5Mb 40ms LL Queue/DropTail MAC/802_3
Channel]
set udp [new Agent/UDP]
#remove the comments for this block to perform additional task and comment the lines which have been
marked as X at the end of the line
#

set n7 [$ns node]

$n7 label "Udp Source "

$ns attach-agent $n7 $udp

$ns duplex-link $n(0) $n7 10Mb 20ms DropTail

$ns duplex-link-op $n(0) $n7 orient left

$ns attach-agent $n(0) $udp #X set


sink0 [new Agent/Null]
$ns attach-agent $n(6) $sink0
$ns connect $udp $sink0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 1000 $cbr0
set interval_ 0.1
$cbr0 attach-agent $udp
$udp set fid_ 1
$ns at 0.01 "$cbr0 start"
$ns at 20.0 "$cbr0 stop"
$ns at 25.0 "finish"
$ns run

Department of MCA, EWIT, Banglore-64

13

Computer Networks Laboratory

13MCA38
OUTPUT

Department of MCA, EWIT, Banglore-64

14

Computer Networks Laboratory

13MCA38

Additional Tasks

Department of MCA, EWIT, Banglore-64

15

Computer Networks Laboratory

13MCA38

3. Write a TCL Script to simulate a File Transfer With NS2


Consider a Client and Server. The Server is running a FTP Application (Over TCP). The Client sends a
request to download s file of size 10 MB from server. Write a script to simulate this scenario. Let node #0
be the server and node #1 be the client. TCP packet size is 1500B. Assume typical values for other
parameters.
Note: This simulation require transfer of a fixed size file. Therefore, time required for the transfer would
be constant for a given bandwidth of a link. To verify this, determine the time that would roughly be
required for the transfer. Then look at the bottom of the trace file and verify whether there is any
transmission beyond the time calculated.
To verify that the client has downloaded the entire file, plot the "Bytes Received " curve for node #1. The
y-axis is in Kbits. Convert it to MB and verify whether it approximates the specified file size. TCP headers
would effectively increase the count of received bytes at node # 1.

Program
#Create a ns simulator
set ns [new Simulator]
#Open the NS trace file set
tracefile [open p3.tr w] $ns
trace-all $tracefile
#Open the NAM trace file set
namfile [open p3.nam w] $ns
namtrace-all $namfile
#Create 2 nodes
set s [$ns node]
set c [$ns node]
$ns color 1 Blue
#Create labels for nodes $s
label "Server"
$c label "Client"

Department of MCA, EWIT, Banglore-64

16

Computer Networks Laboratory

13MCA38

#Create links between nodes


$ns duplex-link $s $c 10Mb 22ms DropTail
#Give node position (for NAM)
$ns duplex-link-op $s $c orient right
#Setup a TCP connection for node s(server) set
tcp0 [new Agent/TCP]
$ns attach-agent $s $tcp0
$tcp0 set packetSize_ 1500
#Setup a TCPSink connection for node c(client) set
sink0 [new Agent/TCPSink]
$ns attach-agent $c $sink0
$ns connect $tcp0 $sink0
#Setup a FTP Application over TCP connection set
ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ftp0 set type_ FTP $tcp0
set fid_ 1
proc finish { } {
global ns tracefile namfile
$ns flush-trace
close $tracefile close
$namfile exec nam
p3.nam &
exec awk -f p3.awk p3.tr &
exec awk -f p31.awk p3.tr > p31.tr &
exec xgraph p31.tr -geometry 800*400 -t "bytes_received_at_client" -x "time_in_secs" -y
"bytes_in_bps" &
}
$ns at 0.01 "$ftp0 start"
$ns at 15.0 "$ftp0 stop"

Department of MCA, EWIT, Banglore-64

17

Computer Networks Laboratory

13MCA38

$ns at 15.1 "finish"


$ns run

Awk Script for finding time taken for data transmission(p3.awk)


# AWK script to calculate the time required to transfer the 10 MB file from the server to client BEGIN {
count=0;
time=0; total_bytes_sent
=0;
total_bytes_received=0;
}
{
if ( $1 == "r" && $4 == 1 && $5 == "tcp")
total_bytes_received += $6;
if($1 == "+" && $3 == 0 && $5 == "tcp")
total_bytes_sent += $6;
}
END { system("clear");
printf("\n Transmission time required to transfer the file is %lf",$2);
printf("\n Actual data sent from the server is %lf Mbps", (total_bytes_sent)/1000000.0); printf("\n Data
Received by the client is %lf Mbps\n",(total_bytes_received)/1000000.0);
}

Department of MCA, EWIT, Banglore-64

18

Computer Networks Laboratory

13MCA38

# AWK Script to calculate amount of data recived for every time intervel(p31.awk) BEGIN {
count=0;
time=0;
}
{
if ( $1 == "r" && $4 == "1" && $5 == "tcp")
{
count += $6;
time=$2;
printf("\n%lf\t%lf",time,(count)/1000000.0);
}
}
END {
}

Department of MCA, EWIT, Banglore-64

19

Computer Networks Laboratory

13MCA38

OUTPUT

Department of MCA, EWIT, Banglore-64

20

Computer Networks Laboratory

13MCA38

4. Simulating link errors


Consider the following network diagram

Here node # 2 act as a router. Any traffic to or from the LAN passes through it. Consider node #1 running a FTP
server, and node # 5 is downloading a file of size 4 MB. However, the link between node # 2 and # 3 is fault. It
drops packets with a fixed probability of 0.2. Implement a link error model to reflect this. It may be noted here that
the file download time will be more than the we had in exercise # 2 of experiment # 1. Try different values of the
simulation time to ensure that the file has been entirely transferred. Is the plot of bytes received a linear curve or
non-linear? Why? Presence of link errors cause one or more packets to be re-transmitted. Verify this from the
"Packet Re-transmissions" plot.

set val(stop) 20.0 ;#time of simulation end


#Create a ns simulator
set ns [new Simulator] #Open
the NS trace file set tracefile
[open p4.tr w] $ns trace-all
$tracefile #Open the NAM
trace file
set namfile [open p4.nam w] $ns
namtrace-all $namfile
#Create 7 nodes

Department of MCA, EWIT, Banglore-64

21

Computer Networks Laboratory

13MCA38

set n0 [$ns node] set n1


[$ns node] $n1 shape
square $n1 label
"ftp_server" set n2 [$ns
node] $n2 color green
$n2 label "error_node"
set n3 [$ns node]
$n3 color green
$n3 label "error_node"
set n4 [$ns node]
set n5 [$ns node] $n5
label "ftp_client" set n6
[$ns node]
#Createlinks between nodes
$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail $ns
queue-limit $n0 $n2 50
$ns duplex-link $n0 $n1 100.0Mb 10ms DropTail $ns
queue-limit $n0 $n1 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail $ns
queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail $ns
queue-limit $n2 $n3 50
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right
$ns duplex-link-op $n0 $n1 orient right-down $ns
duplex-link-op $n1 $n2 orient right-up $ns duplexlink-op $n2 $n3 orient right

set em [new ErrorModel]


$em unit pkt ; # error unit (default: packets) (Other units: time, bits)

Department of MCA, EWIT, Banglore-64

22

Computer Networks Laboratory

13MCA38

$em set rate_ 0.2 ; # error rate probability


$em ranvar [new RandomVariable/Uniform] ; # specify the rv for generating errors $em droptarget [new Agent/Null] ; # collect corrupted packets and handle
#Create a LAN of four nodes and record the trace (ex: collision-c, hop-h)
$ns make-lan -trace on " $n3 $n4 $n5 $n6 " 0.5Mb 40ms LL Queue/DropTail Mac/802_3 #Associate
a link loss model between nodes n2 and n3
$ns link-lossmodel $em $n2 $n3
#Setup a TCP connection set
tcp0 [new Agent/TCP] $ns
attach-agent $n1 $tcp0
set sink2 [new Agent/TCPSink]
$ns attach-agent $n5 $sink2 $ns
connect $tcp0 $sink2 $tcp0 set
packetSize_ 1000
#Setup a FTP Application over TCP connection set
ftp0 [new Application/FTP]
$ftp0

attach-agent

$tcp0

$ns at 0.01 "$ftp0 start" $ns


at 48.0 "$ftp0 stop"
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile close
$namfile exec nam
p4.nam &
exec awk -f p4.awk p4.tr >> p_plo.tr & exec awk
-f ReTans.awk p4.tr > p_rtran.tr & exit 0
}

Department of MCA, EWIT, Banglore-64

23

Computer Networks Laboratory

13MCA38

Note: repeat the experiment for different simulation timing and record the reading(simulation time and total data
transmitted)
example
Awk Script for generating total simulation time and total data transmitted
BEGIN {

count=0;

{
if( $1 == "r" && ( $4 == 2 || $4==3))
{

count += $6;

}
END { printf("%lf\t%lf\n",$2,
(count/1000000));
}

Department of MCA, EWIT, Banglore-64

24

Computer Networks Laboratory

13MCA38

Simulation time

Total Data Transferred

48.909683

0.423680

99.988750

1.420320

143.483058

1.708400

163.125155

1.714800

203.657181

1.726640

295.273139

2.265600

349.995186

2.888720

399.636592

3.761920

444.857848

4.107680

Graph between Simulation time and Data Transfer

Department of MCA, EWIT, Banglore-64

25

Computer Networks Laboratory

13MCA38

Awk Script for generating sequence no and no of retransmissions BEGIN{


i=0;
a[1500];
}
{ if($1=="d")
{ for(i=0;i<1500;i++)
{

if($11==i)
a[i]=a[i]+1;

}
}
}
END{ for(i=0;i<1500;i++)
{

printf("%d\t%d\n",i,a[i]); }

Department of MCA, EWIT, Banglore-64

26

Computer Networks Laboratory

13MCA38

OUTPUT
Graph between packet number and number of re transmissions

Department of MCA, EWIT, Banglore-64

27

Computer Networks Laboratory

13MCA38

5. Measuring Network Performances


Bottleneck in the network
Consider a dumbbell topology with eight nodes as shown as in the following figure.

Consider nodes# 2 and 3 to be two routers connecting two different networks. When the bandwidth
of the link 2-3 is much lower than the sum of bandwidths of the other links in the network, it act as a
bottleneck.
Assume node # 0 running a FTP application (over TCP) and sending data to node # 6. Node # 1 is sending
CBR data node # 7. Assume all the links except 2-3 has a bandwidth of 1 Mb, propagation delay of 10ms
and queue type as DropTail. (All are duplex links). Tasks:
The link 2-3 has a propagation delay of 10 ms. Vary it's bandwidth from 0.5 Mb to 2.5 Mb in steps of
0.25Mb.
Compute the throughput for node # 3 in each case
Plot the throughput vs. bandwidth data in the "Custom Plot" section below
Based on the above plots, suggest what should be the recommended bandwidth of the link 2-3. Now,
plot the end-to-end delay between nodes 0 and 6 for the above chosen values of link 2-3 bandwidth.
Revisit your previous answer (i.e. optimum bandwidth of link 2-3) based on these graphs. Measuring
Network Performances

Department of MCA, EWIT, Banglore-64

28

Computer Networks Laboratory

13MCA38

Program
#Program 5
set bv [lindex $argv 0]
set val(stop) 100.0; #time of simulation end
#Create a ns simulator
set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
#Open the NS trace file set
tracefile [open p5.tr w] $ns
trace-all $tracefile
#Open the NAM trace file set
namfile [open p5.nam w] $ns
namtrace-all $namfile
#Create 8 nodes
set n0 [$ns node]
$n0 label "ftp source" set
n1 [$ns node] $n1 label
"cbr source" $n1 shape
square
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
$n6 label "ftp receiver" set
n7 [$ns node]
$n7 label "cbr receiver"
#Create links between nodes
$ns duplex-link $n2 $n0 1.0Mb 10ms DropTail $ns
queue-limit $n2 $n0 5

Department of MCA, EWIT, Banglore-64

29

Computer Networks Laboratory

13MCA38

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


queue-limit $n1 $n2 5
$ns duplex-link $n2 $n3 ${bv}Mb 10ms DropTail $ns
queue-limit $n2 $n3 2
$ns duplex-link $n3 $n4 1.0Mb 10ms DropTail $ns
queue-limit $n3 $n4 5
$ns duplex-link $n3 $n5 1.0Mb 10ms DropTail $ns
queue-limit $n3 $n5 5
$ns duplex-link $n5 $n7 1.0Mb 10ms DropTail $ns
queue-limit $n5 $n7 5
$ns duplex-link $n4 $n6 1.0Mb 10ms DropTail $ns
queue-limit $n4 $n6 5
#Give node position (for NAM)
$ns duplex-link-op $n2 $n0 orient left-up $ns
duplex-link-op $n1 $n2 orient right-up $ns
duplex-link-op $n2 $n3 orient right $ns duplexlink-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down $ns
duplex-link-op $n5 $n7 orient right
$ns duplex-link-op $n4 $n6 orient right
#Setup a TCP connection set
tcp0 [new Agent/TCP] $ns
attach-agent $n0 $tcp0
set sink6 [new Agent/TCPSink]
$ns attach-agent $n6 $sink6 $ns
connect $tcp0 $sink6 $tcp0 set
packetSize_ 1500

#Setup a UDP connection set


udp1 [new Agent/UDP] $ns
attach-agent $n1 $udp1

Department of MCA, EWIT, Banglore-64

30

Computer Networks Laboratory

13MCA38

set null7 [new Agent/Null] $ns


attach-agent $n7 $null7 $ns
connect $udp1 $null7 $udp1
set packetSize_ 1500 $tcp0 set
fid_ 1
$udp1 set fid_ 2
#Setup a FTP Application over TCP connection set
ftp0 [new Application/FTP]
$ftp0

attach-agent

$tcp0

$ns at 0.01 "$ftp0 start" $ns


at 40.0 "$ftp0 stop"
#Setup a CBR Application over UDP connection set
cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$ns at 0.01 "$cbr1 start" $ns
at 40.0 "$cbr1 stop"
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile bv
$ns flush-trace
close $tracefile close
$namfile exec nam
p5.nam &
exec awk -f p5.awk -v var1=$bv p5.tr >> p51.tr & exec
awk -f p5_delay.awk p5.tr| xgraph
exit 0
}
$ns at $val(stop) "finish"
$ns run

Department of MCA, EWIT, Banglore-64

31

Computer Networks Laboratory

13MCA38

Output

Department of MCA, EWIT, Banglore-64

32

Computer Networks Laboratory

13MCA38

#AWK script to calculate throughput for specific bandwidth BEGIN


{
count=0;
time=0.01;
}
{
if ( $1 == "r" && $3 == 2 && $4 == 3)
{
count += $6;
time=$2;
}
}
END {
printf(" %lf \t %lf\n ", var1,((count/time) * (8/1000000.0)) );
}

Bandwidths

Throughput

0.500000

0.264608

0.750000

0.631865

1.000000

0.604290

1.250000

0.768960

1.500000

1.490149

1.750000

1.490178

2.000000

1.490313

2.250000

1.490418

2.500000

1.490502

Department of MCA, EWIT, Banglore-64

33

Computer Networks Laboratory

Department of MCA, EWIT, Banglore-64

13MCA38

34

Computer Networks Laboratory

13MCA38

BEGIN {
hpid = 0;
}
{
e=$1; t=$2;
fid=$8;
pid=$12;
s=$9; d=$10;
if(pid > hpid)

hpid = pid; if(


st[pid]== 0)
st[pid]=t;
if(fid == 1 && e == "r" && s==0 && d==6)
{
et[pid]=t;
}
else {
et[pid]=0;
}
}
END {
for(pid=0; pid<=hpid; pid++) { start
= st[pid];
end = et[pid];
packet_duration = end - start;
if( start < end )
printf("%d\t%lf\n",pid,packet_duration);

Department of MCA, EWIT, Banglore-64

35

Computer Networks Laboratory

13MCA38

}}

Department of MCA, EWIT, Banglore-64

36

Computer Networks Laboratory

13MCA38

6. Write a TCL script to simulate the following scenario with ns2 simulator.
Consider six nodes, (as shown in the figure below) moving within a flat topology of 700m x 700m. The initial
positions of nodes are 0 (150,300) ,1 (300,500),2 (500,500),3 (300,100),4(500,100) and 5(650,300) respectively.A
TCP connection is initiated between node 0 (source) and node 5 (destination) through node 3 and node 4 i.e the
route is 0-3-4-5. At time t = 3 seconds the FTP application runs over it. After time t=4.0 sec, node 3 (300,100)
moves towards node 1 (300,500) with a speed of 5.0m/secand after some time the path break, then the data
transmit with a new path via node 1 and node 2
i.e the new route 0-1-2-5.The simulation lasts for 60 secs. In the above said case both the route has equal cost
Use DSR as the routing protocol and the IEEE 802.11 MAC protocol.
Now Analyze the trace file and determine when the use of second route commence, and
Plot the number of packets received by each node over the entire time duration of the simulation
# Program 7
#

Simulation parameters setup

set val(chan)

Channel/WirelessChannel

set val(prop)

Propagation/TwoRayGround ;# radio-propagation model

set val(netif)

Phy/WirelessPhy

set val(mac)
set val(ifq)
set val(ant)

;# network interface type

Mac/802_11

;# MAC type

CMUPriQueue

set val(ll) LL

;# channel type

;# interface queue type


;# link layer type

Antenna/OmniAntenna

set val(ifqlen) 50

;# antenna model

;# max packet in ifq

set val(nn)

set val(rp)

DSR

;# routing protocol

set val(x)

700

;# X dimension of topography

set val(y)

700

;# Y dimension of topography

set val(stop)

60.0

;# number of mobilenodes

;# time of simulation end

#Create a ns simulator
set ns [new Simulator]
#Setup topography object set
topo [new Topography]

Department of MCA, EWIT, Banglore-64

37

Computer Networks Laboratory

13MCA38

$topo load_flatgrid $val(x) $val(y)


create-god $val(nn)
#Open the NS trace file set
tracefile [open p6.tr w] $ns
trace-all $tracefile
#Open the NAM trace file set
namfile [open p6.nam w] $ns
namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y) set chan
[new $val(chan)];#Create wireless channel
#

Mobile node parameter setup

$ns node-config -adhocRouting $val(rp) \


-llType

$val(ll) \

-macType

$val(mac) \

-ifqType

$val(ifq) \

-ifqLen

$val(ifqlen) \

-antType

$val(ant) \

-propType

$val(prop) \

-phyType

$val(netif) \

-channel

$chan \

-topoInstance

$topo \

-agentTrace

ON \

-routerTrace

ON \

-macTrace
ON \
-movementTrace ON
#Create 6 nodes with initial positions set
n0 [$ns node]
$n0 set X_ 150
$n0 set Y_ 300
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20

Department of MCA, EWIT, Banglore-64

38

Computer Networks Laboratory

13MCA38

set n1 [$ns node]


$n1 set X_ 300 $n1
set Y_ 500 $n1 set
Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 500 $n2
set Y_ 500 $n2 set
Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 300 $n3
set Y_ 100 $n3 set
Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 500 $n4
set Y_ 100 $n4 set
Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 650 $n5
set Y_ 300 $n5 set
Z_ 0.0
$ns initial_node_pos $n5 20
#Setup a TCP connection set
tcp0 [new Agent/TCP] $ns
attach-agent $n0 $tcp0
set sink5 [new Agent/TCPSink]

Department of MCA, EWIT, Banglore-64

39

Computer Networks Laboratory

13MCA38

$ns attach-agent $n5 $sink5


$ns connect $tcp0 $sink5 $tcp0
set packetSize_ 1500
#Setup a FTP Application over TCP connection set
ftp0 [new Application/FTP]
$ftp0

attach-agent

$tcp0

$ns at 0.0 "$ftp0 start" $ns


at 60.0 "$ftp0 stop"
#Allow node n3 to move towards node n1 with speed 5 m/sec $ns at
4.0 "$n3 setdest 300.0 500.0 5.0"
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile close
$namfile exec nam
p6.nam &
exec cat p6.tr | awk -f p6.awk & exit
0
}
for {set i 0} {$i < $val(nn) } { incr i } { $ns at
$val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at
$val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt" $ns
run

Department of MCA, EWIT, Banglore-64

40

Computer Networks Laboratory

13MCA38

AWK Script for calculating total amount transferred by each node


BEGIN
{ count1=0;
count2=0;
count3=0;
count4=0;
count5=0;
}
{
if( $1=="r" && $3=="_1_" && $4=="RTR")
count1++;
if( $1=="r" && $4=="RTR" && $3=="_2_")
count2++;
if( $1=="r" && $4=="RTR" && $3=="_3_")
count3++;
if( $1=="r" && $4=="RTR" && $3=="_4_")
count4++;
if( $1=="r" && $4=="RTR" && $3=="_5_")
count5++;
}
END {
printf("\n packet received by node 1 %d",count1); printf("\n
packet received by node 2 %d",count2); printf("\n packet
received by node 3 %d",count3); printf("\n packet received
by node 4 %d",count4); printf("\n packet received by node
5 %d\n",count5);
}

Department of MCA, EWIT, Banglore-64

41

Computer Networks Laboratory

13MCA38

OUTPUT num_nodes
is set 6
INITIALIZE THE LIST xListHead
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
SORTING LISTS ...DONE!
packet received by node 1 1727
packet received by node 2 1731
packet received by node 3 717
packet received by node 4 719
packet received by node 5 2451

Department of MCA, EWIT, Banglore-64

42

Computer Networks Laboratory

13MCA38

7. Simulate a network which will create congestion in the network. With the trace file created
identify the points at which congestion occurs by writing sed / awk scripts. Also write a mechanism
to correct/control the congestion.
#Program
set bv [lindex $argv 0]
set val(stop) 100.0; #time of simulation end
#Create a ns simulator
set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
$ns color 3 Green
#Open the NS trace file set
tracefile [open p7.tr w] $ns
trace-all $tracefile
#Open the NAM trace file set
namfile [open p7.nam w] $ns
namtrace-all $namfile
#Create 8 nodes
set n0 [$ns node]
$n0 label "cbr1 source"
set n1 [$ns node]
$n1 label "cbr2 source"
$n1 shape square
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
$n6 label "cbr1 receiver" set
n7 [$ns node]
$n7 label "cbr1 receiver"

Department of MCA, EWIT, Banglore-64

43

Computer Networks Laboratory

13MCA38

#Create links between nodes


$ns duplex-link $n0 $n3 1.0Mb 10ms DropTail $ns
queue-limit $n0 $n3 5
$ns duplex-link $n1 $n3 1.0Mb 10ms DropTail $ns
queue-limit $n1 $n3 5
$ns duplex-link $n2 $n3 1.0Mb 10ms DropTail $ns
queue-limit $n2 $n3 5
$ns duplex-link $n3 $n4 ${bv}Mb 10ms DropTail $ns
queue-limit $n3 $n4 5
$ns duplex-link $n4 $n5 1.0Mb 10ms DropTail $ns
queue-limit $n4 $n5 5
$ns duplex-link $n4 $n6 1.0Mb 10ms DropTail $ns
queue-limit $n4 $n6 5
$ns duplex-link $n4 $n7 1.0Mb 10ms DropTail $ns
queue-limit $n4 $n7 5

#Give node position (for NAM)


$ns duplex-link-op $n0 $n3 orient right-down $ns
duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n2 $n3 orient right-up $ns
duplex-link-op $n3 $n4 orient right $ns duplexlink-op $n4 $n5 orient right-up
$ns duplex-link-op $n4 $n6 orient right-down $ns
duplex-link-op $n4 $n7 orient right
#Setup a TCP connection
set tcp0 [new Agent/TCP/Newreno] $ns
attach-agent $n0 $tcp0
set sink5 [new Agent/TCPSink]
$ns attach-agent $n5 $sink5 $ns
connect $tcp0 $sink5 $tcp0 set
packetSize_ 1500

Department of MCA, EWIT, Banglore-64

44

Computer Networks Laboratory

13MCA38

set tcp1 [new Agent/TCP/Vegas]


$ns attach-agent $n1 $tcp1
set sink7 [new Agent/TCPSink]
$ns attach-agent $n7 $sink7 $ns
connect $tcp1 $sink7 $tcp1 set
packetSize_ 1500
#Setup a UDP connection #Agent/TCP a ``tahoe'' TCP sender set tcp2 [new
Agent/TCP]
$ns attach-agent $n2 $tcp2 set
sink6 [new Agent/TCPSink] $ns
attach-agent $n6 $sink6 $ns
connect $tcp2 $sink6 $tcp2 set
packetSize_ 1500
$tcp0 set fid_ 1
$tcp1 set fid_ 2
$tcp2 set fid_ 3
#Setup a FTP Application over TCP connection set
cbr0 [new Application/Traffic/CBR]
$cbr0

attach-agent

$tcp0

$ns at 0.01 "$cbr0 start" $ns


at 40.0 "$cbr0 stop"
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $tcp1
$ns at 0.01 "$cbr1 start"
$ns at 40.0 "$cbr1 stop"
#Setup a CBR Application over UDP connection set
cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $tcp2
$ns at 0.01 "$cbr2 start"

Department of MCA, EWIT, Banglore-64

45

Computer Networks Laboratory

13MCA38

$ns at 40.0 "$cbr2 stop"


#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile bv
$ns flush-trace
close $tracefile
close $namfile
#

exec nam p7.nam &


exec awk -f p7.awk -v var1=$bv p7.tr >> p71.tr & exit 0

}
$ns at $val(stop) "finish"
$ns run
OUTPUT

Department of MCA, EWIT, Banglore-64

46

Computer Networks Laboratory

13MCA38

AWK Script for calculating number of congestion actions taken by TCPThaho, NewReno, Vegas BEGIN {
countvagus=0;
countreno=0;
counttcp=0;
}
{
if ($8=="1" && $7=="---

A--- " )

countNewreno++;
if ($8=="2" && $7=="---

A--- " )

countvegas++;
if ($8=="3" && $7=="---

A--- " )

counttahoe++;
}
END {
printf(" %lf \t %d\t %d\t %d\n ", var1,countNewreno,countvegas,counttahoe);
}

Department of MCA, EWIT, Banglore-64

47

Computer Networks Laboratory

13MCA38

Graph for number of actions taken by Newreno, Vegas, TCP Thaho

Bandwidth
0.500000

TCP Newreno

TCP Vegas

TCP Thaho

1173

1063

0.750000

1176

1049

1.000000

1200

1123

1.250000

1264

1044

1.500000

1218

1130

1.750000

1166

1200

2.000000

1163

1247

2.250000

1089

1381

2.500000

1157

1221

2.750000

1105

1332

3.000000

1148

1262

3.250000

1101

1382

3.500000

1077

1222

3.750000

1116

1385

4.000000

1126

1378

Department of MCA, EWIT, Banglore-64

48

Computer Networks Laboratory

Department of MCA, EWIT, Banglore-64

13MCA38

49

Computer Networks Laboratory

13MCA38

8. Simulate a wired network and demonstrate Distance Vector Routing algorithm . set ns [new
Simulator]
$ns color 1 blue
$ns color 2 red
set nf [open out.nam w]
$ns namtrace-all $nf set tr
[open out.tr w] $ns traceall $tr
proc finish {} { global
nf ns tr $ns
flush-trace close
$tr close $nf
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$ns duplex-link $n0 $n1 10Mb 10ms DropTail $ns
duplex-link $n1 $n3 4Mb 10ms DropTail $ns
duplex-link $n2 $n1 10Mb 10ms DropTail $ns
duplex-link $n1 $n4 10Mb 10ms DropTail $ns
duplex-link $n4 $n5 10Mb 10ms DropTail $ns
duplex-link $n5 $n3 10Mb 10ms DropTail $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 $ns
duplex-link-op $n1 $n4 orient right-up

Department of MCA, EWIT, Banglore-64

50

Computer Networks Laboratory

13MCA38

$ns duplex-link-op $n4 $n5 orient right


$ns duplex-link-op $n5 $n3 orient right-down 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 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 $tcp $sink $ns
connect $udp $null $tcp set
fid_ 1
$udp set fid_ 2
$ns rtmodel-at 1.0 down $n1 $n3 $ns
rtmodel-at 2.0 up $n1 $n3 $ns rtproto
DV
$ns at 0.1 "$ftp start"
$ns at 0.0 "$cbr start"
$ns at 10.0 "finish" $ns
run

Department of MCA, EWIT, Banglore-64

51

Computer Networks Laboratory

13MCA38

Output

Department of MCA, EWIT, Banglore-64

52

Computer Networks Laboratory

13MCA38

9. Bandwidth sharing between TCP and UDP


Consider the dumbbell topology from our previous exercise:

Node # 0 is a TCP source, and the corresponding sink is at node # 6. Node # 1 is a UDP source (CBR traffic)
with a null agent attached to node # 7. These two traffic flows through the common link 2-3. The aim of this
exercise is to examine how TCP and UDP share the bandwidth between themselves when the rate of CBR
traffic is changed.
Set the TCP packet size to 1460 B. The UDP and CBR packet sizes are 1500 B. All the links in the network
have same bandwidths (say, 4 Mb), delay and queue types.
Part 1:
Set the initial rate of CBR traffic to 0.5 Mb. Run the simulation, and plot the "Bytes Received"
by node #s 4 and 5 (sinks for TCP and UDP traffic)
Now, increment the rate up to 4 Mb, the link bandwidth, in steps of 0.5 Mb. Run the simulation
and plot the graphs again.
How does the graphs change after each run? In particular, what's the nature of the graphs when the rate of
CBR traffic is 50% of the bandwidth?
Part 2: Behaviour of UDP

Department of MCA, EWIT, Banglore-64

53

Computer Networks Laboratory

13MCA38

Reduce the bandwidth of the link 2-3 to say, 2 Mb. Repeat the above steps and observe the graphs in
this case.From the graphs plotted observe how UDP occupies a larger portion of the bandwidth. How does
the behaviour change for other variations of TCP (Newreno, Vegas)?
Program
set val(stop) 50.0 ;#time of simulation end set rt
[lindex $argv 0]
#Create a ns simulator
set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
#Open the NS trace file set
tracefile [open p6.tr w] $ns
trace-all $tracefile #Open the
NAM trace file
set namfile [open p6.nam w] $ns
namtrace-all $namfile #Create 8
nodes
set n0 [$ns node] $n0
label "ftp source" set n1
[$ns node] $n1 label "cbr
source" $n1 shape
square
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
$n6 label "ftp receiver" set
n7 [$ns node]
$n7 label "cbr receiver"
#Create links between nodes
$ns duplex-link $n2 $n0 8.0Mb 10ms DropTail $ns
queue-limit $n2 $n0 50

Department of MCA, EWIT, Banglore-64

54

Computer Networks Laboratory

13MCA38

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


queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 8.0Mb 10ms DropTail $ns
queue-limit $n2 $n3 50
$ns duplex-link $n3 $n4 8.0Mb 10ms DropTail $ns
queue-limit $n3 $n4 50
$ns duplex-link $n3 $n5 8.0Mb 10ms DropTail $ns
queue-limit $n3 $n5 50
$ns duplex-link $n5 $n7 8.0Mb 10ms DropTail $ns
queue-limit $n5 $n7 50
$ns duplex-link $n4 $n6 8.0Mb 10ms DropTail $ns
queue-limit $n4 $n6 50
#Give node position (for NAM)
$ns duplex-link-op $n2 $n0 orient left-up $ns
duplex-link-op $n1 $n2 orient right-up $ns
duplex-link-op $n2 $n3 orient right $ns duplexlink-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down $ns
duplex-link-op $n5 $n7 orient right
$ns duplex-link-op $n4 $n6 orient right
#Setup a TCP connection
set tcp0 [new Agent/TCP/Vegas]
$ns attach-agent $n0 $tcp0
set sink6 [new Agent/TCPSink]
$ns attach-agent $n6 $sink6 $ns
connect $tcp0 $sink6 $tcp0 set
packetSize_ 1460
#Setup a UDP connection set
udp1 [new Agent/UDP] $ns
attach-agent $n1 $udp1 set
null7 [new Agent/Null] $ns
attach-agent $n7 $null7 $ns
connect $udp1 $null7

Department of MCA, EWIT, Banglore-64

55

Computer Networks Laboratory

13MCA38

$udp1 set packetSize_ 1500


$tcp0 set fid_ 1
$udp1 set fid_ 2

#Setup a FTP Application over TCP connection set


cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $tcp0
$cbr0 set packetSize_ 1460
$cbr0 set rate_ ${rt}Mb $cbr0
set random_ null $ns at 0.01
"$cbr0 start" $ns at 40.0 "$cbr0
stop"
#Setup a CBR Application over UDP connection set
cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 1500
$cbr1 set rate_ ${rt}Mb $cbr1
set random_ null $ns at 0.01
"$cbr1 start" $ns at 40.0 "$cbr1
stop"
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile rt $ns
flush-trace
close $tracefile close
$namfile exec nam
p6.nam &
exec awk -f p6_tcp.awk -v var1=$rt p6.tr >> p61.tr & exit 0
}
$ns at $val(stop) "finish"
$ns run

Department of MCA, EWIT, Banglore-64

56

Computer Networks Laboratory

13MCA38

Output

Department of MCA, EWIT, Banglore-64

57

Computer Networks Laboratory

13MCA38

Awk Script for calculating throughput of TCP and UDP


BEGIN
{ tcp_sink=0;
udp_sink=0
}
{
if($1=="r" && $4 == 4)
{ tcp_sink += $6;
}
if($1=="r" && $4 == 5 ){ udp_sink
+= $6;
}
}
END { printf("%lf\t%lf\t%lf\n",var1,tcp_sink/1000000,udp_sink/1000000);
}

Department of MCA, EWIT, Banglore-64

58

Computer Networks Laboratory

13MCA38

Newreno vs UDP

Bandwidth

TCP Newreno

UDP

0.500000

2.636560

2.500500

1.000000

5.273040

4.999500

1.500000

7.909520

7.498500

2.000000

10.546000

9.997500

2.500000

10.987740

12.498000

3.000000

8.540600

14.920500

3.500000

8.773220

17.473500

4.000000

7.929220

15.540000

Department of MCA, EWIT, Banglore-64

59

Computer Networks Laboratory

13MCA38

TCP vs UDP
CBR Rate
0.5
1
1.5
2
2.5
3
3.5
4

Throughput for TCP


2.64
5.27
7.91
10.55
10.99
8.54
5.93
7.93

Department of MCA, EWIT, Banglore-64

UDP
2.5
5
7.5
10
12.5
14.92
17.45
15.54

60

Computer Networks Laboratory

13MCA38

TCP vs UDP for 2 Mbps Link

CBR Rate
0.5
1
1.5
2
2.5
3
3.5
4

Department of MCA, EWIT, Banglore-64

Throughput for TCP


2.64
5.27
7.91
10.55
10.22
7.7
5.01
7.09

UDP
2.5
5
7.5
10
12.5
15
17.49
15.62

61

Computer Networks Laboratory

13MCA38

20
18
16

Throughput

14
12
10
Throughput for Vegas
UDP

8
6
4
2
0
1

CBR Data Rate

Department of MCA, EWIT, Banglore-64

62

You might also like