CN Lab Manual - 18ECL76
CN Lab Manual - 18ECL76
CN Lab Manual - 18ECL76
DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING
(ACADEMIC YEAR 2023-2024)
LABORATORY MANUAL
VISION
Don Bosco group of institutions shines brighter each day with a vision to achieve a world class
status in providing exceptionally excellent higher education in the field of Management,
Technology and Applied Sciences entrenched with Human Values.
MISSION
With a mission to provide refined high quality technical education and training to aspiring
students, we at Don Bosco, strive to impart exclusively valuable, academic knowledge relating to
an array of professional fields undertaken.
Our persistent efforts will evidently create and develop future technocrats and proficient business
leaders who will confidently attend to improve the quality of life for the current generation.
VISION
To become a world-class center in providing globally relevant higher education in the field of
management, technology and applied science embedded with human values.
MISSION
To foster an intellectual and ethical environment in which both skill and spirit will thrive to
impart high quality education, training, and service with an international outlook. To create and
develop technocrats and business leaders who will strive to improve the quality of life.
VISION
To impart value based technical education and train students through continuous improvement
in effectiveness and efficiency of – teaching, learning and associated processes and to collaborate
with industry, foreign universities and institutions for academic exchange program for faculty
and students.
MISSION
To provide an excellent inter-active learning opportunity for all students and staff to develop
knowledge and skills essential in enlightening the individual’s ability to think vitally and utilize
all concepts of Electronics & Communication Engineering in detail to meet the technological
challenges of tomorrow and to refine knowledge and understanding through research and
creative activities.
PROGRAMME OUTCOMES:
k) An ability to use the techniques, skills, and modern engineering tools necessary for
engineering practice and
Laboratory Experiments
PART-A: Simulation experiments using NS2/ NS3/ OPNET/ NCTUNS/ NetSim/ QualNet
or any other equivalent tooL
[1] Implement a point to point network with four nodes and duplex links between them.
Analyze the network performance by setting the queue size and varying the bandwidth.
[2] Implement a four node point to point network with links n0-n2, n1-n2 and n2-n3. Apply
TCP agent between n0-n3 and UDP between n1-n3. Apply relevant applications over
TCP and UDP agents changing the parameter and determine the number of packets sent
by TCP/UDP.
[3] Implement Ethernet LAN using n (6-10) nodes. Compare the throughput by changing
the error rate and data rate.
[4] Implement Ethernet LAN using n nodes and assign multiple traffic to the nodes and
obtain congestion window for different sources/ destinations.
[5] Implement ESS with transmission nodes in Wireless LAN and obtain the performance
parameters.
[6] Implementation of Link state routing algorithm.
PART-B: Implement the following in C/C++
[1] Write a program for a HLDC frame to perform the following. i) Bit stuffing ii)
Character stuffing.
[2] Write a program for distance vector algorithm to find suitable path for transmission.
[3] Implement Dijkstra’s algorithm to compute the shortest routing path.
[4] For the given data, use CRC-CCITT polynomial to obtain CRC code. Verify the
program for the cases a) Without error b) With error
[5] Implementation of Stop and Wait Protocol and Sliding Window Protocol
[6] Write a program for congestion control using leaky bucket algorithm.
Course outcomes: On the completion of this laboratory course, the students will be able to:
1. Choose suitable tools to model a network.
2. Use the network simulator for learning and practice of networking algorithms.
3. Illustrate the operations of network protocols and algorithms using C programming.
4. Simulate the network with different configurations to measure the performance
parameters.
5. Implement the data link and routing protocols using C programming.
Conduct of Practical Examination:
CYCLE-1
1. Implement a point to pint network with four nodes and duplex links between
them. Analyze the network performance by setting the queue size and varying
the bandwidth.
2. Implement a four node point to point network with links n0-n2, n1-n2 and n2-
n3. Apply TCP agent between n0-n3 and UDP between n1-n3. Apply relevant
applications over TCP and UDP agents changing the parameter and determine
the number of packets sent by TCP/UDP.
3. Implement Ethernet LAN using n (6-10) nodes. Compare the throughput by
changing the error rate and data rate.
4. Implement Ethernet LAN using n nodes and assign multiple traffic to the nodes
and obtain congestion window for different sources/ destinations.
CYCLE-2
5. Implement ESS with transmission nodes in Wireless LAN and obtain the
performance parameters.
CONTENT LIST
SL. PAGE
EXPERIMENT NAME
NO. NO.
Implement a point to pint network with four nodes and duplex links
1. between them. Analyze the network performance by setting the queue 11
size and varying the bandwidth
Implement a four node point to point network with links n0-n2, n1-n2
2. and n2-n3. Apply TCP agent between n0-n3 and UDP between n1-n3. 17
Apply relevant applications over TCP and UDP agents changing the
parameter and determine the number of packets sent by TCP/UDP.
Implement Ethernet LAN using n (6-10) nodes. Compare the throughput
3. 23
by changing the error rate and data rate.
Implement Ethernet LAN using n nodes and assign multiple traffic to the
4. nodes and obtain congestion window for different sources/ destinations.
27
Implement ESS with transmission nodes in Wireless LAN and obtain the
5. 31
performance parameters.
For the given data, use CRC-CCITT polynomial to obtain CRC code.
Verify the program for the cases
10. 52
i) Without error
ii) With error
11. Implementation of Stop and Wait Protocol and Sliding Window Protocol 57
12. Write a program for congestion control using leaky bucket algorithm 59
ADDON EXPERIMENT
PART-A
Experiment:1
Aim:Implement a point to point network with four nodes and duplex links between
them. Analyze the network performance by setting the queue size and varying the
bandwidth.
#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 100.0Mb 20ms DropTail
$ns queue-limit $n0 $n2 20 #Q1
$ns duplex-link $n1 $n2 100.0Mb 20ms DropTail
$ns queue-limit $n1 $n2 20 #Q2
$ns duplex-link $n2 $n3 100.0Mb 20ms DropTail
$ns queue-limit $n2 $n3 20 #Q3
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink2 [new Agent/TCPSink]
$ns attach-agent $n3 $sink2
$ns connect $tcp0 $sink2
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 8.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
exec nam lab1.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
Awk Script:
BEGIN{
tcppack=0
tcppack1=0
}
{
if($1=="r"&&$4=="3"&&$5=="tcp"&&$6=="1540")
{
tcppack++;
}
if($1=="d"&&$3=="2"&&$5=="tcp"&&$6=="1540")
{
tcppack1++;
}
}
END{
printf("\n total number of data packets received at Node 3: %d\n", tcppack++);
printf("\n total number of packets dropped at Node 2: %d\n", tcppack1++);
}
Results:
Execution Steps:
Viva Question:
a. Define Network?
b. What is Protocol?
c. List the layers of OSIWhat is Error Detection? What are its methods?
e. What is the difference between TFTP and FTP application layer protocols?
Application:
a. LAN, WAN, MAN
b. Web-caching, multicast
Experiment:2
Aim:Implement a four node point to point network with links N0- N2, N1- N2 and N2-N3.
Apply TCP agent between N0-N3 and UDP between N1-N3. Apply relevant applications
over TCP and UDP agents changing the parameter and determine the number of packets
sent by TCP/UDP.
#===================================
# Simulation parameters setup
#===================================
set val(stop) 50.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Nodes Definition
#===================================
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 200.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n2 $n3 200.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 50
$ns duplex-link $n1 $n2 200.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink3 [new Agent/TCPSink]
$ns attach-agent $n3 $sink3
$ns connect $tcp0 $sink3
$tcp0 set packetSize_ 1500 # Change the Packet Size
$tcp0 set interval_ 0.1
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 9.0 "$ftp0 stop"
Awk Script:
BEGIN{
tcppack=0
tcppack1=0
}
{
if($1=="r"&&$4=="2"&&$5=="tcp"&&$6=="1540") #1540, 1040, 1340
{
tcppack++;
}
if($1=="r"&&$4=="2"&&$5=="cbr"&&$6=="1500") #1500, 1500, 1500
{
tcppack1++;
}
}
END{
printf("\n total number of TCP data packets sent between Node 0 and Node 2: %d\n",
tcppack++);
printf("\n total number of UDP data packets sent between Node 1 and Node 2: %d\n",
tcppack1++);
}
Results:
Execution Steps:
Viva Question:
a. Define Bandwidth and Latency?
b. Define Routing?
c. What is a peer-peer process?
d. Which layers are network support layers?
Application:
a. Web-caching, multicast
b. Process Automation Network
Experiment:3
proc finish { } {
global ns nftf
$ns flush-trace
close $nf
close $tf
exec nam lab3.nam &
exit 0
}
Awk Script:
BEGIN{
tcppack=0
tcppack1=0
}
{
if($1=="r"&&$4=="7"&&$5=="cbr"&&$6=="1000")
{
tcppack++;
}
}
END{
printf("\n total number of data packets at Node 7: %d\n", tcppack++);
}
Results:
Execution Steps:
Viva Question:
a. What are the responsibilities of Data Link Layer??
b. What are the responsibilities of Data Link Layer??
c. What are the responsibilities of Network Layer?
d. What is ethernet?
Application:
a. Process Automation Network
b. Wind farm Network
Experiment:4
Aim:Implement Ethernet LAN using N nodes and assign multiple traffic to the nodes
and obtain congestion window for different sources/ destinations.
$ns make-lan "$n0 $n1 $n2 $n3" 10mb 10ms LL Queue/DropTail Mac/802_3
$ns run
1. File1.tr is the Congestion Window (CWND) value of TCP agent.
2. File2.tr is the Congestion Window (CWND) value of TCPReno agent.
Viva Question:
a. What are the responsibilities of Transport Layer?
b. What are the responsibilities of Session Layer?
c. What are the responsibilities of Presentation Layer?
d. What are the responsibilities of Application Layer?
Application:
a. Wind farm Network
b. Solar Energy Network
Experiment:5
Aim:Implement ESS with transmission nodes in Wireless LAN and obtain then
Performance Parameters.
create-god 3
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
$n0 set X_ 50
$n0 set Y_ 50
$n0 set Z_ 0
$n1 set X_ 100
$n1 set Y_ 100
$n1 set Z_ 0
$n2 set X_ 600
$n2 set Y_ 600
$n2 set Z_ 0
BEGIN{
tcppack=0
tcppack1=0
}
{
if($1=="s"&&$3=="_0_"&&$4=="AGT"&&$8=="1040")
{
tcppack++;
}
if($1=="r"&&$3=="_2_"&&$4=="AGT"&&$8=="1040")
{
tcppack1++;
}
}
END{
printf("\n total number of data packets sent from Node 0: %d\n", tcppack++);
printf("\n total number of data packets received at Node 2: %d\n", tcppack++);
Execution Steps:
Viva Question:
a. What are the two classes of hardware building blocks?
b. What are the different link types used to build a computer network?
c. What are the categories of Transmission media?
d. What is Redundancy?
Application:
a. LAN, WAN, MAN
Experiment:6
#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Nodes Definition
#===================================
#Create 5 nodes
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n1 50
$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 50
$ns duplex-link $n1 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n3 50
$ns duplex-link $n3 $n4 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n4 50
$ns duplex-link $n0 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n3 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n4 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 5.0 "$cbr0 stop"
$ns rtproto LS
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
Viva Question:
a. What is Round Trip Time?
b. What is semantic gap?
c. When a switch is said to be congested?
Application:
a. Wireless Network(Wireless Senor Network, Ad hoc Network)
b. Satellite Networking
c. Mobile Communication
PART-B
Implement the following in C/C++
Experiment:7
Framing in the data link layer separates a message from one source to a destination by adding as
ender address & a destination address. The destination address defines where the packet is tog
o; the sender address helps the recipient acknowledge the receipt. Although the whole messagec
ould be packed in one frame, that is not normally done. One reason is that a frame can be veryl
arge, making flow & error control very inefficient.
When a message is carried in one very largeframe, even a singlebit error would require the ret
ransmission of the whole message. When amessage is divided into smaller frames, a single-
bit error affects only that small frame.
a) Character-oriented approach:
i) Bit stuffing
#include<string.h>
#include<stdio.h>
Main()
{
char a[20],fs[50]="",t[6],r[5];
inti,j,p=0,q=0;
{
r[0]=a[i];
r[1]='\0';
strcat(fs,r);
}
p=0;
}
for(q=i;q<strlen(a);q++)
{
t[p++]=a[q];
}
t[p]='\0';
strcat(fs,t);
}
strcat(fs,"01111110");
printf("After stuffing : %s",fs);
getch();
}
Experiment:8
Aim:Write a program for distance vector algorithm to find suitable path for
transmission.
Distance Vector Algorithm is a decentralized routing algorithm that requires that each router
simply inform its neighbors of its routing table. For each network path, the receiving routers pick
the neighbor advertising the lowest cost, then add this entry into its routing table for re-
advertisement. To find the shortest path, Distance Vector Algorithm is based on one of two basic
algorithms: the Bellman-Ford and the Dijkstra algorithms.
Routers that use this algorithm have to maintain the distance tables (which is a one-dimension
array -- "a vector"), which tell the distances and shortest path to sending packets to each node in
the network. The information in the distance table is always upd by exchanging information with
the neighboring nodes. The number of data in the table equals to that of all nodes in networks
(excluded itself). The columns of table represent the directly attached neighbors whereas the
rows represent all destinations in the network. Each data contains the path for sending packets to
each destination in the network and distance/or time to transmit on that path (we call this as
"cost"). The measurements in this algorithm are the number of hops, latency, the number of
outgoing packets, etc.
The starting assumption for distance-vector routing is each node knows the cost of the link of
each of its directly connected neighbors. Next, every node sends a configured message to its
directly connected neighbors containing its own distance table. Now, every node can learn and
up its distance table with cost and next hops for all nodes network. Repeat exchanging until no
more information between the neighbors.
Consider a node A that is interested in routing to destination H via a directly attached neighbor J.
Node A's distance table entry, Dx(Y,Z) is the sum of the cost of the direct-one hop link between
A and J, c(A,J), plus neighboring J's currently known minimum-cost path (shortest path) from
itself(J) to H. That is Dx(H,J) = c(A,J) + minw{Dj(H,w)} The minw is taken over all the J's This
equation suggests that the form of neighbor-to-neighbor communication that will take place in
the DV algorithm - each node must know the cost of each of its neighbors' minimum-cost path to
each destination. Hence, whenever a node computes a new minimum cost to some destination, it
must inform its neighbors of this new minimum cost.
include<stdio.h>
#include<stdlib.h>
#define nul 1000
#define nodes 10
int no;
struct node
{
int a[nodes][3];
}
router[nodes];
void init(int r)
{
inti;
for(i=1;i<=no;i++)
{
router[r].a[i][1]=i;
router[r].a[i][2]=999;
router[r].a[i][3]=nul;
}
router[r].a[r][2]=0;
router[r].a[r][3]=r;
}
void inp(int r)
{
inti;
printf("\n enter dist to the node %d to other nodes",r);
printf("\n please enter 999 if there is no direct route\n");
for(i=1;i<=no;i++)
{
if(i!=r)
{
printf("\n enter dist to the node %d:",i);
scanf("%d",&router[r].a[i][2]);
router[r].a[i][3]=i;
}
}
}
void display(int r)
{
inti;
printf("\n\n the routimg table for node %d is as follows",r);
for(i=1;i<=no;i++)
{
if(router[r].a[i][2]>=999)
printf("\n\t\t\t %d \t no link \t no hop",router[r].a[i][1]);
else
printf("\n\t\t\t %d \t %d \t\t %d",router[r].a[i][1],router[r].a[i][2],router[r].a[i][3]);
}
}
void dv_algo(int r)
{
inti,j,z;
for(i=1;i<=no;i++)
{
if(router[r].a[i][2]!=999 && router[r].a[i][2]!=0)
{
Viva Question:
a. Why should you care about the OSI Reference Model?
b. What is virtual path?
c. What is packet filter?
Experiment:9
Aim: Implement Dijkstra’s algorithm to compute the shortest routing path
Distance Vector Algorithm is a decentralized routing algorithm that requires that each
router simply inform its neighbors of its routing table. For each network path, the receiving
routers pick the neighbor advertising the lowest cost, then add this entry into its routing table for
re-advertisement. To find the shortest path, Distance Vector Algorithm is based on one of two
basic algorithms: the Bellman-Ford and the Dijkstra algorithms.
Routers that use this algorithm have to maintain the distance tables (which is a one-
dimension array -- "a vector"), which tell the distances and shortest path to sending packets to
each node in the network. The information in the distance table is always upd by exchanging
information with the neighboring nodes. The number of data in the table equals to that of all
nodes in networks (excluded itself). The columns of table represent the directly attached
neighbors whereas the rows represent all destinations in the network. Each data contains the path
for sending packets to each destination in the network and distance/or time to transmit on that
path (we call this as "cost"). The measurements in this algorithm are the number of hops, latency,
the number of outgoing packets, etc.
The starting assumption for distance-vector routing is each node knows the cost of the
link of each of its directly connected neighbors. Next, every node sends a configured message to
its directly connected neighbors containing its own distance table. Now, every node can learn
and up its distance table with cost and next hops for all nodes network. Repeat exchanging until
no more information between the neighbors.
Consider a node A that is interested in routing to destination H via a directly attached
neighbor J. Node A's distance table entry, Dx(Y,Z) is the sum of the cost of the direct-one hop
link between A and J, c(A,J), plus neighboring J's currently known minimum-cost path (shortest
path) from itself(J) to H. That is Dx(H,J) = c(A,J) + minw{Dj(H,w)} The minw is taken over all
the J's This equation suggests that the form of neighbor-to-neighbor communication that will
take place in the DV algorithm - each node must know the cost of each of its neighbors'
minimum-cost path to each destination. Hence, whenever a node computes a new minimum cost
to some destination, it must inform its neighbors of this new minimum cost.
include<stdio.h>
void sort(void);
static intdsp[10][10],nodes;
struct{
char src;
char dest;
int length;
}stemp,permanent[10]={' ',' ',0},temp[10]={' ',' ',-1};
static intperm,tem;
void main()
{
inti,j,k,l,m,n=0,point;
char initial,dest,path[10]={' '};
printf("\t\t Shortest Path (Dijkstra's algorithm)");
printf("\n*******************************************************");
printf("\nEnter the number of nodes:");
scanf("%d",&nodes);
printf("\nEnter the adjacency matrix for the graph:\n");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
scanf("%d",&dsp[i][j]);
}
fflush(stdin);
printf("\n enter the source node:");
scanf("%c",&initial);fflush(stdin);
printf("\n Enter the destination node:");
scanf("%c",&dest);
permanent[perm].src=initial;
permanent[perm].dest=initial;
permanent[perm++].length=0;
i=permanent[perm-1].dest-97;
for(j=0;j<nodes;j++)
{
if(i!=j)
{
if(dsp[i][j]>0)
{
temp[tem].src=permanent[perm-1].src;
temp[tem].dest=j+97;
temp[tem++].length=dsp[i][j];
}
}
}
sort();
Viva Question:
a. What is virtual channel?
b. What is the minimum and maximum length of the header in the TCP segment and IP
datagram?
c. What is Protocol Data Unit?
Application:
a. In data networks determines the best route for data packets
b. Congestion control
Experiment:10
Aim: For the given data, use CRC-CCITT polynomial to obtain CRC code. Verify the
program for the cases a. Without error
b. with error
Whenever digital data is stored or interfaced, data corruption might occur. Since the
beginning of computer science, developers have been thinking of ways to deal with this type of
problem. For serial data they came up with the solution to attach a parity bit to each sent byte.
This simple detection mechanism works if an odd number of bits in a byte changes, but an even
number of false bits in one byte will not be detected by the parity check. To overcome this
problem developers have searched for mathematical sound mechanisms to detect multiple false
bits. The CRC calculation or cyclic redundancy check was the result of this. Nowadays CRC
calculations are used in all types of communications. All packets sent over a network connection
are checked with a CRC. Also each data block on your hard disk has a CRC value attached to it.
Modern computer world cannot do without these CRC calculations. So let's see why they are so
widely used. The answer is simple; they are powerful, detect many types of errors and are
extremely fast to calculate especially when dedicated hardware chips are used.
The idea behind CRC calculation is to look at the data as one large binary number. This
number is divided by a certain value and the remainder of the calculation is called the CRC.
Dividing in the CRC calculation at first looks to cost a lot of computing power, but it can be
performed very quickly if we use a method similar to the one learned at school. We will as an
example calculate the remainder for the character 'm'—which is 1101101 in binary notation—by
dividing it by 19 or 10011. Please note that 19 is an odd number. This is necessary as we will see
further on. Please refer to your schoolbooks as the binary calculation method here is not very
different from the decimal method you learned when you were young. It might only look a little
bit strange. Also notations differ between countries, but the method is similar.
With decimal calculations you can quickly check that 109 divided by 19 gives a quotient
of 5 with 14 as the remainder. But what we also see in the scheme is that every bit extra to check
only costs one binary comparison and in 50% of the cases one binary subtraction. You can easily
increase the number of bits of the test data string—for example to 56 bits if we use our example
value "Lammert"—and the result can be calculated with 56 binary comparisons and an average
of 28 binary subtractions. This can be implemented in hardware directly with only very few
transistors involved. Also software algorithms can be very efficient.
All of the CRC formulas you will encounter are simply checksum algorithms based on
modulo-2 binary division where we ignore carry bits and in effect the subtraction will be equal to
an exclusive or operation. Though some differences exist in the specifics across different CRC
formulas, the basic mathematical process is always the same:
The message bits are appended with c zero bits; this augmented message is the dividend
A predetermined c+1-bit binary sequence, called the generator polynomial, is the divisor
The checksum is the c-bit remainder that results from the division operation
Table 1 lists some of the most commonly used generator polynomials for 16- and 32-bit CRCs.
Remember that the width of the divisor is always one bit wider than the remainder. So, for
example, you’d use a 17-bit generator polynomial whenever a 16-bit checksum is required.
CRC-CCITT CRC-16 CRC-32
Checksum
16 bits 16 bits 32 bits
Width
Generator 100010000001000 11000000000000 10000010011000001000
Polynomial 01 101 1110110110111
int main()
{
void div();
printf("\nEnter the length of Data Frame :");
scanf("%d",&len);
printf("\nEnter the Message :");
for(i=0;i<len;i++)
scanf("%d",&a[i]);
return 0;
}
printf("\nDataRecived is ERROR FREE");
}
Viva Question:
a. What is CRC?
b. What is Checksum?
c. List the steps involved in creating the checksum.
d. What is VRC?
Application:
a. Error control and detection
b. Checksums are used to ensure the integrity of a file after it has been transmitted from
one storage device to another
Experiment:11
Aim: Implementation of Stop and Wait Protocol and Sliding Window Protocol
Design:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int i,j,noframes,x,x1=10,x2;
noframes=10;
i=1;
j=1;
printf("number of frames is %d ",noframes);
getch();
while(noframes>0)
{
printf("\nsending frames is %d",i);
x=rand()%10;
if(x%10==0)
{
for(x2=1;x2<2;x2++)
{
printf("\n waiting for %d seconds\n",x2);
sleep(x2);
}
printf("\n sending frames %d\n",i);
x=rand()%10;
}
printf("\n ack for frame %d\n",j);
noframes=noframes-1;
i++;
j++;
}
printf("\n end of stop and wait protocol\n");
}
Viva Question:
a. What is Stop-and-Wait Protocol?
b. What is Stop-and-Wait Automatic Repeat Request?
c. What is usage of Sequence Number in Relaible Transmission?
d. What Automatic Repeat Request (ARQ)?
Application:
a. Flow and error control
b. Modern file transfer protocol(FTP)
Experiment:12
Aim: Write a program for congestion control using leaky bucket algorithm.
The main concept of the leaky bucket algorithm is that the output data flow remains
constant despite the variant input traffic, such as the water flow in a bucket with a small hole at
the bottom. In case the bucket contains water (or packets) then the output flow follows a constant
rate, while if the bucket is full any additional load will be lost because of spillover. In a similar
way if the bucket is empty the output will be zero.From network perspective, leaky bucket
consists of a finite queue (bucket) where all the incoming packets are stored in case there is
space in the queue, otherwise the packets are discarded. In order to regulate the output flow,
leaky bucket transmits one packet from the queue in a fixed time (e.g. at every clock tick). In
the following figure we can notice the main rationale of leaky bucket algorithm, for both the two
approaches (e.g. leaky bucket with water (a) and with packets (b)).
While leaky bucket eliminates completely bursts traffic by regulating the incoming data
flow its main drawback is that it drops packets if the bucket is full. Also, it doesn’t take into
account the idle process of the sender which means that if the host doesn’t transmit data for some
time the bucket becomes empty without permitting the transmission of any packet.
include<stdio.h>
#include<stdlib.h>
#define MIN(x,y) (x>y)?y:x
int main()
{
intorate,drop=0,cap,x,count=0,inp[10]={0},i=0,nsec,ch;
printf("\n enter bucket size : ");
scanf("%d",&cap);
printf("\n enter output rate :");
scanf("%d",&orate);
do
{
printf("\n enter number of packets coming at second %d :",i+1);
scanf("%d",&inp[i]);
i++;
printf("\n enter 1 to contiue or 0 to quit..........");
scanf("%d",&ch);
}
while(ch);
nsec=i;
printf("\n second \t recieved \t sent \t dropped \t remained \n");
for(i=0;count || i<nsec;i++)
{
printf("%d",i+1);
printf(" \t%d\t ",inp[i]);
printf(" \t %d\t ",MIN((inp[i]+count),orate));
if((x=inp[i]+count-orate)>0)
{
if(x>cap)
{
count=cap;
drop=x-cap;
}
else
{
count=x;
drop=0;
}
}
else
{
drop=0;
count=0;
}
printf(" \t %d\t %d \n",drop,count);
}
Viva Question:
a. What are the types of errors?
b. What is Error Detection? What are its methods?
c. What is Redundancy?
e. Application:
a. Communication for maximum throughput function.
b. Congestion control
ADDON EXPERIMENTS
Experiment:13
#===================================
# Simulation parameters setup
#===================================
set val(stop) 55.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Nodes Definition
#===================================
#Create 8 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n3 100.0Mb 10ms DropTail
Dept of ECE, DBIT Page 66
COMPUTER NETWORKS LABORATORY 2023-2024
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null3 [new Agent/Null]
$ns attach-agent $n5 $null3
$ns connect $udp0 $null3
$udp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 50.0 "$cbr0 stop"
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
exec namqueue.nam&
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
Experiment:14
#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 2 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 849 ;# X dimension of topography
set val(y) 364 ;# Y dimension of topography
set val(stop) 51.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 2 nodes
set n0 [$ns node]
$n0 set X_ 506
$n0 set Y_ 262
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 749
$n1 set Y_ 264
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n1 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 50.0 "$ftp0 stop"
#=================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
exec nam 2nodewireless.nam &
exit 0
}
for {set i 0} {$i< $val(nn) } { incri } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
Experiment:15
Aim: classful addressing identification
An IPv4 address is a 32-bie address that uniquely and universally defines the Connection of a
deevice to the internet
IPv4 addresses are unique. They ar uniqu in the sence that each address defines one,and only
one,connection to the internet.Two dvics on the internet can never have the same address at the
same time. We well see later tht, by using some strategies,an address may be assigned to a dvic for
a time period and then taken away and assigned to another device
Addrss Space
A proctocol such as IPv4 that defins addresss has an address space. An address space is the total
number of addresses used by the protocol. If a protocol uses N bits todefin an address, the address
space is 2N beceuse ach bit can have two different values(0 or 1)and n bits can have 2N values
IPv4 uses 32- bit addresses, which means that the address space is 232 or 4,294,967,296.this means
that,theoretically, if there were no restriction ,more than 4 billions devices could be connected to
the enternet. We will see shortly that the actual number is much less because of the restriction
imposed on the addresses
Notations
There are two prevalent notations to shoe an IPv4 address:binary notation and dottd decimal notation
Binary Notations: in binary notation ,the IPv4 address is displayed as 32bits. Each octet is often referred
to as a byte. So it is common to hear an IPv4 address reffed to as a32- bit address or a 4-byte address. Th
following is aa example of an IPv4 address in binary notations:
01110101 10010101 00011101 00000010
Dotted -Decimal Notation: to make the IPv4 address more compact and easier to read. Interntet addresses
are usually written in decimal form with a decimal point separating the bytes. Th following is the dotted-
decimal notation of the above address
117.149.29.2
Classful Addressing
IPv4 addressing , at its inception, used the concept of classes. The architecture is called classful
addressing.although this scheme is becioming obsolete, w briefly discuss it here to show the rational
classless addressing.
In classful addressing, the address space is divided into five classes:A,B,C,D and E. Each class occupies
some part of the address space
#include <stdio.h>
#include <string.h>
void extractIpAddress(unsigned char *sourceString,short *ipAddress)
{
unsigned short len=0;
unsigned char oct[4]={0},cnt=0,cnt1=0,i,buf[5];
len=strlen(sourceString);
for(i=0;i<len;i++)
{
if(sourceString[i]!='.'){
buf[cnt++] =sourceString[i];
}
if(sourceString[i]=='.' || i==len-1){
buf[cnt]='\0';
cnt=0;
oct[cnt1++]=atoi(buf);
}
}
ipAddress[0]=oct[0];
ipAddress[1]=oct[1];
ipAddress[2]=oct[2];
ipAddress[3]=oct[3];
}
int main()
{
unsigned char ip[20]={0};
short ipAddress[4];
printf("Enter IP Address (xxx.xxx.xxx.xxx format): ");
scanf("%s",ip);
extractIpAddress(ip,&ipAddress[0]);
printf("\nIp Address: %03d. %03d. %03d. %03d\n",ipAddress[0],ipAddress[1],ipAddress[2],ipAddress[3]);
printf("Class B Ip Address.\n");
if(ipAddress[0]>191 && ipAddress[0]<224)
printf("Class C Ip Address.\n");
if(ipAddress[0]>224 && ipAddress[0]<=239)
printf("Class D Ip Address.\n");
if(ipAddress[0]>239)
printf("Class E Ip Address.\n");
return 0;
}
1. Define Network?
2. What is a Link?
3. What is a node?
4. What is a gateway or Router?
5. What is point-point link?
6. What is Multiple Access?
7. What are the advantages of Distributed Processing?
8. What are the criteria necessary for an effective and efficient network?
9. Name the factors that affect the performance of the network?
10. Name the factors that affect the reliability of the network?
11. Name the factors that affect the security of the network?
12. What is Protocol?
13. What are the key elements of protocols?
14. What are the key design issues of a computer Network?
15. Define Bandwidth and Latency?
16. Define Routing?
17. What is a peer-peer process?
18. When a switch is said to be congested?
19. What is semantic gap?
20. What is Round Trip Time?
21. Define the terms Unicasting, Multiccasting and Broadcasting?
22. What is Multiplexing?
23. Name the categories of Multiplexing?
24. What is FDM?
25. What is WDM?
26. What is TDM?
27. What is Synchronous TDM?
28. List the layers of OSI
29. Which layers are network support layers?
30. Which layers are user support layers?
31. Which layer links the network support layers and user support layers?
32. What are the concerns of the Physical Layer?
33. What are the responsibilities of Data Link Layer?
34. What are the responsibilities of Network Layer?
35. What are the responsibilities of Transport Layer?
36. What are the responsibilities of Session Layer?
37. What are the responsibilities of Presentation Layer?
38. What are the responsibilities of Application Layer?
39. What are the two classes of hardware building blocks?
40. What are the different link types used to build a computer network?
41. What are the categories of Transmission media?
42. What are the types of errors?
43. What is Error Detection? What are its methods?