|
|
@ -1,5 +1,5 @@ |
|
|
|
/*
|
|
|
|
* (C) 2007-18 - ntop.org and contributors |
|
|
|
* (C) 2007-20 - ntop.org and contributors |
|
|
|
* |
|
|
|
* 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 |
|
|
@ -16,37 +16,26 @@ |
|
|
|
* |
|
|
|
*/ |
|
|
|
|
|
|
|
#include "n2n_wire.h" |
|
|
|
#include "n2n_transforms.h" |
|
|
|
#include "n2n.h" |
|
|
|
#ifdef __GNUC__ |
|
|
|
#include <sys/time.h> |
|
|
|
#endif |
|
|
|
#include <time.h> |
|
|
|
#include <string.h> |
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
|
|
#if defined(WIN32) && !defined(__GNUC__) |
|
|
|
#include <windows.h> |
|
|
|
|
|
|
|
static int gettimeofday(struct timeval *tp, void *tzp) |
|
|
|
{ |
|
|
|
time_t clock; |
|
|
|
struct tm tm; |
|
|
|
SYSTEMTIME wtm; |
|
|
|
GetLocalTime(&wtm); |
|
|
|
tm.tm_year = wtm.wYear - 1900; |
|
|
|
tm.tm_mon = wtm.wMonth - 1; |
|
|
|
tm.tm_mday = wtm.wDay; |
|
|
|
tm.tm_hour = wtm.wHour; |
|
|
|
tm.tm_min = wtm.wMinute; |
|
|
|
tm.tm_sec = wtm.wSecond; |
|
|
|
tm.tm_isdst = -1; |
|
|
|
clock = mktime(&tm); |
|
|
|
tp->tv_sec = clock; |
|
|
|
tp->tv_usec = wtm.wMilliseconds * 1000; |
|
|
|
return (0); |
|
|
|
time_t clock; |
|
|
|
struct tm tm; |
|
|
|
SYSTEMTIME wtm; |
|
|
|
GetLocalTime(&wtm); |
|
|
|
tm.tm_year = wtm.wYear - 1900; |
|
|
|
tm.tm_mon = wtm.wMonth - 1; |
|
|
|
tm.tm_mday = wtm.wDay; |
|
|
|
tm.tm_hour = wtm.wHour; |
|
|
|
tm.tm_min = wtm.wMinute; |
|
|
|
tm.tm_sec = wtm.wSecond; |
|
|
|
tm.tm_isdst = -1; |
|
|
|
clock = mktime(&tm); |
|
|
|
tp->tv_sec = clock; |
|
|
|
tp->tv_usec = wtm.wMilliseconds * 1000; |
|
|
|
return (0); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
@ -75,7 +64,7 @@ static int perform_decryption = 0; |
|
|
|
|
|
|
|
static void usage() { |
|
|
|
fprintf(stderr, "Usage: benchmark [-d]\n" |
|
|
|
" -d\t\tEnable decryption. Default: only encryption is performed\n"); |
|
|
|
" -d\t\tEnable decryption. Default: only encryption is performed\n"); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
|
|
|
@ -162,7 +151,7 @@ static void run_transop_benchmark(const char *op_name, n2n_trans_op_t *op_fn, n2 |
|
|
|
size_t num_packets = 0; |
|
|
|
|
|
|
|
printf("Run %s[%s] for %us (%u bytes): ", perform_decryption ? "enc/dec" : "enc", |
|
|
|
op_name, target_sec, (unsigned int)sizeof(PKT_CONTENT)); |
|
|
|
op_name, target_sec, (unsigned int)sizeof(PKT_CONTENT)); |
|
|
|
fflush(stdout); |
|
|
|
|
|
|
|
memset(mac_buf, 0, sizeof(mac_buf)); |
|
|
@ -172,8 +161,8 @@ static void run_transop_benchmark(const char *op_name, n2n_trans_op_t *op_fn, n2 |
|
|
|
nw = do_encode_packet( pktbuf, N2N_PKT_BUF_SIZE, conf->community_name); |
|
|
|
|
|
|
|
nw += op_fn->fwd(op_fn, |
|
|
|
pktbuf+nw, N2N_PKT_BUF_SIZE-nw, |
|
|
|
PKT_CONTENT, sizeof(PKT_CONTENT), mac_buf); |
|
|
|
pktbuf+nw, N2N_PKT_BUF_SIZE-nw, |
|
|
|
PKT_CONTENT, sizeof(PKT_CONTENT), mac_buf); |
|
|
|
|
|
|
|
idx=0; |
|
|
|
rem=nw; |
|
|
@ -198,7 +187,7 @@ static void run_transop_benchmark(const char *op_name, n2n_trans_op_t *op_fn, n2 |
|
|
|
float mpps = num_packets / (tdiff / 1e6) / 1e6; |
|
|
|
|
|
|
|
printf("\t%12u packets\t%8.1f Kpps\t%8.1f MB/s\n", |
|
|
|
(unsigned int)num_packets, mpps * 1e3, mpps * sizeof(PKT_CONTENT)); |
|
|
|
(unsigned int)num_packets, mpps * 1e3, mpps * sizeof(PKT_CONTENT)); |
|
|
|
} |
|
|
|
|
|
|
|
static ssize_t do_encode_packet( uint8_t * pktbuf, size_t bufsize, const n2n_community_t c ) |
|
|
|