Esempio n. 1
0
static struct snobj *handle_get_tc_stats(struct snobj *q)
{
	const char *tc_name;

	struct tc *c;
	
	struct snobj *r;

	tc_name = snobj_str_get(q);
	if (!tc_name)
		return snobj_err(EINVAL, "Argument must be a name in str");

	c = ns_lookup(NS_TYPE_TC, tc_name);
	if (!c)
		return snobj_err(ENOENT, "No TC '%s' found", tc_name);

	r = snobj_map();

	snobj_map_set(r, "timestamp", snobj_double(get_epoch_time()));
	snobj_map_set(r, "count", 
			snobj_uint(c->stats.usage[RESOURCE_CNT]));
	snobj_map_set(r, "cycles", 
			snobj_uint(c->stats.usage[RESOURCE_CYCLE]));
	snobj_map_set(r, "packets", 
			snobj_uint(c->stats.usage[RESOURCE_PACKET]));
	snobj_map_set(r, "bits", 
			snobj_uint(c->stats.usage[RESOURCE_BIT]));

	return r;
}
Esempio n. 2
0
File: snctl.c Progetto: apanda/bess
static struct snobj *handle_get_module_info(struct snobj *arg)
{
	const char *m_name;
	struct module *m;

	struct snobj *r;
	struct snobj *gates;

	m_name = snobj_str_get(arg);

	if (!m_name)
		return snobj_err(EINVAL, "Argument must be a name in str");

	if ((m = find_module(m_name)) == NULL)
		return snobj_err(ENOENT, "No module '%s' found", m_name);

	r = snobj_map();
	gates = snobj_list();

	snobj_map_set(r, "name", snobj_str(m->name));
	snobj_map_set(r, "mclass", snobj_str(m->mclass->name));

	if (m->mclass->get_desc)
		snobj_map_set(r, "desc", m->mclass->get_desc(m));

	if (m->mclass->get_dump)
		snobj_map_set(r, "dump", m->mclass->get_dump(m));

	for (int i = 0; i < m->allocated_gates; i++) {
		if (m->gates[i].m) {
			struct snobj *gate = snobj_map();
			snobj_map_set(gate, "gate", snobj_uint(i));
#if TRACK_GATES
			snobj_map_set(gate, "cnt", 
					snobj_uint(m->gates[i].cnt));
			snobj_map_set(gate, "pkts", 
					snobj_uint(m->gates[i].pkts));
			snobj_map_set(gate, "timestamp", 
					snobj_double(get_epoch_time()));
#endif
			snobj_map_set(gate, "name", snobj_str(m->gates[i].m->name));
			snobj_list_add(gates, gate);
		}
	}

	snobj_map_set(r, "gates", gates);

	return r;
}
Esempio n. 3
0
File: snctl.c Progetto: apanda/bess
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;
}