ndt-dev - [ndt-dev] [ndt] r789 committed - Reformat to google style
Subject: NDT-DEV email list created
List archive
- From:
- To:
- Subject: [ndt-dev] [ndt] r789 committed - Reformat to google style
- Date: Thu, 15 Nov 2012 21:34:45 +0000
Revision: 789
Author:
Date: Thu Nov 15 13:33:19 2012
Log: Reformat to google style
http://code.google.com/p/ndt/source/detail?r=789
Modified:
/trunk/src/analyze.c
/trunk/src/fakewww.c
/trunk/src/genplot.c
/trunk/src/heuristics.c
/trunk/src/logging.c
/trunk/src/mrange.c
/trunk/src/ndt_odbc.c
/trunk/src/ndtptestconstants.c
/trunk/src/network.c
/trunk/src/protocol.c
/trunk/src/runningtest.c
/trunk/src/strlutils.c
/trunk/src/test_c2s_clt.c
/trunk/src/test_c2s_srv.c
/trunk/src/test_meta_clt.c
/trunk/src/test_meta_srv.c
/trunk/src/test_mid_clt.c
/trunk/src/test_mid_srv.c
/trunk/src/test_results_clt.c
/trunk/src/test_s2c_clt.c
/trunk/src/test_s2c_srv.c
/trunk/src/test_sfw_clt.c
/trunk/src/test_sfw_srv.c
/trunk/src/testoptions.c
/trunk/src/tr-mkmap.c
/trunk/src/tr-tree.c
/trunk/src/tr-tree6.c
/trunk/src/troute.c
/trunk/src/troute6.c
/trunk/src/usage.c
/trunk/src/utils.c
/trunk/src/viewtrace.c
/trunk/src/web100-admin.c
/trunk/src/web100-pcap.c
/trunk/src/web100-util.c
/trunk/src/web100clt.c
/trunk/src/web100srv.c
=======================================
--- /trunk/src/analyze.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/analyze.c Thu Nov 15 13:33:19 2012
@@ -57,7 +57,7 @@
int CurTimeouts, AbruptTimeouts, SendStall, SubsequentTimeouts;
int autotune, ThruBytesAcked;
int link = 0, mismatch = 0, bad_cable = 0, half_duplex = 0, congestion = 0,
- totaltime;
+ totaltime;
int i, spd, ret;
double order, idle, cpu_idle1, cpu_idle2;
char *name, ip_addr[64], ip_addr2[64];
@@ -73,868 +73,868 @@
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 } };
+ '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);
+ 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;
+ 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:
- c2s_linkspeed_data = indx;
- log_print(1, "Client --> Server data detects link =
");
- break;
- case 1:
- c2s_linkspeed_ack = indx;
- log_print(1, "Client <-- Server Ack's detect link =
");
- break;
- case 2:
- s2c_linkspeed_data = indx;
- log_print(1, "Server --> Client data detects link =
");
- break;
- case 3:
- s2c_linkspeed_ack = indx;
- log_print(1, "Server <-- Client Ack's detect link =
");
- }
+ 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:
+ c2s_linkspeed_data = indx;
+ log_print(1, "Client --> Server data detects link = ");
+ break;
+ case 1:
+ c2s_linkspeed_ack = indx;
+ log_print(1, "Client <-- Server Ack's detect link = ");
+ break;
+ case 2:
+ s2c_linkspeed_data = indx;
+ log_print(1, "Server --> Client data detects link = ");
+ break;
+ case 3:
+ s2c_linkspeed_ack = 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;
- }
- */
- log_linkspeed(indx);
- }
- switch (c2s_linkspeed_data) {
- case -2:
- snprintf(btlneck, sizeof(btlneck), "Insufficent Data");
- break;
- case -1:
- snprintf(btlneck, sizeof(btlneck), "a System Fault");
- break;
- case 0:
- snprintf(btlneck, sizeof(btlneck), "the Round Trip Time");
- break;
- case 1:
- snprintf(btlneck, sizeof(btlneck), "a 'Dial-up modem'
connection");
- break;
- case 2:
- if ((c2sspd / s2cspd > .8) && (c2sspd / s2cspd < 1.2)
- && (c2sspd > 1000))
- snprintf(btlneck, sizeof(btlneck), "a 'T1' subnet");
- else {
- if ((tail[3] > 1) || (s2c_linkspeed_ack == 3))
- snprintf(btlneck, sizeof(btlneck), "a 'Cable
Modem' connection");
- else
- snprintf(btlneck, sizeof(btlneck), "a 'DSL'
connection");
- }
- break;
- case 3:
- if (linkcnt == 16)
- snprintf(btlneck, sizeof(btlneck), "a T1 + subnet");
- else
- snprintf(btlneck, sizeof(btlneck), "an 'Ethernet'
subnet");
- break;
- case 4:
- if (linkcnt == 16)
- snprintf(btlneck, sizeof(btlneck), "a IEEE 802.11b Wifi
subnet");
- else
- snprintf(btlneck, sizeof(btlneck), "a 'T3/DS-3'
subnet");
- break;
- case 5:
- if (linkcnt == 16)
- snprintf(btlneck, sizeof(btlneck), "a Wifi + subnet");
- else
- snprintf(btlneck, sizeof(btlneck), "a 'FastEthernet'
subnet");
- break;
- case 6:
- if (linkcnt == 16)
- snprintf(btlneck, sizeof(btlneck), "a Ethernet
subnet");
- else
- snprintf(btlneck, sizeof(btlneck), "an 'OC-12'
subnet");
- break;
- case 7:
- if (linkcnt == 16)
- snprintf(btlneck, sizeof(btlneck), "a T3/DS3 subnet");
- else
- snprintf(btlneck, sizeof(btlneck), "a 'Gigabit Ethernet'
subnet");
- break;
- case 8:
- if (linkcnt == 16)
- snprintf(btlneck, sizeof(btlneck), "a FastEthernet
subnet");
- else
- snprintf(btlneck, sizeof(btlneck), "an 'OC-48'
subnet");
- break;
- case 9:
- if (linkcnt == 16)
- snprintf(btlneck, sizeof(btlneck), "a OC-12 subnet");
- else
- snprintf(btlneck, sizeof(btlneck), "a '10 Gigabit Enet'
subnet");
- break;
- case 10:
- if (linkcnt == 16)
- snprintf(btlneck, sizeof(btlneck), "a Gigabit Ethernet
subnet");
- else
- snprintf(btlneck, sizeof(btlneck), "Retransmissions");
- case 11:
- snprintf(btlneck, sizeof(btlneck), "an 'OC-48' subnet");
- break;
- case 12:
- snprintf(btlneck, sizeof(btlneck), "a '10 Gigabit Enet'
subnet");
- break;
- case 13:
- snprintf(btlneck, sizeof(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 */
+ /*
+ 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;
+ }
+ */
+ log_linkspeed(indx);
+ }
+ switch (c2s_linkspeed_data) {
+ case -2:
+ snprintf(btlneck, sizeof(btlneck), "Insufficent Data");
+ break;
+ case -1:
+ snprintf(btlneck, sizeof(btlneck), "a System Fault");
+ break;
+ case 0:
+ snprintf(btlneck, sizeof(btlneck), "the Round Trip Time");
+ break;
+ case 1:
+ snprintf(btlneck, sizeof(btlneck), "a 'Dial-up modem' connection");
+ break;
+ case 2:
+ if ((c2sspd / s2cspd > .8) && (c2sspd / s2cspd < 1.2)
+ && (c2sspd > 1000))
+ snprintf(btlneck, sizeof(btlneck), "a 'T1' subnet");
+ else {
+ if ((tail[3] > 1) || (s2c_linkspeed_ack == 3))
+ snprintf(btlneck, sizeof(btlneck), "a 'Cable Modem' connection");
+ else
+ snprintf(btlneck, sizeof(btlneck), "a 'DSL' connection");
+ }
+ break;
+ case 3:
+ if (linkcnt == 16)
+ snprintf(btlneck, sizeof(btlneck), "a T1 + subnet");
+ else
+ snprintf(btlneck, sizeof(btlneck), "an 'Ethernet' subnet");
+ break;
+ case 4:
+ if (linkcnt == 16)
+ snprintf(btlneck, sizeof(btlneck), "a IEEE 802.11b Wifi subnet");
+ else
+ snprintf(btlneck, sizeof(btlneck), "a 'T3/DS-3' subnet");
+ break;
+ case 5:
+ if (linkcnt == 16)
+ snprintf(btlneck, sizeof(btlneck), "a Wifi + subnet");
+ else
+ snprintf(btlneck, sizeof(btlneck), "a 'FastEthernet' subnet");
+ break;
+ case 6:
+ if (linkcnt == 16)
+ snprintf(btlneck, sizeof(btlneck), "a Ethernet subnet");
+ else
+ snprintf(btlneck, sizeof(btlneck), "an 'OC-12' subnet");
+ break;
+ case 7:
+ if (linkcnt == 16)
+ snprintf(btlneck, sizeof(btlneck), "a T3/DS3 subnet");
+ else
+ snprintf(btlneck, sizeof(btlneck), "a 'Gigabit Ethernet' subnet");
+ break;
+ case 8:
+ if (linkcnt == 16)
+ snprintf(btlneck, sizeof(btlneck), "a FastEthernet subnet");
+ else
+ snprintf(btlneck, sizeof(btlneck), "an 'OC-48' subnet");
+ break;
+ case 9:
+ if (linkcnt == 16)
+ snprintf(btlneck, sizeof(btlneck), "a OC-12 subnet");
+ else
+ snprintf(btlneck, sizeof(btlneck), "a '10 Gigabit Enet' subnet");
+ break;
+ case 10:
+ if (linkcnt == 16)
+ snprintf(btlneck, sizeof(btlneck), "a Gigabit Ethernet subnet");
+ else
+ snprintf(btlneck, sizeof(btlneck), "Retransmissions");
+ case 11:
+ snprintf(btlneck, sizeof(btlneck), "an 'OC-48' subnet");
+ break;
+ case 12:
+ snprintf(btlneck, sizeof(btlneck), "a '10 Gigabit Enet' subnet");
+ break;
+ case 13:
+ snprintf(btlneck, sizeof(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;
+ 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;
+ recvbwd = ((MaxRwinRcvd * 8) / avgrtt) / 1000;
+ cwndbwd = ((CurrentCwnd * 8) / avgrtt) / 1000;
+ sendbwd = ((Sndbuf * 8) / avgrtt) / 1000;
- spd = ((double) DataBytesOut / (double) totaltime) * 8;
+ 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;
+ 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. */
+ /* 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;
- }
- }
+ 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;
+ /* 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;
+ 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 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;
+ /* 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 (((rwintime > .95) && (SndLimTransRwin / timesec > 30)
+ && (SndLimTransSender / timesec > 30)) || (link <= 10))
+ half_duplex = 1;
- if ((cwndtime > .02) && (mismatch2 == 0) && (cwndbwd < recvbwd))
- congestion2 = 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);
- }
+ 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,
- c2s_linkspeed_data);
- printf(
- "\tSpeed-chk says {%d, %d, %d, %d}, Running average = {%0.1f, %0.1f, %0.1f, %0.1f}\n",
- c2s_linkspeed_data, c2s_linkspeed_ack, s2c_linkspeed_data, s2c_linkspeed_ack, 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);
+ printf("\tWeb100 says link = %d, speed-chk says link = %d\n", link,
+ c2s_linkspeed_data);
+ printf(
+ "\tSpeed-chk says {%d, %d, %d, %d}, Running average = {%0.1f, %0.1f, %0.1f, %0.1f}\n",
+ c2s_linkspeed_data, c2s_linkspeed_ack, s2c_linkspeed_data, s2c_linkspeed_ack, 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 ((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");
- }
+ 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);
+ 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;
+ 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;
- }
- }
+ 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");
- }
+ if (optind < argc) {
+ short_usage(argv[0], "Unrecognized non-option elements");
+ }
- log_init(argv[0], debug);
+ log_init(argv[0], debug);
- if (LogFileName == NULL) {
- snprintf(tmpstr, sizeof(tmpstr), "%s/%s", BASEDIR, LOGFILE);
- LogFileName = tmpstr;
- }
- log_println(1, "log file = %s", LogFileName);
+ if (LogFileName == NULL) {
+ snprintf(tmpstr, sizeof(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) {
- snprintf(tmpstr, 256, "%s/%s", BASEDIR, PROTOLOGFILE);
- ProtoLogFileName = tmpstr;
- }
- log_println(1, "log file = %s", ProtoLogFileName);
+ //TODO do we need protocol log file in analyze????
+ if (ProtoLogFileName == NULL) {
+ snprintf(tmpstr, 256, "%s/%s", BASEDIR, PROTOLOGFILE);
+ ProtoLogFileName = tmpstr;
+ }
+ log_println(1, "log file = %s", ProtoLogFileName);
- if ((fp = fopen(LogFileName, "r")) == NULL)
- err_sys("Missing Log file ");
+ 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);
+ 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;
+ 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)
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/src/fakewww.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/fakewww.c Thu Nov 15 13:33:19 2012
@@ -50,35 +50,35 @@
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; ";
+" <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 ";
+"\">\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>";
+"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 };
+ "/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;
@@ -98,17 +98,17 @@
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 },
+ '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();
@@ -117,27 +117,27 @@
void logAcLog(char*, time_t*, char*, char*, int, int, char*, char*);
void err_sys(char* s) {
- perror(s);
- exit(1);
+ 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 = LISTEN_PORT;
- int conn_options = 0;
+ int c;
+ int sockfd, newsockfd;
+ int federated = 0, debug = 0, max_ttl = 10;
+ time_t tt;
+ socklen_t clilen;
+ char* srcname = NULL;
+ char* listenport = LISTEN_PORT;
+ int conn_options = 0;
- char *ErLogFileName = BASEDIR
- "/"ERLOGFILE;
- char *AcLogFileName = BASEDIR
- "/"ACLOGFILE;
- struct sockaddr_storage cli_addr;
- I2Addr listenaddr = NULL;
- Allowed* ptr;
+ 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
@@ -145,190 +145,190 @@
#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;
- }
- }
+ case '?':
+ short_usage(argv[0], "");
+ break;
+ }
+ }
- if (optind < argc) {
- short_usage(argv[0], "Unrecognized non-option elements");
- }
+ if (optind < argc) {
+ short_usage(argv[0], "Unrecognized non-option elements");
+ }
- log_init(argv[0], debug);
+ 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 (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) {
- snprintf(dtfn, sizeof(dtfn), "%s/%s", BASEDIR, DFLT_TREE);
- DefaultTree = dtfn;
- }
+ if (DefaultTree == NULL) {
+ snprintf(dtfn, sizeof(dtfn), "%s/%s", BASEDIR, DFLT_TREE);
+ DefaultTree = dtfn;
+ }
#ifdef AF_INET6
- if (DefaultTree6 == NULL) {
- snprintf(dt6fn, sizeof(dtfn), "%s/%s", BASEDIR, DFLT_TREE6);
- DefaultTree6 = dt6fn;
- }
+ if (DefaultTree6 == NULL) {
+ snprintf(dt6fn, sizeof(dtfn), "%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);
+ /*
+ * 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);
+ 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);
+ 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 */
+ 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.
- */
+ /*
+ * 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");
- }
+ 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);
- }
+ 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;
+ /*
+ * 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)
- ;
+ while ((pid = wait3(&status, WNOHANG, (struct rusage *) 0)) > 0)
+ ;
}
/*
@@ -340,405 +340,405 @@
*/
int readline(fd, ptr, maxlen)
- register int fd;register char *ptr;register int maxlen; {
- int n, rc;
- char c;
+ 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 */
- }
+ 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);
-}
+ *ptr = 0;
+ return (n);
+ }
void trim(char* ptr) {
- while (*ptr) {
- if ((*ptr == '\r') || (*ptr == '\n')) {
- *ptr = 0;
- break;
- }
- 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;
+ 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;
+ 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);
+ 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 */
+ 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);
+ 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 */
- char ip_str[16];
- 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++) {
- snprintf(ip_str, sizeof(ip_str),
"%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, ip_str);
- if (i == max_ttl) {
- log_println(4, "Oops,
destination not found!");
- break;
- }
- }
- /* print out last item on list */
- snprintf(ip_str, sizeof(ip_str),
"%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,
ip_str);
+ if (fed_mode == 1) {
+ struct sockaddr* csaddr;
+ csaddr = I2AddrSAddr(addr, NULL);
+ if (csaddr->sa_family == AF_INET) { /* make the IPv4 find */
+ char ip_str[16];
+ 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++) {
+ snprintf(ip_str, sizeof(ip_str), "%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, ip_str);
+ if (i == max_ttl) {
+ log_println(4, "Oops, destination not found!");
+ break;
+ }
+ }
+ /* print out last item on list */
+ snprintf(ip_str, sizeof(ip_str), "%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, ip_str);
- srv_addr = find_compare(IPlist, i);
+ 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;
- }
+ /* 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);
+ 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
- */
+ /* 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));
- snprintf(line, sizeof(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);
- snprintf(line, sizeof(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);
- snprintf(line, sizeof(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;
- }
+ writen(sd, MsgRedir1, strlen(MsgRedir1));
+ writen(sd, MsgRedir2, strlen(MsgRedir2));
+ snprintf(line, sizeof(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);
+ snprintf(line, sizeof(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);
+ snprintf(line, sizeof(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 */
+ 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);
- }
+ 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);
- }
+ 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);
+ 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);
+ 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));
- snprintf(line, sizeof(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);
- snprintf(line, sizeof(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);
- snprintf(line, sizeof(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;
- }
+ writen(sd, MsgRedir1, strlen(MsgRedir1));
+ writen(sd, MsgRedir2, strlen(MsgRedir2));
+ snprintf(line, sizeof(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);
+ snprintf(line, sizeof(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);
+ snprintf(line, sizeof(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;
+ }
#endif
- }
- }
+ }
+ }
- /* try to open and give em what they want */
- tt = time(0);
- ok = 0;
- if (strcmp(filename, "/") == 0)
- strncpy(filename, "/tcpbw100.html", 15);
- for (i = 0; okfile[i]; i++) {
- /* restrict file access */
- if (strcmp(okfile[i], filename) == 0) {
- ok = 1;
- break;
- }
- }
- if (ok == 0) {
- ptr = a_root;
- while (ptr != NULL) {
- if (strcmp(ptr->filename, filename) == 0) {
- ok = 2;
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/src/genplot.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/genplot.c Thu Nov 15 13:33:19 2012
@@ -35,649 +35,649 @@
#include "usage.h"
char *color[16] = { "green", "blue", "orange", "red", "yellow", "magenta",
- "pink", "white", "black" };
+ "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 }
};
+ '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;
+ 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];
+ 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_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));
- 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));
- 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, "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));
+ 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); */
}
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)) {
+ 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;
+ 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.
- */
+ /* 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);
+ memset(lname, 0, 256);
- get_title(snap, log, agent, group, title, remport);
+ 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");
- }
+ 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");
+ 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;
+ 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);
- }
+ 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 ((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, ",");
- }
+ 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);
- }
+ 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 ((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");
+ 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;
+ 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);
+ memset(lname, 0, 256);
- get_title(snap, log, agent, group, title, remport);
+ 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");
- }
+ 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");
+ 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;
+ 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);
- }
+ 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 ((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;
- }
- }
- }
+ 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);
- }
+ 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 ((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");
+ 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)) {
+ 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;
+ 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);
+ 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(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);
- }
+ 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");
- }
+ 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;
+ static int duration;
- if (arg == -1) {
- if (value) {
- printf("%10s\t", "Throughput (kB/s)");
- } else {
- printf("%10s\t", "Duration");
- }
- return;
- }
+ 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);
- }
+ 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;
+ static int duration;
- if (!arg) { /* duration */
- duration = value;
- return value;
- } else { /* DataBytesOut */
- return (((double) value) / ((double) duration)) * 1000000.0;
- }
+ 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;
+ 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 == -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)));
- }
+ 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;
+ 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;
- }
- }
+ 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':
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/src/heuristics.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/heuristics.c Thu Nov 15 13:33:19 2012
@@ -53,76 +53,76 @@
*
* */
void calc_linkspeed(char spds[4][256], int spd_index, int *c2s_linkspeed_data, int *c2s_linkspeed_ack,
- int* s2c_linkspeed_data, int *s2c_linkspeed_ack, float runave[4], u_int32_t *dec_cnt,
- u_int32_t *same_cnt, u_int32_t *inc_cnt, int *timeout, int
*dupack,
- int is_c2stest) {
+ int* s2c_linkspeed_data, int *s2c_linkspeed_ack, float runave[4], u_int32_t *dec_cnt,
+ u_int32_t *same_cnt, u_int32_t *inc_cnt, int *timeout, int *dupack,
+ int is_c2stest) {
- int index = 0; // speed array indices
- int links[16]; // link speed bin values
- int n = 0, j = 0; // temporary iterator variables
- int max; // max speed bin counter value
- int total; // total of the bin counts, used to calculate percentage
- int ifspeedlocal; // local if-speed indicator
+ int index = 0; // speed array indices
+ int links[16]; // link speed bin values
+ int n = 0, j = 0; // temporary iterator variables
+ int max; // max speed bin counter value
+ int total; // total of the bin counts, used to calculate percentage
+ int ifspeedlocal; // local if-speed indicator
- for (n = 0; n < spd_index; n++) {
- sscanf(spds[n],
- "%d %d %d %d %d %d %d %d %d %d %d %d %f %u %u %u
%d %d %d",
- &links[0], &links[1], &links[2], &links[3],
&links[4],
- &links[5], &links[6], &links[7], &links[8],
&links[9],
- &links[10], &links[11], &runave[n], inc_cnt,
dec_cnt,
- same_cnt, timeout, dupack, &ifspeedlocal);
- log_println(log_lvl_heur, " **First ele: spd=%s, runave=%f",
spds[n],
- runave[n]);
- max = 0;
- index = 0;
- total = 0;
+ for (n = 0; n < spd_index; n++) {
+ sscanf(spds[n],
+ "%d %d %d %d %d %d %d %d %d %d %d %d %f %u %u %u %d %d %d",
+ &links[0], &links[1], &links[2], &links[3], &links[4],
+ &links[5], &links[6], &links[7], &links[8], &links[9],
+ &links[10], &links[11], &runave[n], inc_cnt, dec_cnt,
+ same_cnt, timeout, dupack, &ifspeedlocal);
+ log_println(log_lvl_heur, " **First ele: spd=%s, runave=%f", spds[n],
+ runave[n]);
+ max = 0;
+ index = 0;
+ total = 0;
- if ((ifspeedlocal == -1) || (ifspeedlocal == 0) || (ifspeedlocal
> 10))
- ifspeedlocal = 10; // ifspeed was probably not
collected in these cases
+ if ((ifspeedlocal == -1) || (ifspeedlocal == 0) || (ifspeedlocal > 10))
+ ifspeedlocal = 10; // ifspeed was probably not collected in these cases
- // get the ifspeed bin with the biggest counter value.
- // NDT determines link speed using this
- for (j = 0; j <= ifspeedlocal; j++) {
- total += links[j];
- if (max < links[j]) {
- max = links[j];
- index = j;
- }
- }
+ // get the ifspeed bin with the biggest counter value.
+ // NDT determines link speed using this
+ for (j = 0; j <= ifspeedlocal; j++) {
+ total += links[j];
+ if (max < links[j]) {
+ max = links[j];
+ index = j;
+ }
+ }
- // speed data was not collected correctly
- if (links[index] == -1)
- index = -1;
+ // speed data was not collected correctly
+ if (links[index] == -1)
+ index = -1;
- // log
- log_println(0, "spds[%d] = '%s' max=%d [%0.2f%%]\n", n,
spds[n], max,
- (float) max * 100 / total);
+ // log
+ log_println(0, "spds[%d] = '%s' max=%d [%0.2f%%]\n", n, spds[n], max,
+ (float) max * 100 / total);
- // Assign values based on whether C2S or S2C test
- // Note: spd[0] , [1] contains C->S test results
- // spd[2] , spd [3] contains S->C test results
- switch (n + (is_c2stest ? 0 : 2)) {
- case 0:
- *c2s_linkspeed_data = index;
- log_print(log_lvl_heur, "Client --> Server data detects
link = ");
- break;
- case 1:
- *c2s_linkspeed_ack = index;
- log_print(log_lvl_heur, "Client <-- Server Ack's detect
link = ");
- break;
- case 2:
- *s2c_linkspeed_data = index;
- log_print(log_lvl_heur, "Server --> Client data detects
link = ");
- break;
- case 3:
- *s2c_linkspeed_ack = index;
- log_print(1, "Server <-- Client Ack's detect link =
");
- break;
- }
+ // Assign values based on whether C2S or S2C test
+ // Note: spd[0] , [1] contains C->S test results
+ // spd[2] , spd [3] contains S->C test results
+ switch (n + (is_c2stest ? 0 : 2)) {
+ case 0:
+ *c2s_linkspeed_data = index;
+ log_print(log_lvl_heur, "Client --> Server data detects link = ");
+ break;
+ case 1:
+ *c2s_linkspeed_ack = index;
+ log_print(log_lvl_heur, "Client <-- Server Ack's detect link = ");
+ break;
+ case 2:
+ *s2c_linkspeed_data = index;
+ log_print(log_lvl_heur, "Server --> Client data detects link = ");
+ break;
+ case 3:
+ *s2c_linkspeed_ack = index;
+ log_print(1, "Server <-- Client Ack's detect link = ");
+ break;
+ }
- // classify link speed based on the max ifspeed seen
- log_linkspeed(index);
- } //end section to determine speed.
+ // classify link speed based on the max ifspeed seen
+ log_linkspeed(index);
+ } //end section to determine speed.
} //end method calc_linkspeed
@@ -134,11 +134,11 @@
* */
double calc_avg_rtt(int sumRTT, int countRTT, double *avgRTT) {
- *avgRTT = (double) sumRTT / countRTT;
- log_println(log_lvl_heur,
- "-- Average round trip time= SumRTT (%d) over countRTT
(%d)=%f",
- sumRTT, countRTT, (*avgRTT) * .001);
- return ((*avgRTT) * .001);
+ *avgRTT = (double) sumRTT / countRTT;
+ log_println(log_lvl_heur,
+ "-- Average round trip time= SumRTT (%d) over countRTT (%d)=%f",
+ sumRTT, countRTT, (*avgRTT) * .001);
+ return ((*avgRTT) * .001);
}
/**
@@ -160,16 +160,16 @@
* @return packet loss value
* */
double calc_packetloss(int congsnsignals, int pktsout, int c2sdatalinkspd) {
- double packetloss = (double) congsnsignals / pktsout;
- if (packetloss == 0) {
- if (c2sdatalinkspd > 5)
- packetloss = .0000000001; // set to 10^-10 for links
faster than FastE
- else
- packetloss = .000001; // set to 10^-6 otherwise
- }
- log_println(log_lvl_heur, "--packetloss=%d over %d=%f. Link spd=%d",
- congsnsignals, pktsout, packetloss, c2sdatalinkspd);
- return packetloss;
+ double packetloss = (double) congsnsignals / pktsout;
+ if (packetloss == 0) {
+ if (c2sdatalinkspd > 5)
+ packetloss = .0000000001; // set to 10^-10 for links faster than FastE
+ else
+ packetloss = .000001; // set to 10^-6 otherwise
+ }
+ log_println(log_lvl_heur, "--packetloss=%d over %d=%f. Link spd=%d",
+ congsnsignals, pktsout, packetloss, c2sdatalinkspd);
+ return packetloss;
}
/**
@@ -181,9 +181,9 @@
* @return percentage of packets out of order
* */
double calc_packets_outoforder(int dupackcount, int actualackcount) {
- log_println(log_lvl_heur, "--packets out of order: %f",
- (double) dupackcount / actualackcount);
- return ((double) dupackcount / actualackcount);
+ log_println(log_lvl_heur, "--packets out of order: %f",
+ (double) dupackcount / actualackcount);
+ return ((double) dupackcount / actualackcount);
}
/**
@@ -199,13 +199,13 @@
* @return maximum theoretical bandwidth
* */
double calc_max_theoretical_throughput(int currentMSS, double rttsec,
- double packetloss) {
- double maxthruput;
- maxthruput = (currentMSS / (rttsec * sqrt(packetloss))) * BITS_8 / KILO_BITS
- / KILO_BITS;
- log_println(log_lvl_heur, "--max_theoretical_thruput: %f. From
%d,%f,%f",
- maxthruput, currentMSS, rttsec, packetloss);
- return maxthruput;
+ double packetloss) {
+ double maxthruput;
+ maxthruput = (currentMSS / (rttsec * sqrt(packetloss))) * BITS_8 / KILO_BITS
+ / KILO_BITS;
+ log_println(log_lvl_heur, "--max_theoretical_thruput: %f. From %d,%f,%f",
+ maxthruput, currentMSS, rttsec, packetloss);
+ return maxthruput;
}
/**
@@ -220,19 +220,19 @@
*
* */
void calc_window_sizes(int *SndWinScale, int *RcvWinScale, int SendBuf,
- int MaxRwinRcvd, int MaxCwnd, double *rwin, double *swin,
double *cwin) {
- if ((*SndWinScale > WINDOW_SCALE_THRESH) || (SendBuf < MAX_TCP_PORT))
- *SndWinScale = 0;
- if ((*RcvWinScale > WINDOW_SCALE_THRESH) || (MaxRwinRcvd <
MAX_TCP_PORT))
- *RcvWinScale = 0;
+ int MaxRwinRcvd, int MaxCwnd, double *rwin, double *swin, double *cwin) {
+ if ((*SndWinScale > WINDOW_SCALE_THRESH) || (SendBuf < MAX_TCP_PORT))
+ *SndWinScale = 0;
+ if ((*RcvWinScale > WINDOW_SCALE_THRESH) || (MaxRwinRcvd < MAX_TCP_PORT))
+ *RcvWinScale = 0;
- *rwin = (double) MaxRwinRcvd * BITS_8 / KILO_BITS / KILO_BITS;
- *swin = (double) SendBuf * BITS_8 / KILO_BITS / KILO_BITS;
- *cwin = (double) MaxCwnd * BITS_8 / KILO_BITS / KILO_BITS;
- log_println(
- log_lvl_heur,
- "--window sizes: SndWinScale= %d, RcvwinScale=%d, MaxRwinRcvd=%d, maxCwnd=%d,rwin=%f, swin=%f, cwin=%f",
- *SndWinScale, *RcvWinScale, MaxRwinRcvd, MaxCwnd
,*rwin, *swin, *cwin);
+ *rwin = (double) MaxRwinRcvd * BITS_8 / KILO_BITS / KILO_BITS;
+ *swin = (double) SendBuf * BITS_8 / KILO_BITS / KILO_BITS;
+ *cwin = (double) MaxCwnd * BITS_8 / KILO_BITS / KILO_BITS;
+ log_println(
+ log_lvl_heur,
+ "--window sizes: SndWinScale= %d, RcvwinScale=%d, MaxRwinRcvd=%d, maxCwnd=%d,rwin=%f, swin=%f, cwin=%f",
+ *SndWinScale, *RcvWinScale, MaxRwinRcvd, MaxCwnd ,*rwin, *swin, *cwin);
}
/**
@@ -245,10 +245,10 @@
* @return idle time fraction
* */
double calc_RTOIdle(int timeouts, int currentRTO, double totaltime) {
- double idlewaitingforpackets = (timeouts * ((double) currentRTO /
1000))
- / totaltime;
- log_println(log_lvl_heur, "--RTOIdle:%f", idlewaitingforpackets);
- return idlewaitingforpackets;
+ double idlewaitingforpackets = (timeouts * ((double) currentRTO / 1000))
+ / totaltime;
+ log_println(log_lvl_heur, "--RTOIdle:%f", idlewaitingforpackets);
+ return idlewaitingforpackets;
}
/**
@@ -263,11 +263,11 @@
* @return Total test time
* */
int calc_totaltesttime(int SndLimTimeRwin, int SndLimTimeCwnd,
- int SndLimTimeSender) {
- int totaltime = SndLimTimeRwin + SndLimTimeCwnd + SndLimTimeSender;
- log_println(log_lvl_heur, "--Total test time: %d+%d+%d=%d ", SndLimTimeRwin,
- SndLimTimeCwnd, SndLimTimeSender, totaltime);
- return (totaltime);
+ int SndLimTimeSender) {
+ int totaltime = SndLimTimeRwin + SndLimTimeCwnd + SndLimTimeSender;
+ log_println(log_lvl_heur, "--Total test time: %d+%d+%d=%d ", SndLimTimeRwin,
+ SndLimTimeCwnd, SndLimTimeSender, totaltime);
+ return (totaltime);
}
/**
@@ -278,10 +278,10 @@
*
*/
double calc_sendlimited_sndrfault(int SndLimTimeSender, int totaltime) {
- double sendlimitedtime = ((double) SndLimTimeSender) / totaltime;
- log_println(log_lvl_heur, "--Send limited time: %d over %d=%f ",
- SndLimTimeSender, totaltime, sendlimitedtime);
- return sendlimitedtime;
+ double sendlimitedtime = ((double) SndLimTimeSender) / totaltime;
+ log_println(log_lvl_heur, "--Send limited time: %d over %d=%f ",
+ SndLimTimeSender, totaltime, sendlimitedtime);
+ return sendlimitedtime;
}
/**
@@ -293,10 +293,10 @@
*
*/
double calc_sendlimited_rcvrfault(int SndLimTimeRwin, int totaltime) {
- double sendlimitedtime = ((double) SndLimTimeRwin) / totaltime;
- log_println(log_lvl_heur, "--Send limited time: %d over %d=%f ",
- SndLimTimeRwin, totaltime, sendlimitedtime);
- return sendlimitedtime;
+ double sendlimitedtime = ((double) SndLimTimeRwin) / totaltime;
+ log_println(log_lvl_heur, "--Send limited time: %d over %d=%f ",
+ SndLimTimeRwin, totaltime, sendlimitedtime);
+ return sendlimitedtime;
}
/**
@@ -306,10 +306,10 @@
* @return sender limited time ratio
*/
double calc_sendlimited_cong(int SndLimTimeCwnd, int totaltime) {
- double sendlimitedtime = ((double) SndLimTimeCwnd) / totaltime;
- log_println(log_lvl_heur, "--Send limited time: %d over %d=%f ",
- SndLimTimeCwnd, totaltime, sendlimitedtime);
- return sendlimitedtime;
+ double sendlimitedtime = ((double) SndLimTimeCwnd) / totaltime;
+ log_println(log_lvl_heur, "--Send limited time: %d over %d=%f ",
+ SndLimTimeCwnd, totaltime, sendlimitedtime);
+ return sendlimitedtime;
}
/**
@@ -321,9 +321,9 @@
* @return Actual throughput
*/
double calc_real_throughput(int DataBytesOut, int totaltime) {
- double realthruput = ((double) DataBytesOut / (double) totaltime) * BITS_8;
- log_println(log_lvl_heur, "--Actual observed throughput: %f ", realthruput);
- return realthruput;
+ double realthruput = ((double) DataBytesOut / (double) totaltime) * BITS_8;
+ log_println(log_lvl_heur, "--Actual observed throughput: %f ", realthruput);
+ return realthruput;
}
/**
@@ -335,9 +335,9 @@
* @return Actual throughput
*/
double cal_totalwaittime(int currentRTO, int timeoutcounters) {
- double waitarrivetime = (double) (currentRTO * timeoutcounters) /
KILO;
- log_println(log_lvl_heur, "--Total wait time: %f ", waitarrivetime);
- return waitarrivetime;
+ double waitarrivetime = (double) (currentRTO * timeoutcounters) / KILO;
+ log_println(log_lvl_heur, "--Total wait time: %f ", waitarrivetime);
+ return waitarrivetime;
}
/**
@@ -349,10 +349,10 @@
* @return 1 (true) if midboxs2cspd > s2cspd, else 0.
*/
int is_limited_cwnd_throughput_better(int midboxs2cspd, int s2cspd) {
- int thruputmismatch = 0;
- if (midboxs2cspd > s2cspd)
- thruputmismatch = 1;
- return thruputmismatch;
+ int thruputmismatch = 0;
+ if (midboxs2cspd > s2cspd)
+ thruputmismatch = 1;
+ return thruputmismatch;
}
@@ -366,10 +366,10 @@
* @return 1 (true) if c2stestresult > s2ctestresult, else 0.
*/
int is_c2s_throughputbetter(int c2stestresult, int s2ctestresult) {
- int c2sbetter_yes = 0;
- if (c2stestresult > s2ctestresult)
- c2sbetter_yes = 1;
- return c2sbetter_yes;
+ int c2sbetter_yes = 0;
+ if (c2stestresult > s2ctestresult)
+ c2sbetter_yes = 1;
+ return c2sbetter_yes;
}
/**
@@ -378,8 +378,8 @@
* @return 1(true) if multiple test mode is on, else 0
*/
int isNotMultipleTestMode(int multiple) {
- log_println(log_lvl_heur, "--multiple: %f ", multiple);
- return (multiple == 0);
+ log_println(log_lvl_heur, "--multiple: %f ", multiple);
+ return (multiple == 0);
}
/**
@@ -405,24 +405,24 @@
* @return int 1 if duplex mismatch is found, 0 if not.
* */
int detect_duplexmismatch(double cwndtime, double bwtheoretcl, int pktsretxed,
- double timesec, int maxsstartthresh, double idleRTO, int link,
- int s2cspd, int midboxspd, int multiple) {
- int duplex_mismatch_yes = 0;
- if ((cwndtime > .9) // more than 90% time spent being receiver window limited
- && (bwtheoretcl > 2) // theoretical max goodput > 2mbps
- && (pktsretxed / timesec > 2)
- // #of segments with pkt-retransmissions> 2
- && (maxsstartthresh > 0) // max slow start threshold
> 0
- && (idleRTO > .01) // cumulative RTO time > 1% test duration
- && (link > 2) // not wireless link
- && is_limited_cwnd_throughput_better(midboxspd, s2cspd) //S->C throughput calculated
- // by server < client value
- && isNotMultipleTestMode(multiple)) {
+ double timesec, int maxsstartthresh, double idleRTO, int link,
+ int s2cspd, int midboxspd, int multiple) {
+ int duplex_mismatch_yes = 0;
+ if ((cwndtime > .9) // more than 90% time spent being receiver window limited
+ && (bwtheoretcl > 2) // theoretical max goodput > 2mbps
+ && (pktsretxed / timesec > 2)
+ // #of segments with pkt-retransmissions> 2
+ && (maxsstartthresh > 0) // max slow start threshold > 0
+ && (idleRTO > .01) // cumulative RTO time > 1% test duration
+ && (link > 2) // not wireless link
+ && is_limited_cwnd_throughput_better(midboxspd, s2cspd) //S->C throughput calculated
+ // by server < client value
+ && isNotMultipleTestMode(multiple)) {
- duplex_mismatch_yes = 1;
- } //end if
- log_println(log_lvl_heur, "--duplexmismatch?: %d ",
duplex_mismatch_yes);
- return duplex_mismatch_yes;
+ duplex_mismatch_yes = 1;
+ } //end if
+ log_println(log_lvl_heur, "--duplexmismatch?: %d ", duplex_mismatch_yes);
+ return duplex_mismatch_yes;
}
/** Check if internal link is duplex mismatched
@@ -433,17 +433,17 @@
* return 1 if internal duplex mismatch is found, else 0
* */
int detect_internal_duplexmismatch(double s2cspd, double realthruput,
- double rwintime, double packetloss) {
- int duplex_mismatch_yes = 0;
- if ((s2cspd > 50) // S->C goodput > 50 Mbps
- && (realthruput < 5) // actual send throughput < 5 Mbps
- && (rwintime > .9) // receive window limited for >90% of the time
- && (packetloss < .01)) {
- duplex_mismatch_yes = 1;
- }
- log_println(log_lvl_heur, "--internal duplexmismatch?: %d ",
- duplex_mismatch_yes);
- return duplex_mismatch_yes;
+ double rwintime, double packetloss) {
+ int duplex_mismatch_yes = 0;
+ if ((s2cspd > 50) // S->C goodput > 50 Mbps
+ && (realthruput < 5) // actual send throughput < 5 Mbps
+ && (rwintime > .9) // receive window limited for >90% of the time
+ && (packetloss < .01)) {
+ duplex_mismatch_yes = 1;
+ }
+ log_println(log_lvl_heur, "--internal duplexmismatch?: %d ",
+ duplex_mismatch_yes);
+ return duplex_mismatch_yes;
}
/**
@@ -468,14 +468,14 @@
* @return 1 is fault hardware suspected, 0 otherwise
* */
int detect_faultyhardwarelink(double packetloss, double cwndtime,
- double timesec, int maxslowstartthresh) {
- int faultyhw_found = 0;
- if (((packetloss * 100) / timesec > 15) && (cwndtime / timesec > .6)
- && (packetloss < .01) && (maxslowstartthresh > 0)) {
- faultyhw_found = 1;
- }
- log_println(log_lvl_heur, "--faulty hardware?: %d ", faultyhw_found);
- return faultyhw_found;
+ double timesec, int maxslowstartthresh) {
+ int faultyhw_found = 0;
+ if (((packetloss * 100) / timesec > 15) && (cwndtime / timesec > .6)
+ && (packetloss < .01) && (maxslowstartthresh > 0)) {
+ faultyhw_found = 1;
+ }
+ log_println(log_lvl_heur, "--faulty hardware?: %d ", faultyhw_found);
+ return faultyhw_found;
}
@@ -499,14 +499,14 @@
* @return 1 if ethernet link, 0 otherwise
* */
int detect_ethernetlink(double realthruput, double s2cspd, double packetloss,
- double oo_order, int link) {
- int is_ethernet = 0;
- if ((realthruput < 9.5) && (realthruput > 3.0) && ((s2cspd / 1000) <
9.5)
- && (packetloss < .01) && (oo_order < .035) && (link >
0)) {
- is_ethernet = 1;
- }
- log_println(log_lvl_heur, "--Is ethernet?: %d ", is_ethernet);
- return is_ethernet;
+ double oo_order, int link) {
+ int is_ethernet = 0;
+ if ((realthruput < 9.5) && (realthruput > 3.0) && ((s2cspd / 1000) < 9.5)
+ && (packetloss < .01) && (oo_order < .035) && (link > 0)) {
+ is_ethernet = 1;
+ }
+ log_println(log_lvl_heur, "--Is ethernet?: %d ", is_ethernet);
+ return is_ethernet;
}
/**
@@ -533,16 +533,16 @@
* @return 1 if wireless link, 0 otherwise
* */
int detect_wirelesslink(double sendtime, double realthruput, double bw_theortcl,
- int sndlimtrans_rwin, int sndlimtrans_cwnd, double
rwindowtime,
- int link) {
- int is_wireless = 0;
- if ((sendtime == 0) && (realthruput < 5) && (bw_theortcl > 50)
- && ((sndlimtrans_rwin / sndlimtrans_cwnd) == 1)
- && (rwindowtime > .90) && (link > 0)) {
- is_wireless = 1;
- }
- log_println(log_lvl_heur, "--Is wireless?: %d ", is_wireless);
- return is_wireless;
+ int sndlimtrans_rwin, int sndlimtrans_cwnd, double rwindowtime,
+ int link) {
+ int is_wireless = 0;
+ if ((sendtime == 0) && (realthruput < 5) && (bw_theortcl > 50)
+ && ((sndlimtrans_rwin / sndlimtrans_cwnd) == 1)
+ && (rwindowtime > .90) && (link > 0)) {
+ is_wireless = 1;
+ }
+ log_println(log_lvl_heur, "--Is wireless?: %d ", is_wireless);
+ return is_wireless;
}
/**
@@ -565,15 +565,15 @@
* @return 1 if wireless link, 0 otherwise
* */
int detect_DSLCablelink(int sndlim_timesender, int sndlim_transsender,
- double realthruput, double bw_theoretical, int link) {
- int is_dslorcable = 0;
- if ((sndlim_timesender < 600) && (sndlim_transsender == 0)
- && (realthruput < 2) && (realthruput < bw_theoretical)
- && (link > 0)) {
- is_dslorcable = 1;
- }
- log_println(log_lvl_heur, "--Is DSL/Cable?: %d ", is_dslorcable);
- return is_dslorcable;
+ double realthruput, double bw_theoretical, int link) {
+ int is_dslorcable = 0;
+ if ((sndlim_timesender < 600) && (sndlim_transsender == 0)
+ && (realthruput < 2) && (realthruput < bw_theoretical)
+ && (link > 0)) {
+ is_dslorcable = 1;
+ }
+ log_println(log_lvl_heur, "--Is DSL/Cable?: %d ", is_dslorcable);
+ return is_dslorcable;
}
@@ -596,14 +596,14 @@
* @return 1 if half_duplex link suspected, 0 otherwise
* */
int detect_halfduplex(double rwintime, int sndlim_transrwin,
- int sndlim_transsender, double totaltesttime) {
- int is_halfduplex = 0;
- if ((rwintime > .95) && (sndlim_transrwin / totaltesttime > 30)
- && (sndlim_transsender / totaltesttime > 30)) {
- is_halfduplex = 1;
- }
- log_println(log_lvl_heur, "--Is Half_duplex detected? %d ", is_halfduplex);
- return is_halfduplex;
+ int sndlim_transsender, double totaltesttime) {
+ int is_halfduplex = 0;
+ if ((rwintime > .95) && (sndlim_transrwin / totaltesttime > 30)
+ && (sndlim_transsender / totaltesttime > 30)) {
+ is_halfduplex = 1;
+ }
+ log_println(log_lvl_heur, "--Is Half_duplex detected? %d ", is_halfduplex);
+ return is_halfduplex;
}
/**
@@ -626,12 +626,12 @@
* @return 1 if congestion detected, 0 otherwise
* */
int detect_congestionwindow(double cwndtime, int mismatch, double cwin,
- double rwin, double rttsec) {
- int is_congested = 0;
- if ((cwndtime > .02) && (mismatch == 0)
- && ((cwin / rttsec) < (rwin / rttsec))) {
- is_congested = 1;
- }
- log_println(log_lvl_heur, "--Is congested? %d ", is_congested);
- return is_congested;
+ double rwin, double rttsec) {
+ int is_congested = 0;
+ if ((cwndtime > .02) && (mismatch == 0)
+ && ((cwin / rttsec) < (rwin / rttsec))) {
+ is_congested = 1;
+ }
+ log_println(log_lvl_heur, "--Is congested? %d ", is_congested);
+ return is_congested;
}
=======================================
--- /trunk/src/logging.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/logging.c Thu Nov 15 13:33:19 2012
@@ -60,73 +60,73 @@
int zlib_def(char *src_fn) {
- int ret, flush, level = Z_DEFAULT_COMPRESSION;
- char dest_fn[256];
- FILE *dest, *source;
- unsigned have;
- z_stream strm;
- unsigned char in[16384];
- unsigned char out[16384];
+ int ret, flush, level = Z_DEFAULT_COMPRESSION;
+ char dest_fn[256];
+ FILE *dest, *source;
+ unsigned have;
+ z_stream strm;
+ unsigned char in[16384];
+ unsigned char out[16384];
- // allocate deflate state
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- ret = deflateInit(&strm, level);
- if (ret != Z_OK) {
- log_println(6, "zlib deflateInit routine failed with %d",
ret);
- return ret;
- }
+ // allocate deflate state
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ ret = deflateInit(&strm, level);
+ if (ret != Z_OK) {
+ log_println(6, "zlib deflateInit routine failed with %d", ret);
+ return ret;
+ }
- snprintf(dest_fn, sizeof(dest_fn), "%s.gz", src_fn);
- if ((source = fopen(src_fn, "r")) == NULL) {
- log_println(6, "zlib_def(): failed to open src file '%s' for
reading",
- src_fn);
- return -3;
- }
- if ((dest = fopen(dest_fn, "w")) == NULL) {
- log_println(6, "zlib_def(): failed to open dest file '%s' for
writing",
- dest_fn);
- return -4;
- }
- // compress until end of file
- do {
- strm.avail_in = fread(in, 1, 16384, source);
- if (ferror(source)) {
- (void) deflateEnd(&strm);
- return Z_ERRNO;
- }
- flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
- strm.next_in = in;
+ snprintf(dest_fn, sizeof(dest_fn), "%s.gz", src_fn);
+ if ((source = fopen(src_fn, "r")) == NULL) {
+ log_println(6, "zlib_def(): failed to open src file '%s' for reading",
+ src_fn);
+ return -3;
+ }
+ if ((dest = fopen(dest_fn, "w")) == NULL) {
+ log_println(6, "zlib_def(): failed to open dest file '%s' for writing",
+ dest_fn);
+ return -4;
+ }
+ // compress until end of file
+ do {
+ strm.avail_in = fread(in, 1, 16384, source);
+ if (ferror(source)) {
+ (void) deflateEnd(&strm);
+ return Z_ERRNO;
+ }
+ flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
+ strm.next_in = in;
- // run deflate() on input until output buffer not full, finish
- // compression if all of source has been read in
- do {
- strm.avail_out = 16384;
- strm.next_out = out;
+ // run deflate() on input until output buffer not full, finish
+ // compression if all of source has been read in
+ do {
+ strm.avail_out = 16384;
+ strm.next_out = out;
- ret = deflate(&strm, flush); /* no bad return value */
- assert(ret != Z_STREAM_ERROR); /* state not clobbered
*/
- have = 16384 - strm.avail_out;
- if (fwrite(out, 1, have, dest) != have ||
ferror(dest)) {
- (void) deflateEnd(&strm);
- return Z_ERRNO;
- }
+ ret = deflate(&strm, flush); /* no bad return value */
+ assert(ret != Z_STREAM_ERROR); /* state not clobbered */
+ have = 16384 - strm.avail_out;
+ if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
+ (void) deflateEnd(&strm);
+ return Z_ERRNO;
+ }
- } while (strm.avail_out == 0);
- assert(strm.avail_in == 0); /* all input will be used */
+ } while (strm.avail_out == 0);
+ assert(strm.avail_in == 0); /* all input will be used */
- /* done when last data in file processed */
- } while (flush != Z_FINISH);
- assert(ret == Z_STREAM_END); /* stream will be complete */
+ /* done when last data in file processed */
+ } while (flush != Z_FINISH);
+ assert(ret == Z_STREAM_END); /* stream will be complete */
- /* clean up and return */
- (void) deflateEnd(&strm);
+ /* clean up and return */
+ (void) deflateEnd(&strm);
- /* compressed version of file is now created, remove the original uncompressed version */
- remove(src_fn);
+ /* compressed version of file is now created, remove the original uncompressed version */
+ remove(src_fn);
- return Z_OK;
+ return Z_OK;
}
/* #endif */
@@ -137,28 +137,28 @@
*/
void log_init(char* progname, int debuglvl) {
- assert(progname);
+ assert(progname);
- _programname =
- (_programname = strrchr(progname, '/')) ?
- _programname + 1 : progname;
+ _programname =
+ (_programname = strrchr(progname, '/')) ?
+ _programname + 1 : progname;
- _immediateattr.fp = _immediateattr_nl.fp = stderr;
- _immediateattr.line_info = I2MSG | I2NONL;
- _immediateattr_nl.line_info = I2MSG;
- _immediateattr.tformat = _immediateattr_nl.tformat = NULL;
+ _immediateattr.fp = _immediateattr_nl.fp = stderr;
+ _immediateattr.line_info = I2MSG | I2NONL;
+ _immediateattr_nl.line_info = I2MSG;
+ _immediateattr.tformat = _immediateattr_nl.tformat = NULL;
- _errorhandler = I2ErrOpen(progname, I2ErrLogImmediate,
&_immediateattr,
- NULL, NULL);
- _errorhandler_nl = I2ErrOpen(progname, I2ErrLogImmediate,
- &_immediateattr_nl, NULL, NULL);
+ _errorhandler = I2ErrOpen(progname, I2ErrLogImmediate, &_immediateattr,
+ NULL, NULL);
+ _errorhandler_nl = I2ErrOpen(progname, I2ErrLogImmediate,
+ &_immediateattr_nl, NULL, NULL);
- if (!_errorhandler || !_errorhandler_nl) {
- fprintf(stderr, "%s : Couldn't init error module\n",
progname);
- exit(1);
- }
+ if (!_errorhandler || !_errorhandler_nl) {
+ fprintf(stderr, "%s : Couldn't init error module\n", progname);
+ exit(1);
+ }
- _debuglevel = debuglvl;
+ _debuglevel = debuglvl;
}
/**
@@ -168,8 +168,8 @@
* Added RAC 10/13/09
*/
void log_free(void) {
- free(_errorhandler);
- free(_errorhandler_nl);
+ free(_errorhandler);
+ free(_errorhandler_nl);
}
/**
@@ -178,7 +178,7 @@
*/
void set_debuglvl(int debuglvl) {
- _debuglevel = debuglvl;
+ _debuglevel = debuglvl;
}
/**
@@ -187,7 +187,7 @@
*/
void set_logfile(char* filename) {
- LogFileName = filename;
+ LogFileName = filename;
}
/**
@@ -197,23 +197,23 @@
*
*/
void set_protologdir(char* dirname) {
- char localstr[256];
+ char localstr[256];
- // Protocol log location being set
- if (dirname == NULL) {
- //use default of BASEDIR/LOGDIR
- log_println(5, "PV: 1: NULL proto location =%s;\n",
ProtocolLogDirName);
- return;
- } else if (dirname[0] != '/') {
- snprintf(localstr, sizeof(localstr), "%s/%s/", BASEDIR,
dirname);
- ProtocolLogDirName = localstr;
- log_println(5, "PV: 2: non-dir proto location. So=%s;\n",
dirname);
- } //end protocol dir name
- else {
- snprintf(localstr, sizeof(localstr), "%s", dirname);
- ProtocolLogDirName = dirname;
- log_println(5, "PV33: proto location=%s;\n",
ProtocolLogDirName);
- }
+ // Protocol log location being set
+ if (dirname == NULL) {
+ //use default of BASEDIR/LOGDIR
+ log_println(5, "PV: 1: NULL proto location =%s;\n", ProtocolLogDirName);
+ return;
+ } else if (dirname[0] != '/') {
+ snprintf(localstr, sizeof(localstr), "%s/%s/", BASEDIR, dirname);
+ ProtocolLogDirName = localstr;
+ log_println(5, "PV: 2: non-dir proto location. So=%s;\n", dirname);
+ } //end protocol dir name
+ else {
+ snprintf(localstr, sizeof(localstr), "%s", dirname);
+ ProtocolLogDirName = dirname;
+ log_println(5, "PV33: proto location=%s;\n", ProtocolLogDirName);
+ }
}
@@ -222,8 +222,8 @@
* @return directory where protocol logs are placed
*/
char* get_protologdir() {
- log_println(5," Protocol file location=%s;\n", ProtocolLogDirName);
- return ProtocolLogDirName;
+ log_println(5," Protocol file location=%s;\n", ProtocolLogDirName);
+ return ProtocolLogDirName;
}
/**
@@ -231,7 +231,7 @@
* @return is protocol logging enabled?
*/
char get_protocolloggingenabled() {
- return enableprotologging;
+ return enableprotologging;
}
/**
@@ -242,14 +242,14 @@
* @param none
*/
void create_protolog_dir() {
- if ( get_protocolloggingenabled() ) {
- set_timestamp();
- snprintf(protocollogfilestore, sizeof(protocollogfilestore), "%s/", get_protologdir());
- log_println(5,"Creating protocol log directory=%s", protocollogfilestore);
- create_named_logdir(protocollogfilestore, sizeof(protocollogfilestore), "", get_protocolloggingenabled());
- set_protologdir(protocollogfilestore);
- log_println(9,"DataDir remains=%s", DataDirName);
- }
+ if ( get_protocolloggingenabled() ) {
+ set_timestamp();
+ snprintf(protocollogfilestore, sizeof(protocollogfilestore), "%s/", get_protologdir());
+ log_println(5,"Creating protocol log directory=%s", protocollogfilestore);
+ create_named_logdir(protocollogfilestore, sizeof(protocollogfilestore), "", get_protocolloggingenabled());
+ set_protologdir(protocollogfilestore);
+ log_println(9,"DataDir remains=%s", DataDirName);
+ }
}
/**
@@ -259,28 +259,28 @@
* @param filename The new protocol log filename
* */
/*
-void set_protologfile(char* client_ip, char* protologlocalarr) {
- FILE * fp;
+ void set_protologfile(char* client_ip, char* protologlocalarr) {
+ FILE * fp;
- if (ProtocolLogDirName == NULL) {
- ProtocolLogDirName = BASEDIR;
- }
- sprintf(protologlocalarr, "%s/%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX,
- client_ip, PROTOLOGSUFFIX, "\0");
- //strlcpy(ProtocolLogFileName, protologlocalarr, sizeof(ProtocolLogFileName));
- strlcpy(protologlocalarr,ProtocolLogDirName,sizeof(protologlocalarr));
- strlcat(protologlocalarr,"/",sizeof(protologlocalarr));
- strlcat(protologlocalarr,PROTOLOGPREFIX,sizeof(protologlocalarr));
- strlcat(protologlocalarr,client_ip,sizeof(protologlocalarr));
- strlcat(protologlocalarr,PROTOLOGSUFFIX,sizeof(protologlocalarr));
+ if (ProtocolLogDirName == NULL) {
+ ProtocolLogDirName = BASEDIR;
+ }
+ sprintf(protologlocalarr, "%s/%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX,
+ client_ip, PROTOLOGSUFFIX, "\0");
+//strlcpy(ProtocolLogFileName, protologlocalarr, sizeof(ProtocolLogFileName));
+strlcpy(protologlocalarr,ProtocolLogDirName,sizeof(protologlocalarr));
+strlcat(protologlocalarr,"/",sizeof(protologlocalarr));
+strlcat(protologlocalarr,PROTOLOGPREFIX,sizeof(protologlocalarr));
+strlcat(protologlocalarr,client_ip,sizeof(protologlocalarr));
+strlcat(protologlocalarr,PROTOLOGSUFFIX,sizeof(protologlocalarr));
- strlcpy(ProtocolLogFileName, protologlocalarr, sizeof(ProtocolLogFileName));
+strlcpy(ProtocolLogFileName, protologlocalarr, sizeof(ProtocolLogFileName));
- log_println(5, "Protocol filename: %s: %s\n", ProtocolLogFileName,
- ProtocolLogDirName);
+log_println(5, "Protocol filename: %s: %s\n", ProtocolLogFileName,
+ProtocolLogDirName);
}
- */
+*/
/**
* Return the protocol validation log filename.
@@ -290,28 +290,28 @@
*/
char* get_protologfile(int socketNum, char *protologfilename, size_t filename_size) {
- char localAddr[64]="", remoteAddr[64]="";
- I2Addr tmp_addr = NULL;
- size_t tmpstrlen = sizeof(localAddr);
- memset(localAddr, 0, tmpstrlen);
- memset(remoteAddr, 0, tmpstrlen);
+ char localAddr[64]="", remoteAddr[64]="";
+ I2Addr tmp_addr = NULL;
+ size_t tmpstrlen = sizeof(localAddr);
+ memset(localAddr, 0, tmpstrlen);
+ memset(remoteAddr, 0, tmpstrlen);
- // get remote address
- tmp_addr =
- I2AddrBySockFD(get_errhandle(), socketNum, False);
- I2AddrNodeName(tmp_addr, remoteAddr, &tmpstrlen); //client name
+ // get remote address
+ tmp_addr =
+ I2AddrBySockFD(get_errhandle(), socketNum, False);
+ I2AddrNodeName(tmp_addr, remoteAddr, &tmpstrlen); //client name
- // get local address
- tmp_addr = I2AddrByLocalSockFD(get_errhandle(), socketNum, False);
+ // get local address
+ tmp_addr = I2AddrByLocalSockFD(get_errhandle(), socketNum, False);
- I2AddrNodeName(tmp_addr, localAddr, &tmpstrlen);
+ I2AddrNodeName(tmp_addr, localAddr, &tmpstrlen);
- // copy address into filename String
- snprintf(protologfilename, filename_size, "%s/%s%s%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX,
- localAddr, "_",remoteAddr, PROTOLOGSUFFIX, "\0");
- //log_print(0, "Log file name ---%s---", protologfilename);
+ // copy address into filename String
+ snprintf(protologfilename, filename_size, "%s/%s%s%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX,
+ localAddr, "_",remoteAddr, PROTOLOGSUFFIX, "\0");
+ //log_print(0, "Log file name ---%s---", protologfilename);
- return protologfilename;
+ return protologfilename;
}
/**
@@ -320,7 +320,7 @@
*/
int get_debuglvl() {
- return _debuglevel;
+ return _debuglevel;
}
/**
@@ -330,7 +330,7 @@
char*
get_logfile() {
- return LogFileName;
+ return LogFileName;
}
/**
@@ -340,7 +340,7 @@
*/
I2ErrHandle get_errhandle() {
- return _errorhandler_nl;
+ return _errorhandler_nl;
}
/**
@@ -352,15 +352,15 @@
void log_print(int lvl, const char* format, ...)
{
- va_list ap;
+ va_list ap;
- if (lvl > _debuglevel) {
- return;
- }
+ if (lvl > _debuglevel) {
+ return;
+ }
- va_start(ap, format);
- I2ErrLogVT(_errorhandler,-1,0,format,ap);
- va_end(ap);
+ va_start(ap, format);
+ I2ErrLogVT(_errorhandler,-1,0,format,ap);
+ va_end(ap);
}
/**
@@ -373,15 +373,15 @@
void log_println(int lvl, const char* format, ...)
{
- va_list ap;
+ va_list ap;
- if (lvl > _debuglevel) {
- return;
- }
+ if (lvl > _debuglevel) {
+ return;
+ }
- va_start(ap, format);
- I2ErrLogVT(_errorhandler_nl,-1,0,format,ap);
- va_end(ap);
+ va_start(ap, format);
+ I2ErrLogVT(_errorhandler_nl,-1,0,format,ap);
+ va_end(ap);
}
/**
@@ -396,40 +396,40 @@
* */
int quote_delimiters(const char *line, int line_size, char *output_buf, int output_buf_size) {
- static char quoted[4][2] = {
- { '\n', 'n' },
- { '"', '"' },
- { '\0', '0' },
- { '\\', '\\' },
- };
- char quote_char = '\\';
+ static char quoted[4][2] = {
+ { '\n', 'n' },
+ { '"', '"' },
+ { '\0', '0' },
+ { '\\', '\\' },
+ };
+ char quote_char = '\\';
- int i, j, k;
+ int i, j, k;
- for (i = j = 0; i < line_size && j < output_buf_size - 1; i++) {
- // find any matching characters among the quoted
- int match = 0;
- for (k = 0; k < 4; k++) {
- if (line[i] == quoted[k][0]) {
- output_buf[j] = quote_char;
- output_buf[j + 1] = quoted[k][1];
- j += 2;
- match = 1;
- break;
- }
- }
+ for (i = j = 0; i < line_size && j < output_buf_size - 1; i++) {
+ // find any matching characters among the quoted
+ int match = 0;
+ for (k = 0; k < 4; k++) {
+ if (line[i] == quoted[k][0]) {
+ output_buf[j] = quote_char;
+ output_buf[j + 1] = quoted[k][1];
+ j += 2;
+ match = 1;
+ break;
+ }
+ }
- if (match == 0) {
- output_buf[j] = line[i];
- j++;
- }
- }
+ if (match == 0) {
+ output_buf[j] = line[i];
+ j++;
+ }
+ }
- output_buf[j] = '\0'; // make sure it's null-terminated
- log_println(8, "****Received=%s; len=%d; dest=%d; MSG=%s", line, line_size,
- output_buf_size, output_buf);
+ output_buf[j] = '\0'; // make sure it's null-terminated
+ log_println(8, "****Received=%s; len=%d; dest=%d; MSG=%s", line, line_size,
+ output_buf_size, output_buf);
- return j - 1;
+ return j - 1;
}
/**
@@ -442,31 +442,31 @@
* @param socketnum Socket fd
*/
void protolog_printgeneric(const char* key, const char* value, int socketnum) {
- FILE * fp;
- char isotime[64];
+ FILE * fp;
+ char isotime[64];
- char logmessage[4096]; /* 4096 is just a random default buffer size for the protocol message
- Ideally, twice the messsage size will suffice */
- char tmplogname[FILENAME_SIZE];
+ char logmessage[4096]; /* 4096 is just a random default buffer size for the protocol message
+ Ideally, twice the messsage size will suffice */
+ char tmplogname[FILENAME_SIZE];
- if (!enableprotologging) {
- log_println(5, "Protocol logging is not enabled");
- return;
- }
+ if (!enableprotologging) {
+ log_println(5, "Protocol logging is not enabled");
+ return;
+ }
- // make delimiters in message payload explicit
- quote_delimiters(value, strlen(value), logmessage,
sizeof(logmessage));
+ // make delimiters in message payload explicit
+ quote_delimiters(value, strlen(value), logmessage, sizeof(logmessage));
- fp = fopen(get_protologfile(socketnum, tmplogname, sizeof(tmplogname)), "a");
- if (fp == NULL) {
- log_println(5,
- "--Unable to open proto file while trying to
record msg: %s \n",
- key, value);
- } else {
- fprintf(fp, " event=\"%s\", name=\"%s\", time=\"%s\"\n", key,
value,
- get_currenttime(isotime, sizeof(isotime)));
- fclose(fp);
- }
+ fp = fopen(get_protologfile(socketnum, tmplogname, sizeof(tmplogname)), "a");
+ if (fp == NULL) {
+ log_println(5,
+ "--Unable to open proto file while trying to record msg: %s \n",
+ key, value);
+ } else {
+ fprintf(fp, " event=\"%s\", name=\"%s\", time=\"%s\"\n", key, value,
+ get_currenttime(isotime, sizeof(isotime)));
+ fclose(fp);
+ }
}
/**
@@ -480,40 +480,40 @@
*
*/
void protolog_status(int pid, enum TEST_ID testid,
- enum TEST_STATUS_INT teststatus, int socketnum) {
- FILE * fp;
- //va_list ap;
- char protomessage[256];
- char currenttestarr[TEST_NAME_DESC_SIZE];
- char currentstatusarr[TEST_STATUS_DESC_SIZE];
- char isotime[64];
- char *currenttestname = "";
- char *teststatusdesc = "";
- char tmplogname[FILENAME_SIZE]="";
+ enum TEST_STATUS_INT teststatus, int socketnum) {
+ FILE * fp;
+ //va_list ap;
+ char protomessage[256];
+ char currenttestarr[TEST_NAME_DESC_SIZE];
+ char currentstatusarr[TEST_STATUS_DESC_SIZE];
+ char isotime[64];
+ char *currenttestname = "";
+ char *teststatusdesc = "";
+ char tmplogname[FILENAME_SIZE]="";
- //get descriptive strings for test name and status
- currenttestname = get_testnamedesc(testid, currenttestarr);
- teststatusdesc = get_teststatusdesc(teststatus, currentstatusarr);
+ //get descriptive strings for test name and status
+ currenttestname = get_testnamedesc(testid, currenttestarr);
+ teststatusdesc = get_teststatusdesc(teststatus, currentstatusarr);
- if (!enableprotologging) {
- log_println(5, "Protocol logging is not enabled");
- return;
- }
+ if (!enableprotologging) {
+ log_println(5, "Protocol logging is not enabled");
+ return;
+ }
- fp = fopen(get_protologfile(socketnum, tmplogname, sizeof(tmplogname)), "a");
- if (fp == NULL) {
- log_println(
- 5,
- "--Unable to open protocol log file while trying to record test status message: %s for the %s test \n",
- teststatusdesc, currenttestname);
- } else {
- snprintf(protomessage, sizeof(protomessage),
- " event=\"%s\", name=\"%s\", pid=\"%d\",
time=\"%s\"\n",
- teststatusdesc, currenttestname, pid,
- get_currenttime(isotime, sizeof(isotime)));
- fprintf(fp, "%s", protomessage);
- fclose(fp);
- }
+ fp = fopen(get_protologfile(socketnum, tmplogname, sizeof(tmplogname)), "a");
+ if (fp == NULL) {
+ log_println(
+ 5,
+ "--Unable to open protocol log file while trying to record test status message: %s for the %s test \n",
+ teststatusdesc, currenttestname);
+ } else {
+ snprintf(protomessage, sizeof(protomessage),
+ " event=\"%s\", name=\"%s\", pid=\"%d\", time=\"%s\"\n",
+ teststatusdesc, currenttestname, pid,
+ get_currenttime(isotime, sizeof(isotime)));
+ fprintf(fp, "%s", protomessage);
+ fclose(fp);
+ }
}
/**
@@ -527,53 +527,53 @@
* @param socketnum Socket fd
*/
void protolog_procstatus(int pid, enum TEST_ID testidarg,
- enum PROCESS_TYPE_INT procidarg, enum PROCESS_STATUS_INT teststatusarg, int socketnum) {
- FILE * fp;
- char protomessage[256];
- char isotime[64];
- char currentprocarr[TEST_NAME_DESC_SIZE]; // size suffices to describe process name name too
- char currentstatusarr[PROCESS_STATUS_DESC_SIZE];
- char currenttestarr[TEST_NAME_DESC_SIZE];
+ enum PROCESS_TYPE_INT procidarg, enum PROCESS_STATUS_INT teststatusarg, int socketnum) {
+ FILE * fp;
+ char protomessage[256];
+ char isotime[64];
+ char currentprocarr[TEST_NAME_DESC_SIZE]; // size suffices to describe process name name too
+ char currentstatusarr[PROCESS_STATUS_DESC_SIZE];
+ char currenttestarr[TEST_NAME_DESC_SIZE];
- char *currentprocname = "";
- char *procstatusdesc = "";
- char *currenttestname = "";
+ char *currentprocname = "";
+ char *procstatusdesc = "";
+ char *currenttestname = "";
- char tmplogname[FILENAME_SIZE];
+ char tmplogname[FILENAME_SIZE];
- //get descriptive strings for test name and status
- currenttestname = get_testnamedesc(testidarg, currenttestarr);
- currentprocname = get_processtypedesc(procidarg, currentprocarr);
- procstatusdesc = get_procstatusdesc(teststatusarg, currentstatusarr);
+ //get descriptive strings for test name and status
+ currenttestname = get_testnamedesc(testidarg, currenttestarr);
+ currentprocname = get_processtypedesc(procidarg, currentprocarr);
+ procstatusdesc = get_procstatusdesc(teststatusarg, currentstatusarr);
- if (!enableprotologging) {
- log_println(5, "Protocol logging is not enabled");
- return;
- }
+ if (!enableprotologging) {
+ log_println(5, "Protocol logging is not enabled");
+ return;
+ }
- fp = fopen(get_protologfile(socketnum, tmplogname, sizeof(tmplogname)), "a");
+ fp = fopen(get_protologfile(socketnum, tmplogname, sizeof(tmplogname)), "a");
- if (fp == NULL) {
- log_println(
- 5,
- "--Unable to open protocol log file while trying to record process status message: %s for the %s test \n",
- procstatusdesc, currentprocname);
- } else {
- log_println(8, " a0\n %s, %s, %s,%d", procstatusdesc,currentprocname,currenttestname,pid);
- snprintf(protomessage, sizeof(protomessage),
- " event=\"%s\", name=\"%s\", test=\"%s\", pid=\"%d\",
time=\"%s\"\n",
- procstatusdesc, currentprocname,
currenttestname, pid,
- get_currenttime(isotime, sizeof(isotime)));
- fprintf(fp, "%s", protomessage);
- fclose(fp);
- }
+ if (fp == NULL) {
+ log_println(
+ 5,
+ "--Unable to open protocol log file while trying to record process status message: %s for the %s test \n",
+ procstatusdesc, currentprocname);
+ } else {
+ log_println(8, " a0\n %s, %s, %s,%d", procstatusdesc,currentprocname,currenttestname,pid);
+ snprintf(protomessage, sizeof(protomessage),
+ " event=\"%s\", name=\"%s\", test=\"%s\", pid=\"%d\", time=\"%s\"\n",
+ procstatusdesc, currentprocname, currenttestname, pid,
+ get_currenttime(isotime, sizeof(isotime)));
+ fprintf(fp, "%s", protomessage);
+ fclose(fp);
+ }
}
/**
* Enable protocol logging
*/
void enableprotocollogging() {
- enableprotologging = 1;
+ enableprotologging = 1;
}
/**
@@ -583,21 +583,21 @@
* @param binout_arr output array containing binary bits
*/
void printbinary(char *charbinary, int inarray_size, char *binout_arr, int outarr_size) {
- int j = 7, i = 0;
+ int j = 7, i = 0;
- if ( outarr_size < 8 ) {
- log_println(8, "Invalid array sizes while formatting protocol binary data. Quitting");
- return;
- }
+ if ( outarr_size < 8 ) {
+ log_println(8, "Invalid array sizes while formatting protocol binary data. Quitting");
+ return;
+ }
- for (j = 7 ; j >= 0 && i < BITS_8; j--) {
- if ((*charbinary & (1 << j)))
- binout_arr[i] = '1';
- else
- binout_arr[i] = '0';
- i++;
- }
- binout_arr[i] = '\0';
+ for (j = 7 ; j >= 0 && i < BITS_8; j--) {
+ if ((*charbinary & (1 << j)))
+ binout_arr[i] = '1';
+ else
+ binout_arr[i] = '0';
+ i++;
+ }
+ binout_arr[i] = '\0';
}
@@ -618,23 +618,23 @@
* @return isbitfield
*/
int getMessageBodyFormat(int type, int len, char* msgbodytype, char* msgpayload, char* msgbits, int sizemsgbits) {
- int isbitfielddata = 0;
- enum MSG_BODY_TYPE msgbodyformat = NOT_KNOWN;
+ int isbitfielddata = 0;
+ enum MSG_BODY_TYPE msgbodyformat = NOT_KNOWN;
- if (type == MSG_LOGIN && len ==1 ) {
- msgbodyformat = BITFIELD;
- strlcpy(msgbodytype, (char *)getmessageformattype(msgbodyformat,msgbodytype), MSG_BODY_FMT_SIZE );
- printbinary (msgpayload, len, msgbits, sizemsgbits);
- isbitfielddata = 1;
- }
- else {
- msgbodyformat = STRING;
- strlcpy(msgbodytype , (char *)getmessageformattype(msgbodyformat,msgbodytype), MSG_BODY_FMT_SIZE);
- // make delimiters in message payload explicit
- quote_delimiters(msgpayload, len, msgbits, sizemsgbits);
+ if (type == MSG_LOGIN && len ==1 ) {
+ msgbodyformat = BITFIELD;
+ strlcpy(msgbodytype, (char *)getmessageformattype(msgbodyformat,msgbodytype), MSG_BODY_FMT_SIZE );
+ printbinary (msgpayload, len, msgbits, sizemsgbits);
+ isbitfielddata = 1;
+ }
+ else {
+ msgbodyformat = STRING;
+ strlcpy(msgbodytype , (char *)getmessageformattype(msgbodyformat,msgbodytype), MSG_BODY_FMT_SIZE);
+ // make delimiters in message payload explicit
+ quote_delimiters(msgpayload, len, msgbits, sizemsgbits);
- }
- return isbitfielddata;
+ }
+ return isbitfielddata;
}
@@ -650,36 +650,36 @@
* @param ctlSocket socket over which message has been exchanged
* */
void protolog_println(char *msgdirection, const int type, void* msg,
- const int len, const int processid, const int ctlSocket) {
- FILE * fp;
+ const int len, const int processid, const int ctlSocket) {
+ FILE * fp;
- char msgtypedescarr[MSG_TYPE_DESC_SIZE];
- char *currenttestname, *currentmsgtype;
- char isotime[64];
- char logmessage[4096]; // message after replacing delimiter characters
- char protologfile[FILENAME_SIZE];
- char msgbodytype[MSG_BODY_FMT_SIZE];
+ char msgtypedescarr[MSG_TYPE_DESC_SIZE];
+ char *currenttestname, *currentmsgtype;
+ char isotime[64];
+ char logmessage[4096]; // message after replacing delimiter characters
+ char protologfile[FILENAME_SIZE];
+ char msgbodytype[MSG_BODY_FMT_SIZE];
- // get descriptive strings for test name and direction
- currenttestname = get_currenttestdesc();
- currentmsgtype = get_msgtypedesc(type, msgtypedescarr);
+ // get descriptive strings for test name and direction
+ currenttestname = get_currenttestdesc();
+ currentmsgtype = get_msgtypedesc(type, msgtypedescarr);
- getMessageBodyFormat(type, len, msgbodytype, (char *) msg, logmessage, sizeof(logmessage));
+ getMessageBodyFormat(type, len, msgbodytype, (char *) msg, logmessage, sizeof(logmessage));
- fp = fopen(get_protologfile(ctlSocket, protologfile, sizeof(protologfile)), "a");
- if (fp == NULL) {
- log_println(
- 5,
- "Unable to open protocol log file '%s', continuing
on without logging",
- protologfile);
- } else {
- fprintf(
- fp,
- " event=\"message\", direction=\"%s\", test=\"%s\", type=\"%s\", len=\"%d\", msg_body_format=\"%s\", msg=\"%s\", pid=\"%d\", socket=\"%d\", time=\"%s\"\n",
- msgdirection, currenttestname, currentmsgtype, len, msgbodytype, logmessage,
- processid, ctlSocket,
get_currenttime(isotime, sizeof(isotime)));
- fclose(fp);
- }
+ fp = fopen(get_protologfile(ctlSocket, protologfile, sizeof(protologfile)), "a");
+ if (fp == NULL) {
+ log_println(
+ 5,
+ "Unable to open protocol log file '%s', continuing on without logging",
+ protologfile);
+ } else {
+ fprintf(
+ fp,
+ " event=\"message\", direction=\"%s\", test=\"%s\", type=\"%s\", len=\"%d\", msg_body_format=\"%s\", msg=\"%s\", pid=\"%d\", socket=\"%d\", time=\"%s\"\n",
+ msgdirection, currenttestname, currentmsgtype, len, msgbodytype, logmessage,
+ processid, ctlSocket, get_currenttime(isotime, sizeof(isotime)));
+ fclose(fp);
+ }
}
/** Log "sent" protocol messages.
@@ -692,16 +692,16 @@
* @param ctlSocket socket over which message has been exchanged
* */
void protolog_sendprintln(const int type, void* msg, const int len,
- const int processid, const int ctlSocket) {
- char *currentDir;
+ const int processid, const int ctlSocket) {
+ char *currentDir;
- if (!enableprotologging) {
- log_println(5, "Protocol logging is not enabled");
- return;
- }
- currentDir = get_currentdirndesc();
+ if (!enableprotologging) {
+ log_println(5, "Protocol logging is not enabled");
+ return;
+ }
+ currentDir = get_currentdirndesc();
- protolog_println(currentDir, type, msg, len, processid, ctlSocket);
+ protolog_println(currentDir, type, msg, len, processid, ctlSocket);
}
/**
@@ -715,30 +715,30 @@
* @param ctlSocket socket over which message has been exchanged
* */
void protolog_rcvprintln(const int type, void* msg, const int len,
- const int processid, const int ctlSocket) {
- char *otherDir;
- if (!enableprotologging) {
- log_println(5, "Protocol logging is not enabled");
- return;
- }
- otherDir = get_otherdirndesc();
- protolog_println(otherDir, type, msg, len, processid, ctlSocket);
+ const int processid, const int ctlSocket) {
+ char *otherDir;
+ if (!enableprotologging) {
+ log_println(5, "Protocol logging is not enabled");
+ return;
+ }
+ otherDir = get_otherdirndesc();
+ protolog_println(otherDir, type, msg, len, processid, ctlSocket);
}
/**
* Set the timestamp to actual time.
*/
void set_timestamp() {
- struct timeval tv;
+ struct timeval tv;
- gettimeofday(&tv, NULL);
- timestamp = tv.tv_sec;
- utimestamp = tv.tv_usec;
+ gettimeofday(&tv, NULL);
+ timestamp = tv.tv_sec;
+ utimestamp = tv.tv_usec;
- /* Changed function to use gettimeofday() need usec value for ISO8601 file names
- * RAC 5/6/09
- * timestamp = time(NULL);
- */
+ /* Changed function to use gettimeofday() need usec value for ISO8601 file names
+ * RAC 5/6/09
+ * timestamp = time(NULL);
+ */
}
@@ -747,7 +747,7 @@
* @return timestamp
*/
time_t get_timestamp() {
- return timestamp;
+ return timestamp;
}
/**
@@ -755,7 +755,7 @@
* @return The utimestamp
*/
long int get_utimestamp() {
- return utimestamp;
+ return utimestamp;
}
/**
@@ -766,14 +766,14 @@
void get_YYYY(char *year, size_t year_strlen) {
- struct tm *result;
- time_t now;
+ struct tm *result;
+ time_t now;
- setenv("TZ", "UTC", 0);
- now = get_timestamp();
- result = gmtime(&now);
+ setenv("TZ", "UTC", 0);
+ now = get_timestamp();
+ result = gmtime(&now);
- snprintf(year, year_strlen, "%d", 1900 + result->tm_year);
+ snprintf(year, year_strlen, "%d", 1900 + result->tm_year);
}
/**
@@ -784,18 +784,18 @@
void get_MM(char *month, size_t month_strlen) {
- struct tm *result;
- time_t now;
+ struct tm *result;
+ time_t now;
- /* setenv("TZ", NULL, 0); */
- setenv("TZ", "UTC", 0);
- now = get_timestamp();
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/src/mrange.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/mrange.c Thu Nov 15 13:33:19 2012
@@ -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;
@@ -32,61 +32,61 @@
*/
int mrange_parse(char* text) {
- char tmp[300];
- char* ptr, *sptr;
- Range* mr_ptr = NULL;
+ char tmp[300];
+ char* ptr, *sptr;
+ Range* mr_ptr = NULL;
- assert(text);
+ 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;
+ 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;
}
/**
@@ -102,29 +102,29 @@
char*
mrange_next(char* port, size_t port_strlen) {
- int val;
- Range* ptr;
+ int val;
+ Range* ptr;
- assert(port);
+ assert(port);
- if (check_rint(port, &val, 0, MAX_TCP_PORT)) { // check if valid
- log_println(0, "WARNING: invalid port number");
- snprintf(port, port_strlen, 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
- snprintf(port, port_strlen, "%d", val);
- return port;
- }
- ptr = ptr->next;
- }
- val++;
- }
- snprintf(port, port_strlen, RESERVED_PORT);
- return port;
+ if (check_rint(port, &val, 0, MAX_TCP_PORT)) { // check if valid
+ log_println(0, "WARNING: invalid port number");
+ snprintf(port, port_strlen, 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
+ snprintf(port, port_strlen, "%d", val);
+ return port;
+ }
+ ptr = ptr->next;
+ }
+ val++;
+ }
+ snprintf(port, port_strlen, RESERVED_PORT);
+ return port;
}
=======================================
--- /trunk/src/ndt_odbc.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/ndt_odbc.c Thu Nov 15 13:33:19 2012
@@ -102,27 +102,27 @@
* @param type SQLHandle type
* */
-static void
+ 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;
+ 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 );
+ 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
@@ -136,110 +136,110 @@
* */
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];
+ 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");
- snprintf(createTableStmt, sizeof(createTableStmt), "%s%s%s%s", ctStmt_1, ctStmt_2, ctStmt_3, ctStmt_4);
+ log_println(1, "Initializing DB with DSN='%s', UID='%s', PWD=%s", dsn, uid, pwd ? "yes" : "no");
+ snprintf(createTableStmt, sizeof(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);
- log_println(3,"Fetched SQLNumResults:%d", 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;
- }
- }
- }
- }
+ // 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);
+ log_println(3,"Fetched SQLNumResults:%d", 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;
+ // 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
}
@@ -249,87 +249,87 @@
* @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 c2s_linkspeed_data, int c2s_linkspeed_ack, int s2c_linkspeed_data,
- int s2c_linkspeed_ack, 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) {
+ 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 c2s_linkspeed_data, int c2s_linkspeed_ack, int s2c_linkspeed_data,
+ int s2c_linkspeed_ack, 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];
- int i_iter = 0, arr_len = 4; // 4 runspeed-averages are obtained
- if (!stmt) {
- return 1;
- }
- // Check if any of the run averages are nan numbers
- for (i_iter = 0; i_iter < arr_len; i_iter++) {
- log_println(3,"Odbc:Padding %f?", runave[i_iter]);
- pad_NaN(&runave[i_iter]);
- log_println(3,"Odbc:After Padding %f", runave[i_iter]);
- }
- 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, c2s_linkspeed_data, c2s_linkspeed_ack, s2c_linkspeed_data,
- s2c_linkspeed_ack, 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));
- log_println(3, "Trying to insert data using the statement:%s", 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;
- }
+ SQLRETURN ret;
+ char insertStmt[2048];
+ int i_iter = 0, arr_len = 4; // 4 runspeed-averages are obtained
+ if (!stmt) {
+ return 1;
+ }
+ // Check if any of the run averages are nan numbers
+ for (i_iter = 0; i_iter < arr_len; i_iter++) {
+ log_println(3,"Odbc:Padding %f?", runave[i_iter]);
+ pad_NaN(&runave[i_iter]);
+ log_println(3,"Odbc:After Padding %f", runave[i_iter]);
+ }
+ 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, c2s_linkspeed_data, c2s_linkspeed_ack, s2c_linkspeed_data,
+ s2c_linkspeed_ack, 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));
+ log_println(3, "Trying to insert data using the statement:%s", 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;
+ return 0;
#else
- return 1;
+ return 1;
#endif
}
/***
-* Check if the value is a NaN by comparing it with itself.
-* @args float_val value of the float variable which has to be checked for Nan
-*
-**/
+ * Check if the value is a NaN by comparing it with itself.
+ * @args float_val value of the float variable which has to be checked for Nan
+ *
+ **/
void pad_NaN(float *float_val) {
- if (*float_val != *float_val) {
- *float_val = -1;
- log_println(0," A float value you tried to insert into the DB was NaN");
- }
+ if (*float_val != *float_val) {
+ *float_val = -1;
+ log_println(0," A float value you tried to insert into the DB was NaN");
+ }
}
=======================================
--- /trunk/src/ndtptestconstants.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/ndtptestconstants.c Thu Nov 15 13:33:19 2012
@@ -13,20 +13,20 @@
// 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" };
+ "test_in_progress", "test_incomplete", "test_complete" };
// names of tests.
static char *_testnamesarray[] = { "None", "Middlebox", "SFW", "C2S", "S2C",
- "Meta" };
+ "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", };
+ "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" };
+ "server_to_client" };
static char *_msgbodyformattype[] = { "bitfield", "string", "none" };
@@ -37,9 +37,9 @@
* @return char* Descriptive string for test name
* */
char *get_testnamedesc(enum TEST_ID testid, char *snamearg) {
- snamearg = _testnamesarray[testid];
- //printf ("--current test name = %s for %d\n", snamearg ,testid);
- return snamearg;
+ snamearg = _testnamesarray[testid];
+ //printf ("--current test name = %s for %d\n", snamearg ,testid);
+ return snamearg;
}
/**
@@ -49,9 +49,9 @@
* @return char* Descriptive string for test status
* */
char *get_teststatusdesc(enum TEST_STATUS_INT teststatus, char *sstatusarg) {
- sstatusarg = _teststatusdescarray[teststatus];
- //printf ("--current test status = %s, for %d \n", sstatusarg, teststatus);
- return sstatusarg;
+ sstatusarg = _teststatusdescarray[teststatus];
+ //printf ("--current test status = %s, for %d \n", sstatusarg, teststatus);
+ return sstatusarg;
}
/**
@@ -62,9 +62,9 @@
* @return char* Descriptive string fr Test direction
* */
char *get_testdirectiondesc(enum Tx_DIRECTION testdirection, char *sdirnarg) {
- sdirnarg = _txdirectionsarray[testdirection];
- //printf ("--current test direction = %s , for %d\n", sdirnarg, testdirection);
- return sdirnarg;
+ sdirnarg = _txdirectionsarray[testdirection];
+ //printf ("--current test direction = %s , for %d\n", sdirnarg, testdirection);
+ return sdirnarg;
}
/**
@@ -75,9 +75,9 @@
* @return char* Descriptive string for Message type
* */
char *get_msgtypedesc(int msgtype, char *smsgtypearg) {
- smsgtypearg = _testmsgtypesarray[msgtype];
- //printf ("--current test type = %s , for %d\n", smsgtypearg,
msgtype);
- return smsgtypearg;
+ smsgtypearg = _testmsgtypesarray[msgtype];
+ //printf ("--current test type = %s , for %d\n", smsgtypearg, msgtype);
+ return smsgtypearg;
}
/**
@@ -87,6 +87,6 @@
* @return
*/
char * getmessageformattype(enum MSG_BODY_TYPE bodymsgformat, char *smsgformattypearg) {
- smsgformattypearg = _msgbodyformattype[bodymsgformat];
- return smsgformattypearg;
+ smsgformattypearg = _msgbodyformattype[bodymsgformat];
+ return smsgformattypearg;
}
=======================================
--- /trunk/src/network.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/network.c Thu Nov 15 13:33:19 2012
@@ -26,112 +26,112 @@
*/
static int OpenSocket(I2Addr addr, char* serv, int options) {
- struct addrinfo *fai;
- struct addrinfo *ai;
- int on;
- socklen_t onSize;
- int fd = -1;
+ struct addrinfo *fai;
+ struct addrinfo *ai;
+ int on;
+ socklen_t onSize;
+ int fd = -1;
- if (!(fai = I2AddrAddrInfo(addr, NULL, serv))) {
- return -2;
- }
+ if (!(fai = I2AddrAddrInfo(addr, NULL, serv))) {
+ return -2;
+ }
- for (ai = fai; ai; ai = ai->ai_next) {
- // options provided by user indicate V6
+ 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;
- }
+ 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);
+ // 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;
- }
+ // 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
+ // 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;
- }
+ on = 1;
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) {
+ goto failsock;
+ }
- // the IPv6 version socket option setup
+ // 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
+ // 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
+ // 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
+ // 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;
- }
+ 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;
- }
+ // 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))
- ;
- }
+ // 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;
+ // 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;
}
/**
@@ -146,71 +146,71 @@
*/
I2Addr CreateListenSocket(I2Addr addr, char* serv, int options, int buf_size) {
- int fd = -1;
- socklen_t optlen;
- int set_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 && (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 ((!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;
- }
+ 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);
+ // create and bind socket using arguments
+ fd = OpenSocket(addr, serv, options);
- if (fd < 0) {
- log_println(1, "Unable to open socket.");
- goto error;
- }
+ 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
- */
+ /* 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);
+ 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);
+ // 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 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;
- }
+ // 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;
+ return addr;
-// If error, try freeing memory
- error: I2AddrFree(addr);
- return NULL;
+ // If error, try freeing memory
+error: I2AddrFree(addr);
+ return NULL;
}
/**
@@ -228,135 +228,135 @@
*/
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;
+ 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);
+ assert(sockfd);
+ assert(server_addr);
- if (!server_addr) {
- goto error;
- }
+ if (!server_addr) {
+ goto error;
+ }
- // already connected and bound
- if ((*sockfd = I2AddrFD(server_addr)) > -1) {
- return 0;
- }
+ // already connected and bound
+ if ((*sockfd = I2AddrFD(server_addr)) > -1) {
+ return 0;
+ }
- if (!(fai = I2AddrAddrInfo(server_addr, NULL, NULL))) {
- goto error;
- }
+ if (!(fai = I2AddrAddrInfo(server_addr, NULL, NULL))) {
+ goto error;
+ }
- for (ai = fai; ai; ai = ai->ai_next) {
+ for (ai = fai; ai; ai = ai->ai_next) {
- // options provided by user indicate V6
+ // 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;
- }
+ // 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;
- }
+ // 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;
- }
+ // 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) {
+ // 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;
- }
+ 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 */
- }
- }
+ // 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
+ // 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
- */
+ /* 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);
+ 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);
- }
+ // 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) {
+ // 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;
- }
- }
+ // 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;
+error: log_println(1, "Unable to create connect socket.");
+ return -1;
}
/**
@@ -374,54 +374,54 @@
*/
int send_msg(int ctlSocket, int type, void* msg, int len) {
- unsigned char buff[3];
- int rc, i;
+ unsigned char buff[3];
+ int rc, i;
- assert(msg);
- assert(len >= 0);
+ 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;
+ /* 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;
- }
+ // 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;
+ // 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());
+ // 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);
+ protolog_sendprintln(type, msg, len, getpid(), ctlSocket);
- return 0;
+ return 0;
}
/**
@@ -438,40 +438,40 @@
*/
int recv_msg(int ctlSocket, int* type, void* msg, int* len) {
- unsigned char buff[3];
- int length;
+ unsigned char buff[3];
+ int length;
- char *msgtemp = (char*) msg;
+ char *msgtemp = (char*) msg;
- assert(type);
- assert(msg);
- assert(len);
+ assert(type);
+ assert(msg);
+ assert(len);
- // if 3 bytes are not explicitly read, signal error
- if (readn(ctlSocket, buff, 3) != 3) {
- return -1;
- }
+ // 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];
+ // 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);
+ // 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);
+ protolog_rcvprintln(*type, msgtemp, *len, getpid(), ctlSocket);
- return 0;
+ return 0;
}
/**
@@ -483,28 +483,28 @@
*/
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 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;
}
/**
@@ -516,46 +516,46 @@
*/
int readn(int fd, void* buf, int amount) {
- int received = 0, n, rc;
- char* ptr = buf;
- struct timeval sel_tv;
- fd_set rfd;
+ int received = 0, n, rc;
+ char* ptr = buf;
+ struct timeval sel_tv;
+ fd_set rfd;
- assert(amount >= 0);
+ assert(amount >= 0);
- FD_ZERO(&rfd); // initialize with zeroes
- FD_SET(fd, &rfd); //
- sel_tv.tv_sec = 600;
- sel_tv.tv_usec = 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) {
+ /* 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;
+ // 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;
}
=======================================
--- /trunk/src/protocol.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/protocol.c Thu Nov 15 13:33:19 2012
@@ -21,23 +21,23 @@
*/
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 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;
}
=======================================
--- /trunk/src/runningtest.c Tue Sep 25 06:49:57 2012
+++ /trunk/src/runningtest.c Thu Nov 15 13:33:19 2012
@@ -28,7 +28,7 @@
* @return integer current running test Id
* */
int getCurrentTest() {
- return currentTest;
+ return currentTest;
}
/** Set the id of the currently running test.
@@ -36,7 +36,7 @@
*/
void setCurrentTest(int testId) {
- currentTest = testId;
+ currentTest = testId;
}
/**
@@ -44,7 +44,7 @@
* @return integer direction corresponding to an enumerator
* */
int getCurrentDirn() {
- return currentDirection;
+ return currentDirection;
}
/** Set the test directions for the current process.
@@ -60,25 +60,25 @@
*/
void setCurrentDirn(enum Tx_DIRECTION directionarg) {
- char currenttestdirn[TEST_DIRN_DESC_SIZE];
- char othertestdirn[TEST_DIRN_DESC_SIZE];
- currentDirection = directionarg;
- switch (currentDirection) {
- case S_C:
- senddirnstr = get_testdirectiondesc(currentDirection,
currenttestdirn);
- recvdirnstr = get_testdirectiondesc(C_S, othertestdirn);
- break;
- case C_S:
- senddirnstr = get_testdirectiondesc(currentDirection,
currenttestdirn);
- recvdirnstr = get_testdirectiondesc(S_C, othertestdirn);
- break;
- case NO_DIR:
- default:
- senddirnstr = get_testdirectiondesc(NO_DIR, currenttestdirn);
- recvdirnstr = get_testdirectiondesc(NO_DIR, othertestdirn);
- ;
- break;
- }
+ char currenttestdirn[TEST_DIRN_DESC_SIZE];
+ char othertestdirn[TEST_DIRN_DESC_SIZE];
+ currentDirection = directionarg;
+ switch (currentDirection) {
+ case S_C:
+ senddirnstr = get_testdirectiondesc(currentDirection, currenttestdirn);
+ recvdirnstr = get_testdirectiondesc(C_S, othertestdirn);
+ break;
+ case C_S:
+ senddirnstr = get_testdirectiondesc(currentDirection, currenttestdirn);
+ recvdirnstr = get_testdirectiondesc(S_C, othertestdirn);
+ break;
+ case NO_DIR:
+ default:
+ senddirnstr = get_testdirectiondesc(NO_DIR, currenttestdirn);
+ recvdirnstr = get_testdirectiondesc(NO_DIR, othertestdirn);
+ ;
+ break;
+ }
}
/**
@@ -86,30 +86,30 @@
* @return descriptive name for the currently running test
*/
char *get_currenttestdesc() {
- enum TEST_ID currenttestId = NONE;
- char currenttestdesc[TEST_NAME_DESC_SIZE];
- switch (getCurrentTest()) {
- case TEST_MID:
- currenttestId = MIDDLEBOX;
- break;
- case TEST_C2S:
- currenttestId = C2S;
- break;
- case TEST_S2C:
- currenttestId = S2C;
- break;
- case TEST_SFW:
- currenttestId = SFW;
- break;
- case TEST_META:
- currenttestId = META;
- break;
- case TEST_NONE:
- default:
- currenttestId = NONE;
- break;
- }
- return get_testnamedesc(currenttestId, currenttestdesc);
+ enum TEST_ID currenttestId = NONE;
+ char currenttestdesc[TEST_NAME_DESC_SIZE];
+ switch (getCurrentTest()) {
+ case TEST_MID:
+ currenttestId = MIDDLEBOX;
+ break;
+ case TEST_C2S:
+ currenttestId = C2S;
+ break;
+ case TEST_S2C:
+ currenttestId = S2C;
+ break;
+ case TEST_SFW:
+ currenttestId = SFW;
+ break;
+ case TEST_META:
+ currenttestId = META;
+ break;
+ case TEST_NONE:
+ default:
+ currenttestId = NONE;
+ break;
+ }
+ return get_testnamedesc(currenttestId, currenttestdesc);
}
/**
@@ -118,7 +118,7 @@
* @return char* descriptive text of the current local direction
* */
char *get_currentdirndesc() {
- return senddirnstr;
+ return senddirnstr;
}
/**
@@ -127,7 +127,7 @@
* @return char* descriptive text of the current reverse direction
* */
char *get_otherdirndesc() {
- return recvdirnstr;
+ return recvdirnstr;
}
/**
@@ -135,9 +135,9 @@
* @return char* descriptive text of the process status
* */
char *get_procstatusdesc(enum PROCESS_STATUS_INT procstatusarg, char *sprocarg) {
- sprocarg = _procstatusarray[procstatusarg];
- //log_println(7,"--current process status = %s for %d\n", sprocarg, procstatusarg);
- return sprocarg;
+ sprocarg = _procstatusarray[procstatusarg];
+ //log_println(7,"--current process status = %s for %d\n", sprocarg, procstatusarg);
+ return sprocarg;
}
/**
@@ -147,8 +147,7 @@
* @return char* Descriptive string for process (process, connect )
* */
char *get_processtypedesc(enum PROCESS_TYPE_INT procidarg, char *snamearg) {
- snamearg = _proctypesarray[procidarg];
- //log_println(7,"--current process name = %s for %d\n", snamearg, procidarg);
- return snamearg;
+ snamearg = _proctypesarray[procidarg];
+ //log_println(7,"--current process name = %s for %d\n", snamearg, procidarg);
+ return snamearg;
}
-
=======================================
--- /trunk/src/strlutils.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/strlutils.c Thu Nov 15 13:33:19 2012
@@ -25,27 +25,27 @@
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t strlcpy(char *dst, const char *src, size_t siz) {
- char *d = dst;
- const char *s = src;
- size_t n = siz;
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
- /* Copy as many bytes as will fit */
- if (n != 0) {
- while (--n != 0) {
- if ((*d++ = *s++) == '\0')
- break;
- }
- }
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == '\0')
+ break;
+ }
+ }
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0) {
- if (siz != 0)
- *d = '\0'; /* NUL-terminate dst */
- while (*s++)
- ;
- }
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *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 */
}
/*
@@ -56,29 +56,28 @@
* 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;
+ 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;
+ /* 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';
+ 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 */
-}
-
+ return (dlen + (s - src)); /* count does not include NUL */
+ }
=======================================
--- /trunk/src/test_c2s_clt.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/test_c2s_clt.c Thu Nov 15 13:33:19 2012
@@ -42,169 +42,169 @@
*
*/
int test_c2s_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size) {
- /* char buff[BUFFSIZE+1]; */
- char buff[64 * KILO_BITS]; // message payload.
- // note that there is a size variation between server and CLT
- do not
- // know why this was changed from BUFFZISE, though
- // no specific problem is seen due to this
+ int buf_size) {
+ /* char buff[BUFFSIZE+1]; */
+ char buff[64 * KILO_BITS]; // message payload.
+ // note that there is a size variation between server and CLT - do not
+ // know why this was changed from BUFFZISE, though
+ // no specific problem is seen due to this
- int msgLen, msgType; // message related data
- int c2sport = atoi(PORT2); // default C2S port
- I2Addr sec_addr = NULL; // server address
- int retcode; // return code
- int one=1; // socket option store
- int i, k; // temporary iterator
- int outSocket; // socket descriptor for the outgoing
connection
- double t, stop_time;// test-time indicators
- // variables used for protocol validation logs
- enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
- enum TEST_ID testids = C2S;
+ int msgLen, msgType; // message related data
+ int c2sport = atoi(PORT2); // default C2S port
+ I2Addr sec_addr = NULL; // server address
+ int retcode; // return code
+ int one=1; // socket option store
+ int i, k; // temporary iterator
+ int outSocket; // socket descriptor for the outgoing
connection
+ double t, stop_time;// test-time indicators
+ // variables used for protocol validation logs
+ enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
+ enum TEST_ID testids = C2S;
- if (tests & TEST_C2S) { // C2S test has to be performed
- struct sigaction new, old;
- log_println(1, " <-- C2S throughput test -->");
- setCurrentTest(TEST_C2S);
- //protocol logs
- teststatuses = TEST_STARTED;
- protolog_status(getpid(), testids, teststatuses, ctlSocket);
+ if (tests & TEST_C2S) { // C2S test has to be performed
+ struct sigaction new, old;
+ log_println(1, " <-- C2S throughput test -->");
+ setCurrentTest(TEST_C2S);
+ //protocol logs
+ teststatuses = TEST_STARTED;
+ protolog_status(getpid(), testids, teststatuses, ctlSocket);
- msgLen = sizeof(buff);
+ msgLen = sizeof(buff);
- // Initially, the server sends a TEST_PREPARE message. Any
other message
- // type, or a message with payload length <0 is unexpected and
- // indicative of an error
- 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;
- }
+ // Initially, the server sends a TEST_PREPARE message. Any other message
+ // type, or a message with payload length <0 is unexpected and
+ // indicative of an error
+ 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;
+ }
- // Server sends port number to bind to in the TEST_PREPARE.
Check if this
- // message body (string) is a valid integral port number.
- buff[msgLen] = 0;
- if (check_int(buff, &c2sport)) {
- log_println(0, "Invalid port number");
- return 4;
- }
- log_println(1, " -- port: %d", c2sport);
+ // Server sends port number to bind to in the TEST_PREPARE. Check if this
+ // message body (string) is a valid integral port number.
+ buff[msgLen] = 0;
+ if (check_int(buff, &c2sport)) {
+ log_println(0, "Invalid port number");
+ return 4;
+ }
+ log_println(1, " -- port: %d", c2sport);
- // make struct of "address details" of the server using the
host name
- if ((sec_addr = I2AddrByNode(get_errhandle(), host)) == NULL)
{
- log_println(0, "Unable to resolve server address:
%s", strerror(errno));
- return -3;
- }
- I2AddrSetPort(sec_addr, c2sport); //set port value
+ // make struct of "address details" of the server using the host name
+ if ((sec_addr = I2AddrByNode(get_errhandle(), host)) == NULL) {
+ log_println(0, "Unable to resolve server address: %s", strerror(errno));
+ return -3;
+ }
+ I2AddrSetPort(sec_addr, c2sport); //set port value
- // connect to server and set socket options
- if ((retcode = CreateConnectSocket(&outSocket, NULL, sec_addr, conn_options, buf_size))) {
- log_println(0, "Connect() for client to server failed", strerror(errno));
- return -11;
- }
+ // connect to server and set socket options
+ if ((retcode = 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));
+ setsockopt(outSocket, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
- // Expect a TEST_START message from server now. Any other
message
- // type is an error
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed start
message!");
- return 1;
- }
- if (check_msg_type("C2S throughput test", TEST_START, msgType, buff, msgLen)) {
- return 2;
- }
+ // Expect a TEST_START message from server now. Any other message
+ // type is an error
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed start message!");
+ return 1;
+ }
+ if (check_msg_type("C2S throughput test", TEST_START, msgType, buff, msgLen)) {
+ return 2;
+ }
- // Prepare for running a C->S throughput test
- printf("running 10s outbound test (client to server) . . . . .
");
- fflush(stdout);
+ // Prepare for running a C->S throughput test
+ printf("running 10s outbound test (client to server) . . . . . ");
+ fflush(stdout);
- // ....Fill buffer upto NDTConstants.PREDEFNED_BUFFER_SIZE
packets
- pkts = 0;
- k = 0;
- for (i=0; i<(64*KILO_BITS); i++) { // again buffer sizes differ. Since the actual
- //
transmitted byte count is timed, it does'nt appear that it is
- //
causing specific problems.
- while (!isprint(k&0x7f))
- k++;
- buff[i] = (k++ % 0x7f);
- }
+ // ....Fill buffer upto NDTConstants.PREDEFNED_BUFFER_SIZE packets
+ pkts = 0;
+ k = 0;
+ for (i=0; i<(64*KILO_BITS); i++) { // again buffer sizes differ. Since the actual
+ // transmitted byte count is timed, it does'nt appear that it is
+ // causing specific problems.
+ while (!isprint(k&0x7f))
+ k++;
+ buff[i] = (k++ % 0x7f);
+ }
- // set the test time to 10 seconds
- t = secs();
- stop_time = t + 10;
- /* ignore the pipe signal */
- memset(&new, 0, sizeof(new));
- new.sa_handler = SIG_IGN;
- sigaction(SIGPIPE, &new, &old);
+ // set the test time to 10 seconds
+ t = secs();
+ stop_time = t + 10;
+ /* ignore the pipe signal */
+ memset(&new, 0, sizeof(new));
+ new.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &new, &old);
- // While the 10 s timer ticks, stream data to server. Record the byte count
- do {
- write(outSocket, buff, lth);
- pkts++;
- }while (secs() < stop_time);
- sigaction(SIGPIPE, &old, NULL);
- sndqueue = sndq_len(outSocket); //get send-queue length
+ // While the 10 s timer ticks, stream data to server. Record the byte count
+ do {
+ write(outSocket, buff, lth);
+ pkts++;
+ }while (secs() < stop_time);
+ sigaction(SIGPIPE, &old, NULL);
+ sndqueue = sndq_len(outSocket); //get send-queue length
- // get actual duration for which data was sent to the server
- t = secs() - t;
- I2AddrFree(sec_addr);
+ // get actual duration for which data was sent to the server
+ t = secs() - t;
+ I2AddrFree(sec_addr);
- // Calculate C2S throughput in kbps
- spdout = ((BITS_8_FLOAT * pkts * lth) / KILO) / t;
- //log_println(6," ---C->S CLT speed=%0.0f, pkts= %d, lth=%d, time=%d", spdout, pkts, lth, t);
+ // Calculate C2S throughput in kbps
+ spdout = ((BITS_8_FLOAT * pkts * lth) / KILO) / t;
+ //log_println(6," ---C->S CLT speed=%0.0f, pkts= %d, lth=%d, time=%d", spdout, pkts, lth, t);
- // The client has stopped streaming data, and the server is
now
- // expected to send a TEST_MSG message with the throughput it
calculated.
- // So, its time now to receive this throughput (c2sspd).
+ // The client has stopped streaming data, and the server is now
+ // expected to send a TEST_MSG message with the throughput it calculated.
+ // So, its time now to receive this throughput (c2sspd).
- 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)) {
- // other message types at this juncture indicate error
- return 2;
- }
- if (msgLen <= 0) { // message payload size cannot be
negative! Error.
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
+ 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)) {
+ // other message types at this juncture indicate error
+ return 2;
+ }
+ if (msgLen <= 0) { // message payload size cannot be negative!
Error.
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
- // get C->S test speed as calculated by server
- c2sspd = atoi(buff);
+ // get C->S test speed as calculated by server
+ c2sspd = atoi(buff);
- // Print results in the most convenient units (kbps or Mbps)
- if (c2sspd < KILO)
- printf(" %0.2f kb/s\n", c2sspd);
- else
- printf(" %0.2f Mb/s\n", c2sspd/KILO);
+ // Print results in the most convenient units (kbps or Mbps)
+ if (c2sspd < KILO)
+ printf(" %0.2f kb/s\n", c2sspd);
+ else
+ printf(" %0.2f Mb/s\n", c2sspd/KILO);
- // Server should close test session with an empty
TEST_FINALIZE message.
- // Any other type of message is an error.
- 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, " <------------------------->");
- //log protocol validation logs
- teststatuses = TEST_ENDED;
- protolog_status(getpid(), testids, teststatuses,ctlSocket);
- setCurrentTest(TEST_NONE);
- }
- return 0;
+ // Server should close test session with an empty TEST_FINALIZE message.
+ // Any other type of message is an error.
+ 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, " <------------------------->");
+ //log protocol validation logs
+ teststatuses = TEST_ENDED;
+ protolog_status(getpid(), testids, teststatuses,ctlSocket);
+ setCurrentTest(TEST_NONE);
+ }
+ return 0;
}
=======================================
--- /trunk/src/test_c2s_srv.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/test_c2s_srv.c Thu Nov 15 13:33:19 2012
@@ -61,383 +61,383 @@
*
*/
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 recvsfd; // receiver socket file descriptor
- pid_t c2s_childpid = 0; // child process pids
- int msgretvalue, tmpbytecount; // used during the "read"/"write"
process
- int i, j; // used as loop iterators
+ 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 recvsfd; // receiver socket file descriptor
+ pid_t c2s_childpid = 0; // child process pids
+ int msgretvalue, tmpbytecount; // used during the "read"/"write" process
+ int i, j; // used as loop iterators
- struct sockaddr_storage cli_addr;
+ struct sockaddr_storage cli_addr;
- socklen_t clilen;
- char tmpstr[256]; // string array used for all sorts of temp storage purposes
- double tmptime; // time indicator
- double bytes_read = 0; // number of bytes read during the throughput
tests
- struct timeval sel_tv; // time
- fd_set rfd; // receive file descriptor
- char buff[BUFFSIZE + 1]; // message "payload" buffer
- PortPair pair; // socket ports
- I2Addr c2ssrv_addr = NULL; // c2s test's server address
- //I2Addr src_addr=NULL; // c2s test source address
- char listenc2sport[10]; // listening port
- pthread_t workerThreadId;
+ socklen_t clilen;
+ char tmpstr[256]; // string array used for all sorts of temp storage purposes
+ double tmptime; // time indicator
+ double bytes_read = 0; // number of bytes read during the throughput tests
+ struct timeval sel_tv; // time
+ fd_set rfd; // receive file descriptor
+ char buff[BUFFSIZE + 1]; // message "payload" buffer
+ PortPair pair; // socket ports
+ I2Addr c2ssrv_addr = NULL; // c2s test's server address
+ //I2Addr src_addr=NULL; // c2s test source address
+ char listenc2sport[10]; // listening port
+ pthread_t workerThreadId;
- // web_100 related variables
- web100_group* group = NULL;
- web100_connection* conn = NULL;
+ // web_100 related variables
+ web100_group* group = NULL;
+ web100_connection* conn = NULL;
- // snap related variables
- SnapArgs snapArgs;
- snapArgs.snap = NULL;
- snapArgs.log = NULL;
- snapArgs.delay = options->snapDelay;
- wait_sig = 0;
+ // snap related variables
+ SnapArgs snapArgs;
+ snapArgs.snap = NULL;
+ snapArgs.log = NULL;
+ snapArgs.delay = options->snapDelay;
+ wait_sig = 0;
- // Test ID and status descriptors
- enum TEST_ID testids = C2S;
- enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
- enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
- enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;
- char namesuffix[256] = "c2s_snaplog";
+ // Test ID and status descriptors
+ enum TEST_ID testids = C2S;
+ enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
+ enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
+ enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;
+ char namesuffix[256] = "c2s_snaplog";
- if (testOptions->c2sopt) {
- setCurrentTest(TEST_C2S);
- log_println(1, " <-- %d - C2S throughput test -->",
- testOptions->child0);
- strlcpy(listenc2sport, PORT2, sizeof(listenc2sport));
+ if (testOptions->c2sopt) {
+ setCurrentTest(TEST_C2S);
+ log_println(1, " <-- %d - C2S throughput test -->",
+ testOptions->child0);
+ strlcpy(listenc2sport, PORT2, sizeof(listenc2sport));
- //log protocol validation logs
- teststatuses = TEST_STARTED;
- protolog_status(testOptions->child0, testids, teststatuses,
ctlsockfd);
+ //log protocol validation logs
+ teststatuses = TEST_STARTED;
+ protolog_status(testOptions->child0, testids, teststatuses, ctlsockfd);
- // Determine port to be used. Compute based on options set
earlier
- // by reading from config file, or use default port2 (3002).
- if (testOptions->c2ssockport) {
- snprintf(listenc2sport, sizeof(listenc2sport), "%d", testOptions->c2ssockport);
- } else if (testOptions->mainport) {
- snprintf(listenc2sport, sizeof(listenc2sport), "%d", testOptions->mainport + 1);
- }
+ // Determine port to be used. Compute based on options set earlier
+ // by reading from config file, or use default port2 (3002).
+ if (testOptions->c2ssockport) {
+ snprintf(listenc2sport, sizeof(listenc2sport), "%d", testOptions->c2ssockport);
+ } else if (testOptions->mainport) {
+ snprintf(listenc2sport, sizeof(listenc2sport), "%d", testOptions->mainport + 1);
+ }
- if (testOptions->multiple) {
- strlcpy(listenc2sport, "0", sizeof(listenc2sport));
- }
+ if (testOptions->multiple) {
+ strlcpy(listenc2sport, "0", sizeof(listenc2sport));
+ }
- // attempt to bind to a new port and obtain address structure with details of listening port
- while (c2ssrv_addr == NULL) {
- c2ssrv_addr = CreateListenSocket(
- NULL,
- (testOptions->multiple ?
- mrange_next(listenc2sport,
sizeof(listenc2sport)) : listenc2sport),
- conn_options, 0)
- ;
- if (strcmp(listenc2sport, "0") == 0) {
- log_println(0, "WARNING: ephemeral port number was
bound");
- break;
- }
- if (testOptions->multiple == 0) {
- break;
- }
- }
- if (c2ssrv_addr == NULL) {
- log_println(
- 0,
- "Server (C2S throughput test):
CreateListenSocket failed: %s",
- strerror(errno));
- snprintf(buff,
- sizeof(buff),
- "Server (C2S throughput test): CreateListenSocket
failed: %s",
- strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return -1;
- }
+ // attempt to bind to a new port and obtain address structure with details of listening port
+ while (c2ssrv_addr == NULL) {
+ c2ssrv_addr = CreateListenSocket(
+ NULL,
+ (testOptions->multiple ?
+ mrange_next(listenc2sport, sizeof(listenc2sport)) : listenc2sport),
+ conn_options, 0)
+ ;
+ if (strcmp(listenc2sport, "0") == 0) {
+ log_println(0, "WARNING: ephemeral port number was bound");
+ break;
+ }
+ if (testOptions->multiple == 0) {
+ break;
+ }
+ }
+ if (c2ssrv_addr == NULL) {
+ log_println(
+ 0,
+ "Server (C2S throughput test): CreateListenSocket failed: %s",
+ strerror(errno));
+ snprintf(buff,
+ sizeof(buff),
+ "Server (C2S throughput 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 run tests
- testOptions->c2ssockfd = I2AddrFD(c2ssrv_addr);
- testOptions->c2ssockport = I2AddrPort(c2ssrv_addr);
- log_println(1, " -- port: %d", testOptions->c2ssockport);
- pair.port1 = testOptions->c2ssockport;
- pair.port2 = -1;
+ // get socket FD and the ephemeral port number that client will connect to run tests
+ testOptions->c2ssockfd = I2AddrFD(c2ssrv_addr);
+ testOptions->c2ssockport = I2AddrPort(c2ssrv_addr);
+ log_println(1, " -- port: %d", testOptions->c2ssockport);
+ pair.port1 = testOptions->c2ssockport;
+ pair.port2 = -1;
- log_println(
- 1,
- "listening for Inet connection on
testOptions->c2ssockfd, fd=%d",
- testOptions->c2ssockfd);
+ log_println(
+ 1,
+ "listening for Inet connection on testOptions->c2ssockfd, fd=%d",
+ testOptions->c2ssockfd);
- log_println(
- 1,
- "Sending 'GO' signal, to tell client %d to head
for the next test",
- testOptions->child0);
- snprintf(buff, sizeof(buff), "%d", testOptions->c2ssockport);
+ log_println(
+ 1,
+ "Sending 'GO' signal, to tell client %d to head for the next test",
+ testOptions->child0);
+ snprintf(buff, sizeof(buff), "%d", testOptions->c2ssockport);
- // send TEST_PREPARE message with ephemeral port detail, indicating start of tests
- if ((msgretvalue = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff))) < 0)
- return msgretvalue;
+ // send TEST_PREPARE message with ephemeral port detail, indicating start of tests
+ if ((msgretvalue = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff))) < 0)
+ return msgretvalue;
- // Wait on listening socket and read data once ready.
- // Retry 5 times, waiting for activity on the socket
- clilen = sizeof(cli_addr);
- log_println(6, "child %d - sent c2s prepare to client",
- testOptions->child0);
- FD_ZERO(&rfd);
- FD_SET(testOptions->c2ssockfd, &rfd);
- sel_tv.tv_sec = 5;
- sel_tv.tv_usec = 0;
+ // Wait on listening socket and read data once ready.
+ // Retry 5 times, waiting for activity on the socket
+ clilen = sizeof(cli_addr);
+ log_println(6, "child %d - sent c2s prepare to client",
+ testOptions->child0);
+ FD_ZERO(&rfd);
+ FD_SET(testOptions->c2ssockfd, &rfd);
+ sel_tv.tv_sec = 5;
+ sel_tv.tv_usec = 0;
- for (j = 0; j < RETRY_COUNT; j++) {
- msgretvalue = select((testOptions->c2ssockfd) + 1,
&rfd, NULL, NULL,
- &sel_tv);
- if ((msgretvalue == -1) && (errno == EINTR)) // socket interrupted. 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 == (RETRY_COUNT - 1)) // retry exceeded. exit
- return -RETRY_EXCEEDED_WAITING_CONNECT;
- recfd:
+ for (j = 0; j < RETRY_COUNT; j++) {
+ msgretvalue = select((testOptions->c2ssockfd) + 1, &rfd, NULL, NULL,
+ &sel_tv);
+ if ((msgretvalue == -1) && (errno == EINTR)) // socket interrupted. 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 == (RETRY_COUNT - 1)) // retry exceeded. exit
+ return -RETRY_EXCEEDED_WAITING_CONNECT;
+recfd:
- // If a valid connection request is received, client has connected. Proceed.
- // Note the new socket fd - recvsfd- used in the
throughput test
- recvsfd = accept(testOptions->c2ssockfd,
- (struct sockaddr *) &cli_addr,
&clilen);
- if (recvsfd > 0) {
- log_println(6, "accept() for %d completed",
- testOptions->child0);
+ // If a valid connection request is received, client has connected. Proceed.
+ // Note the new socket fd - recvsfd- used in the throughput test
+ recvsfd = accept(testOptions->c2ssockfd,
+ (struct sockaddr *) &cli_addr, &clilen);
+ if (recvsfd > 0) {
+ log_println(6, "accept() for %d completed",
+ testOptions->child0);
- // log protocol validation indicating client
accept
- procstatusenum = PROCESS_STARTED;
- proctypeenum = CONNECT_TYPE;
- protolog_procstatus(testOptions->child0,
testids, proctypeenum,
- procstatusenum, recvsfd);
- break;
- }
- if ((recvsfd == -1) && (errno == EINTR)) { // socket interrupted, wait some more
- log_println(
- 6,
- "Child %d interrupted while
waiting for accept() to complete",
- testOptions->child0);
- goto recfd;
- }
- log_println(
- 6,
- "------- C2S connection setup for %d
returned because (%d)",
- testOptions->child0, errno);
- if (recvsfd < 0) { // other socket errors, quit
- return -errno;
- }
- if (j == (RETRY_COUNT - 1)) { // retry exceeded, quit
- log_println(
- 6,
- "c2s child %d, uable to open
connection, return from test",
- testOptions->child0);
- return RETRY_EXCEEDED_WAITING_DATA;
- }
- }
+ // log protocol validation indicating client accept
+ procstatusenum = PROCESS_STARTED;
+ proctypeenum = CONNECT_TYPE;
+ protolog_procstatus(testOptions->child0, testids, proctypeenum,
+ procstatusenum, recvsfd);
+ break;
+ }
+ if ((recvsfd == -1) && (errno == EINTR)) { // socket interrupted, wait some more
+ log_println(
+ 6,
+ "Child %d interrupted while waiting for accept() to complete",
+ testOptions->child0);
+ goto recfd;
+ }
+ log_println(
+ 6,
+ "------- C2S connection setup for %d returned because (%d)",
+ testOptions->child0, errno);
+ if (recvsfd < 0) { // other socket errors, quit
+ return -errno;
+ }
+ if (j == (RETRY_COUNT - 1)) { // retry exceeded, quit
+ log_println(
+ 6,
+ "c2s child %d, uable to open connection, return from test",
+ testOptions->child0);
+ return RETRY_EXCEEDED_WAITING_DATA;
+ }
+ }
- // Get address associated with the throughput test. Used for packet tracing
- log_println(6, "child %d - c2s ready for test with fd=%d",
- testOptions->child0, recvsfd);
+ // Get address associated with the throughput test. Used for packet tracing
+ log_println(6, "child %d - c2s ready for test with fd=%d",
+ testOptions->child0, recvsfd);
- // commenting out below to move to init_pkttrace function
- I2Addr src_addr = I2AddrByLocalSockFD(get_errhandle(),
recvsfd, 0);
+ // commenting out below to move to init_pkttrace function
+ I2Addr src_addr = I2AddrByLocalSockFD(get_errhandle(), recvsfd, 0);
- // Get web100 connection. Used to collect web100 variable
statistics
- conn = web100_connection_from_socket(agent, recvsfd);
+ // Get web100 connection. Used to collect web100 variable statistics
+ conn = web100_connection_from_socket(agent, recvsfd);
- // set up packet tracing. Collected data is used for bottleneck link calculations
- if (getuid() == 0) {
- /*
- pipe(mon_pipe1);
- log_println(0, "%s test calling pkt_trace_start() with pd=%d for device %s, addr %s",
- currenttestdesc, clilen, device ,
src_addr);
+ // set up packet tracing. Collected data is used for bottleneck link calculations
+ if (getuid() == 0) {
+ /*
+ pipe(mon_pipe1);
+ log_println(0, "%s test calling pkt_trace_start() with pd=%d for device %s, addr %s",
+ currenttestdesc, clilen, device , src_addr);
- start_packet_trace(recvsfd, testOptions->c2ssockfd,
&c2s_childpid,
- mon_pipe1,
(struct sockaddr *) &cli_addr, clilen, device,
- &pair,
currenttestdesc, options->compress, meta.c2s_ndttrace);
- */
+ start_packet_trace(recvsfd, testOptions->c2ssockfd, &c2s_childpid,
+ mon_pipe1, (struct sockaddr *) &cli_addr, clilen, device,
+ &pair, currenttestdesc, options->compress, meta.c2s_ndttrace);
+ */
- pipe(mon_pipe1);
- if ((c2s_childpid = fork()) == 0) {
- /* close(ctlsockfd); */
- close(testOptions->c2ssockfd);
- close(recvsfd);
- log_println(
- 5,
- "C2S test Child %d thinks pipe()
returned fd0=%d, fd1=%d",
- testOptions->child0,
mon_pipe1[0], mon_pipe1[1]);
- log_println(2, "C2S test calling init_pkttrace() with pd=%p", &cli_addr);
- init_pkttrace(src_addr, (struct sockaddr *)
&cli_addr, clilen,
- mon_pipe1, device, &pair, "c2s",
options->compress);
- exit(0); /* Packet trace finished, terminate
gracefully */
- }
+ pipe(mon_pipe1);
+ if ((c2s_childpid = fork()) == 0) {
+ /* close(ctlsockfd); */
+ close(testOptions->c2ssockfd);
+ close(recvsfd);
+ log_println(
+ 5,
+ "C2S test Child %d thinks pipe() returned fd0=%d, fd1=%d",
+ testOptions->child0, mon_pipe1[0], mon_pipe1[1]);
+ log_println(2, "C2S test calling init_pkttrace() with pd=%p", &cli_addr);
+ init_pkttrace(src_addr, (struct sockaddr *) &cli_addr, clilen,
+ mon_pipe1, device, &pair, "c2s", options->compress);
+ exit(0); /* Packet trace finished, terminate gracefully */
+ }
- // Get data collected from packet tracing into the C2S
"ndttrace" file
- memset(tmpstr, 0, 256);
- for (i = 0; i < 5; i++) {
- msgretvalue = read(mon_pipe1[0], tmpstr, 128);
- if ((msgretvalue == -1) && (errno == EINTR))
- continue;
- break;
- }
- if (strlen(tmpstr) > 5)
- memcpy(meta.c2s_ndttrace, tmpstr,
strlen(tmpstr));
- //name of nettrace file passed back from pcap child
+ // Get data collected from packet tracing into the C2S "ndttrace" file
+ memset(tmpstr, 0, 256);
+ for (i = 0; i < 5; i++) {
+ msgretvalue = read(mon_pipe1[0], tmpstr, 128);
+ if ((msgretvalue == -1) && (errno == EINTR))
+ continue;
+ break;
+ }
+ if (strlen(tmpstr) > 5)
+ memcpy(meta.c2s_ndttrace, tmpstr, strlen(tmpstr));
+ //name of nettrace file passed back from pcap child
- log_println(3, "--tracefile after packet_trace %s",
- meta.c2s_ndttrace);
- }
+ log_println(3, "--tracefile after packet_trace %s",
+ meta.c2s_ndttrace);
+ }
- log_println(5, "C2S test Parent thinks pipe() returned fd0=%d,
fd1=%d",
- mon_pipe1[0], mon_pipe1[1]);
+ log_println(5, "C2S test Parent thinks pipe() returned fd0=%d, fd1=%d",
+ mon_pipe1[0], mon_pipe1[1]);
- // experimental code, delete when finished
- setCwndlimit(conn, group, agent, options);
+ // experimental code, delete when finished
+ setCwndlimit(conn, group, agent, options);
- // Create C->S snaplog directories, and perform some initialization based on options
+ // Create C->S snaplog directories, and perform some initialization based on options
- create_client_logdir((struct sockaddr *) &cli_addr, clilen,
- options->c2s_logname,
sizeof(options->c2s_logname), namesuffix,
- sizeof(namesuffix));
- sleep(2);
+ create_client_logdir((struct sockaddr *) &cli_addr, clilen,
+ options->c2s_logname, sizeof(options->c2s_logname), namesuffix,
+ sizeof(namesuffix));
+ sleep(2);
- // send empty TEST_START indicating start of the test
- send_msg(ctlsockfd, TEST_START, "", 0);
- /* alarm(30); *//* reset alarm() again, this 10 sec test should finish before this signal
- * is generated. */
+ // send empty TEST_START indicating start of the test
+ send_msg(ctlsockfd, TEST_START, "", 0);
+ /* alarm(30); *//* reset alarm() again, this 10 sec test should finish before this signal
+ * is generated. */
- // If snaplog recording is enabled, update meta file to
indicate the same
- // and proceed to get snapshot and log it.
- // This block is needed here since the meta file stores names without the full directory
- // but fopen needs full path. Else, it could have gone into the "start_snap_worker" method
- if (options->snaplog) {
- memcpy(meta.c2s_snaplog, namesuffix,
strlen(namesuffix));
- /*start_snap_worker(&snapArgs, agent, options->snaplog,
&workerLoop,
- &workerThreadId, meta.c2s_snaplog,
options->c2s_logname,
- conn, group); */
- }
- start_snap_worker(&snapArgs, agent, NULL, options->snaplog, &workerThreadId,
- meta.c2s_snaplog,
options->c2s_logname, conn, group);
- // Wait on listening socket and read data once ready.
- tmptime = secs();
- sel_tv.tv_sec = 11; // time out after 11 seconds
- sel_tv.tv_usec = 0;
- FD_ZERO(&rfd);
- FD_SET(recvsfd, &rfd);
- for (;;) {
- msgretvalue = select(recvsfd + 1, &rfd, NULL, NULL,
&sel_tv);
- if ((msgretvalue == -1) && (errno == EINTR)) {
- // socket interrupted. Continue waiting for
activity on socket
- continue;
- }
- if (msgretvalue > 0) { // read from socket
- tmpbytecount = read(recvsfd, buff,
sizeof(buff));
- if ((tmpbytecount == -1) && (errno == EINTR)) // read interrupted,continue waiting
- continue;
- if (tmpbytecount == 0) // all data has been
read
- break;
- bytes_read += tmpbytecount; // data byte
count has to be increased
- continue;
- }
- break;
- }
+ // If snaplog recording is enabled, update meta file to indicate the same
+ // and proceed to get snapshot and log it.
+ // This block is needed here since the meta file stores names without the full directory
+ // but fopen needs full path. Else, it could have gone into the "start_snap_worker" method
+ if (options->snaplog) {
+ memcpy(meta.c2s_snaplog, namesuffix, strlen(namesuffix));
+ /*start_snap_worker(&snapArgs, agent, options->snaplog, &workerLoop,
+ &workerThreadId, meta.c2s_snaplog, options->c2s_logname,
+ conn, group); */
+ }
+ start_snap_worker(&snapArgs, agent, NULL, options->snaplog, &workerThreadId,
+ meta.c2s_snaplog, options->c2s_logname, conn,
group);
+ // Wait on listening socket and read data once ready.
+ tmptime = secs();
+ sel_tv.tv_sec = 11; // time out after 11 seconds
+ sel_tv.tv_usec = 0;
+ FD_ZERO(&rfd);
+ FD_SET(recvsfd, &rfd);
+ for (;;) {
+ msgretvalue = select(recvsfd + 1, &rfd, NULL, NULL, &sel_tv);
+ if ((msgretvalue == -1) && (errno == EINTR)) {
+ // socket interrupted. Continue waiting for activity on socket
+ continue;
+ }
+ if (msgretvalue > 0) { // read from socket
+ tmpbytecount = read(recvsfd, buff, sizeof(buff));
+ if ((tmpbytecount == -1) && (errno == EINTR)) // read interrupted,continue waiting
+ continue;
+ if (tmpbytecount == 0) // all data has been read
+ break;
+ bytes_read += tmpbytecount; // data byte count has to be increased
+ continue;
+ }
+ break;
+ }
- tmptime = secs() - tmptime;
- // throughput in kilo bits per sec = (transmitted_byte_count * 8) / (time_duration)*(1000)
- *c2sspd = (8.e-3 * bytes_read) / tmptime;
+ tmptime = secs() - tmptime;
+ // throughput in kilo bits per sec = (transmitted_byte_count * 8) / (time_duration)*(1000)
+ *c2sspd = (8.e-3 * bytes_read) / tmptime;
- // c->s throuput value calculated and assigned ! Release resources, conclude snap writing.
- stop_snap_worker(&workerThreadId, options->snaplog,
&snapArgs);
+ // c->s throuput value calculated and assigned ! Release resources, conclude snap writing.
+ stop_snap_worker(&workerThreadId, options->snaplog, &snapArgs);
- // send the server calculated value of C->S throughput as result to client
- snprintf(buff, sizeof(buff), "%6.0f kbps outbound for child
%d", *c2sspd,
- testOptions->child0);
- log_println(1, "%s", buff);
- snprintf(buff, sizeof(buff), "%0.0f", *c2sspd);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ // send the server calculated value of C->S throughput as result to client
+ snprintf(buff, sizeof(buff), "%6.0f kbps outbound for child %d", *c2sspd,
+ testOptions->child0);
+ log_println(1, "%s", buff);
+ snprintf(buff, sizeof(buff), "%0.0f", *c2sspd);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- // get receiver side Web100 stats and write them to the log file. close sockets
- if (record_reverse == 1)
- web100_get_data_recv(recvsfd, agent, conn,
count_vars);
+ // get receiver side Web100 stats and write them to the log file. close sockets
+ if (record_reverse == 1)
+ web100_get_data_recv(recvsfd, agent, conn, count_vars);
- close(recvsfd);
- close(testOptions->c2ssockfd);
+ close(recvsfd);
+ close(testOptions->c2ssockfd);
- // Next, send speed-chk a flag to retrieve the data it
collected.
- // Skip this step if speed-chk isn't running.
+ // Next, send speed-chk a flag to retrieve the data it collected.
+ // Skip this step if speed-chk isn't running.
- if (getuid() == 0) {
- log_println(1, "Signal USR1(%d) sent to child [%d]",
SIGUSR1,
- c2s_childpid);
- testOptions->child1 = c2s_childpid;
- kill(c2s_childpid, SIGUSR1);
- FD_ZERO(&rfd);
- FD_SET(mon_pipe1[0], &rfd);
- sel_tv.tv_sec = 1;
- sel_tv.tv_usec = 100000;
- i = 0;
+ if (getuid() == 0) {
+ log_println(1, "Signal USR1(%d) sent to child [%d]", SIGUSR1,
+ c2s_childpid);
+ testOptions->child1 = c2s_childpid;
+ kill(c2s_childpid, SIGUSR1);
+ FD_ZERO(&rfd);
+ FD_SET(mon_pipe1[0], &rfd);
+ sel_tv.tv_sec = 1;
+ sel_tv.tv_usec = 100000;
+ i = 0;
- for (;;) {
- msgretvalue = select(mon_pipe1[0] + 1, &rfd,
NULL, NULL,
- &sel_tv);
- if ((msgretvalue == -1) && (errno == EINTR))
- continue;
- if (((msgretvalue == -1) && (errno != EINTR))
- || (msgretvalue == 0)) {
- log_println(4,
- "Failed to read pkt-pair data from
C2S flow, retcode=%d, reason=%d",
- msgretvalue, errno);
- snprintf(spds[(*spd_index)++],
- sizeof(spds[*spd_index]),
- " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 0.0 0 0 0 0 0 -1");
- snprintf(spds[(*spd_index)++],
- sizeof(spds[*spd_index]),
- " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 0.0 0 0 0 0 0 -1");
- break;
- }
- /* There is something to read, so get it from the pktpair child. If an interrupt occurs,
- * just skip the read and go on
- * RAC 2/8/10
- */
- if (msgretvalue > 0) {
- if ((msgretvalue = read(mon_pipe1[0], spds[*spd_index], sizeof(spds[*spd_index])))
- < 0)
- snprintf(
-
spds[*spd_index],
-
sizeof(spds[*spd_index]),
- " -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
- log_println(1, "%d bytes read '%s' from
C2S monitor pipe",
- msgretvalue,
spds[*spd_index]);
- (*spd_index)++;
- if (i++ == 1)
- break;
- sel_tv.tv_sec = 1;
- sel_tv.tv_usec = 100000;
- continue;
- }
+ for (;;) {
+ msgretvalue = select(mon_pipe1[0] + 1, &rfd, NULL, NULL,
+ &sel_tv);
+ if ((msgretvalue == -1) && (errno == EINTR))
+ continue;
+ if (((msgretvalue == -1) && (errno != EINTR))
+ || (msgretvalue == 0)) {
+ log_println(4,
+ "Failed to read pkt-pair data from C2S flow, retcode=%d, reason=%d",
+ msgretvalue, errno);
+ snprintf(spds[(*spd_index)++],
+ sizeof(spds[*spd_index]),
+ " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
+ snprintf(spds[(*spd_index)++],
+ sizeof(spds[*spd_index]),
+ " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
+ break;
+ }
+ /* There is something to read, so get it from the pktpair child. If an interrupt occurs,
+ * just skip the read and go on
+ * RAC 2/8/10
+ */
+ if (msgretvalue > 0) {
+ if ((msgretvalue = read(mon_pipe1[0], spds[*spd_index], sizeof(spds[*spd_index])))
+ < 0)
+ snprintf(
+ spds[*spd_index],
+ sizeof(spds[*spd_index]),
+ " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
+ log_println(1, "%d bytes read '%s' from C2S monitor pipe",
+ msgretvalue, spds[*spd_index]);
+ (*spd_index)++;
+ if (i++ == 1)
+ break;
+ sel_tv.tv_sec = 1;
+ sel_tv.tv_usec = 100000;
+ continue;
+ }
- }
- }
+ }
+ }
- // An empty TEST_FINALIZE message is sent to conclude the test
- send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
+ // An empty TEST_FINALIZE message is sent to conclude the test
+ send_msg(ctlsockfd, TEST_FINALIZE, "", 0);
- // Close opened resources for packet capture
- if (getuid() == 0) {
- stop_packet_trace(mon_pipe1);
- }
+ // Close opened resources for packet capture
+ if (getuid() == 0) {
+ stop_packet_trace(mon_pipe1);
+ }
- // log end of C->S test
- log_println(1, " <----------- %d -------------->",
testOptions->child0);
- //protocol logs
- teststatuses = TEST_ENDED;
- protolog_status(testOptions->child0, testids, teststatuses,
ctlsockfd);
+ // log end of C->S test
+ log_println(1, " <----------- %d -------------->", testOptions->child0);
+ //protocol logs
+ teststatuses = TEST_ENDED;
+ protolog_status(testOptions->child0, testids, teststatuses, ctlsockfd);
- //set current test status and free address
- setCurrentTest(TEST_NONE);
+ //set current test status and free address
+ setCurrentTest(TEST_NONE);
- }
+ }
- return 0;
+ return 0;
}
=======================================
--- /trunk/src/test_meta_clt.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/test_meta_clt.c Thu Nov 15 13:33:19 2012
@@ -38,101 +38,101 @@
* 2: Wrong message type received
*/
int test_meta_clt(int ctlSocket, char tests, char* host, int conn_options) {
- char buff[1024], tmpBuff[512];
- int msgLen, msgType;
- FILE * fp;
+ char buff[1024], tmpBuff[512];
+ int msgLen, msgType;
+ FILE * fp;
- //Protocol validation variables
- enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
- enum TEST_ID testids = META;
+ //Protocol validation variables
+ enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
+ enum TEST_ID testids = META;
- if (tests & TEST_META) { // perform META tests
- log_println(1, " <-- META test -->");
- setCurrentTest(TEST_META);
- //protocol logs
- teststatuses = TEST_STARTED;
- protolog_status(getpid(), testids, teststatuses, ctlSocket);
- msgLen = sizeof(buff);
- // Server starts with a TEST_PREPARE message. Any other
- // .. type of message at this juncture is unexpected !
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed prepare
message!");
- return 1;
- }
- if (check_msg_type(META_TEST_LOG, TEST_PREPARE, msgType,
buff, msgLen)) {
- return 2;
- }
+ if (tests & TEST_META) { // perform META tests
+ log_println(1, " <-- META test -->");
+ setCurrentTest(TEST_META);
+ //protocol logs
+ teststatuses = TEST_STARTED;
+ protolog_status(getpid(), testids, teststatuses, ctlSocket);
+ msgLen = sizeof(buff);
+ // Server starts with a TEST_PREPARE message. Any other
+ // .. type of message at this juncture is unexpected !
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed prepare message!");
+ return 1;
+ }
+ if (check_msg_type(META_TEST_LOG, TEST_PREPARE, msgType, buff, msgLen)) {
+ return 2;
+ }
- // Server now sends a TEST_START message. Any other message
type is
- // .. indicative of errors
- 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_LOG, TEST_START, msgType, buff,
msgLen)) {
- return 2;
- }
+ // Server now sends a TEST_START message. Any other message type is
+ // .. indicative of errors
+ 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_LOG, TEST_START, msgType, buff, msgLen)) {
+ return 2;
+ }
- // As a response to the Server's TEST_START message, client
responds
- // ..with TEST_MSG. These messages may be used, as below, to send configuration data
- // ...name-value pairs. Note that there are length constraints to keys- values: 64/256
- // ....characters respectively
+ // As a response to the Server's TEST_START message, client responds
+ // ..with TEST_MSG. These messages may be used, as below, to send configuration data
+ // ...name-value pairs. Note that there are length constraints to keys- values: 64/256
+ // ....characters respectively
- printf("sending meta information to server . . . . . ");
- fflush(stdout);
+ printf("sending meta information to server . . . . . ");
+ fflush(stdout);
- snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_APPLICATION,
"cli");
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
- // send client os name details
- 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);
- snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_OS,
tmpBuff);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
- }
+ snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_APPLICATION, "cli");
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ // send client os name details
+ 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);
+ snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_OS, tmpBuff);
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ }
- // send client browser name
- snprintf(buff, sizeof(buff), "%s:%s", META_BROWSER_OS, "-
(web100clt)");
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ // send client browser name
+ snprintf(buff, sizeof(buff), "%s:%s", META_BROWSER_OS, "- (web100clt)");
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
- // send client kernel version
- 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);
- snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_KERNEL_VERSION, tmpBuff);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
- }
+ // send client kernel version
+ 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);
+ snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_KERNEL_VERSION, tmpBuff);
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ }
- // send NDT client version
- snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_VERSION,
VERSION);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ // send NDT client version
+ snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_VERSION, VERSION);
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
- // Client can send any number of such meta data in a TEST_MSG
- // .. format, and signal the end of the transmission using an empty TEST_MSG
- send_msg(ctlSocket, TEST_MSG, "", 0);
+ // Client can send any number of such meta data in a TEST_MSG
+ // .. format, and signal the end of the transmission using an empty TEST_MSG
+ send_msg(ctlSocket, TEST_MSG, "", 0);
- printf("Done\n");
+ printf("Done\n");
- // All data has been sent. Expect server to close this META
test session
- // ... by sending an empty TEST_FINALIZE message
- 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_LOG, TEST_FINALIZE, msgType, buff, msgLen)) {
- return 2;
- }
- log_println(1, " <------------------------->");
- // log protocol validation logs
- teststatuses = TEST_ENDED;
- protolog_status(getpid(), testids, teststatuses,ctlSocket);
- setCurrentTest(TEST_NONE);
- }
- return 0;
+ // All data has been sent. Expect server to close this META test session
+ // ... by sending an empty TEST_FINALIZE message
+ 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_LOG, TEST_FINALIZE, msgType, buff, msgLen)) {
+ return 2;
+ }
+ log_println(1, " <------------------------->");
+ // log protocol validation logs
+ teststatuses = TEST_ENDED;
+ protolog_status(getpid(), testids, teststatuses,ctlSocket);
+ setCurrentTest(TEST_NONE);
+ }
+ return 0;
}
=======================================
--- /trunk/src/test_meta_srv.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/test_meta_srv.c Thu Nov 15 13:33:19 2012
@@ -39,125 +39,125 @@
*/
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;
+ 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;
+ // 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 -->");
+ if (testOptions->metaopt) {
+ setCurrentTest(TEST_META);
+ log_println(1, " <-- META test -->");
- // log protocol validation details
- teststatuses = TEST_STARTED;
- protolog_status(testOptions->child0, testids,
teststatuses,ctlsockfd);
+ // log protocol validation details
+ teststatuses = TEST_STARTED;
+ protolog_status(testOptions->child0, testids, teststatuses,ctlsockfd);
- // 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;
- }
+ // 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");
- }
+ // 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.
+ 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!");
- snprintf(buff, sizeof(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!");
- snprintf(buff, sizeof(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");
- snprintf(buff, sizeof(buff), "Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff,
strlen(buff));
- return 3;
- }
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ // message reading error
+ log_println(0, "Protocol error!");
+ snprintf(buff, sizeof(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!");
+ snprintf(buff, sizeof(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");
+ snprintf(buff, sizeof(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;
- }
+ // 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");
+ snprintf(buff, sizeof(buff), "Server (META test): Invalid meta data received");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ return 4;
+ }
+ *value = 0;
+ value++;
- buff[msgLen] = 0;
- value = index(buff, ':');
- if (value == NULL) { // key-value separates by ":"
- log_println(0, "Improper message");
- snprintf(buff, sizeof(buff), "Server (META test): Invalid meta data received");
- send_msg(ctlsockfd, MSG_ERROR, buff,
strlen(buff));
- 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;*/
+ }
- // 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_CLIENT_APPLICATION, buff) == 0) {
- snprintf(meta.client_application, sizeof(meta.client_application), "%s", value);
- /*continue;*/
- }
+ if (strcmp(META_CLIENT_APPLICATION, buff) == 0) {
+ snprintf(meta.client_application, sizeof(meta.client_application), "%s", value);
+ /*continue;*/
+ }
- if (strcmp(META_BROWSER_OS, buff) == 0) {
- snprintf(meta.client_browser,
sizeof(meta.client_browser), "%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);
- }
- new_entry->next = NULL; // ensure meta list ends here
+ // 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);
+ }
+ new_entry->next = NULL; // ensure meta list ends here
- // Finalize test by sending appropriate message, and setting
status
- if (send_msg(ctlsockfd, TEST_FINALIZE, "", 0) < 0) {
- log_println(6, "META test - failed to send finalize
message");
- }
+ // 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, " <-------------------------->");
+ //log end of test and conclude
+ log_println(1, " <-------------------------->");
- teststatuses = TEST_ENDED; // protocol log section
- protolog_status(testOptions->child0, testids,
teststatuses,ctlsockfd);
+ teststatuses = TEST_ENDED; // protocol log section
+ protolog_status(testOptions->child0, testids, teststatuses,ctlsockfd);
- setCurrentTest(TEST_NONE);
- }
- return 0;
+ setCurrentTest(TEST_NONE);
+ }
+ return 0;
}
=======================================
--- /trunk/src/test_mid_clt.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/test_mid_clt.c Thu Nov 15 13:33:19 2012
@@ -46,150 +46,150 @@
*
*/
int test_mid_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size, char* testresult_str) {
- char buff[BUFFSIZE + 1];
- int msgLen, msgType;
- int midport = atoi(PORT3);
- I2Addr sec_addr = NULL;
- int retcode, inlth;
- int in2Socket;
- double t, spdin;
- uint32_t bytes;
- struct timeval sel_tv;
- fd_set rfd;
+ int buf_size, char* testresult_str) {
+ char buff[BUFFSIZE + 1];
+ int msgLen, msgType;
+ int midport = atoi(PORT3);
+ I2Addr sec_addr = NULL;
+ int retcode, inlth;
+ int in2Socket;
+ double t, spdin;
+ uint32_t bytes;
+ struct timeval sel_tv;
+ fd_set rfd;
- enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
- enum TEST_ID testids = MIDDLEBOX;
+ enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
+ enum TEST_ID testids = MIDDLEBOX;
- if (tests & TEST_MID) { // middlebox test has to be performed
- log_println(1, " <-- Middlebox test -->");
- setCurrentTest(TEST_MID);
- //protocol logs
- teststatuses = TEST_STARTED;
- protolog_status(getpid(), testids, teststatuses, ctlSocket);
+ if (tests & TEST_MID) { // middlebox test has to be performed
+ log_println(1, " <-- Middlebox test -->");
+ setCurrentTest(TEST_MID);
+ //protocol logs
+ teststatuses = TEST_STARTED;
+ protolog_status(getpid(), testids, teststatuses, ctlSocket);
- // Initially, expecting a TEST_PREPARE message. Any other
message
- // ..type is unexpected at this stage.
+ // Initially, expecting a TEST_PREPARE message. Any other message
+ // ..type is unexpected at this stage.
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed prepare
message!");
- return 1;
- }
- if (check_msg_type(MIDBOX_TEST_LOG, TEST_PREPARE, msgType, buff, msgLen)) {
- return 2;
- }
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed prepare message!");
+ return 1;
+ }
+ if (check_msg_type(MIDBOX_TEST_LOG, TEST_PREPARE, msgType, buff, msgLen)) {
+ return 2;
+ }
- // The server is expected to send a message with a valid payload that contains
- // .. the port number that server wants client to bind to for
this test
- if (msgLen <= 0) {
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- if (check_int(buff, &midport)) { // obtained message does not contain integer port#
- log_println(0, "Invalid port number");
- return 4;
- }
+ // The server is expected to send a message with a valid payload that contains
+ // .. the port number that server wants client to bind to for this test
+ if (msgLen <= 0) {
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
+ if (check_int(buff, &midport)) { // obtained message does not contain integer port#
+ log_println(0, "Invalid port number");
+ return 4;
+ }
- // get server address and set port
- 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);
+ // get server address and set port
+ 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) { //debug to check if correct port was set in addr struct
- 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 (get_debuglvl() > 4) { //debug to check if correct port was set in addr struct
+ 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));
+ }
- // connect to server using port obtained above
- if ((retcode = CreateConnectSocket(&in2Socket, NULL, sec_addr, conn_options, buf_size))) {
- log_println(0, "Connect() for middlebox failed: %s",
strerror(errno));
- return -10;
- }
+ // connect to server using port obtained above
+ if ((retcode = CreateConnectSocket(&in2Socket, NULL, sec_addr, conn_options, buf_size))) {
+ log_println(0, "Connect() for middlebox failed: %s", strerror(errno));
+ return -10;
+ }
- // start reading throughput test data from server using the connection created above
- printf("Checking for Middleboxes . . . . . . . . . . . . . . . . .
. ");
- fflush(stdout);
- testresult_str[0] = '\0';
- bytes = 0;
- t = secs() + 5.0; // set timer for 5 seconds, and read for 5
seconds
- sel_tv.tv_sec = 6; // Time out the socket after 6.5 seconds
- sel_tv.tv_usec = 5; // 500?
- FD_ZERO(&rfd);
- FD_SET(in2Socket, &rfd);
- for (;;) {
- if (secs() > t)
- break;
- retcode = select(in2Socket+1, &rfd, NULL, NULL,
&sel_tv);
- if (retcode > 0) {
- inlth = read(in2Socket, buff, sizeof(buff));
- if (inlth == 0)
- break;
- bytes += inlth;
- continue;
- }
- if (retcode < 0) {
- printf("nothing to read, exiting read
loop\n");
- break;
- }
- if (retcode == 0) {
- printf("timer expired, exiting read loop\n");
- break;
- }
- }
- // get actual time for which test was run
- t = secs() - t + 5.0;
+ // start reading throughput test data from server using the connection created above
+ printf("Checking for Middleboxes . . . . . . . . . . . . . . . . . . ");
+ fflush(stdout);
+ testresult_str[0] = '\0';
+ bytes = 0;
+ t = secs() + 5.0; // set timer for 5 seconds, and read for 5 seconds
+ sel_tv.tv_sec = 6; // Time out the socket after 6.5 seconds
+ sel_tv.tv_usec = 5; // 500?
+ FD_ZERO(&rfd);
+ FD_SET(in2Socket, &rfd);
+ for (;;) {
+ if (secs() > t)
+ break;
+ retcode = select(in2Socket+1, &rfd, NULL, NULL, &sel_tv);
+ if (retcode > 0) {
+ inlth = read(in2Socket, buff, sizeof(buff));
+ if (inlth == 0)
+ break;
+ bytes += inlth;
+ continue;
+ }
+ if (retcode < 0) {
+ printf("nothing to read, exiting read loop\n");
+ break;
+ }
+ if (retcode == 0) {
+ printf("timer expired, exiting read loop\n");
+ break;
+ }
+ }
+ // get actual time for which test was run
+ t = secs() - t + 5.0;
- // calculate throughput in Kbps
- spdin = ((BITS_8_FLOAT * bytes) / KILO) / t;
+ // calculate throughput in Kbps
+ spdin = ((BITS_8_FLOAT * bytes) / KILO) / t;
- // Test is complete. Now, get results from server (includes CurrentMSS, WinScaleSent, WinScaleRcvd..).
- // The results are sent from server in the form of a TEST_MSG
object
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed text
message!");
- return 1;
- }
- if (check_msg_type(MIDBOX_TEST_LOG " results", TEST_MSG, msgType, buff, msgLen)) {
- return 2;
- }
+ // Test is complete. Now, get results from server (includes CurrentMSS, WinScaleSent, WinScaleRcvd..).
+ // The results are sent from server in the form of a TEST_MSG object
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed text message!");
+ return 1;
+ }
+ if (check_msg_type(MIDBOX_TEST_LOG " results", TEST_MSG, msgType, buff, msgLen)) {
+ return 2;
+ }
- strlcat(testresult_str, buff, MIDBOX_TEST_RES_SIZE);
+ strlcat(testresult_str, buff, MIDBOX_TEST_RES_SIZE);
- memset(buff, 0, sizeof(buff));
- // this should work since the throughput results from the
server should
- // ...fit well
within BUFFSIZE
- snprintf(buff, sizeof(buff), "%0.0f", spdin);
- log_println(4, "CWND limited speed = %0.2f kbps", spdin);
+ memset(buff, 0, sizeof(buff));
+ // this should work since the throughput results from the server should
+ // ...fit well within BUFFSIZE
+ snprintf(buff, sizeof(buff), "%0.0f", spdin);
+ log_println(4, "CWND limited speed = %0.2f kbps", spdin);
- // client now sends throughput it calculated above to server, as a TEST_MSG
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
- printf("Done\n");
+ // client now sends throughput it calculated above to server, as a TEST_MSG
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ printf("Done\n");
- I2AddrFree(sec_addr);
+ I2AddrFree(sec_addr);
- // Expect an empty TEST_FINALIZE message from server
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed finalize
message!");
- return 1;
- }
- if (check_msg_type(MIDBOX_TEST_LOG, TEST_FINALIZE, msgType, buff, msgLen)) {
- return 2;
- }
- log_println(1, " <-------------------->");
- // log protocol test ending
- teststatuses = TEST_ENDED;
- protolog_status(getpid(), testids, teststatuses,ctlSocket);
- setCurrentTest(TEST_NONE);
- }
- return 0;
+ // Expect an empty TEST_FINALIZE message from server
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed finalize message!");
+ return 1;
+ }
+ if (check_msg_type(MIDBOX_TEST_LOG, TEST_FINALIZE, msgType, buff, msgLen)) {
+ return 2;
+ }
+ log_println(1, " <-------------------->");
+ // log protocol test ending
+ teststatuses = TEST_ENDED;
+ protolog_status(getpid(), testids, teststatuses,ctlSocket);
+ setCurrentTest(TEST_NONE);
+ }
+ return 0;
}
=======================================
--- /trunk/src/test_mid_srv.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/test_mid_srv.c Thu Nov 15 13:33:19 2012
@@ -50,252 +50,252 @@
*/
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
+ 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;
+ // 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);
+ assert(ctlsockfd != -1);
+ assert(agent);
+ assert(options);
+ assert(s2c_throughput_mid);
- if (options->midopt) { // middlebox tests need to be run.
+ 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);
+ // Start with readying up (initializing)
+ setCurrentTest(TEST_MID);
+ log_println(1, " <-- %d - Middlebox test -->", options->child0);
- // protocol validation logs indicating start of tests
- thistestId = MIDDLEBOX;
- teststatusnow = TEST_STARTED;
- protolog_status(options->child0, thistestId, teststatusnow,
ctlsockfd);
+ // protocol validation logs indicating start of tests
+ thistestId = MIDDLEBOX;
+ teststatusnow = TEST_STARTED;
+ protolog_status(options->child0, thistestId, teststatusnow, ctlsockfd);
- // 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));
+ // 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) {
- snprintf(listenmidport, sizeof(listenmidport), "%d", options->midsockport);
- } else if (options->mainport) {
- snprintf(listenmidport, sizeof(listenmidport), "%d", options->mainport + 2);
- }
+ if (options->midsockport) {
+ snprintf(listenmidport, sizeof(listenmidport), "%d", options->midsockport);
+ } else if (options->mainport) {
+ snprintf(listenmidport, sizeof(listenmidport), "%d", options->mainport + 2);
+ }
- if (options->multiple) {
- //strcpy(listenmidport, "0");
- strlcpy(listenmidport, "0", sizeof(listenmidport));
- }
+ 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");
- */
+ /* 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) {
+ while (midsrv_addr == NULL) {
- // attempt to bind to a new port and obtain address structure with details of listening port
+ // 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, sizeof(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;
- }
- }
+ midsrv_addr =
+ CreateListenSocket(
+ NULL,
+ (options->multiple ?
+ mrange_next(listenmidport, sizeof(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));
- snprintf(buff, sizeof(buff),
- "Server (Middlebox test):
CreateListenSocket failed: %s",
- strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return -1;
- }
+ if (midsrv_addr == NULL) {
+ log_println(0,
+ "Server (Middlebox test): CreateListenSocket failed: %s",
+ strerror(errno));
+ snprintf(buff, sizeof(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);
+ // 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
- snprintf(buff, sizeof(buff), "%d", options->midsockport);
- if ((msgretvalue = send_msg(ctlsockfd, TEST_PREPARE, buff,
strlen(buff)))
- < 0)
- return msgretvalue;
+ // send this port number to client
+ snprintf(buff, sizeof(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));
+ /* 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);
+ /* 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;
+ // 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, midsfd);
- break;
- }
+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, midsfd);
+ break;
+ }
- if ((midsfd == -1) && (errno == EINTR)) // socket interrupted, wait some more
- goto midfd;
+ if ((midsfd == -1) && (errno == EINTR)) // socket interrupted, wait some more
+ goto midfd;
- snprintf(tmpstr,
- sizeof(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;
- }
+ snprintf(tmpstr,
+ sizeof(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;
+ // 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;
- }
+ 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, sizeof(buff));
+ // Perform S->C throughput test. Obtained results in "buff"
+ web100_middlebox(midsfd, agent, conn, buff, sizeof(buff));
- // Transmit results in the form of a TEST_MSG message
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(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
+ // 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!");
- snprintf(
- buff,
- sizeof(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
- snprintf(
- buff,
- sizeof(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");
- snprintf(
- buff,
- sizeof(buff),
- "Server (Middlebox test): Invalid CWND
limited throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return 3;
- }
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) { // message reception error
+ log_println(0, "Protocol error!");
+ snprintf(
+ buff,
+ sizeof(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
+ snprintf(
+ buff,
+ sizeof(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");
+ snprintf(
+ buff,
+ sizeof(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);
+ // 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);
+ // 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);
- // 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,ctlsockfd);
+ // 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,ctlsockfd);
- setCurrentTest(TEST_NONE);
- /* I2AddrFree(midsrv_addr); */
- }
- /* I2AddrFree(midsrv_addr); */
- return 0;
+ setCurrentTest(TEST_NONE);
+ /* I2AddrFree(midsrv_addr); */
+ }
+ /* I2AddrFree(midsrv_addr); */
+ return 0;
}
=======================================
--- /trunk/src/test_results_clt.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/test_results_clt.c Thu Nov 15 13:33:19 2012
@@ -24,53 +24,53 @@
* @return Current link's speed
*/
double get_linkspeed(int c2s_linkspeed_ind, int half_duplex_ind) {
- double mylinkspeed = 0;
- if (c2s_linkspeed_ind < DATA_RATE_ETHERNET) {
- if (c2s_linkspeed_ind < DATA_RATE_RTT) {
- printf("Server unable to determine bottleneck link
type.\n");
- } else {
- printf("Your host is connected to a ");
+ double mylinkspeed = 0;
+ if (c2s_linkspeed_ind < DATA_RATE_ETHERNET) {
+ if (c2s_linkspeed_ind < DATA_RATE_RTT) {
+ printf("Server unable to determine bottleneck link type.\n");
+ } else {
+ printf("Your host is connected to a ");
- if (c2s_linkspeed_ind == DATA_RATE_DIAL_UP) {
- printf("Dial-up Modem\n");
- mylinkspeed = .064;
- } else {
- printf("Cable/DSL modem\n");
- mylinkspeed = 2;
- }
- }
- } else {
- printf("The slowest link in the end-to-end path is a ");
+ if (c2s_linkspeed_ind == DATA_RATE_DIAL_UP) {
+ printf("Dial-up Modem\n");
+ mylinkspeed = .064;
+ } else {
+ printf("Cable/DSL modem\n");
+ mylinkspeed = 2;
+ }
+ }
+ } else {
+ printf("The slowest link in the end-to-end path is a ");
- if (c2s_linkspeed_ind == DATA_RATE_ETHERNET) {
- printf("10 Mbps Ethernet or WiFi 11b subnet\n");
- mylinkspeed = 10;
- } else if (c2s_linkspeed_ind == DATA_RATE_T3) {
- printf("45 Mbps T3/DS3 or WiFi 11 a/g subnet\n");
- mylinkspeed = 45;
- } else if (c2s_linkspeed_ind == DATA_RATE_FAST_ETHERNET) {
- printf("100 Mbps ");
- mylinkspeed = 100;
- if (half_duplex_ind == NO_HALF_DUPLEX) {
- printf("Full duplex Fast Ethernet subnet\n");
- } else {
- printf("Half duplex Fast Ethernet subnet\n");
- }
- } else if (c2s_linkspeed_ind == DATA_RATE_OC_12) {
- printf("a 622 Mbps OC-12 subnet\n");
- mylinkspeed = 622;
- } else if (c2s_linkspeed_ind == DATA_RATE_GIGABIT_ETHERNET) {
- printf("1.0 Gbps Gigabit Ethernet subnet\n");
- mylinkspeed = 1000;
- } else if (c2s_linkspeed_ind == DATA_RATE_OC_48) {
- printf("2.4 Gbps OC-48 subnet\n");
- mylinkspeed = 2400;
- } else if (c2s_linkspeed_ind == DATA_RATE_10G_ETHERNET) {
- printf("10 Gbps 10 Gigabit Ethernet/OC-192 subnet\n");
- mylinkspeed = 10000;
- }
- }
- return mylinkspeed;
+ if (c2s_linkspeed_ind == DATA_RATE_ETHERNET) {
+ printf("10 Mbps Ethernet or WiFi 11b subnet\n");
+ mylinkspeed = 10;
+ } else if (c2s_linkspeed_ind == DATA_RATE_T3) {
+ printf("45 Mbps T3/DS3 or WiFi 11 a/g subnet\n");
+ mylinkspeed = 45;
+ } else if (c2s_linkspeed_ind == DATA_RATE_FAST_ETHERNET) {
+ printf("100 Mbps ");
+ mylinkspeed = 100;
+ if (half_duplex_ind == NO_HALF_DUPLEX) {
+ printf("Full duplex Fast Ethernet subnet\n");
+ } else {
+ printf("Half duplex Fast Ethernet subnet\n");
+ }
+ } else if (c2s_linkspeed_ind == DATA_RATE_OC_12) {
+ printf("a 622 Mbps OC-12 subnet\n");
+ mylinkspeed = 622;
+ } else if (c2s_linkspeed_ind == DATA_RATE_GIGABIT_ETHERNET) {
+ printf("1.0 Gbps Gigabit Ethernet subnet\n");
+ mylinkspeed = 1000;
+ } else if (c2s_linkspeed_ind == DATA_RATE_OC_48) {
+ printf("2.4 Gbps OC-48 subnet\n");
+ mylinkspeed = 2400;
+ } else if (c2s_linkspeed_ind == DATA_RATE_10G_ETHERNET) {
+ printf("10 Gbps 10 Gigabit Ethernet/OC-192 subnet\n");
+ mylinkspeed = 10000;
+ }
+ }
+ return mylinkspeed;
}
/**
@@ -78,27 +78,27 @@
* @param mismatch Integer indicating results
*/
void print_results_mismatchcheck(int mismatch) {
- switch (mismatch) {
- case DUPLEX_OLD_ALGO_INDICATOR :
- printf("Warning: Old Duplex-Mismatch condition detected.\n");
- break;
+ switch (mismatch) {
+ case DUPLEX_OLD_ALGO_INDICATOR :
+ printf("Warning: Old Duplex-Mismatch condition detected.\n");
+ break;
- case DUPLEX_SWITCH_FULL_HOST_HALF :
- printf("Alarm: Duplex Mismatch condition detected. Switch=Full and Host=Half\n");
- break;
- case DUPLEX_SWITCH_FULL_HOST_HALF_POSS:
- printf("Alarm: Possible Duplex Mismatch condition detected. Switch=Full and Host=Half\n");
- break;
- case DUPLEX_SWITCH_HALF_HOST_FULL:
- printf("Alarm: Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
- break;
- case DUPLEX_SWITCH_HALF_HOST_FULL_POSS:
- printf("Alarm: Possible Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
- break;
- case DUPLEX_SWITCH_HALF_HOST_FULL_WARN:
- printf("Warning: Possible Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
- break;
- }
+ case DUPLEX_SWITCH_FULL_HOST_HALF :
+ printf("Alarm: Duplex Mismatch condition detected. Switch=Full and Host=Half\n");
+ break;
+ case DUPLEX_SWITCH_FULL_HOST_HALF_POSS:
+ printf("Alarm: Possible Duplex Mismatch condition detected. Switch=Full and Host=Half\n");
+ break;
+ case DUPLEX_SWITCH_HALF_HOST_FULL:
+ printf("Alarm: Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
+ break;
+ case DUPLEX_SWITCH_HALF_HOST_FULL_POSS:
+ printf("Alarm: Possible Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
+ break;
+ case DUPLEX_SWITCH_HALF_HOST_FULL_WARN:
+ printf("Warning: Possible Duplex Mismatch condition detected. Switch=Half and Host=Full\n");
+ break;
+ }
}
@@ -113,19 +113,19 @@
* @param max_RwinRcvd
*/
void print_recommend_buffersize(double rwin, double rttsec, double avgrtt,
- double mylink, int max_RwinRcvd){
- int j = 0;
- 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, max_RwinRcvd);
- if (((rwin*2)/rttsec) < mylink) {
- j = (float)((mylink * avgrtt)*1000) / 8;
- if ((int)j > max_RwinRcvd) {
- printf("Information: The receive buffer should be %0.0f
", j/1024.0f);
- printf("kbytes to maximize throughput\n");
- }
- }
+ double mylink, int max_RwinRcvd){
+ int j = 0;
+ 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, max_RwinRcvd);
+ if (((rwin*2)/rttsec) < mylink) {
+ j = (float)((mylink * avgrtt)*1000) / 8;
+ if ((int)j > max_RwinRcvd) {
+ printf("Information: The receive buffer should be %0.0f ", j/1024.0f);
+ printf("kbytes to maximize throughput\n");
+ }
+ }
}
/**
@@ -133,9 +133,9 @@
* @param is_badcable
* */
void check_badcable(int is_bad_cable) {
- if (is_bad_cable == POSSIBLE_BAD_CABLE) {
- printf("Alarm: Excessive errors, check network cable(s).\n");
- }
+ if (is_bad_cable == POSSIBLE_BAD_CABLE) {
+ printf("Alarm: Excessive errors, check network cable(s).\n");
+ }
}
/**
@@ -143,9 +143,9 @@
* @param is_congested
* */
void check_congestion(int is_congested) {
- if (is_congested == POSSIBLE_CONGESTION) {
- printf("Information: Other network traffic is congesting the link\n");
- }
+ if (is_congested == POSSIBLE_CONGESTION) {
+ printf("Information: Other network traffic is congesting the link\n");
+ }
}
/**
@@ -155,15 +155,15 @@
* @param sndqueue length of send queue of the C->S throughput test
*/
void check_C2Spacketqueuing(double c2sthruput, double spdout, int sndqueue, int pktcount, int buflength) {
- if (c2sthruput < (spdout * (1.0 - VIEW_DIFF))) {
- printf("Information [C2S]: Packet queuing detected: %0.2f%% ",
- 100 * (spdout - c2sthruput) / spdout);
- if (sndqueue > (0.8 * pktcount * buflength * (spdout - c2sthruput) / spdout)) {
- printf("(local buffers)\n");
- } else {
- printf("(remote buffers)\n");
- }
- }
+ if (c2sthruput < (spdout * (1.0 - VIEW_DIFF))) {
+ printf("Information [C2S]: Packet queuing detected: %0.2f%% ",
+ 100 * (spdout - c2sthruput) / spdout);
+ if (sndqueue > (0.8 * pktcount * buflength * (spdout - c2sthruput) / spdout)) {
+ printf("(local buffers)\n");
+ } else {
+ printf("(remote buffers)\n");
+ }
+ }
}
@@ -176,15 +176,15 @@
* @param sbytecount total-sent-byte-count in the S->C throughput test
*/
void check_S2Cpacketqueuing(double s2cthroughput, double spdin, int srvsndqueue, int sbytecount) {
- if (spdin < (s2cthroughput * (1.0 - VIEW_DIFF))) {
- printf("Information [S2C]: Packet queuing detected: %0.2f%% ",
- 100 * (s2cthroughput - spdin) /
s2cthroughput);
- if (srvsndqueue > (0.8 * sbytecount * (s2cthroughput - spdin) / s2cthroughput)) {
- printf("(local buffers)\n");
- } else {
- printf("(remote buffers)\n");
- }
- }
+ if (spdin < (s2cthroughput * (1.0 - VIEW_DIFF))) {
+ printf("Information [S2C]: Packet queuing detected: %0.2f%% ",
+ 100 * (s2cthroughput - spdin) / s2cthroughput);
+ if (srvsndqueue > (0.8 * sbytecount * (s2cthroughput - spdin) / s2cthroughput)) {
+ printf("(local buffers)\n");
+ } else {
+ printf("(remote buffers)\n");
+ }
+ }
}
/**
@@ -208,31 +208,31 @@
* @param totaltesttime Total test time
*/
void print_packetloss_statistics(int PktsRetrans, int DupAcksIn, int SACKsRcvd,
- double ooorder, int Timeouts, double waitsec , double
totaltesttime) {
+ double ooorder, int Timeouts, double waitsec , double totaltesttime) {
- 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 (ooorder > 0)
- printf("Packets arrived out-of-order %0.2f%% of the
time.\n",
- ooorder * 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 /
totaltesttime));
- } else if (DupAcksIn > 0) {
- printf("No packet loss - ");
- if (ooorder > 0)
- printf("but packets arrived out-of-order %0.2f%% of the
time.\n",
- ooorder * 100);
- else
- printf("\n");
- } else {
- printf("No packet loss was observed.\n");
- }
+ 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 (ooorder > 0)
+ printf("Packets arrived out-of-order %0.2f%% of the time.\n",
+ ooorder * 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 / totaltesttime));
+ } else if (DupAcksIn > 0) {
+ printf("No packet loss - ");
+ if (ooorder > 0)
+ printf("but packets arrived out-of-order %0.2f%% of the time.\n",
+ ooorder * 100);
+ else
+ printf("\n");
+ } else {
+ printf("No packet loss was observed.\n");
+ }
}
@@ -252,26 +252,26 @@
*/
void print_limitedtime_ratio(double rwintime, double rwin, double sendtime, double swin, double cwndtime,
- double rttsec, double mylinkspeed, int sndbuf, int
max_rwinrcvd) {
+ double rttsec, double mylinkspeed, int sndbuf, int max_rwinrcvd) {
- if (rwintime > .015) {
- printf("This connection is receiver limited %0.2f%% of the
time.\n",
- rwintime * 100);
- if ((2 * (rwin / rttsec)) < mylinkspeed)
- printf(" Increasing the current receive buffer (%0.2f KB) will improve performance\n",
- (float) max_rwinrcvd / KILO_BITS);
- }
- if (sendtime > .015) {
- printf("This connection is sender limited %0.2f%% of the
time.\n",
- sendtime * 100);
- if ((2 * (swin / rttsec)) < mylinkspeed)
- printf(" Increasing the current send buffer (%0.2f KB) will improve performance\n",
- (float) sndbuf / KILO_BITS);
- }
- if (cwndtime > .005) {
- printf("This connection is network limited %0.2f%% of the
time.\n",
- cwndtime * 100);
- }
+ if (rwintime > .015) {
+ printf("This connection is receiver limited %0.2f%% of the time.\n",
+ rwintime * 100);
+ if ((2 * (rwin / rttsec)) < mylinkspeed)
+ printf(" Increasing the current receive buffer (%0.2f KB) will improve performance\n",
+ (float) max_rwinrcvd / KILO_BITS);
+ }
+ if (sendtime > .015) {
+ printf("This connection is sender limited %0.2f%% of the time.\n",
+ sendtime * 100);
+ if ((2 * (swin / rttsec)) < mylinkspeed)
+ printf(" Increasing the current send buffer (%0.2f KB) will improve performance\n",
+ (float) sndbuf / KILO_BITS);
+ }
+ if (cwndtime > .005) {
+ printf("This connection is network limited %0.2f%% of the time.\n",
+ cwndtime * 100);
+ }
}
@@ -281,10 +281,10 @@
* @param loss packet loss
*/
void print_packetloss_excess(double spd, double loss) {
- 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");
- }
+ 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");
+ }
}
/**
@@ -293,11 +293,11 @@
* @param SACKEnabled
*/
void print_SAck_RFC2018(int SACKEnabled) {
- printf("RFC 2018 Selective Acknowledgment: ");
- if (SACKEnabled == 0)
- printf("OFF\n");
- else
- printf("ON\n");
+ printf("RFC 2018 Selective Acknowledgment: ");
+ if (SACKEnabled == 0)
+ printf("OFF\n");
+ else
+ printf("ON\n");
}
/**
@@ -307,11 +307,11 @@
void print_Nagle_RFC896(int is_nagleenabled)
{
- printf("RFC 896 Nagle Algorithm: ");
- if (is_nagleenabled == 0)
- printf("OFF\n");
- else
- printf("ON\n");
+ printf("RFC 896 Nagle Algorithm: ");
+ if (is_nagleenabled == 0)
+ printf("OFF\n");
+ else
+ printf("ON\n");
}
/**
@@ -320,11 +320,11 @@
*/
void print_congestion_RFC3168(int is_ECNenabled)
{
- printf("RFC 3168 Explicit Congestion Notification: ");
- if (is_ECNenabled == 0)
- printf("OFF\n");
- else
- printf("ON\n");
+ printf("RFC 3168 Explicit Congestion Notification: ");
+ if (is_ECNenabled == 0)
+ printf("OFF\n");
+ else
+ printf("ON\n");
}
@@ -335,11 +335,11 @@
*/
void print_timestamping_RFC1323(int is_timestampenabled)
{
- printf("RFC 1323 Time Stamping: ");
- if (is_timestampenabled == 0)
- printf("OFF\n");
- else
- printf("ON\n");
+ printf("RFC 1323 Time Stamping: ");
+ if (is_timestampenabled == 0)
+ printf("OFF\n");
+ else
+ printf("ON\n");
}
/**
@@ -349,15 +349,15 @@
* @param winscale_sent value of the transmitted window scale option
*/
void print_windowscaling(int max_rwinrcvd, int winscale_rcvd, int winscale_sent) {
- printf("RFC 1323 Window Scaling: ");
- if (max_rwinrcvd < 65535)
- winscale_rcvd = 0;
+ printf("RFC 1323 Window Scaling: ");
+ if (max_rwinrcvd < 65535)
+ winscale_rcvd = 0;
- if ((winscale_rcvd == 0) || (winscale_rcvd > 20))
- printf("OFF\n");
- else
- printf("ON; Scaling Factors - Server=%d, Client=%d\n",
- winscale_rcvd, winscale_sent);
+ if ((winscale_rcvd == 0) || (winscale_rcvd > 20))
+ printf("OFF\n");
+ else
+ printf("ON; Scaling Factors - Server=%d, Client=%d\n",
+ winscale_rcvd, winscale_sent);
}
/**
@@ -373,21 +373,21 @@
* @param estimate Estimated theoretical throughput
*/
void print_throughputlimits(int max_rwinrcvd, int rcvwinscale, int *sndbuf,
- double s_win, double r_win, double c_win, double rttsec, double estimate) {
- int tempsendbuf = *sndbuf;
- if ((rcvwinscale == 0) && (tempsendbuf > 65535))
- tempsendbuf = 65535;
+ double s_win, double r_win, double c_win, double rttsec, double estimate) {
+ int tempsendbuf = *sndbuf;
+ if ((rcvwinscale == 0) && (tempsendbuf > 65535))
+ tempsendbuf = 65535;
- printf("The theoretical network limit is %0.2f Mbps\n", estimate);
+ 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) tempsendbuf / KILO_BITS, (float) s_win /
rttsec);
+ printf("The NDT server has a %0.0f KByte buffer which limits the throughput to %0.2f Mbps\n",
+ (float) tempsendbuf / KILO_BITS, (float) s_win / rttsec);
- printf("Your PC/Workstation has a %0.0f KByte buffer which limits the throughput to %0.2f Mbps\n",
- (float) max_rwinrcvd / KILO_BITS, (float) r_win /
rttsec);
+ printf("Your PC/Workstation has a %0.0f KByte buffer which limits the throughput to %0.2f Mbps\n",
+ (float) max_rwinrcvd / KILO_BITS, (float) r_win / rttsec);
- printf("The network based flow control limits the throughput to %0.2f Mbps\n",
- (float) c_win / rttsec);
+ printf("The network based flow control limits the throughput to %0.2f Mbps\n",
+ (float) c_win / rttsec);
}
@@ -402,13 +402,13 @@
* @param s2c_linkspeed_ack Data link speed as detected by client acknowledgments
*/
void print_linkspeed_dataacks(int isC2S_enabled, int c2s_linkspeed_data,
- int c2s_linkspeed_ack, int s2c_linkspeed_data, int
s2c_linkspeed_ack) {
- if (isC2S_enabled) {
- printf("\nClient Data reports link is '%3d', Client Acks report link is '%3d'\n",
- c2s_linkspeed_data, c2s_linkspeed_ack);
- }
- printf("Server Data reports link is '%3d', Server Acks report link is '%3d'\n",
- s2c_linkspeed_data, s2c_linkspeed_ack);
+ int c2s_linkspeed_ack, int s2c_linkspeed_data, int s2c_linkspeed_ack) {
+ if (isC2S_enabled) {
+ printf("\nClient Data reports link is '%3d', Client Acks report link is '%3d'\n",
+ c2s_linkspeed_data, c2s_linkspeed_ack);
+ }
+ printf("Server Data reports link is '%3d', Server Acks report link is '%3d'\n",
+ s2c_linkspeed_data, s2c_linkspeed_ack);
}
@@ -422,25 +422,25 @@
*/
void check_NAT(char *ssip, char *csip, char *scip, char *ccip) {
- // If server and client both see similar server IP addresses,
- // no NAT happening
- 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 server and client both see similar server IP addresses,
+ // no NAT happening
+ 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 server and client both see similar client IP addresses,
- // no NAT happening
- 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);
- }
+ // If server and client both see similar client IP addresses,
+ // no NAT happening
+ 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);
+ }
}
@@ -455,12 +455,12 @@
* @param mssvalue
*/
void check_MSS_modification(int is_timestampenabled, int *mssvalue) {
- if (is_timestampenabled == 1)
- *mssvalue += 12;
- if (*mssvalue == 1456)
- printf("Packet size is preserved End-to-End\n");
- else
- printf("Information: Network Middlebox is modifying MSS variable (changed to %d)\n",
- *mssvalue);
+ if (is_timestampenabled == 1)
+ *mssvalue += 12;
+ if (*mssvalue == 1456)
+ printf("Packet size is preserved End-to-End\n");
+ else
+ printf("Information: Network Middlebox is modifying MSS variable (changed to %d)\n",
+ *mssvalue);
}
=======================================
--- /trunk/src/test_s2c_clt.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/test_s2c_clt.c Thu Nov 15 13:33:19 2012
@@ -40,216 +40,216 @@
*/
int test_s2c_clt(int ctlSocket, char tests, char* host, int conn_options,
- int buf_size, char* result_srv) {
- char buff[BUFFSIZE + 1];
- int msgLen, msgType;
- int s2cport = atoi(PORT3);
- I2Addr sec_addr = NULL;
- int inlth, retcode, one=1, set_size;
- int inSocket;
- socklen_t optlen;
- uint32_t bytes;
- double t;
- struct timeval sel_tv;
- fd_set rfd;
- char* ptr;
+ int buf_size, char* result_srv) {
+ char buff[BUFFSIZE + 1];
+ int msgLen, msgType;
+ int s2cport = atoi(PORT3);
+ I2Addr sec_addr = NULL;
+ int inlth, retcode, one=1, set_size;
+ int inSocket;
+ socklen_t optlen;
+ uint32_t bytes;
+ double t;
+ struct timeval sel_tv;
+ fd_set rfd;
+ char* ptr;
- // variables used for protocol validation logs
- enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
- enum TEST_ID testids = S2C;
+ // variables used for protocol validation logs
+ enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
+ enum TEST_ID testids = S2C;
- if (tests & TEST_S2C) {
- setCurrentTest(TEST_S2C);
- //protocol logs
- teststatuses = TEST_STARTED;
- protolog_status(getpid(), testids, teststatuses, ctlSocket);
+ if (tests & TEST_S2C) {
+ setCurrentTest(TEST_S2C);
+ //protocol logs
+ teststatuses = TEST_STARTED;
+ protolog_status(getpid(), testids, teststatuses, ctlSocket);
- // First message expected from the server is a TEST_PREPARE. Any other message
- // ...type is unexpected at this point.
- log_println(1, " <-- S2C throughput test -->");
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed prepare
message!");
- return 1;
- }
- if (check_msg_type(S2C_TEST_LOG, TEST_PREPARE, msgType, buff,
msgLen)) {
- return 2;
- }
- // This TEST_PREPARE message is expected to have the port number as message body.
- // Check if this is a valid integral port.
- if (msgLen <= 0) {
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- if (check_int(buff, &s2cport)) {
- log_println(0, "Invalid port number");
- return 4;
- }
- log_println(1, " -- port: %d", s2cport);
+ // First message expected from the server is a TEST_PREPARE. Any other message
+ // ...type is unexpected at this point.
+ log_println(1, " <-- S2C throughput test -->");
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed prepare message!");
+ return 1;
+ }
+ if (check_msg_type(S2C_TEST_LOG, TEST_PREPARE, msgType, buff, msgLen)) {
+ return 2;
+ }
+ // This TEST_PREPARE message is expected to have the port number as message body.
+ // Check if this is a valid integral port.
+ if (msgLen <= 0) {
+ log_println(0, "Improper message");
+ return 3;
+ }
+ 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);
+ /* 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);
- // get "address details" of the server using the host name
- if ((sec_addr = I2AddrByNode(get_errhandle(), host)) == NULL)
{
- log_println(0, "Unable to resolve server address:
%s", strerror(errno));
- return -3;
- }
- I2AddrSetPort(sec_addr, s2cport); //set port to value obtained from server
+ // get "address details" of the server using the host name
+ if ((sec_addr = I2AddrByNode(get_errhandle(), host)) == NULL) {
+ log_println(0, "Unable to resolve server address: %s", strerror(errno));
+ return -3;
+ }
+ I2AddrSetPort(sec_addr, s2cport); //set port to value obtained from server
- // Connect to the server; set socket options
- if ((retcode = CreateConnectSocket(&inSocket, NULL, sec_addr, conn_options, buf_size))) {
- log_println(0, "Connect() for Server to Client failed", strerror(errno));
- return -15;
- }
+ // Connect to the server; set socket options
+ if ((retcode = CreateConnectSocket(&inSocket, NULL, sec_addr, conn_options, buf_size))) {
+ log_println(0, "Connect() for Server to Client failed", strerror(errno));
+ return -15;
+ }
- setsockopt(inSocket, SOL_SOCKET, SO_REUSEADDR, &one,
sizeof(one));
+ 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.
- */
+ /* 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.
+ */
- // Expect a TEST_START message from server now. Any other
message
- // type is an error
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed start
message!");
- return 1;
- }
- if (check_msg_type(S2C_TEST_LOG, TEST_START, msgType, buff,
msgLen)) {
- return 2;
- }
+ // Expect a TEST_START message from server now. Any other message
+ // type is an error
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed start message!");
+ return 1;
+ }
+ if (check_msg_type(S2C_TEST_LOG, TEST_START, msgType, buff, msgLen)) {
+ return 2;
+ }
- // server performs the S->C throughput test now. Get data
sent by server.
+ // server performs the S->C throughput test now. Get data sent by server.
- printf("running 10s inbound test (server to client) . . . . . .
");
- fflush(stdout);
+ printf("running 10s inbound test (server to client) . . . . . . ");
+ fflush(stdout);
- // Set socket timeout to 15 seconds
- bytes = 0;
- t = secs() + 15.0;
- sel_tv.tv_sec = 15;
- sel_tv.tv_usec = 5;
- FD_ZERO(&rfd);
- FD_SET(inSocket, &rfd);
- // Read data sent by server as soon as it is available. Stop
listening if
- // ...timeout has been exceeded.
- for (;;) {
- retcode = select(inSocket+1, &rfd, NULL, NULL,
&sel_tv);
- if (secs() > t) {
- log_println(5, "Receive test running long, break
out of read loop");
- break;
- }
- if (retcode > 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;
- }
+ // Set socket timeout to 15 seconds
+ bytes = 0;
+ t = secs() + 15.0;
+ sel_tv.tv_sec = 15;
+ sel_tv.tv_usec = 5;
+ FD_ZERO(&rfd);
+ FD_SET(inSocket, &rfd);
+ // Read data sent by server as soon as it is available. Stop listening if
+ // ...timeout has been exceeded.
+ for (;;) {
+ retcode = select(inSocket+1, &rfd, NULL, NULL, &sel_tv);
+ if (secs() > t) {
+ log_println(5, "Receive test running long, break out of read loop");
+ break;
+ }
+ if (retcode > 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;
+ }
- // get actual time for which data was received, and calculate throughput based on it.
- t = secs() - t + 15.0;
- spdin = ((BITS_8_FLOAT * bytes) / KILO) / t; //kbps
+ // get actual time for which data was received, and calculate throughput based on it.
+ t = secs() - t + 15.0;
+ spdin = ((BITS_8_FLOAT * bytes) / KILO) / t; //kbps
- //log_println(0,"S->C: Received %d bytes in %0.2f secs: Spdin= %f", bytes, t, spdin);
+ //log_println(0,"S->C: Received %d bytes in %0.2f secs: Spdin= %f", bytes, t, spdin);
- // Server sends calculated throughput value, unsent data amount in the socket queue
- // and overall number of sent bytes in a TEST_MSG
- msgLen = sizeof(buff);
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed text
message!");
- return 1;
- }
- if (check_msg_type(S2C_TEST_LOG, TEST_MSG, msgType, buff,
msgLen)) {
- return 2; // no other message type expected
- }
- // Is message of valid length, and does it have all the data
expected?
- if (msgLen <= 0) {
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- ptr = strtok(buff, " ");
- if (ptr == NULL) {
- log_println(0, "S2C: Improper message");
- return 4;
- }
- s2cspd = atoi(ptr); // get S->C throughput first
- ptr = strtok(NULL, " ");
- if (ptr == NULL) {
- log_println(0, "S2C: Improper message");
- return 4;
- }
- ssndqueue = atoi(ptr); // get amount of unsent data in queue
- ptr = strtok(NULL, " ");
- if (ptr == NULL) {
- log_println(0, "S2C: Improper message");
- return 4;
- }
- sbytes = atoi(ptr); // finally get total-sent-byte-count
- //log_println(0,"S->C received throughput: %f",s2cspd);
- // log results in a convenient units format
- if (spdin < 1000)
- printf("%0.2f kb/s\n", spdin);
- else
- printf("%0.2f Mb/s\n", spdin/1000);
+ // Server sends calculated throughput value, unsent data amount in the socket queue
+ // and overall number of sent bytes in a TEST_MSG
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed text message!");
+ return 1;
+ }
+ if (check_msg_type(S2C_TEST_LOG, TEST_MSG, msgType, buff, msgLen)) {
+ return 2; // no other message type expected
+ }
+ // Is message of valid length, and does it have all the data expected?
+ if (msgLen <= 0) {
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
+ ptr = strtok(buff, " ");
+ if (ptr == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ s2cspd = atoi(ptr); // get S->C throughput first
+ ptr = strtok(NULL, " ");
+ if (ptr == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ ssndqueue = atoi(ptr); // get amount of unsent data in queue
+ ptr = strtok(NULL, " ");
+ if (ptr == NULL) {
+ log_println(0, "S2C: Improper message");
+ return 4;
+ }
+ sbytes = atoi(ptr); // finally get total-sent-byte-count
+ //log_println(0,"S->C received throughput: %f",s2cspd);
+ // log results in a convenient units format
+ if (spdin < 1000)
+ printf("%0.2f kb/s\n", spdin);
+ else
+ printf("%0.2f Mb/s\n", spdin/1000);
- I2AddrFree(sec_addr);
+ I2AddrFree(sec_addr);
- // send TEST_MSG to server with the client-calculated
throughput
- snprintf(buff, sizeof(buff), "%0.0f", spdin);
- send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
+ // send TEST_MSG to server with the client-calculated throughput
+ snprintf(buff, sizeof(buff), "%0.0f", spdin);
+ send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
- // client now expected to receive web100 variables collected
by server
+ // client now expected to receive web100 variables collected by server
- result_srv[0] = '\0';
- for (;;) {
- msgLen = sizeof(buff);
- memset(buff,0,msgLen); // reset buff and msgLen
+ result_srv[0] = '\0';
+ for (;;) {
+ msgLen = sizeof(buff);
+ memset(buff,0,msgLen); // reset buff and msgLen
- // get web100 variables
- if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed
text/finalize message!");
- return 1;
- }
+ // get web100 variables
+ if (recv_msg(ctlSocket, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed text/finalize message!");
+ return 1;
+ }
- // TEST_FINALIZE msg from server indicates end of web100 var transmission
- if (msgType == TEST_FINALIZE) {
- break;
- }
+ // TEST_FINALIZE msg from server indicates end of web100 var transmission
+ if (msgType == TEST_FINALIZE) {
+ break;
+ }
- // if neither TEST_FINALIZE, nor TEST_MSG, signal
error!
- if (check_msg_type(S2C_TEST_LOG, TEST_MSG, msgType,
buff, msgLen)) {
- return 2;
- }
+ // if neither TEST_FINALIZE, nor TEST_MSG, signal error!
+ if (check_msg_type(S2C_TEST_LOG, TEST_MSG, msgType, buff, msgLen)) {
+ return 2;
+ }
- strlcat(result_srv, buff, 2 * BUFFSIZE); // hardcoded size of array from main tests
- }
- log_println(6, "result_srv = '%s', of len %d", result_srv,
msgLen);
- log_println(1, " <------------------------->");
+ strlcat(result_srv, buff, 2 * BUFFSIZE); // hardcoded size of array from main tests
+ }
+ log_println(6, "result_srv = '%s', of len %d", result_srv, msgLen);
+ log_println(1, " <------------------------->");
- //log protocol validation logs
- teststatuses = TEST_ENDED;
- protolog_status(getpid(), testids, teststatuses,ctlSocket);
- setCurrentTest(TEST_NONE);
- }
+ //log protocol validation logs
+ teststatuses = TEST_ENDED;
+ protolog_status(getpid(), testids, teststatuses,ctlSocket);
+ setCurrentTest(TEST_NONE);
+ }
- return 0;
+ return 0;
}
=======================================
--- /trunk/src/test_s2c_srv.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/test_s2c_srv.c Thu Nov 15 13:33:19 2012
@@ -70,526 +70,526 @@
* -errno - Other specific socket error numbers
*/
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 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 ret; // ctrl protocol read/write return status
- int j, k, n;
- int xmitsfd; // transmit (i.e server) socket fd
- pid_t s2c_childpid = 0; // s2c_childpid
+ int ret; // ctrl protocol read/write return status
+ int j, k, n;
+ int xmitsfd; // transmit (i.e server) socket fd
+ pid_t s2c_childpid = 0; // s2c_childpid
- char tmpstr[256]; // string array used for temp storage of many char*
- struct sockaddr_storage cli_addr;
+ char tmpstr[256]; // string array used for temp storage of many char*
+ struct sockaddr_storage cli_addr;
- socklen_t clilen;
- double bytes_written; // bytes written in the throughput test
- double tx_duration; // total time for which data was txed
- double tmptime; // temporary time store
- double x2cspd; // s->c test throughput
- struct timeval sel_tv; // time
- fd_set rfd; // receive file descriptor
- char buff[BUFFSIZE + 1]; // message payload buffer
- int bufctrlattempts = 0; // number of buffer control attempts
- int i; // temporary var used for iterators etc
- PortPair pair; // socket ports
- I2Addr s2csrv_addr = NULL;
- I2Addr src_addr = NULL;
- char listens2cport[10];
- int msgType;
- int msgLen;
- int sndqueue;
- struct sigaction new, old;
+ socklen_t clilen;
+ double bytes_written; // bytes written in the throughput test
+ double tx_duration; // total time for which data was txed
+ double tmptime; // temporary time store
+ double x2cspd; // s->c test throughput
+ struct timeval sel_tv; // time
+ fd_set rfd; // receive file descriptor
+ char buff[BUFFSIZE + 1]; // message payload buffer
+ int bufctrlattempts = 0; // number of buffer control attempts
+ int i; // temporary var used for iterators etc
+ PortPair pair; // socket ports
+ I2Addr s2csrv_addr = NULL;
+ I2Addr src_addr = NULL;
+ char listens2cport[10];
+ int msgType;
+ int msgLen;
+ int sndqueue;
+ struct sigaction new, old;
- /* experimental code to capture and log multiple copies of the
- * web100 variables using the web100_snap() & log() functions.
- */
- web100_snapshot* tsnap = NULL;
- web100_snapshot* rsnap = NULL;
- web100_group* group;
- web100_group* tgroup;
- web100_group* rgroup;
- web100_connection* conn;
- web100_var* var;
- pthread_t workerThreadId;
- int nextseqtosend = 0, lastunackedseq = 0;
- int drainingqueuecount = 0, bufctlrnewdata = 0; // sent data attempt queue, Draining Queue.
+ /* experimental code to capture and log multiple copies of the
+ * web100 variables using the web100_snap() & log() functions.
+ */
+ web100_snapshot* tsnap = NULL;
+ web100_snapshot* rsnap = NULL;
+ web100_group* group;
+ web100_group* tgroup;
+ web100_group* rgroup;
+ web100_connection* conn;
+ web100_var* var;
+ pthread_t workerThreadId;
+ int nextseqtosend = 0, lastunackedseq = 0;
+ int drainingqueuecount = 0, bufctlrnewdata = 0; // sent data attempt queue, Draining Queue.
- // variables used for protocol validation logs
- enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
- enum TEST_ID testids = S2C;
- enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
- enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;
- char snaplogsuffix[256] = "s2c_snaplog";
+ // variables used for protocol validation logs
+ enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
+ enum TEST_ID testids = S2C;
+ enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
+ enum PROCESS_TYPE_INT proctypeenum = CONNECT_TYPE;
+ char snaplogsuffix[256] = "s2c_snaplog";
- SnapArgs snapArgs;
- snapArgs.snap = NULL;
- snapArgs.log = NULL;
- snapArgs.delay = options->snapDelay;
- wait_sig = 0;
+ SnapArgs snapArgs;
+ snapArgs.snap = NULL;
+ snapArgs.log = NULL;
+ snapArgs.delay = options->snapDelay;
+ wait_sig = 0;
- // Determine port to be used. Compute based on options set earlier
- // by reading from config file, or use default port2 (3003)
- if (testOptions->s2copt) {
- setCurrentTest(TEST_S2C);
- log_println(1, " <-- %d - S2C throughput test -->",
- testOptions->child0);
+ // Determine port to be used. Compute based on options set earlier
+ // by reading from config file, or use default port2 (3003)
+ if (testOptions->s2copt) {
+ setCurrentTest(TEST_S2C);
+ log_println(1, " <-- %d - S2C throughput test -->",
+ testOptions->child0);
- //protocol logs
- teststatuses = TEST_STARTED;
- protolog_status(testOptions->child0, testids, teststatuses,
ctlsockfd);
+ //protocol logs
+ teststatuses = TEST_STARTED;
+ protolog_status(testOptions->child0, testids, teststatuses, ctlsockfd);
- strlcpy(listens2cport, PORT4, sizeof(listens2cport));
+ strlcpy(listens2cport, PORT4, sizeof(listens2cport));
- if (testOptions->s2csockport) {
- snprintf(listens2cport, sizeof(listens2cport), "%d", testOptions->s2csockport);
- } else if (testOptions->mainport) {
- snprintf(listens2cport, sizeof(listens2cport), "%d", testOptions->mainport + 2);
- }
+ if (testOptions->s2csockport) {
+ snprintf(listens2cport, sizeof(listens2cport), "%d", testOptions->s2csockport);
+ } else if (testOptions->mainport) {
+ snprintf(listens2cport, sizeof(listens2cport), "%d", testOptions->mainport + 2);
+ }
- if (testOptions->multiple) {
- strlcpy(listens2cport, "0", sizeof(listens2cport));
- }
+ if (testOptions->multiple) {
+ strlcpy(listens2cport, "0", sizeof(listens2cport));
+ }
- // attempt to bind to a new port and obtain address structure with details of listening port
- while (s2csrv_addr == NULL) {
- s2csrv_addr = CreateListenSocket(NULL,
-
(testOptions->multiple ?
-
mrange_next(listens2cport, sizeof(listens2cport)) :
-
listens2cport),
- conn_options, 0);
- if (s2csrv_addr == NULL) {
- /*
- log_println(1, " Calling KillHung() because s2csrv_address failed to bind");
- if (KillHung() == 0)
- continue;
- */
- }
- if (strcmp(listens2cport, "0") == 0) {
- log_println(0, "WARNING: ephemeral port number was
bound");
- break;
- }
- if (testOptions->multiple == 0) {
- break;
- }
- }
- if (s2csrv_addr == NULL) {
- log_println(
- 0,
- "Server (S2C throughput test):
CreateListenSocket failed: %s",
- strerror(errno));
- snprintf(
- buff,
- sizeof(buff),
- "Server (S2C throughput test):
CreateListenSocket failed: %s",
- strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return -1;
- }
+ // attempt to bind to a new port and obtain address structure with details of listening port
+ while (s2csrv_addr == NULL) {
+ s2csrv_addr = CreateListenSocket(NULL,
+ (testOptions->multiple ?
+ mrange_next(listens2cport, sizeof(listens2cport)) :
+ listens2cport),
+ conn_options, 0);
+ if (s2csrv_addr == NULL) {
+ /*
+ log_println(1, " Calling KillHung() because s2csrv_address failed to bind");
+ if (KillHung() == 0)
+ continue;
+ */
+ }
+ if (strcmp(listens2cport, "0") == 0) {
+ log_println(0, "WARNING: ephemeral port number was bound");
+ break;
+ }
+ if (testOptions->multiple == 0) {
+ break;
+ }
+ }
+ if (s2csrv_addr == NULL) {
+ log_println(
+ 0,
+ "Server (S2C throughput test): CreateListenSocket failed: %s",
+ strerror(errno));
+ snprintf(
+ buff,
+ sizeof(buff),
+ "Server (S2C throughput 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 run tests
- testOptions->s2csockfd = I2AddrFD(s2csrv_addr);
- testOptions->s2csockport = I2AddrPort(s2csrv_addr);
- log_println(1, " -- s2c %d port: %d", testOptions->child0,
- testOptions->s2csockport);
- pair.port1 = -1;
- pair.port2 = testOptions->s2csockport;
+ // get socket FD and the ephemeral port number that client will connect to run tests
+ testOptions->s2csockfd = I2AddrFD(s2csrv_addr);
+ testOptions->s2csockport = I2AddrPort(s2csrv_addr);
+ log_println(1, " -- s2c %d port: %d", testOptions->child0,
+ testOptions->s2csockport);
+ pair.port1 = -1;
+ pair.port2 = testOptions->s2csockport;
- // Data received from speed-chk. Send TEST_PREPARE "GO" signal with port number
- snprintf(buff, sizeof(buff), "%d", testOptions->s2csockport);
- j = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff));
- if (j == -1) {
- log_println(6, "S2C %d Error!, Test start message not
sent!",
- testOptions->child0);
- return j;
- }
- if (j == -2) { // could not write message data
- log_println(6, "S2C %d Error!, server port [%s] not
sent!",
- testOptions->child0, buff);
- return j;
- }
+ // Data received from speed-chk. Send TEST_PREPARE "GO" signal with port number
+ snprintf(buff, sizeof(buff), "%d", testOptions->s2csockport);
+ j = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff));
+ if (j == -1) {
+ log_println(6, "S2C %d Error!, Test start message not sent!",
+ testOptions->child0);
+ return j;
+ }
+ if (j == -2) { // could not write message data
+ log_println(6, "S2C %d Error!, server port [%s] not sent!",
+ testOptions->child0, buff);
+ return j;
+ }
- // ok, await for connect on 3rd port
- // This is the second throughput test, with data streaming
from
- // the server back to the client. Again stream data for 10
seconds.
+ // ok, await for connect on 3rd port
+ // This is the second throughput test, with data streaming from
+ // the server back to the client. Again stream data for 10 seconds.
- log_println(1, "%d waiting for data on
testOptions->s2csockfd",
- testOptions->child0);
+ log_println(1, "%d waiting for data on testOptions->s2csockfd",
+ testOptions->child0);
- clilen = sizeof(cli_addr);
- FD_ZERO(&rfd);
- FD_SET(testOptions->c2ssockfd, &rfd);
- sel_tv.tv_sec = 5; // wait for 5 secs
- sel_tv.tv_usec = 0;
- for (j = 0; j < RETRY_COUNT; j++) {
- ret = select((testOptions->s2csockfd) + 1, &rfd,
NULL, NULL,
- &sel_tv);
- if ((ret == -1) && (errno == EINTR))
- continue;
- if (ret == 0)
- return SOCKET_CONNECT_TIMEOUT; // timeout
- if (ret < 0)
- return -errno; // other socket errors. exit
- if (j == 4)
- return RETRY_EXCEEDED_WAITING_CONNECT; //
retry exceeded. exit
+ clilen = sizeof(cli_addr);
+ FD_ZERO(&rfd);
+ FD_SET(testOptions->c2ssockfd, &rfd);
+ sel_tv.tv_sec = 5; // wait for 5 secs
+ sel_tv.tv_usec = 0;
+ for (j = 0; j < RETRY_COUNT; j++) {
+ ret = select((testOptions->s2csockfd) + 1, &rfd, NULL, NULL,
+ &sel_tv);
+ if ((ret == -1) && (errno == EINTR))
+ continue;
+ if (ret == 0)
+ return SOCKET_CONNECT_TIMEOUT; // timeout
+ if (ret < 0)
+ return -errno; // other socket errors. exit
+ if (j == 4)
+ return RETRY_EXCEEDED_WAITING_CONNECT; // retry exceeded. exit
- // If a valid connection request is received, client has connected. Proceed.
- // Note the new socket fd - xmitfd - used in the
throughput test
- ximfd: xmitsfd = accept(testOptions->s2csockfd,
- (struct sockaddr *) &cli_addr,
&clilen);
- if (xmitsfd > 0) {
- log_println(6, "accept() for %d completed",
- testOptions->child0);
- procstatusenum = PROCESS_STARTED;
- proctypeenum = CONNECT_TYPE;
- protolog_procstatus(testOptions->child0,
testids, proctypeenum,
- procstatusenum, xmitsfd);
- break;
- }
- if ((xmitsfd == -1) && (errno == EINTR)) { // socket interrupted, wait some more
- log_println(
- 6,
- "Child %d interrupted while
waiting for accept() to complete",
- testOptions->child0);
- goto ximfd;
- }
- log_println(
- 6,
- "------- S2C connection setup for %d
returned because (%d)",
- testOptions->child0, errno);
- if (xmitsfd < 0) // other socket errors, quit
- return -errno;
- if (++j == 4) { // retry exceeded, quit
- log_println(
- 6,
- "s2c child %d, unable to open
connection, return from test",
- testOptions->child0);
- return -102;
- }
- }
- src_addr = I2AddrByLocalSockFD(get_errhandle(), xmitsfd, 0);
- conn = web100_connection_from_socket(agent, xmitsfd);
+ // If a valid connection request is received, client has connected. Proceed.
+ // Note the new socket fd - xmitfd - used in the throughput test
+ximfd: xmitsfd = accept(testOptions->s2csockfd,
+ (struct sockaddr *) &cli_addr, &clilen);
+ if (xmitsfd > 0) {
+ log_println(6, "accept() for %d completed",
+ testOptions->child0);
+ procstatusenum = PROCESS_STARTED;
+ proctypeenum = CONNECT_TYPE;
+ protolog_procstatus(testOptions->child0, testids, proctypeenum,
+ procstatusenum, xmitsfd);
+ break;
+ }
+ if ((xmitsfd == -1) && (errno == EINTR)) { // socket interrupted, wait some more
+ log_println(
+ 6,
+ "Child %d interrupted while waiting for accept() to complete",
+ testOptions->child0);
+ goto ximfd;
+ }
+ log_println(
+ 6,
+ "------- S2C connection setup for %d returned because (%d)",
+ testOptions->child0, errno);
+ if (xmitsfd < 0) // other socket errors, quit
+ return -errno;
+ if (++j == 4) { // retry exceeded, quit
+ log_println(
+ 6,
+ "s2c child %d, unable to open connection, return from test",
+ testOptions->child0);
+ return -102;
+ }
+ }
+ src_addr = I2AddrByLocalSockFD(get_errhandle(), xmitsfd, 0);
+ conn = web100_connection_from_socket(agent, xmitsfd);
- // set up packet capture. The data collected is used for bottleneck link calculations
- if (xmitsfd > 0) {
- log_println(6, "S2C child %d, ready to fork()",
- testOptions->child0);
- if (getuid() == 0) {
- /*
- pipe(mon_pipe2);
- start_packet_trace(xmitsfd,
testOptions->s2csockfd,
- &s2c_childpid, mon_pipe2, (struct
sockaddr *) &cli_addr,
- clilen, device, &pair, "s2c",
options->compress,
- meta.s2c_ndttrace);
- */
- pipe(mon_pipe2);
- if ((s2c_childpid = fork()) == 0) {
- /* close(ctlsockfd); */
- close(testOptions->s2csockfd);
- close(xmitsfd);
- log_println(
- 5,
- "S2C test Child thinks
pipe() returned fd0=%d, fd1=%d",
- mon_pipe2[0],
mon_pipe2[1]);
- /* log_println(2, "S2C test calling init_pkttrace() with pd=0x%x", (int) &cli_addr); */
- init_pkttrace(src_addr, (struct sockaddr
*) &cli_addr,
- clilen, mon_pipe2, device,
&pair, "s2c",
- options->compress);
- log_println(6,
- "S2C test ended, why is
timer still running?");
- exit(0); /* Packet trace finished,
terminate gracefully */
- }
- memset(tmpstr, 0, 256);
- for (i = 0; i < 5; i++) { // read nettrace file name
into "tmpstr"
- ret = read(mon_pipe2[0], tmpstr, 128);
- if ((ret == -1) && (errno == EINTR)) // socket interrupted, try reading again
- continue;
- break;
- }
+ // set up packet capture. The data collected is used for bottleneck link calculations
+ if (xmitsfd > 0) {
+ log_println(6, "S2C child %d, ready to fork()",
+ testOptions->child0);
+ if (getuid() == 0) {
+ /*
+ pipe(mon_pipe2);
+ start_packet_trace(xmitsfd, testOptions->s2csockfd,
+ &s2c_childpid, mon_pipe2, (struct sockaddr *) &cli_addr,
+ clilen, device, &pair, "s2c", options->compress,
+ meta.s2c_ndttrace);
+ */
+ pipe(mon_pipe2);
+ if ((s2c_childpid = fork()) == 0) {
+ /* close(ctlsockfd); */
+ close(testOptions->s2csockfd);
+ close(xmitsfd);
+ log_println(
+ 5,
+ "S2C test Child thinks pipe() returned fd0=%d, fd1=%d",
+ mon_pipe2[0], mon_pipe2[1]);
+ /* log_println(2, "S2C test calling init_pkttrace() with pd=0x%x", (int) &cli_addr); */
+ init_pkttrace(src_addr, (struct sockaddr *) &cli_addr,
+ clilen, mon_pipe2, device, &pair, "s2c",
+ options->compress);
+ log_println(6,
+ "S2C test ended, why is timer still running?");
+ exit(0); /* Packet trace finished, terminate gracefully */
+ }
+ memset(tmpstr, 0, 256);
+ for (i = 0; i < 5; i++) { // read nettrace file name into "tmpstr"
+ ret = read(mon_pipe2[0], tmpstr, 128);
+ if ((ret == -1) && (errno == EINTR)) // socket interrupted, try reading again
+ continue;
+ break;
+ }
- if (strlen(tmpstr) > 5)
- memcpy(meta.s2c_ndttrace, tmpstr,
strlen(tmpstr));
- // name of nettrace file passed back from pcap child copied into meta structure
+ if (strlen(tmpstr) > 5)
+ memcpy(meta.s2c_ndttrace, tmpstr, strlen(tmpstr));
+ // name of nettrace file passed back from pcap child copied into meta structure
- }
+ }
- /* experimental code, delete when finished */
- setCwndlimit(conn, group, agent, options);
- /* End of test code */
+ /* experimental code, delete when finished */
+ setCwndlimit(conn, group, agent, options);
+ /* End of test code */
- // create directory to write web100 snaplog trace
- create_client_logdir((struct sockaddr *) &cli_addr,
clilen,
- options->s2c_logname,
sizeof(options->s2c_logname),
- snaplogsuffix, sizeof(snaplogsuffix));
+ // create directory to write web100 snaplog trace
+ create_client_logdir((struct sockaddr *) &cli_addr, clilen,
+ options->s2c_logname, sizeof(options->s2c_logname),
+ snaplogsuffix, sizeof(snaplogsuffix));
- /* Kludge way of nuking Linux route cache. This
should be done
- * using the sysctl interface.
- */
- if (getuid() == 0) {
- // system("/sbin/sysctl -w
net.ipv4.route.flush=1");
- system("echo 1 >
/proc/sys/net/ipv4/route/flush");
- }
- rgroup = web100_group_find(agent, "read");
- rsnap = web100_snapshot_alloc(rgroup, conn);
- tgroup = web100_group_find(agent, "tune");
- tsnap = web100_snapshot_alloc(tgroup, conn);
+ /* Kludge way of nuking Linux route cache. This should be done
+ * using the sysctl interface.
+ */
+ if (getuid() == 0) {
+ // system("/sbin/sysctl -w net.ipv4.route.flush=1");
+ system("echo 1 > /proc/sys/net/ipv4/route/flush");
+ }
+ rgroup = web100_group_find(agent, "read");
+ rsnap = web100_snapshot_alloc(rgroup, conn);
+ tgroup = web100_group_find(agent, "tune");
+ tsnap = web100_snapshot_alloc(tgroup, conn);
- // fill send buffer with random printable data for
throughput test
- bytes_written = 0;
- k = 0;
- for (j = 0; j <= BUFFSIZE; j++) {
- while (!isprint(k & 0x7f))
- k++;
- buff[j] = (k++ & 0x7f);
- }
+ // fill send buffer with random printable data for throughput test
+ bytes_written = 0;
+ k = 0;
+ for (j = 0; j <= BUFFSIZE; j++) {
+ while (!isprint(k & 0x7f))
+ k++;
+ buff[j] = (k++ & 0x7f);
+ }
- // Send message to client indicating TEST_START
- if (send_msg(ctlsockfd, TEST_START, "", 0) < 0)
- log_println(6,
- "S2C test - Test-start message
failed for pid=%d",
- s2c_childpid);
- // ignore the alarm signal
- memset(&new, 0, sizeof(new));
- new.sa_handler = catch_s2c_alrm;
- sigaction(SIGALRM, &new, &old);
+ // Send message to client indicating TEST_START
+ if (send_msg(ctlsockfd, TEST_START, "", 0) < 0)
+ log_println(6,
+ "S2C test - Test-start message failed for pid=%d",
+ s2c_childpid);
+ // ignore the alarm signal
+ memset(&new, 0, sizeof(new));
+ new.sa_handler = catch_s2c_alrm;
+ sigaction(SIGALRM, &new, &old);
- // capture current values (i.e take snap shot) of
web_100 variables
- // Write snap logs if option is enabled. update meta log to point to this snaplog
+ // capture current values (i.e take snap shot) of web_100 variables
+ // Write snap logs if option is enabled. update meta log to point to this snaplog
- // If snaplog option is enabled, save snaplog details
in meta file
- if (options->snaplog) {
- memcpy(meta.s2c_snaplog, snaplogsuffix,
strlen(snaplogsuffix));
- }
- // get web100 snapshot and also log it based on
options
- /*start_snap_worker(&snapArgs, agent, options->snaplog,
&workerLoop,
- &workerThreadId, meta.s2c_snaplog,
options->s2c_logname,
- conn, group);*///new file changes
- start_snap_worker(&snapArgs, agent, peaks,
options->snaplog,
- &workerThreadId, meta.s2c_snaplog,
options->s2c_logname,
- conn, group);
+ // If snaplog option is enabled, save snaplog details in meta file
+ if (options->snaplog) {
+ memcpy(meta.s2c_snaplog, snaplogsuffix, strlen(snaplogsuffix));
+ }
+ // get web100 snapshot and also log it based on options
+ /*start_snap_worker(&snapArgs, agent, options->snaplog, &workerLoop,
+ &workerThreadId, meta.s2c_snaplog, options->s2c_logname,
+ conn, group);*///new file changes
+ start_snap_worker(&snapArgs, agent, peaks, options->snaplog,
+ &workerThreadId, meta.s2c_snaplog, options->s2c_logname,
+ conn, group);
- /* alarm(20); */
- tmptime = secs(); // current time
- tx_duration = tmptime + 10.0; // set timeout to 10 s
in future
+ /* alarm(20); */
+ tmptime = secs(); // current time
+ tx_duration = tmptime + 10.0; // set timeout to 10 s in future
- log_println(6, "S2C child %d beginning test",
testOptions->child0);
+ log_println(6, "S2C child %d beginning test", testOptions->child0);
- while (secs() < tx_duration) {
- bufctrlattempts++; // Increment total attempts at sending-> buffer control
- if (options->avoidSndBlockUp) { // Do not
block send buffers
- pthread_mutex_lock(&mainmutex);
+ while (secs() < tx_duration) {
+ bufctrlattempts++; // Increment total attempts at sending-> buffer control
+ if (options->avoidSndBlockUp) { // Do not block send buffers
+ pthread_mutex_lock(&mainmutex);
- // get details of next sequence # to be sent and fetch value from snap file
- web100_agent_find_var_and_group(agent,
"SndNxt", &group,
- &var);
- web100_snap_read(var, snapArgs.snap,
tmpstr);
- nextseqtosend = atoi(
-
web100_value_to_text(web100_get_var_type(var),
-
tmpstr));
- // get oldest un-acked sequence number
- web100_agent_find_var_and_group(agent,
"SndUna", &group,
- &var);
- web100_snap_read(var, snapArgs.snap,
tmpstr);
- lastunackedseq = atoi(
-
web100_value_to_text(web100_get_var_type(var),
-
tmpstr));
- pthread_mutex_unlock(&mainmutex);
+ // get details of next sequence # to be sent and fetch value from snap file
+ web100_agent_find_var_and_group(agent, "SndNxt", &group,
+ &var);
+ web100_snap_read(var, snapArgs.snap, tmpstr);
+ nextseqtosend = atoi(
+ web100_value_to_text(web100_get_var_type(var),
+ tmpstr));
+ // get oldest un-acked sequence number
+ web100_agent_find_var_and_group(agent, "SndUna", &group,
+ &var);
+ web100_snap_read(var, snapArgs.snap, tmpstr);
+ lastunackedseq = atoi(
+ web100_value_to_text(web100_get_var_type(var),
+ tmpstr));
+ pthread_mutex_unlock(&mainmutex);
- // Temporarily stop sending data if you sense that the buffer is overwhelmed
- // This is calculated by checking if
(8192 * 4) <
- // ((Next Sequence Number To Be Sent) - (Oldest Unacknowledged Sequence Number) - 1)
- // Increment draining queue value
- if (is_buffer_clogged(nextseqtosend,
lastunackedseq)) {
- drainingqueuecount++;
- continue;
- }
- }
+ // Temporarily stop sending data if you sense that the buffer is overwhelmed
+ // This is calculated by checking if (8192 * 4) <
+ // ((Next Sequence Number To Be Sent) - (Oldest Unacknowledged Sequence Number) - 1)
+ // Increment draining queue value
+ if (is_buffer_clogged(nextseqtosend, lastunackedseq)) {
+ drainingqueuecount++;
+ continue;
+ }
+ }
- // attempt to write random data into the
client socket
- n = write(xmitsfd, buff, RECLTH);
- if ((n == -1) && (errno == EINTR)) // socket interrupted, continue attempting to write
- continue;
- if (n < 0)
- break; // all data written. Exit
- bytes_written += n;
+ // attempt to write random data into the client socket
+ n = write(xmitsfd, buff, RECLTH);
+ if ((n == -1) && (errno == EINTR)) // socket interrupted, continue attempting to write
+ continue;
+ if (n < 0)
+ break; // all data written. Exit
+ bytes_written += n;
- if (options->avoidSndBlockUp) {
- bufctlrnewdata++; // increment "sent
data" queue
- }
- } // Completed end of trying to transmit data for the
goodput test
- /* alarm(10); */
- sigaction(SIGALRM, &old, NULL);
- sndqueue = sndq_len(xmitsfd);
+ if (options->avoidSndBlockUp) {
+ bufctlrnewdata++; // increment "sent data" queue
+ }
+ } // Completed end of trying to transmit data for the goodput test
+ /* alarm(10); */
+ sigaction(SIGALRM, &old, NULL);
+ sndqueue = sndq_len(xmitsfd);
- // finalize the midbox test ; disabling socket used
for throughput test
- log_println(6, "S2C child %d finished test",
testOptions->child0);
- shutdown(xmitsfd, SHUT_WR); /* end of write's */
+ // finalize the midbox test ; disabling socket used for throughput test
+ log_println(6, "S2C child %d finished test", testOptions->child0);
+ shutdown(xmitsfd, SHUT_WR); /* end of write's */
- // get actual time duration during which data was
transmitted
- tx_duration = secs() - tmptime;
+ // get actual time duration during which data was transmitted
+ tx_duration = secs() - tmptime;
- // Throughput in kbps = (no of bits sent * 8) / (1000 * time data was sent)
- x2cspd = (8.e-3 * bytes_written) / tx_duration;
+ // Throughput in kbps = (no of bits sent * 8) / (1000 * time data was sent)
+ x2cspd = (8.e-3 * bytes_written) / tx_duration;
- // Release semaphore, and close snaplog file.
finalize other data
- stop_snap_worker(&workerThreadId, options->snaplog,
&snapArgs);
+ // Release semaphore, and close snaplog file. finalize other data
+ stop_snap_worker(&workerThreadId, options->snaplog, &snapArgs);
- // send the x2cspd to the client
- memset(buff, 0, sizeof(buff));
+ // send the x2cspd to the client
+ memset(buff, 0, sizeof(buff));
- // Send throughput, unsent byte count, total sent
byte count to client
- snprintf(buff, sizeof(buff), "%0.0f %d %0.0f", x2cspd, sndqueue, bytes_written);
- if (send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff))
< 0)
- log_println(6,
- "S2C test - failed to send test
message to pid=%d",
- s2c_childpid);
+ // Send throughput, unsent byte count, total sent byte count to client
+ snprintf(buff, sizeof(buff), "%0.0f %d %0.0f", x2cspd, sndqueue, bytes_written);
+ if (send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff)) < 0)
+ log_println(6,
+ "S2C test - failed to send test message to pid=%d",
+ s2c_childpid);
- web100_snap(rsnap);
- web100_snap(tsnap);
+ web100_snap(rsnap);
+ web100_snap(tsnap);
- log_println(1, "sent %d bytes to client in %0.2f
seconds",
- (int) bytes_written, tx_duration);
- log_println(
- 1,
- "Buffer control counters Total = %d, new data = %d, Draining Queue = %d",
- bufctrlattempts, bufctlrnewdata,
drainingqueuecount);
+ log_println(1, "sent %d bytes to client in %0.2f seconds",
+ (int) bytes_written, tx_duration);
+ log_println(
+ 1,
+ "Buffer control counters Total = %d, new data = %d, Draining Queue = %d",
+ bufctrlattempts, bufctlrnewdata, drainingqueuecount);
- /* Next send speed-chk a flag to retrieve the data it
collected.
- * Skip this step if speed-chk isn't running.
- */
+ /* Next send speed-chk a flag to retrieve the data it collected.
+ * Skip this step if speed-chk isn't running.
+ */
- if (getuid() == 0) {
- log_println(1, "Signal USR2(%d) sent to child
[%d]", SIGUSR2,
- s2c_childpid);
- testOptions->child2 = s2c_childpid;
- kill(s2c_childpid, SIGUSR2);
- FD_ZERO(&rfd);
- FD_SET(mon_pipe2[0], &rfd);
- sel_tv.tv_sec = 1;
- sel_tv.tv_usec = 100000;
- i = 0;
+ if (getuid() == 0) {
+ log_println(1, "Signal USR2(%d) sent to child [%d]", SIGUSR2,
+ s2c_childpid);
+ testOptions->child2 = s2c_childpid;
+ kill(s2c_childpid, SIGUSR2);
+ FD_ZERO(&rfd);
+ FD_SET(mon_pipe2[0], &rfd);
+ sel_tv.tv_sec = 1;
+ sel_tv.tv_usec = 100000;
+ i = 0;
- for (;;) {
- ret = select(mon_pipe2[0] + 1, &rfd,
NULL, NULL, &sel_tv);
- if ((ret == -1) && (errno == EINTR)) {
- log_println(
- 6,
- "Interrupt received while waiting for s2c select90 to finish, continuing");
- continue;
- }
- if (((ret == -1) && (errno != EINTR))
|| (ret == 0)) {
- log_println(
- 4,
- "Failed to read pkt-pair data from S2C flow, retcode=%d, reason=%d, EINTR=%d",
- ret, errno,
EINTR);
- snprintf(
-
spds[(*spd_index)++],
-
sizeof(spds[*spd_index]),
- " -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
- snprintf(
-
spds[(*spd_index)++],
-
sizeof(spds[*spd_index]),
- " -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
- break;
- }
- /* There is something to read, so get it from the pktpair child. If an interrupt occurs,
- * just skip the read and go on
- * RAC 2/8/10
- */
- if (ret > 0) {
- if ((ret = read(mon_pipe2[0],
spds[*spd_index], 128))
- < 0)
- snprintf(
-
spds[*spd_index],
-
sizeof(spds[*spd_index]),
- " -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
- log_println(1,
- "%d bytes read
'%s' from S2C monitor pipe", ret,
-
spds[*spd_index]);
- (*spd_index)++;
- if (i++ == 1)
- break;
- sel_tv.tv_sec = 1;
- sel_tv.tv_usec = 100000;
- continue;
- }
- }
- }
+ for (;;) {
+ ret = select(mon_pipe2[0] + 1, &rfd, NULL, NULL, &sel_tv);
+ if ((ret == -1) && (errno == EINTR)) {
+ log_println(
+ 6,
+ "Interrupt received while waiting for s2c select90 to finish, continuing");
+ continue;
+ }
+ if (((ret == -1) && (errno != EINTR)) || (ret == 0)) {
+ log_println(
+ 4,
+ "Failed to read pkt-pair data from S2C flow, retcode=%d, reason=%d, EINTR=%d",
+ ret, errno, EINTR);
+ snprintf(
+ spds[(*spd_index)++],
+ sizeof(spds[*spd_index]),
+ " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
+ snprintf(
+ spds[(*spd_index)++],
+ sizeof(spds[*spd_index]),
+ " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
+ break;
+ }
+ /* There is something to read, so get it from the pktpair child. If an interrupt occurs,
+ * just skip the read and go on
+ * RAC 2/8/10
+ */
+ if (ret > 0) {
+ if ((ret = read(mon_pipe2[0], spds[*spd_index], 128))
+ < 0)
+ snprintf(
+ spds[*spd_index],
+ sizeof(spds[*spd_index]),
+ " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
+ log_println(1,
+ "%d bytes read '%s' from S2C monitor pipe", ret,
+ spds[*spd_index]);
+ (*spd_index)++;
+ if (i++ == 1)
+ break;
+ sel_tv.tv_sec = 1;
+ sel_tv.tv_usec = 100000;
+ continue;
+ }
+ }
+ }
- log_println(1, "%6.0f kbps inbound pid-%d", x2cspd,
s2c_childpid);
- }
+ log_println(1, "%6.0f kbps inbound pid-%d", x2cspd, s2c_childpid);
+ }
- /* alarm(30); *//* reset alarm() again, this 10 sec test should finish before this signal
- * is generated. */
- // Get web100 variables from snapshot taken earlier and send
to client
- log_println(6, "S2C-Send web100 data vars to client pid=%d",
- s2c_childpid);
- ret = web100_get_data(tsnap, ctlsockfd, agent, count_vars); //send web100 data to client
- web100_snapshot_free(tsnap);
- ret = web100_get_data(rsnap, ctlsockfd, agent, count_vars); //send tuning-related web100 data collected to client
- web100_snapshot_free(rsnap);
+ /* alarm(30); *//* reset alarm() again, this 10 sec test should finish before this signal
+ * is generated. */
+ // Get web100 variables from snapshot taken earlier and send to client
+ log_println(6, "S2C-Send web100 data vars to client pid=%d",
+ s2c_childpid);
+ ret = web100_get_data(tsnap, ctlsockfd, agent, count_vars); //send web100 data to client
+ web100_snapshot_free(tsnap);
+ ret = web100_get_data(rsnap, ctlsockfd, agent, count_vars); //send tuning-related web100 data collected to client
+ web100_snapshot_free(rsnap);
- // If sending web100 variables above failed, indicate to
client
- if (ret < 0) {
- log_println(6, "S2C - No web100 data received for
pid=%d",
- s2c_childpid);
- snprintf(buff, sizeof(buff), "No Data Collected:
000000");
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- }
+ // If sending web100 variables above failed, indicate to client
+ if (ret < 0) {
+ log_println(6, "S2C - No web100 data received for pid=%d",
+ s2c_childpid);
+ snprintf(buff, sizeof(buff), "No Data Collected: 000000");
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ }
- // Wait for message from client. Client sends its calculated throughput value
- log_println(6,"S2CSPD reception starts");
- msgLen = sizeof(buff);
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error!");
- snprintf(
- buff,
- sizeof(buff),
- "Server (S2C throughput test): Invalid S2C
throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return -1;
- }
- if (check_msg_type("S2C throughput test", TEST_MSG, msgType,
buff,
- msgLen)) {
- snprintf(
- buff,
- sizeof(buff),
- "Server (S2C throughput test): Invalid S2C
throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return -2;
- }
- if (msgLen <= 0) {
- log_println(0, "Improper message");
- snprintf(
- buff,
- sizeof(buff),
- "Server (S2C throughput test): Invalid S2C
throughput received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return -3;
- }
- buff[msgLen] = 0;
- *s2cspd = atoi(buff); // save Throughput value as seen by
client
- log_println(6, "S2CSPD from client %f", *s2cspd);
- // Final activities of ending tests. Close sockets, file
descriptors,
- // send finalise message to client
- close(xmitsfd);
- if (send_msg(ctlsockfd, TEST_FINALIZE, "", 0) < 0)
- log_println(6,
- "S2C test - failed to send finalize
message to pid=%d",
- s2c_childpid);
+ // Wait for message from client. Client sends its calculated throughput value
+ log_println(6,"S2CSPD reception starts");
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error!");
+ snprintf(
+ buff,
+ sizeof(buff),
+ "Server (S2C throughput test): Invalid S2C throughput received");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ return -1;
+ }
+ if (check_msg_type("S2C throughput test", TEST_MSG, msgType, buff,
+ msgLen)) {
+ snprintf(
+ buff,
+ sizeof(buff),
+ "Server (S2C throughput test): Invalid S2C throughput received");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ return -2;
+ }
+ if (msgLen <= 0) {
+ log_println(0, "Improper message");
+ snprintf(
+ buff,
+ sizeof(buff),
+ "Server (S2C throughput test): Invalid S2C throughput received");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ return -3;
+ }
+ buff[msgLen] = 0;
+ *s2cspd = atoi(buff); // save Throughput value as seen by client
+ log_println(6, "S2CSPD from client %f", *s2cspd);
+ // Final activities of ending tests. Close sockets, file descriptors,
+ // send finalise message to client
+ close(xmitsfd);
+ if (send_msg(ctlsockfd, TEST_FINALIZE, "", 0) < 0)
+ log_println(6,
+ "S2C test - failed to send finalize message to pid=%d",
+ s2c_childpid);
- if (getuid() == 0) {
- stop_packet_trace(mon_pipe2);
- }
+ if (getuid() == 0) {
+ stop_packet_trace(mon_pipe2);
+ }
- // log end of test (generic and protocol logs)
- log_println(0, " <------------ %d ------------->",
testOptions->child0);
- //log protocol validation logs
- teststatuses = TEST_ENDED;
- protolog_status(testOptions->child0, testids,
teststatuses,ctlsockfd);
+ // log end of test (generic and protocol logs)
+ log_println(0, " <------------ %d ------------->", testOptions->child0);
+ //log protocol validation logs
+ teststatuses = TEST_ENDED;
+ protolog_status(testOptions->child0, testids, teststatuses,ctlsockfd);
- setCurrentTest(TEST_NONE);
+ setCurrentTest(TEST_NONE);
- }
- return 0;
+ }
+ return 0;
}
=======================================
--- /trunk/src/test_sfw_clt.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/test_sfw_clt.c Thu Nov 15 13:33:19 2012
@@ -31,11 +31,11 @@
* @param signo 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);
+ if (signo == SIGALRM) {
+ log_println(1, "SIGALRM was caught");
+ return;
+ }
+ log_println(0, "Unknown (%d) signal was caught", signo);
}
/**
@@ -51,96 +51,96 @@
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;
+ char buff[BUFFSIZE + 1];
+ int sockfd;
+ fd_set fds;
+ struct timeval sel_tv;
+ int msgLen, msgType;
+ struct sockaddr_storage srv_addr;
+ socklen_t srvlen;
- // protocol logging
- enum PROCESS_TYPE_INT proctypeenum = PROCESS_TYPE;
- enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
- enum TEST_ID testids = SFW;
+ // protocol logging
+ enum PROCESS_TYPE_INT proctypeenum = PROCESS_TYPE;
+ enum PROCESS_STATUS_INT procstatusenum = UNKNOWN;
+ enum TEST_ID testids = SFW;
- // listen for a message from server for a preset time, testTime
- 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: // If Socket error, status of firewall is unknown
- log_println(0, "Simple firewall test: select exited with
error");
- I2AddrFree(sfwcli_addr);
- return NULL;
- case 0: // timeout, indicates that firewall is a possibility
- log_println(1, "Simple firewall test: CLT: no connection for %d seconds", testTime);
- s2c_result = SFW_POSSIBLE;
- I2AddrFree(sfwcli_addr);
- return NULL;
- }
+ // listen for a message from server for a preset time, testTime
+ 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: // If Socket error, status of firewall is unknown
+ log_println(0, "Simple firewall test: select exited with error");
+ I2AddrFree(sfwcli_addr);
+ return NULL;
+ case 0: // timeout, indicates that firewall is a possibility
+ log_println(1, "Simple firewall test: CLT: no connection for %d seconds", testTime);
+ s2c_result = SFW_POSSIBLE;
+ I2AddrFree(sfwcli_addr);
+ return NULL;
+ }
- // Get message sent by server. If message reception is erroneous, firewall status
- // .. cannot be determined
- srvlen = sizeof(srv_addr);
- sockfd = accept(sfwsockfd, (struct sockaddr *) &srv_addr, &srvlen);
+ // Get message sent by server. If message reception is erroneous, firewall status
+ // .. cannot be determined
+ srvlen = sizeof(srv_addr);
+ sockfd = accept(sfwsockfd, (struct sockaddr *) &srv_addr, &srvlen);
- // log protocol for connection accept
- if (sockfd > 0) {
- procstatusenum = PROCESS_STARTED;
- proctypeenum = CONNECT_TYPE;
- protolog_procstatus(getpid(), testids , proctypeenum,
- procstatusenum, sockfd );
- }
+ // log protocol for connection accept
+ if (sockfd > 0) {
+ procstatusenum = PROCESS_STARTED;
+ proctypeenum = CONNECT_TYPE;
+ protolog_procstatus(getpid(), testids , proctypeenum,
+ procstatusenum, sockfd );
+ }
- 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;
- }
+ 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;
+ }
- // The server is expected to send a TEST_MSG type of packet. Any other message
- // .. type is unexpected at this point and leaves firewall status indeterminate.
- if (check_msg_type(SFW_TEST_LOG, TEST_MSG, msgType, buff, msgLen)) {
- s2c_result = SFW_UNKNOWN;
- close(sockfd);
- I2AddrFree(sfwcli_addr);
- return NULL;
- }
+ // The server is expected to send a TEST_MSG type of packet. Any other message
+ // .. type is unexpected at this point and leaves firewall status indeterminate.
+ if (check_msg_type(SFW_TEST_LOG, TEST_MSG, msgType, buff, msgLen)) {
+ s2c_result = SFW_UNKNOWN;
+ close(sockfd);
+ I2AddrFree(sfwcli_addr);
+ return NULL;
+ }
- // The server is expected to send a 20 char message that
- // says "Simple firewall test" . Every other message string
- // indicates an unknown firewall status
+ // The server is expected to send a 20 char message that
+ // says "Simple firewall test" . Every other message string
+ // indicates an unknown firewall status
- if (msgLen != SFW_TEST_DEFAULT_LEN) {
- 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, SFW_PREDEFINED_TEST_MSG) != 0) {
- log_println(0, "Simple firewall test: Improper message");
- s2c_result = SFW_UNKNOWN;
- close(sockfd);
- I2AddrFree(sfwcli_addr);
- return NULL;
- }
+ if (msgLen != SFW_TEST_DEFAULT_LEN) {
+ 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, SFW_PREDEFINED_TEST_MSG) != 0) {
+ log_println(0, "Simple firewall test: Improper message");
+ s2c_result = SFW_UNKNOWN;
+ close(sockfd);
+ I2AddrFree(sfwcli_addr);
+ return NULL;
+ }
- // If none of the above conditions were met, then, the server
- // message has been received correctly, and there seems to be no
- // firewall. Perform clean-up activities.
+ // If none of the above conditions were met, then, the server
+ // message has been received correctly, and there seems to be no
+ // firewall. Perform clean-up activities.
- s2c_result = SFW_NOFIREWALL;
- close(sockfd);
- I2AddrFree(sfwcli_addr);
+ s2c_result = SFW_NOFIREWALL;
+ close(sockfd);
+ I2AddrFree(sfwcli_addr);
- return NULL;
+ return NULL;
}
/**
@@ -166,161 +166,161 @@
*
*/
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;
+ char buff[BUFFSIZE + 1];int msgLen, msgType;
+ int sfwport, sfwsock, sfwsockport;
+ I2Addr sfwsrv_addr = NULL;
+ struct sigaction new, old;
+ char* ptr;
+ pthread_t threadId;
- // variables used for protocol validation logs
- enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
- enum TEST_ID testids = SFW;
+ // variables used for protocol validation logs
+ enum TEST_STATUS_INT teststatuses = TEST_NOT_STARTED;
+ enum TEST_ID testids = SFW;
- if (tests & TEST_SFW) { // SFW test is to be performed
- log_println(1, " <-- Simple firewall test -->");
- setCurrentTest(TEST_SFW);
- //protocol logs
- teststatuses = TEST_STARTED;
- protolog_status(getpid(), testids, teststatuses, ctlsockfd);
+ if (tests & TEST_SFW) { // SFW test is to be performed
+ log_println(1, " <-- Simple firewall test -->");
+ setCurrentTest(TEST_SFW);
+ //protocol logs
+ teststatuses = TEST_STARTED;
+ protolog_status(getpid(), testids, teststatuses, ctlsockfd);
- printf("checking for firewalls . . . . . . . . . . . . . . . . . .
. ");
- fflush(stdout);
- msgLen = sizeof(buff);
+ printf("checking for firewalls . . . . . . . . . . . . . . . . . . . ");
+ fflush(stdout);
+ msgLen = sizeof(buff);
- // The first message expected from the server is a
TEST_PREPARE message.
- // Any other type of message is unexpected at this time.
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed prepare
message!");
- return 1;
- }
- if (check_msg_type(SFW_TEST_LOG, TEST_PREPARE, msgType, buff,
msgLen)) {
- return 2;
- }
+ // The first message expected from the server is a TEST_PREPARE message.
+ // Any other type of message is unexpected at this time.
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed prepare message!");
+ return 1;
+ }
+ if (check_msg_type(SFW_TEST_LOG, TEST_PREPARE, msgType, buff, msgLen)) {
+ return 2;
+ }
- // This message is expected to be of valid length, and have a
message
- // .. payload containing the integral ephemeral port number
and testTime
- // ... separated by a single space
- 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)) { // get ephemeral port#
- log_println(0, "Invalid port number");
- return 4;
- }
- ptr = strtok(NULL, " ");
- if (ptr == NULL) {
- log_println(0, "SFW: Improper message");
- return 5;
- }
- if (check_int(ptr, &testTime)) { // get test time
- log_println(0, "Invalid waiting time");
- return 4;
- }
- log_println(1, "\n -- port: %d", sfwport);
- log_println(1, " -- time: %d", testTime);
- 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);
+ // This message is expected to be of valid length, and have a message
+ // .. payload containing the integral ephemeral port number and testTime
+ // ... separated by a single space
+ 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)) { // get ephemeral port#
+ log_println(0, "Invalid port number");
+ return 4;
+ }
+ ptr = strtok(NULL, " ");
+ if (ptr == NULL) {
+ log_println(0, "SFW: Improper message");
+ return 5;
+ }
+ if (check_int(ptr, &testTime)) { // get test time
+ log_println(0, "Invalid waiting time");
+ return 4;
+ }
+ log_println(1, "\n -- port: %d", sfwport);
+ log_println(1, " -- time: %d", testTime);
+ 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);
- // create a listening socket, and if successful, send this socket number to server
- 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);
+ // create a listening socket, and if successful, send this socket number to server
+ 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);
- // Send a TEST_MSG to server with the client's port number
- snprintf(buff, sizeof(buff), "%d", sfwsockport);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ // Send a TEST_MSG to server with the client's port number
+ snprintf(buff, sizeof(buff), "%d", sfwsockport);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- // The server responds to the TEST_MSG messages with a TEST_START message.
- // Any other type of message is an error here.
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed start
message!");
- return 1;
- }
- if (check_msg_type(SFW_TEST_LOG, TEST_START, msgType, buff,
msgLen)) {
- return 2;
- }
+ // The server responds to the TEST_MSG messages with a TEST_START message.
+ // Any other type of message is an error here.
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed start message!");
+ return 1;
+ }
+ if (check_msg_type(SFW_TEST_LOG, TEST_START, msgType, buff, msgLen)) {
+ return 2;
+ }
- // Now listen for server sending out a test for the S->C
direction , and
- // update test results
- pthread_create(&threadId, NULL, &test_osfw_clt, NULL);
+ // Now listen for server sending out a test for the S->C direction , and
+ // update test results
+ pthread_create(&threadId, NULL, &test_osfw_clt, NULL);
- // ignore the alarm signal
- memset(&new, 0, sizeof(new));
- new.sa_handler = catch_alrm;
- sigaction(SIGALRM, &new, &old);
- alarm(testTime + 1);
+ // ignore the alarm signal
+ memset(&new, 0, sizeof(new));
+ new.sa_handler = catch_alrm;
+ sigaction(SIGALRM, &new, &old);
+ alarm(testTime + 1);
- // Now, run Test from client for the C->S direction SFW test
- // ..trying to connect to ephemeral port number sent by server
+ // Now, run Test from client for the C->S direction SFW test
+ // ..trying to connect to ephemeral port number sent by server
- if (CreateConnectSocket(&sfwsock, NULL, sfwsrv_addr, conn_options, 0) == 0) {
- send_msg(sfwsock, TEST_MSG, SFW_PREDEFINED_TEST_MSG,
20);
- }
- alarm(0);
- sigaction(SIGALRM, &old, NULL);
+ if (CreateConnectSocket(&sfwsock, NULL, sfwsrv_addr, conn_options, 0) == 0) {
+ send_msg(sfwsock, TEST_MSG, SFW_PREDEFINED_TEST_MSG, 20);
+ }
+ alarm(0);
+ sigaction(SIGALRM, &old, NULL);
- // Expect a TES_MSG from server with results. Other types of
messages are
- // ..unexpected at this point.
+ // Expect a TES_MSG from server with results. Other types of messages are
+ // ..unexpected at this point.
- msgLen = sizeof(buff);
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed text
message!");
- return 1;
- }
- if (check_msg_type(SFW_TEST_LOG, TEST_MSG, msgType, buff,
msgLen)) {
- return 2;
- }
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed text message!");
+ return 1;
+ }
+ if (check_msg_type(SFW_TEST_LOG, TEST_MSG, msgType, buff, msgLen)) {
+ return 2;
+ }
- // The test results are sent as a numeric encoding the test
results.
+ // The test results are sent as a numeric encoding the test results.
- if (msgLen <= 0) { // test results have valid length
- log_println(0, "Improper message");
- return 3;
- }
- buff[msgLen] = 0;
- if (check_int(buff, &c2s_result)) { // test result has to be a valid integer
- log_println(0, "Invalid test result");
- return 4;
- }
+ if (msgLen <= 0) { // test results have valid length
+ log_println(0, "Improper message");
+ return 3;
+ }
+ buff[msgLen] = 0;
+ if (check_int(buff, &c2s_result)) { // test result has to be a valid integer
+ log_println(0, "Invalid test result");
+ return 4;
+ }
- // wait for the S->C listener thread to finish
- pthread_join(threadId, NULL);
+ // wait for the S->C listener thread to finish
+ pthread_join(threadId, NULL);
- printf("Done\n");
+ printf("Done\n");
- // The last message expected from the server is an empty TEST_FINALIZE message.
- msgLen = sizeof(buff);
- if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
- log_println(0, "Protocol error - missed finalize
message!");
- return 1;
- }
- if (check_msg_type(SFW_TEST_LOG, TEST_FINALIZE, msgType,
buff, msgLen)) {
- return 2;
- }
- log_println(1, " <-------------------------->");
- // log protocol validation test ending
- teststatuses = TEST_ENDED;
- protolog_status(getpid(), testids, teststatuses,ctlsockfd);
- setCurrentTest(TEST_NONE);
- }
- return 0;
+ // The last message expected from the server is an empty TEST_FINALIZE message.
+ msgLen = sizeof(buff);
+ if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
+ log_println(0, "Protocol error - missed finalize message!");
+ return 1;
+ }
+ if (check_msg_type(SFW_TEST_LOG, TEST_FINALIZE, msgType, buff, msgLen)) {
+ return 2;
+ }
+ log_println(1, " <-------------------------->");
+ // log protocol validation test ending
+ teststatuses = TEST_ENDED;
+ protolog_status(getpid(), testids, teststatuses,ctlsockfd);
+ setCurrentTest(TEST_NONE);
+ }
+ return 0;
}
/**
@@ -331,41 +331,41 @@
*/
int results_sfw(char tests, char* host) {
- if (tests & TEST_SFW) { // SFW test has been selected to be run
- // Print C->S direction's results
- 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;
- }
- // Print S->C directions results
- 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;
+ if (tests & TEST_SFW) { // SFW test has been selected to be run
+ // Print C->S direction's results
+ 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;
+ }
+ // Print S->C directions results
+ 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;
}
=======================================
--- /trunk/src/test_sfw_srv.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/test_sfw_srv.c Thu Nov 15 13:33:19 2012
@@ -31,15 +31,15 @@
*/
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);
+ 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);
}
/**
@@ -52,30 +52,30 @@
void*
test_osfw_srv(void* vptr) {
- int sfwsock;
- struct sigaction new, old;
+ 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);
+ // 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);
- }
+ // 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);
+ 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);
+ // signal sleeping threads to wake up
+ pthread_mutex_lock(&mainmutex);
+ toWait = 0;
+ pthread_cond_broadcast(&maincond);
+ pthread_mutex_unlock(&mainmutex);
- return NULL;
+ return NULL;
}
/**
@@ -85,24 +85,24 @@
*/
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);
- }
+ 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);
+ // 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, ctlsockfd);
- log_println(1, " <-------------------------->");
- // unset test name
- setCurrentTest(TEST_NONE);
+ // log
+ teststatusnow = TEST_ENDED;
+ protolog_status(getpid(), thistestId, teststatusnow, ctlsockfd);
+ log_println(1, " <-------------------------->");
+ // unset test name
+ setCurrentTest(TEST_NONE);
}
/**
@@ -121,239 +121,239 @@
*/
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;
+ 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;
+ // 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);
+ 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,ctlsockfd);
+ 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,ctlsockfd);
- // 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));
- snprintf(buff, sizeof(buff), "Server (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return -1;
- }
+ // 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));
+ snprintf(buff, sizeof(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);
+ // 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) {
+ 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));
+ // 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
+ // 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");
- snprintf(buff, sizeof(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);
+ 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");
+ snprintf(buff, sizeof(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
- snprintf(buff, sizeof(buff), "%d %d", sfwsockport, testTime);
- if ((rc = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff)))
< 0)
- return (rc);
+ // try sending TEST_PREPARE msg with ephemeral port number to client.
+ // If unable to, return
+ snprintf(buff, sizeof(buff), "%d %d", sfwsockport, testTime);
+ if ((rc = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff))) < 0)
+ 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!");
- snprintf(buff, sizeof(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!");
- snprintf(buff, sizeof(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");
- snprintf(buff, sizeof(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
+ // 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!");
+ snprintf(buff, sizeof(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!");
+ snprintf(buff, sizeof(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");
+ snprintf(buff, sizeof(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");
- snprintf(buff, sizeof(buff), "Server (Simple firewall test): Invalid port number received");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- I2AddrFree(sfwsrv_addr);
- return 4;
- }
+ buff[msgLen] = 0;
+ if (check_int(buff, &sfwport)) { // message data is not number, thus no port info received
+ log_println(0, "Invalid port number");
+ snprintf(buff, sizeof(buff), "Server (Simple firewall test): Invalid port number received");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ 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);
+ // 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, ctlsockfd);
- log_println(1, " <-------------------------->");
- I2AddrFree(sfwsrv_addr);
- return 5;
- }
- I2AddrSetPort(sfwcli_addr, sfwport);
- log_println(1, " -- oport: %d", sfwport);
+ // log end
+ teststatusnow = TEST_ENDED;
+ protolog_status(options->child0, thistestId, teststatusnow, ctlsockfd);
+ 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 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);
+ // 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;
+ 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.
+ // 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");
- snprintf(buff, sizeof(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);
- snprintf(buff, sizeof(buff), "%d", SFW_POSSIBLE);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- finalize_sfw(ctlsockfd);
- I2AddrFree(sfwsrv_addr);
- I2AddrFree(sfwcli_addr);
- return 2;
- }
+ 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");
+ snprintf(buff, sizeof(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);
+ snprintf(buff, sizeof(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, sockfd);
+ // 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, sockfd);
- msgLen = sizeof(buff);
- if (recv_msg(sockfd, &msgType, buff, &msgLen)) { // message received in error
- log_println(0, "Simple firewall test: unrecognized
message");
- snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
- send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
- 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
- snprintf(buff, sizeof(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");
- snprintf(buff, sizeof(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");
- snprintf(buff, sizeof(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;
- }
+ msgLen = sizeof(buff);
+ if (recv_msg(sockfd, &msgType, buff, &msgLen)) { // message received in error
+ log_println(0, "Simple firewall test: unrecognized message");
+ snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
+ send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
+ 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
+ snprintf(buff, sizeof(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");
+ snprintf(buff, sizeof(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");
+ snprintf(buff, sizeof(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
- snprintf(buff, sizeof(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;
+ // All messages were received correctly, hence no firewall
+ snprintf(buff, sizeof(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;
}
=======================================
--- /trunk/src/testoptions.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/testoptions.c Thu Nov 15 13:33:19 2012
@@ -23,10 +23,10 @@
// 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;
int workerLoop = 0;
@@ -46,42 +46,42 @@
*/
void findCwndPeaks(web100_agent* agent, CwndPeaks* peaks, web100_snapshot* snap) {
- web100_group* group;
- web100_var* var;
- int CurCwnd;
- char tmpstr[256];
+ 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));
+ 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;
+ 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;
}
/**
@@ -90,11 +90,11 @@
*/
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);
+ if (signo == SIGALRM) {
+ log_println(1, "SIGALRM was caught");
+ return;
+ }
+ log_println(0, "Unknown (%d) signal was caught", signo);
}
/**
@@ -106,46 +106,46 @@
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;
+ 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;
+ // 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);
- }
+ 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 enabled, 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);
- }
+ // Find Congestion window peaks from a web_100 snapshot, if enabled
+ // Write snap log , if enabled, 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;
+ return NULL;
}
/**
@@ -155,15 +155,15 @@
* @param test_id id of the test
*/
void add_test_to_suite(int* first, char * buff, size_t buff_strlen, int test_id) {
- char tmpbuff[16];
- if (*first) {
- *first = 0;
- snprintf(buff, buff_strlen, "%d", test_id);
- } else {
- memset(tmpbuff, 0, sizeof(tmpbuff));
- snprintf(tmpbuff, sizeof(tmpbuff), " %d", test_id);
- strlcat(buff, tmpbuff, buff_strlen);
- }
+ char tmpbuff[16];
+ if (*first) {
+ *first = 0;
+ snprintf(buff, buff_strlen, "%d", test_id);
+ } else {
+ memset(tmpbuff, 0, sizeof(tmpbuff));
+ snprintf(tmpbuff, sizeof(tmpbuff), " %d", test_id);
+ strlcat(buff, tmpbuff, buff_strlen);
+ }
}
/**
@@ -182,65 +182,65 @@
*/
int initialize_tests(int ctlsockfd, TestOptions* options, char * buff, size_t buff_strlen) {
- unsigned char useropt = 0;
- int msgType;
- int msgLen = 1;
- int first = 1;
- //char remhostarr[256], protologlocalarr[256];
- //char *remhost_ptr = get_remotehost();
+ 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);
+ assert(ctlsockfd != -1);
+ assert(options);
- // read the test suite request
- if (recv_msg(ctlsockfd, &msgType, &useropt, &msgLen)) {
- snprintf(buff, buff_strlen, "Invalid test suite request");
- send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
- return (-1);
- }
- if (msgLen == -1) {
- snprintf(buff, buff_strlen, "Client timeout");
- return (-4);
- }
- // Expecting a MSG_LOGIN with payload byte indicating tests to be run
- if ((msgType != MSG_LOGIN) || (msgLen != 1)) {
- snprintf(buff, buff_strlen, "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);
+ // read the test suite request
+ if (recv_msg(ctlsockfd, &msgType, &useropt, &msgLen)) {
+ snprintf(buff, buff_strlen, "Invalid test suite request");
+ send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
+ return (-1);
+ }
+ if (msgLen == -1) {
+ snprintf(buff, buff_strlen, "Client timeout");
+ return (-4);
+ }
+ // Expecting a MSG_LOGIN with payload byte indicating tests to be run
+ if ((msgType != MSG_LOGIN) || (msgLen != 1)) {
+ snprintf(buff, buff_strlen, "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);
+ //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!
- snprintf(buff, buff_strlen, "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, buff_strlen, TEST_MID);
- }
- if (useropt & TEST_SFW) {
- add_test_to_suite(&first, buff, buff_strlen, TEST_SFW);
- }
- if (useropt & TEST_C2S) {
- add_test_to_suite(&first, buff, buff_strlen, TEST_C2S);
- }
- if (useropt & TEST_S2C) {
- add_test_to_suite(&first, buff, buff_strlen, TEST_S2C);
- }
- if (useropt & TEST_META) {
- add_test_to_suite(&first, buff, buff_strlen, TEST_META);
- }
- return useropt;
+ if (!(useropt
+ & (TEST_MID | TEST_C2S | TEST_S2C | TEST_SFW | TEST_STATUS
+ | TEST_META))) {
+ // message received does not indicate a valid test!
+ snprintf(buff, buff_strlen, "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, buff_strlen, TEST_MID);
+ }
+ if (useropt & TEST_SFW) {
+ add_test_to_suite(&first, buff, buff_strlen, TEST_SFW);
+ }
+ if (useropt & TEST_C2S) {
+ add_test_to_suite(&first, buff, buff_strlen, TEST_C2S);
+ }
+ if (useropt & TEST_S2C) {
+ add_test_to_suite(&first, buff, buff_strlen, TEST_S2C);
+ }
+ if (useropt & TEST_META) {
+ add_test_to_suite(&first, buff, buff_strlen, TEST_META);
+ }
+ return useropt;
}
/** Method to start snap worker thread that collects snap logs
@@ -255,55 +255,55 @@
* @param web100_group group web100_group pointer
*/
void start_snap_worker(SnapArgs *snaparg, web100_agent *agentarg, CwndPeaks* peaks,
- char snaplogenabled, pthread_t *wrkrthreadidarg,
- char *metafilevariablename, char *metafilename,
web100_connection* conn,
- web100_group* group) {
- FILE *fplocal;
+ char snaplogenabled, 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 = peaks;
- workerArgs.writeSnap = snaplogenabled;
+ WorkerArgs workerArgs;
+ workerArgs.snapArgs = snaparg;
+ workerArgs.agent = agentarg;
+ workerArgs.peaks = peaks;
+ workerArgs.writeSnap = snaplogenabled;
- group = web100_group_find(agentarg, "read");
- snaparg->snap = web100_snapshot_alloc(group, conn);
+ group = web100_group_find(agentarg, "read");
+ snaparg->snap = web100_snapshot_alloc(group, conn);
- if (snaplogenabled) {
+ 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
+ //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);
- }
- }
+ 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;
- }
+ 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);
- workerLoop= 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);
+ pthread_mutex_lock(&mainmutex);
+ workerLoop= 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);
}
/**
@@ -313,18 +313,18 @@
* @param snapArgs_ptr pointer to a snapArgs object
* */
void stop_snap_worker(pthread_t *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);
- }
+ 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);
+ web100_snapshot_free(snapArgs_ptr->snap);
}
@@ -344,43 +344,43 @@
* */
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) {
+ int *imonarg, struct sockaddr *cliaddrarg, socklen_t clilenarg,
+ char* device, PortPair* pairarg, const char* testindicatorarg,
+ int iscompressionenabled, char *copylocationarg) {
- char tmpstr[256];
- int i, readretval;
+ char tmpstr[256];
+ int i, readretval;
- I2Addr src_addr = I2AddrByLocalSockFD(get_errhandle(), socketfdarg,
0);
+ I2Addr src_addr = I2AddrByLocalSockFD(get_errhandle(), socketfdarg, 0);
- if ((*childpid = fork()) == 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]);
+ 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);
+ 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"
- readretval = read(imonarg[0], tmpstr, 128);
- if ((readretval == -1) && (errno == EINTR)) // socket interrupted, try reading again
- continue;
- break;
- }
+ exit(0); // Packet trace finished, terminate gracefully
+ }
+ memset(tmpstr, 0, 256);
+ 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;
+ }
- // 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);
- }
+ // 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);
+ }
- // free this address now.
- I2AddrFree(src_addr);
+ // free this address now.
+ I2AddrFree(src_addr);
}
@@ -390,19 +390,19 @@
*
* */
void stop_packet_trace(int *monpipe_arr) {
- int retval;
- int i;
+ int retval;
+ int i;
- for (i = 0; i < RETRY_COUNT; i++) {
- //retval = write(mon_pipe1[1], "c", 1);
- retval = write(monpipe_arr[1], "c", 1);
- if (retval == 1)
- break;
- if ((retval == -1) && (errno == EINTR))
- continue;
- }
- close(monpipe_arr[0]);
- close(monpipe_arr[1]);
+ for (i = 0; i < RETRY_COUNT; i++) {
+ //retval = write(mon_pipe1[1], "c", 1);
+ retval = write(monpipe_arr[1], "c", 1);
+ if (retval == 1)
+ break;
+ if ((retval == -1) && (errno == EINTR))
+ continue;
+ }
+ close(monpipe_arr[0]);
+ close(monpipe_arr[1]);
}
@@ -413,37 +413,37 @@
* @param agentarg web100 agent pointer
* */
void setCwndlimit(web100_connection* connarg, web100_group* grouparg,
- web100_agent* agentarg, Options* optionsarg) {
+ web100_agent* agentarg, Options* optionsarg) {
- web100_var *LimRwin, *yar;
- u_int32_t limrwin_val;
- char yuff[32];
+ web100_var *LimRwin, *yar;
+ u_int32_t limrwin_val;
+ char yuff[32];
- if (optionsarg->limit > 0) {
- log_print(1, "Setting Cwnd limit - ");
+ if (optionsarg->limit > 0) {
+ 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);
- 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_raw_write(LimRwin, connarg, &limrwin_val);
- log_println(1, " --- Done");
- }
+ if (connarg != NULL) {
+ 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_raw_write(LimRwin, connarg, &limrwin_val);
+ log_println(1, " --- Done");
+ }
- }
+ }
}
/**
@@ -454,9 +454,9 @@
* @return integer indicating whether buffer is clogged
* */
int is_buffer_clogged(int nextseqtosend, int lastunackedseq) {
- int recclog = 0;
- if ((RECLTH << 2) < (nextseqtosend - lastunackedseq - 1)) {
- recclog = 1;
- }
- return recclog;
+ int recclog = 0;
+ if ((RECLTH << 2) < (nextseqtosend - lastunackedseq - 1)) {
+ recclog = 1;
+ }
+ return recclog;
}
=======================================
--- /trunk/src/tr-mkmap.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/tr-mkmap.c Thu Nov 15 13:33:19 2012
@@ -53,69 +53,69 @@
#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 },
+ 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;
- }
- }
+ 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
+ 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
@@ -123,102 +123,102 @@
* lines with *'s too.
*/
uint32_t get_addr(char *tmpbuff) {
- char *tmpstr;
- int i;
- uint32_t ip_addr;
- struct sockaddr_in address;
+ 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 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);
+ /* 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);
+ /* 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
+ int
get_addr6(uint32_t dst_addr[4], char *tmpbuff)
{
- char *tmpstr;
- int i;
- struct sockaddr_in6 address;
+ 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 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;
- }
+ /* 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;
+ /* 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
@@ -226,41 +226,41 @@
* 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);
+ 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
+ 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
@@ -270,33 +270,33 @@
*/
void save_tree(struct tr_tree *cur, FILE *fp) {
- int i;
+ 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);
- }
+ 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
+ void
save_tree6(struct tr_tree6 *cur, FILE *fp)
{
- int i;
+ 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);
- }
+ 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
@@ -304,47 +304,47 @@
* Once restored, the comparison can take place.
*/
void restore_tree2(struct tr_tree *tmp, FILE *fp) {
- struct tr_tree *new;
- int i, j;
+ 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);
- }
+ 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
+ void
restore_tree26(struct tr_tree6 *tmp, FILE *fp)
{
- struct tr_tree6 *new;
- int i, j;
+ 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);
- }
+ 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
@@ -352,464 +352,464 @@
* standard recursive print algorithm
*/
void print_tree(struct tr_tree *cur) {
- static int i;
- int j;
+ 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));
+ 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
+ void
print_tree6(struct tr_tree6 *cur)
{
- static int i;
- int j;
- char nodename[200];
- socklen_t nnlen = 199;
+ 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--;
- }
+ 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;
+ struct tr_tree *root, *current, *new;
+ int i;
+ uint32_t ip_addr;
+ char buff[256], *tmpbuff;
+ FILE * fp;
- root = NULL;
- current = NULL;
+ root = NULL;
+ current = NULL;
- printf("\nBuilding default tree (IPv4)\n\n");
- if (inputfile == NULL)
- inputfile = "/tmp/traceroute.data";
- fp = fopen(inputfile, "r");
+ 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;
- snprintf(new->hostname, sizeof(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 (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;
+ snprintf(new->hostname, sizeof(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);
+ 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
+ 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;
+ 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;
+ root = NULL;
+ current = NULL;
- printf("\nBuilding default tree (IPv6)\n\n");
- if (inputfile == NULL)
- inputfile = "/tmp/traceroute6.data";
- fp = fopen(inputfile, "r");
+ 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);
- snprintf(new->hostname, sizeof(new->hostname), "%s",
nodename);
- /* resolve host name and store for later use */
+ 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);
+ snprintf(new->hostname, sizeof(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);
+ 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;
+ 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;
+ 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++;
+ 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));
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/src/tr-tree.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/tr-tree.c Thu Nov 15 13:33:19 2012
@@ -43,79 +43,79 @@
* Once restored, the comparison can take place.
*/
void restore_tree(struct tr_tree *tmp, FILE *fp) {
- struct tr_tree *new;
- int i, j;
+ 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);
- }
+ 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;
+ 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;
+ 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));
+ 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;
for (j=0; j<current->branches; j++) {
log_print(5, "Comparing map node [%u.%u.%u.%u] ",
- (current->branch[j]->ip_addr & 0xff),
- ((current->branch[j]->ip_addr >> 8) & 0xff),
- ((current->branch[j]->ip_addr >> 16) & 0xff),
- (current->branch[j]->ip_addr >> 24));
+ (current->branch[j]->ip_addr & 0xff),
+ ((current->branch[j]->ip_addr >> 8) & 0xff),
+ ((current->branch[j]->ip_addr >> 16) & 0xff),
+ (current->branch[j]->ip_addr >> 24));
log_println(5, "to client node [%u.%u.%u.%u], cnt = %d",
- (IPlist[i] & 0xff), ((IPlist[i] >> 8) & 0xff),
- ((IPlist[i] >> 16) & 0xff), (IPlist[i] >> 24), i);
+ (IPlist[i] & 0xff), ((IPlist[i] >> 8) & 0xff),
+ ((IPlist[i] >> 16) & 0xff), (IPlist[i] >> 24), i);
if (current->branch[j]->ip_addr == IPlist[i]) {
current = current->branch[j];
@@ -124,8 +124,8 @@
if (current->branch[k]->branches == 0) {
srv_addr = current->branch[k]->ip_addr;
log_println(5, "srv_addr set to [%u.%u.%u.%u]",
- (srv_addr & 0xff), ((srv_addr >> 8) & 0xff),
- ((srv_addr >> 16) & 0xff), (srv_addr >> 24));
+ (srv_addr & 0xff), ((srv_addr >> 8) & 0xff),
+ ((srv_addr >> 16) & 0xff), (srv_addr >> 24));
found_node = 1;
}
}
@@ -137,58 +137,58 @@
break;
}
- if (current->ip_addr == IPlist[cnt]) {
- srv_addr = IPlist[cnt];
- found_node = 1;
- }
- if (srv_addr != 0)
- found_node = 1;
+ 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;
- }
- }
+ 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));
+ 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 *) ¤t->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));
+ 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 *) ¤t->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));
+ 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);
+ return (current->ip_addr);
}
=======================================
--- /trunk/src/tr-tree6.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/tr-tree6.c Thu Nov 15 13:33:19 2012
@@ -47,176 +47,176 @@
/* Restore the default tree, stored by the save tree routine above.
* Once restored, the comparison can take place.
*/
-void
+ void
restore_tree6(struct tr_tree6 *tmp, FILE *fp)
{
- struct tr_tree6 *new;
- int i, j;
+ 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);
- }
+ 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
+ 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;
+ 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;
+ 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);
- }
+ 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->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 (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;
- }
- }
+ 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));
+ 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 (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);
- }
+ 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;
+ memcpy(IPnode, current->ip_addr, 16);
+ return 1;
}
#endif
=======================================
--- /trunk/src/troute.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/troute.c Thu Nov 15 13:33:19 2012
@@ -51,7 +51,7 @@
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1990, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
+ The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
@@ -99,11 +99,11 @@
* 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 */
@@ -134,275 +134,275 @@
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;
+ 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;
+ 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;
+ 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;
+ 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 ((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 ((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;
+ 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 (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;
+ 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));
+ (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:
+ 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);
+ 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;
+ 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);
+ 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);
-}
+ 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;
+ 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);
+ 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);
+ 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");
- }
-}
+ 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;
+ 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);
-}
+ 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;
+ 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;
+ 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);
+ 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;
+ 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
&&
+ 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;
+ /*
+ * 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;
- }
+ /*
+ * 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;
+ /* 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);
- }
+ /*
+ * 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.
- */
+/*
+ * 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;
-}
+ 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;
+ }
=======================================
--- /trunk/src/troute6.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/troute6.c Thu Nov 15 13:33:19 2012
@@ -69,7 +69,7 @@
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1990, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
+ The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#endif
@@ -144,105 +144,105 @@
* either don't send ICMP "time exceeded" messages or send them
* with a ttl too small to reach us. 14 - 17 are running the
* MIT C Gateway code that doesn't send "time exceeded"s. God
- * only knows what's going on with 12.
- *
- * The silent gateway 12 in the above may be the result of a bug in
- * the 4.[23]BSD network code (and its derivatives): 4.x (x <= 3)
- * sends an unreachable message using whatever ttl remains in the
- * original datagram. Since, for gateways, the remaining ttl is
- * zero, the icmp "time exceeded" is guaranteed to not make it back
- * to us. The behavior of this bug is slightly more interesting
- * when it appears on the destination system:
- *
- * 1 helios.ee.lbl.gov (128.3.112.1) 0 ms 0 ms 0 ms
- * 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 19 ms 39 ms
- * 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 19 ms 39 ms 19 ms
- * 4 ccngw-ner-cc.Berkeley.EDU (128.32.136.23) 39 ms 40 ms 19 ms
- * 5 ccn-nerif35.Berkeley.EDU (128.32.168.35) 39 ms 39 ms 39 ms
- * 6 csgw.Berkeley.EDU (128.32.133.254) 39 ms 59 ms 39 ms
- * 7 * * *
- * 8 * * *
- * 9 * * *
- * 10 * * *
- * 11 * * *
- * 12 * * *
- * 13 rip.Berkeley.EDU (128.32.131.22) 59 ms ! 39 ms ! 39 ms !
- *
- * Notice that there are 12 "gateways" (13 is the final
- * destination) and exactly the last half of them are "missing".
- * What's really happening is that rip (a Sun-3 running Sun OS3.5)
- * is using the ttl from our arriving datagram as the ttl in its
- * icmp reply. So, the reply will time out on the return path
- * (with no notice sent to anyone since icmp's aren't sent for
- * icmp's) until we probe with a ttl that's at least twice the path
- * length. I.e., rip is really only 7 hops away. A reply that
- * returns with a ttl of 1 is a clue this problem exists.
- * Traceroute prints a "!" after the time if the ttl is <= 1.
- * Since vendors ship a lot of obsolete (DEC's Ultrix, Sun 3.x) or
- * non-standard (HPUX) software, expect to see this problem
- * frequently and/or take care picking the target host of your
- * probes.
- *
- * Other possible annotations after the time are !H, !N, !P (got a host,
- * network or protocol unreachable, respectively), !S or !F (source
- * route failed or fragmentation needed -- neither of these should
- * ever occur and the associated gateway is busted if you see one). If
- * almost all the probes result in some kind of unreachable, traceroute
- * will give up and exit.
- *
- * Notes
- * -----
- * This program must be run by root or be setuid. (I suggest that
- * you *don't* make it setuid -- casual use could result in a lot
- * of unnecessary traffic on our poor, congested nets.)
- *
- * This program requires a kernel mod that does not appear in any
- * system available from Berkeley: A raw ip socket using proto
- * IPPROTO_RAW must interpret the data sent as an ip datagram (as
- * opposed to data to be wrapped in a ip datagram). See the README
- * file that came with the source to this program for a description
- * of the mods I made to /sys/netinet/raw_ip.c. Your mileage may
- * vary. But, again, ANY 4.x (x < 4) BSD KERNEL WILL HAVE TO BE
- * MODIFIED TO RUN THIS PROGRAM.
- *
- * The udp port usage may appear bizarre (well, ok, it is bizarre).
- * The problem is that an icmp message only contains 8 bytes of
- * data from the original datagram. 8 bytes is the size of a udp
- * header so, if we want to associate replies with the original
- * datagram, the necessary information must be encoded into the
- * udp header (the ip id could be used but there's no way to
- * interlock with the kernel's assignment of ip id's and, anyway,
- * it would have taken a lot more kernel hacking to allow this
- * code to set the ip id). So, to allow two or more users to
- * use traceroute simultaneously, we use this task's pid as the
- * source port (the high bit is set to move the port number out
- * of the "likely" range). To keep track of which probe is being
- * replied to (so times and/or hop counts don't get confused by a
- * reply that was delayed in transit), we increment the destination
- * port number before each probe.
- *
- * Don't use this as a coding example. I was trying to find a
- * routing problem and this code sort-of popped out after 48 hours
- * without sleep. I was amazed it ever compiled, much less ran.
- *
- * I stole the idea for this program from Steve Deering. Since
- * the first release, I've learned that had I attended the right
- * IETF working group meetings, I also could have stolen it from Guy
- * Almes or Matt Mathis. I don't know (or care) who came up with
- * the idea first. I envy the originators' perspicacity and I'm
- * glad they didn't keep the idea a secret.
- *
- * Tim Seaver, Ken Adelman and C. Philip Wood provided bug fixes and/or
- * enhancements to the original distribution.
- *
- * I've hacked up a round-trip-route version of this that works by
- * sending a loose-source-routed udp datagram through the destination
- * back to yourself. Unfortunately, SO many gateways botch source
- * routing, the thing is almost worthless. Maybe one day...
- *
- * -- Van Jacobson
()
- * Tue Dec 20 03:50:13 PST 1988
- */
+* only knows what's going on with 12.
+*
+ * The silent gateway 12 in the above may be the result of a bug in
+* the 4.[23]BSD network code (and its derivatives): 4.x (x <= 3)
+ * sends an unreachable message using whatever ttl remains in the
+ * original datagram. Since, for gateways, the remaining ttl is
+ * zero, the icmp "time exceeded" is guaranteed to not make it back
+ * to us. The behavior of this bug is slightly more interesting
+ * when it appears on the destination system:
+ *
+ * 1 helios.ee.lbl.gov (128.3.112.1) 0 ms 0 ms 0 ms
+ * 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 19 ms 39 ms
+ * 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 19 ms 39 ms 19 ms
+ * 4 ccngw-ner-cc.Berkeley.EDU (128.32.136.23) 39 ms 40 ms 19 ms
+ * 5 ccn-nerif35.Berkeley.EDU (128.32.168.35) 39 ms 39 ms 39 ms
+ * 6 csgw.Berkeley.EDU (128.32.133.254) 39 ms 59 ms 39 ms
+ * 7 * * *
+ * 8 * * *
+ * 9 * * *
+ * 10 * * *
+ * 11 * * *
+ * 12 * * *
+ * 13 rip.Berkeley.EDU (128.32.131.22) 59 ms ! 39 ms ! 39 ms !
+ *
+ * Notice that there are 12 "gateways" (13 is the final
+ * destination) and exactly the last half of them are "missing".
+ * What's really happening is that rip (a Sun-3 running Sun OS3.5)
+ * is using the ttl from our arriving datagram as the ttl in its
+ * icmp reply. So, the reply will time out on the return path
+ * (with no notice sent to anyone since icmp's aren't sent for
+ * icmp's) until we probe with a ttl that's at least twice the path
+ * length. I.e., rip is really only 7 hops away. A reply that
+ * returns with a ttl of 1 is a clue this problem exists.
+ * Traceroute prints a "!" after the time if the ttl is <= 1.
+ * Since vendors ship a lot of obsolete (DEC's Ultrix, Sun 3.x) or
+ * non-standard (HPUX) software, expect to see this problem
+ * frequently and/or take care picking the target host of your
+ * probes.
+ *
+ * Other possible annotations after the time are !H, !N, !P (got a host,
+ * network or protocol unreachable, respectively), !S or !F (source
+ * route failed or fragmentation needed -- neither of these should
+ * ever occur and the associated gateway is busted if you see one). If
+ * almost all the probes result in some kind of unreachable, traceroute
+ * will give up and exit.
+ *
+ * Notes
+ * -----
+ * This program must be run by root or be setuid. (I suggest that
+ * you *don't* make it setuid -- casual use could result in a lot
+ * of unnecessary traffic on our poor, congested nets.)
+ *
+ * This program requires a kernel mod that does not appear in any
+ * system available from Berkeley: A raw ip socket using proto
+ * IPPROTO_RAW must interpret the data sent as an ip datagram (as
+ * opposed to data to be wrapped in a ip datagram). See the README
+ * file that came with the source to this program for a description
+ * of the mods I made to /sys/netinet/raw_ip.c. Your mileage may
+ * vary. But, again, ANY 4.x (x < 4) BSD KERNEL WILL HAVE TO BE
+ * MODIFIED TO RUN THIS PROGRAM.
+ *
+ * The udp port usage may appear bizarre (well, ok, it is bizarre).
+ * The problem is that an icmp message only contains 8 bytes of
+ * data from the original datagram. 8 bytes is the size of a udp
+ * header so, if we want to associate replies with the original
+ * datagram, the necessary information must be encoded into the
+ * udp header (the ip id could be used but there's no way to
+ * interlock with the kernel's assignment of ip id's and, anyway,
+ * it would have taken a lot more kernel hacking to allow this
+ * code to set the ip id). So, to allow two or more users to
+ * use traceroute simultaneously, we use this task's pid as the
+ * source port (the high bit is set to move the port number out
+ * of the "likely" range). To keep track of which probe is being
+ * replied to (so times and/or hop counts don't get confused by a
+ * reply that was delayed in transit), we increment the destination
+ * port number before each probe.
+ *
+ * Don't use this as a coding example. I was trying to find a
+ * routing problem and this code sort-of popped out after 48 hours
+ * without sleep. I was amazed it ever compiled, much less ran.
+ *
+ * I stole the idea for this program from Steve Deering. Since
+ * the first release, I've learned that had I attended the right
+ * IETF working group meetings, I also could have stolen it from Guy
+ * Almes or Matt Mathis. I don't know (or care) who came up with
+ * the idea first. I envy the originators' perspicacity and I'm
+ * glad they didn't keep the idea a secret.
+ *
+ * Tim Seaver, Ken Adelman and C. Philip Wood provided bug fixes and/or
+ * enhancements to the original distribution.
+ *
+ * I've hacked up a round-trip-route version of this that works by
+ * sending a loose-source-routed udp datagram through the destination
+ * back to yourself. Unfortunately, SO many gateways botch source
+ * routing, the thing is almost worthless. Maybe one day...
+ *
+ * -- Van Jacobson
()
+ * Tue Dec 20 03:50:13 PST 1988
+ */
#include <sys/param.h>
#include <sys/time.h>
@@ -292,34 +292,34 @@
#define Fprintf (void)fprintf
#define Printf (void)printf
-/* taken from linux/ipv6.h */
+ /* taken from linux/ipv6.h */
-/*
- * IPv6 fixed header
- *
- * BEWARE, it is incorrect. The first 4 bits of flow_lbl
- * are glued to priority now, forming "class".
- */
+ /*
+ * IPv6 fixed header
+ *
+ * BEWARE, it is incorrect. The first 4 bits of flow_lbl
+ * are glued to priority now, forming "class".
+ */
-struct ipv6hdr {
+ struct ipv6hdr {
#if defined(__LITTLE_ENDIAN_BITFIELD)
-__extension__ __u8 priority:4,
- version:4;
+ __extension__ __u8 priority:4,
+ version:4;
#elif defined(__BIG_ENDIAN_BITFIELD)
-__extension__ __u8 version:4,
- priority:4;
+ __extension__ __u8 version:4,
+ priority:4;
#else
#error "Please fix <asm/byteorder.h>"
#endif
-__extension__ __u8 flow_lbl[3];
+ __extension__ __u8 flow_lbl[3];
-__extension__ __u16 payload_len;
-__extension__ __u8 nexthdr;
-__extension__ __u8 hop_limit;
+ __extension__ __u16 payload_len;
+ __extension__ __u8 nexthdr;
+ __extension__ __u8 hop_limit;
- struct in6_addr saddr;
- struct in6_addr daddr;
-};
+ struct in6_addr saddr;
+ struct in6_addr daddr;
+ };
/* --- */
@@ -327,7 +327,7 @@
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 *);
+ struct timeval *);
void send_probe6(int seq, int ttl);
double deltaT (struct timeval *, struct timeval *);
void tvsub (struct timeval *, struct timeval *);
@@ -355,267 +355,267 @@
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
+ 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;
+ 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;
+ icmp_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+ socket_errno = errno;
- setuid(getuid());
+ setuid(getuid());
- on = 1;
- seq = tos = 0;
- to = (struct sockaddr_in6 *)&whereto;
- (void) bzero((char *)&whereto, sizeof(whereto));
+ 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);
+ 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;
+ 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;
+ ident = (getpid() & 0xffff) | 0x8000;
- sendbuff = malloc(datalen);
- if (sendbuff == NULL) {
- fprintf(stderr, "malloc failed\n");
- return;
- }
+ 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 (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 (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;
- }
+ 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 (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 (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 (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;
- }
+ 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;
+ 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;
+ /* 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;
+ 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;
+ 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_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;
- }
+ 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
+ int
wait_for_reply6(sock, from, reset_timer)
-int sock;
-struct sockaddr_in6 *from;
-int 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_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;
- }
+ 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);
- }
+ 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);
+ return(cc);
}
void send_probe6(int seq, int ttl)
{
- struct pkt_format *pkt = (struct pkt_format *) sendbuff;
- int i;
+ struct pkt_format *pkt = (struct pkt_format *) sendbuff;
+ int i;
- pkt->ident = htonl(ident);
- pkt->seq = htonl(seq);
- gettimeofday(&pkt->tv, &tz);
+ 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;
- }
+ 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);
+ 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");
- }
+ if (i < 0 || i != datalen) {
+ if (i<0)
+ perror("sendto");
+ }
}
/*
@@ -623,99 +623,99 @@
*/
char * pr_type(unsigned char t)
{
- static char *ttab1[] = {
- "Error",
- "Destination Unreachable",
- "Packet Too Big",
- "Time Exceeded in Transit",
- "Parameter Problem"
- };
+ 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",
- };
+ static char *ttab2[] = {
+ "Echo Reply",
+ "Echo Request",
+ "Membership Query",
+ "Membership Report",
+ "Membership Reduction",
+ };
- if (t < 5)
- {
- return (ttab1[t]);
- }
+ if (t < 5)
+ {
+ return (ttab1[t]);
+ }
- unsigned char newt = t - 128;
- if (newt < 5)
- {
- return (ttab2[newt]);
- }
+ unsigned char newt = t - 128;
+ if (newt < 5)
+ {
+ return (ttab2[newt]);
+ }
- return("OUT-OF-RANGE");
+ return("OUT-OF-RANGE");
}
int packet_ok6(u_char *buf, int cc, struct sockaddr_in6 *from, int seq,
- struct timeval *tv)
+ struct timeval *tv)
{
- struct icmp6hdr *icp;
- u_char type, code;
+ struct icmp6hdr *icp;
+ u_char type, code;
- icp = (struct icmp6hdr *) buf;
+ icp = (struct icmp6hdr *) buf;
- type = icp->icmp6_type;
- code = icp->icmp6_code;
+ 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;
+ 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;
+ 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;
+ if (nexthdr == 44) {
+ nexthdr = *(unsigned char*)up;
+ up++;
+ }
+ if (nexthdr == IPPROTO_UDP)
+ {
+ struct pkt_format *pkt;
- pkt = (struct pkt_format *) (up + 1);
+ 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 (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);
+ 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("\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);
+ 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++);
- }
+ for (i = sizeof(struct ipv6hdr); i < cc; i += 4)
+ Printf("%2d: x%8.8x\n", i, *lp++);
+ }
- return(0);
+ return(0);
}
#endif
=======================================
--- /trunk/src/usage.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/usage.c Thu Nov 15 13:33:19 2012
@@ -19,12 +19,12 @@
*/
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);
+ assert(prog != NULL);
+ assert(info != NULL);
+ printf("\n%s\n\n\n", info);
+ printf("Try `%s --help' for more information.\n", prog);
- exit(1);
+ exit(1);
}
/**
@@ -33,90 +33,90 @@
*/
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");
+ 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);
}
/**
@@ -125,34 +125,34 @@
*/
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");
- printf(" -u, --protolog_dir DIR - specify the base directory for protocol validation logs \n");
- printf(" --enableprotolog - enable protocol logging \n");
+ 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");
+ printf(" -u, --protolog_dir DIR - specify the base directory for protocol validation logs \n");
+ printf(" --enableprotolog - enable protocol logging \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);
}
/**
@@ -161,40 +161,40 @@
*/
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");
+ 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);
}
/**
@@ -203,18 +203,18 @@
*/
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");
+ 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);
+ exit(0);
}
/**
@@ -223,34 +223,34 @@
*/
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");
+ 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);
}
/**
@@ -259,26 +259,26 @@
*/
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");
+ 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);
+ exit(0);
}
/**
@@ -288,23 +288,23 @@
*/
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");
+ 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);
+ exit(0);
}
=======================================
--- /trunk/src/utils.c Tue Sep 25 06:49:57 2012
+++ /trunk/src/utils.c Thu Nov 15 13:33:19 2012
@@ -33,21 +33,21 @@
*/
int check_int(char* text, int* number) {
- char* znak;
- long tmp;
+ char* znak;
+ long tmp;
- assert(text != NULL);
- assert(number != NULL);
+ 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;
- }
+ 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;
+ }
}
/**
@@ -63,17 +63,17 @@
*/
int check_rint(char* text, int* number, int minVal, int maxVal) {
- int ret;
+ int ret;
- assert(maxVal >= minVal);
+ assert(maxVal >= minVal);
- if ((ret = check_int(text, number))) {
- return ret;
- }
- if ((*number < minVal) || (*number > maxVal)) {
- return 1;
- }
- return 0;
+ if ((ret = check_int(text, number))) {
+ return ret;
+ }
+ if ((*number < minVal) || (*number > maxVal)) {
+ return 1;
+ }
+ return 0;
}
/**
@@ -86,20 +86,20 @@
*/
int check_long(char* text, long* number) {
- char* tmp;
+ char* tmp;
- assert(text != NULL);
- assert(number != NULL);
+ 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;
- }
+ if (((*number = strtol(text, &tmp, 10)) == LONG_MAX)
+ || (*number == LONG_MIN)) {
+ return 1;
+ }
+ if ((*text != '\0') && (*tmp == '\0')) {
+ return 0;
+ } else {
+ return 2;
+ }
}
/**
@@ -108,9 +108,9 @@
*/
double secs() {
- struct timeval ru;
- gettimeofday(&ru, (struct timezone *) 0);
- return (ru.tv_sec + ((double) ru.tv_usec) / 1000000);
+ struct timeval ru;
+ gettimeofday(&ru, (struct timezone *) 0);
+ return (ru.tv_sec + ((double) ru.tv_usec) / 1000000);
}
/**
@@ -119,8 +119,8 @@
*/
void err_sys(char* s) {
- perror(s);
- /* return -1; */
+ perror(s);
+ /* return -1; */
}
/**
@@ -132,14 +132,14 @@
int sndq_len(int fd) {
#ifdef SIOCOUTQ
- int length = -1;
+ int length = -1;
- if (ioctl(fd, SIOCOUTQ, &length)) {
- return -1;
- }
- return length;
+ if (ioctl(fd, SIOCOUTQ, &length)) {
+ return -1;
+ }
+ return length;
#else
- return 0;
+ return 0;
#endif
}
@@ -149,18 +149,18 @@
*/
void mysleep(double time) {
- int rc;
- struct timeval tv;
- tv.tv_sec = (int) time;
- tv.tv_usec = (int) (time * 1000000) % 1000000;
+ 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;
- }
+ for (;;) {
+ rc = select(0, NULL, NULL, NULL, &tv);
+ if ((rc == -1) && (errno == EINTR))
+ continue;
+ if (rc == 0)
+ return;
+ }
}
/**
@@ -172,28 +172,27 @@
* @return strlen of output string
*/
int trim(char *line, int line_size,
- char * output_buf, int output_buf_size) {
- static char whitespacearr[4]= { '\n', ' ', '\t', '\r' };
+ char * output_buf, int output_buf_size) {
+ static char whitespacearr[4]= { '\n', ' ', '\t', '\r' };
- int i, j, k;
+ int i, j, k;
- for (i = j = 0; i < line_size && j < output_buf_size - 1; i++) {
- // find any matching characters among the quoted
- int is_whitespace = 0;
- for (k = 0; k < 4; k++) {
- if (line[i] == whitespacearr[k]) {
- is_whitespace = 1;
- break;
- }
- }
- if (!is_whitespace) {
- output_buf[j] = line[i];
- j++ ;
- }
- }
- output_buf[j] = '\0'; // null terminate
- //log_println(8,"Received=%s; len=%d; dest=%d; MSG=%s\n", line,
line_size,
- // strlen(output_buf), output_buf);
- return j - 1;
+ for (i = j = 0; i < line_size && j < output_buf_size - 1; i++) {
+ // find any matching characters among the quoted
+ int is_whitespace = 0;
+ for (k = 0; k < 4; k++) {
+ if (line[i] == whitespacearr[k]) {
+ is_whitespace = 1;
+ break;
+ }
+ }
+ if (!is_whitespace) {
+ output_buf[j] = line[i];
+ j++ ;
+ }
+ }
+ output_buf[j] = '\0'; // null terminate
+ //log_println(8,"Received=%s; len=%d; dest=%d; MSG=%s\n", line, line_size,
+ // strlen(output_buf), output_buf);
+ return j - 1;
}
-
=======================================
--- /trunk/src/viewtrace.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/viewtrace.c Thu Nov 15 13:33:19 2012
@@ -51,9 +51,9 @@
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,
+ '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 } };
+ 1, 0, 304 }, { "version", 0, 0, 'v' }, { 0, 0, 0, 0 }
};
/*
* Copy arg vector into a new buffer, concatenating arguments with spaces.
@@ -160,68 +160,68 @@
"%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
- ((cur->daddr >> 16) & 0xff), (cur->daddr >> 24), cur->dport);8) & 0xff),
+ 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 {
+ } 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
- ((cur->saddr >> 16) & 0xff), (cur->saddr8) & 0xff),
>> 24), cur->sport);
+ fprintf(stderr, "%u.%u.%u.%u:%d --> ", (cur->daddr & 0xFF), ((cur->daddr
+ ((cur->daddr >> 16) & 0xff), (cur->daddr >> 24),8) & 0xff),
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;
+ 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);
@@ -313,7 +313,7 @@
* and calculates the link speed between each packet pair. It then
* increments the proper link bin.
*/
-void
+ void
print_speed(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
{
struct ether_header *enet;
@@ -394,9 +394,9 @@
if (fwd.saddr == current.saddr) {
#endif
if (current.dport == c2sport)
- vt_calculate_spd(¤t, &fwd);
+ vt_calculate_spd(¤t,
&fwd);
else if (current.sport == s2cport)
- vt_calculate_spd(¤t, &fwd);
+ vt_calculate_spd(¤t,
&fwd);
}
#if defined(AF_INET6)
if (rev.saddr[0] == current.saddr[0]) {
@@ -404,9 +404,9 @@
if (rev.saddr == current.saddr) {
#endif
if (current.sport == c2sport)
- vt_calculate_spd(¤t,
&rev);
+
vt_calculate_spd(¤t, &rev);
else if (current.dport ==
s2cport)
- vt_calculate_spd(¤t,
&rev);
+
vt_calculate_spd(¤t, &rev);
}
#if defined(AF_INET6)
}
@@ -463,157 +463,157 @@
(fwd.saddr[2] ==
current.saddr[2]) &&
(fwd.saddr[3] ==
current.saddr[3])) {
if (current.dport == c2sport)
- vt_calculate_spd(¤t,
&fwd);
+
vt_calculate_spd(¤t, &fwd);
else if (current.sport ==
s2cport)
- vt_calculate_spd(¤t,
&fwd);
+
vt_calculate_spd(¤t, &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(¤t,
&rev);
+
vt_calculate_spd(¤t, &rev);
else if (current.dport ==
s2cport)
- vt_calculate_spd(¤t,
&rev);
+
vt_calculate_spd(¤t, &rev);
}
}
#endif
}
#endif
-int main(int argc, char **argv) {
+ int main(int argc, char **argv) {
- char *read_file, *cmdbuf, *device;
+ 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;
+ 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':
+ 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;
- }
- }
+ 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");
- }
+ if (optind < argc) {
+ short_usage(argv[0], "Unrecognized
non-option elements");
+ }
- log_init(argv[0], debug);
+ log_init(argv[0], debug);
#ifdef HAVE_LIBPCAP
- init_vars(&fwd);
- init_vars(&rev);
+ 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);
+ 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);
- }
- }
+ }
+ 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]);
+ 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_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);
- }
+ 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);
+ 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);
#else
- log_println(
- 0,
- "\n!!! In order to use viewtrace utility you have to compile it with the pcap library !!!\n");
+ log_println(
+ 0,
+ "\n!!! In order to use viewtrace utility you have to compile it with the pcap library !!!\n");
#endif
- return 0;
-}
+ return 0;
+ }
=======================================
--- /trunk/src/web100-admin.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/web100-admin.c Thu Nov 15 13:33:19 2012
@@ -62,272 +62,272 @@
* @return count of variable values read
*/
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 c2s_linkspeed_data, int s2c_linkspeed_ack, int view_flag)
{
+ 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 c2s_linkspeed_data, int s2c_linkspeed_ack, int view_flag) {
- int congestion2 = 0, i;
- static int totalcnt;
- double rttsec;
- double rwintime=0, cwndtime=0, sendtime=0;
- int totaltime=0;
- char view_string[256], *str, tmpstr[32];
- FILE * fp;
+ int congestion2 = 0, i;
+ static int totalcnt;
+ double rttsec;
+ double rwintime=0, cwndtime=0, sendtime=0;
+ int totaltime=0;
+ char view_string[256], *str, tmpstr[32];
+ FILE * fp;
- if (view_flag == 1) {
- fp = fopen("/tmp/view.string", "r");
- fgets(view_string, 256, fp);
- log_println(3, "View_string=%s", view_string);
- str = view_string;
- sscanf(str, "%[^,]s", tmpstr);
- maxc2sspd = atoi(tmpstr);
+ if (view_flag == 1) {
+ fp = fopen("/tmp/view.string", "r");
+ fgets(view_string, 256, fp);
+ log_println(3, "View_string=%s", view_string);
+ 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);
+ minc2sspd = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- maxs2cspd = 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);
+ mins2cspd = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- totalcnt = 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);
+ totmismatch = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- totbad_cable = 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[0] = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- count[1] = 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[2] = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- count[3] = 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[4] = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- count[5] = 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[6] = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- count[7] = 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[8] = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- count[9] = 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[10] = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- count[11] = 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[12] = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- count[13] = 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[14] = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- count[15] = atoi(tmpstr);
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ count[15] = atoi(tmpstr);
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- strlcpy(maxdate, tmpstr, sizeof(maxdate));
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ strlcpy(maxdate, tmpstr, sizeof(maxdate));
- str = strchr(str, ',') + 1;
- sscanf(str, "%[^,]s", tmpstr);
- strlcpy(mindate, tmpstr, sizeof(mindate));
+ str = strchr(str, ',') + 1;
+ sscanf(str, "%[^,]s", tmpstr);
+ strlcpy(mindate, tmpstr, sizeof(mindate));
- for (i = 0; i < strlen(mindate); i++)
- if (mindate[i] == '\n')
- break;
- mindate[i] = '\0';
+ 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);
+ log_println(1, "Updating admin_view variables: Total count = %d",
+ totalcnt);
- fclose(fp);
- }
+ fclose(fp);
+ }
- // print details about bottleneck link's speed
- switch (c2s_linkspeed_data) {
- case DATA_RATE_INSUFFICIENT_DATA:
- snprintf(btlneck, sizeof(btlneck), "Insufficent Data");
- break;
- case DATA_RATE_SYSTEM_FAULT:
- snprintf(btlneck, sizeof(btlneck), "System Fault");
- break;
- case DATA_RATE_RTT:
- snprintf(btlneck, sizeof(btlneck), "Round Trip Time");
- break;
- case DATA_RATE_DIAL_UP:
- snprintf(btlneck, sizeof(btlneck), "Dial-up modem");
- break;
- case DATA_RATE_T1:
- if (((float) c2sspd / (float) s2cspd > .8)
- && ((float) c2sspd / (float) s2cspd < 1.2) &&
(c2sspd > 1000))
- snprintf(btlneck, sizeof(btlneck), "T1 subnet");
- else {
- if (s2c_linkspeed_ack == 3)
- snprintf(btlneck, sizeof(btlneck), "Cable
Modem");
- else
- snprintf(btlneck, sizeof(btlneck), "DSL");
- }
- break;
- case DATA_RATE_ETHERNET:
- snprintf(btlneck, sizeof(btlneck), "Ethernet");
- break;
- case DATA_RATE_T3:
- snprintf(btlneck, sizeof(btlneck), "T3/DS-3");
- break;
- case DATA_RATE_FAST_ETHERNET:
- snprintf(btlneck, sizeof(btlneck), "FastEthernet");
- break;
- case DATA_RATE_OC_12:
- snprintf(btlneck, sizeof(btlneck), "OC-12");
- break;
- case DATA_RATE_GIGABIT_ETHERNET:
- snprintf(btlneck, sizeof(btlneck), "Gigabit Ethernet");
- break;
- case DATA_RATE_OC_48:
- snprintf(btlneck, sizeof(btlneck), "OC-48");
- break;
- case DATA_RATE_10G_ETHERNET:
- snprintf(btlneck, sizeof(btlneck), "10 Gigabit Enet");
- break;
- case DATA_RATE_RETRANSMISSIONS:
- snprintf(btlneck, sizeof(btlneck), "Retransmissions");
- }
+ // print details about bottleneck link's speed
+ switch (c2s_linkspeed_data) {
+ case DATA_RATE_INSUFFICIENT_DATA:
+ snprintf(btlneck, sizeof(btlneck), "Insufficent Data");
+ break;
+ case DATA_RATE_SYSTEM_FAULT:
+ snprintf(btlneck, sizeof(btlneck), "System Fault");
+ break;
+ case DATA_RATE_RTT:
+ snprintf(btlneck, sizeof(btlneck), "Round Trip Time");
+ break;
+ case DATA_RATE_DIAL_UP:
+ snprintf(btlneck, sizeof(btlneck), "Dial-up modem");
+ break;
+ case DATA_RATE_T1:
+ if (((float) c2sspd / (float) s2cspd > .8)
+ && ((float) c2sspd / (float) s2cspd < 1.2) && (c2sspd > 1000))
+ snprintf(btlneck, sizeof(btlneck), "T1 subnet");
+ else {
+ if (s2c_linkspeed_ack == 3)
+ snprintf(btlneck, sizeof(btlneck), "Cable Modem");
+ else
+ snprintf(btlneck, sizeof(btlneck), "DSL");
+ }
+ break;
+ case DATA_RATE_ETHERNET:
+ snprintf(btlneck, sizeof(btlneck), "Ethernet");
+ break;
+ case DATA_RATE_T3:
+ snprintf(btlneck, sizeof(btlneck), "T3/DS-3");
+ break;
+ case DATA_RATE_FAST_ETHERNET:
+ snprintf(btlneck, sizeof(btlneck), "FastEthernet");
+ break;
+ case DATA_RATE_OC_12:
+ snprintf(btlneck, sizeof(btlneck), "OC-12");
+ break;
+ case DATA_RATE_GIGABIT_ETHERNET:
+ snprintf(btlneck, sizeof(btlneck), "Gigabit Ethernet");
+ break;
+ case DATA_RATE_OC_48:
+ snprintf(btlneck, sizeof(btlneck), "OC-48");
+ break;
+ case DATA_RATE_10G_ETHERNET:
+ snprintf(btlneck, sizeof(btlneck), "10 Gigabit Enet");
+ break;
+ case DATA_RATE_RETRANSMISSIONS:
+ snprintf(btlneck, sizeof(btlneck), "Retransmissions");
+ }
- /* Calculate some values */
- strlcpy(date, now, sizeof(date));
- // Calculate average round trip time and convert to seconds
- rttsec = calc_avg_rtt(SumRTT, CountRTT, &avgrtt);
- loss2 = (double) CongestionSignals / PktsOut;
- if (loss2 == 0)
- loss2 = .000001; /* set to 10^-6 for now */
+ /* Calculate some values */
+ strlcpy(date, now, sizeof(date));
+ // Calculate average round trip time and convert to seconds
+ rttsec = calc_avg_rtt(SumRTT, CountRTT, &avgrtt);
+ loss2 = (double) CongestionSignals / PktsOut;
+ if (loss2 == 0)
+ loss2 = .000001; /* set to 10^-6 for now */
- oo_order = calc_packets_outoforder(DupAcksIn, AckPktsIn);
+ oo_order = calc_packets_outoforder(DupAcksIn, AckPktsIn);
- bw_theortcl = calc_max_theoretical_throughput(CurrentMSS, rttsec,
loss2);
+ bw_theortcl = calc_max_theoretical_throughput(CurrentMSS, rttsec, loss2);
- totaltime = calc_totaltesttime(SndLimTimeRwin, SndLimTimeCwnd,
- SndLimTimeSender);
- log_println(3, "totaltime=%d, sndLim %d", totaltime, SndLimTimeRwin);
- // time spent being send-limited due to client's recv window
- rwintime = calc_sendlimited_rcvrfault(SndLimTimeRwin, totaltime);
- log_println(3, "rwintime=%f", rwintime);
+ totaltime = calc_totaltesttime(SndLimTimeRwin, SndLimTimeCwnd,
+ SndLimTimeSender);
+ log_println(3, "totaltime=%d, sndLim %d", totaltime, SndLimTimeRwin);
+ // time spent being send-limited due to client's recv window
+ rwintime = calc_sendlimited_rcvrfault(SndLimTimeRwin, totaltime);
+ log_println(3, "rwintime=%f", rwintime);
- log_println(3, "before calling cwndtime cal. %d,%d", SndLimTimeCwnd, totaltime);
- // time spent in being send-limited due to congestion window
- cwndtime = calc_sendlimited_cong(SndLimTimeCwnd, totaltime);
- log_println(3, "cwndtime=%f", cwndtime);
- // time spent in being send-limited due to own fault
- sendtime = calc_sendlimited_sndrfault(SndLimTimeSender, totaltime);
- timesec = totaltime / MEGA; // total time in microsecs
+ log_println(3, "before calling cwndtime cal. %d,%d", SndLimTimeCwnd, totaltime);
+ // time spent in being send-limited due to congestion window
+ cwndtime = calc_sendlimited_cong(SndLimTimeCwnd, totaltime);
+ log_println(3, "cwndtime=%f", cwndtime);
+ // time spent in being send-limited due to own fault
+ sendtime = calc_sendlimited_sndrfault(SndLimTimeSender, totaltime);
+ timesec = totaltime / MEGA; // total time in microsecs
- // calculate receive buffer delay, send buffer delay and congestion window delays
- recvbwd = ((MaxRwinRcvd * 8) / avgrtt) / 1000;
- cwndbwd = ((CurrentCwnd * 8) / avgrtt) / 1000;
- sendbwd = ((Sndbuf * 8) / avgrtt) / 1000;
+ // calculate receive buffer delay, send buffer delay and congestion window delays
+ recvbwd = ((MaxRwinRcvd * 8) / avgrtt) / 1000;
+ cwndbwd = ((CurrentCwnd * 8) / avgrtt) / 1000;
+ sendbwd = ((Sndbuf * 8) / avgrtt) / 1000;
- // this is different from congestion window heuristic, but seems
unused
- if ((cwndtime > .02) && (mismatch == 0) && (cwndbwd < recvbwd))
- congestion2 = 1;
+ // this is different from congestion window heuristic, but seems unused
+ if ((cwndtime > .02) && (mismatch == 0) && (cwndbwd < recvbwd))
+ congestion2 = 1;
- // if no web100 variables were read from the file, then assign values
- if (totalcnt == 0) {
- minc2sspd = c2sspd;
- mins2cspd = s2cspd;
- maxc2sspd = c2sspd;
- maxs2cspd = s2cspd;
- strlcpy(startdate, date, sizeof(startdate));
- strlcpy(maxdate, date, sizeof(maxdate));
- strlcpy(mindate, date, sizeof(mindate));
- }
+ // if no web100 variables were read from the file, then assign values
+ if (totalcnt == 0) {
+ minc2sspd = c2sspd;
+ mins2cspd = s2cspd;
+ maxc2sspd = c2sspd;
+ maxs2cspd = s2cspd;
+ strlcpy(startdate, date, sizeof(startdate));
+ strlcpy(maxdate, date, sizeof(maxdate));
+ strlcpy(mindate, date, sizeof(mindate));
+ }
- // assign max/min values of speeds based on real read values
- if (c2sspd > maxc2sspd) {
- maxc2sspd = c2sspd;
- strlcpy(maxdate, date, sizeof(maxdate));
- }
- if (s2cspd > maxs2cspd) {
- maxs2cspd = s2cspd;
- strlcpy(maxdate, date, sizeof(maxdate));
- }
- if (c2sspd < minc2sspd) {
- minc2sspd = c2sspd;
- strlcpy(mindate, date, sizeof(mindate));
+ // assign max/min values of speeds based on real read values
+ if (c2sspd > maxc2sspd) {
+ maxc2sspd = c2sspd;
+ strlcpy(maxdate, date, sizeof(maxdate));
+ }
+ if (s2cspd > maxs2cspd) {
+ maxs2cspd = s2cspd;
+ strlcpy(maxdate, date, sizeof(maxdate));
+ }
+ if (c2sspd < minc2sspd) {
+ minc2sspd = c2sspd;
+ strlcpy(mindate, date, sizeof(mindate));
- }
- if (s2cspd < mins2cspd) {
- mins2cspd = s2cspd;
- strlcpy(mindate, date, sizeof(mindate));
- }
+ }
+ if (s2cspd < mins2cspd) {
+ mins2cspd = s2cspd;
+ 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[c2s_linkspeed_data + 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);
+ log_println(
+ 1,
+ "Initial counter Values Totalcnt = %d, Total Mismatch = %d, Total Bad Cables = %d",
+ totalcnt, totmismatch, totbad_cable);
+ totalcnt++;
+ count[c2s_linkspeed_data + 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);
}
/**
@@ -348,224 +348,224 @@
* @param refresh time in seconds after which to refresh page
*/
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;
+ 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");
+ 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 (bw_theortcl > 1)
- fprintf(fp, " <td align=right>%0.2f Mbps\n", bw_theortcl);
- else
- fprintf(fp, " <td align=right>%0.2f kbps\n", bw_theortcl *
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");
+ /* 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 (bw_theortcl > 1)
+ fprintf(fp, " <td align=right>%0.2f Mbps\n", bw_theortcl);
+ else
+ fprintf(fp, " <td align=right>%0.2f kbps\n", bw_theortcl * 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");
+ 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);
+ /* 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,
+ " <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;
+ 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");
+ 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);
- snprintf(tmpstr, sizeof(tmpstr), "/bin/cat %s/admin_description.html
- AdminFileName);%s", BASEDIR,
- system(tmpstr);
+ /* 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);
+ snprintf(tmpstr, sizeof(tmpstr), "/bin/cat %s/admin_description.html
+ AdminFileName);%s", BASEDIR,
+ 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(fileno(fp), F_SETLKW, lock);
- log_println(1, "successfully locked '/tmp/view.string' for updating");
- snprintf(
- view_string, sizeof(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(fileno(fp), F_SETLK, lock);
- fclose(fp);
+ /* 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(fileno(fp), F_SETLKW, lock);
+ log_println(1, "successfully locked '/tmp/view.string' for updating");
+ snprintf(
+ view_string, sizeof(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(fileno(fp), F_SETLK, lock);
+ fclose(fp);
}
/**
@@ -574,215 +574,215 @@
* @param refresh time in seconds after which to refresh page
*/
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;
- // commenting out lines above to assign values
- int CurrentCwnd = 0, SndLimTimeRwin=0, SndLimTimeCwnd=0, SndLimTimeSender=0,
- DataBytesOut=0;
+ 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;
+ // commenting out lines above to assign values
+ int CurrentCwnd = 0, SndLimTimeRwin=0, SndLimTimeCwnd=0, SndLimTimeSender=0,
+ DataBytesOut=0;
- 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 c2s_linkspeed_data = 0, c2s_linkspeed_ack, s2c_linkspeed_data,
- s2c_linkspeed_ack = 0;
- int totalcnt = 0, view_flag = 0;
+ 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 c2s_linkspeed_data = 0, c2s_linkspeed_ack, s2c_linkspeed_data,
+ s2c_linkspeed_ack = 0;
+ int totalcnt = 0, view_flag = 0;
- if ((fp = fopen(get_logfile(), "r")) == NULL)
- return;
+ if ((fp = fopen(get_logfile(), "r")) == NULL)
+ return;
- while ((fgets(buff, 512, fp)) != NULL) {
- log_println(3,"Reading line: %s",buff);
- 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);
+ while ((fgets(buff, 512, fp)) != NULL) {
+ log_println(3,"Reading line: %s",buff);
+ 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 */
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/src/web100-pcap.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/web100-pcap.c Thu Nov 15 13:33:19 2012
@@ -38,55 +38,55 @@
*
*/
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];
+ /* pcap_addr_t *ifaceAddr; */
+ pcap_if_t *alldevs, *dp;
+ struct ethtool_cmd ecmd;
+ int fd, cnt, i, err;
+ struct ifreq ifr;
+ char errbuf[256];
- 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));
- }
- }
- // Ethernet related speeds alone "specifically" determined.
- // Note that it appears that NDT assumes its an ethernet link. But, if ifspeed is not assigned,
- // a value will be assigned to it in the "calc_linkspeed" method which will still
- // cause all speed-bins to be looked into (i.e correct results
expected).
- 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] = DATA_RATE_ETHERNET;
- break;
- case SPEED_100:
- iflist.speed[i] = DATA_RATE_FAST_ETHERNET;
- break;
- case SPEED_1000:
- iflist.speed[i] = DATA_RATE_GIGABIT_ETHERNET;
- break;
- case SPEED_10000:
- iflist.speed[i] = DATA_RATE_10G_ETHERNET;
- break;
- default:
- iflist.speed[i] = DATA_RATE_RTT;
- }
- }
- }
- // free list allocated by pcap_findalldevs call
- if (alldevs != NULL)
- pcap_freealldevs(alldevs);
+ 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));
+ }
+ }
+ // Ethernet related speeds alone "specifically" determined.
+ // Note that it appears that NDT assumes its an ethernet link. But, if ifspeed is not assigned,
+ // a value will be assigned to it in the "calc_linkspeed" method which will still
+ // cause all speed-bins to be looked into (i.e correct results expected).
+ 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] = DATA_RATE_ETHERNET;
+ break;
+ case SPEED_100:
+ iflist.speed[i] = DATA_RATE_FAST_ETHERNET;
+ break;
+ case SPEED_1000:
+ iflist.speed[i] = DATA_RATE_GIGABIT_ETHERNET;
+ break;
+ case SPEED_10000:
+ iflist.speed[i] = DATA_RATE_10G_ETHERNET;
+ break;
+ default:
+ iflist.speed[i] = DATA_RATE_RTT;
+ }
+ }
+ }
+ // free list allocated by pcap_findalldevs call
+ if (alldevs != NULL)
+ pcap_freealldevs(alldevs);
}
/** Check signal flags and process them accordingly.
@@ -97,99 +97,99 @@
* 0 if no relevant signals were actually received
*/
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) {
+ 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_breakloop(pd);
- }
- if (dumptrace == 1)
- pcap_dump_close(pdump);
- sig1 = 2;
- }
+ }
+ 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_breakloop(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) {
+ 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_breakloop(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_breakloop(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;
}
/**
@@ -198,29 +198,29 @@
* */
void init_vars(struct spdpair *cur) {
- int i;
+ int i;
- assert(cur);
+ assert(cur);
#if defined(AF_INET6)
- memset(cur->saddr, 0, 4);
- memset(cur->daddr, 0, 4);
+ 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;
}
/**
@@ -231,197 +231,197 @@
* */
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;
- int j;
+ int i, total = 0, max = 0, s, index = -1;
+ char buff[256];
+ int tzoffset = 6;
+ 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;
- fp = fopen(get_logfile(), "a");
- log_print(1, "%02d:%02d:%02d.%06u ", s / 3600, (s % 3600) / 60, s %
60,
- cur->st_usec);
+ /* 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;
+ fp = fopen(get_logfile(), "a");
+ log_print(1, "%02d:%02d:%02d.%06u ", s / 3600, (s % 3600) / 60, s % 60,
+ cur->st_usec);
- // Get the ifspeed bin with the biggest counter value.
- // NDT determines link speed using this
- for (i = 0; i < 16; i++) {
- total += cur->links[i];
- if (cur->links[i] > max) {
- max = cur->links[i];
- }
- }
- if (get_debuglvl() > 2) {
+ // Get the ifspeed bin with the biggest counter value.
+ // NDT determines link speed using this
+ 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]
- ((cur->daddr[0] >> 16) & 0xff), (cur->daddr[0]8) & 0xff),
>> 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),
- ((cur->daddr >> 16) & 0xff), (cur->daddr >> 24), cur->dport);
+ 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
- ((cur->saddr >> 16) & 0xff), (cur->saddr8) & 0xff),
>> 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
+ ((cur->saddr >> 16) & 0xff), (cur->saddr >> 24), cur->sport);8) & 0xff),
+ 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 speed is 0, then indicate that no data has been collected
- 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 max speed is 0, then indicate that no data has been collected
+ 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];
+ }
+ }
+ }
- // print details of link speed found
- 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;
- }
+ // print details of link speed found
+ 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;
+ }
- // now print values of speeds for various bins found
- 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);
- }
+ // now print values of speeds for various bins found
+ 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);
+ }
- // make speed bin available to other processes
- snprintf(buff,
- sizeof(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);
+ // make speed bin available to other processes
+ snprintf(buff,
+ sizeof(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);
}
/**
@@ -436,87 +436,87 @@
* @param portB Expected source port
*/
void calculate_spd(struct spdpair *cur, struct spdpair *cur2, int portA,
- int portB) {
+ int portB) {
- float bits = 0, spd = 0, time = 0;
+ float bits = 0, spd = 0, time = 0;
- assert(cur);
- assert(cur2);
+ assert(cur);
+ assert(cur2);
- time = (((cur->sec - cur2->sec) * 1000000) + (cur->usec -
cur2->usec));
- /* time = curt->time - cur2->time; */
- // if ports are as anticipated, use sequence number to calculate no of bits exchanged
- 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 { // use acknowledgement details to calculate number of bits exchanged
- 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++;
- }
- // get throughput
-log_println(8, "0BITS=%f, time=%f, SPD=%f", bits, time, spd);
- spd = (bits / time); /* convert to mbits/sec) */
-log_println(8, "1BITS=%f, time=%f, SPD=%f", bits, time, spd);
- // increment speed bin based on throughput range
- 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;
-log_println(8, "BITS=%f, time=%f, SPD=%f", bits, time, spd);
- if ((time > 10) && (spd > 0)) {
-log_println(8, ">10 : totalcount=%f, spd=%f, cur2->totalcount=%d", cur2->totalspd2, spd, cur2->totalcount);
- cur2->totalspd += spd;
- cur2->totalcount++;
- cur2->totalspd2 = (cur2->totalspd2 + spd) / 2;
- }
- // debug
-//
-//else {
-// log_println(0, "ELSE totalspd2=%f, spd=%f, cur2->totalcount=%d", cur2->totalspd2, spd, cur2->totalcount);
-//}
+ time = (((cur->sec - cur2->sec) * 1000000) + (cur->usec - cur2->usec));
+ /* time = curt->time - cur2->time; */
+ // if ports are as anticipated, use sequence number to calculate no of bits exchanged
+ 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 { // use acknowledgement details to calculate number of bits exchanged
+ 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++;
+ }
+ // get throughput
+ log_println(8, "0BITS=%f, time=%f, SPD=%f", bits, time, spd);
+ spd = (bits / time); /* convert to mbits/sec) */
+ log_println(8, "1BITS=%f, time=%f, SPD=%f", bits, time, spd);
+ // increment speed bin based on throughput range
+ 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;
+ log_println(8, "BITS=%f, time=%f, SPD=%f", bits, time, spd);
+ if ((time > 10) && (spd > 0)) {
+ log_println(8, ">10 : totalcount=%f, spd=%f, cur2->totalcount=%d", cur2->totalspd2, spd, cur2->totalcount);
+ cur2->totalspd += spd;
+ cur2->totalcount++;
+ cur2->totalspd2 = (cur2->totalspd2 + spd) / 2;
+ }
+ // debug
+ //
+ //else {
+ // log_println(0, "ELSE totalspd2=%f, spd=%f, cur2->totalcount=%d", cur2->totalspd2, spd, cur2->totalcount);
+ //}
-log_println(8, "totalspd2 in the end=%f, spd=%f", cur2->totalspd2,spd);
+ log_println(8, "totalspd2 in the end=%f, spd=%f", cur2->totalspd2,spd);
}
/**
@@ -532,534 +532,534 @@
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;
+ 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;
+ const struct tcphdr *tcp;
+ struct spdpair current;
+ int port2 = pair->port1;
+ int port4 = pair->port2;
- assert(user);
+ assert(user);
- if (dumptrace == 1)
- pcap_dump((u_char *) pdump, h, p);
+ 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 (pd == NULL) {
+ fprintf(
+ stderr,
+ "!#!#!#!# Error, trying to process IF data, but pcap fd closed\n");
+ return;
+ }
- if (check_signal_flags()) {
- 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;
+ 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 */
+ enet = (struct ether_header *) p;
+ p += sizeof(struct ether_header); /* move packet pointer past ethernet fields */
- ip = (const struct ip *) p;
+ 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);
+ 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.
- */
+ /* 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;
+ 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;
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/src/web100-util.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/web100-util.c Thu Nov 15 13:33:19 2012
@@ -26,33 +26,33 @@
*/
int web100_init(char *VarFileName) {
- FILE * fp;
- char line[256], trimmedline[256];
- int count_vars = 0;
+ FILE * fp;
+ char line[256], trimmedline[256];
+ int count_vars = 0;
- assert(VarFileName);
+ 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);
- }
+ 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
+ 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
- trim(line, strlen(line), trimmedline, sizeof(trimmedline)); // remove unwanted
- // chars (right now, trailing/preceding
chars from wb100 var names)
- strlcpy(web_vars[count_vars].name, trimmedline,
- sizeof(web_vars[count_vars].name));
- count_vars++;
- }
- fclose(fp);
- log_println(1, "web100_init() read %d variables from file",
count_vars);
+ trim(line, strlen(line), trimmedline, sizeof(trimmedline)); // remove unwanted
+ // chars (right now, trailing/preceding chars from wb100 var names)
+ strlcpy(web_vars[count_vars].name, trimmedline,
+ 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);
+ return (count_vars);
}
/**
@@ -74,166 +74,166 @@
*
*/
void web100_middlebox(int sock, web100_agent* agent, web100_connection* cn,
- char *results, size_t results_strlen) {
+ char *results, size_t results_strlen) {
- 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;
+ 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",
};
+ // middlebox test results
+ static char vars[][255] = { "CurMSS", "WinScaleSent", "WinScaleRecv", };
- assert(results);
+ assert(results);
- log_println(4, "Looking for Web100 data on socketid %d", sock);
+ log_println(4, "Looking for Web100 data on socketid %d", sock);
- // get Server address and add to "results"
+ // 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"
- snprintf(line, sizeof(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, results_strlen);
- I2AddrFree(addr); // free memory
+ // 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"
+ snprintf(line, sizeof(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, results_strlen);
+ 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);
- snprintf(line, sizeof(line), "%s;", tmpstr);
- I2AddrServName(addr, tmpstr, &tmpstrlen);
- log_print(3, "Client: %s%s ", line, tmpstr);
- strlcat(results, line, results_strlen);
- I2AddrFree(addr);
+ // 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);
+ snprintf(line, sizeof(line), "%s;", tmpstr);
+ I2AddrServName(addr, tmpstr, &tmpstrlen);
+ log_print(3, "Client: %s%s ", line, tmpstr);
+ strlcat(results, line, results_strlen);
+ 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 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 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));
- snprintf(line, sizeof(line), "%s;",
-
web100_value_to_text(web100_get_var_type(var), buff));
- if (strcmp(line, "4294967295;") == 0)
- snprintf(line, sizeof(line), "%d;", -1);
+ //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));
+ snprintf(line, sizeof(line), "%s;",
+ web100_value_to_text(web100_get_var_type(var), buff));
+ if (strcmp(line, "4294967295;") == 0)
+ snprintf(line, sizeof(line), "%d;", -1);
- //strlcat(results, line, sizeof(results));
- strlcat(results, line, results_strlen);
- log_print(3, "%s", line);
- }
- log_println(3, "");
- log_println(0, "Sending %d Byte packets over the network, and data=%s", currentMSSval, line);
+ //strlcat(results, line, sizeof(results));
+ strlcat(results, line, results_strlen);
+ log_print(3, "%s", line);
+ }
+ log_println(3, "");
+ log_println(0, "Sending %d Byte packets over the network, and data=%s", currentMSSval, line);
- /* 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
- */
+ /* 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);
+ // 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);
+ // 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");
- }
+ // 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
+ // 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);
- }
+ 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);
+ // 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;
+ 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);
+ 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));
+ // 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;
- }
+ // 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); */
+ // 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); */
}
/**
@@ -246,68 +246,68 @@
*
*/
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;
+ 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);
- snprintf(line, sizeof(line), "%s;", web100_value_to_text(web100_get_var_type(var), buf));
- // write remote address to log file
- if (fp)
- fprintf(fp, "%s", line);
+ // 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);
+ snprintf(line, sizeof(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;
+ ok = 1;
- // get values for other web100 variables and write to the log file
+ // 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;
- }
+ 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 (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) {
- snprintf(web_vars[i].value, sizeof(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;
- }
+ if ((web100_raw_read(var, cn, buf)) != WEB100_ERR_SUCCESS) {
+ if (get_debuglvl() > 9)
+ web100_perror("web100_raw_read()");
+ continue;
+ }
+ if (ok == 1) {
+ snprintf(web_vars[i].value, sizeof(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);
- }
+ // close file pointers after web100 variables have been fetched
+ if (fp) {
+ fprintf(fp, "\n");
+ fclose(fp);
+ }
}
@@ -323,51 +323,51 @@
*
*/
int web100_get_data(web100_snapshot* snap, int ctlsock, web100_agent* agent,
- int count_vars) {
+ int count_vars) {
- int i;
- web100_var* var;
- char buf[32], line[256];
- web100_group* group;
+ int i;
+ web100_var* var;
+ char buf[32], line[256];
+ web100_group* group;
- assert(snap);
- assert(agent);
+ assert(snap);
+ assert(agent);
- 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;
- }
+ 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);
- }
+ // 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;
- }
+ // 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
- snprintf(web_vars[i].value, sizeof(web_vars[i].value), "%s",
-
web100_value_to_text(web100_get_var_type(var), buf));
- snprintf(line, sizeof(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);
+ // assign values and transmit message with all web100 variables to socket receiver end
+ snprintf(web_vars[i].value, sizeof(web_vars[i].value), "%s",
+ web100_value_to_text(web100_get_var_type(var), buf));
+ snprintf(line, sizeof(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);
}
@@ -390,30 +390,30 @@
*
*/
int web100_rtt(int sock, web100_agent* agent, web100_connection* cn) {
- web100_var* var;
- char buf[32];
- web100_group* group;
- double count, sum;
+ web100_var* var;
+ char buf[32];
+ web100_group* group;
+ double count, sum;
- if (cn == NULL)
- return (-10);
+ 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, "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);
+ 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);
}
/**
@@ -434,46 +434,46 @@
*/
int web100_autotune(int sock, web100_agent* agent, web100_connection* cn) {
- web100_var* var;
- char buf[32];
- web100_group* group;
- int i, j = 0;
+ web100_var* var;
+ char buf[32];
+ web100_group* group;
+ int i, j = 0;
- if (cn == NULL)
- return (10);
+ 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));
+ 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 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));
+ /* 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);
+ if (i == 0)
+ j |= 0x02;
+ return (j);
}
/**
@@ -500,68 +500,68 @@
*
*/
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;
+ int autotune) {
+ web100_var* var;
+ char buf[32];
+ web100_group* group;
+ int buff;
+ int sScale, rScale;
- if (cn == NULL)
- return (10);
+ 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 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;
+ // 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 ((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);
- }
- }
- }
+ 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);
+ return (0);
}
/**
@@ -572,101 +572,101 @@
*
*/
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;
+ 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);
- }
+ 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)
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/src/web100clt.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/web100clt.c Thu Nov 15 13:33:19 2012
@@ -45,17 +45,17 @@
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 },
- {
"protocol_log", 1, 0, 'u' },
- {
"enableprotolog", 0, 0, 'e' },
+ '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 },
+ { "protocol_log", 1, 0, 'u' },
+ { "enableprotolog", 0, 0, 'e' },
#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);
@@ -70,24 +70,24 @@
* @param tmpstr Char array containing key-value pairs
* */
void printVariables(char *tmpstr) {
- int i, j, k;
- char sysvar[128], sysval[128];
+ 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;
- }
+ 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;
+ }
}
/**
@@ -99,13 +99,13 @@
*/
void printWeb100VarInfo() {
- int i = 0;
- printf(" --- Detailed description of the Web100 variables ---\n\n");
+ 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;
- }
+ while (web100vartable[i][0]) {
+ printf("* %s\n %s\n", web100vartable[i][0], web100vartable[i][1]);
+ ++i;
+ }
}
/**
@@ -118,120 +118,120 @@
* @param host server host name string
*/
void testResults(char tests, char *testresult_str, char* host) {
- int i = 0;
+ int i = 0;
- char *sysvar, *sysval;
- float j;
+ char *sysvar, *sysval;
+ float j;
- // If the S2C test was not performed, just interpret the C2S and SFW test results
- if (!(tests & TEST_S2C)) {
- if (tests & TEST_C2S) { // Was C2S test performed?
- check_C2Spacketqueuing(c2sspd, spdout, sndqueue,
pkts, lth);
- }
+ // If the S2C test was not performed, just interpret the C2S and SFW test results
+ if (!(tests & TEST_S2C)) {
+ if (tests & TEST_C2S) { // Was C2S test performed?
+ check_C2Spacketqueuing(c2sspd, spdout, sndqueue, pkts, lth);
+ }
- results_sfw(tests, host);
- return;
- }
+ results_sfw(tests, host);
+ return;
+ }
- sysvar = strtok(testresult_str, " ");
- sysval = strtok(NULL, "\n");
- i = atoi(sysval);
- save_int_values(sysvar, i);
+ sysvar = strtok(testresult_str, " ");
+ 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);
- }
- }
+ 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);
+ }
+ }
- //CountRTT = 615596;
- if (CountRTT > 0) { // The number of round trip time samples is finite
+ //CountRTT = 615596;
+ if (CountRTT > 0) { // The number of round trip time samples is finite
- // Get the link speed as determined during the C2S test. if it was performed
- if (tests & TEST_C2S) {
- mylink = get_linkspeed(c2sData, half_duplex);
- }
+ // Get the link speed as determined during the C2S test. if it was performed
+ if (tests & TEST_C2S) {
+ mylink = get_linkspeed(c2sData, half_duplex);
+ }
- print_results_mismatchcheck(mismatch);
+ print_results_mismatchcheck(mismatch);
- if (mismatch == 0) {
- check_congestion(congestion);
- check_badcable(bad_cable);
- print_recommend_buffersize(rwin, rttsec, avgrtt,
mylink,
- MaxRwinRcvd);
- }
+ if (mismatch == 0) {
+ check_congestion(congestion);
+ check_badcable(bad_cable);
+ print_recommend_buffersize(rwin, rttsec, avgrtt, mylink,
+ MaxRwinRcvd);
+ }
- if (tests & TEST_C2S) {
- check_C2Spacketqueuing(c2sspd,spdout,sndqueue, pkts,
lth);
- }
- if (tests & TEST_S2C) {
- check_S2Cpacketqueuing(s2cspd,spdin,ssndqueue,
sbytes);
- }
+ if (tests & TEST_C2S) {
+ check_C2Spacketqueuing(c2sspd,spdout,sndqueue, pkts, lth);
+ }
+ if (tests & TEST_S2C) {
+ check_S2Cpacketqueuing(s2cspd,spdin,ssndqueue, sbytes);
+ }
- results_sfw(tests, host);
+ results_sfw(tests, host);
- if (msglvl > 0) {
- printf("\n\t------ Web100 Detailed Analysis
------\n");
+ if (msglvl > 0) {
+ printf("\n\t------ Web100 Detailed Analysis ------\n");
- printf("\nWeb100 reports the Round trip time = %0.2f
msec;",
- avgrtt);
+ printf("\nWeb100 reports the Round trip time = %0.2f msec;",
+ avgrtt);
- printf("the Packet size = %d Bytes; and \n",
CurrentMSS);
+ printf("the Packet size = %d Bytes; and \n", CurrentMSS);
- // print packet loss statistics
- print_packetloss_statistics (PktsRetrans, DupAcksIn,
SACKsRcvd,
- order,Timeouts,waitsec, timesec);
+ // print packet loss statistics
+ print_packetloss_statistics (PktsRetrans, DupAcksIn, SACKsRcvd,
+ order,Timeouts,waitsec, timesec);
- // print details of whether connection was send/receive/congestion limited
- print_limitedtime_ratio( rwintime, rwin, sendtime, swin, cwndtime, rttsec,
- mylink, Sndbuf, MaxRwinRcvd);
+ // print details of whether connection was send/receive/congestion limited
+ print_limitedtime_ratio( rwintime, rwin, sendtime, swin, cwndtime, rttsec,
+ mylink, Sndbuf, MaxRwinRcvd);
- // check to see if excessive packet loss was reported
- print_packetloss_excess(spd, loss);
+ // check to see if excessive packet loss was reported
+ print_packetloss_excess(spd, loss);
- // Now print details of optional Performance settings values like the following list:
- printf(
- "\n Web100 reports TCP negotiated the optional Performance Settings to: \n");
+ // Now print details of optional Performance settings values like the following list:
+ printf(
+ "\n Web100 reports TCP negotiated the optional Performance Settings to: \n");
- // ..Selective ack options
- print_SAck_RFC2018(SACKEnabled);
+ // ..Selective ack options
+ print_SAck_RFC2018(SACKEnabled);
- // ..Nagle algo details
- print_Nagle_RFC896(NagleEnabled);
+ // ..Nagle algo details
+ print_Nagle_RFC896(NagleEnabled);
- // ..Explicit Congestion Notification
- print_congestion_RFC3168(ECNEnabled);
+ // ..Explicit Congestion Notification
+ print_congestion_RFC3168(ECNEnabled);
- // ..RFC 1323 Time Stamping
- print_timestamping_RFC1323(TimestampsEnabled);
+ // ..RFC 1323 Time Stamping
+ print_timestamping_RFC1323(TimestampsEnabled);
- // ..RFC 1323 Window Scaling
- print_windowscaling(MaxRwinRcvd,WinScaleRcvd,
WinScaleSent);
+ // ..RFC 1323 Window Scaling
+ print_windowscaling(MaxRwinRcvd,WinScaleRcvd, WinScaleSent);
- // ..throughput limiting factors details
- print_throughputlimits(MaxRwinRcvd, RcvWinScale, &Sndbuf, swin, rwin, cwin, rttsec,estimate);
+ // ..throughput limiting factors details
+ print_throughputlimits(MaxRwinRcvd, RcvWinScale, &Sndbuf, swin, rwin, cwin, rttsec,estimate);
- // client and server's views of link speed
- print_linkspeed_dataacks((tests & TEST_C2S), c2sData,
- c2sAck,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");
- }
+ // client and server's views of link speed
+ print_linkspeed_dataacks((tests & TEST_C2S), c2sData,
+ c2sAck,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");
+ }
}
/**
@@ -250,36 +250,36 @@
*/
void middleboxResults(char *midresult_str, I2Addr local_addr, I2Addr peer_addr) {
- char ssip[64], scip[64], *str;
- char csip[64], ccip[64];
- int mss;
- size_t tmpLen;
+ char ssip[64], scip[64], *str;
+ char csip[64], ccip[64];
+ int mss;
+ size_t tmpLen;
- str = strtok(midresult_str, ";");
- strlcpy(ssip, str, sizeof(ssip));
- str = strtok(NULL, ";");
+ str = strtok(midresult_str, ";");
+ strlcpy(ssip, str, sizeof(ssip));
+ str = strtok(NULL, ";");
- strlcpy(scip, str, sizeof(scip));
+ strlcpy(scip, str, sizeof(scip));
- str = strtok(NULL, ";");
- mss = atoi(str);
- str = strtok(NULL, ";");
- winssent = atoi(str); // changing order to read winsent before winsrecv for issue 61
- str = strtok(NULL, ";");
- winsrecv = atoi(str);
+ str = strtok(NULL, ";");
+ mss = atoi(str);
+ str = strtok(NULL, ";");
+ winssent = atoi(str); // changing order to read winsent before winsrecv for issue 61
+ str = strtok(NULL, ";");
+ winsrecv = atoi(str);
- memset(ccip, 0, 64);
- tmpLen = 63;
- I2AddrNodeName(local_addr, ccip, &tmpLen);
- memset(csip, 0, 64);
- tmpLen = 63;
- I2AddrNodeName(peer_addr, csip, &tmpLen);
+ memset(ccip, 0, 64);
+ tmpLen = 63;
+ I2AddrNodeName(local_addr, ccip, &tmpLen);
+ memset(csip, 0, 64);
+ tmpLen = 63;
+ I2AddrNodeName(peer_addr, csip, &tmpLen);
- // Check if MSS modification is happening
- check_MSS_modification(TimestampsEnabled, &mss);
+ // Check if MSS modification is happening
+ check_MSS_modification(TimestampsEnabled, &mss);
- // detect Network Address translation box
- check_NAT(ssip, csip, scip, ccip);
+ // detect Network Address translation box
+ check_NAT(ssip, csip, scip, ccip);
}
@@ -290,127 +290,127 @@
* @param sysval value of this variable
*/
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
- */
+ /* 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);
+ 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;
+ 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;
}
/**
@@ -420,36 +420,36 @@
* @param sysval variable's value
*/
void save_dbl_values(char *sysvar, float *sysval) {
- if (strcmp(sysvar, "bw:") == 0)
- estimate = *sysval;
- else if (strcmp(sysvar, "loss:") == 0)
- loss = *sysval;
- else if (strcmp(sysvar, "avgrtt:") == 0)
- avgrtt = *sysval;
- else if (strcmp(sysvar, "waitsec:") == 0)
- waitsec = *sysval;
- else if (strcmp(sysvar, "timesec:") == 0)
- timesec = *sysval;
- else if (strcmp(sysvar, "order:") == 0)
- order = *sysval;
- else if (strcmp(sysvar, "rwintime:") == 0)
- rwintime = *sysval;
- else if (strcmp(sysvar, "sendtime:") == 0)
- sendtime = *sysval;
- else if (strcmp(sysvar, "cwndtime:") == 0)
- cwndtime = *sysval;
- else if (strcmp(sysvar, "rttsec:") == 0)
- rttsec = *sysval;
- else if (strcmp(sysvar, "rwin:") == 0)
- rwin = *sysval;
- else if (strcmp(sysvar, "swin:") == 0)
- swin = *sysval;
- else if (strcmp(sysvar, "cwin:") == 0)
- cwin = *sysval;
- else if (strcmp(sysvar, "spd:") == 0)
- spd = *sysval;
- else if (strcmp(sysvar, "aspd:") == 0)
- aspd = *sysval;
+ if (strcmp(sysvar, "bw:") == 0)
+ estimate = *sysval;
+ else if (strcmp(sysvar, "loss:") == 0)
+ loss = *sysval;
+ else if (strcmp(sysvar, "avgrtt:") == 0)
+ avgrtt = *sysval;
+ else if (strcmp(sysvar, "waitsec:") == 0)
+ waitsec = *sysval;
+ else if (strcmp(sysvar, "timesec:") == 0)
+ timesec = *sysval;
+ else if (strcmp(sysvar, "order:") == 0)
+ order = *sysval;
+ else if (strcmp(sysvar, "rwintime:") == 0)
+ rwintime = *sysval;
+ else if (strcmp(sysvar, "sendtime:") == 0)
+ sendtime = *sysval;
+ else if (strcmp(sysvar, "cwndtime:") == 0)
+ cwndtime = *sysval;
+ else if (strcmp(sysvar, "rttsec:") == 0)
+ rttsec = *sysval;
+ else if (strcmp(sysvar, "rwin:") == 0)
+ rwin = *sysval;
+ else if (strcmp(sysvar, "swin:") == 0)
+ swin = *sysval;
+ else if (strcmp(sysvar, "cwin:") == 0)
+ cwin = *sysval;
+ else if (strcmp(sysvar, "spd:") == 0)
+ spd = *sysval;
+ else if (strcmp(sysvar, "aspd:") == 0)
+ aspd = *sysval;
}
/**
@@ -459,413 +459,413 @@
* @return > 0 if successful, < 0 if not
*/
int main(int argc, char *argv[]) {
- int useroption; // user options char
- int swait; // server wait status
- char mid_resultstr[MIDBOX_TEST_RES_SIZE]; // MID test results
- char resultstr[2*BUFFSIZE]; // S2C test results, 16384 =
2 * BUFFSIZE
- char varstr[2*BUFFSIZE]; // temporary storage for S2C test results , 16384 = 2 * BUFFSIZE
- unsigned char tests = TEST_MID | TEST_C2S | TEST_S2C | TEST_SFW
- | TEST_STATUS | TEST_META; // which tests have been selectedto be performed?
- int ctlSocket; // socket fd
- int ctlport = atoi(PORT); // default port number
- int retcode; // return code from protocol
operations, mostly
- int xwait; // wait flag
- char buff[BUFFSIZE]; // buffer used to store protocol
message payload
- char* strtokbuf; // buffer to store string
tokens
- char *host = NULL; // server name to connect to
- int buf_size = 0; // TCP send/receive window
size received from user
- int msgLen, msgType; // protocol message related variables
- int conn_options = 0; // connection options received from
user
- int debug = 0; // debug flag
- int testId; // test ID received
from server
- // addresses..
- I2Addr server_addr = NULL;
- I2Addr local_addr = NULL, remote_addr = NULL;
- char* ptr;
+ int useroption; // user options char
+ int swait; // server wait status
+ char mid_resultstr[MIDBOX_TEST_RES_SIZE]; // MID test results
+ char resultstr[2*BUFFSIZE]; // S2C test results, 16384 = 2 *
BUFFSIZE
+ char varstr[2*BUFFSIZE]; // temporary storage for S2C test results , 16384 = 2 * BUFFSIZE
+ unsigned char tests = TEST_MID | TEST_C2S | TEST_S2C | TEST_SFW
+ | TEST_STATUS | TEST_META; // which tests have been selectedto be performed?
+ int ctlSocket; // socket fd
+ int ctlport = atoi(PORT); // default port number
+ int retcode; // return code from protocol
operations, mostly
+ int xwait; // wait flag
+ char buff[BUFFSIZE]; // buffer used to store protocol message
payload
+ char* strtokbuf; // buffer to store string tokens
+ char *host = NULL; // server name to connect to
+ int buf_size = 0; // TCP send/receive window size
received from user
+ int msgLen, msgType; // protocol message related variables
+ int conn_options = 0; // connection options received from
user
+ int debug = 0; // debug flag
+ int testId; // test ID received from
server
+ // addresses..
+ I2Addr server_addr = NULL;
+ I2Addr local_addr = NULL, remote_addr = NULL;
+ char* ptr;
#ifdef AF_INET6
#define GETOPT_LONG_INET6(x) "46"x
#else
#define GETOPT_LONG_INET6(x) x
#endif
- // Read and record various optional values used for the tests/process
- while ((useroption = getopt_long(argc, argv, GETOPT_LONG_INET6("n:u:e:p:dhlvb:"),
- long_options, 0)) != -1) {
- switch (useroption) {
- case '4':
- conn_options |= OPT_IPV4_ONLY;
- break;
- case '6':
- conn_options |= OPT_IPV6_ONLY;
- break;
- case 'h':
- clt_long_usage("ANL/Internet2 NDT version " VERSION "
(client)");
- break;
- case 'v':
- printf("ANL/Internet2 NDT version %s (client)\n",
VERSION);
- exit(0);
- break;
- case 'b':
- buf_size = atoi(optarg);
- break;
- case 'd':
- debug++;
- break;
- case 'l':
- msglvl++;
- break;
- case 'p':
- ctlport = atoi(optarg);
- break;
- case 'n':
- host = optarg;
- break;
- case 'u':
- set_protologdir(strdup(optarg));
- break;
- case 'e':
- enableprotocollogging();
- break;
- case 301:
- printWeb100VarInfo();
- exit(0);
- break;
- case 302:
- tests &= (~TEST_MID);
- break;
- case 303:
- tests &= (~TEST_C2S);
- break;
- case 304:
- tests &= (~TEST_S2C);
- break;
- case 305:
- tests &= (~TEST_SFW);
- break;
- case '?':
- short_usage(argv[0], "");
- break;
+ // Read and record various optional values used for the tests/process
+ while ((useroption = getopt_long(argc, argv, GETOPT_LONG_INET6("n:u:e:p:dhlvb:"),
+ long_options, 0)) != -1) {
+ switch (useroption) {
+ case '4':
+ conn_options |= OPT_IPV4_ONLY;
+ break;
+ case '6':
+ conn_options |= OPT_IPV6_ONLY;
+ break;
+ case 'h':
+ clt_long_usage("ANL/Internet2 NDT version " VERSION " (client)");
+ break;
+ case 'v':
+ printf("ANL/Internet2 NDT version %s (client)\n", VERSION);
+ exit(0);
+ break;
+ case 'b':
+ buf_size = atoi(optarg);
+ break;
+ case 'd':
+ debug++;
+ break;
+ case 'l':
+ msglvl++;
+ break;
+ case 'p':
+ ctlport = atoi(optarg);
+ break;
+ case 'n':
+ host = optarg;
+ break;
+ case 'u':
+ set_protologdir(strdup(optarg));
+ break;
+ case 'e':
+ enableprotocollogging();
+ break;
+ case 301:
+ printWeb100VarInfo();
+ exit(0);
+ break;
+ case 302:
+ tests &= (~TEST_MID);
+ break;
+ case 303:
+ tests &= (~TEST_C2S);
+ break;
+ case 304:
+ tests &= (~TEST_S2C);
+ break;
+ case 305:
+ tests &= (~TEST_SFW);
+ break;
+ case '?':
+ short_usage(argv[0], "");
+ break;
- }
- }
+ }
+ }
- if (optind < argc) {
- short_usage(argv[0], "Unrecognized non-option elements");
- }
+ if (optind < argc) {
+ short_usage(argv[0], "Unrecognized non-option elements");
+ }
- // If protocol log is enabled, create log dir
- create_protolog_dir();
-
- log_init(argv[0], debug);
+ // If protocol log is enabled, create log dir
+ create_protolog_dir();
- failed = 0;
+ log_init(argv[0], debug);
- // Check if user options do not include any test!
- if (!(tests & (TEST_MID | TEST_C2S | TEST_S2C | TEST_SFW))) {
- short_usage(argv[0], "Cannot perform empty test suites");
- }
+ failed = 0;
- // A server is needed to run the tests against
- if (host == NULL) {
- short_usage(argv[0], "Name of the server is required");
- }
+ // Check if user options do not include any test!
+ if (!(tests & (TEST_MID | TEST_C2S | TEST_S2C | TEST_SFW))) {
+ short_usage(argv[0], "Cannot perform empty test suites");
+ }
- // Check for initial configuration and performance problems
- printf(
- "Testing network path for configuration and performance problems -- ");
- fflush(stdout);
+ // A server is needed to run the tests against
+ if (host == NULL) {
+ short_usage(argv[0], "Name of the server is required");
+ }
- if ((server_addr = I2AddrByNode(get_errhandle(), host)) == NULL) {
- printf("Unable to resolve server address\n");
- exit(-3);
- }
- I2AddrSetPort(server_addr, ctlport);
+ // Check for initial configuration and performance problems
+ printf(
+ "Testing network path for configuration and performance problems -- ");
+ fflush(stdout);
- if ((retcode = CreateConnectSocket(&ctlSocket, NULL, server_addr, conn_options,
- 0))) {
- printf("Connect() for control socket failed\n");
- exit(-4);
- }
+ if ((server_addr = I2AddrByNode(get_errhandle(), host)) == NULL) {
+ printf("Unable to resolve server address\n");
+ exit(-3);
+ }
+ I2AddrSetPort(server_addr, ctlport);
- // check and print Address family being used
- if (I2AddrSAddr(server_addr, 0)->sa_family == AF_INET) {
- printf("Using IPv4 address\n");
- } else {
- printf("Using IPv6 address\n");
- }
+ if ((retcode = CreateConnectSocket(&ctlSocket, NULL, server_addr, conn_options,
+ 0))) {
+ printf("Connect() for control socket failed\n");
+ exit(-4);
+ }
- // set options for test direction
- enum Tx_DIRECTION currentDirn = C_S;
- setCurrentDirn(currentDirn);
- // end protocol logging
+ // check and print Address family being used
+ if (I2AddrSAddr(server_addr, 0)->sa_family == AF_INET) {
+ printf("Using IPv4 address\n");
+ } else {
+ printf("Using IPv6 address\n");
+ }
- /* set the TEST_STATUS flag so the server knows this client will respond to status requests.
- * this will let the server kill off zombie clients from the queue
- * RAC 7/7/09
- */
- if (tests & TEST_STATUS) {
- log_println(1, "* New Client, implements queuing feedback");
- }
+ // set options for test direction
+ enum Tx_DIRECTION currentDirn = C_S;
+ setCurrentDirn(currentDirn);
+ // end protocol logging
- log_println(1, "Requesting test suite:");
- if (tests & TEST_MID) {
- log_println(1, " > Middlebox test");
- }
- if (tests & TEST_SFW) {
- log_println(1, " > Simple firewall test");
- }
- if (tests & TEST_C2S) {
- log_println(1, " > C2S throughput test");
- }
- if (tests & TEST_S2C) {
- log_println(1, " > S2C throughput test");
- }
- if (tests & TEST_META) {
- log_println(1, " > META test");
- }
+ /* set the TEST_STATUS flag so the server knows this client will respond to status requests.
+ * this will let the server kill off zombie clients from the queue
+ * RAC 7/7/09
+ */
+ if (tests & TEST_STATUS) {
+ log_println(1, "* New Client, implements queuing feedback");
+ }
- /* The beginning of the protocol */
+ log_println(1, "Requesting test suite:");
+ if (tests & TEST_MID) {
+ log_println(1, " > Middlebox test");
+ }
+ if (tests & TEST_SFW) {
+ log_println(1, " > Simple firewall test");
+ }
+ if (tests & TEST_C2S) {
+ log_println(1, " > C2S throughput test");
+ }
+ if (tests & TEST_S2C) {
+ log_println(1, " > S2C throughput test");
+ }
+ if (tests & TEST_META) {
+ log_println(1, " > META test");
+ }
- /* write our test suite request by sending a login message */
- send_msg(ctlSocket, MSG_LOGIN, &tests, 1);
- /* read the specially crafted data that kicks off the old clients */
- if (readn(ctlSocket, buff, 13) != 13) {
- printf(
- "Information: The server '%s' does not support this command line client\n",
- host);
- exit(0);
- }
+ /* The beginning of the protocol */
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/src/web100srv.c Mon Nov 5 10:30:55 2012
+++ /trunk/src/web100srv.c Thu Nov 15 13:33:19 2012
@@ -1,64 +1,64 @@
/*
- 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)
+ 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."
+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.
+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.
+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.
+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.
+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.
+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/).
- */
+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"
@@ -157,265 +157,265 @@
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' },
+ 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' },
- { "protolog_dir", 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' },
+ { "protolog_dir", 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;
+ 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);
+ 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;
- }
+ /* 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);
- }
+ 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
- */
+ /* 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;
+ 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; */
- }
+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) {
+ 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;
- }
- }
+ 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???");
+ 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???");
}
/**
@@ -423,160 +423,160 @@
* @param signo Signal number
* */
void cleanup(int signo) {
- FILE * fp;
+ FILE * fp;
- if (signo != SIGINT) {
- 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;
+ if (signo != SIGINT) {
+ 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 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 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);
+ 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;
+ /* 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;
- }
+ 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;
+ }
}
/** LoadConfig routine copied from Internet2.
@@ -585,225 +585,225 @@
* @param *lbuf_max line buffer max - both help keep track of a dynamically grown "line" buffer.*/
static void LoadConfig(char* name, char **lbuf, size_t *lbuf_max) {
- FILE *conf;
- char keybuf[256], valbuf[256];
- char *key = keybuf, *val = valbuf;
- int retcode = 0;
+ FILE *conf;
+ char keybuf[256], valbuf[256];
+ char *key = keybuf, *val = valbuf;
+ int retcode = 0;
- if (!(conf = fopen(ConfigFileName, "r")))
- return;
+ if (!(conf = fopen(ConfigFileName, "r")))
+ return;
- log_println(1, " Reading config file %s to obtain options", ConfigFileName);
+ log_println(1, " Reading config file %s to obtain options", ConfigFileName);
- // Read the values for various keys and store them in appropriate variables
- while ((retcode = I2ReadConfVar(conf, retcode, key, val, 256, lbuf,
- lbuf_max)) > 0) {
- if (strncasecmp(key, "administrator_view", 5) == 0) {
- admin_view = 1;
- continue;
- }
+ // Read the values for various keys and store them in appropriate variables
+ while ((retcode = I2ReadConfVar(conf, retcode, key, val, 256, lbuf,
+ lbuf_max)) > 0) {
+ if (strncasecmp(key, "administrator_view", 5) == 0) {
+ admin_view = 1;
+ continue;
+ }
- else if (strncasecmp(key, "multiple_clients", 5) == 0) {
- multiple = 1;
- continue;
- }
+ else if (strncasecmp(key, "multiple_clients", 5) == 0) {
+ multiple = 1;
+ continue;
+ }
- else if (strncasecmp(key, "max_clients", 5) == 0) {
- max_clients = atoi(val);
- continue;
- }
+ else if (strncasecmp(key, "max_clients", 5) == 0) {
+ max_clients = atoi(val);
+ continue;
+ }
- else if (strncasecmp(key, "record_reverse", 6) == 0) {
- record_reverse = 1;
- continue;
- }
+ else if (strncasecmp(key, "record_reverse", 6) == 0) {
+ record_reverse = 1;
+ continue;
+ }
- else if (strncasecmp(key, "write_trace", 5) == 0) {
- dumptrace = 1;
- continue;
- }
+ else if (strncasecmp(key, "write_trace", 5) == 0) {
***The diff for this file has been truncated for email.***
- [ndt-dev] [ndt] r789 committed - Reformat to google style, ndt, 11/15/2012
Archive powered by MHonArc 2.6.16.