4 * Copyright (c) 2023 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 #ifndef __included_hs_test_t__
18 #define __included_hs_test_t__
20 #include <vnet/session/application_interface.h>
21 #include <vnet/session/session.h>
23 #define HS_TEST_CFG_CTRL_MAGIC 0xfeedface
24 #define HS_TEST_CFG_TXBUF_SIZE_DEF 8192
25 #define HS_TEST_CFG_RXBUF_SIZE_DEF (64 * HS_TEST_CFG_TXBUF_SIZE_DEF)
26 #define HS_TEST_CFG_NUM_WRITES_DEF 1000000
28 #define VCL_TEST_TOKEN_HELP "#H"
29 #define VCL_TEST_TOKEN_EXIT "#X"
30 #define VCL_TEST_TOKEN_VERBOSE "#V"
31 #define VCL_TEST_TOKEN_TXBUF_SIZE "#T:"
32 #define VCL_TEST_TOKEN_NUM_TEST_SESS "#I:"
33 #define VCL_TEST_TOKEN_NUM_WRITES "#N:"
34 #define VCL_TEST_TOKEN_RXBUF_SIZE "#R:"
35 #define VCL_TEST_TOKEN_SHOW_CFG "#C"
36 #define HS_TEST_TOKEN_RUN_UNI "#U"
37 #define HS_TEST_TOKEN_RUN_BI "#B"
39 #define HS_TEST_SEPARATOR_STRING " -----------------------------\n"
41 #define HS_CTRL_HANDLE (~0)
57 HS_TEST_TYPE_EXIT_CLIENT,
60 typedef struct __attribute__ ((packed))
67 uint32_t num_test_sessions;
68 uint32_t num_test_sessions_perq;
69 uint32_t num_test_qsessions;
72 uint32_t transport_udp;
81 hs_test_type_str (hs_test_t t)
85 case HS_TEST_TYPE_NONE:
88 case HS_TEST_TYPE_ECHO:
91 case HS_TEST_TYPE_UNI:
97 case HS_TEST_TYPE_EXIT:
106 hs_test_cfg_verify (hs_test_cfg_t *cfg, hs_test_cfg_t *valid_cfg)
108 /* Note: txbuf & rxbuf on server are the same buffer,
109 * so txbuf_size is not included in this check.
111 return ((cfg->magic == valid_cfg->magic) && (cfg->test == valid_cfg->test) &&
112 (cfg->verbose == valid_cfg->verbose) &&
113 (cfg->rxbuf_size == valid_cfg->rxbuf_size) &&
114 (cfg->num_writes == valid_cfg->num_writes) &&
115 (cfg->total_bytes == valid_cfg->total_bytes));
119 hs_test_cfg_init (hs_test_cfg_t *cfg)
121 cfg->magic = HS_TEST_CFG_CTRL_MAGIC;
122 cfg->test = HS_TEST_TYPE_UNI;
123 cfg->ctrl_handle = ~0;
124 cfg->num_test_sessions = 1;
125 cfg->num_test_sessions_perq = 1;
127 cfg->rxbuf_size = HS_TEST_CFG_RXBUF_SIZE_DEF;
128 cfg->num_writes = HS_TEST_CFG_NUM_WRITES_DEF;
129 cfg->txbuf_size = HS_TEST_CFG_TXBUF_SIZE_DEF;
130 cfg->total_bytes = cfg->num_writes * cfg->txbuf_size;
135 hs_test_cmd_to_str (int cmd)
139 case HS_TEST_CMD_SYNC:
141 case HS_TEST_CMD_START:
143 case HS_TEST_CMD_STOP:
150 hs_test_cfg_dump (hs_test_cfg_t *cfg, uint8_t is_client)
154 printf (" test config (%p):\n" HS_TEST_SEPARATOR_STRING
159 "%-5s test: %s (%d)\n"
160 " ctrl handle: %d (0x%x)\n"
161 "%-5s num test sockets: %u (0x%08x)\n"
162 "%-5s verbose: %s (%d)\n"
163 "%-5s rxbuf size: %lu (0x%08lx)\n"
164 "%-5s txbuf size: %lu (0x%08lx)\n"
165 "%-5s num writes: %lu (0x%08lx)\n"
166 " client tx bytes: %lu (0x%08lx)\n" HS_TEST_SEPARATOR_STRING,
167 (void *) cfg, hs_test_cmd_to_str (cfg->cmd), cfg->magic,
168 cfg->seq_num, cfg->test_bytes ? "yes" : "no",
169 is_client && (cfg->test == HS_TEST_TYPE_UNI) ?
170 "'" HS_TEST_TOKEN_RUN_UNI "'" :
171 is_client && (cfg->test == HS_TEST_TYPE_BI) ?
172 "'" HS_TEST_TOKEN_RUN_BI "'" :
174 hs_test_type_str (cfg->test), cfg->test, cfg->ctrl_handle,
176 is_client ? "'" VCL_TEST_TOKEN_NUM_TEST_SESS "'" : spc,
177 cfg->num_test_sessions, cfg->num_test_sessions,
178 is_client ? "'" VCL_TEST_TOKEN_VERBOSE "'" : spc,
179 cfg->verbose ? "on" : "off", cfg->verbose,
180 is_client ? "'" VCL_TEST_TOKEN_RXBUF_SIZE "'" : spc, cfg->rxbuf_size,
181 cfg->rxbuf_size, is_client ? "'" VCL_TEST_TOKEN_TXBUF_SIZE "'" : spc,
182 cfg->txbuf_size, cfg->txbuf_size,
183 is_client ? "'" VCL_TEST_TOKEN_NUM_WRITES "'" : spc, cfg->num_writes,
184 cfg->num_writes, cfg->total_bytes, cfg->total_bytes);
188 hs_make_data_port (u16 p)
190 p = clib_net_to_host_u16 (p);
191 return clib_host_to_net_u16 (p + 1);
195 hs_test_app_session_init_ (app_session_t *as, session_t *s)
197 as->rx_fifo = s->rx_fifo;
198 as->tx_fifo = s->tx_fifo;
199 as->vpp_evt_q = session_main_get_vpp_event_queue (s->thread_index);
200 if (session_get_transport_proto (s) == TRANSPORT_PROTO_UDP)
202 transport_connection_t *tc;
203 tc = session_get_transport (s);
204 clib_memcpy_fast (&as->transport, tc, sizeof (as->transport));
209 #define hs_test_app_session_init(_as, _s) \
210 hs_test_app_session_init_ ((app_session_t *) (_as), (_s))
212 #endif /* __included_hs_test_t__ */