Ejemplo n.º 1
0
/*
 * Delete single flow or all flows.
 *
 * When request->key is empty delete all flows
 */
static void
flow_cmd_del(struct dpdk_flow_message *request)
{
	struct dpdk_message reply = {0};
	struct flow_key empty = {0};
	int pos = 0;

	if (!memcmp(&request->key, &empty, sizeof(request->key))) {
		flow_table_del_all();
		reply.type = 0;
	} else {
		pos = flow_table_lookup(&request->key);
		if (pos < 0) {
			reply.type = ENOENT;
		} else {
			/* Retrieve flow stats*/
			flow_table_get_flow(&request->key,
			               NULL, &request->stats);
			flow_table_del_flow(&request->key);
			reply.type = 0;
		}
	}

	reply.flow_msg = *request;
	send_reply_to_vswitchd(&reply);
}
Ejemplo n.º 2
0
/* Try to delete all flows, which should succeed */
static void
test_flow_table_del_all(int argc, char *argv[])
{
	struct flow_key key1 = {1};
	struct flow_key key2 = {2};
	struct flow_key key_check = {0};
	struct action action_multiple[MAX_ACTIONS] = {0};
	struct action action_check[MAX_ACTIONS] = {0};
	struct flow_stats stats_check = {0};
	int ret = 0;

	flow_table_init();

	action_output_build(&action_multiple[0], 1);
	action_output_build(&action_multiple[1], 2);
	action_null_build(&action_multiple[2]);
	/* Add two flowss to be deleted */
	flow_table_add_flow(&key1, action_multiple);
	ret = flow_table_get_flow(&key1, NULL, NULL);
	assert(ret >= 0);
	flow_table_add_flow(&key2, action_multiple);
	ret = flow_table_get_flow(&key2,  NULL, NULL);
	assert(ret >= 0);
	/* delete all flows and ensure flows are deleted */
	flow_table_del_all();
	ret = flow_table_get_first_flow(&key_check, action_check, &stats_check);
	assert(ret < 0);
}
Ejemplo n.º 3
0
/* Try to get next flow, which should succeed */
static void
test_flow_table_get_next_flow(int argc, char *argv[])
{
	struct flow_key key1 = {1};
	struct flow_key key2 = {2};
	struct flow_key key_check = {0};
	struct action action_multiple[MAX_ACTIONS] = {0};
	struct action action_check[MAX_ACTIONS] = {0};
	struct flow_stats stats_zero = {0};
	struct flow_stats stats_check = {0};
	int ret = 0;

	flow_table_init();

	flow_table_del_all();
	action_output_build(&action_multiple[0], 1);
	action_null_build(&action_multiple[1]);
	ret = flow_table_add_flow(&key1, action_multiple);
	assert(ret >= 0);
	ret = flow_table_add_flow(&key2, action_multiple);
	assert(ret >= 0);

	ret = flow_table_get_first_flow(&key_check, action_check, &stats_check);
	assert(ret >= 0);
	if (memcmp(&key1, &key_check, sizeof(struct flow_key)) == 0 ) {
		ret = flow_table_get_next_flow(&key_check, &key_check, action_check, &stats_check);
		assert(ret >= 0);
		assert(memcmp(action_multiple, action_check, sizeof(struct action)) == 0);
		assert(memcmp(&stats_zero, &stats_check, sizeof(struct flow_stats)) == 0 );
		assert(memcmp(&key2, &key_check, sizeof(struct flow_key)) == 0 );
	} else if (memcmp(&key2, &key_check, sizeof(struct flow_key) == 0)) {
		ret = flow_table_get_next_flow(&key_check, &key_check, action_check, &stats_check);
		assert(ret >= 0);
		assert(memcmp(action_multiple, action_check, sizeof(struct action)) == 0);
		assert(memcmp(&stats_zero, &stats_check, sizeof(struct flow_stats)) == 0 );
		assert(memcmp(&key1, &key_check, sizeof(struct flow_key)) == 0 );
	} else {
		assert(1==0);
	}

}