X-Git-Url: http://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fsptps_speed.c;h=45bbeb5cbce1ce1cc697310e30092c2d916fa8f5;hb=28b8e10015574784f59d4893de11d80f07412459;hp=8e6f5bed688f41547f8e3e02c4004d6aebd45f3a;hpb=2c6b2d70e6640f39563ad7bb0aa0ba87f883848c;p=tinc diff --git a/src/sptps_speed.c b/src/sptps_speed.c index 8e6f5bed..45bbeb5c 100644 --- a/src/sptps_speed.c +++ b/src/sptps_speed.c @@ -1,6 +1,6 @@ /* sptps_speed.c -- SPTPS benchmark - Copyright (C) 2013-2014 Guus Sliepen + Copyright (C) 2013-2022 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,27 +26,41 @@ #include "ecdh.h" #include "ecdsa.h" #include "ecdsagen.h" +#include "meta.h" +#include "protocol.h" #include "sptps.h" +#include "random.h" // Symbols necessary to link with logger.o -bool send_request(void *c, const char *msg, ...) { +bool send_request(struct connection_t *c, const char *msg, ...) { + (void)c; + (void)msg; return false; } -struct list_t *connection_list = NULL; -bool send_meta(void *c, const char *msg, int len) { + +list_t connection_list; + +bool send_meta(struct connection_t *c, const void *msg, size_t len) { + (void)c; + (void)msg; + (void)len; return false; } -char *logfilename = NULL; bool do_detach = false; struct timeval now; static bool send_data(void *handle, uint8_t type, const void *data, size_t len) { + (void)type; int fd = *(int *)handle; send(fd, data, len, 0); return true; } static bool receive_record(void *handle, uint8_t type, const void *data, uint16_t len) { + (void)handle; + (void)type; + (void)data; + (void)len; return true; } @@ -73,7 +87,7 @@ double elapsed; double rate; unsigned int count; -static void clock_start() { +static void clock_start(void) { count = 0; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); } @@ -91,15 +105,13 @@ static bool clock_countto(double seconds) { return false; } -int main(int argc, char *argv[]) { +static int run_benchmark(int argc, char *argv[]) { ecdsa_t *key1, *key2; ecdh_t *ecdh1, *ecdh2; sptps_t sptps1, sptps2; uint8_t buf1[4096], buf2[4096], buf3[4096]; double duration = argc > 1 ? atof(argv[1]) : 10; - crypto_init(); - randomize(buf1, sizeof(buf1)); randomize(buf2, sizeof(buf2)); randomize(buf3, sizeof(buf3)); @@ -156,22 +168,76 @@ int main(int argc, char *argv[]) { fprintf(stderr, "%28.2lf op/s\n", rate); ecdh_free(ecdh1); - // SPTPS authentication phase - int fd[2]; + struct pollfd pfd[2] = {{fd[0], POLLIN}, {fd[1], POLLIN}}; - if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { - fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); - return 1; - } + sptps_params_t params1 = { + .handle = fd + 0, + .initiator = true, + .datagram = false, + .mykey = key1, + .hiskey = key2, + .label = "sptps_speed", + .send_data = send_data, + .receive_record = receive_record, + }; + + sptps_params_t params2 = { + .handle = fd + 1, + .initiator = false, + .datagram = false, + .mykey = key2, + .hiskey = key1, + .label = "sptps_speed", + .send_data = send_data, + .receive_record = receive_record, + }; + + static const char *suite_names[] = { + "Chacha20-Poly1305", + "AES-256-GCM", + }; + + for(uint8_t suite = 0; suite < 2; suite++) { + fprintf(stderr, "\nCipher suite %u (%s):\n", suite, suite_names[suite]); + params1.preferred_suite = params2.preferred_suite = suite; + + // SPTPS authentication phase + + fprintf(stderr, "SPTPS/TCP authenticate for %lg seconds: ", duration); + + if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { + fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); + return 1; + } - struct pollfd pfd[2] = {{fd[0], POLLIN}, {fd[1], POLLIN}}; + pfd[0].fd = fd[0], pfd[1].fd = fd[1]; + params1.datagram = params2.datagram = false; - fprintf(stderr, "SPTPS/TCP authenticate for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) { + sptps_start(&sptps1, ¶ms1); + sptps_start(&sptps2, ¶ms2); - for(clock_start(); clock_countto(duration);) { - sptps_start(&sptps1, fd + 0, true, false, key1, key2, "sptps_speed", 11, send_data, receive_record); - sptps_start(&sptps2, fd + 1, false, false, key2, key1, "sptps_speed", 11, send_data, receive_record); + while(poll(pfd, 2, 0)) { + if(pfd[0].revents) { + receive_data(&sptps1); + } + + if(pfd[1].revents) { + receive_data(&sptps2); + } + } + + sptps_stop(&sptps1); + sptps_stop(&sptps2); + } + + fprintf(stderr, "%10.2lf op/s\n", rate * 2); + + // SPTPS data + + sptps_start(&sptps1, ¶ms1); + sptps_start(&sptps2, ¶ms2); while(poll(pfd, 2, 0)) { if(pfd[0].revents) { @@ -183,65 +249,68 @@ int main(int argc, char *argv[]) { } } - sptps_stop(&sptps1); - sptps_stop(&sptps2); - } + fprintf(stderr, "SPTPS/TCP transmit for %lg seconds: ", duration); - fprintf(stderr, "%10.2lf op/s\n", rate * 2); + for(clock_start(); clock_countto(duration);) { + if(!sptps_send_record(&sptps1, 0, buf1, 1451)) { + abort(); + } - // SPTPS data + receive_data(&sptps2); + } - sptps_start(&sptps1, fd + 0, true, false, key1, key2, "sptps_speed", 11, send_data, receive_record); - sptps_start(&sptps2, fd + 1, false, false, key2, key1, "sptps_speed", 11, send_data, receive_record); + rate *= 2 * 1451 * 8; - while(poll(pfd, 2, 0)) { - if(pfd[0].revents) { - receive_data(&sptps1); + if(rate > 1e9) { + fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); + } else if(rate > 1e6) { + fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); + } else if(rate > 1e3) { + fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); } - if(pfd[1].revents) { - receive_data(&sptps2); - } - } + sptps_stop(&sptps1); + sptps_stop(&sptps2); - fprintf(stderr, "SPTPS/TCP transmit for %lg seconds: ", duration); + close(fd[0]); + close(fd[1]); - for(clock_start(); clock_countto(duration);) { - if(!sptps_send_record(&sptps1, 0, buf1, 1451)) { - abort(); + // SPTPS datagram authentication phase + + if(socketpair(AF_UNIX, SOCK_DGRAM, 0, fd)) { + fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); + return 1; } - receive_data(&sptps2); - } + pfd[0].fd = fd[0], pfd[1].fd = fd[1]; + params1.datagram = params2.datagram = true; - rate *= 2 * 1451 * 8; + fprintf(stderr, "SPTPS/UDP authenticate for %lg seconds: ", duration); - if(rate > 1e9) { - fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); - } else if(rate > 1e6) { - fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); - } else if(rate > 1e3) { - fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); - } + for(clock_start(); clock_countto(duration);) { + sptps_start(&sptps1, ¶ms1); + sptps_start(&sptps2, ¶ms2); - sptps_stop(&sptps1); - sptps_stop(&sptps2); + while(poll(pfd, 2, 0)) { + if(pfd[0].revents) { + receive_data(&sptps1); + } - // SPTPS datagram authentication phase + if(pfd[1].revents) { + receive_data(&sptps2); + } + } - close(fd[0]); - close(fd[1]); + sptps_stop(&sptps1); + sptps_stop(&sptps2); + } - if(socketpair(AF_UNIX, SOCK_DGRAM, 0, fd)) { - fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); - return 1; - } + fprintf(stderr, "%10.2lf op/s\n", rate * 2); - fprintf(stderr, "SPTPS/UDP authenticate for %lg seconds: ", duration); + // SPTPS datagram data - for(clock_start(); clock_countto(duration);) { - sptps_start(&sptps1, fd + 0, true, true, key1, key2, "sptps_speed", 11, send_data, receive_record); - sptps_start(&sptps2, fd + 1, false, true, key2, key1, "sptps_speed", 11, send_data, receive_record); + sptps_start(&sptps1, ¶ms1); + sptps_start(&sptps2, ¶ms2); while(poll(pfd, 2, 0)) { if(pfd[0].revents) { @@ -253,57 +322,48 @@ int main(int argc, char *argv[]) { } } - sptps_stop(&sptps1); - sptps_stop(&sptps2); - } - - fprintf(stderr, "%10.2lf op/s\n", rate * 2); + fprintf(stderr, "SPTPS/UDP transmit for %lg seconds: ", duration); - // SPTPS datagram data - - sptps_start(&sptps1, fd + 0, true, true, key1, key2, "sptps_speed", 11, send_data, receive_record); - sptps_start(&sptps2, fd + 1, false, true, key2, key1, "sptps_speed", 11, send_data, receive_record); - - while(poll(pfd, 2, 0)) { - if(pfd[0].revents) { - receive_data(&sptps1); - } + for(clock_start(); clock_countto(duration);) { + if(!sptps_send_record(&sptps1, 0, buf1, 1451)) { + abort(); + } - if(pfd[1].revents) { receive_data(&sptps2); } - } - fprintf(stderr, "SPTPS/UDP transmit for %lg seconds: ", duration); + rate *= 2 * 1451 * 8; - for(clock_start(); clock_countto(duration);) { - if(!sptps_send_record(&sptps1, 0, buf1, 1451)) { - abort(); + if(rate > 1e9) { + fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); + } else if(rate > 1e6) { + fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); + } else if(rate > 1e3) { + fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); } - receive_data(&sptps2); - } - - rate *= 2 * 1451 * 8; + sptps_stop(&sptps1); + sptps_stop(&sptps2); - if(rate > 1e9) { - fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); - } else if(rate > 1e6) { - fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); - } else if(rate > 1e3) { - fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); + close(fd[0]); + close(fd[1]); } - sptps_stop(&sptps1); - sptps_stop(&sptps2); - // Clean up - close(fd[0]); - close(fd[1]); ecdsa_free(key1); ecdsa_free(key2); - crypto_exit(); return 0; } + +int main(int argc, char *argv[]) { + random_init(); + crypto_init(); + + int result = run_benchmark(argc, argv); + + random_exit(); + + return result; +}