Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r1061 committed - Updated Issue136 branch with trunk changes

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r1061 committed - Updated Issue136 branch with trunk changes


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r1061 committed - Updated Issue136 branch with trunk changes
  • Date: Wed, 28 May 2014 13:02:26 +0000

Revision: 1061
Author:

Date: Wed May 28 13:01:29 2014 UTC
Log: Updated Issue136 branch with trunk changes

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

Added:
/branches/Issue136/Applet/src/edu/internet2/ndt/JSONUtils.java
/branches/Issue136/Applet/src/edu/internet2/ndt/lib
/branches/Issue136/HTML5-frontend/set-active-client.sh
/branches/Issue136/src/jsonutils.c
/branches/Issue136/src/jsonutils.h
Modified:
/branches/Issue136
/branches/Issue136/Applet/MANIFEST.MF
/branches/Issue136/Applet/Makefile.am
/branches/Issue136/Applet/src/edu/internet2/ndt/MessageType.java
/branches/Issue136/Applet/src/edu/internet2/ndt/NDTConstants.java
/branches/Issue136/Applet/src/edu/internet2/ndt/Protocol.java
/branches/Issue136/Applet/src/edu/internet2/ndt/Tcpbw100.java
/branches/Issue136/Applet/src/edu/internet2/ndt/locale/Tcpbw100_msgs_en_US.properties
/branches/Issue136/HTML5-frontend/script.js
/branches/Issue136/HTML5-frontend/widget.html
/branches/Issue136/conf/create-html.sh
/branches/Issue136/configure.ac
/branches/Issue136/flash-client/src/GUI.as
/branches/Issue136/flash-client/src/Handshake.as
/branches/Issue136/flash-client/src/Main.as
/branches/Issue136/flash-client/src/Message.as
/branches/Issue136/flash-client/src/MessageType.as
/branches/Issue136/flash-client/src/NDTConstants.as
/branches/Issue136/flash-client/src/NDTPController.as
/branches/Issue136/flash-client/src/NDTUtils.as
/branches/Issue136/flash-client/src/TestC2S.as
/branches/Issue136/flash-client/src/TestMETA.as
/branches/Issue136/flash-client/src/TestResults.as
/branches/Issue136/flash-client/src/TestResultsUtils.as
/branches/Issue136/flash-client/src/TestS2C.as
/branches/Issue136/flash-client/src/locale/en_US/DisplayMessages.properties
/branches/Issue136/janalyze/src/edu/internet2/ndt/ResultsContainer.java
/branches/Issue136/src/Makefile.am
/branches/Issue136/src/clt_tests.h
/branches/Issue136/src/ndtptestconstants.h
/branches/Issue136/src/network.c
/branches/Issue136/src/network.h
/branches/Issue136/src/protocol.h
/branches/Issue136/src/test_c2s_clt.c
/branches/Issue136/src/test_c2s_srv.c
/branches/Issue136/src/test_meta.h
/branches/Issue136/src/test_meta_clt.c
/branches/Issue136/src/test_meta_srv.c
/branches/Issue136/src/test_mid_clt.c
/branches/Issue136/src/test_mid_srv.c
/branches/Issue136/src/test_s2c_clt.c
/branches/Issue136/src/test_s2c_srv.c
/branches/Issue136/src/test_sfw.h
/branches/Issue136/src/test_sfw_clt.c
/branches/Issue136/src/test_sfw_srv.c
/branches/Issue136/src/testoptions.c
/branches/Issue136/src/testoptions.h
/branches/Issue136/src/usage.c
/branches/Issue136/src/web100-util.c
/branches/Issue136/src/web100clt.c
/branches/Issue136/src/web100srv.c
/branches/Issue136/src/web100srv.h

=======================================
--- /dev/null
+++ /branches/Issue136/Applet/src/edu/internet2/ndt/JSONUtils.java Wed May 28 13:01:29 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
+++ /branches/Issue136/HTML5-frontend/set-active-client.sh Wed May 28 13:01:29 2014 UTC
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# This script changes the widget.html page to use flash or java NDT client
+# as background for JS UI.
+
+flash="flash"
+java="java"
+widget="widget.html"
+embed_tag="<embed id=\"NDT\" name=\"NDT\" type=\"application\/x-shockwave-flash\" src=\"FlashClt.swf\" width=\"600\" height=\"400\" \/>"
+applet_tag="<applet id=\"NDT\" name=\"NDT\" code=\"edu.internet2.ndt.Tcpbw100.class\" codebase=\"<?php print \$applet_url ?>\" archive=\"Tcpbw100.jar\" width=\"400\" height=\"400\"><\/applet>"
+
+echo "This script allows you to change NDT client being used in $widget page."
+if test ! -f "$widget"; then
+ echo "$widget not found. Aborting..."
+ exit
+fi
+
+echo "Choose which client you want to use ($java/$flash): "
+read client
+while test "$client" != "$java" && test "$client" != "$flash"; do
+ echo "Choose which client you want to use ($java/$flash): "
+ read client
+done
+
+if test "$client" = "$java"; then
+ /bin/sed -i "s/$embed_tag/$applet_tag/" $widget
+ /bin/sed -i "s/<!--[ \t\n]*$applet_tag[ \t\n]*-->/<!--$embed_tag-->/" $widget
+fi
+
+if test "$client" = "$flash"; then
+ /bin/sed -i "s/$applet_tag/$embed_tag/" $widget
+ /bin/sed -i "s/<!--[ \t\n]*$embed_tag[ \t\n]*-->/<!--$applet_tag-->/" $widget
+fi
+
+echo "$widget has been successfully changed."
+
=======================================
--- /dev/null
+++ /branches/Issue136/src/jsonutils.c Wed May 28 13:01:29 2014 UTC
@@ -0,0 +1,170 @@
+/*
+ * This file contains functions to handle json messages.
+ * Jansson library is used for encoding/decoding JSON strings.
+ * See http://www.digip.org/jansson/ for more details.
+ *
+ * Sebastian Kostuch 2014-04-30
+ *

+ */
+
+#include <jansson.h>
+#include <string.h>
+#include "jsonutils.h"
+
+/**
+ * Creates string representing JSON object with single key:value pair
+ * where key is default and value is being taken from parameter.
+ *
+ * @param value null-terminated string containing value of map entry
+ * @return encoded JSON string
+ */
+char* json_create_from_single_value(const char* value) {
+ json_t *root;
+
+ root = json_object();
+ json_object_set_new(root, DEFAULT_KEY, json_string(value));
+
+ char* ret = json_dumps(root, 0);
+ json_decref(root);
+
+ return ret;
+}
+
+/**
+ * Creates string representing JSON object with multiple key:value pairs
+ * where keys are taken from "keys" parameter (separated by "keys_separator"
+ * character) and values are taken from "values" parameter (separated by
+ * "values_separator" character). Number of elements in both keys and values
+ * should match.
+ *
+ * @param keys null-terminated string containing keys for JSON map entries
+ * @param keys_delimiters characters by which keys are separated
+ * @param values null-terminated string containing values for JSON map entries
+ * @param values_delimiters characters by which values are separated
+ * @return encoded JSON string
+ */
+char* json_create_from_multiple_values(const char *keys, const char *keys_delimiters,
+ const char *values, char *values_delimiters) {
+ json_t *root;
+ char keysbuff[8192], valuesbuff[8192];
+ char *saveptr1, *saveptr2;
+
+ root = json_object();
+ strncpy(keysbuff, keys, strlen(keys));
+ keysbuff[strlen(keys)] = '\0';
+
+ strncpy(valuesbuff, values, strlen(values));
+ valuesbuff[strlen(values)] = '\0';
+
+ char *keyToken = strtok_r(keysbuff, keys_delimiters, &saveptr1);
+ char *valueToken = strtok_r(valuesbuff, values_delimiters, &saveptr2);
+
+ while (keyToken && valueToken) {
+ json_object_set_new(root, keyToken, json_string(valueToken));
+
+ keyToken = strtok_r(NULL, keys_delimiters, &saveptr1);
+ valueToken = strtok_r(NULL, values_delimiters, &saveptr2);
+ }
+
+ char* ret = json_dumps(root, 0);
+ json_decref(root);
+
+ return ret;
+}
+
+/**
+ * Creates string representing JSON object with proper key:value pairs.
+ * Keys and values are taken from parameter and are separated by colon
+ * while pairs are separated by new line character, e.g.:
+ * key1: value1
+ * key2: value2
+ *
+ * @param pairs null-terminated string containing key:value pairs
+ * @return encoded JSON string
+ */
+char* json_create_from_key_value_pairs(const char* pairs) {
+ json_t *root;
+ char key[1024], value[1024], buff[8192];
+ int i;
+ char *saveptr;
+
+ root = json_object();
+ strncpy(buff, pairs, strlen(pairs));
+ buff[strlen(pairs)] = '\0';
+ char *token = strtok_r(buff, "\n", &saveptr);
+
+ while (token) {
+ i = strcspn(token, ":");
+ strncpy(key, token, i);
+ key[i] = '\0';
+ while(isspace(token[i+1])) { // skip whitespace characters from beginning of value if any
+ i++;
+ }
+ strncpy(value, token+i+1, strlen(token)-i);
+ value[strlen(token)-i] = '\0';
+ json_object_set_new(root, key, json_string(value));
+ token = strtok_r(NULL, "\n", &saveptr);
+ }
+
+ char* ret = json_dumps(root, 0);
+ json_decref(root);
+
+ return ret;
+}
+
+/**
+ * Reads value from JSON object represented by jsontext using specific key
+ *
+ * @param jsontext string representing JSON object
+ * @param key by which value should be obtained from JSON map
+ */
+char* json_read_map_value(const char *jsontext, const char *key) {
+ json_t *root;
+ json_error_t error;
+ json_t *data;
+
+ root = json_loads(jsontext, 0, &error);
+
+ if(!root)
+ {
+ log_println(0, "Error while reading value from JSON string: %s", error.text);
+ return NULL;
+ }
+
+ if(!json_is_object(root))
+ {
+ log_println(0, "Error while reading value from JSON string: root is not an object");
+ json_decref(root);
+ return NULL;
+ }
+
+ data = json_object_get(root, key);
+ if(data != NULL)
+ {
+ char *value = json_string_value(data);
+
+ return value;
+ }
+ else
+ return NULL;
+}
+
+/**
+ * Checks if given msg has correct JSON format
+ * @param msg message to check for correct JSON format
+ * @return 0 if msg is correct JSON message
+ * -1 otherwise
+ */
+int json_check_msg(const char* msg) {
+ json_t *root;
+ json_error_t error;
+
+ root = json_loads(msg, 0, &error);
+
+ if(!root)
+ {
+ return -1;
+ }
+
+ return 0;
+}
=======================================
--- /dev/null
+++ /branches/Issue136/src/jsonutils.h Wed May 28 13:01:29 2014 UTC
@@ -0,0 +1,26 @@
+/*
+ * This file contains function declarations to handle json messages
+ *
+ * Sebastian Kostuch 2014-04-30
+ *

+ */
+
+#ifndef SRC_JSONUTILS_H_
+#define SRC_JSONUTILS_H_
+
+#include <jansson.h>
+#include <string.h>
+
+#define JSON_SINGLE_VALUE 1
+#define JSON_MULTIPLE_VALUES 2
+#define JSON_KEY_VALUE_PAIRS 3
+#define DEFAULT_KEY "msg"
+
+char* json_create_from_single_value(const char* value);
+char* json_create_from_multiple_values(const char *keys, const char *keys_delimiters,
+ const char *values, char *values_delimiters);
+char* json_create_from_key_value_pairs(const char* pairs);
+char* json_read_map_value(const char *jsontext, const char *key);
+int json_check_msg(const char* msg);
+
+#endif // SRC_JSONUTILS_H_
=======================================
--- /branches/Issue136/Applet/MANIFEST.MF Wed Feb 5 13:38:45 2014 UTC
+++ /branches/Issue136/Applet/MANIFEST.MF Wed May 28 13:01:29 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
=======================================
--- /branches/Issue136/Applet/Makefile.am Wed Feb 12 07:16:35 2014 UTC
+++ /branches/Issue136/Applet/Makefile.am Wed May 28 13:01:29 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

=======================================
--- /branches/Issue136/Applet/src/edu/internet2/ndt/MessageType.java Tue Feb 4 10:07:07 2014 UTC
+++ /branches/Issue136/Applet/src/edu/internet2/ndt/MessageType.java Wed May 28 13:01:29 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;

}
=======================================
--- /branches/Issue136/Applet/src/edu/internet2/ndt/NDTConstants.java Tue Feb 4 10:07:07 2014 UTC
+++ /branches/Issue136/Applet/src/edu/internet2/ndt/NDTConstants.java Wed May 28 13:01:29 2014 UTC
@@ -20,7 +20,26 @@
public static final String META_BROWSER_OS = "client.browser.name";
public static final String META_CLIENT_KERNEL_VERSION = "client.kernel.version";
public static final String META_CLIENT_VERSION = "client.version";
- public static final String META_CLIENT_APPLICATION = "client.application";
+ public static final String META_CLIENT_APPLICATION = "client.application";
+
+ // Section: NDT Variables sent by server
+ public static final String AVGRTT = "avgrtt";
+ public static final String CURRWINRCVD = "CurRwinRcvd";
+ public static final String MAXRWINRCVD = "MaxRwinRcvd";
+ public static final String LOSS = "loss";
+ public static final String MINRTT = "MinRTT";
+ public static final String MAXRTT = "MaxRTT";
+ public static final String WAITSEC = "waitsec";
+ public static final String CURRTO = "CurRTO";
+ public static final String SACKSRCVD = "SACKsRcvd";
+ public static final String MISMATCH = "mismatch";
+ public static final String BAD_CABLE = "bad_cable";
+ public static final String CONGESTION = "congestion";
+ public static final String CWNDTIME = "cwndtime";
+ public static final String RWINTIME = "rwintime";
+ public static final String OPTRCVRBUFF = "optimalRcvrBuffer";
+ public static final String ACCESS_TECH = "accessTech";
+ public static final String DUPACKSIN = "DupAcksIn";

/*
* TODO for a later release: Version could be moved to some
"configurable"
=======================================
--- /branches/Issue136/Applet/src/edu/internet2/ndt/Protocol.java Tue Feb 4 10:07:07 2014 UTC
+++ /branches/Issue136/Applet/src/edu/internet2/ndt/Protocol.java Wed May 28 13:01:29 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
=======================================
--- /branches/Issue136/Applet/src/edu/internet2/ndt/Tcpbw100.java Tue Mar 25 13:51:45 2014 UTC
+++ /branches/Issue136/Applet/src/edu/internet2/ndt/Tcpbw100.java Wed May 28 13:01:29 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
@@ -253,7 +253,7 @@
// private String pub_CWNDpeaks = ""; // source variable does not
exist
private int pub_SACKsRcvd = 0;
private String pub_osVer = "unknown";
- private String pub_javaVer = "unknown";
+ private String pub_pluginVer = "unknown";
private String pub_host = "unknown";
private String pub_osName = "unknown";
private String pub_osArch = "unknown";
@@ -265,6 +265,7 @@
private String pub_AccessTech = "unknown";
private String pub_natBox = "unknown";
private int pub_DupAcksOut = 0;
+ private int pub_DupAcksIn = 0;
private Date pub_TimeStamp;
private String pub_isReady = new String("no");
private String pub_clientIP = "unknown";
@@ -278,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
@@ -297,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();
@@ -358,8 +361,8 @@
return pub_osVer;
}

- public String get_javaVer() {
- return pub_javaVer;
+ public String get_pluginVer() {
+ return pub_pluginVer;
}

public String get_host() {
@@ -417,7 +420,7 @@
}

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

@@ -432,6 +435,10 @@
public String get_DupAcksOut() {
return Integer.toString(pub_DupAcksOut);
}
+
+ public String get_DupAcksIn() {
+ return Integer.toString(pub_DupAcksIn);
+ }

public String get_TimeStamp() {
String result = "unknown";
@@ -482,7 +489,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 +528,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 +898,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 +1129,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 +1150,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 +1164,7 @@
}
// prefer IPv6 checkbox
else if (source == _chkboxPreferIPv6) {
- setsHostName(sHostName);
+ setsHostName(sHostName);
}
// mail to functionality
else if (source == _buttonMailTo) {
@@ -1216,33 +1223,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 +1268,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 +1297,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 +1308,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 +1382,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 +1396,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 +1410,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 +1482,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 +1494,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 +1514,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 +1541,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 +1554,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 +1568,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 +1613,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 +1622,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 +1631,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 +1651,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 +1667,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 +1678,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 +1686,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 +1697,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 +1708,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 +1736,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 +1760,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 +1772,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 +1809,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 +1820,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 +1833,7 @@
if (c == 'z') {
c = '0';
}
- _yabuff2Write[i] = c++;
+ _yabuff2Write[i] = c++;
}
System.err.println("******Send buffer size =" + i);

@@ -1810,14 +1864,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 +1898,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 +1923,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 +1934,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 +1970,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 +1981,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 +2003,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 +2026,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 +2036,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 +2070,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 +2080,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 +2091,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 +2116,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 +2141,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 +2151,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 +2217,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 +2235,7 @@


// correctly
_sErrMsg = _resBundDisplayMsgs

.getString("protocolError")
- +
Integer.parseInt(new String(msg.getBody()),
+ +
parseMsgBodyToInt(new String(msg.getBody()),
16) +
" instead\n";
return true;
}
@@ -2176,14 +2252,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 +2291,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 +2314,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 +2324,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 +2337,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 +2350,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 +2363,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 +2391,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 +2401,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 +2427,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 +2517,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 +2538,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 +2550,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;
***The diff for this file has been truncated for email.***
=======================================
--- /branches/Issue136/Applet/src/edu/internet2/ndt/locale/Tcpbw100_msgs_en_US.properties Tue Mar 4 08:44:05 2014 UTC
+++ /branches/Issue136/Applet/src/edu/internet2/ndt/locale/Tcpbw100_msgs_en_US.properties Wed May 28 13:01:29 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
=======================================
--- /branches/Issue136/HTML5-frontend/script.js Fri Mar 18 14:44:18 2011 UTC
+++ /branches/Issue136/HTML5-frontend/script.js Wed May 28 13:01:29 2014 UTC
@@ -58,7 +58,7 @@
showPage('test');
if (simulate) return simulateTest();
currentPhase = PHASE_WELCOME;
- testApplet().run_test();
+ testNDT().run_test();
monitorTest();
}

@@ -322,107 +322,107 @@



-// TESTING APPLET
+// TESTING JAVA/FLASH CLIENT

-function testApplet() {
- return applet = document.applets['NDT'];
+function testNDT() {
+ return ndt = document.getElementById('NDT');
}

function testStatus() {
- return testApplet().get_status();
+ return testNDT().get_status();
}

function testDiagnosis() {
if (simulate) return "Test diagnosis";
- return testApplet().get_diagnosis();
+ return testNDT().get_diagnosis();
}

function testError() {
- return testApplet().get_errmsg();
+ return testNDT().get_errmsg();
}

function remoteServer() {
if (simulate) return '0.0.0.0';
- return testApplet().get_host();
+ return testNDT().get_host();
}

function uploadSpeed(raw) {
if (simulate) return 0;
- var speed = testApplet().get_c2sspd();
+ var speed = testNDT().getNDTvar("ClientToServerSpeed");
return raw ? speed : parseFloat(speed);
}

function downloadSpeed() {
if (simulate) return 0;
- return parseFloat(testApplet().get_s2cspd());
+ return parseFloat(testNDT().getNDTvar("ServerToClientSpeed"));
}

function averageRoundTrip() {
if (simulate) return 0;
- return parseFloat(testApplet().get_avgrtt());
+ return parseFloat(testNDT().getNDTvar("avgrtt"));
}

function jitter() {
if (simulate) return 0;
- return parseFloat(testApplet().get_jitter());
+ return parseFloat(testNDT().getNDTvar("Jitter"));
}

function testDetails() {
if (simulate) return 'Test details';

- var a = testApplet();
+ var a = testNDT();
var d = '';

- d += "Your system: " + a.get_osName() + " version " + a.get_osVer() + "<br>";
- d += "Java version: " + a.get_javaVer() + " (" + a.get_osArch() + ")<br>";
+ d += "Your system: " + a.getNDTvar("OperatingSystem") + "<br>";
+ d += "Plugin version: " + a.getNDTvar("PluginVersion") + " (" + a.getNDTvar("OsArchitecture") + ")<br>";

d += "<br>";

- d += "TCP receive window: " + a.get_CurRwinRcvd() + " current, " + a.get_MaxRwinRcvd() + " maximum<br>";
- d += a.get_loss() + " packets lost during test<br>";
- d += "Round trip time: " + a.get_Ping() + " msec (minimum), " + a.get_MaxRTT() + " msec (maximum), " + a.get_avgrtt() + " msec (average)<br>";
- d += "Jitter: " + a.get_jitter() + " msec<br>";
- d += a.get_WaitSec() + " seconds spend waiting following a timeout<br>";
- d += "TCP time-out counter: " + a.get_CurRTO() + "<br>";
- d += a.get_SACKsRcvd() + " selective acknowledgement packets received<br>";
+ d += "TCP receive window: " + a.getNDTvar("CurRwinRcvd") + " current, " + a.getNDTvar("MaxRwinRcvd") + " maximum<br>";
+ d += a.getNDTvar("loss") + " packets lost during test<br>";
+ d += "Round trip time: " + a.getNDTvar("MinRTT") + " msec (minimum), " + a.getNDTvar("MaxRTT") + " msec (maximum), " + a.getNDTvar("avgrtt") + " msec (average)<br>";
+ d += "Jitter: " + a.getNDTvar("Jitter") + " msec<br>";
+ d += a.getNDTvar("waitsec") + " seconds spend waiting following a timeout<br>";
+ d += "TCP time-out counter: " + a.getNDTvar("CurRTO") + "<br>";
+ d += a.getNDTvar("SACKsRcvd") + " selective acknowledgement packets received<br>";

d += "<br>";

- if (a.get_mismatch() == "yes") {
+ if (a.getNDTvar("mismatch") == "yes") {
d += "A duplex mismatch condition was detected.<br>";
}
else {
d += "No duplex mismatch condition was detected.<br>";
}

- if (a.get_Bad_cable() == "yes") {
+ if (a.getNDTvar("bad_cable") == "yes") {
d += "The test detected a cable fault.<br>";
}
else {
d += "The test did not detect a cable fault.<br>";
}

- if (a.get_congestion() == "yes") {
+ if (a.getNDTvar("congestion") == "yes") {
d += "Network congestion may be limiting the connection.<br>";
}
else {
d += "No network congestion was detected.<br>";
}

- if (a.get_natStatus() == "yes") {
- d += "A network addess translation appliance was detected.<br>";
+ /*if (a.get_natStatus() == "yes") {
+ d += "A network address translation appliance was detected.<br>";
}
else {
d += "No network addess translation appliance was detected.<br>";
- }
+ }*/

d += "<br>";

- d += a.get_cwndtime() + "% of the time was not spent in a receiver limited or sender limited state.<br>";
- d += a.get_rcvrLimiting() + "% of the time the connection is limited by the client machine's receive buffer.<br>";
- d += "Optimal receive buffer: " + a.get_optimalRcvrBuffer() + " bytes<br>";
- d += "Bottleneck link: " + a.get_AccessTech() + "<br>";
- d += a.get_DupAcksOut() + " duplicate ACKs set<br>";
+ d += a.getNDTvar("cwndtime") + "% of the time was not spent in a receiver limited or sender limited state.<br>";
+ d += a.getNDTvar("rwintime") + "% of the time the connection is limited by the client machine's receive buffer.<br>";
+ d += "Optimal receive buffer: " + a.getNDTvar("optimalRcvrBuffer") + " bytes<br>";
+ d += "Bottleneck link: " + a.getNDTvar("accessTech") + "<br>";
+ d += a.getNDTvar("DupAcksIn") + " duplicate ACKs set<br>";

return d;
}
=======================================
--- /branches/Issue136/HTML5-frontend/widget.html Tue Mar 11 08:42:37 2014 UTC
+++ /branches/Issue136/HTML5-frontend/widget.html Wed May 28 13:01:29 2014 UTC
@@ -118,7 +118,11 @@
</div>
</div>

-<applet name="NDT" code="Tcpbw100.class" codebase="<?php print $applet_url ?>" archive="Tcpbw100.jar" width="400" height="400"></applet>
+<!--Use embed tag to have flash client being background for JS UI or applet tag if you want to use java applet instead. -->
+<applet id="NDT" name="NDT" code="edu.internet2.ndt.Tcpbw100.class" codebase="<?php print $applet_url ?>" archive="Tcpbw100.jar" width="400" height="400"></applet>
+
+<!--<embed id="NDT" name="NDT" type="application/x-shockwave-flash" src="FlashClt.swf" width="600" height="400" />-->
+

</body>
</html>
=======================================
--- /branches/Issue136/conf/create-html.sh Thu Feb 13 06:22:16 2014 UTC
+++ /branches/Issue136/conf/create-html.sh Wed May 28 13:01:29 2014 UTC
@@ -73,7 +73,7 @@


if test -f tcpbw100.template ; then
- TEMPLATE_FLASH=../tcpbw100.template
+ TEMPLATE_FLASH=tcpbw100.template
elif test -f ../tcpbw100.template ; then
TEMPLATE_FLASH=../tcpbw100.template
fi
=======================================
--- /branches/Issue136/configure.ac Wed Feb 12 07:16:35 2014 UTC
+++ /branches/Issue136/configure.ac Wed May 28 13:01:29 2014 UTC
@@ -88,6 +88,16 @@
AM_CONDITIONAL(BUILD_APPLET, false)
fi

+# Enabling/disabling fakewww build
+AC_ARG_ENABLE(fakewww, [ --enable-fakewww=[yes/no] turn on fakewww build
+ [default=no]],, enable_fakewww=no_def)
+
+if test "x$enable_fakewww" != "xyes"; then
+ AM_CONDITIONAL(BUILD_FAKEWWW, false)
+else
+ AM_CONDITIONAL(BUILD_FAKEWWW, true)
+fi
+
# Using certificate to sign java applet
AC_ARG_WITH(cert,
AC_HELP_STRING([--with-cert=<file>],
@@ -223,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"
@@ -273,6 +293,7 @@
AC_SUBST(NDTLIBDIR)
AC_SUBST(NDTINCDIR)
AC_SUBST(ZLIB)
+AC_SUBST(JSONLIB)

AC_SUBST(TOP_BUILD_DIRS)

@@ -345,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)"
@@ -356,14 +382,29 @@
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
+if test "x$enable_fakewww" == "xno"; then
+SUMMARY_FAKEWWW="NO (disabled by user)"
+elif test "x$enable_fakewww" != "xyes"; then
+SUMMARY_FAKEWWW="NO (disabled by default)"
+else
SUMMARY_FAKEWWW="YES"
+fi
SUMMARY_ANALYZE="YES"
SUMMARY_VIEWTRACE="YES"
SUMMARY_TRMKMAP="YES"
@@ -411,7 +452,7 @@
echo "* flash-client: ${SUMMARY_FLASHCLT}"
echo ""

-if test "$SUMMARY_FAKEWWW" = "YES" && (test "$SUMMARY_WEB100SRV" = "YES" | | test "$SUMMARY_WEB100GSRV" = "YES"); then
+if test "$SUMMARY_WEB100SRV" = "YES" || test "$SUMMARY_WEB100GSRV" = "YES"; then
echo "*** Server Tools - complete"
else
echo "*** Server Tools - incomplete"
@@ -435,3 +476,5 @@
echo "* Admin.class: ${SUMMARY_ADMINCLASS}"
echo ""
echo ""
+
+
=======================================
--- /branches/Issue136/flash-client/src/GUI.as Wed Feb 26 07:57:55 2014 UTC
+++ /branches/Issue136/flash-client/src/GUI.as Wed May 28 13:01:29 2014 UTC
@@ -377,7 +377,6 @@

private function clickRestart(e:MouseEvent):void {
hideResultsScreen();
- TestResults.clearResults();
_consoleText.text = "";
this.addChild(_consoleText);
_callerObj.startNDTTest();
=======================================
--- /branches/Issue136/flash-client/src/Handshake.as Fri Feb 21 07:41:20 2014 UTC
+++ /branches/Issue136/flash-client/src/Handshake.as Wed May 28 13:01:29 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) {
@@ -52,8 +53,17 @@

public function run():void {
var msgBody:ByteArray = new ByteArray();
+ var clientVersion:String = NDTConstants.CLIENT_VERSION;
+
msgBody.writeByte(_testsRequestByClient);
- _msg = new Message(MessageType.MSG_LOGIN, msgBody);
+ 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);
+ }
+
if (!_msg.sendMessage(_ctlSocket)) {
failHandshake();
}
@@ -97,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;
@@ -129,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);

@@ -198,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();
}
@@ -242,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)
@@ -297,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);

=======================================
--- /branches/Issue136/flash-client/src/Main.as Fri Feb 21 08:01:33 2014 UTC
+++ /branches/Issue136/flash-client/src/Main.as Wed May 28 13:01:29 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)
@@ -47,18 +48,18 @@
// Set the properties of the SWF from HTML tags.
NDTUtils.initializeFromHTML(this.root.loaderInfo.parameters);

- var frame:NDTPController = new NDTPController(server_hostname,
- client_application);
+ var frame:NDTPController = NDTPController.getInstance();

stage.showDefaultContextMenu = false;
if (guiEnabled) {
gui = new GUI(stage.stageWidth, stage.stageHeight, frame);
this.addChild(gui);
- } else {
- // If guiEnabled compiler flag set to false, start test immediately.
- frame.startNDTTest();
}
NDTUtils.addJSCallbacks();
}
+
+ public static function getHost():String {
+ return server_hostname;
+ }
}
}
=======================================
--- /branches/Issue136/flash-client/src/Message.as Sun Feb 2 19:14:17 2014 UTC
+++ /branches/Issue136/flash-client/src/Message.as Wed May 28 13:01:29 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) {
=======================================
--- /branches/Issue136/flash-client/src/MessageType.as Sun Feb 2 19:14:17 2014 UTC
+++ /branches/Issue136/flash-client/src/MessageType.as Wed May 28 13:01:29 2014 UTC
@@ -31,6 +31,7 @@
public static const MSG_RESULTS:int = 8;
public static const MSG_LOGOUT:int = 9;
public static const MSG_WAITING:int = 10;
+ public static const MSG_EXTENDED_LOGIN:int = 11;
}
}

=======================================
--- /branches/Issue136/flash-client/src/NDTConstants.as Fri Feb 21 08:01:33 2014 UTC
+++ /branches/Issue136/flash-client/src/NDTConstants.as Wed May 28 13:01:29 2014 UTC
@@ -101,6 +101,7 @@
public static const DATA_RATE_OC_48:int = 8;
public static const DATA_RATE_10G_ETHERNET:int = 9;

+ public static const ACCESS_TECH:String = "accessTech";
public static const ACCESS_TECH_UNKNOWN:String = "Connection type unknown";
public static const ACCESS_TECH_DIALUP:String = "Dial-up Modem";
public static const ACCESS_TECH_CABLEDSL:String = "Cable/DSL modem";
@@ -229,6 +230,7 @@
public static const CWIN:String = "cwin";
public static const SPD:String = "spd";
public static const ASPD:String = "aspd";
+ public static const OPTRCVRBUFF:String = "optimalRcvrBuffer";
}
}

=======================================
--- /branches/Issue136/flash-client/src/NDTPController.as Fri Mar 7 10:48:11 2014 UTC
+++ /branches/Issue136/flash-client/src/NDTPController.as Wed May 28 13:01:29 2014 UTC
@@ -30,6 +30,7 @@
* the measurement tests and the retrieval of the test results.
*/
public class NDTPController {
+ private static var _instance:NDTPController = null;
private const READ_TIMEOUT:int = 10000; // 10sec
// Valid values for _testStage.
private const REMOTE_RESULTS1:int = 0;
@@ -51,11 +52,27 @@

_remoteTestResults = ""
}
+
+ public static function getInstance():NDTPController {
+ if (_instance == null) {
+ _instance = new NDTPController(Main.server_hostname,
+ Main.client_application);
+ }
+ return _instance;
+ }

public function startNDTTest():void {
_currentTest = 0;
+ // 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.";
TestResults.appendDebugMsg(ResourceManager.getInstance().getString(
NDTConstants.BUNDLE_NAME, "connectingTo", null, Main.locale)
+ " " + _hostname + " " + ResourceManager.getInstance().getString(
@@ -85,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.");
@@ -186,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.
@@ -205,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,
@@ -218,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)
@@ -251,6 +279,11 @@
"Client failed to close Control socket. Error" + e);
}

+ if (!TestResults.ndt_test_results::ndtTestFailed) {
+ TestResults.ndt_test_results::ndtErrStatus = "All tests completed OK.";
+ } else {
+ TestResults.ndt_test_results::ndtErrStatus = TestResults.getErrMsg();
+ }
TestResults.recordEndTime();
TestResults.ndt_test_results::remoteTestResults += _remoteTestResults;

=======================================
--- /branches/Issue136/flash-client/src/NDTUtils.as Wed Mar 12 17:17:08 2014 UTC
+++ /branches/Issue136/flash-client/src/NDTUtils.as Wed May 28 13:01:29 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.
@@ -47,6 +49,14 @@
} catch (e:Error) {
// TODO(tiziana): Find out why ExternalInterface.available does not work
// in some cases and this exception is raised.
+
+ // TestResults.appendDebugMsg() calls callExternalFunction
+ // to invoke JS callbacks. Without this check we can
+ // recurse infinitely.
+ if (functionName != "appendDebugOutput") {
+ TestResults.appendDebugMsg("Failed to call " + functionName + ": "
+ + e.toString());
+ }
}
}
/**
@@ -81,6 +91,8 @@
} catch(e:Error) {
// TODO(tiziana): Find out why ExternalInterface.available does not work
// in some cases and this exception is raised.
+ TestResults.appendDebugMsg("Failed to get window.navigator.userAgent: "
+ + e.toString());
}

try {
@@ -92,8 +104,8 @@
+ Main.server_hostname);
}
} catch(e:Error) {
- TestResults.appendDebugMsg("Bad Flash permissions: No "
- + "access to javascript.");
+ TestResults.appendDebugMsg("Failed to call getNDTServer(): "
+ + e.toString());
}

try {
@@ -107,8 +119,8 @@
+ Main.client_application);
}
} catch(e:Error) {
- TestResults.appendDebugMsg("Bad Flash permissions: No "
- + "access to javascript.");
+ TestResults.appendDebugMsg("Failed to call getClientApplication(): "
+ + e.toString());
}

try {
@@ -122,8 +134,8 @@
+ Main.ndt_description);
}
} catch(e:Error) {
- TestResults.appendDebugMsg("Bad Flash permissions: No "
- + "access to javascript.");
+ TestResults.appendDebugMsg("Failed to call getNDTDescription(): "
+ + e.toString());
}
}

@@ -159,12 +171,17 @@
// TODO(tiziana): Restrict domain to the M-Lab website/server.
Security.allowDomain("*");
try {
+ ExternalInterface.addCallback(
+ "run_test", NDTPController.getInstance().startNDTTest);
+ ExternalInterface.addCallback(
+ "get_status", TestResults.getTestStatus);
ExternalInterface.addCallback(
"getDebugOutput", TestResults.getDebugMsg);
ExternalInterface.addCallback(
- "getDetails", TestResults.getResultDetails);
+ "get_diagnosis", TestResults.getResultDetails);
ExternalInterface.addCallback(
- "getErrors", TestResults.getErrMsg);
+ "get_errmsg", TestResults.getErrStatus);
+ ExternalInterface.addCallback("get_host", Main.getHost);
ExternalInterface.addCallback(
"getNDTvar", TestResultsUtils.getNDTVariable);
} catch (e:Error) {
@@ -219,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 "";
+ }
}
}

=======================================
--- /branches/Issue136/flash-client/src/TestC2S.as Fri Feb 21 07:41:20 2014 UTC
+++ /branches/Issue136/flash-client/src/TestC2S.as Wed May 28 13:01:29 2014 UTC
@@ -30,6 +30,8 @@
* This class performs the Client-to-Server throughput test.
*/
public class TestC2S {
+ private const SPEED_UPDATE_TIMER:int = 1000; // ms
+
// Valid values for _testStage.
private static const PREPARE_TEST1:int = 0;
private static const PREPARE_TEST2:int = 1;
@@ -45,12 +47,14 @@
private var _c2sTestSuccess:Boolean;
// Time to send data to server on the C2S socket.
private var _c2sTestDuration:Number;
+ private var _c2sTestStartTime:Number;
private var _ctlSocket:Socket;
private var _c2sSocket:Socket;
private var _c2sSendCount:int;
// Bytes not sent from last send operation on the C2S socket.
private var _c2sBytesNotSent:int;
private var _c2sTimer:Timer;
+ private var _speedUpdateTimer:Timer;
private var _dataToSend:ByteArray;
private var _msg:Message;
private var _serverHostname:String;
@@ -64,6 +68,7 @@

_c2sTestSuccess = true; // Initially the test has not failed.
_c2sTestDuration = 0;
+ _c2sTestStartTime = 0;
_dataToSend = new ByteArray();
_c2sSendCount = 0;
_c2sBytesNotSent = 0;
@@ -142,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();
@@ -156,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 {
@@ -175,6 +188,8 @@

_c2sTimer = new Timer(NDTConstants.C2S_DURATION);
_c2sTimer.addEventListener(TimerEvent.TIMER, onC2STimeout);
+ _speedUpdateTimer = new Timer(SPEED_UPDATE_TIMER);
+ _speedUpdateTimer.addEventListener(TimerEvent.TIMER, onSpeedUpdate);
_msg = new Message();
_testStage = START_TEST;
TestResults.appendDebugMsg("C2S test: START_TEST stage.");
@@ -244,11 +259,24 @@
TestResults.appendDebugMsg("Timeout for sending data on C2S socket.");
closeC2SSocket();
}
+
+ private function onSpeedUpdate(e:TimerEvent):void {
+ _c2sTestDuration = getTimer() - _c2sTestStartTime;
+ _c2sBytesNotSent = _c2sSocket.bytesPending;
+ var c2sByteSent:Number = (
+ _c2sSendCount * NDTConstants.PREDEFINED_BUFFER_SIZE
+ + (NDTConstants.PREDEFINED_BUFFER_SIZE - _c2sBytesNotSent));
+
+ TestResults.ndt_test_results::c2sSpeed = (c2sByteSent
+ * NDTConstants.BYTES2BITS
+ / _c2sTestDuration);
+ }

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(
@@ -267,9 +295,10 @@
removeCtlSocketOnReceivedDataListener();

_c2sTimer.start();
+ _speedUpdateTimer.start();
// Record start time right before it starts sending data, to be as
// accurate as possible.
- _c2sTestDuration = getTimer();
+ _c2sTestStartTime = getTimer();

_testStage = SEND_DATA;
TestResults.appendDebugMsg("C2S test: SEND_DATA stage.");
@@ -288,9 +317,11 @@
private function closeC2SSocket():void {
// Record end time right after it stops sending data, to be as accurate as
// possible.
- _c2sTestDuration = getTimer() - _c2sTestDuration;
+ _c2sTestDuration = getTimer() - _c2sTestStartTime;
TestResults.appendDebugMsg(
"C2S test lasted " + _c2sTestDuration + " msec.");
+ _speedUpdateTimer.stop();
+ _speedUpdateTimer.removeEventListener(TimerEvent.TIMER, onSpeedUpdate);
_c2sTimer.stop();
_c2sTimer.removeEventListener(TimerEvent.TIMER, onC2STimeout);

@@ -358,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(
@@ -396,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(
=======================================
--- /branches/Issue136/flash-client/src/TestMETA.as Fri Feb 21 07:41:20 2014 UTC
+++ /branches/Issue136/flash-client/src/TestMETA.as Wed May 28 13:01:29 2014 UTC
@@ -39,8 +39,8 @@
private var _testStage:int;
private var _clientApplication:String;

- public function TestMETA(ctlSocket:Socket,
- clientApplication:String,
+ public function TestMETA(ctlSocket:Socket,
+ clientApplication:String,
callerObject:NDTPController) {
_callerObj = callerObject;
_ctlSocket = ctlSocket;
@@ -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(
=======================================
--- /branches/Issue136/flash-client/src/TestResults.as Mon Feb 24 10:22:22 2014 UTC
+++ /branches/Issue136/flash-client/src/TestResults.as Wed May 28 13:01:29 2014 UTC
@@ -34,7 +34,8 @@
ndt_test_results static var ndtVariables:Object = new Object();
ndt_test_results static var userAgent:String;
// Valid only when ndtTestFailed == false.
- ndt_test_results static var ndtTestStatus:String = null;
+ ndt_test_results static var ndtTestStatus:String = "notStarted";
+ ndt_test_results static var ndtErrStatus:String = "Test not run.";
ndt_test_results static var ndtTestFailed:Boolean = false;
ndt_test_results static var c2sSpeed:Number = 0.0;
ndt_test_results static var s2cSpeed:Number = 0.0;
@@ -55,6 +56,14 @@
public static function get duration():Number {
return _ndtTestEndTime - _ndtTestStartTime;
}
+
+ public static function getTestStatus():String {
+ return ndt_test_results::ndtTestStatus;
+ }
+
+ public static function getErrStatus():String {
+ return ndt_test_results::ndtErrStatus;
+ }

public static function get testList():String {
var testSuite:String = "";
@@ -153,7 +162,7 @@
accessTech = null;
linkSpeed = 0.0;
ndtVariables = new Object();
- ndtTestStatus = null;
+ ndtTestStatus = "notStarted";
ndtTestFailed = false;
c2sSpeed = 0.0;
s2cSpeed = 0.0;
=======================================
--- /branches/Issue136/flash-client/src/TestResultsUtils.as Sun Feb 2 19:14:17 2014 UTC
+++ /branches/Issue136/flash-client/src/TestResultsUtils.as Wed May 28 13:01:29 2014 UTC
@@ -75,23 +75,51 @@
case "TestDuration":
return TestResults.duration.toString();
case "ClientToServerSpeed":
- return TestResults.ndt_test_results::c2sSpeed.toString();
+ return (TestResults.ndt_test_results::c2sSpeed
+ / NDTConstants.KBITS2BITS).toString();
case "ServerToClientSpeed":
- return TestResults.ndt_test_results::s2cSpeed.toString();
+ return (TestResults.ndt_test_results::s2cSpeed
+ / NDTConstants.KBITS2BITS).toString();
case "Jitter":
return TestResults.jitter.toString();
case "OperatingSystem":
return Capabilities.os;
case "ClientVersion":
return NDTConstants.CLIENT_VERSION;
- case "FlashVersion":
+ case "PluginVersion":
return Capabilities.version;
case "OsArchitecture":
return Capabilities.cpuArchitecture;
+ case NDTConstants.MISMATCH:
+ if (TestResults.ndtVariables[varName]
+ == NDTConstants.DUPLEX_OK_INDICATOR)
+ return "no";
+ else
+ return "yes";
+ case NDTConstants.BAD_CABLE:
+ if (TestResults.ndtVariables[varName]
+ == NDTConstants.CABLE_STATUS_OK)
+ return "no";
+ else
+ return "yes";
+ case NDTConstants.CONGESTION:
+ if (TestResults.ndtVariables[varName]
+ == NDTConstants.CONGESTION_NONE)
+ return "no";
+ else
+ return "yes";
+ case NDTConstants.RWINTIME:
+ return String(TestResults.ndtVariables[varName] * NDTConstants.PERCENTAGE);
+ case NDTConstants.OPTRCVRBUFF:
+ return String(TestResults.ndtVariables[NDTConstants.MAXRWINRCVD] * NDTConstants.KBITS2BITS);
+ case NDTConstants.ACCESS_TECH:
+ return TestResults.ndt_test_results::accessTech;
+ default:
+ if (varName in TestResults.ndtVariables) {
+ return TestResults.ndtVariables[varName].toString();
+ }
}
- if (varName in TestResults.ndtVariables) {
- return TestResults.ndtVariables[varName].toString();
- }
+
return null;
}

=======================================
--- /branches/Issue136/flash-client/src/TestS2C.as Fri Feb 21 07:41:20 2014 UTC
+++ /branches/Issue136/flash-client/src/TestS2C.as Wed May 28 13:01:29 2014 UTC
@@ -31,6 +31,7 @@
public class TestS2C {
// Timer for single read operation.
private const READ_TIMEOUT:int = 15000; // 15sec
+ private const SPEED_UPDATE_TIMER:int = 1000; // ms

// Valid values for _testStage.
private static const PREPARE_TEST1:int = 0;
@@ -43,22 +44,26 @@
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;
private var _msg:Message;
private var _readTimer:Timer;
+ private var _speedUpdateTimer:Timer;
private var _s2cByteCount:int;
private var _s2cSocket:Socket;
private var _s2cTimer:Timer;
// Time to send data to client on the S2C socket.
private var _s2cTestDuration:Number;
+ private var _s2cTestStartTime:Number;
private var _s2cTestSuccess:Boolean;
private var _serverHostname:String;
private var _testStage:int;
private var _web100VarResult:String;

-
public function TestS2C(ctlSocket:Socket, serverHostname:String,
callerObj:NDTPController) {
_callerObj = callerObj;
@@ -67,6 +72,7 @@

_s2cTestSuccess = true; // Initially the test has not failed.
_s2cTestDuration = 0;
+ _s2cTestStartTime = 0;
_s2cByteCount = 0;
_web100VarResult = "";
}
@@ -147,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 {
@@ -172,6 +186,8 @@
}
_readTimer = new Timer(READ_TIMEOUT);
_readTimer.addEventListener(TimerEvent.TIMER, onS2CTimeout);
+ _speedUpdateTimer = new Timer(SPEED_UPDATE_TIMER);
+ _speedUpdateTimer.addEventListener(TimerEvent.TIMER, onSpeedUpdate);
_s2cTimer = new Timer(NDTConstants.S2C_DURATION);
_s2cTimer.addEventListener(TimerEvent.TIMER, onS2CTimeout);
_msg = new Message();
@@ -234,11 +250,19 @@
_readTimer.start();
receiveData();
}
+
+ private function onSpeedUpdate(e:TimerEvent):void {
+ _s2cTestDuration = getTimer() - _s2cTestStartTime;
+ TestResults.ndt_test_results::s2cSpeed = _s2cByteCount
+ * NDTConstants.BYTES2BITS
+ / _s2cTestDuration;
+ }

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
@@ -258,9 +282,10 @@

_readTimer.start();
_s2cTimer.start();
+ _speedUpdateTimer.start();
// Record start time right before it starts receiving data, to be as
// accurate as possible.
- _s2cTestDuration = getTimer();
+ _s2cTestStartTime = getTimer();

_testStage = RECEIVE_DATA;
TestResults.appendDebugMsg("S2C test: RECEIVE_DATA stage.");
@@ -290,9 +315,11 @@
// Record end time right after it stops receiving data, to be as accurate
// as possible.
_s2cTimer.stop();
- _s2cTestDuration = getTimer() - _s2cTestDuration;
+ _s2cTestDuration = getTimer() - _s2cTestStartTime;
TestResults.appendDebugMsg(
"S2C test lasted " + _s2cTestDuration + " msec.");
+ _speedUpdateTimer.stop();
+ _speedUpdateTimer.removeEventListener(TimerEvent.TIMER, onSpeedUpdate);
_readTimer.stop();
_readTimer.removeEventListener(TimerEvent.TIMER, onS2CTimeout);
_s2cTimer.removeEventListener(TimerEvent.TIMER, onS2CTimeout);
@@ -344,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(
@@ -399,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();
@@ -439,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);
@@ -458,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);
@@ -474,18 +522,23 @@
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();

TestResults.appendDebugMsg("S2C test: END_TEST stage.");
-
if (_s2cTestSuccess)
TestResults.appendDebugMsg(
ResourceManager.getInstance().getString(
=======================================
--- /branches/Issue136/flash-client/src/locale/en_US/DisplayMessages.properties Sun Feb 2 19:14:17 2014 UTC
+++ /branches/Issue136/flash-client/src/locale/en_US/DisplayMessages.properties Wed May 28 13:01:29 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
=======================================
--- /branches/Issue136/janalyze/src/edu/internet2/ndt/ResultsContainer.java Fri Feb 7 10:49:25 2014 UTC
+++ /branches/Issue136/janalyze/src/edu/internet2/ndt/ResultsContainer.java Wed May 28 13:01:29 2014 UTC
@@ -364,6 +364,7 @@
btlneck = "a Gigabit Ethernet subnet";
else
btlneck = "Retransmissions";
+ break;
case 11: btlneck = "an 'OC-48' subnet"; break;
case 12: btlneck = "a '10 Gigabit Enet' subnet"; break;
case 13: btlneck = "Retransmissions"; break;
=======================================
--- /branches/Issue136/src/Makefile.am Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue136/src/Makefile.am Wed May 28 13:01:29 2014 UTC
@@ -22,12 +22,16 @@

ndtdir = $(prefix)/ndt

+if BUILD_FAKEWWW
+ADD_FAKEWWW = fakewww
+endif
+
if HAVE_WEB100
bin_PROGRAMS = web100clt analyze viewtrace tr-mkmap genplot
if HAVE_PCAP_H
-sbin_PROGRAMS = fakewww web100srv
+sbin_PROGRAMS = $(ADD_FAKEWWW) web100srv
else
-sbin_PROGRAMS = fakewww
+sbin_PROGRAMS = $(ADD_FAKEWWW)
endif
else
bin_PROGRAMS = web100clt
@@ -38,15 +42,15 @@
if HAVE_WEB100
sbin_PROGRAMS += web10gsrv genplot10g
else
-sbin_PROGRAMS = fakewww web10gsrv genplot10g
+sbin_PROGRAMS = $(ADD_FAKEWWW) web10gsrv genplot10g
endif
endif
endif

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)

@@ -62,26 +66,28 @@
analyze_LDADD = $(NDTLIBS) $(I2UTILLIBDEPS) $(ZLIB)
analyze_CPPFLAGS ='-DBASEDIR="$(ndtdir)"' -DFORCE_WEB100

+if BUILD_FAKEWWW
fakewww_SOURCES = fakewww.c troute.c troute6.c tr-tree.c tr-tree6.c network.c usage.c logging.c \
runningtest.c ndtptestconstants.c strlutils.c
fakewww_LDADD = $(I2UTILLIBDEPS) $(ZLIB)
fakewww_CPPFLAGS ='-DBASEDIR="$(ndtdir)"'
+endif

web100srv_SOURCES = web100srv.c web100-util.c web100-pcap.c web100-admin.c runningtest.c \
network.c usage.c utils.c mrange.c logging.c testoptions.c ndtptestconstants.c \
protocol.c test_sfw_srv.c test_meta_srv.c ndt_odbc.c strlutils.c heuristics.c \
- test_c2s_srv.c test_s2c_srv.c test_mid_srv.c
+ test_c2s_srv.c test_s2c_srv.c test_mid_srv.c jsonutils.c
web100srv_LDFLAGS = $(NDTLDFLAGS) $(I2UTILLDFLAGS)
-web100srv_LDADD = $(NDTLIBS) $(I2UTILLIBS) $(I2UTILLIBDEPS) -lpthread $(ZLIB)
+web100srv_LDADD = $(NDTLIBS) $(I2UTILLIBS) $(I2UTILLIBDEPS) -lpthread $(ZLIB) $(JSONLIB)
web100srv_CPPFLAGS ='-DBASEDIR="$(ndtdir)"' -DFORCE_WEB100
web100srv_DEPENDENCIES = $(I2UTILLIBDEPS)

web10gsrv_SOURCES = web100srv.c web100-util.c web100-pcap.c web100-admin.c runningtest.c \
network.c usage.c utils.c mrange.c logging.c testoptions.c ndtptestconstants.c \
protocol.c test_sfw_srv.c test_meta_srv.c ndt_odbc.c strlutils.c heuristics.c \
- test_c2s_srv.c test_s2c_srv.c test_mid_srv.c web10g-util.c
+ test_c2s_srv.c test_s2c_srv.c test_mid_srv.c web10g-util.c jsonutils.c
web10gsrv_LDFLAGS = $(NDTLDFLAGS) $(I2UTILLDFLAGS)
-web10gsrv_LDADD = $(NDTLIBS) $(I2UTILLIBS) $(I2UTILLIBDEPS) -lpthread $(ZLIB)
+web10gsrv_LDADD = $(NDTLIBS) $(I2UTILLIBS) $(I2UTILLIBDEPS) -lpthread $(ZLIB) $(JSONLIB)
web10gsrv_CPPFLAGS = '-DBASEDIR="$(ndtdir)"'
web10gsrv_DEPENDENCIES = $(I2UTILLIBDEPS)

=======================================
--- /branches/Issue136/src/clt_tests.h Thu Nov 15 21:33:44 2012 UTC
+++ /branches/Issue136/src/clt_tests.h Wed May 28 13:01:29 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the function declarations to handle client's
* parts of the various tests.
*
- * Jakub S³awiñski 2006-08-02
+ * Jakub S�awi�ski 2006-08-02
*

*/

@@ -14,10 +14,10 @@
#define MIDBOX_TEST_RES_SIZE 512

int test_mid_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size, char* tmpstr2);
+ int buf_size, char* tmpstr2, int jsonSupport);
int test_c2s_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size);
+ int buf_size, int jsonSupport);
int test_s2c_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size, char* tmpstr);
+ int buf_size, char* tmpstr, int jsonSupport);

#endif // SRC_CLT_TESTS_H_
=======================================
--- /branches/Issue136/src/ndtptestconstants.h Thu Nov 15 21:33:44 2012 UTC
+++ /branches/Issue136/src/ndtptestconstants.h Wed May 28 13:01:29 2014 UTC
@@ -33,6 +33,13 @@
#define PORT3 "3003"
#define PORT4 "3003"

+// keys' names used for storing specific data in JSON format
+#define SERVER_ADDRESS "ServerAddress"
+#define CLIENT_ADDRESS "ClientAddress"
+#define CUR_MSS "CurMSS"
+#define WIN_SCALE_SENT "WinScaleSent"
+#define WIN_SCALE_RCVD "WinScaleRcvd"
+
// status of tests. Used mainly to log a "textual" explanation using below array
enum TEST_STATUS_INT {
TEST_NOT_STARTED, TEST_STARTED, TEST_INPROGRESS, TEST_INCOMPLETE, TEST_ENDED
=======================================
--- /branches/Issue136/src/network.c Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue136/src/network.c Wed May 28 13:01:29 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the functions needed to handle network related
* stuff.
*
- * Jakub S³awiñski 2006-05-30
+ * Jakub S�awi�ski 2006-05-30
*

*/

@@ -10,6 +10,7 @@
#include <netdb.h>
#include <string.h>
#include <unistd.h>
+#include "jsonutils.h"

#include "network.h"
#include "logging.h"
@@ -368,18 +369,93 @@
}

/**
- * Sends the protocol message to the control socket.
+ * Converts message to JSON format and sends it to the control socket.
* @param ctlSocket control socket
* @param type type of the message
* @param msg message to send
* @param len length of the message
+ * @param jsonSupport indicates if JSON format is supported by second side (if not
+ * then msg is being sent as it is and
no JSON converting is done)
+ * @param jsonConvertType defines how message converting should be handled:
+ * JSON_SINGLE_VALUE: single key/value pair is being created (using default key)
+ * with msg as value
+ * JSON_MULTIPLE_VALUES: multiple key/values pairs are being created using
+ * keys, keys_delimiters, values and values_delimiters
+ * params
+ * JSON_KEY_VALUE_PAIRS: given message contains one or many key/value pairs
+ * with following syntax: key1: value1
+ * key2: value2 etc
+ * @param keys buffer containing keys' values (used only when jsonConvertType is set to
+ * JSON_MULTIPLE_VALUES)
+ * @param keysDelimiters delimiters for keys parameter (used only when jsonConvertType is set to
+ * JSON_MULTIPLE_VALUES)
+ * @param values buffer containing map values, key-value matching is being done by order in which
+ * they appear in keys and values params (used only when jsonConvertType is set to
+ * JSON_MULTIPLE_VALUES)
+ * @param valuesDelimiters delimiters for values parameter (used only when jsonConvertType is
+ * set to JSON_MULTIPLE_VALUES)
+ *
* @return 0 on success, error code otherwise
* Error codes:
* -1 - Cannot write to socket at all
* -2 - Cannot complete writing full message data into socket
* -3 - Cannot write after retries
+ * -4 - Cannot convert msg to JSON
*
*/
+int send_json_msg(int ctlSocket, int type, const char* msg, int len, int jsonSupport,
+ int jsonConvertType, const char *keys, const char
*keysDelimiters,
+ const char *values, char *valuesDelimiters) {
+ char* tempBuff;
+ int ret = 0;
+ // if JSON is not supported by second side, sends msg as it is
+ if (!jsonSupport) {
+ return send_msg(ctlSocket, type, msg, len);
+ }
+
+ switch(jsonConvertType) {
+ case JSON_SINGLE_VALUE:
+ tempBuff = json_create_from_single_value(msg); break;
+ case JSON_MULTIPLE_VALUES:
+ tempBuff = json_create_from_multiple_values(keys, keysDelimiters,
+ values, valuesDelimiters); break;
+ case JSON_KEY_VALUE_PAIRS:
+ tempBuff = json_create_from_key_value_pairs(msg); break;
+ default:
+ return send_msg(ctlSocket, type, msg, len);
+ }
+
+ if (!tempBuff) {
+ return -4;
+ }
+ ret = send_msg(ctlSocket, type, tempBuff, strlen(tempBuff));
+ free(tempBuff);
+ return ret;
+}
+
+/**
+ * Shortest version of send_json_msg method. Uses default NULL values for JSON_MULTIPLE_VALUES
+ * convert type specific parameters.
+ */
+int send_json_message(int ctlSocket, int type, const char* msg, int len, int jsonSupport,
+ int jsonConvertType) {
+ return send_json_msg(ctlSocket, type, msg, len, jsonSupport, jsonConvertType,
+ NULL, NULL, NULL, NULL);
+}
+
+/**
+ * Sends the protocol message to the control socket.
+ * @param ctlSocket control socket
+ * @param type type of the message
+ * @param msg message to send
+ * @param len length of the message
+ * @return 0 on success, error code otherwise
+ * Error codes:
+ * -1 - Cannot write to socket at all
+ * -2 - Cannot complete writing full message data into socket
+ * -3 - Cannot write after retries
+ */
+

int send_msg(int ctlSocket, int type, const void* msg, int len) {
unsigned char buff[3];
=======================================
--- /branches/Issue136/src/network.h Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue136/src/network.h Wed May 28 13:01:29 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the definitions and function declarations to
* handle network related stuff.
*
- * Jakub S³awiñski 2006-05-30
+ * Jakub S�awi�ski 2006-05-30
*

*/

@@ -20,6 +20,11 @@
I2Addr CreateListenSocket(I2Addr addr, char* serv, int options, int buf_size);
int CreateConnectSocket(int* sockfd, I2Addr local_addr, I2Addr server_addr,
int option, int buf_sizes);
+int send_json_msg(int ctlSocket, int type, const char* msg, int len, int jsonSupport,
+ int jsonConvertType, const char *keys, const char *keysDelimiters,
+ const char *values, char *valuesDelimiters);
+int send_json_message(int ctlSocket, int type, const char* msg, int len, int jsonSupport,
+ int jsonConvertType);
int send_msg(int ctlSocket, int type, const void* msg, int len);
int recv_msg(int ctlSocket, int* type, void* msg, int* len);
int writen(int fd, const void* buf, int amount);
=======================================
--- /branches/Issue136/src/protocol.h Fri Feb 21 16:32:03 2014 UTC
+++ /branches/Issue136/src/protocol.h Wed May 28 13:01:29 2014 UTC
@@ -23,6 +23,9 @@
#define MSG_RESULTS 8
#define MSG_LOGOUT 9
#define MSG_WAITING 10
+#define MSG_EXTENDED_LOGIN 11
+
+#define CS_VERSION_LENGTH_MAX 32

#define SRV_QUEUE_TEST_STARTS_NOW 0
#define SRV_QUEUE_TEST_STARTS_NOW_STR "0"
=======================================
--- /branches/Issue136/src/test_c2s_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /branches/Issue136/src/test_c2s_clt.c Wed May 28 13:01:29 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the functions needed to handle C2S throughput
* test (client part).
*
- * Jakub S³awiñski 2006-08-02
+ * Jakub S�awi�ski 2006-08-02
*

*/

@@ -17,6 +17,7 @@
#include "network.h"
#include "protocol.h"
#include "utils.h"
+#include "jsonutils.h"

int pkts, lth;
int sndqueue;
@@ -31,6 +32,7 @@
* @param host Server name string
* @param conn_options Options to use while connecting to server(for ex, IPV4)
* @param buf_size TCP send/receive buffer size
+ * @param jsonSupport Indicates if messages should be send using JSON format
* @return integer > 0 if successful, < 0 in case of error
* Return codes:
* 1: Error receiving protocol message
@@ -42,12 +44,13 @@
*
*/
int test_c2s_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size) {
+ int buf_size, int jsonSupport) {
/* char buff[BUFFSIZE+1]; */
char buff[64 * KILO_BITS]; // message payload.
// note that there is a size variation between server and CLT - do not
// know why this was changed from BUFFZISE, though
// no specific problem is seen due to this
+ char* jsonMsgValue; // temporary buffer for storing values from JSON message

int msgLen, msgType; // message related data
int c2sport = atoi(PORT2); // default C2S port
@@ -83,6 +86,13 @@
msgLen)) {
return 2;
}
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
@@ -90,7 +100,6 @@

// Server sends port number to bind to in the TEST_PREPARE. Check if this
// message body (string) is a valid integral port number.
- buff[msgLen] = 0;
if (check_int(buff, &c2sport)) {
log_println(0, "Invalid port number");
return 4;
@@ -187,7 +196,14 @@
buff[msgLen] = 0;

// get C->S test speed as calculated by server
- c2sspd = atoi(buff);
+ if (json_check_msg(buff) == 0) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ c2sspd = atoi(jsonMsgValue);
+ free(jsonMsgValue);
+ }
+ else {
+ c2sspd = atoi(buff);
+ }

// Print results in the most convenient units (kbps or Mbps)
if (c2sspd < KILO)
=======================================
--- /branches/Issue136/src/test_c2s_srv.c Wed Mar 12 06:27:30 2014 UTC
+++ /branches/Issue136/src/test_c2s_srv.c Wed May 28 13:01:29 2014 UTC
@@ -20,6 +20,7 @@
#include "protocol.h"
#include "network.h"
#include "mrange.h"
+#include "jsonutils.h"

/**
* Perform the C2S Throughput test. This test intends to measure throughput
@@ -51,7 +52,7 @@
* >0 - error code
* Error codes:
* -1 - Listener socket creation failed
- * -100 - timeout while waiting for client to connect to serverÕs ephemeral port
+ * -100 - timeout while waiting for client to connect to server�s ephemeral port
* -errno - Other specific socket error numbers
* -101 - Retries exceeded while waiting for client to
connect
* -102 - Retries exceeded while waiting for data from
connected client
@@ -150,7 +151,7 @@
sizeof(buff),
"Server (C2S throughput test): CreateListenSocket failed: %s",
strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff), testOptions->json_support, JSON_SINGLE_VALUE);
return -1;
}

@@ -175,8 +176,8 @@

// send TEST_PREPARE message with ephemeral port detail, indicating start
// of tests
- if ((msgretvalue = send_msg(ctlsockfd, TEST_PREPARE, buff,
- strlen(buff))) < 0) {
+ if ((msgretvalue = send_json_message(ctlsockfd, TEST_PREPARE, buff,
+ strlen(buff), testOptions->json_support, JSON_SINGLE_VALUE)) < 0) {
return msgretvalue;
}

@@ -317,7 +318,7 @@
sleep(2);

// send empty TEST_START indicating start of the test
- send_msg(ctlsockfd, TEST_START, "", 0);
+ send_json_message(ctlsockfd, TEST_START, "", 0, testOptions->json_support, JSON_SINGLE_VALUE);
/* alarm(30); */ // reset alarm() again, this 10 sec test should finish
// before this signal is generated.

@@ -373,7 +374,7 @@
testOptions->child0);
log_println(1, "%s", buff);
snprintf(buff, sizeof(buff), "%0.0f", *c2sspd);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff), testOptions->json_support, JSON_SINGLE_VALUE);

// get receiver side Web100 stats and write them to the log file. close
// sockets
@@ -440,7 +441,7 @@
}

// An empty TEST_FINALIZE message is sent to conclude the test
- send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
+ send_json_message(ctlsockfd, TEST_FINALIZE, "", 0, testOptions->json_support, JSON_SINGLE_VALUE);

// Close opened resources for packet capture
if (getuid() == 0) {
=======================================
--- /branches/Issue136/src/test_meta.h Thu Nov 15 21:33:44 2012 UTC
+++ /branches/Issue136/src/test_meta.h Wed May 28 13:01:29 2014 UTC
@@ -16,6 +16,6 @@

#define META_TEST_LOG "META test"

-int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options);
+int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options, int jsonSupport);

#endif // SRC_TEST_META_H_
=======================================
--- /branches/Issue136/src/test_meta_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /branches/Issue136/src/test_meta_clt.c Wed May 28 13:01:29 2014 UTC
@@ -19,6 +19,7 @@
#include "network.h"
#include "protocol.h"
#include "utils.h"
+#include "jsonutils.h"

int pkts, lth;
int sndqueue;
@@ -31,13 +32,14 @@
* @param tests set of tests to perform
* @param host hostname of the server
* @param conn_options connection options
+ * @param jsonSupport indicates if messages should be send using JSON format
* @return integer
* 0 = (the test has been finalized)
* >0 if protocol interactions were not as expected:
* 1: Unable to receive protocol message successfully
* 2: Wrong message type received
*/
-int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options) {
+int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options, int jsonSupport) {
char buff[1024], tmpBuff[512];
int msgLen, msgType;
FILE * fp;
@@ -83,7 +85,8 @@
fflush(stdout);

snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_APPLICATION, "cli");
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);
// send client os name details
if ((fp = fopen("/proc/sys/kernel/ostype", "r")) == NULL) {
log_println(0, "Unable to determine client os type.");
@@ -91,12 +94,14 @@
fscanf(fp, "%s", tmpBuff);
fclose(fp);
snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_OS, tmpBuff);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);
}

// send client browser name
snprintf(buff, sizeof(buff), "%s:%s", META_BROWSER_OS, "- (web100clt)");
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);

// send client kernel version
if ((fp = fopen("/proc/sys/kernel/osrelease", "r")) == NULL) {
@@ -106,16 +111,18 @@
fclose(fp);
snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_KERNEL_VERSION,
tmpBuff);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);
}

// send NDT client version
snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_VERSION, VERSION);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);

// Client can send any number of such meta data in a TEST_MSG
// .. format, and signal the end of the transmission using an empty TEST_MSG
- send_msg(ctlSocket, TEST_MSG, "", 0);
+ send_json_message(ctlSocket, TEST_MSG, "", 0, jsonSupport, JSON_SINGLE_VALUE);

printf("Done\n");

=======================================
--- /branches/Issue136/src/test_meta_srv.c Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue136/src/test_meta_srv.c Wed May 28 13:01:29 2014 UTC
@@ -18,6 +18,7 @@
#include "protocol.h"
#include "utils.h"
#include "testoptions.h"
+#include "jsonutils.h"

/**
* Performs the META test.
@@ -44,7 +45,7 @@
int msgLen, msgType;
char buff[BUFFSIZE + 1];
struct metaentry *new_entry = NULL;
- char* value;
+ char* value, *jsonMsgValue;

// protocol validation logs
enum TEST_ID testids = META;
@@ -59,14 +60,16 @@
protolog_status(testOptions->child0, testids, teststatuses, ctlsockfd);

// first message exchanged is am empty TEST_PREPARE message
- j = send_msg(ctlsockfd, TEST_PREPARE, "", 0);
+ j = send_json_message(ctlsockfd, TEST_PREPARE, "", 0,
+ testOptions->json_support, JSON_SINGLE_VALUE);
if (j == -1 || j == -2) { // Cannot write message headers/data
log_println(6, "META Error!, Test start message not sent!");
return j;
}

// Now, transmit an empty TEST_START message
- if (send_msg(ctlsockfd, TEST_START, "", 0) < 0) {
+ if (send_json_message(ctlsockfd, TEST_START, "", 0,
+ testOptions->json_support, JSON_SINGLE_VALUE) < 0) {
log_println(6, "META test - Test-start message failed");
}

@@ -79,7 +82,8 @@
log_println(0, "Protocol error!");
snprintf(buff, sizeof(buff),
"Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return 1;
}
if (check_msg_type("META test", TEST_MSG, msgType, buff, msgLen)) {
@@ -87,7 +91,8 @@
log_println(0, "Fault, unexpected message received!");
snprintf(buff, sizeof(buff),
"Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return 2;
}
if (msgLen < 0) {
@@ -95,9 +100,21 @@
log_println(0, "Improper message");
snprintf(buff, sizeof(buff),
"Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return 3;
}
+
+ buff[msgLen] = 0;
+ if (testOptions->json_support) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ if (strlen(jsonMsgValue) == 0) {
+ free(jsonMsgValue);
+ break;
+ }
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ free(jsonMsgValue);
+ }

// Received empty TEST_MSG. All meta_data has been received, and test
// can be finalized.
@@ -105,13 +122,13 @@
break;
}

- buff[msgLen] = 0;
value = index(buff, ':');
if (value == NULL) { // key-value separates by ":"
log_println(0, "Improper message");
snprintf(buff, sizeof(buff), "Server (META test): "
"Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return 4;
}
*value = 0;
@@ -153,7 +170,8 @@
new_entry->next = NULL; // ensure meta list ends here

// Finalize test by sending appropriate message, and setting status
- if (send_msg(ctlsockfd, TEST_FINALIZE, "", 0) < 0) {
+ if (send_json_message(ctlsockfd, TEST_FINALIZE, "", 0,
+ testOptions->json_support, JSON_SINGLE_VALUE) < 0) {
log_println(6, "META test - failed to send finalize message");
}

=======================================
--- /branches/Issue136/src/test_mid_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /branches/Issue136/src/test_mid_clt.c Wed May 28 13:01:29 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the functions needed to handle Middlebox
* test (client part).
*
- * Jakub S³awiñski 2006-08-02
+ * Jakub S�awi�ski 2006-08-02
*

*/

@@ -16,6 +16,7 @@
#include "protocol.h"
#include "utils.h"
#include "strlutils.h"
+#include "jsonutils.h"

/**
* Perform the client part of the middleBox testing. The middlebox test
@@ -29,6 +30,7 @@
* @param buf_size TCP send/receive buffer size
* @param testresult_str result obtained from server (containing server ip,
* client ip, currentMSS,
WinSCaleSent, WinScaleRcvd)
+ * @param jsonSupport Indicates if messages should be sent using JSON format
* @return integer
* => 0 on success
* < 0 if error
@@ -46,7 +48,7 @@
*
*/
int test_mid_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size, char* testresult_str) {
+ int buf_size, char* testresult_str, int jsonSupport) {
char buff[BUFFSIZE + 1];
int msgLen, msgType;
int midport = atoi(PORT3);
@@ -57,6 +59,7 @@
uint32_t bytes;
struct timeval sel_tv;
fd_set rfd;
+ char* jsonMsgValue;

enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
enum TEST_ID testids = MIDDLEBOX;
@@ -84,11 +87,17 @@
// The server is expected to send a message with a valid payload that
// contains the port number that server wants client to bind to for this
// test
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
}
- buff[msgLen] = 0;
if (check_int(buff, &midport)) { // obtained message does not contain
// integer port#
log_println(0, "Invalid port number");
@@ -168,6 +177,7 @@
msgLen)) {
return 2;
}
+ buff[msgLen] = 0;

strlcat(testresult_str, buff, MIDBOX_TEST_RES_SIZE);

@@ -178,7 +188,7 @@
log_println(4, "CWND limited speed = %0.2f kbps", spdin);

// client now sends throughput it calculated above to server, as a TEST_MSG
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlSocket, TEST_MSG, buff, strlen(buff), jsonSupport, JSON_SINGLE_VALUE);
printf("Done\n");

I2AddrFree(sec_addr);
=======================================
--- /branches/Issue136/src/test_mid_srv.c Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue136/src/test_mid_srv.c Wed May 28 13:01:29 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;

@@ -228,11 +233,6 @@
if (j == 4)
return RETRY_EXCEEDED_WAITING_DATA;
}
-
- // get meta test details copied into results
- memcpy(&meta.c_addr, &cli_addr, clilen);
- /* meta.c_addr = cli_addr; */
- meta.family = ((struct sockaddr *) &cli_addr)->sa_family;

buff[0] = '\0';
// get tcp_stat connection data
@@ -251,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)) {
@@ -266,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,
@@ -275,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);
@@ -299,7 +308,7 @@
shutdown(midsfd, SHUT_WR);
close(midsfd);
close(options->midsockfd);
- send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
+ send_json_message(ctlsockfd, TEST_FINALIZE, "", 0, options->json_support, JSON_SINGLE_VALUE);
log_println(1, " <--------- %d ----------->", options->child0);

// log end of test into protocol doc, just to delimit.
=======================================
--- /branches/Issue136/src/test_s2c_clt.c Tue May 21 14:47:24 2013 UTC
+++ /branches/Issue136/src/test_s2c_clt.c Wed May 28 13:01:29 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, " <------------------------->");
=======================================
--- /branches/Issue136/src/test_s2c_srv.c Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue136/src/test_s2c_srv.c Wed May 28 13:01:29 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;
@@ -135,6 +138,8 @@
snapArgs.delay = options->snapDelay;
wait_sig = 0;

+ log_println(0, "test client version: %s", testOptions->client_version);
+
// Determine port to be used. Compute based on options set earlier
// by reading from config file, or use default port2 (3003)
if (testOptions->s2copt) {
@@ -194,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;
}

@@ -210,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);
@@ -369,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);
@@ -480,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);
@@ -581,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

@@ -590,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
@@ -603,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,
@@ -612,25 +633,34 @@
buff,
sizeof(buff),
"Server (S2C throughput test): Invalid S2C throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return -2;
}
+ buff[msgLen] = 0;
+ if (testOptions->json_support) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) {
log_println(0, "Improper message");
snprintf(
buff,
sizeof(buff),
"Server (S2C throughput test): Invalid S2C throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ send_json_message(ctlsockfd, MSG_ERROR, buff, strlen(buff),
+ testOptions->json_support, JSON_SINGLE_VALUE);
return -3;
}
- buff[msgLen] = 0;
*s2cspd = atoi(buff); // save Throughput value as seen by client
log_println(6, "S2CSPD from client %f", *s2cspd);
// Final activities of ending tests. Close sockets, file descriptors,
// send finalise message to client
close(xmitsfd);
- if (send_msg(ctlsockfd, TEST_FINALIZE, "", 0) < 0)
+ if (send_json_message(ctlsockfd, TEST_FINALIZE, "", 0,
+ testOptions->json_support, JSON_SINGLE_VALUE) < 0)
log_println(6,
"S2C test - failed to send finalize message to pid=%d",
s2c_childpid);
=======================================
--- /branches/Issue136/src/test_sfw.h Thu Nov 15 21:33:44 2012 UTC
+++ /branches/Issue136/src/test_sfw.h Wed May 28 13:01:29 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the function declarations to handle simple
* firewall test.
*
- * Jakub S³awiñski 2006-07-15
+ * Jakub S�awi�ski 2006-07-15
*

*/

@@ -17,8 +17,10 @@
#define SFW_TEST_DEFAULT_LEN 20
#define SFW_PREDEFINED_TEST_MSG "Simple firewall test"
#define SFW_TEST_LOG "Simple firewall test"
+#define EMPHERAL_PORT_NUMBER "empheralPortNumber"
+#define TEST_TIME "testTime"

-int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options);
+int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options, int jsonSupport);
int results_sfw(char tests, char* host);

#endif // SRC_TEST_SFW_H_
=======================================
--- /branches/Issue136/src/test_sfw_clt.c Thu Nov 15 21:34:19 2012 UTC
+++ /branches/Issue136/src/test_sfw_clt.c Wed May 28 13:01:29 2014 UTC
@@ -2,7 +2,7 @@
* This file contains the functions needed to handle simple firewall
* test (client part).
*
- * Jakub S³awiñski 2006-07-15
+ * Jakub S�awi�ski 2006-07-15
*

*/

@@ -18,6 +18,7 @@
#include "protocol.h"
#include "network.h"
#include "utils.h"
+#include "jsonutils.h"

static int c2s_result = SFW_NOTTESTED;
static int s2c_result = SFW_NOTTESTED;
@@ -57,6 +58,8 @@
int msgLen, msgType;
struct sockaddr_storage srv_addr;
socklen_t srvlen;
+ int jsonSupport = *((int*) vptr);
+ char* jsonMsgValue;

// protocol logging
enum PROCESS_TYPE_INT proctypeenum = PROCESS_TYPE;
@@ -115,7 +118,13 @@
// The server is expected to send a 20 char message that
// says "Simple firewall test" . Every other message string
// indicates an unknown firewall status
-
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen != SFW_TEST_DEFAULT_LEN) {
log_println(0, "Simple firewall test: Improper message");
s2c_result = SFW_UNKNOWN;
@@ -123,7 +132,6 @@
I2AddrFree(sfwcli_addr);
return NULL;
}
- buff[msgLen] = 0;
if (strcmp(buff, SFW_PREDEFINED_TEST_MSG) != 0) {
log_println(0, "Simple firewall test: Improper message");
s2c_result = SFW_UNKNOWN;
@@ -149,6 +157,7 @@
* @param tests set of tests to perform
* @param host hostname of the server
* @param conn_options the connection options
+ * @param jsonSupport indicates if messages should be sent using JSON format
* @return integer
* => 0 on success
* < 0 if error
@@ -165,13 +174,13 @@
* -3: Unable to resolve server address
*
*/
-int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options) {
+int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options, int jsonSupport) {
char buff[BUFFSIZE + 1];
int msgLen, msgType;
int sfwport, sfwsock, sfwsockport;
I2Addr sfwsrv_addr = NULL;
struct sigaction new, old;
- char* ptr;
+ char* ptr, *jsonMsgValue;
pthread_t threadId;

// variables used for protocol validation logs
@@ -203,28 +212,53 @@
// This message is expected to be of valid length, and have a message
// .. payload containing the integral ephemeral port number and testTime
// ... separated by a single space
+ buff[msgLen] = 0;
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
}
- buff[msgLen] = 0;
- ptr = strtok(buff, " ");
- if (ptr == NULL) {
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, EMPHERAL_PORT_NUMBER);
+ if (jsonMsgValue == NULL) {
+ log_println(0, "SFW: Improper message");
+ return 5;
+ }
+ if (check_int(jsonMsgValue, &sfwport)) { // get ephemeral port#
+ log_println(0, "Invalid port number");
+ return 4;
+ }
+ free(jsonMsgValue);
+
+ jsonMsgValue = json_read_map_value(buff, TEST_TIME);
+ if (jsonMsgValue == NULL) {
log_println(0, "SFW: Improper message");
return 5;
}
- if (check_int(ptr, &sfwport)) { // get ephemeral port#
- log_println(0, "Invalid port number");
+ if (check_int(jsonMsgValue, &testTime)) { // get test time
+ log_println(0, "Invalid waiting time");
return 4;
}
- ptr = strtok(NULL, " ");
- if (ptr == NULL) {
- log_println(0, "SFW: Improper message");
- return 5;
+ free(jsonMsgValue);
}
- if (check_int(ptr, &testTime)) { // get test time
- log_println(0, "Invalid waiting time");
- return 4;
+ else {
+ ptr = strtok(buff, " ");
+ if (ptr == NULL) {
+ log_println(0, "SFW: Improper message");
+ return 5;
+ }
+ if (check_int(ptr, &sfwport)) { // get ephemeral port#
+ log_println(0, "Invalid port number");
+ return 4;
+ }
+ ptr = strtok(NULL, " ");
+ if (ptr == NULL) {
+ log_println(0, "SFW: Improper message");
+ return 5;
+ }
+ if (check_int(ptr, &testTime)) { // get test time
+ log_println(0, "Invalid waiting time");
+ return 4;
+ }
}
log_println(1, "\n -- port: %d", sfwport);
log_println(1, " -- time: %d", testTime);
@@ -248,7 +282,8 @@

// Send a TEST_MSG to server with the client's port number
snprintf(buff, sizeof(buff), "%d", sfwsockport);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ send_json_message(ctlsockfd, TEST_MSG, buff, strlen(buff),
+ jsonSupport, JSON_SINGLE_VALUE);

// The server responds to the TEST_MSG messages with a TEST_START message.
// Any other type of message is an error here.
@@ -262,7 +297,7 @@

// Now listen for server sending out a test for the S->C direction , and
// update test results
- pthread_create(&threadId, NULL, &test_osfw_clt, NULL);
+ pthread_create(&threadId, NULL, &test_osfw_clt, &jsonSupport);

// ignore the alarm signal
memset(&new, 0, sizeof(new));
@@ -275,7 +310,8 @@

if (CreateConnectSocket(&sfwsock, NULL, sfwsrv_addr,
conn_options, 0) == 0) {
- send_msg(sfwsock, TEST_MSG, SFW_PREDEFINED_TEST_MSG, 20);
+ send_json_message(sfwsock, TEST_MSG, SFW_PREDEFINED_TEST_MSG, 20,
+ jsonSupport, JSON_SINGLE_VALUE);
}
alarm(0);
sigaction(SIGALRM, &old, NULL);
@@ -293,12 +329,17 @@
}

// The test results are sent as a numeric encoding the test results.
-
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) { // test results have valid length
log_println(0, "Improper message");
return 3;
}
- buff[msgLen] = 0;
if (check_int(buff, &c2s_result)) {
// test result has to be a valid integer
log_println(0, "Invalid test result");
=======================================
--- /branches/Issue136/src/test_sfw_srv.c Mon Oct 14 13:20:21 2013 UTC
+++ /branches/Issue136/src/test_sfw_srv.c Wed May 28 13:01:29 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);
}
=======================================
***Additional files exist in this changeset.***


  • [ndt-dev] [ndt] r1061 committed - Updated Issue136 branch with trunk changes, ndt, 05/28/2014

Archive powered by MHonArc 2.6.16.

Top of Page