Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r753 committed - Include new message body format type in protocol logs, log time at whi...

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r753 committed - Include new message body format type in protocol logs, log time at whi...


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r753 committed - Include new message body format type in protocol logs, log time at whi...
  • Date: Tue, 01 Nov 2011 20:49:54 +0000

Revision: 753
Author:

Date: Tue Nov 1 13:49:11 2011
Log: Include new message body format type in protocol logs, log time at which test was run rather than time at which log ilfes were created per test, and protocl log name errors corrected
http://code.google.com/p/ndt/source/detail?r=753

Modified:
/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/web100clt.c

=======================================
--- /branches/kkumar_code_organize/src/logging.c Sun Oct 30 09:17:00
2011
+++ /branches/kkumar_code_organize/src/logging.c Tue Nov 1 13:49:11
2011
@@ -23,6 +23,7 @@
#include "testoptions.h"
#include "strlutils.h"
#include "utils.h"
+#include "protocol.h"

static int _debuglevel = 0;
static char* _programname = "";
@@ -254,7 +255,7 @@
ProtocolLogDirName);

}
-*/
+ */

/**
* Return the protocol validation log filename.
@@ -264,12 +265,12 @@
*/

char*
-get_protologfile(int socketNum) {
- char localAddr[64], remoteAddr[64], tmpstr[FILENAME_SIZE + 128];
+get_protologfile(int socketNum, char *protologfilename) {
+ char localAddr[64]="", remoteAddr[64]="";
size_t tmpstrlen = sizeof(localAddr);
memset(localAddr, 0, tmpstrlen);
memset(remoteAddr, 0, tmpstrlen);
- memset(tmpstr, 0, 384);
+
// get remote address
I2Addr tmp_addr =
I2AddrBySockFD(get_errhandle(), socketNum, False);
@@ -280,11 +281,12 @@

I2AddrNodeName(tmp_addr, localAddr, &tmpstrlen);

- // copy address into tmpstr String
- sprintf(tmpstr, "%s/%s%s%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX,
- localAddr, "_",remoteAddr, PROTOLOGSUFFIX,
"\0");
- //log_print(0, "Log file name ---%s---", tmpstr);
- return tmpstr;
+ // copy address into filename String
+ sprintf(protologfilename, "%s/%s%s%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX,
+ localAddr, "_",remoteAddr, PROTOLOGSUFFIX, "\0");
+ //log_print(0, "Log file name ---%s---", protologfilename);
+
+ return protologfilename;
}

/**
@@ -418,6 +420,7 @@

char logmessage[4096]; /* 4096 is just a random default buffer size for the protocol message
Ideally, twice the messsage size will suffice */
+ char tmplogname[FILENAME_SIZE];

if (!enableprotologging) {
log_println(5, "Protocol logging is not enabled");
@@ -427,14 +430,14 @@
// make delimiters in message payload explicit
quote_delimiters(value, strlen(value), logmessage,
sizeof(logmessage));

- fp = fopen(get_protologfile(socketnum), "a");
+ fp = fopen(get_protologfile(socketnum, tmplogname), "a");
if (fp == NULL) {
log_println(5,
"--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)));
+ get_currenttime(isotime, sizeof(isotime)));
fclose(fp);
}
}
@@ -459,6 +462,7 @@
char isotime[64];
char *currenttestname = "";
char *teststatusdesc = "";
+ char tmplogname[FILENAME_SIZE]="";

//get descriptive strings for test name and status
currenttestname = get_testnamedesc(testid, currenttestarr);
@@ -469,7 +473,7 @@
return;
}

- fp = fopen(get_protologfile(socketnum), "a");
+ fp = fopen(get_protologfile(socketnum, tmplogname), "a");
if (fp == NULL) {
log_println(
5,
@@ -479,7 +483,7 @@
sprintf(protomessage,
" event=\"%s\", name=\"%s\", pid=\"%d\",
time=\"%s\"\n",
teststatusdesc, currenttestname, pid,
- get_ISOtime(isotime, sizeof(isotime)));
+ get_currenttime(isotime, sizeof(isotime)));
fprintf(fp, "%s", protomessage);
fclose(fp);
}
@@ -508,6 +512,8 @@
char *procstatusdesc = "";
char *currenttestname = "";

+ char tmplogname[FILENAME_SIZE];
+
//get descriptive strings for test name and status
currenttestname = get_testnamedesc(testidarg, currenttestarr);
currentprocname = get_processtypedesc(procidarg, currentprocarr);
@@ -518,7 +524,7 @@
return;
}

- fp = fopen(get_protologfile(socketnum), "a");
+ fp = fopen(get_protologfile(socketnum, tmplogname), "a");

if (fp == NULL) {
printf(
@@ -534,7 +540,7 @@
protomessage,
" event=\"%s\", name=\"%s\", test=\"%s\", pid=\"%d\",
time=\"%s\"\n",
procstatusdesc, currentprocname,
currenttestname, pid,
- get_ISOtime(isotime, sizeof(isotime)));
+ get_currenttime(isotime, sizeof(isotime)));
fprintf(fp, "%s", protomessage);
fclose(fp);
}
@@ -546,6 +552,67 @@
void enableprotocollogging() {
enableprotologging = 1;
}
+
+/**
+ * Utility method to print binary value format of character data.
+ *
+ * @param charbinary 8 digit character that contains binary information
+ * @param binout_arr output array containing binary bits
+ */
+void printbinary(char *charbinary, int inarray_size, char *binout_arr, int outarr_size) {
+ int j = 7, i = 0;
+
+ if (inarray_size < 8 || outarr_size < 8 ) {
+ log_println(8, "Invalid array sizes while formatting protocol binary data. Quitting");
+ }
+
+ for (j = 7 ; j >= 0 && i < BITS_8; j--) {
+ if ((*charbinary & (1 << j)))
+ binout_arr[i] = '1';
+ else
+ binout_arr[i] = '0';
+ i++;
+ }
+ binout_arr[i] = '\0';
+}
+
+
+
+/**
+ * Utility method to get the message body type.
+ * Currently, messages are either composed of one character, holding unsigned data
+ * in the form of bits indicating the chosen tests, or in the form of strings.
+ * Also, currently, there is just one MSG_LOGIN message that carries bit data.
+ * Hence, message body type is based on these factors.
+ *
+ * @param type ProtocolMessage type
+ * @param len Length of message body
+ * @param msgbodytype Storage for Message body type description
+ * @param msgpayload message payload
+ * @param msgbits message payload altered per its format type (output buffer)
+ * @param sizemsgbits Output buffer size
+ * @return isbitfield
+ */
+int getMessageBodyFormat(int type, int len, char* msgbodytype, char* msgpayload, char* msgbits, int sizemsgbits) {
+ int isbitfielddata = 0;
+ enum MSG_BODY_TYPE msgbodyformat = NOT_KNOWN;
+
+ if (type == MSG_LOGIN && len ==1 ) {
+ msgbodyformat = BITFIELD;
+ strlcpy(msgbodytype, (char *)getmessageformattype(msgbodyformat,msgbodytype), MSG_BODY_FMT_SIZE );
+ printbinary (msgpayload, len, msgbits, sizemsgbits);
+ isbitfielddata = 1;
+ }
+ else {
+ msgbodyformat = STRING;
+ strlcpy(msgbodytype , (char *)getmessageformattype(msgbodyformat,msgbodytype), MSG_BODY_FMT_SIZE);
+ // make delimiters in message payload explicit
+ quote_delimiters(msgpayload, len, msgbits, sizemsgbits);
+
+ }
+ return isbitfielddata;
+
+}

/** Log all send/receive protocol messages.
* This method currently is called only internally, and thus
@@ -561,32 +628,33 @@
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 *currenttestname, *currentmsgtype, *currentbodyfmt;
char isotime[64];
char logmessage[4096]; // message after replacing delimiter characters
+ char protologfile[FILENAME_SIZE];
+ char msgbodytype[MSG_BODY_FMT_SIZE];
+ int is_bitmessage = 0;

// 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, len, logmessage, sizeof(logmessage));
-
- fp = fopen(get_protologfile(ctlSocket), "a");
+ is_bitmessage = getMessageBodyFormat(type, len, msgbodytype, (char *) msg, logmessage, sizeof(logmessage));
+
+ fp = fopen(get_protologfile(ctlSocket, protologfile), "a");
if (fp == NULL) {
log_println(
- 5,
+ 0,
"Unable to open protocol log file '%s', continuing
on without logging",
- get_protologfile(ctlSocket));
+ 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)));
+ " event=\"message\", direction=\"%s\", test=\"%s\", type=\"%s\", len=\"%d\", msg_body_format=\"%s\", msg=\"%s\", pid=\"%d\", socket=\"%d\", time=\"%s\"\n",
+ msgdirection, currenttestname, currentmsgtype, len, msgbodytype, logmessage,
+ processid, ctlSocket,
get_currenttime(isotime, sizeof(isotime)));
fclose(fp);
}
}
@@ -611,6 +679,7 @@
}
currentDir = get_currentdirndesc();

+ //printf("--sendprintln=%s;\n", (char *)msg); //to remove
protolog_println(currentDir, type, msg, len, processid, ctlSocket);
}

@@ -729,25 +798,18 @@
sprintf(day, "%d", result->tm_mday);
}

-/** Return a character string in the ISO8601 time foramt
- * used to create snaplog and trace file names
- *
- * Author: Rich Carlson - 5/6/09
- * @param Pointer to the string indicating ISO time
- * @param character string with ISO time string.
+
+/**
+ * Fill in ISOTime standard data
+ * @param result tm structure
+ * @param isoTime Char array to save ISO time in
+ * @param isotimearrsize array size of time output
+ * @return
*/

-char *
-get_ISOtime(char *isoTime, int isotimearrsize) {
-
- struct tm *result;
- time_t now;
+char *fill_ISOtime(struct tm *result, char *isoTime, int isotimearrsize) {
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);
@@ -790,6 +852,54 @@
return isoTime;
}

+/**
+ * Method to get current time
+ * @param isoTime array to store current time in
+ * @param isotimearrsize ISO time array size
+ * @return current time string
+ */
+char *get_currenttime(char *isoTime, int isotimearrsize) {
+ struct timeval now;
+ time_t timenow;
+ struct tm *result;
+ int rc;
+
+ struct timeval tv;
+
+ rc = gettimeofday(&now, NULL);
+
+ if(rc==0) {
+ timenow = now.tv_sec;
+ result = gmtime(&now);
+ //printf("gettimeofday() successful.\n");
+ //printf("time = %u.%06u\n",
+ // now.tv_sec, now.tv_usec);
+ return (fill_ISOtime(result, isoTime, isotimearrsize));
+ }
+ return NULL;
+}
+
+
+/** Return a character string in the ISO8601 time foramt
+ * used to create snaplog and trace file names
+ *
+ * Author: Rich Carlson - 5/6/09
+ * @param Pointer to the string indicating ISO time
+ * @param character string with ISO time string.
+ */
+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);
+
+ return (fill_ISOtime(result, isoTime, isotimearrsize));
+}
/**
* Write meta data out to log file. This file contains details and
* names of the other log files.
@@ -807,8 +917,8 @@
char tmpstr[256];
//char dir[128];
char dirpathstr[256]="";
- char *tempptr;
- int ptrdiff=0;
+ char *tempptr;
+ int ptrdiff=0;

//char isoTime[64];
char filename[256];
@@ -825,7 +935,7 @@
// get socketaddr size based on whether IPv6/IPV4 address was used
#ifdef AF_INET6
if (meta.family == AF_INET6)
- len = sizeof(struct sockaddr_in6);
+ len = sizeof(struct sockaddr_in6);
#endif
if (meta.family == AF_INET)
len = sizeof(struct sockaddr_in);
=======================================
--- /branches/kkumar_code_organize/src/logging.h Fri Oct 28 08:06:41
2011
+++ /branches/kkumar_code_organize/src/logging.h Tue Nov 1 13:49:11
2011
@@ -34,6 +34,7 @@
time_t get_timestamp();
long int get_utimestamp();
char * get_ISOtime(char * isoTime, int isoTimeArrSize);
+char *get_currenttime(char *isoTime, int isotimearrsize);
void get_YYYY(char * year);
void get_MM(char * month);
void get_DD(char * day);
@@ -79,7 +80,9 @@

void set_protologdir(char* dirname);
void set_protologfile(char* client_ip, char *protologfileparam);
-char* get_protologfile(int socketnum);
+//char* get_protologfile(int socketnum);
+char*
+get_protologfile(int socketNum, char *protologfilename) ;
char* get_protologdir();
void enableprotocollogging();
char *createprotologfilename(char* client_ip, char* textappendarg);
=======================================
--- /branches/kkumar_code_organize/src/ndtptestconstants.c Mon Oct 17 06:43:25 2011
+++ /branches/kkumar_code_organize/src/ndtptestconstants.c Tue Nov 1 13:49:11 2011
@@ -8,7 +8,7 @@
*/

#include <string.h>
-#include "ndtptests.h"
+#include "ndtptestconstants.h"

// The arrays below rely on the ordering of corresponding enum in the .h file.
// test names
@@ -28,6 +28,8 @@
static char *_txdirectionsarray[] = { "none", "client_to_server",
"server_to_client" };

+static char *_msgbodyformattype[] = { "bitfield", "string", "none" };
+
/**
* Get descriptive string for test name
* @param testid Id of the test
@@ -77,3 +79,14 @@
//printf ("--current test type = %s , for %d\n", smsgtypearg,
msgtype);
return smsgtypearg;
}
+
+/**
+ * Get descriptive name for message body format type
+ * @param bodymsgformat Message body format type
+ * @param smsgformattypearg descriptive string for message body format type
+ * @return
+ */
+char * getmessageformattype(enum MSG_BODY_TYPE bodymsgformat, char *smsgformattypearg) {
+ smsgformattypearg = _msgbodyformattype[bodymsgformat];
+ return smsgformattypearg;
+}
=======================================
--- /branches/kkumar_code_organize/src/ndtptestconstants.h Sun Oct 23 19:27:44 2011
+++ /branches/kkumar_code_organize/src/ndtptestconstants.h Tue Nov 1 13:49:11 2011
@@ -19,6 +19,7 @@
#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" */
+#define MSG_BODY_FMT_SIZE 10 /* max size for desc "NOT_KNOWN" */

// port numbers
#define PORT "3001"
@@ -42,10 +43,15 @@
NO_DIR, C_S, S_C
} txdirection;

+enum MSG_BODY_TYPE {
+ BITFIELD, STRING, NOT_KNOWN
+} bodyformattype;
+
char *get_testnamedesc(enum TEST_ID testid, char *stestnamearg);
char *get_teststatusdesc(enum TEST_STATUS_INT teststatus, char *steststatusarg);
char *get_testdirectiondesc(enum Tx_DIRECTION testdirection,
char *stestdirectionarg);
char *get_msgtypedesc(int msgtypearg, char *smsgtypearg);
+char * getmessageformattype(enum MSG_BODY_TYPE bodymsgformat, char *smsgformattypearg) ;

#endif
=======================================
--- /branches/kkumar_code_organize/src/web100clt.c Sun Oct 30 09:17:00
2011
+++ /branches/kkumar_code_organize/src/web100clt.c Tue Nov 1 13:49:11
2011
@@ -523,7 +523,7 @@
host = optarg;
break;
case 'u':
- set_protologdir(optarg);
+ set_protologdir(strdup(optarg));
break;
case 'e':
enableprotocollogging();


  • [ndt-dev] [ndt] r753 committed - Include new message body format type in protocol logs, log time at whi..., ndt, 11/01/2011

Archive powered by MHonArc 2.6.16.

Top of Page