summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-05-27 14:46:46 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-05-27 14:46:46 +0200
commit5f79244d8d83fffab21dc3d18697d938ef836c09 (patch)
tree56b88ae328a58f839d40838a92d49c5defde1c09
parent17e9c86c2fa45b39b88b73f9fd34c2d9b95ae7d4 (diff)
downloadouroboros-5f79244d8d83fffab21dc3d18697d938ef836c09.tar.gz
ouroboros-5f79244d8d83fffab21dc3d18697d938ef836c09.zip
tools: updated cbr with flood and sleep options
The cbr client will now use busy waiting by default to control the sending rate. A --sleep option has been added to allow low CPU usage when sending at low data rates. A --flood option has been added that writes SDU's as fast as possible.
-rw-r--r--include/ouroboros/shm_ap_rbuff.h2
-rw-r--r--include/ouroboros/shm_du_map.h2
-rw-r--r--src/tools/cbr/cbr.c13
-rw-r--r--src/tools/cbr/cbr_client.c68
4 files changed, 62 insertions, 23 deletions
diff --git a/include/ouroboros/shm_ap_rbuff.h b/include/ouroboros/shm_ap_rbuff.h
index 99c5a423..053709bb 100644
--- a/include/ouroboros/shm_ap_rbuff.h
+++ b/include/ouroboros/shm_ap_rbuff.h
@@ -29,7 +29,7 @@
#endif
#ifndef SHM_RBUFF_SIZE
-#define SHM_RBUFF_SIZE (1 << 12)
+#define SHM_RBUFF_SIZE (1 << 14)
#endif
#include <sys/types.h>
diff --git a/include/ouroboros/shm_du_map.h b/include/ouroboros/shm_du_map.h
index 35d85b11..cc1e8869 100644
--- a/include/ouroboros/shm_du_map.h
+++ b/include/ouroboros/shm_du_map.h
@@ -33,7 +33,7 @@
#endif
#ifndef SHM_BLOCKS_IN_MAP
-#define SHM_BLOCKS_IN_MAP (1 << 12)
+#define SHM_BLOCKS_IN_MAP (1 << 14)
#endif
#include "common.h"
diff --git a/src/tools/cbr/cbr.c b/src/tools/cbr/cbr.c
index d7077e9c..e36b1856 100644
--- a/src/tools/cbr/cbr.c
+++ b/src/tools/cbr/cbr.c
@@ -55,9 +55,11 @@ static void usage(void)
" -t, --timeout Server timeout interval (s)\n"
"\n"
"Client options:\n"
- " -d --duration Duration for sending (s)\n"
+ " -d, --duration Duration for sending (s)\n"
+ " -f, --flood Send SDU's as fast as possible\n"
" -s, --size SDU size (B)\n"
" -r, --rate Rate (b/s)\n"
+ " --sleep Sleep in between sending sdu's\n"
"\n\n"
" --help Display this help text and exit\n");
}
@@ -67,6 +69,8 @@ int main(int argc, char ** argv)
int duration = 60; /* One minute test */
int size = 1000; /* 1000 byte SDU's */
long rate = 1000000; /* 1 Mb/s */
+ bool flood = false;
+ bool sleep = false;
char * rem;
bool server = false;
@@ -105,6 +109,11 @@ int main(int argc, char ** argv)
} else if (strcmp(*argv, "-l") == 0 ||
strcmp(*argv, "--listen") == 0) {
server = true;
+ } else if (strcmp(*argv, "-f") == 0 ||
+ strcmp(*argv, "--flood") == 0) {
+ flood = true;
+ } else if (strcmp(*argv, "--sleep") == 0) {
+ sleep = true;
} else {
usage();
return 0;
@@ -117,5 +126,5 @@ int main(int argc, char ** argv)
return server_main();
}
- return client_main(duration, size, rate);
+ return client_main(duration, size, rate, flood, sleep);
}
diff --git a/src/tools/cbr/cbr_client.c b/src/tools/cbr/cbr_client.c
index ff7d4057..b0c04f39 100644
--- a/src/tools/cbr/cbr_client.c
+++ b/src/tools/cbr/cbr_client.c
@@ -24,18 +24,29 @@
#include <ouroboros/dev.h>
#include <ouroboros/time_utils.h>
-int client_main(int duration, int size, long rate)
+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);
+}
+
+int client_main(int duration, int size, long rate, bool flood, bool sleep)
{
int fd = 0;
int result = 0;
bool stop = false;
char buf[size];
long seqnr = 0;
- unsigned long gap = size * 8 * (BILLION / rate); /* ns */
+ unsigned long gap = size * 8.0 * (BILLION / (double) rate);
struct timespec start;
struct timespec end;
- struct timespec interval = {(gap / BILLION), gap % BILLION};
+ struct timespec intv = {(gap / BILLION), gap % BILLION};
int ms;
if (ap_init(CLIENT_AP_NAME)) {
@@ -62,24 +73,43 @@ int client_main(int duration, int size, long rate)
}
clock_gettime(CLOCK_REALTIME, &start);
- while (!stop) {
- memcpy(buf, &seqnr, sizeof(seqnr));
-
- if (flow_write(fd, buf, size) == -1) {
- printf("Failed to write SDU.\n");
- stop = true;
- continue;
+ if (!flood) {
+ while (!stop) {
+ clock_gettime(CLOCK_REALTIME, &end);
+ ts_add(&end, &intv, &end);
+ memcpy(buf, &seqnr, sizeof(seqnr));
+
+ if (flow_write(fd, buf, size) == -1) {
+ stop = true;
+ continue;
+ }
+
+ if (sleep)
+ nanosleep(&intv, NULL);
+ else
+ busy_wait_until(&end);
+
+ ++seqnr;
+
+ if (ts_diff_us(&start, &end) / MILLION
+ >= (long) duration)
+ stop = true;
+ }
+ } else { /* flood */
+ while (!stop) {
+ clock_gettime(CLOCK_REALTIME, &end);
+ if (flow_write(fd, buf, size) == -1) {
+ stop = true;
+ continue;
+ }
+
+ ++seqnr;
+
+ if (ts_diff_us(&start, &end) / MILLION
+ >= (long) duration)
+ stop = true;
}
- nanosleep(&interval, NULL);
-
- seqnr++;
-
- clock_gettime(CLOCK_REALTIME, &end);
-
- if (duration != 0
- && ts_diff_us(&start, &end) / MILLION >= (long) duration)
- stop = true;
}
clock_gettime(CLOCK_REALTIME, &end);