Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r735 committed - Re-architecting code for the Middlebox, meta, SFW tests, declaring con...

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r735 committed - Re-architecting code for the Middlebox, meta, SFW tests, declaring con...


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r735 committed - Re-architecting code for the Middlebox, meta, SFW tests, declaring con...
  • Date: Mon, 24 Oct 2011 02:28:51 +0000

Revision: 735
Author:

Date: Sun Oct 23 19:27:44 2011
Log: Re-architecting code for the Middlebox, meta, SFW tests, declaring constants for test-msg-logs, moving a few constants to more appropriate files
http://code.google.com/p/ndt/source/detail?r=735

Modified:
/branches/kkumar_code_organize/src/clt_tests.h
/branches/kkumar_code_organize/src/ndtptestconstants.h
/branches/kkumar_code_organize/src/test_c2s_clt.c
/branches/kkumar_code_organize/src/test_meta.h
/branches/kkumar_code_organize/src/test_meta_clt.c
/branches/kkumar_code_organize/src/test_mid_clt.c
/branches/kkumar_code_organize/src/test_sfw.h
/branches/kkumar_code_organize/src/test_sfw_clt.c
/branches/kkumar_code_organize/src/utils.h
/branches/kkumar_code_organize/src/web100-pcap.c
/branches/kkumar_code_organize/src/web100clt.c
/branches/kkumar_code_organize/src/web100srv.h

=======================================
--- /branches/kkumar_code_organize/src/clt_tests.h Mon Oct 17 06:43:25
2011
+++ /branches/kkumar_code_organize/src/clt_tests.h Sun Oct 23 19:27:44
2011
@@ -9,6 +9,8 @@
#ifndef _JS_CLT_TESTS_H
#define _JS_CLT_TESTS_H

+#define MIDBOX_TEST_LOG "Middlebox test"
+
int test_mid_clt(int ctlSocket, char tests, char* host, int conn_options,
int buf_size, char* tmpstr2);
int test_c2s_clt(int ctlSocket, char tests, char* host, int conn_options,
=======================================
--- /branches/kkumar_code_organize/src/ndtptestconstants.h Mon Oct 17 06:43:25 2011
+++ /branches/kkumar_code_organize/src/ndtptestconstants.h Sun Oct 23 19:27:44 2011
@@ -1,5 +1,6 @@
/**
* This file defines the various test types and other constants that the NDT protocol currently supports/uses.
+ * This is used to define constants related to the test-suite, specifically.
*
* */

@@ -19,6 +20,13 @@
#define TEST_DIRN_DESC_SIZE 20 /* direction is either client_to_server or server_to_client */
#define MSG_TYPE_DESC_SIZE 15 /* max size for now derived from "TEST_FINALIZE" */

+// port numbers
+#define PORT "3001"
+#define PORT2 "3002"
+#define PORT3 "3003"
+#define PORT4 "3003"
+
+
/* status of tests. Used mainly to log a "textual" explanation using below array */
enum TEST_STATUS_INT {
TEST_NOT_STARTED, TEST_STARTED, TEST_INPROGRESS, TEST_INCOMPLETE, TEST_ENDED
=======================================
--- /branches/kkumar_code_organize/src/test_c2s_clt.c Sat Oct 22 10:53:27 2011
+++ /branches/kkumar_code_organize/src/test_c2s_clt.c Sun Oct 23 19:27:44 2011
@@ -159,7 +159,7 @@
return 1;
}
if (check_msg_type("C2S throughput test", TEST_MSG, msgType, buff, msgLen)) {
- // other message types at this junctue indicate error
+ // other message types at this juncture indicate error
return 2;
}
if (msgLen <= 0) { // message payload size cannot be
negative! Error.
@@ -178,7 +178,7 @@
printf(" %0.2f Mb/s\n", c2sspd/KILO);

// Server should close test session with an empty
TEST_FINALIZE message.
- // Any other type of message is an error
+ // Any other type of message is an error.
msgLen = sizeof(buff);
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed finalize
message!");
=======================================
--- /branches/kkumar_code_organize/src/test_meta.h Sun May 8 04:04:21
2011
+++ /branches/kkumar_code_organize/src/test_meta.h Sun Oct 23 19:27:44
2011
@@ -13,6 +13,8 @@
#define META_CLIENT_KERNEL_VERSION "client.kernel.version"
#define META_CLIENT_VERSION "client.version"

+#define META_TEST_LOG "META test"
+
int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options);

#endif
=======================================
--- /branches/kkumar_code_organize/src/test_meta_clt.c Mon Oct 17 06:43:25 2011
+++ /branches/kkumar_code_organize/src/test_meta_clt.c Sun Oct 23 19:27:44 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions needed to handle META
* test (client part).
*
@@ -24,34 +24,57 @@
int sndqueue;
double spdout, c2sspd;

+/**
+ * The META test allows the Client to send additional information to the
+ * Server that gets included along with the overall set of test results.
+ * @param ctlSocket server control socket descriptor
+ * @param tests set of tests to perform
+ * @param host hostname of the server
+ * @param conn_options connection options
+ * @return integer
+ * 0 = (the test has been finalized)
+ * >0 if protocol interactions were not as expected:
+ * 1: Unable to receive protocol message successfully
+ * 2: Wrong message type received
+ */
int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options) {
char buff[1024], tmpBuff[512];
int msgLen, msgType;
FILE * fp;

- if (tests & TEST_META) {
+ if (tests & TEST_META) { // perform META tests
log_println(1, " <-- META test -->");
msgLen = sizeof(buff);
+ // Server starts with a TEST_PREPARE message. Any other
+ // .. type of message at this juncture is unexpected !
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed prepare
message!");
return 1;
}
- if (check_msg_type("META test", TEST_PREPARE, msgType, buff,
msgLen)) {
+ if (check_msg_type(META_TEST_LOG, TEST_PREPARE, msgType,
buff, msgLen)) {
return 2;
}

+ // Server now sends a TEST_START message. Any other message
type is
+ // .. indicative of errors
msgLen = sizeof(buff);
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed start
message!");
return 1;
}
- if (check_msg_type("META test", TEST_START, msgType, buff,
msgLen)) {
+ if (check_msg_type(META_TEST_LOG, TEST_START, msgType, buff,
msgLen)) {
return 2;
}
+
+ // As a response to the Server's TEST_START message, client
responds
+ // ..with TEST_MSG. These messages may be used, as below, to send configuration data
+ // ...name-value pairs. Note that there are length constraints to keys- values: 64/256
+ // ....characters respectively

printf("sending meta information to server . . . . . ");
fflush(stdout);

+ // send client os name details
if ((fp = fopen("/proc/sys/kernel/ostype", "r")) == NULL) {
log_println(0, "Unable to determine client os type.");
} else {
@@ -61,9 +84,11 @@
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
}

+ // send client browser name
sprintf(buff, "%s:%s", META_BROWSER_OS, "- (web100clt)");
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));

+ // send client kernel version
if ((fp = fopen("/proc/sys/kernel/osrelease", "r")) == NULL) {
log_println(0, "Unable to determine client kernel
version.");
} else {
@@ -73,19 +98,24 @@
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
}

+ // send NDT client version
sprintf(buff, "%s:%s", META_CLIENT_VERSION, VERSION);
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));

+ // Client can send any number of such meta data in a TEST_MSG
+ // .. format, and signal the end of the transmission using an empty TEST_MSG
send_msg(ctlSocket, TEST_MSG, "", 0);

printf("Done\n");

+ // All data has been sent. Expect server to close this META
test session
+ // ... by sending an empty TEST_FINALIZE message
msgLen = sizeof(buff);
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed finalize
message!");
return 1;
}
- if (check_msg_type("META test", TEST_FINALIZE, msgType, buff,
msgLen)) {
+ if (check_msg_type(META_TEST_LOG, TEST_FINALIZE, msgType, buff, msgLen)) {
return 2;
}
log_println(1, " <------------------------->");
=======================================
--- /branches/kkumar_code_organize/src/test_mid_clt.c Mon Oct 17 06:43:25 2011
+++ /branches/kkumar_code_organize/src/test_mid_clt.c Sun Oct 23 19:27:44 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions needed to handle Middlebox
* test (client part).
*
@@ -16,37 +16,75 @@
#include "protocol.h"
#include "utils.h"

+/**
+ * Perform the client part of the middleBox testing. The middlebox test
+ * is a 5.0 second throughput test from the Server to the Client to
+ * check for duplex mismatch conditions. It determines if routers or
+ * switches in the path may be making changes to some TCP parameters.
+ * @param ctlSocket server control socket descriptor
+ * @param tests set of tests to perform
+ * @param host hostname of the server
+ * @param conn_options connection options
+ * @param buf_size TCP send/receive buffer size
+ * @param tmpstr2 result obtained from server (containing server ip,
+ * client ip, currentMSS,
WinSCaleSent, WinScaleRcvd)
+ * @return integer
+ * => 0 on success
+ * < 0 if error
+ * Return codes used:
+ * 0 = (the test has been finalized)
+ * > 0 if protocol interactions were not as expected:
+ * 1: Unable to receive protocol message successfully
+ * 2: Wrong message type received
+ * 3: Protocol message received was of invalid length
+ * 4: Protocol payload data received was invalid
+ * 5: Protocol message received was invalid
+ * < 0 if generic error:
+ * -3: Unable to resolve server address
+ * -10: creating connection to server failed
+ *
+ */
int test_mid_clt(int ctlSocket, char tests, char* host, int conn_options,
int buf_size, char* tmpstr2) {
- char buff[BUFFSIZE + 1];int msgLen, msgType;
- int midport = 3003;
+ char buff[BUFFSIZE + 1];
+ int msgLen, msgType;
+ int midport = PORT3;
I2Addr sec_addr = NULL;
- int ret, one=1, i, inlth;
+ int retcode, one=1, i, inlth;
int in2Socket;
double t, spdin;
uint32_t bytes;
struct timeval sel_tv;
fd_set rfd;

- if (tests & TEST_MID) {
+ if (tests & TEST_MID) { // middlebox test has to be performed
log_println(1, " <-- Middlebox test -->");
+
+ // Initially, expecting a TEST_PREPARE message. Any other
message
+ // ..type is unexpected at this stage.
+
msgLen = sizeof(buff);
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed prepare
message!");
return 1;
}
- if (check_msg_type("Middlebox test", TEST_PREPARE, msgType, buff, msgLen)) {
+ if (check_msg_type(MIDBOX_TEST_LOG, TEST_PREPARE, msgType, buff, msgLen)) {
return 2;
}
+
+ // The server is expected to send a message with a valid payload that contains
+ // .. the port number that server wants client to bind to for
this test
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
}
buff[msgLen] = 0;
- if (check_int(buff, &midport)) {
+ if (check_int(buff, &midport)) { // obtained message does not contain integer port#
log_println(0, "Invalid port number");
return 4;
}
+
+ // get server address and set port
log_println(1, " -- port: %d", midport);
if ((sec_addr = I2AddrByNode(get_errhandle(), host)) == NULL)
{
log_println(0, "Unable to resolve server address:
%s", strerror(errno));
@@ -54,7 +92,7 @@
}
I2AddrSetPort(sec_addr, midport);

- if (get_debuglvl() > 4) {
+ if (get_debuglvl() > 4) { //debug to check if correct port was set in addr struct
char tmpbuff[200];
size_t tmpBufLen = 199;
memset(tmpbuff, 0, 200);
@@ -62,69 +100,80 @@
log_println(5, "connecting to %s:%d", tmpbuff,
I2AddrPort(sec_addr));
}

- if ((ret = CreateConnectSocket(&in2Socket, NULL, sec_addr, conn_options, buf_size))) {
+ // connect to server using port obtained above
+ if ((retcode = CreateConnectSocket(&in2Socket, NULL, sec_addr, conn_options, buf_size))) {
log_println(0, "Connect() for middlebox failed: %s",
strerror(errno));
return -10;
}

+ // start reading throughput test data from server using the connection created above
printf("Checking for Middleboxes . . . . . . . . . . . . . . . . .
. ");
fflush(stdout);
tmpstr2[0] = '\0';
i = 0;
bytes = 0;
- t = secs() + 5.0;
- sel_tv.tv_sec = 6;
- sel_tv.tv_usec = 5;
+ t = secs() + 5.0; // set timer for 5 seconds, and read for 5
seconds
+ sel_tv.tv_sec = 6; // Time out the socket after 6.5 seconds
+ sel_tv.tv_usec = 5; // 500?
FD_ZERO(&rfd);
FD_SET(in2Socket, &rfd);
for (;;) {
if (secs() > t)
- break;
- ret = select(in2Socket+1, &rfd, NULL, NULL, &sel_tv);
- if (ret > 0) {
+ break;
+ retcode = select(in2Socket+1, &rfd, NULL, NULL,
&sel_tv);
+ if (retcode > 0) {
inlth = read(in2Socket, buff, sizeof(buff));
if (inlth == 0)
- break;
+ break;
bytes += inlth;
continue;
}
- if (ret < 0) {
+ if (retcode < 0) {
printf("nothing to read, exiting read
loop\n");
break;
}
- if (ret == 0) {
+ if (retcode == 0) {
printf("timer expired, exiting read loop\n");
break;
}
}
+ // get actual time for which
t = secs() - t + 5.0;
- spdin = ((8.0 * bytes) / 1000) / t;
-
+
+ // calculate throughput in Kbps
+ spdin = ((BITS_8 * bytes) / KILO) / t;
+
+ // Test is complete. Now, get throughput results from server.
+ // The results are sent from server in the form of a TEST_MSG
object
msgLen = sizeof(buff);
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed text
message!");
return 1;
}
- if (check_msg_type("Middlebox test results", TEST_MSG, msgType, buff, msgLen)) {
+ if (check_msg_type(MIDBOX_TEST_LOG " results", TEST_MSG, msgType, buff, msgLen)) {
return 2;
}
- //strncat(tmpstr2, buff, msgLen);
- strlcat(tmpstr2, buff, 512);//todo hardcoded size for now
-
- memset(buff, 0, 128);
+
+ strlcat(tmpstr2, buff, 512);// hardcoded size as buffer size
from main
+
+ memset(buff, 0, 128); // this should work since the throuput results from the server should
+ // ...fit well within 128 chars
sprintf(buff, "%0.0f", spdin);
log_println(4, "CWND limited speed = %0.2f kbps", spdin);
+
+ // client now sends throughput it calculated above to server, as a TEST_MSG
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
printf("Done\n");

I2AddrFree(sec_addr);

+ // Expect an empty TEST_FINALIZE message from server
msgLen = sizeof(buff);
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed finalize
message!");
return 1;
}
- if (check_msg_type("Middlebox test", TEST_FINALIZE, msgType, buff, msgLen)) {
+ if (check_msg_type(MIDBOX_TEST_LOG, TEST_FINALIZE, msgType, buff, msgLen)) {
return 2;
}
log_println(1, " <-------------------->");
=======================================
--- /branches/kkumar_code_organize/src/test_sfw.h Fri Aug 25 02:20:49
2006
+++ /branches/kkumar_code_organize/src/test_sfw.h Sun Oct 23 19:27:44
2011
@@ -14,6 +14,10 @@
#define SFW_UNKNOWN 2
#define SFW_POSSIBLE 3

+#define SFW_TEST_DEFAULT_LEN 20
+#define SFW_PREDEFINED_TEST_MSG "Simple firewall test"
+#define SFW_TEST_LOG "Simple firewall test"
+
int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options);
int results_sfw(char tests, char* host);

=======================================
--- /branches/kkumar_code_organize/src/test_sfw_clt.c Mon Oct 17 06:43:25 2011
+++ /branches/kkumar_code_organize/src/test_sfw_clt.c Sun Oct 23 19:27:44 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions needed to handle simple firewall
* test (client part).
*
@@ -25,12 +25,11 @@
static int sfwsockfd;
static I2Addr sfwcli_addr = NULL;

-/*
- * Function name: catch_alrm
- * Description: Prints the appropriate message when the SIGALRM is catched.
- * Arguments: signo - the signal number (shuld be SIGALRM)
- */
-
+
+/**
+ * Print the appropriate message when the SIGALRM is caught.
+ * @param signo signal number (shuld be SIGALRM)
+ */
void catch_alrm(int signo) {
if (signo == SIGALRM) {
log_println(1, "SIGALRM was caught");
@@ -39,39 +38,48 @@
log_println(0, "Unknown (%d) signal was caught", signo);
}

-/*
- * Function name: test_osfw_clt
- * Description: Performs the client part of the opposite Simple
- * firewall test in the separate thread.
+/**
+ * Perform the client part of the opposite Simple firewall test in a separate thread.
+ * This thread listens for messages from the server for a given time period,
+ * and checks to see if the server has sent a message that is valid
+ * and sufficient to determine if the S->C direction has a fire-wall. It updates
+ * the value of the S->C firewall test result indicator based on the outcome.
+ *
+ * @param vptr void pointer reference to argument passed to this routine
+ * @return void pointer NULL
*/

void*
test_osfw_clt(void* vptr) {
- char buff[BUFFSIZE + 1];int sockfd;
+ char buff[BUFFSIZE + 1];
+ int sockfd;
fd_set fds;
struct timeval sel_tv;
int msgLen, msgType;
struct sockaddr_storage srv_addr;
socklen_t srvlen;

+ // listen for a message from server for a preset time, testTime
FD_ZERO(&fds);
FD_SET(sfwsockfd, &fds);
sel_tv.tv_sec = testTime;
sel_tv.tv_usec = 0;
switch (select(sfwsockfd+1, &fds, NULL, NULL, &sel_tv)) {
- case -1:
+ case -1: // If Socket error, status of firewall is unknown
log_println(0, "Simple firewall test: select exited with
error");
I2AddrFree(sfwcli_addr);
return NULL;
- case 0:
+ case 0: // timeout, indicates that firewall is a possibility
log_println(1, "Simple firewall test: no connection for %d seconds", testTime);
s2c_result = SFW_POSSIBLE;
I2AddrFree(sfwcli_addr);
return NULL;
}
+
+ // Get message sent by server. If message reception is erroneous, firewall status
+ // .. cannot be determined
srvlen = sizeof(srv_addr);
sockfd = accept(sfwsockfd, (struct sockaddr *) &srv_addr, &srvlen);
-
msgLen = sizeof(buff);
if (recv_msg(sockfd, &msgType, buff, &msgLen)) {
log_println(0, "Simple firewall test: unrecognized message");
@@ -80,13 +88,21 @@
I2AddrFree(sfwcli_addr);
return NULL;
}
- if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
+
+ // The server is expected to send a TEST_MSG type of packet. Any other message
+ // .. type is unexpected at this point and leaves firewall status indeterminate.
+ if (check_msg_type(SFW_TEST_LOG, TEST_MSG, msgType, buff, msgLen)) {
s2c_result = SFW_UNKNOWN;
close(sockfd);
I2AddrFree(sfwcli_addr);
return NULL;
}
- if (msgLen != 20) {
+
+ // The server is expected to send a 20 char message that
+ // says "Simple firewall test" . Every other message string
+ // indicates an unknown firewall status
+
+ if (msgLen != SFW_TEST_DEFAULT_LEN) {
log_println(0, "Simple firewall test: Improper message");
s2c_result = SFW_UNKNOWN;
close(sockfd);
@@ -94,13 +110,17 @@
return NULL;
}
buff[msgLen] = 0;
- if (strcmp(buff, "Simple firewall test") != 0) {
+ if (strcmp(buff, SFW_PREDEFINED_TEST_MSG) != 0) {
log_println(0, "Simple firewall test: Improper message");
s2c_result = SFW_UNKNOWN;
close(sockfd);
I2AddrFree(sfwcli_addr);
return NULL;
}
+
+ // If none of the above conditions were met, then, the server
+ // message has been received correctly, and there seems to be no
+ // firewall. Perform clean-up activities.

s2c_result = SFW_NOFIREWALL;
close(sockfd);
@@ -109,16 +129,28 @@
return NULL;
}

-/*
- * Function name: test_sfw_clt
- * Description: Performs the client part of the Simple firewall test.
- * Arguments: ctlsockfd - the server control socket descriptor
- * tests - the set of tests to perform
- * host - the hostname of the server
- * conn_options - the connection options
- * Returns: 0 - success (the test has been finalized).
+/**
+ * Perform the client part of the Simple firewall test.
+ * @param ctlsockfd server control socket descriptor
+ * @param tests set of tests to perform
+ * @param host hostname of the server
+ * @param conn_options the connection options
+ * @return integer
+ * => 0 on success
+ * < 0 if error
+ * Return codes used:
+ * 0 = (the test has been finalized)
+ * > 0 if protocol interactions were not as expected:
+ * 1: Unable to receive protocol message successfully
+ * 2: Wrong message type received
+ * 3: Protocol message received was of invalid length
+ * 4: Protocol payload data received was invalid
+ * 5: Protocol message received was invalid
+ * < 0 if generic error:
+ * -1: Listen socket creation failed
+ * -3: Unable to resolve server address
+ *
*/
-
int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options) {
char buff[BUFFSIZE + 1];int msgLen, msgType;
int sfwport, sfwsock, sfwsockport;
@@ -127,18 +159,25 @@
char* ptr;
pthread_t threadId;

- if (tests & TEST_SFW) {
+ if (tests & TEST_SFW) { // SFW test is to be performed
log_println(1, " <-- Simple firewall test -->");
printf("checking for firewalls . . . . . . . . . . . . . . . . . .
. ");
fflush(stdout);
msgLen = sizeof(buff);
+
+ // The first message expected from the server is a
TEST_PREPARE message.
+ // Any other type of message is unexpected at this time.
if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed prepare
message!");
return 1;
}
- if (check_msg_type("Simple firewall test", TEST_PREPARE, msgType, buff, msgLen)) {
+ if (check_msg_type(SFW_TEST_LOG, TEST_PREPARE, msgType, buff,
msgLen)) {
return 2;
}
+
+ // This message is expected to be of valid length, and have a
message
+ // .. payload containing the integral ephemeral port number
and testTime
+ // ... separated by a single space
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
@@ -149,7 +188,7 @@
log_println(0, "SFW: Improper message");
return 5;
}
- if (check_int(ptr, &sfwport)) {
+ if (check_int(ptr, &sfwport)) { // get ephemeral port#
log_println(0, "Invalid port number");
return 4;
}
@@ -158,7 +197,7 @@
log_println(0, "SFW: Improper message");
return 5;
}
- if (check_int(ptr, &testTime)) {
+ if (check_int(ptr, &testTime)) { // get test time
log_println(0, "Invalid waiting time");
return 4;
}
@@ -170,6 +209,7 @@
}
I2AddrSetPort(sfwsrv_addr, sfwport);

+ // create a listening socket, and if successful, send this socket number to server
sfwcli_addr = CreateListenSocket(NULL, "0", conn_options, 0);
if (sfwcli_addr == NULL) {
log_println(0, "Client (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
@@ -179,58 +219,75 @@
sfwsockport = I2AddrPort(sfwcli_addr);
log_println(1, " -- oport: %d", sfwsockport);

+ // Send a TEST_MSG to server with the client's port number
sprintf(buff, "%d", sfwsockport);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));

+ // The server responds to the TEST_MSG messages with a TEST_START message.
+ // Any other type of message is an error here.
if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed text
message!");
+ log_println(0, "Protocol error - missed start
message!");
return 1;
}
- if (check_msg_type("Simple firewall test", TEST_START, msgType, buff, msgLen)) {
+ if (check_msg_type(SFW_TEST_LOG, TEST_START, msgType, buff,
msgLen)) {
return 2;
}

+ // Now listen for server sending out a test for the S->C
direction , and
+ // update test results
pthread_create(&threadId, NULL, &test_osfw_clt, NULL);

- /* ignore the alrm signal */
+ // ignore the alarm signal
memset(&new, 0, sizeof(new));
new.sa_handler = catch_alrm;
sigaction(SIGALRM, &new, &old);
alarm(testTime + 1);
+
+ // Now, run Test from client for the C->S direction SFW test
+ // ..trying to connect to ephemeral port number sent by server
+
if (CreateConnectSocket(&sfwsock, NULL, sfwsrv_addr, conn_options, 0) == 0) {
- send_msg(sfwsock, TEST_MSG, "Simple firewall test",
20);
+ send_msg(sfwsock, TEST_MSG, SFW_PREDEFINED_TEST_MSG,
20);
}
alarm(0);
sigaction(SIGALRM, &old, NULL);

+ // Expect a TES_MSG from server with results. Other types of
messages are
+ // ..unexpected at this point.
+
msgLen = sizeof(buff);
if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed start
message!");
+ log_println(0, "Protocol error - missed text
message!");
return 1;
}
- if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
+ if (check_msg_type(SFW_TEST_LOG, TEST_MSG, msgType, buff,
msgLen)) {
return 2;
}
- if (msgLen <= 0) {
+
+ // The test results are sent as a numeric encoding the test
results.
+
+ if (msgLen <= 0) { // test results have valid length
log_println(0, "Improper message");
return 3;
}
buff[msgLen] = 0;
- if (check_int(buff, &c2s_result)) {
+ if (check_int(buff, &c2s_result)) { // test result has to be a valid integer
log_println(0, "Invalid test result");
return 4;
}

+ // wait for the S->C listener thread to finish
pthread_join(threadId, NULL);

printf("Done\n");

+ // The last message expected from the server is an empty TEST_FINALIZE message.
msgLen = sizeof(buff);
if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed finalize
message!");
return 1;
}
- if (check_msg_type("Simple firewall test", TEST_FINALIZE, msgType, buff, msgLen)) {
+ if (check_msg_type(SFW_TEST_LOG, TEST_FINALIZE, msgType,
buff, msgLen)) {
return 2;
}
log_println(1, " <-------------------------->");
@@ -238,39 +295,44 @@
return 0;
}

-/*
- * Function name: results_sfw
- * Description: Prints the results of the Simple firewall test to the client.
- * Arguments: tests - the set of tests to perform
- * host - the hostname of the server
- * Returns: 0 - success.
+/**
+ * Print the results of the Simple firewall test to the client.
+ * @param tests set of tests to perform
+ * @param host hostname of the server
+ * @return 0
*/

int results_sfw(char tests, char* host) {
- if (tests & TEST_SFW) {
+ if (tests & TEST_SFW) { // SFW test has been selected to be run
+ // Print C->S direction's results
switch (c2s_result) {
case SFW_NOFIREWALL:
printf(
- "Server '%s' is not behind a firewall. [Connection to the ephemeral port was successful]\n",
+ "Server '%s' is not behind a
firewall.",
+ " [Connection to the ephemeral port was
successful]\n",
host);
break;
case SFW_POSSIBLE:
printf(
- "Server '%s' is probably behind a firewall. [Connection to the ephemeral port failed]\n",
+ "Server '%s' is probably behind a
firewall."
+ " [Connection to the ephemeral port
failed]\n",
host);
break;
case SFW_UNKNOWN:
case SFW_NOTTESTED:
break;
}
+ // Print S->C directions results
switch (s2c_result) {
case SFW_NOFIREWALL:
printf(
- "Client is not behind a firewall. [Connection to the ephemeral port was successful]\n");
+ "Client is not behind a firewall.",
+ " [Connection to the ephemeral port was
successful]\n");
break;
case SFW_POSSIBLE:
printf(
- "Client is probably behind a firewall. [Connection to the ephemeral port failed]\n");
+ "Client is probably behind a
firewall.",
+ " [Connection to the ephemeral port
failed]\n");
break;
case SFW_UNKNOWN:
case SFW_NOTTESTED:
=======================================
--- /branches/kkumar_code_organize/src/utils.h Sat Oct 22 10:53:27 2011
+++ /branches/kkumar_code_organize/src/utils.h Sun Oct 23 19:27:44 2011
@@ -60,9 +60,6 @@
#define NO_BAD_CABLE 0
#define POSSIBLE_BAD_CABLE 1

-// SFW Test default message length
-#define SFW_TEST_DEFAULT_LEN 20
-
// generic system wide constants
#define RETRY_COUNT 5 // retry counts
//#define BUFFSIZE 8192 // Buffer size
=======================================
--- /branches/kkumar_code_organize/src/web100-pcap.c Fri Oct 21 13:16:00 2011
+++ /branches/kkumar_code_organize/src/web100-pcap.c Sun Oct 23 19:27:44 2011
@@ -20,6 +20,7 @@
#include <linux/sockios.h>
#include <sys/ioctl.h>
#include "strlutils.h"
+#include "utils.h"

int dumptrace;
pcap_t *pd;
=======================================
--- /branches/kkumar_code_organize/src/web100clt.c Sat Oct 22 10:53:27
2011
+++ /branches/kkumar_code_organize/src/web100clt.c Sun Oct 23 19:27:44
2011
@@ -141,11 +141,11 @@
if (strchr(sysval, '.') == NULL) {
i = atoi(sysval);
save_int_values(sysvar, i);
- log_println(7, "Stored %d [%s] in %s", i, sysval,
sysvar);
+ log_println(6, "Stored %d [%s] in %s", i, sysval, sysvar); //todo change level
} else {
j = atof(sysval);
save_dbl_values(sysvar, &j);
- log_println(7, "Stored %0.2f (%s) in %s", j, sysval,
sysvar);
+ log_println(6, "Stored %0.2f (%s) in %s", j, sysval, sysvar); //todo change level
}
}

@@ -951,6 +951,7 @@
*/
for (;;) {
msgLen = sizeof(buff);
+ memset(buff, 0, msgLen); // reset buff and msgLen
if (ret = (recv_msg(ctlSocket, &msgType, buff, &msgLen))) {
if (errno == ECONNRESET)
log_println(0,
@@ -969,7 +970,6 @@
msgLen)) {
exit(2);
}
- //strncat(tmpstr, buff, msgLen);
strlcat(tmpstr, buff, sizeof(tmpstr));
log_println(6, "tmpstr = '%s'", tmpstr);
}
=======================================
--- /branches/kkumar_code_organize/src/web100srv.h Mon Oct 17 06:43:25
2011
+++ /branches/kkumar_code_organize/src/web100srv.h Sun Oct 23 19:27:44
2011
@@ -62,10 +62,12 @@
#define CONFIGFILE "/etc/ndt.conf"

/* hard-coded port values */
+/*
#define PORT "3001"
#define PORT2 "3002"
#define PORT3 "3003"
#define PORT4 "3003"
+*/

// Congestion window peak information
typedef struct CwndPeaks {


  • [ndt-dev] [ndt] r735 committed - Re-architecting code for the Middlebox, meta, SFW tests, declaring con..., ndt, 10/23/2011

Archive powered by MHonArc 2.6.16.

Top of Page