Bcse2370 DCN Lab
Bcse2370 DCN Lab
Bcse2370 DCN Lab
2022-2023
SUBJECT Data Communication & Networking PROGRAMME B. Tech.
DURATION OF
CREDITS 1 13 Weeks
SEMESTER
PREREQUISITE SESSION
C/C++ 2 Hrs per Week
SUBJECTS DURATION
Vision
"To be recognized globally as a premier School of Computing Science and Engineering for
imparting quality and value based education within a multi-disciplinary and collaborative research
based environment."
Mission
The mission of the school is to:
M2: Establish state-of-the-art facilities and adopt education 4.0 practices to analyze, develop, test
and deploy sustainable ethical IT solutions by involving multiple stakeholders.
M3: Foster multidisciplinary collaborative research in association with academia and industry
through focused research groups, Centre of Excellence, and Industry Oriented R&D Labs.
PROGRAM EDUCATIONAL OBJECTIVES
The Graduates of Computer Science and Engineering shall:
PEO1: be engaged with leading Global Software Services and Product development
companies handling projects in cutting edge technologies.
PEO2: serve in technical or managerial roles at Government firms, Corporates and contributing to
thesociety as successful entrepreneurs through startup.
PSO1: Have the ability to work with emerging technologies in computing requisite to Industry 4.0.
PSO2: Demonstrate Engineering Practice learned through industry internship and research project
tosolve live problems in various domains.
PROGRAMME OUTCOME (PO):
PO1 Computing Science knowledge: Apply the knowledge of mathematics, statistics, computing
science and information science fundamentals to the solution of complex computer application
problems.
PO2 Problem analysis: Identify, formulate, review research literature, and analyze complex
computing science problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and computer sciences.
PO3 Design/development of solutions: Design solutions for complex computing problems and
design system components or processes that meet the specified needs with appropriate consideration
for the public health and safety, and the cultural, societal, and environmental considerations.
PO4 Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
PO5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
computing science and IT tools including prediction and modeling to complex computing activities
with an understanding of the limitations.
PO6 IT specialist and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional computing science and information science practice.
PO7 Environment and sustainability: Understand the impact of the professional computing science
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
PO8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the computing science practice.
PO9 Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
PO10 Communication: Communicate effectively on complex engineering activities with the IT
analyst community and with society at large, such as, being able to comprehend and write effective
reports and design documentation, make effective presentations, and give and receive clear
instructions.
PO11 Project management and finance: Demonstrate knowledge and understanding of the
computing science and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
PO12 Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
List of Programs
Programs
1 Implement bit stuffing
2 Implement bit de-stuffing
3 Write a program for hamming code generation for error detection and correction
4 Implement Cyclic Redundancy Check (CRC)
5 Write a program for congestion control using the leaky bucket algorithm
6 Implement Dijkstra's algorithm to compute a shortest path through graph.
7 Take a 64-bit plain text and encrypt the same using DES algorithm
8 Using RSA algorithm encrypt a text data and decrypt the same.
9 Implementation of the link state routing protocols.
10 Implementation of LZW compression and decompression algorithms.
Course Outcomes
CO2 Understand and configure the different types of network topologies and protocols.
CO3 Understand the different protocols layers of the OSI model.
CO4 Examine and analyze the network-layer concepts like Network-Layer services –
Routing -IP protocol -IP addressing
CO5 Examine and analyze the different link-layer and local area network concepts like
Link-Layer services –Ethernet -Token Ring -Error detection and correction -ARP
protocol
CO6 Gain understanding of latest trends and research areas in the course
CO-PO-PSO MAPPING:
CO/PO
Mapping
CO1 2 1 1 3 2 2 3 1
CO2 2 1 1 2
CO3 1 1 1 1 1 2
CO4
CO5 1 2
100 0 100
1 Performance 2
2 Result 3
3 File 2
4 Viva 3
Total 10
Experiment No:1
Title Implement bit stuffing and de-stuffing.
Algorithm/ In data transmission and telecommunication, bit stuffing (also known—
Theory uncommonly—as positive justification) is the insertion of non-information bits
into data. Stuffed bits should not be confused with overhead bits.
Bit stuffing is used for various purposes, such as for bringing bit streams that do
not necessarily have the same or rationally related bit rates up to a common rate,
or to fill buffers or frames. The location of the stuffing bits is communicated to the
receiving end of the data link, where these extra bits are removed to return the bit
streams to their original bit rates or form. Bit stuffing may be used to synchronize
several channels before multiplexing or to rate-match two single channels to each
other.
Applications include Plesiochronous Digital Hierarchy and Synchronous Digital
Hierarchy.
Source Code
#include <stdio.h>
#include <string.h>
void stuff(char str[40]);
main()
{
char str[40];
int i;
printf("\n enter the string:");
scanf("%s", &str);
printf("\n the given string is:");
printf("\n %s", str);
stuff(str);
}
else
break;
}
if (k == 6)
{
i = i + 6;
z = n + 1;
for (j = z; j >= i; j--)
{
str[j] = str[j - 1];
}
str[j] = '0';
}
}
}
printf("\nThe resultant string after stuffing is..\n");
printf("%s\n", str);
}
Sample
Output
Experiment No:3
Title Write a program for hamming code generation for error detection and
correction.
Algorithm/ In telecommunication, a Hamming code is a linear error-correcting code named
Theory after its inventor, Richard Hamming. Hamming codes can detect up to two
simultaneous bit errors, and correct single-bit errors; thus, reliable communication
is possible when the Hamming distance between the transmitted and received bit
patterns is less than or equal to one. By contrast, the simple parity code cannot
correct errors, and can only detect an odd number of errors.
Source Code
#include<stdlib.h>
#include<stdio.h>
char data[5];
int encoded[8], edata[7], syndrome[3];
int hmatrix[3][7]= { 1,0,0,0,1,1,1,
0,1,0,1,0,1,1,
0,0,1,1,1,0,1};
char gmatrix[4][8]={ "0111000", "1010100", "1100010", "1110001"};
int main()
{
int i,j;
system("clear");
printf("Hamming Code --- Encoding\n");
printf("Enter 4 bit data : ");
scanf("%s",data);
printf("Generator Matrix\n");
for(i=0;i<4;i++)
printf("\t %s \n",gmatrix[i]);
printf("Encoded Data : ");
for(i=0;i<7;i++)
{
for(j=0;j<4;j++)
encoded[i]+=((data[j]- '0')*(gmatrix[j][i]- '0'));
encoded[i]=encoded[i]%2;
printf("%d",encoded[i]);
}
printf("\nHamming code --- Decoding\n");
printf("Enter Encoded bits as received : ");
for(i=0;i<7;i++)
scanf("%d",&edata[i]);
for(i=0;i<3;i++){
for(j=0;j<7;j++)
syndrome[i]=syndrome[i]+(edata[j]*hmatrix[i][j]);
syndrome[i]=syndrome[i]%2;}
for(j=0;j<7;j++)
if ((syndrome[0]==hmatrix[0][j])&&(syndrome[1]==hmatrix[1][j])&&
(syndrome[2]==hmatrix[2][j]))
break;
if(j==7)
printf("Data is error free!!\n");
else {
printf("Error received at bit number %d of the data\n",j+1);
edata[j]=!edata[j];
printf("The Correct data Should be : ");
for(i=0;i<7;i++) printf(" %d ",edata[i]);
}}
Sample
Output
Experiment No:5
Title Write a program for congestion control using the leaky bucket algorithm.
Algorithm/ The Leaky Bucket Algorithm is an algorithm used in packet switched computer
Theory networks and telecommunications networks. It can be used to check that data
transmissions, in the form of packets, conform to defined limits on bandwidth and
burstiness (a measure of the unevenness or variations in the traffic flow). It can
also be used as a scheduling algorithm to determine the timing of transmissions
that will comply with the limits set for the bandwidth and burstiness: see network
scheduler. The leaky bucket algorithm is also used in leaky bucket counters, e.g.
to detect when the average or peak rate of random or stochastic events or
stochastic processes exceed defined limits.
C. SOURCE CODE
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void main()
{ int
packets[8],i,j,clk,b_size,o_rate,i_rate,p_sz_rm=0,p_sz,p_time;
clrscr();
for(i=0;i<5;++i)
{ packets[i]=rand()%10;
if(packets[i]==0) --i;
}
printf("Enter output rate:");
scanf("%d",&o_rate);
printf("\nEnter bucket size:");
scanf("%d",&b_size);
for(i=0;i<5;++i)
{ if((packets[i]+p_sz_rm) > b_size)
{ if(packets[i]>b_size)
printf("\nIncoming packet size:%d greater than
bucket capacity\n",packets[i]);
else printf("Bucket size exceeded\n");
}
else
{
p_sz=packets[i];
p_sz_rm+=p_sz;
printf("\n-------------------------------------------------
-\n");
printf("Incoming packet:%d",p_sz);
printf("\nTransmission left:%d\n",p_sz_rm);
p_time=rand()%10;
printf("Next packet will come at %d",p_time);
for(clk=0;clk<p_time&&p_sz_rm>0;++clk)
{
printf("\nTime left %d---No packets to
transmit!!\n",p_time-clk);
sleep(1);
if(p_sz_rm)
{ printf("Transmitted\n");
if(p_sz_rm<o_rate)
p_sz_rm=0;
else p_sz_rm-=o_rate;
printf("Bytes remaining:%d\n",p_sz_rm);
}
else printf("No packets to transmit\n");
}
}
}
getch();
}
int main() {
int vertexCount, **edgeLength, **res;
int i, j, k;
printf("Enter the no of vertices:");
scanf("%d", &vertexCount);
edgeLength = (int **)calloc(sizeof(int), vertexCount);
res = (int **)calloc(sizeof(int), vertexCount);
for (i = 0; i < vertexCount; i++) {
edgeLength[i] = (int *)calloc(sizeof(int), vertexCount);
res[i] = (int *)calloc(sizeof(int), vertexCount);
}
Either when using the compression or the decompression methods, the elements
of the input array must be of type unsigned char, which is also the type of the
resulting array's elements.
The following example generates a sample array of N random letters (from A to
Z) and compresses it. The compressed array is then decompressed to see if the
sample array is identical to the uncompressed array. The size of the compressed
array is also displayed, to prove the efficiency of the LZW algorithm.
Source Code
#include <codecogs/computing/io/compression/lzw.h>
#include <iostream>
int main()
{
// initialize random seed
srand(time(0));
if (identical)
std::cout << "The sample and uncompressed arrays are identical." << std::endl;
else
std::cout << "Error! The sample and uncompressed arrays are NOT identical."
<< std::endl;
return 0;
}
#include<stdio.h>
main()
int n,a[10][10],i,j,k;
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
for(i=0;i<n;i++)
printf("\n NODE\tDISTANCE\n");
for(j=0;j<n;j++)
if(a[i][j]!=0&&a[i][j]!=-1)
printf("%d\t%d\n",j+1,a[i][j]);
printf("\n\n");
}
Sample
Output
Experiment No:10
Title Implementation of Distance Vector algorithms.
Algorithms/Program In computer communication theory relating to packet-switched networks, a
distance-vector routing protocol is one of the two major classes of
routing protocols, the other major class being the link-state protocol. A
distance-vector routing protocol uses the Bellman-Ford algorithm to
calculate paths. A distance-vector routing protocol requires that a router
informs its neighbors of topology changes periodically and, in some cases,
when a change is detected in the topology of a network. Compared to link-
state protocols, which require a router to inform all the nodes in a network
of topology changes, distance-vector routing protocols have less
computational complexity and message overhead. Distance Vector means
that Routers are advertised as vector of distance and direction. 'Direction' is
represented by next hop address and exit interface, whereas 'Distance' uses
metrics such as hop count.
Routers using distance vector protocol do not have knowledge of the entire
path to a destination. Instead DV uses two methods:
Algorithm/ #include<stdio.h>
Theory
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int dmat[20][20];
int n,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&n);
printf("\nEnter the cost matrix :\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j;
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}while(count!=0);
for(i=0;i<n;i++)
{
printf("\n\nState value for router %d is \n",i+1);
for(j=0;j<n;j++)
{
printf("\t\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
}
SHILPY GUPTA
Name of the Course Coordinator: Signature