Exemple #1
0
static int start_loop(int verbose)
{
 	struct pg_error *error = NULL;
	struct pg_brick *nic_tmp, *switch_east, *print_tmp;
	uint16_t port_count = rte_eth_dev_count();
	GList *nic_manager = NULL;
	GList *manager = NULL;

	g_assert(port_count > 1);

	/*
	 * Here is an ascii graph of the links:
	 *
	 * [NIC-X] - [PRINT-X]   --\
	 *		            \
	 * [NIC-X+1] - [PRINT-X+1]   } -- [SWITCH]
	 *		            /
	 * [NIC-X+2] - [PRINT-X+2] /
	 * ....
	 */
	switch_east = pg_switch_new("switch", 20, 20, &error);
	CHECK_ERROR(error);
	PG_BM_ADD(manager, switch_east);

	for (int i = 0; i < port_count; ++i) {
		nic_tmp = pg_nic_new_by_id("nic", 1, 1, WEST_SIDE, i, &error);
		CHECK_ERROR(error);
		print_tmp = pg_print_new("print", 1, 1, NULL,
					 PG_PRINT_FLAG_MAX, NULL,
					 &error);
		CHECK_ERROR(error);
		if (!verbose)
			pg_brick_chained_links(&error, nic_tmp, switch_east);
		else
			pg_brick_chained_links(&error, nic_tmp,
					       print_tmp, switch_east);
		CHECK_ERROR(error);
		PG_BM_ADD(nic_manager, nic_tmp);
		PG_BM_ADD(manager, print_tmp);
	}
	while (1) {
		uint64_t tot_send_pkts = 0;
		for (int i = 0; i < 100000; ++i) {
			uint16_t nb_send_pkts;

			PG_BM_GET_NEXT(nic_manager, nic_tmp);
			pg_brick_poll(nic_tmp, &nb_send_pkts, &error);
			tot_send_pkts += nb_send_pkts;
			CHECK_ERROR(error);
			usleep(1);
		}
		printf("poll pkts: %lu\n", tot_send_pkts);
	}
	nic_manager = g_list_first(nic_manager);
	PG_BM_DESTROY(manager);
	PG_BM_DESTROY(nic_manager);
	return 0;
}
Exemple #2
0
static int start_loop(int verbose, int nb_vhost)
{
 	struct pg_error *error = NULL;
	struct pg_brick *nic_tmp, *switch_east, *print_tmp;
	uint16_t port_count = rte_eth_dev_count();
	GList *nic_manager = NULL;
	GList *manager = NULL;
	int ret = -1;


	/*
	 * Here is an ascii graph of the links:
	 *
	 * [NIC-X] - [PRINT-X]   --\
	 *		            \
	 * [NIC-X+1] - [PRINT-X+1]   } -- [SWITCH]
	 *		            /
	 * [NIC-X+2] - [PRINT-X+2] /
	 * ....
	 */
	switch_east = pg_switch_new("switch", 20, 20, EAST_SIDE, &error);
	CHECK_ERROR(error);
	PG_BM_ADD(manager, switch_east);

	if (nb_vhost) {
		if (pg_vhost_start("/tmp", &error) < 0)
			goto free_switch;
		port_count = nb_vhost;
	}
	g_assert(port_count > 1);

	
	for (int i = 0; i < port_count; ++i) {
		char *tmp_name;

		if (nb_vhost) {
			tmp_name = g_strdup_printf("vhost-%d", i);
			nic_tmp = pg_vhost_new(tmp_name, 1, 1,
					       WEST_SIDE, &error);
		} else {
			tmp_name = g_strdup_printf("nic-%d", i);
			nic_tmp = pg_nic_new_by_id(tmp_name, i, &error);
		}

		g_free(tmp_name);
		CHECK_ERROR(error);
		tmp_name = g_strdup_printf("print-%d", i);
		print_tmp = pg_print_new(tmp_name, 1, 1, NULL,
					 PG_PRINT_FLAG_MAX, NULL,
					 &error);
		g_free(tmp_name);
		CHECK_ERROR(error);
		if (!verbose)
			pg_brick_chained_links(&error, nic_tmp, switch_east);
		else
			pg_brick_chained_links(&error, nic_tmp,
					       print_tmp, switch_east);
		CHECK_ERROR(error);
		PG_BM_ADD(nic_manager, nic_tmp);
		PG_BM_ADD(manager, print_tmp);
	}
	while (1) {
		uint64_t tot_send_pkts = 0;
		for (int i = 0; i < 100000; ++i) {
			uint16_t nb_send_pkts;

			PG_BM_GET_NEXT(nic_manager, nic_tmp);
			pg_brick_poll(nic_tmp, &nb_send_pkts, &error);
			tot_send_pkts += nb_send_pkts;
			CHECK_ERROR(error);
			usleep(1);
		}
		printf("poll pkts: %lu\n", tot_send_pkts);
	}
	ret = 0;
	nic_manager = g_list_first(nic_manager);
	PG_BM_DESTROY(nic_manager);
free_switch:
	PG_BM_DESTROY(manager);
	pg_vhost_stop();
	return ret;
}