Transmission Control Protocol– Cisco Network Transport

The Transmission Control Protocol (TCP) is a connection-oriented transport protocol. Connection-oriented protocols are useful for

• Transmitting large amounts of data, such as large files.

• Transmitting continuing streams where losing information cannot be tolerated, such as stock market information.

For instance, TCP is used for carrying emails and websites because these kinds of data are large and sensitive to data loss.

Building a TCP Connection TCP builds a connection to:

• Make certain transmitted data is received

• Make certain data is transmitted and received in the same order

• Control the transmitter’s speed so neither the network nor the receiver is overwhelmed

Unlike early physically switched telephone networks—like the ones Chapter 13 describes—TCP runs over a packet-based IP network. TCP builds a virtual connection, or session, rather than a physical one, to support streaming over underlying less-than-reliable networks.

TCP uses a three-way handshake to build the initial connection.

Figure 14-10 illustrates the three-way handshake process.

Figure 14-10 TCP Three-way Handshake

The three steps shown in Figure 14-10 are

1.  Host A sends a packet to C indicating it would like to open a new TCP connection. This packet contains an opening sequence number, used to track transmitted and received data, and a port number indicating which application running on C should receive data carried over this session. This packet is often called an SYN.

2.  Host C determines if the application indicated by the port number is running. If the application exists, host C will set aside memory for this connection, build the data structures needed to track the connection state, and send an acknowledgment packet back to A. This packet will also contain a SYN from C, so the connection’s parameters can be set correctly. This packet is often called an SYN-ACK, and the connection is half-open.

3.  Host A learns C is reachable through the network and the correct application is running on C by receiving C’s acknowledgment. To complete the circuit setup, A acknowledges C’s SYN. This packet is often called an SYN-ACK ACK or just an ACK.

Host A uses a port number to indicate which application on C should receive the data carried on in this session. Chapter 2 described port numbers as the address of an application running on a host.

It is not uncommon for hosts to have multiple TCP sessions, as shown in Figure 14-11.

Figure 14-11 Multiple TCP Sessions Between Hosts

In Figure 14-11:

• Application 1, running on host A, has two objects—images, text files, etc.—to send to application 4, running on host C.

Rather than sending these two objects in a single TCP session, A opens two sessions to C.

• Application 3, running on host A, opens a separate TCP session to host C to send data to application 4.

TCP will open one session per application. Applications may also open more than one TCP session. Two TCP sessions running in parallel will transfer data faster than a single session until the network, or one of the two hosts, runs out of resources.

There are two ways TCP on host A can terminate the session:

• Stop sending data. If A doesn’t send data for a while, B will terminate the session.

• Send a reset, or RST, packet.

TCP Flow and Error Control

Applications rely on TCP to deliver packets without errors and without overwhelming the network or receiver. TCP uses sliding window flow control to accomplish these goals. Figure 14-12 illustrates windowed flow control.

Figure 14-12 Windowed Flow Control

Let’s look at the labels in Figure 14-12 before looking at how windowed flow control works:

• On the far left, T1 through T8 indicate periods of time.

Whether these are seconds, milliseconds, or something in between does not matter.

• The next column, starting with 3500 at the top, is how many octets of data A can transmit at this moment in time.

• The center portion of the illustration shows packets A has transmitted, and B has not acknowledged. Each packet has a label ( 1 through 6) and a size. Each packet also has a sequence number, which is not shown in the illustration.

• The arrows from B to A represent acknowledgments for data transmitted from B to A.

• The far-right column tells you which packets of data B is acknowledging.

The window size in Figure 14-12 is 4000 octets, which means  A may send a total of 4000 octets of data to B before waiting for B to acknowledge receiving some data. In Figure 14-12:

• T1: A transmits a single 500-octet packet of data toward B, labeled packet 1. Packet 1 will have a sequence number of 1. The window size is 4000 octets, so A can still transmit another 3500 octets of data before waiting for an acknowledgment.

• T2: As far as A can tell, packet 1 is still “in flight,” either carried through the network or processed at B. A transmits packet 2, which has a length of 1000 octets. Packet 2’s sequence number will be 501; packet 1’s sequence number will be added to packet 1’s length. A can still transmit another 2500 octets of data before waiting for B to acknowledge receiving any data.

• T3: Packets 1 and 2 are in flight, but A can still send up to 2500 octets of data. A sends packet 3, which is 1500 octets long. A can only send another 1000 octets of data before being forced to wait for B to acknowledge receiving some packets it has already transmitted. Packet 3’s sequence number is set to 1501, and packet 2’s sequence number is added to packet 2’s length.

• T4: B receives packet 1 and sends an acknowledgment (shown as ACK 1 in Figure 14-12).  A can now send 1500 more octets of data—the 1000 octets it could send at T3 plus the 500 octets B just acknowledged receiving.

• T5: Packets 2 and 3 are still in flight, but A can send another 1500 octets of data without waiting on B. A transmits packet 4, which is 1500 octets. A cannot send more data until B acknowledges receiving some packets, so its window is now set to 0. Packet 4’s sequence number is set to 3001, packet 3’s sequence number plus packet 3’s length.

• T6: B acknowledges receiving packets 2 and 3. A can now send up to 2500 octets of data before being forced to wait on B.

• T7: Packet 4 is still in flight. A transmits packet 5, leaving it with 2000 octets it can send before being forced to wait on B.  Packet 5’s sequence number is 4501, and packet 4’s sequence number is added to packet 4’s length.

• T8: A sends packet 6, so it can only send 500 octets before being forced to wait on B. Packet 6’s sequence number is 5001, and packet 5’s sequence number is added to packet 5’s length.

By examining the sequence numbers, B can tell the network has dropped a packet. For instance, if packet 5 were dropped when B receives packet 6, it will notice the 500-octet “gap” in the sequence numbers:

• Packet 4’s sequence number is 3001, and its length is 1500 octets.

• Packet 6’s sequence number is 5001, and its length is 1500 octets.

Subtracting packet 4’s length from packet 6’s sequence number leaves a gap of 500 octets, so a 500-octet packet must have been dropped someplace. A gap in the sequence numbers can be caused by A sending B data too fast or because a router’s queue filled up, forcing the router to drop the packet.

B can also verify each packet has been transmitted without error using the checksum included with each packet. Corrupted packets are intentionally dropped at B.

If B detects a dropped packet, it will send A a retransmit request. Missing packets—no matter the reason—always mean the transmitter needs to slow down.

This example uses 4000 octets as a window size. In actual TCP implementations, the window size varies over time.

When a transmitter receives a retransmit request, it closes the window and enters slow start. Closing the window means the transmitter will wait for the receiver to acknowledge receiving data more often; less data will be in flight at any given time.

As data is successfully transmitted (each time the receiver acknowledges receiving data), the window size is opened or grows larger.

Note Algorithms used to calculate the correct window size based on network conditions are complex and outside the scope of this book.

Leave a Reply

Your email address will not be published. Required fields are marked *