Bandwidth Controller & Monitoring

The purpose of this program is to remotely monitor the bandwidth usage of the platform on which it is installed, and to dynamically manipulate the bandwidth usage of the platform network interfaces. The communication interface between the remote system and the system being monitored is performed through the CoAP transmission protocol. The server side where the monitored system receives new commands or simply the latest bandwidth usage and transfer the requested measurement to the requester.

The test environment is composed of a Raspberry Pi 3B+, a remote computer and Firefox (version 55.0.3 or lower) that supports the CoAP plugin[1]. The newest version of the Firefox does not unfortunately support the CoAP plugin.

The software wraps indeed two Linux programs, namely, wondershaper and ifstat to provide an easy usage to manipulate the network interface. The source code hasn’t been dockerized, therefore the installation of those programs are required. Wondershaper allow us to change the upload&download amount for a specific interface, whereas ifstat is utilized for the bandwidth monitoring purposes.

Wondershaper[2,3]

We can start the wondershaper with some initial parameters as below:

coap://<target-IP>:10001/bwController/limit?netint=eth0&upload=1000&download=1000
  • netint = network interface
  • upload = KB/s
  • download = KB/s

It is also possible to start with a duration parameter, which executes the wondershaper for a specific amount of time. For instance, the following URL will run this software only 3 secondes, afterwards wondershaper configuration will be removed:

coap://<target-IP>:10001/bwController/limit?netint=eth0&upload=1000&download=1000&duration=3
  • duration = seconds

As we can define a number of rules, we can also manually remove all configuration of a network interface below:

coap://<target-IP>:10001/bwController/clear?netint=eth0

ifstat[4]

As mentioned before, the bandwidth monitoring is operated through the ifstat Linux command and it is performed with the following URL:

coap://<target-IP>:10001/bwMonitoring/measure?netint=eth0&wTime=1&mCount=2
  • netint = network interface
  • wTime = waiting Time for each taken measurement
  • mCount = the number of the measurement to be taken

Based on the given parameters, we can give the interval of the measurement times and the number of the total measurements to be taken. Afterwards, it is possible to retrieve the measurement results with the following URL:

coap://<target-IP>:10001/bwMonitoring/read

The intention in this software was to create a REST-based bandwidth monitoring and controlling system. If the bandwidth observation is important and analyzed later on, it is recommended to replace the CoAP protocol with a pub/sub system, i.e. MQTT. The source code of the software can be acceded via this reference[5].

Creating Environment and Testing

Test Environment: Linux Ubuntu Required Tools: wondershaper, ifstat

sudo apt-get install wondershaper trickle ifstat

Run the controller on the side where the bandwidth will be controlled:

$ python BandwidthController.py

Open Firefox Coap Client and search for the published services and call them:

coap://<target-IP>:10001/bwController
coap://<BandwidthController-IP Address>:10001/bwController

The usages of wondershaper and ifstat on the Linux console:

$wondershaper <interface> <download-rate> <upload-rate>
# ifstat -i etho <timeToBeWaited> <MeasurementCount>
$ ifstat -t -i eth0 1 1 > bwmon.log

References:

  1. https://github.com/Tanganelli/CoAPthon
  2. https://github.com/cemakpolat/bw-monitoring-controller
  3. http://kb.bodhost.com/how-to-control-bandwidth-in-linux/
  4. https://github.com/magnific0/wondershaper
  5. https://www.redhat.com/sysadmin/ifstat-network-statistics