Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r723 committed - Formatting changes to all files in the src folder

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r723 committed - Formatting changes to all files in the src folder


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r723 committed - Formatting changes to all files in the src folder
  • Date: Mon, 17 Oct 2011 13:45:02 +0000

Revision: 723
Author:

Date: Mon Oct 17 06:43:25 2011
Log: Formatting changes to all files in the src folder
http://code.google.com/p/ndt/source/detail?r=723

Modified:
/branches/kkumar_code_organize/src/analyze.c
/branches/kkumar_code_organize/src/clt_tests.h
/branches/kkumar_code_organize/src/fakewww.c
/branches/kkumar_code_organize/src/genplot.c
/branches/kkumar_code_organize/src/heuristics.h
/branches/kkumar_code_organize/src/logging.c
/branches/kkumar_code_organize/src/logging.h
/branches/kkumar_code_organize/src/mrange.c
/branches/kkumar_code_organize/src/ndt_odbc.c
/branches/kkumar_code_organize/src/ndt_odbc.h
/branches/kkumar_code_organize/src/ndtptestconstants.c
/branches/kkumar_code_organize/src/ndtptestconstants.h
/branches/kkumar_code_organize/src/network.c
/branches/kkumar_code_organize/src/network.h
/branches/kkumar_code_organize/src/protocol.c
/branches/kkumar_code_organize/src/protocol.h
/branches/kkumar_code_organize/src/runningtest.c
/branches/kkumar_code_organize/src/runningtest.h
/branches/kkumar_code_organize/src/strlutils.c
/branches/kkumar_code_organize/src/strlutils.h
/branches/kkumar_code_organize/src/test_c2s_clt.c
/branches/kkumar_code_organize/src/test_meta_clt.c
/branches/kkumar_code_organize/src/test_meta_srv.c
/branches/kkumar_code_organize/src/test_mid_clt.c
/branches/kkumar_code_organize/src/test_s2c_clt.c
/branches/kkumar_code_organize/src/test_sfw_clt.c
/branches/kkumar_code_organize/src/test_sfw_srv.c
/branches/kkumar_code_organize/src/testoptions.c
/branches/kkumar_code_organize/src/testoptions.h
/branches/kkumar_code_organize/src/tr-mkmap.c
/branches/kkumar_code_organize/src/tr-tree.c
/branches/kkumar_code_organize/src/tr-tree.h
/branches/kkumar_code_organize/src/tr-tree6.c
/branches/kkumar_code_organize/src/troute.c
/branches/kkumar_code_organize/src/troute6.c
/branches/kkumar_code_organize/src/usage.c
/branches/kkumar_code_organize/src/utils.c
/branches/kkumar_code_organize/src/utils.h
/branches/kkumar_code_organize/src/varinfo.h
/branches/kkumar_code_organize/src/viewtrace.c
/branches/kkumar_code_organize/src/web100-admin.c
/branches/kkumar_code_organize/src/web100-admin.h
/branches/kkumar_code_organize/src/web100-pcap.c
/branches/kkumar_code_organize/src/web100-util.c
/branches/kkumar_code_organize/src/web100clt.c
/branches/kkumar_code_organize/src/web100srv.c
/branches/kkumar_code_organize/src/web100srv.h

=======================================
--- /branches/kkumar_code_organize/src/analyze.c Sun Oct 9 17:00:18
2011
+++ /branches/kkumar_code_organize/src/analyze.c Mon Oct 17 06:43:25
2011
@@ -39,16 +39,15 @@
#define WEB100_FILE "web100_variables" /*names of the variables to access*/
#define BUFFSIZE 512

-char buff[BUFFSIZE+1];
-int window = 64000;
-int randomize=0;
+char buff[BUFFSIZE + 1];int window = 64000;
+int randomize = 0;
char *rmt_host;
-char *VarFileName=NULL;
-char *LogFileName=NULL;
-char *ProtoLogFileName=NULL; // Log file used to log protocol validation logs
+char *VarFileName = NULL;
+char *LogFileName = NULL;
+char *ProtoLogFileName = NULL; // Log file used to log protocol validation logs
double avgrtt, loss, loss2, rttsec, bw, bw2, rwin, swin, cwin, speed;
double rwintime, cwndtime, sendtime, timesec;
-int n, m, one=1;
+int n, m, one = 1;
int Timeouts, SumRTT, CountRTT, MinRTT, PktsRetrans, FastRetran, DataPktsOut;
int AckPktsOut, CurrentMSS, DupAcksIn, AckPktsIn, MaxRwinRcvd, Sndbuf;
int CurrentCwnd, SndLimTimeRwin, SndLimTimeCwnd, SndLimTimeSender, DataBytesOut;
@@ -57,7 +56,8 @@
int CongestionOverCount, CongAvoid, SlowStart, MaxRTT, OtherReductions;
int CurTimeouts, AbruptTimeouts, SendStall, SubsequentTimeouts;
int autotune, ThruBytesAcked;
-int link=0, mismatch=0, bad_cable=0, half_duplex=0, congestion=0, totaltime;
+int link = 0, mismatch = 0, bad_cable = 0, half_duplex = 0, congestion = 0,
+ totaltime;
int i, spd, ret;
double order, idle, cpu_idle1, cpu_idle2;
char *name, ip_addr[64], ip_addr2[64];
@@ -72,823 +72,865 @@
int s2c2spd, c2sspd, s2cspd, iponly;
int linkcnt, mismatch2, mismatch3;

-static struct option long_options[] = {
- {"debug", 0, 0, 'd'},
- {"nodns", 0, 0, 'n'},
- {"help", 0, 0, 'h'},
- {"log", 1, 0, 'l'},
- {"version", 0, 0, 'v'},
- {0, 0, 0, 0}
-};
-
-int
-err_sys(char* s)
-{
- perror(s);
- exit(1);
+static struct option long_options[] = { { "debug", 0, 0, 'd' }, { "nodns", 0, 0,
+ 'n' }, { "help", 0, 0, 'h' }, { "log", 1, 0, 'l' }, {
"version", 0, 0,
+ 'v' }, { 0, 0, 0, 0 } };
+
+int err_sys(char* s) {
+ perror(s);
+ exit(1);
}

-void calculate()
-{
- int tail[4], i, head[4], tmpret;
- float k;
- float recvbwd, cwndbwd, sendbwd;
- char btlneck[64];
- int congestion2=0;
- I2Addr addr;
- double acks, aspeed, pureacks;
- float cong, retrn, increase, touts, fr_ratio = 0;
- float retransec;
-
- tail[0] = tail[1] = tail[2] = tail[3] = 0;
- head[0] = head[1] = head[2] = head[3] = 0;
- for (i=0; i<4; i++) {
- max = 0;
- indx = 0;
- total = 0;
- for (j=0; j<linkcnt-1; j++) {
- total += links[i][j];
- if (max < links[i][j]) {
- max = links[i][j];
- indx = j;
- }
- }
- for (j=indx+1; j<10; j++) {
- k = (float) links[i][j] / max;
- if (k > .1)
- tail[i]++;
- }
- for (j=0; j<indx; j++) {
- k = (float) links[i][j] / max;
- if (k > .1)
- head[i]++;
- }
- if (links[i][indx] == -1)
- indx = -1;
- if ((total < 20) && (indx != -1))
- indx = -2;
- switch (i) {
- case 0: c2sdata = indx;
- log_print(1, "Client --> Server data detects link = ");
- break;
- case 1: c2sack = indx;
- log_print(1, "Client <-- Server Ack's detect link = ");
- break;
- case 2: s2cdata = indx;
- log_print(1, "Server --> Client data detects link = ");
- break;
- case 3: s2cack = indx;
- log_print(1, "Server <-- Client Ack's detect link = ");
- }
- switch (indx) {
- case -2: log_println(1, "Insufficent Data"); break;
- case -1: log_println(1, "System Fault"); break;
- case 0: log_println(1, "RTT"); break;
- case 1: log_println(1, "Dial-up"); break;
- case 2: log_println(1, "T1"); break;
- case 3: log_println(1, "Ethernet"); break;
- case 4: log_println(1, "T3"); break;
- case 5: log_println(1, "FastEthernet"); break;
- case 6: log_println(1, "OC-12"); break;
- case 7: log_println(1, "Gigabit Ethernet"); break;
- case 8: log_println(1, "OC-48"); break;
- case 9: log_println(1, "10 Gigabit Enet"); break;
- case 10: log_println(1, "Retransmissions"); break;
- }
- }
- switch (c2sdata) {
- case -2: sprintf(btlneck, "Insufficent Data");
- break;
- case -1: sprintf(btlneck, "a System Fault");
- break;
- case 0: sprintf(btlneck, "the Round Trip Time");
- break;
- case 1: sprintf(btlneck, "a 'Dial-up modem' connection");
- break;
- case 2:
- if ((c2sspd/s2cspd > .8) && (c2sspd/s2cspd < 1.2) && (c2sspd
1000))
- sprintf(btlneck, "a 'T1' subnet");
- else {
- if ((tail[3] > 1) || (s2cack == 3))
- sprintf(btlneck, "a 'Cable Modem' connection");
- else
- sprintf(btlneck, "a 'DSL' connection");
- }
- break;
- case 3: if (linkcnt == 16)
- sprintf(btlneck, "a T1 + subnet");
- else
- sprintf(btlneck, "an 'Ethernet' subnet");
- break;
- case 4: if (linkcnt == 16)
- sprintf(btlneck, "a IEEE 802.11b Wifi subnet");
- else
- sprintf(btlneck, "a 'T3/DS-3' subnet");
- break;
- case 5: if (linkcnt == 16)
- sprintf(btlneck, "a Wifi + subnet");
- else
- sprintf(btlneck, "a 'FastEthernet' subnet");
- break;
- case 6: if (linkcnt == 16)
- sprintf(btlneck, "a Ethernet subnet");
- else
- sprintf(btlneck, "an 'OC-12' subnet");
- break;
- case 7: if (linkcnt == 16)
- sprintf(btlneck, "a T3/DS3 subnet");
- else
- sprintf(btlneck, "a 'Gigabit Ethernet' subnet");
- break;
- case 8: if (linkcnt == 16)
- sprintf(btlneck, "a FastEthernet subnet");
- else
- sprintf(btlneck, "an 'OC-48' subnet");
- break;
- case 9: if (linkcnt == 16)
- sprintf(btlneck, "a OC-12 subnet");
- else
- sprintf(btlneck, "a '10 Gigabit Enet' subnet");
- break;
- case 10: if (linkcnt == 16)
- sprintf(btlneck, "a Gigabit Ethernet subnet");
- else
- sprintf(btlneck, "Retransmissions");
- case 11:
- sprintf(btlneck, "an 'OC-48' subnet");
- break;
- case 12:
- sprintf(btlneck, "a '10 Gigabit Enet' subnet");
- break;
- case 13:
- sprintf(btlneck, "Retransmissions");
- break;
- }
- /* Calculate some values */
- avgrtt = (double) SumRTT/CountRTT;
- rttsec = avgrtt * .001;
- loss = (double)(PktsRetrans- FastRetran)/(double)(DataPktsOut-AckPktsOut);
- loss2 = (double)CongestionSignals/PktsOut;
- if (loss == 0)
- loss = .0000000001; /* set to 10^-6 for now */
- if (loss2 == 0)
- loss2 = .0000000001; /* set to 10^-6 for now */
-
- order = (double)DupAcksIn/AckPktsIn;
- bw = (CurrentMSS / (rttsec * sqrt(loss))) * 8 / 1024 / 1024;
- bw2 = (CurrentMSS / (rttsec * sqrt(loss2))) * 8 / 1024 / 1024;
- totaltime = SndLimTimeRwin + SndLimTimeCwnd + SndLimTimeSender;
- rwintime = (double)SndLimTimeRwin/totaltime;
- cwndtime = (double)SndLimTimeCwnd/totaltime;
- sendtime = (double)SndLimTimeSender/totaltime;
- timesec = totaltime/1000000;
- idle = (Timeouts * ((double)CurrentRTO/1000))/timesec;
- retrn = (float)PktsRetrans / PktsOut;
- increase = (float)CongAvoid / PktsOut;
-
- recvbwd = ((MaxRwinRcvd*8)/avgrtt)/1000;
- cwndbwd = ((CurrentCwnd*8)/avgrtt)/1000;
- sendbwd = ((Sndbuf*8)/avgrtt)/1000;
-
- spd = ((double)DataBytesOut / (double)totaltime) * 8;
-
- mismatch2 = 0;
- mismatch3 = 0;
- mmorder = (float)(DataPktsOut - PktsRetrans - FastRetran) / DataPktsOut;
- cong = (float)(CongestionSignals - CongestionOverCount) / PktsOut;
- touts = (float)Timeouts / PktsOut;
- if (PktsRetrans > 0)
- fr_ratio = (float)FastRetran / PktsRetrans;
- retransec = (float)PktsRetrans / timesec;
-
- /* new test based on analysis of TCP behavior in duplex mismatch condition. */
-
- acks = (double) AckPktsIn / (double) DataPktsOut;
- pureacks = (double) (AckPktsIn - DupAcksIn) / (double) DataPktsOut;
- if (s2cspd < c2sspd)
- aspeed = (double)c2sspd / (double)s2cspd;
- else
- aspeed = (double)s2cspd / (double)c2sspd;
- printf("Acks = %0.4f, async speed = %0.4f, mismatch3 = %0.4f, CongOver = %d\n", acks, aspeed, cong, CongestionOverCount);
- printf("idle = %0.4f, timeout/pkts = %0.4f, %%retranmissions = %0.2f, %%increase = %0.2f\n", idle,
- touts, retrn*100, increase*100);
- printf("FastRetrans/Total = %0.4f, Fast/Retrans = %0.4f, Retrans/sec = %0.4f\n", retrn, fr_ratio, retransec);
- if (((acks > 0.7) || (acks < 0.3)) && (retrn > 0.03) && (CongAvoid > SlowStart)) {
- if ((2*CurrentMSS) == MaxSsthresh) {
- mismatch2 = 1;
- mismatch3 = 0;
- } else if (aspeed > 15){
- mismatch2 = 2;
- }
- }
- if ((idle > 0.65) && (touts < 0.4)) {
- if (MaxSsthresh == (2*CurrentMSS)) {
- mismatch2 = 0;
- mismatch3 = 1;
- } else {
- mismatch3 = 2;
- }
- }
-
- /* estimate is less than throughput, something is wrong */
- if (bw < spd)
- link = 0;
-
- if (((loss*100)/timesec > 15) && (cwndtime/timesec > .6) &&
- (loss < .01) && (MaxSsthresh > 0))
- bad_cable = 1;
-
- /* test for Ethernet link (assume Fast E.) */
- if ((spd < 9.5) && (spd > 3.0) && (loss < .01) && (order < .035) && (link > 0))
- link = 10;
-
- /* test for DSL/Cable modem link */
- if ((SndLimTimeSender < 15000) && (spd < 2) && (spd < bw) && (link > 0))
- link = 2;
-
- if (((rwintime > .95) && (SndLimTransRwin/timesec > 30) &&
- (SndLimTransSender/timesec > 30)) || (link <= 10))
- half_duplex = 1;
-
- if ((cwndtime > .02) && (mismatch2 == 0) && (cwndbwd < recvbwd))
- congestion2 = 1;
-
- if (iponly == 0) {
- char tmpbuff[200];
- socklen_t tmpBufLen = 199;
- if ((addr = I2AddrByNode(get_errhandle(), ip_addr)) == NULL) {
- printf("Throughput to host [%s] is limited by %s\n", ip_addr, btlneck);
- }
- else {
- struct addrinfo *fai;
- fai = I2AddrAddrInfo(addr, ip_addr, NULL);
- if (fai == NULL) {
- printf("Throughput to host [%s] is limited by %s\n", ip_addr, btlneck);
- }
- else {
- memset(tmpbuff, 0, 200);
- if ((tmpret = getnameinfo(fai->ai_addr, fai->ai_addrlen, tmpbuff, tmpBufLen, NULL, 0, 0))) {
- log_println(1, "getnameinfo: %d", tmpret);
- printf("Throughput to host [%s] is limited by %s\n", ip_addr, btlneck);
- }
- else {
- printf("Throughput to host %s [%s] is limited by %s\n", tmpbuff, ip_addr, btlneck);
- }
- }
- }
- }
- else {
- printf("Throughput to host [%s] is limited by %s\n", ip_addr, btlneck);
- }
-
- printf("\tWeb100 says link = %d, speed-chk says link = %d\n", link, c2sdata);
- printf("\tSpeed-chk says {%d, %d, %d, %d}, Running average = {%0.1f, %0.1f, %0.1f, %0.1f}\n",
- c2sdata, c2sack, s2cdata, s2cack, runave[0], runave[1], runave[2], runave[3]);
- if (c2sspd > 1000)
- printf("\tC2Sspeed = %0.2f Mbps, S2Cspeed = %0.2f Mbps, CWND-Limited = %0.2f Mbps, ",
- (float) c2sspd/1000, (float)s2cspd/1000, (float)s2c2spd/1000);
- else
- printf("\tC2Sspeed = %d kbps, S2Cspeed = %d kbps, CWND-Limited: %d kbps, ", c2sspd, s2cspd, s2c2spd);
- if (bw > 1)
- printf("Estimate = %0.2f Mbps (%0.2f Mbps)\n", bw, bw2);
- else
- printf("Estimate = %0.2f kbps (%0.2f kbps)\n", bw*1000, bw2*1000);
-
- if ((bw*1000) > s2cspd)
- printf("\tOld estimate is greater than measured; ");
- else
- printf("\tOld estimate is less than measured; ");
-
- if (CongestionSignals == -1)
- printf("No data collected to calculage new estimate\n");
- else {
- if ((bw2*1000) > s2cspd)
- printf("New estimate is greater than measured\n");
- else
- printf("New estimate is less than measured\n");
- }
-
- printf("\tLoss = %0.2f%% (%0.2f%%), Out-of-Order = %0.2f%%, Long tail = {%d, %d, %d, %d}\n",
- loss*100, loss2*100, order*100, tail[0], tail[1], tail[2], tail[3]);
- printf("\tDistribution = {%d, %d, %d, %d}, time spent {r=%0.1f%% c=%0.1f%% s=%0.1f%%}\n",
- head[0], head[1], head[2], head[3], rwintime*100, cwndtime*100, sendtime*100);
- printf("\tAve(min) RTT = %0.2f (%d) msec, Buffers = {r=%d, c=%d, s=%d}\n",
- avgrtt, MinRTT, MaxRwinRcvd, CurrentCwnd, Sndbuf/2);
- printf("\tbw*delay = {r=%0.2f, c=%0.2f, s=%0.2f}, Transitions/sec = {r=%0.1f, c=%0.1f, s=%0.1f}\n",
- recvbwd, cwndbwd, sendbwd,
- SndLimTransRwin/timesec, SndLimTransCwnd/timesec, SndLimTransSender/timesec);
- printf("\tRetransmissions/sec = %0.1f, Timeouts/sec = %0.1f, SSThreshold = %d\n",
- (float) PktsRetrans/timesec, (float) Timeouts/timesec, MaxSsthresh);
- printf("\tMismatch = %d (%d:%d[%0.2f])", mismatch, mismatch2, mismatch3, mmorder);
- if (mismatch3 == 1)
- printf(" [H=F, S=H]");
- if (mismatch2 == 1)
- printf(" [H=H, S=F]");
- printf(", Cable fault = %d, Congestion = %d, Duplex = %d\n\n",
- bad_cable, congestion2, half_duplex);
+void calculate() {
+ int tail[4], i, head[4], tmpret;
+ float k;
+ float recvbwd, cwndbwd, sendbwd;
+ char btlneck[64];
+ int congestion2 = 0;
+ I2Addr addr;
+ double acks, aspeed, pureacks;
+ float cong, retrn, increase, touts, fr_ratio = 0;
+ float retransec;
+
+ tail[0] = tail[1] = tail[2] = tail[3] = 0;
+ head[0] = head[1] = head[2] = head[3] = 0;
+ for (i = 0; i < 4; i++) {
+ max = 0;
+ indx = 0;
+ total = 0;
+ for (j = 0; j < linkcnt - 1; j++) {
+ total += links[i][j];
+ if (max < links[i][j]) {
+ max = links[i][j];
+ indx = j;
+ }
+ }
+ for (j = indx + 1; j < 10; j++) {
+ k = (float) links[i][j] / max;
+ if (k > .1)
+ tail[i]++;
+ }
+ for (j = 0; j < indx; j++) {
+ k = (float) links[i][j] / max;
+ if (k > .1)
+ head[i]++;
+ }
+ if (links[i][indx] == -1)
+ indx = -1;
+ if ((total < 20) && (indx != -1))
+ indx = -2;
+ switch (i) {
+ case 0:
+ c2sdata = indx;
+ log_print(1, "Client --> Server data detects link =
");
+ break;
+ case 1:
+ c2sack = indx;
+ log_print(1, "Client <-- Server Ack's detect link =
");
+ break;
+ case 2:
+ s2cdata = indx;
+ log_print(1, "Server --> Client data detects link =
");
+ break;
+ case 3:
+ s2cack = indx;
+ log_print(1, "Server <-- Client Ack's detect link =
");
+ }
+ switch (indx) {
+ case -2:
+ log_println(1, "Insufficent Data");
+ break;
+ case -1:
+ log_println(1, "System Fault");
+ break;
+ case 0:
+ log_println(1, "RTT");
+ break;
+ case 1:
+ log_println(1, "Dial-up");
+ break;
+ case 2:
+ log_println(1, "T1");
+ break;
+ case 3:
+ log_println(1, "Ethernet");
+ break;
+ case 4:
+ log_println(1, "T3");
+ break;
+ case 5:
+ log_println(1, "FastEthernet");
+ break;
+ case 6:
+ log_println(1, "OC-12");
+ break;
+ case 7:
+ log_println(1, "Gigabit Ethernet");
+ break;
+ case 8:
+ log_println(1, "OC-48");
+ break;
+ case 9:
+ log_println(1, "10 Gigabit Enet");
+ break;
+ case 10:
+ log_println(1, "Retransmissions");
+ break;
+ }
+ }
+ switch (c2sdata) {
+ case -2:
+ sprintf(btlneck, "Insufficent Data");
+ break;
+ case -1:
+ sprintf(btlneck, "a System Fault");
+ break;
+ case 0:
+ sprintf(btlneck, "the Round Trip Time");
+ break;
+ case 1:
+ sprintf(btlneck, "a 'Dial-up modem' connection");
+ break;
+ case 2:
+ if ((c2sspd / s2cspd > .8) && (c2sspd / s2cspd < 1.2)
+ && (c2sspd > 1000))
+ sprintf(btlneck, "a 'T1' subnet");
+ else {
+ if ((tail[3] > 1) || (s2cack == 3))
+ sprintf(btlneck, "a 'Cable Modem'
connection");
+ else
+ sprintf(btlneck, "a 'DSL' connection");
+ }
+ break;
+ case 3:
+ if (linkcnt == 16)
+ sprintf(btlneck, "a T1 + subnet");
+ else
+ sprintf(btlneck, "an 'Ethernet' subnet");
+ break;
+ case 4:
+ if (linkcnt == 16)
+ sprintf(btlneck, "a IEEE 802.11b Wifi subnet");
+ else
+ sprintf(btlneck, "a 'T3/DS-3' subnet");
+ break;
+ case 5:
+ if (linkcnt == 16)
+ sprintf(btlneck, "a Wifi + subnet");
+ else
+ sprintf(btlneck, "a 'FastEthernet' subnet");
+ break;
+ case 6:
+ if (linkcnt == 16)
+ sprintf(btlneck, "a Ethernet subnet");
+ else
+ sprintf(btlneck, "an 'OC-12' subnet");
+ break;
+ case 7:
+ if (linkcnt == 16)
+ sprintf(btlneck, "a T3/DS3 subnet");
+ else
+ sprintf(btlneck, "a 'Gigabit Ethernet' subnet");
+ break;
+ case 8:
+ if (linkcnt == 16)
+ sprintf(btlneck, "a FastEthernet subnet");
+ else
+ sprintf(btlneck, "an 'OC-48' subnet");
+ break;
+ case 9:
+ if (linkcnt == 16)
+ sprintf(btlneck, "a OC-12 subnet");
+ else
+ sprintf(btlneck, "a '10 Gigabit Enet' subnet");
+ break;
+ case 10:
+ if (linkcnt == 16)
+ sprintf(btlneck, "a Gigabit Ethernet subnet");
+ else
+ sprintf(btlneck, "Retransmissions");
+ case 11:
+ sprintf(btlneck, "an 'OC-48' subnet");
+ break;
+ case 12:
+ sprintf(btlneck, "a '10 Gigabit Enet' subnet");
+ break;
+ case 13:
+ sprintf(btlneck, "Retransmissions");
+ break;
+ }
+ /* Calculate some values */
+ avgrtt = (double) SumRTT / CountRTT;
+ rttsec = avgrtt * .001;
+ loss = (double) (PktsRetrans - FastRetran)
+ / (double) (DataPktsOut - AckPktsOut);
+ loss2 = (double) CongestionSignals / PktsOut;
+ if (loss == 0)
+ loss = .0000000001; /* set to 10^-6 for now */
+ if (loss2 == 0)
+ loss2 = .0000000001; /* set to 10^-6 for now */
+
+ order = (double) DupAcksIn / AckPktsIn;
+ bw = (CurrentMSS / (rttsec * sqrt(loss))) * 8 / 1024 / 1024;
+ bw2 = (CurrentMSS / (rttsec * sqrt(loss2))) * 8 / 1024 / 1024;
+ totaltime = SndLimTimeRwin + SndLimTimeCwnd + SndLimTimeSender;
+ rwintime = (double) SndLimTimeRwin / totaltime;
+ cwndtime = (double) SndLimTimeCwnd / totaltime;
+ sendtime = (double) SndLimTimeSender / totaltime;
+ timesec = totaltime / 1000000;
+ idle = (Timeouts * ((double) CurrentRTO / 1000)) / timesec;
+ retrn = (float) PktsRetrans / PktsOut;
+ increase = (float) CongAvoid / PktsOut;
+
+ recvbwd = ((MaxRwinRcvd * 8) / avgrtt) / 1000;
+ cwndbwd = ((CurrentCwnd * 8) / avgrtt) / 1000;
+ sendbwd = ((Sndbuf * 8) / avgrtt) / 1000;
+
+ spd = ((double) DataBytesOut / (double) totaltime) * 8;
+
+ mismatch2 = 0;
+ mismatch3 = 0;
+ mmorder = (float) (DataPktsOut - PktsRetrans - FastRetran) /
DataPktsOut;
+ cong = (float) (CongestionSignals - CongestionOverCount) / PktsOut;
+ touts = (float) Timeouts / PktsOut;
+ if (PktsRetrans > 0)
+ fr_ratio = (float) FastRetran / PktsRetrans;
+ retransec = (float) PktsRetrans / timesec;
+
+ /* new test based on analysis of TCP behavior in duplex mismatch condition. */
+
+ acks = (double) AckPktsIn / (double) DataPktsOut;
+ pureacks = (double) (AckPktsIn - DupAcksIn) / (double) DataPktsOut;
+ if (s2cspd < c2sspd)
+ aspeed = (double) c2sspd / (double) s2cspd;
+ else
+ aspeed = (double) s2cspd / (double) c2sspd;
+ printf(
+ "Acks = %0.4f, async speed = %0.4f, mismatch3 = %0.4f, CongOver = %d\n",
+ acks, aspeed, cong, CongestionOverCount);
+ printf(
+ "idle = %0.4f, timeout/pkts = %0.4f, %%retranmissions = %0.2f, %%increase = %0.2f\n",
+ idle, touts, retrn * 100, increase * 100);
+ printf(
+ "FastRetrans/Total = %0.4f, Fast/Retrans = %0.4f, Retrans/sec = %0.4f\n",
+ retrn, fr_ratio, retransec);
+ if (((acks > 0.7) || (acks < 0.3)) && (retrn > 0.03)
+ && (CongAvoid > SlowStart)) {
+ if ((2 * CurrentMSS) == MaxSsthresh) {
+ mismatch2 = 1;
+ mismatch3 = 0;
+ } else if (aspeed > 15) {
+ mismatch2 = 2;
+ }
+ }
+ if ((idle > 0.65) && (touts < 0.4)) {
+ if (MaxSsthresh == (2 * CurrentMSS)) {
+ mismatch2 = 0;
+ mismatch3 = 1;
+ } else {
+ mismatch3 = 2;
+ }
+ }
+
+ /* estimate is less than throughput, something is wrong */
+ if (bw < spd)
+ link = 0;
+
+ if (((loss * 100) / timesec > 15) && (cwndtime / timesec > .6)
+ && (loss < .01) && (MaxSsthresh > 0))
+ bad_cable = 1;
+
+ /* test for Ethernet link (assume Fast E.) */
+ if ((spd < 9.5) && (spd > 3.0) && (loss < .01) && (order < .035)
+ && (link > 0))
+ link = 10;
+
+ /* test for DSL/Cable modem link */
+ if ((SndLimTimeSender < 15000) && (spd < 2) && (spd < bw) && (link >
0))
+ link = 2;
+
+ if (((rwintime > .95) && (SndLimTransRwin / timesec > 30)
+ && (SndLimTransSender / timesec > 30)) || (link <=
10))
+ half_duplex = 1;
+
+ if ((cwndtime > .02) && (mismatch2 == 0) && (cwndbwd < recvbwd))
+ congestion2 = 1;
+
+ if (iponly == 0) {
+ char tmpbuff[200];
+ socklen_t tmpBufLen = 199;
+ if ((addr = I2AddrByNode(get_errhandle(), ip_addr)) == NULL) {
+ printf("Throughput to host [%s] is limited by %s\n",
ip_addr,
+ btlneck);
+ } else {
+ struct addrinfo *fai;
+ fai = I2AddrAddrInfo(addr, ip_addr, NULL);
+ if (fai == NULL) {
+ printf("Throughput to host [%s] is limited by
%s\n", ip_addr,
+ btlneck);
+ } else {
+ memset(tmpbuff, 0, 200);
+ if ((tmpret = getnameinfo(fai->ai_addr,
fai->ai_addrlen,
+ tmpbuff, tmpBufLen, NULL, 0,
0))) {
+ log_println(1, "getnameinfo: %d",
tmpret);
+ printf("Throughput to host [%s] is limited
by %s\n",
+ ip_addr, btlneck);
+ } else {
+ printf("Throughput to host %s [%s] is
limited by %s\n",
+ tmpbuff, ip_addr,
btlneck);
+ }
+ }
+ }
+ } else {
+ printf("Throughput to host [%s] is limited by %s\n", ip_addr,
btlneck);
+ }
+
+ printf("\tWeb100 says link = %d, speed-chk says link = %d\n", link,
+ c2sdata);
+ printf(
+ "\tSpeed-chk says {%d, %d, %d, %d}, Running average = {%0.1f, %0.1f, %0.1f, %0.1f}\n",
+ c2sdata, c2sack, s2cdata, s2cack, runave[0],
runave[1], runave[2],
+ runave[3]);
+ if (c2sspd > 1000)
+ printf(
+ "\tC2Sspeed = %0.2f Mbps, S2Cspeed = %0.2f Mbps, CWND-Limited = %0.2f Mbps, ",
+ (float) c2sspd / 1000, (float) s2cspd / 1000,
+ (float) s2c2spd / 1000);
+ else
+ printf(
+ "\tC2Sspeed = %d kbps, S2Cspeed = %d kbps,
CWND-Limited: %d kbps, ",
+ c2sspd, s2cspd, s2c2spd);
+ if (bw > 1)
+ printf("Estimate = %0.2f Mbps (%0.2f Mbps)\n", bw, bw2);
+ else
+ printf("Estimate = %0.2f kbps (%0.2f kbps)\n", bw * 1000, bw2
* 1000);
+
+ if ((bw * 1000) > s2cspd)
+ printf("\tOld estimate is greater than measured; ");
+ else
+ printf("\tOld estimate is less than measured; ");
+
+ if (CongestionSignals == -1)
+ printf("No data collected to calculage new estimate\n");
+ else {
+ if ((bw2 * 1000) > s2cspd)
+ printf("New estimate is greater than measured\n");
+ else
+ printf("New estimate is less than measured\n");
+ }
+
+ printf(
+ "\tLoss = %0.2f%% (%0.2f%%), Out-of-Order = %0.2f%%, Long tail = {%d, %d, %d, %d}\n",
+ loss * 100, loss2 * 100, order * 100, tail[0],
tail[1], tail[2],
+ tail[3]);
+ printf(
+ "\tDistribution = {%d, %d, %d, %d}, time spent {r=%0.1f%% c=%0.1f%% s=%0.1f%%}\n",
+ head[0], head[1], head[2], head[3], rwintime * 100,
cwndtime * 100,
+ sendtime * 100);
+ printf("\tAve(min) RTT = %0.2f (%d) msec, Buffers = {r=%d, c=%d,
s=%d}\n",
+ avgrtt, MinRTT, MaxRwinRcvd, CurrentCwnd, Sndbuf / 2);
+ printf(
+ "\tbw*delay = {r=%0.2f, c=%0.2f, s=%0.2f}, Transitions/sec = {r=%0.1f, c=%0.1f, s=%0.1f}\n",
+ recvbwd, cwndbwd, sendbwd, SndLimTransRwin / timesec,
+ SndLimTransCwnd / timesec, SndLimTransSender /
timesec);
+ printf(
+ "\tRetransmissions/sec = %0.1f, Timeouts/sec = %0.1f, SSThreshold = %d\n",
+ (float) PktsRetrans / timesec, (float) Timeouts /
timesec,
+ MaxSsthresh);
+ printf("\tMismatch = %d (%d:%d[%0.2f])", mismatch, mismatch2,
mismatch3,
+ mmorder);
+ if (mismatch3 == 1)
+ printf(" [H=F, S=H]");
+ if (mismatch2 == 1)
+ printf(" [H=H, S=F]");
+ printf(", Cable fault = %d, Congestion = %d, Duplex = %d\n\n",
bad_cable,
+ congestion2, half_duplex);
}

-int
-main(int argc, char** argv)
-{
- int c;
- char tmpstr[256];
- int debug = 0;
-
- iponly = 0;
- //while ((c = getopt_long(argc, argv, "dnhl:v", long_options, 0)) != -1) {
- while ((c = getopt_long(argc, argv, "udnhl:v", long_options, 0)) != -1) {
- switch (c) {
- case 'h':
- analyze_long_usage("ANL/Internet2 NDT version " VERSION " (analyze)");
- break;
- case 'v':
- printf("ANL/Internet2 NDT version %s (analyze)\n", VERSION);
- exit(0);
- break;
- case 'l':
- LogFileName = optarg;
- break;
- /*
- case 'u':
- ProtoLogFileName = optarg;
- break;
- */
- case 'u':
- printf("Calling set protolog from analyze.c");
- set_protologdir(optarg);
- break;
- case 'n':
- iponly=1;
- break;
- case 'd':
- debug++;
- break;
- case '?':
- short_usage(argv[0], "");
- break;
- }
- }
-
- if (optind < argc) {
- short_usage(argv[0], "Unrecognized non-option elements");
- }
-
- log_init(argv[0], debug);
-
- if (LogFileName == NULL) {
- sprintf(tmpstr, "%s/%s", BASEDIR, LOGFILE);
- LogFileName = tmpstr;
- }
- log_println(1, "log file = %s", LogFileName);
-
- //TODO do we need protocol log file in analyze????
- if (ProtoLogFileName == NULL) {
- sprintf(tmpstr, "%s/%s", BASEDIR, PROTOLOGFILE);
- ProtoLogFileName = tmpstr;
- }
- log_println(1, "log file = %s", ProtoLogFileName);
-
- if ((fp = fopen(LogFileName, "r")) == NULL)
- err_sys("Missing Log file ");
-
- n = 0;
- m = 0;
- while ((fgets(buff, 512, fp)) != NULL) {
- if (strncmp(buff, "spds", 4) == 0) {
- str = strchr(buff, 0x27);
- str++;
- linkcnt = sscanf(str, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %f",
- &links[n][0], &links[n][1], &links[n][2], &links[n][3], &links[n][4],
- &links[n][5], &links[n][6], &links[n][7], &links[n][8],
- &links[n][9], &links[n][10], &links[n][11], &links[n][12],
- &links[n][13], &links[n][14], &runave[n]);
- if (linkcnt != 16)
- linkcnt = sscanf(str, "%d %d %d %d %d %d %d %d %d %d %d %d %f",
- &links[n][0], &links[n][1], &links[n][2], &links[n][3], &links[n][4],
- &links[n][5], &links[n][6], &links[n][7], &links[n][8],
- &links[n][9], &links[n][10], &links[n][11], &runave[n]);
- n++;
- continue;
- }
- if (strncmp(buff, "Running", 6) == 0) {
- ret = sscanf(buff, "%*s %*s %*s %f %*s", &run_ave[m]);
- log_println(1, "read %d tokens from buffer", ret);
- log_println(1, "running average[%d] = %0.2f", m, run_ave[m]);
- if (runave[m] == 0)
- runave[m] = run_ave[m];
- m++;
- continue;
- }
- if ((str = strchr(buff, 'p')) != NULL) {
- if ((strncmp(buff, "Apr", 3) == 0) || (strncmp(buff, "Sep", 3) == 0)) {
-skip2:
- str++;
- str = strchr(str, 'p');
- if (str == NULL)
- goto skip1;
- }
- if (strncmp(str, "port", 4) != 0)
- goto skip2;
- sscanf(buff, "%*s %*s %*s %s %*s", (char*) &ip_addr);
- log_println(1, "Start of New Packet trace -- %s", buff);
- n = 0;
- m = 0;
- run_ave[0] = 0;
- run_ave[1] = 0;
- run_ave[2] = 0;
- run_ave[3] = 0;
- runave[0] = 0;
- runave[1] = 0;
- runave[2] = 0;
- runave[3] = 0;
- }
-skip1:
- if ((str = strchr(buff, ',')) != NULL) {
- str++;
- sscanf(str, "%[^,]s", ip_addr2);
- if ((str = strchr(str, ',')) == NULL)
- continue;
- str++;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- s2c2spd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- s2cspd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- c2sspd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- Timeouts = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- SumRTT = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- CountRTT = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- PktsRetrans = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- FastRetran = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- DataPktsOut = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- AckPktsOut = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- CurrentMSS = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- DupAcksIn = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- AckPktsIn = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- MaxRwinRcvd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- Sndbuf = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- CurrentCwnd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- SndLimTimeRwin = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- SndLimTimeCwnd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- SndLimTimeSender = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- DataBytesOut = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- SndLimTransRwin = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- SndLimTransCwnd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- SndLimTransSender = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- MaxSsthresh = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- CurrentRTO = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- CurrentRwinRcvd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- link = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- mismatch = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- bad_cable = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- half_duplex = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- if (sscanf(str, "%[^,]s", tmpstr) < 1)
- goto display;
- congestion = atoi(tmpstr);
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/clt_tests.h Fri Aug 25 02:20:49
2006
+++ /branches/kkumar_code_organize/src/clt_tests.h Mon Oct 17 06:43:25
2011
@@ -9,8 +9,11 @@
#ifndef _JS_CLT_TESTS_H
#define _JS_CLT_TESTS_H

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

#endif
=======================================
--- /branches/kkumar_code_organize/src/fakewww.c Sun Mar 21 11:04:42
2010
+++ /branches/kkumar_code_organize/src/fakewww.c Mon Oct 17 06:43:25
2011
@@ -47,34 +47,38 @@
char* er_time_format = ER_TIME_FORMAT;
char buff[BUFFSIZE];
/* html message */
-char *MsgOK = "HTTP/1.0 200 OK\r\n\r\n";
+char *MsgOK = "HTTP/1.0 200 OK\r\n\r\n";
char *MsgNope1 = "HTTP/1.0 404 Not found\r\n\r\n";
char *MsgNope2 = "<HEAD><TITLE>File Not Found</TITLE></HEAD>\n"
- "<BODY><H1>The requested file could not be found</H1></BODY>\n";
+ "<BODY><H1>The requested file could not be
found</H1></BODY>\n";

char *MsgRedir1 = "HTTP/1.0 307 Temporary Redirect\r\n";
char *MsgRedir2 = "Location: ";
char *MsgRedir3 = "\r\n\r\n";
char *MsgRedir4 = "<HTML><TITLE>FLM server Redirect Page</TITLE>\n"
- " <BODY>\n <meta http-equiv=\"refresh\" content=\"2; ";
-char *MsgRedir5 = "\">\n\n<h2>FLM server re-direction page</h2>\n"
- "<p><font size=\"+2\">Your client is being redirected to the 'closest' FLM server "
- "for configuration testing.\n <a ";
+ " <BODY>\n <meta http-equiv=\"refresh\" content=\"2; ";
+char *MsgRedir5 =
+ "\">\n\n<h2>FLM server re-direction page</h2>\n"
+ "<p><font size=\"+2\">Your client is being redirected to the 'closest' FLM server "
+ "for configuration testing.\n <a ";
char *MsgRedir6 = ">Click Here </a> if you are not "
- "automatically redirected in the next 2 seconds.\n "
- "</font></BODY>\n</HTML>";
-
-char *Mypagefile = "/tcpbw100.html"; /* we throw the slash away */
-char *okfile[] = {"/tcpbw100.html", "/Tcpbw100.class", "/Tcpbw100$1.class",
- "/Tcpbw100$clsFrame.class", "/Tcpbw100.jar", "/copyright.html",
"/web100variables.html",
- "/"ADMINFILE, "/Admin.class", "/tr.sh", "/traceroute.pl",
"/Tcpbw100$MyTextPane.class",
- "/Tcpbw100$Protocol.class", "/Tcpbw100$StatusPanel.class",
"/Tcpbw100$3.class",
- "/Tcpbw100$OsfwWorker.class", "/Tcpbw100$Message.class",
"/Tcpbw100$StatusPanel$1.class",
- "/Tcpbw100$clsFrame$1.class", "/Tcpbw100$TestWorker.class", "/crossdomain.xml", 0};
+ "automatically redirected in the next 2 seconds.\n "
+ "</font></BODY>\n</HTML>";
+
+char *Mypagefile = "/tcpbw100.html"; /* we throw the slash away */
+char *okfile[] = { "/tcpbw100.html", "/Tcpbw100.class", "/Tcpbw100$1.class",
+ "/Tcpbw100$clsFrame.class", "/Tcpbw100.jar",
"/copyright.html",
+ "/web100variables.html", "/"ADMINFILE, "/Admin.class",
"/tr.sh",
+ "/traceroute.pl", "/Tcpbw100$MyTextPane.class",
+ "/Tcpbw100$Protocol.class", "/Tcpbw100$StatusPanel.class",
+ "/Tcpbw100$3.class", "/Tcpbw100$OsfwWorker.class",
+ "/Tcpbw100$Message.class", "/Tcpbw100$StatusPanel$1.class",
+ "/Tcpbw100$clsFrame$1.class", "/Tcpbw100$TestWorker.class",
+ "/crossdomain.xml", 0 };

typedef struct allowed {
- char* filename;
- struct allowed *next;
+ char* filename;
+ struct allowed *next;
} Allowed;

Allowed* a_root = NULL;
@@ -87,33 +91,23 @@
static char dt6fn[256];
#endif

-int usesyslog=0;
-char *SysLogFacility=NULL;
+int usesyslog = 0;
+char *SysLogFacility = NULL;
int syslogfacility = LOG_FACILITY;
-char *ProcessName={"fakewww"};
-
-static struct option long_options[] = {
- {"debug", 0, 0, 'd'},
- {"help", 0, 0, 'h'},
- {"alog", 1, 0, 'l'},
- {"elog", 1, 0, 'e'},
- {"port", 1, 0, 'p'},
- {"ttl", 1, 0, 't'},
- {"federated", 0, 0, 'F'},
- {"file", 1, 0, 'f'},
- {"basedir", 1, 0, 'b'},
- {"syslog", 0, 0, 's'},
- {"logfacility", 1, 0, 'S'},
- {"version", 0, 0, 'v'},
- {"dflttree", 1, 0, 301},
+char *ProcessName = { "fakewww" };
+
+static struct option long_options[] = { { "debug", 0, 0, 'd' }, { "help", 0, 0,
+ 'h' }, { "alog", 1, 0, 'l' }, { "elog", 1, 0, 'e' },
+ { "port", 1, 0, 'p' }, { "ttl", 1, 0, 't' }, { "federated",
0, 0, 'F' },
+ { "file", 1, 0, 'f' }, { "basedir", 1, 0, 'b' },
+ { "syslog", 0, 0, 's' }, { "logfacility", 1, 0, 'S' }, {
"version", 0,
+ 0, 'v' }, { "dflttree", 1, 0, 301 },
#ifdef AF_INET6
- {"dflttree6", 1, 0, 302},
- {"ipv4", 0, 0, '4'},
- {"ipv6", 0, 0, '6'},
+ { "dflttree6", 1, 0, 302},
+ { "ipv4", 0, 0, '4'},
+ { "ipv6", 0, 0, '6'},
#endif
- {0, 0, 0, 0}
-};
-
+ { 0, 0, 0, 0 } };

void dowww(int, I2Addr, char*, char*, char*, int, int);
void reap();
@@ -121,210 +115,219 @@
void logErLog(char*, time_t*, char*, char*, ...);
void logAcLog(char*, time_t*, char*, char*, int, int, char*, char*);

-void
-err_sys(char* s)
-{
- perror(s);
- exit(1);
+void err_sys(char* s) {
+ perror(s);
+ exit(1);
}

-int
-main(int argc, char** argv)
-{
- int c;
- int sockfd, newsockfd;
- int federated=0, debug=0, max_ttl=10;
- time_t tt;
- socklen_t clilen;
- char* srcname = NULL;
- char* listenport = PORT;
- int conn_options = 0;
-
- char *ErLogFileName= BASEDIR"/"ERLOGFILE;
- char *AcLogFileName= BASEDIR"/"ACLOGFILE;
- struct sockaddr_storage cli_addr;
- I2Addr listenaddr = NULL;
- Allowed* ptr;
+int main(int argc, char** argv) {
+ int c;
+ int sockfd, newsockfd;
+ int federated = 0, debug = 0, max_ttl = 10;
+ time_t tt;
+ socklen_t clilen;
+ char* srcname = NULL;
+ char* listenport = PORT;
+ int conn_options = 0;
+
+ char *ErLogFileName = BASEDIR
+ "/"ERLOGFILE;
+ char *AcLogFileName = BASEDIR
+ "/"ACLOGFILE;
+ struct sockaddr_storage cli_addr;
+ I2Addr listenaddr = NULL;
+ Allowed* ptr;

#ifdef AF_INET6
#define GETOPT_LONG_INET6(x) "46"x
#else
#define GETOPT_LONG_INET6(x) x
#endif
-
- while ((c = getopt_long(argc, argv,
- GETOPT_LONG_INET6("dhl:e:p:t:Ff:b:sS:v"), long_options, 0)) != -1) {
- switch (c) {
- case '4':
- conn_options |= OPT_IPV4_ONLY;
- break;
- case '6':
- conn_options |= OPT_IPV6_ONLY;
- break;
- case 'd':
- debug++;
- break;
- case 'h':
- www_long_usage("ANL/Internet2 NDT version " VERSION " (fakewww)");
- break;
- case 'v':
- printf("ANL/Internet2 NDT version %s (fakewww)\n", VERSION);
- exit(0);
- break;
- case 'l':
- AcLogFileName = optarg;
- break;
- case 'e':
- ErLogFileName = optarg;
- break;
- case 'p':
- listenport = optarg;
- break;
- case 't':
- max_ttl = atoi(optarg);
- break;
- case 'F':
- federated = 1;
- break;
- case 'f':
- ptr = malloc(sizeof(Allowed));
- ptr->filename = optarg;
- ptr->next = a_root;
- a_root = ptr;
- break;
- case 'b':
- basedir = optarg;
- break;
- case 's':
- usesyslog = 1;
- break;
- case 'S':
- SysLogFacility = optarg;
- break;
- case 301:
- DefaultTree = optarg;
- break;
+
+ while ((c = getopt_long(argc, argv,
+ GETOPT_LONG_INET6("dhl:e:p:t:Ff:b:sS:v"),
long_options, 0)) != -1) {
+ switch (c) {
+ case '4':
+ conn_options |= OPT_IPV4_ONLY;
+ break;
+ case '6':
+ conn_options |= OPT_IPV6_ONLY;
+ break;
+ case 'd':
+ debug++;
+ break;
+ case 'h':
+ www_long_usage("ANL/Internet2 NDT version " VERSION "
(fakewww)");
+ break;
+ case 'v':
+ printf("ANL/Internet2 NDT version %s (fakewww)\n",
VERSION);
+ exit(0);
+ break;
+ case 'l':
+ AcLogFileName = optarg;
+ break;
+ case 'e':
+ ErLogFileName = optarg;
+ break;
+ case 'p':
+ listenport = optarg;
+ break;
+ case 't':
+ max_ttl = atoi(optarg);
+ break;
+ case 'F':
+ federated = 1;
+ break;
+ case 'f':
+ ptr = malloc(sizeof(Allowed));
+ ptr->filename = optarg;
+ ptr->next = a_root;
+ a_root = ptr;
+ break;
+ case 'b':
+ basedir = optarg;
+ break;
+ case 's':
+ usesyslog = 1;
+ break;
+ case 'S':
+ SysLogFacility = optarg;
+ break;
+ case 301:
+ DefaultTree = optarg;
+ break;
#ifdef AF_INET6
- case 302:
- DefaultTree6 = optarg;
- break;
+ case 302:
+ DefaultTree6 = optarg;
+ break;
#endif
- case '?':
- short_usage(argv[0], "");
- break;
- }
- }
-
- if (optind < argc) {
- short_usage(argv[0], "Unrecognized non-option elements");
- }
-
- log_init(argv[0], debug);
-
- if (SysLogFacility != NULL) {
- int i = 0;
- while (facilitynames[i].c_name) {
- if (strcmp(facilitynames[i].c_name, SysLogFacility) == 0) {
- syslogfacility = facilitynames[i].c_val;
- break;
- }
- ++i;
- }
- if (facilitynames[i].c_name == NULL) {
- log_println(0, "Warning: Unknown syslog facility [%s] --> using default (%d)",
- SysLogFacility, syslogfacility);
- SysLogFacility = NULL;
- }
- }
-
- if (DefaultTree == NULL) {
- sprintf(dtfn, "%s/%s", BASEDIR, DFLT_TREE);
- DefaultTree = dtfn;
- }
-
+ case '?':
+ short_usage(argv[0], "");
+ break;
+ }
+ }
+
+ if (optind < argc) {
+ short_usage(argv[0], "Unrecognized non-option elements");
+ }
+
+ log_init(argv[0], debug);
+
+ if (SysLogFacility != NULL) {
+ int i = 0;
+ while (facilitynames[i].c_name) {
+ if (strcmp(facilitynames[i].c_name, SysLogFacility)
== 0) {
+ syslogfacility = facilitynames[i].c_val;
+ break;
+ }
+ ++i;
+ }
+ if (facilitynames[i].c_name == NULL) {
+ log_println(
+ 0,
+ "Warning: Unknown syslog facility [%s] -->
using default (%d)",
+ SysLogFacility, syslogfacility);
+ SysLogFacility = NULL;
+ }
+ }
+
+ if (DefaultTree == NULL) {
+ sprintf(dtfn, "%s/%s", BASEDIR, DFLT_TREE);
+ DefaultTree = dtfn;
+ }
+
#ifdef AF_INET6
- if (DefaultTree6 == NULL) {
- sprintf(dt6fn, "%s/%s", BASEDIR, DFLT_TREE6);
- DefaultTree6 = dt6fn;
- }
+ if (DefaultTree6 == NULL) {
+ sprintf(dt6fn, "%s/%s", BASEDIR, DFLT_TREE6);
+ DefaultTree6 = dt6fn;
+ }
#endif
-
- /*
- * Bind our local address so that the client can send to us.
- */
- if (srcname && !(listenaddr = I2AddrByNode(get_errhandle(), srcname))) {
- err_sys("server: Invalid source address specified");
- }
- if ((listenaddr = CreateListenSocket(listenaddr, listenport, conn_options, 0)) == NULL) {
- err_sys("server: CreateListenSocket failed");
- }
- sockfd = I2AddrFD(listenaddr);
-
- tt = time(0);
- log_println(1, "%15.15s fakewww server started (NDT version %s)", ctime(&tt)+4, VERSION);
- log_println(1, "\tport = %d", I2AddrPort(listenaddr));
- log_println(1, "\tfederated mode = %s", (federated == 1) ? "on" : "off");
- log_println(1, "\taccess log = %s\n\terror log = %s", AcLogFileName, ErLogFileName);
- log_println(1, "\tbasedir = %s", basedir);
- if (usesyslog) {
- log_println(1, "\tsyslog facility = %s (%d)", SysLogFacility ? SysLogFacility : "default", syslogfacility);
- }
- log_println(1, "\tdebug level set to %d", debug);
-
- logErLog(ErLogFileName, &tt, "notice", "fakewww server started (NDT version %s)", VERSION);
- logErLog(ErLogFileName, &tt, "notice", "\tport = %d", I2AddrPort(listenaddr));
- logErLog(ErLogFileName, &tt, "notice", "\tfederated mode = %s", (federated == 1) ? "on" : "off");
- logErLog(ErLogFileName, &tt, "notice", "\taccess log = %s", AcLogFileName);
- logErLog(ErLogFileName, &tt, "notice", "\terror log = %s", ErLogFileName);
- logErLog(ErLogFileName, &tt, "notice", "\tbasedir = %s", basedir);
- if (usesyslog) {
- logErLog(ErLogFileName, &tt, "notice", "\tsyslog facility = %s (%d)", SysLogFacility ? SysLogFacility : "default", syslogfacility);
- }
- logErLog(ErLogFileName, &tt, "notice", "\tdebug level set to %d", debug);
-
- if (usesyslog == 1)
- syslog(LOG_FACILITY|LOG_INFO, "Fakewww (ver %s) process started",
- VERSION);
- signal(SIGCHLD, reap); /* get rid of zombies */
-
- /*
- * Wait for a connection from a client process.
- * This is an example of a concurrent server.
- */
-
- for(;;){
- clilen = sizeof(cli_addr);
- newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
- if (newsockfd < 0){
- if (errno == EINTR) continue; /*sig child */
- err_sys("Fakewww server: accept error");
- }
-
- if (fork() == 0){ /* child */
- I2Addr caddr = I2AddrBySAddr(get_errhandle(), (struct sockaddr *) &cli_addr, clilen, 0, 0);
- alarm(300); /* kill child off after 5 minutes, should never happen */
- close(sockfd);
- dowww(newsockfd, caddr, listenport, AcLogFileName, ErLogFileName, federated, max_ttl);
- exit(0);
- }
- close(newsockfd);
- }
+
+ /*
+ * Bind our local address so that the client can send to us.
+ */
+ if (srcname && !(listenaddr = I2AddrByNode(get_errhandle(),
srcname))) {
+ err_sys("server: Invalid source address specified");
+ }
+ if ((listenaddr = CreateListenSocket(listenaddr, listenport,
conn_options,
+ 0)) == NULL) {
+ err_sys("server: CreateListenSocket failed");
+ }
+ sockfd = I2AddrFD(listenaddr);
+
+ tt = time(0);
+ log_println(1, "%15.15s fakewww server started (NDT version %s)",
+ ctime(&tt) + 4, VERSION);
+ log_println(1, "\tport = %d", I2AddrPort(listenaddr));
+ log_println(1, "\tfederated mode = %s", (federated == 1) ? "on" :
"off");
+ log_println(1, "\taccess log = %s\n\terror log = %s", AcLogFileName,
+ ErLogFileName);
+ log_println(1, "\tbasedir = %s", basedir);
+ if (usesyslog) {
+ log_println(1, "\tsyslog facility = %s (%d)",
+ SysLogFacility ? SysLogFacility : "default",
syslogfacility);
+ }
+ log_println(1, "\tdebug level set to %d", debug);
+
+ logErLog(ErLogFileName, &tt, "notice",
+ "fakewww server started (NDT version %s)", VERSION);
+ logErLog(ErLogFileName, &tt, "notice", "\tport = %d",
+ I2AddrPort(listenaddr));
+ logErLog(ErLogFileName, &tt, "notice", "\tfederated mode = %s",
+ (federated == 1) ? "on" : "off");
+ logErLog(ErLogFileName, &tt, "notice", "\taccess log = %s", AcLogFileName);
+ logErLog(ErLogFileName, &tt, "notice", "\terror log = %s",
ErLogFileName);
+ logErLog(ErLogFileName, &tt, "notice", "\tbasedir = %s", basedir);
+ if (usesyslog) {
+ logErLog(ErLogFileName, &tt, "notice", "\tsyslog facility = %s
(%d)",
+ SysLogFacility ? SysLogFacility : "default",
syslogfacility);
+ }
+ logErLog(ErLogFileName, &tt, "notice", "\tdebug level set to %d",
debug);
+
+ if (usesyslog == 1)
+ syslog(LOG_FACILITY | LOG_INFO, "Fakewww (ver %s) process
started",
+ VERSION);
+ signal(SIGCHLD, reap); /* get rid of zombies */
+
+ /*
+ * Wait for a connection from a client process.
+ * This is an example of a concurrent server.
+ */
+
+ for (;;) {
+ clilen = sizeof(cli_addr);
+ newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr,
&clilen);
+ if (newsockfd < 0) {
+ if (errno == EINTR)
+ continue; /*sig child */
+ err_sys("Fakewww server: accept error");
+ }
+
+ if (fork() == 0) { /* child */
+ I2Addr caddr = I2AddrBySAddr(get_errhandle(),
+ (struct sockaddr *) &cli_addr,
clilen, 0, 0);
+ alarm(300); /* kill child off after 5 minutes, should
never happen */
+ close(sockfd);
+ dowww(newsockfd, caddr, listenport, AcLogFileName,
ErLogFileName,
+ federated, max_ttl);
+ exit(0);
+ }
+ close(newsockfd);
+ }

}

#include <sys/wait.h>
-void
-reap(int signo)
-{
- /*
- * avoid zombies, since we run forever
- * Use the wait3() system call with the WNOHANG option.
- */
- int pid;
- union wait status;
-
- while ( (pid = wait3(&status, WNOHANG, (struct rusage *) 0)) > 0)
- ;
+void reap(int signo) {
+ /*
+ * avoid zombies, since we run forever
+ * Use the wait3() system call with the WNOHANG option.
+ */
+ int pid;
+ union wait status;
+
+ while ((pid = wait3(&status, WNOHANG, (struct rusage *) 0)) > 0)
+ ;
}

/*
@@ -335,396 +338,404 @@
* the null (the same as strlen(3)).
*/

-int
-readline(fd, ptr, maxlen)
-register int fd;
-register char *ptr;
-register int maxlen;
-{
- int n, rc;
- char c;
-
- for (n = 1; n < maxlen; n++) {
- if ( (rc = read(fd, &c, 1)) == 1) {
- *ptr++ = c;
- if (c == '\n')
- break;
- } else if (rc == 0) {
- if (n == 1)
- return(0); /* EOF, no data read */
- else
- break; /* EOF, some data was read */
- } else
- return(-1); /* error */
- }
-
- *ptr = 0;
- return(n);
+int readline(fd, ptr, maxlen)
+ register int fd;register char *ptr;register int maxlen; {
+ int n, rc;
+ char c;
+
+ for (n = 1; n < maxlen; n++) {
+ if ((rc = read(fd, &c, 1)) == 1) {
+ *ptr++ = c;
+ if (c == '\n')
+ break;
+ } else if (rc == 0) {
+ if (n == 1)
+ return (0); /* EOF, no data read */
+ else
+ break; /* EOF, some data was read */
+ } else
+ return (-1); /* error */
+ }
+
+ *ptr = 0;
+ return (n);
}

-void
-trim(char* ptr) {
- while (*ptr) {
- if ((*ptr == '\r') || (*ptr == '\n')) {
- *ptr = 0;
- break;
- }
- ptr++;
- }
+void trim(char* ptr) {
+ while (*ptr) {
+ if ((*ptr == '\r') || (*ptr == '\n')) {
+ *ptr = 0;
+ break;
+ }
+ ptr++;
+ }
}

-void
-dowww(int sd, I2Addr addr, char* port, char* AcLogFileName, char* ErLogFileName, int fed_mode, int max_ttl)
-{
- /* process web request */
- int fd, n, i, ok;
- char *p, filename[256], line[256], *ctime();
- char htmlfile[256];
- u_int32_t IPlist[64], srv_addr;
+void dowww(int sd, I2Addr addr, char* port, char* AcLogFileName,
+ char* ErLogFileName, int fed_mode, int max_ttl) {
+ /* process web request */
+ int fd, n, i, ok;
+ char *p, filename[256], line[256], *ctime();
+ char htmlfile[256];
+ u_int32_t IPlist[64], srv_addr;
#ifdef AF_INET6
- u_int32_t IP6list[64][4];
- u_int32_t srv_addr6[4];
+ u_int32_t IP6list[64][4];
+ u_int32_t srv_addr6[4];
#endif
- I2Addr serv_addr = NULL;
- I2Addr loc_addr=NULL;
- time_t tt;
- char nodename[200];
- char onenodename[200];
- size_t nlen = 199;
- Allowed* ptr;
- char lineBuf[100];
- char useragentBuf[100];
- char refererBuf[100];
- int answerSize;
-
- memset(nodename, 0, 200);
- I2AddrNodeName(addr, nodename, &nlen);
-
- while ((n = readline(sd, buff, sizeof(buff))) > 0) {
- if (n < 3)
- break; /* end of html input */
- p = (char *) strstr(buff, "GET");
- if (p == NULL)
- continue;
- memset(lineBuf, 0, 100);
- memset(useragentBuf, 0, 100);
- memset(refererBuf, 0, 100);
- strncpy(lineBuf, buff, 99);
- trim(lineBuf);
- sscanf(p+4, "%s", filename);
- while ((n = readline(sd, buff, sizeof(buff))) > 0) {
- if ((p = (char *) strstr(buff, "User-Agent"))) {
- strncpy(useragentBuf, p+12, 99);
- trim(useragentBuf);
- }
- if ((p = (char *) strstr(buff, "Referer"))) {
- strncpy(refererBuf, p+9, 99);
- trim(refererBuf);
- }
- if (n < 3)
- break; /* end of html input */
- }
- if (strcmp(filename, "/") == 0) {
- /* feed em the default page */
- /* strcpy(filename, Mypagefile); */
- /* By default we now send out the redirect page */
-
- log_println(4, "Received connection from [%s]", nodename);
-
- if (fed_mode == 1) {
- struct sockaddr* csaddr;
- csaddr = I2AddrSAddr(addr, NULL);
- if (csaddr->sa_family == AF_INET) { /* make the IPv4 find */
- struct sockaddr_in* cli_addr = (struct sockaddr_in*) csaddr;
- find_route(cli_addr->sin_addr.s_addr, IPlist, max_ttl);
- for (i=0; IPlist[i]!=cli_addr->sin_addr.s_addr; i++) {
- sprintf(p, "%u.%u.%u.%u", IPlist[i] & 0xff, (IPlist[i] >> 8) & 0xff,
- (IPlist[i] >> 16) & 0xff, (IPlist[i] >> 24) & 0xff);
- log_println(4, "loop IPlist[%d] = %s", i, p);
- if (i == max_ttl) {
- log_println(4, "Oops, destination not found!");
- break;
- }
- }
- /* print out last item on list */
- sprintf(p, "%u.%u.%u.%u", IPlist[i] & 0xff,
- (IPlist[i] >> 8) & 0xff,
- (IPlist[i] >> 16) & 0xff, (IPlist[i] >> 24) & 0xff);
- log_println(4, "IPlist[%d] = %s", i, p);
-
- srv_addr = find_compare(IPlist, i);
-
- /* the find_compare() routine returns the IP address of the 'closest'
- * NDT server. It does this by comparing the clients address to a
- * map of routes between all servers. If this comparison fails, the
- * routine returns 0. In that case, simply use this server.
- */
- if (srv_addr == 0) {
- serv_addr = I2AddrByLocalSockFD(get_errhandle(), sd, False);
- memset(onenodename, 0, 200);
- nlen = 199;
- I2AddrNodeName(serv_addr, onenodename, &nlen);
- log_println(4, "find_compare() returned 0, reset to [%s]", onenodename);
- srv_addr = ((struct sockaddr_in*)I2AddrSAddr(serv_addr, NULL))->sin_addr.s_addr;
- }
-
- log_println(4, "Client host [%s] should be redirected to FLM server [%u.%u.%u.%u]",
- inet_ntoa(cli_addr->sin_addr), srv_addr & 0xff, (srv_addr >> 8) & 0xff,
- (srv_addr >> 16) & 0xff, (srv_addr >> 24) & 0xff);
-
- /* At this point, the srv_addr variable contains the IP address of the
- * server we want to re-direct the connect to. So we should generate a
- * new html page, and sent that back to the client. This new page will
- * use the HTML refresh option with a short (2 second) timer to cause the
- * client's browser to just to the new server.
- *
- * RAC 3/9/04
- */
-
- writen(sd, MsgRedir1, strlen(MsgRedir1));
- writen(sd, MsgRedir2, strlen(MsgRedir2));
- sprintf(line, "http://%u.%u.%u.%u:%s/tcpbw100.html";,
- srv_addr & 0xff, (srv_addr >> 8) & 0xff,
- (srv_addr >> 16) & 0xff, (srv_addr >> 24) & 0xff,
- port);
- writen(sd, line, strlen(line));
- writen(sd, MsgRedir3, strlen(MsgRedir3));
- writen(sd, MsgRedir4, strlen(MsgRedir4));
- answerSize = strlen(MsgRedir4);
- sprintf(line, "url=http://%u.%u.%u.%u:%s/tcpbw100.html";,
- srv_addr & 0xff, (srv_addr >> 8) & 0xff,
- (srv_addr >> 16) & 0xff, (srv_addr >> 24) & 0xff,
- port);
- writen(sd, line, strlen(line));
- answerSize += strlen(line);
- writen(sd, MsgRedir5, strlen(MsgRedir5));
- answerSize += strlen(MsgRedir5);
- sprintf(line, "href=\"http://%u.%u.%u.%u:%s/tcpbw100.html\"";,
- srv_addr & 0xff, (srv_addr >> 8) & 0xff,
- (srv_addr >> 16) & 0xff, (srv_addr >> 24) & 0xff,
- port);
- writen(sd, line, strlen(line));
- answerSize += strlen(line);
- writen(sd, MsgRedir6, strlen(MsgRedir6));
- answerSize += strlen(MsgRedir6);
- log_println(3, "%s redirected to remote server [%u.%u.%u.%u:%s]",
- inet_ntoa(cli_addr->sin_addr), srv_addr & 0xff, (srv_addr >> 8) & 0xff,
- (srv_addr >> 16) & 0xff, (srv_addr >> 24) & 0xff, port);
- tt = time(0);
- logErLog(ErLogFileName, &tt, "notice", "[%s] redirected to remote server [%u.%u.%u.%u:%s]",
- inet_ntoa(cli_addr->sin_addr),
- srv_addr & 0xff, (srv_addr >> 8) & 0xff,
- (srv_addr >> 16) & 0xff, (srv_addr >> 24) & 0xff, port);
- logAcLog(AcLogFileName, &tt, inet_ntoa(cli_addr->sin_addr), lineBuf, 307, answerSize,
- useragentBuf, refererBuf);
- break;
- }
+ I2Addr serv_addr = NULL;
+ I2Addr loc_addr = NULL;
+ time_t tt;
+ char nodename[200];
+ char onenodename[200];
+ size_t nlen = 199;
+ Allowed* ptr;
+ char lineBuf[100];
+ char useragentBuf[100];
+ char refererBuf[100];
+ int answerSize;
+
+ memset(nodename, 0, 200);
+ I2AddrNodeName(addr, nodename, &nlen);
+
+ while ((n = readline(sd, buff, sizeof(buff))) > 0) {
+ if (n < 3)
+ break; /* end of html input */
+ p = (char *) strstr(buff, "GET");
+ if (p == NULL)
+ continue;
+ memset(lineBuf, 0, 100);
+ memset(useragentBuf, 0, 100);
+ memset(refererBuf, 0, 100);
+ strncpy(lineBuf, buff, 99);
+ trim(lineBuf);
+ sscanf(p + 4, "%s", filename);
+ while ((n = readline(sd, buff, sizeof(buff))) > 0) {
+ if ((p = (char *) strstr(buff, "User-Agent"))) {
+ strncpy(useragentBuf, p + 12, 99);
+ trim(useragentBuf);
+ }
+ if ((p = (char *) strstr(buff, "Referer"))) {
+ strncpy(refererBuf, p + 9, 99);
+ trim(refererBuf);
+ }
+ if (n < 3)
+ break; /* end of html input */
+ }
+ if (strcmp(filename, "/") == 0) {
+ /* feed em the default page */
+ /* strcpy(filename, Mypagefile); */
+ /* By default we now send out the redirect page */
+
+ log_println(4, "Received connection from [%s]",
nodename);
+
+ if (fed_mode == 1) {
+ struct sockaddr* csaddr;
+ csaddr = I2AddrSAddr(addr, NULL);
+ if (csaddr->sa_family == AF_INET) { /* make
the IPv4 find */
+ struct sockaddr_in* cli_addr =
(struct sockaddr_in*) csaddr;
+ find_route(cli_addr->sin_addr.s_addr,
IPlist, max_ttl);
+ for (i = 0; IPlist[i] !=
cli_addr->sin_addr.s_addr; i++) {
+ sprintf(p, "%u.%u.%u.%u",
IPlist[i] & 0xff,
+ (IPlist[i] >> 8)
& 0xff,
+ (IPlist[i] >> 16)
& 0xff,
+ (IPlist[i] >> 24)
& 0xff);
+ log_println(4, "loop IPlist[%d] =
%s", i, p);
+ if (i == max_ttl) {
+ log_println(4, "Oops,
destination not found!");
+ break;
+ }
+ }
+ /* print out last item on list */
+ sprintf(p, "%u.%u.%u.%u", IPlist[i] &
0xff,
+ (IPlist[i] >> 8) & 0xff,
(IPlist[i] >> 16) & 0xff,
+ (IPlist[i] >> 24) &
0xff);
+ log_println(4, "IPlist[%d] = %s", i,
p);
+
+ srv_addr = find_compare(IPlist, i);
+
+ /* the find_compare() routine returns
the IP address of the 'closest'
+ * NDT server. It does this by
comparing the clients address to a
+ * map of routes between all servers.
If this comparison fails, the
+ * routine returns 0. In that case,
simply use this server.
+ */
+ if (srv_addr == 0) {
+ serv_addr =
I2AddrByLocalSockFD(get_errhandle(), sd,
+ False);
+ memset(onenodename, 0, 200);
+ nlen = 199;
+ I2AddrNodeName(serv_addr,
onenodename, &nlen);
+ log_println(4,
+ "find_compare()
returned 0, reset to [%s]",
+ onenodename);
+ srv_addr = ((struct
sockaddr_in*) I2AddrSAddr(serv_addr,
+
NULL))->sin_addr.s_addr;
+ }
+
+ log_println(
+ 4,
+ "Client host [%s] should
be redirected to FLM server [%u.%u.%u.%u]",
+
inet_ntoa(cli_addr->sin_addr), srv_addr & 0xff,
+ (srv_addr >> 8) & 0xff,
(srv_addr >> 16) & 0xff,
+ (srv_addr >> 24) &
0xff);
+
+ /* At this point, the srv_addr
variable contains the IP address of the
+ * server we want to re-direct the connect to. So we should generate a
+ * new html page, and sent that back to the client. This new page will
+ * use the HTML refresh option with a short (2 second) timer to cause the
+ * client's browser to just to the
new server.
+ *
+ * RAC 3/9/04
+ */
+
+ writen(sd, MsgRedir1,
strlen(MsgRedir1));
+ writen(sd, MsgRedir2,
strlen(MsgRedir2));
+ sprintf(line,
"http://%u.%u.%u.%u:%s/tcpbw100.html";,
+ srv_addr & 0xff, (srv_addr
>> 8) & 0xff,
+ (srv_addr >> 16) & 0xff,
(srv_addr >> 24) & 0xff,
+ port);
+ writen(sd, line, strlen(line));
+ writen(sd, MsgRedir3,
strlen(MsgRedir3));
+ writen(sd, MsgRedir4,
strlen(MsgRedir4));
+ answerSize = strlen(MsgRedir4);
+ sprintf(line,
"url=http://%u.%u.%u.%u:%s/tcpbw100.html";,
+ srv_addr & 0xff, (srv_addr
>> 8) & 0xff,
+ (srv_addr >> 16) & 0xff,
(srv_addr >> 24) & 0xff,
+ port);
+ writen(sd, line, strlen(line));
+ answerSize += strlen(line);
+ writen(sd, MsgRedir5,
strlen(MsgRedir5));
+ answerSize += strlen(MsgRedir5);
+ sprintf(line,
+
"href=\"http://%u.%u.%u.%u:%s/tcpbw100.html\"";,
+ srv_addr & 0xff, (srv_addr
>> 8) & 0xff,
+ (srv_addr >> 16) & 0xff,
(srv_addr >> 24) & 0xff,
+ port);
+ writen(sd, line, strlen(line));
+ answerSize += strlen(line);
+ writen(sd, MsgRedir6,
strlen(MsgRedir6));
+ answerSize += strlen(MsgRedir6);
+ log_println(3,
+ "%s redirected to remote
server [%u.%u.%u.%u:%s]",
+
inet_ntoa(cli_addr->sin_addr), srv_addr & 0xff,
+ (srv_addr >> 8) & 0xff,
(srv_addr >> 16) & 0xff,
+ (srv_addr >> 24) &
0xff, port);
+ tt = time(0);
+ logErLog(ErLogFileName, &tt, "notice",
+ "[%s] redirected to remote
server [%u.%u.%u.%u:%s]",
+
inet_ntoa(cli_addr->sin_addr), srv_addr & 0xff,
+ (srv_addr >> 8) & 0xff,
(srv_addr >> 16) & 0xff,
+ (srv_addr >> 24) &
0xff, port);
+ logAcLog(AcLogFileName, &tt,
inet_ntoa(cli_addr->sin_addr),
+ lineBuf, 307,
answerSize, useragentBuf, refererBuf);
+ break;
+ }
#ifdef AF_INET6
- else if (csaddr->sa_family == AF_INET6) {
- struct sockaddr_in6* cli_addr = (struct sockaddr_in6*) csaddr;
- socklen_t onenode_len;
- find_route6(nodename, IP6list, max_ttl);
- for (i = 0; memcmp(IP6list[i], &cli_addr->sin6_addr, sizeof(cli_addr->sin6_addr)); i++) {
- memset(onenodename, 0, 200);
- onenode_len = 199;
- inet_ntop(AF_INET6, (void *) IP6list[i], onenodename, onenode_len);
- log_println(4, "loop IP6list[%d], = %s", i, onenodename);
- if (i == max_ttl) {
- log_println(4, "Oops, destination not found!");
- break;
- }
- }
- /* print out last item on list */
-
- if (get_debuglvl() > 3) {
- memset(onenodename, 0, 200);
- onenode_len = 199;
- inet_ntop(AF_INET6, (void *) IP6list[i], onenodename, onenode_len);
- log_println(4, "IP6list[%d] = %s", i, onenodename);
- }
-
- srv_addr = find_compare6(srv_addr6, IP6list, i);
- if (srv_addr == 0) {
- serv_addr = I2AddrByLocalSockFD(get_errhandle(), sd, False);
- memset(onenodename, 0, 200);
- nlen = 199;
- I2AddrNodeName(serv_addr, onenodename, &nlen);
- log_println(4, "find_compare6() returned 0, reset to [%s]", onenodename);
- memcpy(srv_addr6, &((struct sockaddr_in6*)I2AddrSAddr(serv_addr, NULL))->sin6_addr, 16);
- }
-
- nlen = 199;
- memset(onenodename, 0, 200);
- inet_ntop(AF_INET6, (void *) srv_addr6, onenodename, nlen);
-
- log_println(4, "Client host [%s] should be redirected to FLM server [%s]",
- nodename, onenodename);
-
- writen(sd, MsgRedir1, strlen(MsgRedir1));
- writen(sd, MsgRedir2, strlen(MsgRedir2));
- sprintf(line, "http://[%s]:%s/tcpbw100.html";, onenodename, port);
- writen(sd, line, strlen(line));
- writen(sd, MsgRedir3, strlen(MsgRedir3));
- writen(sd, MsgRedir4, strlen(MsgRedir4));
- answerSize = strlen(MsgRedir4);
- sprintf(line, "url=http://[%s]:%s/tcpbw100.html";, onenodename, port);
- writen(sd, line, strlen(line));
- answerSize += strlen(line);
- writen(sd, MsgRedir5, strlen(MsgRedir5));
- answerSize += strlen(MsgRedir5);
- sprintf(line, "href=\"http://[%s]:%s/tcpbw100.html\"";, onenodename, port);
- writen(sd, line, strlen(line));
- answerSize += strlen(line);
- writen(sd, MsgRedir6, strlen(MsgRedir6));
- answerSize += strlen(MsgRedir6);
- log_println(3, "%s redirected to remote server [[%s]:%s]", nodename, onenodename, port);
- tt = time(0);
- logErLog(ErLogFileName, &tt, "notice", "[%s] redirected to remote server [[%s]:%s]",
- nodename, onenodename, port);
- logAcLog(AcLogFileName, &tt, nodename, lineBuf, 307, answerSize,
- useragentBuf, refererBuf);
- break;
- }
+ else if (csaddr->sa_family == AF_INET6) {
+ struct sockaddr_in6* cli_addr =
(struct sockaddr_in6*) csaddr;
+ socklen_t onenode_len;
+ find_route6(nodename, IP6list,
max_ttl);
+ for (i = 0; memcmp(IP6list[i], &cli_addr->sin6_addr, sizeof(cli_addr->sin6_addr)); i++) {
+ memset(onenodename, 0, 200);
+ onenode_len = 199;
+ inet_ntop(AF_INET6, (void *)
IP6list[i], onenodename, onenode_len);
+ log_println(4, "loop IP6list[%d],
= %s", i, onenodename);
+ if (i == max_ttl) {
+ log_println(4, "Oops,
destination not found!");
+ break;
+ }
+ }
+ /* print out last item on list */
+
+ if (get_debuglvl() > 3) {
+ memset(onenodename, 0, 200);
+ onenode_len = 199;
+ inet_ntop(AF_INET6, (void *)
IP6list[i], onenodename, onenode_len);
+ log_println(4, "IP6list[%d] =
%s", i, onenodename);
+ }
+
+ srv_addr = find_compare6(srv_addr6,
IP6list, i);
+ if (srv_addr == 0) {
+ serv_addr =
I2AddrByLocalSockFD(get_errhandle(), sd, False);
+ memset(onenodename, 0, 200);
+ nlen = 199;
+ I2AddrNodeName(serv_addr,
onenodename, &nlen);
+ log_println(4, "find_compare6() returned 0, reset to [%s]", onenodename);
+ memcpy(srv_addr6, &((struct sockaddr_in6*)I2AddrSAddr(serv_addr, NULL))->sin6_addr, 16);
+ }
+
+ nlen = 199;
+ memset(onenodename, 0, 200);
+ inet_ntop(AF_INET6, (void *)
srv_addr6, onenodename, nlen);
+
+ log_println(4, "Client host [%s] should be redirected to FLM server [%s]",
+ nodename,
onenodename);
+
+ writen(sd, MsgRedir1,
strlen(MsgRedir1));
+ writen(sd, MsgRedir2,
strlen(MsgRedir2));
+ sprintf(line,
"http://[%s]:%s/tcpbw100.html";, onenodename, port);
+ writen(sd, line, strlen(line));
+ writen(sd, MsgRedir3,
strlen(MsgRedir3));
+ writen(sd, MsgRedir4,
strlen(MsgRedir4));
+ answerSize = strlen(MsgRedir4);
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/genplot.c Sun Aug 19 03:26:07
2007
+++ /branches/kkumar_code_organize/src/genplot.c Mon Oct 17 06:43:25
2011
@@ -34,633 +34,651 @@

#include "usage.h"

-char *color[16] = {"green",
- "blue",
- "orange",
- "red",
- "yellow",
- "magenta",
- "pink",
- "white",
- "black"
- };
-
-static struct option long_options[] = {
- {"both", 0, 0, 'b'},
- {"multi", 1, 0, 'm'},
- {"text", 0, 0, 't'},
- {"CurCwnd", 0, 0, 'C'},
- {"CurRwinRcvd", 0, 0, 'R'},
- {"throughput", 0, 0, 'S'},
- {"cwndtime", 0, 0, 'c'},
- {"help", 0, 0, 'h'},
- {"version", 0, 0, 'v'},
- {0, 0, 0, 0}
-};
-
-int
-checkmz(int x)
-{
- if (x == 2147483647) {
- return -1;
- }
- return x;
+char *color[16] = { "green", "blue", "orange", "red", "yellow", "magenta",
+ "pink", "white", "black" };
+
+static struct option long_options[] = { { "both", 0, 0, 'b' }, { "multi", 1, 0,
+ 'm' }, { "text", 0, 0, 't' }, { "CurCwnd", 0, 0, 'C' }, {
"CurRwinRcvd",
+ 0, 0, 'R' }, { "throughput", 0, 0, 'S' }, { "cwndtime", 0, 0,
'c' }, {
+ "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { 0, 0, 0, 0 }
};
+
+int checkmz(int x) {
+ if (x == 2147483647) {
+ return -1;
+ }
+ return x;
}

void get_title(web100_snapshot* snap, web100_log* log, web100_agent* agent,
- web100_group* group, char* title, char* remport)
-{
+ web100_group* group, char* title, char* remport) {

web100_var* var;
char buf[128];

if ((web100_snap_from_log(snap, log)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_log_open_read");
- return;
- }
-
- if ((web100_agent_find_var_and_group(agent, "LocalAddress", &group, &var)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_agent_find_var_and_group");
- exit(EXIT_FAILURE);
- }
- if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_snap_read");
- exit(EXIT_FAILURE);
- }
- strcpy(title, web100_value_to_text(web100_get_var_type(var), buf));
+ web100_perror("web100_log_open_read");
+ return;
+ }
+
+ if ((web100_agent_find_var_and_group(agent, "LocalAddress", &group,
&var))
+ != WEB100_ERR_SUCCESS) {
+ web100_perror("web100_agent_find_var_and_group");
+ exit(EXIT_FAILURE);
+ }
+ if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
+ web100_perror("web100_snap_read");
+ exit(EXIT_FAILURE);
+ }
+ strcpy(title, web100_value_to_text(web100_get_var_type(var), buf));
strncat(title, ":", 1);
- if ((web100_agent_find_var_and_group(agent, "LocalPort", &group, &var)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_agent_find_var_and_group");
- exit(EXIT_FAILURE);
- }
- if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_snap_read");
- exit(EXIT_FAILURE);
- }
- strcat(title, web100_value_to_text(web100_get_var_type(var), buf));
+ if ((web100_agent_find_var_and_group(agent, "LocalPort", &group,
&var))
+ != WEB100_ERR_SUCCESS) {
+ web100_perror("web100_agent_find_var_and_group");
+ exit(EXIT_FAILURE);
+ }
+ if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
+ web100_perror("web100_snap_read");
+ exit(EXIT_FAILURE);
+ }
+ strcat(title, web100_value_to_text(web100_get_var_type(var), buf));
strncat(title, " --> ", 5);
- if ((web100_agent_find_var_and_group(agent, "RemAddress", &group, &var)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_agent_find_var_and_group");
- exit(EXIT_FAILURE);
- }
- if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_snap_read");
- exit(EXIT_FAILURE);
- }
- strcat(title, web100_value_to_text(web100_get_var_type(var), buf));
- if ((web100_agent_find_var_and_group(agent, "RemPort", &group, &var)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_agent_find_var_and_group");
- exit(EXIT_FAILURE);
- }
- if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_snap_read");
- exit(EXIT_FAILURE);
- }
- strcpy(remport, web100_value_to_text(web100_get_var_type(var), buf));
- /* printf("%s:%s\n", title, remport); */
+ if ((web100_agent_find_var_and_group(agent, "RemAddress", &group,
&var))
+ != WEB100_ERR_SUCCESS) {
+ web100_perror("web100_agent_find_var_and_group");
+ exit(EXIT_FAILURE);
+ }
+ if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
+ web100_perror("web100_snap_read");
+ exit(EXIT_FAILURE);
+ }
+ strcat(title, web100_value_to_text(web100_get_var_type(var), buf));
+ if ((web100_agent_find_var_and_group(agent, "RemPort", &group, &var))
+ != WEB100_ERR_SUCCESS) {
+ web100_perror("web100_agent_find_var_and_group");
+ exit(EXIT_FAILURE);
+ }
+ if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
+ web100_perror("web100_snap_read");
+ exit(EXIT_FAILURE);
+ }
+ strcpy(remport, web100_value_to_text(web100_get_var_type(var), buf));
+ /* printf("%s:%s\n", title, remport); */
}

-void
-plot_var(char *list, int cnt, char *name, web100_snapshot* snap,
- web100_log* log, web100_agent* agent, web100_group* group,
- int(*func)(const int arg, const int value))
-{
-
- char *varg;
- char buf[256];
- web100_var* var;
- char varlist[256], lname[256], remport[8];
- char title[256];
- int i, first=0;
- float x1, x2, y1[32], y2[32];
- FILE *fn;
-
-
- /* Write a xplot file out to the requested file.
- * Start by extracting the connection info for the
- * page title. Then its a series of line statements
- * with the x1 y1 x2 y2 coordinates.
- */
-
- memset(lname, 0, 256);
-
- get_title(snap, log, agent, group, title, remport);
-
- if (name == NULL) {
- fn = stdout;
- strncpy(name, "Unknown", 7);
- } else {
- strncpy(lname, name, strlen(name));
- strcat(lname, ".");
- strcat(lname, remport);
- strcat(lname, ".xpl");
- fn = fopen(lname, "w");
- }
-
- fprintf(fn, "double double\ntitle\n");
- fprintf(fn, "%s:%s (%s)\n", title, remport, name);
- if ((strncmp(name, "Throughput", 10)) == 0)
- fprintf(fn, "xlabel\nTime\nylabel\nMbits/sec\n");
- else
- fprintf(fn, "xlabel\nTime\nylabel\nKilo Bytes\n");
-
- x1 = x2 = 0;
- for (i=0; i<32; i++) {
- y1[i] = 0;
- y2[i] = 0;
- }
- first = 0;
-
- for (;;) {
- if (first != 0) {
- if ((web100_snap_from_log(snap, log)) != WEB100_ERR_SUCCESS) {
- /* web100_perror("web100_log_open_read"); */
- fprintf(fn, "go\n");
- return;
- }
- }
- strncpy(varlist, list, strlen(list)+1);
- varg=strtok(varlist, ",");
- for (i=0; i<cnt; i++) {
- if ((web100_agent_find_var_and_group(agent, varg, &group, &var)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_agent_find_var_and_group");
- exit(EXIT_FAILURE);
- }
-
- if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_snap_read");
- exit(EXIT_FAILURE);
- }
-
- if (i == 0) {
- if (first == 0) {
- if (func) {
- x1 = func(i, checkmz(atoi(web100_value_to_text(web100_get_var_type(var), buf))));
- }
- else {
- x1 = checkmz(atoi(web100_value_to_text(web100_get_var_type(var), buf)));
- }
- } else {
- x1 = x2;
- }
- } else {
- if (first == 0) {
- if (func) {
- y1[i-1] = func(i, checkmz(atoi(web100_value_to_text(web100_get_var_type(var), buf))));
- }
- else {
- y1[i-1] = checkmz(atoi(web100_value_to_text(web100_get_var_type(var), buf)));
- }
- } else {
- y1[i-1] = y2[i-1];
- }
- }
- varg = strtok(NULL, ",");
- }
-
- first++;
- strncpy(varlist, list, strlen(list)+1);
- varg=strtok(varlist, ",");
- for (i=0; i<cnt; i++) {
- if ((web100_agent_find_var_and_group(agent, varg, &group, &var)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_agent_find_var_and_group");
- exit(EXIT_FAILURE);
- }
-
- if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_snap_read");
- exit(EXIT_FAILURE);
- }
-
- if (i == 0) {
- if (func) {
- x2 = func(i, checkmz(atoi(web100_value_to_text(web100_get_var_type(var), buf))));
- }
- else {
- x2 = checkmz(atoi(web100_value_to_text(web100_get_var_type(var), buf)));
- }
- }
- else {
- if (func) {
- y2[i-1] = func(i, checkmz(atoi(web100_value_to_text(web100_get_var_type(var), buf))));
- }
- else {
- y2[i-1] = checkmz(atoi(web100_value_to_text(web100_get_var_type(var), buf)));
- }
- fprintf(fn, "%s\nline %0.4f %0.4f %0.4f %0.4f\n", color[i-1], x1/1000000, y1[i-1]/1024,
- x2/1000000, y2[i-1]/1024);
- }
- varg = strtok(NULL, ",");
- }
- }
- fprintf(fn, "go\n");
+void plot_var(char *list, int cnt, char *name, web100_snapshot* snap,
+ web100_log* log, web100_agent* agent, web100_group* group,
+ int(*func)(const int arg, const int value)) {
+
+ char *varg;
+ char buf[256];
+ web100_var* var;
+ char varlist[256], lname[256], remport[8];
+ char title[256];
+ int i, first = 0;
+ float x1, x2, y1[32], y2[32];
+ FILE *fn;
+
+ /* Write a xplot file out to the requested file.
+ * Start by extracting the connection info for the
+ * page title. Then its a series of line statements
+ * with the x1 y1 x2 y2 coordinates.
+ */
+
+ memset(lname, 0, 256);
+
+ get_title(snap, log, agent, group, title, remport);
+
+ if (name == NULL) {
+ fn = stdout;
+ strncpy(name, "Unknown", 7);
+ } else {
+ strncpy(lname, name, strlen(name));
+ strcat(lname, ".");
+ strcat(lname, remport);
+ strcat(lname, ".xpl");
+ fn = fopen(lname, "w");
+ }
+
+ fprintf(fn, "double double\ntitle\n");
+ fprintf(fn, "%s:%s (%s)\n", title, remport, name);
+ if ((strncmp(name, "Throughput", 10)) == 0)
+ fprintf(fn, "xlabel\nTime\nylabel\nMbits/sec\n");
+ else
+ fprintf(fn, "xlabel\nTime\nylabel\nKilo Bytes\n");
+
+ x1 = x2 = 0;
+ for (i = 0; i < 32; i++) {
+ y1[i] = 0;
+ y2[i] = 0;
+ }
+ first = 0;
+
+ for (;;) {
+ if (first != 0) {
+ if ((web100_snap_from_log(snap, log)) !=
WEB100_ERR_SUCCESS) {
+ /* web100_perror("web100_log_open_read"); */
+ fprintf(fn, "go\n");
+ return;
+ }
+ }
+ strncpy(varlist, list, strlen(list) + 1);
+ varg = strtok(varlist, ",");
+ for (i = 0; i < cnt; i++) {
+ if ((web100_agent_find_var_and_group(agent, varg, &group,
&var))
+ != WEB100_ERR_SUCCESS) {
+
web100_perror("web100_agent_find_var_and_group");
+ exit(EXIT_FAILURE);
+ }
+
+ if ((web100_snap_read(var, snap, buf)) !=
WEB100_ERR_SUCCESS) {
+ web100_perror("web100_snap_read");
+ exit(EXIT_FAILURE);
+ }
+
+ if (i == 0) {
+ if (first == 0) {
+ if (func) {
+ x1 = func(
+ i,
+ checkmz(
+
atoi(
+
web100_value_to_text(
+
web100_get_var_type(
+
var), buf))));
+ } else {
+ x1 = checkmz(
+ atoi(
+
web100_value_to_text(
+
web100_get_var_type(var),
+
buf)));
+ }
+ } else {
+ x1 = x2;
+ }
+ } else {
+ if (first == 0) {
+ if (func) {
+ y1[i - 1] = func(
+ i,
+ checkmz(
+
atoi(
+
web100_value_to_text(
+
web100_get_var_type(
+
var), buf))));
+ } else {
+ y1[i - 1] = checkmz(
+ atoi(
+
web100_value_to_text(
+
web100_get_var_type(var),
+
buf)));
+ }
+ } else {
+ y1[i - 1] = y2[i - 1];
+ }
+ }
+ varg = strtok(NULL, ",");
+ }
+
+ first++;
+ strncpy(varlist, list, strlen(list) + 1);
+ varg = strtok(varlist, ",");
+ for (i = 0; i < cnt; i++) {
+ if ((web100_agent_find_var_and_group(agent, varg, &group,
&var))
+ != WEB100_ERR_SUCCESS) {
+
web100_perror("web100_agent_find_var_and_group");
+ exit(EXIT_FAILURE);
+ }
+
+ if ((web100_snap_read(var, snap, buf)) !=
WEB100_ERR_SUCCESS) {
+ web100_perror("web100_snap_read");
+ exit(EXIT_FAILURE);
+ }
+
+ if (i == 0) {
+ if (func) {
+ x2 = func(
+ i,
+ checkmz(
+ atoi(
+
web100_value_to_text(
+
web100_get_var_type(var),
+
buf))));
+ } else {
+ x2 = checkmz(
+ atoi(
+
web100_value_to_text(
+
web100_get_var_type(var), buf)));
+ }
+ } else {
+ if (func) {
+ y2[i - 1] = func(
+ i,
+ checkmz(
+ atoi(
+
web100_value_to_text(
+
web100_get_var_type(var),
+
buf))));
+ } else {
+ y2[i - 1] = checkmz(
+ atoi(
+
web100_value_to_text(
+
web100_get_var_type(var), buf)));
+ }
+ fprintf(fn, "%s\nline %0.4f %0.4f %0.4f
%0.4f\n", color[i - 1],
+ x1 / 1000000, y1[i - 1] /
1024, x2 / 1000000,
+ y2[i - 1] / 1024);
+ }
+ varg = strtok(NULL, ",");
+ }
+ }
+ fprintf(fn, "go\n");

}

-void
-plot_cwndtime(char *name, web100_snapshot* snap,
- web100_log* log, web100_agent* agent, web100_group* group)
-{
- double SndLimTimeRwin = 0, SndLimTimeSender = 0;
- char buf[256];
- web100_var* var;
- char lname[256], remport[8];
- char title[256];
- char* variables[] = {"Duration", "SndLimTimeRwin", "SndLimTimeSender", "SndLimTimeCwnd"};
- int i, first=0;
- double x1, x2, y1, y2;
- FILE *fn;
-
- memset(lname, 0, 256);
-
- get_title(snap, log, agent, group, title, remport);
-
- if (name == NULL) {
- fn = stdout;
- strncpy(name, "Unknown", 7);
- } else {
- strncpy(lname, name, strlen(name));
- strcat(lname, ".");
- strcat(lname, remport);
- strcat(lname, ".xpl");
- fn = fopen(lname, "w");
- }
-
- fprintf(fn, "double double\ntitle\n");
- fprintf(fn, "%s:%s (%s)\n", title, remport, name);
- fprintf(fn, "xlabel\nTime\nylabel\nPercentage\n");
-
- x1 = x2 = y1 = y2 = 0;
- first = 0;
-
- for (;;) {
- if (first != 0) {
- if ((web100_snap_from_log(snap, log)) != WEB100_ERR_SUCCESS) {
- fprintf(fn, "go\n");
- return;
- }
- }
- for (i=0; i<4; i++) {
- if ((web100_agent_find_var_and_group(agent, variables[i], &group, &var)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_agent_find_var_and_group");
- exit(EXIT_FAILURE);
- }
-
- if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_snap_read");
- exit(EXIT_FAILURE);
- }
-
- if (i == 0) {
- if (first == 0) {
- x1 = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- } else {
- x1 = x2;
- }
- }
- else if (i == 1) {
- if (first == 0) {
- SndLimTimeRwin = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- }
- }
- else if (i == 2) {
- if (first == 0) {
- SndLimTimeSender = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- }
- }
- else {
- if (first == 0) {
- y1 = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- y1 = y1 / (SndLimTimeRwin + SndLimTimeSender + y1);
- }
- else {
- y1 = y2;
- }
- }
- }
-
- first++;
- for (i=0; i<4; i++) {
- if ((web100_agent_find_var_and_group(agent, variables[i], &group, &var)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_agent_find_var_and_group");
- exit(EXIT_FAILURE);
- }
-
- if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_snap_read");
- exit(EXIT_FAILURE);
- }
-
- if (i == 0) {
- x2 = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- }
- else if (i == 1) {
- SndLimTimeRwin = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- }
- else if (i == 2) {
- SndLimTimeSender = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- }
- else {
- y2 = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- y2 = y2 / (SndLimTimeRwin + SndLimTimeSender + y2);
- fprintf(fn, "%s\nline %0.4f %0.4f %0.4f %0.4f\n", color[i-1], x1/1000000, y1,
- x2/1000000, y2);
- }
- }
- }
- fprintf(fn, "go\n");
+void plot_cwndtime(char *name, web100_snapshot* snap, web100_log* log,
+ web100_agent* agent, web100_group* group) {
+ double SndLimTimeRwin = 0, SndLimTimeSender = 0;
+ char buf[256];
+ web100_var* var;
+ char lname[256], remport[8];
+ char title[256];
+ char* variables[] = { "Duration", "SndLimTimeRwin",
"SndLimTimeSender",
+ "SndLimTimeCwnd" };
+ int i, first = 0;
+ double x1, x2, y1, y2;
+ FILE *fn;
+
+ memset(lname, 0, 256);
+
+ get_title(snap, log, agent, group, title, remport);
+
+ if (name == NULL) {
+ fn = stdout;
+ strncpy(name, "Unknown", 7);
+ } else {
+ strncpy(lname, name, strlen(name));
+ strcat(lname, ".");
+ strcat(lname, remport);
+ strcat(lname, ".xpl");
+ fn = fopen(lname, "w");
+ }
+
+ fprintf(fn, "double double\ntitle\n");
+ fprintf(fn, "%s:%s (%s)\n", title, remport, name);
+ fprintf(fn, "xlabel\nTime\nylabel\nPercentage\n");
+
+ x1 = x2 = y1 = y2 = 0;
+ first = 0;
+
+ for (;;) {
+ if (first != 0) {
+ if ((web100_snap_from_log(snap, log)) !=
WEB100_ERR_SUCCESS) {
+ fprintf(fn, "go\n");
+ return;
+ }
+ }
+ for (i = 0; i < 4; i++) {
+ if ((web100_agent_find_var_and_group(agent, variables[i],
&group,
+ &var)) != WEB100_ERR_SUCCESS) {
+
web100_perror("web100_agent_find_var_and_group");
+ exit(EXIT_FAILURE);
+ }
+
+ if ((web100_snap_read(var, snap, buf)) !=
WEB100_ERR_SUCCESS) {
+ web100_perror("web100_snap_read");
+ exit(EXIT_FAILURE);
+ }
+
+ if (i == 0) {
+ if (first == 0) {
+ x1 = atoi(
+
web100_value_to_text(web100_get_var_type(var),
+ buf));
+ } else {
+ x1 = x2;
+ }
+ } else if (i == 1) {
+ if (first == 0) {
+ SndLimTimeRwin = atoi(
+
web100_value_to_text(web100_get_var_type(var),
+ buf));
+ }
+ } else if (i == 2) {
+ if (first == 0) {
+ SndLimTimeSender = atoi(
+
web100_value_to_text(web100_get_var_type(var),
+ buf));
+ }
+ } else {
+ if (first == 0) {
+ y1 = atoi(
+
web100_value_to_text(web100_get_var_type(var),
+ buf));
+ y1 = y1 / (SndLimTimeRwin +
SndLimTimeSender + y1);
+ } else {
+ y1 = y2;
+ }
+ }
+ }
+
+ first++;
+ for (i = 0; i < 4; i++) {
+ if ((web100_agent_find_var_and_group(agent, variables[i],
&group,
+ &var)) != WEB100_ERR_SUCCESS) {
+
web100_perror("web100_agent_find_var_and_group");
+ exit(EXIT_FAILURE);
+ }
+
+ if ((web100_snap_read(var, snap, buf)) !=
WEB100_ERR_SUCCESS) {
+ web100_perror("web100_snap_read");
+ exit(EXIT_FAILURE);
+ }
+
+ if (i == 0) {
+ x2 =
atoi(web100_value_to_text(web100_get_var_type(var), buf));
+ } else if (i == 1) {
+ SndLimTimeRwin = atoi(
+
web100_value_to_text(web100_get_var_type(var), buf));
+ } else if (i == 2) {
+ SndLimTimeSender = atoi(
+
web100_value_to_text(web100_get_var_type(var), buf));
+ } else {
+ y2 =
atoi(web100_value_to_text(web100_get_var_type(var), buf));
+ y2 = y2 / (SndLimTimeRwin + SndLimTimeSender
+ y2);
+ fprintf(fn, "%s\nline %0.4f %0.4f %0.4f
%0.4f\n", color[i - 1],
+ x1 / 1000000, y1, x2 /
1000000, y2);
+ }
+ }
+ }
+ fprintf(fn, "go\n");

}

-void
-print_var(char *varlist, web100_snapshot* snap, web100_log* log,
- web100_agent* agent, web100_group* group, void(*func)(const int arg, const int value))
-{
-
- char *varg, savelist[256], *text;
- char buf[256], title[256], remport[8];
- int i, j;
- web100_var* var;
- FILE* fn;
-
- fn = stdout;
- get_title(snap, log, agent, group, title, remport);
- fprintf(fn, "Extracting Data from %s:%s connection\n\n", title, remport);
-
- strncpy(savelist, varlist, strlen(varlist)+1);
- printf("Index\t");
- varg = strtok(varlist, ",");
- for (j=0; ;j++) {
- if (varg == NULL)
- break;
- if (func) {
- func(-1, j);
- }
- else {
- printf("%10s\t", varg);
- }
- varg = strtok(NULL, ",");
- }
- printf("\n");
- for (i=0; ; i++) {
- if ((web100_snap_from_log(snap, log)) != WEB100_ERR_SUCCESS) {
- /* web100_perror("web100_log_open_read"); */
- printf("-------------- End Of Data --------------\n\n");
- return;
- }
- printf("%5d\t", i);
-
- strncpy(varlist, savelist, strlen(savelist)+1);
- varg=strtok(varlist, ",");
- for (j=0; ; j++) {
- if (varg == NULL)
- break;
- if ((web100_agent_find_var_and_group(agent, varg, &group, &var)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_agent_find_var_and_group");
- exit(EXIT_FAILURE);
- }
-
- if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
- web100_perror("web100_snap_read");
- exit(EXIT_FAILURE);
- }
- if (func) {
- func(j, atoi(web100_value_to_text(web100_get_var_type(var), buf)));
- }
- else {
- text = web100_value_to_text(web100_get_var_type(var), buf);
- if (strcmp(text, "4294966376") == 0) {
- printf("%10s\t", "-1");
- }
- else {
- printf("%10s\t", text);
- }
- }
- varg = strtok(NULL, ",");
- }
- printf("\n");
- }
+void print_var(char *varlist, web100_snapshot* snap, web100_log* log,
+ web100_agent* agent, web100_group* group,
+ void(*func)(const int arg, const int value)) {
+
+ char *varg, savelist[256], *text;
+ char buf[256], title[256], remport[8];
+ int i, j;
+ web100_var* var;
+ FILE* fn;
+
+ fn = stdout;
+ get_title(snap, log, agent, group, title, remport);
+ fprintf(fn, "Extracting Data from %s:%s connection\n\n", title,
remport);
+
+ strncpy(savelist, varlist, strlen(varlist) + 1);
+ printf("Index\t");
+ varg = strtok(varlist, ",");
+ for (j = 0;; j++) {
+ if (varg == NULL)
+ break;
+ if (func) {
+ func(-1, j);
+ } else {
+ printf("%10s\t", varg);
+ }
+ varg = strtok(NULL, ",");
+ }
+ printf("\n");
+ for (i = 0;; i++) {
+ if ((web100_snap_from_log(snap, log)) != WEB100_ERR_SUCCESS) {
+ /* web100_perror("web100_log_open_read"); */
+ printf("-------------- End Of Data
--------------\n\n");
+ return;
+ }
+ printf("%5d\t", i);
+
+ strncpy(varlist, savelist, strlen(savelist) + 1);
+ varg = strtok(varlist, ",");
+ for (j = 0;; j++) {
+ if (varg == NULL)
+ break;
+ if ((web100_agent_find_var_and_group(agent, varg, &group,
&var))
+ != WEB100_ERR_SUCCESS) {
+
web100_perror("web100_agent_find_var_and_group");
+ exit(EXIT_FAILURE);
+ }
+
+ if ((web100_snap_read(var, snap, buf)) !=
WEB100_ERR_SUCCESS) {
+ web100_perror("web100_snap_read");
+ exit(EXIT_FAILURE);
+ }
+ if (func) {
+ func(
+ j,
+ atoi(
+
web100_value_to_text(web100_get_var_type(var),
+
buf)));
+ } else {
+ text =
web100_value_to_text(web100_get_var_type(var), buf);
+ if (strcmp(text, "4294966376") == 0) {
+ printf("%10s\t", "-1");
+ } else {
+ printf("%10s\t", text);
+ }
+ }
+ varg = strtok(NULL, ",");
+ }
+ printf("\n");
+ }

}

/* workers */
-void
-throughput(const int arg, const int value)
-{
- static int duration;
-
- if (arg == -1) {
- if (value) {
- printf("%10s\t", "Throughput (kB/s)");
- }
- else {
- printf("%10s\t", "Duration");
- }
- return;
- }
-
- if (!arg) { /* duration */
- duration = value;
- printf("%10d\t", value);
- }
- else { /* DataBytesOut */
- printf("%10.2f", ((8*((double) value)) / ((double) duration)) * 1000000.0 / 1024.0 / 1024.0);
- }
+void throughput(const int arg, const int value) {
+ static int duration;
+
+ if (arg == -1) {
+ if (value) {
+ printf("%10s\t", "Throughput (kB/s)");
+ } else {
+ printf("%10s\t", "Duration");
+ }
+ return;
+ }
+
+ if (!arg) { /* duration */
+ duration = value;
+ printf("%10d\t", value);
+ } else { /* DataBytesOut */
+ printf(
+ "%10.2f",
+ ((8 * ((double) value)) / ((double)
duration)) * 1000000.0
+ / 1024.0 / 1024.0);
+ }
}

-int
-throughputPlot(const int arg, const int value)
-{
- static int duration;
-
- if (!arg) { /* duration */
- duration = value;
- return value;
- }
- else { /* DataBytesOut */
- return (((double) value) / ((double) duration)) * 1000000.0;
- }
+int throughputPlot(const int arg, const int value) {
+ static int duration;
+
+ if (!arg) { /* duration */
+ duration = value;
+ return value;
+ } else { /* DataBytesOut */
+ return (((double) value) / ((double) duration)) * 1000000.0;
+ }
}

-void
-cwndtime(const int arg, const int value)
-{
- static int SndLimTimeRwin, SndLimTimeSender;
-
- if (arg == -1) {
- if (value == 0) {
- printf("%10s\t", "Duration");
- }
- else if (value == 3) {
- printf("%10s\t", "CwndTime (%% of total time)");
- }
- return;
- }
-
- if (arg == 0) { /* duration */
- printf("%10d\t", value);
- }
- else if (arg == 1) { /* SndLimTimeRwin */
- SndLimTimeRwin = value;
- }
- else if (arg == 2) { /* SndLimTimeSender */
- SndLimTimeSender = value;
- }
- else { /* SndLimTimeCwnd */
- printf("%10.2f", ((double) value) /
- (((double) SndLimTimeRwin) + ((double) SndLimTimeSender) + ((double) value)));
- }
+void cwndtime(const int arg, const int value) {
+ static int SndLimTimeRwin, SndLimTimeSender;
+
+ if (arg == -1) {
+ if (value == 0) {
+ printf("%10s\t", "Duration");
+ } else if (value == 3) {
+ printf("%10s\t", "CwndTime (%% of total time)");
+ }
+ return;
+ }
+
+ if (arg == 0) { /* duration */
+ printf("%10d\t", value);
+ } else if (arg == 1) { /* SndLimTimeRwin */
+ SndLimTimeRwin = value;
+ } else if (arg == 2) { /* SndLimTimeSender */
+ SndLimTimeSender = value;
+ } else { /* SndLimTimeCwnd */
+ printf(
+ "%10.2f",
+ ((double) value)
+ / (((double) SndLimTimeRwin)
+ + ((double)
SndLimTimeSender) + ((double) value)));
+ }
}

/* --- */

-int
-main(int argc, char** argv)
-{
- web100_agent* agent;
- web100_connection* conn;
- web100_group* group;
- web100_log* log;
- web100_snapshot* snap;
- char fn[128];
- char *varlist=NULL, list[1024];
- char *varg;
- int j, c, plotspd = 0, plotuser = 0;
- int plotboth = 0, plotcwnd = 0, plotrwin = 0;
- int plotcwndtime = 0;
- int k, txt = 0;
-
- while ((c = getopt_long(argc, argv, "hCScRbtm:v", long_options, 0)) != -1) {
- switch (c) {
- case 'b':
- plotboth = 1;
- break;
- case 'h':
- genplot_long_usage("ANL/Internet2 NDT version " VERSION " (genplot)", argv[0]);
- break;
- case 'v':
- printf("ANL/Internet2 NDT version %s (genplot)\n", VERSION);
- exit(0);
- break;
- case 't':
- txt = 1;
- break;
- case 'C':
- plotcwnd = 1;
- break;
- case 'R':
- plotrwin = 1;
- break;
- case 'S':
- plotspd = 1;
- break;
- case 'c':
- plotcwndtime = 1;
- break;
- case 'm':
- varlist = optarg;
- plotuser = 1;
- break;
- }
- }
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/heuristics.h Mon Oct 17 06:31:32
2011
+++ /branches/kkumar_code_organize/src/heuristics.h Mon Oct 17 06:43:25
2011
@@ -32,7 +32,7 @@
int MaxRwinRcvd, int MaxCwnd, double *rwin, double *swin,
double *cwin);

// calculate RTO Idle time
-double calc_RTOIdle (int timeouts, int CurrentRTO, double totaltime);
+double calc_RTOIdle(int timeouts, int CurrentRTO, double totaltime);

// calculate total test time for S_C test
int calc_totaltesttime(int SndLimTimeRwin, int SndLimTimeCwnd,
=======================================
--- /branches/kkumar_code_organize/src/logging.c Mon Oct 17 06:31:32
2011
+++ /branches/kkumar_code_organize/src/logging.c Mon Oct 17 06:43:25
2011
@@ -369,7 +369,6 @@

return j - 1;
}
-

/**
* Log in a single key-value pair as a particular event
@@ -922,7 +921,6 @@
fclose(fp);
}
}
-

/** Create directories for snap/tcp trace log files, and meta files.
*
@@ -977,7 +975,7 @@
strlcat(dirnamedestarg, "/", destnamearrsize);
sprintf(dir, "%s", finalsuffix);
strlcat(dirnamedestarg, dir, destnamearrsize);
-log_println(0,"end named_log_create %s", dirnamedestarg);
+ log_println(0, "end named_log_create %s", dirnamedestarg);
}

/** Create directories for snap/tcp trace log files, and meta files.
=======================================
--- /branches/kkumar_code_organize/src/logging.h Mon Oct 17 06:31:32
2011
+++ /branches/kkumar_code_organize/src/logging.h Mon Oct 17 06:43:25
2011
@@ -15,13 +15,11 @@
#include <sys/types.h>
#include "ndtptestconstants.h"
#include "runningtest.h" // protocol validation
-
#define LOGFILE "web100srv.log" /* Name of log file */
#define PROTOLOGFILE "web100srvprotocol.log" /* Name of protocol validation log file */
#define PROTOLOGPREFIX "web100srvprotocol_" /* prefix for protocol validation log file */
#define PROTOLOGSUFFIX ".log" /* suffix for protocol validation log file */
#define FILENAME_SIZE 256 // This could have been in utils.h, but will be used immediately here
-
void log_init(char* progname, int debuglvl);
void set_debuglvl(int debuglvl);
void set_logfile(char* filename);
@@ -36,21 +34,20 @@
time_t get_timestamp();
long int get_utimestamp();
char * get_ISOtime(char * isoTime, int isoTimeArrSize);
-void get_YYYY(char * year);
-void get_MM(char * month);
-void get_DD(char * day);
+void get_YYYY(char * year);
+void get_MM(char * month);
+void get_DD(char * day);
char * DataDirName;

int zlib_def(char *src_fn);

-
/**
* Format used to exchange meta test data between client->server.
* */
struct metaentry {
- char key[64]; // key name
- char value[256]; // value associated with this meta key
- struct metaentry* next; // pointer to next link
+ char key[64]; // key name
+ char value[256]; // value associated with this meta key
+ struct metaentry* next; // pointer to next link
};

/**
@@ -59,25 +56,25 @@
* meta data file created for every session
* */
struct metadata {
- char c2s_snaplog[FILENAME_SIZE]; // C->S test Snaplog file name, changed to 256 to avoid truncation
- char c2s_ndttrace[FILENAME_SIZE]; // C->S NDT trace file name, changed to 256 to avoid truncation
- char s2c_snaplog[FILENAME_SIZE]; // S->C test Snaplog file name, changed to 256 to avoid truncation
- char s2c_ndttrace[FILENAME_SIZE]; // S->C NDT trace file name, changed to 256 to avoid truncation
- char CPU_time[64]; // CPU time file
- char summary[256]; // Summary data
- char date[32]; // Date and,
- char time[16]; // time
- char client_ip[64]; // Client IP Address
- struct sockaddr_storage c_addr; // client socket details, not logged
- char client_name[64]; // client's host-name
- char client_os[32]; // client OS name
- char client_browser[32]; // client's browser name
- int ctl_port; // ? todo map use
- char server_ip[64]; // server IP address
- char server_name[64]; // server's host-name
- char server_os[32]; // server os name
- int family; // IP family
- struct metaentry* additional; // all other additional data
+ char c2s_snaplog[FILENAME_SIZE]; // C->S test Snaplog file name, changed to 256 to avoid truncation
+ char c2s_ndttrace[FILENAME_SIZE]; // C->S NDT trace file name, changed to 256 to avoid truncation
+ char s2c_snaplog[FILENAME_SIZE]; // S->C test Snaplog file name, changed to 256 to avoid truncation
+ char s2c_ndttrace[FILENAME_SIZE]; // S->C NDT trace file name, changed to 256 to avoid truncation
+ char CPU_time[64]; // CPU time file
+ char summary[256]; // Summary data
+ char date[32]; // Date and,
+ char time[16]; // time
+ char client_ip[64]; // Client IP Address
+ struct sockaddr_storage c_addr; // client socket details, not logged
+ char client_name[64]; // client's host-name
+ char client_os[32]; // client OS name
+ char client_browser[32]; // client's browser name
+ int ctl_port; // ? todo map use
+ char server_ip[64]; // server IP address
+ char server_name[64]; // server's host-name
+ char server_os[32]; // server os name
+ int family; // IP family
+ struct metaentry* additional; // all other additional data
};

void set_protologdir(char* dirname);
@@ -87,21 +84,24 @@
char* get_protologdir();
//char *createprotologfilename (char* textappendarg);
void enableprotocollogging();
-char *createprotologfilename (char* client_ip, char* textappendarg);
+char *createprotologfilename(char* client_ip, char* textappendarg);
void create_named_logdir(char *dirnamedestarg, int destnamearrsize,
- char *finalsuffix);
-void create_client_logdir(struct sockaddr *cliaddrarg, socklen_t clilenarg, char *dirnamedestarg, int destnamearrsize,
- char *finalsuffix, int finalsuffixsize) ;
+ char *finalsuffix);
+void create_client_logdir(struct sockaddr *cliaddrarg, socklen_t clilenarg,
+ char *dirnamedestarg, int destnamearrsize, char *finalsuffix,
+ int finalsuffixsize);

void protolog_printgeneric(const char* key, const char* val);
-void protolog_status(int pid, enum TEST_ID testid, enum TEST_STATUS_INT teststatus);
-void protolog_sendprintln (const int type, void* msg, const int len, const int processid, const int ctlSocket);
-void protolog_rcvprintln (const int type, void* msg, const int len, const int processid, const int ctlSocket);
-void protolog_procstatus(int pid, enum TEST_ID testidarg, enum PROCESS_TYPE_INT procidarg,
- enum
PROCESS_STATUS_INT teststatusarg);
-void protolog_procstatuslog(int pid, enum TEST_ID testidarg,
- enum PROCESS_TYPE_INT procidarg,
- enum PROCESS_STATUS_INT
teststatusarg);
+void protolog_status(int pid, enum TEST_ID testid,
+ enum TEST_STATUS_INT teststatus);
+void protolog_sendprintln(const int type, void* msg, const int len,
+ const int processid, const int ctlSocket);
+void protolog_rcvprintln(const int type, void* msg, const int len,
+ const int processid, const int ctlSocket);
+void protolog_procstatus(int pid, enum TEST_ID testidarg,
+ enum PROCESS_TYPE_INT procidarg, enum PROCESS_STATUS_INT
teststatusarg);
+void protolog_procstatuslog(int pid, enum TEST_ID testidarg,
+ enum PROCESS_TYPE_INT procidarg, enum PROCESS_STATUS_INT
teststatusarg);

struct metadata meta;
#endif
=======================================
--- /branches/kkumar_code_organize/src/mrange.c Fri Oct 14 13:52:19 2011
+++ /branches/kkumar_code_organize/src/mrange.c Mon Oct 17 06:43:25 2011
@@ -15,9 +15,9 @@
#include "strlutils.h"

typedef struct range {
- int min; /**< lower end of the range */
- int max; /**< upper end of the range */
- struct range *next; /**< pointer to the next range member */
+ int min; /**< lower end of the range */
+ int max; /**< upper end of the range */
+ struct range *next; /**< pointer to the next range member */
} Range;

static Range* mrange_root;
@@ -31,65 +31,62 @@
* 1 - there was a syntax error in the string
*/

-int
-mrange_parse(char* text)
-{
- char tmp[300];
- char* ptr, *sptr;
- Range* mr_ptr;
-
- assert(text);
-
- memset(tmp, 0, 300);
- if (strlen(text) > 299) {
- return 1;
- }
- //strcpy(tmp, text);
- strlcpy(tmp, text, sizeof(tmp));
- // tokenize based on a "," character.
- // An example of the string : 2003:3000,4000:5000
- ptr = strtok(tmp, ",");
- while (ptr != NULL) { // tokens found
- if ((sptr = strchr(ptr, ':')) != NULL) { // also found a ":" character,
-
// with sptr pointing to its location
- *sptr++ = 0;
- if (strchr(sptr, ':') != NULL) { // should not find any more range
- return 1;
- }
- }
- else {
- sptr = ptr;
- }
- if ((mr_ptr = malloc(sizeof(Range))) == NULL) {
- log_println(0, "FATAL: cannot allocate memory");
- return 1;
- }
- if (*ptr == 0) {
- ptr = "1";
- }
- // Check if the input string is within range and store
- // result as "minimum"
- // For ex: Is 2003 in a string like "2003:4000" within integer range ?
- // If not, free the memory allocated to store the range and return
- if (check_rint(ptr, &mr_ptr->min, 1, MAX_TCP_PORT)) {
- free(mr_ptr);
- return 1;
- }
- if (*sptr == 0) {
- sptr = MAX_TCP_PORT_STR;
- }
- // now validate if "maximum" is within range and store
- // result as "maximum"
- if (check_rint(sptr, &mr_ptr->max, 1, MAX_TCP_PORT)) {
- free(mr_ptr);
- return 1; // if invalid range, free allocated memory and return
- }
- mr_ptr->next = mrange_root;
- mrange_root = mr_ptr; // ready to point to next member
- ptr = strtok(NULL, ",");
- }
- free(mr_ptr);
- return 0;
+int mrange_parse(char* text) {
+ char tmp[300];
+ char* ptr, *sptr;
+ Range* mr_ptr;
+
+ assert(text);
+
+ memset(tmp, 0, 300);
+ if (strlen(text) > 299) {
+ return 1;
+ }
+ //strcpy(tmp, text);
+ strlcpy(tmp, text, sizeof(tmp));
+ // tokenize based on a "," character.
+ // An example of the string : 2003:3000,4000:5000
+ ptr = strtok(tmp, ",");
+ while (ptr != NULL) { // tokens found
+ if ((sptr = strchr(ptr, ':')) != NULL) { // also found a ":"
character,
+
// with sptr pointing to its location
+ *sptr++ = 0;
+ if (strchr(sptr, ':') != NULL) { // should not find
any more range
+ return 1;
+ }
+ } else {
+ sptr = ptr;
+ }
+ if ((mr_ptr = malloc(sizeof(Range))) == NULL) {
+ log_println(0, "FATAL: cannot allocate memory");
+ return 1;
+ }
+ if (*ptr == 0) {
+ ptr = "1";
+ }
+ // Check if the input string is within range and store
+ // result as "minimum"
+ // For ex: Is 2003 in a string like "2003:4000" within
integer range ?
+ // If not, free the memory allocated to store the range and
return
+ if (check_rint(ptr, &mr_ptr->min, 1, MAX_TCP_PORT)) {
+ free(mr_ptr);
+ return 1;
+ }
+ if (*sptr == 0) {
+ sptr = MAX_TCP_PORT_STR;
+ }
+ // now validate if "maximum" is within range and store
+ // result as "maximum"
+ if (check_rint(sptr, &mr_ptr->max, 1, MAX_TCP_PORT)) {
+ free(mr_ptr);
+ return 1; // if invalid range, free allocated memory
and return
+ }
+ mr_ptr->next = mrange_root;
+ mrange_root = mr_ptr; // ready to point to next member
+ ptr = strtok(NULL, ",");
+ }
+ free(mr_ptr);
+ return 0;
}

/**
@@ -104,31 +101,30 @@
*/

char*
-mrange_next(char* port)
-{
- int val;
- Range* ptr;
-
- assert(port);
-
- if (check_rint(port, &val, 0, MAX_TCP_PORT)) { // check if valid
- log_println(0, "WARNING: invalid port number");
- sprintf(port, RESERVED_PORT);
- return port;
- }
- val++;
- while (val <= MAX_TCP_PORT) { // Maximum port number not exceeded
- ptr = mrange_root;
- while (ptr != NULL) { // While there is some data
- if ((val >= ptr->min) && (val <= ptr->max)) { // check range
-
// and return port if valid
- sprintf(port, "%d", val);
- return port;
- }
- ptr = ptr->next;
- }
- val++;
- }
- sprintf(port, RESERVED_PORT);
- return port;
-}
+mrange_next(char* port) {
+ int val;
+ Range* ptr;
+
+ assert(port);
+
+ if (check_rint(port, &val, 0, MAX_TCP_PORT)) { // check if valid
+ log_println(0, "WARNING: invalid port number");
+ sprintf(port, RESERVED_PORT);
+ return port;
+ }
+ val++;
+ while (val <= MAX_TCP_PORT) { // Maximum port number not exceeded
+ ptr = mrange_root;
+ while (ptr != NULL) { // While there is some data
+ if ((val >= ptr->min) && (val <= ptr->max)) { //
check range
+
// and return port if valid
+ sprintf(port, "%d", val);
+ return port;
+ }
+ ptr = ptr->next;
+ }
+ val++;
+ }
+ sprintf(port, RESERVED_PORT);
+ return port;
+}
=======================================
--- /branches/kkumar_code_organize/src/ndt_odbc.c Fri Oct 14 13:52:19
2011
+++ /branches/kkumar_code_organize/src/ndt_odbc.c Mon Oct 17 06:43:25
2011
@@ -23,75 +23,75 @@
SQLHDBC dbc;
SQLHSTMT stmt = NULL;
char* ctStmt_1 = "CREATE TABLE ndt_test_results ("
- "spds1 TEXT,"
- "spds2 TEXT,"
- "spds3 TEXT,"
- "spds4 TEXT,"
- "runave1 FLOAT,"
- "runave2 FLOAT,"
- "runave3 FLOAT,"
- "runave4 FLOAT,"
- "cputimelog TEXT,"
- "snaplog TEXT,"
- "c2s_snaplog TEXT,"
- "hostName TEXT,"
- "testPort INT,"
- "date TEXT,"
- "rmt_host TEXT,";
+"spds1 TEXT,"
+"spds2 TEXT,"
+"spds3 TEXT,"
+"spds4 TEXT,"
+"runave1 FLOAT,"
+"runave2 FLOAT,"
+"runave3 FLOAT,"
+"runave4 FLOAT,"
+"cputimelog TEXT,"
+"snaplog TEXT,"
+"c2s_snaplog TEXT,"
+"hostName TEXT,"
+"testPort INT,"
+"date TEXT,"
+"rmt_host TEXT,";
char* ctStmt_2 = "s2c2spd INT,"
- "s2cspd INT,"
- "c2sspd INT,"
- "Timeouts INT,"
- "SumRTT INT,"
- "CountRTT INT,"
- "PktsRetrans INT,"
- "FastRetran INT,"
- "DataPktsOut INT,"
- "AckPktsOut INT,"
- "CurrentMSS INT,"
- "DupAcksIn INT,"
- "AckPktsIn INT,"
- "MaxRwinRcvd INT,"
- "Sndbuf INT,"
- "MaxCwnd INT,";
+"s2cspd INT,"
+"c2sspd INT,"
+"Timeouts INT,"
+"SumRTT INT,"
+"CountRTT INT,"
+"PktsRetrans INT,"
+"FastRetran INT,"
+"DataPktsOut INT,"
+"AckPktsOut INT,"
+"CurrentMSS INT,"
+"DupAcksIn INT,"
+"AckPktsIn INT,"
+"MaxRwinRcvd INT,"
+"Sndbuf INT,"
+"MaxCwnd INT,";
char* ctStmt_3 = "SndLimTimeRwin INT,"
- "SndLimTimeCwnd INT,"
- "SndLimTimeSender INT,"
- "DataBytesOut INT,"
- "SndLimTransRwin INT,"
- "SndLimTransCwnd INT,"
- "SndLimTransSender INT,"
- "MaxSsthresh INT,"
- "CurrentRTO INT,"
- "CurrentRwinRcvd INT,"
- "link INT,"
- "mismatch INT,"
- "bad_cable INT,"
- "half_duplex INT,"
- "congestion INT,"
- "c2sdata INT,";
+"SndLimTimeCwnd INT,"
+"SndLimTimeSender INT,"
+"DataBytesOut INT,"
+"SndLimTransRwin INT,"
+"SndLimTransCwnd INT,"
+"SndLimTransSender INT,"
+"MaxSsthresh INT,"
+"CurrentRTO INT,"
+"CurrentRwinRcvd INT,"
+"link INT,"
+"mismatch INT,"
+"bad_cable INT,"
+"half_duplex INT,"
+"congestion INT,"
+"c2sdata INT,";
char* ctStmt_4 = "c2sack INT,"
- "s2cdata INT,"
- "s2cack INT,"
- "CongestionSignals INT,"
- "PktsOut INT,"
- "MinRTT INT,"
- "RcvWinScale INT,"
- "autotune INT,"
- "CongAvoid INT,"
- "CongestionOverCount INT,"
- "MaxRTT INT,"
- "OtherReductions INT,"
- "CurTimeoutCount INT,"
- "AbruptTimeouts INT,"
- "SendStall INT,"
- "SlowStart INT,"
- "SubsequentTimeouts INT,"
- "ThruBytesAcked INT,"
- "minPeak INT,"
- "maxPeak INT,"
- "peaks INT"
- ");";
+"s2cdata INT,"
+"s2cack INT,"
+"CongestionSignals INT,"
+"PktsOut INT,"
+"MinRTT INT,"
+"RcvWinScale INT,"
+"autotune INT,"
+"CongAvoid INT,"
+"CongestionOverCount INT,"
+"MaxRTT INT,"
+"OtherReductions INT,"
+"CurTimeoutCount INT,"
+"AbruptTimeouts INT,"
+"SendStall INT,"
+"SlowStart INT,"
+"SubsequentTimeouts INT,"
+"ThruBytesAcked INT,"
+"minPeak INT,"
+"maxPeak INT,"
+"peaks INT"
+");";
char createTableStmt[2048];

/**
@@ -105,24 +105,24 @@
static void
extract_error(char *fn, SQLHANDLE handle, SQLSMALLINT type)
{
- SQLINTEGER i = 0;
- SQLINTEGER native;
- SQLCHAR state[ 7 ];
- SQLCHAR text[256];
- SQLSMALLINT len;
- SQLRETURN ret;
-
- log_println(2, "\nThe driver reported the following diagnostics whilst running %s:\n", fn);
- do
- {
- // get current values of multiple fields(error, warning, and status) of diagnostic record
- // and see if return value indicated success
- ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
- sizeof(text), &len );
- if (SQL_SUCCEEDED(ret))
- log_println(2, "%s:%ld:%ld:%s", state, i, native, text);
- }
- while( ret == SQL_SUCCESS );
+ SQLINTEGER i = 0;
+ SQLINTEGER native;
+ SQLCHAR state[ 7 ];
+ SQLCHAR text[256];
+ SQLSMALLINT len;
+ SQLRETURN ret;
+
+ log_println(2, "\nThe driver reported the following diagnostics whilst running %s:\n", fn);
+ do
+ {
+ // get current values of multiple fields(error, warning, and status) of diagnostic record
+ // and see if return value indicated success
+ ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
+ sizeof(text), &len );
+ if (SQL_SUCCEEDED(ret))
+ log_println(2, "%s:%ld:%ld:%s", state, i, native, text);
+ }
+ while( ret == SQL_SUCCESS );
}
#endif

@@ -134,114 +134,112 @@
* @param pwd pointer to password string pointer the db uses for authentication
* @return integer 0 if success, 1 if failure
* */
-int
-initialize_db(int options, char* dsn, char* uid, char* pwd)
-{
+int initialize_db(int options, char* dsn, char* uid, char* pwd) {
#if defined(HAVE_ODBC) && defined(DATABASE_ENABLED) && defined(HAVE_SQL_H)
- if (options) {
- SQLRETURN ret; /* ODBC API return status */
- SQLSMALLINT columns; /* number of columns in result-set */
- SQLCHAR outstr[1024];
- SQLSMALLINT outstrlen;
- char loginstring[1024];
-
- log_println(1, "Initializing DB with DSN='%s', UID='%s', PWD=%s", dsn, uid, pwd ? "yes" : "no");
- sprintf(createTableStmt, "%s%s%s%s", ctStmt_1, ctStmt_2, ctStmt_3, ctStmt_4);
-
- // Allocate an environment handle
- SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
- // We want ODBC 3 support
- SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
- // Allocate a connection handle
- SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
- // Connect to the DSN after creating summarizing login data
- // into "loginstring"
- memset(loginstring, 0, 1024);
- snprintf(loginstring, 256, "DSN=%s;", dsn);
- if (uid) {
- /*strcat(loginstring, "UID=");
- strncat(loginstring, uid, 256);
- strcat(loginstring, ";");*/
- strlcat(loginstring, "UID=", sizeof(loginstring));
- strlcat(loginstring, uid, sizeof(loginstring));
- strlcat(loginstring, ";", sizeof(loginstring));
- }
- if (pwd) {
- //strcat(loginstring, "PWD=");
- strlcat(loginstring, "PWD=", sizeof(loginstring));
- //strncat(loginstring, pwd, 256);
- strlcat(loginstring, pwd, sizeof(loginstring));
- }
- ret = SQLDriverConnect(dbc, NULL, (unsigned char*) loginstring, SQL_NTS,
- outstr, sizeof(outstr), &outstrlen, SQL_DRIVER_NOPROMPT);
- if (SQL_SUCCEEDED(ret)) {
- log_println(2, " Connected");
- log_println(2, " Returned connection string was:\n\t%s", outstr);
- if (ret == SQL_SUCCESS_WITH_INFO) {
- log_println(2, "Driver reported the following diagnostics");
- extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC);
- }
- } else {
- log_println(0, " Failed to connect to the DSN\n Continuing without DB logging");
- extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC);
- return 1;
- }
- // Allocate a statement handle
- ret = SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
- if (!SQL_SUCCEEDED(ret)) {
- log_println(0, " Failed to alloc statement handle\n Continuing without DB logging");
- extract_error("SQLAllocHandle", dbc, SQL_HANDLE_DBC);
- return 1;
- }
- // Retrieve a list of tables
- ret = SQLTables(stmt, NULL, 0, NULL, 0, NULL, 0, (unsigned char*) "TABLE", SQL_NTS);
- if (!SQL_SUCCEEDED(ret)) {
- log_println(0, " Failed to fetch table info\n Continuing without DB logging");
- extract_error("SQLTables", dbc, SQL_HANDLE_DBC);
- return 1;
- }
- // How many columns are there?
- SQLNumResultCols(stmt, &columns);
-
- // Loop through the rows in the result-set
- while (SQL_SUCCEEDED(ret = SQLFetch(stmt))) {
- SQLUSMALLINT i;
- // Loop through the columns
- for (i = 2; i <= columns; i++) {
- SQLINTEGER indicator;
- char buf[512];
- // retrieve column data as a string
- ret = SQLGetData(stmt, i, SQL_C_CHAR,
- buf, sizeof(buf), &indicator);
- if (SQL_SUCCEEDED(ret)) {
- // Handle null columns
- if (indicator == SQL_NULL_DATA)
- //strcpy(buf, "NULL");
- strlcpy(buf, "NULL", sizeof(buf));
- if (strcmp(buf, "ndt_test_results") == 0) {
- // the table exists - do nothing
- SQLFreeStmt(stmt, SQL_CLOSE);
- return 0;
- }
- }
- }
- }
-
- // the table doesn't exist - create it
- SQLFreeStmt(stmt, SQL_CLOSE);
- log_print(1, "The table 'ndt_test_results' doesn't exist, creating...");
- ret = SQLExecDirect(stmt, (unsigned char*) createTableStmt, strlen(createTableStmt));
- if (!SQL_SUCCEEDED(ret)) {
- log_println(0, " Failed to create table\n Continuing without DB logging");
- extract_error("SQLExecDirect", dbc, SQL_HANDLE_DBC);
- stmt = NULL;
- return 1;
- }
- log_println(1, " SUCCESS!");
- }
- return 0;
+ if (options) {
+ SQLRETURN ret; /* ODBC API return status */
+ SQLSMALLINT columns; /* number of columns in result-set */
+ SQLCHAR outstr[1024];
+ SQLSMALLINT outstrlen;
+ char loginstring[1024];
+
+ log_println(1, "Initializing DB with DSN='%s', UID='%s', PWD=%s", dsn, uid, pwd ? "yes" : "no");
+ sprintf(createTableStmt, "%s%s%s%s", ctStmt_1, ctStmt_2, ctStmt_3, ctStmt_4);
+
+ // Allocate an environment handle
+ SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
+ // We want ODBC 3 support
+ SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *)
SQL_OV_ODBC3, 0);
+ // Allocate a connection handle
+ SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
+ // Connect to the DSN after creating summarizing login data
+ // into "loginstring"
+ memset(loginstring, 0, 1024);
+ snprintf(loginstring, 256, "DSN=%s;", dsn);
+ if (uid) {
+ /*strcat(loginstring, "UID=");
+ strncat(loginstring, uid, 256);
+ strcat(loginstring, ";");*/
+ strlcat(loginstring, "UID=", sizeof(loginstring));
+ strlcat(loginstring, uid, sizeof(loginstring));
+ strlcat(loginstring, ";", sizeof(loginstring));
+ }
+ if (pwd) {
+ //strcat(loginstring, "PWD=");
+ strlcat(loginstring, "PWD=", sizeof(loginstring));
+ //strncat(loginstring, pwd, 256);
+ strlcat(loginstring, pwd, sizeof(loginstring));
+ }
+ ret = SQLDriverConnect(dbc, NULL, (unsigned char*)
loginstring, SQL_NTS,
+ outstr, sizeof(outstr), &outstrlen,
SQL_DRIVER_NOPROMPT);
+ if (SQL_SUCCEEDED(ret)) {
+ log_println(2, " Connected");
+ log_println(2, " Returned connection string
was:\n\t%s", outstr);
+ if (ret == SQL_SUCCESS_WITH_INFO) {
+ log_println(2, "Driver reported the following
diagnostics");
+ extract_error("SQLDriverConnect", dbc,
SQL_HANDLE_DBC);
+ }
+ } else {
+ log_println(0, " Failed to connect to the DSN\n Continuing without DB logging");
+ extract_error("SQLDriverConnect", dbc,
SQL_HANDLE_DBC);
+ return 1;
+ }
+ // Allocate a statement handle
+ ret = SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
+ if (!SQL_SUCCEEDED(ret)) {
+ log_println(0, " Failed to alloc statement handle\n Continuing without DB logging");
+ extract_error("SQLAllocHandle", dbc, SQL_HANDLE_DBC);
+ return 1;
+ }
+ // Retrieve a list of tables
+ ret = SQLTables(stmt, NULL, 0, NULL, 0, NULL, 0, (unsigned char*) "TABLE", SQL_NTS);
+ if (!SQL_SUCCEEDED(ret)) {
+ log_println(0, " Failed to fetch table info\n Continuing without DB logging");
+ extract_error("SQLTables", dbc, SQL_HANDLE_DBC);
+ return 1;
+ }
+ // How many columns are there?
+ SQLNumResultCols(stmt, &columns);
+
+ // Loop through the rows in the result-set
+ while (SQL_SUCCEEDED(ret = SQLFetch(stmt))) {
+ SQLUSMALLINT i;
+ // Loop through the columns
+ for (i = 2; i <= columns; i++) {
+ SQLINTEGER indicator;
+ char buf[512];
+ // retrieve column data as a string
+ ret = SQLGetData(stmt, i, SQL_C_CHAR,
+ buf, sizeof(buf), &indicator);
+ if (SQL_SUCCEEDED(ret)) {
+ // Handle null columns
+ if (indicator == SQL_NULL_DATA)
+ //strcpy(buf, "NULL");
+ strlcpy(buf, "NULL", sizeof(buf));
+ if (strcmp(buf, "ndt_test_results")
== 0) {
+ // the table exists - do
nothing
+ SQLFreeStmt(stmt, SQL_CLOSE);
+ return 0;
+ }
+ }
+ }
+ }
+
+ // the table doesn't exist - create it
+ SQLFreeStmt(stmt, SQL_CLOSE);
+ log_print(1, "The table 'ndt_test_results' doesn't exist,
creating...");
+ ret = SQLExecDirect(stmt, (unsigned char*) createTableStmt, strlen(createTableStmt));
+ if (!SQL_SUCCEEDED(ret)) {
+ log_println(0, " Failed to create table\n Continuing without DB logging");
+ extract_error("SQLExecDirect", dbc, SQL_HANDLE_DBC);
+ stmt = NULL;
+ return 1;
+ }
+ log_println(1, " SUCCESS!");
+ }
+ return 0;
#else
- return 1;
+ return 1;
#endif
}

@@ -250,66 +248,68 @@
* @params All parameters related to test results collected
* @return integer 0 if success, 1 if failure
* */
-int
-db_insert(char spds[4][256], float runave[], char* cputimelog, char* snaplog, char* c2s_snaplog,
- char* hostName, int testPort,
- char* date, char* rmt_host, int s2c2spd, int s2cspd, int c2sspd, int Timeouts,
- int SumRTT, int CountRTT, int PktsRetrans, int FastRetran, int DataPktsOut,
- int AckPktsOut, int CurrentMSS, int DupAcksIn, int AckPktsIn, int MaxRwinRcvd,
- int Sndbuf, int MaxCwnd, int SndLimTimeRwin, int SndLimTimeCwnd, int SndLimTimeSender,
- int DataBytesOut, int SndLimTransRwin, int SndLimTransCwnd, int SndLimTransSender,
- int MaxSsthresh, int CurrentRTO, int CurrentRwinRcvd, int link, int mismatch,
- int bad_cable, int half_duplex, int congestion, int c2sdata, int c2sack, int s2cdata,
- int s2cack, int CongestionSignals, int PktsOut, int MinRTT, int RcvWinScale,
- int autotune, int CongAvoid, int CongestionOverCount, int MaxRTT, int OtherReductions,
- int CurTimeoutCount, int AbruptTimeouts, int SendStall, int SlowStart,
- int SubsequentTimeouts, int ThruBytesAcked, int minPeak, int maxPeak, int peaks)
-{
+int db_insert(char spds[4][256], float runave[], char* cputimelog,
+ char* snaplog, char* c2s_snaplog, char* hostName, int
testPort,
+ char* date, char* rmt_host, int s2c2spd, int s2cspd, int
c2sspd,
+ int Timeouts, int SumRTT, int CountRTT, int PktsRetrans, int
FastRetran,
+ int DataPktsOut, int AckPktsOut, int CurrentMSS, int
DupAcksIn,
+ int AckPktsIn, int MaxRwinRcvd, int Sndbuf, int MaxCwnd,
+ int SndLimTimeRwin, int SndLimTimeCwnd, int SndLimTimeSender,
+ int DataBytesOut, int SndLimTransRwin, int SndLimTransCwnd,
+ int SndLimTransSender, int MaxSsthresh, int CurrentRTO,
+ int CurrentRwinRcvd, int link, int mismatch, int bad_cable,
+ int half_duplex, int congestion, int c2sdata, int c2sack, int
s2cdata,
+ int s2cack, int CongestionSignals, int PktsOut, int MinRTT,
+ int RcvWinScale, int autotune, int CongAvoid, int
CongestionOverCount,
+ int MaxRTT, int OtherReductions, int CurTimeoutCount,
+ int AbruptTimeouts, int SendStall, int SlowStart,
+ int SubsequentTimeouts, int ThruBytesAcked, int minPeak, int
maxPeak,
+ int peaks) {
#if defined(HAVE_ODBC) && defined(DATABASE_ENABLED) && defined(HAVE_SQL_H)
- SQLRETURN ret;
- char insertStmt[2048];
- if (!stmt) {
- return 1;
- }
- snprintf(insertStmt, 2040, "INSERT INTO ndt_test_results VALUES ("
- "'%s','%s','%s','%s',%f,%f,%f,%f,"
- "'%s','%s','%s','%s',%d,"
- "'%s','%s',%d,%d,%d,%d,"
- "%d,%d,%d,%d,%d,"
- "%d,%d,%d,%d,%d,"
- "%d,%d,%d,%d,%d,"
- "%d,%d,%d,%d,"
- "%d,%d,%d,%d,%d,"
- "%d,%d,%d,%d,%d,%d,"
- "%d,%d,%d,%d,%d,"
- "%d,%d,%d,%d,%d,"
- "%d,%d,%d,%d,"
- "%d,%d,%d,%d,%d"
- ");",
- spds[0], spds[1], spds[2], spds[3], runave[0], runave[1], runave[2], runave[3],
- cputimelog, snaplog, c2s_snaplog, hostName, testPort,
- date, rmt_host, s2c2spd, s2cspd, c2sspd, Timeouts,
- SumRTT, CountRTT, PktsRetrans, FastRetran, DataPktsOut,
- AckPktsOut, CurrentMSS, DupAcksIn, AckPktsIn, MaxRwinRcvd,
- Sndbuf, MaxCwnd, SndLimTimeRwin, SndLimTimeCwnd, SndLimTimeSender,
- DataBytesOut, SndLimTransRwin, SndLimTransCwnd, SndLimTransSender,
- MaxSsthresh, CurrentRTO, CurrentRwinRcvd, link, mismatch,
- bad_cable, half_duplex, congestion, c2sdata, c2sack, s2cdata,
- s2cack, CongestionSignals, PktsOut, MinRTT, RcvWinScale,
- autotune, CongAvoid, CongestionOverCount, MaxRTT, OtherReductions,
- CurTimeoutCount, AbruptTimeouts, SendStall, SlowStart,
- SubsequentTimeouts, ThruBytesAcked, minPeak, maxPeak, peaks
- );
- ret = SQLExecDirect(stmt, (unsigned char*) insertStmt, strlen(insertStmt));
- if (!SQL_SUCCEEDED(ret)) {
- log_println(0, " Failed to insert test results into the table\n Continuing without DB logging");
- extract_error("SQLExecDirect", dbc, SQL_HANDLE_DBC);
- stmt = NULL;
- return 1;
- }
-
- return 0;
+ SQLRETURN ret;
+ char insertStmt[2048];
+ if (!stmt) {
+ return 1;
+ }
+ snprintf(insertStmt, 2040, "INSERT INTO ndt_test_results VALUES ("
+ "'%s','%s','%s','%s',%f,%f,%f,%f,"
+ "'%s','%s','%s','%s',%d,"
+ "'%s','%s',%d,%d,%d,%d,"
+ "%d,%d,%d,%d,%d,"
+ "%d,%d,%d,%d,%d,"
+ "%d,%d,%d,%d,%d,"
+ "%d,%d,%d,%d,"
+ "%d,%d,%d,%d,%d,"
+ "%d,%d,%d,%d,%d,%d,"
+ "%d,%d,%d,%d,%d,"
+ "%d,%d,%d,%d,%d,"
+ "%d,%d,%d,%d,"
+ "%d,%d,%d,%d,%d"
+ ");",
+ spds[0], spds[1], spds[2], spds[3], runave[0], runave[1], runave[2], runave[3],
+ cputimelog, snaplog, c2s_snaplog, hostName, testPort,
+ date, rmt_host, s2c2spd, s2cspd, c2sspd, Timeouts,
+ SumRTT, CountRTT, PktsRetrans, FastRetran,
DataPktsOut,
+ AckPktsOut, CurrentMSS, DupAcksIn, AckPktsIn,
MaxRwinRcvd,
+ Sndbuf, MaxCwnd, SndLimTimeRwin, SndLimTimeCwnd,
SndLimTimeSender,
+ DataBytesOut, SndLimTransRwin, SndLimTransCwnd,
SndLimTransSender,
+ MaxSsthresh, CurrentRTO, CurrentRwinRcvd, link,
mismatch,
+ bad_cable, half_duplex, congestion, c2sdata, c2sack,
s2cdata,
+ s2cack, CongestionSignals, PktsOut, MinRTT,
RcvWinScale,
+ autotune, CongAvoid, CongestionOverCount, MaxRTT,
OtherReductions,
+ CurTimeoutCount, AbruptTimeouts, SendStall, SlowStart,
+ SubsequentTimeouts, ThruBytesAcked, minPeak, maxPeak,
peaks
+ );
+ ret = SQLExecDirect(stmt, (unsigned char*) insertStmt, strlen(insertStmt));
+ if (!SQL_SUCCEEDED(ret)) {
+ log_println(0, " Failed to insert test results into the table\n Continuing without DB logging");
+ extract_error("SQLExecDirect", dbc, SQL_HANDLE_DBC);
+ stmt = NULL;
+ return 1;
+ }
+
+ return 0;
#else
- return 1;
+ return 1;
#endif
}
=======================================
--- /branches/kkumar_code_organize/src/ndt_odbc.h Sun Sep 23 12:50:26
2007
+++ /branches/kkumar_code_organize/src/ndt_odbc.h Mon Oct 17 06:43:25
2011
@@ -9,18 +9,22 @@
#define _JS_NDT_ODBC_H

int initialize_db(int options, char* dsn, char* uin, char* pwd);
-int db_insert(char spds[4][256], float runave[], char* cputimelog, char* snaplog, char* c2s_snaplog,
- char* hostName, int testPort,
- char* date, char* rmt_host, int s2c2spd, int s2cspd, int c2sspd, int Timeouts,
- int SumRTT, int CountRTT, int PktsRetrans, int FastRetran, int DataPktsOut,
- int AckPktsOut, int CurrentMSS, int DupAcksIn, int AckPktsIn, int MaxRwinRcvd,
- int Sndbuf, int MaxCwnd, int SndLimTimeRwin, int SndLimTimeCwnd, int SndLimTimeSender,
- int DataBytesOut, int SndLimTransRwin, int SndLimTransCwnd, int SndLimTransSender,
- int MaxSsthresh, int CurrentRTO, int CurrentRwinRcvd, int link, int mismatch,
- int bad_cable, int half_duplex, int congestion, int c2sdata, int c2sack, int s2cdata,
- int s2cack, int CongestionSignals, int PktsOut, int MinRTT, int RcvWinScale,
- int autotune, int CongAvoid, int CongestionOverCount, int MaxRTT, int OtherReductions,
- int CurTimeoutCount, int AbruptTimeouts, int SendStall, int SlowStart,
- int SubsequentTimeouts, int ThruBytesAcked, int minPeaks, int maxPeaks, int peaks);
+int db_insert(char spds[4][256], float runave[], char* cputimelog,
+ char* snaplog, char* c2s_snaplog, char* hostName, int
testPort,
+ char* date, char* rmt_host, int s2c2spd, int s2cspd, int
c2sspd,
+ int Timeouts, int SumRTT, int CountRTT, int PktsRetrans, int
FastRetran,
+ int DataPktsOut, int AckPktsOut, int CurrentMSS, int
DupAcksIn,
+ int AckPktsIn, int MaxRwinRcvd, int Sndbuf, int MaxCwnd,
+ int SndLimTimeRwin, int SndLimTimeCwnd, int SndLimTimeSender,
+ int DataBytesOut, int SndLimTransRwin, int SndLimTransCwnd,
+ int SndLimTransSender, int MaxSsthresh, int CurrentRTO,
+ int CurrentRwinRcvd, int link, int mismatch, int bad_cable,
+ int half_duplex, int congestion, int c2sdata, int c2sack, int
s2cdata,
+ int s2cack, int CongestionSignals, int PktsOut, int MinRTT,
+ int RcvWinScale, int autotune, int CongAvoid, int
CongestionOverCount,
+ int MaxRTT, int OtherReductions, int CurTimeoutCount,
+ int AbruptTimeouts, int SendStall, int SlowStart,
+ int SubsequentTimeouts, int ThruBytesAcked, int minPeaks, int
maxPeaks,
+ int peaks);

#endif
=======================================
--- /branches/kkumar_code_organize/src/ndtptestconstants.c Sun Oct 9 17:00:18 2011
+++ /branches/kkumar_code_organize/src/ndtptestconstants.c Mon Oct 17 06:43:25 2011
@@ -12,45 +12,21 @@

// The arrays below rely on the ordering of corresponding enum in the .h file.
// test names
-static char *_teststatusdescarray[] = {
- "test_not_started",
- "test_started",
- "test_in_progress",
- "test_incomplete",
- "test_complete"
-};
+static char *_teststatusdescarray[] = { "test_not_started", "test_started",
+ "test_in_progress", "test_incomplete", "test_complete" };

// names of tests.
-static char *_testnamesarray[] = {
- "None",
- "Middlebox",
- "SFW",
- "C2S",
- "S2C",
- "Meta"
-};
+static char *_testnamesarray[] = { "None", "Middlebox", "SFW", "C2S", "S2C",
+ "Meta" };

// names of test messages to log in descriptive names instead of numbers
-static char * _testmsgtypesarray[] = {
- "COMM_FAILURE",
- "SRV_QUEUE",
- "MSG_LOGIN",
- "TEST_PREPARE",
- "TEST_START",
- "TEST_MSG",
- "TEST_FINALIZE",
- "MSG_ERROR",
- "MSG_RESULTS",
- "MSG_LOGOUT",
- "MSG_WAITING",
-};
+static char * _testmsgtypesarray[] = { "COMM_FAILURE", "SRV_QUEUE", "MSG_LOGIN",
+ "TEST_PREPARE", "TEST_START", "TEST_MSG", "TEST_FINALIZE",
"MSG_ERROR",
+ "MSG_RESULTS", "MSG_LOGOUT", "MSG_WAITING", };

// names of protocol message transmission directions
-static char *_txdirectionsarray[] = {
- "none",
- "client_to_server",
- "server_to_client"
-};
+static char *_txdirectionsarray[] = { "none", "client_to_server",
+ "server_to_client" };

/**
* Get descriptive string for test name
@@ -71,7 +47,7 @@
* @return char* Descriptive string for test status
* */
char *get_teststatusdesc(enum TEST_STATUS_INT teststatus, char *sstatusarg) {
- sstatusarg = _teststatusdescarray[teststatus];
+ sstatusarg = _teststatusdescarray[teststatus];
//printf ("--current test status = %s, for %d \n", sstatusarg, teststatus);
return sstatusarg;
}
=======================================
--- /branches/kkumar_code_organize/src/ndtptestconstants.h Sun Oct 9 17:00:18 2011
+++ /branches/kkumar_code_organize/src/ndtptestconstants.h Mon Oct 17 06:43:25 2011
@@ -20,17 +20,24 @@
#define MSG_TYPE_DESC_SIZE 15 /* max size for now derived from "TEST_FINALIZE" */

/* status of tests. Used mainly to log a "textual" explanation using below array */
-enum TEST_STATUS_INT { TEST_NOT_STARTED, TEST_STARTED, TEST_INPROGRESS, TEST_INCOMPLETE, TEST_ENDED } teststatusint;
+enum TEST_STATUS_INT {
+ TEST_NOT_STARTED, TEST_STARTED, TEST_INPROGRESS, TEST_INCOMPLETE, TEST_ENDED
+} teststatusint;

/* Test IDs */
-enum TEST_ID{ NONE, MIDDLEBOX, SFW, C2S, S2C, META } testid;
+enum TEST_ID {
+ NONE, MIDDLEBOX, SFW, C2S, S2C, META
+} testid;

/* Transmission direction */
-enum Tx_DIRECTION { NO_DIR, C_S , S_C} txdirection;
+enum Tx_DIRECTION {
+ NO_DIR, C_S, S_C
+} txdirection;

char *get_testnamedesc(enum TEST_ID testid, char *stestnamearg);
char *get_teststatusdesc(enum TEST_STATUS_INT teststatus, char *steststatusarg);
-char *get_testdirectiondesc(enum Tx_DIRECTION testdirection, char *stestdirectionarg);
-char *get_msgtypedesc(int msgtypearg, char *smsgtypearg) ;
+char *get_testdirectiondesc(enum Tx_DIRECTION testdirection,
+ char *stestdirectionarg);
+char *get_msgtypedesc(int msgtypearg, char *smsgtypearg);

#endif
=======================================
--- /branches/kkumar_code_organize/src/network.c Mon Oct 17 06:31:32
2011
+++ /branches/kkumar_code_organize/src/network.c Mon Oct 17 06:43:25
2011
@@ -24,110 +24,117 @@
* -2 : Unable to set socket options
*/

-static int
-OpenSocket(I2Addr addr, char* serv, int options)
-{
- struct addrinfo *fai;
- struct addrinfo *ai;
- int on;
- socklen_t onSize;
- int fd=-1;
-
- if (!(fai = I2AddrAddrInfo(addr, NULL, serv))) {
- return -2;
- }
-
- for (ai = fai; ai; ai = ai->ai_next) {
- // options provided by user indicate V6
+static int OpenSocket(I2Addr addr, char* serv, int options) {
+ struct addrinfo *fai;
+ struct addrinfo *ai;
+ int on;
+ socklen_t onSize;
+ int fd = -1;
+
+ if (!(fai = I2AddrAddrInfo(addr, NULL, serv))) {
+ return -2;
+ }
+
+ for (ai = fai; ai; ai = ai->ai_next) {
+ // options provided by user indicate V6
#ifdef AF_INET6
- if (options & OPT_IPV6_ONLY) { // If not an INET6 address, move on
- if(ai->ai_family != AF_INET6)
- continue;
- }
+ if (options & OPT_IPV6_ONLY) { // If not an INET6 address,
move on
+ if(ai->ai_family != AF_INET6)
+ continue;
+ }
#endif
-
- if (options & OPT_IPV4_ONLY) { // options provided by user indicate V4
- if(ai->ai_family != AF_INET) // Not valid Inet address family. move on
- continue;
- }
-
- // create socket with obtained address domain, socket type and protocol
- fd = socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol);
-
- // socket create failed. Abandon further activities using this socket
- if (fd < 0) {
- continue;
- }
-
- // allow sockets to reuse local address while binding unless there
- // is an active listener. If unable to set this option, indicate failure
-
- on=1;
- if (setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on)) != 0) {
- goto failsock;
- }
-
- // the IPv6 version socket option setup
+
+ if (options & OPT_IPV4_ONLY) { // options provided by user
indicate V4
+ if (ai->ai_family != AF_INET) // Not valid Inet
address family. move on
+ continue;
+ }
+
+ // create socket with obtained address domain, socket type
and protocol
+ fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+
+ // socket create failed. Abandon further activities using
this socket
+ if (fd < 0) {
+ continue;
+ }
+
+ // allow sockets to reuse local address while binding unless
there
+ // is an active listener. If unable to set this option,
indicate failure
+
+ on = 1;
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))
!= 0) {
+ goto failsock;
+ }
+
+ // the IPv6 version socket option setup
#if defined(AF_INET6) && defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
- if ((ai->ai_family == AF_INET6) && (options & OPT_IPV6_ONLY) &&
- setsockopt(fd,IPPROTO_IPV6,IPV6_V6ONLY,&on,sizeof(on)) != 0) {
- goto failsock;
- }
+ if ((ai->ai_family == AF_INET6) && (options & OPT_IPV6_ONLY)
&&
+
setsockopt(fd,IPPROTO_IPV6,IPV6_V6ONLY,&on,sizeof(on)) != 0) {
+ goto failsock;
+ }
#endif
- // end trying to set socket option to reuse local address
-
- // try to bind to address
- if (bind(fd,ai->ai_addr,ai->ai_addrlen) == 0) { // successful
-
- // set values in "addr" structure
- if (!I2AddrSetSAddr(addr,ai->ai_addr,ai->ai_addrlen) ||
- !I2AddrSetProtocol(addr,ai->ai_protocol) ||
- !I2AddrSetSocktype(addr,ai->ai_socktype)) {
- log_println(1, "OpenSocket: Unable to set saddr in address record");
- return -1;
- }
- // set port if not already done, else return -1
- if (!I2AddrPort(addr)) {
- struct sockaddr_storage tmp_addr;
- socklen_t tmp_addr_len = sizeof(tmp_addr);
- I2Addr tmpAddr;
- if (getsockname(fd, (struct sockaddr*) &tmp_addr, &tmp_addr_len)) {
- return -1;
- }
- tmpAddr = I2AddrBySAddr(get_errhandle(), (struct sockaddr*) &tmp_addr, tmp_addr_len, 0, 0);
- I2AddrSetPort(addr, I2AddrPort(tmpAddr));
- I2AddrFree(tmpAddr);
- }
- // save socket file descriptor
- if (!I2AddrSetFD(addr,fd,True)) {
- log_println(1, "OpenSocket: Unable to set file descriptor in address record");
- return -1;
- }
- // end setting values in "addr" structure
-
- break;
- }
-
- // Address is indicated as being in use. Display actual socket options to user and return
- if (errno == EADDRINUSE) {
- /* RAC debug statemement 10/11/06 */
- onSize = sizeof(on);
- getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, &onSize);
- log_println(1, "bind(%d) failed: Address already in use given as the reason, getsockopt() returned %d", fd, on);
- return -2;
- }
-
- // If setting socket option failed, print error, and try to close socket file-descriptor
-failsock:
- /* RAC debug statemement 10/11/06 */
- log_println(1, "failsock: Unable to set socket options for fd=%d", fd);
- while((close(fd) < 0) && (errno == EINTR));
- }
-
- // set meta test's address domain family to the one used to create socket
- if (meta.family == 0)
- meta.family = ai->ai_family;
- return fd;
+ // end trying to set socket option to reuse local address
+
+ // try to bind to address
+ if (bind(fd, ai->ai_addr, ai->ai_addrlen) == 0) { //
successful
+
+ // set values in "addr" structure
+ if (!I2AddrSetSAddr(addr, ai->ai_addr, ai->ai_addrlen)
+ || !I2AddrSetProtocol(addr,
ai->ai_protocol)
+ || !I2AddrSetSocktype(addr,
ai->ai_socktype)) {
+ log_println(1,
+ "OpenSocket: Unable to set saddr
in address record");
+ return -1;
+ }
+ // set port if not already done, else return -1
+ if (!I2AddrPort(addr)) {
+ struct sockaddr_storage tmp_addr;
+ socklen_t tmp_addr_len = sizeof(tmp_addr);
+ I2Addr tmpAddr;
+ if (getsockname(fd, (struct sockaddr*)
&tmp_addr,
+ &tmp_addr_len)) {
+ return -1;
+ }
+ tmpAddr = I2AddrBySAddr(get_errhandle(),
+ (struct sockaddr*) &tmp_addr,
tmp_addr_len, 0, 0);
+ I2AddrSetPort(addr, I2AddrPort(tmpAddr));
+ I2AddrFree(tmpAddr);
+ }
+ // save socket file descriptor
+ if (!I2AddrSetFD(addr, fd, True)) {
+ log_println(
+ 1,
+ "OpenSocket: Unable to set file
descriptor in address record");
+ return -1;
+ }
+ // end setting values in "addr" structure
+
+ break;
+ }
+
+ // Address is indicated as being in use. Display actual socket options to user and return
+ if (errno == EADDRINUSE) {
+ /* RAC debug statemement 10/11/06 */
+ onSize = sizeof(on);
+ getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on,
&onSize);
+ log_println(
+ 1,
+ "bind(%d) failed: Address already in use given as the reason, getsockopt() returned %d",
+ fd, on);
+ return -2;
+ }
+
+ // If setting socket option failed, print error, and try to close socket file-descriptor
+ failsock:
+ /* RAC debug statemement 10/11/06 */
+ log_println(1, "failsock: Unable to set socket options for
fd=%d", fd);
+ while ((close(fd) < 0) && (errno == EINTR))
+ ;
+ }
+
+ // set meta test's address domain family to the one used to create
socket
+ if (meta.family == 0)
+ meta.family = ai->ai_family;
+ return fd;
}

/**
@@ -141,230 +148,229 @@
* @returns I2Addr structure with the listen socket.
*/

-I2Addr
-CreateListenSocket(I2Addr addr, char* serv, int options, int buf_size)
-{
- int fd = -1;
- socklen_t optlen;
- int set_size;
-
- if (addr && (I2AddrFD(addr) > -1)) {
- log_println(1, "Invalid I2Addr record - fd already specified.");
- goto error;
- }
-
- if ((!addr) && !(addr = I2AddrByWildcard(get_errhandle(), SOCK_STREAM, serv))) {
- log_println(1, "Unable to create I2Addr record by wildcard.");
- goto error;
- }
-
- if (!I2AddrSetPassive(addr,True)) {
- log_println(1, "Unable to set passive mode in I2Addr record.");
- goto error;
- }
-
- // create and bind socket using arguments
- fd = OpenSocket(addr, serv, options);
-
- if (fd < 0) {
- log_println(1, "Unable to open socket.");
- goto error;
- }
-
-/* Set sock opt code from Marion Nakanson
<
- * OHSU Advanced Computing Center
- * email on 2/19/09 correctly notes that setsockops must be made before open()
- * or listen() calls are made
- */
-
- optlen = sizeof(set_size);
- // get send buffer size
- getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &set_size, &optlen);
- log_print(5, "\nSend buffer initialized to %d, ", set_size);
-
- // get receive buffer size
- getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &set_size, &optlen);
- log_println(5, "Receive buffer initialized to %d", set_size);
-
- // now assign buffer sizes passed as arguments
- if (buf_size > 0) {
- setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buf_size, sizeof(buf_size)); // send buffer
- setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buf_size, sizeof(buf_size)); // receive buffer
- // print values set to help user verify
- getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &set_size, &optlen);
- log_print(5, "Changed buffer sizes: Send buffer set to %d(%d), ", set_size, buf_size);
- getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &set_size, &optlen);
- log_println(5, "Receive buffer set to %d(%d)", set_size, buf_size);
- }
-
- // now listen on socket for connections, with backlog queue length = NDT_BACKLOG
- if (listen(fd, NDT_BACKLOG) < 0) { // if listen returns value <0, then error
- log_println(1, "listen(%d,%d):%s", fd, NDT_BACKLOG, strerror(errno));
- goto error;
- }
-
- return addr;
+I2Addr CreateListenSocket(I2Addr addr, char* serv, int options, int buf_size) {
+ int fd = -1;
+ socklen_t optlen;
+ int set_size;
+
+ if (addr && (I2AddrFD(addr) > -1)) {
+ log_println(1, "Invalid I2Addr record - fd already
specified.");
+ goto error;
+ }
+
+ if ((!addr)
+ && !(addr = I2AddrByWildcard(get_errhandle(),
SOCK_STREAM, serv))) {
+ log_println(1, "Unable to create I2Addr record by wildcard.");
+ goto error;
+ }
+
+ if (!I2AddrSetPassive(addr, True)) {
+ log_println(1, "Unable to set passive mode in I2Addr
record.");
+ goto error;
+ }
+
+ // create and bind socket using arguments
+ fd = OpenSocket(addr, serv, options);
+
+ if (fd < 0) {
+ log_println(1, "Unable to open socket.");
+ goto error;
+ }
+
+ /* Set sock opt code from Marion Nakanson
<
+ * OHSU Advanced Computing Center
+ * email on 2/19/09 correctly notes that setsockops must be made before open()
+ * or listen() calls are made
+ */
+
+ optlen = sizeof(set_size);
+ // get send buffer size
+ getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &set_size, &optlen);
+ log_print(5, "\nSend buffer initialized to %d, ", set_size);
+
+ // get receive buffer size
+ getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &set_size, &optlen);
+ log_println(5, "Receive buffer initialized to %d", set_size);
+
+ // now assign buffer sizes passed as arguments
+ if (buf_size > 0) {
+ setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buf_size, sizeof(buf_size)); // send buffer
+ setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buf_size, sizeof(buf_size)); // receive buffer
+ // print values set to help user verify
+ getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &set_size, &optlen);
+ log_print(5, "Changed buffer sizes: Send buffer set to %d(%d),
",
+ set_size, buf_size);
+ getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &set_size, &optlen);
+ log_println(5, "Receive buffer set to %d(%d)", set_size,
buf_size);
+ }
+
+ // now listen on socket for connections, with backlog queue length = NDT_BACKLOG
+ if (listen(fd, NDT_BACKLOG) < 0) { // if listen returns value <0, then error
+ log_println(1, "listen(%d,%d):%s", fd, NDT_BACKLOG,
strerror(errno));
+ goto error;
+ }
+
+ return addr;

// If error, try freeing memory
-error:
- I2AddrFree(addr);
- return NULL;
+ error: I2AddrFree(addr);
+ return NULL;
}

/**
- * Function name: CreateConnectSocket
- * Description: Creates the connect socket and adds it to the I2Addr
+ * Create the connect socket and adds it to the I2Addr
* structure.
- * Arguments: sockfd - the target place for the socket descriptor
- * local_addr - the I2Addr structure with the local address
+ * @param sockfd target place for the socket descriptor
+ * @param local_addr I2Addr structure with the local address
* to bind the connect socket to
- * server_addr - the I2Addr structure with the remote
+ * @param server_addr I2Addr structure with the remote
* server address
- * options - the connect socket options
- * buf_size - manually set the TCP send/receive buffer size`
- * Returns: 0 - success,
+ * @param options connect socket options
+ * @param buf_size manually set the TCP send/receive buffer size`
+ * @return 0 - success,
* !0 - error code.
*/

-int
-CreateConnectSocket(int* sockfd, I2Addr local_addr, I2Addr server_addr, int options, int buf_size)
-{
- struct addrinfo *fai = NULL;
- struct addrinfo *ai = NULL;
- struct addrinfo *lfai = NULL;
- struct addrinfo *lai = NULL;
- socklen_t optlen;
- int set_size;
-
- assert(sockfd);
- assert(server_addr);
-
- if (!server_addr) {
- goto error;
- }
-
- // already connected and bound
- if ((*sockfd = I2AddrFD(server_addr)) > -1) {
- return 0;
- }
-
- if (!(fai = I2AddrAddrInfo(server_addr, NULL, NULL))) {
- goto error;
- }
-
- for (ai=fai; ai; ai=ai->ai_next) {
-
- // options provided by user indicate V6
+int CreateConnectSocket(int* sockfd, I2Addr local_addr, I2Addr server_addr,
+ int options, int buf_size) {
+ struct addrinfo *fai = NULL;
+ struct addrinfo *ai = NULL;
+ struct addrinfo *lfai = NULL;
+ struct addrinfo *lai = NULL;
+ socklen_t optlen;
+ int set_size;
+
+ assert(sockfd);
+ assert(server_addr);
+
+ if (!server_addr) {
+ goto error;
+ }
+
+ // already connected and bound
+ if ((*sockfd = I2AddrFD(server_addr)) > -1) {
+ return 0;
+ }
+
+ if (!(fai = I2AddrAddrInfo(server_addr, NULL, NULL))) {
+ goto error;
+ }
+
+ for (ai = fai; ai; ai = ai->ai_next) {
+
+ // options provided by user indicate V6
#ifdef AF_INET6
- if (options & OPT_IPV6_ONLY) { // If not an INET6 address, move on
- if(ai->ai_family != AF_INET6)
- continue;
- }
+ if (options & OPT_IPV6_ONLY) { // If not an INET6 address,
move on
+ if(ai->ai_family != AF_INET6)
+ continue;
+ }
#endif

- // options provided by user indicate V4
- if (options & OPT_IPV4_ONLY) {
- if(ai->ai_family != AF_INET) // NOT valid inet address family. Move on.
- continue;
- }
-
- // create socket with obtained address domain, socket type and protocol
- *sockfd = socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol);
- if (*sockfd < 0) { // socket create failed. Abandon further activities using this socket
- continue;
- }
-
- // local address has been specified. Get details and bind to this adderess
- if (local_addr) {
- int bindFailed = 1;
- if (!(lfai = I2AddrAddrInfo(local_addr, NULL, NULL))) {
- continue;
- }
-
- // Validate INET address family
- for (lai=lfai; lai; lai=lai->ai_next) {
+ // options provided by user indicate V4
+ if (options & OPT_IPV4_ONLY) {
+ if (ai->ai_family != AF_INET) // NOT valid inet
address family. Move on.
+ continue;
+ }
+
+ // create socket with obtained address domain, socket type
and protocol
+ *sockfd = socket(ai->ai_family, ai->ai_socktype,
ai->ai_protocol);
+ if (*sockfd < 0) { // socket create failed. Abandon further activities using this socket
+ continue;
+ }
+
+ // local address has been specified. Get details and bind to this adderess
+ if (local_addr) {
+ int bindFailed = 1;
+ if (!(lfai = I2AddrAddrInfo(local_addr, NULL, NULL)))
{
+ continue;
+ }
+
+ // Validate INET address family
+ for (lai = lfai; lai; lai = lai->ai_next) {
#ifdef AF_INET6
- if (options & OPT_IPV6_ONLY) {
- if(lai->ai_family != AF_INET6)
- continue;
- }
+ if (options & OPT_IPV6_ONLY) {
+ if(lai->ai_family != AF_INET6)
+ continue;
+ }
#endif

- if (options & OPT_IPV4_ONLY) {
- if(lai->ai_family != AF_INET)
- continue;
- }
-
- // bind to local address
- if (bind((*sockfd), lai->ai_addr, lai->ai_addrlen) == 0) {
- bindFailed = 0; // bind successful
- break; /* success */
- }
- }
-
- // Failed to bind. Close socket file-descriptor and move on
- if (bindFailed == 1) {
- close((*sockfd)); /* ignore this one */
- continue;
- }
- } // end local address
-
-/* Set sock opt code from Marion Nakanson
<
- * OHSU Advanced Computing Center
- * email on 2/19/09 correctly notes that setsockops must be made before open()
- * or listen() calls are made
- */
-
- optlen = sizeof(set_size);
- // get send buffer size for logs
- getsockopt(*sockfd, SOL_SOCKET, SO_SNDBUF, &set_size, &optlen);
- log_print(5, "\nSend buffer initialized to %d, ", set_size);
- // get receive buffer size for logs
- getsockopt(*sockfd, SOL_SOCKET, SO_RCVBUF, &set_size, &optlen);
- log_println(5, "Receive buffer initialized to %d", set_size);
-
- // now assign buffer sizes passed as arguments
- if (buf_size > 0) {
- setsockopt(*sockfd, SOL_SOCKET, SO_SNDBUF, &buf_size, sizeof(buf_size));
- setsockopt(*sockfd, SOL_SOCKET, SO_RCVBUF, &buf_size, sizeof(buf_size));
- // log values for reference
- getsockopt(*sockfd, SOL_SOCKET, SO_SNDBUF, &set_size, &optlen);
- log_print(5, "Changed buffer sizes: Send buffer set to %d(%d), ", set_size, buf_size);
- getsockopt(*sockfd, SOL_SOCKET, SO_RCVBUF, &set_size, &optlen);
- log_println(5, "Receive buffer set to %d(%d)", set_size, buf_size);
- }
-
- // Connect to target socket
- if (connect(*sockfd,ai->ai_addr,ai->ai_addrlen) == 0) {
-
- // save server address values
- if(I2AddrSetSAddr(server_addr,ai->ai_addr,ai->ai_addrlen) &&
- I2AddrSetSocktype(server_addr,ai->ai_socktype) &&
- I2AddrSetProtocol(server_addr,ai->ai_protocol) &&
- I2AddrSetFD(server_addr,*sockfd,True)){
- return 0;
- }
- // unable to save
- log_println(1, "I2Addr functions failed after successful connection");
- while((close(*sockfd) < 0) && (errno == EINTR));
- return 1;
- }
- }
-
-error:
- log_println(1, "Unable to create connect socket.");
- return -1;
+ if (options & OPT_IPV4_ONLY) {
+ if (lai->ai_family != AF_INET)
+ continue;
+ }
+
+ // bind to local address
+ if (bind((*sockfd), lai->ai_addr,
lai->ai_addrlen) == 0) {
+ bindFailed = 0; // bind successful
+ break; /* success */
+ }
+ }
+
+ // Failed to bind. Close socket file-descriptor and
move on
+ if (bindFailed == 1) {
+ close((*sockfd)); /* ignore this one */
+ continue;
+ }
+ } // end local address
+
+ /* Set sock opt code from Marion Nakanson
<
+ * OHSU Advanced Computing Center
+ * email on 2/19/09 correctly notes that setsockops must be made before open()
+ * or listen() calls are made
+ */
+
+ optlen = sizeof(set_size);
+ // get send buffer size for logs
+ getsockopt(*sockfd, SOL_SOCKET, SO_SNDBUF, &set_size,
&optlen);
+ log_print(5, "\nSend buffer initialized to %d, ", set_size);
+ // get receive buffer size for logs
+ getsockopt(*sockfd, SOL_SOCKET, SO_RCVBUF, &set_size,
&optlen);
+ log_println(5, "Receive buffer initialized to %d", set_size);
+
+ // now assign buffer sizes passed as arguments
+ if (buf_size > 0) {
+ setsockopt(*sockfd, SOL_SOCKET, SO_SNDBUF, &buf_size,
+ sizeof(buf_size));
+ setsockopt(*sockfd, SOL_SOCKET, SO_RCVBUF, &buf_size,
+ sizeof(buf_size));
+ // log values for reference
+ getsockopt(*sockfd, SOL_SOCKET, SO_SNDBUF, &set_size,
&optlen);
+ log_print(5, "Changed buffer sizes: Send buffer set to
%d(%d), ",
+ set_size, buf_size);
+ getsockopt(*sockfd, SOL_SOCKET, SO_RCVBUF, &set_size,
&optlen);
+ log_println(5, "Receive buffer set to %d(%d)",
set_size, buf_size);
+ }
+
+ // Connect to target socket
+ if (connect(*sockfd, ai->ai_addr, ai->ai_addrlen) == 0) {
+
+ // save server address values
+ if (I2AddrSetSAddr(server_addr, ai->ai_addr,
ai->ai_addrlen)
+ && I2AddrSetSocktype(server_addr,
ai->ai_socktype)
+ && I2AddrSetProtocol(server_addr,
ai->ai_protocol)
+ && I2AddrSetFD(server_addr, *sockfd,
True)) {
+ return 0;
+ }
+ // unable to save
+ log_println(1,
+ "I2Addr functions failed after successful
connection");
+ while ((close(*sockfd) < 0) && (errno == EINTR))
+ ;
+ return 1;
+ }
+ }
+
+ error: log_println(1, "Unable to create connect socket.");
+ return -1;
}

/**
- * Function name: send_msg
- * Description: Sends the protocol message to the control socket.
- * Arguments: ctlSocket - the control socket
- * type - the type of the message
- * msg - the message to send
- * len - the length of the message
- * Returns: 0 - success,
- * !0 - error code.
+ * Sends the protocol message to the control socket.
+ * @param ctlSocket control socket
+ * @param type type of the message
+ * @param msg message to send
+ * @param len length of the message
+ * @return 0 on success, error code otherwise
* Error codes:
* -1 - Cannot write to socket at all
* -2 - Cannot complete writing full message data into socket
@@ -372,112 +378,107 @@
*
*/

-int
-send_msg(int ctlSocket, int type, void* msg, int len)
-{
- unsigned char buff[3];
- int rc, i;
- FILE *fp;
-
- assert(msg);
- assert(len >= 0);
-
- /* memset(0, buff, 3); */
- // set message type and length into message itself
- buff[0] = type;
- buff[1] = len >> 8;
- buff[2] = len;
-
- // retry sending data 5 times
- for (i=0; i<5; i++) {
- // Write initial data about length and type to socket
- rc = writen(ctlSocket, buff, 3);
- if (rc == 3) // write completed
- break;
- if (rc == 0) // nothing written yet,
- continue;
- if (rc == -1) // error writing to socket..cannot continue
- return -1;
- }
-
- // Exceeded retries, return as "failed trying to write"
- if (i == 5)
- return -3;
-
- // Now write the actual message
- for (i=0; i<5; i++) {
- rc = writen(ctlSocket, msg, len);
- // all the data has been written successfully
- if (rc == len)
- break;
- // data writing not complete, continue
- if (rc == 0)
- continue;
- if (rc == -1) //error writing to socket, cannot continue writing data
- return -2;
- }
- if (i == 5)
- return -3;
- log_println(8, ">>> send_msg: type=%d, len=%d, msg=%s, pid=%d", type, len, msg, getpid());
-
- protolog_sendprintln(type, msg, len, getpid(),ctlSocket);
-
- return 0;
+int send_msg(int ctlSocket, int type, void* msg, int len) {
+ unsigned char buff[3];
+ int rc, i;
+ FILE * fp;
+
+ assert(msg);
+ assert(len >= 0);
+
+ /* memset(0, buff, 3); */
+ // set message type and length into message itself
+ buff[0] = type;
+ buff[1] = len >> 8;
+ buff[2] = len;
+
+ // retry sending data 5 times
+ for (i = 0; i < 5; i++) {
+ // Write initial data about length and type to socket
+ rc = writen(ctlSocket, buff, 3);
+ if (rc == 3) // write completed
+ break;
+ if (rc == 0) // nothing written yet,
+ continue;
+ if (rc == -1) // error writing to socket..cannot continue
+ return -1;
+ }
+
+ // Exceeded retries, return as "failed trying to write"
+ if (i == 5)
+ return -3;
+
+ // Now write the actual message
+ for (i = 0; i < 5; i++) {
+ rc = writen(ctlSocket, msg, len);
+ // all the data has been written successfully
+ if (rc == len)
+ break;
+ // data writing not complete, continue
+ if (rc == 0)
+ continue;
+ if (rc == -1) //error writing to socket, cannot continue
writing data
+ return -2;
+ }
+ if (i == 5)
+ return -3;
+ log_println(8, ">>> send_msg: type=%d, len=%d, msg=%s, pid=%d", type,
len,
+ msg, getpid());
+
+ protolog_sendprintln(type, msg, len, getpid(), ctlSocket);
+
+ return 0;
}

/**
- * Function name: recv_msg
- * Description: Receives the protocol message from the control socket.
- * Arguments: ctlSocket - the control socket
- * type - the target place for type of the message
- * msg - the target place for the message body
- * len - the target place for the length of the message
- * Returns: 0 - success
- * !0 - error code.
+ * Receive the protocol message from the control socket.
+ * @param ctlSocket control socket
+ * @param typetarget place for type of the message
+ * @param msg target place for the message body
+ * @param len target place for the length of the message
+ * @returns 0 on success, error code otherwise.
* Error codes:
* -1 : Error reading from socket
* -2 : No of bytes received were lesser than expected byte count
* -3 : No of bytes received did not match expected byte count
*/

-int
-recv_msg(int ctlSocket, int* type, void* msg, int* len)
-{
- unsigned char buff[3];
- int length;
- FILE *fp;
-
- char *msgtemp = (char*)msg;
-
- assert(type);
- assert(msg);
- assert(len);
-
- // if 3 bytes are not explicitly read, signal error
- if (readn(ctlSocket, buff, 3) != 3) {
- return -1;
- }
-
- // get msg type, and calculate length as sum of the next 2 bytes
- *type = buff[0];
- length = buff[1];
- length = (length << 8) + buff[2];
-
- // if received buffer size < length as conveyed by buffer contents, then error
- assert(length <= (*len));
- if (length > (*len)) {
- log_println(3, "recv_msg: length [%d] > *len [%d]", length, *len);
- return -2;
- }
- *len = length;
- if (readn(ctlSocket, msg, length) != length) {
- return -3;
- }
- log_println(8, "<<< recv_msg: type=%d, len=%d", *type, *len);
-
- protolog_rcvprintln(*type, msgtemp, *len, getpid(),ctlSocket);
-
- return 0;
+int recv_msg(int ctlSocket, int* type, void* msg, int* len) {
+ unsigned char buff[3];
+ int length;
+ FILE * fp;
+
+ char *msgtemp = (char*) msg;
+
+ assert(type);
+ assert(msg);
+ assert(len);
+
+ // if 3 bytes are not explicitly read, signal error
+ if (readn(ctlSocket, buff, 3) != 3) {
+ return -1;
+ }
+
+ // get msg type, and calculate length as sum of the next 2 bytes
+ *type = buff[0];
+ length = buff[1];
+ length = (length << 8) + buff[2];
+
+ // if received buffer size < length as conveyed by buffer contents, then error
+ assert(length <= (*len));
+ if (length > (*len)) {
+ log_println(3, "recv_msg: length [%d] > *len [%d]", length,
*len);
+ return -2;
+ }
+ *len = length;
+ if (readn(ctlSocket, msg, length) != length) {
+ return -3;
+ }
+ log_println(8, "<<< recv_msg: type=%d, len=%d", *type, *len);
+
+ protolog_rcvprintln(*type, msgtemp, *len, getpid(), ctlSocket);
+
+ return 0;
}

/**
@@ -488,30 +489,30 @@
* @return The amount of bytes written to the file descriptor
*/

-int
-writen(int fd, void* buf, int amount)
-{
- int sent, n;
- char* ptr = buf;
- sent = 0;
- assert(amount >= 0);
- while (sent < amount) {
- n = write(fd, ptr+sent, amount - sent);
- if (n == -1) {
- if (errno == EINTR) // interrupted, retry writing again
- continue;
- if (errno != EAGAIN) { // some genuine socket write error
- log_println(6, "writen() Error! write(%d) failed with err='%s(%d) pic=%d'", fd,
- strerror(errno), errno, getpid());
- return -1;
- }
- }
- assert(n != 0);
- if (n != -1) { // success writing "n" bytes. Increment total bytes written
- sent += n;
- }
- }
- return sent;
+int writen(int fd, void* buf, int amount) {
+ int sent, n;
+ char* ptr = buf;
+ sent = 0;
+ assert(amount >= 0);
+ while (sent < amount) {
+ n = write(fd, ptr + sent, amount - sent);
+ if (n == -1) {
+ if (errno == EINTR) // interrupted, retry writing
again
+ continue;
+ if (errno != EAGAIN) { // some genuine socket write
error
+ log_println(
+ 6,
+ "writen() Error! write(%d) failed
with err='%s(%d) pic=%d'",
+ fd, strerror(errno), errno,
getpid());
+ return -1;
+ }
+ }
+ assert(n != 0);
+ if (n != -1) { // success writing "n" bytes. Increment total bytes written
+ sent += n;
+ }
+ }
+ return sent;
}

/**
@@ -522,49 +523,49 @@
* @return The amount of bytes read from the file descriptor
*/

-int
-readn(int fd, void* buf, int amount)
-{
- int received=0, n, rc;
- char* ptr = buf;
- struct timeval sel_tv;
- fd_set rfd;
-
- assert(amount >= 0);
-
- FD_ZERO(&rfd); // initialize with zeroes
- FD_SET(fd, &rfd); //
- sel_tv.tv_sec = 600;
- sel_tv.tv_usec = 0;
-
- /* modified readn() routine 11/26/09 - RAC
- * addedd in select() call, to timeout if no read occurs after 10 seconds of waiting.
- * This should fix a bug where the server hangs at it looks like it's in this read
- * state. The select() should check to see if there is anything to read on this socket.
- * if not, and the 3 second timer goes off, exit out and clean up.
- */
- while (received < amount) {
-
- // check if fd+1 socket is ready to be read
- rc = select(fd+1, &rfd, NULL, NULL, &sel_tv);
- if (rc == 0) { /* A timeout occurred, nothing to read from socket after 3 seconds */
- log_println(6, "readn() routine timeout occurred, return error signal and kill off child");
- return received;
- }
- if ((rc == -1) && (errno == EINTR)) /* a signal was processed, ignore it */
- continue;
- n = read(fd, ptr+received, amount - received);
- if (n == -1) { // error
- if (errno == EINTR) // interrupted , try reading again
- continue;
- if (errno != EAGAIN) // genuine socket read error, return
- return -errno;
- }
- if (n != -1) { // if no errors reading, increment data byte count
- received += n;
- }
- if (n == 0)
- return 0;
- }
- return received;
-}
+int readn(int fd, void* buf, int amount) {
+ int received = 0, n, rc;
+ char* ptr = buf;
+ struct timeval sel_tv;
+ fd_set rfd;
+
+ assert(amount >= 0);
+
+ FD_ZERO(&rfd); // initialize with zeroes
+ FD_SET(fd, &rfd); //
+ sel_tv.tv_sec = 600;
+ sel_tv.tv_usec = 0;
+
+ /* modified readn() routine 11/26/09 - RAC
+ * addedd in select() call, to timeout if no read occurs after 10 seconds of waiting.
+ * This should fix a bug where the server hangs at it looks like it's in this read
+ * state. The select() should check to see if there is anything to read on this socket.
+ * if not, and the 3 second timer goes off, exit out and clean up.
+ */
+ while (received < amount) {
+
+ // check if fd+1 socket is ready to be read
+ rc = select(fd + 1, &rfd, NULL, NULL, &sel_tv);
+ if (rc == 0) { /* A timeout occurred, nothing to read from socket after 3 seconds */
+ log_println(
+ 6,
+ "readn() routine timeout occurred, return error signal and kill off child");
+ return received;
+ }
+ if ((rc == -1) && (errno == EINTR)) /* a signal was processed, ignore it */
+ continue;
+ n = read(fd, ptr + received, amount - received);
+ if (n == -1) { // error
+ if (errno == EINTR) // interrupted , try reading again
+ continue;
+ if (errno != EAGAIN) // genuine socket read error,
return
+ return -errno;
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/network.h Mon Oct 17 06:31:32
2011
+++ /branches/kkumar_code_organize/src/network.h Mon Oct 17 06:43:25
2011
@@ -17,9 +17,9 @@
#define OPT_IPV6_ONLY 1
#define OPT_IPV4_ONLY 2

-
I2Addr CreateListenSocket(I2Addr addr, char* serv, int options, int buf_size);
-int CreateConnectSocket(int* sockfd, I2Addr local_addr, I2Addr server_addr, int option, int buf_sizes);
+int CreateConnectSocket(int* sockfd, I2Addr local_addr, I2Addr server_addr,
+ int option, int buf_sizes);
int send_msg(int ctlSocket, int type, void* msg, int len);
int recv_msg(int ctlSocket, int* type, void* msg, int* len);
int writen(int fd, void* buf, int amount);
=======================================
--- /branches/kkumar_code_organize/src/protocol.c Mon Oct 17 06:31:32
2011
+++ /branches/kkumar_code_organize/src/protocol.c Mon Oct 17 06:43:25
2011
@@ -20,25 +20,24 @@
*
*/

-int
-check_msg_type(char* prefix, int expected, int received, char* buff, int len)
-{
- // check if expected and received messages are the same
- if (expected != received) {
- if (prefix) { // Add prefix to log message
- log_print(0, "%s: ", prefix);
- }
- if (received == MSG_ERROR) { // if Error message was actually received,
- // then its not an
unexpected message exchange
- buff[len] = 0; // terminate string
- log_println(0, "ERROR MSG: %s", buff);
- }
- else {
- // certainly an unexpected message
- log_println(0, "ERROR: received message type %d (expected %d)", received, expected);
- }
- return 1;
- }
- // everything is well, return 0
- return 0;
-}
+int check_msg_type(char* prefix, int expected, int received, char* buff,
+ int len) {
+ // check if expected and received messages are the same
+ if (expected != received) {
+ if (prefix) { // Add prefix to log message
+ log_print(0, "%s: ", prefix);
+ }
+ if (received == MSG_ERROR) { // if Error message was actually
received,
+ //
then its not an unexpected message exchange
+ buff[len] = 0; // terminate string
+ log_println(0, "ERROR MSG: %s", buff);
+ } else {
+ // certainly an unexpected message
+ log_println(0, "ERROR: received message type %d (expected
%d)",
+ received, expected);
+ }
+ return 1;
+ }
+ // everything is well, return 0
+ return 0;
+}
=======================================
--- /branches/kkumar_code_organize/src/protocol.h Fri Sep 30 21:38:03
2011
+++ /branches/kkumar_code_organize/src/protocol.h Mon Oct 17 06:43:25
2011
@@ -11,7 +11,6 @@

//new addition after separating out ndtptests header
#include "ndtptestconstants.h" //protocol validation
-
// Todo could be made into enumeration
#define COMM_FAILURE 0
#define SRV_QUEUE 1
@@ -26,14 +25,14 @@
#define MSG_WAITING 10

/*
-#define TEST_NONE 0
-#define TEST_MID (1L << 0)
-#define TEST_C2S (1L << 1)
-#define TEST_S2C (1L << 2)
-#define TEST_SFW (1L << 3)
-#define TEST_STATUS (1L << 4)
-#define TEST_META (1L << 5)
-*/
+ #define TEST_NONE 0
+ #define TEST_MID (1L << 0)
+ #define TEST_C2S (1L << 1)
+ #define TEST_S2C (1L << 2)
+ #define TEST_SFW (1L << 3)
+ #define TEST_STATUS (1L << 4)
+ #define TEST_META (1L << 5)
+ */

#define TOPT_DISABLED 0
#define TOPT_ENABLED 1
@@ -43,6 +42,7 @@
*/
#define VIEW_DIFF 0.1

-int check_msg_type(char* prefix, int expected, int received, char* buff, int len);
+int check_msg_type(char* prefix, int expected, int received, char* buff,
+ int len);

#endif
=======================================
--- /branches/kkumar_code_organize/src/runningtest.c Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/runningtest.c Mon Oct 17 06:43:25 2011
@@ -16,15 +16,12 @@
/**
* array defining possible events pertaining to process status
*/
-static char *_procstatusarray[] = { "unknown", "started",
- "completed" };
-
+static char *_procstatusarray[] = { "unknown", "started", "completed" };

/** array defining various "processes" like a web100srv process,
* or a client connection
*/
-static char *_proctypesarray[] = { "process", "connect"};
-
+static char *_proctypesarray[] = { "process", "connect" };

/**
* Get ID of currently running test
@@ -151,7 +148,7 @@
* */
char *get_processtypedesc(enum PROCESS_TYPE_INT procidarg, char *snamearg) {
snamearg = _proctypesarray[procidarg];
- printf ("--current process name = %s for %d\n", snamearg ,procidarg);
+ printf("--current process name = %s for %d\n", snamearg, procidarg);
return snamearg;
}

=======================================
--- /branches/kkumar_code_organize/src/runningtest.h Sun Oct 9 17:00:18 2011
+++ /branches/kkumar_code_organize/src/runningtest.h Mon Oct 17 06:43:25 2011
@@ -9,22 +9,24 @@
#define RUNNINGTEST_H_

#define PROCESS_STATUS_DESC_SIZE 17 // suffice to hold status defined below
-
// indicates the status of process like the web100srv or web100clt
//enum PROCESS_STATUS_INT { UNKNOWN, PROCESS_STARTED, PROCESS_ENDED };
-enum PROCESS_STATUS_INT { UNKNOWN, PROCESS_STARTED, PROCESS_ENDED };
-
-enum PROCESS_TYPE_INT { PROCESS_TYPE, CONNECT_TYPE };
-
+enum PROCESS_STATUS_INT {
+ UNKNOWN, PROCESS_STARTED, PROCESS_ENDED
+};
+
+enum PROCESS_TYPE_INT {
+ PROCESS_TYPE, CONNECT_TYPE
+};

int getCurrentTest();
void setCurrentTest(int testId);
-char *get_currenttestdesc ();
+char *get_currenttestdesc();
int getCurrentDirn();
void setCurrentDirn(enum Tx_DIRECTION directionarg);
int getCurrentDirn();
-char *get_currentdirndesc ();
-char *get_otherdirndesc ();
+char *get_currentdirndesc();
+char *get_otherdirndesc();
char *get_procstatusdesc(enum PROCESS_STATUS_INT procstatusarg, char *sprocarg);
char *get_processtypedesc(enum PROCESS_TYPE_INT procid, char *snamearg);

=======================================
--- /branches/kkumar_code_organize/src/strlutils.c Fri Oct 14 13:53:27
2011
+++ /branches/kkumar_code_organize/src/strlutils.c Mon Oct 17 06:43:25
2011
@@ -24,9 +24,7 @@
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
-size_t
-strlcpy(char *dst, const char *src, size_t siz)
-{
+size_t strlcpy(char *dst, const char *src, size_t siz) {
char *d = dst;
const char *s = src;
size_t n = siz;
@@ -42,12 +40,12 @@
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
- *d = '\0'; /* NUL-terminate dst */
+ *d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}

- return(s - src - 1); /* count does not include NUL */
+ return (s - src - 1); /* count does not include NUL */
}

/*
@@ -57,35 +55,30 @@
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
-size_t
-strlcat(dst, src, siz)
- char *dst;
- const char *src;
- size_t siz;
-{
- register char *d = dst;
- register const char *s = src;
- register size_t n = siz;
- size_t dlen;
-
- /* Find the end of dst and adjust bytes left but don't go past end */
- while (n-- != 0 && *d != '\0')
- d++;
- dlen = d - dst;
- n = siz - dlen;
-
- if (n == 0)
- return(dlen + strlen(s));
- while (*s != '\0') {
- if (n != 1) {
- *d++ = *s;
- n--;
- }
- s++;
- }
- *d = '\0';
-
- return(dlen + (s - src)); /* count does not include NUL */
+size_t strlcat(dst, src, siz)
+ char *dst;const char *src;size_t siz; {
+ register char *d = dst;
+ register const char *s = src;
+ register size_t n = siz;
+ size_t dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return (dlen + strlen(s));
+ while (*s != '\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
+ }
+ *d = '\0';
+
+ return (dlen + (s - src)); /* count does not include NUL */
}

-
=======================================
--- /branches/kkumar_code_organize/src/strlutils.h Fri Oct 14 13:53:27
2011
+++ /branches/kkumar_code_organize/src/strlutils.h Mon Oct 17 06:43:25
2011
@@ -1,4 +1,3 @@
-
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */

/*
@@ -34,5 +33,3 @@

#endif

-
-
=======================================
--- /branches/kkumar_code_organize/src/test_c2s_clt.c Tue Jun 30 09:17:48 2009
+++ /branches/kkumar_code_organize/src/test_c2s_clt.c Mon Oct 17 06:43:25 2011
@@ -22,118 +22,116 @@
int sndqueue;
double spdout, c2sspd;

-int
-test_c2s_clt(int ctlSocket, char tests, char* host, int conn_options, int buf_size)
-{
- /* char buff[BUFFSIZE+1]; */
- char buff[64*1024];
- int msgLen, msgType;
- int c2sport = 3002;
- I2Addr sec_addr = NULL;
- int ret, one=1, i, k;
- int outSocket;
- double t, stop_time;
-
- if (tests & TEST_C2S) {
- struct sigaction new, old;
- log_println(1, " <-- C2S 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("C2S throughput test", TEST_PREPARE, msgType, buff, msgLen)) {
- return 2;
- }
- if (msgLen <= 0) {
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- if (check_int(buff, &c2sport)) {
- log_println(0, "Invalid port number");
- return 4;
- }
- log_println(1, " -- port: %d", c2sport);
-
- if ((sec_addr = I2AddrByNode(get_errhandle(), host)) == NULL) {
- log_println(0, "Unable to resolve server address: %s", strerror(errno));
- return -3;
- }
- I2AddrSetPort(sec_addr, c2sport);
-
- if ((ret = CreateConnectSocket(&outSocket, NULL, sec_addr, conn_options, buf_size))) {
- log_println(0, "Connect() for client to server failed", strerror(errno));
- return -11;
- }
-
- setsockopt(outSocket, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
-
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed start message!");
- return 1;
- }
- if (check_msg_type("C2S throughput test", TEST_START, msgType, buff, msgLen)) {
- return 2;
- }
-
- printf("running 10s outbound test (client to server) . . . . . ");
- fflush(stdout);
-
- pkts = 0;
- k = 0;
- for (i=0; i<(64*1024); i++) {
- while (!isprint(k&0x7f))
- k++;
- buff[i] = (k++ % 0x7f);
- }
- t = secs();
- stop_time = t + 10;
- /* ignore the pipe signal */
- memset(&new, 0, sizeof(new));
- new.sa_handler = SIG_IGN;
- sigaction(SIGPIPE, &new, &old);
- do {
- write(outSocket, buff, lth);
- pkts++;
- } while (secs() < stop_time);
- sigaction(SIGPIPE, &old, NULL);
- sndqueue = sndq_len(outSocket);
- t = secs() - t;
- I2AddrFree(sec_addr);
- spdout = ((8.0 * pkts * lth) / 1000) / t;
-
- /* receive the c2sspd from the server */
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed text message!");
- return 1;
- }
- if (check_msg_type("C2S throughput test", TEST_MSG, msgType, buff, msgLen)) {
- return 2;
- }
- if (msgLen <= 0) {
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- c2sspd = atoi(buff);
-
- if (c2sspd < 1000)
- printf(" %0.2f kb/s\n", c2sspd);
- else
- printf(" %0.2f Mb/s\n", c2sspd/1000);
-
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed finalize message!");
- return 1;
- }
- if (check_msg_type("C2S throughput test", TEST_FINALIZE, msgType, buff, msgLen)) {
- return 2;
- }
- log_println(1, " <------------------------->");
- }
- return 0;
-}
+int test_c2s_clt(int ctlSocket, char tests, char* host, int conn_options,
+ int buf_size) {
+ /* char buff[BUFFSIZE+1]; */
+ char buff[64 * 1024];int msgLen, msgType;
+ int c2sport = 3002;
+ I2Addr sec_addr = NULL;
+ int ret, one=1, i, k;
+ int outSocket;
+ double t, stop_time;
+
+ if (tests & TEST_C2S) {
+ struct sigaction new, old;
+ log_println(1, " <-- C2S 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("C2S throughput test", TEST_PREPARE, msgType, buff, msgLen)) {
+ return 2;
+ }
+ if (msgLen <= 0) {
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
+ if (check_int(buff, &c2sport)) {
+ log_println(0, "Invalid port number");
+ return 4;
+ }
+ log_println(1, " -- port: %d", c2sport);
+
+ if ((sec_addr = I2AddrByNode(get_errhandle(), host)) == NULL)
{
+ log_println(0, "Unable to resolve server address:
%s", strerror(errno));
+ return -3;
+ }
+ I2AddrSetPort(sec_addr, c2sport);
+
+ if ((ret = CreateConnectSocket(&outSocket, NULL, sec_addr, conn_options, buf_size))) {
+ log_println(0, "Connect() for client to server failed", strerror(errno));
+ return -11;
+ }
+
+ setsockopt(outSocket, SOL_SOCKET, SO_REUSEADDR, &one,
sizeof(one));
+
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed start
message!");
+ return 1;
+ }
+ if (check_msg_type("C2S throughput test", TEST_START, msgType, buff, msgLen)) {
+ return 2;
+ }
+
+ printf("running 10s outbound test (client to server) . . . . .
");
+ fflush(stdout);
+
+ pkts = 0;
+ k = 0;
+ for (i=0; i<(64*1024); i++) {
+ while (!isprint(k&0x7f))
+ k++;
+ buff[i] = (k++ % 0x7f);
+ }
+ t = secs();
+ stop_time = t + 10;
+ /* ignore the pipe signal */
+ memset(&new, 0, sizeof(new));
+ new.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &new, &old);
+ do {
+ write(outSocket, buff, lth);
+ pkts++;
+ }while (secs() < stop_time);
+ sigaction(SIGPIPE, &old, NULL);
+ sndqueue = sndq_len(outSocket);
+ t = secs() - t;
+ I2AddrFree(sec_addr);
+ spdout = ((8.0 * pkts * lth) / 1000) / t;
+
+ /* receive the c2sspd from the server */
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed text
message!");
+ return 1;
+ }
+ if (check_msg_type("C2S throughput test", TEST_MSG, msgType, buff, msgLen)) {
+ return 2;
+ }
+ if (msgLen <= 0) {
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
+ c2sspd = atoi(buff);
+
+ if (c2sspd < 1000)
+ printf(" %0.2f kb/s\n", c2sspd);
+ else
+ printf(" %0.2f Mb/s\n", c2sspd/1000);
+
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed finalize
message!");
+ return 1;
+ }
+ if (check_msg_type("C2S throughput test", TEST_FINALIZE, msgType, buff, msgLen)) {
+ return 2;
+ }
+ log_println(1, " <------------------------->");
+ }
+ return 0;
+}
=======================================
--- /branches/kkumar_code_organize/src/test_meta_clt.c Sun May 8 04:04:21 2011
+++ /branches/kkumar_code_organize/src/test_meta_clt.c Mon Oct 17 06:43:25 2011
@@ -24,73 +24,71 @@
int sndqueue;
double spdout, c2sspd;

-int
-test_meta_clt(int ctlSocket, char tests, char* host, int conn_options)
-{
- char buff[1024], tmpBuff[512];
- int msgLen, msgType;
- FILE *fp;
-
- if (tests & TEST_META) {
- log_println(1, " <-- META 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("META test", TEST_PREPARE, msgType, buff, msgLen)) {
- return 2;
- }
-
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed start message!");
- return 1;
- }
- if (check_msg_type("META test", TEST_START, msgType, buff, msgLen)) {
- return 2;
- }
-
- printf("sending meta information to server . . . . . ");
- fflush(stdout);
-
- if ((fp = fopen("/proc/sys/kernel/ostype", "r")) == NULL) {
- log_println(0, "Unable to determine client os type.");
- } else {
- fscanf(fp, "%s", tmpBuff);
- fclose(fp);
- sprintf(buff, "%s:%s", META_CLIENT_OS, tmpBuff);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
- }
-
- sprintf(buff, "%s:%s", META_BROWSER_OS, "- (web100clt)");
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
-
- if ((fp = fopen("/proc/sys/kernel/osrelease", "r")) == NULL) {
- log_println(0, "Unable to determine client kernel version.");
- } else {
- fscanf(fp, "%s", tmpBuff);
- fclose(fp);
- sprintf(buff, "%s:%s", META_CLIENT_KERNEL_VERSION, tmpBuff);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
- }
-
- sprintf(buff, "%s:%s", META_CLIENT_VERSION, VERSION);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
-
- send_msg(ctlSocket, TEST_MSG, "", 0);
-
- printf("Done\n");
-
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed finalize message!");
- return 1;
- }
- if (check_msg_type("META test", TEST_FINALIZE, msgType, buff, msgLen)) {
- return 2;
- }
- log_println(1, " <------------------------->");
- }
- return 0;
-}
+int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options) {
+ char buff[1024], tmpBuff[512];
+ int msgLen, msgType;
+ FILE * fp;
+
+ if (tests & TEST_META) {
+ log_println(1, " <-- META 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("META test", TEST_PREPARE, msgType, buff,
msgLen)) {
+ return 2;
+ }
+
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed start
message!");
+ return 1;
+ }
+ if (check_msg_type("META test", TEST_START, msgType, buff,
msgLen)) {
+ return 2;
+ }
+
+ printf("sending meta information to server . . . . . ");
+ fflush(stdout);
+
+ if ((fp = fopen("/proc/sys/kernel/ostype", "r")) == NULL) {
+ log_println(0, "Unable to determine client os type.");
+ } else {
+ fscanf(fp, "%s", tmpBuff);
+ fclose(fp);
+ sprintf(buff, "%s:%s", META_CLIENT_OS, tmpBuff);
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ }
+
+ sprintf(buff, "%s:%s", META_BROWSER_OS, "- (web100clt)");
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+
+ if ((fp = fopen("/proc/sys/kernel/osrelease", "r")) == NULL) {
+ log_println(0, "Unable to determine client kernel
version.");
+ } else {
+ fscanf(fp, "%s", tmpBuff);
+ fclose(fp);
+ sprintf(buff, "%s:%s", META_CLIENT_KERNEL_VERSION,
tmpBuff);
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ }
+
+ sprintf(buff, "%s:%s", META_CLIENT_VERSION, VERSION);
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+
+ send_msg(ctlSocket, TEST_MSG, "", 0);
+
+ printf("Done\n");
+
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed finalize
message!");
+ return 1;
+ }
+ if (check_msg_type("META test", TEST_FINALIZE, msgType, buff,
msgLen)) {
+ return 2;
+ }
+ log_println(1, " <------------------------->");
+ }
+ return 0;
+}
=======================================
--- /branches/kkumar_code_organize/src/test_meta_srv.c Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/test_meta_srv.c Mon Oct 17 06:43:25 2011
@@ -38,119 +38,120 @@
* 4 - Invalid data format in received message
*/

-int
-test_meta_srv(int ctlsockfd, web100_agent* agent, TestOptions* testOptions, int conn_options)
-{
- int j;
- int msgLen, msgType;
- char buff[BUFFSIZE+1];
- struct metaentry *new_entry = NULL;
- char* value;
-
- // protocol validation logs
- enum TEST_ID testids = META;
- enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
-
- if (testOptions->metaopt) {
- setCurrentTest(TEST_META);
- log_println(1, " <-- META test -->");
-
- // log protocol validation details
- teststatuses = TEST_STARTED;
- protolog_status(testOptions->child0, testids, teststatuses);
-
- // first message exchanged is am empty TEST_PREPARE message
- j = send_msg(ctlsockfd, TEST_PREPARE, "", 0);
- if (j == -1 || j == -2) { // Cannot write message headers/data
- log_println(6, "META Error!, Test start message not sent!");
- return j;
- }
-
- // Now, transmit an empty TEST_START message
- if (send_msg(ctlsockfd, TEST_START, "", 0) < 0) {
- log_println(6, "META test - Test-start message failed");
- }
-
- while (1) {
- msgLen = sizeof(buff);
- // Now read the meta data sent by client.
-
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- // message reading error
- log_println(0, "Protocol error!");
- sprintf(buff, "Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return 1;
- }
- if (check_msg_type("META test", TEST_MSG, msgType, buff, msgLen)) {
- // expected a TEST_MSG only
- log_println(0, "Fault, unexpected message received!");
- sprintf(buff, "Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return 2;
- }
- if (msgLen < 0) {
- // meta data should be present at this stage
- log_println(0, "Improper message");
- sprintf(buff, "Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return 3;
- }
-
- // Received empty TEST_MSG. All meta_data has been received, and test
- // can be finalized.
- if (msgLen == 0) {
- break;
- }
-
- buff[msgLen] = 0;
- value = index(buff, ':');
- if (value == NULL) { // key-value separates by ":"
- log_println(0, "Improper message");
- sprintf(buff, "Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return 4;
- }
- *value = 0;
- value++;
-
- // get the recommended set of data expected: client os name , client browser name,
- //why not if else-if for the whole set? TODO
- if (strcmp(META_CLIENT_OS, buff) == 0) {
- snprintf(meta.client_os, sizeof(meta.client_os), "%s", value);
- /*continue;*/
- }
-
- if (strcmp(META_BROWSER_OS, buff) == 0) {
- snprintf(meta.client_browser, sizeof(meta.client_browser), "%s", value);
- /*continue;*/
- }
-
- // now get all the key-value tuples
- if (new_entry) {
- new_entry->next = (struct metaentry *) malloc(sizeof(struct metaentry));
- new_entry = new_entry->next;
- }
- else {
- new_entry = (struct metaentry *) malloc(sizeof(struct metaentry));
- meta.additional = new_entry;
- }
- snprintf(new_entry->key, sizeof(new_entry->key), "%s", buff);
- snprintf(new_entry->value, sizeof(new_entry->value), "%s", value);
- }
-
- // Finalize test by sending appropriate message, and setting status
- if (send_msg(ctlsockfd, TEST_FINALIZE, "", 0) < 0) {
- log_println(6, "META test - failed to send finalize message");
- }
-
- //log end of test and conclude
- log_println(1, " <-------------------------->");
-
- teststatuses = TEST_ENDED; // protocol log section
- protolog_status(testOptions->child0, testids, teststatuses);
-
- setCurrentTest(TEST_NONE);
- }
- return 0;
-}
+int test_meta_srv(int ctlsockfd, web100_agent* agent, TestOptions* testOptions,
+ int conn_options) {
+ int j;
+ int msgLen, msgType;
+ char buff[BUFFSIZE + 1];struct
+metaentry *new_entry = NULL;
+ char* value;
+
+ // protocol validation logs
+ enum TEST_ID testids = META;
+ enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
+
+ if (testOptions->metaopt) {
+ setCurrentTest(TEST_META);
+ log_println(1, " <-- META test -->");
+
+ // log protocol validation details
+ teststatuses = TEST_STARTED;
+ protolog_status(testOptions->child0, testids, teststatuses);
+
+ // first message exchanged is am empty TEST_PREPARE message
+ j = send_msg(ctlsockfd, TEST_PREPARE, "", 0);
+ if (j == -1 || j == -2) { // Cannot write message headers/data
+ log_println(6, "META Error!, Test start message not
sent!");
+ return j;
+ }
+
+ // Now, transmit an empty TEST_START message
+ if (send_msg(ctlsockfd, TEST_START, "", 0) < 0) {
+ log_println(6, "META test - Test-start message
failed");
+ }
+
+ while (1) {
+ msgLen = sizeof(buff);
+ // Now read the meta data sent by client.
+
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ // message reading error
+ log_println(0, "Protocol error!");
+ sprintf(buff, "Server (META test): Invalid meta
data received");
+ send_msg(ctlsockfd, MSG_ERROR, buff,
strlen(buff));
+ return 1;
+ }
+ if (check_msg_type("META test", TEST_MSG, msgType,
buff, msgLen)) {
+ // expected a TEST_MSG only
+ log_println(0, "Fault, unexpected message
received!");
+ sprintf(buff, "Server (META test): Invalid meta
data received");
+ send_msg(ctlsockfd, MSG_ERROR, buff,
strlen(buff));
+ return 2;
+ }
+ if (msgLen < 0) {
+ // meta data should be present at this stage
+ log_println(0, "Improper message");
+ sprintf(buff, "Server (META test): Invalid meta
data received");
+ send_msg(ctlsockfd, MSG_ERROR, buff,
strlen(buff));
+ return 3;
+ }
+
+ // Received empty TEST_MSG. All meta_data has been
received, and test
+ // can be finalized.
+ if (msgLen == 0) {
+ break;
+ }
+
+ buff[msgLen] = 0;
+ value = index(buff, ':');
+ if (value == NULL) { // key-value separates by ":"
+ log_println(0, "Improper message");
+ sprintf(buff, "Server (META test): Invalid meta
data received");
+ send_msg(ctlsockfd, MSG_ERROR, buff,
strlen(buff));
+ return 4;
+ }
+ *value = 0;
+ value++;
+
+ // get the recommended set of data expected: client os name , client browser name,
+ //why not if else-if for the whole set? TODO
+ if (strcmp(META_CLIENT_OS, buff) == 0) {
+ snprintf(meta.client_os, sizeof(meta.client_os),
"%s", value);
+ /*continue;*/
+ }
+
+ if (strcmp(META_BROWSER_OS, buff) == 0) {
+ snprintf(meta.client_browser,
sizeof(meta.client_browser), "%s",
+ value);
+ /*continue;*/
+ }
+
+ // now get all the key-value tuples
+ if (new_entry) {
+ new_entry->next = (struct metaentry *) malloc(
+ sizeof(struct metaentry));
+ new_entry = new_entry->next;
+ } else {
+ new_entry = (struct metaentry *) malloc(
+ sizeof(struct metaentry));
+ meta.additional = new_entry;
+ }
+ snprintf(new_entry->key, sizeof(new_entry->key),
"%s", buff);
+ snprintf(new_entry->value, sizeof(new_entry->value),
"%s", value);
+ }
+
+ // Finalize test by sending appropriate message, and setting
status
+ if (send_msg(ctlsockfd, TEST_FINALIZE, "", 0) < 0) {
+ log_println(6, "META test - failed to send finalize
message");
+ }
+
+ //log end of test and conclude
+ log_println(1, " <-------------------------->");
+
+ teststatuses = TEST_ENDED; // protocol log section
+ protolog_status(testOptions->child0, testids, teststatuses);
+
+ setCurrentTest(TEST_NONE);
+ }
+ return 0;
+}
=======================================
--- /branches/kkumar_code_organize/src/test_mid_clt.c Fri Oct 14 13:52:19 2011
+++ /branches/kkumar_code_organize/src/test_mid_clt.c Mon Oct 17 06:43:25 2011
@@ -16,120 +16,118 @@
#include "protocol.h"
#include "utils.h"

-int
-test_mid_clt(int ctlSocket, char tests, char* host, int conn_options, int buf_size, char* tmpstr2)
-{
- char buff[BUFFSIZE+1];
- int msgLen, msgType;
- int midport = 3003;
- I2Addr sec_addr = NULL;
- int ret, one=1, i, inlth;
- int in2Socket;
- double t, spdin;
- uint32_t bytes;
- struct timeval sel_tv;
- fd_set rfd;
-
- if (tests & TEST_MID) {
- log_println(1, " <-- Middlebox 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("Middlebox test", TEST_PREPARE, msgType, buff, msgLen)) {
- return 2;
- }
- if (msgLen <= 0) {
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- if (check_int(buff, &midport)) {
- log_println(0, "Invalid port number");
- return 4;
- }
- log_println(1, " -- port: %d", midport);
- if ((sec_addr = I2AddrByNode(get_errhandle(), host)) == NULL) {
- log_println(0, "Unable to resolve server address: %s", strerror(errno));
- return -3;
- }
- I2AddrSetPort(sec_addr, midport);
-
- if (get_debuglvl() > 4) {
- char tmpbuff[200];
- size_t tmpBufLen = 199;
- memset(tmpbuff, 0, 200);
- I2AddrNodeName(sec_addr, tmpbuff, &tmpBufLen);
- log_println(5, "connecting to %s:%d", tmpbuff, I2AddrPort(sec_addr));
- }
-
- if ((ret = CreateConnectSocket(&in2Socket, NULL, sec_addr, conn_options, buf_size))) {
- log_println(0, "Connect() for middlebox failed: %s", strerror(errno));
- return -10;
- }
-
- printf("Checking for Middleboxes . . . . . . . . . . . . . . . . . . ");
- fflush(stdout);
- tmpstr2[0] = '\0';
- i = 0;
- bytes = 0;
- t = secs() + 5.0;
- sel_tv.tv_sec = 6;
- sel_tv.tv_usec = 5;
- FD_ZERO(&rfd);
- FD_SET(in2Socket, &rfd);
- for (;;) {
- if (secs() > t)
- break;
- ret = select(in2Socket+1, &rfd, NULL, NULL, &sel_tv);
- if (ret > 0) {
- inlth = read(in2Socket, buff, sizeof(buff));
- if (inlth == 0)
- break;
- bytes += inlth;
- continue;
- }
- if (ret < 0) {
- printf("nothing to read, exiting read loop\n");
- break;
- }
- if (ret == 0) {
- printf("timer expired, exiting read loop\n");
- break;
- }
- }
- t = secs() - t + 5.0;
- spdin = ((8.0 * bytes) / 1000) / t;
-
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed text message!");
- return 1;
- }
- if (check_msg_type("Middlebox test results", TEST_MSG, msgType, buff, msgLen)) {
- return 2;
- }
- //strncat(tmpstr2, buff, msgLen);
- strlcat(tmpstr2, buff, 512); //todo hardcoded size for now
-
- memset(buff, 0, 128);
- sprintf(buff, "%0.0f", spdin);
- log_println(4, "CWND limited speed = %0.2f kbps", spdin);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
- printf("Done\n");
-
- I2AddrFree(sec_addr);
-
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed finalize message!");
- return 1;
- }
- if (check_msg_type("Middlebox test", TEST_FINALIZE, msgType, buff, msgLen)) {
- return 2;
- }
- log_println(1, " <-------------------->");
- }
- return 0;
-}
+int test_mid_clt(int ctlSocket, char tests, char* host, int conn_options,
+ int buf_size, char* tmpstr2) {
+ char buff[BUFFSIZE + 1];int msgLen, msgType;
+ int midport = 3003;
+ I2Addr sec_addr = NULL;
+ int ret, one=1, i, inlth;
+ int in2Socket;
+ double t, spdin;
+ uint32_t bytes;
+ struct timeval sel_tv;
+ fd_set rfd;
+
+ if (tests & TEST_MID) {
+ log_println(1, " <-- Middlebox 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("Middlebox test", TEST_PREPARE, msgType, buff, msgLen)) {
+ return 2;
+ }
+ if (msgLen <= 0) {
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
+ if (check_int(buff, &midport)) {
+ log_println(0, "Invalid port number");
+ return 4;
+ }
+ log_println(1, " -- port: %d", midport);
+ if ((sec_addr = I2AddrByNode(get_errhandle(), host)) == NULL)
{
+ log_println(0, "Unable to resolve server address:
%s", strerror(errno));
+ return -3;
+ }
+ I2AddrSetPort(sec_addr, midport);
+
+ if (get_debuglvl() > 4) {
+ char tmpbuff[200];
+ size_t tmpBufLen = 199;
+ memset(tmpbuff, 0, 200);
+ I2AddrNodeName(sec_addr, tmpbuff, &tmpBufLen);
+ log_println(5, "connecting to %s:%d", tmpbuff,
I2AddrPort(sec_addr));
+ }
+
+ if ((ret = CreateConnectSocket(&in2Socket, NULL, sec_addr, conn_options, buf_size))) {
+ log_println(0, "Connect() for middlebox failed: %s",
strerror(errno));
+ return -10;
+ }
+
+ printf("Checking for Middleboxes . . . . . . . . . . . . . . . . .
. ");
+ fflush(stdout);
+ tmpstr2[0] = '\0';
+ i = 0;
+ bytes = 0;
+ t = secs() + 5.0;
+ sel_tv.tv_sec = 6;
+ sel_tv.tv_usec = 5;
+ FD_ZERO(&rfd);
+ FD_SET(in2Socket, &rfd);
+ for (;;) {
+ if (secs() > t)
+ break;
+ ret = select(in2Socket+1, &rfd, NULL, NULL, &sel_tv);
+ if (ret > 0) {
+ inlth = read(in2Socket, buff, sizeof(buff));
+ if (inlth == 0)
+ break;
+ bytes += inlth;
+ continue;
+ }
+ if (ret < 0) {
+ printf("nothing to read, exiting read
loop\n");
+ break;
+ }
+ if (ret == 0) {
+ printf("timer expired, exiting read loop\n");
+ break;
+ }
+ }
+ t = secs() - t + 5.0;
+ spdin = ((8.0 * bytes) / 1000) / t;
+
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed text
message!");
+ return 1;
+ }
+ if (check_msg_type("Middlebox test results", TEST_MSG, msgType, buff, msgLen)) {
+ return 2;
+ }
+ //strncat(tmpstr2, buff, msgLen);
+ strlcat(tmpstr2, buff, 512);//todo hardcoded size for now
+
+ memset(buff, 0, 128);
+ sprintf(buff, "%0.0f", spdin);
+ log_println(4, "CWND limited speed = %0.2f kbps", spdin);
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ printf("Done\n");
+
+ I2AddrFree(sec_addr);
+
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed finalize
message!");
+ return 1;
+ }
+ if (check_msg_type("Middlebox test", TEST_FINALIZE, msgType, buff, msgLen)) {
+ return 2;
+ }
+ log_println(1, " <-------------------->");
+ }
+ return 0;
+}
=======================================
--- /branches/kkumar_code_organize/src/test_s2c_clt.c Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/test_s2c_clt.c Mon Oct 17 06:43:25 2011
@@ -19,176 +19,173 @@
int ssndqueue, sbytes;
double spdin, s2cspd;

-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;
- I2Addr sec_addr = NULL;
- int inlth, ret, one=1, set_size;
- int inSocket;
- socklen_t optlen;
- uint32_t bytes;
- double t;
- struct timeval sel_tv;
- fd_set rfd;
- char* ptr;
-
- if (tests & TEST_S2C) {
- 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)) {
- return 2;
- }
- if (msgLen <= 0) {
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- if (check_int(buff, &s2cport)) {
- log_println(0, "Invalid port number");
- return 4;
- }
- log_println(1, " -- port: %d", s2cport);
-
- /* Cygwin seems to want/need this extra getsockopt() function
- * call. It certainly doesn't do anything, but the S2C test fails
- * at the connect() call if it's not there. 4/14/05 RAC
- */
- optlen = sizeof(set_size);
- getsockopt(ctlSocket, SOL_SOCKET, SO_SNDBUF, &set_size, &optlen);
-
- 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))) {
- log_println(0, "Connect() for Server to Client failed", strerror(errno));
- return -15;
- }
-
- setsockopt(inSocket, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
-
- /* Linux updates the sel_tv time values everytime select returns. This
- * means that eventually the timer will reach 0 seconds and select will
- * exit with a timeout signal. Other OS's don't do that so they need
- * another method for detecting a long-running process. The check below
- * will cause the loop to terminate if select says there is something
- * to read and the loop has been active for over 14 seconds. This usually
- * happens when there is a problem (duplex mismatch) and there is data
- * queued up on the server.
- */
-
- 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)) {
- return 2;
- }
-
- printf("running 10s inbound test (server to client) . . . . . . ");
- fflush(stdout);
-
- bytes = 0;
- t = secs() + 15.0;
- sel_tv.tv_sec = 15;
- sel_tv.tv_usec = 5;
- FD_ZERO(&rfd);
- FD_SET(inSocket, &rfd);
- for (;;) {
- ret = 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) {
- inlth = read(inSocket, buff, sizeof(buff));
- if (inlth == 0)
- break;
- bytes += inlth;
- continue;
- }
- if (get_debuglvl() > 5) {
- log_println(0, "s2c read loop exiting:", strerror(errno));
- }
- break;
- }
- t = secs() - t + 15.0;
- spdin = ((8.0 * bytes) / 1000) / t;
-
- /* receive the s2cspd from the server */
- 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 (msgLen <= 0) {
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- ptr = strtok(buff, " ");
- if (ptr == NULL) {
- log_println(0, "S2C: Improper message");
- return 4;
- }
- s2cspd = atoi(ptr);
- ptr = strtok(NULL, " ");
- if (ptr == NULL) {
- log_println(0, "S2C: Improper message");
- return 4;
- }
- ssndqueue = atoi(ptr);
- ptr = strtok(NULL, " ");
- if (ptr == NULL) {
- log_println(0, "S2C: Improper message");
- return 4;
- }
- sbytes = atoi(ptr);
-
- if (spdin < 1000)
- printf("%0.2f kb/s\n", spdin);
- else
- printf("%0.2f Mb/s\n", spdin/1000);
-
- I2AddrFree(sec_addr);
-
- sprintf(buff, "%0.0f", spdin);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
-
- /* get web100 variables from server */
- tmpstr[0] = '\0';
- for (;;) {
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed text/finalize message!");
- return 1;
- }
- if (msgType == TEST_FINALIZE) {
- break;
- }
- if (check_msg_type("S2C throughput test", 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);
- log_println(1, " <------------------------->");
- }
-
-
- return 0;
-}
+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;
+ I2Addr sec_addr = NULL;
+ int inlth, ret, one=1, set_size;
+ int inSocket;
+ socklen_t optlen;
+ uint32_t bytes;
+ double t;
+ struct timeval sel_tv;
+ fd_set rfd;
+ char* ptr;
+
+ if (tests & TEST_S2C) {
+ 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)) {
+ return 2;
+ }
+ if (msgLen <= 0) {
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
+ if (check_int(buff, &s2cport)) {
+ log_println(0, "Invalid port number");
+ return 4;
+ }
+ log_println(1, " -- port: %d", s2cport);
+
+ /* Cygwin seems to want/need this extra getsockopt() function
+ * call. It certainly doesn't do anything, but the S2C test
fails
+ * at the connect() call if it's not there. 4/14/05 RAC
+ */
+ optlen = sizeof(set_size);
+ getsockopt(ctlSocket, SOL_SOCKET, SO_SNDBUF, &set_size,
&optlen);
+
+ 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))) {
+ log_println(0, "Connect() for Server to Client failed", strerror(errno));
+ return -15;
+ }
+
+ setsockopt(inSocket, SOL_SOCKET, SO_REUSEADDR, &one,
sizeof(one));
+
+ /* Linux updates the sel_tv time values everytime select
returns. This
+ * means that eventually the timer will reach 0 seconds and
select will
+ * exit with a timeout signal. Other OS's don't do that so
they need
+ * another method for detecting a long-running process. The
check below
+ * will cause the loop to terminate if select says there is
something
+ * to read and the loop has been active for over 14 seconds. This usually
+ * happens when there is a problem (duplex mismatch) and
there is data
+ * queued up on the server.
+ */
+
+ 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)) {
+ return 2;
+ }
+
+ printf("running 10s inbound test (server to client) . . . . . .
");
+ fflush(stdout);
+
+ bytes = 0;
+ t = secs() + 15.0;
+ sel_tv.tv_sec = 15;
+ sel_tv.tv_usec = 5;
+ FD_ZERO(&rfd);
+ FD_SET(inSocket, &rfd);
+ for (;;) {
+ ret = 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) {
+ inlth = read(inSocket, buff, sizeof(buff));
+ if (inlth == 0)
+ break;
+ bytes += inlth;
+ continue;
+ }
+ if (get_debuglvl() > 5) {
+ log_println(0, "s2c read loop exiting:",
strerror(errno));
+ }
+ break;
+ }
+ t = secs() - t + 15.0;
+ spdin = ((8.0 * bytes) / 1000) / t;
+
+ /* receive the s2cspd from the server */
+ 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 (msgLen <= 0) {
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
+ ptr = strtok(buff, " ");
+ if (ptr == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ s2cspd = atoi(ptr);
+ ptr = strtok(NULL, " ");
+ if (ptr == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ ssndqueue = atoi(ptr);
+ ptr = strtok(NULL, " ");
+ if (ptr == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ sbytes = atoi(ptr);
+
+ if (spdin < 1000)
+ printf("%0.2f kb/s\n", spdin);
+ else
+ printf("%0.2f Mb/s\n", spdin/1000);
+
+ I2AddrFree(sec_addr);
+
+ sprintf(buff, "%0.0f", spdin);
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+
+ /* get web100 variables from server */
+ tmpstr[0] = '\0';
+ for (;;) {
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed
text/finalize message!");
+ return 1;
+ }
+ if (msgType == TEST_FINALIZE) {
+ break;
+ }
+ if (check_msg_type("S2C throughput test", 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);
+ log_println(1, " <------------------------->");
+ }
+
+ return 0;
+}
=======================================
--- /branches/kkumar_code_organize/src/test_sfw_clt.c Tue Jun 30 09:17:48 2009
+++ /branches/kkumar_code_organize/src/test_sfw_clt.c Mon Oct 17 06:43:25 2011
@@ -31,14 +31,12 @@
* Arguments: signo - the signal number (shuld be SIGALRM)
*/

-void
-catch_alrm(int signo)
-{
- if (signo == SIGALRM) {
- log_println(1, "SIGALRM was caught");
- return;
- }
- log_println(0, "Unknown (%d) signal was caught", signo);
+void catch_alrm(int signo) {
+ if (signo == SIGALRM) {
+ log_println(1, "SIGALRM was caught");
+ return;
+ }
+ log_println(0, "Unknown (%d) signal was caught", signo);
}

/*
@@ -48,69 +46,67 @@
*/

void*
-test_osfw_clt(void* vptr)
-{
- char buff[BUFFSIZE+1];
- int sockfd;
- fd_set fds;
- struct timeval sel_tv;
- int msgLen, msgType;
- struct sockaddr_storage srv_addr;
- socklen_t srvlen;
-
- FD_ZERO(&fds);
- FD_SET(sfwsockfd, &fds);
- sel_tv.tv_sec = testTime;
- sel_tv.tv_usec = 0;
- switch (select(sfwsockfd+1, &fds, NULL, NULL, &sel_tv)) {
- case -1:
- log_println(0, "Simple firewall test: select exited with error");
- I2AddrFree(sfwcli_addr);
- return NULL;
- case 0:
- log_println(1, "Simple firewall test: no connection for %d seconds", testTime);
- s2c_result = SFW_POSSIBLE;
- I2AddrFree(sfwcli_addr);
- return NULL;
- }
- srvlen = sizeof(srv_addr);
- sockfd = accept(sfwsockfd, (struct sockaddr *) &srv_addr, &srvlen);
-
- msgLen = sizeof(buff);
- if (recv_msg(sockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Simple firewall test: unrecognized message");
- s2c_result = SFW_UNKNOWN;
- close(sockfd);
- I2AddrFree(sfwcli_addr);
- return NULL;
- }
- if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
- s2c_result = SFW_UNKNOWN;
- close(sockfd);
- I2AddrFree(sfwcli_addr);
- return NULL;
- }
- if (msgLen != 20) {
- log_println(0, "Simple firewall test: Improper message");
- s2c_result = SFW_UNKNOWN;
- close(sockfd);
- I2AddrFree(sfwcli_addr);
- return NULL;
- }
- buff[msgLen] = 0;
- if (strcmp(buff, "Simple firewall test") != 0) {
- log_println(0, "Simple firewall test: Improper message");
- s2c_result = SFW_UNKNOWN;
- close(sockfd);
- I2AddrFree(sfwcli_addr);
- return NULL;
- }
-
- s2c_result = SFW_NOFIREWALL;
- close(sockfd);
- I2AddrFree(sfwcli_addr);
-
- return NULL;
+test_osfw_clt(void* vptr) {
+ char buff[BUFFSIZE + 1];int sockfd;
+ fd_set fds;
+ struct timeval sel_tv;
+ int msgLen, msgType;
+ struct sockaddr_storage srv_addr;
+ socklen_t srvlen;
+
+ FD_ZERO(&fds);
+ FD_SET(sfwsockfd, &fds);
+ sel_tv.tv_sec = testTime;
+ sel_tv.tv_usec = 0;
+ switch (select(sfwsockfd+1, &fds, NULL, NULL, &sel_tv)) {
+ case -1:
+ log_println(0, "Simple firewall test: select exited with
error");
+ I2AddrFree(sfwcli_addr);
+ return NULL;
+ case 0:
+ log_println(1, "Simple firewall test: no connection for %d seconds", testTime);
+ s2c_result = SFW_POSSIBLE;
+ I2AddrFree(sfwcli_addr);
+ return NULL;
+ }
+ srvlen = sizeof(srv_addr);
+ sockfd = accept(sfwsockfd, (struct sockaddr *) &srv_addr, &srvlen);
+
+ msgLen = sizeof(buff);
+ if (recv_msg(sockfd, &msgType, buff, &msgLen)) {
+ log_println(0, "Simple firewall test: unrecognized message");
+ s2c_result = SFW_UNKNOWN;
+ close(sockfd);
+ I2AddrFree(sfwcli_addr);
+ return NULL;
+ }
+ if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
+ s2c_result = SFW_UNKNOWN;
+ close(sockfd);
+ I2AddrFree(sfwcli_addr);
+ return NULL;
+ }
+ if (msgLen != 20) {
+ log_println(0, "Simple firewall test: Improper message");
+ s2c_result = SFW_UNKNOWN;
+ close(sockfd);
+ I2AddrFree(sfwcli_addr);
+ return NULL;
+ }
+ buff[msgLen] = 0;
+ if (strcmp(buff, "Simple firewall test") != 0) {
+ log_println(0, "Simple firewall test: Improper message");
+ s2c_result = SFW_UNKNOWN;
+ close(sockfd);
+ I2AddrFree(sfwcli_addr);
+ return NULL;
+ }
+
+ s2c_result = SFW_NOFIREWALL;
+ close(sockfd);
+ I2AddrFree(sfwcli_addr);
+
+ return NULL;
}

/*
@@ -123,126 +119,123 @@
* Returns: 0 - success (the test has been finalized).
*/

-int
-test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options)
-{
- char buff[BUFFSIZE+1];
- int msgLen, msgType;
- int sfwport, sfwsock, sfwsockport;
- I2Addr sfwsrv_addr = NULL;
- struct sigaction new, old;
- char* ptr;
- pthread_t threadId;
-
- if (tests & TEST_SFW) {
- log_println(1, " <-- Simple firewall test -->");
- printf("checking for firewalls . . . . . . . . . . . . . . . . . . . ");
- fflush(stdout);
- msgLen = sizeof(buff);
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed prepare message!");
- return 1;
- }
- if (check_msg_type("Simple firewall test", TEST_PREPARE, msgType, buff, msgLen)) {
- return 2;
- }
- if (msgLen <= 0) {
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- ptr = strtok(buff, " ");
- if (ptr == NULL) {
- log_println(0, "SFW: Improper message");
- return 5;
- }
- if (check_int(ptr, &sfwport)) {
- log_println(0, "Invalid port number");
- return 4;
- }
- ptr = strtok(NULL, " ");
- if (ptr == NULL) {
- log_println(0, "SFW: Improper message");
- return 5;
- }
- if (check_int(ptr, &testTime)) {
- log_println(0, "Invalid waiting time");
- return 4;
- }
- log_println(1, "\n -- port: %d", sfwport);
- log_println(1, " -- time: %d", testTime);
- if ((sfwsrv_addr = I2AddrByNode(get_errhandle(), host)) == NULL) {
- log_println(0, "Unable to resolve server address: %s", strerror(errno));
- return -3;
- }
- I2AddrSetPort(sfwsrv_addr, sfwport);
-
- sfwcli_addr = CreateListenSocket(NULL, "0", conn_options, 0);
- if (sfwcli_addr == NULL) {
- log_println(0, "Client (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
- return -1;
- }
- sfwsockfd = I2AddrFD(sfwcli_addr);
- sfwsockport = I2AddrPort(sfwcli_addr);
- log_println(1, " -- oport: %d", sfwsockport);
-
- sprintf(buff, "%d", sfwsockport);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
-
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed text message!");
- return 1;
- }
- if (check_msg_type("Simple firewall test", TEST_START, msgType, buff, msgLen)) {
- return 2;
- }
-
- pthread_create(&threadId, NULL, &test_osfw_clt, NULL);
-
- /* ignore the alrm signal */
- memset(&new, 0, sizeof(new));
- new.sa_handler = catch_alrm;
- sigaction(SIGALRM, &new, &old);
- alarm(testTime + 1);
- if (CreateConnectSocket(&sfwsock, NULL, sfwsrv_addr, conn_options, 0) == 0) {
- send_msg(sfwsock, TEST_MSG, "Simple firewall test", 20);
- }
- alarm(0);
- sigaction(SIGALRM, &old, NULL);
-
- msgLen = sizeof(buff);
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed start message!");
- return 1;
- }
- if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
- return 2;
- }
- if (msgLen <= 0) {
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- if (check_int(buff, &c2s_result)) {
- log_println(0, "Invalid test result");
- return 4;
- }
-
- pthread_join(threadId, NULL);
-
- printf("Done\n");
-
- msgLen = sizeof(buff);
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed finalize message!");
- return 1;
- }
- if (check_msg_type("Simple firewall test", TEST_FINALIZE, msgType, buff, msgLen)) {
- return 2;
- }
- log_println(1, " <-------------------------->");
- }
- return 0;
+int test_sfw_clt(int ctlsockfd, char tests, char* host, int conn_options) {
+ char buff[BUFFSIZE + 1];int msgLen, msgType;
+ int sfwport, sfwsock, sfwsockport;
+ I2Addr sfwsrv_addr = NULL;
+ struct sigaction new, old;
+ char* ptr;
+ pthread_t threadId;
+
+ if (tests & TEST_SFW) {
+ log_println(1, " <-- Simple firewall test -->");
+ printf("checking for firewalls . . . . . . . . . . . . . . . . . .
. ");
+ fflush(stdout);
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed prepare
message!");
+ return 1;
+ }
+ if (check_msg_type("Simple firewall test", TEST_PREPARE, msgType, buff, msgLen)) {
+ return 2;
+ }
+ if (msgLen <= 0) {
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
+ ptr = strtok(buff, " ");
+ if (ptr == NULL) {
+ log_println(0, "SFW: Improper message");
+ return 5;
+ }
+ if (check_int(ptr, &sfwport)) {
+ log_println(0, "Invalid port number");
+ return 4;
+ }
+ ptr = strtok(NULL, " ");
+ if (ptr == NULL) {
+ log_println(0, "SFW: Improper message");
+ return 5;
+ }
+ if (check_int(ptr, &testTime)) {
+ log_println(0, "Invalid waiting time");
+ return 4;
+ }
+ log_println(1, "\n -- port: %d", sfwport);
+ log_println(1, " -- time: %d", testTime);
+ if ((sfwsrv_addr = I2AddrByNode(get_errhandle(), host)) ==
NULL) {
+ log_println(0, "Unable to resolve server address:
%s", strerror(errno));
+ return -3;
+ }
+ I2AddrSetPort(sfwsrv_addr, sfwport);
+
+ sfwcli_addr = CreateListenSocket(NULL, "0", conn_options, 0);
+ if (sfwcli_addr == NULL) {
+ log_println(0, "Client (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
+ return -1;
+ }
+ sfwsockfd = I2AddrFD(sfwcli_addr);
+ sfwsockport = I2AddrPort(sfwcli_addr);
+ log_println(1, " -- oport: %d", sfwsockport);
+
+ sprintf(buff, "%d", sfwsockport);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed text
message!");
+ return 1;
+ }
+ if (check_msg_type("Simple firewall test", TEST_START, msgType, buff, msgLen)) {
+ return 2;
+ }
+
+ pthread_create(&threadId, NULL, &test_osfw_clt, NULL);
+
+ /* ignore the alrm signal */
+ memset(&new, 0, sizeof(new));
+ new.sa_handler = catch_alrm;
+ sigaction(SIGALRM, &new, &old);
+ alarm(testTime + 1);
+ if (CreateConnectSocket(&sfwsock, NULL, sfwsrv_addr, conn_options, 0) == 0) {
+ send_msg(sfwsock, TEST_MSG, "Simple firewall test",
20);
+ }
+ alarm(0);
+ sigaction(SIGALRM, &old, NULL);
+
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed start
message!");
+ return 1;
+ }
+ if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
+ return 2;
+ }
+ if (msgLen <= 0) {
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
+ if (check_int(buff, &c2s_result)) {
+ log_println(0, "Invalid test result");
+ return 4;
+ }
+
+ pthread_join(threadId, NULL);
+
+ printf("Done\n");
+
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed finalize
message!");
+ return 1;
+ }
+ if (check_msg_type("Simple firewall test", TEST_FINALIZE, msgType, buff, msgLen)) {
+ return 2;
+ }
+ log_println(1, " <-------------------------->");
+ }
+ return 0;
}

/*
@@ -253,32 +246,36 @@
* Returns: 0 - success.
*/

-int
-results_sfw(char tests, char* host)
-{
- if (tests & TEST_SFW) {
- switch (c2s_result) {
- case SFW_NOFIREWALL:
- printf("Server '%s' is not behind a firewall. [Connection to the ephemeral port was successful]\n", host);
- break;
- case SFW_POSSIBLE:
- printf("Server '%s' is probably behind a firewall. [Connection to the ephemeral port failed]\n", host);
- break;
- case SFW_UNKNOWN:
- case SFW_NOTTESTED:
- break;
- }
- switch (s2c_result) {
- case SFW_NOFIREWALL:
- printf("Client is not behind a firewall. [Connection to the ephemeral port was successful]\n");
- break;
- case SFW_POSSIBLE:
- printf("Client is probably behind a firewall. [Connection to the ephemeral port failed]\n");
- break;
- case SFW_UNKNOWN:
- case SFW_NOTTESTED:
- break;
- }
- }
- return 0;
-}
+int results_sfw(char tests, char* host) {
+ if (tests & TEST_SFW) {
+ switch (c2s_result) {
+ case SFW_NOFIREWALL:
+ printf(
+ "Server '%s' is not behind a firewall. [Connection to the ephemeral port was successful]\n",
+ host);
+ break;
+ case SFW_POSSIBLE:
+ printf(
+ "Server '%s' is probably behind a firewall. [Connection to the ephemeral port failed]\n",
+ host);
+ break;
+ case SFW_UNKNOWN:
+ case SFW_NOTTESTED:
+ break;
+ }
+ switch (s2c_result) {
+ case SFW_NOFIREWALL:
+ printf(
+ "Client is not behind a firewall. [Connection to the ephemeral port was successful]\n");
+ break;
+ case SFW_POSSIBLE:
+ printf(
+ "Client is probably behind a firewall. [Connection to the ephemeral port failed]\n");
+ break;
+ case SFW_UNKNOWN:
+ case SFW_NOTTESTED:
+ break;
+ }
+ }
+ return 0;
+}
=======================================
--- /branches/kkumar_code_organize/src/test_sfw_srv.c Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/test_sfw_srv.c Mon Oct 17 06:43:25 2011
@@ -18,7 +18,6 @@
#include "runningtest.h"
#include "strlutils.h"

-
static pthread_mutex_t mainmutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t maincond = PTHREAD_COND_INITIALIZER;
static I2Addr sfwcli_addr = NULL;
@@ -31,18 +30,16 @@
* @param signo Signal number (should be SIGALRM)
*/

-void
-catch_alrm(int signo)
-{
- if (signo == SIGALRM) {
- log_println(1, "SFW - SIGALRM was caught");
- if (threadId != -1) { /* we forward the signal to the osfw thread */
- pthread_kill(threadId, SIGALRM);
- threadId =-1;
- }
- return;
- }
- log_println(0, "Unknown (%d) signal was caught", signo);
+void catch_alrm(int signo) {
+ if (signo == SIGALRM) {
+ log_println(1, "SFW - SIGALRM was caught");
+ if (threadId != -1) { /* we forward the signal to the osfw
thread */
+ pthread_kill(threadId, SIGALRM);
+ threadId = -1;
+ }
+ return;
+ }
+ log_println(0, "Unknown (%d) signal was caught", signo);
}

/**
@@ -54,32 +51,31 @@
*/

void*
-test_osfw_srv(void* vptr)
-{
- int sfwsock;
- struct sigaction new, old;
-
- // ignore the alarm signal
- memset(&new, 0, sizeof(new));
- new.sa_handler = catch_alrm;
- sigaction(SIGALRM, &new, &old);
- alarm(testTime);
-
- // connect to client and send TEST_MSG message containing a pre-defined string
- if (CreateConnectSocket(&sfwsock, NULL, sfwcli_addr, 0, 0) == 0) {
- send_msg(sfwsock, TEST_MSG, "Simple firewall test", 20);
- }
-
- alarm(0);
- sigaction(SIGALRM, &old, NULL);
-
- // signal sleeping threads to wake up
- pthread_mutex_lock( &mainmutex);
- toWait = 0;
- pthread_cond_broadcast(&maincond);
- pthread_mutex_unlock( &mainmutex);
-
- return NULL;
+test_osfw_srv(void* vptr) {
+ int sfwsock;
+ struct sigaction new, old;
+
+ // ignore the alarm signal
+ memset(&new, 0, sizeof(new));
+ new.sa_handler = catch_alrm;
+ sigaction(SIGALRM, &new, &old);
+ alarm(testTime);
+
+ // connect to client and send TEST_MSG message containing a pre-defined string
+ if (CreateConnectSocket(&sfwsock, NULL, sfwcli_addr, 0, 0) == 0) {
+ send_msg(sfwsock, TEST_MSG, "Simple firewall test", 20);
+ }
+
+ alarm(0);
+ sigaction(SIGALRM, &old, NULL);
+
+ // signal sleeping threads to wake up
+ pthread_mutex_lock(&mainmutex);
+ toWait = 0;
+ pthread_cond_broadcast(&maincond);
+ pthread_mutex_unlock(&mainmutex);
+
+ return NULL;
}

/**
@@ -88,27 +84,25 @@
* @param ctlsockfd Client control socket descriptor
*/

-void
-finalize_sfw(int ctlsockfd)
-{
- enum TEST_ID thistestId = SFW;
- enum TEST_STATUS_INT teststatusnow = NONE;
- // wait for mutex to be released before attempting to finalize
- while (toWait) {
- pthread_mutex_lock( &mainmutex);
- pthread_cond_wait(&maincond, &mainmutex);
- pthread_mutex_unlock( &mainmutex);
- }
-
- // close the SFW test by sending a nil (0 length) message
- send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
-
- // log
- teststatusnow = TEST_ENDED;
- protolog_status (getpid() , thistestId, teststatusnow);
- log_println(1, " <-------------------------->");
- // unset test name
- setCurrentTest(TEST_NONE);
+void finalize_sfw(int ctlsockfd) {
+ enum TEST_ID thistestId = SFW;
+ enum TEST_STATUS_INT teststatusnow = NONE;
+ // wait for mutex to be released before attempting to finalize
+ while (toWait) {
+ pthread_mutex_lock(&mainmutex);
+ pthread_cond_wait(&maincond, &mainmutex);
+ pthread_mutex_unlock(&mainmutex);
+ }
+
+ // close the SFW test by sending a nil (0 length) message
+ send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
+
+ // log
+ teststatusnow = TEST_ENDED;
+ protolog_status(getpid(), thistestId, teststatusnow);
+ log_println(1, " <-------------------------->");
+ // unset test name
+ setCurrentTest(TEST_NONE);
}

/**
@@ -126,246 +120,240 @@
* 5 - Unable to resolve client address
*/

-int
-test_sfw_srv(int ctlsockfd, web100_agent* agent, TestOptions* options, int conn_options)
-{
- char buff[BUFFSIZE+1];
- I2Addr sfwsrv_addr = NULL;
- int sfwsockfd, sfwsockport, sockfd, sfwport;
- struct sockaddr_storage cli_addr;
- socklen_t clilen;
- fd_set fds;
- struct timeval sel_tv;
- int msgLen, msgType;
- web100_var* var;
- web100_connection* cn;
- web100_group* group;
- int maxRTT, maxRTO;
- char hostname[256];
- int rc;
-
- // variables used for protocol validation
- enum TEST_ID thistestId = NONE;
- enum TEST_STATUS_INT teststatusnow = TEST_NOT_STARTED;
- enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;
- enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
-
-
- assert(ctlsockfd != -1);
- assert(options);
-
- if (options->sfwopt) {
- setCurrentTest(TEST_SFW);
- log_println(1, " <-- %d - Simple firewall test -->", options->child0);
- thistestId = SFW;
- teststatusnow = TEST_STARTED;
- protolog_status(options->child0, thistestId, teststatusnow);
-
- // bind to a new port and obtain address structure with details of port etc
- sfwsrv_addr = CreateListenSocket(NULL, "0", conn_options, 0);
- if (sfwsrv_addr == NULL) {
- log_println(0, "Server (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
- sprintf(buff, "Server (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return -1;
- }
-
- // get socket FD and the ephemeral port number to be used
- sfwsockfd = I2AddrFD(sfwsrv_addr);
- sfwsockport = I2AddrPort(sfwsrv_addr);
- log_println(1, " -- port: %d", sfwsockport);
-
-
- cn = web100_connection_from_socket(agent, ctlsockfd);
- if (cn) {
-
- // Get remote end's address
- web100_agent_find_var_and_group(agent, "RemAddress", &group, &var);
- web100_raw_read(var, cn, buff);
- memset(hostname, 0, 256);
- //strncpy(hostname, web100_value_to_text(web100_get_var_type(var), buff), 255);
- strlcpy(hostname, web100_value_to_text(web100_get_var_type(var), buff), sizeof(hostname));
-
- // Determine test time in seconds.
- // test-time = max(round trip time, timeout) > 3 ? 3 : 1
-
- web100_agent_find_var_and_group(agent, "MaxRTT", &group, &var);
- web100_raw_read(var, cn, buff);
- maxRTT = atoi(web100_value_to_text(web100_get_var_type(var), buff));
- web100_agent_find_var_and_group(agent, "MaxRTO", &group, &var);
- web100_raw_read(var, cn, buff);
- maxRTO = atoi(web100_value_to_text(web100_get_var_type(var), buff));
- if (maxRTT > maxRTO)
- maxRTO = maxRTT;
- if ((((double) maxRTO) / 1000.0) > 3.0)
- /* `testTime = (((double) maxRTO) / 1000.0) * 4 ; */
- testTime = 3;
- else
- testTime = 1;
- }
- else {
- log_println(0, "Simple firewall test: Cannot find connection");
- sprintf(buff, "Server (Simple firewall test): Cannot find connection");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- I2AddrFree(sfwsrv_addr);
- return -1;
- }
- log_println(1, " -- SFW time: %d", testTime);
-
- // try sending TEST_PREPARE msg with ephemeral port number to client.
- // If unable to, return
- sprintf(buff, "%d %d", sfwsockport, testTime);
- if ((rc = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff))) < 0)
- return (rc);
-
- // Listen for TEST_MSG from client's port number sent as data.
- // Any other type of message is unexpected at this juncture.
- msgLen = sizeof(buff);
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) { // message reception error
- log_println(0, "Protocol error!");
- sprintf(buff, "Server (Simple firewall test): Invalid port number received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- I2AddrFree(sfwsrv_addr);
- return 1;
- }
- if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
- log_println(0, "Fault, unexpected message received!");
- sprintf(buff, "Server (Simple firewall test): Invalid port number received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- I2AddrFree(sfwsrv_addr);
- return 2;
- }
- if (msgLen <= 0) { // message reception has error
- log_println(0, "Improper message");
- sprintf(buff, "Server (Simple firewall test): Invalid port number received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- I2AddrFree(sfwsrv_addr);
- return 3;
- }
- // Note: The same error message is transmitted to the client
- // under any error condition, but the log messages indicate the difference
-
-
- buff[msgLen] = 0;
- if (check_int(buff, &sfwport)) { // message data is not number, thus no port info received
- log_println(0, "Invalid port number");
- sprintf(buff, "Server (Simple firewall test): Invalid port number received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- I2AddrFree(sfwsrv_addr);
- return 4;
- }
-
- // Get node, port(if present) and other details of client end.
- // If not able to resolve it, the test cannot proceed to the "throughput" stage
- if ((sfwcli_addr = I2AddrByNode(get_errhandle(), hostname)) == NULL) {
- log_println(0, "Unable to resolve server address"); //todo, this is the client address we cannot resolve?
- send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
-
- // log end
- teststatusnow = TEST_ENDED;
- protolog_status(options->child0, thistestId, teststatusnow);
- log_println(1, " <-------------------------->");
- I2AddrFree(sfwsrv_addr);
- return 5;
- }
- I2AddrSetPort(sfwcli_addr, sfwport);
- log_println(1, " -- oport: %d", sfwport);
-
- // send S->C side TEST_MSG
- send_msg(ctlsockfd, TEST_START, "", 0);
-
- // send the S->C default test message in a separate thread to client
- pthread_create(&threadId, NULL, &test_osfw_srv, NULL);
-
- FD_ZERO(&fds);
- FD_SET(sfwsockfd, &fds);
- sel_tv.tv_sec = testTime;
- sel_tv.tv_usec = 0;
-
- // determine status of listening socket - looking for TEST_MSG from client.
- // The following switch statement checks for cases where this socket status
- // indicates error , and finalizes the test at this point.
-
- switch (select(sfwsockfd+1, &fds, NULL, NULL, &sel_tv)) {
- case -1: // If SOCKET_ERROR - status of firewall unknown
- log_println(0, "Simple firewall test: select exited with error");
- sprintf(buff, "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- finalize_sfw(ctlsockfd);
- I2AddrFree(sfwsrv_addr);
- I2AddrFree(sfwcli_addr);
- return 1;
- case 0: // Time expiration. SFW possible in C->S side
- log_println(0, "Simple firewall test: no connection for %d seconds", testTime);
- sprintf(buff, "%d", SFW_POSSIBLE);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- finalize_sfw(ctlsockfd);
- I2AddrFree(sfwsrv_addr);
- I2AddrFree(sfwcli_addr);
- return 2;
- }
-
- // Now read actual data from the sockets listening for client message.
- // Based on data, conclude SFW status and send TEST_MSG with result.
- // In all cases, finalize the test
- clilen = sizeof(cli_addr);
- sockfd = accept(sfwsockfd, (struct sockaddr *) &cli_addr, &clilen);
- // protocol validation log to indicate client tried connecting
- procstatusenum = PROCESS_STARTED;
- protolog_procstatus(options->child0, thistestId, proctypeenum, procstatusenum);
-
-
- msgLen = sizeof(buff);
- if (recv_msg(sockfd, &msgType, buff, &msgLen)) { // message received in error
- log_println(0, "Simple firewall test: unrecognized message");
- sprintf(buff, "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- close(sockfd);
- finalize_sfw(ctlsockfd);
- I2AddrFree(sfwsrv_addr);
- I2AddrFree(sfwcli_addr);
- return 1;
- }
- if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
- // unexpected message type received
- sprintf(buff, "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- close(sockfd);
- finalize_sfw(ctlsockfd);
- I2AddrFree(sfwsrv_addr);
- I2AddrFree(sfwcli_addr);
- return 1;
- }
- if (msgLen != SFW_TEST_DEFAULT_LEN) { // Expecting default 20 byte long "Simple firewall test" message
- log_println(0, "Simple firewall test: Improper message");
- sprintf(buff, "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- close(sockfd);
- finalize_sfw(ctlsockfd);
- I2AddrFree(sfwsrv_addr);
- I2AddrFree(sfwcli_addr);
- return 1;
- }
- buff[msgLen] = 0;
- if (strcmp(buff, "Simple firewall test") != 0) {
- // Message was of correct length, but was not expected content-wise
- log_println(0, "Simple firewall test: Improper message");
- sprintf(buff, "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- close(sockfd);
- finalize_sfw(ctlsockfd);
- I2AddrFree(sfwsrv_addr);
- I2AddrFree(sfwcli_addr);
- return 1;
- }
-
- // All messages were received correctly, hence no firewall
- sprintf(buff, "%d", SFW_NOFIREWALL);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- close(sockfd);
- finalize_sfw(ctlsockfd);
- I2AddrFree(sfwsrv_addr);
- I2AddrFree(sfwcli_addr);
- }
- return 0;
-}
+int test_sfw_srv(int ctlsockfd, web100_agent* agent, TestOptions* options,
+ int conn_options) {
+ char buff[BUFFSIZE + 1];I2Addr sfwsrv_addr = NULL;
+ int sfwsockfd, sfwsockport, sockfd, sfwport;
+ struct sockaddr_storage cli_addr;
+ socklen_t clilen;
+ fd_set fds;
+ struct timeval sel_tv;
+ int msgLen, msgType;
+ web100_var* var;
+ web100_connection* cn;
+ web100_group* group;
+ int maxRTT, maxRTO;
+ char hostname[256];
+ int rc;
+
+ // variables used for protocol validation
+ enum TEST_ID thistestId = NONE;
+ enum TEST_STATUS_INT teststatusnow = TEST_NOT_STARTED;
+ enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;
+ enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
+
+ assert(ctlsockfd != -1);
+ assert(options);
+
+ if (options->sfwopt) {
+ setCurrentTest(TEST_SFW);
+ log_println(1, " <-- %d - Simple firewall test -->",
options->child0);
+ thistestId = SFW;
+ teststatusnow = TEST_STARTED;
+ protolog_status(options->child0, thistestId, teststatusnow);
+
+ // bind to a new port and obtain address structure with details of port etc
+ sfwsrv_addr = CreateListenSocket(NULL, "0", conn_options, 0);
+ if (sfwsrv_addr == NULL) {
+ log_println(0, "Server (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
+ sprintf(buff, "Server (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ return -1;
+ }
+
+ // get socket FD and the ephemeral port number to be used
+ sfwsockfd = I2AddrFD(sfwsrv_addr);
+ sfwsockport = I2AddrPort(sfwsrv_addr);
+ log_println(1, " -- port: %d", sfwsockport);
+
+ cn = web100_connection_from_socket(agent, ctlsockfd);
+ if (cn) {
+
+ // Get remote end's address
+ web100_agent_find_var_and_group(agent, "RemAddress",
&group, &var);
+ web100_raw_read(var, cn, buff);
+ memset(hostname, 0, 256);
+ //strncpy(hostname, web100_value_to_text(web100_get_var_type(var), buff), 255);
+ strlcpy(hostname, web100_value_to_text(web100_get_var_type(var), buff), sizeof(hostname));
+
+ // Determine test time in seconds.
+ // test-time = max(round trip time, timeout) > 3 ? 3
: 1
+
+ web100_agent_find_var_and_group(agent, "MaxRTT", &group,
&var);
+ web100_raw_read(var, cn, buff);
+ maxRTT =
atoi(web100_value_to_text(web100_get_var_type(var), buff));
+ web100_agent_find_var_and_group(agent, "MaxRTO", &group,
&var);
+ web100_raw_read(var, cn, buff);
+ maxRTO =
atoi(web100_value_to_text(web100_get_var_type(var), buff));
+ if (maxRTT > maxRTO)
+ maxRTO = maxRTT;
+ if ((((double) maxRTO) / 1000.0) > 3.0)
+ /* `testTime = (((double) maxRTO) / 1000.0) * 4 ; */
+ testTime = 3;
+ else
+ testTime = 1;
+ }
+ else {
+ log_println(0, "Simple firewall test: Cannot find
connection");
+ sprintf(buff, "Server (Simple firewall test): Cannot find
connection");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ I2AddrFree(sfwsrv_addr);
+ return -1;
+ }
+ log_println(1, " -- SFW time: %d", testTime);
+
+ // try sending TEST_PREPARE msg with ephemeral port number to
client.
+ // If unable to, return
+ sprintf(buff, "%d %d", sfwsockport, testTime);
+ if ((rc = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff)))
< 0)
+ return (rc);
+
+ // Listen for TEST_MSG from client's port number sent as data.
+ // Any other type of message is unexpected at this juncture.
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) { // message reception error
+ log_println(0, "Protocol error!");
+ sprintf(buff, "Server (Simple firewall test): Invalid port number received");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ I2AddrFree(sfwsrv_addr);
+ return 1;
+ }
+ if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
+ log_println(0, "Fault, unexpected message received!");
+ sprintf(buff, "Server (Simple firewall test): Invalid port number received");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ I2AddrFree(sfwsrv_addr);
+ return 2;
+ }
+ if (msgLen <= 0) { // message reception has error
+ log_println(0, "Improper message");
+ sprintf(buff, "Server (Simple firewall test): Invalid port number received");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ I2AddrFree(sfwsrv_addr);
+ return 3;
+ }
+ // Note: The same error message is transmitted to the client
+ // under any error condition, but the log messages indicate the difference
+
+ buff[msgLen] = 0;
+ if (check_int(buff, &sfwport)) { // message data is not number, thus no port info received
+ log_println(0, "Invalid port number");
+ sprintf(buff, "Server (Simple firewall test): Invalid port number received");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ I2AddrFree(sfwsrv_addr);
+ return 4;
+ }
+
+ // Get node, port(if present) and other details of client end.
+ // If not able to resolve it, the test cannot proceed to the "throughput" stage
+ if ((sfwcli_addr = I2AddrByNode(get_errhandle(), hostname))
== NULL) {
+ log_println(0, "Unable to resolve server address"); //todo, this is the client address we cannot resolve?
+ send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
+
+ // log end
+ teststatusnow = TEST_ENDED;
+ protolog_status(options->child0, thistestId,
teststatusnow);
+ log_println(1, " <-------------------------->");
+ I2AddrFree(sfwsrv_addr);
+ return 5;
+ }
+ I2AddrSetPort(sfwcli_addr, sfwport);
+ log_println(1, " -- oport: %d", sfwport);
+
+ // send S->C side TEST_MSG
+ send_msg(ctlsockfd, TEST_START, "", 0);
+
+ // send the S->C default test message in a separate thread to
client
+ pthread_create(&threadId, NULL, &test_osfw_srv, NULL);
+
+ FD_ZERO(&fds);
+ FD_SET(sfwsockfd, &fds);
+ sel_tv.tv_sec = testTime;
+ sel_tv.tv_usec = 0;
+
+ // determine status of listening socket - looking for TEST_MSG from client.
+ // The following switch statement checks for cases where this socket status
+ // indicates error , and finalizes the test at this point.
+
+ switch (select(sfwsockfd+1, &fds, NULL, NULL, &sel_tv)) {
+ case -1: // If SOCKET_ERROR - status of firewall
unknown
+ log_println(0, "Simple firewall test: select exited with
error");
+ sprintf(buff, "%d", SFW_UNKNOWN);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ finalize_sfw(ctlsockfd);
+ I2AddrFree(sfwsrv_addr);
+ I2AddrFree(sfwcli_addr);
+ return 1;
+ case 0:// Time expiration. SFW possible in C->S side
+ log_println(0, "Simple firewall test: no connection for %d seconds", testTime);
+ sprintf(buff, "%d", SFW_POSSIBLE);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ finalize_sfw(ctlsockfd);
+ I2AddrFree(sfwsrv_addr);
+ I2AddrFree(sfwcli_addr);
+ return 2;
+ }
+
+ // Now read actual data from the sockets listening for client
message.
+ // Based on data, conclude SFW status and send TEST_MSG with
result.
+ // In all cases, finalize the test
+ clilen = sizeof(cli_addr);
+ sockfd = accept(sfwsockfd, (struct sockaddr *) &cli_addr,
&clilen);
+ // protocol validation log to indicate client tried connecting
+ procstatusenum = PROCESS_STARTED;
+ protolog_procstatus(options->child0, thistestId, proctypeenum, procstatusenum);
+
+ msgLen = sizeof(buff);
+ if (recv_msg(sockfd, &msgType, buff, &msgLen)) { // message received in error
+ log_println(0, "Simple firewall test: unrecognized
message");
+ sprintf(buff, "%d", SFW_UNKNOWN);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ close(sockfd);
+ finalize_sfw(ctlsockfd);
+ I2AddrFree(sfwsrv_addr);
+ I2AddrFree(sfwcli_addr);
+ return 1;
+ }
+ if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
+ // unexpected message type received
+ sprintf(buff, "%d", SFW_UNKNOWN);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ close(sockfd);
+ finalize_sfw(ctlsockfd);
+ I2AddrFree(sfwsrv_addr);
+ I2AddrFree(sfwcli_addr);
+ return 1;
+ }
+ if (msgLen != SFW_TEST_DEFAULT_LEN) { // Expecting default 20 byte long "Simple firewall test" message
+ log_println(0, "Simple firewall test: Improper
message");
+ sprintf(buff, "%d", SFW_UNKNOWN);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ close(sockfd);
+ finalize_sfw(ctlsockfd);
+ I2AddrFree(sfwsrv_addr);
+ I2AddrFree(sfwcli_addr);
+ return 1;
+ }
+ buff[msgLen] = 0;
+ if (strcmp(buff, "Simple firewall test") != 0) {
+ // Message was of correct length, but was not
expected content-wise
+ log_println(0, "Simple firewall test: Improper
message");
+ sprintf(buff, "%d", SFW_UNKNOWN);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ close(sockfd);
+ finalize_sfw(ctlsockfd);
+ I2AddrFree(sfwsrv_addr);
+ I2AddrFree(sfwcli_addr);
+ return 1;
+ }
+
+ // All messages were received correctly, hence no firewall
+ sprintf(buff, "%d", SFW_NOFIREWALL);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ close(sockfd);
+ finalize_sfw(ctlsockfd);
+ I2AddrFree(sfwsrv_addr);
+ I2AddrFree(sfwcli_addr);
+ }
+ return 0;
+}
=======================================
--- /branches/kkumar_code_organize/src/testoptions.c Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/testoptions.c Mon Oct 17 06:43:25 2011
@@ -25,20 +25,20 @@

// Snap log characteristics
typedef struct snapArgs {
- web100_snapshot* snap; // web_100 snapshot indicator
- web100_log* log; // web_100 log
- int delay; // periodicity, in ms, of collecting
snap
+ web100_snapshot* snap; // web_100 snapshot indicator
+ web100_log* log; // web_100 log
+ int delay; // periodicity, in ms, of collecting snap
} SnapArgs;

// Worker thread characteristics used to record snaplog and Cwnd peaks
typedef struct workerArgs {
- SnapArgs* snapArgs; // snapArgs struct pointer
- web100_agent* agent; // web_100 agent pointer
- CwndPeaks* peaks; // data indicating Cwnd values
- int writeSnap; // enable writing snaplog
+ SnapArgs* snapArgs; // snapArgs struct pointer
+ web100_agent* agent; // web_100 agent pointer
+ CwndPeaks* peaks; // data indicating Cwnd values
+ int writeSnap; // enable writing snaplog
} WorkerArgs;

-static int workerLoop = 0; // semaphore
+static int workerLoop = 0; // semaphore
static pthread_mutex_t mainmutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t maincond = PTHREAD_COND_INITIALIZER;
static int slowStart = 1;
@@ -55,8 +55,6 @@
//other constants
static const int ETHERNET_MTU_SIZE = 1456;

-
-
/**
* Count the CWND peaks from a snapshot and record the minimal and maximum one.
* Also record the number of transitions between increasing or decreasing
@@ -66,47 +64,43 @@
* @param snap Web100 snapshot structure
*/

-void
-findCwndPeaks(web100_agent* agent, CwndPeaks* peaks, web100_snapshot* snap)
-{
- web100_group* group;
- web100_var* var;
- int CurCwnd;
- char tmpstr[256];
-
- web100_agent_find_var_and_group(agent, "CurCwnd", &group, &var);
- web100_snap_read(var, snap, tmpstr);
- CurCwnd = atoi(web100_value_to_text(web100_get_var_type(var), tmpstr));
-
- if (slowStart) {
- if (CurCwnd < prevCWNDval) {
- slowStart = 0;
- peaks->max = prevCWNDval;
- peaks->amount = 1;
- decreasing = 1;
- }
- }
- else {
- // current congestion window < previous value, so, decreasing
- if (CurCwnd < prevCWNDval) {
- // update values based on actual values
- if (prevCWNDval > peaks->max) {
- peaks->max = prevCWNDval;
- }
- if (!decreasing) {
- peaks->amount += 1;
- }
- decreasing = 1;
- }
- else if (CurCwnd > prevCWNDval) { // current congestion window size
previous value,
- //
not decreasing.
- if ((peaks->min == -1) || (prevCWNDval < peaks->min)) {
- peaks->min = prevCWNDval;
- }
- decreasing = 0;
- }
- }
- prevCWNDval = CurCwnd;
+void findCwndPeaks(web100_agent* agent, CwndPeaks* peaks, web100_snapshot* snap) {
+ web100_group* group;
+ web100_var* var;
+ int CurCwnd;
+ char tmpstr[256];
+
+ web100_agent_find_var_and_group(agent, "CurCwnd", &group, &var);
+ web100_snap_read(var, snap, tmpstr);
+ CurCwnd = atoi(web100_value_to_text(web100_get_var_type(var),
tmpstr));
+
+ if (slowStart) {
+ if (CurCwnd < prevCWNDval) {
+ slowStart = 0;
+ peaks->max = prevCWNDval;
+ peaks->amount = 1;
+ decreasing = 1;
+ }
+ } else {
+ // current congestion window < previous value, so, decreasing
+ if (CurCwnd < prevCWNDval) {
+ // update values based on actual values
+ if (prevCWNDval > peaks->max) {
+ peaks->max = prevCWNDval;
+ }
+ if (!decreasing) {
+ peaks->amount += 1;
+ }
+ decreasing = 1;
+ } else if (CurCwnd > prevCWNDval) { // current congestion window size > previous value,
+
// not decreasing.
+ if ((peaks->min == -1) || (prevCWNDval < peaks->min))
{
+ peaks->min = prevCWNDval;
+ }
+ decreasing = 0;
+ }
+ }
+ prevCWNDval = CurCwnd;
}

/**
@@ -114,14 +108,12 @@
* @param signo The signal number (shuld be SIGALRM)
*/

-void
-catch_s2c_alrm(int signo)
-{
- if (signo == SIGALRM) {
- log_println(1, "SIGALRM was caught");
- return;
- }
- log_println(0, "Unknown (%d) signal was caught", signo);
+void catch_s2c_alrm(int signo) {
+ if (signo == SIGALRM) {
+ log_println(1, "SIGALRM was caught");
+ return;
+ }
+ log_println(0, "Unknown (%d) signal was caught", signo);
}

/**
@@ -132,48 +124,47 @@
*/

void*
-snapWorker(void* arg)
-{
- WorkerArgs *workerArgs = (WorkerArgs*) arg;
- SnapArgs *snapArgs = workerArgs->snapArgs;
- web100_agent* agent = workerArgs->agent;
- CwndPeaks* peaks = workerArgs->peaks;
- int writeSnap = workerArgs->writeSnap;
-
- // snap log written into every "delay" milliseconds
- double delay = ((double) snapArgs->delay) / 1000.0;
-
- while (1) {
- pthread_mutex_lock(&mainmutex);
- if (workerLoop) {
- pthread_mutex_unlock(&mainmutex);
- pthread_cond_broadcast(&maincond);
- break;
- }
- pthread_mutex_unlock(&mainmutex);
- mysleep(0.01);
- }
-
- // Find Congestion window peaks from a web_100 snapshot, if enabled
- // Write snap log , if enable, all in a synchronous manner.
- while (1) {
- pthread_mutex_lock(&mainmutex);
- if (!workerLoop) {
- pthread_mutex_unlock(&mainmutex);
- break;
- }
- web100_snap(snapArgs->snap);
- if (peaks) {
- findCwndPeaks(agent, peaks, snapArgs->snap);
- }
- if (writeSnap) {
- web100_log_write(snapArgs->log, snapArgs->snap);
- }
- pthread_mutex_unlock(&mainmutex);
- mysleep(delay);
- }
-
- return NULL;
+snapWorker(void* arg) {
+ WorkerArgs *workerArgs = (WorkerArgs*) arg;
+ SnapArgs *snapArgs = workerArgs->snapArgs;
+ web100_agent* agent = workerArgs->agent;
+ CwndPeaks* peaks = workerArgs->peaks;
+ int writeSnap = workerArgs->writeSnap;
+
+ // snap log written into every "delay" milliseconds
+ double delay = ((double) snapArgs->delay) / 1000.0;
+
+ while (1) {
+ pthread_mutex_lock(&mainmutex);
+ if (workerLoop) {
+ pthread_mutex_unlock(&mainmutex);
+ pthread_cond_broadcast(&maincond);
+ break;
+ }
+ pthread_mutex_unlock(&mainmutex);
+ mysleep(0.01);
+ }
+
+ // Find Congestion window peaks from a web_100 snapshot, if enabled
+ // Write snap log , if enable, all in a synchronous manner.
+ while (1) {
+ pthread_mutex_lock(&mainmutex);
+ if (!workerLoop) {
+ pthread_mutex_unlock(&mainmutex);
+ break;
+ }
+ web100_snap(snapArgs->snap);
+ if (peaks) {
+ findCwndPeaks(agent, peaks, snapArgs->snap);
+ }
+ if (writeSnap) {
+ web100_log_write(snapArgs->log, snapArgs->snap);
+ }
+ pthread_mutex_unlock(&mainmutex);
+ mysleep(delay);
+ }
+
+ return NULL;
}

/**
@@ -182,20 +173,17 @@
* @param buff test suite description
* @param test_id id of the test
*/
-void
-add_test_to_suite(int* first, char * buff, int test_id)
-{
- char tmpbuff[16];
- if (*first) {
- *first = 0;
- sprintf(buff, "%d", test_id);
- }
- else {
- memset(tmpbuff, 0, 16);
- sprintf(tmpbuff, " %d", test_id);
- //strcat(buff, tmpbuff);
- strlcat(buff, tmpbuff, 16); //setting buffsize= 16 as is initialized in main()
- }
+void add_test_to_suite(int* first, char * buff, int test_id) {
+ char tmpbuff[16];
+ if (*first) {
+ *first = 0;
+ sprintf(buff, "%d", test_id);
+ } else {
+ memset(tmpbuff, 0, 16);
+ sprintf(tmpbuff, " %d", test_id);
+ //strcat(buff, tmpbuff);
+ strlcat(buff, tmpbuff, 16); //setting buffsize= 16 as is initialized in main()
+ }
}

/**
@@ -213,66 +201,66 @@
*
*/

-int
-initialize_tests(int ctlsockfd, TestOptions* options, char * buff)
-{
- unsigned char useropt=0;
- int msgType;
- int msgLen = 1;
- int first = 1;
- char remhostarr[256], protologlocalarr[256];
- char *remhost_ptr = get_remotehost();
-
-
- assert(ctlsockfd != -1);
- assert(options);
-
- // read the test suite request
- if (recv_msg(ctlsockfd, &msgType, &useropt, &msgLen)) {
- sprintf(buff, "Invalid test suite request");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return (-1);
- }
- if (msgLen == -1) {
- sprintf(buff, "Client timeout");
- return (-4);
- }
- // Expecting a MSG_LOGIN with payload byte indicating tests to be run
- if ((msgType != MSG_LOGIN) || (msgLen != 1)) {
- sprintf(buff, "Invalid test request");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return (-2);
- }
- // client connect received correctly. Logging activity
- // log that client connected, and create log file
- log_println(0,
- "Client connect received from :IP %s to some server on socket %d", get_remotehost(), ctlsockfd);
-
- set_protologfile(get_remotehost(), protologlocalarr);
-
- if (!(useropt & (TEST_MID | TEST_C2S | TEST_S2C | TEST_SFW | TEST_STATUS | TEST_META))) {
- // message received does not indicate a valid test!
- sprintf(buff, "Invalid test suite request");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return (-3);
- }
- // construct test suite request based on user options received
- if (useropt & TEST_MID) {
- add_test_to_suite(&first, buff, TEST_MID);
- }
- if (useropt & TEST_SFW) {
- add_test_to_suite(&first, buff, TEST_SFW);
- }
- if (useropt & TEST_C2S) {
- add_test_to_suite(&first, buff, TEST_C2S);
- }
- if (useropt & TEST_S2C) {
- add_test_to_suite(&first, buff, TEST_S2C);
- }
- if (useropt & TEST_META) {
- add_test_to_suite(&first, buff, TEST_META);
- }
- return useropt;
+int initialize_tests(int ctlsockfd, TestOptions* options, char * buff) {
+ unsigned char useropt = 0;
+ int msgType;
+ int msgLen = 1;
+ int first = 1;
+ char remhostarr[256], protologlocalarr[256];
+ char *remhost_ptr = get_remotehost();
+
+ assert(ctlsockfd != -1);
+ assert(options);
+
+ // read the test suite request
+ if (recv_msg(ctlsockfd, &msgType, &useropt, &msgLen)) {
+ sprintf(buff, "Invalid test suite request");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ return (-1);
+ }
+ if (msgLen == -1) {
+ sprintf(buff, "Client timeout");
+ return (-4);
+ }
+ // Expecting a MSG_LOGIN with payload byte indicating tests to be run
+ if ((msgType != MSG_LOGIN) || (msgLen != 1)) {
+ sprintf(buff, "Invalid test request");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ return (-2);
+ }
+ // client connect received correctly. Logging activity
+ // log that client connected, and create log file
+ log_println(0,
+ "Client connect received from :IP %s to some server on
socket %d",
+ get_remotehost(), ctlsockfd);
+
+ set_protologfile(get_remotehost(), protologlocalarr);
+
+ if (!(useropt
+ & (TEST_MID | TEST_C2S | TEST_S2C | TEST_SFW |
TEST_STATUS
+ | TEST_META))) {
+ // message received does not indicate a valid test!
+ sprintf(buff, "Invalid test suite request");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ return (-3);
+ }
+ // construct test suite request based on user options received
+ if (useropt & TEST_MID) {
+ add_test_to_suite(&first, buff, TEST_MID);
+ }
+ if (useropt & TEST_SFW) {
+ add_test_to_suite(&first, buff, TEST_SFW);
+ }
+ if (useropt & TEST_C2S) {
+ add_test_to_suite(&first, buff, TEST_C2S);
+ }
+ if (useropt & TEST_S2C) {
+ add_test_to_suite(&first, buff, TEST_S2C);
+ }
+ if (useropt & TEST_META) {
+ add_test_to_suite(&first, buff, TEST_META);
+ }
+ return useropt;
}

/** Method to start snap worker thread that collects snap logs
@@ -286,55 +274,57 @@
* @param web100_connection connection pointer
* @param web100_group group web100_group pointer
*/
-void start_snap_worker(SnapArgs *snaparg, web100_agent *agentarg, char snaplogenabled, int *workerlooparg,
- pthread_t *wrkrthreadidarg,
- char *metafilevariablename, char *metafilename,
- web100_connection* conn, web100_group* group) {
+void start_snap_worker(SnapArgs *snaparg, web100_agent *agentarg,
+ char snaplogenabled, int *workerlooparg, pthread_t
*wrkrthreadidarg,
+ char *metafilevariablename, char *metafilename,
web100_connection* conn,
+ web100_group* group) {
FILE *fplocal;

- WorkerArgs workerArgs;
- workerArgs.snapArgs = snaparg;
- workerArgs.agent = agentarg;
- workerArgs.peaks = NULL;
- workerArgs.writeSnap = snaplogenabled;
-
- group = web100_group_find(agentarg, "read");
- snaparg->snap = web100_snapshot_alloc(group, conn);
-
- if (snaplogenabled) {
-
- //memcpy(metafilevariablename, metafilename, strlen(metafilename));
- // The above could have been here, except for a caveat: metafile stores
- // just the file name, but full filename is needed to open the log file
-
- fplocal = fopen(get_logfile(),"a");
- snaparg->log = web100_log_open_write(metafilename, conn, group);
- if (fplocal == NULL) {
- log_println(0, "Unable to open log file '%s', continuing on without logging", get_logfile());
- }
- else {
- log_println(0, "Snaplog file: %s\n", metafilename);
- fprintf(fplocal, "Snaplog file: %s\n", metafilename);
- fclose(fplocal);
- }
- }
-
- if (pthread_create(wrkrthreadidarg, NULL, snapWorker, (void*) &workerArgs)) {
- log_println(0, "Cannot create worker thread for writing snap log!");
- *wrkrthreadidarg = 0;
- }
-
- pthread_mutex_lock(&mainmutex);
- *workerlooparg = 1;
- // obtain web100 snap into "snaparg.snap"
- web100_snap(snaparg->snap);
- if (snaplogenabled) {
- web100_log_write(snaparg->log, snaparg->snap);
- }
- pthread_cond_wait(&maincond, &mainmutex);
- pthread_mutex_unlock(&mainmutex);
-}
-
+ WorkerArgs workerArgs;
+ workerArgs.snapArgs = snaparg;
+ workerArgs.agent = agentarg;
+ workerArgs.peaks = NULL;
+ workerArgs.writeSnap = snaplogenabled;
+
+ group = web100_group_find(agentarg, "read");
+ snaparg->snap = web100_snapshot_alloc(group, conn);
+
+ if (snaplogenabled) {
+
+ //memcpy(metafilevariablename, metafilename,
strlen(metafilename));
+ // The above could have been here, except for a caveat:
metafile stores
+ // just the file name, but full filename is needed to open
the log file
+
+ fplocal = fopen(get_logfile(), "a");
+ snaparg->log = web100_log_open_write(metafilename, conn,
group);
+ if (fplocal == NULL) {
+ log_println(
+ 0,
+ "Unable to open log file '%s', continuing
on without logging",
+ get_logfile());
+ } else {
+ log_println(0, "Snaplog file: %s\n", metafilename);
+ fprintf(fplocal, "Snaplog file: %s\n", metafilename);
+ fclose(fplocal);
+ }
+ }
+
+ if (pthread_create(wrkrthreadidarg, NULL, snapWorker,
+ (void*) &workerArgs)) {
+ log_println(0, "Cannot create worker thread for writing snap
log!");
+ *wrkrthreadidarg = 0;
+ }
+
+ pthread_mutex_lock(&mainmutex);
+ *workerlooparg = 1;
+ // obtain web100 snap into "snaparg.snap"
+ web100_snap(snaparg->snap);
+ if (snaplogenabled) {
+ web100_log_write(snaparg->log, snaparg->snap);
+ }
+ pthread_cond_wait(&maincond, &mainmutex);
+ pthread_mutex_unlock(&mainmutex);
+}

/**
* Stop snapWorker
@@ -342,19 +332,20 @@
* @param snaplogenabled boolean indication whether snap logging is enabled
* @param snapArgs_ptr pointer to a snapArgs object
* */
-void stop_snap_worker (int *workerThreadId, char snaplogenabled, SnapArgs* snapArgs_ptr) {
- if (*workerThreadId) {
- pthread_mutex_lock(&mainmutex);
- workerLoop = 0;
- pthread_mutex_unlock(&mainmutex);
- pthread_join(*workerThreadId, NULL);
- }
- // close writing snaplog, if snaplog recording is enabled
- if (snaplogenabled) {
- web100_log_close_write(snapArgs_ptr->log);
- }
-
- web100_snapshot_free(snapArgs_ptr->snap);
+void stop_snap_worker(int *workerThreadId, char snaplogenabled,
+ SnapArgs* snapArgs_ptr) {
+ if (*workerThreadId) {
+ pthread_mutex_lock(&mainmutex);
+ workerLoop = 0;
+ pthread_mutex_unlock(&mainmutex);
+ pthread_join(*workerThreadId, NULL);
+ }
+ // close writing snaplog, if snaplog recording is enabled
+ if (snaplogenabled) {
+ web100_log_close_write(snapArgs_ptr->log);
+ }
+
+ web100_snapshot_free(snapArgs_ptr->snap);

}

@@ -373,8 +364,9 @@
* @param copylocationarg memory location to copy resulting string (from packet trace) into
* */

-void start_packet_trace (int socketfdarg, int socketfdarg2, pid_t *childpid, int *imonarg,
- struct sockaddr *cliaddrarg, socklen_t clilenarg, char* device, PortPair* pairarg, const char* testindicatorarg,
+void start_packet_trace(int socketfdarg, int socketfdarg2, pid_t *childpid,
+ int *imonarg, struct sockaddr *cliaddrarg, socklen_t
clilenarg,
+ char* device, PortPair* pairarg, const char* testindicatorarg,
int iscompressionenabled, char *copylocationarg) {

char tmpstr[256];
@@ -382,30 +374,30 @@

I2Addr src_addr = I2AddrByLocalSockFD(get_errhandle(), socketfdarg,
0);

- if ((*childpid = fork()) == 0) {
-
- close(socketfdarg2);
- close(socketfdarg);
- log_println(0, "%s test Child thinks pipe() returned fd0=%d, fd1=%d", testindicatorarg, imonarg[0], imonarg[1]);
-
- init_pkttrace(src_addr, cliaddrarg, clilenarg,
- imonarg, device, &pairarg,
- testindicatorarg, iscompressionenabled);
-
- exit(0); // Packet trace finished, terminate gracefully
- }
+ if ((*childpid = fork()) == 0) {
+
+ close(socketfdarg2);
+ close(socketfdarg);
+ log_println(0, "%s test Child thinks pipe() returned fd0=%d,
fd1=%d",
+ testindicatorarg, imonarg[0], imonarg[1]);
+
+ init_pkttrace(src_addr, cliaddrarg, clilenarg, imonarg,
device,
+ &pairarg, testindicatorarg,
iscompressionenabled);
+
+ exit(0); // Packet trace finished, terminate gracefully
+ }
memset(tmpstr, 0, 256);
- for (i=0; i< 5; i++) { // read nettrace file name into "tmpstr"
+ for (i = 0; i < 5; i++) { // read nettrace file name into "tmpstr"
readretval = read(imonarg[0], tmpstr, 128);
- if ((readretval == -1) && (errno == EINTR)) // socket interrupted, try reading again
- continue;
- break;
+ if ((readretval == -1) && (errno == EINTR)) // socket interrupted, try reading again
+ continue;
+ break;
}

// name of nettrace file passed back from pcap child copied into meta structure
if (strlen(tmpstr) > 5) {
- memcpy(copylocationarg, tmpstr, strlen(tmpstr));
- log_println(8, "**start pkt trace, memcopied dir name %s", tmpstr );
+ memcpy(copylocationarg, tmpstr, strlen(tmpstr));
+ log_println(8, "**start pkt trace, memcopied dir name %s",
tmpstr);
}

// free this address now.
@@ -422,18 +414,17 @@
int retval;
int i;

- for (i=0; i<RETRY_COUNT; i++) {
+ for (i = 0; i < RETRY_COUNT; i++) {
retval = write(mon_pipe1[1], "c", 1);
- if (retval == 1)
- break;
- if ((retval == -1) && (errno == EINTR))
- continue;
- }
- close(monpipe_arr[0]);
- close(monpipe_arr[1]);
+ if (retval == 1)
+ break;
+ if ((retval == -1) && (errno == EINTR))
+ continue;
+ }
+ close(monpipe_arr[0]);
+ close(monpipe_arr[1]);

}
-

/**
* Set Cwnd limit
@@ -441,9 +432,10 @@
* @param group_arg web100 group pointer
* @param agentarg web100 agent pointer
* */
-void setCwndlimit(web100_connection* connarg, web100_group* grouparg, web100_agent* agentarg, Options* optionsarg) {
-
- web100_var *LimRwin, *yar;
+void setCwndlimit(web100_connection* connarg, web100_group* grouparg,
+ web100_agent* agentarg, Options* optionsarg) {
+
+ web100_var *LimRwin, *yar;
u_int32_t limrwin_val;
char yuff[32];

@@ -451,14 +443,22 @@
log_print(1, "Setting Cwnd limit - ");

if (connarg != NULL) {
- log_println(1, "Got web100 connection pointer for recvsfd
socket\n");
- web100_agent_find_var_and_group(agentarg, "CurMSS",
&grouparg, &yar);
+ log_println(1,
+ "Got web100 connection pointer for recvsfd
socket\n");
+ web100_agent_find_var_and_group(agentarg, "CurMSS",
&grouparg,
+ &yar);
web100_raw_read(yar, connarg, yuff);
log_println(1, "MSS = %s, multiplication factor = %d",
- web100_value_to_text(web100_get_var_type(yar), yuff), optionsarg->limit);
- limrwin_val = optionsarg->limit * (atoi(web100_value_to_text(web100_get_var_type(yar), yuff)));
- web100_agent_find_var_and_group(agentarg, "LimRwin", &grouparg, &LimRwin);
- log_print(1, "now write %d to limit the Receive
window", limrwin_val);
+
web100_value_to_text(web100_get_var_type(yar), yuff),
+ optionsarg->limit);
+ limrwin_val = optionsarg->limit
+ * (atoi(
+
web100_value_to_text(web100_get_var_type(yar),
+
yuff)));
+ web100_agent_find_var_and_group(agentarg, "LimRwin",
&grouparg,
+ &LimRwin);
+ log_print(1, "now write %d to limit the Receive
window",
+ limrwin_val);
web100_raw_write(LimRwin, connarg, &limrwin_val);
log_println(1, " --- Done");
}
@@ -475,13 +475,11 @@
* */
int is_buffer_clogged(int nextseqtosend, int lastunackedseq) {
int recclog = 0;
- if ( (RECLTH<<2) < (nextseqtosend - lastunackedseq - 1) ) {
+ if ((RECLTH << 2) < (nextseqtosend - lastunackedseq - 1)) {
recclog = 1;
}
return recclog;
}
-
-

/**
* Perform the Middlebox test. This is a brief throughput test from the Server to the Client
@@ -510,234 +508,256 @@
*
*/

-int
-test_mid(int ctlsockfd, web100_agent* agent, TestOptions* options, int conn_options, double* s2c_throughput_mid)
-{
- int maxseg = ETHERNET_MTU_SIZE;
- /* int maxseg=1456, largewin=16*1024*1024; */
- /* int seg_size, win_size; */
- int midsfd; // socket file-descriptor, used in mid-box throughput test from S->C
- int j; // temporary
integer store
- int msgretvalue; // return value from
socket read/writes
- struct sockaddr_storage cli_addr;
- /* socklen_t optlen, clilen; */
- socklen_t clilen;
- char buff[BUFFSIZE+1]; // buf used for message
payload
- I2Addr midsrv_addr = NULL; // server address
- char listenmidport[10]; // listener socket for middlebox tests
- int msgType;
- int msgLen;
- web100_connection* conn;
- char tmpstr[256]; // temporary string
storage
- struct timeval sel_tv; // time
- fd_set rfd; // receiver file
descriptor
-
- // variables used for protocol validation logging
- enum TEST_ID thistestId = NONE;
- enum TEST_STATUS_INT teststatusnow = TEST_NOT_STARTED;
- enum PROCESS_STATUS_INT procstatusenum = PROCESS_STARTED;
- enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;
-
- assert(ctlsockfd != -1);
- assert(agent);
- assert(options);
- assert(s2c_throughput_mid);
-
- if (options->midopt) { // middlebox tests need to be run.
-
- // Start with readying up (initializing)
- setCurrentTest(TEST_MID);
- log_println(1, " <-- %d - Middlebox test -->", options->child0);
-
- // protocol validation logs indicating start of tests
- printf(" <--- %d - Middlebox test --->", options->child0);
- thistestId = MIDDLEBOX;
- teststatusnow = TEST_STARTED;
- protolog_status(options->child0, thistestId, teststatusnow);
-
- // determine port to be used. Compute based on options set earlier
- // by reading from config file, or use default port3 (3003),
- //strcpy(listenmidport, PORT3);
- strlcpy(listenmidport, PORT3, sizeof(listenmidport));
-
- if (options->midsockport) {
- sprintf(listenmidport, "%d", options->midsockport);
- }
- else if (options->mainport) {
- sprintf(listenmidport, "%d", options->mainport + 2);
- }
-
- if (options->multiple) {
- //strcpy(listenmidport, "0");
- strlcpy(listenmidport, "0", sizeof(listenmidport));
- }
-
-/* RAC debug */
-/*
- if (KillHung() == 0)
- log_println(5, "KillHung() returned 0, should have tried to kill off some LastAck process");
- else
- log_println(5, "KillHung(): returned non-0 response, nothing to kill or kill failed");
-*/
-
- while (midsrv_addr == NULL) {
-
- // attempt to bind to a new port and obtain address structure with details of listening port
-
- midsrv_addr = CreateListenSocket(NULL,
- (options->multiple ? mrange_next(listenmidport) : listenmidport), conn_options, 0);
- if (midsrv_addr == NULL) {
- /*
- log_println(5, " Calling KillHung() because midsrv_address failed to bind");
- if (KillHung() == 0)
- continue;
- */
- }
- if (strcmp(listenmidport, "0") == 0) {
- log_println(0, "WARNING: ephemeral port number was bound");
- break;
- }
- if (options->multiple == 0) { // simultaneous tests from multiple clients not allowed, quit now
- break;
- }
- }
-
- if (midsrv_addr == NULL) {
- log_println(0, "Server (Middlebox test): CreateListenSocket failed: %s", strerror(errno));
- sprintf(buff, "Server (Middlebox test): CreateListenSocket failed: %s", strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return -1;
- }
-
- // get socket FD and the ephemeral port number that client will connect to
- options->midsockfd = I2AddrFD(midsrv_addr);
- options->midsockport = I2AddrPort(midsrv_addr);
- log_println(1, " -- port: %d", options->midsockport);
-
- // send this port number to client
- sprintf(buff, "%d", options->midsockport);
- if ((msgretvalue = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff))) < 0)
- return msgretvalue;
-
- /* set mss to 1456 (strange value), and large snd/rcv buffers
- * should check to see if server supports window scale ?
- */
- setsockopt(options->midsockfd, SOL_TCP, TCP_MAXSEG, &maxseg, sizeof(maxseg));
-
- /* Post a listen on port 3003. Client will connect here to run the
- * middlebox test. At this time it really only checks the MSS value
- * and does NAT detection. More analysis functions (window scale)
- * will be done in the future.
- */
- clilen = sizeof(cli_addr);
-
- // Wait on listening socket and read data once ready.
- // Choose a retry count of "5" to wait for activity on the socket
- FD_ZERO(&rfd);
- FD_SET(options->midsockfd, &rfd);
- sel_tv.tv_sec = 5;
- sel_tv.tv_usec = 0;
- for (j=0; j<RETRY_COUNT; j++) {
- msgretvalue = select((options->midsockfd)+1, &rfd, NULL, NULL, &sel_tv);
- if ((msgretvalue == -1) && (errno == EINTR)) // socket interruption. continue waiting for activity on socket
- continue;
- if (msgretvalue == 0) // timeout
- return SOCKET_CONNECT_TIMEOUT;
- if (msgretvalue < 0) // other socket errors, exit
- return -errno;
- if (j == 4) // retry exceeded. Quit
- return RETRY_EXCEEDED_WAITING_CONNECT;
-
-midfd:
- // if a valid connection request is received, client has connected. Proceed.
- // Note the new socket fd used in the throughput test is this
(midsfd)
- if ((midsfd = accept(options->midsockfd, (struct sockaddr *) &cli_addr, &clilen)) > 0) {
- // log protocol validation indicating client connection
- procstatusenum = PROCESS_STARTED;
- proctypeenum = CONNECT_TYPE;
- protolog_procstatus(options->child0, thistestId, proctypeenum, procstatusenum);
- break;
- }
-
- if ((midsfd == -1) && (errno == EINTR)) // socket interrupted, wait some more
- goto midfd;
-
- sprintf(tmpstr, "------- middlebox connection setup returned because (%d)", errno);
- if (get_debuglvl() > 1)
- perror(tmpstr);
- if (midsfd < 0)
- return -errno;
- if (j == 4)
- return RETRY_EXCEEDED_WAITING_DATA;
- }
-
- // get meta test details copied into results
- memcpy(&meta.c_addr, &cli_addr, clilen);
- /* meta.c_addr = cli_addr; */
- meta.family = ((struct sockaddr *) &cli_addr)->sa_family;
-
- buff[0] = '\0';
- // get web100 connection data
- if ((conn = web100_connection_from_socket(agent, midsfd)) == NULL) {
- log_println(0, "!!!!!!!!!!! test_mid() failed to get web100 connection data, rc=%d", errno);
- /* exit(-1); */
- return -3;
- }
-
- // Perform S->C throughput test. Obtained results in "buff"
- web100_middlebox(midsfd, agent, conn, buff);
-
- // Transmit results in the form of a TEST_MSG message
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
-
- // Expect client to send throughput as calculated at its end
-
- msgLen = sizeof(buff);
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) { // message reception error
- log_println(0, "Protocol error!");
- sprintf(buff, "Server (Middlebox test): Invalid CWND limited throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return 1;
- }
- if (check_msg_type("Middlebox test", TEST_MSG, msgType, buff, msgLen)) { // only TEST_MSG type valid
- sprintf(buff, "Server (Middlebox test): Invalid CWND limited throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return 2;
- }
- if (msgLen <= 0) { // received message's length has to be a valid one
- log_println(0, "Improper message");
- sprintf(buff, "Server (Middlebox test): Invalid CWND limited throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return 3;
- }
-
- // message payload from client == midbox S->c throughput
- buff[msgLen] = 0;
- *s2c_throughput_mid = atof(buff);
- log_println(4, "CWND limited throughput = %0.0f kbps (%s)", *s2c_throughput_mid, buff);
-
- // finalize the midbox test ; disabling socket used for throughput test and closing out both sockets
- shutdown(midsfd, SHUT_WR);
- close(midsfd);
- close(options->midsockfd);
- send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
- log_println(1, " <--------- %d ----------->", options->child0);
-
- printf(" <--- %d - Middlebox test --->", options->child0);
-
- // log end of test into protocol doc, just to delimit.
- teststatusnow = TEST_ENDED;
- //protolog_status(1, options->child0, thistestId, teststatusnow);
- protolog_status( options->child0, thistestId, teststatusnow);
-
- setCurrentTest(TEST_NONE);
- /* I2AddrFree(midsrv_addr); */
- }
- /* I2AddrFree(midsrv_addr); */
- return 0;
-}
-
-
+int test_mid(int ctlsockfd, web100_agent* agent, TestOptions* options,
+ int conn_options, double* s2c_throughput_mid) {
+ int maxseg = ETHERNET_MTU_SIZE;
+ /* int maxseg=1456, largewin=16*1024*1024; */
+ /* int seg_size, win_size; */
+ int midsfd; // socket file-descriptor, used in mid-box throughput test from S->C
+ int j; // temporary integer store
+ int msgretvalue; // return value from socket read/writes
+ struct sockaddr_storage cli_addr;
+ /* socklen_t optlen, clilen; */
+ socklen_t clilen;
+ char buff[BUFFSIZE + 1]; // buf used for message payload
+I2Addr midsrv_addr = NULL; // server address
+ char listenmidport[10]; // listener socket for middlebox tests
+ int msgType;
+ int msgLen;
+ web100_connection* conn;
+ char tmpstr[256]; // temporary string storage
+ struct timeval sel_tv; // time
+ fd_set rfd; // receiver file descriptor
+
+ // variables used for protocol validation logging
+ enum TEST_ID thistestId = NONE;
+ enum TEST_STATUS_INT teststatusnow = TEST_NOT_STARTED;
+ enum PROCESS_STATUS_INT procstatusenum = PROCESS_STARTED;
+ enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;
+
+ assert(ctlsockfd != -1);
+ assert(agent);
+ assert(options);
+ assert(s2c_throughput_mid);
+
+ if (options->midopt) { // middlebox tests need to be run.
+
+ // Start with readying up (initializing)
+ setCurrentTest(TEST_MID);
+ log_println(1, " <-- %d - Middlebox test -->",
options->child0);
+
+ // protocol validation logs indicating start of tests
+ printf(" <--- %d - Middlebox test --->", options->child0);
+ thistestId = MIDDLEBOX;
+ teststatusnow = TEST_STARTED;
+ protolog_status(options->child0, thistestId, teststatusnow);
+
+ // determine port to be used. Compute based on options set
earlier
+ // by reading from config file, or use default port3 (3003),
+ //strcpy(listenmidport, PORT3);
+ strlcpy(listenmidport, PORT3, sizeof(listenmidport));
+
+ if (options->midsockport) {
+ sprintf(listenmidport, "%d", options->midsockport);
+ } else if (options->mainport) {
+ sprintf(listenmidport, "%d", options->mainport + 2);
+ }
+
+ if (options->multiple) {
+ //strcpy(listenmidport, "0");
+ strlcpy(listenmidport, "0", sizeof(listenmidport));
+ }
+
+ /* RAC debug */
+ /*
+ if (KillHung() == 0)
+ log_println(5, "KillHung() returned 0, should have tried to kill off some LastAck process");
+ else
+ log_println(5, "KillHung(): returned non-0 response, nothing to kill or kill failed");
+ */
+
+ while (midsrv_addr == NULL) {
+
+ // attempt to bind to a new port and obtain address structure with details of listening port
+
+ midsrv_addr =
+ CreateListenSocket(
+ NULL,
+ (options->multiple ?
+
mrange_next(listenmidport) : listenmidport), conn_options, 0)
+ ;
+ if (midsrv_addr == NULL) {
+ /*
+ log_println(5, " Calling KillHung() because midsrv_address failed to bind");
+ if (KillHung() == 0)
+ continue;
+ */
+ }
+ if (strcmp(listenmidport, "0") == 0) {
+ log_println(0, "WARNING: ephemeral port number was
bound");
+ break;
+ }
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/testoptions.h Fri Sep 23 13:50:35 2011
+++ /branches/kkumar_code_organize/src/testoptions.h Mon Oct 17 06:43:25 2011
@@ -12,44 +12,50 @@
#include "web100srv.h"

typedef struct testoptions {
- int multiple; // TODO field comments
- int mainport;
-
- int midopt;
- int midsockfd;
- int midsockport;
-
- int c2sopt;
- int c2ssockfd;
- int c2ssockport;
-
- int s2copt;
- int s2csockfd;
- int s2csockport;
-
- pid_t child0;
- pid_t child1;
- pid_t child2;
-
- int sfwopt;
- int State;
-
- int metaopt;
+ int multiple; // TODO field comments
+ int mainport;
+
+ int midopt;
+ int midsockfd;
+ int midsockport;
+
+ int c2sopt;
+ int c2ssockfd;
+ int c2ssockport;
+
+ int s2copt;
+ int s2csockfd;
+ int s2csockport;
+
+ pid_t child0;
+ pid_t child1;
+ pid_t child2;
+
+ int sfwopt;
+ int State;
+
+ int metaopt;
} TestOptions;

int wait_sig;

-int initialize_tests(int ctlsockfd, TestOptions* testOptions, char * test_suite);
-
-int test_mid(int ctlsockfd, web100_agent* agent, TestOptions* testOptions, int conn_options, double* s2c2spd);
-int test_c2s(int ctlsockfd, web100_agent* agent, TestOptions* testOptions, int conn_options, double* c2sspd,
- int set_buff, int window, int autotune, char* device, Options* options,
- int record_reverse, int count_vars, char spds[4][256], int* spd_index);
-int test_s2c(int ctlsockfd, web100_agent* agent, TestOptions* testOptions, int conn_options, double* s2cspd,
- int set_buff, int window, int autotune, char* device, Options* options, char spds[4][256],
- int* spd_index, int count_vars, CwndPeaks* peaks);
-int test_sfw_srv(int ctlsockfd, web100_agent* agent, TestOptions* options, int conn_options);
-int test_meta_srv(int ctlsockfd, web100_agent* agent, TestOptions* options, int conn_options);
+int initialize_tests(int ctlsockfd, TestOptions* testOptions,
+ char * test_suite);
+
+int test_mid(int ctlsockfd, web100_agent* agent, TestOptions* testOptions,
+ int conn_options, double* s2c2spd);
+int test_c2s(int ctlsockfd, web100_agent* agent, TestOptions* testOptions,
+ int conn_options, double* c2sspd, int set_buff, int window,
+ int autotune, char* device, Options* options, int
record_reverse,
+ int count_vars, char spds[4][256], int* spd_index);
+int test_s2c(int ctlsockfd, web100_agent* agent, TestOptions* testOptions,
+ int conn_options, double* s2cspd, int set_buff, int window,
+ int autotune, char* device, Options* options, char
spds[4][256],
+ int* spd_index, int count_vars, CwndPeaks* peaks);
+int test_sfw_srv(int ctlsockfd, web100_agent* agent, TestOptions* options,
+ int conn_options);
+int test_meta_srv(int ctlsockfd, web100_agent* agent, TestOptions* options,
+ int conn_options);

int getCurrentTest();
void setCurrentTest(int testId);
=======================================
--- /branches/kkumar_code_organize/src/tr-mkmap.c Fri Oct 14 13:52:19
2011
+++ /branches/kkumar_code_organize/src/tr-mkmap.c Mon Oct 17 06:43:25
2011
@@ -52,230 +52,215 @@
static char dt6fn[256];
#endif

-static struct option long_options[] = {
- {"build", 0, 0, 'b'},
- {"compare", 1, 0, 'c'},
- {"file", 1, 0, 'f'},
- {"help", 0, 0, 'h'},
- {"print", 0, 0, 'p'},
- {"debug", 0, 0, 'd'},
- {"version", 0, 0, 'v'},
- {"dflttree", 1, 0, 301},
+static struct option long_options[] = { { "build", 0, 0, 'b' }, { "compare", 1,
+ 0, 'c' }, { "file", 1, 0, 'f' }, { "help", 0, 0, 'h' }, {
"print", 0, 0,
+ 'p' }, { "debug", 0, 0, 'd' }, { "version", 0, 0, 'v' }, {
"dflttree",
+ 1, 0, 301 },
#ifdef AF_INET6
- {"dflttree6", 1, 0, 302},
- {"ipv4", 0, 0, '4'},
- {"ipv6", 0, 0, '6'},
+ { "dflttree6", 1, 0, 302},
+ { "ipv4", 0, 0, '4'},
+ { "ipv6", 0, 0, '6'},
#endif
- {0, 0, 0, 0}
-};
+ { 0, 0, 0, 0 } };

/* Recursive sub-routine that walks through the tree. In
* build mode (flag = b) add a new node to the tree if
* a leaf is reached and this new node should go under it.
*/
-void
-build_tree(struct tr_tree *tmp, struct tr_tree *new)
-{
- if (new->ip_addr == tmp->ip_addr)
- return;
- if (new->ip_addr < tmp->ip_addr) {
- if (tmp->left == NULL) {
- tmp->left = new;
- return;
- }
- else {
- build_tree(tmp->left, new);
- return;
- }
- }
- if (new->ip_addr > tmp->ip_addr) {
- if (tmp->right == NULL) {
- tmp->right = new;
- return;
- }
- else {
- build_tree(tmp->right, new);
- return;
- }
- }
+void build_tree(struct tr_tree *tmp, struct tr_tree *new) {
+ if (new->ip_addr == tmp->ip_addr)
+ return;
+ if (new->ip_addr < tmp->ip_addr) {
+ if (tmp->left == NULL) {
+ tmp->left = new;
+ return;
+ } else {
+ build_tree(tmp->left, new);
+ return;
+ }
+ }
+ if (new->ip_addr > tmp->ip_addr) {
+ if (tmp->right == NULL) {
+ tmp->right = new;
+ return;
+ } else {
+ build_tree(tmp->right, new);
+ return;
+ }
+ }
}
#ifdef AF_INET6
void
build_tree6(struct tr_tree6 *tmp, struct tr_tree6 *new)
{
- if (memcmp(new->ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) == 0) {
- return;
- }
- if (memcmp(new->ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) < 0) {
- if (tmp->left == NULL) {
- tmp->left = new;
- return;
- }
- else {
- build_tree6(tmp->left, new);
- return;
- }
- }
- if (memcmp(new->ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) > 0) {
- if (tmp->right == NULL) {
- tmp->right = new;
- return;
- }
- else {
- build_tree6(tmp->right, new);
- return;
- }
- }
+ if (memcmp(new->ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) == 0) {
+ return;
+ }
+ if (memcmp(new->ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) < 0) {
+ if (tmp->left == NULL) {
+ tmp->left = new;
+ return;
+ }
+ else {
+ build_tree6(tmp->left, new);
+ return;
+ }
+ }
+ if (memcmp(new->ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) > 0) {
+ if (tmp->right == NULL) {
+ tmp->right = new;
+ return;
+ }
+ else {
+ build_tree6(tmp->right, new);
+ return;
+ }
+ }
}
#endif

/* Walk through traceroute output file and return IP address. handle
* lines with *'s too.
*/
-uint32_t
-get_addr(char *tmpbuff)
-{
- char *tmpstr;
- int i;
- uint32_t ip_addr;
- struct sockaddr_in address;
-
- /* no response from intermediate/destination host found, line should
- * just contain * * * sequence. return -1 (255.255.255.255)
- */
- if ((strchr(tmpbuff, '*') != NULL) && (strchr(tmpbuff, '.') == NULL))
- return(-1);
-
- /* No IP address found on this line (can this occur or will the previous
- * test catch everything?
- */
- if (strchr(tmpbuff, '.') == NULL)
- return(-1);
-
- /* now check to see if '-n' option was used. Output could be
- * line_no. hostname (ip_addr) time1 time2 time3 flag
- * OR '-n'
- * line_no ip_addr time1 time2 time3
- */
- if (strchr(tmpbuff, '(') != NULL) {
- tmpstr = strchr(tmpbuff, '(');
- tmpstr++;
- tmpbuff = strtok(tmpstr, ")");
- }
- else {
- tmpstr = strchr(tmpbuff, '.');
- while (tmpstr[0] != ' ') {
- if (tmpstr == tmpbuff)
- break;
- tmpstr--;
- }
- tmpbuff = strtok(tmpstr, " ");
- }
- if ((i = inet_aton(tmpbuff, &address.sin_addr)) == -1) {
- printf("Error: Improper format for traceroute compare file\n");
- exit(-39);
- }
- ip_addr = address.sin_addr.s_addr;
- return(ip_addr);
+uint32_t get_addr(char *tmpbuff) {
+ char *tmpstr;
+ int i;
+ uint32_t ip_addr;
+ struct sockaddr_in address;
+
+ /* no response from intermediate/destination host found, line should
+ * just contain * * * sequence. return -1 (255.255.255.255)
+ */
+ if ((strchr(tmpbuff, '*') != NULL) && (strchr(tmpbuff, '.') == NULL))
+ return (-1);
+
+ /* No IP address found on this line (can this occur or will the
previous
+ * test catch everything?
+ */
+ if (strchr(tmpbuff, '.') == NULL)
+ return (-1);
+
+ /* now check to see if '-n' option was used. Output could be
+ * line_no. hostname (ip_addr) time1 time2 time3 flag
+ * OR '-n'
+ * line_no ip_addr time1 time2 time3
+ */
+ if (strchr(tmpbuff, '(') != NULL) {
+ tmpstr = strchr(tmpbuff, '(');
+ tmpstr++;
+ tmpbuff = strtok(tmpstr, ")");
+ } else {
+ tmpstr = strchr(tmpbuff, '.');
+ while (tmpstr[0] != ' ') {
+ if (tmpstr == tmpbuff)
+ break;
+ tmpstr--;
+ }
+ tmpbuff = strtok(tmpstr, " ");
+ }
+ if ((i = inet_aton(tmpbuff, &address.sin_addr)) == -1) {
+ printf("Error: Improper format for traceroute compare
file\n");
+ exit(-39);
+ }
+ ip_addr = address.sin_addr.s_addr;
+ return (ip_addr);
}
#ifdef AF_INET6
int
get_addr6(uint32_t dst_addr[4], char *tmpbuff)
{
- char *tmpstr;
- int i;
- struct sockaddr_in6 address;
-
- /* no response from intermediate/destination host found, line should
- * just contain IP t1 !x t2 !x t3 !x sequence. Set addr to 16x255, return 0.
- */
- if ((tmpstr = strchr(tmpbuff, '!')) != NULL) {
- tmpstr++;
- if ((tmpstr = strchr(tmpstr, '!')) != NULL) {
- tmpstr++;
- if (strchr(tmpstr, '!') != NULL) {
- memset(dst_addr, 255, 16);
- return 0;
- }
- }
- }
-
- /* No IP address found on this line. Set addr to 16x255, return 0.
- */
- if (strchr(tmpbuff, ':') == NULL) {
- memset(dst_addr, 255, 16);
- return 0;
- }
-
- /* now check to see if '-n' option was used. Output could be
- * line_no. hostname (ip_addr) time1 time2 time3 flag
- * OR '-n'
- * line_no ip_addr time1 time2 time3
- */
- if (strchr(tmpbuff, '(') != NULL) {
- tmpstr = strchr(tmpbuff, '(');
- tmpstr++;
- tmpbuff = strtok(tmpstr, ")");
- }
- else {
- tmpstr = strchr(tmpbuff, ':');
- while (tmpstr[0] != ' ') {
- if (tmpstr == tmpbuff)
- break;
- tmpstr--;
- }
- tmpbuff = strtok(tmpstr, " ");
- }
- if ((i = inet_pton(AF_INET6, tmpbuff, &address.sin6_addr)) == -1) {
- printf("Error: Improper format for traceroute6 compare file\n");
- exit(-39);
- }
- memcpy(dst_addr, &address.sin6_addr, 16);
- return 1;
+ char *tmpstr;
+ int i;
+ struct sockaddr_in6 address;
+
+ /* no response from intermediate/destination host found, line should
+ * just contain IP t1 !x t2 !x t3 !x sequence. Set addr to 16x255, return 0.
+ */
+ if ((tmpstr = strchr(tmpbuff, '!')) != NULL) {
+ tmpstr++;
+ if ((tmpstr = strchr(tmpstr, '!')) != NULL) {
+ tmpstr++;
+ if (strchr(tmpstr, '!') != NULL) {
+ memset(dst_addr, 255, 16);
+ return 0;
+ }
+ }
+ }
+
+ /* No IP address found on this line. Set addr to 16x255, return 0.
+ */
+ if (strchr(tmpbuff, ':') == NULL) {
+ memset(dst_addr, 255, 16);
+ return 0;
+ }
+
+ /* now check to see if '-n' option was used. Output could be
+ * line_no. hostname (ip_addr) time1 time2 time3 flag
+ * OR '-n'
+ * line_no ip_addr time1 time2 time3
+ */
+ if (strchr(tmpbuff, '(') != NULL) {
+ tmpstr = strchr(tmpbuff, '(');
+ tmpstr++;
+ tmpbuff = strtok(tmpstr, ")");
+ }
+ else {
+ tmpstr = strchr(tmpbuff, ':');
+ while (tmpstr[0] != ' ') {
+ if (tmpstr == tmpbuff)
+ break;
+ tmpstr--;
+ }
+ tmpbuff = strtok(tmpstr, " ");
+ }
+ if ((i = inet_pton(AF_INET6, tmpbuff, &address.sin6_addr)) == -1) {
+ printf("Error: Improper format for traceroute6 compare
file\n");
+ exit(-39);
+ }
+ memcpy(dst_addr, &address.sin6_addr, 16);
+ return 1;
}
#endif

/* Compare tree sub-routine. Sets global found_node flag to
* indicate completion status
*/
-void
-compare_tree(struct tr_tree *tmp, uint32_t ip_addr)
-{
- if (tmp->ip_addr == ip_addr) {
- found_node = 1;
- tr_cur = tmp;
- return;
- }
- if ((tmp->left == NULL) && (tmp->right == NULL)) {
- found_node = 2;
- tr_cur = tmp;
- return;
- }
- if ((tmp->ip_addr < ip_addr) && (found_node == 0))
- compare_tree(tmp->left, ip_addr);
- if ((tmp->ip_addr > ip_addr) && (found_node == 0))
- compare_tree(tmp->right, ip_addr);
+void compare_tree(struct tr_tree *tmp, uint32_t ip_addr) {
+ if (tmp->ip_addr == ip_addr) {
+ found_node = 1;
+ tr_cur = tmp;
+ return;
+ }
+ if ((tmp->left == NULL) && (tmp->right == NULL)) {
+ found_node = 2;
+ tr_cur = tmp;
+ return;
+ }
+ if ((tmp->ip_addr < ip_addr) && (found_node == 0))
+ compare_tree(tmp->left, ip_addr);
+ if ((tmp->ip_addr > ip_addr) && (found_node == 0))
+ compare_tree(tmp->right, ip_addr);
}
#ifdef AF_INET6
void
compare_tree6(struct tr_tree6 *tmp, uint32_t ip_addr[4])
{
- if (memcmp(ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) == 0) {
- found_node = 1;
- tr_cur6 = tmp;
- return;
- }
- if ((tmp->left == NULL) && (tmp->right == NULL)) {
- found_node = 2;
- tr_cur6 = tmp;
- return;
- }
- if ((memcmp(ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) > 0) && (found_node == 0)) {
- compare_tree6(tmp->left, ip_addr);
- }
- if ((memcmp(ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) < 0) && (found_node == 0)) {
- compare_tree6(tmp->right, ip_addr);
- }
+ if (memcmp(ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) == 0) {
+ found_node = 1;
+ tr_cur6 = tmp;
+ return;
+ }
+ if ((tmp->left == NULL) && (tmp->right == NULL)) {
+ found_node = 2;
+ tr_cur6 = tmp;
+ return;
+ }
+ if ((memcmp(ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) > 0) && (found_node == 0)) {
+ compare_tree6(tmp->left, ip_addr);
+ }
+ if ((memcmp(ip_addr, tmp->ip_addr, sizeof(tmp->ip_addr)) < 0) && (found_node == 0)) {
+ compare_tree6(tmp->right, ip_addr);
+ }
}
#endif

@@ -284,663 +269,653 @@
* default tree in memory. This works for testing.
*/

-void
-save_tree(struct tr_tree *cur, FILE *fp)
-{
- int i;
-
- for (i=0; i<cur->branches; i++) {
- if (i == 0)
- fwrite(cur, sizeof(struct tr_tree), 1, fp);
- save_tree(&*cur->branch[i], fp);
- }
- if (cur->branches == 0) {
- fwrite(cur, sizeof(struct tr_tree), 1, fp);
- free(cur);
- }
+void save_tree(struct tr_tree *cur, FILE *fp) {
+ int i;
+
+ for (i = 0; i < cur->branches; i++) {
+ if (i == 0)
+ fwrite(cur, sizeof(struct tr_tree), 1, fp);
+ save_tree(&*cur->branch[i], fp);
+ }
+ if (cur->branches == 0) {
+ fwrite(cur, sizeof(struct tr_tree), 1, fp);
+ free(cur);
+ }
}
#ifdef AF_INET6
void
save_tree6(struct tr_tree6 *cur, FILE *fp)
{
- int i;
-
- for (i=0; i<cur->branches; i++) {
- if (i == 0)
- fwrite(cur, sizeof(struct tr_tree6), 1, fp);
- save_tree6(&*cur->branch[i], fp);
- }
- if (cur->branches == 0) {
- fwrite(cur, sizeof(struct tr_tree6), 1, fp);
- free(cur);
- }
+ int i;
+
+ for (i=0; i<cur->branches; i++) {
+ if (i == 0)
+ fwrite(cur, sizeof(struct tr_tree6), 1, fp);
+ save_tree6(&*cur->branch[i], fp);
+ }
+ if (cur->branches == 0) {
+ fwrite(cur, sizeof(struct tr_tree6), 1, fp);
+ free(cur);
+ }
}
#endif

/* Restore the default tree, stored by the save tree routine above.
* Once restored, the comparison can take place.
*/
-void
-restore_tree2(struct tr_tree *tmp, FILE *fp)
-{
- struct tr_tree *new;
- int i, j;
-
- for (i=0; i<tmp->branches; i++) {
- new = (struct tr_tree *) malloc(sizeof(struct tr_tree));
- memset(&*new, 0, sizeof(struct tr_tree));
- if (fread(&*new, sizeof(struct tr_tree), 1, fp) == 0)
- return;
- else {
- for (j=0; j<25; j++)
- new->branch[j] = NULL;
- }
- tmp->branch[i] = new;
- if (new->branches == 0) {
- continue;
- }
- restore_tree( &*tmp->branch[i], fp);
- }
+void restore_tree2(struct tr_tree *tmp, FILE *fp) {
+ struct tr_tree *new;
+ int i, j;
+
+ for (i = 0; i < tmp->branches; i++) {
+ new = (struct tr_tree *) malloc(sizeof(struct tr_tree));
+ memset(&*new, 0, sizeof(struct tr_tree));
+ if (fread(&*new, sizeof(struct tr_tree), 1, fp) == 0)
+ return;
+ else {
+ for (j = 0; j < 25; j++)
+ new->branch[j] = NULL;
+ }
+ tmp->branch[i] = new;
+ if (new->branches == 0) {
+ continue;
+ }
+ restore_tree(&*tmp->branch[i], fp);
+ }
}
#ifdef AF_INET6
void
restore_tree26(struct tr_tree6 *tmp, FILE *fp)
{
- struct tr_tree6 *new;
- int i, j;
-
- for (i=0; i<tmp->branches; i++) {
- new = (struct tr_tree6 *) malloc(sizeof(struct tr_tree6));
- memset(&*new, 0, sizeof(struct tr_tree6));
- if (fread(&*new, sizeof(struct tr_tree6), 1, fp) == 0)
- return;
- else {
- for (j=0; j<25; j++)
- new->branch[j] = NULL;
- }
- tmp->branch[i] = new;
- if (new->branches == 0) {
- continue;
- }
- restore_tree6( &*tmp->branch[i], fp);
- }
+ struct tr_tree6 *new;
+ int i, j;
+
+ for (i=0; i<tmp->branches; i++) {
+ new = (struct tr_tree6 *) malloc(sizeof(struct tr_tree6));
+ memset(&*new, 0, sizeof(struct tr_tree6));
+ if (fread(&*new, sizeof(struct tr_tree6), 1, fp) == 0)
+ return;
+ else {
+ for (j=0; j<25; j++)
+ new->branch[j] = NULL;
+ }
+ tmp->branch[i] = new;
+ if (new->branches == 0) {
+ continue;
+ }
+ restore_tree6( &*tmp->branch[i], fp);
+ }
}
#endif

-
/* Print out the default tree using this routine. Use a
* standard recursive print algorithm
*/
-void
-print_tree(struct tr_tree *cur)
-{
- static int i;
- int j;
-
- if (i == 0)
- printf("Root node is [%u.%u.%u.%u]\n",
- (cur->ip_addr & 0xff), ((cur->ip_addr >> 8) & 0xff),
- ((cur->ip_addr >> 16) & 0xff), (cur->ip_addr >> 24));
- else {
- printf("Leaf %d node [%u.%u.%u.%u]\n", i,
- (cur->ip_addr & 0xff), ((cur->ip_addr >> 8) & 0xff),
+void print_tree(struct tr_tree *cur) {
+ static int i;
+ int j;
+
+ if (i == 0)
+ printf(
+ "Root node is [%u.%u.%u.%u]\n",
+ (cur->ip_addr & 0xff), ((cur->ip_addr >> 8) &
0xff),
+ ((cur->ip_addr >> 16) & 0xff), (cur->ip_addr
>> 24));
+ else {
+ printf("Leaf %d node
[%u.%u.%u.%u]\n", i,
+ (cur->ip_addr & 0xff),
((cur->ip_addr >> 8) &0xff),
((cur->ip_addr >> 16) & 0xff), ((cur->ip_addr >> 24) & 0xff));
}
- for (j=0; j<cur->branches; j++) {
- i++;
- print_tree(&*cur->branch[j]);
- i--;
- }
+ for (j = 0; j < cur->branches; j++) {
+ i++;
+ print_tree(&*cur->branch[j]);
+ i--;
+ }
}
#ifdef AF_INET6
void
print_tree6(struct tr_tree6 *cur)
{
- static int i;
- int j;
- char nodename[200];
- socklen_t nnlen = 199;
-
- if (i == 0) {
- inet_ntop(AF_INET6, cur->ip_addr, nodename, nnlen);
- printf("Root node is [%s]\n", nodename);
- }
- else {
- inet_ntop(AF_INET6, cur->ip_addr, nodename, nnlen);
- printf("Leaf %d node [%s]\n", i, nodename);
- }
- for (j=0; j<cur->branches; j++) {
- i++;
- print_tree6(&*cur->branch[j]);
- i--;
- }
+ static int i;
+ int j;
+ char nodename[200];
+ socklen_t nnlen = 199;
+
+ if (i == 0) {
+ inet_ntop(AF_INET6, cur->ip_addr, nodename, nnlen);
+ printf("Root node is [%s]\n", nodename);
+ }
+ else {
+ inet_ntop(AF_INET6, cur->ip_addr, nodename, nnlen);
+ printf("Leaf %d node [%s]\n", i, nodename);
+ }
+ for (j=0; j<cur->branches; j++) {
+ i++;
+ print_tree6(&*cur->branch[j]);
+ i--;
+ }
}
#endif

/* Builds the tree from the given file
*/
-void
-build(char* inputfile)
-{
- struct tr_tree *root, *current, *new;
- int i;
- uint32_t ip_addr;
- char buff[256], *tmpbuff;
- FILE *fp;
-
- root = NULL;
- current = NULL;
-
- printf("\nBuilding default tree (IPv4)\n\n");
- if (inputfile == NULL)
- inputfile = "/tmp/traceroute.data";
- fp = fopen(inputfile, "r");
-
- if (fp == NULL) {
- printf("Error: Default tree input file '%s' missing!\n", inputfile);
- exit (-5);
- }
- while ((fgets(buff, 256, fp)) != NULL) {
- tmpbuff = strtok(buff, "\n");
- if (tmpbuff == NULL) {
- current = root;
- continue;
- }
- ip_addr = get_addr(tmpbuff);
- new = (struct tr_tree *) malloc(sizeof(struct tr_tree));
- if (new == NULL) {
- printf("Error: malloc failed, out of memory\n");
- exit (-10);
- }
- memset(&*new, 0, sizeof(struct tr_tree));
- new->ip_addr = ip_addr;
- sprintf(new->hostname, "%u.%u.%u.%u",
- (ip_addr & 0xff), ((ip_addr >> 8) & 0xff),
- ((ip_addr >> 16) & 0xff), (ip_addr >> 24));
- /* resolve host name and store for later use */
-
- if (root == NULL) {
- root = new;
- }
- else {
- if ((current == root) && (current->ip_addr == new->ip_addr)) {
- free(new);
- continue;
- }
- for (i=0; i<current->branches; i++) {
- if (current->branch[i]->ip_addr == new->ip_addr) {
- current = current->branch[i];
- free(new);
- new = NULL;
- break;
- }
- }
- if (new == NULL) {
- continue;
- } else {
- i = 0;
- while (current->branch[i] != NULL)
- i++;
- current->branch[i] = new;
- current->branches++;
- }
- }
- current = new;
- }
- fp = fopen(DefaultTree, "wb");
- if (fp == NULL) {
- printf("Error: Can't write default tree '%s', exiting save_tree()\n", DefaultTree);
- exit (-15);
- }
- print_tree(&*root);
- printf("Finished printing default tree '%s'\n", DefaultTree);
- save_tree(&*root, fp);
- fclose(fp);
+void build(char* inputfile) {
+ struct tr_tree *root, *current, *new;
+ int i;
+ uint32_t ip_addr;
+ char buff[256], *tmpbuff;
+ FILE * fp;
+
+ root = NULL;
+ current = NULL;
+
+ printf("\nBuilding default tree (IPv4)\n\n");
+ if (inputfile == NULL)
+ inputfile = "/tmp/traceroute.data";
+ fp = fopen(inputfile, "r");
+
+ if (fp == NULL) {
+ printf("Error: Default tree input file '%s' missing!\n",
inputfile);
+ exit(-5);
+ }
+ while ((fgets(buff, 256, fp)) != NULL) {
+ tmpbuff = strtok(buff, "\n");
+ if (tmpbuff == NULL) {
+ current = root;
+ continue;
+ }
+ ip_addr = get_addr(tmpbuff);
+ new = (struct tr_tree *) malloc(sizeof(struct tr_tree));
+ if (new == NULL) {
+ printf("Error: malloc failed, out of memory\n");
+ exit(-10);
+ }
+ memset(&*new, 0, sizeof(struct tr_tree));
+ new->ip_addr = ip_addr;
+ sprintf(new->hostname, "%u.%u.%u.%u",
+ (ip_addr & 0xff), ((ip_addr >> 8) & 0xff),
+ ((ip_addr >> 16) & 0xff), (ip_addr >> 24));
+ /* resolve host name and store for later use */
+
+ if (root == NULL) {
+ root = new;
+ } else {
+ if ((current == root) && (current->ip_addr ==
new->ip_addr)) {
+ free(new);
+ continue;
+ }
+ for (i = 0; i < current->branches; i++) {
+ if (current->branch[i]->ip_addr ==
new->ip_addr) {
+ current = current->branch[i];
+ free(new);
+ new = NULL;
+ break;
+ }
+ }
+ if (new == NULL) {
+ continue;
+ } else {
+ i = 0;
+ while (current->branch[i] != NULL)
+ i++;
+ current->branch[i] = new;
+ current->branches++;
+ }
+ }
+ current = new;
+ }
+ fp = fopen(DefaultTree, "wb");
+ if (fp == NULL) {
+ printf("Error: Can't write default tree '%s', exiting
save_tree()\n",
+ DefaultTree);
+ exit(-15);
+ }
+ print_tree(&*root);
+ printf("Finished printing default tree '%s'\n", DefaultTree);
+ save_tree(&*root, fp);
+ fclose(fp);
}
#ifdef AF_INET6
void
build6(char* inputfile)
{
- struct tr_tree6 *root, *current, *new;
- int i;
- uint32_t ip_addr[4];
- char buff[256], *tmpbuff;
- char nodename[200];
- socklen_t nnlen = 199;
- FILE *fp;
-
- root = NULL;
- current = NULL;
-
- printf("\nBuilding default tree (IPv6)\n\n");
- if (inputfile == NULL)
- inputfile = "/tmp/traceroute6.data";
- fp = fopen(inputfile, "r");
-
- if (fp == NULL) {
- printf("Error: Default tree6 input file '%s' missing!\n", inputfile);
- exit (-5);
- }
- while ((fgets(buff, 256, fp)) != NULL) {
- tmpbuff = strtok(buff, "\n");
- if (tmpbuff == NULL) {
- current = root;
- continue;
- }
- get_addr6(ip_addr, tmpbuff);
- new = (struct tr_tree6 *) malloc(sizeof(struct tr_tree6));
- if (new == NULL) {
- printf("Error: malloc failed, out of memory\n");
- exit (-10);
- }
- memset(&*new, 0, sizeof(struct tr_tree6));
- memcpy(new->ip_addr, ip_addr, sizeof(new->ip_addr));
- inet_ntop(AF_INET6, new->ip_addr, nodename, nnlen);
- sprintf(new->hostname, "%s", nodename);
- /* resolve host name and store for later use */
-
- if (root == NULL) {
- root = new;
- }
- else {
- if ((current == root) && (memcmp(current->ip_addr, new->ip_addr, sizeof(new->ip_addr)) == 0)) {
- free(new);
- continue;
- }
- for (i=0; i<current->branches; i++) {
- if (memcmp(current->branch[i]->ip_addr, new->ip_addr, sizeof(new->ip_addr)) == 0) {
- current = current->branch[i];
- free(new);
- new = NULL;
- break;
- }
- }
- if (new == NULL) {
- continue;
- } else {
- i = 0;
- while (current->branch[i] != NULL)
- i++;
- current->branch[i] = new;
- current->branches++;
- }
- }
- current = new;
- }
- fp = fopen(DefaultTree6, "wb");
- if (fp == NULL) {
- printf("Error: Can't write default tree6 '%s', exiting save_tree()\n", DefaultTree6);
- exit (-15);
- }
- print_tree6(&*root);
- printf("Finished printing default tree6 '%s'\n", DefaultTree6);
- save_tree6(&*root, fp);
- fclose(fp);
+ struct tr_tree6 *root, *current, *new;
+ int i;
+ uint32_t ip_addr[4];
+ char buff[256], *tmpbuff;
+ char nodename[200];
+ socklen_t nnlen = 199;
+ FILE *fp;
+
+ root = NULL;
+ current = NULL;
+
+ printf("\nBuilding default tree (IPv6)\n\n");
+ if (inputfile == NULL)
+ inputfile = "/tmp/traceroute6.data";
+ fp = fopen(inputfile, "r");
+
+ if (fp == NULL) {
+ printf("Error: Default tree6 input file '%s' missing!\n",
inputfile);
+ exit (-5);
+ }
+ while ((fgets(buff, 256, fp)) != NULL) {
+ tmpbuff = strtok(buff, "\n");
+ if (tmpbuff == NULL) {
+ current = root;
+ continue;
+ }
+ get_addr6(ip_addr, tmpbuff);
+ new = (struct tr_tree6 *) malloc(sizeof(struct tr_tree6));
+ if (new == NULL) {
+ printf("Error: malloc failed, out of memory\n");
+ exit (-10);
+ }
+ memset(&*new, 0, sizeof(struct tr_tree6));
+ memcpy(new->ip_addr, ip_addr, sizeof(new->ip_addr));
+ inet_ntop(AF_INET6, new->ip_addr, nodename, nnlen);
+ sprintf(new->hostname, "%s", nodename);
+ /* resolve host name and store for later use */
+
+ if (root == NULL) {
+ root = new;
+ }
+ else {
+ if ((current == root) && (memcmp(current->ip_addr, new->ip_addr, sizeof(new->ip_addr)) == 0)) {
+ free(new);
+ continue;
+ }
+ for (i=0; i<current->branches; i++) {
+ if (memcmp(current->branch[i]->ip_addr, new->ip_addr, sizeof(new->ip_addr)) == 0) {
+ current = current->branch[i];
+ free(new);
+ new = NULL;
+ break;
+ }
+ }
+ if (new == NULL) {
+ continue;
+ } else {
+ i = 0;
+ while (current->branch[i] != NULL)
+ i++;
+ current->branch[i] = new;
+ current->branches++;
+ }
+ }
+ current = new;
+ }
+ fp = fopen(DefaultTree6, "wb");
+ if (fp == NULL) {
+ printf("Error: Can't write default tree6 '%s', exiting save_tree()\n", DefaultTree6);
+ exit (-15);
+ }
+ print_tree6(&*root);
+ printf("Finished printing default tree6 '%s'\n", DefaultTree6);
+ save_tree6(&*root, fp);
+ fclose(fp);
}
#endif

/* Compares the traceroute to the default tree
*/
-void
-compare(char* cmp_ip)
-{
- struct tr_tree *root, *current, *new;
- int i;
- uint32_t ip_addr, IPlist[64];
- char h_name[256], c_name[256], buff[256], *tmpbuff;
- struct hostent *hp;
- FILE *fp;
-
- root = NULL;
- current = NULL;
-
- printf("\nComparing traceroute (IPv4)\n\n");
- fp = fopen(DefaultTree, "rb");
- if (fp == NULL) {
- printf("Error: Can't read default tree '%s', exiting restore_tree()\n", DefaultTree);
- exit (-15);
- }
- new = (struct tr_tree *) malloc(sizeof(struct tr_tree));
- memset(&*new, 0, sizeof(struct tr_tree));
- if (fread(&*new, sizeof(struct tr_tree), 1, fp) == 0)
- return;
- else {
- for (i=0; i<25; i++)
- new->branch[i] = NULL;
- }
- if (root == NULL) {
- root = new;
- }
- restore_tree(&*root, fp);
- fclose(fp);
- fp = fopen(cmp_ip, "r");
- if (fp == NULL) {
- printf("Error: Can't read comparison file '%s', exiting main()\n", cmp_ip);
- exit (-17);
- }
- found_node = 0;
- current = root;
- i = 0;
- while ((fgets(buff, 256, fp)) != NULL) {
- tmpbuff = strtok(buff, "\n");
- IPlist[i] = get_addr(tmpbuff);
- log_println(5, "IPlist[%d] = %u.%u.%u.%u", (i),
- (IPlist[i] & 0xff), ((IPlist[i] >> 8) & 0xff),
- ((IPlist[i] >> 16) & 0xff), (IPlist[i] >> 24));
- i++;
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/tr-tree.c Fri Aug 18 03:16:24
2006
+++ /branches/kkumar_code_organize/src/tr-tree.c Mon Oct 17 06:43:25
2011
@@ -42,71 +42,68 @@
/* Restore the default tree, stored by the save tree routine above.
* Once restored, the comparison can take place.
*/
-void
-restore_tree(struct tr_tree *tmp, FILE *fp)
-{
- struct tr_tree *new;
- int i, j;
-
- for (i=0; i<tmp->branches; i++) {
- new = (struct tr_tree *) malloc(sizeof(struct tr_tree));
- memset(&*new, 0, sizeof(struct tr_tree));
- if (fread(&*new, sizeof(struct tr_tree), 1, fp) == 0)
- return;
- else {
- for (j=0; j<25; j++)
- new->branch[j] = NULL;
- }
- tmp->branch[i] = new;
- if (new->branches == 0) {
- continue;
- }
- restore_tree( &*tmp->branch[i], fp);
- }
+void restore_tree(struct tr_tree *tmp, FILE *fp) {
+ struct tr_tree *new;
+ int i, j;
+
+ for (i = 0; i < tmp->branches; i++) {
+ new = (struct tr_tree *) malloc(sizeof(struct tr_tree));
+ memset(&*new, 0, sizeof(struct tr_tree));
+ if (fread(&*new, sizeof(struct tr_tree), 1, fp) == 0)
+ return;
+ else {
+ for (j = 0; j < 25; j++)
+ new->branch[j] = NULL;
+ }
+ tmp->branch[i] = new;
+ if (new->branches == 0) {
+ continue;
+ }
+ restore_tree(&*tmp->branch[i], fp);
+ }
}

-u_int32_t
-find_compare(u_int32_t IPlist[], int cnt)
-{
-
- struct tr_tree *root, *current, *new;
- int i, j, k;
- uint32_t srv_addr;
- char h_name[256], c_name[256];
- FILE *fp;
- struct hostent *hp;
-
- root = NULL;
- current = NULL;
-
- fp = fopen(DefaultTree, "rb");
- if (fp == NULL) {
- log_println(5, "Error: Can't read default tree, exiting find_compare()");
- return 0;
- }
- new = (struct tr_tree *) malloc(sizeof(struct tr_tree));
- memset(&*new, 0, sizeof(struct tr_tree));
- if (fread(&*new, sizeof(struct tr_tree), 1, fp) == 0)
- return 0;
- else {
- for (i=0; i<25; i++)
- new->branch[i] = NULL;
- }
- if (root == NULL) {
- root = new;
- }
- restore_tree(&*root, fp);
- fclose(fp);
- found_node = 0;
- srv_addr = 0;
- current = root;
- log_println(6, "route to client contains %d hops", cnt);
- for (i=0; i<=cnt; i++) {
- log_print(6, "New client node [%u.%u.%u.%u] ",
- (IPlist[i] & 0xff), ((IPlist[i] >> 8) & 0xff),
- ((IPlist[i] >> 16) & 0xff), (IPlist[i] >> 24));
- log_println(6, "to map node [%u.%u.%u.%u]",
- (current->ip_addr & 0xff), ((current->ip_addr >> 8) & 0xff),
+u_int32_t find_compare(u_int32_t IPlist[], int cnt) {
+
+ struct tr_tree *root, *current, *new;
+ int i, j, k;
+ uint32_t srv_addr;
+ char h_name[256], c_name[256];
+ FILE * fp;
+ struct hostent *hp;
+
+ root = NULL;
+ current = NULL;
+
+ fp = fopen(DefaultTree, "rb");
+ if (fp == NULL) {
+ log_println(5,
+ "Error: Can't read default tree, exiting
find_compare()");
+ return 0;
+ }
+ new = (struct tr_tree *) malloc(sizeof(struct tr_tree));
+ memset(&*new, 0, sizeof(struct tr_tree));
+ if (fread(&*new, sizeof(struct tr_tree), 1, fp) == 0)
+ return 0;
+ else {
+ for (i = 0; i < 25; i++)
+ new->branch[i] = NULL;
+ }
+ if (root == NULL) {
+ root = new;
+ }
+ restore_tree(&*root, fp);
+ fclose(fp);
+ found_node = 0;
+ srv_addr = 0;
+ current = root;
+ log_println(6, "route to client contains %d hops", cnt);
+ for (i = 0; i <= cnt; i++) {
+ log_print(6, "New client node [%u.%u.%u.%u] ",
+ (IPlist[i] & 0xff), ((IPlist[i] >> 8) & 0xff),
+ ((IPlist[i] >> 16) & 0xff), (IPlist[i] >>
24));
+ log_println(6, "to map node [%u.%u.%u.%u]",
+ (current->ip_addr & 0xff),
((current->ip_addr >> 8) & 0xff),
((current->ip_addr >> 16) & 0xff), (current->ip_addr >> 24));
if (current->ip_addr == IPlist[i])
continue;
@@ -138,56 +135,60 @@
}
if (found_node == -1)
break;
- }
-
- if (current->ip_addr == IPlist[cnt]) {
- srv_addr = IPlist[cnt];
- found_node = 1;
- }
- if (srv_addr != 0)
- found_node = 1;
-
- if (found_node == -1) {
- log_println(6, "Broke out of compare loop, setting current pointer");
- if (current->branches == 1) {
- current = current->branch[0];
- if (current->branches == 0)
- found_node = 2;
- else {
- found_node = 4;
- current = root;
- }
- }
- else {
- found_node = 3;
- current = root;
- }
- }
-
- hp = gethostbyaddr((char *) &IPlist[i], 4, AF_INET);
- if (hp == NULL)
- strncpy(c_name, "Unknown Host", 13);
- else
- strncpy(c_name, hp->h_name, strlen(hp->h_name));
-
- if (found_node == 1) {
- log_println(5, "Router %s [%u.%u.%u.%u] is last common router in the path!",
- c_name, (IPlist[i] & 0xff), ((IPlist[i] >> 8) & 0xff),
- ((IPlist[i] >> 16) & 0xff), (IPlist[i] >> 24));
- return(srv_addr);
- }
- log_println(6, "New Server Node found! found_node set to %d", found_node);
- hp = (struct hostent *)gethostbyaddr((char *) &current->ip_addr, 4, AF_INET);
- if (hp == NULL)
- strncpy(h_name, "Unknown Host", 13);
- else
- strncpy(h_name, hp->h_name, strlen(hp->h_name));
-
- log_println(6, "\tThe eNDT server %s [%u.%u.%u.%u] is closest to %s [%u.%u.%u.%u]",
- h_name, (current->ip_addr & 0xff), ((current->ip_addr >> 8) & 0xff),
- ((current->ip_addr >> 16) & 0xff), (current->ip_addr >> 24),
- c_name, (IPlist[cnt] & 0xff), ((IPlist[cnt] >> 8) & 0xff),
- ((IPlist[cnt] >> 16) & 0xff), (IPlist[cnt] >> 24));
-
- return(current->ip_addr);
-}
+ }
+
+ if (current->ip_addr == IPlist[cnt]) {
+ srv_addr = IPlist[cnt];
+ found_node = 1;
+ }
+ if (srv_addr != 0)
+ found_node = 1;
+
+ if (found_node == -1) {
+ log_println(6, "Broke out of compare loop, setting current
pointer");
+ if (current->branches == 1) {
+ current = current->branch[0];
+ if (current->branches == 0)
+ found_node = 2;
+ else {
+ found_node = 4;
+ current = root;
+ }
+ } else {
+ found_node = 3;
+ current = root;
+ }
+ }
+
+ hp = gethostbyaddr((char *) &IPlist[i], 4, AF_INET);
+ if (hp == NULL)
+ strncpy(c_name, "Unknown Host", 13);
+ else
+ strncpy(c_name, hp->h_name, strlen(hp->h_name));
+
+ if (found_node == 1) {
+ log_println(5,
+ "Router %s [%u.%u.%u.%u] is last common router in
the path!",
+ c_name, (IPlist[i] & 0xff), ((IPlist[i] >> 8)
& 0xff),
+ ((IPlist[i] >> 16) & 0xff), (IPlist[i] >>
24));
+ return(srv_addr);
+ }
+ log_println(6, "New Server Node found! found_node set to %d", found_node);
+ hp = (struct hostent *) gethostbyaddr((char *) &current->ip_addr, 4,
+ AF_INET);
+ if (hp == NULL)
+ strncpy(h_name, "Unknown Host", 13);
+ else
+ strncpy(h_name, hp->h_name, strlen(hp->h_name));
+
+ log_println(
+ 6,
+ "\tThe eNDT server %s [%u.%u.%u.%u] is closest to %s
[%u.%u.%u.%u]",
+ h_name,
+ (current->ip_addr & 0xff), ((current->ip_addr >> 8) &
0xff),
+ ((current->ip_addr >> 16) & 0xff), (current->ip_addr
>> 24),
+ c_name, (IPlist[cnt] & 0xff), ((IPlist[cnt] >> 8) &
0xff),
+ ((IPlist[cnt] >> 16) & 0xff), (IPlist[cnt] >> 24));
+
+ return (current->ip_addr);
+}
=======================================
--- /branches/kkumar_code_organize/src/tr-tree.h Fri Aug 18 03:16:24
2006
+++ /branches/kkumar_code_organize/src/tr-tree.h Mon Oct 17 06:43:25
2011
@@ -10,12 +10,12 @@
#define _JS_TR_TREE_H

struct tr_tree {
- uint32_t ip_addr; /* IP addr of current node */
- int branches;
- char hostname[256]; /* Hostname placeholder */
- struct tr_tree *branch[25]; /* pointer to child */
- struct tr_tree *left; /* pointer to child */
- struct tr_tree *right; /* pointer to child */
+ uint32_t ip_addr; /* IP addr of current node */
+ int branches;
+ char hostname[256]; /* Hostname placeholder */
+ struct tr_tree *branch[25]; /* pointer to child */
+ struct tr_tree *left; /* pointer to child */
+ struct tr_tree *right; /* pointer to child */
};

#define DFLT_TREE "Default.tree" /* file containing default tree */
@@ -26,12 +26,12 @@
#ifdef AF_INET6

struct tr_tree6 {
- uint32_t ip_addr[4]; /* IP addr of the current node */
- int branches;
- char hostname[256]; /* Hostname placeholder */
- struct tr_tree6 *branch[25]; /* pointer to child */
- struct tr_tree6 *left; /* pointer to child */
- struct tr_tree6 *right; /* pointer to child */
+ uint32_t ip_addr[4]; /* IP addr of the current node */
+ int branches;
+ char hostname[256]; /* Hostname placeholder */
+ struct tr_tree6 *branch[25]; /* pointer to child */
+ struct tr_tree6 *left; /* pointer to child */
+ struct tr_tree6 *right; /* pointer to child */
};

#define DFLT_TREE6 "Default.tree6" /* file containing default tree for IPv6 nodes */
=======================================
--- /branches/kkumar_code_organize/src/tr-tree6.c Fri Aug 18 03:16:24
2006
+++ /branches/kkumar_code_organize/src/tr-tree6.c Mon Oct 17 06:43:25
2011
@@ -50,173 +50,173 @@
void
restore_tree6(struct tr_tree6 *tmp, FILE *fp)
{
- struct tr_tree6 *new;
- int i, j;
-
- for (i=0; i<tmp->branches; i++) {
- new = (struct tr_tree6 *) malloc(sizeof(struct tr_tree6));
- memset(&*new, 0, sizeof(struct tr_tree6));
- if (fread(&*new, sizeof(struct tr_tree6), 1, fp) == 0)
- return;
- else {
- for (j=0; j<25; j++)
- new->branch[j] = NULL;
- }
- tmp->branch[i] = new;
- if (new->branches == 0) {
- continue;
- }
- restore_tree6( &*tmp->branch[i], fp);
- }
+ struct tr_tree6 *new;
+ int i, j;
+
+ for (i=0; i<tmp->branches; i++) {
+ new = (struct tr_tree6 *) malloc(sizeof(struct tr_tree6));
+ memset(&*new, 0, sizeof(struct tr_tree6));
+ if (fread(&*new, sizeof(struct tr_tree6), 1, fp) == 0)
+ return;
+ else {
+ for (j=0; j<25; j++)
+ new->branch[j] = NULL;
+ }
+ tmp->branch[i] = new;
+ if (new->branches == 0) {
+ continue;
+ }
+ restore_tree6( &*tmp->branch[i], fp);
+ }
}

int
find_compare6(u_int32_t IPnode[4], u_int32_t IP6list[][4], int cnt)
{

- struct tr_tree6 *root, *current, *new;
- int i, j, k, fnode = 0;
- char h_name[256], c_name[256];
- char nodename[200];
- size_t nnlen;
- FILE *fp;
- struct hostent *hp;
-
- root = NULL;
- current = NULL;
-
- fp = fopen(DefaultTree6, "rb");
- if (fp == NULL) {
- log_println(5, "Error: Can't read default tree, exiting find_compare6()");
- return 0;
- }
- new = (struct tr_tree6 *) malloc(sizeof(struct tr_tree6));
- memset(&*new, 0, sizeof(struct tr_tree6));
- if (fread(&*new, sizeof(struct tr_tree6), 1, fp) == 0)
- return 0;
- else {
- for (i=0; i<25; i++)
- new->branch[i] = NULL;
- }
- if (root == NULL) {
- root = new;
- }
- restore_tree6(&*root, fp);
- fclose(fp);
- found_node = 0;
- current = root;
- log_println(6, "route to client contains %d hops", cnt);
- for (i=0; i<=cnt; i++) {
- if (get_debuglvl() > 5) {
- memset(nodename, 0, 200);
- nnlen = 199;
- inet_ntop(AF_INET6, (void *) IP6list[i], nodename, nnlen);
- log_print(6, "New client node [%s] ", nodename);
- memset(nodename, 0, 200);
- nnlen = 199;
- inet_ntop(AF_INET6, (void *) current->ip_addr, nodename, nnlen);
- log_println(6, "to map node [%s]", nodename);
- }
- if (memcmp(IP6list[i], current->ip_addr, sizeof(current->ip_addr)) == 0) {
- continue;
- }
- for (j=0; j<current->branches; j++) {
- if (get_debuglvl() > 4) {
- memset(nodename, 0, 200);
- nnlen = 199;
- inet_ntop(AF_INET6, (void *) current->branch[j]->ip_addr, nodename, nnlen);
- log_print(5, "Comparing map node [%s] ", nodename);
- memset(nodename, 0, 200);
- nnlen = 199;
- inet_ntop(AF_INET6, (void *) IP6list[i], nodename, nnlen);
- log_println(5, "to client node [%s], cnt = %d", nodename, i);
- }
-
- if (memcmp(current->branch[j]->ip_addr, IP6list[i], sizeof(IP6list[i])) == 0) {
- current = current->branch[j];
- found_node = 0;
- for (k=0; k<current->branches; k++) {
- if (current->branch[k]->branches == 0) {
- memcpy(IPnode, current->branch[k]->ip_addr, 16);
- if (get_debuglvl() > 4) {
- memset(nodename, 0, 200);
- nnlen = 199;
- inet_ntop(AF_INET6, (void *) IPnode, nodename, nnlen);
- log_println(5, "srv_addr set to [%s]", nodename);
- }
- found_node = 1;
- fnode = 1;
- }
- }
- break;
- }
- found_node = -1;
- }
- if (found_node == -1)
- break;
- }
-
- if (memcmp(current->ip_addr, IP6list[cnt], sizeof(IP6list[cnt])) == 0) {
- memcpy(IPnode, IP6list[cnt], 16);
- found_node = 1;
- fnode = 1;
- }
- if (fnode) {
- found_node = 1;
- }
-
- if (found_node == -1) {
- log_println(6, "Broke out of compare loop, setting current pointer");
- if (current->branches == 1) {
- current = current->branch[0];
- if (current->branches == 0)
- found_node = 2;
- else {
- found_node = 4;
- current = root;
- }
- }
- else {
- found_node = 3;
- current = root;
- }
- }
-
- hp = gethostbyaddr((char *) IP6list[i], 16, AF_INET6);
- if (hp == NULL)
- strncpy(c_name, "Unknown Host", 13);
- else
- strncpy(c_name, hp->h_name, strlen(hp->h_name));
-
- if (found_node == 1) {
- if (get_debuglvl() > 4) {
- memset(nodename, 0, 200);
- nnlen = 199;
- inet_ntop(AF_INET6, (void *) IP6list[i], nodename, nnlen);
- log_println(5, "Router %s [%s] is last common router in the path!", c_name, nodename);
- }
- return 1;
- }
- log_println(6, "New Server Node found! found_node set to %d", found_node);
- hp = (struct hostent *)gethostbyaddr((char *) current->ip_addr, 16, AF_INET6);
- if (hp == NULL)
- strncpy(h_name, "Unknown Host", 13);
- else
- strncpy(h_name, hp->h_name, strlen(hp->h_name));
-
- if (get_debuglvl() > 5) {
- memset(nodename, 0, 200);
- nnlen = 199;
- inet_ntop(AF_INET6, (void *) current->ip_addr, nodename, nnlen);
- log_print(6, "\tThe eNDT server %s [%s]", h_name, nodename);
- memset(nodename, 0, 200);
- nnlen = 199;
- inet_ntop(AF_INET6, (void *) IP6list[cnt], nodename, nnlen);
- log_println(6, " is closest to %s [%s]", c_name, nodename);
- }
-
- memcpy(IPnode, current->ip_addr, 16);
- return 1;
+ struct tr_tree6 *root, *current, *new;
+ int i, j, k, fnode = 0;
+ char h_name[256], c_name[256];
+ char nodename[200];
+ size_t nnlen;
+ FILE *fp;
+ struct hostent *hp;
+
+ root = NULL;
+ current = NULL;
+
+ fp = fopen(DefaultTree6, "rb");
+ if (fp == NULL) {
+ log_println(5, "Error: Can't read default tree, exiting find_compare6()");
+ return 0;
+ }
+ new = (struct tr_tree6 *) malloc(sizeof(struct tr_tree6));
+ memset(&*new, 0, sizeof(struct tr_tree6));
+ if (fread(&*new, sizeof(struct tr_tree6), 1, fp) == 0)
+ return 0;
+ else {
+ for (i=0; i<25; i++)
+ new->branch[i] = NULL;
+ }
+ if (root == NULL) {
+ root = new;
+ }
+ restore_tree6(&*root, fp);
+ fclose(fp);
+ found_node = 0;
+ current = root;
+ log_println(6, "route to client contains %d hops", cnt);
+ for (i=0; i<=cnt; i++) {
+ if (get_debuglvl() > 5) {
+ memset(nodename, 0, 200);
+ nnlen = 199;
+ inet_ntop(AF_INET6, (void *) IP6list[i], nodename,
nnlen);
+ log_print(6, "New client node [%s] ", nodename);
+ memset(nodename, 0, 200);
+ nnlen = 199;
+ inet_ntop(AF_INET6, (void *) current->ip_addr,
nodename, nnlen);
+ log_println(6, "to map node [%s]", nodename);
+ }
+ if (memcmp(IP6list[i], current->ip_addr, sizeof(current->ip_addr)) == 0) {
+ continue;
+ }
+ for (j=0; j<current->branches; j++) {
+ if (get_debuglvl() > 4) {
+ memset(nodename, 0, 200);
+ nnlen = 199;
+ inet_ntop(AF_INET6, (void *) current->branch[j]->ip_addr, nodename, nnlen);
+ log_print(5, "Comparing map node [%s] ",
nodename);
+ memset(nodename, 0, 200);
+ nnlen = 199;
+ inet_ntop(AF_INET6, (void *) IP6list[i],
nodename, nnlen);
+ log_println(5, "to client node [%s], cnt =
%d", nodename, i);
+ }
+
+ if (memcmp(current->branch[j]->ip_addr, IP6list[i], sizeof(IP6list[i])) == 0) {
+ current = current->branch[j];
+ found_node = 0;
+ for (k=0; k<current->branches; k++) {
+ if (current->branch[k]->branches ==
0) {
+ memcpy(IPnode,
current->branch[k]->ip_addr, 16);
+ if (get_debuglvl() > 4) {
+ memset(nodename, 0,
200);
+ nnlen = 199;
+ inet_ntop(AF_INET6,
(void *) IPnode, nodename, nnlen);
+ log_println(5, "srv_addr
set to [%s]", nodename);
+ }
+ found_node = 1;
+ fnode = 1;
+ }
+ }
+ break;
+ }
+ found_node = -1;
+ }
+ if (found_node == -1)
+ break;
+ }
+
+ if (memcmp(current->ip_addr, IP6list[cnt], sizeof(IP6list[cnt])) ==
0) {
+ memcpy(IPnode, IP6list[cnt], 16);
+ found_node = 1;
+ fnode = 1;
+ }
+ if (fnode) {
+ found_node = 1;
+ }
+
+ if (found_node == -1) {
+ log_println(6, "Broke out of compare loop, setting current
pointer");
+ if (current->branches == 1) {
+ current = current->branch[0];
+ if (current->branches == 0)
+ found_node = 2;
+ else {
+ found_node = 4;
+ current = root;
+ }
+ }
+ else {
+ found_node = 3;
+ current = root;
+ }
+ }
+
+ hp = gethostbyaddr((char *) IP6list[i], 16, AF_INET6);
+ if (hp == NULL)
+ strncpy(c_name, "Unknown Host", 13);
+ else
+ strncpy(c_name, hp->h_name, strlen(hp->h_name));
+
+ if (found_node == 1) {
+ if (get_debuglvl() > 4) {
+ memset(nodename, 0, 200);
+ nnlen = 199;
+ inet_ntop(AF_INET6, (void *) IP6list[i], nodename,
nnlen);
+ log_println(5, "Router %s [%s] is last common router in the path!", c_name, nodename);
+ }
+ return 1;
+ }
+ log_println(6, "New Server Node found! found_node set to %d", found_node);
+ hp = (struct hostent *)gethostbyaddr((char *) current->ip_addr, 16, AF_INET6);
+ if (hp == NULL)
+ strncpy(h_name, "Unknown Host", 13);
+ else
+ strncpy(h_name, hp->h_name, strlen(hp->h_name));
+
+ if (get_debuglvl() > 5) {
+ memset(nodename, 0, 200);
+ nnlen = 199;
+ inet_ntop(AF_INET6, (void *) current->ip_addr, nodename,
nnlen);
+ log_print(6, "\tThe eNDT server %s [%s]", h_name, nodename);
+ memset(nodename, 0, 200);
+ nnlen = 199;
+ inet_ntop(AF_INET6, (void *) IP6list[cnt], nodename, nnlen);
+ log_println(6, " is closest to %s [%s]", c_name, nodename);
+ }
+
+ memcpy(IPnode, current->ip_addr, 16);
+ return 1;
}

#endif
=======================================
--- /branches/kkumar_code_organize/src/troute.c Fri Aug 18 03:16:24 2006
+++ /branches/kkumar_code_organize/src/troute.c Mon Oct 17 06:43:25 2011
@@ -95,20 +95,19 @@
#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
#endif

-
/*
* format of a (udp) probe packet.
*/
struct opacket {
- struct ip ip;
- struct udphdr udp;
- u_char seq; /* sequence number of this packet */
- u_char ttl; /* ttl packet left with */
- struct timeval tv; /* time packet left */
+ struct ip ip;
+ struct udphdr udp;
+ u_char seq; /* sequence number of this packet */
+ u_char ttl; /* ttl packet left with */
+ struct timeval tv; /* time packet left */
};

-u_char packet[512]; /* last inbound (icmp) packet */
-struct opacket *outpacket; /* last output (udp) packet */
+u_char packet[512]; /* last inbound (icmp) packet */
+struct opacket *outpacket; /* last output (udp) packet */

int wait_for_reply __P((int, struct sockaddr_in *));
void send_probe __P((int, int));
@@ -116,313 +115,295 @@
int packet_ok __P((u_char *, int, struct sockaddr_in *, int));
void tvsub __P((struct timeval *, struct timeval *));

-int s; /* receive (icmp) socket file descriptor */
-int sndsock; /* send (udp) socket file descriptor */
-struct timezone tz; /* leftover */
-
-struct sockaddr whereto; /* Who to try to reach */
-int datalen; /* How much data */
+int s; /* receive (icmp) socket file descriptor */
+int sndsock; /* send (udp) socket file descriptor */
+struct timezone tz; /* leftover */
+
+struct sockaddr whereto; /* Who to try to reach */
+int datalen; /* How much data */

char *source = 0;
char *hostname;

int nprobes = 2;
u_short ident;
-u_short port = 32768+666; /* start udp dest port # for probe packets */
-int options; /* socket options */
+u_short port = 32768 + 666; /* start udp dest port # for probe packets */
+int options; /* socket options */
int verbose;
-int waittime = 1; /* time to wait for response (in seconds) */
-int nflag; /* print addresses numerically */
-
-void
-find_route(u_int32_t destIP, u_int32_t IPlist[], int max_ttl)
-{
- extern char *optarg;
- extern int optind;
- struct protoent *pe;
- struct sockaddr_in from, *to;
- int i, on, probe, seq, tos, ttl;
-
- on = 1;
- seq = tos = 0;
- to = (struct sockaddr_in *)&whereto;
- (void) bzero((char *)&whereto, sizeof(struct sockaddr));
- to->sin_family = AF_INET;
- to->sin_addr.s_addr = destIP;
-
- datalen += sizeof(struct opacket);
- outpacket = (struct opacket *)malloc((unsigned)datalen);
- if (! outpacket) {
- perror("traceroute: malloc");
- exit(1);
- }
- (void) bzero((char *)outpacket, datalen);
- outpacket->ip.ip_dst = to->sin_addr;
- outpacket->ip.ip_tos = tos;
- outpacket->ip.ip_v = IPVERSION;
- outpacket->ip.ip_id = 0;
-
- ident = (getpid() & 0xffff) | 0x8000;
-
- if ((pe = getprotobyname("icmp")) == NULL) {
- fprintf(stderr, "icmp: unknown protocol\n");
- exit(10);
- }
- if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0) {
- perror("traceroute: icmp socket");
- exit(5);
- }
-
- if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
- perror("traceroute: raw socket");
- exit(5);
- }
-
- if (source) {
- (void) bzero((char *)&from, sizeof(struct sockaddr));
- from.sin_family = AF_INET;
- from.sin_addr.s_addr = inet_addr(source);
- if (from.sin_addr.s_addr == -1) {
- printf("traceroute: unknown host %s\n", source);
- exit(1);
- }
- outpacket->ip.ip_src = from.sin_addr;
+int waittime = 1; /* time to wait for response (in seconds) */
+int nflag; /* print addresses numerically */
+
+void find_route(u_int32_t destIP, u_int32_t IPlist[], int max_ttl) {
+ extern char *optarg;
+ extern int optind;
+ struct protoent *pe;
+ struct sockaddr_in from, *to;
+ int i, on, probe, seq, tos, ttl;
+
+ on = 1;
+ seq = tos = 0;
+ to = (struct sockaddr_in *) &whereto;
+ (void) bzero((char *) &whereto, sizeof(struct sockaddr));
+ to->sin_family = AF_INET;
+ to->sin_addr.s_addr = destIP;
+
+ datalen += sizeof(struct opacket);
+ outpacket = (struct opacket *) malloc((unsigned) datalen);
+ if (!outpacket) {
+ perror("traceroute: malloc");
+ exit(1);
+ }
+ (void) bzero((char *) outpacket, datalen);
+ outpacket->ip.ip_dst = to->sin_addr;
+ outpacket->ip.ip_tos = tos;
+ outpacket->ip.ip_v = IPVERSION;
+ outpacket->ip.ip_id = 0;
+
+ ident = (getpid() & 0xffff) | 0x8000;
+
+ if ((pe = getprotobyname("icmp")) == NULL) {
+ fprintf(stderr, "icmp: unknown protocol\n");
+ exit(10);
+ }
+ if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0) {
+ perror("traceroute: icmp socket");
+ exit(5);
+ }
+
+ if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
+ perror("traceroute: raw socket");
+ exit(5);
+ }
+
+ if (source) {
+ (void) bzero((char *) &from, sizeof(struct sockaddr));
+ from.sin_family = AF_INET;
+ from.sin_addr.s_addr = inet_addr(source);
+ if (from.sin_addr.s_addr == -1) {
+ printf("traceroute: unknown host %s\n", source);
+ exit(1);
+ }
+ outpacket->ip.ip_src = from.sin_addr;
#ifndef IP_HDRINCL
- if (bind(sndsock, (struct sockaddr *)&from, sizeof(from)) < 0) {
- perror ("traceroute: bind:");
- exit (1);
- }
+ if (bind(sndsock, (struct sockaddr *) &from, sizeof(from)) <
0) {
+ perror("traceroute: bind:");
+ exit(1);
+ }
#endif /* IP_HDRINCL */
- }
-
- for (ttl = 1; ttl <= max_ttl; ++ttl) {
- u_long lastaddr = 0;
- int got_there = 0;
- int unreachable = 0;
-
- for (probe = 0; probe < nprobes; ++probe) {
- int cc;
- struct timeval t1, t2;
- struct timezone tz;
- struct ip *ip;
-
- (void) gettimeofday(&t1, &tz);
- send_probe(++seq, ttl);
- while ((cc = wait_for_reply(s, &from))) {
- (void) gettimeofday(&t2, &tz);
- if ((i = packet_ok(packet, cc, &from, seq))) {
- if (from.sin_addr.s_addr != lastaddr) {
- IPlist[ttl-1] = from.sin_addr.s_addr;
- lastaddr = from.sin_addr.s_addr;
- }
- log_println(5, "Probe %d resulted in reply from [%s]", probe, inet_ntoa(from.sin_addr));
-
- switch(i - 1) {
- case ICMP_UNREACH_PORT:
+ }
+
+ for (ttl = 1; ttl <= max_ttl; ++ttl) {
+ u_long lastaddr = 0;
+ int got_there = 0;
+ int unreachable = 0;
+
+ for (probe = 0; probe < nprobes; ++probe) {
+ int cc;
+ struct timeval t1, t2;
+ struct timezone tz;
+ struct ip *ip;
+
+ (void) gettimeofday(&t1, &tz);
+ send_probe(++seq, ttl);
+ while ((cc = wait_for_reply(s, &from))) {
+ (void) gettimeofday(&t2, &tz);
+ if ((i = packet_ok(packet, cc, &from, seq))) {
+ if (from.sin_addr.s_addr != lastaddr)
{
+ IPlist[ttl - 1] =
from.sin_addr.s_addr;
+ lastaddr =
from.sin_addr.s_addr;
+ }
+ log_println(5, "Probe %d resulted in reply
from [%s]",
+ probe,
inet_ntoa(from.sin_addr));
+
+ switch (i - 1) {
+ case ICMP_UNREACH_PORT:
#ifndef ARCHAIC
- ip = (struct ip *)packet;
+ ip = (struct ip *) packet;
#endif /* ARCHAIC */
- ++got_there;
- break;
- case ICMP_UNREACH_NET:
- ++unreachable;
- break;
- case ICMP_UNREACH_HOST:
- ++unreachable;
- break;
- case ICMP_UNREACH_PROTOCOL:
- ++got_there;
- break;
- case ICMP_UNREACH_NEEDFRAG:
- ++unreachable;
- break;
- case ICMP_UNREACH_SRCFAIL:
- ++unreachable;
- break;
- }
- break;
- }
- }
- }
- if (got_there || unreachable >= nprobes-1) {
- return;
- }
- }
+ ++got_there;
+ break;
+ case ICMP_UNREACH_NET:
+ ++unreachable;
+ break;
+ case ICMP_UNREACH_HOST:
+ ++unreachable;
+ break;
+ case ICMP_UNREACH_PROTOCOL:
+ ++got_there;
+ break;
+ case ICMP_UNREACH_NEEDFRAG:
+ ++unreachable;
+ break;
+ case ICMP_UNREACH_SRCFAIL:
+ ++unreachable;
+ break;
+ }
+ break;
+ }
+ }
+ }
+ if (got_there || unreachable >= nprobes - 1) {
+ return;
+ }
+ }
}

-int
-wait_for_reply(sock, from)
- int sock;
- struct sockaddr_in *from;
-{
- fd_set fds;
- struct timeval wait;
- int cc = 0;
- socklen_t fromlen = sizeof (*from);
-
- FD_ZERO(&fds);
- FD_SET(sock, &fds);
- wait.tv_sec = waittime; wait.tv_usec = 0;
-
- if (select(sock+1, &fds, (fd_set *)0, (fd_set *)0, &wait) > 0)
- cc=recvfrom(s, (char *)packet, sizeof(packet), 0,
- (struct sockaddr *)from, &fromlen);
-
- return(cc);
+int wait_for_reply(sock, from)
+ int sock;struct sockaddr_in *from; {
+ fd_set fds;
+ struct timeval wait;
+ int cc = 0;
+ socklen_t fromlen = sizeof(*from);
+
+ FD_ZERO(&fds);
+ FD_SET(sock, &fds);
+ wait.tv_sec = waittime;
+ wait.tv_usec = 0;
+
+ if (select(sock + 1, &fds, (fd_set *) 0, (fd_set *) 0, &wait) > 0)
+ cc = recvfrom(s, (char *) packet, sizeof(packet), 0,
+ (struct sockaddr *) from, &fromlen);
+
+ return (cc);
}

-
-void
-send_probe(seq, ttl)
- int seq, ttl;
-{
- struct opacket *op = outpacket;
- struct ip *ip = &op->ip;
- struct udphdr *up = &op->udp;
- int i;
-
- ip->ip_off = 0;
- ip->ip_hl = sizeof(*ip) >> 2;
- ip->ip_p = IPPROTO_UDP;
- ip->ip_len = datalen;
- ip->ip_ttl = ttl;
- ip->ip_v = IPVERSION;
- ip->ip_id = htons(ident+seq);
+void send_probe(seq, ttl)
+ int seq, ttl; {
+ struct opacket *op = outpacket;
+ struct ip *ip = &op->ip;
+ struct udphdr *up = &op->udp;
+ int i;
+
+ ip->ip_off = 0;
+ ip->ip_hl = sizeof(*ip) >> 2;
+ ip->ip_p = IPPROTO_UDP;
+ ip->ip_len = datalen;
+ ip->ip_ttl = ttl;
+ ip->ip_v = IPVERSION;
+ ip->ip_id = htons(ident + seq);

#ifdef __FAVOR_BSD
- up->uh_sport = htons(ident);
- up->uh_dport = htons(port+seq);
- up->uh_ulen = htons((u_short)(datalen - sizeof(struct ip)));
- up->uh_sum = 0;
+ up->uh_sport = htons(ident);
+ up->uh_dport = htons(port+seq);
+ up->uh_ulen = htons((u_short)(datalen - sizeof(struct ip)));
+ up->uh_sum = 0;
#else
- up->source = htons(ident);
- up->dest = htons(port+seq);
- up->len = htons((u_short)(datalen - sizeof(struct ip)));
- up->check = 0;
+ up->source = htons(ident);
+ up->dest = htons(port + seq);
+ up->len = htons((u_short)(datalen - sizeof(struct ip)));
+ up->check = 0;
#endif

- op->seq = seq;
- op->ttl = ttl;
- (void) gettimeofday(&op->tv, &tz);
-
- i = sendto(sndsock, (char *)outpacket, datalen, 0, &whereto,
- sizeof(struct sockaddr));
- if (i < 0 || i != datalen) {
- if (i<0)
- perror("sendto");
- }
+ op->seq = seq;
+ op->ttl = ttl;
+ (void) gettimeofday(&op->tv, &tz);
+
+ i = sendto(sndsock, (char *) outpacket, datalen, 0, &whereto,
+ sizeof(struct sockaddr));
+ if (i < 0 || i != datalen) {
+ if (i < 0)
+ perror("sendto");
+ }
}

-
-double
-deltaT(t1p, t2p)
- struct timeval *t1p, *t2p;
-{
- register double dt;
-
- dt = (double)(t2p->tv_sec - t1p->tv_sec) * 1000.0 +
- (double)(t2p->tv_usec - t1p->tv_usec) / 1000.0;
- return (dt);
+double deltaT(t1p, t2p)
+ struct timeval *t1p, *t2p; {
+ register double dt;
+
+ dt = (double) (t2p->tv_sec - t1p->tv_sec) * 1000.0
+ + (double) (t2p->tv_usec - t1p->tv_usec) / 1000.0;
+ return (dt);
}

-
-int
-packet_ok(buf, cc, from, seq)
- u_char *buf;
- int cc;
- struct sockaddr_in *from;
- int seq;
-{
- register struct icmp *icp;
- u_char type, code;
- int hlen;
+int packet_ok(buf, cc, from, seq)
+ u_char *buf;int cc;struct sockaddr_in *from;int seq; {
+ register struct icmp *icp;
+ u_char type, code;
+ int hlen;
#ifndef ARCHAIC
- struct ip *ip;
-
- ip = (struct ip *) buf;
- hlen = ip->ip_hl << 2;
- if (cc < hlen + ICMP_MINLEN) {
- return (0);
- }
- cc -= hlen;
- icp = (struct icmp *)(buf + hlen);
+ struct ip *ip;
+
+ ip = (struct ip *) buf;
+ hlen = ip->ip_hl << 2;
+ if (cc < hlen + ICMP_MINLEN) {
+ return (0);
+ }
+ cc -= hlen;
+ icp =
+ (struct icmp *) (buf + hlen);
#else
- icp = (struct icmp *)buf;
+ icp = (struct icmp *)buf;
#endif /* ARCHAIC */
- type = icp->icmp_type; code = icp->icmp_code;
- if ((type == ICMP_TIMXCEED && code == ICMP_TIMXCEED_INTRANS) ||
- type == ICMP_UNREACH) {
- struct ip *hip;
- struct udphdr *up;
-
- hip = &icp->icmp_ip;
- hlen = hip->ip_hl << 2;
- up = (struct udphdr *)((u_char *)hip + hlen);
- if (hlen + 12 <= cc && hip->ip_p == IPPROTO_UDP &&
+ type = icp->icmp_type; code = icp->icmp_code;
+ if ((type == ICMP_TIMXCEED && code ==
ICMP_TIMXCEED_INTRANS) ||
+ type == ICMP_UNREACH) {
+ struct ip *hip;
+ struct udphdr *up;
+
+ hip = &icp->icmp_ip;
+ hlen = hip->ip_hl << 2;
+ up = (struct udphdr *)((u_char *)hip + hlen);
+ if (hlen + 12 <= cc && hip->ip_p == IPPROTO_UDP
&&
#ifdef __FAVOR_BSD
- up->uh_sport == htons(ident) &&
- up->uh_dport == htons(port+seq))
+ up->uh_sport == htons(ident) &&
+ up->uh_dport == htons(port+seq))
#else
- up->source == htons(ident) &&
- up->dest == htons(port+seq))
+ up->source == htons(ident) &&
+ up->dest == htons(port+seq))
#endif
- return (type == ICMP_TIMXCEED? -1 : code+1);
- }
- return(0);
-}
-
-
+ return (type == ICMP_TIMXCEED? -1 : code+1);
+ }
+ return(0)
+;}
#ifdef notyet
-/*
- * Checksum routine for Internet Protocol family headers (C Version)
- */
-u_short
-in_cksum(addr, len)
- u_short *addr;
- int len;
-{
- register int nleft = len;
- register u_short *w = addr;
- register u_short answer;
- register int sum = 0;
-
- /*
- * Our algorithm is simple, using a 32 bit accumulator (sum),
- * we add sequential 16 bit words to it, and at the end, fold
- * back all the carry bits from the top 16 bits into the lower
- * 16 bits.
- */
- while (nleft > 1) {
- sum += *w++;
- nleft -= 2;
- }
-
- /* mop up an odd byte, if necessary */
- if (nleft == 1)
- sum += *(u_char *)w;
-
- /*
- * add back carry outs from top 16 bits to low 16 bits
- */
- sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
- sum += (sum >> 16); /* add carry */
- answer = ~sum; /* truncate to 16 bits */
- return (answer);
-}
+ /*
+ * Checksum routine for Internet Protocol family headers (C Version)
+ */
+ u_short
+ in_cksum(addr, len)
+ u_short *addr;
+ int len;
+ {
+ register int nleft = len;
+ register u_short *w = addr;
+ register u_short answer;
+ register int sum = 0;
+
+ /*
+ * Our algorithm is simple, using a 32 bit accumulator (sum),
+ * we add sequential 16 bit words to it, and at the end, fold
+ * back all the carry bits from the top 16 bits into the
lower
+ * 16 bits.
+ */
+ while (nleft > 1) {
+ sum += *w++;
+ nleft -= 2;
+ }
+
+ /* mop up an odd byte, if necessary */
+ if (nleft == 1)
+ sum += *(u_char *)w;
+
+ /*
+ * add back carry outs from top 16 bits to low 16 bits
+ */
+ sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
+ sum += (sum >> 16); /* add carry */
+ answer = ~sum; /* truncate to 16 bits */
+ return (answer);
+ }
#endif /* notyet */

-/*
- * Subtract 2 timeval structs: out = out - in.
- * Out is assumed to be >= in.
- */
-void
-tvsub(out, in)
- register struct timeval *out, *in;
-{
- if ((out->tv_usec -= in->tv_usec) < 0) {
- out->tv_sec--;
- out->tv_usec += 1000000;
- }
- out->tv_sec -= in->tv_sec;
+ /*
+ * Subtract 2 timeval structs: out = out - in.
+ * Out is assumed to be >= in.
+ */
+voidtvsub (out, in)
+ register struct timeval *out, *in; {
+ if ((out->tv_usec -= in->tv_usec) < 0) {
+ out->tv_sec--;
+ out->tv_usec += 1000000;
+ }
+ out->tv_sec -= in->tv_sec;
}

=======================================
--- /branches/kkumar_code_organize/src/troute6.c Wed Apr 8 12:34:07
2009
+++ /branches/kkumar_code_organize/src/troute6.c Mon Oct 17 06:43:25
2011
@@ -244,7 +244,6 @@
* Tue Dec 20 03:50:13 PST 1988
*/

-
#include <sys/param.h>
#include <sys/time.h>
#include <sys/socket.h>
@@ -294,7 +293,7 @@
#define Printf (void)printf

/* taken from linux/ipv6.h */
-
+
/*
* IPv6 fixed header
*
@@ -304,41 +303,41 @@

struct ipv6hdr {
#if defined(__LITTLE_ENDIAN_BITFIELD)
- __u8 priority:4,
- version:4;
+ __u8 priority:4,
+ version:4;
#elif defined(__BIG_ENDIAN_BITFIELD)
- __u8 version:4,
- priority:4;
+ __u8 version:4,
+ priority:4;
#else
#error "Please fix <asm/byteorder.h>"
#endif
- __u8 flow_lbl[3];
-
- __u16 payload_len;
- __u8 nexthdr;
- __u8 hop_limit;
-
- struct in6_addr saddr;
- struct in6_addr daddr;
+ __u8 flow_lbl[3];
+
+ __u16 payload_len;
+ __u8 nexthdr;
+ __u8 hop_limit;
+
+ struct in6_addr saddr;
+ struct in6_addr daddr;
};

/* --- */
-
-u_char packet[512]; /* last inbound (icmp) packet */
-
-int wait_for_reply6(int, struct sockaddr_in6 *, int);
-int packet_ok6(u_char *buf, int cc, struct sockaddr_in6 *from, int seq,
- struct timeval *);
-void send_probe6(int seq, int ttl);
-double deltaT (struct timeval *, struct timeval *);
-void tvsub (struct timeval *, struct timeval *);
-void usage(void);
-
-int icmp_sock; /* receive (icmp) socket file descriptor */
-int sndsock; /* send (udp) socket file descriptor */
-struct timezone tz; /* leftover */
-
-struct sockaddr_in6 whereto; /* Who to try to reach */
+
+u_char packet[512]; /* last inbound (icmp) packet */
+
+int wait_for_reply6(int, struct sockaddr_in6 *, int);
+int packet_ok6(u_char *buf, int cc, struct sockaddr_in6 *from, int seq,
+ struct timeval *);
+void send_probe6(int seq, int ttl);
+double deltaT (struct timeval *, struct timeval *);
+void tvsub (struct timeval *, struct timeval *);
+void usage(void);
+
+int icmp_sock; /* receive (icmp) socket file descriptor */
+int sndsock; /* send (udp) socket file descriptor */
+struct timezone tz; /* leftover */
+
+struct sockaddr_in6 whereto; /* Who to try to reach */

struct sockaddr_in6 saddr;
struct sockaddr_in6 firsthop;
@@ -348,279 +347,275 @@

int nprobes6 = 2;
pid_t ident;
-u_short port6 = 32768+666; /* start udp dest port # for probe packets */
-int options; /* socket options */
+u_short port6 = 32768+666; /* start udp dest port # for probe packets */
+int options; /* socket options */
int verbose;
-int waittime6 = 5; /* time to wait for response (in seconds) */
-int nflag; /* print addresses numerically */
-
+int waittime6 = 5; /* time to wait for response (in seconds) */
+int nflag; /* print addresses numerically */

struct pkt_format
{
- __u32 ident;
- __u32 seq;
- struct timeval tv;
+ __u32 ident;
+ __u32 seq;
+ struct timeval tv;
};

char *sendbuff;
int datalen = sizeof(struct pkt_format);

-
-
void
find_route6(char* dst, u_int32_t IPlist[][4], int max_ttl)
{
- extern char *optarg;
- extern int optind;
- struct hostent *hp;
- struct sockaddr_in6 from, *to;
- int i, on, probe, seq, tos, ttl;
- int socket_errno;
-
- icmp_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
- socket_errno = errno;
-
- setuid(getuid());
-
- on = 1;
- seq = tos = 0;
- to = (struct sockaddr_in6 *)&whereto;
- (void) bzero((char *)&whereto, sizeof(whereto));
-
- to->sin6_family = AF_INET6;
- to->sin6_port = htons(port6);
-
- if (inet_pton(AF_INET6, dst, &to->sin6_addr) > 0) {
- hostname = dst;
- } else {
- hp = gethostbyname2(dst, AF_INET6);
- if (hp) {
- memmove((caddr_t)&to->sin6_addr, hp->h_addr, sizeof(to->sin6_addr));
- hostname = (char *)hp->h_name;
- } else {
- (void)fprintf(stderr,
- "traceroute: unknown host %s\n", dst);
- return;
- }
- }
- firsthop = *to;
-
- ident = (getpid() & 0xffff) | 0x8000;
-
- sendbuff = malloc(datalen);
- if (sendbuff == NULL) {
- fprintf(stderr, "malloc failed\n");
- return;
- }
-
- if (icmp_sock < 0) {
- errno = socket_errno;
- perror("traceroute6: icmp socket");
- return;
- }
-
- if (options & SO_DEBUG)
- setsockopt(icmp_sock, SOL_SOCKET, SO_DEBUG,
- (char *)&on, sizeof(on));
- if (options & SO_DONTROUTE)
- setsockopt(icmp_sock, SOL_SOCKET, SO_DONTROUTE,
- (char *)&on, sizeof(on));
- on = 2;
- if (setsockopt(icmp_sock, SOL_RAW, IPV6_CHECKSUM, &on, sizeof(on)) < 0) {
- perror("setsockopt(RAW_CHECKSUM)");
- return;
- }
-
- if ((sndsock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- perror("traceroute: UDP socket");
- return;
- }
+ extern char *optarg;
+ extern int optind;
+ struct hostent *hp;
+ struct sockaddr_in6 from, *to;
+ int i, on, probe, seq, tos, ttl;
+ int socket_errno;
+
+ icmp_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+ socket_errno = errno;
+
+ setuid(getuid());
+
+ on = 1;
+ seq = tos = 0;
+ to = (struct sockaddr_in6 *)&whereto;
+ (void) bzero((char *)&whereto, sizeof(whereto));
+
+ to->sin6_family = AF_INET6;
+ to->sin6_port = htons(port6);
+
+ if (inet_pton(AF_INET6, dst, &to->sin6_addr) > 0) {
+ hostname = dst;
+ } else {
+ hp = gethostbyname2(dst, AF_INET6);
+ if (hp) {
+ memmove((caddr_t)&to->sin6_addr, hp->h_addr,
sizeof(to->sin6_addr));
+ hostname = (char *)hp->h_name;
+ } else {
+ (void)fprintf(stderr,
+ "traceroute: unknown host %s\n", dst);
+ return;
+ }
+ }
+ firsthop = *to;
+
+ ident = (getpid() & 0xffff) | 0x8000;
+
+ sendbuff = malloc(datalen);
+ if (sendbuff == NULL) {
+ fprintf(stderr, "malloc failed\n");
+ return;
+ }
+
+ if (icmp_sock < 0) {
+ errno = socket_errno;
+ perror("traceroute6: icmp socket");
+ return;
+ }
+
+ if (options & SO_DEBUG)
+ setsockopt(icmp_sock, SOL_SOCKET, SO_DEBUG,
+ (char *)&on, sizeof(on));
+ if (options & SO_DONTROUTE)
+ setsockopt(icmp_sock, SOL_SOCKET, SO_DONTROUTE,
+ (char *)&on, sizeof(on));
+ on = 2;
+ if (setsockopt(icmp_sock, SOL_RAW, IPV6_CHECKSUM, &on, sizeof(on)) <
0) {
+ perror("setsockopt(RAW_CHECKSUM)");
+ return;
+ }
+
+ if ((sndsock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+ perror("traceroute: UDP socket");
+ return;
+ }
#ifdef SO_SNDBUF
- if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&datalen,
- sizeof(datalen)) < 0) {
- perror("traceroute: SO_SNDBUF");
- return;
- }
+ if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&datalen,
+ sizeof(datalen)) < 0) {
+ perror("traceroute: SO_SNDBUF");
+ return;
+ }
#endif /* SO_SNDBUF */

- if (options & SO_DEBUG)
- (void) setsockopt(sndsock, SOL_SOCKET, SO_DEBUG,
- (char *)&on, sizeof(on));
- if (options & SO_DONTROUTE)
- (void) setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE,
- (char *)&on, sizeof(on));
-
- if (source6 == NULL) {
- socklen_t alen;
- int probe_fd = socket(AF_INET6, SOCK_DGRAM, 0);
-
- if (probe_fd < 0) {
- perror("socket");
- return;
- }
- if (device) {
- if (setsockopt(probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device)+1) == -1)
- perror("WARNING: interface is ignored");
- }
- firsthop.sin6_port = htons(1025);
- if (connect(probe_fd, (struct sockaddr*)&firsthop, sizeof(firsthop)) == -1) {
- perror("connect");
- return;
- }
- alen = sizeof(saddr);
- if (getsockname(probe_fd, (struct sockaddr*)&saddr, &alen) == -1) {
- perror("getsockname");
- return;
- }
- saddr.sin6_port = 0;
- close(probe_fd);
- } else {
- (void) bzero((char *)&saddr, sizeof(saddr));
- saddr.sin6_family = AF_INET6;
- if (inet_pton(AF_INET6, source6, &saddr.sin6_addr) < 0)
- {
- Printf("traceroute: unknown addr %s\n", source6);
- return;
- }
- }
-
- if (bind(sndsock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
- perror ("traceroute: bind sending socket");
- return;
- }
- if (bind(icmp_sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
- perror ("traceroute: bind icmp6 socket");
- return;
- }
-
- for (ttl = 1; ttl <= max_ttl; ++ttl) {
- struct in6_addr lastaddr = {{{0,}}};
- int got_there = 0;
- int unreachable = 0;
-
- /* Printf("%2d ", ttl); */
- for (probe = 0; probe < nprobes6; ++probe) {
- int cc, reset_timer;
- struct timeval t1, t2;
- struct timezone tz;
-
- gettimeofday(&t1, &tz);
- send_probe6(++seq, ttl);
- reset_timer = 1;
-
- while ((cc = wait_for_reply6(icmp_sock, &from, reset_timer)) != 0) {
- gettimeofday(&t2, &tz);
- if (cc > 0 && (i = packet_ok6(packet, cc, &from, seq, &t1))) {
- reset_timer = 1;
- if (memcmp(&from.sin6_addr, &lastaddr, sizeof(from.sin6_addr))) {
- memcpy(IPlist[ttl-1],
- &from.sin6_addr,
- sizeof(IPlist[ttl-1]));
- memcpy(&lastaddr,
- &from.sin6_addr,
- sizeof(lastaddr));
- }
- if (get_debuglvl() > 4) {
- char tmp[MAXHOSTNAMELEN];
- inet_ntop(AF_INET6, &from.sin6_addr, tmp, sizeof(tmp));
- log_println(5, "Probe %d resulted in reply from [%s]", probe, tmp);
- }
- switch(i - 1) {
- case ICMPV6_PORT_UNREACH:
- ++got_there;
- break;
-
- case ICMPV6_NOROUTE:
- ++unreachable;
- Printf(" !N");
- break;
- case ICMPV6_ADDR_UNREACH:
- ++unreachable;
- Printf(" !H");
- break;
-
- case ICMPV6_ADM_PROHIBITED:
- ++unreachable;
- Printf(" !S");
- break;
- }
- break;
- } else
- reset_timer = 0;
- }
- if (cc <= 0)
- Printf(" *");
- (void) fflush(stdout);
- }
- if (got_there || (unreachable > 0 && unreachable >= nprobes6-1))
- return;
- }
+ if (options & SO_DEBUG)
+ (void) setsockopt(sndsock, SOL_SOCKET, SO_DEBUG,
+ (char *)&on, sizeof(on));
+ if (options & SO_DONTROUTE)
+ (void) setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE,
+ (char *)&on, sizeof(on));
+
+ if (source6 == NULL) {
+ socklen_t alen;
+ int probe_fd = socket(AF_INET6, SOCK_DGRAM, 0);
+
+ if (probe_fd < 0) {
+ perror("socket");
+ return;
+ }
+ if (device) {
+ if (setsockopt(probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device)+1) == -1)
+ perror("WARNING: interface is ignored");
+ }
+ firsthop.sin6_port = htons(1025);
+ if (connect(probe_fd, (struct sockaddr*)&firsthop, sizeof(firsthop)) == -1) {
+ perror("connect");
+ return;
+ }
+ alen = sizeof(saddr);
+ if (getsockname(probe_fd, (struct sockaddr*)&saddr, &alen) ==
-1) {
+ perror("getsockname");
+ return;
+ }
+ saddr.sin6_port = 0;
+ close(probe_fd);
+ } else {
+ (void) bzero((char *)&saddr, sizeof(saddr));
+ saddr.sin6_family = AF_INET6;
+ if (inet_pton(AF_INET6, source6, &saddr.sin6_addr) < 0)
+ {
+ Printf("traceroute: unknown addr %s\n", source6);
+ return;
+ }
+ }
+
+ if (bind(sndsock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
+ perror ("traceroute: bind sending socket");
+ return;
+ }
+ if (bind(icmp_sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
+ perror ("traceroute: bind icmp6 socket");
+ return;
+ }
+
+ for (ttl = 1; ttl <= max_ttl; ++ttl) {
+ struct in6_addr lastaddr = { { {0,}}};
+ int got_there = 0;
+ int unreachable = 0;
+
+ /* Printf("%2d ", ttl); */
+ for (probe = 0; probe < nprobes6; ++probe) {
+ int cc, reset_timer;
+ struct timeval t1, t2;
+ struct timezone tz;
+
+ gettimeofday(&t1, &tz);
+ send_probe6(++seq, ttl);
+ reset_timer = 1;
+
+ while ((cc = wait_for_reply6(icmp_sock, &from,
reset_timer)) != 0) {
+ gettimeofday(&t2, &tz);
+ if (cc > 0 && (i = packet_ok6(packet, cc, &from,
seq, &t1))) {
+ reset_timer = 1;
+ if (memcmp(&from.sin6_addr,
&lastaddr, sizeof(from.sin6_addr))) {
+ memcpy(IPlist[ttl-1],
+
&from.sin6_addr,
+
sizeof(IPlist[ttl-1]));
+ memcpy(&lastaddr,
+
&from.sin6_addr,
+
sizeof(lastaddr));
+ }
+ if (get_debuglvl() > 4) {
+ char tmp[MAXHOSTNAMELEN];
+ inet_ntop(AF_INET6,
&from.sin6_addr, tmp, sizeof(tmp));
+ log_println(5, "Probe %d resulted
in reply from [%s]", probe, tmp);
+ }
+ switch(i - 1) {
+ case ICMPV6_PORT_UNREACH:
+ ++got_there;
+ break;
+
+ case ICMPV6_NOROUTE:
+ ++unreachable;
+ Printf(" !N");
+ break;
+ case ICMPV6_ADDR_UNREACH:
+ ++unreachable;
+ Printf(" !H");
+ break;
+
+ case ICMPV6_ADM_PROHIBITED:
+ ++unreachable;
+ Printf(" !S");
+ break;
+ }
+ break;
+ } else
+ reset_timer = 0;
+ }
+ if (cc <= 0)
+ Printf(" *");
+ (void) fflush(stdout);
+ }
+ if (got_there || (unreachable > 0 && unreachable >=
nprobes6-1))
+ return;
+ }
}

int
wait_for_reply6(sock, from, reset_timer)
- int sock;
- struct sockaddr_in6 *from;
- int reset_timer;
-{
- fd_set fds;
- static struct timeval wait;
- int cc = 0;
- socklen_t fromlen = sizeof (*from);
-
- FD_ZERO(&fds);
- FD_SET(sock, &fds);
- if (reset_timer) {
- /*
- * traceroute could hang if someone else has a ping
- * running and our ICMP reply gets dropped but we don't
- * realize it because we keep waking up to handle those
- * other ICMP packets that keep coming in. To fix this,
- * "reset_timer" will only be true if the last packet that
- * came in was for us or if this is the first time we're
- * waiting for a reply since sending out a probe. Note
- * that this takes advantage of the select() feature on
- * Linux where the remaining timeout is written to the
- * struct timeval area.
- */
- wait.tv_sec = waittime6;
- wait.tv_usec = 0;
- }
-
- if (select(sock+1, &fds, (fd_set *)0, (fd_set *)0, &wait) > 0) {
- cc=recvfrom(icmp_sock, (char *)packet, sizeof(packet), 0,
- (struct sockaddr *)from, &fromlen);
- }
-
- return(cc);
-}
-
+int sock;
+struct sockaddr_in6 *from;
+int reset_timer;
+{
+ fd_set fds;
+ static struct timeval wait;
+ int cc = 0;
+ socklen_t fromlen = sizeof (*from);
+
+ FD_ZERO(&fds);
+ FD_SET(sock, &fds);
+ if (reset_timer) {
+ /*
+ * traceroute could hang if someone else has a ping
+ * running and our ICMP reply gets dropped but we don't
+ * realize it because we keep waking up to handle those
+ * other ICMP packets that keep coming in. To fix this,
+ * "reset_timer" will only be true if the last packet that
+ * came in was for us or if this is the first time we're
+ * waiting for a reply since sending out a probe. Note
+ * that this takes advantage of the select() feature on
+ * Linux where the remaining timeout is written to the
+ * struct timeval area.
+ */
+ wait.tv_sec = waittime6;
+ wait.tv_usec = 0;
+ }
+
+ if (select(sock+1, &fds, (fd_set *)0, (fd_set *)0, &wait) > 0) {
+ cc=recvfrom(icmp_sock, (char *)packet, sizeof(packet), 0,
+ (struct sockaddr *)from, &fromlen);
+ }
+
+ return(cc);
+}

void send_probe6(int seq, int ttl)
{
- struct pkt_format *pkt = (struct pkt_format *) sendbuff;
- int i;
-
- pkt->ident = htonl(ident);
- pkt->seq = htonl(seq);
- gettimeofday(&pkt->tv, &tz);
-
- i = setsockopt(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl));
- if (i < 0)
- {
- perror("setsockopt");
- return;
- }
-
- do {
- i = sendto(sndsock, sendbuff, datalen, 0,
- (struct sockaddr *)&whereto, sizeof(whereto));
- } while (i<0 && errno == ECONNREFUSED);
-
- if (i < 0 || i != datalen) {
- if (i<0)
- perror("sendto");
- }
+ struct pkt_format *pkt = (struct pkt_format *) sendbuff;
+ int i;
+
+ pkt->ident = htonl(ident);
+ pkt->seq = htonl(seq);
+ gettimeofday(&pkt->tv, &tz);
+
+ i = setsockopt(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, &ttl,
sizeof(ttl));
+ if (i < 0)
+ {
+ perror("setsockopt");
+ return;
+ }
+
+ do {
+ i = sendto(sndsock, sendbuff, datalen, 0,
+ (struct sockaddr *)&whereto, sizeof(whereto));
+ }while (i<0 && errno == ECONNREFUSED);
+
+ if (i < 0 || i != datalen) {
+ if (i<0)
+ perror("sendto");
+ }
}

/*
@@ -628,99 +623,98 @@
*/
char * pr_type(unsigned char t)
{
- static char *ttab1[] = {
- "Error",
- "Destination Unreachable",
- "Packet Too Big",
- "Time Exceeded in Transit",
- "Parameter Problem"
- };
-
- static char *ttab2[] = {
- "Echo Reply",
- "Echo Request",
- "Membership Query",
- "Membership Report",
- "Membership Reduction",
- };
-
- if (t < 5)
- {
- return (ttab1[t]);
- }
-
- if (t >= 128 && t <= 131)
- {
- return (ttab2[t]);
- }
-
- return("OUT-OF-RANGE");
-}
-
+ static char *ttab1[] = {
+ "Error",
+ "Destination Unreachable",
+ "Packet Too Big",
+ "Time Exceeded in Transit",
+ "Parameter Problem"
+ };
+
+ static char *ttab2[] = {
+ "Echo Reply",
+ "Echo Request",
+ "Membership Query",
+ "Membership Report",
+ "Membership Reduction",
+ };
+
+ if (t < 5)
+ {
+ return (ttab1[t]);
+ }
+
+ if (t >= 128 && t <= 131)
+ {
+ return (ttab2[t]);
+ }
+
+ return("OUT-OF-RANGE");
+}

int packet_ok6(u_char *buf, int cc, struct sockaddr_in6 *from, int seq,
- struct timeval *tv)
-{
- struct icmp6hdr *icp;
- u_char type, code;
-
- icp = (struct icmp6hdr *) buf;
-
- type = icp->icmp6_type;
- code = icp->icmp6_code;
-
- if ((type == ICMPV6_TIME_EXCEED && code == ICMPV6_EXC_HOPLIMIT) ||
- type == ICMPV6_DEST_UNREACH)
- {
- struct ipv6hdr *hip;
- struct udphdr *up;
- int nexthdr;
-
- hip = (struct ipv6hdr *) (icp + 1);
- up = (struct udphdr *)(hip+1);
- nexthdr = hip->nexthdr;
-
- if (nexthdr == 44) {
- nexthdr = *(unsigned char*)up;
- up++;
- }
- if (nexthdr == IPPROTO_UDP)
- {
- struct pkt_format *pkt;
-
- pkt = (struct pkt_format *) (up + 1);
-
- if (ntohl(pkt->ident) == ident &&
- ntohl(pkt->seq) == seq)
- {
- *tv = pkt->tv;
- return (type == ICMPV6_TIME_EXCEED? -1 : code+1);
- }
- }
-
- }
-
- if (verbose) {
- struct ipv6hdr *hip;
- __u32 *lp;
- char pa1[MAXHOSTNAMELEN];
- char pa2[MAXHOSTNAMELEN];
- int i;
- hip = (struct ipv6hdr *) (icp + 1);
- lp = (__u32 *) (icp + 1);
-
- Printf("\n%d bytes from %s to %s", cc,
- inet_ntop(AF_INET6, &hip->saddr, pa1, sizeof(pa1)),
- inet_ntop(AF_INET6, &hip->daddr, pa2, sizeof(pa2)));
-
- Printf(": icmp type %d (%s) code %d\n", type, pr_type(type),
- icp->icmp6_code);
-
- for (i = sizeof(struct ipv6hdr); i < cc ; i += 4)
- Printf("%2d: x%8.8x\n", i, *lp++);
- }
-
- return(0);
+ struct timeval *tv)
+{
+ struct icmp6hdr *icp;
+ u_char type, code;
+
+ icp = (struct icmp6hdr *) buf;
+
+ type = icp->icmp6_type;
+ code = icp->icmp6_code;
+
+ if ((type == ICMPV6_TIME_EXCEED && code == ICMPV6_EXC_HOPLIMIT) ||
+ type == ICMPV6_DEST_UNREACH)
+ {
+ struct ipv6hdr *hip;
+ struct udphdr *up;
+ int nexthdr;
+
+ hip = (struct ipv6hdr *) (icp + 1);
+ up = (struct udphdr *)(hip+1);
+ nexthdr = hip->nexthdr;
+
+ if (nexthdr == 44) {
+ nexthdr = *(unsigned char*)up;
+ up++;
+ }
+ if (nexthdr == IPPROTO_UDP)
+ {
+ struct pkt_format *pkt;
+
+ pkt = (struct pkt_format *) (up + 1);
+
+ if (ntohl(pkt->ident) == ident &&
+ ntohl(pkt->seq) == seq)
+ {
+ *tv = pkt->tv;
+ return (type == ICMPV6_TIME_EXCEED? -1 :
code+1);
+ }
+ }
+
+ }
+
+ if (verbose) {
+ struct ipv6hdr *hip;
+ __u32 *lp;
+ char pa1[MAXHOSTNAMELEN];
+ char pa2[MAXHOSTNAMELEN];
+ int i;
+ hip = (struct ipv6hdr *) (icp + 1);
+ lp = (__u32 *) (icp + 1);
+
+ Printf("\n%d bytes from %s to %s", cc,
+ inet_ntop(AF_INET6, &hip->saddr, pa1,
sizeof(pa1)),
+ inet_ntop(AF_INET6, &hip->daddr, pa2,
sizeof(pa2)));
+
+ Printf(": icmp type %d (%s) code %d\n", type, pr_type(type),
+ icp->icmp6_code);
+
+ for (i = sizeof(struct ipv6hdr); i < cc; i += 4)
+ Printf("%2d: x%8.8x\n", i, *lp++);
+ }
+
+ return(0);
}

#endif
=======================================
--- /branches/kkumar_code_organize/src/usage.c Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/usage.c Mon Oct 17 06:43:25 2011
@@ -18,15 +18,13 @@
* @param info Text printed in the first line
*/

-void
-short_usage(char* prog, char* info)
-{
- assert(prog != NULL);
- assert(info != NULL);
- printf("\n%s\n\n\n", info);
- printf("Try `%s --help' for more information.\n", prog);
-
- exit(1);
+void short_usage(char* prog, char* info) {
+ assert(prog != NULL);
+ assert(info != NULL);
+ printf("\n%s\n\n\n", info);
+ printf("Try `%s --help' for more information.\n", prog);
+
+ exit(1);
}

/*
@@ -35,71 +33,91 @@
* Arguments: info - the text printed in the first line
*/

-void
-srv_long_usage(char* info)
-{
- assert(info != NULL);
- printf("\n%s\n\n\n", info);
- printf(" Basic options:\n\n");
- printf(" -a, --adminview - generate administrator view html page\n");
- printf(" -d, --debug - print additional diagnostic messages\n");
- printf(" Note: add multiple d's (-ddd) for more details\n");
- printf(" -h, --help - print help message (this message)\n");
- printf(" -m, --multiple - select single or multi-test mode\n");
- printf(" -o, --old - use old Duplex Mismatch heuristic\n");
- printf(" -q, --disable-queue - disable FIFO queuing of client requests\n");
- printf(" -r, --record - record client to server Web100 variables\n");
- printf(" -s, --syslog - use the syslog() to log some information\n");
- printf(" -t, --tcpdump - write tcpdump formatted file to disk\n");
- printf(" -v, --version - print version number\n");
- printf(" -x, --max_clients - maximum numbers of clients permited in FIFO queue (default=50)\n");
- printf(" -z, --gzip - disable compression of tcptrace, snaplog, and cputime files\n\n");
- printf(" Configuration:\n\n");
- printf(" -c, --config #filename - specify the name of the file with configuration\n");
- printf(" -b, --buffer #size - set TCP send/recv buffers to user value\n");
- printf(" -f, --file variable_FN - specify alternate 'web100_variables' file\n");
- printf(" -i, --interface device - specify network interface (libpcap device)\n");
- printf(" -l, --log Log_FN - specify alternate 'web100srv.log' file\n");
- printf(" -u, --protolog_dir DIR - specify the base directory for protocol validation logs \n");
- printf(" --enableprotolog - enable protocol logging \n");
- printf(" -p, --port #port - specify primary port number (default 3001)\n");
- printf(" --midport #port - specify Middlebox test port number (default 3003)\n");
- printf(" --c2sport #port - specify C2S throughput test port number (default 3002)\n");
- printf(" --s2cport #port - specify S2C throughput test port number (default 3003)\n");
- printf(" -T, --refresh #time - specify the refresh time of the admin page\n");
- printf(" --mrange #range - set the port range used in multi-test mode\n");
- printf(" Note: this enables multi-test mode\n");
- printf(" -A, --adminfile #FN - specify alternate filename for Admin web page\n");
- printf(" Note: this doesn't enable 'adminview'\n");
- printf(" -L, --log_dir DIR - specify the base directory for snaplog and tcpdump files\n");
- printf(" (default %s/serverdata)\n", BASEDIR);
- printf(" -S, --logfacility #F - specify syslog facility name\n");
- printf(" Note: this doesn't enable 'syslog'\n\n");
+void srv_long_usage(char* info) {
+ assert(info != NULL);
+ printf("\n%s\n\n\n", info);
+ printf(" Basic options:\n\n");
+ printf(
+ " -a, --adminview - generate administrator view
html page\n");
+ printf(" -d, --debug - print additional diagnostic messages\n");
+ printf(
+ " Note: add multiple d's (-ddd) for more details\n");
+ printf(" -h, --help - print help message (this
message)\n");
+ printf(" -m, --multiple - select single or multi-test
mode\n");
+ printf(" -o, --old - use old Duplex Mismatch
heuristic\n");
+ printf(
+ " -q, --disable-queue - disable FIFO queuing of client
requests\n");
+ printf(
+ " -r, --record - record client to server Web100 variables\n");
+ printf(
+ " -s, --syslog - use the syslog() to log some information\n");
+ printf(" -t, --tcpdump - write tcpdump formatted file to disk\n");
+ printf(" -v, --version - print version number\n");
+ printf(
+ " -x, --max_clients - maximum numbers of clients permited in FIFO queue (default=50)\n");
+ printf(
+ " -z, --gzip - disable compression of tcptrace, snaplog, and cputime files\n\n");
+ printf(" Configuration:\n\n");
+ printf(
+ " -c, --config #filename - specify the name of the file with configuration\n");
+ printf(
+ " -b, --buffer #size - set TCP send/recv buffers to
user value\n");
+ printf(
+ " -f, --file variable_FN - specify alternate 'web100_variables' file\n");
+ printf(
+ " -i, --interface device - specify network interface (libpcap device)\n");
+ printf(
+ " -l, --log Log_FN - specify alternate
'web100srv.log' file\n");
+ printf(
+ " -u, --protolog_dir DIR - specify the base directory for protocol validation logs \n");
+ printf(" --enableprotolog - enable protocol logging \n");
+ printf(
+ " -p, --port #port - specify primary port number (default 3001)\n");
+ printf(
+ " --midport #port - specify Middlebox test port number (default 3003)\n");
+ printf(
+ " --c2sport #port - specify C2S throughput test port number (default 3002)\n");
+ printf(
+ " --s2cport #port - specify S2C throughput test port number (default 3003)\n");
+ printf(
+ " -T, --refresh #time - specify the refresh time of the admin page\n");
+ printf(
+ " --mrange #range - set the port range used in multi-test mode\n");
+ printf(" Note: this enables multi-test
mode\n");
+ printf(
+ " -A, --adminfile #FN - specify alternate filename for Admin web page\n");
+ printf(
+ " Note: this doesn't enable
'adminview'\n");
+ printf(
+ " -L, --log_dir DIR - specify the base directory for snaplog and tcpdump files\n");
+ printf(" (default %s/serverdata)\n",
BASEDIR);
+ printf(" -S, --logfacility #F - specify syslog facility name\n");
+ printf(" Note: this doesn't enable 'syslog'\n\n");
#ifdef EXPERIMENTAL_ENABLED
- printf(" Experimental code:\n\n");
- printf(" --avoidsndblockup - enable code to avoid send buffers blocking in the S2C test\n");
- printf(" --snaplog - enable the snaplog writing\n");
- printf(" --snapdelay #msec - specify the delay in the snaplog thread (default 5 msec)\n");
- printf(" Note: this doesn't enable 'snaplog'\n");
- printf(" --cwnddecrease - enable analyzing of the cwnd changes during the S2C test\n");
- printf(" Note: this automatically enables 'snaplog'\n");
- printf(" --cputime - enable the cputime writing\n");
- printf(" -y, --limit #limit - enable the throughput limiting code\n\n");
+ printf(" Experimental code:\n\n");
+ printf(" --avoidsndblockup - enable code to avoid send buffers blocking in the S2C test\n");
+ printf(" --snaplog - enable the snaplog writing\n");
+ printf(" --snapdelay #msec - specify the delay in the snaplog thread (default 5 msec)\n");
+ printf(" Note: this doesn't enable 'snaplog'\n");
+ printf(" --cwnddecrease - enable analyzing of the cwnd changes during the S2C test\n");
+ printf(" Note: this automatically enables 'snaplog'\n");
+ printf(" --cputime - enable the cputime writing\n");
+ printf(" -y, --limit #limit - enable the throughput limiting code\n\n");
#endif
#if defined(HAVE_ODBC) && defined(DATABASE_ENABLED) && defined(HAVE_SQL_H)
- printf(" Database support:\n\n");
- printf(" --enableDBlogging - enable the test results logging to the database\n");
- printf(" --dbDSN #dsn - specify the DSN to use (this doesn't enable DBlogging)\n");
- printf(" --dbUID #uid - specify the UID to use (this doesn't enable DBlogging)\n");
- printf(" --dbPWD #pwd - specify the PWD to use (this doesn't enable DBlogging)\n\n");
+ printf(" Database support:\n\n");
+ printf(" --enableDBlogging - enable the test results logging to the database\n");
+ printf(" --dbDSN #dsn - specify the DSN to use (this doesn't enable DBlogging)\n");
+ printf(" --dbUID #uid - specify the UID to use (this doesn't enable DBlogging)\n");
+ printf(" --dbPWD #pwd - specify the PWD to use (this doesn't enable DBlogging)\n\n");
#endif
#ifdef AF_INET6
- printf(" IP family:\n\n");
- printf(" -4, --ipv4 - use IPv4 addresses only\n");
- printf(" -6, --ipv6 - use IPv6 addresses only\n\n");
+ printf(" IP family:\n\n");
+ printf(" -4, --ipv4 - use IPv4 addresses only\n");
+ printf(" -6, --ipv6 - use IPv6 addresses only\n\n");
#endif

- exit(0);
+ exit(0);
}

/*
@@ -108,33 +126,33 @@
* Arguments: info - the text printed in the first line
*/

-void
-clt_long_usage(char* info)
-{
- assert(info != NULL);
- printf("\n%s\n\n\n", info);
- printf(" Basic options:\n\n");
- printf(" -n, --name #name - specify name of the server\n");
- printf(" -p, --port #port - specify port server is listening on\n");
- printf(" -d, --debug - Increase debug level details\n");
- printf(" Note: add multiple d's (-ddd) for more details\n");
- printf(" -h, --help - print this help message\n");
- printf(" -l, --msglvl - increase message level details\n");
- printf(" --web100variables - print the information about each Web100 variable\n");
- printf(" -v, --version - print version number\n\n");
- printf(" Configuration:\n\n");
- printf(" -b, --buffer #size - set send/receive buffer to value\n");
- printf(" --disablemid - disable the Middlebox test\n");
- printf(" --disablec2s - disable the C2S throughput test\n");
- printf(" --disables2c - disable the S2C throughput test\n");
- printf(" --disablesfw - disable the Simple firewall test\n\n");
+void clt_long_usage(char* info) {
+ assert(info != NULL);
+ printf("\n%s\n\n\n", info);
+ printf(" Basic options:\n\n");
+ printf(" -n, --name #name - specify name of the server\n");
+ printf(" -p, --port #port - specify port server is listening on\n");
+ printf(" -d, --debug - Increase debug level details\n");
+ printf(
+ " Note: add multiple d's (-ddd) for more details\n");
+ printf(" -h, --help - print this help message\n");
+ printf(" -l, --msglvl - increase message level details\n");
+ printf(
+ " --web100variables - print the information about each Web100 variable\n");
+ printf(" -v, --version - print version number\n\n");
+ printf(" Configuration:\n\n");
+ printf(" -b, --buffer #size - set send/receive buffer to
value\n");
+ printf(" --disablemid - disable the Middlebox test\n");
+ printf(" --disablec2s - disable the C2S throughput
test\n");
+ printf(" --disables2c - disable the S2C throughput
test\n");
+ printf(" --disablesfw - disable the Simple firewall
test\n\n");
#ifdef AF_INET6
- printf(" IP family:\n\n");
- printf(" -4, --ipv4 - use IPv4 addresses only\n");
- printf(" -6, --ipv6 - use IPv6 addresses only\n\n");
+ printf(" IP family:\n\n");
+ printf(" -4, --ipv4 - use IPv4 addresses only\n");
+ printf(" -6, --ipv6 - use IPv6 addresses only\n\n");
#endif

- exit(0);
+ exit(0);
}

/*
@@ -143,38 +161,41 @@
* Arguments: info - the text printed in the first line
*/

-void
-www_long_usage(char* info)
-{
- assert(info != NULL);
- printf("\n%s\n\n\n", info);
- printf(" Basic options:\n\n");
- printf(" -d, --debug - increment debugging mode\n");
- printf(" Note: add multiple d's (-ddd) for more details\n");
- printf(" -h, --help - print this help message\n");
- printf(" -F, --federated - operate in Federated mode\n");
- printf(" -f, --file FN - add the file to the allowed list\n");
- printf(" -s, --syslog - use the syslog() to log some information\n");
- printf(" -v, --version - print version number\n\n");
- printf(" Configuration:\n\n");
- printf(" -l, --alog alog_FN - specify the access log filename\n");
- printf(" -e, --elog elog_FN - specify the error log filename\n");
- printf(" -b, --basedir path - set the basedir for the documents\n");
- printf(" -S, --logfacility #F - specify syslog facility name\n");
- printf(" Note: this doesn't enable 'syslog'\n");
- printf(" -p, --port #port - specify the port number (default is 7123)\n");
- printf(" -t, --ttl #amount - specify maximum number of hops in path (default is 10)\n");
- printf(" --dflttree fn - specify alternate 'Default.tree' file\n");
+void www_long_usage(char* info) {
+ assert(info != NULL);
+ printf("\n%s\n\n\n", info);
+ printf(" Basic options:\n\n");
+ printf(" -d, --debug - increment debugging mode\n");
+ printf(
+ " Note: add multiple d's (-ddd) for more details\n");
+ printf(" -h, --help - print this help message\n");
+ printf(" -F, --federated - operate in Federated mode\n");
+ printf(" -f, --file FN - add the file to the allowed
list\n");
+ printf(
+ " -s, --syslog - use the syslog() to log some information\n");
+ printf(" -v, --version - print version number\n\n");
+ printf(" Configuration:\n\n");
+ printf(" -l, --alog alog_FN - specify the access log
filename\n");
+ printf(" -e, --elog elog_FN - specify the error log filename\n");
+ printf(" -b, --basedir path - set the basedir for the
documents\n");
+ printf(" -S, --logfacility #F - specify syslog facility name\n");
+ printf(" Note: this doesn't enable
'syslog'\n");
+ printf(
+ " -p, --port #port - specify the port number (default is 7123)\n");
+ printf(
+ " -t, --ttl #amount - specify maximum number of hops in path (default is 10)\n");
+ printf(
+ " --dflttree fn - specify alternate
'Default.tree' file\n");
#ifdef AF_INET6
- printf(" --dflttree6 fn - specify alternate 'Default.tree6' file\n\n");
- printf(" IP family:\n\n");
- printf(" -4, --ipv4 - use IPv4 addresses only\n");
- printf(" -6, --ipv6 - use IPv6 addresses only\n\n");
+ printf(" --dflttree6 fn - specify alternate 'Default.tree6' file\n\n");
+ printf(" IP family:\n\n");
+ printf(" -4, --ipv4 - use IPv4 addresses only\n");
+ printf(" -6, --ipv6 - use IPv6 addresses only\n\n");
#else
- printf("\n");
+ printf("\n");
#endif

- exit(0);
+ exit(0);
}

/*
@@ -183,20 +204,19 @@
* Arguments: info - the text printed in the first line
*/

-void
-analyze_long_usage(char* info)
-{
- assert(info != NULL);
- printf("\n%s\n\n\n", info);
- printf(" Basic options:\n\n");
- printf(" -d, --debug - increment debugging mode\n");
- printf(" Note: add multiple d's (-ddd) for more details\n");
- printf(" -n, --nodns - disable resolving DNS names\n");
- printf(" -h, --help - print this help message\n");
- printf(" -l, --log log_FN - specify the file with the logs\n");
- printf(" -v, --version - print version number\n\n");
-
- exit(0);
+void analyze_long_usage(char* info) {
+ assert(info != NULL);
+ printf("\n%s\n\n\n", info);
+ printf(" Basic options:\n\n");
+ printf(" -d, --debug - increment debugging mode\n");
+ printf(
+ " Note: add multiple d's (-ddd) for more details\n");
+ printf(" -n, --nodns - disable resolving DNS names\n");
+ printf(" -h, --help - print this help message\n");
+ printf(" -l, --log log_FN - specify the file with the logs\n");
+ printf(" -v, --version - print version number\n\n");
+
+ exit(0);
}

/*
@@ -205,33 +225,35 @@
* Arguments: info - the text printed in the first line
*/

-void
-mkmap_long_usage(char* info)
-{
- assert(info != NULL);
- printf("\n%s\n\n\n", info);
- printf(" Basic options:\n\n");
- printf(" -b, --build - build a new default tree\n");
- printf(" -c, --compare fn - compare new traceroute to tree\n");
- printf(" Note: -b and -c are mutually exclusive\n");
- printf(" -f, --file fn - specify the name of the input file\n");
- printf(" -h, --help - print this help message\n");
- printf(" -p, --print - [default] print out the current traceroute map\n");
- printf(" -d, --debug - increment debugging mode\n");
- printf(" Note: add multiple d's (-ddd) for more details\n");
- printf(" -v, --version - print version number\n\n");
- printf(" Configuration:\n\n");
- printf(" --dflttree fn - specify alternate 'Default.tree' file\n");
+void mkmap_long_usage(char* info) {
+ assert(info != NULL);
+ printf("\n%s\n\n\n", info);
+ printf(" Basic options:\n\n");
+ printf(" -b, --build - build a new default tree\n");
+ printf(" -c, --compare fn - compare new traceroute to tree\n");
+ printf(
+ " Note: -b and -c are mutually
exclusive\n");
+ printf(" -f, --file fn - specify the name of the input
file\n");
+ printf(" -h, --help - print this help message\n");
+ printf(
+ " -p, --print - [default] print out the current traceroute map\n");
+ printf(" -d, --debug - increment debugging mode\n");
+ printf(
+ " Note: add multiple d's (-ddd) for more details\n");
+ printf(" -v, --version - print version number\n\n");
+ printf(" Configuration:\n\n");
+ printf(
+ " --dflttree fn - specify alternate
'Default.tree' file\n");
#ifdef AF_INET6
- printf(" --dflttree6 fn - specify alternate 'Default.tree6' file\n\n");
- printf(" IP family:\n\n");
- printf(" -4, --ipv4 - use only IPv4 operational mode\n");
- printf(" -6, --ipv6 - use only IPv6 operational mode\n\n");
+ printf(" --dflttree6 fn - specify alternate 'Default.tree6' file\n\n");
+ printf(" IP family:\n\n");
+ printf(" -4, --ipv4 - use only IPv4 operational mode\n");
+ printf(" -6, --ipv6 - use only IPv6 operational
mode\n\n");
#else
- printf("\n");
+ printf("\n");
#endif

- exit(0);
+ exit(0);
}

/*
@@ -240,23 +262,27 @@
* Arguments: info - the text printed in the first line
*/

-void
-vt_long_usage(char* info)
-{
- assert(info != NULL);
- printf("\n%s\n\n\n", info);
- printf(" Basic options:\n\n");
- printf(" -c, --count #amount - specify how many packets will be viewed\n");
- printf(" -d, --debug - increment debugging mode\n");
- printf(" Note: add multiple d's (-ddd) for more details\n");
- printf(" -f, --file fn - specify the name of the file to offline trace\n");
- printf(" -h, --help - print this help message\n");
- printf(" -i, --interface device - specify network interface (libpcap device)\n");
- printf(" --c2sport #port - specify C2S throughput test port number (default 3002)\n");
- printf(" --s2cport #port - specify S2C throughput test port number (default 3003)\n");
- printf(" -v, --version - print version number\n\n");
-
- exit(0);
+void vt_long_usage(char* info) {
+ assert(info != NULL);
+ printf("\n%s\n\n\n", info);
+ printf(" Basic options:\n\n");
+ printf(
+ " -c, --count #amount - specify how many packets will
be viewed\n");
+ printf(" -d, --debug - increment debugging mode\n");
+ printf(
+ " Note: add multiple d's (-ddd) for more details\n");
+ printf(
+ " -f, --file fn - specify the name of the file to offline trace\n");
+ printf(" -h, --help - print this help message\n");
+ printf(
+ " -i, --interface device - specify network interface (libpcap device)\n");
+ printf(
+ " --c2sport #port - specify C2S throughput test port number (default 3002)\n");
+ printf(
+ " --s2cport #port - specify S2C throughput test port number (default 3003)\n");
+ printf(" -v, --version - print version number\n\n");
+
+ exit(0);
}

/*
@@ -265,23 +291,24 @@
* Arguments: info - the text printed in the first line
*/

-void
-genplot_long_usage(char* info, char* argv0)
-{
- assert(info != NULL);
- printf("\n%s\n\n\n", info);
- printf("Usage: %s [options] filelist\n", argv0);
- printf("This program generates xplot graphs from Web100 variables\n\n");
- printf(" Basic options:\n\n");
- printf(" -b, --both - generate plot of both CurCwnd and CurRwinRcvd\n");
- printf(" -m, --multi varlist - a comma separated list of Web100 vars to plot\n");
- printf(" -t, --text - print variable values instead of generating plots\n");
- printf(" -C, --CurCwnd - generate CurCwnd plot\n");
- printf(" -R, --CurRwinRcvd - generate CurRwinRcvd plot\n");
- printf(" -S, --throughput - generate throughput plot\n");
- printf(" -c, --cwndtime - generate Cwnd time plot\n");
- printf(" -h, --help - print this help message\n");
- printf(" -v, --version - print version number\n\n");
-
- exit(0);
-}
+void genplot_long_usage(char* info, char* argv0) {
+ assert(info != NULL);
+ printf("\n%s\n\n\n", info);
+ printf("Usage: %s [options] filelist\n", argv0);
+ printf("This program generates xplot graphs from Web100
variables\n\n");
+ printf(" Basic options:\n\n");
+ printf(
+ " -b, --both - generate plot of both CurCwnd and CurRwinRcvd\n");
+ printf(
+ " -m, --multi varlist - a comma separated list of Web100 vars to plot\n");
+ printf(
+ " -t, --text - print variable values instead of generating plots\n");
+ printf(" -C, --CurCwnd - generate CurCwnd plot\n");
+ printf(" -R, --CurRwinRcvd - generate CurRwinRcvd plot\n");
+ printf(" -S, --throughput - generate throughput plot\n");
+ printf(" -c, --cwndtime - generate Cwnd time plot\n");
+ printf(" -h, --help - print this help message\n");
+ printf(" -v, --version - print version number\n\n");
+
+ exit(0);
+}
=======================================
--- /branches/kkumar_code_organize/src/utils.c Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/utils.c Mon Oct 17 06:43:25 2011
@@ -32,25 +32,22 @@
* 2 - not the valid int number.
*/

-int
-check_int(char* text, int* number)
-{
- char* znak;
- long tmp;
-
- assert(text != NULL);
- assert(number != NULL);
-
- if (((tmp = strtol(text, &znak, 10)) >= INT_MAX) || (tmp <= INT_MIN)) {
- return 1;
- }
- if ((*text != '\0') && (*znak == '\0')) {
- *number = tmp;
- return 0;
- }
- else {
- return 2;
- }
+int check_int(char* text, int* number) {
+ char* znak;
+ long tmp;
+
+ assert(text != NULL);
+ assert(number != NULL);
+
+ if (((tmp = strtol(text, &znak, 10)) >= INT_MAX) || (tmp <= INT_MIN))
{
+ return 1;
+ }
+ if ((*text != '\0') && (*znak == '\0')) {
+ *number = tmp;
+ return 0;
+ } else {
+ return 2;
+ }
}

/**
@@ -65,20 +62,18 @@
* 2 - not the valid int number.
*/

-int
-check_rint(char* text, int* number, int minVal, int maxVal)
-{
- int ret;
-
- assert(maxVal >= minVal);
-
- if ((ret = check_int(text, number))) {
- return ret;
- }
- if ((*number < minVal) || (*number > maxVal)) {
- return 1;
- }
- return 0;
+int check_rint(char* text, int* number, int minVal, int maxVal) {
+ int ret;
+
+ assert(maxVal >= minVal);
+
+ if ((ret = check_int(text, number))) {
+ return ret;
+ }
+ if ((*number < minVal) || (*number > maxVal)) {
+ return 1;
+ }
+ return 0;
}

/**
@@ -90,23 +85,21 @@
* 2 - not the valid long number.
*/

-int
-check_long(char* text, long* number)
-{
- char* tmp;
-
- assert(text != NULL);
- assert(number != NULL);
-
- if (((*number = strtol(text, &tmp, 10)) == LONG_MAX) || (*number == LONG_MIN)) {
- return 1;
- }
- if ((*text != '\0') && (*tmp == '\0')) {
- return 0;
- }
- else {
- return 2;
- }
+int check_long(char* text, long* number) {
+ char* tmp;
+
+ assert(text != NULL);
+ assert(number != NULL);
+
+ if (((*number = strtol(text, &tmp, 10)) == LONG_MAX)
+ || (*number == LONG_MIN)) {
+ return 1;
+ }
+ if ((*text != '\0') && (*tmp == '\0')) {
+ return 0;
+ } else {
+ return 2;
+ }
}

/**
@@ -114,12 +107,10 @@
* @return seconds from the beginning of the epoch.
*/

-double
-secs()
-{
- struct timeval ru;
- gettimeofday(&ru, (struct timezone *)0);
- return(ru.tv_sec + ((double)ru.tv_usec)/1000000);
+double secs() {
+ struct timeval ru;
+ gettimeofday(&ru, (struct timezone *) 0);
+ return (ru.tv_sec + ((double) ru.tv_usec) / 1000000);
}

/**
@@ -127,11 +118,9 @@
* @param s the argument to the perror() function
*/

-void
-err_sys(char* s)
-{
- perror(s);
- return -1;
+void err_sys(char* s) {
+ perror(s);
+ return -1;
}

/**
@@ -141,18 +130,16 @@
* @return length of the sending queue.
*/

-int
-sndq_len(int fd)
-{
+int sndq_len(int fd) {
#ifdef SIOCOUTQ
- int length = -1;
-
- if (ioctl(fd, SIOCOUTQ, &length)) {
- return -1;
- }
- return length;
+ int length = -1;
+
+ if (ioctl(fd, SIOCOUTQ, &length)) {
+ return -1;
+ }
+ return length;
#else
- return 0;
+ return 0;
#endif
}

@@ -161,19 +148,17 @@
* @arg time in seconds to sleep for
*/

-void
-mysleep(double time)
-{
- int rc;
- struct timeval tv;
- tv.tv_sec = (int) time;
- tv.tv_usec = (int)(time * 1000000)%1000000;
-
- for (;;) {
- rc = select(0, NULL, NULL, NULL, &tv);
- if ((rc == -1) && (errno == EINTR))
- continue;
- if (rc == 0)
- return;
- }
-}
+void mysleep(double time) {
+ int rc;
+ struct timeval tv;
+ tv.tv_sec = (int) time;
+ tv.tv_usec = (int) (time * 1000000) % 1000000;
+
+ for (;;) {
+ rc = select(0, NULL, NULL, NULL, &tv);
+ if ((rc == -1) && (errno == EINTR))
+ continue;
+ if (rc == 0)
+ return;
+ }
+}
=======================================
--- /branches/kkumar_code_organize/src/utils.h Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/utils.h Mon Oct 17 06:43:25 2011
@@ -68,4 +68,3 @@
// MAX TCP window size in bytes
#define MAX_TCP_WIN_BYTES 64

-
=======================================
--- /branches/kkumar_code_organize/src/varinfo.h Fri Aug 18 03:16:24
2006
+++ /branches/kkumar_code_organize/src/varinfo.h Mon Oct 17 06:43:25
2011
@@ -9,155 +9,251 @@
#ifndef _JS_VARINFO_H
#define _JS_VARINFO_H

-char* web100vartable[][2] = {
- {"CurMSS", "The current maximum segment size (MSS), in octets.\n"},
- {"X_Rcvbuf", "The socket receive buffer size in octets. Note that the\n"
- "meaning of this variable is implementation dependent. In\n"
- "particular, it may or may not include the reassembly queue.\n"},
- {"X_Sndbuf", "The socket send buffer size in octets. Note that the\n"
- "meaning of this variable is implementation dependent.\n"
- "Particularly, it may or may not include the retransmit\n"
- "queue.\n"},
- {"AckPktsIn", "The number of valid pure ack packets that have been\n"
- "received on this connection by the Local Host.\n"},
- {"AckPktsOut", "The number of pure ack packets that have been sent\n"
- "on this connection by the Local Host.\n"},
- {"BytesRetrans", "The number of octets retransmitted.\n"},
- {"CongAvoid", "The number of times the congestion window has been\n"
- "increased by the Congestion Avoidance algorithm.\n"},
- {"CongestionOverCount", "The number of congestion events which were 'backed out' of\n"
- "the congestion control state machine such that the\n"
- "congestion window was restored to a prior value. This can\n"
- "happen due to the Eifel algorithm [RFC3522] or other\n"
- "algorithms which can be used to detect and cancel spurious\n"
- "invocations of the Fast Retransmit Algorithm.\n"},
- {"CongestionSignals", "The number of multiplicative downward congestion window\n"
- "adjustments due to all forms of congestion signals,\n"
- "including Fast Retransmit, ECN and timeouts. This object\n"
- "summarizes all events that invoke the MD portion of AIMD\n"
- "congestion control, and as such is the best indicator of\n"
- "how cwnd is being affected by congestion.\n"},
- {"CountRTT", "The number of round trip time samples included in\n"
- "tcpEStatsPathSumRTT and tcpEStatsPathHCSumRTT.\n"},
- {"CurCwnd", "The current congestion window, in octets.\n"},
- {"CurRTO", "The current value of the retransmit timer RTO.\n"},
- {"CurRwinRcvd", "The most recent window advertisement received, in octets.\n"},
- {"CurRwinSent", "The most recent window advertisement sent, in octets.\n"},
- {"CurSsthresh", "The current slow start threshold in octets.\n"},
- {"DSACKDups", "The number of duplicate segments reported to the local host\n"
- "by D-SACK blocks.\n"},
- {"DataBytesIn", "The number of octets contained in received data segments,\n"
- "including retransmitted data. Note that this does not\n"
- "include TCP headers.\n"},
- {"DataBytesOut", "The number of octets of data contained in transmitted segments,\n"
- "including retransmitted data. Note that this does not include\n"
- "TCP headers.\n"},
- {"DataPktsIn", "The number of segments received containing a positive length\n"
- "data segment.\n"},
- {"DataPktsOut", "The number of segments sent containing a positive length data\n"
- "segment.\n"},
- {"DupAcksIn", "The number of duplicate ACKs received.\n"},
- {"ECNEnabled", "Enabled(1) if Explicit Congestion Notification (ECN)\n"
- "has been negotiated on,\n"
- "selfDisabled(2) if it is disabled or not implemented\n"
- "on the local host, or\n"
- "peerDisabled(3) if not negotiated by the remote hosts.\n"},
- {"FastRetran", "The number of invocations of the Fast Retransmit algorithm.\n"},
- {"MaxCwnd", "The maximum congestion window used during Slow Start, in octets.\n"},
- {"MaxMSS", "The maximum MSS, in octets.\n"},
- {"MaxRTO", "The maximum value of the retransmit timer RTO.\n"},
- {"MaxRTT", "The maximum sampled round trip time.\n"},
- {"MaxRwinRcvd", "The maximum window advertisement received, in octets.\n"},
- {"MaxRwinSent", "The maximum window advertisement sent, in octets.\n"},
- {"MaxSsthresh", "The maximum slow start threshold, excluding the initial\n"
- "value.\n"},
- {"MinMSS", "The minimum MSS, in octets.\n"},
- {"MinRTO", "The minimum value of the retransmit timer RTO.\n"},
- {"MinRTT", "The minimum sampled round trip time.\n"},
- {"MinRwinRcvd", "The minimum window advertisement received, in octets.\n"},
- {"MinRwinSent", "The minimum window advertisement sent, excluding the initial\n"
- "unscaled window advertised on the SYN, in octets.\n"},
- {"NagleEnabled", "True(1) if the Nagle algorithm is being used, else false(2).\n"},
- {"OtherReductions", "The number of congestion window reductions made as a result\n"
- "of anything other than AIMD congestion control algorithms.\n"
- "Examples of non-multiplicative window reductions include\n"
- "Congestion Window Validation [RFC2861] and experimental\n"
- "algorithms such as Vegas.\n"},
- {"PktsIn", "The total number of segments received.\n"},
- {"PktsOut", "The total number of segments sent.\n"},
- {"PktsRetrans", "The number of segments transmitted containing at least some\n"
- "retransmitted data.\n"},
- {"RcvWinScale", "The value of Rcv.Wind.Scale. Note that\n"
- "RcvWinScale is either zero or the same as WinScaleSent.\n"},
- {"SACKEnabled", "True(1) if SACK has been negotiated on, else false(2).\n"},
- {"SACKsRcvd", "The number of SACK options received.\n"},
- {"SendStall", "The number of interface stalls or other sender local\n"
- "resource limitations that are treated as congestion\n"
- "signals.\n"},
- {"SlowStart", "The number of times the congestion window has been\n"
- "increased by the Slow Start algorithm.\n"},
- {"SampleRTT", "The most recent raw round trip time measurement used in\n"
- "calculation of the RTO.\n"},
- {"SmoothedRTT", "The smoothed round trip time used in calculation of the\n"
- "RTO. See SRTT in [RFC2988].\n"},
- {"SndWinScale", "The value of Snd.Wind.Scale. Note that\n"
- "SndWinScale is either zero or the same as WinScaleRcvd.\n"},
- {"SndLimTimeRwin", "The cumulative time spent in the 'Receiver Limited' state.\n"},
- {"SndLimTimeCwnd", "The cumulative time spent in the 'Congestion Limited' state.\n"},
- {"SndLimTimeSender", "The cumulative time spent in the 'Sender Limited' state.\n"},
- {"SndLimTransRwin", "The number of transitions into the 'Receiver Limited' state\n"
- "from either the 'Congestion Limited' or 'Sender Limited'\n"
- "states. This state is entered whenever TCP transmission\n"
- "stops because the sender has filled the announced receiver\n"
- "window.\n"},
- {"SndLimTransCwnd", "The number of transitions into the 'Congestion Limited'\n"
- "state from either the 'Receiver Limited' or 'Sender\n"
- "Limited' states. This state is entered whenever TCP\n"
- "transmission stops because the sender has reached some\n"
- "limit defined by congestion control (e.g. cwnd) or other\n"
- "algorithms (retransmission timeouts) designed to control\n"
- "network traffic.\n"},
- {"SndLimTransSender", "The number of transitions into the 'Sender Limited' state\n"
- "from either the 'Receiver Limited' or 'Congestion Limited'\n"
- "states. This state is entered whenever TCP transmission\n"
- "stops due to some sender limit such as running out of\n"
- "application data or other resources and the Karn algorithm.\n"
- "When TCP stops sending data for any reason which can not be\n"
- "classified as Receiver Limited or Congestion Limited it\n"
- "MUST be treated as Sender Limited.\n"},
- {"SndLimBytesRwin", "The cumulative bytes sent while in the 'Receiver Limited'\n"
- "state, as determined by the Local Host, when the Local Host is\n"
- "a sender. This state is entered whenever TCP transmission\n"
- "stops due to Receiver not being able to receive data.\n"},
- {"SndLimBytesCwnd", "The cumulative bytes sent while in the 'Congestion Limited'\n"
- "state, as determined by the Local Host, when the Local Host is\n"
- "a sender. This state is entered whenever TCP transmission\n"
- "stops due to congestion.\n"},
- {"SndLimBytesSender", "The cumulative bytes sent while in the 'Sender Limited'\n"
- "state, as determined by the Local Host, when the Local Host is\n"
- "a sender. This state is entered whenever TCP transmission\n"
- "stops because there is no more data in sender's buffer.\n"},
- {"SubsequentTimeouts", "The number of times the retransmit timeout has expired\n"
- "after the RTO has been doubled. See section 5.5 in RFC2988.\n"},
- {"SumRTT", "The sum of all sampled round trip times.\n"},
- {"Timeouts", "The number of times the retransmit timeout has expired when\n"
- "the RTO backoff multiplier is equal to one.\n"},
- {"TimestampsEnabled", "Enabled(1) if TCP timestamps have been negotiated on,\n"
- "selfDisabled(2) if they are disabled or not implemented on\n"
- "the local host, or peerDisabled(3) if not negotiated by the\n"
- "remote hosts.\n"},
- {"WinScaleRcvd", "The value of the received window scale option if one was\n"
- "received; otherwise, a value of -1.\n"},
- {"WinScaleSent", "The value of the transmitted window scale option if one was\n"
- "sent; otherwise, a value of -1.\n"},
- {"DupAcksOut", "The number of duplicate ACKs sent.\n"},
- {"StartTimeUsec", "The value of sysUpTime at the time this listener was\n"
- "established. If the current state was entered prior to\n"
- "the last re-initialization of the local network management\n"
- "subsystem, then this object contains a zero value.\n"},
- {"Duration", "The seconds part of the time elapsed between StartTimeStamp\n"
- "and the most recent protocol event (segment sent or received).\n"},
- {NULL, NULL}
-};
+char* web100vartable[][2] =
+ {
+ { "CurMSS",
+ "The current maximum segment size
(MSS), in octets.\n" },
+ {
+ "X_Rcvbuf",
+ "The socket receive buffer size in
octets. Note that the\n"
+ "meaning of this
variable is implementation dependent. In\n"
+ "particular, it
may or may not include the reassembly queue.\n" },
+ {
+ "X_Sndbuf",
+ "The socket send buffer size in
octets. Note that the\n"
+ "meaning of this
variable is implementation dependent.\n"
+ "Particularly, it
may or may not include the retransmit\n"
+ "queue.\n" },
+ {
+ "AckPktsIn",
+ "The number of valid pure ack
packets that have been\n"
+ "received on this
connection by the Local Host.\n" },
+ { "AckPktsOut",
+ "The number of pure ack packets
that have been sent\n"
+ "on this
connection by the Local Host.\n" },
+ { "BytesRetrans", "The number of octets
retransmitted.\n" },
+ {
+ "CongAvoid",
+ "The number of times the
congestion window has been\n"
+ "increased by the
Congestion Avoidance algorithm.\n" },
+ {
+ "CongestionOverCount",
+ "The number of congestion events
which were 'backed out' of\n"
+ "the congestion
control state machine such that the\n"
+ "congestion window
was restored to a prior value. This can\n"
+ "happen due to the
Eifel algorithm [RFC3522] or other\n"
+ "algorithms which
can be used to detect and cancel spurious\n"
+ "invocations of
the Fast Retransmit Algorithm.\n" },
+ {
+ "CongestionSignals",
+ "The number of multiplicative
downward congestion window\n"
+ "adjustments due
to all forms of congestion signals,\n"
+ "including Fast
Retransmit, ECN and timeouts. This object\n"
+ "summarizes all
events that invoke the MD portion of AIMD\n"
+ "congestion
control, and as such is the best indicator of\n"
+ "how cwnd is being
affected by congestion.\n" },
+ {
+ "CountRTT",
+ "The number of round trip time
samples included in\n"
+
"tcpEStatsPathSumRTT and tcpEStatsPathHCSumRTT.\n" },
+ { "CurCwnd", "The current congestion window, in
octets.\n" },
+ { "CurRTO", "The current value of the retransmit
timer RTO.\n" },
+ {
+ "CurRwinRcvd",
+ "The most recent window
advertisement received, in octets.\n" },
+ {
+ "CurRwinSent",
+ "The most recent window
advertisement sent, in octets.\n" },
+ { "CurSsthresh", "The current slow start threshold
in octets.\n" },
+ {
+ "DSACKDups",
+ "The number of duplicate segments
reported to the local host\n"
+ "by D-SACK
blocks.\n" },
+ {
+ "DataBytesIn",
+ "The number of octets contained in
received data segments,\n"
+ "including
retransmitted data. Note that this does not\n"
+ "include TCP
headers.\n" },
+ {
+ "DataBytesOut",
+ "The number of octets of data
contained in transmitted segments,\n"
+ "including
retransmitted data. Note that this does not include\n"
+ "TCP
headers.\n" },
+ {
+ "DataPktsIn",
+ "The number of segments received
containing a positive length\n"
+ "data
segment.\n" },
+ {
+ "DataPktsOut",
+ "The number of segments sent
containing a positive length data\n"
+ "segment.\n"
},
+ { "DupAcksIn", "The number of duplicate ACKs
received.\n" },
+ {
+ "ECNEnabled",
+ "Enabled(1) if Explicit Congestion
Notification (ECN)\n"
+ "has been
negotiated on,\n"
+ "selfDisabled(2)
if it is disabled or not implemented\n"
+ "on the local
host, or\n"
+ "peerDisabled(3)
if not negotiated by the remote hosts.\n" },
+ {
+ "FastRetran",
+ "The number of invocations of the
Fast Retransmit algorithm.\n" },
+ {
+ "MaxCwnd",
+ "The maximum congestion window used during Slow Start, in octets.\n" },
+ { "MaxMSS", "The maximum MSS, in octets.\n" },
+ { "MaxRTO", "The maximum value of the retransmit
timer RTO.\n" },
+ { "MaxRTT", "The maximum sampled round trip
time.\n" },
+ {
+ "MaxRwinRcvd",
+ "The maximum window advertisement
received, in octets.\n" },
+ { "MaxRwinSent",
+ "The maximum window advertisement
sent, in octets.\n" },
+ {
+ "MaxSsthresh",
+ "The maximum slow start threshold,
excluding the initial\n"
+ "value.\n" },
+ { "MinMSS", "The minimum MSS, in octets.\n" },
+ { "MinRTO", "The minimum value of the retransmit
timer RTO.\n" },
+ { "MinRTT", "The minimum sampled round trip
time.\n" },
+ {
+ "MinRwinRcvd",
+ "The minimum window advertisement
received, in octets.\n" },
+ {
+ "MinRwinSent",
+ "The minimum window advertisement
sent, excluding the initial\n"
+ "unscaled window
advertised on the SYN, in octets.\n" },
+ {
+ "NagleEnabled",
+ "True(1) if the Nagle algorithm is
being used, else false(2).\n" },
+ {
+ "OtherReductions",
+ "The number of congestion window
reductions made as a result\n"
+ "of anything other
than AIMD congestion control algorithms.\n"
+ "Examples of
non-multiplicative window reductions include\n"
+ "Congestion Window
Validation [RFC2861] and experimental\n"
+ "algorithms such
as Vegas.\n" },
+ { "PktsIn", "The total number of segments
received.\n" },
+ { "PktsOut", "The total number of segments
sent.\n" },
+ {
+ "PktsRetrans",
+ "The number of segments
transmitted containing at least some\n"
+ "retransmitted
data.\n" },
+ {
+ "RcvWinScale",
+ "The value of Rcv.Wind.Scale.
Note that\n"
+ "RcvWinScale is
either zero or the same as WinScaleSent.\n" },
+ {
+ "SACKEnabled",
+ "True(1) if SACK has been
negotiated on, else false(2).\n" },
+ { "SACKsRcvd", "The number of SACK options
received.\n" },
+ {
+ "SendStall",
+ "The number of interface stalls or
other sender local\n"
+ "resource
limitations that are treated as congestion\n"
+ "signals.\n"
},
+ { "SlowStart",
+ "The number of times the
congestion window has been\n"
+ "increased by the
Slow Start algorithm.\n" },
+ {
+ "SampleRTT",
+ "The most recent raw round trip
time measurement used in\n"
+ "calculation of
the RTO.\n" },
+ {
+ "SmoothedRTT",
+ "The smoothed round trip time used
in calculation of the\n"
+ "RTO. See SRTT in
[RFC2988].\n" },
+ {
+ "SndWinScale",
+ "The value of Snd.Wind.Scale.
Note that\n"
+ "SndWinScale is
either zero or the same as WinScaleRcvd.\n" },
+ {
+ "SndLimTimeRwin",
+ "The cumulative time spent in the
'Receiver Limited' state.\n" },
+ {
+ "SndLimTimeCwnd",
+ "The cumulative time spent in the
'Congestion Limited' state.\n" },
+ {
+ "SndLimTimeSender",
+ "The cumulative time spent in the
'Sender Limited' state.\n" },
+ {
+ "SndLimTransRwin",
+ "The number of transitions into
the 'Receiver Limited' state\n"
+ "from either the
'Congestion Limited' or 'Sender Limited'\n"
+ "states. This
state is entered whenever TCP transmission\n"
+ "stops because the
sender has filled the announced receiver\n"
+ "window.\n" },
+ {
+ "SndLimTransCwnd",
+ "The number of transitions into
the 'Congestion Limited'\n"
+ "state from either
the 'Receiver Limited' or 'Sender\n"
+ "Limited' states.
This state is entered whenever TCP\n"
+ "transmission
stops because the sender has reached some\n"
+ "limit defined by
congestion control (e.g. cwnd) or other\n"
+ "algorithms
(retransmission timeouts) designed to control\n"
+ "network
traffic.\n" },
+ {
+ "SndLimTransSender",
+ "The number of transitions into
the 'Sender Limited' state\n"
+ "from either the
'Receiver Limited' or 'Congestion Limited'\n"
+ "states. This
state is entered whenever TCP transmission\n"
+ "stops due to some
sender limit such as running out of\n"
+ "application data
or other resources and the Karn algorithm.\n"
+ "When TCP stops
sending data for any reason which can not be\n"
+ "classified as
Receiver Limited or Congestion Limited it\n"
+ "MUST be treated
as Sender Limited.\n" },
+ {
+ "SndLimBytesRwin",
+ "The cumulative bytes sent while
in the 'Receiver Limited'\n"
+ "state, as
determined by the Local Host, when the Local Host is\n"
+ "a sender. This
state is entered whenever TCP transmission\n"
+ "stops due to
Receiver not being able to receive data.\n" },
+ {
+ "SndLimBytesCwnd",
+ "The cumulative bytes sent while
in the 'Congestion Limited'\n"
+ "state, as
determined by the Local Host, when the Local Host is\n"
+ "a sender. This
state is entered whenever TCP transmission\n"
+ "stops due to
congestion.\n" },
+ {
+ "SndLimBytesSender",
+ "The cumulative bytes sent while
in the 'Sender Limited'\n"
+ "state, as
determined by the Local Host, when the Local Host is\n"
+ "a sender. This
state is entered whenever TCP transmission\n"
+ "stops because
there is no more data in sender's buffer.\n" },
+ {
+ "SubsequentTimeouts",
+ "The number of times the
retransmit timeout has expired\n"
+ "after the RTO has
been doubled. See section 5.5 in RFC2988.\n" },
+ { "SumRTT", "The sum of all sampled round trip
times.\n" },
+ {
+ "Timeouts",
+ "The number of times the
retransmit timeout has expired when\n"
+ "the RTO backoff
multiplier is equal to one.\n" },
+ {
+ "TimestampsEnabled",
+ "Enabled(1) if TCP timestamps have
been negotiated on,\n"
+ "selfDisabled(2)
if they are disabled or not implemented on\n"
+ "the local host,
or peerDisabled(3) if not negotiated by the\n"
+ "remote
hosts.\n" },
+ {
+ "WinScaleRcvd",
+ "The value of the received window
scale option if one was\n"
+ "received;
otherwise, a value of -1.\n" },
+ {
+ "WinScaleSent",
+ "The value of the transmitted
window scale option if one was\n"
+ "sent; otherwise,
a value of -1.\n" },
+ { "DupAcksOut", "The number of duplicate ACKs
sent.\n" },
+ {
+ "StartTimeUsec",
+ "The value of sysUpTime at the
time this listener was\n"
+ "established. If
the current state was entered prior to\n"
+ "the last
re-initialization of the local network management\n"
+ "subsystem, then
this object contains a zero value.\n" },
+ {
+ "Duration",
+ "The seconds part of the time
elapsed between StartTimeStamp\n"
+ "and the most recent protocol event (segment sent or received).\n" },
+ { NULL, NULL } };

#endif
=======================================
--- /branches/kkumar_code_organize/src/viewtrace.c Sun Aug 19 03:26:07
2007
+++ /branches/kkumar_code_organize/src/viewtrace.c Mon Oct 17 06:43:25
2011
@@ -47,267 +47,265 @@
extern char *optarg;
FILE *fp;

-int c2sport = 3002,
- s2cport = 3003;
-
-static struct option long_options[] = {
- {"count", 1, 0, 'c'},
- {"debug", 0, 0, 'd'},
- {"file", 1, 0, 'f'},
- {"help", 0, 0, 'h'},
- {"interface", 1, 0, 'i'},
- {"log", 1, 0, 'l'},
- {"c2sport", 1, 0, 303},
- {"s2cport", 1, 0, 304},
- {"version", 0, 0, 'v'},
- {0, 0, 0, 0}
-};
+int c2sport = 3002, s2cport = 3003;
+
+static struct option long_options[] = { { "count", 1, 0, 'c' }, { "debug", 0, 0,
+ 'd' }, { "file", 1, 0, 'f' }, { "help", 0, 0, 'h' }, {
"interface", 1,
+ 0, 'i' }, { "log", 1, 0, 'l' }, { "c2sport", 1, 0, 303 }, {
"s2cport",
+ 1, 0, 304 }, { "version", 0, 0, 'v' }, { 0, 0, 0, 0 } };

/*
* Copy arg vector into a new buffer, concatenating arguments with spaces.
*/
char *
-copy_argv(register char **argv)
-{
- register char **p;
- register u_int len = 0;
- char *buf;
- char *src, *dst;
-
- p = argv;
- if (*p == 0)
- return 0;
-
- while (*p)
- len += strlen(*p++) + 1;
-
- buf = (char *)malloc(len);
- if (buf == NULL) {
- perror("copy_argv: malloc");
- exit(1);
- }
-
- p = argv;
- dst = buf;
- while ((src = *p++) != NULL) {
- while ((*dst++ = *src++) != '\0')
- ;
- dst[-1] = ' ';
- }
- dst[-1] = '\0';
-
- return buf;
+copy_argv(register char **argv) {
+ register char **p;
+ register u_int len = 0;
+ char *buf;
+ char *src, *dst;
+
+ p = argv;
+ if (*p == 0)
+ return 0;
+
+ while (*p)
+ len += strlen(*p++) + 1;
+
+ buf = (char *) malloc(len);
+ if (buf == NULL) {
+ perror("copy_argv: malloc");
+ exit(1);
+ }
+
+ p = argv;
+ dst = buf;
+ while ((src = *p++) != NULL) {
+ while ((*dst++ = *src++) != '\0')
+ ;
+ dst[-1] = ' ';
+ }
+ dst[-1] = '\0';
+
+ return buf;
}

/* initialize variables before starting to accumulate data */
-void
-init_vars(struct spdpair *cur)
-{
- int i;
+void init_vars(struct spdpair *cur) {
+ int i;

#if defined(AF_INET6)
memset(cur->saddr, 0, 4);
memset(cur->daddr, 0, 4);
#else
- cur->saddr = 0;
- cur->daddr = 0;
+ cur->saddr = 0;
+ cur->daddr = 0;
#endif
- cur->sport = 0;
- cur->dport = 0;
- cur->seq = 0;
- cur->ack = 0;
- cur->win = 0;
- cur->sec = 0;
- cur->usec = 0;
- cur->time = 0;
- cur->totalspd = 0;
- cur->totalcount = 0;
- for (i=0; i<16; i++)
- cur->links[i] = 0;
-}
-
+ cur->sport = 0;
+ cur->dport = 0;
+ cur->seq = 0;
+ cur->ack = 0;
+ cur->win = 0;
+ cur->sec = 0;
+ cur->usec = 0;
+ cur->time = 0;
+ cur->totalspd = 0;
+ cur->totalcount = 0;
+ for (i = 0; i < 16; i++)
+ cur->links[i] = 0;
+}

/* This routine prints results to the screen. */
-void
-vt_print_bins(struct spdpair *cur)
-{
-
- int i, total=0, max=0, s, index=0;
- char buff[256];
- int tzoffset = 6;
-
- /* the tzoffset value is fixed for CST (6), use 5 for CDT. The code needs to find the
- * current timezone and use that value here! */
- s = (cur->st_sec - (tzoffset * 3600)) %86400;
-
- for (i=0; i<16; i++) {
- total += cur->links[i];
- if (cur->links[i] > max) {
- max = cur->links[i];
- index = i;
- }
- }
- if ((max == cur->links[10]) || (max == cur->links[11])) {
- max = 0;
- for (i=0; i<10; i++) {
- if (max < cur->links[i]) {
- index = i;
- max = cur->links[i];
- }
- }
- }
-
- fprintf(stderr, "%02d:%02d:%02d.%06u ",
- s / 3600, (s % 3600) / 60, s % 60, cur->st_usec);
- if ((cur->sport == c2sport) || (cur->dport == c2sport)) {
+void vt_print_bins(struct spdpair *cur) {
+
+ int i, total = 0, max = 0, s, index = 0;
+ char buff[256];
+ int tzoffset = 6;
+
+ /* the tzoffset value is fixed for CST (6), use 5 for CDT. The code needs to find the
+ * current timezone and use that value here! */
+ s = (cur->st_sec - (tzoffset * 3600)) % 86400;
+
+ for (i = 0; i < 16; i++) {
+ total += cur->links[i];
+ if (cur->links[i] > max) {
+ max = cur->links[i];
+ index = i;
+ }
+ }
+ if ((max == cur->links[10]) || (max == cur->links[11])) {
+ max = 0;
+ for (i = 0; i < 10; i++) {
+ if (max < cur->links[i]) {
+ index = i;
+ max = cur->links[i];
+ }
+ }
+ }
+
+ fprintf(stderr, "%02d:%02d:%02d.%06u ", s / 3600, (s % 3600) / 60, s % 60,
+ cur->st_usec);
+ if ((cur->sport == c2sport) || (cur->dport == c2sport)) {
#if defined(AF_INET6)
- char str[136];
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) cur->saddr, str, sizeof(str));
- fprintf(stderr, "%s.%d --> ", str, cur->sport);
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) cur->daddr, str, sizeof(str));
- fprintf(stderr, "%s.%d ", str, cur->dport);
+ char str[136];
+ memset(str, 0, 136);
+ inet_ntop(AF_INET6, (void *) cur->saddr, str, sizeof(str));
+ fprintf(stderr, "%s.%d --> ", str, cur->sport);
+ memset(str, 0, 136);
+ inet_ntop(AF_INET6, (void *) cur->daddr, str, sizeof(str));
+ fprintf(stderr, "%s.%d ", str, cur->dport);
#else
- fprintf(stderr, "%u.%u.%u.%u:%d --> ", (cur->saddr & 0xFF), ((cur->saddr >> 8) & 0xff),
- ((cur->saddr >> 16) & 0xff), (cur->saddr >> 24), cur->sport);
- fprintf(stderr, "%u.%u.%u.%u:%d ", (cur->daddr & 0xFF), ((cur->daddr
8) & 0xff),
+ fprintf(
+ stderr,
+ "%u.%u.%u.%u:%d --> ",
+ (cur->saddr & 0xFF), ((cur->saddr >> 8) &
0xff),
+ ((cur->saddr >> 16) & 0xff), (cur->saddr >> 24),
cur->sport);
+ fprintf(stderr, "%u.%u.%u.%u:%d ", (cur->daddr & 0xFF), ((cur->daddr
8) & 0xff),
((cur->daddr >> 16) & 0xff), (cur->daddr >> 24), cur->dport);
#endif
} else {
#if defined(AF_INET6)
- char str[136];
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) cur->daddr, str, sizeof(str));
- fprintf(stderr, "%s.%d --> ", str, cur->dport);
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) cur->saddr, str, sizeof(str));
- fprintf(stderr, "%s.%d ", str, cur->sport);
+ char str[136];
+ memset(str, 0, 136);
+ inet_ntop(AF_INET6, (void *) cur->daddr, str,
sizeof(str));
+ fprintf(stderr, "%s.%d --> ", str, cur->dport);
+ memset(str, 0, 136);
+ inet_ntop(AF_INET6, (void *) cur->saddr, str,
sizeof(str));
+ fprintf(stderr, "%s.%d ", str, cur->sport);
#else
- fprintf(stderr, "%u.%u.%u.%u:%d --> ", (cur->daddr & 0xFF), ((cur->daddr >> 8) & 0xff),
- ((cur->daddr >> 16) & 0xff), (cur->daddr >> 24), cur->dport);
- fprintf(stderr, "%u.%u.%u.%u:%d ", (cur->saddr & 0xFF), ((cur->saddr
8) & 0xff),
- ((cur->saddr >> 16) & 0xff), (cur->saddr >> 24), cur->sport);
+ fprintf(stderr, "%u.%u.%u.%u:%d --> ", (cur->daddr & 0xFF), ((cur->daddr >> 8) & 0xff),
+ ((cur->daddr >> 16) & 0xff), (cur->daddr
>> 24), cur->dport);
+ fprintf(stderr, "%u.%u.%u.%u:%d ", (cur->saddr & 0xFF), ((cur->saddr
8) & 0xff),
+ ((cur->saddr >> 16) & 0xff), (cur->saddr
>> 24), cur->sport);
#endif
- }
- if (max == 0)
- fprintf(stderr, "\n\tNo packets collected\n");
-
- switch (index) {
- case -1: fprintf(stderr, "link=%d (Fault); ", index);
- break;
- case 0: fprintf(stderr, "link=%d (RTT); ", index);
- break;
- case 1: fprintf(stderr, "link=%d (dial-up); ", index);
- break;
- case 2: fprintf(stderr, "link=%d (T1); ", index);
- break;
- case 3: fprintf(stderr, "link=%d (Enet); ", index);
- break;
- case 4: fprintf(stderr, "link=%d (T3); ", index);
- break;
- case 5: fprintf(stderr, "link=%d (FastE); ", index);
- break;
- case 6: fprintf(stderr, "link=%d (OC-12); ", index);
- break;
- case 7: fprintf(stderr, "link=%d (GigE); ", index);
- break;
- case 8: fprintf(stderr, "link=%d (OC-48); ", index);
- break;
- case 9: fprintf(stderr, "link=%d (10 GigE); ", index);
- break;
- case 10: fprintf(stderr, "retransmission; ");
- break;
- case 11: fprintf(stderr, "link=%d (unknown); ", index);
- break;
- }
- fprintf(stderr, "packets=%d\n", total);
- fprintf(stderr, "Running Average = %0.2f Mbps ", cur->totalspd2);
- fprintf(stderr, "Average speed = %0.2f Mbps\n", cur->totalspd/cur->totalcount);
-
- if (cur->totalcount > 0) {
- sprintf(buff, "%d %d %d %d %d %d %d %d %d %d %d %d %0.2f", cur->links[0], cur->links[1],
- cur->links[2], cur->links[3], cur->links[4], cur->links[5], cur->links[6],
- cur->links[7], cur->links[8], cur->links[9], cur->links[10], cur->links[11],
- cur->totalspd2);
- fprintf(stderr, "link counters are '%s'\n", buff);
- }
-
- init_vars(&*cur);
+ }
+ if (max == 0)
+ fprintf(stderr, "\n\tNo packets collected\n");
+
+ switch (index) {
+ case -1:
+ fprintf(stderr, "link=%d (Fault); ", index);
+ break;
+ case 0:
+ fprintf(stderr, "link=%d (RTT); ", index);
+ break;
+ case 1:
+ fprintf(stderr, "link=%d (dial-up); ", index);
+ break;
+ case 2:
+ fprintf(stderr, "link=%d (T1); ", index);
+ break;
+ case 3:
+ fprintf(stderr, "link=%d (Enet); ", index);
+ break;
+ case 4:
+ fprintf(stderr, "link=%d (T3); ", index);
+ break;
+ case 5:
+ fprintf(stderr, "link=%d (FastE); ", index);
+ break;
+ case 6:
+ fprintf(stderr, "link=%d (OC-12); ", index);
+ break;
+ case 7:
+ fprintf(stderr, "link=%d (GigE); ", index);
+ break;
+ case 8:
+ fprintf(stderr, "link=%d (OC-48); ", index);
+ break;
+ case 9:
+ fprintf(stderr, "link=%d (10 GigE); ", index);
+ break;
+ case 10:
+ fprintf(stderr, "retransmission; ");
+ break;
+ case 11:
+ fprintf(stderr, "link=%d (unknown); ", index);
+ break;
+ }
+ fprintf(stderr, "packets=%d\n", total);
+ fprintf(stderr, "Running Average = %0.2f Mbps ", cur->totalspd2);
+ fprintf(stderr, "Average speed = %0.2f Mbps\n",
+ cur->totalspd / cur->totalcount);
+
+ if (cur->totalcount > 0) {
+ sprintf(buff, "%d %d %d %d %d %d %d %d %d %d %d %d %0.2f",
+ cur->links[0], cur->links[1], cur->links[2],
cur->links[3],
+ cur->links[4], cur->links[5], cur->links[6],
cur->links[7],
+ cur->links[8], cur->links[9], cur->links[10],
cur->links[11],
+ cur->totalspd2);
+ fprintf(stderr, "link counters are '%s'\n", buff);
+ }
+
+ init_vars(&*cur);
}

-void
-vt_calculate_spd(struct spdpair *cur, struct spdpair *cur2)
-{
-
- float bits, spd, time;
-
- time = (((cur->sec - cur2->sec)*1000000) + (cur->usec - cur2->usec));
- if ((cur->dport == c2sport) || (cur->sport == s2cport)) {
- if (cur->seq >= cur2->seq)
- bits = (cur->seq - cur2->seq) * 8;
- else
- bits = 0;
- } else {
- if (cur->ack >= cur2->ack)
- bits = (cur->ack - cur2->ack) * 8;
- else
- bits = 0;
- }
- spd = (bits/time); /* convert to mbits/sec) */
- if ((spd > 0) && (spd <= 0.01))
- cur2->links[0]++;
- if ((spd > 0.01) && (spd <= 0.064))
- cur2->links[1]++;
- if ((spd > 0.064) && (spd <= 1.5))
- cur2->links[2]++;
- else if ((spd > 1.5) && (spd <= 10))
- cur2->links[3]++;
- else if ((spd > 10) && (spd <=40))
- cur2->links[4]++;
- else if ((spd > 40) && (spd <=100))
- cur2->links[5]++;
- else if ((spd > 100) && (spd <= 622))
- cur2->links[6]++;
- else if ((spd > 622) && (spd <= 1000))
- cur2->links[7]++;
- else if ((spd > 1000) && (spd <= 2400))
- cur2->links[8]++;
- else if ((spd > 2400) && (spd <= 10000))
- cur2->links[9]++;
- else if (spd == 0)
- cur2->links[10]++;
- else
- cur2->links[11]++;
- cur2->seq = cur->seq;
- cur2->ack = cur->ack;
- cur2->win = cur->win;
- cur2->time = cur->time;
- cur2->sec = cur->sec;
- cur2->usec = cur->usec;
- if ((time > 10) && (spd > 0)) {
- cur2->totalspd += spd;
- cur2->totalcount++;
- cur2->totalspd2 = (cur2->totalspd2 + spd) / 2;
- }
+void vt_calculate_spd(struct spdpair *cur, struct spdpair *cur2) {
+
+ float bits, spd, time;
+
+ time = (((cur->sec - cur2->sec) * 1000000) + (cur->usec -
cur2->usec));
+ if ((cur->dport == c2sport) || (cur->sport == s2cport)) {
+ if (cur->seq >= cur2->seq)
+ bits = (cur->seq - cur2->seq) * 8;
+ else
+ bits = 0;
+ } else {
+ if (cur->ack >= cur2->ack)
+ bits = (cur->ack - cur2->ack) * 8;
+ else
+ bits = 0;
+ }
+ spd = (bits / time); /* convert to mbits/sec) */
+ if ((spd > 0) && (spd <= 0.01))
+ cur2->links[0]++;
+ if ((spd > 0.01) && (spd <= 0.064))
+ cur2->links[1]++;
+ if ((spd > 0.064) && (spd <= 1.5))
+ cur2->links[2]++;
+ else if ((spd > 1.5) && (spd <= 10))
+ cur2->links[3]++;
+ else if ((spd > 10) && (spd <= 40))
+ cur2->links[4]++;
+ else if ((spd > 40) && (spd <= 100))
+ cur2->links[5]++;
+ else if ((spd > 100) && (spd <= 622))
+ cur2->links[6]++;
+ else if ((spd > 622) && (spd <= 1000))
+ cur2->links[7]++;
+ else if ((spd > 1000) && (spd <= 2400))
+ cur2->links[8]++;
+ else if ((spd > 2400) && (spd <= 10000))
+ cur2->links[9]++;
+ else if (spd == 0)
+ cur2->links[10]++;
+ else
+ cur2->links[11]++;
+ cur2->seq = cur->seq;
+ cur2->ack = cur->ack;
+ cur2->win = cur->win;
+ cur2->time = cur->time;
+ cur2->sec = cur->sec;
+ cur2->usec = cur->usec;
+ if ((time > 10) && (spd > 0)) {
+ cur2->totalspd += spd;
+ cur2->totalcount++;
+ cur2->totalspd2 = (cur2->totalspd2 + spd) / 2;
+ }
}

/* Catch termination signal(s) and print remaining statistics */
-void
-cleanup(int signo)
-{
- if (signo == SIGALRM) {
- vt_print_bins(&fwd);
- vt_print_bins(&rev);
- return;
- }
+void cleanup(int signo) {
+ if (signo == SIGALRM) {
+ vt_print_bins(&fwd);
+ vt_print_bins(&rev);
+ return;
+ }

#ifdef HAVE_LIBPCAP
- pcap_close(pd);
+ pcap_close(pd);
#endif
- exit(0);
-}
-
+ exit(0);
+}

#ifdef HAVE_LIBPCAP
/* This routine does the main work. It steps through the input file
@@ -317,300 +315,304 @@
void
print_speed(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
{
- struct ether_header *enet;
- const struct ip *ip;
+ struct ether_header *enet;
+ const struct ip *ip;
#if defined(AF_INET6)
- const struct ip6_hdr *ip6;
+ const struct ip6_hdr *ip6;
#endif
- const struct tcphdr *tcp;
- struct spdpair current;
-
- current.sec = h->ts.tv_sec;
- current.usec = h->ts.tv_usec;
- current.time = (current.sec*1000000) + current.usec;
-
- enet = (struct ether_header *)p;
- p += sizeof(struct ether_header); /* move packet pointer past ethernet fields */
-
- ip = (const struct ip *)p;
+ const struct tcphdr *tcp;
+ struct spdpair current;
+
+ current.sec = h->ts.tv_sec;
+ current.usec = h->ts.tv_usec;
+ current.time = (current.sec*1000000) + current.usec;
+
+ enet = (struct ether_header *)p;
+ p += sizeof(struct ether_header); /* move packet pointer past ethernet fields */
+
+ ip = (const struct ip *)p;
#if defined(AF_INET6)
- if (ip->ip_v == 4) {
+ if (ip->ip_v == 4) {
#endif
- p += (ip->ip_hl) * 4;
- tcp = (const struct tcphdr *)p;
+ p += (ip->ip_hl) * 4;
+ tcp = (const struct tcphdr *)p;
#if defined(AF_INET6)
- current.saddr[0] = ip->ip_src.s_addr;
- current.daddr[0] = ip->ip_dst.s_addr;
+ current.saddr[0] = ip->ip_src.s_addr;
+ current.daddr[0] = ip->ip_dst.s_addr;
#else
- current.saddr = ip->ip_src.s_addr;
- current.daddr = ip->ip_dst.s_addr;
+ current.saddr = ip->ip_src.s_addr;
+ current.daddr = ip->ip_dst.s_addr;
#endif
- current.sport = ntohs(tcp->source);
- current.dport = ntohs(tcp->dest);
- current.seq = ntohl(tcp->seq);
- current.ack = ntohl(tcp->ack_seq);
- current.win = ntohs(tcp->window);
-
- if (tcp->rst == 1) {
- fprintf(stderr, "Reset packet found, aborting data collection\n");
- vt_print_bins(&fwd);
- vt_print_bins(&rev);
- return;
- }
+ current.sport = ntohs(tcp->source);
+ current.dport = ntohs(tcp->dest);
+ current.seq = ntohl(tcp->seq);
+ current.ack = ntohl(tcp->ack_seq);
+ current.win = ntohs(tcp->window);
+
+ if (tcp->rst == 1) {
+ fprintf(stderr, "Reset packet found, aborting data
collection\n");
+ vt_print_bins(&fwd);
+ vt_print_bins(&rev);
+ return;
+ }
#if defined(AF_INET6)
- if (fwd.saddr[0] == 0) {
- fprintf(stderr, "Started data collection for sockets %d:%d\n", current.dport,
- current.sport);
- fwd.saddr[0] = current.saddr[0];
- fwd.daddr[0] = current.daddr[0];
+ if (fwd.saddr[0] == 0) {
+ fprintf(stderr, "Started data collection for sockets %d:%d\n", current.dport,
+ current.sport);
+ fwd.saddr[0] = current.saddr[0];
+ fwd.daddr[0] = current.daddr[0];
#else
- if (fwd.saddr == 0) {
- fprintf(stderr, "Started data collection for sockets %d:%d\n", current.dport,
- current.sport);
- fwd.saddr = current.saddr;
- fwd.daddr = current.daddr;
+ if (fwd.saddr == 0) {
+ fprintf(stderr, "Started data collection for sockets %d:%d\n", current.dport,
+ current.sport);
+ fwd.saddr = current.saddr;
+ fwd.daddr = current.daddr;
#endif
- fwd.sport = current.sport;
- fwd.dport = current.dport;
- fwd.st_sec = current.sec;
- fwd.st_usec = current.usec;
+ fwd.sport = current.sport;
+ fwd.dport = current.dport;
+ fwd.st_sec = current.sec;
+ fwd.st_usec = current.usec;
#if defined(AF_INET6)
- rev.saddr[0] = current.daddr[0];
- rev.daddr[0] = current.saddr[0];
+ rev.saddr[0] = current.daddr[0];
+ rev.daddr[0] = current.saddr[0];
#else
- rev.saddr = current.daddr;
- rev.daddr = current.saddr;
+ rev.saddr = current.daddr;
+ rev.daddr = current.saddr;
#endif
- rev.sport = current.dport;
- rev.dport = current.sport;
- rev.st_sec = current.sec;
- rev.st_usec = current.usec;
- log_println(1, "Completed data collection for port %d", current.dport);
- return;
- }
+ rev.sport = current.dport;
+ rev.dport = current.sport;
+ rev.st_sec = current.sec;
+ rev.st_usec = current.usec;
+ log_println(1, "Completed data collection for port
%d", current.dport);
+ return;
+ }

#if defined(AF_INET6)
- if (fwd.saddr[0] == current.saddr[0]) {
+ if (fwd.saddr[0] == current.saddr[0]) {
#else
- if (fwd.saddr == current.saddr) {
+ if (fwd.saddr == current.saddr) {
#endif
- if (current.dport == c2sport)
- vt_calculate_spd(&current, &fwd);
- else if (current.sport == s2cport)
- vt_calculate_spd(&current, &fwd);
- }
+ if (current.dport == c2sport)
+ vt_calculate_spd(&current, &fwd);
+ else if (current.sport == s2cport)
+ vt_calculate_spd(&current, &fwd);
+ }
#if defined(AF_INET6)
- if (rev.saddr[0] == current.saddr[0]) {
+ if (rev.saddr[0] == current.saddr[0]) {
#else
- if (rev.saddr == current.saddr) {
+ if (rev.saddr == current.saddr) {
#endif
- if (current.sport == c2sport)
- vt_calculate_spd(&current, &rev);
- else if (current.dport == s2cport)
- vt_calculate_spd(&current, &rev);
- }
+ if (current.sport == c2sport)
+ vt_calculate_spd(&current,
&rev);
+ else if (current.dport ==
s2cport)
+ vt_calculate_spd(&current,
&rev);
+ }
#if defined(AF_INET6)
- }
- else {
- ip6 = (const struct ip6_hdr *)p;
-
- p += 40;
- tcp = (const struct tcphdr *)p;
- memcpy(current.saddr, (void *) &ip6->ip6_src, 16);
- memcpy(current.daddr, (void *) &ip6->ip6_dst, 16);
-
- current.sport = ntohs(tcp->source);
- current.dport = ntohs(tcp->dest);
- current.seq = ntohl(tcp->seq);
- current.ack = ntohl(tcp->ack_seq);
- current.win = ntohs(tcp->window);
-
- if (tcp->rst == 1) {
- fprintf(stderr, "Reset packet found, aborting data collection\n");
- vt_print_bins(&fwd);
- vt_print_bins(&rev);
- return;
- }
- if ((fwd.saddr[0] == 0) && (fwd.saddr[1] == 0) && (fwd.saddr[2] == 0) && (fwd.saddr[3] == 0)) {
- fprintf(stderr, "Started data collection for sockets %d:%d\n", current.dport,
- current.sport);
- memcpy(fwd.saddr, (void *) current.saddr, 16);
- memcpy(fwd.daddr, (void *) current.daddr, 16);
- fwd.sport = current.sport;
- fwd.dport = current.dport;
- fwd.st_sec = current.sec;
- fwd.st_usec = current.usec;
- memcpy(rev.saddr, (void *) current.daddr, 16);
- memcpy(rev.daddr, (void *) current.saddr, 16);
- rev.sport = current.dport;
- rev.dport = current.sport;
- rev.st_sec = current.sec;
- rev.st_usec = current.usec;
- fwd.dec_cnt = 0;
- fwd.inc_cnt = 0;
- fwd.same_cnt = 0;
- fwd.timeout = 0;
- fwd.dupack = 0;
- rev.dec_cnt = 0;
- rev.inc_cnt = 0;
- rev.same_cnt = 0;
- rev.timeout = 0;
- rev.dupack = 0;
- return;
- }
-
- if ((fwd.saddr[0] == current.saddr[0]) &&
- (fwd.saddr[1] == current.saddr[1]) &&
- (fwd.saddr[2] == current.saddr[2]) &&
- (fwd.saddr[3] == current.saddr[3])) {
- if (current.dport == c2sport)
- vt_calculate_spd(&current, &fwd);
- else if (current.sport == s2cport)
- vt_calculate_spd(&current, &fwd);
- }
- if ((rev.saddr[0] == current.saddr[0]) &&
- (rev.saddr[1] == current.saddr[1]) &&
- (rev.saddr[2] == current.saddr[2]) &&
- (rev.saddr[3] == current.saddr[3])) {
- if (current.sport == c2sport)
- vt_calculate_spd(&current, &rev);
- else if (current.dport == s2cport)
- vt_calculate_spd(&current, &rev);
- }
- }
+ }
+ else {
+ ip6 = (const struct ip6_hdr *)p;
+
+ p += 40;
+ tcp = (const struct tcphdr *)p;
+ memcpy(current.saddr, (void *)
&ip6->ip6_src, 16);
+ memcpy(current.daddr, (void *)
&ip6->ip6_dst, 16);
+
+ current.sport = ntohs(tcp->source);
+ current.dport = ntohs(tcp->dest);
+ current.seq = ntohl(tcp->seq);
+ current.ack = ntohl(tcp->ack_seq);
+ current.win = ntohs(tcp->window);
+
+ if (tcp->rst == 1) {
+ fprintf(stderr, "Reset packet
found, aborting data collection\n");
+ vt_print_bins(&fwd);
+ vt_print_bins(&rev);
+ return;
+ }
+ if ((fwd.saddr[0] == 0) && (fwd.saddr[1] == 0) && (fwd.saddr[2] == 0) && (fwd.saddr[3] == 0)) {
+ fprintf(stderr, "Started data collection for sockets %d:%d\n", current.dport,
+
current.sport);
+ memcpy(fwd.saddr, (void *)
current.saddr, 16);
+ memcpy(fwd.daddr, (void *)
current.daddr, 16);
+ fwd.sport = current.sport;
+ fwd.dport = current.dport;
+ fwd.st_sec = current.sec;
+ fwd.st_usec = current.usec;
+ memcpy(rev.saddr, (void *)
current.daddr, 16);
+ memcpy(rev.daddr, (void *)
current.saddr, 16);
+ rev.sport = current.dport;
+ rev.dport = current.sport;
+ rev.st_sec = current.sec;
+ rev.st_usec = current.usec;
+ fwd.dec_cnt = 0;
+ fwd.inc_cnt = 0;
+ fwd.same_cnt = 0;
+ fwd.timeout = 0;
+ fwd.dupack = 0;
+ rev.dec_cnt = 0;
+ rev.inc_cnt = 0;
+ rev.same_cnt = 0;
+ rev.timeout = 0;
+ rev.dupack = 0;
+ return;
+ }
+
+ if ((fwd.saddr[0] == current.saddr[0])
&&
+ (fwd.saddr[1] ==
current.saddr[1]) &&
+ (fwd.saddr[2] ==
current.saddr[2]) &&
+ (fwd.saddr[3] ==
current.saddr[3])) {
+ if (current.dport == c2sport)
+ vt_calculate_spd(&current,
&fwd);
+ else if (current.sport ==
s2cport)
+ vt_calculate_spd(&current,
&fwd);
+ }
+ if ((rev.saddr[0] == current.saddr[0])
&&
+ (rev.saddr[1] ==
current.saddr[1]) &&
+ (rev.saddr[2] ==
current.saddr[2]) &&
+ (rev.saddr[3] ==
current.saddr[3])) {
+ if (current.sport == c2sport)
+ vt_calculate_spd(&current,
&rev);
+ else if (current.dport ==
s2cport)
+ vt_calculate_spd(&current,
&rev);
+ }
+ }
#endif
-}
+ }
#endif

-int
-main(int argc, char **argv)
-{
-
- char *read_file, *cmdbuf, *device;
+int main(int argc, char **argv) {
+
+ char *read_file, *cmdbuf, *device;
#ifdef HAVE_LIBPCAP
- pcap_handler printer;
- u_char * pcap_userdata = NULL;
- struct bpf_program fcode;
- char errbuf[PCAP_ERRBUF_SIZE];
+ pcap_handler printer;
+ u_char * pcap_userdata = NULL;
+ struct bpf_program fcode;
+ char errbuf[PCAP_ERRBUF_SIZE];
#endif
- int cnt, pflag = 0, debug = 0, c;
- struct sigaction new;
-
- read_file = NULL;
- device = NULL;
- cnt = -1; /* read forever, or until end of file */
- while ((c = getopt_long(argc, argv, "c:df:hi:l:v", long_options, 0)) != -1) {
- switch (c) {
- case 'c':
- cnt = atoi(optarg);
- break;
- case 'd':
- debug++;
- break;
- case 'f' :
- read_file = optarg;
- break;
- case 'i' :
- device = optarg;
- break;
- case 'h':
+ int cnt, pflag = 0, debug = 0, c;
+ struct sigaction new;
+
+ read_file = NULL;
+ device = NULL;
+ cnt = -1; /* read forever, or until end of file */
+ while ((c = getopt_long(argc, argv, "c:df:hi:l:v", long_options, 0)) != -1) {
+ switch (c) {
+ case 'c':
+ cnt = atoi(optarg);
+ break;
+ case 'd':
+ debug++;
+ break;
+ case 'f':
+ read_file = optarg;
+ break;
+ case 'i':
+ device = optarg;
+ break;
+ case 'h':
#ifdef HAVE_LIBPCAP
- vt_long_usage("ANL/Internet2 NDT version " VERSION " (viewtrace)");
+ vt_long_usage("ANL/Internet2 NDT version " VERSION "
(viewtrace)");
#else
- vt_long_usage("ANL/Internet2 NDT version " VERSION " (viewtrace) [missing pcap library]");
+ vt_long_usage("ANL/Internet2 NDT version " VERSION " (viewtrace) [missing pcap library]");
#endif
- break;
- case 'v':
+ break;
+ case 'v':
#ifdef HAVE_LIBPCAP
- printf("ANL/Internet2 NDT version %s (viewtrace)\n", VERSION);
+ printf("ANL/Internet2 NDT version %s (viewtrace)\n",
VERSION);
#else
- printf("ANL/Internet2 NDT version %s (viewtrace) [missing pcap library]\n", VERSION);
+ printf(
+ "ANL/Internet2 NDT version %s (viewtrace)
[missing pcap library]\n",
+ VERSION);
#endif
- exit(0);
- break;
- case 303:
- if (check_int(optarg, &c2sport)) {
- char tmpText[200];
- snprintf(tmpText, 200, "Invalid C2S throughput test port number: %s", optarg);
- short_usage(argv[0], tmpText);
- }
- break;
- case 304:
- if (check_int(optarg, &s2cport)) {
- char tmpText[200];
- snprintf(tmpText, 200, "Invalid S2C throughput test port number: %s", optarg);
- short_usage(argv[0], tmpText);
- }
- break;
- case '?':
- short_usage(argv[0], "");
- break;
- }
- }
-
- if (optind < argc) {
- short_usage(argv[0], "Unrecognized non-option elements");
- }
-
- log_init(argv[0], debug);
+ exit(0);
+ break;
+ case 303:
+ if (check_int(optarg, &c2sport)) {
+ char tmpText[200];
+ snprintf(tmpText, 200,
+ "Invalid C2S throughput test port
number: %s", optarg);
+ short_usage(argv[0], tmpText);
+ }
+ break;
+ case 304:
+ if (check_int(optarg, &s2cport)) {
+ char tmpText[200];
+ snprintf(tmpText, 200,
+ "Invalid S2C throughput test port
number: %s", optarg);
+ short_usage(argv[0], tmpText);
+ }
+ break;
+ case '?':
+ short_usage(argv[0], "");
+ break;
+ }
+ }
+
+ if (optind < argc) {
+ short_usage(argv[0], "Unrecognized non-option elements");
+ }
+
+ log_init(argv[0], debug);

#ifdef HAVE_LIBPCAP
- init_vars(&fwd);
- init_vars(&rev);
-
- if (read_file == NULL) {
- if (device == NULL) {
- device = pcap_lookupdev(errbuf);
- if (device == NULL) {
- fprintf(stderr, "pcap_lookupdev failed: %s\n", errbuf);
- exit (-1);
- }
- }
- if ((pd = pcap_open_live(device, 68, !pflag, 1000, errbuf)) == NULL) {
- fprintf(stderr, "pcap_open_live failed: %s\n", errbuf);
- exit (-9);
- }
- memset(&new, 0, sizeof(new));
- new.sa_handler = cleanup;
- sigaction(SIGTERM, &new, NULL);
- sigaction(SIGINT, &new, NULL);
- sigaction(SIGALRM, &new, NULL);
-
- }
- else {
- if ((pd = pcap_open_offline(read_file, errbuf)) == NULL) {
- fprintf(stderr, "pcap_open_offline failed: %s\n", errbuf);
- exit (-2);
- }
- }
-
- cmdbuf = copy_argv(&argv[optind]);
-
- if (pcap_compile(pd, &fcode, cmdbuf, 0, 0xFFFFFF00) < 0) {
- fprintf(stderr, "pcap_compile failed %s\n", pcap_geterr(pd));
- exit(-2);
- }
-
- if (pcap_setfilter(pd, &fcode) < 0) {
- fprintf(stderr, "pcap_setfiler failed %s\n", pcap_geterr(pd));
- exit (-2);
- }
-
- printer = (pcap_handler) print_speed;
- if (pcap_loop(pd, cnt, printer, pcap_userdata) < 0) {
- fprintf(stderr, "pcap_loop failed %s\n", pcap_geterr(pd));
- exit(-2);
- }
- if (fwd.sport == s2cport) {
- vt_print_bins(&rev);
- vt_print_bins(&fwd);
- } else {
- vt_print_bins(&fwd);
- vt_print_bins(&rev);
- }
- pcap_close(pd);
+ init_vars(&fwd);
+ init_vars(&rev);
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/web100-admin.c Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/web100-admin.c Mon Oct 17 06:43:25 2011
@@ -20,7 +20,7 @@
* catch up on what's happened before.
*/

-int maxc2sspd=0, minc2sspd=0, maxs2cspd=0, mins2cspd=0;
+int maxc2sspd = 0, minc2sspd = 0, maxs2cspd = 0, mins2cspd = 0;
int count[16], totmismatch, totbad_cable;

float recvbwd, cwndbwd, sendbwd;
@@ -31,617 +31,693 @@
double bwin, bwout;
char *AdminFileName;

-int
-calculate(char now[32], int SumRTT, int CountRTT, int CongestionSignals, int PktsOut,
- int DupAcksIn, int AckPktsIn, int CurrentMSS, int SndLimTimeRwin,
- int SndLimTimeCwnd, int SndLimTimeSender, int MaxRwinRcvd, int CurrentCwnd,
- int Sndbuf, int DataBytesOut, int mismatch, int bad_cable, int c2sspd, int s2cspd,
- int c2sdata, int s2cack, int view_flag)
-{
-
- int congestion2=0, i;
- static int totalcnt;
- double rttsec;
- double rwintime, cwndtime, sendtime;
- int totaltime;
- char view_string[256], *str, tmpstr[32];
- FILE *fp;
-
- if (view_flag == 1) {
- fp = fopen("/tmp/view.string", "r");
- fgets(view_string, 256, fp);
-
- str = view_string;
- sscanf(str, "%[^,]s", tmpstr);
- maxc2sspd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- minc2sspd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- maxs2cspd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- mins2cspd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- totalcnt = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- totmismatch = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- totbad_cable = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[0] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[1] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[2] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[3] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[4] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[5] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[6] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[7] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[8] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[9] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[10] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[11] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[12] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[13] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[14] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- count[15] = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- //strncpy(maxdate, tmpstr, strlen(tmpstr));
- strlcpy(maxdate, tmpstr, sizeof(maxdate));
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- //strncpy(mindate, tmpstr, strlen(tmpstr));
- strlcpy(mindate, tmpstr, sizeof(mindate));
-
- for (i=0; i<strlen(mindate); i++)
- if (mindate[i] == '\n')
- break;
- mindate[i] = '\0';
-
- log_println(1, "Updating admin_view variables: Total count = %d", totalcnt);
-
- fclose(fp);
- }
-
- switch (c2sdata) {
- case -2: sprintf(btlneck, "Insufficent Data");
- break;
- case -1: sprintf(btlneck, "System Fault");
- break;
- case 0: sprintf(btlneck, "Round Trip Time");
- break;
- case 1: sprintf(btlneck, "Dial-up modem");
- break;
- case 2:
- if (((float)c2sspd/(float)s2cspd > .8)
- && ((float)c2sspd/(float)s2cspd < 1.2) && (c2sspd > 1000))
- sprintf(btlneck, "T1 subnet");
- else {
- if (s2cack == 3)
- sprintf(btlneck, "Cable Modem");
- else
- sprintf(btlneck, "DSL");
- }
- break;
- case 3: sprintf(btlneck, "Ethernet");
- break;
- case 4: sprintf(btlneck, "T3/DS-3");
- break;
- case 5: sprintf(btlneck, "FastEthernet");
- break;
- case 6: sprintf(btlneck, "OC-12");
- break;
- case 7: sprintf(btlneck, "Gigabit Ethernet");
- break;
- case 8: sprintf(btlneck, "OC-48");
- break;
- case 9: sprintf(btlneck, "10 Gigabit Enet");
- break;
- case 10: sprintf(btlneck, "Retransmissions");
- }
-
- /* Calculate some values */
- //strncpy(date, now, strlen(now));
- strlcpy(date, now, sizeof(date));
- avgrtt = (double) SumRTT/CountRTT;
- rttsec = avgrtt * .001;
- loss2 = (double)CongestionSignals/PktsOut;
- if (loss2 == 0)
- loss2 = .000001; /* set to 10^-6 for now */
-
- oo_order = (double)DupAcksIn/AckPktsIn;
- bw2 = (CurrentMSS / (rttsec * sqrt(loss2))) * 8 / 1024 / 1024;
- totaltime = SndLimTimeRwin + SndLimTimeCwnd + SndLimTimeSender;
- rwintime = (double)SndLimTimeRwin/totaltime;
- cwndtime = (double)SndLimTimeCwnd/totaltime;
- sendtime = (double)SndLimTimeSender/totaltime;
- timesec = totaltime/1000000;
-
- recvbwd = ((MaxRwinRcvd*8)/avgrtt)/1000;
- cwndbwd = ((CurrentCwnd*8)/avgrtt)/1000;
- sendbwd = ((Sndbuf*8)/avgrtt)/1000;
-
- if ((cwndtime > .02) && (mismatch == 0) && (cwndbwd < recvbwd))
- congestion2 = 1;
-
- if (totalcnt == 0) {
- minc2sspd = c2sspd;
- mins2cspd = s2cspd;
- maxc2sspd = c2sspd;
- maxs2cspd = s2cspd;
- /*strncpy(startdate, date, strlen(date));
- strncpy(maxdate, date, strlen(date));
- strncpy(mindate, date, strlen(date));*/
- strlcpy(startdate, date, sizeof(startdate));
- strlcpy(maxdate, date, sizeof(maxdate));
- strlcpy(mindate, date, sizeof(mindate));
- }
- if (c2sspd > maxc2sspd) {
- maxc2sspd = c2sspd;
- //strncpy(maxdate, date, strlen(date));
- strlcpy(maxdate, date, sizeof(maxdate));
- }
- if (s2cspd > maxs2cspd) {
- maxs2cspd = s2cspd;
- //strncpy(maxdate, date, strlen(date));
- strlcpy(maxdate, date, sizeof(maxdate));
- }
- if (c2sspd < minc2sspd) {
- minc2sspd = c2sspd;
- //strncpy(mindate, date, strlen(date));
- strlcpy(mindate, date, sizeof(mindate));
-
- }
- if (s2cspd < mins2cspd) {
- mins2cspd = s2cspd;
- //strncpy(mindate, date, strlen(date));
- strlcpy(mindate, date, sizeof(mindate));
- }
-
- log_println(1, "Initial counter Values Totalcnt = %d, Total Mismatch = %d, Total Bad Cables = %d",
- totalcnt, totmismatch, totbad_cable);
- totalcnt++;
- count[c2sdata+1]++;
- if (mismatch > 0)
- totmismatch++;
- if (bad_cable == 1)
- totbad_cable++;
- log_println(1, "Updated counter values Totalcnt = %d, Total Mismatch = %d, Total Bad Cables = %d",
- totalcnt, totmismatch, totbad_cable);
- log_println(1, "Individual counts = [%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d]",
- count[0], count[1], count[2], count[3], count[4], count[5], count[6], count[7],
- count[8], count[9], count[10], count[11], count[12], count[13], count[14], count[15]);
- return(totalcnt);
+int calculate(char now[32], int SumRTT, int CountRTT, int CongestionSignals,
+ int PktsOut, int DupAcksIn, int AckPktsIn, int CurrentMSS,
+ int SndLimTimeRwin, int SndLimTimeCwnd, int SndLimTimeSender,
+ int MaxRwinRcvd, int CurrentCwnd, int Sndbuf, int
DataBytesOut,
+ int mismatch, int bad_cable, int c2sspd, int s2cspd, int
c2sdata,
+ int s2cack, int view_flag) {
+
+ int congestion2 = 0, i;
+ static int totalcnt;
+ double rttsec;
+ double rwintime, cwndtime, sendtime;
+ int totaltime;
+ char view_string[256], *str, tmpstr[32];
+ FILE * fp;
+
+ if (view_flag == 1) {
+ fp = fopen("/tmp/view.string", "r");
+ fgets(view_string, 256, fp);
+
+ str = view_string;
+ sscanf(str, "%[^,]s", tmpstr);
+ maxc2sspd = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ minc2sspd = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ maxs2cspd = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ mins2cspd = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ totalcnt = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ totmismatch = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ totbad_cable = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[0] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[1] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[2] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[3] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[4] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[5] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[6] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[7] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[8] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[9] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[10] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[11] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[12] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[13] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[14] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[15] = atoi(tmpstr);
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ //strncpy(maxdate, tmpstr, strlen(tmpstr));
+ strlcpy(maxdate, tmpstr, sizeof(maxdate));
+
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ //strncpy(mindate, tmpstr, strlen(tmpstr));
+ strlcpy(mindate, tmpstr, sizeof(mindate));
+
+ for (i = 0; i < strlen(mindate); i++)
+ if (mindate[i] == '\n')
+ break;
+ mindate[i] = '\0';
+
+ log_println(1, "Updating admin_view variables: Total count =
%d",
+ totalcnt);
+
+ fclose(fp);
+ }
+
+ switch (c2sdata) {
+ case -2:
+ sprintf(btlneck, "Insufficent Data");
+ break;
+ case -1:
+ sprintf(btlneck, "System Fault");
+ break;
+ case 0:
+ sprintf(btlneck, "Round Trip Time");
+ break;
+ case 1:
+ sprintf(btlneck, "Dial-up modem");
+ break;
+ case 2:
+ if (((float) c2sspd / (float) s2cspd > .8)
+ && ((float) c2sspd / (float) s2cspd < 1.2) &&
(c2sspd > 1000))
+ sprintf(btlneck, "T1 subnet");
+ else {
+ if (s2cack == 3)
+ sprintf(btlneck, "Cable Modem");
+ else
+ sprintf(btlneck, "DSL");
+ }
+ break;
+ case 3:
+ sprintf(btlneck, "Ethernet");
+ break;
+ case 4:
+ sprintf(btlneck, "T3/DS-3");
+ break;
+ case 5:
+ sprintf(btlneck, "FastEthernet");
+ break;
+ case 6:
+ sprintf(btlneck, "OC-12");
+ break;
+ case 7:
+ sprintf(btlneck, "Gigabit Ethernet");
+ break;
+ case 8:
+ sprintf(btlneck, "OC-48");
+ break;
+ case 9:
+ sprintf(btlneck, "10 Gigabit Enet");
+ break;
+ case 10:
+ sprintf(btlneck, "Retransmissions");
+ }
+
+ /* Calculate some values */
+ //strncpy(date, now, strlen(now));
+ strlcpy(date, now, sizeof(date));
+ avgrtt = (double) SumRTT / CountRTT;
+ rttsec = avgrtt * .001;
+ loss2 = (double) CongestionSignals / PktsOut;
+ if (loss2 == 0)
+ loss2 = .000001; /* set to 10^-6 for now */
+
+ oo_order = (double) DupAcksIn / AckPktsIn;
+ bw2 = (CurrentMSS / (rttsec * sqrt(loss2))) * 8 / 1024 / 1024;
+ totaltime = SndLimTimeRwin + SndLimTimeCwnd + SndLimTimeSender;
+ rwintime = (double) SndLimTimeRwin / totaltime;
+ cwndtime = (double) SndLimTimeCwnd / totaltime;
+ sendtime = (double) SndLimTimeSender / totaltime;
+ timesec = totaltime / 1000000;
+
+ recvbwd = ((MaxRwinRcvd * 8) / avgrtt) / 1000;
+ cwndbwd = ((CurrentCwnd * 8) / avgrtt) / 1000;
+ sendbwd = ((Sndbuf * 8) / avgrtt) / 1000;
+
+ if ((cwndtime > .02) && (mismatch == 0) && (cwndbwd < recvbwd))
+ congestion2 = 1;
+
+ if (totalcnt == 0) {
+ minc2sspd = c2sspd;
+ mins2cspd = s2cspd;
+ maxc2sspd = c2sspd;
+ maxs2cspd = s2cspd;
+ /*strncpy(startdate, date, strlen(date));
+ strncpy(maxdate, date, strlen(date));
+ strncpy(mindate, date, strlen(date));*/
+ strlcpy(startdate, date, sizeof(startdate));
+ strlcpy(maxdate, date, sizeof(maxdate));
+ strlcpy(mindate, date, sizeof(mindate));
+ }
+ if (c2sspd > maxc2sspd) {
+ maxc2sspd = c2sspd;
+ //strncpy(maxdate, date, strlen(date));
+ strlcpy(maxdate, date, sizeof(maxdate));
+ }
+ if (s2cspd > maxs2cspd) {
+ maxs2cspd = s2cspd;
+ //strncpy(maxdate, date, strlen(date));
+ strlcpy(maxdate, date, sizeof(maxdate));
+ }
+ if (c2sspd < minc2sspd) {
+ minc2sspd = c2sspd;
+ //strncpy(mindate, date, strlen(date));
+ strlcpy(mindate, date, sizeof(mindate));
+
+ }
+ if (s2cspd < mins2cspd) {
+ mins2cspd = s2cspd;
+ //strncpy(mindate, date, strlen(date));
+ strlcpy(mindate, date, sizeof(mindate));
+ }
+
+ log_println(
+ 1,
+ "Initial counter Values Totalcnt = %d, Total Mismatch = %d, Total Bad Cables = %d",
+ totalcnt, totmismatch, totbad_cable);
+ totalcnt++;
+ count[c2sdata + 1]++;
+ if (mismatch > 0)
+ totmismatch++;
+ if (bad_cable == 1)
+ totbad_cable++;
+ log_println(
+ 1,
+ "Updated counter values Totalcnt = %d, Total Mismatch = %d, Total Bad Cables = %d",
+ totalcnt, totmismatch, totbad_cable);
+ log_println(
+ 1,
+ "Individual counts = [%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d]",
+ count[0], count[1], count[2], count[3], count[4],
count[5],
+ count[6], count[7], count[8], count[9], count[10],
count[11],
+ count[12], count[13], count[14], count[15]);
+ return (totalcnt);
}

-void
-gen_html(int c2sspd, int s2cspd, int MinRTT, int PktsRetrans, int Timeouts, int Sndbuf,
- int MaxRwinRcvd, int CurrentCwnd, int mismatch, int bad_cable, int totalcnt, int refresh)
-{
- FILE *fp;
- char view_string[256], tmpstr[256];
- int i;
- struct flock lock;
-
- fp = fopen(AdminFileName, "w");
- if (fp == NULL) {
- log_println(1, "Cannot open file for the admin web page...");
- return;
- }
- /* generate an HTML page for display. */
- fprintf(fp, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
- fprintf(fp, "<html> <head> <title>NDT server Admin Page</title>\n");
- fprintf(fp, "<meta http-equiv=\"refresh\" content=\"%d; url="ADMINFILE"\">\n", refresh);
- fprintf(fp, "<meta http-equiv=\"Content-Language\" content=\"en\">\n");
- fprintf(fp, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
- fprintf(fp, "</head>\n");
-
- /* First build current results table */
- fprintf(fp, "<table border>\n <tr>\n ");
- fprintf(fp, " <th colspan=8><font size=\"+1\">NDT Usage Statistics -- Current Test Results\n");
- fprintf(fp, " </font></tr>\n");
- fprintf(fp, " <tr>\n <th>Date/Time\n <th>Total Tests\n <th rowspan=6>\n");
- fprintf(fp, " <th>Bottleneck Link\n <th>Theoritical Limit\n <th rowspan=6>\n");
- fprintf(fp, " <th>C2S Speed\n <th>S2C Speed\n </tr>\n");
- fprintf(fp, " <tr>\n <td align=right>%s\n <td align=right>%d\n <td align=right>%s\n",
- date, totalcnt, btlneck);
- if (bw2 > 1)
- fprintf(fp, " <td align=right>%0.2f Mbps\n", bw2);
- else
- fprintf(fp, " <td align=right>%0.2f kbps\n", bw2*1000);
- if (c2sspd > 1000)
- fprintf(fp, " <td align=right>%0.2f Mbps\n <td align=right>%0.2f Mbps\n",
- (float) c2sspd/1000, (float)s2cspd/1000);
- else
- fprintf(fp, " <td align=right>%d kbps\n <td align=right>%d kbps, ", c2sspd, s2cspd);
- fprintf(fp, " </tr>\n <tr>\n <th>Packet Loss\n <th>Average RTT\n");
- fprintf(fp, " <th>Mininum RTT\n <th>Retrans/sec\n <th>Timeouts/sec\n");
- fprintf(fp, " <th>%% Out-of-Order\n </tr>\n <tr>\n");
- if (loss2 == .000001)
- fprintf(fp, " <td align=right>None\n <td align=right>%0.2f msec\n <td align=right>%d msec\n",
- avgrtt, MinRTT);
- else
- fprintf(fp, " <td align=right>%0.4f%%\n <td align=right>%0.2f msec\n <td align=right>%d msec\n",
- loss2*100, avgrtt, MinRTT);
- fprintf(fp, " <td align=right>%0.2f\n <td align=right>%0.2f\n <td align=right>%0.2f\n </tr>\n",
- (float) PktsRetrans/timesec, (float) Timeouts/timesec, oo_order*100);
- fprintf(fp, " <tr>\n <th>Send Buffer\n <th>BW*Delay\n");
- fprintf(fp, " <th>Receive Buffer\n <th>BW*Delay\n");
- fprintf(fp, " <th>Congestion Window\n <th>BW*Delay\n </tr>\n");
- fprintf(fp, " <tr>\n <td align=right>%d Bytes\n <td align=right>%0.2f Mbps\n", Sndbuf, sendbwd);
- fprintf(fp, " <td align=right>%d Bytes\n <td align=right>%0.2f Mbps\n", MaxRwinRcvd, recvbwd);
- fprintf(fp, " <td align=right>%d Bytes\n <td align=right>%0.2f Mbps\n", CurrentCwnd, cwndbwd);
- fprintf(fp, " </tr>\n</table>\n\n");
-
- fprintf(fp, "<applet code=Admin.class\n width=600 height=400>\n");
- fprintf(fp, " <PARAM NAME=\"Fault\" VALUE=\"%d\">\n", count[0]);
- fprintf(fp, " <PARAM NAME=\"RTT\" VALUE=\"%d\">\n", count[1]);
- fprintf(fp, " <PARAM NAME=\"Dial-up\" VALUE=\"%d\">\n", count[2]);
- fprintf(fp, " <PARAM NAME=\"T1\" VALUE=\"%d\">\n", count[3]);
- fprintf(fp, " <PARAM NAME=\"Enet\" VALUE=\"%d\">\n", count[4]);
- fprintf(fp, " <PARAM NAME=\"T3\" VALUE=\"%d\">\n", count[5]);
- fprintf(fp, " <PARAM NAME=\"FastE\" VALUE=\"%d\">\n", count[6]);
- fprintf(fp, " <PARAM NAME=\"OC-12\" VALUE=\"%d\">\n", count[7]);
- fprintf(fp, " <PARAM NAME=\"GigE\" VALUE=\"%d\">\n", count[8]);
- fprintf(fp, " <PARAM NAME=\"OC-48\" VALUE=\"%d\">\n", count[9]);
- fprintf(fp, " <PARAM NAME=\"tenGE\" VALUE=\"%d\">\n", count[10]);
- fprintf(fp, " <PARAM NAME=\"Total\" VALUE=\"%d\">\n", totalcnt);
- fprintf(fp, "</applet>\n<br>\n");
-
- /* Next generate summary table */
- fprintf(fp, "<table border>\n <tr>\n");
- fprintf(fp, " <th>\n <th>Date/Time\n <th rowspan=5>\n");
- fprintf(fp, " <th colspan=2>Throughput Summary\n <th rowspan=5>\n");
- fprintf(fp, " <th colspan=2>Configuration Fault Summary\n </tr>\n <tr>\n");
- fprintf(fp, " <td><b>Log Starts</b>\n <td align=right>%s\n <th>Client-to-Server\n", startdate);
- fprintf(fp, " <th>Server-to-Client\n <th>Duplex Mismatch\n");
- fprintf(fp, " <th>Excessive Errors\n </tr>\n");
- fprintf(fp, " <tr>\n <td><b>Current</b>\n <td align=right>%s\n", date);
- if (c2sspd > 1000)
- fprintf(fp, " <td align=right>%0.2f Mbps\n <td align=right>%0.2f Mbps\n",
- (float) c2sspd/1000, (float)s2cspd/1000);
- else
- fprintf(fp, " <td align=right>%d kbps\n <td align=right>%d kbps, ", c2sspd, s2cspd);
-
- fprintf(fp, " <td align=right>%s\n <td align=right>%s\n </tr>\n <tr>\n",
- mismatch==1?"Yes":"No", bad_cable==1?"Yes":"No");
- fprintf(fp, " <td><b>Maximum</b>\n <td align=right>%s\n", maxdate);
- if (maxc2sspd > 1000)
- fprintf(fp, " <td align=right>%0.2f Mbps\n <td align=right>%0.2f Mbps\n",
- (float) maxc2sspd/1000, (float)maxs2cspd/1000);
- else
- fprintf(fp, " <td align=right>%d kbps\n <td align=right>%d kbps, ", maxc2sspd, maxs2cspd);
- fprintf(fp, " <td align=right>%d found\n <td align=right>%d found\n </tr>\n",
- totmismatch, totbad_cable);
- fprintf(fp, " <tr>\n <td><b>Minimum</b>\n <td align=right>%s\n", mindate);
- if (minc2sspd > 1000)
- fprintf(fp, " <td align=right>%0.2f Mbps\n <td align=right>%0.2f Mbps\n",
- (float) minc2sspd/1000, (float)mins2cspd/1000);
- else
- fprintf(fp, " <td align=right>%d kbps\n <td align=right>%d kbps\n", minc2sspd, mins2cspd);
- fprintf(fp, " <td>\n <td>\n </tr>\n</table>\n");
-
- fprintf(fp, "<br>\n<hr width=\"100%%\" noShade size=4>\n");
- fprintf(fp, "<table border>\n <tr>\n");
- fprintf(fp, " <th>\n <th>Filename\n <th>Size\n </tr>\n <tr>\n");
- fprintf(fp, " <td><b>Log</b>\n <td> %s <td>\n", get_logfile());
- {
- struct stat fstats;
-
- if (stat(get_logfile(), &fstats) == 0) {
- char* names[] = {"B", "KB", "MB", "GB"};
- int idname;
- double size = fstats.st_size;
- for (idname = 0; idname < 3; ++idname) {
- if (size < 1024) {
- break;
- }
- size /= 1024.0;
- }
- fprintf(fp, "%.2f %s\n", size, names[idname]);
- }
- else {
- fprintf(fp, "???\n");
- }
- }
- fprintf(fp, " </tr>\n</table>\n");
-
- /* now pick up the rest of the descriptive text that goes along with this page.
- * instead of burying all the text in this program, just include it from an external
- * file. For now, use the system command to append the text to the just created file.
- */
- fclose(fp);
- sprintf(tmpstr, "/bin/cat %s/admin_description.html >> %s", BASEDIR, AdminFileName);
- system(tmpstr);
-
- /* Save the current variables into a file for later use. These
- * variables are updated by each child process at the end of every
- * test. This data must be shared between multiple children. If
- * not, then the admin view page doesn't get update after every
- * test.
- */
- fp = fopen("/tmp/view.string", "w");
- if (fp == NULL) {
- return;
- }
- lock.l_type = F_WRLCK;
- i = fcntl((int)fp, F_SETLKW, lock);
- log_println(1, "successfully locked '/tmp/view.string' for updating");
- sprintf(view_string, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%s,%s",
- maxc2sspd, minc2sspd, maxs2cspd, mins2cspd, totalcnt,
- totmismatch, totbad_cable, count[0], count[1], count[2], count[3], count[4],
- count[5], count[6], count[7], count[8], count[9], count[10], count[11],
- count[12], count[13], count[14], count[15], maxdate, mindate);
- log_println(1, "sending '%s' to tmp file", view_string);
- fprintf(fp, "%s\n", view_string);
- lock.l_type = F_UNLCK;
- fcntl((int)fp, F_SETLK, lock);
- fclose(fp);
+void gen_html(int c2sspd, int s2cspd, int MinRTT, int PktsRetrans, int Timeouts,
+ int Sndbuf, int MaxRwinRcvd, int CurrentCwnd, int mismatch,
+ int bad_cable, int totalcnt, int refresh) {
+ FILE * fp;
+ char view_string[256], tmpstr[256];
+ int i;
+ struct flock lock;
+
+ fp = fopen(AdminFileName, "w");
+ if (fp == NULL) {
+ log_println(1, "Cannot open file for the admin web page...");
+ return;
+ }
+ /* generate an HTML page for display. */
+ fprintf(
+ fp,
+ "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\">\n");
+ fprintf(fp, "<html> <head> <title>NDT server Admin Page</title>\n");
+ fprintf(fp,
+ "<meta http-equiv=\"refresh\" content=\"%d;
url="ADMINFILE"\">\n",
+ refresh);
+ fprintf(fp, "<meta http-equiv=\"Content-Language\"
content=\"en\">\n");
+ fprintf(
+ fp,
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
+ fprintf(fp, "</head>\n");
+
+ /* First build current results table */
+ fprintf(fp, "<table border>\n <tr>\n ");
+ fprintf(
+ fp,
+ " <th colspan=8><font size=\"+1\">NDT Usage Statistics -- Current Test Results\n");
+ fprintf(fp, " </font></tr>\n");
+ fprintf(
+ fp,
+ " <tr>\n <th>Date/Time\n <th>Total Tests\n <th
rowspan=6>\n");
+ fprintf(
+ fp,
+ " <th>Bottleneck Link\n <th>Theoritical Limit\n <th rowspan=6>\n");
+ fprintf(fp, " <th>C2S Speed\n <th>S2C Speed\n </tr>\n");
+ fprintf(
+ fp,
+ " <tr>\n <td align=right>%s\n <td align=right>%d\n <td align=right>%s\n",
+ date, totalcnt, btlneck);
+ if (bw2 > 1)
+ fprintf(fp, " <td align=right>%0.2f Mbps\n", bw2);
+ else
+ fprintf(fp, " <td align=right>%0.2f kbps\n", bw2 * 1000);
+ if (c2sspd > 1000)
+ fprintf(
+ fp,
+ " <td align=right>%0.2f Mbps\n <td
align=right>%0.2f Mbps\n",
+ (float) c2sspd / 1000, (float) s2cspd / 1000);
+ else
+ fprintf(fp,
+ " <td align=right>%d kbps\n <td
align=right>%d kbps, ",
+ c2sspd, s2cspd);
+ fprintf(fp, " </tr>\n <tr>\n <th>Packet Loss\n <th>Average RTT\n");
+ fprintf(fp,
+ " <th>Mininum RTT\n <th>Retrans/sec\n
<th>Timeouts/sec\n");
+ fprintf(fp, " <th>%% Out-of-Order\n </tr>\n <tr>\n");
+ if (loss2 == .000001)
+ fprintf(
+ fp,
+ " <td align=right>None\n <td align=right>%0.2f msec\n <td align=right>%d msec\n",
+ avgrtt, MinRTT);
+ else
+ fprintf(
+ fp,
+ " <td align=right>%0.4f%%\n <td align=right>%0.2f msec\n <td align=right>%d msec\n",
+ loss2 * 100, avgrtt, MinRTT);
+ fprintf(
+ fp,
+ " <td align=right>%0.2f\n <td align=right>%0.2f\n <td align=right>%0.2f\n </tr>\n",
+ (float) PktsRetrans / timesec, (float) Timeouts /
timesec,
+ oo_order * 100);
+ fprintf(fp, " <tr>\n <th>Send Buffer\n <th>BW*Delay\n");
+ fprintf(fp, " <th>Receive Buffer\n <th>BW*Delay\n");
+ fprintf(fp, " <th>Congestion Window\n <th>BW*Delay\n </tr>\n");
+ fprintf(
+ fp,
+ " <tr>\n <td align=right>%d Bytes\n <td align=right>%0.2f Mbps\n",
+ Sndbuf, sendbwd);
+ fprintf(fp,
+ " <td align=right>%d Bytes\n <td align=right>%0.2f
Mbps\n",
+ MaxRwinRcvd, recvbwd);
+ fprintf(fp,
+ " <td align=right>%d Bytes\n <td align=right>%0.2f
Mbps\n",
+ CurrentCwnd, cwndbwd);
+ fprintf(fp, " </tr>\n</table>\n\n");
+
+ fprintf(fp, "<applet code=Admin.class\n width=600 height=400>\n");
+ fprintf(fp, " <PARAM NAME=\"Fault\" VALUE=\"%d\">\n", count[0]);
+ fprintf(fp, " <PARAM NAME=\"RTT\" VALUE=\"%d\">\n", count[1]);
+ fprintf(fp, " <PARAM NAME=\"Dial-up\" VALUE=\"%d\">\n", count[2]);
+ fprintf(fp, " <PARAM NAME=\"T1\" VALUE=\"%d\">\n", count[3]);
+ fprintf(fp, " <PARAM NAME=\"Enet\" VALUE=\"%d\">\n", count[4]);
+ fprintf(fp, " <PARAM NAME=\"T3\" VALUE=\"%d\">\n", count[5]);
+ fprintf(fp, " <PARAM NAME=\"FastE\" VALUE=\"%d\">\n", count[6]);
+ fprintf(fp, " <PARAM NAME=\"OC-12\" VALUE=\"%d\">\n", count[7]);
+ fprintf(fp, " <PARAM NAME=\"GigE\" VALUE=\"%d\">\n", count[8]);
+ fprintf(fp, " <PARAM NAME=\"OC-48\" VALUE=\"%d\">\n", count[9]);
+ fprintf(fp, " <PARAM NAME=\"tenGE\" VALUE=\"%d\">\n", count[10]);
+ fprintf(fp, " <PARAM NAME=\"Total\" VALUE=\"%d\">\n", totalcnt);
+ fprintf(fp, "</applet>\n<br>\n");
+
+ /* Next generate summary table */
+ fprintf(fp, "<table border>\n <tr>\n");
+ fprintf(fp, " <th>\n <th>Date/Time\n <th rowspan=5>\n");
+ fprintf(fp, " <th colspan=2>Throughput Summary\n <th
rowspan=5>\n");
+ fprintf(fp,
+ " <th colspan=2>Configuration Fault Summary\n </tr>\n
<tr>\n");
+ fprintf(
+ fp,
+ " <td><b>Log Starts</b>\n <td align=right>%s\n <th>Client-to-Server\n",
+ startdate);
+ fprintf(fp, " <th>Server-to-Client\n <th>Duplex Mismatch\n");
+ fprintf(fp, " <th>Excessive Errors\n </tr>\n");
+ fprintf(fp, " <tr>\n <td><b>Current</b>\n <td
align=right>%s\n",
+ date);
+ if (c2sspd > 1000)
+ fprintf(
+ fp,
+ " <td align=right>%0.2f Mbps\n <td
align=right>%0.2f Mbps\n",
+ (float) c2sspd / 1000, (float) s2cspd / 1000);
+ else
+ fprintf(fp,
+ " <td align=right>%d kbps\n <td
align=right>%d kbps, ",
+ c2sspd, s2cspd);
+
+ fprintf(fp,
+ " <td align=right>%s\n <td align=right>%s\n </tr>\n
<tr>\n",
+ mismatch == 1 ? "Yes" : "No", bad_cable == 1 ? "Yes" :
"No");
+ fprintf(fp, " <td><b>Maximum</b>\n <td align=right>%s\n",
maxdate);
+ if (maxc2sspd > 1000)
+ fprintf(
+ fp,
+ " <td align=right>%0.2f Mbps\n <td
align=right>%0.2f Mbps\n",
+ (float) maxc2sspd / 1000, (float) maxs2cspd /
1000);
+ else
+ fprintf(fp,
+ " <td align=right>%d kbps\n <td
align=right>%d kbps, ",
+ maxc2sspd, maxs2cspd);
+ fprintf(
+ fp,
+ " <td align=right>%d found\n <td align=right>%d found\n
</tr>\n",
+ totmismatch, totbad_cable);
+ fprintf(fp, " <tr>\n <td><b>Minimum</b>\n <td
align=right>%s\n",
+ mindate);
+ if (minc2sspd > 1000)
+ fprintf(
+ fp,
+ " <td align=right>%0.2f Mbps\n <td
align=right>%0.2f Mbps\n",
+ (float) minc2sspd / 1000, (float) mins2cspd /
1000);
+ else
+ fprintf(fp,
+ " <td align=right>%d kbps\n <td
align=right>%d kbps\n",
+ minc2sspd, mins2cspd);
+ fprintf(fp, " <td>\n <td>\n </tr>\n</table>\n");
+
+ fprintf(fp, "<br>\n<hr width=\"100%%\" noShade size=4>\n");
+ fprintf(fp, "<table border>\n <tr>\n");
+ fprintf(fp, " <th>\n <th>Filename\n <th>Size\n </tr>\n <tr>\n");
+ fprintf(fp, " <td><b>Log</b>\n <td> %s <td>\n",
get_logfile());
+ {
+ struct stat fstats;
+
+ if (stat(get_logfile(), &fstats) == 0) {
+ char* names[] = { "B", "KB", "MB", "GB" };
+ int idname;
+ double size = fstats.st_size;
+ for (idname = 0; idname < 3; ++idname) {
+ if (size < 1024) {
+ break;
+ }
+ size /= 1024.0;
+ }
+ fprintf(fp, "%.2f %s\n", size, names[idname]);
+ } else {
+ fprintf(fp, "???\n");
+ }
+ }
+ fprintf(fp, " </tr>\n</table>\n");
+
+ /* now pick up the rest of the descriptive text that goes along with this page.
+ * instead of burying all the text in this program, just include it from an external
+ * file. For now, use the system command to append the text to the just created file.
+ */
+ fclose(fp);
+ sprintf(tmpstr, "/bin/cat %s/admin_description.html >> %s", BASEDIR,
+ AdminFileName);
+ system(tmpstr);
+
+ /* Save the current variables into a file for later use. These
+ * variables are updated by each child process at the end of every
+ * test. This data must be shared between multiple children. If
+ * not, then the admin view page doesn't get update after every
+ * test.
+ */
+ fp = fopen("/tmp/view.string", "w");
+ if (fp == NULL) {
+ return;
+ }
+ lock.l_type = F_WRLCK;
+ i = fcntl((int) fp, F_SETLKW, lock);
+ log_println(1, "successfully locked '/tmp/view.string' for updating");
+ sprintf(
+ view_string,
+ "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%s,%s",
+ maxc2sspd, minc2sspd, maxs2cspd, mins2cspd, totalcnt,
totmismatch,
+ totbad_cable, count[0], count[1], count[2], count[3],
count[4],
+ count[5], count[6], count[7], count[8], count[9],
count[10],
+ count[11], count[12], count[13], count[14],
count[15], maxdate,
+ mindate);
+ log_println(1, "sending '%s' to tmp file", view_string);
+ fprintf(fp, "%s\n", view_string);
+ lock.l_type = F_UNLCK;
+ fcntl((int) fp, F_SETLK, lock);
+ fclose(fp);
}

-void
-view_init(int refresh)
-{
- int Timeouts = 0, SumRTT, CountRTT, MinRTT = 0, PktsRetrans = 0, FastRetran, DataPktsOut;
- int AckPktsOut, CurrentMSS, DupAcksIn, AckPktsIn, MaxRwinRcvd = 0, Sndbuf = 0;
- int CurrentCwnd = 0, SndLimTimeRwin, SndLimTimeCwnd, SndLimTimeSender, DataBytesOut;
- int SndLimTransRwin, SndLimTransCwnd, SndLimTransSender, MaxSsthresh;
- int CurrentRTO, CurrentRwinRcvd, CongestionSignals, PktsOut = 0;
- FILE *fp;
- int c2sspd = 0, s2cspd = 0;
- char ip_addr2[64], buff[512], *str, tmpstr[32];
- int link=0, mismatch=0, bad_cable=0, half_duplex=0, congestion=0;
- int c2sdata = 0, c2sack, s2cdata, s2cack = 0;
- int totalcnt=0, view_flag=0;
-
- if ((fp = fopen(get_logfile(), "r")) == NULL)
- return;
-
- while ((fgets(buff, 512, fp)) != NULL) {
- if ((str = strchr(buff, ',')) != NULL) {
- sscanf(buff, "%[^,]s", date);
- str++;
- sscanf(str, "%[^,]s", ip_addr2);
- if ((str = strchr(str, ',')) == NULL)
- continue;
- /* skip over s2c cwnd-limited speed value */
- str++;
- sscanf(str, "%[^,]s", tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- c2sspd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- s2cspd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- Timeouts = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- SumRTT = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- CountRTT = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- PktsRetrans = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- FastRetran = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- DataPktsOut = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- AckPktsOut = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- CurrentMSS = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- DupAcksIn = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- AckPktsIn = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- MaxRwinRcvd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- Sndbuf = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- CurrentCwnd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- SndLimTimeRwin = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
- SndLimTimeCwnd = atoi(tmpstr);
-
- str = strchr(str, ',') +1;
- sscanf(str, "%[^,]s", tmpstr);
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/web100-admin.h Fri Aug 18 03:16:24 2006
+++ /branches/kkumar_code_organize/src/web100-admin.h Mon Oct 17 06:43:25 2011
@@ -13,12 +13,14 @@
#define ADMINFILE "admin.html"

void view_init(int refresh);
-int calculate(char now[32], int SumRTT, int CountRTT, int CongestionSignals, int PktsOut,
- int DupAcksIn, int AckPktsIn, int CurrentMSS, int SndLimTimeRwin,
- int SndLimTimeCwnd, int SndLimTimeSender, int MaxRwinRcvd, int CurrentCwnd,
- int Sndbuf, int DataBytesOut, int mismatch, int bad_cable, int c2sspd, int s2cspd,
- int c2sdata, int s2cack, int view_flag);
-void gen_html(int c2sspd, int s2cspd, int MinRTT, int PktsRetrans, int Timeouts, int Sndbuf,
- int MaxRwinRcvd, int CurrentCwnd, int mismatch, int bad_cable, int totalcnt, int refresh);
+int calculate(char now[32], int SumRTT, int CountRTT, int CongestionSignals,
+ int PktsOut, int DupAcksIn, int AckPktsIn, int CurrentMSS,
+ int SndLimTimeRwin, int SndLimTimeCwnd, int SndLimTimeSender,
+ int MaxRwinRcvd, int CurrentCwnd, int Sndbuf, int
DataBytesOut,
+ int mismatch, int bad_cable, int c2sspd, int s2cspd, int
c2sdata,
+ int s2cack, int view_flag);
+void gen_html(int c2sspd, int s2cspd, int MinRTT, int PktsRetrans, int Timeouts,
+ int Sndbuf, int MaxRwinRcvd, int CurrentCwnd, int mismatch,
+ int bad_cable, int totalcnt, int refresh);

#endif
=======================================
--- /branches/kkumar_code_organize/src/web100-pcap.c Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/web100-pcap.c Mon Oct 17 06:43:25 2011
@@ -26,157 +26,162 @@
pcap_dumper_t *pdump;
int mon_pipe1[2], mon_pipe2[2];
/* int sig1, sig2; */
-int sigj=0, sigk=0;
+int sigj = 0, sigk = 0;
int ifspeed;

-void get_iflist(void)
-{
- /* pcap_addr_t *ifaceAddr; */
- pcap_if_t *alldevs, *dp;
- struct ethtool_cmd ecmd;
- int fd, cnt, i, err;
- struct ifreq ifr;
- char errbuf[256];
-
- /* scan through the interface device list and get the names/speeds of each
- * * if. The speed data can be used to cap the search for the bottleneck link
- * * capacity. The intent is to reduce the impact of interrupt coalescing on
- * * the bottleneck link detection algorithm
- * * RAC 7/14/09
- * */
- cnt=0;
- if (pcap_findalldevs(&alldevs, errbuf) == 0) {
- for (dp=alldevs; dp!=NULL; dp=dp->next) {
- memcpy(iflist.name[cnt++], dp->name, strlen(dp->name));
- }
- }
- for (i=0; i<cnt; i++) {
- if (strncmp((char *)iflist.name[i], "eth", 3) != 0)
- continue;
- memset(&ifr, 0, sizeof(ifr));
- memcpy(ifr.ifr_name, (char *)iflist.name[i], strlen(iflist.name[i]));
- /* strcpy(ifr.ifr_name, iflist.name[i]); */
- fd = socket(AF_INET, SOCK_DGRAM, 0);
- ecmd.cmd = ETHTOOL_GSET;
- ifr.ifr_data = (caddr_t) &ecmd;
- err = ioctl(fd, SIOCETHTOOL, &ifr);
- if (err == 0) {
- switch (ecmd.speed) {
- case SPEED_10:
- iflist.speed[i] = 3;
- break;
- case SPEED_100:
- iflist.speed[i] = 5;
- break;
- case SPEED_1000:
- iflist.speed[i] = 7;
- break;
- case SPEED_10000:
- iflist.speed[i] = 9;
- break;
- default :
- iflist.speed[i] = 0;
- }
- }
- }
- if (alldevs != NULL)
- pcap_freealldevs(alldevs);
+void get_iflist(void) {
+ /* pcap_addr_t *ifaceAddr; */
+ pcap_if_t *alldevs, *dp;
+ struct ethtool_cmd ecmd;
+ int fd, cnt, i, err;
+ struct ifreq ifr;
+ char errbuf[256];
+
+ /* scan through the interface device list and get the names/speeds of
each
+ * * if. The speed data can be used to cap the search for the bottleneck link
+ * * capacity. The intent is to reduce the impact of interrupt coalescing on
+ * * the bottleneck link detection algorithm
+ * * RAC 7/14/09
+ * */
+ cnt = 0;
+ if (pcap_findalldevs(&alldevs, errbuf) == 0) {
+ for (dp = alldevs; dp != NULL; dp = dp->next) {
+ memcpy(iflist.name[cnt++], dp->name,
strlen(dp->name));
+ }
+ }
+ for (i = 0; i < cnt; i++) {
+ if (strncmp((char *) iflist.name[i], "eth", 3) != 0)
+ continue;
+ memset(&ifr, 0, sizeof(ifr));
+ memcpy(ifr.ifr_name, (char *) iflist.name[i],
strlen(iflist.name[i]));
+ /* strcpy(ifr.ifr_name, iflist.name[i]); */
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ ecmd.cmd = ETHTOOL_GSET;
+ ifr.ifr_data = (caddr_t) & ecmd;
+ err = ioctl(fd, SIOCETHTOOL, &ifr);
+ if (err == 0) {
+ switch (ecmd.speed) {
+ case SPEED_10:
+ iflist.speed[i] = 3;
+ break;
+ case SPEED_100:
+ iflist.speed[i] = 5;
+ break;
+ case SPEED_1000:
+ iflist.speed[i] = 7;
+ break;
+ case SPEED_10000:
+ iflist.speed[i] = 9;
+ break;
+ default:
+ iflist.speed[i] = 0;
+ }
+ }
+ }
+ if (alldevs != NULL)
+ pcap_freealldevs(alldevs);
}

-
-int
-check_signal_flags()
-{
- if ((sig1 == 1) || (sig2 == 1)) {
- log_println(5, "Received SIGUSRx signal terminating data collection loop for pid=%d", getpid());
- if (sig1 == 1) {
- log_println(4, "Sending pkt-pair data back to parent on pipe %d, %d", mon_pipe1[0], mon_pipe1[1]);
- if (get_debuglvl() > 3) {
+int check_signal_flags() {
+ if ((sig1 == 1) || (sig2 == 1)) {
+ log_println(
+ 5,
+ "Received SIGUSRx signal terminating data
collection loop for pid=%d",
+ getpid());
+ if (sig1 == 1) {
+ log_println(4,
+ "Sending pkt-pair data back to parent on
pipe %d, %d",
+ mon_pipe1[0], mon_pipe1[1]);
+ if (get_debuglvl() > 3) {
#ifdef AF_INET6
- if (fwd.family == 4) {
- fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
- fwd.saddr[0], fwd.sport, rev.saddr[0], rev.sport);
+ if (fwd.family == 4) {
+ fprintf(stderr, "fwd.saddr = %x:%d,
rev.saddr = %x:%d\n",
+ fwd.saddr[0],
fwd.sport, rev.saddr[0], rev.sport);
#else
- fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
- fwd.saddr, fwd.sport, rev.saddr, rev.sport);
+ fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr =
%x:%d\n",
+ fwd.saddr, fwd.sport,
rev.saddr, rev.sport);
#endif
#ifdef AF_INET6
- }
- else if (fwd.family == 6) {
- char str[136];
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) fwd.saddr, str, sizeof(str));
- fprintf(stderr, "fwd.saddr = %s:%d", str, fwd.sport);
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) rev.saddr, str, sizeof(str));
- fprintf(stderr, ", rev.saddr = %s:%d\n", str, rev.sport);
- }
- else {
- fprintf(stderr, "check_signal_flags: Unknown IP family (%d)\n", fwd.family);
- }
+ }
+ else if (fwd.family == 6) {
+ char str[136];
+ memset(str, 0, 136);
+ inet_ntop(AF_INET6, (void *) fwd.saddr, str,
sizeof(str));
+ fprintf(stderr, "fwd.saddr = %s:%d", str,
fwd.sport);
+ memset(str, 0, 136);
+ inet_ntop(AF_INET6, (void *) rev.saddr, str,
sizeof(str));
+ fprintf(stderr, ", rev.saddr = %s:%d\n", str,
rev.sport);
+ }
+ else {
+ fprintf(stderr, "check_signal_flags: Unknown IP family (%d)\n", fwd.family);
+ }
#endif
- }
- print_bins(&fwd, mon_pipe1);
- usleep(30000); /* wait here 30 msec, for parent to read this data */
- print_bins(&rev, mon_pipe1);
- usleep(30000); /* wait here 30 msec, for parent to read this data */
- if (pd != NULL)
- pcap_close(pd);
- if (dumptrace == 1)
- pcap_dump_close(pdump);
- sig1 = 2;
- }
-
- if (sig2 == 1) {
- log_println(4, "Sending pkt-pair data back to parent on pipe %d, %d", mon_pipe2[0], mon_pipe2[1]);
- if (get_debuglvl() > 3) {
+ }
+ print_bins(&fwd, mon_pipe1);
+ usleep(30000); /* wait here 30 msec, for parent to
read this data */
+ print_bins(&rev, mon_pipe1);
+ usleep(30000); /* wait here 30 msec, for parent to
read this data */
+ if (pd != NULL)
+ pcap_close(pd);
+ if (dumptrace == 1)
+ pcap_dump_close(pdump);
+ sig1 = 2;
+ }
+
+ if (sig2 == 1) {
+ log_println(4,
+ "Sending pkt-pair data back to parent on
pipe %d, %d",
+ mon_pipe2[0], mon_pipe2[1]);
+ if (get_debuglvl() > 3) {
#ifdef AF_INET6
- if (fwd.family == 4) {
- fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
- fwd.saddr[0], fwd.sport, rev.saddr[0], rev.sport);
+ if (fwd.family == 4) {
+ fprintf(stderr, "fwd.saddr = %x:%d,
rev.saddr = %x:%d\n",
+ fwd.saddr[0],
fwd.sport, rev.saddr[0], rev.sport);
#else
- fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
- fwd.saddr, fwd.sport, rev.saddr, rev.sport);
+ fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr =
%x:%d\n",
+ fwd.saddr, fwd.sport,
rev.saddr, rev.sport);
#endif
#ifdef AF_INET6
- }
- else if (fwd.family == 6) {
- char str[136];
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) fwd.saddr, str, sizeof(str));
- fprintf(stderr, "fwd.saddr = %s:%d", str, fwd.sport);
- memset(str, 0, 136);
- inet_ntop(AF_INET6, (void *) rev.saddr, str, sizeof(str));
- fprintf(stderr, ", rev.saddr = %s:%d\n", str, rev.sport);
- }
- else {
- fprintf(stderr, "check_signal_flags: Unknown IP family (%d)\n", fwd.family);
- }
+ }
+ else if (fwd.family == 6) {
+ char str[136];
+ memset(str, 0, 136);
+ inet_ntop(AF_INET6, (void *) fwd.saddr, str,
sizeof(str));
+ fprintf(stderr, "fwd.saddr = %s:%d", str,
fwd.sport);
+ memset(str, 0, 136);
+ inet_ntop(AF_INET6, (void *) rev.saddr, str,
sizeof(str));
+ fprintf(stderr, ", rev.saddr = %s:%d\n", str,
rev.sport);
+ }
+ else {
+ fprintf(stderr, "check_signal_flags: Unknown IP family (%d)\n", fwd.family);
+ }
#endif
- }
- print_bins(&fwd, mon_pipe2);
- usleep(30000); /* wait here 30 msec, for parent to read this data */
- print_bins(&rev, mon_pipe2);
- usleep(30000); /* wait here 30 msec, for parent to read this data */
- if (pd != NULL)
- pcap_close(pd);
- if (dumptrace == 1)
- pcap_dump_close(pdump);
- sig2 = 2;
- }
- log_println(6, "Finished reading pkt-pair data from network, process %d should terminate now", getpid());
- return 1;
- }
- return 0;
+ }
+ print_bins(&fwd, mon_pipe2);
+ usleep(30000); /* wait here 30 msec, for parent to
read this data */
+ print_bins(&rev, mon_pipe2);
+ usleep(30000); /* wait here 30 msec, for parent to
read this data */
+ if (pd != NULL)
+ pcap_close(pd);
+ if (dumptrace == 1)
+ pcap_dump_close(pdump);
+ sig2 = 2;
+ }
+ log_println(
+ 6,
+ "Finished reading pkt-pair data from network, process %d should terminate now",
+ getpid());
+ return 1;
+ }
+ return 0;
}

/* initialize variables before starting to accumlate data */
-void init_vars(struct spdpair *cur)
-{
+void init_vars(struct spdpair *cur) {

int i;

- assert(cur);
+ assert(cur);

#if defined(AF_INET6)
memset(cur->saddr, 0, 4);
@@ -195,225 +200,255 @@
cur->time = 0;
cur->totalspd = 0;
cur->totalcount = 0;
- for (i=0; i<16; i++)
- cur->links[i] = 0;
-}
-
+ for (i = 0; i < 16; i++)
+ cur->links[i] = 0;
+}

/* This routine prints results to the screen. */
-void print_bins(struct spdpair *cur, int monitor_pipe[2])
-{
-
- int i, total=0, max=0, s, index = -1;
+void print_bins(struct spdpair *cur, int monitor_pipe[2]) {
+
+ int i, total = 0, max = 0, s, index = -1;
char buff[256];
int tzoffset = 6;
- FILE *fp;
+ FILE * fp;
int j;

- assert(cur);
+ assert(cur);

/* the tzoffset value is fixed for CST (6), use 5 for CDT. The code needs to find the
* current timezone and use that value here! */
- s = (cur->st_sec - (tzoffset * 3600)) %86400;
+ s = (cur->st_sec - (tzoffset * 3600)) % 86400;
fp = fopen(get_logfile(), "a");
- log_print(1, "%02d:%02d:%02d.%06u ", s / 3600, (s % 3600) / 60, s % 60, cur->st_usec);
-
- for (i=0; i<16; i++) {
- total += cur->links[i];
- if (cur->links[i] > max) {
- max = cur->links[i];
- }
+ log_print(1, "%02d:%02d:%02d.%06u ", s / 3600, (s % 3600) / 60, s %
60,
+ cur->st_usec);
+
+ for (i = 0; i < 16; i++) {
+ total += cur->links[i];
+ if (cur->links[i] > max) {
+ max = cur->links[i];
+ }
}
if (get_debuglvl() > 2) {
#ifdef AF_INET6
- if (cur->family == 4) {
- if (fp) {
- fprintf(fp, "%u.%u.%u.%u:%d --> ", (cur->saddr[0] & 0xFF), ((cur->saddr[0] >> 8) & 0xff),
- ((cur->saddr[0] >> 16) & 0xff), (cur->saddr[0] >> 24), cur->sport);
- fprintf(fp, "%u.%u.%u.%u:%d ", (cur->daddr[0] & 0xFF), ((cur->daddr[0] >> 8) & 0xff),
- ((cur->daddr[0] >> 16) & 0xff), (cur->daddr[0] >> 24), cur->dport);
- }
- log_print(3, "%u.%u.%u.%u:%d --> ", (cur->saddr[0] & 0xFF), ((cur->saddr[0] >> 8) & 0xff),
- ((cur->saddr[0] >> 16) & 0xff), (cur->saddr[0] >> 24), cur->sport);
- log_print(3, "%u.%u.%u.%u:%d ", (cur->daddr[0] & 0xFF), ((cur->daddr[0] >> 8) & 0xff),
- ((cur->daddr[0] >> 16) & 0xff), (cur->daddr[0] >> 24), cur->dport);
- }
+ if (cur->family == 4) {
+ if (fp) {
+ fprintf(fp, "%u.%u.%u.%u:%d --> ", (cur->saddr[0] & 0xFF), ((cur->saddr[0] >> 8) & 0xff),
+ ((cur->saddr[0] >> 16) & 0xff),
(cur->saddr[0] >> 24), cur->sport);
+ fprintf(fp, "%u.%u.%u.%u:%d ", (cur->daddr[0] & 0xFF), ((cur->daddr[0] >> 8) & 0xff),
+ ((cur->daddr[0] >> 16) & 0xff),
(cur->daddr[0] >> 24), cur->dport);
+ }
+ log_print(3, "%u.%u.%u.%u:%d --> ", (cur->saddr[0] & 0xFF), ((cur->saddr[0] >> 8) & 0xff),
+ ((cur->saddr[0] >> 16) & 0xff), (cur->saddr[0]
>> 24), cur->sport);
+ log_print(3, "%u.%u.%u.%u:%d ", (cur->daddr[0] & 0xFF), ((cur->daddr[0]
8) & 0xff),
+ ((cur->daddr[0] >> 16) & 0xff), (cur->daddr[0]
>> 24), cur->dport);
+ }
#else
- if (fp) {
- fprintf(fp, "%u.%u.%u.%u:%d --> ", (cur->saddr & 0xFF), ((cur->saddr
8) & 0xff),
- ((cur->saddr >> 16) & 0xff), (cur->saddr >> 24), cur->sport);
- fprintf(fp, "%u.%u.%u.%u:%d ", (cur->daddr & 0xFF), ((cur->daddr >> 8) & 0xff),
+ if (fp) {
+ fprintf(
+ fp,
+ "%u.%u.%u.%u:%d --> ",
+ (cur->saddr & 0xFF), ((cur->saddr >> 8)
& 0xff),
+ ((cur->saddr >> 16) & 0xff), (cur->saddr
>> 24), cur->sport);
+ fprintf(fp, "%u.%u.%u.%u:%d ", (cur->daddr & 0xFF), ((cur->daddr >> 8) & 0xff),
((cur->daddr >> 16) & 0xff), (cur->daddr >> 24), cur->dport);
}
- log_print(3, "%u.%u.%u.%u:%d --> ", (cur->saddr & 0xFF), ((cur->saddr
8) & 0xff),
- ((cur->saddr >> 16) & 0xff), (cur->saddr >> 24), cur->sport);
- log_print(3, "%u.%u.%u.%u:%d ", (cur->daddr & 0xFF), ((cur->daddr >> 8) & 0xff),
- ((cur->daddr >> 16) & 0xff), (cur->daddr >> 24), cur->dport);
+ log_print(3, "%u.%u.%u.%u:%d --> ", (cur->saddr & 0xFF), ((cur->saddr
8) & 0xff),
+ ((cur->saddr >> 16) & 0xff), (cur->saddr
>> 24), cur->sport);
+ log_print(3, "%u.%u.%u.%u:%d ", (cur->daddr & 0xFF), ((cur->daddr >> 8) & 0xff),
+ ((cur->daddr >> 16) & 0xff), (cur->daddr
>> 24), cur->dport);
#endif
#ifdef AF_INET6
- else {
- char name[200];
- socklen_t len;
- memset(name, 0, 200);
- len = 199;
- inet_ntop(AF_INET6, cur->saddr, name, len);
- if (fp) {
- fprintf(fp, "%s:%d --> ", name, cur->sport);
- }
- log_print(3, "%s:%d --> ", name, cur->sport);
- memset(name, 0, 200);
- len = 199;
- inet_ntop(AF_INET6, cur->daddr, name, len);
- if (fp) {
- fprintf(fp, "%s:%d ", name, cur->dport);
- }
- log_print(3, "%s:%d ", name, cur->dport);
- }
+ else {
+ char name[200];
+ socklen_t len;
+ memset(name, 0, 200);
+ len = 199;
+ inet_ntop(AF_INET6, cur->saddr, name, len);
+ if (fp) {
+ fprintf(fp, "%s:%d --> ", name,
cur->sport);
+ }
+ log_print(3, "%s:%d --> ", name, cur->sport);
+ memset(name, 0, 200);
+ len = 199;
+ inet_ntop(AF_INET6, cur->daddr, name, len);
+ if (fp) {
+ fprintf(fp, "%s:%d ", name,
cur->dport);
+ }
+ log_print(3, "%s:%d ", name, cur->dport);
+ }
#endif
- }
- if (max == 0) {
- log_println(3, "No data Packets collected");
- if (get_debuglvl() > 2) {
- if (fp) {
- fprintf(fp, "\n\tNo packets collected\n");
- }
- }
- for (i=0; i<16; i++)
- cur->links[i] = -1;
- index = -1;
- }
- log_println(3, "Collected pkt-pair data max = %d", max);
+ }
+ if (max == 0) {
+ log_println(3, "No data Packets collected");
+ if (get_debuglvl() > 2) {
+ if (fp) {
+ fprintf(fp, "\n\tNo packets collected\n");
+ }
+ }
+ for (i = 0; i < 16; i++)
+ cur->links[i] = -1;
+ index = -1;
+ }
+ log_println(3, "Collected pkt-pair data max = %d", max);
if (max == cur->links[8]) {
- max = 0;
- for (i=0; i<10; i++) {
- if (max < cur->links[i]) {
- index = i;
- max = cur->links[i];
- }
- }
- }
- if (fp) {
- if (get_debuglvl() > 2) {
- switch (index) {
- case -1: fprintf(fp, "link=System Fault; ");
- break;
- case 0: fprintf(fp, "link=RTT; ");
- break;
- case 1: fprintf(fp, "link=dial-up; ");
- break;
- case 2: fprintf(fp, "link=T1; ");
- break;
- case 3: fprintf(fp, "link=Enet; ");
- break;
- case 4: fprintf(fp, "link=T3; ");
- break;
- case 5: fprintf(fp, "link=FastE; ");
- break;
- case 6: fprintf(fp, "link=OC-12; ");
- break;
- case 7: fprintf(fp, "link=GigE; ");
- break;
- case 8: fprintf(fp, "link=OC-48; ");
- break;
- case 9: fprintf(fp, "link=10 GigE; ");
- break;
- case 10: fprintf(fp, "retransmission; ");
- break;
- case 11: fprintf(fp, "link=unknown; ");
- break;
- }
-
- fprintf(fp, "packets=%d\n", total);
- fprintf(fp, "Running Average = %0.2f Mbps ", cur->totalspd2);
- fprintf(fp, "Average speed = %0.2f Mbps\n", cur->totalspd/cur->totalcount);
- fprintf(fp, "\tT1=%d (%0.2f%%); ", cur->links[2], ((float) cur->links[2]*100/total));
- fprintf(fp, "Ethernet=%d (%0.2f%%); ", cur->links[3], ((float) cur->links[3]*100/total));
- fprintf(fp, "T3=%d (%0.2f%%); ", cur->links[4], ((float) cur->links[4]*100/total));
- fprintf(fp, "FastEthernet=%d (%0.2f%%);\n", cur->links[5], ((float) cur->links[5]*100/total));
- fprintf(fp, "OC-12=%d (%0.2f%%); ", cur->links[6], ((float) cur->links[6]*100/total));
- fprintf(fp, "\tGigabit Ethernet=%d (%0.2f%%); ", cur->links[7], ((float) cur->links[7]*100/total));
- fprintf(fp, "OC-48=%d (%0.2f%%); ", cur->links[8], ((float) cur->links[8]*100/total));
- fprintf(fp, "10 Gigabit Enet=%d (%0.2f%%);\n", cur->links[9], ((float) cur->links[9]*100/total));
- fprintf(fp, "\tRetransmissions=%d (%0.2f%%); ", cur->links[10], ((float) cur->links[10]*100/total));
- fprintf(fp, "Unknown=%d (%0.2f%%);\n", cur->links[11], ((float) cur->links[11]*100/total));
- }
- fclose(fp);
- }
-
- sprintf(buff, " %d %d %d %d %d %d %d %d %d %d %d %d %0.2f %d %d %d %d %d %d",
- cur->links[0], cur->links[1], cur->links[2], cur->links[3], cur->links[4],
- cur->links[5], cur->links[6], cur->links[7], cur->links[8], cur->links[9],
- cur->links[10], cur->links[11], cur->totalspd2, cur->inc_cnt, cur->dec_cnt,
- cur->same_cnt, cur->timeout, cur->dupack, ifspeed);
- for (j=0; j<5; j++) {
- i = write(monitor_pipe[1], buff, strlen(buff));
- if (i == strlen(buff))
- break;
- if ((i == -1) && (errno == EINTR))
- continue;
- }
- log_println(6, "wrote %d bytes: link counters are '%s'", i, buff);
- log_println(6, "#$#$#$#$ pcap routine says window increases = %d, decreases = %d, no change = %d",
- cur->inc_cnt, cur->dec_cnt, cur->same_cnt);
+ max = 0;
+ for (i = 0; i < 10; i++) {
+ if (max < cur->links[i]) {
+ index = i;
+ max = cur->links[i];
+ }
+ }
+ }
+ if (fp) {
+ if (get_debuglvl() > 2) {
+ switch (index) {
+ case -1:
+ fprintf(fp, "link=System Fault; ");
+ break;
+ case 0:
+ fprintf(fp, "link=RTT; ");
+ break;
+ case 1:
+ fprintf(fp, "link=dial-up; ");
+ break;
+ case 2:
+ fprintf(fp, "link=T1; ");
+ break;
+ case 3:
+ fprintf(fp, "link=Enet; ");
+ break;
+ case 4:
+ fprintf(fp, "link=T3; ");
+ break;
+ case 5:
+ fprintf(fp, "link=FastE; ");
+ break;
+ case 6:
+ fprintf(fp, "link=OC-12; ");
+ break;
+ case 7:
+ fprintf(fp, "link=GigE; ");
+ break;
+ case 8:
+ fprintf(fp, "link=OC-48; ");
+ break;
+ case 9:
+ fprintf(fp, "link=10 GigE; ");
+ break;
+ case 10:
+ fprintf(fp, "retransmission; ");
+ break;
+ case 11:
+ fprintf(fp, "link=unknown; ");
+ break;
+ }
+
+ fprintf(fp, "packets=%d\n", total);
+ fprintf(fp, "Running Average = %0.2f Mbps ",
cur->totalspd2);
+ fprintf(fp, "Average speed = %0.2f Mbps\n",
+ cur->totalspd / cur->totalcount);
+ fprintf(fp, "\tT1=%d (%0.2f%%); ", cur->links[2],
+ ((float) cur->links[2] * 100 /
total));
+ fprintf(fp, "Ethernet=%d (%0.2f%%); ", cur->links[3],
+ ((float) cur->links[3] * 100 /
total));
+ fprintf(fp, "T3=%d (%0.2f%%); ", cur->links[4],
+ ((float) cur->links[4] * 100 /
total));
+ fprintf(fp, "FastEthernet=%d (%0.2f%%);\n",
cur->links[5],
+ ((float) cur->links[5] * 100 /
total));
+ fprintf(fp, "OC-12=%d (%0.2f%%); ", cur->links[6],
+ ((float) cur->links[6] * 100 /
total));
+ fprintf(fp, "\tGigabit Ethernet=%d (%0.2f%%); ",
cur->links[7],
+ ((float) cur->links[7] * 100 /
total));
+ fprintf(fp, "OC-48=%d (%0.2f%%); ", cur->links[8],
+ ((float) cur->links[8] * 100 /
total));
+ fprintf(fp, "10 Gigabit Enet=%d (%0.2f%%);\n",
cur->links[9],
+ ((float) cur->links[9] * 100 /
total));
+ fprintf(fp, "\tRetransmissions=%d (%0.2f%%); ",
cur->links[10],
+ ((float) cur->links[10] * 100 /
total));
+ fprintf(fp, "Unknown=%d (%0.2f%%);\n", cur->links[11],
+ ((float) cur->links[11] * 100 /
total));
+ }
+ fclose(fp);
+ }
+
+ sprintf(buff,
+ " %d %d %d %d %d %d %d %d %d %d %d %d %0.2f %d %d %d %d
%d %d",
+ cur->links[0], cur->links[1], cur->links[2],
cur->links[3],
+ cur->links[4], cur->links[5], cur->links[6],
cur->links[7],
+ cur->links[8], cur->links[9], cur->links[10],
cur->links[11],
+ cur->totalspd2, cur->inc_cnt, cur->dec_cnt,
cur->same_cnt,
+ cur->timeout, cur->dupack, ifspeed);
+ for (j = 0; j < 5; j++) {
+ i = write(monitor_pipe[1], buff, strlen(buff));
+ if (i == strlen(buff))
+ break;
+ if ((i == -1) && (errno == EINTR))
+ continue;
+ }
+ log_println(6, "wrote %d bytes: link counters are '%s'", i, buff);
+ log_println(
+ 6,
+ "#$#$#$#$ pcap routine says window increases = %d, decreases = %d, no change = %d",
+ cur->inc_cnt, cur->dec_cnt, cur->same_cnt);
}

-void calculate_spd(struct spdpair *cur, struct spdpair *cur2, int portA, int portB)
-{
-
+void calculate_spd(struct spdpair *cur, struct spdpair *cur2, int portA,
+ int portB) {
+
float bits = 0, spd, time;

- assert(cur);
- assert(cur2);
-
- time = (((cur->sec - cur2->sec)*1000000) + (cur->usec - cur2->usec));
+ assert(cur);
+ assert(cur2);
+
+ time = (((cur->sec - cur2->sec) * 1000000) + (cur->usec -
cur2->usec));
/* time = curt->time - cur2->time; */
if ((cur->dport == portA) || (cur->sport == portB)) {
- if (cur->seq >= cur2->seq)
- bits = (cur->seq - cur2->seq) * 8;
- else
- bits = 0;
- if (time > 200000) {
- cur2->timeout++;
- }
- } else {
- if (cur->ack > cur2->ack)
- bits = (cur->ack - cur2->ack) * 8;
- else if (cur->ack == cur2->ack)
- cur2->dupack++;
- else
- bits = 0;
- if (cur->win > cur2->win)
- cur2->inc_cnt++;
- if (cur->win == cur2->win)
- cur2->same_cnt++;
- if (cur->win < cur2->win)
- cur2->dec_cnt++;
- }
- spd = (bits/time); /* convert to mbits/sec) */
+ if (cur->seq >= cur2->seq)
+ bits = (cur->seq - cur2->seq) * 8;
+ else
+ bits = 0;
+ if (time > 200000) {
+ cur2->timeout++;
+ }
+ } else {
+ if (cur->ack > cur2->ack)
+ bits = (cur->ack - cur2->ack) * 8;
+ else if (cur->ack == cur2->ack)
+ cur2->dupack++;
+ else
+ bits = 0;
+ if (cur->win > cur2->win)
+ cur2->inc_cnt++;
+ if (cur->win == cur2->win)
+ cur2->same_cnt++;
+ if (cur->win < cur2->win)
+ cur2->dec_cnt++;
+ }
+ spd = (bits / time); /* convert to mbits/sec) */
if ((spd > 0) && (spd <= 0.01))
- cur2->links[0]++;
+ cur2->links[0]++;
if ((spd > 0.01) && (spd <= 0.064))
- cur2->links[1]++;
+ cur2->links[1]++;
if ((spd > 0.064) && (spd <= 1.5))
- cur2->links[2]++;
+ cur2->links[2]++;
else if ((spd > 1.5) && (spd <= 10))
- cur2->links[3]++;
- else if ((spd > 10) && (spd <=40))
- cur2->links[4]++;
- else if ((spd > 40) && (spd <=100))
- cur2->links[5]++;
+ cur2->links[3]++;
+ else if ((spd > 10) && (spd <= 40))
+ cur2->links[4]++;
+ else if ((spd > 40) && (spd <= 100))
+ cur2->links[5]++;
else if ((spd > 100) && (spd <= 622))
- cur2->links[6]++;
+ cur2->links[6]++;
else if ((spd > 622) && (spd <= 1000))
- cur2->links[7]++;
+ cur2->links[7]++;
else if ((spd > 1000) && (spd <= 2400))
- cur2->links[8]++;
+ cur2->links[8]++;
else if ((spd > 2400) && (spd <= 10000))
- cur2->links[9]++;
+ cur2->links[9]++;
else if (spd == 0)
- cur2->links[10]++;
- else
- cur2->links[11]++;
+ cur2->links[10]++;
+ else
+ cur2->links[11]++;
cur2->seq = cur->seq;
cur2->ack = cur->ack;
cur2->win = cur->win;
@@ -421,9 +456,9 @@
cur2->sec = cur->sec;
cur2->usec = cur->usec;
if ((time > 10) && (spd > 0)) {
- cur2->totalspd += spd;
- cur2->totalcount++;
- cur2->totalspd2 = (cur2->totalspd2 + spd) / 2;
+ cur2->totalspd += spd;
+ cur2->totalcount++;
+ cur2->totalspd2 = (cur2->totalspd2 + spd) / 2;
}
}

@@ -433,235 +468,242 @@
* bin.
*/

-void
-print_speed(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
-{
-
- struct ether_header *enet;
- const struct ip *ip = NULL;
- PortPair* pair = (PortPair*) user;
+void print_speed(u_char *user, const struct pcap_pkthdr *h, const u_char *p) {
+
+ struct ether_header *enet;
+ const struct ip *ip = NULL;
+ PortPair* pair = (PortPair*) user;
#if defined(AF_INET6)
- const struct ip6_hdr *ip6;
+ const struct ip6_hdr *ip6;
#endif
- const struct tcphdr *tcp;
- struct spdpair current;
- int port2 = pair->port1;
- int port4 = pair->port2;
-
- assert(user);
-
- if (dumptrace == 1)
- pcap_dump((u_char *)pdump, h, p);
-
- if (pd == NULL) {
- fprintf(stderr, "!#!#!#!# Error, trying to process IF data, but pcap fd closed\n");
- return;
- }
-
- if (check_signal_flags()) {
- return;
- }
-
- current.sec = h->ts.tv_sec;
- current.usec = h->ts.tv_usec;
- current.time = (current.sec*1000000) + current.usec;
-
- enet = (struct ether_header *)p;
- p += sizeof(struct ether_header); /* move packet pointer past ethernet fields */
-
- ip = (const struct ip *)p;
+ const struct tcphdr *tcp;
+ struct spdpair current;
+ int port2 = pair->port1;
+ int port4 = pair->port2;
+
+ assert(user);
+
+ if (dumptrace == 1)
+ pcap_dump((u_char *) pdump, h, p);
+
+ if (pd == NULL) {
+ fprintf(
+ stderr,
+ "!#!#!#!# Error, trying to process IF data, but
pcap fd closed\n");
+ return;
+ }
+
+ if (check_signal_flags()) {
+ return;
+ }
+
+ current.sec = h->ts.tv_sec;
+ current.usec = h->ts.tv_usec;
+ current.time = (current.sec * 1000000) + current.usec;
+
+ enet = (struct ether_header *) p;
+ p += sizeof(struct ether_header); /* move packet pointer past ethernet fields */
+
+ ip = (const struct ip *) p;
#if defined(AF_INET6)
- if (ip->ip_v == 4) {
+ if (ip->ip_v == 4) {
#endif

-/* This section grabs the IP & TCP header values from an IPv4 packet and loads the various
- * variables with the packet's values.
- */
- p += (ip->ip_hl) * 4;
- tcp = (const struct tcphdr *)p;
+ /* This section grabs the IP & TCP header values from an IPv4 packet and loads the various
+ * variables with the packet's values.
+ */
+ p += (ip->ip_hl) * 4;
+ tcp = (const struct tcphdr *) p;
#if defined(AF_INET6)
- current.saddr[0] = ip->ip_src.s_addr;
- current.daddr[0] = ip->ip_dst.s_addr;
+ current.saddr[0] = ip->ip_src.s_addr;
+ current.daddr[0] = ip->ip_dst.s_addr;
#else
- current.saddr = ip->ip_src.s_addr;
- current.daddr = ip->ip_dst.s_addr;
+ current.saddr = ip->ip_src.s_addr;
+ current.daddr = ip->ip_dst.s_addr;
#endif

- current.sport = ntohs(tcp->source);
- current.dport = ntohs(tcp->dest);
- current.seq = ntohl(tcp->seq);
- current.ack = ntohl(tcp->ack_seq);
- current.win = ntohs(tcp->window);
-
-/* the current structure now has copies of the IP/TCP header values, if this is the
- * first packet, then there is nothing to compare them to, so just finish the initialization
- * step and return.
- */
-
- if (fwd.seq == 0) {
- log_println(1, "New IPv4 packet trace started -- initializing counters");
- fwd.seq = current.seq;
-
- fwd.st_sec = current.sec;
- fwd.st_usec = current.usec;
- rev.st_sec = current.sec;
- rev.st_usec = current.usec;
- fwd.dec_cnt = 0;
- fwd.inc_cnt = 0;
- fwd.same_cnt = 0;
- fwd.timeout = 0;
- fwd.dupack = 0;
- rev.dec_cnt = 0;
- rev.inc_cnt = 0;
- rev.same_cnt = 0;
- rev.timeout = 0;
- rev.dupack = 0;
- fwd.family = 4;
- rev.family = 4;
- return;
- }
-
-/* a new IPv4 packet has been received and it isn't the 1st one, so calculate the bottleneck link
- * capacity based on the times between this packet and the previous one.
- */
+ current.sport = ntohs(tcp->source);
+ current.dport = ntohs(tcp->dest);
+ current.seq = ntohl(tcp->seq);
+ current.ack = ntohl(tcp->ack_seq);
+ current.win = ntohs(tcp->window);
+
+ /* the current structure now has copies of the IP/TCP header values, if this is the
+ * first packet, then there is nothing to compare them to, so just finish the initialization
+ * step and return.
+ */
+
+ if (fwd.seq == 0) {
+ log_println(1,
+ "New IPv4 packet trace started -- initializing
counters");
+ fwd.seq = current.seq;
+
+ fwd.st_sec = current.sec;
+ fwd.st_usec = current.usec;
+ rev.st_sec = current.sec;
+ rev.st_usec = current.usec;
+ fwd.dec_cnt = 0;
+ fwd.inc_cnt = 0;
+ fwd.same_cnt = 0;
+ fwd.timeout = 0;
+ fwd.dupack = 0;
+ rev.dec_cnt = 0;
+ rev.inc_cnt = 0;
+ rev.same_cnt = 0;
+ rev.timeout = 0;
+ rev.dupack = 0;
+ fwd.family = 4;
+ rev.family = 4;
+ return;
+ }
+
+ /* a new IPv4 packet has been received and it isn't the 1st one, so calculate the bottleneck link
+ * capacity based on the times between this packet and the previous
one.
+ */

#if defined(AF_INET6)
- if (fwd.saddr[0] == current.saddr[0]) {
+ if (fwd.saddr[0] == current.saddr[0]) {
#else
- if (fwd.saddr == current.saddr) {
+ if (fwd.saddr == current.saddr) {
#endif
- if (current.dport == port2) {
- calculate_spd(&current, &fwd, port2, port4);
- return;
- }
- if (current.sport == port4) {
- calculate_spd(&current, &fwd, port2, port4);
- return;
- }
- }
+ if (current.dport == port2) {
+ calculate_spd(&current, &fwd, port2, port4);
+ return;
+ }
+ if (current.sport == port4) {
+ calculate_spd(&current, &fwd, port2, port4);
+ return;
+ }
+ }
#if defined(AF_INET6)
- if (rev.saddr[0] == current.saddr[0]) {
+ if (rev.saddr[0] == current.saddr[0]) {
#else
- if (rev.saddr == current.saddr) {
+ if (rev.saddr == current.saddr) {
#endif
- if (current.sport == port2) {
- calculate_spd(&current, &rev, port2, port4);
- return;
- }
- if (current.dport == port4) {
- calculate_spd(&current, &rev, port2, port4);
- return;
- }
- }
+ if (current.sport == port2) {
+ calculate_spd(&current, &rev, port2, port4);
+ return;
+ }
+ if (current.dport == port4) {
+ calculate_spd(&current, &rev, port2, port4);
+ return;
+ }
+ }
#if defined(AF_INET6)
- }
- else { /* IP header value is not = 4, so must be IPv6 */
-
-/* This is an IPv6 packet, grab the IP & TCP header values for further use.
- */
-
- ip6 = (const struct ip6_hdr *)p;
-
- p += 40;
- tcp = (const struct tcphdr *)p;
- memcpy(current.saddr, (void *) &ip6->ip6_src, 16);
- memcpy(current.daddr, (void *) &ip6->ip6_dst, 16);
-
- current.sport = ntohs(tcp->source);
- current.dport = ntohs(tcp->dest);
- current.seq = ntohl(tcp->seq);
- current.ack = ntohl(tcp->ack_seq);
- current.win = ntohs(tcp->window);
-
-/* The 1st packet has been received, finish the initialization process and return.
- */
-
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/web100-util.c Mon Oct 17 06:31:32 2011
+++ /branches/kkumar_code_organize/src/web100-util.c Mon Oct 17 06:43:25 2011
@@ -24,33 +24,33 @@
* @return integer indicating number of web100 variables read
* or indicating failure of initialization
*/
-int
-web100_init(char *VarFileName)
-{
-
- FILE *fp;
- char line[256];
- int count_vars = 0;
-
- assert(VarFileName);
-
- if((fp = fopen(VarFileName, "r")) == NULL) { // unable to open web100 variable file
- err_sys("Required Web100 variables file missing, use -f option to specify file location\n");
- exit(5);
- }
-
- while (fgets(line, 255, fp) != NULL) { // read file linewise
- if ((line[0] == '#') || (line[0] == '\n')) // if newline or comment, ignore
- continue;
- // copy web100 variable into our array and increment count of read variables
- //strncpy(web_vars[count_vars].name, line, (strlen(line)-1));
- strlcpy(web_vars[count_vars].name, line, sizeof(web_vars[count_vars].name));
- count_vars++;
- }
- fclose(fp);
- log_println(1, "web100_init() read %d variables from file", count_vars);
-
- return(count_vars);
+int web100_init(char *VarFileName) {
+
+ FILE * fp;
+ char line[256];
+ int count_vars = 0;
+
+ assert(VarFileName);
+
+ if ((fp = fopen(VarFileName, "r")) == NULL) { // unable to open web100 variable file
+ err_sys(
+ "Required Web100 variables file missing, use -f option to specify file location\n");
+ exit(5);
+ }
+
+ while (fgets(line, 255, fp) != NULL) { // read file linewise
+ if ((line[0] == '#') || (line[0] == '\n')) // if newline or comment, ignore
+ continue;
+ // copy web100 variable into our array and increment count of read variables
+ //strncpy(web_vars[count_vars].name, line, (strlen(line)-1));
+ strlcpy(web_vars[count_vars].name, line,
+ sizeof(web_vars[count_vars].name));
+ count_vars++;
+ }
+ fclose(fp);
+ log_println(1, "web100_init() read %d variables from file",
count_vars);
+
+ return (count_vars);
}

/**
@@ -71,168 +71,168 @@
*
*
*/
-void
-web100_middlebox(int sock, web100_agent* agent, web100_connection* cn, char *results)
-{
-
- web100_var* var;
- web100_group* group;
- web100_snapshot* snap;
- char buff[8192], line[256];
- char* sndbuff;
- int i, j, k, currentMSSval =0;
- int SndMax=0, SndUna=0;
- fd_set wfd;
- struct timeval sel_tv;
- int ret;
- char tmpstr[200];
- size_t tmpstrlen = sizeof(tmpstr);
- I2Addr addr = NULL;
- web100_var *LimCwnd;
- u_int32_t limcwnd_val;
-
- // middlebox test results
- static char vars[][255] = {
- "CurMSS",
- "WinScaleSent",
- "WinScaleRecv",
- };
-
- assert(results);
-
- log_println(4, "Looking for Web100 data on socketid %d", sock);
-
- // get Server address and add to "results"
-
- // get socket name
- addr = I2AddrByLocalSockFD(get_errhandle(), sock, False);
- memset(tmpstr, 0, 200);
- // copy address into tmpstr String
- I2AddrNodeName(addr, tmpstr, &tmpstrlen);
- // now copy tmpstr containing address into "line"
- sprintf(line, "%s;", tmpstr);
- memset(tmpstr, 0, 200);
- // service name into tmpstr
- I2AddrServName(addr, tmpstr, &tmpstrlen);
- log_print(3, "Server: %s%s ", line, tmpstr);
- // copy servers address into the meta test struct
- memcpy(meta.server_ip, line, strlen(line));
- // terminate the IP address string
- meta.server_ip[(strlen(line)-1)] = 0;
- // Add this address to results
- strlcat(results, line, (BUFFSIZE+1)); // using a "known" hardcoded value for size of results
- I2AddrFree(addr); // free memory
-
- // Now perform the above set of functions for client address/service name
- // and copy into results
- tmpstrlen = sizeof(tmpstr);
- addr = I2AddrBySockFD(get_errhandle(), sock, False);
- memset(tmpstr, 0, 200);
- I2AddrNodeName(addr, tmpstr, &tmpstrlen);
- sprintf(line, "%s;", tmpstr);
- I2AddrServName(addr, tmpstr, &tmpstrlen);
- log_print(3, "Client: %s%s ", line, tmpstr);
- strlcat(results, line, (BUFFSIZE+1));
- I2AddrFree(addr);
-
- // get web100 values for the middlebox test result group
- for (i=0; i<3; i++) {
- // read web100_group and web100_var of vars[i] into group and var
- web100_agent_find_var_and_group(agent, vars[i], &group, &var);
- web100_raw_read(var, cn, buff); // read variable value from web100 connection
-
- // get current MSS in textual format and append to results
-
- //get current MSS value and append to "results"
- if (strcmp(vars[i], "CurMSS") == 0)
- currentMSSval = atoi(web100_value_to_text(web100_get_var_type(var), buff));
- sprintf(line, "%s;", web100_value_to_text(web100_get_var_type(var), buff));
- if (strcmp(line, "4294967295;") == 0)
- sprintf(line, "%d;", -1);
-
- strlcat(results, line, sizeof(results));
- log_print(3, "%s", line);
- }
- log_println(3, "");
- log_println(0, "Sending %d Byte packets over the network", currentMSSval);
-
- /* The initial check has been completed, now stream data to the remote client
- * for 5 seconds with very limited buffer space. The idea is to see if there
- * is a difference between this test and the later s2c speed test. If so, then
- * it may be due to a duplex mismatch condition.
- * RAC 2/28/06
- */
-
- // get web100_var and web100_group
- web100_agent_find_var_and_group(agent, "LimCwnd", &group, &LimCwnd);
-
- // set TCP CWND web100 variable to twice the current MSS Value
- limcwnd_val = 2 * currentMSSval;
- web100_raw_write(LimCwnd, cn, &limcwnd_val);
- log_println(5, "Setting Cwnd Limit to %d octets", limcwnd_val);
-
- // try to allocate memory of the size of current MSS Value
- sndbuff = malloc(currentMSSval);
- if (sndbuff == NULL) { // not possible, use MIDDLEBOX_PREDEFINED_MSS bytes
- log_println(0, "Failed to allocate memory --> switching to 8192 Byte packets");
- sndbuff = buff;
- currentMSSval = MIDDLEBOX_PREDEFINED_MSS;
- }
- if (getuid() == 0) {
- system("echo 1 > /proc/sys/net/ipv4/route/flush");
- }
-
- // fill send buffer with random printable data
-
- k=0;
- for (j=0; j<currentMSSval; j++) {
- while (!isprint(k & 0x7f)) // Is character printable?
- k++;
- sndbuff[j] = (k++ & 0x7f);
- }
-
- // get web100 group with name "read"
- group = web100_group_find(agent, "read");
- snap = web100_snapshot_alloc(group, cn);
-
- FD_ZERO(&wfd);
- FD_SET(sock, &wfd);
- sel_tv.tv_sec = 5; // 5 seconds maximum for select call below to complete
- sel_tv.tv_usec = 0; // 5s + 0ms
- while ((ret = select(sock+1, NULL, &wfd, NULL, &sel_tv)) > 0) {
- if ((ret == -1) && (errno == EINTR)) /* a signal arrived, ignore it */
- continue;
-
- web100_snap(snap);
-
- // get next sequence # to be sent
- web100_agent_find_var_and_group(agent, "SndNxt", &group, &var);
- web100_snap_read(var, snap, line);
- SndMax = atoi(web100_value_to_text(web100_get_var_type(var), line));
- // get oldest un-acked sequence number
- web100_agent_find_var_and_group(agent, "SndUna", &group, &var);
- web100_snap_read(var, snap, line);
- SndUna = atoi(web100_value_to_text(web100_get_var_type(var), line));
-
- // stop sending data if (buf size * 16) <
- // [ (Next Sequence # To Be Sent) - (Oldest Unacknowledged Sequence #) - 1 ]
- if ((currentMSSval<<4) < (SndMax - SndUna - 1)) {
- continue;
- }
-
- // write currentMSSval number of bytes from send-buffer data into socket
- k = write(sock, sndbuff, currentMSSval);
- if ((k == -1) && (errno == EINTR)) // error writing into socket due
- // to
interruption, try again
- continue;
- if (k < 0 ) // general error writing to socket. quit
- break;
- }
- log_println(5, "Finished with web100_middlebox() routine snap-0x%x, sndbuff=%x0x", snap, sndbuff);
- web100_snapshot_free(snap);
- /* free(sndbuff); */
-}
-
+void web100_middlebox(int sock, web100_agent* agent, web100_connection* cn,
+ char *results) {
+
+ web100_var* var;
+ web100_group* group;
+ web100_snapshot* snap;
+ char buff[8192], line[256];
+ char* sndbuff;
+ int i, j, k, currentMSSval = 0;
+ int SndMax = 0, SndUna = 0;
+ fd_set wfd;
+ struct timeval sel_tv;
+ int ret;
+ char tmpstr[200];
+ size_t tmpstrlen = sizeof(tmpstr);
+ I2Addr addr = NULL;
+ web100_var *LimCwnd;
+ u_int32_t limcwnd_val;
+
+ // middlebox test results
+ static char vars[][255] = { "CurMSS", "WinScaleSent", "WinScaleRecv",
};
+
+ assert(results);
+
+ log_println(4, "Looking for Web100 data on socketid %d", sock);
+
+ // get Server address and add to "results"
+
+ // get socket name
+ addr = I2AddrByLocalSockFD(get_errhandle(), sock, False);
+ memset(tmpstr, 0, 200);
+ // copy address into tmpstr String
+ I2AddrNodeName(addr, tmpstr, &tmpstrlen);
+ // now copy tmpstr containing address into "line"
+ sprintf(line, "%s;", tmpstr);
+ memset(tmpstr, 0, 200);
+ // service name into tmpstr
+ I2AddrServName(addr, tmpstr, &tmpstrlen);
+ log_print(3, "Server: %s%s ", line, tmpstr);
+ // copy servers address into the meta test struct
+ memcpy(meta.server_ip, line, strlen(line));
+ // terminate the IP address string
+ meta.server_ip[(strlen(line) - 1)] = 0;
+ // Add this address to results
+ strlcat(results, line, (BUFFSIZE + 1)); // using a "known" hardcoded value for size of results
+ I2AddrFree(addr); // free memory
+
+ // Now perform the above set of functions for client address/service
name
+ // and copy into results
+ tmpstrlen = sizeof(tmpstr);
+ addr = I2AddrBySockFD(get_errhandle(), sock, False);
+ memset(tmpstr, 0, 200);
+ I2AddrNodeName(addr, tmpstr, &tmpstrlen);
+ sprintf(line, "%s;", tmpstr);
+ I2AddrServName(addr, tmpstr, &tmpstrlen);
+ log_print(3, "Client: %s%s ", line, tmpstr);
+ strlcat(results, line, (BUFFSIZE + 1));
+ I2AddrFree(addr);
+
+ // get web100 values for the middlebox test result group
+ for (i = 0; i < 3; i++) {
+ // read web100_group and web100_var of vars[i] into group and
var
+ web100_agent_find_var_and_group(agent, vars[i], &group, &var);
+ web100_raw_read(var, cn, buff); // read variable value from web100 connection
+
+ // get current MSS in textual format and append to results
+
+ //get current MSS value and append to "results"
+ if (strcmp(vars[i], "CurMSS") == 0)
+ currentMSSval = atoi(
+
web100_value_to_text(web100_get_var_type(var), buff));
+ sprintf(line, "%s;",
+
web100_value_to_text(web100_get_var_type(var), buff));
+ if (strcmp(line, "4294967295;") == 0)
+ sprintf(line, "%d;", -1);
+
+ strlcat(results, line, sizeof(results));
+ log_print(3, "%s", line);
+ }
+ log_println(3, "");
+ log_println(0, "Sending %d Byte packets over the network",
currentMSSval);
+
+ /* The initial check has been completed, now stream data to the remote client
+ * for 5 seconds with very limited buffer space. The idea is to see if there
+ * is a difference between this test and the later s2c speed test. If so, then
+ * it may be due to a duplex mismatch condition.
+ * RAC 2/28/06
+ */
+
+ // get web100_var and web100_group
+ web100_agent_find_var_and_group(agent, "LimCwnd", &group, &LimCwnd);
+
+ // set TCP CWND web100 variable to twice the current MSS Value
+ limcwnd_val = 2 * currentMSSval;
+ web100_raw_write(LimCwnd, cn, &limcwnd_val);
+ log_println(5, "Setting Cwnd Limit to %d octets", limcwnd_val);
+
+ // try to allocate memory of the size of current MSS Value
+ sndbuff = malloc(currentMSSval);
+ if (sndbuff == NULL) { // not possible, use MIDDLEBOX_PREDEFINED_MSS
bytes
+ log_println(0,
+ "Failed to allocate memory --> switching to 8192
Byte packets");
+ sndbuff = buff;
+ currentMSSval = MIDDLEBOX_PREDEFINED_MSS;
+ }
+ if (getuid() == 0) {
+ system("echo 1 > /proc/sys/net/ipv4/route/flush");
+ }
+
+ // fill send buffer with random printable data
+
+ k = 0;
+ for (j = 0; j < currentMSSval; j++) {
+ while (!isprint(k & 0x7f)) // Is character printable?
+ k++;
+ sndbuff[j] = (k++ & 0x7f);
+ }
+
+ // get web100 group with name "read"
+ group = web100_group_find(agent, "read");
+ snap = web100_snapshot_alloc(group, cn);
+
+ FD_ZERO(&wfd);
+ FD_SET(sock, &wfd);
+ sel_tv.tv_sec = 5; // 5 seconds maximum for select call below to
complete
+ sel_tv.tv_usec = 0; // 5s + 0ms
+ while ((ret = select(sock + 1, NULL, &wfd, NULL, &sel_tv)) > 0) {
+ if ((ret == -1) && (errno == EINTR)) /* a signal arrived,
ignore it */
+ continue;
+
+ web100_snap(snap);
+
+ // get next sequence # to be sent
+ web100_agent_find_var_and_group(agent, "SndNxt", &group,
&var);
+ web100_snap_read(var, snap, line);
+ SndMax = atoi(web100_value_to_text(web100_get_var_type(var),
line));
+ // get oldest un-acked sequence number
+ web100_agent_find_var_and_group(agent, "SndUna", &group,
&var);
+ web100_snap_read(var, snap, line);
+ SndUna = atoi(web100_value_to_text(web100_get_var_type(var),
line));
+
+ // stop sending data if (buf size * 16) <
+ // [ (Next Sequence # To Be Sent) - (Oldest Unacknowledged Sequence #) - 1 ]
+ if ((currentMSSval << 4) < (SndMax - SndUna - 1)) {
+ continue;
+ }
+
+ // write currentMSSval number of bytes from send-buffer data
into socket
+ k = write(sock, sndbuff, currentMSSval);
+ if ((k == -1) && (errno == EINTR)) // error writing into
socket due
+
// to interruption, try again
+ continue;
+ if (k < 0) // general error writing to socket. quit
+ break;
+ }
+ log_println(5,
+ "Finished with web100_middlebox() routine snap-0x%x,
sndbuff=%x0x",
+ snap, sndbuff);
+ web100_snapshot_free(snap);
+ /* free(sndbuff); */
+}
+
/**
* Get receiver side Web100 stats and write them to the log file
*
@@ -242,68 +242,71 @@
* @param count_vars integer number of web100_variables to get value of
*
*/
-void
-web100_get_data_recv(int sock, web100_agent* agent, web100_connection* cn, int count_vars)
-{
- int i, ok;
- web100_var* var;
- char buf[32], line[256], *ctime();
- web100_group* group;
- FILE *fp;
- time_t tt;
-
- // get current time
- tt=time(0);
- // open logfile in append mode and write time into it
- fp=fopen(get_logfile(),"a");
- if (fp)
- fprintf(fp,"%15.15s;", ctime(&tt)+4);
- // get values for group, var of IP Address of the Remote host's side of connection
- web100_agent_find_var_and_group(agent, "RemAddress", &group, &var);
- web100_raw_read(var, cn, buf);
- sprintf(line, "%s;", web100_value_to_text(web100_get_var_type(var), buf));
- // write remote address to log file
- if (fp)
- fprintf(fp,"%s", line);
-
- ok = 1;
-
- // get values for other web100 variables and write to the log file
-
- for(i=0; i<count_vars; i++) {
- if ((web100_agent_find_var_and_group(agent, web_vars[i].name, &group, &var)) != WEB100_ERR_SUCCESS) {
- log_println(1, "Variable %d (%s) not found in KIS", i, web_vars[i].name);
- ok = 0;
- continue;
- }
-
- if (cn == NULL) {
- fprintf(stderr, "Web100_get_data_recv() failed, return to testing routine\n");
- return;
- }
-
- if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
- if (get_debuglvl() > 9)
- web100_perror("web100_raw_read()");
- continue;
- }
- if (ok == 1) {
- sprintf(web_vars[i].value, "%s", web100_value_to_text(web100_get_var_type(var), buf));
- if (fp)
- fprintf(fp, "%d;", (int32_t)atoi(web_vars[i].value));
- log_println(9, "%s: %d", web_vars[i].name, atoi(web_vars[i].value));
- }
- ok = 1;
- }
-
- // close file pointers after web100 variables have been fetched
- if (fp) {
- fprintf(fp, "\n");
- fclose(fp);
- }
+void web100_get_data_recv(int sock, web100_agent* agent, web100_connection* cn,
+ int count_vars) {
+ int i, ok;
+ web100_var* var;
+ char buf[32], line[256], *ctime();
+ web100_group* group;
+ FILE * fp;
+ time_t tt;
+
+ // get current time
+ tt = time(0);
+ // open logfile in append mode and write time into it
+ fp = fopen(get_logfile(), "a");
+ if (fp)
+ fprintf(fp, "%15.15s;", ctime(&tt) + 4);
+ // get values for group, var of IP Address of the Remote host's side of connection
+ web100_agent_find_var_and_group(agent, "RemAddress", &group, &var);
+ web100_raw_read(var, cn, buf);
+ sprintf(line, "%s;", web100_value_to_text(web100_get_var_type(var),
buf));
+ // write remote address to log file
+ if (fp)
+ fprintf(fp, "%s", line);
+
+ ok = 1;
+
+ // get values for other web100 variables and write to the log file
+
+ for (i = 0; i < count_vars; i++) {
+ if ((web100_agent_find_var_and_group(agent, web_vars[i].name,
&group,
+ &var)) != WEB100_ERR_SUCCESS) {
+ log_println(1, "Variable %d (%s) not found in KIS", i,
+ web_vars[i].name);
+ ok = 0;
+ continue;
+ }
+
+ if (cn == NULL) {
+ fprintf(
+ stderr,
+ "Web100_get_data_recv() failed, return to
testing routine\n");
+ return;
+ }
+
+ if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
+ if (get_debuglvl() > 9)
+ web100_perror("web100_raw_read()");
+ continue;
+ }
+ if (ok == 1) {
+ sprintf(web_vars[i].value, "%s",
+
web100_value_to_text(web100_get_var_type(var), buf));
+ if (fp)
+ fprintf(fp, "%d;", (int32_t)
atoi(web_vars[i].value));
+ log_println(9, "%s: %d", web_vars[i].name,
atoi(web_vars[i].value));
+ }
+ ok = 1;
+ }
+
+ // close file pointers after web100 variables have been fetched
+ if (fp) {
+ fprintf(fp, "\n");
+ fclose(fp);
+ }

}
-

/**
* Collect Web100 stats from a snapshot and transmit to a receiver.
@@ -316,49 +319,53 @@
* @param count_vars integer number of web100_variables to get value of
*
*/
-int
-web100_get_data(web100_snapshot* snap, int ctlsock, web100_agent* agent, int count_vars)
-{
-
- int i;
- web100_var* var;
- char buf[32], line[256];
- web100_group* group;
-
- assert(snap);
- assert(agent);
-
- // Read values for number of variables intended
- for(i=0; i<count_vars; i++) {
- if ((web100_agent_find_var_and_group(agent, web_vars[i].name, &group, &var)) != WEB100_ERR_SUCCESS) {
- log_println(9, "Variable %d (%s) not found in KIS", i, web_vars[i].name);
- continue;
- }
-
- // if no snapshot provided, no way to get values
- if (snap == NULL) {
- fprintf(stderr, "Web100_get_data() failed, return to testing routine\n");
- log_println(6, "Web100_get_data() failed, return to testing routine\n");
- return(-1);
- }
-
- // handle an unsuccessful data retrieval
- if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) {
- if (get_debuglvl() > 9) {
- log_print(9, "Variable %d (%s): ", i, web_vars[i].name);
- web100_perror("web100_snap_read()");
- }
- continue;
- }
-
- // assign values and transmit message with all web100 variables to socket receiver end
- sprintf(web_vars[i].value, "%s", web100_value_to_text(web100_get_var_type(var), buf));
- sprintf(line, "%s: %d\n", web_vars[i].name, atoi(web_vars[i].value));
- send_msg(ctlsock, TEST_MSG, line, strlen(line));
- log_print(9, "%s", line);
- }
- log_println(6, "S2C test - Send web100 data to client pid=%d", getpid());
- return(0);
+int web100_get_data(web100_snapshot* snap, int ctlsock, web100_agent* agent,
+ int count_vars) {
+
+ int i;
+ web100_var* var;
+ char buf[32], line[256];
+ web100_group* group;
+
+ assert(snap);
+ assert(agent);
+
+ // Read values for number of variables intended
+ for (i = 0; i < count_vars; i++) {
+ if ((web100_agent_find_var_and_group(agent, web_vars[i].name,
&group,
+ &var)) != WEB100_ERR_SUCCESS) {
+ log_println(9, "Variable %d (%s) not found in KIS", i,
+ web_vars[i].name);
+ continue;
+ }
+
+ // if no snapshot provided, no way to get values
+ if (snap == NULL) {
+ fprintf(stderr,
+ "Web100_get_data() failed, return to
testing routine\n");
+ log_println(6,
+ "Web100_get_data() failed, return to
testing routine\n");
+ return (-1);
+ }
+
+ // handle an unsuccessful data retrieval
+ if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS)
{
+ if (get_debuglvl() > 9) {
+ log_print(9, "Variable %d (%s): ", i,
web_vars[i].name);
+ web100_perror("web100_snap_read()");
+ }
+ continue;
+ }
+
+ // assign values and transmit message with all web100 variables to socket receiver end
+ sprintf(web_vars[i].value, "%s",
+
web100_value_to_text(web100_get_var_type(var), buf));
+ sprintf(line, "%s: %d\n", web_vars[i].name,
atoi(web_vars[i].value));
+ send_msg(ctlsock, TEST_MSG, line, strlen(line));
+ log_print(9, "%s", line);
+ }
+ log_println(6, "S2C test - Send web100 data to client pid=%d",
getpid());
+ return (0);

}

@@ -380,33 +387,32 @@
*
*
*/
-int
-web100_rtt(int sock, web100_agent* agent, web100_connection* cn)
-{
- web100_var* var;
- char buf[32];
- web100_group* group;
- double count, sum;
-
- if (cn == NULL)
- return(-10);
-
- if ((web100_agent_find_var_and_group(agent, "CountRTT", &group, &var)) != WEB100_ERR_SUCCESS)
- return(-24);
- if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
- return(-25);
- }
- count = atoi(web100_value_to_text(web100_get_var_type(var), buf));
-
- if ((web100_agent_find_var_and_group(agent, "SumRTT", &group, &var)) != WEB100_ERR_SUCCESS)
- return(-24);
- if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
- return(-25);
- }
- sum = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- return(sum/count);
-}
-
+int web100_rtt(int sock, web100_agent* agent, web100_connection* cn) {
+ web100_var* var;
+ char buf[32];
+ web100_group* group;
+ double count, sum;
+
+ if (cn == NULL)
+ return (-10);
+
+ if ((web100_agent_find_var_and_group(agent, "CountRTT", &group, &var))
+ != WEB100_ERR_SUCCESS)
+ return (-24);
+ if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
+ return (-25);
+ }
+ count = atoi(web100_value_to_text(web100_get_var_type(var), buf));
+
+ if ((web100_agent_find_var_and_group(agent, "SumRTT", &group, &var))
+ != WEB100_ERR_SUCCESS)
+ return (-24);
+ if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
+ return (-25);
+ }
+ sum = atoi(web100_value_to_text(web100_get_var_type(var), buf));
+ return (sum / count);
+}

/**
* Check if the "Auto Tune Send Buffer" and "Auto Tune Receive Buffer" options
@@ -425,45 +431,47 @@
* 23 cannot read the value of the X_SBufMode or X_RBufMode web100_variable.
*/

-int
-web100_autotune(int sock, web100_agent* agent, web100_connection* cn)
-{
- web100_var* var;
- char buf[32];
- web100_group* group;
- int i, j=0;
-
- if (cn == NULL)
- return(10);
-
- if ((web100_agent_find_var_and_group(agent, "X_SBufMode", &group, &var)) != WEB100_ERR_SUCCESS)
- return(22);
- if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
- log_println(4, "Web100_raw_read(X_SBufMode) failed with errorno=%d", errno);
- return(23);
- }
- i = atoi(web100_value_to_text(web100_get_var_type(var), buf));
-
- /* OK, the variable i now holds the value of the sbufmode autotune parm. If it
- * is 0, autotuning is turned off, so we turn it on for this socket.
- */
- if (i == 0)
- j |= 0x01;
-
- /* OK, the variable i now holds the value of the rbufmode autotune parm. If it
- * is 0, autotuning is turned off, so we turn it on for this socket.
- */
- if ((web100_agent_find_var_and_group(agent, "X_RBufMode", &group, &var)) != WEB100_ERR_SUCCESS)
- return(22);
- if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
- log_println(4, "Web100_raw_read(X_RBufMode) failed with errorno=%d", errno);
- return(23);
- }
- i = atoi(web100_value_to_text(web100_get_var_type(var), buf));
-
- if (i == 0)
- j |= 0x02;
- return(j);
+int web100_autotune(int sock, web100_agent* agent, web100_connection* cn) {
+ web100_var* var;
+ char buf[32];
+ web100_group* group;
+ int i, j = 0;
+
+ if (cn == NULL)
+ return (10);
+
+ if ((web100_agent_find_var_and_group(agent, "X_SBufMode", &group,
&var))
+ != WEB100_ERR_SUCCESS)
+ return (22);
+ if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
+ log_println(4, "Web100_raw_read(X_SBufMode) failed with
errorno=%d",
+ errno);
+ return (23);
+ }
+ i = atoi(web100_value_to_text(web100_get_var_type(var), buf));
+
+ /* OK, the variable i now holds the value of the sbufmode autotune parm. If it
+ * is 0, autotuning is turned off, so we turn it on for this socket.
+ */
+ if (i == 0)
+ j |= 0x01;
+
+ /* OK, the variable i now holds the value of the rbufmode autotune parm. If it
+ * is 0, autotuning is turned off, so we turn it on for this socket.
+ */
+ if ((web100_agent_find_var_and_group(agent, "X_RBufMode", &group,
&var))
+ != WEB100_ERR_SUCCESS)
+ return (22);
+ if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
+ log_println(4, "Web100_raw_read(X_RBufMode) failed with
errorno=%d",
+ errno);
+ return (23);
+ }
+ i = atoi(web100_value_to_text(web100_get_var_type(var), buf));
+
+ if (i == 0)
+ j |= 0x02;
+ return (j);
}

/**
@@ -489,172 +497,175 @@
* 35 - cannot read value of RcvWinScale
web100 variable.
*
*/
-int
-web100_setbuff(int sock, web100_agent* agent, web100_connection* cn, int autotune)
-{
- web100_var* var;
- char buf[32];
- web100_group* group;
- int buff;
- int sScale, rScale;
-
- if (cn == NULL)
- return(10);
-
- // get Window scale used by the sender to decode snd.wnd
- if ((web100_agent_find_var_and_group(agent, "SndWinScale", &group, &var)) != WEB100_ERR_SUCCESS)
- return(24);
- if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
- return(25);
- }
- sScale = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- if (sScale > 15) // define constant for 15
- sScale = 0;
-
- // get Window scale used by the sender to decode seg.wnd
- if ((web100_agent_find_var_and_group(agent, "RcvWinScale", &group, &var)) != WEB100_ERR_SUCCESS)
- return(34);
- if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
- return(35);
- }
- rScale = atoi(web100_value_to_text(web100_get_var_type(var), buf));
- if (rScale > 15)
- rScale = 0;
-
- if ((sScale > 0) && (rScale > 0)) {
- buff = (MAX_TCP_WIN_BYTES * KILO_BITS) << sScale; // 64k( max TCP rcv window)
- if (autotune & 0x01) { // autotune send buffer is not enabled
- if ((web100_agent_find_var_and_group(agent, "LimCwnd", &group, &var)) != WEB100_ERR_SUCCESS)
- return(22);
- // attempt writing variable value, log failure
- if ((web100_raw_write(var, cn, &buff)) != WEB100_ERR_SUCCESS) {
- log_println(4, "Web100_raw_write(LimCwnd) failed with errorno=%d", errno);
- return(23);
- }
- }
- buff = (MAX_TCP_WIN_BYTES * KILO_BITS) << rScale;
-
-
- if (autotune & 0x02) { // autotune receive buffer is not enabled
- if ((web100_agent_find_var_and_group(agent, "LimRwin", &group, &var)) != WEB100_ERR_SUCCESS)
- return(22);
- if ((web100_raw_write(var, cn, &buff)) != WEB100_ERR_SUCCESS) {
- log_println(4, "Web100_raw_write(LimRwin) failed with errorno=%d", errno);
- return(23);
- }
- }
- }
-
- return(0);
-}
-
+int web100_setbuff(int sock, web100_agent* agent, web100_connection* cn,
+ int autotune) {
+ web100_var* var;
+ char buf[32];
+ web100_group* group;
+ int buff;
+ int sScale, rScale;
+
+ if (cn == NULL)
+ return (10);
+
+ // get Window scale used by the sender to decode snd.wnd
+ if ((web100_agent_find_var_and_group(agent, "SndWinScale", &group,
&var))
+ != WEB100_ERR_SUCCESS)
+ return (24);
+ if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
+ return (25);
+ }
+ sScale = atoi(web100_value_to_text(web100_get_var_type(var), buf));
+ if (sScale > 15) // define constant for 15
+ sScale = 0;
+
+ // get Window scale used by the sender to decode seg.wnd
+ if ((web100_agent_find_var_and_group(agent, "RcvWinScale", &group,
&var))
+ != WEB100_ERR_SUCCESS)
+ return (34);
+ if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
+ return (35);
+ }
+ rScale = atoi(web100_value_to_text(web100_get_var_type(var), buf));
+ if (rScale > 15)
+ rScale = 0;
+
+ if ((sScale > 0) && (rScale > 0)) {
+ buff = (MAX_TCP_WIN_BYTES * KILO_BITS) << sScale; // 64k( max TCP rcv window)
+ if (autotune & 0x01) { // autotune send buffer is not enabled
+ if ((web100_agent_find_var_and_group(agent, "LimCwnd",
&group, &var))
+ != WEB100_ERR_SUCCESS)
+ return (22);
+ // attempt writing variable value, log failure
+ if ((web100_raw_write(var, cn, &buff)) !=
WEB100_ERR_SUCCESS) {
+ log_println(4,
+ "Web100_raw_write(LimCwnd) failed
with errorno=%d",
+ errno);
+ return (23);
+ }
+ }
+ buff = (MAX_TCP_WIN_BYTES * KILO_BITS) << rScale;
+
+ if (autotune & 0x02) { // autotune receive buffer is not
enabled
+ if ((web100_agent_find_var_and_group(agent, "LimRwin",
&group, &var))
+ != WEB100_ERR_SUCCESS)
+ return (22);
+ if ((web100_raw_write(var, cn, &buff)) !=
WEB100_ERR_SUCCESS) {
+ log_println(4,
+ "Web100_raw_write(LimRwin) failed
with errorno=%d",
+ errno);
+ return (23);
+ }
+ }
+ }
+
+ return (0);
+}

/**
-* @param sock integer socket file descriptor indicating data recipient
-* @param pointers to local copies of web100 variables
-* @return integer 0
-*
-*
-*/
-int
-web100_logvars(int *Timeouts, int *SumRTT, int *CountRTT,
- int *PktsRetrans, int *FastRetran, int *DataPktsOut, int *AckPktsOut,
- int *CurrentMSS, int *DupAcksIn, int *AckPktsIn, int *MaxRwinRcvd,
- int *Sndbuf, int *CurrentCwnd, int *SndLimTimeRwin, int *SndLimTimeCwnd,
- int *SndLimTimeSender, int *DataBytesOut, int *SndLimTransRwin,
- int *SndLimTransCwnd, int *SndLimTransSender, int *MaxSsthresh,
- int *CurrentRTO, int *CurrentRwinRcvd, int *MaxCwnd, int *CongestionSignals,
- int *PktsOut, int *MinRTT, int count_vars, int *RcvWinScale, int *SndWinScale,
- int *CongAvoid, int *CongestionOverCount, int *MaxRTT, int *OtherReductions,
- int *CurTimeoutCount, int *AbruptTimeouts, int *SendStall, int *SlowStart,
- int *SubsequentTimeouts, int *ThruBytesAcked)
-{
- int i;
-
- for (i=0; i<=count_vars; i++) {
- if (strcmp(web_vars[i].name, "Timeouts") == 0)
- *Timeouts = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SumRTT") == 0)
- *SumRTT = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "CountRTT") == 0)
- *CountRTT = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "PktsRetrans") == 0)
- *PktsRetrans = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "FastRetran") == 0)
- *FastRetran = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "DataPktsOut") == 0)
- *DataPktsOut = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "AckPktsOut") == 0)
- *AckPktsOut = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "CurMSS") == 0)
- *CurrentMSS = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "DupAcksIn") == 0)
- *DupAcksIn = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "AckPktsIn") == 0)
- *AckPktsIn = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "MaxRwinRcvd") == 0)
- *MaxRwinRcvd = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "X_Sndbuf") == 0)
- *Sndbuf = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "CurCwnd") == 0)
- *CurrentCwnd = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "MaxCwnd") == 0)
- *MaxCwnd = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SndLimTimeRwin") == 0)
- *SndLimTimeRwin = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SndLimTimeCwnd") == 0)
- *SndLimTimeCwnd = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SndLimTimeSender") == 0)
- *SndLimTimeSender = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "DataBytesOut") == 0)
- *DataBytesOut = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SndLimTransRwin") == 0)
- *SndLimTransRwin = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SndLimTransCwnd") == 0)
- *SndLimTransCwnd = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SndLimTransSender") == 0)
- *SndLimTransSender = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "MaxSsthresh") == 0)
- *MaxSsthresh = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "CurRTO") == 0)
- *CurrentRTO = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "CurRwinRcvd") == 0)
- *CurrentRwinRcvd = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "CongestionSignals") == 0)
- *CongestionSignals = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "PktsOut") == 0)
- *PktsOut = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "MinRTT") == 0)
- *MinRTT = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "RcvWinScale") == 0)
- *RcvWinScale = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SndWinScale") == 0)
- *SndWinScale = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "CongAvoid") == 0)
- *CongAvoid = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "CongestionOverCount") == 0)
- *CongestionOverCount = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "MaxRTT") == 0)
- *MaxRTT = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "OtherReductions") == 0)
- *OtherReductions = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "CurTimeoutCount") == 0)
- *CurTimeoutCount = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "AbruptTimeouts") == 0)
- *AbruptTimeouts = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SendStall") == 0)
- *SendStall = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SlowStart") == 0)
- *SlowStart = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "SubsequentTimeouts") == 0)
- *SubsequentTimeouts = atoi(web_vars[i].value);
- else if (strcmp(web_vars[i].name, "ThruBytesAcked") == 0)
- *ThruBytesAcked = atoi(web_vars[i].value);
- }
-
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/web100clt.c Fri Oct 14 13:52:19
2011
+++ /branches/kkumar_code_organize/src/web100clt.c Mon Oct 17 06:43:25
2011
@@ -35,9 +35,9 @@
int SACKsRcvd, DupAcksIn, MaxRwinRcvd, MaxRwinSent;
int DataPktsOut, Rcvbuf, Sndbuf, AckPktsIn, DataBytesOut;
int PktsOut, CongestionSignals, RcvWinScale;
-int pkts, lth=8192, CurrentRTO;
+int pkts, lth = 8192, CurrentRTO;
int c2sData, c2sAck, s2cData, s2cAck;
-int winssent, winsrecv, msglvl=0;
+int winssent, winsrecv, msglvl = 0;
int sndqueue, ssndqueue, sbytes;
int minPeak, maxPeak, peaks;
double spdin, spdout, c2sspd, s2cspd;
@@ -48,326 +48,355 @@
double order, rwintime, sendtime, cwndtime, rwin, swin, cwin;
double mylink;

-static struct option long_options[] = {
- {"name", 1, 0, 'n'},
- {"port", 1, 0, 'p'},
- {"debug", 0, 0, 'd'},
- {"help", 0, 0, 'h'},
- {"msglvl", 0, 0, 'l'},
- {"web100variables", 0, 0, 301},
- {"buffer", 1, 0, 'b'},
- {"disablemid", 0, 0, 302},
- {"disablec2s", 0, 0, 303},
- {"disables2c", 0, 0, 304},
- {"disablesfw", 0, 0, 305},
+static struct option long_options[] = { { "name", 1, 0, 'n' }, { "port", 1, 0,
+ 'p' }, { "debug", 0, 0, 'd' }, { "help", 0, 0, 'h' }, {
"msglvl", 0, 0,
+ 'l' }, { "web100variables", 0, 0, 301 }, { "buffer", 1, 0,
'b' }, {
+ "disablemid", 0, 0, 302 }, { "disablec2s", 0, 0, 303 }, {
"disables2c",
+ 0, 0, 304 }, { "disablesfw", 0, 0, 305 },
#ifdef AF_INET6
- {"ipv4", 0, 0, '4'},
- {"ipv6", 0, 0, '6'},
+ { "ipv4", 0, 0, '4'},
+ { "ipv6", 0, 0, '6'},
#endif
- {0, 0, 0, 0}
-};
+ { 0, 0, 0, 0 } };

void save_int_values(char *sysvar, int sysval);
void save_dbl_values(char *sysvar, float *sysval);
-
-void
-printVariables(char *tmpstr)
-{
- int i, j, k;
- char sysvar[128], sysval[128];
-
- k = strlen(tmpstr) - 1;
- i = 0;
- for (;;) {
- for (j=0; tmpstr[i]!=' '; j++)
- sysvar[j] = tmpstr[i++];
- sysvar[j] = '\0';
- i++;
- for (j=0; tmpstr[i]!='\n'; j++)
- sysval[j] = tmpstr[i++];
- sysval[j] = '\0';
- i++;
- printf("%s %s\n", sysvar, sysval);
- if (i >= k)
- return;
- }
+
+void printVariables(char *tmpstr) {
+ int i, j, k;
+ char sysvar[128], sysval[128];
+
+ k = strlen(tmpstr) - 1;
+ i = 0;
+ for (;;) {
+ for (j = 0; tmpstr[i] != ' '; j++)
+ sysvar[j] = tmpstr[i++];
+ sysvar[j] = '\0';
+ i++;
+ for (j = 0; tmpstr[i] != '\n'; j++)
+ sysval[j] = tmpstr[i++];
+ sysval[j] = '\0';
+ i++;
+ printf("%s %s\n", sysvar, sysval);
+ if (i >= k)
+ return;
+ }
}

-void
-printWeb100VarInfo()
-{
- int i = 0;
- printf(" --- Detailed description of the Web100 variables ---\n\n");
-
- while (web100vartable[i][0])
- {
- printf("* %s\n %s\n", web100vartable[i][0], web100vartable[i][1]);
- ++i;
- }
+void printWeb100VarInfo() {
+ int i = 0;
+ printf(" --- Detailed description of the Web100 variables ---\n\n");
+
+ while (web100vartable[i][0]) {
+ printf("* %s\n %s\n", web100vartable[i][0],
web100vartable[i][1]);
+ ++i;
+ }
}

-void
-testResults(char tests, char *tmpstr, char* host)
-{
- int i=0, Zero=0;
- char *sysvar, *sysval;
- float j;
-
- if (!(tests & TEST_S2C)) {
- if (tests & TEST_C2S) {
- if (c2sspd < (spdout * (1.0 - VIEW_DIFF))) {
- printf("Information [C2S]: Packet queuing detected: %0.2f%% ", 100 * (spdout - c2sspd) / spdout);
- if (sndqueue > (0.8 * pkts * lth * (spdout - c2sspd) / spdout)) {
- printf("(local buffers)\n");
- }
- else {
- printf("(remote buffers)\n");
- }
- }
- }
-
- results_sfw(tests, host);
- return;
- }
-
- sysvar = strtok(tmpstr, " ");
- sysval = strtok(NULL, "\n");
- i = atoi(sysval);
- save_int_values(sysvar, i);
-
- for(;;) {
- sysvar = strtok(NULL, " ");
- if (sysvar == NULL)
- break;
- sysval = strtok(NULL, "\n");
- if (strchr(sysval, '.') == NULL) {
- i = atoi(sysval);
- save_int_values(sysvar, i);
- log_println(7, "Stored %d [%s] in %s", i, sysval, sysvar);
- }
- else {
- j = atof(sysval);
- save_dbl_values(sysvar, &j);
- log_println(7, "Stored %0.2f (%s) in %s", j, sysval, sysvar);
- }
- }
-
- if(CountRTT > 0) {
-
- if (tests & TEST_C2S) {
- if (c2sData < 3) {
- if (c2sData < 0) {
- printf("Server unable to determine bottleneck link type.\n");
- } else {
- printf("Your host is connected to a ");
- if (c2sData == 1) {
- printf("Dial-up Modem\n");
- mylink = .064;
- } else {
- printf("Cable/DSL modem\n");
- mylink = 2;
- }
- }
- } else {
- printf("The slowest link in the end-to-end path is a ");
- if (c2sData == 3) {
- printf("10 Mbps Ethernet or WiFi 11b subnet\n");
- mylink = 10;
- } else if (c2sData == 4) {
- printf("45 Mbps T3/DS3 or WiFi 11 a/g subnet\n");
- mylink = 45;
- } else if (c2sData == 5) {
- printf("100 Mbps ");
- mylink = 100;
- if (half_duplex == 0) {
- printf("Full duplex Fast Ethernet subnet\n");
- } else {
- printf("Half duplex Fast Ethernet subnet\n");
- }
- } else if (c2sData == 6) {
- printf("a 622 Mbps OC-12 subnet\n");
- mylink = 622;
- } else if (c2sData == 7) {
- printf("1.0 Gbps Gigabit Ethernet subnet\n");
- mylink = 1000;
- } else if (c2sData == 8) {
- printf("2.4 Gbps OC-48 subnet\n");
- mylink = 2400;
- } else if (c2sData == 9) {
- printf("10 Gbps 10 Gigabit Ethernet/OC-192 subnet\n");
- mylink = 10000;
- }
- }
- }
-
- switch(mismatch) {
- case 1 : printf("Warning: Old Duplex-Mismatch condition detected.\n");
- break;
-
- case 2 : printf("Alarm: Duplex Mismatch condition detected. Switch=Full and Host=Half\n");
- break;
- case 4 : printf("Alarm: Possible Duplex Mismatch condition detected. Switch=Full and Host=Half\n");
- break;
-
- case 3 : printf("Alarm: Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
- break;
- case 5 : printf("Alarm: Possible Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
- break;
- case 7 : printf("Warning: Possible Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
- break;
- }
-
-
- if (mismatch == 0) {
- if (bad_cable == 1) {
- printf("Alarm: Excessive errors, check network cable(s).\n");
- }
- if (congestion == 1) {
- printf("Information: Other network traffic is congesting the link\n");
- }
- log_print(3, "Is larger buffer recommended? rwin*2/rttsec (%0.4f) < mylink (%0.4f) ", ((rwin*2)/rttsec), mylink);
- log_println(3, "AND j (%0.4f) > MaxRwinRcvd (%d)", (float)((mylink * avgrtt)*1000)/8, MaxRwinRcvd);
- if (((rwin*2)/rttsec) < mylink) {
- j = (float)((mylink * avgrtt)*1000) / 8;
- if ((int)j > MaxRwinRcvd) {
- printf("Information: The receive buffer should be %0.0f ", j/1024);
- printf("kbytes to maximize throughput\n");
- }
- }
- }
-
- if (tests & TEST_C2S) {
- if (c2sspd < (spdout * (1.0 - VIEW_DIFF))) {
- printf("Information [C2S]: Packet queuing detected: %0.2f%% ", 100 * (spdout - c2sspd) / spdout);
- if (sndqueue > (0.8 * pkts * lth * (spdout - c2sspd) / spdout)) {
- printf("(local buffers)\n");
- }
- else {
- printf("(remote buffers)\n");
- }
- }
- }
- if (tests & TEST_S2C) {
- if (spdin < (s2cspd * (1.0 - VIEW_DIFF))) {
- printf("Information [S2C]: Packet queuing detected: %0.2f%% ", 100 * (s2cspd - spdin) / s2cspd);
- if (ssndqueue > (0.8 * sbytes * (s2cspd - spdin) / s2cspd)) {
- printf("(local buffers)\n");
- }
- else {
- printf("(remote buffers)\n");
- }
- }
- }
-
- results_sfw(tests, host);
-
- if (msglvl > 0) {
- printf("\n\t------ Web100 Detailed Analysis ------\n");
-
- printf("\nWeb100 reports the Round trip time = %0.2f msec;", avgrtt);
-
- printf("the Packet size = %d Bytes; and \n", CurrentMSS);
- if (PktsRetrans > 0) {
- printf("There were %d packets retransmitted", PktsRetrans);
- printf(", %d duplicate acks received", DupAcksIn);
- printf(", and %d SACK blocks received\n", SACKsRcvd);
- if (order > 0)
- printf("Packets arrived out-of-order %0.2f%% of the time.\n", order*100);
- if (Timeouts > 0)
- printf("The connection stalled %d times due to packet loss.\n", Timeouts);
- if (waitsec > 0)
- printf("The connection was idle %0.2f seconds (%0.2f%%) of the time.\n",
- waitsec, (100*waitsec/timesec));
- } else if (DupAcksIn > 0) {
- printf("No packet loss - ");
- if (order > 0)
- printf("but packets arrived out-of-order %0.2f%% of the time.\n", order*100);
- else
- printf("\n");
- } else {
- printf("No packet loss was observed.\n");
- }
-
- if (rwintime > .015) {
- printf("This connection is receiver limited %0.2f%% of the time.\n", rwintime*100);
- if ((2*(rwin/rttsec)) < mylink)
- printf(" Increasing the current receive buffer (%0.2f KB) will improve performance\n",
- (float) MaxRwinRcvd/1024);
- }
- if (sendtime > .015) {
- printf("This connection is sender limited %0.2f%% of the time.\n", sendtime*100);
- if ((2*(swin/rttsec)) < mylink)
- printf(" Increasing the current send buffer (%0.2f KB) will improve performance\n",
- (float) Sndbuf/1024);
- }
- if (cwndtime > .005) {
- printf("This connection is network limited %0.2f%% of the time.\n", cwndtime*100);
- }
- if ((spd < 4) && (loss > .01)) {
- printf("Excessive packet loss is impacting your performance, check the ");
- printf("auto-negotiate function on your local PC and network switch\n");
- }
- printf("\n Web100 reports TCP negotiated the optional Performance Settings to: \n");
- printf("RFC 2018 Selective Acknowledgment: ");
- if(SACKEnabled == Zero)
- printf("OFF\n");
- else
- printf("ON\n");
-
- printf("RFC 896 Nagle Algorithm: ");
- if(NagleEnabled == Zero)
- printf("OFF\n");
- else
- printf("ON\n");
-
- printf("RFC 3168 Explicit Congestion Notification: ");
- if(ECNEnabled == Zero)
- printf("OFF\n");
- else
- printf("ON\n");
-
- printf("RFC 1323 Time Stamping: ");
- if(TimestampsEnabled == 0)
- printf("OFF\n");
- else
- printf("ON\n");
-
- printf("RFC 1323 Window Scaling: ");
- if (MaxRwinRcvd < 65535)
- WinScaleRcvd = 0;
-
- if((WinScaleRcvd == 0) || (WinScaleRcvd > 20))
- printf("OFF\n");
- else
- printf("ON; Scaling Factors - Server=%d, Client=%d\n",
- WinScaleRcvd, WinScaleSent);
-
- if ((RcvWinScale == 0) && (Sndbuf > 65535))
- Sndbuf = 65535;
-
- printf("The theoretical network limit is %0.2f Mbps\n", estimate);
-
- printf("The NDT server has a %0.0f KByte buffer which limits the throughput to %0.2f Mbps\n",
- (float)Sndbuf/1024, (float)swin/rttsec);
-
- printf("Your PC/Workstation has a %0.0f KByte buffer which limits the throughput to %0.2f Mbps\n",
- (float)MaxRwinRcvd/1024, (float)rwin/rttsec);
-
- printf("The network based flow control limits the throughput to %0.2f Mbps\n",
- (float)cwin/rttsec);
-
- if (tests & TEST_C2S) {
- printf("\nClient Data reports link is '%3d', Client Acks report link is '%3d'\n",
- c2sData, c2sAck);
- }
- printf("Server Data reports link is '%3d', Server Acks report link is '%3d'\n",
- s2cData, s2cAck);
- }
- } else {
- printf("No Web100 data collected! Possible Duplex Mismatch condition caused ");
- printf("Server to client test to run long.\nCheck for host=Full and switch=Half ");
- printf("mismatch condition\n");
- }
+void testResults(char tests, char *tmpstr, char* host) {
+ int i = 0, Zero = 0;
+ char *sysvar, *sysval;
+ float j;
+
+ if (!(tests & TEST_S2C)) {
+ if (tests & TEST_C2S) {
+ if (c2sspd < (spdout * (1.0 - VIEW_DIFF))) {
+ printf("Information [C2S]: Packet queuing
detected: %0.2f%% ",
+ 100 * (spdout - c2sspd) /
spdout);
+ if (sndqueue
+ > (0.8 * pkts * lth * (spdout
- c2sspd) / spdout)) {
+ printf("(local buffers)\n");
+ } else {
+ printf("(remote buffers)\n");
+ }
+ }
+ }
+
+ results_sfw(tests, host);
+ return;
+ }
+
+ sysvar = strtok(tmpstr, " ");
+ sysval = strtok(NULL, "\n");
+ i = atoi(sysval);
+ save_int_values(sysvar, i);
+
+ for (;;) {
+ sysvar = strtok(NULL, " ");
+ if (sysvar == NULL)
+ break;
+ sysval = strtok(NULL, "\n");
+ if (strchr(sysval, '.') == NULL) {
+ i = atoi(sysval);
+ save_int_values(sysvar, i);
+ log_println(7, "Stored %d [%s] in %s", i, sysval,
sysvar);
+ } else {
+ j = atof(sysval);
+ save_dbl_values(sysvar, &j);
+ log_println(7, "Stored %0.2f (%s) in %s", j, sysval,
sysvar);
+ }
+ }
+
+ if (CountRTT > 0) {
+
+ if (tests & TEST_C2S) {
+ if (c2sData < 3) {
+ if (c2sData < 0) {
+ printf(
+ "Server unable to
determine bottleneck link type.\n");
+ } else {
+ printf("Your host is connected to a
");
+ if (c2sData == 1) {
+ printf("Dial-up Modem\n");
+ mylink = .064;
+ } else {
+ printf("Cable/DSL modem\n");
+ mylink = 2;
+ }
+ }
+ } else {
+ printf("The slowest link in the end-to-end path is
a ");
+ if (c2sData == 3) {
+ printf("10 Mbps Ethernet or WiFi 11b
subnet\n");
+ mylink = 10;
+ } else if (c2sData == 4) {
+ printf("45 Mbps T3/DS3 or WiFi 11 a/g
subnet\n");
+ mylink = 45;
+ } else if (c2sData == 5) {
+ printf("100 Mbps ");
+ mylink = 100;
+ if (half_duplex == 0) {
+ printf("Full duplex Fast Ethernet
subnet\n");
+ } else {
+ printf("Half duplex Fast Ethernet
subnet\n");
+ }
+ } else if (c2sData == 6) {
+ printf("a 622 Mbps OC-12 subnet\n");
+ mylink = 622;
+ } else if (c2sData == 7) {
+ printf("1.0 Gbps Gigabit Ethernet
subnet\n");
+ mylink = 1000;
+ } else if (c2sData == 8) {
+ printf("2.4 Gbps OC-48 subnet\n");
+ mylink = 2400;
+ } else if (c2sData == 9) {
+ printf("10 Gbps 10 Gigabit Ethernet/OC-192
subnet\n");
+ mylink = 10000;
+ }
+ }
+ }
+
+ switch (mismatch) {
+ case 1:
+ printf("Warning: Old Duplex-Mismatch condition
detected.\n");
+ break;
+
+ case 2:
+ printf(
+ "Alarm: Duplex Mismatch condition detected. Switch=Full and Host=Half\n");
+ break;
+ case 4:
+ printf(
+ "Alarm: Possible Duplex Mismatch condition detected. Switch=Full and Host=Half\n");
+ break;
+
+ case 3:
+ printf(
+ "Alarm: Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
+ break;
+ case 5:
+ printf(
+ "Alarm: Possible Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
+ break;
+ case 7:
+ printf(
+ "Warning: Possible Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
+ break;
+ }
+
+ if (mismatch == 0) {
+ if (bad_cable == 1) {
+ printf("Alarm: Excessive errors, check network
cable(s).\n");
+ }
+ if (congestion == 1) {
+ printf(
+ "Information: Other network
traffic is congesting the link\n");
+ }
+ log_print(
+ 3,
+ "Is larger buffer recommended? rwin*2/rttsec (%0.4f) < mylink (%0.4f) ",
+ ((rwin * 2) / rttsec), mylink);
+ log_println(3, "AND j (%0.4f) > MaxRwinRcvd (%d)",
+ (float) ((mylink * avgrtt) * 1000) /
8, MaxRwinRcvd);
+ if (((rwin * 2) / rttsec) < mylink) {
+ j = (float) ((mylink * avgrtt) * 1000) / 8;
+ if ((int) j > MaxRwinRcvd) {
+ printf("Information: The receive buffer
should be %0.0f ",
+ j / 1024);
+ printf("kbytes to maximize
throughput\n");
+ }
+ }
+ }
+
+ if (tests & TEST_C2S) {
+ if (c2sspd < (spdout * (1.0 - VIEW_DIFF))) {
+ printf("Information [C2S]: Packet queuing
detected: %0.2f%% ",
+ 100 * (spdout - c2sspd) /
spdout);
+ if (sndqueue
+ > (0.8 * pkts * lth * (spdout
- c2sspd) / spdout)) {
+ printf("(local buffers)\n");
+ } else {
+ printf("(remote buffers)\n");
+ }
+ }
+ }
+ if (tests & TEST_S2C) {
+ if (spdin < (s2cspd * (1.0 - VIEW_DIFF))) {
+ printf("Information [S2C]: Packet queuing
detected: %0.2f%% ",
+ 100 * (s2cspd - spdin) /
s2cspd);
+ if (ssndqueue > (0.8 * sbytes * (s2cspd -
spdin) / s2cspd)) {
+ printf("(local buffers)\n");
+ } else {
+ printf("(remote buffers)\n");
+ }
+ }
+ }
+
+ results_sfw(tests, host);
+
+ if (msglvl > 0) {
+ printf("\n\t------ Web100 Detailed Analysis
------\n");
+
+ printf("\nWeb100 reports the Round trip time = %0.2f
msec;",
+ avgrtt);
+
+ printf("the Packet size = %d Bytes; and \n",
CurrentMSS);
+ if (PktsRetrans > 0) {
+ printf("There were %d packets retransmitted",
PktsRetrans);
+ printf(", %d duplicate acks received",
DupAcksIn);
+ printf(", and %d SACK blocks received\n",
SACKsRcvd);
+ if (order > 0)
+ printf(
+ "Packets arrived
out-of-order %0.2f%% of the time.\n",
+ order * 100);
+ if (Timeouts > 0)
+ printf(
+ "The connection stalled %d
times due to packet loss.\n",
+ Timeouts);
+ if (waitsec > 0)
+ printf(
+ "The connection was idle
%0.2f seconds (%0.2f%%) of the time.\n",
+ waitsec, (100 *
waitsec / timesec));
+ } else if (DupAcksIn > 0) {
+ printf("No packet loss - ");
+ if (order > 0)
+ printf(
+ "but packets arrived
out-of-order %0.2f%% of the time.\n",
+ order * 100);
+ else
+ printf("\n");
+ } else {
+ printf("No packet loss was observed.\n");
+ }
+
+ if (rwintime > .015) {
+ printf(
+ "This connection is receiver
limited %0.2f%% of the time.\n",
+ rwintime * 100);
+ if ((2 * (rwin / rttsec)) < mylink)
+ printf(
+ " Increasing the current receive buffer (%0.2f KB) will improve performance\n",
+ (float) MaxRwinRcvd /
1024);
+ }
+ if (sendtime > .015) {
+ printf(
+ "This connection is sender limited
%0.2f%% of the time.\n",
+ sendtime * 100);
+ if ((2 * (swin / rttsec)) < mylink)
+ printf(
+ " Increasing the current send buffer (%0.2f KB) will improve performance\n",
+ (float) Sndbuf /
1024);
+ }
+ if (cwndtime > .005) {
+ printf(
+ "This connection is network
limited %0.2f%% of the time.\n",
+ cwndtime * 100);
+ }
+ if ((spd < 4) && (loss > .01)) {
+ printf(
+ "Excessive packet loss is
impacting your performance, check the ");
+ printf(
+ "auto-negotiate function on your
local PC and network switch\n");
+ }
+ printf(
+ "\n Web100 reports TCP negotiated the optional Performance Settings to: \n");
+ printf("RFC 2018 Selective Acknowledgment: ");
+ if (SACKEnabled == Zero)
+ printf("OFF\n");
+ else
+ printf("ON\n");
+
+ printf("RFC 896 Nagle Algorithm: ");
+ if (NagleEnabled == Zero)
+ printf("OFF\n");
+ else
+ printf("ON\n");
+
+ printf("RFC 3168 Explicit Congestion Notification: ");
+ if (ECNEnabled == Zero)
+ printf("OFF\n");
+ else
+ printf("ON\n");
+
+ printf("RFC 1323 Time Stamping: ");
+ if (TimestampsEnabled == 0)
+ printf("OFF\n");
+ else
+ printf("ON\n");
+
+ printf("RFC 1323 Window Scaling: ");
+ if (MaxRwinRcvd < 65535)
+ WinScaleRcvd = 0;
+
+ if ((WinScaleRcvd == 0) || (WinScaleRcvd > 20))
+ printf("OFF\n");
+ else
+ printf("ON; Scaling Factors - Server=%d,
Client=%d\n",
+ WinScaleRcvd, WinScaleSent);
+
+ if ((RcvWinScale == 0) && (Sndbuf > 65535))
+ Sndbuf = 65535;
+
+ printf("The theoretical network limit is %0.2f
Mbps\n", estimate);
+
+ printf(
+ "The NDT server has a %0.0f KByte buffer which limits the throughput to %0.2f Mbps\n",
+ (float) Sndbuf / 1024, (float) swin /
rttsec);
+
+ printf(
+ "Your PC/Workstation has a %0.0f KByte buffer which limits the throughput to %0.2f Mbps\n",
+ (float) MaxRwinRcvd / 1024, (float)
rwin / rttsec);
+
+ printf(
+ "The network based flow control limits the throughput to %0.2f Mbps\n",
+ (float) cwin / rttsec);
+
+ if (tests & TEST_C2S) {
+ printf(
+ "\nClient Data reports link is '%3d', Client Acks report link is '%3d'\n",
+ c2sData, c2sAck);
+ }
+ printf(
+ "Server Data reports link is '%3d', Server Acks report link is '%3d'\n",
+ s2cData, s2cAck);
+ }
+ } else {
+ printf(
+ "No Web100 data collected! Possible Duplex Mismatch condition caused ");
+ printf(
+ "Server to client test to run long.\nCheck for host=Full and switch=Half ");
+ printf("mismatch condition\n");
+ }
}

/* this routine decodes the middlebox test results. The data is returned
@@ -381,548 +410,563 @@
* Server IP; Client IP.
*/

-void
-middleboxResults(char *tmpstr, I2Addr local_addr, I2Addr peer_addr)
-{
- char ssip[64], scip[64], *str;
- char csip[64], ccip[64];
- int mss;
- size_t tmpLen;
-
- str = strtok(tmpstr, ";");
- //strcpy(ssip, str);
- strlcpy(ssip, str, sizeof(ssip));
- str = strtok(NULL, ";");
- //strcpy(scip, str);
- strlcpy(scip, str, sizeof(scip));
-
- str = strtok(NULL, ";");
- mss = atoi(str);
- str = strtok(NULL, ";");
- winsrecv = atoi(str);
- str = strtok(NULL, ";");
- winssent = atoi(str);
-
- memset(ccip, 0, 64);
- tmpLen = 63;
- I2AddrNodeName(local_addr, ccip, &tmpLen);
- memset(csip, 0, 64);
- tmpLen = 63;
- I2AddrNodeName(peer_addr, csip, &tmpLen);
-
- if (TimestampsEnabled == 1)
- mss += 12;
- if (mss == 1456)
- printf("Packet size is preserved End-to-End\n");
- else
- printf("Information: Network Middlebox is modifying MSS variable (changed to %d)\n", mss);
-
- if (strcmp(ssip, csip) == 0)
- printf("Server IP addresses are preserved End-to-End\n");
- else {
- printf("Information: Network Address Translation (NAT) box is ");
- printf("modifying the Server's IP address\n");
- printf("\tServer says [%s] but Client says [ %s]\n", ssip, csip);
- }
-
- if (strcmp(scip, ccip) == 0)
- printf("Client IP addresses are preserved End-to-End\n");
- else {
- printf("Information: Network Address Translation (NAT) box is ");
- printf("modifying the Client's IP address\n");
- printf("\tServer says [%s] but Client says [ %s]\n", scip, ccip);
- }
+void middleboxResults(char *tmpstr, I2Addr local_addr, I2Addr peer_addr) {
+ char ssip[64], scip[64], *str;
+ char csip[64], ccip[64];
+ int mss;
+ size_t tmpLen;
+
+ str = strtok(tmpstr, ";");
+ //strcpy(ssip, str);
+ strlcpy(ssip, str, sizeof(ssip));
+ str = strtok(NULL, ";");
+ //strcpy(scip, str);
+ strlcpy(scip, str, sizeof(scip));
+
+ str = strtok(NULL, ";");
+ mss = atoi(str);
+ str = strtok(NULL, ";");
+ winsrecv = atoi(str);
+ str = strtok(NULL, ";");
+ winssent = atoi(str);
+
+ memset(ccip, 0, 64);
+ tmpLen = 63;
+ I2AddrNodeName(local_addr, ccip, &tmpLen);
+ memset(csip, 0, 64);
+ tmpLen = 63;
+ I2AddrNodeName(peer_addr, csip, &tmpLen);
+
+ if (TimestampsEnabled == 1)
+ mss += 12;
+ if (mss == 1456)
+ printf("Packet size is preserved End-to-End\n");
+ else
+ printf(
+ "Information: Network Middlebox is modifying MSS variable (changed to %d)\n",
+ mss);
+
+ if (strcmp(ssip, csip) == 0)
+ printf("Server IP addresses are preserved End-to-End\n");
+ else {
+ printf("Information: Network Address Translation (NAT) box is
");
+ printf("modifying the Server's IP address\n");
+ printf("\tServer says [%s] but Client says [ %s]\n", ssip,
csip);
+ }
+
+ if (strcmp(scip, ccip) == 0)
+ printf("Client IP addresses are preserved End-to-End\n");
+ else {
+ printf("Information: Network Address Translation (NAT) box is
");
+ printf("modifying the Client's IP address\n");
+ printf("\tServer says [%s] but Client says [ %s]\n", scip,
ccip);
+ }
}

-void
-save_int_values(char *sysvar, int sysval)
-{
- /* Values saved for interpretation:
- * SumRTT
- * CountRTT
- * CurrentMSS
- * Timeouts
- * PktsRetrans
- * SACKsRcvd
- * DupAcksIn
- * MaxRwinRcvd
- * MaxRwinSent
- * Sndbuf
- * Rcvbuf
- * DataPktsOut
- * SndLimTimeRwin
- * SndLimTimeCwnd
- * SndLimTimeSender
- */
-
- log_println(6, "save_int_values(%s, %d)", sysvar, sysval);
-
- if(strcmp("MSSSent:", sysvar) == 0)
- MSSSent = sysval;
- else if(strcmp("MSSRcvd:", sysvar) == 0)
- MSSRcvd = sysval;
- else if(strcmp("ECNEnabled:", sysvar) == 0)
- ECNEnabled = sysval;
- else if(strcmp("NagleEnabled:", sysvar) == 0)
- NagleEnabled = sysval;
- else if(strcmp("SACKEnabled:", sysvar) == 0)
- SACKEnabled = sysval;
- else if(strcmp("TimestampsEnabled:", sysvar) == 0)
- TimestampsEnabled = sysval;
- else if(strcmp("WinScaleRcvd:", sysvar) == 0)
- WinScaleRcvd = sysval;
- else if(strcmp("WinScaleSent:", sysvar) == 0)
- WinScaleSent = sysval;
- else if(strcmp("SumRTT:", sysvar) == 0)
- SumRTT = sysval;
- else if(strcmp("CountRTT:", sysvar) == 0)
- CountRTT = sysval;
- else if(strcmp("CurMSS:", sysvar) == 0)
- CurrentMSS = sysval;
- else if(strcmp("Timeouts:", sysvar) == 0)
- Timeouts = sysval;
- else if(strcmp("PktsRetrans:", sysvar) == 0)
- PktsRetrans = sysval;
- else if(strcmp("SACKsRcvd:", sysvar) == 0)
- SACKsRcvd = sysval;
- else if(strcmp("DupAcksIn:", sysvar) == 0)
- DupAcksIn = sysval;
- else if(strcmp("MaxRwinRcvd:", sysvar) == 0)
- MaxRwinRcvd = sysval;
- else if(strcmp("MaxRwinSent:", sysvar) == 0)
- MaxRwinSent = sysval;
- else if(strcmp("Sndbuf:", sysvar) == 0)
- Sndbuf = sysval;
- else if(strcmp("X_Rcvbuf:", sysvar) == 0)
- Rcvbuf = sysval;
- else if(strcmp("DataPktsOut:", sysvar) == 0)
- DataPktsOut = sysval;
- else if(strcmp("FastRetran:", sysvar) == 0)
- FastRetran = sysval;
- else if(strcmp("AckPktsOut:", sysvar) == 0)
- AckPktsOut = sysval;
- else if(strcmp("SmoothedRTT:", sysvar) == 0)
- SmoothedRTT = sysval;
- else if(strcmp("CurCwnd:", sysvar) == 0)
- CurrentCwnd = sysval;
- else if(strcmp("MaxCwnd:", sysvar) == 0)
- MaxCwnd = sysval;
- else if(strcmp("SndLimTimeRwin:", sysvar) == 0)
- SndLimTimeRwin = sysval;
- else if(strcmp("SndLimTimeCwnd:", sysvar) == 0)
- SndLimTimeCwnd = sysval;
- else if(strcmp("SndLimTimeSender:", sysvar) == 0)
- SndLimTimeSender = sysval;
- else if(strcmp("DataBytesOut:", sysvar) == 0)
- DataBytesOut = sysval;
- else if(strcmp("AckPktsIn:", sysvar) == 0)
- AckPktsIn = sysval;
- else if(strcmp("SndLimTransRwin:", sysvar) == 0)
- SndLimTransRwin = sysval;
- else if(strcmp("SndLimTransCwnd:", sysvar) == 0)
- SndLimTransCwnd = sysval;
- else if(strcmp("SndLimTransSender:", sysvar) == 0)
- SndLimTransSender = sysval;
- else if(strcmp("MaxSsthresh:", sysvar) == 0)
- MaxSsthresh = sysval;
- else if(strcmp("CurRTO:", sysvar) == 0)
- CurrentRTO = sysval;
- else if(strcmp("c2sData:", sysvar) == 0)
- c2sData = sysval;
- else if(strcmp("c2sAck:", sysvar) == 0)
- c2sAck = sysval;
- else if(strcmp("s2cData:", sysvar) == 0)
- s2cData = sysval;
- else if(strcmp("s2cAck:", sysvar) == 0)
- s2cAck = sysval;
- else if(strcmp("PktsOut:", sysvar) == 0)
- PktsOut = sysval;
- else if(strcmp("mismatch:", sysvar) == 0)
- mismatch = sysval;
- else if(strcmp("bad_cable:", sysvar) == 0)
- bad_cable = sysval;
- else if(strcmp("congestion:", sysvar) == 0)
- congestion = sysval;
- else if(strcmp("half_duplex:", sysvar) == 0)
- half_duplex = sysval;
- else if(strcmp("CongestionSignals:", sysvar) == 0)
- CongestionSignals = sysval;
- else if(strcmp("RcvWinScale:", sysvar) == 0) {
- if (sysval > 15)
- RcvWinScale = 0;
- else
- RcvWinScale = sysval;
- }
- else if(strcmp("minCWNDpeak:", sysvar) == 0)
- minPeak = sysval;
- else if(strcmp("maxCWNDpeak:", sysvar) == 0)
- maxPeak = sysval;
- else if(strcmp("CWNDpeaks:", sysvar) == 0)
- peaks = sysval;
+void save_int_values(char *sysvar, int sysval) {
+ /* Values saved for interpretation:
+ * SumRTT
+ * CountRTT
+ * CurrentMSS
+ * Timeouts
+ * PktsRetrans
+ * SACKsRcvd
+ * DupAcksIn
+ * MaxRwinRcvd
+ * MaxRwinSent
+ * Sndbuf
+ * Rcvbuf
+ * DataPktsOut
+ * SndLimTimeRwin
+ * SndLimTimeCwnd
+ * SndLimTimeSender
+ */
+
+ log_println(6, "save_int_values(%s, %d)", sysvar, sysval);
+
+ if (strcmp("MSSSent:", sysvar) == 0)
+ MSSSent = sysval;
+ else if (strcmp("MSSRcvd:", sysvar) == 0)
+ MSSRcvd = sysval;
+ else if (strcmp("ECNEnabled:", sysvar) == 0)
+ ECNEnabled = sysval;
+ else if (strcmp("NagleEnabled:", sysvar) == 0)
+ NagleEnabled = sysval;
+ else if (strcmp("SACKEnabled:", sysvar) == 0)
+ SACKEnabled = sysval;
+ else if (strcmp("TimestampsEnabled:", sysvar) == 0)
+ TimestampsEnabled = sysval;
+ else if (strcmp("WinScaleRcvd:", sysvar) == 0)
+ WinScaleRcvd = sysval;
+ else if (strcmp("WinScaleSent:", sysvar) == 0)
+ WinScaleSent = sysval;
+ else if (strcmp("SumRTT:", sysvar) == 0)
+ SumRTT = sysval;
+ else if (strcmp("CountRTT:", sysvar) == 0)
+ CountRTT = sysval;
+ else if (strcmp("CurMSS:", sysvar) == 0)
+ CurrentMSS = sysval;
+ else if (strcmp("Timeouts:", sysvar) == 0)
+ Timeouts = sysval;
+ else if (strcmp("PktsRetrans:", sysvar) == 0)
+ PktsRetrans = sysval;
+ else if (strcmp("SACKsRcvd:", sysvar) == 0)
+ SACKsRcvd = sysval;
+ else if (strcmp("DupAcksIn:", sysvar) == 0)
+ DupAcksIn = sysval;
+ else if (strcmp("MaxRwinRcvd:", sysvar) == 0)
+ MaxRwinRcvd = sysval;
+ else if (strcmp("MaxRwinSent:", sysvar) == 0)
+ MaxRwinSent = sysval;
+ else if (strcmp("Sndbuf:", sysvar) == 0)
+ Sndbuf = sysval;
+ else if (strcmp("X_Rcvbuf:", sysvar) == 0)
+ Rcvbuf = sysval;
+ else if (strcmp("DataPktsOut:", sysvar) == 0)
+ DataPktsOut = sysval;
+ else if (strcmp("FastRetran:", sysvar) == 0)
+ FastRetran = sysval;
+ else if (strcmp("AckPktsOut:", sysvar) == 0)
+ AckPktsOut = sysval;
+ else if (strcmp("SmoothedRTT:", sysvar) == 0)
+ SmoothedRTT = sysval;
+ else if (strcmp("CurCwnd:", sysvar) == 0)
+ CurrentCwnd = sysval;
+ else if (strcmp("MaxCwnd:", sysvar) == 0)
+ MaxCwnd = sysval;
+ else if (strcmp("SndLimTimeRwin:", sysvar) == 0)
+ SndLimTimeRwin = sysval;
+ else if (strcmp("SndLimTimeCwnd:", sysvar) == 0)
+ SndLimTimeCwnd = sysval;
+ else if (strcmp("SndLimTimeSender:", sysvar) == 0)
+ SndLimTimeSender = sysval;
+ else if (strcmp("DataBytesOut:", sysvar) == 0)
+ DataBytesOut = sysval;
+ else if (strcmp("AckPktsIn:", sysvar) == 0)
+ AckPktsIn = sysval;
+ else if (strcmp("SndLimTransRwin:", sysvar) == 0)
+ SndLimTransRwin = sysval;
+ else if (strcmp("SndLimTransCwnd:", sysvar) == 0)
+ SndLimTransCwnd = sysval;
+ else if (strcmp("SndLimTransSender:", sysvar) == 0)
+ SndLimTransSender = sysval;
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/web100srv.c Mon Oct 17 06:31:32
2011
+++ /branches/kkumar_code_organize/src/web100srv.c Mon Oct 17 06:43:25
2011
@@ -1,63 +1,63 @@
/*
-Copyright (c) 2003 University of Chicago. All rights reserved.
-The Web100 Network Diagnostic Tool (NDT) is distributed subject to
-the following license conditions:
-SOFTWARE LICENSE AGREEMENT
-Software: Web100 Network Diagnostic Tool (NDT)
-
-1. The "Software", below, refers to the Web100 Network Diagnostic Tool (NDT)
-(in either source code, or binary form and accompanying documentation). Each
-licensee is addressed as "you" or "Licensee."
-
-2. The copyright holder shown above hereby grants Licensee a royalty-free
-nonexclusive license, subject to the limitations stated herein and U.S. Government
-license rights.
-
-3. You may modify and make a copy or copies of the Software for use within your
-organization, if you meet the following conditions:
- a. Copies in source code must include the copyright notice and this Software
- License Agreement.
- b. Copies in binary form must include the copyright notice and this Software
- License Agreement in the documentation and/or other materials provided with the copy.
-
-4. You may make a copy, or modify a copy or copies of the Software or any
-portion of it, thus forming a work based on the Software, and distribute copies
-outside your organization, if you meet all of the following conditions:
- a. Copies in source code must include the copyright notice and this
- Software License Agreement;
- b. Copies in binary form must include the copyright notice and this
- Software License Agreement in the documentation and/or other materials
- provided with the copy;
- c. Modified copies and works based on the Software must carry prominent
- notices stating that you changed specified portions of the Software.
-
-5. Portions of the Software resulted from work developed under a U.S. Government
-contract and are subject to the following license: the Government is granted
-for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable
-worldwide license in this computer software to reproduce, prepare derivative
-works, and perform publicly and display publicly.
-
-6. WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY
-OF ANY KIND. THE COPYRIGHT HOLDER, THE UNITED STATES, THE UNITED STATES
-DEPARTMENT OF ENERGY, AND THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR NON-INFRINGEMENT,
-(2) DO NOT ASSUME ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
-COMPLETENESS, OR USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE
-OF THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4) DO NOT WARRANT
-THAT THE SOFTWARE WILL FUNCTION UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT
-ANY ERRORS WILL BE CORRECTED.
-
-7. LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT HOLDER, THE
-UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, OR THEIR EMPLOYEES:
-BE LIABLE FOR ANY INDIRECT, INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE
-DAMAGES OF ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS
-OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER SUCH LIABILITY IS ASSERTED
-ON THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR
-OTHERWISE, EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE POSSIBILITY OF
-SUCH LOSS OR DAMAGES.
-The Software was developed at least in part by the University of Chicago,
-as Operator of Argonne National Laboratory (http://miranda.ctd.anl.gov:7123/).
+ Copyright (c) 2003 University of Chicago. All rights reserved.
+ The Web100 Network Diagnostic Tool (NDT) is distributed subject to
+ the following license conditions:
+ SOFTWARE LICENSE AGREEMENT
+ Software: Web100 Network Diagnostic Tool (NDT)
+
+ 1. The "Software", below, refers to the Web100 Network Diagnostic Tool (NDT)
+ (in either source code, or binary form and accompanying documentation). Each
+ licensee is addressed as "you" or "Licensee."
+
+ 2. The copyright holder shown above hereby grants Licensee a royalty-free
+ nonexclusive license, subject to the limitations stated herein and U.S. Government
+ license rights.
+
+ 3. You may modify and make a copy or copies of the Software for use within your
+ organization, if you meet the following conditions:
+ a. Copies in source code must include the copyright notice and this Software
+ License Agreement.
+ b. Copies in binary form must include the copyright notice and this Software
+ License Agreement in the documentation and/or other materials provided with the copy.
+
+ 4. You may make a copy, or modify a copy or copies of the Software or any
+ portion of it, thus forming a work based on the Software, and distribute copies
+ outside your organization, if you meet all of the following conditions:
+ a. Copies in source code must include the copyright notice and this
+ Software License Agreement;
+ b. Copies in binary form must include the copyright notice and this
+ Software License Agreement in the documentation and/or other materials
+ provided with the copy;
+ c. Modified copies and works based on the Software must carry prominent
+ notices stating that you changed specified portions of the Software.
+
+ 5. Portions of the Software resulted from work developed under a U.S. Government
+ contract and are subject to the following license: the Government is granted
+ for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable
+ worldwide license in this computer software to reproduce, prepare derivative
+ works, and perform publicly and display publicly.
+
+ 6. WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY
+ OF ANY KIND. THE COPYRIGHT HOLDER, THE UNITED STATES, THE UNITED STATES
+ DEPARTMENT OF ENERGY, AND THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR NON-INFRINGEMENT,
+ (2) DO NOT ASSUME ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
+ COMPLETENESS, OR USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE
+ OF THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4) DO NOT WARRANT
+ THAT THE SOFTWARE WILL FUNCTION UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT
+ ANY ERRORS WILL BE CORRECTED.
+
+ 7. LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT HOLDER, THE
+ UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, OR THEIR EMPLOYEES:
+ BE LIABLE FOR ANY INDIRECT, INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE
+ DAMAGES OF ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS
+ OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER SUCH LIABILITY IS ASSERTED
+ ON THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR
+ OTHERWISE, EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE POSSIBILITY OF
+ SUCH LOSS OR DAMAGES.
+ The Software was developed at least in part by the University of Chicago,
+ as Operator of Argonne National Laboratory (http://miranda.ctd.anl.gov:7123/).
*/

#include "../config.h"
@@ -85,36 +85,36 @@
#include "strlutils.h"
#include "heuristics.h"

-static char lgfn[FILENAME_SIZE]; // log file name
-static char wvfn[FILENAME_SIZE]; // file name of web100-variables list
-static char apfn[FILENAME_SIZE]; // admin file name
-static char slfa[256]; // syslog facility
-static char logd[256]; // log dir name
-static char portbuf[10]; // port number user option store
-static char devicebuf[100]; // device name buf (seems unused)
-static char dbDSNbuf[256]; // DB datasource name
-static char dbUIDbuf[256]; // DB UID
-static char dbPWDbuf[256]; // DB Password
+static char lgfn[FILENAME_SIZE]; // log file name
+static char wvfn[FILENAME_SIZE]; // file name of web100-variables list
+static char apfn[FILENAME_SIZE]; // admin file name
+static char slfa[256]; // syslog facility
+static char logd[256]; // log dir name
+static char portbuf[10]; // port number user option store
+static char devicebuf[100]; // device name buf (seems unused)
+static char dbDSNbuf[256]; // DB datasource name
+static char dbUIDbuf[256]; // DB UID
+static char dbPWDbuf[256]; // DB Password

// list of global variables used throughout this program.
-int window = 64000; // TCP buffer size
-int randomize=0;
-int count_vars=0;
-int dumptrace=0;
-int usesyslog=0;
-int multiple=0;
-int compress=1;
-int max_clients=50;
-int set_buff=0;
-int admin_view=0;
-int queue=1;
-int view_flag=0;
-int record_reverse=0;
+int window = 64000; // TCP buffer size
+int randomize = 0;
+int count_vars = 0;
+int dumptrace = 0;
+int usesyslog = 0;
+int multiple = 0;
+int compress = 1;
+int max_clients = 50;
+int set_buff = 0;
+int admin_view = 0;
+int queue = 1;
+int view_flag = 0;
+int record_reverse = 0;
int testing; // a test is currently being performed.
int waiting; // # of many tests pending
int mclients; // multiple client mode client count
int refresh = 30;
-int old_mismatch=0; /* use the old duplex mismatch detection heuristic */
+int old_mismatch = 0; /* use the old duplex mismatch detection heuristic */
/* int sig1, sig2, sig17; */

Options options;
@@ -122,23 +122,22 @@
int cputime = 0;
char cputimelog[256];
pthread_t workerThreadId, zombieThreadId;
-int cputimeworkerLoop=1, zombie_check=0;
+int cputimeworkerLoop = 1, zombie_check = 0;

int useDB = 0;
char* dbDSN = NULL;
char* dbUID = NULL;
char* dbPWD = NULL;

-char *VarFileName=NULL;
-char *AdminFileName=NULL;
-char *SysLogFacility=NULL;
+char *VarFileName = NULL;
+char *AdminFileName = NULL;
+char *SysLogFacility = NULL;
int syslogfacility = LOG_FACILITY;
-char *ProcessName={"web100srv"};
-char *ConfigFileName=NULL;
-char buff[BUFFSIZE+1];
-char *rmt_host;
+char *ProcessName = { "web100srv" };
+char *ConfigFileName = NULL;
+char buff[BUFFSIZE + 1];char*rmt_host;
char spds[4][256], buff2[32];
-char *device=NULL;
+char *device = NULL;
char* port = PORT;
TestOptions testopt;

@@ -153,387 +152,427 @@
char testName[256];

#include <semaphore.h>
-sem_t ndtq; /* create semaphore to allow only 1 process to modify the wait queue */
-
-static struct option long_options[] = {
- {"adminview", 0, 0, 'a'},
- {"debug", 0, 0, 'd'},
- {"help", 0, 0, 'h'},
- {"multiple", 0, 0, 'm'},
- {"max_clients", 1, 0, 'x'},
- {"mrange", 1, 0, 301},
- {"old", 0, 0, 'o'},
- {"disable-queue", 0, 0, 'q'},
- {"record", 0, 0, 'r'},
- {"syslog", 0, 0, 's'},
- {"tcpdump", 0, 0, 't'},
- {"version", 0, 0, 'v'},
- {"gzip", 0, 0, 'z'},
- {"config", 1, 0, 'c'},
+sem_t ndtq; /* create semaphore to allow only 1 process to modify the wait queue */
+
+static struct option long_options[] = { { "adminview", 0, 0, 'a' }, { "debug",
+ 0, 0, 'd' }, { "help", 0, 0, 'h' }, { "multiple", 0, 0, 'm'
}, {
+ "max_clients", 1, 0, 'x' }, { "mrange", 1, 0, 301 },
+ { "old", 0, 0, 'o' }, { "disable-queue", 0, 0, 'q' }, {
"record", 0, 0,
+ 'r' }, { "syslog", 0, 0, 's' }, { "tcpdump",
0, 0, 't' }, {
+ "version", 0, 0, 'v' }, { "gzip", 0, 0, 'z' }, {
"config", 1, 0,
+ 'c' },
#ifdef EXPERIMENTAL_ENABLED
- {"avoidsndblockup", 0, 0, 306},
- {"snaplog", 0, 0, 307},
- {"snapdelay", 1, 0, 305},
- {"cwnddecrease", 0, 0, 308},
- {"cputime", 0, 0, 309},
- {"limit", 1, 0, 'y'},
+ { "avoidsndblockup", 0, 0, 306},
+ { "snaplog", 0, 0, 307},
+ { "snapdelay", 1, 0, 305},
+ { "cwnddecrease", 0, 0, 308},
+ { "cputime", 0, 0, 309},
+ { "limit", 1, 0, 'y'},
#endif
- {"buffer", 1, 0, 'b'},
- {"file", 1, 0, 'f'},
- {"interface", 1, 0, 'i'},
- {"log", 1, 0, 'l'},
- {"protocol_log", 1, 0, 'u'},
- {"enableprotolog", 0, 0, 'e'},
- {"port", 1, 0, 'p'},
- {"midport", 1, 0, 302},
- {"c2sport", 1, 0, 303},
- {"s2cport", 1, 0, 304},
- {"refresh", 1, 0, 'T'},
- {"adminfile", 1, 0, 'A'},
- {"log_dir", 1, 0, 'L'},
- {"logfacility", 1, 0, 'S'},
+ { "buffer", 1, 0, 'b' },
+ { "file", 1, 0, 'f' },
+ { "interface", 1, 0, 'i' },
+ { "log", 1, 0, 'l' },
+ { "protocol_log", 1, 0, 'u' },
+ { "enableprotolog", 0, 0, 'e' },
+ { "port", 1, 0, 'p' },
+ { "midport", 1, 0, 302 },
+ { "c2sport", 1, 0, 303 },
+ { "s2cport", 1, 0, 304 },
+ { "refresh", 1, 0, 'T' },
+ { "adminfile", 1, 0, 'A' },
+ { "log_dir", 1, 0, 'L' },
+ { "logfacility", 1, 0, 'S' },
#if defined(HAVE_ODBC) && defined(DATABASE_ENABLED) && defined(HAVE_SQL_H)
- {"enableDBlogging", 0, 0, 310},
- {"dbDSN", 1, 0, 311},
- {"dbUID", 1, 0, 312},
- {"dbPWD", 1, 0, 313},
+ { "enableDBlogging", 0, 0, 310},
+ { "dbDSN", 1, 0, 311},
+ { "dbUID", 1, 0, 312},
+ { "dbPWD", 1, 0, 313},
#endif
#ifdef AF_INET6
- {"ipv4", 0, 0, '4'},
- {"ipv6", 0, 0, '6'},
+ { "ipv4", 0, 0, '4'},
+ { "ipv6", 0, 0, '6'},
#endif
- {0, 0, 0, 0}
-};
-
+ { 0, 0, 0, 0 } };

/**
* Process a SIGCHLD signal.
* @param pid_t Process id to be processed
* */
-void
-child_sig(pid_t chld_pid)
-{
- int pid, status, retcode;
- struct ndtchild *child_proc1, *child_proc2;
-
- child_proc1 = head_ptr;
- log_println(2, "Processing SIGCHLD signal for active web100srv process [%d], sig17=%d", chld_pid, sig17);
-
- /* this routine cleans up after a child process has terminated. There are 2 types of
- * child processes. The pkt-pair timing children are type 1 and the spawned children to run
- * the test are type 0. For the pkt-pair children, just acknowledge their signal to keep
- * them from becoming defunct. For the type 0 children, use wait3() to figure out which
- * child terminated and then clean up the FIFO queue.
- * RAC 2/8/10
- *
- * Added new type (-1) on 2/11/10. This type indicates a child has terminated due to
- * a communications fault. For some reason the child is stuck in the FIFO queue and
- * it needs to be removed. In this case, the calling function will grab the head pointer's
- * PID value, call this function with a -1 to remove the entry from the FIFO, issue a
- * SIGTERM signal and call this function with the childs PID. This should prevent the
- * code from entering into a loop.
- * RAC 2/11/10
- */
- if (chld_pid > 0) {
- while ((pid = wait4(chld_pid, &status, WNOHANG, (struct rusage *) 0))
-1) {
- log_println(3, "wait4() returned %d for PID=%d", status, pid);
- if (WIFEXITED(status) != 0) {
- log_println(3, "wexitstatus = '%d'", WEXITSTATUS(status));
- break;
- }
- if (WIFSIGNALED(status) == 1) {
- log_println(3, "wtermsig = %d", WTERMSIG(status));
- }
- if (WIFSTOPPED(status) == 1) {
- log_println(3, "wstopsig = %d", WSTOPSIG(status));
- }
- if (status != 0) {
- log_println(4, "child_sig() routine, wait4() non-zero status (%d) returned", status);
- return;
- }
- }
- return;
- }
-
- if (chld_pid == 0) {
- while ((pid = wait3(&status, WNOHANG, (struct rusage*) 0)) > 0) {
- log_println(3, "wait3() returned status=%d for PID=%d", status, pid);
- if (WIFEXITED(status) != 0) {
- log_println(3, "wexitstatus = '%d'", WEXITSTATUS(status));
- break;
- }
- if (WIFSIGNALED(status) == 1) {
- log_println(3, "wtermsig = %d", WTERMSIG(status));
- }
- if (WIFSTOPPED(status) == 1) {
- log_println(3, "wstopsig = %d", WSTOPSIG(status));
- }
- if (status != 0) {
- log_println(4, "child_sig() routine, wait3() non-zero status (%d) returned", status);
- return;
- }
- }
- log_println(6, "child_sig() called pid=%d, wait returned child=%d - status=%d",
- chld_pid, pid, status);
- if (pid == 0) {
- log_println(6, "wait3() failed to return non-zero PID, ignore it");
- if (sig17 > 0)
- sig17--;
- return;
- }
- }
- else { /* chld_pid must be -1, the error condition */
- pid = head_ptr->pid;
- log_println(6, "Stuck child at head of queue, set pid=%d and remove it from queue", pid);
- }
-
- /* the pid variable now holds the PID of the child that exited. Find out if this is one
- * of the queued children, and if so remove it from the queue and relink everything. At
- * the end of this, update the sig17 counter.
- * RAC 2/8/10
- */
-
- if (head_ptr == NULL)
- return;
- log_println(5, "checking for pktpair timing children, skip them");
- child_proc1 = head_ptr;
- while (child_proc1 != NULL) {
- log_println(5, "\tLooking for %d, curent queue Child %d, host: %s [%s], next=0x%x", pid, child_proc1->pid,
- child_proc1->host, child_proc1->addr, (u_int64_t) child_proc1->next);
- if (child_proc1->pid == pid) {
- log_println(4, "Main test process %d terminated, remove from queue", pid);
- break;
- }
- child_proc1 = child_proc1->next;
- }
- if (child_proc1 == NULL)
- return;
-
-reap_child:
- if (multiple == 1) {
- log_println(5, "mclient child '%d' (%d) has finished its test", mclients, pid);
- mclients--;
- /* return; */
- }
-
- log_println(4, "Attempting to clean up child %d, head pid = %d", pid, head_ptr->pid);
- if (head_ptr->pid == pid) {
-
- if (get_debuglvl() > 5) {
- log_println(5, "Walkingqueue");
- child_proc1 = head_ptr;
- while (child_proc1 != NULL) {
- log_println(5, "\tChild %d, host: %s [%s], next=0x%x", child_proc1->pid,
- child_proc1->host, child_proc1->addr, (u_int64_t) child_proc1->next);
- if (child_proc1->next == NULL)
- break;
- child_proc1 = child_proc1->next;
- }
- }
-
- while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
- log_println(6, "Waiting for ndtq semaphore to free - 1");
- continue;
- }
- log_println(5, "Child process %d causing head pointer modification, semaphore locked", pid);
- if (head_ptr != NULL) {
- child_proc1 = head_ptr;
- log_println(6, "modifying queue child_proc1=0x%x, head_ptr=0x%x", child_proc1, head_ptr);
- head_ptr = head_ptr->next;
- log_println(6, "free child_proc1=0x%x", child_proc1);
- free(child_proc1);
- }
- if (head_ptr == NULL)
- testing = 0;
- if (multiple == 0)
- testing = 0;
- waiting--;
- log_println(3, "Removing Child from head, decremented waiting/mclients %d/%d", waiting, mclients);
- sem_post(&ndtq);
- log_println(6, "Free'd ndtq semaphore lock - 3");
- if (sig17 > 0)
- sig17--;
- return;
- }
- else {
- child_proc1 = head_ptr;
- while (child_proc1->next != NULL) {
- if (child_proc1->next->pid == pid) {
- while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
- log_println(6, "Waiting for ndtq semaphore to free - 2");
- continue;
- }
- log_println(4, "Child process %d causing task list modification, semaphore locked", chld_pid);
- child_proc2 = child_proc1->next;
- child_proc1->next = child_proc2->next;
- log_println(6, "free child_proc2=0x%x", child_proc2);
- free(child_proc2);
- /* testing = 0; */
- waiting--;
- log_println(3, "Removing Child from list, decremented waiting/mclients %d/%d", waiting, mclients);
- sem_post(&ndtq);
- log_println(6, "Free'd ndtq semaphore lock - 4");
- if (sig17 > 0)
- sig17--;
- return;
- }
- child_proc1 = child_proc1->next;
- log_println(6, "Looping through service queue ptr = 0x%x", (u_int64_t) child_proc1);
- }
- }
- if (sig17 > 0)
- sig17--;
- log_println(3, "SIGCHLD routine finished!, decremented sig17 counter now =%d", sig17);
- return;
- if (pid > 0) {
- chld_pid = head_ptr->pid;
- log_println(6, "stuck process or other problem, removing pointer from head of queue");
- goto reap_child;
- }
- log_println(6, "Did we get here???");
-}
-
+void child_sig(pid_t chld_pid) {
+ int pid, status, retcode;
+ struct ndtchild *child_proc1, *child_proc2;
+
+ child_proc1 = head_ptr;
+ log_println(
+ 2,
+ "Processing SIGCHLD signal for active web100srv process
[%d], sig17=%d",
+ chld_pid, sig17);
+
+ /* this routine cleans up after a child process has terminated. There are 2 types of
+ * child processes. The pkt-pair timing children are type 1 and the spawned children to run
+ * the test are type 0. For the pkt-pair children, just acknowledge their signal to keep
+ * them from becoming defunct. For the type 0 children, use wait3() to figure out which
+ * child terminated and then clean up the FIFO queue.
+ * RAC 2/8/10
+ *
+ * Added new type (-1) on 2/11/10. This type indicates a child has terminated due to
+ * a communications fault. For some reason the child is stuck in the FIFO queue and
+ * it needs to be removed. In this case, the calling function will grab the head pointer's
+ * PID value, call this function with a -1 to remove the entry from the FIFO, issue a
+ * SIGTERM signal and call this function with the childs PID. This should prevent the
+ * code from entering into a loop.
+ * RAC 2/11/10
+ */
+ if (chld_pid > 0) {
+ while ((pid = wait4(chld_pid, &status, WNOHANG, (struct
rusage *) 0))
+ > -1) {
+ log_println(3, "wait4() returned %d for PID=%d",
status, pid);
+ if (WIFEXITED(status) != 0) {
+ log_println(3, "wexitstatus = '%d'",
WEXITSTATUS(status));
+ break;
+ }
+ if (WIFSIGNALED(status) == 1) {
+ log_println(3, "wtermsig = %d",
WTERMSIG(status));
+ }
+ if (WIFSTOPPED(status) == 1) {
+ log_println(3, "wstopsig = %d",
WSTOPSIG(status));
+ }
+ if (status != 0) {
+ log_println(
+ 4,
+ "child_sig() routine, wait4()
non-zero status (%d) returned",
+ status);
+ return;
+ }
+ }
+ return;
+ }
+
+ if (chld_pid == 0) {
+ while ((pid = wait3(&status, WNOHANG, (struct rusage*) 0)) >
0) {
+ log_println(3, "wait3() returned status=%d for
PID=%d", status,
+ pid);
+ if (WIFEXITED(status) != 0) {
+ log_println(3, "wexitstatus = '%d'",
WEXITSTATUS(status));
+ break;
+ }
+ if (WIFSIGNALED(status) == 1) {
+ log_println(3, "wtermsig = %d",
WTERMSIG(status));
+ }
+ if (WIFSTOPPED(status) == 1) {
+ log_println(3, "wstopsig = %d",
WSTOPSIG(status));
+ }
+ if (status != 0) {
+ log_println(
+ 4,
+ "child_sig() routine, wait3()
non-zero status (%d) returned",
+ status);
+ return;
+ }
+ }
+ log_println(6,
+ "child_sig() called pid=%d, wait returned child=%d
- status=%d",
+ chld_pid, pid, status);
+ if (pid == 0) {
+ log_println(6, "wait3() failed to return non-zero PID,
ignore it");
+ if (sig17 > 0)
+ sig17--;
+ return;
+ }
+ } else { /* chld_pid must be -1, the error condition */
+ pid = head_ptr->pid;
+ log_println(
+ 6,
+ "Stuck child at head of queue, set pid=%d and
remove it from queue",
+ pid);
+ }
+
+ /* the pid variable now holds the PID of the child that exited. Find out if this is one
+ * of the queued children, and if so remove it from the queue and relink everything. At
+ * the end of this, update the sig17 counter.
+ * RAC 2/8/10
+ */
+
+ if (head_ptr == NULL)
+ return;
+ log_println(5, "checking for pktpair timing children, skip them");
+ child_proc1 = head_ptr;
+ while (child_proc1 != NULL) {
+ log_println(
+ 5,
+ "\tLooking for %d, curent queue Child %d, host: %s
[%s], next=0x%x",
+ pid, child_proc1->pid, child_proc1->host,
child_proc1->addr,
+ (u_int64_t) child_proc1->next);
+ if (child_proc1->pid == pid) {
+ log_println(4, "Main test process %d terminated, remove
from queue",
+ pid);
+ break;
+ }
+ child_proc1 = child_proc1->next;
+ }
+ if (child_proc1 == NULL)
+ return;
+
+ reap_child: if (multiple == 1) {
+ log_println(5, "mclient child '%d' (%d) has finished its
test",
+ mclients, pid);
+ mclients--;
+ /* return; */
+ }
+
+ log_println(4, "Attempting to clean up child %d, head pid = %d", pid,
+ head_ptr->pid);
+ if (head_ptr->pid == pid) {
+
+ if (get_debuglvl() > 5) {
+ log_println(5, "Walkingqueue");
+ child_proc1 = head_ptr;
+ while (child_proc1 != NULL) {
+ log_println(5, "\tChild %d, host: %s [%s],
next=0x%x",
+ child_proc1->pid,
child_proc1->host, child_proc1->addr,
+ (u_int64_t)
child_proc1->next);
+ if (child_proc1->next == NULL)
+ break;
+ child_proc1 = child_proc1->next;
+ }
+ }
+
+ while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
+ log_println(6, "Waiting for ndtq semaphore to free -
1");
+ continue;
+ }
+ log_println(
+ 5,
+ "Child process %d causing head pointer
modification, semaphore locked",
+ pid);
+ if (head_ptr != NULL) {
+ child_proc1 = head_ptr;
+ log_println(6, "modifying queue child_proc1=0x%x,
head_ptr=0x%x",
+ child_proc1, head_ptr);
+ head_ptr = head_ptr->next;
+ log_println(6, "free child_proc1=0x%x", child_proc1);
+ free(child_proc1);
+ }
+ if (head_ptr == NULL)
+ testing = 0;
+ if (multiple == 0)
+ testing = 0;
+ waiting--;
+ log_println(3,
+ "Removing Child from head, decremented
waiting/mclients %d/%d",
+ waiting, mclients);
+ sem_post(&ndtq);
+ log_println(6, "Free'd ndtq semaphore lock - 3");
+ if (sig17 > 0)
+ sig17--;
+ return;
+ } else {
+ child_proc1 = head_ptr;
+ while (child_proc1->next != NULL) {
+ if (child_proc1->next->pid == pid) {
+ while ((retcode = sem_wait(&ndtq)) == -1 &&
errno == EINTR) {
+ log_println(6, "Waiting for ndtq semaphore
to free - 2");
+ continue;
+ }
+ log_println(
+ 4,
+ "Child process %d causing task
list modification, semaphore locked",
+ chld_pid);
+ child_proc2 = child_proc1->next;
+ child_proc1->next = child_proc2->next;
+ log_println(6, "free child_proc2=0x%x",
child_proc2);
+ free(child_proc2);
+ /* testing = 0; */
+ waiting--;
+ log_println(
+ 3,
+ "Removing Child from list,
decremented waiting/mclients %d/%d",
+ waiting, mclients);
+ sem_post(&ndtq);
+ log_println(6, "Free'd ndtq semaphore lock -
4");
+ if (sig17 > 0)
+ sig17--;
+ return;
+ }
+ child_proc1 = child_proc1->next;
+ log_println(6, "Looping through service queue ptr =
0x%x",
+ (u_int64_t) child_proc1);
+ }
+ }
+ if (sig17 > 0)
+ sig17--;
+ log_println(3,
+ "SIGCHLD routine finished!, decremented sig17 counter now
=%d",
+ sig17);
+ return;
+ if (pid > 0) {
+ chld_pid = head_ptr->pid;
+ log_println(
+ 6,
+ "stuck process or other problem, removing pointer
from head of queue");
+ goto reap_child;
+ }
+ log_println(6, "Did we get here???");
+}

/**
* Catch termination signal(s) and print message in log file
* @param signo Signal number
* */
-void
-cleanup(int signo)
-{
- FILE *fp;
-
- log_println(1, "Signal %d received by process %d", signo, getpid());
- if (get_debuglvl() > 0) {
- fp = fopen(get_logfile(),"a");
- if (fp != NULL) {
- fprintf(fp, "Signal %d received by process %d\n", signo, getpid());
- fclose(fp);
- }
- }
- switch (signo) {
- default:
- fp = fopen(get_logfile(),"a");
- if (fp != NULL) {
- fprintf(fp, "Unexpected signal (%d) received, process (%d) may terminate\n",
- signo, getpid());
- fclose(fp);
- }
- break;
- case SIGSEGV:
- log_println(6, "DEBUG, caught SIGSEGV signal and terminated process (%d)", getpid());
- if (getpid() != ndtpid)
- exit(-2);
- break;
- case SIGINT:
- exit(0);
- case SIGTERM:
- if (getpid() == ndtpid) {
- log_println(6, "DEBUG, SIGTERM signal received for parent process (%d), ignore it", ndtpid);
- break;
- }
- exit(0);
- case SIGUSR1:
- log_println(6, "DEBUG, caught SIGUSR1, setting sig1 flag to force exit");
- sig1 = 1;
- /* check_signal_flags(); */
- break;
-
- case SIGUSR2:
- log_println(6, "DEBUG, caught SIGUSR2, setting sig2 flag to force exit");
- sig2 = 1;
- /* check_signal_flags(); */
- break;
-
- case SIGALRM:
- switch (getCurrentTest()) {
- case TEST_MID:
- log_println(6, "Received SIGALRM signal [Middlebox test]");
- break;
- case TEST_C2S:
- log_println(6, "Received SIGALRM signal [C2S throughput test] pid=%d", getpid());
- break;
- case TEST_S2C:
- log_println(6, "Received SIGALRM signal [S2C throughput test] pid=%d", getpid());
- break;
- case TEST_SFW:
- log_println(6, "Received SIGALRM signal [Simple firewall test]");
- break;
- case TEST_META:
- log_println(6, "Received SIGALRM signal [META test]");
- break;
- }
- fp = fopen(get_logfile(),"a");
- if (fp != NULL) {
- if (get_debuglvl() > 4)
- fprintf(fp,"Received SIGALRM signal: terminating active web100srv process [%d]",
- getpid());
- switch (getCurrentTest()) {
- case TEST_MID:
- fprintf(fp, " [Middlebox test]\n");
- break;
- case TEST_C2S:
- fprintf(fp, " [C2S throughput test]\n");
- /* break; */
- if (wait_sig == 1)
- return;
- break;
- case TEST_S2C:
- fprintf(fp, " [S2C throughput test]\n");
- /* break; */
- if (wait_sig == 1)
- return;
- break;
- case TEST_SFW:
- fprintf(fp, " [Simple firewall test]\n");
- break;
- case TEST_META:
- fprintf(fp, " [META test]\n");
- break;
- default:
- fprintf(fp, "\n");
- }
- fclose(fp);
- }
- exit(0);
- case SIGPIPE:
- fp = fopen(get_logfile(),"a");
- if ((fp != NULL) && (get_debuglvl() > 4)) {
- fprintf(fp,"Received SIGPIPE signal: terminating active web100srv process [%d]\n",
- getpid());
- fclose(fp);
- }
- sig13 = 1;
- break;
-
- case SIGHUP:
- /* Initialize Web100 structures */
- count_vars = web100_init(VarFileName);
-
- /* The administrator view automatically generates a usage page for the
- * NDT server. This page is then accessable to the general public.
- * At this point read the existing log file and generate the necessary
- * data. This data is then updated at the end of each test.
- * RAC 3/11/04
- */
- if (admin_view == 1)
- view_init(refresh);
- break;
-
- case SIGCHLD:
- /* moved actions to child_sig() routine on 3/10/05 RAC
- * Now all we do here is set a flag and return the flag
- * is checked near the top of the main wait loop, so it
- * will only be accessed once and only the testing proces
- * will attempt to do something with it.
- */
- /* sig17 = 1; */
- if (ndtpid != getppid()) {
- sig17++;
- log_println(5, "Signal 17 (SIGCHLD) received - completed tests = %d", sig17);
- }
- break;
- }
+void cleanup(int signo) {
+ FILE * fp;
+
+ log_println(1, "Signal %d received by process %d", signo, getpid());
+ if (get_debuglvl() > 0) {
+ fp = fopen(get_logfile(), "a");
+ if (fp != NULL) {
+ fprintf(fp, "Signal %d received by process %d\n",
signo, getpid());
+ fclose(fp);
+ }
+ }
+ switch (signo) {
+ default:
+ fp = fopen(get_logfile(), "a");
+ if (fp != NULL) {
+ fprintf(
+ fp,
+ "Unexpected signal (%d) received, process
(%d) may terminate\n",
+ signo, getpid());
+ fclose(fp);
+ }
+ break;
+ case SIGSEGV:
+ log_println(6,
+ "DEBUG, caught SIGSEGV signal and terminated
process (%d)",
+ getpid());
+ if (getpid() != ndtpid)
+ exit(-2);
+ break;
+ case SIGINT:
+ exit(0);
+ case SIGTERM:
+ if (getpid() == ndtpid) {
+ log_println(
+ 6,
+ "DEBUG, SIGTERM signal received for parent
process (%d), ignore it",
+ ndtpid);
+ break;
+ }
+ exit(0);
+ case SIGUSR1:
+ log_println(6,
+ "DEBUG, caught SIGUSR1, setting sig1 flag to force
exit");
+ sig1 = 1;
+ /* check_signal_flags(); */
+ break;
+
+ case SIGUSR2:
+ log_println(6,
+ "DEBUG, caught SIGUSR2, setting sig2 flag to force
exit");
+ sig2 = 1;
+ /* check_signal_flags(); */
+ break;
+
+ case SIGALRM:
+ switch (getCurrentTest()) {
+ case TEST_MID:
+ log_println(6, "Received SIGALRM signal [Middlebox
test]");
+ break;
+ case TEST_C2S:
+ log_println(6,
+ "Received SIGALRM signal [C2S throughput
test] pid=%d",
+ getpid());
+ break;
+ case TEST_S2C:
+ log_println(6,
+ "Received SIGALRM signal [S2C throughput
test] pid=%d",
+ getpid());
+ break;
+ case TEST_SFW:
+ log_println(6, "Received SIGALRM signal [Simple firewall
test]");
+ break;
+ case TEST_META:
+ log_println(6, "Received SIGALRM signal [META test]");
+ break;
+ }
+ fp = fopen(get_logfile(), "a");
+ if (fp != NULL) {
+ if (get_debuglvl() > 4)
+ fprintf(
+ fp,
+ "Received SIGALRM signal:
terminating active web100srv process [%d]",
+ getpid());
+ switch (getCurrentTest()) {
+ case TEST_MID:
+ fprintf(fp, " [Middlebox test]\n");
+ break;
+ case TEST_C2S:
+ fprintf(fp, " [C2S throughput test]\n");
+ /* break; */
+ if (wait_sig == 1)
+ return;
+ break;
+ case TEST_S2C:
+ fprintf(fp, " [S2C throughput test]\n");
+ /* break; */
+ if (wait_sig == 1)
+ return;
+ break;
+ case TEST_SFW:
+ fprintf(fp, " [Simple firewall test]\n");
+ break;
+ case TEST_META:
+ fprintf(fp, " [META test]\n");
+ break;
+ default:
+ fprintf(fp, "\n");
+ }
+ fclose(fp);
+ }
+ exit(0);
+ case SIGPIPE:
+ fp = fopen(get_logfile(), "a");
+ if ((fp != NULL) && (get_debuglvl() > 4)) {
+ fprintf(
+ fp,
+ "Received SIGPIPE signal: terminating active web100srv process [%d]\n",
+ getpid());
+ fclose(fp);
+ }
+ sig13 = 1;
+ break;
+
+ case SIGHUP:
+ /* Initialize Web100 structures */
+ count_vars = web100_init(VarFileName);
+
+ /* The administrator view automatically generates a usage
page for the
+ * NDT server. This page is then accessable to the general
public.
+ * At this point read the existing log file and generate the
necessary
+ * data. This data is then updated at the end of each test.
+ * RAC 3/11/04
+ */
+ if (admin_view == 1)
+ view_init(refresh);
+ break;
+
+ case SIGCHLD:
+ /* moved actions to child_sig() routine on 3/10/05 RAC
+ * Now all we do here is set a flag and return the flag
+ * is checked near the top of the main wait loop, so it
+ * will only be accessed once and only the testing proces
+ * will attempt to do something with it.
+ */
+ /* sig17 = 1; */
+ if (ndtpid != getppid()) {
***The diff for this file has been truncated for email.***
=======================================
--- /branches/kkumar_code_organize/src/web100srv.h Sun Oct 16 15:37:17
2011
+++ /branches/kkumar_code_organize/src/web100srv.h Mon Oct 17 06:43:25
2011
@@ -50,7 +50,7 @@
#include <I2util/util.h>

/* move version to configure.ac file for package name */
-/* #define VERSION "3.0.7" */ /* version number */
+/* #define VERSION "3.0.7" *//* version number */
#define RECLTH 8192

#define WEB100_VARS 128 /* number of web100 variables you want to access*/
@@ -58,7 +58,6 @@
#define LOG_FACILITY LOG_LOCAL0 /* Syslog facility to log at
*/
#define LOGDIR "serverdata" /* directory for detailed snaplog and tcpdump files */

-
/* Location of default config file */
#define CONFIGFILE "/etc/ndt.conf"

@@ -70,88 +69,87 @@

// Congestion window peak information
typedef struct CwndPeaks {
- int min; // trough of peak value
- int max; // maximum peak value
- int amount; // number of transitions between peaks
+ int min; // trough of peak value
+ int max; // maximum peak value
+ int amount; // number of transitions between peaks
} CwndPeaks;

// Options to run test with
typedef struct options {
- u_int32_t limit; // used to calculate receive window limit
- int snapDelay; // Frequency of snap log collection in milliseconds (i.e logged every snapDelay ms)
- char avoidSndBlockUp; // flag set to indicate avoiding send buffer blocking in the S2C test
- char snaplog; // enable collecting snap log
- char cwndDecrease; // enable analysis of the cwnd changes (S2C test)
- char s2c_logname[256]; // S2C log file name - size changed to 256
- char c2s_logname[256]; // C2S log file name - size changed to 256
- int compress; // enable compressing log files
+ u_int32_t limit; // used to calculate receive window limit
+ int snapDelay; // Frequency of snap log collection in milliseconds (i.e logged every snapDelay ms)
+ char avoidSndBlockUp; // flag set to indicate avoiding send buffer blocking in the S2C test
+ char snaplog; // enable collecting snap log
+ char cwndDecrease; // enable analysis of the cwnd changes (S2C test)
+ char s2c_logname[256]; // S2C log file name - size changed to 256
+ char c2s_logname[256]; // C2S log file name - size changed to 256
+ int compress; // enable compressing log files
} Options;

typedef struct portpair {
- int port1;
- int port2;
+ int port1;
+ int port2;
} PortPair;

// Structure defining NDT child process
struct ndtchild {
- int pid; // process id
- char addr[64]; // IP Address
- char host[256]; // Hostname
- time_t stime; // estimated start time of test
- time_t qtime; // time when queued
- int pipe; // writing end of pipe
- int running; // Is process running?
- int ctlsockfd; // Socket file descriptor
- int oldclient; // Is old client?
+ int pid; // process id
+ char addr[64]; // IP Address
+ char host[256]; // Hostname
+ time_t stime; // estimated start time of test
+ time_t qtime; // time when queued
+ int pipe; // writing end of pipe
+ int running; // Is process running?
+ int ctlsockfd; // Socket file descriptor
+ int oldclient; // Is old client?
char tests[16]; // What tests are scheduled?
struct ndtchild *next; // next process in queue
};

/* structure used to collect speed data in bins */
struct spdpair {
- int family; // Address family
+ int family; // Address family
#if defined(AF_INET6)
u_int32_t saddr[4]; // source address
- u_int32_t daddr[4]; // dest address
+ u_int32_t daddr[4];// dest address
#else
- u_int32_t saddr; // source address
- u_int32_t daddr; // dest address
+ u_int32_t saddr; // source address
+ u_int32_t daddr; // dest address
#endif
- u_int16_t sport; // source port
- u_int16_t dport; // destination port
- u_int32_t seq; // seq number
- u_int32_t ack; // number of acked bytes
- u_int32_t win; // window size
- int links[16]; // bins for link speeds
- u_int32_t sec; // time indicator
- u_int32_t usec; // time indicator, microsecs
+ u_int16_t sport; // source port
+ u_int16_t dport; // destination port
+ u_int32_t seq; // seq number
+ u_int32_t ack; // number of acked bytes
+ u_int32_t win; // window size
+ int links[16]; // bins for link speeds
+ u_int32_t sec; // time indicator
+ u_int32_t usec; // time indicator, microsecs
u_int32_t st_sec;
u_int32_t st_usec;
- u_int32_t inc_cnt; // count of times window size was incremented
- u_int32_t dec_cnt; // count of times window size was decremented
- u_int32_t same_cnt; // count of times window size remained same
- u_int32_t timeout; // # of timeouts
- u_int32_t dupack; // # of duplicate acks
- double time; // time, often sec+usec from above
- double totalspd; // speed observed
- double totalspd2; // running average (spd of current calculated (total speed) and prior value)
+ u_int32_t inc_cnt; // count of times window size was incremented
+ u_int32_t dec_cnt; // count of times window size was decremented
+ u_int32_t same_cnt; // count of times window size remained same
+ u_int32_t timeout; // # of timeouts
+ u_int32_t dupack; // # of duplicate acks
+ double time; // time, often sec+usec from above
+ double totalspd; // speed observed
+ double totalspd2; // running average (spd of current calculated (total speed) and prior value)
u_int32_t totalcount; // total number of valid speed data bins
};

struct spdpair fwd, rev;

-
struct web100_variables {
- char name[256]; // key
- char value[256]; // value
+ char name[256]; // key
+ char value[256]; // value
} web_vars[WEB100_VARS];

-struct pseudo_hdr { /* used to compute TCP checksum */
- unsigned long s_addr; // source addr
- unsigned long d_addr; // destination address
- char pad; // padding characterr
- unsigned char protocol; // protocol indicator
- unsigned short len; // header length
+struct pseudo_hdr { /* used to compute TCP checksum */
+ unsigned long s_addr; // source addr
+ unsigned long d_addr; // destination address
+ char pad; // padding characterr
+ unsigned char protocol; // protocol indicator
+ unsigned short len; // header length
};

int32_t gmt2local(time_t);
@@ -167,33 +165,32 @@

/* This should work for both 32 and 64 bit userland. */
struct ethtool_cmd {
- u_int32_t cmd;
- u_int32_t supported; /* Features this interface supports */
- u_int32_t advertising; /* Features this interface advertises */
- u_int16_t speed; /* The forced speed, 10Mb, 100Mb, gigabit */
- u_int8_t duplex; /* Duplex, half or full */
- u_int8_t port; /* Which connector port */
- u_int8_t phy_address;
- u_int8_t transceiver; /* Which tranceiver to use */
- u_int8_t autoneg; /* Enable or disable autonegotiation */
- u_int32_t maxtxpkt; /* Tx pkts before generating tx int */
- u_int32_t maxrxpkt; /* Rx pkts before generating rx int */
- u_int32_t reserved[4];
+ u_int32_t cmd;
+ u_int32_t supported; /* Features this interface supports */
+ u_int32_t advertising; /* Features this interface advertises */
+ u_int16_t speed; /* The forced speed, 10Mb, 100Mb, gigabit */
+ u_int8_t duplex; /* Duplex, half or full */
+ u_int8_t port; /* Which connector port */
+ u_int8_t phy_address;
+ u_int8_t transceiver; /* Which tranceiver to use */
+ u_int8_t autoneg; /* Enable or disable autonegotiation */
+ u_int32_t maxtxpkt; /* Tx pkts before generating tx int */
+ u_int32_t maxrxpkt; /* Rx pkts before generating rx int */
+ u_int32_t reserved[4];
};

struct iflists {
- char name[8][32];
+ char name[8][32];
u_int16_t speed[32];
} iflist;

-
/* web100-pcap */
#ifdef HAVE_LIBPCAP
void init_vars(struct spdpair *cur);
void print_bins(struct spdpair *cur, int monitor_pipe[2]);
void calculate_spd(struct spdpair *cur, struct spdpair *cur2, int port2, int port3);
void init_pkttrace(I2Addr srcAddr, struct sockaddr *sock_addr, socklen_t saddrlen, int monitor_pipe[2],
- char *device, PortPair* pair, char * direction, int compress);
+ char *device, PortPair* pair, char * direction, int compress);
int check_signal_flags();
#endif

@@ -208,16 +205,16 @@
int web100_get_data(web100_snapshot* snap, int ctlsock, web100_agent* agent, int count_vars);
int CwndDecrease(web100_agent* agent, char* logname, int *dec_cnt, int *same_cnt, int *inc_cnt);
int web100_logvars(int *Timeouts, int *SumRTT, int *CountRTT,
- int *PktsRetrans, int *FastRetran, int *DataPktsOut, int *AckPktsOut,
- int *CurrentMSS, int *DupAcksIn, int *AckPktsIn, int *MaxRwinRcvd,
- int *Sndbuf, int *CurrentCwnd, int *SndLimTimeRwin, int *SndLimTimeCwnd,
- int *SndLimTimeSender, int *DataBytesOut, int *SndLimTransRwin,
- int *SndLimTransCwnd, int *SndLimTransSender, int *MaxSsthresh,
- int *CurrentRTO, int *CurrentRwinRcvd, int *MaxCwnd, int *CongestionSignals,
- int *PktsOut, int *MinRTT, int count_vars, int *RcvWinScale, int *SndWinScale,
- int *CongAvoid, int *CongestionOverCount, int *MaxRTT, int *OtherReductions,
- int *CurTimeoutCount, int *AbruptTimeouts, int *SendStall, int *SlowStart,
- int *SubsequentTimeouts, int *ThruBytesAcked);
+ int *PktsRetrans, int *FastRetran, int *DataPktsOut, int
*AckPktsOut,
+ int *CurrentMSS, int *DupAcksIn, int *AckPktsIn, int
*MaxRwinRcvd,
+ int *Sndbuf, int *CurrentCwnd, int *SndLimTimeRwin, int
*SndLimTimeCwnd,
+ int *SndLimTimeSender, int *DataBytesOut, int
*SndLimTransRwin,
+ int *SndLimTransCwnd, int *SndLimTransSender, int
*MaxSsthresh,
+ int *CurrentRTO, int *CurrentRwinRcvd, int *MaxCwnd, int *CongestionSignals,
+ int *PktsOut, int *MinRTT, int count_vars, int *RcvWinScale, int *SndWinScale,
+ int *CongAvoid, int *CongestionOverCount, int *MaxRTT, int *OtherReductions,
+ int *CurTimeoutCount, int *AbruptTimeouts, int *SendStall, int *SlowStart,
+ int *SubsequentTimeouts, int *ThruBytesAcked);
#endif
int KillHung(void);
void writeMeta(int compress, int cputime, int snaplog, int tcpdump);


  • [ndt-dev] [ndt] r723 committed - Formatting changes to all files in the src folder, ndt, 10/17/2011

Archive powered by MHonArc 2.6.16.

Top of Page