Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r736 committed - S->C CLT side code inline comments and code factoring

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r736 committed - S->C CLT side code inline comments and code factoring


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r736 committed - S->C CLT side code inline comments and code factoring
  • Date: Mon, 24 Oct 2011 20:08:42 +0000

Revision: 736
Author:

Date: Mon Oct 24 13:08:20 2011
Log: S->C CLT side code inline comments and code factoring
http://code.google.com/p/ndt/source/detail?r=736

Modified:
/branches/kkumar_code_organize/src/test_s2c_clt.c

=======================================
--- /branches/kkumar_code_organize/src/test_s2c_clt.c Mon Oct 17 06:43:25 2011
+++ /branches/kkumar_code_organize/src/test_s2c_clt.c Mon Oct 24 13:08:20 2011
@@ -1,4 +1,4 @@
-/*
+/**
* This file contains the functions needed to handle S2C throughput
* test (client part).
*
@@ -19,12 +19,32 @@
int ssndqueue, sbytes;
double spdin, s2cspd;

+/**
+ * S2C throughput test to measure network bandwidth
+ * from server to client.
+ * @param ctlSocket Socket on which messages are received from the server
+ * @param tests Character indicator for test to be run
+ * @param host Server name string
+ * @param conn_options Options to use while connecting to server(for ex, IPV4)
+ * @param buf_size TCP send/receive buffer size
+ * @param result_srv result obtained from server (containing values of web100 variables)
+ * @return integer > 0 if successful, < 0 in case of error
+ * Return codes:
+ * 1: Error receiving protocol message
+ * 2: Unexpected protocol message (type) received
+ * 3: Improper message payload
+ * 4: Incorrect message data received
+ * -3: Unable to resolve server address
+ * -15: Cannot connect to server
+ */
+
int test_s2c_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size, char* tmpstr) {
- char buff[BUFFSIZE + 1];int msgLen, msgType;
- int s2cport = 3003;
+ int buf_size, char* result_srv) {
+ char buff[BUFFSIZE + 1];
+ int msgLen, msgType;
+ int s2cport = PORT3;
I2Addr sec_addr = NULL;
- int inlth, ret, one=1, set_size;
+ int inlth, retcode, one=1, set_size;
int inSocket;
socklen_t optlen;
uint32_t bytes;
@@ -34,15 +54,19 @@
char* ptr;

if (tests & TEST_S2C) {
+ // First message expected from the server is a TEST_PREPARE. Any other message
+ // ...type is unexpected at this point.
log_println(1, " <-- S2C throughput test -->");
msgLen = sizeof(buff);
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed prepare
message!");
return 1;
}
- if (check_msg_type("S2C throughput test", TEST_PREPARE, msgType, buff, msgLen)) {
+ if (check_msg_type(S2C_TEST_LOG, TEST_PREPARE, msgType, buff,
msgLen)) {
return 2;
}
+ // This TEST_PREPARE message is expected to have the port number as message body.
+ // Check if this is a valid integral port.
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
@@ -61,13 +85,15 @@
optlen = sizeof(set_size);
getsockopt(ctlSocket, SOL_SOCKET, SO_SNDBUF, &set_size,
&optlen);

+ // get "address details" of the server using the host name
if ((sec_addr = I2AddrByNode(get_errhandle(), host)) == NULL)
{
log_println(0, "Unable to resolve server address:
%s", strerror(errno));
return -3;
}
- I2AddrSetPort(sec_addr, s2cport);
-
- if ((ret = CreateConnectSocket(&inSocket, NULL, sec_addr, conn_options, buf_size))) {
+ I2AddrSetPort(sec_addr, s2cport); //set port to value obtained from server
+
+ // Connect to the server; set socket options
+ if ((retcode = CreateConnectSocket(&inSocket, NULL, sec_addr, conn_options, buf_size))) {
log_println(0, "Connect() for Server to Client failed", strerror(errno));
return -15;
}
@@ -84,31 +110,38 @@
* queued up on the server.
*/

+ // Expect a TEST_START message from server now. Any other
message
+ // type is an error
msgLen = sizeof(buff);
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed start
message!");
return 1;
}
- if (check_msg_type("S2C throughput test", TEST_START, msgType, buff, msgLen)) {
+ if (check_msg_type(S2C_TEST_LOG, TEST_START, msgType, buff,
msgLen)) {
return 2;
}
+
+ // server performs the S->C throughput test now. Get data
sent by server.

printf("running 10s inbound test (server to client) . . . . . .
");
fflush(stdout);

+ // Set socket timeout to 15 seconds
bytes = 0;
t = secs() + 15.0;
sel_tv.tv_sec = 15;
sel_tv.tv_usec = 5;
FD_ZERO(&rfd);
FD_SET(inSocket, &rfd);
+ // Read data sent by server as soon as it is available. Stop
listening if
+ // ...timeout has been exceeded.
for (;;) {
- ret = select(inSocket+1, &rfd, NULL, NULL, &sel_tv);
+ retcode = select(inSocket+1, &rfd, NULL, NULL,
&sel_tv);
if (secs() > t) {
log_println(5, "Receive test running long, break
out of read loop");
break;
}
- if (ret > 0) {
+ if (retcode > 0) {
inlth = read(inSocket, buff, sizeof(buff));
if (inlth == 0)
break;
@@ -120,18 +153,22 @@
}
break;
}
+
+ // get actual time for which data was received, and calculate throughput based on it.
t = secs() - t + 15.0;
- spdin = ((8.0 * bytes) / 1000) / t;
-
- /* receive the s2cspd from the server */
+ spdin = ((BITS_8 * bytes) / KILO) / t; //kbps
+
+ // Server sends calculated throughput value, unsent data amount in the socket queue
+ // and overall number of sent bytes in a TEST_MSG
msgLen = sizeof(buff);
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed text
message!");
return 1;
}
- if (check_msg_type("S2C throughput test", TEST_MSG, msgType, buff, msgLen)) {
- return 2;
- }
+ if (check_msg_type(S2C_TEST_LOG, TEST_MSG, msgType, buff,
msgLen)) {
+ return 2; // no other message type expected
+ }
+ // Is message of valid length, and does it have all the data
expected?
if (msgLen <= 0) {
log_println(0, "Improper message");
return 3;
@@ -142,20 +179,21 @@
log_println(0, "S2C: Improper message");
return 4;
}
- s2cspd = atoi(ptr);
+ s2cspd = atoi(ptr); // get S->C throughput first
ptr = strtok(NULL, " ");
if (ptr == NULL) {
log_println(0, "S2C: Improper message");
return 4;
}
- ssndqueue = atoi(ptr);
+ ssndqueue = atoi(ptr); // get amount of unsent data in queue
ptr = strtok(NULL, " ");
if (ptr == NULL) {
log_println(0, "S2C: Improper message");
return 4;
}
- sbytes = atoi(ptr);
-
+ sbytes = atoi(ptr); // finally get total-sent-byte-count
+log_println(0,"S->C received throughput: %f",s2cspd);
+ // log results in a convenient units format
if (spdin < 1000)
printf("%0.2f kb/s\n", spdin);
else
@@ -163,27 +201,36 @@

I2AddrFree(sec_addr);

+ // send TEST_MSG to server with the client-calculated
throughput
sprintf(buff, "%0.0f", spdin);
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));

- /* get web100 variables from server */
- tmpstr[0] = '\0';
+ // client now expected to receive web100 variables collected
by server
+
+ result_srv[0] = '\0';
for (;;) {
msgLen = sizeof(buff);
+ memset(buff,0,msgLen); // reset buff and msgLen
+
+ // get web100 variables
if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error - missed
text/finalize message!");
return 1;
}
+
+ // TEST_FINALIZE msg from server indicates end of web100 var transmission
if (msgType == TEST_FINALIZE) {
break;
}
- if (check_msg_type("S2C throughput test", TEST_MSG, msgType, buff, msgLen)) {
+
+ // if neither TEST_FINALIZE, nor TEST_MSG, signal
error!
+ if (check_msg_type(S2C_TEST_LOG, TEST_MSG, msgType,
buff, msgLen)) {
return 2;
}
- //strncat(tmpstr, buff, msgLen);
- strlcat(tmpstr, buff, 512);//todo hardcoded size of
array for now
- }
- log_println(6, "tmpstr = '%s'", tmpstr);
+
+ strlcat(result_srv, buff, 2 * BUFFSIZE); // hardcoded size of array from main tests
+ }
+ log_println(6, "result_srv = '%s', of len %d", result_srv,
msgLen);
log_println(1, " <------------------------->");
}



  • [ndt-dev] [ndt] r736 committed - S->C CLT side code inline comments and code factoring, ndt, 10/24/2011

Archive powered by MHonArc 2.6.16.

Top of Page