Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
COMPUTER NETWORKS
LAB
List of Experiments
S.No. Title of Experiment
1 Study of Network Devices
2 Study of Network IP
3 Implementation of Datalink framing methods(Character count, Bit
stuffing and destuffing)
4 Implementation of Error detection methods(Even and Odd parity CRC
polynomials)
5 Implementation of Unrestricted simplex protocol
6 Implementation of Stop and Wait Protocol
7 Implementation of Djkstra’s algorithm
8 Design of client server application for file transfer
PROCEDURE:
2. Hub: An Ethernet hub, active hub, network hub, repeater hub, hub or
concentrator is a device for connecting multiple twisted pair or fiber
optic Ethernet devices together and making them act as a single network
segment. Hubs work at the physical layer (layer 1) of the OSI model. The
device is a form of multiport repeater. Repeater hubs also participate in
collision detection, forwarding a jam signal to all ports if it detects a
collision.
RESULT:
2. STUDY OF NETWORK IP
AIM: To study the Network IP
Classification of IP address
Sub netting
Super netting
Classification of IP address
As shown in table we teach how the IP addresses are classified and when they
are used.
TCP/IP defines five classes of IP addresses: class A, B, C, D, and E. Each class has
a range of valid IP addresses. The value of the first octet determines the class. IP
addresses from the first three classes (A, B and C) can be used for host addresses.
The other two classes are used for other purposes – class D for multicast and class
E for experimental purposes.
Sub netting
There are some points which should be kept in mind while supernetting:
RESULT:
AIM: To implement Data link framing methods – character count, Bit stuffing
and Destuffing using C language.
THEORY:
1. Fixed size – The frame is of fixed size and there is no need to provide
boundaries to the frame, length of the frame itself acts as delimiter.
PROCEDURE:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 100
int main()
{
char *p,*q;
char temp;
char in[MAXSIZE];
char stuff[MAXSIZE];
chardestuff[MAXSIZE];
int count=0;
p=in;
q=stuff;
while(*p!='\0')
{
if(*p=='0')
{
*q=*p;
q++;
p++;
}
else
{
while(*p=='1' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
*q='0';
q++;
}
count=0;
}
}
*q='\0';
printf("\nthe stuffed character string is");
printf("\n%s",stuff);
p=stuff;
q=destuff;
while(*p!='\0')
{
if(*p=='0')
{
*q=*p;
q++;
p++;
}
else
{
while(*p=='1' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
p++;
}
count=0;
}
}
*q='\0';
printf("\nthedestuffed character string is");
printf("\n%s\n",destuff);
return 0;
}
OUTPUT:
RESULT:
AIM: To implement error detection method-even and odd parity and CRC polynomials using
C language.
THEORY:
A condition when the receiver’s information does not matches with the sender’s
information. During transmission, digital signals suffer from noise that can
introduce errors in the binary bits travelling from sender to receiver. That means a
0 bit may change to 1 or a 1 bit may change to 0. To avoid this, we use error-
detecting codes which are additional data added to a given digital message to help
us detect if any error has occurred during transmission of the message.
Basic approach used for error detection is the use of redundancy bits, where
additional bits are added to facilitate detection of errors. One of the most popular
technique for error detection is CRC(Cyclic Redundancy Check).
PROCEDURE:
PROGRAM:
#include<stdio.h>
char text[100];
char key[100];
char rem[100];
void crc()
{
inti,j;
intkeylen,textlen;
char temp[100];
strcpy(temp,text);
keylen=strlen(key);
for(i=0;i<keylen-1;i++)
strcat(temp,"0");
textlen=strlen(temp);
strncpy(rem,temp,keylen);
while(i!=textlen)
{
if(rem[0]=='0')
{
strcpy(rem,&rem[1]);
rem[keylen-1]=temp[++i];
rem[keylen]='\0';
continue;
}
for(j=0;j<keylen;j++)
rem[j]=((rem[j]-'0')^(key[j]-'0'))+'0';
}
}
main()
{
int i;
int choice;
while(1)
{
printf("\n1.find crc\t2.check crc\t3.exit crc\nyour choice\t");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the input string\n");
scanf("%s",text);
printf("Enter the key\n");
scanf("%s",key);
crc();
printf("the transmitted message is %s\n",strcat(text,rem));
break;
case 2:
printf("Enter the input string\n");
scanf("%s",&text);
printf("Enter the key\n");
scanf("%s",key);
crc();
for(i=0;i<strlen(key)-1;i++)
if(rem[i]=='1')
break;
if(i==strlen(key)-1)
printf("There is no error in the message\n");
else
printf("There is error in the message\n");
break;
case 3:
exit(0);
}
}
}
OUTPUT:
RESULT:
THEORY:
This protocol consists of two procedures - sender and receiver. The sender sends
the data to the receiver and runs on the data link layer of the sender’s machine and
receiver receives the data from the sender and it runs on the data link layer of the
receiver’s machine. And here a frame arrival is used which sends the information
that an undamaged frame has arrived.
This is a very simple protocol in which the sender uses a while loop and it
continuously sends the data to the receiver. The initial work of the receiver is to
wait for the frame. as soon as it starts receiving the frame it set the event to frame
arrival or else event is set to wait for frame.
PROCEDURE:
PROGRAM:
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
typedefstruct
{
intseqno;
intackno;
char data[50];
}frame;
voidfrom_network_layer(char buffer[])
{
printf("Enter Data : ");
scanf("%s",buffer);
}
voidto_physical_layer(int pid1,frame *f)
{
write(pid1,f,sizeof(frame));
}
voidfrom_physical_layer(int pid1,frame *f)
{
read(pid1,f,sizeof(frame));
}
voidto_network_layer(char buffer[])
{
printf("\n%s",buffer);
}
[ SENDER SIDE ]
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include "header.h"
void main()
{
int pid1,i,no;
char buffer[50];
frame f;
system(">pipe1");
pid1=open("pipe1",O_WRONLY);
printf("Enter NUMBER OF DATA : ");
scanf("%d",&no);
write(pid1,&no,sizeof(no));
for(i=0;i<no;i++)
{
from_network_layer(buffer);
strcpy(f.data,buffer);
to_physical_layer(pid1,&f);
}
close(pid1);
}
[ RECEIVER SIDE ]
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include "header.h"
void main()
{
int pid1,no,i;
char buffer[50];
frame f;
pid1=open("pipe1",O_RDONLY);
read(pid1,&no,sizeof(no));
printf("DATA RECEIVED : %d",no);
printf("\nDATA");
for(i=0;i<no;i++)
{
from_physical_layer(pid1,&f);
strcpy(buffer,f.data);
to_network_layer(buffer);
}
close(pid1);
unlink("pipe1");
}
OUTPUT:
RESULT:
AIM: To implement a Data link protocol – Stop and Wait protocol using C
language.
THEORY:
In this method of flow control, the sender sends a single frame to receiver & waits
for an acknowledgment. The next frame is sent by sender only when
acknowledgment of previous frame is received. This process of sending a frame &
waiting for an acknowledgment continues as long as the sender has data to
send. To end up the transmission sender transmits end of transmission (EOT)
frame. The main advantage of stop & wait protocol is its accuracy. Next frame is
transmitted only when the first frame is acknowledged. So there is no chance of
frame being lost. The main disadvantage of this method is that it is inefficient. It
makes the transmission process slow. In this method single frame travels from
source to destination and single acknowledgment travels from destination to
source. As a result each frame sent and received uses the entire time needed to
traverse the link. Moreover, if two devices are distance apart, a lot of time is
wasted waiting for ACKs that leads to increase in total transmission time.
PROCEDURE:
PROGRAM:
[ SENDER SIDE ]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int i, n, ch;
char input[20];
FILE *in;
randomize();
printf(“\n\t\t Stop and Wait Protocol \n”);
printf(“\n 1. Send \n2. Check ACK\n3.EOT\n”);
while(1)
{
printf(“Enter your choice….”);
scanf(“%d”, &ch);
switch(ch)
{
case 1:
in = fopen(“data.txt”, “w”);
printf(“Enter the Data: “);
scanf(“%s”, input);
n = strlen(input);
[ RECEIVER SIDE ]
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i, n,one;
char output[20];
FILE *out;
clrscr();
out=fopen(“data_parity.txt”, “r”);
fscanf(out, “%s”, output);
n = strlen(output);
for(i=0; i<n; i++)
if(output[i]==’1’)
one++;
if(one%2==0)
{
printf(“Received Data has Even Parity\n”);
printf(“Data Accepted\n”);
}
else
{
printf(“Received Data has Odd Parity\n”);
printf(“Data Rejected\n”);
}
printf(“Received Data: “);
for(i=0;i<n-1; i++)
printf(“%c”, output[i];
fclose(out);
getch();
}
OUTPUT:
RESULT:
THEORY:
1) Create a set sptSet (shortest path tree set) that keeps track of vertices included in
shortest path tree, i.e., whose minimum distance from source is calculated and
finalized. Initially, this set is empty.
2) Assign a distance value to all vertices in the input graph. Initialize all distance
values as INFINITE. Assign distance value as 0 for the source vertex so that it is
picked first.
….a) Pick a vertex u which is not there in sptSet and has minimum distance value.
….b) Include u to sptSet.
….c) Update distance value of all adjacent vertices of u. To update the distance
values, iterate through all adjacent vertices. For every adjacent vertex v, if sum of
distance value of u (from source) and weight of edge u-v, is less than the distance
value of v, then update the distance value of v.
PROCEDURE:
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define INFINITY 9999
#define MAX 10
voiddijkstra(int G[MAX][MAX],intn,intstartnode);
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;
}
voiddijkstra(int G[MAX][MAX],intn,intstartnode)
{
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;
}
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++;
}
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);
}
}
OUTPUT:
RESULT:
THEORY:
PROCEDURE:
On the host computer
On the host computer, follow these steps to share the Internet connection:
1. Log on to the host computer as Administrator or as Owner.
2. Click Start, and then click Control Panel.
3. Click Network and Internet Connections.
4. Click Network Connections.
5. Right-click the connection that you use to connect to the Internet. For
example, if you connect to the Internet by using a modem, right-click
the connection that you want under Dial-up / other network available.
6. Click Properties.
7. Click the Advanced tab.
8. Under Internet Connection Sharing, select the Allow other network
users to connect through this computer's Internet connection check box.
9. If you are sharing a dial-up Internet connection, select the Establish a
dial-up connection whenever a computer on my network attempts to
access the Internet check box if you want to permit your computer to
automatically connect to the Internet.
10. Click OK. You receive the following message:
When Internet Connection Sharing is enabled, your LAN adapter
will be set to use IP address 192.168.0.1. Your computer may lose
connectivity with other computers on your network. If these other
computers have static IP addresses, it is a good idea to set them to
obtain their IP addresses automatically. Are you sure you want to
enable Internet Connection Sharing?
11. Click Yes.
The connection to the Internet is shared to other computers on the
local area network (LAN). The network adapter that is connected to the
RESULT: