Search code examples
clinuxbandwidthbandwidth-throttling

Controlling network bandwidth


Is it possible to write simple module in C to control network bandwidth. For example, in a 10 GB/s network one should be able to increase/decrease bandwidth over 1-2 GB/s in multiples of 50/100 MB/s.

The objective is to do this using a slider. The user should be able to move a slider right/left in order to increase/decrease bandwidth. Right now I am using iperf, but using that I am just able to measure bandwidth between client/server and not control bandwidth.


Solution

  • I am suggesting you command line tools.

    Wondershaper

    This is the easiest tool I have found to limit bandwidth of a particular interface. All it takes is,

    $ sudo wondershaper {interface} {down} {up}
    

    the {down} and {up} are bandwidth in kilobits. So for example if you want to limit the bandwidth of interface eth1 to 256kbps uplink and 128kbps downlink,

    $ sudo wondershaper eth1 256 128
    

    To clear the limit,

    $ sudo wondershaper clear eth1
    

    Trickle

    Unlike wondershaper, which limits the bandwidth to an entire interface, trickle is user-space bandwidth limiting tool. The syntax is,

    $ trickle -u {up} -d {down} {program}
    

    Both {up} and {down} and bandwidth in KB/s. Now if you invoke it as,

    $ trickle -u 8 -d 8 firefox
    

    It will fire up Firefox, limiting the bandwidth to 8KB/s. This is very useful specially if you are a web developer and want to test your application under various bandwidth conditions.

    Reference http://jwalanta.blogspot.in/2009/04/easy-bandwidth-shaping-in-linux.html