NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Data Structures | Macros | Typedefs | Functions
tlv-decoder.h File Reference
#include "nni.h"

Go to the source code of this file.

Data Structures

struct  TlvDecoder
 TLV decoder. More...
 

Macros

#define TlvDecoder_EachTL(d, typeVar, lengthVar)
 Iterate over TLV elements. More...
 
#define TlvDecoder_ReadNniToTypeMax_(sizeofValue)
 
#define TlvDecoder_ReadNniTo4_(d, length, max, ptr)
 
#define TlvDecoder_ReadNniTo3_(d, length, ptr)    TlvDecoder_ReadNniTo4_((d), (length), UINT64_MAX, (ptr))
 
#define TlvDecoder_ReadNniToArg5_(a1, a2, a3, a4, a5, ...)   a5
 
#define TlvDecoder_ReadNniToChoose_(...)    TlvDecoder_ReadNniToArg5_(__VA_ARGS__, TlvDecoder_ReadNniTo4_, TlvDecoder_ReadNniTo3_, )
 
#define TlvDecoder_ReadNniTo(...)   (TlvDecoder_ReadNniToChoose_(__VA_ARGS__)(__VA_ARGS__))
 Read non-negative integer to a pointer of any unsigned type. More...
 

Typedefs

typedef struct TlvDecoder TlvDecoder
 TLV decoder. More...
 

Functions

void TlvDecoder_Truncate (TlvDecoder *d)
 Truncate mbuf to the remaining bytes. More...
 
void TlvDecoder_Copy_ (TlvDecoder *d, uint8_t *output, uint16_t count)
 
struct rte_mbuf * TlvDecoder_Clone (TlvDecoder *d, uint32_t count, struct rte_mempool *indirectMp)
 Clone next count octets to indirect mbufs. More...
 
void TlvDecoder_Fragment (TlvDecoder *d, uint32_t count, struct rte_mbuf *frames[], uint32_t *fragIndex, uint32_t fragCount, uint16_t fragSize, uint16_t headroom)
 Copy next count octets to fragments. More...
 
const uint8_t * TlvDecoder_Linearize_NonContiguous_ (TlvDecoder *d, uint16_t count)
 

Macro Definition Documentation

◆ TlvDecoder_EachTL

#define TlvDecoder_EachTL (   d,
  typeVar,
  lengthVar 
)
Value:
for (uint32_t lengthVar, typeVar = TlvDecoder_ReadTL((d), &lengthVar); typeVar != 0; \
typeVar = TlvDecoder_ReadTL((d), &lengthVar))

Iterate over TLV elements.

TlvDecoder_EachTL (&decoder, type, length) {
// type is the TLV-TYPE
// length is the TLV-LENGTH
TlvDecoder_Skip(&decoder, length); // must advance after TLV-VALUE
}
#define TlvDecoder_EachTL(d, typeVar, lengthVar)
Iterate over TLV elements.
Definition: tlv-decoder.h:257

◆ TlvDecoder_ReadNniTo

#define TlvDecoder_ReadNniTo (   ...)    (TlvDecoder_ReadNniToChoose_(__VA_ARGS__)(__VA_ARGS__))

Read non-negative integer to a pointer of any unsigned type.

bool ok = TlvDecoder_ReadNniTo(&decoder, length, max, &var);
bool ok = TlvDecoder_ReadNniTo(&decoder, length, &var);
// Target variable can be uint8_t, uint16_t, uint32_t, or uint64_t.
// max defaults to, and is reduced to the maximum value assignable to the target variable.
#define TlvDecoder_ReadNniTo(...)
Read non-negative integer to a pointer of any unsigned type.
Definition: tlv-decoder.h:321
Returns
whether success.
Postcondition
Decoder is advanced after the number.

◆ TlvDecoder_ReadNniTo3_

#define TlvDecoder_ReadNniTo3_ (   d,
  length,
  ptr 
)     TlvDecoder_ReadNniTo4_((d), (length), UINT64_MAX, (ptr))

◆ TlvDecoder_ReadNniTo4_

#define TlvDecoder_ReadNniTo4_ (   d,
  length,
  max,
  ptr 
)
Value:
__extension__({ \
static_assert(__builtin_constant_p(TlvDecoder_ReadNniToTypeMax_(sizeof(*(ptr)))), ""); \
uint64_t value; \
bool ok = TlvDecoder_ReadNni( \
(d), (length), RTE_MIN((max), TlvDecoder_ReadNniToTypeMax_(sizeof(*(ptr)))), &value); \
*(ptr) = value; \
ok; \
})
#define TlvDecoder_ReadNniToTypeMax_(sizeofValue)
Definition: tlv-decoder.h:289

◆ TlvDecoder_ReadNniToArg5_

#define TlvDecoder_ReadNniToArg5_ (   a1,
  a2,
  a3,
  a4,
  a5,
  ... 
)    a5

◆ TlvDecoder_ReadNniToChoose_

#define TlvDecoder_ReadNniToChoose_ (   ...)     TlvDecoder_ReadNniToArg5_(__VA_ARGS__, TlvDecoder_ReadNniTo4_, TlvDecoder_ReadNniTo3_, )

◆ TlvDecoder_ReadNniToTypeMax_

#define TlvDecoder_ReadNniToTypeMax_ (   sizeofValue)
Value:
(sizeofValue) == sizeof(uint8_t) ? UINT8_MAX \
: (sizeofValue) == sizeof(uint16_t) ? UINT16_MAX \
: (sizeofValue) == sizeof(uint32_t) ? UINT32_MAX \
: (sizeofValue) == sizeof(uint64_t) ? UINT64_MAX \
: 0

Typedef Documentation

◆ TlvDecoder

typedef struct TlvDecoder TlvDecoder

TLV decoder.

Function Documentation

◆ TlvDecoder_Clone()

struct rte_mbuf* TlvDecoder_Clone ( TlvDecoder d,
uint32_t  count,
struct rte_mempool *  indirectMp 
)

Clone next count octets to indirect mbufs.

Returns
indirect mbufs.
Return values
NULLallocation failure.
Precondition
Decoder has no less than count remaining octets.
Postcondition
Decoder is advanced by count octets.

◆ TlvDecoder_Copy_()

void TlvDecoder_Copy_ ( TlvDecoder d,
uint8_t *  output,
uint16_t  count 
)

◆ TlvDecoder_Fragment()

void TlvDecoder_Fragment ( TlvDecoder d,
uint32_t  count,
struct rte_mbuf *  frames[],
uint32_t *  fragIndex,
uint32_t  fragCount,
uint16_t  fragSize,
uint16_t  headroom 
)

Copy next count octets to fragments.

Parameters
framesvector of fragments. They should not be chained.
[in,out]fragIndexpointer to first FragIndex, updated as last FragIndex.
fragCountcorrectly calculated FragCount.
fragSizemaximum fragment payload size.
headroomheadroom for subsequent fragments.
Precondition
Each segment has at least headroom+fragSize dataroom.
First fragment frames[*fragIndex] has initialized headroom and may contain payload.
Subsequent fragments are empty.
Postcondition
First fragment is appended up to headroom+fragSize offset.

◆ TlvDecoder_Linearize_NonContiguous_()

const uint8_t* TlvDecoder_Linearize_NonContiguous_ ( TlvDecoder d,
uint16_t  count 
)

◆ TlvDecoder_Truncate()

void TlvDecoder_Truncate ( TlvDecoder d)

Truncate mbuf to the remaining bytes.

Parameters
ddecoder. It shall have a uniquely owned, possibly segmented, direct mbuf. Its remaining length shall be non-zero.
Postcondition
d cannot be further used.