Giter Site home page Giter Site logo

shapy's Introduction

ShaPy can be used to easily create an emulated network. ShaPy consists from two main parts: ShaPy Framework and ShaPy Emulation. ShaPy Framework allows accessing traffic control capabilities of the Linux kernel using the Netlink interface. ShaPy Emulation builds on the framework and focuses on building emulated network.

Installation

Standard distutils installation is supported. Since ShaPy is also in PyPI you can use:

pip install shapy

or if you prefer development version from the repo:

pip install -e git://github.com/praus/shapy.git#egg=shapy

or download/clone and install the package manually:

python setup.py install

Examples

ShaPy Emulation

The following snippet gives you a virtual network of three IP addresses with exactly the declared speeds and delays.

from shapy.emulation.shaper import Shaper

ps = {("127.0.0.2",) : {'upload': 1024, 'download': 1024, 'delay': 56},
      ("127.0.0.3",) : {'upload': 256, 'download': 512, 'delay': 30},
      ("127.0.0.4",) : {'upload': 256, 'download': 512, 'delay': 30},
}

sh = Shaper()
sh.set_shaping(ps)

ShaPy Framework

The following snippet is an example of ShaPy Framework. It creates a HTB qdisc as a root qdisc on interface lo, creates a HTB class with maximum throughput 500 kbit (units are set in settings, see below) and a filter that will redirect all traffic with source IP 127.0.0.3 to the HTB class to be shaped.

lo = Interface('lo')
h1 = HTBQdisc('1:', default_class='1ff')
h1.add( FlowFilter('src 127.0.0.3', '1:1', prio=2) )
h1.add( HTBClass('1:1', rate=500, ceil=500) )
lo.add( h1 )
lo.set_shaping()

ShaPy Settings

Shapy framework provides a simple facility for managing settings. User creates a regular Python file accessible as a module. In his main program he subsequently registers this module as shown below. The module name is not important but the convention is to call it settings.py. The custom settings file can override or add values specified in the default ShaPy settings module shapy.framework.settings.default.

import shapy
shapy.register_settings('settings')

Settings file for ShaPy Emulation might look like this:

COMMANDS = 'shapy.emulation.commands'
UNITS = 'kbit'

### CWC settings ###

# it's advisable to set MTU of the interfaces to something real, for example 1500
EMU_INTERFACES = (
    'lo',
)

# ports excluded from shaping and delaying (holds for in and out)
# usually used for control ports
EMU_NOSHAPE_PORTS = (8000,)

shapy's People

Contributors

praus avatar

Watchers

James Cloos avatar  avatar

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.