net: add rte prefix to IP defines
[dpdk.git] / app / test / test_thash.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015 Vladimir Medvedkin <medvedkinv@gmail.com>
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <rte_common.h>
35 #include <rte_eal.h>
36 #include <rte_ip.h>
37
38 #include "test.h"
39
40 #include <rte_thash.h>
41
42 struct test_thash_v4 {
43         uint32_t        dst_ip;
44         uint32_t        src_ip;
45         uint16_t        dst_port;
46         uint16_t        src_port;
47         uint32_t        hash_l3;
48         uint32_t        hash_l3l4;
49 };
50
51 struct test_thash_v6 {
52         uint8_t         dst_ip[16];
53         uint8_t         src_ip[16];
54         uint16_t        dst_port;
55         uint16_t        src_port;
56         uint32_t        hash_l3;
57         uint32_t        hash_l3l4;
58 };
59
60 /*From 82599 Datasheet 7.1.2.8.3 RSS Verification Suite*/
61 struct test_thash_v4 v4_tbl[] = {
62 {RTE_IPv4(161, 142, 100, 80), RTE_IPv4(66, 9, 149, 187),
63         1766, 2794, 0x323e8fc2, 0x51ccc178},
64 {RTE_IPv4(65, 69, 140, 83), RTE_IPv4(199, 92, 111, 2),
65         4739, 14230, 0xd718262a, 0xc626b0ea},
66 {RTE_IPv4(12, 22, 207, 184), RTE_IPv4(24, 19, 198, 95),
67         38024, 12898, 0xd2d0a5de, 0x5c2b394a},
68 {RTE_IPv4(209, 142, 163, 6), RTE_IPv4(38, 27, 205, 30),
69         2217, 48228, 0x82989176, 0xafc7327f},
70 {RTE_IPv4(202, 188, 127, 2), RTE_IPv4(153, 39, 163, 191),
71         1303, 44251, 0x5d1809c5, 0x10e828a2},
72 };
73
74 struct test_thash_v6 v6_tbl[] = {
75 /*3ffe:2501:200:3::1*/
76 {{0x3f, 0xfe, 0x25, 0x01, 0x02, 0x00, 0x00, 0x03,
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,},
78 /*3ffe:2501:200:1fff::7*/
79 {0x3f, 0xfe, 0x25, 0x01, 0x02, 0x00, 0x1f, 0xff,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,},
81 1766, 2794, 0x2cc18cd5, 0x40207d3d},
82 /*ff02::1*/
83 {{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,},
85 /*3ffe:501:8::260:97ff:fe40:efab*/
86 {0x3f, 0xfe, 0x05, 0x01, 0x00, 0x08, 0x00, 0x00,
87 0x02, 0x60, 0x97, 0xff, 0xfe, 0x40, 0xef, 0xab,},
88 4739, 14230, 0x0f0c461c, 0xdde51bbf},
89 /*fe80::200:f8ff:fe21:67cf*/
90 {{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x02, 0x00, 0xf8, 0xff, 0xfe, 0x21, 0x67, 0xcf,},
92 /*3ffe:1900:4545:3:200:f8ff:fe21:67cf*/
93 {0x3f, 0xfe, 0x19, 0x00, 0x45, 0x45, 0x00, 0x03,
94 0x02, 0x00, 0xf8, 0xff, 0xfe, 0x21, 0x67, 0xcf,},
95 38024, 44251, 0x4b61e985, 0x02d1feef},
96 };
97
98 uint8_t default_rss_key[] = {
99 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
100 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
101 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
102 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
103 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa,
104 };
105
106 static int
107 test_thash(void)
108 {
109         uint32_t i, j;
110         union rte_thash_tuple tuple;
111         uint32_t rss_l3, rss_l3l4;
112         uint8_t rss_key_be[RTE_DIM(default_rss_key)];
113         struct rte_ipv6_hdr ipv6_hdr;
114
115         /* Convert RSS key*/
116         rte_convert_rss_key((uint32_t *)&default_rss_key,
117                 (uint32_t *)rss_key_be, RTE_DIM(default_rss_key));
118
119
120         for (i = 0; i < RTE_DIM(v4_tbl); i++) {
121                 tuple.v4.src_addr = v4_tbl[i].src_ip;
122                 tuple.v4.dst_addr = v4_tbl[i].dst_ip;
123                 tuple.v4.sport = v4_tbl[i].src_port;
124                 tuple.v4.dport = v4_tbl[i].dst_port;
125                 /*Calculate hash with original key*/
126                 rss_l3 = rte_softrss((uint32_t *)&tuple,
127                                 RTE_THASH_V4_L3_LEN, default_rss_key);
128                 rss_l3l4 = rte_softrss((uint32_t *)&tuple,
129                                 RTE_THASH_V4_L4_LEN, default_rss_key);
130                 if ((rss_l3 != v4_tbl[i].hash_l3) ||
131                                 (rss_l3l4 != v4_tbl[i].hash_l3l4))
132                         return -1;
133                 /*Calculate hash with converted key*/
134                 rss_l3 = rte_softrss_be((uint32_t *)&tuple,
135                                 RTE_THASH_V4_L3_LEN, rss_key_be);
136                 rss_l3l4 = rte_softrss_be((uint32_t *)&tuple,
137                                 RTE_THASH_V4_L4_LEN, rss_key_be);
138                 if ((rss_l3 != v4_tbl[i].hash_l3) ||
139                                 (rss_l3l4 != v4_tbl[i].hash_l3l4))
140                         return -1;
141         }
142         for (i = 0; i < RTE_DIM(v6_tbl); i++) {
143                 /*Fill ipv6 hdr*/
144                 for (j = 0; j < RTE_DIM(ipv6_hdr.src_addr); j++)
145                         ipv6_hdr.src_addr[j] = v6_tbl[i].src_ip[j];
146                 for (j = 0; j < RTE_DIM(ipv6_hdr.dst_addr); j++)
147                         ipv6_hdr.dst_addr[j] = v6_tbl[i].dst_ip[j];
148                 /*Load and convert ipv6 address into tuple*/
149                 rte_thash_load_v6_addrs(&ipv6_hdr, &tuple);
150                 tuple.v6.sport = v6_tbl[i].src_port;
151                 tuple.v6.dport = v6_tbl[i].dst_port;
152                 /*Calculate hash with original key*/
153                 rss_l3 = rte_softrss((uint32_t *)&tuple,
154                                 RTE_THASH_V6_L3_LEN, default_rss_key);
155                 rss_l3l4 = rte_softrss((uint32_t *)&tuple,
156                                 RTE_THASH_V6_L4_LEN, default_rss_key);
157                 if ((rss_l3 != v6_tbl[i].hash_l3) ||
158                                 (rss_l3l4 != v6_tbl[i].hash_l3l4))
159                         return -1;
160                 /*Calculate hash with converted key*/
161                 rss_l3 = rte_softrss_be((uint32_t *)&tuple,
162                                 RTE_THASH_V6_L3_LEN, rss_key_be);
163                 rss_l3l4 = rte_softrss_be((uint32_t *)&tuple,
164                                 RTE_THASH_V6_L4_LEN, rss_key_be);
165                 if ((rss_l3 != v6_tbl[i].hash_l3) ||
166                                 (rss_l3l4 != v6_tbl[i].hash_l3l4))
167                         return -1;
168         }
169         return 0;
170 }
171
172 REGISTER_TEST_COMMAND(thash_autotest, test_thash);