R20 CN Lab Manual
R20 CN Lab Manual
CERTIFICATE
Date: Date:
Date: Date:
1
INDEX
Page
S.No Name of the Experiment DATE No Remarks
1. Study of Network devices in detail and connect
the computers in Local Area Network.
2
EXPERIMENT-1
a) 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.
4
Diagram shows you how to prepare straight through wired connection
5
b) AIM: Study of following Network Devices in Detail
Repeater
Hub
Switch
Bridge
Router
Gate Way
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 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.
6
Bridge: A network bridge connects multiple network segments at the data link layer of the OSI
model. In Ethernet networks, the term bridge formally means a device that behaves according to the
IEEE 802.1 D standards. 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.
Router: A router is an electronic device that interconnects two or more computer networks, and
selectively interchanges packets of data between them. Each data packet contains address
information that a router can use to determine if the source and destination are on the same
network, or if the data packet must be transferred from one network to another. Where multiple
routers are used in a large collection of interconnected networks, the routers exchange information
about target system addresses, so that each router can build up a table showing the preferred paths
between any two systems on the interconnected networks.
Gateway:
7
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.
8
c) AIM: Study of network IP
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.
9
d) AIM: Connect the computers in Local Area Network.
PROCEDURE:
On the host computer, follow these steps to share the Internet connection:
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:
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.
12. Quit Control Panel.
10
EXPERIMENT-2
AIM: Write a Program to implement the data link layer framing methods such as
i) Character stuffing ii) bit stuffing.
i) PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
int i,k=0,n,j=6;
char s[100],res[100]=" ",a[100]=" ";
printf("Enter the string:");
gets(s);
strcpy(res,"dlestx");
for(i=0;s[i]!='\0';i++)
{
if(s[i]=='d'&&s[i+1]=='l'&&s[i+2]=='e')
{
res[j]='d';
res[j+1]='l';
res[j+2]='e';
j=j+3;
}
res[j]=s[i];
j++;
}
strcat(res,"dleetx");
printf("Stuffed char:%s",res);
n=strlen(res);
for(i=6;i<n-6;i++)
{
if(res[i]=='d'&&res[i+1]=='l'&&res[i+2]=='e')
{
i=i+3;
}
a[k]=res[i];
k++;
}
printf("\nDestuffed char:%s",a);
}
OUTPUT:
Enter the string:hello
Stuffed char:dlestxhellodleetx
Destuffed char:hello
13
ii)PROGRAM:
a)
#include<stdio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
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)
{
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]);
}
OUTPUT:
Enter frame length:7
Enter input frame (0's & 1's only):
1
1
1
1
1
1
1
After stuffing the frame is:11111011
14
b)
#include <stdio.h>
#include <string.h>
int main() {
char data[100], stuffedData[200];
int i, count = 0, j = 0;
printf("Enter the data: ");
scanf("%s", data);
for(i = 0; i < strlen(data); i++) {
if(data[i] == '1') {
count++;
stuffedData[j++] = data[i];
}
else {
count = 0;
stuffedData[j++] = data[i];
}
if(count == 5) {
count = 0;
stuffedData[j++] = '0';
}
}
stuffedData[j] = '\0';
printf("Data after bit stuffing: %s\n", stuffedData);
return 0;
}
OUTPUT:
15
EXPERIMENT-3
AIM: Write a Program to implement data link layer framing method checksum.
PROGRAM:
#include <stdio.h>
#include <string.h>
// Function to find the One's complement of the given binary string
void Ones_complement(char* data) {
for (int i = 0; i < strlen(data); i++) {
if (data[i] == '0')
data[i] = '1';
Else
data[i] = '0';
}
}
// Function to return the checksum value of the given string when divided in K size blocks
void checkSum(char* data, int block_size, char* result) {
int n = strlen(data);
// After binary addition of two blocks with carry, if carry is 1 then apply binary addition
char final[block_size + 1];
if (carry == 1) {
for (int l = block_size - 1; l >= 0; l--) {
if (carry == 0) {
final[l] = additions[l];
}
else if (((additions[l] - '0') + carry) % 2 == 0) {
final[l] = '0';
carry = 1;
}
else {
final[l] = '1';
carry = 0;
}
}
strncpy(result, final, block_size);
}
else {
strncpy(result, additions, block_size);
}
}
// Return One's complements of result value which represents the required checksum value
Ones_complement(result);
}
17
// Function to check if the received message is the same as the sender's message
int checker(char* sent_message, char* rec_message, int block_size) {
char sender_checksum[block_size + 1];
char receiver_checksum[block_size + 1];
// Driver Code
int main() {
char sent_message[] = "10000101011000111001010011101101";
char recv_message[] = "10000101011000111001010011101101";
int block_size = 8;
if (checker(sent_message, recv_message, block_size)) {
printf("No Error");
}
else {
printf("Error");
}
return 0;
}
OUTPUT:
No Error
18
EXPERIMENT-4
AIM: Write a program for Hamming Code generation for error detection and correction.
PROGRAM:
#include <math.h>
#include <stdio.h>
// Store input
bits
int input[32];
// Store hamming
code
int code[32];
// Driver Code
void main()
{
// Given input message Bit
input[0] = 0;
input[1] = 1;
input[2] = 1;
input[3] = 1;
int N = 4;
// Function Call
solve(input, N);
}
OUTPUT:
20
EXPERIMENT-5
AIM: Write a program to implement on a data set of characters the three CRC polynomials – CRC 12, CRC
16 and CRC CCIP.
PROGRAM:
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<stdlib.h>
int copy();
int check();
int i,j,k,t,count=0,num=0;
int gen[10],frame[30],rem[30],temp[30];
void main()
{
char c,plym[50];
char ch[]={'0','1','2','3','4','5','6','7','8','9'};
clrscr();
printf("\t\t\t**CYCLIC REDUNDANCY CHECK-12**\n\n\n");
for(i=0;i<50;i++)
plym[i]='\0';
for(i=0;i<30;i++)
temp[i]=rem[i]=frame[i]='\0';
for(i=0;i<10;i++)
gen[i]='\0';
printf("enter the polynomial:");
gets(plym);
plym[strlen(plym)]=' ';
for(i=0;i<strlen(plym);i++)
{
if(plym[i]=='x')
{
i++;
for(;plym[i]!=' ';count,i++)
{
}
if(count==3)
{
for(i=i-1,j=3;j<=9;j++)
if(plym[i]==ch[j])
{
printf("\Enter the polynomial's");
printf("degree is high");
getch();
22
exit(0);
}
for(j=0,num=10;j<=2;j++)
if(plym[i]==ch[j])
{
num=num+j;
frame[num]=1;
}
}
if(count==2)
{
for(i=i-1,j=1,num=0;j<=9;j++)
if(plym[i]==ch[j])
num=j;
frame[num]=1;
}
if(count==0)
frame[1]=1;
count=0;
}
else if(plym[i]=='1')
frame[0]=1;
}
printf("Frame is:");
for(i=12,j=0;i>=0;i--,j++)
{
temp[j]=frame[i];
printf("%d",frame[i]);
}
printf("\n\n\n>>>>both high & low orders");
printf("bits of GENERATOR must be 1<<<<");
printf("\n enter the generator:");
for(num=i=0;(c=getchar())!='\n';i++,num)
{
if(c=='1')
gen[i]=1;
else if(c=='0')
gen[i]=0;
else
{
printf("\nEnter the GENERATOR");
printf("is other then 0 or 1");
getch();
exit(0);
}
}
for(j=13,i=i-1;i>0;i--,j++)
23
temp[j]=0;
printf("\n\n Frame after appending 0's:");
copy();
check();
printf("\n The REMAINDER is:");
for(i=13;i<j;i++)
{
temp[i]=rem[i];
printf("%d",rem[i]);
}
printf("\n\n\n Transmitting FRAME....");
delay(10000);
printf("\n\n\n Transmitted FRAME is:");
copy();
check();
printf("\n frame received");
printf("\n\n\n checking for errors..");
delay(10000);
printf("\n\n\n received frame is:");
copy();
check();
printf("\n the remainder is:");
for(i=13;i<j;i++)
printf("%d",rem[i]);
printf("\n DATA SENT SUCCESSFULLY");
getch();
}
check()
{
for(i=0;i<=12;i++)
{
if(rem[i]==0)
continue;
else
{
for(k=0,t=i;k<num;k++,t++)
{
if(rem[t]==1&&gen[k]==1)
rem[t]=0;
else if(rem[t]==0&&gen[k]==0)
rem[t]=0;
else if(rem[t]==1&&gen[k]==0)
rem[t]=1;
else if(rem[t]==0&&gen[k]==1)
rem[t]=1;
}
}
24
}
return 0;
}
copy()
{
for(i=0;i<j;i++)
{
printf("%d",temp[i]);
rem[i]=temp[i];
}
return 0;
}
OUTPUT:
25
EXPERIMENT-6
AIM: Write a program to implement Sliding window protocol for Goback N.
PROGRAM:
#include<stdio.h>
int main()
{
int windowsize,sent=0,ack,i;
printf("enter window size\n");
scanf("%d",&windowsize);
while(1)
{
for(i=0;i<windowsize;i++)
{
printf("Frame %d has been transmitted.\n",sent);
sent++;
if(sent==windowsize)
break;
}
printf("\nPlease enter the last Acknowledgement received.\n");
scanf("%d",&ack);
if(ack==windowsize)
break;
else
sent=ack;
}
return 0;
}
OUTPUT:
enter window size
8
Frame 0 has been transmitted.
Frame 1 has been transmitted.
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Frame 5 has been transmitted.
Frame 6 has been transmitted.
Frame 7 has been transmitted.
Please enter the last Acknowledgement received.
2
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Frame 5 has been transmitted.
26
Frame 6 has been transmitted.
Frame 7 has been transmitted.
Please enter the last Acknowledgement received. 8
27
EXPERIMENT-7
AIM: Write a program to implement Sliding window protocol for Selective repeat.
PROGRAM:
#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:
28
EXPERIMENT-8
AIM: Write a Program to implement Stop and Wait Protocol.
PROGRAM:
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
bool valid(char f[8])
{
int c=0;
for(int i=0;i<8;i++){
if(f[i]=='0' || f[i]=='1')
c++;
}
if(c==8)
return true;
else
return false;
}
int main()
{
int s;
int fcount1=0,fcount2=0,fcount3=0,fcount4=0;
printf("1:ERROR FREE CHANNEL\n2:FRAME WITH ERROR\n3:ACK IS LOST\n4:FRAME IS LOST\n");
printf("Enter the choice:");
scanf("%d",&s);
switch(s)
{
case 1:
for(int i=1;i<=4;i++){
char f[8];
printf("Enter the value of frame %d:",i);
scanf("%s",f);
printf("ack%d, frame %d is received\n",i,i);
fcount1++;
}
if(fcount1==4)
printf("\nAll frames received successfully");
break;
case 2:
for(int i=1;i<=4;i++){
int e=0;
while(e!=1){
char f[8];
29
printf("Enter the value of frame %d:",i);
scanf("%s",f);
if(valid(f)){
printf("ack%d, frame %d is received
\n",i,i);
e=1;
fcount2++;
}
else{
printf("Nack%d-frame %d is in error\n",i,i);
printf("re-enter the value of frame%d\n",i);
e=0;
}
}
}
if(fcount2==4)
printf("\nAll frames received successfully");
break;
case 3:
for(int i=1;i<=4;i++){
int e=0;
while(e!=1){
char f[8];
printf("Enter the value of frame %d:",i);
scanf("%s",f);
if(i<=3){
if(valid(f)){
printf("ack%d, frame %d is received\n",i,i);
e=1;
fcount3++;
}
else{
printf("Error in the received frame\n");
e=0;
}
}
else{
printf("Ack lost...\n");
printf("Re-enter the frame 4:");
scanf("%s",f);
printf("ack%d, frame %d is received\n",i,i);
fcount3++;
e=1;
}
}
}
30
if(fcount3==4)
printf("\nAll frames received successfully");
break;
case 4:
for(int i=1;i<=4;i++){
int e=0;
while(e!=1){
char f[8]={0};
printf("Enter the value of frame %d:",i);
scanf("%s",f);
if(strlen(f)<=1){
printf("Frame %d is missing\n",i);
printf("Re-Enter the Frame\n");
continue;
}
if(valid(f)){
printf("ack%d, frame %d is received\n",i,i);
e=1;
fcount4++;
}
else{
printf("Error in the received frame\n");
e=0;
}
}
}
if(fcount4==4)
printf("\nAll frames received successfully");
break;
default:
printf("Invalid Choice");
}
}
OUTPUT:
31
ack3, frame 3 is received
Enter the value of frame 4:11110000
ack4, frame 4 is received
All frames received successfully
32
EXPERIMENT-8
AIM: Write a program for congestion control using leaky bucket algorithm.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int rand_num(int a)
{
int rn=(rand()%10)%a;
return rn==0?1:rn;
}
int main()
{
int packet_sz[5],i,clk,b_size,o_rate,p_sz_rm=0,p_sz,p_time;
for(i=0;i<5;++i)
packet_sz[i]=rand_num(6)*10;
for(i=0;i<5;++i)
printf("packet[%d]:%d bytes\t",i,packet_sz[i]);
printf("\nEnter the Output rate:");
scanf("%d",&o_rate);
printf("Enter the Bucket Size:");
scanf("%d",&b_size);
for(i=0; i<5; ++i)
{
if((packet_sz[i]+p_sz_rm)>b_size)
{
if(packet_sz[i] > b_size)
printf("\n\nIncomming packet size (%d) is Greater than bucket capacity-PACKET REJECTED",packet_sz[i]);
}
else
{
p_sz_rm+=packet_sz[i];
printf("\n\nIncoming Packet size: %d",packet_sz[i]);
printf("\nBytes remaining to Transmit:%d",p_sz_rm);
p_time = rand_num(4)*10;
printf("\nTime left for transmission: %d units",p_time);
for(clk=10; clk<=p_time; clk+=10)
{
sleep(1);
if(p_sz_rm)
{
if(p_sz_rm <= o_rate)
{
printf("\n Packet of size %dTransmitted",p_sz_rm);
33
p_sz_rm=0;
}
else
{
p_sz_rm-=o_rate;
}
printf("\n Packet of size %d Transmitted",o_rate);
printf(" Bytes Remaining after Transmission: %d",p_sz_rm);
}
else
{
printf("\n No packets to transmit!!");
printf(" Time Left:%d",p_time-clk);
}
}
}
}
}
OUTPUT:
packet[0]:10 bytes packet[1]:10 bytes packet[2]:20 bytes packet[3]:10 bytes packet[4]:10
bytes
Enter the Output rate:20
Enter the Bucket Size:50
34
Bytes remaining to Transmit:10
Time left for transmission: 10 units
Packet of size 10Transmitted
Packet of size 20 Transmitted Bytes Remaining after Transmission: 0
35
EXPERIMENT-10
AIM: Write a Program to implement Dijkstra‘s algorithm to compute the Shortest path through a graph.
PROGRAM:
#include<stdio.h>
int main()
{
int n,AB,BC,CD,BE,EF,FH,AG,GH,HD,EG,P1,P2;
printf("Enter the number of nodes in subnet:");
scanf("%d",&n);
printf("Computation of shortest path connecting node A & node D is as follows\n");
printf("Enter the distance between Node A and Node B:");
scanf("%d",&AB);
printf("Enter the distance between Node B and Node C:");
scanf("%d",&BC);
printf("Enter the distance between Node C and Node D:");
scanf("%d",&CD);
printf("Enter the distance between Node B and Node E:");
scanf("%d",&BE);
printf("Enter the distance between Node E and Node F:");
scanf("%d",&EF);
printf("Enter the distance between Node F and Node H:");
scanf("%d",&FH);
printf("Enter the distance between Node A and Node G:");
scanf("%d",&AG);
printf("Enter the distance between Node G and Node H:");
scanf("%d",&GH);
printf("Enter the distance between Node H and Node D:");
scanf("%d",&HD);
printf("Enter the distance between Node E and Node G:");
scanf("%d",&EG);
printf("Computation of path from node A to node D is path P1 or path P2\n");
printf("Path P1:(A->B)+(B->E)+(E->G)+(G->H)+(H->D) \n");
P1=AB+BE+EG+GH+HD;
printf("Path P1= %d\n",P1);
printf("Path P2:(A->B)+(B->E)+(E->F)+(F->H)+(H->D) \n");
P2=AB+BE+EF+FH+HD;
printf("Path P2= %d\n",P2);
if(P1<P2)
printf("Path connecting node A and node D is P1=%d",P1);
else
printf("Path connecting node A and node D is P2=%d",P2);
return 0;
}
36
OUTPUT:
37
EXPERIMENT-11
AIM: Write a Program to implement Distance vector routing algorithm by obtaining routing table at each node
(Take an example subnet graph with weights indicating delay between nodes).
PROGRAM:
#include<stdio.h>
int main()
{
int n,P[4],JH,HG,JK,KG,JA,AG,JI,IG,value=P[1],index=1,i;
printf("Enter the number of nods in subnet:");
scanf("%d",&n);
printf("Computation of shortest path from node J to node G applying Distance Vector Routing Algorithm\n");
printf("Possible paths connecting node J & node G are P1/P2/P3/P4\n");
printf("Path P1: JH + HG\n");
printf("Enter the values of JH & HG:");
scanf("%d %d",&JH,&HG);
P[1]=JH+HG;
printf("Path P1= %d\n",P[1]);
printf("Path P2: JK + KG\n");
printf("Enter the values of JK & KG:");
scanf("%d %d",&JK,&KG);
P[2]=JK+KG;
printf("Path P2= %d\n",P[2]);
printf("Path P3: JA + AG\n");
printf("Enter the values of JA & AG:");
scanf("%d %d",&JA,&AG);
P[3]=JA+AG;
printf("Path P3= %d\n",P[3]);
printf("Path P4: JI + IG\n");
printf("Enter the values of JI & IG:");
scanf("%d %d",&JI,&IG);
P[4]=JI+IG;
printf("Path P4= %d\n",P[4]);
//SORTING
for(i=1;i<=4;i++){
if(P[i]<value){
value=P[i];
index=i;
}
}
printf("The shortest path connecting Node J & Node G is:P%d = %d",index,P[index]);
return 0;
}
OUTPUT:
38
Enter the number of nods in subnet:10
Computation of shortest path from node J to node G applying Distance Vector Routing Algorithm
Possible paths connecting node J & node G are P1/P2/P3/P4
Path P1: JH + HG
Enter the values of JH & HG:12 6
Path P1= 18
Path P2: JK + KG
Enter the values of JK & KG:7 4
Path P2= 11
Path P3: JA + AG
Enter the values of JA & AG:3 9
Path P3= 12
Path P4: JI + IG
Enter the values of JI & IG:2 5
Path P4= 7
The shortest path connecting Node J & Node G is:P1 = 18
39
EXPERIMENT-12
AIM: Write a Program to implement Broadcast tree by taking subnet of hosts.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void main()
{
unsigned int compad[4];
unsigned int mask[4];
unsigned int netadr[4];
int i;
clrscr();
printf("Enter the ip address:\n");
scanf("%u%*c%u%*c%u%*c%u%*c",&compad[3],&compad[2],&compad[1],&compad[0]);
printf("Enter the subnet address:\n");
scanf("%u%*c%u%*c%u%*c%u%*c",&mask[3],&mask[2],&mask[1],&mask[0]);
for(i=0;i<4;i++)
{
netadr[i]= compad[i]&mask[i];
}
printf("\nNetwork address is:\n");
printf("%u.%u.%u.%u",netadr[3],netadr[2],netadr[1],netadr[0]);
printf("\nsubnet address is:\n");
printf("%u.%u.%u.%u",mask[3],mask[2],mask[1],mask[0]);
printf("\nip address is:\n");
printf("%u.%u.%u.%u",compad[3],compad[2],compad[1],compad[0]);
getch();
}
OUTPUT:
40