int main(int argc, char *argv[]) { int tcpsock = 0; int udpsock = 0; struct sockaddr_in from; double capacityup = 0, capacitydown = 0; double measupcap = 0, measdowncap = 0; unsigned int tbresult = 0, tbmindepth = 0, tbmaxdepth = 0, tbabortflag = 0; double tbrate = 0, truecapup = 0, truecapdown = 0; double sleepRes = 1; char filename[256], tracefile[256]; int fileid = -1; struct in_addr sin_addr; struct timeval tv; FILE *fp; extern double TB_RATE_AVG_INTERVAL; TB_RATE_AVG_INTERVAL = 0.3; memset(tracefile, 0, 256); CHKRET(prober_config_load(argc, argv, tracefile, &fileid)); sleepRes = prober_sleep_resolution(); if (serverip) { tcpsock = connect2server(serverip, fileid); } else { tcpsock = selectServer(fileid); if(tcpsock <= 0) printf("Server busy. Please try again later.\n"); } CHKRET(tcpsock); memset(&from, 0, sizeof(from)); from.sin_family = PF_INET; //from.sin_port = htons(SERV_PORT_UDP); from.sin_port = htons(serv_port); from.sin_addr.s_addr = serverip; gettimeofday(&tv, NULL); sin_addr.s_addr = serverip; memset(filename, 0, 256); sprintf(filename, "/tmp/udp_%s.log", inet_ntoa(sin_addr)); fp = fopen(filename, "a+w"); fprintf(fp, "sleep time resolution: %.2f ms.\n", sleepRes*1000); //udpsock = udpclient(serverip, SERV_PORT_UDP); udpsock = udpclient(serverip, serv_port); CHKRET(udpsock); sin_addr.s_addr = serverip; fprintf(fp, "Connected to server %s.\n", inet_ntoa(sin_addr)); fprintf(fp, "\nEstimating capacity:\n"); capacityup = estimateCapacity(tcpsock, udpsock, &from); CHKRET(capacityup); CHKRET(sendCapEst(tcpsock)); fprintf(fp, "Upstream: %d Kbps.\n", (int)capacityup); capacitydown = capacityEstimation(tcpsock, udpsock, &from, fp); CHKRET(capacitydown); //printf("Downstream: %d Kbps.\n", (int)capacitydown); // send to test log printf("%s, %d, %.2f, %.2f\n",inet_ntoa(sin_addr), (int)tv.tv_sec, capacityup, capacitydown); fprintf(fp, "LOG: %s, %s, %d, %.2f, %.2f\n", filename, inet_ntoa(sin_addr), (int)tv.tv_sec, capacityup, capacitydown); // finished logging close(udpsock); close(tcpsock); //printf("\nFor more information, visit: http://www.cc.gatech.edu/~partha/diffprobe\n"); fprintf(fp, "\nDONE\n"); fclose(fp); unlink(filename); return(0); }
int main(int argc, char *argv[]) { int tcpsock = 0; int udpsock = 0; struct sockaddr_in from; double capacityup = 0, capacitydown = 0; double measupcap = 0, measdowncap = 0; unsigned int tbresult = 0, tbmindepth = 0, tbmaxdepth = 0, tbabortflag = 0; double tbrate = 0, truecapup = 0, truecapdown = 0; double sleepRes = 1; char filename[256], tracefile[256]; int fileid = -1; struct in_addr sin_addr; struct timeval tv; FILE *fp; extern double TB_RATE_AVG_INTERVAL; TB_RATE_AVG_INTERVAL = 0.3; printf("DiffProbe beta release. October 2009.\n"); printf("Shaper Detection Module.\n\n"); memset(tracefile, 0, 256); CHKRET(prober_config_load(argc, argv, tracefile, &fileid)); sleepRes = prober_sleep_resolution(); tcpsock = connect2server(serverip, fileid); //tcpsock = selectServer(fileid); if(tcpsock <= 0) printf("Server busy. Please try again later.\n"); CHKRET(tcpsock); memset(&from, 0, sizeof(from)); from.sin_family = PF_INET; //from.sin_port = htons(SERV_PORT_UDP); from.sin_port = htons(serv_port); from.sin_addr.s_addr = serverip; gettimeofday(&tv, NULL); sin_addr.s_addr = serverip; memset(filename, 0, 256); sprintf(filename, "%s_%d.txt", inet_ntoa(sin_addr), (int)tv.tv_sec); //fp = fopen(filename, "w"); //fprintf(fp, "sleep time resolution: %.2f ms.\n", sleepRes*1000); //udpsock = udpclient(serverip, SERV_PORT_UDP); udpsock = udpclient(serverip, serv_port); CHKRET(udpsock); sin_addr.s_addr = serverip; printf("Connected to server %s.\n", inet_ntoa(sin_addr)); printf("\nEstimating capacity:\n"); capacityup = estimateCapacity(tcpsock, udpsock, &from); CHKRET(capacityup); CHKRET(sendCapEst(tcpsock)); capacitydown = capacityEstimation(tcpsock, udpsock, &from, fp); CHKRET(capacitydown); mflowSender(tcpsock, udpsock, &from, (capacityup > 100000) ? 95000 : capacityup, sleepRes, &measupcap); mflowReceiver(tcpsock, udpsock, &measdowncap, fp); //XXX: the meas code needs trains and lower cpu if(capacityup < 80000) capacityup = measupcap; if(capacitydown < 80000) capacitydown = measdowncap; if(capacityup > 100000) { //printf("Upstream: greater than 100 Mbps.\n"); printf("Upstream: %d Kbps.\n", (int)capacityup); capacityup = 95000; } else { printf("Upstream: %d Kbps.\n", (int)capacityup); // capacityup *= 0.95; //reduce loss-based aborts } truecapup = capacityup; if(capacitydown > 100000) { //printf("Downstream: greater than 100 Mbps.\n"); printf("Downstream: %d Kbps.\n", (int)capacitydown); capacitydown = 95000; } else { printf("Downstream: %d Kbps.\n", (int)capacitydown); // capacitydown *= 0.95; //reduce loss-based aborts } truecapdown = capacitydown; printf("\nThe measurement will last for about %.1f minutes. Please wait.\n", 0.5*ceil(2*( (2 * (60) // probing + low-rate + (40560 + 3.5 * capacitydown * (60) ) * 8 / (1000*capacityup))/60))); // to upload file printf("\nChecking for traffic shapers:\n\n"); CHKRET(tbdetectSender(tcpsock, udpsock, &from, capacityup, sleepRes, &tbresult, &tbmindepth, &tbmaxdepth, &tbrate, &tbabortflag, fp)); if(tbresult == 1) truecapup = tbrate; // mflowSender(tcpsock, udpsock, &from, (tbresult == 1) ? tbrate : capacityup/2.0, sleepRes); printShaperResult(tbresult, tbmindepth, tbmaxdepth, tbrate, tbabortflag, 0, stdout); CHKRET(tbdetectReceiver(tcpsock, udpsock, capacitydown, sleepRes, &tbresult, &tbmindepth, &tbmaxdepth, &tbrate, &tbabortflag, fp)); if(tbresult == 1) truecapdown = tbrate; // mflowReceiver(tcpsock, udpsock, fp); //fclose(fp); //sendData(tcpsock, filename); printShaperResult(tbresult, tbmindepth, tbmaxdepth, tbrate, tbabortflag, 1, stdout); close(udpsock); close(tcpsock); printf("\nFor more information, visit: http://www.cc.gatech.edu/~partha/diffprobe\n"); return(0); }