You are on page 1of 37

1.

Study of Network devices in detail and


connect the computers in Local Area
Network.
Network Devices (Hub, Repeater, Bridge, Switch, Router,
Gateways and Brouter):
1. Repeater – A repeater operates at the physical layer. Its job is to regenerate
the signal over the same network before the signal becomes too weak or
corrupted so as to extend the length to which the signal can be transmitted over
the same network. An important point to be noted about repeaters is that they
do not amplify the signal. When the signal becomes weak, they copy the signal
bit by bit and regenerate it at the original strength. It is a 2 port device. 
2. Hub –  A hub is basically a multiport repeater. A hub connects multiple wires
coming from different branches, for example, the connector in star topology
which connects different stations. Hubs cannot filter data, so data packets are
sent to all connected devices.  In other words, the collision domain of all hosts
connected through Hub remains one.  Also, they do not have the intelligence to
find out the best path for data packets which leads to inefficiencies and
wastage. 
 
Types of Hub 
 Active Hub:- These are the hubs that have their own power supply and can
clean, boost, and relay the signal along with the network. It serves both as a
repeater as well as a wiring center. These are used to extend the maximum
distance between nodes.
 Passive Hub :- These are the hubs that collect wiring from nodes and power
supply from the active hub. These hubs relay signals onto the network
without cleaning and boosting them and can’t be used to extend the distance
between nodes.
 Intelligent Hub :- It works like active hubs and includes remote
management capabilities. They also provide flexible data rates to network
devices. It also enables an administrator to monitor the traffic passing
through the hub and to configure each port in the hub.
3. Bridge – A bridge operates at the data link layer. A bridge is a repeater, with
add on the functionality of filtering content by reading the MAC addresses of
source and destination. It is also used for interconnecting two LANs working on
the same protocol. It has a single input and single output port, thus making it a
2 port device.
Types of Bridges 
 Transparent Bridges:- These are the bridge in which the stations are
completely unaware of the bridge’s existence i.e. whether or not a bridge is
added or deleted from the network, reconfiguration of the stations is
unnecessary. These bridges make use of two processes i.e. bridge
forwarding and bridge learning.
 Source Routing Bridges:- In these bridges, routing operation is performed
by the source station and the frame specifies which route to follow. The host
can discover the frame by sending a special frame called the discovery
frame, which spreads through the entire network using all possible paths to
the destination.
4. Switch – A switch is a multiport bridge with a buffer and a design that can
boost its efficiency(a large number of ports imply less traffic) and performance.
A switch is a data link layer device. The switch can perform error checking
before forwarding data, which makes it very efficient as it does not forward
packets that have errors and forward good packets selectively to the correct
port only.  In other words, the switch divides the collision domain of hosts,
but broadcast domain remains the same. 
  
5. Routers – A router is a device like a switch that routes data packets based
on their IP addresses. The router is mainly a Network Layer device. Routers
normally connect LANs and WANs together and have a dynamically updating
routing table based on which they make decisions on routing the data packets.
Router divide broadcast domains of hosts connected through it.
 
  
 
6. Gateway – A gateway, as the name suggests, is a passage to connect two
networks together that may work upon different networking models. They
basically work as the messenger agents that take data from one system,
interpret it, and transfer it to another system. Gateways are also called protocol
converters and can operate at any network layer. Gateways are generally more
complex than switches or routers. Gateway is also called a protocol converter. 
7. Brouter – It is also known as the bridging router is a device that combines
features of both bridge and router. It can work either at the data link layer or a
network layer. Working as a router, it is capable of routing packets across
networks, and working as the bridge, it is capable of filtering local area network
traffic. 
8. NIC – NIC or network interface card is a network adapter that is used to
connect the computer to the network. It is installed in the computer to establish
a LAN.  It has a unique id that is written on the chip, and it has a connector to
connect the cable to it. The cable acts as an interface between the computer
and router or modem. NIC card is a layer 2 device which means that it works on
both physical and data link layer of the network model. 
   How to Set Up a LAN Network?
LAN (Local Area Network) is a data communication network that locally
connects network devices such as workstations, servers, routers, etc. to share
the resources within a small area such as a building or campus. Physical or
wireless connections are set up between workstations to share the resources.
Ethernet and Wi-fi are the most important technologies of LAN. Personal
networks at home, school, office, etc. are examples of LAN. These are
generally privately-owned networks.
Requirements to set up LAN Network:
 Workstation/Personal devices: laptop, computer, mobile phones, etc.
 Network devices: router, switch, modem (if not already present in the
router)
 Sharing resources: printers, disk drives, etc.
 Cables: Ethernet cables, wires for connecting other devices (in case of
wired LAN)
 Internet connection: Wi-Fi (in case of wireless LAN)
Instructions to set up LAN Network:
Following steps should be followed to set up a LAN network:
1. Identify services: Identify the network services such as printers, disk drives,
data, etc. that will be shared among workstations.
2. Identify devices: Identify devices such as computers, mobile phones,
laptops, etc. with a unique address that will be connected to the network.
3. Plan connections: Design the network by laying out cable wires between
network devices or by making wireless connections. Wired LAN is set up
using Ethernet cables while wireless LAN is set up using Wi-Fi that connects
network devices without making any physical connection. A wired LAN
network is more secure than a wireless LAN network but it is difficult to
relocate.
4. Select networking device: Select switch or router with enough ports to
connect all workstations within the network. The choice of networking device
is based on the requirements of the network.
5. Configure ports: Configure WAN ports according to the information
provided by ISP (Internet Service Provider). Also, configure LAN ports of
cable routers such that there are enough addresses available for all the
workstations within the network. A cable router acts as DHCP (Dynamic Host
Configuration Server) server that automatically allocates addresses to all the
devices connected to the network.
6. Make connections: Connect all the devices using wires to configure a LAN
network. Standard Ethernet cables are used to connect workstations and
servers while Ethernet crossover cable is used to connect the switch to cable
routers by connecting the standard port of the switch with router’s LAN port.
For wireless LAN, connect all the devices to Wi-Fi with SSID (Service Set
Identifier) provided by the router or switch to configure the LAN network.
7. Test the network: Test each of the workstation connected to the network
and ensure every workstation have access to network services.
Tips for LAN Set-Up:
1. Make a comprehensive plan about connections before making actual
connections to avoid confusion.
2. Carefully identify the requirements and size of the network and plan
accordingly.
3. Smartly choose the networking device which provides more flexibility to the
network.
4. Ensure the cable length is not more than 100 meters.
5. Avoid laying cables in air ducts unless fire rated.
6. Perform detailed testing after network set up to analyze the actual
performance of the network.
Applications of LAN:
1. Resource sharing: LAN network allows workstations connected to the
network to share resources such as printers, scanners, CD drives, etc. which
reduces the cost of the set up of the network.
2. Software sharing: LAN network allows to share a single copy of licensed
software among workstations connected to the network instead of
purchasing separate software for each computer.
3. Internet sharing: LAN network facilitates sharing of internet connection
among all the devices connected to the network.
4. Data sharing: LAN network allows different workstations to share the data
and files with each other. It also allows access to data stored on the central
server.
5. Communication: Devices connected to a LAN network can communicate
with each other.
Advantages of LAN:
1. It is an easy and cheap way of communication within a small geographical
location.
2. It is easy to expand the network by connecting workstations to a central
server.
3. It is easy to manage the resources and data from the central server.
4. It is more secure since data is stored on a central server which denies illegal
access to data.
5. It has high data transmission rates.
Disadvantages of LAN:
1. It has a high initial setup cost.
2. It violates the privacy of network users as administrators have access to all
their data and files.
3. It can face security issues if the central server is not properly secured.
4. It needs regular maintenance to deal with issues such as software
installations, hardware failures, cable disturbances, etc.
5. It restricts the size of the network.

2. Write a Program to implement the data


link layer farming methods such as i) bit
stuffing i i) Character stuffing .
1)Implement the datalink layer framing methods such as bit
stuffing and character stuffing.

1)a) PROGRAM SPECIFICATION:

Program to implement the stuffing.

ALGORITHM:

Step-1:start

Step-2:Read the bit string to be transmitted in o’s and1’s.

Step-3: for stuffing process,append at begin and end of the string.

Step-4: Check the string whether it has 5 consecutive 1’s except the
appending string.

Step-5:If yes,insert’0’ bit as stuff in the next bit,else transmit the next
bit.

Step-6:continue this process until the completion of the string.

Step-7:stuffed data is obtained.


Step-8:Now destuffing process,remove the appended string at start and
end of string.

Step-9:check the stuffed string again whether it has five consecutive


1’s.

Step-10:If yes then remove the next bit i.e.do not transmit the next bit
else transmit the data.

Step-11:continue this process until the last bit of string.

Step-12:original bit data has been obtained.

Step-13:stop.

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 size:”);

scanf(“%d”,&n);

printf(“enter the frame:”);

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 bit stuffing the frame is:”);

for(i=0;i<j;i++)

printf(“%d”,b[i]);

getch();

INPUT-1:

Enter frame size:8

Enter the frame:

1
1

OUTPUT-1:

After bit stuffing:111110111

INPUT-2:

Enter frame size:8

Enter the frame:

OUTPUT-2:

After bit stuffing:011111010


1)b)PROBLEM SPECIFICATION:

Program to implement character stuffing.

ALGORITHM:

Step-1:start.

Step-2:Read the character string to be transimmited in uppercase.

Step-3:For stuffing process,append at begin with ‘DLE STX’ as starting


flag byte and end with ‘DLE ETX’ as ending flag byte of the string.

Step-4:check the string whether it has ‘DLE’,’STX’ and ‘ETX’.

Step-5:If yes then insert the string ‘DLE’ before the character else
transmit the next character.

Step-6:continue the process until the completion of the string.

Step-7:stuffed data is obtained.

Step-8:now destuffing process,remove the appended string at start and


end of the string.

Step-9:check the stuffed string again whether it has ‘DLE’,’STX’


and’ETX’.

Step-10:if yes the remove the string ‘DLE’ that is encounterd first else
transmit the data.

Step-11:continue this process until the last character of the string.

Step-12:original data has been obtained.


Step-13:stop.

PROGRAM:

#include<stdio.h>

#include<conio.h>

#include<string.h>

Void main()

char a[30],b[4]=”dle”;

int i,j,count=0,n,p;

printf(“enter the frame to be send:”);

scanf(“%s”,a);

n=strlen(a);

printf(“length is %d\n”,n);

printf(“Frame after shifting\n”);

printf(“dle stx”);

for(i=0;i<n;i++)

count=0;

p=i;
for(j=0;j<3;j++)

count=0;

p=i;

for(j=0;j<3;j++)

if(a[i]==b[j])

count=count+1;

i++;

if(count!=3)

i=p;

}
if(count==3)

printf(“dledle”);

else

printf(“%c”,a[i]);

printf(“dleetx\n”);

printf(“frame received after receiving is:\n”);

printf(“%s”,a);

getch();

INPUT:

Enter the frame to be send:radle


OUTPUT:

length is 5

frame after shifting

dle stx radle dle dleetx

frame received after removing:radle

3. Write a Program to implement data link


layer farming method checksum.

8-digit sum check program in c language

Here you will get checksum program in C and C++.

Here, you will get a checksum program for C and C++.

A checksum is a error detection method in Data Communication. It is used for


errors which may have been introduced during transmission or storage. It is
usually applied to an installation file after it is received from the download
server.

Checksum is an error detection method in data communication. It is used for


errors that may be introduced during transmission or storage. After receiving
the installation file from the download server, it is usually applied to the
installation file.

The actual procedure which yields the checksum, given a data input is called
a checksum function or checksum algorithm.
Given data input, the actual process of generating a checksum is called a
checksum function or checksum algorithm.

Also Read: Hamming Code in C and C++

Also read: Hamming code in C and C++

Checksum method can only detect errors but is unable to correct the error.

The checksum method can only detect errors, but cannot correct them.

In this method a checksum is calculated based on the given binary strings


which is sent with the data as redundant bits. This data + checksum is
received at receiver end and checksum is calculated again, if checksum is 0 it
means no error in data received, else there exists some error in the received
data.

In this method, a checksum is calculated based on a given binary string,


which is sent as redundant bits along with the data. This data + checksum is
received at the receiver, and the checksum is calculated again. If the
checksum is 0, it means that the received data has no errors, otherwise there
are some errors in the received data.

For the purpose of this program we are finding checksum for 2 binary strings.

For this program, we found the checksum of 2 binary strings.

Checksum Algorithm (Checksum Algorithm)

 Take 2 binary input strings. Take 2 binary input strings.


 Do their binary sum to find out the checksum which will be sent to the
destination or to the receiver. Sum their binary sum to find the
checksum that will be sent to the destination or recipient.
 In binary sum there are 6 cases:-

Use binary sum to represent 6 situations:

 If both bits are 0 and carry is 0, sum=0 and carry=0 If both bits are
0 and the carry is 0, then sum = 0 and carry = 0
 If both bits are 0 and carry is 1,sum=1 and carry=0 If both bits are
0 and carry is 1, sum = 1 and carry = 0
 If both bits are 1 and carry is 0,sum=0 and carry=1 If both bits are
1 and the carry is 0, then sum = 0 and carry = 1
 If both bits are 1 and carry is 1,sum=1 and carry=1 If both bits are
1 and the carry is 1, sum = 1 and carry = 1
 If either bit is 1 and carry is 0,sum=1 and carry=0 If any bit is 1
and carry is 0, sum = 1 and carry = 0
 If either bit is 1 and carry is 1,sum=0 and carry=1 If any bit is 1
and carry is 1, sum = 0 and carry = 1
 While doing the addition we have to add the binary strings from
rightmost end i.e LSB to MSB. When adding, we must add a binary
string from the rightmost end (that is, LSB) to the MSB.
 When binary sum is done 1's complement of it is taken by reversing 1's
to 0's and vice versa. When the binary sum is completed, by inverting 1
to 0, and vice versa, one's complement can be obtained.
 The resulting 1's complement is the Checksum. The resulting 1's
complement is the checksum.
 Stop. stop.
C language checksum program (Checksum Program in C)

#include<stdio.h>

#include<string.h>

 int main()

    char a[20],b[20];

    char sum[20],complement[20];

    int i,length;

    

printf("Enter first binary string\n");

    scanf("%s",&a);

    printf("Enter second binary string\n");

    scanf("%s",&b);

    

    if(strlen(a)==strlen(b)){
length = strlen(a);

char carry='0';

        

for(i=length-1;i>=0;i--)

        {

if(a[i]=='0' && b[i]=='0' && carry=='0')

            {

                sum[i]='0';

                carry='0';

            }

            else if(a[i]=='0' && b[i]=='0' && carry=='1')

            {

                sum[i]='1';
                carry='0';

            }

            else if(a[i]=='0' && b[i]=='1' && carry=='0')

            {

                sum[i]='1';

                carry='0';

            }

            else if(a[i]=='0' && b[i]=='1' && carry=='1')

            {

                sum[i]='0';
                carry='1';

            }

            else if(a[i]=='1' && b[i]=='0' && carry=='0')

            {

                sum[i]='1';

                carry='0';

            }

            else if(a[i]=='1' && b[i]=='0' && carry=='1')

            {

                sum[i]='0';
                carry='1';

            }

            else if(a[i]=='1' && b[i]=='1' && carry=='0')

            {

                sum[i]='0';

                carry='1';

            }

            else if(a[i]=='1' && b[i]=='1' && carry=='1')

            {

                sum[i]='1';
                carry='1';

            }

            else

                break;

        }

        

printf("\nSum=%c%s",carry,sum);

for(i=0;i<length;i++)

        {

            if(sum[i]=='0')

                complement[i]='1';
            else

                complement[i]='0';

        }

        

        if(carry=='1')

            carry='0';

        else

            carry='1';

        

printf("\nChecksum=%c%s",carry,complement);

else {

printf("\nWrong input strings");

}
}

Output:
Enter first binary string

10101

Enter second binary string

11001

Sum=101110

Checksum=010001

4.write a program for hamming code generation


for error detection and correction.

Algorithm:

 Initialize r by 1 and increment it by 1 until 2r is smaller


than m+r+1.
 Initialize a vector hammingCode of size r + m which will be
the length of the output message.
 Initialize all the positions of redundant bits with -1 by
traversing from i = 0 to r – 1 and
setting hammingCode [2i – 1] = -1. Then place the input
message bits in all the positions where hammingCode[j] is
not -1 in order where 0 <= j < (r + m).
 Initialize a variable one_count with 0 to store the number of
ones and then traverse from i = 0 to (r + m – 1).
 If the current bit i.e., hammingCode[i] is not -1 then find the
message bit containing set bit at log2(i+1)th position by
traversing from j = i+2 to r+m by
incrementing one_count by 1 if (j & (1<<x)) is
not 0 and hammingCode[j – 1] is 1.
 If for index i, one_count is even, set hammingCode[i] =
0 otherwise set hammingCode[i] = 1.
 After traversing, print the hammingCode[] vector as the
output message.
Program:
// C program for the above approach

#include <math.h>
#include <stdio.h>

// Store input bits


int input[32];

// Store hamming code


int code[32];

int ham_calc(int, int);


void solve(int input[], int);

// Function to calculate bit for


// ith position
int ham_calc(int position, int c_l)
{
int count = 0, i, j;
i = position - 1;

// Traverse to store Hamming Code


while (i < c_l) {

for (j = i; j < i + position; j++) {

// If current boit is 1
if (code[j] == 1)
count++;
}

// Update i
i = i + 2 * position;
}

if (count % 2 == 0)
return 0;
else
return 1;
}
// Function to calculate hamming code
void solve(int input[], int n)
{
int i, p_n = 0, c_l, j, k;
i = 0;

// Find msg bits having set bit


// at x'th position of number
while (n > (int)pow(2, i) - (i + 1)) {
p_n++;
i++;
}

c_l = p_n + n;

j = k = 0;

// Traverse the msgBits


for (i = 0; i < c_l; i++) {

// Update the code


if (i == ((int)pow(2, k) - 1)) {
code[i] = 0;
k++;
}

// Update the code[i] to the


// input character at index j
else {
code[i] = input[j];
j++;
}
}

// Traverse and update the


// hamming code
for (i = 0; i < p_n; i++) {

// Find current position


int position = (int)pow(2, i);

// Find value at current position


int value = ham_calc(position, c_l);

// Update the code


code[position - 1] = value;
}

// Print the Hamming Code


printf("\nThe generated Code Word is: ");
for (i = 0; i < c_l; i++) {
printf("%d", code[i]);
}
}

// 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:
The generated Code Word is: 0001111
Computer Network,

5.Write a program to implement on a data set of characters


the three CRC polynomials – CRC 12, CRC 16 and CRC CCIP.
Introduction to Cyclic Redundancy Check:
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 that is 0.5. so the probability of a bad block being expected when it should not be
2 power(-n). This scheme sometimes is known as Cyclic Redundancy Code.

Program Algorithm/Flowchart:
Begin
Step 1:Declare I, j , fr[8], dupfr[11], recfr[11], tlen, flag,
gen[4], genl, frl, rem[4] as integer
Step 2: initialize frl=8 and genl=4
Step 3: initialize i=0
Step 4: Repeat step(5to7) until i<frl
Step 5: read fr[i]
Step 6: dupfr[i]=fr[i]
Step 7: increment i
Step 8: initialize i=0
Step 9: repeat step(10to11) until i<genl
Step 10: read gen[i]
Step 11: increment i
Step 12: tlen=frl+genl-1
Step 13: initialize i=frl
Step 14: Repeat step(15to16) until i<tlen
Step 15: dupfr[i]=0
Step 16: increment i
Step 17: call the function remainder(dupfr)
Step 18: initialize i=0
Step 19: repeat step(20 to 21) until j<genl
Step 20: recfr[i]=rem[j]
Step 21: increment I and j
Step 22: call the function remainder(dupfr)
Step 23: initialize flag=0 and i=0
Step 24: Repeat step(25to28) until i<4
Step 25: if rem[i]!=0 then
Step 26: increment flag
Step 27: end if
Step 28: increment i
Step 29: if flag=0 then
Step 25: print frame received correctly
Step 25: else
Step 25: print the received frame is wrong
End
Function: Remainder(int fr[])
Begin
Step 1: Declare k,k1,I,j as integer
Step 2: initialize k=0;
Step 3: repeat step(4 to 14) until k<frl
Step 4: if ((fr[k] == 1) then
Step 5: k1=k
Step 6: initialize i=0, j=k
Step 7: repeat step(8 to 9) until i<genl
Step 8: rem[i] =fr[j] exponential gen[i]
Step 9: increment I and j
Step 10: initialize I = 0
Step 11: repeat step(12to13) until I <genl
Step 12: fr[k1] = rem[i]
Step 13: increment k1 and i
Step 14: end if
End

Program Code: // Program for Cyclic Redundency


Check
#include<stdio.h>
int gen[4],genl,frl,rem[4];
void main()
{
int i,j,fr[8],dupfr[11],recfr[11],tlen,flag;
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;
}
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");
}
}
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++;
}
}
}
}

Program Output:
Enter frame: MLRITM
Enter generator: frame received correctly
------------------
(program exited with code: 24)
Press return to continue

6.Write a program to implement Sliding window protocol for


Goback N.
#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

Enter window size: 3

Enter number of frames to transmit: 5


Enter 5 frames: 12 5 89 4 6

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

You might also like