blob: 30c11760c92a1c5b0ca0dd5b9f12719d9c38137f [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>
20#include <vnet/pg/pg.h>
21#include <vnet/ethernet/ethernet.h>
22#include <vnet/ethernet/packet.h>
23#include <vnet/ip/ip_packet.h>
24#include <vnet/ip/ip4_packet.h>
25#include <vnet/ip/ip6_packet.h>
Florin Corasb040f982020-10-20 14:59:43 -070026#include <vnet/udp/udp_packet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070027#include <vlib/cli.h>
28#include <vppinfra/error.h>
29#include <vppinfra/hash.h>
30#include <vppinfra/cache.h>
31
Ole Troana9855ef2018-05-02 12:45:10 +020032#include <vnet/ipfix-export/ipfix_packet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070033
Dave Barach2be45812018-05-13 08:50:25 -040034/* ipfix field definitions for a particular report */
35typedef struct
36{
37 u32 info_element;
38 u32 size;
39} ipfix_report_element_t;
40
Ed Warnickecb9cada2015-12-08 15:45:58 -070041/* Used to build the rewrite */
Swarup Nayak6bcac062017-11-26 23:11:40 +053042typedef struct
43{
Ed Warnickecb9cada2015-12-08 15:45:58 -070044 ip4_header_t ip4;
45 udp_header_t udp;
46 ipfix_template_packet_t ipfix;
47} ip4_ipfix_template_packet_t;
48
49struct flow_report_main;
50struct flow_report;
51
Swarup Nayak6bcac062017-11-26 23:11:40 +053052typedef vlib_frame_t *(vnet_flow_data_callback_t) (struct flow_report_main *,
53 struct flow_report *,
54 vlib_frame_t *, u32 *,
55 u32);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070056
Dave Barach2be45812018-05-13 08:50:25 -040057typedef u8 *(vnet_flow_rewrite_callback_t) (struct flow_report_main *,
58 struct flow_report *,
59 ip4_address_t *,
60 ip4_address_t *, u16,
61 ipfix_report_element_t * elts,
62 u32 n_elts, u32 * stream_index);
63
64u8 *vnet_flow_rewrite_generic_callback (struct flow_report_main *,
65 struct flow_report *,
66 ip4_address_t *,
67 ip4_address_t *, u16,
68 ipfix_report_element_t * elts,
69 u32 n_elts, u32 * stream_index);
70
Swarup Nayak6bcac062017-11-26 23:11:40 +053071typedef union
72{
73 void *as_ptr;
Juraj Slobodaffa652a2016-08-07 23:43:42 -070074 uword as_uword;
75} opaque_t;
76
Swarup Nayak6bcac062017-11-26 23:11:40 +053077typedef struct
78{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070079 u32 domain_id;
80 u32 sequence_number;
81 u16 src_port;
82 u16 n_reports;
83 u16 next_template_no;
84} flow_report_stream_t;
85
Swarup Nayak6bcac062017-11-26 23:11:40 +053086typedef struct flow_report
87{
Ed Warnickecb9cada2015-12-08 15:45:58 -070088 /* ipfix rewrite, set by callback */
Swarup Nayak6bcac062017-11-26 23:11:40 +053089 u8 *rewrite;
Juraj Slobodaffa652a2016-08-07 23:43:42 -070090 u16 template_id;
91 u32 stream_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -070092 f64 last_template_sent;
93 int update_rewrite;
94
95 /* Bitmap of fields to send */
Swarup Nayak6bcac062017-11-26 23:11:40 +053096 uword *fields_to_send;
Ed Warnickecb9cada2015-12-08 15:45:58 -070097
98 /* Opaque data */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070099 opaque_t opaque;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100
Dave Barach2be45812018-05-13 08:50:25 -0400101 /* build-the-template-packet rewrite callback */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102 vnet_flow_rewrite_callback_t *rewrite_callback;
Dave Barach2be45812018-05-13 08:50:25 -0400103 ipfix_report_element_t *report_elements;
104 u32 n_report_elements;
105 u32 *stream_indexp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700106
107 /* Send-flow-data callback */
108 vnet_flow_data_callback_t *flow_data_callback;
109} flow_report_t;
110
Swarup Nayak6bcac062017-11-26 23:11:40 +0530111typedef struct flow_report_main
112{
113 flow_report_t *reports;
114 flow_report_stream_t *streams;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700115
Juraj Sloboda5a49bb92016-07-07 03:23:15 -0700116 /* ipfix collector ip address, port, our ip address, fib index */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117 ip4_address_t ipfix_collector;
Juraj Sloboda5a49bb92016-07-07 03:23:15 -0700118 u16 collector_port;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700119 ip4_address_t src_address;
Juraj Sloboda86634f02016-07-01 06:12:58 -0700120 u32 fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121
Juraj Sloboda5a49bb92016-07-07 03:23:15 -0700122 /* Path MTU */
123 u32 path_mtu;
124
125 /* time interval in seconds after which to resend templates */
126 u32 template_interval;
127
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700128 /* UDP checksum calculation enable flag */
129 u8 udp_checksum;
130
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131 /* time scale transform. Joy. */
132 u32 unix_time_0;
133 f64 vlib_time_0;
134
135 /* convenience variables */
Swarup Nayak6bcac062017-11-26 23:11:40 +0530136 vlib_main_t *vlib_main;
137 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138} flow_report_main_t;
139
Juraj Sloboda837fbb12016-07-06 23:11:47 -0700140extern flow_report_main_t flow_report_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141
Damjan Marionb8abf872016-03-14 20:02:35 +0100142extern vlib_node_registration_t flow_report_process_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700143
144int vnet_flow_report_enable_disable (u32 sw_if_index, u32 table_index,
Swarup Nayak6bcac062017-11-26 23:11:40 +0530145 int enable_disable);
146typedef struct
147{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148 vnet_flow_data_callback_t *flow_data_callback;
149 vnet_flow_rewrite_callback_t *rewrite_callback;
Dave Barach2be45812018-05-13 08:50:25 -0400150 ipfix_report_element_t *report_elements;
151 u32 n_report_elements;
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700152 opaque_t opaque;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153 int is_add;
154 u32 domain_id;
Juraj Sloboda483f6682016-07-06 17:04:06 -0700155 u16 src_port;
Dave Barach2be45812018-05-13 08:50:25 -0400156 u32 *stream_indexp;
Swarup Nayak6bcac062017-11-26 23:11:40 +0530157} vnet_flow_report_add_del_args_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158
Swarup Nayak6bcac062017-11-26 23:11:40 +0530159int vnet_flow_report_add_del (flow_report_main_t * frm,
160 vnet_flow_report_add_del_args_t * a,
161 u16 * template_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162
Swarup Nayak6bcac062017-11-26 23:11:40 +0530163clib_error_t *flow_report_add_del_error_to_clib_error (int error);
Juraj Sloboda24648ad2016-09-06 04:43:52 -0700164
Juraj Sloboda837fbb12016-07-06 23:11:47 -0700165void vnet_flow_reports_reset (flow_report_main_t * frm);
166
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700167void vnet_stream_reset (flow_report_main_t * frm, u32 stream_index);
168
169int vnet_stream_change (flow_report_main_t * frm,
Swarup Nayak6bcac062017-11-26 23:11:40 +0530170 u32 old_domain_id, u16 old_src_port,
171 u32 new_domain_id, u16 new_src_port);
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700172
Ed Warnickecb9cada2015-12-08 15:45:58 -0700173#endif /* __included_vnet_flow_report_h__ */
Swarup Nayak6bcac062017-11-26 23:11:40 +0530174
175/*
176 * fd.io coding-style-patch-verification: ON
177 *
178 * Local Variables:
179 * eval: (c-set-style "gnu")
180 * End:
181 */