tc-wrapper
Wrapper & parser of linux tc command (traffic control).
Allow setting, consulting and deleting rules of delay, jitter, bandwidth and corruption
Installation
This module is installed via npm:
npm install --save tc-wrapper
Usage
The library export a instantiable class that has three major methods: del
, get
and set
, for deleting, fetching and setting tc rules.
Keep in mind that set
method will call del
before execute, so it will clean all the rules before aplying the new ones.
Allowed targeting
Currently tc-wrapper only supports ip traffic, and can match by network, src and dst ports.
Allowed modificators
- rate: Bandwith limitation, htb algorith will be used, tbf is not supported (yet).
- delay: Round trip time of packets, will be added as additional time.
- jitter: Delay variation normal-distributed.
- loss: Packet loss, in percentage.
- corrupt: Packet corruption, in percentage.
Clean all rules for eth0
import TCWrapper from 'tc-wrapper';
const tcWrapper = new TCWrapper('eth0');
tc.Wrapper.get().then((rules) => {
});
Increase output packets Round Trip Time by 20 ms
import TCWrapper from 'tc-wrapper';
const tcWrapper = new TCWrapper('eth0');
const myRules = {
outgoing: {
'network=0.0.0.0/0,protocol=ip':{
delay: '20ms'
}
}
};
tc.Wrapper.set(myRules).then((rules) => {
});
Limit incoming bandwith of eth0 to 20 Mbit
import TCWrapper from 'tc-wrapper';
const tcWrapper = new TCWrapper('eth0');
const myRules = {
incoming: {
'network=0.0.0.0/0,protocol=ip':{
rate: '20Mbit'
}
}
};
tc.Wrapper.set(myRules).then((rules) => {
});
Enable debug of module
This module uses debug for debugging, you can enable debug messages of all modules with:
DEBUG=tc-wrapper*
Each module has custom debug label. Example:
DEBUG=tc-wrapper:TCfilterParser
Will only show debug messages about TCfilterParser module.
Run tests
npm test
License (MIT)
In case you never heard about the MIT license.
See the LICENSE file for details.