Nothing Special   »   [go: up one dir, main page]

DCN Lab Manual-CSE-IT

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Computer Networks Laboratory |

COMPUTER NETWORKS AND


WEB TECHNOLOGIES LAB
MANUAL

(III-B. TECH-I SEM-CSE)

DEPARTMENT OF COMPUTER
SCIENCE ENGINEERING
Computer Networks Laboratory |

Computer Networks Laboratory Manual (2020-21)


B.Tech. III Year I Semester Syllabus
Course Objectives
1. To understand the working principle of various communication protocols.
2. To understand the network simulator environment and visualize a network
topology and observe its performance
3. To analyze the traffic flow and the contents of protocol frames

Course Outcomes:
1. Implement data link layer farming methods
2. Analyze error detection and error correction codes.
3. Implement and analyze routing and congestion issues in network design.
4. Implement Encoding and Decoding techniques used in presentation layer
5. To be able to work with different network tools

List Of Experiment:
1. Implement the data link layer framing methods such as character, character-stuffing
and bit stuffing.
2. Character stuffing
3. Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and
CRC CCIP
4. Develop a simple data link layer that performs the flow control using the sliding
window protocol, and loss recovery using the Go-Back-N mechanism.
5. Implement Dijsktras algorithm to compute the shortest path through a network
6. Take an example subnet of hosts and obtain a broadcast tree for the subnet.
7. Implement distance vector routing algorithm for obtaining routing tables at each
node.
8. Implement data encryption and data decryption
9. Write a program for congestion control using Leaky bucket algorithm.
10. Write a program for frame sorting technique used in buffers.
11. Wireshark
1. Packet Capture Using Wire shark
2. Starting Wire shark
3. Viewing Captured Traffic
4. Analysis and Statistics and Filters.
12. How to run Nmap scan
13. Operating System Detection using Nmap
14. Do the following using NS2 Simulator
1. NS2 Simulator-Introduction
2. Simulate to Find the Number of Packets Dropped
3. Simulate to Find the Number of Packets Dropped by TCP/UDP
4. Simulate to Find the Number of Packets Dropped due to Congestion
5. Simulate to Compare Data Rateand Throughput.
6. Simulate to Plot Congestion for Different Source/Destination
7. Simulate to Determine the Performance with respect to Transmission of
Packets
Computer Networks Laboratory |

1. NAME OF THE EXPERIMENT: Bit Stuffing.


AIM: Write a C program to implement the data link layer framing methods such as bit
stuffing.

Source Code:
#include<stdio.H>
#include<conio.H>
#include<string.h>

void main()
{
int a[20],b[30],i,j,k,count,n;
clrscr();
printf("enter frame length:");
scanf("%d",&n);
pritf("enter input frame(0's&1's only):");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0;count=1;j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;a[k]==1&&k<n&&count<5;k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After stuffing the frame is:");
for(i=0;i<j;i++)
printf("%d",b[i]);
getch();
}

Output:
Enter the number of bits: 10
1010111111
Computer Networks Laboratory |

Data after stuffing: 10101111101


2. NAME OF THE EXPERIMENT: Character Stuffing.

AIM: Write a C program to Implement the data link layer framing method such as
character stuffing.

Source Code:

//program for character stuffing


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
clrscr();
printf("enter string:\n");
scanf("%s",&a);
n=strlen(a);
printf("enter position\n");
scanf("%d",&pos);
if(pos>n)
{
printf("invalid position,Enter again:");
scanf("%d",&pos);
}
printf("enter the character\n");
ch=getche();
b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d'&&a[i+1]=='l'&& a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e;
Computer Networks Laboratory |

j=j+3;
}
b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\n frame after stuffing: \n");
printf("%s",b);
getch();
}

OUTPUT:
Enter String:
haiarchana
Enter position:
4
Enter the Character
K
Frame after stuffing:
dlestxhaidlekdlearchanadleetx
Computer Networks Laboratory |

3. NAME OF THE EXPERIMENT: Cyclic Redundancy Check

AIM: Write a C program to implement on a data set characters the three CRC polynomials
– CRC 12, CRC 16, and CRC CCIP.

Source Code:
// program for Cyclic Redundancy Check
#include<stdio.h>
#include<conio.h>
int main(void)
{
int data[50],div[16],rem[16];
int datalen, divlen, i,j,k;
int ch;
clrscr();
printf("Enter the data: ");
i = 0;
while((ch = fgetc(stdin)) != '\n')
{
if(ch == '1')
data[i] = 1;
else
data[i] = 0;
i++;
}
datalen = i;
printf("\nEnter the divisor: ");
i = 0;
while((ch = fgetc(stdin)) != '\n')
{
if(ch == '1')
div[i] = 1;
else
div[i] = 0;
i++;
}
divlen = i;
for(i = datalen ; i < datalen + divlen - 1 ; i++)
data[i] = 0;
datalen = datalen + divlen - 1;
for(i = 0 ; i < divlen ; i++)
rem[i] = data[i];
k = divlen-1;
while(k < datalen)
if(rem[0] == 1)
{
for(i = 0 ; i < divlen ; i++)
rem[i] = rem[i] ^ div[i];
}

else
{
if(k == datalen-1)
break;
for(i = 0 ; i < divlen-1 ; i++)
Computer Networks Laboratory |

{
rem[i] = rem[i+1];
printf("%d",rem[i]);
}
rem[i] = data[++k];
printf("%d\n",rem[i]);
}
j=1;
for(i = datalen - divlen + 1 ; i < datalen ; i++)
{
data[i] = rem[j++];
}
printf("\nThe data to be sent is\n");
for(i = 0 ; i < datalen ; i++)
printf("%d",data[i]);
getch();
return 0;
}

OUTPUT:
Enter the data: 10101111
Enter the divisor: 1011
0011
0111
1111
1001
0100
COMPUTER NETWORKS LAB
14 COMPUTER SCIENCE & ENGINEERING

1000
0110
The data to be sent is
10101111110
Computer Networks Laboratory |

4. NAME OF THE EXPERIMENT: Shortest path

AIM: Write a C program to Implement Dijkstra’s Algorithm to compute the shortest path
through a given path.

SOURCE CODE:

#include<stdio.h>
#include<conio.h>
#define INFINITY 9999
#define MAX 10

void dijkstra(int G[MAX][MAX],int n,int startnode);

int main()
{
int G[MAX][MAX],i,j,n,u;
printf("Enter no. of vertices:");
scanf("%d",&n);
printf("\nEnter the adjacency matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&G[i][j]);
printf("\nEnter the starting node:");
scanf("%d",&u);
dijkstra(G,n,u);
return 0;
}
void dijkstra(int G[MAX][MAX],int n,int startnode)
{
int cost[MAX][MAX],distance[MAX],pred[MAX];
int visited[MAX],count,mindistance,nextnode,i,j;
//pred[] stores the predecessor of each node
//count gives the number of nodes seen so far
//create the cost matrix
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(G[i][j]==0)
cost[i][j]=INFINITY;
else
cost[i][j]=G[i][j];
//initialize pred[],distance[] and visited[]
for(i=0;i<n;i++)
{
distance[i]=cost[startnode][i];
pred[i]=startnode;
visited[i]=0;
}
Computer Networks Laboratory |

distance[startnode]=0;
visited[startnode]=1;
count=1;
while(count<n-1)
{
mindistance=INFINITY;
//nextnode gives the node at minimum distance
for(i=0;i<n;i++)
if(distance[i]<mindistance&&!visited[i])
{
mindistance=distance[i];
nextnode=i;
}
//check if a better path exists through nextnode
visited[nextnode]=1;
for(i=0;i<n;i++)
if(!visited[i])
if(mindistance+cost[nextnode][i]<distance[i])
{
distance[i]=mindistance+cost[nextnode][i];
pred[i]=nextnode;
}
count++;
}
//print the path and distance of each node
for(i=0;i<n;i++)
if(i!=startnode)
{
printf("\nDistance of node%d=%d",i,distance[i]);
printf("\nPath=%d",i);
j=i;
do
{
j=pred[j];
printf("<-%d",j);
}while(j!=startnode);
}
}
Computer Networks Laboratory |

5. NAME OF THE EXPERIMENT: Sliding Window Protocol

AIM: Develop a simple data link layer that performs the flow control using the sliding
window protocol, and loss recovery using the Go-Back-N mechanism.

Source Code:

#include<stdio.h>

int main()
{
int w,i,f,frames[50];

printf("Enter window size: ");


scanf("%d",&w);

printf("\nEnter number of frames to transmit: ");


scanf("%d",&f);

printf("\nEnter %d frames: ",f);

for(i=1;i<=f;i++)
scanf("%d",&frames[i]);

printf("\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the
receiver\n\n",w);

for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}

if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");

return 0;
}

Output

Enter window size: 3

Enter number of frames to transmit: 5

Enter 5 frames: 12 5 89 4 6
Computer Networks Laboratory |

With sliding window protocol the frames will be sent in the following manner (assuming no
corruption of frames)

After sending 3 frames at each stage sender waits for acknowledgement sent by the receiver
12 5 89
Acknowledgement of above frames sent is received by sender

46
Acknowledgement of above frames sent is received by sender
Computer Networks Laboratory |

6. NAME OF THE EXPERIMENT: Distant Vector Routing

AIM: Write a C program to take an example subnet graph with weights indicating delay
between nodes. Now obtain Routing table art each node using distance vector routing
algorithm.

Source Code:

#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];

int main()
{
int dmat[20][20];
int n,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&n);
printf("\nEnter the cost matrix :\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j;
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[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\nState value for router %d is \n",i+1);
for(j=0;j<n;j++)
{
printf("\t\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
}
Computer Networks Laboratory |

7. NAME OF THE EXPERIMENT: Broadcast Tree

AIM: Write a C program Implement Broadcast Tree for a given subnet hosts.

SOURCE CODE:

#include<stdio.h>
int a[10][10],n;
main()
{
int i,j,root;
clrscr();
printf("Enter no.of nodes:");
scanf("%d",&n);
printf("Enter adjacent matrix\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
printf("Enter connecting of %d>%d::",i,j);
scanf("%d",&a[i][j]);
}
printf("Enter root node:");
scanf("%d",&root);
adj(root);
}
adj(int k)
{
int i,j;
printf("Adjacent node of root node::\n");
printf("%d\n",k);
for(j=1;j<=n;j++)
{
if(a[k][j]==1 || a[j][k]==1)
printf("%d\t",j);
}
printf("\n");
for(i=1;i<=n;i++)
{
if((a[k][j]==0) && (a[i][k]==0) && (i!=k))
printf("%d",i);
}
}

OUTPUT:

Enter no.of nodes:5

Enter adjacent matrix


Enter connecting of 1–>1::0
Enter connecting of 1–>2::1
Enter connecting of 1–>3::1
Enter connecting of 1–>4::0
Enter connecting of 1–>5::0
Enter connecting of 2–>1::1
Computer Networks Laboratory |

Enter connecting of 2–>2::0


Enter connecting of 2–>3::1
Enter connecting of 2–>4::1
Enter connecting of 2–>5::0
Enter connecting of 3–>1::1
Enter connecting of 3–>2::1
Enter connecting of 3–>3::0
Enter connecting of 3–>4::0
Enter connecting of 3–>5::0
Enter connecting of 4–>1::0
Enter connecting of 4–>2::1
Enter connecting of 4–>3::0
Enter connecting of 4–>4::0
Enter connecting of 4–>5::1
Enter connecting of 5–>1::0
Enter connecting of 5–>2::0
Enter connecting of 5–>3::0
Enter connecting of 5–>4::1
Enter connecting of 5–>5::0

Enter root node:2


Adjacent node of root node::
2
134
5
Computer Networks Laboratory |

Introduction to NS2 Simulator


Network Simulator (Version 2), widely known as NS2, is simply an event-
driven simulation tool that has proved useful in studying the dynamic nature of
communication networks. Simulation of wired as well as wireless network functions
and protocols (e.g., routing algorithms, TCP, UDP) can be done using NS2. In
general, NS2 provides users with a way of specifying such network protocols and
simulating their corresponding behaviours.

Due to its flexibility and modular nature, NS2 has gained constant popularity
in the networking research community since its birth in 1989. Ever since, several
revolutions and revisions have marked the growing maturity of the tool, thanks to
substantial contributions from the players in the field. Among these are the
University of California and Cornell University who developed the REAL network
simulator,1 the foundation on which NS is invented. Since 1995 the Defense
Advanced Research Projects Agency (DARPA) supported the development of NS
through the Virtual Internetwork Test bed (VINT) project [10].2 Currently the
National Science Foundation (NSF) has joined the ride in development. Last but not
the least, the group of researchers and developers in the community are constantly
working to keep NS2 strong and versatile.

NS2- Architecture:
Computer Networks Laboratory |

1. Name of the Program: Simulate to Find the Number of Packets Dropped by TCP/UDP

AIM: Simulate a four-node point-to-point network and connect the link as follows: Apply a
TCP agent between n0 to n3 and apply a UDP agent between n1 and n3. Apply relevant
applications over TCP and UDP agents changing the parameters and determine the number
of packets sent by two agents.

Topology:-

Sender:-
stcp –p 3000 –l 1024 1.0.1.3
stg –u 1024 1.0.1.3
Receiver:-
rtcp –p 3000 –l 1024
rtg –u 3000

Parameters:-
Throughput of incoming and outgoing Packets

Step1: Drawing topology


1. Select/click the HOST icon on the toolbar and click the left mouse button on the
editor, to place a host on the editor. Repeat the above procedure and place two other
hosts “HOST2” and “HOST3” on the editor.
2. Select/click the HUB (or SWITCH) icon on the toolbar and click the left mouse button
on the editor, to place a HUB (or SWITCH) on the editor.
3. Click on the LINK icon on the toolbar and connect HOST1 to HUB, HOST2 to HUB and
HUB to HOST3
4. Click on the “E” icon on the toolbar to save the current topology e.g: file2.tpl (Look
for the******.tpl extension.)

NOTE: Changes cannot / (should not) be done after selecting the “E” icon.

Step2: Configuration
1. Double click the left mouse button while cursor is on HOST1 to open the HOST
window.
2. Select Add button on the HOST window to invoke the command window and provide
the
following command in the command textbox. stcp –p 21 –l 1024 1.0.1.3
3. Click OK button on the command window to exit
4. Click NODE EDITOR Button on the HOST window and select the MAC tab from the
modal
window that pops up.
5. Select LOG STATISTICS and select checkbox for output throughput in the MAC
Computer Networks Laboratory |

window
6. Click OK button on the MAC window to exit and once again click on the OK button
on the
HOST window to exit.
7. Double click the left mouse button while cursor is on HOST2 to open the HOST
window.
8. Select Add button on the HOST window to invoke the command window and provide
the
following command in the command textbox.
stg –u 1024 100 1.0.1.3
9. Click OK button on the command window to exit
10. Click NODE EDITOR Button on the HOST window and select the MAC tab from the
modal
window that pops up.
11. Select LOG STATISTICS and select checkbox for output throughput in the MAC
window
12. Click OK button on the MAC window to exit and once again click on the OK button
on the
HOST window to exit.
13. Double click the left mouse button while cursor is on HOST3 to open the HOST
window.
14. Select Add button on the HOST window to invoke the command window and
provide the
following command in the command textbox.
rtcp –p 21 –l 1024
15. Click OK button on the command window to exit.
16. Also add the following command on HOST3
rtg –u –w log1
17. Click NODE EDITOR Button on the HOST window and select the MAC tab from the
modal
window that pops up.
18. Select LOG STATISTICS and select checkbox for input and output throughput in the
MAC
window
19. Click OK button on the MAC window to exit and once again click on the OK button
on the
HOST window to exit.

Step3: Simulate

i. Click “R” icon on the tool bar


ii. Select Simulation in the menu bar and click/ select RUN in the dropdown list to
execute the simulation.
iii. To start playback select “►” icon located at the bottom right corner of the editor.
iv. To view results, Open up new TERMINAL window, move to file2.results folder and
open input and output throughput log files in separate TERMINAL window.

Caution: file2 is the hypothetical name given to this simulation.


(Refer Step 1.4)
Computer Networks Laboratory |

2. Name of the Program: Simulate to Find the Number of Packets Dropped due to
Congestion.

AIM: Simulate the transmission of ping messages over a network topology consisting of 6
nodes and find the number of packets dropped due to congestion.

Topology:-

Sender:-
stcp –p 2000 –l 1024 1.0.1.4

Receiver:-
rtcp –p 2000 –l 1024

Command Console:-
Goto tools-> simulation time and change Simulation time to 100. During run mode, double
click host
2 and then click command console. And execute the following command.
ping 1.0.1.4

Parameters:-
Drop Packets and Collision Packets.

Step1: Drawing topology


1. Select/click the SUBNET icon on the toolbar and click the left mouse button on the
editor, to place a SUBNET on the editor.
2. A pop up window appears requesting the number of nodes and radius for the
subnet
Set number of nodes=6;
Set radius of subnet >150
3. Click on the “E” icon on the toolbar to save the current topology e.g: file4.tpl (Look
for the ******.tpl extension.)

NOTE: Changes cannot / (should not) be done after selecting

Step2 : Configuration
Computer Networks Laboratory |

4. Double click the left mouse button while cursor is on a HOST to open the HOST
window.
5. Click NODE EDITOR Button on the HOST window and select the INTERFACE tab (1st
tab)
from the modal window that pops up.
6. Determine the IP address of the selected host.
7. Click OK button on the INTERFACE window to exit and once again click on the OK
button on the HOST window to exit.
8. Repeat the above step for 2 other HOSTS
9. Also click NODE EDITOR Button on the HOST window and select the MAC tab from
the modal window that pops up.
10. Select LOG STATISTICS and select checkbox for drop and collision log statistics in
the MAC window
11. Click OK button on the MAC window to exit and once again click on the OK button
on the
HOST window to exit.
12. Repeat steps 6 to 9 for the other hosts selected at step 5.
13. Select G_Setting from the menu bar and select Simulation from the drop down list
Set simulation time>600sec

Step3: Simulate

i. Click “R” icon on the tool bar


ii. Select Simulation in the menu bar and click/ select RUN in the dropdown list to
execute the simulation.
iii. During simulation, open a new terminal window.
iv. Type ping IP address of a host in the subnet at the command prompt.
v. To view results, Open up new TERMINAL window, move to file4.results folder and
open drop and collision log files in separate TERMINAL window.

Caution: file4 is the hypothetical name given to this simulation.


(Refer Step 1.3)

You might also like