# The OSI Model
It should be no surprise that communication in digital systems, just like in human communication, is also layered. To define a set of layers in the protocols that digital systems use for communicating is like putting envelopes inside envelopes. Imagine you are sending a letter—a physical letter—to a colleague from an overseas subsidiary of the company you both work for. You would use any international post service for this, where you would write your colleague's office address in the envelope. But because you want the letter to land on her specific desk at her office, you would also put inside the envelope another envelope to be processed by the company receptionist who would then open the envelope, check the floor and desk number, and route the letter accordingly. Granted, this requires the receptionist to open the outer envelope, which is something that needs to be agreed upon for privacy reasons. Communication protocols in digital systems face the same situations.
The definition of protocol layers is somewhat arbitrary, although there is one de facto definition which includes seven layers, called the OSI model.
The OSI model was developed in the late 1970s and early 1980s by the International Organization for Standardization (ISO) as a part of the OSI project. The aim was to create a standardized framework that would enable different systems to interoperate. Before the OSI model, communication between heterogeneous systems was problematic due to the absence of common standards.
The growing complexity of networking methodologies and the need for interoperability was the driving force behind the development of the OSI model. At that time, computer networking was a new and emerging field, and several proprietary networking frameworks existed—like IBM's Systems Network Architecture (SNA) and Digital Equipment Corporation's DECnet—making it challenging for systems to communicate if they did not use the same architecture.
To address these issues, the ISO began working on the OSI model in 1977. By 1984, they had formally released the OSI reference model, ISO 7498. Although the OSI protocols themselves were not widely adopted, the OSI model became extremely influential in the teaching and understanding of network architecture.
The model itself is abstract and not bound to any particular set of network protocols. Instead, it provides a general framework that aligns with the layers of real network protocols and services. The OSI model remains relevant today as a guide for the design of new protocols and the education of network professionals. It helps to conceptualize and visualize network functions, troubleshoot, and understand interlayer and inter-network interactions.
It has seven layers:
The lowest layer, and the layer we will dive a bit deeper in the next sections, is called the [[Physical Layer|physical layer]]. This layer provides a medium for signals to travel across a distance and get converted into symbols that a computer can process and manipulate better. These signals are, in essence, electromagnetic waves propagating in a channel connecting a transmitter and a receiver, which we will call an interconnect. An interconnect is anything that can guide electromagnetic waves from sources to sinks. It can be a copper track in a circuit board, a coaxial wire connecting two racks in a data center, or an optical fiber connecting two cities. Mind you, electromagnetic waves do not need a cable to propagate; they can also propagate in a vacuum, but we will leave that out of the scope of this text as that belongs more to the wireless domain; we will strictly focus on cable-based interconnects. We will especially dive into this layer due to the importance it brings to high-speed digital systems. Other layers include:
==Data Link Layer==: This layer is strictly a local messenger and strictly delivers a collection of ones and zeros ("frames" in this layer's jargon) from one point to another point without asking further questions. Examples of data link layer protocols are Ethernet (see section 2.4.4), SpaceWire, MIL-STD-1553, etc. Many of these protocols' specifications may include the physical layer.
Further up, we have the Network Layer and Upper Layers (Transport, Session, Presentation, Application):
The network layer manages device addressing, tracks the location of devices on the network, and determines the best way to move data. That means that the network layer must necessarily take a peek into the data because it knows a portion of the data might actually be the destination address and it might also mean the chunk of data ("packet" in this layer's jargon) could be targeted to a neighboring network.
---
It should be evident by now that the way data traverses through interconnects needs formatting. This is what packets do: packets are a well-defined collection of bytes consisting of a header, data, and trailer.
Notice that there is nothing in the definition about source and destination addresses, CRCs, minimum lengths, or layers. A packet is simply a data structure with defined starting and ending points. Packets are used everywhere to transfer information. But what do packets have to do with networks? Most data transferred across a network is embedded in some sort of packet.
The network layer may do clever things such as routing packets through different paths according to some routing rules, and fancier operations such as ensuring packets are in the right order or fragmenting them if too large for what the network can handle.
An interesting fact starts to appear: the more ones and zeros a layer needs to spy on—these are called _headers_ in the jargon—the more such data becomes unavailable as user payload data: some metrics consider the ratio of useful/user data vs header data, for instance, *goodput* and protocol efficiency. A classic example of layer 3 is the known old Internet Protocol (IP).

> [!Figure]
> _Header data vs User Data. Credit: NASA._
The fourth layer (transport layer) helps by adding mechanisms to ensure reliable transfers of data from source to destination and vice versa. For sure, adding these facilities contributes to more overhead—the need to transmit information that is not strictly used for the conversation itself. Classical examples of layer 4 protocols are TCP and UDP.
The TCP protocol is a conversational (interactive) protocol due to the fact a complete one-way message involves many source-to-destination signaling round-trips:
- Set-Up: A three-way "Hello" handshake.
- Segment Transfer and Acknowledgement: Each TCP segment (or a few segments) sent by the source is acknowledged by the destination.
- Take Down: A four-way "Goodbye" handshake.
The use of positive or negative acknowledgments to control the retransmission of lost or corrupt segments is called an Automatic Repeat reQuest (ARQ) protocol.

> [!Figure]
> _TCP/IP handshake. Credit: NASA._
From this point on, upper layers go further distilling the information in less and less "machine-like" formats the higher they go, making data increasingly more aligned with the data structures that the application software is expecting at the topmost layer, often paying the penalty of losing efficiency and performance in exchange of readability. For example, HTTP requests sending back and forth [JSON](https://www.w3schools.com/whatis/whatis_json.asp) objects is an effort to transfer data in a way data structures can be populated but also data is human-readable, whereas the underlying layers could not---and should not---care less about these factors; they are comfortable working with obscure, meaningless ones and zeros. In IP-based networks, each hop on a network path can use a different link-layer and physical-layer protocol, but the IP protocol runs on all nodes and the TCP protocol runs only on source and destination hosts. Routers, in their function of forwarding data, use only the lower three protocols. Several other Internet protocols and applications are also used to provide routing-path discovery, path selection, name resolution, and error recovery services.
It is important to note that protocol layers may be encapsulated in some other layers if need be, which is the governing principle of several virtual network technologies (VLAN), for example, VXLAN. VXLAN creates virtualized Layer 2 networks on top of Layer 3 networks. VXLAN allows for the creation of overlay networks by encapsulating Ethernet frames in transport layer packets, with this encapsulation occurring at the network\'s edge and being removed at the destination. VXLAN enables Layer 2 networks to be extended over Layer 3 infrastructures, which is useful in cloud environments where workloads are distributed across different physical locations.
The process involves encapsulating Ethernet frames in a VXLAN header and a UDP header for transmission, and at the destination, these headers are removed to extract the original Ethernet frame. VXLAN Tunnel End Points (VTEPs) are entities that perform encapsulation and decapsulation, and they can be implemented in virtual or physical switches.
In the next section, we will discuss in more detail how data structures are populated at both ends of a communication channel connecting two systems that are very different from each other.

> [!Figure]
> _OSI Layers. Source: #ref/Dubuisson_

> [!Figure]
> _OSI layers and IP routing_