Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r722 committed - Some more variables renamed, constants for often used values, and clea...

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r722 committed - Some more variables renamed, constants for often used values, and clea...


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r722 committed - Some more variables renamed, constants for often used values, and clea...
  • Date: Mon, 17 Oct 2011 13:31:56 +0000

Revision: 722
Author:

Date: Mon Oct 17 06:31:32 2011
Log: Some more variables renamed, constants for often used values, and cleanup
http://code.google.com/p/ndt/source/detail?r=722

Modified:
/branches/kkumar_code_organize/src/heuristics.h
/branches/kkumar_code_organize/src/logging.c
/branches/kkumar_code_organize/src/logging.h
/branches/kkumar_code_organize/src/network.c
/branches/kkumar_code_organize/src/network.h
/branches/kkumar_code_organize/src/protocol.c
/branches/kkumar_code_organize/src/runningtest.c
/branches/kkumar_code_organize/src/test_meta_srv.c
/branches/kkumar_code_organize/src/test_s2c_clt.c
/branches/kkumar_code_organize/src/test_sfw_srv.c
/branches/kkumar_code_organize/src/testoptions.c
/branches/kkumar_code_organize/src/usage.c
/branches/kkumar_code_organize/src/utils.c
/branches/kkumar_code_organize/src/utils.h
/branches/kkumar_code_organize/src/web100-admin.c
/branches/kkumar_code_organize/src/web100-pcap.c
/branches/kkumar_code_organize/src/web100-util.c
/branches/kkumar_code_organize/src/web100srv.c

=======================================
--- /branches/kkumar_code_organize/src/heuristics.h Sun Oct 16 15:37:17
2011
+++ /branches/kkumar_code_organize/src/heuristics.h Mon Oct 17 06:31:32
2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains function declarations for heuristics and algorithms.
*
* Created : Oct 2011
=======================================
--- /branches/kkumar_code_organize/src/logging.c Sun Oct 16 15:37:17
2011
+++ /branches/kkumar_code_organize/src/logging.c Mon Oct 17 06:31:32
2011
@@ -20,28 +20,22 @@
/* #endif */

#include "logging.h"
-//new addition after separating out ndtptests header, to include test types
-#include "testoptions.h" // Used only for getCurrentTest(), which can probably be moved elsewhere
-//#include "runningtest.h" // protocol validation
+#include "testoptions.h"
#include "strlutils.h"

-
-static int _debuglevel = 0;
-static char* _programname = "";
-static char* LogFileName = BASEDIR"/"LOGFILE;
-static char ProtocolLogFileName[256] = BASEDIR"/"PROTOLOGFILE;
-//static char* ProtocolLogFileName ;
-static char* ProtocolLogDirName = BASEDIR"/"LOGDIR;
-static char protocollogfilestore[256];
-static char enableprotologging = 0;
-static I2ErrHandle _errorhandler_nl = NULL;
-static I2ErrHandle _errorhandler = NULL;
+static int _debuglevel = 0;
+static char* _programname = "";
+static char* LogFileName = BASEDIR"/"LOGFILE;
+static char ProtocolLogFileName[FILENAME_SIZE] = BASEDIR"/"PROTOLOGFILE;
+static char* ProtocolLogDirName = BASEDIR"/"LOGDIR;
+static char protocollogfilestore[FILENAME_SIZE];
+static char enableprotologging = 0;
+static I2ErrHandle _errorhandler_nl = NULL;
+static I2ErrHandle _errorhandler = NULL;
static I2LogImmediateAttr _immediateattr_nl;
static I2LogImmediateAttr _immediateattr;
-static time_t timestamp;
-static long int utimestamp;
-
-
+static time_t timestamp;
+static long int utimestamp;

/**
* Compress snaplog, tcpdump, and cputime files to save disk space.
@@ -65,71 +59,73 @@

int zlib_def(char *src_fn) {

- int ret, flush, level=Z_DEFAULT_COMPRESSION;
- char dest_fn[256];
- FILE *dest, *source;
- unsigned have;
- z_stream strm;
- unsigned char in[16384];
- unsigned char out[16384];
-
- // allocate deflate state
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- ret = deflateInit(&strm, level);
- if (ret != Z_OK) {
- log_println(6, "zlib deflateInit routine failed with %d", ret);
- return ret;
- }
-
- sprintf(dest_fn, "%s.gz", src_fn);
- if ((source = fopen(src_fn, "r")) == NULL) {
- log_println(6, "zlib_def(): failed to open src file '%s' for reading", src_fn);
- return -3;
- }
- if ((dest = fopen(dest_fn, "w")) == NULL) {
- log_println(6, "zlib_def(): failed to open dest file '%s' for writing", dest_fn);
- return -4;
- }
- // compress until end of file
- do {
- strm.avail_in = fread(in, 1, 16384, source);
- if (ferror(source)) {
- (void)deflateEnd(&strm);
- return Z_ERRNO;
- }
- flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
- strm.next_in = in;
-
- // run deflate() on input until output buffer not full, finish
- // compression if all of source has been read in
- do {
- strm.avail_out = 16384;
- strm.next_out = out;
-
- ret = deflate(&strm, flush); /* no bad return value */
- assert(ret != Z_STREAM_ERROR); /* state not clobbered */
- have = 16384 - strm.avail_out;
- if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
- (void)deflateEnd(&strm);
- return Z_ERRNO;
- }
-
- } while (strm.avail_out == 0);
- assert(strm.avail_in == 0); /* all input will be used */
-
- /* done when last data in file processed */
- } while (flush != Z_FINISH);
- assert(ret == Z_STREAM_END); /* stream will be complete */
-
- /* clean up and return */
- (void)deflateEnd(&strm);
-
- /* compressed version of file is now created, remove the original uncompressed version */
- remove(src_fn);
-
- return Z_OK;
+ int ret, flush, level = Z_DEFAULT_COMPRESSION;
+ char dest_fn[256];
+ FILE *dest, *source;
+ unsigned have;
+ z_stream strm;
+ unsigned char in[16384];
+ unsigned char out[16384];
+
+ // allocate deflate state
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ ret = deflateInit(&strm, level);
+ if (ret != Z_OK) {
+ log_println(6, "zlib deflateInit routine failed with %d",
ret);
+ return ret;
+ }
+
+ sprintf(dest_fn, "%s.gz", src_fn);
+ if ((source = fopen(src_fn, "r")) == NULL) {
+ log_println(6, "zlib_def(): failed to open src file '%s' for
reading",
+ src_fn);
+ return -3;
+ }
+ if ((dest = fopen(dest_fn, "w")) == NULL) {
+ log_println(6, "zlib_def(): failed to open dest file '%s' for
writing",
+ dest_fn);
+ return -4;
+ }
+ // compress until end of file
+ do {
+ strm.avail_in = fread(in, 1, 16384, source);
+ if (ferror(source)) {
+ (void) deflateEnd(&strm);
+ return Z_ERRNO;
+ }
+ flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
+ strm.next_in = in;
+
+ // run deflate() on input until output buffer not full, finish
+ // compression if all of source has been read in
+ do {
+ strm.avail_out = 16384;
+ strm.next_out = out;
+
+ ret = deflate(&strm, flush); /* no bad return value */
+ assert(ret != Z_STREAM_ERROR); /* state not clobbered
*/
+ have = 16384 - strm.avail_out;
+ if (fwrite(out, 1, have, dest) != have ||
ferror(dest)) {
+ (void) deflateEnd(&strm);
+ return Z_ERRNO;
+ }
+
+ } while (strm.avail_out == 0);
+ assert(strm.avail_in == 0); /* all input will be used */
+
+ /* done when last data in file processed */
+ } while (flush != Z_FINISH);
+ assert(ret == Z_STREAM_END); /* stream will be complete */
+
+ /* clean up and return */
+ (void) deflateEnd(&strm);
+
+ /* compressed version of file is now created, remove the original uncompressed version */
+ remove(src_fn);
+
+ return Z_OK;
}
/* #endif */

@@ -139,43 +135,40 @@
* @param debuglvl The debug level
*/

-void
-log_init(char* progname, int debuglvl)
-{
- assert(progname);
-
- _programname = (_programname = strrchr(progname,'/')) ? _programname+1 : progname;
-
- _immediateattr.fp = _immediateattr_nl.fp = stderr;
- _immediateattr.line_info = I2MSG | I2NONL;
- _immediateattr_nl.line_info = I2MSG;
- _immediateattr.tformat = _immediateattr_nl.tformat = NULL;
-
- _errorhandler = I2ErrOpen(progname, I2ErrLogImmediate, &_immediateattr, NULL, NULL);
- _errorhandler_nl = I2ErrOpen(progname, I2ErrLogImmediate, &_immediateattr_nl, NULL, NULL);
-
- if (!_errorhandler || !_errorhandler_nl) {
- fprintf(stderr, "%s : Couldn't init error module\n", progname);
- exit(1);
- }
-
- _debuglevel = debuglvl;
+void log_init(char* progname, int debuglvl) {
+ assert(progname);
+
+ _programname =
+ (_programname = strrchr(progname, '/')) ?
+ _programname + 1 : progname;
+
+ _immediateattr.fp = _immediateattr_nl.fp = stderr;
+ _immediateattr.line_info = I2MSG | I2NONL;
+ _immediateattr_nl.line_info = I2MSG;
+ _immediateattr.tformat = _immediateattr_nl.tformat = NULL;
+
+ _errorhandler = I2ErrOpen(progname, I2ErrLogImmediate,
&_immediateattr,
+ NULL, NULL);
+ _errorhandler_nl = I2ErrOpen(progname, I2ErrLogImmediate,
+ &_immediateattr_nl, NULL, NULL);
+
+ if (!_errorhandler || !_errorhandler_nl) {
+ fprintf(stderr, "%s : Couldn't init error module\n",
progname);
+ exit(1);
+ }
+
+ _debuglevel = debuglvl;
}

/**
- * Function name: log_free
- * Description: Free malloc'ed memmory after child process ends. Allocation without
+ * Free malloc'ed memmory after child process ends. Allocation without
* a corresponding free() causes a memory leak, and the main process never ends so
* memory is not free'ed on a close.
- * Arguments: none
* Added RAC 10/13/09
*/
-
-void
-log_free(void)
-{
- free(_errorhandler);
- free(_errorhandler_nl);
+void log_free(void) {
+ free(_errorhandler);
+ free(_errorhandler_nl);
}

/**
@@ -183,10 +176,8 @@
* @param debuglvl new debug level to use
*/

-void
-set_debuglvl(int debuglvl)
-{
- _debuglevel = debuglvl;
+void set_debuglvl(int debuglvl) {
+ _debuglevel = debuglvl;
}

/**
@@ -194,10 +185,8 @@
* @param new log filename
*/

-void
-set_logfile(char* filename)
-{
- LogFileName = filename;
+void set_logfile(char* filename) {
+ LogFileName = filename;
}

/**
@@ -206,29 +195,23 @@
* @param filename The new protocol log filename
*
*/
-void
-set_protologdir(char* dirname)
-{
+void set_protologdir(char* dirname) {
char * localstr[256];

// Protocol log location being set
if (dirname == NULL) {
//use default of BASEDIR/LOGDIR
- // printf ("PV: 1: NULL proto location =%s;\n",
ProtocolLogDirName);
- log_println (0, "PV: 1: NULL proto location =%s;\n",
ProtocolLogDirName);
+ log_println(5, "PV: 1: NULL proto location =%s;\n",
ProtocolLogDirName);
return;
- }
- else if (dirname[0] != '/') {
+ } else if (dirname[0] != '/') {
sprintf(localstr, "%s/%s/", BASEDIR, dirname);
ProtocolLogDirName = localstr;
- //printf ("PV: 2: non-dir proto location. So=%s;\n", dirname);
- log_println (0, "PV: 2: non-dir proto location. So=%s;\n",
dirname);
+ log_println(5, "PV: 2: non-dir proto location. So=%s;\n",
dirname);
} //end protocol dir name
else {
sprintf(localstr, "%s", dirname);
ProtocolLogDirName = dirname;
- //printf ("PV3: proto location=%s;\n", ProtocolLogDirName);
- log_println (0, "PV33: proto location=%s;\n",
ProtocolLogDirName);
+ log_println(5, "PV33: proto location=%s;\n",
ProtocolLogDirName);
}

}
@@ -236,9 +219,9 @@
/**
* Get the directory where the protocol log will be placed
* @return directory where protocol logs are placed
-*/
+ */
char* get_protologdir() {
- printf ("PV34: proto location=%s;\n", ProtocolLogDirName);
+ printf("PV34: proto location=%s;\n", ProtocolLogDirName);
return ProtocolLogDirName;
}

@@ -247,51 +230,18 @@
* @param filename The new protocol log filename
*
*/
-
-void set_protologfile(char* client_ip, char* protologlocalarr){
- FILE *fp;
+void set_protologfile(char* client_ip, char* protologlocalarr) {
+ FILE * fp;

if (ProtocolLogDirName == NULL) {
ProtocolLogDirName = BASEDIR;
- //printf ("ProtoLogDir was empty when trying to create
protologFILE");
- }
- sprintf(protologlocalarr, "%s/%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX , client_ip,
- PROTOLOGSUFFIX,"\0");
- //strncpy(ProtocolLogFileName, protologlocalarr, strnlen(protologlocalarr));
- strlcpy(ProtocolLogFileName, protologlocalarr, sizeof(ProtocolLogFileName));
-
- //log_println (0, "***SET %s: %s;****\n", ProtocolLogFileName, ProtocolLogDirName);
-
- /* debug block
- fp = fopen(get_protologfile(),"a");
- if (fp == NULL) {
- printf("--Unable to trial open proto file ");
- log_println(0, "--Unable to trial open proto");
- }
- else {
- printf("--****** to trial open proto file ");
- log_println(0, "********trial open proto");
- fclose(fp);
- }
- */
-}
-
-/**
- * concatenate input parameters to form a protocol log file name that contains the client's
- * IP address.
- * @param client_ip client IP address
- * @param textappendarg local protocol store file
- * @return File name of protocol log file.
- * @todo: Can be deleted. unused currently. leaving for pre-release
- */
-char *createprotologfilename (char* client_ip, char* textappendarg) {
- char localprotofilename[256];
-
- log_println (0, "%s, %s %s;\n",protocollogfilestore, ProtocolLogFileName, ProtocolLogDirName);
- sprintf(localprotofilename, "%s/%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX , client_ip,
- PROTOLOGSUFFIX);
- textappendarg = localprotofilename;
- return textappendarg;
+ }
+ sprintf(protologlocalarr, "%s/%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX,
+ client_ip, PROTOLOGSUFFIX, "\0");
+
+ strlcpy(ProtocolLogFileName, protologlocalarr, sizeof(ProtocolLogFileName));
+ log_println(5, "Protocol filename: %s: %s\n", ProtocolLogFileName,
+ ProtocolLogDirName);
}

/**
@@ -300,10 +250,8 @@
*/

char*
-get_protologfile()
-{
- //log_println (0, "**ProtoLog = %s ", ProtocolLogFileName);
- return ProtocolLogFileName;
+get_protologfile() {
+ return ProtocolLogFileName;
}

/**
@@ -311,10 +259,8 @@
* @return current debug level
*/

-int
-get_debuglvl()
-{
- return _debuglevel;
+int get_debuglvl() {
+ return _debuglevel;
}

/**
@@ -323,9 +269,8 @@
*/

char*
-get_logfile()
-{
- return LogFileName;
+get_logfile() {
+ return LogFileName;
}

/**
@@ -334,10 +279,8 @@
* @return The error handle
*/

-I2ErrHandle
-get_errhandle()
-{
- return _errorhandler_nl;
+I2ErrHandle get_errhandle() {
+ return _errorhandler_nl;
}

/**
@@ -347,99 +290,139 @@
* ... - the additional arguments
*/

-void
-log_print(int lvl, const char* format, ...)
-{
- va_list ap;
-
- if (lvl > _debuglevel) {
- return;
- }
-
- va_start(ap, format);
- I2ErrLogVT(_errorhandler,-1,0,format,ap);
- va_end(ap);
+void log_print(int lvl, const char* format, ...)
+{
+ va_list ap;
+
+ if (lvl > _debuglevel) {
+ return;
+ }
+
+ va_start(ap, format);
+ I2ErrLogVT(_errorhandler,-1,0,format,ap);
+ va_end(ap);
}

/**
* Log the message with the given level. New line character
* is appended to the error stream.
- * @arg lvl level of the message
- * @arg format format of the message
+ * @param lvl level of the message
+ * @param format format of the message
* ... - the additional arguments
*/

-void
-log_println(int lvl, const char* format, ...)
-{
- va_list ap;
-
- if (lvl > _debuglevel) {
- return;
- }
-
- va_start(ap, format);
- I2ErrLogVT(_errorhandler_nl,-1,0,format,ap);
- va_end(ap);
+void log_println(int lvl, const char* format, ...)
+{
+ va_list ap;
+
+ if (lvl > _debuglevel) {
+ return;
+ }
+
+ va_start(ap, format);
+ I2ErrLogVT(_errorhandler_nl,-1,0,format,ap);
+ va_end(ap);
}

+/**
+ * Method to replace certain characters in received messages with ones that are quoted, so that
+ * the content is explicitly legible.
+ *
+ * @param line string containing characters to be replaced
+ * @param line_size length of the string to be replaced
+ * @param output_buf output buffer
+ * @param output_buf_size size of buffer to write output to
+ * @return number or characters written to the output buffer
+ * */
+
+int quote_delimiters(char *line, int line_size, char *output_buf,
+ int output_buf_size) {
+ static quoted[4][2] = { { '\n', 'n' }, { '"', '"' }, { '\0', '0' }, { '\\',
+ '\\' }, };
+ char quote_char = '\\';
+
+ int i, j, k;
+ int match;
+
+ for (i = j = 0; i < line_size && j < output_buf_size - 1; i++) {
+ // find any matching characters among the quoted
+ int match = 0;
+ for (k = 0; k < 4; k++) {
+ if (line[i] == quoted[k][0]) {
+ output_buf[j] = quote_char;
+ output_buf[j + 1] = quoted[k][1];
+ j += 2;
+ match = 1;
+ break;
+ }
+ }
+
+ if (match == 0) {
+ output_buf[j] = line[i];
+ j++;
+ }
+ }
+
+ output_buf[j] = '\0'; // make sure it's null-terminated
+ log_println(8, "****Received=%s; len=%d; dest=%d; MSG=%s", line, line_size,
+ output_buf_size, output_buf);
+
+ return j - 1;
+}
+

/**
* Log in a single key-value pair as a particular event
*
* In future, based on need, this may be expanded to log
* in a list of key-value pairs
- * @arg key string key
- * @arg value string value associated with this key
+ * @param key string key
+ * @param value string value associated with this key
*/
-void
-protolog_printgeneric(const char* key, const char* value)
-{
- FILE *fp;
+void protolog_printgeneric(const char* key, const char* value) {
+ FILE * fp;
char isotime[64];
- char *parsedvalue;
+
char logmessage[4096]; /* 4096 is just a random default buffer size for the protocol message
- Ideally, twice the
messsage size will suffice */
- //va_list ap;
-
- /*
- if (lvl > _debuglevel) {
- return;
- }
- */
+ Ideally, twice the messsage size will suffice */
+
if (!enableprotologging) {
- log_println(0, "Protocol logging is not enabled");
+ log_println(5, "Protocol logging is not enabled");
return;
}

// make delimiters in message payload explicit
quote_delimiters(value, strlen(value), logmessage,
sizeof(logmessage));

- fp = fopen(get_protologfile(),"a");
+ fp = fopen(get_protologfile(), "a");
if (fp == NULL) {
- printf("--Unable to open proto file while trying to record key-vale: %s:%s \n", key, value);
- log_println(0, "--Unable to open proto file while trying to record msg: %s \n", key, value);
- }
- else {
- fprintf(fp, " event=\"%s\", name=\"%s\", time=\"%s\"\n", key, value, get_ISOtime(isotime,sizeof(isotime)));
+ printf(
+ "--Unable to open proto file while trying to record key-vale: %s:%s \n",
+ key, value);
+ log_println(0,
+ "--Unable to open proto file while trying to
record msg: %s \n",
+ key, value);
+ } else {
+ fprintf(fp, " event=\"%s\", name=\"%s\", time=\"%s\"\n", key,
value,
+ get_ISOtime(isotime, sizeof(isotime)));
printf("%s = \"%s\" \n", key, logmessage);
fclose(fp);
}
}

/**
- * Logs a protocol message specifically indicating the start/end or other status of tests
+ * Logs a protocol message specifically indicating the start/end or other status of tests.
+ *
* @param lvl Level of the message
* @param testid enumerator indicating name of the test @see TEST_ID
* @param pid PID of process
* @param teststatus enumerator indicating test status. @see TEST_STATUS_INT
- * TODO: It may be good to define constants for event, pid etc. Use these instead.
+ *
*/
-void
-protolog_status(int pid, enum TEST_ID testid, enum TEST_STATUS_INT teststatus)
-{
- FILE *fp;
- va_list ap;
+void protolog_status(int pid, enum TEST_ID testid,
+ enum TEST_STATUS_INT teststatus) {
+ FILE * fp;
+ va_list ap;
char protomessage[256];
char currenttestarr[TEST_NAME_DESC_SIZE];
char currentstatusarr[TEST_STATUS_DESC_SIZE];
@@ -451,26 +434,27 @@
currenttestname = get_testnamedesc(testid, currenttestarr);
teststatusdesc = get_teststatusdesc(teststatus, currentstatusarr);

- /*
- if (lvl > _debuglevel) {
- return;
- }
- */
if (!enableprotologging) {
- log_println(0, "Protocol logging is not enabled");
+ log_println(5, "Protocol logging is not enabled");
return;
}

- fp = fopen(get_protologfile(),"a");
+ fp = fopen(get_protologfile(), "a");
if (fp == NULL) {
- printf("--Unable to open protocol log file while trying to record test status message: %s for the %s test \n",
+ printf(
+ "--Unable to open protocol log file while trying to record test status message: %s for the %s test \n",
teststatusdesc, currenttestname);
- log_println(0, "--Unable to open protocol log file while trying to record test status message: %s for the %s test \n",
+ log_println(
+ 0,
+ "--Unable to open protocol log file while trying to record test status message: %s for the %s test \n",
teststatusdesc, currenttestname);
- }
- else {
- sprintf(protomessage, " event=\"%s\", name=\"%s\", pid=\"%d\", time=\"%s\"\n",teststatusdesc, currenttestname, pid, get_ISOtime(isotime, sizeof(isotime)) );
- printf("%s: <-- %d - %s - %s --> \n ", protomessage, pid, teststatusdesc, currenttestname );
+ } else {
+ sprintf(protomessage,
+ " event=\"%s\", name=\"%s\", pid=\"%d\",
time=\"%s\"\n",
+ teststatusdesc, currenttestname, pid,
+ get_ISOtime(isotime, sizeof(isotime)));
+ printf("%s: <-- %d - %s - %s --> \n ", protomessage, pid,
+ teststatusdesc, currenttestname);
fprintf(fp, "%s", protomessage);
fclose(fp);
}
@@ -486,12 +470,9 @@
* @param teststatusarg enumerator indicating test status. @see TEST_STATUS_INT
*
*/
-void
-protolog_procstatus(int pid, enum TEST_ID testidarg,
- enum PROCESS_TYPE_INT procidarg,
- enum PROCESS_STATUS_INT teststatusarg)
-{
- FILE *fp;
+void protolog_procstatus(int pid, enum TEST_ID testidarg,
+ enum PROCESS_TYPE_INT procidarg, enum PROCESS_STATUS_INT
teststatusarg) {
+ FILE * fp;
char protomessage[256];
char isotime[64];
char currentprocarr[TEST_NAME_DESC_SIZE]; // size suffices to describe process name name too
@@ -508,21 +489,27 @@
procstatusdesc = get_procstatusdesc(teststatusarg, currentstatusarr);

if (!enableprotologging) {
- log_println(0, "Protocol logging is not enabled");
+ log_println(5, "Protocol logging is not enabled");
return;
}

- fp = fopen(get_protologfile(),"a");
+ fp = fopen(get_protologfile(), "a");
if (fp == NULL) {
- printf("--Unable to open protocol log file while trying to record process status message: %s for the %s test \n",
+ printf(
+ "--Unable to open protocol log file while trying to record process status message: %s for the %s test \n",
procstatusdesc, currentprocname);
- log_println(0, "--Unable to open protocol log file while trying to record process status message: %s for the %s test \n",
+ log_println(
+ 0,
+ "--Unable to open protocol log file while trying to record process status message: %s for the %s test \n",
procstatusdesc, currentprocname);
- }
- else {
- sprintf(protomessage, " event=\"%s\", name=\"%s\", test=\"%s\", pid=\"%d\", time=\"%s\"\n",procstatusdesc,
- currentprocname, currenttestname, pid, get_ISOtime(isotime, sizeof(isotime)) );
- printf("%s: -- %d - %s - %s - %s -- \n ", protomessage, pid,currenttestname, procstatusdesc, currentprocname );
+ } else {
+ sprintf(
+ protomessage,
+ " event=\"%s\", name=\"%s\", test=\"%s\", pid=\"%d\",
time=\"%s\"\n",
+ procstatusdesc, currentprocname,
currenttestname, pid,
+ get_ISOtime(isotime, sizeof(isotime)));
+ printf("%s: -- %d - %s - %s - %s -- \n ", protomessage, pid,
+ currenttestname, procstatusdesc,
currentprocname);
fprintf(fp, "%s", protomessage);
fclose(fp);
}
@@ -546,13 +533,10 @@
* @param processid PID of process
* @param ctlSocket socket over which message has been exchanged
* */
-
-//void protolog_println(int lvl, char *msgdirection,
-void protolog_println(char *msgdirection,
- const int type, void* msg, const int len, const int processid, const int ctlSocket)
-{
- FILE *fp;
- char currentdrcnarr[TEST_DIRN_DESC_SIZE];
+void protolog_println(char *msgdirection, const int type, void* msg,
+ const int len, const int processid, const int ctlSocket) {
+ FILE * fp;
+ //char currentdrcnarr[TEST_DIRN_DESC_SIZE];
char msgtypedescarr[MSG_TYPE_DESC_SIZE];
char *currenttestname, *currentmsgtype;
char isotime[64];
@@ -560,26 +544,28 @@

// get descriptive strings for test name and direction
currenttestname = get_currenttestdesc();
- currentmsgtype = get_msgtypedesc(type,msgtypedescarr);
+ currentmsgtype = get_msgtypedesc(type, msgtypedescarr);

// make delimiters in message payload explicit
quote_delimiters(msg, len, logmessage, sizeof(logmessage));

- fp = fopen(get_protologfile(),"a");
+ fp = fopen(get_protologfile(), "a");
if (fp == NULL) {
- //printf("--Unable to open proto, RCV");
- log_println(0, "Unable to open protocol log file '%s', continuing on without logging", get_protologfile());
- }
- else {
- /*fprintf(fp, " event=\"message\", direction=\"%s\", test=\"%s\", type=\"%s\", len=\"%d\", msg=\"%s\", pid=\"%d\", socket=\"%d\", time=\"%s\"\n",
- msgdirection, currenttestname, currentmsgtype, len, (char*)msg, processid, ctlSocket,get_ISOtime(isotime));
- printf("direction = %s, test= %s, type=%s, len=%d, msg=%s, pid=%d, socket=%d, time=%s\n",
- msgdirection, currenttestname, currentmsgtype, len, (char*)msg, processid, ctlSocket, get_ISOtime(isotime));
- */
- fprintf(fp, " event=\"message\", direction=\"%s\", test=\"%s\", type=\"%s\", len=\"%d\", msg=\"%s\", pid=\"%d\", socket=\"%d\", time=\"%s\"\n",
- msgdirection, currenttestname, currentmsgtype, len, logmessage, processid, ctlSocket,get_ISOtime(isotime,sizeof(isotime)));
- printf("direction = %s, test= %s, type=%s, len=%d, msg=%s, pid=%d, socket=%d, time=%s\n",
- msgdirection, currenttestname, currentmsgtype, len, logmessage, processid, ctlSocket, get_ISOtime(isotime,sizeof(isotime)));
+ log_println(
+ 5,
+ "Unable to open protocol log file '%s', continuing
on without logging",
+ get_protologfile());
+ } else {
+
+ fprintf(
+ fp,
+ " event=\"message\", direction=\"%s\", test=\"%s\", type=\"%s\", len=\"%d\", msg=\"%s\", pid=\"%d\", socket=\"%d\", time=\"%s\"\n",
+ msgdirection, currenttestname,
currentmsgtype, len, logmessage,
+ processid, ctlSocket, get_ISOtime(isotime,
sizeof(isotime)));
+ printf(
+ "direction = %s, test= %s, type=%s, len=%d, msg=%s, pid=%d, socket=%d, time=%s\n",
+ msgdirection, currenttestname,
currentmsgtype, len, logmessage,
+ processid, ctlSocket, get_ISOtime(isotime,
sizeof(isotime)));
fclose(fp);
}
}
@@ -594,15 +580,16 @@
* @param ctlSocket socket over which message has been exchanged
* */
//void protolog_sendprintln (int lvl, const int type, void* msg, const int len, const int processid, const int ctlSocket) {
-void protolog_sendprintln (const int type, void* msg, const int len, const int processid, const int ctlSocket) {
+void protolog_sendprintln(const int type, void* msg, const int len,
+ const int processid, const int ctlSocket) {
char *currentDir;

if (!enableprotologging) {
log_println(0, "Protocol logging is not enabled");
- return;
+ return;
}
currentDir = get_currentdirndesc();
- //protolog_println(lvl, currentDir, type, msg, len, processid,
ctlSocket);
+
protolog_println(currentDir, type, msg, len, processid, ctlSocket);
}

@@ -616,7 +603,8 @@
* @param processid PID of process
* @param ctlSocket socket over which message has been exchanged
* */
-void protolog_rcvprintln (const int type, void* msg, const int len, const int processid, const int ctlSocket){
+void protolog_rcvprintln(const int type, void* msg, const int len,
+ const int processid, const int ctlSocket) {
char *otherDir;
if (!enableprotologging) {
log_println(0, "Protocol logging is not enabled");
@@ -630,19 +618,17 @@
/**
* Set the timestamp to actual time.
*/
-void
-set_timestamp()
-{
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
- timestamp = tv.tv_sec;
- utimestamp = tv.tv_usec;
-
-/* Changed function to use gettimeofday() need usec value for ISO8601 file names
- * RAC 5/6/09
- * timestamp = time(NULL);
- */
+void set_timestamp() {
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ timestamp = tv.tv_sec;
+ utimestamp = tv.tv_usec;
+
+ /* Changed function to use gettimeofday() need usec value for ISO8601 file names
+ * RAC 5/6/09
+ * timestamp = time(NULL);
+ */

}

@@ -650,20 +636,16 @@
* Return the previously recorded timestamp.
* @return timestamp
*/
-time_t
-get_timestamp()
-{
- return timestamp;
+time_t get_timestamp() {
+ return timestamp;
}

/**
* Return the previously recorded utimestamp.
* @return The utimestamp
*/
-long int
-get_utimestamp()
-{
- return utimestamp;
+long int get_utimestamp() {
+ return utimestamp;
}

/**
@@ -672,20 +654,17 @@
* @param Pointer to the string indicating the year
*/

-void
- get_YYYY (char *year)
-{
-
-struct tm *result;
-time_t now;
-
-setenv("TZ", "UTC", 0);
-now = get_timestamp();
-result = gmtime(&now);
-
-sprintf(year, "%d", 1900+result->tm_year);
-}
-
+void get_YYYY(char *year) {
+
+ struct tm *result;
+ time_t now;
+
+ setenv("TZ", "UTC", 0);
+ now = get_timestamp();
+ result = gmtime(&now);
+
+ sprintf(year, "%d", 1900 + result->tm_year);
+}

/**
* Return a character string MM for the current year
@@ -693,22 +672,20 @@
* @param Pointer to the string indicating month
*/

-void
- get_MM (char *month)
-{
-
-struct tm *result;
-time_t now;
-
-/* setenv("TZ", NULL, 0); */
-setenv("TZ", "UTC", 0);
-now = get_timestamp();
-result = gmtime(&now);
-
-if (1+result->tm_mon < 10)
- sprintf(month, "0%d", 1+result->tm_mon);
-else
- sprintf(month, "%d", 1+result->tm_mon);
+void get_MM(char *month) {
+
+ struct tm *result;
+ time_t now;
+
+ /* setenv("TZ", NULL, 0); */
+ setenv("TZ", "UTC", 0);
+ now = get_timestamp();
+ result = gmtime(&now);
+
+ if (1 + result->tm_mon < 10)
+ sprintf(month, "0%d", 1 + result->tm_mon);
+ else
+ sprintf(month, "%d", 1 + result->tm_mon);
}

/**
@@ -717,21 +694,19 @@
* @param Pointer to the string indicating day
*/

-void
- get_DD (char *day)
-{
-
-struct tm *result;
-time_t now;
-
-setenv("TZ", "UTC", 0);
-now = get_timestamp();
-result = gmtime(&now);
-
-if (result->tm_mday < 10)
- sprintf(day, "0%d", result->tm_mday);
-else
- sprintf(day, "%d", result->tm_mday);
+void get_DD(char *day) {
+
+ struct tm *result;
+ time_t now;
+
+ setenv("TZ", "UTC", 0);
+ now = get_timestamp();
+ result = gmtime(&now);
+
+ if (result->tm_mday < 10)
+ sprintf(day, "0%d", result->tm_mday);
+ else
+ sprintf(day, "%d", result->tm_mday);
}

/** Return a character string in the ISO8601 time foramt
@@ -740,61 +715,59 @@
* Author: Rich Carlson - 5/6/09
* @param Pointer to the string indicating ISO time
* @param character string with ISO time string.
- * #param
*/

char *
- get_ISOtime (char *isoTime, int isotimearrsize)
-{
-
-struct tm *result;
-time_t now;
-char tmpstr[16];
-
-setenv("TZ", "UTC", 0);
-now = get_timestamp();
-result = gmtime(&now);
-
-sprintf(isoTime, "%d", 1900+result->tm_year);
-if (1+result->tm_mon < 10)
- sprintf(tmpstr, "0%d", 1+result->tm_mon);
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/logging.h Sun Oct 16 15:37:17
2011
+++ /branches/kkumar_code_organize/src/logging.h Mon Oct 17 06:31:32
2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the function declarations of the logging
* system.
*
=======================================
--- /branches/kkumar_code_organize/src/network.c Sun Oct 9 17:00:18
2011
+++ /branches/kkumar_code_organize/src/network.c Mon Oct 17 06:31:32
2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions needed to handle network related
* stuff.
*
@@ -14,15 +14,14 @@
#include "logging.h"

/**
- * Function name: OpenSocket
- * Description: Creates and binds the socket.
- * Arguments: addr - the I2Addr structure, where the new socket will be stored
- * serv - the port number
- * options - the binding socket options
- * Returns: The socket descriptor or error code (<0).
- * Error codes:
- * -1 : Unable to set socket address/port/file descriptor in address record "addr"
- * -2 : Unable to set socket options
+ * Create and bind socket.
+ * @param addr I2Addr structure, where the new socket will be stored
+ * @param serv the port number
+ * @param options the binding socket options
+ * @returns The socket descriptor or error code (<0).
+ * Error codes:
+ * -1 : Unable to set socket address/port/file descriptor in address record "addr"
+ * -2 : Unable to set socket options
*/

static int
@@ -55,10 +54,6 @@
// create socket with obtained address domain, socket type and protocol
fd = socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol);

-/*
- if (meta.family == 0)
- meta.family = ai->ai_family;
- */
// socket create failed. Abandon further activities using this socket
if (fd < 0) {
continue;
@@ -136,7 +131,7 @@
}

/**
- * Creates the I2Addr structure with the listen socket.
+ * Createsthe I2Addr structure with the listen socket.
* @param addr the I2Addr structure, where listen socket should
* be added, or NULL, if the new structure should be
* created
@@ -382,11 +377,7 @@
{
unsigned char buff[3];
int rc, i;
- FILE *fp; //kk
- //todo remove
- char tmpstr[256];
- I2Addr tmp_addr;
- //todo remove
+ FILE *fp;

assert(msg);
assert(len >= 0);
@@ -397,7 +388,6 @@
buff[1] = len >> 8;
buff[2] = len;

- //TODO could define a constant for 5, or leave it that way here
// retry sending data 5 times
for (i=0; i<5; i++) {
// Write initial data about length and type to socket
@@ -432,21 +422,6 @@

protolog_sendprintln(type, msg, len, getpid(),ctlSocket);

- //This section is used to get remote/local address on the fly, so that
- // both could be included in the name of the protocol log. todo
- /*
- tmp_addr = I2AddrByLocalSockFD(get_errhandle(), ctlSocket, 0);
- I2AddrNodeName(tmp_addr, tmpstr, 255);
- log_println(0, ">>> send_msg: from %s", tmpstr);
- // get addr details based on socket info available
- tmp_addr = I2AddrBySockFD(get_errhandle(), ctlSocket, 0);
-
- I2AddrNodeName(tmp_addr, tmpstr, 256);
- log_println(0, "to %s", tmpstr);
-
- *
- */
-
return 0;
}

@@ -470,18 +445,10 @@
{
unsigned char buff[3];
int length;
- FILE *fp; //kk
- //todo remove
- I2Addr tmp_addr;
- char tmpstr[256];
- // todo remove
-
- int itype = *type;
- int ilen = *len;
+ FILE *fp;
+
char *msgtemp = (char*)msg;

- //end
-
assert(type);
assert(msg);
assert(len);
@@ -508,34 +475,17 @@
}
log_println(8, "<<< recv_msg: type=%d, len=%d", *type, *len);

- // This section is used to get the local and remote addresses of the socket on the fly
- // to be used in the protocol log name
- /*
- tmp_addr = I2AddrBySockFD(get_errhandle(), ctlSocket, 0);
- I2AddrNodeName(tmp_addr, tmpstr, 256);
- log_println(0, "<<< recv_msg: from %s", tmpstr);
-
- // get addr details based on socket info available
- tmp_addr = I2AddrByLocalSockFD(get_errhandle(), ctlSocket, 0);
-
- I2AddrNodeName(tmp_addr, tmpstr, 256);
- log_println(0, "to %s", tmpstr);
-
- //end todo
- * */
-
protolog_rcvprintln(*type, msgtemp, *len, getpid(),ctlSocket);

return 0;
}

/**
- * Function name: writen
- * Description: Writes the given amount of data to the file descriptor.
- * Arguments: fd - the file descriptor
- * buf - buffer with data to write
- * amount - the size of the data
- * Returns: The amount of bytes written to the file descriptor
+ * Write the given amount of data to the file descriptor.
+ * @param fd the file descriptor
+ * @param buf buffer with data to write
+ * @param amount the size of the data
+ * @return The amount of bytes written to the file descriptor
*/

int
@@ -565,12 +515,11 @@
}

/**
- * Function name: readn
- * Description: Reads the given amount of data from the file descriptor.
- * Arguments: fd - the file descriptor
- * buf - buffer for data
- * amount - the size of the data to read
- * Returns: The amount of bytes read from the file descriptor.
+ * Read the given amount of data from the file descriptor.
+ * @param fd the file descriptor
+ * @param buf buffer for data
+ * @param amount size of the data to read
+ * @return The amount of bytes read from the file descriptor
*/

int
=======================================
--- /branches/kkumar_code_organize/src/network.h Mon Apr 6 12:39:53
2009
+++ /branches/kkumar_code_organize/src/network.h Mon Oct 17 06:31:32
2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the definitions and function declarations to
* handle network related stuff.
*
=======================================
--- /branches/kkumar_code_organize/src/protocol.c Tue Sep 13 07:04:10
2011
+++ /branches/kkumar_code_organize/src/protocol.c Mon Oct 17 06:31:32
2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions for the protocol handling.
*
* Jakub S³awiñski 2006-07-11
@@ -9,16 +9,15 @@
#include "logging.h"

/**
- * Function name: check_msg_type
- * Description: Checks if the received msg type is compatible
+ * Check if the received msg type is compatible
* with the expected one.
- * Arguments: prefix - the prefix printed before the error message
- * expected - the expected msg type
- * received - the received msg type
- * @param buff actual message received
- * len length of received message
- * Return: 0 - everything is ok
- * 1 - error code
+ * @param prefix the prefix printed before the error message
+ * @param expected the expected msg type
+ * @param received the received msg type
+ * @param buff actual message received
+ * @param len length of received message
+ * @return 0 if everything is ok, 1 otherwise
+ *
*/

int
=======================================
--- /branches/kkumar_code_organize/src/runningtest.c Sun Oct 9 17:00:18 2011
+++ /branches/kkumar_code_organize/src/runningtest.c Mon Oct 17 06:31:32 2011
@@ -8,11 +8,6 @@
#include "ndtptestconstants.h"
#include "runningtest.h"

-/**
- * Return the id of the currently running test.
- * @return integer id of the currently running test.
- */
-
static int currentTest = TEST_NONE;
static enum Tx_DIRECTION currentDirection = NONE;
static char *senddirnstr;
@@ -21,15 +16,10 @@
/**
* array defining possible events pertaining to process status
*/
-/*
-static char *_procstatusarray[] = { "unknown", "process_started",
- "process_ended" };
-*/
-
-
static char *_procstatusarray[] = { "unknown", "started",
"completed" };

+
/** array defining various "processes" like a web100srv process,
* or a client connection
*/
@@ -40,7 +30,6 @@
* Get ID of currently running test
* @return integer current running test Id
* */
-
int getCurrentTest() {
return currentTest;
}
@@ -61,9 +50,7 @@
return currentDirection;
}

-/** Set the id of the currently running test.
- * Then determine the string descriptions for
- * the test directions for the current process.
+/** Set the test directions for the current process.
* For example, for server process,
* the current-test-direction = S->C (send direction)
* , and the other/reverse
@@ -72,7 +59,7 @@
* that decides to have protocol logging.
* An example direction: client->server or vice
* versa.
- * @param testId Id of the currently running test
+ * @param directionarg direction of the currently running process
*/

void setCurrentDirn(enum Tx_DIRECTION directionarg) {
@@ -97,8 +84,9 @@
}
}

-/** Get a description of the currently running test
- * @returns descriptive name for the currently running test
+/**
+ * Get a description of the currently running test
+ * @return descriptive name for the currently running test
*/
char *get_currenttestdesc() {
enum TEST_ID currenttestId = NONE;
=======================================
--- /branches/kkumar_code_organize/src/test_meta_srv.c Sun Oct 9 17:00:18 2011
+++ /branches/kkumar_code_organize/src/test_meta_srv.c Mon Oct 17 06:31:32 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions needed to handle META
* test (server part).
*
@@ -25,7 +25,7 @@
* @param agent Web100 agent used to track the connection
* @param testOptions The test options
* @param conn_options The connection options
- * @returns 0 - success,
+ * @return 0 - success,
* >0 - error code.
* Error codes:
* -1 - Cannot write message header information while attempting to send
@@ -43,7 +43,7 @@
{
int j;
int msgLen, msgType;
- char buff[BUFFSIZE+1]; // TODO
+ char buff[BUFFSIZE+1];
struct metaentry *new_entry = NULL;
char* value;

@@ -57,7 +57,6 @@

// log protocol validation details
teststatuses = TEST_STARTED;
- //protolog_status(0,testOptions->child0, testids, teststatuses);
protolog_status(testOptions->child0, testids, teststatuses);

// first message exchanged is am empty TEST_PREPARE message
@@ -66,7 +65,6 @@
log_println(6, "META Error!, Test start message not sent!");
return j;
}
-

// Now, transmit an empty TEST_START message
if (send_msg(ctlsockfd, TEST_START, "", 0) < 0) {
@@ -150,7 +148,6 @@
log_println(1, " <-------------------------->");

teststatuses = TEST_ENDED; // protocol log section
- //protolog_status(0,testOptions->child0, testids, teststatuses);
protolog_status(testOptions->child0, testids, teststatuses);

setCurrentTest(TEST_NONE);
=======================================
--- /branches/kkumar_code_organize/src/test_s2c_clt.c Fri Oct 14 13:52:19 2011
+++ /branches/kkumar_code_organize/src/test_s2c_clt.c Mon Oct 17 06:31:32 2011
@@ -184,8 +184,8 @@
}
//strncat(tmpstr, buff, msgLen);
strlcat(tmpstr, buff, 512); //todo hardcoded size of array for now
- log_println(6, "tmpstr = '%s'", tmpstr);
- }
+ }
+ log_println(6, "tmpstr = '%s'", tmpstr);
log_println(1, " <------------------------->");
}

=======================================
--- /branches/kkumar_code_organize/src/test_sfw_srv.c Fri Oct 14 13:52:19 2011
+++ /branches/kkumar_code_organize/src/test_sfw_srv.c Mon Oct 17 06:31:32 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions needed to handle simple firewall
* test (server part).
*
@@ -105,7 +105,6 @@

// log
teststatusnow = TEST_ENDED;
- //protolog_status(1, getpid() , thistestId, teststatusnow); //todo will getpid() be correct?
protolog_status (getpid() , thistestId, teststatusnow);
log_println(1, " <-------------------------->");
// unset test name
@@ -160,7 +159,6 @@
log_println(1, " <-- %d - Simple firewall test -->", options->child0);
thistestId = SFW;
teststatusnow = TEST_STARTED;
- //protolog_status(1, options->child0, thistestId, teststatusnow);
protolog_status(options->child0, thistestId, teststatusnow);

// bind to a new port and obtain address structure with details of port etc
@@ -226,7 +224,6 @@
if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) { // message reception error
log_println(0, "Protocol error!");
sprintf(buff, "Server (Simple firewall test): Invalid port number received");
- //TODO above seems incorrect w.r.t the error message too
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
I2AddrFree(sfwsrv_addr);
return 1;
@@ -240,13 +237,14 @@
}
if (msgLen <= 0) { // message reception has error
log_println(0, "Improper message");
- // TODO: why are log messages and msg to client different? why is the only
- // status used all over here == Invalid port number?
sprintf(buff, "Server (Simple firewall test): Invalid port number received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
I2AddrFree(sfwsrv_addr);
return 3;
}
+ // Note: The same error message is transmitted to the client
+ // under any error condition, but the log messages indicate the difference
+

buff[msgLen] = 0;
if (check_int(buff, &sfwport)) { // message data is not number, thus no port info received
@@ -260,12 +258,11 @@
// Get node, port(if present) and other details of client end.
// If not able to resolve it, the test cannot proceed to the "throughput" stage
if ((sfwcli_addr = I2AddrByNode(get_errhandle(), hostname)) == NULL) {
- log_println(0, "Unable to resolve server address"); //todo is'nt this client address we cannot resolve?
+ log_println(0, "Unable to resolve server address"); //todo, this is the client address we cannot resolve?
send_msg(ctlsockfd, TEST_FINALIZE, "", 0);

// log end
teststatusnow = TEST_ENDED;
- //protolog_status(0,options->child0, thistestId, teststatusnow);
protolog_status(options->child0, thistestId, teststatusnow);
log_println(1, " <-------------------------->");
I2AddrFree(sfwsrv_addr);
@@ -339,8 +336,7 @@
I2AddrFree(sfwcli_addr);
return 1;
}
- if (msgLen != 20) { // Expecting default 20 byte long "Simple firewall test" message
- // todo define constants for 20 and default message string
+ if (msgLen != SFW_TEST_DEFAULT_LEN) { // Expecting default 20 byte long "Simple firewall test" message
log_println(0, "Simple firewall test: Improper message");
sprintf(buff, "%d", SFW_UNKNOWN);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
=======================================
--- /branches/kkumar_code_organize/src/testoptions.c Fri Oct 14 13:52:19 2011
+++ /branches/kkumar_code_organize/src/testoptions.c Mon Oct 17 06:31:32 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions needed to handle various tests.
*
* Jakub S�awi�ski 2006-06-24
@@ -23,8 +23,6 @@
int mon_pipe1[2]; // used to store file descriptors of pipes created for ndttrace for C2S tests
int mon_pipe2[2]; // used to store file descriptors of pipes created for ndttrace data in S2c test

-static const int RETRY_COUNT = 5;
-
// Snap log characteristics
typedef struct snapArgs {
web100_snapshot* snap; // web_100 snapshot indicator
@@ -362,10 +360,17 @@

/**
* Start packet tracing for this client
- * @param socketfd
- * @param socketfdarg
- * todo: change testindicatorarg to const instead pf str compare, in web100-pcap too
- *
+ * @param socketfdarg socket file descriptor to initialize packet trace from
+ * @param socketfdarg socket file descriptor to close
+ * @param childpid pid resulting from fork()
+ * @param imonarg int array of socket fd from pipe
+ * @param cliaddrarg sock_addr used to determine client IP
+ * @param clilenarg socket length
+ * @param device device type
+ * @param pairarg portpair struct instance
+ * @param testindicator string indicating C2S/S2c test
+ * @param iscompressionenabled is compression enabled (for log files)?
+ * @param copylocationarg memory location to copy resulting string (from packet trace) into
* */

void start_packet_trace (int socketfdarg, int socketfdarg2, pid_t *childpid, int *imonarg,
@@ -400,10 +405,10 @@
// name of nettrace file passed back from pcap child copied into meta structure
if (strlen(tmpstr) > 5) {
memcpy(copylocationarg, tmpstr, strlen(tmpstr));
- log_println(0, "**memcopied dir name %s", tmpstr );
+ log_println(8, "**start pkt trace, memcopied dir name %s", tmpstr );
}

- //free this address now. Lets see if this works alright
+ // free this address now.
I2AddrFree(src_addr);

}
@@ -708,7 +713,7 @@

// message payload from client == midbox S->c throughput
buff[msgLen] = 0;
- *s2c_throughput_mid = atof(buff); //todo s2c_throughput_mid could be named better
+ *s2c_throughput_mid = atof(buff);
log_println(4, "CWND limited throughput = %0.0f kbps (%s)", *s2c_throughput_mid, buff);

// finalize the midbox test ; disabling socket used for throughput test and closing out both sockets
@@ -776,14 +781,13 @@
int set_buff, int window, int autotune, char* device, Options* options,
int record_reverse, int count_vars, char spds[4][256], int* spd_index)
{
- /* int largewin=16*1024*1024; */
int recvsfd; // receiver
socket file descriptor
pid_t c2s_childpid = 0; // child process pids
int msgretvalue, tmpbytecount; // used during the "read"/"write"
process
int i, j; // used as
loop iterators
- /* int seg_size, win_size; */
+
struct sockaddr_storage cli_addr;
- /* socklen_t optlen, clilen; */
+
socklen_t clilen;
char tmpstr[256]; // string array used for all sorts of temp storage purposes
double tmptime; // time indicator
@@ -797,16 +801,6 @@
char listenc2sport[10]; // listening port
pthread_t workerThreadId;

- // comment out unused variables
- //FILE *fp;
- //DIR *dp;
- //char isoTime[64];
- //char dir[128];
-
- // server address stores
- //size_t nameBufLen = 255;
- //char namebuf[256];
-
// web_100 related variables
web100_group* group;
web100_connection* conn;
@@ -829,13 +823,10 @@
if (testOptions->c2sopt) {
setCurrentTest(TEST_C2S);
log_println(1, " <-- %d - C2S throughput test -->", testOptions->child0);
- //strcpy(listenc2sport, PORT2);
strlcpy(listenc2sport, PORT2, sizeof(listenc2sport));

-
//log protocol validation logs
teststatuses = TEST_STARTED;
- //protolog_status(0,testOptions->child0, testids, teststatuses);
protolog_status(testOptions->child0, testids, teststatuses);

// Determine port to be used. Compute based on options set earlier
@@ -848,7 +839,6 @@
}

if (testOptions->multiple) {
- //strcpy(listenc2sport, "0");
strlcpy(listenc2sport, "0", sizeof(listenc2sport));
}

@@ -952,7 +942,7 @@
log_println(0, "C2S test calling pkt_trace_start() with pd=%d", clilen);
start_packet_trace (recvsfd, testOptions->c2ssockfd, &c2s_childpid, mon_pipe1,
(struct sockaddr *) &cli_addr, clilen, device, &pair, "c2s", options->compress, meta.c2s_ndttrace) ;
- log_println(0, "--tracefile after packet_trace %s", meta.c2s_ndttrace); //todo change level
+ log_println(3, "--tracefile after packet_trace %s", meta.c2s_ndttrace);
}


@@ -963,20 +953,10 @@

// Create C->S snaplog directories, and perform some initialization based on options

- /*
- I2Addr sockAddr = I2AddrBySAddr(get_errhandle(), (struct sockaddr *) &cli_addr, clilen, 0, 0);
- memset(namebuf, 0, 256);
- I2AddrNodeName(sockAddr, namebuf, &nameBufLen);
- //createDir(namebuf, I2AddrPort(sockAddr),options->c2s_logname, namesuffix);
- *
- */
+
create_client_logdir((struct sockaddr *) &cli_addr, clilen,
options->c2s_logname, sizeof(options->c2s_logname), namesuffix, sizeof(namesuffix));

- //group = web100_group_find(agent, "read");
- //snapArgs.snap = web100_snapshot_alloc(group, conn);
-
- //I2AddrFree(sockAddr);

sleep(2);

@@ -1038,7 +1018,7 @@
// get receiver side Web100 stats and write them to the log file. close sockets
if (record_reverse == 1)
web100_get_data_recv(recvsfd, agent, conn, count_vars);
- /* shutdown(recvsfd, SHUT_RD); */
+
close(recvsfd);
close(testOptions->c2ssockfd);

@@ -1080,13 +1060,7 @@
sel_tv.tv_usec = 100000;
continue;
}
- /* if ((ret = read(mon_pipe1[0], spds[*spd_index], 128)) < 0)
- * sprintf(spds[*spd_index], " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
- * log_println(1, "%d bytes read '%s' from C2S monitor pipe", ret, spds[*spd_index]);
- * (*spd_index)++;
- * break;
- * }
- */
+
}
}

@@ -1105,12 +1079,9 @@
//protolog_status(0,testOptions->child0, testids, teststatuses);
protolog_status(testOptions->child0, testids, teststatuses);

-
//set current test status and free address
setCurrentTest(TEST_NONE);
- /* I2AddrFree(c2ssrv_addr); */
- //I2AddrFree(src_addr); //commenting out now
- /* testOptions->child1 = c2s_childpid; */
+
}

return 0;
@@ -1140,7 +1111,7 @@
* @param autotune autotuning option. Deprecated.
* @param device string devine name inout parameter
* @param options Test Option variables
- * @param spds[] [] speed check array
+ * @param spds[][] speed check array
* @param spd_index index used for speed check array
* @param count_vars count of web100 variables
* @param peaks Cwnd peaks structure pointer
@@ -1164,15 +1135,15 @@
int set_buff, int window, int autotune, char* device, Options* options, char spds[4][256],
int* spd_index, int count_vars, CwndPeaks* peaks)
{
- /* int largewin=16*1024*1024; */
+
int ret; // ctrl
protocol read/write return status
int j, k, n;
int xmitsfd; // transmit (i.e
server) socket fd
pid_t s2c_childpid = 0; // s2c_childpid
- /* int seg_size, win_size; */
+
char tmpstr[256]; // string array used
for temp storage of many char*
struct sockaddr_storage cli_addr;
- /* socklen_t optlen, clilen; */
+
socklen_t clilen;
double bytes_written; // bytes written in
the throughput test
double tx_duration; // total time for which data
was txed
@@ -1190,13 +1161,6 @@
int msgLen;
int sndqueue;
struct sigaction new, old;
- //char namebuf[256];
- //dir[126];
- //char isoTime[64];
- //size_t nameBufLen = 255;
- //DIR *dp;
- //FILE *fp;
- //I2Addr src_addr=NULL;

/* experimental code to capture and log multiple copies of the
* web100 variables using the web100_snap() & log() functions.
@@ -1233,10 +1197,9 @@

//protocol logs
teststatuses = TEST_STARTED;
- //protolog_status(0,testOptions->child0, testids, teststatuses);
protolog_status(testOptions->child0, testids, teststatuses);

- //strcpy(listens2cport, PORT4);
+
strlcpy(listens2cport, PORT4, sizeof(listens2cport));

if (testOptions->s2csockport) {
@@ -1247,7 +1210,6 @@
}

if (testOptions->multiple) {
- //strcpy(listens2cport, "0");
strlcpy(listens2cport, "0",sizeof(listens2cport));
}

@@ -1325,7 +1287,6 @@
xmitsfd = accept(testOptions->s2csockfd, (struct sockaddr *) &cli_addr, &clilen);
if (xmitsfd > 0) {
log_println(6, "accept() for %d completed", testOptions->child0);
- //protocol logging
procstatusenum = PROCESS_STARTED;
proctypeenum = CONNECT_TYPE;
protolog_procstatus(testOptions->child0, testids, proctypeenum, procstatusenum);
@@ -1524,13 +1485,6 @@
sel_tv.tv_usec = 100000;
continue;
}
- /* if ((ret = read(mon_pipe2[0], spds[*spd_index], 128)) < 0)
- * sprintf(spds[*spd_index], " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
- * log_println(1, "%d bytes read '%s' from S2C monitor pipe", ret, spds[*spd_index]);
- * (*spd_index)++;
- * break;
- * }
- */
}
}

@@ -1589,13 +1543,10 @@
log_println(1, " <------------ %d ------------->", testOptions->child0);
//log protocol validation logs
teststatuses = TEST_ENDED;
- //protolog_status(1,testOptions->child0, testids, teststatuses);
protolog_status(testOptions->child0, testids, teststatuses);

setCurrentTest(TEST_NONE);
- /* I2AddrFree(s2csrv_addr); */
- // I2AddrFree(src_addr); //commented for packettrace. moved into function
- /* testOptions->child2 = mon_pid2; */
+
}
return 0;
}
=======================================
--- /branches/kkumar_code_organize/src/usage.c Sun Oct 9 17:00:18 2011
+++ /branches/kkumar_code_organize/src/usage.c Mon Oct 17 06:31:32 2011
@@ -60,7 +60,7 @@
printf(" -f, --file variable_FN - specify alternate 'web100_variables' file\n");
printf(" -i, --interface device - specify network interface (libpcap device)\n");
printf(" -l, --log Log_FN - specify alternate 'web100srv.log' file\n");
- printf(" -u, --protolog_dir protolog_DIR - specify the base directory for protocol validation logs \n");
+ printf(" -u, --protolog_dir DIR - specify the base directory for protocol validation logs \n");
printf(" --enableprotolog - enable protocol logging \n");
printf(" -p, --port #port - specify primary port number (default 3001)\n");
printf(" --midport #port - specify Middlebox test port number (default 3003)\n");
=======================================
--- /branches/kkumar_code_organize/src/utils.c Fri Oct 14 13:52:19 2011
+++ /branches/kkumar_code_organize/src/utils.c Mon Oct 17 06:31:32 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains functions needed to handle numbers sanity checks
* and some other utility things.
*
@@ -23,14 +23,13 @@
#include "utils.h"
#include "strlutils.h"

-/*
- * Function name: check_int
- * Description: Checks if the string is a valid int number.
- * Arguments: text - the string representing number
- * number - the pointer where decoded number will be stored
- * Returns: 0 - success,
- * 1 - value from outside the int number range,
- * 2 - not the valid int number.
+/**
+ * Check if the string is a valid int number.
+ * @param text the string representing number
+ * @param number the pointer where decoded number will be stored
+ * @return 0 on success,
+ * 1 - value from outside the int number range,
+ * 2 - not the valid int number.
*/

int
@@ -54,15 +53,14 @@
}
}

-/*
- * Function name: check_rint
- * Description: Checks if the string is a valid int number from the specified
+/**
+ * Check if the string is a valid int number from the specified
* range.
- * Arguments: text - the string representing number
- * number - the pointer where decoded number will be stored
- * minVal - the minimal value restriction (inclusive)
- * maxVal - the maximum value restriction (inclusive)
- * Returns: 0 - success,
+ * @param text string representing number
+ * @param number pointer where decoded number will be stored
+ * @param minVal the minimal value restriction (inclusive)
+ * @param maxVal the maximum value restriction (inclusive)
+ * @return 0 - success,
* 1 - value from outside the specified range,
* 2 - not the valid int number.
*/
@@ -83,12 +81,11 @@
return 0;
}

-/*
- * Function name: check_long
- * Description: Checks if the string is a valid long number.
- * Arguments: text - the string representing number
- * number - the pointer where decoded number will be stored
- * Returns: 0 - success,
+/**
+ * Check if the string is a valid long number.
+ * @param text the string representing number
+ * @param number the pointer where decoded number will be stored
+ * @return 0 - success,
* 1 - value from outside the long number range,
* 2 - not the valid long number.
*/
@@ -112,10 +109,9 @@
}
}

-/*
- * Function name: secs
- * Description: Returns the seconds from the beginning of the epoch.
- * Returns: The seconds from the beginning of the epoch.
+/**
+ * Return the seconds from the beginning of the epoch.
+ * @return seconds from the beginning of the epoch.
*/

double
@@ -126,10 +122,9 @@
return(ru.tv_sec + ((double)ru.tv_usec)/1000000);
}

-/*
- * Function name: err_sys
- * Description: Prints the perror and exits.
- * Arguments: s - the argument to the perror() function
+/**
+ * Print the perror and exit.
+ * @param s the argument to the perror() function
*/

void
@@ -139,12 +134,11 @@
return -1;
}

-/*
- * Function name: sndq_len
- * Description: Returns the length of the sending queue of the given
+/**
+ * Return the length of the sending queue of the given
* file descriptor.
- * Arguments: fd - file descriptor to check
- * Returns: The length of the sending queue.
+ * @param fd file descriptor to check
+ * @return length of the sending queue.
*/

int
@@ -183,30 +177,3 @@
return;
}
}
-
-/**
- * Replace part of string by another string
- * @param strinput Input string that contains pasrt of string
- * needing to be replaced
- * @param orig original string to be replaced
- * @param repl Replacement string
- * @param arrsize Size of array
- * @todo This function will have changed in the todo areas listed below
- * */
-/*
-char *replaceStr(char *strinput, char *orig, char *repl, int arrsize) {
- char buffer[arrsize]; //todo size
- char *ch;
- memcpy(buffer, strinput, strlen(strinput));
- printf("0.%s,%s,\n",buffer, strinput);
- while ((ch = strstr(strinput, orig))) {
- strncpy (buffer, strinput, ch-strinput);
- buffer [ch-strinput] = 0;
- sprintf(buffer+(ch-strinput), "%s%s", repl, ch+strlen(orig));
- strinput = buffer;
- printf ("1=%s,%s\n", buffer, ch);
- }
- printf ("2=%s,%s\n", buffer, ch);
- return buffer;
-}
-*/
=======================================
--- /branches/kkumar_code_organize/src/utils.h Sun Oct 16 15:37:17 2011
+++ /branches/kkumar_code_organize/src/utils.h Mon Oct 17 06:31:32 2011
@@ -56,7 +56,16 @@
#define NO_BAD_CABLE 0
#define POSSIBLE_BAD_CABLE 1

+// SFW Test default message length
+#define SFW_TEST_DEFAULT_LEN 20

// generic system wide retry counts
#define RETRY_COUNT 5

+// middlebox test default MSS
+#define MIDDLEBOX_PREDEFINED_MSS 8192
+
+// MAX TCP window size in bytes
+#define MAX_TCP_WIN_BYTES 64
+
+
=======================================
--- /branches/kkumar_code_organize/src/web100-admin.c Fri Oct 14 13:52:19 2011
+++ /branches/kkumar_code_organize/src/web100-admin.c Mon Oct 17 06:31:32 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions needed to handle the Admin
* page. This page allows a remote user to view the usage statistics
* via a web page.
=======================================
--- /branches/kkumar_code_organize/src/web100-pcap.c Sun Oct 16 15:37:17 2011
+++ /branches/kkumar_code_organize/src/web100-pcap.c Mon Oct 17 06:31:32 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the libpcap routines needed by the web100srv
* program. The global headers and variables are defined in the
* web100srv.h file. This should make it easier to maintain the
=======================================
--- /branches/kkumar_code_organize/src/web100-util.c Fri Oct 14 13:52:19 2011
+++ /branches/kkumar_code_organize/src/web100-util.c Mon Oct 17 06:31:32 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions needed to read the web100
* variables. It links into the main web100srv program.
*
@@ -22,11 +22,7 @@
* beginning
* @param *VarFileName pointer to file name of Web100 variables
* @return integer indicating number of web100 variables read
- * , or indicating failure of initialization
- * Error codes:
- * 5 : Unable to open web100 variable file
- * -1: TODO :When is -1 returned? Calling code seems to rely on -1?
- *
+ * or indicating failure of initialization
*/
int
web100_init(char *VarFileName)
@@ -67,7 +63,6 @@
* These are written using a buffer of the size of the current MSS or
* 8192 bytes.
*
- * @TODO Why is this method in web100-util.c?
* @param sock integer socket file descriptor
* @param agent pointer to a web100_agent
* @param cn pointer to the web100_connection
@@ -125,8 +120,7 @@
// terminate the IP address string
meta.server_ip[(strlen(line)-1)] = 0;
// Add this address to results
- //strncat(results, line, strlen(line));
- strlcat(results, line, (BUFFSIZE+1)); //todo : later: using a "known" hardcoded value for size of results
+ strlcat(results, line, (BUFFSIZE+1)); // using a "known" hardcoded value for size of results
I2AddrFree(addr); // free memory

// Now perform the above set of functions for client address/service name
@@ -138,8 +132,7 @@
sprintf(line, "%s;", tmpstr);
I2AddrServName(addr, tmpstr, &tmpstrlen);
log_print(3, "Client: %s%s ", line, tmpstr);
- //strncat(results, line, strlen(line));
- strlcat(results, line, (BUFFSIZE+1)); //todo :later: using a "known" hardcoded value for size of results
+ strlcat(results, line, (BUFFSIZE+1));
I2AddrFree(addr);

// get web100 values for the middlebox test result group
@@ -154,9 +147,9 @@
if (strcmp(vars[i], "CurMSS") == 0)
currentMSSval = atoi(web100_value_to_text(web100_get_var_type(var), buff));
sprintf(line, "%s;", web100_value_to_text(web100_get_var_type(var), buff));
- if (strcmp(line, "4294967295;") == 0) // TODO what is this number?
+ if (strcmp(line, "4294967295;") == 0)
sprintf(line, "%d;", -1);
- //strcat(results, line);
+
strlcat(results, line, sizeof(results));
log_print(3, "%s", line);
}
@@ -180,10 +173,10 @@

// try to allocate memory of the size of current MSS Value
sndbuff = malloc(currentMSSval);
- if (sndbuff == NULL) { // not possible, use 8192 bytes
+ if (sndbuff == NULL) { // not possible, use MIDDLEBOX_PREDEFINED_MSS bytes
log_println(0, "Failed to allocate memory --> switching to 8192 Byte packets");
sndbuff = buff;
- currentMSSval = 8192; //todo define constant
+ currentMSSval = MIDDLEBOX_PREDEFINED_MSS;
}
if (getuid() == 0) {
system("echo 1 > /proc/sys/net/ipv4/route/flush");
@@ -198,13 +191,12 @@
sndbuff[j] = (k++ & 0x7f);
}

- // search web100 group with name "read"?
+ // get web100 group with name "read"
group = web100_group_find(agent, "read");
snap = web100_snapshot_alloc(group, cn);

FD_ZERO(&wfd);
FD_SET(sock, &wfd);
- // TODO: define constants for 5 seconds, 0 ms
sel_tv.tv_sec = 5; // 5 seconds maximum for select call below to complete
sel_tv.tv_usec = 0; // 5s + 0ms
while ((ret = select(sock+1, NULL, &wfd, NULL, &sel_tv)) > 0) {
@@ -255,7 +247,7 @@
{
int i, ok;
web100_var* var;
- char buf[32], line[256], *ctime(); // todo: define constants for 32, 256
+ char buf[32], line[256], *ctime();
web100_group* group;
FILE *fp;
time_t tt;
@@ -501,7 +493,7 @@
web100_setbuff(int sock, web100_agent* agent, web100_connection* cn, int autotune)
{
web100_var* var;
- char buf[32]; // todo defined constants for 32
+ char buf[32];
web100_group* group;
int buff;
int sScale, rScale;
@@ -530,7 +522,7 @@
rScale = 0;

if ((sScale > 0) && (rScale > 0)) {
- buff = (64 * 1024) << sScale; // todo define constants for 64k( max TCP rcv window)
+ buff = (MAX_TCP_WIN_BYTES * KILO_BITS) << sScale; // 64k( max TCP rcv window)
if (autotune & 0x01) { // autotune send buffer is not enabled
if ((web100_agent_find_var_and_group(agent, "LimCwnd", &group, &var)) != WEB100_ERR_SUCCESS)
return(22);
@@ -540,7 +532,7 @@
return(23);
}
}
- buff = (64 * 1024) << rScale;
+ buff = (MAX_TCP_WIN_BYTES * KILO_BITS) << rScale;


if (autotune & 0x02) { // autotune receive buffer is not enabled
@@ -560,8 +552,8 @@
/**
* @param sock integer socket file descriptor indicating data recipient
* @param pointers to local copies of web100 variables
-* @return Integer 0
-* @TODO this method can be altered to return void
+* @return integer 0
+*
*
*/
int
=======================================
--- /branches/kkumar_code_organize/src/web100srv.c Sun Oct 16 15:37:17
2011
+++ /branches/kkumar_code_organize/src/web100srv.c Mon Oct 17 06:31:32
2011
@@ -122,7 +122,7 @@
int cputime = 0;
char cputimelog[256];
pthread_t workerThreadId, zombieThreadId;
-int workerLoop=1, zombie_check=0;
+int cputimeworkerLoop=1, zombie_check=0;

int useDB = 0;
char* dbDSN = NULL;
@@ -213,11 +213,10 @@
void
child_sig(pid_t chld_pid)
{
- int pid, status, rc;
- /* int i=0, j=0; */
- struct ndtchild *tmp1, *tmp2;
-
- tmp1 = head_ptr;
+ int pid, status, retcode;
+ struct ndtchild *child_proc1, *child_proc2;
+
+ child_proc1 = head_ptr;
log_println(2, "Processing SIGCHLD signal for active web100srv process [%d], sig17=%d", chld_pid, sig17);

/* this routine cleans up after a child process has terminated. There are 2 types of
@@ -297,17 +296,17 @@
if (head_ptr == NULL)
return;
log_println(5, "checking for pktpair timing children, skip them");
- tmp1 = head_ptr;
- while (tmp1 != NULL) {
- log_println(5, "\tLooking for %d, curent queue Child %d, host: %s [%s], next=0x%x", pid, tmp1->pid,
- tmp1->host, tmp1->addr, (u_int64_t) tmp1->next);
- if (tmp1->pid == pid) {
+ child_proc1 = head_ptr;
+ while (child_proc1 != NULL) {
+ log_println(5, "\tLooking for %d, curent queue Child %d, host: %s [%s], next=0x%x", pid, child_proc1->pid,
+ child_proc1->host, child_proc1->addr, (u_int64_t) child_proc1->next);
+ if (child_proc1->pid == pid) {
log_println(4, "Main test process %d terminated, remove from queue", pid);
break;
}
- tmp1 = tmp1->next;
- }
- if (tmp1 == NULL)
+ child_proc1 = child_proc1->next;
+ }
+ if (child_proc1 == NULL)
return;

reap_child:
@@ -322,27 +321,27 @@

if (get_debuglvl() > 5) {
log_println(5, "Walkingqueue");
- tmp1 = head_ptr;
- while (tmp1 != NULL) {
- log_println(5, "\tChild %d, host: %s [%s], next=0x%x", tmp1->pid,
- tmp1->host, tmp1->addr, (u_int64_t) tmp1->next);
- if (tmp1->next == NULL)
+ child_proc1 = head_ptr;
+ while (child_proc1 != NULL) {
+ log_println(5, "\tChild %d, host: %s [%s], next=0x%x", child_proc1->pid,
+ child_proc1->host, child_proc1->addr, (u_int64_t) child_proc1->next);
+ if (child_proc1->next == NULL)
break;
- tmp1 = tmp1->next;
+ child_proc1 = child_proc1->next;
}
}

- while ((rc = sem_wait(&ndtq)) == -1 && errno == EINTR) {
+ while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
log_println(6, "Waiting for ndtq semaphore to free - 1");
continue;
}
log_println(5, "Child process %d causing head pointer modification, semaphore locked", pid);
if (head_ptr != NULL) {
- tmp1 = head_ptr;
- log_println(6, "modifying queue tmp1=0x%x, head_ptr=0x%x", tmp1, head_ptr);
+ child_proc1 = head_ptr;
+ log_println(6, "modifying queue child_proc1=0x%x, head_ptr=0x%x", child_proc1, head_ptr);
head_ptr = head_ptr->next;
- log_println(6, "free tmp1=0x%x", tmp1);
- free(tmp1);
+ log_println(6, "free child_proc1=0x%x", child_proc1);
+ free(child_proc1);
}
if (head_ptr == NULL)
testing = 0;
@@ -357,18 +356,18 @@
return;
}
else {
- tmp1 = head_ptr;
- while (tmp1->next != NULL) {
- if (tmp1->next->pid == pid) {
- while ((rc = sem_wait(&ndtq)) == -1 && errno == EINTR) {
+ child_proc1 = head_ptr;
+ while (child_proc1->next != NULL) {
+ if (child_proc1->next->pid == pid) {
+ while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
log_println(6, "Waiting for ndtq semaphore to free - 2");
continue;
}
log_println(4, "Child process %d causing task list modification, semaphore locked", chld_pid);
- tmp2 = tmp1->next;
- tmp1->next = tmp2->next;
- log_println(6, "free tmp2=0x%x", tmp2);
- free(tmp2);
+ child_proc2 = child_proc1->next;
+ child_proc1->next = child_proc2->next;
+ log_println(6, "free child_proc2=0x%x", child_proc2);
+ free(child_proc2);
/* testing = 0; */
waiting--;
log_println(3, "Removing Child from list, decremented waiting/mclients %d/%d", waiting, mclients);
@@ -378,8 +377,8 @@
sig17--;
return;
}
- tmp1 = tmp1->next;
- log_println(6, "Looping through service queue ptr = 0x%x", (u_int64_t) tmp1);
+ child_proc1 = child_proc1->next;
+ log_println(6, "Looping through service queue ptr = 0x%x", (u_int64_t) child_proc1);
}
}
if (sig17 > 0)
@@ -547,7 +546,7 @@
FILE *conf;
char keybuf[256], valbuf[256];
char *key=keybuf, *val=valbuf;
- int rc=0;
+ int retcode=0;


if (!(conf = fopen(ConfigFileName, "r")))
@@ -556,7 +555,7 @@
log_println(1, " Reading config file %s to obtain options", ConfigFileName);

// Read the values for various keys and store them in appropriate variables
- while ((rc = I2ReadConfVar(conf, rc, key, val, 256, lbuf, lbuf_max)) > 0) {
+ while ((retcode = I2ReadConfVar(conf, retcode, key, val, 256, lbuf, lbuf_max)) > 0) {
if (strncasecmp(key, "administrator_view", 5) == 0) {
admin_view = 1;
continue;
@@ -757,8 +756,8 @@
exit(1);
}
}
- if (rc < 0) {
- log_println(0, "Syntax error in line %d of the config file %s", (-rc), ConfigFileName);
+ if (retcode < 0) {
+ log_println(0, "Syntax error in line %d of the config file %s", (-retcode), ConfigFileName);
exit(1);
}
fclose(conf);
@@ -775,7 +774,7 @@
zombieWorker(void *head_ptr) {

struct ndtchild *tmp_ptr, *tmp, *pre_ptr=NULL;
- int i=0, rc;
+ int i=0, retcode;
struct timeval sel_tv;
fd_set rfd;
char tmpstr[8], buff[32];
@@ -805,19 +804,19 @@
log_println(6, "New client found, checking for response, child=%d", tmp_ptr->pid);

// send "keep-alive" SRV_QUEUE message to client and expect a response
- rc = send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr));
- log_println(6, "send_msg() returned %d during zombie check on client %d", rc, tmp_ptr->pid);
+ retcode = send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr,
strlen(tmpstr));
+ log_println(6, "send_msg() returned %d during zombie check on client %d", retcode, tmp_ptr->pid);
FD_ZERO(&rfd);
FD_SET(tmp_ptr->ctlsockfd, &rfd);
sel_tv.tv_sec = 1;
sel_tv.tv_usec = 500000;
for (;;) {
- rc = select((tmp_ptr->ctlsockfd)+1, &rfd, NULL, NULL, &sel_tv);
- switch (rc) {
+ retcode = select((tmp_ptr->ctlsockfd)+1, &rfd, NULL, NULL, &sel_tv);
+ switch (retcode) {
case 0:
// a timeout occurred, remove zombie client from list
log_println(6, "New client didn't respond - must be a zombie, get rid of it, child=%d", tmp_ptr->pid);
- while ((rc = sem_wait(&ndtq)) == -1 && errno == EINTR) {
+ while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
log_println(6, "Waiting for ndtq semaphore to free - adding new client 1");
continue;
}
@@ -832,7 +831,7 @@
log_println(6, "Free'd semaphore lock - 4");
break;
default:
- log_println(6, "%d new client(s) responded, bumping pointers child=%d", rc, tmp_ptr->pid);
+ log_println(6, "%d new client(s) responded, bumping pointers child=%d", retcode, tmp_ptr->pid);
recv_msg(tmp_ptr->ctlsockfd, &msgType, buff, &msgLen);
tmp_ptr = tmp_ptr->next;
pre_ptr = pre_ptr->next;
@@ -874,7 +873,7 @@
return NULL;

while (1) {
- if (!workerLoop) {
+ if (!cputimeworkerLoop) {
break;
}
times(&buf);
@@ -1391,7 +1390,7 @@
main(int argc, char** argv)
{
pid_t chld_pid;
- int rc;
+ int retcode;
int tpid, mwaiting = 0;
int ctlsockfd = -1;
int c, chld_pipe[2];
@@ -1413,7 +1412,7 @@
I2Addr listenaddr = NULL;
int listenfd;
char* srcname = NULL;
- char isoTime[64], dir[64];
+ char isoTime[64], dir[128];
int debug = 0;

DIR *dp;
@@ -1918,7 +1917,7 @@
log_println(6, "Fault: Negative number of clents waiting=%d, mclients=%d, nuke them", waiting, mclients);
while (head_ptr != NULL) {
/* send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9933", 4); */
- send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9988", 4); // TODO constants
+ send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9988", 4); // indicate server waiting in queue
shutdown(head_ptr->ctlsockfd, SHUT_WR);
close(head_ptr->ctlsockfd);
tpid = head_ptr->pid;
@@ -1949,7 +1948,7 @@
}

if (head_ptr != NULL) {
- if ((time(0) - head_ptr->stime) > 70) { // TODO: 70 => WAIT_TIME-THRESH
+ if ((time(0) - head_ptr->stime) > 70) { // 70 => WAIT-TIME-THRESH
log_println(6, "Fault: Something in queue, but child %d (fd=%d) has exceeded wait time",
head_ptr->pid, head_ptr->ctlsockfd);
// Should send new 9977 'test aborted' signal to client. Using this for now
@@ -1960,7 +1959,6 @@
log_println(6, "pipe-fd=%d, running=%d, ctlsockfd=%d, client-type=%d, tests='%s'",
head_ptr->pipe, head_ptr->running,
head_ptr->ctlsockfd,
head_ptr->oldclient, head_ptr->tests);
- /* send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9966", 4); */
send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9988", 4); // boot the client
shutdown(head_ptr->ctlsockfd, SHUT_WR);
close(head_ptr->ctlsockfd);
@@ -1988,8 +1986,8 @@
sel_tv.tv_usec = 0;
log_println(3, "Waiting for new connection, timer running");
sel_11:
- rc = select(listenfd+1, &rfd, NULL, NULL, &sel_tv);
- if ((rc == -1) && (errno == EINTR))
+ retcode = select(listenfd+1, &rfd, NULL, NULL, &sel_tv);
+ if ((retcode == -1) && (errno == EINTR))
/* continue; */ // a signal caused the select() to exit, re-enter loop & check
goto sel_11;
tt = time(0);
@@ -2000,18 +1998,18 @@
log_println(3, "Timer not running, waiting for new connection");
mclients = 0;
sel_12:
- rc = select(listenfd+1, &rfd, NULL, NULL, NULL);
- if ((rc == -1) && (errno == EINTR))
+ retcode = select(listenfd+1, &rfd, NULL, NULL, NULL);
+ if ((retcode == -1) && (errno == EINTR))
goto sel_12; // a signal caused the select() to exit, re-enter loop & check
}

- if (rc < 0) {
+ if (retcode < 0) {
// an interrupt or signal caused the select() to exit, go back and start over
- log_println(5, "Select exited with rc = %d", rc);
+ log_println(5, "Select exited with return code = %d", retcode);
continue;
}

- if (rc == 0) { // select exited due to timer expiration
+ if (retcode == 0) { // select exited due to timer expiration
log_println(3, "Timer expired while waiting for a new connection");
/* if ((waiting > 0) && (testing == 0)) */
if (multiple == 0) {
@@ -2030,8 +2028,8 @@
/* } */
clilen = sizeof(cli_addr);
memset(&cli_addr, 0, clilen);
- log_println(6, "Select() found %d clients ready, highest fd=%d", rc, listenfd);
- if (rc > 1) {
+ log_println(6, "Select() found %d clients ready, highest fd=%d", retcode, listenfd);
+ if (retcode > 1) {
for (i=3; i<=listenfd; i++) {
if (FD_ISSET(i, &rfd)) {
listenfd = i;
@@ -2070,12 +2068,12 @@

// the specially crafted data that kicks off the old clients
for (i=0; i<RETRY_COUNT; i++) {
- rc = write(ctlsockfd, "123456 654321", 13);
- if ((rc == -1) && (errno == EINTR)) // interrupted, retry
+ retcode = write(ctlsockfd, "123456 654321", 13);
+ if ((retcode == -1) && (errno == EINTR)) // interrupted, retry
continue;
- if (rc == 13) // 13 bytes correctly written, exit
+ if (retcode == 13) // 13 bytes correctly written, exit
break;
- if (rc == -1) { // socket error hindering further retries
+ if (retcode == -1) { // socket error hindering further retries
log_println(1, "Initial contact with client failed errno=%d",
errno);
close(chld_pipe[0]);
close(chld_pipe[1]);
@@ -2168,7 +2166,7 @@
}
continue;
}
- while ((rc = sem_wait(&ndtq)) == -1 && errno == EINTR) { // socket interrupt, retry
+ while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) { // socket interrupt, retry
log_println(6, "Waiting for ndtq semaphore to free - 1");
continue;
}
@@ -2227,7 +2225,7 @@
head_ptr = new_child;
else {
log_println(4, "New request has arrived, adding request to queue list");
- while ((rc = sem_wait(&ndtq)) == -1 && errno == EINTR) {
+ while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
log_println(6, "Waiting for ndtq semaphore to free, adding new client 2");
continue;
}
@@ -2361,16 +2359,16 @@
log_println(5, "sending 'GO' signal to client msg='%s'", tmpstr);
send_msg(mchild->ctlsockfd, SRV_QUEUE, "0", 1); // test session starts now
for (i=0; i<5; i++) {
- rc = write(mchild->pipe, tmpstr, strlen(tmpstr));
- log_println(6, "write(%d) returned %d, errno=%d", mchild->pid, rc, errno);
- if ((rc == -1) && (errno == EINTR))
+ retcode = write(mchild->pipe, tmpstr, strlen(tmpstr));
+ log_println(6, "write(%d) returned %d, errno=%d", mchild->pid, retcode, errno);
+ if ((retcode == -1) && (errno == EINTR))
continue;
- if (rc == strlen(tmpstr))
+ if (retcode == strlen(tmpstr))
break;
log_println(6, "Failed to write 'GO' message to client %d, reason=%d, errno=%d",
- mchild->pid, rc, errno);
+ mchild->pid, retcode, errno);
/* TODO: handle other error conditions */
- if (rc == -1) {
+ if (retcode == -1) {
log_println(1, "Dispatch multi-client failed because '%s'", strerror(errno));
shutdown(mchild->ctlsockfd, SHUT_WR);
close(mchild->ctlsockfd);
@@ -2388,13 +2386,13 @@
log_println(5, "sending 'GO' signal to client msg='%s'", tmpstr);
send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "0", 1);
for (i=0; i<5; i++) {
- rc = write(head_ptr->pipe, tmpstr, strlen(tmpstr));
- if ((rc == -1) && (errno == EINTR))
+ retcode = write(head_ptr->pipe, tmpstr, strlen(tmpstr));
+ if ((retcode == -1) && (errno == EINTR))
continue;
- if (rc == strlen(tmpstr))
+ if (retcode == strlen(tmpstr))
break;
/* TODO: handle other error conditions */
- if (rc == -1) {
+ if (retcode == -1) {
log_println(1, "Dispatch multi-client failed because '%s'", strerror(errno));
shutdown(head_ptr->ctlsockfd, SHUT_WR);
close(head_ptr->ctlsockfd);
@@ -2430,9 +2428,9 @@
// should be checked for and the read() restarted if necessary
// RAC 3/18/10
//
- rc = read(chld_pipe[0], buff, 32);
+ retcode = read(chld_pipe[0], buff, 32);
log_println(6, "Child %d received '%s' from parent", getpid(),
buff);
- if ((rc == -1) && (errno == EINTR))
+ if ((retcode == -1) && (errno == EINTR))
continue;
if (strncmp(buff, "go", 2) == 0) {
log_println(6, "Got 'go' signal from parent, ready to start testing %d", getpid());
@@ -2467,39 +2465,10 @@
I2AddrFree(tmp_addr);
memset(cputimelog, 0, 256);
if (cputime) {
- //strncpy(cputimelog, DataDirName, strlen(DataDirName));
- strlcpy(cputimelog, DataDirName, sizeof(cputimelog));
- if ((dp = opendir(cputimelog)) == NULL && errno == ENOENT)
- mkdir(cputimelog, 0755);
- closedir(dp);
- get_YYYY(dir);
- //strncat(cputimelog, dir, 4);
- strlcat(cputimelog, dir, sizeof(cputimelog));
- if ((dp = opendir(cputimelog)) == NULL && errno == ENOENT)
- mkdir(cputimelog, 0755);
- closedir(dp);
- //strncat(cputimelog, "/", 1);
- strncat(cputimelog, "/", sizeof(cputimelog));
- get_MM(dir);
- //strncat(cputimelog, dir, 2);
- strlcat(cputimelog, dir, sizeof(cputimelog));
- if ((dp = opendir(cputimelog)) == NULL && errno == ENOENT)
- mkdir(cputimelog, 0755);
- closedir(dp);
- //strncat(cputimelog, "/", 1);
- strlcat(cputimelog, "/", sizeof(cputimelog));
- get_DD(dir);
- //strncat(cputimelog, dir, 2);
- strlcat(cputimelog, dir, sizeof(cputimelog));
- if ((dp = opendir(cputimelog)) == NULL && errno == ENOENT)
- mkdir(cputimelog, 0755);
- closedir(dp);
- //strncat(cputimelog, "/", 1);
- strncat(cputimelog, "/", sizeof(cputimelog));
- sprintf(dir, "%s_%s:%d.cputime", get_ISOtime(isoTime, sizeof(isoTime)), name, testPort);
- //strncat(cputimelog, dir, strlen(dir));
- strlcat(cputimelog, dir, sizeof(cputimelog));
- memcpy(meta.CPU_time, dir, strlen(dir));
+ sprintf(dir, "%s_%s:%d.cputime", get_ISOtime(isoTime, sizeof(isoTime)), name, testPort);
+ log_println(0, "CPUTIME:suffix=%s",dir);
+ create_named_logdir(cputimelog, sizeof(cputimelog),dir);
+ memcpy(meta.CPU_time, dir, strlen(dir));
if (pthread_create(&workerThreadId, NULL, cputimeWorker, (void*) cputimelog)) {
log_println(0, "Cannot create worker thread for writing cpu usage!");
workerThreadId = 0;
@@ -2541,14 +2510,14 @@
// run tests based on options
if (strncmp(test_suite, "Invalid", 7) != 0) {
log_println(3, "Valid test sequence requested, run test for client=%d", getpid());
- rc = run_test(agent, ctlsockfd, &testopt, test_suite);
+ retcode = run_test(agent, ctlsockfd, &testopt, test_suite);
}

// conclude all test runs
- if (rc == 0)
+ if (retcode == 0)
log_println(3, "Successfully returned from run_test() routine");
else {
- log_println(3, "Child %d returned non-zero (%d) from run_test() results some test failed!", getpid(), rc);
+ log_println(3, "Child %d returned non-zero (%d) from run_test() results some test failed!", getpid(), retcode);
child_sig(0);
}
close(ctlsockfd);
@@ -2556,15 +2525,15 @@
log_free();

if (cputime && workerThreadId) {
- workerLoop = 0;
+ cputimeworkerLoop = 0;
pthread_join(workerThreadId, NULL);
}

// At this point the tests have been run and we need to clean up and handle
// and child processes that might still be lying around. If we don't we get
- // zombies. The pkt-pair handling created 2 childern and we need to
get
- // rid of them. To know what PIDs to look for on 1/19/10 the
run_test()
- // routine was modified to pass around these values. The values are set in
+ // zombies. The pkt-pair handling created 2 childern and we need to
get
+ // rid of them. To know what PIDs to look for on 1/19/10 the
run_test()
+ // routine was modified to pass around these values. The values are
set in
// the proper routine in the testoptions.c file.
// Then add call to child_sig() routine and pass in these PID's so we handle
// each child in sequence


  • [ndt-dev] [ndt] r722 committed - Some more variables renamed, constants for often used values, and clea..., ndt, 10/17/2011

Archive powered by MHonArc 2.6.16.

Top of Page