Skip to content

Commit a59689e

Browse files
asasidharanAkhil Goyal
authored andcommitted
test/ipsec: add unit test for stateless processing
Add unit test for IPsec stateless processing. Signed-off-by: Aakash Sasidharan <[email protected]> Acked-by: Akhil Goyal <[email protected]>
1 parent ba7cb47 commit a59689e

File tree

1 file changed

+99
-14
lines changed

1 file changed

+99
-14
lines changed

app/test/test_ipsec.c

Lines changed: 99 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ test_ipsec(void)
5353
#define BURST_SIZE 32
5454
#define REORDER_PKTS 1
5555
#define DEQUEUE_COUNT 1000
56+
#define SQN_START 255
5657

5758
struct user_params {
5859
enum rte_crypto_sym_xform_type auth;
@@ -82,6 +83,7 @@ struct ipsec_unitest_params {
8283

8384
struct rte_security_ipsec_xform ipsec_xform;
8485

86+
struct rte_ipsec_state ipsec_state;
8587
struct rte_ipsec_sa_prm sa_prm;
8688
struct rte_ipsec_session ss[MAX_NB_SAS];
8789

@@ -91,6 +93,7 @@ struct ipsec_unitest_params {
9193
*testbuf[BURST_SIZE];
9294

9395
uint16_t pkt_index;
96+
bool is_stateless;
9497
};
9598

9699
struct ipsec_test_cfg {
@@ -773,8 +776,13 @@ crypto_ipsec(uint16_t num_pkts)
773776
struct rte_ipsec_group grp[1];
774777

775778
/* call crypto prepare */
776-
k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
777-
ut_params->cop, num_pkts);
779+
if (ut_params->is_stateless && (ut_params->ipsec_state.sqn != 0))
780+
k = rte_ipsec_pkt_crypto_prepare_stateless(&ut_params->ss[0],
781+
ut_params->ibuf, ut_params->cop, num_pkts, &ut_params->ipsec_state);
782+
else
783+
k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
784+
ut_params->cop, num_pkts);
785+
778786
if (k != num_pkts) {
779787
RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
780788
return TEST_FAILED;
@@ -1322,23 +1330,35 @@ crypto_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
13221330
}
13231331

13241332
static int
1325-
test_ipsec_crypto_outb_burst_null_null(int i)
1333+
test_ipsec_verify_sqn(struct ipsec_unitest_params *ut_params,
1334+
uint16_t num_pkts, uint32_t sqn_start)
1335+
{
1336+
struct rte_esp_hdr esph;
1337+
uint8_t *obuf_data;
1338+
uint32_t sqn;
1339+
uint16_t j;
1340+
1341+
for (j = 0; j < num_pkts; j++) {
1342+
obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1343+
1344+
memcpy(&esph, obuf_data + sizeof(ipv4_outer), sizeof(esph));
1345+
sqn = rte_be_to_cpu_32(esph.seq);
1346+
TEST_ASSERT_EQUAL(sqn, sqn_start + j,
1347+
"Invalid sequence number in packet %u\n", j);
1348+
}
1349+
1350+
return 0;
1351+
}
1352+
1353+
static int
1354+
test_ipsec_crypto_outb_single_burst_null_null(int i, uint32_t sqn_start)
13261355
{
13271356
struct ipsec_testsuite_params *ts_params = &testsuite_params;
13281357
struct ipsec_unitest_params *ut_params = &unittest_params;
13291358
uint16_t num_pkts = test_cfg[i].num_pkts;
13301359
uint16_t j;
1331-
int32_t rc;
1332-
1333-
/* create rte_ipsec_sa*/
1334-
rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1335-
test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1336-
if (rc != 0) {
1337-
RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1338-
return rc;
1339-
}
1360+
int rc = 0;
13401361

1341-
/* Generate input mbuf data */
13421362
for (j = 0; j < num_pkts && rc == 0; j++) {
13431363
ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
13441364
null_plain_data, sizeof(null_plain_data),
@@ -1351,7 +1371,7 @@ test_ipsec_crypto_outb_burst_null_null(int i)
13511371
ut_params->testbuf[j] = setup_test_string_tunneled(
13521372
ts_params->mbuf_pool,
13531373
null_plain_data, test_cfg[i].pkt_sz,
1354-
OUTBOUND_SPI, j + 1);
1374+
OUTBOUND_SPI, j + sqn_start);
13551375
if (ut_params->testbuf[j] == NULL)
13561376
rc = TEST_FAILED;
13571377
}
@@ -1374,10 +1394,73 @@ test_ipsec_crypto_outb_burst_null_null(int i)
13741394
if (rc == TEST_FAILED)
13751395
test_ipsec_dump_buffers(ut_params, i);
13761396

1397+
test_ipsec_verify_sqn(ut_params, num_pkts, sqn_start);
1398+
1399+
return rc;
1400+
}
1401+
1402+
static int
1403+
test_ipsec_crypto_outb_burst_null_null(int i)
1404+
{
1405+
struct ipsec_unitest_params *ut_params = &unittest_params;
1406+
uint32_t sqn_start;
1407+
int32_t rc;
1408+
1409+
/* create rte_ipsec_sa*/
1410+
rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1411+
test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1412+
if (rc != 0) {
1413+
RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1414+
return rc;
1415+
}
1416+
1417+
/* Generate input mbuf data and test normal IPsec processing */
1418+
sqn_start = 1;
1419+
rc = test_ipsec_crypto_outb_single_burst_null_null(i, sqn_start);
1420+
if (rc != 0) {
1421+
RTE_LOG(ERR, USER1, "burst failed, cfg %d\n", i);
1422+
return rc;
1423+
}
1424+
1425+
if (ut_params->is_stateless) {
1426+
1427+
/* Generate input mbuf data for stateless IPsec processing. */
1428+
sqn_start = ut_params->ipsec_state.sqn = SQN_START;
1429+
rc = test_ipsec_crypto_outb_single_burst_null_null(i, sqn_start);
1430+
if (rc != 0) {
1431+
RTE_LOG(ERR, USER1, "stateless burst failed, cfg %d\n", i);
1432+
return rc;
1433+
}
1434+
}
1435+
13771436
destroy_sa(0);
13781437
return rc;
13791438
}
13801439

1440+
static int
1441+
test_ipsec_crypto_outb_burst_stateless_null_null_wrapper(void)
1442+
{
1443+
struct ipsec_unitest_params *ut_params = &unittest_params;
1444+
int rc = 0;
1445+
int i;
1446+
1447+
ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1448+
ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1449+
ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1450+
ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1451+
ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1452+
ut_params->is_stateless = true;
1453+
1454+
for (i = 0; i < num_cfg && rc == 0; i++) {
1455+
ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1456+
ut_params->ipsec_state.sqn = 0;
1457+
rc = test_ipsec_crypto_outb_burst_null_null(i);
1458+
1459+
}
1460+
1461+
return rc;
1462+
}
1463+
13811464
static int
13821465
test_ipsec_crypto_outb_burst_null_null_wrapper(void)
13831466
{
@@ -2496,6 +2579,8 @@ static struct unit_test_suite ipsec_testsuite = {
24962579
test_ipsec_crypto_inb_burst_null_null_wrapper),
24972580
TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
24982581
test_ipsec_crypto_outb_burst_null_null_wrapper),
2582+
TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2583+
test_ipsec_crypto_outb_burst_stateless_null_null_wrapper),
24992584
TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
25002585
test_ipsec_inline_crypto_inb_burst_null_null_wrapper),
25012586
TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,

0 commit comments

Comments
 (0)