comcast README

The project's README from github.com/tylertreat/comcast. As one markdown file: README.md.

Comcast

Testing distributed systems under hard failures like network partitions and instance termination is critical, but it's also important we test them under less catastrophic conditions because this is what they most often experience. Comcast is a tool designed to simulate common network problems like latency, bandwidth restrictions, and dropped/reordered/corrupted packets.

It works by wrapping up some system tools in a portable(ish) way. On BSD-derived systems such as OSX, we use tools like ipfw and pfctl to inject failure. On Linux, we use iptables and tc. Comcast is merely a thin wrapper around these controls. Windows support may be possible with wipfw or even the native network stack, but this has not yet been implemented in Comcast and may be at a later date.

Installation

$ go install github.com/tylertreat/comcast@latest

Path addition may be needed

In unix-like systems, after installing comcast with go, it may be needed to add it to the PATH. Go installs by default in $HOME/go/bin.

$ export PATH=$PATH:$HOME/go/bin

Usage

On Linux, Comcast supports several options: device, latency, target/default bandwidth, packet loss, protocol, and port number.

$ comcast --device=eth0 --latency=250 --target-bw=1000 --default-bw=1000000 --packet-loss=10% --target-addr=8.8.8.8,10.0.0.0/24 --target-proto=tcp,udp,icmp --target-port=80,22,1000:2000

On OSX, Comcast will check for pfctl support (as of Yosemite), which supports the same options as above. If pfctl is not available, it will use ipfw instead, which supports device, latency, target bandwidth, and packet-loss options.

On BSD (with ipfw), Comcast currently supports only: device, latency, target bandwidth, and packet loss.

$ comcast --device=eth0 --latency=250 --target-bw=1000 --packet-loss=10%

This will add 250ms of latency, limit bandwidth to 1Mbps, and drop 10% of packets to the targetted (on Linux) destination addresses using the specified protocols on the specified port numbers (slow lane). The default bandwidth specified will apply to all egress traffic (fast lane). To turn this off, run the following:

$ comcast --stop

By default, comcast will determine the system commands to execute, log them to stdout, and execute them. The --dry-run flag will skip execution.

I don't trust you, this code sucks, I hate Go, etc.

If you don't like running code that executes shell commands for you (despite it being open source, so you can read it and change the code) or want finer-grained control, you can run them directly instead. Read the man pages on these things for more details.

Linux

On Linux, you can use iptables to drop incoming and outgoing packets.

$ iptables -A INPUT -m statistic --mode random --probability 0.1 -j DROP
$ iptables -A OUTPUT -m statistic --mode random --probability 0.1 -j DROP

Alternatively, you can use tc which supports some additional options.

$ tc qdisc add dev eth0 root netem delay 50ms 20ms distribution normal
$ tc qdisc change dev eth0 root netem reorder 0.02 duplicate 0.05 corrupt 0.01

To reset:

$ tc qdisc del dev eth0 root netem

BSD/OSX

To shape traffic in BSD-derived systems, create an ipfw pipe and configure it. You can control incoming and outgoing traffic separately for any specific host or network.

$ ipfw add 1 pipe 1 ip from me to any
$ ipfw add 2 pipe 1 ip from any to me
$ ipfw pipe 1 config delay 500ms bw 1Mbit/s plr 0.1

To reset:

$ ipfw delete 1

Note: ipfw was removed in OSX Yosemite in favor of pfctl.

Network Condition Profiles

Here's a list of network conditions with values that you can plug into Comcast. Please add any more that you may come across.

Name Latency Bandwidth Packet-loss
GPRS (good) 500 50 2
EDGE (good) 300 250 1.5
3G/HSDPA (good) 250 750 1.5
DIAL-UP (good) 185 40 2
DSL (poor) 70 2000 2
DSL (good) 40 8000 0.5
WIFI (good) 40 30000 0.2
Starlink 20 - 2.5

comcast (tylertreat/comcast)

Searching Database…

10.5K ·GitHub
这是干什么的?Comcast 是一个命令行工具,用来模拟常见的网络问题——延迟、带宽限制、丢包、乱序和损坏的数据包——让你能构建出在糟糕网络下也能正常运行的系统。
它是我导入的库,还是在我电脑上运行的命令?它是一个在终端里运行的命令。底层它只是对操作系统自带流量控制工具的薄封装,所以它会真正改变这台机器的网络行为。
除了 Go,还需要别的东西吗?它调用的是操作系统自带的工具:Linux 上是 iptables 和 tc,BSD/macOS 上是 ipfw 或 pfctl。Comcast 会检测你的系统有哪些,然后自动选用。
它真的会让我的网络变慢吗?怎么恢复?会——在你撤销之前,流量控制对真实网络流量一直生效。README 里有关闭这些设置的命令,还有手动重置 tc 和 ipfw 的说明。
它支持哪些操作系统?Linux(通过 iptables 和 tc),以及 macOS 等源自 BSD 的系统(通过 ipfw 或 pfctl)。目前还不支持 Windows。
为什么要在糟糕的网络下测试,而不是只模拟严重的故障?因为分布式系统大部分时间都处在网络质量不佳的状态——延迟、丢包、带宽受限——而不是灾难性故障。作者认为这种日常 reality 才是值得测试的东西。
如果我不放心一个在我电脑上执行 shell 命令的工具怎么办?代码是开源的,而且 README 说明了如何手动做同样的事——Linux 上用 iptables 或 tc,BSD/OSX 上用 ipfw 管道——如果你更愿意自己运行命令,或者想要更细粒度的控制。
它在较新版本的 macOS 上还能用吗?能。macOS 从 Yosemite 起移除了 ipfw,改用 pfctl,所以 Comcast 会优先检测并使用 pfctl;如果 pfctl 不可用,就退回到 ipfw,但 ipfw 支持的选项更少。
Creator
tylertreat
Size
0.1 MB
Stars
10.5K
Age
11y
Commits · 90 Days