简体   繁体   中英

How can I automatically test a networking (TCP/IP) application?

I teach students to develop network applications, both clients and servers. At this moment, we have not yet touched existing protocols such as HTTP, SMTP, etc. The students write very simple programs on top of the plain socket API. Currently I check a students' work manually, but I want to automate this task and create an automated test bench for networking applications. The most interesting topics for testing are:

  1. Breaking TCP segments into small parts and delivering them with a noticeable delay. A reason I need such test is that students usually just issue a read/recv call and process the received data without checking that all necessary data was received. TCP doesn't guarantee the message boundaries, so in certain circumstances it is necessary to make several read/recv calls. The problem is that in most simple network applications (for example, in a chat application) messages are small and fit into the single TCP segment, so the issue doesn't appear. My idea is to artificially break messages into several small TCP segments (ie several bytes of data) so the problem will appear.
  2. Pausing the data transfer for some time to simulate multiple slow clients and check that the multithreading/async sockets are implemented properly in the students' servers.
  3. Resetting a connection in random moments of time.

I've found several systems which simulate a bad network (dummynet, clumsy, netem). Hovewer, they all work on the IP level of the stack, so OS and it's TCP implementation will compensate the data loss. Such systems are able to solve the task number 2, but they are not able to solve tasks 1 and 3. So I think that I need to develop my own solution, which will act as a TCP proxy. My questions are:

  1. Maybe the are any libraries or applications which can (at least partially) solve the given tasks, so I'll be able to use them as a base for my own solution?
  2. In case there is none any suitable existing software projects, maybe there are any ideas and approaches about how to do this properly?

From WireShark mailing list - Creating and Modifying Packets :

...There's a "Tools" page on the Wireshark Wiki:

which has a "Traffic generators" section:

which lists some tools that might be useful...

The "Traffic generators" chapter also mentions another collection of traffic generators

If you write your own socket code, you can address all 3 tasks.

  1. enable the socket's TCP_NODELAY option (disable the Nagle Algorithm for Send Coalescing) via setsockopt() , then you can send() small fragments of data as you wish, optionally with a delay in between (see #2).

  2. simply put a delay in between your send() calls.

  3. use setsockopt() to adjust the socket's SO_LINGER and SO_DONTLINGER options to control whether closing the socket performs an abortive or graceful closure, then simply close the socket at some random interval after the connection is established.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM