NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
source.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_PDUMP_SOURCE_H
2 #define NDNDPDK_PDUMP_SOURCE_H
3 
6 #include "../core/urcu.h"
7 #include "../iface/faceid.h"
8 #include "../vendor/pcg_basic.h"
9 #include "enum.h"
10 #include <urcu-pointer.h>
11 
12 typedef struct PdumpSource PdumpSource;
13 
14 typedef bool (*PdumpSource_Filter)(PdumpSource* s, struct rte_mbuf* pkt);
15 
17 struct PdumpSource {
18  struct rte_mempool* directMp;
19  struct rte_ring* queue;
21  uint32_t mbufType;
22  uint16_t mbufPort;
23  bool mbufCopy;
24 };
25 
27 __attribute__((nonnull)) void
28 PdumpSource_Process(PdumpSource* s, struct rte_mbuf** pkts, uint16_t count);
29 
31 typedef struct PdumpSourceRef {
34 
39 __attribute__((nonnull(1))) PdumpSource*
41 
47 __attribute__((nonnull)) static __rte_always_inline PdumpSource*
48 PdumpSourceRef_Get(PdumpSourceRef* ref) {
49  return rcu_dereference(ref->s);
50 }
51 
56 __attribute__((nonnull)) static __rte_always_inline bool
57 PdumpSourceRef_Process(PdumpSourceRef* ref, struct rte_mbuf** pkts, uint16_t count) {
58  PdumpSource* s = PdumpSourceRef_Get(ref);
59  if (s == NULL) {
60  return false;
61  }
62  PdumpSource_Process(s, pkts, count);
63  return true;
64 }
65 
67 typedef struct PdumpFaceSource {
69  pcg32_random_t rng;
70  uint32_t sample[PdumpMaxNames];
71  uint16_t nameL[PdumpMaxNames];
74 
80 __attribute__((nonnull)) bool
81 PdumpFaceSource_Filter(PdumpSource* s, struct rte_mbuf* pkt);
82 
83 extern PdumpSourceRef gPdumpEthPortSources[RTE_MAX_ETHPORTS];
84 
86 typedef struct PdumpEthPortUnmatchedCtx {
88  uint16_t count;
89  struct rte_mbuf* pkts[MaxBurstSize];
91 
96 static __rte_always_inline void
97 PdumpEthPortUnmatchedCtx_Init(PdumpEthPortUnmatchedCtx* ctx, uint16_t port) {
99  ctx->source = PdumpSourceRef_Get(ref);
100  ctx->count = 0;
101  POISON(ctx->pkts);
102 }
103 
110 static __rte_always_inline bool
111 PdumpEthPortUnmatchedCtx_Append(PdumpEthPortUnmatchedCtx* ctx, struct rte_mbuf* pkt) {
112  if (ctx->source == NULL) {
113  return false;
114  }
115  ctx->pkts[ctx->count++] = pkt;
116  return true;
117 }
118 
120 static __rte_always_inline void
121 PdumpEthPortUnmatchedCtx_Process(PdumpEthPortUnmatchedCtx* ctx) {
122  if (ctx->source == NULL || ctx->count == 0) {
123  return;
124  }
125  PdumpSource_Process(ctx->source, ctx->pkts, ctx->count);
126  NULLize(ctx->source);
127  POISON(ctx->pkts);
128 }
129 
130 #endif // NDNDPDK_PDUMP_SOURCE_H
#define POISON(...)
Write junk to memory region to expose memory access bugs.
Definition: common.h:104
#define NULLize(x)
Set x to NULL to expose memory access bugs.
Definition: common.h:79
@ MaxBurstSize
Definition: enum.h:7
@ NameMaxLength
Definition: enum.h:10
@ PdumpMaxNames
Definition: enum.h:7
void PdumpSource_Process(PdumpSource *s, struct rte_mbuf **pkts, uint16_t count)
Submit packets for potential dumping.
Definition: source.c:5
bool PdumpFaceSource_Filter(PdumpSource *s, struct rte_mbuf *pkt)
Perform name filtering to determine whether to capture a packet.
Definition: source.c:51
bool(* PdumpSource_Filter)(PdumpSource *s, struct rte_mbuf *pkt)
Definition: source.h:14
PdumpSource * PdumpSourceRef_Set(PdumpSourceRef *ref, PdumpSource *s)
Assign or clear PdumpSource in PdumpSourceRef.
Definition: source.c:31
struct PdumpSourceRef PdumpSourceRef
RCU-protected pointer to PdumpSource.
PdumpSourceRef gPdumpEthPortSources[RTE_MAX_ETHPORTS]
Definition: source.c:58
struct PdumpEthPortUnmatchedCtx PdumpEthPortUnmatchedCtx
Packet dump for unmatched frames on an Ethernet port, contextual information.
struct PdumpFaceSource PdumpFaceSource
Packet dump from a face on RX or TX direction.
Packet dump for unmatched frames on an Ethernet port, contextual information.
Definition: source.h:86
uint16_t count
Definition: source.h:88
PdumpSource * source
Definition: source.h:87
struct rte_mbuf * pkts[MaxBurstSize]
Definition: source.h:89
Packet dump from a face on RX or TX direction.
Definition: source.h:67
pcg32_random_t rng
Definition: source.h:69
uint16_t nameL[PdumpMaxNames]
Definition: source.h:71
uint32_t sample[PdumpMaxNames]
Definition: source.h:70
uint8_t nameV[PdumpMaxNames *NameMaxLength]
Definition: source.h:72
PdumpSource base
Definition: source.h:68
RCU-protected pointer to PdumpSource.
Definition: source.h:31
PdumpSource * s
Definition: source.h:32
Packet dump source.
Definition: source.h:17
PdumpSource_Filter filter
Definition: source.h:20
uint32_t mbufType
Definition: source.h:21
uint16_t mbufPort
Definition: source.h:22
struct rte_mempool * directMp
Definition: source.h:18
struct rte_ring * queue
Definition: source.h:19
bool mbufCopy
Definition: source.h:23