NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pcc-entry.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_PCCT_PCC_ENTRY_H
2 #define NDNDPDK_PCCT_PCC_ENTRY_H
3 
6 #include "../vendor/uthash-handle.h"
7 #include "cs-entry.h"
8 #include "pcc-key.h"
9 #include "pit-entry.h"
10 
11 enum {
13  PccTokenBits = PccTokenSize * CHAR_BIT,
14  PccTokenMask = ((uint64_t)1 << PccTokenBits) - 1,
15 };
16 
17 typedef struct PccEntry PccEntry;
18 
24 typedef union PccSlot {
25  struct {
26  uint64_t a_[2];
28  };
32 
34 typedef enum PccSlotIndex {
36  PCC_SLOT1 = 1,
37  PCC_SLOT2 = 2,
38  PCC_SLOT3 = 3,
40 
46 typedef struct PccEntryExt {
50 
56 struct PccEntry {
58  UT_hash_handle hh;
59 
60  RTE_MARKER a_;
61  union {
62  struct {
63  bool hasToken : 1;
64  int : 1;
68  int : 8;
69  uint64_t token : PccTokenBits;
71  struct {
72  int : 2;
73  const int hasPitEntry0 : 2;
74  const int hasPitEntry1 : 2;
75  const int hasCsEntry : 2;
76  uint64_t : 56;
78  struct {
79  int : 2;
80  const int hasPitEntries : 4;
81  uint64_t : 58;
83  struct {
84  int : 2;
85  const int hasEntries : 6;
86  uint64_t : 56;
88  uint64_t tokenQword;
89  };
90  RTE_MARKER b_;
91 
94 };
95 static_assert(offsetof(PccEntry, b_) - offsetof(PccEntry, a_) == sizeof(uint64_t), "");
96 
97 __attribute__((nonnull)) static __rte_always_inline PccSlot*
98 PccEntry_GetSlot_(PccEntry* entry, PccSlotIndex slot) {
99  switch (slot) {
100  case PCC_SLOT1:
101  return &entry->slot1;
102  case PCC_SLOT2:
103  NDNDPDK_ASSERT(entry->ext != NULL);
104  return &entry->ext->slot2;
105  case PCC_SLOT3:
106  NDNDPDK_ASSERT(entry->ext != NULL);
107  return &entry->ext->slot3;
108  default:
109  NDNDPDK_ASSERT(false);
110  return NULL;
111  }
112 }
113 
114 __attribute__((nonnull)) PccSlotIndex
115 PccEntry_AllocateSlot_(PccEntry* entry, PccSlot** slot);
116 
117 __attribute__((nonnull)) PccSlotIndex
119 
124 __attribute__((nonnull, returns_nonnull)) static inline PitEntry*
125 PccEntry_GetPitEntry0(PccEntry* entry) {
126  return &PccEntry_GetSlot_(entry, entry->pitEntry0Slot)->pitEntry;
127 }
128 
134 __attribute__((nonnull)) static inline PitEntry*
135 PccEntry_AddPitEntry0(PccEntry* entry) {
136  if (entry->hasPitEntry0) {
137  return PccEntry_GetPitEntry0(entry);
138  }
139  PccSlot* slot = NULL;
140  entry->pitEntry0Slot = PccEntry_AllocateSlot_(entry, &slot);
141  if (unlikely(slot == NULL)) {
142  return NULL;
143  }
144  return &slot->pitEntry;
145 }
146 
148 __attribute__((nonnull)) static inline void
149 PccEntry_RemovePitEntry0(PccEntry* entry) {
150  entry->pitEntry0Slot = PccEntry_ClearSlot_(entry, entry->pitEntry0Slot);
151 }
152 
157 __attribute__((nonnull, returns_nonnull)) static inline PitEntry*
158 PccEntry_GetPitEntry1(PccEntry* entry) {
159  return &PccEntry_GetSlot_(entry, entry->pitEntry1Slot)->pitEntry;
160 }
161 
167 __attribute__((nonnull)) static inline PitEntry*
168 PccEntry_AddPitEntry1(PccEntry* entry) {
169  if (entry->hasPitEntry1) {
170  return PccEntry_GetPitEntry1(entry);
171  }
172  PccSlot* slot = NULL;
173  entry->pitEntry1Slot = PccEntry_AllocateSlot_(entry, &slot);
174  if (unlikely(slot == NULL)) {
175  return NULL;
176  }
177  return &slot->pitEntry;
178 }
179 
181 __attribute__((nonnull)) static inline void
182 PccEntry_RemovePitEntry1(PccEntry* entry) {
183  entry->pitEntry1Slot = PccEntry_ClearSlot_(entry, entry->pitEntry1Slot);
184 }
185 
190 __attribute__((nonnull, returns_nonnull)) static inline CsEntry*
191 PccEntry_GetCsEntry(PccEntry* entry) {
192  return &PccEntry_GetSlot_(entry, entry->csEntrySlot)->csEntry;
193 }
194 
200 __attribute__((nonnull)) static inline CsEntry*
201 PccEntry_AddCsEntry(PccEntry* entry) {
202  if (entry->hasCsEntry) {
203  return PccEntry_GetCsEntry(entry);
204  }
205  PccSlot* slot = NULL;
206  entry->csEntrySlot = PccEntry_AllocateSlot_(entry, &slot);
207  if (unlikely(slot == NULL)) {
208  return NULL;
209  }
210  return &slot->csEntry;
211 }
212 
214 __attribute__((nonnull)) static inline void
215 PccEntry_RemoveCsEntry(PccEntry* entry) {
216  entry->csEntrySlot = PccEntry_ClearSlot_(entry, entry->csEntrySlot);
217 }
218 
219 #endif // NDNDPDK_PCCT_PCC_ENTRY_H
struct vlanhdr __rte_packed
#define NDNDPDK_ASSERT(x)
Definition: common.h:60
PccSlotIndex PccEntry_ClearSlot_(PccEntry *entry, PccSlotIndex slot)
Definition: pcc-entry.c:49
PccSlotIndex
Identify a PCC entry slot.
Definition: pcc-entry.h:34
@ PCC_SLOT_NONE
Definition: pcc-entry.h:35
@ PCC_SLOT3
Definition: pcc-entry.h:38
@ PCC_SLOT1
Definition: pcc-entry.h:36
@ PCC_SLOT2
Definition: pcc-entry.h:37
@ PccTokenBits
Definition: pcc-entry.h:13
@ PccTokenSize
Definition: pcc-entry.h:12
@ PccTokenMask
Definition: pcc-entry.h:14
struct PccEntryExt PccEntryExt
PCC entry extension.
union PccSlot PccSlot
PCC entry slot.
PccSlotIndex PccEntry_AllocateSlot_(PccEntry *entry, PccSlot **slot)
Definition: pcc-entry.c:8
A CS entry.
Definition: cs-entry.h:22
PCC entry extension.
Definition: pcc-entry.h:46
PccSlot slot3
Definition: pcc-entry.h:48
PccSlot slot2
Definition: pcc-entry.h:47
PIT-CS composite entry.
Definition: pcc-entry.h:56
const int hasPitEntries
Definition: pcc-entry.h:80
PccSlotIndex pitEntry1Slot
Definition: pcc-entry.h:66
bool hasToken
Definition: pcc-entry.h:63
const int hasPitEntry1
Definition: pcc-entry.h:74
UT_hash_handle hh
Definition: pcc-entry.h:58
PccSlot slot1
Definition: pcc-entry.h:92
const int hasPitEntry0
Definition: pcc-entry.h:73
uint64_t token
Definition: pcc-entry.h:69
RTE_MARKER b_
Definition: pcc-entry.h:90
const int hasEntries
Definition: pcc-entry.h:85
PccKey key
Definition: pcc-entry.h:57
PccSlotIndex pitEntry0Slot
Definition: pcc-entry.h:65
RTE_MARKER a_
Definition: pcc-entry.h:60
PccEntryExt * ext
Definition: pcc-entry.h:93
struct PccEntry::@76::@78 __rte_packed
const int hasCsEntry
Definition: pcc-entry.h:75
PccSlotIndex csEntrySlot
Definition: pcc-entry.h:67
uint64_t tokenQword
Definition: pcc-entry.h:88
Hash key stored in PccEntry .
Definition: pcc-key.h:50
A PIT entry.
Definition: pit-entry.h:24
PCC entry slot.
Definition: pcc-entry.h:24
PitEntry pitEntry
Definition: pcc-entry.h:29
PccEntry * pccEntry
NULL indicates unoccupied slot.
Definition: pcc-entry.h:27
uint64_t a_[2]
Definition: pcc-entry.h:26
CsEntry csEntry
Definition: pcc-entry.h:30