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

What's hot

Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Make Mannan
 
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating SystemLPU
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
ashikul akash
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
Ankit Kumar
 
Ooprc3c
Ooprc3cOoprc3c
Ooprc3c
Ankit Dubey
 
Oops in c++
Oops in c++Oops in c++
Oops in c++
DravidSh
 
C programms
C programmsC programms
C programms
Mukund Gandrakota
 
Graphics point clipping c program
Graphics point clipping c programGraphics point clipping c program
Graphics point clipping c program
Dr.M.Karthika parthasarathy
 
Os lab 1st mid
Os lab 1st midOs lab 1st mid
Os lab 1st mid
Murali Kummitha
 
Reverse string
Reverse stringReverse string
Reverse stringWarawut
 
Fragmentation
FragmentationFragmentation
Fragmentation
A. S. M. Shafi
 

What's hot (18)

Polar plots with R
Polar plots with RPolar plots with R
Polar plots with R
 
C++ programs
C++ programsC++ programs
C++ programs
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
 
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating System
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
Include
IncludeInclude
Include
 
Lab loop
Lab loopLab loop
Lab loop
 
Ooprc3c
Ooprc3cOoprc3c
Ooprc3c
 
Session07 recursion
Session07 recursionSession07 recursion
Session07 recursion
 
Oops in c++
Oops in c++Oops in c++
Oops in c++
 
C programms
C programmsC programms
C programms
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
Graphics point clipping c program
Graphics point clipping c programGraphics point clipping c program
Graphics point clipping c program
 
Os lab 1st mid
Os lab 1st midOs lab 1st mid
Os lab 1st mid
 
Caropro
CaroproCaropro
Caropro
 
Reverse string
Reverse stringReverse string
Reverse string
 
Fragmentation
FragmentationFragmentation
Fragmentation
 

Similar to VTU Network lab programs

C Programming
C ProgrammingC Programming
C Programming
Sumant Diwakar
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
PRATHAMESH DESHPANDE
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
Ashishchinu
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
Kandarp Tiwari
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
Syed Tanveer
 
C Programming lab
C Programming labC Programming lab
C Programming lab
Vikram Nandini
 
C basics
C basicsC basics
C basicsMSc CST
 
C file
C fileC file
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
Cpds lab
Cpds labCpds lab
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
Abdullah Al Shiam
 
C lab
C labC lab
C Programming Example
C Programming Example C Programming Example
C Programming Example
University of Potsdam
 
C-programs
C-programsC-programs
C-programs
SSGMCE SHEGAON
 

Similar to VTU Network lab programs (20)

C lab manaual
C lab manaualC lab manaual
C lab manaual
 
week-3x
week-3xweek-3x
week-3x
 
C Programming
C ProgrammingC Programming
C Programming
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
C basics
C basicsC basics
C basics
 
C file
C fileC file
C file
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 
C lab
C labC lab
C lab
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
C-programs
C-programsC-programs
C-programs
 

More from Ananda Kumar HN

DAA 18CS42 VTU CSE
DAA 18CS42 VTU CSEDAA 18CS42 VTU CSE
DAA 18CS42 VTU CSE
Ananda Kumar HN
 
CGV 18CS62 VTU CSE
CGV 18CS62 VTU CSECGV 18CS62 VTU CSE
CGV 18CS62 VTU CSE
Ananda Kumar HN
 
Python for beginners
Python for beginnersPython for beginners
Python for beginners
Ananda Kumar HN
 
VTU CN-1important questions
VTU CN-1important questionsVTU CN-1important questions
VTU CN-1important questions
Ananda Kumar HN
 
Oop with c++ notes unit 01 introduction
Oop with c++ notes   unit 01 introductionOop with c++ notes   unit 01 introduction
Oop with c++ notes unit 01 introduction
Ananda Kumar HN
 
C++ prgms io file unit 7
C++ prgms io file unit 7C++ prgms io file unit 7
C++ prgms io file unit 7
Ananda Kumar HN
 
C++ prgms 5th unit (inheritance ii)
C++ prgms 5th unit (inheritance ii)C++ prgms 5th unit (inheritance ii)
C++ prgms 5th unit (inheritance ii)
Ananda Kumar HN
 
C++ prgms 4th unit Inheritance
C++ prgms 4th unit InheritanceC++ prgms 4th unit Inheritance
C++ prgms 4th unit Inheritance
Ananda Kumar HN
 
C++ prgms 3rd unit
C++ prgms 3rd unitC++ prgms 3rd unit
C++ prgms 3rd unit
Ananda Kumar HN
 
Microsoft office in kannada for begineers
Microsoft office in kannada for begineersMicrosoft office in kannada for begineers
Microsoft office in kannada for begineers
Ananda Kumar HN
 
Microsoft office in KANNADA
Microsoft office in KANNADAMicrosoft office in KANNADA
Microsoft office in KANNADA
Ananda Kumar HN
 

More from Ananda Kumar HN (11)

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

Recently uploaded

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 

Recently uploaded (20)

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 

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