simulate-network-conditions
Simulate lossy or high-latency network conditions. Like the throttling option in the Chrome/Chromium DevTools.
Installation
npm install simulate-network-conditions
Usage
Let's simulate an unreliable transport protocol (like UDP, unlike TCP) over a bad 2G connection:
const pipeline = const simulate = const signalStrenth = t % 20_000 / 20_000 const lossy = simulate const slow = simulate // A -> 2G network -> B// B -> 2G network -> A
simulate()
returns a transform stream in object mode.
The stream only represents one-way of network traffic. If you want two-way network traffic as usually required, use two emulate()
streams and duplexer3
:
const duplexer = const aToB = const bToA = // A end of the connectionconst aEnd = // B end of the connectionconst bEnd =
packet processors
A
// every packet delayed by exactly .2ssimulate // jitter: packets randomly delayed by .1-.25s (breaks order!)simulate // 2% lost (randomly)simulate // 3 packets lost, every 20 packetssimulatesimulate // 500ms loss every 3ssimulate
Related
The great Mininet allows you to specify bandwidth, latency & loss, and probably works in a much more accurate way. You can use the mininet
npm package from Node.js.
Contributing
If you have a question or need support using simulate-network-conditions
, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use the issues page.