Mod2.Data Link Layer - 1
Mod2.Data Link Layer - 1
Module2
Data Link Layer Design Issues/Functionalities
of DLL
• Services Provided to the Network Layer
• Framing
• Error Control
• Flow Control
2
Functions of the Data Link Layer
• To accomplish the above goals DLL takes the packets it gets
from the network layer and encapsulates them into frames for
transmission.
3
Relationship between packets and frames.
4
Services provided to the Network Layer
5
Services provided to the Network Layer
The job of the data link layer is to transmit the bits to the
destination machine so they can be handed over to the network
layer there,
Virtual Communication
6
Services provided to the Network Layer
Actual Communication.
7
Services provided to the Network Layer
8
Framing
• Data-link layer takes the packets from the Network Layer and
encapsulates them into frames.
• Process of breaking down a stream of bits into smaller, manageable
units called frames is known as Framing
• To provide service to the network layer, the data link layer must use
the service provided to it by the physical layer.
• What the physical layer does is accept a raw bit stream and attempt
to deliver it to the destination.
• This bit stream is not guaranteed to be error free.
Framing
• The number of bits received may be less than, equal to, or more than
the number of bits transmitted, and they may have different values.
• It is up to the data link layer to detect and, if necessary, correct errors.
• The usual approach is for the data link layer to break the bit stream
up into discrete frames and compute the checksum for each frame.
• When a frame arrives at the destination, the checksum is
recomputed.
• If the newly-computed checksum is different from the one contained
in the frame, the data link layer knows that an error has occurred and
takes steps to deal with it (e.g., discarding the bad frame and possibly
also sending back an error report).
Framing- Types
1. Fixed-sized Framing
2. Variable – Sized Framing
Fixed-sized Framing
• Here the size of the frame is fixed and so the frame length acts as delimiter of
the frame.
• Consequently, it does not require additional boundary bits to identify the
start and end of the frame.
Framing- Types
• Variable – Sized Framing
• Here, the size of each frame to be transmitted may be different.
• So additional mechanisms are kept to mark the end of one frame and the
beginning of the next frame.
• One way to achieve this framing is to insert time gaps between frames, much
like the spaces between words in ordinary text.
• However, networks rarely make any guarantees about timing, so it is possible
these gaps might be squeezed out or other gaps might be inserted during
transmission.
Methods of Framing
1. Character count.
2. Flag bytes with byte stuffing.
3. Starting and ending flags, with bit stuffing.
4. Physical layer coding violations.
1. Character count.
Without errors
Character count
• The trouble with this method is that the count can be garbled by a
transmission error.
• For example, if the character count of 5 becomes a 7, the destination
will get out of synchronization and will be unable to locate the start of
the next frame
• For this reason, the character count method is rarely used anymore.
2.Flag bytes with byte stuffing
• if the receiver ever loses synchronization, it can just search for the
flag byte to find the end of the current frame.
• Two consecutive flag bytes indicate the end of one frame and start of
the next one.
Flag bytes with byte stuffing
• A serious problem occurs with this method when binary data, such as
object programs or floating-point numbers, are being transmitted.
• It may easily happen that the flag byte's bit pattern occurs in the data.
• This situation will usually interfere with the framing.
• 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 byte
before the data are given to the network layer.
• This technique is called byte stuffing or character stuffing.
• Thus, a framing flag byte can be distinguished from one in the data
by the absence or presence of an escape byte before it.
Four examples of byte sequences before and after
stuffing.
Framing
21
3.Starting and ending flags, with bit stuffing
• When the receiver sees five consecutive incoming 1 bits, followed by a 0 bit,
it automatically destuffs (i.e., deletes) the 0 bit.
• Just as byte stuffing is completely transparent to the network layer in both
computers.
• With bit stuffing, the boundary between two frames can be unambiguously
recognized by the flag pattern.
• Thus, if the receiver loses track of where it is, all it has to do is scan the input
for flag sequences,
• since they can only occur at frame boundaries and never within the data
Starting and ending flags, with bit stuffing-Example
• (c) The data as they are stored in the receiver's memory after
destuffing
4.Physical layer coding violations
• only applicable to networks in which the encoding on the
physical medium contains some redundancy
• Eg: some LANs encode 1 bit of data by using 2 physical bits.
• Normally, a 1 bit is a high-low pair and a 0 bit is a low-high
pair.
• The scheme means that every data bit has a transition in the
middle, making it easy for the receiver to locate the bit
boundaries.
• The combinations high-high and low-low are not used for
data but are used for delimiting frames in some protocols
25
Error Control
• To make sure all frames are eventually delivered to the
network layer at the destination and in the proper order
• The usual way to ensure reliable delivery is to provide the
sender with some feedback about what is happening at the
other end of the line
• For reliable delivery, protocol calls for the receiver to send back
special control frames bearing positive or negative
acknowledgements about the incoming frames
• If the sender receives a positive acknowledgement about a
frame, it knows the frame has arrived safely.
• On the other hand, a negative acknowledgement means that
something has gone wrong, and the frame must be
transmitted again 26
Error Control
• Problem:
• hardware troubles may cause a frame to vanish completely
• In this case, the receiver will not react at all, since it has no
reason to react.
• Thus sender transmits a frame and then waits for an
acknowledgement, positive or negative, will hang forever if a
frame is ever lost
• Solution:
• by introducing timers into the DLL
27
Error Control
29
Flow Control
• Mechanisms used to prevent a fast sender from
overloading a slow receiver with data
• This situation occurs when the sender is running on a fast
(or lightly loaded) computer and the receiver is running
on a slow (or heavily loaded) machine.
• The sender keeps pumping the frames out at a high rate
until the receiver is completely swamped.
• Even if the transmission is error free, at a certain point
the receiver will simply be unable to handle the frames as
they arrive and will start to lose some
• Two approaches
• feedback-based flow control
• rate-based flow control 30
Flow Control
• 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
• The protocol contains well-defined rules about
when a sender may transmit the next frame
31
Problems
Given the output after byte-stuffing: FLAG A B ESC ESC C ESC ESC ESC
FLAG ESC FLAG D F FLAG. What is the original data?
solution
ANS: A B ESC C ESC FLAG FLAG D F
Question
The following character encoding is used in a data link protocol: A:
01000111; B: 11100011; FLAG: 01111110; ESC: 11100000 Show the bit
sequence transmitted (in binary) for the four-character frame: A B ESC
FLAG when each of the following framing methods are used:
(a) Character count
(b) Flag bytes with byte stuffing.
(c) Starting and ending flag bytes, with bit stuffing.
Solution
ANS: a) 00000100 01000111 11100011 11100000 01111110
b) 01111110 01000111 11100011 11100000 11100000 11100000
01111110 01111110
c) 01111110 01000111 110100011 11100000 011111010 0111110
QUESTION
The following character encoding is used in a data link protocol: A:
11010101; B: 10101001; FLAG: 01111110; ESC: 10100011 Show the bit
sequence transmitted (in binary) for the five-character frame: A ESC B
ESC FLAG when each of the following framing methods are used:
(a) Flag bytes with byte stuffing.
(b) Starting and ending flag bytes, with bit stuffing.
SOLUTION
ANS:
a) 01111110 11010101 10100011 10100011 10101001 10100011
10100011 10100011 01111110 01111110
b) 01111110 11010101 10100011 10101001 10100011 011111010
0111110
• A bit string, 0111101111101111110, needs to be transmitted at the
data link layer. What is the string actually transmitted after bit
stuffing?
Ans
The output is 011110111110011111010
• The following data fragment occurs in the middle of a data stream for
which the bytestuffing algorithm described in the text is used: A B ESC
C ESC FLAG FLAG D. What is the output after stuffing?