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