Skip to content

Commit

Permalink
Merge pull request appneta#77 from appneta/Release_4.0.4_#69
Browse files Browse the repository at this point in the history
Release 4.0.4 appneta#69
  • Loading branch information
fklassen committed Mar 23, 2014
2 parents 6adaabf + 7937989 commit 84821ad
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 69 deletions.
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -2959,7 +2959,7 @@ MAINTAINER_AUTOGEN_VERSION=5.16.2

MAJOR_VERSION=4
MINOR_VERSION=0
MICRO_VERSION=4beta1
MICRO_VERSION=4beta2
TCPREPLAY_VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
PACKAGE_URL=http://tcpreplay.appneta.com/

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ AC_CONFIG_MACRO_DIR([m4])
dnl Set version info here!
MAJOR_VERSION=4
MINOR_VERSION=0
MICRO_VERSION=4beta1
MICRO_VERSION=4beta2
TCPREPLAY_VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
PACKAGE_URL=http://tcpreplay.appneta.com/

Expand Down
4 changes: 3 additions & 1 deletion docs/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
$Id$

xx/xx/xxxx Version 4.0.4
- Number of packets inaccurate when using --netmap method (#76)
- Unexpected packet counts with --loop and --cachefile enabled (#75)
- Improved error messages when interface is a file (#74)
- Missing interfaces with --listnics option (#67)
- Compile issue with netmap v10 and debugging (#66)
- Bad values with --stats and -t options (#65)
Expand Down
75 changes: 53 additions & 22 deletions src/common/sendpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@ static void sendpacket_seterr(sendpacket_t *sp, const char *fmt, ...);
static sendpacket_t * sendpacket_open_khial(const char *, char *) _U_;
static struct tcpr_ether_addr * sendpacket_get_hwaddr_khial(sendpacket_t *) _U_;

#ifdef HAVE_NETMAP
static inline uint32_t get_netmap_buf_avail(struct netmap_ring *ring)
{
uint32_t avail;
#if NETMAP_API > 4
avail = nm_ring_space(ring);
#else
avail = ring->avail;
#endif

return avail;
}
#endif /* HAVE_NETMAP */

/**
* returns number of bytes sent on success or -1 on error
* Note: it is theoretically possible to get a return code >0 and < len
Expand Down Expand Up @@ -445,20 +459,16 @@ sendpacket(sendpacket_t *sp, const u_char *data, size_t len, struct pcap_pkthdr
case SP_TYPE_NETMAP:
#ifdef HAVE_NETMAP
txring = NETMAP_TXRING(sp->nm_if, 0);
#if NETMAP_API > 4
avail = nm_ring_space(txring);
#else
avail = txring->avail;
#endif
avail = get_netmap_buf_avail(txring);
while (avail == 0) {
struct pollfd x[1];
struct pollfd pfd;

/* send TX interrupt signal just in case */
ioctl(sp->handle.fd, NIOCTXSYNC, NULL);
x[0].fd = sp->handle.fd;
x[0].events = POLLOUT;
x[0].revents = 0;
if (poll(x, 1, 100) <= 0) {
pfd.fd = sp->handle.fd;
pfd.events = POLLOUT;
pfd.revents = 0;
if (poll(&pfd, 1, 1000) <= 0) {
if (sp->abort)
return retcode;

Expand All @@ -474,13 +484,9 @@ sendpacket(sendpacket_t *sp, const u_char *data, size_t len, struct pcap_pkthdr
* of the TX queue.
*/
ioctl(sp->handle.fd, NIOCTXSYNC, NULL);
avail = get_netmap_buf_avail(txring);

#if NETMAP_API > 4
avail = nm_ring_space(txring);
#else
avail = txring->avail;
#endif
dbgx(2, "netmap pollempty=%d avail=%u bufsize=%d\n",
dbgx(2, "netmap poll empty=%d avail=%u bufsize=%d\n",
NETMAP_TX_RING_EMPTY(txring),
avail, txring->nr_buf_size);
}
Expand All @@ -496,14 +502,14 @@ sendpacket(sendpacket_t *sp, const u_char *data, size_t len, struct pcap_pkthdr

/* let kernel know that packet is available */
#if NETMAP_API >= 10
dbgx(2, "netmap cur=%d slot index=%d flags=0x%x empty=%d avail=%u bufsize=%d\n",
dbgx(3, "netmap cur=%d slot index=%d flags=0x%x empty=%d avail=%u bufsize=%d\n",
cur, slot->buf_idx, slot->flags, NETMAP_TX_RING_EMPTY(txring),
nm_ring_space(txring), txring->nr_buf_size);
cur = nm_ring_next(txring, cur);
tx_queue_empty = nm_ring_empty(txring);
txring->head = cur;
#else
dbgx(2, "netmap cur=%d slot index=%d flags=0x%x empty=%d avail=%u bufsize=%d\n",
dbgx(3, "netmap cur=%d slot index=%d flags=0x%x empty=%d avail=%u bufsize=%d\n",
cur, slot->buf_idx, slot->flags, NETMAP_TX_RING_EMPTY(txring),
txring->avail, txring->nr_buf_size);
cur = NETMAP_RING_NEXT(txring, cur);
Expand All @@ -523,7 +529,7 @@ sendpacket(sendpacket_t *sp, const u_char *data, size_t len, struct pcap_pkthdr
break;

default:
errx(1, "Unsupported sp->handle_type = %d", sp->handle_type);
errx(-1, "Unsupported sp->handle_type = %d", sp->handle_type);
} /* end case */

if (retcode < 0) {
Expand Down Expand Up @@ -562,8 +568,33 @@ sendpacket_open(const char *device, char *errbuf, tcpr_dir_t direction,
sp = sendpacket_open_khial(device, errbuf);

} else {
errx(1, "%s is not a valid Tcpreplay character device",
device);
switch (sdata.st_mode & S_IFMT) {
case S_IFBLK:
errx(-1, "\"%s\" is a block device and is not a valid Tcpreplay device",
device);
break;
break;
case S_IFDIR:
errx(-1, "\"%s\" is a directory and is not a valid Tcpreplay device",
device);
break;
case S_IFIFO:
errx(-1, "\"%s\" is a FIFO and is not a valid Tcpreplay device",
device);
break;
case S_IFLNK:
errx(-1, "\"%s\" is a symbolic link and is not a valid Tcpreplay device",
device);
break;
case S_IFREG:
errx(-1, "\"%s\" is a file and is not a valid Tcpreplay device",
device);
break;
default:
errx(-1, "\"%s\" is not a valid Tcpreplay device",
device);
break;
}
}
} else {
#ifdef HAVE_NETMAP
Expand All @@ -588,7 +619,7 @@ sendpacket_open(const char *device, char *errbuf, tcpr_dir_t direction,
sp->open = 1;
sp->cache_dir = direction;
} else {
errx(1, "failed to open device %s", device);
errx(-1, "failed to open device %s", device);
}
return sp;
}
Expand Down
36 changes: 28 additions & 8 deletions src/send_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
#include "timestamp_trace.h"
#include "../lib/sll.h"

#if defined HAVE_NETMAP
#include <sys/ioctl.h>
#include <net/netmap.h>
#include <net/netmap_user.h>
#endif

#ifdef TCPREPLAY

#ifdef TCPREPLAY_EDIT
Expand Down Expand Up @@ -443,7 +449,7 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
{
struct timeval print_delta, now;
tcpreplay_opt_t *options = ctx->options;
COUNTER packetnum = ctx->stats.pkts_sent;
COUNTER packetnum = 0;
int limit_send = options->limit_send;
struct pcap_pkthdr pkthdr;
u_char *pktdata = NULL;
Expand Down Expand Up @@ -482,10 +488,10 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
return;

/* stop sending based on the limit -L? */
packetnum++;
if (limit_send > 0 && packetnum > (COUNTER)limit_send)
if (limit_send > 0 && ctx->stats.pkts_sent > (COUNTER)limit_send)
break;

packetnum++;
#if defined TCPREPLAY || defined TCPREPLAY_EDIT
/* do we use the snaplen (caplen) or the "actual" packet len? */
pktlen = options->use_pkthdr_len ? pkthdr.len : pkthdr.caplen;
Expand Down Expand Up @@ -582,7 +588,7 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
*/
if (!do_not_timestamp && timercmp(&ctx->stats.last_time, &pkthdr.ts, <))
memcpy(&ctx->stats.last_time, &pkthdr.ts, sizeof(struct timeval));
ctx->stats.pkts_sent ++;
ctx->stats.pkts_sent++;
ctx->stats.bytes_sent += pktlen;

/* print stats during the run? */
Expand All @@ -603,6 +609,11 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
}
} /* while */

#ifdef HAVE_NETMAP
/* flush any remaining netmap packets */
if (options->netmap)
ioctl(sp->handle.fd, NIOCTXSYNC, NULL);
#endif
++ctx->iteration;
}

Expand All @@ -615,7 +626,7 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t *
{
struct timeval print_delta, now;
tcpreplay_opt_t *options = ctx->options;
COUNTER packetnum = ctx->stats.pkts_sent;
COUNTER packetnum = 0;
int limit_send = options->limit_send;
int cache_file_idx;
pcap_t *pcap;
Expand Down Expand Up @@ -659,10 +670,11 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t *
return;

/* stop sending based on the limit -L? */
packetnum++;
if (limit_send > 0 && packetnum > (COUNTER)limit_send)
if (limit_send > 0 && ctx->stats.pkts_sent > (COUNTER)limit_send)
break;

packetnum++;

/* figure out which pcap file we need to process next
* when get_next_packet() returns null for pktdata, the pkthdr
* will still have the old values from the previous call. This
Expand Down Expand Up @@ -788,7 +800,7 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t *
if (!do_not_timestamp && timercmp(&ctx->stats.last_time, &pkthdr_ptr->ts, <))
memcpy(&ctx->stats.last_time, &pkthdr_ptr->ts, sizeof(struct timeval));

ctx->stats.pkts_sent ++;
ctx->stats.pkts_sent++;
ctx->stats.bytes_sent += pktlen;

/* print stats during the run? */
Expand All @@ -815,6 +827,14 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t *
}
} /* while */

#ifdef HAVE_NETMAP
/* flush any remaining netmap packets */
if (options->netmap) {
ioctl(ctx->intf1->handle.fd, NIOCTXSYNC, NULL);
ioctl(ctx->intf2->handle.fd, NIOCTXSYNC, NULL);
}
#endif

++ctx->iteration;
}

Expand Down
Loading

0 comments on commit 84821ad

Please sign in to comment.