blob: 7f0c92d3a92813cdd25b20f1cae458fc8eb2a8d9 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef __included_vnet_flow_report_h__
16#define __included_vnet_flow_report_h__
17
18#include <vlib/vlib.h>
19#include <vnet/vnet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070020#include <vnet/ethernet/ethernet.h>
21#include <vnet/ethernet/packet.h>
22#include <vnet/ip/ip_packet.h>
23#include <vnet/ip/ip4_packet.h>
24#include <vnet/ip/ip6_packet.h>
Florin Corasb040f982020-10-20 14:59:43 -070025#include <vnet/udp/udp_packet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070026#include <vlib/cli.h>
27#include <vppinfra/error.h>
28#include <vppinfra/hash.h>
29#include <vppinfra/cache.h>
30
Ole Troana9855ef2018-05-02 12:45:10 +020031#include <vnet/ipfix-export/ipfix_packet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070032
Dave Barach2be45812018-05-13 08:50:25 -040033/* ipfix field definitions for a particular report */
34typedef struct
35{
36 u32 info_element;
37 u32 size;
38} ipfix_report_element_t;
39
Ed Warnickecb9cada2015-12-08 15:45:58 -070040/* Used to build the rewrite */
Swarup Nayak6bcac062017-11-26 23:11:40 +053041typedef struct
42{
Ed Warnickecb9cada2015-12-08 15:45:58 -070043 ip4_header_t ip4;
44 udp_header_t udp;
45 ipfix_template_packet_t ipfix;
46} ip4_ipfix_template_packet_t;
47
48struct flow_report_main;
49struct flow_report;
Paul Atkins40f9a7a2021-09-22 10:06:23 +010050struct ipfix_exporter;
Ed Warnickecb9cada2015-12-08 15:45:58 -070051
Paul Atkins40f9a7a2021-09-22 10:06:23 +010052typedef vlib_frame_t *(vnet_flow_data_callback_t) (
53 struct flow_report_main *frm, struct ipfix_exporter *exp,
54 struct flow_report *, vlib_frame_t *, u32 *, u32);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070055
Paul Atkins40f9a7a2021-09-22 10:06:23 +010056typedef u8 *(vnet_flow_rewrite_callback_t) (struct ipfix_exporter *exp,
Dave Barach2be45812018-05-13 08:50:25 -040057 struct flow_report *,
Paul Atkins40f9a7a2021-09-22 10:06:23 +010058 ip4_address_t *, ip4_address_t *,
59 u16, ipfix_report_element_t *elts,
60 u32 n_elts, u32 *stream_index);
Dave Barach2be45812018-05-13 08:50:25 -040061
Paul Atkins40f9a7a2021-09-22 10:06:23 +010062u8 *vnet_flow_rewrite_generic_callback (struct ipfix_exporter *exp,
63 struct flow_report *, ip4_address_t *,
Dave Barach2be45812018-05-13 08:50:25 -040064 ip4_address_t *, u16,
Paul Atkins40f9a7a2021-09-22 10:06:23 +010065 ipfix_report_element_t *elts,
66 u32 n_elts, u32 *stream_index);
Dave Barach2be45812018-05-13 08:50:25 -040067
Swarup Nayak6bcac062017-11-26 23:11:40 +053068typedef union
69{
70 void *as_ptr;
Juraj Slobodaffa652a2016-08-07 23:43:42 -070071 uword as_uword;
72} opaque_t;
73
Swarup Nayak6bcac062017-11-26 23:11:40 +053074typedef struct
75{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070076 u32 domain_id;
77 u32 sequence_number;
78 u16 src_port;
79 u16 n_reports;
80 u16 next_template_no;
81} flow_report_stream_t;
82
Swarup Nayak6bcac062017-11-26 23:11:40 +053083typedef struct flow_report
84{
Ed Warnickecb9cada2015-12-08 15:45:58 -070085 /* ipfix rewrite, set by callback */
Swarup Nayak6bcac062017-11-26 23:11:40 +053086 u8 *rewrite;
Juraj Slobodaffa652a2016-08-07 23:43:42 -070087 u16 template_id;
88 u32 stream_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -070089 f64 last_template_sent;
90 int update_rewrite;
91
92 /* Bitmap of fields to send */
Swarup Nayak6bcac062017-11-26 23:11:40 +053093 uword *fields_to_send;
Ed Warnickecb9cada2015-12-08 15:45:58 -070094
95 /* Opaque data */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070096 opaque_t opaque;
Ed Warnickecb9cada2015-12-08 15:45:58 -070097
Dave Barach2be45812018-05-13 08:50:25 -040098 /* build-the-template-packet rewrite callback */
Ed Warnickecb9cada2015-12-08 15:45:58 -070099 vnet_flow_rewrite_callback_t *rewrite_callback;
Dave Barach2be45812018-05-13 08:50:25 -0400100 ipfix_report_element_t *report_elements;
101 u32 n_report_elements;
102 u32 *stream_indexp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700103
104 /* Send-flow-data callback */
105 vnet_flow_data_callback_t *flow_data_callback;
106} flow_report_t;
107
Paul Atkins9ec64492021-09-21 20:49:12 +0100108/*
109 * The maximum number of ipfix exporters we can have at once
110 */
111#define IPFIX_EXPORTERS_MAX 5
112
113/*
114 * We support multiple exporters. Each one has its own configured
115 * destination, and its own set of reports and streams.
116 */
117typedef struct ipfix_exporter
Swarup Nayak6bcac062017-11-26 23:11:40 +0530118{
119 flow_report_t *reports;
120 flow_report_stream_t *streams;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121
Juraj Sloboda5a49bb92016-07-07 03:23:15 -0700122 /* ipfix collector ip address, port, our ip address, fib index */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700123 ip4_address_t ipfix_collector;
Juraj Sloboda5a49bb92016-07-07 03:23:15 -0700124 u16 collector_port;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125 ip4_address_t src_address;
Juraj Sloboda86634f02016-07-01 06:12:58 -0700126 u32 fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700127
Juraj Sloboda5a49bb92016-07-07 03:23:15 -0700128 /* Path MTU */
129 u32 path_mtu;
130
131 /* time interval in seconds after which to resend templates */
132 u32 template_interval;
133
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700134 /* UDP checksum calculation enable flag */
135 u8 udp_checksum;
Paul Atkins9ec64492021-09-21 20:49:12 +0100136} ipfix_exporter_t;
137
138typedef struct flow_report_main
139{
140 /*
141 * A pool of the exporters. Entry 0 is always there for backwards
142 * compatability reasons. Entries 1 and above have to be created by
143 * the users.
144 */
145 ipfix_exporter_t *exporters;
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700146
Ed Warnickecb9cada2015-12-08 15:45:58 -0700147 /* time scale transform. Joy. */
148 u32 unix_time_0;
149 f64 vlib_time_0;
150
151 /* convenience variables */
Swarup Nayak6bcac062017-11-26 23:11:40 +0530152 vlib_main_t *vlib_main;
153 vnet_main_t *vnet_main;
Filip Tehlar53dea272021-06-21 10:57:49 +0000154
155 u16 msg_id_base;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156} flow_report_main_t;
157
Juraj Sloboda837fbb12016-07-06 23:11:47 -0700158extern flow_report_main_t flow_report_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700159
Damjan Marionb8abf872016-03-14 20:02:35 +0100160extern vlib_node_registration_t flow_report_process_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700161
Swarup Nayak6bcac062017-11-26 23:11:40 +0530162typedef struct
163{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164 vnet_flow_data_callback_t *flow_data_callback;
165 vnet_flow_rewrite_callback_t *rewrite_callback;
Dave Barach2be45812018-05-13 08:50:25 -0400166 ipfix_report_element_t *report_elements;
167 u32 n_report_elements;
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700168 opaque_t opaque;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700169 int is_add;
170 u32 domain_id;
Juraj Sloboda483f6682016-07-06 17:04:06 -0700171 u16 src_port;
Dave Barach2be45812018-05-13 08:50:25 -0400172 u32 *stream_indexp;
Swarup Nayak6bcac062017-11-26 23:11:40 +0530173} vnet_flow_report_add_del_args_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700174
Paul Atkins40f9a7a2021-09-22 10:06:23 +0100175int vnet_flow_report_add_del (ipfix_exporter_t *exp,
176 vnet_flow_report_add_del_args_t *a,
177 u16 *template_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178
Swarup Nayak6bcac062017-11-26 23:11:40 +0530179clib_error_t *flow_report_add_del_error_to_clib_error (int error);
Juraj Sloboda24648ad2016-09-06 04:43:52 -0700180
Paul Atkins40f9a7a2021-09-22 10:06:23 +0100181void vnet_flow_reports_reset (ipfix_exporter_t *exp);
Juraj Sloboda837fbb12016-07-06 23:11:47 -0700182
Paul Atkins40f9a7a2021-09-22 10:06:23 +0100183void vnet_stream_reset (ipfix_exporter_t *exp, u32 stream_index);
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700184
Paul Atkins40f9a7a2021-09-22 10:06:23 +0100185int vnet_stream_change (ipfix_exporter_t *exp, u32 old_domain_id,
186 u16 old_src_port, u32 new_domain_id, u16 new_src_port);
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700187
Ed Warnickecb9cada2015-12-08 15:45:58 -0700188#endif /* __included_vnet_flow_report_h__ */
Swarup Nayak6bcac062017-11-26 23:11:40 +0530189
190/*
191 * fd.io coding-style-patch-verification: ON
192 *
193 * Local Variables:
194 * eval: (c-set-style "gnu")
195 * End:
196 */