Vous êtes sur la page 1sur 22

INDEX

Serial Date Name of Experiment Remarks


No.
Experiment-1
Aim of the Experiment: To study about different physical components used in networking.

Networking: Networking refers to the total process of creating and using computer networks, with
respect to hardware, protocols and software, including wired and wireless technology.

Communication: The process through which two or more nodes exchange data by using a medium.

Types of network:
The different networks based on size are:

 Personal area network, or PAN


 Local area network, or LAN
 Metropolitan area network, or MAN
 Wide area network, or WAN

Components of Computer Network:


The different components of computer network are:
Servers - Servers are computers that hold shared files, programs, and the network operating system.
Servers provide access to network resources to all the users of the network. There are many different
kinds of servers, and one server can provide several functions.
Clients - Clients are computers that access and use the network and shared network resources. Client
computers are basically the customers(users) of the network, as they request and receive services from the
servers.
Transmission Media - Transmission media are the facilities used to interconnect computers in a
network, such as twisted-pair wire, coaxial cable, and optical fiber cable. Transmission media are
sometimes called channels, links or lines.
Shared data - Shared data are data that file servers provide to clients such as data files, printer access
programs and e-mail.
Types of Communication:
1. Point to Point communication: A direct communication is established between the two communicating
computers.
2. Bus Topology: There is a main cable to which all of the computers are connected. Here, the data flows
in a single direction. It is cost effective and used in small networks. The whole network goes down if the
main cable fails.
3. Ring Topology: The computers are connected in a ring structure. It is easy to install and reconfigure.
4. Star Topology: All the computer are connected to a central hub/switch. Here, the whole network goes
down if the hub fails. It is less expensive and robust.
5. Mesh Topology: In this topology, all the computers are interconnected with each other. So, there are
n*(n-1)/2 bus needed. It is highly private and has secure connection. More no of cabling and I/O ports are
required.
6. Hybrid Topology: Combination of two or more types of topology is called Hybrid Topology.
Physical Equipments:
NIC: A network interface card (NIC) is a circuit board or card that is installed in a computer so that it can
be connected to a network. A network interface card provides the computer with a dedicated, full-time
connection to a network
Router: Routers are devices on the network which is responsible for forwarding data from one device to
another. This data is sent in packets (basic units of information) from one device to another. The router
reads the network information on the packets in order to determine the destination it should be routed to.
It acts an intermediate node between source and destination.
Hub: Hub is a device that splits a network connection into multiple computers. It is like a distribution
center. When a computer requests information from a network or a specific computer, it sends the request
to the hub through a cable. The hub will receive the request and transmit it to the entire network. Each
computer in the network should then figure out whether the broadcast data is for them or not.
Switch: A switch is a networking device that connects devices on the network allowing for data to be
transferred within the network
Firewall: Firewall is a logical component that prohibits unauthorised access to one’s computer. It acts as
a wall between external world and our Personal Computer.
Socket: A socket is a logical endpoint between two computers through which communication can take
place.
Port: A port is an endpoint of communication. Different port numbers are used to provide different types
of services. The range of port numbers is from 0-65535 out of which 0-1023 are assigned with some
existing service.

Submitted By:
Priyabrata Mohapatra
Roll No: 1602040017
Computer Science and Engineering
Experiment-2
Aim of the Experiment: Program to connect 2 PC’s using peer to peer communication.
Program:
Server Side-
import socket
import sys
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind(('localhost',8080))
active=True
while active:
data,addr=sock.recvfrom(1024)
data=str(data)
if data=='quit':
sock.close()
else:
print(“received:%s”%data)
d=raw_input("->")
sock.sendto(d,addr)
sock.close()

Client Side-
import socket
import sys
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
print("enter quit to exit")
c=str(raw_input("->"))
while c!='quit':
sock.sendto(c,('localhost',8080))
data,server=sock.recvfrom(1024)
print("received:%s"%data)
c=str(raw_input('->'))
sock.sendto(c,('localhost',5555))
sock.close()

Output-
Server Side
hey
->hi
how are you
->fine
Client Side
->hey
hi
->how are you
fine

Conclusion: Hence, we connected two computers using peer to peer connection.

Submitted By:
Priyabrata Mohapatra
Roll No: 1602040017
Computer Science and Engineering
Experiment-3
Aim of the Experiment: Program to implement Stop and Wait protocol
Algorithm:
Step 1: Start the program.
Step 2: Generate a random that gives the total number of frames to be transmitted.
Step 3: Transmit the first frame.
Step 4: Receive the acknowledgement for the first frame.
Step 5: Transmit the next frame
Step 6: Find the remaining frames to be sent.
Step 7: If an acknowledgement is not received for a particular frame retransmit that frame
alone again.
Step 8: Repeat the steps 5 to 7 till the number of remaining frames to be send becomes zero.
Step 9: Stop the program.
Program:
Server side:
import socket
import sys
import time
j=1
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind(('localhost',8080))
active=True
while active:
data,addr=sock.recvfrom(1024)
time.sleep(10)
data=str(data)
if data=='quit':
sock.close()
elif data=="":
d="no data received"
else :
print(data+" id= %d"%j)
#c=str(input('->'))
j=j+1
d="ack"
sock.sendto(d,addr)
sock.close()

Client side:
import socket
import sys
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
i=1
print("enter quit to exit")
c=str(input("->"))
while c!='quit':
sock.sendto(c,('localhost',8080))
data,server=sock.recvfrom(1024)
#print("%s"%data)
if(data=="ack"):
print("Acknowledgement %d received. Now you can send"%i)
i=i+1
elif(data==""):
print(data)
c=str(input('->'))
sock.sendto(c,('localhost',5555))
sock.close()

Output-
Server Side
hey
how are you
Client Side
->hey
Acknowledgement 1 received. Now you can send.
->how are you
Acknowledgement 2 received. Now you can send.

Conclusion: Stop and Wait protocol is implemented successfully.

Submitted By:
Priyabrata Mohapatra
Roll No: 1602040017
Computer Science and Engineering
Experiment-4
Aim of the Experiment: Program to implement leaky Bucket algorithm.
Algorithm:
1. Initialize a counter to n at the tick of the clock.
2. If n is greater than the size of the packet, send the packet and decrement the counter by the packet
size. Repeat this step until n is smaller than the packet size.
3. Reset the counter and go to step 1.

Program:
storage=0
no_of_queries=4
bucket_size=10
input_pkt_size=4
output_pkt_size=1
for i in range(0,no_of_queries):
size_left=bucket_size-storage

if(input_pkt_size<=(size_left)):

storage+=input_pkt_size
print(“Buffer size=%d out of bucket size%d”%storage,%bucket_size)

else:

k=input_pkt_size-(size_left)
print(“Packet loss=%d”%k)
storage=bucket_size
print(“Buffer size=%d out of bucket size%d”%storage,%bucket_size)

storage-=output_pkt_size

Output

Buffer size= 4 out of bucket size= 10


Buffer size= 7 out of bucket size= 10
Buffer size= 10 out of bucket size= 10
Packet loss = 3
Buffer size= 10 out of bucket size= 10

Conclusion: Leaky bucket algorithm is implemented successfully.

Submitted By:
Priyabrata Mohapatra
Roll No : 1602040017
Computer Science and Engineering
Experiment-5
Aim of the Experiment: Program to implement token bucket algorithm.
Algorithm:

 A token is added to the bucket every 1/r seconds.


 The bucket can hold at the most b tokens. If a token arrives when the bucket is full, it is discarded.
 When a packet (network layer PDU) of n bytes arrives,
 if at least n tokens are in the bucket, n tokens are removed from the bucket, and the packet is sent
to the network.
 if fewer than n tokens are available, no tokens are removed from the bucket, and the packet is
considered to be non-conformant.
Experiment-6
Aim of the Experiment: Program to implement hamming code.
Algorithm:
1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).
2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).
3. All the other bit positions are marked as data bits.
4. Each data bit is included in a unique set of parity bits, as determined its bit position in binary form.
a. Parity bit 1 covers all the bits positions whose binary representation includes a 1 in the least
significant
position (1, 3, 5, 7, 9, 11, etc).
b. Parity bit 2 covers all the bits positions whose binary representation includes a 1 in the second
position from
the least significant bit (2, 3, 6, 7, 10, 11, etc).
c. Parity bit 4 covers all the bits positions whose binary representation includes a 1 in the third
position from
the least significant bit (4–7, 12–15, 20–23, etc).
d. Parity bit 8 covers all the bits positions whose binary representation includes a 1 in the fourth
position from
the least significant bit bits (8–15, 24–31, 40–47, etc).
e. In general each parity bit covers all bits where the bitwise AND of the parity position and the bit
position is
non-zero.

Program:
#include<bits/stdc++.h>
using namespace std;
int data[100];
int m,r=0,f=1,s;
string st;
int main()
{
cout<<"Enter no of bits:";
cin>>m;
for(int i=1;i<100;i++)
data[i]=-1;
while(1)
{
data[f]=0;
s=m+r+1;
if(f>=s)
break;
f=f*2;
r++;
}
int n=m+r;
cout<<"Enter data:\n";
cin>>st;
int j=0;
for(int i=1;i<=n;i++)
{
if(data[i]==-1)
{
data[i]=int(st[j]-'0');
j++;
}
}
f=1;
for(int i=1;i<=r;i++)
{
for(int j=f;j<=n;j=j+f)
{
for(int k=0;k<f;k++)
{
data[f]^=data[j];
j++;
}
}
f=f*2;
}
cout<<"data to be sent :\n";
for(int i=1;i<=n;i++)
cout<<data[i];
}
Output
Enter no of bits:9
Enter data:
100100110
hamming code to be sent :
1110001000110

Conclusion: Hamming code is implemented successfully.

Submitted By:
Priyabrata Mohapatra
Roll No : 1602040017
Computer Science and Engineering
Signature:
Experiment-7
Aim of the Experiment: Program to implement Dijkstra’s algorithm.
Algorithm: -
Step 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.
Step 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.
Step 3: While sptSet doesn’t include all vertices,
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.
PROGRAM: -
#include<stdio.h>
#define INFINITY 9999
#define MAX 10
void dijkstra(int G[MAX][MAX],int n,int startnode);
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;
}
void dijkstra(int G[MAX][MAX],int n,int startnode)
{ int cost[MAX][MAX],distance[MAX],pred[MAX];
int visited[MAX],count,mindistance,nextnode,i,j;
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];
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;
for(i=0;i<n;i++)
if(distance[i]<mindistance&&!visited[i])
{ mindistance=distance[i];
nextnode=i;
}
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++;
}
for(i=0;i<n;i++)
if(i!=startnode)
{ 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:-
Enter no. of vertices: 5
Enter the adjacency matrix:
10231
00111
21200
10100
11111
Enter the starting node:2
Distance of node0=2
Path=0<-2
Distance of node1=1
Path=1<-2
Distance of node3=2
Path=3<-1<-2
Distance of node4=2
Path=4<-1<-2

Conclusion: Dijisktra’s algorithm is implemented successfully.

Submitted By:
Priyabrata Mohapatra
Roll No : 1602040017
Computer Science and Engineering
Signature:
Experiment-8
Aim of the Experiment: Program to implement bit stuffing and destuffing.
Algorithm:

1. Start
2. Initialize the array for transmitted stream with the special bit pattern 0111 1110
which indicates the beginning of the frame.
3. Get the bit stream to be transmitted in to the array.
4. Check for five consecutive ones and if they occur, stuff a bit 0
5. Display the data transmitted as it appears on the data line after appending 0111 1110
at the end
6. For de−stuffing, copy the transmitted data to another array after detecting the stuffed
bits
7. Display the received bit stream
8. Stop
Program:
#include<iostream>
#include<string.h>
using namespace std;
char str[100],str2[100];
main()
{
int i,j=0,l,k=0,t=0,z=0;
cout<<"Enter the data frame\n";
cin>>str;
//int l=str.length();
l=strlen(str);
for(i=0;i<l;i++)
{
if(str[i]=='0'&&str[i+1]=='1'&&str[i+2]=='1'&&str[i+3]=='1'&&str[i+4]=='1'&&str[i+5]=='1')
{
for(int k=0;k<6;k++)
{
str2[j]=str[i];
i++;
j++;
}
str2[j]='0';j++;i--;
}
else
{
str2[j]=str[i];
j++;
}

}
z=strlen(str2);
cout<<”Data to be sent is:\n"
for(i=0;i<z;i++)
cout<<str2[i];
}
Output:
Enter the data frame
1011111011111
Data to be sent is:
101111100111110
Bit Destuffing:
Program:
#include<bits/stdc++.h>
using namespace std;
main()
{
string res(50,' '),s;
int z=0,o=0,l=0,k=0;
cout<<"enter the data received:";
cin>>s;
l=s.length();
for(int i=0;i<l;i++)
{
if(s[i]=='0')
{
o=0;
z=1;
}
else
o++;
res[k]=s[i];
k++;
if(z==1 && o==5)
{
i++;
z=0;
o=0;
}
}
cout<<res;
}
Output:
enter the data received:01111101111110
0111111111110
Conclusion: Bit stuffing and destuffing is implemented successfully.

Submitted By:
Priyabrata Mohapatra
Roll No : 1602040017
Computer Science and Engineering
Signature:
Experiment-9
Aim of the Experiment: Program to implement character stuffing and destuffing.
Program:
#include<bits/stdc++.h>
using namespace std;
main()
{
string res(100,' '),s;
int l=0,k=0;
cout<<"enter the data to be sent:";
cin>>s;
l=s.length();
for(int i=1;i<7;i++)
res[i]='1';
res[0]='0';
res[7]='0';
k=8;
for(int i=0;i<l;i++)
{
if(s[i]=='0' && s[i+1]=='1' && s[i+2]=='1' && s[i+3]=='1' && s[i+4]=='1' && s[i+5]=='1' &&
s[i+6]=='1' && s[i+7]=='0')
{
res[k]='0';
k++;
for(int j=0;j<6;j++)
{
res[k]='1';
k++;
}
res[k]='0';k++;
}
for(int j=0;j<8;j++)
{
res[k]=s[i];
k++;
i++;
}
}
res[k]='0';k++;
for(int i=1;i<7;i++)
{
res[k]='1';k++;
}
res[k]='0';
cout<<res;
}
Output:
enter the data to be sent:011101111101111110
01111110011101111011111101111110

Byte destuffing
Program:
#include<bits/stdc++.h>
using namespace std;
main()
{
string res(100,' '),s;
int l=0,k=0;
cout<<"enter the data to be sent:";
cin>>s;
l=s.length();
for(int i=0;i<l;i++)
{
if(s[i]=='0' && s[i+1]=='1' && s[i+2]=='1' && s[i+3]=='1' && s[i+4]=='1' && s[i+5]=='1' &&
s[i+6]=='1' && s[i+7]=='0')
{
i=i+8;
}
for(int j=0;j<8;j++)
{
res[k]=s[i];
k++;
i++;
}
}
cout<<res;
}
Output:
enter the data to be sent:0111111011111101
11111101
Conclusion: Character stuffing and destuffing is implemented successfully.

Submitted By:
Priyabrata Mohapatra
Roll No: 1602040017
Computer Science and Engineering
Signature:

Vous aimerez peut-être aussi