The Data Link Layer
The Data Link Layer
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Data Link Layer Design Issues
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Packets and Frames
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Services provided to the Network Layer
The function of the data link layer is to provide services to the network layer.
The principal service is transferring data from the network layer on the
source machine to the network layer on the destination machine.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Framing Methods
• To provide service to the network layer, the data link layer
must use the service provided to it by the physical layer.
• The bit stream received by the data link layer is not
guaranteed to be error free.
• The usual approach is for the data link layer to break up
the bit stream into discrete frames, compute a short token
called a checksum for each frame, and include the
checksum in the frame when it is transmitted.
• The four framing methods are
1. Byte count.
2. Flag bytes with byte stuffing.
3. Flag bits with bit stuffing.
4. Physical layer coding violations.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Byte count
• This method uses a field in the header to specify the
number of bytes in the frame.
• When the data link layer at the destination sees the byte
count, it knows how many bytes follow and hence where
the end of the frame is.
• The trouble with this algorithm is that the count can be
garbled by a transmission error.
• Sending a frame back to the source asking for a
retransmission does not help either, since the destination
does not know how many bytes to skip over to get to the
start of the retransmission.
• For this reason, the byte count method is rarely used by
itself.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Byte Count
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Byte Stuffing
• This method gets around the problem of resynchronization after an
error by having each frame start and end with special bytes. Often the
same byte, called a flag byte, is used as both the starting and ending
delimiter.When the data link layer at the destination sees the byte
count, it knows how many bytes follow and hence where the end of the
frame is.
• Two consecutive flag bytes indicate the end of one frame and the start
of the next.
• It may happen that the flag byte occurs in the data, One way to solve
this problem is to have the sender’s data link layer insert a special
escape byte (ESC) just before each ‘‘accidental’’ flag byte in the data.
• The data link layer on the receiving end removes the escape bytes
before giving the data to the network layer. This technique is called
byte stuffing.
• It was developed for PPP(Point to Point Protocol)
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
a) A frame delimited by flag bytes.
b) Four examples of byte sequences before and after byte stuffing.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Bit Stuffing
• Byte stuffing is tied to the use of 8-bit bytes. Framing can
be also be done at the bit level.
• It was developed for the once very popular HDLC
(Highlevel Data Link Control) protocol.
• Each frame begins and ends with a special bit pattern,
01111110 or 0x7E in hexadecimal. This pattern is a flag
byte.
• Whenever the sender’s data link layer encounters five
consecutive 1s in the data, it automatically stuffs a 0 bit into
the outgoing bit stream.
• With both bit and byte stuffing, a side effect is that the
length of a frame now depends on the contents of the data
it carries.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Bit stuffing. (a) The original data. (b) The data as they appear on
the line. (c) The data as they are stored in the receiver’s memory after destuffing.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Physical layer coding violations.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Error Control
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Flow Control
• If the sender is running on a fast, powerful computer and
the receiver is running on a slow, low-end machine.(Fast
sender and slow receiver).
• Even if the transmission is error free, the receiver may be
unable to handle the frames as fast as they arrive and will
lose some.
• Two approaches are use to prevent this situation.
• Feedback-based flow control, the receiver sends back
information to the sender giving it permission to send more
data, or at least telling the sender how the receiver is
doing.
• Rate-based flow control, the protocol has a built-in
mechanism that limits the rate at which senders may
transmit data, without using feedback from the receiver.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Error Detection and Correction
• Network designers have developed two basic strategies for
dealing with errors. Both add redundant information to the
data that is sent.
• Error correcting codes(Forward Error Correction(FEC))
and error detecting code(retransmission takes place).
• On channels that are highly reliable, such as fiber, it is
cheaper to use an error-detecting code.
• FEC is used on noisy channels.
• Neither error-correcting codes nor error-detecting codes
can handle all possible errors since the redundant bits that
offer protection are as likely to be received in error as the
data bits
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Error Correcting Codes
1. Hamming codes.
2. Binary convolutional codes.
3. Reed-Solomon codes.
4. Low-Density Parity Check codes.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Hamming codes
• These codes add redundancy to the information that is
sent. A frame consists of m data (i.e., message) bits and r
redundant (i.e. check) bits.
• Let the total length of a block be n (i.e., n = m + r). We will
describe this as an (n,m) code. An n-bit unit containing
data and check bits is referred to as an n bit codeword.
• The code rate, or simply rate, is the fraction of the
codeword that carries information that is not redundant, or
m/n.
• The number of bit positions in which two codewords differ
is called the Hamming distance.
10001001
10110001
00111000
• Next discussion in notes
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Binary convolutional codes
• In a convolutional code, an encoder processes a sequence
of input bits and generates a sequence of output bits.
• There is no natural message size or encoding boundary as
in a block code.
• The output depends on the current and previous input bits.
That is, the encoder has memory.
• The number of previous bits on which the output depends
is called the constraint length of the code.
• Each input bit on the left-hand side produces two output
bits on the right-hand side that are XOR sums of the input
and internal state.
• Since it deals with bits and performs linear operations, this
is a binary, linear convolutional code. Since 1 input bit
produces 2 output bits, the code rate is 1/2. It is not
systematic since none of the output bits is simply the input
bit.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
The NASA binary convolutional code used in 802.11.
• The internal state is kept in six memory registers. Each time another
bit is input the values in the registers are shifted to the right.
• For example, if 111 is input and the initial state is all zeros, the
internal state, written left to right, will become 100000, 110000, and
111000 after the first, second, and third bits have been input. The
output bits will be 11, followed by 10, and then 01.
• Convolutional codes have been popular in practice because it is easy
to factor the uncertainty of a bit being a 0 or a 1 into the decoding.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Reed-Solomon codes
• Like Hamming codes, Reed-Solomon codes are linear
block codes, and they are often systematic too.
• Unlike Hamming codes, which operate on individual bits,
Reed-Solomon codes operate on m bit symbols.
• Reed-Solomon codes are based on the fact that every n
degree polynomial is uniquely determined by n + 1 points.
• . For example, a line having the form ax + b is determined
by two points. Extra points on the same line are redundant,
which is helpful for error correction.
• For m bit symbols, the codewords are 2m−1 symbols long.
A popular choice is to make m = 8 so that symbols are
bytes. A codeword is then 255 bytes long. The (255, 233)
code is widely used; it adds 32 redundant symbols to 233
data symbols.
• Reed-Solomon codes are widely used in practice because
of their strong error-correction properties, particularly for
burst errors.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Low Density Parity Check code
• LDPC codes are linear block codes.
• In an LDPC code, each output bit is formed from only a
fraction of the input bits. This leads to a matrix
representation of the code that has a low density of 1s,
hence the name for the code.
• The received codewords are decoded with an
approximation algorithm that iteratively improves on a best
fit of the received data to a legal codeword. This corrects
errors.
• LDPC codes are practical for large block sizes and have
excellent error-correction abilities that outperform many
other codes in practice.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Error-Detecting Codes
1. Parity.
2. Checksums.
3. Cyclic Redundancy Checks (CRCs).
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Error-Detecting Codes:Parity
• A single parity bit is appended to the data. The parity bit
is chosen so that the number of 1 bits in the codeword is
even (or odd).
• For example, when 1011010 is sent in even parity, a bit
is added to the end to make it 10110100. With odd parity
1011010 becomes 10110101.
• It can detect single-bit errors. If the block is badly garbled
by a long burst error, the probability that the error will be
detected is only 0.5, which is hardly acceptable.
• We can compute the parity bits over the data in a
different order than the order in which the data bits are
transmitted. Doing so is called interleaving.
• In this case, we will compute a parity bit for each of the n
columns and send all the data bits as k rows, sending the
rows from top to bottom and the bits in each row from left
to right in the usual manner. At the last row, we send the
n parity bits.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Interleaving of parity bits to detect a burst error.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Error-Detecting Codes: CRC
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
The algorithm for computing the CRC is as follows:
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Error-Detecting Codes (3)
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Elementary Data Link Protocols
The physical layer process and some of the data link layer process run on
dedicate hardware called a NIC (Network Interface Card). The rest of the
link layer process and the network layer process run on the main CPU as
part of the operating system, with the software for the link layer process
often taking the form of a device driver.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Elementary Data Link Protocols
...
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Utopian Simplex Protocol
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Utopian Simplex Protocol
...
A utopian simplex protocol.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Utopian Simplex Protocol
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Simplex Stop-and-Wait Protocol
for a Noisy Channel (1)
...
A simplex stop-and-wait protocol.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Simplex Stop-and-Wait Protocol
for a Noisy Channel (2)
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Sliding Window Protocol
• Using this protocol data frames were transmitted in both
the direction(Full duplex can be achieved)
• When a data frame arrives, instead of immediately
sending a separate control frame, the receiver restrains
itself and waits until the network layer passes it the next
packet.
• The technique of temporarily delaying outgoing
acknowledgements so that they can be hooked onto the
next outgoing data frame is known as piggybacking.
• The principal advantage of using piggybacking over
having distinct acknowledgement frames is a better use
of the available channel bandwidth.
• However, piggybacking introduces a complication,that
How long should the data link layer wait for a packet
onto which to piggyback the acknowledgement?
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
• The three protocols are bidirectional protocols that belong to a
class called sliding window protocols.
One bit sliding window protocol
Go back N sliding window protocol
Selective repeat sliding window protocol
• Sequence numbers range from 0 to 2n-1 for n-bit sequence
number.
• The sender maintains a set of sequence numbers corresponding
to frames it is permitted to send. These frames are said to fall
within the sending window.
• Similarly, the receiver also maintains a receiving window
corresponding to the set of frames it is permitted to accept.
• The sender’s window and the receiver’s window need not have the
same lower and upper limits or even have the same size. In some
protocols they are fixed in size, but in others they can grow or
shrink over the course of time as frames are sent and received.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
• The sequence numbers within the sender’s window
represent frames that have been sent or can be sent
but are as yet not acknowledged.
• Whenever a new packet arrives from the network layer,
it is given the next highest sequence number, and the
upper edge of the window is advanced by one.
• When an acknowledgement comes in, the lower edge is
advanced by one. In this way the window continuously
maintains a list of unacknowledged frames.
• The receiving data link layer’s window corresponds to
the frames it may accept. Any frame falling outside the
window is discarded.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
A sliding window of size 1, with a 3-bit sequence number.
(a) Initially. (b) After the first frame has been sent.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
A sliding window of size 1, with a 3-bit sequence number
(c) After the first frame has been received. (d) After the first
acknowledgement has been received.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
One-Bit Sliding Window Protocol
• A sliding window protocol with a window size of 1, uses stop-and-
wait since the sender transmits a frame and waits for its
acknowledgement before sending the next one.
• Under normal circumstances, one of the two data link layers goes
first and transmits the first frame.
• The starting machine fetches the first packet from its network layer,
builds a frame from it, and sends it. When this (or any) frame
arrives, the receiving data link layer checks to see if it is a
duplicate. If the frame is the one expected, it is passed to the
network layer and the receiver’s window is slid up.
• The acknowledgement field contains the number of the last frame
received without error.
• If this number agrees with the sequence number of the frame the
sender is trying to send, the sender knows it is done with the frame
stored in buffer and can fetch the next packet from its network
layer. If the sequence number disagrees, it must continue trying to
send the same frame. Whenever a frame is received, a frame is
also sent back.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Two scenarios for protocol 4. (a) Normal case. (b) Abnormal
case. The notation is (seq, ack, packet number). An asterisk indicates where a network
layer accepts a packet
In (b) half of the frames contain duplicates, even though there are no
transmission errors.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Protocol Using Go-Back-N
• Assume that the transmission time required for a frame to
arrive at the receiver plus the transmission time for the
acknowledgement to come back is long, The long round-trip
time can have important implications for the efficiency of the
bandwidth utilization.
• Basically, the solution lies in allowing the sender to transmit
up to w frames before blocking, instead of just 1.
• The need for a large window on the sender side occurs when
ever the bandwidth delay product is large.
• The product of these two factors tells the capacity of the pipe
and the sender needs the ability to fill it without stopping in
order to operate at peak efficiency. This technique is known
as pipelining.
• Pipelining frames over an unreliable communication channel
raises some serious issues.
• Two basic approaches are available for dealing with errors in
the presence of pipelining
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Protocol Using Go-Back-N
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Protocol Using Selective repeat
• A bad frame that is received is discarded, but any good
frames received after it are accepted and buffered.
When the sender times out, only the oldest
unacknowledged frame is retransmitted.
• If that frame arrives correctly, the receiver can deliver to
the network layer, in sequence, all the frames it has
buffered. Selective repeat corresponds to a receiver
window larger than 1.
• Selective repeat is often combined with having the
receiver send a negative acknowledgement (NAK) when
it detects an error, for example, when it receives a
checksum error or a frame out of sequence. NAKs
stimulate retransmission before the corresponding timer
expires and thus improve performance.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Pipelining and error recovery. Effect of an error when
(b) receiver’s window size is large.
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Protocol Using Selective Repeat
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Differences between goback n and
selective repeat
Operation
Window size
Acknowledgements
Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011