summaryrefslogtreecommitdiffstats
path: root/src/vnet/vxlan
diff options
context:
space:
mode:
authorZhiyong Yang <zhiyong.yang@intel.com>2020-03-27 13:04:38 +0000
committerDamjan Marion <dmarion@me.com>2020-03-30 12:59:09 +0000
commit102dd1cfa792f3e70679463df141fe21fc67a8ea (patch)
treed67f4d43a9e44a33fbe5ff3d045e31e2f840b33c /src/vnet/vxlan
parent0c7aa7ab54dd6c9074079d589d0c32873a1085bb (diff)
vxlan: leverage vlib_get_buffers in vxlan_encap_inline
vlib_get_buffers can save about 1.2 clocks per packet for vxlan encap graph node on Skylake. Type: improvement Signed-off-by: Zhiyong Yang <zhiyong.yang@intel.com> Change-Id: I9cad3211883de117c1b84324e8dfad38879de2d2
Diffstat (limited to 'src/vnet/vxlan')
-rw-r--r--src/vnet/vxlan/encap.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/vnet/vxlan/encap.c b/src/vnet/vxlan/encap.c
index da890b2d5fb..2426a8ccaf0 100644
--- a/src/vnet/vxlan/encap.c
+++ b/src/vnet/vxlan/encap.c
@@ -81,6 +81,8 @@ vxlan_encap_inline (vlib_main_t * vm,
u32 next0 = 0, next1 = 0;
vxlan_tunnel_t * t0 = NULL, * t1 = NULL;
index_t dpoi_idx0 = INDEX_INVALID, dpoi_idx1 = INDEX_INVALID;
+ vlib_buffer_t *bufs[VLIB_FRAME_SIZE];
+ vlib_buffer_t **b = bufs;
from = vlib_frame_vector_args (from_frame);
n_left_from = from_frame->n_vectors;
@@ -96,6 +98,7 @@ vxlan_encap_inline (vlib_main_t * vm,
u32 const csum_flags = is_ip4 ? VNET_BUFFER_F_OFFLOAD_IP_CKSUM |
VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_OFFLOAD_UDP_CKSUM :
VNET_BUFFER_F_IS_IP6 | VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
+ vlib_get_buffers (vm, from, bufs, n_left_from);
while (n_left_from > 0)
{
@@ -108,16 +111,11 @@ vxlan_encap_inline (vlib_main_t * vm,
{
/* Prefetch next iteration. */
{
- vlib_buffer_t * p2, * p3;
+ vlib_prefetch_buffer_header (b[2], LOAD);
+ vlib_prefetch_buffer_header (b[3], LOAD);
- p2 = vlib_get_buffer (vm, from[2]);
- p3 = vlib_get_buffer (vm, from[3]);
-
- vlib_prefetch_buffer_header (p2, LOAD);
- vlib_prefetch_buffer_header (p3, LOAD);
-
- CLIB_PREFETCH (p2->data - CLIB_CACHE_LINE_BYTES, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
- CLIB_PREFETCH (p3->data - CLIB_CACHE_LINE_BYTES, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (b[2]->data - CLIB_CACHE_LINE_BYTES, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (b[3]->data - CLIB_CACHE_LINE_BYTES, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
}
u32 bi0 = to_next[0] = from[0];
@@ -127,8 +125,10 @@ vxlan_encap_inline (vlib_main_t * vm,
n_left_to_next -= 2;
n_left_from -= 2;
- vlib_buffer_t * b0 = vlib_get_buffer (vm, bi0);
- vlib_buffer_t * b1 = vlib_get_buffer (vm, bi1);
+ vlib_buffer_t * b0 = b[0];
+ vlib_buffer_t * b1 = b[1];
+ b += 2;
+
u32 flow_hash0 = vnet_l2_compute_flow_hash (b0);
u32 flow_hash1 = vnet_l2_compute_flow_hash (b1);
@@ -334,7 +334,9 @@ vxlan_encap_inline (vlib_main_t * vm,
n_left_from -= 1;
n_left_to_next -= 1;
- vlib_buffer_t * b0 = vlib_get_buffer (vm, bi0);
+ vlib_buffer_t * b0 = b[0];
+ b += 1;
+
u32 flow_hash0 = vnet_l2_compute_flow_hash(b0);
/* Get next node index and adj index from tunnel next_dpo */
97 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
/*-
 *   BSD LICENSE
 *
 *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * Neither the name of Intel Corporation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <string.h>
#include <inttypes.h>

#include <rte_common.h>
#include <rte_string_fns.h>

#include <cmdline_parse.h>
#include <cmdline_parse_string.h>

#include "test_cmdline.h"

/* structures needed to run tests */

struct string_elt_str {
	const char * str;	/* parsed string */
	const char * result;	/* expected string */
	int idx;	/* position at which result is expected to be */
};

struct string_elt_str string_elt_strs[] = {
		{"one#two#three", "three", 2},
		{"one#two with spaces#three", "three", 2},
		{"one#two\twith\ttabs#three", "three", 2},
		{"one#two\rwith\rreturns#three", "three", 2},
		{"one#two\nwith\nnewlines#three", "three", 2},
		{"one#two#three", "one", 0},
		{"one#two#three", "two", 1},
		{"one#two\0three", "two", 1},
		{"one#two with spaces#three", "two with spaces", 1},
		{"one#two\twith\ttabs#three", "two\twith\ttabs", 1},
		{"one#two\rwith\rreturns#three", "two\rwith\rreturns", 1},
		{"one#two\nwith\nnewlines#three", "two\nwith\nnewlines", 1},
};

#if (CMDLINE_TEST_BUFSIZE < STR_TOKEN_SIZE) \
|| (CMDLINE_TEST_BUFSIZE < STR_MULTI_TOKEN_SIZE)
#undef CMDLINE_TEST_BUFSIZE
#define CMDLINE_TEST_BUFSIZE RTE_MAX(STR_TOKEN_SIZE, STR_MULTI_TOKEN_SIZE)
#endif

struct string_nb_str {
	const char * str;	/* parsed string */
	int nb_strs;	/* expected number of strings in str */
};

struct string_nb_str string_nb_strs[] = {
		{"one#two#three", 3},
		{"one", 1},
		{"one# \t two \r # three \n #four", 4},
};



struct string_parse_str {
	const char * str;	/* parsed string */
	const char * fixed_str;	/* parsing mode (any, fixed or multi) */
	const char * result;	/* expected result */
};

struct string_parse_str string_parse_strs[] = {
		{"one", NULL, "one"},	/* any string */
		{"two", "one#two#three", "two"},	/* multiple choice string */
		{"three", "three", "three"},	/* fixed string */
		{"three", "one#two with\rgarbage\tcharacters\n#three", "three"},
		{"two with\rgarbage\tcharacters\n",
				"one#two with\rgarbage\tcharacters\n#three",
				"two with\rgarbage\tcharacters\n"},
		{"one two", "one", "one"}, /* fixed string */
		{"one two", TOKEN_STRING_MULTI, "one two"}, /* multi string */
		{"one two", NULL, "one"}, /* any string */
		{"one two #three", TOKEN_STRING_MULTI, "one two "},
		/* multi string with comment */
};



struct string_invalid_str {
	const char * str;	/* parsed string */
	const char * fixed_str;	/* parsing mode (any, fixed or multi) */
};

struct string_invalid_str string_invalid_strs[] = {
		{"invalid", "one"},	/* fixed string */
		{"invalid", "one#two#three"},	/* multiple choice string */
		{"invalid", "invalidone"},	/* string that starts the same */
		{"invalidone", "invalid"},	/* string that starts the same */
		{"toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
		 "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
		 "toolong!!!", NULL },
		{"toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
		 "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
		 "toolong!!!", "fixed" },
		{"toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
		 "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
		 "toolong!!!", "multi#choice#string" },
		{"invalid",
		 "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
		 "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
		 "toolong!!!" },
		 {"", "invalid"}
};



const char * string_help_strs[] = {
		NULL,
		"fixed_str",
		"multi#str",
};



#define STRING_PARSE_STRS_SIZE \
	(sizeof(string_parse_strs) / sizeof(string_parse_strs[0]))
#define STRING_HELP_STRS_SIZE \
	(sizeof(string_help_strs) / sizeof(string_help_strs[0]))
#define STRING_ELT_STRS_SIZE \
	(sizeof(string_elt_strs) / sizeof(string_elt_strs[0]))
#define STRING_NB_STRS_SIZE \
	(sizeof(string_nb_strs) / sizeof(string_nb_strs[0]))
#define STRING_INVALID_STRS_SIZE \
	(sizeof(string_invalid_strs) / sizeof(string_invalid_strs[0]))

#define SMALL_BUF 8

/* test invalid parameters */
int
test_parse_string_invalid_param(void)
{
	cmdline_parse_token_string_t token;
	int result;
	char buf[CMDLINE_TEST_BUFSIZE];

	memset(&token, 0, sizeof(token));

	snprintf(buf, sizeof(buf), "buffer");

	/* test null token */
	if (cmdline_get_help_string(
		NULL, buf, 0) != -1) {
		printf("Error: function accepted null token!\n");
		return -1;
	}
	if (cmdline_complete_get_elt_string(
			NULL, 0, buf, 0) != -1) {
		printf("Error: function accepted null token!\n");
		return -1;
	}
	if (cmdline_complete_get_nb_string(NULL) != -1) {
		printf("Error: function accepted null token!\n");
		return -1;
	}
	if (cmdline_parse_string(NULL, buf, NULL, 0) != -1) {
		printf("Error: function accepted null token!\n");
		return -1;
	}
	/* test null buffer */
	if (cmdline_complete_get_elt_string(
			(cmdline_parse_token_hdr_t*)&token, 0, NULL, 0) != -1) {
		printf("Error: function accepted null buffer!\n");
		return -1;
	}
	if (cmdline_parse_string(
			(cmdline_parse_token_hdr_t*)&token, NULL,
			(void*)&result, sizeof(result)) != -1) {
		printf("Error: function accepted null buffer!\n");
		return -1;
	}
	if (cmdline_get_help_string(
			(cmdline_parse_token_hdr_t*)&token, NULL, 0) != -1) {
		printf("Error: function accepted null buffer!\n");
		return -1;
	}
	/* test null result */
	if (cmdline_parse_string(
			(cmdline_parse_token_hdr_t*)&token, buf, NULL, 0) == -1) {
		printf("Error: function rejected null result!\n");
		return -1;
	}
	/* test negative index */
	if (cmdline_complete_get_elt_string(
			(cmdline_parse_token_hdr_t*)&token, -1, buf, 0) != -1) {
		printf("Error: function accepted negative index!\n");
		return -1;
	}
	return 0;
}

/* test valid parameters but invalid data */
int
test_parse_string_invalid_data(void)
{
	cmdline_parse_token_string_t token;
	cmdline_parse_token_string_t help_token;
	char buf[CMDLINE_TEST_BUFSIZE];
	char help_str[CMDLINE_TEST_BUFSIZE];
	char small_buf[SMALL_BUF];
	unsigned i;

	/* test parsing invalid strings */
	for (i = 0; i < STRING_INVALID_STRS_SIZE; i++) {
		memset(&token, 0, sizeof(token));
		memset(buf, 0, sizeof(buf));

		/* prepare test token data */
		token.string_data.str = string_invalid_strs[i].fixed_str;

		if (cmdline_parse_string((cmdline_parse_token_hdr_t*)&token,
				string_invalid_strs[i].str, (void*)buf,
				sizeof(buf)) != -1) {
			memset(help_str, 0, sizeof(help_str));
			memset(&help_token, 0, sizeof(help_token));

			help_token.string_data.str = string_invalid_strs[i].fixed_str;

			/* get parse type so we can give a good error message */
			cmdline_get_help_string((cmdline_parse_token_hdr_t*)&token, help_str,
					sizeof(help_str));

			printf("Error: parsing %s as %s succeeded!\n",
					string_invalid_strs[i].str, help_str);
			return -1;
		}
	}

	/* misc tests (big comments signify test cases) */
	memset(&token, 0, sizeof(token));
	memset(small_buf, 0, sizeof(small_buf));

	/*
	 * try to get element from a null token
	 */
	token.string_data.str = NULL;
	if (cmdline_complete_get_elt_string(
			(cmdline_parse_token_hdr_t*)&token, 1,
			buf, sizeof(buf)) != -1) {
		printf("Error: getting token from null token string!\n");
		return -1;
	}

	/*
	 * try to get element into a buffer that is too small
	 */
	token.string_data.str = "too_small_buffer";
	if (cmdline_complete_get_elt_string(
			(cmdline_parse_token_hdr_t*)&token, 0,
			small_buf, sizeof(small_buf)) != -1) {
		printf("Error: writing token into too small a buffer succeeded!\n");
		return -1;
	}

	/*
	 * get help string written into a buffer smaller than help string
	 * truncation should occur
	 */
	token.string_data.str = NULL;
	if (cmdline_get_help_string(
			(cmdline_parse_token_hdr_t*)&token,
			small_buf, sizeof(small_buf)) == -1) {
		printf("Error: writing help string into too small a buffer failed!\n");
		return -1;
	}
	/* get help string for "any string" so we can compare it with small_buf */
	cmdline_get_help_string((cmdline_parse_token_hdr_t*)&token, help_str,
			sizeof(help_str));
	if (strncmp(small_buf, help_str, sizeof(small_buf) - 1)) {
		printf("Error: help string mismatch!\n");
		return -1;
	}
	/* check null terminator */
	if (small_buf[sizeof(small_buf) - 1] != '\0') {
		printf("Error: small buffer doesn't have a null terminator!\n");
		return -1;
	}

	/*
	 * try to count tokens in a null token
	 */
	token.string_data.str = NULL;
	if (cmdline_complete_get_nb_string(
			(cmdline_parse_token_hdr_t*)&token) != 0) {
		printf("Error: getting token count from null token succeeded!\n");
		return -1;
	}

	return 0;
}

/* test valid parameters and data */
int
test_parse_string_valid(void)
{
	cmdline_parse_token_string_t token;
	cmdline_parse_token_string_t help_token;
	char buf[CMDLINE_TEST_BUFSIZE];
	char help_str[CMDLINE_TEST_BUFSIZE];
	unsigned i;

	/* test parsing strings */
	for (i = 0; i < STRING_PARSE_STRS_SIZE; i++) {
		memset(&token, 0, sizeof(token));
		memset(buf, 0, sizeof(buf));

		token.string_data.str = string_parse_strs[i].fixed_str;

		if (cmdline_parse_string((cmdline_parse_token_hdr_t*)&token,
				string_parse_strs[i].str, (void*)buf,
				sizeof(buf)) < 0) {

			/* clean help data */
			memset(&help_token, 0, sizeof(help_token));
			memset(help_str, 0, sizeof(help_str));

			/* prepare help token */
			help_token.string_data.str = string_parse_strs[i].fixed_str;

			/* get help string so that we get an informative error message */
			cmdline_get_help_string((cmdline_parse_token_hdr_t*)&token, help_str,
					sizeof(help_str));

			printf("Error: parsing %s as %s failed!\n",
					string_parse_strs[i].str, help_str);
			return -1;
		}
		if (strcmp(buf, string_parse_strs[i].result) != 0) {
			printf("Error: result mismatch!\n");
			return -1;
		}
	}

	/* get number of string tokens and verify it's correct */
	for (i = 0; i < STRING_NB_STRS_SIZE; i++) {
		memset(&token, 0, sizeof(token));

		token.string_data.str = string_nb_strs[i].str;

		if (cmdline_complete_get_nb_string(
				(cmdline_parse_token_hdr_t*)&token) <
				string_nb_strs[i].nb_strs) {
			printf("Error: strings count mismatch!\n");
			return -1;
		}
	}

	/* get token at specified position and verify it's correct */
	for (i = 0; i < STRING_ELT_STRS_SIZE; i++) {
		memset(&token, 0, sizeof(token));
		memset(buf, 0, sizeof(buf));

		token.string_data.str = string_elt_strs[i].str;

		if (cmdline_complete_get_elt_string(
				(cmdline_parse_token_hdr_t*)&token, string_elt_strs[i].idx,
				buf, sizeof(buf)) < 0) {
			printf("Error: getting string element failed!\n");
			return -1;
		}
		if (strncmp(buf, string_elt_strs[i].result,
				sizeof(buf)) != 0) {
			printf("Error: result mismatch!\n");
			return -1;
		}
	}

	/* cover all cases with help strings */
	for (i = 0; i < STRING_HELP_STRS_SIZE; i++) {
		memset(&help_token, 0, sizeof(help_token));
		memset(help_str, 0, sizeof(help_str));
		help_token.string_data.str = string_help_strs[i];
		if (cmdline_get_help_string((cmdline_parse_token_hdr_t*)&help_token,
				help_str, sizeof(help_str)) < 0) {
			printf("Error: help operation failed!\n");
			return -1;
		}
	}

	return 0;
}