8b08e47e22b87693819dc4df2d807799f9ca6c29
[vpp.git] / vnet / vnet / flow / flow_report.h
1 /*
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>
26 #include <vnet/ip/udp.h>
27 #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 */
35 typedef struct {
36   ip4_header_t ip4;
37   udp_header_t udp;
38   ipfix_template_packet_t ipfix;
39 } ip4_ipfix_template_packet_t;
40
41 struct flow_report_main;
42 struct flow_report;
43
44 typedef u8 * (vnet_flow_rewrite_callback_t)(struct flow_report_main *, 
45                                             struct flow_report *,
46                                             ip4_address_t *,
47                                             ip4_address_t *,
48                                             u16);
49
50 typedef vlib_frame_t * (vnet_flow_data_callback_t) (struct flow_report_main *, 
51                                                     struct flow_report *,
52                                                     vlib_frame_t *, u32 *, 
53                                                     u32);
54 typedef struct flow_report {
55   /* ipfix rewrite, set by callback */
56   u8 * rewrite;
57   u32 sequence_number;
58   u32 domain_id;
59   f64 last_template_sent;
60   int update_rewrite;
61
62   /* Bitmap of fields to send */
63   uword * fields_to_send;
64
65   /* Opaque data */
66   void * opaque;
67
68   /* build-the-rewrite callback */
69   vnet_flow_rewrite_callback_t *rewrite_callback;
70
71   /* Send-flow-data callback */
72   vnet_flow_data_callback_t *flow_data_callback;
73 } flow_report_t;
74
75 typedef struct flow_report_main {
76   flow_report_t * reports;
77
78   /* ipfix collector ip address, port, our ip address, fib index */
79   ip4_address_t ipfix_collector;
80   u16 collector_port;
81   ip4_address_t src_address;
82   u32 fib_index;
83
84   /* Path MTU */
85   u32 path_mtu;
86
87   /* time interval in seconds after which to resend templates */
88   u32 template_interval;
89
90   /* time scale transform. Joy. */
91   u32 unix_time_0;
92   f64 vlib_time_0;
93
94   /* convenience variables */
95   vlib_main_t * vlib_main;
96   vnet_main_t * vnet_main;
97 } flow_report_main_t;
98
99 flow_report_main_t flow_report_main;
100
101 extern vlib_node_registration_t flow_report_process_node;
102
103 int vnet_flow_report_enable_disable (u32 sw_if_index, u32 table_index,
104                                        int enable_disable);
105 typedef struct {
106   vnet_flow_data_callback_t *flow_data_callback;
107   vnet_flow_rewrite_callback_t *rewrite_callback;
108   void * opaque;
109   int is_add;
110   u32 domain_id;
111 } vnet_flow_report_add_del_args_t;  
112
113 int vnet_flow_report_add_del (flow_report_main_t *frm, 
114                               vnet_flow_report_add_del_args_t *a);
115
116 #endif /* __included_vnet_flow_report_h__ */