Add rx interface, ip4 src+dst to the flow-per-packet records

Change-Id: I1f49cdaf5879d9638742ed1ecc699f2e9a87f0f8
Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:
Dave Barach
2016-11-30 15:23:07 -05:00
committed by Damjan Marion
parent 10389371b3
commit de7f3a7791
2 changed files with 72 additions and 15 deletions

View File

@ -143,7 +143,10 @@ flowperpkt_template_rewrite (flow_report_main_t * frm,
/* /*
* Supported Fields: * Supported Fields:
* *
* ingressInterface, TLV type 10, u32
* egressInterface, TLV type 14, u32 * egressInterface, TLV type 14, u32
* sourceIpv4Address, TLV type 8, u32
* destinationIPv4Address, TLV type 12, u32
* ipClassOfService, TLV type 5, u8 * ipClassOfService, TLV type 5, u8
* flowStartNanoseconds, TLV type 156, dateTimeNanoseconds (f64) * flowStartNanoseconds, TLV type 156, dateTimeNanoseconds (f64)
* Implementation: f64 nanoseconds since VPP started * Implementation: f64 nanoseconds since VPP started
@ -152,8 +155,8 @@ flowperpkt_template_rewrite (flow_report_main_t * frm,
* warning: wireshark doesn't understand this TLV at all * warning: wireshark doesn't understand this TLV at all
*/ */
/* Currently 4 fields */ /* Currently 7 fields */
field_count += 4; field_count += 7;
/* allocate rewrite space */ /* allocate rewrite space */
vec_validate_aligned (rewrite, vec_validate_aligned (rewrite,
@ -183,9 +186,18 @@ flowperpkt_template_rewrite (flow_report_main_t * frm,
h->domain_id = clib_host_to_net_u32 (stream->domain_id); h->domain_id = clib_host_to_net_u32 (stream->domain_id);
/* Add TLVs to the template */ /* Add TLVs to the template */
f->e_id_length = ipfix_e_id_length (0 /* enterprise */ , ingressInterface,
4);
f++;
f->e_id_length = ipfix_e_id_length (0 /* enterprise */ , egressInterface, f->e_id_length = ipfix_e_id_length (0 /* enterprise */ , egressInterface,
4); 4);
f++; f++;
f->e_id_length = ipfix_e_id_length (0 /* enterprise */ , sourceIPv4Address,
4);
f++;
f->e_id_length = ipfix_e_id_length (0 /* enterprise */ ,
destinationIPv4Address, 4);
f++;
f->e_id_length = ipfix_e_id_length (0 /* enterprise */ , ipClassOfService, f->e_id_length = ipfix_e_id_length (0 /* enterprise */ , ipClassOfService,
1); 1);
f++; f++;

View File

@ -27,7 +27,10 @@
typedef struct typedef struct
{ {
/** interface handle */ /** interface handle */
u32 sw_if_index; u32 rx_sw_if_index;
u32 tx_sw_if_index;
u32 src_address;
u32 dst_address;
/** ToS bits */ /** ToS bits */
u8 tos; u8 tos;
/** packet timestamp */ /** packet timestamp */
@ -45,8 +48,11 @@ format_flowperpkt_trace (u8 * s, va_list * args)
flowperpkt_trace_t *t = va_arg (*args, flowperpkt_trace_t *); flowperpkt_trace_t *t = va_arg (*args, flowperpkt_trace_t *);
s = format (s, s = format (s,
"FLOWPERPKT: sw_if_index %d, tos %0x2, timestamp %lld, size %d", "FLOWPERPKT: rx_sw_if_index %d, tx_sw_if_index %d, src %U dst %U tos %0x2, timestamp %lld, size %d",
t->sw_if_index, t->tos, t->timestamp, t->buffer_size); t->rx_sw_if_index, t->tx_sw_if_index,
format_ip4_address, &t->src_address,
format_ip4_address, &t->dst_address,
t->tos, t->timestamp, t->buffer_size);
return s; return s;
} }
@ -89,7 +95,8 @@ typedef enum
static inline void static inline void
add_to_flow_record (vlib_main_t * vm, add_to_flow_record (vlib_main_t * vm,
flowperpkt_main_t * fm, flowperpkt_main_t * fm,
u32 sw_if_index, u32 rx_sw_if_index, u32 tx_sw_if_index,
u32 src_address, u32 dst_address,
u8 tos, u64 timestamp, u16 length, int do_flush) u8 tos, u64 timestamp, u16 length, int do_flush)
{ {
u32 my_cpu_number = vm->cpu_index; u32 my_cpu_number = vm->cpu_index;
@ -171,6 +178,7 @@ add_to_flow_record (vlib_main_t * vm,
ip->ip_version_and_header_length = 0x45; ip->ip_version_and_header_length = 0x45;
ip->ttl = 254; ip->ttl = 254;
ip->protocol = IP_PROTOCOL_UDP; ip->protocol = IP_PROTOCOL_UDP;
ip->flags_and_fragment_offset = 0;
ip->src_address.as_u32 = frm->src_address.as_u32; ip->src_address.as_u32 = frm->src_address.as_u32;
ip->dst_address.as_u32 = frm->ipfix_collector.as_u32; ip->dst_address.as_u32 = frm->ipfix_collector.as_u32;
udp->src_port = clib_host_to_net_u16 (UDP_DST_PORT_ipfix); udp->src_port = clib_host_to_net_u16 (UDP_DST_PORT_ipfix);
@ -195,13 +203,31 @@ add_to_flow_record (vlib_main_t * vm,
{ {
/* Add data */ /* Add data */
/* Ingress interface */
{
u32 ingress_interface = clib_host_to_net_u32 (rx_sw_if_index);
clib_memcpy (b0->data + offset, &ingress_interface,
sizeof (ingress_interface));
offset += sizeof (ingress_interface);
}
/* Egress interface */ /* Egress interface */
{ {
u32 egress_interface = clib_host_to_net_u32 (sw_if_index); u32 egress_interface = clib_host_to_net_u32 (tx_sw_if_index);
clib_memcpy (b0->data + offset, &egress_interface, clib_memcpy (b0->data + offset, &egress_interface,
sizeof (egress_interface)); sizeof (egress_interface));
offset += sizeof (egress_interface); offset += sizeof (egress_interface);
} }
/* ip4 src address */
{
clib_memcpy (b0->data + offset, &src_address, sizeof (src_address));
offset += sizeof (src_address);
}
/* ip4 dst address */
{
clib_memcpy (b0->data + offset, &dst_address, sizeof (dst_address));
offset += sizeof (dst_address);
}
/* ToS */ /* ToS */
b0->data[offset++] = tos; b0->data[offset++] = tos;
@ -218,7 +244,7 @@ add_to_flow_record (vlib_main_t * vm,
b0->current_length += b0->current_length +=
/* sw_if_index + tos + timestamp + length = 15 */ /* sw_if_index + tos + timestamp + length = 15 */
sizeof (u32) + sizeof (u8) + sizeof (f64) + sizeof (u16); 4 * sizeof (u32) + sizeof (u8) + sizeof (f64) + sizeof (u16);
} }
/* Time to flush the buffer? */ /* Time to flush the buffer? */
@ -270,7 +296,10 @@ flowperpkt_flush_callback (void)
vlib_main_t *vm = vlib_get_main (); vlib_main_t *vm = vlib_get_main ();
flowperpkt_main_t *fm = &flowperpkt_main; flowperpkt_main_t *fm = &flowperpkt_main;
add_to_flow_record (vm, fm, 0 /* sw_if_index */ , add_to_flow_record (vm, fm, 0 /* rx_sw_if_index */ ,
0 /* tx_sw_if_index */ ,
0 /* src_address */ ,
0 /* dst_address */ ,
0 /* ToS */ , 0 /* ToS */ ,
0ULL /* timestamp */ , 0ULL /* timestamp */ ,
0 /* length */ , 0 /* length */ ,
@ -346,7 +375,10 @@ flowperpkt_node_fn (vlib_main_t * vm,
if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_FLOW_REPORT) == 0)) if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_FLOW_REPORT) == 0))
add_to_flow_record (vm, fm, add_to_flow_record (vm, fm,
vnet_buffer (b0)->sw_if_index[VLIB_RX],
vnet_buffer (b0)->sw_if_index[VLIB_TX], vnet_buffer (b0)->sw_if_index[VLIB_TX],
ip0->src_address.as_u32,
ip0->dst_address.as_u32,
ip0->tos, now, len0, 0 /* flush */ ); ip0->tos, now, len0, 0 /* flush */ );
ip1 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b1) + ip1 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b1) +
@ -355,7 +387,10 @@ flowperpkt_node_fn (vlib_main_t * vm,
if (PREDICT_TRUE ((b1->flags & VLIB_BUFFER_FLOW_REPORT) == 0)) if (PREDICT_TRUE ((b1->flags & VLIB_BUFFER_FLOW_REPORT) == 0))
add_to_flow_record (vm, fm, add_to_flow_record (vm, fm,
vnet_buffer (b1)->sw_if_index[VLIB_RX],
vnet_buffer (b1)->sw_if_index[VLIB_TX], vnet_buffer (b1)->sw_if_index[VLIB_TX],
ip1->src_address.as_u32,
ip1->dst_address.as_u32,
ip1->tos, now, len1, 0 /* flush */ ); ip1->tos, now, len1, 0 /* flush */ );
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
@ -364,18 +399,22 @@ flowperpkt_node_fn (vlib_main_t * vm,
{ {
flowperpkt_trace_t *t = flowperpkt_trace_t *t =
vlib_add_trace (vm, node, b0, sizeof (*t)); vlib_add_trace (vm, node, b0, sizeof (*t));
t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; t->rx_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
t->tx_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
t->src_address = ip0->src_address.as_u32;
t->dst_address = ip0->dst_address.as_u32;
t->tos = ip0->tos; t->tos = ip0->tos;
t->timestamp = now; t->timestamp = now;
t->buffer_size = len0; t->buffer_size = len0;
} }
if (b1->flags & VLIB_BUFFER_IS_TRACED) if (b1->flags & VLIB_BUFFER_IS_TRACED)
{ {
flowperpkt_trace_t *t = flowperpkt_trace_t *t =
vlib_add_trace (vm, node, b1, sizeof (*t)); vlib_add_trace (vm, node, b1, sizeof (*t));
t->rx_sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX];
t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_TX]; t->tx_sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_TX];
t->src_address = ip1->src_address.as_u32;
t->dst_address = ip1->dst_address.as_u32;
t->tos = ip1->tos; t->tos = ip1->tos;
t->timestamp = now; t->timestamp = now;
t->buffer_size = len1; t->buffer_size = len1;
@ -422,15 +461,21 @@ flowperpkt_node_fn (vlib_main_t * vm,
if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_FLOW_REPORT) == 0)) if (PREDICT_TRUE ((b0->flags & VLIB_BUFFER_FLOW_REPORT) == 0))
add_to_flow_record (vm, fm, add_to_flow_record (vm, fm,
vnet_buffer (b0)->sw_if_index[VLIB_RX],
vnet_buffer (b0)->sw_if_index[VLIB_TX], vnet_buffer (b0)->sw_if_index[VLIB_TX],
ip0->tos, now, len0, 0 /* do flush */ ); ip0->src_address.as_u32,
ip0->dst_address.as_u32,
ip0->tos, now, len0, 0 /* flush */ );
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
&& (b0->flags & VLIB_BUFFER_IS_TRACED))) && (b0->flags & VLIB_BUFFER_IS_TRACED)))
{ {
flowperpkt_trace_t *t = flowperpkt_trace_t *t =
vlib_add_trace (vm, node, b0, sizeof (*t)); vlib_add_trace (vm, node, b0, sizeof (*t));
t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; t->rx_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
t->tx_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
t->src_address = ip0->src_address.as_u32;
t->dst_address = ip0->dst_address.as_u32;
t->tos = ip0->tos; t->tos = ip0->tos;
t->timestamp = now; t->timestamp = now;
t->buffer_size = len0; t->buffer_size = len0;