示例#1
0
void test_tx_thread()
{
        pfq_t * q = pfq_open(64, 1024, 1024);

        assert(pfq_bind_tx(q, "lo", Q_ANY_QUEUE, 0) == 0);
        assert(pfq_enable(q) == 0);

        pfq_close(q);
}
示例#2
0
void test_tx_queue()
{
        pfq_t * q = pfq_open(64, 1024, 1024);
        assert(pfq_tx_queue(q, 1) == -1);

        assert(pfq_bind_tx(q, "lo", Q_ANY_QUEUE, Q_NO_KTHREAD) == 0);
        assert(pfq_enable(q) == 0);

        assert(pfq_tx_queue(q, 0) == 0);

        pfq_close(q);
}
示例#3
0
void test_is_enabled()
{
	pfq_t * q = pfq_open(64, 1024, 1024);

	assert(q);
	assert(pfq_is_enabled(q) == 0);
	assert(pfq_enable(q) == 0);
	assert(pfq_is_enabled(q) == 1);
	assert(pfq_disable(q) == 0);
	assert(pfq_is_enabled(q) == 0);

	pfq_close(q);
}
示例#4
0
void test_enable_disable()
{
	pfq_t * q = pfq_open(64, 1024, 1024);

	assert(q);
	assert(pfq_mem_addr(q) == NULL);
	assert(pfq_enable(q) == 0);
	assert(pfq_mem_addr(q) != NULL);
	assert(pfq_disable(q) == 0);
	assert(pfq_mem_addr(q) == NULL);

	pfq_close(q);
}
示例#5
0
void test_read()
{
	pfq_t * q = pfq_open(64, 1024, 1024);
        assert(q);

	struct pfq_net_queue nq;
        assert(pfq_read(q, &nq, 10) == -1);

	assert(pfq_enable(q) == 0);

        assert(pfq_read(q, &nq, 10) == 0);

	pfq_close(q);
}
示例#6
0
void test_rx_slots()
{
	pfq_t * q = pfq_open(64, 1024, 1024);
        assert(q);

	assert(pfq_get_rx_slots(q) == 1024);

	assert(pfq_enable(q) == 0);
	assert(pfq_set_rx_slots(q, 4096) == -1);
	assert(pfq_disable(q) == 0);

	assert(pfq_set_rx_slots(q, 4096) == 0);
	assert(pfq_get_rx_slots(q) == 4096);

	pfq_close(q);
}
示例#7
0
void test_caplen()
{
	pfq_t * q = pfq_open(64, 1024, 1024);
        assert(q);

	assert(pfq_get_caplen(q) == 64);
	assert(pfq_set_caplen(q, 128) == 0);
	assert(pfq_get_caplen(q) == 128);

	assert(pfq_enable(q) == 0);
	assert(pfq_set_caplen(q, 10) == -1);
	assert(pfq_disable(q) == 0);

	assert(pfq_set_caplen(q, 64) == 0);
	assert(pfq_get_caplen(q) == 64);

	pfq_close(q);
}
示例#8
0
文件: test-send.c 项目: bullno1/PFQ
int
main(int argc, char *argv[])
{
        if (argc < 5)
        {
                fprintf(stderr, "usage: %s dev queue kthread num\n", argv[0]);
                return -1;
        }

        const char *dev = argv[1];
        int queue  = atoi(argv[2]);
        int kthread = atoi(argv[3]);
        unsigned long long num = atoll(argv[4]);

        pfq_t * q= pfq_open(64, 1024, 1024);

        if (pfq_bind_tx(q, dev, queue, kthread) < 0) {
		fprintf(stderr, "%s\n", pfq_error(q));
		return -1;
	}

        pfq_enable(q);

	if (kthread == -1) {
		send_packets(q, num);
	}
	else  {
		send_packets_async(q, num);
	}

        sleep(2);

        struct pfq_stats stat;
        pfq_get_stats(q, &stat);

        fprintf(stdout, "sent: %lu - disc: %lu\n", stat.sent, stat.disc);

        pfq_close(q);

        return 0;
}
示例#9
0
文件: test-read.c 项目: emmericp/PFQ
int
main(int argc, char *argv[])
{
        if (argc < 2) {
                fprintf(stderr, "usage: %s dev\n", argv[0]);
                return 0;
        }

        pfq_t *p = pfq_open(64, 4096, 1024);
        if (p == NULL) {
                printf("error: %s\n", pfq_error(p));
                return -1;
        }

        if (pfq_enable(p) < 0) {
                printf("error: %s\n", pfq_error(p));
                return -1;
        }

        if (pfq_bind(p, argv[1], Q_ANY_QUEUE) < 0) {
		printf("error: %s\n", pfq_error(p));
		return -1;
        }

        if (pfq_timestamping_enable(p, 1) < 0) {
		printf("error: %s\n", pfq_error(p));
		return -1;
	}

	printf("reading from %s...\n", argv[1]);


	for(;;) {

                struct pfq_net_queue nq;
		pfq_iterator_t it, it_e;

		int many = pfq_read(p, &nq, 1000000);
		if (many < 0) {
			printf("error: %s\n", pfq_error(p));
			break;
		}

		if (nq.len == 0) {
			pfq_yield();
			continue;
		}

		printf("queue size: %zd\n", nq.len);

		it = pfq_net_queue_begin(&nq);
		it_e = pfq_net_queue_end(&nq);

		for(; it != it_e; it = pfq_net_queue_next(&nq, it))
		{
			int x;

			while (!pfq_pkt_ready(&nq, it))
				pfq_yield();

			const struct pfq_pkthdr *h = pfq_pkt_header(it);

			printf("caplen:%d len:%d ifindex:%d hw_queue:%d tstamp: %u:%u -> ",
					h->caplen, h->len, h->if_index, h->queue,
                                        h->tstamp.tv.sec, h->tstamp.tv.nsec);

			const char *buff = pfq_pkt_data(it);

			for(x=0; x < MIN(h->caplen, 34); x++)
			{
				printf("%2x ", (unsigned char)buff[x]);
			}
			printf("\n");
		}

        }

        // struct pfq_stats s = pfq_get_stats(p, &ok);
        // if (!ok) {
        //         printf("error: %s\n", pfq_error(p));
        //         return -1;
        // }

        // printf("stats:: recv=%d lost=%d drop=%d\n", s.recv, s.lost, s.drop);

        pfq_close(p);
        return 0;
}