为单元测试创​​建TCP网络错误

为单元测试创​​建TCP网络错误

本文介绍了为单元测试创​​建TCP网络错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在测试期间创建各种网络错误。我在Linux上直接在C ++中使用Berkely套接字API。我在从Boost.Test中监听localhost的另一个线程中运行一个模拟服务器。

I'd like to create various network errors during testing. I'm using the Berkely sockets API directly in C++ on Linux. I'm running a mock server in another thread from within Boost.Test which listens on localhost.

例如,我想在连接期间创建一个超时。到目前为止,我试图不在我的模拟服务器调用接受和设置积压为1,然后进行多个连接,但都似乎成功连接。我想如果在积压队列中没有空间,我至少会得到一个连接拒绝错误,如果不是超时。

For instance, I'd like to create a timeout during connect. So far I've tried not calling accept in my mock server and setting the backlog to 1, then making multiple connections, but all seem to successfully connect. I would think that if there wasn't room in the backlog queue I would at least get a connection refused error if not a timeout.

我想这样做所有的编程,如果可能的话,但我会考虑使用外部像IPchains有意在测试期间将某些数据包丢弃到某些端口,但我需要自动创建和删除规则,所以我可以在我的Boost.Test单元测试。

I'd like to do this all programatically if possible, but I'd consider using something external like IPchains to intentionally drop certain packets to certain ports during testing, but I'd need to automate creating and removing rules so I could do it from within my Boost.Test unit tests.

我想我可以模拟涉及的各种系统调用,但如果可能,我宁愿经历一个真正的TCP栈。

I suppose I could mock the various system calls involved, but I'd rather go through a real TCP stack if possible.

想法?

推荐答案

当我最近进行一些密集协议测试时,我使用了。优点是它相当强大,相对容易访问。如果您安装的是在linux机器上点击为,则可以轻松访问网络元素参数,用于设置和读取它们。因此,您可以将drop元素的丢失率从0更改为100%。虽然它开始有点难度,你可以模拟相当复杂的东西。我个人使用它(例如)这种方式来模拟变化的带宽和丢包情况来测试RTP视频流。

When I did some intensive protocol testing recently I used the click modular router. The advantage is it's quite powerful and relatively easy accessible. If you install click as a kernel module on a linux machine, you can easily reach network elements parameters for both setting and reading them. So you can for example change the loss rate of a drop element from 0 to 100%. While it is a little bit more difficult to get started with, you can simulate quite complex things with it. I personally used it (for example) this way to simulate varying bandwidth and packet loss circumstances to test an RTP video stream.

这篇关于为单元测试创​​建TCP网络错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 08:29