0% found this document useful (0 votes)
13 views

Chapter 8 - Data Link Layer

Uploaded by

pranavgoryt
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Chapter 8 - Data Link Layer

Uploaded by

pranavgoryt
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

Data Link Layer

Data Link Layer Design issues :


Main functions of Data Link Layer :
1. Providing a well-defined service interface to the network layer.
2. Dealing with transmission errors.
3. Regulating the flow of data so that slow receivers are not overflowed by fast senders.
 The data link layer takes the packets it gets from the network layer and encapsulates
them into frames for transmission.
 Each frame contains a frame header, a payload field for holding the packet, and a
frame trailer.
 When the data link layer accepts a packet, it encapsulates the packet in a frame by
adding a data link header and trailer to it.
 Thus, a frame consist of an embedded packet, some control information(in the
header), and a checksum (in the trailer).
Service Provided by DLL 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.
 On the source machine the network layer gives some bits to the data link layer for
transmission to the destination.
 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, as shown in figure (a) below.
 But the actual transmission follows the path as shown in figure (b) below.
Service Provided by DLL to the Network Layer :
There are mainly three types of services provided by DLL to NL :

1. Unacknowledged connectionless service.


2. Acknowledged connectionless service.
3. Acknowledged connection-oriented service.

1. Unacknowledged connectionless service.


Unacknowledged connectionless service consists of having the source machine send
independent frames to the destination machine without having the destination machine
acknowledged them.
No logical connection is established beforehand or released afterward. If a frame is lost
due to noise on the line, no attempt is made to detect the loss or recover from it in the
data link layer.
This class of service is appropriate when the error rate is very low.
It is also appropriate for real-time traffic, such as voice, in which bad data is allowed but
late data is not.
Most LAN’s used unacknowledged connectionless service in the DLL.
There are mainly three types of services provided by DLL to NL :

2. Acknowledged connectionless service.


 When acknowledged connectionless service is offered, there are still no logical
connections used, but each frame is acknowledged.
 In this way, the sender knows whether a frame has arrived correctly. If it has not
arrived within a specified time interval, it can be sent again.
 This service is useful over unreliable channels, such as wireless systems.
There are mainly three types of services provided by DLL to NL :

3. Acknowledged connection-oriented service.


 It is the most sophisticated service the data link layer can provide to the network layer.
 With this service, the source and destination machines establish a connection before
any data are transferred.
 Each frame sent over the connection is numbered, and the data link layer guarantees
that each frame sent is received exactly once and in right order.
 Provides the network layer processes with the equivalent of a reliable stream;
Transfer phases :
Connection established;
Frames actually transmitted;
Connection released;
 The disadvantage is that with this service, if an acknowledgement is lost then it causes
a packet to be sent several times and thus received several times.
 Example : a WAN subnet.
Following services are provided by the Data Link Layer :
Framing :

 The data link layer has to detect and, if necessary, correct errors in the bit stream
received by the physical layer of receiver.
 One way to do this is to break the bit stream up into discrete frames and computer 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 asks transmitter to retransmit the bad
frame.

 Three methods of framing:


1. Character count.
2. Flag bytes with byte stuffing.
3. Starting and ending flags, with bit stuffing.
1. Character count
 The first framing method uses a field in the header to specify the number of
characters in the frame. When the data link layer at the destination sees the character
count, it knows how many characters follow and hence where the end of the frame is.

 The problem with this algorithm is that if the count is changed by a transmission error,
then the destination will get out of synchronization and will not be able to locate the
start of the next frame.
 So, character count method is rarely used anymore.
2. Flag Bytes with Byte Stuffing
 Here, each frame starts and ends with special bytes, called a flag byte.
 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.
 If the flag byte’s bit pattern occurs in the data, then sender’s data link layer insert a
special escape byte (ESC) just before 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.
 If an escape byte occurs in the data, then that it too, is stuffed with an escape byte.
 Disadvantages: It can be used with 8-bit characters coding scheme only. Not all
character codes use 8-bit characters.
3. Flag Bits with Bit Stuffing
 Each frame begins and ends with special bit pattern, 01111110.
 If the user data contain the flag pattern, 01111110, it automatically stuffs a 0 bit into
the out going bit stream after five 1s. So, it is transmitted as 011111010.
 Two consecutive flag bytes indicate the end of one frame and start of the next one.
Error Control :
 The next problem is how to make sure all frames are delivered to the network layer at
the destination and in the proper order.
 One way to ensure reliable delivery is 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.
 In this scheme, a Timer is required at the data link layer. When the sender transmits a
frame, it starts a timer. The timer is set to expire after an interval long enough for the
frame to reach the destination, be processed there, and have the acknowledgement
propagate back to the sender. When the frame will be correctly received and the
acknowledgement will get back before the timer runs out, in which case the timer will
be canceled.
 If the acknowledgement is not received before timer goes off then sender transmits
the frame again.
 There is a danger that the receiver will accept the same frame two or more times and
pass it to the network layer more than once.
 To solve this problem DLL assigns sequence numbers to outgoing frames.
 Any time an error is detected in an exchange, specified frames are retransmitted. This
process is called automatic repeat request (ARQ).
Flow Control :
 Another important design issue is what to do with a sender that transmits frames
faster than the receiver can accept them.
 This situation can easily occur when the sender is running on a fast (or lightly loaded)
computer and the receiver is running on a slow (or heavily loaded) machine.

Two solutions of this problem:


 Feedback-based flow control, where the receiver sends back information to the
sender giving it permission to send more data.
 Rate-based flow control, where the protocol limits the rate at which senders may
transmit data, without using feedback from the receiver.
Timer :
 In most of the protocols, we assume that the channel is unreliable and loses entire
frames upon occasion.
 To be able to recover from such calamities, the sending data link layer must start an
internal timer or clock whenever it sends a frame. If no reply has been received within
a certain predetermined time interval, the clock times out and the data link layer
receives an interrupt signal.
 The time interval should be chosen to allow enough time for the frame to get to the
receiver, for the receiver to process it in the worst case, and for the acknowledgement
frame to propagate back to the sender.
 Only when that time interval has elapsed is it safe to assume that either the
transmitted frame or its acknowledgement has been lost, and to send a duplicate. If
the timeout interval is set too short, the sender will transmit unnecessary frames.
While these extra frames will not affect the correctness of the protocol, they will hurt
performance.
Standard procedures of data link layer which are used to implements the protocols :
1. to_physical_layer (Frame f)
Used to transmit the frame from DLL to the physical layer (at transmitter
side).
2. from_physical_layer (Frame &r);
Used to accept the frame from physical layer at receiver side.
3. to_network_layer
Used to send packet to the network layer from DLL (at receiver’s
side)
4. from_network_layer
Used to accept packet from n/w layer at transmitter side.
5. start_timer
Use to start timer once frame is send to the receiver
6. stop_timer :
Use to stop timer if acknowledgement signal is received on line. (at transmitter
side)
7. start_ack_timer & 8. stop_ack_timer
Timer related to acknowledgement
9. wait_for_event (event_type event);

 Initially, the receiver has nothing to do. It just sits around waiting for something
to happen.
 In the example protocols we will indicate that the data link layer is waiting for
something to happen by the function call wait_for_event (&event). This
procedure only returns when something has happened (e.g., a frame has
arrived). Upon return, the variable event tells what happened
A frame header is made up of four fields :
 A frame is composed of four fields: kind, seq, ack, and info, the first three of which
contain control information and the last of which may contain actual data to be
transferred.
 These control fields are collectively called the frame header.
 The kind field tells whether there are any data in the frame, because some of the
protocols distinguish frames containing only control information from those containing
data as well.
 The seq and ack fields are used for sequence numbers and acknowledgements,
respectively
 The info field of a data frame contains a single packet; the info field of a control frame is
not used.
 Kind – Type of frame (Data frame or acknowledgement frame)
Seq - Frame sequence number
Ack - Acknowledgement sequence number
Info - actual data to be transferred (a packet)
Protocols:
Utopian/Unrestricted simplex protocol :

Key assumptions:

 Data are transmitted in one direction only.


 Network layers on both transmitter and receiver sides are always ready.
 Processing time is ignored.
 Infinite buffer space is available.
 Common channel is 100% reliable so it does not lose or damage any frame.
 No sequence number or acknowledgements are used.
void Sender1(void)
{
Frame s; Packet p1;
While (true)
{
from _ network _ layer (&p1);
s.info=p1;
to_physical_layer (&s),
}
}
void receiver1(void)
{
Frame r;
event_type event;
while (true)
{
wait_for_event(&event);
from_phsyical_layer (&r);
to_network_layer (&r. info);
}
}
Sender:
 The protocol consists of two distinct procedures, a sender and a receiver. The sender
runs in the data link layer of the source machine, and the receiver runs in the data link
layer of the destination machine.
 No sequence numbers or acknowledgements are used here. The only event type
possible is frame_arrival (i.e., the arrival of an undamaged frame).
 The sender is in an infinite while loop just pumping data out onto the line as fast as it
can. The body of the loop consists of three actions:
 go fetch a packet from the (always obliging) network layer
 construct an outbound frame using the variable s
 send the frame on its way.
Receiver:
 The receiver is equally simple. Initially, it waits for something to happen, the only
possibility being the arrival of an undamaged frame.
 Eventually, the frame arrives and the procedure wait_for_event returns, with event set
to frame_arrival (which is ignored anyway).
 The call to from_physical_layer removes the newly arrived frame from the hardware
buffer and puts it in the variable r, where the receiver code can get at it.
 Finally, the data portion is passed on to the network layer, and the data link layer settles
back to wait for the next frame, effectively suspending itself until the frame arrives.
Simplex stop & wait protocol:
 Prevents sender from flooding the receiver with frames faster than receiver can handle
them [flow control]
 Communication channel is considered as error free.
 Data can flow in one direction only.
 In this protocol, the sender sends one frame to the receiver and then waits for an
acknowledgement.
 Frames travel in both directions: Data frames, from sender to receiver and
acknowledgement frames, from receiver to sender.
 After having passed a packet to its network layer, the receiver sends a little dummy
frame(acknowledgement) back to the sender
 It gives the sender permission to transmit the next frame. After having sent a frame, the
sender is required by the protocol to bide its time until the little dummy (i.e.,
acknowledgement) frame arrives.
void sender (void)
{
Frame s; Packet p1;
event_type event;
while (true)
{
from_network_layer(&p1);
s.info=p1;
to_physical_layer(&s);
wait_for_event(&event);
}
}
void receiver (void)
{
Frame r, ack;
event_type event;
while (true)
{
wait_for_event(&event)
from_physical_layer(&r)
to_netowork_layer(&r.info);
to_physical_layer(&ack);
}
}
Problems with stop & wait protocol:
1. Frame is destroyed in between
The network layer on A gives packet 1 to its data link layer. The packet is lost
somewhere in between and hence receiver is not sending an acknowledgment.

As reply is not coming from the receiver our sender will be continuously waiting for
the acknowledgement

The solution to this is to add a timer which times out after some span of time.

Hence if acknowledgment is not received in that time interval then eventually timer
will stop and A will again send the copy of the frame to B.
2. Acknowledgement is destroyed in between
 The network layer on A gives packet 1 to its data link layer. The packet is correctly
received at B and passed to the network layer on B. B sends an acknowledgement frame
back to A.
 The acknowledgement frame gets lost completely. It just never arrives at all.
 The data link layer on A eventually times out. Not having received an acknowledgement,
it (incorrectly) assumes that its data frame was lost or damaged and sends the frame
containing packet 1 again.
 The duplicate frame also arrives at the data link layer on B perfectly and is unwittingly
passed to the network layer there. If A is sending a file to B, part of the file will be
duplicated (i.e., the copy of the file made by B will be incorrect and the error will not
have been detected).
 The solution to this problem is that the sender put a sequence number in the header of
each frame it sends. Then the receiver can check the sequence number of each arriving
frame to see if it is a new frame or a duplicate to be discarded.
Sliding window protocol :
 In the previous protocols, data frames were transmitted in one direction only. In most
practical situations, there is a need for transmitting data in both directions.
 A better idea is to use the same circuit for data in both directions.
 In this model the data frames from A to B are intermixed with the acknowledgement
frames from A to B.
 By looking at the kind field in the header of an incoming frame, the receiver can tell
whether the frame is data or acknowledgement.
 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.
 The ack field in the frame header costs only a few bits, whereas a separate frame would
need a header, the acknowledgement, and a checksum.
Sliding window protocol :
 The essence of all sliding window protocols is that at any instant of time, 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.
One-bit Sliding window protocol :

 A sliding window protocol with a maximum window size of 1.


 Such a protocol uses stop-and-wait since the sender transmits a frame and waits for its
acknowledgement before sending the next one.
 The protocol provides full-duplex communication. Thus, acknowledgement is attached
along with the data frame to be sent by piggybacking.
 Since this is bidirectional protocol, the same algorithm applies to both communicating
parties.
One-bit Sliding window protocol :

A sliding window of size 1, with a 3-bit sequence number. (a) Initially.


(b) After the first frame has been sent. (c) After the first frame has
been received. (d) After the first acknowledgement has been
received.
 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.
 Frames are numbered alternately: 0, 1, 0, 1, …
 These are 1-bit sequence numbers. Receiver acknowledges the correct frames with an
ACK of the same sequence number as the frame.
 If not receiving the corresponding ACK after a time-out period, the sender retransmits the
frame.
What happens if time interval period of A is too short ?
 Assume that computer A is trying to send its frame 0 to computer B and that B is trying to
send its frame 0 to A.
 Suppose that A sends a frame to B, but A’s timeout interval is a little too short.
Consequently, A may time out repeatedly, sending a series of identical frames, all with seq =
0 and ack = 1.
 When the first valid frame arrives at computer B, it will be accepted and frame_expected
will be set to 1.
 All the subsequent frames will be rejected because B is now expecting frames with
sequence number 1, not 0.
 Furthermore, since all the duplicates have ack = 1 and B is still waiting for an
acknowledgement of 0, B will not fetch a new packet from its network layer.
 After every rejected duplicate comes in, B sends A a frame containing seq = 0 and ack = 0.
Eventually, one of these arrives correctly at A, causing A to begin sending the next packet.
 No combination of lost frames or premature timeouts can cause the protocol to deliver
duplicate packets to either network layer, to skip a packet, or to deadlock.
What happens if both A and B start sending packets simultaneously ?

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.
What happens if both A and B start sending packets simultaneously ?

if A and B simultaneously initiate communication, their first frames cross, and


the data link layers then get into situation (b). In (b) half of the frames contain
duplicates, even though there are no transmissions.

You might also like