October 22, 2024
Chicago 12, Melborne City, USA
python

Mininet bandwidth not updating dynamically via HTTP request in Flask API


I am simulating a custom network topology using Mininet and controlling bandwidth dynamically through a Flask API. The setup involves a server, a router, and two clients. I’m using TCLink in Mininet for bandwidth control and using tc (traffic control) to limit bandwidth per client dynamically.

The code works well initially, and the Flask API successfully executes when I send a request to change the bandwidth for a specific client. However, despite the HTTP request being executed correctly, I don’t see the expected bandwidth change in the monitoring logs, where the bandwidth should be limited to the specified value (e.g., 30 Mbps).

Here’s a summary of the setup:

  • Mininet network: Server, Router, and two clients.
  • Flask API: Allows setting custom bandwidth per client via
    /api/set_bandwidth.
  • Monitoring: Running iperf to monitor bandwidth between clients and
    the server every 5 seconds.
  • Bandwidth control: Using tc (Linux traffic control) to set a TBF rate
    limit for each link.

Example of API call:
I send a POST request to /api/set_bandwidth with the following payload:

{
   "client": "client1",
   "bandwidth": 30
}

Relevant Code Snippets:

  • Flask API for setting bandwidth:

    @app.route("/api/set_bandwidth", methods=["POST"])
    def set_bandwidth():
        data = request.json
        client = data.get("client")
        bandwidth = data.get("bandwidth")
    
        if client not in links:
            return jsonify({"status": "error", "message": "Client not found", "links": list(links.keys())})
    
        link = links[client]
        client_iface = f"{client}-eth0"
        router_iface = f"router-eth{1 if client == 'client1' else 2}"
    
        setCustomBandwidth(link, bandwidth, client_iface, router_iface)
        return jsonify({"status": "success"})
    
    • Setting custom bandwidth using tc:
    def setCustomBandwidth(link, bw, client_iface, router_iface):
        def configure_tc(node, iface, bw):
            node.cmd(f"tc qdisc replace dev {iface} root tbf rate {bw}mbit burst 10kb latency 50ms")
    
        configure_tc(link.intf1.node, client_iface, bw)
        configure_tc(link.intf2.node, router_iface, bw)
    
  • Bandwidth Monitoring:

    def monitorBandwidth(client, server, interval=5):
        while True:
            result = client.cmd(f"iperf -c {server.IP()} -t 1")
            bandwidth = re.search(r"(\d+\.\d+)\sMbits/sec", result)
            if bandwidth:
                bw_value = float(bandwidth.group(1))
                timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                insert_bandwidth_data(client.name, client.IP(), bw_value, timestamp)
            time.sleep(interval)
    

Expected Behavior:
When I set the bandwidth to 30 Mbps via the HTTP request, the monitoring should reflect that the client’s bandwidth does not exceed 30 Mbps. However, the bandwidth remains unaffected.

My Question:
Why isn’t the bandwidth limitation being enforced dynamically when setting the bandwidth via the API, even though the HTTP request executes successfully? Am I missing something in how tc applies the bandwidth changes, or do I need additional configuration in Mininet?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video