Ejemplo n.º 1
0
int main(int argc, char **argv)
{
	int ret;
	uint64_t test_flags;
	struct pg_error *error = NULL;
	/* tests in the same order as the header function declarations */
	g_test_init(&argc, &argv, NULL);

	/* initialize packetgraph */
	ret = pg_start(argc, argv, &error);
	g_assert(ret >= 0);
	g_assert(!error);

	/* accounting program name */
	ret += + 1;
	argc -= ret;
	argv += ret;
	test_flags = parse_args(argc, argv);
	if (test_flags & PRINT_USAGE)
		print_usage();
	g_assert(!(test_flags & FAIL));

	test_error();
	test_brick_core();
	test_brick_flow();
	test_pkts_count();
	test_brick_graph();

	return g_test_run();
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
	struct pg_error *error = NULL;
	int r;

	/* tests in the same order as the header function declarations */
	g_test_init(&argc, &argv, NULL);

	/* initialize packetgraph */
	pg_start(argc, argv, &error);
	g_assert(!error);

	g_test_add_func("/brick/antispoof/mac",
			test_antispoof_mac);
	g_test_add_func("/brick/antispoof/rarp",
			test_antispoof_rarp);
	g_test_add_func("/brick/antispoof/arp/request",
			test_antispoof_arp_request);
	g_test_add_func("/brick/antispoof/arp/response",
			test_antispoof_arp_response);
	g_test_add_func("/brick/antispoof/arp/gratuitous",
			test_antispoof_arp_gratuitous);
	g_test_add_func("/brick/antispoof/arp/disable",
			test_pg_antispoof_arp_disable);

	r = g_test_run();

	pg_stop();
	return r;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
	struct pg_error *error = NULL;
	int ret = -1;
	int verbose = 0;
	int nb_vhost = 0;
	
	ret = pg_start(argc, argv, &error);
	g_assert(ret != -1);
	CHECK_ERROR(error);
	argc -= ret;
	argv += ret;
	while (argc > 1) {
		if (g_str_equal(argv[1], "-verbose")) {
			verbose = 1;
		} else if (g_str_equal(argv[1], "-vhost")) {
			if (argc < 2)
				goto exit;
			nb_vhost = atoi(argv[2]);
			if (!nb_vhost)
				goto exit;
			--argc;
			++argv;
		}
		--argc;
		++argv;
	}

	/* accounting program name */
	ret = start_loop(verbose, nb_vhost);
exit:
	pg_stop();
	return ret;
}
Ejemplo n.º 4
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;
}
Ejemplo 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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
	struct pg_error *error = NULL;
	int r;

	g_test_init(&argc, &argv, NULL);
	pg_start(argc, argv, &error);
	g_assert(!error);
	test_benchmark_rxtx(argc, argv);
	r = g_test_run();
	pg_stop();
	return r;
}
Ejemplo n.º 8
0
int main(int argc, char **argv)
{
	struct pg_error *error = NULL;
	int ret;
	int verbose = 0;
	
	ret = pg_start(argc, argv, &error);
	g_assert(ret != -1);
	CHECK_ERROR(error);
	argc -= ret;
	argv += ret;
	verbose = (argc > 1 && g_str_equal(argv[1], "-verbose"));
	/* accounting program name */
	ret = start_loop(verbose);
	pg_stop();
	return ret;
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
	struct pg_error *error = NULL;
	int r;

	/* tests in the same order as the header function declarations */
	g_test_init(&argc, &argv, NULL);

	/* initialize packetgraph */
	pg_start(argc, argv, &error);
	g_assert(!error);

	test_pmtud();
	r = g_test_run();

	pg_stop();
	return r;
}
Ejemplo n.º 10
0
int main(int argc, char **argv)
{
	struct pg_error *error = NULL;
	int r;

	/* tests in the same order as the header function declarations */
	g_test_init(&argc, &argv, NULL);

	/* initialize packetgraph */
	pg_start(argc, argv, &error);
	CHECK_ERROR(error);

	g_test_add_func("/queue/lifecycle", test_queue_lifecycle);
	g_test_add_func("/queue/friend", test_queue_friend);
	g_test_add_func("/queue/burst", test_queue_burst);
	g_test_add_func("/queue/limit", test_queue_limit);
	g_test_add_func("/queue/reset", test_queue_reset);
	r = g_test_run();

	pg_stop();
	return r;
}
Ejemplo n.º 11
0
int main(int argc, char **argv)
{
	int ret;
	uint64_t test_flags;
	struct pg_error **err = NULL;
	/* tests in the same order as the header function declarations */
	g_test_init(&argc, &argv, NULL);

	ret = pg_start(argc, argv, err);
	g_assert(!err);
	/* accounting program name */
	ret += + 1;
	argc -= ret;
	argv += ret;
	test_flags = parse_args(argc, argv);

	if (test_flags & PRINT_USAGE)
		print_usage();
	g_assert(!(test_flags & FAIL));

	test_nic();
	return g_test_run();
}
Ejemplo n.º 12
0
int main(int argc, char **argv)
{
	struct pg_error *error = NULL;
	struct pg_brick *fw;
	struct pg_brick *nic_west, *nic_east;
	uint16_t nb_send_pkts;
	uint64_t total;
	struct timeval start, end;
	int i;

	pg_start(argc, argv, &error);
	CHECK_ERROR(error);
	g_assert(rte_eth_dev_count() >= 2);

	nic_west = pg_nic_new_by_id("port 0", 1, 1, WEST_SIDE, 0, &error);
	CHECK_ERROR(error);
	fw = pg_firewall_new("fw", 1, 1, PG_NO_CONN_WORKER, &error);
	pg_firewall_thread_register(fw);
	CHECK_ERROR(error);
	nic_east = pg_nic_new_by_id("port 1", 1, 1, EAST_SIDE, 1, &error);
	CHECK_ERROR(error);

	pg_brick_link(nic_west, fw, &error);
	CHECK_ERROR(error);
	pg_brick_link(fw, nic_east, &error);
	CHECK_ERROR(error);

	g_assert(!pg_firewall_rule_add(fw, "tcp portrange 50-60", MAX_SIDE, 1,
				       &error));
	CHECK_ERROR(error);
	g_assert(!pg_firewall_rule_add(fw, "icmp", MAX_SIDE, 1, &error));
	CHECK_ERROR(error);
	g_assert(!pg_firewall_reload(fw, &error));
	CHECK_ERROR(error);

	for (;;) {
		gettimeofday(&start, 0);
		total = 0;
		for (i = 0; i < LOOPS; i++) {
			g_assert(pg_brick_poll(nic_west,
					       &nb_send_pkts,
					       &error));
			usleep(1);
			total += nb_send_pkts;
			g_assert(pg_brick_poll(nic_east,
					       &nb_send_pkts,
					       &error));
			total += nb_send_pkts;
			usleep(1);
		}
		gettimeofday(&end, 0);
		usleep(100);
		printf("time in us: for %i loops: %lu\ntotal %"PRIu64"\n",
		       LOOPS,
		       (end.tv_sec * 1000000 + end.tv_usec) -
		       (start.tv_sec * 1000000 + start.tv_usec), total);
		pg_firewall_gc(fw);
	}

	pg_stop();
	return 0;
}
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
    struct pg_error *error = NULL;
    int ret;
    uint64_t args_flags;
    struct vtep_opts opt = {NULL, NULL, NULL, NULL};
    int32_t ip;
    struct ether_addr eth_addr;
    struct ether_addr inner_addr;
    GList *neighbor_addrs = NULL;

    ret = pg_start(argc, argv, &error);
    g_assert(ret != -1);
    CHECK_ERROR(error);

    if (signal(SIGINT, sig_handler) == SIG_ERR)
        return -errno;

    /* accounting program name */
    argc -= ret;
    argv += ret;
    args_flags = parse_args(argc, argv, &opt);
    if (args_flags & PRINT_USAGE)
        print_usage();

    if (!!(args_flags & FAIL)) {
        dprintf(2, "Invalide arguments, use '-h'\n");
        ret = -EINVAL;
        goto exit;
    }

    if (!pg_scan_ether_addr(&eth_addr, opt.mac) ||
            !is_valid_assigned_ether_addr(&eth_addr)) {
        char buf[40];

        ether_format_addr(buf, 40, &eth_addr);
        dprintf(2, "%s is an invalide ethernet adress\n"
                "sould be an unicast addr and have format XX:XX:XX:XX:XX:XX\n",
                buf);
        ret = -EINVAL;
        goto exit;
    }

    if (!pg_scan_ether_addr(&inner_addr, opt.inner_mac) ||
            !is_valid_assigned_ether_addr(&inner_addr)) {
        char buf[40];

        ether_format_addr(buf, 40, &inner_addr);
        dprintf(2, "%s is an invalide ethernet adress\n"
                "sould be an unicast addr and have format XX:XX:XX:XX:XX:XX\n",
                buf);
        ret = -EINVAL;
        goto exit;
    }

    for (GList *lst = opt.neighbor_macs; lst != NULL;
            lst = lst->next) {
        const char *data = lst->data;
        struct ether_addr *tmp = g_new0(struct ether_addr, 1);

        if (!pg_scan_ether_addr(tmp, data) ||
                !is_valid_assigned_ether_addr(tmp)) {
            char buf[40];

            ether_format_addr(buf, 40, tmp);
            dprintf(2, "%s is an invalide ethernet adress\n"
                    "sould be an unicast addr and have format XX:XX:XX:XX:XX:XX\n",
                    buf);
            ret = -EINVAL;
            goto exit;
        }
        neighbor_addrs = g_list_append(neighbor_addrs, tmp);
    }

    ip = inet_addr(opt.ip);
    if (ip < 0) {
        dprintf(2, "invalide ip\n"
                "should have format: XXX.XXX.XXX.XXX\n");
        return -EINVAL;
    }

    ret = start_loop(ip, &eth_addr, &inner_addr, neighbor_addrs);
exit:
    g_list_free(opt.neighbor_macs);
    g_list_free_full(neighbor_addrs, destroy_ether_addr);
    pg_stop();
    return ret;
}