Beispiel #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);
}
Beispiel #2
0
QGroupBox*
HW3b::controlPanel()
{
    // init group box
    QGroupBox *groupBox = new QGroupBox("Homework 3a");

    groupBox->setMinimumWidth(300);
    QGridLayout *layout = new QGridLayout;
    m_comboBox = new QComboBox();
    m_comboBox->addItem("Texture");
    m_comboBox->addItem("Wireframe");
    m_comboBox->addItem("Tex+Wire");
    m_comboBox->setCurrentIndex(TEX_WIRE);
    
    
    m_comboBox_mode = new QComboBox();
    m_comboBox_mode->addItem("FLAT");
    m_comboBox_mode->addItem("SPIKE");
    m_comboBox_mode->addItem("DIAGONALWALL");
    m_comboBox_mode->addItem("SIDEWALL");
    m_comboBox_mode->addItem("HOLE");
    m_comboBox_mode->addItem("MIDDLEBLOCK");
    m_comboBox_mode->addItem("DIAGONALBLOCK");
    m_comboBox_mode->addItem("CORNERBLOCK");
    m_comboBox_mode->addItem("HILL");
    m_comboBox_mode->addItem("HILLFOUR");
    m_comboBox_mode->setCurrentIndex(HILLFOUR);
    
    
    
    m_PushbottonGo = new QPushButton("go");
    m_PushbottonStop = new QPushButton("Stop");
    layout->addWidget(m_PushbottonGo,0,0,1,2);
    layout->addWidget(m_PushbottonStop,1,0,1,2);
    layout->addWidget(m_comboBox,2,0,1,2);
    layout->addWidget(m_comboBox_mode,3,0,1,2);
    
    m_sliderGrid = new QSlider(Qt::Horizontal);
    m_sliderGrid->setRange(2, 64);
    m_sliderGrid->setValue(16);
    
    m_spinboxGrid = new QSpinBox;
    m_spinboxGrid->setRange(2,64);
    m_spinboxGrid->setValue(16);
    
    
    m_sliderSpeed = new QSlider(Qt::Horizontal);
    m_sliderSpeed->setRange(1, 20);
    m_sliderSpeed->setValue(6);
    
    
    m_spinboxSpeed = new QSpinBox;
    m_spinboxSpeed->setRange(1,20);
    m_spinboxSpeed->setValue(6);
    
    
    m_labelGrid = new QLabel("Grid");
    m_labelSpeed = new QLabel("Speed");
    
    layout->addWidget(m_labelGrid,4,0,1,1);
    layout->addWidget(m_sliderGrid,4,1,1,1);
    layout->addWidget(m_spinboxGrid,4,3,1,1);
    
    layout->addWidget(m_labelSpeed,5,0,1,1);
    layout->addWidget(m_sliderSpeed,5,1,1,1);
    layout->addWidget(m_spinboxSpeed,5,3,1,1);

    
    connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(displayChange(int)));
    connect(m_comboBox_mode, SIGNAL(currentIndexChanged(int)), this, SLOT(selectMode(int)));
    connect(m_PushbottonGo, SIGNAL(clicked()), this, SLOT(begintimer()));
    connect(m_PushbottonStop, SIGNAL(clicked()), this, SLOT(stopTimer()));
    
    connect(m_sliderGrid, SIGNAL(valueChanged(int)), this, SLOT(setsize(int)));
    connect(m_spinboxGrid, SIGNAL(valueChanged(int)), this, SLOT(setsize(int)));
    connect(m_sliderSpeed, SIGNAL(valueChanged(int)), this, SLOT(setSpeed(int)));
//    connect(m_spinboxSpeed, SIGNAL(valueChanged(int)), this, SLOT(setSpeed(int)));

    
    groupBox->setLayout(layout);
    

    return(groupBox);
}