Exemplo n.º 1
0
/* Create a control connection to a slave */
static int
new_control_connection(group_t *g, char *host)
{
	protocol_t *p;

	if (host == NULL || host[0] == '\0') {
		uperf_error("remotehost not specified. Check profile\n");
		return (UPERF_FAILURE);
	}
	/* First check if we already have one */
	p = g->control;
	while (p) {
		if (strncasecmp(host, p->host, MAXHOSTNAME) == 0) {
			uperf_info("Resuing control connection for %s\n", host);
			return (UPERF_SUCCESS);
		}
		p = p->next;
	}
	/* Not found, create a new one */
	p = create_protocol(PROTOCOL_TCP, host, MASTER_PORT, MASTER);
	if (p != NULL) {
		/* Try connecting */
		if (p->connect(p, NULL) == 0) {
			p->next = g->control;
			if (g->control)
				g->control->prev = p;
			g->control = p;
			slaves[no_slaves++] = p;
			return (UPERF_SUCCESS);
		}
	}
	uperf_error("Error connecting to %s\n", host);
	return (UPERF_FAILURE);
}
Exemplo n.º 2
0
static void
master_prepare_to_exit(uperf_shm_t *shm)
{
	static int cleaned_up = 0;
	if (cleaned_up > 1)
		abort();
	uperf_info("Master: Shutting down strands\n");
	strand_killall(shm);
	(void) send_command_to_slaves(UPERF_CMD_ABORT, 0);
	cleaned_up++;
}
Exemplo n.º 3
0
Arquivo: ssl.c Projeto: FPiriz/uperf
static protocol_t *
protocol_ssl_accept(protocol_t * p, void *options)
{
	protocol_t *newp;
	struct sockaddr_in remote;
	socklen_t addrlen;
	int ret;
	ssl_private_t *ssl_p = (ssl_private_t *) p->_protocol_p;
	ssl_private_t *new_ssl_p;
	struct sockaddr name;
	char hostname[128];
	flowop_options_t *flowop_options = (flowop_options_t *) options;
	BIO *sbio;

	newp = protocol_ssl_new();
	new_ssl_p = (ssl_private_t *) newp->_protocol_p;
	addrlen = (socklen_t) sizeof (remote);
	uperf_debug("ssl - ssl obj waiting for accept\n");
	newp->fd = accept(p->fd, (struct sockaddr *) &remote,
		&addrlen);
	if (newp->fd < 0) {
		uperf_log_msg(UPERF_LOG_ERROR, errno, "accept");
		return (NULL);
	}
	if (getnameinfo((const struct sockaddr *) & remote, addrlen,
			hostname, sizeof (hostname), NULL, 0, 0) == 0) {
		uperf_debug("ssl - Connection from %s:%d\n", hostname,
			SOCK_PORT(remote));
		strlcpy(newp->host, hostname, sizeof (newp->host));
		newp->port = SOCK_PORT(remote);
	}
	if (flowop_options) {
		if ((load_engine(flowop_options->engine)) == -1) {
			uperf_info(
"ssl - Engine %s does NOT exist! Using the default OpenSSL softtoken",
			flowop_options->engine);
		}
	}
	sbio = BIO_new_socket(newp->fd, BIO_NOCLOSE);
	if (!(new_ssl_p->ssl = SSL_new(ctx))) {
		uperf_log_msg(UPERF_LOG_ERROR, 0, "SSL_new error");
		return (NULL);
	}
	SSL_set_bio(new_ssl_p->ssl, sbio, sbio);

	ret = SSL_accept(new_ssl_p->ssl);
	if (my_ssl_error(new_ssl_p->ssl, ret) == 0) {
		return (newp);
	} else {
		return (0);
	}
}
Exemplo n.º 4
0
static int
say_goodbye(goodbye_stat_t *total, protocol_t *p, int timeout)
{
	goodbye_t g;
	char msg[GOODBYE_MESSAGE_LEN];

	if (recv_goodbye(&g, p, timeout) != UPERF_SUCCESS) {
		uperf_error("\nError saying goodbye with %s\n", p->host);
		return (1);
	}

	switch (g.msg_type) {
		case MESSAGE_INFO:
			(void) snprintf(msg, GOODBYE_MESSAGE_LEN,
			    "[%s] %s", p->host, g.message);
			uperf_info(msg);
			break;
		case MESSAGE_NONE:
			break;
		case MESSAGE_ERROR:
			(void) snprintf(msg, GOODBYE_MESSAGE_LEN,
			    "[%s] %s", p->host, g.message);
			uperf_log_msg(UPERF_LOG_ERROR, 0, msg);
			break;
		case MESSAGE_WARNING:
			(void) snprintf(msg, GOODBYE_MESSAGE_LEN,
			    "[%s] %s\n", p->host, g.message);
			uperf_log_msg(UPERF_LOG_WARN, 0, msg);
			break;
	}
	(void) print_goodbye_stat(p->host, &g.gstat);
	total->elapsed_time = MAX(g.gstat.elapsed_time, total->elapsed_time);
	total->error += g.gstat.error;
	total->bytes_xfer += g.gstat.bytes_xfer;
	total->count += g.gstat.count;

	return (0);
}
Exemplo n.º 5
0
Arquivo: ssl.c Projeto: FPiriz/uperf
static int
protocol_ssl_connect(protocol_t * p, void *options)
{
	BIO *sbio;
	int status;

	ssl_private_t *ssl_p = (ssl_private_t *) p->_protocol_p;
	flowop_options_t *flowop_options = (flowop_options_t *) options;

	uperf_debug("ssl - Connecting to %s:%d\n", p->host, p->port);

	status = generic_connect(p, IPPROTO_TCP);
	if (status == UPERF_SUCCESS)
		set_tcp_options(p->fd, flowop_options);

	if (flowop_options && (strcmp(flowop_options->engine, ""))) {
		status = load_engine(flowop_options->engine);
		if (status == -1) {
			uperf_info(
"ssl - Engine %s does NOT exist! Using the default OpenSSL softtoken",
			flowop_options->engine);
		}
	}
	if ((ssl_p->ssl = SSL_new(ctx)) == NULL) {
		ulog_err("Error initializng SSL");
		return (-1);
	}
	sbio = BIO_new_socket(p->fd, BIO_NOCLOSE);
	SSL_set_bio(ssl_p->ssl, sbio, sbio);

	status = SSL_connect(ssl_p->ssl);
	if (status <= 0) {
		uperf_log_msg(UPERF_LOG_ERROR, 0, "ssl connect error");
		return (-1);
	}
	return (0);
}
Exemplo n.º 6
0
int
master(workorder_t *w)
{
	int rc;
	int i;
	int thr_count;
	int nthr, nproc;
	int id;
	int goodbye_timeout = UPERF_GOODBYE_TIMEOUT;
	hrtime_t start, stop;
	uperf_shm_t *shm;
	goodbye_stat_t gtotal;
	int error;

	if ((shm = master_init(w)) == NULL)
		exit(1);

	/*
	 * We need to get the total number of threads to arm the
	 * start, and end barriers.
	 */
	nproc = workorder_num_strands_bytype(w, STRAND_TYPE_PROCESS);
	nthr = workorder_num_strands_bytype(w, STRAND_TYPE_THREAD);
	thr_count = nproc + nthr;

	if (handshake(shm, w) != UPERF_SUCCESS) {
		uperf_info("Error in handshake\n");
		shm_fini(shm);
		exit(1);
	}

	if (nthr == 0 && nproc != 0) {
		(void) printf("Starting %d processes running profile:%s ... ",
		    thr_count, w->name);
	} else if (nproc == 0 && nthr != 0) {
		(void) printf("Starting %d threads running profile:%s ... ",
		    thr_count, w->name);
	} else {
	(void) printf(
		"Starting %d threads, %d processes running profile:%s ... ",
		nthr, nproc, w->name);
	}
	(void) fflush(stdout);

	start = GETHRTIME();
	/* Traverse through the worklist and create threads */
	id = 0;
	for (i = 0; i < w->ngrp; i++) {
		w->grp[i].groupid = i;
		if (shm->global_error > 0)
			break;
		if (spawn_strands_group(shm, &w->grp[i], id) != 0)
			shm->global_error++;
		id += w->grp[i].nthreads;
	}

	if (shm->global_error > 0) {
		master_prepare_to_exit(shm);
		shm_fini(shm);
		return (UPERF_FAILURE);
	}
	stop = GETHRTIME();
	(void) printf(" %5.2f seconds\n", (stop-start)/1.0e+9);
	(void) fflush(stdout);

	/* Handshake end */
	if (handshake_end_master(shm, w) != UPERF_SUCCESS) {
		return (UPERF_FAILURE);
	}

#ifdef ENABLE_NETSTAT
	if (ENABLED_PACKET_STATS(options))
		netstat_snap(SNAP_BEGIN);
#endif /* ENABLE_NETSTAT */

	/*
	 * The main Loop.
	 * if either global_error is not 0 or master_poll returns 1
	 * let wait_for_strands know that.
	 */
	newstat_begin(0, AGG_STAT(shm), 0, 0);
	error =  master_poll(shm);
	if (error == 0 && shm->global_error != 0)
		error = shm->global_error;

	(void) wait_for_strands(shm, error);
	newstat_end(0, AGG_STAT(shm), 0, 0);

	shm->current_time = GETHRTIME();

#ifdef ENABLE_NETSTAT
	if (ENABLED_PACKET_STATS(options))
		netstat_snap(SNAP_END);
#endif /* ENABLE_NETSTAT */
	if (ENABLED_STATS(options)) {
		print_summary(AGG_STAT(shm), 0);
	}

	if (shm->global_error > 0) {
		/* decrease timeout coz no point in waiting */
		goodbye_timeout = 1000;
	}

	if (ENABLED_GROUP_STATS(options))
		print_group_details(shm);
	if (ENABLED_THREAD_STATS(options))
		print_strand_details(shm);
	if (ENABLED_TXN_STATS(options))
		print_txn_averages(shm);
	if (ENABLED_FLOWOP_STATS(options))
		print_flowop_averages(shm);
#ifdef ENABLE_NETSTAT
	if (ENABLED_PACKET_STATS(options))
		print_netstat();
#endif /* ENABLE_NETSTAT */
	if (ENABLED_ERROR_STATS(options)) {
		goodbye_stat_t local;

		(void) memset(&gtotal, 0, sizeof (goodbye_stat_t));
		if ((rc = say_goodbyes_and_close(&gtotal, goodbye_timeout))
		    == 0) {
			update_aggr_stat(shm);
			local.elapsed_time = (AGG_STAT(shm))->end_time
			    - (AGG_STAT(shm))->start_time;
			local.error = 0;
			local.bytes_xfer = (AGG_STAT(shm))->size;
			local.count = (AGG_STAT(shm))->count;
			print_goodbye_stat("master", &local);
			print_difference(local, gtotal);
		}
	}
	uperf_log_flush();

	if (ENABLED_HISTORY_STATS(options)) {
		(void) fclose(options.history_fd);
	}
	/* Cleanup */
	if (shm->global_error != 0) {
		(void) printf("\nWARNING: Errors detected during run\n");
		shm_fini(shm);
		exit(1);
	}
	shm_fini(shm);

	return (rc);
}