Changeset View
Changeset View
Standalone View
Standalone View
tools/tools/netmap/nmreplay.c
Context not available. | |||||
#define DDD(_fmt, ...) ED("--DDD-- " _fmt, ##__VA_ARGS__) | #define DDD(_fmt, ...) ED("--DDD-- " _fmt, ##__VA_ARGS__) | ||||
#define _GNU_SOURCE // for CPU_SET() etc | #define _GNU_SOURCE // for CPU_SET() etc | ||||
#include <errno.h> | |||||
#include <fcntl.h> | |||||
#include <libnetmap.h> | |||||
#include <math.h> /* log, exp etc. */ | |||||
#include <pthread.h> | |||||
#ifdef __FreeBSD__ | |||||
#include <pthread_np.h> /* pthread w/ affinity */ | |||||
#include <sys/cpuset.h> /* cpu_set */ | |||||
#endif /* __FreeBSD__ */ | |||||
#include <signal.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #define NETMAP_WITH_LIBS | ||||
#include <string.h> /* memcpy */ | #include <net/netmap_user.h> | ||||
#include <stdint.h> | |||||
#include <sys/ioctl.h> | |||||
#include <sys/mman.h> | |||||
#include <sys/poll.h> | #include <sys/poll.h> | ||||
#include <sys/resource.h> // setpriority | |||||
#include <sys/time.h> | |||||
#include <unistd.h> | |||||
/* | /* | ||||
* | * | ||||
Context not available. | |||||
static void destroy_pcap(struct nm_pcap_file *file); | static void destroy_pcap(struct nm_pcap_file *file); | ||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <stdint.h> | |||||
#include <unistd.h> | |||||
#include <fcntl.h> | |||||
#include <string.h> /* memcpy */ | |||||
#include <sys/mman.h> | |||||
#define NS_SCALE 1000000000UL /* nanoseconds in 1s */ | #define NS_SCALE 1000000000UL /* nanoseconds in 1s */ | ||||
static void destroy_pcap(struct nm_pcap_file *pf) | static void destroy_pcap(struct nm_pcap_file *pf) | ||||
Context not available. | |||||
static int do_abort = 0; | static int do_abort = 0; | ||||
#include <stdlib.h> | |||||
#include <stdio.h> | |||||
#include <pthread.h> | |||||
#include <sys/time.h> | |||||
#include <sys/resource.h> // setpriority | |||||
#ifdef __FreeBSD__ | |||||
#include <pthread_np.h> /* pthread w/ affinity */ | |||||
#include <sys/cpuset.h> /* cpu_set */ | |||||
#endif /* __FreeBSD__ */ | |||||
#ifdef linux | #ifdef linux | ||||
#define cpuset_t cpu_set_t | #define cpuset_t cpu_set_t | ||||
#endif | #endif | ||||
Context not available. | |||||
struct nm_pcap_file *pcap; /* the pcap struct */ | struct nm_pcap_file *pcap; /* the pcap struct */ | ||||
/* parameters for reading from the netmap port */ | /* parameters for reading from the netmap port */ | ||||
struct nmport_d *src_port; /* netmap descriptor */ | struct nm_desc *src_port; /* netmap descriptor */ | ||||
const char * prod_ifname; /* interface name or pcap file */ | const char * prod_ifname; /* interface name or pcap file */ | ||||
struct netmap_ring *rxring; /* current ring being handled */ | struct netmap_ring *rxring; /* current ring being handled */ | ||||
uint32_t si; /* ring index */ | uint32_t si; /* ring index */ | ||||
Context not available. | |||||
int cons_core; /* core for cons() */ | int cons_core; /* core for cons() */ | ||||
int prod_core; /* core for prod() */ | int prod_core; /* core for prod() */ | ||||
struct nmport_d *pa; /* netmap descriptor */ | struct nm_desc *pa; /* netmap descriptor */ | ||||
struct nmport_d *pb; | struct nm_desc *pb; | ||||
struct _qs q; | struct _qs q; | ||||
}; | }; | ||||
Context not available. | |||||
if (q->buf != NULL) { | if (q->buf != NULL) { | ||||
free(q->buf); | free(q->buf); | ||||
} | } | ||||
nmport_close(pa->pb); | nm_close(pa->pb); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
Context not available. | |||||
continue; | continue; | ||||
} | } | ||||
/* XXX copy is inefficient but simple */ | /* XXX copy is inefficient but simple */ | ||||
if (nmport_inject(pa->pb, (char *)(p + 1), p->pktlen) == 0) { | if (nm_inject(pa->pb, (char *)(p + 1), p->pktlen) == 0) { | ||||
RD(1, "inject failed len %d now %ld tx %ld h %ld t %ld next %ld", | RD(1, "inject failed len %d now %ld tx %ld h %ld t %ld next %ld", | ||||
(int)p->pktlen, (u_long)q->cons_now, (u_long)p->pt_tx, | (int)p->pktlen, (u_long)q->cons_now, (u_long)p->pt_tx, | ||||
(u_long)q->_head, (u_long)q->_tail, (u_long)p->next); | (u_long)q->_head, (u_long)q->_tail, (u_long)p->next); | ||||
Context not available. | |||||
pcap_prod((void*)a); | pcap_prod((void*)a); | ||||
destroy_pcap(q->pcap); | destroy_pcap(q->pcap); | ||||
q->pcap = NULL; | q->pcap = NULL; | ||||
a->pb = nmport_open(q->cons_ifname); | a->pb = nm_open(q->cons_ifname, NULL, 0, NULL); | ||||
if (a->pb == NULL) { | if (a->pb == NULL) { | ||||
EEE("cannot open netmap on %s", q->cons_ifname); | EEE("cannot open netmap on %s", q->cons_ifname); | ||||
do_abort = 1; // XXX any better way ? | do_abort = 1; // XXX any better way ? | ||||
Context not available. | |||||
* 24 useful random bits. | * 24 useful random bits. | ||||
*/ | */ | ||||
#include <math.h> /* log, exp etc. */ | |||||
static inline uint64_t | static inline uint64_t | ||||
my_random24(void) /* 24 useful bits */ | my_random24(void) /* 24 useful bits */ | ||||
{ | { | ||||
Context not available. |