Computer Networks Lab Programs
Computer Networks Lab Programs
LABORATORY
PROGRAM No. 1
Aim: Study of different types of Network cables and Practically implement the cross-
wired cable and straight through cable using clamping tool.
1. Start by stripping off about 2 inches of the plastic jacket off the end of the cable. Be very
careful at this point, as to not nick or cut into the wires, which are inside. Doing so could alter
the characteristics of your cable, or even worse render is useless. Check the wires, one more
time for nicks or cuts. If there are any, just whack the whole end off, and start over.
2. Spread the wires apart, but be sure to hold onto the base of the jacket with your other hand.
You do not want the wires to become untwisted down inside the jacket. Category 5 cable
must only have 1/2 of an inch of 'untwisted' wire at the end; otherwise it will be 'out of spec'.
At this point, you obviously have ALOT more than 1/2 of an inch of un-twisted wire.
3. You have 2 end jacks, which must be installed on your cable. If you are using a pre-made
cable, with one of the ends whacked off, you only have one end to install - the crossed over
end. Below are two diagrams, which show how you need to arrange the cables for each type
of cable end. Decide at this point which end you are making and examine the associated
picture below.
Diagram shows you how to prepare Cross wired connection
Diagram shows you how to prepare straight through wired connection
PROGRAM No. 2
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.
4. Bridge: A network bridge connects multiple network segments at the data link layer
(Layer 2) of the OSI model. In Ethernet networks, the term bridge formally means a device
that behaves according to the IEEE 802.1D standard. A bridge and switch are very much
alike; a switch being a bridge with numerous ports. Switch or Layer 2 switch is often used
interchangeably with bridge.Bridges can analyze incoming data packets to determine if the
bridge is able to send the given packet to another segment of the network.
6. Gate Way: In a communications network, a network node equipped for interfacing with
another network that uses different protocols.
A gateway may contain devices such as protocol translators, impedance matching
devices, rate converters, fault isolators, or signal translators as necessary to provide
system interoperability. It also requires the establishment of mutually acceptable
administrative procedures between both networks.
A protocol translation/mapping gateway interconnects networks with different
network protocol technologies by performing the required protocol conversions.
PROGRAM No. 3
Classification of IP address
Sub netting
Super netting
Apparatus (Software): NA
As show in figure we teach how the ip addresses are classified and when they are used.
Sub netting
Why we Develop sub netting and How to calculate subnet mask and how to identify
subnet address.
Super netting
Why we develop super netting and How to calculate supernet mask and how to
identify supernet address.
PROGRAM NO : 4
Aim: Connect the computers in Local Area Network.
On the host computer, follow these steps to share the Internet connection:
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.
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?
The network adapter that is connected to the LAN is configured with a static IP address
of 192.168.0.1 and a subnet mask of 255.255.255.0
To connect to the Internet by using the shared connection, you must confirm the LAN
adapter IP configuration, and then configure the client computer. To confirm the LAN
adapter IP configuration, follow these steps:
7. In the Internet Protocol (TCP/IP) Properties dialog box, click Obtain an IP address
automatically (if it is not already selected), and then click OK.
Note: You can also assign a unique static IP address in the range of 192.168.0.2 to
192.168.0.254. For example, you can assign the following static IP address, subnet mask, and
default gateway:
8. IP Address 192.168.31.202
9. Subnet mask 255.255.255.0
10. Default gateway 192.168.31.1
11. In the Local Area Connection Properties dialog box, click OK.
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';
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("\nframe after stuffing:\n");
printf("%s",b);
getch();
}
OUTPUT:
Viva Questions:
1. What is Character stuffing?
2. What is the use of character stuffing?
3. Are the delimiters for the character stuffing?
4. Expand DLE STX?
5. Expand DLE ETX?
11
PROGRAM No. : 5(b)
NAME OF THE EXPERIMENT: Bit Stuffing.
OBJECTIVE: Implement the data link layer framing method.
RESOURCE: Turbo C
PROGRAM LOGIC:
The new technique allows data frames to contain an arbitrary number if bits
and allows character codes with an arbitrary no of bits per character. Each frame begins and
ends with special bit pattern, 01111110, called a flag byte. Whenever the sender’s
data link layer encounters five consecutive ones in the data, it automatically stuffs a 0 bit
int o the outgoing bit st ream. This bit stuffing is analogous to charact er stuffing, in
whic h a D LE is stuffed int o t he outgoing character stream before DLE in the data.
SOURCE CODE:
// BIT Stuffing
program
#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);
printf("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)
{
12
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();
}
13
OUTPUT:
Viva questions:
2. What is Stuffing?
3. What is use of Stuffing?
4. With bit stuffing the boundary between two frames can be unambiguously recognize by?
5. Is a analogous to character stuffing?
6. The senders data link layer encounters ...... no of 1’s consecutively
14
PROGRAM No.: 6
NAME OF THE EXPERIMENT: Cyclic Redundancy Check.
OBJECTIVE: Implement on a data set of characters the three CRC polynomials – CRC 12,
CRC16 and CRC CCIP.
RESOURCE: Turbo C
PROGRAM LOGIC:
CRC method can detect a single burst of length n, since only one bit per column will
be changed, a burst of length n+1 will pass undetected, if the first bit is inverted, the last bit
is inverted and all other bits are correct. If the block is badly garbled by a long burst or by
multiple shorter burst, the probability that any of the n columns will have the correct
parity t hat is 0.5 so the proba bilit y of a bad blo ck being expected when it should not
be 2 power(-n). This scheme sometimes known as Cyclic Redundancy Code
SOURCE CODE:
//PROGRAM FOR CYCLIC REDUNDENCY CHECK
#include<stdio.h>
#include<conio.h>
int
gen[4],genl,frl,rem[4];
void main()
{
int i,j,fr[8],dupfr[11],recfr[11],tlen,flag;
clrscr();
frl=8;
genl=4;
printf("enter
frame:");
for(i=0;i<frl;i++)
{
scanf("%d",&fr[i]);
dupfr[i]=fr[i];
}
printf("enter
generator:");
for(i=0;i<genl;i++)
scanf("%d",&gen[i]);
tlen=frl+genl-1;
for(i=frl;i<tlen;i++)
{
dupfr[i]=0;
}
15
remainder(dupfr);
for(i=0;i<frl;i++)
{
recfr[i]=fr[i];
}
for(i=frl,j=1;j<genl;i++,j++)
{
recfr[i]=rem[j];
}
remainder(recfr);
flag=0;
for(i=0;i<4;i++)
{
if(rem[i]!=0)
flag++;
}
if(flag==0)
{
printf("frame received correctly");
}
Else
{
printf("the received frame is wrong");
}
getch();
}
remainder(int fr[])
{
int k,k1,i,j;
for(k=0;k<frl;k++)
{
if(fr[k]==1)
{
k1=k;
for(i=0,j=k;i<genl;i++,j++)
{
rem[i]=fr[j]^gen[i];
}
for(i=0;i<genl;i++)
{
fr[k1]=rem[i];
k1++;
}
}
}
}
16
OUTPUT:
Viva Questions:
1. What is CRC?
2. What is the use of the CRC?
3. Name the CRC standards?
4. Define Checksum?
5. Define generator polynomial?
17
PROGRAM No : 7
RESOURCE: Turbo C
Program Logic: Dijkstra's algorithm is very similar to Prim's algorithm for minimum
spanning tree. Like Prim's MST, we generate a SPT (shortest path tree) with given source as
root. We maintain two sets, one set contains vertices included in shortest path tree, and other
set includes vertices not yet included in shortest path tree.
PROCEDURE: Go to debug -> run or press CTRL + F9 to run the program.
SOURCE CODE:
// .PROGRAM FOR FINDING SHORTEST PATH FOR A GIVEN GRAPH//
#include<stdio.h>
#include<conio.h>
void main()
{
int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;clrscr();
printf("enter the cost matrix\n");
for(i=1;i<=5;i++) for(j=1;j<=5;j++)
scanf("%d",&a[i][j]); printf("enter
the paths\n"); scanf("%d",&p);
printf("enter possible paths\n");
for(i=1;i<=p;i++) for(j=1;j<=5;j++)
scanf("%d",&path[i][j]);
18
for(i=1;i<=p;i++)
{
t[i]=0;
stp=st;
for(j=1;j<=5;j++)
{
edp=path[i][j+1];
t[i]=t[i]+a[stp][edp];
if(edp==ed)
break;
else
stp=edp;
}
}min=t[st];
index=st;
for(i=1;i<=p;i++)
{
if(min>t[i])
{
min=t[i];
index=i;
}
}
printf("minimum cost %d",min);
printf("\n minimum cost path ");
for(i=1;i<=5;i++)
{
printf("--> %d",path[index][i]);
if(path[index][i]==ed)
break;
}
getch();
}
19
Output:
Viva questions:
20
PROGRAM No. : 8
RESOURCE: Turbo C
PROGRAM LOGIC:
Distance Vector Routing Algorithms calculate a best route to reach a
destination based solely on distance. E.g. RIP. RIP calculates the reach ability
based on hop count. It’s different from link state algorithms which consider some other
factors like bandwidth and other metrics to reach a destination. Distance vector
routing algorithms are not preferable for complex networks and take longer to converge.
22
Output:
Viva Questions:
1. What is routing?
2. What is best algorithm among all routing algorithms?
3. What is static routing?
4. Differences between static and dynamic?
5. What is optimality principle?
23
PROGRAM No : 9
SOURCE CODE:
// Write a ‘c’ program for Broadcast tree from subnet of host
#include<stdio.h>
#include<conio.h
> int p,q,u,v,n;
int min=99,mincost=0;
int t[50][2],i,j;
int parent[50],edge[50][50];
main()
{
clrscr();
printf("\n Enter the number of
nodes"); scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("%c\t",65+i);
parent[i]=-1;
}
printf("\n");
for(i=0;i<n;i++)
{
printf("%c",65+i);
for(j=0;j<n;j++)
scanf("%d",&edge[i][j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if(edge[i][j]!=99)
if(min>edge[i][j])
{
24
min=edge[i][j];
u=i;
v=j;
}
p=find(u)
;
q=find(v)
;if(p!=q)
{
t[i][0]=u;
t[i][1]=v;
mincost=mincost+edge[u][v]
; sunion(p,q);
}
Else
{
t[i][0]=-1;t[i][1]=-1;
}
min=99;
}
printf("Minimum cost is %d\n Minimum spanning tree is\n"
,mincost);for(i=0;i<n;i++)
if(t[i][0]!=-1 && t[i][1]!=-1)
{
printf("%c %c %d", 65+t[i][0],65+t[i][1],edge[t[i][0]][t[i][1]]);printf("\n");
}
getch();
}
sunion(int l,int m)
{
parent[l]=m;
}
find(int l)
{
if(parent[l]>0)
i=parent[i];
return i;
25
Output:
Viva questions:
1. What is spanning tree?
2. What is broad cast tree?
3. What are the advantages of broadcast tree?
4. What is flooding?
5. What is subnet?
26
PROGRAM No : 10(a)
SOURCE CODE:
#include<stdio.h
>
#include<conio.h
>
#include<stdlib.h
>
#include<string.h
> void main()
{
int i,ch,lp;char cipher[50],plain[50];
char key[50];
clrscr();
while(1)
{
printf("\n-----MENU ---\n");
printf("\n1:Data Encryption\t\n\n2:Data Decryption\t\n\n3:Exit");
printf("\n\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nData Encryption");
printf("\nEnter the plain text:");
fflush(stdin);
gets(plain);
printf("\nEnter the encryption key:");
gets(key);
lp=strlen(key);
for(i=0;plain[i]!='\0';i++)
cipher[i]=plain[i]^lp;
27
cipher[i]='\0';
printf("\nThe encrypted text is:");
puts(cipher);
break;
case 2:
printf("\nData decryption");
for(i=0;cipher[i]!='\0';i++)
plain[i]=cipher[i]^lp;
printf("\nDecrypted text
is:");puts(plain);
break;
case 3: exit(0);
}
}
getch();
}
28
Output:
Viva Questions:
1. Expand DES
5. Define encryption?
29
PROGRAM No: 10(b)
NAME OF THE EXPERIMENT: Decrypting DES.
OBJECTIVE: Write a program to break the above DES coding
RESOURCE: Turbo C
PROGRAM LOGIC:
Data encryption standard was widely adopted by the industry in security products. Plain
t ext is encr ypt ed in block of 64 bit s yielding 64 bit s of cipher t ext . The algorithm
which is parameterized by a 56 bit key has 19 distinct stages. The first stage is a key
independent transposition and the last stage is exactly inverse of the transposition. There
mining stages are functionally identical but are parameterized by different functions of the key.
The algorithm has been designed to allow decryption to be done with the same key as
encryption.
SOURCE CODE:
/*Write a program to break the above DES
coding*/ #include<stdio.h>
#include<conio.>
#include<string.>
#include<ctype.>
void main()
{
char pwd[20];
char alpha[26]="abcdefghijklmnopqrstuvwxyz";
int num[20],i,n,key;
clrscr();
printf("\nEnter the password:");
scanf("%s",&pwd);
n=strlen(pwd);
for(i=0;i<n;i++)
num[i]=toascii(tolower(pwd[i]))-'a';
printf("\nEnter the key:");
scanf("%d",&key);
for(i=0;i<n;i++)
num[i]=(num[i]+key)%26;
for(i=0;i<n;i++)
pwd[i]=alpha[num[i]];
printf("\nThe key is:%d",key);
printf("\nEncrypted text is:%s",pwd);
for(i=0;i<n;i++)
{
num[i]=(num[i]-key)%26;
if(num[i]<0)
30
num[i]=26+num[i];
pwd[i]=alpha[num[i]];
}
printf("\nDecrypted text is:%s",pwd);getch();
}
31
Output:
Viva Questions:
1. Define decryption
2. What is private key?
3. What is cipher feedback mode?
4. Define product cipher
5. What is DES chaining?
32
PROGRAM No : 11
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct frame{
int fslno;
char finfo[20];
};
struct frame arr[10];
int n;
void sort()
{
int i,j,ex;
struct frame temp;
for(i=0;i<n;i++)
{
ex=0;
for(j=0;j<n-i-1;j++)
if(arr[j].fslno>arr[j+1].fslno)
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
ex++;
}
if(ex==0) break;
}
}
void main()
{
int i;
clrscr();
33
printf("\n Enter the number of frames \n");
scanf("%d",&n);
for(i=0;i<n;i++)
{ arr[i].fslno=random(50);
printf("\n Enter the frame contents for sequence number
%d\n",arr[i].fslno);
scanf("%s",arr[i].finfo);
}
sort();
printf("\n The frames in sequence \n");
for(i=0;i<n;i++)
printf("\n %d\t%s \n",arr[i].fslno,arr[i].finfo);
getch();
}
34
OUTPUT
35
PROGRAM NO: 12
Aim: Configure Network using Link State Vector Routing protocol.
OSPF
Procedure:
36
PROGRAM No: 13
SOFTWARE REQUIREMENTS:
Turbo C THEORY: The upper layers work on some generalized view of network architecture and
are not aware of actual hardware data processing. Hence, the upper layers expect error-free
transmission between the systems. Most of the applications would not function expectedly if they
receive erroneous data. Applications such as voice and video may not be that affected and with some
errors they may still function well. Data-link layer uses some error control mechanism to ensure that
frames (data bit streams) are transmitted with certain level of accuracy. But to understand how errors is
controlled, it is essential to know what types of errors may occur. CRC is a different approach to detect
if the received frame contains valid data. This technique involves binary division of the data bits being
sent. The divisor is generated using polynomials. The sender performs a division operation on the bits
being sent and calculates the remainder. Before sending the actual bits, the sender adds the remainder
at the end of the actual bits. Actual data bits plus the remainder is called a codeword. The sender
transmits data bits as codewords.
ALGORITHM:
1. Open Turbo c++ software and type the program for error detection
2. Get the input in the form of bits.
3. Append 16 zeros as redundancy bits.
4. Divide the appended data using a divisor polynomial
5. The resulting data should be transmitted to the receiver.
6. At the receiver the received data is entered.
7. The same process is repeated at the receiver.
8. If the remainder is zero there is no error otherwise there is some error in the received bits
9. Run the program
C PROGRAM :
#include <stdio.h>
char m[50],g[50],r[50],q[50],temp[50];
void caltrans(int);
void crc(int);
void calram();
void shiftl();
int main() { int n,i=0;
char ch,flag=0;
printf("Enter the frame bits:");
while((ch=getc(stdin))!='\n')
m[i++]=ch;
n=i;
for(i=0;i<=16;i++)
m{m++}='0';
m[n]= '0';
37
printf("Message after appending 16 zeros:%s",m);
for(i=0;i<=16;i++)
g[i]='0';
g[0]=g[4]=g[11]=g[16]='1';g[17]='\0';
printf("\ngenerator:%s\n",g);
crc(n);
printf("\n\nquotient:%s",q);
caltrans(n);
printf("\ntransmitted frame:%s",m);
printf("\nEnter transmitted frame:");
scanf("\n%s",m);
printf("CRC checking\n");
crc(n);
printf("\n\nlast remainder:%s",r);
for(i=1;i<=16;i++)
if(r[i]!='0') flag=1;
else
continue;
if(flag==1) printf("Error during transmission");
else
printf("\n\nReceived freme is correct"); }
void crc(int n)
{
int i,j;
for(i=0;i<16;i++)
r[i]=m[i];
printf("\nintermediate remainder\n");
for(i=0;i
{
q[i]='1';
calram(); }
else
{
q[i]='0';
shiftl();
}
r[16]=m[17+i];
r[17]='\0';
printf("\nremainder %d:%s",i+1,r);
for(j=0;j<=17;j++) temp[j]=r[j];
}
q[n-16]='\0';
}
void calram()
{ int i,j;
for(i=1;i<=16;i++) r[i-1]=((int)temp[i]-48)^((int) g[i]-48)+48;
}
void shiftl()
{ int i;
for(i=1;i<=16;i++) r[i-1]=r[i];
}
void caltrans(int n)
38
{ int i,k=0;
for(i=n-16;i++)
m[i]=((int)m[i]-48)^((int)r[k++]-48)+48;
m[i]='\0';
}
OUTPUT:
VIVA QUESTIONS:
1. What are the types of errors?
2. What is Error Detection? What are its methods?
3. What is Redundancy?
4. What is CRC?
5. What is Checksum
39