Computer Networks (21UIS613C)
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 "[Link]" w]
$ns trace-all $tr
set ftr [open "[Link]" 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 [Link] &
exit
}
1 Department of Information Science and Engineering
Computer Networks (21UIS613C)
$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
2 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Output
3 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Assignment No 2
Four node point to point network using TCP/UDP
tcl-file
set ns [new Simulator]
set tr [open "[Link]" w]
$ns trace-all $tr
set ftr [open "[Link]" w]
$ns namtrace-all $ftr
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 2Mb 4ms DropTail
$ns duplex-link $n1 $n2 2Mb 4ms DropTail
$ns duplex-link $n2 $n3 2Mb 4ms DropTail
$ns queue-limit $n0 $n1 10
$ns queue-limit $n1 $n2 10
$ns queue-limit $n2 $n3 10
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 $n1 $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 $n2 $tcp3
$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
4 Department of Information Science and Engineering
Computer Networks (21UIS613C)
proc finish { } {
global ns tr ftr ftp1 ftp2 ftp3 n0 n1 n2 n3 tcp1 tcp2 tcp3 sink1 sink2 sink3
$ns flush-trace
close $tr
close $ftr
exec nam [Link] &
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
BEGIN {C=0
d=0} {
if ($1=="r" && $5=="tcp")
C++;
if ($1=="r" && $5=="cbr")
d++;
}
END{printf("No of packets transferred by tcp=%d\n",C);
printf("No of packets transferred by udp=%d\n",d);}
5 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Output
6 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Assignment No 3
Transmission of ping messages over a network topology consisting of 6 nodes
tcl-file
set ns [new Simulator]
set tr [open "[Link]" w]
$ns trace-all $tr
set ntr [open "[Link]" 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]
set p2 [new Agent/Ping]
set p3 [new Agent/Ping]
set p4 [new Agent/Ping]
set p5 [new Agent/Ping]
$ns attach-agent $n0 $p1
$ns attach-agent $n1 $p2
$ns attach-agent $n2 $p3
$ns attach-agent $n3 $p4
$ns attach-agent $n4 $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_} Recived Ping message from $from with rtt value $rtt";
}
$ns connect $p1 $p5
$ns connect $p3 $p4
proc finish { } {
global ns tr ntr n0 n1 n2 n3 n4 n5 p1 p2 p3 p4 p5
$ns flush-trace
close $tr
close $ntr
exec nam [Link] &
exit 0
7 Department of Information Science and Engineering
Computer Networks (21UIS613C)
$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("No of packets dropped=%d",c);}
8 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Output
9 Department of Information Science and Engineering
Computer Networks (21UIS613C)
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 "[Link]" w]
$ns trace-all $tracefile
set namfile [open "[Link]" 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]
set sink [new Agent/TCPSink]
$ns attach-agent $n0 $tcp
$ns attach-agent $n5 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
proc finish { } {
global ns tracefile namfile n0 n1 n2 n3 n4 n5 Lan tcp sink ftp
$ns flush-trace
close $tracefile
close $namfile
exec nam [Link] &
exit 0
}
$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("Throughput is = %d",ftpthroughput);
}
10 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Output
11 Department of Information Science and Engineering
Computer Networks (21UIS613C)
12 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Part B
Assignment No 1
Error detection using CRC-CCITT (16-bits)
Sender
#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("Enetr 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;
}
13 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Receiver
#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 code word\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 occured\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;
}
14 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Output
CRC-Sender
CRC-Reciver
15 Department of Information Science and Engineering
Computer Networks (21UIS613C)
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
16 Department of Information Science and Engineering
Computer Networks (21UIS613C)
{
while(stuff[p]=='1' && c!=5)
{
c++;
destuff[q]=stuff[p];
q++;
p++;
}
if(c==5)
{
p++;
}
c=0;
}
}
destuff[p]='\0';
printf("destuff = %s\n",destuff);
return 0;
}
17 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Output
18 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Assignment No 3
Distance vector algorithm to find suitable path for transmission
#include<stdio.h>
#include<stdlib.h>
struct node
{
int dest[20];
int from[20];
}rt[10];
int main()
{
int c[20][20],arr[20];
int d,i,j,k,n,s,ct =0;
printf("Enter the no 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\t via\t cost\n");
for(j=0;j<n;j++)
printf("%d\t %d\t\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++;
19 Department of Information Science and Engineering
Computer Networks (21UIS613C)
}
}while(ct!=0);
printf("After Updating\n");
for(i=0;i<n;i++)
{
printf("Routing table info 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\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;
}
20 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Output
21 Department of Information Science and Engineering
Computer Networks (21UIS613C)
22 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Assignment No 4
Congestion control using leaky bucket algorithm
#include<stdio.h>
int main()
{
int size,orate,n,i,pkt[50];
printf("enter the bucket size\n");
scanf("%d",&size);
printf("enter the total number of packet\n");
scanf("%d",&n);
printf("enter the output rate\n");
scanf("%d",&orate);
for(i=0;i<n;i++)
{
printf("enter %d packet size\n",i+1);
scanf("%d",&pkt[i]);
}
for(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 directly transmitted\n",pkt[i]);
pkt[i]=0;
}
}
printf("packet %d is completely transmitted\n",i+1);
}
return 0;
}
23 Department of Information Science and Engineering
Computer Networks (21UIS613C)
Output
24 Department of Information Science and Engineering