Esempio n. 1
0
static void test_brick_verify_re_link_monopole(void)
{
	struct pg_brick *west_brick, *east_brick;
	struct pg_error *error = NULL;

	west_brick = pg_queue_new("q1", 1, &error);
	g_assert(!error);
	east_brick = pg_queue_new("q2", 1, &error);
	g_assert(!error);

	/* We link the 2 bricks */
	pg_brick_link(west_brick, east_brick, &error);
	g_assert(!error);

	/* We unlink them  */
	pg_brick_unlink(west_brick, &error);
	g_assert(!error);

	/* We relink them to make sure unlink works */
	pg_brick_link(west_brick, east_brick, &error);
	g_assert(!error);

	pg_brick_destroy(west_brick);
	pg_brick_destroy(east_brick);

	
}
Esempio n. 2
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);
}
Esempio n. 3
0
static void test_brick_core_verify_re_link(void)
{
	struct pg_error *e = NULL;
	struct pg_brick *v = pg_nop_new("v", &e);
	g_assert(!e);
	struct pg_brick *f = pg_nop_new("f", &e);
	g_assert(!e);
	struct pg_brick *a = pg_nop_new("a", &e);
	g_assert(!e);
	struct pg_brick *s = pg_nop_new("s", &e);
	g_assert(!e);

	/* Initial state: v -- f -- a */
	pg_brick_chained_links(&e, v, f, a);
	g_assert(!e);
	test_brick_sanity_check_expected(v, 0, 1);
	test_brick_sanity_check_expected(f, 1, 1);
	test_brick_sanity_check_expected(a, 1, 0);

	/* Unlink f */
	pg_brick_unlink(f, &e);
	g_assert(!e);
	test_brick_sanity_check_expected(v, 0, 0);
	test_brick_sanity_check_expected(f, 0, 0);
	test_brick_sanity_check_expected(a, 0, 0);

	/* Link v and s */
	pg_brick_link(v, s, &e);
	g_assert(!e);
	test_brick_sanity_check_expected(v, 0, 1);
	test_brick_sanity_check_expected(s, 1, 0);
	test_brick_sanity_check_expected(f, 0, 0);
	test_brick_sanity_check_expected(a, 0, 0);

	/* link the rest to have v -- s -- f -- a */
	pg_brick_link(s, f, &e);
	g_assert(!e);
	test_brick_sanity_check_expected(v, 0, 1);
	test_brick_sanity_check_expected(s, 1, 1);
	test_brick_sanity_check_expected(f, 1, 0);
	test_brick_sanity_check_expected(a, 0, 0);

	pg_brick_link(f, a, &e);
	g_assert(!e);
	test_brick_sanity_check_expected(v, 0, 1);
	test_brick_sanity_check_expected(s, 1, 1);
	test_brick_sanity_check_expected(f, 1, 1);
	test_brick_sanity_check_expected(a, 1, 0);

	pg_brick_destroy(a);
	pg_brick_destroy(v);
	pg_brick_destroy(f);
	pg_brick_destroy(s);
}
Esempio n. 4
0
static void test_antispoof_rarp(void)
{
#	include "rarp.c"
	const unsigned char *pkts[] = {pkt1};
	int pkts_size[] = {15};
	uint16_t pkts_nb = 1;
	struct ether_addr inside_mac;
	struct pg_brick *gen_west;
	struct pg_brick *antispoof;
	struct pg_brick *col_east;
	struct pg_error *error = NULL;
	uint16_t packet_count;
	uint16_t i;
	struct rte_mbuf *packet;
	uint64_t filtered_pkts_mask;

	pg_scan_ether_addr(&inside_mac, "00:23:df:ff:c9:23");

	/* [generator>]--[antispoof]--[collector] */
	gen_west = pg_packetsgen_new("gen_west", 1, 1, EAST_SIDE,
				     &packet, 1, &error);
	g_assert(!error);
	antispoof = pg_antispoof_new("antispoof", 1, 1, EAST_SIDE,
				     inside_mac, &error);
	g_assert(!error);
	col_east = pg_collect_new("col_east", 1, 1, &error);
	g_assert(!error);
	pg_brick_link(gen_west, antispoof, &error);
	g_assert(!error);
	pg_brick_link(antispoof, col_east, &error);
	g_assert(!error);

	/* replay traffic */
	for (i = 0; i < pkts_nb; i++) {
		packet = build_packet(pkts[i], pkts_size[i]);
		pg_brick_poll(gen_west, &packet_count, &error);
		g_assert(!error);
		g_assert(packet_count == 1);
		pg_brick_west_burst_get(col_east, &filtered_pkts_mask, &error);
		g_assert(!error);
		g_assert(pg_mask_count(filtered_pkts_mask) == 0);
		rte_pktmbuf_free(packet);
	}
	pg_brick_destroy(gen_west);
	pg_brick_destroy(antispoof);
	pg_brick_destroy(col_east);

}
Esempio n. 5
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. 6
0
static void test_sorting_pmtud(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *pmtud;
	struct pg_brick *col_east;
	struct rte_mbuf **pkts;
	uint64_t pkts_mask;
	struct ether_addr eth = {{0}};

	pkts = pg_packets_append_ether(pg_packets_create(pg_mask_firsts(64)),
				       pg_mask_firsts(64),  &eth, &eth,
				       ETHER_TYPE_IPv4);
	pg_packets_append_ipv4(pkts, pg_mask_firsts(64), 1, 2, 0, 0);
	

	pg_packets_append_blank(pkts,
				pg_mask_firsts(32),
				431 - sizeof(struct ipv4_hdr) -
				sizeof(struct ether_hdr));
	pg_packets_append_blank(pkts,
				pg_mask_firsts(64) & ~pg_mask_firsts(32),
				430 - sizeof(struct ipv4_hdr) -
				sizeof(struct ether_hdr));
	pmtud = pg_pmtud_new("pmtud", PG_WEST_SIDE, 430, &error);
	g_assert(!error);
	col_east = pg_collect_new("col_east", &error);
	g_assert(!error);
	pg_brick_link(pmtud, col_east, &error);
	g_assert(!error);

	pg_brick_burst(pmtud, PG_WEST_SIDE, 0, pkts, pg_mask_firsts(64), &error);
	g_assert(!error);

	pg_brick_west_burst_get(col_east, &pkts_mask, &error);
	g_assert(!error);
	g_assert(pg_mask_count(pkts_mask) == 32);

	pg_brick_destroy(pmtud);
	pg_brick_destroy(col_east);
	pg_packets_free(pkts, pg_mask_firsts(64));
	g_free(pkts);
}
Esempio n. 7
0
static void test_queue_lifecycle(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *brick;
	struct pg_queue_state *state;

	brick = pg_queue_new("test_queue", 0, &error);
	g_assert(brick);
	CHECK_ERROR(error);
	state = pg_brick_get_state(brick, struct pg_queue_state);
	g_assert(state->rx_max_size == 10);
	pg_brick_destroy(brick);
	brick = pg_queue_new("test_queue", 1, &error);
	g_assert(brick);
	CHECK_ERROR(error);
	state = pg_brick_get_state(brick, struct pg_queue_state);
	g_assert(state->rx_max_size == 1);

	pg_brick_destroy(brick);
	CHECK_ERROR(error);
}
Esempio n. 8
0
static void test_sorting_pmtud_df(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *pmtud;
	struct pg_brick *col_east;
	struct rte_mbuf **pkts;
	uint64_t pkts_mask;
	struct ether_addr eth = {{0}};
	uint64_t buff[4] = {0, 0, 0, 0};

	pkts = pg_packets_append_ether(pg_packets_create(pg_mask_firsts(64)),
				       pg_mask_firsts(64),  &eth, &eth,
				       ETHER_TYPE_IPv4);
	pg_packets_append_ipv4(pkts, pg_mask_firsts(32), 1, 2, 0, 0);
	

	/* Initialise ip header to 0, this ensure that DF flag is not set*/
	pg_packets_append_buf(pkts,
			      pg_mask_firsts(64) & ~pg_mask_firsts(32),
			      buff, sizeof(uint64_t) * 4);
	pg_packets_append_blank(pkts, pg_mask_firsts(64), 400);
	pmtud = pg_pmtud_new("pmtud", PG_WEST_SIDE, 430, &error);
	g_assert(!error);
	col_east = pg_collect_new("col_east", &error);
	g_assert(!error);
	pg_brick_link(pmtud, col_east, &error);
	g_assert(!error);

	pg_brick_burst(pmtud, PG_WEST_SIDE, 0, pkts, pg_mask_firsts(64), &error);
	g_assert(!error);

	pg_brick_west_burst_get(col_east, &pkts_mask, &error);
	g_assert(!error);
	g_assert(pg_mask_count(pkts_mask) == 32);

	pg_brick_destroy(pmtud);
	pg_brick_destroy(col_east);
	pg_packets_free(pkts, pg_mask_firsts(64));
	g_free(pkts);
}
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);
}
Esempio n. 10
0
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);
}
Esempio n. 11
0
static void test_vhost_fd(void)
{
	struct pg_brick *vhost[VHOST_CNT];
	struct pg_error *error = NULL;

	g_assert(pg_vhost_start("/tmp", &error) == 0);
	g_assert(!error);

	for (int j = 0; j < 10; j++) {
		for (int i = 0; i < VHOST_CNT; i++) {
			gchar *name = g_strdup_printf("vhost-%i", i);
			vhost[i] = pg_vhost_new(name, &error);
			g_free(name);
			g_assert(!error);
			g_assert(vhost[i]);
		}
		for (int i = 0; i < VHOST_CNT; i++) {
			pg_brick_destroy(vhost[i]);
			g_assert(!error);
		}
	}
	pg_vhost_stop();
}
Esempio n. 12
0
static void test_antispoof_generic(const unsigned char **pkts,
				   int *pkts_size,
				   uint16_t pkts_nb,
				   struct ether_addr inside_mac,
				   uint32_t inside_ip)
{
	struct pg_brick *gen_west;
	struct pg_brick *antispoof;
	struct pg_brick *col_east;
	struct pg_error *error = NULL;
	uint16_t packet_count;
	uint16_t i;
	struct rte_mbuf *packet;
	uint64_t filtered_pkts_mask;
	struct rte_mbuf **filtered_pkts;

	/* [generator>]--[antispoof]--[collector] */
	gen_west = pg_packetsgen_new("gen_west", 1, 1, EAST_SIDE,
				     &packet, 1, &error);
	g_assert(!error);
	antispoof = pg_antispoof_new("antispoof", 1, 1, EAST_SIDE,
				     inside_mac, &error);
	g_assert(!error);
	col_east = pg_collect_new("col_east", 1, 1, &error);
	g_assert(!error);
	pg_brick_link(gen_west, antispoof, &error);
	g_assert(!error);
	pg_brick_link(antispoof, col_east, &error);
	g_assert(!error);

	/* enable ARP antispoof with the correct IP */
	pg_antispoof_arp_enable(antispoof, inside_ip);

	/* replay traffic */
	for (i = 0; i < pkts_nb; i++) {
		packet = build_packet(pkts[i], pkts_size[i]);
		pg_brick_poll(gen_west, &packet_count, &error);
		g_assert(!error);
		g_assert(packet_count == 1);
		filtered_pkts = pg_brick_west_burst_get(col_east,
							&filtered_pkts_mask,
							&error);
		g_assert(!error);
		g_assert(pg_mask_count(filtered_pkts_mask) == 1);
		pg_packets_free(filtered_pkts, filtered_pkts_mask);
		rte_pktmbuf_free(packet);
	}

	/* set another IP, should not pass */
	inside_ip = htobe32(IPv4(42, 0, 42, 0));
	pg_antispoof_arp_enable(antispoof, inside_ip);

	/* replay traffic */
	for (i = 0; i < pkts_nb; i++) {
		packet = build_packet(pkts[i], pkts_size[i]);
		pg_brick_poll(gen_west, &packet_count, &error);
		g_assert(!error);
		g_assert(packet_count == 1);
		filtered_pkts = pg_brick_west_burst_get(col_east,
							&filtered_pkts_mask,
							&error);
		g_assert(!error);
		g_assert(pg_mask_count(filtered_pkts_mask) == 0);
		pg_packets_free(filtered_pkts, filtered_pkts_mask);
		rte_pktmbuf_free(packet);
	}

	pg_brick_destroy(gen_west);
	pg_brick_destroy(antispoof);
	pg_brick_destroy(col_east);
}
Esempio n. 13
0
static void test_icmp_pmtud(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *pmtud;
	struct pg_brick *col_east;
	struct pg_brick *col_west;
	/* struct pg_brick *print_east; */
	/* struct pg_brick *print_west; */
	/* FILE *east_file = fopen("east_file.pcap", "w+"); */
	/* FILE *west_file = fopen("west_file.pcap", "w+"); */
	struct rte_mbuf **pkts;
	struct rte_mbuf *tmp;
	uint64_t pkts_mask;
	struct ether_addr eth_s = {{2}};
	struct ether_addr eth_d = {{4}};

	pkts = pg_packets_append_ether(pg_packets_create(pg_mask_firsts(64)),
				       pg_mask_firsts(64),  &eth_s, &eth_d,
				       ETHER_TYPE_IPv4);
	pg_packets_append_ipv4(pkts, pg_mask_firsts(64), 1, 2, 0, 0);
	

	/* 10 caracter with the \0*/
	pg_packets_append_str(pkts, pg_mask_firsts(64), "siegzeon ");
	pg_packets_append_blank(pkts,
				pg_mask_firsts(32),
				421 - sizeof(struct ipv4_hdr) -
				sizeof(struct ether_hdr));
	pg_packets_append_blank(pkts,
				pg_mask_firsts(64) & ~pg_mask_firsts(32),
				420 - sizeof(struct ipv4_hdr) -
				sizeof(struct ether_hdr));

	/*
	 * [col_west] -- [print_west] -- [pmtud] -- [print_east] -- [col_east]
	 */

	pmtud = pg_pmtud_new("pmtud", PG_WEST_SIDE, 430, &error);
	g_assert(!error);
	col_east = pg_collect_new("col_east", &error);
	g_assert(col_east);
	g_assert(!error);
	col_west = pg_collect_new("col_west", &error);
	g_assert(!error);
	g_assert(col_west);

	/* print_east = pg_print_new("print_east", 1, 1, east_file, */
	/* 			PG_PRINT_FLAG_PCAP,  NULL, &error); */
	/* g_assert(col_east); */
	/* g_assert(!error); */
	/* print_west = pg_print_new("print_west", 1, 1, west_file, */
	/* 			PG_PRINT_FLAG_PCAP, NULL, &error); */
	/* g_assert(!error); */
	/* g_assert(col_west); */


	/* pg_brick_chained_links(&error, col_west, print_west, pmtud, */
	/* 		       print_east, col_east); */
	/* g_assert(!error); */

	pg_brick_chained_links(&error, col_west, pmtud, col_east);
	g_assert(!error);

	pg_brick_burst_to_east(pmtud, 0, pkts, pg_mask_firsts(64), &error);
	g_assert(!error);

	pg_brick_west_burst_get(col_east, &pkts_mask, &error);
	g_assert(!error);
	g_assert(pg_mask_count(pkts_mask) == 32);

	g_assert(pg_brick_pkts_count_get(pmtud, PG_EAST_SIDE) == 64);
	g_assert(pg_brick_pkts_count_get(col_east, PG_EAST_SIDE) == 32);
	g_assert(pg_brick_pkts_count_get(col_west, PG_WEST_SIDE) == 32);
	tmp = pg_brick_east_burst_get(col_west, &pkts_mask, &error)[0];
	g_assert(pkts_mask == 1);
	g_assert(tmp);

	pg_brick_destroy(col_west);
	pg_brick_destroy(pmtud);
	pg_brick_destroy(col_east);
	pg_packets_free(pkts, pg_mask_firsts(64));
	/* fclose(east_file); */
	/* fclose(west_file); */
	g_free(pkts);
	return;
}
Esempio n. 14
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");
}
Esempio n. 15
0
static void pg_brick_destroy_wraper(void *arg)
{
	pg_brick_destroy(arg);
}
Esempio n. 16
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);
}
Esempio n. 17
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);
}
Esempio n. 18
0
static int start_loop(uint32_t vtep_ip, struct ether_addr *vtep_mac,
                      struct ether_addr *inner_mac,
                      GList *neighbor_macs)
{
    struct pg_error *error = NULL;
    struct pg_brick *nic_east, *nic_west, *vtep_east, *vtep_west;
    struct pg_brick *print_east, *print_west, *print_middle;

    /*
     * Here is an ascii graph of the links:
     * NIC = nic
     * VT = vtep
     *
     * [NIC] - [PRINT] - [VT] -- [PRINT] -- [VT] -- [PRINT] -- [NIC]
     */
    nic_east = pg_nic_new_by_id("nic-e", 1, 1, EAST_SIDE, 0, &error);
    CHECK_ERROR(error);
    nic_west = pg_nic_new_by_id("nic-w", 1, 1, WEST_SIDE, 1, &error);
    CHECK_ERROR(error);
    vtep_east = pg_vtep_new("vt-e", 1, 1, WEST_SIDE,
                            vtep_ip, *vtep_mac, 1, &error);
    CHECK_ERROR(error);
    inverse_mac(vtep_mac);
    pg_print_mac(vtep_mac);
    printf("\n");
    vtep_west = pg_vtep_new("vt-w", 1, 1, EAST_SIDE,
                            ~vtep_ip, *vtep_mac, 1, &error);
    CHECK_ERROR(error);
    print_west = pg_print_new("west", 1, 1, NULL, PG_PRINT_FLAG_MAX, NULL,
                              &error);
    CHECK_ERROR(error);
    print_east = pg_print_new("east", 1, 1, NULL, PG_PRINT_FLAG_MAX, NULL,
                              &error);
    CHECK_ERROR(error);
    print_middle = pg_print_new("middle", 1, 1, NULL, PG_PRINT_FLAG_MAX,
                                NULL, &error);
    CHECK_ERROR(error);

    /* If you want to print transmiting pkts uncomment this and coment
     * the bellow pg_brick_chained_links
     * Attention: this may slow down the transmition */
    /* pg_brick_chained_links(&error, nic_west, print_west, */
    /* 		    vtep_west, print_middle, vtep_east, */
    /* 		    print_east, nic_east); */
    pg_brick_chained_links(&error, nic_west, vtep_west, vtep_east, nic_east);
    CHECK_ERROR(error);
    pg_vtep_add_vni(vtep_west, nic_west, 0, inet_addr("225.0.0.43"), &error);
    CHECK_ERROR(error);
    pg_vtep_add_vni(vtep_east, nic_east, 0, inet_addr("225.0.0.43"), &error);
    CHECK_ERROR(error);
    while (!quit) {
        uint16_t nb_send_pkts;

        g_assert(pg_brick_poll(nic_west, &nb_send_pkts, &error));
        usleep(1);
        g_assert(pg_brick_poll(nic_east, &nb_send_pkts, &error));
        usleep(1);
    }
    pg_brick_destroy(nic_west);
    pg_brick_destroy(print_west);
    pg_brick_destroy(vtep_west);
    pg_brick_destroy(print_middle);
    pg_brick_destroy(vtep_east);
    pg_brick_destroy(print_east);
    pg_brick_destroy(nic_east);

    return 0;
}
Esempio n. 19
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. 20
0
static void test_pg_antispoof_arp_disable(void)
{
#	include "arp_request.c"
	const unsigned char *pkts[] = {pkt1};
	int pkts_size[] = {42};
	uint16_t pkts_nb = 1;
	struct ether_addr inside_mac;
	uint32_t inside_ip;
	struct pg_brick *gen_west;
	struct pg_brick *antispoof;
	struct pg_brick *col_east;
	struct pg_error *error = NULL;
	uint16_t packet_count;
	uint16_t i;
	struct rte_mbuf *packet;
	uint64_t filtered_pkts_mask;
	struct rte_mbuf **filtered_pkts;

	pg_scan_ether_addr(&inside_mac, "00:e0:81:d5:02:91");
	inside_ip = htobe32(IPv4(0, 0, 0, 42));

	/* [generator>]--[antispoof]--[collector] */
	gen_west = pg_packetsgen_new("gen_west", 1, 1, EAST_SIDE,
				     &packet, 1, &error);
	g_assert(!error);
	antispoof = pg_antispoof_new("antispoof", 1, 1, EAST_SIDE,
				     inside_mac, &error);
	g_assert(!error);
	col_east = pg_collect_new("col_east", 1, 1, &error);
	g_assert(!error);
	pg_brick_link(gen_west, antispoof, &error);
	g_assert(!error);
	pg_brick_link(antispoof, col_east, &error);
	g_assert(!error);

	/* enable ARP antispoof with a wrong IP */
	pg_antispoof_arp_enable(antispoof, inside_ip);

	/* replay traffic */
	for (i = 0; i < pkts_nb; i++) {
		packet = build_packet(pkts[i], pkts_size[i]);
		pg_brick_poll(gen_west, &packet_count, &error);
		g_assert(!error);
		g_assert(packet_count == 1);
		filtered_pkts = pg_brick_west_burst_get(col_east,
							&filtered_pkts_mask,
							&error);
		g_assert(!error);
		g_assert(pg_mask_count(filtered_pkts_mask) == 0);
		pg_packets_free(filtered_pkts, filtered_pkts_mask);
		rte_pktmbuf_free(packet);
	}

	/* disable ARP antispoof, should now pass */
	pg_antispoof_arp_disable(antispoof);

	/* replay traffic */
	for (i = 0; i < pkts_nb; i++) {
		packet = build_packet(pkts[i], pkts_size[i]);
		pg_brick_poll(gen_west, &packet_count, &error);
		g_assert(!error);
		g_assert(packet_count == 1);
		filtered_pkts = pg_brick_west_burst_get(col_east,
							&filtered_pkts_mask,
							&error);
		g_assert(!error);
		g_assert(pg_mask_count(filtered_pkts_mask) == 1);
		pg_packets_free(filtered_pkts, filtered_pkts_mask);
		rte_pktmbuf_free(packet);
	}

	pg_brick_destroy(gen_west);
	pg_brick_destroy(antispoof);
	pg_brick_destroy(col_east);
}
Esempio n. 21
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);
}
Esempio n. 22
0
static void firewall_filter_rules(enum pg_side dir)
{
	struct pg_brick *gen;
	struct pg_brick *fw;
	struct pg_brick *col;
	struct pg_error *error = NULL;
	uint16_t i;
	int ret;
	static uint16_t nb = 30;
	struct rte_mbuf *packets[nb];
	uint64_t filtered_pkts_mask;
	struct rte_mbuf **filtered_pkts;
	uint64_t bit;
	uint16_t packet_count;
	struct ip *ip;
	struct ether_hdr *eth;

	/* create and connect 3 bricks: generator -> firewall -> collector */
	gen = pg_packetsgen_new("gen", 2, 2, pg_flip_side(dir), packets, nb, &error);
	g_assert(!error);
	fw = pg_firewall_new("fw", 2, 2, PG_NONE, &error);
	g_assert(!error);
	col = pg_collect_new("col", 2, 2, &error);
	g_assert(!error);
	/* revert link if needed */
	if (dir == WEST_SIDE) {
		pg_brick_link(gen, fw, &error);
		g_assert(!error);
		pg_brick_link(fw, col, &error);
		g_assert(!error);
	} else {
		pg_brick_link(col, fw, &error);
		g_assert(!error);
		pg_brick_link(fw, gen, &error);
		g_assert(!error);
	}

	/* build some UDP packets mixed sources */
	for (i = 0; i < nb; i++)
		switch (i % 3) {
		case 0:
			packets[i] = build_ip_packet("10.0.0.1",
						     "10.0.0.255", i);
			break;
		case 1:
			packets[i] = build_ip_packet("10.0.0.2",
						     "10.0.0.255", i);
			break;
		case 2:
			packets[i] = build_ip_packet("10.0.0.3",
						     "10.0.0.255", i);
			break;
		}

	/* configure firewall to allow traffic from 10.0.0.1 */
	ret = pg_firewall_rule_add(fw, "src host 10.0.0.1", dir, 0, &error);
	g_assert(!error);
	g_assert(ret == 0);
	ret = pg_firewall_reload(fw, &error);
	g_assert(ret < 0);
	g_assert(!error);

	/* let's burst ! */
	pg_brick_poll(gen, &packet_count, &error);
	g_assert(!error);
	g_assert(packet_count == nb);

	/* check collect brick */
	if (dir == WEST_SIDE)
		filtered_pkts = pg_brick_west_burst_get(col, &filtered_pkts_mask,
						     &error);
	else
		filtered_pkts = pg_brick_east_burst_get(col, &filtered_pkts_mask,
						     &error);
	g_assert(!error);
	g_assert(pg_mask_count(filtered_pkts_mask) == nb / 3);
	for (; filtered_pkts_mask;) {
		pg_low_bit_iterate_full(filtered_pkts_mask, bit, i);
		g_assert(i % 3 == 0);
		eth = rte_pktmbuf_mtod(filtered_pkts[i], struct ether_hdr*);
		ip = (struct ip *)(eth + 1);
		g_assert(ip->ip_src.s_addr == inet_addr("10.0.0.1"));
	}

	/* now allow packets from 10.0.0.2 */
	ret = pg_firewall_rule_add(fw, "src host 10.0.0.2", dir, 0, &error);
	g_assert(!error);
	g_assert(ret == 0);
	ret = pg_firewall_reload(fw, &error);
	g_assert(ret < 0);
	g_assert(!error);

	/* let it goooo */
	pg_brick_poll(gen, &packet_count, &error);
	g_assert(!error);
	g_assert(packet_count == nb);

	/* check collect brick */
	if (dir == WEST_SIDE)
		filtered_pkts = pg_brick_west_burst_get(col, &filtered_pkts_mask,
						     &error);
	else
		filtered_pkts = pg_brick_east_burst_get(col, &filtered_pkts_mask,
						     &error);
	g_assert(!error);
	g_assert(pg_mask_count(filtered_pkts_mask) == nb * 2 / 3);
	for (; filtered_pkts_mask;) {
		pg_low_bit_iterate_full(filtered_pkts_mask, bit, i);
		g_assert(i % 3 == 0 || i % 3 == 1);
		eth = rte_pktmbuf_mtod(filtered_pkts[i], struct ether_hdr*);
		ip = (struct ip *)(eth + 1);
		g_assert(ip->ip_src.s_addr == inet_addr("10.0.0.1") ||
			 ip->ip_src.s_addr == inet_addr("10.0.0.2"));
	}

	/* test that flush really blocks */
	pg_firewall_rule_flush(fw);
	ret = pg_firewall_reload(fw, &error);
	g_assert(!error);
	g_assert(ret < 0);

	/* let it goooo */
	pg_brick_poll(gen, &packet_count, &error);
	g_assert(!error);
	g_assert(packet_count == nb);

	/* check collect brick */
	if (dir == WEST_SIDE)
		filtered_pkts = pg_brick_west_burst_get(col, &filtered_pkts_mask,
						     &error);
	else
		filtered_pkts = pg_brick_east_burst_get(col, &filtered_pkts_mask,
						     &error);
	g_assert(!error);
	g_assert(pg_mask_count(filtered_pkts_mask) == 0);

	/* flush and only allow packets from 10.0.0.2 */
	pg_firewall_rule_flush(fw);
	ret = pg_firewall_rule_add(fw, "src host 10.0.0.2", dir, 0, &error);
	g_assert(!error);
	g_assert(ret == 0);
	ret = pg_firewall_reload(fw, &error);
	g_assert(ret < 0);
	g_assert(!error);

	/* let it goooo */
	pg_brick_poll(gen, &packet_count, &error);
	g_assert(!error);
	g_assert(packet_count == nb);

	/* check collect brick */
	if (dir == WEST_SIDE)
		filtered_pkts = pg_brick_west_burst_get(col, &filtered_pkts_mask,
						     &error);
	else
		filtered_pkts = pg_brick_east_burst_get(col, &filtered_pkts_mask,
						     &error);
	g_assert(!error);
	g_assert(pg_mask_count(filtered_pkts_mask) == nb / 3);
	for (; filtered_pkts_mask;) {
		pg_low_bit_iterate_full(filtered_pkts_mask, bit, i);
		g_assert(i % 3 == 1);
		eth = rte_pktmbuf_mtod(filtered_pkts[i], struct ether_hdr*);
		ip = (struct ip *)(eth + 1);
		g_assert(ip->ip_src.s_addr == inet_addr("10.0.0.2"));
	}

	/* flush and make two rules in one */
	pg_firewall_rule_flush(fw);
	ret = pg_firewall_rule_add(fw, "src host (10.0.0.1 or 10.0.0.2)", dir, 0,
				&error);
	g_assert(!error);
	g_assert(ret == 0);
	ret = pg_firewall_reload(fw, &error);
	g_assert(ret < 0);
	g_assert(!error);

	/* let it goooo */
	pg_brick_poll(gen, &packet_count, &error);
	g_assert(!error);
	g_assert(packet_count == nb);

	/* check collect brick */
	if (dir == WEST_SIDE)
		filtered_pkts = pg_brick_west_burst_get(col, &filtered_pkts_mask,
						     &error);
	else
		filtered_pkts = pg_brick_east_burst_get(col, &filtered_pkts_mask,
						     &error);
	g_assert(!error);
	g_assert(pg_mask_count(filtered_pkts_mask) == nb * 2 / 3);
	for (; filtered_pkts_mask;) {
		pg_low_bit_iterate_full(filtered_pkts_mask, bit, i);
		g_assert(i % 3 == 0 || i % 3 == 1);
		eth = rte_pktmbuf_mtod(filtered_pkts[i], struct ether_hdr*);
		ip = (struct ip *)(eth + 1);
		g_assert(ip->ip_src.s_addr == inet_addr("10.0.0.1") ||
			 ip->ip_src.s_addr == inet_addr("10.0.0.2"));
	}

	/* flush and revert rules, packets should not pass */
	pg_firewall_rule_flush(fw);
	ret = pg_firewall_rule_add(fw, "src host (10.0.0.1)", pg_flip_side(dir), 0,
				&error);
	g_assert(!error);
	g_assert(ret == 0);
	ret = pg_firewall_reload(fw, &error);
	g_assert(ret < 0);
	g_assert(!error);

	/* let it goooo */
	pg_brick_poll(gen, &packet_count, &error);
	g_assert(!error);
	g_assert(packet_count == nb);

	/* check collect brick */
	if (dir == WEST_SIDE)
		filtered_pkts = pg_brick_west_burst_get(col, &filtered_pkts_mask,
						     &error);
	else
		filtered_pkts = pg_brick_east_burst_get(col, &filtered_pkts_mask,
						     &error);
	g_assert(!error);
	g_assert(pg_mask_count(filtered_pkts_mask) == 0);

	/* flush and allow packets from both sides */
	pg_firewall_rule_flush(fw);
	ret = pg_firewall_rule_add(fw, "src host (10.0.0.1)", MAX_SIDE, 0, &error);
	g_assert(!error);
	g_assert(ret == 0);
	ret = pg_firewall_reload(fw, &error);
	g_assert(ret < 0);
	g_assert(!error);

	/* let it goooo */
	pg_brick_poll(gen, &packet_count, &error);
	g_assert(!error);
	g_assert(packet_count == nb);

	if (dir == WEST_SIDE)
		filtered_pkts = pg_brick_west_burst_get(col, &filtered_pkts_mask,
						     &error);
	else
		filtered_pkts = pg_brick_east_burst_get(col, &filtered_pkts_mask,
						     &error);
	g_assert(!error);
	g_assert(pg_mask_count(filtered_pkts_mask) == nb / 3);
	for (; filtered_pkts_mask;) {
		pg_low_bit_iterate_full(filtered_pkts_mask, bit, i);
		g_assert(i % 3 == 0);
		eth = rte_pktmbuf_mtod(filtered_pkts[i], struct ether_hdr*);
		ip = (struct ip *)(eth + 1);
		g_assert(ip->ip_src.s_addr == inet_addr("10.0.0.1"));
	}

	/* inverse generator and collector to test both sides */
	pg_brick_unlink(fw, &error);
	g_assert(!error);
	if (dir == WEST_SIDE) {
		pg_brick_link(col, fw, &error);
		g_assert(!error);
		pg_brick_link(fw, gen, &error);
		g_assert(!error);
	} else {
		pg_brick_link(gen, fw, &error);
		g_assert(!error);
		pg_brick_link(fw, col, &error);
		g_assert(!error);
	}

	/* let it goooo */
	pg_brick_poll(gen, &packet_count, &error);
	g_assert(!error);
	g_assert(packet_count == nb);

	if (dir == WEST_SIDE)
		filtered_pkts = pg_brick_west_burst_get(col, &filtered_pkts_mask,
						     &error);
	else
		filtered_pkts = pg_brick_east_burst_get(col, &filtered_pkts_mask,
						     &error);
	g_assert(!error);
	g_assert(pg_mask_count(filtered_pkts_mask) == nb / 3);
	for (; filtered_pkts_mask;) {
		pg_low_bit_iterate_full(filtered_pkts_mask, bit, i);
		g_assert(i % 3 == 0);
		eth = rte_pktmbuf_mtod(filtered_pkts[i], struct ether_hdr*);
		ip = (struct ip *)(eth + 1);
		g_assert(ip->ip_src.s_addr == inet_addr("10.0.0.1"));
	}

	/* clean */
	for (i = 0; i < nb; i++)
		rte_pktmbuf_free(packets[i]);
	pg_brick_destroy(gen);
	pg_brick_destroy(fw);
	pg_brick_destroy(col);
}
Esempio n. 23
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. 24
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);
}
Esempio n. 25
0
/* this test harness a Linux guest to check that packet are send and received
 * by the vhost brick. An ethernet bridge inside the guest will forward packets
 * between the two vhost-user virtio interfaces.
 */
static void test_vhost_flow_(int qemu_exit_signal)
{
	const char mac_addr_0[18] = "52:54:00:12:34:11";
	const char mac_addr_1[18] = "52:54:00:12:34:12";
	struct rte_mempool *mbuf_pool = pg_get_mempool();
	struct pg_brick *vhost_0, *vhost_1, *collect;
	struct rte_mbuf *pkts[PG_MAX_PKTS_BURST];
	const char *socket_path_0, *socket_path_1;
	struct pg_error *error = NULL;
	struct rte_mbuf **result_pkts;
	int ret, qemu_pid, i;
	uint64_t pkts_mask;

	/* start vhost */
	ret = pg_vhost_start("/tmp", &error);
	g_assert(ret == 0);
	g_assert(!error);

	/* instanciate brick */
	vhost_0 = pg_vhost_new("vhost-0", &error);
	g_assert(!error);
	g_assert(vhost_0);

	vhost_1 = pg_vhost_new("vhost-1", &error);
	g_assert(!error);
	g_assert(vhost_1);

	collect = pg_collect_new("collect", &error);
	g_assert(!error);
	g_assert(collect);

	/* build the graph */
	pg_brick_link(collect, vhost_1, &error);
	g_assert(!error);

	/* spawn first QEMU */
	socket_path_0 = pg_vhost_socket_path(vhost_0, &error);
	g_assert(!error);
	g_assert(socket_path_0);
	socket_path_1 = pg_vhost_socket_path(vhost_1, &error);
	g_assert(!error);
	g_assert(socket_path_1);

	qemu_pid = pg_util_spawn_qemu(socket_path_0, socket_path_1,
				      mac_addr_0, mac_addr_1,
				      glob_vm_path,
				      glob_vm_key_path,
				      glob_hugepages_path, &error);

	g_assert(!error);
	g_assert(qemu_pid);

	/* Prepare VM's bridge. */
#	define SSH(c) \
		g_assert(pg_util_ssh("localhost", ssh_port_id, glob_vm_key_path, c) == 0)
	SSH("brctl addbr br0");
	SSH("ifconfig br0 up");
	SSH("ifconfig ens4 up");
	SSH("ifconfig ens5 up");
	SSH("brctl addif br0 ens4");
	SSH("brctl addif br0 ens5");
	SSH("brctl setfd br0 0");
	SSH("brctl stp br0 off");
#	undef SSH
	ssh_port_id++;

	/* prepare packet to send */
	for (i = 0; i < NB_PKTS; i++) {
		pkts[i] = rte_pktmbuf_alloc(mbuf_pool);
		g_assert(pkts[i]);
		rte_pktmbuf_append(pkts[i], ETHER_MIN_LEN);
		/* set random dst/src mac address so the linux guest bridge
		 * will not filter them
		 */
		pg_set_mac_addrs(pkts[i],
			      "52:54:00:12:34:15", "52:54:00:12:34:16");
		/* set size */
		pg_set_ether_type(pkts[i], ETHER_MIN_LEN - ETHER_HDR_LEN - 4);
	}

	/* send packet to the guest via one interface */
	pg_brick_burst_to_east(vhost_0, 0, pkts,
			       pg_mask_firsts(NB_PKTS), &error);
	g_assert(!error);

	/* let the packet propagate and flow */
	for (i = 0; i < 10; i++) {
		uint16_t count = 0;

		usleep(100000);
		pg_brick_poll(vhost_1, &count, &error);
		g_assert(!error);
		if (count)
			break;
	}

	result_pkts = pg_brick_east_burst_get(collect, &pkts_mask, &error);
	g_assert(!error);
	g_assert(result_pkts);
	g_assert(pg_brick_rx_bytes(vhost_0) == 0);
	g_assert(pg_brick_tx_bytes(vhost_0) != 0);
	g_assert(pg_brick_rx_bytes(vhost_1) != 0);
	g_assert(pg_brick_tx_bytes(vhost_1) == 0);

	/* kill QEMU */
	pg_util_stop_qemu(qemu_pid, qemu_exit_signal);

	/* free result packets */
	pg_packets_free(result_pkts, pkts_mask);

	/* free sent packet */
	for (i = 0; i < NB_PKTS; i++)
		rte_pktmbuf_free(pkts[i]);

	/* break the graph */
	pg_brick_unlink(collect, &error);
	g_assert(!error);

	/* clean up */
	/* pg_brick_decref(vhost_0, &error); */
	pg_brick_destroy(vhost_0);
	g_assert(!error);
	pg_brick_destroy(vhost_1);
	/* pg_brick_decref(vhost_1, &error); */
	g_assert(!error);
	pg_brick_decref(collect, &error);
	g_assert(!error);

	/* stop vhost */
	pg_vhost_stop();
}
Esempio n. 26
0
static void brick_destroy_cb(gpointer data)
{
	pg_brick_destroy(data);
}