SlideShare a Scribd company logo
Networks Laboratory – 10CSL77 PART - B
Implement the following in C/C++:
1. Write a program for error detecting code using CRC CCIT(16 bits).
#include<stdio.h>
#include<string.h>
#define N strlen(g)
char t[128],cs[128],g[]="10001000000100001";
int a,e,c;
void xor()
{
for(c=1;c<N;c++)
cs[c]=((cs[c] == g[c])?'0':'1');
}
void crc()
{
for(e=0;e<N;e++)
cs[e]=t[e];
do{
if(cs[0]=='1')
xor( );
for(c=0;c<N-1;c++)
cs[c]=cs[c+1];
cs[c]=t[e++];
}while(e<=a+N-1);
}
int main()
{
int flag=0;
system("clear");
printf("Enter polynomial:n");
scanf("%s",&t);
printf("Generated divisor is :%sn",g);
a=strlen(t);
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("Modified polynomial is %sn",t);
crc( );
printf("Checksum is :%sn",cs);
for(e=a;e<a+N-1;e++)
t[e]=cs[e-a];
printf("Final codeword is %sn",t);
printf("Test error detection?n1(yes) 0(no):n");
scanf("%d",&flag);
if(flag==0)
return;
if(flag==1)
{
printf("Enter position where error is to be inserted:n ");
scanf("%d",&e);
if(e<a+N-1){
t[e]=(t[e]=='0')?'1':'0';
1 | P a g e A n a n d a K u m a r H N
Networks Laboratory – 10CSL77 PART - B
printf("err data : %sn",t);
}
else
printf("Position where error should be created is above the length of Codeword...Hencen");
}
crc();
for(e=0;(e<N-1)&&(cs[e]!='1');e++);
if(e<N-1)
printf("Error detectedn");
else
printf("No error detected n");
return;
}
OUTPUT:
2. Write a program for “distance vector algorithm” to find suitable path for
transmission.
#include<stdio.h>
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;
printf("nEnter the number of nodes : ");
scanf("%d",&n);
printf("nEnter the cost/distance matrix :n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&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++)
2 | P a g e A n a n d a K u m a r H N
Networks Laboratory – 10CSL77 PART - B
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++)
{ printf("n---------------------------------");
printf("nRouting table for router %d :nDesttNextHopttDistn",i+1);
printf("----------------------------------n");
for(j=0;j<n;j++)
printf("%dt%dtt%dn",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
printf("nEnter source and destination : ");
scanf("%d%d",&src,&dest);
src--; dest--;
if(rt[src].dist[dest]!=999)
printf("Shortest path : n Via router : %dn Shortest distance : %d n",rt[src].from[dest]+1,rt[src].dist[dest]);
else
printf("no connection exists between %d----->%d",src+1,dest+1);
return 0;
}
6. Write a program for congestion control using leaky bucket algorithm.
#include<stdio.h>
#include<math.h>
int random(int a)
{ int rn=(rand()%10)%a;
return rn==0?1:rn;
}
int main()
{
int packet_sz[5],i,clk,b_size,o_rate,p_sz_rm=0,p_sz,p_time;
for(i=0;i<5;++i)
packet_sz[i]=random(6)*10;
for(i=0;i<5;++i)
printf("packet[%d]:%d bytesn",i,packet_sz[i]);
printf("nEnter the Output rate:");
scanf("%d",&o_rate);
printf("Enter the Bucket Size:");
scanf("%d",&b_size);
for(i=0; i<5; ++i)
{
if((packet_sz[i]+p_sz_rm) > b_size)
if(packet_sz[i] > b_size)
printf("nnIncomming packet size (%d) is Greater than bucket capacity-PACKET REJECTED",packet_sz[i]);
else
3 | P a g e A n a n d a K u m a r H N
Networks Laboratory – 10CSL77 PART - B
printf("nnPacket[%d] size %d + Packet remaining %d exceeds Bucket capacity - PACKET
REJECTED!!",i+1,packet_sz[i],p_sz_rm);
else
{
p_sz_rm+=packet_sz[i];
printf("nnIncomming Packet size: %d",packet_sz[i]);
printf("nBytes remaining to Transmit: %d",p_sz_rm);
p_time = random(4)*10;
printf("nTime left for transmission: %d units",p_time);
for(clk=10; clk<=p_time; clk+=10)
{
if(p_sz_rm)
{
if(p_sz_rm <= o_rate)
{
printf("n Packet of size %d Transmitted",p_sz_rm);
p_sz_rm=0;
}
else
{
printf("n Packet of size %d Transmitted",o_rate);
p_sz_rm -= o_rate;
printf("nBytes Remaining after Transmission:%d",p_sz_rm);
}
}
else
printf("n No packets to transmit!!");
printf(" Time Left:%d",p_time-clk);
}
}
}
}
4 | P a g e A n a n d a K u m a r H N

More Related Content

DOCX
Os lab file c programs
PDF
Cn os-lp lab manual k.roshan
PDF
Insertion sort
DOCX
Project code for Project on Student information management system
DOCX
Cpp programs
TXT
Dvst
Os lab file c programs
Cn os-lp lab manual k.roshan
Insertion sort
Project code for Project on Student information management system
Cpp programs
Dvst

What's hot (18)

PDF
Polar plots with R
PDF
C++ programs
DOCX
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
TXT
Programs for Operating System
 
DOCX
Numerical Method Assignment
DOCX
Computer graphics programs in c++
DOCX
Include
DOCX
Lab loop
PDF
Ooprc3c
PPTX
Session07 recursion
PPTX
Oops in c++
PDF
C programms
DOCX
Graphics point clipping c program
PDF
Os lab 1st mid
DOCX
Caropro
PDF
Reverse string
PDF
Fragmentation
Polar plots with R
C++ programs
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Programs for Operating System
 
Numerical Method Assignment
Computer graphics programs in c++
Include
Lab loop
Ooprc3c
Session07 recursion
Oops in c++
C programms
Graphics point clipping c program
Os lab 1st mid
Caropro
Reverse string
Fragmentation
Ad

Similar to VTU Network lab programs (20)

DOCX
C lab manaual
DOCX
C Programming
PDF
C Programming Example
PPT
All important c programby makhan kumbhkar
DOCX
ADA FILE
DOC
'C' language notes (a.p)
DOCX
Computer Networks Lab File
PDF
Cpd lecture im 207
PDF
C Programming lab
DOC
C basics
DOCX
DOCX
Chapter 8 c solution
DOC
Basic c programs updated on 31.8.2020
DOCX
DOCX
SaraPIC
DOCX
Computer graphics lab assignment
DOCX
PPTX
C Programming Example
DOC
C-programs
C lab manaual
C Programming
C Programming Example
All important c programby makhan kumbhkar
ADA FILE
'C' language notes (a.p)
Computer Networks Lab File
Cpd lecture im 207
C Programming lab
C basics
Chapter 8 c solution
Basic c programs updated on 31.8.2020
SaraPIC
Computer graphics lab assignment
C Programming Example
C-programs
Ad

More from Ananda Kumar HN (11)

PPTX
DAA 18CS42 VTU CSE
PPTX
CGV 18CS62 VTU CSE
PDF
Python for beginners
PDF
VTU CN-1important questions
PDF
Oop with c++ notes unit 01 introduction
PDF
C++ prgms io file unit 7
PDF
C++ prgms 5th unit (inheritance ii)
PDF
C++ prgms 4th unit Inheritance
PDF
C++ prgms 3rd unit
PDF
Microsoft office in kannada for begineers
PPTX
Microsoft office in KANNADA
DAA 18CS42 VTU CSE
CGV 18CS62 VTU CSE
Python for beginners
VTU CN-1important questions
Oop with c++ notes unit 01 introduction
C++ prgms io file unit 7
C++ prgms 5th unit (inheritance ii)
C++ prgms 4th unit Inheritance
C++ prgms 3rd unit
Microsoft office in kannada for begineers
Microsoft office in KANNADA

Recently uploaded (20)

PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Classroom Observation Tools for Teachers
PDF
RMMM.pdf make it easy to upload and study
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Classroom Observation Tools for Teachers
RMMM.pdf make it easy to upload and study
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
01-Introduction-to-Information-Management.pdf
Microbial diseases, their pathogenesis and prophylaxis
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Renaissance Architecture: A Journey from Faith to Humanism
O5-L3 Freight Transport Ops (International) V1.pdf
Pre independence Education in Inndia.pdf
Basic Mud Logging Guide for educational purpose
Final Presentation General Medicine 03-08-2024.pptx
Pharma ospi slides which help in ospi learning
102 student loan defaulters named and shamed – Is someone you know on the list?

VTU Network lab programs

  • 1. Networks Laboratory – 10CSL77 PART - B Implement the following in C/C++: 1. Write a program for error detecting code using CRC CCIT(16 bits). #include<stdio.h> #include<string.h> #define N strlen(g) char t[128],cs[128],g[]="10001000000100001"; int a,e,c; void xor() { for(c=1;c<N;c++) cs[c]=((cs[c] == g[c])?'0':'1'); } void crc() { for(e=0;e<N;e++) cs[e]=t[e]; do{ if(cs[0]=='1') xor( ); for(c=0;c<N-1;c++) cs[c]=cs[c+1]; cs[c]=t[e++]; }while(e<=a+N-1); } int main() { int flag=0; system("clear"); printf("Enter polynomial:n"); scanf("%s",&t); printf("Generated divisor is :%sn",g); a=strlen(t); for(e=a;e<a+N-1;e++) t[e]='0'; printf("Modified polynomial is %sn",t); crc( ); printf("Checksum is :%sn",cs); for(e=a;e<a+N-1;e++) t[e]=cs[e-a]; printf("Final codeword is %sn",t); printf("Test error detection?n1(yes) 0(no):n"); scanf("%d",&flag); if(flag==0) return; if(flag==1) { printf("Enter position where error is to be inserted:n "); scanf("%d",&e); if(e<a+N-1){ t[e]=(t[e]=='0')?'1':'0'; 1 | P a g e A n a n d a K u m a r H N
  • 2. Networks Laboratory – 10CSL77 PART - B printf("err data : %sn",t); } else printf("Position where error should be created is above the length of Codeword...Hencen"); } crc(); for(e=0;(e<N-1)&&(cs[e]!='1');e++); if(e<N-1) printf("Error detectedn"); else printf("No error detected n"); return; } OUTPUT: 2. Write a program for “distance vector algorithm” to find suitable path for transmission. #include<stdio.h> 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; printf("nEnter the number of nodes : "); scanf("%d",&n); printf("nEnter the cost/distance matrix :n"); for(i=0;i<n;i++) for(j=0;j<n;j++) { scanf("%d",&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++) 2 | P a g e A n a n d a K u m a r H N
  • 3. Networks Laboratory – 10CSL77 PART - B 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++) { printf("n---------------------------------"); printf("nRouting table for router %d :nDesttNextHopttDistn",i+1); printf("----------------------------------n"); for(j=0;j<n;j++) printf("%dt%dtt%dn",j+1,rt[i].from[j]+1,rt[i].dist[j]); } printf("nEnter source and destination : "); scanf("%d%d",&src,&dest); src--; dest--; if(rt[src].dist[dest]!=999) printf("Shortest path : n Via router : %dn Shortest distance : %d n",rt[src].from[dest]+1,rt[src].dist[dest]); else printf("no connection exists between %d----->%d",src+1,dest+1); return 0; } 6. Write a program for congestion control using leaky bucket algorithm. #include<stdio.h> #include<math.h> int random(int a) { int rn=(rand()%10)%a; return rn==0?1:rn; } int main() { int packet_sz[5],i,clk,b_size,o_rate,p_sz_rm=0,p_sz,p_time; for(i=0;i<5;++i) packet_sz[i]=random(6)*10; for(i=0;i<5;++i) printf("packet[%d]:%d bytesn",i,packet_sz[i]); printf("nEnter the Output rate:"); scanf("%d",&o_rate); printf("Enter the Bucket Size:"); scanf("%d",&b_size); for(i=0; i<5; ++i) { if((packet_sz[i]+p_sz_rm) > b_size) if(packet_sz[i] > b_size) printf("nnIncomming packet size (%d) is Greater than bucket capacity-PACKET REJECTED",packet_sz[i]); else 3 | P a g e A n a n d a K u m a r H N
  • 4. Networks Laboratory – 10CSL77 PART - B printf("nnPacket[%d] size %d + Packet remaining %d exceeds Bucket capacity - PACKET REJECTED!!",i+1,packet_sz[i],p_sz_rm); else { p_sz_rm+=packet_sz[i]; printf("nnIncomming Packet size: %d",packet_sz[i]); printf("nBytes remaining to Transmit: %d",p_sz_rm); p_time = random(4)*10; printf("nTime left for transmission: %d units",p_time); for(clk=10; clk<=p_time; clk+=10) { if(p_sz_rm) { if(p_sz_rm <= o_rate) { printf("n Packet of size %d Transmitted",p_sz_rm); p_sz_rm=0; } else { printf("n Packet of size %d Transmitted",o_rate); p_sz_rm -= o_rate; printf("nBytes Remaining after Transmission:%d",p_sz_rm); } } else printf("n No packets to transmit!!"); printf(" Time Left:%d",p_time-clk); } } } } 4 | P a g e A n a n d a K u m a r H N