VPP includes a high-performance IPFIX record exporter. This note explains how to use the internal APIs to export IPFIX data, and how to configure and send the required IPFIX templates.
As you'll see, a bit of typing is required.
First: create an ipfix "report"
Include the flow report header file, fill out a vnet_flow_report_add_del_args_t structure, and call vnet_flow_report_add_del.
typedef struct
{
typedef struct
{
int is_add;
#define foreach_simple_report_ipfix_element \
_(sourceIPv4Address, 4) \
_(destinationIPv4Address, 4) \
_(sourceTransportPort, 2) \
_(destinationTransportPort, 2) \
_(protocolIdentifier, 1) \
_(flowStartMicroseconds, 8) \
_(flowEndMicroseconds, 8)
#define _(a,b) {a,b},
foreach_simple_report_ipfix_element
#undef _
};
typedef struct
{
u32 *next_record_offset_by_thread;
} my_logging_main_t;
extern my_logging_main_t my_logging_main;
...
my_logging_main_t *mlm = &my_logging_main;
...
...
memset (&
a, 0,
sizeof (
a));
a.src_port = UDP_DST_PORT_ipfix ;
a.report_elements = simple_report_elements;
a.n_report_elements =
ARRAY_LEN (simple_report_elements);
a.stream_indexp = &mlm->stream_index;
a.flow_data_callback = my_flow_data_callback;
oops...
mlm->template_id = template_id;
Several things are worth describing in more detail.
vnet_flow_rewrite_generic_callback programming
This generic callback helps build ipfix template packets. When registering an ipfix report, pass an (array, count) of ipfix elements as shown above.
my_flow_data_callback
The ipfix flow export infrastructure calls this callback to flush the current ipfix packet; to make sure that ipfix data is not retained for an unreasonably long period of time.
We typically code it as shown below, to call an application-specific function with (uninteresting arguments), and "do_flush = 1":
{
my_buffer_flow_record (0, ... , 0, 1 );
}
my_flow_data_header
This function creates the packet header for an ipfix data packet
static inline void
{
my_logging_main_t *mlm = &my_logging_main;
stream = &frm->
streams[mlm->stream_index];
sizeof (*s);
b0->
flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_FLOW_REPORT);
ip->ip_version_and_header_length = 0x45;
ip->protocol = IP_PROTOCOL_UDP;
ip->flags_and_fragment_offset = 0;
h->export_time = clib_host_to_net_u32 ((
u32)
h->domain_id = clib_host_to_net_u32 (stream->
domain_id);
}
fixup and transmit a flow record
static inline void
{
(sizeof (*
ip) +
sizeof (*udp) +
(sizeof (*
ip) +
sizeof (*udp)));
{
}
}
my_buffer_flow_record
This is the key routine which paints individual flow records into an ipfix packet under construction. It's pretty straightforward (albeit stateful) vpp data-plane code. The code shown below is thread-safe by construction.
static inline void
my_buffer_flow_record_internal (my_flow_record_t * rp, int do_flush,
{
my_logging_main_t *mlm = &jvp_ipfix_main;
{
if (do_flush)
return;
{
return;
}
}
else
{
}
{
to_next[0] = bi0;
}
my_flow_report_header (frm, b0, &
offset);
{
}
{
return;
send_ipfix_pkt (frm,
f, b0, mlm->template_ids[0]);
}
}
static void
my_buffer_flow_record (my_flow_record_t * rp, int do_flush)
{
my_buffer_flow_record_internal (rp, do_flush,
thread_index);
}