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> |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 26 | #include <fcntl.h> |
Dave Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 27 | #ifndef VCL_TEST |
| 28 | #include <sys/un.h> |
| 29 | #endif |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 30 | |
| 31 | typedef struct |
| 32 | { |
| 33 | #ifdef VCL_TEST |
| 34 | vppcom_endpt_t server_endpt; |
Dave Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 35 | #else |
| 36 | int af_unix_echo_tx; |
| 37 | int af_unix_echo_rx; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 38 | #endif |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 39 | struct sockaddr_storage server_addr; |
| 40 | uint32_t server_addr_size; |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 41 | uint32_t cfg_seq_num; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 42 | vcl_test_session_t ctrl_socket; |
| 43 | vcl_test_session_t *test_socket; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 44 | uint32_t num_test_sockets; |
| 45 | uint8_t dump_cfg; |
| 46 | } sock_client_main_t; |
| 47 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 48 | sock_client_main_t vcl_client_main; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 49 | |
| 50 | |
| 51 | static int |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 52 | sock_test_cfg_sync (vcl_test_session_t * socket) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 53 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 54 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 55 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 56 | vcl_test_cfg_t *rl_cfg = (vcl_test_cfg_t *) socket->rxbuf; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 57 | int rx_bytes, tx_bytes; |
| 58 | |
| 59 | if (socket->cfg.verbose) |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 60 | vcl_test_cfg_dump (&socket->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 61 | |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 62 | ctrl->cfg.seq_num = ++scm->cfg_seq_num; |
| 63 | if (socket->cfg.verbose) |
| 64 | { |
| 65 | printf ("CLIENT (fd %d): Sending config sent to server.\n", socket->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 66 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 67 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 68 | tx_bytes = sock_test_write (socket->fd, (uint8_t *) & ctrl->cfg, |
| 69 | sizeof (ctrl->cfg), NULL, ctrl->cfg.verbose); |
| 70 | if (tx_bytes < 0) |
| 71 | { |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 72 | fprintf (stderr, "CLIENT (fd %d): ERROR: write test cfg failed (%d)!\n", |
| 73 | socket->fd, tx_bytes); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 74 | return tx_bytes; |
| 75 | } |
| 76 | |
| 77 | rx_bytes = sock_test_read (socket->fd, (uint8_t *) socket->rxbuf, |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 78 | sizeof (vcl_test_cfg_t), NULL); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 79 | if (rx_bytes < 0) |
| 80 | return rx_bytes; |
| 81 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 82 | if (rl_cfg->magic != VCL_TEST_CFG_CTRL_MAGIC) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 83 | { |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 84 | fprintf (stderr, "CLIENT (fd %d): ERROR: Bad server reply cfg " |
| 85 | "-- aborting!\n", socket->fd); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 86 | return -1; |
| 87 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 88 | if ((rx_bytes != sizeof (vcl_test_cfg_t)) |
| 89 | || !vcl_test_cfg_verify (rl_cfg, &ctrl->cfg)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 90 | { |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 91 | fprintf (stderr, "CLIENT (fd %d): ERROR: Invalid config received " |
| 92 | "from server!\n", socket->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 93 | if (rx_bytes != sizeof (vcl_test_cfg_t)) |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 94 | { |
| 95 | fprintf (stderr, "\tRx bytes %d != cfg size %lu\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 96 | rx_bytes, sizeof (vcl_test_cfg_t)); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 97 | } |
| 98 | else |
| 99 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 100 | vcl_test_cfg_dump (rl_cfg, 1 /* is_client */ ); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 101 | fprintf (stderr, "CLIENT (fd %d): Valid config sent to server.\n", |
| 102 | socket->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 103 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 104 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 105 | return -1; |
| 106 | } |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 107 | else if (socket->cfg.verbose) |
| 108 | { |
| 109 | printf ("CLIENT (fd %d): Got config back from server.\n", socket->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 110 | vcl_test_cfg_dump (rl_cfg, 1 /* is_client */ ); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 111 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 112 | ctrl->cfg.ctrl_handle = ((ctrl->cfg.ctrl_handle == ~0) ? |
| 113 | rl_cfg->ctrl_handle : ctrl->cfg.ctrl_handle); |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | static void |
| 119 | echo_test_client () |
| 120 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 121 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 122 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 123 | vcl_test_session_t *tsock; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 124 | int rx_bytes, tx_bytes, nbytes; |
| 125 | uint32_t i, n; |
| 126 | int rv; |
| 127 | int nfds = 0; |
| 128 | fd_set wr_fdset, rd_fdset; |
| 129 | fd_set _wfdset, *wfdset = &_wfdset; |
| 130 | fd_set _rfdset, *rfdset = &_rfdset; |
| 131 | |
| 132 | FD_ZERO (&wr_fdset); |
| 133 | FD_ZERO (&rd_fdset); |
| 134 | memset (&ctrl->stats, 0, sizeof (ctrl->stats)); |
| 135 | ctrl->cfg.total_bytes = nbytes = strlen (ctrl->txbuf) + 1; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 136 | for (n = 0; n != ctrl->cfg.num_test_sessions; n++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 137 | { |
| 138 | tsock = &scm->test_socket[n]; |
| 139 | tsock->cfg = ctrl->cfg; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 140 | vcl_test_session_buf_alloc (tsock); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 141 | if (sock_test_cfg_sync (tsock)) |
| 142 | return; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 143 | |
| 144 | memcpy (tsock->txbuf, ctrl->txbuf, nbytes); |
| 145 | memset (&tsock->stats, 0, sizeof (tsock->stats)); |
| 146 | |
| 147 | FD_SET (tsock->fd, &wr_fdset); |
| 148 | FD_SET (tsock->fd, &rd_fdset); |
| 149 | nfds = ((tsock->fd + 1) > nfds) ? (tsock->fd + 1) : nfds; |
| 150 | } |
| 151 | |
| 152 | nfds++; |
| 153 | clock_gettime (CLOCK_REALTIME, &ctrl->stats.start); |
| 154 | while (n) |
| 155 | { |
| 156 | _wfdset = wr_fdset; |
| 157 | _rfdset = rd_fdset; |
| 158 | |
| 159 | #ifdef VCL_TEST |
| 160 | rv = vppcom_select (nfds, (uint64_t *) rfdset, (uint64_t *) wfdset, |
| 161 | NULL, 0); |
| 162 | #else |
| 163 | { |
| 164 | struct timeval timeout; |
| 165 | timeout.tv_sec = 0; |
| 166 | timeout.tv_usec = 0; |
| 167 | rv = select (nfds, rfdset, wfdset, NULL, &timeout); |
| 168 | } |
| 169 | #endif |
| 170 | if (rv < 0) |
| 171 | { |
| 172 | perror ("select()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 173 | fprintf (stderr, "\nCLIENT: ERROR: select() failed -- " |
| 174 | "aborting test!\n"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 175 | return; |
| 176 | } |
| 177 | else if (rv == 0) |
| 178 | continue; |
| 179 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 180 | for (i = 0; i < ctrl->cfg.num_test_sessions; i++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 181 | { |
| 182 | tsock = &scm->test_socket[i]; |
| 183 | if (!((tsock->stats.stop.tv_sec == 0) && |
| 184 | (tsock->stats.stop.tv_nsec == 0))) |
| 185 | continue; |
| 186 | |
| 187 | if (FD_ISSET (tsock->fd, wfdset) && |
| 188 | (tsock->stats.tx_bytes < ctrl->cfg.total_bytes)) |
| 189 | |
| 190 | { |
| 191 | tx_bytes = |
| 192 | sock_test_write (tsock->fd, (uint8_t *) tsock->txbuf, nbytes, |
| 193 | &tsock->stats, ctrl->cfg.verbose); |
| 194 | if (tx_bytes < 0) |
| 195 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 196 | fprintf (stderr, "\nCLIENT: ERROR: sock_test_write(%d) " |
| 197 | "failed -- aborting test!\n", tsock->fd); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 198 | return; |
| 199 | } |
| 200 | |
| 201 | printf ("CLIENT (fd %d): TX (%d bytes) - '%s'\n", |
| 202 | tsock->fd, tx_bytes, tsock->txbuf); |
| 203 | } |
| 204 | |
| 205 | if ((FD_ISSET (tsock->fd, rfdset)) && |
| 206 | (tsock->stats.rx_bytes < ctrl->cfg.total_bytes)) |
| 207 | { |
| 208 | rx_bytes = |
| 209 | sock_test_read (tsock->fd, (uint8_t *) tsock->rxbuf, |
| 210 | nbytes, &tsock->stats); |
| 211 | if (rx_bytes > 0) |
| 212 | { |
| 213 | printf ("CLIENT (fd %d): RX (%d bytes) - '%s'\n", |
| 214 | tsock->fd, rx_bytes, tsock->rxbuf); |
| 215 | |
| 216 | if (tsock->stats.rx_bytes != tsock->stats.tx_bytes) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 217 | printf ("CLIENT: WARNING: bytes read (%lu) " |
| 218 | "!= bytes written (%lu)!\n", |
| 219 | tsock->stats.rx_bytes, tsock->stats.tx_bytes); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | if (tsock->stats.rx_bytes >= ctrl->cfg.total_bytes) |
| 224 | { |
| 225 | clock_gettime (CLOCK_REALTIME, &tsock->stats.stop); |
| 226 | n--; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | clock_gettime (CLOCK_REALTIME, &ctrl->stats.stop); |
| 231 | |
Dave Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 232 | #ifndef VCL_TEST |
| 233 | { |
| 234 | int fd, errno_val; |
| 235 | struct sockaddr_un serveraddr; |
| 236 | uint8_t buffer[256]; |
| 237 | size_t nbytes = strlen (SOCK_TEST_MIXED_EPOLL_DATA) + 1; |
| 238 | struct timeval timeout; |
| 239 | |
| 240 | /* Open AF_UNIX socket and send an echo to test mixed epoll on server. |
| 241 | */ |
| 242 | fd = socket (AF_UNIX, SOCK_STREAM, 0); |
| 243 | if (fd < 0) |
| 244 | { |
| 245 | errno_val = errno; |
| 246 | perror ("ERROR in echo_test_client(): socket(AF_UNIX) failed"); |
| 247 | fprintf (stderr, |
| 248 | "CLIENT: ERROR: socket(AF_UNIX, SOCK_STREAM, 0) failed " |
| 249 | "(errno = %d)!\n", errno_val); |
| 250 | goto out; |
| 251 | } |
| 252 | memset (&serveraddr, 0, sizeof (serveraddr)); |
| 253 | serveraddr.sun_family = AF_UNIX; |
| 254 | strcpy (serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME); |
| 255 | rv = connect (fd, (struct sockaddr *) &serveraddr, SUN_LEN (&serveraddr)); |
| 256 | if (rv < 0) |
| 257 | { |
| 258 | errno_val = errno; |
| 259 | perror ("ERROR in echo_test_client(): connect() failed"); |
| 260 | fprintf (stderr, "CLIENT: ERROR: connect(fd %d, \"%s\", %lu) " |
| 261 | "failed (errno = %d)!\n", fd, SOCK_TEST_AF_UNIX_FILENAME, |
| 262 | SUN_LEN (&serveraddr), errno_val); |
| 263 | goto done; |
| 264 | } |
| 265 | |
| 266 | scm->af_unix_echo_tx++; |
| 267 | strcpy ((char *) buffer, SOCK_TEST_MIXED_EPOLL_DATA); |
| 268 | timeout.tv_sec = 0; |
| 269 | timeout.tv_usec = 250000; |
| 270 | select (0, NULL, NULL, NULL, &timeout); /* delay .25 secs */ |
| 271 | rv = write (fd, buffer, nbytes); |
| 272 | if (rv < 0) |
| 273 | { |
| 274 | errno_val = errno; |
| 275 | perror ("ERROR in echo_test_client(): write() failed"); |
| 276 | fprintf (stderr, "CLIENT: ERROR: write(fd %d, \"%s\", %lu) " |
| 277 | "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val); |
| 278 | goto done; |
| 279 | } |
| 280 | else if (rv < nbytes) |
| 281 | { |
| 282 | fprintf (stderr, "CLIENT: ERROR: write(fd %d, \"%s\", %lu) " |
| 283 | "returned %d!\n", fd, buffer, nbytes, rv); |
| 284 | goto done; |
| 285 | } |
| 286 | |
| 287 | printf ("CLIENT (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer); |
| 288 | memset (buffer, 0, sizeof (buffer)); |
| 289 | rv = read (fd, buffer, nbytes); |
| 290 | if (rv < 0) |
| 291 | { |
| 292 | errno_val = errno; |
| 293 | perror ("ERROR in echo_test_client(): read() failed"); |
| 294 | fprintf (stderr, "CLIENT: ERROR: read(fd %d, %p, %lu) " |
| 295 | "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val); |
| 296 | goto done; |
| 297 | } |
| 298 | else if (rv < nbytes) |
| 299 | { |
| 300 | fprintf (stderr, "CLIENT: ERROR: read(fd %d, %p, %lu) " |
| 301 | "returned %d!\n", fd, buffer, nbytes, rv); |
| 302 | goto done; |
| 303 | } |
| 304 | |
| 305 | if (!strncmp (SOCK_TEST_MIXED_EPOLL_DATA, (const char *) buffer, nbytes)) |
| 306 | { |
| 307 | printf ("CLIENT (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer); |
| 308 | scm->af_unix_echo_rx++; |
| 309 | } |
| 310 | else |
| 311 | printf ("CLIENT (AF_UNIX): ERROR: RX (%d bytes) - '%s'\n", rv, buffer); |
| 312 | |
| 313 | done: |
| 314 | close (fd); |
| 315 | out: |
| 316 | ; |
| 317 | } |
| 318 | #endif |
| 319 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 320 | for (i = 0; i < ctrl->cfg.num_test_sessions; i++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 321 | { |
| 322 | tsock = &scm->test_socket[i]; |
| 323 | tsock->stats.start = ctrl->stats.start; |
| 324 | |
| 325 | if (ctrl->cfg.verbose) |
| 326 | { |
| 327 | static char buf[64]; |
| 328 | |
| 329 | sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 330 | vcl_test_stats_dump (buf, &tsock->stats, |
| 331 | 1 /* show_rx */ , 1 /* show tx */ , |
| 332 | ctrl->cfg.verbose); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 333 | } |
| 334 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 335 | vcl_test_stats_accumulate (&ctrl->stats, &tsock->stats); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | if (ctrl->cfg.verbose) |
| 339 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 340 | vcl_test_stats_dump ("CLIENT RESULTS", &ctrl->stats, |
| 341 | 1 /* show_rx */ , 1 /* show tx */ , |
| 342 | ctrl->cfg.verbose); |
| 343 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 344 | |
| 345 | if (ctrl->cfg.verbose > 1) |
| 346 | { |
| 347 | printf (" ctrl socket info\n" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 348 | VCL_TEST_SEPARATOR_STRING |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 349 | " fd: %d (0x%08x)\n" |
| 350 | " rxbuf: %p\n" |
| 351 | " rxbuf size: %u (0x%08x)\n" |
| 352 | " txbuf: %p\n" |
| 353 | " txbuf size: %u (0x%08x)\n" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 354 | VCL_TEST_SEPARATOR_STRING, |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 355 | ctrl->fd, (uint32_t) ctrl->fd, |
| 356 | ctrl->rxbuf, ctrl->rxbuf_size, ctrl->rxbuf_size, |
| 357 | ctrl->txbuf, ctrl->txbuf_size, ctrl->txbuf_size); |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | static void |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 363 | stream_test_client (vcl_test_t test) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 364 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 365 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 366 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 367 | vcl_test_session_t *tsock; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 368 | int tx_bytes; |
| 369 | uint32_t i, n; |
| 370 | int rv; |
| 371 | int nfds = 0; |
| 372 | fd_set wr_fdset, rd_fdset; |
| 373 | fd_set _wfdset, *wfdset = &_wfdset; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 374 | fd_set _rfdset, *rfdset = (test == VCL_TEST_TYPE_BI) ? &_rfdset : 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 375 | |
| 376 | ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
| 377 | ctrl->cfg.ctrl_handle = ~0; |
| 378 | |
| 379 | printf ("\n" SOCK_TEST_BANNER_STRING |
| 380 | "CLIENT (fd %d): %s-directional Stream Test!\n\n" |
| 381 | "CLIENT (fd %d): Sending config to server on ctrl socket...\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 382 | ctrl->fd, test == VCL_TEST_TYPE_BI ? "Bi" : "Uni", ctrl->fd); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 383 | |
| 384 | if (sock_test_cfg_sync (ctrl)) |
| 385 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 386 | fprintf (stderr, "CLIENT: ERROR: test cfg sync failed -- aborting!"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 387 | return; |
| 388 | } |
| 389 | |
| 390 | FD_ZERO (&wr_fdset); |
| 391 | FD_ZERO (&rd_fdset); |
| 392 | memset (&ctrl->stats, 0, sizeof (ctrl->stats)); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 393 | for (n = 0; n != ctrl->cfg.num_test_sessions; n++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 394 | { |
| 395 | tsock = &scm->test_socket[n]; |
| 396 | tsock->cfg = ctrl->cfg; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 397 | vcl_test_session_buf_alloc (tsock); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 398 | printf ("CLIENT (fd %d): Sending config to server on " |
| 399 | "test socket %d...\n", tsock->fd, n); |
| 400 | sock_test_cfg_sync (tsock); |
| 401 | |
| 402 | /* Fill payload with incrementing uint32's */ |
| 403 | for (i = 0; i < tsock->txbuf_size; i++) |
| 404 | tsock->txbuf[i] = i & 0xff; |
| 405 | |
| 406 | memset (&tsock->stats, 0, sizeof (tsock->stats)); |
| 407 | FD_SET (tsock->fd, &wr_fdset); |
| 408 | FD_SET (tsock->fd, &rd_fdset); |
| 409 | nfds = ((tsock->fd + 1) > nfds) ? (tsock->fd + 1) : nfds; |
| 410 | } |
| 411 | |
| 412 | nfds++; |
| 413 | clock_gettime (CLOCK_REALTIME, &ctrl->stats.start); |
| 414 | while (n) |
| 415 | { |
| 416 | _wfdset = wr_fdset; |
| 417 | _rfdset = rd_fdset; |
| 418 | |
| 419 | #ifdef VCL_TEST |
| 420 | rv = vppcom_select (nfds, (uint64_t *) rfdset, (uint64_t *) wfdset, |
| 421 | NULL, 0); |
| 422 | #else |
| 423 | { |
| 424 | struct timeval timeout; |
| 425 | timeout.tv_sec = 0; |
| 426 | timeout.tv_usec = 0; |
| 427 | rv = select (nfds, rfdset, wfdset, NULL, &timeout); |
| 428 | } |
| 429 | #endif |
| 430 | if (rv < 0) |
| 431 | { |
| 432 | perror ("select()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 433 | fprintf (stderr, "\nCLIENT: ERROR: select() failed -- " |
| 434 | "aborting test!\n"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 435 | return; |
| 436 | } |
| 437 | else if (rv == 0) |
| 438 | continue; |
| 439 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 440 | for (i = 0; i < ctrl->cfg.num_test_sessions; i++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 441 | { |
| 442 | tsock = &scm->test_socket[i]; |
| 443 | if (!((tsock->stats.stop.tv_sec == 0) && |
| 444 | (tsock->stats.stop.tv_nsec == 0))) |
| 445 | continue; |
| 446 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 447 | if ((test == VCL_TEST_TYPE_BI) && |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 448 | FD_ISSET (tsock->fd, rfdset) && |
| 449 | (tsock->stats.rx_bytes < ctrl->cfg.total_bytes)) |
| 450 | { |
| 451 | (void) sock_test_read (tsock->fd, |
| 452 | (uint8_t *) tsock->rxbuf, |
| 453 | tsock->rxbuf_size, &tsock->stats); |
| 454 | } |
| 455 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 456 | if (FD_ISSET (tsock->fd, wfdset) && |
| 457 | (tsock->stats.tx_bytes < ctrl->cfg.total_bytes)) |
| 458 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 459 | tx_bytes = sock_test_write (tsock->fd, (uint8_t *) tsock->txbuf, |
| 460 | ctrl->cfg.txbuf_size, &tsock->stats, |
| 461 | ctrl->cfg.verbose); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 462 | if (tx_bytes < 0) |
| 463 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 464 | fprintf (stderr, "\nCLIENT: ERROR: sock_test_write(%d) " |
| 465 | "failed -- aborting test!\n", tsock->fd); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 466 | return; |
| 467 | } |
| 468 | } |
| 469 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 470 | if (((test == VCL_TEST_TYPE_UNI) && |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 471 | (tsock->stats.tx_bytes >= ctrl->cfg.total_bytes)) || |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 472 | ((test == VCL_TEST_TYPE_BI) && |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 473 | (tsock->stats.rx_bytes >= ctrl->cfg.total_bytes))) |
| 474 | { |
| 475 | clock_gettime (CLOCK_REALTIME, &tsock->stats.stop); |
| 476 | n--; |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | clock_gettime (CLOCK_REALTIME, &ctrl->stats.stop); |
| 481 | |
| 482 | printf ("CLIENT (fd %d): Sending config to server on ctrl socket...\n", |
| 483 | ctrl->fd); |
| 484 | |
| 485 | if (sock_test_cfg_sync (ctrl)) |
| 486 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 487 | fprintf (stderr, "CLIENT: ERROR: test cfg sync failed -- aborting!"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 488 | return; |
| 489 | } |
| 490 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 491 | for (i = 0; i < ctrl->cfg.num_test_sessions; i++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 492 | { |
| 493 | tsock = &scm->test_socket[i]; |
| 494 | |
| 495 | if (ctrl->cfg.verbose) |
| 496 | { |
| 497 | static char buf[64]; |
| 498 | |
| 499 | sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 500 | vcl_test_stats_dump (buf, &tsock->stats, |
| 501 | test == VCL_TEST_TYPE_BI /* show_rx */ , |
| 502 | 1 /* show tx */ , ctrl->cfg.verbose); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 503 | } |
| 504 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 505 | vcl_test_stats_accumulate (&ctrl->stats, &tsock->stats); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 506 | } |
| 507 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 508 | vcl_test_stats_dump ("CLIENT RESULTS", &ctrl->stats, |
| 509 | test == VCL_TEST_TYPE_BI /* show_rx */ , |
| 510 | 1 /* show tx */ , ctrl->cfg.verbose); |
| 511 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 512 | |
| 513 | if (ctrl->cfg.verbose) |
| 514 | { |
| 515 | printf (" ctrl socket info\n" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 516 | VCL_TEST_SEPARATOR_STRING |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 517 | " fd: %d (0x%08x)\n" |
| 518 | " rxbuf: %p\n" |
| 519 | " rxbuf size: %u (0x%08x)\n" |
| 520 | " txbuf: %p\n" |
| 521 | " txbuf size: %u (0x%08x)\n" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 522 | VCL_TEST_SEPARATOR_STRING, |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 523 | ctrl->fd, (uint32_t) ctrl->fd, |
| 524 | ctrl->rxbuf, ctrl->rxbuf_size, ctrl->rxbuf_size, |
| 525 | ctrl->txbuf, ctrl->txbuf_size, ctrl->txbuf_size); |
| 526 | } |
| 527 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 528 | ctrl->cfg.test = VCL_TEST_TYPE_ECHO; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 529 | if (sock_test_cfg_sync (ctrl)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 530 | fprintf (stderr, "CLIENT: ERROR: post-test cfg sync failed!"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 531 | |
| 532 | printf ("CLIENT (fd %d): %s-directional Stream Test Complete!\n" |
| 533 | SOCK_TEST_BANNER_STRING "\n", ctrl->fd, |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 534 | test == VCL_TEST_TYPE_BI ? "Bi" : "Uni"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | static void |
| 538 | exit_client (void) |
| 539 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 540 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 541 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 542 | vcl_test_session_t *tsock; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 543 | int i; |
| 544 | |
Dave Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 545 | #ifndef VCL_TEST |
| 546 | printf ("CLIENT: af_unix_echo_tx %d, af_unix_echo_rx %d\n", |
| 547 | scm->af_unix_echo_tx, scm->af_unix_echo_rx); |
| 548 | #endif |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 549 | for (i = 0; i < ctrl->cfg.num_test_sessions; i++) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 550 | { |
| 551 | tsock = &scm->test_socket[i]; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 552 | tsock->cfg.test = VCL_TEST_TYPE_EXIT; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 553 | |
Chris Luke | b2bcad6 | 2017-09-18 08:51:22 -0400 | [diff] [blame] | 554 | /* coverity[COPY_PASTE_ERROR] */ |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 555 | if (ctrl->cfg.verbose) |
| 556 | { |
| 557 | printf ("\nCLIENT (fd %d): Sending exit cfg to server...\n", |
| 558 | tsock->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 559 | vcl_test_cfg_dump (&tsock->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 560 | } |
| 561 | (void) sock_test_write (tsock->fd, (uint8_t *) & tsock->cfg, |
| 562 | sizeof (tsock->cfg), &tsock->stats, |
| 563 | ctrl->cfg.verbose); |
| 564 | } |
| 565 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 566 | ctrl->cfg.test = VCL_TEST_TYPE_EXIT; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 567 | if (ctrl->cfg.verbose) |
| 568 | { |
| 569 | printf ("\nCLIENT (fd %d): Sending exit cfg to server...\n", ctrl->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 570 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 571 | } |
| 572 | (void) sock_test_write (ctrl->fd, (uint8_t *) & ctrl->cfg, |
| 573 | sizeof (ctrl->cfg), &ctrl->stats, |
| 574 | ctrl->cfg.verbose); |
| 575 | printf ("\nCLIENT: So long and thanks for all the fish!\n\n"); |
| 576 | sleep (1); |
| 577 | } |
| 578 | |
| 579 | static int |
| 580 | sock_test_connect_test_sockets (uint32_t num_test_sockets) |
| 581 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 582 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 583 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 584 | vcl_test_session_t *tsock; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 585 | int i, rv, errno_val; |
| 586 | |
| 587 | if (num_test_sockets < 1) |
| 588 | { |
| 589 | errno = EINVAL; |
| 590 | return -1; |
| 591 | } |
| 592 | |
| 593 | if (num_test_sockets < scm->num_test_sockets) |
| 594 | { |
| 595 | for (i = scm->num_test_sockets - 1; i >= num_test_sockets; i--) |
| 596 | { |
| 597 | tsock = &scm->test_socket[i]; |
| 598 | #ifdef VCL_TEST |
| 599 | vppcom_session_close (tsock->fd); |
| 600 | #else |
| 601 | close (tsock->fd); |
| 602 | #endif |
| 603 | free (tsock->txbuf); |
| 604 | free (tsock->rxbuf); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | else if (num_test_sockets > scm->num_test_sockets) |
| 609 | { |
| 610 | tsock = realloc (scm->test_socket, |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 611 | sizeof (vcl_test_session_t) * num_test_sockets); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 612 | if (!tsock) |
| 613 | { |
| 614 | errno_val = errno; |
| 615 | perror ("ERROR in sock_test_connect_test_sockets()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 616 | fprintf (stderr, "CLIENT: ERROR: socket failed (errno = %d)!\n", |
| 617 | errno_val); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 618 | return -1; |
| 619 | } |
| 620 | |
Dave Wallace | d48e976 | 2017-08-22 23:29:33 -0400 | [diff] [blame] | 621 | if (!scm->test_socket) |
| 622 | memset (tsock, 0, sizeof (*tsock)); |
| 623 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 624 | scm->test_socket = tsock; |
| 625 | for (i = scm->num_test_sockets; i < num_test_sockets; i++) |
| 626 | { |
| 627 | tsock = &scm->test_socket[i]; |
| 628 | #ifdef VCL_TEST |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 629 | tsock->fd = vppcom_session_create (ctrl->cfg.transport_udp ? |
| 630 | VPPCOM_PROTO_UDP : |
| 631 | VPPCOM_PROTO_TCP, |
| 632 | 1 /* is_nonblocking */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 633 | if (tsock->fd < 0) |
| 634 | { |
| 635 | errno = -tsock->fd; |
| 636 | tsock->fd = -1; |
| 637 | } |
| 638 | #else |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 639 | tsock->fd = socket (ctrl->cfg.address_ip6 ? AF_INET6 : AF_INET, |
| 640 | ctrl->cfg.transport_udp ? |
| 641 | SOCK_DGRAM : SOCK_STREAM, 0); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 642 | #endif |
| 643 | if (tsock->fd < 0) |
| 644 | { |
| 645 | errno_val = errno; |
| 646 | perror ("ERROR in sock_test_connect_test_sockets()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 647 | fprintf (stderr, "CLIENT: ERROR: socket failed (errno = %d)!\n", |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 648 | errno_val); |
| 649 | return tsock->fd; |
| 650 | } |
Florin Coras | c227e49 | 2018-12-21 19:28:34 -0800 | [diff] [blame^] | 651 | if (fcntl (tsock->fd, F_SETFL, O_NONBLOCK) < 0) |
| 652 | { |
| 653 | errno_val = errno; |
| 654 | perror ("ERROR in sock_test_connect_test_sockets()"); |
| 655 | fprintf (stderr, "CLIENT: ERROR: fcntl failed (errno = %d)!\n", |
| 656 | errno_val); |
| 657 | return -1; |
| 658 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 659 | |
| 660 | #ifdef VCL_TEST |
| 661 | rv = vppcom_session_connect (tsock->fd, &scm->server_endpt); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 662 | if (rv) |
| 663 | { |
| 664 | errno = -rv; |
| 665 | rv = -1; |
| 666 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 667 | #else |
| 668 | rv = |
| 669 | connect (tsock->fd, (struct sockaddr *) &scm->server_addr, |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 670 | scm->server_addr_size); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 671 | #endif |
| 672 | if (rv < 0) |
| 673 | { |
| 674 | errno_val = errno; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 675 | perror ("ERROR in sock_test_connect_test_sockets()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 676 | fprintf (stderr, "CLIENT: ERROR: connect failed " |
| 677 | "(errno = %d)!\n", errno_val); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 678 | return -1; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 679 | } |
| 680 | tsock->cfg = ctrl->cfg; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 681 | vcl_test_session_buf_alloc (tsock); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 682 | sock_test_cfg_sync (tsock); |
| 683 | |
| 684 | printf ("CLIENT (fd %d): Test socket %d connected.\n", |
| 685 | tsock->fd, i); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | scm->num_test_sockets = num_test_sockets; |
| 690 | printf ("CLIENT: All sockets (%d) connected!\n", scm->num_test_sockets + 1); |
| 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | static void |
| 695 | dump_help (void) |
| 696 | { |
| 697 | #define INDENT "\n " |
| 698 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 699 | printf ("CLIENT: Test configuration commands:" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 700 | INDENT VCL_TEST_TOKEN_HELP |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 701 | "\t\t\tDisplay help." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 702 | INDENT VCL_TEST_TOKEN_EXIT |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 703 | "\t\t\tExit test client & server." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 704 | INDENT VCL_TEST_TOKEN_SHOW_CFG |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 705 | "\t\t\tShow the current test cfg." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 706 | INDENT VCL_TEST_TOKEN_RUN_UNI |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 707 | "\t\t\tRun the Uni-directional test." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 708 | INDENT VCL_TEST_TOKEN_RUN_BI |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 709 | "\t\t\tRun the Bi-directional test." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 710 | INDENT VCL_TEST_TOKEN_VERBOSE |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 711 | "\t\t\tToggle verbose setting." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 712 | INDENT VCL_TEST_TOKEN_RXBUF_SIZE |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 713 | "<rxbuf size>\tRx buffer size (bytes)." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 714 | INDENT VCL_TEST_TOKEN_TXBUF_SIZE |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 715 | "<txbuf size>\tTx buffer size (bytes)." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 716 | INDENT VCL_TEST_TOKEN_NUM_WRITES |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 717 | "<# of writes>\tNumber of txbuf writes to server." "\n"); |
| 718 | } |
| 719 | |
| 720 | static void |
| 721 | cfg_txbuf_size_set (void) |
| 722 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 723 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 724 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 725 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_TXBUF_SIZE); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 726 | uint64_t txbuf_size = strtoull ((const char *) p, NULL, 10); |
| 727 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 728 | if (txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 729 | { |
| 730 | ctrl->cfg.txbuf_size = txbuf_size; |
| 731 | ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 732 | vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ , |
| 733 | (uint8_t **) & ctrl->txbuf, &ctrl->txbuf_size); |
| 734 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 735 | } |
| 736 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 737 | fprintf (stderr, "CLIENT: ERROR: Invalid txbuf size (%lu) < " |
| 738 | "minimum buf size (%u)!\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 739 | txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | static void |
| 743 | cfg_num_writes_set (void) |
| 744 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 745 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 746 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 747 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_WRITES); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 748 | uint32_t num_writes = strtoul ((const char *) p, NULL, 10); |
| 749 | |
| 750 | if (num_writes > 0) |
| 751 | { |
| 752 | ctrl->cfg.num_writes = num_writes; |
| 753 | ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 754 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 755 | } |
| 756 | else |
| 757 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 758 | fprintf (stderr, "CLIENT: ERROR: invalid num writes: %u\n", num_writes); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 759 | } |
| 760 | } |
| 761 | |
| 762 | static void |
| 763 | cfg_num_test_sockets_set (void) |
| 764 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 765 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 766 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 767 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_TEST_SESS); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 768 | uint32_t num_test_sockets = strtoul ((const char *) p, NULL, 10); |
| 769 | |
| 770 | if ((num_test_sockets > 0) && |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 771 | (num_test_sockets <= VCL_TEST_CFG_MAX_TEST_SESS)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 772 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 773 | ctrl->cfg.num_test_sessions = num_test_sockets; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 774 | sock_test_connect_test_sockets (num_test_sockets); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 775 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 776 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 777 | } |
| 778 | else |
| 779 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 780 | fprintf (stderr, "CLIENT: ERROR: invalid num test sockets: " |
| 781 | "%u, (%d max)\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 782 | num_test_sockets, VCL_TEST_CFG_MAX_TEST_SESS); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |
| 786 | static void |
| 787 | cfg_rxbuf_size_set (void) |
| 788 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 789 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 790 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 791 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_RXBUF_SIZE); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 792 | uint64_t rxbuf_size = strtoull ((const char *) p, NULL, 10); |
| 793 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 794 | if (rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 795 | { |
| 796 | ctrl->cfg.rxbuf_size = rxbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 797 | vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ , |
| 798 | (uint8_t **) & ctrl->rxbuf, &ctrl->rxbuf_size); |
| 799 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 800 | } |
| 801 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 802 | fprintf (stderr, "CLIENT: ERROR: Invalid rxbuf size (%lu) < " |
| 803 | "minimum buf size (%u)!\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 804 | rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | static void |
| 808 | cfg_verbose_toggle (void) |
| 809 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 810 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 811 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 812 | |
| 813 | ctrl->cfg.verbose = ctrl->cfg.verbose ? 0 : 1; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 814 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 815 | |
| 816 | } |
| 817 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 818 | static vcl_test_t |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 819 | parse_input () |
| 820 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 821 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 822 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
| 823 | vcl_test_t rv = VCL_TEST_TYPE_NONE; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 824 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 825 | if (!strncmp (VCL_TEST_TOKEN_EXIT, ctrl->txbuf, |
| 826 | strlen (VCL_TEST_TOKEN_EXIT))) |
| 827 | rv = VCL_TEST_TYPE_EXIT; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 828 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 829 | else if (!strncmp (VCL_TEST_TOKEN_HELP, ctrl->txbuf, |
| 830 | strlen (VCL_TEST_TOKEN_HELP))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 831 | dump_help (); |
| 832 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 833 | else if (!strncmp (VCL_TEST_TOKEN_SHOW_CFG, ctrl->txbuf, |
| 834 | strlen (VCL_TEST_TOKEN_SHOW_CFG))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 835 | scm->dump_cfg = 1; |
| 836 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 837 | else if (!strncmp (VCL_TEST_TOKEN_VERBOSE, ctrl->txbuf, |
| 838 | strlen (VCL_TEST_TOKEN_VERBOSE))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 839 | cfg_verbose_toggle (); |
| 840 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 841 | else if (!strncmp (VCL_TEST_TOKEN_TXBUF_SIZE, ctrl->txbuf, |
| 842 | strlen (VCL_TEST_TOKEN_TXBUF_SIZE))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 843 | cfg_txbuf_size_set (); |
| 844 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 845 | else if (!strncmp (VCL_TEST_TOKEN_NUM_TEST_SESS, ctrl->txbuf, |
| 846 | strlen (VCL_TEST_TOKEN_NUM_TEST_SESS))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 847 | cfg_num_test_sockets_set (); |
| 848 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 849 | else if (!strncmp (VCL_TEST_TOKEN_NUM_WRITES, ctrl->txbuf, |
| 850 | strlen (VCL_TEST_TOKEN_NUM_WRITES))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 851 | cfg_num_writes_set (); |
| 852 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 853 | else if (!strncmp (VCL_TEST_TOKEN_RXBUF_SIZE, ctrl->txbuf, |
| 854 | strlen (VCL_TEST_TOKEN_RXBUF_SIZE))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 855 | cfg_rxbuf_size_set (); |
| 856 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 857 | else if (!strncmp (VCL_TEST_TOKEN_RUN_UNI, ctrl->txbuf, |
| 858 | strlen (VCL_TEST_TOKEN_RUN_UNI))) |
| 859 | rv = ctrl->cfg.test = VCL_TEST_TYPE_UNI; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 860 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 861 | else if (!strncmp (VCL_TEST_TOKEN_RUN_BI, ctrl->txbuf, |
| 862 | strlen (VCL_TEST_TOKEN_RUN_BI))) |
| 863 | rv = ctrl->cfg.test = VCL_TEST_TYPE_BI; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 864 | |
| 865 | else |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 866 | rv = VCL_TEST_TYPE_ECHO; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 867 | |
| 868 | return rv; |
| 869 | } |
| 870 | |
| 871 | void |
| 872 | print_usage_and_exit (void) |
| 873 | { |
| 874 | fprintf (stderr, |
| 875 | "sock_test_client [OPTIONS] <ipaddr> <port>\n" |
| 876 | " OPTIONS\n" |
| 877 | " -h Print this message and exit.\n" |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 878 | " -6 Use IPv6\n" |
| 879 | " -u Use UDP transport layer\n" |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 880 | " -c Print test config before test.\n" |
| 881 | " -w <dir> Write test results to <dir>.\n" |
| 882 | " -X Exit after running test.\n" |
| 883 | " -E Run Echo test.\n" |
| 884 | " -N <num-writes> Test Cfg: number of writes.\n" |
| 885 | " -R <rxbuf-size> Test Cfg: rx buffer size.\n" |
| 886 | " -T <txbuf-size> Test Cfg: tx buffer size.\n" |
| 887 | " -U Run Uni-directional test.\n" |
| 888 | " -B Run Bi-directional test.\n" |
| 889 | " -V Verbose mode.\n"); |
| 890 | exit (1); |
| 891 | } |
| 892 | |
| 893 | int |
| 894 | main (int argc, char **argv) |
| 895 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 896 | sock_client_main_t *scm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 897 | vcl_test_session_t *ctrl = &scm->ctrl_socket; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 898 | int c, rv, errno_val; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 899 | vcl_test_t post_test = VCL_TEST_TYPE_NONE; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 900 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 901 | vcl_test_cfg_init (&ctrl->cfg); |
| 902 | vcl_test_session_buf_alloc (ctrl); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 903 | |
| 904 | opterr = 0; |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 905 | 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] | 906 | switch (c) |
| 907 | { |
| 908 | case 'c': |
| 909 | scm->dump_cfg = 1; |
| 910 | break; |
| 911 | |
| 912 | case 's': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 913 | if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1) |
| 914 | if (sscanf (optarg, "%u", &ctrl->cfg.num_test_sessions) != 1) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 915 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 916 | fprintf (stderr, "CLIENT: ERROR: Invalid value for " |
| 917 | "option -%c!\n", c); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 918 | print_usage_and_exit (); |
| 919 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 920 | if (!ctrl->cfg.num_test_sessions || |
| 921 | (ctrl->cfg.num_test_sessions > FD_SETSIZE)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 922 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 923 | fprintf (stderr, "CLIENT: ERROR: Invalid number of " |
| 924 | "sockets (%d) specified for option -%c!\n" |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 925 | " Valid range is 1 - %d\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 926 | ctrl->cfg.num_test_sessions, c, FD_SETSIZE); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 927 | print_usage_and_exit (); |
| 928 | } |
| 929 | break; |
| 930 | |
| 931 | case 'w': |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 932 | fprintf (stderr, "CLIENT: Writing test results to files is TBD.\n"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 933 | break; |
| 934 | |
| 935 | case 'X': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 936 | post_test = VCL_TEST_TYPE_EXIT; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 937 | break; |
| 938 | |
| 939 | case 'E': |
| 940 | if (strlen (optarg) > ctrl->txbuf_size) |
| 941 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 942 | fprintf (stderr, "CLIENT: ERROR: Option -%c value " |
| 943 | "larger than txbuf size (%d)!\n", |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 944 | optopt, ctrl->txbuf_size); |
| 945 | print_usage_and_exit (); |
| 946 | } |
| 947 | strcpy (ctrl->txbuf, optarg); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 948 | ctrl->cfg.test = VCL_TEST_TYPE_ECHO; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 949 | break; |
| 950 | |
| 951 | case 'I': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 952 | if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1) |
| 953 | if (sscanf (optarg, "%d", &ctrl->cfg.num_test_sessions) != 1) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 954 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 955 | fprintf (stderr, "CLIENT: ERROR: Invalid value for " |
| 956 | "option -%c!\n", c); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 957 | print_usage_and_exit (); |
| 958 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 959 | if (ctrl->cfg.num_test_sessions > VCL_TEST_CFG_MAX_TEST_SESS) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 960 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 961 | fprintf (stderr, "CLIENT: ERROR: value greater than max " |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 962 | "number test sockets (%d)!", VCL_TEST_CFG_MAX_TEST_SESS); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 963 | print_usage_and_exit (); |
| 964 | } |
| 965 | break; |
| 966 | |
| 967 | case 'N': |
| 968 | if (sscanf (optarg, "0x%lx", &ctrl->cfg.num_writes) != 1) |
| 969 | if (sscanf (optarg, "%ld", &ctrl->cfg.num_writes) != 1) |
| 970 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 971 | fprintf (stderr, "CLIENT: ERROR: Invalid value for " |
| 972 | "option -%c!\n", c); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 973 | print_usage_and_exit (); |
| 974 | } |
| 975 | ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
| 976 | break; |
| 977 | |
| 978 | case 'R': |
| 979 | if (sscanf (optarg, "0x%lx", &ctrl->cfg.rxbuf_size) != 1) |
| 980 | if (sscanf (optarg, "%ld", &ctrl->cfg.rxbuf_size) != 1) |
| 981 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 982 | fprintf (stderr, "CLIENT: ERROR: Invalid value for " |
| 983 | "option -%c!\n", c); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 984 | print_usage_and_exit (); |
| 985 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 986 | if (ctrl->cfg.rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 987 | { |
| 988 | ctrl->rxbuf_size = ctrl->cfg.rxbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 989 | vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ , |
| 990 | (uint8_t **) & ctrl->rxbuf, |
| 991 | &ctrl->rxbuf_size); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 992 | } |
| 993 | else |
| 994 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 995 | fprintf (stderr, "CLIENT: ERROR: rxbuf size (%lu) " |
| 996 | "less than minumum (%u)\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 997 | ctrl->cfg.rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 998 | print_usage_and_exit (); |
| 999 | } |
| 1000 | |
| 1001 | break; |
| 1002 | |
| 1003 | case 'T': |
| 1004 | if (sscanf (optarg, "0x%lx", &ctrl->cfg.txbuf_size) != 1) |
| 1005 | if (sscanf (optarg, "%ld", &ctrl->cfg.txbuf_size) != 1) |
| 1006 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1007 | fprintf (stderr, "CLIENT: ERROR: Invalid value " |
| 1008 | "for option -%c!\n", c); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1009 | print_usage_and_exit (); |
| 1010 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1011 | if (ctrl->cfg.txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1012 | { |
| 1013 | ctrl->txbuf_size = ctrl->cfg.txbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1014 | vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ , |
| 1015 | (uint8_t **) & ctrl->txbuf, |
| 1016 | &ctrl->txbuf_size); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1017 | ctrl->cfg.total_bytes = |
| 1018 | ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
| 1019 | } |
| 1020 | else |
| 1021 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1022 | fprintf (stderr, "CLIENT: ERROR: txbuf size (%lu) " |
| 1023 | "less than minumum (%u)!\n", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1024 | ctrl->cfg.txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1025 | print_usage_and_exit (); |
| 1026 | } |
| 1027 | break; |
| 1028 | |
| 1029 | case 'U': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1030 | ctrl->cfg.test = VCL_TEST_TYPE_UNI; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1031 | break; |
| 1032 | |
| 1033 | case 'B': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1034 | ctrl->cfg.test = VCL_TEST_TYPE_BI; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1035 | break; |
| 1036 | |
| 1037 | case 'V': |
| 1038 | ctrl->cfg.verbose = 1; |
| 1039 | break; |
| 1040 | |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1041 | case '6': |
| 1042 | ctrl->cfg.address_ip6 = 1; |
| 1043 | break; |
| 1044 | |
| 1045 | case 'D': |
| 1046 | ctrl->cfg.transport_udp = 1; |
| 1047 | break; |
| 1048 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1049 | case '?': |
| 1050 | switch (optopt) |
| 1051 | { |
| 1052 | case 'E': |
| 1053 | case 'I': |
| 1054 | case 'N': |
| 1055 | case 'R': |
| 1056 | case 'T': |
| 1057 | case 'w': |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1058 | fprintf (stderr, "CLIENT: ERROR: Option -%c " |
| 1059 | "requires an argument.\n", optopt); |
Chris Luke | ab7b8d9 | 2017-09-07 07:40:13 -0400 | [diff] [blame] | 1060 | break; |
| 1061 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1062 | default: |
| 1063 | if (isprint (optopt)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1064 | fprintf (stderr, "CLIENT: ERROR: Unknown " |
| 1065 | "option `-%c'.\n", optopt); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1066 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1067 | fprintf (stderr, "CLIENT: ERROR: Unknown " |
| 1068 | "option character `\\x%x'.\n", optopt); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1069 | } |
| 1070 | /* fall thru */ |
| 1071 | case 'h': |
| 1072 | default: |
| 1073 | print_usage_and_exit (); |
| 1074 | } |
| 1075 | |
| 1076 | if (argc < (optind + 2)) |
| 1077 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1078 | fprintf (stderr, "CLIENT: ERROR: Insufficient number of arguments!\n"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1079 | print_usage_and_exit (); |
| 1080 | } |
| 1081 | |
| 1082 | #ifdef VCL_TEST |
| 1083 | ctrl->fd = vppcom_app_create ("vcl_test_client"); |
| 1084 | if (ctrl->fd < 0) |
| 1085 | { |
| 1086 | errno = -ctrl->fd; |
| 1087 | ctrl->fd = -1; |
| 1088 | } |
| 1089 | else |
| 1090 | { |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1091 | ctrl->fd = vppcom_session_create (ctrl->cfg.transport_udp ? |
| 1092 | VPPCOM_PROTO_UDP : |
| 1093 | VPPCOM_PROTO_TCP, |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1094 | 0 /* is_nonblocking */ ); |
| 1095 | if (ctrl->fd < 0) |
| 1096 | { |
| 1097 | errno = -ctrl->fd; |
| 1098 | ctrl->fd = -1; |
| 1099 | } |
| 1100 | } |
| 1101 | #else |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1102 | ctrl->fd = socket (ctrl->cfg.address_ip6 ? AF_INET6 : AF_INET, |
| 1103 | ctrl->cfg.transport_udp ? SOCK_DGRAM : SOCK_STREAM, 0); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1104 | #endif |
| 1105 | |
| 1106 | if (ctrl->fd < 0) |
| 1107 | { |
| 1108 | errno_val = errno; |
| 1109 | perror ("ERROR in main()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1110 | fprintf (stderr, "CLIENT: ERROR: socket " |
| 1111 | "failed (errno = %d)!\n", errno_val); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1112 | return ctrl->fd; |
| 1113 | } |
| 1114 | |
| 1115 | memset (&scm->server_addr, 0, sizeof (scm->server_addr)); |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1116 | if (ctrl->cfg.address_ip6) |
| 1117 | { |
| 1118 | struct sockaddr_in6 *server_addr = |
| 1119 | (struct sockaddr_in6 *) &scm->server_addr; |
| 1120 | scm->server_addr_size = sizeof (*server_addr); |
| 1121 | server_addr->sin6_family = AF_INET6; |
| 1122 | inet_pton (AF_INET6, argv[optind++], &(server_addr->sin6_addr)); |
| 1123 | server_addr->sin6_port = htons (atoi (argv[optind])); |
| 1124 | } |
| 1125 | else |
| 1126 | { |
| 1127 | struct sockaddr_in *server_addr = |
| 1128 | (struct sockaddr_in *) &scm->server_addr; |
| 1129 | scm->server_addr_size = sizeof (*server_addr); |
| 1130 | server_addr->sin_family = AF_INET; |
| 1131 | inet_pton (AF_INET, argv[optind++], &(server_addr->sin_addr)); |
| 1132 | server_addr->sin_port = htons (atoi (argv[optind])); |
| 1133 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1134 | |
| 1135 | #ifdef VCL_TEST |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1136 | if (ctrl->cfg.address_ip6) |
| 1137 | { |
| 1138 | struct sockaddr_in6 *server_addr = |
| 1139 | (struct sockaddr_in6 *) &scm->server_addr; |
| 1140 | scm->server_endpt.is_ip4 = 0; |
| 1141 | scm->server_endpt.ip = (uint8_t *) & server_addr->sin6_addr; |
| 1142 | scm->server_endpt.port = (uint16_t) server_addr->sin6_port; |
| 1143 | } |
| 1144 | else |
| 1145 | { |
| 1146 | struct sockaddr_in *server_addr = |
| 1147 | (struct sockaddr_in *) &scm->server_addr; |
| 1148 | scm->server_endpt.is_ip4 = 1; |
| 1149 | scm->server_endpt.ip = (uint8_t *) & server_addr->sin_addr; |
| 1150 | scm->server_endpt.port = (uint16_t) server_addr->sin_port; |
| 1151 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1152 | #endif |
| 1153 | |
| 1154 | do |
| 1155 | { |
| 1156 | printf ("\nCLIENT: Connecting to server...\n"); |
| 1157 | |
| 1158 | #ifdef VCL_TEST |
| 1159 | rv = vppcom_session_connect (ctrl->fd, &scm->server_endpt); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1160 | if (rv) |
| 1161 | { |
| 1162 | errno = -rv; |
| 1163 | rv = -1; |
| 1164 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1165 | #else |
| 1166 | rv = |
| 1167 | connect (ctrl->fd, (struct sockaddr *) &scm->server_addr, |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 1168 | scm->server_addr_size); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1169 | #endif |
| 1170 | if (rv < 0) |
| 1171 | { |
| 1172 | errno_val = errno; |
| 1173 | perror ("ERROR in main()"); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1174 | fprintf (stderr, "CLIENT: ERROR: connect failed (errno = %d)!\n", |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1175 | errno_val); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1176 | return -1; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | sock_test_cfg_sync (ctrl); |
| 1180 | printf ("CLIENT (fd %d): Control socket connected.\n", ctrl->fd); |
| 1181 | } |
| 1182 | while (rv < 0); |
| 1183 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1184 | sock_test_connect_test_sockets (ctrl->cfg.num_test_sessions); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1185 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1186 | while (ctrl->cfg.test != VCL_TEST_TYPE_EXIT) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1187 | { |
| 1188 | if (scm->dump_cfg) |
| 1189 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1190 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1191 | scm->dump_cfg = 0; |
| 1192 | } |
| 1193 | |
| 1194 | switch (ctrl->cfg.test) |
| 1195 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1196 | case VCL_TEST_TYPE_ECHO: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1197 | echo_test_client (); |
| 1198 | break; |
| 1199 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1200 | case VCL_TEST_TYPE_UNI: |
| 1201 | case VCL_TEST_TYPE_BI: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1202 | stream_test_client (ctrl->cfg.test); |
| 1203 | break; |
| 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 | continue; |
| 1207 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1208 | case VCL_TEST_TYPE_NONE: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1209 | default: |
| 1210 | break; |
| 1211 | } |
| 1212 | switch (post_test) |
| 1213 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1214 | case VCL_TEST_TYPE_EXIT: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1215 | switch (ctrl->cfg.test) |
| 1216 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1217 | case VCL_TEST_TYPE_EXIT: |
| 1218 | case VCL_TEST_TYPE_UNI: |
| 1219 | case VCL_TEST_TYPE_BI: |
| 1220 | case VCL_TEST_TYPE_ECHO: |
| 1221 | ctrl->cfg.test = VCL_TEST_TYPE_EXIT; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1222 | continue; |
| 1223 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1224 | case VCL_TEST_TYPE_NONE: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1225 | default: |
| 1226 | break; |
| 1227 | } |
| 1228 | break; |
| 1229 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1230 | case VCL_TEST_TYPE_NONE: |
| 1231 | case VCL_TEST_TYPE_ECHO: |
| 1232 | case VCL_TEST_TYPE_UNI: |
| 1233 | case VCL_TEST_TYPE_BI: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1234 | default: |
| 1235 | break; |
| 1236 | } |
| 1237 | |
| 1238 | memset (ctrl->txbuf, 0, ctrl->txbuf_size); |
| 1239 | memset (ctrl->rxbuf, 0, ctrl->rxbuf_size); |
| 1240 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1241 | printf ("\nCLIENT: Type some characters and hit <return>\n" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1242 | "('" VCL_TEST_TOKEN_HELP "' for help): "); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1243 | |
| 1244 | if (fgets (ctrl->txbuf, ctrl->txbuf_size, stdin) != NULL) |
| 1245 | { |
| 1246 | if (strlen (ctrl->txbuf) == 1) |
| 1247 | { |
| 1248 | printf ("\nCLIENT: Nothing to send! Please try again...\n"); |
| 1249 | continue; |
| 1250 | } |
| 1251 | ctrl->txbuf[strlen (ctrl->txbuf) - 1] = 0; // chomp the newline. |
| 1252 | |
| 1253 | /* Parse input for keywords */ |
| 1254 | ctrl->cfg.test = parse_input (); |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | exit_client (); |
| 1259 | #ifdef VCL_TEST |
| 1260 | vppcom_session_close (ctrl->fd); |
| 1261 | vppcom_app_destroy (); |
Dave Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 1262 | return 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1263 | #else |
| 1264 | close (ctrl->fd); |
Dave Wallace | 3ee1fe1 | 2018-02-23 01:09:11 -0500 | [diff] [blame] | 1265 | 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] | 1266 | #endif |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | /* |
| 1270 | * fd.io coding-style-patch-verification: ON |
| 1271 | * |
| 1272 | * Local Variables: |
| 1273 | * eval: (c-set-style "gnu") |
| 1274 | * End: |
| 1275 | */ |