DCN Lab Manual-CSE-IT
DCN Lab Manual-CSE-IT
DCN Lab Manual-CSE-IT
DEPARTMENT OF COMPUTER
SCIENCE ENGINEERING
Computer Networks Laboratory |
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 |
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 |
AIM: Write a C program to Implement the data link layer framing method such as
character stuffing.
Source Code:
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 |
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 |
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
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 |
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];
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 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 |
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 |
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:
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
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
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.
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