Part - A
Assignment No. -1
Three node point to point network with duplex link between them
.tcl file
set ns [new Simulator]
set tr [open "out.tr" w]
$ns trace-all $tr
set ftr [open "out.nam" w]
$ns namtrace-all $ftr
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
$ns duplex-link $n0 $n1 2mb 4ms DropTail
$ns duplex-link $n0 $n2 2mb 4ms DropTail
$ns duplex-link $n1 $n2 2mb 4ms DropTail
set tcp1 [new Agent/TCP]
set sink1 [new Agent/TCPSink]
$ns attach-agent $n0 $tcp1
$ns attach-agent $n1 $sink1
$ns connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set tcp2 [new Agent/TCP]
set sink2 [new Agent/TCPSink]
$ns attach-agent $n0 $tcp2
$ns attach-agent $n2 $sink2
$ns connect $tcp2 $sink2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
set tcp3 [new Agent/TCP]
set sink3 [new Agent/TCPSink]
$ns attach-agent $n1 $tcp3
$ns attach-agent $n2 $sink3
$ns connect $tcp3 $sink3
set ftp3 [new Application/FTP]
$ftp3 attach-agent $tcp3
proc finish { } {
global ns tr ftr ftp1 ftp2 ftp3 n0 n1 n2 tcp1 tcp2 tcp3 sink1 sink2 sink3
$ns flush-trace
close $tr
close $ftr
exec nam out.nam &
exit
}
$ns at 0.1 "$ftp1 start"
$ns at 2.0 "$ftp1 stop"
$ns at 0.1 "$ftp2 start"
$ns at 2.0 "$ftp2 stop"
$ns at 0.1 "$ftp3 start"
$ns at 2.0 "$ftp3 stop"
$ns at 2.1 "finish"
$ns run
Topology :
Output :
Assignment No. -2
Four node point to point network using TCP/UDP
.tcl file
set ns [new Simulator]
set tracefile [open "out.tr" w]
$ns trace-all $tracefile
set namfile [open "out.nam" w]
$ns namtrace-all $namfile
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 10Mb 2ms DropTail
$ns duplex-link $n1 $n2 10Mb 2ms DropTail
$ns duplex-link $n2 $n3 10Mb 2ms DropTail
$ns queue-limit $n0 $n1 10
$ns queue-limit $n1 $n2 10
$ns queue-limit $n2 $n3 10
set tcp1 [new Agent/TCP]
$ns attach-agent $n0 $tcp1
set sink1 [new Agent/TCPSink]
$ns attach-agent $n1 $sink1
$ns connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set tcp2 [new Agent/TCP]
$ns attach-agent $n1 $tcp2
set sink2 [new Agent/TCPSink]
$ns attach-agent $n2 $sink2
$ns connect $tcp2 $sink2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
set tcp3 [new Agent/TCP]
$ns attach-agent $n2 $tcp3
set sink3 [new Agent/TCPSink]
$ns attach-agent $n3 $sink3
$ns connect $tcp3 $sink3
set ftp3 [new Application/FTP]
$ftp3 attach-agent $tcp3
set udp [new Agent/UDP]
$ns attach-agent $n0 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
proc finish { } {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit
}
$ns at 1.0 "$ftp1 start"
$ns at 1.0 "$ftp2 start"
$ns at 1.0 "$ftp3 start"
$ns at 1.0 "$cbr start"
$ns at 2.0 "finish"
$ns run
.awk file
AWT File
BEGIN {
C = 0
d = 0
}
{
if($1 == "r" && $5 == "tcp")
C++;
if($1 == "r" && $5 == "cbr")
d++;
}
END {
printf("Number of PKT sent = %d\n", C);
printf("Number of PKT sent = %d\n", d);
}
Topology :
Output :
Assignment No. -3
Transmission of ping messages over a network topology consisting of 6 nodes.tcl file
.tcl file
set ns [new Simulator]
set tr [open "out.tr" w]
$ns trace-all $tr
set ntr [open "out.nam" w]
$ns namtrace-all $ntr
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 $n4 10Mb 4ms DropTail
$ns duplex-link $n1 $n4 20Mb 5ms DropTail
$ns duplex-link $n2 $n4 30Mb 6ms DropTail
$ns duplex-link $n3 $n4 40Mb 7ms DropTail
$ns duplex-link $n4 $n5 50Mb 8ms DropTail
set p1 [new Agent/Ping]
$ns attach-agent $n0 $p1
set p2 [new Agent/Ping]
$ns attach-agent $n1 $p2
set p3 [new Agent/Ping]
$ns attach-agent $n2 $p3
set p4 [new Agent/Ping]
$ns attach-agent $n3 $p4
set p5 [new Agent/Ping]
$ns attach-agent $n5 $p5
$ns queue-limit $n0 $n4 5
$ns queue-limit $n2 $n4 3
$ns queue-limit $n4 $n5 2
Agent/Ping instproc recv {from rtt} {
$self instvar node_
puts "node[$node_ id]Received Ping message from $from with rtt value $rtt";
}
$ns connect $p1 $p5
$ns connect $p3 $p4
proc finish { } {
global ns tr ntr
$ns flush-trace
close $tr
close $ntr
exec nam out.nam &
exit 0
}
$ns at 0.1 "$p1 send"
$ns at 0.2 "$p1 send"
$ns at 0.3 "$p1 send"
$ns at 0.4 "$p1 send"
$ns at 0.5 "$p1 send"
$ns at 0.6 "$p1 send"
$ns at 0.7 "$p1 send"
$ns at 0.8 "$p1 send"
$ns at 0.9 "$p1 send"
$ns at 1.0 "$p1 send"
$ns at 0.1 "$p3 send"
$ns at 0.2 "$p3 send"
$ns at 0.3 "$p3 send"
$ns at 0.4 "$p3 send"
$ns at 0.5 "$p3 send"
$ns at 0.6 "$p3 send"
$ns at 0.7 "$p3 send"
$ns at 0.8 "$p3 send"
$ns at 0.9 "$p3 send"
$ns at 1.0 "$p3 send"
$ns at 2.0 "finish"
$ns run
.awk file
BEGIN {c=0} {
if($1=="d")
c++;
}
}
END { printf("Num of pkt droped = %d",c);
Topology :
Output :
Assignment No. -4
Ethernet LAN using N nodes (6-10), change error rate and data rate and compare throughput
.tcl file
set ns [new Simulator]
set tracefile [open "out.tr" w]
$ns trace-all $tracefile
set namfile [open "out.nam" w]
$ns namtrace-all $namfile
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 15Mb 4ms DropTail
$ns duplex-link $n1 $n2 5Mb 3ms DropTail
set Lan [$ns newLan "$n1 $n3 $n4 $n5" 3Mb 1ms LL Queue/DropTail Mac/Csma/Cd channel]
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n5 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
proc finish { } {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit
}
$ns at 1.0 "$ftp start"
$ns at 5.0 "$ftp stop"
$ns at 10.0 "finish"
$ns run
.awk file
BEGIN{ c=0; ftppktsize=0; ftpthrough=0} {
if($1=="r" && $5=="tcp" && $4="0" && $3="3")
c++;
$6=ftppktsize;
}
END { ftpthroughput=c+ftppktsize/10;
printf("Throghput is = %d\n",ftpthroughput);}
Topology :
Output :
)
Part - B
Assignment No. -1
Congestion control using leaky bucket algorithm
#include<stdio.h>
int main() {
int size, orate, n, i, pkt[50];
printf("Enter the bucket size");
scanf("%d", &size);
printf("Enter the total number of the packet");
scanf("%d", &n);
printf("Enter the output rate");
scanf("%d", &orate);
for(i = 0; i < n; i++) {
printf("Enter the %d packet size\n", i + 1);
scanf("%d", &pkt[i]);
}
for(int i = 0; i < n; i++) {
if(pkt[i] > size) {
printf("Packet %d will be discarded\n", i + 1);
continue;
}
while(pkt[i] != 0) {
if(orate < pkt[i]) {
printf("From packet %d,%d bytes are transmitted\n", i + 1, orate);
pkt[i] = pkt[i] - orate;
} else {
printf(" %d bytes are diretcly transmitted \n", pkt[i]); // Preserved original spelling
pkt[i] = 0;
}
}
printf("Packet %d is completely transmitted\n", i + 1);
}
return 0;
}
Output:
Assignment No. -2
Bit stuffing and de-stuffing of binary data
#include<stdio.h>
int main() {
char n[50], stuff[50], destuff[50];
int p = 0, q = 0, c = 0;
printf("Enter the data\n");
scanf("%s", n);
while(n[p] != '\0') {
if(n[p] == '0') {
stuff[q] = n[p];
q++;
p++;
} else {
while(n[p] == '1' && c != 5) {
c++;
stuff[q] = n[p];
q++;
p++;
}
if(c == 5) {
stuff[q] = '0';
q++;
}
c = 0;
}
}
stuff[q] = '\0';
printf("Stuff=%s\n", stuff);
p = 0;
q = 0;
while(stuff[p] != '\0') {
if(stuff[p] == '0') {
destuff[q] = stuff[p];
q++;
p++;
} else {
while(stuff[p] == '1' && c != 5) {
c++;
destuff[q] = stuff[p];
q++;
p++;
}
if(c == 5) {
p++;
}
c = 0;
}
}
destuff[q] = '\0';
printf("Destuff=%s\n", destuff);
return 0;
}
Output :
Assignment No. - 3
Error detection using CRC-CCITT (16-bits)
CRC-Sender Side:
#include<stdio.h>
int main() {
int i, j, dw[24], cw[24];
int p[17] = {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
printf("Enter the 8 bit data\n");
for(i = 0; i < 8; i++)
scanf("%d", &dw[i]);
for(i = 0; i < 8; i++)
cw[i] = dw[i];
for(i = 8; i < 24; i++)
cw[i] = 0;
for(i = 0; i < 8; i++) {
if(cw[i] == 1) {
for(j = 0; j < 17; j++) {
cw[i + j] = cw[i + j] ^ p[j];
}
}
}
printf("Codeword");
for(i = 0; i < 8; i++)
printf("%d", dw[i]);
for(i = 8; i < 24; i++)
printf("%d", cw[i]);
return 0;
}
CRC-Receiver Side:
#include<stdio.h>
#include<stdlib.h>
int main() {
int i, j, dw[24], cw[24], flag;
int p[17] = {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
printf("Enter the codeword \n");
for(i = 0; i < 24; i++)
scanf("%d", &cw[i]);
for(i = 0; i < 24; i++)
dw[i] = cw[i];
for(i = 0; i < 8; i++) {
if(cw[i] == 1) {
for(j = 0; j < 17; j++) {
cw[i + j] = cw[i + j] ^ p[j];
}
}
}
for(i = 0; i < 24; i++) {
if(cw[i] != 0) {
printf("Error occurred\n");
flag = 1;
exit(0);
} else {
flag = 0;
}
}
if(flag == 0) {
printf("Data is error free\n");
for(i = 0; i < 8; i++)
printf("%d", dw[i]);
}
return 0;
}
Output:
CRC-Sender :
CRC-Receiver :
Assignment No. -4
Distance vector algorithm to find suitable path for transmission
#include<stdio.h>
#include<stdlib.h>
struct node {
int dest[20];
int from[20];
} rt[20];
int main() {
int c[20][20], arr[20];
int d, i, j, k, n, s, ct = 0;
printf("Enter the number of nodes\n");
scanf("%d", &n);
printf("Enter the cost matrix\n");
for(i = 0; i < n; i++) {
for(j = 0; j < n; j++) {
scanf("%d", &c[i][j]);
rt[i].dest[j] = c[i][j];
rt[i].from[j] = j;
}
}
printf("Enter the source node\n");
scanf("%d", &s);
printf("Enter the destination node\n");
scanf("%d", &d);
for(i = 0; i < n; i++) {
printf("Routing table info of %d route\n", i + 1);
printf("Source\t Destination via\t Cost\n");
for(j = 0; j < n; j++) {
printf("%d\t %d\t %d\t %d\n", i, j, rt[i].from[j], rt[i].dest[j]);
}
}
do {
ct = 0;
for(i = 0; i < n; i++) {
for(j = 0; j < n; j++) {
for(k = 0; k < n; k++) {
if(rt[i].dest[j] > c[i][k] + rt[k].dest[j]) {
rt[i].dest[j] = rt[i].dest[k] + rt[k].dest[j];
rt[i].from[j] = k;
ct++;
}
}
}
}
} while(ct != 0);
printf("After updating..\n");
for(i = 0; i < n; i++) {
printf("Routing table of %d route\n", i + 1);
printf("Source\t Destination\t Via\t Cost\n");
for(j = 0; j < n; j++) {
printf("%d\t %d\t %d\t %d\n", i, j, rt[i].from[j], rt[i].dest[j]);
}
}
printf("The minimum cost from %d to %d is %d\n", s, d, rt[s].dest[d]);
printf("The shortest path from %d to %d\n", s, d);
arr[0] = s;
i = 1;
while(s != d) {
arr[i++] = rt[s].from[d];
s = rt[s].from[d];
}
for(j = 0; j < i - 1; j++) {
printf("%d------->", arr[j]);
}
printf("%d\n", arr[j]);
return 0;
}
Output :