Git Product home page Git Product logo

pynetem's Introduction

pynetem

PyNetem is a tool that allow the user to limit the bandwidth or simulate weak network. It does so by using iproute's tc command, but greatly simplifies its operation. And provide apis if you need in your work.

Installation

pip install pynetem

How to Use It?

In command mode, type pynetem -h, you will see help information, parameters in this tool is same as 'tc/netem'.

If the host cannot download package from PyPI, you can use PyNetem (>=0.1.2) in your PC (no mater Windows or Linux) with the following parameters in addition:

--host          The host IP, which you will send command to
--usrname       The username of host
--password      The password of host

You can also use original command of tc/netem. For more information about tc/netem, you can click here: netem

It is recommended to use web mode, when you have several hosts to control, or you want to build a web page for easier usage.

Run in web mode: pynetem --web, default port is 8899, you can specify by yourself pynetem --web --port=9090

There are 8 APIs:

[GET] /pynetem/help                                     -- Get demo post data and simple description
[GET] /pynetem/listInterfaces                           -- Get interfaces name of host
[GET] /pynetem/getRules?eth=<interface name>            -- Get qdisc rules by interface
[GET/DELETE] /pynetem/clear?eth=<interface name>        -- Clear all rules
[POST] /pynetem/setRules?eth=<interface name>           -- Set tc qdisc rule

[POST] /pynetem/brctl/addbr                             -- Set bridge, the bridge name is pynetem_bridge by defaut
[GET/DELETE] /pynetem/brctl/delbr                       -- Delete pynetem_bridge
[POST] /pynetem/brctl/addif                             -- Add interface(s) to pynetem_bridge

Post Body, if you set parameter None or '', the parameter will be ignored.

Format for the options is the same as tc-netem's and tc-tbf's.

[POST] /pynetem/setRules?eth=<interface name>

{
    "delay": "100ms 10ms 25%",
    "distribution": "normal",
    "reorder": "25% 50%",
    "loss": "0.3% 25%",
    "duplicate": "1%",
    "corrupt": "0.1%",
    # Bitrate control using Netem 
    "netem_rate": "256kbit",
    "netem_limit": 3000,
    # Bitrate control using TBF
    "rate": "256kbit",
    "buffer": 1600,
    "limit": 3000,
    "dst": "10.10.10.0/24"
}

netem_rate and rate are mutually exclusive.

buffer, limit, and dst can only be used if rate is set.


[POST] /pynetem/brctl/addbr

stp is "on" by default.

{
    "interfaces": ["eth0", "eth1"],
    "stp": "on"
}

[POST] /pynetem/brctl/addif

{
    "interfaces": ["eth2"]
}

ATTENTION!

When you press ctrl + c to stop the web server, ALL qdisc rules in all interfaces AND the pynetem_bridge will be cleared automatically.

pynetem's People

Contributors

guotengda1993 avatar loricvdt avatar

Stargazers

EpollRaze avatar  avatar  avatar chingye avatar HatimLiu avatar  avatar  avatar Iván Álvarez avatar Nick avatar  avatar Duplicate4 avatar smith avatar Jialiang Pei avatar

Watchers

James Cloos avatar  avatar

pynetem's Issues

如何模拟波动网络带宽

您好! pynetem很好用,我想请教一下:有无办法动态模拟不同带宽的网络,例如传入一个带宽列表,每隔n秒修改一下。 我尝试用tc/netem等工具,每次更新带宽后网卡似乎重启了,tcp连接严重被影响(断开后重连),请教一下有无热修改方案?

tc-netem rate options

Hi, thanks for this tool.
Wouldn't it be easier if the "rate" option of the API would map to the "rate" parameter of tc-netem?
(setting the "limit" option may also be helpful)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.