Hands-On Network Programming with C# and .NET Core
上QQ阅读APP看书,第一时间看更新

The Basic Reference Model

The Basic Reference Model was formalized by ISO as standard ISO-7498 (and as standard X.200 by the ITU, the successor to the CCITT). The model could be cleanly broken into two parts. The first part is the abstract Basic Reference Model for networking. The second is the list of protocols the organizations saw fit to standardize for use by systems that implement the reference model.

The reference model defines network communication streams, as implemented by a compliant device on a network, in a hierarchy of seven distinct conceptual tiers, or layers, organized in a stack. This stack is defined as far down as the transmission of raw bits over physical media, and all the way up to the high-level application software that might use any resource distributed over a network.

For our purposes, as we describe these layers, when we say a layer is higher  in the stack, we mean farther away from the hardware-level transmission of bits across a physical medium.

The model defines a strict mechanism of unidirectional interaction between layers. According to this communication standard, a given layer can only ever communicate with the layer directly beneath it through an abstract interface exposed by that lower layer. This interface is known as the service definition of a layer, and it defines the valid operations by which a higher layer can interact with any lower layers. The interaction model between layers of the OSI network stack shows the same:

As data moves through the layers of the stack, each lower layer wraps the packet in its own series of headers and footers to be parsed by the recipient device. This contains information about what layer in the stack the data originated from, as well as how to parse it. The data packet that gets passed down, layer-to-layer, through the network stack, is known as a Protocol Data Unit (PDU).

While service definitions provide an interface for interaction from one layer to the layer beneath it, protocols provide standardized interaction for an entity at a given level in the network stack to interact directly with a corresponding component at the same level on a remote host. These protocols assume smooth interaction down the stack of the originating host, and then back up the stack on the remote host. Once it has bubbled up the stack to the target layer of the remote host, the protocol determines how the receiving entity should process the data.

So, we can describe the entire process of data transmission through the OSI stack, as follows:

  1. An entity on the originating host creates a data packet, known as a PDU, at a given layer in the network stack, N.
  2. The originating layer passes it down the stack by leveraging the service definition of the layer immediately beneath it.
  3. Lower layers receive the PDU, each wrapping it in a set of headers and footers, to be parsed by the corresponding layer on the remote host.
  4. Once the PDU has been wrapped in headers and footers by the bottom most layer of the stack, it is transmitted to the remote host.
  5. Each layer of the stack on the remote host removes the headers and footers applied by the corresponding layer of the originating host, bubbling the PDU up through the stack.
  6. The PDU is received by layer N on the remote host. The receiving layer then parses the data of the PDU according to the specifications of a protocol for layer Nas specified by the originating host.

And just like that, our data is transmitted, reliably, over the network. That is the complete, if abstract, process of using protocols to transmit data units through the service definitions of each layer in the network stack. I know, it's a lot to take in at once, but it will become slightly more clear as we build up the picture more completely. So, with that, let's look at what the individual layers of the stack are, why they're ordered the way they are, and what they're ultimately responsible for.