test/service: fix race condition on stopping lcore
[dpdk.git] / app / test / test_thash.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2019 Vladimir Medvedkin <medvedkinv@gmail.com>
3  */
4
5 #include <rte_common.h>
6 #include <rte_eal.h>
7 #include <rte_ip.h>
8
9 #include "test.h"
10
11 #include <rte_thash.h>
12
13 struct test_thash_v4 {
14         uint32_t        dst_ip;
15         uint32_t        src_ip;
16         uint16_t        dst_port;
17         uint16_t        src_port;
18         uint32_t        hash_l3;
19         uint32_t        hash_l3l4;
20 };
21
22 struct test_thash_v6 {
23         uint8_t         dst_ip[16];
24         uint8_t         src_ip[16];
25         uint16_t        dst_port;
26         uint16_t        src_port;
27         uint32_t        hash_l3;
28         uint32_t        hash_l3l4;
29 };
30
31 /*From 82599 Datasheet 7.1.2.8.3 RSS Verification Suite*/
32 struct test_thash_v4 v4_tbl[] = {
33 {RTE_IPV4(161, 142, 100, 80), RTE_IPV4(66, 9, 149, 187),
34         1766, 2794, 0x323e8fc2, 0x51ccc178},
35 {RTE_IPV4(65, 69, 140, 83), RTE_IPV4(199, 92, 111, 2),
36         4739, 14230, 0xd718262a, 0xc626b0ea},
37 {RTE_IPV4(12, 22, 207, 184), RTE_IPV4(24, 19, 198, 95),
38         38024, 12898, 0xd2d0a5de, 0x5c2b394a},
39 {RTE_IPV4(209, 142, 163, 6), RTE_IPV4(38, 27, 205, 30),
40         2217, 48228, 0x82989176, 0xafc7327f},
41 {RTE_IPV4(202, 188, 127, 2), RTE_IPV4(153, 39, 163, 191),
42         1303, 44251, 0x5d1809c5, 0x10e828a2},
43 };
44
45 struct test_thash_v6 v6_tbl[] = {
46 /*3ffe:2501:200:3::1*/
47 {{0x3f, 0xfe, 0x25, 0x01, 0x02, 0x00, 0x00, 0x03,
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,},
49 /*3ffe:2501:200:1fff::7*/
50 {0x3f, 0xfe, 0x25, 0x01, 0x02, 0x00, 0x1f, 0xff,
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,},
52 1766, 2794, 0x2cc18cd5, 0x40207d3d},
53 /*ff02::1*/
54 {{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,},
56 /*3ffe:501:8::260:97ff:fe40:efab*/
57 {0x3f, 0xfe, 0x05, 0x01, 0x00, 0x08, 0x00, 0x00,
58 0x02, 0x60, 0x97, 0xff, 0xfe, 0x40, 0xef, 0xab,},
59 4739, 14230, 0x0f0c461c, 0xdde51bbf},
60 /*fe80::200:f8ff:fe21:67cf*/
61 {{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x02, 0x00, 0xf8, 0xff, 0xfe, 0x21, 0x67, 0xcf,},
63 /*3ffe:1900:4545:3:200:f8ff:fe21:67cf*/
64 {0x3f, 0xfe, 0x19, 0x00, 0x45, 0x45, 0x00, 0x03,
65 0x02, 0x00, 0xf8, 0xff, 0xfe, 0x21, 0x67, 0xcf,},
66 38024, 44251, 0x4b61e985, 0x02d1feef},
67 };
68
69 uint8_t default_rss_key[] = {
70 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
71 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
72 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
73 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
74 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa,
75 };
76
77 static int
78 test_thash(void)
79 {
80         uint32_t i, j;
81         union rte_thash_tuple tuple;
82         uint32_t rss_l3, rss_l3l4;
83         uint8_t rss_key_be[RTE_DIM(default_rss_key)];
84         struct rte_ipv6_hdr ipv6_hdr;
85
86         /* Convert RSS key*/
87         rte_convert_rss_key((uint32_t *)&default_rss_key,
88                 (uint32_t *)rss_key_be, RTE_DIM(default_rss_key));
89
90
91         for (i = 0; i < RTE_DIM(v4_tbl); i++) {
92                 tuple.v4.src_addr = v4_tbl[i].src_ip;
93                 tuple.v4.dst_addr = v4_tbl[i].dst_ip;
94                 tuple.v4.sport = v4_tbl[i].src_port;
95                 tuple.v4.dport = v4_tbl[i].dst_port;
96                 /*Calculate hash with original key*/
97                 rss_l3 = rte_softrss((uint32_t *)&tuple,
98                                 RTE_THASH_V4_L3_LEN, default_rss_key);
99                 rss_l3l4 = rte_softrss((uint32_t *)&tuple,
100                                 RTE_THASH_V4_L4_LEN, default_rss_key);
101                 if ((rss_l3 != v4_tbl[i].hash_l3) ||
102                                 (rss_l3l4 != v4_tbl[i].hash_l3l4))
103                         return -1;
104                 /*Calculate hash with converted key*/
105                 rss_l3 = rte_softrss_be((uint32_t *)&tuple,
106                                 RTE_THASH_V4_L3_LEN, rss_key_be);
107                 rss_l3l4 = rte_softrss_be((uint32_t *)&tuple,
108                                 RTE_THASH_V4_L4_LEN, rss_key_be);
109                 if ((rss_l3 != v4_tbl[i].hash_l3) ||
110                                 (rss_l3l4 != v4_tbl[i].hash_l3l4))
111                         return -1;
112         }
113         for (i = 0; i < RTE_DIM(v6_tbl); i++) {
114                 /*Fill ipv6 hdr*/
115                 for (j = 0; j < RTE_DIM(ipv6_hdr.src_addr); j++)
116                         ipv6_hdr.src_addr[j] = v6_tbl[i].src_ip[j];
117                 for (j = 0; j < RTE_DIM(ipv6_hdr.dst_addr); j++)
118                         ipv6_hdr.dst_addr[j] = v6_tbl[i].dst_ip[j];
119                 /*Load and convert ipv6 address into tuple*/
120                 rte_thash_load_v6_addrs(&ipv6_hdr, &tuple);
121                 tuple.v6.sport = v6_tbl[i].src_port;
122                 tuple.v6.dport = v6_tbl[i].dst_port;
123                 /*Calculate hash with original key*/
124                 rss_l3 = rte_softrss((uint32_t *)&tuple,
125                                 RTE_THASH_V6_L3_LEN, default_rss_key);
126                 rss_l3l4 = rte_softrss((uint32_t *)&tuple,
127                                 RTE_THASH_V6_L4_LEN, default_rss_key);
128                 if ((rss_l3 != v6_tbl[i].hash_l3) ||
129                                 (rss_l3l4 != v6_tbl[i].hash_l3l4))
130                         return -1;
131                 /*Calculate hash with converted key*/
132                 rss_l3 = rte_softrss_be((uint32_t *)&tuple,
133                                 RTE_THASH_V6_L3_LEN, rss_key_be);
134                 rss_l3l4 = rte_softrss_be((uint32_t *)&tuple,
135                                 RTE_THASH_V6_L4_LEN, rss_key_be);
136                 if ((rss_l3 != v6_tbl[i].hash_l3) ||
137                                 (rss_l3l4 != v6_tbl[i].hash_l3l4))
138                         return -1;
139         }
140         return 0;
141 }
142
143 REGISTER_TEST_COMMAND(thash_autotest, test_thash);