Simulate packet loss from the command line
The same program runs without its window. Give it any option and it works in the console instead, which is how a script or a CI job uses it.
How it starts
On Windows it is the same BeanNetworkTester.exe that opens the window: with no
options it opens the window, and with any option it runs in the console and shows no window. From a
copy of the source code, write python bean_network_tester.py in its place. On Linux the
program is ./BeanNetworkTester in the folder you unpacked, and a real capture needs
sudo; Bad network on Linux says what else
it needs there.
The command line always speaks English, whatever the language of the window, so its messages read the same in every log.
Try it without risk first
BeanNetworkTester.exe --simulate --loss 20 --duration 10
BeanNetworkTester.exe --doctor
BeanNetworkTester.exe --config my-settings.json --dry-run
The first runs on made-up traffic, so it needs no driver and no administrator rights and cannot touch the network. The second checks this computer: the rights a capture needs, the capture driver, and leftovers from an earlier run. The third reads a settings file and says whether it is valid, without starting anything.
Where the settings come from
Four sources, each one overriding the one before: the defaults, a settings file
(--config), a ready profile (--preset) and the flags on the command line.
--print-config shows the result as JSON, and --save-config writes it to a
file you can load again, in the window or on the command line.
Every setting in the window has a flag of its own, such as --loss or
--target. They are listed, with what each one does, on
the reference page. The options below are
everything else.
Every other option
The program itself
- --help
Prints every option with a short note, a few examples and the exit codes, then exits.
- --version
Prints the program's version and exits.
- --license
Prints the licence and the notices of the third-party parts the program contains, then exits.
- --gui
Opens the window. Only on its own: the window has its own controls, so it takes no settings from the command line.
- --install-desktop
Linux package only: adds the program to your desktop's applications menu, then exits. Run it as yourself, without sudo.
- --remove-desktop
Linux package only: removes that menu entry again, then exits.
Settings from a file or a profile
- --config
Loads the settings from a JSON file, for example one saved from the window. A profile and the flags on the same line still override it.
- --preset
Loads a ready profile, by its id (presets.3g) or by its name in any language of the window ("3G network"). The profiles and their numbers are on the reference page.
- --print-config
Prints the settings the run would use, after the defaults, the file, the profile and the flags, as JSON, and exits.
- --save-config
Writes the settings this command line adds up to into a JSON file and exits without starting anything. The window and --config can load the file.
How a run goes
- --simulate
Runs on made-up traffic instead of a real capture: no driver, no administrator or root rights, and nothing on the network changes. For trying settings out and for tests.
- --scenario
Plays a scenario file, a timeline that changes the settings at the seconds it names. A ready one can be named as scenarios/cafe-wifi.json from any folder.
- --loop
Plays the scenario again from the start each time it ends, until the run stops.
- --interval
How often a report line is printed, in seconds: more than 0, at most 86400.
- --log-conns
At the end, prints the connections the run saw.
- --repro-out
At the end, writes a JSON report with the settings, the seed and the command that repeats the run.
- --stop-on-stdin-close
Ends the run when standard input closes, as a normal end with its summary. A program that started this one stops it by closing the pipe, and if that program dies, the run ends at once instead of at --duration.
What it prints
- --verbose
Logs what the tool is doing: the settings it uses, the ports it found for a program, scenario steps, the driver opening and closing.
- --quiet
Logs errors only, with no periodic reports.
- --log-level
Sets the log level by name, and wins over -v and -q.
- --log-file
Also appends the log to this file.
- --format
The format of standard output: text for people, or json for a pipeline, one JSON object per line.
Checks for a pipeline and for this computer
- --dry-run
Checks the settings, a settings file and a scenario, then exits without loading the driver or touching any traffic. A cheap check for a pipeline.
- --doctor
Checks this computer and exits: the rights a capture needs, the capture library and driver, leftovers in the temporary folder and a clock that jumped.
- --min-packets
Ends with exit code 6 when fewer than this many packets were captured, which catches a traffic filter that matched nothing.
- --fail-on-no-traffic
The same as --min-packets 1: ends with exit code 6 when nothing was captured at all.
- --cleanup-driver
Windows: unloads a capture driver left behind by an earlier run, which frees its locked file without a restart, then exits.
What it prints
The log, meant for people, goes to standard error, each line starting with
[bean]. Data goes to standard output: a report line every few seconds and a summary at
the end. With --format json, standard output carries one JSON object per line: a
sample object for each report, and a final summary with the exit code,
the seed and the command that repeats the run.
Before the first report comes a start object, written once the capture is running, so a program that starts this one knows when to send its traffic.
BeanNetworkTester.exe --simulate --duration 30 --format json > run.ndjson
Each way a run can end has its own exit code, so a pipeline can tell a failing application from a tool that could not start. The codes are listed on the reference page.
Examples
Impair one program for a minute, and nothing else on the computer:
BeanNetworkTester.exe --target myapp.exe --latency 200 --loss 2 --duration 60
Impair one server for two minutes, with output a pipeline can read, and fail if nothing was captured at all:
BeanNetworkTester.exe --dst-ip 10.0.0.5 --dst-port 443 --loss 5 --duration 120 --format json --fail-on-no-traffic
Play a ready scenario that does not repeat by itself in a loop for ten minutes, and keep a report that repeats the run:
BeanNetworkTester.exe --scenario scenarios/upload-drop-midway.json --loop --target myapp.exe --duration 600 --repro-out run.json
More recipes for pipelines are on Network tests in CI.