1#ifndef NDNDPDK_NDNI_NAME_H
2#define NDNDPDK_NDNI_NAME_H
16__attribute__((nonnull))
static __rte_always_inline
bool
17LName_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
48LName_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;
68static __rte_always_inline
LName
69LName_SliceByte_(
LName name, uint16_t start, uint16_t end) {
70 return (
LName){.length = end - start, .value = RTE_PTR_ADD(name.
value, start)};
73static __rte_always_inline
LName
74LName_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);
97LName_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
119LNamePrefixFilter_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) {
139typedef struct __rte_packed_begin
PName {
156static __rte_always_inline
LName
157PName_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
168PName_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
178PName_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
206PName_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
218PName_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
235PName_ComputeHash(
const PName* p) {
236 return PName_ComputePrefixHash(p, p->
nComps);
struct __rte_packed_begin vlanhdr __rte_packed_end
#define NDNDPDK_ASSERT(x)
Definition common.h:60
#define CLAMP(x, lo, hi)
Definition common.h:106
uint64_t LName_EmptyHash_
Definition name.c:7
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
void PName_PrepareHashes_(PName *p)
Definition name.c:57
@ 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
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