Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	struct pg_brick *nic = NULL;
	struct pg_error *error = NULL;
	uint32_t rx, tx;
	int port_count;

	pg_start(argc, argv, &error);
	if (pg_error_is_set(&error)) {
		pg_error_print(error);
		pg_error_free(error);
		return 1;
	}

	port_count = pg_nic_port_count();
	if (port_count == 0) {
		printf("Error: you need at least one DPDK port\n");
		return 1;
	}

	for (int i = 0; i < port_count; i++) {
		nic = pg_nic_new_by_id("nic", i, &error);
		if (!nic) {
			printf("Error on nic creation (port %i)\n", i);
			pg_error_print(error);
			pg_error_free(error);
			pg_stop();
			return 1;
		}
		pg_nic_capabilities(nic, &rx, &tx);
		printf("====== Port %i capabilities ======\nRX:\n", i);
#define print_capa(R, capa) \
		printf(#capa ":\t\t%s\n", (R) & (capa) ? "yes" : "no");
		print_capa(rx, PG_NIC_RX_OFFLOAD_VLAN_STRIP);
		print_capa(rx, PG_NIC_RX_OFFLOAD_IPV4_CKSUM);
		print_capa(rx, PG_NIC_RX_OFFLOAD_UDP_CKSUM);
		print_capa(rx, PG_NIC_RX_OFFLOAD_TCP_CKSUM);
		print_capa(rx, PG_NIC_RX_OFFLOAD_TCP_LRO);
		print_capa(rx, PG_NIC_RX_OFFLOAD_QINQ_STRIP);
		print_capa(rx, PG_NIC_RX_OFFLOAD_OUTER_IPV4_CKSUM);
		printf("TX:\n");
		print_capa(tx, PG_NIC_TX_OFFLOAD_VLAN_INSERT);
		print_capa(tx, PG_NIC_TX_OFFLOAD_IPV4_CKSUM);
		print_capa(tx, PG_NIC_TX_OFFLOAD_UDP_CKSUM);
		print_capa(tx, PG_NIC_TX_OFFLOAD_TCP_CKSUM);
		print_capa(tx, PG_NIC_TX_OFFLOAD_SCTP_CKSUM);
		print_capa(tx, PG_NIC_TX_OFFLOAD_TCP_TSO);
		print_capa(tx, PG_NIC_TX_OFFLOAD_UDP_TSO);
		print_capa(tx, PG_NIC_TX_OFFLOAD_OUTER_IPV4_CKSUM);
		print_capa(tx, PG_NIC_TX_OFFLOAD_QINQ_INSERT);
#undef print_capa
		pg_brick_destroy(nic);
	}
	pg_stop();
	return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	struct pg_error *error = NULL;
	struct pg_brick *nic, *app;
	struct pg_graph *graph;
	struct mydata pd;

	pd.pkt_count = 0;
	pg_start(argc, argv, &error);
	start_time = g_get_real_time();

	if (pg_nic_port_count() < 1) {
		g_printf("No NIC port has been found, try adding --vdev=eth_pcap0,iface=eth0 arguments\n");
		return 1;
	}

	nic = pg_nic_new_by_id("port 0", 0, &error);
	app = pg_rxtx_new("myapp", &rx_callback, &tx_callback, (void *) &pd);
	pg_brick_link(nic, app, &error);

	graph = pg_graph_new("example", nic, &error);

	while (42)
		if (pg_graph_poll(graph, &error) < 0)
			break;
	pg_error_print(error);
	pg_error_free(error);
	pg_graph_destroy(graph);
	pg_stop();
	return 1;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
	/**
	 * Simple example of firewall between two NICs.
	 * Print brick simply show packets.
	 *
	 * [nic-west]--[print-west]--[firewall]--[print-east]--[nic_east]
	 */

	struct pg_error *error = NULL;
	struct pg_brick *nic_west, *nic_east;
	struct pg_brick *print_west, *print_east;
	struct pg_brick *fw;
	struct pg_graph *graph;

	/* init packetgraph and nics */
	pg_start(argc, argv, &error);
	if (pg_nic_port_count() < 2) {
		printf("You need two DPDK ports to run this example\n");
		return 1;
	}

	/* create bricks */
	nic_west = pg_nic_new_by_id("nic-west", 0, &error);
	fw = pg_firewall_new("fw", PG_NO_CONN_WORKER, &error);
	print_west = pg_print_new("print-west", 0,
				  PG_PRINT_FLAG_MAX, 0, &error);
	print_east = pg_print_new("print-east", 0,
				  PG_PRINT_FLAG_MAX, 0, &error);
	nic_east = pg_nic_new_by_id("nic_east", 1, &error);

	/* link bricks */
	pg_brick_chained_links(&error, nic_west, print_west,
			       fw, print_east, nic_east);

	/* add some rules to firewall */
	pg_firewall_rule_add(fw, "tcp portrange 1-1024", PG_MAX_SIDE, 1, &error);
	pg_firewall_rule_add(fw, "icmp", PG_MAX_SIDE, 1, &error);
	pg_firewall_reload(fw, &error);

	/* create a graph with all bricks inside */
	graph = pg_graph_new("graph", fw, &error);

	printf("let's pool 1000*1000 times ...\n");
	for (int i = 0; i < 1000000; i++) {
		if (pg_graph_poll(graph, &error) < 0) {
			pg_error_print(error);
			pg_error_free(error);
		}
	}

	pg_graph_destroy(graph);
	pg_stop();
	return 0;
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
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);
}
Exemplo n.º 7
0
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);
}