• Stars
    star
    787
  • Rank 57,828 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tc command wrapper. Make it easy to set up traffic control of network bandwidth/latency/packet-loss/packet-corruption/etc. to a network-interface/Docker-container(veth).

Summary

tcconfig is a tc command wrapper. Make it easy to set up traffic control of network bandwidth/latency/packet-loss/packet-corruption/etc. to a network-interface/Docker-container(veth).

PyPI package version Supported Python versions Test CI status Build CI status

Traffic control

Setup traffic shaping rules

Easy to apply traffic shaping rules to specific network:

  • Outgoing/Incoming packets
  • Source/Destination IP-address/network (IPv4/IPv6)
  • Source/Destination ports

Available parameters

The following parameters can be set to network interfaces:

  • Network bandwidth rate [G/M/K bps]
  • Network latency [microseconds/milliseconds/seconds/minutes]
  • Packet loss rate [%]
  • Packet corruption rate [%]
  • Packet duplicate rate [%]
  • Packet reordering rate [%]

Targets

  • Network interfaces: e.g. eth0
  • Docker container (veth corresponding with a container)

docs/gif/tcset_example.gif

Usage

Set traffic control (tcset command)

tcset is a command to add traffic control rule to a network interface (device).

e.g. Set a limit on bandwidth up to 100Kbps

# tcset eth0 --rate 100Kbps

e.g. Set network latency

You can use time units (such as us/sec/min/etc.) to designate delay time.

Set 100 milliseconds network latency
# tcset eth0 --delay 100ms
Set 10 seconds network latency
# tcset eth0 --delay 10sec
Set 0.5 minutes (30 seconds) network latency
# tcset eth0 --delay 0.5min

You can also use the following time units:

Unit Available specifiers (str)
hours h/hour/hours
minutes m/min/mins/minute/minutes
seconds s/sec/secs/second/seconds
milliseconds ms/msec/msecs/millisecond/milliseconds
microseconds us/usec/usecs/microsecond/microseconds

e.g. Set 0.1% packet loss

# tcset eth0 --loss 0.1%

e.g. All of the above settings at once

# tcset eth0 --rate 100Kbps --delay 100ms --loss 0.1%

e.g. Specify the IP address of traffic control

# tcset eth0 --delay 100ms --network 192.168.0.10

e.g. Specify the IP network and port of traffic control

# tcset eth0 --delay 100ms --network 192.168.0.0/24 --port 80

Set traffic control to a docker container

Execute tcconfig with --docker option on a Docker host:

# tcset <container name or ID> --docker ...

You could use --src-container/--dst-container options to specify source/destination container.

Set traffic control within a docker container

You need to run a container with --cap-add NET_ADMIN option if you you would like to set a tc rule within a container:

docker run -d --cap-add NET_ADMIN -t <docker image>

A container image that builtin tcconfig can be available at https://hub.docker.com/r/thombashi/tcconfig/

Delete traffic control (tcdel command)

tcdel is a command to delete traffic shaping rules from a network interface (device).

e.g. Delete traffic control of eth0

You can delete all of the shaping rules for the eth0 with -a/--all option:

# tcdel eth0 --all

Display traffic control configurations (tcshow command)

tcshow is a command to display the current traffic control settings for network interface(s).

Example

# tcset eth0 --delay 10ms --delay-distro 2  --loss 0.01% --rate 0.25Mbps --network 192.168.0.10 --port 8080
# tcset eth0 --delay 1ms --loss 0.02% --rate 500Kbps --direction incoming
# tcshow eth0
{
    "eth0": {
        "outgoing": {
            "dst-network=192.168.0.10/32, dst-port=8080, protocol=ip": {
                "filter_id": "800::800",
                "delay": "10.0ms",
                "delay-distro": "2.0ms",
                "loss": "0.01%",
                "rate": "250Kbps"
            }
        },
        "incoming": {
            "protocol=ip": {
                "filter_id": "800::800",
                "delay": "1.0ms",
                "loss": "0.02%",
                "rate": "500Kbps"
            }
        }
    }
}

For more information

More examples are available at https://tcconfig.rtfd.io/en/latest/pages/usage/index.html

Installation

Installation: pip

tcconfig can be installed from PyPI via pip (Python package manager) command.

sudo pip install tcconfig

Installation: dpkg (Debian/Ubuntu)

curl -sSL https://raw.githubusercontent.com/thombashi/tcconfig/master/scripts/installer.sh | sudo bash

Dependencies

Linux packages

  • mandatory: required for tc command:
    • Ubuntu/Debian: iproute2
    • Fedora/RHEL: iproute-tc
  • optional: required to when you use --iptables option:
    • iptables

Linux kernel module

  • sch_netem

Optional Python packages

Documentation

https://tcconfig.rtfd.io/

Troubleshooting

https://tcconfig.rtfd.io/en/latest/pages/troubleshooting.html

Docker image

https://hub.docker.com/r/thombashi/tcconfig/

Sponsors

Charles Becker (chasbecker) onetime: Arturi0 onetime: Dmitry Belyaev (b4tman)

Become a sponsor

More Repositories

1

sqlitebiter

A CLI tool to convert CSV / Excel / HTML / JSON / Jupyter Notebook / LDJSON / LTSV / Markdown / SQLite / SSV / TSV / Google-Sheets to a SQLite database file.
Python
841
star
2

pytablewriter

pytablewriter is a Python library to write a table in various formats: AsciiDoc / CSV / Elasticsearch / HTML / JavaScript / JSON / LaTeX / LDJSON / LTSV / Markdown / MediaWiki / NumPy / Excel / Pandas / Python / reStructuredText / SQLite / TOML / TSV.
Python
602
star
3

allpairspy

A python library for test combinations generator. The generator allows one to create a set of tests using "pairwise combinations" method, reducing a number of combinations of variables into a lesser set that covers most situations.
Python
258
star
4

pathvalidate

A Python library to sanitize/validate a string such as filenames/file-paths/etc.
Python
215
star
5

SimpleSQLite

SimpleSQLite is a Python library to simplify SQLite database operations: table creation, data insertion and get data as other data formats. Simple ORM functionality for SQLite.
Python
128
star
6

pytablereader

A Python library to load structured table data from files/strings/URL with various data format: CSV / Excel / Google-Sheets / HTML / JSON / LDJSON / LTSV / Markdown / SQLite / TSV.
Python
105
star
7

DateTimeRange

DateTimeRange is a Python library to handle a time range. e.g. check whether a time is within the time range, get the intersection of time ranges, truncate a time range, iterate through a time range, and so forth.
Python
102
star
8

pingparsing

pingparsing is a CLI-tool/Python-library parser and transmitter for ping command ↪️
Python
77
star
9

pytest-md-report

A pytest plugin to generate test outcomes reports with markdown table format.
Python
32
star
10

subprocrunner

A Python wrapper library for subprocess module.
Python
21
star
11

typepy

A Python library for variable type checker/validator/converter at a run time.
Python
17
star
12

humanreadable

humanreadable is a Python library to convert human-readable values to other units.
Python
16
star
13

DataProperty

A Python library for extract property from data.
Python
15
star
14

cleanpy

cleanpy is a CLI tool to remove caches and temporary files related to Python.
Python
13
star
15

sqliteschema

sqliteschema is a Python library to dump table schema of a SQLite database file.
Python
11
star
16

elasticsearch-faker

elasticsearch-faker is a CLI tool to generate fake data for Elasticsearch.
Python
11
star
17

tcolorpy

tcolopy is a Python library to apply true color for terminal text.
Python
11
star
18

ghscard

A JavaScript widget to generate interactive GitHub user/repository/organization cards for static web pages (like GitHub pages).
JavaScript
10
star
19

excelrd

excelrd is a modified version of xlrd to work for the latest Python versions.
Python
9
star
20

cmakew

cmakew is a CMake wrapper CLI tool.
Python
9
star
21

thank-you-stars

thank-you-stars is a CLI tool to stars to a PyPI package and its dependencies hosted on GitHub ⭐
Python
8
star
22

tabledata

tabledata is a Python library to represent tabular data.
Python
7
star
23

mbstrdecoder

Python library for multi-byte character string decoder.
Python
6
star
24

pytest-discord

A pytest plugin to notify test results to a Discord channel.
Python
5
star
25

tblfaker

tblfaker is a Python library to generate fake tabular data.
Python
5
star
26

CriterionSample

📔 Examples of Criterion (https://github.com/Snaipe/Criterion)
C
5
star
27

python-lib-project-template

A project template for a Python library with CI configurations
Python
5
star
28

envinfopy

envinfopy is a Python Library to get execution environment information.
Python
4
star
29

NFStest

NFStest mirror with command help wiki.
Python
4
star
30

readmemaker

A Python utility library to help make a README file from document files.
Python
4
star
31

retryrequests

A Python library that make HTTP requests with exponential back-off retry by using requests package.
Python
4
star
32

gtest-project-template

C++ test project template using Google Test.
C++
4
star
33

releasecmd

releasecmd is a release subcommand for setup.py (setuptools.setup). The subcommand create a git tag and push, and upload packages to PyPI.
Python
3
star
34

appconfigpy

A Python library to create/load an application configuration file.
Python
3
star
35

msgfy

msgfy is a Python library for convert Exception instance to a human-readable error message.
Python
3
star
36

python-cli-project-template

A project template for a Python CLI tool with CI configurations
Python
2
star
37

homebrew-sqlitebiter

Homebrew Formula for sqlitebiter
Ruby
2
star
38

docker-alias

Docker aliases and functions 🐳
Shell
2
star
39

universal-ctags-installer

Build and installation script for Universal Ctags
Shell
2
star
40

gh-upgrade

gh-upgrade is a gh extension that updates the gh and its extensions to the latest version.
Shell
2
star
41

docker-opengrok

Docker image for OpenGrok
Dockerfile
2
star
42

vscode-snippets

User defined snippets for Visual Studio Code
2
star
43

pytablewriter-altrow-theme

pytablewriter-altrow-theme is a pytablewriter plugin to provide a theme that colored rows alternatively.
Python
1
star
44

thutils

Personal python utility library (may delete in the future)
Python
1
star
45

install-gh

Simple one-liner installer of gh (cli/cli) from the release assets.
Shell
1
star
46

Connectathon_README

Connectathon test suite README
HTML
1
star
47

pathvalidate-cli

pathvalidate-cli is a command line interface for pathvalidate library. The tool can do sanitize/validate a string such as file-names/file-paths.
Python
1
star
48

PythonExamples

📔 Learning Python libraries by examples.
Jupyter Notebook
1
star
49

dotfiles

♻️ dotfiles
Python
1
star
50

df-diskcache

df-diskcache is a Python library for caching pandas.DataFrame objects to local disk.
Python
1
star
51

gh-git-describe

gh extension to execute `git describe` on a remote GitHub repository.
Go
1
star
52

list-sponsors

A CLI tool to list GitHub sponsors of a user/organization with specified format (markdown/html/rst).
Python
1
star
53

pre-commit-bin

Single executable binary packages of pre-commit/pre-commit
Shell
1
star
54

gh-update

gh-update is a gh extension that updates the gh to the latest version.
Shell
1
star