Data Link Layer

We now take a closer look at the data link layer. Recall that the data link layer provides several services:

Framing. The data link layer is charged with packing the data bits into frames, such that each frame can be distinguished from other frames. Question: Why do we need frames? We need frames because of the fact that we break down transmitted into smaller chunks. The receiving node must have some way of determining the start and end of each chunk. That's done via framing, which is handled by the data link layer.

Encapsulating Network Layer Data. The data link layer is also charged with encapsulating the header and trailer into the packet. Recall that the header contains (1) the source MAC address, and (2) the destination MAC address.

Flow Control. ata link layer must also provide flow control services. If the sending node is too fast, the data link layer must slow down the amount of incoming packets to ensure the recipient system doesn't get overwhelmed.

Access Control. The data link layer must provide access control services. These are services that regulate the system's entry and exit from a connection.

Error Control. Finally, the data link layer must also provide error control services. Whenever we transmit data from one node to another, there's always the risk of a packet getting lost. The data link layer's error control services provide either (a) error detection, (b) error correction, or (c) both (a) and (b).

The data link layer consists of two sublayers — (i) the logical link control layer (LLC) and (ii) the MAC layer.

data link sublayers

The LLC, also called the Data Link Control (DLC) layer is charged with handling communications between the network layer and the physical layer. The LLC accomplishes this through a two step process:

  1. Take as input the network layer data.
  2. Add control information (the information needed to enforce the speed limit the system and the recipient agreed to)

MAC Layer

The MAC layer is charged with moving the data it receives from the LLC to the physical layer, and moving the data it receives from the physical layer to the LLC. Typically, this layer is implemented by hardware (the computer's network interface card).

The MAC layer transports data through the following process:

  1. Take the data as input.
  2. Assemble/disassemble: If the data is coming from the LLC, attach the header and trailer frames. If the data is coming from the physical layer, assemble the frames into data (the framing service).
  3. Transport the frames/data.

Alongside framing, the MAC layer also handles error control. What kind of errors is the MAC layer handling? To answer this question, we examine the process of framing.

Framing

When a node A{A} sends data to node B,{B,} the data changes substantially as it moves from layer to layer. The presentation layer adds data, followed by the session layer, the network layer, and so on. Let's say the data sent by A{A} is roughly 50 megabytes.

When the data is sent by the physical layer, however, it's sent as sequence of signals (which we can think of as 0s and 1s), with no clear delimiters. Without more, node B{B} has no way of knowing where specific parts of the data start and end. One section might run for 5 bytes, another 10, and another 25. Or it might be 10, 15, 5. This is precisely what framing is supposed to solve.

There are three flavors of framing techniques: (1) variable-size framing, (2) fixed-size framing, and (3) clock-based framing. We examing each in turn.

Fixed-size Framing

Here's how fixed-size framing works: Before any data is exchanged between A{A}f and B,{B,} they mutually agree that the bits they exchange with one another can be organized into groups of x{x} bits. That is, each frame will be of size x.{x.} Thus, when B{B} receives the bitstream, it will construct a frame every x{x} bits.

Fixed-size framing's primary benefit: It's easy to manage for the receiver and faster to process for the receiver. The receiver simply needs to keep track of how many bits its read, and reset that count everytime it hits x.{x.}

The costs: It can lead to substantial wasted space because of the fixed size. If a chunk of data only takes up 1 byte in reality but x=2{x = 2} bytes, an additional byte must be added to the frame as padding. Inversely, if a chunk of data should ideally be treated as 2 bytes and x=1{x = 1} byte, then the chunk must be split into two separate frames. This leads to increased fragmentation, which increases the risk of packet loss and corruption. Because of these costs, network engineers developed an alternative: variable-size framing.

Variable-size Framing

Here's how variable-size framing works: Before any data is exchanged between A{A} and B,{B,} both A{A} and B{B} must agree on a sequence of bits (called a sentinel) that marks the start and end of frame.

There's a problem here: The substantive data itself contains the sentinel 11011. How does B{B} know which 11011s are sentinels and which are substantive data? The two most common approaches to resolving this problem are bit stuffing and byte stuffing.

Bit Stuffing

In bit stuffing, A{A} and B{B} agree to interpret frames as collections of bits. It doesn't matter what the bits actually represent — be it text, sound, or video — they're just collections of bits. A{A} and B{B} make this agreement by following bit-oriented protocols like HDLC (High-level Data Link Control).

Under HDLC, frames have the following form:

8 bits 16 bits x{x} bits 16 bits 8 bits
begin header body crc end
01111110
address control
... ... 01111110

In an HDLC frame, the begin and end bits are sentinels with the bitsequence 01111110. Importantly, this bit sequence is sent continuously by either A{A} or B{B} (whichever is idle), so long as they maintain a connection. This ensures A{A} and B{B}'s clocks remain in sync throughout the transmission.

The header consists of two subfields: an address field and a control field. The address field is self-explanatory: It contains the necessary address for processing. The control field is more interesting: It determines whether the frame is an I-frame (information frame), S-frame (supervisory frame), or a U-frame (unnumbered frame). The determinants are as follows:

  1. If the first bit is a 0, then the frame is an I-frame — a framed used to number the frame (we'll revisit these frames in detail later).
  2. If the first two bits are 10, then the frame is an S-frame — a frame used for error and flow control.
  3. If the first two bits are 11, then the frame is a U-frame — a frame containing special commands for processing the frame.

The crc (Cyclic Redundancy Check) is used for error detection. This is also where the trailer is found.

The body, contains the payload (the substantive data). This field is of variable size. What if the sentinel bits appear in the payload? The sender places a 0 after every five consecutive 1s it sees. For example, suppose subsequence of the body contains:

 0 1 1 1 1 1   \ldots~0~1~1~1~1~1~\ldots~

when the sender encounters that fifth 1 bit, it immediately places a 0:

 0 1 1 1 1 1 0   \ldots~0~1~1~1~1~1~{\color{salmon}{0}}~\ldots~

then, whenever the receiver sees five ones, it removes the next 0. What are the costs to this approach? Well, the most obvious is overhead. We add additional non-data bits to the stream. Moreover, the shorter a packet is, the more likely we are to bit stuff.

The real problem, however, is that the code rate — the proportion of the body relative to the other fields — is now unpredictable. In some sense, this puts us back at the original problem framing was supposed to solve in the first place — where does the actual substantive data start and end? Viewed this way, it seems as if bit stuffing is a "sweep under the rug" solution. We didn't solve the problem completely, but packaged it into a smaller box and tuck it away.

Byte Stuffing

With byte stuffing, A{A} and B{B} agree to interpret frames as collections of bytes (char values), rather than bits. A{A} and B{B} make this agreement by following any one of several byte-oriented protocols: BSC (Binary Synchronous Communication), DDCMP (Digital Data Communication Message Protocol), and PPP (Point-to-Point Protocol).

BSC Protocol

In the BSC protocol, frames take the following form:

8 bits 8 bits 8 bits8 bits x{x} bits 8 bits 16 bits
syn syn soh header stx body etx crc

The frame starts with two fields, syn and syn (sync fields). The next field is soh (start of header). Then the header itself. The end of the header, and the payload's start, is delimited with the stx (start of text) field. The body is of variable length, delimited by the etx (end of text) field. The frame ends with the crc field, similary to what we saw for HDLC.

Like HDLC, we face the problem of the stx or etx field appearing in the body. The difference: We stuff a byte rather than a bit.

PPP Protocol

The Point-to-Point Protocol (PPP) is another popular byte-oriented protocol.

Clock-based Framing

Clock-based framing drastically departs from fixed- and variable-size framing. This approach essentially asks: Why should we frame according to the transferred data? Why not just use an external clock? The idea is, instead using some fixed length or sentinels, we use a clock that samples frames at specific intervals. Because the frames arrive at B{B} at equidistant points in time, B{B} can readily determine what's a frame and what isn't. A{A} and B{B} can take a clock-based framing approach by following a clock-oriented protocol like SONET (Synchronous Optical Network).

The problem with clock-based framing: It's very expensive and tricky to implement. Clock-based framing requires designers to account for delays due to relativity. It's akin to running a hybrid lecture where some students are in-person, while others are on the moon. The students in-person will hear the lecturer at the same time, but those on the moon will hear the lecturer some time t{t} later. This makes routine tasks difficult. Those on the moon might respond to questions that were asked and answered a few minutes ago.