1 #ifndef NDNDPDK_NDNI_NAME_H
2 #define NDNDPDK_NDNI_NAME_H
16 __attribute__((nonnull))
static __rte_always_inline
bool
17 LName_ParseVarNum_(
LName name, uint16_t* restrict pos, uint16_t* restrict n, uint16_t minTail) {
18 if (unlikely(*pos + 1 + minTail > name.
length)) {
22 *n = name.
value[*pos];
24 if (likely(*n < 0xFD)) {
28 if (unlikely(*n > 0xFD) || unlikely(*pos + 2 + minTail > name.
length)) {
32 *n = rte_be_to_cpu_16(*(unaligned_uint16_t*)&name.
value[*pos]);
47 __attribute__((nonnull))
static inline bool
48 LName_Component(
LName name, uint16_t* restrict pos, uint16_t* restrict type,
49 uint16_t* restrict length) {
50 return LName_ParseVarNum_(name, pos, type, 1) && likely(*type != 0) &&
51 LName_ParseVarNum_(name, pos, length, 0) && *pos + *length <= name.
length;
68 static __rte_always_inline
LName
69 LName_SliceByte_(
LName name, uint16_t start, uint16_t end) {
70 return (
LName){.
length = end - start, .value = RTE_PTR_ADD(name.
value, start)};
73 static __rte_always_inline
LName
74 LName_Slice_(
LName name, uint16_t start, uint16_t end) {
75 uint16_t i = 0, pos = 0, type = 0, length = 0;
76 uint16_t posStart = likely(start == 0) ? 0 : name.
length;
77 uint16_t posEnd = name.
length;
78 while (likely(LName_Component(name, &pos, &type, &length))) {
83 }
else if (i == end) {
88 return LName_SliceByte_(name, posStart, posEnd);
97 LName_Slice(
LName name, uint16_t start, uint16_t end) {
98 if (unlikely(start >= end)) {
101 return LName_Slice_(name, start, end);
118 __attribute__((nonnull))
static inline int
119 LNamePrefixFilter_Find(
LName name,
int maxPrefix,
const uint16_t* prefixL,
const uint8_t* prefixV) {
121 for (
int i = 0; i < maxPrefix; ++i) {
122 if (prefixL[i] == UINT16_MAX) {
127 .
value = RTE_PTR_ADD(prefixV, offset),
128 .length = prefixL[i],
130 if (LName_IsPrefix(prefix, name) >= 0) {
156 static __rte_always_inline
LName
157 PName_ToLName(
const PName* p) {
158 static_assert(offsetof(
LName, value) == offsetof(
PName, value),
"");
159 static_assert(offsetof(
LName, length) == offsetof(
PName, length),
"");
160 return *(
const LName*)p;
164 __attribute__((nonnull))
bool
167 __attribute__((nonnull))
static __rte_noinline
LName
168 PName_Slice_Uncached_(
const PName* p, int16_t start, int16_t end) {
169 return LName_Slice_(PName_ToLName(p), (uint16_t)start, (uint16_t)end);
177 __attribute__((nonnull))
static __rte_always_inline
LName
178 PName_Slice(
const PName* p, int16_t start, int16_t end) {
179 if (unlikely(start < 0)) {
184 if (unlikely(end < 0)) {
189 if (unlikely(start >= end)) {
194 return PName_Slice_Uncached_(p, start, end);
197 return LName_SliceByte_(PName_ToLName(p), likely(start == 0) ? 0 : p->
comp_[start - 1],
205 __attribute__((nonnull))
static __rte_always_inline
LName
206 PName_GetPrefix(
const PName* p, int16_t n) {
207 return PName_Slice(p, 0, n);
210 __attribute__((nonnull))
void
217 __attribute__((nonnull))
static inline uint64_t
218 PName_ComputePrefixHash(
const PName* p, uint16_t i) {
220 if (unlikely(i == 0)) {
230 return p->
hash_[i - 1];
234 __attribute__((nonnull))
static inline uint64_t
235 PName_ComputeHash(
const PName* p) {
236 return PName_ComputePrefixHash(p, p->
nComps);
#define NDNDPDK_ASSERT(x)
Definition: common.h:60
#define CLAMP(x, lo, hi)
Definition: common.h:106
uint64_t LName_ComputeHash(LName name)
Compute hash for a name.
Definition: name.c:10
bool PName_Parse(PName *p, LName l)
Parse a name from memory buffer.
Definition: name.c:32
uint64_t LName_EmptyHash_
Definition: name.c:7
struct PName PName
Parsed name.
void PName_PrepareHashes_(PName *p)
Definition: name.c:57
struct LName LName
Name in linear buffer.
@ NameMaxLength
Definition: enum.h:10
@ PNameCachedComponents
Definition: enum.h:13
Name in linear buffer.
Definition: name.h:11
const uint8_t * value
Definition: name.h:12
uint16_t length
Definition: name.h:13
Parsed name.
Definition: name.h:139
uint16_t comp_[PNameCachedComponents]
end offset of i-th component
Definition: name.h:149
uint16_t length
TLV-LENGTH.
Definition: name.h:141
struct PName::@65 __rte_packed
const uint8_t * value
TLV-VALUE.
Definition: name.h:140
uint16_t nComps
number of components
Definition: name.h:142
bool hasHashes_
hash_ computed?
Definition: name.h:146
uint32_t a_
Definition: name.h:147
int16_t firstNonGeneric
index of first non-generic component
Definition: name.h:144
bool hasDigestComp
ends with digest component?
Definition: name.h:145
uint64_t hash_[PNameCachedComponents]
hash of i+1-component prefix
Definition: name.h:150