Esempio n. 1
0
static void test_nic_simple_flow(void)
{
	struct pg_brick *nic_west, *nic_ring;
	int i = 0;
	int nb_iteration = 32;
	uint16_t nb_send_pkts;
	uint16_t total_send_pkts = 0;
	uint16_t total_get_pkts = 0;
	struct pg_error *error = NULL;
	struct pg_nic_stats info;

	/* create a chain of a few nop brick with collectors on each sides */
	/*
	 * [nic_west] ------- [nic_east]
	 */

	/* write rx pcap file (required bu pcap driver) */
	const gchar pcap_in_file[] = {
		212, 195, 178, 161, 2, 0, 4, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 255, 255, 0, 0, 1, 0, 0, 0};
	g_assert(g_file_set_contents("in.pcap", pcap_in_file,
				     sizeof(pcap_in_file), NULL));

	nic_west = pg_nic_new("nic", "eth_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap", &error);
	CHECK_ERROR(error);
	nic_ring = pg_nic_new_by_id("nic", 0, &error);
	CHECK_ERROR(error);
	pg_brick_link(nic_west, nic_ring, &error);
	CHECK_ERROR(error);

	for (i = 0; i < nb_iteration * 6; ++i) {
		/* max pkts is the maximum nbr of packets
		   rte_eth_burst_wrap can send */
		max_pkts = i * 2;
		if (max_pkts > 64)
			max_pkts = 64;
		/*poll packets to east*/
		pg_brick_poll(nic_west, &nb_send_pkts, &error);
		CHECK_ERROR(error);
		/* collect pkts on the east */
		if (nb_send_pkts) {
			total_send_pkts += max_pkts;
		}
		/* check no pkts end here */
		CHECK_ERROR(error);
	}
	pg_nic_get_stats(nic_ring, &info);
	g_assert(info.opackets == total_send_pkts);
	max_pkts = 64;
	for (i = 0; i < nb_iteration; ++i) {
		/* poll packet to the west */
		pg_brick_poll(nic_ring, &nb_send_pkts, &error);
		CHECK_ERROR(error);
		total_get_pkts += nb_send_pkts;
	}
	/* This assert allow us to check nb_send_pkts*/
	g_assert(total_get_pkts == total_send_pkts);
	g_assert(info.opackets == total_send_pkts);
	/* use packets_count in collect_west here to made
	 * another check when merge*/

	/* break the chain */
	pg_brick_destroy(nic_west);
	pg_brick_destroy(nic_ring);

	/* remove pcap files */
	g_assert(g_unlink("in.pcap") == 0);
	g_assert(g_unlink("out.pcap") == 0);
}
Esempio n. 2
0
static void test_nic_simple_flow(void)
{
	struct pg_brick *nic_west, *nic_ring;
	int i = 0;
	int nb_iteration = 32;
	uint16_t nb_send_pkts;
	uint16_t total_send_pkts = 0;
	uint16_t total_get_pkts = 0;
	struct pg_error *error = NULL;
	struct pg_nic_stats info;
	gchar *tmp;

	/* create a chain of a few nop brick with collectors on each sides */
	/*
	 * [nic_west] ------- [nic_east]
	 */
	tmp = g_strdup_printf("eth_pcap0,rx_pcap=%s,tx_pcap=out.pcap",
			      glob_pcap_in);
	nic_west = pg_nic_new("nic", tmp, &error);
	g_free(tmp);
	CHECK_ERROR(error);
	nic_ring = pg_nic_new_by_id("nic", 0, &error);
	CHECK_ERROR(error);
	pg_brick_link(nic_west, nic_ring, &error);
	CHECK_ERROR(error);

	for (i = 0; i < nb_iteration * 6; ++i) {
		/* max pkts is the maximum nbr of packets
		   rte_eth_burst_wrap can send */
		max_pkts = i * 2;
		if (max_pkts > 64)
			max_pkts = 64;
		/*poll packets to east*/
		pg_brick_poll(nic_west, &nb_send_pkts, &error);
		CHECK_ERROR(error);
		/* collect pkts on the east */
		if (nb_send_pkts) {
			total_send_pkts += max_pkts;
		}
		/* check no pkts end here */
		CHECK_ERROR(error);
	}
	pg_nic_get_stats(nic_ring, &info);
	g_assert(info.opackets == total_send_pkts);
	max_pkts = 64;
	for (i = 0; i < nb_iteration; ++i) {
		/* poll packet to the west */
		pg_brick_poll(nic_ring, &nb_send_pkts, &error);
		CHECK_ERROR(error);
		total_get_pkts += nb_send_pkts;
	}
	/* This assert allow us to check nb_send_pkts*/
	g_assert(total_get_pkts == total_send_pkts);
	g_assert(info.opackets == total_send_pkts);
	/* use packets_count in collect_west here to made
	 * another check when merge*/

	/* break the chain */
	pg_brick_destroy(nic_west);
	pg_brick_destroy(nic_ring);
}