Download VTU 7 SEM CSE Networks lab manual and more Exercises Computer Networks in PDF only on Docsity!
Program - 1
Question
Simulate a three nodes point – to – point network with duplex links between them.
Set the queue size and vary the bandwidth and find the number of packets dropped.
To execute:
To run the simulation:
$ns 1.tcl
To plot the graph:
$xgraph [-fg ][-bg ][-lw ] .xg
File: 1.tcl
#Create a new Simulation Instance
set ns [new Simulator]
#Turn on the Trace and the animation files
set f [open out.tr w]
set nf [open out.nam w]
$ns trace-all $f
$ns namtrace-all $nf
#Define the finish procedure to perform at the end of the simulation
proc finish {} {
global f nf ns
$ns flush-trace
close $f
close $nf
exec nam out.nam &
exec awk -f 1.awk out.tr &
exit 0
#Create the nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
#Label the nodes
$n0 label "TCP Source"
$n1 label "UDP Source"
$n2 label "Sink"
#Set the color
$ns color 1 red
$ns color 2 yellow
#Create the Topology
$ns duplex-link $n0 $n1 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 1.75Mb 20ms DropTail
#Attach a Queue of size N Packets between the nodes n1 n
$ns queue-limit $n1 $n2 10
#Make the Link Orientation
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right
#Create a UDP Agent and attach to the node n
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp
#Create a CBR Traffic source and attach to the UDP Agent
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp
#Specify the Packet Size and interval
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.
#Create a Null Agent and attach to the node n
set null0 [new Agent/Null]
$ns attach-agent $n2 $null
#Connect the CBR Traffic source to the Null agent
$ns connect $udp0 $null
#Create a TCP agent and attach to the node n
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp
#Create a FTP source and attach to the TCP agent
set ftp0 [new Application/FTP]
File: 1.xg
TitleText: Performance Analysis (Bandwidth vs Packet Dropped)
XUnitText: Bandwidth(in Mbps)
YUnitText: No.of Packet Dropped
"CBR"
"TCP"
OUTPUT:
Program - 2
Question
Simulate a four node point-to-point network with the links connected as follows:
n0 – n2, n1 – n2 and n2 – n3. Apply TCP agent between n0-n3 and UDP between
n1-n3. Apply relevant applications over TCP and UDP agents changing the
parameter and determine the number of packets sent by TCP / UDP.
File: 2.tcl
set ns [new Simulator]
set f [open out.tr w]
set nf [open out.nam w]
$ns trace-all $f
$ns namtrace-all $nf
$ns color 1 "Blue"
$ns color 2 "Red"
proc finish {} {
global ns f nf
$ns flush-trace
close $f
close $nf
exec nam out.nam &
exec awk -f 2.awk out.tr &
exit 0
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 2.75Mb 20ms DropTail
$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
$ns queue-limit $n2 $n3 50
set udp0 [new Agent/UDP]
$ns attach-agent $n1 $udp
$udp0 set class_ 2
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp
$cbr0 set packetSize_ 1000
$cbr0 set interval_ 0.
if((event=="d")&&(type=="cbr")) { CBRDrop++; } }
END {
printf "\nTCPSend %d", TCPSend; printf "\nCBRSend %d", CBRSend; printf "\nTCPDrop %d", TCPDrop; printf "\nCBRDrop %d", CBRDrop;
TCPArrivalRatio=((TCPSend-TCPDrop)/TCPSend); TCPDropRatio=(TCPDrop/TCPSend);
UDPArrivalRatio=((CBRSend-CBRDrop)/CBRSend); UDPDropRatio=(CBRDrop/CBRSend);
printf "\nTCPArrivalRatio %f", TCPArrivalRatio; printf "\nTCPDropRatio %f", TCPDropRatio; printf "\nUDPArrivalRatio %f", UDPArrivalRatio; printf "\nUDPDropRatio %f", UDPDropRatio; }
File: 2AR.xg
TitleText: Performance Analysis (Bandwidth vs Packet Arrival Ratio) XUnitText: Bandwidth(in Mbps) YUnitText: Packet arrival ratio
"TCP"
"CBR"
File: 2DR.xg
TitleText: Performance Analysis (Bandwidth vs Packet Arrival Ratio) XUnitText: Bandwidth(in Mbps) YUnitText: Packet arrival ratio
"TCP" 0.25 0. 0.50 0. 0.75 0. 1.0 0. 1.25 0. 1.5 0. 1.75 0. 2.0 0. 2.25 0. 2.5 0 2.75 0
"CBR"
Program - 3
Question
Simulate the transmission of ping messages over a network topology consisting of 6
nodes and find the number of packets dropped due to congestion.
File : 3.tcl
set ns [new Simulator] set f [open out.tr w] set nf [open out.nam w]
Agent/Ping instproc recv {from rtt} { global seq $self instvar node_ puts "The node [$node_ id] received an ACK from the node $from with RTT $rtt ms" }
$ping0 set class_ 1 $ping1 set class_ 2 $ping4 set class_ 4 $ping5 set class_ 5
$ns at 0.01 "sendPingPacket" $ns at 10.0 "finish" $ns run
File 3.xg
TitleText: Performance Analysis of Bandwidth v/s Packet Dropped xUnitText: Bandwidth in Mbps yUnitText: Packet Dropped
Program - 4
Question
Simulate an Ethernet LAN using n nodes (6-10), change error rate and
data rate and compare throughput.
File : 4.awk
#!/usr/bin/awk -f
BEGIN {
cbrPktReceived=0;
totalPktReceived=0;
ftpPktReceived=0;
throughput=0.0;
src=$3;
des=$4;
type=$5;
event=$1;
if((event=="+") && (src=="2") && (des=="6") && (type=="cbr"))
cbrPktReceived++;
if(($1=="+") && ($3=="2") && ($4=="6") && (type=="tcp"))
ftpPktReceived++;
totalPktReceived=cbrPktReceived+ftpPktReceived;
END {
throughput=((totalPktReceived5008)/(8*1000000));
printf "the throughput is:%f\n",throughput;
printf "the throughput is:%d\n",cbrPktReceived;
printf "the throughput is:%d\n",ftpPktReceived;
File : 4.xg
TitleText: Program 4
XUnitText: Error Rate
YUnitText: Throughput
$n0 label "TCP FTP Source" $n3 label "Sink Destination" $n5 label "TCP Telnet Source" $n7 label "Sink Destination"
#Create the LAN topology $ns make-lan "$n0 $n1 $n2 $n3 $n4 $n5 $n6 $n7" 10Mb 30ms LL Queue/DropTail Mac/802_
#Set up the TCP Agents set tcp1 [new Agent/TCP] $ns attach-agent $n0 $tcp set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp set sink1 [new Agent/TCPSink] $ns attach-agent $n3 $sink $ns connect $tcp1 $sink $tcp1 set class_ 1
#Set up the telnet set tcp2 [new Agent/TCP] $ns attach-agent $n5 $tcp set telnet1 [new Application/FTP] $telnet1 attach-agent $tcp set sink2 [new Agent/TCPSink] $ns attach-agent $n7 $sink $ns connect $tcp2 $sink $telnet1 set type_ $sink $tcp2 set class_ 2
set outFile1 [open Congestion1.xg w] set outFile2 [open Congestion2.xg w]
puts $outFile1 "TitleText: Congestion Window Plot for TCP1" puts $outFile1 "XUnitText: SimulationTime(Secs)" puts $outFile1 "YUnitText: CongestionWindowSize" puts $outFile2 "TitleText: Congestion Window Plot for TCP2" puts $outFile2 "XUnitText: SimulationTime(Secs)" puts $outFile2 "YUnitText: CongestionWindowSize"
#define findWindowSize proc findWindowSize {tcpSource outFile} { global ns set now [$ns now] set cWindSize [$tcpSource set cwnd_] puts $outFile "$now $cWindSize" $ns at [expr $now + 0.1] "findWindowSize $tcpSource $outFile" }
#schedule the events $ns at 0.0 "findWindowSize $tcp1 $outFile1" $ns at 0.1 "findWindowSize $tcp2 $outFile2" $ns at 0.3 "$ftp1 start" $ns at 0.5 "$telnet1 start" $ns at 50.0 "$ftp1 stop" $ns at 50.0 "$telnet1 stop" $ns at 50.0 "finish" $ns run
File : Congestion1.xg
XUnitText: SimulationTime(Secs) YUnitText: CongestionWindowSize
- TitleText: Congestion Window Plot for TCP
- 0.10000000000000001
- 0.20000000000000001
- 0.30000000000000004
- 0.40000000000000002
- 0.5
- 0.59999999999999998
- 0.69999999999999996
- 0.79999999999999993
- 0.89999999999999991
- 0.99999999999999989 20.
- 1.0999999999999999 21.
- 1.2 22.
- 1.3 23.
- 1.4000000000000001 23.
- 1.5000000000000002 24.
- 1.6000000000000003 24.
- 1.7000000000000004 25.
- 1.8000000000000005 26.
- 1.9000000000000006 27.
- 2.0000000000000004 27.
- 2.1000000000000005 28.
- 2.2000000000000006 28.
- 2.3000000000000007 29.
- 2.4000000000000008 30.
- 2.5000000000000009 30.
- 2.600000000000001 30.
- 2.7000000000000011 31.
- 2.8000000000000012 32.
- 2.9000000000000012 32.
- 3.0000000000000013 33.
- 3.1000000000000014 33.
- 3.2000000000000015 33.
- 3.3000000000000016 34.
- 3.4000000000000017 34.
- 3.5000000000000018 35.
- 3.6000000000000019 36.
- 3.700000000000002 36.
- 3.800000000000002 36.
- 3.9000000000000021 37.
- 4.0000000000000018 37.
- 4.1000000000000014 38.
- 4.2000000000000011 38.
- 4.3000000000000007 39.
- 4.4000000000000004 39.
- 4.5 39.
- 4.5999999999999996 40.
- 4.6999999999999993 40.
- 4.7999999999999989 41.
- 4.8999999999999986 41.
- 4.9999999999999982 41.
- 5.0999999999999979 42.
- 5.1999999999999975 42.
- 5.2999999999999972 43.
- 5.3999999999999968 43.
- 5.4999999999999964 43.
- 5.5999999999999961 44.
- 5.6999999999999957 44.
- 5.7999999999999954 44.
- 5.899999999999995 45.
- 5.9999999999999947 45.
- 6.0999999999999943 45.
- 6.199999999999994 46.
- 6.2999999999999936 46.
- 6.3999999999999932 47.
- 6.4999999999999929 47.
- 6.5999999999999925 47.
- 6.6999999999999922 48.
- 6.7999999999999918 48.
- 6.8999999999999915 48.
- 6.9999999999999911 49.
- 7.0999999999999908 49.
- 7.1999999999999904 49.
- 7.2999999999999901 50.
- 7.3999999999999897 50.
- 7.4999999999999893 50.
- 7.599999999999989 51.
- 7.6999999999999886 51.
- 7.7999999999999883 51.
- 7.8999999999999879 52.
- 7.9999999999999876 52.
- 8.0999999999999872 52.
- 8.1999999999999869 53.
- 8.2999999999999865 53.
- 8.3999999999999861 53.
- 8.4999999999999858 53.
- 8.5999999999999854 54.
- 8.6999999999999851 54.
- 8.7999999999999847 55.
- 8.8999999999999844 55.
- 8.999999999999984 55.
- 9.0999999999999837 55.
- 9.1999999999999833 56.
- 9.2999999999999829 56.
- 9.3999999999999826 56.
- 9.4999999999999822 57.
- 9.5999999999999819 57.
- 9.6999999999999815 57.
- 9.7999999999999812 57.
- 9.8999999999999808 58.
- 9.9999999999999805 58.
- 10.09999999999998 58.
- 10.19999999999998 58.
- 10.299999999999979 59.
- 10.399999999999979 59.
- 10.499999999999979 59.
- 10.599999999999978 60.
- 10.699999999999978 60.
- 10.799999999999978 60.
- 10.899999999999977 60.
- 10.999999999999977 61.
- 11.099999999999977 61.
- 11.199999999999976 61.
- 11.299999999999976 61.
- 11.399999999999975 62.
- 11.499999999999975 62.
- 11.599999999999975 62.
- 11.699999999999974 63.
- 11.799999999999974 63.
- 11.899999999999974 63.
- 11.999999999999973 63.
- 12.099999999999973 64.
- 12.199999999999973 64.
- 12.299999999999972 64.
- 12.399999999999972 64.
- 12.499999999999972 65.
- 12.599999999999971 65.
- 12.699999999999971 65.
- 12.799999999999971 65.
- 12.89999999999997 66.
- 12.99999999999997 66.
- 13.099999999999969 66.
- 13.199999999999969 66.
- 13.299999999999969 67.
- 13.399999999999968 67.
- 13.499999999999968 67.
- 13.599999999999968 67.
- 13.699999999999967 68.
- 13.799999999999967 68.
- 13.899999999999967 68.
- 13.999999999999966 68.
- 14.099999999999966 69.
- 14.199999999999966 69.
- 14.299999999999965 69.
- 14.399999999999965 69.
- 14.499999999999964 70.
- 14.599999999999964 70.
- 14.699999999999964 70.
- 14.799999999999963 70.
- 14.899999999999963 70.
- 14.999999999999963 71.
- 15.099999999999962 71.
- 15.199999999999962 71.
- 15.299999999999962 71.
- 15.399999999999961 72.
- 15.499999999999961 72.
- 15.599999999999961 72.
- 15.69999999999996 72.
- 15.79999999999996 73.
- 15.899999999999959 73.
- 15.999999999999959 73.
- 16.099999999999959 73.
- 16.19999999999996 73.
- 16.299999999999962 74.
- 16.399999999999963 74.
- 16.499999999999964 74.
- 16.599999999999966 74.
- 16.699999999999967 75.
- 16.799999999999969 75.
- 16.89999999999997 75.
- 16.999999999999972 75.
- 17.099999999999973 75.
- 17.199999999999974 76.
- 17.299999999999976 76.
- 17.399999999999977 76.
- 17.499999999999979 76.
- 17.59999999999998 77.
- 17.699999999999982 77.
- 17.799999999999983 77.
- 17.899999999999984 77.
- 17.999999999999986 77.
- 18.099999999999987 78.
- 18.199999999999989 78.
- 18.29999999999999 78.
- 18.399999999999991 78.
- 18.499999999999993 78.
- 18.599999999999994 79.
- 18.699999999999996 79.
- 18.799999999999997 79.
- 18.899999999999999 79.
- 19 79.
- 19.100000000000001 80.
- 19.200000000000003 80.
- 19.300000000000004 80.
- 19.400000000000006 80.
- 19.500000000000007 80.
- 19.600000000000009 81.
- 19.70000000000001 81.
- 19.800000000000011 81.
- 19.900000000000013 81.
- 20.000000000000014 81.
- 20.100000000000016 82.
- 20.200000000000017 82.
- 20.300000000000018 82.
- 20.40000000000002 82.
- 20.500000000000021 83.
- 20.600000000000023 83.
- 20.700000000000024 83.
- 20.800000000000026 83.
- 20.900000000000027 83.
- 21.000000000000028 84.
- 21.10000000000003 84.
- 21.200000000000031 84.
- 21.300000000000033 84.
- 21.400000000000034 84.
- 21.500000000000036 85.
- 21.600000000000037 85.
- 21.700000000000038 85.
- 21.80000000000004 85.
- 21.900000000000041 85.
- 22.000000000000043 85.
- 22.100000000000044 86.
- 22.200000000000045 86.
- 22.300000000000047 86.
- 22.400000000000048 86.
- 22.50000000000005 86.
- 22.600000000000051 87.
- 22.700000000000053 87.
- 22.800000000000054 87.
- 22.900000000000055 87.
- 23.000000000000057 87.
- 23.100000000000058 88.
- 23.20000000000006 88.
- 23.300000000000061 88.
- 23.400000000000063 88.
- 23.500000000000064 88.
- 23.600000000000065 88.
- 23.700000000000067 89.
- 23.800000000000068 89.
- 23.90000000000007 89.
- 24.000000000000071 89.
- 24.100000000000072 89.
- 24.200000000000074 90.
- 24.300000000000075 90.
- 24.400000000000077 90.
- 24.500000000000078 90.
- 24.60000000000008 90.
- 24.700000000000081 90.
- 24.800000000000082 91.
- 24.900000000000084 91.
- 25.000000000000085 91.
- 25.100000000000087 91.
- 25.200000000000088 91.
- 25.30000000000009 92.
- 25.400000000000091 92.
- 25.500000000000092 92.
- 25.600000000000094 92.
- 25.700000000000095 92.
- 25.800000000000097 92.
- 25.900000000000098 93.
- 26.000000000000099 93.
- 26.100000000000101 93.
- 26.200000000000102 93.
- 26.300000000000104 93.
- 26.400000000000105 93.
- 26.500000000000107 94.
- 26.600000000000108 94.
- 26.700000000000109 94.
- 26.800000000000111 94.
- 26.900000000000112 94.
- 27.000000000000114 95.
- 27.100000000000115 95.
- 27.200000000000117 95.
- 27.300000000000118 95.
- 27.400000000000119 95.
- 27.500000000000121 95.
- 27.600000000000122 96.
- 27.700000000000124 96.
- 27.800000000000125 96.
- 27.900000000000126 96.
- 28.000000000000128 96.
- 28.100000000000129 96.
- 28.200000000000131 97.
- 28.300000000000132 97.
- 28.400000000000134 97.
- 28.500000000000135 97.
- 28.600000000000136 97.
- 28.700000000000138 97.
- 28.800000000000139 98.
- 28.900000000000141 98.
- 29.000000000000142 98.
- 29.100000000000144 98.
- 29.200000000000145 98.
- 29.300000000000146 98.
- 29.400000000000148 99.
- 29.500000000000149 99.
- 29.600000000000151 99.
- 29.700000000000152 99.
- 29.800000000000153 99.
- 29.900000000000155 99.
- 30.000000000000156 100.
- 30.100000000000158 100.
- 30.200000000000159 100.
- 30.300000000000161 100.
- 30.400000000000162 100.
- 30.500000000000163 100.
- 30.600000000000165 101.
- 30.700000000000166 101.
- 30.800000000000168 101.
- 30.900000000000169 101.
- 31.000000000000171 101.
- 31.100000000000172 101.
- 31.200000000000173 102.
- 31.300000000000175 102.
- 31.400000000000176 102.
- 31.500000000000178 102.
- 31.600000000000179 102.
- 31.70000000000018 102.
- 31.800000000000182 103.
- 31.900000000000183 103.
- 32.000000000000185 103.
- 32.100000000000186 103.
- 32.200000000000188 103.
- 32.300000000000189 103.
- 32.40000000000019 104.
- 32.500000000000192 104.
- 32.600000000000193 104.
- 32.700000000000195 104.
- 32.800000000000196 104.
- 32.900000000000198 104.
- 33.000000000000199 105.
- 33.1000000000002 105.
- 33.200000000000202 105.
- 33.300000000000203 105.
- 33.400000000000205 105.
- 33.500000000000206 105.
- 33.600000000000207 105.
- 33.700000000000209 106.
- 33.80000000000021 106.
- 33.900000000000212 106.
- 34.000000000000213 106.
- 34.100000000000215 106.
- 34.200000000000216 106.
- 34.300000000000217 107.
- 34.400000000000219 107.
- 34.50000000000022 107.
- 34.600000000000222 107.
- 34.700000000000223 107.
- 34.800000000000225 107.
- 34.900000000000226 108.
- 35.000000000000227 108.
- 35.100000000000229 108.
- 35.20000000000023 108.
- 35.300000000000232 108.
- 35.400000000000233 108.
- 35.500000000000234 108.
- 35.600000000000236 108.
- 35.700000000000237 109.
- 35.800000000000239 109.
- 35.90000000000024 109.
- 36.000000000000242 109.
- 36.100000000000243 109.
- 36.200000000000244 109.
- 36.300000000000246 110.
- 36.400000000000247 110.
- 36.500000000000249 110.
- 36.60000000000025 110.
- 36.700000000000252 110.
- 36.800000000000253 110.
- 36.900000000000254 110.
- 37.000000000000256 111.
- 37.100000000000257 111.
- 37.200000000000259 111.
- 37.30000000000026 111.
- 37.400000000000261 111.
- 37.500000000000263 111.
- 37.600000000000264 112.
- 37.700000000000266 112.
- 37.800000000000267 112.
- 37.900000000000269 112.
- 38.00000000000027 112.
- 38.100000000000271 112.
- 38.200000000000273 112.
- 38.300000000000274 113.
- 38.400000000000276 113.
- 38.500000000000277 113.
- 38.600000000000279 113.
- 38.70000000000028 113.
- 38.800000000000281 113.
- 38.900000000000283 113.
- 39.000000000000284 114.
- 39.100000000000286 114.
- 39.200000000000287 114.
- 39.300000000000288 114.
- 39.40000000000029 114.
- 39.500000000000291 114.
- 39.600000000000293 114.
- 39.700000000000294 115.
- 39.800000000000296 115.
- 39.900000000000297 115.
- 40.000000000000298 115.
- 40.1000000000003 115.
- 40.200000000000301 115.
- 40.300000000000303 115.
- 40.400000000000304 116.
- 40.500000000000306 116.
- 40.600000000000307 116.
- 40.700000000000308 116.
- 40.80000000000031 116.
- 40.900000000000311 116.
- 41.000000000000313 116.
- 41.100000000000314 117.
- 41.200000000000315 117.
- 41.300000000000317 117.
- 41.400000000000318 117.
- 41.50000000000032 117.
- 41.600000000000321 117.
- 41.700000000000323 117.
- 41.800000000000324 118.
- 41.900000000000325 118.