Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/npf/npftest npftest: add a choice of "rule" or "sta...
details: https://anonhg.NetBSD.org/src/rev/a72b8ee47adb
branches: trunk
changeset: 790182:a72b8ee47adb
user: rmind <rmind%NetBSD.org@localhost>
date: Tue Sep 24 02:44:20 2013 +0000
description:
npftest: add a choice of "rule" or "state" for -b option.
diffstat:
usr.sbin/npf/npftest/libnpftest/npf_perf_test.c | 46 ++++++++++++++----------
usr.sbin/npf/npftest/libnpftest/npf_test.h | 2 +-
usr.sbin/npf/npftest/npftest.c | 21 +++++++----
usr.sbin/npf/npftest/npftest.h | 2 +-
4 files changed, 42 insertions(+), 29 deletions(-)
diffs (183 lines):
diff -r 64efef7ecee0 -r a72b8ee47adb usr.sbin/npf/npftest/libnpftest/npf_perf_test.c
--- a/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c Tue Sep 24 02:04:21 2013 +0000
+++ b/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c Tue Sep 24 02:44:20 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_perf_test.c,v 1.1 2013/09/24 02:04:21 rmind Exp $ */
+/* $NetBSD: npf_perf_test.c,v 1.2 2013/09/24 02:44:20 rmind Exp $ */
/*
* NPF benchmarking.
@@ -16,24 +16,30 @@
#include "npf_impl.h"
#include "npf_test.h"
-#define NSECS 1 /* seconds */
+#define NSECS 10 /* seconds */
static volatile int run;
static volatile int done;
+static uint64_t * npackets;
+static bool stateful;
+
static struct mbuf *
-fill_packet(void)
+fill_packet(unsigned i)
{
struct mbuf *m;
struct ip *ip;
- struct tcphdr *th;
+ struct udphdr *uh;
+ char buf[32];
+
+ m = mbuf_construct(IPPROTO_UDP);
+ uh = mbuf_return_hdrs(m, false, &ip);
- m = mbuf_construct(IPPROTO_TCP);
- th = mbuf_return_hdrs(m, false, &ip);
+ snprintf(buf, sizeof(buf), "192.0.2.%u", i + i);
ip->ip_src.s_addr = inet_addr(PUB_IP1);
- ip->ip_dst.s_addr = inet_addr(LOCAL_IP3);
- th->th_sport = htons(80);
- th->th_dport = htons(15000);
+ ip->ip_dst.s_addr = inet_addr(stateful ? LOCAL_IP2 : LOCAL_IP3);
+ uh->uh_sport = htons(80);
+ uh->uh_dport = htons(15000 + i);
return m;
}
@@ -41,8 +47,9 @@
worker(void *arg)
{
ifnet_t *ifp = ifunit(IFNAME_INT);
- uint64_t n = 0, *npackets = arg;
- struct mbuf *m = fill_packet();
+ unsigned int i = (uintptr_t)arg;
+ struct mbuf *m = fill_packet(i);
+ uint64_t n = 0;
while (!run)
/* spin-wait */;
@@ -53,28 +60,29 @@
KASSERT(error == 0);
n++;
}
- *npackets = n;
+ npackets[i] = n;
kthread_exit(0);
}
void
-npf_test_conc(unsigned nthreads)
+npf_test_conc(bool st, unsigned nthreads)
{
- uint64_t total = 0, *npackets;
+ uint64_t total = 0;
int error;
lwp_t **l;
+ printf("THREADS\tPKTS\n");
+ stateful = st;
+ done = false;
+ run = false;
+
npackets = kmem_zalloc(sizeof(uint64_t) * nthreads, KM_SLEEP);
l = kmem_zalloc(sizeof(lwp_t *) * nthreads, KM_SLEEP);
- printf("THREADS\tPKTS\n");
- done = false;
- run = false;
-
for (unsigned i = 0; i < nthreads; i++) {
const int flags = KTHREAD_MUSTJOIN | KTHREAD_MPSAFE;
error = kthread_create(PRI_NONE, flags, NULL,
- worker, &npackets[i], &l[i], "npfperf");
+ worker, (void *)(uintptr_t)i, &l[i], "npfperf");
KASSERT(error == 0);
}
diff -r 64efef7ecee0 -r a72b8ee47adb usr.sbin/npf/npftest/libnpftest/npf_test.h
--- a/usr.sbin/npf/npftest/libnpftest/npf_test.h Tue Sep 24 02:04:21 2013 +0000
+++ b/usr.sbin/npf/npftest/libnpftest/npf_test.h Tue Sep 24 02:44:20 2013 +0000
@@ -45,7 +45,7 @@
int npf_test_statetrack(const void *, size_t, unsigned,
bool, int64_t *);
-void npf_test_conc(unsigned);
+void npf_test_conc(bool, unsigned);
struct mbuf * mbuf_getwithdata(const void *, size_t);
struct mbuf * mbuf_construct_ether(int);
diff -r 64efef7ecee0 -r a72b8ee47adb usr.sbin/npf/npftest/npftest.c
--- a/usr.sbin/npf/npftest/npftest.c Tue Sep 24 02:04:21 2013 +0000
+++ b/usr.sbin/npf/npftest/npftest.c Tue Sep 24 02:44:20 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: npftest.c,v 1.11 2013/09/24 02:04:21 rmind Exp $ */
+/* $NetBSD: npftest.c,v 1.12 2013/09/24 02:44:20 rmind Exp $ */
/*
* NPF testing framework.
@@ -137,12 +137,12 @@
int
main(int argc, char **argv)
{
- bool benchmark, test, ok, fail, tname_matched;
- char *config, *interface, *stream, *testname;
+ bool test, ok, fail, tname_matched;
+ char *benchmark, *config, *interface, *stream, *testname;
unsigned nthreads = 0;
int idx = -1, ch;
- benchmark = false;
+ benchmark = NULL;
test = false;
tname_matched = false;
@@ -154,10 +154,10 @@
verbose = false;
quiet = false;
- while ((ch = getopt(argc, argv, "bqvc:i:s:tT:Lp:")) != -1) {
+ while ((ch = getopt(argc, argv, "b:qvc:i:s:tT:Lp:")) != -1) {
switch (ch) {
case 'b':
- benchmark = true;
+ benchmark = optarg;
break;
case 'q':
quiet = true;
@@ -204,7 +204,7 @@
* interface should be specified. If benchmark, then the
* config should be loaded.
*/
- if (benchmark == test && (stream && !interface)) {
+ if ((benchmark != NULL) == test && (stream && !interface)) {
usage();
}
if (benchmark && (!config || !nthreads)) {
@@ -276,7 +276,12 @@
}
if (benchmark) {
- rumpns_npf_test_conc(nthreads);
+ if (strcmp("rule", benchmark) == 0) {
+ rumpns_npf_test_conc(false, nthreads);
+ }
+ if (strcmp("state", benchmark) == 0) {
+ rumpns_npf_test_conc(true, nthreads);
+ }
}
rump_unschedule();
diff -r 64efef7ecee0 -r a72b8ee47adb usr.sbin/npf/npftest/npftest.h
--- a/usr.sbin/npf/npftest/npftest.h Tue Sep 24 02:04:21 2013 +0000
+++ b/usr.sbin/npf/npftest/npftest.h Tue Sep 24 02:44:20 2013 +0000
@@ -17,7 +17,7 @@
int rumpns_npf_test_statetrack(const void *, size_t,
unsigned, bool, int64_t *);
-void rumpns_npf_test_conc(unsigned);
+void rumpns_npf_test_conc(bool, unsigned);
bool rumpns_npf_nbuf_test(bool);
bool rumpns_npf_bpf_test(bool);
Home |
Main Index |
Thread Index |
Old Index