Search code examples
traffictrafficshaping

Removing the tc config on a particular interface


I am new to using the tc command.

I am writing a test script to add delays to an interface. This is being done using python and fabric api

So the script will do something like:

sudo tc qdisc add dev eth1 root netem delay

And at the end of script we would do

sudo tc qdisc del dev eth1 root netem

But at the same time I wanted to make sure at the very beginning that there was no existing tc control that has been done on the system. So I wanted to run the delete command before the whole script started. but that gives me an error if there is no tc config done.

abc@abcvmm:~$ sudo tc qdisc del dev eth1 root netem

RTNETLINK answers: Invalid argument

Is there a way to delete the interface configured only if there is an existing tc config done and not otherwise.


Solution

  • I think I found a way of doing that.

    I can use something like:

    netem_exists= run("tc qdisc show dev eth1 | grep netem | awk '{print $2}'")
            if netem_exists=="netem":
                print "Delete"
                run("sudo tc qdisc del dev eth1 root netem")
            else:
                print "No delete"