void test_benchmark_queue(int argc, char **argv)
{
	struct pg_error *error = NULL;
	struct pg_brick *queue_enter;
	struct pg_brick *queue_exit;
	struct pg_bench bench;
	struct pg_bench_stats stats;
	struct ether_addr mac1 = {{0x52,0x54,0x00,0x12,0x34,0x11}};
	struct ether_addr mac2 = {{0x52,0x54,0x00,0x12,0x34,0x21}};
	uint32_t len;

	queue_enter = pg_queue_new("enter", 10, &error);
	if (error) {
		pg_error_print(error);
		g_assert(0);
	}
	queue_exit = pg_queue_new("enter", 10, &error);
	if (error) {
		pg_error_print(error);
		g_assert(0);
	}
	if (pg_queue_friend(queue_enter, queue_exit, &error)) {
		pg_error_print(error);
		g_assert(0);
	}

	g_assert(!pg_bench_init(&bench, "queue", argc, argv, &error));
	bench.input_brick = queue_enter;
	bench.input_side = WEST_SIDE;
	bench.output_brick = queue_exit;
	bench.output_side = WEST_SIDE;
	bench.output_poll = true;
	bench.max_burst_cnt = 1000000;
	bench.count_brick = NULL;
	bench.pkts_nb = 64;
	bench.pkts_mask = pg_mask_firsts(64);
	bench.pkts = pg_packets_create(bench.pkts_mask);
	bench.pkts = pg_packets_append_ether(
		bench.pkts,
		bench.pkts_mask,
		&mac1, &mac2,
		ETHER_TYPE_IPv4);
	len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + 1400;
	pg_packets_append_ipv4(
		bench.pkts,
		bench.pkts_mask,
		0x000000EE, 0x000000CC, len, 17);
	bench.pkts = pg_packets_append_udp(
		bench.pkts,
		bench.pkts_mask,
		1000, 2000, 1400);
	bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1400);

	g_assert(!pg_bench_run(&bench, &stats, &error));
	pg_bench_print(&stats);

	pg_packets_free(bench.pkts, bench.pkts_mask);
	pg_brick_destroy(queue_enter);
	pg_brick_destroy(queue_exit);
}
void test_benchmark_antispoof(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *antispoof;
	struct pg_bench bench;
	struct pg_bench_stats stats;
	struct ether_addr mac1 = {{0x52,0x54,0x00,0x12,0x34,0x11}};
	struct ether_addr mac2 = {{0x52,0x54,0x00,0x12,0x34,0x21}};
	uint32_t len;

	pg_bench_init(&bench);
	antispoof = pg_antispoof_new("antispoof", 1, 1, EAST_SIDE,
				     mac1, &error);
	g_assert(!error);
	pg_antispoof_arp_enable(antispoof, 0x000000EE);

	bench.input_brick = antispoof;
	bench.input_side = WEST_SIDE;
	bench.output_brick = antispoof;
	bench.output_side = EAST_SIDE;
	bench.output_poll = false;
	bench.max_burst_cnt = 10000000;
	bench.count_brick = NULL;
	bench.pkts_nb = 64;
	bench.pkts_mask = pg_mask_firsts(64);
	bench.pkts = pg_packets_create(bench.pkts_mask);
	bench.pkts = pg_packets_append_ether(
		bench.pkts,
		bench.pkts_mask,
		&mac1, &mac2,
		ETHER_TYPE_IPv4);
	len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) +
		sizeof(struct vxlan_hdr) + sizeof(struct ether_hdr) + 1400;
	pg_packets_append_ipv4(
		bench.pkts,
		bench.pkts_mask,
		0x000000EE, 0x000000CC, len, 17);
	bench.pkts = pg_packets_append_udp(
		bench.pkts,
		bench.pkts_mask,
		1000, 2000, 1400);
	bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1400);

	g_assert(pg_bench_run(&bench, &stats, &error));
	/* We know that this brick burst all packets. */
	stats.pkts_burst = stats.pkts_sent;
	g_assert(pg_bench_print(&stats, NULL));

	pg_packets_free(bench.pkts, bench.pkts_mask);
	pg_brick_destroy(antispoof);
}
void test_benchmark_print(int argc, char **argv)
{
	struct pg_error *error = NULL;
	struct pg_brick *print;
	struct pg_bench bench;
	struct pg_bench_stats stats;
	struct ether_addr mac1 = {{0x52,0x54,0x00,0x12,0x34,0x11}};
	struct ether_addr mac2 = {{0x52,0x54,0x00,0x12,0x34,0x21}};
	uint32_t len;

	g_assert(!pg_bench_init(&bench, "print", argc, argv, &error));
	print = pg_print_new("print", stderr,
			     PG_PRINT_FLAG_SUMMARY | PG_PRINT_FLAG_TIMESTAMP,
			     NULL, &error);
	g_assert(!error);

	bench.input_brick = print;
	bench.input_side = WEST_SIDE;
	bench.output_brick = print;
	bench.output_side = EAST_SIDE;
	bench.output_poll = false;
	bench.max_burst_cnt = 100000;
	bench.count_brick = NULL;
	bench.pkts_nb = 64;
	bench.pkts_mask = pg_mask_firsts(64);
	bench.pkts = pg_packets_create(bench.pkts_mask);
	bench.pkts = pg_packets_append_ether(
		bench.pkts,
		bench.pkts_mask,
		&mac1, &mac2,
		ETHER_TYPE_IPv4);
	bench.brick_full_burst = 1;
	len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + 1400;
	pg_packets_append_ipv4(
		bench.pkts,
		bench.pkts_mask,
		0x000000EE, 0x000000CC, len, 17);
	bench.pkts = pg_packets_append_udp(
		bench.pkts,
		bench.pkts_mask,
		1000, 2000, 1400);
	bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1400);

	g_assert(pg_bench_run(&bench, &stats, &error) == 0);
	pg_bench_print(&stats);

	pg_packets_free(bench.pkts, bench.pkts_mask);
	pg_brick_destroy(print);
}
Exemple #4
0
void test_benchmark_tap(int argc, char **argv)
{
	struct pg_error *error = NULL;
	struct pg_brick *tap_enter;
	struct pg_brick *tap_exit;
	struct pg_bench bench;
	struct pg_bench_stats stats;
	struct ether_addr mac1 = {{0x52,0x54,0x00,0x12,0x34,0x11}};
	struct ether_addr mac2 = {{0x52,0x54,0x00,0x12,0x34,0x21}};
	uint32_t len;

	tap_enter = pg_tap_new("tap 0", "bench0", &error);
	g_assert(tap_enter);
	g_assert(!error);
	tap_exit = pg_tap_new("tap 1", "bench1", &error);
	g_assert(tap_exit);
	g_assert(!error);
	/* put both tap in a linux bridge */
	run_ok("brctl -h &> /dev/null");
	run("ip netns del bench &> /dev/null");
	run_ok("ip netns add bench");
	run_ok("ip netns exec bench ip link set dev lo up");
	run_ok("ip link set bench0 up netns bench");
	run_ok("ip link set bench1 up netns bench");
	run_ok("ip netns exec bench brctl addbr br0");
	run_ok("ip netns exec bench brctl addif br0 bench0");
	run_ok("ip netns exec bench brctl addif br0 bench1");
	run_ok("ip netns exec bench ip link set br0 up");

	g_assert(!pg_bench_init(&bench, "tap", argc, argv, &error));
	bench.input_brick = tap_enter;
	bench.input_side = WEST_SIDE;
	bench.output_brick = tap_exit;
	bench.output_side = WEST_SIDE;
	bench.output_poll = true;
	bench.max_burst_cnt = 100000;
	bench.count_brick = NULL;
	bench.pkts_nb = 64;
	bench.pkts_mask = pg_mask_firsts(64);
	bench.pkts = pg_packets_create(bench.pkts_mask);
	bench.pkts = pg_packets_append_ether(
		bench.pkts,
		bench.pkts_mask,
		&mac1, &mac2,
		ETHER_TYPE_IPv4);
	len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + 1400;
	pg_packets_append_ipv4(
		bench.pkts,
		bench.pkts_mask,
		0x000000EE, 0x000000CC, len, 17);
	bench.pkts = pg_packets_append_udp(
		bench.pkts,
		bench.pkts_mask,
		1000, 2000, 1400);
	bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1400);

	g_assert(!pg_bench_run(&bench, &stats, &error));
	pg_bench_print(&stats);

	pg_packets_free(bench.pkts, bench.pkts_mask);
	pg_brick_destroy(tap_enter);
	pg_brick_destroy(tap_exit);
	run("ip netns del bench");
}
static void inside_to_vxlan(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *vtep;
	struct pg_bench bench;
	struct pg_bench_stats stats;
	struct pg_brick *inside_nop;
	struct ether_addr mac1 = {{0x52,0x54,0x00,0x12,0x34,0x11}};
	struct ether_addr mac2 = {{0x52,0x54,0x00,0x12,0x34,0x21}};
	struct ether_addr mac3 = {{0x52,0x54,0x00,0x12,0x34,0x31}};
	uint32_t len;

	pg_bench_init(&bench);
	vtep = pg_vtep_new("vtep", 1, 1, EAST_SIDE, inet_addr("192.168.0.1"),
			   mac3, NO_PACKETS_CLEANUP | NO_COPY |
			   NO_INNERMAC_CKECK, &error);
	g_assert(!error);

	inside_nop = pg_nop_new("nop-input", &error);
	bench.input_brick = inside_nop;
	bench.input_side = WEST_SIDE;
	bench.output_brick = vtep;
	bench.output_side = EAST_SIDE;
	bench.output_poll = false;
	bench.max_burst_cnt = 3000000;
	bench.count_brick = pg_nop_new("nop-inside", &error);
	bench.post_burst_op = remove_vtep_hdr;
	g_assert(!error);
	pg_brick_link(inside_nop, vtep, &error);
	g_assert(!error);
	pg_brick_link(vtep, bench.count_brick, &error);
	g_assert(!error);
	pg_vtep_add_vni(vtep, inside_nop, 0,
			inet_addr("224.0.0.5"), &error);
	g_assert(!error);
	bench.pkts_nb = 64;
	bench.pkts_mask = pg_mask_firsts(64);
	bench.pkts = pg_packets_create(bench.pkts_mask);
	bench.pkts = pg_packets_append_ether(
		bench.pkts,
		bench.pkts_mask,
		&mac1, &mac2,
		ETHER_TYPE_IPv4);
	len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + 1356;
	pg_packets_append_ipv4(
		bench.pkts,
		bench.pkts_mask,
		0x000000EE, 0x000000CC, len, 17);
	bench.pkts = pg_packets_append_udp(
		bench.pkts,
		bench.pkts_mask,
		1000, 2000, 1356);
	bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1356);

	//g_assert(pg_bench_run(&bench, &stats, &error));
	pg_bench_run(&bench, &stats, &error);
	pg_error_print(error);

	/* We know that this brick burst all packets. */
	stats.pkts_burst = stats.pkts_sent;
	printf("[inside] ==> [vtep] ==> [count] (VXLAN side)\n");
	g_assert(pg_bench_print(&stats, NULL));

	pg_packets_free(bench.pkts, bench.pkts_mask);
	pg_brick_destroy(vtep);
	pg_brick_destroy(inside_nop);
	pg_brick_destroy(bench.count_brick);
}
static void vxlan_to_inside(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *vtep;
	struct pg_bench bench;
	struct pg_bench_stats stats;
	struct pg_brick *outside_nop;
	struct ether_addr mac3 = {{0x52,0x54,0x00,0x12,0x34,0x31}};
	struct ether_addr mac4 = {{0x52,0x54,0x00,0x12,0x34,0x41}};
	static struct ether_addr mac_vtep = {{0xb0,0xb1,0xb2,0xb3,0xb4,0xb5}};
	uint32_t len;

	vtep = pg_vtep_new("vtep", 1, 1, WEST_SIDE, 0x000000EE,
			   mac_vtep,
			   NO_INNERMAC_CKECK | NO_PACKETS_CLEANUP | NO_COPY,
			   &error);
	g_assert(!error);

	pg_bench_init(&bench);
	outside_nop = pg_nop_new("nop-outside", &error);
	bench.input_brick = outside_nop;
	bench.input_side = WEST_SIDE;
	bench.output_brick = vtep;
	bench.output_side = EAST_SIDE;
	bench.output_poll = false;
	bench.max_burst_cnt = 1000000;
	bench.count_brick = pg_nop_new("nop-bench", &error);
	bench.post_burst_op = add_vtep_hdr;
	g_assert(!error);
	pg_brick_link(outside_nop, vtep, &error);
	g_assert(!error);
	pg_brick_link(vtep, bench.count_brick, &error);
	g_assert(!error);
	pg_vtep_add_vni(vtep, bench.count_brick, 1,
			inet_addr("224.0.0.1"), &error);
	pg_error_print(error);
	g_assert(!error);
	bench.pkts_nb = 64;
	bench.pkts_mask = pg_mask_firsts(64);
	bench.pkts = pg_packets_create(bench.pkts_mask);
	bench.pkts = pg_packets_append_ether(
		bench.pkts,
		bench.pkts_mask,
		&mac_vtep, &mac_vtep,
		ETHER_TYPE_IPv4);
	len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) +
		sizeof(struct vxlan_hdr) + sizeof(struct ether_hdr) + 1400;
	pg_packets_append_ipv4(
		bench.pkts,
		bench.pkts_mask,
		0x000000EE, 0x000000CC, len, 17);
	bench.pkts = pg_packets_append_udp(
		bench.pkts,
		bench.pkts_mask,
		1000, 2000, 1400);
	pg_packets_append_vxlan(bench.pkts, bench.pkts_mask, 1);
	bench.pkts = pg_packets_append_ether(
		bench.pkts,
		bench.pkts_mask,
		&mac3, &mac4,
		ETHER_TYPE_IPv4);
	bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1400);
	memcpy(vxlan_hdr, rte_pktmbuf_mtod(bench.pkts[0], void *), len - 1400);
	vxlan_hdr[sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) +
		  sizeof(struct vxlan_hdr) +
		  sizeof(struct ether_hdr)] = '\0';

	g_assert(pg_bench_run(&bench, &stats, &error));
	/* We know that this brick burst all packets. */
	stats.pkts_burst = stats.pkts_sent;
	printf("[outside] ==> [vtep] ==> [count] (no VXLAN side)\n");
	g_assert(pg_bench_print(&stats, NULL));

	pg_packets_free(bench.pkts, bench.pkts_mask);
	pg_brick_destroy(vtep);
	pg_brick_destroy(outside_nop);
	pg_brick_destroy(bench.count_brick);
}
static void inside_to_vxlan(int argc, char **argv)
{
	struct pg_error *error = NULL;
	struct pg_brick *vtep;
	struct pg_bench bench;
	struct pg_bench_stats stats;
	struct pg_brick *inside_nop;
	struct ether_addr mac1 = {{0x52,0x54,0x00,0x12,0x34,0x11}};
	struct ether_addr mac2 = {{0x52,0x54,0x00,0x12,0x34,0x21}};
	struct ether_addr mac3 = {{0x52,0x54,0x00,0x12,0x34,0x31}};
	uint32_t len;

	g_assert(!pg_bench_init(&bench, "vtep inside to vxlan",
				argc, argv, &error));
	vtep = pg_vtep_new("vtep", 1, 1, EAST_SIDE, inet_addr("192.168.0.1"),
			   mac3, PG_VTEP_DST_PORT, ALL_OPTI, &error);
	g_assert(!error);

	inside_nop = pg_nop_new("nop-input", &error);
	bench.input_brick = inside_nop;
	bench.input_side = WEST_SIDE;
	bench.output_brick = vtep;
	bench.output_side = EAST_SIDE;
	bench.output_poll = false;
	bench.max_burst_cnt = 3000000;
	bench.count_brick = pg_nop_new("nop-inside", &error);
	bench.post_burst_op = remove_vtep_hdr;
	g_assert(!error);
	pg_brick_link(inside_nop, vtep, &error);
	g_assert(!error);
	pg_brick_link(vtep, bench.count_brick, &error);
	g_assert(!error);
	pg_vtep_add_vni(vtep, inside_nop, 0,
			inet_addr("224.0.0.5"), &error);
	g_assert(!error);
	bench.pkts_nb = 64;
	bench.pkts_mask = pg_mask_firsts(64);
	bench.pkts = pg_packets_create(bench.pkts_mask);
	bench.pkts = pg_packets_append_ether(
		bench.pkts,
		bench.pkts_mask,
		&mac1, &mac2,
		ETHER_TYPE_IPv4);
	len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + 1356;
	pg_packets_append_ipv4(
		bench.pkts,
		bench.pkts_mask,
		0x000000EE, 0x000000CC, len, 17);
	bench.pkts = pg_packets_append_udp(
		bench.pkts,
		bench.pkts_mask,
		1000, PG_VTEP_DST_PORT, 1356);
	bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1356);
	bench.brick_full_burst = 1;

	//g_assert(pg_bench_run(&bench, &stats, &error));
	pg_bench_run(&bench, &stats, &error);
	g_assert(!pg_error_is_set(&error));

	pg_bench_print(&stats);

	pg_packets_free(bench.pkts, bench.pkts_mask);
	pg_brick_destroy(vtep);
	pg_brick_destroy(inside_nop);
	pg_brick_destroy(bench.count_brick);
}
static void vxlan_to_inside(int flags, const char *title, int argc, char **argv)
{
	struct pg_error *error = NULL;
	struct pg_brick *vtep;
	struct pg_bench bench;
	struct pg_bench_stats stats;
	struct pg_brick *outside_nop;
	struct ether_addr mac3 = {{0x52,0x54,0x00,0x12,0x34,0x31}};
	struct ether_addr mac4 = {{0x52,0x54,0x00,0x12,0x34,0x41}};
	static struct ether_addr mac_vtep = {{0xb0,0xb1,0xb2,0xb3,0xb4,0xb5}};
	uint32_t len;

	vtep = pg_vtep_new("vtep", 1, 1, WEST_SIDE, 0x000000EE,
			   mac_vtep, PG_VTEP_DST_PORT, flags, &error);
	g_assert(!error);

	g_assert(!pg_bench_init(&bench, title, argc, argv, &error));
	outside_nop = pg_nop_new("nop-outside", &error);
	bench.input_brick = outside_nop;
	bench.input_side = WEST_SIDE;
	bench.output_brick = vtep;
	bench.output_side = EAST_SIDE;
	bench.output_poll = false;
	bench.max_burst_cnt = 1000000;
	bench.count_brick = pg_nop_new("nop-bench", &error);
	if (flags & NO_COPY)
		bench.post_burst_op = add_vtep_hdr;
	g_assert(!error);
	pg_brick_link(outside_nop, vtep, &error);
	g_assert(!error);
	pg_brick_link(vtep, bench.count_brick, &error);
	g_assert(!error);

	pg_vtep_add_vni(vtep, bench.count_brick, 1,
			inet_addr("224.0.0.1"), &error);
	g_assert(!pg_error_is_set(&error));
	if (pg_vtep_add_mac(vtep, 1, &mac4, &error) < 0)
		pg_error_print(error);
	g_assert(!pg_error_is_set(&error));
	pg_vtep_add_mac(vtep, 1, &mac3, &error);
	if (pg_vtep_add_mac(vtep, 1, &mac4, &error) < 0)
		pg_error_print(error);
	g_assert(!pg_error_is_set(&error));

	bench.pkts_nb = 64;
	bench.pkts_mask = pg_mask_firsts(64);
	bench.pkts = pg_packets_create(bench.pkts_mask);
	bench.pkts = pg_packets_append_ether(
		bench.pkts,
		bench.pkts_mask,
		&mac_vtep, &mac_vtep,
		ETHER_TYPE_IPv4);
	bench.brick_full_burst = 1;
	len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) +
		sizeof(struct vxlan_hdr) + sizeof(struct ether_hdr) + 1400;
	pg_packets_append_ipv4(
		bench.pkts,
		bench.pkts_mask,
		0x000000EE, 0x000000CC, len, 17);
	bench.pkts = pg_packets_append_udp(
		bench.pkts,
		bench.pkts_mask,
		1000, PG_VTEP_DST_PORT, 1400);
	pg_packets_append_vxlan(bench.pkts, bench.pkts_mask, 1);
	bench.pkts = pg_packets_append_ether(
		bench.pkts,
		bench.pkts_mask,
		&mac3, &mac4,
		ETHER_TYPE_IPv4);
	bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1400);
	memcpy(vxlan_hdr, rte_pktmbuf_mtod(bench.pkts[0], void *), len - 1400);
	vxlan_hdr[sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) +
		  sizeof(struct vxlan_hdr) +
		  sizeof(struct ether_hdr)] = '\0';

	g_assert(pg_bench_run(&bench, &stats, &error) == 0);
	pg_bench_print(&stats);

	pg_packets_free(bench.pkts, bench.pkts_mask);
	pg_brick_destroy(vtep);
	pg_brick_destroy(outside_nop);
	pg_brick_destroy(bench.count_brick);
}