int main(int argc, char* argv[]) { char *device = NULL, c; int i; startTime.tv_sec = 0; while((c = getopt(argc,argv,"ab:c:g:hi:n:p:l:z")) != '?') { if((c == 255) || (c == -1)) break; switch(c) { case 'h': printHelp(); break; case 'a': active = 1; break; case 'b': num_ips = atoi(optarg); break; case 'c': cluster_id = atoi(optarg); break; case 'i': device = strdup(optarg); break; case 'l': packet_len = atoi(optarg); break; case 'n': num_to_send = atoi(optarg); break; case 'p': pps = atoi(optarg); break; case 'g': bind_core = atoi(optarg); break; #ifdef BURST_API case 'z': use_pkt_burst_api = 1; break; #endif } } if (cluster_id < 0) printHelp(); if (device) { num_queue_buffers = MAX_CARD_SLOTS; } else { num_queue_buffers = QUEUE_LEN; } stdin_packet_len = read_packet_hex(stdin_packet, sizeof(stdin_packet)); if (stdin_packet_len > 0) packet_len = stdin_packet_len; zc = pfring_zc_create_cluster( cluster_id, 1536, 0, num_queue_buffers + NBUFF, numa_node_of_cpu(bind_core), NULL /* auto hugetlb mountpoint */ ); if(zc == NULL) { fprintf(stderr, "pfring_zc_create_cluster error [%s] Please check your hugetlb configuration\n", strerror(errno)); return -1; } for (i = 0; i < NBUFF; i++) { buffers[i] = pfring_zc_get_packet_handle(zc); if (buffers[i] == NULL) { fprintf(stderr, "pfring_zc_get_packet_handle error\n"); return -1; } } if (device) { zq = pfring_zc_open_device(zc, device, tx_only, 0); if(zq == NULL) { fprintf(stderr, "pfring_zc_open_device error [%s] Please check that %s is up and not already used\n", strerror(errno), device); return -1; } fprintf(stderr, "Sending packets to %s\n", device); } else { zq = pfring_zc_create_queue(zc, num_queue_buffers); if(zq == NULL) { fprintf(stderr, "pfring_zc_create_queue error [%s]\n", strerror(errno)); return -1; } zp = pfring_zc_create_buffer_pool(zc, POOL_SIZE); if (zp == NULL) { fprintf(stderr, "pfring_zc_create_buffer_pool error\n"); return -1; } fprintf(stderr, "Sending packets to cluster %u queue %u\n", cluster_id, 0); } signal(SIGINT, sigproc); signal(SIGTERM, sigproc); signal(SIGINT, sigproc); signal(SIGALRM, my_sigalarm); alarm(ALARM_SLEEP); send_traffic(); print_stats(); pfring_zc_destroy_cluster(zc); return 0; }
int main(int argc, char* argv[]) { char *device = NULL, c; pthread_t thread; pthread_t time_thread; char *vm_sock = NULL; int i, rc, ipc_q_attach = 0; startTime.tv_sec = 0; while((c = getopt(argc,argv,"ab:c:g:hi:n:p:l:zN:S:P:Q:")) != '?') { if((c == 255) || (c == -1)) break; switch(c) { case 'h': printHelp(); break; case 'a': active = 1; break; case 'b': num_ips = atoi(optarg); break; case 'c': cluster_id = atoi(optarg); break; case 'i': device = strdup(optarg); break; case 'l': packet_len = atoi(optarg); break; case 'n': num_to_send = atoi(optarg); break; case 'p': pps = atoi(optarg); /* auto flush on wait flush_packet = 1; */ break; case 'g': bind_core = atoi(optarg); break; case 'Q': enable_vm_support = 1; vm_sock = strdup(optarg); break; #ifdef BURST_API case 'z': use_pkt_burst_api = 1; break; #endif case 'N': n2disk_producer = 1; n2disk_threads = atoi(optarg); break; case 'S': append_timestamp = 1; bind_time_pulse_core = atoi(optarg); break; case 'P': use_pulse_time = 1; bind_time_pulse_core = atoi(optarg); break; } } if (n2disk_producer) device = NULL; /* checking if the interface is a queue allocated by an external cluster (ipc) */ if (device != NULL && is_a_queue(device, &cluster_id, &queue_id)) ipc_q_attach = 1; if (cluster_id < 0) printHelp(); stdin_packet_len = read_packet_hex(stdin_packet, sizeof(stdin_packet)); if (stdin_packet_len > 0) packet_len = stdin_packet_len; if (n2disk_producer) { if (device != NULL || ipc_q_attach) printHelp(); if (n2disk_threads < 1) printHelp(); metadata_len = N2DISK_METADATA; num_consumer_buffers += (n2disk_threads * (N2DISK_CONSUMER_QUEUE_LEN + 1)) + N2DISK_PREFETCH_BUFFERS; } if (!ipc_q_attach) { if (device != NULL) num_queue_buffers = MAX_CARD_SLOTS; else num_queue_buffers = QUEUE_LEN; zc = pfring_zc_create_cluster( cluster_id, max_packet_len(device), metadata_len, num_queue_buffers + NBUFF + num_consumer_buffers, numa_node_of_cpu(bind_core), NULL /* auto hugetlb mountpoint */ ); if(zc == NULL) { fprintf(stderr, "pfring_zc_create_cluster error [%s] Please check your hugetlb configuration\n", strerror(errno)); return -1; } for (i = 0; i < NBUFF; i++) { buffers[i] = pfring_zc_get_packet_handle(zc); if (buffers[i] == NULL) { fprintf(stderr, "pfring_zc_get_packet_handle error\n"); return -1; } } if (device) { zq = pfring_zc_open_device(zc, device, tx_only, 0); if(zq == NULL) { fprintf(stderr, "pfring_zc_open_device error [%s] Please check that %s is up and not already used\n", strerror(errno), device); return -1; } fprintf(stderr, "Sending packets to %s\n", device); } else { zq = pfring_zc_create_queue(zc, num_queue_buffers); if(zq == NULL) { fprintf(stderr, "pfring_zc_create_queue error [%s]\n", strerror(errno)); return -1; } if (pfring_zc_create_buffer_pool(zc, n2disk_producer ? (N2DISK_PREFETCH_BUFFERS + n2disk_threads) : 1) == NULL) { fprintf(stderr, "pfring_zc_create_buffer_pool error\n"); return -1; } fprintf(stderr, "Sending packets to cluster %u queue %u\n", cluster_id, 0); if (n2disk_producer) { char queues_list[256]; queues_list[0] = '\0'; for (i = 0; i < n2disk_threads; i++) { if(pfring_zc_create_queue(zc, N2DISK_CONSUMER_QUEUE_LEN) == NULL) { fprintf(stderr, "pfring_zc_create_queue error [%s]\n", strerror(errno)); return -1; } sprintf(&queues_list[strlen(queues_list)], "%d,", i+1); } queues_list[strlen(queues_list)-1] = '\0'; fprintf(stderr, "Run n2disk with: --cluster-ipc-attach --cluster-id %d --cluster-ipc-queues %s --cluster-ipc-pool 0\n", cluster_id, queues_list); } } if (enable_vm_support) { rc = pfring_zc_vm_register(zc, vm_sock); if (rc < 0) { fprintf(stderr, "pfring_zc_vm_register(%s) error\n", vm_sock); return -1; } rc = pfring_zc_vm_backend_enable(zc); if (rc < 0) { fprintf(stderr, "pfring_zc_vm_backend_enable error\n"); return -1; } } } else { /* IPC */ fprintf(stderr, "Attaching to cluster %d queue %d (IPC)\n", cluster_id, queue_id); zq = pfring_zc_ipc_attach_queue(cluster_id, queue_id, tx_only); if(zq == NULL) { fprintf(stderr, "pfring_zc_ipc_attach_queue error [%s] Please check that cluster %d is running\n", strerror(errno), cluster_id); return -1; } zp = pfring_zc_ipc_attach_buffer_pool(cluster_id, queue_id); if(zp == NULL) { fprintf(stderr, "pfring_zc_ipc_attach_buffer_pool error [%s] Please check that cluster %d is running\n", strerror(errno), cluster_id); return -1; } for (i = 0; i < NBUFF; i++) { buffers[i] = pfring_zc_get_packet_handle_from_pool(zp); if (buffers[i] == NULL) { fprintf(stderr, "pfring_zc_get_packet_handle_from_pool error\n"); return -1; } } } signal(SIGINT, sigproc); signal(SIGTERM, sigproc); signal(SIGINT, sigproc); if (use_pulse_time) pulse_timestamp_ns = calloc(CACHE_LINE_LEN/sizeof(u_int64_t), sizeof(u_int64_t)); if (append_timestamp) pulse_timestamp_ns_n = calloc(CACHE_LINE_LEN/sizeof(u_int64_t), sizeof(u_int64_t)); if (append_timestamp || use_pulse_time) pthread_create(&time_thread, NULL, time_pulse_thread, NULL); if (use_pulse_time) while (!*pulse_timestamp_ns && !do_shutdown); /* wait for ts */ if (append_timestamp) while (!*pulse_timestamp_ns_n && !do_shutdown); /* wait for ts */ pthread_create(&thread, NULL, send_traffic, NULL); while (!do_shutdown) { sleep(ALARM_SLEEP); print_stats(); } pthread_join(thread, NULL); print_stats(); if (append_timestamp || use_pulse_time) pthread_join(time_thread, NULL); if (!ipc_q_attach) { pfring_zc_destroy_cluster(zc); } else { for (i = 0; i < NBUFF; i++) pfring_zc_release_packet_handle_to_pool(zp, buffers[i]); pfring_zc_ipc_detach_queue(zq); pfring_zc_ipc_detach_buffer_pool(zp); } return 0; }
int main(int argc, char* argv[]) { char *device = NULL, c; int i; startTime.tv_sec = 0; while((c = getopt(argc,argv,"ab:c:g:hi:n:p:l:zN:")) != '?') { if((c == 255) || (c == -1)) break; switch(c) { case 'h': printHelp(); break; case 'a': active = 1; break; case 'b': num_ips = atoi(optarg); break; case 'c': cluster_id = atoi(optarg); break; case 'i': device = strdup(optarg); break; case 'l': packet_len = atoi(optarg); break; case 'n': num_to_send = atoi(optarg); break; case 'p': pps = atoi(optarg); break; case 'g': bind_core = atoi(optarg); break; #ifdef BURST_API case 'z': use_pkt_burst_api = 1; break; #endif case 'N': n2disk_producer = 1; n2disk_threads = atoi(optarg); break; } } if (cluster_id < 0) printHelp(); if (n2disk_producer) { if (device != NULL) printHelp(); if (n2disk_threads < 1) printHelp(); metadata_len = N2DISK_METADATA; num_consumer_buffers += (n2disk_threads * (N2DISK_CONSUMER_QUEUE_LEN + 1)) + N2DISK_PREFETCH_BUFFERS; } if (device) { num_queue_buffers = MAX_CARD_SLOTS; } else { num_queue_buffers = QUEUE_LEN; } stdin_packet_len = read_packet_hex(stdin_packet, sizeof(stdin_packet)); if (stdin_packet_len > 0) packet_len = stdin_packet_len; zc = pfring_zc_create_cluster( cluster_id, max_packet_len(device), metadata_len, num_queue_buffers + NBUFF + num_consumer_buffers, numa_node_of_cpu(bind_core), NULL /* auto hugetlb mountpoint */ ); if(zc == NULL) { fprintf(stderr, "pfring_zc_create_cluster error [%s] Please check your hugetlb configuration\n", strerror(errno)); return -1; } for (i = 0; i < NBUFF; i++) { buffers[i] = pfring_zc_get_packet_handle(zc); if (buffers[i] == NULL) { fprintf(stderr, "pfring_zc_get_packet_handle error\n"); return -1; } } if (device) { zq = pfring_zc_open_device(zc, device, tx_only, 0); if(zq == NULL) { fprintf(stderr, "pfring_zc_open_device error [%s] Please check that %s is up and not already used\n", strerror(errno), device); return -1; } fprintf(stderr, "Sending packets to %s\n", device); } else { zq = pfring_zc_create_queue(zc, num_queue_buffers); if(zq == NULL) { fprintf(stderr, "pfring_zc_create_queue error [%s]\n", strerror(errno)); return -1; } fprintf(stderr, "Sending packets to cluster %u queue %u\n", cluster_id, 0); if (n2disk_producer) { char queues_list[256]; queues_list[0] = '\0'; for (i = 0; i < n2disk_threads; i++) { if(pfring_zc_create_queue(zc, N2DISK_CONSUMER_QUEUE_LEN) == NULL) { fprintf(stderr, "pfring_zc_create_queue error [%s]\n", strerror(errno)); return -1; } sprintf(&queues_list[strlen(queues_list)], "%d,", i+1); } queues_list[strlen(queues_list)-1] = '\0'; if (pfring_zc_create_buffer_pool(zc, N2DISK_PREFETCH_BUFFERS + n2disk_threads) == NULL) { fprintf(stderr, "pfring_zc_create_buffer_pool error\n"); return -1; } fprintf(stderr, "Run n2disk with: --cluster-ipc-attach --cluster-id %d --cluster-ipc-queues %s --cluster-ipc-pool 0\n", cluster_id, queues_list); } } signal(SIGINT, sigproc); signal(SIGTERM, sigproc); signal(SIGINT, sigproc); signal(SIGALRM, my_sigalarm); alarm(ALARM_SLEEP); send_traffic(); print_stats(); pfring_zc_destroy_cluster(zc); return 0; }
int main(int argc, char* argv[]) { char c; char *in_pair = NULL, *out_pair = NULL; char *vm_sockets = NULL, *vm_sock; long i; int cluster_id = -1; int rc; start_time.tv_sec = 0; while((c = getopt(argc,argv,"ac:fhi:o:n:Q:r:t:")) != '?') { if((c == 255) || (c == -1)) break; switch(c) { case 'h': printHelp(); break; case 'a': wait_for_packet = 0; break; case 'c': cluster_id = atoi(optarg); break; case 'f': flush_packet = 1; break; case 'n': num_ipc_queues = atoi(optarg); break; case 'i': in_pair = strdup(optarg); break; case 'o': out_pair = strdup(optarg); break; case 'r': forwarder[RX_FWDR].bind_core = atoi(optarg); break; case 't': forwarder[TX_FWDR].bind_core = atoi(optarg); break; case 'Q': enable_vm_support = 1; vm_sockets = strdup(optarg); break; } } if (cluster_id < 0) printHelp(); if (num_ipc_queues < 1) printHelp(); if (in_pair != NULL) { char *q_id = strchr(in_pair, ';'); if (q_id == NULL) printHelp(); q_id[0] = '\0'; q_id++; in_device = strdup(in_pair); in_queue_id = atoi(q_id); if (in_queue_id < 0 || in_queue_id >= num_ipc_queues) printHelp(); } if (out_pair != NULL) { char *q_id = strchr(out_pair, ';'); if (q_id == NULL) printHelp(); q_id[0] = '\0'; q_id++; out_device = strdup(out_pair); out_queue_id = atoi(q_id); if (out_queue_id < 0 || out_queue_id >= num_ipc_queues) printHelp(); } ipczqs = calloc(num_ipc_queues, sizeof(pfring_zc_queue *)); pools = calloc(num_ipc_queues, sizeof(pfring_zc_buffer_pool *)); zc = pfring_zc_create_cluster( cluster_id, in_device != NULL ? max_packet_len(in_device) : 1536, 0, (((in_device != NULL) + (out_device != NULL)) * (MAX_CARD_SLOTS + 1)) + (num_ipc_queues * (QUEUE_LEN + 1)), numa_node_of_cpu(forwarder[RX_FWDR].bind_core), NULL /* auto hugetlb mountpoint */ ); if(zc == NULL) { fprintf(stderr, "pfring_zc_create_cluster error [%s] Please check your hugetlb configuration\n", strerror(errno)); return -1; } for (i = 0; i < num_ipc_queues; i++) { ipczqs[i] = pfring_zc_create_queue(zc, QUEUE_LEN); if(ipczqs[i] == NULL) { fprintf(stderr, "pfring_zc_create_queue error [%s]\n", strerror(errno)); return -1; } } for (i = 0; i < num_ipc_queues; i++) { pools[i] = pfring_zc_create_buffer_pool(zc, 1); if (pools[i] == NULL) { fprintf(stderr, "pfring_zc_create_buffer_pool error\n"); return -1; } } if (in_device != NULL) { forwarder[RX_FWDR].inzq = pfring_zc_open_device(zc, in_device, rx_only, 0); forwarder[RX_FWDR].outzq = ipczqs[in_queue_id]; if(forwarder[RX_FWDR].inzq == NULL) { fprintf(stderr, "pfring_zc_open_device error [%s] Please check that %s is up and not already used\n", strerror(errno), in_device); return -1; } forwarder[RX_FWDR].buffer = pfring_zc_get_packet_handle(zc); if (forwarder[RX_FWDR].buffer == NULL) { fprintf(stderr, "pfring_zc_get_packet_handle error\n"); return -1; } printf("Forwarding from %s to Q%u\n", in_device, in_queue_id); } if (out_device != NULL) { forwarder[TX_FWDR].inzq = ipczqs[out_queue_id]; forwarder[TX_FWDR].outzq = pfring_zc_open_device(zc, out_device, tx_only, 0); if(forwarder[TX_FWDR].outzq == NULL) { fprintf(stderr, "pfring_zc_open_device error [%s] Please check that %s is up and not already used\n", strerror(errno), out_device); return -1; } forwarder[TX_FWDR].buffer = pfring_zc_get_packet_handle(zc); if (forwarder[TX_FWDR].buffer == NULL) { fprintf(stderr, "pfring_zc_get_packet_handle error\n"); return -1; } printf("Forwarding from Q%u to %s\n", out_queue_id, out_device); } if (enable_vm_support) { vm_sock = strtok(vm_sockets, ","); while(vm_sock != NULL) { rc = pfring_zc_vm_register(zc, vm_sock); if (rc < 0) { fprintf(stderr, "pfring_zc_vm_register error\n"); return -1; } vm_sock = strtok(NULL, ","); } rc = pfring_zc_vm_backend_enable(zc); if (rc < 0) { fprintf(stderr, "pfring_zc_vm_backend_enable error\n"); return -1; } } signal(SIGINT, sigproc); signal(SIGTERM, sigproc); signal(SIGINT, sigproc); printf("Starting master with %d queues..\n", num_ipc_queues); if (out_device != NULL) pthread_create(&forwarder[TX_FWDR].thread, NULL, forwarder_thread, &forwarder[TX_FWDR]); if (in_device != NULL) pthread_create(&forwarder[RX_FWDR].thread, NULL, forwarder_thread, &forwarder[RX_FWDR]); while (!do_shutdown) { sleep(ALARM_SLEEP); print_stats(); } if (out_device != NULL) pthread_join(forwarder[TX_FWDR].thread, NULL); if (in_device != NULL) pthread_join(forwarder[RX_FWDR].thread, NULL); pfring_zc_destroy_cluster(zc); return 0; }
int main(int argc, char* argv[]) { char *device = NULL, *dev, c; long i; int cluster_id = -1; char *bind_mask = NULL; pthread_t *threads; char *id; u_int numCPU = sysconf( _SC_NPROCESSORS_ONLN ); int hash_mode = 0; startTime.tv_sec = 0; while((c = getopt(argc,argv,"ac:g:hi:r:m:")) != '?') { if((c == 255) || (c == -1)) break; switch(c) { case 'h': printHelp(); break; case 'a': wait_for_packet = 0; break; case 'c': cluster_id = atoi(optarg); break; case 'm': hash_mode = atoi(optarg); break; case 'i': device = strdup(optarg); break; case 'g': bind_mask = strdup(optarg); break; case 'r': bind_worker_core = atoi(optarg); break; } } if (device == NULL) printHelp(); if (cluster_id < 0) printHelp(); if (bind_mask == NULL) printHelp(); id = strtok(bind_mask, ":"); while(id != NULL) { bind_core = realloc(bind_core, sizeof(int) * (num_threads+1)); bind_core[num_threads] = atoi(id) % numCPU; num_threads++; id = strtok(NULL, ":"); } if (num_threads < 1) printHelp(); dev = strtok(device, ","); while(dev != NULL) { devices = realloc(devices, sizeof(char *) * (num_devices+1)); devices[num_devices] = strdup(dev); num_devices++; dev = strtok(NULL, ","); } zc = pfring_zc_create_cluster( cluster_id, max_packet_len(devices[0]), 0, (num_devices * MAX_CARD_SLOTS) + (num_threads * QUEUE_LEN) + num_threads + PREFETCH_BUFFERS, numa_node_of_cpu(bind_worker_core), NULL /* auto hugetlb mountpoint */ ); if(zc == NULL) { fprintf(stderr, "pfring_zc_create_cluster error [%s] Please check your hugetlb configuration\n", strerror(errno)); return -1; } threads = calloc(num_threads, sizeof(pthread_t)); buffers = calloc(num_threads, sizeof(pfring_zc_pkt_buff *)); inzq = calloc(num_devices, sizeof(pfring_zc_queue *)); outzq = calloc(num_threads, sizeof(pfring_zc_queue *)); consumers_stats = calloc(num_threads, sizeof(struct stats)); for (i = 0; i < num_threads; i++) { buffers[i] = pfring_zc_get_packet_handle(zc); if (buffers[i] == NULL) { fprintf(stderr, "pfring_zc_get_packet_handle error\n"); return -1; } } for (i = 0; i < num_devices; i++) { inzq[i] = pfring_zc_open_device(zc, devices[i], rx_only, 0); if(inzq[i] == NULL) { fprintf(stderr, "pfring_zc_open_device error [%s] Please check that %s is up and not already used\n", strerror(errno), devices[i]); return -1; } //printf("Created device with ID=%u, INDEX=%u\n", pfring_zc_get_queue_id(inzq[i]), QUEUEID_TO_IFINDEX(pfring_zc_get_queue_id(inzq[i]))); } for (i = 0; i < num_threads; i++) { outzq[i] = pfring_zc_create_queue(zc, QUEUE_LEN); if(outzq[i] == NULL) { fprintf(stderr, "pfring_zc_create_queue error [%s]\n", strerror(errno)); return -1; } //printf("Created queue with ID=%u\n", pfring_zc_get_queue_id(outzq[i])); } wsp = pfring_zc_create_buffer_pool(zc, PREFETCH_BUFFERS); if (wsp == NULL) { fprintf(stderr, "pfring_zc_create_buffer_pool error\n"); return -1; } signal(SIGINT, sigproc); signal(SIGTERM, sigproc); signal(SIGINT, sigproc); printf("Starting balancer with %d consumer threads..\n", num_threads); if (hash_mode < 2) { /* balancer */ pfring_zc_distribution_func func; if(strcmp(device, "sysdig") == 0) func = (hash_mode == 0) ? rr_distribution_func : sysdig_distribution_func; else func = (hash_mode == 0) ? rr_distribution_func : NULL /* built-in IP-based */; zw = pfring_zc_run_balancer( inzq, outzq, num_devices, num_threads, wsp, round_robin_bursts_policy, NULL /* idle callback */, func, (void *) ((long) num_threads), !wait_for_packet, bind_worker_core ); } else { outzmq = pfring_zc_create_multi_queue(outzq, num_threads); if(outzmq == NULL) { fprintf(stderr, "pfring_zc_create_multi_queue error [%s]\n", strerror(errno)); return -1; } zw = pfring_zc_run_fanout( inzq, outzmq, num_devices, wsp, round_robin_bursts_policy, NULL /* idle callback */, NULL /* built-in send-to-all */, (void *) ((long) num_threads), !wait_for_packet, bind_worker_core ); } if(zw == NULL) { fprintf(stderr, "pfring_zc_run_balancer error [%s]\n", strerror(errno)); return -1; } for (i = 0; i < num_threads; i++) pthread_create(&threads[i], NULL, consumer_thread, (void*) i); while (!do_shutdown) { sleep(ALARM_SLEEP); print_stats(); } for (i = 0; i < num_threads; i++) pthread_join(threads[i], NULL); pfring_zc_kill_worker(zw); pfring_zc_destroy_cluster(zc); return 0; }
int main(int argc, char* argv[]) { char c; char *ingress_devices = NULL, *egress_devices = NULL, *dev; long i; int wait_for_packet = 1; start_time.tv_sec = 0; while((c = getopt(argc,argv, "ac:g:hi:o:")) != '?') { if((c == 255) || (c == -1)) break; switch(c) { case 'h': printHelp(); break; case 'a': wait_for_packet = 0; break; case 'c': cluster_id = atoi(optarg); break; case 'i': ingress_devices = strdup(optarg); break; case 'o': egress_devices = strdup(optarg); break; case 'g': bind_worker_core = atoi(optarg); break; } } if(cluster_id < 0) printHelp(); dev = strtok(ingress_devices, ","); while(dev != NULL) { in_devices = realloc(in_devices, sizeof(char *) * (num_in_devices+1)); in_devices[num_in_devices] = strdup(dev); num_in_devices++; dev = strtok(NULL, ","); } dev = strtok(egress_devices, ","); while(dev != NULL) { out_devices = realloc(out_devices, sizeof(char *) * (num_out_devices+1)); out_devices[num_out_devices] = strdup(dev); num_out_devices++; dev = strtok(NULL, ","); } if((num_in_devices == 0) || (num_out_devices == 0)) printHelp(); zc = pfring_zc_create_cluster(cluster_id, max_packet_len(in_devices[0]), metadata_len, ((num_in_devices + num_out_devices) * MAX_CARD_SLOTS) + PREFETCH_BUFFERS, numa_node_of_cpu(bind_worker_core), NULL /* auto hugetlb mountpoint */); if(zc == NULL) { fprintf(stderr, "pfring_zc_create_cluster error [%s] Please check your hugetlb configuration\n", strerror(errno)); return -1; } inzqs = calloc(num_in_devices, sizeof(pfring_zc_queue *)); outzqs = calloc(num_out_devices, sizeof(pfring_zc_queue *)); for(i = 0; i < num_in_devices; i++) { inzqs[i] = pfring_zc_open_device(zc, in_devices[i], rx_only, 0); if(inzqs[i] == NULL) { fprintf(stderr, "[RX] pfring_zc_open_device error [%s] Please check that %s is up and not already used\n", strerror(errno), in_devices[i]); return -1; } } for(i = 0; i < num_out_devices; i++) { outzqs[i] = pfring_zc_open_device(zc, out_devices[i], tx_only, 0); if(outzqs[i] == NULL) { fprintf(stderr, "[TX] pfring_zc_open_device error [%s] Please check that %s is up and not already used\n", strerror(errno), out_devices[i]); return -1; } } signal(SIGINT, sigproc); signal(SIGTERM, sigproc); signal(SIGINT, sigproc); outzmq = pfring_zc_create_multi_queue(outzqs, num_out_devices); if(outzmq == NULL) { fprintf(stderr, "pfring_zc_create_multi_queue error [%s]\n", strerror(errno)); return -1; } wsp = pfring_zc_create_buffer_pool(zc, PREFETCH_BUFFERS); if(wsp == NULL) { fprintf(stderr, "pfring_zc_create_buffer_pool error\n"); return -1; } zw = pfring_zc_run_fanout(inzqs, outzmq, num_in_devices, wsp, round_robin_bursts_policy, NULL /* idle callback */, NULL /* fanout */, NULL, !wait_for_packet, bind_worker_core); if(zw == NULL) { fprintf(stderr, "pfring_zc_run_fanout error [%s]\n", strerror(errno)); return -1; } while(!do_shutdown) { sleep(ALARM_SLEEP); print_stats(); } pfring_zc_destroy_cluster(zc); return 0; }