Removing the tc config on a particular interface
Asked Answered
S

2

9

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.

Sechrist answered 5/5, 2014 at 22:45 Comment(0)
S
4

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"
Sechrist answered 5/5, 2014 at 23:9 Comment(1)
A simple "sudo tc qdisc del dev eth1 root netem 2>/dev/null || true" should also do the trick as this error is something you expectManganate
N
6

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.

Nyctaginaceous answered 13/6, 2014 at 13:30 Comment(0)
S
4

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"
Sechrist answered 5/5, 2014 at 23:9 Comment(1)
A simple "sudo tc qdisc del dev eth1 root netem 2>/dev/null || true" should also do the trick as this error is something you expectManganate

© 2022 - 2024 — McMap. All rights reserved.