blob: 75913d9deda2fcdb4b1ae36051849a36b072eeaf [file] [log] [blame]
Dave Wallace543852a2017-08-03 02:11:34 -04001/*
2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * 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>
Dave Wallace3ee1fe12018-02-23 01:09:11 -050026#ifndef VCL_TEST
27#include <sys/un.h>
28#endif
Dave Wallace543852a2017-08-03 02:11:34 -040029
30typedef struct
31{
32#ifdef VCL_TEST
33 vppcom_endpt_t server_endpt;
Dave Wallace3ee1fe12018-02-23 01:09:11 -050034#else
35 int af_unix_echo_tx;
36 int af_unix_echo_rx;
Dave Wallace543852a2017-08-03 02:11:34 -040037#endif
Dave Wallacede910062018-03-20 09:22:13 -040038 struct sockaddr_storage server_addr;
39 uint32_t server_addr_size;
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070040 uint32_t cfg_seq_num;
Florin Coras1502fc32018-10-05 00:50:30 -070041 vcl_test_session_t ctrl_socket;
42 vcl_test_session_t *test_socket;
Dave Wallace543852a2017-08-03 02:11:34 -040043 uint32_t num_test_sockets;
44 uint8_t dump_cfg;
45} sock_client_main_t;
46
Florin Coras6d4bb422018-09-04 22:07:27 -070047sock_client_main_t vcl_client_main;
Dave Wallace543852a2017-08-03 02:11:34 -040048
49
50static int
Florin Coras1502fc32018-10-05 00:50:30 -070051sock_test_cfg_sync (vcl_test_session_t * socket)
Dave Wallace543852a2017-08-03 02:11:34 -040052{
Florin Coras6d4bb422018-09-04 22:07:27 -070053 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -070054 vcl_test_session_t *ctrl = &scm->ctrl_socket;
55 vcl_test_cfg_t *rl_cfg = (vcl_test_cfg_t *) socket->rxbuf;
Dave Wallace543852a2017-08-03 02:11:34 -040056 int rx_bytes, tx_bytes;
57
58 if (socket->cfg.verbose)
Florin Coras1502fc32018-10-05 00:50:30 -070059 vcl_test_cfg_dump (&socket->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -040060
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070061 ctrl->cfg.seq_num = ++scm->cfg_seq_num;
62 if (socket->cfg.verbose)
63 {
64 printf ("CLIENT (fd %d): Sending config sent to server.\n", socket->fd);
Florin Coras1502fc32018-10-05 00:50:30 -070065 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070066 }
Dave Wallace543852a2017-08-03 02:11:34 -040067 tx_bytes = sock_test_write (socket->fd, (uint8_t *) & ctrl->cfg,
68 sizeof (ctrl->cfg), NULL, ctrl->cfg.verbose);
69 if (tx_bytes < 0)
70 {
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070071 fprintf (stderr, "CLIENT (fd %d): ERROR: write test cfg failed (%d)!\n",
72 socket->fd, tx_bytes);
Dave Wallace543852a2017-08-03 02:11:34 -040073 return tx_bytes;
74 }
75
76 rx_bytes = sock_test_read (socket->fd, (uint8_t *) socket->rxbuf,
Florin Coras1502fc32018-10-05 00:50:30 -070077 sizeof (vcl_test_cfg_t), NULL);
Dave Wallace543852a2017-08-03 02:11:34 -040078 if (rx_bytes < 0)
79 return rx_bytes;
80
Florin Coras1502fc32018-10-05 00:50:30 -070081 if (rl_cfg->magic != VCL_TEST_CFG_CTRL_MAGIC)
Dave Wallace543852a2017-08-03 02:11:34 -040082 {
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070083 fprintf (stderr, "CLIENT (fd %d): ERROR: Bad server reply cfg "
84 "-- aborting!\n", socket->fd);
Dave Wallace543852a2017-08-03 02:11:34 -040085 return -1;
86 }
Florin Coras1502fc32018-10-05 00:50:30 -070087 if ((rx_bytes != sizeof (vcl_test_cfg_t))
88 || !vcl_test_cfg_verify (rl_cfg, &ctrl->cfg))
Dave Wallace543852a2017-08-03 02:11:34 -040089 {
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070090 fprintf (stderr, "CLIENT (fd %d): ERROR: Invalid config received "
91 "from server!\n", socket->fd);
Florin Coras1502fc32018-10-05 00:50:30 -070092 if (rx_bytes != sizeof (vcl_test_cfg_t))
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070093 {
94 fprintf (stderr, "\tRx bytes %d != cfg size %lu\n",
Florin Coras1502fc32018-10-05 00:50:30 -070095 rx_bytes, sizeof (vcl_test_cfg_t));
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -070096 }
97 else
98 {
Florin Coras1502fc32018-10-05 00:50:30 -070099 vcl_test_cfg_dump (rl_cfg, 1 /* is_client */ );
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -0700100 fprintf (stderr, "CLIENT (fd %d): Valid config sent to server.\n",
101 socket->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700102 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -0700103 }
Dave Wallace543852a2017-08-03 02:11:34 -0400104 return -1;
105 }
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -0700106 else if (socket->cfg.verbose)
107 {
108 printf ("CLIENT (fd %d): Got config back from server.\n", socket->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700109 vcl_test_cfg_dump (rl_cfg, 1 /* is_client */ );
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -0700110 }
Dave Wallace543852a2017-08-03 02:11:34 -0400111 ctrl->cfg.ctrl_handle = ((ctrl->cfg.ctrl_handle == ~0) ?
112 rl_cfg->ctrl_handle : ctrl->cfg.ctrl_handle);
113
114 return 0;
115}
116
117static void
118echo_test_client ()
119{
Florin Coras6d4bb422018-09-04 22:07:27 -0700120 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700121 vcl_test_session_t *ctrl = &scm->ctrl_socket;
122 vcl_test_session_t *tsock;
Dave Wallace543852a2017-08-03 02:11:34 -0400123 int rx_bytes, tx_bytes, nbytes;
124 uint32_t i, n;
125 int rv;
126 int nfds = 0;
127 fd_set wr_fdset, rd_fdset;
128 fd_set _wfdset, *wfdset = &_wfdset;
129 fd_set _rfdset, *rfdset = &_rfdset;
130
131 FD_ZERO (&wr_fdset);
132 FD_ZERO (&rd_fdset);
133 memset (&ctrl->stats, 0, sizeof (ctrl->stats));
134 ctrl->cfg.total_bytes = nbytes = strlen (ctrl->txbuf) + 1;
Florin Coras1502fc32018-10-05 00:50:30 -0700135 for (n = 0; n != ctrl->cfg.num_test_sessions; n++)
Dave Wallace543852a2017-08-03 02:11:34 -0400136 {
137 tsock = &scm->test_socket[n];
138 tsock->cfg = ctrl->cfg;
Florin Coras1502fc32018-10-05 00:50:30 -0700139 vcl_test_session_buf_alloc (tsock);
Keith Burns (alagalah)410bcca2018-03-23 13:42:49 -0700140 if (sock_test_cfg_sync (tsock))
141 return;
Dave Wallace543852a2017-08-03 02:11:34 -0400142
143 memcpy (tsock->txbuf, ctrl->txbuf, nbytes);
144 memset (&tsock->stats, 0, sizeof (tsock->stats));
145
146 FD_SET (tsock->fd, &wr_fdset);
147 FD_SET (tsock->fd, &rd_fdset);
148 nfds = ((tsock->fd + 1) > nfds) ? (tsock->fd + 1) : nfds;
149 }
150
151 nfds++;
152 clock_gettime (CLOCK_REALTIME, &ctrl->stats.start);
153 while (n)
154 {
155 _wfdset = wr_fdset;
156 _rfdset = rd_fdset;
157
158#ifdef VCL_TEST
159 rv = vppcom_select (nfds, (uint64_t *) rfdset, (uint64_t *) wfdset,
160 NULL, 0);
161#else
162 {
163 struct timeval timeout;
164 timeout.tv_sec = 0;
165 timeout.tv_usec = 0;
166 rv = select (nfds, rfdset, wfdset, NULL, &timeout);
167 }
168#endif
169 if (rv < 0)
170 {
171 perror ("select()");
Dave Wallace048b1d62018-01-03 22:24:41 -0500172 fprintf (stderr, "\nCLIENT: ERROR: select() failed -- "
173 "aborting test!\n");
Dave Wallace543852a2017-08-03 02:11:34 -0400174 return;
175 }
176 else if (rv == 0)
177 continue;
178
Florin Coras1502fc32018-10-05 00:50:30 -0700179 for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
Dave Wallace543852a2017-08-03 02:11:34 -0400180 {
181 tsock = &scm->test_socket[i];
182 if (!((tsock->stats.stop.tv_sec == 0) &&
183 (tsock->stats.stop.tv_nsec == 0)))
184 continue;
185
186 if (FD_ISSET (tsock->fd, wfdset) &&
187 (tsock->stats.tx_bytes < ctrl->cfg.total_bytes))
188
189 {
190 tx_bytes =
191 sock_test_write (tsock->fd, (uint8_t *) tsock->txbuf, nbytes,
192 &tsock->stats, ctrl->cfg.verbose);
193 if (tx_bytes < 0)
194 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500195 fprintf (stderr, "\nCLIENT: ERROR: sock_test_write(%d) "
196 "failed -- aborting test!\n", tsock->fd);
Dave Wallace543852a2017-08-03 02:11:34 -0400197 return;
198 }
199
200 printf ("CLIENT (fd %d): TX (%d bytes) - '%s'\n",
201 tsock->fd, tx_bytes, tsock->txbuf);
202 }
203
204 if ((FD_ISSET (tsock->fd, rfdset)) &&
205 (tsock->stats.rx_bytes < ctrl->cfg.total_bytes))
206 {
207 rx_bytes =
208 sock_test_read (tsock->fd, (uint8_t *) tsock->rxbuf,
209 nbytes, &tsock->stats);
210 if (rx_bytes > 0)
211 {
212 printf ("CLIENT (fd %d): RX (%d bytes) - '%s'\n",
213 tsock->fd, rx_bytes, tsock->rxbuf);
214
215 if (tsock->stats.rx_bytes != tsock->stats.tx_bytes)
Dave Wallace048b1d62018-01-03 22:24:41 -0500216 printf ("CLIENT: WARNING: bytes read (%lu) "
217 "!= bytes written (%lu)!\n",
218 tsock->stats.rx_bytes, tsock->stats.tx_bytes);
Dave Wallace543852a2017-08-03 02:11:34 -0400219 }
220 }
221
222 if (tsock->stats.rx_bytes >= ctrl->cfg.total_bytes)
223 {
224 clock_gettime (CLOCK_REALTIME, &tsock->stats.stop);
225 n--;
226 }
227 }
228 }
229 clock_gettime (CLOCK_REALTIME, &ctrl->stats.stop);
230
Dave Wallace3ee1fe12018-02-23 01:09:11 -0500231#ifndef VCL_TEST
232 {
233 int fd, errno_val;
234 struct sockaddr_un serveraddr;
235 uint8_t buffer[256];
236 size_t nbytes = strlen (SOCK_TEST_MIXED_EPOLL_DATA) + 1;
237 struct timeval timeout;
238
239 /* Open AF_UNIX socket and send an echo to test mixed epoll on server.
240 */
241 fd = socket (AF_UNIX, SOCK_STREAM, 0);
242 if (fd < 0)
243 {
244 errno_val = errno;
245 perror ("ERROR in echo_test_client(): socket(AF_UNIX) failed");
246 fprintf (stderr,
247 "CLIENT: ERROR: socket(AF_UNIX, SOCK_STREAM, 0) failed "
248 "(errno = %d)!\n", errno_val);
249 goto out;
250 }
251 memset (&serveraddr, 0, sizeof (serveraddr));
252 serveraddr.sun_family = AF_UNIX;
253 strcpy (serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME);
254 rv = connect (fd, (struct sockaddr *) &serveraddr, SUN_LEN (&serveraddr));
255 if (rv < 0)
256 {
257 errno_val = errno;
258 perror ("ERROR in echo_test_client(): connect() failed");
259 fprintf (stderr, "CLIENT: ERROR: connect(fd %d, \"%s\", %lu) "
260 "failed (errno = %d)!\n", fd, SOCK_TEST_AF_UNIX_FILENAME,
261 SUN_LEN (&serveraddr), errno_val);
262 goto done;
263 }
264
265 scm->af_unix_echo_tx++;
266 strcpy ((char *) buffer, SOCK_TEST_MIXED_EPOLL_DATA);
267 timeout.tv_sec = 0;
268 timeout.tv_usec = 250000;
269 select (0, NULL, NULL, NULL, &timeout); /* delay .25 secs */
270 rv = write (fd, buffer, nbytes);
271 if (rv < 0)
272 {
273 errno_val = errno;
274 perror ("ERROR in echo_test_client(): write() failed");
275 fprintf (stderr, "CLIENT: ERROR: write(fd %d, \"%s\", %lu) "
276 "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val);
277 goto done;
278 }
279 else if (rv < nbytes)
280 {
281 fprintf (stderr, "CLIENT: ERROR: write(fd %d, \"%s\", %lu) "
282 "returned %d!\n", fd, buffer, nbytes, rv);
283 goto done;
284 }
285
286 printf ("CLIENT (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer);
287 memset (buffer, 0, sizeof (buffer));
288 rv = read (fd, buffer, nbytes);
289 if (rv < 0)
290 {
291 errno_val = errno;
292 perror ("ERROR in echo_test_client(): read() failed");
293 fprintf (stderr, "CLIENT: ERROR: read(fd %d, %p, %lu) "
294 "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val);
295 goto done;
296 }
297 else if (rv < nbytes)
298 {
299 fprintf (stderr, "CLIENT: ERROR: read(fd %d, %p, %lu) "
300 "returned %d!\n", fd, buffer, nbytes, rv);
301 goto done;
302 }
303
304 if (!strncmp (SOCK_TEST_MIXED_EPOLL_DATA, (const char *) buffer, nbytes))
305 {
306 printf ("CLIENT (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer);
307 scm->af_unix_echo_rx++;
308 }
309 else
310 printf ("CLIENT (AF_UNIX): ERROR: RX (%d bytes) - '%s'\n", rv, buffer);
311
312 done:
313 close (fd);
314 out:
315 ;
316 }
317#endif
318
Florin Coras1502fc32018-10-05 00:50:30 -0700319 for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
Dave Wallace543852a2017-08-03 02:11:34 -0400320 {
321 tsock = &scm->test_socket[i];
322 tsock->stats.start = ctrl->stats.start;
323
324 if (ctrl->cfg.verbose)
325 {
326 static char buf[64];
327
328 sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700329 vcl_test_stats_dump (buf, &tsock->stats,
330 1 /* show_rx */ , 1 /* show tx */ ,
331 ctrl->cfg.verbose);
Dave Wallace543852a2017-08-03 02:11:34 -0400332 }
333
Florin Coras1502fc32018-10-05 00:50:30 -0700334 vcl_test_stats_accumulate (&ctrl->stats, &tsock->stats);
Dave Wallace543852a2017-08-03 02:11:34 -0400335 }
336
337 if (ctrl->cfg.verbose)
338 {
Florin Coras1502fc32018-10-05 00:50:30 -0700339 vcl_test_stats_dump ("CLIENT RESULTS", &ctrl->stats,
340 1 /* show_rx */ , 1 /* show tx */ ,
341 ctrl->cfg.verbose);
342 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400343
344 if (ctrl->cfg.verbose > 1)
345 {
346 printf (" ctrl socket info\n"
Florin Coras1502fc32018-10-05 00:50:30 -0700347 VCL_TEST_SEPARATOR_STRING
Dave Wallace543852a2017-08-03 02:11:34 -0400348 " fd: %d (0x%08x)\n"
349 " rxbuf: %p\n"
350 " rxbuf size: %u (0x%08x)\n"
351 " txbuf: %p\n"
352 " txbuf size: %u (0x%08x)\n"
Florin Coras1502fc32018-10-05 00:50:30 -0700353 VCL_TEST_SEPARATOR_STRING,
Dave Wallace543852a2017-08-03 02:11:34 -0400354 ctrl->fd, (uint32_t) ctrl->fd,
355 ctrl->rxbuf, ctrl->rxbuf_size, ctrl->rxbuf_size,
356 ctrl->txbuf, ctrl->txbuf_size, ctrl->txbuf_size);
357 }
358 }
359}
360
361static void
Florin Coras1502fc32018-10-05 00:50:30 -0700362stream_test_client (vcl_test_t test)
Dave Wallace543852a2017-08-03 02:11:34 -0400363{
Florin Coras6d4bb422018-09-04 22:07:27 -0700364 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700365 vcl_test_session_t *ctrl = &scm->ctrl_socket;
366 vcl_test_session_t *tsock;
Dave Wallace543852a2017-08-03 02:11:34 -0400367 int tx_bytes;
368 uint32_t i, n;
369 int rv;
370 int nfds = 0;
371 fd_set wr_fdset, rd_fdset;
372 fd_set _wfdset, *wfdset = &_wfdset;
Florin Coras1502fc32018-10-05 00:50:30 -0700373 fd_set _rfdset, *rfdset = (test == VCL_TEST_TYPE_BI) ? &_rfdset : 0;
Dave Wallace543852a2017-08-03 02:11:34 -0400374
375 ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
376 ctrl->cfg.ctrl_handle = ~0;
377
378 printf ("\n" SOCK_TEST_BANNER_STRING
379 "CLIENT (fd %d): %s-directional Stream Test!\n\n"
380 "CLIENT (fd %d): Sending config to server on ctrl socket...\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700381 ctrl->fd, test == VCL_TEST_TYPE_BI ? "Bi" : "Uni", ctrl->fd);
Dave Wallace543852a2017-08-03 02:11:34 -0400382
383 if (sock_test_cfg_sync (ctrl))
384 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500385 fprintf (stderr, "CLIENT: ERROR: test cfg sync failed -- aborting!");
Dave Wallace543852a2017-08-03 02:11:34 -0400386 return;
387 }
388
389 FD_ZERO (&wr_fdset);
390 FD_ZERO (&rd_fdset);
391 memset (&ctrl->stats, 0, sizeof (ctrl->stats));
Florin Coras1502fc32018-10-05 00:50:30 -0700392 for (n = 0; n != ctrl->cfg.num_test_sessions; n++)
Dave Wallace543852a2017-08-03 02:11:34 -0400393 {
394 tsock = &scm->test_socket[n];
395 tsock->cfg = ctrl->cfg;
Florin Coras1502fc32018-10-05 00:50:30 -0700396 vcl_test_session_buf_alloc (tsock);
Dave Wallace543852a2017-08-03 02:11:34 -0400397 printf ("CLIENT (fd %d): Sending config to server on "
398 "test socket %d...\n", tsock->fd, n);
399 sock_test_cfg_sync (tsock);
400
401 /* Fill payload with incrementing uint32's */
402 for (i = 0; i < tsock->txbuf_size; i++)
403 tsock->txbuf[i] = i & 0xff;
404
405 memset (&tsock->stats, 0, sizeof (tsock->stats));
406 FD_SET (tsock->fd, &wr_fdset);
407 FD_SET (tsock->fd, &rd_fdset);
408 nfds = ((tsock->fd + 1) > nfds) ? (tsock->fd + 1) : nfds;
409 }
410
411 nfds++;
412 clock_gettime (CLOCK_REALTIME, &ctrl->stats.start);
413 while (n)
414 {
415 _wfdset = wr_fdset;
416 _rfdset = rd_fdset;
417
418#ifdef VCL_TEST
419 rv = vppcom_select (nfds, (uint64_t *) rfdset, (uint64_t *) wfdset,
420 NULL, 0);
421#else
422 {
423 struct timeval timeout;
424 timeout.tv_sec = 0;
425 timeout.tv_usec = 0;
426 rv = select (nfds, rfdset, wfdset, NULL, &timeout);
427 }
428#endif
429 if (rv < 0)
430 {
431 perror ("select()");
Dave Wallace048b1d62018-01-03 22:24:41 -0500432 fprintf (stderr, "\nCLIENT: ERROR: select() failed -- "
433 "aborting test!\n");
Dave Wallace543852a2017-08-03 02:11:34 -0400434 return;
435 }
436 else if (rv == 0)
437 continue;
438
Florin Coras1502fc32018-10-05 00:50:30 -0700439 for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
Dave Wallace543852a2017-08-03 02:11:34 -0400440 {
441 tsock = &scm->test_socket[i];
442 if (!((tsock->stats.stop.tv_sec == 0) &&
443 (tsock->stats.stop.tv_nsec == 0)))
444 continue;
445
Florin Coras1502fc32018-10-05 00:50:30 -0700446 if ((test == VCL_TEST_TYPE_BI) &&
Dave Wallace048b1d62018-01-03 22:24:41 -0500447 FD_ISSET (tsock->fd, rfdset) &&
448 (tsock->stats.rx_bytes < ctrl->cfg.total_bytes))
449 {
450 (void) sock_test_read (tsock->fd,
451 (uint8_t *) tsock->rxbuf,
452 tsock->rxbuf_size, &tsock->stats);
453 }
454
Dave Wallace543852a2017-08-03 02:11:34 -0400455 if (FD_ISSET (tsock->fd, wfdset) &&
456 (tsock->stats.tx_bytes < ctrl->cfg.total_bytes))
457 {
Florin Coras54693d22018-07-17 10:46:29 -0700458 tx_bytes = sock_test_write (tsock->fd, (uint8_t *) tsock->txbuf,
459 ctrl->cfg.txbuf_size, &tsock->stats,
460 ctrl->cfg.verbose);
Dave Wallace543852a2017-08-03 02:11:34 -0400461 if (tx_bytes < 0)
462 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500463 fprintf (stderr, "\nCLIENT: ERROR: sock_test_write(%d) "
464 "failed -- aborting test!\n", tsock->fd);
Dave Wallace543852a2017-08-03 02:11:34 -0400465 return;
466 }
467 }
468
Florin Coras1502fc32018-10-05 00:50:30 -0700469 if (((test == VCL_TEST_TYPE_UNI) &&
Dave Wallace543852a2017-08-03 02:11:34 -0400470 (tsock->stats.tx_bytes >= ctrl->cfg.total_bytes)) ||
Florin Coras1502fc32018-10-05 00:50:30 -0700471 ((test == VCL_TEST_TYPE_BI) &&
Dave Wallace543852a2017-08-03 02:11:34 -0400472 (tsock->stats.rx_bytes >= ctrl->cfg.total_bytes)))
473 {
474 clock_gettime (CLOCK_REALTIME, &tsock->stats.stop);
475 n--;
476 }
477 }
478 }
479 clock_gettime (CLOCK_REALTIME, &ctrl->stats.stop);
480
481 printf ("CLIENT (fd %d): Sending config to server on ctrl socket...\n",
482 ctrl->fd);
483
484 if (sock_test_cfg_sync (ctrl))
485 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500486 fprintf (stderr, "CLIENT: ERROR: test cfg sync failed -- aborting!");
Dave Wallace543852a2017-08-03 02:11:34 -0400487 return;
488 }
489
Florin Coras1502fc32018-10-05 00:50:30 -0700490 for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
Dave Wallace543852a2017-08-03 02:11:34 -0400491 {
492 tsock = &scm->test_socket[i];
493
494 if (ctrl->cfg.verbose)
495 {
496 static char buf[64];
497
498 sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700499 vcl_test_stats_dump (buf, &tsock->stats,
500 test == VCL_TEST_TYPE_BI /* show_rx */ ,
501 1 /* show tx */ , ctrl->cfg.verbose);
Dave Wallace543852a2017-08-03 02:11:34 -0400502 }
503
Florin Coras1502fc32018-10-05 00:50:30 -0700504 vcl_test_stats_accumulate (&ctrl->stats, &tsock->stats);
Dave Wallace543852a2017-08-03 02:11:34 -0400505 }
506
Florin Coras1502fc32018-10-05 00:50:30 -0700507 vcl_test_stats_dump ("CLIENT RESULTS", &ctrl->stats,
508 test == VCL_TEST_TYPE_BI /* show_rx */ ,
509 1 /* show tx */ , ctrl->cfg.verbose);
510 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400511
512 if (ctrl->cfg.verbose)
513 {
514 printf (" ctrl socket info\n"
Florin Coras1502fc32018-10-05 00:50:30 -0700515 VCL_TEST_SEPARATOR_STRING
Dave Wallace543852a2017-08-03 02:11:34 -0400516 " fd: %d (0x%08x)\n"
517 " rxbuf: %p\n"
518 " rxbuf size: %u (0x%08x)\n"
519 " txbuf: %p\n"
520 " txbuf size: %u (0x%08x)\n"
Florin Coras1502fc32018-10-05 00:50:30 -0700521 VCL_TEST_SEPARATOR_STRING,
Dave Wallace543852a2017-08-03 02:11:34 -0400522 ctrl->fd, (uint32_t) ctrl->fd,
523 ctrl->rxbuf, ctrl->rxbuf_size, ctrl->rxbuf_size,
524 ctrl->txbuf, ctrl->txbuf_size, ctrl->txbuf_size);
525 }
526
Florin Coras1502fc32018-10-05 00:50:30 -0700527 ctrl->cfg.test = VCL_TEST_TYPE_ECHO;
Dave Wallace543852a2017-08-03 02:11:34 -0400528 if (sock_test_cfg_sync (ctrl))
Dave Wallace048b1d62018-01-03 22:24:41 -0500529 fprintf (stderr, "CLIENT: ERROR: post-test cfg sync failed!");
Dave Wallace543852a2017-08-03 02:11:34 -0400530
531 printf ("CLIENT (fd %d): %s-directional Stream Test Complete!\n"
532 SOCK_TEST_BANNER_STRING "\n", ctrl->fd,
Florin Coras1502fc32018-10-05 00:50:30 -0700533 test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
Dave Wallace543852a2017-08-03 02:11:34 -0400534}
535
536static void
537exit_client (void)
538{
Florin Coras6d4bb422018-09-04 22:07:27 -0700539 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700540 vcl_test_session_t *ctrl = &scm->ctrl_socket;
541 vcl_test_session_t *tsock;
Dave Wallace543852a2017-08-03 02:11:34 -0400542 int i;
543
Dave Wallace3ee1fe12018-02-23 01:09:11 -0500544#ifndef VCL_TEST
545 printf ("CLIENT: af_unix_echo_tx %d, af_unix_echo_rx %d\n",
546 scm->af_unix_echo_tx, scm->af_unix_echo_rx);
547#endif
Florin Coras1502fc32018-10-05 00:50:30 -0700548 for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
Dave Wallace543852a2017-08-03 02:11:34 -0400549 {
550 tsock = &scm->test_socket[i];
Florin Coras1502fc32018-10-05 00:50:30 -0700551 tsock->cfg.test = VCL_TEST_TYPE_EXIT;
Dave Wallace543852a2017-08-03 02:11:34 -0400552
Chris Lukeb2bcad62017-09-18 08:51:22 -0400553 /* coverity[COPY_PASTE_ERROR] */
Dave Wallace543852a2017-08-03 02:11:34 -0400554 if (ctrl->cfg.verbose)
555 {
556 printf ("\nCLIENT (fd %d): Sending exit cfg to server...\n",
557 tsock->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700558 vcl_test_cfg_dump (&tsock->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400559 }
560 (void) sock_test_write (tsock->fd, (uint8_t *) & tsock->cfg,
561 sizeof (tsock->cfg), &tsock->stats,
562 ctrl->cfg.verbose);
563 }
564
Florin Coras1502fc32018-10-05 00:50:30 -0700565 ctrl->cfg.test = VCL_TEST_TYPE_EXIT;
Dave Wallace543852a2017-08-03 02:11:34 -0400566 if (ctrl->cfg.verbose)
567 {
568 printf ("\nCLIENT (fd %d): Sending exit cfg to server...\n", ctrl->fd);
Florin Coras1502fc32018-10-05 00:50:30 -0700569 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400570 }
571 (void) sock_test_write (ctrl->fd, (uint8_t *) & ctrl->cfg,
572 sizeof (ctrl->cfg), &ctrl->stats,
573 ctrl->cfg.verbose);
574 printf ("\nCLIENT: So long and thanks for all the fish!\n\n");
575 sleep (1);
576}
577
578static int
579sock_test_connect_test_sockets (uint32_t num_test_sockets)
580{
Florin Coras6d4bb422018-09-04 22:07:27 -0700581 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700582 vcl_test_session_t *ctrl = &scm->ctrl_socket;
583 vcl_test_session_t *tsock;
Dave Wallace543852a2017-08-03 02:11:34 -0400584 int i, rv, errno_val;
585
586 if (num_test_sockets < 1)
587 {
588 errno = EINVAL;
589 return -1;
590 }
591
592 if (num_test_sockets < scm->num_test_sockets)
593 {
594 for (i = scm->num_test_sockets - 1; i >= num_test_sockets; i--)
595 {
596 tsock = &scm->test_socket[i];
597#ifdef VCL_TEST
598 vppcom_session_close (tsock->fd);
599#else
600 close (tsock->fd);
601#endif
602 free (tsock->txbuf);
603 free (tsock->rxbuf);
604 }
605 }
606
607 else if (num_test_sockets > scm->num_test_sockets)
608 {
609 tsock = realloc (scm->test_socket,
Florin Coras1502fc32018-10-05 00:50:30 -0700610 sizeof (vcl_test_session_t) * num_test_sockets);
Dave Wallace543852a2017-08-03 02:11:34 -0400611 if (!tsock)
612 {
613 errno_val = errno;
614 perror ("ERROR in sock_test_connect_test_sockets()");
Dave Wallace048b1d62018-01-03 22:24:41 -0500615 fprintf (stderr, "CLIENT: ERROR: socket failed (errno = %d)!\n",
616 errno_val);
Dave Wallace543852a2017-08-03 02:11:34 -0400617 return -1;
618 }
619
Dave Wallaced48e9762017-08-22 23:29:33 -0400620 if (!scm->test_socket)
621 memset (tsock, 0, sizeof (*tsock));
622
Dave Wallace543852a2017-08-03 02:11:34 -0400623 scm->test_socket = tsock;
624 for (i = scm->num_test_sockets; i < num_test_sockets; i++)
625 {
626 tsock = &scm->test_socket[i];
627#ifdef VCL_TEST
Dave Wallacede910062018-03-20 09:22:13 -0400628 tsock->fd = vppcom_session_create (ctrl->cfg.transport_udp ?
629 VPPCOM_PROTO_UDP :
630 VPPCOM_PROTO_TCP,
631 1 /* is_nonblocking */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400632 if (tsock->fd < 0)
633 {
634 errno = -tsock->fd;
635 tsock->fd = -1;
636 }
637#else
Dave Wallacede910062018-03-20 09:22:13 -0400638 tsock->fd = socket (ctrl->cfg.address_ip6 ? AF_INET6 : AF_INET,
639 ctrl->cfg.transport_udp ?
640 SOCK_DGRAM : SOCK_STREAM, 0);
Dave Wallace543852a2017-08-03 02:11:34 -0400641#endif
642 if (tsock->fd < 0)
643 {
644 errno_val = errno;
645 perror ("ERROR in sock_test_connect_test_sockets()");
Dave Wallace048b1d62018-01-03 22:24:41 -0500646 fprintf (stderr, "CLIENT: ERROR: socket failed (errno = %d)!\n",
Dave Wallace543852a2017-08-03 02:11:34 -0400647 errno_val);
648 return tsock->fd;
649 }
650
651#ifdef VCL_TEST
652 rv = vppcom_session_connect (tsock->fd, &scm->server_endpt);
Dave Wallaceee45d412017-11-24 21:44:06 -0500653 if (rv)
654 {
655 errno = -rv;
656 rv = -1;
657 }
Dave Wallace543852a2017-08-03 02:11:34 -0400658#else
659 rv =
660 connect (tsock->fd, (struct sockaddr *) &scm->server_addr,
Dave Wallacede910062018-03-20 09:22:13 -0400661 scm->server_addr_size);
Dave Wallace543852a2017-08-03 02:11:34 -0400662#endif
663 if (rv < 0)
664 {
665 errno_val = errno;
Dave Wallaceee45d412017-11-24 21:44:06 -0500666 perror ("ERROR in sock_test_connect_test_sockets()");
Dave Wallace048b1d62018-01-03 22:24:41 -0500667 fprintf (stderr, "CLIENT: ERROR: connect failed "
668 "(errno = %d)!\n", errno_val);
Dave Wallaceee45d412017-11-24 21:44:06 -0500669 return -1;
Dave Wallace543852a2017-08-03 02:11:34 -0400670 }
671 tsock->cfg = ctrl->cfg;
Florin Coras1502fc32018-10-05 00:50:30 -0700672 vcl_test_session_buf_alloc (tsock);
Dave Wallace543852a2017-08-03 02:11:34 -0400673 sock_test_cfg_sync (tsock);
674
675 printf ("CLIENT (fd %d): Test socket %d connected.\n",
676 tsock->fd, i);
677 }
678 }
679
680 scm->num_test_sockets = num_test_sockets;
681 printf ("CLIENT: All sockets (%d) connected!\n", scm->num_test_sockets + 1);
682 return 0;
683}
684
685static void
686dump_help (void)
687{
688#define INDENT "\n "
689
Dave Wallace048b1d62018-01-03 22:24:41 -0500690 printf ("CLIENT: Test configuration commands:"
Florin Coras1502fc32018-10-05 00:50:30 -0700691 INDENT VCL_TEST_TOKEN_HELP
Dave Wallace543852a2017-08-03 02:11:34 -0400692 "\t\t\tDisplay help."
Florin Coras1502fc32018-10-05 00:50:30 -0700693 INDENT VCL_TEST_TOKEN_EXIT
Dave Wallace543852a2017-08-03 02:11:34 -0400694 "\t\t\tExit test client & server."
Florin Coras1502fc32018-10-05 00:50:30 -0700695 INDENT VCL_TEST_TOKEN_SHOW_CFG
Dave Wallace543852a2017-08-03 02:11:34 -0400696 "\t\t\tShow the current test cfg."
Florin Coras1502fc32018-10-05 00:50:30 -0700697 INDENT VCL_TEST_TOKEN_RUN_UNI
Dave Wallace543852a2017-08-03 02:11:34 -0400698 "\t\t\tRun the Uni-directional test."
Florin Coras1502fc32018-10-05 00:50:30 -0700699 INDENT VCL_TEST_TOKEN_RUN_BI
Dave Wallace543852a2017-08-03 02:11:34 -0400700 "\t\t\tRun the Bi-directional test."
Florin Coras1502fc32018-10-05 00:50:30 -0700701 INDENT VCL_TEST_TOKEN_VERBOSE
Dave Wallace543852a2017-08-03 02:11:34 -0400702 "\t\t\tToggle verbose setting."
Florin Coras1502fc32018-10-05 00:50:30 -0700703 INDENT VCL_TEST_TOKEN_RXBUF_SIZE
Dave Wallace543852a2017-08-03 02:11:34 -0400704 "<rxbuf size>\tRx buffer size (bytes)."
Florin Coras1502fc32018-10-05 00:50:30 -0700705 INDENT VCL_TEST_TOKEN_TXBUF_SIZE
Dave Wallace543852a2017-08-03 02:11:34 -0400706 "<txbuf size>\tTx buffer size (bytes)."
Florin Coras1502fc32018-10-05 00:50:30 -0700707 INDENT VCL_TEST_TOKEN_NUM_WRITES
Dave Wallace543852a2017-08-03 02:11:34 -0400708 "<# of writes>\tNumber of txbuf writes to server." "\n");
709}
710
711static void
712cfg_txbuf_size_set (void)
713{
Florin Coras6d4bb422018-09-04 22:07:27 -0700714 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700715 vcl_test_session_t *ctrl = &scm->ctrl_socket;
716 char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_TXBUF_SIZE);
Dave Wallace543852a2017-08-03 02:11:34 -0400717 uint64_t txbuf_size = strtoull ((const char *) p, NULL, 10);
718
Florin Coras1502fc32018-10-05 00:50:30 -0700719 if (txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
Dave Wallace543852a2017-08-03 02:11:34 -0400720 {
721 ctrl->cfg.txbuf_size = txbuf_size;
722 ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
Florin Coras1502fc32018-10-05 00:50:30 -0700723 vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
724 (uint8_t **) & ctrl->txbuf, &ctrl->txbuf_size);
725 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400726 }
727 else
Dave Wallace048b1d62018-01-03 22:24:41 -0500728 fprintf (stderr, "CLIENT: ERROR: Invalid txbuf size (%lu) < "
729 "minimum buf size (%u)!\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700730 txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
Dave Wallace543852a2017-08-03 02:11:34 -0400731}
732
733static void
734cfg_num_writes_set (void)
735{
Florin Coras6d4bb422018-09-04 22:07:27 -0700736 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700737 vcl_test_session_t *ctrl = &scm->ctrl_socket;
738 char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_WRITES);
Dave Wallace543852a2017-08-03 02:11:34 -0400739 uint32_t num_writes = strtoul ((const char *) p, NULL, 10);
740
741 if (num_writes > 0)
742 {
743 ctrl->cfg.num_writes = num_writes;
744 ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
Florin Coras1502fc32018-10-05 00:50:30 -0700745 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400746 }
747 else
748 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500749 fprintf (stderr, "CLIENT: ERROR: invalid num writes: %u\n", num_writes);
Dave Wallace543852a2017-08-03 02:11:34 -0400750 }
751}
752
753static void
754cfg_num_test_sockets_set (void)
755{
Florin Coras6d4bb422018-09-04 22:07:27 -0700756 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700757 vcl_test_session_t *ctrl = &scm->ctrl_socket;
758 char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_TEST_SESS);
Dave Wallace543852a2017-08-03 02:11:34 -0400759 uint32_t num_test_sockets = strtoul ((const char *) p, NULL, 10);
760
761 if ((num_test_sockets > 0) &&
Florin Coras1502fc32018-10-05 00:50:30 -0700762 (num_test_sockets <= VCL_TEST_CFG_MAX_TEST_SESS))
Dave Wallace543852a2017-08-03 02:11:34 -0400763 {
Florin Coras1502fc32018-10-05 00:50:30 -0700764 ctrl->cfg.num_test_sessions = num_test_sockets;
Dave Wallace543852a2017-08-03 02:11:34 -0400765 sock_test_connect_test_sockets (num_test_sockets);
Dave Wallaceee45d412017-11-24 21:44:06 -0500766
Florin Coras1502fc32018-10-05 00:50:30 -0700767 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400768 }
769 else
770 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500771 fprintf (stderr, "CLIENT: ERROR: invalid num test sockets: "
772 "%u, (%d max)\n",
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 }
775}
776
777static void
778cfg_rxbuf_size_set (void)
779{
Florin Coras6d4bb422018-09-04 22:07:27 -0700780 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700781 vcl_test_session_t *ctrl = &scm->ctrl_socket;
782 char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_RXBUF_SIZE);
Dave Wallace543852a2017-08-03 02:11:34 -0400783 uint64_t rxbuf_size = strtoull ((const char *) p, NULL, 10);
784
Florin Coras1502fc32018-10-05 00:50:30 -0700785 if (rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
Dave Wallace543852a2017-08-03 02:11:34 -0400786 {
787 ctrl->cfg.rxbuf_size = rxbuf_size;
Florin Coras1502fc32018-10-05 00:50:30 -0700788 vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
789 (uint8_t **) & ctrl->rxbuf, &ctrl->rxbuf_size);
790 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400791 }
792 else
Dave Wallace048b1d62018-01-03 22:24:41 -0500793 fprintf (stderr, "CLIENT: ERROR: Invalid rxbuf size (%lu) < "
794 "minimum buf size (%u)!\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700795 rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
Dave Wallace543852a2017-08-03 02:11:34 -0400796}
797
798static void
799cfg_verbose_toggle (void)
800{
Florin Coras6d4bb422018-09-04 22:07:27 -0700801 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700802 vcl_test_session_t *ctrl = &scm->ctrl_socket;
Dave Wallace543852a2017-08-03 02:11:34 -0400803
804 ctrl->cfg.verbose = ctrl->cfg.verbose ? 0 : 1;
Florin Coras1502fc32018-10-05 00:50:30 -0700805 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -0400806
807}
808
Florin Coras1502fc32018-10-05 00:50:30 -0700809static vcl_test_t
Dave Wallace543852a2017-08-03 02:11:34 -0400810parse_input ()
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;
814 vcl_test_t rv = VCL_TEST_TYPE_NONE;
Dave Wallace543852a2017-08-03 02:11:34 -0400815
Florin Coras1502fc32018-10-05 00:50:30 -0700816 if (!strncmp (VCL_TEST_TOKEN_EXIT, ctrl->txbuf,
817 strlen (VCL_TEST_TOKEN_EXIT)))
818 rv = VCL_TEST_TYPE_EXIT;
Dave Wallace543852a2017-08-03 02:11:34 -0400819
Florin Coras1502fc32018-10-05 00:50:30 -0700820 else if (!strncmp (VCL_TEST_TOKEN_HELP, ctrl->txbuf,
821 strlen (VCL_TEST_TOKEN_HELP)))
Dave Wallace543852a2017-08-03 02:11:34 -0400822 dump_help ();
823
Florin Coras1502fc32018-10-05 00:50:30 -0700824 else if (!strncmp (VCL_TEST_TOKEN_SHOW_CFG, ctrl->txbuf,
825 strlen (VCL_TEST_TOKEN_SHOW_CFG)))
Dave Wallace543852a2017-08-03 02:11:34 -0400826 scm->dump_cfg = 1;
827
Florin Coras1502fc32018-10-05 00:50:30 -0700828 else if (!strncmp (VCL_TEST_TOKEN_VERBOSE, ctrl->txbuf,
829 strlen (VCL_TEST_TOKEN_VERBOSE)))
Dave Wallace543852a2017-08-03 02:11:34 -0400830 cfg_verbose_toggle ();
831
Florin Coras1502fc32018-10-05 00:50:30 -0700832 else if (!strncmp (VCL_TEST_TOKEN_TXBUF_SIZE, ctrl->txbuf,
833 strlen (VCL_TEST_TOKEN_TXBUF_SIZE)))
Dave Wallace543852a2017-08-03 02:11:34 -0400834 cfg_txbuf_size_set ();
835
Florin Coras1502fc32018-10-05 00:50:30 -0700836 else if (!strncmp (VCL_TEST_TOKEN_NUM_TEST_SESS, ctrl->txbuf,
837 strlen (VCL_TEST_TOKEN_NUM_TEST_SESS)))
Dave Wallace543852a2017-08-03 02:11:34 -0400838 cfg_num_test_sockets_set ();
839
Florin Coras1502fc32018-10-05 00:50:30 -0700840 else if (!strncmp (VCL_TEST_TOKEN_NUM_WRITES, ctrl->txbuf,
841 strlen (VCL_TEST_TOKEN_NUM_WRITES)))
Dave Wallace543852a2017-08-03 02:11:34 -0400842 cfg_num_writes_set ();
843
Florin Coras1502fc32018-10-05 00:50:30 -0700844 else if (!strncmp (VCL_TEST_TOKEN_RXBUF_SIZE, ctrl->txbuf,
845 strlen (VCL_TEST_TOKEN_RXBUF_SIZE)))
Dave Wallace543852a2017-08-03 02:11:34 -0400846 cfg_rxbuf_size_set ();
847
Florin Coras1502fc32018-10-05 00:50:30 -0700848 else if (!strncmp (VCL_TEST_TOKEN_RUN_UNI, ctrl->txbuf,
849 strlen (VCL_TEST_TOKEN_RUN_UNI)))
850 rv = ctrl->cfg.test = VCL_TEST_TYPE_UNI;
Dave Wallace543852a2017-08-03 02:11:34 -0400851
Florin Coras1502fc32018-10-05 00:50:30 -0700852 else if (!strncmp (VCL_TEST_TOKEN_RUN_BI, ctrl->txbuf,
853 strlen (VCL_TEST_TOKEN_RUN_BI)))
854 rv = ctrl->cfg.test = VCL_TEST_TYPE_BI;
Dave Wallace543852a2017-08-03 02:11:34 -0400855
856 else
Florin Coras1502fc32018-10-05 00:50:30 -0700857 rv = VCL_TEST_TYPE_ECHO;
Dave Wallace543852a2017-08-03 02:11:34 -0400858
859 return rv;
860}
861
862void
863print_usage_and_exit (void)
864{
865 fprintf (stderr,
866 "sock_test_client [OPTIONS] <ipaddr> <port>\n"
867 " OPTIONS\n"
868 " -h Print this message and exit.\n"
Dave Wallacede910062018-03-20 09:22:13 -0400869 " -6 Use IPv6\n"
870 " -u Use UDP transport layer\n"
Dave Wallace543852a2017-08-03 02:11:34 -0400871 " -c Print test config before test.\n"
872 " -w <dir> Write test results to <dir>.\n"
873 " -X Exit after running test.\n"
874 " -E Run Echo test.\n"
875 " -N <num-writes> Test Cfg: number of writes.\n"
876 " -R <rxbuf-size> Test Cfg: rx buffer size.\n"
877 " -T <txbuf-size> Test Cfg: tx buffer size.\n"
878 " -U Run Uni-directional test.\n"
879 " -B Run Bi-directional test.\n"
880 " -V Verbose mode.\n");
881 exit (1);
882}
883
884int
885main (int argc, char **argv)
886{
Florin Coras6d4bb422018-09-04 22:07:27 -0700887 sock_client_main_t *scm = &vcl_client_main;
Florin Coras1502fc32018-10-05 00:50:30 -0700888 vcl_test_session_t *ctrl = &scm->ctrl_socket;
Dave Wallace543852a2017-08-03 02:11:34 -0400889 int c, rv, errno_val;
Florin Coras1502fc32018-10-05 00:50:30 -0700890 vcl_test_t post_test = VCL_TEST_TYPE_NONE;
Dave Wallace543852a2017-08-03 02:11:34 -0400891
Florin Coras1502fc32018-10-05 00:50:30 -0700892 vcl_test_cfg_init (&ctrl->cfg);
893 vcl_test_session_buf_alloc (ctrl);
Dave Wallace543852a2017-08-03 02:11:34 -0400894
895 opterr = 0;
Dave Wallacede910062018-03-20 09:22:13 -0400896 while ((c = getopt (argc, argv, "chn:w:XE:I:N:R:T:UBV6D")) != -1)
Dave Wallace543852a2017-08-03 02:11:34 -0400897 switch (c)
898 {
899 case 'c':
900 scm->dump_cfg = 1;
901 break;
902
903 case 's':
Florin Coras1502fc32018-10-05 00:50:30 -0700904 if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1)
905 if (sscanf (optarg, "%u", &ctrl->cfg.num_test_sessions) != 1)
Dave Wallace543852a2017-08-03 02:11:34 -0400906 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500907 fprintf (stderr, "CLIENT: ERROR: Invalid value for "
908 "option -%c!\n", c);
Dave Wallace543852a2017-08-03 02:11:34 -0400909 print_usage_and_exit ();
910 }
Florin Coras1502fc32018-10-05 00:50:30 -0700911 if (!ctrl->cfg.num_test_sessions ||
912 (ctrl->cfg.num_test_sessions > FD_SETSIZE))
Dave Wallace543852a2017-08-03 02:11:34 -0400913 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500914 fprintf (stderr, "CLIENT: ERROR: Invalid number of "
915 "sockets (%d) specified for option -%c!\n"
Dave Wallace543852a2017-08-03 02:11:34 -0400916 " Valid range is 1 - %d\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700917 ctrl->cfg.num_test_sessions, c, FD_SETSIZE);
Dave Wallace543852a2017-08-03 02:11:34 -0400918 print_usage_and_exit ();
919 }
920 break;
921
922 case 'w':
Dave Wallace048b1d62018-01-03 22:24:41 -0500923 fprintf (stderr, "CLIENT: Writing test results to files is TBD.\n");
Dave Wallace543852a2017-08-03 02:11:34 -0400924 break;
925
926 case 'X':
Florin Coras1502fc32018-10-05 00:50:30 -0700927 post_test = VCL_TEST_TYPE_EXIT;
Dave Wallace543852a2017-08-03 02:11:34 -0400928 break;
929
930 case 'E':
931 if (strlen (optarg) > ctrl->txbuf_size)
932 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500933 fprintf (stderr, "CLIENT: ERROR: Option -%c value "
934 "larger than txbuf size (%d)!\n",
Dave Wallace543852a2017-08-03 02:11:34 -0400935 optopt, ctrl->txbuf_size);
936 print_usage_and_exit ();
937 }
938 strcpy (ctrl->txbuf, optarg);
Florin Coras1502fc32018-10-05 00:50:30 -0700939 ctrl->cfg.test = VCL_TEST_TYPE_ECHO;
Dave Wallace543852a2017-08-03 02:11:34 -0400940 break;
941
942 case 'I':
Florin Coras1502fc32018-10-05 00:50:30 -0700943 if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1)
944 if (sscanf (optarg, "%d", &ctrl->cfg.num_test_sessions) != 1)
Dave Wallace543852a2017-08-03 02:11:34 -0400945 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500946 fprintf (stderr, "CLIENT: ERROR: Invalid value for "
947 "option -%c!\n", c);
Dave Wallace543852a2017-08-03 02:11:34 -0400948 print_usage_and_exit ();
949 }
Florin Coras1502fc32018-10-05 00:50:30 -0700950 if (ctrl->cfg.num_test_sessions > VCL_TEST_CFG_MAX_TEST_SESS)
Dave Wallace543852a2017-08-03 02:11:34 -0400951 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500952 fprintf (stderr, "CLIENT: ERROR: value greater than max "
Florin Coras1502fc32018-10-05 00:50:30 -0700953 "number test sockets (%d)!", VCL_TEST_CFG_MAX_TEST_SESS);
Dave Wallace543852a2017-08-03 02:11:34 -0400954 print_usage_and_exit ();
955 }
956 break;
957
958 case 'N':
959 if (sscanf (optarg, "0x%lx", &ctrl->cfg.num_writes) != 1)
960 if (sscanf (optarg, "%ld", &ctrl->cfg.num_writes) != 1)
961 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500962 fprintf (stderr, "CLIENT: ERROR: Invalid value for "
963 "option -%c!\n", c);
Dave Wallace543852a2017-08-03 02:11:34 -0400964 print_usage_and_exit ();
965 }
966 ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
967 break;
968
969 case 'R':
970 if (sscanf (optarg, "0x%lx", &ctrl->cfg.rxbuf_size) != 1)
971 if (sscanf (optarg, "%ld", &ctrl->cfg.rxbuf_size) != 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 }
Florin Coras1502fc32018-10-05 00:50:30 -0700977 if (ctrl->cfg.rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
Dave Wallace543852a2017-08-03 02:11:34 -0400978 {
979 ctrl->rxbuf_size = ctrl->cfg.rxbuf_size;
Florin Coras1502fc32018-10-05 00:50:30 -0700980 vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
981 (uint8_t **) & ctrl->rxbuf,
982 &ctrl->rxbuf_size);
Dave Wallace543852a2017-08-03 02:11:34 -0400983 }
984 else
985 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500986 fprintf (stderr, "CLIENT: ERROR: rxbuf size (%lu) "
987 "less than minumum (%u)\n",
Florin Coras1502fc32018-10-05 00:50:30 -0700988 ctrl->cfg.rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
Dave Wallace543852a2017-08-03 02:11:34 -0400989 print_usage_and_exit ();
990 }
991
992 break;
993
994 case 'T':
995 if (sscanf (optarg, "0x%lx", &ctrl->cfg.txbuf_size) != 1)
996 if (sscanf (optarg, "%ld", &ctrl->cfg.txbuf_size) != 1)
997 {
Dave Wallace048b1d62018-01-03 22:24:41 -0500998 fprintf (stderr, "CLIENT: ERROR: Invalid value "
999 "for option -%c!\n", c);
Dave Wallace543852a2017-08-03 02:11:34 -04001000 print_usage_and_exit ();
1001 }
Florin Coras1502fc32018-10-05 00:50:30 -07001002 if (ctrl->cfg.txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
Dave Wallace543852a2017-08-03 02:11:34 -04001003 {
1004 ctrl->txbuf_size = ctrl->cfg.txbuf_size;
Florin Coras1502fc32018-10-05 00:50:30 -07001005 vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
1006 (uint8_t **) & ctrl->txbuf,
1007 &ctrl->txbuf_size);
Dave Wallace543852a2017-08-03 02:11:34 -04001008 ctrl->cfg.total_bytes =
1009 ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
1010 }
1011 else
1012 {
Dave Wallace048b1d62018-01-03 22:24:41 -05001013 fprintf (stderr, "CLIENT: ERROR: txbuf size (%lu) "
1014 "less than minumum (%u)!\n",
Florin Coras1502fc32018-10-05 00:50:30 -07001015 ctrl->cfg.txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
Dave Wallace543852a2017-08-03 02:11:34 -04001016 print_usage_and_exit ();
1017 }
1018 break;
1019
1020 case 'U':
Florin Coras1502fc32018-10-05 00:50:30 -07001021 ctrl->cfg.test = VCL_TEST_TYPE_UNI;
Dave Wallace543852a2017-08-03 02:11:34 -04001022 break;
1023
1024 case 'B':
Florin Coras1502fc32018-10-05 00:50:30 -07001025 ctrl->cfg.test = VCL_TEST_TYPE_BI;
Dave Wallace543852a2017-08-03 02:11:34 -04001026 break;
1027
1028 case 'V':
1029 ctrl->cfg.verbose = 1;
1030 break;
1031
Dave Wallacede910062018-03-20 09:22:13 -04001032 case '6':
1033 ctrl->cfg.address_ip6 = 1;
1034 break;
1035
1036 case 'D':
1037 ctrl->cfg.transport_udp = 1;
1038 break;
1039
Dave Wallace543852a2017-08-03 02:11:34 -04001040 case '?':
1041 switch (optopt)
1042 {
1043 case 'E':
1044 case 'I':
1045 case 'N':
1046 case 'R':
1047 case 'T':
1048 case 'w':
Dave Wallace048b1d62018-01-03 22:24:41 -05001049 fprintf (stderr, "CLIENT: ERROR: Option -%c "
1050 "requires an argument.\n", optopt);
Chris Lukeab7b8d92017-09-07 07:40:13 -04001051 break;
1052
Dave Wallace543852a2017-08-03 02:11:34 -04001053 default:
1054 if (isprint (optopt))
Dave Wallace048b1d62018-01-03 22:24:41 -05001055 fprintf (stderr, "CLIENT: ERROR: Unknown "
1056 "option `-%c'.\n", optopt);
Dave Wallace543852a2017-08-03 02:11:34 -04001057 else
Dave Wallace048b1d62018-01-03 22:24:41 -05001058 fprintf (stderr, "CLIENT: ERROR: Unknown "
1059 "option character `\\x%x'.\n", optopt);
Dave Wallace543852a2017-08-03 02:11:34 -04001060 }
1061 /* fall thru */
1062 case 'h':
1063 default:
1064 print_usage_and_exit ();
1065 }
1066
1067 if (argc < (optind + 2))
1068 {
Dave Wallace048b1d62018-01-03 22:24:41 -05001069 fprintf (stderr, "CLIENT: ERROR: Insufficient number of arguments!\n");
Dave Wallace543852a2017-08-03 02:11:34 -04001070 print_usage_and_exit ();
1071 }
1072
1073#ifdef VCL_TEST
1074 ctrl->fd = vppcom_app_create ("vcl_test_client");
1075 if (ctrl->fd < 0)
1076 {
1077 errno = -ctrl->fd;
1078 ctrl->fd = -1;
1079 }
1080 else
1081 {
Dave Wallacede910062018-03-20 09:22:13 -04001082 ctrl->fd = vppcom_session_create (ctrl->cfg.transport_udp ?
1083 VPPCOM_PROTO_UDP :
1084 VPPCOM_PROTO_TCP,
Dave Wallace543852a2017-08-03 02:11:34 -04001085 0 /* is_nonblocking */ );
1086 if (ctrl->fd < 0)
1087 {
1088 errno = -ctrl->fd;
1089 ctrl->fd = -1;
1090 }
1091 }
1092#else
Dave Wallacede910062018-03-20 09:22:13 -04001093 ctrl->fd = socket (ctrl->cfg.address_ip6 ? AF_INET6 : AF_INET,
1094 ctrl->cfg.transport_udp ? SOCK_DGRAM : SOCK_STREAM, 0);
Dave Wallace543852a2017-08-03 02:11:34 -04001095#endif
1096
1097 if (ctrl->fd < 0)
1098 {
1099 errno_val = errno;
1100 perror ("ERROR in main()");
Dave Wallace048b1d62018-01-03 22:24:41 -05001101 fprintf (stderr, "CLIENT: ERROR: socket "
1102 "failed (errno = %d)!\n", errno_val);
Dave Wallace543852a2017-08-03 02:11:34 -04001103 return ctrl->fd;
1104 }
1105
1106 memset (&scm->server_addr, 0, sizeof (scm->server_addr));
Dave Wallacede910062018-03-20 09:22:13 -04001107 if (ctrl->cfg.address_ip6)
1108 {
1109 struct sockaddr_in6 *server_addr =
1110 (struct sockaddr_in6 *) &scm->server_addr;
1111 scm->server_addr_size = sizeof (*server_addr);
1112 server_addr->sin6_family = AF_INET6;
1113 inet_pton (AF_INET6, argv[optind++], &(server_addr->sin6_addr));
1114 server_addr->sin6_port = htons (atoi (argv[optind]));
1115 }
1116 else
1117 {
1118 struct sockaddr_in *server_addr =
1119 (struct sockaddr_in *) &scm->server_addr;
1120 scm->server_addr_size = sizeof (*server_addr);
1121 server_addr->sin_family = AF_INET;
1122 inet_pton (AF_INET, argv[optind++], &(server_addr->sin_addr));
1123 server_addr->sin_port = htons (atoi (argv[optind]));
1124 }
Dave Wallace543852a2017-08-03 02:11:34 -04001125
1126#ifdef VCL_TEST
Dave Wallacede910062018-03-20 09:22:13 -04001127 if (ctrl->cfg.address_ip6)
1128 {
1129 struct sockaddr_in6 *server_addr =
1130 (struct sockaddr_in6 *) &scm->server_addr;
1131 scm->server_endpt.is_ip4 = 0;
1132 scm->server_endpt.ip = (uint8_t *) & server_addr->sin6_addr;
1133 scm->server_endpt.port = (uint16_t) server_addr->sin6_port;
1134 }
1135 else
1136 {
1137 struct sockaddr_in *server_addr =
1138 (struct sockaddr_in *) &scm->server_addr;
1139 scm->server_endpt.is_ip4 = 1;
1140 scm->server_endpt.ip = (uint8_t *) & server_addr->sin_addr;
1141 scm->server_endpt.port = (uint16_t) server_addr->sin_port;
1142 }
Dave Wallace543852a2017-08-03 02:11:34 -04001143#endif
1144
1145 do
1146 {
1147 printf ("\nCLIENT: Connecting to server...\n");
1148
1149#ifdef VCL_TEST
1150 rv = vppcom_session_connect (ctrl->fd, &scm->server_endpt);
Dave Wallaceee45d412017-11-24 21:44:06 -05001151 if (rv)
1152 {
1153 errno = -rv;
1154 rv = -1;
1155 }
Dave Wallace543852a2017-08-03 02:11:34 -04001156#else
1157 rv =
1158 connect (ctrl->fd, (struct sockaddr *) &scm->server_addr,
Dave Wallacede910062018-03-20 09:22:13 -04001159 scm->server_addr_size);
Dave Wallace543852a2017-08-03 02:11:34 -04001160#endif
1161 if (rv < 0)
1162 {
1163 errno_val = errno;
1164 perror ("ERROR in main()");
Dave Wallace048b1d62018-01-03 22:24:41 -05001165 fprintf (stderr, "CLIENT: ERROR: connect failed (errno = %d)!\n",
Dave Wallace543852a2017-08-03 02:11:34 -04001166 errno_val);
Dave Wallaceee45d412017-11-24 21:44:06 -05001167 return -1;
Dave Wallace543852a2017-08-03 02:11:34 -04001168 }
1169
1170 sock_test_cfg_sync (ctrl);
1171 printf ("CLIENT (fd %d): Control socket connected.\n", ctrl->fd);
1172 }
1173 while (rv < 0);
1174
Florin Coras1502fc32018-10-05 00:50:30 -07001175 sock_test_connect_test_sockets (ctrl->cfg.num_test_sessions);
Dave Wallace543852a2017-08-03 02:11:34 -04001176
Florin Coras1502fc32018-10-05 00:50:30 -07001177 while (ctrl->cfg.test != VCL_TEST_TYPE_EXIT)
Dave Wallace543852a2017-08-03 02:11:34 -04001178 {
1179 if (scm->dump_cfg)
1180 {
Florin Coras1502fc32018-10-05 00:50:30 -07001181 vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
Dave Wallace543852a2017-08-03 02:11:34 -04001182 scm->dump_cfg = 0;
1183 }
1184
1185 switch (ctrl->cfg.test)
1186 {
Florin Coras1502fc32018-10-05 00:50:30 -07001187 case VCL_TEST_TYPE_ECHO:
Dave Wallace543852a2017-08-03 02:11:34 -04001188 echo_test_client ();
1189 break;
1190
Florin Coras1502fc32018-10-05 00:50:30 -07001191 case VCL_TEST_TYPE_UNI:
1192 case VCL_TEST_TYPE_BI:
Dave Wallace543852a2017-08-03 02:11:34 -04001193 stream_test_client (ctrl->cfg.test);
1194 break;
1195
Florin Coras1502fc32018-10-05 00:50:30 -07001196 case VCL_TEST_TYPE_EXIT:
Dave Wallace543852a2017-08-03 02:11:34 -04001197 continue;
1198
Florin Coras1502fc32018-10-05 00:50:30 -07001199 case VCL_TEST_TYPE_NONE:
Dave Wallace543852a2017-08-03 02:11:34 -04001200 default:
1201 break;
1202 }
1203 switch (post_test)
1204 {
Florin Coras1502fc32018-10-05 00:50:30 -07001205 case VCL_TEST_TYPE_EXIT:
Dave Wallace543852a2017-08-03 02:11:34 -04001206 switch (ctrl->cfg.test)
1207 {
Florin Coras1502fc32018-10-05 00:50:30 -07001208 case VCL_TEST_TYPE_EXIT:
1209 case VCL_TEST_TYPE_UNI:
1210 case VCL_TEST_TYPE_BI:
1211 case VCL_TEST_TYPE_ECHO:
1212 ctrl->cfg.test = VCL_TEST_TYPE_EXIT;
Dave Wallace543852a2017-08-03 02:11:34 -04001213 continue;
1214
Florin Coras1502fc32018-10-05 00:50:30 -07001215 case VCL_TEST_TYPE_NONE:
Dave Wallace543852a2017-08-03 02:11:34 -04001216 default:
1217 break;
1218 }
1219 break;
1220
Florin Coras1502fc32018-10-05 00:50:30 -07001221 case VCL_TEST_TYPE_NONE:
1222 case VCL_TEST_TYPE_ECHO:
1223 case VCL_TEST_TYPE_UNI:
1224 case VCL_TEST_TYPE_BI:
Dave Wallace543852a2017-08-03 02:11:34 -04001225 default:
1226 break;
1227 }
1228
1229 memset (ctrl->txbuf, 0, ctrl->txbuf_size);
1230 memset (ctrl->rxbuf, 0, ctrl->rxbuf_size);
1231
Dave Wallace048b1d62018-01-03 22:24:41 -05001232 printf ("\nCLIENT: Type some characters and hit <return>\n"
Florin Coras1502fc32018-10-05 00:50:30 -07001233 "('" VCL_TEST_TOKEN_HELP "' for help): ");
Dave Wallace543852a2017-08-03 02:11:34 -04001234
1235 if (fgets (ctrl->txbuf, ctrl->txbuf_size, stdin) != NULL)
1236 {
1237 if (strlen (ctrl->txbuf) == 1)
1238 {
1239 printf ("\nCLIENT: Nothing to send! Please try again...\n");
1240 continue;
1241 }
1242 ctrl->txbuf[strlen (ctrl->txbuf) - 1] = 0; // chomp the newline.
1243
1244 /* Parse input for keywords */
1245 ctrl->cfg.test = parse_input ();
1246 }
1247 }
1248
1249 exit_client ();
1250#ifdef VCL_TEST
1251 vppcom_session_close (ctrl->fd);
1252 vppcom_app_destroy ();
Dave Wallace3ee1fe12018-02-23 01:09:11 -05001253 return 0;
Dave Wallace543852a2017-08-03 02:11:34 -04001254#else
1255 close (ctrl->fd);
Dave Wallace3ee1fe12018-02-23 01:09:11 -05001256 return (scm->af_unix_echo_tx == scm->af_unix_echo_rx) ? 0 : -1;
Dave Wallace543852a2017-08-03 02:11:34 -04001257#endif
Dave Wallace543852a2017-08-03 02:11:34 -04001258}
1259
1260/*
1261 * fd.io coding-style-patch-verification: ON
1262 *
1263 * Local Variables:
1264 * eval: (c-set-style "gnu")
1265 * End:
1266 */