Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.

Categories: DCCN Lab. No Comments on DCCN lab program – To implement stop-and-wait protocol
0
(0)

Aim

To implement stop-and-wait protocol.

 

S/W required

NS2


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


 

Background information

Flow control

Flow control is a technique that allows two stations working at different speeds to communicate with each other. It is a set of measures taken to regulate the amount of data that a sender sends so that a fast sender does not overwhelm a slow receiver. In data link layer, flow control restricts the number of frames the sender can send before it waits for an acknowledgment from the receiver.

 

Flow control can be broadly classified into two categories:

  • Feedback based Flow Control: In these protocols, the sender sends frames after it has received acknowledgments from the user. This is used in the data link layer.
  • Rate based Flow Control: These protocols have built in mechanisms to restrict the rate of transmission of data without requiring acknowledgment from the receiver. This is used in the network layer and the transport layer.

 

Flow Control Techniques in Data Link Layer:

Data link layer uses feedback-based flow control mechanisms. There are two main techniques:

  1. Stop and Wait Protocol
  2. Sliding Window Protocol

 

Stop and wait protocol

It is the simplest flow control method. In this, the sender will send one frame at a time to the receiver. Until then, the sender will stop and wait for the acknowledgment from the receiver. When the sender gets the acknowledgment then it will send the next data packet to the receiver and wait for the acknowledgment again and this process will continue. This can be understood by the diagram below.

stop and wait protocol

Suppose if any frame sent is not received by the receiver and is lost. So the receiver will not send any acknowledgment as it has not received any frame. Also, the sender will not send the next frame as it will wait for the acknowledgment for the previous frame which it had sent. So, a deadlock situation can be created here. To avoid any such situation there is a time-out timer. The sender will wait for this fixed amount of time for the acknowledgment and if the acknowledgment is not received then it will send the frame again.

 

Disadvantages of Stop and Wait Protocol are:

  • We can send only one packet at a time.
  • If the distance between the sender and the receiver is large then the propagation delay would be more than the transmission delay. Hence, efficiency would become very low.
  • After every transmission, the sender has to wait for the acknowledgment and this time will increase the total transmission time.

 

Activity

Program

#Implmentation of Stop-and-wait protocol

#Create Simulator Object
set ns [new Simulator]

#Initialization code
set namfile [open out.nam w]
$ns namtrace-all $namfile

#Termination code
proc finish {} {
	global ns namfile
	$ns flush-trace
	close $namfile
	puts "Executing NAM..."
	exec nam out.nam &
	exit 0
}

#Creating nodes
set n1 [$ns node]
set n2 [$ns node]

#Assign labels to nodes
$ns at 0.0 "$n1 label Sender"
$ns at 0.0 "$n2 label Receiver"

#Creating links
$ns duplex-link $n1 $n2 10Mb 10ms DropTail

#Setting queue limit
$ns queue-limit $n1 $n2 10

#Creating TCP agent and TCP sink
set tcp [new Agent/TCP]
$ns attach-agent $n1 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $sink

#Connect TCP agent and TCP sink
$ns connect $tcp $sink

#Creating FTP application
set ftp [new Application/FTP]
$ftp attach-agent $tcp

#Setting TCP window size and congestion window size
#window_ is the upper bound on the advertised window for the TCP connection.
$tcp set window_ 1
#maxcwnd_ is the upper bound on the congestion window for the TCP connection.
$tcp set maxcwnd_ 1

#Set the location of node labels
$ns at 0.0 "$n1 label-at up"
$ns at 0.0 "$n1 color Red"
$ns at 0.0 "$n2 label-at up"
$ns at 0.0 "$n2 color Blue"

#Set the timing of events
$ns at 0.3 "$ftp start"
$ns at 2.8 "$ftp stop"
$ns at 3.0 "finish"

$ns run

 

Input and output

stop and wait protocol ns2 output

 

Result

Stop-and-wait protocol was understood and implemented successfully.

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

Leave a Reply

Your email address will not be published. Required fields are marked *