Lab - Manual - Cse-354 P PDF
Lab - Manual - Cse-354 P PDF
Goals and Applications of Networks, Network structure and architecture,The OSI reference model,
services, Network Topology Design - Delay Analysis, Back BoneDesign, Local Access Network Design,
Physical Layer Transmission Media, Switching methods,ISDN, Terminal Handling.
Medium Access sub layer - Channel Allocations, LAN protocols -ALOHA protocols - Overview of IEEE
standards - FDDI. Data Link Layer - Elementary DataLink Protocols, Sliding Window protocols, Error
Handling
Network Layer - Point - to Pont Networks, routing, Congestion controlInternetworking -TCP / IP, IP
packet, IP address, IPv6.
Transport Layer - Design issues, connection management, session Layer-Design issues, remote
procedure call. Presentation Layer-Design issues, Data compressiontechniques, cryptography - TCP -
Window Management.
File Transfer, Access and Management, Electronic mail, Virtual Terminals, Other application. Example
Networks - Internet and Public Networks.
References:
LIST OF EXPERIMENTS
Sl. No Topic
• Introduction to basic Linux networking commands. (Commands like ipconfig, getmac, tracert,
pathping, arp, ping, netstat, finger etc.)
• Write a program for hamming code generation for error detection and correction.
• Write a program for congestion control using the leaky bucket algorithm.
• Take a 64-bit plain text and encrypt the same using DES algorithm.
• Using RSA algorithm encrypts a text data and decrypts the same.
Experiment No: 1 Introduction to basic Linux networking commands (Commands like ipconfig,
getmac, tracert, pathping, arp, ping, netstat, finger etc.)
Theory
ipconfig
getmac
Returns the media access control (MAC) address and list of network protocols associated with each
address for all network cards in each computer.
tracert
In computing, traceroute is a computer network diagnostic tool for displaying the route (path) and
measuring transit delays of packets across an Internet Protocol (IP) network. The history of the route is
recorded as the round-trip times of the packets received from each successive host (remote node) in the
route (path); the sum of the mean times in each hop indicates the total time spent to establish the
connection.
pathping
PathPing is a network utility supplied in Windows NT and beyond that combines the functionality of ping
with that of tracert. It provides details of the path between two hosts and Ping-like statistics for each
node in the path based on samples taken over a time period, depending on how many nodes are
between the start and end host.
netstat
In computing, netstat (network statistics) is a command-line tool that displays network connections
(both incoming and outgoing), routing tables, and a number of network interface (network interface
controller or software-defined network interface) and network protocol statistics.
ping
Ping is a computer network administration utility used to test the reachability of a host on an Internet
Protocol (IP) network and to measure the round-trip time for messages sent from the originating host to
a destination computer.
Experiment No: 2
Theory
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>
main()
char str[40];
int i;
scanf("%s", &str);
stuff(str);
int i, j, k = 0, l, n, z;
n = strlen(str);
{
if (str[i] == '1')
k = 1;
if (str[l] == '1')
k++;
else
break;
if (k == 6)
i = i + 6;
z = n + 1;
str[j] = '0';
printf("%s\n", str);
}
Output
Experiment No: 3 Write a program for hamming code generation for error detection and
correction.
B. Theory
In telecommunication, a Hamming code is a linear error-correcting code named 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];
0,1,0,1,0,1,1,
0,0,1,1,1,0,1};
int main()
int i,j;
system("clear");
scanf("%s",data);
printf("Generator Matrix\n");
for(i=0;i<4;i++)
printf("\t %s \n",gmatrix[i]);
for(i=0;i<7;i++)
{
for(j=0;j<4;j++)
encoded[i]=encoded[i]%2;
printf("%d",encoded[i]);
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)
else {
edata[j]=!edata[j];
Output
Generator Matrix
0111000
1010100
1100010
1110001
001001
Generator Matrix
0111000
1010100
1100010
1110001
Encoded Data : 0101011
Experiment No: 4
B. Theory
A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and
storage devices to detect accidental changes to raw data. Blocks of data entering these systems get a
short check value attached, based on the remainder of a polynomial division of their contents; on
retrieval the calculation is repeated, and corrective action can be taken against presumed data
corruption if the check values do not match.
Source Code
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
int i,j,keylen,msglen;
clrscr();
printf("Enter Data: ");
gets(input);
gets(key);
keylen=strlen(key);
msglen=strlen(input);
strcpy(key1,key);
for(i=0;i<keylen-1;i++)
input[msglen+i]='0';
for(i=0;i<keylen;i++)
temp[i]=input[i];
for(i=0;i<msglen;i++)
quot[i]=temp[0];
if(quot[i]=='0')
for(j=0;j<keylen;j++)
key[j]='0';
else
for(j=0;j<keylen;j++)
key[j]=key1[j];
for(j=keylen-1;j>0;j--)
if(temp[j]==key[j])
rem[j-1]='0';
else
rem[j-1]='1';
rem[keylen-1]=input[i+keylen];
strcpy(temp,rem);
strcpy(rem,temp);
printf("\nQuotient is ");
for(i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for(i=0;i<keylen-1;i++)
printf("%c",rem[i]);
for(i=0;i<msglen;i++)
printf("%c",input[i]);
for(i=0;i<keylen-1;i++)
printf("%c",rem[i]);
getch();
Output
Experiment No: 5
Write a program for congestion control using the leaky bucket algorithm.
B. Theory
The Leaky Bucket Algorithm is an algorithm used in packet switched computer 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;
scanf("%d",&o_rate);
scanf("%d",&b_size);
for(i=0;i<5;++i)
{ if(packets[i]>b_size)
bucket capacity\n",packets[i]);
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;
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);
getch();
D.Output
--------------------------------------------------
Incoming packet:6
Transmission left:6
Next packet will come at 7
Transmitted
Bytes remaining:4
Transmitted
Bytes remaining:2
Transmitted
Bytes remaining:0
--------------------------------------------------
Incoming packet:0
Transmission left:0
--------------------------------------------------
Incoming packet:2
Transmission left:2
Transmitted
Bytes remaining:0
--------------------------------------------------
Incoming packet:0
Transmission left:0
Incoming packet:6
Transmission left:6
Transmitted
Bytes remaining:4
Transmitted
Bytes remaining:2
Transmitted
Bytes remaining:0
Experiment No: 6
B. Theory
Dijkstra's algorithm, conceived by Dutch computer scientist Edsger Dijkstra in 1956 and published in
1959, is a graph search algorithm that solves the single-source shortest path problem for a graph with
non-negative edge path costs, producing a shortest path tree. This algorithm is often used in routing and
as a subroutine in other graph algorithms.
Source Code
#include <stdio.h>
#include <stdlib.h>
int main() {
int i, j, k;
scanf("%d", &vertexCount);
scanf("%d", &edgeLength[i][j]);
if (edgeLength[i][j] == 0) {
res[i][j] = INFINITY;
} else {
res[i][j] = edgeLength[i][j];
printf("%3d", edgeLength[i][j]);
printf("\n");
if (res[i][j] == INFINITY)
printf("%3d", 0);
else
printf("%3d", res[i][j]);
printf("\n");
return 0;
Output
0 0 9 4
5 0 0 0
10 6 0 8
0 7 0 0
16 11 9 4
5 16 14 9
10 6 19 8
12 7 21 16
Experiment No: 7
Take a 64-bit plain text and encrypt the same using DES algorithm.
B. Theory
The Data Encryption Standard is a previously predominant symmetric-key algorithm for the encryption
of electronic data. It was highly influential in the advancement of modern cryptography in the academic
world. Developed in the early 1970s at IBM and based on an earlier design by Horst Feistel, the
algorithm was submitted to the National Bureau of Standards (NBS) following the agency's invitation to
propose a candidate for the protection of sensitive, unclassified electronic government data. In 1976,
after consultation with the National Security Agency (NSA), the NBS eventually selected a slightly
modified version, which was published as an official Federal Information Processing Standard (FIPS) for
the United States in 1977. The publication of an NSA-approved encryption standard simultaneously
resulted in its quick international adoption and widespread academic scrutiny. Controversies arose out
of classified design elements, a relatively short key length of the symmetric-key block cipher design, and
the involvement of the NSA, nourishing suspicions about a backdoor. The intense academic scrutiny the
algorithm received over time led to the modern understanding of block ciphers and their cryptanalysis.
C. SOURCE CODE
#include
#include
void main()
{
int a[20],b[20],c[20],i,j,k,l,m,n,x1;
int p,q,r[20],s[20],d[20],y[20],e[10],z=0;
clrscr();
printf(“\n Enter the plain Text number:\n”);
scanf(“%d”,&n);
printf(“\n Enter the key number \n”);
scanf(“%d”,&k);
printf(“\n Enter the bit stream \n”);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
p=n\2;
x1=p-k;
for(i=0;i<=x1;i++)
{
c[i]=0;
z++;
}
z=z-1;
s[i]=a[i];
printf("%d",a[i]);
}
printf("\n Right hand data \n");
for(i=p;i<n;i++)
{
b[i]=a[i];
printf("%d",a[i]);
}
q=p;
for(j=0,l=p;j<z,l<n;j++,l++)
{
if(b[l]==1&&c[j]==1)
d[j]=0;
else if(b[l]==1&&c[j]==0)
d[j]=l;
else
d[j]=0;
}
printf("\n First XOR");
for(i=0;i<p;i++)
{
printf("%d",d[i]);
}
for(j=0,l=0;j<p,j++;j++,l++)
{
if(s[l]=1&&d[j]==1)
r[j]=0;
else if(s[l]=1&&d[j]==0)
r[j]=l;
else if(s[l]==0&&d[j]==1)
r[j]=0;
}
printf("\n Second XOR\n ");
for(i=0;i<p;i++)
printf("%d",r[j]);
getch();
}
D.Output
Experiment No: 8
Using RSA algorithm encrypt a text data and decrypt the same.
B. Theory
RSA is a cryptosystem, which is known as one of the first practicable public-key cryptosystems and is
widely used for secure data transmission. In such a cryptosystem, the encryption key is public and differs
from the decryption key which is kept secret. In RSA, this asymmetry is based on the practical difficulty
of factoring the product of two large prime numbers, the factoring problem. RSA stands for Ron Rivest,
Adi Shamir and Leonard Adleman, who first publicly described the algorithm in 1977. Clifford Cocks, an
English mathematician, had developed an equivalent system in 1973, but it wasn't declassified until
1997.
C. SOURCE CODE
#include<stdio.h>
#include<conio.h>
int phi,M,n,e,d,C,FLAG;
int check()
int i;
FLAG = 1;
return;
FLAG = 0;
void encrypt()
int i;
C = 1;
for(i=0;i< e;i++)
C=C*M%n;
C = C%n;
void decrypt()
int i;
M = 1;
for(i=0;i< d;i++)
M=M*C%n;
M = M%n;
void main()
int p,q,s;
clrscr();
scanf(“%d%d”,&p,&q);
n = p*q;
phi=(p-1)*(q-1);
do
{
printf(“\n\nEnter e which is prime number and less than phi \t: “,n);
scanf(“%d”,&e);
check();
}while(FLAG==1);
d = 1;
do
s = (d*e)%phi; d++;
}while(s!=1);
d = d-1;
scanf(“%d”,&M);
encrypt();
scanf(“%d”,&C);
decrypt();
getch(); }
D.Output
The cipher text: the quick bro n fo☺ runs over the la♥☻ dog
Experiment No: 9
Theory:
A link-state routing protocol is one of the two main classes of routing protocols used in packet
switching networks for computer communications (the other is the distance-vector routing protocol).
Examples of link-state routing protocols include open shortest path first (OSPF) and intermediate
system to intermediate system (IS-IS).
The link-state protocol is performed by every switching node in the network (i.e., nodes that are
prepared to forward packets; in the Internet, these are called routers). The basic concept of link-state
routing is that every node constructs a map of the connectivity to the network, in the form of a graph,
showing which nodes are connected to which other nodes. Each node then independently calculates
the next best logical path from it to every possible destination in the network. The collection of best
paths will then form the node's routing table.
This contrasts with distance-vector routing protocols, which work by having each node share
its routing table with its neighbors. In a link-state protocol the only information passed between
nodes is connectivity related.
Link-state algorithms are sometimes characterized informally as each router 'telling the world about
its neighbors'.
Experiment No: 10
To compress or decompress an input array using the Lempel-Ziv-Welch (LZW) algorithm. The LZW
algorithm is a lossless data compression algorithm created by Terry Welch in 1984. This algorithm
represents an improved version of the LZ78 algorithm created by Abraham Lempel and Jacob Ziv in
1978.
The idea of the compression algorithm is the following: as the input data is being processed, a dictionary
keeps a correspondence between the longest encountered words and a list of code values. The words
are replaced by their corresponding codes and so the input file is compressed. Therefore, the efficiency
of the algorithm increases as the number of long, repetitive words in the input data increases.
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.
B. Source Code
#include <codecogs/computing/io/compression/lzw.h>
#include <iostream>
#define N 10000
int main()
std::cout << " Size of the sample array: " << N << std::endl;
std::cout << " Size of the compressed array: " << compressed.size() << std::endl;
std::cout << "Size of the uncompressed array: " << uncompressed.size() << std::endl;
// this proves that the LZW compression algorithm does not affect the initial data
if (sample[i] != uncompressed[i])
identical = false;
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;
C Output: