模拟网络到特定的进程
我正在尝试模拟一种场景,其中一个进程与服务器的连接已关闭,而与另一台服务器的连接已开启。在我的情况下,仅拉动网络电缆是行不通的,因为我需要另一个过程连接来保持运行。
有没有适合这种工作的工具?我在 Windows 上。谢谢!
I am trying to simulate a scenario where connection to the server of one process is down while the connection to another server is up. Just pulling the network cable won't work in my case since I need another process connection to stay up.
Is there any tool for this kind of job? I am on Windows. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在几个层上进行模拟。最简单的情况是您的两台服务器侦听两个不同的 TCP 端口。在这种情况下,您可以运行两个 tcp 代理,并在想要模拟故障时停止/暂停其中一个。对于 Windows,我建议使用 tcpTrace 来执行此操作。
另一种选择是将两台服务器绑定到两个虚拟 NIC,这些虚拟 NIC 桥接到物理 NIC。当然,如果您有两个物理网卡,则可以将每个服务器进程绑定到不同的物理网卡。
在较低级别,您可以运行 WAN 模拟器。大多数模拟器允许您削弱特定类型的流量或特定端口。此类模拟器之一是 Packetstorm。
我建议的另一种方法是将调试器附加到一个进程,并使用调试器停止该进程上的所有线程。通常,进程不会终止,而是陷入垃圾收集或循环中。由于套接字不会关闭,许多“高可用性”解决方案不会自动进行故障转移。
There's a few layers which you can simulate this at. The easiest would be if your two servers listen on two distinct TCP ports. In that case, you could run two tcp proxies, and stop/pause one when you want to simulate a failure. For Windows I would suggest using tcpTrace to do this.
Another option would be to have the two servers bound to two virtual NICs, which are bridged to the physical NIC. Of course if you have two physical NICs, you could bind each server process to a different physical NIC.
At a lower level, you can ran a WAN simulator. Most simulators allow you to impair specific types of traffic or specific ports. One such simulator is Packetstorm.
One other method which I would suggest is attaching a debugger to one process, and halting all threads on the process with the debugger. Often, a process doesn't die, but gets stuck in garbage collection, or in a loop. As the sockets don't close, many 'high availability' solutions won't automatically failover.
一种方法是模拟相关网络连接代码以进行测试。在这种情况下,您可能想要模拟它返回连接断开时通常会返回的任何内容。
One approach would be to mock the relevant network connection code for the purposes of testing. In this case you would probably want to mock it returning whatever it usually would if the connection was down.
如果您可以在计算机上使用睡眠/休眠模式,那么穷人的方法是:
请注意,它不会模拟网络中断,因为每个连接都会立即失败并出现权限错误。但它阻止了建立连接的过程。
A poor man's approach if you can use sleep/hibernate mode on your machine :
Note that it does not simulate network outage because each connection fails immediately with an permission error. But it prevents a process to establish connections.