How to design a TCP connection timeout test?

Source: Internet
Author: User
Document directory
  • 1. Problem:
  • 2. Theoretical calculation:
  • 3. Test Cases
TCP connection timeout and Test Cases

1. Problem:

I encountered a problem at work: If a TCP connection cannot be established due to timeout, what is the timeout time?

2. Theoretical calculation:

This value can be calculated as follows:
In the Linux kernel source code, linux-2.6.18/include/NET/tcp. h defines the following macro

# Define tcp_syn_retries 5/* Number of times to retry active opening
* Connection :~ 180sec is RFC minimum */

# Define tcp_rto_max (unsigned) (120 * Hz ))

Tcp_syn_retries specifies the number of retransmission times when a TCP connection is actively initiated.
Tcp_rto_max specifies the maximum RTO value.
In Linux, set the initial RTO value to 3 S (where ?), At the same time, we know that in the case of retransmission, The Karn algorithm is used to multiply the RTO value, so the timeout time is:

3 + 6 + 12 + 24 + 48 + 96 = 189 seconds

3. Test Cases

The problem is that you need to design a test case to verify the result. At first, I thought the problem was very simple. I tried several methods and did not succeed. The test procedure is as follows:

1. Assume that the IP address of the Linux server for testing is 192.168.0.1, and no network connection is required.

2. Add a 192.168.ing to 192.168.0.2 in the system's ARP cache. The mapped MAC address can be any value. For example, here we use 00: 00: 00: 00: 00: 00: 11

# Ip neigh add 192.168.0.2 lladdr 00: 00: 00: 00: 11 dev eth0

3. Write a simple test program tcpconn to connect to the specified IP address and port.

4. Use the time tool to execute tcpconn to connect an arbitrary port of 192.168.0.2, such as 1000.

# Time./tcpconn 192.168.0.2 1000

5. Finally, the output result of time can verify the above theoretical calculation value.

6. When running this test, you 'd better open another window and use tcpdump to observe the process. If you do not want to write tcpconn, you can also use telnet, but the test results may be slightly different.

 

The key to this test case is to add a ing in the ARP cache to bypass Linux's neighbor discovery ing mechanism. Through this test case, you can better understand the TCP/IP protocol.

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.