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> |
| 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 Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 26 | #include <vnet/udp/udp.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 35 | typedef struct |
| 36 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | ip4_header_t ip4; |
| 38 | udp_header_t udp; |
| 39 | ipfix_template_packet_t ipfix; |
| 40 | } ip4_ipfix_template_packet_t; |
| 41 | |
| 42 | struct flow_report_main; |
| 43 | struct flow_report; |
| 44 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 45 | typedef u8 *(vnet_flow_rewrite_callback_t) (struct flow_report_main *, |
| 46 | struct flow_report *, |
| 47 | ip4_address_t *, |
| 48 | ip4_address_t *, u16); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 49 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 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); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 54 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 55 | typedef union |
| 56 | { |
| 57 | void *as_ptr; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 58 | uword as_uword; |
| 59 | } opaque_t; |
| 60 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 61 | typedef struct |
| 62 | { |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 63 | u32 domain_id; |
| 64 | u32 sequence_number; |
| 65 | u16 src_port; |
| 66 | u16 n_reports; |
| 67 | u16 next_template_no; |
| 68 | } flow_report_stream_t; |
| 69 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 70 | typedef struct flow_report |
| 71 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 72 | /* ipfix rewrite, set by callback */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 73 | u8 *rewrite; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 74 | u16 template_id; |
| 75 | u32 stream_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 76 | f64 last_template_sent; |
| 77 | int update_rewrite; |
| 78 | |
| 79 | /* Bitmap of fields to send */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 80 | uword *fields_to_send; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 81 | |
| 82 | /* Opaque data */ |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 83 | opaque_t opaque; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | |
| 85 | /* build-the-rewrite callback */ |
| 86 | vnet_flow_rewrite_callback_t *rewrite_callback; |
| 87 | |
| 88 | /* Send-flow-data callback */ |
| 89 | vnet_flow_data_callback_t *flow_data_callback; |
| 90 | } flow_report_t; |
| 91 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 92 | typedef struct flow_report_main |
| 93 | { |
| 94 | flow_report_t *reports; |
| 95 | flow_report_stream_t *streams; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 97 | /* ipfix collector ip address, port, our ip address, fib index */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 98 | ip4_address_t ipfix_collector; |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 99 | u16 collector_port; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 100 | ip4_address_t src_address; |
Juraj Sloboda | 86634f0 | 2016-07-01 06:12:58 -0700 | [diff] [blame] | 101 | u32 fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 103 | /* Path MTU */ |
| 104 | u32 path_mtu; |
| 105 | |
| 106 | /* time interval in seconds after which to resend templates */ |
| 107 | u32 template_interval; |
| 108 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 109 | /* UDP checksum calculation enable flag */ |
| 110 | u8 udp_checksum; |
| 111 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 112 | /* time scale transform. Joy. */ |
| 113 | u32 unix_time_0; |
| 114 | f64 vlib_time_0; |
| 115 | |
| 116 | /* convenience variables */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 117 | vlib_main_t *vlib_main; |
| 118 | vnet_main_t *vnet_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | } flow_report_main_t; |
| 120 | |
Juraj Sloboda | 837fbb1 | 2016-07-06 23:11:47 -0700 | [diff] [blame] | 121 | extern flow_report_main_t flow_report_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | |
Damjan Marion | b8abf87 | 2016-03-14 20:02:35 +0100 | [diff] [blame] | 123 | extern vlib_node_registration_t flow_report_process_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | |
| 125 | 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] | 126 | int enable_disable); |
| 127 | typedef struct |
| 128 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 129 | vnet_flow_data_callback_t *flow_data_callback; |
| 130 | vnet_flow_rewrite_callback_t *rewrite_callback; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 131 | opaque_t opaque; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 132 | int is_add; |
| 133 | u32 domain_id; |
Juraj Sloboda | 483f668 | 2016-07-06 17:04:06 -0700 | [diff] [blame] | 134 | u16 src_port; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 135 | } vnet_flow_report_add_del_args_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 136 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 137 | int vnet_flow_report_add_del (flow_report_main_t * frm, |
| 138 | vnet_flow_report_add_del_args_t * a, |
| 139 | u16 * template_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 140 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 141 | 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] | 142 | |
Juraj Sloboda | 837fbb1 | 2016-07-06 23:11:47 -0700 | [diff] [blame] | 143 | void vnet_flow_reports_reset (flow_report_main_t * frm); |
| 144 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 145 | void vnet_stream_reset (flow_report_main_t * frm, u32 stream_index); |
| 146 | |
| 147 | int vnet_stream_change (flow_report_main_t * frm, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 148 | u32 old_domain_id, u16 old_src_port, |
| 149 | u32 new_domain_id, u16 new_src_port); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 150 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | #endif /* __included_vnet_flow_report_h__ */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * fd.io coding-style-patch-verification: ON |
| 155 | * |
| 156 | * Local Variables: |
| 157 | * eval: (c-set-style "gnu") |
| 158 | * End: |
| 159 | */ |