예제 #1
0
파일: shaper.py 프로젝트: redNixon/shapy
    def get_traffic(self, ip):
        """
        Returns sent/received data for the given IP. This is based on
        tc statistics (tc -s) of HTB classes on the respective IFB devices.
        """
        if not hasattr(self, 'ip_handles'):
            return None, None

        def get_htb_class_send(stats):
            try:
                return int(re.search(r"Sent ([0-9]+) ", stats).group(1))
            except:
                return None, None

        handle = self.ip_handles[ip]
        up = executor.get_command('TCStats',
                                  interface=self.ifb_up,
                                  handle=handle)
        down = executor.get_command('TCStats',
                                    interface=self.ifb_down,
                                    handle=handle)
        up_stats = executor.run(up, sudo=False)
        down_stats = executor.run(down, sudo=False)

        return get_htb_class_send(up_stats), get_htb_class_send(down_stats)
예제 #2
0
 def teardown():
     """
     A custom teardown, all we need to do is unload the module
     """
     #Interface.teardown(self)
     if IFB.module_loaded:
         executor.run('rmmod ifb')
         IFB.module_loaded = False
예제 #3
0
파일: interface.py 프로젝트: boonchu/shapy
 def teardown():
     """
     A custom teardown, all we need to do is unload the module
     """
     #Interface.teardown(self)
     if IFB.module_loaded:
         executor.run('rmmod ifb')
         IFB.module_loaded = False
예제 #4
0
파일: interface.py 프로젝트: boonchu/shapy
 def teardown(self):
     """
     Tears down all custom qdiscs, classes and filters on this interface.
     """
     cmd_e = executor.get_command('TCInterfaceTeardown', interface=self.name,
                                handle='root')
     cmd_i = executor.get_command('TCInterfaceTeardown', interface=self.name,
                                handle='ingress')
     executor.run(cmd_e)
     executor.run(cmd_i)
예제 #5
0
 def teardown(self):
     """
     Tears down all custom qdiscs, classes and filters on this interface.
     """
     cmd_e = executor.get_command('TCInterfaceTeardown',
                                  interface=self.name,
                                  handle='root')
     cmd_i = executor.get_command('TCInterfaceTeardown',
                                  interface=self.name,
                                  handle='ingress')
     executor.run(cmd_e)
     executor.run(cmd_i)
예제 #6
0
파일: utils.py 프로젝트: redNixon/shapy
def get_if_index(if_name):
    """
    Retrieves interface index based on interface name.
    Ugly implementation of if_nametoindex() from net/if.h
    """
    out = run("ip link show dev {interface}".format(interface=if_name))
    try:
        return int(re.match('^([0-9]+)', out).group(0), 10)
    except:
        return 0
예제 #7
0
파일: utils.py 프로젝트: praus/shapy
def get_if_index(if_name):
    """
    Retrieves interface index based on interface name.
    Ugly implementation of if_nametoindex() from net/if.h
    """
    out = run("ip link show dev {interface}".format(interface=if_name))
    try:
        return int(re.match("^([0-9]+)", out).group(0), 10)
    except:
        return 0
예제 #8
0
파일: shaper.py 프로젝트: praus/shapy
    def get_traffic(self, ip):
        """
        Returns sent/received data for the given IP. This is based on
        tc statistics (tc -s) of HTB classes on the respective IFB devices.
        """
        if not hasattr(self, "ip_handles"):
            return None, None

        def get_htb_class_send(stats):
            try:
                return int(re.search(r"Sent ([0-9]+) ", stats).group(1))
            except:
                return None, None

        handle = self.ip_handles[ip]
        up = executor.get_command("TCStats", interface=self.ifb_up, handle=handle)
        down = executor.get_command("TCStats", interface=self.ifb_down, handle=handle)
        up_stats = executor.run(up, sudo=False)
        down_stats = executor.run(down, sudo=False)

        return get_htb_class_send(up_stats), get_htb_class_send(down_stats)
예제 #9
0
 def modprobe():
     if not IFB.module_loaded:
         executor.run('modprobe ifb')
         IFB.module_loaded = True
예제 #10
0
 def test_pfifo(self):
     out = run('tc qdisc show dev lo')
예제 #11
0
파일: interface.py 프로젝트: boonchu/shapy
 def modprobe():
     if not IFB.module_loaded:
         executor.run('modprobe ifb')
         IFB.module_loaded = True
예제 #12
0
파일: test_pfifo.py 프로젝트: boonchu/shapy
 def test_pfifo(self):
     out = run('tc qdisc show dev lo')