CN Lab
CN Lab
Part A
Assignment No 1
Three node point to point network with duplex link between them
tcl-file
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
}
Output
Assignment No 2
Four node point to point network using TCP/UDP
tcl-file
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 out.nam &
exit
}
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);}
Output
Assignment No 3
Transmission of ping messages over a network topology consisting of 6 nodes
tcl-file
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 out.nam &
exit 0
awk-file
BEGIN{c=0}{
if($1=="d")
c++;
}
END{printf("No of packets dropped=%d",c);}
Output
Assignment No 4
Ethernet LAN using N nodes (6-10), change error rate and data rate and compare throughput
tcl-file
set Lan [$ns newLan "$n1 $n3 $n4 $n5" 3Mb 1ms LL Queue/DropTail Mac/Csma/Cd channel]
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 out.nam &
exit 0
}
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);
}
Output
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;
}
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;
}
Output
CRC-Sender
CRC-Reciver
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[p]='\0';
printf("destuff = %s\n",destuff);
return 0;
}
Output
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++;
}
}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;
}
Output
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;
}
Output