Making traffic you can trust
Outcome: you can generate network traffic whose size, rate, sender, and receiver you know in advance — and then watch bandwhich report it, which turns its screen from something you believe into something you have tested.
A monitor is only worth reading once you have seen it describe traffic whose truth you already know. "Some process was busy" proves nothing. "The download I throttled to one megabyte per second, of a file whose size and hash I know, appeared on the right process at about the right rate" proves the chain works: sniffer, matcher, and sampler, end to end. This chapter builds that traffic. Everything in it is the lab talking to itself — a fixture server and a fixture client, both on the same machine, both started by the lab. That is the pattern to copy on your own machine: practise on traffic you made, never on someone else's.
The fixture
Three pieces, all shipped in
examples/:
- A payload of a stated size.
examples/make-payload.pywrites exactly 10 MiB — 10,485,760 bytes — of a repeating plain-text pattern. The lab's copy has SHA-256707d33427940b1f71edf821567c92863077b3a917c500c8288a29d759f9362e2, so what arrives can be checked byte for byte against what was served. - A server. Python's built-in
http.server, listening on 127.0.0.1 port 18090 — the loopback address, reachable only from this machine:
bash
python3 -m http.server 18090 --bind 127.0.0.1 --directory www
Its process name is python3, which
is the name to expect in bandwhich's
processes table.
- A client with a name of its own.
The lab copied the system curl to a
file named fixture-fetch and ran
that, so the client's process name is
unmistakably fixture-fetch, and used
curl's --limit-rate 1M to hold the
download to at most 1 MiB per second:
bash
./fixture-fetch -s -o downloaded.bin --limit-rate 1M http://127.0.0.1:18090/payload.bin
The rate limit is the teaching trick. Unthrottled, loopback moves 10 MiB in about six hundredths of a second — too fast for a once-a-second display to describe honestly (the lab tried; chapter 10 shows what it made of it). At 1 MiB per second the same file takes about ten seconds: long enough for the sampler to settle and for you to watch several refreshes agree.
What the lab measured
The full raw capture is transcript t02;
the driver's timings are in
examples/transcripts/t02-t03-driver.txt.
The download took 9.811 seconds and
delivered all 10,485,760 bytes,
hash-checked at both ends. Across the
refreshes while it ran:
python3, the server, climbed from 168,148 bytes per second in the first refresh to a peak of 973,548, and held roughly 800,000–870,000 for the middle refreshes. The client limits the flow; the sending process carries it. In a download on one machine, the busy row is the sender — the bytes still have to be sent by someone.fixture-fetch, the client, showed only a few hundred bytes per second of its own — its request and the conversation's housekeeping — because of the oddity the next paragraph names.- Both processes showed down: 0 for the entire run.
That last point is loopback being honest about itself, not bandwhich failing. Direction is decided by whether a packet's source address is one of this machine's own. On loopback, both ends are this machine — every packet's source is local — so every byte lands in the "up" column and the "down" column stays at zero. Chapter 10 returns to this. The practical lesson stands on its own: on loopback, read the pair of process rows, not the direction arrows.
A second run (transcript t03) swapped
the client for wget limited to
2 MiB per second. bandwhich attributed
the flow to wget and python3 —
the attribution follows the programs,
not the brands — and the server's row
peaked at 2,501,702 bytes per
second, above the 2 MiB limit. That
overshoot is real evidence about the
sampler, and chapter 10 explains it
rather than hiding it.
Doing it yourself
You need two terminals: one for bandwhich (started the chapter 4 way, with the privilege), one for the fixture. Start the watcher first, start the transfer second, and let the watcher run a few seconds after the transfer ends — the sampler's tail is part of the lesson. If your machine cannot use port 18090 because something already holds it, pass the fixture any free port; the numbers that matter are the payload size and the rate limit, not the port.
Check: the download's byte count and hash match at both ends; bandwhich's processes table names your server and your client and no one else; and the server's rate settles near — not exactly on — the limit you set. Near, not on: you have met the sampler, and chapter 10 is its biography.