Comparing version 0.2.0 to 0.3.0
@@ -16,4 +16,3 @@ #!/usr/bin/env node | ||
console.log(' --device The device to use [eth0]'); | ||
console.log(' --bandwidth.download Download bandwidth [5Mbps] '); | ||
console.log(' --bandwidth.upload Upload bandwidth [1.6Mbps] '); | ||
console.log(' --bandwidth Bandwidth [5Mbps] '); | ||
console.log(' --latency Latency [28ms]'); | ||
@@ -23,3 +22,3 @@ console.log(' --pl Packet loss in percent [0%] '); | ||
} else { | ||
if (!hasbin.all.sync(['tc', 'modprobe', 'ip'])) { | ||
if (!hasbin.all.sync(['tc'])) { | ||
console.error('You need to have tc in your path to do traffic control'); | ||
@@ -26,0 +25,0 @@ } else { |
112
lib/sltc.js
@@ -7,10 +7,6 @@ 'use strict'; | ||
const merge = require('lodash.merge'); | ||
const Promise = require('bluebird'); | ||
const defaultConfig = { | ||
device: 'eth0', | ||
bandwidth: { | ||
download: '625kbps', | ||
upload: '200kbps', | ||
}, | ||
bandwidth: '5Mbps', | ||
latency: '28ms', | ||
@@ -23,32 +19,8 @@ pl: '0%', | ||
'sudo tc filter add dev %s protocol ip prio 1 u32 match ip dport 80 0xffff flowid 1:11', | ||
// Re-create the root ingress TBF queuing discipline. | ||
'sudo tc qdisc add dev %s ingress handle ffff:', | ||
// Redirect all ingress IP traffic to the IFB. | ||
'sudo tc filter add dev %s parent ffff: protocol ip u32 match u32 0 0 action' + | ||
' mirred egress redirect dev ifb0', | ||
]; | ||
const setupScriptsNoParam = [ | ||
// Set up a known Intermediate Functional Block device (IFB) that we'll redirect the device's | ||
// ingress traffic to. | ||
'sudo modprobe ifb numifbs=1', | ||
'sudo ip link set dev ifb0 up', | ||
// Process all IP traffic on port 80 flowing across the IFB with the 1:11 class. | ||
'sudo tc qdisc add dev ifb0 handle 1: root htb', | ||
'sudo tc filter add dev ifb0 protocol ip prio 1 u32 match ip sport 80 0xffff' + | ||
' flowid 1:11', | ||
]; | ||
const egressRateScripts = [ | ||
const rateScripts = [ | ||
'sudo tc class add dev %s parent 1: classid 1:11 htb rate %s', | ||
]; | ||
const ingressRateScripts = [ | ||
'sudo tc class add dev ifb0 parent 1: classid 1:11 htb rate %s', | ||
]; | ||
const delayLossScripts = [ | ||
@@ -60,4 +32,2 @@ 'sudo tc qdisc add dev %s parent 1:11 handle 10: netem delay %s loss %s', | ||
'sudo tc qdisc del dev %s root', | ||
'sudo tc qdisc del dev %s ingress', | ||
'sudo tc qdisc del dev ifb0 root', | ||
]; | ||
@@ -69,70 +39,22 @@ | ||
if (options.remove) { | ||
return new Promise(function(resolve, reject) { | ||
deleteScripts.forEach((script) => { | ||
if (!(script.includes('%s'))) { | ||
log.info(script); | ||
execSync(script); | ||
} else { | ||
log.info(util.format(script, options.device)); | ||
try { | ||
execSync(util.format(script, options.device)); | ||
resolve(); | ||
} catch (e) { | ||
log.error(e); | ||
reject(Error("Couldn't delete sltc settings")); | ||
} | ||
} | ||
}); | ||
deleteScripts.forEach((script) => { | ||
log.info(util.format(script, options.device)); | ||
execSync(util.format(script, options.device)); | ||
}); | ||
} else { | ||
return new Promise(function(resolve, reject) { | ||
setupScriptsNoParam.forEach((script) => { | ||
log.info(script); | ||
try { | ||
execSync(script); | ||
} catch (e) { | ||
log.error(e); | ||
reject(Error()); | ||
} | ||
}); | ||
setupScripts.forEach((script) => { | ||
log.info(util.format(script, options.device)); | ||
try { | ||
execSync(util.format(script, options.device)); | ||
} catch (e) { | ||
log.error(e); | ||
reject(Error()); | ||
} | ||
}); | ||
egressRateScripts.forEach((script) => { | ||
log.info(util.format(script, options.device, options.bandwidth.upload)); | ||
try { | ||
execSync(util.format(script, options.device, options.bandwidth.upload)); | ||
} catch (e) { | ||
log.error(e); | ||
reject(Error()); | ||
} | ||
}); | ||
ingressRateScripts.forEach((script) => { | ||
log.info(util.format(script, options.bandwidth.download)); | ||
try { | ||
execSync(util.format(script, options.bandwidth.download)); | ||
} catch (e) { | ||
log.error(e); | ||
reject(Error()); | ||
} | ||
}); | ||
delayLossScripts.forEach((script) => { | ||
log.info(util.format(script, options.device, options.latency, options.pl)); | ||
try { | ||
execSync(util.format(script, options.device, options.latency, options.pl)); | ||
} catch (e) { | ||
log.error(e); | ||
reject(Error()); | ||
} | ||
}); | ||
resolve(); | ||
setupScripts.forEach((script) => { | ||
log.info(util.format(script, options.device)); | ||
execSync(util.format(script, options.device)); | ||
}); | ||
rateScripts.forEach((script) => { | ||
log.info(util.format(script, options.device, options.bandwidth)); | ||
execSync(util.format(script, options.device, options.bandwidth)); | ||
}); | ||
delayLossScripts.forEach((script) => { | ||
log.info(util.format(script, options.device, options.latency, options.pl)); | ||
execSync(util.format(script, options.device, options.latency, options.pl)); | ||
}); | ||
} | ||
}, | ||
}; |
{ | ||
"description": "Simple Linux Traffic Control", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"bin": "./bin/sltc.js", | ||
"main": "./lib/sltc.js", | ||
"dependencies": { | ||
"bluebird": "3.4.0", | ||
"hasbin": "1.2.2", | ||
@@ -9,0 +8,0 @@ "intel": "^1.1.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
3929
70
- Removedbluebird@3.4.0
- Removedbluebird@3.4.0(transitive)