SlideShare a Scribd company logo
1 of 4
Download to read offline
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 (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

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

VTU CN-1important questions
VTU CN-1important questionsVTU CN-1important questions
VTU CN-1important questionsAnanda 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 introductionAnanda Kumar HN
 
C++ prgms io file unit 7
C++ prgms io file unit 7C++ prgms io file unit 7
C++ prgms io file unit 7Ananda 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 InheritanceAnanda Kumar HN
 
Microsoft office in kannada for begineers
Microsoft office in kannada for begineersMicrosoft office in kannada for begineers
Microsoft office in kannada for begineersAnanda Kumar HN
 
Microsoft office in KANNADA
Microsoft office in KANNADAMicrosoft office in KANNADA
Microsoft office in KANNADAAnanda 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

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

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