NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ndt.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_NDT_NDT_H
2 #define NDNDPDK_NDT_NDT_H
3 
6 #include "../ndni/name.h"
7 
9 typedef struct Ndt {
10  uint64_t indexMask;
11  uint64_t sampleMask;
12  uint16_t prefixLen;
13  _Atomic uint8_t table[];
14 } Ndt;
15 
17 __attribute__((returns_nonnull)) Ndt*
18 Ndt_New(uint64_t nEntries, int numaSocket);
19 
21 __attribute__((nonnull)) static inline void
22 Ndt_Update(Ndt* ndt, uint64_t index, uint8_t value) {
23  atomic_store_explicit(&ndt->table[index], value, memory_order_relaxed);
24 }
25 
27 __attribute__((nonnull)) static __rte_always_inline uint8_t
28 Ndt_Read(Ndt* ndt, uint64_t index) {
29  return atomic_load_explicit(&ndt->table[index], memory_order_relaxed);
30 }
31 
33 __attribute__((nonnull)) static inline uint8_t
34 Ndt_Lookup(Ndt* ndt, const PName* name, uint64_t* index) {
35  uint16_t prefixLen = RTE_MIN(name->nComps, ndt->prefixLen);
36  LName prefix = PName_GetPrefix(name, prefixLen);
37  // compute hash in 'uncached' mode, to reduce workload of FwInput thread
38  uint64_t hash = LName_ComputeHash(prefix);
39  *index = hash & ndt->indexMask;
40  return Ndt_Read(ndt, *index);
41 }
42 
48 typedef struct NdtQuerier {
49  Ndt* ndt;
50  uint64_t nLookups;
51  uint32_t* nHits;
53 
55 __attribute__((nonnull)) static inline uint8_t
56 NdtQuerier_Lookup(NdtQuerier* ndq, const PName* name) {
57  uint64_t index;
58  uint8_t value = Ndt_Lookup(ndq->ndt, name, &index);
59  if ((++ndq->nLookups & ndq->ndt->sampleMask) == 0) {
60  ++ndq->nHits[index];
61  }
62  return value;
63 }
64 
65 #endif // NDNDPDK_NDT_NDT_H
uint64_t LName_ComputeHash(LName name)
Compute hash for a name.
Definition: name.c:10
struct Ndt Ndt
A replica of the Name Dispatch Table (NDT).
Ndt * Ndt_New(uint64_t nEntries, int numaSocket)
Create NDT replica.
Definition: ndt.c:4
struct NdtQuerier NdtQuerier
NDT querier with counters.
Name in linear buffer.
Definition: name.h:11
NDT querier with counters.
Definition: ndt.h:48
Ndt * ndt
Definition: ndt.h:49
uint64_t nLookups
Definition: ndt.h:50
uint32_t * nHits
Definition: ndt.h:51
A replica of the Name Dispatch Table (NDT).
Definition: ndt.h:9
_Atomic uint8_t table[]
Definition: ndt.h:13
uint64_t indexMask
Definition: ndt.h:10
uint16_t prefixLen
Definition: ndt.h:12
uint64_t sampleMask
Definition: ndt.h:11
Parsed name.
Definition: name.h:139
uint16_t nComps
number of components
Definition: name.h:142