Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation
3 : : */
4 : :
5 : : #ifndef RTE_EXEC_ENV_WINDOWS
6 : :
7 : : #include <string.h>
8 : : #include "test_table_combined.h"
9 : : #include "test_table.h"
10 : : #include <rte_table_lpm_ipv6.h>
11 : :
12 : : #define MAX_TEST_KEYS 128
13 : : #define N_PACKETS 50
14 : :
15 : : enum check_table_result {
16 : : CHECK_TABLE_OK,
17 : : CHECK_TABLE_PORT_CONFIG,
18 : : CHECK_TABLE_PORT_ENABLE,
19 : : CHECK_TABLE_TABLE_CONFIG,
20 : : CHECK_TABLE_ENTRY_ADD,
21 : : CHECK_TABLE_DEFAULT_ENTRY_ADD,
22 : : CHECK_TABLE_CONNECT,
23 : : CHECK_TABLE_MANAGE_ERROR,
24 : : CHECK_TABLE_CONSISTENCY,
25 : : CHECK_TABLE_NO_TRAFFIC,
26 : : CHECK_TABLE_INVALID_PARAMETER,
27 : : };
28 : :
29 : : struct table_packets {
30 : : uint32_t hit_packet[MAX_TEST_KEYS];
31 : : uint32_t miss_packet[MAX_TEST_KEYS];
32 : : uint32_t n_hit_packets;
33 : : uint32_t n_miss_packets;
34 : : };
35 : :
36 : : combined_table_test table_tests_combined[] = {
37 : : test_table_lpm_combined,
38 : : test_table_lpm_ipv6_combined,
39 : : test_table_hash8lru,
40 : : test_table_hash8ext,
41 : : test_table_hash16lru,
42 : : test_table_hash16ext,
43 : : test_table_hash32lru,
44 : : test_table_hash32ext,
45 : : test_table_hash_cuckoo_combined,
46 : : };
47 : :
48 : : unsigned n_table_tests_combined = RTE_DIM(table_tests_combined);
49 : :
50 : : /* Generic port tester function */
51 : : static int
52 : 30 : test_table_type(struct rte_table_ops *table_ops, void *table_args,
53 : : void *key, struct table_packets *table_packets,
54 : : struct manage_ops *manage_ops, unsigned n_ops)
55 : : {
56 : : uint32_t ring_in_id, table_id, ring_out_id, ring_out_2_id;
57 : : unsigned i;
58 : :
59 : : RTE_SET_USED(manage_ops);
60 : : RTE_SET_USED(n_ops);
61 : : /* Create pipeline */
62 : 30 : struct rte_pipeline_params pipeline_params = {
63 : : .name = "pipeline",
64 : : .socket_id = 0,
65 : : };
66 : :
67 : 30 : struct rte_pipeline *pipeline = rte_pipeline_create(&pipeline_params);
68 : :
69 : : /* Create input ring */
70 : 30 : struct rte_port_ring_reader_params ring_params_rx = {
71 : 30 : .ring = RING_RX,
72 : : };
73 : :
74 : 30 : struct rte_port_ring_writer_params ring_params_tx = {
75 : : .ring = RING_RX,
76 : : .tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX,
77 : : };
78 : :
79 : 30 : struct rte_pipeline_port_in_params ring_in_params = {
80 : : .ops = &rte_port_ring_reader_ops,
81 : : .arg_create = (void *)&ring_params_rx,
82 : : .f_action = NULL,
83 : : .burst_size = RTE_PORT_IN_BURST_SIZE_MAX,
84 : : };
85 : :
86 [ - + ]: 30 : if (rte_pipeline_port_in_create(pipeline, &ring_in_params,
87 : : &ring_in_id) != 0) {
88 : 0 : rte_pipeline_free(pipeline);
89 : 0 : return -CHECK_TABLE_PORT_CONFIG;
90 : : }
91 : :
92 : : /* Create table */
93 : 30 : struct rte_pipeline_table_params table_params = {
94 : : .ops = table_ops,
95 : : .arg_create = table_args,
96 : : .f_action_hit = NULL,
97 : : .f_action_miss = NULL,
98 : : .arg_ah = NULL,
99 : : .action_data_size = 0,
100 : : };
101 : :
102 [ + + ]: 30 : if (rte_pipeline_table_create(pipeline, &table_params,
103 : : &table_id) != 0) {
104 : 17 : rte_pipeline_free(pipeline);
105 : 17 : return -CHECK_TABLE_TABLE_CONFIG;
106 : : }
107 : :
108 : : /* Create output ports */
109 : 13 : ring_params_tx.ring = RING_TX;
110 : :
111 : 13 : struct rte_pipeline_port_out_params ring_out_params = {
112 : : .ops = &rte_port_ring_writer_ops,
113 : : .arg_create = (void *)&ring_params_tx,
114 : : .f_action = NULL,
115 : : };
116 : :
117 [ - + ]: 13 : if (rte_pipeline_port_out_create(pipeline, &ring_out_params,
118 : : &ring_out_id) != 0) {
119 : 0 : rte_pipeline_free(pipeline);
120 : 0 : return -CHECK_TABLE_PORT_CONFIG;
121 : : }
122 : :
123 : 13 : ring_params_tx.ring = RING_TX_2;
124 : :
125 [ - + ]: 13 : if (rte_pipeline_port_out_create(pipeline, &ring_out_params,
126 : : &ring_out_2_id) != 0) {
127 : 0 : rte_pipeline_free(pipeline);
128 : 0 : return -CHECK_TABLE_PORT_CONFIG;
129 : : }
130 : :
131 : : /* Add entry to the table */
132 : 13 : struct rte_pipeline_table_entry default_entry = {
133 : : .action = RTE_PIPELINE_ACTION_DROP,
134 : : {.table_id = ring_out_id},
135 : : };
136 : :
137 : 13 : struct rte_pipeline_table_entry table_entry = {
138 : : .action = RTE_PIPELINE_ACTION_PORT,
139 : : {.table_id = ring_out_id},
140 : : };
141 : :
142 : : struct rte_pipeline_table_entry *default_entry_ptr, *entry_ptr;
143 : :
144 : : int key_found;
145 : :
146 [ - + ]: 13 : if (rte_pipeline_table_default_entry_add(pipeline, table_id,
147 : : &default_entry, &default_entry_ptr) != 0) {
148 : 0 : rte_pipeline_free(pipeline);
149 : 0 : return -CHECK_TABLE_DEFAULT_ENTRY_ADD;
150 : : }
151 : :
152 [ + - + + ]: 26 : if (rte_pipeline_table_entry_add(pipeline, table_id,
153 : : key ? key : &table_entry, &table_entry, &key_found,
154 : : &entry_ptr) != 0) {
155 : 4 : rte_pipeline_free(pipeline);
156 : 4 : return -CHECK_TABLE_ENTRY_ADD;
157 : : }
158 : :
159 : : /* Create connections and check consistency */
160 [ - + ]: 9 : if (rte_pipeline_port_in_connect_to_table(pipeline, ring_in_id,
161 : : table_id) != 0) {
162 : 0 : rte_pipeline_free(pipeline);
163 : 0 : return -CHECK_TABLE_CONNECT;
164 : : }
165 : :
166 [ - + ]: 9 : if (rte_pipeline_port_in_enable(pipeline, ring_in_id) != 0) {
167 : 0 : rte_pipeline_free(pipeline);
168 : 0 : return -CHECK_TABLE_PORT_ENABLE;
169 : : }
170 : :
171 [ - + ]: 9 : if (rte_pipeline_check(pipeline) != 0) {
172 : 0 : rte_pipeline_free(pipeline);
173 : 0 : return -CHECK_TABLE_CONSISTENCY;
174 : : }
175 : :
176 : :
177 : :
178 : : /* Flow test - All hits */
179 [ + - ]: 9 : if (table_packets->n_hit_packets) {
180 [ + + ]: 459 : for (i = 0; i < table_packets->n_hit_packets; i++)
181 [ + - - + : 900 : RING_ENQUEUE(RING_RX, table_packets->hit_packet[i]);
- - - ]
182 : :
183 : 9 : RUN_PIPELINE(pipeline);
184 : :
185 [ - + - - : 459 : VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets,
- - + + +
- + ]
186 : : table_packets->n_hit_packets);
187 : : }
188 : :
189 : : /* Flow test - All misses */
190 [ + - ]: 9 : if (table_packets->n_miss_packets) {
191 [ + + ]: 459 : for (i = 0; i < table_packets->n_miss_packets; i++)
192 [ + - - + : 900 : RING_ENQUEUE(RING_RX, table_packets->miss_packet[i]);
- - - ]
193 : :
194 : 9 : RUN_PIPELINE(pipeline);
195 : :
196 [ - + - - : 18 : VERIFY_TRAFFIC(RING_TX, table_packets->n_miss_packets, 0);
- - - + -
- + ]
197 : : }
198 : :
199 : : /* Flow test - Half hits, half misses */
200 [ + - + - ]: 9 : if (table_packets->n_hit_packets && table_packets->n_miss_packets) {
201 [ + + ]: 234 : for (i = 0; i < (table_packets->n_hit_packets) / 2; i++)
202 [ + - - + : 450 : RING_ENQUEUE(RING_RX, table_packets->hit_packet[i]);
- - - ]
203 : :
204 [ + + ]: 234 : for (i = 0; i < (table_packets->n_miss_packets) / 2; i++)
205 [ + - - + : 450 : RING_ENQUEUE(RING_RX, table_packets->miss_packet[i]);
- - - ]
206 : :
207 : 9 : RUN_PIPELINE(pipeline);
208 [ - + - - : 243 : VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets,
- - + + -
- + ]
209 : : table_packets->n_hit_packets / 2);
210 : : }
211 : :
212 : : /* Flow test - Single packet */
213 [ + - ]: 9 : if (table_packets->n_hit_packets) {
214 [ + - - + : 9 : RING_ENQUEUE(RING_RX, table_packets->hit_packet[0]);
- - - ]
215 : 9 : RUN_PIPELINE(pipeline);
216 [ - + - - : 27 : VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets, 1);
- - + + -
- + ]
217 : : }
218 [ + - ]: 9 : if (table_packets->n_miss_packets) {
219 [ + - - + : 9 : RING_ENQUEUE(RING_RX, table_packets->miss_packet[0]);
- - - ]
220 : 9 : RUN_PIPELINE(pipeline);
221 [ - + - - : 18 : VERIFY_TRAFFIC(RING_TX, table_packets->n_miss_packets, 0);
- - - + -
- + ]
222 : : }
223 : :
224 : :
225 : : /* Change table entry action */
226 : : printf("Change entry action\n");
227 : 9 : table_entry.table_id = ring_out_2_id;
228 : :
229 [ - + ]: 9 : if (rte_pipeline_table_default_entry_add(pipeline, table_id,
230 : : &default_entry, &default_entry_ptr) != 0) {
231 : 0 : rte_pipeline_free(pipeline);
232 : 0 : return -CHECK_TABLE_ENTRY_ADD;
233 : : }
234 : :
235 [ - + ]: 9 : if (rte_pipeline_table_entry_add(pipeline, table_id,
236 : : key ? key : &table_entry, &table_entry, &key_found,
237 : : &entry_ptr) != 0) {
238 : 0 : rte_pipeline_free(pipeline);
239 : 0 : return -CHECK_TABLE_ENTRY_ADD;
240 : : }
241 : :
242 : : /* Check that traffic destination has changed */
243 [ + - ]: 9 : if (table_packets->n_hit_packets) {
244 [ + + ]: 459 : for (i = 0; i < table_packets->n_hit_packets; i++)
245 [ + - - + : 900 : RING_ENQUEUE(RING_RX, table_packets->hit_packet[i]);
- - - ]
246 : :
247 : 9 : RUN_PIPELINE(pipeline);
248 [ - + - - : 18 : VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets, 0);
- - - + -
- + ]
249 [ - + - - : 459 : VERIFY_TRAFFIC(RING_TX_2, table_packets->n_hit_packets,
- - + + +
- + ]
250 : : table_packets->n_hit_packets);
251 : : }
252 : :
253 : : printf("delete entry\n");
254 : : /* Delete table entry */
255 : 9 : rte_pipeline_table_entry_delete(pipeline, table_id,
256 : : key ? key : &table_entry, &key_found, NULL);
257 : :
258 : 9 : rte_pipeline_free(pipeline);
259 : :
260 : 9 : return 0;
261 : : }
262 : :
263 : : /* Table tests */
264 : : int
265 : 0 : test_table_stub_combined(void)
266 : : {
267 : : int status, i;
268 : : struct table_packets table_packets;
269 : :
270 : : printf("--------------\n");
271 : : printf("RUNNING TEST - %s\n", __func__);
272 : : printf("--------------\n");
273 [ # # ]: 0 : for (i = 0; i < N_PACKETS; i++)
274 : 0 : table_packets.hit_packet[i] = i;
275 : :
276 : 0 : table_packets.n_hit_packets = N_PACKETS;
277 : 0 : table_packets.n_miss_packets = 0;
278 : :
279 : 0 : status = test_table_type(&rte_table_stub_ops, NULL, NULL,
280 : : &table_packets, NULL, 1);
281 [ # # ]: 0 : VERIFY(status, CHECK_TABLE_OK);
282 : :
283 : : return 0;
284 : : }
285 : :
286 : : int
287 : 1 : test_table_lpm_combined(void)
288 : : {
289 : : int status, i;
290 : :
291 : : /* Traffic flow */
292 : 1 : struct rte_table_lpm_params lpm_params = {
293 : : .name = "LPM",
294 : : .n_rules = 1 << 16,
295 : : .number_tbl8s = 1 << 8,
296 : : .flags = 0,
297 : : .entry_unique_size = 8,
298 : : .offset = APP_METADATA_OFFSET(0),
299 : : };
300 : :
301 : 1 : struct rte_table_lpm_key lpm_key = {
302 : : .ip = 0xadadadad,
303 : : .depth = 16,
304 : : };
305 : :
306 : : struct table_packets table_packets;
307 : :
308 : : printf("--------------\n");
309 : : printf("RUNNING TEST - %s\n", __func__);
310 : : printf("--------------\n");
311 : :
312 [ + + ]: 51 : for (i = 0; i < N_PACKETS; i++)
313 : 50 : table_packets.hit_packet[i] = 0xadadadad;
314 : :
315 [ + + ]: 51 : for (i = 0; i < N_PACKETS; i++)
316 : 50 : table_packets.miss_packet[i] = 0xfefefefe;
317 : :
318 : 1 : table_packets.n_hit_packets = N_PACKETS;
319 : 1 : table_packets.n_miss_packets = N_PACKETS;
320 : :
321 : 1 : status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
322 : : (void *)&lpm_key, &table_packets, NULL, 0);
323 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_OK);
324 : :
325 : : /* Invalid parameters */
326 : 1 : lpm_params.n_rules = 0;
327 : :
328 : 1 : status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
329 : : (void *)&lpm_key, &table_packets, NULL, 0);
330 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
331 : :
332 : 1 : lpm_params.n_rules = 1 << 24;
333 : 1 : lpm_key.depth = 0;
334 : :
335 : 1 : status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
336 : : (void *)&lpm_key, &table_packets, NULL, 0);
337 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_ENTRY_ADD);
338 : :
339 : 1 : lpm_key.depth = 33;
340 : :
341 : 1 : status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
342 : : (void *)&lpm_key, &table_packets, NULL, 0);
343 [ - + ]: 1 : VERIFY(status, CHECK_TABLE_ENTRY_ADD);
344 : :
345 : : return 0;
346 : : }
347 : :
348 : : int
349 : 1 : test_table_lpm_ipv6_combined(void)
350 : : {
351 : : int status, i;
352 : :
353 : : /* Traffic flow */
354 : 1 : struct rte_table_lpm_ipv6_params lpm_ipv6_params = {
355 : : .name = "LPM",
356 : : .n_rules = 1 << 16,
357 : : .number_tbl8s = 1 << 13,
358 : : .entry_unique_size = 8,
359 : : .offset = APP_METADATA_OFFSET(32),
360 : : };
361 : :
362 : 1 : struct rte_table_lpm_ipv6_key lpm_ipv6_key = {
363 : : .depth = 16,
364 : : };
365 : : memset(&lpm_ipv6_key.ip, 0xad, 16);
366 : :
367 : : struct table_packets table_packets;
368 : :
369 : : printf("--------------\n");
370 : : printf("RUNNING TEST - %s\n", __func__);
371 : : printf("--------------\n");
372 [ + + ]: 51 : for (i = 0; i < N_PACKETS; i++)
373 : 50 : table_packets.hit_packet[i] = 0xadadadad;
374 : :
375 [ + + ]: 51 : for (i = 0; i < N_PACKETS; i++)
376 : 50 : table_packets.miss_packet[i] = 0xadadadab;
377 : :
378 : 1 : table_packets.n_hit_packets = N_PACKETS;
379 : 1 : table_packets.n_miss_packets = N_PACKETS;
380 : :
381 : 1 : status = test_table_type(&rte_table_lpm_ipv6_ops,
382 : : (void *)&lpm_ipv6_params,
383 : : (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
384 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_OK);
385 : :
386 : : /* Invalid parameters */
387 : 1 : lpm_ipv6_params.n_rules = 0;
388 : :
389 : 1 : status = test_table_type(&rte_table_lpm_ipv6_ops,
390 : : (void *)&lpm_ipv6_params,
391 : : (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
392 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
393 : :
394 : 1 : lpm_ipv6_params.n_rules = 1 << 24;
395 : 1 : lpm_ipv6_key.depth = 0;
396 : :
397 : 1 : status = test_table_type(&rte_table_lpm_ipv6_ops,
398 : : (void *)&lpm_ipv6_params,
399 : : (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
400 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_ENTRY_ADD);
401 : :
402 : 1 : lpm_ipv6_key.depth = 129;
403 : 1 : status = test_table_type(&rte_table_lpm_ipv6_ops,
404 : : (void *)&lpm_ipv6_params,
405 : : (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
406 [ - + ]: 1 : VERIFY(status, CHECK_TABLE_ENTRY_ADD);
407 : :
408 : : return 0;
409 : : }
410 : :
411 : : int
412 : 1 : test_table_hash8lru(void)
413 : : {
414 : : int status, i;
415 : :
416 : : /* Traffic flow */
417 : 1 : struct rte_table_hash_params key8lru_params = {
418 : : .name = "TABLE",
419 : : .key_size = 8,
420 : : .key_offset = APP_METADATA_OFFSET(32),
421 : : .key_mask = NULL,
422 : : .n_keys = 1 << 16,
423 : : .n_buckets = 1 << 16,
424 : : .f_hash = pipeline_test_hash,
425 : : .seed = 0,
426 : : };
427 : :
428 : : uint8_t key8lru[8];
429 : : uint32_t *k8lru = (uint32_t *) key8lru;
430 : :
431 : : memset(key8lru, 0, sizeof(key8lru));
432 : 1 : k8lru[0] = 0xadadadad;
433 : :
434 : : struct table_packets table_packets;
435 : :
436 : : printf("--------------\n");
437 : : printf("RUNNING TEST - %s\n", __func__);
438 : : printf("--------------\n");
439 [ + + ]: 51 : for (i = 0; i < 50; i++)
440 : 50 : table_packets.hit_packet[i] = 0xadadadad;
441 : :
442 [ + + ]: 51 : for (i = 0; i < 50; i++)
443 : 50 : table_packets.miss_packet[i] = 0xfefefefe;
444 : :
445 : 1 : table_packets.n_hit_packets = 50;
446 : 1 : table_packets.n_miss_packets = 50;
447 : :
448 : 1 : status = test_table_type(&rte_table_hash_key8_lru_ops,
449 : : (void *)&key8lru_params, (void *)key8lru, &table_packets,
450 : : NULL, 0);
451 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_OK);
452 : :
453 : : /* Invalid parameters */
454 : 1 : key8lru_params.n_keys = 0;
455 : :
456 : 1 : status = test_table_type(&rte_table_hash_key8_lru_ops,
457 : : (void *)&key8lru_params, (void *)key8lru, &table_packets,
458 : : NULL, 0);
459 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
460 : :
461 : 1 : key8lru_params.n_keys = 1<<16;
462 : 1 : key8lru_params.f_hash = NULL;
463 : :
464 : 1 : status = test_table_type(&rte_table_hash_key8_lru_ops,
465 : : (void *)&key8lru_params, (void *)key8lru, &table_packets,
466 : : NULL, 0);
467 [ - + ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
468 : :
469 : : return 0;
470 : : }
471 : :
472 : : int
473 : 1 : test_table_hash16lru(void)
474 : : {
475 : : int status, i;
476 : :
477 : : /* Traffic flow */
478 : 1 : struct rte_table_hash_params key16lru_params = {
479 : : .name = "TABLE",
480 : : .key_size = 16,
481 : : .key_offset = APP_METADATA_OFFSET(32),
482 : : .key_mask = NULL,
483 : : .n_keys = 1 << 16,
484 : : .n_buckets = 1 << 16,
485 : : .f_hash = pipeline_test_hash,
486 : : .seed = 0,
487 : : };
488 : :
489 : : uint8_t key16lru[16];
490 : : uint32_t *k16lru = (uint32_t *) key16lru;
491 : :
492 : : memset(key16lru, 0, sizeof(key16lru));
493 : 1 : k16lru[0] = 0xadadadad;
494 : :
495 : : struct table_packets table_packets;
496 : :
497 : : printf("--------------\n");
498 : : printf("RUNNING TEST - %s\n", __func__);
499 : : printf("--------------\n");
500 [ + + ]: 51 : for (i = 0; i < 50; i++)
501 : 50 : table_packets.hit_packet[i] = 0xadadadad;
502 : :
503 [ + + ]: 51 : for (i = 0; i < 50; i++)
504 : 50 : table_packets.miss_packet[i] = 0xfefefefe;
505 : :
506 : 1 : table_packets.n_hit_packets = 50;
507 : 1 : table_packets.n_miss_packets = 50;
508 : :
509 : 1 : status = test_table_type(&rte_table_hash_key16_lru_ops,
510 : : (void *)&key16lru_params, (void *)key16lru, &table_packets,
511 : : NULL, 0);
512 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_OK);
513 : :
514 : : /* Invalid parameters */
515 : 1 : key16lru_params.n_keys = 0;
516 : :
517 : 1 : status = test_table_type(&rte_table_hash_key16_lru_ops,
518 : : (void *)&key16lru_params, (void *)key16lru, &table_packets,
519 : : NULL, 0);
520 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
521 : :
522 : 1 : key16lru_params.n_keys = 1<<16;
523 : 1 : key16lru_params.f_hash = NULL;
524 : :
525 : 1 : status = test_table_type(&rte_table_hash_key16_lru_ops,
526 : : (void *)&key16lru_params, (void *)key16lru, &table_packets,
527 : : NULL, 0);
528 [ - + ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
529 : :
530 : : return 0;
531 : : }
532 : :
533 : : int
534 : 1 : test_table_hash32lru(void)
535 : : {
536 : : int status, i;
537 : :
538 : : /* Traffic flow */
539 : 1 : struct rte_table_hash_params key32lru_params = {
540 : : .name = "TABLE",
541 : : .key_size = 32,
542 : : .key_offset = APP_METADATA_OFFSET(32),
543 : : .key_mask = NULL,
544 : : .n_keys = 1 << 16,
545 : : .n_buckets = 1 << 16,
546 : : .f_hash = pipeline_test_hash,
547 : : .seed = 0,
548 : : };
549 : :
550 : : uint8_t key32lru[32];
551 : : uint32_t *k32lru = (uint32_t *) key32lru;
552 : :
553 : : memset(key32lru, 0, sizeof(key32lru));
554 : 1 : k32lru[0] = 0xadadadad;
555 : :
556 : : struct table_packets table_packets;
557 : :
558 : : printf("--------------\n");
559 : : printf("RUNNING TEST - %s\n", __func__);
560 : : printf("--------------\n");
561 [ + + ]: 51 : for (i = 0; i < 50; i++)
562 : 50 : table_packets.hit_packet[i] = 0xadadadad;
563 : :
564 [ + + ]: 51 : for (i = 0; i < 50; i++)
565 : 50 : table_packets.miss_packet[i] = 0xbdadadad;
566 : :
567 : 1 : table_packets.n_hit_packets = 50;
568 : 1 : table_packets.n_miss_packets = 50;
569 : :
570 : 1 : status = test_table_type(&rte_table_hash_key32_lru_ops,
571 : : (void *)&key32lru_params, (void *)key32lru, &table_packets,
572 : : NULL, 0);
573 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_OK);
574 : :
575 : : /* Invalid parameters */
576 : 1 : key32lru_params.n_keys = 0;
577 : :
578 : 1 : status = test_table_type(&rte_table_hash_key32_lru_ops,
579 : : (void *)&key32lru_params, (void *)key32lru, &table_packets,
580 : : NULL, 0);
581 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
582 : :
583 : 1 : key32lru_params.n_keys = 1<<16;
584 : 1 : key32lru_params.f_hash = NULL;
585 : :
586 : 1 : status = test_table_type(&rte_table_hash_key32_lru_ops,
587 : : (void *)&key32lru_params, (void *)key32lru, &table_packets,
588 : : NULL, 0);
589 [ - + ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
590 : :
591 : : return 0;
592 : : }
593 : :
594 : : int
595 : 1 : test_table_hash8ext(void)
596 : : {
597 : : int status, i;
598 : :
599 : : /* Traffic flow */
600 : 1 : struct rte_table_hash_params key8ext_params = {
601 : : .name = "TABLE",
602 : : .key_size = 8,
603 : : .key_offset = APP_METADATA_OFFSET(32),
604 : : .key_mask = NULL,
605 : : .n_keys = 1 << 16,
606 : : .n_buckets = 1 << 16,
607 : : .f_hash = pipeline_test_hash,
608 : : .seed = 0,
609 : : };
610 : :
611 : : uint8_t key8ext[8];
612 : : uint32_t *k8ext = (uint32_t *) key8ext;
613 : :
614 : : memset(key8ext, 0, sizeof(key8ext));
615 : 1 : k8ext[0] = 0xadadadad;
616 : :
617 : : struct table_packets table_packets;
618 : :
619 : : printf("--------------\n");
620 : : printf("RUNNING TEST - %s\n", __func__);
621 : : printf("--------------\n");
622 [ + + ]: 51 : for (i = 0; i < 50; i++)
623 : 50 : table_packets.hit_packet[i] = 0xadadadad;
624 : :
625 [ + + ]: 51 : for (i = 0; i < 50; i++)
626 : 50 : table_packets.miss_packet[i] = 0xbdadadad;
627 : :
628 : 1 : table_packets.n_hit_packets = 50;
629 : 1 : table_packets.n_miss_packets = 50;
630 : :
631 : 1 : status = test_table_type(&rte_table_hash_key8_ext_ops,
632 : : (void *)&key8ext_params, (void *)key8ext, &table_packets,
633 : : NULL, 0);
634 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_OK);
635 : :
636 : : /* Invalid parameters */
637 : 1 : key8ext_params.n_keys = 0;
638 : :
639 : 1 : status = test_table_type(&rte_table_hash_key8_ext_ops,
640 : : (void *)&key8ext_params, (void *)key8ext, &table_packets,
641 : : NULL, 0);
642 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
643 : :
644 : 1 : key8ext_params.n_keys = 1<<16;
645 : 1 : key8ext_params.f_hash = NULL;
646 : :
647 : 1 : status = test_table_type(&rte_table_hash_key8_ext_ops,
648 : : (void *)&key8ext_params, (void *)key8ext, &table_packets,
649 : : NULL, 0);
650 [ - + ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
651 : :
652 : : return 0;
653 : : }
654 : :
655 : : int
656 : 1 : test_table_hash16ext(void)
657 : : {
658 : : int status, i;
659 : :
660 : : /* Traffic flow */
661 : 1 : struct rte_table_hash_params key16ext_params = {
662 : : .name = "TABLE",
663 : : .key_size = 16,
664 : : .key_offset = APP_METADATA_OFFSET(32),
665 : : .key_mask = NULL,
666 : : .n_keys = 1 << 16,
667 : : .n_buckets = 1 << 16,
668 : : .f_hash = pipeline_test_hash,
669 : : .seed = 0,
670 : : };
671 : :
672 : : uint8_t key16ext[16];
673 : : uint32_t *k16ext = (uint32_t *) key16ext;
674 : :
675 : : memset(key16ext, 0, sizeof(key16ext));
676 : 1 : k16ext[0] = 0xadadadad;
677 : :
678 : : struct table_packets table_packets;
679 : :
680 : : printf("--------------\n");
681 : : printf("RUNNING TEST - %s\n", __func__);
682 : : printf("--------------\n");
683 [ + + ]: 51 : for (i = 0; i < 50; i++)
684 : 50 : table_packets.hit_packet[i] = 0xadadadad;
685 : :
686 [ + + ]: 51 : for (i = 0; i < 50; i++)
687 : 50 : table_packets.miss_packet[i] = 0xbdadadad;
688 : :
689 : 1 : table_packets.n_hit_packets = 50;
690 : 1 : table_packets.n_miss_packets = 50;
691 : :
692 : 1 : status = test_table_type(&rte_table_hash_key16_ext_ops,
693 : : (void *)&key16ext_params, (void *)key16ext, &table_packets,
694 : : NULL, 0);
695 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_OK);
696 : :
697 : : /* Invalid parameters */
698 : 1 : key16ext_params.n_keys = 0;
699 : :
700 : 1 : status = test_table_type(&rte_table_hash_key16_ext_ops,
701 : : (void *)&key16ext_params, (void *)key16ext, &table_packets,
702 : : NULL, 0);
703 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
704 : :
705 : 1 : key16ext_params.n_keys = 1<<16;
706 : 1 : key16ext_params.f_hash = NULL;
707 : :
708 : 1 : status = test_table_type(&rte_table_hash_key16_ext_ops,
709 : : (void *)&key16ext_params, (void *)key16ext, &table_packets,
710 : : NULL, 0);
711 [ - + ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
712 : :
713 : : return 0;
714 : : }
715 : :
716 : : int
717 : 1 : test_table_hash32ext(void)
718 : : {
719 : : int status, i;
720 : :
721 : : /* Traffic flow */
722 : 1 : struct rte_table_hash_params key32ext_params = {
723 : : .name = "TABLE",
724 : : .key_size = 32,
725 : : .key_offset = APP_METADATA_OFFSET(32),
726 : : .key_mask = NULL,
727 : : .n_keys = 1 << 16,
728 : : .n_buckets = 1 << 16,
729 : : .f_hash = pipeline_test_hash,
730 : : .seed = 0,
731 : : };
732 : :
733 : : uint8_t key32ext[32];
734 : : uint32_t *k32ext = (uint32_t *) key32ext;
735 : :
736 : : memset(key32ext, 0, sizeof(key32ext));
737 : 1 : k32ext[0] = 0xadadadad;
738 : :
739 : : struct table_packets table_packets;
740 : :
741 : : printf("--------------\n");
742 : : printf("RUNNING TEST - %s\n", __func__);
743 : : printf("--------------\n");
744 [ + + ]: 51 : for (i = 0; i < 50; i++)
745 : 50 : table_packets.hit_packet[i] = 0xadadadad;
746 : :
747 [ + + ]: 51 : for (i = 0; i < 50; i++)
748 : 50 : table_packets.miss_packet[i] = 0xbdadadad;
749 : :
750 : 1 : table_packets.n_hit_packets = 50;
751 : 1 : table_packets.n_miss_packets = 50;
752 : :
753 : 1 : status = test_table_type(&rte_table_hash_key32_ext_ops,
754 : : (void *)&key32ext_params, (void *)key32ext, &table_packets,
755 : : NULL, 0);
756 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_OK);
757 : :
758 : : /* Invalid parameters */
759 : 1 : key32ext_params.n_keys = 0;
760 : :
761 : 1 : status = test_table_type(&rte_table_hash_key32_ext_ops,
762 : : (void *)&key32ext_params, (void *)key32ext, &table_packets,
763 : : NULL, 0);
764 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
765 : :
766 : 1 : key32ext_params.n_keys = 1<<16;
767 : 1 : key32ext_params.f_hash = NULL;
768 : :
769 : 1 : status = test_table_type(&rte_table_hash_key32_ext_ops,
770 : : (void *)&key32ext_params, (void *)key32ext, &table_packets,
771 : : NULL, 0);
772 [ - + ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
773 : :
774 : : return 0;
775 : : }
776 : :
777 : : int
778 : 1 : test_table_hash_cuckoo_combined(void)
779 : : {
780 : : int status, i;
781 : :
782 : : /* Traffic flow */
783 : 1 : struct rte_table_hash_cuckoo_params cuckoo_params = {
784 : : .name = "TABLE",
785 : : .key_size = 32,
786 : : .key_offset = APP_METADATA_OFFSET(32),
787 : : .key_mask = NULL,
788 : : .n_keys = 1 << 16,
789 : : .n_buckets = 1 << 16,
790 : : .f_hash = pipeline_test_hash_cuckoo,
791 : : .seed = 0,
792 : : };
793 : :
794 : : uint8_t key_cuckoo[32];
795 : : uint32_t *kcuckoo = (uint32_t *) key_cuckoo;
796 : :
797 : : memset(key_cuckoo, 0, sizeof(key_cuckoo));
798 : 1 : kcuckoo[0] = 0xadadadad;
799 : :
800 : : struct table_packets table_packets;
801 : :
802 : : printf("--------------\n");
803 : : printf("RUNNING TEST - %s\n", __func__);
804 : : printf("--------------\n");
805 [ + + ]: 51 : for (i = 0; i < 50; i++)
806 : 50 : table_packets.hit_packet[i] = 0xadadadad;
807 : :
808 [ + + ]: 51 : for (i = 0; i < 50; i++)
809 : 50 : table_packets.miss_packet[i] = 0xbdadadad;
810 : :
811 : 1 : table_packets.n_hit_packets = 50;
812 : 1 : table_packets.n_miss_packets = 50;
813 : :
814 : 1 : status = test_table_type(&rte_table_hash_cuckoo_ops,
815 : : (void *)&cuckoo_params, (void *)key_cuckoo, &table_packets,
816 : : NULL, 0);
817 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_OK);
818 : :
819 : : /* Invalid parameters */
820 : 1 : cuckoo_params.key_size = 0;
821 : :
822 : 1 : status = test_table_type(&rte_table_hash_cuckoo_ops,
823 : : (void *)&cuckoo_params, (void *)key_cuckoo, &table_packets,
824 : : NULL, 0);
825 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
826 : :
827 : 1 : cuckoo_params.key_size = 32;
828 : 1 : cuckoo_params.n_keys = 0;
829 : :
830 : 1 : status = test_table_type(&rte_table_hash_cuckoo_ops,
831 : : (void *)&cuckoo_params, (void *)key_cuckoo, &table_packets,
832 : : NULL, 0);
833 [ + - ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
834 : :
835 : 1 : cuckoo_params.n_keys = 1<<16;
836 : 1 : cuckoo_params.f_hash = NULL;
837 : :
838 : 1 : status = test_table_type(&rte_table_hash_cuckoo_ops,
839 : : (void *)&cuckoo_params, (void *)key_cuckoo, &table_packets,
840 : : NULL, 0);
841 [ - + ]: 1 : VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
842 : :
843 : : return 0;
844 : : }
845 : :
846 : : #endif /* !RTE_EXEC_ENV_WINDOWS */
|