-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TMP: add pcaps, for now dealing with capacity of shm
- Loading branch information
1 parent
1691b6f
commit 0fd8555
Showing
9 changed files
with
139 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,63 @@ | ||
#include "sharedmemory.h" | ||
#include "common/type.h" | ||
#include "common/utils.h" | ||
#include "metadata.h" | ||
|
||
using namespace sharedmemory; | ||
namespace sharedmemory | ||
{ | ||
|
||
SharedMemoryDumpRing::SharedMemoryDumpRing(DumpFormat format, void* memory, size_t dump_size, size_t dump_count) : | ||
format_(format) | ||
DumpRingRaw::DumpRingRaw(void* memory, size_t max_pkt_size, size_t pkt_count) : | ||
buffer_(memory, max_pkt_size, pkt_count), ring_(buffer_.ring) | ||
{ | ||
switch (format_) | ||
{ | ||
case DumpFormat::kPcap: | ||
// init somehow with pcaps | ||
break; | ||
|
||
case DumpFormat::kRaw: | ||
buffer = common::PacketBufferRing(memory, dump_size, dump_count); | ||
capacity_ = buffer.capacity; | ||
|
||
buffer.ring->header.before = 0; | ||
buffer.ring->header.after = 0; | ||
|
||
break; | ||
default: | ||
YANET_THROW("Wrong shared memory dump format"); | ||
} | ||
ring_->header.before = 0; | ||
ring_->header.after = 0; | ||
} | ||
|
||
void SharedMemoryDumpRing::write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type) | ||
void DumpRingRaw::write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type) | ||
{ | ||
// Each ring has its own header, the header contains absolute position | ||
// to which next packet should be written. Position has two state: | ||
// -- "before" increments immediately before of copying data to memory; | ||
// -- "after" increments after copying data. | ||
|
||
uint64_t wpos = (buffer.ring->header.before) % buffer.units_number; | ||
buffer.ring->header.before++; | ||
auto* item = (item_t*)((uintptr_t)buffer.ring->memory + (wpos * buffer.unit_size)); | ||
uint64_t wpos = (ring_->header.before) % buffer_.units_number; | ||
ring_->header.before++; | ||
auto* item = utils::ShiftBuffer<item_t*>(ring_->memory, wpos * buffer_.unit_size); | ||
|
||
dataplane::metadata* metadata = YADECAP_METADATA(mbuf); | ||
|
||
uint64_t memory_size = buffer.unit_size - sizeof(ring_header_t); | ||
uint64_t memory_size = buffer_.unit_size - sizeof(ring_header_t); | ||
uint64_t copy_size = RTE_MIN(memory_size, mbuf->data_len); | ||
|
||
item->header.size = copy_size; | ||
item->header.tag = metadata->hash; | ||
item->header.in_logicalport_id = metadata->in_logicalport_id; | ||
item->header.out_logicalport_id = metadata->out_logicalport_id; | ||
item->header.flow_type = (uint8_t)flow_type; | ||
item->header.flow_type = static_cast<uint8_t>(flow_type); | ||
|
||
memcpy(item->memory, | ||
rte_pktmbuf_mtod(mbuf, void*), | ||
copy_size); | ||
memcpy(item->memory, rte_pktmbuf_mtod(mbuf, void*), copy_size); | ||
|
||
YANET_MEMORY_BARRIER_COMPILE; | ||
|
||
buffer.ring->header.after++; | ||
ring_->header.after++; | ||
} | ||
|
||
size_t DumpRingRaw::GetCapacity(size_t max_pkt_size, size_t pkt_count) | ||
{ | ||
return PacketBufferRing::GetCapacity(max_pkt_size, pkt_count); | ||
} | ||
|
||
DumpRingPcap::DumpRingPcap(void* memory, size_t max_pkt_size, size_t pkt_count) : dev_(memory, 12, 3) | ||
{ | ||
} | ||
|
||
void DumpRingPcap::write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type) | ||
{ | ||
} | ||
|
||
size_t DumpRingPcap::GetCapacity(size_t max_pkt_size, size_t pkt_count) | ||
{ | ||
return 0; | ||
} | ||
|
||
} // namespace sharedmemory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,86 @@ | ||
#pragma once | ||
//TODO: RENAME TO dump_rings.h | ||
|
||
#include <rte_mbuf.h> | ||
|
||
#include "common/bufferring.h" | ||
#include "common/type.h" | ||
|
||
#include "config.h" | ||
#include "pcap_shm_device.h" | ||
|
||
namespace sharedmemory | ||
{ | ||
|
||
using ring_header_t = common::PacketBufferRing::ring_header_t; | ||
using ring_t = common::PacketBufferRing::ring_t; | ||
using item_header_t = common::PacketBufferRing::item_header_t; | ||
using item_t = common::PacketBufferRing::item_t; | ||
using DumpFormat = tDataPlaneConfig::DumpFormat; | ||
using DumpConfig = tDataPlaneConfig::DumpConfig; | ||
|
||
struct DumpRingBase | ||
{ | ||
virtual ~DumpRingBase() = 0; | ||
|
||
class SharedMemoryDumpRing | ||
virtual void write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type) = 0; | ||
}; | ||
|
||
class DumpRingRaw : public DumpRingBase | ||
{ | ||
DumpFormat format_; | ||
size_t capacity_; | ||
using PacketBufferRing = common::PacketBufferRing; | ||
using ring_t = PacketBufferRing::ring_t; | ||
using item_t = PacketBufferRing::item_t; | ||
using ring_header_t = PacketBufferRing::ring_header_t; | ||
|
||
PacketBufferRing buffer_; | ||
ring_t* ring_; | ||
|
||
public: | ||
SharedMemoryDumpRing() : | ||
format_(DumpFormat::kRaw), capacity_(0) {} | ||
DumpRingRaw(void* memory, size_t max_pkt_size, size_t pkt_count); | ||
|
||
SharedMemoryDumpRing(DumpFormat format, void* memory, size_t dump_size, size_t dump_count); | ||
void write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type) override; | ||
|
||
void write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type); | ||
static size_t GetCapacity(size_t max_pkt_size, size_t pkt_count); | ||
}; | ||
|
||
class DumpRingPcap : public DumpRingBase | ||
{ | ||
pcpp::PcapShmWriterDevice dev_; | ||
|
||
public: | ||
DumpRingPcap(void* memory, size_t max_pkt_size, size_t pkt_count); | ||
|
||
// FIXME: make it private. I've made it public to simplify hexdump code | ||
common::PacketBufferRing buffer; | ||
void write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type) override; | ||
|
||
[[nodiscard]] size_t Capacity() const | ||
static size_t GetCapacity(size_t max_pkt_size, size_t pkt_count); | ||
}; | ||
|
||
inline size_t GetCapacity(const DumpConfig& config) | ||
{ | ||
auto& [format, max_pkt_size, pkt_count] = config; | ||
|
||
switch (format) | ||
{ | ||
return capacity_; | ||
case DumpFormat::kRaw: | ||
return DumpRingRaw::GetCapacity(max_pkt_size, pkt_count); | ||
case DumpFormat::kPcap: | ||
return DumpRingPcap::GetCapacity(max_pkt_size, pkt_count); | ||
default: | ||
YANET_THROW("Invalid dump format"); | ||
std::abort(); | ||
} | ||
}; | ||
} | ||
|
||
inline std::unique_ptr<DumpRingBase> CreateSharedMemoryDumpRing(const DumpConfig& config, void* memory) | ||
{ | ||
auto& [format, max_pkt_size, pkt_count] = config; | ||
|
||
switch (format) | ||
{ | ||
case DumpFormat::kRaw: | ||
return std::make_unique<DumpRingRaw>(memory, max_pkt_size, pkt_count); | ||
case DumpFormat::kPcap: | ||
return std::make_unique<DumpRingPcap>(memory, max_pkt_size, pkt_count); | ||
default: | ||
YANET_THROW("Invalid dump format"); | ||
std::abort(); | ||
} | ||
} | ||
|
||
} // namespace sharedmemory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters