
tc コマンドラッパー。ネットワーク帯域幅/遅延/パケットロス/パケット破損などのトラフィック制御を、ネットワークインターフェースや Docker コンテナ(veth)に簡単に設定できるようにします。
.. contents:: tcconfig :backlinks: top :depth: 2
tcconfig <https://github.com/thombashi/tcconfig>__ は tc コマンドのラッパーです。ネットワークインターフェースや 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 パッケージバージョン
.. |Supported Python ver| image:: https://img.shields.io/pypi/pyversions/tcconfig.svg :target: https://pypi.org/project/tcconfig :alt: 対応 Python バージョン
.. |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: テスト CI ステータス
.. |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: ビルド CI ステータス
トラフィックシェイピングルールの設定 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 特定のネットワークに対するトラフィックシェイピングルールを簡単に適用できます:
利用可能なパラメーター ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ネットワークインターフェースには以下のパラメーターを設定できます:
[G/M/K bps][マイクロ秒/ミリ秒/秒/分][%][%][%][%][COUNT]対象 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
eth0veth).. image:: docs/gif/tcset_example.gif
tcset コマンド)tcset はネットワークインターフェース(デバイス)にトラフィック制御ルールを追加するコマンドです。
例:帯域幅を 100Kbps に制限する ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: console
# tcset eth0 --rate 100Kbps
例:ネットワークレイテンシを設定する ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 遅延時間の指定には時間単位(us/sec/min など)を使用できます。
100 ミリ秒のネットワークレイテンシを設定 ''''''''''''''''''''''''''''''''''''''''''''''''''' .. code-block:: console
# tcset eth0 --delay 100ms
10 秒のネットワークレイテンシを設定 ''''''''''''''''''''''''''''''''''''''''''''''''''' .. code-block:: console
# tcset eth0 --delay 10sec
0.5 分(30 秒)のネットワークレイテンシを設定 ''''''''''''''''''''''''''''''''''''''''''''''''''' .. code-block:: console
# tcset eth0 --delay 0.5min
以下の時間単位も使用できます:
.. table::
+------------+----------------------------------------------------------+
| 単位 | 利用可能な指定子(文字列) |
+============+==========================================================+
|時間 |``h``/``hour``/``hours`` |
+------------+----------------------------------------------------------+
|分 |``m``/``min``/``mins``/``minute``/``minutes`` |
+------------+----------------------------------------------------------+
|秒 |``s``/``sec``/``secs``/``second``/``seconds`` |
+------------+----------------------------------------------------------+
|ミリ秒 |``ms``/``msec``/``msecs``/``millisecond``/``milliseconds``|
+------------+----------------------------------------------------------+
|マイクロ秒 |``us``/``usec``/``usecs``/``microsecond``/``microseconds``|
+------------+----------------------------------------------------------+
例:0.1% のパケットロスを設定 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: console
# tcset eth0 --loss 0.1%
例:上記のすべての設定を一度に行う ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: console
# tcset eth0 --rate 100Kbps --delay 100ms --loss 0.1%
例:トラフィック制御の IP アドレスを指定 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: console
# tcset eth0 --delay 100ms --network 192.168.0.10
例:トラフィック制御の IP ネットワークとポートを指定 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: console
# tcset eth0 --delay 100ms --network 192.168.0.0/24 --port 80
Docker コンテナにトラフィック制御を設定
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Docker ホスト上で --docker オプションを付けて tcconfig を実行します:
.. code-block:: console
# tcset <コンテナ名または ID> --docker ...
--src-container/--dst-container オプションを使用して、送信元/宛先コンテナを指定することもできます。
Docker コンテナ内でトラフィック制御を設定
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
コンテナ内で tc ルールを設定するには、コンテナを --cap-add NET_ADMIN オプション付きで実行する必要があります:
.. code-block:: console
docker run -d --cap-add NET_ADMIN -t <docker イメージ>
tcconfig が組み込まれたコンテナイメージは https://hub.docker.com/r/thombashi/tcconfig/ で入手できます。
tcdel コマンド)tcdel はネットワークインターフェース(デバイス)からトラフィックシェイピングルールを削除するコマンドです。
例:eth0 のトラフィック制御を削除
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-a/--all オプションを使用して、eth0 のすべてのシェイピングルールを削除できます:
.. code-block:: console
# tcdel eth0 --all
tcshow コマンド)tcshow はネットワークインターフェースの現在のトラフィック制御設定を表示するコマンドです。
例 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. 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"
}
}
}
}
より多くの例は以下で入手可能です: https://tcconfig.rtfd.io/en/latest/pages/usage/index.html
tcconfig は PyPI <https://pypi.python.org/pypi>__ から pip <https://pip.pypa.io/en/stable/installing/>__ (Python パッケージマネージャー)コマンドでインストールできます。
.. code:: console
sudo pip install tcconfig
.. code:: console
curl -sSL https://raw.githubusercontent.com/thombashi/tcconfig/master/scripts/installer.sh | sudo bash
Python パッケージの依存関係(自動インストール) <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: 旧スポンサー: Charles Becker (chasbecker) .. |shiguredo| image:: https://avatars.githubusercontent.com/u/2549434?s=48&v=4 :target: https://github.com/shiguredo :alt: 旧スポンサー: 時雨堂 (shiguredo) .. |b4tman| image:: https://avatars.githubusercontent.com/u/3658062?s=48&v=4 :target: https://github.com/b4tman :alt: 一時スポンサー: Dmitry Belyaev (b4tman) .. |Arturi0| image:: https://avatars.githubusercontent.com/u/46711571?s=48&u=57687c0e02d5d6e8eeaf9177f7b7af4c9f275eb5&v=4 :target: https://github.com/Arturi0 :alt: 一時スポンサー: Arturi0 .. |github| image:: https://avatars.githubusercontent.com/u/9919?s=48&v=4 :target: https://github.com/github :alt: 一時スポンサー: GitHub (github)
スポンサーになる <https://github.com/sponsors/thombashi>__