TCP/IP Transport Layer
The TCP/IP Transport Layer is the fourth layer of the TCP/IP and OSI Network Models. The Transport Layer takes the information given to it from the Application Layer (TCP/IP Model) or the Session Layer (OSI Model) depending on which network model is referenced. When the Application Layer takes the data that it has formed and hands it down the stack to the Transport Layer the Transport Layer receives it and encapsulates it in a Protocol Data Unit referred to as a Segment.
The Segment is a unit of data encapsulation that provides header information for various purposes depending on whether it is TCP or UDP based.
The Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) are the two primary protocols of the Transport Layer. They provide certain benefits but as a consequence lend themselves to certain drawbacks when compared to each-other.
Every computer and server that communicates over an IP network transmits or listens using Port Numbers. Imagine a server that responds to requests that it receives from computers. In this example we will use a web server that offers up web pages to host computers like the one you use to browse the web. What if this computer was also used as an email server? How would it know how to differentiate requests sent to it for web pages versus requests it receives for email? The answer is Port Numbers. Every server needs to “listen” on port numbers so that it can choose which application to send the request to that it hosts. We can liken this to a home with multiple people living in it. Lets say Sally and Bob both live in the same house and their cousin Ed wants to send Bob a letter. Once the letter arrives at the address of the home (like an IP Address) the people in the home need to know which person the letter is addressed to. The name on the letter can be thought of as a “TCP or UDP Port Number“. With the the name of the person on the letter the correct person can receive the letter. Likewise, a server would know which application the request is intended for.
There are a total of 2^16 number of port numbers equaling 65,535 total possible port numbers. There are three main ranges of port numbers. The First 1,023 Port numbers are referred to as “Well Known” port numbers. These port numbers are designated so that application developers can uniformly design their applications (like a web browser) to address their communication according to what is universally accepted by listening applications (like a web server). For example almost all web servers “listen” for incoming web requests on either TCP Port Number 80 (TCP/80) or TCP/443. Likewise, almost DNS servers “listen” to incoming name resolution requests on UDP/53. The other two ranges of TCP and UDP Port Numbers are Registered Port Numbers: 1,024-49,151 and Dynamic/Private Port Numbers: 49,152-65,535. Registered Port Numbers are controlled by the Internet Corporation for Assigned Names and Numbers (ICANN).
Transmission Control Protocol (TCP)
Error Detection and Recovery
The Transmission Control Protocol (TCP) provides Error Detection and Recovery. Because of this it is often referred to as a “Connection Oriented” protocol. As an example, lets say a computer’s web browser wants to go to a website. The computer needs a way to guarantee that the entire website loads appropriately in it’s web browser. In order to accomplish this it needs to be able to detect if information is lost along the way or arrives out of order. TCP provides these benefits by adding certain information to the segments as they are formed. Remember, the segment holds the data inside of it. In order to achieve Error Detection and Recovery certain control information is attached to the segment in what is referred to as a Header. Continuing with our example, the web browser forms a segment and adds a number value to the header called a Sequence Number. The Sequence Number is typically a large integer value but for this example we will use 1, 2 and 3. When forming the first segment the number 1 will be added to the header by the computer. Once the first segment is crafted it forms the next segment and adds a 2 to the header and then the next with a 3. The segments get transmitted to the web server which get received and processed. The number values are evaluated on each segment for correct sequencing (1,2,3…). If the segments arrive out of order, no big deal, the receiving Transport Layer of the web server re-organizes the segments for correct processing. Let’s say that the web server receives segments 1 then 3 but does not get 2. If that happens the web server will send a request back to the computer for the missing segment. Once that happens the computer will re-transmit segment 2 which will be received by the web server. This is an example of Error Detection and Recovery. This is also an example of Same Layer Interaction: two adjacent transport layers on different devices talking back and forth to each-other.
Three Way Handshake
Another aspect of the Connection Oriented design is referred to as as the “Three Way Handshake“. The handshake is initiated by the originating device sending a Synchronization Segment to the receiving device. The receiving device responds with a Synchronization and Acknowledgement to which it is replied to by an Acknowledgement. This is commonly seen in text as SYN/SYN-ACK/ACK.
User Datagram Protocol (UDP)
The User Datagram Protocol (UDP) provides faster data exchange than TCP. However, this comes at the price of Error Detection and Recovery. Since UDP was designed for speed it lacks the inherent benefits of TCP in that UDP data cannot guarantee delivery of information. This does not mean that data delivery services provided by UDP are lost to the application since the applications themselves will typically provide Error Detection and Recovery in the Application Layer instead. As an example, the Voice Over IP Protocol (VOIP) uses the UDP protocol to communicate back and forth between VOIP devices such as phones. Since audio services are typically required to be as synchronous as possible (meaning two people need to hear each-other as fast as possible in order to prevent delay) UDP is employed since it does not have the burden of having to evaluate sequence numbers or comply with the SYN/SYN-ACK/ACK procedure. Therefore UDP is processed and communicated at a much faster rate than TCP. As a result, UDP is commonly referred to as a “Connectionless Protocol“.