Data Link Layer and Framing
In questa pagina 4
Where we are and what it does
The data link layer (DLL) sits above the physical layer and below the network layer (ISO-OSI Model and TCP-IP StackCommunication between two computers is too varied a problem (signals, errors, medium access, routing, flow control, data representation) for a single protocol, so it is divided into layers. The ISO/OSI model has 7 layers (physical, data link, network, transport, session, presentation, application); the TCP/IP stack merges the top three into one application layer, so it has 5. Each layer offers a service to the one above and talks only to its peer layer through PDUs; going down a header (PCI) is added: encapsulation. Addresses: MAC (link, local), IP (network, global), port (transport).ISO-OSI Model and TCP-IP Stack →). Its protocols in the course: ARP, ARQ, HDLC, PPP, LLC, and for medium access ALOHA, slotted ALOHA, CSMA, CSMA/CD, CSMA/CA, and TDMA, FDMA, SDMA, CDMA, OFDMA.
Terminology.
- Nodes: hosts and routers.
- Links: communication channels joining adjacent nodes along the path. A data unit must cross many networks (LANs and WANs) joined by routers; each stretch is a link, possibly point-to-point.
- Frame: the PDU of the link layer. It encapsulates the datagram received from the network layer: its header (PCI) and optional trailer surround the IP datagram, which is the SDU of the frame.
Definition (task of the DLL). Deliver a frame from a node to a physically adjacent node over a link, possibly reliably. Different frames can be carried by different link protocols on different links.
Example (Padova - New York trip). Car from Padova to Venice airport, plane to New York JFK, subway to downtown. The tourist is the frame, each stretch is a link, the means of transport is the link protocol, the travel agency is the routing algorithm (network layer).
Link-layer services
- Framing: encapsulate the datagram in a frame, adding header and trailer.
- Link access (MAC): if the medium is shared, regulate access; the MAC addresses in the headers identify source and destination.
- Flow control: adapt the pace between adjacent sending and receiving nodes (the receiver must not be overwhelmed).
- Error detection: errors are caused by attenuation and noise; the receiver detects an error and asks the sender to retransmit, or discards the frame.
- Error correction: the receiver identifies and corrects wrong bits without retransmission.
The two sublayers
- Data Link Control (DLC): handles the problems common to point-to-point and broadcast links: framing, error control and flow control;
- Medium Access Control (MAC): handles the problems specific to broadcast (shared medium) links: random access, controlled access, channelization (Multiple Access Protocols - ALOHA and CSMAWhen several stations share a medium a medium access (MAC) protocol must decide who transmits. Random access: pure ALOHA (transmit immediately, vulnerable time 2 t_F), slotted ALOHA (start only at slot boundaries, vulnerable t_F), CSMA (listen before talking, vulnerable tau_p) with 1-persistent, non-persistent and p-persistent variants, CSMA/CD (detects collisions while transmitting: needs t_F >= 2 tau_p, hence a minimum frame) and the Wi-Fi CSMA/CA (IFS, contention window with backoff, ACK, RTS/CTS and NAV). Controlled access: reservation, polling, token. Channelization: FDMA, TDMA, OFDMA, CDMA, SDMA.Multiple Access Protocols - ALOHA and CSMA →).
(Other descriptions use the LLC sublayer, Logical Link Control, for local flow and error control.)
Error control. It can be done in two ways: correction (enough redundancy to correct errors: FEC, Forward Error Correction) or detection with retransmission (redundancy suffices to discover an error and the wrong packet is retransmitted: ARQ, ARQ Protocols - Stop-and-Wait, Go-Back-N and Selective RepeatARQ (Automatic Repeat reQuest) makes an error-prone link reliable: the receiver acknowledges (ACK) frames received correctly and the sender retransmits when the timeout expires. Timeouts (against deadlock) and sequence numbers (against duplicates) are needed. With t_G = t_F + 2 tau_p + t_A and error probability p: Stop-and-Wait rho = t_F(1-p)/t_G; Go-Back-N with window N >= t_G/t_F rho = (1-p)/(1+(N-1)p); Selective Repeat rho = 1-p. Efficiency eta = rho I/F. The optimal window is the pipe capacity in packets. For Selective Repeat there is also an optimal frame length: with overhead o and bit error probability P_b, x_opt is about o/2 + sqrt(o/P_b) (shorter frames when the channel errs more).ARQ Protocols - Stop-and-Wait, Go-Back-N and Selective Repeat →). Detection uses a CRC (Cyclic Redundancy Check). Why both exist: a code with minimum distance detects up to errors but corrects only about half, , so correcting costs much more redundancy than detecting; on a link with few errors it pays to detect and retransmit.
Flow control. The sending DLL tries to push frames to the receiver; if the latter cannot process and deliver them to its network layer at the same pace, it is overwhelmed. The receiver may send back to the sender an indication to stop or slow down.
MAC addresses
Definition (MAC address). Link-layer address of 48 bits ( possible addresses), written as hexadecimal digits separated by colons, e.g.
A3:34:45:11:92:F1.
Why digits: each hex digit is bit ( values), so digits, in groups of two (one byte). How many addresses: .
- The first bits are the OUI (Organizationally Unique Identifier) assigned to the manufacturer; the last are specific to the network card (NIC).
- It is local (valid only on the link), fixed for each card and unique worldwide: assigned by the manufacturer.
- For the destination address: unicast (second hex digit even, e.g.
A2:34:45:11:92:F1), multicast (second digit odd, e.g.A3:34:45:11:92:F1), broadcast (all 1s,FF:FF:FF:FF:FF:FF).
Example. On a Linux PC ifconfig shows for eth0 the hardware address 28:d2:44:eb:bd:98 and for wlan0 38:b1:db:7c:78:c7: each card has its own. In 28:d2:... the second digit is 8 (even): unicast.
Why the second digit? The group bit is the least significant bit of the first byte, which lies in the second hex digit (the first digit is the high bits, the second the low bits): if it is (odd digit) the address is a group address. A3 : last bit , multicast. A2 has last bit : unicast. A number is odd if and only if its last binary bit is .
A network interface must have (at least) a link address (MAC) and a network address (IP). When forwarding, a MAC must be associated with the transmission according to the destination node: this is done by ARP (ARP - Address Resolution ProtocolTo place an IP datagram in a frame a node needs the MAC address of the next hop, obtained with ARP: a broadcast request (destination MAC FF:FF:FF:FF:FF:FF, carrying the sender's IP and MAC and the wanted IP) and a unicast reply with the wanted MAC, stored in the ARP cache; ARP always resolves the next hop (destination host or router), never the final destination, and since broadcasts do not leave the subnet a router can answer with its own MAC (proxy ARP).ARP - Address Resolution Protocol →); when a host joins the network it must be assigned an IP (BOOTP, DHCP).
Framing
The physical layer gives bit synchronization (same bit duration and timing for TX and RX), but bits arrive as a continuous stream. The DLL must pack them into frames distinguishable from one another: framing divides the message into smaller parts and adds a source and a destination address (in the header).
Why not send one huge frame:
- a very large frame makes flow and error control inefficient;
- a single wrong bit would force retransmitting everything;
- with small frames a one-bit error affects only that small frame.
Frame size
- Fixed: no delimiters needed, the size itself is the delimiter (example: ATM WAN).
- Variable (the most used): a way to tell where a frame ends is needed.
- Character-oriented (byte-oriented): data are 8-bit characters (ASCII); header and trailer are multiples of 8 bits. To separate a frame from the next, a 1-byte flag is added at the beginning and at the end.
- Bit-oriented: the data part is a sequence of bits to be interpreted as text, graphics, audio, video. A delimiter is needed here too: most protocols use the 8-bit flag
01111110.
The flag-in-data problem and the solution: stuffing
A character equal to the flag may also appear in the data, and the receiver would take it for the end of the frame. The solution is to insert filler bits or bytes: stuffing.
Byte stuffing (character-oriented). When the data contain a byte equal to the flag, a special byte, the escape character (ESC), is inserted before it. When the receiver finds ESC it removes it and treats the following byte as data, not as a delimiter. An ESC in the data must also be preceded by an ESC (otherwise the receiver could not tell a "real" ESC from one preceding a data byte). In the worst case, with data made only of bytes equal to the flag or ESC, every byte doubles: overhead up to .
Example. With flag 7E and ESC 7D, data 41 7E 42 7D 43 become 41 7D 7E 42 7D 7D 43 (two bytes added: one for the 7E, one for the 7D). The receiver removes every ESC and keeps the byte that follows, rebuilding 41 7E 42 7D 43.
Bit stuffing (bit-oriented). If the data contain a 0 followed by five consecutive 1s, the sender inserts right after them an extra 0. Thus the pattern 01111110 of the flag never appears in the data: after stuffing, the data never contain six consecutive 1s (after every group of five 1s there is always an inserted 0), while the flag contains six; if the data contained 01111110 it would become 011111010. The real flag is not stuffed by the sender and is recognized by the receiver. The added 0 is removed by the receiver: every 0 following five consecutive 1s is an inserted 0.
Example. Data 0111111011111111 ( bits). Scan from the left counting consecutive 1s and insert a 0 as soon as five are counted:
0then11111(five 1s) insert a0:0111110; then the sixth 1 of the data and the data0:10;- then
11111(another five 1s) insert a0:111110;111remain.
The result is 0111110 1 0 111110 111 011111010111110111 ( bits: two stuffing bits). The receiver, seeing five 1s followed by a 0, removes that 0 and rebuilds the original bits. In the worst case (all 1s) one bit is added every : ten 1s become 111110111110 ( bits). In general all-1 bits become , with maximum overhead : far less than byte stuffing.
Framing is the tool that later allows numbering frames and protecting them with error control: the subject of ARQ Protocols - Stop-and-Wait, Go-Back-N and Selective RepeatARQ (Automatic Repeat reQuest) makes an error-prone link reliable: the receiver acknowledges (ACK) frames received correctly and the sender retransmits when the timeout expires. Timeouts (against deadlock) and sequence numbers (against duplicates) are needed. With t_G = t_F + 2 tau_p + t_A and error probability p: Stop-and-Wait rho = t_F(1-p)/t_G; Go-Back-N with window N >= t_G/t_F rho = (1-p)/(1+(N-1)p); Selective Repeat rho = 1-p. Efficiency eta = rho I/F. The optimal window is the pipe capacity in packets. For Selective Repeat there is also an optimal frame length: with overhead o and bit error probability P_b, x_opt is about o/2 + sqrt(o/P_b) (shorter frames when the channel errs more).ARQ Protocols - Stop-and-Wait, Go-Back-N and Selective Repeat →. When several nodes share the medium, frames can collide: Multiple Access Protocols - ALOHA and CSMAWhen several stations share a medium a medium access (MAC) protocol must decide who transmits. Random access: pure ALOHA (transmit immediately, vulnerable time 2 t_F), slotted ALOHA (start only at slot boundaries, vulnerable t_F), CSMA (listen before talking, vulnerable tau_p) with 1-persistent, non-persistent and p-persistent variants, CSMA/CD (detects collisions while transmitting: needs t_F >= 2 tau_p, hence a minimum frame) and the Wi-Fi CSMA/CA (IFS, contention window with backoff, ACK, RTS/CTS and NAV). Controlled access: reservation, polling, token. Channelization: FDMA, TDMA, OFDMA, CDMA, SDMA.Multiple Access Protocols - ALOHA and CSMA → and, for Ethernet, LAN - Ethernet and Wi-FiA LAN covers a limited area and is defined by the IEEE 802.x family (802.3 Ethernet, 802.11 Wi-Fi), which splits the link layer into LLC and MAC. Ethernet is connectionless, with no flow control and no ACK; it uses 1-persistent CSMA/CD; the frame is 64 to 1518 bytes (6-byte addresses, type/length, data 46-1500, 4-byte CRC) and the 64 B minimum comes from t_F >= 2 tau_p. From 10 Mbit/s on coax up to 10 Gbit/s on fibre, with full-duplex switches removing collisions. Wi-Fi (802.11) uses CSMA/CA, has BSS (with access point) and ad hoc modes, EBSS with a distribution system, adapts its bitrate to the SNR, and has hidden and exposed terminal problems, partly solved by RTS/CTS and NAV.LAN - Ethernet and Wi-Fi →.
Versione ripasso
- Task of the DLL. Deliver a frame from a node to a physically adjacent node over a link, possibly reliably. The frame is the PDU of the link layer: header and trailer surround the IP datagram. Different links may use different protocols (ISO-OSI Model and TCP-IP StackCommunication between two computers is too varied a problem (signals, errors, medium access, routing, flow control, data representation) for a single protocol, so it is divided into layers. The ISO/OSI model has 7 layers (physical, data link, network, transport, session, presentation, application); the TCP/IP stack merges the top three into one application layer, so it has 5. Each layer offers a service to the one above and talks only to its peer layer through PDUs; going down a header (PCI) is added: encapsulation. Addresses: MAC (link, local), IP (network, global), port (transport).ISO-OSI Model and TCP-IP Stack →).
- Services. Framing (encapsulate the datagram); medium access (MAC) with source and destination MAC addresses; flow control (the receiver must not be overwhelmed); error detection (the receiver asks for retransmission or discards the frame); error correction (corrects bits without retransmission, FEC).
- Sublayers. DLC (Data Link Control): framing, error and flow control, common to point-to-point and broadcast links. MAC (Medium Access Control): only for the shared medium (Multiple Access Protocols - ALOHA and CSMAWhen several stations share a medium a medium access (MAC) protocol must decide who transmits. Random access: pure ALOHA (transmit immediately, vulnerable time 2 t_F), slotted ALOHA (start only at slot boundaries, vulnerable t_F), CSMA (listen before talking, vulnerable tau_p) with 1-persistent, non-persistent and p-persistent variants, CSMA/CD (detects collisions while transmitting: needs t_F >= 2 tau_p, hence a minimum frame) and the Wi-Fi CSMA/CA (IFS, contention window with backoff, ACK, RTS/CTS and NAV). Controlled access: reservation, polling, token. Channelization: FDMA, TDMA, OFDMA, CDMA, SDMA.Multiple Access Protocols - ALOHA and CSMA →).
- Error control. Two ways: correction (FEC, enough redundancy to correct) or detection with retransmission (ARQ, ARQ Protocols - Stop-and-Wait, Go-Back-N and Selective RepeatARQ (Automatic Repeat reQuest) makes an error-prone link reliable: the receiver acknowledges (ACK) frames received correctly and the sender retransmits when the timeout expires. Timeouts (against deadlock) and sequence numbers (against duplicates) are needed. With t_G = t_F + 2 tau_p + t_A and error probability p: Stop-and-Wait rho = t_F(1-p)/t_G; Go-Back-N with window N >= t_G/t_F rho = (1-p)/(1+(N-1)p); Selective Repeat rho = 1-p. Efficiency eta = rho I/F. The optimal window is the pipe capacity in packets. For Selective Repeat there is also an optimal frame length: with overhead o and bit error probability P_b, x_opt is about o/2 + sqrt(o/P_b) (shorter frames when the channel errs more).ARQ Protocols - Stop-and-Wait, Go-Back-N and Selective Repeat →). Detection uses the CRC (Cyclic Redundancy Check).
- MAC address. 48 bits, i.e. addresses, written as 12 hex digits, e.g.
A3:34:45:11:92:F1. The first 24 bits are the manufacturer's OUI, the last 24 are the card's (NIC). Local to the link, fixed per card and unique worldwide. - Destination address types. Second hex digit even: unicast (
A2:...). Odd: multicast (A3:...). All 1s: broadcastFF:FF:FF:FF:FF:FF. The group bit is the least significant bit of the first byte:A3ends in 1, so multicast. - MAC and IP. An interface has at least one MAC and one IP. The destination's MAC is found with ARP; the IP is assigned with BOOTP or DHCP.
- Why framing. The physical layer gives bit synchronization, but the stream is continuous: the DLL splits data into distinguishable frames. Small frames limit damage: a wrong bit forces retransmitting only that frame, not the whole message.
- Frame size. Fixed (the size is the delimiter, e.g. ATM). Variable, the most used, with delimiters:
- character-oriented (byte): 1-byte flag at start and end;
- bit-oriented: flag
01111110(8 bits).
- Byte stuffing. Each data byte equal to the flag (
7E) is preceded by an ESC (7D); an ESC in the data is also preceded by an ESC. The receiver removes each ESC and takes the next byte as data. - Byte stuffing example. Flag
7E, ESC7D: data41 7E 42 7D 43become41 7D 7E 42 7D 7D 43(two bytes added) and the receiver rebuilds41 7E 42 7D 43. - Bit stuffing. After five consecutive 1s in the data the sender inserts a 0. So the flag
01111110never appears in the data. The receiver removes the 0 following five consecutive 1s. The real flag is not stuffed. - Bit stuffing example. Data
0111111011111111(16 bits) become011111010111110111(18 bits, two stuffing bits). Worst case (all 1s): one bit every five; ten 1s become111110111110. Overhead at most 20 %. - Typical mistakes: forgetting to escape the ESC too; believing the MAC is routable (it is local to the link, routing uses IPs); forgetting that stuffing lengthens the frame.