1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2a9de470cSBruce Richardson * Copyright(c) 2010-2014 Intel Corporation 3a9de470cSBruce Richardson */ 4a9de470cSBruce Richardson 5a9de470cSBruce Richardson #include <rte_table_stub.h> 6a9de470cSBruce Richardson #include <rte_table_lpm.h> 7a9de470cSBruce Richardson #include <rte_table_lpm_ipv6.h> 8a9de470cSBruce Richardson #include <rte_table_hash.h> 9a9de470cSBruce Richardson #include <rte_table_hash_cuckoo.h> 10a9de470cSBruce Richardson #include <rte_table_array.h> 11a9de470cSBruce Richardson #include <rte_pipeline.h> 12a9de470cSBruce Richardson 13*a8d0d473SBruce Richardson #ifdef RTE_LIB_ACL 14a9de470cSBruce Richardson #include <rte_table_acl.h> 15a9de470cSBruce Richardson #endif 16a9de470cSBruce Richardson 17a9de470cSBruce Richardson #include <rte_port_ring.h> 18a9de470cSBruce Richardson #include <rte_port_ethdev.h> 19a9de470cSBruce Richardson #include <rte_port_source_sink.h> 20a9de470cSBruce Richardson 21a9de470cSBruce Richardson #ifndef TEST_TABLE_H_ 22a9de470cSBruce Richardson #define TEST_TABLE_H_ 23a9de470cSBruce Richardson 24a9de470cSBruce Richardson #define RING_SIZE 4096 25a9de470cSBruce Richardson #define MAX_BULK 32 26a9de470cSBruce Richardson #define N 65536 27a9de470cSBruce Richardson #define TIME_S 5 28a9de470cSBruce Richardson #define TEST_RING_FULL_EMTPY_ITER 8 29a9de470cSBruce Richardson #define N_PORTS 2 30a9de470cSBruce Richardson #define N_PKTS 2 31a9de470cSBruce Richardson #define N_PKTS_EXT 6 32a9de470cSBruce Richardson #define RING_RX rings_rx[0] 33a9de470cSBruce Richardson #define RING_RX_2 rings_rx[1] 34a9de470cSBruce Richardson #define RING_TX rings_tx[0] 35a9de470cSBruce Richardson #define RING_TX_2 rings_tx[1] 36a9de470cSBruce Richardson #define PORT_RX_RING_SIZE 128 37a9de470cSBruce Richardson #define PORT_TX_RING_SIZE 512 38a9de470cSBruce Richardson #define RING_RX_SIZE 128 39a9de470cSBruce Richardson #define RING_TX_SIZE 128 40a9de470cSBruce Richardson #define POOL_BUFFER_SIZE RTE_MBUF_DEFAULT_BUF_SIZE 41a9de470cSBruce Richardson #define POOL_SIZE (32 * 1024) 42a9de470cSBruce Richardson #define POOL_CACHE_SIZE 256 43a9de470cSBruce Richardson #define BURST_SIZE 8 44a9de470cSBruce Richardson #define WORKER_TYPE 1 45a9de470cSBruce Richardson #define MAX_DUMMY_PORTS 2 46a9de470cSBruce Richardson #define MP_NAME "dummy_port_mempool" 47a9de470cSBruce Richardson #define MBUF_COUNT (8000 * MAX_DUMMY_PORTS) 48a9de470cSBruce Richardson #define MP_CACHE_SZ 256 49a9de470cSBruce Richardson #define MP_SOCKET 0 50a9de470cSBruce Richardson #define MP_FLAGS 0 51a9de470cSBruce Richardson 52a9de470cSBruce Richardson /* Macros */ 53a9de470cSBruce Richardson #define APP_METADATA_OFFSET(offset) (sizeof(struct rte_mbuf) + (offset)) 54a9de470cSBruce Richardson 55a9de470cSBruce Richardson #define RING_ENQUEUE(ring, value) do { \ 56a9de470cSBruce Richardson struct rte_mbuf *m; \ 57a9de470cSBruce Richardson uint32_t *k32, *signature; \ 58a9de470cSBruce Richardson uint8_t *key; \ 59a9de470cSBruce Richardson \ 60a9de470cSBruce Richardson m = rte_pktmbuf_alloc(pool); \ 61a9de470cSBruce Richardson if (m == NULL) \ 62a9de470cSBruce Richardson return -1; \ 63a9de470cSBruce Richardson signature = RTE_MBUF_METADATA_UINT32_PTR(m, \ 64a9de470cSBruce Richardson APP_METADATA_OFFSET(0)); \ 65a9de470cSBruce Richardson key = RTE_MBUF_METADATA_UINT8_PTR(m, \ 66a9de470cSBruce Richardson APP_METADATA_OFFSET(32)); \ 67a9de470cSBruce Richardson k32 = (uint32_t *) key; \ 68a9de470cSBruce Richardson k32[0] = (value); \ 69a9de470cSBruce Richardson *signature = pipeline_test_hash(key, NULL, 0, 0); \ 70a9de470cSBruce Richardson rte_ring_enqueue((ring), m); \ 71a9de470cSBruce Richardson } while (0) 72a9de470cSBruce Richardson 73a9de470cSBruce Richardson #define RUN_PIPELINE(pipeline) do { \ 74a9de470cSBruce Richardson rte_pipeline_run((pipeline)); \ 75a9de470cSBruce Richardson rte_pipeline_flush((pipeline)); \ 76a9de470cSBruce Richardson } while (0) 77a9de470cSBruce Richardson 78a9de470cSBruce Richardson #define VERIFY(var, value) do { \ 79a9de470cSBruce Richardson if ((var) != -(value)) \ 80a9de470cSBruce Richardson return var; \ 81a9de470cSBruce Richardson } while (0) 82a9de470cSBruce Richardson 83a9de470cSBruce Richardson #define VERIFY_TRAFFIC(ring, sent, expected) do { \ 84a9de470cSBruce Richardson unsigned i, n = 0; \ 85a9de470cSBruce Richardson void *mbuf = NULL; \ 86a9de470cSBruce Richardson \ 87a9de470cSBruce Richardson for (i = 0; i < (sent); i++) { \ 88a9de470cSBruce Richardson if (!rte_ring_dequeue((ring), &mbuf)) { \ 89a9de470cSBruce Richardson if (mbuf == NULL) \ 90a9de470cSBruce Richardson continue; \ 91a9de470cSBruce Richardson n++; \ 92a9de470cSBruce Richardson rte_pktmbuf_free((struct rte_mbuf *)mbuf); \ 93a9de470cSBruce Richardson } \ 94a9de470cSBruce Richardson else \ 95a9de470cSBruce Richardson break; \ 96a9de470cSBruce Richardson } \ 97a9de470cSBruce Richardson printf("Expected %d, got %d\n", expected, n); \ 98a9de470cSBruce Richardson if (n != (expected)) { \ 99a9de470cSBruce Richardson return -21; \ 100a9de470cSBruce Richardson } \ 101a9de470cSBruce Richardson } while (0) 102a9de470cSBruce Richardson 103a9de470cSBruce Richardson /* Function definitions */ 104a9de470cSBruce Richardson uint64_t pipeline_test_hash( 105a9de470cSBruce Richardson void *key, 106f2fc83b4SThomas Monjalon __rte_unused void *key_mask, 107f2fc83b4SThomas Monjalon __rte_unused uint32_t key_size, 108f2fc83b4SThomas Monjalon __rte_unused uint64_t seed); 109a9de470cSBruce Richardson 110a9de470cSBruce Richardson uint32_t pipeline_test_hash_cuckoo( 111a9de470cSBruce Richardson const void *key, 112f2fc83b4SThomas Monjalon __rte_unused uint32_t key_size, 113f2fc83b4SThomas Monjalon __rte_unused uint32_t seed); 114a9de470cSBruce Richardson 115a9de470cSBruce Richardson /* Extern variables */ 116a9de470cSBruce Richardson extern struct rte_pipeline *p; 117a9de470cSBruce Richardson extern struct rte_ring *rings_rx[N_PORTS]; 118a9de470cSBruce Richardson extern struct rte_ring *rings_tx[N_PORTS]; 119a9de470cSBruce Richardson extern struct rte_mempool *pool; 120a9de470cSBruce Richardson extern uint32_t port_in_id[N_PORTS]; 121a9de470cSBruce Richardson extern uint32_t port_out_id[N_PORTS]; 122a9de470cSBruce Richardson extern uint32_t port_out_id_type[3]; 123a9de470cSBruce Richardson extern uint32_t table_id[N_PORTS*2]; 124a9de470cSBruce Richardson extern uint64_t override_hit_mask; 125a9de470cSBruce Richardson extern uint64_t override_miss_mask; 126a9de470cSBruce Richardson extern uint64_t non_reserved_actions_hit; 127a9de470cSBruce Richardson extern uint64_t non_reserved_actions_miss; 128a9de470cSBruce Richardson extern uint8_t connect_miss_action_to_port_out; 129a9de470cSBruce Richardson extern uint8_t connect_miss_action_to_table; 130a9de470cSBruce Richardson extern uint32_t table_entry_default_action; 131a9de470cSBruce Richardson extern uint32_t table_entry_hit_action; 132a9de470cSBruce Richardson extern uint32_t table_entry_miss_action; 133a9de470cSBruce Richardson extern rte_pipeline_port_in_action_handler port_in_action; 134a9de470cSBruce Richardson extern rte_pipeline_port_out_action_handler port_out_action; 135a9de470cSBruce Richardson extern rte_pipeline_table_action_handler_hit action_handler_hit; 136a9de470cSBruce Richardson extern rte_pipeline_table_action_handler_miss action_handler_miss; 137a9de470cSBruce Richardson 138a9de470cSBruce Richardson /* Global data types */ 139a9de470cSBruce Richardson struct manage_ops { 140a9de470cSBruce Richardson uint32_t op_id; 141a9de470cSBruce Richardson void *op_data; 142a9de470cSBruce Richardson int expected_result; 143a9de470cSBruce Richardson }; 144a9de470cSBruce Richardson 145a9de470cSBruce Richardson /* Internal pipeline structures */ 146a9de470cSBruce Richardson struct rte_port_in { 147a9de470cSBruce Richardson struct rte_port_in_ops ops; 148a9de470cSBruce Richardson uint32_t burst_size; 149a9de470cSBruce Richardson uint32_t table_id; 150a9de470cSBruce Richardson void *h_port; 151a9de470cSBruce Richardson }; 152a9de470cSBruce Richardson 153a9de470cSBruce Richardson struct rte_port_out { 154a9de470cSBruce Richardson struct rte_port_out_ops ops; 155a9de470cSBruce Richardson void *h_port; 156a9de470cSBruce Richardson }; 157a9de470cSBruce Richardson 158a9de470cSBruce Richardson struct rte_table { 159a9de470cSBruce Richardson struct rte_table_ops ops; 160a9de470cSBruce Richardson rte_pipeline_table_action_handler_hit f_action; 161a9de470cSBruce Richardson uint32_t table_next_id; 162a9de470cSBruce Richardson uint32_t table_next_id_valid; 163a9de470cSBruce Richardson uint8_t actions_lookup_miss[RTE_CACHE_LINE_SIZE]; 164a9de470cSBruce Richardson uint32_t action_data_size; 165a9de470cSBruce Richardson void *h_table; 166a9de470cSBruce Richardson }; 167a9de470cSBruce Richardson 168a9de470cSBruce Richardson #define RTE_PIPELINE_MAX_NAME_SZ 124 169a9de470cSBruce Richardson 170a9de470cSBruce Richardson struct rte_pipeline { 171a9de470cSBruce Richardson char name[RTE_PIPELINE_MAX_NAME_SZ]; 172a9de470cSBruce Richardson uint32_t socket_id; 173a9de470cSBruce Richardson struct rte_port_in ports_in[16]; 174a9de470cSBruce Richardson struct rte_port_out ports_out[16]; 175a9de470cSBruce Richardson struct rte_table tables[64]; 176a9de470cSBruce Richardson uint32_t num_ports_in; 177a9de470cSBruce Richardson uint32_t num_ports_out; 178a9de470cSBruce Richardson uint32_t num_tables; 179a9de470cSBruce Richardson struct rte_mbuf *pkts[RTE_PORT_IN_BURST_SIZE_MAX]; 180a9de470cSBruce Richardson struct rte_table_entry *actions[RTE_PORT_IN_BURST_SIZE_MAX]; 181a9de470cSBruce Richardson uint64_t mask_action[64]; 182a9de470cSBruce Richardson uint32_t mask_actions; 183a9de470cSBruce Richardson }; 184a9de470cSBruce Richardson #endif 185