Esempio n. 1
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;
}
Esempio n. 2
0
static int packetsgen_init(struct pg_brick *brick,
			   struct pg_brick_config *config,
			   struct pg_error **errp)
{
	struct pg_packetsgen_state *state;
	struct pg_packetsgen_config *packetsgen_config;

	state = pg_brick_get_state(brick, struct pg_packetsgen_state);

	if (!config->brick_config) {
		*errp = pg_error_new("config->brick_config is NULL");
		return -1;
	}

	packetsgen_config = ((struct pg_packetsgen_config *)
			     config->brick_config);

	if (packetsgen_config->packets == NULL) {
		*errp = pg_error_new("packets argument is NULL");
		return -1;
	}

	if (packetsgen_config->packets_nb == 0) {
		*errp = pg_error_new("packet number must be positive");
		return -1;
	}

	state->output = packetsgen_config->output;
	state->packets = packetsgen_config->packets;
	state->packets_nb = packetsgen_config->packets_nb;

	if (pg_error_is_set(errp))
		return -1;

	/* Initialize fast path */
	brick->burst = packetsgen_burst;
	brick->poll = packetsgen_poll;

	return 0;
}
Esempio n. 3
0
static void test_queue_friend(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *q1, *q2, *q3;

	q1 = pg_queue_new("q1", 1, &error);
	CHECK_ERROR(error);
	q2 = pg_queue_new("q2", 1, &error);
	CHECK_ERROR(error);
	q3 = pg_queue_new("q3", 1, &error);
	CHECK_ERROR(error);

	/* classic scenario */
	g_assert(!pg_queue_get_friend(q1));
	g_assert(!pg_queue_get_friend(q2));
	g_assert(!pg_queue_friend(q1, q2, &error));
	CHECK_ERROR(error);
	g_assert(pg_queue_get_friend(q1) == q2);
	g_assert(pg_queue_are_friend(q1, q2));
	g_assert(pg_queue_get_friend(q2) == q1);
	g_assert(pg_queue_are_friend(q2, q1));
	pg_queue_unfriend(q1);
	g_assert(!pg_queue_get_friend(q1));
	g_assert(!pg_queue_are_friend(q1, q2));
	g_assert(!pg_queue_get_friend(q2));
	g_assert(!pg_queue_are_friend(q2, q1));

	/* same but unfriend with second brick */
	g_assert(!pg_queue_friend(q1, q2, &error));
	CHECK_ERROR(error);
	g_assert(pg_queue_are_friend(q1, q2));
	g_assert(pg_queue_are_friend(q2, q1));
	pg_queue_unfriend(q2);
	g_assert(!pg_queue_get_friend(q1));
	g_assert(!pg_queue_get_friend(q2));

	/* friend with itself */
	g_assert(!pg_queue_friend(q1, q1, &error));
	CHECK_ERROR(error);
	g_assert(pg_queue_get_friend(q1) == q1);
	g_assert(pg_queue_are_friend(q1, q1));
	pg_queue_unfriend(q1);
	g_assert(!pg_queue_get_friend(q1));

	/* several unfriend ok ? (test should die if not) */
	pg_queue_unfriend(q1);
	pg_queue_unfriend(q1);
	pg_queue_unfriend(q1);

	/* error if already friend */
	g_assert(!pg_queue_friend(q1, q2, &error));
	CHECK_ERROR(error);
	g_assert(pg_queue_friend(q1, q2, &error) == -1);
	g_assert(pg_error_is_set(&error));
	pg_error_free(error);
	error = NULL;
	g_assert(pg_queue_friend(q2, q1, &error) == -1);
	g_assert(pg_error_is_set(&error));
	pg_error_free(error);
	error = NULL;
	g_assert(pg_queue_friend(q1, q3, &error) == -1);
	g_assert(pg_error_is_set(&error));
	pg_error_free(error);
	error = NULL;
	g_assert(pg_queue_friend(q2, q3, &error) == -1);
	g_assert(pg_error_is_set(&error));
	pg_error_free(error);
	error = NULL;
	g_assert(pg_queue_friend(q3, q1, &error) == -1);
	g_assert(pg_error_is_set(&error));
	pg_error_free(error);
	error = NULL;
	g_assert(pg_queue_friend(q3, q2, &error) == -1);
	g_assert(pg_error_is_set(&error));
	pg_error_free(error);
	error = NULL;

	/* check that death break friendship */
	pg_brick_decref(q1, &error);
	CHECK_ERROR(error);
	g_assert(!pg_queue_get_friend(q2));

	/* ... and can be friend again */
	g_assert(!pg_queue_friend(q2, q3, &error));
	g_assert(pg_queue_are_friend(q2, q3));
	g_assert(pg_queue_are_friend(q3, q2));

	pg_brick_decref(q2, &error);
	CHECK_ERROR(error);
	pg_brick_decref(q3, &error);
	CHECK_ERROR(error);
}
Esempio n. 4
0
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);
}
Esempio n. 5
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);
}