BIND 10 exp/res-research, updated. f03e60f9c0847867bc20f0c69f924974b5b659a4 [res-research] some updates to the forwarder:
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jun 29 21:02:21 UTC 2012
The branch, exp/res-research has been updated
via f03e60f9c0847867bc20f0c69f924974b5b659a4 (commit)
from 2ea61cbc5aaf38777cc9e9483e03ec28b8fa5b7d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit f03e60f9c0847867bc20f0c69f924974b5b659a4
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Fri Jun 29 17:01:13 2012 -0400
[res-research] some updates to the forwarder:
make local forwarding port configurable
check queries before checking responses (for stabler resutls)
dump more statistics
-----------------------------------------------------------------------
Summary of changes:
exp/res-research/benchmark/simple_forwarder.cc | 134 +++++++++++++++++-------
1 file changed, 98 insertions(+), 36 deletions(-)
-----------------------------------------------------------------------
diff --git a/exp/res-research/benchmark/simple_forwarder.cc b/exp/res-research/benchmark/simple_forwarder.cc
index 9630e2b..ed3d247 100644
--- a/exp/res-research/benchmark/simple_forwarder.cc
+++ b/exp/res-research/benchmark/simple_forwarder.cc
@@ -35,23 +35,31 @@ using namespace isc::util::io::internal;
namespace {
unsigned long recv_count = 0;
unsigned long resp_count = 0;
+unsigned long recvresp_count = 0;
+unsigned long forward_count = 0;
void
sigterm_handler(int) {
- cout << recv_count << " packets received, " << resp_count
- << " responded" << endl;
+ cout << recv_count << " packets received, "
+ << forward_count << " forwarded, "
+ << recvresp_count << " response received, "
+ << resp_count << " responded" << endl;
exit(0);
}
void
usage() {
- cout << "usage: simple_forwarder [-p port] [-P fwd_port] [-s size] [-S addr]\n";
+ cout << "usage: simple_forwarder [-p port] [-P fwd_port] "
+ "[-Q fwd_local_port] [-s size] [-S addr]\n";
cout << " -p port: specifies the receiving port (default 5300)\n";
cout << " -s size: specifies the size of responses (default 512)\n";
cout << " -P port: specifies the remote port for forwarding "
+ "(default 5302)\n";
+ cout << " -Q port: specifies the local port for forwarding "
"(default 5301)\n";
cout << " -S addr: specifies the remote address for forwarding "
"(default 127.0.0.1)\n";
+ exit(1);
}
}
@@ -59,17 +67,25 @@ int
main(int argc, char** argv) {
int ch;
const char* recvport = "5300";
- const char* fwdport = "5301";
+ const char* fwd_localport = "5301";
+ const char* fwdport = "5302";
const char* fwdaddr = "127.0.0.1";
size_t resp_size = 512;
- while ((ch = getopt(argc, argv, "hp:P:s:S:")) != -1) {
+ int rcvbuf_set = 0; // unspecified
+ while ((ch = getopt(argc, argv, "b:hp:P:Q:s:S:")) != -1) {
switch (ch) {
+ case 'b':
+ rcvbuf_set = atoi(optarg);
+ break;
case 'p':
recvport = optarg;
break;
case 'P':
fwdport = optarg;
break;
+ case 'Q':
+ fwd_localport = optarg;
+ break;
case 's':
resp_size = atoi(optarg);
break;
@@ -88,6 +104,7 @@ main(int argc, char** argv) {
usage();
}
+ // Create "server" socket that accepts queries
struct addrinfo hints;
struct addrinfo* res;
memset(&hints, 0, sizeof(hints));
@@ -111,6 +128,23 @@ main(int argc, char** argv) {
}
freeaddrinfo(res);
+ int rcvbuf;
+ socklen_t optlen = sizeof(rcvbuf);
+ if (getsockopt(s, SOL_SOCKET, SO_RCVBUF, &rcvbuf, &optlen) != 0) {
+ cout << "getsockopt failed " << strerror(errno) << endl;
+ return (1);
+ }
+ cout << "current receive socket buffer=" << rcvbuf << endl;
+ if (rcvbuf_set > 0) {
+ if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &rcvbuf_set,
+ sizeof(rcvbuf_set)) != 0) {
+ cout << "setsockopt failed " << strerror(errno) << endl;
+ return (1);
+ }
+ cout << "receive socket buffer reset to=" << rcvbuf_set << endl;
+ }
+
+ // Create forwarding socket
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
@@ -119,7 +153,7 @@ main(int argc, char** argv) {
const int error2 = getaddrinfo(fwdaddr, fwdport, &hints, &res);
if (error2 != 0) {
cerr << "getaddrinfo failed for forward addr/port: "
- << gai_strerror(error) << endl;
+ << gai_strerror(error2) << endl;
return (1);
}
const int s_fwd = socket(res->ai_family, res->ai_socktype,
@@ -128,19 +162,33 @@ main(int argc, char** argv) {
cout << "socket failed " << strerror(errno) << endl;
return (1);
}
- if (bind(s_fwd, res->ai_addr, res->ai_addrlen) != 0) {
- cout << "bind failed " << strerror(errno) << endl;
- return (1);
- }
struct sockaddr_storage fwd_ss;
memcpy(&fwd_ss, res->ai_addr, res->ai_addrlen);
const socklen_t fwd_salen = res->ai_addrlen;
freeaddrinfo(res);
+ // Bind the forwarding socket
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_protocol = IPPROTO_UDP;
+ hints.ai_flags = AI_NUMERICSERV | AI_PASSIVE;
+ const int error3 = getaddrinfo(NULL, fwd_localport, &hints, &res);
+ if (error3 != 0) {
+ cerr << "getaddrinfo failed: " << gai_strerror(error3) << endl;
+ return (1);
+ }
+ if (bind(s_fwd, res->ai_addr, res->ai_addrlen) != 0) {
+ cout << "bind (local forward port) failed " << strerror(errno) << endl;
+ return (1);
+ }
+ freeaddrinfo(res);
+
signal(SIGTERM, sigterm_handler);
signal(SIGINT, sigterm_handler);
struct sockaddr_storage from_ss;
+ socklen_t fromlen = sizeof(from_ss);
struct sockaddr_storage from_fwd_ss;
uint8_t recvbuf[4096];
assert(sizeof(recvbuf) >= resp_size);
@@ -158,32 +206,10 @@ main(int argc, char** argv) {
return (1);
}
- struct sockaddr* from = convertSockAddr(&from_ss);
- socklen_t fromlen = sizeof(from_ss);
- struct sockaddr* from_fwd = convertSockAddr(&from_fwd_ss);
- socklen_t fromfwd_len = sizeof(from_fwd_ss);
-
- if (FD_ISSET(s_fwd, &fdset)) {
- // If we get a response from the "remote server", send it back
- // to the client
- int cc = recvfrom(s_fwd, recvbuf, sizeof(recvbuf), 0,
- from_fwd, &fromfwd_len);
- if (cc <= 0) {
- cout << "unexpected empty result on recvfrom" << endl;
- return (1);
- }
- cc = sendto(s, recvbuf, resp_size, 0, from, fromlen);
- if (cc < 0 || cc != resp_size) {
- cout << "unexpected result on sendto" << endl;
- return (1);
- }
- ++resp_count;
- }
-
// This is a "normal query" from a client
if (FD_ISSET(s, &fdset)) {
int cc = recvfrom(s, recvbuf, sizeof(recvbuf), 0,
- from, &fromlen);
+ convertSockAddr(&from_ss), &fromlen);
if (cc <= 0) {
cout << "unexpected empty result on recvfrom" << endl;
return (1);
@@ -193,19 +219,55 @@ main(int argc, char** argv) {
// emulating "90% cache hit": 10% of queries are forwarded, and
// the rest are responded immediately.
if ((recv_count % 10) == 9) {
- cc = sendto(s, recvbuf, cc, 0, convertSockAddr(&fwd_ss),
+ cc = sendto(s_fwd, recvbuf, cc, 0, convertSockAddr(&fwd_ss),
fwd_salen);
if (cc < 0) {
cout << "unexpected result on sendto for forward" << endl;
return (1);
}
+ ++forward_count;
+ } else {
+ cc = sendto(s, recvbuf, resp_size, 0,
+ convertSockAddr(&from_ss), fromlen);
+ if (cc < 0 || cc != resp_size) {
+ cout << "unexpected result on sendto";
+ if (cc < 0) {
+ cout << ": " << strerror(errno);
+ }
+ cout << endl;
+ return (1);
+ }
+ ++resp_count;
+ }
+ }
+
+ struct sockaddr* from_fwd = convertSockAddr(&from_fwd_ss);
+ socklen_t fromfwd_len = sizeof(from_fwd_ss);
+ if (FD_ISSET(s_fwd, &fdset)) {
+ // If we get a response from the "remote server", send it back
+ // to the client
+ int cc = recvfrom(s_fwd, recvbuf, sizeof(recvbuf), 0,
+ from_fwd, &fromfwd_len);
+ if (cc <= 0) {
+ cout << "unexpected empty result on recvfrom" << endl;
+ return (1);
+ }
+ ++recvresp_count;
+ if (recv_count == 0) {
+ cout << "skip responding" << endl;
} else {
- cc = sendto(s, recvbuf, resp_size, 0, from, fromlen);
+ cc = sendto(s, recvbuf, resp_size, 0,
+ convertSockAddr(&from_ss), fromlen);
if (cc < 0 || cc != resp_size) {
- cout << "unexpected result on sendto" << endl;
+ cout << "unexpected result on sendto 2";
+ if (cc < 0) {
+ cout << ": " << strerror(errno);
+ }
+ cout << endl;
return (1);
}
}
+ ++resp_count;
}
}
return (0);
More information about the bind10-changes
mailing list