Professional Documents
Culture Documents
13MCA38
REVA INSTITUTE OF
TECHNOLOGY AND MANAGEMENT
Kattigenahalli, Jala Hobli, Yelahanka, Bangalore 560 064
Laboratory Manual
Computer Networks Laboratory
13MCA38
Department of MCA, EWIT, Banglore-64
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
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
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
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
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
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)?
13MCA38
13MCA38
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
13MCA38
13MCA38
flow-id
10
13MCA38
OUTPUT
11
13MCA38
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
}
12
13MCA38
13
13MCA38
OUTPUT
14
13MCA38
Additional Tasks
15
13MCA38
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"
16
13MCA38
17
13MCA38
18
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 {
}
19
13MCA38
OUTPUT
20
13MCA38
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.
21
13MCA38
22
13MCA38
attach-agent
$tcp0
23
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));
}
24
13MCA38
Simulation time
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
25
13MCA38
if($11==i)
a[i]=a[i]+1;
}
}
}
END{ for(i=0;i<1500;i++)
{
printf("%d\t%d\n",i,a[i]); }
26
13MCA38
OUTPUT
Graph between packet number and number of re transmissions
27
13MCA38
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
28
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
29
13MCA38
30
13MCA38
attach-agent
$tcp0
31
13MCA38
Output
32
13MCA38
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
33
13MCA38
34
13MCA38
BEGIN {
hpid = 0;
}
{
e=$1; t=$2;
fid=$8;
pid=$12;
s=$9; d=$10;
if(pid > hpid)
35
13MCA38
}}
36
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
#
set val(chan)
Channel/WirelessChannel
set val(prop)
set val(netif)
Phy/WirelessPhy
set val(mac)
set val(ifq)
set val(ant)
Mac/802_11
;# MAC type
CMUPriQueue
set val(ll) LL
;# channel type
Antenna/OmniAntenna
set val(ifqlen) 50
;# antenna model
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
#Create a ns simulator
set ns [new Simulator]
#Setup topography object set
topo [new Topography]
37
13MCA38
$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
38
13MCA38
39
13MCA38
attach-agent
$tcp0
40
13MCA38
41
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
42
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"
43
13MCA38
44
13MCA38
attach-agent
$tcp0
45
13MCA38
}
$ns at $val(stop) "finish"
$ns run
OUTPUT
46
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);
}
47
13MCA38
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
48
13MCA38
49
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
50
13MCA38
51
13MCA38
Output
52
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
53
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
54
13MCA38
55
13MCA38
56
13MCA38
Output
57
13MCA38
58
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
59
13MCA38
TCP vs UDP
CBR Rate
0.5
1
1.5
2
2.5
3
3.5
4
UDP
2.5
5
7.5
10
12.5
14.92
17.45
15.54
60
13MCA38
CBR Rate
0.5
1
1.5
2
2.5
3
3.5
4
UDP
2.5
5
7.5
10
12.5
15
17.49
15.62
61
13MCA38
20
18
16
Throughput
14
12
10
Throughput for Vegas
UDP
8
6
4
2
0
1
62