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(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_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)