Sunteți pe pagina 1din 44

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 <color>][-bg <color>][-lw <int value>] <name>.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 n2
$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 n1
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
#Create a CBR Traffic source and attach to the UDP Agent
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
#Specify the Packet Size and interval
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
#Create a Null Agent and attach to the node n2
set null0 [new Agent/Null]
$ns attach-agent $n2 $null0
#Connect the CBR Traffic source to the Null agent
$ns connect $udp0 $null0
#Create a TCP agent and attach to the node n0
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0

#Create a FTP source and attach to the TCP agent


set ftp0 [new Application/FTP]
#Attach the FTP source to the TCP Agent
$ftp0 attach-agent $tcp0
#Create a TCPSink agent and attach to the node n2
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $sink
#Specify the Max file Size in Bytes
$ftp0 set maxPkts_ 1000
#Connect the TCP Agent with the TCPSink
$ns connect $tcp0 $sink
$udp0 set class_ 1
$tcp0 set class_ 2
#Schedule the Events
$ns at 0.1 "$cbr0 start"
$ns at 1.0 "$ftp0 start"
$ns at 4.0 "$ftp0 stop"
$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"
$ns run

File: 1.awk
#!/usr/bin/awk -f
BEGIN{
cbrPkt=0;
tcpPkt=0;
}
{
if(($1 == "d")&&($5 == "cbr")) {
cbrPkt = cbrPkt + 1;
}
if(($1 == "d")&&($5 == "tcp")) {
tcpPkt = tcpPkt + 1;
}
}

END {
printf "\nNo. of CBR Packets Dropped %d", cbrPkt;
printf "\nNo. of TCP Packets Dropped %d", tcpPkt;
}

File: 1.xg
TitleText: Performance Analysis (Bandwidth vs Packet Dropped)
XUnitText: Bandwidth(in Mbps)
YUnitText: No.of Packet Dropped
"CBR"
0.25 617
0.50 369
0.75 138
1.0 80
1.25 62
1.5 32
1.75 38
2.0 0
"TCP"
0.25 6
0.50 8
0.75 6
1.0 9
1.25 15
1.5 10
1.75 8
2.0 0

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
$ns
$ns
$ns

trace-all $f
namtrace-all $nf
color 1 "Blue"
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
set
set
set

n0
n1
n2
n3

[$ns
[$ns
[$ns
[$ns

node]
node]
node]
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 $udp0
$udp0 set class_ 2
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 1000


$cbr0 set interval_ 0.005

set null0 [new Agent/Null]


$ns attach-agent $n3 $null0
$ns connect $udp0 $null0
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
$tcp0 set class_ 1
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp0 $sink
$ns
$ns
$ns
$ns

at
at
at
at

0.1
1.0
4.0
4.5

"$cbr0 start"
"$ftp0 start"
"$ftp0 stop"
"$cbr0 stop"

$ns at 5.0 "finish"


$ns run

File: 2.awk
#!/usr/bin/awk -f
BEGIN {
TCPSend=0;
CBRSend=0;
TCPDrop=0;
CBRDrop=0;
TCPDropRatio=0.0;
UDPDropRatio=0.0;
TCPArrivalRatio=0.0;
CBRArrivalRatio=0.0;
}
{

src=$3;
des=$4;
type=$5;
event=$1;
if((src=="0")&&(des=="2")&&(event=="+")) {
TCPSend++;
}
if((src=="1")&&(des=="2")&&(event=="+")) {
CBRSend++;
}

if((event=="d")&&(type=="tcp")) {
TCPDrop++;
}
if((event=="d")&&(type=="cbr")) {
CBRDrop++;
}
}
END {

printf
printf
printf
printf

"\nTCPSend
"\nCBRSend
"\nTCPDrop
"\nCBRDrop

%d",
%d",
%d",
%d",

TCPSend;
CBRSend;
TCPDrop;
CBRDrop;

TCPArrivalRatio=((TCPSend-TCPDrop)/TCPSend);
TCPDropRatio=(TCPDrop/TCPSend);
UDPArrivalRatio=((CBRSend-CBRDrop)/CBRSend);
UDPDropRatio=(CBRDrop/CBRSend);
printf
printf
printf
printf

"\nTCPArrivalRatio %f", TCPArrivalRatio;


"\nTCPDropRatio %f", TCPDropRatio;
"\nUDPArrivalRatio %f", UDPArrivalRatio;
"\nUDPDropRatio %f", UDPDropRatio;

File: 2AR.xg
TitleText: Performance Analysis (Bandwidth vs Packet Arrival Ratio)
XUnitText: Bandwidth(in Mbps)
YUnitText: Packet arrival ratio
"TCP"
0.25 0.21
0.50 0.37
0.75 0.52
1.0 0.68
1.25 0.83
1.5 0.94
1.75 0.99
2.0 0.998
2.25 0.998
2.5 1
2.75 1
"CBR"
0.25 0.33
0.50 0.25
0.75 0.63
1.0 0.63
1.25 0.37
1.5 0.70
1.75 0.88
2.0 0.96
2.25 0.995
2.5 1
2.75 1

File: 2DR.xg
TitleText: Performance Analysis (Bandwidth vs Packet Arrival Ratio)
XUnitText: Bandwidth(in Mbps)
YUnitText: Packet arrival ratio
"TCP"
0.25 0.67
0.50 0.75
0.75 0.38
1.0 0.38
1.25 0.63
1.5 0.29
1.75 0.12
2.0 0.04
2.25 0.004
2.5 0
2.75 0
"CBR"
0.25 0.79
0.50 0.63
0.75 0.48
1.0 0.32
1.25 0.16
1.5 0.05
1.75 0.01
2.0 0.001
2.25 0.001
2.5 0
2.75 0

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]
$ns trace-all $f
$ns namtrace-all $nf
proc finish {} {
global ns f nf
$ns flush-trace
close $f
close $nf
exec nam out.nam &
exit 0
}
set
set
set
set
set
set

n0
n1
n2
n3
n4
n5

[$ns
[$ns
[$ns
[$ns
[$ns
[$ns

node]
node]
node]
node]
node]
node]

$n0
$n1
$n2
$n3
$n4
$n5

label
label
label
label
label
label

"ping0"
"ping1"
"R1"
"R2"
"ping4"
"ping5"

$ns
$ns
$ns
$ns

color
color
color
color

1
2
3
4

$ns
$ns
$ns
$ns
$ns

duplex-link
duplex-link
duplex-link
duplex-link
duplex-link

red
blue
green
orange
$n0
$n1
$n2
$n3
$n3

$n2
$n2
$n3
$n4
$n5

1Mb 10ms DropTail


1Mb 10ms DropTail
0.4Mb 30ms DropTail
1Mb 10ms DropTail
1Mb 10ms DropTail

set ping0 [new Agent/Ping]


$ns attach-agent $n0 $ping0
set ping1 [new Agent/Ping]
$ns attach-agent $n1 $ping1
set ping4 [new Agent/Ping]
$ns attach-agent $n4 $ping4
set ping5 [new Agent/Ping]
$ns attach-agent $n5 $ping5
$ns connect $ping0 $ping4
$ns connect $ping1 $ping5
proc sendPingPacket {} {
global ns ping0 ping1

set
set
$ns
$ns
$ns

intervalTime 0.001
now [$ns now]
at [expr $now + $intervalTime] "$ping0 send"
at [expr $now + $intervalTime] "$ping1 send"
at [expr $now + $intervalTime] "sendPingPacket"

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
$ping1
$ping4
$ping5

set
set
set
set

class_
class_
class_
class_

1
2
4
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
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0

17960
16011
14062
12113
10164
8216
6267
4318
2369
420

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=((totalPktReceived*500*8)/(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
""
0.00 0.569

0.01 0.5425
0.02 0.539
0.03 0.5275
0.04 0.5295
0.05 0.507
0.06 0.5065
0.07 0.481
0.08 0.4755
0.09 0.464
0.1 0.4595

Program - 5
Question
Simulate an Ethernet LAN using n nodes and set multiple traffic nodes
and plot congestion window for different source / destination.

File : 5.tcl
#set up a new instance of Simulator
set ns [new Simulator]
#Open the trace file and animation file
set f [open 5.tr w]
set nf [open 5.nam w]
$ns trace-all $f
$ns namtrace-all $nf
#Define the finish Procedure
proc finish {} {
global ns f nf outFile1 outFile2
$ns flush-trace
close $f
close $nf
exec nam 5.nam &
exec xgraph Congestion1.xg -geometry 400x400 &
exec xgraph Congestion2.xg -geometry 400x400 &
exit 0
}
$ns color 1 red

$ns color 2 green


#set up the
set n0 [$ns
set n1 [$ns
set n2 [$ns
set n3 [$ns
set n4 [$ns
set n5 [$ns
set n6 [$ns
set n7 [$ns

nodes
node]
node]
node]
node]
node]
node]
node]
node]

#Label the nodes


$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_3
#Set up the TCP Agents
set tcp1 [new Agent/TCP]
$ns attach-agent $n0 $tcp1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set sink1 [new Agent/TCPSink]
$ns attach-agent $n3 $sink1
$ns connect $tcp1 $sink1
$tcp1 set class_ 1
#Set up the telnet
set tcp2 [new Agent/TCP]
$ns attach-agent $n5 $tcp2
set telnet1 [new Application/FTP]
$telnet1 attach-agent $tcp2
set sink2 [new Agent/TCPSink]
$ns attach-agent $n7 $sink2
$ns connect $tcp2 $sink2
$telnet1 set type_ $sink2
$tcp2 set class_ 2
set outFile1 [open Congestion1.xg w]
set outFile2 [open Congestion2.xg w]
puts
puts
puts
puts
puts
puts

$outFile1
$outFile1
$outFile1
$outFile2
$outFile2
$outFile2

"TitleText:
"XUnitText:
"YUnitText:
"TitleText:
"XUnitText:
"YUnitText:

Congestion Window Plot for TCP1"


SimulationTime(Secs)"
CongestionWindowSize"
Congestion Window Plot for TCP2"
SimulationTime(Secs)"
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
TitleText: Congestion Window Plot for TCP1
XUnitText: SimulationTime(Secs)
YUnitText: CongestionWindowSize
0 1
0.10000000000000001 1
0.20000000000000001 1
0.30000000000000004 1
0.40000000000000002 1
0.5 2
0.59999999999999998 4
0.69999999999999996 8
0.79999999999999993 16
0.89999999999999991 16
0.99999999999999989 20.592
1.0999999999999999 21.5424
1.2 22.4525
1.3 23.3271
1.4000000000000001 23.9621
1.5000000000000002 24.17
1.6000000000000003 24.9845
1.7000000000000004 25.7731
1.8000000000000005 26.5383
1.9000000000000006 27.2821
2.0000000000000004 27.6464
2.1000000000000005 28.006
2.2000000000000006 28.7117
2.3000000000000007 29.4004
2.4000000000000008 30.0734
2.5000000000000009 30.7316
2.600000000000001 30.8939
2.7000000000000011 31.376
2.8000000000000012 32.0074
2.9000000000000012 32.6265
3.0000000000000013 33.2341
3.1000000000000014 33.8308
3.2000000000000015 33.8308
3.3000000000000016 34.4172
3.4000000000000017 34.9937
3.5000000000000018 35.5609
3.6000000000000019 36.1191
3.700000000000002 36.6416
3.800000000000002 36.6689
3.9000000000000021 37.2105
4.0000000000000018 37.7443
4.1000000000000014 38.2707

4.2000000000000011 38.79
4.3000000000000007 39.1238
4.4000000000000004 39.3024
4.5 39.8082
4.5999999999999996 40.3076
4.6999999999999993 40.8009
4.7999999999999989 41.2883
4.8999999999999986 41.4817
4.9999999999999982 41.77
5.0999999999999979 42.2463
5.1999999999999975 42.7172
5.2999999999999972 43.183
5.3999999999999968 43.6438
5.4999999999999964 43.7125
5.5999999999999961 44.0998
5.6999999999999957 44.5511
5.7999999999999954 44.9979
5.899999999999995 45.4403
5.9999999999999947 45.8784
6.0999999999999943 45.8784
6.199999999999994 46.3124
6.2999999999999936 46.7424
6.3999999999999932 47.1684
6.4999999999999929 47.5906
6.5999999999999925 47.9466
6.6999999999999922 48.0091
6.7999999999999918 48.424
6.8999999999999915 48.8354
6.9999999999999911 49.2433
7.0999999999999908 49.6479
7.1999999999999904 49.869
7.2999999999999901 50.0492
7.3999999999999897 50.4473
7.4999999999999893 50.8422
7.599999999999989 51.2342
7.6999999999999886 51.6231
7.7999999999999883 51.7393
7.8999999999999879 52.0092
7.9999999999999876 52.3924
8.0999999999999872 52.7728
8.1999999999999869 53.1505
8.2999999999999865 53.5256
8.3999999999999861 53.5442
8.4999999999999858 53.898
8.5999999999999854 54.2678
8.6999999999999851 54.6352
8.7999999999999847 55.0001
8.8999999999999844 55.3626
8.999999999999984 55.3626
9.0999999999999837 55.7228
9.1999999999999833 56.0806
9.2999999999999829 56.4361
9.3999999999999826 56.7895
9.4999999999999822 57.053
9.5999999999999819 57.1406
9.6999999999999815 57.4896
9.7999999999999812 57.8365
9.8999999999999808 58.1813
9.9999999999999805 58.5241
10.09999999999998 58.6948
10.19999999999998 58.8649

10.299999999999979 59.2038
10.399999999999979 59.5407
10.499999999999979 59.8757
10.599999999999978 60.2088
10.699999999999978 60.2752
10.799999999999978 60.5401
10.899999999999977 60.8696
10.999999999999977 61.1974
11.099999999999977 61.5234
11.199999999999976 61.8476
11.299999999999976 61.8476
11.399999999999975 62.1702
11.499999999999975 62.4911
11.599999999999975 62.8104
11.699999999999974 63.128
11.799999999999974 63.4126
11.899999999999974 63.4441
11.999999999999973 63.7586
12.099999999999973 64.0716
12.199999999999973 64.383
12.299999999999972 64.6929
12.399999999999972 64.8936
12.499999999999972 65.0014
12.599999999999971 65.3084
12.699999999999971 65.6139
12.799999999999971 65.9181
12.89999999999997 66.2208
12.99999999999997 66.3415
13.099999999999969 66.5222
13.199999999999969 66.8222
13.299999999999969 67.1209
13.399999999999968 67.4182
13.499999999999968 67.7143
13.599999999999968 67.7438
13.699999999999967 68.009
13.799999999999967 68.3025
13.899999999999967 68.5947
13.999999999999966 68.8857
14.099999999999966 69.1754
14.199999999999966 69.1754
14.299999999999965 69.464
14.399999999999965 69.7513
14.499999999999964 70.0375
14.599999999999964 70.3225
14.699999999999964 70.5497
14.799999999999963 70.6064
14.899999999999963 70.8891
14.999999999999963 71.1707
15.099999999999962 71.4512
15.199999999999962 71.7306
15.299999999999962 71.8838
15.399999999999961 72.0089
15.499999999999961 72.2861
15.599999999999961 72.5623
15.69999999999996 72.8374
15.79999999999996 73.1115
15.899999999999959 73.1936
15.999999999999959 73.3846
16.099999999999959 73.6567
16.19999999999996 73.9277
16.299999999999962 74.1978

16.399999999999963 74.4669
16.499999999999964 74.4669
16.599999999999966 74.735
16.699999999999967 75.0021
16.799999999999969 75.2684
16.89999999999997 75.5336
16.999999999999972 75.798
17.099999999999973 75.798
17.199999999999974 76.0614
17.299999999999976 76.3239
17.399999999999977 76.5855
17.499999999999979 76.8463
17.59999999999998 77.0282
17.699999999999982 77.1061
17.799999999999983 77.3651
17.899999999999984 77.6232
17.999999999999986 77.8804
18.099999999999987 78.1368
18.199999999999989 78.2519
18.29999999999999 78.3924
18.399999999999991 78.6471
18.499999999999993 78.901
18.599999999999994 79.1541
18.699999999999996 79.4064
18.799999999999997 79.4568
18.899999999999999 79.6579
19 79.9086
19.100000000000001 80.1585
19.200000000000003 80.4077
19.300000000000004 80.656
19.400000000000006 80.656
19.500000000000007 80.9036
19.600000000000009 81.1505
19.70000000000001 81.3966
19.800000000000011 81.6419
19.900000000000013 81.8621
20.000000000000014 81.8866
20.100000000000016 82.1305
20.200000000000017 82.3736
20.300000000000018 82.6161
20.40000000000002 82.8578
20.500000000000021 83.0026
20.600000000000023 83.0989
20.700000000000024 83.3392
20.800000000000026 83.5789
20.900000000000027 83.8179
21.000000000000028 84.0561
21.10000000000003 84.1394
21.200000000000031 84.2938
21.300000000000033 84.5307
21.400000000000034 84.767
21.500000000000036 85.0026
21.600000000000037 85.2376
21.700000000000038 85.2611
21.80000000000004 85.4719
21.900000000000041 85.7056
22.000000000000043 85.9387
22.100000000000044 86.1711
22.200000000000045 86.4029
22.300000000000047 86.4029
22.400000000000048 86.6341

22.50000000000005 86.8647
22.600000000000051 87.0946
22.700000000000053 87.324
22.800000000000054 87.507
22.900000000000055 87.5527
23.000000000000057 87.7809
23.100000000000058 88.0084
23.20000000000006 88.2354
23.300000000000061 88.4618
23.400000000000063 88.5748
23.500000000000064 88.6876
23.600000000000065 88.9128
23.700000000000067 89.1375
23.800000000000068 89.3616
23.90000000000007 89.5852
24.000000000000071 89.641
24.100000000000072 89.8081
24.200000000000074 90.0306
24.300000000000075 90.2525
24.400000000000077 90.4738
24.500000000000078 90.6946
24.60000000000008 90.6946
24.700000000000081 90.9149
24.800000000000082 91.1346
24.900000000000084 91.3538
25.000000000000085 91.5725
25.100000000000087 91.7798
25.200000000000088 91.7907
25.30000000000009 92.0083
25.400000000000091 92.2254
25.500000000000092 92.442
25.600000000000094 92.6582
25.700000000000095 92.8091
25.800000000000097 92.8738
25.900000000000098 93.0889
26.000000000000099 93.3035
26.100000000000101 93.5176
26.200000000000102 93.7312
26.300000000000104 93.8166
26.400000000000105 93.9444
26.500000000000107 94.157
26.600000000000108 94.3692
26.700000000000109 94.5809
26.800000000000111 94.7922
26.900000000000112 94.8238
27.000000000000114 95.0029
27.100000000000115 95.2132
27.200000000000117 95.4231
27.300000000000118 95.6324
27.400000000000119 95.8414
27.500000000000121 95.8414
27.600000000000122 96.0498
27.700000000000124 96.2578
27.800000000000125 96.4654
27.900000000000126 96.6725
28.000000000000128 96.8482
28.100000000000129 96.8792
28.200000000000131 97.0854
28.300000000000132 97.2912
28.400000000000134 97.4966
28.500000000000135 97.7015

28.600000000000136 97.8243
28.700000000000138 97.906
28.800000000000139 98.1101
28.900000000000141 98.3137
29.000000000000142 98.517
29.100000000000144 98.7198
29.200000000000145 98.7907
29.300000000000146 98.9222
29.400000000000148 99.1242
29.500000000000149 99.3257
29.600000000000151 99.5269
29.700000000000152 99.7277
29.800000000000153 99.7377
29.900000000000155 99.928
30.000000000000156 100.128
30.100000000000158 100.328
30.200000000000159 100.527
30.300000000000161 100.725
30.400000000000162 100.725
30.500000000000163 100.924
30.600000000000165 101.122
30.700000000000166 101.319
30.800000000000168 101.517
30.900000000000169 101.664
31.000000000000171 101.713
31.100000000000172 101.91
31.200000000000173 102.106
31.300000000000175 102.302
31.400000000000176 102.497
31.500000000000178 102.595
31.600000000000179 102.692
31.70000000000018 102.887
31.800000000000182 103.081
31.900000000000183 103.275
32.000000000000185 103.468
32.100000000000186 103.516
32.200000000000188 103.661
32.300000000000189 103.854
32.40000000000019 104.046
32.500000000000192 104.238
32.600000000000193 104.43
32.700000000000195 104.43
32.800000000000196 104.621
32.900000000000198 104.812
33.000000000000199 105.003
33.1000000000002 105.193
33.200000000000202 105.364
33.300000000000203 105.383
33.400000000000205 105.573
33.500000000000206 105.762
33.600000000000207 105.951
33.700000000000209 106.14
33.80000000000021 106.262
33.900000000000212 106.328
34.000000000000213 106.516
34.100000000000215 106.704
34.200000000000216 106.891
34.300000000000217 107.078
34.400000000000219 107.153
34.50000000000022 107.265
34.600000000000222 107.451

34.700000000000223 107.637
34.800000000000225 107.822
34.900000000000226 108.008
35.000000000000227 108.036
35.100000000000229 108.193
35.20000000000023 108.378
35.300000000000232 108.562
35.400000000000233 108.746
35.500000000000234 108.93
35.600000000000236 108.93
35.700000000000237 109.113
35.800000000000239 109.296
35.90000000000024 109.479
36.000000000000242 109.662
36.100000000000243 109.817
36.200000000000244 109.844
36.300000000000246 110.026
36.400000000000247 110.208
36.500000000000249 110.389
36.60000000000025 110.57
36.700000000000252 110.669
36.800000000000253 110.751
36.900000000000254 110.931
37.000000000000256 111.111
37.100000000000257 111.291
37.200000000000259 111.471
37.30000000000026 111.525
37.400000000000261 111.65
37.500000000000263 111.829
37.600000000000264 112.008
37.700000000000266 112.186
37.800000000000267 112.364
37.900000000000269 112.373
38.00000000000027 112.542
38.100000000000271 112.72
38.200000000000273 112.897
38.300000000000274 113.074
38.400000000000276 113.251
38.500000000000277 113.251
38.600000000000279 113.427
38.70000000000028 113.603
38.800000000000281 113.779
38.900000000000283 113.955
39.000000000000284 114.087
39.100000000000286 114.13
39.200000000000287 114.305
39.300000000000288 114.48
39.40000000000029 114.655
39.500000000000291 114.829
39.600000000000293 114.908
39.700000000000294 115.003
39.800000000000296 115.177
39.900000000000297 115.351
40.000000000000298 115.524
40.1000000000003 115.697
40.200000000000301 115.731
40.300000000000303 115.87
40.400000000000304 116.042
40.500000000000306 116.214
40.600000000000307 116.386
40.700000000000308 116.558

40.80000000000031 116.558
40.900000000000311 116.729
41.000000000000313 116.901
41.100000000000314 117.072
41.200000000000315 117.242
41.300000000000317 117.396
41.400000000000318 117.413
41.50000000000032 117.583
41.600000000000321 117.753
41.700000000000323 117.923
41.800000000000324 118.092
41.900000000000325 118.202
42.000000000000327 118.261
42.100000000000328 118.43
42.20000000000033 118.599
42.300000000000331 118.768
42.400000000000333 118.936
42.500000000000334 118.995
42.600000000000335 119.104
42.700000000000337 119.272
42.800000000000338 119.439
42.90000000000034 119.607
43.000000000000341 119.774
43.100000000000342 119.791
43.200000000000344 119.941
43.300000000000345 120.107
43.400000000000347 120.274
43.500000000000348 120.44
43.60000000000035 120.606
43.700000000000351 120.606
43.800000000000352 120.772
43.900000000000354 120.937
44.000000000000355 121.102
44.100000000000357 121.267
44.200000000000358 121.399
44.30000000000036 121.432
44.400000000000361 121.597
44.500000000000362 121.761
44.600000000000364 121.925
44.700000000000365 122.089
44.800000000000367 122.179
44.900000000000368 122.253
45.000000000000369 122.417
45.100000000000371 122.58
45.200000000000372 122.743
45.300000000000374 122.906
45.400000000000375 122.946
45.500000000000377 123.068
45.600000000000378 123.231
45.700000000000379 123.393
45.800000000000381 123.555
45.900000000000382 123.717
46.000000000000384 123.717
46.100000000000385 123.878
46.200000000000387 124.04
46.300000000000388 124.201
46.400000000000389 124.362
46.500000000000391 124.514
46.600000000000392 124.522
46.700000000000394 124.683
46.800000000000395 124.843

46.900000000000396
47.000000000000398
47.100000000000399
47.200000000000401
47.300000000000402
47.400000000000404
47.500000000000405
47.600000000000406
47.700000000000408
47.800000000000409
47.900000000000411
48.000000000000412
48.100000000000414
48.200000000000415
48.300000000000416
48.400000000000418
48.500000000000419
48.600000000000421
48.700000000000422
48.800000000000423
48.900000000000425
49.000000000000426
49.100000000000428
49.200000000000429
49.300000000000431
49.400000000000432
49.500000000000433
49.600000000000435
49.700000000000436
49.800000000000438
49.900000000000439

125.003
125.163
125.275
125.323
125.482
125.642
125.801
125.96
126.031
126.118
126.277
126.435
126.593
126.751
126.775
126.909
127.066
127.224
127.381
127.538
127.538
127.694
127.851
128.007
128.163
128.296
128.319
128.475
128.631
128.786
128.941

File: Congestion2.xg
TitleText: Congestion Window Plot for TCP2
XUnitText: SimulationTime(Secs)
YUnitText: CongestionWindowSize
0.10000000000000001 1
0.20000000000000001 1
0.30000000000000004 1
0.40000000000000002 1
0.5 1
0.59999999999999998 1
0.69999999999999996 2
0.79999999999999993 4
0.89999999999999991 8
0.99999999999999989 16
1.0999999999999999 16
1.2 20.592
1.3 21.5424
1.4000000000000001 22.4525
1.5000000000000002 23.3271
1.6000000000000003 23.9621
1.7000000000000004 24.17
1.8000000000000005 24.9845
1.9000000000000006 25.7731
2.0000000000000004 26.5383
2.1000000000000005 27.2821
2.2000000000000006 27.6464

2.3000000000000007 28.006
2.4000000000000008 28.7117
2.5000000000000009 29.4004
2.600000000000001 30.0734
2.7000000000000011 30.7316
2.8000000000000012 30.8939
2.9000000000000012 31.376
3.0000000000000013 32.0074
3.1000000000000014 32.6265
3.2000000000000015 33.2341
3.3000000000000016 33.8308
3.4000000000000017 33.8308
3.5000000000000018 34.4172
3.6000000000000019 34.9937
3.700000000000002 35.5609
3.800000000000002 36.1191
3.9000000000000021 36.6416
4.0000000000000018 36.6689
4.1000000000000014 37.2105
4.2000000000000011 37.7443
4.3000000000000007 38.2707
4.4000000000000004 38.79
4.5 39.1238
4.5999999999999996 39.3024
4.6999999999999993 39.8082
4.7999999999999989 40.3076
4.8999999999999986 40.8009
4.9999999999999982 41.2883
5.0999999999999979 41.4817
5.1999999999999975 41.77
5.2999999999999972 42.2463
5.3999999999999968 42.7172
5.4999999999999964 43.183
5.5999999999999961 43.6438
5.6999999999999957 43.7125
5.7999999999999954 44.0998
5.899999999999995 44.5511
5.9999999999999947 44.9979
6.0999999999999943 45.4403
6.199999999999994 45.8784
6.2999999999999936 45.8784
6.3999999999999932 46.3124
6.4999999999999929 46.7424
6.5999999999999925 47.1684
6.6999999999999922 47.5906
6.7999999999999918 47.9466
6.8999999999999915 48.0091
6.9999999999999911 48.424
7.0999999999999908 48.8354
7.1999999999999904 49.2433
7.2999999999999901 49.6479
7.3999999999999897 49.869
7.4999999999999893 50.0492
7.599999999999989 50.4473
7.6999999999999886 50.8422
7.7999999999999883 51.2342
7.8999999999999879 51.6231
7.9999999999999876 51.7393
8.0999999999999872 52.0092
8.1999999999999869 52.3924
8.2999999999999865 52.7728

8.3999999999999861 53.1505
8.4999999999999858 53.5256
8.5999999999999854 53.5442
8.6999999999999851 53.898
8.7999999999999847 54.2678
8.8999999999999844 54.6352
8.999999999999984 55.0001
9.0999999999999837 55.3626
9.1999999999999833 55.3626
9.2999999999999829 55.7228
9.3999999999999826 56.0806
9.4999999999999822 56.4361
9.5999999999999819 56.7895
9.6999999999999815 57.053
9.7999999999999812 57.1406
9.8999999999999808 57.4896
9.9999999999999805 57.8365
10.09999999999998 58.1813
10.19999999999998 58.5241
10.299999999999979 58.6948
10.399999999999979 58.8649
10.499999999999979 59.2038
10.599999999999978 59.5407
10.699999999999978 59.8757
10.799999999999978 60.2088
10.899999999999977 60.2752
10.999999999999977 60.5401
11.099999999999977 60.8696
11.199999999999976 61.1974
11.299999999999976 61.5234
11.399999999999975 61.8476
11.499999999999975 61.8476
11.599999999999975 62.1702
11.699999999999974 62.4911
11.799999999999974 62.8104
11.899999999999974 63.128
11.999999999999973 63.4126
12.099999999999973 63.4441
12.199999999999973 63.7586
12.299999999999972 64.0716
12.399999999999972 64.383
12.499999999999972 64.6929
12.599999999999971 64.8936
12.699999999999971 65.0014
12.799999999999971 65.3084
12.89999999999997 65.6139
12.99999999999997 65.9181
13.099999999999969 66.2208
13.199999999999969 66.3415
13.299999999999969 66.5222
13.399999999999968 66.8222
13.499999999999968 67.1209
13.599999999999968 67.4182
13.699999999999967 67.7143
13.799999999999967 67.7438
13.899999999999967 68.009
13.999999999999966 68.3025
14.099999999999966 68.5947
14.199999999999966 68.8857
14.299999999999965 69.1754
14.399999999999965 69.1754

14.499999999999964 69.464
14.599999999999964 69.7513
14.699999999999964 70.0375
14.799999999999963 70.3225
14.899999999999963 70.5497
14.999999999999963 70.6064
15.099999999999962 70.8891
15.199999999999962 71.1707
15.299999999999962 71.4512
15.399999999999961 71.7306
15.499999999999961 71.8838
15.599999999999961 72.0089
15.69999999999996 72.2861
15.79999999999996 72.5623
15.899999999999959 72.8374
15.999999999999959 73.1115
16.099999999999959 73.1936
16.19999999999996 73.3846
16.299999999999962 73.6567
16.399999999999963 73.9277
16.499999999999964 74.1978
16.599999999999966 74.4669
16.699999999999967 74.4669
16.799999999999969 74.735
16.89999999999997 75.0021
16.999999999999972 75.2684
17.099999999999973 75.5336
17.199999999999974 75.798
17.299999999999976 75.798
17.399999999999977 76.0614
17.499999999999979 76.3239
17.59999999999998 76.5855
17.699999999999982 76.8463
17.799999999999983 77.0282
17.899999999999984 77.1061
17.999999999999986 77.3651
18.099999999999987 77.6232
18.199999999999989 77.8804
18.29999999999999 78.1368
18.399999999999991 78.2519
18.499999999999993 78.3924
18.599999999999994 78.6471
18.699999999999996 78.901
18.799999999999997 79.1541
18.899999999999999 79.4064
19 79.4568
19.100000000000001 79.6579
19.200000000000003 79.9086
19.300000000000004 80.1585
19.400000000000006 80.4077
19.500000000000007 80.656
19.600000000000009 80.656
19.70000000000001 80.9036
19.800000000000011 81.1505
19.900000000000013 81.3966
20.000000000000014 81.6419
20.100000000000016 81.8621
20.200000000000017 81.8866
20.300000000000018 82.1305
20.40000000000002 82.3736
20.500000000000021 82.6161

20.600000000000023 82.8578
20.700000000000024 83.0026
20.800000000000026 83.0989
20.900000000000027 83.3392
21.000000000000028 83.5789
21.10000000000003 83.8179
21.200000000000031 84.0561
21.300000000000033 84.1394
21.400000000000034 84.2938
21.500000000000036 84.5307
21.600000000000037 84.767
21.700000000000038 85.0026
21.80000000000004 85.2376
21.900000000000041 85.2611
22.000000000000043 85.4719
22.100000000000044 85.7056
22.200000000000045 85.9387
22.300000000000047 86.1711
22.400000000000048 86.4029
22.50000000000005 86.4029
22.600000000000051 86.6341
22.700000000000053 86.8647
22.800000000000054 87.0946
22.900000000000055 87.324
23.000000000000057 87.507
23.100000000000058 87.5527
23.20000000000006 87.7809
23.300000000000061 88.0084
23.400000000000063 88.2354
23.500000000000064 88.4618
23.600000000000065 88.5748
23.700000000000067 88.6876
23.800000000000068 88.9128
23.90000000000007 89.1375
24.000000000000071 89.3616
24.100000000000072 89.5852
24.200000000000074 89.641
24.300000000000075 89.8081
24.400000000000077 90.0306
24.500000000000078 90.2525
24.60000000000008 90.4738
24.700000000000081 90.6946
24.800000000000082 90.6946
24.900000000000084 90.9149
25.000000000000085 91.1346
25.100000000000087 91.3538
25.200000000000088 91.5725
25.30000000000009 91.7798
25.400000000000091 91.7907
25.500000000000092 92.0083
25.600000000000094 92.2254
25.700000000000095 92.442
25.800000000000097 92.6582
25.900000000000098 92.8091
26.000000000000099 92.8738
26.100000000000101 93.0889
26.200000000000102 93.3035
26.300000000000104 93.5176
26.400000000000105 93.7312
26.500000000000107 93.8166
26.600000000000108 93.9444

26.700000000000109 94.157
26.800000000000111 94.3692
26.900000000000112 94.5809
27.000000000000114 94.7922
27.100000000000115 94.8238
27.200000000000117 95.0029
27.300000000000118 95.2132
27.400000000000119 95.4231
27.500000000000121 95.6324
27.600000000000122 95.8414
27.700000000000124 95.8414
27.800000000000125 96.0498
27.900000000000126 96.2578
28.000000000000128 96.4654
28.100000000000129 96.6725
28.200000000000131 96.8482
28.300000000000132 96.8792
28.400000000000134 97.0854
28.500000000000135 97.2912
28.600000000000136 97.4966
28.700000000000138 97.7015
28.800000000000139 97.8243
28.900000000000141 97.906
29.000000000000142 98.1101
29.100000000000144 98.3137
29.200000000000145 98.517
29.300000000000146 98.7198
29.400000000000148 98.7907
29.500000000000149 98.9222
29.600000000000151 99.1242
29.700000000000152 99.3257
29.800000000000153 99.5269
29.900000000000155 99.7277
30.000000000000156 99.7377
30.100000000000158 99.928
30.200000000000159 100.128
30.300000000000161 100.328
30.400000000000162 100.527
30.500000000000163 100.725
30.600000000000165 100.725
30.700000000000166 100.924
30.800000000000168 101.122
30.900000000000169 101.319
31.000000000000171 101.517
31.100000000000172 101.664
31.200000000000173 101.713
31.300000000000175 101.91
31.400000000000176 102.106
31.500000000000178 102.302
31.600000000000179 102.497
31.70000000000018 102.595
31.800000000000182 102.692
31.900000000000183 102.887
32.000000000000185 103.081
32.100000000000186 103.275
32.200000000000188 103.468
32.300000000000189 103.516
32.40000000000019 103.661
32.500000000000192 103.854
32.600000000000193 104.046
32.700000000000195 104.238

32.800000000000196 104.43
32.900000000000198 104.43
33.000000000000199 104.621
33.1000000000002 104.812
33.200000000000202 105.003
33.300000000000203 105.193
33.400000000000205 105.364
33.500000000000206 105.383
33.600000000000207 105.573
33.700000000000209 105.762
33.80000000000021 105.951
33.900000000000212 106.14
34.000000000000213 106.262
34.100000000000215 106.328
34.200000000000216 106.516
34.300000000000217 106.704
34.400000000000219 106.891
34.50000000000022 107.078
34.600000000000222 107.153
34.700000000000223 107.265
34.800000000000225 107.451
34.900000000000226 107.637
35.000000000000227 107.822
35.100000000000229 108.008
35.20000000000023 108.036
35.300000000000232 108.193
35.400000000000233 108.378
35.500000000000234 108.562
35.600000000000236 108.746
35.700000000000237 108.93
35.800000000000239 108.93
35.90000000000024 109.113
36.000000000000242 109.296
36.100000000000243 109.479
36.200000000000244 109.662
36.300000000000246 109.817
36.400000000000247 109.844
36.500000000000249 110.026
36.60000000000025 110.208
36.700000000000252 110.389
36.800000000000253 110.57
36.900000000000254 110.669
37.000000000000256 110.751
37.100000000000257 110.931
37.200000000000259 111.111
37.30000000000026 111.291
37.400000000000261 111.471
37.500000000000263 111.525
37.600000000000264 111.65
37.700000000000266 111.829
37.800000000000267 112.008
37.900000000000269 112.186
38.00000000000027 112.364
38.100000000000271 112.373
38.200000000000273 112.542
38.300000000000274 112.72
38.400000000000276 112.897
38.500000000000277 113.074
38.600000000000279 113.251
38.70000000000028 113.251
38.800000000000281 113.427

38.900000000000283 113.603
39.000000000000284 113.779
39.100000000000286 113.955
39.200000000000287 114.087
39.300000000000288 114.13
39.40000000000029 114.305
39.500000000000291 114.48
39.600000000000293 114.655
39.700000000000294 114.829
39.800000000000296 114.908
39.900000000000297 115.003
40.000000000000298 115.177
40.1000000000003 115.351
40.200000000000301 115.524
40.300000000000303 115.697
40.400000000000304 115.731
40.500000000000306 115.87
40.600000000000307 116.042
40.700000000000308 116.214
40.80000000000031 116.386
40.900000000000311 116.558
41.000000000000313 116.558
41.100000000000314 116.729
41.200000000000315 116.901
41.300000000000317 117.072
41.400000000000318 117.242
41.50000000000032 117.396
41.600000000000321 117.413
41.700000000000323 117.583
41.800000000000324 117.753
41.900000000000325 117.923
42.000000000000327 118.092
42.100000000000328 118.202
42.20000000000033 118.261
42.300000000000331 118.43
42.400000000000333 118.599
42.500000000000334 118.768
42.600000000000335 118.936
42.700000000000337 118.995
42.800000000000338 119.104
42.90000000000034 119.272
43.000000000000341 119.439
43.100000000000342 119.607
43.200000000000344 119.774
43.300000000000345 119.791
43.400000000000347 119.941
43.500000000000348 120.107
43.60000000000035 120.274
43.700000000000351 120.44
43.800000000000352 120.606
43.900000000000354 120.606
44.000000000000355 120.772
44.100000000000357 120.937
44.200000000000358 121.102
44.30000000000036 121.267
44.400000000000361 121.399
44.500000000000362 121.432
44.600000000000364 121.597
44.700000000000365 121.761
44.800000000000367 121.925
44.900000000000368 122.089

45.000000000000369
45.100000000000371
45.200000000000372
45.300000000000374
45.400000000000375
45.500000000000377
45.600000000000378
45.700000000000379
45.800000000000381
45.900000000000382
46.000000000000384
46.100000000000385
46.200000000000387
46.300000000000388
46.400000000000389
46.500000000000391
46.600000000000392
46.700000000000394
46.800000000000395
46.900000000000396
47.000000000000398
47.100000000000399
47.200000000000401
47.300000000000402
47.400000000000404
47.500000000000405
47.600000000000406
47.700000000000408
47.800000000000409
47.900000000000411
48.000000000000412
48.100000000000414
48.200000000000415
48.300000000000416
48.400000000000418
48.500000000000419
48.600000000000421
48.700000000000422
48.800000000000423
48.900000000000425
49.000000000000426
49.100000000000428
49.200000000000429
49.300000000000431
49.400000000000432
49.500000000000433
49.600000000000435
49.700000000000436
49.800000000000438
49.900000000000439

122.179
122.253
122.417
122.58
122.743
122.906
122.946
123.068
123.231
123.393
123.555
123.717
123.717
123.878
124.04
124.201
124.362
124.514
124.522
124.683
124.843
125.003
125.163
125.275
125.323
125.482
125.642
125.801
125.96
126.031
126.118
126.277
126.435
126.593
126.751
126.775
126.909
127.066
127.224
127.381
127.538
127.538
127.694
127.851
128.007
128.163
128.296
128.319
128.475
128.631

Program - 6
Question
Simulate simple ESS and with transmitting nodes in wire-less LAN by simulation and
determine the performance with respect to transmission of packets.

File : p6.tcl
if {$argc != 1} {
error "Command: ns <ScriptName.tcl> <Number_of_Nodes>"
exit 0
}
#Define the simulation options
set val(chan)
Channel/WirelessChannel
set val(prop)
Propagation/TwoRayGround
set val(ant)
Antenna/OmniAntenna
set val(ll)
LL
set val(ifq)
Queue/DropTail/PriQueue
set val(ifqlen)
50
set val(netif)
Phy/WirelessPhy
set val(mac)
Mac/802_11
set val(rp)
AODV
set val(nn)
[lindex $argv 0]
set opt(x)
750
set opt(y)
750
set val(stop)
100
set ns [new Simulator]
set trfd [open Wireless.tr w]
set namfd [open Wireless.nam w]
$ns trace-all $trfd
$ns namtrace-all-wireless $namfd $opt(x) $opt(y)
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)
set god_ [create-god $val(nn)]
#Configure the nodes
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-channelType $val(chan) \
-propType $val(prop) \
-antType $val(ant) \
-ifqLen $val(ifqlen) \
-phyType $val(netif) \
-topoInstance $topo \

-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF
for {set i 0} {$i < $val(nn)} {incr i} {
set n($i) [$ns node]
}
#Randomly placing the nodes
for {set i 0} {$i < $val(nn)} {incr i} {
set XX [expr rand()*750]
set YY [expr rand()*750]
$n($i) set X_ $XX
$n($i) set Y_ $YY
}
for {set i 0} {$i < $val(nn)} {incr i} {
$ns initial_node_pos $n($i) 30
}
set tcp1 [new Agent/TCP]
$ns attach-agent $n(1) $tcp1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set sink1 [new Agent/TCPSink]
$ns attach-agent $n(3) $sink1
$ns connect $tcp1 $sink1
$ns at 0.0 "destination"
proc destination {} {
global ns val n
set now [$ns now]
set time 5.0
for {set i 0} {$i < $val(nn)} {incr i} {
set XX [expr rand()*750]
set YY [expr rand()*750]
$ns at [expr $now + $time] "$n($i) setdest $XX $YY 20.0"
}
$ns at [expr $now + $time] "destination"
}
#tell nodes when the simulation ends
for {set i 0} {$i < $val(nn)} {incr i} {
$ns at $val(stop) "$n($i) reset"
}
$ns at 5.0 "$ftp1 start"
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
proc stop {} {
global ns trfd namfd
close $trfd
close $namfd
exec nam Wireless.nam &
exec awk -f 6.awk Wireless.tr &

exit 0

$ns run

File : 6.awk
BEGIN{
}
{

}
END {
}

PacketRcvd=0;
Throughput=0.0;
if(($1=="r")&&($3=="_3_")&&($4=="AGT")&&($7=="tcp")&&($8>1000))
{
PacketRcvd++;
}
Throughput=((PacketRcvd*1000*8)/(95.0*1000000));
printf "the throughput is:%f\n",Throughput;

PART-B
Implement the following in C/C++:

Program - 7
Question
Write a program for error detecting code using CRC-CCITT (16- bits).
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
// mode=1 is for calculating CRC of original message and create final
message to be transmitted at sender's end
// mode=0 is for calculating CRC of recieved message at reciever's end
int crc(char input[],char output[],const char gp[],int mode)
{
int j,k;
strcpy(output,input);

if(mode)
{
for(j=1; j<strlen(gp); j++)
//append as many zeroes as the width(position of
the highest 1 bit) of generator polynomial.
strcat(output,"0");
}
//calculate final message to be transmitted and store it in
output - loop simulates CRC division and finding of remainder
for(j=0; j<strlen(input); j++)
if(output[j] == '1')
for(k=0; k<strlen(gp); k++)
{
//perform xor operation
if ((output[j+k] =='0') && (gp[k] == '0')
|| (output[j+k] == '1') && (gp[k] == '1'))
output[j+k]='0';
else
output[j+k]='1';
}
cout<<"The checksum calculated is: "<<output+strlen(input);
for(j=0; j<strlen(output); j++)
if(output[j] == '1')
//return-error
return 1;
//error free
return 0;
}
int main()
{
char input[50],output[50],receive[50];
//16-bit CRC-CCITT specification G(x): x^16+x^12+x^5+1
const char gp[18]="10001000000100001";
cout<<"Enter the input message in binary\n";
cin>>input;
crc(input,output,gp,1);
cout<<"\nThe transmitted message is:
"<<input<<output+strlen(input);
cout<<"\n\nEnter the recevied message in binary: ";
cin>>receive;
if(!crc(receive,output,gp,0))
cout<<"\nNo error in data\n";
else
cout<<"\nError in data transmission has occurred\n";
return 0;
}

Program - 8
Question
Write a program for distance vector algorithm to find suitable path for
File : p8.cpp
#include <iostream>
#include <stdio.h>
using namespace std;
struct node
{
int dist[20];
int from[20];
}rt[10];
int main()
{
int distance_matrix[20][20];
int n,i,j,k,count=0,src,dest;
cout<<"\nEnter the number of nodes : ";
cin>>n;
cout<<"\nEnter the cost/distance matrix :\n";
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
cin>>distance_matrix[i][j];
distance_matrix[i][i]=0;
rt[i].dist[j]=distance_matrix[i][j];
rt[i].from[j]=j;
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>distance_matrix[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]
+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
} while(count!=0);
for(i=0;i<n;i++)
{
cout<<"\nRouting table for
router"<<i+1<<":\nDest\tNextHop\tDist\n";
for(j=0;j<n;j++)
printf("%d\t%d\t%d\n",j+1,rt[i].from[j]
+1,rt[i].dist[j]);
}

cout<<"\nEnter source and destination : ";


cin>>src>>dest;
src--; dest--;
printf("Shortest path : \n Via router : %d\n Shortest distance :
%d \n",rt[src].from[dest]+1,rt[src].dist[dest]);
return 0;
}

transmission.

Program - 9
Question
Using TCP/IP sockets, write a client server program to make the client
send the file name and to make the server send back the contents of the
requested file if present.
File: client.cpp
#include <iostream>
#include <arpa/inet.h>
using namespace std;
int main(int argc, char* argv[])
{
char fname[50], buffer[1025];
int sd;
struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_port = htons(5000);
address.sin_addr.s_addr = inet_addr("127.0.0.1");
sd = socket(AF_INET, SOCK_STREAM, 0);
connect(sd, (struct sockaddr*)&address, sizeof(address));
cout<<"Enter a filename: ";
cin>>fname;
cout<<"Sending request"<<endl;
send(sd, fname, sizeof(fname), 0);
cout<<"Recieved response:"<<endl;
int n=recv(sd, buffer, sizeof(buffer), 0);
buffer[n]='\0';
cout<<buffer;
cout<<endl;
return 0;

File: server.cpp
#include
#include
#include
#include

<iostream>
<fstream>
<string.h>
<arpa/inet.h>

using namespace std;


int main()
{
char fname[50];
int sd, source, file;
struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_port = htons(5000);
address.sin_addr.s_addr = INADDR_ANY;
cout<<"Waiting for request."<<endl;
sd = socket(AF_INET, SOCK_STREAM, 0);
bind(sd, (struct sockaddr*)&address, sizeof(address));
listen(sd, 10);
while(1)
{
source = accept(sd, (struct sockaddr*)NULL, NULL);
recv(source, fname, sizeof(fname), 0);
cout<<"Received request for: "<<fname<<endl;
ifstream is (fname);
if (is)
{
is.seekg (0, is.end);
int length = is.tellg();
is.seekg (0, is.beg);
char * buffer = new char [length];
cout << "Sending " << length << " characters...

"<<endl;

is.read (buffer,length);
is.close();
send(source, buffer, length, 0);
}
else
{

delete[] buffer;

cout<<"Sending file not found"<<endl;


send(source, "File not found", sizeof("File not
found"), 0);
}

return 0;

File: test.txt
This
This
This
This
This
This

is
is
is
is
is
is

a
a
a
a
a
a

text
text
text
text
text
text

file
file
file
file
file
file

Program - 10
Question
Using TCP/IP sockets, write a client server program to make the client
send the file name and to make the server send back the contents of the
requested file if present.
File: 10-c.c
#include <stdio.h>
#include <fcntl.h>
int main() {
char fname[50], buffer[1025];
int request, response, n;
request = open("request.fifo", O_WRONLY);
response = open("response.fifo", O_RDONLY);
printf("Enter a filename to request: ");
scanf("%s", fname);
write(request, fname, sizeof(fname), 0);
printf("Received response: \n");
while((n = read(response, buffer, sizeof(buffer), 0)) > 0) {
write(1, buffer, n);
}
close(request);
close(response);
return 0;
}

File: 10-s.c
#include <stdio.h>
#include <fcntl.h>
int main() {
char fname[50], buffer[1025];
int request, response, file, n;
mkfifo("request.fifo", 0777);
mkfifo("response.fifo", 0777);
printf("Waiting for request... \n");
request = open("request.fifo", O_RDONLY);
response = open("response.fifo", O_WRONLY);
read(request, fname, sizeof(fname), 0);
printf("Received request for %s \n", fname);
file = open(fname, O_RDONLY);
if(file < 0) {
write(response, "File not found. \n", 18, 0);
} else {
while((n = read(file, buffer, sizeof(buffer), 0)) > 0) {
write(response, buffer, n, 0);
}
}
printf("Response sent. \n");
close(request);
close(response);
unlink("request.fifo");
unlink("response.fifo");
return 0;
}

File: test.txt
This
This
This
This
This
This

is
is
is
is
is
is

a
a
a
a
a
a

text
text
text
text
text
text

file
file
file
file
file
file

Program - 11
Question
Write a program for simple RSA algorithm to encrypt and decrypt the
data.

File: main.cpp
/*
RSA ALGORITHM
------------1.Generate two large random primes, p and q, of approximately equal size.
2.Compute n=p*q;
3.Calculate another number =(p-1)*(q-1)
4.Choose a random number e. Then calculate d so that d*e=1 mod phi
5.We can now announe e and n to public. and d is kept secret
Hence, the public key is (n, e) and the private key is (, d).
*/
#include
#include
#include
#include

<iostream>
<stdlib.h>
<string.h>
<math.h>

using namespace std;


long int i,e,d,n,p,q,phi,cipher[50];
int encrypt(char ch);
char decrypt(long int ch);
int gcd(long int a,long int b);
int prime(int a);
int main()
{
int i,len;
char text[50];
cout<<"Enter the text to be encrypted: ";
cin>>text;
len = strlen(text);
do
{

p = rand()%30;
}while(!prime(p));
do
{

q = rand()%30;
}while(!prime(q));
n=p*q;
phi=(p-1)*(q-1);

// generate prime p

// generate prime number q

//compute n and

do
{

e = rand()%phi; //compute E
}while(gcd(e,phi)!=1);
do
{
d = rand()%phi; //compute d

}while(((d*e)%phi)!=1);
cout<<"\n\nTwo prime numbers (p and q) are: "<<p<<" and
"<<q<<endl;
cout<<"n(p*q) = "<<p<<" * "<<q<<" = "<<p*q<<endl;
cout<<"(p-1)(q-1) = ("<<p<<"-1) * ("<<q<<"-1) = "<<(p-1)*(q1)<<endl;
cout<<"Public key (n, e): ("<<n<<", "<<e<<")\n";
cout<<"Private key (, d): ("<<phi<<", "<<d<<")\n";
//Encrypt the plain text
for(i=0; i<len; i++)
cipher[i]=encrypt(text[i]);
cout<<"\n\nEncrypted message: ";
for(i=0; i<len; i++)
cout<<cipher[i];
//Decrypt the cipher text
for(i=0; i<len; i++)
text[i]=decrypt(cipher[i]);
text[i]='\0';
cout<<"\nDecrypted message: "<<text<<endl;
return 0;
}
int gcd(long int a,long int b)
{
if(a==0) return b;
if(b==0) return a;
return gcd(b ,a%b);
}
int prime(int a)
{
for(i=2; i<a; i++)
if((a%i)==0)
return 0;
return 1;
}
int encrypt(char ch)
{
long int temp=ch;
for(i=1; i<e; i++)
temp=(temp*ch)%n;
return temp;
}
char decrypt(long int ch)
{
long int temp=ch;
for(i=1; i<d; i++)
ch=(temp*ch)%n;
return ch;
}

Program - 12
Question
Write a program for congestion control using leaky bucket algorithm.
#include <iostream>
#include <iomanip>
using namespace std;
int min(int x, int y)
{
if(x<y)
return x;
else
return y;
}
int main()
{
int size,count=0,drop,time,in[30],sent,rate,i;
cout<<"Enter bucket size (no of packets): ";
cin>>size;
cout<<"Enter bandwidth (packets/second): ";
cin>>rate;
cout<<"Enter burst time (seconds): ";
cin>>time;
for(i=1;i<=time;i++)
{
cout<<"\tEnter number of packets at time "<<i<<": ";
cin>>in[i];
}
cout<<"----------------------------------------------"<<endl;
cout<<"Time |"<<" Incomming |"<<" Outgoing |"<<" InBucket |"<<"
Drop "<<endl;
cout<<"----------------------------------------------"<<endl;
for(i=1;i<=time;i++)
{
count+=in[i];
if(count>size)
{
drop=count-size;
count=size;
}
else
{
drop=0;
}
sent=min(count,rate);
count-=sent;
cout<<setw(3)<<i<<setw(9)<<in[i]<<setw(11)<<sent<<setw(11)<<count<<setw(9

)<<drop;

if(drop)
{

cout<<" <-- non conforming packets";


}
cout<<endl;
}
for(;count!=0;i++)
{
drop=0;
sent=min(count,rate);
count-=sent;
cout<<setw(3)<<i<<setw(9)<<"0"<<setw(11)<<sent<<setw(11)<<count<<setw(9)<
<drop<<endl;
}
cout<<"----------------------------------------------"<<endl;
return 0;
}