Understanding Layer 4 Protocols
To appreciate the part that a content switch plays in the lifecycle of a
Figure 2-5. Different IP protocol
|
|
IP P ROTOCOL N UMBER |
L AYER 4 P ROTOCOL |
|---|---|
|
1 |
ICMP ” Internet Control Message Protocol |
|
6 |
TCP ” Transmission Control Protocol |
|
17 |
UDP ” User Datagram Protocol |
|
112 |
VRRP ” Virtual Router Redundancy Protocol |
Some Layer 4 protocols effectively
In terms of content switching, the two most commonly
Transport Control Protocol (TCP)
As the Layer 3 IP protocol is principally a connectionless and best-efforts delivery mechanism, there is a requirement for many applications to ensure the correctly
Along with these mechanisms, TCP must also be able to uniquely identify each conversation within an internetwork. We've already seen the idea of a TCP port number that is used, among other things, to identify the application process to the high OSI
This combination of source and destination ports, along with the Layer 3 IP addressing, gives TCP the ability to uniquely identify each conversation or session within an internetwork, even in the case of the Internet itself. The Lifecycle of a TCP Session
Let's put these concepts of addresses, ports, and sequencing numbers together and look at how a conversation between two end stations is initiated, sustained, and
1. Initiating a SessionBefore initiating the session, there are two pieces of information upon which the client must decide. First, in order to identify the session uniquely between itself and the server, it selects a TCP port number to represent the session. This port will be the source port for packets from the client to the server and the destination port for packets from the server to the client. The client will select the source port sequentially on a connection-by-connection basis starting from a value greater than 1024. Port numbers below 1024 are typically referred to as well-known ports and are used to identify well-known applications. Table 2-2 shows some well-known reserved ports as defined by IANA. Table 2-2. Some Well-Known TCP Port Number Assignments
The second element that needs to be decided by the client is the starting sequence number. This will be selected based on an internal 32-bit clock that ensures both randomness and that sequence numbers will not overlap should a lost packet reappear some time after its original transmission. Just as with the TCP ports used by both the client and server, each side also uses its own sequence numbering to identify where within the session each frame fits.
Once the client has determined these two
Figure 2-6. The TCP three-way handshake.
Taking this sequence packet by packet, we can see the importance of the port and sequence numbers in ensuring the reliable transport between the client and server. The first frame from the client to the server initiates the connection by setting the client side port and sequence numbers as shown in Figure 2-7. As we can see, the client chooses a random source port that will be used by the client to identify this session uniquely in cases where it has concurrent sessions to the same server. Figure 2-7 The SYN packet sent by the client.
Internet Protocol Headers
Version: 4
Time to live: 128
Protocol: TCP (0x06)
Header checksum: 0xb926 (correct)
Source: 10.10.10.10
Destination: 20.20.20.20
Transmission Control Protocol Headers
Source port: 3086 (3086)
Destination port: http (80)
Sequence number: 713245119
Header length: 28 bytes
Flags: 0x0002 (SYN)
0... .... = Congestion Window Reduced (CWR): Not set
.0.. .... = ECN-Echo: Not set
..0. .... = Urgent: Not set
...0 .... = Acknowledgment: Not set
.... 0... = Push: Not set
.... .0.. = Reset: Not set
.... ..1. = Syn: Set
.... ...0 = Fin: Not set
When the server replies, both the SYN and ACK flags are set in the TCP headers to indicate that the server acknowledges the client's connection request. To ensure that each packet can be accounted for, the server will set an acknowledgment number that is equal to the last byte received from the client, relative to the starting sequence number, plus one. In our example, the client started with a sequence number of 713245119 and transmitted no
It is also important to notice the change in source and destination ports depending on which way a particular packet is directed. In our example, the client sends on port 80 and listens on port 3086, whereas the server sends on port 3086 and listens on port 80. Figure 2-8 shows the return packet from the server to the client.
The final packet exchanged during this handshake period is an acknowledgment from the client to the server. This allows the client to correctly
Figure 2-8 The SYN-ACK packet sent by the server.
Internet Protocol Headers
Version: 4
Time to live: 114
Protocol: TCP (0x06)
Header checksum: 0x9889 (correct)
Source: 20.20.20.20
Destination: 10.10.10.10
Transmission Control Protocol Headers
Source port: http (80)
Destination port: 3086 (3086)
Sequence number: 20072
Acknowledgement number: 713245120
Header length: 28 bytes
Flags: 0x0012 (SYN, ACK)
0... .... = Congestion Window Reduced (CWR): Not set
.0.. .... = ECN-Echo: Not set
..0. .... = Urgent: Not set
...1 .... = Acknowledgment: Set
.... 0... = Push: Not set
.... .0.. = Reset: Not set
.... ..1. = Syn: Set
.... ...0 = Fin: Not set
2. Data TransferOnce the connection has moved into the established state, data transmission can begin between the two end points. During this state, the ACK flag is always set and the two end stations use the sequence and acknowledgment numbering to track the successful delivery of each segment of data. TCP also employs a number of windowing and buffering techniques to ensure the optimal delivery, retransmission, and buffering of data during this state. The discussions of such techniques are outside of the scope of this book. Figure 2-9 The final ACK packet of the handshake.
Internet Protocol Headers
Version: 4
Time to live: 128
Protocol: TCP (0x06)
Header checksum: 0xb92c (correct)
Source: 192.168.254.201 (192.168.254.201)
Destination: 212.58.226.40 (212.58.226.40)
Transmission Control Protocol Headers
Source port: 3086 (3086)
Destination port: http (80)
Sequence number: 713245120
Acknowledgement number: 20073
Header length: 20 bytes
Flags: 0x0010 (ACK)
0... .... = Congestion Window Reduced (CWR): Not set
.0.. .... = ECN-Echo: Not set
..0. .... = Urgent: Not set
...1 .... = Acknowledgment: Set
.... 0... = Push: Not set
.... .0.. = Reset: Not set
.... ..0. = Syn: Set
.... ...0 = Fin: Not set
3. Terminating a SessionUnlike the session initiation, the termination of a TCP connection can be initiated from either side. Once one side of the connection decides that it has no more data to transmit, it will set the FIN flag in the TCP header to indicate to the other side that it is ready to terminate the connection. In simple terms, the receiving station will then acknowledge the FIN, by setting the ACK flag, and set its own FIN flag to show that it too is ready to terminate the connection. This series of exchanges results in both sides moving through the TIME WAIT state to the CLOSED state and the connection is closed. In some instances, when the client receives the FIN it might still have data to send, in which case it will issue only an ACK back to the closing station. This allows the client to continue sending data until it is complete and then issue a FIN to show that the termination of the session can commence. During this period, the initiator and recipient of the initial FIN are referred to as being in the FIN WAIT 2 and CLOSE WAIT states, respectively. Some applications, such as Web browsers, will often use this type of exchange to leave the connection in a type of half-closed state, thereby allowing the connection to be brought back into use when needed without having to reinitiate the entire connection (see Figure 2-10). Figure 2-10. Closing a TCP session.
A more detailed description of TCP can be found in RFC 793. |