Skip to content

Commit

Permalink
FromDump/FromFile: Add DPDK arugment
Browse files Browse the repository at this point in the history
Forces the creation of a DPDK packet. MMAP should also be set to false,
as it is useless with small buffers.
  • Loading branch information
tbarbette committed Jan 14, 2025
1 parent d6509a5 commit ae011a3
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 24 deletions.
3 changes: 3 additions & 0 deletions include/click/fromfile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class FromFile { public:
#ifdef ALLOW_MMAP
bool _mmap;
#endif
#if HAVE_DPDK
bool _dpdk;
#endif

#ifdef ALLOW_MMAP
enum { WANT_MMAP_UNIT = 4194304 }; // 4 MB
Expand Down
2 changes: 2 additions & 0 deletions include/click/packet.hh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class Packet { public:
uint32_t length, uint32_t tailroom, bool clear = true) CLICK_WARN_UNUSED_RESULT;
static inline WritablePacket *make(const void *data, uint32_t length) CLICK_WARN_UNUSED_RESULT;
static inline WritablePacket *make(uint32_t length) CLICK_WARN_UNUSED_RESULT;
static WritablePacket *make_dpdk_packet(uint32_t headroom,
uint32_t length, uint32_t tailroom, bool clear) CLICK_WARN_UNUSED_RESULT;
static WritablePacket *make_similar(Packet* original, uint32_t length) CLICK_WARN_UNUSED_RESULT;
#if CLICK_LINUXMODULE
static Packet *make(struct sk_buff *skb) CLICK_WARN_UNUSED_RESULT;
Expand Down
66 changes: 46 additions & 20 deletions lib/fromfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ FromFile::FromFile()
#endif
#ifdef ALLOW_MMAP
_mmap(true),
#endif
#if HAVE_DPDK
_dpdk(true),
#endif
_filename(), _pipe(0), _landmark_pattern("%f"), _lineno(0)
{
Expand All @@ -57,20 +60,32 @@ FromFile::FromFile()
int
FromFile::configure_keywords(Vector<String> &conf, Element *e, ErrorHandler *errh)
{
#if HAVE_DPDK
bool dpdk = _dpdk;
#else
bool dpdk = false;
#endif
#ifdef ALLOW_MMAP
bool mmap = _mmap;
#else
bool mmap = false;
#endif
if (Args(e, errh).bind(conf)
.read("MMAP", mmap)
.read("DPDK", dpdk)
.consume() < 0)
return -1;
#ifdef ALLOW_MMAP
_mmap = mmap;
#else
if (mmap)
errh->warning("%<MMAP true%> is not supported on this platform");
#endif
#if HAVE_DPDK
_dpdk = dpdk;
#else
if (dpdk)
errh->warning("%<DPDK true%> is not supported on this platform");
#endif
return 0;
}
Expand Down Expand Up @@ -245,16 +260,16 @@ FromFile::read(void *vdata, uint32_t dlen, ErrorHandler *errh)
uint32_t dpos = 0;

while (dpos < dlen) {
if (_pos < _len) {
uint32_t howmuch = dlen - dpos;
if (howmuch > _len - _pos)
howmuch = _len - _pos;
memcpy(data + dpos, _buffer + _pos, howmuch);
dpos += howmuch;
_pos += howmuch;
}
if (dpos < dlen && read_buffer(errh) <= 0)
return dpos;
if (_pos < _len) {
uint32_t howmuch = dlen - dpos;
if (howmuch > _len - _pos)
howmuch = _len - _pos;
memcpy(data + dpos, _buffer + _pos, howmuch);
dpos += howmuch;
_pos += howmuch;
}
if (dpos < dlen && read_buffer(errh) <= 0)
return dpos;
}

return dlen;
Expand Down Expand Up @@ -577,10 +592,21 @@ FromFile::get_string(size_t size, ErrorHandler *errh)
Packet *
FromFile::get_packet(size_t size, uint32_t sec, uint32_t subsec, ErrorHandler *errh)
{
if (_dpdk) {
WritablePacket *p = Packet::make_dpdk_packet(0, size, 0, 0);
//click_chatter("P %p, %d %d %d %d", p, p->length(), p->buffer_length(), p->headroom(), p->tailroom());
assert(DPDKDevice::is_dpdk_packet(p));
if (read(p->data(), size, errh) < (int)size) {
p->kill();
return 0;
} else {
p->timestamp_anno().assign(sec, subsec);
return p;
}
}
#if CLICK_PACKET_USE_DPDK
#else
if (_pos + size <= _len) {

#ifndef CLICK_NOINDIRECT
if (Packet *p = _data_packet->clone()) {
p->shrink_data(_buffer + _pos, size);
Expand All @@ -598,15 +624,15 @@ FromFile::get_packet(size_t size, uint32_t sec, uint32_t subsec, ErrorHandler *e
} else
#endif
{
if (WritablePacket *p = Packet::make(0, 0, size, 0)) {
if (read(p->data(), size, errh) < (int)size) {
p->kill();
return 0;
} else {
p->timestamp_anno().assign(sec, subsec);
return p;
}
}
if (WritablePacket *p = Packet::make(0, 0, size, 0)) {
if (read(p->data(), size, errh) < (int)size) {
p->kill();
return 0;
} else {
p->timestamp_anno().assign(sec, subsec);
return p;
}
}
}
error(errh, strerror(ENOMEM));
return 0;
Expand Down
52 changes: 48 additions & 4 deletions lib/packet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,9 @@ inline bool
Packet::alloc_data(uint32_t headroom, uint32_t length, uint32_t tailroom)
{
uint32_t n = length + headroom + tailroom;
if (n < min_buffer_length) {
tailroom = min_buffer_length - length - headroom;
n = min_buffer_length;
if (unlikely(n < min_buffer_length)) {
tailroom = min_buffer_length - length - headroom;
n = min_buffer_length;
}
# if CLICK_USERLEVEL || CLICK_MINIOS
unsigned char *d = 0;
Expand Down Expand Up @@ -839,6 +839,49 @@ void WritablePacket::pool_transfer(int from, int to) {
}


/**
* @brief Make a Packet with a DPDK-backed buffer
*
* @param headroom
* @param data
* @param length
* @param tailroom
* @param clear
* @return WritablePacket*
*/
WritablePacket *
Packet::make_dpdk_packet(uint32_t headroom, uint32_t length, uint32_t tailroom, bool clear) {
uint32_t n = length + headroom + tailroom;
if (unlikely(n < min_buffer_length)) {
tailroom = min_buffer_length - length - headroom;
n = min_buffer_length;
}

WritablePacket* p = WritablePacket::pool_allocate();

unsigned char *d = 0;

struct rte_mbuf *mb = DPDKDevice::get_pkt();
if (likely(mb)) {
d = (unsigned char*)mb->buf_addr;
p->_destructor = DPDKDevice::free_pkt;
p->_destructor_argument = mb;
} else {
p->kill();
return 0;
}

p->_head = d;
p->_data = d + headroom;
p->_tail = p->_data + length;
p->_end = p->_head + n;
p->_use_count = 1;
p->_data_packet = 0;
if (clear)
p->clear_annotations();
return p;
}



/** @brief Create and return a new packet.
Expand Down Expand Up @@ -938,9 +981,10 @@ Packet::make(uint32_t headroom, const void *data,
#endif
return p;
#endif

}



#if CLICK_USERLEVEL || CLICK_MINIOS
/** @brief Create and return a new packet (userlevel).
* @param data data used in the new packet
Expand Down

0 comments on commit ae011a3

Please sign in to comment.