Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r704 committed - Protocol logging : Include option to enable logging, addition of conne...

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r704 committed - Protocol logging : Include option to enable logging, addition of conne...


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r704 committed - Protocol logging : Include option to enable logging, addition of conne...
  • Date: Mon, 10 Oct 2011 00:01:30 +0000

Revision: 704
Author:

Date: Sun Oct 9 17:00:18 2011
Log: Protocol logging : Include option to enable logging, addition of connect messages, changes names for some test constants, quoting odd chars in payload, and inclusion of clientIP in log file name
http://code.google.com/p/ndt/source/detail?r=704

Modified:
/branches/kkumar_code_organize/src/analyze.c
/branches/kkumar_code_organize/src/logging.c
/branches/kkumar_code_organize/src/logging.h
/branches/kkumar_code_organize/src/ndtptestconstants.c
/branches/kkumar_code_organize/src/ndtptestconstants.h
/branches/kkumar_code_organize/src/network.c
/branches/kkumar_code_organize/src/runningtest.c
/branches/kkumar_code_organize/src/runningtest.h
/branches/kkumar_code_organize/src/test_meta_srv.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/web100srv.c
/branches/kkumar_code_organize/src/web100srv.h

=======================================
--- /branches/kkumar_code_organize/src/analyze.c Fri Sep 30 21:38:03
2011
+++ /branches/kkumar_code_organize/src/analyze.c Sun Oct 9 17:00:18
2011
@@ -409,9 +409,15 @@
case 'l':
LogFileName = optarg;
break;
+ /*
case 'u':
ProtoLogFileName = optarg;
break;
+ */
+ case 'u':
+ printf("Calling set protolog from analyze.c");
+ set_protologdir(optarg);
+ break;
case 'n':
iponly=1;
break;
@@ -436,6 +442,7 @@
}
log_println(1, "log file = %s", LogFileName);

+ //TODO do we need protocol log file in analyze????
if (ProtoLogFileName == NULL) {
sprintf(tmpstr, "%s/%s", BASEDIR, PROTOLOGFILE);
ProtoLogFileName = tmpstr;
=======================================
--- /branches/kkumar_code_organize/src/logging.c Fri Sep 30 21:38:03
2011
+++ /branches/kkumar_code_organize/src/logging.c Sun Oct 9 17:00:18
2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions of the logging system.
*
* Jakub S�awi�ski 2006-06-14
@@ -22,13 +22,18 @@
#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 "runningtest.h" // protocol validation


static int _debuglevel = 0;
static char* _programname = "";
static char* LogFileName = BASEDIR"/"LOGFILE;
-static char* ProtoLogFileName = BASEDIR"/"PROTOLOGFILE;
+static char ProtocolLogFileName[256] = BASEDIR"/"PROTOLOGFILE;
+//static char* ProtocolLogFileName ;
+static char* ProtocolLogDirName = BASEDIR"/"LOGDIR;
+static char protocollogfilestore[256];
+static char enableprotologging = 0;
+static const char* abc = "/var/log/ndt//web100srvprotocol_207.75.164.174.log";
static I2ErrHandle _errorhandler_nl = NULL;
static I2ErrHandle _errorhandler = NULL;
static I2LogImmediateAttr _immediateattr_nl;
@@ -174,9 +179,8 @@
}

/**
- * Function name: set_debuglvl
- * Description: Sets the debug level to the given value.
- * Arguments: debuglvl - the new debug level
+ * Set the debug level to the given value.
+ * @param debuglvl new debug level to use
*/

void
@@ -186,9 +190,8 @@
}

/**
- * Function name: set_logfile
- * Description: Sets the log filename.
- * Arguments: filename - new log filename
+ * Set the log filename.
+ * @param new log filename
*/

void
@@ -198,35 +201,116 @@
}

/**
- * set_protologfile
- * Sets the protocol log filename.
+ * Set the protocol log directory. The log directory is accepted as
+ * a command line argument using the -u option.
* @param filename The new protocol log filename
+ *
*/
void
-set_protologfile(char* filename)
-{
- printf ("SET FILENAME=%s;", filename);
- ProtoLogFileName = filename;
- printf ("END SET FILENAME=%s;", get_protologfile()); //protocol validation to remove printf
+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);
+ return;
+ }
+ 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);
+ } //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);
+ }
+
}

/**
- * Returns the protocol validation log filename.
- * @returns The protocol log filename
+ * 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);
+ return ProtocolLogDirName;
+}
+
+/**
+ * Sets the protocol log filename.
+ * @param filename The new protocol log filename
+ *
*/

+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");
+ PROTOLOGSUFFIX);
+ strncpy(ProtocolLogFileName, protologlocalarr,
strnlen(protologlocalarr));
+
+
+ //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;
+}
+
+/**
+ * Return the protocol validation log filename.
+ * @return The protocol log filename
+ */
+
char*
get_protologfile()
{
- printf ("GET FILENAME=");
- printf ("%s;\n",ProtoLogFileName);
- return ProtoLogFileName;
+ //return ProtocolLogFileName;
+ log_println (0, "**ProtoLog = %s ", ProtocolLogFileName);
+ return abc;
}

/**
- * Function name: get_debuglvl
- * Description: Returns the current debug level.
- * Returns: The current debug level
+ * Return the current debug level.
+ * @return current debug level
*/

int
@@ -236,9 +320,8 @@
}

/**
- * Function name: get_logfile
- * Description: Returns the log filename.
- * Returns: The log filename
+ * Return the log filename.
+ * @return The log filename
*/

char*
@@ -248,10 +331,9 @@
}

/**
- * Function name: get_errhandle
- * Description: Returns the error handle, that writes the messages
+ * Return the error handle, that writes the messages
* with the new line.
- * Returns: The error handle
+ * @return The error handle
*/

I2ErrHandle
@@ -261,10 +343,9 @@
}

/**
- * Function name: ndt_print
- * Description: Logs the message with the given lvl.
- * Arguments: lvl - the level of the message
- * format - the format of the message
+ * Logs the message with the given level.
+ * @param lvl level of the message
+ * @param format format of the message
* ... - the additional arguments
*/

@@ -283,11 +364,10 @@
}

/**
- * Function name: ndt_println
- * Description: Logs the message with the given lvl. New line character
+ * Log the message with the given level. New line character
* is appended to the error stream.
- * Arguments: lvl - the level of the message
- * format - the format of the message
+ * @arg lvl level of the message
+ * @arg format format of the message
* ... - the additional arguments
*/

@@ -306,21 +386,36 @@
}


-/** Log in a single key-value pair as a particular event
+/**
+ * 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
*/
void
-protolog_printgeneric(int lvl, const char* key, const char* value)
+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;
}
+ */
+ if (!enableprotologging) {
+ log_println(0, "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");
if (fp == NULL) {
@@ -328,8 +423,8 @@
log_println(0, "--Unable to open proto file while trying to record msg: %s \n", key, value);
}
else {
- fprintf(fp, " event = \"%s\", name = \"%s\" \n", key, value);
- printf("%s = \"%s\" \n", key, value);
+ fprintf(fp, " event=\"%s\", name=\"%s\", time=\"%s\"\n", key, value, get_ISOtime(isotime));
+ printf("%s = \"%s\" \n", key, logmessage);
fclose(fp);
}
}
@@ -343,23 +438,30 @@
* TODO: It may be good to define constants for event, pid etc. Use these instead.
*/
void
-protolog_status(int lvl, int pid, enum TEST_ID testid, enum TEST_STATUS_INT teststatus)
+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];
- char *currenttestname = "";
- char *teststatusdesc = "";
-
- //get descriptive strings for test name and status
- currenttestname = get_testnamedesc(testid, currenttestarr);
- teststatusdesc = get_teststatusdesc(teststatus, currentstatusarr);
-
+ char protomessage[256];
+ char currenttestarr[TEST_NAME_DESC_SIZE];
+ char currentstatusarr[TEST_STATUS_DESC_SIZE];
+ char isotime[64];
+ char *currenttestname = "";
+ char *teststatusdesc = "";
+
+ //get descriptive strings for test name and status
+ currenttestname = get_testnamedesc(testid, currenttestarr);
+ teststatusdesc = get_teststatusdesc(teststatus, currentstatusarr);
+
+ /*
if (lvl > _debuglevel) {
return;
}
+ */
+ if (!enableprotologging) {
+ log_println(0, "Protocol logging is not enabled");
+ return;
+ }

fp = fopen(get_protologfile(),"a");
if (fp == NULL) {
@@ -369,14 +471,75 @@
teststatusdesc, currenttestname);
}
else {
- sprintf(protomessage, " event = \"%s\", name=\"%s\", pid=\"%d\" \n",teststatusdesc, currenttestname, pid );
+ sprintf(protomessage, " event=\"%s\", name=\"%s\", pid=\"%d\", time=\"%s\"\n",teststatusdesc, currenttestname, pid, get_ISOtime(isotime) );
printf("%s: <-- %d - %s - %s --> \n ", protomessage, pid, teststatusdesc, currenttestname );
fprintf(fp, "%s", protomessage);
fclose(fp);
}
}
+
+/**
+ * Logs a protocol message specifically indicating the start/end or other status of processes.
+ * This method is different from the protolog_status in that this logs in status/progress of generic
+ * processes.
+ * @param pid PID of process
+ * @param testidarg enumerator indicating name of the test @see TEST_ID
+ * @param procidarg enumerator indicating name of the test @see PROCESS_TYPE_INT
+ * @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;
+ char protomessage[256];
+ char isotime[64];
+ char currentprocarr[TEST_NAME_DESC_SIZE]; // size suffices to describe process name name too
+ char currentstatusarr[PROCESS_STATUS_DESC_SIZE];
+ char currenttestarr[TEST_NAME_DESC_SIZE];
+
+ char *currentprocname = "";
+ char *procstatusdesc = "";
+ char *currenttestname = "";
+
+ //get descriptive strings for test name and status
+ currenttestname = get_testnamedesc(testidarg, currenttestarr);
+ currentprocname = get_processtypedesc(procidarg, currentprocarr);
+ procstatusdesc = get_procstatusdesc(teststatusarg, currentstatusarr);
+
+ if (!enableprotologging) {
+ log_println(0, "Protocol logging is not enabled");
+ return;
+ }
+
+ 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",
+ procstatusdesc, currentprocname);
+ 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) );
+ printf("%s: -- %d - %s - %s - %s -- \n ", protomessage, pid,currenttestname, procstatusdesc, currentprocname );
+ fprintf(fp, "%s", protomessage);
+ fclose(fp);
+ }
+}
+
+/**
+ * Enable protocol logging
+ */
+void enableprotocollogging() {
+ enableprotologging = 1;
+}

/** Log all send/receive protocol messages.
+ * This method currently is called only internally, and thus
+ * does not check for whether protocol logging is enabled
* @param lvl Level of the message
* @param *msgdirection Direction of msg (S->C, C->S)
* @param type message type
@@ -386,30 +549,41 @@
* @param ctlSocket socket over which message has been exchanged
* */

-void protolog_println(int lvl, char *msgdirection,
- const int type, void* msg, const int len, const int processid, const int ctlSocket)
+//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];
char msgtypedescarr[MSG_TYPE_DESC_SIZE];
char *currenttestname, *currentmsgtype;
+ char isotime[64];
+ char logmessage[4096]; // message after replacing unnecessary
characters

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

+ // make delimiters in message payload explicit
+ quote_delimiters(msg, strlen(msg), logmessage, sizeof(logmessage));
+
fp = fopen(get_protologfile(),"a");
- if (fp == NULL) {
- //printf("--Unable to open proto, RCV");
- log_println(0, "Unable to open protocol log file '%s\n', 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\"\n",
- msgdirection, currenttestname, currentmsgtype, len, (char*)msg, processid, ctlSocket);
- printf("direction = %s, test= %s, type=%s, len=%d, msg=%s, pid=%d, socket=%d\n",
- msgdirection, currenttestname, currentmsgtype, len, (char*)msg, processid, ctlSocket);
- fclose(fp);
- }
+ 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));
+ 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));
+ fclose(fp);
+ }
}

/** Log "sent" protocol messages.
@@ -421,9 +595,15 @@
* @param processid PID of process
* @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) {
- char *currentDir = get_currentdirndesc();
- protolog_println(lvl, currentDir, type, msg, len, processid,
ctlSocket);
+//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) {
+ if (!enableprotologging) {
+ log_println(0, "Protocol logging is not enabled");
+ return;
+ }
+ char *currentDir = get_currentdirndesc();
+ //protolog_println(lvl, currentDir, type, msg, len, processid,
ctlSocket);
+ protolog_println(currentDir, type, msg, len, processid, ctlSocket);
}

/**
@@ -436,9 +616,14 @@
* @param processid PID of process
* @param ctlSocket socket over which message has been exchanged
* */
-void protolog_rcvprintln (int lvl, const int type, void* msg, const int len, const int processid, const int ctlSocket){
- char *otherDir = get_otherdirndesc();
- protolog_println(lvl, otherDir, type, msg, len, processid,
ctlSocket);
+void protolog_rcvprintln (const int type, void* msg, const int len, const int processid, const int ctlSocket){
+ if (!enableprotologging) {
+ log_println(0, "Protocol logging is not enabled");
+ return;
+ }
+ char *otherDir = get_otherdirndesc();
+ //protolog_println(lvl, otherDir, type, msg, len, processid,
ctlSocket);
+ protolog_println(otherDir, type, msg, len, processid, ctlSocket);
}

/**
@@ -461,9 +646,8 @@
}

/**
- * Function name: get_timestamp
- * Description: Returns the previously recorded timestamp.
- * Returns: The timestamp
+ * Return the previously recorded timestamp.
+ * @return timestamp
*/
time_t
get_timestamp()
@@ -472,9 +656,8 @@
}

/**
- * Function name: get_utimestamp
- * Description: Returns the previously recorded utimestamp.
- * Returns: The utimestamp
+ * Return the previously recorded utimestamp.
+ * @return The utimestamp
*/
long int
get_utimestamp()
@@ -483,8 +666,7 @@
}

/**
- * Function name get_YYYY
- * Description: Returns a character string YYYY for the current year
+ * Return a character string YYYY for the current year
* Author: Rich Carlson - 6/29/09
* @param Pointer to the string indicating the year
*/
@@ -505,8 +687,7 @@


/**
- * Function name get_MM
- * Description: Returns a character string MM for the current year
+ * Return a character string MM for the current year
* Author: Rich Carlson - 6/29/09
* @param Pointer to the string indicating month
*/
@@ -530,8 +711,7 @@
}

/**
- * Function name get_DD
- * Description: Returns a character string DD for the current year
+ * Return a character string DD for the current year
* Author: Rich Carlson - 6/29/09
* @param Pointer to the string indicating day
*/
@@ -553,13 +733,12 @@
sprintf(day, "%d", result->tm_mday);
}

-/**
- * Function name get_ISOtime
- * Description: Returns a character string in the ISO8601 time foramt
+/** Return a character string in the ISO8601 time foramt
* used to create snaplog and trace file names
- * Returns: character string with ISO time string.
+ *
* Author: Rich Carlson - 5/6/09
* @param Pointer to the string indicating ISO time
+ * @param character string with ISO time string.
*/

char *
@@ -666,7 +845,7 @@
// and name themselves record the year, month, date, time and client
name.
// The "primary" location for this log file is obtained as a command line option
// from the user, or is the default location of BASE_DIR+LOG_DIR of the NDT installation
-
+//TODO : Move this into a new method??
strncpy(tmpstr, DataDirName, strlen(DataDirName));
// Open the directory or create one if not yet present
if ((dp = opendir(tmpstr)) == NULL && errno == ENOENT)
@@ -691,7 +870,7 @@
closedir(dp);

// end block creating log directory
-
+//end creating dir

memcpy(tmp2str, tmpstr, tmpstrlen); // tmp2str now contains the dir name intended
// tmpstr will henceforth refer to the log file's name
@@ -808,3 +987,59 @@
fclose(fp);
}
}
+
+
+
+/**
+ * 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
+ * */
+
+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(0,"****Received=%s; len=%d; dest=%d; MSG=%s",line , line_size,output_buf_size, output_buf);
+
+ return j - 1;
+}
+
+
+/** Method to create directories for log files */
+/*
+createDir(char *dirName) {
+}
+*/
=======================================
--- /branches/kkumar_code_organize/src/logging.h Fri Sep 30 21:38:03
2011
+++ /branches/kkumar_code_organize/src/logging.h Sun Oct 9 17:00:18
2011
@@ -14,17 +14,19 @@
#include <sys/stat.h>
#include <sys/types.h>
#include "ndtptestconstants.h"
+#include "runningtest.h" // protocol validation

#define LOGFILE "web100srv.log" /* Name of log file */
#define PROTOLOGFILE "web100srvprotocol.log" /* Name of protocol validation log file */
+#define PROTOLOGPREFIX "web100srvprotocol_" /* prefix for protocol validation log file */
+#define PROTOLOGSUFFIX ".log" /* suffix for protocol validation log file */

void log_init(char* progname, int debuglvl);
void set_debuglvl(int debuglvl);
void set_logfile(char* filename);
-void set_protologfile(char* filename);
int get_debuglvl();
char* get_logfile();
-char* get_protologfile();
+
I2ErrHandle get_errhandle();
void log_print(int lvl, const char* format, ...);
void log_println(int lvl, const char* format, ...);
@@ -77,13 +79,25 @@
struct metaentry* additional; // all other additional data
};

-
-void protolog_printgeneric(int lvl, const char* key, const char* val);
-void protolog_status(int lvl, int pid, enum TEST_ID testid, enum TEST_STATUS_INT teststatus);
-void protolog_println(int lvl, char *msgdirection,
- const int type, void* msg, const int len, const int processid, const int ctlSocket);
-void protolog_sendprintln (int lvl, const int type, void* msg, const int len, const int processid, const int ctlSocket);
-void protolog_rcvprintln (int lvl, const int type, void* msg, const int len, const int processid, const int ctlSocket);
+void set_protologdir(char* dirname);
+//void set_protologfile(char* ipaddress);
+void set_protologfile(char* client_ip, char *protologfileparam);
+char* get_protologfile();
+char* get_protologdir();
+//char *createprotologfilename (char* textappendarg);
+void enableprotocollogging();
+char *createprotologfilename (char* client_ip, char* textappendarg);
+
+
+void protolog_printgeneric(const char* key, const char* val);
+void protolog_status(int pid, enum TEST_ID testid, enum TEST_STATUS_INT teststatus);
+void protolog_sendprintln (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);
+void protolog_procstatus(int pid, enum TEST_ID testidarg, enum PROCESS_TYPE_INT procidarg,
+ enum
PROCESS_STATUS_INT teststatusarg);
+void protolog_procstatuslog(int pid, enum TEST_ID testidarg,
+ enum PROCESS_TYPE_INT procidarg,
+ enum PROCESS_STATUS_INT
teststatusarg);

struct metadata meta;
#endif
=======================================
--- /branches/kkumar_code_organize/src/ndtptestconstants.c Fri Sep 30 21:38:03 2011
+++ /branches/kkumar_code_organize/src/ndtptestconstants.c Sun Oct 9 17:00:18 2011
@@ -13,11 +13,11 @@
// The arrays below rely on the ordering of corresponding enum in the .h file.
// test names
static char *_teststatusdescarray[] = {
- "not started",
- "started",
- "in progress",
- "incomplete",
- "complete"
+ "test_not_started",
+ "test_started",
+ "test_in_progress",
+ "test_incomplete",
+ "test_complete"
};

// names of tests.
@@ -60,7 +60,7 @@
* */
char *get_testnamedesc(enum TEST_ID testid, char *snamearg) {
snamearg = _testnamesarray[testid];
- printf ("--current test name = %s for %d\n", snamearg ,testid);
+ //printf ("--current test name = %s for %d\n", snamearg ,testid);
return snamearg;
}

@@ -72,7 +72,7 @@
* */
char *get_teststatusdesc(enum TEST_STATUS_INT teststatus, char *sstatusarg) {
sstatusarg = _teststatusdescarray[teststatus];
- printf ("--current test status = %s, for %d \n", sstatusarg,
teststatus);
+ //printf ("--current test status = %s, for %d \n", sstatusarg, teststatus);
return sstatusarg;
}

@@ -85,7 +85,7 @@
* */
char *get_testdirectiondesc(enum Tx_DIRECTION testdirection, char *sdirnarg) {
sdirnarg = _txdirectionsarray[testdirection];
- printf ("--current test direction = %s , for %d\n", sdirnarg, testdirection);
+ //printf ("--current test direction = %s , for %d\n", sdirnarg, testdirection);
return sdirnarg;
}

@@ -98,6 +98,6 @@
* */
char *get_msgtypedesc(int msgtype, char *smsgtypearg) {
smsgtypearg = _testmsgtypesarray[msgtype];
- printf ("--current test type = %s , for %d\n", smsgtypearg, msgtype);
+ //printf ("--current test type = %s , for %d\n", smsgtypearg,
msgtype);
return smsgtypearg;
}
=======================================
--- /branches/kkumar_code_organize/src/ndtptestconstants.h Fri Sep 30 21:38:03 2011
+++ /branches/kkumar_code_organize/src/ndtptestconstants.h Sun Oct 9 17:00:18 2011
@@ -14,18 +14,18 @@
#define TEST_STATUS (1L << 4)
#define TEST_META (1L << 5)

-#define TEST_NAME_DESC_SIZE 10 // will hold "string "middlebox", which is the longest name
-#define TEST_STATUS_DESC_SIZE 15 // test status < 15 chars
-#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"
-
-// status of tests. Used mainly to log a "textual" explanation using below array
+#define TEST_NAME_DESC_SIZE 10 /* will hold "string "middlebox", which is the longest name */
+#define TEST_STATUS_DESC_SIZE 18 /* test status < 18 chars */
+#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" */
+
+/* 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 } teststatusint;

-// Test IDs
+/* Test IDs */
enum TEST_ID{ NONE, MIDDLEBOX, SFW, C2S, S2C, META } testid;

-// Transmission direction
+/* Transmission direction */
enum Tx_DIRECTION { NO_DIR, C_S , S_C} txdirection;

char *get_testnamedesc(enum TEST_ID testid, char *stestnamearg);
=======================================
--- /branches/kkumar_code_organize/src/network.c Fri Sep 30 21:38:03
2011
+++ /branches/kkumar_code_organize/src/network.c Sun Oct 9 17:00:18
2011
@@ -383,6 +383,10 @@
unsigned char buff[3];
int rc, i;
FILE *fp; //kk
+ //todo remove
+ char tmpstr[256];
+ I2Addr tmp_addr;
+ //todo remove

assert(msg);
assert(len >= 0);
@@ -426,9 +430,22 @@
return -3;
log_println(8, ">>> send_msg: type=%d, len=%d, msg=%s, pid=%d", type, len, msg, getpid());

- //todo level = 0 could be made into a constant or option. move out of here in that case
- protolog_sendprintln(0,
- type, msg, len, getpid(),ctlSocket);
+ 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;
}
@@ -454,7 +471,9 @@
unsigned char buff[3];
int length;
FILE *fp; //kk
-
+ //todo remove
+ I2Addr tmp_addr;
+ char tmpstr[256];
// todo remove

int itype = *type;
@@ -489,9 +508,23 @@
}
log_println(8, "<<< recv_msg: type=%d, len=%d", *type, *len);

- //todo level = 0 could be made into a constant or option. move out of here in that case
- //protolog_rcvprintln(0, itype, msgtemp, ilen, getpid(),ctlSocket);
- protolog_rcvprintln(0, *type, msgtemp, *len, getpid(),ctlSocket);
+ // 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;
}
=======================================
--- /branches/kkumar_code_organize/src/runningtest.c Fri Sep 30 21:38:03 2011
+++ /branches/kkumar_code_organize/src/runningtest.c Sun Oct 9 17:00:18 2011
@@ -21,8 +21,20 @@
/**
* 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
+ */
+static char *_proctypesarray[] = { "process", "connect"};
+

/**
* Get ID of currently running test
@@ -139,7 +151,19 @@
* */
char *get_procstatusdesc(enum PROCESS_STATUS_INT procstatusarg, char *sprocarg) {
sprocarg = _procstatusarray[procstatusarg];
- printf("--current test name = %s for %d\n", sprocarg, procstatusarg);
+ printf("--current process status = %s for %d\n", sprocarg,
procstatusarg);
return sprocarg;
}

+/**
+ * Get descriptive string for process name
+ * @param procid Id of the test
+ * @param *snamearg storage for test name description
+ * @return char* Descriptive string for process (process, connect )
+ * */
+char *get_processtypedesc(enum PROCESS_TYPE_INT procidarg, char *snamearg) {
+ snamearg = _proctypesarray[procidarg];
+ printf ("--current process name = %s for %d\n", snamearg ,procidarg);
+ return snamearg;
+}
+
=======================================
--- /branches/kkumar_code_organize/src/runningtest.h Fri Sep 30 21:38:03 2011
+++ /branches/kkumar_code_organize/src/runningtest.h Sun Oct 9 17:00:18 2011
@@ -9,9 +9,14 @@
#define RUNNINGTEST_H_

#define PROCESS_STATUS_DESC_SIZE 17 // suffice to hold status defined below
+
// indicates the status of process like the web100srv or web100clt
+//enum PROCESS_STATUS_INT { UNKNOWN, PROCESS_STARTED, PROCESS_ENDED };
enum PROCESS_STATUS_INT { UNKNOWN, PROCESS_STARTED, PROCESS_ENDED };

+enum PROCESS_TYPE_INT { PROCESS_TYPE, CONNECT_TYPE };
+
+
int getCurrentTest();
void setCurrentTest(int testId);
char *get_currenttestdesc ();
@@ -21,5 +26,6 @@
char *get_currentdirndesc ();
char *get_otherdirndesc ();
char *get_procstatusdesc(enum PROCESS_STATUS_INT procstatusarg, char *sprocarg);
+char *get_processtypedesc(enum PROCESS_TYPE_INT procid, char *snamearg);

#endif /* RUNNINGTEST_H_ */
=======================================
--- /branches/kkumar_code_organize/src/test_meta_srv.c Fri Sep 30 21:38:03 2011
+++ /branches/kkumar_code_organize/src/test_meta_srv.c Sun Oct 9 17:00:18 2011
@@ -57,7 +57,8 @@

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

// first message exchanged is am empty TEST_PREPARE message
j = send_msg(ctlsockfd, TEST_PREPARE, "", 0);
@@ -149,7 +150,8 @@
log_println(1, " <-------------------------->");

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

setCurrentTest(TEST_NONE);
}
=======================================
--- /branches/kkumar_code_organize/src/test_sfw_srv.c Fri Sep 30 21:38:03 2011
+++ /branches/kkumar_code_organize/src/test_sfw_srv.c Sun Oct 9 17:00:18 2011
@@ -15,6 +15,8 @@
#include "network.h"
#include "utils.h"
#include "testoptions.h"
+#include "runningtest.h"
+

static pthread_mutex_t mainmutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t maincond = PTHREAD_COND_INITIALIZER;
@@ -102,7 +104,8 @@

// log
teststatusnow = TEST_ENDED;
- protolog_status(1, getpid() , thistestId, teststatusnow); //todo will getpid() be correct?
+ //protolog_status(1, getpid() , thistestId, teststatusnow); //todo will getpid() be correct?
+ protolog_status (getpid() , thistestId, teststatusnow);
log_println(1, " <-------------------------->");
// unset test name
setCurrentTest(TEST_NONE);
@@ -144,6 +147,9 @@
// variables used for protocol validation
enum TEST_ID thistestId = NONE;
enum TEST_STATUS_INT teststatusnow = TEST_NOT_STARTED;
+ enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;
+ enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
+

assert(ctlsockfd != -1);
assert(options);
@@ -153,7 +159,8 @@
log_println(1, " <-- %d - Simple firewall test -->", options->child0);
thistestId = SFW;
teststatusnow = TEST_STARTED;
- protolog_status(1, options->child0, thistestId, teststatusnow);
+ //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
sfwsrv_addr = CreateListenSocket(NULL, "0", conn_options, 0);
@@ -217,7 +224,7 @@
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 erroe message too
+ //TODO above seems incorrect w.r.t the error message too
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
I2AddrFree(sfwsrv_addr);
return 1;
@@ -256,7 +263,8 @@

// log end
teststatusnow = TEST_ENDED;
- protolog_status(0,options->child0, thistestId, teststatusnow);
+ //protolog_status(0,options->child0, thistestId, teststatusnow);
+ protolog_status(options->child0, thistestId, teststatusnow);
log_println(1, " <-------------------------->");
I2AddrFree(sfwsrv_addr);
return 5;
@@ -301,9 +309,12 @@
// Now read actual data from the sockets listening for client message.
// Based on data, conclude SFW status and send TEST_MSG with result.
// In all cases, finalize the test
-
clilen = sizeof(cli_addr);
sockfd = accept(sfwsockfd, (struct sockaddr *) &cli_addr, &clilen);
+ // protocol validation log to indicate client tried connecting
+ procstatusenum = PROCESS_STARTED;
+ protolog_procstatus(options->child0, thistestId, proctypeenum, procstatusenum);
+

msgLen = sizeof(buff);
if (recv_msg(sockfd, &msgType, buff, &msgLen)) { // message received in error
=======================================
--- /branches/kkumar_code_organize/src/testoptions.c Fri Sep 30 21:38:03 2011
+++ /branches/kkumar_code_organize/src/testoptions.c Sun Oct 9 17:00:18 2011
@@ -43,6 +43,7 @@
static int prevCWNDval = -1;
static int decreasing = 0;

+
/**
* Count the CWND peaks from a snapshot and record the minimal and maximum one.
* @param agent Web100 agent used to track the connection
@@ -200,6 +201,9 @@
int msgType;
int msgLen = 1;
int first = 1;
+ char remhostarr[256], protologlocalarr[256];
+ char *remhost_ptr = get_remotehost();
+

assert(ctlsockfd != -1);
assert(options);
@@ -220,6 +224,14 @@
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return (-2);
}
+ // client connect received correctly. Logging activity
+ // log that client connected, and create log file
+ log_println(0,
+ "Client connect received from :IP %s to some server on socket %d", get_remotehost(), ctlsockfd);
+
+ set_protologfile(get_remotehost(), protologlocalarr);
+
+
if (!(useropt & (TEST_MID | TEST_C2S | TEST_S2C | TEST_SFW | TEST_STATUS | TEST_META))) {
// message received does not indicate a valid test!
sprintf(buff, "Invalid test suite request");
@@ -257,7 +269,7 @@
* Error codes:
* -1 - Listener socket creation failed
* -3-web100 connection data not obtained
- * -100 -timeout while waitinf for client to connect to serverÕs ephemeral port
+ * -100 -timeout while waiting for client to connect to serverÕs ephemeral port
* -errono- Other specific socket error numbers
* -101 - Retries exceeded while waiting for
client to connect
* -102 - Retries exceeded while waiting for
data from connected client
@@ -291,6 +303,8 @@
// variables used for protocol validation logging
enum TEST_ID thistestId = NONE;
enum TEST_STATUS_INT teststatusnow = TEST_NOT_STARTED;
+ enum PROCESS_STATUS_INT procstatusenum = PROCESS_STARTED;
+ enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;

assert(ctlsockfd != -1);
assert(agent);
@@ -305,7 +319,8 @@
printf(" <--- %d - Middlebox test --->", options->child0);
thistestId = MIDDLEBOX;
teststatusnow = TEST_STARTED;
- protolog_status(1, options->child0, thistestId, teststatusnow);
+ //protolog_status(1, options->child0, thistestId, teststatusnow);
+ protolog_status(options->child0, thistestId, teststatusnow);

// determine port to be used. Compute based on options set earlier
// by reading from config file, or use default port3 (3003),
@@ -413,8 +428,13 @@

// if a valid connection request is received, client has connected. Proceed.
// Note the new socket fd used in the throughput test is this
(midsfd)
- if ((midsfd = accept(options->midsockfd, (struct sockaddr *) &cli_addr, &clilen)) > 0)
+ if ((midsfd = accept(options->midsockfd, (struct sockaddr *) &cli_addr, &clilen)) > 0) {
+ // log protocol validation indicating client connection
+ procstatusenum = PROCESS_STARTED;
+ proctypeenum = CONNECT_TYPE;
+ protolog_procstatus(options->child0, thistestId, proctypeenum, procstatusenum);
break;
+ }

if ((midsfd == -1) && (errno == EINTR)) // socket interrupted, wait some more
goto midfd;
@@ -484,7 +504,8 @@

// log end of test into protocol doc, just to delimit.
teststatusnow = TEST_ENDED;
- protolog_status(1, options->child0, thistestId, teststatusnow);
+ //protolog_status(1, options->child0, thistestId, teststatusnow);
+ protolog_status( options->child0, thistestId, teststatusnow);

setCurrentTest(TEST_NONE);
/* I2AddrFree(midsrv_addr); */
@@ -551,6 +572,9 @@
// Test ID and status descriptors
enum TEST_ID testids = C2S;
enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
+ enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
+ enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;
+

if (testOptions->c2sopt) {
setCurrentTest(TEST_C2S);
@@ -559,7 +583,8 @@

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

// Determine port to be used. Compute based on options set earlier
// by reading from config file, or use default port2 (3002).
@@ -653,6 +678,10 @@
recvsfd = accept(testOptions->c2ssockfd, (struct sockaddr *) &cli_addr, &clilen);
if (recvsfd > 0) {
log_println(6, "accept() for %d completed", testOptions->child0);
+ // log protocol validation indicating client accept
+ procstatusenum = PROCESS_STARTED;
+ proctypeenum = CONNECT_TYPE;
+ protolog_procstatus(testOptions->child0,testids, proctypeenum, procstatusenum);
break;
}
if ((recvsfd == -1) && (errno == EINTR)) { // socket interrupted, wait some more
@@ -950,7 +979,8 @@
log_println(1, " <----------- %d -------------->", testOptions->child0);
//protocol logs
teststatuses = TEST_ENDED;
- protolog_status(0,testOptions->child0, testids, teststatuses);
+ //protolog_status(0,testOptions->child0, testids, teststatuses);
+ protolog_status(testOptions->child0, testids, teststatuses);


//set current test status and free address
@@ -1040,6 +1070,8 @@
// variables used for protocol validation logs
enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
enum TEST_ID testids = S2C;
+ enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
+ enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;

// Determine port to be used. Compute based on options set earlier
// by reading from config file, or use default port2 (3003)
@@ -1049,7 +1081,8 @@

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

strcpy(listens2cport, PORT4);

@@ -1156,8 +1189,12 @@
ximfd:
xmitsfd = accept(testOptions->s2csockfd, (struct sockaddr *) &cli_addr, &clilen);
if (xmitsfd > 0) {
- log_println(6, "accept() for %d completed", testOptions->child0);
- break;
+ log_println(6, "accept() for %d completed", testOptions->child0);
+ //protocol logging
+ procstatusenum = PROCESS_STARTED;
+ proctypeenum = CONNECT_TYPE;
+ protolog_procstatus(testOptions->child0, testids, proctypeenum, procstatusenum);
+ break;
}
if ((xmitsfd == -1) && (errno == EINTR)) { // socket interrupted, wait some more
log_println(6, "Child %d interrupted while waiting for accept() to complete",
@@ -1537,7 +1574,8 @@
log_println(1, " <------------ %d ------------->", testOptions->child0);
//log protocol validation logs
teststatuses = TEST_ENDED;
- protolog_status(1,testOptions->child0, testids, teststatuses);
+ //protolog_status(1,testOptions->child0, testids, teststatuses);
+ protolog_status(testOptions->child0, testids, teststatuses);

setCurrentTest(TEST_NONE);
/* I2AddrFree(s2csrv_addr); */
=======================================
--- /branches/kkumar_code_organize/src/usage.c Fri Sep 23 13:50:35 2011
+++ /branches/kkumar_code_organize/src/usage.c Sun Oct 9 17:00:18 2011
@@ -60,6 +60,8 @@
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(" --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");
printf(" --c2sport #port - specify C2S throughput test port number (default 3002)\n");
=======================================
--- /branches/kkumar_code_organize/src/utils.c Sun Feb 28 12:04:47 2010
+++ /branches/kkumar_code_organize/src/utils.c Sun Oct 9 17:00:18 2011
@@ -161,10 +161,9 @@
#endif
}

-/*
- * Function name: mysleep
- * Description: Sleeps for the given amount of seconds.
- * Arguments: time - the amount of seconds to sleep for
+/**
+ * Sleep for the given amount of seconds.
+ * @arg time in seconds to sleep for
*/

void
@@ -183,3 +182,30 @@
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/web100srv.c Fri Sep 30 21:38:03
2011
+++ /branches/kkumar_code_organize/src/web100srv.c Sun Oct 9 17:00:18
2011
@@ -182,6 +182,7 @@
{"interface", 1, 0, 'i'},
{"log", 1, 0, 'l'},
{"protocol_log", 1, 0, 'u'},
+ {"enableprotolog", 0, 0, 'e'},
{"port", 1, 0, 'p'},
{"midport", 1, 0, 302},
{"c2sport", 1, 0, 303},
@@ -609,10 +610,15 @@
}
else if (strncasecmp(key, "protocol_log", 12) == 0) {
sprintf(lgfn, "%s", val);
- printf("protocol_log: %s\n", val); //todo remove printf
- set_protologfile(lgfn);
+ printf("protocol_log calling set_protocoldir from: %s\n", val); //todo remove printf
+ set_protologdir(lgfn);
continue;
}
+ else if (strncasecmp(key, "enableprotolog", 11) == 0) {
+ printf("enabling protocol logging from: %s\n", val); //todo remove printf
+ enableprotocollogging();
+ continue;
+ }
else if (strncasecmp(key, "admin_file", 10) == 0) {
sprintf(apfn, "%s", val);
AdminFileName = apfn;
@@ -886,10 +892,12 @@
}

/**
- * Capture CPU time details
+ * Run all tests, process results, record them into relevant log files
*
- * @param arg* void pointer to the log file sued to record CPU time details
- * @param void* NULL
+ * @param agent pointer to web_100 agent
+ * @param ctlsockfd socket used for server->client communication
+ * @param testopt TestOptions *
+ * @param test_suite pointer to string indicating tests to be run
* */

int
@@ -949,7 +957,7 @@
// protocol logging addition
// start with a clean slate of currently running test and direction
setCurrentTest(TEST_NONE);
-
+ printf ("Remote host= %s", get_remotehost());

stime = time(0);
log_println(4, "Child process %d started", getpid());
@@ -1149,7 +1157,7 @@

// section to calculate duplex mismatch

- // Calculate average sound trip time and convert to seconds
+ // Calculate average round trip time and convert to seconds
avgrtt = (double) SumRTT/CountRTT;
rttsec = avgrtt * .001;
/* loss = (double)(PktsRetrans- FastRetran)/(double)(DataPktsOut-AckPktsOut); */
@@ -1488,6 +1496,8 @@
char *srvstatusdesc;
enum PROCESS_STATUS_INT srvstatusenum = UNKNOWN;
char statustemparr[PROCESS_STATUS_DESC_SIZE]; // temp storage for process name
+ enum PROCESS_TYPE_INT proctypeenum = PROCESS_TYPE;
+ enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;

options.limit = 0;
options.snapDelay = 5;
@@ -1504,6 +1514,8 @@
memset(&testopt, 0, sizeof(testopt));
/* sigset_t newmask, oldmask; */

+
+
#ifdef AF_INET6
#define GETOPT_LONG_INET6(x) "46"x
#else
@@ -1519,7 +1531,7 @@
opterr = 0;
while ((c = getopt_long(argc, argv,
// GETOPT_LONG_INET6(GETOPT_LONG_EXP("adhmoqrstvzc:x:b:f:i:l:p:T:A:S:")), long_options, 0)) != -1) {
- GETOPT_LONG_INET6(GETOPT_LONG_EXP("adhmoqrstvzc:x:b:f:i:l:u:p:T:A:S:")), long_options, 0)) != -1) {
+ GETOPT_LONG_INET6(GETOPT_LONG_EXP("adhmoqrstvzc:x:b:f:i:l:u:e:p:T:A:S:")), long_options, 0)) != -1) {
switch (c) {
case 'c':
ConfigFileName = optarg;
@@ -1554,7 +1566,7 @@
// Get server execution options
while ((c = getopt_long(argc, argv,
// GETOPT_LONG_INET6(GETOPT_LONG_EXP("adhmoqrstvzc:x:b:f:i:l:p:T:A:S:")), long_options, 0)) != -1) {
- GETOPT_LONG_INET6(GETOPT_LONG_EXP("adhmoqrstvzc:x:b:f:i:l:u:p:T:A:S:")), long_options, 0)) != -1) {
+ GETOPT_LONG_INET6(GETOPT_LONG_EXP("adhmoqrstvzc:x:b:f:i:l:u:e:p:T:A:S:")), long_options, 0)) != -1) {
switch (c) {
case '4':
conn_options |= OPT_IPV4_ONLY;
@@ -1615,7 +1627,12 @@
set_logfile(optarg);
break;
case 'u':
- set_protologfile(optarg);
+ printf("Calling set protolog from case-u");
+ set_protologdir(optarg);
+ break;
+ case 'e':
+ printf("Enabling protocol logging");
+ enableprotocollogging();
break;
case 'o':
old_mismatch = 1;
@@ -1739,6 +1756,7 @@
sprintf(logd, "%s/%s/", BASEDIR, DataDirName);
DataDirName = logd;
}
+

if (SysLogFacility != NULL) {
i = 0;
@@ -1850,7 +1868,8 @@
sprintf(startsrvmsg, "Web100srv (ver %s)",VERSION);
srvstatusenum = PROCESS_STARTED;
srvstatusdesc = get_procstatusdesc(srvstatusenum, statustemparr);
- protolog_printgeneric(0, srvstatusdesc, startsrvmsg);
+ //protolog_printgeneric(0, srvstatusdesc, startsrvmsg);
+ protolog_printgeneric(srvstatusdesc, startsrvmsg);


// scan through the interface device list and get the names/speeds of each
@@ -2093,7 +2112,8 @@
for (i=0;i<5;i++) {
ctlsockfd = 0;
ctlsockfd = accept(listenfd, (struct sockaddr *) &cli_addr, &clilen);
- if ((ctlsockfd == -1) && (errno == EINTR))
+
+ if ((ctlsockfd == -1) && (errno == EINTR)) // socket interrupted, retry
continue; // sig child
size_t tmpstrlen = sizeof(tmpstr);
memset(tmpstr, 0, tmpstrlen);
@@ -2102,7 +2122,8 @@
I2AddrNodeName(tmp_addr, tmpstr, &tmpstrlen);
/* I2AddrFree(tmp_addr); */
log_println(4, "New connection received from 0x%x [%s] sockfd=%d.", tmp_addr, tmpstr, ctlsockfd);
- break;
+
+ break;
}

// verify that accept really worked and don't process connections that've failed
@@ -2111,11 +2132,16 @@
log_println(4, "New connection request failed sockfd=%d reason-%d.", ctlsockfd, errno);
continue;
}
+ else { // accept worked, log protocol validation log to indicate that client tried connecting
+ procstatusenum = PROCESS_STARTED;
+ proctypeenum = CONNECT_TYPE;
+ protolog_procstatus(getpid(), getCurrentTest(), proctypeenum, procstatusenum); // todo pid?
+ }

// the specially crafted data that kicks off the old clients
for (i=0; i<5; i++) { // todo 5==SOCKET_IO_RETRY_COUNT
rc = write(ctlsockfd, "123456 654321", 13);
- if ((rc == -1) && (errno == EINTR)) // interrupted, retyr
+ if ((rc == -1) && (errno == EINTR)) // interrupted, retry
continue;
if (rc == 13) // 13 bytes correctly written, exit
break;
@@ -2130,6 +2156,7 @@

log_println(6, "xxx, calling initialize_tests()");
t_opts = initialize_tests(ctlsockfd, &testopt, test_suite);
+
if (t_opts < 1) {
log_println(3, "Invalid test suite string '%s' received, terminate child", test_suite);
close(chld_pipe[0]);
@@ -2611,3 +2638,10 @@
}
}
}
+
+/** Method to get remote hots's address.
+ * */
+char *get_remotehost() {
+ return rmt_host;
+}
+
=======================================
--- /branches/kkumar_code_organize/src/web100srv.h Fri Sep 23 13:50:35
2011
+++ /branches/kkumar_code_organize/src/web100srv.h Sun Oct 9 17:00:18
2011
@@ -218,6 +218,8 @@
int KillHung(void);
void writeMeta(int compress, int cputime, int snaplog, int tcpdump);

+char *get_remotehost();
+
/* global variables for signal processing */
sig_atomic_t sig1;
sig_atomic_t sig2;


  • [ndt-dev] [ndt] r704 committed - Protocol logging : Include option to enable logging, addition of conne..., ndt, 10/09/2011

Archive powered by MHonArc 2.6.16.

Top of Page