The Layered OSI Model


The Layered OSI Model
With OSI (Open System Interconnection) the International Organization for Standardization (ISO) defined a model for a standardized network that would replace TCP/IP, DECNet, and other protocols, as the primary network protocol used in the Internet. However, because of the complexity of the OSI protocol, not many implementations were built and put to use. TCP/IP was much simpler, and thus can now be found everywhere. But many new ideas from the OSI protocol can be found in the next version of IP, IPv6.
While the OSI protocol didn't catch on, the OSI seven layer model was very successful, and it is now used as a reference model to describe different network protocols and their functionality.
The layers of the OSI model separate out the basic tasks that network protocols must accomplish, and describe how network applications can communicate. Each layer has a specific purpose and is connected to the layers immediately above and below it. The seven layers defined by OSI are shown here:

The application layer defines a programming interface to the network for user applications.
The presentation layer is responsible for encoding data from the application layer ready for transmission over the network, and vice versa.
The session layer creates a virtual connection between applications.
The transport layer allows reliable communication of data.
The network layer makes it possible to access nodes in a LAN using logical addressing.
The data link layer accesses the physical network with physical addresses.
Finally, the physical layer includes the connectors, cables, and so on.
The next picture shows communication between two machines, and how data passes down through the protocol stack on the sender, and up through it on receipt. The D sent from the application on the first machine is shown in the figure as the box containing the letter D. The application layer (layer 7) adds a header to the message (called H7 in the figure), and passes the message to the presentation layer (layer 6), which adds H6 to the message before passing it to the session layer (layer 5). This continues until the message, with all its headers, arrives at the physical network (layer 1) and is transmitted to the receiver. At the receiving side, every layer performs any necessary processing, and removes the relevant header passing the message up to the next layer. At the end of all this, the receiving application accesses the original data sent by the application on the first computer:

Now we understand the concept of these seven layers, we can look at the functionality of each layer in more detail. We'll start at the bottom, and work our way up.
Layer 1: Physical Layer
The physical layer includes the physical environment such as cable requirements, connectors, interface specifications, hub and repeater specifications, and the like. This layer specifies exactly what physical network signal will be used to send a '1', and what will represent a '0'.
Layer 2: Data Link Layer
The MAC address that we've already talked about is a layer 2 address. Nodes on the LAN send messages to each other using IP addresses, and these must be translated to the corresponding MAC addresses by the data layer.
The Address Resolution Protocol (ARP) translates IP addresses to MAC addresses. A cache of known MAC addresses speeds this process, and it can be examined with the arp utility, arp -a, which shows MAC addresses of all recently used nodes in the ARP cache:

The arp utility also allows us to map IP addresses to MAC addresses so that ARP queries for MAC addresses are no longer needed. However, the mapping would break if the network card were replaced, so it should be used with care.
Other responsibilities of the data layer include sending and receiving messages and error detection. With Ethernet, we also have collision detection, as discussed already.
A network switch operates at the data link layer by filtering messages according to their recipients' MAC addresses.
Layer 3: Network Layer
One layer above the data link layer is the network layer. Within layer 3, logical addressing is used to connect to other nodes. MAC addresses of layer 2 can only be used inside a LAN, and we have to use layer 3 addressing when accessing nodes in a WAN.
The Internet Protocol (IP) is a layer 3 protocol; it uses IP addresses to identify nodes on the network.
Routers work at layer 3 to route traffic between networks.
Layer 4: Transport Layer
The network layer identifies hosts by logical addresses. The transport layer identifies an application by what is known as an endpoint. With the TCP protocol, an endpoint is given by a port number and IP address combination.
The transport layer is differentiated according to whether or not we are using reliable or unreliable communication. Reliable communication is when an error is produced if a message was sent but not received correctly, while unreliable communication sends messages without checking if it is received at all. In reliable communication, the transport layer is responsible for sending acknowledgements of data packets, for retransmitting messages if data was corrupted or missing, for discarding duplicate messages, and so on.
Another way network communication can be differentiated at the transport layer is as either connection-oriented or connection-less:
With connection-oriented communication, a connection must be made before messages can be sent or received.
With a connection-less communication, setting up individual connections is not necessary, and messages are sent immediately.
The TCP protocol uses a connection-oriented communication mechanism, while UDP (User Datagram Protocol) uses a connection-less communication mechanism. Connection-oriented communication is reliable as acknowledgements are sent, and retransmitted if data is not received or has become corrupted for any reason. Connection-less communication can be useful with broadcasts where messages are sent to multiple nodes. Here message arrival is not guaranteed. If reliable messaging is needed, reliability can be enforced by a higher-level protocol on top of the connection-less mechanism.
Layer 5: Session Layer
With the OSI model, the session layer defines services for an application, such as logging in and out of an application. The session represents a virtual (logical) connection between applications. The session layer connection is independent of the underlying physical connection at the transport layer, and the virtual connection can exist for a longer time than the connection at the transport layer. Multiple transport layer connections may be required for a single session layer connection.
We can compare this functionality with the functionality offered by ASP.NET session objects. The session objects exist until a session times out (usually 20 minutes), independent of the underlying TCP connection.
Layer 6: Presentation Layer
The presentation layer is used to format the data according to application requirements. Encryption, decryption, and compression typically happen in this layer.
Layer 7: Application Layer
The application layer is the highest layer of the OSI model. This layer contains applications using networking features. These applications can perform tasks such as file transfer, printing, e-mail, web browsing, and more. The example applications that we will create in this book