Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r1060 committed - Merged Issues 145,146,147 into trunk (JSON support)

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r1060 committed - Merged Issues 145,146,147 into trunk (JSON support)


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r1060 committed - Merged Issues 145,146,147 into trunk (JSON support)
  • Date: Wed, 28 May 2014 11:18:08 +0000

Revision: 1060
Author:

Date: Wed May 28 11:17:18 2014 UTC
Log: Merged Issues 145,146,147 into trunk (JSON support)

http://code.google.com/p/ndt/source/detail?r=1060

Added:
/trunk/Applet/src/edu/internet2/ndt/JSONUtils.java
/trunk/Applet/src/edu/internet2/ndt/lib
/trunk/src/jsonutils.c
/trunk/src/jsonutils.h
Modified:
/trunk
/trunk/Applet/MANIFEST.MF
/trunk/Applet/Makefile.am
/trunk/Applet/src/edu/internet2/ndt/MessageType.java
/trunk/Applet/src/edu/internet2/ndt/Protocol.java
/trunk/Applet/src/edu/internet2/ndt/Tcpbw100.java
/trunk/Applet/src/edu/internet2/ndt/lib/json-smart-1.1.1.jar
/trunk/Applet/src/edu/internet2/ndt/locale/Tcpbw100_msgs_en_US.properties
/trunk/configure.ac
/trunk/flash-client/src/Handshake.as
/trunk/flash-client/src/Main.as
/trunk/flash-client/src/Message.as
/trunk/flash-client/src/NDTPController.as
/trunk/flash-client/src/NDTUtils.as
/trunk/flash-client/src/TestC2S.as
/trunk/flash-client/src/TestMETA.as
/trunk/flash-client/src/TestS2C.as
/trunk/flash-client/src/locale/en_US/DisplayMessages.properties
/trunk/src/Makefile.am
/trunk/src/clt_tests.h
/trunk/src/ndtptestconstants.h
/trunk/src/network.c
/trunk/src/network.h
/trunk/src/test_c2s_clt.c
/trunk/src/test_c2s_srv.c
/trunk/src/test_meta.h
/trunk/src/test_meta_clt.c
/trunk/src/test_meta_srv.c
/trunk/src/test_mid_clt.c
/trunk/src/test_mid_srv.c
/trunk/src/test_s2c_clt.c
/trunk/src/test_s2c_srv.c
/trunk/src/test_sfw.h
/trunk/src/test_sfw_clt.c
/trunk/src/test_sfw_srv.c
/trunk/src/testoptions.c
/trunk/src/testoptions.h
/trunk/src/web100-util.c
/trunk/src/web100clt.c
/trunk/src/web100srv.c
/trunk/src/web100srv.h

=======================================
--- /dev/null
+++ /trunk/Applet/src/edu/internet2/ndt/JSONUtils.java Wed May 28 11:17:18 2014 UTC
@@ -0,0 +1,69 @@
+package edu.internet2.ndt;
+
+import net.minidev.json.JSONObject;
+import net.minidev.json.JSONValue;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Created by Sebastian Malecki on 13.05.14.
+ */
+public class JSONUtils {
+
+ /**
+ * Function that return value from json object represented by jsontext containing a single message
+ * which is assigned to "msg" key.
+ * @param {String} JSON object
+ * @return {int} obtained value from JSON object
+ */
+ public static String getSingleMessage(String jsonTxt) {
+ return getValueFromJsonObj(jsonTxt, "msg");
+ }
+
+ /**
+ * Function that return value for given key from json object represented by jsontext
+ * @param {String} JSON object
+ * @param {int} key by which value should be obtained from JSON map
+ * @return {int} obtained value from JSON map
+ */
+ public static String getValueFromJsonObj(String jsonTxt, String key) {
+ JSONValue jsonParser = new JSONValue();
+ Map json = (Map)jsonParser.parse(new String(jsonTxt));
+ Iterator iter = json.entrySet().iterator();
+ while(iter.hasNext()){
+ Map.Entry entry = (Map.Entry)iter.next();
+ if (entry.getKey().equals(key)) {
+ return entry.getValue().toString();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Function that add new value to JSON map
+ * @param {String} JSON object
+ * @param {String} key by which value should be assigned to JSON map
+ * @param {String} value for given key
+ * @return {String} json object with added value.
+ */
+ public static String addValueToJsonObj(String jsonTxt, String key, String value) {
+ JSONValue jsonParser = new JSONValue();
+ JSONObject json = (JSONObject)jsonParser.parse(new
String(jsonTxt));
+ json.put(key, value);
+
+ return json.toJSONString();
+ }
+
+ /**
+ * Function that return json object represented by jsontext and
included
+ * single message assigned to "msg" key
+ * @param {byte[]} message which should be assigned to json object
+ * @return {byte[]} json object represented by jsontext and encodes into a sequence of bytes
+ */
+ public static byte[] createJsonObj(byte[] msg) {
+ JSONObject obj = new JSONObject();
+ obj.put("msg", new String(msg));
+
+ return obj.toJSONString().getBytes();
+ }
+}
=======================================
--- /dev/null
+++ /trunk/src/jsonutils.c Wed May 28 11:17:18 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
+++ /trunk/src/jsonutils.h Wed May 28 11:17:18 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_
=======================================
--- /trunk/Applet/MANIFEST.MF Wed Feb 5 13:38:45 2014 UTC
+++ /trunk/Applet/MANIFEST.MF Wed May 28 11:17:18 2014 UTC
@@ -1,3 +1,4 @@
Manifest-Version: 1.0
+Class-Path: lib/json-smart-1.1.1.jar
Created-By: My own fingers
Main-Class: edu.internet2.ndt.Tcpbw100
=======================================
--- /trunk/Applet/Makefile.am Wed Feb 12 07:16:35 2014 UTC
+++ /trunk/Applet/Makefile.am Wed May 28 11:17:18 2014 UTC
@@ -17,13 +17,17 @@

GCJLINK = $(GCJLD)
CLASSPATH_ENV =
-NDTGCJFLAGS = -d bin -sourcepath src
+jsonlib = lib/json-smart-1.1.1.jar
+NDTGCJFLAGS = -d bin -sourcepath src -cp src/edu/internet2/ndt/$(jsonlib)
NDTJARSIGNERFLAG = -keystore
TEMPDIRS = bin dist

ndtdir = $(prefix)/ndt
+jsonlibdir = $(ndtdir)/lib

-ndt_DATA = dist/Tcpbw100.jar
+ndt_DATA = dist/Tcpbw100.jar
+jsonlib_DATA = dist/$(jsonlib)
+
Tcpbw100dir = $(ndtdir)

noinst_PROGRAMS = Tcpbw100.jar
@@ -34,8 +38,7 @@
src/edu/internet2/ndt/UserAgentTools.java src/edu/internet2/ndt/NDTConstants.java \
src/edu/internet2/ndt/OsfwWorker.java src/edu/internet2/ndt/NewFrame.java \
src/edu/internet2/ndt/ResultsTextPane.java src/edu/internet2/ndt/MessageType.java \
- src/edu/internet2/ndt/NDTUtils.java
-
+ src/edu/internet2/ndt/NDTUtils.java src/edu/internet2/ndt/JSONUtils.java
Tcpbw100$(EXEEXT): $(Tcpbw100_OBJECTS) $(Tcpbw100_DEPENDENCIES)
@rm -f Tcpbw100$(EXEEXT)
@if test ! -s "classTcpbw100.stamp"; then \
@@ -88,8 +91,10 @@
Tcpbw100.jar: $(TEMPDIRS) all.class
cp -r src/edu/internet2/ndt/locale bin/edu/internet2/ndt/
$(NDTJAR) $(NDTJARFLAG) MANIFEST.MF dist/Tcpbw100.jar -C bin .
+ cp -r src/edu/internet2/ndt/lib dist
if test -n "$(CERTIFICATE_FILE)"; then \
$(NDTJARSIGNER) $(NDTJARSIGNERFLAG) $(CERTIFICATE_FILE) $(ndt_DATA) $(ALIAS); \
+ $(NDTJARSIGNER) $(NDTJARSIGNERFLAG) $(CERTIFICATE_FILE) dist/$(jsonlib) $(ALIAS); \
else :; fi
echo timestamp > classTcpbw100.stamp

=======================================
--- /trunk/Applet/src/edu/internet2/ndt/MessageType.java Tue Feb 4 10:07:07 2014 UTC
+++ /trunk/Applet/src/edu/internet2/ndt/MessageType.java Wed May 28 11:17:18 2014 UTC
@@ -16,5 +16,6 @@
public static final byte MSG_RESULTS = 8;
public static final byte MSG_LOGOUT = 9;
public static final byte MSG_WAITING = 10;
+ public static final byte MSG_EXTENDED_LOGIN = 11;

}
=======================================
--- /trunk/Applet/src/edu/internet2/ndt/Protocol.java Tue Feb 4 10:07:07 2014 UTC
+++ /trunk/Applet/src/edu/internet2/ndt/Protocol.java Wed May 28 11:17:18 2014 UTC
@@ -14,6 +14,7 @@
public class Protocol {
private InputStream _ctlInStream;
private OutputStream _ctlOutStream;
+ private boolean jsonSupport = true;

/**
* Constructor that accepts socket over which to communicate as
parameter
@@ -44,6 +45,42 @@
byte[] tab = new byte[] { bParamToSend };
send_msg(bParamType, tab);
}
+
+ /**
+ * Send message given its Type and data byte
+ *
+ * @param bParamType
+ * Control Message Type
+ * @param bParamToSend
+ * Data value to send
+ * @throws IOException
+ * If data cannot be successfully written to the Output
Stream
+ *
+ * */
+ public void send_json_msg(byte bParamType, byte bParamToSend) throws IOException {
+ byte[] tab = new byte[] { bParamToSend };
+ send_json_msg(bParamType, tab);
+ }
+
+ /**
+ * Send protocol messages given their type and data byte array
+ *
+ * @param bParamType
+ * Control Message Type
+ * @param bParamToSend
+ * Data value array to send
+ * @throws IOException
+ * If data cannot be successfully written to the Output
Stream
+ *
+ * */
+ public void send_json_msg(byte bParamType, byte[] bParamToSend)
+ throws IOException {
+ if (jsonSupport) {
+ send_msg(bParamType,
JSONUtils.createJsonObj(bParamToSend));
+ } else {
+ send_msg(bParamType, bParamToSend);
+ }
+ }

/**
* Send protocol messages given their type and data byte array
@@ -149,5 +186,9 @@
e.printStackTrace();
}
}
+
+ public void setJsonSupport(boolean jsonSupport) {
+ this.jsonSupport = jsonSupport;
+ }

} // end class Protocol
=======================================
--- /trunk/Applet/src/edu/internet2/ndt/Tcpbw100.java Fri Mar 21 10:33:50 2014 UTC
+++ /trunk/Applet/src/edu/internet2/ndt/Tcpbw100.java Wed May 28 11:17:18 2014 UTC
@@ -167,7 +167,7 @@
NewFrame _frameWeb100Vars, _frameDetailedStats, _frameOptions;
// String s; Unused, commenting out
double _dTime;
- int _s2cspdUpdateTime = 500, _c2sspdUpdateTime = 500; // ms
+ int _s2cspdUpdateTime = 500, _c2sspdUpdateTime = 500; // ms
int _iECNEnabled, _iNagleEnabled, MSSSent, MSSRcvd;
int _iSACKEnabled, _iTimestampsEnabled, _iWinScaleRcvd,
_iWinScaleSent;
int _iFastRetran, _iAckPktsOut, _iSmoothedRTT, _iCurrentCwnd,
_iMaxCwnd;
@@ -177,7 +177,7 @@
int _iSumRTT, _iCountRTT, _iCurrentMSS, _iTimeouts, _iPktsRetrans;
int _iSACKsRcvd, _iDupAcksIn, _iMaxRwinRcvd, _iMaxRwinSent;
int _iDataPktsOut, _iRcvbuf, _iSndbuf, _iAckPktsIn;
- long _iDataBytesOut;
+ long _iDataBytesOut;
int _iPktsOut, _iCongestionSignals, _iRcvWinScale;
// int _iPkts, _iLength=8192, _iCurrentRTO;
int _iPkts, _iLength = NDTConstants.PREDEFINED_BUFFER_SIZE,
_iCurrentRTO;
@@ -191,7 +191,7 @@
double _dS2cspd, _dC2sspd, _dSc2sspd, _dSs2cspd;
int _iSsndqueue;
double _dSbytes;
- byte[] _yabuff2Write;
+ byte[] _yabuff2Write;

/**
* Added by Martin Sandsmark, UNINETT AS Internationalization
@@ -265,7 +265,7 @@
private String pub_AccessTech = "unknown";
private String pub_natBox = "unknown";
private int pub_DupAcksOut = 0;
- private int pub_DupAcksIn = 0;
+ private int pub_DupAcksIn = 0;
private Date pub_TimeStamp;
private String pub_isReady = new String("no");
private String pub_clientIP = "unknown";
@@ -279,6 +279,8 @@
private long pub_bytes = 0;
private String _sIsAutoRun;
private String _sUserAgent = null;
+ private boolean jsonSupport = true;
+ private boolean retry = false;

/**
* public static void main for invoking as an Application
@@ -298,9 +300,9 @@
}
});
applet._bIsApplication = true;
- if (args.length > 1) {
- applet._sClient = args[1];
- }
+ if (args.length > 1) {
+ applet._sClient = args[1];
+ }
frame.getContentPane().add(applet);
frame.setSize(700, 320);
applet.init();
@@ -418,7 +420,7 @@
}

public String get_optimalRcvrBuffer() {
- //buffer size in bits
+ //buffer size in bits
return Integer.toString(pub_MaxRwinRcvd *
NDTConstants.KILO_BITS);
}

@@ -434,9 +436,9 @@
return Integer.toString(pub_DupAcksOut);
}

- public String get_DupAcksIn() {
- return Integer.toString(pub_DupAcksIn);
- }
+ public String get_DupAcksIn() {
+ return Integer.toString(pub_DupAcksIn);
+ }

public String get_TimeStamp() {
String result = "unknown";
@@ -482,7 +484,7 @@
}

public String get_instSpeed() {
- //Get speed in bits, hence multiply by 8 for byte->bit
conversion
+ //Get speed in bits, hence multiply by 8 for byte->bit
conversion
return Double.toString((NDTConstants.EIGHT * pub_bytes)
/ (System.currentTimeMillis() - pub_time));
}
@@ -521,7 +523,7 @@
* Set Client->Server fire-wall test results.
*
* @param iParamC2SRes
- * integer indicating C->S test results
+ * integer indicating C->S test results
* */
public void setC2sSFWTestResults(int iParamC2SRes) {
this._iC2sSFWResult = iParamC2SRes;
@@ -891,7 +893,7 @@
_chkboxPreferIPv6 = new JCheckBox(
_resBundDisplayMsgs.getString("preferIPv6"));
_chkboxPreferIPv6.setSelected(true);
- _chkboxPreferIPv6.addActionListener(this);
+ _chkboxPreferIPv6.addActionListener(this);
// 2. Conduct default tests?
_chkboxDefaultTest = new JCheckBox(

_resBundDisplayMsgs.getString("defaultTests"));
@@ -1122,10 +1124,10 @@
_frameWeb100Vars.setResizable(true);
_frameWeb100Vars.setVisible(true);

- if (NDTUtils.isNotEmpty(_txtDiagnosis.getText())) {
- // enable copy button only if there is details informations
- _buttonDetailsCopy.setEnabled(true);
- }
+ if (NDTUtils.isNotEmpty(_txtDiagnosis.getText())) {
+ // enable copy button only if there is
details informations
+ _buttonDetailsCopy.setEnabled(true);
+ }
}
// "More Details" Web100 variables window to be closed
else if (source == _buttonDetailsDismiss) {
@@ -1143,8 +1145,8 @@
}
// "Statistics" copy button functionality
else if (source == _buttonStatsCopy) {
- copy(_txtStatistics);
- }
+ copy(_txtStatistics);
+ }
// Show "statistics" window
else if (source == _buttonStatistics) {
_frameDetailedStats.setResizable(true);
@@ -1157,7 +1159,7 @@
}
// prefer IPv6 checkbox
else if (source == _chkboxPreferIPv6) {
- setsHostName(sHostName);
+ setsHostName(sHostName);
}
// mail to functionality
else if (source == _buttonMailTo) {
@@ -1216,33 +1218,31 @@
} // end mail-to functionality
} // actionPerformed()

- /**
- * Copy text from JTextarea to clipboard
- *
- * @param _txt
- * Source copied text to clipboard
- * */
- private void copy (JTextArea _txt) {
- try {
- Clipboard clipbd = getToolkit().getSystemClipboard();
- _bCanCopy = true;
- String sTemp = _txt.getText();
- StringSelection ssTemp = new StringSelection(sTemp);
- clipbd.setContents(ssTemp, ssTemp);
- } catch (SecurityException e) {
- _bCanCopy = false;
- // this Exception is only when the client cannot copy
- // some data, and is acted on by disabling the
- // copy button.
- System.err.println(" You may not have some security Permissions. Please confirm");
- }
- }
+ /**
+ * Copy text from JTextarea to clipboard
+ *
+ * @param _txt Source copied text to clipboard
+ * */
+ private void copy (JTextArea _txt) {
+ try {
+ Clipboard clipbd = getToolkit().getSystemClipboard();
+ _bCanCopy = true;
+ String sTemp = _txt.getText();
+ StringSelection ssTemp = new StringSelection(sTemp);
+ clipbd.setContents(ssTemp, ssTemp);
+ } catch (SecurityException e) {
+ _bCanCopy = false;
+ // this Exception is only when the client cannot copy
+ // some data, and is acted on by disabling the
+ // copy button.
+ System.err.println(" You may not have some security Permissions. Please confirm");
+ }
+ }

/**
* Display current status in Applet window.
*
- * @param msg
- * String value of status
+ * @param msg String value of status
* */
public void showStatus(String msg) {
if (!_bIsApplication) {
@@ -1263,7 +1263,7 @@
* @throws IOException
* when sending/receiving messages from server fails
* @see Protocol#recv_msg(Message msgParam)
- * @see Protocol#send_msg(byte bParamType, byte[] baParamTab) These methods
+ * @see Protocol#send_json_msg(byte bParamType, byte[] baParamTab) These methods
* indicate more information about IOException
* */

@@ -1292,7 +1292,7 @@
// as a failure
if (paramProtoObj.recv_msg(msg) != NDTConstants.PROTOCOL_MSG_READ_SUCCESS) {
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1303,14 +1303,14 @@
+ "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
}

// get port number that server wants client to bind
to for this test
- int midport = Integer.parseInt(new
String(msg.getBody()));
+ int midport = parseMsgBodyToInt(new
String(msg.getBody()));

// connect to server using port obtained above
Socket midSrvrSockObj = null;
@@ -1377,7 +1377,7 @@

// msg not received correctly
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1391,7 +1391,7 @@
// get error code
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -1405,31 +1405,68 @@

//
Double.toString(_dS2cspd*

//
1000);
System.out.println("Sending '" + tmpstr4 + "' back to
server");
- paramProtoObj.send_msg(MessageType.TEST_MSG,
tmpstr4.getBytes());
+ paramProtoObj.send_json_msg(MessageType.TEST_MSG,
tmpstr4.getBytes());

// Append server address as seen by the client
// to the Test Results obtained from server
- try {
- _sMidBoxTestResult += midSrvrSockObj.getInetAddress() +
";";
- } catch (SecurityException e) {
- System.err
- .println("Unable to obtain Servers
IP addresses: using "
- + sHostName);
- _sErrMsg = "getInetAddress() called failed\n";
- _sMidBoxTestResult += sHostName + ";";
- _resultsTxtPane.append(_resBundDisplayMsgs
- .getString("lookupError") +
"\n");
- }
+ if (jsonSupport) {
+ String sClientSideServerIp;
+ try {
+ // Get Client reported server IP
+ sClientSideServerIp =
midSrvrSockObj.getInetAddress() + "";
+ } catch (SecurityException e) {
+ System.err
+ .println("Unable to obtain
Servers IP addresses: using "
+ +
sHostName);
+ _sErrMsg = "getInetAddress() called
failed\n";
+ sClientSideServerIp = sHostName;
+
_resultsTxtPane.append(_resBundDisplayMsgs
+ .getString("lookupError") +
"\n");
+ }
+ int k = sClientSideServerIp.indexOf("/");
+ sClientSideServerIp =
sClientSideServerIp.substring(k + 1);
+ _sMidBoxTestResult = JSONUtils.addValueToJsonObj(_sMidBoxTestResult, "ClientSideServerIp", sClientSideServerIp);
+
+
+ // Append local address to the Test results
obtained from server
+ System.err.println("calling
in2Socket.getLocalAddress()");
+ String sClientSideClientIp;
+ try {
+ sClientSideClientIp =
midSrvrSockObj.getLocalAddress() + ";";
+ } catch (SecurityException e) {
+ System.err
+ .println("Unable to obtain
local IP address: using 127.0.0.1");
+ _sErrMsg = "getLocalAddress() call
failed\n";
+ sClientSideClientIp =
NDTConstants.LOOPBACK_ADDRS_STRING + ";";
+ }
+
+ k = sClientSideClientIp.indexOf("/");
+ sClientSideClientIp =
sClientSideClientIp.substring(k + 1);
+ _sMidBoxTestResult = JSONUtils.addValueToJsonObj(_sMidBoxTestResult, "ClientSideClientIp", sClientSideClientIp);
+ } else {
+ try {
+ _sMidBoxTestResult +=
midSrvrSockObj.getInetAddress() + ";";
+ } catch (SecurityException e) {
+ System.err
+ .println("Unable to obtain
Servers IP addresses: using "
+ +
sHostName);
+ _sErrMsg = "getInetAddress() called
failed\n";
+ _sMidBoxTestResult += sHostName + ";";
+
_resultsTxtPane.append(_resBundDisplayMsgs
+ .getString("lookupError") +
"\n");
+ }
+

- // Append local address to the Test results obtained
from server
- System.err.println("calling
in2Socket.getLocalAddress()");
- try {
- _sMidBoxTestResult += midSrvrSockObj.getLocalAddress()
+ ";";
- } catch (SecurityException e) {
- System.err
- .println("Unable to obtain local
IP address: using 127.0.0.1");
- _sErrMsg = "getLocalAddress() call failed\n";
- _sMidBoxTestResult +=
NDTConstants.LOOPBACK_ADDRS_STRING + ";";
+ // Append local address to the Test results
obtained from server
+ System.err.println("calling
in2Socket.getLocalAddress()");
+ try {
+ _sMidBoxTestResult +=
midSrvrSockObj.getLocalAddress() + ";";
+ } catch (SecurityException e) {
+ System.err
+ .println("Unable to obtain
local IP address: using 127.0.0.1");
+ _sErrMsg = "getLocalAddress() call
failed\n";
+ _sMidBoxTestResult +=
NDTConstants.LOOPBACK_ADDRS_STRING + ";";
+ }
}

// wrap up test set up
@@ -1440,7 +1477,7 @@
// Expect TEST_FINALIZE message from server
if (paramProtoObj.recv_msg(msg) != NDTConstants.PROTOCOL_MSG_READ_SUCCESS) {
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1452,7 +1489,7 @@
_sErrMsg =
_resBundDisplayMsgs.getString("mboxWrongMessage");
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -1472,14 +1509,14 @@
* server. Tests are performed in both directions.
*
* @param protocolObj
- * Protocol Object used for message exchange
+ * Protocol Object used for message exchange
* @return boolean, true if test was not completed, false if test was
* completed.
* @throws IOException
* when sending/receiving messages from server fails. See the @see
* methods for more information on causes for Exception.
* @see Protocol#recv_msg(Message msgParam)
- * @see Protocol#send_msg(byte bParamType, byte[] baParamTab)
+ * @see Protocol#send_json_msg(byte bParamType, byte[] baParamTab)
*
* */
public boolean test_sfw(Protocol protocolObj) throws IOException {
@@ -1499,7 +1536,7 @@
// Message received in error?
if (protocolObj.recv_msg(msg) != NDTConstants.PROTOCOL_MSG_READ_SUCCESS) {
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1512,7 +1549,7 @@
+ "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -1526,14 +1563,25 @@
// single space

int iSrvPort, iTestTime;
- try {
- int k = sMsgBody.indexOf(" ");
- iSrvPort =
Integer.parseInt(sMsgBody.substring(0, k));
- iTestTime =
Integer.parseInt(sMsgBody.substring(k + 1));
- } catch (Exception e) {
- _sErrMsg =
_resBundDisplayMsgs.getString("sfwWrongMessage")
- + "\n";
- return true;
+ if (jsonSupport) {
+ try {
+ iSrvPort = Integer.parseInt(JSONUtils.getValueFromJsonObj(new String(msg.getBody()), "empheralPortNumber"));
+ iTestTime = Integer.parseInt(JSONUtils.getValueFromJsonObj(new String(msg.getBody()), "testTime"));
+ } catch (Exception e) {
+ _sErrMsg =
_resBundDisplayMsgs.getString("sfwWrongMessage")
+ + "\n";
+ return true;
+ }
+ } else {
+ try {
+ int k = sMsgBody.indexOf(" ");
+ iSrvPort =
Integer.parseInt(sMsgBody.substring(0, k));
+ iTestTime =
Integer.parseInt(sMsgBody.substring(k + 1));
+ } catch (Exception e) {
+ _sErrMsg =
_resBundDisplayMsgs.getString("sfwWrongMessage")
+ + "\n";
+ return true;
+ }
}

System.out.println("SFW: port=" + iSrvPort);
@@ -1560,7 +1608,7 @@

System.out.println("SFW: oport=" +
srvSocket.getLocalPort());
// Send TEST_MSG
- protocolObj.send_msg(MessageType.TEST_MSG,
+ protocolObj.send_json_msg(MessageType.TEST_MSG,

Integer.toString(srvSocket.getLocalPort()).getBytes());

// Expect a TEST_START message from the server
@@ -1569,7 +1617,7 @@


// receiving


// message
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1578,7 +1626,7 @@
_sErrMsg =
_resBundDisplayMsgs.getString("sfwWrongMessage");
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -1598,9 +1646,10 @@
iTestTime *
NDTConstants.KILO);

Protocol sfwCtl = new Protocol(sfwSocket);
+ sfwCtl.setJsonSupport(jsonSupport);

// send a simple string message over this
socket
- sfwCtl.send_msg(MessageType.TEST_MSG, new
String(
+ sfwCtl.send_json_msg(MessageType.TEST_MSG,
new String(

NDTConstants.SFW_PREDEFINED_TEST_MESSAGE).getBytes());
} catch (Exception e) {
e.printStackTrace();
@@ -1613,7 +1662,7 @@


// reading


// Protocol
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1624,7 +1673,7 @@
+ "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -1632,7 +1681,7 @@

// This is an integer with value 0/1/2/3 indicating
status of a
// firewall's presence
- _iC2sSFWResult = Integer.parseInt(new
String(msg.getBody()));
+ _iC2sSFWResult = parseMsgBodyToInt(new
String(msg.getBody()));

// Sleep for some time
osfwTest.finalize();
@@ -1643,7 +1692,7 @@


// reading


// message
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1654,7 +1703,7 @@
+ "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -1682,7 +1731,7 @@
* @throws IOException
* when sending/receiving messages from server fails
* @see Protocol#recv_msg(Message msgParam)
- * @see Protocol#send_msg(byte bParamType, byte[] baParamTab)
+ * @see Protocol#send_json_msg(byte bParamType, byte[] baParamTab)
*
*/
public boolean test_c2s(Protocol paramProtoObj) throws IOException {
@@ -1706,7 +1755,7 @@


// receive/read


// error
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1718,13 +1767,13 @@
.getString("outboundWrongMessage") +
"\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
}
// Server sends port number to bind to in the
TEST_PREPARE
- int iC2sport = Integer.parseInt(new
String(msg.getBody()));
+ int iC2sport = parseMsgBodyToInt(new
String(msg.getBody()));

// client connects to this port
final Socket outSocket;
@@ -1755,7 +1804,7 @@


// reading/receiving


// message
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1766,7 +1815,7 @@
.getString("outboundWrongMessage") +
"\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -1779,7 +1828,7 @@
if (c == 'z') {
c = '0';
}
- _yabuff2Write[i] = c++;
+ _yabuff2Write[i] = c++;
}
System.err.println("******Send buffer size =" + i);

@@ -1810,14 +1859,14 @@
}
}.start();

- Timer c2sspdUpdateTimer = new Timer();
- c2sspdUpdateTimer.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- pub_c2sspd = ((NDTConstants.EIGHT * _iPkts * _yabuff2Write.length) / NDTConstants.KILO)
- / (System.currentTimeMillis() - _dTime);
- }
- }, 100, _c2sspdUpdateTime);
+ Timer c2sspdUpdateTimer = new Timer();
+ c2sspdUpdateTimer.scheduleAtFixedRate(new TimerTask()
{
+ @Override
+ public void run() {
+ pub_c2sspd = ((NDTConstants.EIGHT * _iPkts * _yabuff2Write.length) / NDTConstants.KILO)
+ /
(System.currentTimeMillis() - _dTime);
+ }
+ }, 100, _c2sspdUpdateTime);

// While the 10 s timer ticks, write buffer data into
server socket
while (true) {
@@ -1844,7 +1893,7 @@
pub_bytes = (_iPkts * _iLength);
}

- c2sspdUpdateTimer.cancel();
+ c2sspdUpdateTimer.cancel();
_dTime = System.currentTimeMillis() - _dTime;
System.err.println(_dTime + " millisec test completed" +
","
+ _yabuff2Write.length + ","+ _iPkts);
@@ -1869,7 +1918,7 @@


// reading/receiving


// data
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1880,13 +1929,19 @@

.getString("outboundWrongMessage");
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
}
// Get throughput as calculated by server
- String tmpstr3 = new String(msg.getBody());
+ String tmpstr3;
+ if (jsonSupport) {
+ tmpstr3 = JSONUtils.getSingleMessage(new
String(msg.getBody()));
+ } else {
+ tmpstr3 = new String(msg.getBody());
+ }
+
_dSc2sspd = Double.parseDouble(tmpstr3) /
NDTConstants.KILO;

// Print results in the most convenient units (kbps
or Mbps)
@@ -1910,7 +1965,7 @@
if (paramProtoObj.recv_msg(msg) != NDTConstants.PROTOCOL_MSG_READ_SUCCESS) { // read/receive


// error
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1921,7 +1976,7 @@

.getString("outboundWrongMessage");
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true; // true indicates test incomplete
@@ -1943,7 +1998,7 @@
* @throws IOException
* when sending/receiving messages from server fails
* @see Protocol#recv_msg(Message msgParam)
- * @see Protocol#send_msg(byte bParamType, byte[] baParamTab)
+ * @see Protocol#send_json_msg(byte bParamType, byte[] baParamTab)
*
* */
public boolean test_s2c(Protocol paramProtoObj, Socket paramSocketObj)
@@ -1966,7 +2021,7 @@
if (paramProtoObj.recv_msg(msg) != NDTConstants.PROTOCOL_MSG_READ_SUCCESS) { // read/receive


// error
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -1976,13 +2031,13 @@
+ "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
}
// get port to bind to for S2C tests
- int iS2cport = Integer.parseInt(new
String(msg.getBody()));
+ int iS2cport = parseMsgBodyToInt(new
String(msg.getBody()));

// Create socket and bind to port as instructed by
server
Socket inSocket;
@@ -2010,7 +2065,7 @@
if (paramProtoObj.recv_msg(msg) != NDTConstants.PROTOCOL_MSG_READ_SUCCESS) { // erroneous


// read/receive
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -2020,7 +2075,7 @@
_sErrMsg =
_resBundDisplayMsgs.getString("inboundWrongMessage") + "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -2031,14 +2086,14 @@
_dTime = System.currentTimeMillis();
pub_time = _dTime;

- Timer s2cspdUpdateTimer = new Timer();
- s2cspdUpdateTimer.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- pub_s2cspd = ((NDTConstants.EIGHT * pub_bytes) / NDTConstants.KILO)
- / (System.currentTimeMillis() - _dTime);
- }
- }, 100, _s2cspdUpdateTime);
+ Timer s2cspdUpdateTimer = new Timer();
+ s2cspdUpdateTimer.scheduleAtFixedRate(new TimerTask()
{
+ @Override
+ public void run() {
+ pub_s2cspd = ((NDTConstants.EIGHT *
pub_bytes) / NDTConstants.KILO)
+ /
(System.currentTimeMillis() - _dTime);
+ }
+ }, 100, _s2cspdUpdateTime);

// read data sent by server
try {
@@ -2056,8 +2111,8 @@
_sErrMsg = "Server Failed while reading socket
data\n";
return true;
} finally {
- s2cspdUpdateTimer.cancel();
- }
+ s2cspdUpdateTimer.cancel();
+ }

// get time duration during which bytes were received
_dTime = System.currentTimeMillis() - _dTime;
@@ -2081,7 +2136,7 @@


// of


// msg
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -2091,27 +2146,43 @@
+ "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
}
// get data from payload
- try {
- String tmpstr3 = new String(msg.getBody());
- int k1 = tmpstr3.indexOf(" ");
- int k2 = tmpstr3.substring(k1 + 1).indexOf("
");
- _dSs2cspd =
Double.parseDouble(tmpstr3.substring(0, k1))
- / NDTConstants.KILO;
- _iSsndqueue =
Integer.parseInt(tmpstr3.substring(k1 + 1)
- .substring(0, k2));
- _dSbytes =
Double.parseDouble(tmpstr3.substring(k1 + 1)
- .substring(k2 + 1));
- } catch (Exception e) {
- e.printStackTrace();
- _sErrMsg =
_resBundDisplayMsgs.getString("inboundWrongMessage")
- + "\n";
- return true;
+ if (jsonSupport) {
+ try {
+ String tmpstr3 = new
String(msg.getBody());
+ _dSs2cspd = Double.parseDouble(JSONUtils.getValueFromJsonObj(tmpstr3, "ThroughputValue"))
+ / NDTConstants.KILO;
+ _iSsndqueue = Integer.parseInt(JSONUtils.getValueFromJsonObj(tmpstr3, "UnsentDataAmount"));
+ _dSbytes = Double.parseDouble(JSONUtils.getValueFromJsonObj(tmpstr3, "TotalSentByte"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ _sErrMsg =
_resBundDisplayMsgs.getString("inboundWrongMessage")
+ + "\n";
+ return true;
+ }
+ }
+ else {
+ try {
+ String tmpstr3 = new
String(msg.getBody());
+ int k1 = tmpstr3.indexOf(" ");
+ int k2 = tmpstr3.substring(k1 +
1).indexOf(" ");
+ _dSs2cspd =
Double.parseDouble(tmpstr3.substring(0, k1))
+ / NDTConstants.KILO;
+ _iSsndqueue =
Integer.parseInt(tmpstr3.substring(k1 + 1)
+ .substring(0, k2));
+ _dSbytes =
Double.parseDouble(tmpstr3.substring(k1 + 1)
+ .substring(k2 + 1));
+ } catch (Exception e) {
+ e.printStackTrace();
+ _sErrMsg =
_resBundDisplayMsgs.getString("inboundWrongMessage")
+ + "\n";
+ return true;
+ }
}

// Represent throughput using optimal units (kbps /
mbps)
@@ -2141,7 +2212,7 @@
buff = Double.toString(_dS2cspd *
NDTConstants.KILO).getBytes();
String tmpstr4 = new String(buff, 0, buff.length);
System.out.println("Sending '" + tmpstr4 + "' back to
server");
- paramProtoObj.send_msg(MessageType.TEST_MSG, buff);
+ paramProtoObj.send_json_msg(MessageType.TEST_MSG,
buff);

// get web100 variables from server
_sTestResults = "";
@@ -2159,7 +2230,7 @@


// correctly
_sErrMsg = _resBundDisplayMsgs

.getString("protocolError")
- +
Integer.parseInt(new String(msg.getBody()),
+ +
parseMsgBodyToInt(new String(msg.getBody()),
16) +
" instead\n";
return true;
}
@@ -2176,14 +2247,18 @@

.getString("inboundWrongMessage") + "\n";
if (msg.getType() ==
MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG:
"
- +
Integer.parseInt(
+ +
parseMsgBodyToInt(

new String(msg.getBody()), 16)
+
"\n";
}
return true;
}
// Get all web100 variables as
name-value string pairs
- _sTestResults += new
String(msg.getBody());
+ if (jsonSupport) {
+ _sTestResults += JSONUtils.getSingleMessage(new String(msg.getBody()));
+ } else {
+ _sTestResults += new
String(msg.getBody());
+ }
i++;
} // end for
} catch (IOException ioExcep) {
@@ -2211,7 +2286,7 @@
* @throws IOException
* when sending/receiving messages from server fails
* @see Protocol#recv_msg(Message msgParam)
- * @see Protocol#send_msg(byte bParamType, byte[] baParamTab) These methods
+ * @see Protocol#send_json_msg(byte bParamType, byte[] baParamTab) These methods
* indicate more information about IOException
* */
public boolean test_meta(Protocol paramProtoObj, String application) throws IOException {
@@ -2234,7 +2309,7 @@


// received


// correctly
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -2244,7 +2319,7 @@
+ "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -2257,7 +2332,7 @@


// read/received


// correctly
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -2270,7 +2345,7 @@

if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -2283,24 +2358,24 @@
// Note that there are length constraints to keys-
values: 64/256
// characters respectively
System.err.println("USERAGENT " + getUserAgent());
- paramProtoObj.send_msg(MessageType.TEST_MSG,
+ paramProtoObj.send_json_msg(MessageType.TEST_MSG,
(NDTConstants.META_CLIENT_OS + ":" +
System

.getProperty("os.name")).getBytes());
- paramProtoObj.send_msg(MessageType.TEST_MSG,
+ paramProtoObj.send_json_msg(MessageType.TEST_MSG,
(NDTConstants.META_BROWSER_OS + ":" +
UserAgentTools

.getBrowser(getUserAgent())[2]).getBytes());
- paramProtoObj.send_msg(MessageType.TEST_MSG,
+ paramProtoObj.send_json_msg(MessageType.TEST_MSG,
(NDTConstants.META_CLIENT_KERNEL_VERSION +
":" + System

.getProperty("os.version")).getBytes());
- paramProtoObj.send_msg(MessageType.TEST_MSG,
- (NDTConstants.META_CLIENT_VERSION + ":" + NDTConstants.VERSION).getBytes());
- paramProtoObj.send_msg(MessageType.TEST_MSG,
- (NDTConstants.META_CLIENT_APPLICATION + ":" + application) .getBytes());
+ paramProtoObj.send_json_msg(MessageType.TEST_MSG,
+ (NDTConstants.META_CLIENT_VERSION + ":" + NDTConstants.VERSION).getBytes());
+ paramProtoObj.send_json_msg(MessageType.TEST_MSG,
+ (NDTConstants.META_CLIENT_APPLICATION + ":" + application) .getBytes());

// 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
- paramProtoObj.send_msg(MessageType.TEST_MSG, new
byte[0]);
+ paramProtoObj.send_json_msg(MessageType.TEST_MSG, new
byte[0]);

// The server now closes the META test session by
sending a
// TEST_FINALIZE message
@@ -2311,7 +2386,7 @@


// read/received


// properly
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
return true;
}
@@ -2321,7 +2396,7 @@
_sErrMsg =
_resBundDisplayMsgs.getString("metaWrongMessage");
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: "
- +
Integer.parseInt(new String(msg.getBody()), 16)
+ +
parseMsgBodyToInt(new String(msg.getBody()), 16)
+ "\n";
}
return true;
@@ -2347,7 +2422,7 @@
* @throws IOException
* when sending/receiving messages from server fails
* @see Protocol#recv_msg(Message msgParam)
- * @see Protocol#send_msg(byte bParamType, byte[] baParamTab)
+ * @see Protocol#send_json_msg(byte bParamType, byte[] baParamTab)
*
*/
public void dottcp(StatusPanel sPanel) throws IOException {
@@ -2437,8 +2512,11 @@

// write our test suite request by sending a login message
// _yTests indicates the requested test-suite
+ byte [] send = new byte[NDTConstants.VERSION.length()+1];
+ send[0] = _yTests;
+ System.arraycopy(NDTConstants.VERSION.getBytes(), 0, send, 1, NDTConstants.VERSION.length());

- protocolObj.send_msg(MessageType.MSG_LOGIN, _yTests);
+ protocolObj.send_json_msg(MessageType.MSG_EXTENDED_LOGIN,
send);

// read the specially crafted data that kicks off the old
clients
if (protocolObj.readn(msg, 13) != 13) {
@@ -2455,7 +2533,7 @@
// session starts now, return
if (protocolObj.recv_msg(msg) != NDTConstants.PROTOCOL_MSG_READ_SUCCESS) {
_sErrMsg =
_resBundDisplayMsgs.getString("protocolError")
- + Integer.parseInt(new
String(msg.getBody()), 16)
+ + parseMsgBodyToInt(new
String(msg.getBody()), 16)
+ " instead\n";
_bFailed = true;
return;
@@ -2467,15 +2545,67 @@
// below.
// Any other type of message at this stage is
incorrect
if (msg.getType() != MessageType.SRV_QUEUE) {
- _sErrMsg =
_resBundDisplayMsgs.getString("loggingWrongMessage")
- + "\n";
- _bFailed = true;
- return;
+ if (!retry && !new String(msg.getBody()).equals("Invalid login message.")) {
+ jsonSupport = false;
+ retry = true;
+ try {
+
+ // RAC Debug message
+
_resultsTxtPane.append(_resBundDisplayMsgs
+
.getString("unsupportedMsgExtendedLogin")
+ + "\n");
+ // create socket to host
specified by user and the default port
+ ctlSocket = new
Socket(hostAddress, ctlport);
+ } catch (UnknownHostException e) {
+ System.err.println("Don't know
about host: " + sHostName);
+ _sErrMsg =
_resBundDisplayMsgs.getString("unknownServer") + "\n";
+ _bFailed = true;
+ return;
+ } catch (IOException e) {
***The diff for this file has been truncated for email.***
=======================================
--- /branches/Issue146/Applet/src/edu/internet2/ndt/lib/json-smart-1.1.1.jar Tue May 27 14:19:34 2014 UTC
+++ /trunk/Applet/src/edu/internet2/ndt/lib/json-smart-1.1.1.jar Wed May 28 11:17:18 2014 UTC
Binary file, no diff available.
=======================================
--- /trunk/Applet/src/edu/internet2/ndt/locale/Tcpbw100_msgs_en_US.properties Tue Mar 4 08:44:05 2014 UTC
+++ /trunk/Applet/src/edu/internet2/ndt/locale/Tcpbw100_msgs_en_US.properties Wed May 28 11:17:18 2014 UTC
@@ -210,6 +210,7 @@
unknownID = Unknown test ID
unknownServer = Unknown server
unsupportedClient = Information: The server does not support this command line client
+unsupportedMsgExtendedLogin = Information: The server does not support MSG_EXTENDED_LOGIN message. Trying to connect using MSG_LOGIN.
vendor = Vendor
version = Version
versionWrongMessage = Negotiating NDT version: Received wrong type of the message
=======================================
--- /trunk/configure.ac Mon Mar 24 08:50:46 2014 UTC
+++ /trunk/configure.ac Wed May 28 11:17:18 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 ""
+
+
=======================================
--- /trunk/flash-client/src/Handshake.as Tue Apr 15 22:51:33 2014 UTC
+++ /trunk/flash-client/src/Handshake.as Wed May 28 11:17:18 2014 UTC
@@ -40,6 +40,7 @@
private var _testsRequestByClient:int;
// Has the client already received a wait message?
private var _isNotFirstWaitFlag:Boolean;
+ private static var _loginRetried:Boolean = false;

public function Handshake(ctlSocket:Socket, testsRequestByClient:int,
callerObject:NDTPController) {
@@ -55,9 +56,14 @@
var clientVersion:String = NDTConstants.CLIENT_VERSION;

msgBody.writeByte(_testsRequestByClient);
- msgBody.writeMultiByte(clientVersion, "us-ascii");
+ if (_loginRetried) {
+ _msg = new Message(MessageType.MSG_LOGIN, msgBody, false);
+ } else {
+ msgBody.writeMultiByte(clientVersion, "us-ascii");
+ _msg = new Message(MessageType.MSG_EXTENDED_LOGIN, msgBody,
+ Main.jsonSupport);
+ }

- _msg = new Message(MessageType.MSG_EXTENDED_LOGIN, msgBody);
if (!_msg.sendMessage(_ctlSocket)) {
failHandshake();
}
@@ -101,7 +107,7 @@
private function kickOldClients():void {
_msg = new Message();
if (!_msg.readBody(_ctlSocket, NDTConstants.KICK_OLD_CLIENTS_MSG_LENGTH))
- return;
+ return;

_msg = new Message();
_testStage = SRV_QUEUE1;
@@ -133,13 +139,30 @@
return;

if (_msg.type != MessageType.SRV_QUEUE) {
- TestResults.appendErrMsg(ResourceManager.getInstance().getString(
- NDTConstants.BUNDLE_NAME, "loggingWrongMessage", null,
- Main.locale));
- failHandshake();
+ if (!_loginRetried) {
+ removeOnReceivedDataListener();
+ TestResults.appendDebugMsg(ResourceManager.getInstance().getString(
+ NDTConstants.BUNDLE_NAME,
+ "loggingUsingExtendedMsgFailed", null,
+ Main.locale));
+ // try to login using old MSG_LOGIN message
+ _testStage = KICK_CLIENTS;
+ _loginRetried = true;
+ Main.jsonSupport = false;
+ _callerObj.startNDTTest();
+ } else {
+ TestResults.appendErrMsg(ResourceManager.getInstance().getString(
+ NDTConstants.BUNDLE_NAME, "loggingWrongMessage", null,
+ Main.locale));
+ failHandshake();
+ }
}

- var waitFlagString:String = new String(_msg.body);
+ var waitFlagString:String = Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body);
TestResults.appendDebugMsg("Received wait flag = " + waitFlagString);
var waitFlag:int = parseInt(waitFlagString);

@@ -202,7 +225,8 @@
// Client should respond with a MSG_WAITING message.
var _msgBody:ByteArray = new ByteArray();
_msgBody.writeByte(_testsRequestByClient);
- _msg = new Message(MessageType.MSG_WAITING, _msgBody);
+ _msg = new Message(MessageType.MSG_WAITING, _msgBody,
+ Main.jsonSupport);
if (!_msg.sendMessage(_ctlSocket)) {
failHandshake();
}
@@ -246,7 +270,11 @@
return;
}

- var receivedServerVersion:String = new String(_msg.body);
+ var receivedServerVersion:String = Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body);
TestResults.appendDebugMsg("Server version: " + receivedServerVersion);
// See https://code.google.com/p/ndt/issues/detail?id=104.
if (receivedServerVersion != NDTConstants.EXPECTED_SERVER_VERSION)
@@ -301,7 +329,11 @@
return;
}

- var confirmedTests:String = new String(_msg.body);
+ var confirmedTests:String = Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body);
TestResults.ndt_test_results::testsConfirmedByServer =
TestType.listToBitwiseOR(confirmedTests);

=======================================
--- /trunk/flash-client/src/Main.as Fri Mar 21 10:33:50 2014 UTC
+++ /trunk/flash-client/src/Main.as Wed May 28 11:17:18 2014 UTC
@@ -28,6 +28,7 @@
public static var server_hostname:String = NDTConstants.SERVER_HOSTNAME;
public static var client_application:String = NDTConstants.CLIENT_ID;
public static var ndt_description:String = NDTConstants.NDT_DESCRIPTION;
+ public static var jsonSupport:Boolean = true;

public function Main():void {
if (stage)
=======================================
--- /trunk/flash-client/src/Message.as Sun Feb 2 19:14:17 2014 UTC
+++ /trunk/flash-client/src/Message.as Wed May 28 11:17:18 2014 UTC
@@ -31,11 +31,20 @@
private var _length:int;

public function Message(
- type:int=MessageType.UNDEF_TYPE, body:ByteArray=null):void {
+ type:int=MessageType.UNDEF_TYPE, body:ByteArray=null,
+ jsonFormat:Boolean = false):void {
_type = type;
_body = new ByteArray();
- if (body != null)
- _body.writeBytes(body);
+ if (body != null) {
+ if (jsonFormat) {
+ _body.writeUTFBytes(NDTUtils.createJsonFromSingleValue(
+ String(body)));
+ } else {
+ _body.writeBytes(body);
+ }
+ } else if(Main.jsonSupport) {
+ _body.writeUTFBytes(NDTUtils.createJsonFromSingleValue(""));
+ }
_length = _body.length;
}

@@ -90,6 +99,7 @@
header[0] = _type;
header[1] = (_length >> 8);
header[2] = _length;
+
try {
socket.writeBytes(header);
} catch(e:IOError) {
=======================================
--- /trunk/flash-client/src/NDTPController.as Fri Mar 21 10:33:50 2014 UTC
+++ /trunk/flash-client/src/NDTPController.as Wed May 28 11:17:18 2014 UTC
@@ -63,7 +63,13 @@

public function startNDTTest():void {
_currentTest = 0;
- TestResults.clearResults();
+ // socket was once opened so do not clear previous debug messages
+ // and just try to connect again to server using old MSG_LOGIN message
+ if (_ctlSocket) {
+ removeSocketEventListeners();
+ } else {
+ TestResults.clearResults();
+ }
TestResults.recordStartTime();
TestResults.ndt_test_results::ndtTestFailed = false;
TestResults.ndt_test_results::ndtErrStatus = "Test in progress.";
@@ -96,6 +102,14 @@
_ctlSocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
onSecurityError);
}
+
+ private function removeSocketEventListeners():void {
+ _ctlSocket.removeEventListener(Event.CONNECT, onConnect);
+ _ctlSocket.removeEventListener(Event.CLOSE, onClose);
+ _ctlSocket.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
+ _ctlSocket.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,
+ onSecurityError);
+ }

private function onConnect(e:Event):void {
TestResults.appendDebugMsg("Control socket connected.");
@@ -197,6 +211,8 @@
private function getRemoteResults1():void {
if (!_msg.readHeader(_ctlSocket))
return;
+ if (!_msg.readBody(_ctlSocket, _msg.length))
+ return;

if (_msg.type == MessageType.MSG_LOGOUT) {
// All results obtained.
@@ -216,9 +232,6 @@
}

private function getRemoteResults2():void {
- if (!_msg.readBody(_ctlSocket, _msg.length))
- return;
-
if (_msg.type != MessageType.MSG_RESULTS) {
TestResults.appendErrMsg(ResourceManager.getInstance().getString(
NDTConstants.BUNDLE_NAME, "resultsWrongMessage", null,
@@ -229,7 +242,11 @@
return;
}

- _remoteTestResults += new String(_msg.body);
+ _remoteTestResults += Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body);
_msg = new Message();
_testStage = REMOTE_RESULTS1;
if (_ctlSocket.bytesAvailable > 0)
=======================================
--- /trunk/flash-client/src/NDTUtils.as Thu Mar 27 20:00:04 2014 UTC
+++ /trunk/flash-client/src/NDTUtils.as Wed May 28 11:17:18 2014 UTC
@@ -24,6 +24,8 @@
import mx.resources.ResourceManager;

public class NDTUtils {
+ public static const JSON_DEFAULT_KEY:String = "msg";
+
/**
* Function that calls a JS function through the ExternalInterface class if
* it exists by the name specified in the parameter.
@@ -49,8 +51,8 @@
// in some cases and this exception is raised.

// TestResults.appendDebugMsg() calls callExternalFunction
- // to invoke JS callbacks. Without this check we can
- // recurse infinitely.
+ // to invoke JS callbacks. Without this check we can
+ // recurse infinitely.
if (functionName != "appendDebugOutput") {
TestResults.appendDebugMsg("Failed to call " + functionName + ": "
+ e.toString());
@@ -234,6 +236,36 @@
}
return bytesCount;
}
+
+ /**
+ * 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
+ */
+ public static function createJsonFromSingleValue(value:String):String {
+ return "{\"" + JSON_DEFAULT_KEY + "\": \"" + value + "\"}";
+ }
+
+ /**
+ * 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
+ */
+ public static function readJsonMapValue(jsonText:String,
+ key:String):String {
+ try {
+ var decodedObj:Object = JSON.parse(jsonText);
+ return decodedObj[key];
+ } catch(e:TypeError) {
+ TestResults.appendErrMsg("Error while trying to read value of " + key
+ + "from JSON: " + jsonText + "."
+ + " Original message: " + e);
+ }
+ return "";
+ }
}
}

=======================================
--- /trunk/flash-client/src/TestC2S.as Wed Apr 16 10:12:51 2014 UTC
+++ /trunk/flash-client/src/TestC2S.as Wed May 28 11:17:18 2014 UTC
@@ -147,7 +147,11 @@
Main.locale));
if (_msg.type == MessageType.MSG_ERROR) {
TestResults.appendErrMsg(
- "ERROR MSG: " + parseInt(new String(_msg.body), 16));
+ "ERROR MSG: " + parseInt(Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body), 16));
}
_c2sTestSuccess = false;
endTest();
@@ -161,7 +165,11 @@
TestResults.appendDebugMsg(
"Each message of the C2S test has " + _dataToSend.length + " bytes.");

- var c2sPort:int = parseInt(new String(_msg.body));
+ var c2sPort:int = parseInt(Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body));
_c2sSocket = new Socket();
addC2SSocketEventListeners();
try {
@@ -267,7 +275,8 @@
private function startTest():void {
if (!_msg.readHeader(_ctlSocket))
return;
- // TEST_START message has no body.
+ if (!_msg.readBody(_ctlSocket, _msg.length))
+ return;

if (_msg.type != MessageType.TEST_START) {
TestResults.appendErrMsg(ResourceManager.getInstance().getString(
@@ -380,14 +389,22 @@
Main.locale));
if(_msg.type == MessageType.MSG_ERROR) {
TestResults.appendErrMsg("ERROR MSG: "
- + parseInt(new String(_msg.body), 16));
+ + parseInt(Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body), 16));
}
_c2sTestSuccess = false;
endTest();
return;
}

- var sc2sSpeedStr:String = new String(_msg.body);
+ var sc2sSpeedStr:String = Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body);
var sc2sSpeed:Number = parseFloat(sc2sSpeedStr);
if (isNaN(sc2sSpeed)) {
TestResults.appendErrMsg(
@@ -418,7 +435,8 @@
private function finalizeTest():void {
if (!_msg.readHeader(_ctlSocket))
return;
- // TEST_FINALIZE message has no body.
+ if (!_msg.readBody(_ctlSocket, _msg.length))
+ return;

if (_msg.type != MessageType.TEST_FINALIZE) {
TestResults.appendErrMsg(ResourceManager.getInstance().getString(
=======================================
--- /trunk/flash-client/src/TestMETA.as Fri Mar 21 10:33:50 2014 UTC
+++ /trunk/flash-client/src/TestMETA.as Wed May 28 11:17:18 2014 UTC
@@ -117,7 +117,11 @@
NDTConstants.BUNDLE_NAME, "metaWrongMessage", null, Main.locale));
if (_msg.type == MessageType.MSG_ERROR) {
TestResults.appendErrMsg("ERROR MSG: "
- + parseInt(new String(_msg.body), 16));
+ + parseInt(Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body), 16));
}
_metaTestSuccess = false;
endTest();
@@ -139,7 +143,8 @@
private function startTest():void {
if (!_msg.readHeader(_ctlSocket))
return;
- // TEST_START message has no body.
+ if (!_msg.readBody(_ctlSocket, _msg.length))
+ return;

if (_msg.type != MessageType.TEST_START) {
TestResults.appendErrMsg(
@@ -148,7 +153,11 @@
Main.locale));
if (_msg.type == MessageType.MSG_ERROR) {
TestResults.appendErrMsg(
- "ERROR MSG: " + parseInt(new String(_msg.body), 16));
+ "ERROR MSG: " + parseInt(Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body), 16));
}
_metaTestSuccess = false;
endTest();
@@ -165,7 +174,8 @@

bodyToSend.writeUTFBytes(new String(
NDTConstants.META_CLIENT_OS + ":" + Capabilities.os));
- var _msg:Message = new Message(MessageType.TEST_MSG, bodyToSend);
+ var _msg:Message = new Message(MessageType.TEST_MSG, bodyToSend,
+ Main.jsonSupport);
if (!_msg.sendMessage(_ctlSocket)) {
_metaTestSuccess = false;
endTest();
@@ -176,7 +186,7 @@
bodyToSend.writeUTFBytes(new String(
NDTConstants.META_CLIENT_BROWSER + ":" + UserAgentTools.getBrowser(
TestResults.ndt_test_results::userAgent)[2]));
- _msg = new Message(MessageType.TEST_MSG, bodyToSend);
+ _msg = new Message(MessageType.TEST_MSG, bodyToSend, Main.jsonSupport);
if (!_msg.sendMessage(_ctlSocket)) {
_metaTestSuccess = false;
endTest();
@@ -187,7 +197,7 @@
bodyToSend.writeUTFBytes(new String(
NDTConstants.META_CLIENT_VERSION + ":"
+ NDTConstants.CLIENT_VERSION));
- _msg = new Message(MessageType.TEST_MSG, bodyToSend);
+ _msg = new Message(MessageType.TEST_MSG, bodyToSend, Main.jsonSupport);
if (!_msg.sendMessage(_ctlSocket)) {
_metaTestSuccess = false;
endTest();
@@ -197,7 +207,7 @@
bodyToSend.clear();
bodyToSend.writeUTFBytes(new String(
NDTConstants.META_CLIENT_APPLICATION + ":" + _clientApplication));
- _msg = new Message(MessageType.TEST_MSG, bodyToSend);
+ _msg = new Message(MessageType.TEST_MSG, bodyToSend, Main.jsonSupport);
if (!_msg.sendMessage(_ctlSocket)) {
_metaTestSuccess = false;
endTest();
@@ -206,7 +216,8 @@

// Client can send any number of such meta data in a TEST_MSG format and
// signal the send of the transmission using an empty TEST_MSG.
- _msg = new Message(MessageType.TEST_MSG, new ByteArray());
+ _msg = new Message(MessageType.TEST_MSG, new ByteArray(),
+ Main.jsonSupport);
if (!_msg.sendMessage(_ctlSocket)) {
_metaTestSuccess = false;
endTest();
@@ -224,7 +235,8 @@
private function finalizeTest():void {
if (!_msg.readHeader(_ctlSocket))
return;
- // TEST_FINALIZE message has no body.
+ if (!_msg.readBody(_ctlSocket, _msg.length))
+ return;

if (_msg.type != MessageType.TEST_FINALIZE) {
TestResults.appendErrMsg(
=======================================
--- /trunk/flash-client/src/TestS2C.as Wed Apr 16 10:12:51 2014 UTC
+++ /trunk/flash-client/src/TestS2C.as Wed May 28 11:17:18 2014 UTC
@@ -44,6 +44,9 @@
private static const GET_WEB1001:int = 7;
private static const GET_WEB1002:int = 8;
private static const END_TEST:int = 9;
+ private static const THROUGHPUT_VALUE:String = "ThroughputValue";
+ private static const UNSENT_DATA_AMOUNT:String = "UnsentDataAmount";
+ private static const TOTAL_SENT_BYTE:String = "TotalSentByte";

private var _callerObj:NDTPController;
private var _ctlSocket:Socket;
@@ -150,14 +153,22 @@
Main.locale));
if (_msg.type == MessageType.MSG_ERROR) {
TestResults.appendErrMsg(
- "ERROR MESSAGE : " + parseInt(new String(_msg.body), 16));
+ "ERROR MESSAGE : " + parseInt(Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body), 16));
}
_s2cTestSuccess = false;
endTest();
return;
}

- var s2cPort:int = parseInt(new String(_msg.body));
+ var s2cPort:int = parseInt(Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body));
_s2cSocket = new Socket();
addS2CSocketEventListeners();
try {
@@ -250,7 +261,8 @@
private function startTest():void {
if (!_msg.readHeader(_ctlSocket))
return;
- // TEST_START message has no body.
+ if (!_msg.readBody(_ctlSocket, _msg.length))
+ return;

if (_msg.type != MessageType.TEST_START) {
// See https://code.google.com/p/ndt/issues/detail?id=105
@@ -359,29 +371,44 @@
Main.locale));
if (_msg.type == MessageType.MSG_ERROR) {
TestResults.appendErrMsg("ERROR MSG: "
- + parseInt(new String(_msg.body), 16));
+ + parseInt(Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body), 16));
}
_s2cTestSuccess = false;
endTest();
return;
}

- var _msgBody:String = new String(_msg.body);
- var _msgFields:Array = _msgBody.split(" ");
- if (_msgFields.length != 3) {
- TestResults.appendErrMsg(
- ResourceManager.getInstance().getString(
- NDTConstants.BUNDLE_NAME, "inboundWrongMessage", null,
- Main.locale)
- + "Message received: " + _msgBody);
- _s2cTestSuccess = false;
- endTest();
- return;
- }
+ var _msgBody:String, sc2sSpeed:Number, sSendQueue:int, sBytes:Number;
+ _msgBody = new String(_msg.body);
+ if (Main.jsonSupport) {
+ sc2sSpeed = parseFloat(NDTUtils.readJsonMapValue(_msgBody,
+ THROUGHPUT_VALUE));
+ sSendQueue = parseInt(NDTUtils.readJsonMapValue(_msgBody,
+ UNSENT_DATA_AMOUNT));
+ sBytes = parseFloat(NDTUtils.readJsonMapValue(_msgBody,
+ TOTAL_SENT_BYTE));
+ } else {
+ var _msgFields:Array = _msgBody.split(" ");
+ if (_msgFields.length != 3) {
+ TestResults.appendErrMsg(
+ ResourceManager.getInstance().getString(
+ NDTConstants.BUNDLE_NAME, "inboundWrongMessage", null,
+ Main.locale)
+ + "Message received: " + _msgBody);
+ _s2cTestSuccess = false;
+ endTest();
+ return;
+ }
+
+ sc2sSpeed = parseFloat(_msgFields[0]);
+ sSendQueue = parseInt(_msgFields[1]);
+ sBytes = parseFloat(_msgFields[2]);
+ }

- var sc2sSpeed:Number = parseFloat(_msgFields[0]);
- var sSendQueue:int = parseInt(_msgFields[1]);
- var sBytes:Number = parseFloat(_msgFields[2]);
if (isNaN(sc2sSpeed) || isNaN(sSendQueue) || isNaN(sBytes)) {
TestResults.appendErrMsg(
ResourceManager.getInstance().getString(
@@ -414,11 +441,12 @@
+ s2cSpeed.toFixed(2) + " kbps.");

var sendData:ByteArray = new ByteArray();
- sendData.writeFloat(s2cSpeed);
+ sendData.writeUTFBytes(String(s2cSpeed));
TestResults.appendDebugMsg(
- "Sending '" + s2cSpeed + "' back to the server.");
+ "Sending '" + String(s2cSpeed) + "' back to the server.");

- var _msgToSend:Message = new Message(MessageType.TEST_MSG, sendData);
+ var _msgToSend:Message = new Message(MessageType.TEST_MSG, sendData,
+ Main.jsonSupport);
if (!_msgToSend.sendMessage(_ctlSocket)) {
_s2cTestSuccess = false;
endTest();
@@ -454,7 +482,9 @@
if (!_msg.readHeader(_ctlSocket))
return;

+
if (_msg.type == MessageType.TEST_FINALIZE) {
+ TestResults.appendDebugMsg("!!" + _msg.type + " " + _msg.length +
"\n");
// All web100 variables have been sent by the server.
_readTimer.stop();
_readTimer.removeEventListener(TimerEvent.TIMER, onWeb100ReadTimeout);
@@ -473,14 +503,17 @@
private function getWeb100Vars2():void {
if (!_msg.readBody(_ctlSocket, _msg.length))
return;
-
if (_msg.type != MessageType.TEST_MSG) {
TestResults.appendErrMsg(ResourceManager.getInstance().getString(
NDTConstants.BUNDLE_NAME, "inboundWrongMessage", null,
Main.locale));
if (_msg.type == MessageType.MSG_ERROR) {
TestResults.appendErrMsg("ERROR MSG: "
- + parseInt(new String(_msg.body), 16));
+ + parseInt(Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body), 16));
}
_readTimer.stop();
_readTimer.removeEventListener(TimerEvent.TIMER, onWeb100ReadTimeout);
@@ -489,13 +522,19 @@
endTest();
return;
}
- _web100VarResult += new String(_msg.body);
+ _web100VarResult += Main.jsonSupport ?
+ new String(NDTUtils.readJsonMapValue(
+ String(_msg.body),
+ NDTUtils.JSON_DEFAULT_KEY))
+ : new String(_msg.body);
_testStage = GET_WEB1001;
if (_ctlSocket.bytesAvailable > 0)
getWeb100Vars1();
}

private function endTest():void {
+ if (!_msg.readBody(_ctlSocket, _msg.length))
+ return;
TestResults.ndt_test_results::s2cTestResults = _web100VarResult;
removeCtlSocketOnReceivedDataListener();

=======================================
--- /trunk/flash-client/src/locale/en_US/DisplayMessages.properties Sun Feb 2 19:14:17 2014 UTC
+++ /trunk/flash-client/src/locale/en_US/DisplayMessages.properties Wed May 28 11:17:18 2014 UTC
@@ -98,6 +98,7 @@
linkFullDpx = Link set to Full Duplex mode
linkHalfDpx = Link set to Half Duplex mode
loggingWrongMessage = Logging to server: Received wrong type of the message
+loggingUsingExtendedMsgFailed = Logging to server: Failed to login using MSG_LOGIN_EXTENDED message. Trying again with old MSG_LOGIN.
lookupError = Unable to obtain remote IP address
mboxWrongMessage = Middlebox test: Received wrong type of the message
meta = META
@@ -123,7 +124,7 @@
ooOrder = but packets arrived out-of-order
options = Options
osData = OS data:
-otherClient = Another client is currently being served, your test will begin within
+otherClient = Another client is currently being served, your test will begin within
otherTraffic = Information: Other network traffic is congesting the link
outboundTest = Tcpbw100 outbound test...
outboundWrongMessage = C2S throughput test: Received wrong type of the message
@@ -196,7 +197,7 @@
systemFault = System Fault
test = Test
testsuiteWrongMessage = Negotiating test suite: Received wrong type of the message
-theSlowestLink = The slowest link in the end-to-end path is a
+theSlowestLink = The slowest link in the end-to-end path is a
theoreticalLimit = The theoretical network limit is
thisConnIs = This connection is
timesPktLoss = times due to packet loss
@@ -231,5 +232,5 @@
oc48Str = OC-48
tengigabitEthernetStr = 10 Gig
systemFaultStr = systemFault
-dialupStr = dialup2
+dialupStr = dialup2
rttStr = rtt
=======================================
--- /trunk/src/Makefile.am Mon Mar 24 08:50:46 2014 UTC
+++ /trunk/src/Makefile.am Wed May 28 11:17:18 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)

=======================================
--- /trunk/src/clt_tests.h Thu Nov 15 21:33:44 2012 UTC
+++ /trunk/src/clt_tests.h Wed May 28 11:17:18 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_
=======================================
--- /trunk/src/ndtptestconstants.h Thu Nov 15 21:33:44 2012 UTC
+++ /trunk/src/ndtptestconstants.h Wed May 28 11:17:18 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
=======================================
--- /trunk/src/network.c Mon Oct 14 13:20:21 2013 UTC
+++ /trunk/src/network.c Wed May 28 11:17:18 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];
=======================================
--- /trunk/src/network.h Mon Oct 14 13:20:21 2013 UTC
+++ /trunk/src/network.h Wed May 28 11:17:18 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);
=======================================
--- /trunk/src/test_c2s_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /trunk/src/test_c2s_clt.c Wed May 28 11:17:18 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)
=======================================
--- /trunk/src/test_c2s_srv.c Wed Mar 12 06:27:30 2014 UTC
+++ /trunk/src/test_c2s_srv.c Wed May 28 11:17:18 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) {
=======================================
--- /trunk/src/test_meta.h Thu Nov 15 21:33:44 2012 UTC
+++ /trunk/src/test_meta.h Wed May 28 11:17:18 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_
=======================================
--- /trunk/src/test_meta_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /trunk/src/test_meta_clt.c Wed May 28 11:17:18 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");

=======================================
--- /trunk/src/test_meta_srv.c Mon Oct 14 13:20:21 2013 UTC
+++ /trunk/src/test_meta_srv.c Wed May 28 11:17:18 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");
}

=======================================
--- /trunk/src/test_mid_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /trunk/src/test_mid_clt.c Wed May 28 11:17:18 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);
=======================================
--- /trunk/src/test_mid_srv.c Fri Mar 21 07:54:57 2014 UTC
+++ /trunk/src/test_mid_srv.c Wed May 28 11:17:18 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.
=======================================
--- /trunk/src/test_s2c_clt.c Tue May 21 14:47:24 2013 UTC
+++ /trunk/src/test_s2c_clt.c Wed May 28 11:17:18 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

@@ -243,8 +284,16 @@
return 2;
}

- // hardcoded size of array from main tests
- strlcat(result_srv, buff, 2 * BUFFSIZE);
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcat(result_srv, jsonMsgValue, 2 * BUFFSIZE);
+ free(jsonMsgValue);
+ }
+ else {
+ // hardcoded size of array from main tests
+ strlcat(result_srv, buff, 2 * BUFFSIZE);
+ }
+
}
log_println(6, "result_srv = '%s', of len %d", result_srv, msgLen);
log_println(1, " <------------------------->");
=======================================
--- /trunk/src/test_s2c_srv.c Tue Apr 15 22:51:33 2014 UTC
+++ /trunk/src/test_s2c_srv.c Wed May 28 11:17:18 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);
@@ -583,7 +600,7 @@
ret = tcp_stat_get_data(rsnap, xmitsfd, ctlsockfd, agent, count_vars);
web100_snapshot_free(rsnap);
#elif USE_WEB10G
- ret = tcp_stat_get_data(snap, xmitsfd, ctlsockfd, agent, count_vars);
+ ret = tcp_stat_get_data(snap, xmitsfd, ctlsockfd, agent, count_vars, testOptions->json_support);
estats_val_data_free(&snap);
#endif

@@ -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);
=======================================
--- /trunk/src/test_sfw.h Thu Nov 15 21:33:44 2012 UTC
+++ /trunk/src/test_sfw.h Wed May 28 11:17:18 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_
=======================================
--- /trunk/src/test_sfw_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /trunk/src/test_sfw_clt.c Wed May 28 11:17:18 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");
=======================================
--- /trunk/src/test_sfw_srv.c Mon Oct 14 13:20:21 2013 UTC
+++ /trunk/src/test_sfw_srv.c Wed May 28 11:17:18 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);
}
=======================================
--- /trunk/src/testoptions.c Tue Apr 15 22:51:33 2014 UTC
+++ /trunk/src/testoptions.c Wed May 28 11:17:18 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,23 @@
* 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;
+ jsonMsgValue = json_read_map_value(msgValue, DEFAULT_KEY);
+ strlcpy(msgValue, jsonMsgValue, sizeof(msgValue));
+ msgLen = strlen(jsonMsgValue);
+ free(jsonMsgValue);
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 +292,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
=======================================
--- /trunk/src/testoptions.h Tue Apr 15 22:51:33 2014 UTC
+++ /trunk/src/testoptions.h Wed May 28 11:17:18 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
=======================================
--- /trunk/src/web100-util.c Mon Oct 14 13:20:21 2013 UTC
+++ /trunk/src/web100-util.c Wed May 28 11:17:18 2014 UTC
@@ -16,6 +16,7 @@
#include "strlutils.h"
#include "utils.h"
#include "web100srv.h"
+#include "jsonutils.h"

struct tcp_name {
char* web100_name;
@@ -150,13 +151,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 +185,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 +216,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 +238,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 +275,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, "");
@@ -514,6 +523,7 @@
* @param line A char* to write the line to
* @param line_size Size of line in bytes
* @param ctlsock The socket to write to
+ * @param jsonSupport Indicates if messages should be sent using JSON format
*
* If this fails nothing is sent on the cltsocket and the error will
* be logged.
@@ -521,7 +531,7 @@
*/
static void print_10gvar_renamed(const char * old_name,
const char * new_name, const tcp_stat_snap* snap, char * line,
- int line_size, int ctlsock) {
+ int line_size, int ctlsock, int jsonSupport) {
int type;
struct estats_val val;
estats_error* err;
@@ -539,7 +549,7 @@
estats_error_free(&err);
} else {
snprintf(line, line_size, "%s: %s\n", new_name, str);
- send_msg(ctlsock, TEST_MSG, line, strlen(line));
+ send_json_message(ctlsock, TEST_MSG, line, strlen(line), jsonSupport, JSON_SINGLE_VALUE);
free(str);
str = NULL;
}
@@ -558,10 +568,11 @@
* @param ctlsock integer socket file descriptor indicating data recipient
* @param agent pointer to a tcp_stat_agent
* @param count_vars integer number of tcp_stat_variables to get value of
+ * @param jsonSupport indicates if messages should be sent usin JSON format
*
*/
int tcp_stat_get_data(tcp_stat_snap* snap, int testsock, int ctlsock,
- tcp_stat_agent* agent, int count_vars) {
+ tcp_stat_agent* agent, int count_vars, int jsonSupport) {
char line[256];
#if USE_WEB100
int i;
@@ -605,7 +616,7 @@
/* Why do we atoi after getting as text anyway ?? */
snprintf(line, sizeof(line), "%s: %d\n", web_vars[i].name,
atoi(web_vars[i].value));
- send_msg(ctlsock, TEST_MSG, line, strlen(line));
+ send_json_message(ctlsock, TEST_MSG, line, strlen(line), jsonSupport, JSON_SINGLE_VALUE);
log_print(9, "%s", line);
}
log_println(6, "S2C test - Send web100 data to client pid=%d", getpid());
@@ -648,7 +659,7 @@
}
snprintf(line, sizeof(line), "%s: %s\n",
estats_var_array[j].name, str);
- send_msg(ctlsock, TEST_MSG, (const void *) line, strlen(line));
+ send_json_message(ctlsock, TEST_MSG, line, strlen(line), jsonSupport, JSON_SINGLE_VALUE);
log_print(9, "%s", line);
free(str);
str = NULL;
@@ -677,8 +688,7 @@
static const char* frame_web100 = "-~~~Web100_old_var_names~~~-: 1\n";
int type;
char *str = NULL;
- send_msg(ctlsock, TEST_MSG, (const void *)frame_web100,
- strlen(frame_web100));
+ send_json_message(ctlsock, TEST_MSG, frame_web100, strlen(frame_web100), jsonSupport, JSON_SINGLE_VALUE);

/* ECNEnabled -> ECN */
type = web10g_find_val(snap, "ECN", &val);
@@ -687,7 +697,7 @@
" failed to find ECN bad type=%d", type);
} else {
snprintf(line, sizeof(line), "ECNEnabled: %"PRId32"\n", (val.sv32 == 1) ? 1 : 0);
- send_msg(ctlsock, TEST_MSG, line, strlen(line));
+ send_json_message(ctlsock, TEST_MSG, line, strlen(line), jsonSupport, JSON_SINGLE_VALUE);
}

/* NagleEnabled -> Nagle */
@@ -697,7 +707,7 @@
" failed to find Nagle bad type=%d", type);
} else {
snprintf(line, sizeof(line), "NagleEnabled: %"PRId32"\n", (val.sv32 == 2) ? 1 : 0);
- send_msg(ctlsock, TEST_MSG, line, strlen(line));
+ send_json_message(ctlsock, TEST_MSG, line, strlen(line), jsonSupport, JSON_SINGLE_VALUE);
}

/* SACKEnabled -> WillUseSACK & WillSendSACK */
@@ -708,7 +718,7 @@
} else {
/* Yes this comes through as 3 from web100 */
snprintf(line, sizeof(line), "SACKEnabled: %d\n", (val.sv32 == 1) ? 3 : 0);
- send_msg(ctlsock, TEST_MSG, line, strlen(line));
+ send_json_message(ctlsock, TEST_MSG, line, strlen(line), jsonSupport, JSON_SINGLE_VALUE);
}

/* TimestampsEnabled -> TimeStamps */
@@ -718,40 +728,40 @@
" failed to find TimeStamps bad type=%d", type);
} else {
snprintf(line, sizeof(line), "TimestampsEnabled: %"PRId32"\n", (val.sv32 == 1) ? 1 : 0);
- send_msg(ctlsock, TEST_MSG, line, strlen(line));
+ send_json_message(ctlsock, TEST_MSG, line, strlen(line), jsonSupport, JSON_SINGLE_VALUE);
}

/* PktsRetrans -> SegsRetrans */
print_10gvar_renamed("SegsRetrans", "PktsRetrans", snap, line,
- sizeof(line), ctlsock);
+ sizeof(line), ctlsock, jsonSupport);

/* DataPktsOut -> DataSegsOut */
print_10gvar_renamed("DataSegsOut", "DataPktsOut", snap, line,
- sizeof(line), ctlsock);
+ sizeof(line), ctlsock, jsonSupport);

/* MaxCwnd -> MAX(MaxSsCwnd, MaxCaCwnd) */
print_10gvar_renamed("MaxCwnd", "MaxCwnd", snap, line,
- sizeof(line), ctlsock);
+ sizeof(line), ctlsock, jsonSupport);

/* SndLimTimeSender -> SndLimTimeSnd */
print_10gvar_renamed("SndLimTimeSnd", "SndLimTimeSender", snap, line,
- sizeof(line), ctlsock);
+ sizeof(line), ctlsock, jsonSupport);

/* DataBytesOut -> DataOctetsOut */
print_10gvar_renamed("HCDataOctetsOut", "DataBytesOut", snap, line,
- sizeof(line), ctlsock);
+ sizeof(line), ctlsock, jsonSupport);

/* SndLimTransSender -> SndLimTransSnd */
print_10gvar_renamed("SndLimTransSnd", "SndLimTransSender", snap, line,
- sizeof(line), ctlsock);
+ sizeof(line), ctlsock, jsonSupport);

/* PktsOut -> SegsOut */
print_10gvar_renamed("SegsOut", "PktsOut", snap, line,
- sizeof(line), ctlsock);
+ sizeof(line), ctlsock, jsonSupport);

/* CongestionSignals -> CongSignals */
print_10gvar_renamed("CongSignals", "CongestionSignals", snap, line,
- sizeof(line), ctlsock);
+ sizeof(line), ctlsock, jsonSupport);

/* RcvWinScale -> Same as WinScaleSent if WinScaleSent != -1 */
type = web10g_find_val(snap, "WinScaleSent", &val);
@@ -763,17 +773,16 @@
snprintf(line, sizeof(line), "RcvWinScale: %u\n", 0);
else
snprintf(line, sizeof(line), "RcvWinScale: %d\n", val.sv32);
- send_msg(ctlsock, TEST_MSG, (const void *) line, strlen(line));
+ send_json_message(ctlsock, TEST_MSG, line, strlen(line), jsonSupport, JSON_SINGLE_VALUE);
}

/* X_Rcvbuf & X_Sndbuf */
snprintf(line, sizeof(line), "X_Rcvbuf: %d\n", X_RcvBuf);
- send_msg(ctlsock, TEST_MSG, (const void *) line, strlen(line));
+ send_json_message(ctlsock, TEST_MSG, line, strlen(line), jsonSupport, JSON_SINGLE_VALUE);
snprintf(line, sizeof(line), "X_Sndbuf: %d\n", X_SndBuf);
- send_msg(ctlsock, TEST_MSG, (const void *) line, strlen(line));
+ send_json_message(ctlsock, TEST_MSG, line, strlen(line), jsonSupport, JSON_SINGLE_VALUE);

- send_msg(ctlsock, TEST_MSG, (const void *)frame_web100,
- strlen(frame_web100));
+ send_json_message(ctlsock, TEST_MSG, frame_web100, strlen(frame_web100), jsonSupport, JSON_SINGLE_VALUE);

log_println(6, "S2C test - Send web100 data to client pid=%d", getpid());
return 0;
=======================================
--- /trunk/src/web100clt.c Tue Mar 25 09:36:53 2014 UTC
+++ /trunk/src/web100clt.c Wed May 28 11:17:18 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);

- strlcpy(scip, str, sizeof(scip));
+ jsonMsgValue = json_read_map_value(midresult_str, CLIENT_ADDRESS);
+ strlcpy(scip, jsonMsgValue, sizeof(scip));
+ free(jsonMsgValue);

- 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);
+ 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));
+
+ 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,9 +531,12 @@
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
+ int retry = 0; // flag set after invalid login message is being received
+ char *invalid_login_msg = "Invalid login message.";
// addresses..
I2Addr server_addr = NULL;
- char* ptr;
+ char* ptr, *jsonMsgValue;
#ifdef AF_INET6
#define GETOPT_LONG_INET6(x) "46"x
#else
@@ -651,8 +680,10 @@

/* The beginning of the protocol */

+ buff[0] = tests;
+ strlcpy(buff + 1, VERSION, sizeof(buff) - 1);
/* write our test suite request by sending a login message */
- send_msg(ctlSocket, MSG_LOGIN, &tests, 1);
+ send_json_message(ctlSocket, MSG_EXTENDED_LOGIN, buff, strlen(buff), jsonSupport, JSON_SINGLE_VALUE);
/* 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 "
@@ -675,13 +706,55 @@
if (check_msg_type("Logging to server", SRV_QUEUE, msgType, buff,
msgLen)) {
// Any other type of message at this stage is incorrect
+ // If received invalid login message error then try to connect using basic MSG_LOGIN msg
+ if (!retry) {
+ printf("Information: The server '%s' does not support MSG_EXTENDED_LOGIN message. "
+ "Trying to connect using MSG_LOGIN\n", host);
+ retry = 1; // to prevent infinite retrying to connect
+ jsonSupport = 0;
+ if ((server_addr = I2AddrByNode(get_errhandle(), host)) == NULL) {
+ printf("Unable to resolve server address\n");
+ exit(-3);
+ }
+ I2AddrSetPort(server_addr, ctlport);
+
+ if ((retcode = CreateConnectSocket(&ctlSocket, NULL, server_addr,
+ conn_options, 0))) {
+ printf("Connect() for control socket failed\n");
+ exit(-4);
+ }
+
+ // check and print Address family being used
+ if (I2AddrSAddr(server_addr, 0)->sa_family == AF_INET) {
+ printf("Using IPv4 address\n");
+ } else {
+ printf("Using IPv6 address\n");
+ }
+
+ send_msg(ctlSocket, MSG_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 "
+ "client\n", host);
+ exit(0);
+ }
+
+ continue;
+ }
+
exit(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");
exit(3);
}
- buff[msgLen] = 0;
if (check_int(buff, &xwait)) {
log_println(0, "Invalid queue indicator");
exit(4);
@@ -717,7 +790,7 @@
}
// Signal from the server to see if the client is still alive
if (xwait == SRV_QUEUE_HEARTBEAT) {
- send_msg(ctlSocket, MSG_WAITING, &tests, 1);
+ send_json_message(ctlSocket, MSG_WAITING, &tests, 1, jsonSupport, JSON_SINGLE_VALUE);
continue;
}

@@ -753,6 +826,13 @@
msgLen)) {
exit(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");
exit(3);
@@ -760,7 +840,6 @@

// Version compatibility between server-client must be verified

- buff[msgLen] = 0;
if (buff[0] != 'v') { // payload doesn't start with a version indicator
log_println(0, "Incompatible version number");
exit(4);
@@ -795,13 +874,19 @@
msgLen)) {
exit(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");
exit(3);
}

// get ids of tests to be run now
- buff[msgLen] = 0;
log_println(5, "Received tests sequence: '%s'", buff);
if ((strtokbuf = malloc(1024)) == NULL) {
log_println(0, "Malloc failed!");
@@ -818,32 +903,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);
}
@@ -882,7 +967,14 @@
exit(2);
}

- strlcat(resultstr, buff, sizeof(resultstr));
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcat(resultstr, jsonMsgValue, sizeof(resultstr));
+ free(jsonMsgValue);
+ }
+ else {
+ strlcat(resultstr, buff, sizeof(resultstr));
+ }
log_println(6, "resultstr = '%s'", resultstr);
}

@@ -892,7 +984,7 @@

// print middlebox test results
if (tests & TEST_MID) {
- middleboxResults(mid_resultstr, ctlSocket);
+ middleboxResults(mid_resultstr, ctlSocket, jsonSupport);
}

I2AddrFree(server_addr);
=======================================
--- /trunk/src/web100srv.c Tue Apr 15 22:51:33 2014 UTC
+++ /trunk/src/web100srv.c Wed May 28 11:17:18 2014 UTC
@@ -86,6 +86,7 @@
#include "strlutils.h"
#include "heuristics.h"
#include "tests_srv.h"
+#include "jsonutils.h"

static char lgfn[FILENAME_SIZE]; // log file name
static char wvfn[FILENAME_SIZE]; // file name of web100-variables list
@@ -778,9 +779,10 @@
tmp_ptr->pid);

// send "keep-alive" SRV_QUEUE message to client and expect a response
- retcode = send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE,
+ retcode = send_json_message(tmp_ptr->ctlsockfd, SRV_QUEUE,
SRV_QUEUE_HEARTBEAT_STR,
- strlen(SRV_QUEUE_HEARTBEAT_STR));
+ strlen(SRV_QUEUE_HEARTBEAT_STR),
+ testopt.json_support, JSON_SINGLE_VALUE);
log_println(6,
"send_msg() returned %d during zombie check on client %d",
retcode, tmp_ptr->pid);
@@ -970,12 +972,13 @@

// client needs to be version compatible. Send current version
snprintf(buff, sizeof(buff), "v%s", VERSION "-" TCP_STAT_NAME);
- send_msg(ctlsockfd, MSG_LOGIN, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_LOGIN, buff, strlen(buff), testopt->json_support, JSON_SINGLE_VALUE);

// initiate test with MSG_LOGIN message.
log_println(3, "run_test() routine, asking for test_suite = %s",
test_suite);
- send_msg(ctlsockfd, MSG_LOGIN, test_suite, strlen(test_suite));
+ send_json_message(ctlsockfd, MSG_LOGIN, test_suite, strlen(test_suite),
+ testopt->json_support, JSON_SINGLE_VALUE);
/* if ((n = initialize_tests(ctlsockfd, &testopt, conn_options))) {
log_println(0, "ERROR: Tests initialization failed (%d)", n);
return;
@@ -1220,38 +1223,38 @@
snprintf(buff, sizeof(buff), "c2sData: %d\nc2sAck: %d\ns2cData: %d\n"
"s2cAck: %d\n", c2s_linkspeed_data, c2s_linkspeed_ack,
s2c_linkspeed_data, s2c_linkspeed_ack);
- send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_RESULTS, buff, strlen(buff), testopt->json_support, JSON_SINGLE_VALUE);

snprintf(buff, sizeof(buff),
"half_duplex: %d\nlink: %d\ncongestion: %d\nbad_cable: %d\n"
"mismatch: %d\nspd: %0.2f\n", half_duplex, link, congestion,
bad_cable, mismatch, realthruput);
- send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_RESULTS, buff, strlen(buff), testopt->json_support, JSON_SINGLE_VALUE);

snprintf(buff, sizeof(buff),
"bw: %0.2f\nloss: %0.9f\navgrtt: %0.2f\nwaitsec: %0.2f\n"
"timesec: %0.2f\norder: %0.4f\n", bw_theortcl, packetloss_s2c,
avgrtt, waitsec, timesec, oo_order);
- send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_RESULTS, buff, strlen(buff), testopt->json_support, JSON_SINGLE_VALUE);

snprintf(buff, sizeof(buff),
"rwintime: %0.4f\nsendtime: %0.4f\ncwndtime: %0.4f\n"
"rwin: %0.4f\nswin: %0.4f\n", rwintime, sendtime, cwndtime, rwin,
swin);
- send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_RESULTS, buff, strlen(buff), testopt->json_support, JSON_SINGLE_VALUE);

snprintf(buff, sizeof(buff),
"cwin: %0.4f\nrttsec: %0.6f\nSndbuf: %"VARtype"\naspd: %0.5f\n"
"CWND-Limited: %0.2f\n", cwin, rttsec, vars.Sndbuf, aspd, s2c2spd);
- send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_RESULTS, buff, strlen(buff), testopt->json_support, JSON_SINGLE_VALUE);

snprintf(buff, sizeof(buff),
"minCWNDpeak: %d\nmaxCWNDpeak: %d\nCWNDpeaks: %d\n",
peaks.min, peaks.max, peaks.amount);
- send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_RESULTS, buff, strlen(buff), testopt->json_support, JSON_SINGLE_VALUE);

// Signal end of test results to client
- send_msg(ctlsockfd, MSG_LOGOUT, "", 0);
+ send_json_message(ctlsockfd, MSG_LOGOUT, "", 0, testopt->json_support, JSON_SINGLE_VALUE);

// Copy collected values into the meta data structures. This section
// seems most readable, easy to debug here.
@@ -1988,7 +1991,8 @@
if (tmp_ptr == NULL)
break;
if (i == (2 * max_clients)) {
- rac = send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, "1", 1);
+ rac = send_json_message(tmp_ptr->ctlsockfd, SRV_QUEUE, "1", 1,
+ testopt.json_support, JSON_SINGLE_VALUE);
log_println(
6,
"sent 45 sec update message to client %d on fd=%d, "
@@ -1996,7 +2000,8 @@
tmp_ptr->pid, tmp_ptr->ctlsockfd, rac);
}
if (i == (3 * max_clients)) {
- rac = send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, "2", 1);
+ rac = send_json_message(tmp_ptr->ctlsockfd, SRV_QUEUE, "2", 1,
+ testopt.json_support, JSON_SINGLE_VALUE);
log_println(
6,
"sent 90 sec update message to client %d on fd=%d, "
@@ -2018,9 +2023,10 @@
while (head_ptr != NULL) {
/* send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9933", 4); */
// indicate server waiting in queue
- send_msg(head_ptr->ctlsockfd, SRV_QUEUE,
+ send_json_message(head_ptr->ctlsockfd, SRV_QUEUE,
SRV_QUEUE_SERVER_BUSY_STR,
- strlen(SRV_QUEUE_SERVER_BUSY_STR));
+ strlen(SRV_QUEUE_SERVER_BUSY_STR),
+ testopt.json_support, JSON_SINGLE_VALUE);
shutdown(head_ptr->ctlsockfd, SHUT_WR);
close(head_ptr->ctlsockfd);
tpid = head_ptr->pid;
@@ -2039,9 +2045,10 @@
"clients", head_ptr->pid);
while (head_ptr != NULL) {
/* send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9977", 4); */
- send_msg(head_ptr->ctlsockfd, SRV_QUEUE,
+ send_json_message(head_ptr->ctlsockfd, SRV_QUEUE,
SRV_QUEUE_SERVER_BUSY_STR,
- strlen(SRV_QUEUE_SERVER_BUSY_STR));
+ strlen(SRV_QUEUE_SERVER_BUSY_STR),
+ testopt.json_support, JSON_SINGLE_VALUE);
shutdown(head_ptr->ctlsockfd, SHUT_WR);
close(head_ptr->ctlsockfd);
tpid = head_ptr->pid;
@@ -2075,9 +2082,10 @@
head_ptr->pipe, head_ptr->running, head_ptr->ctlsockfd,
head_ptr->oldclient, head_ptr->tests);
// boot the client
- send_msg(head_ptr->ctlsockfd, SRV_QUEUE,
+ send_json_message(head_ptr->ctlsockfd, SRV_QUEUE,
SRV_QUEUE_SERVER_BUSY_STR,
- strlen(SRV_QUEUE_SERVER_BUSY_STR));
+ strlen(SRV_QUEUE_SERVER_BUSY_STR),
+ testopt.json_support, JSON_SINGLE_VALUE);
shutdown(head_ptr->ctlsockfd, SHUT_WR);
close(head_ptr->ctlsockfd);
tpid = head_ptr->pid;
@@ -2282,9 +2290,10 @@
0,
"Too many clients/mclients (%d) waiting to be served, "
"Please try again later.", chld_pid);
- send_msg(ctlsockfd, SRV_QUEUE,
+ send_json_message(ctlsockfd, SRV_QUEUE,
SRV_QUEUE_SERVER_BUSY_STR,
- strlen(SRV_QUEUE_SERVER_BUSY_STR));
+ strlen(SRV_QUEUE_SERVER_BUSY_STR),
+ testopt.json_support, JSON_SINGLE_VALUE);
close(chld_pipe[0]);
close(chld_pipe[1]);
shutdown(ctlsockfd, SHUT_WR);
@@ -2347,9 +2356,10 @@
3,
"queuing disabled and testing in progress, tell client no");
/* send_msg(new_child->ctlsockfd, SRV_QUEUE, "9944", 4); */
- send_msg(new_child->ctlsockfd, SRV_QUEUE,
+ send_json_message(new_child->ctlsockfd, SRV_QUEUE,
SRV_QUEUE_SERVER_BUSY_STR,
- strlen(SRV_QUEUE_SERVER_BUSY_STR));
+ strlen(SRV_QUEUE_SERVER_BUSY_STR),
+ testopt.json_support, JSON_SINGLE_VALUE);
close(chld_pipe[1]);
shutdown(new_child->ctlsockfd, SHUT_WR);
close(new_child->ctlsockfd);
@@ -2407,7 +2417,8 @@
"begin within %d minutes", (waiting - 1), tmp_ptr->pid,
(waiting-1));
snprintf(tmpstr, sizeof(tmpstr), "%d", (waiting-1));
- send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr));
+ send_json_message(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr),
+ testopt.json_support, JSON_SINGLE_VALUE);
continue;
}

@@ -2417,7 +2428,8 @@
"will begin within %d minutes",
(waiting-max_clients), mchild->pid, xx);
snprintf(tmpstr, sizeof(tmpstr), "%d", xx);
- send_msg(mchild->ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr));
+ send_json_message(mchild->ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr),
+ testopt.json_support, JSON_SINGLE_VALUE);
continue;
}

@@ -2456,8 +2468,8 @@
(waiting-1), tmp_ptr->pid, (waiting-j));

snprintf(tmpstr, sizeof(tmpstr), "%d", (waiting-j));
- send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr,
- strlen(tmpstr));
+ send_json_message(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr,
+ strlen(tmpstr), testopt.json_support, JSON_SINGLE_VALUE);
tmp_ptr = tmp_ptr->next;
j--;
}
@@ -2522,7 +2534,8 @@
log_println(5, "sending 'GO' signal to client msg='%s'",
tmpstr);
// test session starts now
- send_msg(mchild->ctlsockfd, SRV_QUEUE, "0", 1);
+ send_json_message(mchild->ctlsockfd, SRV_QUEUE, "0", 1,
+ testopt.json_support, JSON_SINGLE_VALUE);
for (i = 0; i < 5; i++) {
retcode = write(mchild->pipe, tmpstr, strlen(tmpstr));
log_println(6, "write(%d) returned %d, errno=%d",
@@ -2553,7 +2566,8 @@
head_ptr->tests);
log_println(5, "sending 'GO' signal to client msg='%s'",
tmpstr);
- send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "0", 1);
+ send_json_message(head_ptr->ctlsockfd, SRV_QUEUE, "0", 1,
+ testopt.json_support, JSON_SINGLE_VALUE);
for (i = 0; i < 5; i++) {
retcode = write(head_ptr->pipe, tmpstr, strlen(tmpstr));
if ((retcode == -1) && (errno == EINTR))
=======================================
--- /trunk/src/web100srv.h Wed Mar 12 06:27:30 2014 UTC
+++ /trunk/src/web100srv.h Wed May 28 11:17:18 2014 UTC
@@ -309,14 +309,14 @@

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,
tcp_stat_connection cn, int count_vars);
int tcp_stat_get_data(tcp_stat_snap* snap, int testsock, int ctlsock,
- tcp_stat_agent* agent, int count_vars);
+ tcp_stat_agent* agent, int count_vars, int jsonSupport);

int CwndDecrease(char* logname,
u_int32_t *dec_cnt, u_int32_t *same_cnt, u_int32_t *inc_cnt);


  • [ndt-dev] [ndt] r1060 committed - Merged Issues 145,146,147 into trunk (JSON support), ndt, 05/28/2014

Archive powered by MHonArc 2.6.16.

Top of Page