






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Computer Networks Practical File
Typology: Study notes
1 / 30
This page cannot be seen from the preview
Don't miss anything!























1 WAP to simulate Cyclic Redundance Check (CRC) error detection 3 algorithm for noisy channel. 2 WAP to simulate and implement stop and wait protocol for noisy 8 channel 3 WAP to simulate and implement go back and sliding window protocol. 15 4 WAP to simulate and implement selective repeat sliding window 17 protocol. 5 WAP to simulate and implement distance vector routing algorithm. 23 6 WAP to simulate and implement Dijkstra algorithm for shortest 26 path routing.
reverse(bin,i); length=i; for(int a=0;a<i;a++) cout<<bin[a]; cout<<endl; return; } int xor_bin(int divt[],int divr[],int len_div,int len) { int j=0,k; while(divt[j]!=1) { j++; } if((len-j)<len_div) return 0; for(int i=j,k=0;i<(len_div+j);i++,k++) { if(divt[i]==divr[k]) divt[i]=0; else divt[i]=1; } return 1; } void append(int n[],int app,int &norm) { length=(norm+app)-1; for(int i=norm-1;i<length;i++)
n[i]=0; } cout<<"\n The number after appending is: "; for(int i=0;i<length;i++) { cout<<n[i]<<" "; } cout<<endl; norm=length; } void division(int mess[],int &len_mess,int a[],int len_a) { int flag; append(mess,len_a,len_mess); for(int i=0;i<len_mess-2;i++) { flag=xor_bin(mess,a,len_a,len_mess); if(flag==0) break; } cout<<"\n The new message now after dividing is: "; for(int i=0;i<len_mess;i++) cout<<mess[i]<<" "; cout<<endl; } int main()
cout<<"\n The Cyclic Redundancy Check remainder is: "; for(int j=i;j<length_mess;j++) { cout<<mess_pass[j]<<" "; mess_temp[r]=mess_pass[j]; r++; } cout<<endl; } cout<<"\n The message to be passed is: "; for(i=0;i<r;i++) cout<<mess_temp[i]<<" "; cout<<endl; return 0; }
#include
void sender() { static int FrameToSend=0; static frame f; packet buf; eventtype e; static int flag=0; if (flag==0) { FromNetworkLayer(&buf); f.info=buf; f.seq=FrameToSend; cout<<"\n Sender information: \t"<<f.info.data<<"\n"; cout<<"\n Sequence number: \t"<<f.seq; turn='r'; ToPhysicalLayer(&f); flag=1; } WaitForEventSender(&e); if(turn=='f') { if(e==framearr) { FromNetworkLayer(&buf); inc(FrameToSend); f.info=buf; f.seq=FrameToSend;
cout<<"\n Sender information: \t"<<f.info.data<<"\n"; cout<<"\n Sequence number: \t"<<f.seq<<"\n"; getch(); turn='r'; ToPhysicalLayer(&f); } } } void FromNetworkLayer(packet buf) { (buf).data=i; i++; } void ToPhysicalLayer(frame f) { data1=f; } void WaitForEventSender(eventtype *ev) { static int timer=0; if(turn=='f') { timer++; return ;
ToPhysicalLayer(&f); } } } void WaitForEventReceiver(eventtype *ev) { if(turn=='r') { *ev=framearr; } } void FromPhysicalLayer(frame *buf) { *buf=data1; } void ToNetworkLayer(packet *buf) { cout<<"\n Receiver : packet received \t"<< i-1; cout<<"\n Acknowledgement sent \t"; getch(); if(i>total) { disc=1; cout<<"\ndiscontinue\n";
cout<<"\n Acknowledgement of above frames sent is received by sender\n\n"; } else cout<<frames[i]<<" "; } if(f%win!=0) cout<<"\n Acknowledgement of above frames sent is received by sender\n"; return 0; }
#include
receiver(m); } void sel_repeat::receiver(int m) { time_t t; int f, j, f1, a1; char ch; srand((unsigned)time(&t)); for(int i=0;i<fr_send_at_instance;i++) { if(rcvd_ack[i]=='n') { f=rand()%10; if(f!=5) { for(int j=0;j<fr_send_at_instance;j++) if(rcvd[j]==send[i]) { cout<<"\n RECEIVER DETAILS :Frame "<<rcvd[j]<<" recieved correctly! "; rcvd[j]=arr[rw]; rw=(rw+1)%m; break; } int j; if(j==fr_send_at_instance) cout<<"\n RECEIVER DETAILS: Duplicate frame "<<send[i]<<" has been discarded.";
a1=rand()%5; if(a1==3) { cout<<"\n (Acknowledgement "<<send[i]<<" lost!)"; cout<<"\n (SENDER TIMEOUT! PLEASE RESEND THE FRAME. )"; rcvd_ack[i]='n'; } else { cout<<"\n (Acknowledgement "<<send[i]<<" recieved.)"; rcvd_ack[i]='p'; } } else { int ld=rand()%2; if(ld==0) { cout<<"\n RECEIVER DETAILS: Frame "<<send[i]<<" is damaged."; cout<<"\n RECEIVER DETAILS: Negative acknowledgement "<<send[i]<<" sent."; } else { cout<<"RECEIVER DETAILS: Frame "<<send[i]<<" is lost!"; cout<<"\n (SENDER TIMEOUT! PLEASE RESEND THE FRAME. )";