Ejemplo n.º 1
0
    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)
Ejemplo n.º 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
Ejemplo n.º 3
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
Ejemplo n.º 4
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)
Ejemplo n.º 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)
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
Archivo: utils.py Proyecto: 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
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
 def modprobe():
     if not IFB.module_loaded:
         executor.run('modprobe ifb')
         IFB.module_loaded = True
Ejemplo n.º 10
0
 def test_pfifo(self):
     out = run('tc qdisc show dev lo')
Ejemplo n.º 11
0
 def modprobe():
     if not IFB.module_loaded:
         executor.run('modprobe ifb')
         IFB.module_loaded = True
Ejemplo n.º 12
0
 def test_pfifo(self):
     out = run('tc qdisc show dev lo')