コード例 #1
0
    def handle_rc_response(self, response, *_):
        """Handle WIFI_RC_STATS_RESPONSE message."""

        # get lvap mac address
        sta = EtherAddress(response.sta)
        sta = sta.to_str()

        lvap = self.context.lvaps[sta]

        # update this object
        self.lvap_rates[sta] = {}
        self.lvap_best_prob[sta] = None
        self.lvap_best_tp[sta] = None

        # generate data points
        points = []
        timestamp = datetime.utcnow()

        for entry in response.stats:

            rate = entry.rate if lvap.ht_caps else entry.rate / 2.0

            fields = {
                'prob': entry.prob / 180.0,
                'cur_prob': entry.cur_prob / 180.0,
                'cur_tp': entry.cur_tp / ((18000 << 10) / 96) / 10,
                'last_attempts': entry.last_attempts,
                'last_successes': entry.last_successes,
                'hist_attempts': entry.hist_attempts,
                'hist_successes': entry.hist_successes,
            }

            tags = dict(self.params)
            tags["rate"] = rate

            self.lvap_rates[sta][rate] = fields

            sample = {
                "measurement": self.name,
                "tags": tags,
                "time": timestamp,
                "fields": fields
            }

            points.append(sample)

            # compute statistics
            self.lvap_best_prob[sta] = \
                max(self.rates.keys(), key=(lambda key: self.rates[key]['prob']))

            self.lvap_best_tp[sta] = \
                max(self.lvap_rates[sta].keys(), key=(lambda key: self.lvap_rates[sta][key]['cur_tp']))

            # save to db
            # self.write_points(points)

            # handle callbacks
            self.handle_callbacks()
コード例 #2
0
    def handle_lvap_response(self, response, *_):
        """Handle BIN_COUNTERS_RESPONSE message."""

        # get lvap mac address
        sta = EtherAddress(response.sta)
        sta = sta.to_str()

        # update this object

        tx_samples = response.stats[0:response.nb_tx]
        rx_samples = response.stats[response.nb_tx:-1]

        old_tx_bytes = self.lvap_counters[sta][
            "tx_bytes"] if sta in self.lvap_counters else 0.0
        old_rx_bytes = self.lvap_counters[sta][
            "rx_bytes"] if sta in self.lvap_counters else 0.0

        old_tx_packets = self.lvap_counters[sta][
            "tx_packets"] if sta in self.lvap_counters else 0.0
        old_rx_packets = self.lvap_counters[sta][
            "rx_packets"] if sta in self.lvap_counters else 0.0

        if not (sta in self.lvap_counters):
            self.lvap_counters[sta] = {}

        self.lvap_counters[sta]["tx_bytes"] = self.fill_bytes_samples(
            tx_samples)
        self.lvap_counters[sta]["rx_bytes"] = self.fill_bytes_samples(
            rx_samples)

        self.lvap_counters[sta]["tx_packets"] = self.fill_packets_samples(
            tx_samples)
        self.lvap_counters[sta]["rx_packets"] = self.fill_packets_samples(
            rx_samples)

        self.lvap_counters[sta]["tx_bps"] = 0
        self.lvap_counters[sta]["rx_bps"] = 0
        self.lvap_counters[sta]["tx_pps"] = 0
        self.lvap_counters[sta]["rx_pps"] = 0

        if sta in self.lvap_last and self.lvap_last[sta] != None:

            delta = time.time() - self.lvap_last[sta]

            self.lvap_counters[sta]["tx_bps"] = \
                self.update_stats(delta, old_tx_bytes, self.lvap_counters[sta]["tx_bytes"])

            self.lvap_counters[sta]["rx_bps"] = \
                self.update_stats(delta, old_rx_bytes, self.lvap_counters[sta]["rx_bytes"])

            self.lvap_counters[sta]["tx_pps"] = \
                self.update_stats(delta, old_tx_packets, self.lvap_counters[sta]["tx_packets"])

            self.lvap_counters[sta]["rx_pps"] = \
                self.update_stats(delta, old_rx_packets, self.lvap_counters[sta]["rx_packets"])

        # generate data points
        points = []
        timestamp = datetime.utcnow()

        fields = {
            "tx_bytes": float(self.lvap_counters[sta]["tx_bytes"]),
            "rx_bytes": float(self.lvap_counters[sta]["rx_bytes"]),
            "tx_packets": float(self.lvap_counters[sta]["tx_packets"]),
            "rx_packets": float(self.lvap_counters[sta]["rx_packets"]),
            "tx_bps": float(self.lvap_counters[sta]["tx_bps"]),
            "rx_bps": float(self.lvap_counters[sta]["rx_bps"]),
            "tx_pps": float(self.lvap_counters[sta]["tx_pps"]),
            "rx_pps": float(self.lvap_counters[sta]["rx_pps"])
        }

        tags = dict(self.params)
        tags["sta"] = sta

        sample = {
            "measurement": 'lvap_counters_stats',
            "tags": tags,
            "time": timestamp,
            "fields": fields
        }

        points.append(sample)

        # save to db
        self.write_points(points)

        # handle callbacks
        self.handle_callbacks()

        # set last iteration time
        self.lvap_last[sta] = time.time()

        # handle rc stats response
        self.handle_class_rc_response(sta)