Example #1
0
static struct snobj *handle_list_ports(struct snobj *q)
{
	struct snobj *r;

	int cnt = 1;
	int offset;

	r = snobj_list();

	for (offset = 0; cnt != 0; offset += cnt) {
		const int arr_size = 16;
		const struct port *ports[arr_size];

		int i;

		cnt = list_ports(ports, arr_size, offset);

		for (i = 0; i < cnt; i++) {
			struct snobj *port = snobj_map();

			snobj_map_set(port, "name",
					snobj_str(ports[i]->name));
			snobj_map_set(port, "driver",
					snobj_str(ports[i]->driver->name));

			snobj_list_add(r, port);
		}
	};

	return r;
}
Example #2
0
File: snctl.c Project: 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;
}
Example #3
0
File: snctl.c Project: apanda/bess
static struct snobj *handle_list_modules(struct snobj *q)
{
	struct snobj *r;

	int cnt = 1;
	int offset;

	r = snobj_list();

	for (offset = 0; cnt != 0; offset += cnt) {
		const int arr_size = 16;
		const struct module *modules[arr_size];

		int i;
		
		cnt = list_modules(modules, arr_size, offset);

		for (i = 0; i < cnt; i++) {
			const struct module *m = modules[i];
			const struct mclass *mclass = m->mclass;

			struct snobj *module = snobj_map();

			snobj_map_set(module, "name", 
					snobj_str(m->name));
			snobj_map_set(module, "mclass", 
					snobj_str(mclass->name));
			if (mclass->get_desc) {
				snobj_map_set(module, "desc", 
						mclass->get_desc(m));
			}

			snobj_list_add(r, module);
		}
	};

	return r;
}
Example #4
0
File: snctl.c Project: apanda/bess
static struct snobj *handle_list_drivers(struct snobj *q)
{
	struct snobj *r;

	int cnt = 1;
	int offset;

	r = snobj_list();

	for (offset = 0; cnt != 0; offset += cnt) {
		const int arr_size = 16;
		const struct driver *drivers[arr_size];

		int i;

		cnt = list_drivers(drivers, arr_size, offset);

		for (i = 0; i < cnt; i++)
			snobj_list_add(r, snobj_str(drivers[i]->name));
	};

	return r;
}
Example #5
0
static struct snobj *handle_list_tcs(struct snobj *q)
{
	struct snobj *r;
	struct snobj *t;

	unsigned int wid_filter = MAX_WORKERS;

	struct ns_iter iter;

	struct tc *c;

	t = snobj_eval(q, "wid");
	if (t) {
		wid_filter = snobj_uint_get(t);

		if (wid_filter >= MAX_WORKERS)
			return snobj_err(EINVAL, 
					"'wid' must be between 0 and %d",
					MAX_WORKERS - 1);

		if (!is_worker_active(wid_filter))
			return snobj_err(EINVAL, "worker:%d does not exist", 
					wid_filter);
	}

	r = snobj_list();

	ns_init_iterator(&iter, NS_TYPE_TC);

	while ((c = (struct tc *)ns_next(&iter)) != NULL) {
		int wid;

		if (wid_filter < MAX_WORKERS) {
			if (workers[wid_filter]->s != c->s)
				continue;
			wid = wid_filter;
		} else {
			for (wid = 0; wid < MAX_WORKERS; wid++)
				if (is_worker_active(wid) && 
						workers[wid]->s == c->s)
					break;
		}

		struct snobj *elem = snobj_map();

		snobj_map_set(elem, "name", snobj_str(c->name));
		snobj_map_set(elem, "tasks", snobj_int(c->num_tasks));
		snobj_map_set(elem, "parent", snobj_str(c->parent->name));
		snobj_map_set(elem, "priority", snobj_int(c->priority));

		if (wid < MAX_WORKERS)
			snobj_map_set(elem, "wid", snobj_uint(wid));
		else
			snobj_map_set(elem, "wid", snobj_int(-1));


		snobj_list_add(r, elem);
	}

	ns_release_iterator(&iter);

	return r;
}