Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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> |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 25 | #include <vnet/udp/udp_packet.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | #include <vlib/cli.h> |
| 27 | #include <vppinfra/error.h> |
| 28 | #include <vppinfra/hash.h> |
| 29 | #include <vppinfra/cache.h> |
| 30 | |
Ole Troan | a9855ef | 2018-05-02 12:45:10 +0200 | [diff] [blame] | 31 | #include <vnet/ipfix-export/ipfix_packet.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 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 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 40 | /* Used to build the rewrite */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 41 | typedef struct |
| 42 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 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); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 55 | |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 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 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 70 | typedef union |
| 71 | { |
| 72 | void *as_ptr; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 73 | uword as_uword; |
| 74 | } opaque_t; |
| 75 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 76 | typedef struct |
| 77 | { |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 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 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 85 | typedef struct flow_report |
| 86 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | /* ipfix rewrite, set by callback */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 88 | u8 *rewrite; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 89 | u16 template_id; |
| 90 | u32 stream_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | f64 last_template_sent; |
| 92 | int update_rewrite; |
| 93 | |
| 94 | /* Bitmap of fields to send */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 95 | uword *fields_to_send; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | |
| 97 | /* Opaque data */ |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 98 | opaque_t opaque; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 100 | /* build-the-template-packet rewrite callback */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | vnet_flow_rewrite_callback_t *rewrite_callback; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 102 | ipfix_report_element_t *report_elements; |
| 103 | u32 n_report_elements; |
| 104 | u32 *stream_indexp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | |
| 106 | /* Send-flow-data callback */ |
| 107 | vnet_flow_data_callback_t *flow_data_callback; |
| 108 | } flow_report_t; |
| 109 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 110 | typedef struct flow_report_main |
| 111 | { |
| 112 | flow_report_t *reports; |
| 113 | flow_report_stream_t *streams; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 114 | |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 115 | /* ipfix collector ip address, port, our ip address, fib index */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | ip4_address_t ipfix_collector; |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 117 | u16 collector_port; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 118 | ip4_address_t src_address; |
Juraj Sloboda | 86634f0 | 2016-07-01 06:12:58 -0700 | [diff] [blame] | 119 | u32 fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 120 | |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 121 | /* Path MTU */ |
| 122 | u32 path_mtu; |
| 123 | |
| 124 | /* time interval in seconds after which to resend templates */ |
| 125 | u32 template_interval; |
| 126 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 127 | /* UDP checksum calculation enable flag */ |
| 128 | u8 udp_checksum; |
| 129 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | /* time scale transform. Joy. */ |
| 131 | u32 unix_time_0; |
| 132 | f64 vlib_time_0; |
| 133 | |
| 134 | /* convenience variables */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 135 | vlib_main_t *vlib_main; |
| 136 | vnet_main_t *vnet_main; |
Filip Tehlar | 53dea27 | 2021-06-21 10:57:49 +0000 | [diff] [blame] | 137 | |
| 138 | u16 msg_id_base; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 139 | } flow_report_main_t; |
| 140 | |
Juraj Sloboda | 837fbb1 | 2016-07-06 23:11:47 -0700 | [diff] [blame] | 141 | extern flow_report_main_t flow_report_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | |
Damjan Marion | b8abf87 | 2016-03-14 20:02:35 +0100 | [diff] [blame] | 143 | extern vlib_node_registration_t flow_report_process_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 144 | |
| 145 | int vnet_flow_report_enable_disable (u32 sw_if_index, u32 table_index, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 146 | int enable_disable); |
| 147 | typedef struct |
| 148 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | vnet_flow_data_callback_t *flow_data_callback; |
| 150 | vnet_flow_rewrite_callback_t *rewrite_callback; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 151 | ipfix_report_element_t *report_elements; |
| 152 | u32 n_report_elements; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 153 | opaque_t opaque; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 154 | int is_add; |
| 155 | u32 domain_id; |
Juraj Sloboda | 483f668 | 2016-07-06 17:04:06 -0700 | [diff] [blame] | 156 | u16 src_port; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 157 | u32 *stream_indexp; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 158 | } vnet_flow_report_add_del_args_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 159 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 160 | int vnet_flow_report_add_del (flow_report_main_t * frm, |
| 161 | vnet_flow_report_add_del_args_t * a, |
| 162 | u16 * template_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 163 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 164 | clib_error_t *flow_report_add_del_error_to_clib_error (int error); |
Juraj Sloboda | 24648ad | 2016-09-06 04:43:52 -0700 | [diff] [blame] | 165 | |
Juraj Sloboda | 837fbb1 | 2016-07-06 23:11:47 -0700 | [diff] [blame] | 166 | void vnet_flow_reports_reset (flow_report_main_t * frm); |
| 167 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 168 | void vnet_stream_reset (flow_report_main_t * frm, u32 stream_index); |
| 169 | |
| 170 | int vnet_stream_change (flow_report_main_t * frm, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 171 | u32 old_domain_id, u16 old_src_port, |
| 172 | u32 new_domain_id, u16 new_src_port); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 173 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 174 | #endif /* __included_vnet_flow_report_h__ */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * fd.io coding-style-patch-verification: ON |
| 178 | * |
| 179 | * Local Variables: |
| 180 | * eval: (c-set-style "gnu") |
| 181 | * End: |
| 182 | */ |