ipfix-export: refactor fields in flow_report_main
[vpp.git] / src / vnet / ipfix-export / 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/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>
25 #include <vnet/udp/udp_packet.h>
26 #include <vlib/cli.h>
27 #include <vppinfra/error.h>
28 #include <vppinfra/hash.h>
29 #include <vppinfra/cache.h>
30
31 #include <vnet/ipfix-export/ipfix_packet.h>
32
33 /* ipfix field definitions for a particular report */
34 typedef struct
35 {
36   u32 info_element;
37   u32 size;
38 } ipfix_report_element_t;
39
40 /* Used to build the rewrite */
41 typedef struct
42 {
43   ip4_header_t ip4;
44   udp_header_t udp;
45   ipfix_template_packet_t ipfix;
46 } ip4_ipfix_template_packet_t;
47
48 struct flow_report_main;
49 struct flow_report;
50
51 typedef vlib_frame_t *(vnet_flow_data_callback_t) (struct flow_report_main *,
52                                                    struct flow_report *,
53                                                    vlib_frame_t *, u32 *,
54                                                    u32);
55
56 typedef u8 *(vnet_flow_rewrite_callback_t) (struct flow_report_main *,
57                                             struct flow_report *,
58                                             ip4_address_t *,
59                                             ip4_address_t *, u16,
60                                             ipfix_report_element_t * elts,
61                                             u32 n_elts, u32 * stream_index);
62
63 u8 *vnet_flow_rewrite_generic_callback (struct flow_report_main *,
64                                         struct flow_report *,
65                                         ip4_address_t *,
66                                         ip4_address_t *, u16,
67                                         ipfix_report_element_t * elts,
68                                         u32 n_elts, u32 * stream_index);
69
70 typedef union
71 {
72   void *as_ptr;
73   uword as_uword;
74 } opaque_t;
75
76 typedef struct
77 {
78   u32 domain_id;
79   u32 sequence_number;
80   u16 src_port;
81   u16 n_reports;
82   u16 next_template_no;
83 } flow_report_stream_t;
84
85 typedef struct flow_report
86 {
87   /* ipfix rewrite, set by callback */
88   u8 *rewrite;
89   u16 template_id;
90   u32 stream_index;
91   f64 last_template_sent;
92   int update_rewrite;
93
94   /* Bitmap of fields to send */
95   uword *fields_to_send;
96
97   /* Opaque data */
98   opaque_t opaque;
99
100   /* build-the-template-packet rewrite callback */
101   vnet_flow_rewrite_callback_t *rewrite_callback;
102   ipfix_report_element_t *report_elements;
103   u32 n_report_elements;
104   u32 *stream_indexp;
105
106   /* Send-flow-data callback */
107   vnet_flow_data_callback_t *flow_data_callback;
108 } flow_report_t;
109
110 /*
111  * The maximum number of ipfix exporters we can have at once
112  */
113 #define IPFIX_EXPORTERS_MAX 5
114
115 /*
116  * We support multiple exporters. Each one has its own configured
117  * destination, and its own set of reports and streams.
118  */
119 typedef struct ipfix_exporter
120 {
121   flow_report_t *reports;
122   flow_report_stream_t *streams;
123
124   /* ipfix collector ip address, port, our ip address, fib index */
125   ip4_address_t ipfix_collector;
126   u16 collector_port;
127   ip4_address_t src_address;
128   u32 fib_index;
129
130   /* Path MTU */
131   u32 path_mtu;
132
133   /* time interval in seconds after which to resend templates */
134   u32 template_interval;
135
136   /* UDP checksum calculation enable flag */
137   u8 udp_checksum;
138 } ipfix_exporter_t;
139
140 typedef struct flow_report_main
141 {
142   /*
143    * A pool of the exporters. Entry 0 is always there for backwards
144    * compatability reasons. Entries 1 and above have to be created by
145    * the users.
146    */
147   ipfix_exporter_t *exporters;
148
149   /* time scale transform. Joy. */
150   u32 unix_time_0;
151   f64 vlib_time_0;
152
153   /* convenience variables */
154   vlib_main_t *vlib_main;
155   vnet_main_t *vnet_main;
156
157   u16 msg_id_base;
158 } flow_report_main_t;
159
160 extern flow_report_main_t flow_report_main;
161
162 extern vlib_node_registration_t flow_report_process_node;
163
164 typedef struct
165 {
166   vnet_flow_data_callback_t *flow_data_callback;
167   vnet_flow_rewrite_callback_t *rewrite_callback;
168   ipfix_report_element_t *report_elements;
169   u32 n_report_elements;
170   opaque_t opaque;
171   int is_add;
172   u32 domain_id;
173   u16 src_port;
174   u32 *stream_indexp;
175 } vnet_flow_report_add_del_args_t;
176
177 int vnet_flow_report_add_del (flow_report_main_t * frm,
178                               vnet_flow_report_add_del_args_t * a,
179                               u16 * template_id);
180
181 clib_error_t *flow_report_add_del_error_to_clib_error (int error);
182
183 void vnet_flow_reports_reset (flow_report_main_t * frm);
184
185 void vnet_stream_reset (flow_report_main_t * frm, u32 stream_index);
186
187 int vnet_stream_change (flow_report_main_t * frm,
188                         u32 old_domain_id, u16 old_src_port,
189                         u32 new_domain_id, u16 new_src_port);
190
191 #endif /* __included_vnet_flow_report_h__ */
192
193 /*
194  * fd.io coding-style-patch-verification: ON
195  *
196  * Local Variables:
197  * eval: (c-set-style "gnu")
198  * End:
199  */