NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pcc-key.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_PCCT_PCC_KEY_H
2 #define NDNDPDK_PCCT_PCC_KEY_H
3 
6 #include "../ndni/interest.h"
7 
8 #define PccKey_CountExtensions_(nameL, fhL) \
9  (SPDK_CEIL_DIV(nameL - PccKeyNameCapacity, PccKeyExtCapacity) + \
10  SPDK_CEIL_DIV(fhL - PccKeyFhCapacity, PccKeyExtCapacity))
11 
12 enum {
17 };
18 
20 typedef struct PccSearch {
23  uint64_t hash;
25 
27 __attribute__((nonnull)) static inline PccSearch
28 PccSearch_FromNames(const PName* name, const PInterest* interest) {
29  PccSearch search = {
30  .name = PName_ToLName(name),
31  .hash = PName_ComputeHash(name),
32  };
33  if (interest->activeFwHint >= 0) {
34  search.fh = PName_ToLName(&interest->fwHint);
35  search.hash ^= PName_ComputeHash(&interest->fwHint);
36  }
37  return search;
38 }
39 
44 __attribute__((nonnull, returns_nonnull)) const char*
46 
47 typedef struct PccKeyExt PccKeyExt;
48 
50 typedef struct PccKey {
53  uint16_t nameL;
54  uint16_t fhL;
58 
59 struct PccKeyExt {
62 };
63 
64 __attribute__((nonnull)) bool
65 PccKey_MatchFieldWithExt_(LName name, const uint8_t* firstV, uint16_t firstCapacity,
66  const PccKeyExt* ext);
67 
68 __attribute__((nonnull(2))) static __rte_always_inline bool
69 PccKey_MatchField_(LName name, const uint8_t* firstV, uint16_t firstCapacity,
70  const PccKeyExt* ext) {
71  if (unlikely(name.length > firstCapacity)) {
72  return PccKey_MatchFieldWithExt_(name, firstV, firstCapacity, ext);
73  }
74  return memcmp(firstV, name.value, name.length) == 0;
75 }
76 
78 __attribute__((nonnull)) static inline bool
79 PccKey_MatchName(const PccKey* key, LName name) {
80  return name.length == key->nameL &&
81  PccKey_MatchField_(name, key->nameV, PccKeyNameCapacity, key->nameExt);
82 }
83 
85 __attribute__((nonnull)) static inline bool
86 PccKey_MatchSearch(const PccKey* key, const PccSearch* search) {
87  return search->fh.length == key->fhL && PccKey_MatchName(key, search->name) &&
88  PccKey_MatchField_(search->fh, key->fhV, PccKeyFhCapacity, key->fhExt);
89 }
90 
92 __attribute__((nonnull)) static inline int
93 PccKey_CountExtensions(const PccSearch* search) {
94  return PccKey_CountExtensions_(search->name.length, search->fh.length);
95 }
96 
97 __attribute__((nonnull)) int
98 PccKey_WriteFieldWithExt_(LName name, uint8_t* firstV, uint16_t firstCapacity, PccKeyExt** next,
99  PccKeyExt* exts[]);
100 
101 __attribute__((nonnull)) static __rte_always_inline int
102 PccKey_WriteField_(LName name, uint8_t* firstV, uint16_t firstCapacity, PccKeyExt** next,
103  PccKeyExt* exts[]) {
104  if (unlikely(name.length > firstCapacity)) {
105  return PccKey_WriteFieldWithExt_(name, firstV, firstCapacity, next, exts);
106  }
107  rte_memcpy(firstV, name.value, name.length);
108  *next = NULL;
109  return 0;
110 }
111 
113 __attribute__((nonnull)) static inline void
114 PccKey_CopyFromSearch(PccKey* key, const PccSearch* search, PccKeyExt* exts[], int nExts) {
115  NDNDPDK_ASSERT(nExts == PccKey_CountExtensions(search));
116  key->nameL = search->name.length;
117  key->fhL = search->fh.length;
118  int nNameExts =
119  PccKey_WriteField_(search->name, key->nameV, PccKeyNameCapacity, &key->nameExt, exts);
120  int nFhExts =
121  PccKey_WriteField_(search->fh, key->fhV, PccKeyFhCapacity, &key->fhExt, &exts[nNameExts]);
122  NDNDPDK_ASSERT(nNameExts + nFhExts == nExts);
123 }
124 
126 __attribute__((nonnull)) static inline int
127 PccKey_StripExts(PccKey* key, PccKeyExt* exts[PccKeyMaxExts]) {
128  int nExts = 0;
129  for (PccKeyExt* ext = key->nameExt; unlikely(ext != NULL); ext = ext->next) {
130  exts[nExts++] = ext;
131  }
132  for (PccKeyExt* ext = key->fhExt; unlikely(ext != NULL); ext = ext->next) {
133  exts[nExts++] = ext;
134  }
135  NDNDPDK_ASSERT(nExts == PccKey_CountExtensions_(key->nameL, key->fhL));
136  return nExts;
137 }
138 
139 #endif // NDNDPDK_PCCT_PCC_KEY_H
#define NDNDPDK_ASSERT(x)
Definition: common.h:60
@ NameMaxLength
Definition: enum.h:10
const char * PccSearch_ToDebugString(const PccSearch *search)
Convert search to a string for debug purpose.
Definition: pcc-key.c:9
struct PccKey PccKey
Hash key stored in PccEntry .
@ PccKeyMaxExts
Definition: pcc-key.h:16
@ PccKeyFhCapacity
Definition: pcc-key.h:14
@ PccKeyNameCapacity
Definition: pcc-key.h:13
@ PccKeyExtCapacity
Definition: pcc-key.h:15
#define PccKey_CountExtensions_(nameL, fhL)
Definition: pcc-key.h:8
bool PccKey_MatchFieldWithExt_(LName name, const uint8_t *firstV, uint16_t firstCapacity, const PccKeyExt *ext)
Definition: pcc-key.c:25
int PccKey_WriteFieldWithExt_(LName name, uint8_t *firstV, uint16_t firstCapacity, PccKeyExt **next, PccKeyExt *exts[])
Definition: pcc-key.c:43
struct PccSearch PccSearch
Hash key for searching among PccEntry .
Name in linear buffer.
Definition: name.h:11
const uint8_t * value
Definition: name.h:12
uint16_t length
Definition: name.h:13
Parsed Interest packet.
Definition: interest.h:9
int8_t activeFwHint
index of active forwarding hint
Definition: interest.h:21
PName fwHint
parsed forwarding hint at activeFwHint
Definition: interest.h:27
Parsed name.
Definition: name.h:139
Definition: pcc-key.h:59
PccKeyExt * next
Definition: pcc-key.h:60
uint8_t value[PccKeyExtCapacity]
Definition: pcc-key.h:61
Hash key stored in PccEntry .
Definition: pcc-key.h:50
PccKeyExt * fhExt
Definition: pcc-key.h:52
PccKeyExt * nameExt
Definition: pcc-key.h:51
uint8_t fhV[PccKeyFhCapacity]
Definition: pcc-key.h:56
uint8_t nameV[PccKeyNameCapacity]
Definition: pcc-key.h:55
uint16_t fhL
Definition: pcc-key.h:54
uint16_t nameL
Definition: pcc-key.h:53
Hash key for searching among PccEntry .
Definition: pcc-key.h:20
uint64_t hash
Definition: pcc-key.h:23
LName name
Definition: pcc-key.h:21
LName fh
Definition: pcc-key.h:22