FD.io VPP  v21.01.1
Vector Packet Processing
buffer.h File Reference

vlib buffer structure definition and a few select access methods. More...

+ Include dependency graph for buffer.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  vlib_buffer_t
 VLIB buffer representation. More...
 
struct  vlib_buffer_pool_thread_t
 
struct  vlib_buffer_pool_t
 
struct  vlib_buffer_main_t
 

Macros

#define VLIB_BUFFER_PRE_DATA_SIZE   __PRE_DATA_SIZE
 
#define VLIB_BUFFER_DEFAULT_DATA_SIZE   (2048)
 
#define VLIB_BUFFER_MIN_CHAIN_SEG_SIZE   (128)
 
#define VLIB_BUFFER_CLONE_HEAD_SIZE   (256)
 
#define foreach_vlib_buffer_flag
 Buffer Flags. More...
 
#define LOG2_VLIB_BUFFER_FLAG_USER(n)   (32 - (n))
 
#define VLIB_BUFFER_FLAG_USER(n)   (1 << LOG2_VLIB_BUFFER_FLAG_USER(n))
 
#define VLIB_BUFFER_FLAGS_ALL   (0x0f)
 
#define VLIB_BUFFER_HDR_SIZE   (sizeof(vlib_buffer_t) - VLIB_BUFFER_PRE_DATA_SIZE)
 
#define vlib_prefetch_buffer_header(b, type)   CLIB_PREFETCH (b, 64, type)
 Prefetch buffer metadata. More...
 
#define vlib_prefetch_buffer_data(b, type)   CLIB_PREFETCH (vlib_buffer_get_current(b), CLIB_CACHE_LINE_BYTES, type)
 
#define VLIB_BUFFER_POOL_PER_THREAD_CACHE_SZ   512
 
#define VLIB_BUFFER_MAX_NUMA_NODES   32
 
#define VLIB_BUFFER_TRACE_TRAJECTORY   0
 Compile time buffer trajectory tracing option Turn this on if you run into "bad monkey" contexts, and you want to know exactly which nodes they've visited... More...
 
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
 
#define VLIB_BUFFER_SET_EXT_HDR_SIZE(x)
 

Enumerations

enum  { foreach_vlib_buffer_flag }
 
enum  { foreach_vlib_buffer_flag }
 

Functions

 STATIC_ASSERT_SIZEOF (vlib_buffer_t, 128+VLIB_BUFFER_PRE_DATA_SIZE)
 
 STATIC_ASSERT (VLIB_BUFFER_PRE_DATA_SIZE % CLIB_CACHE_LINE_BYTES==0, "VLIB_BUFFER_PRE_DATA_SIZE must be divisible by cache line size")
 
static void vlib_buffer_struct_is_sane (vlib_buffer_t *b)
 
static uword vlib_buffer_get_va (vlib_buffer_t *b)
 
static void * vlib_buffer_get_current (vlib_buffer_t *b)
 Get pointer to current data to process. More...
 
static uword vlib_buffer_get_current_va (vlib_buffer_t *b)
 
static void vlib_buffer_advance (vlib_buffer_t *b, word l)
 Advance current data pointer by the supplied (signed!) amount. More...
 
static u8 vlib_buffer_has_space (vlib_buffer_t *b, word l)
 Check if there is enough space in buffer to advance. More...
 
static void vlib_buffer_reset (vlib_buffer_t *b)
 Reset current header & length to state they were in when packet was received. More...
 
static void * vlib_get_buffer_opaque (vlib_buffer_t *b)
 Get pointer to buffer's opaque data array. More...
 
static void * vlib_get_buffer_opaque2 (vlib_buffer_t *b)
 Get pointer to buffer's opaque2 data array. More...
 
static u8vlib_buffer_get_tail (vlib_buffer_t *b)
 Get pointer to the end of buffer's data. More...
 
static void * vlib_buffer_put_uninit (vlib_buffer_t *b, u16 size)
 Append uninitialized data to buffer. More...
 
static void * vlib_buffer_push_uninit (vlib_buffer_t *b, u8 size)
 Prepend uninitialized data to buffer. More...
 
static void * vlib_buffer_make_headroom (vlib_buffer_t *b, u8 size)
 Make head room, typically for packet headers. More...
 
static u32 vlib_buffer_make_trace_handle (u32 thread, u32 pool_index)
 Construct a trace handle from thread and pool index. More...
 
static u32 vlib_buffer_get_trace_thread (vlib_buffer_t *b)
 Extract the thread id from a trace handle. More...
 
static u32 vlib_buffer_get_trace_index (vlib_buffer_t *b)
 Extract the trace (pool) index from a trace handle. More...
 
static void * vlib_buffer_pull (vlib_buffer_t *b, u8 size)
 Retrieve bytes from buffer head. More...
 
clib_error_tvlib_buffer_main_init (struct vlib_main_t *vm)
 

Detailed Description

vlib buffer structure definition and a few select access methods.

This structure and the buffer allocation mechanism should perhaps live in vnet, but it would take a lot of typing to make it so.

Definition in file buffer.h.

Macro Definition Documentation

◆ foreach_vlib_buffer_flag

foreach_vlib_buffer_flag
Value:
_( 0, IS_TRACED, 0) \
_( 1, NEXT_PRESENT, "next-present") \
_( 2, TOTAL_LENGTH_VALID, 0) \
_( 3, EXT_HDR_VALID, "ext-hdr-valid")

Buffer Flags.

Definition at line 73 of file buffer.h.

◆ LOG2_VLIB_BUFFER_FLAG_USER

#define LOG2_VLIB_BUFFER_FLAG_USER (   n)    (32 - (n))

Definition at line 97 of file buffer.h.

◆ VLIB_BUFFER_CLONE_HEAD_SIZE

#define VLIB_BUFFER_CLONE_HEAD_SIZE   (256)

Definition at line 61 of file buffer.h.

◆ VLIB_BUFFER_DEFAULT_DATA_SIZE

#define VLIB_BUFFER_DEFAULT_DATA_SIZE   (2048)

Definition at line 53 of file buffer.h.

◆ VLIB_BUFFER_FLAG_USER

#define VLIB_BUFFER_FLAG_USER (   n)    (1 << LOG2_VLIB_BUFFER_FLAG_USER(n))

Definition at line 98 of file buffer.h.

◆ VLIB_BUFFER_FLAGS_ALL

#define VLIB_BUFFER_FLAGS_ALL   (0x0f)

Definition at line 99 of file buffer.h.

◆ VLIB_BUFFER_HDR_SIZE

#define VLIB_BUFFER_HDR_SIZE   (sizeof(vlib_buffer_t) - VLIB_BUFFER_PRE_DATA_SIZE)

Definition at line 198 of file buffer.h.

◆ VLIB_BUFFER_MAX_NUMA_NODES

#define VLIB_BUFFER_MAX_NUMA_NODES   32

Definition at line 449 of file buffer.h.

◆ VLIB_BUFFER_MIN_CHAIN_SEG_SIZE

#define VLIB_BUFFER_MIN_CHAIN_SEG_SIZE   (128)

Definition at line 58 of file buffer.h.

◆ VLIB_BUFFER_POOL_PER_THREAD_CACHE_SZ

#define VLIB_BUFFER_POOL_PER_THREAD_CACHE_SZ   512

Definition at line 417 of file buffer.h.

◆ VLIB_BUFFER_PRE_DATA_SIZE

#define VLIB_BUFFER_PRE_DATA_SIZE   __PRE_DATA_SIZE

Definition at line 51 of file buffer.h.

◆ VLIB_BUFFER_SET_EXT_HDR_SIZE

#define VLIB_BUFFER_SET_EXT_HDR_SIZE (   x)
Value:
static void __clib_constructor \
vnet_buffer_set_ext_hdr_size() \
{ \
if (__vlib_buffer_external_hdr_size) \
clib_error ("buffer external header space already set"); \
__vlib_buffer_external_hdr_size = CLIB_CACHE_LINE_ROUND (x); \
}
#define CLIB_CACHE_LINE_ROUND(x)
Definition: cache.h:61

Definition at line 501 of file buffer.h.

◆ VLIB_BUFFER_TRACE_TRAJECTORY

#define VLIB_BUFFER_TRACE_TRAJECTORY   0

Compile time buffer trajectory tracing option Turn this on if you run into "bad monkey" contexts, and you want to know exactly which nodes they've visited...

See vlib/main.c...

Definition at line 488 of file buffer.h.

◆ VLIB_BUFFER_TRACE_TRAJECTORY_INIT

#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT (   b)

Definition at line 497 of file buffer.h.

◆ vlib_prefetch_buffer_data

#define vlib_prefetch_buffer_data (   b,
  type 
)    CLIB_PREFETCH (vlib_buffer_get_current(b), CLIB_CACHE_LINE_BYTES, type)

Definition at line 208 of file buffer.h.

◆ vlib_prefetch_buffer_header

#define vlib_prefetch_buffer_header (   b,
  type 
)    CLIB_PREFETCH (b, 64, type)

Prefetch buffer metadata.

The first 64 bytes of buffer contains most header information

Parameters
b- (vlib_buffer_t *) pointer to the buffer
type- LOAD, STORE. In most cases, STORE is the right answer

Definition at line 207 of file buffer.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
foreach_vlib_buffer_flag 

Definition at line 82 of file buffer.h.

◆ anonymous enum

anonymous enum
Enumerator
foreach_vlib_buffer_flag 

Definition at line 89 of file buffer.h.

Function Documentation

◆ STATIC_ASSERT()

STATIC_ASSERT ( VLIB_BUFFER_PRE_DATA_SIZE CLIB_CACHE_LINE_BYTES = =0,
"VLIB_BUFFER_PRE_DATA_SIZE must be divisible by cache line size  
)

◆ STATIC_ASSERT_SIZEOF()

STATIC_ASSERT_SIZEOF ( vlib_buffer_t  ,
128+  VLIB_BUFFER_PRE_DATA_SIZE 
)

◆ vlib_buffer_advance()

static void vlib_buffer_advance ( vlib_buffer_t b,
word  l 
)
inlinestatic

Advance current data pointer by the supplied (signed!) amount.

Parameters
b- (vlib_buffer_t *) pointer to the buffer
l- (word) signed increment

Definition at line 252 of file buffer.h.

◆ vlib_buffer_get_current()

static void* vlib_buffer_get_current ( vlib_buffer_t b)
inlinestatic

Get pointer to current data to process.

Parameters
b- (vlib_buffer_t *) pointer to the buffer
Returns
- (void *) (b->data + b->current_data)

Definition at line 233 of file buffer.h.

◆ vlib_buffer_get_current_va()

static uword vlib_buffer_get_current_va ( vlib_buffer_t b)
inlinestatic

Definition at line 241 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_get_tail()

static u8* vlib_buffer_get_tail ( vlib_buffer_t b)
inlinestatic

Get pointer to the end of buffer's data.

Parameters
bpointer to the buffer
Returns
pointer to tail of packet's data

Definition at line 314 of file buffer.h.

+ Here is the caller graph for this function:

◆ vlib_buffer_get_trace_index()

static u32 vlib_buffer_get_trace_index ( vlib_buffer_t b)
inlinestatic

Extract the trace (pool) index from a trace handle.

Parameters
trace_handlethe trace handle
Returns
the trace index

Definition at line 392 of file buffer.h.

+ Here is the caller graph for this function:

◆ vlib_buffer_get_trace_thread()

static u32 vlib_buffer_get_trace_thread ( vlib_buffer_t b)
inlinestatic

Extract the thread id from a trace handle.

Parameters
trace_handlethe trace handle
Returns
the thread id

Definition at line 380 of file buffer.h.

+ Here is the caller graph for this function:

◆ vlib_buffer_get_va()

static uword vlib_buffer_get_va ( vlib_buffer_t b)
inlinestatic

Definition at line 221 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_has_space()

static u8 vlib_buffer_has_space ( vlib_buffer_t b,
word  l 
)
inlinestatic

Check if there is enough space in buffer to advance.

Parameters
b- (vlib_buffer_t *) pointer to the buffer
l- (word) size to check
Returns
- 0 if there is less space than 'l' in buffer

Definition at line 269 of file buffer.h.

+ Here is the caller graph for this function:

◆ vlib_buffer_main_init()

clib_error_t* vlib_buffer_main_init ( struct vlib_main_t vm)

Definition at line 852 of file buffer.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_make_headroom()

static void* vlib_buffer_make_headroom ( vlib_buffer_t b,
u8  size 
)
inlinestatic

Make head room, typically for packet headers.

Parameters
bpointer to the buffer
sizenumber of head room bytes
Returns
pointer to start of buffer (current data)

Definition at line 354 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_make_trace_handle()

static u32 vlib_buffer_make_trace_handle ( u32  thread,
u32  pool_index 
)
inlinestatic

Construct a trace handle from thread and pool index.

Parameters
threadThread id
pool_indexPool index
Returns
trace handle

Definition at line 366 of file buffer.h.

+ Here is the caller graph for this function:

◆ vlib_buffer_pull()

static void* vlib_buffer_pull ( vlib_buffer_t b,
u8  size 
)
inlinestatic

Retrieve bytes from buffer head.

Parameters
bpointer to the buffer
sizenumber of bytes to pull
Returns
pointer to start of buffer (current data)

Definition at line 404 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_push_uninit()

static void* vlib_buffer_push_uninit ( vlib_buffer_t b,
u8  size 
)
inlinestatic

Prepend uninitialized data to buffer.

Parameters
bpointer to the buffer
sizenumber of uninitialized bytes
Returns
pointer to beginning of uninitialized data

Definition at line 339 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_put_uninit()

static void* vlib_buffer_put_uninit ( vlib_buffer_t b,
u16  size 
)
inlinestatic

Append uninitialized data to buffer.

Parameters
bpointer to the buffer
sizenumber of uninitialized bytes
Returns
pointer to beginning of uninitialized data

Definition at line 325 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_reset()

static void vlib_buffer_reset ( vlib_buffer_t b)
inlinestatic

Reset current header & length to state they were in when packet was received.

Parameters
b- (vlib_buffer_t *) pointer to the buffer

Definition at line 281 of file buffer.h.

+ Here is the caller graph for this function:

◆ vlib_buffer_struct_is_sane()

static void vlib_buffer_struct_is_sane ( vlib_buffer_t b)
inlinestatic

Definition at line 212 of file buffer.h.

◆ vlib_get_buffer_opaque()

static void* vlib_get_buffer_opaque ( vlib_buffer_t b)
inlinestatic

Get pointer to buffer's opaque data array.

Parameters
b- (vlib_buffer_t *) pointer to the buffer
Returns
- (void *) b->opaque

Definition at line 293 of file buffer.h.

◆ vlib_get_buffer_opaque2()

static void* vlib_get_buffer_opaque2 ( vlib_buffer_t b)
inlinestatic

Get pointer to buffer's opaque2 data array.

Parameters
b- (vlib_buffer_t *) pointer to the buffer
Returns
- (void *) b->opaque2

Definition at line 304 of file buffer.h.