Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r1057 committed - Add JSON support to java client

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r1057 committed - Add JSON support to java client


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r1057 committed - Add JSON support to java client
  • Date: Wed, 21 May 2014 09:10:01 +0000

Revision: 1057
Author:

Date: Wed May 21 09:09:42 2014 UTC
Log: Add JSON support to java client
http://code.google.com/p/ndt/source/detail?r=1057

Added:
/branches/Issue146/Applet/src/edu/internet2/ndt/JSONUtils.java
Modified:
/branches/Issue146
/branches/Issue146/Applet/MANIFEST.MF
/branches/Issue146/Applet/Makefile.am
/branches/Issue146/Applet/src/edu/internet2/ndt/MessageType.java
/branches/Issue146/Applet/src/edu/internet2/ndt/Protocol.java
/branches/Issue146/Applet/src/edu/internet2/ndt/Tcpbw100.java
/branches/Issue146/Applet/src/edu/internet2/ndt/locale/Tcpbw100_msgs_en_US.properties
/branches/Issue146/src/test_s2c_clt.c
/branches/Issue146/src/test_s2c_srv.c
/branches/Issue146/src/testoptions.c
/branches/Issue146/src/web100-util.c
/branches/Issue146/src/web100clt.c
/branches/Issue146/src/web100srv.c
/branches/Issue146/src/web100srv.h

=======================================
--- /dev/null
+++ /branches/Issue146/Applet/src/edu/internet2/ndt/JSONUtils.java Wed May 21 09:09:42 2014 UTC
@@ -0,0 +1,47 @@
+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 on 13.05.14.
+ */
+public class JSONUtils {
+ public static final int JSON_SINGLE_VALUE = 1;
+ public static final int JSON_MULTIPLE_VALUES = 2;
+ public static final int JSON_KEY_VALUE_PAIRS = 3;
+
+ public static String getSingleMessage(String jsonTxt) {
+ return getValueFromJsonObj(jsonTxt, "msg");
+ }
+
+ 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;
+ }
+
+ 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();
+ }
+
+ public static byte[] createJsonObj(byte[] msg) {
+ JSONObject obj = new JSONObject();
+ obj.put("msg", new String(msg));
+
+ return obj.toJSONString().getBytes();
+ }
+}
=======================================
--- /branches/Issue146/Applet/MANIFEST.MF Wed Feb 5 13:38:45 2014 UTC
+++ /branches/Issue146/Applet/MANIFEST.MF Wed May 21 09:09:42 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/Issue146/Applet/Makefile.am Wed Feb 12 07:16:35 2014 UTC
+++ /branches/Issue146/Applet/Makefile.am Wed May 21 09:09:42 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/Issue146/Applet/src/edu/internet2/ndt/MessageType.java Tue Feb 4 10:07:07 2014 UTC
+++ /branches/Issue146/Applet/src/edu/internet2/ndt/MessageType.java Wed May 21 09:09:42 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/Issue146/Applet/src/edu/internet2/ndt/Protocol.java Tue Feb 4 10:07:07 2014 UTC
+++ /branches/Issue146/Applet/src/edu/internet2/ndt/Protocol.java Wed May 21 09:09:42 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,43 @@
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
@@ -133,7 +171,7 @@
length += (int) yaMsgBody[2] & 0xFF;

if (readn(msgParam, length) != length) {
- return 3;
+ return 3;
}
return 0;
}
@@ -149,5 +187,9 @@
e.printStackTrace();
}
}
+
+ public void setJsonSupport(boolean jsonSupport) {
+ this.jsonSupport = jsonSupport;
+ }

} // end class Protocol
=======================================
--- /branches/Issue146/Applet/src/edu/internet2/ndt/Tcpbw100.java Fri Mar 21 10:33:50 2014 UTC
+++ /branches/Issue146/Applet/src/edu/internet2/ndt/Tcpbw100.java Wed May 21 09:09:42 2014 UTC
@@ -279,6 +279,8 @@
private long pub_bytes = 0;
private String _sIsAutoRun;
private String _sUserAgent = null;
+ private boolean jsonSupport = true;
+ private boolean retry = false;

/**
* public static void main for invoking as an Application
@@ -1263,7 +1265,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 +1294,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 +1305,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 +1379,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 +1393,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,32 +1407,69 @@

//
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
srvin2.close();
@@ -1440,7 +1479,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 +1491,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;
@@ -1479,7 +1518,7 @@
* 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 +1538,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 +1551,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,15 +1565,26 @@
// 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);
System.out.println("SFW: testTime=" + iTestTime);
@@ -1560,7 +1610,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 +1619,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 +1628,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 +1648,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 +1664,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 +1675,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 +1683,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 +1694,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 +1705,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 +1733,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 +1757,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 +1769,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 +1806,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 +1817,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;
@@ -1869,7 +1920,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 +1931,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 +1967,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 +1978,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 +2000,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 +2023,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 +2033,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 +2067,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 +2077,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;
@@ -2081,7 +2138,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,28 +2148,44 @@
+ "\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)
if (_dS2cspd < 1.0) {
@@ -2141,7 +2214,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 +2232,7 @@


// correctly
_sErrMsg = _resBundDisplayMsgs

.getString("protocolError")
- +
Integer.parseInt(new String(msg.getBody()),
+ +
parseMsgBodyToInt(new String(msg.getBody()),
16) +
" instead\n";
return true;
}
@@ -2176,14 +2249,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 +2288,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 +2311,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 +2321,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 +2334,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 +2347,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 +2360,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,
+ paramProtoObj.send_json_msg(MessageType.TEST_MSG,
(NDTConstants.META_CLIENT_VERSION + ":" + NDTConstants.VERSION).getBytes());
- paramProtoObj.send_msg(MessageType.TEST_MSG,
+ 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 +2388,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 +2398,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 +2424,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 +2514,11 @@

// write our test suite request by sending a login message
// _yTests indicates the requested test-suite
-
- protocolObj.send_msg(MessageType.MSG_LOGIN, _yTests);
+ byte [] send = new byte[NDTConstants.VERSION.length()+1];
+ send[0] = _yTests;
+ System.arraycopy(NDTConstants.VERSION.getBytes(), 0, send, 1, NDTConstants.VERSION.length());
+
+ 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 +2535,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 +2547,67 @@
// below.
// Any other type of message at this stage is
incorrect
if (msg.getType() != MessageType.SRV_QUEUE) {
- _sErrMsg =
_resBundDisplayMsgs.getString("loggingWrongMessage")
- + "\n";
- _bFailed = true;
- return;
+ if (!retry && !new String(msg.getBody()).equals("Invalid login message.")) {
+ jsonSupport = false;
+ retry = true;
+ try {
+
+ // RAC Debug message
+ _resultsTxtPane.append(_resBundDisplayMsgs
+ .getString("unsupportedMsgExtendedLogin")
+ + "\n");
+ // create socket to host specified by user and the default port
+ ctlSocket = new Socket(hostAddress, ctlport);
+ } catch (UnknownHostException e) {
+ System.err.println("Don't know about host: " + sHostName);
+ _sErrMsg = _resBundDisplayMsgs.getString("unknownServer") + "\n";
+ _bFailed = true;
+ return;
+ } catch (IOException e) {
+ System.err.println("Couldn't get the connection to: " + sHostName
+ + " " + ctlport);
+ _sErrMsg = _resBundDisplayMsgs.getString("serverNotRunning") + " ("
+ + sHostName + ":" + ctlport + ")\n";
+ _bFailed = true;
+ return;
+ }
+
+ protocolObj = new Protocol(ctlSocket);
+ protocolObj.setJsonSupport(false);
+ // The beginning of the protocol
+
+ // Determine, and indicate to client about Inet6/4 address being used
+ if (ctlSocket.getInetAddress() instanceof Inet6Address) {
+ _resultsTxtPane.append(_resBundDisplayMsgs.getString("connected")
+ + " " + sHostName
+ + _resBundDisplayMsgs.getString("usingIpv6") + "\n");
+ } else {
+ _resultsTxtPane.append(_resBundDisplayMsgs.getString("connected")
+ + " " + sHostName
+ + _resBundDisplayMsgs.getString("usingIpv4") + "\n");
+ }
+
+ protocolObj.send_msg(MessageType.MSG_LOGIN, _yTests);
+
+
+ if (protocolObj.readn(msg, 13) != 13) {
+ _sErrMsg = _resBundDisplayMsgs.getString("unsupportedClient")
+ + "\n";
+ _bFailed = true;
+ return;
+ }
+ continue;
+ } else {
+ _sErrMsg = _resBundDisplayMsgs.getString("loggingWrongMessage")
+ + "\n";
+ _bFailed = true;
+ return;
+ }
}

// Get wait flag value
String tmpstr3 = new String(msg.getBody());
- wait = Integer.parseInt(tmpstr3);
+ wait = parseMsgBodyToInt(tmpstr3);
System.out.println("wait flag received = " + wait);

if (wait == NDTConstants.SRV_QUEUE_TEST_STARTS_NOW) { // SRV_QUEUE message received indicating
@@ -2521,7 +2653,7 @@

// Client has to respond with a "MSG_WAITING"
to such heart-beat
// messages from server
- protocolObj.send_msg(MessageType.MSG_WAITING,
_yTests);
+
protocolObj.send_json_msg(MessageType.MSG_WAITING, _yTests);
continue;
}

@@ -2550,7 +2682,7 @@


// protocol


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

// Version compatibility between server-client must be
verified
- String vVersion = new String(msg.getBody());
+ String vVersion;
+ if (jsonSupport) {
+ vVersion = JSONUtils.getSingleMessage(new String(msg.getBody()));
+ } else {
+ vVersion = new String(msg.getBody());
+ }
+
if (!vVersion.startsWith("v")) {
_sErrMsg =
_resBundDisplayMsgs.getString("incompatibleVersion");
_bFailed = true;
@@ -2602,7 +2740,7 @@
// requested by the client earlier
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;
@@ -2618,8 +2756,13 @@
}

// get ids of tests to be run now
- StringTokenizer tokenizer = new StringTokenizer(new String(
- msg.getBody()), " ");
+ String tmpstr;
+ if (jsonSupport) {
+ tmpstr = JSONUtils.getSingleMessage(new String(msg.getBody()));
+ } else {
+ tmpstr = new String(msg.getBody());
+ }
+ StringTokenizer tokenizer = new StringTokenizer(tmpstr, " ");

// Run all tests requested, based on the ID. In each case, if
tests
// cannot be successfully run,
@@ -2627,7 +2770,7 @@
while (tokenizer.hasMoreTokens()) {
if (sPanel.wantToStop()) { // user has indicated
decision to stop

// tests from GUI
- protocolObj.send_msg(MessageType.MSG_ERROR,
+
protocolObj.send_json_msg(MessageType.MSG_ERROR,
"Manually stopped by the
user".getBytes());
protocolObj.close();
ctlSocket.close();
@@ -2692,7 +2835,7 @@

if (sPanel.wantToStop()) { // user has indicated decision to
stop tests
//
from GUI
- protocolObj.send_msg(MessageType.MSG_ERROR,
+ protocolObj.send_json_msg(MessageType.MSG_ERROR,
"Manually stopped by the
user".getBytes());
protocolObj.close();
ctlSocket.close();
@@ -2709,7 +2852,7 @@
for (;;) {
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;
@@ -2727,7 +2870,11 @@
_bFailed = true;
return;
}
- _sTestResults += new String(msg.getBody());
+ if (jsonSupport) {
+ _sTestResults += JSONUtils.getSingleMessage(new String(msg.getBody()));
+ } else {
+ _sTestResults += new String(msg.getBody());
+ }
i++;
}
} catch (IOException e) {
@@ -3668,33 +3815,47 @@
*/

public void middleboxResults(String sMidBoxTestResParam) {
- StringTokenizer tokens;
- int k;
+ String sServerIp;
+ String sClientIp;
+ int iMss;
+ // changing order for issue 61
+ int iWinsSent;
+ int iWinsRecv; // unused, but retaining
+ String sClientSideServerIp;
+ String sClientSideClientIp;

- tokens = new StringTokenizer(sMidBoxTestResParam, ";");
- String sServerIp = tokens.nextToken();
- String sClientIp = tokens.nextToken();
-
- // Fix for JS API not reporting NAT'd IPs correctly
- // Assign client and server IP addresses for JA API
- // based on public, not local IP.
- pub_clientIP = sClientIp;
-
- int iMss = Integer.parseInt(tokens.nextToken());
- // changing order for issue 61
- int iWinsSent = Integer.parseInt(tokens.nextToken());
- int iWinsRecv = Integer.parseInt(tokens.nextToken()); // unused, but retaining
-
- // Get Client reported server IP
- String sClientSideServerIp = tokens.nextToken();
- k = sClientSideServerIp.indexOf("/");
- sClientSideServerIp = sClientSideServerIp.substring(k + 1);
-
- // get client side IP
- String sClientSideClientIp = tokens.nextToken();
- k = sClientSideClientIp.indexOf("/");
- sClientSideClientIp = sClientSideClientIp.substring(k + 1);
-
+ if (jsonSupport) {
+ sServerIp = JSONUtils.getValueFromJsonObj(sMidBoxTestResParam, "ServerAddress");
+ sClientIp = JSONUtils.getValueFromJsonObj(sMidBoxTestResParam, "ClientAddress");
+ iMss = Integer.parseInt(JSONUtils.getValueFromJsonObj(sMidBoxTestResParam, "CurMSS"));
+ iWinsSent = Integer.parseInt(JSONUtils.getValueFromJsonObj(sMidBoxTestResParam, "WinScaleSent"));
+ iWinsRecv = Integer.parseInt(JSONUtils.getValueFromJsonObj(sMidBoxTestResParam, "WinScaleRcvd"));
+ sClientSideServerIp = JSONUtils.getValueFromJsonObj(sMidBoxTestResParam, "ClientSideServerIp");
+ sClientSideClientIp = JSONUtils.getValueFromJsonObj(sMidBoxTestResParam, "ClientSideClientIp");
+ } else {
+ StringTokenizer tokens;
+ int k;
+
+ tokens = new StringTokenizer(sMidBoxTestResParam, ";");
+ sServerIp = tokens.nextToken();
+ sClientIp = tokens.nextToken();
+
+ iMss = Integer.parseInt(tokens.nextToken());
+ // changing order for issue 61
+ iWinsSent = Integer.parseInt(tokens.nextToken());
+ iWinsRecv = Integer.parseInt(tokens.nextToken()); // unused, but retaining
+
+ // Get Client reported server IP
+ sClientSideServerIp = tokens.nextToken();
+ k = sClientSideServerIp.indexOf("/");
+ sClientSideServerIp = sClientSideServerIp.substring(k + 1);
+
+ // get client side IP
+ sClientSideClientIp = tokens.nextToken();
+ k = sClientSideClientIp.indexOf("/");
+ sClientSideClientIp = sClientSideClientIp.substring(k + 1);
+ }
+
// MSS = 1456 = Ethernet MTU = 1500 - 24 -20 (bytes of IP
header) =
// 1456, thus preserved
if(_iTimestampsEnabled == NDTConstants.RFC_1323_ENABLED)
@@ -4214,5 +4375,27 @@
else
return null;
}
+
+ /**
+ * Function that parse String to Integer
+ * @param {String} Value to parse.
+ * @return {int} The parsed value.
+ */
+ private int parseMsgBodyToInt(String msg) {
+ return parseMsgBodyToInt(msg, 10);
+ }
+
+ /**
+ * Function that parse String to Integer
+ * @param {String} Value to parse.
+ * @return {int} The parsed value.
+ */
+ private int parseMsgBodyToInt(String msg, int radix) {
+ if (jsonSupport) {
+ return Integer.parseInt(JSONUtils.getSingleMessage(msg), radix);
+ } else {
+ return Integer.parseInt(msg, radix);
+ }
+ }

} // class: Tcpbw100
=======================================
--- /branches/Issue146/Applet/src/edu/internet2/ndt/locale/Tcpbw100_msgs_en_US.properties Tue Mar 4 08:44:05 2014 UTC
+++ /branches/Issue146/Applet/src/edu/internet2/ndt/locale/Tcpbw100_msgs_en_US.properties Wed May 21 09:09:42 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/Issue146/src/test_s2c_clt.c Tue May 13 13:52:22 2014 UTC
+++ /branches/Issue146/src/test_s2c_clt.c Wed May 21 09:09:42 2014 UTC
@@ -284,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/Issue146/src/test_s2c_srv.c Tue May 13 13:52:22 2014 UTC
+++ /branches/Issue146/src/test_s2c_srv.c Wed May 21 09:09:42 2014 UTC
@@ -600,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

=======================================
--- /branches/Issue146/src/testoptions.c Wed May 14 06:39:08 2014 UTC
+++ /branches/Issue146/src/testoptions.c Wed May 21 09:09:42 2014 UTC
@@ -260,6 +260,10 @@
}
} else if (msgType == MSG_EXTENDED_LOGIN) { /* Case 2 */
options->json_support = 1;
+ jsonMsgValue = json_read_map_value(msgValue, DEFAULT_KEY);
+ strlcpy(msgValue, jsonMsgValue, sizeof(msgValue));
+ msgLen = strlen(jsonMsgValue);
+ free(jsonMsgValue);
if (msgLen >= 1 && msgLen <= (CS_VERSION_LENGTH_MAX + 1)) {
memcpy(options->client_version, msgValue + 1, msgLen - 1);
log_println(0, "Client version: %s-\n", options->client_version);
=======================================
--- /branches/Issue146/src/web100-util.c Tue May 13 13:52:22 2014 UTC
+++ /branches/Issue146/src/web100-util.c Wed May 21 09:09:42 2014 UTC
@@ -16,6 +16,7 @@
#include "strlutils.h"
#include "utils.h"
#include "web100srv.h"
+#include "jsonutils.h"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

log_println(6, "S2C test - Send web100 data to client pid=%d", getpid());
return 0;
=======================================
--- /branches/Issue146/src/web100clt.c Wed May 14 06:39:08 2014 UTC
+++ /branches/Issue146/src/web100clt.c Wed May 21 09:09:42 2014 UTC
@@ -536,7 +536,7 @@
char *invalid_login_msg = "Invalid login message.";
// addresses..
I2Addr server_addr = NULL;
- char* ptr;
+ char* ptr, *jsonMsgValue;
#ifdef AF_INET6
#define GETOPT_LONG_INET6(x) "46"x
#else
@@ -683,7 +683,7 @@
buff[0] = tests;
strlcpy(buff + 1, VERSION, sizeof(buff) - 1);
/* write our test suite request by sending a login message */
- send_msg(ctlSocket, MSG_EXTENDED_LOGIN, buff, strlen(buff));
+ send_json_message(ctlSocket, MSG_EXTENDED_LOGIN, buff, strlen(buff), jsonSupport, JSON_SINGLE_VALUE);
/* read the specially crafted data that kicks off the old clients */
if (readn(ctlSocket, buff, 13) != 13) {
printf("Information: The server '%s' does not support this command line "
@@ -707,7 +707,7 @@
msgLen)) {
// Any other type of message at this stage is incorrect
// If received invalid login message error then try to connect using basic MSG_LOGIN msg
- if (!retry && strcmp(buff, invalid_login_msg) == 0) {
+ if (!retry) {
printf("Information: The server '%s' does not support MSG_EXTENDED_LOGIN message. "
"Trying to connect using MSG_LOGIN\n", host);
retry = 1; // to prevent infinite retrying to connect
@@ -744,11 +744,17 @@

exit(2);
}
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) {
log_println(0, "Improper message");
exit(3);
}
- buff[msgLen] = 0;
if (check_int(buff, &xwait)) {
log_println(0, "Invalid queue indicator");
exit(4);
@@ -784,7 +790,7 @@
}
// Signal from the server to see if the client is still alive
if (xwait == SRV_QUEUE_HEARTBEAT) {
- send_msg(ctlSocket, MSG_WAITING, &tests, 1);
+ send_json_message(ctlSocket, MSG_WAITING, &tests, 1, jsonSupport, JSON_SINGLE_VALUE);
continue;
}

@@ -820,6 +826,13 @@
msgLen)) {
exit(2);
}
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) {
log_println(0, "Improper message");
exit(3);
@@ -827,7 +840,6 @@

// Version compatibility between server-client must be verified

- buff[msgLen] = 0;
if (buff[0] != 'v') { // payload doesn't start with a version indicator
log_println(0, "Incompatible version number");
exit(4);
@@ -862,13 +874,19 @@
msgLen)) {
exit(2);
}
+ buff[msgLen] = 0;
+ if (jsonSupport) {
+ jsonMsgValue = json_read_map_value(buff, DEFAULT_KEY);
+ strlcpy(buff, jsonMsgValue, sizeof(buff));
+ msgLen = strlen(buff);
+ free(jsonMsgValue);
+ }
if (msgLen <= 0) {
log_println(0, "Improper message");
exit(3);
}

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

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

=======================================
--- /branches/Issue146/src/web100srv.c Tue Apr 15 22:51:33 2014 UTC
+++ /branches/Issue146/src/web100srv.c Wed May 21 09:09:42 2014 UTC
@@ -86,6 +86,7 @@
#include "strlutils.h"
#include "heuristics.h"
#include "tests_srv.h"
+#include "jsonutils.h"

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

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

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

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

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

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

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

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

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

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

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

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

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

snprintf(tmpstr, sizeof(tmpstr), "%d", (waiting-j));
- send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr,
- strlen(tmpstr));
+ send_json_message(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr,
+ strlen(tmpstr), testopt.json_support, JSON_SINGLE_VALUE);
tmp_ptr = tmp_ptr->next;
j--;
}
@@ -2522,7 +2534,8 @@
log_println(5, "sending 'GO' signal to client msg='%s'",
tmpstr);
// test session starts now
- send_msg(mchild->ctlsockfd, SRV_QUEUE, "0", 1);
+ send_json_message(mchild->ctlsockfd, SRV_QUEUE, "0", 1,
+ testopt.json_support, JSON_SINGLE_VALUE);
for (i = 0; i < 5; i++) {
retcode = write(mchild->pipe, tmpstr, strlen(tmpstr));
log_println(6, "write(%d) returned %d, errno=%d",
@@ -2553,7 +2566,8 @@
head_ptr->tests);
log_println(5, "sending 'GO' signal to client msg='%s'",
tmpstr);
- send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "0", 1);
+ send_json_message(head_ptr->ctlsockfd, SRV_QUEUE, "0", 1,
+ testopt.json_support, JSON_SINGLE_VALUE);
for (i = 0; i < 5; i++) {
retcode = write(head_ptr->pipe, tmpstr, strlen(tmpstr));
if ((retcode == -1) && (errno == EINTR))
=======================================
--- /branches/Issue146/src/web100srv.h Tue May 13 13:52:22 2014 UTC
+++ /branches/Issue146/src/web100srv.h Wed May 21 09:09:42 2014 UTC
@@ -316,7 +316,7 @@
void tcp_stat_get_data_recv(int sock, tcp_stat_agent* agent,
tcp_stat_connection cn, int count_vars);
int tcp_stat_get_data(tcp_stat_snap* snap, int testsock, int ctlsock,
- tcp_stat_agent* agent, int count_vars);
+ tcp_stat_agent* agent, int count_vars, int jsonSupport);

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


  • [ndt-dev] [ndt] r1057 committed - Add JSON support to java client, ndt, 05/21/2014

Archive powered by MHonArc 2.6.16.

Top of Page