forked from wolfSSL/wolfssl
Enhnacement to the tls_bench tool to support new -S
command to indicate total size of data to exchange. Previously was just sending one packet back and forth. Imporved the shutdown handling code.
This commit is contained in:
@ -82,7 +82,8 @@ bench_tls(args);
|
|||||||
#define NUM_THREAD_PAIRS 1 /* Thread pairs of server/client */
|
#define NUM_THREAD_PAIRS 1 /* Thread pairs of server/client */
|
||||||
#define BENCH_RUNTIME_SEC 1
|
#define BENCH_RUNTIME_SEC 1
|
||||||
#define MEM_BUFFER_SZ ((16 * 1024) + 38 + 32) /* Must be large enough to handle max packet size plus max TLS header MAX_MSG_EXTRA */
|
#define MEM_BUFFER_SZ ((16 * 1024) + 38 + 32) /* Must be large enough to handle max packet size plus max TLS header MAX_MSG_EXTRA */
|
||||||
#define TEST_PACKET_SIZE (16 * 1024) /* max TLS packet size */
|
#define TEST_PACKET_SIZE (16 * 1024) /* TLS packet size */
|
||||||
|
#define TEST_MAX_SIZE (16 * 1024) /* Total bytes to benchmark */
|
||||||
#define SHOW_VERBOSE 0 /* Default output is tab delimited format */
|
#define SHOW_VERBOSE 0 /* Default output is tab delimited format */
|
||||||
|
|
||||||
static const char* kShutdown = "shutdown";
|
static const char* kShutdown = "shutdown";
|
||||||
@ -243,6 +244,7 @@ typedef struct {
|
|||||||
const char* host;
|
const char* host;
|
||||||
word32 port;
|
word32 port;
|
||||||
int packetSize; /* The data payload size in the packet */
|
int packetSize; /* The data payload size in the packet */
|
||||||
|
int maxSize;
|
||||||
int runTimeSec;
|
int runTimeSec;
|
||||||
int showPeerInfo;
|
int showPeerInfo;
|
||||||
int showVerbose;
|
int showVerbose;
|
||||||
@ -599,6 +601,7 @@ static int bench_tls_client(info_t* info)
|
|||||||
WOLFSSL* cli_ssl = NULL;
|
WOLFSSL* cli_ssl = NULL;
|
||||||
int haveShownPeerInfo = 0;
|
int haveShownPeerInfo = 0;
|
||||||
int tls13 = XSTRNCMP(info->cipher, "TLS13", 5) == 0;
|
int tls13 = XSTRNCMP(info->cipher, "TLS13", 5) == 0;
|
||||||
|
int total_sz;
|
||||||
|
|
||||||
total = gettime_secs(0);
|
total = gettime_secs(0);
|
||||||
|
|
||||||
@ -653,11 +656,7 @@ static int bench_tls_client(info_t* info)
|
|||||||
/* Allocate and initialize a packet sized buffer */
|
/* Allocate and initialize a packet sized buffer */
|
||||||
writeBuf = (unsigned char*)XMALLOC(info->packetSize, NULL,
|
writeBuf = (unsigned char*)XMALLOC(info->packetSize, NULL,
|
||||||
DYNAMIC_TYPE_TMP_BUFFER);
|
DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
if (writeBuf != NULL) {
|
if (writeBuf == NULL) {
|
||||||
XMEMSET(writeBuf, 0, info->packetSize);
|
|
||||||
XSTRNCPY((char*)writeBuf, kTestStr, info->packetSize);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("failed to allocate write memory\n");
|
printf("failed to allocate write memory\n");
|
||||||
ret = MEMORY_E; goto exit;
|
ret = MEMORY_E; goto exit;
|
||||||
}
|
}
|
||||||
@ -677,17 +676,6 @@ static int bench_tls_client(info_t* info)
|
|||||||
int err;
|
int err;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* check for run time completion and issue shutdown */
|
|
||||||
if (gettime_secs(0) - total >= info->runTimeSec) {
|
|
||||||
info->client.shutdown = 1;
|
|
||||||
|
|
||||||
writeSz = (int)XSTRLEN(kShutdown) + 1;
|
|
||||||
XMEMCPY(writeBuf, kShutdown, writeSz); /* include null term */
|
|
||||||
if (info->showVerbose) {
|
|
||||||
printf("Sending shutdown\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD
|
#ifdef HAVE_PTHREAD
|
||||||
if (!info->useLocalMem)
|
if (!info->useLocalMem)
|
||||||
#endif
|
#endif
|
||||||
@ -732,51 +720,79 @@ static int bench_tls_client(info_t* info)
|
|||||||
showPeer(cli_ssl);
|
showPeer(cli_ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write test message to server */
|
/* check for run time completion and issue shutdown */
|
||||||
start = gettime_secs(1);
|
if (gettime_secs(0) - total >= info->runTimeSec) {
|
||||||
#ifndef BENCH_USE_NONBLOCK
|
info->client.shutdown = 1;
|
||||||
ret = wolfSSL_write(cli_ssl, writeBuf, writeSz);
|
|
||||||
#else
|
writeSz = (int)XSTRLEN(kShutdown) + 1;
|
||||||
do {
|
XMEMCPY(writeBuf, kShutdown, writeSz); /* include null term */
|
||||||
|
if (info->showVerbose) {
|
||||||
|
printf("Sending shutdown\n");
|
||||||
|
}
|
||||||
|
|
||||||
ret = wolfSSL_write(cli_ssl, writeBuf, writeSz);
|
ret = wolfSSL_write(cli_ssl, writeBuf, writeSz);
|
||||||
err = wolfSSL_get_error(cli_ssl, ret);
|
if (ret < 0) {
|
||||||
|
printf("error on client write\n");
|
||||||
|
ret = wolfSSL_get_error(cli_ssl, ret);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (err == WOLFSSL_ERROR_WANT_WRITE);
|
else {
|
||||||
#endif
|
XMEMSET(writeBuf, 0, info->packetSize);
|
||||||
info->client_stats.txTime += gettime_secs(0) - start;
|
XSTRNCPY((char*)writeBuf, kTestStr, info->packetSize);
|
||||||
if (ret < 0) {
|
|
||||||
printf("error on client write\n");
|
|
||||||
ret = wolfSSL_get_error(cli_ssl, ret);
|
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
info->client_stats.txTotal += ret;
|
|
||||||
|
|
||||||
/* read echo of message from server */
|
/* write / read echo loop */
|
||||||
XMEMSET(readBuf, 0, readBufSz);
|
ret = 0;
|
||||||
start = gettime_secs(1);
|
total_sz = 0;
|
||||||
#ifndef BENCH_USE_NONBLOCK
|
while (ret == 0 && total_sz < info->maxSize && !info->client.shutdown) {
|
||||||
ret = wolfSSL_read(cli_ssl, readBuf, readBufSz);
|
/* write test message to server */
|
||||||
#else
|
start = gettime_secs(1);
|
||||||
do {
|
#ifndef BENCH_USE_NONBLOCK
|
||||||
|
ret = wolfSSL_write(cli_ssl, writeBuf, writeSz);
|
||||||
|
#else
|
||||||
|
do {
|
||||||
|
ret = wolfSSL_write(cli_ssl, writeBuf, writeSz);
|
||||||
|
err = wolfSSL_get_error(cli_ssl, ret);
|
||||||
|
}
|
||||||
|
while (err == WOLFSSL_ERROR_WANT_WRITE);
|
||||||
|
#endif
|
||||||
|
info->client_stats.txTime += gettime_secs(0) - start;
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("error on client write\n");
|
||||||
|
ret = wolfSSL_get_error(cli_ssl, ret);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
info->client_stats.txTotal += ret;
|
||||||
|
total_sz += ret;
|
||||||
|
|
||||||
|
/* read echo of message from server */
|
||||||
|
XMEMSET(readBuf, 0, readBufSz);
|
||||||
|
start = gettime_secs(1);
|
||||||
|
#ifndef BENCH_USE_NONBLOCK
|
||||||
ret = wolfSSL_read(cli_ssl, readBuf, readBufSz);
|
ret = wolfSSL_read(cli_ssl, readBuf, readBufSz);
|
||||||
err = wolfSSL_get_error(cli_ssl, ret);
|
#else
|
||||||
}
|
do {
|
||||||
while (err == WOLFSSL_ERROR_WANT_READ);
|
ret = wolfSSL_read(cli_ssl, readBuf, readBufSz);
|
||||||
#endif
|
err = wolfSSL_get_error(cli_ssl, ret);
|
||||||
info->client_stats.rxTime += gettime_secs(0) - start;
|
}
|
||||||
if (ret < 0) {
|
while (err == WOLFSSL_ERROR_WANT_READ);
|
||||||
printf("error on client read\n");
|
#endif
|
||||||
ret = wolfSSL_get_error(cli_ssl, ret);
|
info->client_stats.rxTime += gettime_secs(0) - start;
|
||||||
goto exit;
|
if (ret < 0) {
|
||||||
}
|
printf("error on client read\n");
|
||||||
info->client_stats.rxTotal += ret;
|
ret = wolfSSL_get_error(cli_ssl, ret);
|
||||||
ret = 0; /* reset return code */
|
goto exit;
|
||||||
|
}
|
||||||
|
info->client_stats.rxTotal += ret;
|
||||||
|
ret = 0; /* reset return code */
|
||||||
|
|
||||||
/* validate echo */
|
/* validate echo */
|
||||||
if (XMEMCMP((char*)writeBuf, (char*)readBuf, writeSz) != 0) {
|
if (XMEMCMP((char*)writeBuf, (char*)readBuf, writeSz) != 0) {
|
||||||
printf("echo check failed!\n");
|
printf("echo check failed!\n");
|
||||||
ret = wolfSSL_get_error(cli_ssl, ret);
|
ret = wolfSSL_get_error(cli_ssl, ret);
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseAndCleanupSocket(&info->client.sockFd);
|
CloseAndCleanupSocket(&info->client.sockFd);
|
||||||
@ -906,6 +922,7 @@ static int bench_tls_server(info_t* info)
|
|||||||
WOLFSSL_CTX* srv_ctx = NULL;
|
WOLFSSL_CTX* srv_ctx = NULL;
|
||||||
WOLFSSL* srv_ssl = NULL;
|
WOLFSSL* srv_ssl = NULL;
|
||||||
int tls13 = XSTRNCMP(info->cipher, "TLS13", 5) == 0;
|
int tls13 = XSTRNCMP(info->cipher, "TLS13", 5) == 0;
|
||||||
|
int total_sz;
|
||||||
|
|
||||||
/* set up server */
|
/* set up server */
|
||||||
#ifdef WOLFSSL_TLS13
|
#ifdef WOLFSSL_TLS13
|
||||||
@ -1036,53 +1053,65 @@ static int bench_tls_server(info_t* info)
|
|||||||
info->server_stats.connTime += start;
|
info->server_stats.connTime += start;
|
||||||
info->server_stats.connCount++;
|
info->server_stats.connCount++;
|
||||||
|
|
||||||
/* read message from client */
|
/* echo loop */
|
||||||
XMEMSET(readBuf, 0, readBufSz);
|
ret = 0;
|
||||||
start = gettime_secs(1);
|
total_sz = 0;
|
||||||
#ifndef BENCH_USE_NONBLOCK
|
while (ret == 0 && total_sz < info->maxSize) {
|
||||||
ret = wolfSSL_read(srv_ssl, readBuf, readBufSz);
|
double rxTime;
|
||||||
#else
|
|
||||||
do {
|
/* read message from client */
|
||||||
|
XMEMSET(readBuf, 0, readBufSz);
|
||||||
|
start = gettime_secs(1);
|
||||||
|
#ifndef BENCH_USE_NONBLOCK
|
||||||
ret = wolfSSL_read(srv_ssl, readBuf, readBufSz);
|
ret = wolfSSL_read(srv_ssl, readBuf, readBufSz);
|
||||||
err = wolfSSL_get_error(srv_ssl, ret);
|
#else
|
||||||
}
|
do {
|
||||||
while (err == WOLFSSL_ERROR_WANT_READ);
|
ret = wolfSSL_read(srv_ssl, readBuf, readBufSz);
|
||||||
#endif
|
err = wolfSSL_get_error(srv_ssl, ret);
|
||||||
info->server_stats.rxTime += gettime_secs(0) - start;
|
|
||||||
if (ret < 0) {
|
|
||||||
printf("error on server read\n");
|
|
||||||
ret = wolfSSL_get_error(srv_ssl, ret);
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
info->server_stats.rxTotal += ret;
|
|
||||||
len = ret;
|
|
||||||
|
|
||||||
/* write message back to client */
|
|
||||||
start = gettime_secs(1);
|
|
||||||
#ifndef BENCH_USE_NONBLOCK
|
|
||||||
ret = wolfSSL_write(srv_ssl, readBuf, len);
|
|
||||||
#else
|
|
||||||
do {
|
|
||||||
ret = wolfSSL_write(srv_ssl, readBuf, len);
|
|
||||||
err = wolfSSL_get_error(srv_ssl, ret);
|
|
||||||
}
|
|
||||||
while (err == WOLFSSL_ERROR_WANT_WRITE);
|
|
||||||
#endif
|
|
||||||
info->server_stats.txTime += gettime_secs(0) - start;
|
|
||||||
if (ret < 0) {
|
|
||||||
printf("error on server write\n");
|
|
||||||
ret = wolfSSL_get_error(srv_ssl, ret);
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
info->server_stats.txTotal += ret;
|
|
||||||
ret = 0; /* reset return code */
|
|
||||||
|
|
||||||
/* shutdown signals, no more connections for this cipher */
|
|
||||||
if (XSTRSTR((const char*)readBuf, kShutdown) != NULL) {
|
|
||||||
info->server.shutdown = 1;
|
|
||||||
if (info->showVerbose) {
|
|
||||||
printf("Server shutdown done\n");
|
|
||||||
}
|
}
|
||||||
|
while (err == WOLFSSL_ERROR_WANT_READ);
|
||||||
|
#endif
|
||||||
|
rxTime = gettime_secs(0) - start;
|
||||||
|
|
||||||
|
/* shutdown signals, no more connections for this cipher */
|
||||||
|
if (XSTRSTR((const char*)readBuf, kShutdown) != NULL) {
|
||||||
|
info->server.shutdown = 1;
|
||||||
|
if (info->showVerbose) {
|
||||||
|
printf("Server shutdown done\n");
|
||||||
|
}
|
||||||
|
ret = 0; /* success */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
info->server_stats.rxTime += rxTime;
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("error on server read\n");
|
||||||
|
ret = wolfSSL_get_error(srv_ssl, ret);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
info->server_stats.rxTotal += ret;
|
||||||
|
len = ret;
|
||||||
|
total_sz += ret;
|
||||||
|
|
||||||
|
/* write message back to client */
|
||||||
|
start = gettime_secs(1);
|
||||||
|
#ifndef BENCH_USE_NONBLOCK
|
||||||
|
ret = wolfSSL_write(srv_ssl, readBuf, len);
|
||||||
|
#else
|
||||||
|
do {
|
||||||
|
ret = wolfSSL_write(srv_ssl, readBuf, len);
|
||||||
|
err = wolfSSL_get_error(srv_ssl, ret);
|
||||||
|
}
|
||||||
|
while (err == WOLFSSL_ERROR_WANT_WRITE);
|
||||||
|
#endif
|
||||||
|
info->server_stats.txTime += gettime_secs(0) - start;
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("error on server write\n");
|
||||||
|
ret = wolfSSL_get_error(srv_ssl, ret);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
info->server_stats.txTotal += ret;
|
||||||
|
ret = 0; /* reset return code */
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseAndCleanupSocket(&info->server.sockFd);
|
CloseAndCleanupSocket(&info->server.sockFd);
|
||||||
@ -1188,6 +1217,7 @@ static void Usage(void)
|
|||||||
printf("-l <str> Cipher suite list (: delimited)\n");
|
printf("-l <str> Cipher suite list (: delimited)\n");
|
||||||
printf("-t <num> Time <num> (seconds) to run each test (default %d)\n", BENCH_RUNTIME_SEC);
|
printf("-t <num> Time <num> (seconds) to run each test (default %d)\n", BENCH_RUNTIME_SEC);
|
||||||
printf("-p <num> The packet size <num> in bytes [1-16kB] (default %d)\n", TEST_PACKET_SIZE);
|
printf("-p <num> The packet size <num> in bytes [1-16kB] (default %d)\n", TEST_PACKET_SIZE);
|
||||||
|
printf("-S <num> The total size <num> in bytes (default %d)\n", TEST_MAX_SIZE);
|
||||||
printf("-v Show verbose output\n");
|
printf("-v Show verbose output\n");
|
||||||
#ifdef DEBUG_WOLFSSL
|
#ifdef DEBUG_WOLFSSL
|
||||||
printf("-d Enable debug messages\n");
|
printf("-d Enable debug messages\n");
|
||||||
@ -1227,6 +1257,7 @@ int bench_tls(void* args)
|
|||||||
int argRuntimeSec = BENCH_RUNTIME_SEC;
|
int argRuntimeSec = BENCH_RUNTIME_SEC;
|
||||||
char *argCipherList = NULL;
|
char *argCipherList = NULL;
|
||||||
int argTestPacketSize = TEST_PACKET_SIZE;
|
int argTestPacketSize = TEST_PACKET_SIZE;
|
||||||
|
int argTestMaxSize = TEST_MAX_SIZE;
|
||||||
int argThreadPairs = NUM_THREAD_PAIRS;
|
int argThreadPairs = NUM_THREAD_PAIRS;
|
||||||
int argShowVerbose = SHOW_VERBOSE;
|
int argShowVerbose = SHOW_VERBOSE;
|
||||||
int argClientOnly = 0;
|
int argClientOnly = 0;
|
||||||
@ -1249,7 +1280,7 @@ int bench_tls(void* args)
|
|||||||
wolfSSL_Init();
|
wolfSSL_Init();
|
||||||
|
|
||||||
/* Parse command line arguments */
|
/* Parse command line arguments */
|
||||||
while ((ch = mygetopt(argc, argv, "?" "deil:p:t:vT:sch:P:m")) != -1) {
|
while ((ch = mygetopt(argc, argv, "?" "deil:p:t:vT:sch:P:mS:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '?' :
|
case '?' :
|
||||||
Usage();
|
Usage();
|
||||||
@ -1298,6 +1329,10 @@ int bench_tls(void* args)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'S' :
|
||||||
|
argTestMaxSize = atoi(myoptarg);
|
||||||
|
break;
|
||||||
|
|
||||||
case 't' :
|
case 't' :
|
||||||
argRuntimeSec = atoi(myoptarg);
|
argRuntimeSec = atoi(myoptarg);
|
||||||
break;
|
break;
|
||||||
@ -1391,6 +1426,7 @@ int bench_tls(void* args)
|
|||||||
info->cipher = cipher;
|
info->cipher = cipher;
|
||||||
info->packetSize = argTestPacketSize;
|
info->packetSize = argTestPacketSize;
|
||||||
info->runTimeSec = argRuntimeSec;
|
info->runTimeSec = argRuntimeSec;
|
||||||
|
info->maxSize = argTestMaxSize;
|
||||||
info->showPeerInfo = argShowPeerInfo;
|
info->showPeerInfo = argShowPeerInfo;
|
||||||
info->showVerbose = argShowVerbose;
|
info->showVerbose = argShowVerbose;
|
||||||
#ifndef NO_WOLFSSL_SERVER
|
#ifndef NO_WOLFSSL_SERVER
|
||||||
|
Reference in New Issue
Block a user