0% found this document useful (0 votes)
71 views14 pages

Data Link Layer: Paolo Costa Costa@cs - Vu.nl

The document discusses the data link layer, which is responsible for transmitting data frames between devices reliably. It describes some basic services the data link layer provides, such as acknowledged and unacknowledged transmission. The data link layer must also regulate data flow between sender and receiver. It introduces various techniques for framing data, detecting errors, and correcting errors when transmitting frames across physical links.

Uploaded by

indrajeet04bs
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views14 pages

Data Link Layer: Paolo Costa Costa@cs - Vu.nl

The document discusses the data link layer, which is responsible for transmitting data frames between devices reliably. It describes some basic services the data link layer provides, such as acknowledged and unacknowledged transmission. The data link layer must also regulate data flow between sender and receiver. It introduces various techniques for framing data, detecting errors, and correcting errors when transmitting frames across physical links.

Uploaded by

indrajeet04bs
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Data Link Layer

Physical: Describes the transmission of raw bits in terms of


mechanical and electrical issues.
Data Link: Describes how a shared communication channel can
Computer Networks be accessed, and how a data frame can be reliably transmitted.
Data Link Layer Network: Describes how routing is to be done. Mostly needed in
subnets.
Transport: The hardest one: generally offers connection-oriented
Paolo Costa as well as connectionless services, and varying degrees of
[email protected] reliability. This layer provides the actual network interface to
http://www.cs.vu.nl/∼costa applications.
Vrije Universiteit Amsterdam Application: Contains the stuff that users see: e-mail, remote
logins, the Web’s exchange protocol, etc.

Note
We’ll just concentrate on transmission issues. Channel access is
(Version May 9, 2008) discussed in Chapter 4
Paolo Costa 03 - Data Link Layer 1 / 55 Paolo Costa 03 - Data Link Layer Introduction 2 / 55

Design Issues Basic Services


Network layer passes a number of bits (frame) to the data link
layer.
Data link layer is responsible for transmitting the frame to the
destination machine.
Receiving layer passes received frame to its network layer.
Basic services commonly provided:
unacknowledged connectionless service (LANs)
acknowledged connectionless service (Wireless systems).
acknowledged connection-oriented service (WANs).

Question
1 Provide well-defined interface to network layer Why are we so concerned about error-free frame transmissions?
2 Handle transmission errors Can’t the higher layers take care of that?
It’s not mandatory but it may improve efficiency (fine-grained
3 Regulate flow of data: get sender and receiver in the same pace
recovery: frames vs. messages)
Paolo Costa 03 - Data Link Layer Design Issues 3 / 55 Paolo Costa 03 - Data Link Layer Design Issues 4 / 55
Transmission Routing

The network layer consists of routing


they are connected through point=to-point links
The router would really its packet to be sent correctly, guaranteed,
The actual transmissions follow the path of (b) but it is easier to and in the order it was issued.
think in terms of two data link process communicating using a It is up to the data link to make unreliable connections look
data link protocol (a) perfect, or at least, fairly good
Paolo Costa 03 - Data Link Layer Design Issues 5 / 55 Paolo Costa 03 - Data Link Layer Design Issues 6 / 55

Frames Frames
Counting Byte Stuffing

The physical layer doesn’t do much: it just pumps bits from one Byte stuffing: Mark the beginning and end of a byte frame with two
end to the other. special flag bytes – a special bit sequence (e.g. 01111110). If
But things may go wrong such bytes appear in the original frame, escape them:
⇒ the data link layer needs a means to do retransmissions.
The unit of retransmission is a frame (which is just a fixed number
of bits).
Problem: How can we break up a bit stream into frames?
naive solution: counting

(a) Without errors (b) With errors


Paolo Costa 03 - Data Link Layer Design Issues 7 / 55 Paolo Costa 03 - Data Link Layer Design Issues 8 / 55
Frames Error Correction and Detection
Bit Stuffing
Problem: Suppose something went wrong during frame
Byte stuffing is closely tied to the use of 8-bit character transmission. How do we actually notice that something’s wrong,
Solution and can it be corrected by the receiver?
⇒ Bit stuffing: Escape the flag byte (e.g., 01111110) through an
Definition: The Hamming distance between two frames ~a and ~b is
additional bit the number of bits at the same position that differ.
whenever the sender’s data link encounters five consecutive 1s in Example
the data, it automatically stuffs a 0 bit
10001001 and 10110001 are at Hamming distance 3

1 0 0 0 1 0 0 1
1 0 1 1 0 0 0 1 ⊕ ←− XOR
0 0 1 1 1 0 0 0
To detect d errors, you need a distance d + 1 code
d-single bit errors cannot change a valid codeword in another
To correct d errors, you need a distance 2d+1 code
(a) frame to send (b) frame transmitted over the wire (c) reconstructed frame this way, even with 2d changes, the original codeword is still closer
that any other codeword
Paolo Costa 03 - Data Link Layer Design Issues 9 / 55 Paolo Costa 03 - Data Link Layer Error Control 10 / 55

Error Detection Error Correction


Parity Example

Consider a code with only four valid codewords:


Add a bit to a bit string such that the total number of 1-bits is even 1 0000000000
2 0000011111
(or odd)
3 1111100000
e.g., (even parity) 1011010 ⇒ 10110100 4 1111111111
(odd parity) 1011010 ⇒ 10110101 This code has distance 5
The XOR between any pair of the above codeword gives at least
The distance between two (legal) frames is at least d = 2. five 1 bits
any single-bit error produces a code word with the wrong parity ⇒ it means it can correct double errors
remember that to correct d errors, you need a distance 2d+1 code

We can detect a single error (i.e., k = 1 and d = 2) E.g., if the codeword 0000000111 is received, the receiver knows
remember that to detect d errors, you need a distance d+1 code that the original must have been 0000011111
If, however, a triple error changes 0000000000 into 0000000111,
the error will not be corrected properly

Paolo Costa 03 - Data Link Layer Error Control 11 / 55 Paolo Costa 03 - Data Link Layer Error Control 12 / 55
Error Correction Error Correction: Hamming
Lower Bound Definition

The theoretical lower limit can be achieved using a method due to


Problem: we want to design a code with m message bits and r Hamming (1950)
check bits to correct all single errors Enumerate all bits in a codeword starting with bit 1 at the left
The bits at position 2k (k ≥ 0) are check bits, the rest (3,5,6,7,. . . )
Each of the 2m legal messages has n illegal codewords at
are filled with the m data bits
distance 1
Every check bit is used as a parity bit for those positions to which it
these are obtained by systematically change each of the n bits in contributes
the n-bit codeword
b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11
Each of the 2m legal messages require n + 1 bit patterns 1 X X X X X X
dedicated to it 2 X X X X X X
4 X X X X
The total number of bit pattern is 2n
n=m+r
8 X X X X
⇒ (n + 1)2m ≤ 2n =⇒ (m + r + 1) ≤ 2r
Rewrite every data bit as sums of power of 2
Given m, it is possible to have a lower bound to the number r of e.g., 7 = 1 + 2 + 4 and 11 = 1 + 2 + 8
check bits needed to correct single errors A bit is checked by just those bits occurring in its expansion
e.g., bit 11 is checked by bit 1, 2, and 8

Paolo Costa 03 - Data Link Layer Error Control 13 / 55 Paolo Costa 03 - Data Link Layer Error Control 14 / 55

Error Correction: Hamming Error Correction: Hamming


Coding Decoding

If a check bit at position p is wrong upon receipt, the receiver


b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11
increments a counter v with p
1 X X X X X X
The value of v will, in the end, give the position of the wrong bit,
2 X X X X X X
which should then be swapped. E.g.:
4 X X X X
b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11
8 X X X X 1 X X X X X X
1 0 1 1 1 0 0 1 0 0 1 2 X X X X X X
4 X X X X
8 X X X X
Check bits are used to even out the number of 1 bits they S: 1 0 1 1 1 0 0 1 0 0 1
contribute to R: 1 0 1 1 1 0 0 1 1 0 1
C: 0 0 1 1 1 0 0 0 1 0 1
e.g., assume the message is 1100001
F: 1 0 1 1 1 0 0 1 0 0 1
Check bit at position 2, is used to even out the bits for positions 2,
3, 6, 7, 10, and 11 S: string sent
⇒ b2 = 0 as the number of 1s is even (b3 and b11) R: string received
C: string corrected on the check bits: #1 and #8 corrected ⇒ bit #9 is wrong
Other check bits are computed in the same way
(v = 1 + 9)
The final codeword is 1011100101 F: final result after correction
Paolo Costa 03 - Data Link Layer Error Control 15 / 55 Paolo Costa 03 - Data Link Layer Error Control 16 / 55
Error Correction: Hamming Error Detection
Burst Errors CRC

Error correcting codes are simply too expensive


Hamming codes can only detect single errors e.g., for 10,000 bit blocks, 10 check bits are needed
However, there is a trick to correct burst errors ⇒ only use error detection combined with retransmissions
Cyclic Redundancy Check (CRC), a.k.a. polynomial code, is
A sequence of k codewords based upon treating bit strings as polynomials with coefficient of 0
are arranged as a matrix, one and 1 only
codeword per row a k -bit frame is regarded as the coefficient list for a polynomial with
k terms, from x k −1 to x 0
Data are transmitted one
e.g., a 6-bit block
column at a time
M(x) = mk −1 x k −1 + . . . + m1 x 1 + m0 x 0
If a burst error of length k
occurs, at most 1 bit per
codeword is affected 110001 ⇒ 1ẋ 5 + 1ẋ 4 + 0ẋ 3 + 0ẋ 2 + 0ẋ 1 + 1ẋ 0
Hamming code can correct = x5 + x4 + 1
one error per codeword
⇒ the entire block can be
Polynomial arithmetic is done in modulo 2, according to the rule of
restored
algebraic field theory
Paolo Costa 03 - Data Link Layer Error Control 17 / 55 Paolo Costa 03 - Data Link Layer Error Control 18 / 55

Polynomial Arithmetic Polynomial Arithmetic


Addition and Subtraction Multiplication and Division

Since the coefficients are constrained to a single bit, any math


operation on CRC polynomials must map the coefficients of the Multiplication
result to either 0 or 1 It follows the rule of traditional polynomials but, again, addition of
Addition coefficient is done module 2

(x 3 + x) + (x + 1) = x 3 + 2x + 1 ≡ x 3 + 1 (x 2 + x)(x + 1) = x 3 + x 2 + x 2 + 1 = x 3 + 2x 2 + 1 ≡ x 3 + 1
note that 2x becomes zero because addition of coefficient is done Division
modulo 2 we can also divide polynomials mod 2 and find the quotient and
2x = x + x = (1 + 1)x = 0x = 0 remainder
analogous to exclusive OR (XOR) x3 + x2 + x 1
= (x 2 + 1) −
x +1 x −1
1010 ⊕ 0011 → 1001
or in other words:
Subtraction
works like addition (only absolute values are used) (x 3 + x 2 + x) = (x 2 + 1)(x + 1) − 1

(x 4 + x 2 + 1) − (x + 1) = x 4 + x 2 − x ≡ x 4 + x 2 + x

Paolo Costa 03 - Data Link Layer Error Control 19 / 55 Paolo Costa 03 - Data Link Layer Error Control 20 / 55
CRC CRC
Algorithm Division Example

Let’s go back our problem


Sender and receiver agree upon a generator polynomial G(x) 1 Check the input bit above the
both the high- and low-order bits of the generator must be 1 leftmost divisor
the frame M(x) must be longer than the generator (m > r ) If it is 0, do nothing
Idea: append a checksum to the end of the frame in such a way If it is 1, the divisor is
that the polynomial obtained is divisible (i.e., no remainder) by XORed into (i.e., subtracted
G(x) from) the input
when the receivers gets the checksummed frame, it tries dividing it 2 Move the divisor to the right by
by G(x) one bit
if there is a remainder, there has been a transmission error 3 The process is repeated until
Algorithm the divisor reaches the
1 append r zero bits to the low order of the frame right-hand end of the input row
now it contains m + r bits and corresponds to x r M(x)
2 divide x r M(x) by G(x)
4 The left bits are the remainder
3 subtract (mod 2) the remainder from x r M(x). The result is the of the division to be appended
checksummed frame T (x) to be transmitted to the frame
Paolo Costa 03 - Data Link Layer Error Control 21 / 55 Paolo Costa 03 - Data Link Layer Error Control 22 / 55

CRC CRC
Decoding Burst Error

If a transmission error occurs, instead of the original polynomial


T (x),T (x) + E(x) arrives By carefully choosing G(x), burst errors can be correctly detected
a burst error is a contiguous sequence of bits, containing wrong bits
each 1 bit in E(x) corresponds to a bit that has been inverted
if there are k 1 bits in E(x), k single bit errors have occurred It can be shown, that a polynomial code with r check bits, will
E(x) is characterized by an initial 1, a mixture of 0s and 1s, and a detect all bursts errors of length ≤ r
final 1
If the burst length is r + 1, the probability of accepting an incorrect
The receiver divided the received frame by G(x), i.e., frame is 2r1−1
[T (x) + E(x)]/G(x) and computes the remainder
in case of error, the remainder will be E(x)/G(x)
It can also be shown that for bursts longer than r + 1 bit, such
probability becomes 21r , assuming that all bit patterns are equally
If there is a single-bit error, E(x) = x i (being i the position of the
likely (not always true)
wrong bit)
if G(x) contains two or more terms, it will never divide E(x) ⇒ all
Certain polynomial have become standards
single-bit errors will be detected e.g., the one used in IEEE 802 (Wi-Fi) is:
the simplest error-detection system, the parity bit, is in fact a trivial x 32 +x 26 +x 23 +x 22 +x 16 +x 12 +x 11 +x 10 +x 8 +x 7 +x 5 +x 4 +x 2 +x 1 +1
CRC: it uses the two-bit-long divisor 11 it detects all bursts of length 32 or less and all bursts affecting an
odd number of bits
Paolo Costa 03 - Data Link Layer Error Control 23 / 55 Paolo Costa 03 - Data Link Layer Error Control 24 / 55
CRC Data Link Layer Protocols
Applications
Concentrated on design aspects and error control
frame size (stuffing)
error correction (Hamming Code)
error detection (CRC)
CRC is not used by the data link layer but also by applications to Now: basic protocols and real-world examples
check the correctness of a given file
Some basic assumptions:
e.g., WinZip
We have a machine A that wants to send data to machine B
There is always enough data for A to send
There is a well-defined interface to the network layer, and to the
physical layer
void from_network_layer(packet *)
void to_network_layer(packet *)
void from_physical_layer(packet *)
void to_physical_layer(packet *)
The receiver generally waits for an event to happen by calling
void wait_for_event(event_type *event)
Paolo Costa 03 - Data Link Layer Error Control 25 / 55 Paolo Costa 03 - Data Link Layer Basic Protocols 26 / 55

Unrestricted Simplex Protocol Unrestricted Simplex Protocol


Issues
1 typedef enum {false, true} boolean;
2 typedef unsigned int seq_nr;
3
4
typedef
typedef
struct {unsigned char data[MAX_PKT];} packet;
enum {data, ack, nak} frame_kind;
Question
5
6 typedef struct { What are some of the underlying assumptions here? How does
7 frame_kind kind; /* what kind of a frame is it? */
8 seq_nr seq; /* sequence number */ the flow control manifest itself?
9 seq_nr ack; /* acknowledgment number */
10 packet info; /* the network layer packet */ Underlying assumptions are error-free transmission, and
11 } frame;
12 sender-receiver are in pace.
13 typedef enum {frame_arrival} event_type;
14
15 void sender1(void){
16 frame s; packet buffer; Issue: Fast senders would make receivers collapse
17 while (true) {
18 from_network_layer(&buffer);
19
20
s.info = buffer;
to_physical_layer(&s);
Question
21 }
22 } Would a simple delay on sender’s side fix the problem ?
23
24 void receiver1(void){ Not really! It’s hard to predict when receiver’s congestion may
25 frame r; event_type event;
26 while (true) { occur.
27 wait_for_event(&event);
28 from_physical_layer(&r);
29
30 }
to_network_layer(&r.info); Assuming always the worst-case behavior would be highly
31 } inefficient
Paolo Costa 03 - Data Link Layer Basic Protocols 27 / 55 Paolo Costa 03 - Data Link Layer Basic Protocols 28 / 55
Simplex Stop-and-Wait Simplex Protocol for Noisy Channel
1
2
typedef enum {frame_arrival} event_type;
#include "protocol.h"
Question
3
4 void sender2(void){ What are the assumptions in this case? We are assuming only
5 frame s; packet buffer;
6 event_type event; error-free transmission.
7 while (true) {
8 from_network_layer(&buffer);
9 s.info = buffer; Ok, so assume that damaged frames can be detected
10 to_physical_layer(\&s);
11 wait_for_event(&event);
12 } Question
13 }
14
15 void receiver2(void){
Idea: send the ack only upon correct receipt! Works ? No, because also
16 frame r, s; event_type event; the ack can be lost.
17 while (true) {
18 wait_for_event(&event);
19 from_physical_layer(\&r);
20 to_network_layer(&r.info); Question
21 to_physical_layer(&s);
22
23 }
} Second idea: let the sender use a timer by which it simply retransmits
unacknowledged frames after some time! Works ? No again! Because
the data link layer cannot detect duplicate transmissions.
Here the receiver provide the feedback to the sender
it sends a little dummy packet (acknowledgment) back to the sender Let’s use sequence numbers!
After having sent a frame, the sender is required to wait for the ack Problem: sequence number cannot go on for ever and they wast space
Solution: no worries, we need just two (0 & 1)
Paolo Costa 03 - Data Link Layer Basic Protocols 29 / 55 Paolo Costa 03 - Data Link Layer Basic Protocols 30 / 55

Simplex Protocol for Noisy Channel Simplex Protocol for Noisy Channel
Sender Receiver

next_frame_to_send indicates which is the last message sent frame_expected enables filtering out duplicate
A timer is started after sending a message Its value is increased each time a frame is delivered to the
Only if the correct ack is received, the next message is sent
network layer
1 #define MAX_SEQ 1 ⇒ only two values (0 and 1) are needed
2 typedef enum {frame_arrival, cksum_err, timeout} event_type;
3 void sender3(void) { 1 void receiver3(void) {
4 int next_frame_to_send; 2
5 frame s; 3 seq_nr frame_expected; frame r, s; event_type event;
6 packet buffer; 4
7 event_type event; 5 frame_expected = 0;
8 6 while (true) {
9 next_frame_to_send = 0; 7
10 from_network_layer(&buffer); 8 wait_for_event(&event);
11 while (true) { 9 if(event == frame_arrival) {
12 s.info = buffer; 10
13 s.seq = next_frame_to_send; 11 from_physical_layer(&r);
14 to_physical_layer(&s); 12 if (r.seq == frame_expected) {
15 start_timer(s.seq); 13
16 wait_for_event(&event); 14 to_network_layer(&r.info);
17 15 inc(frame_expected);
18 if (event == frame_arrival) { 16 }
19 from_physical_layer(&s); 17 s.ack = 1 - frame_expected;
20 if (s.ack == next_frame_to_send) { 18 to_physical_layer(&s);
21 stop_timer(s.ack); 19 }
22 from_network_layer(&buffer); 20 }
23 inc(next_frame_to_send); 21 }
24 } } } }

Paolo Costa 03 - Data Link Layer Basic Protocols 31 / 55 Paolo Costa 03 - Data Link Layer Basic Protocols 32 / 55
From Simplex to Duplex Sliding Windows
Problem: We want to allow symmetric frame transmission Principle: Rather than just sending a single frame at a time, permit
between two communicating parties, rather than transmission in the sender to transmit a set of frames, called the sending window.
one direction. a frame is removed from the sending window iff it has been
don’t waste channels, so use the same channel for duplex acknowledged.
communication. the receiver has a receiving window containing frames it is
Solution: Just transmit frames, but distinguish between data, permitted to receive.
acknowledgments (acks), and possibly negative acks (nacks) in A damaged frame is kept in the receiving window until a correct
version is received. Also, frame N is kept in the window until frame
the frame’s type field.
N-1 has been received.
Idea: If the other party is going to send data as well, it might as if both window sizes equal one, we are dealing with the
well send acknowledgments along with its data frames stop-and-wait protocols.
⇒ piggybacking.
Question
Question Is there a relationship between window size, transmission rate, and
What’s good and bad about piggybacking? propagation delay ? If the propagation delay is high and the window size
Good: save bandwidth. is small, transmission rate decreases dramatically because the sender
Bad: poor performance with irregular transmission rate. while waiting for acks cannot send new messages

Paolo Costa 03 - Data Link Layer Basic Protocols 33 / 55 Paolo Costa 03 - Data Link Layer Sliding Window Protocols 34 / 55

Window Size & Sequence Number 1-Bit Sliding Window


1 void protocol4 (void) {
2 seq_nr next_frame_to_send, frame_expected;
3 frame r, s; packet buffer;
4 event_type event;
5
6 next_frame_to_send = 0; frame_expected = 0; next_frame_to_send
7 from_network_layer(&buffer); tells which frame the
8 s.info = buffer;
9 s.seq = next_frame_to_send; sender is trying to
10 s.ack = 1 - frame_expected;
11 to_physical_layer(&s); start_timer(s.seq);
send
12
13 while (true) {
frame_expected
14 wait_for_event(&event); tells which frames the
15 if (event == frame_arrival) {
16 from_physical_layer(&r); receiver is expecting
17 if (r.seq == frame_expected){
18 to_network_layer(&r.info); If the received frame
19 inc(frame_expected);} is the one expected,
20
(a) Initially (b) After sending frame #1. 21 if (r.ack == next_frame_to_send){ the frame is passed
(c) After receiving frame #1. (d) After receiving ack for frame #1 22 from_network_layer(&buffer); to the network layer
23 inc(next_frame_to_send);}
24 If the received ack is
Question 25 }
26 s.info = buffer; the one expected, the
How would you interpret the shaded areas? 27 s.seq = next_frame_to_send;
next frame is sent
28 s.ack = 1 - frame_expected;
Shaded area is to-be-acknowledged (at sender) and 29 to_physical_layer(&s); start_timer(s.seq);
30 }
to-be-received next (at receiver). 31 }

Paolo Costa 03 - Data Link Layer Sliding Window Protocols 35 / 55 Paolo Costa 03 - Data Link Layer Sliding Window Protocols 36 / 55
1-Bit Sliding Window Error Control
Simultaneous Transmissions

Problem: What should the receiver do if a frame is damaged ?


Go back n
Simply request retransmission of all frames starting from frame
#N. If any other frames had been received in the meantime (and
stored in the receiver’s window), they’ll just be ignored
Selective Repeat
Request just retransmission of the damaged frame, and wait until
it comes in before delivering any frames after that
The notation is (seq, ack, packet number). * means: passed to network layer

All things go well, but behavior is a bit strange when A and B


transmit simultaneously.
We are transmitting more than once, just because the two senders
are more or less out of sync.
Paolo Costa 03 - Data Link Layer Sliding Window Protocols 37 / 55 Paolo Costa 03 - Data Link Layer Sliding Window Protocols 38 / 55

Error Control Error Control


Example Pros & Cons

Go-back-N is really simple: the sender keeps a frame in its


window until it is acknowledged.
if the window is full, the network layer is not allowed to submit new
packets.
the receiver hardly needs to keep an account on what happens: if a
frame is damaged, its successors in the receive window are
ignored.
it is equivalent to a receive window of size 1
Selective repeat seems to do better because frames aren’t
discarded, but the administration is much harder
it also requires large amounts of memory if the window is large
Trade-off between bandwidth and data link layer buffer space

(a) Go back n (b) Selective Repeat.


Paolo Costa 03 - Data Link Layer Sliding Window Protocols 39 / 55 Paolo Costa 03 - Data Link Layer Sliding Window Protocols 40 / 55
Go-back-n (1/2) Go-back-n (2/2)
1 #define MAX_SEQ 7 /* should be 2^n - 1 */ 1 while (true) {
2 typedef enum {frame_arrival, cksum_err, 2 wait_for_event(&event);
3 timeout, network_layer_ready} event_type; 3 switch(event) {
4 #include "protocol.h" 4 case network_layer_ready:
5 5 from_network_layer(&buffer[next_frame_to_send]);
6 static boolean between(seq_nr a, seq_nr b, seq_nr c) { 6 nbuffered = nbuffered + 1;
7 /* Return TRUE iff a <= b < c (cyclic) */ 7 send_data(next_frame_to_send, frame_expected, buffer);
8 ... 8 inc(next_frame_to_send);
9 } 9 break;
10 10 case frame_arrival:
11 static void send_data( 11 from_physical_layer(&r);
12 seq_nr frame_nr, seq_nr frame_expected, packet buffer[]){ 12 if (r.seq == frame_expected) {
13 frame s; 13 to_network_layer(&r.info);
14 s.info = buffer[frame_nr]; s.seq = frame_nr; 14 inc(frame_expected); }
15 s.ack = (frame_expected + MAX_SEQ) % (MAX_SEQ + 1); 15 while (between(ack_expected, r.ack, next_frame_to_send)) {
16 to_physical_layer(&s); start_timer(frame_nr); 16 nbuffered = nbuffered - 1;
17 } 17 stop_timer(ack_expected);
18 18 inc(ack_expected); }
19 void protocol5(void) { 19 break;
20 seq_nr next_frame_to_send, ack_expected, frame_expected; 20 case cksum_err: break; /* just ignore bad frames */
21 frame r; 21 case timeout: /* trouble; retransmit outstanding frames */
22 packet buffer[MAX_SEQ + 1]; 22 next_frame_to_send = ack_expected;
23 seq_nr nbuffered, i; 23 for (i = 1; i <= nbuffered; i++) {
24 event_type event; 24 send_data(next_frame_to_send, frame_expected, buffer);
25 25 inc(next_frame_to_send); }
26 enable_network_layer(); 26 }
27 ack_expected = 0; next_frame_to_send = 0; frame_expected = 0; 27 if (nbuffered < MAX_SEQ)
28 nbuffered = 0; 28 enable_network_layer();
29 else
30 disable_network_layer();
enable_network_layer prevents network layer to input more frames when 31 } }
there are MAX_SEQ unacknowledged frames
Paolo Costa 03 - Data Link Layer Sliding Window Protocols 41 / 55 Paolo Costa 03 - Data Link Layer Sliding Window Protocols 42 / 55

Go-back-n Selective Repeat


Comments

An ack for frame n, automatically acknowledges also frames n-1,


n-2, etc.
Note that a maximum of MAX_SEQ frames and not MAX_SEQ + 1 Go-back-n works well if errors are rare, but if the line is poor, it
frames may be outstanding
wastes a lot of bandwidth
→ packet buffer[MAX_SEQ+1]
→ if nbuffered < MAX_SEQ An alternative strategy is to allow receiver to accept and buffer the
The reason is the following: frames following a damaged or lost one
1 The sender sends frames 0 through 7 both sender and receiver maintain a window larger than 1
2 An ack for frame 7 comes back to the sender whenever a frame arrives, its sequence number is checked by the
3 The sender sends other eight frames with sequence number 0 function between to see if it falls within the window
through 7 however, it must be kept within the data link layer and not passed to
4 Now another piggybacked ack for frame 7 comes in the network layer until all lower numbered frames are received
Problem: Did all eight frames belonging to the second batch arrive
correctly or did all get lost ?
the sender has no way to detect it
Solution Restrict the maximum number of outstanding frames to
MAX_SEQ
Paolo Costa 03 - Data Link Layer Sliding Window Protocols 43 / 55 Paolo Costa 03 - Data Link Layer Sliding Window Protocols 44 / 55
Selective Repeat (1/3) Example: Selective Repeat (2/3)
1 static boolean between(seq_nr a, seq_nr b, seq_nr c) {...} 1 case frame_arrival:
2 static void send_frame(frame_kind fk, seq_nr frame_nr, 2 from_physical_layer(&r);
3 seq_nr frame_expected, packet buffer[]){ 3 if (r.kind == data) {
4 frame s; s.kind = fk; 4 if ((r.seq != frame_expected) && no_nak)
5 if (fk == data) s.info = buffer[frame_nr % NR_BUFS]; 5 send_frame(nak, 0, frame_expected, out_buf);
6 s.seq = frame_nr; 6 else start_ack_timer();
7 s.ack = (frame_expected + MAX_SEQ) % (MAX_SEQ + 1); 7 if (between(frame_expected, r.seq, too_far) &&
8 if (fk == nak) no_nak = false; 8 if(arrived[r.seq % NR_BUFS] == false)) {
9 to_physical_layer(&s); 9 arrived[r.seq % NR_BUFS] = true;
10 if (fk == data) start_timer(frame_nr % NR_BUFS); 10 in_buf[r.seq % NR_BUFS] = r.info;
11 stop_ack_timer(); 11 while (arrived[frame_expected % NR_BUFS]) {
12 { 12 to_network_layer(&in_buf[frame_expected % NR_BUFS]);
13 void protocol6(void){ 13 no_nak = true;
14 seq_nr ack_expected, next_frame_to_send, frame_expected; 14 arrived[frame_expected % NR_BUFS] = false;
15 seq_nr nbuffered, too_far; event_type event;int i; frame r; 15 inc(frame_expected);
16 packet out_buf[NR_BUFS], in_buf[NR_BUFS]; 16 inc(too_far);
17 boolean arrived[NR_BUFS]; 17 start_ack_timer(); }
18 18 }
19 enable_network_layer(); 19 }
20 ack_expected = 0; next_frame_to_send = 0; frame_expected = 0; 20 if ((r.kind == nak) &&
21 too_far = NR_BUFS; nbuffered = 0; 21 if between(ack_expected, (r.ack+1) % (MAX_SEQ+1)
22 for (i = 0; i < NR_BUFS; i++) arrived[i] = false; 22 next_frame_to_send))
23 while (true) { 23 send_frame(data, (r.ack+1) % (MAX_SEQ + 1),
24 wait_for_event(&event); 24 frame_expected,out_buf);
25 switch(event) { 25
26 case network_layer_ready: 26 while (between(ack_expected, r.ack, next_frame_to_send)) {
27 nbuffered = nbuffered + 1; 27 nbuffered = nbuffered - 1;
28 from_network_layer(&out_buf[next_frame_to_send % NR_BUFS]); 28 stop_timer(ack_expected % NR_BUFS);
29 send_frame(data,next_frame_to_send,frame_expected,out_buf); 29 inc(ack_expected);
30 inc(next_frame_to_send); 30 }
31 break; 31 break;

Paolo Costa 03 - Data Link Layer Sliding Window Protocols 45 / 55 Paolo Costa 03 - Data Link Layer Sliding Window Protocols 46 / 55

Example: Selective Repeat (3/3) Selective Repeat


Comments

Frames need not be received in order,


we may have an undamaged frame N, while still waiting for an
1 case cksum_err: undamaged version of N − 1.
2 if (no_nak) send_frame(nak, 0, frame_expected, out_buf);
3 break; If the receiver delivers all frames in its window just after sending
4
5 case timeout: an ack for the entire window, we may have a serious problem:
6 send_frame(data, oldest_frame, frame_expected, out_buf);
Station A Station B
7 break; (window size = 4) (window size = 5)
8
9 case ack_timeout: Send window
01234567
10 send_frame(ack,0,frame_expected, out_buf);
0 1 2 3 4 5 6 7 Receive 0-3
11 }
12 if (nbuffered < NR_BUFS) enable_network_layer(); 0 1 2 3 4 5 6 7 Advance window
13 else disable_network_layer();
14 }
15 } 01234567 Resend window
Frame #0 is
01234567
duplicate

Solution: we must avoid overlapping send and receive windows


⇒ the highest sequence number must be at least twice the window
size.
Paolo Costa 03 - Data Link Layer Sliding Window Protocols 47 / 55 Paolo Costa 03 - Data Link Layer Sliding Window Protocols 48 / 55
Data Link Protocols Data Link Layer Protocols
Demo

Now let’s take a look how point-to-point connections are supported in,
for example, the Internet.
Recall:
The data link layer is responsible for transmitting frames from
sender to receiver.
http://www.csi.uottawa.ca/~elsaddik/abedweb/applets/ It can use only the physical layer, which supports only
Applets/Sliding_Window/sliding-window/index.html transmission of a bit at a time.
The DLL has to take into account that transmission errors may
occur
⇒ error control (ACKs, NACKs, checksums, etc.)
The DLL has to take into account that sender and receiver may
operate at different speeds
⇒ flow control (windows, frame numbers, etc.)

Paolo Costa 03 - Data Link Layer Sliding Window Protocols 49 / 55 Paolo Costa 03 - Data Link Layer Examples 50 / 55

High-Level Data Link Control Internet Point-to-Point Connections


This is what may happen when you have an Internet connection to
HDLC: A pretty old, but widely used protocol for point-to-point a provider:
connections. Is bit-oriented.

HDLC uses a sliding window protocol with 3-bit sequencing


The control field is used to distinguish different kinds of frames
contains sequence numbers, acks, nacks, etc. We’d like to use the Internet protocol stack at our home (e.g.,
ADSL)
the bottom line is that we’ll have to transfer IP (network) packets
Question
across our telephone line
What do we need the address field for? Useful on line with Issues:
multiple terminals how can we embed IP packets into frames ?
how can we unpacked at the other end ?
Paolo Costa 03 - Data Link Layer Examples 51 / 55 Paolo Costa 03 - Data Link Layer Examples 52 / 55
PPP: Point-to-Point Protocol PPP
Connection Setup
PPP is the data link protocol for point-to-point connections with
respect to the Internet (home-ISP and router-to-router):
Proper framing, i.e. the start and end of a frame can be Suppose you want to set up a true Internet connection to your provider.
unambiguously detected. 1 Set up a physical connection through your modem
A separate protocol for controlling the line (setup, testing,
negotiating options, and tear-down) (LCP) 2 Your PC starts sending a number of Link Control Packets (LCP) to
Supports many different network layer protocols, not just IP. negotiate the kind of PPP connection you want.
No need for fixed network addresses.
the maximum payload size in data frames
The default frame: do authentication (e.g. ask for a password)
monitor the quality of the link (e.g. how many frames didn’t come
through).
compress headers (useful for slow links between fast computers)
3 Then, we negotiate network layer stuff, like getting an IP address
that the provider’s router can use to forward packets to you.
Address (no data link addresses) Control no seq. number (no reliable transmission)
Protocol LCP / NCP / IP / . . . Payload (up to a negotiated maximum)
Checksum (usually 2 bytes)
Paolo Costa 03 - Data Link Layer Examples 53 / 55 Paolo Costa 03 - Data Link Layer Examples 54 / 55

PPP
Example

Question
If an IP address is dynamically assigned, who does the assignment ? The
provider

Question
If an IP address is dynamically assigned, Can someone else ever send you data
(they don’t know your address, do they?) We need to contact them first (our
address is included in the request).

Paolo Costa 03 - Data Link Layer Examples 55 / 55

You might also like