Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1 | /* |
| 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 Wallace | 5c7cf1c | 2017-10-24 04:12:18 -0400 | [diff] [blame] | 25 | #include <vcl/sock_test.h> |
Dave Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 26 | #ifndef VCL_TEST |
| 27 | #include <sys/un.h> |
| 28 | #endif |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 29 | |
| 30 | typedef struct |
| 31 | { |
| 32 | #ifdef VCL_TEST |
| 33 | vppcom_endpt_t server_endpt; |
Dave Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 34 | #else |
| 35 | int af_unix_echo_tx; |
| 36 | int af_unix_echo_rx; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 37 | #endif |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 38 | struct sockaddr_storage server_addr; |
| 39 | uint32_t server_addr_size; |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 40 | uint32_t cfg_seq_num; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 41 | vcl_test_session_t ctrl_socket; |
| 42 | vcl_test_session_t *test_socket; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 43 | uint32_t num_test_sockets; |
| 44 | uint8_t dump_cfg; |
| 45 | } sock_client_main_t; |
| 46 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 47 | sock_client_main_t vcl_client_main; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 48 | |
| 49 | |
| 50 | static int |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 51 | sock_test_cfg_sync (vcl_test_session_t * socket) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 52 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 53 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 54 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 55 | vcl_test_cfg_t *rl_cfg = (vcl_test_cfg_t *) socket->rxbuf; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 56 | int rx_bytes, tx_bytes; |
| 57 | |
| 58 | if (socket->cfg.verbose) |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 59 | vcl_test_cfg_dump (&socket->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 60 | |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 61 | 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 65 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 66 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 67 | 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) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 71 | fprintf (stderr, "CLIENT (fd %d): ERROR: write test cfg failed (%d)!\n", |
| 72 | socket->fd, tx_bytes); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 73 | return tx_bytes; |
| 74 | } |
| 75 | |
| 76 | rx_bytes = sock_test_read (socket->fd, (uint8_t *) socket->rxbuf, |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 77 | sizeof (vcl_test_cfg_t), NULL); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 78 | if (rx_bytes < 0) |
| 79 | return rx_bytes; |
| 80 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 81 | if (rl_cfg->magic != VCL_TEST_CFG_CTRL_MAGIC) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 82 | { |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 83 | fprintf (stderr, "CLIENT (fd %d): ERROR: Bad server reply cfg " |
| 84 | "-- aborting!\n", socket->fd); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 85 | return -1; |
| 86 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 87 | if ((rx_bytes != sizeof (vcl_test_cfg_t)) |
| 88 | || !vcl_test_cfg_verify (rl_cfg, &ctrl->cfg)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 89 | { |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 90 | fprintf (stderr, "CLIENT (fd %d): ERROR: Invalid config received " |
| 91 | "from server!\n", socket->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 92 | if (rx_bytes != sizeof (vcl_test_cfg_t)) |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 93 | { |
| 94 | fprintf (stderr, "\tRx bytes %d != cfg size %lu\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 95 | rx_bytes, sizeof (vcl_test_cfg_t)); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 96 | } |
| 97 | else |
| 98 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 99 | vcl_test_cfg_dump (rl_cfg, 1 /* is_client */ ); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 100 | fprintf (stderr, "CLIENT (fd %d): Valid config sent to server.\n", |
| 101 | socket->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 102 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 103 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 104 | return -1; |
| 105 | } |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 106 | else if (socket->cfg.verbose) |
| 107 | { |
| 108 | printf ("CLIENT (fd %d): Got config back from server.\n", socket->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 109 | vcl_test_cfg_dump (rl_cfg, 1 /* is_client */ ); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 110 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 111 | ctrl->cfg.ctrl_handle = ((ctrl->cfg.ctrl_handle == ~0) ? |
| 112 | rl_cfg->ctrl_handle : ctrl->cfg.ctrl_handle); |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static void |
| 118 | echo_test_client () |
| 119 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 120 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 121 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 122 | vcl_test_session_t *tsock; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 123 | 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 135 | for (n = 0; n != ctrl->cfg.num_test_sessions; n++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 136 | { |
| 137 | tsock = &scm->test_socket[n]; |
| 138 | tsock->cfg = ctrl->cfg; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 139 | vcl_test_session_buf_alloc (tsock); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 140 | if (sock_test_cfg_sync (tsock)) |
| 141 | return; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 142 | |
| 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 Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 172 | fprintf (stderr, "\nCLIENT: ERROR: select() failed -- " |
| 173 | "aborting test!\n"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 174 | return; |
| 175 | } |
| 176 | else if (rv == 0) |
| 177 | continue; |
| 178 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 179 | for (i = 0; i < ctrl->cfg.num_test_sessions; i++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 180 | { |
| 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 Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 195 | fprintf (stderr, "\nCLIENT: ERROR: sock_test_write(%d) " |
| 196 | "failed -- aborting test!\n", tsock->fd); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 197 | 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 Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 216 | printf ("CLIENT: WARNING: bytes read (%lu) " |
| 217 | "!= bytes written (%lu)!\n", |
| 218 | tsock->stats.rx_bytes, tsock->stats.tx_bytes); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 219 | } |
| 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 Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 231 | #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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 319 | for (i = 0; i < ctrl->cfg.num_test_sessions; i++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 320 | { |
| 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 329 | vcl_test_stats_dump (buf, &tsock->stats, |
| 330 | 1 /* show_rx */ , 1 /* show tx */ , |
| 331 | ctrl->cfg.verbose); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 332 | } |
| 333 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 334 | vcl_test_stats_accumulate (&ctrl->stats, &tsock->stats); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | if (ctrl->cfg.verbose) |
| 338 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 339 | 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 Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 343 | |
| 344 | if (ctrl->cfg.verbose > 1) |
| 345 | { |
| 346 | printf (" ctrl socket info\n" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 347 | VCL_TEST_SEPARATOR_STRING |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 348 | " 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 353 | VCL_TEST_SEPARATOR_STRING, |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 354 | 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 | |
| 361 | static void |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 362 | stream_test_client (vcl_test_t test) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 363 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 364 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 365 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 366 | vcl_test_session_t *tsock; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 367 | 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 373 | fd_set _rfdset, *rfdset = (test == VCL_TEST_TYPE_BI) ? &_rfdset : 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 374 | |
| 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 381 | ctrl->fd, test == VCL_TEST_TYPE_BI ? "Bi" : "Uni", ctrl->fd); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 382 | |
| 383 | if (sock_test_cfg_sync (ctrl)) |
| 384 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 385 | fprintf (stderr, "CLIENT: ERROR: test cfg sync failed -- aborting!"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 386 | return; |
| 387 | } |
| 388 | |
| 389 | FD_ZERO (&wr_fdset); |
| 390 | FD_ZERO (&rd_fdset); |
| 391 | memset (&ctrl->stats, 0, sizeof (ctrl->stats)); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 392 | for (n = 0; n != ctrl->cfg.num_test_sessions; n++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 393 | { |
| 394 | tsock = &scm->test_socket[n]; |
| 395 | tsock->cfg = ctrl->cfg; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 396 | vcl_test_session_buf_alloc (tsock); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 397 | 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 Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 432 | fprintf (stderr, "\nCLIENT: ERROR: select() failed -- " |
| 433 | "aborting test!\n"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 434 | return; |
| 435 | } |
| 436 | else if (rv == 0) |
| 437 | continue; |
| 438 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 439 | for (i = 0; i < ctrl->cfg.num_test_sessions; i++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 440 | { |
| 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 446 | if ((test == VCL_TEST_TYPE_BI) && |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 447 | 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 Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 455 | if (FD_ISSET (tsock->fd, wfdset) && |
| 456 | (tsock->stats.tx_bytes < ctrl->cfg.total_bytes)) |
| 457 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 458 | tx_bytes = sock_test_write (tsock->fd, (uint8_t *) tsock->txbuf, |
| 459 | ctrl->cfg.txbuf_size, &tsock->stats, |
| 460 | ctrl->cfg.verbose); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 461 | if (tx_bytes < 0) |
| 462 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 463 | fprintf (stderr, "\nCLIENT: ERROR: sock_test_write(%d) " |
| 464 | "failed -- aborting test!\n", tsock->fd); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 465 | return; |
| 466 | } |
| 467 | } |
| 468 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 469 | if (((test == VCL_TEST_TYPE_UNI) && |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 470 | (tsock->stats.tx_bytes >= ctrl->cfg.total_bytes)) || |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 471 | ((test == VCL_TEST_TYPE_BI) && |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 472 | (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 Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 486 | fprintf (stderr, "CLIENT: ERROR: test cfg sync failed -- aborting!"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 487 | return; |
| 488 | } |
| 489 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 490 | for (i = 0; i < ctrl->cfg.num_test_sessions; i++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 491 | { |
| 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 499 | vcl_test_stats_dump (buf, &tsock->stats, |
| 500 | test == VCL_TEST_TYPE_BI /* show_rx */ , |
| 501 | 1 /* show tx */ , ctrl->cfg.verbose); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 504 | vcl_test_stats_accumulate (&ctrl->stats, &tsock->stats); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 505 | } |
| 506 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 507 | 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 Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 511 | |
| 512 | if (ctrl->cfg.verbose) |
| 513 | { |
| 514 | printf (" ctrl socket info\n" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 515 | VCL_TEST_SEPARATOR_STRING |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 516 | " 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 521 | VCL_TEST_SEPARATOR_STRING, |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 522 | 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 527 | ctrl->cfg.test = VCL_TEST_TYPE_ECHO; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 528 | if (sock_test_cfg_sync (ctrl)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 529 | fprintf (stderr, "CLIENT: ERROR: post-test cfg sync failed!"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 530 | |
| 531 | printf ("CLIENT (fd %d): %s-directional Stream Test Complete!\n" |
| 532 | SOCK_TEST_BANNER_STRING "\n", ctrl->fd, |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 533 | test == VCL_TEST_TYPE_BI ? "Bi" : "Uni"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static void |
| 537 | exit_client (void) |
| 538 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 539 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 540 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 541 | vcl_test_session_t *tsock; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 542 | int i; |
| 543 | |
Dave Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 544 | #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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 548 | for (i = 0; i < ctrl->cfg.num_test_sessions; i++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 549 | { |
| 550 | tsock = &scm->test_socket[i]; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 551 | tsock->cfg.test = VCL_TEST_TYPE_EXIT; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 552 | |
Chris Luke | b2bcad6 | 2017-09-18 08:51:22 -0400 | [diff] [blame] | 553 | /* coverity[COPY_PASTE_ERROR] */ |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 554 | if (ctrl->cfg.verbose) |
| 555 | { |
| 556 | printf ("\nCLIENT (fd %d): Sending exit cfg to server...\n", |
| 557 | tsock->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 558 | vcl_test_cfg_dump (&tsock->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 559 | } |
| 560 | (void) sock_test_write (tsock->fd, (uint8_t *) & tsock->cfg, |
| 561 | sizeof (tsock->cfg), &tsock->stats, |
| 562 | ctrl->cfg.verbose); |
| 563 | } |
| 564 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 565 | ctrl->cfg.test = VCL_TEST_TYPE_EXIT; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 566 | if (ctrl->cfg.verbose) |
| 567 | { |
| 568 | printf ("\nCLIENT (fd %d): Sending exit cfg to server...\n", ctrl->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 569 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 570 | } |
| 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 | |
| 578 | static int |
| 579 | sock_test_connect_test_sockets (uint32_t num_test_sockets) |
| 580 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 581 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 582 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 583 | vcl_test_session_t *tsock; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 584 | 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 610 | sizeof (vcl_test_session_t) * num_test_sockets); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 611 | if (!tsock) |
| 612 | { |
| 613 | errno_val = errno; |
| 614 | perror ("ERROR in sock_test_connect_test_sockets()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 615 | fprintf (stderr, "CLIENT: ERROR: socket failed (errno = %d)!\n", |
| 616 | errno_val); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 617 | return -1; |
| 618 | } |
| 619 | |
Dave Wallace | d48e976 | 2017-08-22 23:29:33 -0400 | [diff] [blame] | 620 | if (!scm->test_socket) |
| 621 | memset (tsock, 0, sizeof (*tsock)); |
| 622 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 623 | 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 Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 628 | tsock->fd = vppcom_session_create (ctrl->cfg.transport_udp ? |
| 629 | VPPCOM_PROTO_UDP : |
| 630 | VPPCOM_PROTO_TCP, |
| 631 | 1 /* is_nonblocking */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 632 | if (tsock->fd < 0) |
| 633 | { |
| 634 | errno = -tsock->fd; |
| 635 | tsock->fd = -1; |
| 636 | } |
| 637 | #else |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 638 | tsock->fd = socket (ctrl->cfg.address_ip6 ? AF_INET6 : AF_INET, |
| 639 | ctrl->cfg.transport_udp ? |
| 640 | SOCK_DGRAM : SOCK_STREAM, 0); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 641 | #endif |
| 642 | if (tsock->fd < 0) |
| 643 | { |
| 644 | errno_val = errno; |
| 645 | perror ("ERROR in sock_test_connect_test_sockets()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 646 | fprintf (stderr, "CLIENT: ERROR: socket failed (errno = %d)!\n", |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 647 | errno_val); |
| 648 | return tsock->fd; |
| 649 | } |
| 650 | |
| 651 | #ifdef VCL_TEST |
| 652 | rv = vppcom_session_connect (tsock->fd, &scm->server_endpt); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 653 | if (rv) |
| 654 | { |
| 655 | errno = -rv; |
| 656 | rv = -1; |
| 657 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 658 | #else |
| 659 | rv = |
| 660 | connect (tsock->fd, (struct sockaddr *) &scm->server_addr, |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 661 | scm->server_addr_size); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 662 | #endif |
| 663 | if (rv < 0) |
| 664 | { |
| 665 | errno_val = errno; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 666 | perror ("ERROR in sock_test_connect_test_sockets()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 667 | fprintf (stderr, "CLIENT: ERROR: connect failed " |
| 668 | "(errno = %d)!\n", errno_val); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 669 | return -1; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 670 | } |
| 671 | tsock->cfg = ctrl->cfg; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 672 | vcl_test_session_buf_alloc (tsock); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 673 | 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 | |
| 685 | static void |
| 686 | dump_help (void) |
| 687 | { |
| 688 | #define INDENT "\n " |
| 689 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 690 | printf ("CLIENT: Test configuration commands:" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 691 | INDENT VCL_TEST_TOKEN_HELP |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 692 | "\t\t\tDisplay help." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 693 | INDENT VCL_TEST_TOKEN_EXIT |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 694 | "\t\t\tExit test client & server." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 695 | INDENT VCL_TEST_TOKEN_SHOW_CFG |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 696 | "\t\t\tShow the current test cfg." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 697 | INDENT VCL_TEST_TOKEN_RUN_UNI |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 698 | "\t\t\tRun the Uni-directional test." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 699 | INDENT VCL_TEST_TOKEN_RUN_BI |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 700 | "\t\t\tRun the Bi-directional test." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 701 | INDENT VCL_TEST_TOKEN_VERBOSE |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 702 | "\t\t\tToggle verbose setting." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 703 | INDENT VCL_TEST_TOKEN_RXBUF_SIZE |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 704 | "<rxbuf size>\tRx buffer size (bytes)." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 705 | INDENT VCL_TEST_TOKEN_TXBUF_SIZE |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 706 | "<txbuf size>\tTx buffer size (bytes)." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 707 | INDENT VCL_TEST_TOKEN_NUM_WRITES |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 708 | "<# of writes>\tNumber of txbuf writes to server." "\n"); |
| 709 | } |
| 710 | |
| 711 | static void |
| 712 | cfg_txbuf_size_set (void) |
| 713 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 714 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 715 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 716 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_TXBUF_SIZE); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 717 | uint64_t txbuf_size = strtoull ((const char *) p, NULL, 10); |
| 718 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 719 | if (txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 720 | { |
| 721 | ctrl->cfg.txbuf_size = txbuf_size; |
| 722 | ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 723 | 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 Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 726 | } |
| 727 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 728 | fprintf (stderr, "CLIENT: ERROR: Invalid txbuf size (%lu) < " |
| 729 | "minimum buf size (%u)!\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 730 | txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | static void |
| 734 | cfg_num_writes_set (void) |
| 735 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 736 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 737 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 738 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_WRITES); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 739 | 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 745 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 746 | } |
| 747 | else |
| 748 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 749 | fprintf (stderr, "CLIENT: ERROR: invalid num writes: %u\n", num_writes); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | |
| 753 | static void |
| 754 | cfg_num_test_sockets_set (void) |
| 755 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 756 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 757 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 758 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_TEST_SESS); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 759 | uint32_t num_test_sockets = strtoul ((const char *) p, NULL, 10); |
| 760 | |
| 761 | if ((num_test_sockets > 0) && |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 762 | (num_test_sockets <= VCL_TEST_CFG_MAX_TEST_SESS)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 763 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 764 | ctrl->cfg.num_test_sessions = num_test_sockets; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 765 | sock_test_connect_test_sockets (num_test_sockets); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 766 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 767 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 768 | } |
| 769 | else |
| 770 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 771 | fprintf (stderr, "CLIENT: ERROR: invalid num test sockets: " |
| 772 | "%u, (%d max)\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 773 | num_test_sockets, VCL_TEST_CFG_MAX_TEST_SESS); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | |
| 777 | static void |
| 778 | cfg_rxbuf_size_set (void) |
| 779 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 780 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 781 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 782 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_RXBUF_SIZE); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 783 | uint64_t rxbuf_size = strtoull ((const char *) p, NULL, 10); |
| 784 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 785 | if (rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 786 | { |
| 787 | ctrl->cfg.rxbuf_size = rxbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 788 | 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 Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 791 | } |
| 792 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 793 | fprintf (stderr, "CLIENT: ERROR: Invalid rxbuf size (%lu) < " |
| 794 | "minimum buf size (%u)!\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 795 | rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | static void |
| 799 | cfg_verbose_toggle (void) |
| 800 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 801 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 802 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 803 | |
| 804 | ctrl->cfg.verbose = ctrl->cfg.verbose ? 0 : 1; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 805 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 806 | |
| 807 | } |
| 808 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 809 | static vcl_test_t |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 810 | parse_input () |
| 811 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 812 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 813 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 814 | vcl_test_t rv = VCL_TEST_TYPE_NONE; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 815 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 816 | if (!strncmp (VCL_TEST_TOKEN_EXIT, ctrl->txbuf, |
| 817 | strlen (VCL_TEST_TOKEN_EXIT))) |
| 818 | rv = VCL_TEST_TYPE_EXIT; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 819 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 820 | else if (!strncmp (VCL_TEST_TOKEN_HELP, ctrl->txbuf, |
| 821 | strlen (VCL_TEST_TOKEN_HELP))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 822 | dump_help (); |
| 823 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 824 | else if (!strncmp (VCL_TEST_TOKEN_SHOW_CFG, ctrl->txbuf, |
| 825 | strlen (VCL_TEST_TOKEN_SHOW_CFG))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 826 | scm->dump_cfg = 1; |
| 827 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 828 | else if (!strncmp (VCL_TEST_TOKEN_VERBOSE, ctrl->txbuf, |
| 829 | strlen (VCL_TEST_TOKEN_VERBOSE))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 830 | cfg_verbose_toggle (); |
| 831 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 832 | else if (!strncmp (VCL_TEST_TOKEN_TXBUF_SIZE, ctrl->txbuf, |
| 833 | strlen (VCL_TEST_TOKEN_TXBUF_SIZE))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 834 | cfg_txbuf_size_set (); |
| 835 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 836 | else if (!strncmp (VCL_TEST_TOKEN_NUM_TEST_SESS, ctrl->txbuf, |
| 837 | strlen (VCL_TEST_TOKEN_NUM_TEST_SESS))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 838 | cfg_num_test_sockets_set (); |
| 839 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 840 | else if (!strncmp (VCL_TEST_TOKEN_NUM_WRITES, ctrl->txbuf, |
| 841 | strlen (VCL_TEST_TOKEN_NUM_WRITES))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 842 | cfg_num_writes_set (); |
| 843 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 844 | else if (!strncmp (VCL_TEST_TOKEN_RXBUF_SIZE, ctrl->txbuf, |
| 845 | strlen (VCL_TEST_TOKEN_RXBUF_SIZE))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 846 | cfg_rxbuf_size_set (); |
| 847 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 848 | 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 Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 851 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 852 | 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 Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 855 | |
| 856 | else |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 857 | rv = VCL_TEST_TYPE_ECHO; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 858 | |
| 859 | return rv; |
| 860 | } |
| 861 | |
| 862 | void |
| 863 | print_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 Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 869 | " -6 Use IPv6\n" |
| 870 | " -u Use UDP transport layer\n" |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 871 | " -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 | |
| 884 | int |
| 885 | main (int argc, char **argv) |
| 886 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 887 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 888 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 889 | int c, rv, errno_val; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 890 | vcl_test_t post_test = VCL_TEST_TYPE_NONE; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 891 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 892 | vcl_test_cfg_init (&ctrl->cfg); |
| 893 | vcl_test_session_buf_alloc (ctrl); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 894 | |
| 895 | opterr = 0; |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 896 | while ((c = getopt (argc, argv, "chn:w:XE:I:N:R:T:UBV6D")) != -1) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 897 | switch (c) |
| 898 | { |
| 899 | case 'c': |
| 900 | scm->dump_cfg = 1; |
| 901 | break; |
| 902 | |
| 903 | case 's': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 904 | if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1) |
| 905 | if (sscanf (optarg, "%u", &ctrl->cfg.num_test_sessions) != 1) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 906 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 907 | fprintf (stderr, "CLIENT: ERROR: Invalid value for " |
| 908 | "option -%c!\n", c); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 909 | print_usage_and_exit (); |
| 910 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 911 | if (!ctrl->cfg.num_test_sessions || |
| 912 | (ctrl->cfg.num_test_sessions > FD_SETSIZE)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 913 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 914 | fprintf (stderr, "CLIENT: ERROR: Invalid number of " |
| 915 | "sockets (%d) specified for option -%c!\n" |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 916 | " Valid range is 1 - %d\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 917 | ctrl->cfg.num_test_sessions, c, FD_SETSIZE); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 918 | print_usage_and_exit (); |
| 919 | } |
| 920 | break; |
| 921 | |
| 922 | case 'w': |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 923 | fprintf (stderr, "CLIENT: Writing test results to files is TBD.\n"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 924 | break; |
| 925 | |
| 926 | case 'X': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 927 | post_test = VCL_TEST_TYPE_EXIT; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 928 | break; |
| 929 | |
| 930 | case 'E': |
| 931 | if (strlen (optarg) > ctrl->txbuf_size) |
| 932 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 933 | fprintf (stderr, "CLIENT: ERROR: Option -%c value " |
| 934 | "larger than txbuf size (%d)!\n", |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 935 | optopt, ctrl->txbuf_size); |
| 936 | print_usage_and_exit (); |
| 937 | } |
| 938 | strcpy (ctrl->txbuf, optarg); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 939 | ctrl->cfg.test = VCL_TEST_TYPE_ECHO; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 940 | break; |
| 941 | |
| 942 | case 'I': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 943 | if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1) |
| 944 | if (sscanf (optarg, "%d", &ctrl->cfg.num_test_sessions) != 1) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 945 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 946 | fprintf (stderr, "CLIENT: ERROR: Invalid value for " |
| 947 | "option -%c!\n", c); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 948 | print_usage_and_exit (); |
| 949 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 950 | if (ctrl->cfg.num_test_sessions > VCL_TEST_CFG_MAX_TEST_SESS) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 951 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 952 | fprintf (stderr, "CLIENT: ERROR: value greater than max " |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 953 | "number test sockets (%d)!", VCL_TEST_CFG_MAX_TEST_SESS); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 954 | 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 Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 962 | fprintf (stderr, "CLIENT: ERROR: Invalid value for " |
| 963 | "option -%c!\n", c); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 964 | 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 Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 973 | fprintf (stderr, "CLIENT: ERROR: Invalid value for " |
| 974 | "option -%c!\n", c); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 975 | print_usage_and_exit (); |
| 976 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 977 | if (ctrl->cfg.rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 978 | { |
| 979 | ctrl->rxbuf_size = ctrl->cfg.rxbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 980 | vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ , |
| 981 | (uint8_t **) & ctrl->rxbuf, |
| 982 | &ctrl->rxbuf_size); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 983 | } |
| 984 | else |
| 985 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 986 | fprintf (stderr, "CLIENT: ERROR: rxbuf size (%lu) " |
| 987 | "less than minumum (%u)\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 988 | ctrl->cfg.rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 989 | 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 Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 998 | fprintf (stderr, "CLIENT: ERROR: Invalid value " |
| 999 | "for option -%c!\n", c); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1000 | print_usage_and_exit (); |
| 1001 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1002 | if (ctrl->cfg.txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1003 | { |
| 1004 | ctrl->txbuf_size = ctrl->cfg.txbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1005 | vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ , |
| 1006 | (uint8_t **) & ctrl->txbuf, |
| 1007 | &ctrl->txbuf_size); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1008 | ctrl->cfg.total_bytes = |
| 1009 | ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
| 1010 | } |
| 1011 | else |
| 1012 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1013 | fprintf (stderr, "CLIENT: ERROR: txbuf size (%lu) " |
| 1014 | "less than minumum (%u)!\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1015 | ctrl->cfg.txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1016 | print_usage_and_exit (); |
| 1017 | } |
| 1018 | break; |
| 1019 | |
| 1020 | case 'U': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1021 | ctrl->cfg.test = VCL_TEST_TYPE_UNI; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1022 | break; |
| 1023 | |
| 1024 | case 'B': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1025 | ctrl->cfg.test = VCL_TEST_TYPE_BI; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1026 | break; |
| 1027 | |
| 1028 | case 'V': |
| 1029 | ctrl->cfg.verbose = 1; |
| 1030 | break; |
| 1031 | |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1032 | case '6': |
| 1033 | ctrl->cfg.address_ip6 = 1; |
| 1034 | break; |
| 1035 | |
| 1036 | case 'D': |
| 1037 | ctrl->cfg.transport_udp = 1; |
| 1038 | break; |
| 1039 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1040 | case '?': |
| 1041 | switch (optopt) |
| 1042 | { |
| 1043 | case 'E': |
| 1044 | case 'I': |
| 1045 | case 'N': |
| 1046 | case 'R': |
| 1047 | case 'T': |
| 1048 | case 'w': |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1049 | fprintf (stderr, "CLIENT: ERROR: Option -%c " |
| 1050 | "requires an argument.\n", optopt); |
Chris Luke | ab7b8d9 | 2017-09-07 07:40:13 -0400 | [diff] [blame] | 1051 | break; |
| 1052 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1053 | default: |
| 1054 | if (isprint (optopt)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1055 | fprintf (stderr, "CLIENT: ERROR: Unknown " |
| 1056 | "option `-%c'.\n", optopt); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1057 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1058 | fprintf (stderr, "CLIENT: ERROR: Unknown " |
| 1059 | "option character `\\x%x'.\n", optopt); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1060 | } |
| 1061 | /* fall thru */ |
| 1062 | case 'h': |
| 1063 | default: |
| 1064 | print_usage_and_exit (); |
| 1065 | } |
| 1066 | |
| 1067 | if (argc < (optind + 2)) |
| 1068 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1069 | fprintf (stderr, "CLIENT: ERROR: Insufficient number of arguments!\n"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1070 | 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 Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1082 | ctrl->fd = vppcom_session_create (ctrl->cfg.transport_udp ? |
| 1083 | VPPCOM_PROTO_UDP : |
| 1084 | VPPCOM_PROTO_TCP, |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1085 | 0 /* is_nonblocking */ ); |
| 1086 | if (ctrl->fd < 0) |
| 1087 | { |
| 1088 | errno = -ctrl->fd; |
| 1089 | ctrl->fd = -1; |
| 1090 | } |
| 1091 | } |
| 1092 | #else |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1093 | ctrl->fd = socket (ctrl->cfg.address_ip6 ? AF_INET6 : AF_INET, |
| 1094 | ctrl->cfg.transport_udp ? SOCK_DGRAM : SOCK_STREAM, 0); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1095 | #endif |
| 1096 | |
| 1097 | if (ctrl->fd < 0) |
| 1098 | { |
| 1099 | errno_val = errno; |
| 1100 | perror ("ERROR in main()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1101 | fprintf (stderr, "CLIENT: ERROR: socket " |
| 1102 | "failed (errno = %d)!\n", errno_val); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1103 | return ctrl->fd; |
| 1104 | } |
| 1105 | |
| 1106 | memset (&scm->server_addr, 0, sizeof (scm->server_addr)); |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1107 | 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 Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1125 | |
| 1126 | #ifdef VCL_TEST |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1127 | 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 Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1143 | #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 Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1151 | if (rv) |
| 1152 | { |
| 1153 | errno = -rv; |
| 1154 | rv = -1; |
| 1155 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1156 | #else |
| 1157 | rv = |
| 1158 | connect (ctrl->fd, (struct sockaddr *) &scm->server_addr, |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1159 | scm->server_addr_size); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1160 | #endif |
| 1161 | if (rv < 0) |
| 1162 | { |
| 1163 | errno_val = errno; |
| 1164 | perror ("ERROR in main()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1165 | fprintf (stderr, "CLIENT: ERROR: connect failed (errno = %d)!\n", |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1166 | errno_val); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1167 | return -1; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1168 | } |
| 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 Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1175 | sock_test_connect_test_sockets (ctrl->cfg.num_test_sessions); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1176 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1177 | while (ctrl->cfg.test != VCL_TEST_TYPE_EXIT) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1178 | { |
| 1179 | if (scm->dump_cfg) |
| 1180 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1181 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1182 | scm->dump_cfg = 0; |
| 1183 | } |
| 1184 | |
| 1185 | switch (ctrl->cfg.test) |
| 1186 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1187 | case VCL_TEST_TYPE_ECHO: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1188 | echo_test_client (); |
| 1189 | break; |
| 1190 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1191 | case VCL_TEST_TYPE_UNI: |
| 1192 | case VCL_TEST_TYPE_BI: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1193 | stream_test_client (ctrl->cfg.test); |
| 1194 | break; |
| 1195 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1196 | case VCL_TEST_TYPE_EXIT: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1197 | continue; |
| 1198 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1199 | case VCL_TEST_TYPE_NONE: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1200 | default: |
| 1201 | break; |
| 1202 | } |
| 1203 | switch (post_test) |
| 1204 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1205 | case VCL_TEST_TYPE_EXIT: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1206 | switch (ctrl->cfg.test) |
| 1207 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1208 | 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 Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1213 | continue; |
| 1214 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1215 | case VCL_TEST_TYPE_NONE: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1216 | default: |
| 1217 | break; |
| 1218 | } |
| 1219 | break; |
| 1220 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1221 | case VCL_TEST_TYPE_NONE: |
| 1222 | case VCL_TEST_TYPE_ECHO: |
| 1223 | case VCL_TEST_TYPE_UNI: |
| 1224 | case VCL_TEST_TYPE_BI: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1225 | default: |
| 1226 | break; |
| 1227 | } |
| 1228 | |
| 1229 | memset (ctrl->txbuf, 0, ctrl->txbuf_size); |
| 1230 | memset (ctrl->rxbuf, 0, ctrl->rxbuf_size); |
| 1231 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1232 | printf ("\nCLIENT: Type some characters and hit <return>\n" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1233 | "('" VCL_TEST_TOKEN_HELP "' for help): "); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1234 | |
| 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 Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 1253 | return 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1254 | #else |
| 1255 | close (ctrl->fd); |
Dave Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 1256 | return (scm->af_unix_echo_tx == scm->af_unix_echo_rx) ? 0 : -1; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1257 | #endif |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | /* |
| 1261 | * fd.io coding-style-patch-verification: ON |
| 1262 | * |
| 1263 | * Local Variables: |
| 1264 | * eval: (c-set-style "gnu") |
| 1265 | * End: |
| 1266 | */ |