0% found this document useful (0 votes)
20 views19 pages

CNL Exp 1-4

Computer Networks Lab Experiments
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views19 pages

CNL Exp 1-4

Computer Networks Lab Experiments
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

STUDY OF NETWORK DEVICES

1. AIM: To study the following network devices in detail.

 Repeater
 Hub
 Switch
 Bridge
 Router
 Gate Way

APPARATUS: No Software needed


PROCEDURE:
Following should be done to understand this practical.

1. Repeater: Functioning at Physical Layer. A repeater is an


electronic device that receives a signal and retransmits it at a higher
level and/or higher power, or onto the other side of an obstruction, so
that the signal can cover longer distances. Repeater have two ports,
so cannot be used to connect for more than two devices

2. Hub: A hub is a device that links multiple computers and devices


together. Hubs can also be referred to as repeaters or concentrators,
and they serve as the center of a local area network (LAN). In a hub,
each connected device is on the same subnet and receives all data sent
to the hub. 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.

VFSTR (Deemed to be University) 1


3. Switch: The Switch is a network device that is used to segment the
networks into different subnetworks called subnets or LAN segments.
It is responsible for filtering and forwarding the packets between LAN
segments based on MAC address.

Switches have many ports, and when data arrives at any port, the
destination address is examined first and some checks are also done
and then it is processed to the devices. Different types of
communication are supported here like unicast, multicast, and
broadcast communication.

4. Bridge: A network bridge is a computer networking device that


creates a single, aggregate network from multiple communication
networks or network segments. This function is called network
bridging. Bridging is distinct from routing. Routing allows multiple
networks to communicate independently and yet remain separate,
whereas bridging connects two separate networks as if they were a
single network. In the OSI model, bridging is performed in the data link
layer (layer 2). If one or more segments of the bridged network are
wireless, the device is known as a wireless bridge.

5. 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

VFSTR (Deemed to be University) 2


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.

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.

RESULT:

VFSTR (Deemed to be University) 3


GENERATION OF IP ADDRESS, PROTOCOL HEADER, AND
FRAMES

2. AIM: To generate IP address, Protocol header and frames using C language.


APPARATUS: PC with Windows OS & C-Language
THEORY:
An IP address is the unique numerical address of a device in a
computer network that uses Internet Protocol for communication. The IP
address allow you to pinpoint a particular device from the billions of devices
on the Internet. To send you a letter, someone needs your mailing address. In
the same sense, one computer needs the IP address of another computer to
communicate with it. An IP address consists of four numbers; each can
contain one to three digits. These numbers are separated with a single dot (.).
These four numbers can range from 0 to 255.

A frame is a digital data transmission unit in computer networking


and telecommunication. In packet switched systems, a frame is a simple
container for a single network packet. In other telecommunications systems,
a frame is a repeating structure supporting time-division multiplexing.

A frame typically includes frame synchronization features consisting of


a sequence of bits or symbols that indicate to the receiver the beginning and
end of the payload data within the stream of symbols or bits it receives. If a
receiver is connected to the system during frame transmission, it ignores the
data until it detects a new frame synchronization sequence. In the OSI model
of computer networking, a frame is the protocol data unit at the data link
layer. Frames are the result of the final layer of encapsulation before the data
is transmitted over the physical layer.[1] A frame is "the unit of transmission
in a link layer protocol, and consists of a link layer header followed by a
packet."[2] Each frame is separated from the next by an interframe gap. A frame
is a series of bits generally composed of frame synchronization bits, the
packet payload, and a frame check sequence. Examples are Ethernet

VFSTR (Deemed to be University) 4


frames, Point-to-Point Protocol (PPP) frames, Fiber Channel frames,
and V.42 modem frames.

PROCEDURE:

PROGRAM:

A) To generate IP address

#include<stdlib.h>
int main()
{
system("C:\\Windows\\System32\\ipconfig");
return 0;
}

OUTPUT:

VFSTR (Deemed to be University) 5


B) To generate protocol header

#include<stdio.h>
#include<conio.h>
int main()
{
FILE *input,*out;
int c, counter=0;
//Source Add
char source[]="192.168.1.1";
//Destination Add
char dest[]="192.168.1.20";
input= fopen("input.txt","r");
out=fopen("output.txt","w");
if(input==NULL)

{ printf("Input File Not


found");
}
else if(out==NULL)

{ printf("Output file notcreated");


}
Else
{
//Counting No of character in files
do{
c=getc(input);
//getc() function is used
to read a single character
from the given file
stream.
counter++;

VFSTR (Deemed to be University) 6


}
while(c!=EOF);
counter= counter-1;
//Generatting Headers fprintf(out,"%s,%s,
%d",source,dest,counter);
printf("Header generated Successfully.\nCheck output.txt file.");
fclose(input);

fclose(out);
return 0;
}
}

INPUT:

OUTPUT:

VFSTR (Deemed to be University) 7


C) To generate frames

#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp1, *fp2, *fopen();
int i;
char c,cnt=49;
fp1 = fopen("input.txt","r");
// open for reading
fp2 = fopen("output.txt","w") ;
//open for writing
if ( fp1 == NULL )
{
printf("Cannot open input.txt." );
exit(1);
}
else if ( fp2 == NULL )
{
printf("Cannot open output.txt.");
exit(1);
}
else
{
c = getc(fp1) ;
while ( c != EOF)
{
putc(cnt++,fp2); # display on standard output or
write into a file (putc).

VFSTR (Deemed to be University) 8


fputs(",192.168.1.1,192.168.1.2,",fp2);

#This fputs() in C is used for writing the string or


the array of characters in a file.
//Logic to track 5 characters
for(i=0;i<5;i++)
{
putc( c, fp2); //Write to Output.txt
c = getc( fp1 ) ;
//putc(10,fp2); #getc() functions are file handling function in C
programming language which is used to read a character from a file
(getc)
}
putc(10,fp2);
}
printf("Frames generated in Output.txt file.");
fclose(fp1); //close files
fclose(fp2);
}
return 0;
}

INPUT:

OUTPUT:

RESULT:

VFSTR (Deemed to be University) 9


DATA LINK FRAMING METHODS – CHARACTER COUNT, BIT
STUFFING AND DESTUFFING
3. AIM: To implement Data link framing methods – Character Count, Bit
stuffing and Destuffing using C language.
APPARATUS: PC with Windows OS & C-Language
THEORY:
Framing is a point-to-point connection between two computers or
devices consists of a wire in which data is transmitted as a stream of bits.
However, these bits must be framed into discernible blocks of information.
Framing is a function of the data link layer. It provides a way for a sender to
transmit a set of bits that are meaningful to the receiver. Ethernet, token ring,
frame relay, and other data link layer technologies have their own frame
structures. Frames have headers that contain information such as error-
checking codes.
There are two types of framing:

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.

2. Variable size – In this there is need to define end of frame as well as


beginning of next frame to distinguish. This can be done in two ways:

 Length field – We can introduce a length field in the frame to


indicate the length of the frame. Used in Ethernet (802.3). The
problem with this is that sometimes the length field might get
corrupted.
 End Delimiter (ED) – We can introduce an ED (pattern) to indicate
the end of the frame. Used in Token Ring. The problem with this is
that ED can occur in the data.
This can be solved by:

Character/Byte Stuffing: Used when frames consist of character. If data


contains ED then, byte is stuffed into data to diffentiate it from ED.

VFSTR (Deemed to be University) 10


Bit Stuffing: Let ED = 01111 and if data = 01111
–> Sender stuffs a bit to break the pattern i.e. here appends a 0 in data =
011101.
–> Receiver receives the frame.
–> If data contains 011101, receiver removes the 0 and reads the data.

VFSTR (Deemed to be University) 11


PROCEDURE:

PROGRAM:
CHARACTER COUNT

#include <stdio.h>
#include <string.h>
int main()
{
char str[50];
int i=0, chr=0;
printf("\nEnter Your String: ");
gets(str);
// The gets() function enables
the user to enter some
characters followed by the enter
key.

while (str[i] != '\0')


{
if (str[i] == ' ')
{
chr++;
}
else
chr++;
i++;
}
printf("\nNumber of characters: %d", chr);
}

OUTPUT:

VFSTR (Deemed to be University) 12


BIT STUFFING AND DESTUFFING
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100

int main()
{
char *p,*q;
char in[MAXSIZE];
char stuff[MAXSIZE];
char destuff[MAXSIZE];

int count=0;
printf("Enter the input character string (0 & 1 only):\n");
scanf("%s",in);

p=in;
q=stuff;

while(*p!='\0')
{
if(*p=='0')
{
*q=*p;
q++;
p++;
}
else
{
while(*p=='1' && count!=3)
{
count++;
*q=*p;
q++;
p++;
}

if(count==3)
{
*q='0';

VFSTR (Deemed to be University) 13


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!=3)
{
count++;
*q=*p;
q++;
p++;
}
if(count==3)
{
p++;
}
count=0;
}
}
*q='\0';
printf("\nThe destuffed character string is:"); printf("\n%s\
n",destuff);
return 0;
}

VFSTR (Deemed to be University) 14


OUTPUT:

VFSTR (Deemed to be University) 15


CLASSIFICATION OF IP ADDRESSES
4. AIM: To implement and find Classes of IP Address using C language.
APPARATUS: PC with Windows OS & C-Language
THEORY:
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.

The system of IP address classes was developed for the purpose of


Internet IP addresses assignment. The classes created were based on the
network size. For example, for the small number of networks with a very
large number of hosts, the Class A was created. The Class C was created for
numerous networks with small number of hosts.

Classes of IP addresses are:

For the IP addresses from Class A, the first 8 bits (the first decimal
number) represent the network part, while the remaining 24 bits represent the
host part. For Class B, the first 16 bits (the first two numbers) represent the
network part, while the remaining 16 bits represent the host part. For Class
C, the first 24 bits represent the network part, while the remaining 8 bits
represent the host part.

VFSTR (Deemed to be University) 16


For Example: the following IP addresses:

 10.50.120.7 – because this is a Class A address, the first number (10)


represents the network part, while the remainder of the address represents
the host part (50.120.7). This means that, in order for devices to be on the
same network, the first number of their IP addresses has to be the same
for both devices. In this case, a device with the IP address of 10.47.8.4 is
on the same network as the device with the IP address listed above. The
device with the IP address 11.5.4.3 is not on the same network, because
the first number of its IP address is different.
 172.16.55.13 – because this is a Class B address, the first two numbers
(172.16) represent the network part, while the remainder of the address
represents the host part (55.13). A device with the IP address of
172.16.254.3 is on the same network, while a device with the IP address
of 172.55.54.74 isn’t.

PROGRAM:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int i=0;
int ip=0;
char str[100];
printf("Enter IP Address (xxx.xxx.xxx.xxx): ");
gets(str);
while(str[i]!='.')
{ // The atoi() function converts a character string to an integer value
ip=atoi(str);
i++ ;
}
if(ip>=1 && ip<=127)
{
printf("class is A ");

VFSTR (Deemed to be University) 17


}
if(ip>=128 && ip<=191)
{
printf("class is B ");
}
if(ip>=192 && ip<=223)
{
printf("class is C ");
}
if(ip>=224 && ip<=239)
{
printf("class is D ");
}
if(ip>=240 && ip<=254)
{
printf("class is E ");
}
return 0;
}

OUTPUT:

VFSTR (Deemed to be University) 18


VFSTR (Deemed to be University) 19

You might also like