コード例 #1
0
ファイル: snctl.c プロジェクト: Grace-Liu/bess
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;
}
コード例 #2
0
ファイル: snctl.c プロジェクト: Grace-Liu/bess
static struct snobj *handle_attach_task(struct snobj *q)
{
	const char *m_name;
	const char *tc_name;

	task_id_t tid;

	struct module *m;
	struct task *t;

	m_name = snobj_eval_str(q, "name");

	if (!m_name)
		return snobj_err(EINVAL, "Missing 'name' field");

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

	tid = snobj_eval_uint(q, "taskid");
	if (tid >= MAX_TASKS_PER_MODULE)
		return snobj_err(EINVAL, "'taskid' must be between 0 and %d",
				MAX_TASKS_PER_MODULE - 1);

	if ((t = m->tasks[tid]) == NULL)
		return snobj_err(ENOENT, "Task %s:%hu does not exist", 
				m_name, tid);

	tc_name = snobj_eval_str(q, "tc");

	if (tc_name) {
		struct tc *c;

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

		task_attach(t, c);
	} else {
		int wid;		/* TODO: worker_id_t */

		if (task_is_attached(t))
			return snobj_err(EBUSY, "Task %s:%hu is already "
					"attached to a TC", m_name, tid);

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

		if (!is_worker_active(wid))
			return snobj_err(EINVAL, "Worker %d does not exist", wid);

		assign_default_tc(wid, t);
	}

	return NULL;
}
コード例 #3
0
ファイル: mclass.c プロジェクト: Grace-Liu/bess
const struct mclass *find_mclass(const char *name)
{
	return (struct mclass *) ns_lookup(NS_TYPE_MCLASS, name);
}
コード例 #4
0
ファイル: driver.c プロジェクト: apanda/bess
const struct driver *find_driver(const char *name)
{
	return (struct driver *) ns_lookup(NS_TYPE_DRIVER, name);
}