From 2be45813c757137000878dc711dd169fc2d414af Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Sun, 13 May 2018 08:50:25 -0400 Subject: Improve ipfix template packet rewrite construction Instead of repeatedly cutting, pasting, and hacking to create a new callback, use vnet_flow_rewrite_generic_callback(). Add three arguments to the flow rewrite callback: (in) pointer to an array of report elements, (in) length of array, (out) pointer to the stream index Change existing code prototypes. Code owners encouraged to evaluate whether they can use the generic callback or not, at leisure. /* ipfix field definitions for a particular report */ typedef struct { u32 info_element; u32 size; } ipfix_report_element_t; Best generated like so: _(sourceIPv4Address, 4) \ _(destinationIPv4Address, 4) \ _(sourceTransportPort, 2) \ _(destinationTransportPort, 2) \ _(protocolIdentifier, 1) \ _(flowStartMicroseconds, 8) \ _(flowEndMicroseconds, 8) static ipfix_report_element_t simple_report_elements[] = { foreach_simple_report_ipfix_element }; ... /* Set up the ipfix report */ memset (&a, 0, sizeof (a)); a.is_add = 1 /* to enable the report */ ; a.domain_id = 1 /* pick a domain ID */ ; a.src_port = UDP_DST_PORT_ipfix /* src port for reports */ ; a.rewrite_callback = vnet_flow_rewrite_generic_callback; a.report_elements = simple_report_elements; a.n_report_elements = ARRAY_LEN (simple_report_elements); a.stream_indexp = &jim->stream_index; a.flow_data_callback = simple_flow_data_callback; /* Create the report */ rv = vnet_flow_report_add_del (frm, &a, &template_id); if (rv) return rv; ... Change-Id: If6131e6821d3a37a29269c0d58040cdf18ff05e4 Signed-off-by: Dave Barach --- src/plugins/ioam/analyse/ioam_summary_export.c | 4 +++- src/plugins/ioam/analyse/ioam_summary_export.h | 4 +++- src/plugins/ioam/udp-ping/udp_ping_export.c | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/plugins/ioam') diff --git a/src/plugins/ioam/analyse/ioam_summary_export.c b/src/plugins/ioam/analyse/ioam_summary_export.c index af2d39ab582..c118bfa3529 100644 --- a/src/plugins/ioam/analyse/ioam_summary_export.c +++ b/src/plugins/ioam/analyse/ioam_summary_export.c @@ -21,7 +21,9 @@ u8 * ioam_template_rewrite (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, - ip4_address_t * src_address, u16 collector_port) + ip4_address_t * src_address, u16 collector_port, + ipfix_report_element_t * elts, + u32 n_elts, u32 * stream_index) { ip4_header_t *ip; udp_header_t *udp; diff --git a/src/plugins/ioam/analyse/ioam_summary_export.h b/src/plugins/ioam/analyse/ioam_summary_export.h index 1397f9e8bd4..99890ad43d9 100755 --- a/src/plugins/ioam/analyse/ioam_summary_export.h +++ b/src/plugins/ioam/analyse/ioam_summary_export.h @@ -67,7 +67,9 @@ clib_error_t *ioam_flow_create (u8 del); u8 *ioam_template_rewrite (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, - ip4_address_t * src_address, u16 collector_port); + ip4_address_t * src_address, u16 collector_port, + ipfix_report_element_t * elts, + u32 n_elts, u32 * stream_index); u16 ioam_analyse_add_ipfix_record (flow_report_t * fr, ioam_analyser_data_t * record, diff --git a/src/plugins/ioam/udp-ping/udp_ping_export.c b/src/plugins/ioam/udp-ping/udp_ping_export.c index 2b3a4de11a4..73835919dd9 100644 --- a/src/plugins/ioam/udp-ping/udp_ping_export.c +++ b/src/plugins/ioam/udp-ping/udp_ping_export.c @@ -23,10 +23,13 @@ static u8 * udp_ping_template_rewrite (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, - ip4_address_t * src_address, u16 collector_port) + ip4_address_t * src_address, u16 collector_port, + ipfix_report_element_t * elts, + u32 n_elts, u32 * stream_index) { return ioam_template_rewrite (frm, fr, collector_address, - src_address, collector_port); + src_address, collector_port, elts, n_elts, + stream_index); } static vlib_frame_t * -- cgit 1.2.3-korg