The data link layer, or layer 2, is the second layer of the seven-layer OSI model of computer networking. This layer is the protocol layer that transfers data between adjacent network nodes in a wide area network (WAN) or between nodes on the same local area network (LAN) segment.
2. Data Link Layer Design Issues
âą Services Provided to the Network Layer
âą Framing
âą Error Control
âą Flow Control
3.
4. Functions of the Data Link Layer
âą Provide service interface to the network layer
âą Dealing with transmission errors
âą Regulating data flow
âą Slow receivers not swamped by fast senders
5. Functions of the Data Link Layer (2)
Relationship between packets and frames.
ï±Each frame contains a frame header,
ï±A payload field for holding the packet, and
ï±A frame trailer
6. Services Provided to Network Layer
(a) Virtual communication.
(b) Actual communication.
The principal service is transferring data from the network layer on the source
machine to the network layer on the destination machine.
7. Services Provided to Network Layer
ï±Unacknowledged connectionless service.
ï¶ source machine send independent frames to the destination
machine without having the destination machine acknowledge them.
ï±Acknowledged connectionless service.
ï¶ When this service is offered, there are still no logical connections used, but
each frame sent is individually acknowledged. In this way, the sender knows
whether a frame has arrived correctly.
ï±Acknowledged connection-oriented service.
8. Services Provided to Network Layer
ï± WAN subnet consisting of routers connected by point-to-point
leased telephone lines.
ï± When a frame arrives at a router, the hardware checks it for
errors
ï± Then passes the frame to the data link layer software.
ï± The data link layer software checks to see if this is the frame
expected,
ï± Gives the packet contained in the payload field to the routing
software.
ï± The routing software then chooses the appropriate outgoing line
ï± Passes the packet back down to the data link layer software,
which then transmits it
10. Framing
ï±Data link layer must use the service provided to it by the
physical layer.
ï±This bit stream is not guaranteed to be error free.
ï±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
11. Framing
It is too risky to count on timing to mark the start and end of each
frame, we will look at four methods:
ï±Character count.
ï±Flag bytes with byte stuffing.
ï±Starting and ending flags, with bit stuffing.
ï±Physical layer coding violations.
13. Framing Flag Byte
(a) A frame delimited by flag bytes.
(b) Four examples of byte sequences before and after stuffing.
14. Framing Flag Byte
ï± 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.
15. Framing Bit Stuffing
Bit stuffing
(a) The original data.
(b) The data as they appear on the line.
(c) The data as they are stored in receiverâs memory after destuffing.
16. Types of Error Single Bit Errors
In a single bit error, only 1 bit in the data unit changes:
Burst Errors
17. Error Detection and Correction
âą Error-Correcting Codes
âą Error-Detecting Codes
ï± Computer data always sent in blocks of bits.
ï± Suppose that the block size is 1000 bits and the error
rate is 0.001 per bit.
ï± If errors were independent, most blocks would contain
an error.
ï± If the errors came in bursts of 100 however, only one or
two blocks in 100 would be affected, on average
18. Error-Correcting Codes
ï± Block of data sent,
ï± Include only enough redundancy to allow the receiver to deduce that an error occurred, but
not which error, and have it request a retransmission.
ï± it is necessary to look closely at what an error really is.
ï± Normally, a frame consists of m data (i.e., message) bits and r redundant, or
check, bits.
ï± Let the total length be n (i.e., n = m + r). An n-bit unit containing data and check
bits is often referred to as an n-bit codeword.
Given any two codewords, say, 10001001 and 10110001, it is possible to determine how many
corresponding bits differ.
The number of bit positions in which two codewords differ is called the Hamming distance
here 3 (Hamming, 1950).
19. Error-Correcting Codes
ï±Error-detecting code, consider a code in which 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.
ï±A code with a single parity bit has a distance 2, since any single-bit
error produces a codeword with the wrong parity.
ï±0000000000, 0000011111, 1111100000, and 1111111111
ï±This code has a distance 5,
ï±Which means that it can correct double errors.
ï±If the codeword 0000000111 arrives, the receiver knows that the
original must have been 0000011111.
ï± If, however, a triple error changes 0000000000 into 0000000111,
the error will not be corrected properly
20. Error-Correcting Codes
ï±The bits of the codeword are numbered consecutively, starting with
bit 1 at the left end, bit 2 to its immediate right, and so on.
ï±The bits that are powers of 2 (1, 2, 4, 8, 16, etc.) are check bits.
ï±The rest (3, 5, 6, 7, 9, etc.) are filled up with the m data bits.
ï±For example, 11 = 1 + 2 + 8 and 29 = 1 + 4 + 8 + 16. A bit is
checked by just those check bits occurring in its expansion
(e.g., bit 11 is checked by bits 1, 2, and 8).
ï±When a codeword arrives, the receiver initializes a counter to
zero. It then examines each check bit, k (k = 1, 2, 4, 8, ...), to
see if it has the correct parity. If not, the receiver adds k to the
counter
22. Lecture 4: 9-6-01 22
Error Detection â CRC
a) View data bits, D, as a binary number
b) Choose r+1 bit pattern (generator), G
c) Goal: choose r CRC bits, R, such that
â <D,R> exactly divisible by G (modulo 2)
â Receiver knows G, divides <D,R> by G. If non-zero remainder: error
detected!
â Can detect all burst errors less than r+1 bits
a) Widely used in practice (ATM, HDCL)
(Cyclic Redundancy Check)
23. Lecture 4: 9-6-01 23
CRC Example
Want:
D.2r XOR R = nG
equivalently:
D.2r = nG XOR R
equivalently:
if we divide D.2r by G,
want reminder Rb
R = remainder[ ]
D.2r
G
10111010011
24. Flow and Error ControlFlow and Error Control
a) The most important responsibilities of the data link
layer are flow control and error control. these
functions are known as :
b) data link control.
25. 10.
Data link control.
ïData must be checked and processed before
they can be used.
ïThe rate of such processing is often slower
than the rate of transmission.
ïFor this reason , each receiver has a buffer to
store incoming data until they are processed.
ïIf buffer begin to fill up, the sender must slow
or halt transmission.
26. Flow Control
a) Necessary when data is being sent faster than it can be
processed by receiver
b) Computer to printer is typical setting
c) Can also be from computer to computer, when a processing
program is limited in capacity
d) Flow control is needed since the sending entity should not
overwhelm the receiving entity
â Recipient needs some time to process incoming packets
â If sender sends faster than recipient processes, then buffer overflow
occurs
âą flow control prevents buffer overflow
26
27. 10.
Flow control refers to a set of procedures
used to restrict the amount of data that the
sender can send before waiting for
acknowledgment.
Note
28.
29. Stop and Wait Flow Control
a) Source transmits frame
b) Destination receives frame and replies with acknowledgement
(ACK)
c) Source waits for ACK before sending next frame
d) Destination can stop flow by not sending ACK
e) Works well for large frames
f) Inefficient for smaller frames
30. Stop and Wait Flow Control
a) However, generally large block of data split into small frames
â Called âFragmentationâ
âą Limited buffer size at receiver
âą Errors detected sooner (when whole frame received)
â On error, retransmission of smaller frames is needed
âą Prevents one station occupying medium for long periods
32. Sliding Window Flow Control
a) The problem of âStop and Waitâ is not be able to send
multiple frames
b) Sliding Window Protocol allows multiple frames to be in
transit
c) Receiver has buffer of W (called window size) frames
d) Transmitter can send up to W frames without ACK
e) Each frame is numbered
â Sequence number bounded by size of the sequence number field (k
bits)
â thus frames are numbered modulo 2k
(0 ⊠2k-1
)
a) ACK includes number of next frame expected
37. Error Control
a) Actions to be taken against
â Lost frames
â Damaged frames
a) Automatic repeat request (ARQ) mechanism components
â Error detection
â Positive acknowledgment
â Retransmission after timeout
â Negative acknowledgement and retransmission
38. 10.
Error control : is both error detection and
correction. Error correction in data link layer is
implemented simply: anytime an error is detected
in exchange, specified frames are retransmitted.
This process is called Automatic Repeat Request
Data link control.
39. 10.
Error control in the data link layer is based
on automatic repeat request, which is the
retransmission of data.
Note
40. Error Control
ï± Having solved the problem of marking the start and end of each
frame,
ï± How make sure all frames delivered to the network layer
destination and proper order.
ï± To ensure reliable delivery is to provide the sender with some
feedback about what is happening
ï± 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.
41. Error Control
ï± When the sender transmits a frame, it generally also starts a
timer.
ï± The timer is set to expire after an interval long enough for the
frame to reach the destination
ï± Acknowledgement propagate back to the sender.
ï± The frame correctly received and the acknowledgement will get
back before the timer runs out,
ï± If either the frame or the acknowledgement is lost, the timer will
go off, alerting the sender to a potential problem.
ï± The obvious solution is to just transmit the frame again.
ï± To prevent this from happening, it is generally necessary to assign
sequence numbers to outgoing frames, so that the receiver can
distinguish retransmissions from originals
42. PROTOCOLS
Now let us see how the data link layer can
combine flow control , and error control to
achieve the delivery of data from one node to
another . The protocols are normally
implemented in software.
Stop-and-Wait ARQ
Go-Back-N ARQ
Selective Repeat ARQ
PROTOCOLS
43. ï A transmitter sends a frame then stops and waits for
an acknowledgment.
ï Stop-and-Wait ARQ has the following features:
ïŒ The sending device keeps a copy of the sent frame
transmitted until it receives an
acknowledgment( ACK)
ïŒ The sender starts a timer when it sends a frame. If
an ACK is not received within an allocated time
period, the sender resends it
ïŒ Both frames and acknowledgment (ACK) are
numbered alternately 0 and 1( two sequence number
only)
ïŒ This numbering allows for identification of frames in
case of duplicate transmission
Stop-and-Wait ARQ
44. ï The acknowledgment number defines the number of
next expected frame. (frame 0 received ACK 1 is
sent)
ï A damage or lost frame treated by the same manner
by the receiver
ï If the receiver detects an error in the received frame,
or receives a frame out of order it simply discards
the frame
ï The receiver send only positive ACK for frames
received safe; it is silent about the frames damage
or lost.
ï The sender has a control variable Sthat holds the
number of most recently sent frame (0 or 1). The
receiver has control variable R, that holds the
Stop-and-Wait ARQ
45. Cases of Operations:
1.Normal operation
2.The frame is lost
3.The Acknowledgment (ACK) is lost
4.The Ack is delayed
Stop-and-Wait
ARQ
46. ï The sender will not
send the next frame
until it is sure that the
current one is
correctly receive
ï sequence number is
necessary to check
for duplicated frames
Stop-and-Wait ARQ
47. 1. Stop and Wait ARQ
2. Lost or damaged frame
ï A damage or lost frame
treated by the same
manner by the receiver.
ï No NACK when frame is
corrupted / duplicate
48. 3. Lost ACK frame
ï Importance of frame
numbering
Stop-and-Wait ARQ
49. 10.
In Stop and-Wait ARQ, numbering frames
prevents the retaining of duplicate
frames.
Note
50. 4. Delayed ACK and lost frame
ï Importance of
frame numbering
Stop-and-Wait ARQ
52. Go-Back-N ARQ
a) Based on sliding window
b) If no error, ACK as usual with next frame expected
â ACKi means âI am ready to receive frame iâ and âI received all
frames between i and my previous ackâ
a) Sender uses window to control the number of
unacknowledged frames
b) If error, reply with rejection (negative ack)
â Discard that frame and all future frames until the frame in error
received correctly
â Transmitter must go back and retransmit that frame and all
subsequent frames
53. Go-Back-N ARQ
Example: The sender has sent frame 6 , and timer expires for frame 3(
frame 3 has not been acknowledge); the sender goes back and
resends frames 3, 4,5 and 6
54. Go-Back-N ARQ
Normal operation
ï How many frame scan be
transmitted Without
acknowledgment?
ï ACK1 is not necessary if
ACK2 is sent: Cumulative
ACK
55. Go-Back-N ARQ -
Damaged Frame
a) Receiver detects error in frame i
b) Receiver sends âreject iâ
c) Transmitter gets âreject iâ
d) Transmitter retransmits frame i and all subsequent frames
56. Go-Back-N ARQ
Damage or Lost Frame
Correctly received out of
order packets are not
Buffered
What is the disadvantage of
this?
57. Go-Back-N ARQ - Lost Frame
a) Frame i lost
b) Transmitter sends frame i+1
c) Receiver gets frame i+1 out of sequence
d) Receiver sends âreject iâ
e) Transmitter goes back to frame i and
retransmits it and all subsequent frames
58. Go-Back-N ARQ
Damage or Lost Frame
Correctly received out of
order packets are not
Buffered
What is the disadvantage of
this?
59. 10.
Stop-and-Wait ARQ is a special case of
Go-Back-N ARQ in which the size of
the send window is 1
Note
60. Selective Repeat ARQ
Go-Back-N ARQ is inefficient of a noisy link.
ïIn a noisy link frames have higher probability of damage , which
means the resending of multiple frames.
ïthis resending consumes the bandwidth and slow down the
transmission .
Solution:
ïSelective Repeat ARQ protocol : resent only the damage frame
ïIt defines a negative Acknolgment (NAK) that report the sequence
number of a damaged frame before the timer expires
ïIt is more efficient for noisy link, but the processing at the receiver
is more complex