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.
Tc is used to configure Traffic Control in the Linux kernel. Traffic Control consists of the following: SHAPING When traffic is shaped, its rate of transmission is under control. Shaping may be more than lowering the available bandwidth - it is also used to smooth out bursts in traffic for better network behaviour.
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.
your first step would be: tc qdisc del dev eth1 root
and then: tc qdisc add dev eth1 root handle 1: htb default 100
Checkout my code in my git repo: https://github.com/Puneeth-n/tcp-eval/blob/development/topology/build_net.py
I think I have implemented already what you are trying to implement (using fabric). Or may be you can use parts of the code.
The code makes sure that if there is no error when you are trying to delete a non existing qdisc.
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"
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