Пример #1
0
/**
 * Evaluate TX/RX bytes of switch ports.
 * @bp:
 * @return:
 * 	< 0:			always turn on LED
 *  >= NR_BLED_INTERVAL_SET:	always turn on LED
 *  otherwise:			blink LED in accordance with bp->intervals[RETURN_VALUE]
 */
unsigned int swports_check_traffic(struct bled_priv *bp)
{
	int p, c;
	unsigned int b = 0, m;
	unsigned long d, diff, rx_bytes, tx_bytes;
	struct swport_bled_ifstat *ifs;
	struct swport_bled_priv *sp = bp->check_priv;

	m = sp->port_mask;
	for (p = 0, c = 0, diff = 0, ifs = &sp->portstat[0]; m > 0; ++p, ++ifs, m >>= 1) {
		if (!(m & 1))
			continue;

		get_port_stats(p, &rx_bytes, &tx_bytes);
		if (unlikely(!ifs->last_rx_bytes && !ifs->last_tx_bytes)) {
			ifs->last_rx_bytes = rx_bytes;
			ifs->last_tx_bytes = tx_bytes;
			continue;
		}

		d = bdiff(ifs->last_rx_bytes, rx_bytes) + bdiff(ifs->last_tx_bytes, tx_bytes);
		diff += d;
		if (unlikely(bp->flags & BLED_FLAGS_DBG_CHECK_FUNC)) {
			prn_bl_v("GPIO#%d: port %2d, d %10lu (RX %10lu,%10lu / TX %10lu,%10lu)\n",
				bp->gpio_nr, p, d, ifs->last_rx_bytes, rx_bytes,
				ifs->last_tx_bytes, tx_bytes);
		}

		ifs->last_rx_bytes = rx_bytes;
		ifs->last_tx_bytes = tx_bytes;
		c++;
	}

	if (likely(diff >= bp->threshold))
		b = 1;
	if (unlikely(!c))
		bp->next_check_interval = BLED_WAIT_IF_INTERVAL;

	return b;
}
Пример #2
0
/**
 * Reset statistics information.
 * @bp:
 * @return:
 */
int swports_reset_check_traffic(struct bled_priv *bp)
{
	int p;
	unsigned int m;
	unsigned long rx_bytes, tx_bytes;
	struct swport_bled_ifstat *ifs;
	struct swport_bled_priv *sp = bp->check_priv;

	m = sp->port_mask;
	for (p = 0, ifs = &sp->portstat[0]; m > 0; ++p, ++ifs, m >>= 1) {
		ifs->last_rx_bytes = 0;
		ifs->last_tx_bytes = 0;
		if (!(m & 1))
			continue;

		get_port_stats(p, &rx_bytes, &tx_bytes);
		ifs->last_rx_bytes = rx_bytes;
		ifs->last_tx_bytes = tx_bytes;
	}

	return 0;
}
Пример #3
0
static struct snobj *handle_get_port_stats(struct snobj *arg)
{
	const char *port_name;

	struct port *port;

	port_stats_t stats;

	struct snobj *r;
	struct snobj *inc;
	struct snobj *out;

	port_name = snobj_str_get(arg);
	if (!port_name)
		return snobj_err(EINVAL, "Argument must be a name in str");
	
	port = find_port(port_name);
	if (!port)
		return snobj_err(ENOENT, "No port `%s' found", port_name);

	get_port_stats(port, &stats);

	inc = snobj_map();
	snobj_map_set(inc, "packets", snobj_uint(stats[PACKET_DIR_INC].packets));
	snobj_map_set(inc, "dropped", snobj_uint(stats[PACKET_DIR_INC].dropped));
	snobj_map_set(inc, "bytes",   snobj_uint(stats[PACKET_DIR_INC].bytes));

	out = snobj_map();
	snobj_map_set(out, "packets", snobj_uint(stats[PACKET_DIR_OUT].packets));
	snobj_map_set(out, "dropped", snobj_uint(stats[PACKET_DIR_OUT].dropped));
	snobj_map_set(out, "bytes",   snobj_uint(stats[PACKET_DIR_OUT].bytes));

	r = snobj_map();
	snobj_map_set(r, "inc", inc);
	snobj_map_set(r, "out", out);
	snobj_map_set(r, "timestamp", snobj_double(get_epoch_time()));

	return r;
}