
Un wrapper per il comando tc. Rende facile configurare il controllo del traffico di banda/latenza/perdita di pacchetti/corruzione di pacchetti/ecc. su un'interfaccia di rete/contenitore Docker (veth).
.. contents:: tcconfig :backlinks: top :depth: 2
tcconfig <https://github.com/thombashi/tcconfig>__ è un wrapper per il comando tc. Semplifica l'impostazione del controllo del traffico di rete (larghezza di banda/latenza/perdita di pacchetti/corruzione di pacchetti/ecc.) per un'interfaccia di rete/container Docker (veth).
|PyPI pkg ver| |Supported Python ver| |CI status| |CodeQL|
.. |PyPI pkg ver| image:: https://badge.fury.io/py/tcconfig.svg :target: https://badge.fury.io/py/tcconfig :alt: PyPI package version
.. |Supported Python ver| image:: https://img.shields.io/pypi/pyversions/tcconfig.svg :target: https://pypi.org/project/tcconfig :alt: Supported Python versions
.. |CI status| image:: https://github.com/thombashi/tcconfig/actions/workflows/ci.yml/badge.svg :target: https://github.com/thombashi/tcconfig/actions/workflows/ci.yml :alt: Test CI status
.. |CodeQL| image:: https://github.com/thombashi/tcconfig/actions/workflows/build_and_release.yml/badge.svg :target: https://github.com/thombashi/tcconfig/actions/workflows/build_and_release.yml :alt: Build CI status
Impostazione delle regole di shaping del traffico ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Facile da applicare regole di shaping del traffico a reti specifiche:
Parametri disponibili ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I seguenti parametri possono essere impostati sulle interfacce di rete:
[G/M/K bps][microsecondi/millisecondi/secondi/minuti][%][%][%][%][COUNT]Destinazioni ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
eth0veth corrispondente a un container).. image:: docs/gif/tcset_example.gif
tcset)tcset è un comando per aggiungere una regola di controllo del traffico a un'interfaccia di rete (dispositivo).
es. Imposta un limite sulla larghezza di banda fino a 100Kbps ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: console
# tcset eth0 --rate 100Kbps
es. Imposta la latenza di rete ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Puoi utilizzare unità di tempo (come us/sec/min/ecc.) per designare il tempo di ritardo.
Imposta 100 millisecondi di latenza di rete ''''''''''''''''''''''''''''''''''''''''''''''''''' .. code-block:: console
# tcset eth0 --delay 100ms
Imposta 10 secondi di latenza di rete ''''''''''''''''''''''''''''''''''''''''''''''''''' .. code-block:: console
# tcset eth0 --delay 10sec
Imposta 0.5 minuti (30 secondi) di latenza di rete ''''''''''''''''''''''''''''''''''''''''''''''''''' .. code-block:: console
# tcset eth0 --delay 0.5min
Puoi anche utilizzare le seguenti unità di tempo:
.. table::
+------------+----------------------------------------------------------+
| Unità | Specificatori disponibili (str) |
+============+==========================================================+
|ore |``h``/``hour``/``hours`` |
+------------+----------------------------------------------------------+
|minuti |``m``/``min``/``mins``/``minute``/``minutes`` |
+------------+----------------------------------------------------------+
|secondi |``s``/``sec``/``secs``/``second``/``seconds`` |
+------------+----------------------------------------------------------+
|millisecondi|``ms``/``msec``/``msecs``/``millisecond``/``milliseconds``|
+------------+----------------------------------------------------------+
|microsecondi|``us``/``usec``/``usecs``/``microsecond``/``microseconds``|
+------------+----------------------------------------------------------+
es. Imposta 0.1% di perdita di pacchetti ^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: console
# tcset eth0 --loss 0.1%
es. Tutte le impostazioni precedenti contemporaneamente ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: console
# tcset eth0 --rate 100Kbps --delay 100ms --loss 0.1%
es. Specifica l'indirizzo IP del controllo del traffico ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: console
# tcset eth0 --delay 100ms --network 192.168.0.10
es. Specifica la rete IP e la porta del controllo del traffico ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: console
# tcset eth0 --delay 100ms --network 192.168.0.0/24 --port 80
Imposta il controllo del traffico su un container Docker
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Esegui tcconfig con l'opzione --docker su un host Docker:
.. code-block:: console
# tcset <nome o ID container> --docker ...
Puoi utilizzare le opzioni --src-container/--dst-container per specificare il container sorgente/destinazione.
Imposta il controllo del traffico all'interno di un container Docker
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
È necessario eseguire un container con l'opzione --cap-add NET_ADMIN se si desidera impostare una regola tc all'interno di un container:
.. code-block:: console
docker run -d --cap-add NET_ADMIN -t <immagine docker>
Un'immagine container con tcconfig integrato è disponibile su https://hub.docker.com/r/thombashi/tcconfig/
tcdel)tcdel è un comando per eliminare le regole di shaping del traffico da un'interfaccia di rete (dispositivo).
es. Elimina il controllo del traffico di eth0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Puoi eliminare tutte le regole di shaping per eth0 con l'opzione -a/--all:
.. code-block:: console
# tcdel eth0 --all
tcshow)tcshow è un comando per visualizzare le impostazioni correnti del controllo del traffico per una o più interfacce di rete.
Esempio ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: console
# 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"
}
}
}
}
Maggiori esempi sono disponibili su https://tcconfig.rtfd.io/en/latest/pages/usage/index.html
tcconfig può essere installato da PyPI <https://pypi.python.org/pypi>__ tramite
il comando pip <https://pip.pypa.io/en/stable/installing/>__ (gestore di pacchetti Python).
.. code:: console
sudo pip install tcconfig
.. code:: console
curl -sSL https://raw.githubusercontent.com/thombashi/tcconfig/master/scripts/installer.sh | sudo bash
Dipendenze dei pacchetti Python (installate automaticamente) <https://github.com/thombashi/tcconfig/network/dependencies>__tc:
Ubuntu/Debian: iproute2Fedora/RHEL: iproute-tc--iptables:
iptablessch_netemPygments <http://pygments.org/>__https://tcconfig.rtfd.io/en/latest/pages/troubleshooting.html
https://hub.docker.com/r/thombashi/tcconfig/
|chasbecker| |shiguredo| |b4tman| |Arturi0| |github|
.. |chasbecker| image:: https://avatars.githubusercontent.com/u/44389260?s=48&u=6da7176e51ae2654bcfd22564772ef8a3bb22318&v=4 :target: https://github.com/chasbecker :alt: ex-sponsor: Charles Becker (chasbecker) .. |shiguredo| image:: https://avatars.githubusercontent.com/u/2549434?s=48&v=4 :target: https://github.com/shiguredo :alt: ex-sponsor: 時雨堂 (shiguredo) .. |b4tman| image:: https://avatars.githubusercontent.com/u/3658062?s=48&v=4 :target: https://github.com/b4tman :alt: onetime: Dmitry Belyaev (b4tman) .. |Arturi0| image:: https://avatars.githubusercontent.com/u/46711571?s=48&u=57687c0e02d5d6e8eeaf9177f7b7af4c9f275eb5&v=4 :target: https://github.com/Arturi0 :alt: onetime: Arturi0 .. |github| image:: https://avatars.githubusercontent.com/u/9919?s=48&v=4 :target: https://github.com/github :alt: onetime: GitHub (github)
Diventa uno sponsor <https://github.com/sponsors/thombashi>__