Chapter 18 TCP Connection Establishment and Termination
2016-09-20 23:05:29 0 举报
AI智能生成
TCP/IP 卷一详解版
作者其他创作
大纲/内容
18.1 Introduction
TCP is connection-oriented protocol. Before either end can send data to the other, a connection must be established between them.
18.2 Connection Establishment and Termination
To see what happens when a TCP connection is established and then terminated , we type the following command on the system svr4: telnet bsdi discard
tcpdump Output
Figure 18.1 shows the tcpdump output for the segments generated by this command
Time Line
Figure 18.3 shows the time line for this sequence of packets. This figure shows which end is sending packets.
Connection Establishment Protocol
Now let's return to the details of the TCP protocol that are shown in Figure 18.3 . To establish a TCP connection.
Connection Termination Protocol
While it takes three segments to establish a connection, it takes four to terminate a connection. This is caused by TCP's half-close.
Normal tcpdump Output
Having to sort through all the huge sequence numbers is cumbersome, so the default tcpdump output show the complete sequence numbers only on the SYN segment, and shows all following sequence numbers as relative offsets from the original sequence numbers.
18.3 Timeout of Connection Establishment
There are several instances when the connection can't be established . In one example the server host is down. To simulate this scenario we issue our telnet command after disconnecting the Ethernet cable from the server's host .
First Timeout Period
One puzzling item in Figure 18.6 is that the first timeout period, 5.8 seconds, is close the 6 second , but not exact , while the second period is almost exactly 24 second.
Type-of-Service Field
In Figure 18.6 , the notation appears . This is the type-of-service field in the IP datagram . The BSD/386 Telnet client sets the field for minimum delay
18.4 Maximum Segment Size
The maximum segment size is the largest "chunk" of data that TCP will send to the other end. When a connection is established , each end can announce its MSS. The values we've seen have all been 1024. The resulting IP datagram is normally 40 bytes larger: 20 bytes for the TCP header and 20 bytes for the IP header.
18.5 TCP Half-Close
TCP provides the ability for one end of a connection to terminate its output , while still receiving data from the other end. This is called a half-close. Few applications take advantage of this capability , as we mentioned earlier.
18.6 TCP State Transition Diagram
We've described numerous rules regarding the initiation and termination of a TCP connection. These rules can be summarized in a state transition diagram, which we show in Figure 18.12
2MSL Wait State
The TIME_WAIT state is also called the 2MSL wait state. Every implementation must choose a value for the maximum segment lifetime(MSL). It is the maximum amount of tim any segment can exist in the network before being discarded.
Quiet Time Concept
The 2MSL wait provides protection against delayed segments from an earlier incamation of a connection from being interpreted as part of a new connection that uses the same local and foreign IP addresses and port number.
FIN_WAIT_2 State
In the FIN_WAIT_2 state we have sent our FIN and the other end has acknowledged it . Unless we have done a half-close, we are waiting for the application on the other end to recognize that it has received an end-of-file notification and close its end of the connection, which sends us a FIN.
18.7 Reset Segments
We've mentioned a bit in the TCP header named RST for "reset". In general , a reset is send by TCP whenever a segment arrives that doesn't appear correct for the referned connection.
Connection Request to Nonexistent Port
A common case for generating a reset is when a connection request arrives and no process is listening on the destination port . In the case of UDP ,we saw in Section 6.5 that an IGMP port unreachable was generated when a datagram arrived for a destination port that was not in use.
Aborting a Connection
We saw in Section 18.2 that the normal way to terminate a connection is for one side to send a FIN. This is sometimes called an orderly release since the FIN is sent after all previously queued data has been sent , and there is normally no loss of data.
Detecting Half-Open Connections
A TCP connection is said to be half-open if one end has closed or aborted the connetion without the knowledge of the other end. This can happen any time one of the two hosts crashes.
18.8 Simultaneous Open
It is possible , although improbable, for two applications to both perform an active open to each other at the same time.
18.9 Simultaneous Close
We said earlier that one side performs the active close, causing the first FIN to be sent. It's also possible for both sides to perform an active close, and the TCP protocol allows for this simultaneous close
18.10 TCP Option
The TCP header can contain options(Figure 17.2 ) . the only options defined in the original TCP specification are the end of option list, no operation, and the maximum segment size option.
18.11 TCP Server Design
We said in Section 1.8 that most TCP servers are concurrent. When a new connection request arrives at a server, the server accepts the connection and invokes a new process to handle the new client.
TCP Server Port Numbers
We can see how TCP handles the port numbers by watching any TCP server. We'll watch the Telnet server using the netstat command.
Resticting Local IP Address
We can see what happens when the server does not wildcard its local IP address, setting it to one particular local interface address instead.
子主题 2
Restricting Foreign IP address
In Section 11.12 we saw that a UDP server can normally specify the foreign IP address and foreign port, in addition to specifying the local IP address and local port.
Incoming Connection Request Queue
A concurrent server invokes a new process to handle each client, so the listening server should always be ready to handle the next incoming connection request.
18.12 Summary
0 条评论
下一页