Where can I learn about controlling/interrogating the network interface under Linux? I'd like to get specific application upload/download speeds, and enforce a speed limit for a specific application.
I'd particularly like information that can help me write a traffic shaping application using Python.
tc (traffic control) is the user-space system administration utility program used to configure the Linux kernel packet scheduler. Tc is usually packaged as part of the iproute2 package.
qdisc. Simply put, a qdisc is a scheduler (Section 3.2). Every output interface needs a scheduler of some kind, and the default scheduler is a FIFO. Other qdiscs available under Linux will rearrange the packets entering the scheduler's queue in accordance with that scheduler's rules.
A traffic shaper works by delaying metered traffic such that each packet complies with the relevant traffic contract. Metering may be implemented with, for example, the leaky bucket or token bucket algorithms (the former typically in ATM and the latter in IP networks).
To enable the traffic shaping feature, go to the Network tab and make sure the Configuration Mode is set to Advanced. Then scroll down and click the checkbox to enable Traffic Shaping.
You want the iproute2 suite, in which you use the tc command. tc commands look like
tc class add dev eth2 parent 1: classid 1:1 htb rate 100Mbit ceil 100Mbit quantum 1600
Here's an existing Python traffic-shaping application that uses iproute2.
It is actually quite hard shaping per application using the linux kernel tools, unless the application uses specific ip addresses and/or ports you can match on.
Assuming that is the case then you'll need to read up on iptables
and in particular fwmarks. You'll also need to read up on tc
. In combination those two tools can do what you want. The Linux Advanced Routing & Traffic Control is a good place to start.
Assuming your application doesn't use a predictable set of ports/ip addresses then you'll need to use a userspace shaper like Trickle. This inserts itself between the application and the kernel and shapes the traffic for that application in userspace.
I don't think there are any direct python bindings for any of those tools, but it would be simple to script them using python and just calling the executables directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With