The Link-Layer Protocols

As was mentioned earlier, Ethernet and Wi-fi are the protocols that are widely used to connect devices in wired or wireless settings. Hence, we will provide a quick overview of their basic workings here.

Ethernet

Ethernet went through various phases and evolved over time. This meant that changes were made in the specifications, both at the hardware level and on the associated protocols.

Initially, Ethernet aimed to connect multiple computers over a shared coaxial cable, which would act as a broadcast-transmission medium. This topology is also known as a bus topology, as shown in the following illustration.

This meant that any data transmitted by a node would be received by all of the other nodes connected to that particular cable.

The network interface card was responsible for reading the metadata of each packet and passing the packets only to the processor they were addressed. In order to carry out this process, each network interface card owns one or multiple unique addresses, which are known as MAC (media access control) addresses. These are 48-bit numbers, which are allocated by the IEEE association.

Every Ethernet frame contains a source and a destination MAC address with the latter being used by a network interface card to identify the frames destined to it. There are also some special addresses which allow us to send a frame to multiple network interface cards at a given time. One such example is the broadcast address, which is only composed of bits set to one (also represented as FF:FF:FF:FF:FF:FF) and is accepted by all the nodes. The frame also contains other fields, as shown in the illustration below.

  • The preamble is a static value, which is used to synchronize the clocks of the sender and the receiver so that the subsequent data is translated in the right way by the recipient.

  • The EtherType field contains an identifier, which indicates the network-layer protocol the data should be passed to.

  • The payload field carries the data of the network-layer protocol

  • The CRC is used to detect bit errors.

Since the medium is shared, if two stations attempt to transmit at the same time, a collision may occur, which can lead to corruption of the transmitted data. Therefore, early versions of Ethernet used a variant of CSMA, known as CSMA/CD, to recover from such collisions and transmit data successfully.

For the CSMA/CD protocol to operate efficiently, the specific length limits for a cable segment are specified. This keeps the propagation delay of a collision and signals degradation down to tolerable levels.

Later on, the bus topology was replaced by a star topology, in which multiple nodes were connected to a device called repeater or hub with twisted-pair copper wire, as shown in the illustration below.

Hub

A hub is a physical-layer device, which acts on individual bits rather than frames. When a bit arrives from one interface, the hub recreates the bit, boosts its signal strength, and transmits the bit onto the other interfaces. As a result, Ethernet with a hub-based star topology remains a shared-broadcast medium, which means that CSMA/CD is still used.

Note:There are advantages to using star topology as opposed to bus topology. For example, star topology allows for easier installation into buildings that already use star topology cable plans for telephony and better fault-tolerance, as it is able to able to easily disconnect faulty peers and prevent them from affecting other devices on the network.

The next and most recent evolution led to the replacement of hubs at the center of the star topology with devices called switches, which operate at the link layer. This is shown in the following illustration.

Switch

A switch receives link-layer frames and forwards them to the specific outgoing links they are addressed to. In order to do this, the switch maintains a switch table that maps MAC addresses to the corresponding interfaces that lead to them. This is done automatically, without the need for manual configuration or extra protocols.

The switch table is initially empty, and the switch adds entries to the table by inspecting the source addresses of incoming frames and associating them to the interface they arrived from.

Note: Every time a switch receives an incoming frame, it searches for an entry that contains the destination address in the table. Recent advancements mean that switches may be able to perform forwarding based on more complicated logic, using more information than just the destination MAC address. One such example of this is the OpenFlow protocolN. McKeown et al., “OpenFlow: Enabling Innovation in Campus Networks,” ACM SIGCOMM Computer Communication Review, March 2008, 2008.. However, we intentionally focused on the original and simplest use here.

For each frame, a switch finds the interface that corresponds to the destination address. If there is no such entry, the frame is forwarded to all the other interfaces, that is, all interfaces except the one it was received on. This is called flooding and is the reason why switches are said to be self-learning or plug-and-play devices.

In cases where nodes are directly connected to switches in a full-duplex mode, there is no possibility of a collision, which means that there is no need for a medium access control protocol, such as CSMA/CD, and the link’s bandwidth is utilized more efficiently.

Note: The use of a switch instead of a hub can also lead to the overall reduction of traffic. Reduced broadcast traffic can, in turn, lead to increased performance in the network.

Wifi

Wi-Fi uses two basic modes of operation:

  • Ad-hoc mode
  • Infrastructure mode

Ad-hoc mode

In ad-hoc mode, each node transmits data directly to other nodes.

Infrastructure mode

In infrastructure mode, communication typically goes through a central access point (AP), which connects wireless devices (stations) to a wired network. Infrastructure mode is used more widely and in most everyday scenarios, so we will focus on that.

In this mode, there is a basic service set (BSS), which is a group of stations that are all connected to the same access point. Each access point is associated with an identifier, known as the Service Set Identifier (SSID), which is configured by the administrator.

Note: Every wireless station needs to be associated with an access point before it can send or receive data to or from the rest of the network.

Association

Association is performed in the following way: APs periodically transmit special messages, called beacon frames, which contain the access point’s SSID and MAC address. The wireless station listens for these messages and selects one of them for association or presents them to the user. The user selects a message via the user interface. This process of listening to the medium for beacon frames is known as passive scanning.

A wireless device can also perform active scanning by broadcasting a probe frame that is received by all the access points within the wireless device’s range. Access points respond to the probe request frame with a probe response frame. The device sends an association request frame to the access point, and the access point responds with an association response frame to associate with an AP.

Once the association is complete, the device starts to send and receive data frames to and from the network.

Given that there can be many wireless devices sharing the same medium, a multiple access protocol is needed to coordinate the transmissions. For this reason, 802.11 makes use of CSMA with collision avoidance (CSMA/CA).

Collision detection is replaced with collision avoidance, because the received signal is, typically, weak compared to the strength of the transmitted signal at the 802.11 adapter. Hence, it is costly to build hardware that can detect a collision.

Compared to wired links, wireless links suffer from higher signal attenuation and interference, which makes it more likely for transmitted data to be corrupted. For this reason, an acknowledgment protocol is used where a recipient replies to a data message with an acknowledgment message to let the sender know that the message was received intact. If the message is not received intact or if the acknowledgment message is lost, the sender will try to send the message again.

The stations introduce additional delays when they sense that the channel is not idle, in order to ensure that another node is not trying to send a frame at the same time. This is the collision avoidance part and is introduced because in this protocol, the nodes do not stop transmitting when there is a collision (that is, there is no collision detection).

Hidden terminal problem

Wireless links are also subject to a problem known as the hidden terminal problem. There are cases where two stations are unable to detect each other’s transmissions because they are too far from each other, while still being within the access point range. This is shown in the following illustration.

The Wifi protocol contains an optional mode, where a station can transmit a specific message to the access point to get access to transmit, known as Request to Send (RTS). If no other device is transmitting, the access point replies with a message, known as Clear to Send (CTS). The CTS is received by all the devices associated with the access point, which reserves the medium for the corresponding station.

Types of frames

In general, there are three types of frames, namely:

  • Data frames: These are used to transmit data payloads between nodes.
  • Control frames: These are used to facilitate the exchange of data frames, CTS/RTS and acknowledgment frames are examples of control frames.
  • Management frames: These are used for the maintenance or discontinuation of communication. Beacon frames or probe requests are examples of management frames.

The frame structure shares many similarities with Ethernet.

The payload contains the payload of an encapsulated higher-level protocol and a CRC that protects against transmission errors.

The frame contains four MAC addresses as can be seen in the following illustration.

  • Address 1 is the direct receiver
  • Address 2 is the direct transmitter
  • Address 3 is the indirect receiver/transmitter

These addresses correspond to the access point, the source station, and the destination station, respectively, for frames that are sent by a station to the access point in order to be delivered to another station. Alternatively, they correspond to the destination station, the access point, and the source station, respectively, for frames that are sent by an access point to the final destination station. The frame also contains sequence numbers for deduplication purposes, a duration field used for reserving the channel, and a frame control field that contains various sub-fields, such as the protocol version, the type of the frame (for example, data, control, or management), and so on.

Get hands-on with 1400+ tech skills courses.