Computer Networks Practical File, Study notes of Computer Networks

Computer Networks Practical File

Typology: Study notes

2022/2023

Uploaded on 12/09/2022

anirban-21hcs4116
anirban-21hcs4116 🇮🇳

2 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COMPUTER NETWORKS
PRACTICAL FILE
BSc COMPUTER SCIENCE HONS
III SEMESTER
NIRBAN BHATTACHARJEE
21015570015
A
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Computer Networks Practical File and more Study notes Computer Networks in PDF only on Docsity!

COMPUTER NETWORKS

PRACTICAL FILE

BSc COMPUTER SCIENCE HONS

III SEMESTER

NIRBAN BHATTACHARJEE

A

INDEX

S. No PRACTICAL DETAIL PAGE No.

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; }

Question 2

WAP in C++ to simulate and implement stop and wait protocol for noisy

channel.

#include #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<dos.h> using namespace std; #define t 5 #define max 1 #define total 5 int randn(int n) { return rand()%n+1; } typedef struct info { int data; }packet; typedef struct info { int kind;

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; }

Question 4

WAP in C++ to simulate and implement selective repeat sliding window

protocol.

#include #include<conio.h> #include<stdlib.h> #include<time.h> #include<math.h> #define TOT_FRAMES 500 #define FRAMES_SEND 10 using namespace std; class sel_repeat { int fr_send_at_instance; int arr[TOT_FRAMES]; int send[FRAMES_SEND]; int rcvd[FRAMES_SEND]; char rcvd_ack[FRAMES_SEND]; int sw; int rw; public: void input(); void sender(int); void receiver(int); };

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. )";