CH4 DCO
CH4 DCO
Chapter No: 4
Error Detection and Correction
Total Marks: 16
Teaching Hours: 10
Page 1 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
First Principle
The first principle dictates that if we want bidirectional communication, we need to make each layer so that it is
able to perform two opposite tasks, one in each direction.
For example, the third layer task is to listen (in one direction) and talk (in the other direction). The second layer
needs to be able to encrypt and decrypt. The first layer needs to send and receive mail. Refer figure 1.
Second Principle
The second principle that we need to follow in protocol layering is that the two objects under each layer at both
sites should be identical.
For example, the object under layer 3 at both sites should be a plaintext letter. The object under layer 2 at both
sites should be a cipher text letter. The object under layer 1 at both sites should be a piece of mail.
Layered Architecture
To show how the layers in the TCP/IP protocol suite are involved in communication between two hosts, we
assume that we want to use the suite in a small internet made up of three LANs (links), each with a link-layer
switch.
We also assume that the links are connected by one router, as shown in Figure 2.
Let us assume that computer A communicates with computer B.
As the figure shows, we have five communicating devices in this communication: source host (computer A), the
link-layer switch in link 1, the router, the link-layer switch in link 2, and the destination host (computer B).
Page 2 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Each device is involved with a set of layers depending on the role of the device in the internet.
The two hosts are involved in all five layers; the source host needs to create a message in the application layer
and send it down the layers so that it is physically sent to the destination host.
The destination host needs to receive the communication at the physical layer and then deliver it through the
other layers to the application layer.
Although a router is always involved in one network layer, it is involved in n combinations of link and physical
layers in which n is the number of links the router is connected to.
The reason is that each link may use its own data-link or physical protocol.
Established in 1947, the International Organization for Standardization (ISO) is a multinational body
dedicated to worldwide agreement on international standards.
Almost three-fourths of the countries in the world are represented in the ISO. An ISO standard that covers all
aspects of network communications is the Open Systems Interconnection (OSI) model. It was first introduced
in the late 1970s.
An open system is a set of protocols that allows any two different systems to communicate regardless of their
underlying architecture.
The purpose of the OSI model is to show how to facilitate communication between different systems without
requiring changes to the logic of the underlying hardware and software.
The OSI model is not a protocol; it is a model for understanding and designing a network architecture that is
flexible, robust, and interoperable.
The OSI model was intended to be the basis for the creation of the protocols in the OSI stack.
The OSI model is a layered framework for the design of network systems that allows communication between
all types of computer systems.
It consists of seven separate but related layers, each of which defines a part of the process of moving information
across a network (see Figure 3).
Page 4 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
The design issues have to do with making sure that when one side sends a 1 bit it is received by the other side
as a 1 bit, not as a 0 bit.
The physical layer is responsible for movements of individual bits from one hop (node) to the next.
Two devices are connected by a transmission medium (cable or air). We need to know that the transmission
medium does not carry bits; it carries electrical or optical signals.
So the bits received in a frame from the data-link layer are transformed and sent through the transmission media.
It does so by masking the real errors so the network layer does not see them.
It accomplishes this task by having the sender break up the input data into data frames (typically a few hundred
or a few thousand bytes) and transmit the frames sequentially.
If the service is reliable, the receiver confirms correct receipt of each frame by sending back an
acknowledgement frame.
Another issue that arises in the data link layer (and most of the higher layers as well) is how to keep a fast
transmitter from drowning a slow receiver in data.
Some traffic regulation mechanism may be needed to let the transmitter know when the receiver can accept
more data.
Broadcast networks have an additional issue in the data link layer: how to control access to the shared channel.
A special sub-layer of the data link layer, the medium access control sub-layer, deals with this problem.
Routes can be based on static tables that are ‘‘wired into’’ the network and rarely changed, or more often they
can be updated automatically to avoid failed components.
If too many packets are present in the subnet at the same time, they will get in one another’s way, forming
bottlenecks. Handling congestion is also a responsibility of the network layer,
Page 5 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Furthermore, all this must be done efficiently and in a way that isolates the upper layers from the inevitable
changes in the hardware technology over the course of time.
The transport layer also determines what type of service to provide to the session layer, and, ultimately, to the
users of the network.
The most popular type of transport connection is an error-free point-to-point channel that delivers messages or
bytes in the order in which they were sent.
The transport layer is a true end-to-end layer; it carries data all the way from the source to the destination.
In other words, a program on the source machine carries on a conversation with a similar program on the
destination machine, using the message headers and control messages.
Sessions offer various services, including dialog control (keeping track of whose turn it is to transmit), token
management (preventing two parties from attempting the same critical operation simultaneously), and
synchronization (check pointing long transmissions to allow them to pick up from where they left off in the event
of a crash and subsequent recovery).
In order to make it possible for computers with different internal data representations to communicate, the data
structures to be exchanged can be defined in an abstract way, along with a standard encoding to be used ‘‘on
the wire.’’
The presentation layer manages these abstract data structures and allows higher-level data structures (e.g.,
banking records) to be defined and exchanged.
One widely used application protocol is HTTP (Hyper Text Transfer Protocol), which is the basis for the World
Wide Web.
When a browser wants a Web page, it sends the name of the page it wants to the server hosting the page using
HTTP. The server then sends the page back.
Other application protocols are used for file transfer, electronic mail, and network news.
Page 6 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
ERROR CONTROL
Errors are introduced into the binary data transmitted from the sender to the receiver due to noise during
transmission.
When the information received at the receiver end does not match the sent data. At the time of transmission,
errors are introduced into the binary data sent from the sender to the receiver due to noise during transmission.
This means that a bit having a 0 value can change to 1 and a bit having a 1 value can change to 0.
Types of Errors:
➢ single-bit error
➢ burst error
Whenever bits flow from one point to another, they are subject to unpredictable changes because of
interference. This interference can change the shape of the signal.
The term single-bit error means that only 1 bit of a given data unit is changed from 1 to 0 or from 0
to 1. The term burst error means that 2 or more bits in the data unit have changed from 1 to 0 or
from 0 to 1.
Figure 4 shows the effect of a single-bit and a burst error on a data unit.
A burst error is more likely to occur than a single-bit error because the duration of the noise signal is
normally longer than the duration of 1 bit, which means that when noise affects data, it affects a set
of bits.
The number of bits affected depends on the data rate and duration of noise. For example, if we are
sending data at 1 kbps, a noise of 1/100 second can affect 10 bits; if we are sending data at 1 Mbps,
the same noise can affect 10,000 bits.
Redundancy
The central concept in detecting or correcting errors is redundancy. To be able to detect or correct
errors, we need to send some extra bits with our data.
These redundant bits are added by the sender and removed by the receiver. Their presence allows the
receiver to detect or correct corrupted bits.
Page 7 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
In error correction, we need to know the exact number of bits that are corrupted and, more
importantly, their location in the message. The number of errors and the size of the message are
important factors.
However, retransmission of corrupted and lost packets is not useful for real-time multimedia
transmission because it creates an unacceptable delay in reproducing: we need to wait until the lost
or corrupted packet is resent.
We need to correct the error or reproduce the packet immediately. Several schemes have been
designed and used in this case that are collectively referred to as forward error correction (FEC)
techniques. We briefly discuss some of the common techniques here.
BLOCK CODING
In block coding, we divide our message into blocks, each of k bits, called datawords.
We add r redundant bits to each block to make the length n =k + r. The resulting n-bit blocks are
called codewords.
It is important to know that we have a set of datawords, each of size k, and a set of codewords, each
of size of n.
With k bits, we can create a combination of 2k datawords; with n bits, we can create a combination of
2n codewords.
Since n > k, the number of possible codewords is larger than the number of possible datawords.
Error Detection
How can errors be detected by using block coding? If the following two conditions are met, the
receiver can detect a change in the original codeword.
Page 8 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Figure 5 shows the role of block coding in error detection. The sender creates codewords out of
datawords by using a generator that applies the rules and procedures of encoding.
If the received codeword is the same as one of the valid codewords, the word is accepted; the
corresponding dataword is extracted for use.
If the received codeword is not valid, it is discarded. However, if the codeword is corrupted during
transmission but the received word still matches a valid codeword, the error remains undetected.
Example 1
Let us assume that k =2 and n=3. Table 1 shows the list of datawords and codewords. Later, we will
see how to derive a codeword from a dataword.
Assume the sender encodes the dataword 01 as 011 and sends it to the receiver. Consider the following
cases:
1. The receiver receives 011. It is a valid codeword. The receiver extracts the dataword 01 from it.
2. The codeword is corrupted during transmission, and 111 is received (the leftmost bit is corrupted).
This is not a valid codeword and is discarded.
3. The codeword is corrupted during transmission, and 000 is received (the right two bits are
corrupted). This is a valid codeword. The receiver incorrectly extracts the dataword 00.
Page 9 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
“An error-detecting code can detect only the types of errors for which it is designed; other
types of errors may remain undetected.”
The use of nonlinear block codes for error detection and correction is not as widespread because their
structure makes theoretical analysis and implementation difficult.
A linear block code is a code in which the exclusive OR (addition modulo-2) of two valid codewords
creates another valid codeword.
Example 2
The code in Table 1 is a linear block code because the result of XORing any codeword with any other
codeword is a valid codeword. For example, the XORing of the second and third codewords creates
the fourth one.
Parity-Check Code
Perhaps the most familiar error-detecting code is the parity-check code. This code is a linear block
code. In this code, a k-bit dataword is changed to an n-bit codeword where n = k + 1.
The extra bit, called the parity bit, is selected to make the total number of 1s in the codeword even.
Although some implementations specify an odd number of 1s, we discuss the even case.
Here the right most bit with light blue colour is parity bit chosen to set even parity.
Page 10 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Let’s take the first dataword are four zeros (0000) and codeword for the same is five zeros (00000)
the last bit i.e. parity bit is selected 0 to satisfy even parity condition.
If we set parity bit 1 it will not satisfy even parity and the generated codeword is wrong likewise you
can check all the code word whether it is correct codeword or not.
CYCLIC CODES
Cyclic codes are special linear block codes with one extra property. In a cyclic code, if a codeword is
cyclically shifted (rotated), the result is another codeword.
For example, if 1011000 is a codeword and we cyclically left-shift, then 0110001 is also a codeword.
In this case, if we call the bits in the first word a0 to a6, and the bits in the second word b0 to b6, we
can shift the bits by using the following:
In the rightmost equation, the last bit of the first word is wrapped around and becomes the first bit of
the second word.
We can create cyclic codes to correct errors. Here we simply discuss a subset of cyclic codes called
the cyclic redundancy check (CRC), which is used in networks such as LANs and WANs.
Table 3 shows an example of a CRC code. We can see both the linear and cyclic properties of this
code.
Figure 6 shows one possible design for the encoder and decoder.
Page 11 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
In the encoder, the dataword has k bits (4 here); the codeword has n bits (7 here). The size of the
dataword is augmented by adding n − k (3 here) 0s to the right-hand side of the word.
The n-bit result is fed into the generator. The generator uses a divisor of size n − k + 1 (4 here),
predefined and agreed upon. The generator divides the augmented dataword by the divisor (modulo-
2 division).
The quotient of the division is discarded; the remainder (r2r1r0) is appended to the dataword to create
the codeword.
The decoder receives the codeword (possibly corrupted in transition). A copy of all n bits is fed to the
checker, which is a replica of the generator.
The remainder produced by the checker is a syndrome of n − k (3 here) bits, which is fed to the
decision logic analyser.
The analyser has a simple function. If the syndrome bits are all 0s, the 4 leftmost bits of the codeword
are accepted as the dataword (interpreted as no error); otherwise, the 4 bits are discarded (error).
Encoder
Let us take a closer look at the encoder. The encoder takes a dataword and augments it with n − k
number of 0s. It then divides the augmented dataword by the divisor, as shown in Figure 7.
Page 12 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
The process of modulo-2 binary division is the same as the familiar division process we use for
decimal numbers.
As in decimal division, the process is done step by step. In each step, a copy of the divisor is XORed
with the 4 bits of the dividend.
The result of the XOR operation (remainder) is 3 bits (in this case), which is used for the next step
after 1 extra bit is pulled down to make it 4 bits long.
There is one important point we need to remember in this type of division. If the leftmost bit of the
dividend (or the part used in each step) is 0, the step cannot use the regular divisor; we need to use an
all-0s divisor.
When there are no bits left to pull down, we have a result. The 3-bit remainder forms the check bits
(r2, r1, and r0). They are appended to the dataword to create the codeword.
Decoder
The codeword can change during transmission. The decoder does the same division process as the
encoder. The remainder of the division is the syndrome.
If the syndrome is all 0s, there is no error with a high probability; the dataword is separated from the
received codeword and accepted. Otherwise, everything is discarded.
Page 13 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Figure 8 shows two cases: The left-hand figure shows the value of the syndrome when no error has
occurred; the syndrome is 000. The right-hand part of the figure shows the case in which there is a
single error. The syndrome is not all 0s (it is 011).
Polynomials
A pattern of 0s and 1s can be represented as a polynomial with coefficients of 0 and 1. The power of
each term shows the position of the bit; the coefficient shows the value of the bit.
Figure 9 shows a binary pattern and its polynomial representation. In Figure 9a we show how to
translate a binary pattern into a polynomial; in Figure 9b we show how the polynomial can be
shortened by removing all terms with zero coefficients and replacing x1 by x and x0 by 1.
Page 14 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
We have seen that cyclic codes have a very good performance in detecting single-bit errors, double
errors, an odd number of errors, and burst errors.
They can easily be implemented in hardware and software. They are especially fast when
implemented in hardware.
This has made cyclic codes a good candidate for many networks.
CHECKSUM
Checksum is an error-detecting technique that can be applied to a message of any length. In the
Internet, the checksum technique is mostly used at the network and transport layer rather than the
data-link layer.
At the source, the message is first divided into m-bit units. The generator then creates an extra m-bit
unit called the checksum, which is sent with the message.
At the destination, the checker creates a new checksum from the combination of the message and sent
checksum.
If the new checksum is all 0s, the message is accepted; otherwise, the message is discarded (Figure
10).
Note that in the real implementation, the checksum unit is not necessarily added at the end of the
message; it can be inserted in the middle of the message.
Page 15 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
EXAMPLS ON CHECKSUM:
Example-1:
Framing
Data transmission in the physical layer means moving bits in the form of a signal from the source to
the destination.
The physical layer provides bit synchronization to ensure that the sender and receiver use the same
bit durations and timing.
The data-link layer, on the other hand, needs to pack bits into frames, so that each frame is
distinguishable from another. Our postal system practices a type of framing.
The simple act of inserting a letter into an envelope separates one piece of information from another;
the envelope serves as the delimiter. In addition, each envelope defines the sender and receiver
addresses, which is necessary since the postal system is a many-to-many carrier facility.
Page 16 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Framing in the data-link layer separates a message from one source to a destination by adding a
sender address and a destination address. The destination address defines where the packet is to go;
the sender address helps the recipient acknowledge the receipt.
When a message is carried in one very large frame, even a single-bit error would require the
retransmission of the whole frame. When a message is divided into smaller frames, a single-bit error
affects only that small frame.
Frame Size
Frames can be of fixed or variable size. In fixed-size framing, there is no need for defining the
boundaries of the frames; the size itself can be used as a delimiter. An example of this type of framing
is the ATM WAN, which uses frames of fixed size called cells.
Our main discussion in this topic is concerns variable-size framing, prevalent in local-area networks.
In variable-size framing, we need a way to define the end of one frame and the beginning of the next.
Historically, two approaches were used for this purpose: a character-oriented approach and a bit-
oriented approach.
Flow Control
Whenever an entity produces items and another entity consumes them, there should be a balance
between production and consumption rates. If the items are produced faster than they can be
consumed, the consumer can be overwhelmed and may need to discard some items.
If the items are produced more slowly than they can be consumed, the consumer must wait, and the
system becomes less efficient. Flow control is related to the first issue. We need to prevent losing the
data items at the consumer site.
In communication at the data-link layer, we are dealing with four entities: network and data-link layers
at the sending node and network and data-link layers at the receiving node.
Although we can have a complex relationship with more than one producer and consumer, we ignore
the relationships between networks and data-link layers and concentrate on the relationship between
two data-link layers, as shown in Figure 11.
Page 17 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
The figure 11 shows that the data-link layer at the sending node tries to push frames toward the data-
link layer at the receiving node.
If the receiving node cannot process and deliver the packet to its network at the same rate that the
frames arrive, it becomes overwhelmed with frames. Flow control in this case can be feedback from
the receiving node to the sending node to stop or slow down pushing frames.
Buffers
Although flow control can be implemented in several ways, one of the solutions is normally to use
two buffers; one at the sending data-link layer and the other at the receiving data-link layer.
A buffer is a set of memory locations that can hold packets at the sender and receiver.
The flow control communication can occur by sending signals from the consumer to the producer.
When the buffer of the receiving data-link layer is full, it informs the sending data-link layer to stop
pushing frames.
Error Control
Since the underlying technology at the physical layer is not fully reliable, we need to implement error
control at the data-link layer to prevent the receiving node from delivering corrupted packets to its
network layer.
Error control at the data-link layer is normally very simple and implemented using one of the
following two methods. In both methods, a CRC is added to the frame header by the sender and
checked by the receiver.
❑ In the first method, if the frame is corrupted, it is silently discarded; if it is not corrupted, the packet
is delivered to the network layer. This method is used mostly in wired LANs such as Ethernet.
❑ In the second method, if the frame is corrupted, it is silently discarded; if it is not corrupted, an
acknowledgment is sent (for the purpose of both flow and error control) to the sender.
Flow and error control can be combined. In a simple situation, the acknowledgment that is sent for
flow control can also be used for error control to tell the sender the packet has arrived uncorrupted.
The lack of acknowledgment means that there is a problem in the sent frame.
A frame that carries an acknowledgment is normally called an ACK to distinguish it from the data
frame.
Page 18 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Stop-and-Wait,
Go-Back-N, and
Selective-Repeat.
The behaviour of a data-link-layer protocol can be better shown as a finite state machine (FSM). An
FSM is thought of as a machine with a finite number of states.
The machine is always in one of the states until an event occurs. Each event is associated with two
reactions: defining the list of actions to be performed and determining the next state.
One of the states must be defined as the initial state, the state in which the machine starts when it turns
on.
In this protocol, the sender sends one frame at a time and waits for an acknowledgment before sending
the next one. To detect corrupted frames, we need to add a CRC to each data frame. When a frame
arrives at the receiver site, it is checked.
If its CRC is incorrect, the frame is corrupted and silently discarded. The silence of the receiver is a
signal for the sender that a frame was either corrupted or lost.
Every time the sender sends a frame, it starts a timer. If an acknowledgment arrives before the timer
expires, the timer is stopped and the sender sends the next frame (if it has one to send).
If the timer expires, the sender resends the previous frame, assuming that the frame was either lost or
corrupted. This means that the sender needs to keep a copy of the frame until its acknowledgment
arrives.
When the corresponding acknowledgment arrives, the sender discards the copy and sends the next
frame if it is ready.
Figure 12 shows the outline for the Stop-and-Wait protocol. Note that only one frame and one
acknowledgment can be in the channels at any time.
Page 19 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Figure 13: shows the FSMs for our primitive Stop-and-Wait protocol.
Sender States
The sender is initially in the ready state, but it can move between the ready and blocking state.
❑ Ready State. When the sender is in this state, it is only waiting for a packet from the network
layer. If a packet comes from the network layer, the sender creates a frame, saves a copy of the frame,
starts the only timer and sends the frame. The sender then moves to the blocking state.
❑ Blocking State. When the sender is in this state, three events can occur:
a. If a time-out occurs, the sender resends the saved copy of the frame and restarts the timer.
Page 20 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
b. If a corrupted ACK arrives, it is discarded.
c. If an error-free ACK arrives, the sender stops the timer and discards the saved copy of the frame.
It then moves to the ready state.
Receiver
The receiver is always in the ready state. Two events may occur:
a. If an error-free frame arrives, the message in the frame is delivered to the network layer and an
ACK is sent.
b. If a corrupted frame arrives, the frame is discarded.
Now let us consider the normal situation of a communication channel that makes errors. Frames may
be either damaged or lost completely. However, we assume that if a frame is damaged in transit, the
receiver hardware will detect this when it computes the checksum.
If the frame is damaged in such a way that the checksum is nevertheless correct—an unlikely
occurrence—this protocol (and all other protocols) can fail (i.e., deliver an incorrect packet to the
network layer).
At first glance it might seem that a variation of protocol 2 would work: adding a timer. The sender
could send a frame, but the receiver would only send an acknowledgement frame if the data were
correctly received. If a damaged frame arrived at the receiver, it would be discarded.
After a while the sender would time out and send the frame again. This process would be repeated
until the frame finally arrived intact.
This scheme has a fatal flaw in it though. Think about the problem and try to discover what might go
wrong before reading further.
To see what might go wrong, remember that the goal of the data link layer is to provide error-free,
transparent communication between network layer processes.
The network layer on machine A gives a series of packets to its data link layer, which must ensure
that an identical series of packets is delivered to the network layer on machine B by its data link layer.
In particular, the network layer on B has no way of knowing that a packet has been lost or duplicated,
so the data link layer must guarantee that no combination of transmission errors, however unlikely,
can cause a duplicate packet to be delivered to a network layer.
Page 21 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Example 1
Figure 14 shows an example. The first frame is sent and acknowledged. The second frame is sent, but
lost. After time-out, it is resent. The third frame is sent and acknowledged, but the acknowledgment
is lost. The frame is resent. However, there is a problem with this scheme.
The network layer at the receiver site receives two copies of the third packet, which is not right. In
the next section, we will see how we can correct this problem using sequence numbers and
acknowledgment numbers.
When a frame containing the correct sequence number arrives, it is accepted and passed to the network
layer, then acknowledged.
Then the expected sequence number is incremented modulo 2 (i.e., 0 becomes 1 and 1 becomes 0).
Any arriving frame containing the wrong sequence number is rejected as a duplicate.
Page 22 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Protocols in which the sender waits for a positive acknowledgement before advancing to the next data
item are often called ARQ (Automatic Repeat reQuest) or PAR (Positive Acknowledgement with
Retransmission).
We saw a problem in Example 1 that needs to be addressed and corrected. Duplicate packets, as much
as corrupted packets, need to be avoided.
If each packet defines the specification of an item to be ordered, duplicate packets mean ordering an
item more than once.
To correct the problem in Example 11.3, we need to add sequence numbers to the data frames and
acknowledgment numbers to the ACK frames.
However, numbering in this case is very simple. Sequence numbers are 0, 1, 0, 1, 0, 1, ….; the
acknowledgment numbers can also be 1, 0, 1, 0, 1, 0, …
In other words, the sequence numbers start with 0, the acknowledgment numbers start with 1. An
acknowledgment number always defines the sequence number of the next frame to receive.
Example 2
Figure 15 shows how adding sequence numbers and acknowledgment numbers can prevent
duplicates. The first frame is sent and acknowledged. The second frame is sent, but lost.
After time-out, it is resent. The third frame is sent and acknowledged, but the acknowledgment is lost.
The frame is resent.
Page 23 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Efficiency
The Stop-and-Wait protocol is very inefficient if our channel is thick and long. By thick, we mean
that our channel has a large bandwidth (high data rate); by long, we mean the round-trip delay is
long.
The product of these two is called the bandwidth delay product. We can think of the channel as a
pipe. The bandwidth-delay product then is the volume of the pipe in bits.
It is not efficient if it is not used. The bandwidth-delay product is a measure of the number of bits a
sender can transmit through the system while waiting for an acknowledgment from the receiver.
Page 24 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
At the sender site, when a packet is sent, the corresponding slice is marked. When all the slices are
marked, it means that the buffer is full and no further messages can be accepted from the application
layer.
When an acknowledgment arrives, the corresponding slice is unmarked. If some consecutive slices
from the beginning of the window are unmarked, the window slides over the range of the
corresponding sequence numbers to allow more free slices at the end of the window.
The sequence numbers are in modulo 16 (m = 4) and the size of the window is 7. Note that the sliding
window is just an abstraction: the actual situation uses computer variables to hold the sequence
numbers of the next packet to be sent and the last packet sent.
Figure 17 shows this representation. Both representations tell us the same thing.
Page 25 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Pipelining
In networking and in other areas, a task is often begun before the previous task has ended. This is
known as pipelining.
There is no pipelining in the Stop-and-Wait protocol because a sender must wait for a packet to reach
the destination and be acknowledged before the next packet can be sent.
However, pipelining does apply to our next two protocols because several packets can be sent before
a sender receives feedback about the previous packets.
Pipelining improves the efficiency of the transmission if the number of bits in transition is large with
respect to the bandwidth delay product.
In other words, we need to let more than one packet be outstanding to keep the channel busy while
the sender is waiting for acknowledgment.
It is called Go-Back-N (GBN) (the rationale for the name will become clear later).
The key to Go-back-N is that we can send several packets before receiving acknowledgments, but the
receiver can only buffer one packet. We keep a copy of the sent packets until the acknowledgments
arrive.
Sequence Numbers
The sequence numbers are modulo 2m, where m is the size of the sequence number field in bits.
Acknowledgment Numbers
An acknowledgment number in this protocol is cumulative and defines the sequence number of the
next packet expected.
Page 26 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
For example, if the acknowledgment number (ackNo) is 7, it means all packets with sequence number
up to 6 have arrived, safe and sound, and the receiver is expecting the packet with sequence number
7.
“In the Go-Back-N protocol, the acknowledgment number is cumulative and defines the
sequence number of the next packet expected to arrive.”
Send Window
The send window is an imaginary box covering the sequence numbers of the data packets that can be
in transit or can be sent.
In each window position, some of these sequence numbers define the packets that have been sent;
others define those that can be sent. The maximum size of the window is 2m − 1.
The sender does not worry about these packets and keeps no copies of them. The second region,
colored (coloured), defines the range of sequence numbers belonging to the packets that have been
sent, but have an unknown status.
The sender needs to wait to find out if these packets have been received or were lost. We call these
outstanding packets.
The third range, white in the figure, defines the range of sequence numbers for packets that can be
sent; however, the corresponding data have not yet been received from the application layer.
Finally, the fourth region, right of the window, defines sequence numbers that cannot be used until
the window slides.
Page 27 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
The window itself is an abstraction; three variables define its size and location at any time. We call
these variables Sf (send window, the first outstanding packet), Sn (send window, the next packet to be
sent), and Ssize (send window, size).
The variable Sf defines the sequence number of the first (oldest) outstanding packet. The variable Sn
holds the sequence number that will be assigned to the next packet to be sent.
Finally, the variable Ssize defines the size of the window, which is fixed in our protocol.
The send window is an abstract concept defining an imaginary box of maximum size = 2m − 1
with three variables: Sf, Sn, and Ssize.
Figure 19 shows how a send window can slide one or more slots to the right when an acknowledgment
arrives from the other end.
In the figure, an acknowledgment with ackNo = 6 has arrived. This means that the receiver is waiting
for packets with sequence number 6.
“The send window can slide one or more slots when an error-free ACK with ackNo greater
than or equal to Sf and less than Sn (in modular arithmetic) arrives.”
Receive Window
The receive window makes sure that the correct data packets are received and that the correct
acknowledgments are sent.
In Go-Back-N, the size of the receive window is always 1. The receiver is always looking for the
arrival of a specific packet. Any packet arriving out of order is discarded and needs to be resent.
Figure 20 shows the receive window. Note that we need only one variable, Rn (receive window, next
packet expected), to define this abstraction.
Page 28 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
The sequence numbers to the left of the window belong to the packets already received and
acknowledged; the sequence numbers to the right of this window define the packets that cannot be
received.
Any received packet with a sequence number in these two regions is discarded. Only a packet with a
sequence number matching the value of Rn is accepted and acknowledged.
The receive window also slides, but only one slot at a time. When a correct packet is received, the
window slides, Rn = (Rn + 1) modulo 2m.
Timers
Although there can be a timer for each packet that is sent, in our protocol we use only one. The reason
is that the timer for the first outstanding packet always expires first. We resend all outstanding packets
when this timer expires.
When the timer expires, the sender resends all outstanding packets.
For example, suppose the sender has already sent packet 6 (Sn = 7), but the only timer expires. If Sf
= 3, this means that packets 3, 4, 5, and 6 have not been acknowledged; the sender goes back and
resends packets 3, 4, 5, and 6. That is why the protocol is called Go-Back-N. On a time-out, the
machine goes back N locations and resends all packets.
As an example, we choose m = 2, which means the size of the window can be 2m − 1, or 3. Figure 21
compares a window size of 3 against a window size of 4.
Page 29 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
If the size of the window is 3 (less than 2m) and all three acknowledgments are lost, the only timer
expires and all three packets are resent. The receiver is now expecting packet 3, not packet 0, so the
duplicate packet is correctly discarded.
On the other hand, if the size of the window is 4 (equal to 22) and all acknowledgments are lost, the
sender will send a duplicate of packet 0.
However, this time the window of the receiver expects to receive packet 0 (in the next cycle), so it
accepts packet 0, not as a duplicate, but as the first packet in the next cycle.
This is an error. This shows that the size of the send window must be less than 2m.
However, this protocol is inefficient if the underlying network protocol loses a lot of packets.
Page 30 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Need
Each time a single packet is lost or corrupted, the sender resends all outstanding packets, even though
some of these packets may have been received safe and sound but out of order.
If the network layer is losing many packets because of congestion in the network, the resending of all
of these outstanding packets makes the congestion worse, and eventually more packets are lost.
This has an avalanche effect that may result in the total collapse of the network.
Another protocol, called the Selective-Repeat (SR) protocol, has been devised, which, as the name
implies, resends only selective packets, those that are actually lost.
The Selective-Repeat protocol also uses two windows: a send window and a receive window.
However, there are differences between the windows in this protocol and the ones in Go-Back-N.
First, the maximum size of the send window is much smaller; it is 2m−1. Second, the receive window
is the same size as the send window.
The send window maximum size can be 2m−1. For example, if m = 4, the sequence numbers go from
0 to 15, but the maximum size of the window is just 8 (it is 15 in the Go-Back-N Protocol).
The Selective-Repeat protocol allows as many packets as the size of the receive window to arrive out
of order and be kept until there is a set of consecutive packets to be delivered to the application layer.
Because the sizes of the send window and receive window are the same, all the packets in the send
packet can arrive out of order and be stored until they can be delivered.
We need, however, to emphasize that in a reliable protocol the receiver never delivers packets out of
order to the application layer.
Page 31 of 32
S.Y. DIPLOMA_IT-3I_DCO – 22322 CH-04
Figure 23 shows the receive window in Selective-Repeat. Those slots inside the window that are
shaded define packets that have arrived out of order and are waiting for the earlier transmitted packet
to arrive before delivery to the application layer.
Acknowledgments
There is yet another difference between the two protocols. In GBN an ackNo is cumulative; it defines
the sequence number of the next packet expected, confirming that all previous packets have been
received safe and sound.
The semantics of acknowledgment is different in SR. In SR, an ackNo defines the sequence number
of a single packet that is received safe and sound; there is no feedback for any other.
“In the Selective-Repeat protocol, an acknowledgment number defines the sequence number
of the error-free packet received.”
Page 32 of 32