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)
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
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)
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
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
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)
def modprobe(): if not IFB.module_loaded: executor.run('modprobe ifb') IFB.module_loaded = True
def test_pfifo(self): out = run('tc qdisc show dev lo')