@@ -124,6 +124,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_IVSHMEM) += test_ivshmem.c
SRCS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) += test_distributor.c
SRCS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) += test_distributor_perf.c
+SRCS-$(CONFIG_RTE_LIBRTE_REORDER) += test_reorder.c
+
SRCS-y += test_devargs.c
SRCS-y += virtual_pmd.c
SRCS-y += packet_burst_generator.c
new file mode 100644
@@ -0,0 +1,452 @@
+/*-
+ * 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 "test.h"
+#include "stdio.h"
+
+#include <unistd.h>
+#include <string.h>
+
+#include <rte_cycles.h>
+#include <rte_errno.h>
+#include <rte_mbuf.h>
+#include <rte_reorder.h>
+#include <rte_lcore.h>
+#include <rte_malloc.h>
+
+#include "test.h"
+
+#define BURST 32
+#define REORDER_BUFFER_SIZE 16384
+#define NUM_MBUFS (2*REORDER_BUFFER_SIZE)
+#define REORDER_BUFFER_SIZE_INVALID 2049
+#define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
+
+struct reorder_unittest_params {
+ struct rte_mempool *p;
+ struct rte_reorder_buffer *b;
+};
+
+static struct reorder_unittest_params default_params = {
+ .p = NULL,
+ .b = NULL
+};
+
+static struct reorder_unittest_params *test_params = &default_params;
+
+static int
+test_reorder_create_inval_name(void)
+{
+ struct rte_reorder_buffer *b = NULL;
+ char *name = NULL;
+
+ b = rte_reorder_create(name, rte_socket_id(), REORDER_BUFFER_SIZE);
+ TEST_ASSERT_EQUAL(b, NULL, "No error on create() with invalid name param.");
+ TEST_ASSERT_EQUAL(rte_errno, EINVAL,
+ "No error on create() with invalid name param.");
+ return 0;
+}
+
+static int
+test_reorder_create_inval_size(void)
+{
+ struct rte_reorder_buffer *b = NULL;
+
+ b = rte_reorder_create("PKT", rte_socket_id(), REORDER_BUFFER_SIZE_INVALID);
+ TEST_ASSERT_EQUAL(b, NULL,
+ "No error on create() with invalid buffer size param.");
+ TEST_ASSERT_EQUAL(rte_errno, EINVAL,
+ "No error on create() with invalid buffer size param.");
+ return 0;
+}
+
+static int
+test_reorder_init_null_buffer(void)
+{
+ struct rte_reorder_buffer *b = NULL;
+ /*
+ * The minimum memory area size that should be passed to library is,
+ * sizeof(struct rte_reorder_buffer) + (2 * size * sizeof(struct rte_mbuf *));
+ * Otherwise error will be thrown
+ */
+ unsigned int mzsize = 262336;
+ b = rte_reorder_init(b, mzsize, "PKT1", REORDER_BUFFER_SIZE);
+ TEST_ASSERT_EQUAL(b, NULL, "No error on init with NULL buffer.");
+ TEST_ASSERT_EQUAL(rte_errno, EINVAL, "No error on init with NULL buffer.");
+ return 0;
+}
+
+static int
+test_reorder_init_inval_mzsize(void)
+{
+ struct rte_reorder_buffer *b = NULL;
+ unsigned int mzsize = 100;
+ b = rte_malloc(NULL, mzsize, 0);
+ b = rte_reorder_init(b, mzsize, "PKT1", REORDER_BUFFER_SIZE);
+ TEST_ASSERT_EQUAL(b, NULL, "No error on init with invalid mem zone size.");
+ TEST_ASSERT_EQUAL(rte_errno, ENOMEM,
+ "No error on init with invalid mem zone size.");
+ rte_free(b);
+ return 0;
+}
+
+static int
+test_reorder_init_inval_size(void)
+{
+ struct rte_reorder_buffer *b = NULL;
+ unsigned int mzsize = 262336;
+ b = rte_malloc(NULL, mzsize, 0);
+ b = rte_reorder_init(b, mzsize, "PKT1", REORDER_BUFFER_SIZE_INVALID);
+ TEST_ASSERT_EQUAL(b, NULL, "No error on init with invalid buffer size param.");
+ TEST_ASSERT_EQUAL(rte_errno, EINVAL,
+ "No error on init with invalid buffer size param.");
+ rte_free(b);
+ return 0;
+}
+
+static int
+test_reorder_init_inval_name(void)
+{
+ struct rte_reorder_buffer *b = NULL;
+ char *name = NULL;
+ unsigned int mzsize = 262336;
+ b = rte_malloc(NULL, mzsize, 0);
+ b = rte_reorder_init(b, mzsize, name, REORDER_BUFFER_SIZE);
+ TEST_ASSERT_EQUAL(b, NULL, "No error on init with invalid name.");
+ TEST_ASSERT_EQUAL(rte_errno, EINVAL, "No error on init with invalid name.");
+ rte_free(b);
+ return 0;
+}
+
+static int
+test_reorder_buf_instance_existance(void)
+{
+ struct rte_reorder_buffer *result = NULL;
+ struct rte_reorder_buffer *b1 = NULL;
+ struct rte_reorder_buffer *b2 = NULL;
+ unsigned int mzsize = 262336;
+
+ /* Try to find existing reorder buffer instance */
+ result = rte_reorder_find_existing("PKT_RO1");
+ TEST_ASSERT_EQUAL(test_params->b, result,
+ "existing reorder buffer instance not found");
+
+ /* Try to find non existing reorder buffer instance */
+ result = rte_reorder_find_existing("ro_find_non_existing");
+ TEST_ASSERT_EQUAL(result, NULL,
+ "non existing reorder buffer instance found");
+ TEST_ASSERT_EQUAL(rte_errno, ENOENT,
+ "non existing reorder buffer instance found");
+
+ b1 = rte_malloc(NULL, mzsize, 0);
+ b2 = rte_reorder_init(b1, mzsize, "PKT_RO1", REORDER_BUFFER_SIZE);
+ TEST_ASSERT_EQUAL(b2, test_params->b,
+ "no error on init with existing reorder instance name");
+ rte_free(b1);
+
+ b1 = rte_malloc(NULL, mzsize, 0);
+ b2 = rte_reorder_init(b1, mzsize, "ro_find_nonexisting1", REORDER_BUFFER_SIZE);
+ TEST_ASSERT_EQUAL(b2, b1,
+ "error on init with non existing reorder instance name");
+ rte_reorder_free(b1);
+
+ return 0;
+}
+
+static int
+test_reorder_insert(void)
+{
+ struct rte_reorder_buffer *b = test_params->b;
+ struct rte_mempool *p = test_params->p;
+ rte_reorder_reset(b);
+ int num_bufs = 4;
+ struct rte_mbuf *bufs[num_bufs];
+ int ret = 0;
+ if (rte_mempool_get_bulk(p, (void *)bufs, num_bufs) != 0) {
+ printf("%s: Error getting mbuf from pool\n", __func__);
+ return -1;
+ }
+
+ /* too early packet */
+ bufs[0]->seqn = (3*REORDER_BUFFER_SIZE);
+ ret = rte_reorder_insert(b, bufs[0]);
+ if (ret != -1 || rte_errno != ERANGE) {
+ printf("%s:%d: No error on insert() of too early packet with seqn:"
+ " (3*REORDER_BUFFER_SIZE)\n", __func__, __LINE__);
+ rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
+ return -1;
+ }
+
+ /* early packet */
+ bufs[1]->seqn = (2*REORDER_BUFFER_SIZE)-2;
+ ret = rte_reorder_insert(b, bufs[1]);
+ if (ret == -1 || rte_errno == ENOSPC) {
+ printf("%s:%d: Error on insert of early packet with seqn:"
+ " (2*REORDER_BUFFER_SIZE)-2\n", __func__ , __LINE__);
+ rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
+ return -1;
+ }
+
+ bufs[2]->seqn = (3*REORDER_BUFFER_SIZE)-1;
+ ret = rte_reorder_insert(b, bufs[2]);
+ if (ret != -1 && rte_errno != ENOSPC) {
+ printf("%s:%d: Error on insert of early packet with seqn:"
+ " (3*REORDER_BUFFER_SIZE)-3\n", __func__ , __LINE__);
+ rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
+ return -1;
+ }
+
+ rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
+ return 0;
+}
+
+/* Test case covers draining conditions on order buffer */
+static int
+test_reorder_drain_order_buf(void)
+{
+
+ struct rte_reorder_buffer *b = test_params->b;
+ struct rte_mempool *p = test_params->p;
+ rte_reorder_reset(b);
+ struct rte_mbuf *bufs[REORDER_BUFFER_SIZE+10] = {NULL};
+ struct rte_mbuf *robufs[REORDER_BUFFER_SIZE+10] = {NULL};
+ int cnt;
+ int i = 0;
+
+ if (rte_mempool_get_bulk(p, (void *)bufs, REORDER_BUFFER_SIZE+10) != 0) {
+ printf("%s: Error getting mbuf from pool\n", __func__);
+ return -1;
+ }
+
+ /* insert mbufs in order buffer with gaps i.e seqn 0 to 5 and 8,9 inserted */
+ for (i = 0; i < 10; ) {
+ bufs[i]->seqn = i;
+ rte_reorder_insert(b, bufs[i]);
+ if (i == 5)
+ i += 3;
+ else
+ i++;
+ }
+
+ /* should drain till first gap */
+ cnt = rte_reorder_drain(b, robufs, BURST);
+ if (cnt != 6) {
+ printf("%s:%d:%d: number of expected packets not drained\n",
+ __func__, __LINE__, cnt);
+ rte_mempool_put_bulk(p, (void *)bufs, REORDER_BUFFER_SIZE+10);
+ return -1;
+ }
+
+ /* now add missing entries and remaining entries till end of order buf */
+ bufs[6]->seqn = 6;
+ bufs[7]->seqn = 7;
+ rte_reorder_insert(b, bufs[6]);
+ rte_reorder_insert(b, bufs[7]);
+ for (i = 10; i < REORDER_BUFFER_SIZE; i++) {
+ bufs[i]->seqn = i;
+ rte_reorder_insert(b, bufs[i]);
+ }
+
+ /*
+ * hence gaps are filled now, drain should return entries
+ * from last gap to till end
+ */
+ cnt = rte_reorder_drain(b, robufs, REORDER_BUFFER_SIZE+1);
+ if (cnt != REORDER_BUFFER_SIZE-6) {
+ printf("%s:%d: number of expected packets not drained\n",
+ __func__, __LINE__);
+ rte_mempool_put_bulk(p, (void *)bufs, REORDER_BUFFER_SIZE+10);
+ return -1;
+ }
+ rte_mempool_put_bulk(p, (void *)bufs, REORDER_BUFFER_SIZE+10);
+ return 0;
+}
+
+/* Test case covers draining conditions on ready buffer */
+static int
+test_reorder_drain_ready_buf(void)
+{
+
+ struct rte_reorder_buffer *b = test_params->b;
+ struct rte_mempool *p = test_params->p;
+ rte_reorder_reset(b);
+
+ struct rte_mbuf *bufs[REORDER_BUFFER_SIZE+10] = {NULL};
+ struct rte_mbuf *robufs[REORDER_BUFFER_SIZE+10] = {NULL};
+ int cnt = 0;
+ int i;
+ int ret = 0;
+
+ if (rte_mempool_get_bulk(p, (void *)bufs, REORDER_BUFFER_SIZE+10) != 0) {
+ printf("%s: Error getting mbuf from pool\n", __func__);
+ return -1;
+ }
+
+ /*1: draining of ready buffer with tail == 0 */
+ for (i = 0; i < REORDER_BUFFER_SIZE; i++) {
+ bufs[i]->seqn = i;
+ ret = rte_reorder_insert(b, bufs[i]);
+ if (ret) {
+ printf("%s: Error on insert of bufs[%u]\n",
+ __func__, i);
+ rte_mempool_put_bulk(p, (void *)bufs, REORDER_BUFFER_SIZE+10);
+ return -1;
+ }
+ }
+
+ /*
+ * insert early packet, this moves entries from order buffer
+ * to ready buffer
+ */
+ bufs[REORDER_BUFFER_SIZE]->seqn = (2*REORDER_BUFFER_SIZE)-1;
+ rte_reorder_insert(b, bufs[REORDER_BUFFER_SIZE]);
+
+ /*
+ * since ready buffer is full, could drain REORDER_BUFFER_SIZE
+ * entries from ready buffer
+ */
+ cnt = rte_reorder_drain(b, robufs, REORDER_BUFFER_SIZE);
+ if (cnt != REORDER_BUFFER_SIZE) {
+ printf("%s:%d:%d: number of expected packets not drained\n",
+ __func__, __LINE__, cnt);
+ rte_mempool_put_bulk(p, (void *)bufs, REORDER_BUFFER_SIZE+10);
+ return -1;
+ }
+
+ /*2: draining of ready buffer with tail != 0 */
+
+ /* insert mbufs with seqn:REORDER_BUFFER_SIZE to 2*REORDER_BUFFER_SIZE */
+ for (i = 0; i < REORDER_BUFFER_SIZE; i++) {
+ bufs[i]->seqn = REORDER_BUFFER_SIZE+1+i;
+ ret = rte_reorder_insert(b, bufs[i]);
+ if (ret) {
+ printf("%s: Error on insert of bufs[%u]\n",
+ __func__, i);
+ rte_mempool_put_bulk(p, (void *)bufs, REORDER_BUFFER_SIZE+10);
+ return -1;
+ }
+ }
+
+ /*
+ * insert early packet, this will move entries
+ * from order buffer to ready buffer
+ */
+ bufs[REORDER_BUFFER_SIZE]->seqn = (3*REORDER_BUFFER_SIZE)-5;
+ rte_reorder_insert(b, bufs[REORDER_BUFFER_SIZE]);
+
+ /*
+ * drain only 3 mbufs, this will drain ready buffer
+ * and advances tail by 3
+ */
+ cnt = rte_reorder_drain(b, robufs, 3);
+ if (cnt != 3) {
+ printf("%s:%d:%d: number of expected packets not drained\n",
+ __func__, __LINE__, cnt);
+ rte_mempool_put_bulk(p, (void *)bufs, REORDER_BUFFER_SIZE+10);
+ return -1;
+ }
+
+ /* insert early packet */
+ bufs[REORDER_BUFFER_SIZE]->seqn = (3*REORDER_BUFFER_SIZE)+2;
+ rte_reorder_insert(b, bufs[REORDER_BUFFER_SIZE]);
+
+ /*
+ * perform drain on ready buffer with advanced tail,
+ * validates if(tail == size) in drain
+ */
+ rte_reorder_drain(b, robufs, REORDER_BUFFER_SIZE);
+ rte_mempool_put_bulk(p, (void *)bufs, REORDER_BUFFER_SIZE+10);
+ return 0;
+}
+
+static int
+test_setup(void)
+{
+ /* reorder buffer instance creation */
+ if (test_params->b == NULL) {
+ test_params->b = rte_reorder_create("PKT_RO1", rte_socket_id(),
+ REORDER_BUFFER_SIZE);
+ if (test_params->b == NULL) {
+ printf("%s: Error creating reorder buffer instance b\n",
+ __func__);
+ return -1;
+ }
+ } else
+ rte_reorder_reset(test_params->b);
+
+ /* mempool creation */
+ if (test_params->p == NULL) {
+ test_params->p = rte_mempool_create("RO_MBUF_POOL", NUM_MBUFS,
+ MBUF_SIZE, BURST,
+ sizeof(struct rte_pktmbuf_pool_private),
+ rte_pktmbuf_pool_init, NULL,
+ rte_pktmbuf_init, NULL,
+ rte_socket_id(), 0);
+ if (test_params->p == NULL) {
+ printf("%s: Error creating mempool\n", __func__);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static struct unit_test_suite reorder_test_suite = {
+
+ .setup = test_setup,
+ .suite_name = "Reorder Unit Test Suite",
+ .unit_test_cases = {
+ TEST_CASE(test_reorder_create_inval_name),
+ TEST_CASE(test_reorder_create_inval_size),
+ TEST_CASE(test_reorder_init_null_buffer),
+ TEST_CASE(test_reorder_init_inval_mzsize),
+ TEST_CASE(test_reorder_init_inval_size),
+ TEST_CASE(test_reorder_init_inval_name),
+ TEST_CASE(test_reorder_buf_instance_existance),
+ TEST_CASE(test_reorder_insert),
+ TEST_CASE(test_reorder_drain_order_buf),
+ TEST_CASE(test_reorder_drain_ready_buf),
+ TEST_CASES_END()
+ }
+};
+
+static int
+test_reorder(void)
+{
+ return unit_test_suite_runner(&reorder_test_suite);
+}
+
+static struct test_command reorder_cmd = {
+ .command = "reorder_autotest",
+ .callback = test_reorder,
+};
+REGISTER_TEST_COMMAND(reorder_cmd);
@@ -67,6 +67,10 @@ ifeq ($(CONFIG_RTE_LIBRTE_DISTRIBUTOR),y)
LDLIBS += -lrte_distributor
endif
+ifeq ($(CONFIG_RTE_LIBRTE_REORDER),y)
+LDLIBS += -lrte_reorder
+endif
+
ifeq ($(CONFIG_RTE_LIBRTE_KNI),y)
ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
LDLIBS += -lrte_kni