Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 638
Akshya11235 Avatar asked May 05 '14 22:05

Akshya11235


People also ask

What is the TC command?

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.

What is TC in Linux kernel?

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.

What is Qdisc in Linux?

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.


2 Answers

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.

like image 74
puneeth Avatar answered Oct 06 '22 14:10

puneeth


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"
like image 22
Akshya11235 Avatar answered Oct 06 '22 14:10

Akshya11235