In the last chapter, we have learned that layer 1 is responsible for the physical transmission of data between connected machines. The physical layer receives that data from the layer right above it: Layer 2, “Data Link Layer”.
Data Link Layer Roles
The data link layer has two main roles :
- It allows communication between two machines, whether they are connected directly with each other, or connected through a layer 2 network equipment that simulates a direct link. One example of such equipment is the switch, which I will talk about later in this chapter.
- Layer 2 also has an important role in detecting errors that might occur as a result of the physical transmission conducted by layer 1.
In case only two machines are connected, then communication is easy: There will always be one recipient. No confusion there.
However, if more than two machines are connected, then communication will get more complicated: If one computer needs to send a message to another, then it needs to address it directly without other machines knowing. Otherwise, the confidentiality of the communication would be compromised.
To solve this problem, the researchers have come up with an addressing mechanism that would allow each machine to be identified throughout its lifetime using a physical address hardwired into its Network Interface Card (NIC). This address is called MAC address. It is unique to the NIC, meaning that you cannot find two machines in the world with the same MAC address.
The MAC address is 48 bit long (6 octets), and is generally written in hexadecimal in the following format:
The first three octets identify the manufacturer, while the last three identify the NIC.
There is one special address that you need to know before we move on : The broadcast address. It is used to send a message to all the machines connected to the network. In this address, all bits are equal to 1, which result in the following address:
If a computer sends a message to this address, then all computers present in the network will receive it.
A network switch is a Layer 2 network equipment that serves in connecting multiple machines in a single network. When connected by a switch, the machines are said to be in the same LAN (Local Area Network).
This is how a switch looks like:
As you can see in the image, this switch has 24 ports. Each port can connect one computer, so this switch can support up to 24 computers. There are of course different types of switches that can have a various number of ports. You can also connect a switch with another switch to have an even bigger LAN.
The switch keeps a table associating each port with the MAC address of the machine connected to it. This way, it always forwards the traffic to the correct destination.
In the first chapter, we have talked about how each layer encapsulates data that it receives before it can send it down to the next layer. Well, in the case of layer 2, this encapsulation is done using Ethernet.
Ethernet is the main communication protocol for layer 2. There are of course other protocols that operate on the data link layer, but by far the most common one is Ethernet.
Ethernet adds 4 pieces of information during the encapsulation process:
- Destination MAC address.
- Source MAC address.
- Layer 3 protocol.
- CRC: A number that the sending machine calculates based on the content of the message before sending it. The receiving machine will calculate that same number, and verify that it is equal to the one that it has received. If they’re not equal, then this means that an error has occurred and the message has changed.
The Layer 2 data after encapsulation is called a frame and it looks something like this:
Now that you understand how machines communicate within a Local Area Network (LAN), it is now time to venture outside the LAN. But to do this, we need to go up one layer higher. In the next chapter, we will talk about the network layer.