71f417824d5a0ea0f12dac2ca8ecc9bd0e73e2e6
[vpp.git] / src / plugins / hs_apps / hs_test.h
1 /*
2  * hs_test.h
3  *
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:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 #ifndef __included_hs_test_t__
18 #define __included_hs_test_t__
19
20 #include <vnet/session/application_interface.h>
21
22 #define HS_TEST_CFG_CTRL_MAGIC     0xfeedface
23 #define HS_TEST_CFG_TXBUF_SIZE_DEF 8192
24 #define HS_TEST_CFG_RXBUF_SIZE_DEF (64 * HS_TEST_CFG_TXBUF_SIZE_DEF)
25 #define HS_TEST_CFG_NUM_WRITES_DEF 1000000
26
27 #define VCL_TEST_TOKEN_HELP          "#H"
28 #define VCL_TEST_TOKEN_EXIT          "#X"
29 #define VCL_TEST_TOKEN_VERBOSE       "#V"
30 #define VCL_TEST_TOKEN_TXBUF_SIZE    "#T:"
31 #define VCL_TEST_TOKEN_NUM_TEST_SESS "#I:"
32 #define VCL_TEST_TOKEN_NUM_WRITES    "#N:"
33 #define VCL_TEST_TOKEN_RXBUF_SIZE    "#R:"
34 #define VCL_TEST_TOKEN_SHOW_CFG      "#C"
35 #define HS_TEST_TOKEN_RUN_UNI        "#U"
36 #define HS_TEST_TOKEN_RUN_BI         "#B"
37
38 #define HS_TEST_SEPARATOR_STRING "  -----------------------------\n"
39
40 #define HS_CTRL_HANDLE (~0)
41
42 typedef enum
43 {
44   HS_TEST_CMD_SYNC,
45   HS_TEST_CMD_START,
46   HS_TEST_CMD_STOP,
47 } hs_test_cmd_t;
48
49 typedef enum
50 {
51   HS_TEST_TYPE_NONE,
52   HS_TEST_TYPE_ECHO,
53   HS_TEST_TYPE_UNI,
54   HS_TEST_TYPE_BI,
55   HS_TEST_TYPE_EXIT,
56   HS_TEST_TYPE_EXIT_CLIENT,
57 } hs_test_t;
58
59 typedef struct __attribute__ ((packed))
60 {
61   uint32_t magic;
62   uint32_t seq_num;
63   uint32_t test;
64   uint32_t cmd;
65   uint32_t ctrl_handle;
66   uint32_t num_test_sessions;
67   uint32_t num_test_sessions_perq;
68   uint32_t num_test_qsessions;
69   uint32_t verbose;
70   uint32_t address_ip6;
71   uint32_t transport_udp;
72   uint64_t rxbuf_size;
73   uint64_t txbuf_size;
74   uint64_t num_writes;
75   uint64_t total_bytes;
76   uint32_t test_bytes;
77 } hs_test_cfg_t;
78
79 static inline char *
80 hs_test_type_str (hs_test_t t)
81 {
82   switch (t)
83     {
84     case HS_TEST_TYPE_NONE:
85       return "NONE";
86
87     case HS_TEST_TYPE_ECHO:
88       return "ECHO";
89
90     case HS_TEST_TYPE_UNI:
91       return "UNI";
92
93     case HS_TEST_TYPE_BI:
94       return "BI";
95
96     case HS_TEST_TYPE_EXIT:
97       return "EXIT";
98
99     default:
100       return "Unknown";
101     }
102 }
103
104 static inline int
105 hs_test_cfg_verify (hs_test_cfg_t *cfg, hs_test_cfg_t *valid_cfg)
106 {
107   /* Note: txbuf & rxbuf on server are the same buffer,
108    *       so txbuf_size is not included in this check.
109    */
110   return ((cfg->magic == valid_cfg->magic) && (cfg->test == valid_cfg->test) &&
111           (cfg->verbose == valid_cfg->verbose) &&
112           (cfg->rxbuf_size == valid_cfg->rxbuf_size) &&
113           (cfg->num_writes == valid_cfg->num_writes) &&
114           (cfg->total_bytes == valid_cfg->total_bytes));
115 }
116
117 static inline void
118 hs_test_cfg_init (hs_test_cfg_t *cfg)
119 {
120   cfg->magic = HS_TEST_CFG_CTRL_MAGIC;
121   cfg->test = HS_TEST_TYPE_UNI;
122   cfg->ctrl_handle = ~0;
123   cfg->num_test_sessions = 1;
124   cfg->num_test_sessions_perq = 1;
125   cfg->verbose = 0;
126   cfg->rxbuf_size = HS_TEST_CFG_RXBUF_SIZE_DEF;
127   cfg->num_writes = HS_TEST_CFG_NUM_WRITES_DEF;
128   cfg->txbuf_size = HS_TEST_CFG_TXBUF_SIZE_DEF;
129   cfg->total_bytes = cfg->num_writes * cfg->txbuf_size;
130   cfg->test_bytes = 0;
131 }
132
133 static inline char *
134 hs_test_cmd_to_str (int cmd)
135 {
136   switch (cmd)
137     {
138     case HS_TEST_CMD_SYNC:
139       return "SYNC";
140     case HS_TEST_CMD_START:
141       return "START";
142     case HS_TEST_CMD_STOP:
143       return "STOP";
144     }
145   return "";
146 }
147
148 static inline void
149 hs_test_cfg_dump (hs_test_cfg_t *cfg, uint8_t is_client)
150 {
151   char *spc = "     ";
152
153   printf ("  test config (%p):\n" HS_TEST_SEPARATOR_STRING
154           "               command: %s\n"
155           "                 magic:  0x%08x\n"
156           "               seq_num:  0x%08x\n"
157           "            test bytes:  %s\n"
158           "%-5s             test:  %s (%d)\n"
159           "           ctrl handle:  %d (0x%x)\n"
160           "%-5s num test sockets:  %u (0x%08x)\n"
161           "%-5s          verbose:  %s (%d)\n"
162           "%-5s       rxbuf size:  %lu (0x%08lx)\n"
163           "%-5s       txbuf size:  %lu (0x%08lx)\n"
164           "%-5s       num writes:  %lu (0x%08lx)\n"
165           "       client tx bytes:  %lu (0x%08lx)\n" HS_TEST_SEPARATOR_STRING,
166           (void *) cfg, hs_test_cmd_to_str (cfg->cmd), cfg->magic,
167           cfg->seq_num, cfg->test_bytes ? "yes" : "no",
168           is_client && (cfg->test == HS_TEST_TYPE_UNI) ?
169                   "'" HS_TEST_TOKEN_RUN_UNI "'" :
170           is_client && (cfg->test == HS_TEST_TYPE_BI) ?
171                   "'" HS_TEST_TOKEN_RUN_BI "'" :
172                   spc,
173           hs_test_type_str (cfg->test), cfg->test, cfg->ctrl_handle,
174           cfg->ctrl_handle,
175           is_client ? "'" VCL_TEST_TOKEN_NUM_TEST_SESS "'" : spc,
176           cfg->num_test_sessions, cfg->num_test_sessions,
177           is_client ? "'" VCL_TEST_TOKEN_VERBOSE "'" : spc,
178           cfg->verbose ? "on" : "off", cfg->verbose,
179           is_client ? "'" VCL_TEST_TOKEN_RXBUF_SIZE "'" : spc, cfg->rxbuf_size,
180           cfg->rxbuf_size, is_client ? "'" VCL_TEST_TOKEN_TXBUF_SIZE "'" : spc,
181           cfg->txbuf_size, cfg->txbuf_size,
182           is_client ? "'" VCL_TEST_TOKEN_NUM_WRITES "'" : spc, cfg->num_writes,
183           cfg->num_writes, cfg->total_bytes, cfg->total_bytes);
184 }
185
186 static inline u16
187 hs_make_data_port (u16 p)
188 {
189   p = clib_net_to_host_u16 (p);
190   return clib_host_to_net_u16 (p + 1);
191 }
192
193 #endif /* __included_hs_test_t__ */