summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/cbr/cbr_client.c6
-rw-r--r--src/tools/operf/operf.c5
-rw-r--r--src/tools/operf/operf_client.c23
3 files changed, 27 insertions, 7 deletions
diff --git a/src/tools/cbr/cbr_client.c b/src/tools/cbr/cbr_client.c
index b2cf7d7f..58198b86 100644
--- a/src/tools/cbr/cbr_client.c
+++ b/src/tools/cbr/cbr_client.c
@@ -46,7 +46,7 @@ int client_main(char * server,
int result = 0;
bool stop = false;
char buf[size];
- int seqnr = 0;
+ long seqnr = 0;
long gap = size * 8.0 * (BILLION / (double) rate);
struct timespec start;
@@ -114,8 +114,8 @@ int client_main(char * server,
ms = ts_diff_ms(&start, &end);
printf("sent statistics: "
- "%9d SDUs, %12d bytes in %9d ms, %4.4f Mb/s\n",
- seqnr, seqnr * size, ms, (seqnr * size * 8.0)/(ms * 1000));
+ "%9ld SDUs, %12ld bytes in %9d ms, %4.4f Mb/s\n",
+ seqnr, seqnr * size, ms, (seqnr / (ms * 1000.0)) * size * 8.0);
flow_dealloc(fd);
diff --git a/src/tools/operf/operf.c b/src/tools/operf/operf.c
index b52109cf..46dfc14d 100644
--- a/src/tools/operf/operf.c
+++ b/src/tools/operf/operf.c
@@ -41,6 +41,7 @@ struct c {
int size;
long rate;
bool flood;
+ bool sleep;
int duration;
size_t sent;
@@ -81,6 +82,7 @@ static void usage(void)
" -r, --rate Rate (b/s)\n"
" -s, --size Payload size (B, default 1500)\n"
" -f, --flood Send SDUs as fast as possible\n"
+ " --sleep Sleep in between sending SDUs\n"
" --help Display this help text and exit\n");
}
@@ -100,6 +102,7 @@ int main(int argc, char ** argv)
server.timeout = 1000; /* ms */
client.rate = 1000000;
client.flood = false;
+ client.sleep = false;
while (argc > 0) {
if (strcmp(*argv, "-n") == 0 ||
@@ -127,6 +130,8 @@ int main(int argc, char ** argv)
} else if (strcmp(*argv, "-f") == 0 ||
strcmp(*argv, "--flood") == 0) {
client.flood = true;
+ } else if (strcmp(*argv, "--sleep") == 0) {
+ client.sleep = true;
} else if (strcmp(*argv, "-l") == 0 ||
strcmp(*argv, "--listen") == 0) {
serv = true;
diff --git a/src/tools/operf/operf_client.c b/src/tools/operf/operf_client.c
index 1f6226d4..902a7b41 100644
--- a/src/tools/operf/operf_client.c
+++ b/src/tools/operf/operf_client.c
@@ -36,6 +36,17 @@
#include <errno.h>
#include <float.h>
+static void busy_wait_until(const struct timespec * deadline)
+{
+ struct timespec now;
+ clock_gettime(CLOCK_REALTIME, &now);
+ while (now.tv_sec < deadline->tv_sec)
+ clock_gettime(CLOCK_REALTIME, &now);
+ while (now.tv_sec == deadline->tv_sec
+ && now.tv_nsec < deadline->tv_nsec)
+ clock_gettime(CLOCK_REALTIME, &now);
+}
+
void shutdown_client(int signo, siginfo_t * info, void * c)
{
(void) info;
@@ -85,6 +96,7 @@ void * writer(void * o)
struct timespec now;
struct timespec start;
struct timespec intv = {(gap / BILLION), gap % BILLION};
+ struct timespec end = {0, 0};
char * buf = malloc(client.size);
if (buf == NULL)
@@ -123,6 +135,9 @@ void * writer(void * o)
}
} else {
while (ts_diff_ms(&start, &now) < client.duration) {
+ clock_gettime(CLOCK_REALTIME, &now);
+ ts_add(&now, &intv, &end);
+
if (flow_write(*fdp, buf, client.size) == -1) {
printf("Failed to send SDU.\n");
flow_dealloc(*fdp);
@@ -131,10 +146,10 @@ void * writer(void * o)
}
++client.sent;
-
- nanosleep(&intv, NULL);
-
- clock_gettime(CLOCK_REALTIME, &now);
+ if (client.sleep)
+ nanosleep(&intv, NULL);
+ else
+ busy_wait_until(&end);
}
}