Salta al contenuto
Note per Studenti Data Link Layer and Framing Report

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).

  • 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

(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 dmind_{min} detects up to dmin−1d_{min}-1 errors but corrects only about half, ⌊(dmin−1)/2⌋\lfloor(d_{min}-1)/2\rfloor, 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 (248≈2.8⋅10142^{48}\approx2.8\cdot10^{14} possible addresses), written as 1212 hexadecimal digits separated by colons, e.g. A3:34:45:11:92:F1.

Why 1212 digits: each hex digit is 44 bit (16=2416=2^4 values), so 48/4=1248/4=12 digits, in groups of two (one byte). How many addresses: 248=240⋅28≈(1.0995⋅1012)⋅256=2.81⋅10142^{48}=2^{40}\cdot2^{8}\approx(1.0995\cdot10^{12})\cdot256=2.81\cdot10^{14}.

  • The first 2424 bits are the OUI (Organizationally Unique Identifier) assigned to the manufacturer; the last 2424 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 44 bits, the second the low 44 bits): if it is 11 (odd digit) the address is a group address. A3 =1010 0011=1010\,0011: last bit 11, multicast. A2 =1010 0010=1010\,0010 has last bit 00: unicast. A number is odd if and only if its last binary bit is 11.

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 100 %100\,\%.

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 (1616 bits). Scan from the left counting consecutive 1s and insert a 0 as soon as five are counted:

  • 0 then 11111 (five 1s) →\to insert a 0: 011111 0; then the sixth 1 of the data and the data 0: 1 0;
  • then 11111 (another five 1s) →\to insert a 0: 111110; 111 remain.

The result is 0111110 1 0 111110 111 == 011111010111110111 (1818 bits: two stuffing bits). The receiver, seeing five 1s followed by a 0, removes that 0 and rebuilds the original 1616 bits. In the worst case (all 1s) one bit is added every 55: ten 1s become 111110111110 (1212 bits). In general nn all-1 bits become n+⌊n/5⌋n+\lfloor n/5\rfloor, with maximum overhead 1/5=20 %1/5=20\,\%: 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

Teoria collegata