Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1 | /* |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Cisco and/or its affiliates. |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 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 | |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 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> |
| 25 | #include <vcl/vcl_test.h> |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 26 | #include <pthread.h> |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 27 | |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 28 | typedef struct |
| 29 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 30 | vcl_test_session_t *sessions; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 31 | uint32_t n_sessions; |
| 32 | uint32_t wrk_index; |
| 33 | fd_set wr_fdset; |
| 34 | fd_set rd_fdset; |
| 35 | int max_fd_index; |
| 36 | pthread_t thread_handle; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 37 | vcl_test_cfg_t cfg; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 38 | } vcl_test_client_worker_t; |
| 39 | |
| 40 | typedef struct |
| 41 | { |
| 42 | vcl_test_client_worker_t *workers; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 43 | vppcom_endpt_t server_endpt; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 44 | uint32_t cfg_seq_num; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 45 | vcl_test_session_t ctrl_session; |
| 46 | vcl_test_session_t *sessions; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 47 | uint8_t dump_cfg; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 48 | vcl_test_t post_test; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 49 | uint32_t proto; |
| 50 | uint32_t n_workers; |
| 51 | volatile int active_workers; |
| 52 | struct sockaddr_storage server_addr; |
| 53 | } vcl_test_client_main_t; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 54 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 55 | static __thread int __wrk_index = 0; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 56 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 57 | vcl_test_client_main_t vcl_client_main; |
| 58 | |
| 59 | #define vtc_min(a, b) (a < b ? a : b) |
| 60 | #define vtc_max(a, b) (a > b ? a : b) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 61 | |
| 62 | static int |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 63 | vtc_cfg_sync (vcl_test_session_t * ts) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 64 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 65 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 66 | vcl_test_cfg_t *rx_cfg = (vcl_test_cfg_t *) ts->rxbuf; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 67 | int rx_bytes, tx_bytes; |
| 68 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 69 | vt_atomic_add (&ts->cfg.seq_num, 1); |
| 70 | if (ts->cfg.verbose) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 71 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 72 | vtinf ("(fd %d): Sending config to server.", ts->fd); |
| 73 | vcl_test_cfg_dump (&ts->cfg, 1 /* is_client */ ); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 74 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 75 | tx_bytes = vcl_test_write (ts->fd, (uint8_t *) & ts->cfg, |
| 76 | sizeof (ts->cfg), NULL, ts->cfg.verbose); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 77 | if (tx_bytes < 0) |
| 78 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 79 | vtwrn ("(fd %d): write test cfg failed (%d)!", ts->fd, tx_bytes); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 80 | return tx_bytes; |
| 81 | } |
| 82 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 83 | rx_bytes = vcl_test_read (ts->fd, (uint8_t *) ts->rxbuf, |
| 84 | sizeof (vcl_test_cfg_t), NULL); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 85 | if (rx_bytes < 0) |
| 86 | return rx_bytes; |
| 87 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 88 | if (rx_cfg->magic != VCL_TEST_CFG_CTRL_MAGIC) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 89 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 90 | vtwrn ("(fd %d): Bad server reply cfg -- aborting!", ts->fd); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 91 | return -1; |
| 92 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 93 | if ((rx_bytes != sizeof (vcl_test_cfg_t)) |
| 94 | || !vcl_test_cfg_verify (rx_cfg, &ts->cfg)) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 95 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 96 | vtwrn ("(fd %d): Invalid config received from server!", ts->fd); |
| 97 | if (rx_bytes != sizeof (vcl_test_cfg_t)) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 98 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 99 | vtinf ("\tRx bytes %d != cfg size %lu", rx_bytes, |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 100 | sizeof (vcl_test_cfg_t)); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 101 | } |
| 102 | else |
| 103 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 104 | vcl_test_cfg_dump (rx_cfg, 1 /* is_client */ ); |
| 105 | vtinf ("(fd %d): Valid config sent to server.", ts->fd); |
| 106 | vcl_test_cfg_dump (&ts->cfg, 1 /* is_client */ ); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 107 | } |
| 108 | return -1; |
| 109 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 110 | if (ts->cfg.verbose) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 111 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 112 | vtinf ("(fd %d): Got config back from server.", ts->fd); |
| 113 | vcl_test_cfg_dump (rx_cfg, 1 /* is_client */ ); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 114 | } |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 119 | static int |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 120 | vtc_connect_test_sessions (vcl_test_client_worker_t * wrk) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 121 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 122 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 123 | vcl_test_session_t *ts; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 124 | uint32_t n_test_sessions; |
| 125 | int i, rv; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 126 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 127 | n_test_sessions = wrk->cfg.num_test_sessions; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 128 | if (n_test_sessions < 1) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 129 | { |
| 130 | errno = EINVAL; |
| 131 | return -1; |
| 132 | } |
| 133 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 134 | if (wrk->n_sessions >= n_test_sessions) |
| 135 | goto done; |
| 136 | |
| 137 | if (wrk->n_sessions) |
| 138 | wrk->sessions = realloc (wrk->sessions, |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 139 | n_test_sessions * sizeof (vcl_test_session_t)); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 140 | else |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 141 | wrk->sessions = calloc (n_test_sessions, sizeof (vcl_test_session_t)); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 142 | |
| 143 | if (!wrk->sessions) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 144 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 145 | vterr ("failed to alloc sessions", -errno); |
| 146 | return errno; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 147 | } |
| 148 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 149 | for (i = 0; i < n_test_sessions; i++) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 150 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 151 | ts = &wrk->sessions[i]; |
| 152 | ts->fd = vppcom_session_create (vcm->proto, 1 /* is_nonblocking */ ); |
| 153 | if (ts->fd < 0) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 154 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 155 | vterr ("vppcom_session_create()", ts->fd); |
| 156 | return ts->fd; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 159 | rv = vppcom_session_connect (ts->fd, &vcm->server_endpt); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 160 | if (rv < 0) |
| 161 | { |
| 162 | vterr ("vppcom_session_connect()", rv); |
| 163 | return rv; |
| 164 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 165 | vtinf ("Test session %d (fd %d) connected.", i, ts->fd); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 166 | } |
| 167 | wrk->n_sessions = n_test_sessions; |
| 168 | |
| 169 | done: |
| 170 | vtinf ("All test sessions (%d) connected!", n_test_sessions); |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | static int |
| 175 | vtc_worker_test_setup (vcl_test_client_worker_t * wrk) |
| 176 | { |
| 177 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 178 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
| 179 | vcl_test_cfg_t *cfg = &wrk->cfg; |
| 180 | vcl_test_session_t *ts; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 181 | uint32_t sidx; |
| 182 | int i, j; |
| 183 | |
| 184 | FD_ZERO (&wrk->wr_fdset); |
| 185 | FD_ZERO (&wrk->rd_fdset); |
| 186 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 187 | for (i = 0; i < cfg->num_test_sessions; i++) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 188 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 189 | ts = &wrk->sessions[i]; |
| 190 | ts->cfg = wrk->cfg; |
| 191 | vcl_test_session_buf_alloc (ts); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 192 | |
| 193 | switch (cfg->test) |
| 194 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 195 | case VCL_TEST_TYPE_ECHO: |
| 196 | memcpy (ts->txbuf, ctrl->txbuf, cfg->total_bytes); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 197 | break; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 198 | case VCL_TEST_TYPE_UNI: |
| 199 | case VCL_TEST_TYPE_BI: |
| 200 | for (j = 0; j < ts->txbuf_size; j++) |
| 201 | ts->txbuf[j] = j & 0xff; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 202 | break; |
| 203 | } |
| 204 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 205 | FD_SET (vppcom_session_index (ts->fd), &wrk->wr_fdset); |
| 206 | FD_SET (vppcom_session_index (ts->fd), &wrk->rd_fdset); |
| 207 | sidx = vppcom_session_index (ts->fd); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 208 | wrk->max_fd_index = vtc_max (sidx, wrk->max_fd_index); |
| 209 | } |
| 210 | wrk->max_fd_index += 1; |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int |
| 216 | vtc_worker_init (vcl_test_client_worker_t * wrk) |
| 217 | { |
| 218 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 219 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
| 220 | vcl_test_cfg_t *cfg = &wrk->cfg; |
| 221 | vcl_test_session_t *ts; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 222 | uint32_t i, n; |
| 223 | int rv, nbytes; |
| 224 | |
| 225 | __wrk_index = wrk->wrk_index; |
| 226 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 227 | vtinf ("Initializing worker %u ...", wrk->wrk_index); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 228 | |
| 229 | if (wrk->wrk_index) |
| 230 | { |
| 231 | if (vppcom_worker_register ()) |
| 232 | { |
| 233 | vtwrn ("failed to register worker"); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 234 | return -1; |
| 235 | } |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 236 | vt_atomic_add (&vcm->active_workers, 1); |
| 237 | } |
| 238 | rv = vtc_connect_test_sessions (wrk); |
| 239 | if (rv) |
| 240 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 241 | vterr ("vtc_connect_test_sessions ()", rv); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 242 | return rv; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 243 | } |
| 244 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 245 | if (vtc_worker_test_setup (wrk)) |
| 246 | return -1; |
| 247 | |
| 248 | vtinf ("Sending config to server on all sessions ..."); |
| 249 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 250 | for (n = 0; n < cfg->num_test_sessions; n++) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 251 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 252 | ts = &wrk->sessions[n]; |
| 253 | if (vtc_cfg_sync (ts)) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 254 | return -1; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 255 | memset (&ts->stats, 0, sizeof (ts->stats)); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 258 | return 0; |
| 259 | } |
| 260 | |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 261 | static int stats_lock = 0; |
| 262 | |
| 263 | static void |
| 264 | vtc_accumulate_stats (vcl_test_client_worker_t * wrk, |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 265 | vcl_test_session_t * ctrl) |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 266 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 267 | vcl_test_session_t *ts; |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 268 | static char buf[64]; |
| 269 | int i, show_rx = 0; |
| 270 | |
| 271 | while (__sync_lock_test_and_set (&stats_lock, 1)) |
| 272 | ; |
| 273 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 274 | if (ctrl->cfg.test == VCL_TEST_TYPE_BI |
| 275 | || ctrl->cfg.test == VCL_TEST_TYPE_ECHO) |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 276 | show_rx = 1; |
| 277 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 278 | for (i = 0; i < wrk->cfg.num_test_sessions; i++) |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 279 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 280 | ts = &wrk->sessions[i]; |
| 281 | ts->stats.start = ctrl->stats.start; |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 282 | |
| 283 | if (ctrl->cfg.verbose > 1) |
| 284 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 285 | sprintf (buf, "CLIENT (fd %d) RESULTS", ts->fd); |
| 286 | vcl_test_stats_dump (buf, &ts->stats, show_rx, 1 /* show tx */ , |
| 287 | ctrl->cfg.verbose); |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 290 | vcl_test_stats_accumulate (&ctrl->stats, &ts->stats); |
| 291 | if (vcl_comp_tspec (&ctrl->stats.stop, &ts->stats.stop) < 0) |
| 292 | ctrl->stats.stop = ts->stats.stop; |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | __sync_lock_release (&stats_lock); |
| 296 | } |
| 297 | |
| 298 | static void |
| 299 | vtc_worker_sessions_exit (vcl_test_client_worker_t * wrk) |
| 300 | { |
| 301 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 302 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
| 303 | vcl_test_session_t *ts; |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 304 | int i, verbose = ctrl->cfg.verbose; |
| 305 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 306 | for (i = 0; i < wrk->cfg.num_test_sessions; i++) |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 307 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 308 | ts = &wrk->sessions[i]; |
| 309 | ts->cfg.test = VCL_TEST_TYPE_EXIT; |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 310 | |
| 311 | if (verbose) |
| 312 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 313 | vtinf ("(fd %d): Sending exit cfg to server...", ts->fd); |
| 314 | vcl_test_cfg_dump (&ts->cfg, 1 /* is_client */ ); |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 315 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 316 | (void) vcl_test_write (ts->fd, (uint8_t *) & ts->cfg, |
| 317 | sizeof (ts->cfg), &ts->stats, verbose); |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 318 | } |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 319 | wrk->n_sessions = 0; |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 322 | static void * |
| 323 | vtc_worker_loop (void *arg) |
| 324 | { |
| 325 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 326 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 327 | vcl_test_client_worker_t *wrk = arg; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 328 | uint32_t n_active_sessions, n_bytes; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 329 | fd_set _wfdset, *wfdset = &_wfdset; |
| 330 | fd_set _rfdset, *rfdset = &_rfdset; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 331 | vcl_test_session_t *ts; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 332 | int i, rv, check_rx = 0; |
| 333 | |
| 334 | rv = vtc_worker_init (wrk); |
| 335 | if (rv) |
| 336 | { |
| 337 | vterr ("vtc_worker_init()", rv); |
| 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | vtinf ("Starting test ..."); |
| 342 | |
| 343 | if (wrk->wrk_index == 0) |
| 344 | clock_gettime (CLOCK_REALTIME, &ctrl->stats.start); |
| 345 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 346 | check_rx = wrk->cfg.test != VCL_TEST_TYPE_UNI; |
| 347 | n_active_sessions = wrk->cfg.num_test_sessions; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 348 | while (n_active_sessions) |
| 349 | { |
| 350 | _wfdset = wrk->wr_fdset; |
| 351 | _rfdset = wrk->rd_fdset; |
| 352 | |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 353 | rv = vppcom_select (wrk->max_fd_index, (unsigned long *) rfdset, |
| 354 | (unsigned long *) wfdset, NULL, 0); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 355 | if (rv < 0) |
| 356 | { |
| 357 | vterr ("vppcom_select()", rv); |
| 358 | goto exit; |
| 359 | } |
| 360 | else if (rv == 0) |
| 361 | continue; |
| 362 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 363 | for (i = 0; i < wrk->cfg.num_test_sessions; i++) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 364 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 365 | ts = &wrk->sessions[i]; |
| 366 | if (!((ts->stats.stop.tv_sec == 0) && |
| 367 | (ts->stats.stop.tv_nsec == 0))) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 368 | continue; |
| 369 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 370 | if (FD_ISSET (vppcom_session_index (ts->fd), rfdset) |
| 371 | && ts->stats.rx_bytes < ts->cfg.total_bytes) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 372 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 373 | (void) vcl_test_read (ts->fd, (uint8_t *) ts->rxbuf, |
| 374 | ts->rxbuf_size, &ts->stats); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 377 | if (FD_ISSET (vppcom_session_index (ts->fd), wfdset) |
| 378 | && ts->stats.tx_bytes < ts->cfg.total_bytes) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 379 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 380 | n_bytes = ts->cfg.txbuf_size; |
| 381 | if (ts->cfg.test == VCL_TEST_TYPE_ECHO) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 382 | n_bytes = strlen (ctrl->txbuf) + 1; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 383 | rv = vcl_test_write (ts->fd, (uint8_t *) ts->txbuf, |
| 384 | n_bytes, &ts->stats, ts->cfg.verbose); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 385 | if (rv < 0) |
| 386 | { |
| 387 | vtwrn ("vppcom_test_write (%d) failed -- aborting test", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 388 | ts->fd); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 389 | goto exit; |
| 390 | } |
| 391 | } |
| 392 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 393 | if ((!check_rx && ts->stats.tx_bytes >= ts->cfg.total_bytes) |
| 394 | || (check_rx && ts->stats.rx_bytes >= ts->cfg.total_bytes)) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 395 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 396 | clock_gettime (CLOCK_REALTIME, &ts->stats.stop); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 397 | n_active_sessions--; |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | exit: |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 402 | vtinf ("Worker %d done ...", wrk->wrk_index); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 403 | if (wrk->cfg.test != VCL_TEST_TYPE_ECHO) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 404 | vtc_accumulate_stats (wrk, ctrl); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 405 | sleep (VCL_TEST_DELAY_DISCONNECT); |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 406 | vtc_worker_sessions_exit (wrk); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 407 | if (wrk->wrk_index) |
| 408 | vt_atomic_add (&vcm->active_workers, -1); |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static void |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 413 | vtc_print_stats (vcl_test_session_t * ctrl) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 414 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 415 | int is_echo = ctrl->cfg.test == VCL_TEST_TYPE_ECHO; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 416 | int show_rx = 0; |
| 417 | char buf[64]; |
| 418 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 419 | if (ctrl->cfg.test == VCL_TEST_TYPE_BI |
| 420 | || ctrl->cfg.test == VCL_TEST_TYPE_ECHO) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 421 | show_rx = 1; |
| 422 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 423 | vcl_test_stats_dump ("CLIENT RESULTS", &ctrl->stats, |
| 424 | show_rx, 1 /* show tx */ , |
| 425 | ctrl->cfg.verbose); |
| 426 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 427 | |
| 428 | if (ctrl->cfg.verbose) |
| 429 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 430 | vtinf (" ctrl session info\n" |
| 431 | VCL_TEST_SEPARATOR_STRING |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 432 | " fd: %d (0x%08x)\n" |
| 433 | " rxbuf: %p\n" |
| 434 | " rxbuf size: %u (0x%08x)\n" |
| 435 | " txbuf: %p\n" |
| 436 | " txbuf size: %u (0x%08x)\n" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 437 | VCL_TEST_SEPARATOR_STRING, |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 438 | ctrl->fd, (uint32_t) ctrl->fd, |
| 439 | ctrl->rxbuf, ctrl->rxbuf_size, ctrl->rxbuf_size, |
| 440 | ctrl->txbuf, ctrl->txbuf_size, ctrl->txbuf_size); |
| 441 | } |
| 442 | |
| 443 | if (is_echo) |
| 444 | sprintf (buf, "Echo"); |
| 445 | else |
| 446 | sprintf (buf, "%s-directional Stream", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 447 | ctrl->cfg.test == VCL_TEST_TYPE_BI ? "Bi" : "Uni"); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static void |
| 451 | vtc_echo_client (vcl_test_client_main_t * vcm) |
| 452 | { |
| 453 | vcl_test_client_worker_t *wrk; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 454 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
| 455 | vcl_test_cfg_t *cfg = &ctrl->cfg; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 456 | |
| 457 | cfg->total_bytes = strlen (ctrl->txbuf) + 1; |
| 458 | memset (&ctrl->stats, 0, sizeof (ctrl->stats)); |
| 459 | |
| 460 | /* Echo works with only one worker */ |
| 461 | wrk = vcm->workers; |
| 462 | wrk->wrk_index = 0; |
| 463 | wrk->cfg = *cfg; |
| 464 | |
| 465 | vtc_worker_loop (wrk); |
| 466 | |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 467 | /* Not relevant for echo test |
| 468 | clock_gettime (CLOCK_REALTIME, &ctrl->stats.stop); |
| 469 | vtc_accumulate_stats (wrk, ctrl); |
| 470 | vtc_print_stats (ctrl); |
| 471 | */ |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static void |
| 475 | vtc_stream_client (vcl_test_client_main_t * vcm) |
| 476 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 477 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
| 478 | vcl_test_cfg_t *cfg = &ctrl->cfg; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 479 | vcl_test_client_worker_t *wrk; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 480 | vcl_test_session_t *ts; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 481 | int tx_bytes, rv; |
| 482 | uint32_t i, n, sidx, n_conn, n_conn_per_wrk; |
| 483 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 484 | vtinf ("%s-directional Stream Test Starting!", |
| 485 | ctrl->cfg.test == VCL_TEST_TYPE_BI ? "Bi" : "Uni"); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 486 | |
| 487 | cfg->total_bytes = cfg->num_writes * cfg->txbuf_size; |
| 488 | cfg->ctrl_handle = ~0; |
| 489 | if (vtc_cfg_sync (ctrl)) |
| 490 | { |
| 491 | vtwrn ("test cfg sync failed -- aborting!"); |
| 492 | return; |
| 493 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 494 | cfg->ctrl_handle = ((vcl_test_cfg_t *) ctrl->rxbuf)->ctrl_handle; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 495 | memset (&ctrl->stats, 0, sizeof (ctrl->stats)); |
| 496 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 497 | n_conn = cfg->num_test_sessions; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 498 | n_conn_per_wrk = n_conn / vcm->n_workers; |
| 499 | for (i = 0; i < vcm->n_workers; i++) |
| 500 | { |
| 501 | wrk = &vcm->workers[i]; |
| 502 | wrk->wrk_index = i; |
| 503 | wrk->cfg = ctrl->cfg; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 504 | wrk->cfg.num_test_sessions = vtc_min (n_conn_per_wrk, n_conn); |
| 505 | n_conn -= wrk->cfg.num_test_sessions; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | for (i = 1; i < vcm->n_workers; i++) |
| 509 | { |
| 510 | wrk = &vcm->workers[i]; |
| 511 | pthread_create (&wrk->thread_handle, NULL, vtc_worker_loop, |
| 512 | (void *) wrk); |
| 513 | } |
| 514 | vtc_worker_loop (&vcm->workers[0]); |
| 515 | |
| 516 | while (vcm->active_workers > 0) |
| 517 | ; |
| 518 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 519 | vtinf ("Sending config on ctrl session (fd %d) for stats...", ctrl->fd); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 520 | if (vtc_cfg_sync (ctrl)) |
| 521 | { |
| 522 | vtwrn ("test cfg sync failed -- aborting!"); |
| 523 | return; |
| 524 | } |
| 525 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 526 | vtc_print_stats (ctrl); |
| 527 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 528 | ctrl->cfg.test = VCL_TEST_TYPE_ECHO; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 529 | ctrl->cfg.total_bytes = 0; |
| 530 | if (vtc_cfg_sync (ctrl)) |
| 531 | vtwrn ("post-test cfg sync failed!"); |
| 532 | } |
| 533 | |
| 534 | static void |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 535 | dump_help (void) |
| 536 | { |
| 537 | #define INDENT "\n " |
| 538 | |
| 539 | printf ("CLIENT: Test configuration commands:" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 540 | INDENT VCL_TEST_TOKEN_HELP |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 541 | "\t\t\tDisplay help." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 542 | INDENT VCL_TEST_TOKEN_EXIT |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 543 | "\t\t\tExit test client & server." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 544 | INDENT VCL_TEST_TOKEN_SHOW_CFG |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 545 | "\t\t\tShow the current test cfg." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 546 | INDENT VCL_TEST_TOKEN_RUN_UNI |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 547 | "\t\t\tRun the Uni-directional test." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 548 | INDENT VCL_TEST_TOKEN_RUN_BI |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 549 | "\t\t\tRun the Bi-directional test." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 550 | INDENT VCL_TEST_TOKEN_VERBOSE |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 551 | "\t\t\tToggle verbose setting." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 552 | INDENT VCL_TEST_TOKEN_RXBUF_SIZE |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 553 | "<rxbuf size>\tRx buffer size (bytes)." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 554 | INDENT VCL_TEST_TOKEN_TXBUF_SIZE |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 555 | "<txbuf size>\tTx buffer size (bytes)." |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 556 | INDENT VCL_TEST_TOKEN_NUM_WRITES |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 557 | "<# of writes>\tNumber of txbuf writes to server." "\n"); |
| 558 | } |
| 559 | |
| 560 | static void |
| 561 | cfg_txbuf_size_set (void) |
| 562 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 563 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 564 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
| 565 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_TXBUF_SIZE); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 566 | uint64_t txbuf_size = strtoull ((const char *) p, NULL, 10); |
| 567 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 568 | if (txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 569 | { |
| 570 | ctrl->cfg.txbuf_size = txbuf_size; |
| 571 | ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 572 | vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ , |
| 573 | (uint8_t **) & ctrl->txbuf, &ctrl->txbuf_size); |
| 574 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 575 | } |
| 576 | else |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 577 | vtwrn ("Invalid txbuf size (%lu) < minimum buf size (%u)!", |
| 578 | txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static void |
| 582 | cfg_num_writes_set (void) |
| 583 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 584 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 585 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
| 586 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_WRITES); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 587 | uint32_t num_writes = strtoul ((const char *) p, NULL, 10); |
| 588 | |
| 589 | if (num_writes > 0) |
| 590 | { |
| 591 | ctrl->cfg.num_writes = num_writes; |
| 592 | ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 593 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 594 | } |
| 595 | else |
| 596 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 597 | vtwrn ("invalid num writes: %u", num_writes); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | |
| 601 | static void |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 602 | cfg_num_test_sessions_set (void) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 603 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 604 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 605 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
| 606 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_TEST_SESS); |
| 607 | uint32_t num_test_sessions = strtoul ((const char *) p, NULL, 10); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 608 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 609 | if ((num_test_sessions > 0) && |
| 610 | (num_test_sessions <= VCL_TEST_CFG_MAX_TEST_SESS)) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 611 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 612 | ctrl->cfg.num_test_sessions = num_test_sessions; |
| 613 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 614 | } |
| 615 | else |
| 616 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 617 | vtwrn ("invalid num test sessions: %u, (%d max)", |
| 618 | num_test_sessions, VCL_TEST_CFG_MAX_TEST_SESS); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | |
| 622 | static void |
| 623 | cfg_rxbuf_size_set (void) |
| 624 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 625 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 626 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
| 627 | char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_RXBUF_SIZE); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 628 | uint64_t rxbuf_size = strtoull ((const char *) p, NULL, 10); |
| 629 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 630 | if (rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 631 | { |
| 632 | ctrl->cfg.rxbuf_size = rxbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 633 | vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ , |
| 634 | (uint8_t **) & ctrl->rxbuf, &ctrl->rxbuf_size); |
| 635 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 636 | } |
| 637 | else |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 638 | vtwrn ("Invalid rxbuf size (%lu) < minimum buf size (%u)!", |
| 639 | rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | static void |
| 643 | cfg_verbose_toggle (void) |
| 644 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 645 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 646 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 647 | |
| 648 | ctrl->cfg.verbose = ctrl->cfg.verbose ? 0 : 1; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 649 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 650 | |
| 651 | } |
| 652 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 653 | static vcl_test_t |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 654 | parse_input () |
| 655 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 656 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 657 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
| 658 | vcl_test_t rv = VCL_TEST_TYPE_NONE; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 659 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 660 | if (!strncmp (VCL_TEST_TOKEN_EXIT, ctrl->txbuf, |
| 661 | strlen (VCL_TEST_TOKEN_EXIT))) |
| 662 | rv = VCL_TEST_TYPE_EXIT; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 663 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 664 | else if (!strncmp (VCL_TEST_TOKEN_HELP, ctrl->txbuf, |
| 665 | strlen (VCL_TEST_TOKEN_HELP))) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 666 | dump_help (); |
| 667 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 668 | else if (!strncmp (VCL_TEST_TOKEN_SHOW_CFG, ctrl->txbuf, |
| 669 | strlen (VCL_TEST_TOKEN_SHOW_CFG))) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 670 | vcm->dump_cfg = 1; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 671 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 672 | else if (!strncmp (VCL_TEST_TOKEN_VERBOSE, ctrl->txbuf, |
| 673 | strlen (VCL_TEST_TOKEN_VERBOSE))) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 674 | cfg_verbose_toggle (); |
| 675 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 676 | else if (!strncmp (VCL_TEST_TOKEN_TXBUF_SIZE, ctrl->txbuf, |
| 677 | strlen (VCL_TEST_TOKEN_TXBUF_SIZE))) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 678 | cfg_txbuf_size_set (); |
| 679 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 680 | else if (!strncmp (VCL_TEST_TOKEN_NUM_TEST_SESS, ctrl->txbuf, |
| 681 | strlen (VCL_TEST_TOKEN_NUM_TEST_SESS))) |
| 682 | cfg_num_test_sessions_set (); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 683 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 684 | else if (!strncmp (VCL_TEST_TOKEN_NUM_WRITES, ctrl->txbuf, |
| 685 | strlen (VCL_TEST_TOKEN_NUM_WRITES))) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 686 | cfg_num_writes_set (); |
| 687 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 688 | else if (!strncmp (VCL_TEST_TOKEN_RXBUF_SIZE, ctrl->txbuf, |
| 689 | strlen (VCL_TEST_TOKEN_RXBUF_SIZE))) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 690 | cfg_rxbuf_size_set (); |
| 691 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 692 | else if (!strncmp (VCL_TEST_TOKEN_RUN_UNI, ctrl->txbuf, |
| 693 | strlen (VCL_TEST_TOKEN_RUN_UNI))) |
| 694 | rv = ctrl->cfg.test = VCL_TEST_TYPE_UNI; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 695 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 696 | else if (!strncmp (VCL_TEST_TOKEN_RUN_BI, ctrl->txbuf, |
| 697 | strlen (VCL_TEST_TOKEN_RUN_BI))) |
| 698 | rv = ctrl->cfg.test = VCL_TEST_TYPE_BI; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 699 | |
| 700 | else |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 701 | rv = VCL_TEST_TYPE_ECHO; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 702 | |
| 703 | return rv; |
| 704 | } |
| 705 | |
| 706 | void |
| 707 | print_usage_and_exit (void) |
| 708 | { |
| 709 | fprintf (stderr, |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 710 | "vcl_test_client [OPTIONS] <ipaddr> <port>\n" |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 711 | " OPTIONS\n" |
| 712 | " -h Print this message and exit.\n" |
| 713 | " -6 Use IPv6\n" |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 714 | " -c Print test config before test.\n" |
| 715 | " -w <dir> Write test results to <dir>.\n" |
| 716 | " -X Exit after running test.\n" |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 717 | " -D Use UDP transport layer\n" |
Dave Wallace | 03dd90a | 2019-03-25 19:34:50 -0400 | [diff] [blame] | 718 | " -L Use TLS transport layer\n" |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 719 | " -E Run Echo test.\n" |
| 720 | " -N <num-writes> Test Cfg: number of writes.\n" |
| 721 | " -R <rxbuf-size> Test Cfg: rx buffer size.\n" |
| 722 | " -T <txbuf-size> Test Cfg: tx buffer size.\n" |
| 723 | " -U Run Uni-directional test.\n" |
| 724 | " -B Run Bi-directional test.\n" |
| 725 | " -V Verbose mode.\n"); |
| 726 | exit (1); |
| 727 | } |
| 728 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 729 | static void |
| 730 | vtc_process_opts (vcl_test_client_main_t * vcm, int argc, char **argv) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 731 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 732 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 733 | int c, v; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 734 | |
| 735 | opterr = 0; |
Dave Wallace | 03dd90a | 2019-03-25 19:34:50 -0400 | [diff] [blame] | 736 | while ((c = getopt (argc, argv, "chn:w:XE:I:N:R:T:UBV6DL")) != -1) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 737 | switch (c) |
| 738 | { |
| 739 | case 'c': |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 740 | vcm->dump_cfg = 1; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 741 | break; |
| 742 | |
| 743 | case 's': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 744 | if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1) |
| 745 | if (sscanf (optarg, "%u", &ctrl->cfg.num_test_sessions) != 1) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 746 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 747 | vtwrn ("Invalid value for option -%c!", c); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 748 | print_usage_and_exit (); |
| 749 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 750 | if (!ctrl->cfg.num_test_sessions || |
| 751 | (ctrl->cfg.num_test_sessions > FD_SETSIZE)) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 752 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 753 | vtwrn ("Invalid number of sessions (%d) specified for option -%c!" |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 754 | "\n Valid range is 1 - %d", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 755 | ctrl->cfg.num_test_sessions, c, FD_SETSIZE); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 756 | print_usage_and_exit (); |
| 757 | } |
| 758 | break; |
| 759 | |
| 760 | case 'w': |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 761 | if (sscanf (optarg, "%d", &v) != 1) |
| 762 | { |
| 763 | vtwrn ("Invalid value for option -%c!", c); |
| 764 | print_usage_and_exit (); |
| 765 | } |
| 766 | if (v > 1) |
| 767 | vcm->n_workers = v; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case 'X': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 771 | vcm->post_test = VCL_TEST_TYPE_EXIT; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 772 | break; |
| 773 | |
| 774 | case 'E': |
| 775 | if (strlen (optarg) > ctrl->txbuf_size) |
| 776 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 777 | vtwrn ("Option -%c value larger than txbuf size (%d)!", |
| 778 | optopt, ctrl->txbuf_size); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 779 | print_usage_and_exit (); |
| 780 | } |
| 781 | strcpy (ctrl->txbuf, optarg); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 782 | ctrl->cfg.test = VCL_TEST_TYPE_ECHO; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 783 | break; |
| 784 | |
| 785 | case 'I': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 786 | if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1) |
| 787 | if (sscanf (optarg, "%d", &ctrl->cfg.num_test_sessions) != 1) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 788 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 789 | vtwrn ("Invalid value for option -%c!", c); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 790 | print_usage_and_exit (); |
| 791 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 792 | if (ctrl->cfg.num_test_sessions > VCL_TEST_CFG_MAX_TEST_SESS) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 793 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 794 | vtwrn ("value greater than max number test sessions (%d)!", |
| 795 | VCL_TEST_CFG_MAX_TEST_SESS); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 796 | print_usage_and_exit (); |
| 797 | } |
| 798 | break; |
| 799 | |
| 800 | case 'N': |
| 801 | if (sscanf (optarg, "0x%lx", &ctrl->cfg.num_writes) != 1) |
| 802 | if (sscanf (optarg, "%ld", &ctrl->cfg.num_writes) != 1) |
| 803 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 804 | vtwrn ("Invalid value for option -%c!", c); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 805 | print_usage_and_exit (); |
| 806 | } |
| 807 | ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
| 808 | break; |
| 809 | |
| 810 | case 'R': |
| 811 | if (sscanf (optarg, "0x%lx", &ctrl->cfg.rxbuf_size) != 1) |
| 812 | if (sscanf (optarg, "%ld", &ctrl->cfg.rxbuf_size) != 1) |
| 813 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 814 | vtwrn ("Invalid value for option -%c!", c); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 815 | print_usage_and_exit (); |
| 816 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 817 | if (ctrl->cfg.rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 818 | { |
| 819 | ctrl->rxbuf_size = ctrl->cfg.rxbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 820 | vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ , |
| 821 | (uint8_t **) & ctrl->rxbuf, |
| 822 | &ctrl->rxbuf_size); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 823 | } |
| 824 | else |
| 825 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 826 | vtwrn ("rxbuf size (%lu) less than minumum (%u)", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 827 | ctrl->cfg.rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 828 | print_usage_and_exit (); |
| 829 | } |
| 830 | |
| 831 | break; |
| 832 | |
| 833 | case 'T': |
| 834 | if (sscanf (optarg, "0x%lx", &ctrl->cfg.txbuf_size) != 1) |
| 835 | if (sscanf (optarg, "%ld", &ctrl->cfg.txbuf_size) != 1) |
| 836 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 837 | vtwrn ("Invalid value for option -%c!", c); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 838 | print_usage_and_exit (); |
| 839 | } |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 840 | if (ctrl->cfg.txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 841 | { |
| 842 | ctrl->txbuf_size = ctrl->cfg.txbuf_size; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 843 | vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ , |
| 844 | (uint8_t **) & ctrl->txbuf, |
| 845 | &ctrl->txbuf_size); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 846 | ctrl->cfg.total_bytes = |
| 847 | ctrl->cfg.num_writes * ctrl->cfg.txbuf_size; |
| 848 | } |
| 849 | else |
| 850 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 851 | vtwrn ("txbuf size (%lu) less than minumum (%u)!", |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 852 | ctrl->cfg.txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 853 | print_usage_and_exit (); |
| 854 | } |
| 855 | break; |
| 856 | |
| 857 | case 'U': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 858 | ctrl->cfg.test = VCL_TEST_TYPE_UNI; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 859 | break; |
| 860 | |
| 861 | case 'B': |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 862 | ctrl->cfg.test = VCL_TEST_TYPE_BI; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 863 | break; |
| 864 | |
| 865 | case 'V': |
| 866 | ctrl->cfg.verbose = 1; |
| 867 | break; |
| 868 | |
| 869 | case '6': |
| 870 | ctrl->cfg.address_ip6 = 1; |
| 871 | break; |
| 872 | |
| 873 | case 'D': |
| 874 | ctrl->cfg.transport_udp = 1; |
| 875 | break; |
| 876 | |
Dave Wallace | 03dd90a | 2019-03-25 19:34:50 -0400 | [diff] [blame] | 877 | case 'L': |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 878 | ctrl->cfg.transport_tls = 1; |
| 879 | break; |
| 880 | |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 881 | case '?': |
| 882 | switch (optopt) |
| 883 | { |
| 884 | case 'E': |
| 885 | case 'I': |
| 886 | case 'N': |
| 887 | case 'R': |
| 888 | case 'T': |
| 889 | case 'w': |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 890 | vtwrn ("Option -%c requires an argument.", optopt); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 891 | break; |
| 892 | |
| 893 | default: |
| 894 | if (isprint (optopt)) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 895 | vtwrn ("Unknown option `-%c'.", optopt); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 896 | else |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 897 | vtwrn ("Unknown option character `\\x%x'.", optopt); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 898 | } |
| 899 | /* fall thru */ |
| 900 | case 'h': |
| 901 | default: |
| 902 | print_usage_and_exit (); |
| 903 | } |
| 904 | |
| 905 | if (argc < (optind + 2)) |
| 906 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 907 | vtwrn ("Insufficient number of arguments!"); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 908 | print_usage_and_exit (); |
| 909 | } |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 910 | |
| 911 | if (ctrl->cfg.transport_udp) |
| 912 | { |
| 913 | vcm->proto = VPPCOM_PROTO_UDP; |
| 914 | } |
| 915 | else if (ctrl->cfg.transport_tls) |
| 916 | { |
| 917 | vcm->proto = VPPCOM_PROTO_TLS; |
| 918 | } |
| 919 | else |
| 920 | { |
| 921 | vcm->proto = VPPCOM_PROTO_TCP; |
| 922 | } |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 923 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 924 | memset (&vcm->server_addr, 0, sizeof (vcm->server_addr)); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 925 | if (ctrl->cfg.address_ip6) |
| 926 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 927 | struct sockaddr_in6 *sddr6 = (struct sockaddr_in6 *) &vcm->server_addr; |
| 928 | sddr6->sin6_family = AF_INET6; |
| 929 | inet_pton (AF_INET6, argv[optind++], &(sddr6->sin6_addr)); |
| 930 | sddr6->sin6_port = htons (atoi (argv[optind])); |
| 931 | |
| 932 | vcm->server_endpt.is_ip4 = 0; |
| 933 | vcm->server_endpt.ip = (uint8_t *) & sddr6->sin6_addr; |
| 934 | vcm->server_endpt.port = (uint16_t) sddr6->sin6_port; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 935 | } |
| 936 | else |
| 937 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 938 | struct sockaddr_in *saddr4 = (struct sockaddr_in *) &vcm->server_addr; |
| 939 | saddr4->sin_family = AF_INET; |
| 940 | inet_pton (AF_INET, argv[optind++], &(saddr4->sin_addr)); |
| 941 | saddr4->sin_port = htons (atoi (argv[optind])); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 942 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 943 | vcm->server_endpt.is_ip4 = 1; |
| 944 | vcm->server_endpt.ip = (uint8_t *) & saddr4->sin_addr; |
| 945 | vcm->server_endpt.port = (uint16_t) saddr4->sin_port; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 946 | } |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 947 | } |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 948 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 949 | static void |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 950 | vtc_read_user_input (vcl_test_session_t * ctrl) |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 951 | { |
| 952 | printf ("\nType some characters and hit <return>\n" |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 953 | "('" VCL_TEST_TOKEN_HELP "' for help): "); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 954 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 955 | if (fgets (ctrl->txbuf, ctrl->txbuf_size, stdin) != NULL) |
| 956 | { |
| 957 | if (strlen (ctrl->txbuf) == 1) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 958 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 959 | printf ("\nNothing to send! Please try again...\n"); |
| 960 | return; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 961 | } |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 962 | ctrl->txbuf[strlen (ctrl->txbuf) - 1] = 0; // chomp the newline. |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 963 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 964 | /* Parse input for keywords */ |
| 965 | ctrl->cfg.test = parse_input (); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 966 | } |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 967 | } |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 968 | |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 969 | static void |
| 970 | vtc_ctrl_session_exit (void) |
| 971 | { |
| 972 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 973 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 974 | int verbose = ctrl->cfg.verbose; |
| 975 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 976 | ctrl->cfg.test = VCL_TEST_TYPE_EXIT; |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 977 | if (verbose) |
| 978 | { |
| 979 | vtinf ("(fd %d): Sending exit cfg to server...", ctrl->fd); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 980 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 981 | } |
| 982 | (void) vcl_test_write (ctrl->fd, (uint8_t *) & ctrl->cfg, |
| 983 | sizeof (ctrl->cfg), &ctrl->stats, verbose); |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 984 | sleep (1); |
| 985 | } |
| 986 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 987 | int |
| 988 | main (int argc, char **argv) |
| 989 | { |
| 990 | vcl_test_client_main_t *vcm = &vcl_client_main; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 991 | vcl_test_session_t *ctrl = &vcm->ctrl_session; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 992 | int rv, errno_val; |
| 993 | |
| 994 | vcm->n_workers = 1; |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 995 | vcl_test_cfg_init (&ctrl->cfg); |
| 996 | vcl_test_session_buf_alloc (ctrl); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 997 | vtc_process_opts (vcm, argc, argv); |
| 998 | |
| 999 | vcm->workers = calloc (vcm->n_workers, sizeof (vcl_test_client_worker_t)); |
| 1000 | rv = vppcom_app_create ("vcl_test_client"); |
| 1001 | if (rv < 0) |
| 1002 | vtfail ("vppcom_app_create()", rv); |
| 1003 | |
| 1004 | ctrl->fd = vppcom_session_create (vcm->proto, 0 /* is_nonblocking */ ); |
| 1005 | if (ctrl->fd < 0) |
| 1006 | vtfail ("vppcom_session_create()", ctrl->fd); |
| 1007 | |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 1008 | if (vcm->proto == VPPCOM_PROTO_TLS) |
| 1009 | { |
Florin Coras | 8a14061 | 2019-02-18 22:39:39 -0800 | [diff] [blame] | 1010 | vtinf ("Adding tls certs ..."); |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 1011 | vppcom_session_tls_add_cert (ctrl->fd, vcl_test_crt_rsa, |
| 1012 | vcl_test_crt_rsa_len); |
| 1013 | vppcom_session_tls_add_key (ctrl->fd, vcl_test_key_rsa, |
| 1014 | vcl_test_key_rsa_len); |
| 1015 | } |
| 1016 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 1017 | vtinf ("Connecting to server..."); |
| 1018 | rv = vppcom_session_connect (ctrl->fd, &vcm->server_endpt); |
| 1019 | if (rv) |
| 1020 | vtfail ("vppcom_session_connect()", rv); |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1021 | vtinf ("Control session (fd %d) connected.", ctrl->fd); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 1022 | |
| 1023 | rv = vtc_cfg_sync (ctrl); |
| 1024 | if (rv) |
| 1025 | vtfail ("vtc_cfg_sync()", rv); |
| 1026 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1027 | ctrl->cfg.ctrl_handle = ((vcl_test_cfg_t *) ctrl->rxbuf)->ctrl_handle; |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 1028 | memset (&ctrl->stats, 0, sizeof (ctrl->stats)); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1029 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1030 | while (ctrl->cfg.test != VCL_TEST_TYPE_EXIT) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1031 | { |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 1032 | if (vcm->dump_cfg) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1033 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1034 | vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ ); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 1035 | vcm->dump_cfg = 0; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | switch (ctrl->cfg.test) |
| 1039 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1040 | case VCL_TEST_TYPE_ECHO: |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 1041 | vtc_echo_client (vcm); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1042 | break; |
| 1043 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1044 | case VCL_TEST_TYPE_UNI: |
| 1045 | case VCL_TEST_TYPE_BI: |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 1046 | vtc_stream_client (vcm); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1047 | break; |
| 1048 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1049 | case VCL_TEST_TYPE_EXIT: |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1050 | continue; |
| 1051 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1052 | case VCL_TEST_TYPE_NONE: |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1053 | default: |
| 1054 | break; |
| 1055 | } |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 1056 | switch (vcm->post_test) |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1057 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1058 | case VCL_TEST_TYPE_EXIT: |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1059 | switch (ctrl->cfg.test) |
| 1060 | { |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1061 | case VCL_TEST_TYPE_EXIT: |
| 1062 | case VCL_TEST_TYPE_UNI: |
| 1063 | case VCL_TEST_TYPE_BI: |
| 1064 | case VCL_TEST_TYPE_ECHO: |
| 1065 | ctrl->cfg.test = VCL_TEST_TYPE_EXIT; |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1066 | continue; |
| 1067 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1068 | case VCL_TEST_TYPE_NONE: |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1069 | default: |
| 1070 | break; |
| 1071 | } |
| 1072 | break; |
| 1073 | |
Florin Coras | 1502fc3 | 2018-10-05 00:50:30 -0700 | [diff] [blame] | 1074 | case VCL_TEST_TYPE_NONE: |
| 1075 | case VCL_TEST_TYPE_ECHO: |
| 1076 | case VCL_TEST_TYPE_UNI: |
| 1077 | case VCL_TEST_TYPE_BI: |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1078 | default: |
| 1079 | break; |
| 1080 | } |
| 1081 | |
| 1082 | memset (ctrl->txbuf, 0, ctrl->txbuf_size); |
| 1083 | memset (ctrl->rxbuf, 0, ctrl->rxbuf_size); |
| 1084 | |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 1085 | vtc_read_user_input (ctrl); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1086 | } |
| 1087 | |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 1088 | vtc_ctrl_session_exit (); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1089 | vppcom_session_close (ctrl->fd); |
| 1090 | vppcom_app_destroy (); |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 1091 | free (vcm->workers); |
Dave Wallace | e4d5a65 | 2018-06-24 21:21:21 -0400 | [diff] [blame] | 1092 | return 0; |
| 1093 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1094 | |
| 1095 | /* |
| 1096 | * fd.io coding-style-patch-verification: ON |
| 1097 | * |
| 1098 | * Local Variables: |
| 1099 | * eval: (c-set-style "gnu") |
| 1100 | * End: |
| 1101 | */ |