コード例 #1
0
ファイル: test_delay.py プロジェクト: redNixon/shapy
import unittest
import SocketServer, socket
from tests.utils import ping
from tests.mixins import ShaperMixin
import time

from shapy import register_settings

register_settings('tests.emulation.settings')


class TestCWCDelay(unittest.TestCase, ShaperMixin):
    def setUp(self):
        self.server_addr = ('127.0.0.2', 55000)  # 5 ms delay
        self.client_addr = ('127.0.0.3', 55001)  # 30 ms delay
        ShaperMixin.setUp(self)

    def test_delay(self):
        c = self.client_addr[0]
        s = self.server_addr[0]
        ping(c, s, 1)  # ARP
        est_delay = self.estimate_delay(c, s)

        self.assertAlmostEqual(ping(c, s), est_delay * 2, delta=1)
        self.assertAlmostEqual(ping(s, c), est_delay * 2, delta=1)
        self.assertAlmostEqual(ping(c, "127.0.0.1"), 60, delta=0.5)
        self.assertAlmostEqual(ping("127.0.0.1", c), 60, delta=0.5)
        self.assertAlmostEqual(ping(s, "127.0.0.1"), 10, delta=1)
        self.assertAlmostEqual(ping("127.0.0.1", s), 10, delta=1)

    def tearDown(self):
コード例 #2
0
ファイル: test_settings.py プロジェクト: redNixon/shapy
 def test_settings_override(self):
     shapy.register_settings('test_settings')
     from shapy import settings
     self.assertEqual(settings.UNITS, 'override')
     self.assertEqual(getattr(settings, 'NEW_OPTION', None), 'new')
コード例 #3
0
ファイル: teardown.py プロジェクト: jirwin/shapy
def scan_interfaces():
    """Parses a list of all interfaces reported by `ip link`"""
    import subprocess
    import re
    ifcs = []
    out = subprocess.check_output(["ip", "link"]).split('\n')
    for line in out:
        m = re.match("^[0-9]+:[ ]([a-z0-9]+):", line)
        if m:
            ifcs.append(m.group(1))
    return ifcs


from shapy import register_settings
register_settings('settings')
from shapy.emulation.shaper import Shaper

from shapy import settings
settings.EMU_INTERFACES = scan_interfaces()

notice = """\
This will clear entire Traffic Control configuration and unload IFB module.
Please note reported errors usually do not mean anything bad, just that there
was nothing to tear down on that particular interface."""

if __name__ == '__main__':
    print "Tearing down all interfaces: %s" % ', '.join(settings.EMU_INTERFACES)
    print notice
    print "-"*80
    sh = Shaper()
コード例 #4
0
#!/usr/bin/env python

import logging
logging.basicConfig(level=logging.INFO,
                    datefmt='%H:%M:%S',
                    format='%(asctime)s %(name)s %(levelname)s: %(message)s')

from shapy import register_settings
register_settings('settings')
from shapy.emulation.shaper import Shaper

if __name__ == '__main__':
    ps = {
        ("127.0.0.2", ): {
            'upload': 1024,
            'download': 1024,
            'delay': 5,
            'jitter': 5
        },
        ("127.0.0.3", ): {
            'upload': 256,
            'download': 512,
            'delay': 20
        },
        ("127.0.0.4", ): {
            'upload': 256,
            'download': 512,
            'delay': 20
        },
    }
コード例 #5
0
ファイル: test_delay.py プロジェクト: boonchu/shapy
import unittest
import SocketServer, socket
from tests.utils import ping
from tests.mixins import ShaperMixin
import time

from shapy import register_settings
register_settings('tests.emulation.settings')

class TestCWCDelay(unittest.TestCase, ShaperMixin):
    def setUp(self):
        self.server_addr = ('127.0.0.2', 55000) # 5 ms delay
        self.client_addr = ('127.0.0.3', 55001) # 30 ms delay
        ShaperMixin.setUp(self)
    
    def test_delay(self):
        c = self.client_addr[0]
        s = self.server_addr[0]
        ping(c, s, 1) # ARP
        est_delay = self.estimate_delay(c, s)
        
        self.assertAlmostEqual(ping(c, s), est_delay*2, delta=1)
        self.assertAlmostEqual(ping(s, c), est_delay*2, delta=1)
        self.assertAlmostEqual(ping(c, "127.0.0.1"), 60, delta=0.5)
        self.assertAlmostEqual(ping("127.0.0.1", c), 60, delta=0.5)
        self.assertAlmostEqual(ping(s, "127.0.0.1"), 10, delta=1)
        self.assertAlmostEqual(ping("127.0.0.1", s), 10, delta=1)
    
    def tearDown(self):
        ShaperMixin.tearDown(self)