blob: e8ed381853444ba72360edab2e91ffff21497b8f [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>
Dave Barach68b0fb02017-02-28 15:15:56 -050026#include <vnet/udp/udp.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
32#include <vnet/flow/ipfix_packet.h>
33
34/* Used to build the rewrite */
35typedef struct {
36 ip4_header_t ip4;
37 udp_header_t udp;
38 ipfix_template_packet_t ipfix;
39} ip4_ipfix_template_packet_t;
40
41struct flow_report_main;
42struct flow_report;
43
44typedef u8 * (vnet_flow_rewrite_callback_t)(struct flow_report_main *,
45 struct flow_report *,
46 ip4_address_t *,
Juraj Sloboda5a49bb92016-07-07 03:23:15 -070047 ip4_address_t *,
48 u16);
Ed Warnickecb9cada2015-12-08 15:45:58 -070049
50typedef vlib_frame_t * (vnet_flow_data_callback_t) (struct flow_report_main *,
51 struct flow_report *,
52 vlib_frame_t *, u32 *,
53 u32);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070054
55typedef union {
56 void * as_ptr;
57 uword as_uword;
58} opaque_t;
59
60typedef struct {
61 u32 domain_id;
62 u32 sequence_number;
63 u16 src_port;
64 u16 n_reports;
65 u16 next_template_no;
66} flow_report_stream_t;
67
Ed Warnickecb9cada2015-12-08 15:45:58 -070068typedef struct flow_report {
69 /* ipfix rewrite, set by callback */
70 u8 * rewrite;
Juraj Slobodaffa652a2016-08-07 23:43:42 -070071 u16 template_id;
72 u32 stream_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -070073 f64 last_template_sent;
74 int update_rewrite;
75
76 /* Bitmap of fields to send */
77 uword * fields_to_send;
78
79 /* Opaque data */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070080 opaque_t opaque;
Ed Warnickecb9cada2015-12-08 15:45:58 -070081
82 /* build-the-rewrite callback */
83 vnet_flow_rewrite_callback_t *rewrite_callback;
84
85 /* Send-flow-data callback */
86 vnet_flow_data_callback_t *flow_data_callback;
87} flow_report_t;
88
89typedef struct flow_report_main {
90 flow_report_t * reports;
Juraj Slobodaffa652a2016-08-07 23:43:42 -070091 flow_report_stream_t * streams;
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
Juraj Sloboda5a49bb92016-07-07 03:23:15 -070093 /* ipfix collector ip address, port, our ip address, fib index */
Ed Warnickecb9cada2015-12-08 15:45:58 -070094 ip4_address_t ipfix_collector;
Juraj Sloboda5a49bb92016-07-07 03:23:15 -070095 u16 collector_port;
Ed Warnickecb9cada2015-12-08 15:45:58 -070096 ip4_address_t src_address;
Juraj Sloboda86634f02016-07-01 06:12:58 -070097 u32 fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -070098
Juraj Sloboda5a49bb92016-07-07 03:23:15 -070099 /* Path MTU */
100 u32 path_mtu;
101
102 /* time interval in seconds after which to resend templates */
103 u32 template_interval;
104
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700105 /* UDP checksum calculation enable flag */
106 u8 udp_checksum;
107
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108 /* time scale transform. Joy. */
109 u32 unix_time_0;
110 f64 vlib_time_0;
111
112 /* convenience variables */
113 vlib_main_t * vlib_main;
114 vnet_main_t * vnet_main;
115} flow_report_main_t;
116
Juraj Sloboda837fbb12016-07-06 23:11:47 -0700117extern flow_report_main_t flow_report_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700118
Damjan Marionb8abf872016-03-14 20:02:35 +0100119extern vlib_node_registration_t flow_report_process_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700120
121int vnet_flow_report_enable_disable (u32 sw_if_index, u32 table_index,
122 int enable_disable);
123typedef struct {
124 vnet_flow_data_callback_t *flow_data_callback;
125 vnet_flow_rewrite_callback_t *rewrite_callback;
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700126 opaque_t opaque;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700127 int is_add;
128 u32 domain_id;
Juraj Sloboda483f6682016-07-06 17:04:06 -0700129 u16 src_port;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130} vnet_flow_report_add_del_args_t;
131
132int vnet_flow_report_add_del (flow_report_main_t *frm,
133 vnet_flow_report_add_del_args_t *a);
134
Juraj Sloboda24648ad2016-09-06 04:43:52 -0700135clib_error_t * flow_report_add_del_error_to_clib_error (int error);
136
Juraj Sloboda837fbb12016-07-06 23:11:47 -0700137void vnet_flow_reports_reset (flow_report_main_t * frm);
138
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700139void vnet_stream_reset (flow_report_main_t * frm, u32 stream_index);
140
141int vnet_stream_change (flow_report_main_t * frm,
142 u32 old_domain_id, u16 old_src_port,
143 u32 new_domain_id, u16 new_src_port);
144
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145#endif /* __included_vnet_flow_report_h__ */