Example #1
0
int main(int argc, char *argv[], char **env)
{
	int tcpsock, tcpclientsock;
	int udpsockcap;
	double upcap = 0, downcap = 0;
	double measupcap = 0, measdowncap = 0;
	unsigned int tbresult = 0, tbabortflag = 0,
		tbmindepth = 0, tbmaxdepth = 0;
	double tbrate = 0, trueupcap = 0, truedowncap = 0;
	double sleepRes = 1;
	struct sockaddr_in saddr;
	unsigned int ssz = sizeof(saddr);
	char tracefile[256], filename[256];
	struct timeval tv;
	struct sockaddr_in from;
	FILE *fp;
	extern double TB_RATE_AVG_INTERVAL;
	int clientversion = 0;
	double upCapLimit = 100000; double upProbeLimit = 95000;
	double downCapLimit = 100000; double downProbeLimit = 95000;

	TB_RATE_AVG_INTERVAL = 0.3;
	memset(tracefile, 0, 256);

	tcpsock = create_server();
	sleepRes = prober_sleep_resolution();
	printf("sleep time resolution: %.2f ms.\n", sleepRes*1000);

while(1)
{
	printf("Waiting for new clients..\n");

	udpsockcap = prober_bind_port(SERV_PORT_UDP);
	CHKRET(udpsockcap);

	tcpclientsock = handle_clients(tcpsock, udpsockcap);
	CHKRET(tcpclientsock);
	close(tcpsock);

	begintimer();

	if(getpeername(tcpclientsock, (struct sockaddr *)&saddr, &ssz) == -1)
	fprintf(stderr, "cannot get peer address\n");
	gettimeofday(&tv, NULL);
	memset(filename, 0, 256);
	printf("Probing from %s\n", inet_ntoa(saddr.sin_addr));

	printf("\nEstimating capacity:\n");

	fp = openLog(filename, inet_ntoa(saddr.sin_addr), tv); //assume this opens a fp
	fprintf(fp, "sleep time resolution: %.2f ms.\n", sleepRes*1000);

	CHKRET(preprocess_newclient(tcpclientsock, udpsockcap, &clientversion,
				&upcap, &downcap, &from, tracefile, fp, filename));
	trueupcap = upcap; truedowncap = downcap;

	if(clientversion > 3) // newer clients
	{ upCapLimit = 200000; upProbeLimit = 195000;
	downCapLimit = 200000; downProbeLimit = 195000; }

	if(upcap > upCapLimit /*200000*/) { upcap = upProbeLimit /*195000*/; }
	if(downcap > downCapLimit /*200000*/) { downcap = downProbeLimit /*195000*/; }

	mflowReceiver(tcpclientsock, udpsockcap, &measupcap, fp, 0);
	mflowSender(tcpclientsock, udpsockcap, &from, downcap, sleepRes, &measdowncap, 0);
	printf("recvrates: up %f, down %f Kbps\n", measupcap, measdowncap);
	upcap = measupcap; downcap = measdowncap;

	fprintf(fp, "upstream capacity: %.2f Kbps.\n", upcap);
	fprintf(fp, "downstream capacity: %.2f Kbps.\n", downcap);
	fprintf(fp, "### UPSTREAM ###\n");
	printf("upstream capacity: %.2f Kbps.\n", upcap);
	printf("downstream capacity: %.2f Kbps.\n", downcap);
	if(upcap > upCapLimit /*200000*/) { upcap = upProbeLimit /*195000*/; } //else { upcap *= 0.95; }
	if(downcap > downCapLimit /*200000*/) { downcap = downProbeLimit /*195000*/; } //else { downcap *= 0.95; }

	printf("Checking for traffic shapers:\n");
	if(clientversion > 3) //backwards-compatibility
	mflowReceiver(tcpclientsock, udpsockcap, NULL, fp, 1);
	CHKRET(tbdetectReceiver(tcpclientsock, udpsockcap, upcap, sleepRes,
		&tbresult, &tbmindepth, &tbmaxdepth, &tbrate, &tbabortflag, fp));
	if(tbresult == 1) trueupcap = tbrate;
	printShaperResult(tbresult, tbmindepth, tbmaxdepth, tbrate, 0, fp);

	if(clientversion > 3) //backwards-compatibility
	mflowSender(tcpclientsock, udpsockcap, &from, -1, sleepRes, NULL, 1);
	CHKRET(tbdetectSender(tcpclientsock, udpsockcap, &from, downcap, sleepRes,
		&tbresult, &tbmindepth, &tbmaxdepth, &tbrate, &tbabortflag, fp));
	if(tbresult == 1) truedowncap = tbrate;
	printShaperResult(tbresult, tbmindepth, tbmaxdepth, tbrate, 1, fp);
	recvData(tcpclientsock, fp, 1 /*0 up 1 down*/);

	fclose(fp);
	close(udpsockcap);
	close(tcpclientsock);

	break;
}

	execl("/bin/bzip2", "/bin/bzip2", filename, NULL);

	return(0);
}
Example #2
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);
}