能夠經過開啓宏VLIB_BUFFER_TRACE_TRAJECTORY,在mbuf裏記錄mbuf通過的node個數以及所通過的node的index:node
if (VLIB_BUFFER_TRACE_TRAJECTORY && frame)ide
{函數
int i;spa
int log_index;orm
u32 * from;ip
from = vlib_frame_vector_args (frame);get
for (i = 0; i < frame->n_vectors; i++)it
{io
vlib_buffer_t *b = vlib_get_buffer (vm, from[i]);function
ASSERT (b->pre_data[0] < 32);
log_index = b->pre_data[0]++ + 1;
b->pre_data[log_index] = node->node_index;
}
n = node->function (vm, node, frame);
}
用如下函數打印記錄的node信息
void vlib_dump_context_trace (vlib_main_t*vm, u32 bi)
{
vlib_node_main_t * vnm = &vm->node_main;
vlib_buffer_t * b;
u8 i, n;
if (VLIB_BUFFER_TRACE_TRAJECTORY)
{
b = vlib_get_buffer (vm, bi);
n = b->pre_data[0];
fformat(stderr, "Context trace for bi %d b 0x%llx, visited%d\n",
bi, b, n);
if (n == 0 || n > 20)
{
fformat(stderr, "n is unreasonable\n");
return;
}
for (i = 0; i < n; i++)
{
u32 node_index;
node_index = b->pre_data[i+1];
if (node_index > vec_len (vnm->nodes))
{
fformat(stderr, "Skip bogusnode index %d\n", node_index);
continue;
}
fformat(stderr, "%v (%d)\n",vnm->nodes[node_index]->name,
node_index);
}
}
else
{
fformat(stderr,
"in vlib/buffers.h,#define VLIB_BUFFER_TRACE_TRAJECTORY 1\n");
}
}