Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r506 committed - Code re-organization and inline documentation of NDT java client is co...

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r506 committed - Code re-organization and inline documentation of NDT java client is co...


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r506 committed - Code re-organization and inline documentation of NDT java client is co...
  • Date: Fri, 19 Aug 2011 18:46:49 +0000

Revision: 506
Author:

Date: Fri Aug 19 11:46:28 2011
Log: Code re-organization and inline documentation of NDT java client is complete. I look forward to comments/reviews/suggestions
http://code.google.com/p/ndt/source/detail?r=506

Added:
/branches/kkumar_code_organize/Applet/NewFrame.java
Modified:
/branches/kkumar_code_organize/Applet/Message.java
/branches/kkumar_code_organize/Applet/NDTConstants.java
/branches/kkumar_code_organize/Applet/OsfwWorker.java
/branches/kkumar_code_organize/Applet/Protocol.java
/branches/kkumar_code_organize/Applet/StatusPanel.java
/branches/kkumar_code_organize/Applet/Tcpbw100.java
/branches/kkumar_code_organize/Applet/UserAgentTools.java

=======================================
--- /dev/null
+++ /branches/kkumar_code_organize/Applet/NewFrame.java Fri Aug 19 11:46:28 2011
@@ -0,0 +1,30 @@
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.JFrame;
+
+
+/*
+ * Class that defines a new Frame with a window closing functionality
+ *
+ */
+class NewFrame extends JFrame {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8990839319520684317L;
+
+ /*Constructor
+ * @param none*/
+
+ public NewFrame() {
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent event) {
+ // System.err.println("Handling window closing
event");
+ dispose();
+ }
+ });
+ // System.err.println("Extended Frame class - RAC9/15/03");
+ }
+
+} // class: NewFrame
=======================================
--- /branches/kkumar_code_organize/Applet/Message.java Fri Aug 12 09:47:53 2011
+++ /branches/kkumar_code_organize/Applet/Message.java Fri Aug 19 11:46:28 2011
@@ -2,39 +2,61 @@
* Messages are composed of a "type" and a body
* Some examples of message types are : COMM_FAILURE, SRV_QUEUE, MSG_LOGIN, TEST_PREPARE etc
* @see MessageType.java for more examples
- * TODO: NDTP messages are defined to have a "length" field in wiki. Not defined here. Why?
- * Looks like all of the tests (MID, SFW, C2S, s2c, META are using this message type..so,
- * no specific "mesage type" which does not contain length exists
- * TODO: Is it a good idea to merge MessageTypes into this class?
+ * Messages are defined to have a "length" field too. Currently, 2 bytes of the the message
+ * "body" byte array are often used to store length (second/third array positions , for example)
+ *
+ * TODO: It may be worthwhile exploring whether MessageTypes could be merged into here instead of NDTConstants.
+ * . For a later release
*
*/
public class Message {

- //TODO: Make this private and test changes in Protocol class
+ //TODO: Could make these private and test changes in Protocol class. For later release
byte _yType;
byte[] _yaBody;
-
+
+ /* Getter method to get Message Type
+ * @param: none
+ * @return byte indicating Message Type
+ * */
public byte getType() {
return _yType;
}
-
+
+ /* Setter method to set Message Type
+ * @return: none
+ * @param byte indicating Message Type
+ * */
public void setType(byte bParamType) {
this._yType = bParamType;
}
-
+
+ /* Getter method to get Message body
+ * @return: byte array message body
+ * @param none
+ * */
public byte[] getBody() {
return _yaBody;
}
-
+
+ /* Setter method to get Message body
+ * @param iParamSize : byte array size
+ * @param byte array message body
+ * @return: none
+ * */
public void setBody(byte[] baParamBody, int iParamSize) {
_yaBody = new byte[iParamSize];
System.arraycopy(baParamBody, 0, _yaBody, 0, iParamSize);
}
-
+
+
+ /* Utility method to initialize Message body
+ * @param iParamSize : byte array size
+ * @return: none
+ * */
public void initBodySize(int iParamSize) {
- this._yaBody = new byte[iParamSize];
-
- }
-
-
-}
+ this._yaBody = new byte[iParamSize];
+ }
+
+
+}
=======================================
--- /branches/kkumar_code_organize/Applet/NDTConstants.java Wed Aug 17 19:59:44 2011
+++ /branches/kkumar_code_organize/Applet/NDTConstants.java Fri Aug 19 11:46:28 2011
@@ -8,95 +8,122 @@
*/

/**
- * @author kkumar
+ *
* Class to hold constants, mostly those that are "non-protocol" related
* The different sections of constants are enlisted under appropriate "sections"
* If necessary, these sections can be broken off later into different files for
* better readability
- * TODO: Revisit documentation. Currently also used to record change history
*
* Changed access specifier of constants to public from private. These are static message
* types and not data members, and having public access privilege will not affect
* encapsulation
*/
public class NDTConstants {
-
- //Section: System variables
- //used by the META tests
- public static final String META_CLIENT_OS = "client.os.name";
- 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";
-
- //TODO Check if version could be moved to some "configurable" or "property" area
- public static final String VERSION = "3.6.4";
-
- //Section: Test type
- //TODO: TestType class?
- public static final byte TEST_MID = (1 << 0);
- public static final byte TEST_C2S = (1 << 1);
- public static final byte TEST_S2C = (1 << 2);
- public static final byte TEST_SFW = (1 << 3);
- public static final byte TEST_STATUS = (1 << 4);
- public static final byte TEST_META = (1 << 5);
-
- //Section: Firewall test status
- public static final int SFW_NOTTESTED = 0;
- public static final int SFW_NOFIREWALL = 1;
- public static final int SFW_UNKNOWN = 2;
- public static final int SFW_POSSIBLE = 3;
-
- public static final double VIEW_DIFF = 0.1;
-
- //
- public static String TARGET1 = "U";
- public static String TARGET2 = "H";
-
- //NDT pre-fixed port ID
- public static final int CONTROL_PORT_DEFAULT = 3001;
-
- //SRV-QUEUE message status constants
- public static final int SRV_QUEUE_TEST_STARTS_NOW = 0;
- public static final int SRV_QUEUE_SERVER_FAULT = 9977;
- public static final int SRV_QUEUE_SERVER_BUSY = 9988;
- public static final int SRV_QUEUE_HEARTBEAT = 9990 ;
- public static final int SRV_QUEUE_SERVER_BUSY_60s = 9999;
-
- //Middlebox test related constants
- public static final int MIDDLEBOX_PREDEFINED_MSS = 8192;
-
- /*Method to initialise a few constants */
- private static ResourceBundle _rscBundleMessages;
- public static String TCPBW100_MSGS = "Tcpbw100_msgs";
-
-
- //system variables could be declared as strings too
- //half_duplex:, country , etc
-
- public static void initConstants(Locale paramLocale) {
- try {
- _rscBundleMessages = ResourceBundle.getBundle( TCPBW100_MSGS, paramLocale);
- System.out.println("Obtained messages ");
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Error while loading language files:\n" + e.getMessage());
- e.printStackTrace();
- }
-
- } //end method
-
- public static void initConstants(String lang, String country) {
- try {
- Locale locale = new Locale(lang, country);
- _rscBundleMessages = ResourceBundle.getBundle("Tcpbw100_msgs", locale);
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Error while loading language files:\n" + e.getMessage());
- e.printStackTrace();
- }
- }//end method initconstants
-
-
- public static String getMessageString(String paramStrName) {
- return _rscBundleMessages.getString(paramStrName);
- }
+
+ //Section: System variables
+ //used by the META tests
+ public static final String META_CLIENT_OS = "client.os.name";
+ 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";
+
+ //TODO Check if version could be moved to some "configurable" or "property" area
+ public static final String VERSION = "3.6.4";
+
+ //Section: Test type
+ //TODO: TestType class?
+ public static final byte TEST_MID = (1 << 0);
+ public static final byte TEST_C2S = (1 << 1);
+ public static final byte TEST_S2C = (1 << 2);
+ public static final byte TEST_SFW = (1 << 3);
+ public static final byte TEST_STATUS = (1 << 4);
+ public static final byte TEST_META = (1 << 5);
+
+ //Section: Firewall test status
+ public static final int SFW_NOTTESTED = 0;
+ public static final int SFW_NOFIREWALL = 1;
+ public static final int SFW_UNKNOWN = 2;
+ public static final int SFW_POSSIBLE = 3;
+
+ public static final double VIEW_DIFF = 0.1;
+
+ //
+ public static String TARGET1 = "U";
+ public static String TARGET2 = "H";
+
+ //NDT pre-fixed port ID
+ public static final int CONTROL_PORT_DEFAULT = 3001;
+
+ //SRV-QUEUE message status constants
+ public static final int SRV_QUEUE_TEST_STARTS_NOW = 0;
+ public static final int SRV_QUEUE_SERVER_FAULT = 9977;
+ public static final int SRV_QUEUE_SERVER_BUSY = 9988;
+ public static final int SRV_QUEUE_HEARTBEAT = 9990 ;
+ public static final int SRV_QUEUE_SERVER_BUSY_60s = 9999;
+
+ //Middlebox test related constants
+ public static final int MIDDLEBOX_PREDEFINED_MSS = 8192;//8k buffer
size
+ public static final int ETHERNET_MTU_SIZE = 1456;
+
+ //SFW test related constants
+ public static final String SFW_PREDEFINED_TEST_MESSAGE = "Simple firewall test";
+
+
+ private static ResourceBundle _rscBundleMessages;
+ public static String TCPBW100_MSGS = "Tcpbw100_msgs";
+ public static int PREDEFINED_BUFFER_SIZE = 8192; //8k buffer size
+
+ //Data rate indicator strings
+ public static String T1_STR = "T1";
+ public static String T3_STR = "T3";
+ public static String ETHERNET_STR = "Ethernet";
+ public static String FAST_ETHERNET = "FastE";
+ public static String OC_12_STR = "OC-12";
+ public static String GIGABIT_ETHERNET_STR = "GigE";
+ public static String OC_48_STR = "OC-48";
+ public static String TENGIGABIT_ETHERNET_STR = "10 Gig";
+ public static String SYSTEM_FAULT_STR = "systemFault";
+ public static String DIALUP_STR = "dialup2";
+ public static String RTT_STR = "systemFault"; //round trip time
+
+
+ //system variables could be declared as strings too
+ //half_duplex:, country , etc. F
+
+ /* Method to initialize a few constants
+ * @param Locale: local Locale object
+ * @return none */
+ public static void initConstants(Locale paramLocale) {
+ try {
+ _rscBundleMessages = ResourceBundle.getBundle( TCPBW100_MSGS, paramLocale);
+ System.out.println("Obtained messages ");
+ } catch (Exception e) {
+ JOptionPane.showMessageDialog(null, "Error while loading language files:\n" + e.getMessage());
+ e.printStackTrace();
+ }
+
+ } //end method
+
+ /* Overloaded Method to initialize a few constants
+ * @param lang: local Language String
+ * @param country: local country object
+ * @return none */
+ public static void initConstants(String lang, String country) {
+ try {
+ Locale locale = new Locale(lang, country);
+ _rscBundleMessages =
ResourceBundle.getBundle("Tcpbw100_msgs", locale);
+ } catch (Exception e) {
+ JOptionPane.showMessageDialog(null, "Error while loading language files:\n" + e.getMessage());
+ e.printStackTrace();
+ }
+ }//end method initconstants
+
+
+ /* Getter method for to fetch from resourceBundle
+ * @param: String name of parameter to be fetched
+ * @return: Value of parameter input*/
+ public static String getMessageString(String paramStrName) {
+ return _rscBundleMessages.getString(paramStrName);
+ }

}
=======================================
--- /branches/kkumar_code_organize/Applet/OsfwWorker.java Wed Aug 17 19:50:47 2011
+++ /branches/kkumar_code_organize/Applet/OsfwWorker.java Fri Aug 19 11:46:28 2011
@@ -1,3 +1,15 @@
+/*
+ * OsfwWorker creates a thread that listens for a message from the server
+ *
+ * As part of the simple firewall test, The Server MUST try to connect to the Client's
+ * ephemeral port and MUST send a TEST_MSG message containing a pre-defined string
+ * "Simple firewall test" of 20 chars using the newly created connection.
+ * This class implements this functionality
+ *
+ * The result of the test is set back into the Tcpbw100._iS2cSFWResult variable
+ * via its setter methods for the test results to be interpreted later
+ * */
+
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
@@ -17,6 +29,11 @@
this._iTestTime = iParamTestTime;
}

+ /*Constructor
+ * @param ServerSocket: Socket on which to accept connections
+ * @param int: Test time duration to wait for message from server
+ * @param Tcpbw100: Applet object used to set the result of the S->C firewall test
+ */
OsfwWorker(ServerSocket srvSocketParam, int iParamTestTime, Tcpbw100 _localParam)
{
this._srvSocket = srvSocketParam;
@@ -30,6 +47,7 @@
* */
public void finalize()
{
+ //If test is not already complete/terminated, then sleep
while (!_iFinalized) {
try {
Thread.currentThread().sleep(1000);
@@ -40,62 +58,84 @@
}
}

- public void run()
- {
+ /* Run method of this SFW Worker thread.
+ * This thread listens on the socket from the server for a given time period,
+ * and checks to see
+ * if the server has sent a message that is valid and sufficient to determine
+ * if the S->C direction has a fire-wall
+ * @return none*/
+ public void run() {
+
Message msg = new Message();
- Socket sock = null;
+ Socket socketObj = null;

try {
+ //set timeout to given value in ms
_srvSocket.setSoTimeout(_iTestTime * 1000);
try {
- sock = _srvSocket.accept();
+ //Blocking call trying to create connection
to socket and accept it
+ socketObj = _srvSocket.accept();
}
catch (Exception e) {
e.printStackTrace();
- //s2cResult = NDTConstants.SFW_POSSIBLE;
-
this._localTcpAppObj.setS2CTestResults(NDTConstants.SFW_POSSIBLE);
+ //The "accept" call has failed, and indicates
a firewall possibility
+
this._localTcpAppObj.setS2cSFWTestResults(NDTConstants.SFW_POSSIBLE);
_srvSocket.close();
_iFinalized = true;
return;
}
- Protocol sfwCtl = new Protocol(sock);
+ Protocol sfwCtl = new Protocol(socketObj);

//commented out sections indicate move to outer class
- if (sfwCtl.recv_msg(msg) != 0) {
+ if (sfwCtl.recv_msg(msg) != 0) {
+ /* error, msg read/received incorrectly.
Hence set status as unknown */
System.out.println("Simple firewall test:
unrecognized message");
//s2cResult = NDTConstants.SFW_UNKNOWN;
-
this._localTcpAppObj.setS2CTestResults(NDTConstants.SFW_UNKNOWN);
- sock.close();
+
this._localTcpAppObj.setS2cSFWTestResults(NDTConstants.SFW_UNKNOWN);
+ //close socket objects and wrap up
+ socketObj.close();
_srvSocket.close();
_iFinalized = true;
return;
}
+ /* The server sends a TEST_MSG type packet. Any other message-type is not expected
+ at this point, and hence an error */
if (msg.getType() != MessageType.TEST_MSG) {
//s2cResult = NDTConstants.SFW_UNKNOWN;
-
this._localTcpAppObj.setS2CTestResults(NDTConstants.SFW_UNKNOWN);
- sock.close();
+
this._localTcpAppObj.setS2cSFWTestResults(NDTConstants.SFW_UNKNOWN);
+ //close socket objects and wrap up
+ socketObj.close();
_srvSocket.close();
_iFinalized = true;
return;
}
- if (! new String(msg.getBody()).equals("Simple firewall
test")) {
+ /* The server protocol is expected to send a 20 char message that says "Simple firewall test" .
+ * Every other message string indicates an unknown
firewall status
+ */
+ if (! new String(msg.getBody()).equals(NDTConstants.SFW_PREDEFINED_TEST_MESSAGE)) {
System.out.println("Simple firewall test: Improper
message");
//s2cResult = NDTConstants.SFW_UNKNOWN;
-
this._localTcpAppObj.setS2CTestResults(NDTConstants.SFW_UNKNOWN);
- sock.close();
+
this._localTcpAppObj.setS2cSFWTestResults(NDTConstants.SFW_UNKNOWN);
+ //close socket objects and wrap up
+ socketObj.close();
_srvSocket.close();
_iFinalized = true;
return;
}
//s2cResult = NDTConstants.SFW_NOFIREWALL;
-
this._localTcpAppObj.setS2CTestResults(NDTConstants.SFW_NOFIREWALL);
+ /* If none of the above conditions were met, then,
the server message
+ has been received correctly, and there seems to be no
firewall */
+
this._localTcpAppObj.setS2cSFWTestResults(NDTConstants.SFW_NOFIREWALL);
}
catch (IOException ex) {
+ //Status of firewall could not be determined before
concluding
//s2cResult = NDTConstants.SFW_UNKNOWN;
-
this._localTcpAppObj.setS2CTestResults(NDTConstants.SFW_UNKNOWN);
- }
+
this._localTcpAppObj.setS2cSFWTestResults(NDTConstants.SFW_UNKNOWN);
+ }
+
+ //finalize an close open connections
try {
- sock.close();
+ socketObj.close();
_srvSocket.close();
}
catch (IOException e) {
@@ -104,3 +144,4 @@
_iFinalized = true;
}
}
+
=======================================
--- /branches/kkumar_code_organize/Applet/Protocol.java Wed Aug 17 19:50:47 2011
+++ /branches/kkumar_code_organize/Applet/Protocol.java Fri Aug 19 11:46:28 2011
@@ -3,26 +3,26 @@
import java.io.OutputStream;
import java.net.Socket;

-/* Class to define Protocol
- * TODO :summarize methods below to give a brief explanation of the Protocol class
- * TODO :use setter/getter methods for
+/* Class aggregating operations that can be performed for sending/receiving/reading
+ * Protocol messages
+ *
* */


public class Protocol {
- private InputStream _ctlin;
- private OutputStream _ctlout;
-
- /* Class Constructor
- * @param Socket: socket used to send the protocol messages over
- */
+ private InputStream _ctlInStream;
+ private OutputStream _ctlOutStream;
+
+ /* Class Constructor
+ * @param Socket: socket used to send the protocol messages over
+ */
public Protocol(Socket ctlSocketParam) throws IOException
{
- _ctlin = ctlSocketParam.getInputStream();
- _ctlout = ctlSocketParam.getOutputStream();
+ _ctlInStream = ctlSocketParam.getInputStream();
+ _ctlOutStream = ctlSocketParam.getOutputStream();
}

- /* Method to send msg. Overloaded
+ /* Method to send message. Overloaded
* @param bParamType: Ctrl Message Type
* @param bParamToSend: Data value to send
* @return none
@@ -34,7 +34,7 @@
send_msg(bParamType, tab);
}

-
+
/* Method to send msg. Overloaded
* @param bParamType: Ctrl Message Type
* @param bParamToSend[]: Data value to send
@@ -45,14 +45,14 @@
{
byte[] header = new byte[3];
header[0] = bParamType;
-
+
//2 bytes are used to hold data length. Thus, max(data
length) = 65535
header[1] = (byte) (baParamTab.length >> 8);
header[2] = (byte) baParamTab.length;

//Write data to outputStream
- _ctlout.write(header);
- _ctlout.write(baParamTab);
+ _ctlOutStream.write(header);
+ _ctlOutStream.write(baParamTab);
}

/* Populate Message byte array with specific number of bytes of data
@@ -69,7 +69,7 @@
msgParam.initBodySize(iParamAmount);
while (read != iParamAmount) {
//tmp = _ctlin.read(msg.body, read, amount - read);
- tmp = _ctlin.read(msgParam._yaBody, read,
iParamAmount - read);
+ tmp = _ctlInStream.read(msgParam._yaBody, read,
iParamAmount - read);
if (tmp <= 0) {
return read;
}
@@ -101,10 +101,10 @@
* msg.type = msg.body[0];
length = ((int) msg.body[1] & 0xFF) << 8;
length += (int) msg.body[2] & 0xFF;
- */
+ */
byte [] yaMsgBody = msgParam.getBody();
msgParam.setType(yaMsgBody[0]);
-
+
//Get data length
length = ((int) yaMsgBody[1] & 0xFF) << 8;
length += (int) yaMsgBody[2] & 0xFF;
@@ -115,14 +115,14 @@
return 0;
}

- /* Method to clsoe open Streams
+ /* Method to close open Streams
* @param none
* @return none*/
public void close()
{
try {
- _ctlin.close();
- _ctlout.close();
+ _ctlInStream.close();
+ _ctlOutStream.close();
}
catch (IOException e) {
e.printStackTrace();
=======================================
--- /branches/kkumar_code_organize/Applet/StatusPanel.java Fri Aug 12 09:47:53 2011
+++ /branches/kkumar_code_organize/Applet/StatusPanel.java Fri Aug 19 11:46:28 2011
@@ -7,10 +7,16 @@
import javax.swing.JProgressBar;

/* Class that displays status of tests being run Status
- * TODO: Can this be named better? */
+ * Also provides "utility" methods like displaying test number
+ * being currently run, and stopping tests
+ * */

public class StatusPanel extends JPanel
{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2609233901130079136L; //generated value
private int _iTestsCompleted; //variable used to record the count of "finished" tests
private int _iTestsNum;
private boolean _bStop = false;
@@ -75,19 +81,25 @@
_labelTestNum.setText(NDTConstants.getMessageString("test") + " " + _iTestsCompleted + " " + NDTConstants.getMessageString("of") + " " +_iTestsNum);
}

- /*record intention to stop tests */
+ /*record intention to stop tests
+ * @param none
+ * @return boolean: intention to stop or not*/
public boolean wantToStop() {
return _bStop;
}

- /*end the currently runnig test */
+ /*end the currently running test
+ * @param none
+ * @return none*/
public void endTest() {
_progressBarObj.setValue(_iTestsCompleted);
_iTestsCompleted++;
setTestNoLabelText();
}

- /* Set progress text */
+ /* Set progress text
+ * @param sParamText: String status
+ * @return none */
public void setText(String sParamText) {
if (!_progressBarObj.isIndeterminate()) {
_progressBarObj.setString(sParamText);
=======================================
--- /branches/kkumar_code_organize/Applet/Tcpbw100.java Wed Aug 17 19:50:47 2011
+++ /branches/kkumar_code_organize/Applet/Tcpbw100.java Fri Aug 19 11:46:28 2011
@@ -138,10 +138,10 @@

JTextArea _txtDiagnosis, _txtStatistics;
ResultsTextPane _resultsTxtPane;
- //String inresult, outresult;
+ //String inresult, outresult; //comment out unused variables
String _sErrMsg;
JButton _buttonStartTest;
- //TODO: Use just one button for dismiss and copy
+ //TODO: Could use just one button for dismiss and copy. For later
release
JButton _buttonDismiss, _buttonStatsDismiss;
JButton _buttonCopy, _buttonStatsCopy;
JButton _buttonDetails;
@@ -167,8 +167,8 @@
int _iSACKsRcvd, _iDupAcksIn, _iMaxRwinRcvd, _iMaxRwinSent;
int _iDataPktsOut, _iRcvbuf, _iSndbuf, _iAckPktsIn, _iDataBytesOut;
int _iPktsOut, _iCongestionSignals, _iRcvWinScale;
- //what length is 8192? TODO
- int _iPkts, _iLength=8192, _iCurrentRTO;
+ //int _iPkts, _iLength=8192, _iCurrentRTO;
+ int _iPkts, _iLength = NDTConstants.PREDEFINED_BUFFER_SIZE,
_iCurrentRTO;
int _iC2sData, _iC2sAck, _iS2cData, _iS2cAck;
// added for mailto url
protected URL _targetURL;
@@ -187,7 +187,7 @@
* from web applications using NDT as a back-end.
*/

- //These variables are accessed by the setter/getter methods. While they do not follow naming convention,
+ //These variables are accessed by the setter/getter methods. While they do not follow naming convention,
// are left this way
// pub_c2sspd is assigned the value of _dC2sspd (declared above). the pub_xxx version seems to be used
//for making public to javascript. No other details known
@@ -460,7 +460,10 @@
return Double.toString((8.0 * pub_bytes) / (System.currentTimeMillis() - pub_time));
}

- // "Remote Control" function - invoke NDT' runtest() method from the
API
+ /* "Remote Control" function - invoke NDT' runtest() method from the
API
+ * @param none
+ * @return none
+ */
public void run_test()
{
// The Java security model considers calling a method that
opens a socket
@@ -476,10 +479,19 @@
});
}

+ /*Getter method for UserAgent String
+ * @param none
+ * @return String UserAgent
+ * @see UserAgentTools.java */
public String getUserAgent() {
return _sUserAgent;
}

+ /*Setter method for UserAgent String
+ * @param String UserAgent
+ * @return none
+ * @see UserAgentTools.java
+ * */
public void setUserAgent(String userAgent) {
this._sUserAgent = userAgent;
}
@@ -501,24 +513,26 @@
//private static String country="NO";
/***/

+ //these variables are self-explanatory. Do not follow naming convention, but left that way
int half_duplex, congestion, bad_cable, mismatch;
double mylink;
double loss, estimate, avgrtt, spd, waitsec, timesec, rttsec;
double order, rwintime, sendtime, cwndtime, rwin, swin, cwin;
double aspd;
+ //end nameing convention-not-followed variables

boolean _bIsApplication = false;
boolean _bTestInProgress = false;
- String host = null;
+ String sHostName = null;
String _sTestResults, _sMidBoxTestResult;
byte _yTests = NDTConstants.TEST_MID | NDTConstants.TEST_C2S | NDTConstants.TEST_S2C |
NDTConstants.TEST_SFW | NDTConstants.TEST_STATUS | NDTConstants.TEST_META;
- int c2sResult = NDTConstants.SFW_NOTTESTED;
- int s2cResult = NDTConstants.SFW_NOTTESTED;
+ int _iC2sSFWResult = NDTConstants.SFW_NOTTESTED;
+ int _iS2cSFWResult = NDTConstants.SFW_NOTTESTED;


/* Method to initialize the base NDT window
- * The init() method
+ * Applet init() method
* @param none
* @return none
*/
@@ -541,74 +555,6 @@

//call method to create a window
createMainWindow();
-
- //TODO :Can we move this to SwiigUtilies? Plan for after documentation - it does'nt help
- //with understanding the functionality itself
-
- /*
- getContentPane().setLayout(new BorderLayout());
- showStatus(_resBundleMessages.getString("ready"));
- _bFailed = false ;
- _bRandomize = false;
- _bCanCopy = false;
- _resultsTxtPane = new ResultsTextPane();
- _resultsTxtPane.append("TCP/Web100 Network Diagnostic Tool v" + NDTConstants.VERSION + "\n");
- _resultsTxtPane.setEditable(false);
- getContentPane().add(new JScrollPane(_resultsTxtPane));
- _resultsTxtPane.append(_resBundleMessages.getString("clickStart") + "\n");
- Panel mPanel = new Panel();
- _buttonStartTest = new
JButton(_resBundleMessages.getString("start"));
- _buttonStartTest.addActionListener(this);
- mPanel.add(_buttonStartTest);
- _buttonStatistics = new JButton(_resBundleMessages.getString("statistics"));
- _buttonStatistics.addActionListener(this);
- if (getParameter("disableStatistics") == null) {
- mPanel.add(_buttonStatistics);
- }
- _buttonStatistics.setEnabled(false);
- _buttonDetails = new JButton(_resBundleMessages.getString("moreDetails"));
- _buttonDetails.addActionListener(this);
- if (getParameter("disableDetails") == null) {
- mPanel.add(_buttonDetails);
- }
- _buttonDetails.setEnabled(false);
- _buttonMailTo = new JButton(_resBundleMessages.getString("reportProblem"));
- _buttonMailTo.addActionListener(this);
- if (getParameter("disableMailto") == null) {
- mPanel.add(_buttonMailTo);
- }
- _buttonMailTo.setEnabled(false);
- options = new JButton(_resBundleMessages.getString("options") +
"...");
- options.addActionListener(new ActionListener() {
-
- public void actionPerformed(ActionEvent e) {
- options.setEnabled(false);
- showOptions();
- options.setEnabled(true);
- }
-
- });
- if (getParameter("disableOptions") == null) {
- mPanel.add(options);
- }
- getContentPane().add(BorderLayout.SOUTH, mPanel);
- _chkboxPreferIPv6 = new JCheckBox(_resBundleMessages.getString("_chkboxPreferIPv6"));
- _chkboxPreferIPv6.setSelected(true);
- _chkboxDefaultTest = new JCheckBox(_resBundleMessages.getString("_chkboxDefaultTests"));
- _chkboxDefaultTest.setSelected(true);
- _chkboxDefaultTest.setEnabled(false);
- SpinnerNumberModel model = new SpinnerNumberModel();
- model.setMinimum(new Integer(0));
- model.setValue(new Integer(1));
- _spinnerTestCount.setModel(model);
- _spinnerTestCount.setPreferredSize(new Dimension(60, 20));
- delay = new JComboBox();
- for (int i = 0; i < _saDelays.length; i++) {
-
delay.addItem(_resBundleMessages.getString(_saDelays[i]));
- }
- delay.setSelectedIndex(0);
- */
-

//Autorun functionality
_sIsAutoRun = getParameter("autoRun");
@@ -618,40 +564,44 @@
}

}
-
+
/* Method that initializes the "main" window
* The main window is composed of
* 1. The results pane, which describes the process and displays their results
* 2. The buttons pane, which houses all the buttons for various
options
* @param none
- * @return none */
+ * @return none
+ * //TODO :Can we move this to SwingUtilies? Plan for later release - it does'nt help
+ //with understanding the functionality itself
+ *
+ * */
private void createMainWindow () {
//set content manager
getContentPane().setLayout(new BorderLayout());
-
+
//start with status set to "Ready" to perform tests
showStatus(_resBundleMessages.getString("ready"));
-
+
//initialize
_bFailed = false ;
_bRandomize = false; //what is this used for? Seems unused in
code
_bCanCopy = false;
-
+
//Results panel
_resultsTxtPane = new ResultsTextPane();
_resultsTxtPane.append("TCP/Web100 Network Diagnostic Tool v" + NDTConstants.VERSION + "\n");
_resultsTxtPane.setEditable(false);
getContentPane().add(new JScrollPane(_resultsTxtPane));
_resultsTxtPane.append(_resBundleMessages.getString("clickStart") + "\n");
-
+
//Panel too add all buttons
Panel buttonsPanel = new Panel();
-
+
//Add "start" button
_buttonStartTest = new
JButton(_resBundleMessages.getString("start"));
_buttonStartTest.addActionListener(this);
buttonsPanel.add(_buttonStartTest);
-
+
//Add "statistics" button
_buttonStatistics = new JButton(_resBundleMessages.getString("statistics"));
_buttonStatistics.addActionListener(this);
@@ -659,7 +609,7 @@
buttonsPanel.add(_buttonStatistics);
}
_buttonStatistics.setEnabled(false);
-
+
//Add "Details" button
_buttonDetails = new JButton(_resBundleMessages.getString("moreDetails"));
_buttonDetails.addActionListener(this);
@@ -667,7 +617,7 @@
buttonsPanel.add(_buttonDetails);
}
_buttonDetails.setEnabled(false);
-
+
//Add "Report problem" button
_buttonMailTo = new JButton(_resBundleMessages.getString("reportProblem"));
_buttonMailTo.addActionListener(this);
@@ -675,7 +625,7 @@
buttonsPanel.add(_buttonMailTo);
}
_buttonMailTo.setEnabled(false);
-
+
//Add "Options" button
_buttonOptions = new JButton(_resBundleMessages.getString("options") + "...");
_buttonOptions.addActionListener(new ActionListener() {
@@ -690,10 +640,10 @@
if (getParameter("disableOptions") == null) {
buttonsPanel.add(_buttonOptions);
}
-
+
//add buttons panel to the main window
getContentPane().add(BorderLayout.SOUTH, buttonsPanel);
-
+
//"Options" panel components
//1. Is IPv6 preferred?
_chkboxPreferIPv6 = new JCheckBox(_resBundleMessages.getString("preferIPv6"));
@@ -713,10 +663,9 @@

_cmboboxDelay.addItem(_resBundleMessages.getString(_saDelays[i]));
}
_cmboboxDelay.setSelectedIndex(0);
-
-
- }
-
+
+ }
+
/* Method that creates the "More details" window
* @param none
* @return none */
@@ -778,7 +727,7 @@
_frameDetailedStats.pack();
} // statistics()

-
+
/* Method that creates the "Options" window
* The options displayed to the user are:
* 1. Perform default tests?
@@ -812,7 +761,7 @@
/*
* If user has enabled multiple tests, then build the
panel, and add it
* to the parent( options ) panel
- */
+ */
if (getParameter("enableMultipleTests") != null) {
JPanel generalPanel = new JPanel();
generalPanel.setLayout(new
BoxLayout(generalPanel, BoxLayout.Y_AXIS));
@@ -831,7 +780,7 @@

//Add options to the parent frame
_frameOptions.getContentPane().add(optionsPanel);
-
+
//create and add panel containing buttons
Panel buttonsPanel = new Panel();
_frameOptions.getContentPane().add("South",
buttonsPanel);
@@ -858,18 +807,20 @@
/*Method to run the Thread that calls the "dottcp" method to run tests
* This method is called by the Applet's init method if user selected
an
* "autorun" option, is run individually if user presses the "start button",
- * and is internally run by API call */
+ * and is internally run by API call
+ * @param none
+ * @return none*/
synchronized public void runtest() {
pub_status = "notStarted";
new Thread(new TestWorker()).start();
}

- /*Class that starts the tests in a thread
+ /* Class that starts the tests in a thread
* Starts by disabling all buttons
* Calls the dottcp() method
* This thread is stopped when the number of tests that was configured to be
* run have all completed, or if the user stops it by interrupting from the GUI
- * Once the tests have been run, the buttons are enabled*/
+ * Once the tests have been run, the buttons are enabled */
class TestWorker implements Runnable {
public void run() {
if (!_bTestInProgress) {
@@ -888,11 +839,11 @@
//StatusPanel sPanel = new
StatusPanel(testsNum);
//re-arch. Replaced above by the line below
String sTempEnable =
getParameter("enableMultipleTests");
-
+
/*create status panel based on whether
multiple tests are enabled
If not, then the progress bar displays just the specifi test (middlebox, C2S, firewall etc)
If yes, then the progress bar also shows the progress on the number of tests
- */
+ */
StatusPanel sPanel = new
StatusPanel(testsNum, sTempEnable);
getContentPane().add(BorderLayout.NORTH,
sPanel);
getContentPane().validate();
@@ -922,7 +873,7 @@
sPanel.endTest();
//increment test count
testNo += 1;
-
+
/* This iteration of tests is now complete. Enable all buttons and output
so that user can view details
of results */

_buttonDetails.setEnabled(true);
@@ -931,7 +882,7 @@

_buttonOptions.setEnabled(true);
_txtStatistics.append("\n** " + _resBundleMessages.getString("test") + " " + testNo + " **\n");
_txtDiagnosis.append("\n** " + _resBundleMessages.getString("test") + " " + testNo + " **\n");
-
+
//Now, sleep for some time based on user's choice before running the next iteration of the test suite
try {
switch
(_cmboboxDelay.getSelectedIndex()) {
@@ -1000,11 +951,16 @@
}
}

+ /* Action handler method called when an associate action is performed
+ * @param Event : Event object that prompted the call
+ * @return nonw
+ * */
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
// System.err.println("Processing WINDOW event #"
+event.getID());
// System.err.println("Processing event " + source);

+ //Start the test
if (source == _buttonStartTest) {
if(_frameWeb100Vars != null) {
_frameWeb100Vars.toBack();
@@ -1021,24 +977,24 @@
pub_errmsg = "Test in progress.";
runtest();
}
-
+ //show details of tests
else if (source == _buttonDetails) {
_buttonDetails.setEnabled(false);
_frameWeb100Vars.setResizable(true);
_frameWeb100Vars.setVisible(true);
_buttonDetails.setEnabled(true);
}
-
+ //"More Details" Web100 variables window to be closed
else if (source == _buttonDismiss) {
_frameWeb100Vars.toBack();
_frameWeb100Vars.dispose();
}
-
+ //"statistics" window to be closed
else if (source == _buttonStatsDismiss) {
_frameDetailedStats.toBack();
_frameDetailedStats.dispose();
}
-
+ //"More details" copy button functionality
else if (source == _buttonCopy) {
try {
Clipboard clipbd =
getToolkit().getSystemClipboard();
@@ -1051,7 +1007,7 @@
_bCanCopy = false;
}
}
-
+ //"Statistics" copy button functionality
else if (source == _buttonStatsCopy) {
Clipboard clipbd = getToolkit().getSystemClipboard();
String sTemp = _txtStatistics.getText();
@@ -1059,18 +1015,18 @@
clipbd.setContents(ssTemp, ssTemp);
_txtStatistics.selectAll();
}
-
+ //Show "statistics" window
else if (source == _buttonStatistics) {
_buttonStatistics.setEnabled(false);
_frameDetailedStats.setResizable(true);
_frameDetailedStats.setVisible(true);
_buttonStatistics.setEnabled(true);
}
-
+ //mail to functionality
else if (source == _buttonMailTo) {
//int i; //did'nt need it
//char key; comment out. seems unused
- String to[], from[], comments[];
+ //String to[], from[], comments[]; //commented out
unused variables
String sName, sHost;

_buttonMailTo.setEnabled(false);
@@ -1079,16 +1035,17 @@

_resultsTxtPane.append(_resBundleMessages.getString("generatingReport") + "\n");
try {
- //TODO exception here occasionaly. Check out if my changes introduced these
+ //user
if ((sName =
getParameter(NDTConstants.TARGET1)) == null) {
throw new IllegalArgumentException("U
parameter Required:");
}
+ //host name
if ((sHost =
getParameter(NDTConstants.TARGET2)) == null) {
throw new IllegalArgumentException("H
parameter Required:");
}

String theURL = "; + sName + "@" +
sHost;
- String subject = getParameter("subject");
+ String subject = getParameter("subject");
//get subject

if (subject == null) {
subject = _resBundleMessages.getString("troubleReportFrom") + " " + getCodeBase().getHost();
@@ -1103,7 +1060,7 @@
}

getAppletContext().showDocument(_targetURL);
- }
+ } //end mail-to functionality
} // actionPerformed()

/* Method to display current status in Applet window
@@ -1114,21 +1071,28 @@
super.showStatus(msg);
}
}
-
-
+
+
/* MiddleBox testing method
- * @param Protocol Object
+ * This is a throughput test from the Server to the Client to check
for
+ * duplex mismatch condition
+ * @param Protocol Object usd to exchange messages
* @return boolean value indicating test failure status
- * true if test failed
- * false if test passed
- * @ */
-
+ * true if test was not completed
+ * false if test was completed
+ *
+ * @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 indicate more information about IOException
+ * */
+
public boolean test_mid(Protocol ctl) throws IOException {

//byte buff[] = new byte[8192];
//
byte buff[] = new byte[NDTConstants.MIDDLEBOX_PREDEFINED_MSS];
-
+
Message msg = new Message();
if ((_yTests & NDTConstants.TEST_MID) ==
NDTConstants.TEST_MID) {
/* now look for middleboxes (firewalls, NATs, and
other boxes that
@@ -1145,7 +1109,7 @@
_sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
return true;
}
-
+
//Initially, expecting a TEST_PREPARE message
if (msg.getType() != MessageType.TEST_PREPARE) {
_sErrMsg =
_resBundleMessages.getString("mboxWrongMessage") + "\n";
@@ -1160,13 +1124,13 @@
//connect to server using port obtained above
Socket midSrvrSockObj = null;
try {
- midSrvrSockObj = new Socket(host, midport);
+ midSrvrSockObj = new Socket(sHostName,
midport);
} catch (UnknownHostException e) {
- System.err.println("Don't know about host: "
+ host);
+ System.err.println("Don't know about host: "
+ sHostName);
_sErrMsg =
_resBundleMessages.getString("unknownServer") + "\n" ;
return true;
} catch (IOException e) {
- System.err.println("Couldn't perform middlebox
testing to: " + host);
+ System.err.println("Couldn't perform middlebox testing to: " + sHostName);
_sErrMsg =
_resBundleMessages.getString("middleboxFail") + "\n" ;
return true;
}
@@ -1185,7 +1149,7 @@

/*Read server packets into the pre-initialized buffer.
* Record number of packets read as reading completes
- */
+ */
try {
while ((inlth=srvin2.read(buff,0,buff.length))
> 0) {
bytes += inlth;
@@ -1195,7 +1159,8 @@
break;
}
}
- catch (IOException e) {} //TODO Question for a later fix. Why no exception handling code?
+ catch (IOException e) {}
+ //TODO Question for a later fix. Why no exception
handling code?

//Record test duration seconds
_dTime = System.currentTimeMillis() - _dTime;
@@ -1208,7 +1173,7 @@
_sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
return true;
}
-
+
//Results are sent from server in the form of a
TEST_MSG object
if (msg.getType() != MessageType.TEST_MSG) { //If not TEST_MSG, then test results not obtained
_sErrMsg =
_resBundleMessages.getString("mboxWrongMessage") + "\n";
@@ -1218,7 +1183,7 @@
}
return true;
}
-
+
//Get Test results
_sMidBoxTestResult = new String(msg.getBody());

@@ -1227,16 +1192,18 @@
System.out.println("Sending '" + tmpstr4 + "' back to
server");
ctl.send_msg(MessageType.TEST_MSG,
tmpstr4.getBytes());

- //append local address to the Test Results obtained
from server
+ /* 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 " + host);
+ System.err.println("Unable to obtain Servers IP addresses: using " + sHostName);
_sErrMsg = "getInetAddress() called failed\n"
;
- _sMidBoxTestResult += host + ";";
+ _sMidBoxTestResult += sHostName + ";";
_resultsTxtPane.append(_resBundleMessages.getString("lookupError") + "\n");
}

+ /* Append local address to the Test results obtained
from server*/
System.err.println("calling
in2Socket.getLocalAddress()");
try {
_sMidBoxTestResult += midSrvrSockObj.getLocalAddress()
+ ";";
@@ -1245,7 +1212,7 @@
_sErrMsg = "getLocalAddress() call failed\n" ;
_sMidBoxTestResult += "127.0.0.1;";
}
-
+
//wrap up test set up
srvin2.close();
srvout2.close();
@@ -1256,7 +1223,7 @@
_sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
return true;
}
-
+
if (msg.getType() != MessageType.TEST_FINALIZE) { //report unexpected message reception
_sErrMsg =
_resBundleMessages.getString("mboxWrongMessage");
if (msg.getType() == MessageType.MSG_ERROR) {
@@ -1264,7 +1231,7 @@
}
return true;
}
-
+
//Report status as "complete"
_resultsTxtPane.append(_resBundleMessages.getString("done") +
"\n");
_txtStatistics.append(_resBundleMessages.getString("done") +
"\n");
@@ -1273,14 +1240,18 @@
return false;
}

- /* Fireiwall tests aiming to find out if one exists between Client and server
+ /* Firewall tests aiming to find out if one exists between Client and server
* Tests performed in both directions
- * @param Protocol Object
+ * @param Protocol Object used for message exchange
* @return boolean
- * true if test failed
- * false if test passed */
- public boolean test_sfw(Protocol protocolObj) throws IOException
- {
+ * true if test was not completed
+ * false if test was completed
+ * @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 indicate more information about IOException
+ * */
+ public boolean test_sfw(Protocol protocolObj) throws IOException {
Message msg = new Message();
//start test
if ((_yTests & NDTConstants.TEST_SFW) ==
NDTConstants.TEST_SFW) {
@@ -1296,7 +1267,7 @@
_sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
return true;
}
-
+
//TEST_PREPARE is the first message expected from the
server
if (msg.getType() != MessageType.TEST_PREPARE) { //oops, unexpected message received
_sErrMsg =
_resBundleMessages.getString("sfwWrongMessage") + "\n";
@@ -1313,19 +1284,19 @@
* This message body contains ephemeral port # and testTime separated by a
* single space
*/
- int srvPort, testTime;
+ int iSrvPort, iTestTime;
try {
int k = sMsgBody.indexOf(" ");
- srvPort =
Integer.parseInt(sMsgBody.substring(0,k));
- testTime =
Integer.parseInt(sMsgBody.substring(k+1));
+ iSrvPort =
Integer.parseInt(sMsgBody.substring(0,k));
+ iTestTime =
Integer.parseInt(sMsgBody.substring(k+1));
}
catch (Exception e) {
_sErrMsg =
_resBundleMessages.getString("sfwWrongMessage") + "\n";
return true;
}

- System.out.println("SFW: port=" + srvPort);
- System.out.println("SFW: testTime=" + testTime);
+ System.out.println("SFW: port=" + iSrvPort);
+ System.out.println("SFW: testTime=" + iTestTime);

//Clients creates a server socket to send TEST_MSG
ServerSocket srvSocket;
@@ -1364,19 +1335,21 @@

//re-arch new code
//OsfwWorker osfwTest = new OsfwWorker(srvSocket,
testTime);
- OsfwWorker osfwTest = new OsfwWorker(srvSocket,
testTime, this);
+ //Listen for server sending out a test for the S->C direction , and update test results
+ OsfwWorker osfwTest = new OsfwWorker(srvSocket,
iTestTime, this);
new Thread(osfwTest).start();

- //Now, run test trying to connect to ephemeral port
+ //Now, run Test from client for the C->S direction
SFW test
+ //trying to connect to ephemeral port number sent by
server
Socket sfwSocket = new Socket();
try {
//create socket to ephemeral port. testTime
now specified in mS
- sfwSocket.connect(new InetSocketAddress(host, srvPort), testTime * 1000);
+ sfwSocket.connect(new InetSocketAddress(sHostName, iSrvPort), iTestTime * 1000);

Protocol sfwCtl = new Protocol(sfwSocket);
-
+
//send a simple string message over this
socket
- sfwCtl.send_msg(MessageType.TEST_MSG, new String("Simple firewall test").getBytes());
+ sfwCtl.send_msg(MessageType.TEST_MSG, new String(NDTConstants.SFW_PREDEFINED_TEST_MESSAGE).getBytes());
}
catch (Exception e) {
e.printStackTrace();
@@ -1387,7 +1360,7 @@
_sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
return true;
}
-
+
//Only TEST_MSG type expected at this point
if (msg.getType() != MessageType.TEST_MSG) {
_sErrMsg =
_resBundleMessages.getString("sfwWrongMessage") + "\n";
@@ -1396,10 +1369,9 @@
}
return true;
}
-
- //Todo: Could not determine where this is used yet
- //But this is an integer with value 0/1/2/3
indicating connection status
- c2sResult = Integer.parseInt(new
String(msg.getBody()));
+
+ //This is an integer with value 0/1/2/3 indicating status of a firewall's presence
+ _iC2sSFWResult = Integer.parseInt(new
String(msg.getBody()));

//Sleep for some time
osfwTest.finalize();
@@ -1409,7 +1381,7 @@
_sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
return true;
}
-
+
//ONLY TEST_FINALIZE type of message expected here
if (msg.getType() != MessageType.TEST_FINALIZE) {
_sErrMsg =
_resBundleMessages.getString("sfwWrongMessage") + "\n";
@@ -1418,22 +1390,36 @@
}
return true;
}
-
+
//Conclude by updatng status as "complete" on GUI
window
_resultsTxtPane.append(_resBundleMessages.getString("done") +
"\n");
_txtStatistics.append(_resBundleMessages.getString("done") +
"\n");
_sEmailText += _resBundleMessages.getString("done") +
"\n%0A";
}
-
- //successfully finished the SFW test, hence return
testfailure=false
+
+ //completed the SFW test, hence return false
return false;
}

- public boolean test_c2s(Protocol ctl) throws IOException
- {
+ /* Client to server throughput test
+ * Performs 10 seconds memory-to-memory data transfer to
+ * test achievable network bandwidth
+ * @param Protocol Object used to exchange messages
+ * @return boolean
+ * true if test was not completed
+ * false if test was completed
+ * @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 indicate more information about IOException
+ */
+ public boolean test_c2s(Protocol ctl) throws IOException {
+
// byte buff2[] = new byte[8192];
- byte buff2[] = new byte[64*1024];
+ //Initialise for 64 Kb
+ byte yabuff2Write[] = new byte[64*1024];
Message msg = new Message();
+ //start C2S throughput tests
if ((_yTests & NDTConstants.TEST_C2S) ==
NDTConstants.TEST_C2S) {

showStatus(_resBundleMessages.getString("outboundTest"));
_resultsTxtPane.append(_resBundleMessages.getString("runningOutboundTest") + " ");
@@ -1441,44 +1427,49 @@
_sEmailText += _resBundleMessages.getString("runningOutboundTest") + " ";
pub_status = "runningOutboundTest";

- if (ctl.recv_msg(msg) != 0) {
+ if (ctl.recv_msg(msg) != 0) { //msg receive/read error
_sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
return true;
}
- if (msg.getType() != MessageType.TEST_PREPARE) {
+ //Initial message expected from server is a
TEST_PREPARE
+ if (msg.getType() != MessageType.TEST_PREPARE) { //any other msg is error indicator
_sErrMsg =
_resBundleMessages.getString("outboundWrongMessage") + "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: " + Integer.parseInt(new String(msg.getBody()), 16) + "\n";
}
return true;
}
- int c2sport = Integer.parseInt(new
String(msg.getBody()));
-
+ //Server sends port number to bind to in the
TEST_PREPARE
+ int iC2sport = Integer.parseInt(new
String(msg.getBody()));
+
+ //client connects to this port
final Socket outSocket;
try {
- outSocket = new Socket(host, c2sport);
+ outSocket = new Socket(sHostName, iC2sport);
} catch (UnknownHostException e) {
- System.err.println("Don't know about host: "
+ host);
+ System.err.println("Don't know about host: "
+ sHostName);
_sErrMsg =
_resBundleMessages.getString("unknownServer") + "\n" ;
return true;
} catch (IOException e) {
- System.err.println("Couldn't get 2nd connection
to: " + host);
+ System.err.println("Couldn't get 2nd connection
to: " + sHostName);
_sErrMsg =
_resBundleMessages.getString("serverBusy15s") + "\n";
return true;
}

// Get server IP address from the outSocket.
- pub_host =
outSocket.getInetAddress().getHostAddress().toString();
-
-
- final OutputStream out = outSocket.getOutputStream();
+ pub_host =
outSocket.getInetAddress().getHostAddress().toString();
+
+ //Get output Stream from socket to write data into
+ final OutputStream outStream =
outSocket.getOutputStream();

// wait here for signal from server application
// This signal tells the client to start pumping out
data
- if (ctl.recv_msg(msg) != 0) {
- _sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
+ if (ctl.recv_msg(msg) != 0) { //error
reading/receiving message
+ _sErrMsg =
_resBundleMessages.getString("protocolError") +
+ Integer.parseInt(new
String(msg.getBody()), 16) + " instead\n";
return true;
}
+ //Expect a TEST_START message from server now. Any other message type is an error
if (msg.getType() != MessageType.TEST_START) {
_sErrMsg =
_resBundleMessages.getString("outboundWrongMessage") + "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
@@ -1487,17 +1478,21 @@
return true;
}

+ //Fill buffer upto NDTConstants.PREDEFNED_BUFFER_SIZE
packets
byte c = '0';
int i;
for (i=0; i<_iLength; i++) {
if (c == 'z')
c = '0';
- buff2[i] = c++;
+ yabuff2Write[i] = c++;
}
System.err.println("Send buffer size =" + i);
+
_iPkts = 0;
_dTime = System.currentTimeMillis();
pub_time = _dTime;
+
+ //sleep for 10 s
new Thread() {

public void run() {
@@ -1507,17 +1502,19 @@
System.out.println(e);
}
try {
- out.close();
+ outStream.close();
outSocket.close();
} catch (IOException e) {
System.out.println(e);
}
}
}.start();
+
+ //While the 10 s timer ticks, write buffer data into
server socket
while (true) {
// System.err.println("Send pkt = " + pkts + "; at " + System.currentTimeMillis());
try {
- out.write(buff2, 0, buff2.length);
+ outStream.write(yabuff2Write, 0,
yabuff2Write.length);
}
catch (SocketException e) {
System.out.println(e);
@@ -1529,31 +1526,39 @@
break;
}
_iPkts++;
+ //number of bytes sent = (num of iterations)
X (buffer size)
pub_bytes = (_iPkts * _iLength);
}

_dTime = System.currentTimeMillis() - _dTime;
- System.err.println(_dTime + "sec test completed");
+ System.err.println(_dTime + "sec test completed" +","+yabuff2Write.length); //actually ms, not s
if (_dTime == 0) {
_dTime = 1;
}
- System.out.println((8.0 * _iPkts * buff2.length) / _dTime + " kb/s outbound");
- _dC2sspd = ((8.0 * _iPkts * buff2.length) / 1000) /
_dTime;
- /* receive the c2sspd from the server */
- if (ctl.recv_msg(msg) != 0) {
+ System.out.println((8.0 * _iPkts * yabuff2Write.length) / _dTime + " kb/s outbound");
+
+ //Calculate C2S throughput
+ _dC2sspd = ((8.0 * _iPkts * yabuff2Write.length) /
1000) / _dTime;
+
+ /* The client has stopped straming data, and the
server is now expected
+ to send a TEST_MSG message with the throughout it
calculated
+ So, its time now to receive the c2sspd from the
server */
+ if (ctl.recv_msg(msg) != 0) { //error
reading/receiving data
_sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
return true;
}
- if (msg.getType() != MessageType.TEST_MSG) {
+ if (msg.getType() != MessageType.TEST_MSG) { //if not TEST_MSG, wrong , unexpected
_sErrMsg =
_resBundleMessages.getString("outboundWrongMessage");
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: " + Integer.parseInt(new String(msg.getBody()), 16) + "\n";
}
return true;
}
+ //Get throughput as calculated by server
String tmpstr3 = new String(msg.getBody());
_dSc2sspd = Double.parseDouble(tmpstr3) / 1000.0;

+ //Print results in the most convenient units (kbps or
Mbps)
if (_dSc2sspd < 1.0) {
_resultsTxtPane.append(prtdbl(_dSc2sspd*1000) +
"kb/s\n");
_txtStatistics.append(prtdbl(_dSc2sspd*1000) +
"kb/s\n");
@@ -1568,25 +1573,39 @@
// Expose upload speed to JavaScript clients
pub_c2sspd = _dSc2sspd;

- if (ctl.recv_msg(msg) != 0) {
+ //Server should close test session with a
TEST_FINALIZE message
+ if (ctl.recv_msg(msg) != 0) { //read/receive error
_sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
return true;
}
- if (msg.getType() != MessageType.TEST_FINALIZE) {
+ if (msg.getType() != MessageType.TEST_FINALIZE) { //all other types unexpected, erroneous
_sErrMsg =
_resBundleMessages.getString("outboundWrongMessage");
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: " + Integer.parseInt(new String(msg.getBody()), 16) + "\n";
}
- return true;
+ return true; //true indicates test incomplete
}
}
+ //false indicates test's completion
return false;
}

- public boolean test_s2c(Protocol ctl, Socket ctlSocket) throws
IOException
- {
- byte buff[] = new byte[8192];
+ /* S2C throughput test to measure network bandwidth from server to
client
+ * @param protoObj: Protocol Object used to exchange messages
+ * @param ctlSocket: Socket Object to write/read NDTProtocol control messages
+ * @return boolean
+ * true if test was not completed
+ * false if test was completed
+ * @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 indicate more information about IOException
+ * */
+ public boolean test_s2c(Protocol protoObj, Socket ctlSocket) throws IOException {
+ //byte buff[] = new byte[8192];
+ byte buff[] = new byte[NDTConstants.PREDEFINED_BUFFER_SIZE];
Message msg = new Message();
+ //start S2C tests
if ((_yTests & NDTConstants.TEST_S2C) ==
NDTConstants.TEST_S2C) {

showStatus(_resBundleMessages.getString("inboundTest"));
_resultsTxtPane.append(_resBundleMessages.getString("runningInboundTest") + " ");
@@ -1594,74 +1613,93 @@
_sEmailText +=
_resBundleMessages.getString("runningInboundTest") + " ";
pub_status = "runningInboundTest";

- if (ctl.recv_msg(msg) != 0) {
+ //Server sends TEST_PREPARE with port to bind to as
message body
+ if (protoObj.recv_msg(msg) != 0) { //read/receive
error
_sErrMsg = _resBundleMessages.getString("protocolError") + Integer.parseInt(new String(msg.getBody()), 16) + " instead\n";
return true;
}
- if (msg.getType() != MessageType.TEST_PREPARE) {
+ if (msg.getType() != MessageType.TEST_PREPARE) { //no other message type expected
_sErrMsg =
_resBundleMessages.getString("inboundWrongMessage") + "\n";
if (msg.getType() == MessageType.MSG_ERROR) {
_sErrMsg += "ERROR MSG: " + Integer.parseInt(new String(msg.getBody()), 16) + "\n";
}
return true;
}
- int s2cport = Integer.parseInt(new
String(msg.getBody()));
-
+ //get port to bind to for S2C tests
+ int iS2cport = Integer.parseInt(new
String(msg.getBody()));
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/Applet/UserAgentTools.java Wed Aug 17 19:50:47 2011
+++ /branches/kkumar_code_organize/Applet/UserAgentTools.java Fri Aug 19 11:46:28 2011
@@ -1,9 +1,16 @@
-/* This class has
-* code taken from http://nerds.palmdrive.net/useragent/code.html
-*
-* It has been move out and made into a non-static , outer class that can be replaced more quickly, if need be
-* TODO: this comment may be removed
-*/
+/* This class has code taken from
+ * http://nerds.palmdrive.net/useragent/code.html
+ *
+ * Class used to obtain information about who is accessing a web-server.
+ *
+ * When a web browser accesses a web-server, it usually transmits a "User-Agent" string.
+ * This is expected to include the name and versions of the browser and
+ * the underlying Operating System. Though the information inside a user-agent string is not restricted to
+ * these alone, currently, NDT uses this to get Browser OS only.
+ *
+ * It has been moved out and made into a non-static outer class that can be replaced more quickly, if need be
+ *
+ */
//private static class UserAgentTools {
public class UserAgentTools {



  • [ndt-dev] [ndt] r506 committed - Code re-organization and inline documentation of NDT java client is co..., ndt, 08/19/2011

Archive powered by MHonArc 2.6.16.

Top of Page