blob: a28feee674ff32cc6955ad2a5cafe0d64a9afc90 [file] [log] [blame]
Dave Wallace543852a2017-08-03 02:11:34 -04001/*
Florin Coras5e062572019-03-14 19:07:51 -07002 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
Dave Wallace543852a2017-08-03 02:11:34 -04003 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <unistd.h>
17#include <errno.h>
18#include <stdlib.h>
19#include <ctype.h>
20#include <sys/types.h>
21#include <sys/socket.h>
22#include <stdio.h>
23#include <time.h>
24#include <arpa/inet.h>
Dave Wallace5c7cf1c2017-10-24 04:12:18 -040025#include <vcl/sock_test.h>
Florin Corasdc2e2512018-12-03 17:47:26 -080026#include <fcntl.h>
Dave Wallace3ee1fe12018-02-23 01:09:11 -050027#ifndef VCL_TEST
28#include <sys/un.h>
29#endif
Dave Wallace543852a2017-08-03 02:11:34 -040030
31typedef struct
32{
33#ifdef VCL_TEST
34 vppcom_endpt_t server_endpt;
Dave Wallace3ee1fe12018-02-23 01:09:11 -050035#else
36 int af_unix_echo_tx;
37 int af_unix_echo_rx;
Dave Wallace543852a2017-08-03 02:11:34 -040038#endif
Dave Wallacede910062018-03-20 09:22:13 -040039 struct sockaddr_storage server_addr;
40 uint32_t server_addr_size;
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070041 uint32_t cfg_seq_num;
Florin Coras1502fc32018-10-05 00:50:30 -070042 vcl_test_session_t ctrl_socket;
43 vcl_test_session_t *test_socket;
Dave Wallace543852a2017-08-03 02:11:34 -040044 uint32_t num_test_sockets;
45 uint8_t dump_cfg;
46} sock_client_main_t;
47
Florin Coras6d4bb422018-09-04 22:07:27 -070048sock_client_main_t vcl_client_main;
Dave Wallace543852a2017-08-03 02:11:34 -040049
50
51static int
Florin Coras1502fc32018-10-05 00:50:30 -070052sock_test_cfg_sync (vcl_test_session_t * socket)
Dave Wallace543852a2017-08-03 02:11:34 -040053{
Florin Coras6d4bb422018-09-04 22:07:27 -070054 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -070055 vcl_test_session_t *ctrl = &scm->ctrl_socket;
56 vcl_test_cfg_t *rl_cfg = (vcl_test_cfg_t *) socket->rxbuf;
Dave Wallace543852a2017-08-03 02:11:34 -040057 int rx_bytes, tx_bytes;
58
59 if (socket->cfg.verbose)
Florin Coras1502fc32018-10-05 00:50:30 -070060 vcl_test_cfg_dump (&socket->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -040061
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070062 ctrl->cfg.seq_num = ++scm->cfg_seq_num;
63 if (socket->cfg.verbose)
64 {
65 printf ("CLIENT (fd %d): Sending config sent to server.\n", socket->fd);
Florin Coras1502fc32018-10-05 00:50:30 -070066 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070067 }
Dave Wallace543852a2017-08-03 02:11:34 -040068 tx_bytes = sock_test_write (socket->fd, (uint8_t *) & ctrl->cfg,
69 sizeof (ctrl->cfg), NULL, ctrl->cfg.verbose);
70 if (tx_bytes < 0)
71 {
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070072 fprintf (stderr, "CLIENT (fd %d): ERROR: write test cfg failed (%d)!\n",
73 socket->fd, tx_bytes);
Dave Wallace543852a2017-08-03 02:11:34 -040074 return tx_bytes;
75 }
76
77 rx_bytes = sock_test_read (socket->fd, (uint8_t *) socket->rxbuf,
Florin Coras1502fc32018-10-05 00:50:30 -070078 sizeof (vcl_test_cfg_t), NULL);
Dave Wallace543852a2017-08-03 02:11:34 -040079 if (rx_bytes < 0)
80 return rx_bytes;
81
Florin Coras1502fc32018-10-05 00:50:30 -070082 if (rl_cfg->magic != VCL_TEST_CFG_CTRL_MAGIC)
Dave Wallace543852a2017-08-03 02:11:34 -040083 {
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070084 fprintf (stderr, "CLIENT (fd %d): ERROR: Bad server reply cfg "
85 "-- aborting!\n", socket->fd);
Dave Wallace543852a2017-08-03 02:11:34 -040086 return -1;
87 }
Florin Coras1502fc32018-10-05 00:50:30 -070088 if ((rx_bytes != sizeof (vcl_test_cfg_t))
89 || !vcl_test_cfg_verify (rl_cfg, &ctrl->cfg))
Dave Wallace543852a2017-08-03 02:11:34 -040090 {
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070091 fprintf (stderr, "CLIENT (fd %d): ERROR: Invalid config received "
92 "from server!\n", socket->fd);
Florin Coras1502fc32018-10-05 00:50:30 -070093 if (rx_bytes != sizeof (vcl_test_cfg_t))
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070094 {
95 fprintf (stderr, "\tRx bytes %d != cfg size %lu\n",
Florin Coras1502fc32018-10-05 00:50:30 -070096 rx_bytes, sizeof (vcl_test_cfg_t));
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070097 }
98 else
99 {
Florin Coras1502fc32018-10-05 00:50:30 -0700100 vcl_test_cfg_dump (rl_cfg, 1 /* is_client */ );
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -0700101 fprintf (stderr, "CLIENT (fd %d): Valid config sent to server.\n",
102 socket->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700103 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -0700104 }
Dave Wallace543852a2017-08-03 02:11:34 -0400105 return -1;
106 }
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -0700107 else if (socket->cfg.verbose)
108 {
109 printf ("CLIENT (fd %d): Got config back from server.\n", socket->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700110 vcl_test_cfg_dump (rl_cfg, 1 /* is_client */ );
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -0700111 }
Dave Wallace543852a2017-08-03 02:11:34 -0400112 ctrl->cfg.ctrl_handle = ((ctrl->cfg.ctrl_handle == ~0) ?
113 rl_cfg->ctrl_handle : ctrl->cfg.ctrl_handle);
114
115 return 0;
116}
117
118static void
119echo_test_client ()
120{
Florin Coras6d4bb422018-09-04 22:07:27 -0700121 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700122 vcl_test_session_t *ctrl = &scm->ctrl_socket;
123 vcl_test_session_t *tsock;
Dave Wallace543852a2017-08-03 02:11:34 -0400124 int rx_bytes, tx_bytes, nbytes;
125 uint32_t i, n;
126 int rv;
127 int nfds = 0;
128 fd_set wr_fdset, rd_fdset;
129 fd_set _wfdset, *wfdset = &_wfdset;
130 fd_set _rfdset, *rfdset = &_rfdset;
131
132 FD_ZERO (&wr_fdset);
133 FD_ZERO (&rd_fdset);
134 memset (&ctrl->stats, 0, sizeof (ctrl->stats));
135 ctrl->cfg.total_bytes = nbytes = strlen (ctrl->txbuf) + 1;
Florin Coras1502fc32018-10-05 00:50:30 -0700136 for (n = 0; n != ctrl->cfg.num_test_sessions; n++)
Dave Wallace543852a2017-08-03 02:11:34 -0400137 {
138 tsock = &scm->test_socket[n];
139 tsock->cfg = ctrl->cfg;
Florin Coras1502fc32018-10-05 00:50:30 -0700140 vcl_test_session_buf_alloc (tsock);
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -0700141 if (sock_test_cfg_sync (tsock))
142 return;
Dave Wallace543852a2017-08-03 02:11:34 -0400143
144 memcpy (tsock->txbuf, ctrl->txbuf, nbytes);
145 memset (&tsock->stats, 0, sizeof (tsock->stats));
146
147 FD_SET (tsock->fd, &wr_fdset);
148 FD_SET (tsock->fd, &rd_fdset);
149 nfds = ((tsock->fd + 1) > nfds) ? (tsock->fd + 1) : nfds;
150 }
151
152 nfds++;
153 clock_gettime (CLOCK_REALTIME, &ctrl->stats.start);
154 while (n)
155 {
156 _wfdset = wr_fdset;
157 _rfdset = rd_fdset;
158
159#ifdef VCL_TEST
David Johnsond9818dd2018-12-14 14:53:41 -0500160 rv =
161 vppcom_select (nfds, (unsigned long *) rfdset,
162 (unsigned long *) wfdset, NULL, 0);
Dave Wallace543852a2017-08-03 02:11:34 -0400163#else
164 {
165 struct timeval timeout;
166 timeout.tv_sec = 0;
167 timeout.tv_usec = 0;
168 rv = select (nfds, rfdset, wfdset, NULL, &timeout);
169 }
170#endif
171 if (rv < 0)
172 {
173 perror ("select()");
Dave Wallace048b1d62018-01-03 22:24:41 -0500174 fprintf (stderr, "\nCLIENT: ERROR: select() failed -- "
175 "aborting test!\n");
Dave Wallace543852a2017-08-03 02:11:34 -0400176 return;
177 }
178 else if (rv == 0)
179 continue;
180
Florin Coras1502fc32018-10-05 00:50:30 -0700181 for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
Dave Wallace543852a2017-08-03 02:11:34 -0400182 {
183 tsock = &scm->test_socket[i];
184 if (!((tsock->stats.stop.tv_sec == 0) &&
185 (tsock->stats.stop.tv_nsec == 0)))
186 continue;
187
188 if (FD_ISSET (tsock->fd, wfdset) &&
189 (tsock->stats.tx_bytes < ctrl->cfg.total_bytes))
190
191 {
192 tx_bytes =
193 sock_test_write (tsock->fd, (uint8_t *) tsock->txbuf, nbytes,
194 &tsock->stats, ctrl->cfg.verbose);
195 if (tx_bytes < 0)
196 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500197 fprintf (stderr, "\nCLIENT: ERROR: sock_test_write(%d) "
198 "failed -- aborting test!\n", tsock->fd);
Dave Wallace543852a2017-08-03 02:11:34 -0400199 return;
200 }
201
202 printf ("CLIENT (fd %d): TX (%d bytes) - '%s'\n",
203 tsock->fd, tx_bytes, tsock->txbuf);
204 }
205
206 if ((FD_ISSET (tsock->fd, rfdset)) &&
207 (tsock->stats.rx_bytes < ctrl->cfg.total_bytes))
208 {
209 rx_bytes =
210 sock_test_read (tsock->fd, (uint8_t *) tsock->rxbuf,
211 nbytes, &tsock->stats);
212 if (rx_bytes > 0)
213 {
214 printf ("CLIENT (fd %d): RX (%d bytes) - '%s'\n",
215 tsock->fd, rx_bytes, tsock->rxbuf);
216
217 if (tsock->stats.rx_bytes != tsock->stats.tx_bytes)
Dave Wallace048b1d62018-01-03 22:24:41 -0500218 printf ("CLIENT: WARNING: bytes read (%lu) "
219 "!= bytes written (%lu)!\n",
220 tsock->stats.rx_bytes, tsock->stats.tx_bytes);
Dave Wallace543852a2017-08-03 02:11:34 -0400221 }
222 }
223
224 if (tsock->stats.rx_bytes >= ctrl->cfg.total_bytes)
225 {
226 clock_gettime (CLOCK_REALTIME, &tsock->stats.stop);
227 n--;
228 }
229 }
230 }
231 clock_gettime (CLOCK_REALTIME, &ctrl->stats.stop);
232
Dave Wallace3ee1fe12018-02-23 01:09:11 -0500233#ifndef VCL_TEST
234 {
235 int fd, errno_val;
236 struct sockaddr_un serveraddr;
237 uint8_t buffer[256];
238 size_t nbytes = strlen (SOCK_TEST_MIXED_EPOLL_DATA) + 1;
239 struct timeval timeout;
240
241 /* Open AF_UNIX socket and send an echo to test mixed epoll on server.
242 */
243 fd = socket (AF_UNIX, SOCK_STREAM, 0);
244 if (fd < 0)
245 {
246 errno_val = errno;
247 perror ("ERROR in echo_test_client(): socket(AF_UNIX) failed");
248 fprintf (stderr,
249 "CLIENT: ERROR: socket(AF_UNIX, SOCK_STREAM, 0) failed "
250 "(errno = %d)!\n", errno_val);
251 goto out;
252 }
253 memset (&serveraddr, 0, sizeof (serveraddr));
254 serveraddr.sun_family = AF_UNIX;
255 strcpy (serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME);
256 rv = connect (fd, (struct sockaddr *) &serveraddr, SUN_LEN (&serveraddr));
257 if (rv < 0)
258 {
259 errno_val = errno;
260 perror ("ERROR in echo_test_client(): connect() failed");
261 fprintf (stderr, "CLIENT: ERROR: connect(fd %d, \"%s\", %lu) "
262 "failed (errno = %d)!\n", fd, SOCK_TEST_AF_UNIX_FILENAME,
263 SUN_LEN (&serveraddr), errno_val);
264 goto done;
265 }
266
267 scm->af_unix_echo_tx++;
268 strcpy ((char *) buffer, SOCK_TEST_MIXED_EPOLL_DATA);
269 timeout.tv_sec = 0;
270 timeout.tv_usec = 250000;
271 select (0, NULL, NULL, NULL, &timeout); /* delay .25 secs */
272 rv = write (fd, buffer, nbytes);
273 if (rv < 0)
274 {
275 errno_val = errno;
276 perror ("ERROR in echo_test_client(): write() failed");
277 fprintf (stderr, "CLIENT: ERROR: write(fd %d, \"%s\", %lu) "
278 "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val);
279 goto done;
280 }
281 else if (rv < nbytes)
282 {
283 fprintf (stderr, "CLIENT: ERROR: write(fd %d, \"%s\", %lu) "
284 "returned %d!\n", fd, buffer, nbytes, rv);
285 goto done;
286 }
287
288 printf ("CLIENT (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer);
289 memset (buffer, 0, sizeof (buffer));
290 rv = read (fd, buffer, nbytes);
291 if (rv < 0)
292 {
293 errno_val = errno;
294 perror ("ERROR in echo_test_client(): read() failed");
295 fprintf (stderr, "CLIENT: ERROR: read(fd %d, %p, %lu) "
296 "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val);
297 goto done;
298 }
299 else if (rv < nbytes)
300 {
301 fprintf (stderr, "CLIENT: ERROR: read(fd %d, %p, %lu) "
302 "returned %d!\n", fd, buffer, nbytes, rv);
303 goto done;
304 }
305
306 if (!strncmp (SOCK_TEST_MIXED_EPOLL_DATA, (const char *) buffer, nbytes))
307 {
308 printf ("CLIENT (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer);
309 scm->af_unix_echo_rx++;
310 }
311 else
312 printf ("CLIENT (AF_UNIX): ERROR: RX (%d bytes) - '%s'\n", rv, buffer);
313
314 done:
315 close (fd);
316 out:
317 ;
318 }
319#endif
320
Florin Coras1502fc32018-10-05 00:50:30 -0700321 for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
Dave Wallace543852a2017-08-03 02:11:34 -0400322 {
323 tsock = &scm->test_socket[i];
324 tsock->stats.start = ctrl->stats.start;
325
326 if (ctrl->cfg.verbose)
327 {
328 static char buf[64];
329
330 sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700331 vcl_test_stats_dump (buf, &tsock->stats,
332 1 /* show_rx */ , 1 /* show tx */ ,
333 ctrl->cfg.verbose);
Dave Wallace543852a2017-08-03 02:11:34 -0400334 }
335
Florin Coras1502fc32018-10-05 00:50:30 -0700336 vcl_test_stats_accumulate (&ctrl->stats, &tsock->stats);
Dave Wallace543852a2017-08-03 02:11:34 -0400337 }
338
339 if (ctrl->cfg.verbose)
340 {
Florin Coras1502fc32018-10-05 00:50:30 -0700341 vcl_test_stats_dump ("CLIENT RESULTS", &ctrl->stats,
342 1 /* show_rx */ , 1 /* show tx */ ,
343 ctrl->cfg.verbose);
344 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400345
346 if (ctrl->cfg.verbose > 1)
347 {
348 printf (" ctrl socket info\n"
Florin Coras1502fc32018-10-05 00:50:30 -0700349 VCL_TEST_SEPARATOR_STRING
Dave Wallace543852a2017-08-03 02:11:34 -0400350 " fd: %d (0x%08x)\n"
351 " rxbuf: %p\n"
352 " rxbuf size: %u (0x%08x)\n"
353 " txbuf: %p\n"
354 " txbuf size: %u (0x%08x)\n"
Florin Coras1502fc32018-10-05 00:50:30 -0700355 VCL_TEST_SEPARATOR_STRING,
Dave Wallace543852a2017-08-03 02:11:34 -0400356 ctrl->fd, (uint32_t) ctrl->fd,
357 ctrl->rxbuf, ctrl->rxbuf_size, ctrl->rxbuf_size,
358 ctrl->txbuf, ctrl->txbuf_size, ctrl->txbuf_size);
359 }
360 }
361}
362
363static void
Florin Coras1502fc32018-10-05 00:50:30 -0700364stream_test_client (vcl_test_t test)
Dave Wallace543852a2017-08-03 02:11:34 -0400365{
Florin Coras6d4bb422018-09-04 22:07:27 -0700366 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700367 vcl_test_session_t *ctrl = &scm->ctrl_socket;
368 vcl_test_session_t *tsock;
Dave Wallace543852a2017-08-03 02:11:34 -0400369 int tx_bytes;
370 uint32_t i, n;
371 int rv;
372 int nfds = 0;
373 fd_set wr_fdset, rd_fdset;
374 fd_set _wfdset, *wfdset = &_wfdset;
Florin Coras1502fc32018-10-05 00:50:30 -0700375 fd_set _rfdset, *rfdset = (test == VCL_TEST_TYPE_BI) ? &_rfdset : 0;
Dave Wallace543852a2017-08-03 02:11:34 -0400376
377 ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
378 ctrl->cfg.ctrl_handle = ~0;
379
380 printf ("\n" SOCK_TEST_BANNER_STRING
381 "CLIENT (fd %d): %s-directional Stream Test!\n\n"
382 "CLIENT (fd %d): Sending config to server on ctrl socket...\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700383 ctrl->fd, test == VCL_TEST_TYPE_BI ? "Bi" : "Uni", ctrl->fd);
Dave Wallace543852a2017-08-03 02:11:34 -0400384
385 if (sock_test_cfg_sync (ctrl))
386 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500387 fprintf (stderr, "CLIENT: ERROR: test cfg sync failed -- aborting!");
Dave Wallace543852a2017-08-03 02:11:34 -0400388 return;
389 }
390
391 FD_ZERO (&wr_fdset);
392 FD_ZERO (&rd_fdset);
393 memset (&ctrl->stats, 0, sizeof (ctrl->stats));
Florin Coras1502fc32018-10-05 00:50:30 -0700394 for (n = 0; n != ctrl->cfg.num_test_sessions; n++)
Dave Wallace543852a2017-08-03 02:11:34 -0400395 {
396 tsock = &scm->test_socket[n];
397 tsock->cfg = ctrl->cfg;
Florin Coras1502fc32018-10-05 00:50:30 -0700398 vcl_test_session_buf_alloc (tsock);
Dave Wallace543852a2017-08-03 02:11:34 -0400399 printf ("CLIENT (fd %d): Sending config to server on "
400 "test socket %d...\n", tsock->fd, n);
401 sock_test_cfg_sync (tsock);
402
403 /* Fill payload with incrementing uint32's */
404 for (i = 0; i < tsock->txbuf_size; i++)
405 tsock->txbuf[i] = i & 0xff;
406
407 memset (&tsock->stats, 0, sizeof (tsock->stats));
408 FD_SET (tsock->fd, &wr_fdset);
409 FD_SET (tsock->fd, &rd_fdset);
410 nfds = ((tsock->fd + 1) > nfds) ? (tsock->fd + 1) : nfds;
411 }
412
413 nfds++;
414 clock_gettime (CLOCK_REALTIME, &ctrl->stats.start);
415 while (n)
416 {
417 _wfdset = wr_fdset;
418 _rfdset = rd_fdset;
419
420#ifdef VCL_TEST
David Johnsond9818dd2018-12-14 14:53:41 -0500421 rv =
422 vppcom_select (nfds, (unsigned long *) rfdset,
423 (unsigned long *) wfdset, NULL, 0);
Dave Wallace543852a2017-08-03 02:11:34 -0400424#else
425 {
426 struct timeval timeout;
427 timeout.tv_sec = 0;
428 timeout.tv_usec = 0;
429 rv = select (nfds, rfdset, wfdset, NULL, &timeout);
430 }
431#endif
432 if (rv < 0)
433 {
434 perror ("select()");
Dave Wallace048b1d62018-01-03 22:24:41 -0500435 fprintf (stderr, "\nCLIENT: ERROR: select() failed -- "
436 "aborting test!\n");
Dave Wallace543852a2017-08-03 02:11:34 -0400437 return;
438 }
439 else if (rv == 0)
440 continue;
441
Florin Coras1502fc32018-10-05 00:50:30 -0700442 for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
Dave Wallace543852a2017-08-03 02:11:34 -0400443 {
444 tsock = &scm->test_socket[i];
445 if (!((tsock->stats.stop.tv_sec == 0) &&
446 (tsock->stats.stop.tv_nsec == 0)))
447 continue;
448
Florin Coras1502fc32018-10-05 00:50:30 -0700449 if ((test == VCL_TEST_TYPE_BI) &&
Dave Wallace048b1d62018-01-03 22:24:41 -0500450 FD_ISSET (tsock->fd, rfdset) &&
451 (tsock->stats.rx_bytes < ctrl->cfg.total_bytes))
452 {
453 (void) sock_test_read (tsock->fd,
454 (uint8_t *) tsock->rxbuf,
455 tsock->rxbuf_size, &tsock->stats);
456 }
457
Dave Wallace543852a2017-08-03 02:11:34 -0400458 if (FD_ISSET (tsock->fd, wfdset) &&
459 (tsock->stats.tx_bytes < ctrl->cfg.total_bytes))
460 {
Florin Coras54693d22018-07-17 10:46:29 -0700461 tx_bytes = sock_test_write (tsock->fd, (uint8_t *) tsock->txbuf,
462 ctrl->cfg.txbuf_size, &tsock->stats,
463 ctrl->cfg.verbose);
Dave Wallace543852a2017-08-03 02:11:34 -0400464 if (tx_bytes < 0)
465 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500466 fprintf (stderr, "\nCLIENT: ERROR: sock_test_write(%d) "
467 "failed -- aborting test!\n", tsock->fd);
Dave Wallace543852a2017-08-03 02:11:34 -0400468 return;
469 }
470 }
471
Florin Coras1502fc32018-10-05 00:50:30 -0700472 if (((test == VCL_TEST_TYPE_UNI) &&
Dave Wallace543852a2017-08-03 02:11:34 -0400473 (tsock->stats.tx_bytes >= ctrl->cfg.total_bytes)) ||
Florin Coras1502fc32018-10-05 00:50:30 -0700474 ((test == VCL_TEST_TYPE_BI) &&
Dave Wallace543852a2017-08-03 02:11:34 -0400475 (tsock->stats.rx_bytes >= ctrl->cfg.total_bytes)))
476 {
477 clock_gettime (CLOCK_REALTIME, &tsock->stats.stop);
478 n--;
479 }
480 }
481 }
482 clock_gettime (CLOCK_REALTIME, &ctrl->stats.stop);
483
484 printf ("CLIENT (fd %d): Sending config to server on ctrl socket...\n",
485 ctrl->fd);
486
487 if (sock_test_cfg_sync (ctrl))
488 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500489 fprintf (stderr, "CLIENT: ERROR: test cfg sync failed -- aborting!");
Dave Wallace543852a2017-08-03 02:11:34 -0400490 return;
491 }
492
Florin Coras1502fc32018-10-05 00:50:30 -0700493 for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
Dave Wallace543852a2017-08-03 02:11:34 -0400494 {
495 tsock = &scm->test_socket[i];
496
497 if (ctrl->cfg.verbose)
498 {
499 static char buf[64];
500
501 sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700502 vcl_test_stats_dump (buf, &tsock->stats,
503 test == VCL_TEST_TYPE_BI /* show_rx */ ,
504 1 /* show tx */ , ctrl->cfg.verbose);
Dave Wallace543852a2017-08-03 02:11:34 -0400505 }
506
Florin Coras1502fc32018-10-05 00:50:30 -0700507 vcl_test_stats_accumulate (&ctrl->stats, &tsock->stats);
Dave Wallace543852a2017-08-03 02:11:34 -0400508 }
509
Florin Coras1502fc32018-10-05 00:50:30 -0700510 vcl_test_stats_dump ("CLIENT RESULTS", &ctrl->stats,
511 test == VCL_TEST_TYPE_BI /* show_rx */ ,
512 1 /* show tx */ , ctrl->cfg.verbose);
513 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400514
515 if (ctrl->cfg.verbose)
516 {
517 printf (" ctrl socket info\n"
Florin Coras1502fc32018-10-05 00:50:30 -0700518 VCL_TEST_SEPARATOR_STRING
Dave Wallace543852a2017-08-03 02:11:34 -0400519 " fd: %d (0x%08x)\n"
520 " rxbuf: %p\n"
521 " rxbuf size: %u (0x%08x)\n"
522 " txbuf: %p\n"
523 " txbuf size: %u (0x%08x)\n"
Florin Coras1502fc32018-10-05 00:50:30 -0700524 VCL_TEST_SEPARATOR_STRING,
Dave Wallace543852a2017-08-03 02:11:34 -0400525 ctrl->fd, (uint32_t) ctrl->fd,
526 ctrl->rxbuf, ctrl->rxbuf_size, ctrl->rxbuf_size,
527 ctrl->txbuf, ctrl->txbuf_size, ctrl->txbuf_size);
528 }
529
Florin Coras1502fc32018-10-05 00:50:30 -0700530 ctrl->cfg.test = VCL_TEST_TYPE_ECHO;
Dave Wallace543852a2017-08-03 02:11:34 -0400531 if (sock_test_cfg_sync (ctrl))
Dave Wallace048b1d62018-01-03 22:24:41 -0500532 fprintf (stderr, "CLIENT: ERROR: post-test cfg sync failed!");
Dave Wallace543852a2017-08-03 02:11:34 -0400533
534 printf ("CLIENT (fd %d): %s-directional Stream Test Complete!\n"
535 SOCK_TEST_BANNER_STRING "\n", ctrl->fd,
Florin Coras1502fc32018-10-05 00:50:30 -0700536 test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
Dave Wallace543852a2017-08-03 02:11:34 -0400537}
538
539static void
540exit_client (void)
541{
Florin Coras6d4bb422018-09-04 22:07:27 -0700542 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700543 vcl_test_session_t *ctrl = &scm->ctrl_socket;
544 vcl_test_session_t *tsock;
Dave Wallace543852a2017-08-03 02:11:34 -0400545 int i;
546
Dave Wallace3ee1fe12018-02-23 01:09:11 -0500547#ifndef VCL_TEST
548 printf ("CLIENT: af_unix_echo_tx %d, af_unix_echo_rx %d\n",
549 scm->af_unix_echo_tx, scm->af_unix_echo_rx);
550#endif
Florin Coras1502fc32018-10-05 00:50:30 -0700551 for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
Dave Wallace543852a2017-08-03 02:11:34 -0400552 {
553 tsock = &scm->test_socket[i];
Florin Coras1502fc32018-10-05 00:50:30 -0700554 tsock->cfg.test = VCL_TEST_TYPE_EXIT;
Dave Wallace543852a2017-08-03 02:11:34 -0400555
Chris Lukeb2bcad62017-09-18 08:51:22 -0400556 /* coverity[COPY_PASTE_ERROR] */
Dave Wallace543852a2017-08-03 02:11:34 -0400557 if (ctrl->cfg.verbose)
558 {
559 printf ("\nCLIENT (fd %d): Sending exit cfg to server...\n",
560 tsock->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700561 vcl_test_cfg_dump (&tsock->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400562 }
563 (void) sock_test_write (tsock->fd, (uint8_t *) & tsock->cfg,
564 sizeof (tsock->cfg), &tsock->stats,
565 ctrl->cfg.verbose);
566 }
567
Florin Coras1502fc32018-10-05 00:50:30 -0700568 ctrl->cfg.test = VCL_TEST_TYPE_EXIT;
Dave Wallace543852a2017-08-03 02:11:34 -0400569 if (ctrl->cfg.verbose)
570 {
571 printf ("\nCLIENT (fd %d): Sending exit cfg to server...\n", ctrl->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700572 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400573 }
574 (void) sock_test_write (ctrl->fd, (uint8_t *) & ctrl->cfg,
575 sizeof (ctrl->cfg), &ctrl->stats,
576 ctrl->cfg.verbose);
577 printf ("\nCLIENT: So long and thanks for all the fish!\n\n");
578 sleep (1);
579}
580
581static int
582sock_test_connect_test_sockets (uint32_t num_test_sockets)
583{
Florin Coras6d4bb422018-09-04 22:07:27 -0700584 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700585 vcl_test_session_t *ctrl = &scm->ctrl_socket;
586 vcl_test_session_t *tsock;
Dave Wallace543852a2017-08-03 02:11:34 -0400587 int i, rv, errno_val;
588
589 if (num_test_sockets < 1)
590 {
591 errno = EINVAL;
592 return -1;
593 }
594
595 if (num_test_sockets < scm->num_test_sockets)
596 {
597 for (i = scm->num_test_sockets - 1; i >= num_test_sockets; i--)
598 {
599 tsock = &scm->test_socket[i];
600#ifdef VCL_TEST
601 vppcom_session_close (tsock->fd);
602#else
603 close (tsock->fd);
604#endif
605 free (tsock->txbuf);
606 free (tsock->rxbuf);
607 }
608 }
609
610 else if (num_test_sockets > scm->num_test_sockets)
611 {
612 tsock = realloc (scm->test_socket,
Florin Coras1502fc32018-10-05 00:50:30 -0700613 sizeof (vcl_test_session_t) * num_test_sockets);
Dave Wallace543852a2017-08-03 02:11:34 -0400614 if (!tsock)
615 {
616 errno_val = errno;
617 perror ("ERROR in sock_test_connect_test_sockets()");
Dave Wallace048b1d62018-01-03 22:24:41 -0500618 fprintf (stderr, "CLIENT: ERROR: socket failed (errno = %d)!\n",
619 errno_val);
Dave Wallace543852a2017-08-03 02:11:34 -0400620 return -1;
621 }
622
Dave Wallaced48e9762017-08-22 23:29:33 -0400623 if (!scm->test_socket)
624 memset (tsock, 0, sizeof (*tsock));
625
Dave Wallace543852a2017-08-03 02:11:34 -0400626 scm->test_socket = tsock;
627 for (i = scm->num_test_sockets; i < num_test_sockets; i++)
628 {
629 tsock = &scm->test_socket[i];
630#ifdef VCL_TEST
Dave Wallacede910062018-03-20 09:22:13 -0400631 tsock->fd = vppcom_session_create (ctrl->cfg.transport_udp ?
632 VPPCOM_PROTO_UDP :
633 VPPCOM_PROTO_TCP,
634 1 /* is_nonblocking */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400635 if (tsock->fd < 0)
636 {
637 errno = -tsock->fd;
638 tsock->fd = -1;
639 }
640#else
Dave Wallacede910062018-03-20 09:22:13 -0400641 tsock->fd = socket (ctrl->cfg.address_ip6 ? AF_INET6 : AF_INET,
642 ctrl->cfg.transport_udp ?
643 SOCK_DGRAM : SOCK_STREAM, 0);
Dave Wallace543852a2017-08-03 02:11:34 -0400644#endif
645 if (tsock->fd < 0)
646 {
647 errno_val = errno;
648 perror ("ERROR in sock_test_connect_test_sockets()");
Dave Wallace048b1d62018-01-03 22:24:41 -0500649 fprintf (stderr, "CLIENT: ERROR: socket failed (errno = %d)!\n",
Dave Wallace543852a2017-08-03 02:11:34 -0400650 errno_val);
651 return tsock->fd;
652 }
Florin Corasc227e492018-12-21 19:28:34 -0800653 if (fcntl (tsock->fd, F_SETFL, O_NONBLOCK) < 0)
654 {
655 errno_val = errno;
656 perror ("ERROR in sock_test_connect_test_sockets()");
657 fprintf (stderr, "CLIENT: ERROR: fcntl failed (errno = %d)!\n",
658 errno_val);
659 return -1;
660 }
Dave Wallace543852a2017-08-03 02:11:34 -0400661
662#ifdef VCL_TEST
663 rv = vppcom_session_connect (tsock->fd, &scm->server_endpt);
Dave Wallaceee45d412017-11-24 21:44:06 -0500664 if (rv)
665 {
666 errno = -rv;
667 rv = -1;
668 }
Dave Wallace543852a2017-08-03 02:11:34 -0400669#else
670 rv =
671 connect (tsock->fd, (struct sockaddr *) &scm->server_addr,
Dave Wallacede910062018-03-20 09:22:13 -0400672 scm->server_addr_size);
Dave Wallace543852a2017-08-03 02:11:34 -0400673#endif
674 if (rv < 0)
675 {
676 errno_val = errno;
Dave Wallaceee45d412017-11-24 21:44:06 -0500677 perror ("ERROR in sock_test_connect_test_sockets()");
Dave Wallace048b1d62018-01-03 22:24:41 -0500678 fprintf (stderr, "CLIENT: ERROR: connect failed "
679 "(errno = %d)!\n", errno_val);
Dave Wallaceee45d412017-11-24 21:44:06 -0500680 return -1;
Dave Wallace543852a2017-08-03 02:11:34 -0400681 }
682 tsock->cfg = ctrl->cfg;
Florin Coras1502fc32018-10-05 00:50:30 -0700683 vcl_test_session_buf_alloc (tsock);
Dave Wallace543852a2017-08-03 02:11:34 -0400684 sock_test_cfg_sync (tsock);
685
686 printf ("CLIENT (fd %d): Test socket %d connected.\n",
687 tsock->fd, i);
688 }
689 }
690
691 scm->num_test_sockets = num_test_sockets;
692 printf ("CLIENT: All sockets (%d) connected!\n", scm->num_test_sockets + 1);
693 return 0;
694}
695
696static void
697dump_help (void)
698{
699#define INDENT "\n "
700
Dave Wallace048b1d62018-01-03 22:24:41 -0500701 printf ("CLIENT: Test configuration commands:"
Florin Coras1502fc32018-10-05 00:50:30 -0700702 INDENT VCL_TEST_TOKEN_HELP
Dave Wallace543852a2017-08-03 02:11:34 -0400703 "\t\t\tDisplay help."
Florin Coras1502fc32018-10-05 00:50:30 -0700704 INDENT VCL_TEST_TOKEN_EXIT
Dave Wallace543852a2017-08-03 02:11:34 -0400705 "\t\t\tExit test client & server."
Florin Coras1502fc32018-10-05 00:50:30 -0700706 INDENT VCL_TEST_TOKEN_SHOW_CFG
Dave Wallace543852a2017-08-03 02:11:34 -0400707 "\t\t\tShow the current test cfg."
Florin Coras1502fc32018-10-05 00:50:30 -0700708 INDENT VCL_TEST_TOKEN_RUN_UNI
Dave Wallace543852a2017-08-03 02:11:34 -0400709 "\t\t\tRun the Uni-directional test."
Florin Coras1502fc32018-10-05 00:50:30 -0700710 INDENT VCL_TEST_TOKEN_RUN_BI
Dave Wallace543852a2017-08-03 02:11:34 -0400711 "\t\t\tRun the Bi-directional test."
Florin Coras1502fc32018-10-05 00:50:30 -0700712 INDENT VCL_TEST_TOKEN_VERBOSE
Dave Wallace543852a2017-08-03 02:11:34 -0400713 "\t\t\tToggle verbose setting."
Florin Coras1502fc32018-10-05 00:50:30 -0700714 INDENT VCL_TEST_TOKEN_RXBUF_SIZE
Dave Wallace543852a2017-08-03 02:11:34 -0400715 "<rxbuf size>\tRx buffer size (bytes)."
Florin Coras1502fc32018-10-05 00:50:30 -0700716 INDENT VCL_TEST_TOKEN_TXBUF_SIZE
Dave Wallace543852a2017-08-03 02:11:34 -0400717 "<txbuf size>\tTx buffer size (bytes)."
Florin Coras1502fc32018-10-05 00:50:30 -0700718 INDENT VCL_TEST_TOKEN_NUM_WRITES
Dave Wallace543852a2017-08-03 02:11:34 -0400719 "<# of writes>\tNumber of txbuf writes to server." "\n");
720}
721
722static void
723cfg_txbuf_size_set (void)
724{
Florin Coras6d4bb422018-09-04 22:07:27 -0700725 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700726 vcl_test_session_t *ctrl = &scm->ctrl_socket;
727 char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_TXBUF_SIZE);
Dave Wallace543852a2017-08-03 02:11:34 -0400728 uint64_t txbuf_size = strtoull ((const char *) p, NULL, 10);
729
Florin Coras1502fc32018-10-05 00:50:30 -0700730 if (txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
Dave Wallace543852a2017-08-03 02:11:34 -0400731 {
732 ctrl->cfg.txbuf_size = txbuf_size;
733 ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
Florin Coras1502fc32018-10-05 00:50:30 -0700734 vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
735 (uint8_t **) & ctrl->txbuf, &ctrl->txbuf_size);
736 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400737 }
738 else
Dave Wallace048b1d62018-01-03 22:24:41 -0500739 fprintf (stderr, "CLIENT: ERROR: Invalid txbuf size (%lu) < "
740 "minimum buf size (%u)!\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700741 txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
Dave Wallace543852a2017-08-03 02:11:34 -0400742}
743
744static void
745cfg_num_writes_set (void)
746{
Florin Coras6d4bb422018-09-04 22:07:27 -0700747 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700748 vcl_test_session_t *ctrl = &scm->ctrl_socket;
749 char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_WRITES);
Dave Wallace543852a2017-08-03 02:11:34 -0400750 uint32_t num_writes = strtoul ((const char *) p, NULL, 10);
751
752 if (num_writes > 0)
753 {
754 ctrl->cfg.num_writes = num_writes;
755 ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
Florin Coras1502fc32018-10-05 00:50:30 -0700756 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400757 }
758 else
759 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500760 fprintf (stderr, "CLIENT: ERROR: invalid num writes: %u\n", num_writes);
Dave Wallace543852a2017-08-03 02:11:34 -0400761 }
762}
763
764static void
765cfg_num_test_sockets_set (void)
766{
Florin Coras6d4bb422018-09-04 22:07:27 -0700767 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700768 vcl_test_session_t *ctrl = &scm->ctrl_socket;
769 char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_TEST_SESS);
Dave Wallace543852a2017-08-03 02:11:34 -0400770 uint32_t num_test_sockets = strtoul ((const char *) p, NULL, 10);
771
772 if ((num_test_sockets > 0) &&
Florin Coras1502fc32018-10-05 00:50:30 -0700773 (num_test_sockets <= VCL_TEST_CFG_MAX_TEST_SESS))
Dave Wallace543852a2017-08-03 02:11:34 -0400774 {
Florin Coras1502fc32018-10-05 00:50:30 -0700775 ctrl->cfg.num_test_sessions = num_test_sockets;
Dave Wallace543852a2017-08-03 02:11:34 -0400776 sock_test_connect_test_sockets (num_test_sockets);
Dave Wallaceee45d412017-11-24 21:44:06 -0500777
Florin Coras1502fc32018-10-05 00:50:30 -0700778 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400779 }
780 else
781 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500782 fprintf (stderr, "CLIENT: ERROR: invalid num test sockets: "
783 "%u, (%d max)\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700784 num_test_sockets, VCL_TEST_CFG_MAX_TEST_SESS);
Dave Wallace543852a2017-08-03 02:11:34 -0400785 }
786}
787
788static void
789cfg_rxbuf_size_set (void)
790{
Florin Coras6d4bb422018-09-04 22:07:27 -0700791 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700792 vcl_test_session_t *ctrl = &scm->ctrl_socket;
793 char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_RXBUF_SIZE);
Dave Wallace543852a2017-08-03 02:11:34 -0400794 uint64_t rxbuf_size = strtoull ((const char *) p, NULL, 10);
795
Florin Coras1502fc32018-10-05 00:50:30 -0700796 if (rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
Dave Wallace543852a2017-08-03 02:11:34 -0400797 {
798 ctrl->cfg.rxbuf_size = rxbuf_size;
Florin Coras1502fc32018-10-05 00:50:30 -0700799 vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
800 (uint8_t **) & ctrl->rxbuf, &ctrl->rxbuf_size);
801 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400802 }
803 else
Dave Wallace048b1d62018-01-03 22:24:41 -0500804 fprintf (stderr, "CLIENT: ERROR: Invalid rxbuf size (%lu) < "
805 "minimum buf size (%u)!\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700806 rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
Dave Wallace543852a2017-08-03 02:11:34 -0400807}
808
809static void
810cfg_verbose_toggle (void)
811{
Florin Coras6d4bb422018-09-04 22:07:27 -0700812 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700813 vcl_test_session_t *ctrl = &scm->ctrl_socket;
Dave Wallace543852a2017-08-03 02:11:34 -0400814
815 ctrl->cfg.verbose = ctrl->cfg.verbose ? 0 : 1;
Florin Coras1502fc32018-10-05 00:50:30 -0700816 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400817
818}
819
Florin Coras1502fc32018-10-05 00:50:30 -0700820static vcl_test_t
Dave Wallace543852a2017-08-03 02:11:34 -0400821parse_input ()
822{
Florin Coras6d4bb422018-09-04 22:07:27 -0700823 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700824 vcl_test_session_t *ctrl = &scm->ctrl_socket;
825 vcl_test_t rv = VCL_TEST_TYPE_NONE;
Dave Wallace543852a2017-08-03 02:11:34 -0400826
Florin Coras1502fc32018-10-05 00:50:30 -0700827 if (!strncmp (VCL_TEST_TOKEN_EXIT, ctrl->txbuf,
828 strlen (VCL_TEST_TOKEN_EXIT)))
829 rv = VCL_TEST_TYPE_EXIT;
Dave Wallace543852a2017-08-03 02:11:34 -0400830
Florin Coras1502fc32018-10-05 00:50:30 -0700831 else if (!strncmp (VCL_TEST_TOKEN_HELP, ctrl->txbuf,
832 strlen (VCL_TEST_TOKEN_HELP)))
Dave Wallace543852a2017-08-03 02:11:34 -0400833 dump_help ();
834
Florin Coras1502fc32018-10-05 00:50:30 -0700835 else if (!strncmp (VCL_TEST_TOKEN_SHOW_CFG, ctrl->txbuf,
836 strlen (VCL_TEST_TOKEN_SHOW_CFG)))
Dave Wallace543852a2017-08-03 02:11:34 -0400837 scm->dump_cfg = 1;
838
Florin Coras1502fc32018-10-05 00:50:30 -0700839 else if (!strncmp (VCL_TEST_TOKEN_VERBOSE, ctrl->txbuf,
840 strlen (VCL_TEST_TOKEN_VERBOSE)))
Dave Wallace543852a2017-08-03 02:11:34 -0400841 cfg_verbose_toggle ();
842
Florin Coras1502fc32018-10-05 00:50:30 -0700843 else if (!strncmp (VCL_TEST_TOKEN_TXBUF_SIZE, ctrl->txbuf,
844 strlen (VCL_TEST_TOKEN_TXBUF_SIZE)))
Dave Wallace543852a2017-08-03 02:11:34 -0400845 cfg_txbuf_size_set ();
846
Florin Coras1502fc32018-10-05 00:50:30 -0700847 else if (!strncmp (VCL_TEST_TOKEN_NUM_TEST_SESS, ctrl->txbuf,
848 strlen (VCL_TEST_TOKEN_NUM_TEST_SESS)))
Dave Wallace543852a2017-08-03 02:11:34 -0400849 cfg_num_test_sockets_set ();
850
Florin Coras1502fc32018-10-05 00:50:30 -0700851 else if (!strncmp (VCL_TEST_TOKEN_NUM_WRITES, ctrl->txbuf,
852 strlen (VCL_TEST_TOKEN_NUM_WRITES)))
Dave Wallace543852a2017-08-03 02:11:34 -0400853 cfg_num_writes_set ();
854
Florin Coras1502fc32018-10-05 00:50:30 -0700855 else if (!strncmp (VCL_TEST_TOKEN_RXBUF_SIZE, ctrl->txbuf,
856 strlen (VCL_TEST_TOKEN_RXBUF_SIZE)))
Dave Wallace543852a2017-08-03 02:11:34 -0400857 cfg_rxbuf_size_set ();
858
Florin Coras1502fc32018-10-05 00:50:30 -0700859 else if (!strncmp (VCL_TEST_TOKEN_RUN_UNI, ctrl->txbuf,
860 strlen (VCL_TEST_TOKEN_RUN_UNI)))
861 rv = ctrl->cfg.test = VCL_TEST_TYPE_UNI;
Dave Wallace543852a2017-08-03 02:11:34 -0400862
Florin Coras1502fc32018-10-05 00:50:30 -0700863 else if (!strncmp (VCL_TEST_TOKEN_RUN_BI, ctrl->txbuf,
864 strlen (VCL_TEST_TOKEN_RUN_BI)))
865 rv = ctrl->cfg.test = VCL_TEST_TYPE_BI;
Dave Wallace543852a2017-08-03 02:11:34 -0400866
867 else
Florin Coras1502fc32018-10-05 00:50:30 -0700868 rv = VCL_TEST_TYPE_ECHO;
Dave Wallace543852a2017-08-03 02:11:34 -0400869
870 return rv;
871}
872
873void
874print_usage_and_exit (void)
875{
876 fprintf (stderr,
877 "sock_test_client [OPTIONS] <ipaddr> <port>\n"
878 " OPTIONS\n"
879 " -h Print this message and exit.\n"
Dave Wallacede910062018-03-20 09:22:13 -0400880 " -6 Use IPv6\n"
881 " -u Use UDP transport layer\n"
Dave Wallace543852a2017-08-03 02:11:34 -0400882 " -c Print test config before test.\n"
883 " -w <dir> Write test results to <dir>.\n"
884 " -X Exit after running test.\n"
885 " -E Run Echo test.\n"
886 " -N <num-writes> Test Cfg: number of writes.\n"
887 " -R <rxbuf-size> Test Cfg: rx buffer size.\n"
888 " -T <txbuf-size> Test Cfg: tx buffer size.\n"
889 " -U Run Uni-directional test.\n"
890 " -B Run Bi-directional test.\n"
891 " -V Verbose mode.\n");
892 exit (1);
893}
894
895int
896main (int argc, char **argv)
897{
Florin Coras6d4bb422018-09-04 22:07:27 -0700898 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700899 vcl_test_session_t *ctrl = &scm->ctrl_socket;
Dave Wallace543852a2017-08-03 02:11:34 -0400900 int c, rv, errno_val;
Florin Coras1502fc32018-10-05 00:50:30 -0700901 vcl_test_t post_test = VCL_TEST_TYPE_NONE;
Dave Wallace543852a2017-08-03 02:11:34 -0400902
Florin Coras1502fc32018-10-05 00:50:30 -0700903 vcl_test_cfg_init (&ctrl->cfg);
904 vcl_test_session_buf_alloc (ctrl);
Dave Wallace543852a2017-08-03 02:11:34 -0400905
906 opterr = 0;
Dave Wallacede910062018-03-20 09:22:13 -0400907 while ((c = getopt (argc, argv, "chn:w:XE:I:N:R:T:UBV6D")) != -1)
Dave Wallace543852a2017-08-03 02:11:34 -0400908 switch (c)
909 {
910 case 'c':
911 scm->dump_cfg = 1;
912 break;
913
914 case 's':
Florin Coras1502fc32018-10-05 00:50:30 -0700915 if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1)
916 if (sscanf (optarg, "%u", &ctrl->cfg.num_test_sessions) != 1)
Dave Wallace543852a2017-08-03 02:11:34 -0400917 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500918 fprintf (stderr, "CLIENT: ERROR: Invalid value for "
919 "option -%c!\n", c);
Dave Wallace543852a2017-08-03 02:11:34 -0400920 print_usage_and_exit ();
921 }
Florin Coras1502fc32018-10-05 00:50:30 -0700922 if (!ctrl->cfg.num_test_sessions ||
923 (ctrl->cfg.num_test_sessions > FD_SETSIZE))
Dave Wallace543852a2017-08-03 02:11:34 -0400924 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500925 fprintf (stderr, "CLIENT: ERROR: Invalid number of "
926 "sockets (%d) specified for option -%c!\n"
Dave Wallace543852a2017-08-03 02:11:34 -0400927 " Valid range is 1 - %d\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700928 ctrl->cfg.num_test_sessions, c, FD_SETSIZE);
Dave Wallace543852a2017-08-03 02:11:34 -0400929 print_usage_and_exit ();
930 }
931 break;
932
933 case 'w':
Dave Wallace048b1d62018-01-03 22:24:41 -0500934 fprintf (stderr, "CLIENT: Writing test results to files is TBD.\n");
Dave Wallace543852a2017-08-03 02:11:34 -0400935 break;
936
937 case 'X':
Florin Coras1502fc32018-10-05 00:50:30 -0700938 post_test = VCL_TEST_TYPE_EXIT;
Dave Wallace543852a2017-08-03 02:11:34 -0400939 break;
940
941 case 'E':
942 if (strlen (optarg) > ctrl->txbuf_size)
943 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500944 fprintf (stderr, "CLIENT: ERROR: Option -%c value "
945 "larger than txbuf size (%d)!\n",
Dave Wallace543852a2017-08-03 02:11:34 -0400946 optopt, ctrl->txbuf_size);
947 print_usage_and_exit ();
948 }
949 strcpy (ctrl->txbuf, optarg);
Florin Coras1502fc32018-10-05 00:50:30 -0700950 ctrl->cfg.test = VCL_TEST_TYPE_ECHO;
Dave Wallace543852a2017-08-03 02:11:34 -0400951 break;
952
953 case 'I':
Florin Coras1502fc32018-10-05 00:50:30 -0700954 if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1)
955 if (sscanf (optarg, "%d", &ctrl->cfg.num_test_sessions) != 1)
Dave Wallace543852a2017-08-03 02:11:34 -0400956 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500957 fprintf (stderr, "CLIENT: ERROR: Invalid value for "
958 "option -%c!\n", c);
Dave Wallace543852a2017-08-03 02:11:34 -0400959 print_usage_and_exit ();
960 }
Florin Coras1502fc32018-10-05 00:50:30 -0700961 if (ctrl->cfg.num_test_sessions > VCL_TEST_CFG_MAX_TEST_SESS)
Dave Wallace543852a2017-08-03 02:11:34 -0400962 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500963 fprintf (stderr, "CLIENT: ERROR: value greater than max "
Florin Coras1502fc32018-10-05 00:50:30 -0700964 "number test sockets (%d)!", VCL_TEST_CFG_MAX_TEST_SESS);
Dave Wallace543852a2017-08-03 02:11:34 -0400965 print_usage_and_exit ();
966 }
967 break;
968
969 case 'N':
970 if (sscanf (optarg, "0x%lx", &ctrl->cfg.num_writes) != 1)
971 if (sscanf (optarg, "%ld", &ctrl->cfg.num_writes) != 1)
972 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500973 fprintf (stderr, "CLIENT: ERROR: Invalid value for "
974 "option -%c!\n", c);
Dave Wallace543852a2017-08-03 02:11:34 -0400975 print_usage_and_exit ();
976 }
977 ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
978 break;
979
980 case 'R':
981 if (sscanf (optarg, "0x%lx", &ctrl->cfg.rxbuf_size) != 1)
982 if (sscanf (optarg, "%ld", &ctrl->cfg.rxbuf_size) != 1)
983 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500984 fprintf (stderr, "CLIENT: ERROR: Invalid value for "
985 "option -%c!\n", c);
Dave Wallace543852a2017-08-03 02:11:34 -0400986 print_usage_and_exit ();
987 }
Florin Coras1502fc32018-10-05 00:50:30 -0700988 if (ctrl->cfg.rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
Dave Wallace543852a2017-08-03 02:11:34 -0400989 {
990 ctrl->rxbuf_size = ctrl->cfg.rxbuf_size;
Florin Coras1502fc32018-10-05 00:50:30 -0700991 vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
992 (uint8_t **) & ctrl->rxbuf,
993 &ctrl->rxbuf_size);
Dave Wallace543852a2017-08-03 02:11:34 -0400994 }
995 else
996 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500997 fprintf (stderr, "CLIENT: ERROR: rxbuf size (%lu) "
998 "less than minumum (%u)\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700999 ctrl->cfg.rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
Dave Wallace543852a2017-08-03 02:11:34 -04001000 print_usage_and_exit ();
1001 }
1002
1003 break;
1004
1005 case 'T':
1006 if (sscanf (optarg, "0x%lx", &ctrl->cfg.txbuf_size) != 1)
1007 if (sscanf (optarg, "%ld", &ctrl->cfg.txbuf_size) != 1)
1008 {
Dave Wallace048b1d62018-01-03 22:24:41 -05001009 fprintf (stderr, "CLIENT: ERROR: Invalid value "
1010 "for option -%c!\n", c);
Dave Wallace543852a2017-08-03 02:11:34 -04001011 print_usage_and_exit ();
1012 }
Florin Coras1502fc32018-10-05 00:50:30 -07001013 if (ctrl->cfg.txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
Dave Wallace543852a2017-08-03 02:11:34 -04001014 {
1015 ctrl->txbuf_size = ctrl->cfg.txbuf_size;
Florin Coras1502fc32018-10-05 00:50:30 -07001016 vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
1017 (uint8_t **) & ctrl->txbuf,
1018 &ctrl->txbuf_size);
Dave Wallace543852a2017-08-03 02:11:34 -04001019 ctrl->cfg.total_bytes =
1020 ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
1021 }
1022 else
1023 {
Dave Wallace048b1d62018-01-03 22:24:41 -05001024 fprintf (stderr, "CLIENT: ERROR: txbuf size (%lu) "
1025 "less than minumum (%u)!\n",
Florin Coras1502fc32018-10-05 00:50:30 -07001026 ctrl->cfg.txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
Dave Wallace543852a2017-08-03 02:11:34 -04001027 print_usage_and_exit ();
1028 }
1029 break;
1030
1031 case 'U':
Florin Coras1502fc32018-10-05 00:50:30 -07001032 ctrl->cfg.test = VCL_TEST_TYPE_UNI;
Dave Wallace543852a2017-08-03 02:11:34 -04001033 break;
1034
1035 case 'B':
Florin Coras1502fc32018-10-05 00:50:30 -07001036 ctrl->cfg.test = VCL_TEST_TYPE_BI;
Dave Wallace543852a2017-08-03 02:11:34 -04001037 break;
1038
1039 case 'V':
1040 ctrl->cfg.verbose = 1;
1041 break;
1042
Dave Wallacede910062018-03-20 09:22:13 -04001043 case '6':
1044 ctrl->cfg.address_ip6 = 1;
1045 break;
1046
1047 case 'D':
1048 ctrl->cfg.transport_udp = 1;
1049 break;
1050
Dave Wallace543852a2017-08-03 02:11:34 -04001051 case '?':
1052 switch (optopt)
1053 {
1054 case 'E':
1055 case 'I':
1056 case 'N':
1057 case 'R':
1058 case 'T':
1059 case 'w':
Dave Wallace048b1d62018-01-03 22:24:41 -05001060 fprintf (stderr, "CLIENT: ERROR: Option -%c "
1061 "requires an argument.\n", optopt);
Chris Lukeab7b8d92017-09-07 07:40:13 -04001062 break;
1063
Dave Wallace543852a2017-08-03 02:11:34 -04001064 default:
1065 if (isprint (optopt))
Dave Wallace048b1d62018-01-03 22:24:41 -05001066 fprintf (stderr, "CLIENT: ERROR: Unknown "
1067 "option `-%c'.\n", optopt);
Dave Wallace543852a2017-08-03 02:11:34 -04001068 else
Dave Wallace048b1d62018-01-03 22:24:41 -05001069 fprintf (stderr, "CLIENT: ERROR: Unknown "
1070 "option character `\\x%x'.\n", optopt);
Dave Wallace543852a2017-08-03 02:11:34 -04001071 }
1072 /* fall thru */
1073 case 'h':
1074 default:
1075 print_usage_and_exit ();
1076 }
1077
1078 if (argc < (optind + 2))
1079 {
Dave Wallace048b1d62018-01-03 22:24:41 -05001080 fprintf (stderr, "CLIENT: ERROR: Insufficient number of arguments!\n");
Dave Wallace543852a2017-08-03 02:11:34 -04001081 print_usage_and_exit ();
1082 }
1083
1084#ifdef VCL_TEST
1085 ctrl->fd = vppcom_app_create ("vcl_test_client");
1086 if (ctrl->fd < 0)
1087 {
1088 errno = -ctrl->fd;
1089 ctrl->fd = -1;
1090 }
1091 else
1092 {
Dave Wallacede910062018-03-20 09:22:13 -04001093 ctrl->fd = vppcom_session_create (ctrl->cfg.transport_udp ?
1094 VPPCOM_PROTO_UDP :
1095 VPPCOM_PROTO_TCP,
Dave Wallace543852a2017-08-03 02:11:34 -04001096 0 /* is_nonblocking */ );
1097 if (ctrl->fd < 0)
1098 {
1099 errno = -ctrl->fd;
1100 ctrl->fd = -1;
1101 }
1102 }
1103#else
Dave Wallacede910062018-03-20 09:22:13 -04001104 ctrl->fd = socket (ctrl->cfg.address_ip6 ? AF_INET6 : AF_INET,
1105 ctrl->cfg.transport_udp ? SOCK_DGRAM : SOCK_STREAM, 0);
Dave Wallace543852a2017-08-03 02:11:34 -04001106#endif
1107
1108 if (ctrl->fd < 0)
1109 {
1110 errno_val = errno;
1111 perror ("ERROR in main()");
Dave Wallace048b1d62018-01-03 22:24:41 -05001112 fprintf (stderr, "CLIENT: ERROR: socket "
1113 "failed (errno = %d)!\n", errno_val);
Dave Wallace543852a2017-08-03 02:11:34 -04001114 return ctrl->fd;
1115 }
1116
1117 memset (&scm->server_addr, 0, sizeof (scm->server_addr));
Dave Wallacede910062018-03-20 09:22:13 -04001118 if (ctrl->cfg.address_ip6)
1119 {
1120 struct sockaddr_in6 *server_addr =
1121 (struct sockaddr_in6 *) &scm->server_addr;
1122 scm->server_addr_size = sizeof (*server_addr);
1123 server_addr->sin6_family = AF_INET6;
1124 inet_pton (AF_INET6, argv[optind++], &(server_addr->sin6_addr));
1125 server_addr->sin6_port = htons (atoi (argv[optind]));
1126 }
1127 else
1128 {
1129 struct sockaddr_in *server_addr =
1130 (struct sockaddr_in *) &scm->server_addr;
1131 scm->server_addr_size = sizeof (*server_addr);
1132 server_addr->sin_family = AF_INET;
1133 inet_pton (AF_INET, argv[optind++], &(server_addr->sin_addr));
1134 server_addr->sin_port = htons (atoi (argv[optind]));
1135 }
Dave Wallace543852a2017-08-03 02:11:34 -04001136
1137#ifdef VCL_TEST
Dave Wallacede910062018-03-20 09:22:13 -04001138 if (ctrl->cfg.address_ip6)
1139 {
1140 struct sockaddr_in6 *server_addr =
1141 (struct sockaddr_in6 *) &scm->server_addr;
1142 scm->server_endpt.is_ip4 = 0;
1143 scm->server_endpt.ip = (uint8_t *) & server_addr->sin6_addr;
1144 scm->server_endpt.port = (uint16_t) server_addr->sin6_port;
1145 }
1146 else
1147 {
1148 struct sockaddr_in *server_addr =
1149 (struct sockaddr_in *) &scm->server_addr;
1150 scm->server_endpt.is_ip4 = 1;
1151 scm->server_endpt.ip = (uint8_t *) & server_addr->sin_addr;
1152 scm->server_endpt.port = (uint16_t) server_addr->sin_port;
1153 }
Dave Wallace543852a2017-08-03 02:11:34 -04001154#endif
1155
1156 do
1157 {
1158 printf ("\nCLIENT: Connecting to server...\n");
1159
1160#ifdef VCL_TEST
1161 rv = vppcom_session_connect (ctrl->fd, &scm->server_endpt);
Dave Wallaceee45d412017-11-24 21:44:06 -05001162 if (rv)
1163 {
1164 errno = -rv;
1165 rv = -1;
1166 }
Dave Wallace543852a2017-08-03 02:11:34 -04001167#else
1168 rv =
1169 connect (ctrl->fd, (struct sockaddr *) &scm->server_addr,
Dave Wallacede910062018-03-20 09:22:13 -04001170 scm->server_addr_size);
Dave Wallace543852a2017-08-03 02:11:34 -04001171#endif
1172 if (rv < 0)
1173 {
1174 errno_val = errno;
1175 perror ("ERROR in main()");
Dave Wallace048b1d62018-01-03 22:24:41 -05001176 fprintf (stderr, "CLIENT: ERROR: connect failed (errno = %d)!\n",
Dave Wallace543852a2017-08-03 02:11:34 -04001177 errno_val);
Dave Wallaceee45d412017-11-24 21:44:06 -05001178 return -1;
Dave Wallace543852a2017-08-03 02:11:34 -04001179 }
1180
1181 sock_test_cfg_sync (ctrl);
1182 printf ("CLIENT (fd %d): Control socket connected.\n", ctrl->fd);
1183 }
1184 while (rv < 0);
1185
Florin Coras1502fc32018-10-05 00:50:30 -07001186 sock_test_connect_test_sockets (ctrl->cfg.num_test_sessions);
Dave Wallace543852a2017-08-03 02:11:34 -04001187
Florin Coras1502fc32018-10-05 00:50:30 -07001188 while (ctrl->cfg.test != VCL_TEST_TYPE_EXIT)
Dave Wallace543852a2017-08-03 02:11:34 -04001189 {
1190 if (scm->dump_cfg)
1191 {
Florin Coras1502fc32018-10-05 00:50:30 -07001192 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -04001193 scm->dump_cfg = 0;
1194 }
1195
1196 switch (ctrl->cfg.test)
1197 {
Florin Coras1502fc32018-10-05 00:50:30 -07001198 case VCL_TEST_TYPE_ECHO:
Dave Wallace543852a2017-08-03 02:11:34 -04001199 echo_test_client ();
1200 break;
1201
Florin Coras1502fc32018-10-05 00:50:30 -07001202 case VCL_TEST_TYPE_UNI:
1203 case VCL_TEST_TYPE_BI:
Dave Wallace543852a2017-08-03 02:11:34 -04001204 stream_test_client (ctrl->cfg.test);
1205 break;
1206
Florin Coras1502fc32018-10-05 00:50:30 -07001207 case VCL_TEST_TYPE_EXIT:
Dave Wallace543852a2017-08-03 02:11:34 -04001208 continue;
1209
Florin Coras1502fc32018-10-05 00:50:30 -07001210 case VCL_TEST_TYPE_NONE:
Dave Wallace543852a2017-08-03 02:11:34 -04001211 default:
1212 break;
1213 }
1214 switch (post_test)
1215 {
Florin Coras1502fc32018-10-05 00:50:30 -07001216 case VCL_TEST_TYPE_EXIT:
Dave Wallace543852a2017-08-03 02:11:34 -04001217 switch (ctrl->cfg.test)
1218 {
Florin Coras1502fc32018-10-05 00:50:30 -07001219 case VCL_TEST_TYPE_EXIT:
1220 case VCL_TEST_TYPE_UNI:
1221 case VCL_TEST_TYPE_BI:
1222 case VCL_TEST_TYPE_ECHO:
1223 ctrl->cfg.test = VCL_TEST_TYPE_EXIT;
Dave Wallace543852a2017-08-03 02:11:34 -04001224 continue;
1225
Florin Coras1502fc32018-10-05 00:50:30 -07001226 case VCL_TEST_TYPE_NONE:
Dave Wallace543852a2017-08-03 02:11:34 -04001227 default:
1228 break;
1229 }
1230 break;
1231
Florin Coras1502fc32018-10-05 00:50:30 -07001232 case VCL_TEST_TYPE_NONE:
1233 case VCL_TEST_TYPE_ECHO:
1234 case VCL_TEST_TYPE_UNI:
1235 case VCL_TEST_TYPE_BI:
Dave Wallace543852a2017-08-03 02:11:34 -04001236 default:
1237 break;
1238 }
1239
1240 memset (ctrl->txbuf, 0, ctrl->txbuf_size);
1241 memset (ctrl->rxbuf, 0, ctrl->rxbuf_size);
1242
Dave Wallace048b1d62018-01-03 22:24:41 -05001243 printf ("\nCLIENT: Type some characters and hit <return>\n"
Florin Coras1502fc32018-10-05 00:50:30 -07001244 "('" VCL_TEST_TOKEN_HELP "' for help): ");
Dave Wallace543852a2017-08-03 02:11:34 -04001245
1246 if (fgets (ctrl->txbuf, ctrl->txbuf_size, stdin) != NULL)
1247 {
1248 if (strlen (ctrl->txbuf) == 1)
1249 {
1250 printf ("\nCLIENT: Nothing to send! Please try again...\n");
1251 continue;
1252 }
1253 ctrl->txbuf[strlen (ctrl->txbuf) - 1] = 0; // chomp the newline.
1254
1255 /* Parse input for keywords */
1256 ctrl->cfg.test = parse_input ();
1257 }
1258 }
1259
1260 exit_client ();
1261#ifdef VCL_TEST
1262 vppcom_session_close (ctrl->fd);
1263 vppcom_app_destroy ();
Dave Wallace3ee1fe12018-02-23 01:09:11 -05001264 return 0;
Dave Wallace543852a2017-08-03 02:11:34 -04001265#else
1266 close (ctrl->fd);
Dave Wallace3ee1fe12018-02-23 01:09:11 -05001267 return (scm->af_unix_echo_tx == scm->af_unix_echo_rx) ? 0 : -1;
Dave Wallace543852a2017-08-03 02:11:34 -04001268#endif
Dave Wallace543852a2017-08-03 02:11:34 -04001269}
1270
1271/*
1272 * fd.io coding-style-patch-verification: ON
1273 *
1274 * Local Variables:
1275 * eval: (c-set-style "gnu")
1276 * End:
1277 */