Пример #1
0
    def setup_iface(self, run_info):
        if run_info['profile'] not in ('udp_rates', 'udp_ratios', 'tcp_algos', 'tcp_windows', 'hold_times', 'power_meas'):
            return True
        iface = self.args.wifi_iface
        state = "on" if run_info['promisc'] else "off"
        cmd = ['ip', 'link', 'set', 'dev', iface, 'promisc', state]
        r = subprocess.call(cmd)
        if r:
            return False

        cmd = ['iw', 'phy0', 'set', 'rts', str(run_info['rts'])]
        r = subprocess.call(cmd)
        if r:
            return False

        if state == "on" and os.path.exists("/sys/class/net/mesh0"):
            if not os.path.exists("/sys/class/net/mon0"):
                cmd = ["iw", "phy0", "interface", "add", "mon0", "type", "monitor", "flags", "none"]
                if interface.exec_cmd(cmd) == False:
                    self.error = "Failed to create mon0: {}".format(cmd)
                    return False

            cmd = ["ip", "link", "set", "dev", "mon0", "up"]
            if interface.exec_cmd(cmd) == False:
                self.error = "Failed to up mon0: {}".format(cmd)
                return False

            cmd = ["iw", "mon0", "del"]
            if interface.exec_cmd(cmd) == False:
                self.error = "Failed to del mon0: {}".format(cmd)
                return False

        return True
Пример #2
0
    def sample_cpu(self):
        # Run the command
        cmd = ["cat", "/proc/stat"]
        cpu = interface.exec_cmd(cmd)
        if not cpu:
            return

        # Save temporary values for later calculations
        last_cpu = self.total_cpu
        last_idle = self.total_idle

        # Parse the output
        line = cpu.split("\n")[0]
        self.total_cpu = sum(map(lambda x: float(x), line.split()[1:]))
        self.total_idle = float(line.split()[4])
        if not last_cpu:
            return

        # Calculate the utilization since last sample
        total = self.total_cpu - last_cpu
        idle = self.total_idle - last_idle
        sample = {'cpu': int(100*(total - idle)/total)}

        # Add the sample to the set
        self.append_sample(sample)
Пример #3
0
    def sample_iw(self):
        sample = {}

        # Run the command
        cmd = ["iw", "dev", self.args.wifi_iface, "station", "dump"]
        output = interface.exec_cmd(cmd)
        if not output:
            return

        # Parse the output
        for line in output.split('\n'):
            # Find the mac address for the next set of counters
            match = re.findall("((?:[0-9a-f]{2}:){5}[0-9a-f]{2})", line)
            if match:
                mac = "iw " + match[0]
                continue

            # Read out the counter for this line (for this mac)
            match = re.findall("\s+(.+):\s+(.+)", line)
            if not match:
                continue

            # Generate a key specific to this mac and counter
            mac_key = mac + " " + match[0][0]

            # We want integers to be integers
            try:
                # Try to convert
                val = int(match[0][1])

                # Okay, the convert did not fail, so compose the key
                key = "iw " + match[0][0]

                # Update or set the value for this counter
                if key in sample:
                    sample[key] += val
                else:
                    sample[key] = val
            except ValueError:
                # The convert failed, so just use the string version
                val = match[0][1]
            finally:
                # Set the value for this mac
                sample[mac_key] = val

        # Add the sample to the set
        self.append_sample(sample)
Пример #4
0
    def sample_originators(self):
        sample = {'nexthops': {}}
        if not os.path.exists(orig_path):
            return

        # Read the file (why don't we just open() the file?)
        cmd = ["cat", orig_path]
        output = interface.exec_cmd(cmd)
        if not output:
            return

        sample['mac'] = re.findall("/([0-9a-f:]{17})", output)[0]
        nexthops = re.findall("(?P<orig>[0-9a-f:]{17}) +\d.\d{3}s +\((?P<tq>\d+)\) (?P=orig)", output)
        for nexthop in nexthops:
            sample['nexthops'][nexthop[0]] = nexthop[1]

        self.append_sample(sample)
Пример #5
0
    def sample_nc(self):
        sample = {}

        # Read the file (why don't we just open() the file?)
        cmd = ["ethtool", "-S", "bat0"]
        output = interface.exec_cmd(cmd)
        if not output:
            return

        # Parse the contents of the file
        for line in output.split("\n"):
            match = re.findall("\s+([a-z_]+):\s+(\d+)", line)
            if match:
                key = "bat_" + match[0][0]
                sample[key] = int(match[0][1])

        # Add some extra numbers
        sample['bat_nc_fwd_coded'] = sample['bat_nc_code'] + sample['bat_forward']

        # Add the sample to the set
        self.append_sample(sample)
Пример #6
0
    def sample_ip(self):
        # Run the command
        cmd = ["ip", "-s", "-s", "link", "show", self.args.wifi_iface]
        output = interface.exec_cmd(cmd)
        if not output:
            return

        # Remove first to lines
        for line in output.split("\n", 2):
            o = line

        # Parse the output
        n = re.findall("\s+(\d+)", o)
        sample = {
                'ip_rx_bytes':          int(n[0]),
                'ip_rx_packets':        int(n[1]),
                'ip_rx_errors':         int(n[2]),
                'ip_rx_dropped':        int(n[3]),
                'ip_rx_overrun':        int(n[4]),
                'ip_rx_errors_length':  int(n[6]),
                'ip_rx_errors_crc':     int(n[7]),
                'ip_rx_errors_frame':   int(n[8]),
                'ip_rx_errors_fifo':    int(n[9]),
                'ip_rx_errors_missed':  int(n[10]),
                'ip_tx_bytes':          int(n[11]),
                'ip_tx_packets':        int(n[12]),
                'ip_tx_errors':         int(n[13]),
                'ip_tx_dropped':        int(n[14]),
                'ip_tx_carrier':        int(n[15]),
                'ip_tx_collsns':        int(n[16]),
                'ip_tx_errors_aborted': int(n[17]),
                'ip_tx_errors_fifo':    int(n[18]),
                'ip_tx_errors_window':  int(n[19]),
                'ip_tx_errors_heartbeat': int(n[20]),
                }

        # Add the sample to the set
        self.append_sample(sample)
Пример #7
0
 def send_node_info(self):
     args = self.server.args
     output = interface.exec_cmd(["batctl", "o"])
     mac = re.findall("((?:[0-9a-f]{2}:){5}[0-9a-f]{2})", output)[0]
     obj = interface.node(interface.NODE_INFO, mesh_host=args.mesh_host, mesh_port=args.mesh_port, mesh_mac=mac)
     self.report(obj)