# NetworkLab_13MCA38

September 10, 2017 | Author: Joyanta Singha | Category: Routing, Computer Network, Transmission Control Protocol, Network Topology, Internet Standards

#### Short Description

computer network lab manual for m.c.a. v.t.u....

#### Description

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, REVA ITM, Banglore-64

1

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

01

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

02

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

03

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, REVA ITM, Banglore-64

2

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, REVA ITM, Banglore-64

3

Computer Networks Laboratory

13MCA38

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

Department of MCA, REVA ITM, Banglore-64

4

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 06

(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

07

08 09

file created identfy the points at which congestion occurs by writing sed / awk scripts. Also write a mechanism to correct/control the congestion. 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, REVA ITM, Banglore-64

5

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, REVA ITM, Banglore-64

6

Computer Networks Laboratory 01 02 03 04 05

13MCA38

INSTRUCTIONS TO COMPILE AND EXECUTE PROGRAMS Type the program in any editor and save it with .tcl extention To compile the program use ns filename.tcl To construct the graph use xgraph filename.tr

Department of MCA, REVA ITM, Banglore-64

7

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, REVA ITM, Banglore-64

8

Computer Networks Laboratory

13MCA38

Department of MCA, REVA ITM, Banglore-64

9

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, REVA ITM, 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, REVA ITM, 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, REVA ITM, 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, REVA ITM, Banglore-64

13

Computer Networks Laboratory

13MCA38 OUTPUT

Department of MCA, REVA ITM, Banglore-64

14

Computer Networks Laboratory

13MCA38

Department of MCA, REVA ITM, 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, REVA ITM, 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, REVA ITM, 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, REVA ITM, 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, REVA ITM, Banglore-64

19

Computer Networks Laboratory

13MCA38

OUTPUT

Department of MCA, REVA ITM, 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, REVA ITM, 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 duplex-link-op \$n2 \$n3 orient right

set em [new ErrorModel] \$em unit pkt ; # error unit (default: packets) (Other units: time, bits)

Department of MCA, REVA ITM, 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 drop-target [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, REVA ITM, 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, REVA ITM, 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, REVA ITM, 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> p61.tr & exit 0 } \$ns at \$val(stop) "finish" \$ns run

Department of MCA, REVA ITM, Banglore-64

56

Computer Networks Laboratory

13MCA38

Output

Department of MCA, REVA ITM, 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, REVA ITM, 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, REVA ITM, 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, REVA ITM, 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

Throughput for TCP 2.64 5.27 7.91 10.55 10.22 7.7 5.01 7.09

Department of MCA, REVA ITM, Banglore-64

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

2

3

4

5

6

7

8

CBR Data Rate

Department of MCA, REVA ITM, Banglore-64

62