Agora  1.2.0
Agora project
packet_txrx_dpdk.h
Go to the documentation of this file.
1 
7 #ifndef PACKETTXRX_DPDK_H_
8 #define PACKETTXRX_DPDK_H_
9 
10 #if !defined(USE_DPDK)
11 static_assert(false, "Packet tx rx dpdk defined but DPDK is not enabled");
12 #endif
13 
14 #include "dpdk_transport.h"
15 #include "packet_txrx.h"
16 
17 //Removed support for copy free dpdk memory due to slowdown issue.
18 //#define USE_DPDK_MEMORY
19 
20 #if defined(USE_DPDK_MEMORY)
21 class DPDKRxPacket : public RxPacket {
22  public:
23  DPDKRxPacket() : RxPacket() { mem_ = nullptr; }
24  explicit DPDKRxPacket(const DPDKRxPacket& copy) : RxPacket(copy) {
25  mem_ = copy.mem_;
26  }
27  ~DPDKRxPacket() = default;
28  inline bool Set(rte_mbuf* mem, Packet* in_pkt) {
29  mem_ = mem;
30  return RxPacket::Set(in_pkt);
31  }
32 
33  private:
34  rte_mbuf* mem_;
35  inline void GcPacket() override {
36  //std::printf("Garbage collecting the memory for DPDKRxPacket\n");
37  rte_pktmbuf_free(mem_);
38  this->Set(nullptr, nullptr);
39  }
40 };
41 #endif // defined(USE_DPDK_MEMORY)
42 
46 class PacketTxRxDpdk : public PacketTxRx {
47  public:
48  PacketTxRxDpdk(Config* const cfg, size_t core_offset,
51  moodycamel::ProducerToken** notify_producer_tokens,
52  moodycamel::ProducerToken** tx_producer_tokens,
53  Table<char>& rx_buffer, size_t packet_num_in_buffer,
54  Table<size_t>& frame_start, char* tx_buffer);
55  ~PacketTxRxDpdk() final;
56 
57  private:
58  void DoTxRx(size_t tid); // The thread function for thread [tid]
59 
60  bool CreateWorker(size_t tid, size_t interface_count, size_t interface_offset,
61  size_t* rx_frame_start, std::vector<RxPacket>& rx_memory,
62  std::byte* const tx_memory) final;
63 
64  uint32_t bs_rru_addr_; // IPv4 address of the simulator sender
65  uint32_t bs_server_addr_; // IPv4 address of the Agora server
66  rte_mempool* mbuf_pool_;
67 
68  // Worker x (dpdk dev : queueid)
69  std::vector<std::vector<std::pair<uint16_t, uint16_t>>>
71 
72  // Dimension 1: socket_thread
73  // Dimension 2: rx_packet
74 #if defined(USE_DPDK_MEMORY)
75  std::vector<std::vector<DPDKRxPacket>> rx_packets_dpdk_;
76 #endif
77 };
78 
79 #endif // PACKETTXRX_DPDK_H_
AgoraTxRx
Definition: packet_txrx.h:18
PacketTxRxDpdk::worker_dev_queue_assignment_
std::vector< std::vector< std::pair< uint16_t, uint16_t > > > worker_dev_queue_assignment_
Definition: packet_txrx_dpdk.h:70
PacketTxRx::cond_
std::condition_variable cond_
Definition: packet_txrx.h:90
fmt::v8::detail::byte
byte
Definition: core.h:388
PacketTxRx::mutex_
std::mutex mutex_
Owned by this class and shared with the workers.
Definition: packet_txrx.h:89
PacketTxRx::worker_threads_
std::vector< std::unique_ptr< TxRxWorker > > worker_threads_
Definition: packet_txrx.h:76
moodycamel::ProducerToken
Definition: concurrentqueue.h:630
AgoraTxRx::TxRxTypes
TxRxTypes
Definition: packet_txrx.h:19
PacketTxRx::tx_producer_tokens_
moodycamel::ProducerToken ** tx_producer_tokens_
Definition: packet_txrx.h:86
DpdkTransport::GetPortIDFromMacAddr
static std::vector< uint16_t > GetPortIDFromMacAddr(size_t port_num, const std::string &mac_addrs)
PacketTxRxDpdk::bs_server_addr_
uint32_t bs_server_addr_
Definition: packet_txrx_dpdk.h:65
packet_txrx_dpdk.h
Implementation of PacketTxRxDpdk datapath functions for communicating with DPDK.
packet_txrx.h
Common definations for PacketTxRx. Including datapath functions for communicating with simulators.
PacketTxRx::StopTxRx
bool StopTxRx()
Definition: packet_txrx.cc:109
PacketTxRx::cfg_
Config *const cfg_
Definition: packet_txrx.h:77
PacketTxRxDpdk::DoTxRx
void DoTxRx(size_t tid)
AGORA_LOG_ERROR
#define AGORA_LOG_ERROR(...)
Definition: logger.h:39
PacketTxRx::proceed_
std::atomic< bool > proceed_
Definition: packet_txrx.h:91
Table< char >
txrx_worker_dpdk.h
txrx worker dpdk definition. This is the simulator declaration with dpdk enhancements
Config::DpdkPortOffset
uint16_t DpdkPortOffset() const
Definition: config.h:314
PacketTxRxDpdk::mbuf_pool_
rte_mempool * mbuf_pool_
Definition: packet_txrx_dpdk.h:66
RxPacket::GcPacket
virtual void GcPacket()
Definition: message.h:191
PacketTxRx::NumberTotalWorkers
size_t NumberTotalWorkers() const
Definition: packet_txrx.h:67
i
for i
Definition: generate_data.m:107
Config::BsServerAddr
std::string BsServerAddr() const
Definition: config.h:299
Packet
Definition: message.h:164
DpdkTransport::CreateMempool
static rte_mempool * CreateMempool(size_t num_ports, size_t packet_length=kJumboFrameMaxSize)
PacketTxRx::NumberTotalInterfaces
size_t NumberTotalInterfaces() const
Definition: packet_txrx.h:68
PacketTxRx
Implementations of this class provide packet I/O for Agora.
Definition: packet_txrx.h:34
PacketTxRxDpdk
Implementations of this class provide packet I/O for Agora using dpdk accelerations.
Definition: packet_txrx_dpdk.h:46
moodycamel::ConcurrentQueue< EventData >
PacketTxRx::event_notify_q_
moodycamel::ConcurrentQueue< EventData > * event_notify_q_
Definition: packet_txrx.h:80
kUseDPDK
static constexpr bool kUseDPDK
Definition: symbols.h:144
frame_start
frame_start
Definition: parse_dl_file.m:6
DpdkTransport::NicInit
static int NicInit(uint16_t port, struct rte_mempool *mbuf_pool, int thread_num, size_t pkt_len=kJumboFrameMaxSize)
PacketTxRx::notify_producer_tokens_
moodycamel::ProducerToken ** notify_producer_tokens_
Definition: packet_txrx.h:84
Config
Definition: config.h:26
AGORA_LOG_INFO
#define AGORA_LOG_INFO(...)
Definition: logger.h:62
Config::DpdkMacAddrs
const std::string & DpdkMacAddrs() const
Definition: config.h:316
AGORA_LOG_FRAME
#define AGORA_LOG_FRAME(...)
Definition: logger.h:72
RtAssert
static void RtAssert(bool condition, const char *throw_str)
Definition: utils.h:104
fmt::v8::detail::copy
OutputIterator copy(const RangeT &range, OutputIterator out)
Definition: ranges.h:26
to_string
std::string to_string() const
Definition: eth_common.h:64
PacketTxRx::core_offset_
const size_t core_offset_
Definition: packet_txrx.h:79
RxPacket
Definition: message.h:186
PacketTxRxDpdk::CreateWorker
bool CreateWorker(size_t tid, size_t interface_count, size_t interface_offset, size_t *rx_frame_start, std::vector< RxPacket > &rx_memory, std::byte *const tx_memory) final
Definition: packet_txrx_dpdk.cc:132
PacketTxRx::InterfaceToWorker
const size_t & InterfaceToWorker(size_t interface) const
Definition: packet_txrx.h:71
RxPacket::Set
bool Set(Packet *in_pkt)
Definition: message.h:204
PacketTxRxDpdk::~PacketTxRxDpdk
~PacketTxRxDpdk() final
Definition: packet_txrx_dpdk.cc:93
PacketTxRxDpdk::bs_rru_addr_
uint32_t bs_rru_addr_
Definition: packet_txrx_dpdk.h:64
dpdk_transport.h
Declaration file for the DpdkTransport class.
DpdkTransport::DpdkInit
static void DpdkInit(uint16_t core_offset, size_t thread_num)
Init dpdk on core [core_offset:core_offset+thread_num].
Config::DpdkNumPorts
uint16_t DpdkNumPorts() const
Definition: config.h:313
PacketTxRxDpdk::PacketTxRxDpdk
PacketTxRxDpdk(Config *const cfg, size_t core_offset, moodycamel::ConcurrentQueue< EventData > *event_notify_q, moodycamel::ConcurrentQueue< EventData > *tx_pending_q, moodycamel::ProducerToken **notify_producer_tokens, moodycamel::ProducerToken **tx_producer_tokens, Table< char > &rx_buffer, size_t packet_num_in_buffer, Table< size_t > &frame_start, char *tx_buffer)
Definition: packet_txrx_dpdk.cc:14
PacketTxRx::tx_pending_q_
moodycamel::ConcurrentQueue< EventData > * tx_pending_q_
Definition: packet_txrx.h:81
Config::BsRruAddr
std::string BsRruAddr() const
Definition: config.h:302
AgoraTxRx::kBaseStation
@ kBaseStation
Definition: packet_txrx.h:19
PacketTxRx::NumChannels
size_t NumChannels() const
Definition: packet_txrx.h:74