void test_ifindex() { pfq_t * q = pfq_open(64, 1024, 1024); assert(q); assert(pfq_ifindex(q, "lo") != -1); pfq_close(q); }
void test_rx_slot_size() { pfq_t * q = pfq_open(64, 1024, 1024); assert(q); size_t size = sizeof(struct pfq_pkthdr) + 64; /* ALIGN(1514, 8) */ assert(pfq_get_rx_slot_size(q) == size); pfq_close(q); }
void test_egress_unbind() { pfq_t * q = pfq_open(64, 1024, 1024); assert(pfq_egress_unbind(q) == 0); pfq_close(q); }
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); }
void test_egress_bind() { pfq_t * q = pfq_open(64, 1024, 1024); assert(pfq_egress_bind(q, "lo", -1) == 0); assert(pfq_egress_bind(q, "unknown", -1) == -1); pfq_close(q); }
void test_maxlen() { pfq_t * q = pfq_open(64, 1024, 1024); assert(q); assert(pfq_get_maxlen(q) == 1514); pfq_close(q); }
void test_poll() { pfq_t * q = pfq_open(64, 1024, 1024); assert(q); assert(pfq_poll(q, 0) == 0); pfq_close(q); }
void test_bind_tx() { pfq_t * q = pfq_open(64, 1024, 1024); assert(pfq_bind_tx(q, "lo", Q_ANY_QUEUE, Q_NO_KTHREAD) == 0); assert(pfq_bind_tx(q, "unknown", Q_ANY_QUEUE, Q_NO_KTHREAD) == -1); pfq_close(q); }
void test_bind_device() { pfq_t * q = pfq_open(64, 1024, 1024); assert(q); assert(pfq_bind(q, "unknown", Q_ANY_QUEUE) == -1); assert(pfq_bind(q, "eth0", Q_ANY_QUEUE) == 0); assert(pfq_bind_group(q, 11, "eth0", Q_ANY_QUEUE) == -1); pfq_close(q); }
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); }
void test_groups_mask() { pfq_t * q = pfq_open(64, 1024, 1024); assert(q); unsigned long groups; assert(pfq_groups_mask(q, &groups) == 0); assert(groups > 0); pfq_close(q); }
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); }
void test_timestamp() { pfq_t * q = pfq_open(64, 1024, 1024); assert(q); assert(pfq_is_timestamping_enabled(q) == 0); assert(pfq_timestamping_enable(q, 1) == 0); assert(pfq_is_timestamping_enabled(q) == 1); assert(pfq_timestamping_enable(q, 0) == 0); assert(pfq_is_timestamping_enabled(q) == 0); pfq_close(q); }
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); }
void test_stats() { pfq_t * q = pfq_open(64, 1024, 1024); assert(q); struct pfq_stats s; assert(pfq_get_stats(q, &s) == 0); assert(s.recv == 0); assert(s.lost == 0); assert(s.drop == 0); pfq_close(q); }
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); }
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); }
void test_join_private_() { pfq_t * q = pfq_open(64, 1024, 1024); pfq_t * y = pfq_open_group(Q_CLASS_DEFAULT, Q_POLICY_GROUP_UNDEFINED, 64, 1024, 1024); int gid = pfq_group_id(q); assert( pfq_join_group(y, gid, Q_CLASS_DEFAULT, Q_POLICY_GROUP_PRIVATE) < 0); assert( pfq_join_group(y, gid, Q_CLASS_DEFAULT, Q_POLICY_GROUP_RESTRICTED) < 0); assert( pfq_join_group(y, gid, Q_CLASS_DEFAULT, Q_POLICY_GROUP_SHARED) < 0); assert( pfq_join_group(y, gid, Q_CLASS_DEFAULT, Q_POLICY_GROUP_UNDEFINED) < 0); pfq_close(q); pfq_close(y); }
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); }
void test_group_stats() { pfq_t * q = pfq_open(64, 1024, 1024); assert(q); struct pfq_stats s; assert(pfq_get_group_stats(q, 11, &s) == -1); assert(pfq_join_group(q, 11, Q_CLASS_DEFAULT, Q_POLICY_GROUP_RESTRICTED) == 11); assert(pfq_get_group_stats(q, 11, &s) == 0); assert(s.recv == 0); assert(s.lost == 0); assert(s.drop == 0); pfq_close(q); }
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; }
void test_group_context() { /* TODO */ #if 0 pfq_t * q = pfq_open(64, 0, 1024, 1024); struct pfq_meta_prog * prg = (struct pfq_meta_prog *) (malloc(sizeof(int) + sizeof(pfq_fun_t) * 1)); prg->size = 1; int n = 22; prg->fun[0].symbol = "id"; prg->fun[0].context.addr = &n; prg->fun[0].context.size = sizeof(n); assert(pfq_set_group_program(q, pfq_group_id(q), prg) == 0); pfq_close(q); #endif }
void test_vlan() { pfq_t * q = pfq_open(64, 1024, 1024); int gid; assert(q); gid = pfq_group_id(q); assert(pfq_vlan_filters_enable(q, gid, 1) == 0); assert(pfq_vlan_filters_enable(q, gid, 0) == 0); assert(pfq_vlan_set_filter(q, gid, 22) == -1); assert(pfq_vlan_reset_filter(q, gid, 22) == -1); assert(pfq_vlan_filters_enable(q, gid, 1) == 0); assert(pfq_vlan_set_filter(q, gid, 22) == 0); assert(pfq_vlan_reset_filter(q, gid, 22) == 0); pfq_close(q); }
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; }