ndt-dev - [ndt-dev] [ndt] r1052 committed - Changed tests specific methods to use JSON format
Subject: NDT-DEV email list created
List archive
[ndt-dev] [ndt] r1052 committed - Changed tests specific methods to use JSON format
Chronological Thread
- From:
- To:
- Subject: [ndt-dev] [ndt] r1052 committed - Changed tests specific methods to use JSON format
- Date: Tue, 13 May 2014 13:53:14 +0000
Revision: 1052
Author:
Date: Tue May 13 13:52:22 2014 UTC
Log: Changed tests specific methods to use JSON format
http://code.google.com/p/ndt/source/detail?r=1052
Added:
/branches/Issue145/src/jsonutils.c
/branches/Issue145/src/jsonutils.h
Modified:
/branches/Issue145/configure.ac
/branches/Issue145/src/Makefile.am
/branches/Issue145/src/clt_tests.h
/branches/Issue145/src/ndtptestconstants.h
/branches/Issue145/src/network.c
/branches/Issue145/src/network.h
/branches/Issue145/src/test_c2s_clt.c
/branches/Issue145/src/test_c2s_srv.c
/branches/Issue145/src/test_meta.h
/branches/Issue145/src/test_meta_clt.c
/branches/Issue145/src/test_meta_srv.c
/branches/Issue145/src/test_mid_clt.c
/branches/Issue145/src/test_mid_srv.c
/branches/Issue145/src/test_s2c_clt.c
/branches/Issue145/src/test_s2c_srv.c
/branches/Issue145/src/test_sfw.h
/branches/Issue145/src/test_sfw_clt.c
/branches/Issue145/src/test_sfw_srv.c
/branches/Issue145/src/testoptions.c
/branches/Issue145/src/testoptions.h
/branches/Issue145/src/web100-util.c
/branches/Issue145/src/web100clt.c
/branches/Issue145/src/web100srv.h
=======================================
--- /dev/null
+++ /branches/Issue145/src/jsonutils.c Tue May 13 13:52:22 2014 UTC
@@ -0,0 +1,170 @@
+/*
+ * This file contains functions to handle json messages.
+ * Jansson library is used for encoding/decoding JSON strings.
+ * See http://www.digip.org/jansson/ for more details.
+ *
+ * Sebastian Kostuch 2014-04-30
+ *
+ */
+
+#include <jansson.h>
+#include <string.h>
+#include "jsonutils.h"
+
+/**
+ * Creates string representing JSON object with single key:value pair
+ * where key is default and value is being taken from parameter.
+ *
+ * @param value null-terminated string containing value of map entry
+ * @return encoded JSON string
+ */
+char* json_create_from_single_value(const char* value) {
+ json_t *root;
+
+ root = json_object();
+ json_object_set_new(root, DEFAULT_KEY, json_string(value));
+
+ char* ret = json_dumps(root, 0);
+ json_decref(root);
+
+ return ret;
+}
+
+/**
+ * Creates string representing JSON object with multiple key:value pairs
+ * where keys are taken from "keys" parameter (separated by "keys_separator"
+ * character) and values are taken from "values" parameter (separated by
+ * "values_separator" character). Number of elements in both keys and values
+ * should match.
+ *
+ * @param keys null-terminated string containing keys for JSON map entries
+ * @param keys_delimiters characters by which keys are separated
+ * @param values null-terminated string containing values for JSON map entries
+ * @param values_delimiters characters by which values are separated
+ * @return encoded JSON string
+ */
+char* json_create_from_multiple_values(const char *keys, const char *keys_delimiters,
+ const char *values, char *values_delimiters) {
+ json_t *root;
+ char keysbuff[8192], valuesbuff[8192];
+ char *saveptr1, *saveptr2;
+
+ root = json_object();
+ strncpy(keysbuff, keys, strlen(keys));
+ keysbuff[strlen(keys)] = '\0';
+
+ strncpy(valuesbuff, values, strlen(values));
+ valuesbuff[strlen(values)] = '\0';
+
+ char *keyToken = strtok_r(keysbuff, keys_delimiters, &saveptr1);
+ char *valueToken = strtok_r(valuesbuff, values_delimiters, &saveptr2);
+
+ while (keyToken && valueToken) {
+ json_object_set_new(root, keyToken, json_string(valueToken));
+
+ keyToken = strtok_r(NULL, keys_delimiters, &saveptr1);
+ valueToken = strtok_r(NULL, values_delimiters, &saveptr2);
+ }
+
+ char* ret = json_dumps(root, 0);
+ json_decref(root);
+
+ return ret;
+}
+
+/**
+ * Creates string representing JSON object with proper key:value pairs.
+ * Keys and values are taken from parameter and are separated by colon
+ * while pairs are separated by new line character, e.g.:
+ * key1: value1
+ * key2: value2
+ *
+ * @param pairs null-terminated string containing key:value pairs
+ * @return encoded JSON string
+ */
+char* json_create_from_key_value_pairs(const char* pairs) {
+ json_t *root;
+ char key[1024], value[1024], buff[8192];
+ int i;
+ char *saveptr;
+
+ root = json_object();
+ strncpy(buff, pairs, strlen(pairs));
+ buff[strlen(pairs)] = '\0';
+ char *token = strtok_r(buff, "\n", &saveptr);
+
+ while (token) {
+ i = strcspn(token, ":");
+ strncpy(key, token, i);
+ key[i] = '\0';
+ while(isspace(token[i+1])) { // skip whitespace characters from beginning of value if any
+ i++;
+ }
+ strncpy(value, token+i+1, strlen(token)-i);
+ value[strlen(token)-i] = '\0';
+ json_object_set_new(root, key, json_string(value));
+ token = strtok_r(NULL, "\n", &saveptr);
+ }
+
+ char* ret = json_dumps(root, 0);
+ json_decref(root);
+
+ return ret;
+}
+
+/**
+ * Reads value from JSON object represented by jsontext using specific key
+ *
+ * @param jsontext string representing JSON object
+ * @param key by which value should be obtained from JSON map
+ */
+char* json_read_map_value(const char *jsontext, const char *key) {
+ json_t *root;
+ json_error_t error;
+ json_t *data;
+
+ root = json_loads(jsontext, 0, &error);
+
+ if(!root)
+ {
+ log_println(0, "Error while reading value from JSON string: %s", error.text);
+ return NULL;
+ }
+
+ if(!json_is_object(root))
+ {
+ log_println(0, "Error while reading value from JSON string: root is not an object");
+ json_decref(root);
+ return NULL;
+ }
+
+ data = json_object_get(root, key);
+ if(data != NULL)
+ {
+ char *value = json_string_value(data);
+
+ return value;
+ }
+ else
+ return NULL;
+}
+
+/**
+ * Checks if given msg has correct JSON format
+ * @param msg message to check for correct JSON format
+ * @return 0 if msg is correct JSON message
+ * -1 otherwise
+ */
+int json_check_msg(const char* msg) {
+ json_t *root;
+ json_error_t error;
+
+ root = json_loads(msg, 0, &error);
+
+ if(!root)
+ {
+ return -1;
+ }
+
+ return 0;
+}
=======================================
--- /dev/null
+++ /branches/Issue145/src/jsonutils.h Tue May 13 13:52:22 2014 UTC
@@ -0,0 +1,26 @@
+/*
+ * This file contains function declarations to handle json messages
+ *
+ * Sebastian Kostuch 2014-04-30
+ *
+ */
+
+#ifndef SRC_JSONUTILS_H_
+#define SRC_JSONUTILS_H_
+
+#include <jansson.h>
+#include <string.h>
+
+#define JSON_SINGLE_VALUE 1
+#define JSON_MULTIPLE_VALUES 2
+#define JSON_KEY_VALUE_PAIRS 3
+#define DEFAULT_KEY "msg"
+
+char* json_create_from_single_value(const char* value);
+char* json_create_from_multiple_values(const char *keys, const char *keys_delimiters,
+ const char *values, char *values_delimiters);
+char* json_create_from_key_value_pairs(const char* pairs);
+char* json_read_map_value(const char *jsontext, const char *key);
+int json_check_msg(const char* msg);
+
+#endif // SRC_JSONUTILS_H_
=======================================
--- /branches/Issue145/configure.ac Mon Mar 24 08:50:46 2014 UTC
+++ /branches/Issue145/configure.ac Tue May 13 13:52:22 2014 UTC
@@ -233,6 +233,16 @@
AM_CONDITIONAL(HAVE_PCAP_H, false)
fi
+AC_CHECK_HEADER(jansson.h, [] [b=0])
+if test $b == 0
+then
+ JSONLIB="-ljansson"
+ AC_DEFINE(HAVE_JANSSON_H, 1, [Have JANSSON header file.])
+ AM_CONDITIONAL(HAVE_JANSSON_H, true)
+else
+ AM_CONDITIONAL(HAVE_JANSSON_H, false)
+fi
+
AC_CHECK_LIB([z], [deflateInit_],
[
ZLIB="-lz"
@@ -283,6 +293,7 @@
AC_SUBST(NDTLIBDIR)
AC_SUBST(NDTINCDIR)
AC_SUBST(ZLIB)
+AC_SUBST(JSONLIB)
AC_SUBST(TOP_BUILD_DIRS)
@@ -355,8 +366,13 @@
if test -z "$HAVE_WEB10G_TRUE" && test -n "$HAVE_WEB10G_FALSE"; then
if test -z "$HAVE_PCAP_H_TRUE" && test -n "$HAVE_PCAP_H_FALSE"; then
+if test -z "$HAVE_JANSSON_H_TRUE" && test -n "$HAVE_JANSSON_H_FALSE"; then
SUMMARY_WEB10GSRV="YES"
SUMMARY_GENPLOT10G="YES"
+else
+ SUMMARY_GENPLOT10G="YES"
+ SUMMARY_WEB10GSRV="NO (missing jansson headers)"
+fi
else
SUMMARY_GENPLOT10G="YES"
SUMMARY_WEB10GSRV="NO (missing pcap headers)"
@@ -366,10 +382,19 @@
SUMMARY_GENPLOT10G="NO (missing web10g userland library >=2.0.6.2)"
fi
-SUMMARY_WEB100CLT="YES"
+if test -z "$HAVE_JANSSON_H_TRUE" && test -n "$HAVE_JANSSON_H_FALSE"; then
+ SUMMARY_WEB100CLT="YES"
+else
+ SUMMARY_WEB100CLT="NO (missing jansson headers)"
+fi
+
if test -z "$HAVE_WEB100_TRUE" && test -n "$HAVE_WEB100_FALSE"; then
if test -z "$HAVE_PCAP_H_TRUE" && test -n "$HAVE_PCAP_H_FALSE"; then
+if test -z "$HAVE_JANSSON_H_TRUE" && test -n "$HAVE_JANSSON_H_FALSE"; then
SUMMARY_WEB100SRV="YES"
+else
+SUMMARY_WEB100SRV="NO (missing jansson headers)"
+fi
else
SUMMARY_WEB100SRV="NO (missing pcap headers)"
fi
@@ -451,3 +476,5 @@
echo "* Admin.class: ${SUMMARY_ADMINCLASS}"
echo ""
echo ""
+
+
=======================================
--- /branches/Issue145/src/Makefile.am Mon Mar 24 08:50:46 2014 UTC
+++ /branches/Issue145/src/Makefile.am Tue May 13 13:52:22 2014 UTC
@@ -49,8 +49,8 @@
web100clt_SOURCES = web100clt.c network.c usage.c logging.c utils.c protocol.c runningtest.c ndtptestconstants.c \
test_sfw_clt.c test_mid_clt.c test_c2s_clt.c test_s2c_clt.c test_meta_clt.c strlutils.c \
- test_results_clt.c
-web100clt_LDADD = $(I2UTILLIBDEPS) -lpthread $(ZLIB)
+ test_results_clt.c jsonutils.c
+web100clt_LDADD = $(I2UTILLIBDEPS) -lpthread $(ZLIB) $(JSONLIB)
web100clt_CPPFLAGS ='-DBASEDIR="$(ndtdir)"'
web100clt_DEPENDENCIES = $(I2UTILLIBDEPS)
@@ -76,18 +76,18 @@
web100srv_SOURCES = web100srv.c web100-util.c web100-pcap.c web100-admin.c runningtest.c \
network.c usage.c utils.c mrange.c logging.c testoptions.c ndtptestconstants.c \
protocol.c test_sfw_srv.c test_meta_srv.c ndt_odbc.c strlutils.c heuristics.c \
- test_c2s_srv.c test_s2c_srv.c test_mid_srv.c
+ test_c2s_srv.c test_s2c_srv.c test_mid_srv.c jsonutils.c
web100srv_LDFLAGS = $(NDTLDFLAGS) $(I2UTILLDFLAGS)
-web100srv_LDADD = $(NDTLIBS) $(I2UTILLIBS) $(I2UTILLIBDEPS) -lpthread $(ZLIB)
+web100srv_LDADD = $(NDTLIBS) $(I2UTILLIBS) $(I2UTILLIBDEPS) -lpthread $(ZLIB) $(JSONLIB)
web100srv_CPPFLAGS ='-DBASEDIR="$(ndtdir)"' -DFORCE_WEB100
web100srv_DEPENDENCIES = $(I2UTILLIBDEPS)
web10gsrv_SOURCES = web100srv.c web100-util.c web100-pcap.c web100-admin.c runningtest.c \
network.c usage.c utils.c mrange.c logging.c testoptions.c ndtptestconstants.c \
protocol.c test_sfw_srv.c test_meta_srv.c ndt_odbc.c strlutils.c heuristics.c \
- test_c2s_srv.c test_s2c_srv.c test_mid_srv.c web10g-util.c
+ test_c2s_srv.c test_s2c_srv.c test_mid_srv.c web10g-util.c jsonutils.c
web10gsrv_LDFLAGS = $(NDTLDFLAGS) $(I2UTILLDFLAGS)
-web10gsrv_LDADD = $(NDTLIBS) $(I2UTILLIBS) $(I2UTILLIBDEPS) -lpthread $(ZLIB)
+web10gsrv_LDADD = $(NDTLIBS) $(I2UTILLIBS) $(I2UTILLIBDEPS) -lpthread $(ZLIB) $(JSONLIB)
web10gsrv_CPPFLAGS = '-DBASEDIR="$(ndtdir)"'
web10gsrv_DEPENDENCIES = $(I2UTILLIBDEPS)
=======================================
--- /branches/Issue145/src/clt_tests.h Thu Nov 15 21:33:44 2012 UTC
+++ /branches/Issue145/src/clt_tests.h Tue May 13 13:52:22 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the function declarations to handle client's
* parts of the various tests.
*
- * Jakub S³awiñski 2006-08-02
+ * Jakub S�awi�ski 2006-08-02
*
*/
@@ -14,10 +14,10 @@
#define MIDBOX_TEST_RES_SIZE 512
int test_mid_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size, char* tmpstr2);
+ int buf_size, char* tmpstr2, int jsonSupport);
int test_c2s_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size);
+ int buf_size, int jsonSupport);
int test_s2c_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size, char* tmpstr);
+ int buf_size, char* tmpstr, int jsonSupport);
#endif // SRC_CLT_TESTS_H_
=======================================
--- /branches/Issue145/src/ndtptestconstants.h Thu Nov 15 21:33:44 2012 UTC
+++ /branches/Issue145/src/ndtptestconstants.h Tue May 13 13:52:22 2014 UTC
@@ -33,6 +33,13 @@
#define PORT3 "3003"
#define PORT4 "3003"
+// keys' names used for storing specific data in JSON format
+#define SERVER_ADDRESS "ServerAddress"
+#define CLIENT_ADDRESS "ClientAddress"
+#define CUR_MSS "CurMSS"
+#define WIN_SCALE_SENT "WinScaleSent"
+#define WIN_SCALE_RCVD "WinScaleRcvd"
+
// status of tests. Used mainly to log a "textual" explanation using below array
enum TEST_STATUS_INT {
TEST_NOT_STARTED, TEST_STARTED, TEST_INPROGRESS, TEST_INCOMPLETE, TEST_ENDED
=======================================
--- /branches/Issue145/src/network.c Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue145/src/network.c Tue May 13 13:52:22 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the functions needed to handle network related
* stuff.
*
- * Jakub S³awiñski 2006-05-30
+ * Jakub S�awi�ski 2006-05-30
*
*/
@@ -10,6 +10,7 @@
#include <netdb.h>
#include <string.h>
#include <unistd.h>
+#include "jsonutils.h"
#include "network.h"
#include "logging.h"
@@ -368,18 +369,93 @@
}
/**
- * Sends the protocol message to the control socket.
+ * Converts message to JSON format and sends it to the control socket.
* @param ctlSocket control socket
* @param type type of the message
* @param msg message to send
* @param len length of the message
+ * @param jsonSupport indicates if JSON format is supported by second side (if not
+ * then msg is being sent as it is and
no JSON converting is done)
+ * @param jsonConvertType defines how message converting should be handled:
+ * JSON_SINGLE_VALUE: single key/value pair is being created (using default key)
+ * with msg as value
+ * JSON_MULTIPLE_VALUES: multiple key/values pairs are being created using
+ * keys, keys_delimiters, values and values_delimiters
+ * params
+ * JSON_KEY_VALUE_PAIRS: given message contains one or many key/value pairs
+ * with following syntax: key1: value1
+ * key2: value2 etc
+ * @param keys buffer containing keys' values (used only when jsonConvertType is set to
+ * JSON_MULTIPLE_VALUES)
+ * @param keysDelimiters delimiters for keys parameter (used only when jsonConvertType is set to
+ * JSON_MULTIPLE_VALUES)
+ * @param values buffer containing map values, key-value matching is being done by order in which
+ * they appear in keys and values params (used only when jsonConvertType is set to
+ * JSON_MULTIPLE_VALUES)
+ * @param valuesDelimiters delimiters for values parameter (used only when jsonConvertType is
+ * set to JSON_MULTIPLE_VALUES)
+ *
* @return 0 on success, error code otherwise
* Error codes:
* -1 - Cannot write to socket at all
* -2 - Cannot complete writing full message data into socket
* -3 - Cannot write after retries
+ * -4 - Cannot convert msg to JSON
*
*/
+int send_json_msg(int ctlSocket, int type, const char* msg, int len, int jsonSupport,
+ int jsonConvertType, const char *keys, const char
*keysDelimiters,
+ const char *values, char *valuesDelimiters) {
+ char* tempBuff;
+ int ret = 0;
+ // if JSON is not supported by second side, sends msg as it is
+ if (!jsonSupport) {
+ return send_msg(ctlSocket, type, msg, len);
+ }
+
+ switch(jsonConvertType) {
+ case JSON_SINGLE_VALUE:
+ tempBuff = json_create_from_single_value(msg); break;
+ case JSON_MULTIPLE_VALUES:
+ tempBuff = json_create_from_multiple_values(keys, keysDelimiters,
+ values, valuesDelimiters); break;
+ case JSON_KEY_VALUE_PAIRS:
+ tempBuff = json_create_from_key_value_pairs(msg); break;
+ default:
+ return send_msg(ctlSocket, type, msg, len);
+ }
+
+ if (!tempBuff) {
+ return -4;
+ }
+ ret = send_msg(ctlSocket, type, tempBuff, strlen(tempBuff));
+ free(tempBuff);
+ return ret;
+}
+
+/**
+ * Shortest version of send_json_msg method. Uses default NULL values for JSON_MULTIPLE_VALUES
+ * convert type specific parameters.
+ */
+int send_json_message(int ctlSocket, int type, const char* msg, int len, int jsonSupport,
+ int jsonConvertType) {
+ return send_json_msg(ctlSocket, type, msg, len, jsonSupport, jsonConvertType,
+ NULL, NULL, NULL, NULL);
+}
+
+/**
+ * Sends the protocol message to the control socket.
+ * @param ctlSocket control socket
+ * @param type type of the message
+ * @param msg message to send
+ * @param len length of the message
+ * @return 0 on success, error code otherwise
+ * Error codes:
+ * -1 - Cannot write to socket at all
+ * -2 - Cannot complete writing full message data into socket
+ * -3 - Cannot write after retries
+ */
+
int send_msg(int ctlSocket, int type, const void* msg, int len) {
unsigned char buff[3];
=======================================
--- /branches/Issue145/src/network.h Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue145/src/network.h Tue May 13 13:52:22 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the definitions and function declarations to
* handle network related stuff.
*
- * Jakub S³awiñski 2006-05-30
+ * Jakub S�awi�ski 2006-05-30
*
*/
@@ -20,6 +20,11 @@
I2Addr CreateListenSocket(I2Addr addr, char* serv, int options, int buf_size);
int CreateConnectSocket(int* sockfd, I2Addr local_addr, I2Addr server_addr,
int option, int buf_sizes);
+int send_json_msg(int ctlSocket, int type, const char* msg, int len, int jsonSupport,
+ int jsonConvertType, const char *keys, const char *keysDelimiters,
+ const char *values, char *valuesDelimiters);
+int send_json_message(int ctlSocket, int type, const char* msg, int len, int jsonSupport,
+ int jsonConvertType);
int send_msg(int ctlSocket, int type, const void* msg, int len);
int recv_msg(int ctlSocket, int* type, void* msg, int* len);
int writen(int fd, const void* buf, int amount);
=======================================
--- /branches/Issue145/src/test_c2s_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /branches/Issue145/src/test_c2s_clt.c Tue May 13 13:52:22 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the functions needed to handle C2S throughput
* test (client part).
*
- * Jakub S³awiñski 2006-08-02
+ * Jakub S�awi�ski 2006-08-02
*
*/
@@ -17,6 +17,7 @@
#include "network.h"
#include "protocol.h"
#include "utils.h"
+#include "jsonutils.h"
int pkts, lth;
int sndqueue;
@@ -31,6 +32,7 @@
* @param host Server name string
* @param conn_options Options to use while connecting to server(for ex, IPV4)
* @param buf_size TCP send/receive buffer size
+ * @param jsonSupport Indicates if messages should be send using JSON format
* @return integer > 0 if successful, < 0 in case of error
* Return codes:
* 1: Error receiving protocol message
@@ -42,12 +44,13 @@
*
*/
int test_c2s_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size) {
+ int buf_size, int jsonSupport) {
/* char buff[BUFFSIZE+1]; */
char buff[64 * KILO_BITS]; // message payload.
// note that there is a size variation between server and CLT - do not
// know why this was changed from BUFFZISE, though
// no specific problem is seen due to this
+ char* jsonMsgValue; // temporary buffer for storing values from JSON message
int msgLen, msgType; // message related data
int c2sport = atoi(PORT2); // default C2S port
@@ -83,6 +86,13 @@
msgLen)) {
return 2;
}
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
@@ -90,7 +100,6 @@
// Server sends port number to bind to in the TEST_PREPARE. Check if this
// message body (string) is a valid integral port number.
- buff[msgLen] = 0;
if (check_int(buff, &c2sport)) {
log_println(0, "Invalid port number");
return 4;
@@ -187,7 +196,14 @@
buff[msgLen] = 0;
// get C->S test speed as calculated by server
- c2sspd = atoi(buff);
+ if (json_check_msg(buff) == 0) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ c2sspd = atoi(jsonMsgValue);
+ free(jsonMsgValue);
+ }
+ else {
+ c2sspd = atoi(buff);
+ }
// Print results in the most convenient units (kbps or Mbps)
if (c2sspd < KILO)
=======================================
--- /branches/Issue145/src/test_c2s_srv.c Wed Mar 12 06:27:30 2014 UTC
+++ /branches/Issue145/src/test_c2s_srv.c Tue May 13 13:52:22 2014 UTC
@@ -20,6 +20,7 @@
#include "protocol.h"
#include "network.h"
#include "mrange.h"
+#include "jsonutils.h"
/**
* Perform the C2S Throughput test. This test intends to measure throughput
@@ -51,7 +52,7 @@
* >0 - error code
* Error codes:
* -1 - Listener socket creation failed
- * -100 - timeout while waiting for client to connect to serverÕs ephemeral port
+ * -100 - timeout while waiting for client to connect to server�s ephemeral port
* -errno - Other specific socket error numbers
* -101 - Retries exceeded while waiting for client to
connect
* -102 - Retries exceeded while waiting for data from
connected client
@@ -150,7 +151,7 @@
sizeof(buff),
"Server (C2S throughput test): CreateListenSocket failed: %s",
strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff), testOptions->json_support, JSON_SINGLE_VALUE);
return -1;
}
@@ -175,8 +176,8 @@
// send TEST_PREPARE message with ephemeral port detail, indicating start
// of tests
- if ((msgretvalue = send_msg(ctlsockfd, TEST_PREPARE, buff,
- strlen(buff))) < 0) {
+ if ((msgretvalue = send_json_message(ctlsockfd, TEST_PREPARE, buff,
+ strlen(buff), testOptions->json_support, JSON_SINGLE_VALUE)) < 0) {
return msgretvalue;
}
@@ -317,7 +318,7 @@
sleep(2);
// send empty TEST_START indicating start of the test
- send_msg(ctlsockfd, TEST_START, "", 0);
+ send_json_message(ctlsockfd, TEST_START, "", 0, testOptions->json_support, JSON_SINGLE_VALUE);
/* alarm(30); */ // reset alarm() again, this 10 sec test should finish
// before this signal is generated.
@@ -373,7 +374,7 @@
testOptions->child0);
log_println(1, "%s", buff);
snprintf(buff, sizeof(buff), "%0.0f", *c2sspd);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff), testOptions->json_support, JSON_SINGLE_VALUE);
// get receiver side Web100 stats and write them to the log file. close
// sockets
@@ -440,7 +441,7 @@
}
// An empty TEST_FINALIZE message is sent to conclude the test
- send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
+ send_json_message(ctlsockfd, TEST_FINALIZE, "", 0, testOptions->json_support, JSON_SINGLE_VALUE);
// Close opened resources for packet capture
if (getuid() == 0) {
=======================================
--- /branches/Issue145/src/test_meta.h Thu Nov 15 21:33:44 2012 UTC
+++ /branches/Issue145/src/test_meta.h Tue May 13 13:52:22 2014 UTC
@@ -16,6 +16,6 @@
#define META_TEST_LOG "META test"
-int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options);
+int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options, int jsonSupport);
#endif // SRC_TEST_META_H_
=======================================
--- /branches/Issue145/src/test_meta_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /branches/Issue145/src/test_meta_clt.c Tue May 13 13:52:22 2014 UTC
@@ -19,6 +19,7 @@
#include "network.h"
#include "protocol.h"
#include "utils.h"
+#include "jsonutils.h"
int pkts, lth;
int sndqueue;
@@ -31,13 +32,14 @@
* @param tests set of tests to perform
* @param host hostname of the server
* @param conn_options connection options
+ * @param jsonSupport indicates if messages should be send using JSON format
* @return integer
* 0 = (the test has been finalized)
* >0 if protocol interactions were not as expected:
* 1: Unable to receive protocol message successfully
* 2: Wrong message type received
*/
-int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options) {
+int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options, int jsonSupport) {
char buff[1024], tmpBuff[512];
int msgLen, msgType;
FILE * fp;
@@ -83,7 +85,8 @@
fflush(stdout);
snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_APPLICATION, "cli");
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);
// send client os name details
if ((fp = fopen("/proc/sys/kernel/ostype", "r")) == NULL) {
log_println(0, "Unable to determine client os type.");
@@ -91,12 +94,14 @@
fscanf(fp, "%s", tmpBuff);
fclose(fp);
snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_OS, tmpBuff);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);
}
// send client browser name
snprintf(buff, sizeof(buff), "%s:%s", META_BROWSER_OS, "- (web100clt)");
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);
// send client kernel version
if ((fp = fopen("/proc/sys/kernel/osrelease", "r")) == NULL) {
@@ -106,16 +111,18 @@
fclose(fp);
snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_KERNEL_VERSION,
tmpBuff);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);
}
// send NDT client version
snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_VERSION, VERSION);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);
// Client can send any number of such meta data in a TEST_MSG
// .. format, and signal the end of the transmission using an empty TEST_MSG
- send_msg(ctlSocket, TEST_MSG, "", 0);
+ send_json_message(ctlSocket, TEST_MSG, "", 0, jsonSupport, JSON_SINGLE_VALUE);
printf("Done\n");
=======================================
--- /branches/Issue145/src/test_meta_srv.c Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue145/src/test_meta_srv.c Tue May 13 13:52:22 2014 UTC
@@ -18,6 +18,7 @@
#include "protocol.h"
#include "utils.h"
#include "testoptions.h"
+#include "jsonutils.h"
/**
* Performs the META test.
@@ -44,7 +45,7 @@
int msgLen, msgType;
char buff[BUFFSIZE + 1];
struct metaentry *new_entry = NULL;
- char* value;
+ char* value, *jsonMsgValue;
// protocol validation logs
enum TEST_ID testids = META;
@@ -59,14 +60,16 @@
protolog_status(testOptions->child0, testids, teststatuses, ctlsockfd);
// first message exchanged is am empty TEST_PREPARE message
- j = send_msg(ctlsockfd, TEST_PREPARE, "", 0);
+ j = send_json_message(ctlsockfd, TEST_PREPARE, "", 0,
+ testOptions->json_support, JSON_SINGLE_VALUE);
if (j == -1 || j == -2) { // Cannot write message headers/data
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) {
+ if (send_json_message(ctlsockfd, TEST_START, "", 0,
+ testOptions->json_support, JSON_SINGLE_VALUE) < 0) {
log_println(6, "META test - Test-start message failed");
}
@@ -79,7 +82,8 @@
log_println(0, "Protocol error!");
snprintf(buff, sizeof(buff),
"Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return 1;
}
if (check_msg_type("META test", TEST_MSG, msgType, buff, msgLen)) {
@@ -87,7 +91,8 @@
log_println(0, "Fault, unexpected message received!");
snprintf(buff, sizeof(buff),
"Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return 2;
}
if (msgLen < 0) {
@@ -95,9 +100,21 @@
log_println(0, "Improper message");
snprintf(buff, sizeof(buff),
"Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return 3;
}
+
+ buff[msgLen] = 0;
+ if (testOptions->json_support) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ if (strlen(jsonMsgValue) == 0) {
+ free(jsonMsgValue);
+ break;
+ }
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ free(jsonMsgValue);
+ }
// Received empty TEST_MSG. All meta_data has been received, and test
// can be finalized.
@@ -105,13 +122,13 @@
break;
}
- buff[msgLen] = 0;
value = index(buff, ':');
if (value == NULL) { // key-value separates by ":"
log_println(0, "Improper message");
snprintf(buff, sizeof(buff), "Server (META test): "
"Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return 4;
}
*value = 0;
@@ -153,7 +170,8 @@
new_entry->next = NULL; // ensure meta list ends here
// Finalize test by sending appropriate message, and setting status
- if (send_msg(ctlsockfd, TEST_FINALIZE, "", 0) < 0) {
+ if (send_json_message(ctlsockfd, TEST_FINALIZE, "", 0,
+ testOptions->json_support, JSON_SINGLE_VALUE) < 0) {
log_println(6, "META test - failed to send finalize message");
}
=======================================
--- /branches/Issue145/src/test_mid_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /branches/Issue145/src/test_mid_clt.c Tue May 13 13:52:22 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the functions needed to handle Middlebox
* test (client part).
*
- * Jakub S³awiñski 2006-08-02
+ * Jakub S�awi�ski 2006-08-02
*
*/
@@ -16,6 +16,7 @@
#include "protocol.h"
#include "utils.h"
#include "strlutils.h"
+#include "jsonutils.h"
/**
* Perform the client part of the middleBox testing. The middlebox test
@@ -29,6 +30,7 @@
* @param buf_size TCP send/receive buffer size
* @param testresult_str result obtained from server (containing server ip,
* client ip, currentMSS,
WinSCaleSent, WinScaleRcvd)
+ * @param jsonSupport Indicates if messages should be sent using JSON format
* @return integer
* => 0 on success
* < 0 if error
@@ -46,7 +48,7 @@
*
*/
int test_mid_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size, char* testresult_str) {
+ int buf_size, char* testresult_str, int jsonSupport) {
char buff[BUFFSIZE + 1];
int msgLen, msgType;
int midport = atoi(PORT3);
@@ -57,6 +59,7 @@
uint32_t bytes;
struct timeval sel_tv;
fd_set rfd;
+ char* jsonMsgValue;
enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
enum TEST_ID testids = MIDDLEBOX;
@@ -84,11 +87,17 @@
// The server is expected to send a message with a valid payload that
// contains the port number that server wants client to bind to for this
// test
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
}
- buff[msgLen] = 0;
if (check_int(buff, &midport)) { // obtained message does not contain
// integer port#
log_println(0, "Invalid port number");
@@ -168,6 +177,7 @@
msgLen)) {
return 2;
}
+ buff[msgLen] = 0;
strlcat(testresult_str, buff, MIDBOX_TEST_RES_SIZE);
@@ -178,7 +188,7 @@
log_println(4, "CWND limited speed = %0.2f kbps", spdin);
// client now sends throughput it calculated above to server, as a TEST_MSG
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff), jsonSupport, JSON_SINGLE_VALUE);
printf("Done\n");
I2AddrFree(sec_addr);
=======================================
--- /branches/Issue145/src/test_mid_srv.c Fri Mar 21 07:54:57 2014 UTC
+++ /branches/Issue145/src/test_mid_srv.c Tue May 13 13:52:22 2014 UTC
@@ -24,6 +24,7 @@
#include "protocol.h"
#include "network.h"
#include "mrange.h"
+#include "jsonutils.h"
/**
* Perform the Middlebox test.
@@ -38,14 +39,14 @@
* Error codes:
* -1 - Listener socket creation failed
* -3 - tcp_stat connection data not obtained
- * -100 - timeout while waiting for client to connect to serverÕs ephemeral port
+ * -100 - timeout while waiting for client to connect to server�s ephemeral port
* -errno- Other specific socket error numbers
* -101 - Retries exceeded while waiting for
client to connect
* -102 - Retries exceeded while waiting for
data from connected client
* Other used return codes:
* 1 - Message reception errors/inconsistencies
* 2 - Unexpected message type received/no message received due to timeout
- * 3 Ð Received message is invalid
+ * 3 � Received message is invalid
*
*/
@@ -70,6 +71,8 @@
char tmpstr[256]; // temporary string storage
struct timeval sel_tv; // time
fd_set rfd; // receiver file descriptor
+ char results_keys[BUFFSIZE + 1];
+ char *jsonMsgValue;
// variables used for protocol validation logging
enum TEST_ID thistestId = NONE;
@@ -153,7 +156,8 @@
snprintf(buff, sizeof(buff),
"Server (Middlebox test): CreateListenSocket failed: %s",
strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
return -1;
}
@@ -164,7 +168,8 @@
// send this port number to client
snprintf(buff, sizeof(buff), "%d", options->midsockport);
- if ((msgretvalue = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff)))
+ if ((msgretvalue = send_json_message(ctlsockfd, TEST_PREPARE, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE))
< 0)
return msgretvalue;
@@ -246,13 +251,13 @@
}
// Perform S->C throughput test. Obtained results in "buff"
- tcp_stat_middlebox(midsfd, agent, conn, buff, sizeof(buff));
+ tcp_stat_middlebox(midsfd, agent, conn, results_keys, sizeof(results_keys), buff, sizeof(buff));
// Transmit results in the form of a TEST_MSG message
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_msg(ctlsockfd, TEST_MSG, buff, strlen(buff), options->json_support, JSON_MULTIPLE_VALUES,
+ results_keys, ";", buff, ";");
// Expect client to send throughput as calculated at its end
-
msgLen = sizeof(buff);
// message reception error
if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
@@ -261,7 +266,8 @@
buff,
sizeof(buff),
"Server (Middlebox test): Invalid CWND limited throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
return 1;
}
if (check_msg_type("Middlebox test", TEST_MSG, msgType, buff,
@@ -270,21 +276,29 @@
buff,
sizeof(buff),
"Server (Middlebox test): Invalid CWND limited throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
return 2;
}
+ buff[msgLen] = 0;
+ if (options->json_support) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) { // received message's length has to be a valid one
log_println(0, "Improper message");
snprintf(
buff,
sizeof(buff),
"Server (Middlebox test): Invalid CWND limited throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
return 3;
}
// message payload from client == midbox S->c throughput
- buff[msgLen] = 0;
*s2c_throughput_mid = atof(buff);
log_println(4, "CWND limited throughput = %0.0f kbps (%s)",
*s2c_throughput_mid, buff);
@@ -294,7 +308,7 @@
shutdown(midsfd, SHUT_WR);
close(midsfd);
close(options->midsockfd);
- send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
+ send_json_message(ctlsockfd, TEST_FINALIZE, "", 0, options->json_support, JSON_SINGLE_VALUE);
log_println(1, " <--------- %d ----------->", options->child0);
// log end of test into protocol doc, just to delimit.
=======================================
--- /branches/Issue145/src/test_s2c_clt.c Tue May 21 14:47:24 2013 UTC
+++ /branches/Issue145/src/test_s2c_clt.c Tue May 13 13:52:22 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the functions needed to handle S2C throughput
* test (client part).
*
- * Jakub S³awiñski 2006-08-02
+ * Jakub S�awi�ski 2006-08-02
*
*/
@@ -16,10 +16,15 @@
#include "protocol.h"
#include "utils.h"
#include "strlutils.h"
+#include "jsonutils.h"
int ssndqueue, sbytes;
double spdin, s2cspd;
+#define THROUGHPUT_VALUE "ThroughputValue"
+#define UNSENT_DATA_AMOUNT "UnsentDataAmount"
+#define TOTALSENTBYTE "TotalSentByte"
+
/**
* S2C throughput test to measure network bandwidth
* from server to client.
@@ -29,6 +34,7 @@
* @param conn_options Options to use while connecting to server(for ex, IPV4)
* @param buf_size TCP send/receive buffer size
* @param result_srv result obtained from server (containing values of web100 variables)
+ * @param jsonSupport Indicates if messages should be sent using JSON format
* @return integer > 0 if successful, < 0 in case of error
* Return codes:
* 1: Error receiving protocol message
@@ -40,7 +46,7 @@
*/
int test_s2c_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size, char* result_srv) {
+ int buf_size, char* result_srv, int jsonSupport) {
char buff[BUFFSIZE + 1];
int msgLen, msgType;
int s2cport = atoi(PORT3);
@@ -52,7 +58,7 @@
double t;
struct timeval sel_tv;
fd_set rfd;
- char* ptr;
+ char* ptr, *jsonMsgValue;
// variables used for protocol validation logs
enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
@@ -75,13 +81,19 @@
if (check_msg_type(S2C_TEST_LOG, TEST_PREPARE, msgType, buff, msgLen)) {
return 2;
}
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
// This TEST_PREPARE message is expected to have the port number as message
// body. Check if this is a valid integral port.
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
}
- buff[msgLen] = 0;
if (check_int(buff, &s2cport)) {
log_println(0, "Invalid port number");
return 4;
@@ -183,30 +195,58 @@
if (check_msg_type(S2C_TEST_LOG, TEST_MSG, msgType, buff, msgLen)) {
return 2; // no other message type expected
}
+ buff[msgLen] = 0;
// Is message of valid length, and does it have all the data expected?
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
}
- buff[msgLen] = 0;
- ptr = strtok(buff, " ");
- if (ptr == NULL) {
- log_println(0, "S2C: Improper message");
- return 4;
- }
- s2cspd = atoi(ptr); // get S->C throughput first
- ptr = strtok(NULL, " ");
- if (ptr == NULL) {
- log_println(0, "S2C: Improper message");
- return 4;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, THROUGHPUT_VALUE);
+ if (jsonMsgValue == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ s2cspd = atoi(jsonMsgValue);
+ free(jsonMsgValue);
+
+ jsonMsgValue = json_read_map_value(buff, UNSENT_DATA_AMOUNT);
+ if (jsonMsgValue == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ ssndqueue = atoi(jsonMsgValue);
+ free(jsonMsgValue);
+
+ jsonMsgValue = json_read_map_value(buff, TOTALSENTBYTE);
+ if (jsonMsgValue == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ sbytes = atoi(jsonMsgValue);
+ free(jsonMsgValue);
}
- ssndqueue = atoi(ptr); // get amount of unsent data in queue
- ptr = strtok(NULL, " ");
- if (ptr == NULL) {
- log_println(0, "S2C: Improper message");
- return 4;
+ else {
+ ptr = strtok(buff, " ");
+ if (ptr == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ s2cspd = atoi(ptr); // get S->C throughput first
+ ptr = strtok(NULL, " ");
+ if (ptr == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ ssndqueue = atoi(ptr); // get amount of unsent data in queue
+ ptr = strtok(NULL, " ");
+ if (ptr == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ sbytes = atoi(ptr); // finally get total-sent-byte-count
}
- sbytes = atoi(ptr); // finally get total-sent-byte-count
+
// log_println(0,"S->C received throughput: %f",s2cspd);
// log results in a convenient units format
if (spdin < 1000)
@@ -218,7 +258,8 @@
// send TEST_MSG to server with the client-calculated throughput
snprintf(buff, sizeof(buff), "%0.0f", spdin);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);
// client now expected to receive web100 variables collected by server
=======================================
--- /branches/Issue145/src/test_s2c_srv.c Tue Apr 15 22:51:33 2014 UTC
+++ /branches/Issue145/src/test_s2c_srv.c Tue May 13 13:52:22 2014 UTC
@@ -21,10 +21,12 @@
#include "protocol.h"
#include "network.h"
#include "mrange.h"
+#include "jsonutils.h"
extern pthread_mutex_t mainmutex;
extern pthread_cond_t maincond;
+const char RESULTS_KEYS[] = "ThroughputValue UnsentDataAmount TotalSentByte";
/**
* Perform the S2C Throughput test. This throughput test tests the achievable
@@ -58,12 +60,12 @@
* @return 0 - success,
* >0 - error code.
* Error codes:
- * -1 - Message reception errors/inconsistencies in clientÕs final message, or Listener socket creation failed or cannot write message header information while attempting to send
+ * -1 - Message reception errors/inconsistencies in client�s final message, or Listener socket creation failed or cannot write message header information while attempting to send
* TEST_PREPARE message
* -2 - Cannot write message data while
attempting to send
* TEST_PREPARE message, or Unexpected message type
received
* -3 - Received message is invalid
- * -100 - timeout while waiting for client to connect to serverÕs ephemeral port
+ * -100 - timeout while waiting for client to connect to server�s ephemeral port
* -101 - Retries exceeded while waiting for
client to connect
* -102 - Retries exceeded while waiting for data from connected client
* -errno - Other specific socket error numbers
@@ -115,6 +117,7 @@
int msgLen;
int sndqueue;
struct sigaction new, old;
+ char* jsonMsgValue;
pthread_t workerThreadId;
int nextseqtosend = 0, lastunackedseq = 0;
@@ -196,7 +199,8 @@
sizeof(buff),
"Server (S2C throughput test): CreateListenSocket failed: %s",
strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return -1;
}
@@ -212,7 +216,8 @@
// Data received from speed-chk. Send TEST_PREPARE "GO" signal with port
// number
snprintf(buff, sizeof(buff), "%d", testOptions->s2csockport);
- j = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff));
+ j = send_json_message(ctlsockfd, TEST_PREPARE, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
if (j == -1) {
log_println(6, "S2C %d Error!, Test start message not sent!",
testOptions->child0);
@@ -371,7 +376,8 @@
}
// Send message to client indicating TEST_START
- if (send_msg(ctlsockfd, TEST_START, "", 0) < 0)
+ if (send_json_message(ctlsockfd, TEST_START, "", 0, testOptions->json_support,
+ JSON_SINGLE_VALUE) < 0)
log_println(6,
"S2C test - Test-start message failed for pid=%d",
s2c_childpid);
@@ -482,10 +488,21 @@
// Send throughput, unsent byte count, total sent byte count to client
snprintf(buff, sizeof(buff), "%0.0f %d %0.0f", x2cspd, sndqueue,
bytes_written);
- if (send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff)) < 0)
- log_println(6,
- "S2C test - failed to send test message to pid=%d",
- s2c_childpid);
+ if (testOptions->json_support) {
+ if (send_json_msg(ctlsockfd, TEST_MSG, buff, strlen(buff), testOptions->json_support,
+ JSON_MULTIPLE_VALUES, RESULTS_KEYS, " ", buff, " ") < 0)
+ log_println(6,
+ "S2C test - failed to send test message to pid=%d",
+ s2c_childpid);
+ }
+ else {
+ if (send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE) < 0)
+ log_println(6,
+ "S2C test - failed to send test message to pid=%d",
+ s2c_childpid);
+ }
+
#if USE_WEB100
web100_snap(rsnap);
@@ -592,7 +609,8 @@
log_println(6, "S2C - No web100 data received for pid=%d",
s2c_childpid);
snprintf(buff, sizeof(buff), "No Data Collected: 000000");
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff), testOptions->json_support,
+ JSON_SINGLE_VALUE);
}
// Wait for message from client. Client sends its calculated throughput
@@ -605,7 +623,8 @@
buff,
sizeof(buff),
"Server (S2C throughput test): Invalid S2C throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return -1;
}
if (check_msg_type("S2C throughput test", TEST_MSG, msgType, buff,
@@ -614,25 +633,34 @@
buff,
sizeof(buff),
"Server (S2C throughput test): Invalid S2C throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return -2;
}
+ buff[msgLen] = 0;
+ if (testOptions->json_support) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) {
log_println(0, "Improper message");
snprintf(
buff,
sizeof(buff),
"Server (S2C throughput test): Invalid S2C throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return -3;
}
- buff[msgLen] = 0;
*s2cspd = atoi(buff); // save Throughput value as seen by client
log_println(6, "S2CSPD from client %f", *s2cspd);
// Final activities of ending tests. Close sockets, file descriptors,
// send finalise message to client
close(xmitsfd);
- if (send_msg(ctlsockfd, TEST_FINALIZE, "", 0) < 0)
+ if (send_json_message(ctlsockfd, TEST_FINALIZE, "", 0,
+ testOptions->json_support, JSON_SINGLE_VALUE) < 0)
log_println(6,
"S2C test - failed to send finalize message to pid=%d",
s2c_childpid);
=======================================
--- /branches/Issue145/src/test_sfw.h Thu Nov 15 21:33:44 2012 UTC
+++ /branches/Issue145/src/test_sfw.h Tue May 13 13:52:22 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the function declarations to handle simple
* firewall test.
*
- * Jakub S³awiñski 2006-07-15
+ * Jakub S�awi�ski 2006-07-15
*
*/
@@ -17,8 +17,10 @@
#define SFW_TEST_DEFAULT_LEN 20
#define SFW_PREDEFINED_TEST_MSG "Simple firewall test"
#define SFW_TEST_LOG "Simple firewall test"
+#define EMPHERAL_PORT_NUMBER "empheralPortNumber"
+#define TEST_TIME "testTime"
-int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options);
+int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options, int jsonSupport);
int results_sfw(char tests, char* host);
#endif // SRC_TEST_SFW_H_
=======================================
--- /branches/Issue145/src/test_sfw_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /branches/Issue145/src/test_sfw_clt.c Tue May 13 13:52:22 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the functions needed to handle simple firewall
* test (client part).
*
- * Jakub S³awiñski 2006-07-15
+ * Jakub S�awi�ski 2006-07-15
*
*/
@@ -18,6 +18,7 @@
#include "protocol.h"
#include "network.h"
#include "utils.h"
+#include "jsonutils.h"
static int c2s_result = SFW_NOTTESTED;
static int s2c_result = SFW_NOTTESTED;
@@ -57,6 +58,8 @@
int msgLen, msgType;
struct sockaddr_storage srv_addr;
socklen_t srvlen;
+ int jsonSupport = *((int*) vptr);
+ char* jsonMsgValue;
// protocol logging
enum PROCESS_TYPE_INT proctypeenum = PROCESS_TYPE;
@@ -115,7 +118,13 @@
// The server is expected to send a 20 char message that
// says "Simple firewall test" . Every other message string
// indicates an unknown firewall status
-
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen != SFW_TEST_DEFAULT_LEN) {
log_println(0, "Simple firewall test: Improper message");
s2c_result = SFW_UNKNOWN;
@@ -123,7 +132,6 @@
I2AddrFree(sfwcli_addr);
return NULL;
}
- buff[msgLen] = 0;
if (strcmp(buff, SFW_PREDEFINED_TEST_MSG) != 0) {
log_println(0, "Simple firewall test: Improper message");
s2c_result = SFW_UNKNOWN;
@@ -149,6 +157,7 @@
* @param tests set of tests to perform
* @param host hostname of the server
* @param conn_options the connection options
+ * @param jsonSupport indicates if messages should be sent using JSON format
* @return integer
* => 0 on success
* < 0 if error
@@ -165,13 +174,13 @@
* -3: Unable to resolve server address
*
*/
-int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options) {
+int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options, int jsonSupport) {
char buff[BUFFSIZE + 1];
int msgLen, msgType;
int sfwport, sfwsock, sfwsockport;
I2Addr sfwsrv_addr = NULL;
struct sigaction new, old;
- char* ptr;
+ char* ptr, *jsonMsgValue;
pthread_t threadId;
// variables used for protocol validation logs
@@ -203,28 +212,53 @@
// This message is expected to be of valid length, and have a message
// .. payload containing the integral ephemeral port number and testTime
// ... separated by a single space
+ buff[msgLen] = 0;
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
}
- buff[msgLen] = 0;
- ptr = strtok(buff, " ");
- if (ptr == NULL) {
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, EMPHERAL_PORT_NUMBER);
+ if (jsonMsgValue == NULL) {
+ log_println(0, "SFW: Improper message");
+ return 5;
+ }
+ if (check_int(jsonMsgValue, &sfwport)) { // get ephemeral port#
+ log_println(0, "Invalid port number");
+ return 4;
+ }
+ free(jsonMsgValue);
+
+ jsonMsgValue = json_read_map_value(buff, TEST_TIME);
+ if (jsonMsgValue == NULL) {
log_println(0, "SFW: Improper message");
return 5;
}
- if (check_int(ptr, &sfwport)) { // get ephemeral port#
- log_println(0, "Invalid port number");
+ if (check_int(jsonMsgValue, &testTime)) { // get test time
+ log_println(0, "Invalid waiting time");
return 4;
}
- ptr = strtok(NULL, " ");
- if (ptr == NULL) {
- log_println(0, "SFW: Improper message");
- return 5;
+ free(jsonMsgValue);
}
- if (check_int(ptr, &testTime)) { // get test time
- log_println(0, "Invalid waiting time");
- return 4;
+ else {
+ ptr = strtok(buff, " ");
+ if (ptr == NULL) {
+ log_println(0, "SFW: Improper message");
+ return 5;
+ }
+ if (check_int(ptr, &sfwport)) { // get ephemeral port#
+ log_println(0, "Invalid port number");
+ return 4;
+ }
+ ptr = strtok(NULL, " ");
+ if (ptr == NULL) {
+ log_println(0, "SFW: Improper message");
+ return 5;
+ }
+ if (check_int(ptr, &testTime)) { // get test time
+ log_println(0, "Invalid waiting time");
+ return 4;
+ }
}
log_println(1, "\n -- port: %d", sfwport);
log_println(1, " -- time: %d", testTime);
@@ -248,7 +282,8 @@
// Send a TEST_MSG to server with the client's port number
snprintf(buff, sizeof(buff), "%d", sfwsockport);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);
// The server responds to the TEST_MSG messages with a TEST_START message.
// Any other type of message is an error here.
@@ -262,7 +297,7 @@
// Now listen for server sending out a test for the S->C direction , and
// update test results
- pthread_create(&threadId, NULL, &test_osfw_clt, NULL);
+ pthread_create(&threadId, NULL, &test_osfw_clt, &jsonSupport);
// ignore the alarm signal
memset(&new, 0, sizeof(new));
@@ -275,7 +310,8 @@
if (CreateConnectSocket(&sfwsock, NULL, sfwsrv_addr,
conn_options, 0) == 0) {
- send_msg(sfwsock, TEST_MSG, SFW_PREDEFINED_TEST_MSG, 20);
+ send_json_message(sfwsock, TEST_MSG, SFW_PREDEFINED_TEST_MSG, 20,
+ jsonSupport, JSON_SINGLE_VALUE);
}
alarm(0);
sigaction(SIGALRM, &old, NULL);
@@ -293,12 +329,17 @@
}
// The test results are sent as a numeric encoding the test results.
-
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) { // test results have valid length
log_println(0, "Improper message");
return 3;
}
- buff[msgLen] = 0;
if (check_int(buff, &c2s_result)) {
// test result has to be a valid integer
log_println(0, "Invalid test result");
=======================================
--- /branches/Issue145/src/test_sfw_srv.c Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue145/src/test_sfw_srv.c Tue May 13 13:52:22 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the functions needed to handle simple firewall
* test (server part).
*
- * Jakub S³awiñski 2006-07-15
+ * Jakub S�awi�ski 2006-07-15
*
*/
@@ -17,6 +17,7 @@
#include "testoptions.h"
#include "runningtest.h"
#include "strlutils.h"
+#include "jsonutils.h"
static pthread_mutex_t mainmutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t maincond = PTHREAD_COND_INITIALIZER;
@@ -47,13 +48,14 @@
* firewall test in a separate thread.
* In other words, sends the S->C TEST_MSG with message body
* "Simple firewall test"
- * @param vptr void pointer
+ * @param vptr void pointer containing jsonSupport parameter
*/
void*
test_osfw_srv(void* vptr) {
int sfwsock;
struct sigaction new, old;
+ int jsonSupport = *((int*) vptr);
// ignore the alarm signal
memset(&new, 0, sizeof(new));
@@ -63,7 +65,8 @@
// connect to client and send TEST_MSG message containing a pre-defined string
if (CreateConnectSocket(&sfwsock, NULL, sfwcli_addr, 0, 0) == 0) {
- send_msg(sfwsock, TEST_MSG, "Simple firewall test", 20);
+ send_json_message(sfwsock, TEST_MSG, "Simple firewall test", 20,
+ jsonSupport, JSON_SINGLE_VALUE);
}
alarm(0);
@@ -82,9 +85,10 @@
* Wait for the every thread to conclude and finalize
* the SFW test.
* @param ctlsockfd Client control socket descriptor
+ * @param jsonSupport Indicates if messages should be sent using JSON format
*/
-void finalize_sfw(int ctlsockfd) {
+void finalize_sfw(int ctlsockfd, int jsonSupport) {
enum TEST_ID thistestId = SFW;
enum TEST_STATUS_INT teststatusnow = NONE;
// wait for mutex to be released before attempting to finalize
@@ -95,7 +99,7 @@
}
// close the SFW test by sending a nil (0 length) message
- send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
+ send_json_message(ctlsockfd, TEST_FINALIZE, "", 0, jsonSupport, JSON_SINGLE_VALUE);
// log
teststatusnow = TEST_ENDED;
@@ -130,6 +134,7 @@
fd_set fds;
struct timeval sel_tv;
int msgLen, msgType;
+ char* jsonMsgValue;
#if USE_WEB100
web100_var* var;
@@ -166,7 +171,8 @@
"CreateListenSocket failed: %s", strerror(errno));
snprintf(buff, sizeof(buff), "Server (Simple firewall test): "
"CreateListenSocket failed: %s", strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
return -1;
}
@@ -219,7 +225,8 @@
log_println(0, "Simple firewall test: Cannot find connection");
snprintf(buff, sizeof(buff), "Server (Simple firewall test): "
"Cannot find connection");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
I2AddrFree(sfwsrv_addr);
return -1;
}
@@ -227,8 +234,16 @@
// try sending TEST_PREPARE msg with ephemeral port number to client.
// If unable to, return
- snprintf(buff, sizeof(buff), "%d %d", sfwsockport, testTime);
- if ((rc = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff))) < 0)
+ if (options->json_support) {
+ snprintf(buff, sizeof(buff), "%s: %d\n%s: %d", EMPHERAL_PORT_NUMBER,sfwsockport,
+ TEST_TIME, testTime);
+ }
+ else {
+ snprintf(buff, sizeof(buff), "%d %d", sfwsockport, testTime);
+ }
+
+ if ((rc = send_json_message(ctlsockfd, TEST_PREPARE, buff, strlen(buff),
+ options->json_support, JSON_KEY_VALUE_PAIRS)) < 0)
return (rc);
// Listen for TEST_MSG from client's port number sent as data.
@@ -239,7 +254,8 @@
log_println(0, "Protocol error!");
snprintf(buff, sizeof(buff), "Server (Simple firewall test): "
"Invalid port number received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
I2AddrFree(sfwsrv_addr);
return 1;
}
@@ -248,28 +264,37 @@
log_println(0, "Fault, unexpected message received!");
snprintf(buff, sizeof(buff), "Server (Simple firewall test): "
"Invalid port number received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
I2AddrFree(sfwsrv_addr);
return 2;
}
+ buff[msgLen] = 0;
+ if (options->json_support) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) { // message reception has error
log_println(0, "Improper message");
snprintf(buff, sizeof(buff), "Server (Simple firewall test): "
"Invalid port number received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
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
log_println(0, "Invalid port number");
snprintf(buff, sizeof(buff), "Server (Simple firewall test): "
"Invalid port number received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
I2AddrFree(sfwsrv_addr);
return 4;
}
@@ -280,7 +305,8 @@
if ((sfwcli_addr = I2AddrByNode(get_errhandle(), hostname)) == NULL) {
// todo, this is the client address we cannot resolve?
log_println(0, "Unable to resolve server address");
- send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
+ send_json_message(ctlsockfd, TEST_FINALIZE, "", 0,
+ options->json_support, JSON_SINGLE_VALUE);
// log end
teststatusnow = TEST_ENDED;
@@ -293,10 +319,10 @@
log_println(1, " -- oport: %d", sfwport);
// send S->C side TEST_MSG
- send_msg(ctlsockfd, TEST_START, "", 0);
+ send_json_message(ctlsockfd, TEST_START, "", 0, options->json_support, JSON_SINGLE_VALUE);
// send the S->C default test message in a separate thread to client
- pthread_create(&threadId, NULL, &test_osfw_srv, NULL);
+ pthread_create(&threadId, NULL, &test_osfw_srv, &options->json_support);
FD_ZERO(&fds);
FD_SET(sfwsockfd, &fds);
@@ -311,8 +337,9 @@
case -1: // If SOCKET_ERROR - status of firewall unknown
log_println(0, "Simple firewall test: select exited with error");
snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- finalize_sfw(ctlsockfd);
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
+ finalize_sfw(ctlsockfd, options->json_support);
I2AddrFree(sfwsrv_addr);
I2AddrFree(sfwcli_addr);
return 1;
@@ -320,8 +347,9 @@
log_println(0, "Simple firewall test: no connection for %d seconds",
testTime);
snprintf(buff, sizeof(buff), "%d", SFW_POSSIBLE);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- finalize_sfw(ctlsockfd);
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
+ finalize_sfw(ctlsockfd, options->json_support);
I2AddrFree(sfwsrv_addr);
I2AddrFree(sfwcli_addr);
return 2;
@@ -342,9 +370,10 @@
// message received in error
log_println(0, "Simple firewall test: unrecognized message");
snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
close(sockfd);
- finalize_sfw(ctlsockfd);
+ finalize_sfw(ctlsockfd, options->json_support);
I2AddrFree(sfwsrv_addr);
I2AddrFree(sfwcli_addr);
return 1;
@@ -353,32 +382,41 @@
msgLen)) {
// unexpected message type received
snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
close(sockfd);
- finalize_sfw(ctlsockfd);
+ finalize_sfw(ctlsockfd, options->json_support);
I2AddrFree(sfwsrv_addr);
I2AddrFree(sfwcli_addr);
return 1;
}
+ buff[msgLen] = 0;
+ if (options->json_support) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen != SFW_TEST_DEFAULT_LEN) {
// Expecting default 20 byte long "Simple firewall test" message
log_println(0, "Simple firewall test: Improper message");
snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
close(sockfd);
- finalize_sfw(ctlsockfd);
+ finalize_sfw(ctlsockfd, options->json_support);
I2AddrFree(sfwsrv_addr);
I2AddrFree(sfwcli_addr);
return 1;
}
- buff[msgLen] = 0;
if (strcmp(buff, "Simple firewall test") != 0) {
// Message was of correct length, but was not expected content-wise
log_println(0, "Simple firewall test: Improper message");
snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
close(sockfd);
- finalize_sfw(ctlsockfd);
+ finalize_sfw(ctlsockfd, options->json_support);
I2AddrFree(sfwsrv_addr);
I2AddrFree(sfwcli_addr);
return 1;
@@ -386,9 +424,10 @@
// All messages were received correctly, hence no firewall
snprintf(buff, sizeof(buff), "%d", SFW_NOFIREWALL);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff),
+ options->json_support, JSON_SINGLE_VALUE);
close(sockfd);
- finalize_sfw(ctlsockfd);
+ finalize_sfw(ctlsockfd, options->json_support);
I2AddrFree(sfwsrv_addr);
I2AddrFree(sfwcli_addr);
}
=======================================
--- /branches/Issue145/src/testoptions.c Tue Apr 15 22:51:33 2014 UTC
+++ /branches/Issue145/src/testoptions.c Tue May 13 13:52:22 2014 UTC
@@ -19,6 +19,7 @@
#include "I2util/util.h"
#include "runningtest.h"
#include "strlutils.h"
+#include "jsonutils.h"
// Worker thread characteristics used to record snaplog and Cwnd peaks
@@ -215,6 +216,7 @@
char *client_timeout = "Client timeout.";
char *invalid_test = "Invalid test request.";
char *invalid_login_msg = "Invalid login message.";
+ char* jsonMsgValue;
// char remhostarr[256], protologlocalarr[256];
// char *remhost_ptr = get_remotehost();
@@ -251,16 +253,19 @@
* into useropt so we'll do that in the fallthrough.
*/
if (msgType == MSG_LOGIN) { /* Case 1 */
+ options->json_support = 0;
if (msgLen != 1) {
send_msg(ctlsockfd, MSG_ERROR, invalid_test, strlen(invalid_test));
return (-2);
}
} else if (msgType == MSG_EXTENDED_LOGIN) { /* Case 2 */
+ options->json_support = 1;
if (msgLen >= 1 && msgLen <= (CS_VERSION_LENGTH_MAX + 1)) {
memcpy(options->client_version, msgValue + 1, msgLen - 1);
log_println(0, "Client version: %s-\n", options->client_version);
} else {
- send_msg(ctlsockfd, MSG_ERROR, invalid_test, strlen(invalid_test));
+ send_json_message(ctlsockfd, MSG_ERROR, invalid_test, strlen(invalid_test),
+ options->json_support, JSON_SINGLE_VALUE);
return (-2);
}
} else { /* Case 3 */
@@ -283,8 +288,8 @@
& (TEST_MID | TEST_C2S | TEST_S2C | TEST_SFW | TEST_STATUS
| TEST_META))) {
// message received does not indicate a valid test!
- send_msg(ctlsockfd, MSG_ERROR, invalid_test_suite,
- strlen(invalid_test_suite));
+ send_json_message(ctlsockfd, MSG_ERROR, invalid_test_suite,
+ strlen(invalid_test_suite), options->json_support, JSON_SINGLE_VALUE);
return (-3);
}
// construct test suite request based on user options received
=======================================
--- /branches/Issue145/src/testoptions.h Tue Apr 15 22:51:33 2014 UTC
+++ /branches/Issue145/src/testoptions.h Tue May 13 13:52:22 2014 UTC
@@ -24,6 +24,8 @@
char client_version[CS_VERSION_LENGTH_MAX + 1]; // client version number.
+ int json_support; // indicates if client supports JSON messages
+
int midopt; // middlebox test to be perfomed?
int midsockfd; // socket file desc for middlebox test
int midsockport; // port used for middlebox test
=======================================
--- /branches/Issue145/src/web100-util.c Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue145/src/web100-util.c Tue May 13 13:52:22 2014 UTC
@@ -150,13 +150,14 @@
* @param sock integer socket file descriptor
* @param agent pointer to a web100_agent
* @param cn pointer to the web100_connection
- * @param results pointer to string containing Server address , client address
+ * @param results_keys pointer to string containing names of variables stored in results_values
+ * @param results_values pointer to string containing Server address , client address
* currentMSS, WinScaleSent and WinScaleRecv values
*
*
*/
-void tcp_stat_middlebox(int sock, tcp_stat_agent* agent, tcp_stat_connection cn,
- char *results, size_t results_strlen) {
+void tcp_stat_middlebox(int sock, tcp_stat_agent* agent, tcp_stat_connection cn, char *results_keys,
+ size_t results_keys_strlen, char *results_values, size_t results_strlen) {
#if USE_WEB100
web100_var* var;
web100_group* group;
@@ -183,7 +184,8 @@
// middlebox test results
static char vars[][255] = { "CurMSS", "WinScaleSent", "WinScaleRcvd", };
- assert(results);
+ assert(results_keys);
+ assert(results_values);
log_println(4, "Looking for Web100 data on socketid %d", sock);
@@ -213,7 +215,9 @@
// terminate the IP address string
meta.server_ip[(strlen(line) - 1)] = 0;
// Add this address to results
- strlcat(results, line, results_strlen);
+ strlcat(results_keys, SERVER_ADDRESS, results_keys_strlen);
+ strlcat(results_keys, ";", results_keys_strlen);
+ strlcat(results_values, line, results_strlen);
// Now perform the above set of functions for client address/service name
// and copy into results
@@ -233,7 +237,9 @@
port2a(&saddr, tmpstr, tmpstrlen);
}
log_print(3, "Client: %s%s ", line, tmpstr);
- strlcat(results, line, results_strlen);
+ strlcat(results_keys, CLIENT_ADDRESS, results_keys_strlen);
+ strlcat(results_keys, ";", results_keys_strlen);
+ strlcat(results_values, line, results_strlen);
// get web100 values for the middlebox test result group
for (i = 0; i < sizeof(vars) / sizeof(vars[0]); i++) {
@@ -268,7 +274,9 @@
snprintf(line, sizeof(line), "%d;", -1);
// strlcat(results, line, sizeof(results));
- strlcat(results, line, results_strlen);
+ strlcat(results_keys, vars[i], results_keys_strlen);
+ strlcat(results_keys, ";", results_keys_strlen);
+ strlcat(results_values, line, results_strlen);
log_print(3, "%s", line);
}
log_println(3, "");
=======================================
--- /branches/Issue145/src/web100clt.c Tue Mar 25 09:36:53 2014 UTC
+++ /branches/Issue145/src/web100clt.c Tue May 13 13:52:22 2014 UTC
@@ -23,6 +23,7 @@
#include "test_results_clt.h"
#include <arpa/inet.h>
#include <assert.h>
+#include "jsonutils.h"
extern int h_errno;
@@ -256,29 +257,54 @@
* Server IP; Client IP.
* @param midresult_str String containing test results
* @param cltsock Used to get address information
+ * @param jsonFormat Indicates if results are saved using JSON format
*/
-void middleboxResults(char *midresult_str, int cltsock) {
+void middleboxResults(char *midresult_str, int cltsock, int jsonFormat) {
char ssip[64], scip[64], *str;
char csip[64], ccip[64];
struct sockaddr_storage addr;
socklen_t addr_size;
int mss;
size_t tmpLen;
+ char *jsonMsgValue;
- str = strtok(midresult_str, ";");
- strlcpy(ssip, str, sizeof(ssip));
- str = strtok(NULL, ";");
+ if (jsonFormat) {
+ jsonMsgValue = json_read_map_value(midresult_str, SERVER_ADDRESS);
+ strlcpy(ssip, jsonMsgValue, sizeof(ssip));
+ free(jsonMsgValue);
+
+ jsonMsgValue = json_read_map_value(midresult_str, CLIENT_ADDRESS);
+ strlcpy(scip, jsonMsgValue, sizeof(scip));
+ free(jsonMsgValue);
+
+ jsonMsgValue = json_read_map_value(midresult_str, CUR_MSS);
+ mss = atoi(jsonMsgValue);
+ free(jsonMsgValue);
+
+ jsonMsgValue = json_read_map_value(midresult_str, WIN_SCALE_SENT);
+ winssent = atoi(jsonMsgValue);
+ free(jsonMsgValue);
+
+ jsonMsgValue = json_read_map_value(midresult_str, WIN_SCALE_RCVD);
+ winsrecv = atoi(jsonMsgValue);
+ free(jsonMsgValue);
+ }
+ else {
+ str = strtok(midresult_str, ";");
+ strlcpy(ssip, str, sizeof(ssip));
+ str = strtok(NULL, ";");
- strlcpy(scip, str, sizeof(scip));
+ strlcpy(scip, str, sizeof(scip));
- str = strtok(NULL, ";");
- mss = atoi(str);
- str = strtok(NULL, ";");
- // changing order to read winsent before winsrecv for issue 61
- winssent = atoi(str);
- str = strtok(NULL, ";");
- winsrecv = atoi(str);
+ str = strtok(NULL, ";");
+ mss = atoi(str);
+ str = strtok(NULL, ";");
+ // changing order to read winsent before winsrecv for issue 61
+ winssent = atoi(str);
+ str = strtok(NULL, ";");
+ winsrecv = atoi(str);
+ }
/* Get the our local IP address */
addr_size = sizeof(addr);
@@ -505,6 +531,7 @@
int conn_options = 0; // connection options received from user
int debug = 0; // debug flag
int testId; // test ID received from server
+ int jsonSupport = 1; // indicates if client should sent messages in JSON format
// addresses..
I2Addr server_addr = NULL;
char* ptr;
@@ -652,7 +679,7 @@
/* The beginning of the protocol */
/* write our test suite request by sending a login message */
- send_msg(ctlSocket, MSG_LOGIN, &tests, 1);
+ send_msg(ctlSocket, MSG_EXTENDED_LOGIN, &tests, 1);
/* read the specially crafted data that kicks off the old clients */
if (readn(ctlSocket, buff, 13) != 13) {
printf("Information: The server '%s' does not support this command line "
@@ -818,32 +845,32 @@
switch (testId) {
case TEST_MID:
if (test_mid_clt(ctlSocket, tests, host, conn_options, buf_size,
- mid_resultstr)) {
+ mid_resultstr, jsonSupport)) {
log_println(0, "Middlebox test FAILED!");
tests &= (~TEST_MID);
}
break;
case TEST_C2S:
- if (test_c2s_clt(ctlSocket, tests, host, conn_options, buf_size)) {
+ if (test_c2s_clt(ctlSocket, tests, host, conn_options, buf_size, jsonSupport)) {
log_println(0, "C2S throughput test FAILED!");
tests &= (~TEST_C2S);
}
break;
case TEST_S2C:
if (test_s2c_clt(ctlSocket, tests, host, conn_options, buf_size,
- resultstr)) {
+ resultstr, jsonSupport)) {
log_println(0, "S2C throughput test FAILED!");
tests &= (~TEST_S2C);
}
break;
case TEST_SFW:
- if (test_sfw_clt(ctlSocket, tests, host, conn_options)) {
+ if (test_sfw_clt(ctlSocket, tests, host, conn_options, jsonSupport)) {
log_println(0, "Simple firewall test FAILED!");
tests &= (~TEST_SFW);
}
break;
case TEST_META:
- if (test_meta_clt(ctlSocket, tests, host, conn_options)) {
+ if (test_meta_clt(ctlSocket, tests, host, conn_options, jsonSupport)) {
log_println(0, "META test FAILED!");
tests &= (~TEST_META);
}
@@ -892,7 +919,7 @@
// print middlebox test results
if (tests & TEST_MID) {
- middleboxResults(mid_resultstr, ctlSocket);
+ middleboxResults(mid_resultstr, ctlSocket, jsonSupport);
}
I2AddrFree(server_addr);
=======================================
--- /branches/Issue145/src/web100srv.h Wed Mar 12 06:27:30 2014 UTC
+++ /branches/Issue145/src/web100srv.h Tue May 13 13:52:22 2014 UTC
@@ -309,8 +309,8 @@
int tcp_stat_autotune(int sock, tcp_stat_agent* agent, tcp_stat_connection cn);
int tcp_stat_init(char *VarFileName);
-void tcp_stat_middlebox(int sock, tcp_stat_agent* agent, tcp_stat_connection cn,
- char *results, size_t results_strlen);
+void tcp_stat_middlebox(int sock, tcp_stat_agent* agent, tcp_stat_connection cn, char *results_keys,
+ size_t results_keys_strlen, char *results_values, size_t results_strlen);
int tcp_stat_setbuff(int sock, tcp_stat_agent* agent, tcp_stat_connection cn,
int autotune);/* Not used so no web10g version */
void tcp_stat_get_data_recv(int sock, tcp_stat_agent* agent,
- [ndt-dev] [ndt] r1052 committed - Changed tests specific methods to use JSON format, ndt, 05/13/2014
Archive powered by MHonArc 2.6.16.