| 1 |
/* |
| 2 |
* Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved. |
| 3 |
* |
| 4 |
* This Software is licensed under one of the following licenses: |
| 5 |
* |
| 6 |
* 1) under the terms of the "Common Public License 1.0" a copy of which is |
| 7 |
* in the file LICENSE.txt in the root directory. The license is also |
| 8 |
* available from the Open Source Initiative, see |
| 9 |
* http://www.opensource.org/licenses/cpl.php. |
| 10 |
* |
| 11 |
* 2) under the terms of the "The BSD License" a copy of which is in the file |
| 12 |
* LICENSE2.txt in the root directory. The license is also available from |
| 13 |
* the Open Source Initiative, see |
| 14 |
* http://www.opensource.org/licenses/bsd-license.php. |
| 15 |
* |
| 16 |
* 3) under the terms of the "GNU General Public License (GPL) Version 2" a |
| 17 |
* copy of which is in the file LICENSE3.txt in the root directory. The |
| 18 |
* license is also available from the Open Source Initiative, see |
| 19 |
* http://www.opensource.org/licenses/gpl-license.php. |
| 20 |
* |
| 21 |
* Licensee has the right to choose one of the above licenses. |
| 22 |
* |
| 23 |
* Redistributions of source code must retain the above copyright |
| 24 |
* notice and one of the license notices. |
| 25 |
* |
| 26 |
* Redistributions in binary form must reproduce both the above copyright |
| 27 |
* notice, one of the license notices in the documentation |
| 28 |
* and/or other materials provided with the distribution. |
| 29 |
*/ |
| 30 |
|
| 31 |
#include "dapl_proto.h" |
| 32 |
|
| 33 |
static bool DT_Transaction_Cmd_Parse_Op(Transaction_Cmd_t * cmd, char *arg) |
| 34 |
{ |
| 35 |
char *c_ptr; |
| 36 |
int op; |
| 37 |
if (cmd->num_ops >= MAX_OPS) { |
| 38 |
DT_Mdep_printf("Client: Too Many Ops - Max %d\n", MAX_OPS); |
| 39 |
goto error_return; |
| 40 |
} |
| 41 |
op = cmd->num_ops; |
| 42 |
cmd->num_ops++; |
| 43 |
|
| 44 |
/* set some defaults */ |
| 45 |
cmd->op[op].seg_size = 4096; |
| 46 |
cmd->op[op].num_segs = 1; |
| 47 |
cmd->op[op].reap_send_on_recv = false; |
| 48 |
|
| 49 |
/* |
| 50 |
* packet format: <server/client> <RR/RW/SR> [seg_size] [num_segs] |
| 51 |
*/ |
| 52 |
c_ptr = strtok(arg, " \t"); |
| 53 |
if (!c_ptr) { |
| 54 |
DT_Mdep_printf("OP first arg must <server/client>\n"); |
| 55 |
goto error_return; |
| 56 |
} |
| 57 |
/* first token is <who>: */ |
| 58 |
if (strcmp(c_ptr, "server") == 0) { |
| 59 |
cmd->op[op].server_initiated = true; |
| 60 |
} else { |
| 61 |
if (strcmp(c_ptr, "client") == 0) { |
| 62 |
cmd->op[op].server_initiated = false; |
| 63 |
} else { |
| 64 |
DT_Mdep_printf("OP first arg must <server/client>\n"); |
| 65 |
goto error_return; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
c_ptr = strtok(0, " \t"); |
| 70 |
if (!c_ptr) { |
| 71 |
DT_Mdep_printf("OP Second arg must be <RR/RW/SR>\n"); |
| 72 |
goto error_return; |
| 73 |
} |
| 74 |
/* second token is <transfer_type>: */ |
| 75 |
if (strcmp(c_ptr, "RR") == 0) { |
| 76 |
cmd->op[op].transfer_type = RDMA_READ; |
| 77 |
} else { |
| 78 |
if (strcmp(c_ptr, "RW") == 0) { |
| 79 |
cmd->op[op].transfer_type = RDMA_WRITE; |
| 80 |
} else { |
| 81 |
if (strcmp(c_ptr, "SR") == 0) { |
| 82 |
cmd->op[op].transfer_type = SEND_RECV; |
| 83 |
} else { |
| 84 |
DT_Mdep_printf |
| 85 |
("OP Second arg must be <RR/RW/SR>\n"); |
| 86 |
goto error_return; |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
/* |
| 91 |
* there may or may not be additional parameters... [seg_size] [num_segs] |
| 92 |
* [-f] |
| 93 |
*/ |
| 94 |
c_ptr = strtok(0, " \t"); |
| 95 |
if (c_ptr && strspn(c_ptr, "0123456789") != 0) { |
| 96 |
cmd->op[op].seg_size = atoi(c_ptr); |
| 97 |
c_ptr = strtok(0, " \t"); |
| 98 |
} |
| 99 |
if (c_ptr && strspn(c_ptr, "0123456789") != 0) { |
| 100 |
cmd->op[op].num_segs = atoi(c_ptr); |
| 101 |
c_ptr = strtok(0, " \t"); |
| 102 |
} |
| 103 |
if (c_ptr && strcmp(c_ptr, "-f") == 0) { |
| 104 |
cmd->op[op].reap_send_on_recv = true; |
| 105 |
if (cmd->op[op].transfer_type != SEND_RECV) { |
| 106 |
DT_Mdep_printf("OP: -f only valid on SEND_RECV\n"); |
| 107 |
goto error_return; |
| 108 |
} |
| 109 |
c_ptr = strtok(0, " \t"); |
| 110 |
} |
| 111 |
if (c_ptr) { |
| 112 |
DT_Mdep_printf("OP too many args \n"); |
| 113 |
goto error_return; |
| 114 |
} |
| 115 |
return true; |
| 116 |
|
| 117 |
error_return: |
| 118 |
return false; |
| 119 |
} |
| 120 |
|
| 121 |
static bool DT_Transaction_Cmd_Validate(Transaction_Cmd_t * cmd) |
| 122 |
{ |
| 123 |
unsigned int i; |
| 124 |
bool has_server_send; |
| 125 |
bool has_client_send; |
| 126 |
unsigned int reap_count; |
| 127 |
has_server_send = false; |
| 128 |
has_client_send = false; |
| 129 |
reap_count = 0; |
| 130 |
|
| 131 |
if (cmd->server_name[0] == '\0') { |
| 132 |
DT_Mdep_printf |
| 133 |
("Must specify server_name in command line or scriptfile\n"); |
| 134 |
return (false); |
| 135 |
} |
| 136 |
for (i = 0; i < cmd->num_ops; i++) { |
| 137 |
switch (cmd->op[i].transfer_type) { |
| 138 |
case SEND_RECV: |
| 139 |
{ |
| 140 |
if (cmd->op[i].server_initiated) { |
| 141 |
has_server_send = true; |
| 142 |
} else { |
| 143 |
has_client_send = true; |
| 144 |
} |
| 145 |
if (cmd->op[i].reap_send_on_recv) { |
| 146 |
if (!cmd->op[i].server_initiated) { |
| 147 |
/* client */ |
| 148 |
reap_count++; |
| 149 |
} else { |
| 150 |
/* server */ |
| 151 |
if (reap_count > 0) { |
| 152 |
reap_count--; |
| 153 |
} else { |
| 154 |
DT_Mdep_printf |
| 155 |
("OP: Unbalanced -f options\n"); |
| 156 |
return false; |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
break; |
| 161 |
} |
| 162 |
case RDMA_READ: |
| 163 |
{ |
| 164 |
break; |
| 165 |
} |
| 166 |
case RDMA_WRITE: |
| 167 |
{ |
| 168 |
break; |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
if (!has_server_send || !has_client_send) { |
| 174 |
DT_Mdep_printf("Error: Transaction test requires \n"); |
| 175 |
DT_Mdep_printf |
| 176 |
("Error: At least one server SR and one client SR Operation\n"); |
| 177 |
return false; |
| 178 |
} |
| 179 |
if (reap_count != 0) { |
| 180 |
DT_Mdep_printf("OP: Unbalanced -f options\n"); |
| 181 |
return false; |
| 182 |
} |
| 183 |
if (cmd->debug) { |
| 184 |
DT_Transaction_Cmd_Print(cmd); |
| 185 |
} |
| 186 |
return true; |
| 187 |
} |
| 188 |
|
| 189 |
static void DT_Transaction_Cmd_Usage(void) |
| 190 |
{ |
| 191 |
DT_Mdep_printf("USAGE: ---- TRANSACTION TEST ----\n"); |
| 192 |
DT_Mdep_printf("USAGE: dapltest -T T\n"); |
| 193 |
DT_Mdep_printf("USAGE: -s <server Name>\n"); |
| 194 |
DT_Mdep_printf("USAGE: [-D <device Name>]\n"); |
| 195 |
DT_Mdep_printf("USAGE: [-n <server port number>]\n"); |
| 196 |
DT_Mdep_printf("USAGE: [-d] : debug (zero)\n"); |
| 197 |
DT_Mdep_printf("USAGE: [-i <num iterations>] : (1, 000)\n"); |
| 198 |
DT_Mdep_printf("USAGE: [-t <num threads>] : (1)\n"); |
| 199 |
DT_Mdep_printf("USAGE: [-w <num EPs per thread>] : (1)\n"); |
| 200 |
DT_Mdep_printf("USAGE: [-V ] : Validate data: (false)\n"); |
| 201 |
DT_Mdep_printf("USAGE: [-P ] : DTO Completion Polling: (false)\n"); |
| 202 |
DT_Mdep_printf("USAGE: [-r ] : Use RSPs: (false)\n"); |
| 203 |
DT_Mdep_printf("USAGE: [-R <service reliability>]\n"); |
| 204 |
DT_Mdep_printf("USAGE: (BE == QOS_BEST_EFFORT - Default)\n"); |
| 205 |
DT_Mdep_printf("USAGE: (HT == QOS_HIGH_THROUGHPUT)\n"); |
| 206 |
DT_Mdep_printf("USAGE: (LL == QOS_LOW_LATENCY)\n"); |
| 207 |
DT_Mdep_printf("USAGE: (EC == QOS_ECONOMY)\n"); |
| 208 |
DT_Mdep_printf("USAGE: (PM == QOS_PREMIUM)\n"); |
| 209 |
DT_Mdep_printf("USAGE: <OP [OP...]\n"); |
| 210 |
DT_Mdep_printf("USAGE:\n"); |
| 211 |
DT_Mdep_printf("USAGE: Each OP consists of:\n"); |
| 212 |
DT_Mdep_printf("USAGE: <who> : \"server\"/\"client\"\n"); |
| 213 |
DT_Mdep_printf("USAGE: <transfer_type> : \"SR\" (SEND/RECV)\n"); |
| 214 |
DT_Mdep_printf("USAGE: : \"RR\" (RDMA READ)\n"); |
| 215 |
DT_Mdep_printf("USAGE: : \"RW\" (RDMA WRITE)\n"); |
| 216 |
DT_Mdep_printf("USAGE: [seg_size [num_segs] ] : (4096, 1)\n"); |
| 217 |
DT_Mdep_printf("USAGE: [-f] : Reap sends on recv\n"); |
| 218 |
DT_Mdep_printf("USAGE:\n"); |
| 219 |
DT_Mdep_printf("NOTE: -f is only allowed on \"SR\" OPs\n"); |
| 220 |
DT_Mdep_printf("NOTE: -f must appear in pairs (one client, one server)\n"); |
| 221 |
DT_Mdep_printf("NOTE: At least one server SR and one client SR OP are required\n"); |
| 222 |
DT_Mdep_printf("NOTE: and use of -V results in the use of three extra OPs\n"); |
| 223 |
} |
| 224 |
|
| 225 |
void DT_Transaction_Cmd_Init(Transaction_Cmd_t * cmd) |
| 226 |
{ |
| 227 |
memset((void *)cmd, 0, sizeof(Transaction_Cmd_t)); |
| 228 |
cmd->dapltest_version = DAPLTEST_VERSION; |
| 229 |
cmd->client_is_little_endian = DT_local_is_little_endian; |
| 230 |
cmd->num_iterations = 1000; |
| 231 |
cmd->num_threads = 1; |
| 232 |
cmd->eps_per_thread = 1; |
| 233 |
cmd->debug = false; |
| 234 |
cmd->validate = false; |
| 235 |
cmd->port = SERVER_PORT_NUMBER; |
| 236 |
cmd->ReliabilityLevel = DAT_QOS_BEST_EFFORT; |
| 237 |
} |
| 238 |
|
| 239 |
bool |
| 240 |
DT_Transaction_Cmd_Parse(Transaction_Cmd_t * cmd, |
| 241 |
int my_argc, char **my_argv, mygetopt_t * opts) |
| 242 |
{ |
| 243 |
int c; |
| 244 |
unsigned int len; |
| 245 |
int i; |
| 246 |
char op[100]; |
| 247 |
for (;;) { |
| 248 |
c = DT_mygetopt_r(my_argc, my_argv, "rQVPdw:s:D:i:t:v:R:n:", |
| 249 |
opts); |
| 250 |
if (c == EOF) { |
| 251 |
break; |
| 252 |
} |
| 253 |
switch (c) { |
| 254 |
case 's': /* server name */ |
| 255 |
{ |
| 256 |
if ((opts->optarg == 0) |
| 257 |
|| strlen(opts->optarg) == 0 |
| 258 |
|| *opts->optarg == '-') { |
| 259 |
DT_Mdep_printf |
| 260 |
("must specify server name\n"); |
| 261 |
DT_Transaction_Cmd_Usage(); |
| 262 |
return (false); |
| 263 |
} |
| 264 |
strcpy(cmd->server_name, opts->optarg); |
| 265 |
break; |
| 266 |
} |
| 267 |
case 'D': /* device name */ |
| 268 |
{ |
| 269 |
strcpy(cmd->dapl_name, opts->optarg); |
| 270 |
break; |
| 271 |
} |
| 272 |
|
| 273 |
case 'i': /* num iterations */ |
| 274 |
{ |
| 275 |
len = strspn(opts->optarg, "0123456789"); |
| 276 |
if (len == 0 || len != strlen(opts->optarg)) { |
| 277 |
DT_Mdep_printf |
| 278 |
("Syntax Error -i<iterations> option\n"); |
| 279 |
DT_Transaction_Cmd_Usage(); |
| 280 |
return (false); |
| 281 |
} |
| 282 |
cmd->num_iterations = atol(opts->optarg); |
| 283 |
|
| 284 |
break; |
| 285 |
} |
| 286 |
case 't': /* num threads */ |
| 287 |
{ |
| 288 |
len = strspn(opts->optarg, "0123456789"); |
| 289 |
if (len == 0 || len != strlen(opts->optarg)) { |
| 290 |
DT_Mdep_printf |
| 291 |
("Syntax Error -t<num threads> option\n"); |
| 292 |
DT_Transaction_Cmd_Usage(); |
| 293 |
return (false); |
| 294 |
} |
| 295 |
cmd->num_threads = atol(opts->optarg); |
| 296 |
break; |
| 297 |
} |
| 298 |
case 'w': /* num EPs per thread */ |
| 299 |
{ |
| 300 |
len = strspn(opts->optarg, "0123456789"); |
| 301 |
if (len == 0 || len != strlen(opts->optarg)) { |
| 302 |
DT_Mdep_printf |
| 303 |
("Syntax Error -w<EPs/thread> option\n"); |
| 304 |
DT_Transaction_Cmd_Usage(); |
| 305 |
return (false); |
| 306 |
} |
| 307 |
cmd->eps_per_thread = atol(opts->optarg); |
| 308 |
break; |
| 309 |
} |
| 310 |
case 'd': /* print debug messages */ |
| 311 |
{ |
| 312 |
DT_dapltest_debug++; |
| 313 |
cmd->debug = true; |
| 314 |
break; |
| 315 |
} |
| 316 |
case 'r': /* use RSP instead of PSP */ |
| 317 |
{ |
| 318 |
cmd->use_rsp = true; |
| 319 |
break; |
| 320 |
} |
| 321 |
case 'V': /* validate data being sent/received */ |
| 322 |
{ |
| 323 |
cmd->validate = true; |
| 324 |
break; |
| 325 |
} |
| 326 |
case 'P': /* use completion polling */ |
| 327 |
{ |
| 328 |
cmd->poll = true; |
| 329 |
break; |
| 330 |
} |
| 331 |
case 'R': /* Service Reliability Level */ |
| 332 |
{ |
| 333 |
cmd->ReliabilityLevel = |
| 334 |
DT_ParseQoS(opts->optarg); |
| 335 |
break; |
| 336 |
} |
| 337 |
case 'n': |
| 338 |
{ |
| 339 |
cmd->port = atoi(opts->optarg); |
| 340 |
break; |
| 341 |
} |
| 342 |
case '?': |
| 343 |
default: |
| 344 |
{ |
| 345 |
DT_Mdep_printf |
| 346 |
("Invalid Transaction Test Parameter: %c\n", |
| 347 |
c); |
| 348 |
DT_Transaction_Cmd_Usage(); |
| 349 |
return (false); |
| 350 |
} |
| 351 |
} |
| 352 |
} |
| 353 |
if (cmd->dapl_name[0] == '\0') { |
| 354 |
if (!DT_Mdep_GetDefaultDeviceName(cmd->dapl_name)) { |
| 355 |
DT_Mdep_printf("can't get default device name\n"); |
| 356 |
DT_Transaction_Cmd_Usage(); |
| 357 |
return (false); |
| 358 |
} |
| 359 |
} |
| 360 |
/* |
| 361 |
* now parse the transaction ops this is ugly, but it's easier to gather |
| 362 |
* each transaction into a single string |
| 363 |
*/ |
| 364 |
for (i = opts->optind; i < my_argc; i++) { |
| 365 |
strcpy(&op[0], my_argv[i]); |
| 366 |
while (i < my_argc - 1) { |
| 367 |
i++; |
| 368 |
if ((strncmp(my_argv[i], "client", 6) == 0) || |
| 369 |
strncmp(my_argv[i], "server", 6) == 0) { |
| 370 |
i--; |
| 371 |
break; |
| 372 |
} |
| 373 |
strcat(op, " "); |
| 374 |
strcat(op, my_argv[i]); |
| 375 |
} |
| 376 |
if (!DT_Transaction_Cmd_Parse_Op(cmd, op)) { |
| 377 |
DT_Transaction_Cmd_Usage(); |
| 378 |
return (false); |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
/* |
| 383 |
* If we're going to validate the data, we append 3 OPs that |
| 384 |
* serve as barriers so that both the client and server can |
| 385 |
* validate their entire set of recv transactions without |
| 386 |
* interference. |
| 387 |
* |
| 388 |
* The first op appended serves to notify the client that the |
| 389 |
* server is at the rendezvous and will transfer nothing else, |
| 390 |
* so the client can validate all recv buffers. The second op |
| 391 |
* notifies the server that the client is quiescent, so the |
| 392 |
* server can safely validate its recv buffers. The final op |
| 393 |
* tells the client that the server is done, and both can |
| 394 |
* proceed with the next iteration. |
| 395 |
*/ |
| 396 |
if (cmd->validate) { |
| 397 |
DT_Mdep_printf |
| 398 |
("NOTE: Adding OP \"server SR\" - for validation\n"); |
| 399 |
memcpy(op, "server SR", strlen("server SR") + 1); |
| 400 |
DT_Transaction_Cmd_Parse_Op(cmd, op); |
| 401 |
|
| 402 |
DT_Mdep_printf |
| 403 |
("NOTE: Adding OP \"client SR\" - for validation\n"); |
| 404 |
memcpy(op, "client SR", strlen("client SR") + 1); |
| 405 |
DT_Transaction_Cmd_Parse_Op(cmd, op); |
| 406 |
|
| 407 |
DT_Mdep_printf |
| 408 |
("NOTE: Adding OP \"server SR\" - for validation\n"); |
| 409 |
memcpy(op, "server SR", strlen("server SR") + 1); |
| 410 |
DT_Transaction_Cmd_Parse_Op(cmd, op); |
| 411 |
} |
| 412 |
if (!DT_Transaction_Cmd_Validate(cmd)) { |
| 413 |
DT_Transaction_Cmd_Usage(); |
| 414 |
return (false); |
| 415 |
} |
| 416 |
return (true); |
| 417 |
} |
| 418 |
|
| 419 |
void DT_Transaction_Cmd_Print(Transaction_Cmd_t * cmd) |
| 420 |
{ |
| 421 |
unsigned int i; |
| 422 |
DT_Mdep_printf("-------------------------------------\n"); |
| 423 |
DT_Mdep_printf("TransCmd.server_name : %s\n", |
| 424 |
cmd->server_name); |
| 425 |
DT_Mdep_printf("TransCmd.server_port_number : %lu\n", |
| 426 |
cmd->port); |
| 427 |
DT_Mdep_printf("TransCmd.num_iterations : %d\n", |
| 428 |
cmd->num_iterations); |
| 429 |
DT_Mdep_printf("TransCmd.num_threads : %d\n", |
| 430 |
cmd->num_threads); |
| 431 |
DT_Mdep_printf("TransCmd.eps_per_thread : %d\n", |
| 432 |
cmd->eps_per_thread); |
| 433 |
DT_Mdep_printf("TransCmd.validate : %d\n", |
| 434 |
cmd->validate); |
| 435 |
DT_Mdep_printf("TransCmd.dapl_name : %s\n", |
| 436 |
cmd->dapl_name); |
| 437 |
DT_Mdep_printf("TransCmd.num_ops : %d\n", |
| 438 |
cmd->num_ops); |
| 439 |
|
| 440 |
for (i = 0; i < cmd->num_ops; i++) { |
| 441 |
DT_Mdep_printf("TransCmd.op[%d].transfer_type : %s %s\n", |
| 442 |
i, |
| 443 |
cmd->op[i].transfer_type == 0 ? "RDMA_READ" : |
| 444 |
cmd->op[i].transfer_type == 1 ? "RDMA_WRITE" : |
| 445 |
"SEND_RECV", |
| 446 |
cmd->op[i]. |
| 447 |
server_initiated ? " (server)" : " (client)"); |
| 448 |
DT_Mdep_printf("TransCmd.op[%d].seg_size : %d\n", i, |
| 449 |
cmd->op[i].seg_size); |
| 450 |
DT_Mdep_printf("TransCmd.op[%d].num_segs : %d\n", i, |
| 451 |
cmd->op[i].num_segs); |
| 452 |
DT_Mdep_printf("TransCmd.op[%d].reap_send_on_recv : %d\n", i, |
| 453 |
cmd->op[i].reap_send_on_recv); |
| 454 |
} |
| 455 |
} |