Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r830 committed - Fix for packet pair timing see issue#85.

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r830 committed - Fix for packet pair timing see issue#85.


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r830 committed - Fix for packet pair timing see issue#85.
  • Date: Wed, 17 Jul 2013 14:57:58 +0000

Revision: 830
Author:

Date: Wed Jul 17 07:57:34 2013
Log: Fix for packet pair timing see issue#85.
http://code.google.com/p/ndt/source/detail?r=830

Modified:
/trunk/src/test_c2s_srv.c
/trunk/src/test_s2c_srv.c
/trunk/src/web100-pcap.c
/trunk/src/web100srv.c
/trunk/src/web100srv.h

=======================================
--- /trunk/src/test_c2s_srv.c Thu Apr 11 07:37:40 2013
+++ /trunk/src/test_c2s_srv.c Wed Jul 17 07:57:34 2013
@@ -21,10 +21,6 @@
#include "network.h"
#include "mrange.h"

-// used to store file descriptors of pipes created for ndttrace for C2S tests
-int mon_pipe1[2];
-
-
/**
* Perform the C2S Throughput test. This test intends to measure throughput
* from the client to the server by performing a 10 seconds memory-to-memory data transfer.
@@ -65,6 +61,8 @@
int conn_options, double* c2sspd, int set_buff, int window,
int autotune, char* device, Options* options, int record_reverse,
int count_vars, char spds[4][256], int* spd_index) {
+ /* The pipe that will return packet pair results */
+ int mon_pipe[2];
int recvsfd; // receiver socket file descriptor
pid_t c2s_childpid = 0; // child process pids
int msgretvalue, tmpbytecount; // used during the "read"/"write" process
@@ -268,7 +266,7 @@
&pair, currenttestdesc, options->compress, meta.c2s_ndttrace);
*/

- pipe(mon_pipe1);
+ pipe(mon_pipe);
if ((c2s_childpid = fork()) == 0) {
/* close(ctlsockfd); */
close(testOptions->c2ssockfd);
@@ -276,18 +274,22 @@
log_println(
5,
"C2S test Child %d thinks pipe() returned fd0=%d, fd1=%d",
- testOptions->child0, mon_pipe1[0], mon_pipe1[1]);
+ testOptions->child0, mon_pipe[0], mon_pipe[1]);
log_println(2, "C2S test calling init_pkttrace() with pd=%p",
&cli_addr);
init_pkttrace(src_addr, (struct sockaddr *) &cli_addr, clilen,
- mon_pipe1, device, &pair, "c2s", options->compress);
+ mon_pipe, device, &pair, "c2s", options->compress);
+ log_println(1, "c2s is exiting gracefully");
+ /* Close the pipe */
+ close(mon_pipe[0]);
+ close(mon_pipe[1]);
exit(0); /* Packet trace finished, terminate gracefully */
}

// Get data collected from packet tracing into the C2S "ndttrace" file
memset(tmpstr, 0, 256);
for (i = 0; i < 5; i++) {
- msgretvalue = read(mon_pipe1[0], tmpstr, 128);
+ msgretvalue = read(mon_pipe[0], tmpstr, 128);
if ((msgretvalue == -1) && (errno == EINTR))
continue;
break;
@@ -300,7 +302,7 @@
}

log_println(5, "C2S test Parent thinks pipe() returned fd0=%d, fd1=%d",
- mon_pipe1[0], mon_pipe1[1]);
+ mon_pipe[0], mon_pipe[1]);

// experimental code, delete when finished
setCwndlimit(conn, group, agent, options);
@@ -389,13 +391,13 @@
testOptions->child1 = c2s_childpid;
kill(c2s_childpid, SIGUSR1);
FD_ZERO(&rfd);
- FD_SET(mon_pipe1[0], &rfd);
+ FD_SET(mon_pipe[0], &rfd);
sel_tv.tv_sec = 1;
sel_tv.tv_usec = 100000;
i = 0;

for (;;) {
- msgretvalue = select(mon_pipe1[0] + 1, &rfd, NULL, NULL,
+ msgretvalue = select(mon_pipe[0] + 1, &rfd, NULL, NULL,
&sel_tv);
if ((msgretvalue == -1) && (errno == EINTR))
continue;
@@ -416,7 +418,7 @@
* RAC 2/8/10
*/
if (msgretvalue > 0) {
- if ((msgretvalue = read(mon_pipe1[0], spds[*spd_index],
+ if ((msgretvalue = read(mon_pipe[0], spds[*spd_index],
sizeof(spds[*spd_index]))) < 0) {
snprintf(
spds[*spd_index],
@@ -440,7 +442,7 @@

// Close opened resources for packet capture
if (getuid() == 0) {
- stop_packet_trace(mon_pipe1);
+ stop_packet_trace(mon_pipe);
}

// log end of C->S test
=======================================
--- /trunk/src/test_s2c_srv.c Thu Apr 11 07:37:40 2013
+++ /trunk/src/test_s2c_srv.c Wed Jul 17 07:57:34 2013
@@ -25,8 +25,6 @@
extern pthread_mutex_t mainmutex;
extern pthread_cond_t maincond;

-// used to store file descriptors of pipes created for ndttrace for S2C tests
-int mon_pipe2[2];

/**
* Perform the S2C Throughput test. This throughput test tests the achievable
@@ -74,6 +72,8 @@
int conn_options, double* s2cspd, int set_buff, int window,
int autotune, char* device, Options* options, char spds[4][256],
int* spd_index, int count_vars, CwndPeaks* peaks) {
+ /* Pipe that handles returning packet pair timing */
+ int mon_pipe[2];
int ret; // ctrl protocol read/write return status
int j, k, n;
int xmitsfd; // transmit (i.e server) socket fd
@@ -291,7 +291,7 @@
clilen, device, &pair, "s2c", options->compress,
meta.s2c_ndttrace);
*/
- pipe(mon_pipe2);
+ pipe(mon_pipe);
if ((s2c_childpid = fork()) == 0) {
/* close(ctlsockfd); */
close(testOptions->s2csockfd);
@@ -299,19 +299,22 @@
log_println(
5,
"S2C test Child thinks pipe() returned fd0=%d, fd1=%d",
- mon_pipe2[0], mon_pipe2[1]);
+ mon_pipe[0], mon_pipe[1]);
// log_println(2, "S2C test calling init_pkttrace() with pd=0x%x",
// (int) &cli_addr);
init_pkttrace(src_addr, (struct sockaddr *) &cli_addr,
- clilen, mon_pipe2, device, &pair, "s2c",
+ clilen, mon_pipe, device, &pair, "s2c",
options->compress);
log_println(6,
"S2C test ended, why is timer still running?");
+ /* Close the pipe */
+ close(mon_pipe[0]);
+ close(mon_pipe[1]);
exit(0); /* Packet trace finished, terminate gracefully */
}
memset(tmpstr, 0, 256);
for (i = 0; i < 5; i++) { // read nettrace file name into "tmpstr"
- ret = read(mon_pipe2[0], tmpstr, 128);
+ ret = read(mon_pipe[0], tmpstr, 128);
// socket interrupted, try reading again
if ((ret == -1) && (errno == EINTR))
continue;
@@ -484,13 +487,13 @@
testOptions->child2 = s2c_childpid;
kill(s2c_childpid, SIGUSR2);
FD_ZERO(&rfd);
- FD_SET(mon_pipe2[0], &rfd);
+ FD_SET(mon_pipe[0], &rfd);
sel_tv.tv_sec = 1;
sel_tv.tv_usec = 100000;
i = 0;

for (;;) {
- ret = select(mon_pipe2[0] + 1, &rfd, NULL, NULL, &sel_tv);
+ ret = select(mon_pipe[0] + 1, &rfd, NULL, NULL, &sel_tv);
if ((ret == -1) && (errno == EINTR)) {
log_println(
6,
@@ -519,7 +522,7 @@
* RAC 2/8/10
*/
if (ret > 0) {
- if ((ret = read(mon_pipe2[0], spds[*spd_index], 128))
+ if ((ret = read(mon_pipe[0], spds[*spd_index], 128))
< 0)
snprintf(
spds[*spd_index],
@@ -604,7 +607,7 @@
s2c_childpid);

if (getuid() == 0) {
- stop_packet_trace(mon_pipe2);
+ stop_packet_trace(mon_pipe);
}

// log end of test (generic and protocol logs)
=======================================
--- /trunk/src/web100-pcap.c Sun Apr 21 10:37:52 2013
+++ /trunk/src/web100-pcap.c Wed Jul 17 07:57:34 2013
@@ -30,8 +30,7 @@
static int dumptrace;
static pcap_t *pd;
static pcap_dumper_t *pdump;
-static int mon_pipe1[2], mon_pipe2[2];
-/* int sig1, sig2; */
+static int* mon_pipe;
static int sigj = 0, sigk = 0;
static int ifspeed;

@@ -47,7 +46,7 @@
void init_iflist(void) {
/* pcap_addr_t *ifaceAddr; */
pcap_if_t *alldevs, *dp;
- struct ethtool_cmd ecmd;
+ struct ethtool_cmd ecmd = {0}; /* Keep valgrind happy */
int fd, cnt, i, err;
struct ifreq ifr;
char errbuf[256];
@@ -114,83 +113,43 @@
}
}

-/** Check signal flags and process them accordingly.
- * If signal indicates request to terminate data collection for the speed bins,
- * make packet-pair based speed bins available to the parent process.
- *
- * @return 1 if data was successfully written
- * 0 if no relevant signals were actually received
+/**
+ * Send the packet-pair speed bins over pipe to parent.
*/
-static int check_signal_flags() {
- if ((sig1 == 1) || (sig2 == 1)) {
- log_println(
- 5,
- "Received SIGUSRx signal terminating data collection loop for pid=%d",
- getpid());
- if (sig1 == 1) {
- log_println(4,
- "Sending pkt-pair data back to parent on pipe %d, %d",
- mon_pipe1[0], mon_pipe1[1]);
- if (get_debuglvl() > 3) {
- if (fwd.family == 4) {
- fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
- fwd.saddr[0], fwd.sport, rev.saddr[0], rev.sport);
- } else if (fwd.family == 6) {
- char str[136];
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) fwd.saddr, str, sizeof(str));
- fprintf(stderr, "fwd.saddr = %s:%d", str, fwd.sport);
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) rev.saddr, str, sizeof(str));
- fprintf(stderr, ", rev.saddr = %s:%d\n", str, rev.sport);
- } else {
- fprintf(stderr, "check_signal_flags: Unknown IP family (%d)\n",
- fwd.family);
- }
- }
- print_bins(&fwd, mon_pipe1);
- usleep(30000); /* wait here 30 msec, for parent to read this data */
- print_bins(&rev, mon_pipe1);
- usleep(30000); /* wait here 30 msec, for parent to read this data */
- if (dumptrace == 1)
- pcap_dump_close(pdump);
- sig1 = 2;
+static void send_bins() {
+ log_println(
+ 5,
+ "Received SIGUSRx signal terminating data collection loop for pid=%d",
+ getpid());
+ log_println(4,
+ "Sending pkt-pair data back to parent on pipe %d, %d",
+ mon_pipe[0], mon_pipe[1]);
+ if (get_debuglvl() > 3) {
+ if (fwd.family == 4) {
+ fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
+ fwd.saddr[0], fwd.sport, rev.saddr[0], rev.sport);
+ } else if (fwd.family == 6) {
+ char str[136];
+ memset(str, 0, 136);
+ inet_ntop(AF_INET6, (void *) fwd.saddr, str, sizeof(str));
+ fprintf(stderr, "fwd.saddr = %s:%d", str, fwd.sport);
+ memset(str, 0, 136);
+ inet_ntop(AF_INET6, (void *) rev.saddr, str, sizeof(str));
+ fprintf(stderr, ", rev.saddr = %s:%d\n", str, rev.sport);
+ } else {
+ fprintf(stderr, "check_signal_flags: Unknown IP family (%d)\n",
+ fwd.family);
}
-
- if (sig2 == 1) {
- log_println(4,
- "Sending pkt-pair data back to parent on pipe %d, %d",
- mon_pipe2[0], mon_pipe2[1]);
- if (get_debuglvl() > 3) {
- if (fwd.family == 4) {
- fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
- fwd.saddr[0], fwd.sport, rev.saddr[0], rev.sport);
- } else if (fwd.family == 6) {
- char str[136];
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) fwd.saddr, str, sizeof(str));
- fprintf(stderr, "fwd.saddr = %s:%d", str, fwd.sport);
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) rev.saddr, str, sizeof(str));
- fprintf(stderr, ", rev.saddr = %s:%d\n", str, rev.sport);
- } else {
- fprintf(stderr, "check_signal_flags: Unknown IP family (%d)\n",
- fwd.family);
- }
- }
- print_bins(&fwd, mon_pipe2);
- usleep(30000); /* wait here 30 msec, for parent to read this data */
- print_bins(&rev, mon_pipe2);
- usleep(30000); /* wait here 30 msec, for parent to read this data */
- if (dumptrace == 1)
- pcap_dump_close(pdump);
- sig2 = 2;
- }
- log_println(6, "Finished reading pkt-pair data from network, process %d "
- "should terminate now", getpid());
- return 1;
}
- return 0;
+ print_bins(&fwd, mon_pipe);
+ usleep(30000); /* wait here 30 msec, for parent to read this data */
+ print_bins(&rev, mon_pipe);
+ usleep(30000); /* wait here 30 msec, for parent to read this data */
+ if (dumptrace == 1)
+ pcap_dump_close(pdump);
+
+ log_println(6, "Finished reading pkt-pair data from network, process %d "
+ "should terminate now", getpid());
}

/**
@@ -743,14 +702,13 @@

void init_pkttrace(I2Addr srcAddr, struct sockaddr *sock_addr,
socklen_t saddrlen, int monitor_pipe[2], char *device,
- PortPair* pair, char *direction, int compress) {
+ PortPair* pair, const char *direction, int compress) {
char cmdbuf[256], dir[256];
pcap_handler printer;
u_char * pcap_userdata = (u_char*) pair;
struct bpf_program fcode;
char errbuf[PCAP_ERRBUF_SIZE];
int cnt, pflag = 0, i;
- char c;
char namebuf[200], isoTime[64];
size_t nameBufLen = 199;
I2Addr sockAddr = NULL;
@@ -762,9 +720,10 @@
char logdir[256];

cnt = -1; /* read forever, or until end of file */
- sig1 = 0;
- sig2 = 0;

+ /* Store the monitor pipe as a static global for this file
+ * so we can stop the trace later */
+ mon_pipe = monitor_pipe;
init_vars(&fwd);
init_vars(&rev);

@@ -779,10 +738,18 @@
sock_addr = I2AddrSAddr(sockAddr, 0);
src_addr = I2AddrSAddr(srcAddr, 0);

+ // Disable, device can be NULL trying to copy "lo" into
+ // it will fail. Also fwd/rev still need to be set
+ //
+ // Pcap will figure out this should be "lo" below anyway
+ // TODO move fwd/rev outside of device == NULL check
+#if 0
/* special check for localhost, set device accordingly */
if (I2SockAddrIsLoopback(sock_addr, saddrlen) > 0)
// hardcoding device address to 100, as initialised in main()
strlcpy(device, "lo", 100);
+#endif
+
if (device == NULL) {
if (pcap_findalldevs(&alldevs, errbuf) == 0) {
for (dp = alldevs; dp != NULL; dp = dp->next) {
@@ -1005,9 +972,7 @@
}

/* Send back results to our parent */
- if(check_signal_flags() == 0){
- log_println(5, "Whatever happened, we should have a sig flag set");
- }
+ send_bins();

pcap_close(pd);

@@ -1028,20 +993,6 @@
*/
free(sockAddr);

- if (sig1 == 2) {
- while ((read(mon_pipe1[0], &c, 1)) < 0) { }
- close(mon_pipe1[0]);
- close(mon_pipe1[1]);
- sig1 = 0;
- }
- if (sig2 == 2) {
- while ((read(mon_pipe2[0], &c, 1)) < 0) { }
- sleep(2);
- close(mon_pipe2[0]);
- close(mon_pipe2[1]);
- sig2 = 0;
- }
-
log_println(
8,
"Finally Finished reading data from network, process %d should "
=======================================
--- /trunk/src/web100srv.c Sun Apr 21 12:34:46 2013
+++ /trunk/src/web100srv.c Wed Jul 17 07:57:34 2013
@@ -464,7 +464,6 @@
log_println(6,
"DEBUG, caught SIGUSR1, setting sig1 flag and calling force_breakloop");
force_breakloop();
- sig1 = 1;
break;

case SIGUSR2:
@@ -472,7 +471,6 @@
log_println(6,
"DEBUG, caught SIGUSR2, setting sig2 flag and calling force_breakloop");
force_breakloop();
- sig2 = 1;
break;

case SIGALRM:
@@ -1885,8 +1883,6 @@
head_ptr = NULL;
sig13 = 0;
sig17 = 0;
- sig1 = 0;
- sig2 = 0;
sem_init(&ndtq, 0, 1);

for (;;) {
=======================================
--- /trunk/src/web100srv.h Sun Apr 21 10:37:52 2013
+++ /trunk/src/web100srv.h Wed Jul 17 07:57:34 2013
@@ -187,7 +187,7 @@
int port3);
void init_pkttrace(I2Addr srcAddr, struct sockaddr *sock_addr,
socklen_t saddrlen, int monitor_pipe[2], char *device,
- PortPair* pair, char * direction, int compress);
+ PortPair* pair, const char* direction, int compress);
void force_breakloop();
#endif

@@ -227,8 +227,6 @@
char *get_remotehost();

/* global variables for signal processing */
-sig_atomic_t sig1;
-sig_atomic_t sig2;
sig_atomic_t sig13;
sig_atomic_t sig17;
pid_t sig17_pid[256];


  • [ndt-dev] [ndt] r830 committed - Fix for packet pair timing see issue#85., ndt, 07/17/2013

Archive powered by MHonArc 2.6.16.

Top of Page