Handout Nivel Retea
Handout Nivel Retea
Computer Networks
Data Link Layer
Paolo Costa
[email protected]
http://www.cs.vu.nl/costa
Vrije Universiteit Amsterdam
1 / 55
Notes
Note
Well just concentrate on transmission issues. Channel access is
discussed in Chapter 4
Paolo Costa
Introduction
2 / 55
Design Issues
Notes
Regulate flow of data: get sender and receiver in the same pace
Paolo Costa
Design Issues
3 / 55
Basic Services
Notes
Question
Why are we so concerned about error-free frame transmissions?
Cant the higher layers take care of that?
Its not mandatory but it may improve efficiency (fine-grained
recovery: frames vs. messages)
Paolo Costa
Design Issues
4 / 55
Transmission
Notes
Design Issues
5 / 55
Routing
Notes
Design Issues
6 / 55
Frames
Notes
Counting
The physical layer doesnt do much: it just pumps bits from one
end to the other.
But things may go wrong
the data link layer needs a means to do retransmissions.
Design Issues
7 / 55
Frames
Notes
Byte Stuffing
Byte stuffing: Mark the beginning and end of a byte frame with two
special flag bytes a special bit sequence (e.g. 01111110). If
such bytes appear in the original frame, escape them:
Paolo Costa
Design Issues
8 / 55
Frames
Notes
Bit Stuffing
Paolo Costa
Design Issues
9 / 55
Notes
Example
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
Error Control
10 / 55
Error Detection
Notes
Parity
Add a bit to a bit string such that the total number of 1-bits is even
(or odd)
e.g., (even parity) 1011010 10110100
(odd parity) 1011010 10110101
Paolo Costa
Error Control
11 / 55
Error Correction
Notes
Example
0000000000
0000011111
1111100000
1111111111
Error Control
12 / 55
Error Correction
Notes
Lower Bound
(n + 1)2m 2n
(m + r + 1) 2r
Paolo Costa
Error Control
13 / 55
Notes
Definition
1
2
4
8
b2
X
b3
X
X
b4
b5
X
b6
b7
X
X
X
X
X
b8
b9
X
b10
b11
X
X
Error Control
14 / 55
Notes
Coding
b1
X
1
2
4
8
b2
X
b3
X
X
b4
b5
X
X
X
b7
X
X
X
b6
b8
X
1
b9
X
X
0
b10
X
b11
X
X
X
0
X
1
Check bits are used to even out the number of 1 bits they
contribute to
e.g., assume the message is 1100001
Check bit at position 2, is used to even out the bits for positions 2,
3, 6, 7, 10, and 11
b2 = 0 as the number of 1s is even (b3 and b11)
Error Control
15 / 55
Notes
Decoding
b1
X
b2
X
b3
X
X
b4
b5
X
b6
X
X
b7
X
X
X
b8
b9
X
b10
X
b11
X
X
X
S:
R:
C:
F:
S: string sent
R: string received
C: string corrected on the check bits: #1 and #8 corrected bit #9 is wrong
(v = 1 + 9)
F: final result after correction
Paolo Costa
Error Control
16 / 55
Notes
Burst Errors
Error Control
17 / 55
Error Detection
Notes
CRC
mk 1 x k 1 + . . . + m1 x 1 + m0 x 0
110001 1x 5 + 1x 4 + 0x 3 + 0x 2 + 0x 1 + 1x 0
=
x5 + x4 + 1
Error Control
18 / 55
Polynomial Arithmetic
Notes
Subtraction
works like addition (only absolute values are used)
(x 4 + x 2 + 1) (x + 1) = x 4 + x 2 x x 4 + x 2 + x
Paolo Costa
Error Control
19 / 55
Polynomial Arithmetic
Notes
Multiplication
It follows the rule of traditional polynomials but, again, addition of
coefficient is done module 2
(x 2 + x)(x + 1) = x 3 + x 2 + x 2 + 1 = x 3 + 2x 2 + 1 x 3 + 1
Division
we can also divide polynomials mod 2 and find the quotient and
remainder
x3 + x2 + x
1
= (x 2 + 1)
x +1
x 1
or in other words:
(x 3 + x 2 + x) = (x 2 + 1)(x + 1) 1
Paolo Costa
Error Control
20 / 55
CRC
Notes
Algorithm
Algorithm
1
Paolo Costa
Error Control
21 / 55
CRC
Notes
Division Example
Error Control
22 / 55
CRC
Notes
Decoding
Error Control
23 / 55
CRC
Notes
Burst Error
Error Control
24 / 55
CRC
Notes
Applications
CRC is not used by the data link layer but also by applications to
check the correctness of a given file
e.g., WinZip
Paolo Costa
Error Control
25 / 55
Notes
from_network_layer(packet *)
to_network_layer(packet *)
from_physical_layer(packet *)
to_physical_layer(packet *)
Basic Protocols
26 / 55
typedef
typedef
typedef
typedef
Notes
typedef struct {
frame_kind kind;
seq_nr seq;
seq_nr ack;
packet info;
} frame;
/*
/*
/*
/*
Basic Protocols
27 / 55
Notes
Issues
Question
What are some of the underlying assumptions here? How does
the flow control manifest itself?
Underlying assumptions are error-free transmission, and
sender-receiver are in pace.
Issue: Fast senders would make receivers collapse
Question
Would a simple delay on senders side fix the problem ?
Not really! Its hard to predict when receivers congestion may
occur.
Assuming always the worst-case behavior would be highly
inefficient
Paolo Costa
Basic Protocols
28 / 55
Simplex Stop-and-Wait
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Notes
After having sent a frame, the sender is required to wait for the ack
Paolo Costa
Basic Protocols
29 / 55
Notes
Question
What are the assumptions in this case? We are assuming only
error-free transmission.
Ok, so assume that damaged frames can be detected
Question
Idea: send the ack only upon correct receipt! Works ? No, because also
the ack can be lost.
Question
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.
Basic Protocols
30 / 55
Notes
Sender
next_frame_to_send indicates which is the last message sent
A timer is started after sending a message
Only if the correct ack is received, the next message is sent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#define MAX_SEQ 1
typedef enum {frame_arrival, cksum_err, timeout} event_type;
void sender3(void) {
int
next_frame_to_send;
frame
s;
packet
buffer;
event_type event;
next_frame_to_send = 0;
from_network_layer(&buffer);
while (true) {
s.info = buffer;
s.seq = next_frame_to_send;
to_physical_layer(&s);
start_timer(s.seq);
wait_for_event(&event);
if (event == frame_arrival) {
from_physical_layer(&s);
if (s.ack == next_frame_to_send) {
stop_timer(s.ack);
from_network_layer(&buffer);
inc(next_frame_to_send);
} } } }
Paolo Costa
Basic Protocols
31 / 55
Notes
Receiver
void receiver3(void) {
seq_nr frame_expected; frame r, s; event_type event;
frame_expected = 0;
while (true) {
wait_for_event(&event);
if(event == frame_arrival) {
from_physical_layer(&r);
if (r.seq == frame_expected) {
to_network_layer(&r.info);
inc(frame_expected);
}
s.ack = 1 - frame_expected;
to_physical_layer(&s);
}
}
}
Paolo Costa
Basic Protocols
32 / 55
Notes
Question
Whats good and bad about piggybacking?
Good: save bandwidth.
Bad: poor performance with irregular transmission rate.
Paolo Costa
Basic Protocols
33 / 55
Sliding Windows
Notes
Question
Is there a relationship between window size, transmission rate, and
propagation delay ? If the propagation delay is high and the window size
is small, transmission rate decreases dramatically because the sender
while waiting for acks cannot send new messages
Paolo Costa
34 / 55
(a) Initially
(c) After receiving frame #1.
Notes
Question
How would you interpret the shaded areas?
Shaded area is to-be-acknowledged (at sender) and
to-be-received next (at receiver).
Paolo Costa
35 / 55
Notes
next_frame_to_send
}
}
Paolo Costa
36 / 55
Notes
Simultaneous Transmissions
The notation is (seq, ack, packet number). * means: passed to network layer
37 / 55
Error Control
Notes
Paolo Costa
38 / 55
Error Control
Notes
Example
(a) Go back n
Paolo Costa
39 / 55
Error Control
Notes
Paolo Costa
40 / 55
Go-back-n (1/2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Notes
41 / 55
Go-back-n (2/2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Notes
while (true) {
wait_for_event(&event);
switch(event) {
case network_layer_ready:
from_network_layer(&buffer[next_frame_to_send]);
nbuffered = nbuffered + 1;
send_data(next_frame_to_send, frame_expected, buffer);
inc(next_frame_to_send);
break;
case frame_arrival:
from_physical_layer(&r);
if (r.seq == frame_expected) {
to_network_layer(&r.info);
inc(frame_expected); }
while (between(ack_expected, r.ack, next_frame_to_send)) {
nbuffered = nbuffered - 1;
stop_timer(ack_expected);
inc(ack_expected); }
break;
case cksum_err: break; /* just ignore bad frames */
case timeout: /* trouble; retransmit outstanding frames */
next_frame_to_send = ack_expected;
for (i = 1; i <= nbuffered; i++) {
send_data(next_frame_to_send, frame_expected, buffer);
inc(next_frame_to_send); }
}
if (nbuffered < MAX_SEQ)
enable_network_layer();
else
disable_network_layer();
} }
Paolo Costa
42 / 55
Go-back-n
Notes
Comments
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
43 / 55
Selective Repeat
Notes
Go-back-n works well if errors are rare, but if the line is poor, it
wastes a lot of bandwidth
An alternative strategy is to allow receiver to accept and buffer the
frames following a damaged or lost one
both sender and receiver maintain a window larger than 1
whenever a frame arrives, its sequence number is checked by the
function between to see if it falls within the window
however, it must be kept within the data link layer and not passed to
the network layer until all lower numbered frames are received
Paolo Costa
44 / 55
Notes
45 / 55
Notes
case frame_arrival:
from_physical_layer(&r);
if (r.kind == data) {
if ((r.seq != frame_expected) && no_nak)
send_frame(nak, 0, frame_expected, out_buf);
else start_ack_timer();
if (between(frame_expected, r.seq, too_far) &&
if(arrived[r.seq % NR_BUFS] == false)) {
arrived[r.seq % NR_BUFS] = true;
in_buf[r.seq % NR_BUFS] = r.info;
while (arrived[frame_expected % NR_BUFS]) {
to_network_layer(&in_buf[frame_expected % NR_BUFS]);
no_nak = true;
arrived[frame_expected % NR_BUFS] = false;
inc(frame_expected);
inc(too_far);
start_ack_timer(); }
}
}
if ((r.kind == nak) &&
if between(ack_expected, (r.ack+1) % (MAX_SEQ+1)
next_frame_to_send))
send_frame(data, (r.ack+1) % (MAX_SEQ + 1),
frame_expected,out_buf);
while (between(ack_expected, r.ack, next_frame_to_send)) {
nbuffered = nbuffered - 1;
stop_timer(ack_expected % NR_BUFS);
inc(ack_expected);
}
break;
Paolo Costa
46 / 55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Notes
case cksum_err:
if (no_nak) send_frame(nak, 0, frame_expected, out_buf);
break;
case timeout:
send_frame(data, oldest_frame, frame_expected, out_buf);
break;
case ack_timeout:
send_frame(ack,0,frame_expected, out_buf);
}
if (nbuffered < NR_BUFS) enable_network_layer();
else disable_network_layer();
}
}
Paolo Costa
47 / 55
Selective Repeat
Notes
Comments
If the receiver delivers all frames in its window just after sending
an ack for the entire window, we may have a serious problem:
Station A
(window size = 4)
01234567
Station B
(window size = 5)
Send window
0 1 2 3 4 5 6 7 Receive 0-3
0 1 2 3 4 5 6 7 Advance window
01234567
Resend window
01234567
Frame #0 is
duplicate
48 / 55
Notes
Demo
http://www.csi.uottawa.ca/~elsaddik/abedweb/applets/
Applets/Sliding_Window/sliding-window/index.html
Paolo Costa
49 / 55
Notes
Now lets 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.
It can use only the physical layer, which supports only
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
Examples
50 / 55
Notes
Question
What do we need the address field for? Useful on line with
multiple terminals
Paolo Costa
Examples
51 / 55
Notes
Wed like to use the Internet protocol stack at our home (e.g.,
ADSL)
the bottom line is that well have to transfer IP (network) packets
across our telephone line
Issues:
how can we embed IP packets into frames ?
how can we unpacked at the other end ?
Paolo Costa
Examples
52 / 55
Notes
Address
Protocol
Checksum
Paolo Costa
Control
Payload
Examples
53 / 55
PPP
Notes
Connection Setup
Paolo Costa
Examples
54 / 55
PPP
Notes
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 dont know your address, do they?) We need to contact them first (our
address is included in the request).
Paolo Costa
Examples
55 / 55
Notes