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 | /* |
| 16 | * flow_report.c |
| 17 | */ |
Ole Troan | a9855ef | 2018-05-02 12:45:10 +0200 | [diff] [blame] | 18 | #include <vnet/ipfix-export/flow_report.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 19 | #include <vnet/api_errno.h> |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 20 | #include <vnet/udp/udp.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 21 | |
Juraj Sloboda | 837fbb1 | 2016-07-06 23:11:47 -0700 | [diff] [blame] | 22 | flow_report_main_t flow_report_main; |
| 23 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 24 | static_always_inline u8 |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 25 | stream_index_valid (ipfix_exporter_t *exp, u32 index) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 26 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 27 | return index < vec_len (exp->streams) && exp->streams[index].domain_id != ~0; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 30 | static_always_inline flow_report_stream_t * |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 31 | add_stream (ipfix_exporter_t *exp) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 32 | { |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 33 | u32 i; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 34 | for (i = 0; i < vec_len (exp->streams); i++) |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 35 | if (!stream_index_valid (exp, i)) |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 36 | return &exp->streams[i]; |
| 37 | u32 index = vec_len (exp->streams); |
| 38 | vec_validate (exp->streams, index); |
| 39 | return &exp->streams[index]; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 42 | static_always_inline void |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 43 | delete_stream (ipfix_exporter_t *exp, u32 index) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 44 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 45 | ASSERT (index < vec_len (exp->streams)); |
| 46 | ASSERT (exp->streams[index].domain_id != ~0); |
| 47 | exp->streams[index].domain_id = ~0; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 50 | static i32 |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 51 | find_stream (ipfix_exporter_t *exp, u32 domain_id, u16 src_port) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 52 | { |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 53 | flow_report_stream_t *stream; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 54 | u32 i; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 55 | for (i = 0; i < vec_len (exp->streams); i++) |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 56 | if (stream_index_valid (exp, i)) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 57 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 58 | stream = &exp->streams[i]; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 59 | if (domain_id == stream->domain_id) |
| 60 | { |
| 61 | if (src_port != stream->src_port) |
| 62 | return -2; |
| 63 | return i; |
| 64 | } |
| 65 | else if (src_port == stream->src_port) |
| 66 | { |
| 67 | return -2; |
| 68 | } |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 69 | } |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 70 | return -1; |
| 71 | } |
| 72 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 73 | int |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 74 | send_template_packet (flow_report_main_t *frm, ipfix_exporter_t *exp, |
| 75 | flow_report_t *fr, u32 *buffer_indexp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 76 | { |
| 77 | u32 bi0; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 78 | vlib_buffer_t *b0; |
| 79 | ip4_ipfix_template_packet_t *tp; |
| 80 | ipfix_message_header_t *h; |
| 81 | ip4_header_t *ip; |
| 82 | udp_header_t *udp; |
| 83 | vlib_main_t *vm = frm->vlib_main; |
| 84 | flow_report_stream_t *stream; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 85 | |
| 86 | ASSERT (buffer_indexp); |
| 87 | |
| 88 | if (fr->update_rewrite || fr->rewrite == 0) |
| 89 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 90 | if (exp->ipfix_collector.as_u32 == 0 || exp->src_address.as_u32 == 0) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 91 | { |
| 92 | vlib_node_set_state (frm->vlib_main, flow_report_process_node.index, |
| 93 | VLIB_NODE_STATE_DISABLED); |
| 94 | return -1; |
| 95 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | vec_free (fr->rewrite); |
| 97 | fr->update_rewrite = 1; |
| 98 | } |
| 99 | |
| 100 | if (fr->update_rewrite) |
| 101 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 102 | fr->rewrite = fr->rewrite_callback ( |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 103 | exp, fr, &exp->ipfix_collector, &exp->src_address, exp->collector_port, |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 104 | fr->report_elements, fr->n_report_elements, fr->stream_indexp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | fr->update_rewrite = 0; |
| 106 | } |
| 107 | |
| 108 | if (vlib_buffer_alloc (vm, &bi0, 1) != 1) |
| 109 | return -1; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 110 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | b0 = vlib_get_buffer (vm, bi0); |
| 112 | |
Damjan Marion | 8934a04 | 2019-02-09 23:29:26 +0100 | [diff] [blame] | 113 | ASSERT (vec_len (fr->rewrite) < vlib_buffer_get_default_data_size (vm)); |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 114 | |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 115 | clib_memcpy_fast (b0->data, fr->rewrite, vec_len (fr->rewrite)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | b0->current_data = 0; |
| 117 | b0->current_length = vec_len (fr->rewrite); |
Damjan Marion | dac0352 | 2018-02-01 15:30:13 +0100 | [diff] [blame] | 118 | b0->flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_FLOW_REPORT); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 120 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = exp->fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | |
| 122 | tp = vlib_buffer_get_current (b0); |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 123 | ip = (ip4_header_t *) & tp->ip4; |
| 124 | udp = (udp_header_t *) (ip + 1); |
| 125 | h = (ipfix_message_header_t *) (udp + 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 127 | /* FIXUP: message header export_time */ |
| 128 | h->export_time = (u32) |
| 129 | (((f64) frm->unix_time_0) + |
| 130 | (vlib_time_now (frm->vlib_main) - frm->vlib_time_0)); |
| 131 | h->export_time = clib_host_to_net_u32 (h->export_time); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 132 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 133 | stream = &exp->streams[fr->stream_index]; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 134 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | /* FIXUP: message header sequence_number. Templates do not increase it */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 136 | h->sequence_number = clib_host_to_net_u32 (stream->sequence_number); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 137 | |
| 138 | /* FIXUP: udp length */ |
| 139 | udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip)); |
| 140 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 141 | if (exp->udp_checksum) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 142 | { |
| 143 | /* RFC 7011 section 10.3.2. */ |
| 144 | udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip); |
| 145 | if (udp->checksum == 0) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 146 | udp->checksum = 0xffff; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | *buffer_indexp = bi0; |
Juraj Sloboda | 0d2a8e7 | 2016-07-07 02:59:28 -0700 | [diff] [blame] | 150 | |
| 151 | fr->last_template_sent = vlib_time_now (vm); |
| 152 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 153 | return 0; |
| 154 | } |
| 155 | |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 156 | u8 * |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 157 | vnet_flow_rewrite_generic_callback (ipfix_exporter_t *exp, flow_report_t *fr, |
| 158 | ip4_address_t *collector_address, |
| 159 | ip4_address_t *src_address, |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 160 | u16 collector_port, |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 161 | ipfix_report_element_t *report_elts, |
| 162 | u32 n_elts, u32 *stream_indexp) |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 163 | { |
| 164 | ip4_header_t *ip; |
| 165 | udp_header_t *udp; |
| 166 | ipfix_message_header_t *h; |
| 167 | ipfix_set_header_t *s; |
| 168 | ipfix_template_header_t *t; |
| 169 | ipfix_field_specifier_t *f; |
| 170 | ipfix_field_specifier_t *first_field; |
| 171 | u8 *rewrite = 0; |
| 172 | ip4_ipfix_template_packet_t *tp; |
| 173 | flow_report_stream_t *stream; |
| 174 | int i; |
| 175 | ipfix_report_element_t *ep; |
| 176 | |
| 177 | ASSERT (stream_indexp); |
| 178 | ASSERT (n_elts); |
| 179 | ASSERT (report_elts); |
| 180 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 181 | stream = &exp->streams[fr->stream_index]; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 182 | *stream_indexp = fr->stream_index; |
| 183 | |
| 184 | /* allocate rewrite space */ |
| 185 | vec_validate_aligned (rewrite, |
| 186 | sizeof (ip4_ipfix_template_packet_t) |
| 187 | + n_elts * sizeof (ipfix_field_specifier_t) - 1, |
| 188 | CLIB_CACHE_LINE_BYTES); |
| 189 | |
| 190 | /* create the packet rewrite string */ |
| 191 | tp = (ip4_ipfix_template_packet_t *) rewrite; |
| 192 | ip = (ip4_header_t *) & tp->ip4; |
| 193 | udp = (udp_header_t *) (ip + 1); |
| 194 | h = (ipfix_message_header_t *) (udp + 1); |
| 195 | s = (ipfix_set_header_t *) (h + 1); |
| 196 | t = (ipfix_template_header_t *) (s + 1); |
| 197 | first_field = f = (ipfix_field_specifier_t *) (t + 1); |
| 198 | |
| 199 | ip->ip_version_and_header_length = 0x45; |
| 200 | ip->ttl = 254; |
| 201 | ip->protocol = IP_PROTOCOL_UDP; |
| 202 | ip->src_address.as_u32 = src_address->as_u32; |
| 203 | ip->dst_address.as_u32 = collector_address->as_u32; |
| 204 | udp->src_port = clib_host_to_net_u16 (stream->src_port); |
| 205 | udp->dst_port = clib_host_to_net_u16 (collector_port); |
| 206 | udp->length = clib_host_to_net_u16 (vec_len (rewrite) - sizeof (*ip)); |
| 207 | |
| 208 | /* FIXUP LATER: message header export_time */ |
| 209 | h->domain_id = clib_host_to_net_u32 (stream->domain_id); |
| 210 | |
| 211 | ep = report_elts; |
| 212 | |
| 213 | for (i = 0; i < n_elts; i++) |
| 214 | { |
| 215 | f->e_id_length = ipfix_e_id_length (0, ep->info_element, ep->size); |
| 216 | f++; |
| 217 | ep++; |
| 218 | } |
| 219 | |
| 220 | /* Back to the template packet... */ |
| 221 | ip = (ip4_header_t *) & tp->ip4; |
| 222 | udp = (udp_header_t *) (ip + 1); |
| 223 | |
| 224 | ASSERT (f - first_field); |
| 225 | /* Field count in this template */ |
| 226 | t->id_count = ipfix_id_count (fr->template_id, f - first_field); |
| 227 | |
| 228 | /* set length in octets */ |
| 229 | s->set_id_length = |
| 230 | ipfix_set_id_length (2 /* set_id */ , (u8 *) f - (u8 *) s); |
| 231 | |
| 232 | /* message length in octets */ |
| 233 | h->version_length = version_length ((u8 *) f - (u8 *) h); |
| 234 | |
| 235 | ip->length = clib_host_to_net_u16 ((u8 *) f - (u8 *) ip); |
| 236 | ip->checksum = ip4_header_checksum (ip); |
| 237 | |
| 238 | return rewrite; |
| 239 | } |
| 240 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 241 | static uword |
| 242 | flow_report_process (vlib_main_t * vm, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 243 | vlib_node_runtime_t * rt, vlib_frame_t * f) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 244 | { |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 245 | flow_report_main_t *frm = &flow_report_main; |
| 246 | flow_report_t *fr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 247 | u32 ip4_lookup_node_index; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 248 | vlib_node_t *ip4_lookup_node; |
| 249 | vlib_frame_t *nf = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 250 | u32 template_bi; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 251 | u32 *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 252 | int send_template; |
Matthew Smith | baa1870 | 2021-04-28 11:48:39 -0500 | [diff] [blame] | 253 | f64 now, wait_time; |
| 254 | f64 def_wait_time = 5.0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 255 | int rv; |
| 256 | uword event_type; |
| 257 | uword *event_data = 0; |
| 258 | |
| 259 | /* Wait for Godot... */ |
| 260 | vlib_process_wait_for_event_or_clock (vm, 1e9); |
| 261 | event_type = vlib_process_get_events (vm, &event_data); |
| 262 | if (event_type != 1) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 263 | clib_warning ("bogus kickoff event received, %d", event_type); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 264 | vec_reset_length (event_data); |
| 265 | |
| 266 | /* Enqueue pkts to ip4-lookup */ |
| 267 | ip4_lookup_node = vlib_get_node_by_name (vm, (u8 *) "ip4-lookup"); |
| 268 | ip4_lookup_node_index = ip4_lookup_node->index; |
| 269 | |
Matthew Smith | baa1870 | 2021-04-28 11:48:39 -0500 | [diff] [blame] | 270 | wait_time = def_wait_time; |
| 271 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 272 | while (1) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 273 | { |
Matthew Smith | baa1870 | 2021-04-28 11:48:39 -0500 | [diff] [blame] | 274 | vlib_process_wait_for_event_or_clock (vm, wait_time); |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 275 | event_type = vlib_process_get_events (vm, &event_data); |
| 276 | vec_reset_length (event_data); |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 277 | ipfix_exporter_t *exp; |
| 278 | pool_foreach (exp, frm->exporters) |
Paul Atkins | 292992e | 2021-09-21 21:08:14 +0100 | [diff] [blame] | 279 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 280 | |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 281 | /* 5s delay by default, possibly reduced by template intervals */ |
| 282 | wait_time = def_wait_time; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 283 | |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 284 | vec_foreach (fr, exp->reports) |
Paul Atkins | 292992e | 2021-09-21 21:08:14 +0100 | [diff] [blame] | 285 | { |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 286 | f64 next_template; |
| 287 | now = vlib_time_now (vm); |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 288 | |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 289 | /* Need to send a template packet? */ |
| 290 | send_template = |
| 291 | now > (fr->last_template_sent + exp->template_interval); |
| 292 | send_template += fr->last_template_sent == 0; |
| 293 | template_bi = ~0; |
| 294 | rv = 0; |
| 295 | |
| 296 | if (send_template) |
| 297 | rv = send_template_packet (frm, exp, fr, &template_bi); |
| 298 | |
| 299 | if (rv < 0) |
| 300 | continue; |
| 301 | |
| 302 | /* |
| 303 | * decide if template should be sent sooner than current wait |
| 304 | * time |
| 305 | */ |
| 306 | next_template = |
| 307 | (fr->last_template_sent + exp->template_interval) - now; |
| 308 | wait_time = clib_min (wait_time, next_template); |
| 309 | |
| 310 | nf = vlib_get_frame_to_node (vm, ip4_lookup_node_index); |
| 311 | nf->n_vectors = 0; |
| 312 | to_next = vlib_frame_vector_args (nf); |
| 313 | |
| 314 | if (template_bi != ~0) |
| 315 | { |
| 316 | to_next[0] = template_bi; |
| 317 | to_next++; |
| 318 | nf->n_vectors++; |
| 319 | } |
| 320 | |
| 321 | nf = fr->flow_data_callback (frm, exp, fr, nf, to_next, |
| 322 | ip4_lookup_node_index); |
| 323 | if (nf) |
| 324 | vlib_put_frame_to_node (vm, ip4_lookup_node_index, nf); |
| 325 | } |
Paul Atkins | 292992e | 2021-09-21 21:08:14 +0100 | [diff] [blame] | 326 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 329 | return 0; /* not so much */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 332 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 333 | VLIB_REGISTER_NODE (flow_report_process_node) = { |
| 334 | .function = flow_report_process, |
| 335 | .type = VLIB_NODE_TYPE_PROCESS, |
| 336 | .name = "flow-report-process", |
| 337 | }; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 338 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 339 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 340 | int |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 341 | vnet_flow_report_add_del (ipfix_exporter_t *exp, |
| 342 | vnet_flow_report_add_del_args_t *a, u16 *template_id) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 343 | { |
| 344 | int i; |
| 345 | int found_index = ~0; |
| 346 | flow_report_t *fr; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 347 | flow_report_stream_t *stream; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 348 | u32 si; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 349 | |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 350 | si = find_stream (exp, a->domain_id, a->src_port); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 351 | if (si == -2) |
| 352 | return VNET_API_ERROR_INVALID_VALUE; |
| 353 | if (si == -1 && a->is_add == 0) |
| 354 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
| 355 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 356 | for (i = 0; i < vec_len (exp->reports); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 357 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 358 | fr = vec_elt_at_index (exp->reports, i); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 359 | if (fr->opaque.as_uword == a->opaque.as_uword |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 360 | && fr->rewrite_callback == a->rewrite_callback |
| 361 | && fr->flow_data_callback == a->flow_data_callback) |
| 362 | { |
| 363 | found_index = i; |
| 364 | if (template_id) |
| 365 | *template_id = fr->template_id; |
| 366 | break; |
| 367 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | if (a->is_add == 0) |
| 371 | { |
| 372 | if (found_index != ~0) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 373 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 374 | vec_delete (exp->reports, 1, found_index); |
| 375 | stream = &exp->streams[si]; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 376 | stream->n_reports--; |
| 377 | if (stream->n_reports == 0) |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 378 | delete_stream (exp, si); |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 379 | return 0; |
| 380 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 381 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
| 382 | } |
| 383 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 384 | if (found_index != ~0) |
| 385 | return VNET_API_ERROR_VALUE_EXIST; |
| 386 | |
| 387 | if (si == -1) |
| 388 | { |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 389 | stream = add_stream (exp); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 390 | stream->domain_id = a->domain_id; |
| 391 | stream->src_port = a->src_port; |
| 392 | stream->sequence_number = 0; |
| 393 | stream->n_reports = 0; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 394 | si = stream - exp->streams; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 395 | } |
| 396 | else |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 397 | stream = &exp->streams[si]; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 398 | |
| 399 | stream->n_reports++; |
| 400 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 401 | vec_add2 (exp->reports, fr, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 402 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 403 | fr->stream_index = si; |
| 404 | fr->template_id = 256 + stream->next_template_no; |
| 405 | stream->next_template_no = (stream->next_template_no + 1) % (65536 - 256); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 406 | fr->update_rewrite = 1; |
| 407 | fr->opaque = a->opaque; |
| 408 | fr->rewrite_callback = a->rewrite_callback; |
| 409 | fr->flow_data_callback = a->flow_data_callback; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 410 | fr->report_elements = a->report_elements; |
| 411 | fr->n_report_elements = a->n_report_elements; |
| 412 | fr->stream_indexp = a->stream_indexp; |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 413 | if (template_id) |
| 414 | *template_id = fr->template_id; |
| 415 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 419 | clib_error_t * |
| 420 | flow_report_add_del_error_to_clib_error (int error) |
Juraj Sloboda | 24648ad | 2016-09-06 04:43:52 -0700 | [diff] [blame] | 421 | { |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 422 | switch (error) |
| 423 | { |
| 424 | case 0: |
| 425 | return 0; |
| 426 | case VNET_API_ERROR_NO_SUCH_ENTRY: |
| 427 | return clib_error_return (0, "Flow report not found"); |
| 428 | case VNET_API_ERROR_VALUE_EXIST: |
| 429 | return clib_error_return (0, "Flow report already exists"); |
| 430 | case VNET_API_ERROR_INVALID_VALUE: |
| 431 | return clib_error_return (0, "Expecting either still unused values " |
| 432 | "for both domain_id and src_port " |
| 433 | "or already used values for both fields"); |
| 434 | default: |
| 435 | return clib_error_return (0, "vnet_flow_report_add_del returned %d", |
| 436 | error); |
| 437 | } |
Juraj Sloboda | 24648ad | 2016-09-06 04:43:52 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 440 | void |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 441 | vnet_flow_reports_reset (ipfix_exporter_t *exp) |
Juraj Sloboda | 618ab08 | 2016-07-06 06:11:00 -0700 | [diff] [blame] | 442 | { |
| 443 | flow_report_t *fr; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 444 | u32 i; |
| 445 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 446 | for (i = 0; i < vec_len (exp->streams); i++) |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 447 | if (stream_index_valid (exp, i)) |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 448 | exp->streams[i].sequence_number = 0; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 449 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 450 | vec_foreach (fr, exp->reports) |
Paul Atkins | 292992e | 2021-09-21 21:08:14 +0100 | [diff] [blame] | 451 | { |
| 452 | fr->update_rewrite = 1; |
| 453 | fr->last_template_sent = 0; |
| 454 | } |
Juraj Sloboda | 618ab08 | 2016-07-06 06:11:00 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 457 | void |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 458 | vnet_stream_reset (ipfix_exporter_t *exp, u32 stream_index) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 459 | { |
| 460 | flow_report_t *fr; |
| 461 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 462 | exp->streams[stream_index].sequence_number = 0; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 463 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 464 | vec_foreach (fr, exp->reports) |
| 465 | if (exp->reports->stream_index == stream_index) |
Paul Atkins | 292992e | 2021-09-21 21:08:14 +0100 | [diff] [blame] | 466 | { |
| 467 | fr->update_rewrite = 1; |
| 468 | fr->last_template_sent = 0; |
| 469 | } |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 472 | int |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 473 | vnet_stream_change (ipfix_exporter_t *exp, u32 old_domain_id, u16 old_src_port, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 474 | u32 new_domain_id, u16 new_src_port) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 475 | { |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 476 | i32 stream_index = find_stream (exp, old_domain_id, old_src_port); |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 477 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 478 | if (stream_index < 0) |
| 479 | return 1; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 480 | flow_report_stream_t *stream = &exp->streams[stream_index]; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 481 | stream->domain_id = new_domain_id; |
| 482 | stream->src_port = new_src_port; |
| 483 | if (old_domain_id != new_domain_id || old_src_port != new_src_port) |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 484 | vnet_stream_reset (exp, stream_index); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 485 | return 0; |
| 486 | } |
| 487 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 488 | static clib_error_t * |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 489 | set_ipfix_exporter_command_fn (vlib_main_t * vm, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 490 | unformat_input_t * input, |
| 491 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 492 | { |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 493 | flow_report_main_t *frm = &flow_report_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 494 | ip4_address_t collector, src; |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 495 | u16 collector_port = UDP_DST_PORT_ipfix; |
Juraj Sloboda | 86634f0 | 2016-07-01 06:12:58 -0700 | [diff] [blame] | 496 | u32 fib_id; |
| 497 | u32 fib_index = ~0; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 498 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 499 | collector.as_u32 = 0; |
| 500 | src.as_u32 = 0; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 501 | u32 path_mtu = 512; // RFC 7011 section 10.3.3. |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 502 | u32 template_interval = 20; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 503 | u8 udp_checksum = 0; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 504 | ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 505 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 506 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 507 | { |
| 508 | if (unformat (input, "collector %U", unformat_ip4_address, &collector)) |
| 509 | ; |
Elias Rudberg | 2dca180 | 2020-05-27 01:03:46 +0200 | [diff] [blame] | 510 | else if (unformat (input, "port %U", unformat_udp_port, |
| 511 | &collector_port)) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 512 | ; |
| 513 | else if (unformat (input, "src %U", unformat_ip4_address, &src)) |
| 514 | ; |
| 515 | else if (unformat (input, "fib-id %u", &fib_id)) |
| 516 | { |
| 517 | ip4_main_t *im = &ip4_main; |
| 518 | uword *p = hash_get (im->fib_index_by_table_id, fib_id); |
| 519 | if (!p) |
| 520 | return clib_error_return (0, "fib ID %d doesn't exist\n", fib_id); |
| 521 | fib_index = p[0]; |
| 522 | } |
| 523 | else if (unformat (input, "path-mtu %u", &path_mtu)) |
| 524 | ; |
| 525 | else if (unformat (input, "template-interval %u", &template_interval)) |
| 526 | ; |
| 527 | else if (unformat (input, "udp-checksum")) |
| 528 | udp_checksum = 1; |
| 529 | else |
| 530 | break; |
| 531 | } |
| 532 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 533 | if (collector.as_u32 != 0 && src.as_u32 == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 534 | return clib_error_return (0, "src address required"); |
| 535 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 536 | if (path_mtu > 1450 /* vpp does not support fragmentation */ ) |
| 537 | return clib_error_return (0, "too big path-mtu value, maximum is 1450"); |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 538 | |
| 539 | if (path_mtu < 68) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 540 | return clib_error_return (0, "too small path-mtu value, minimum is 68"); |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 541 | |
Juraj Sloboda | 618ab08 | 2016-07-06 06:11:00 -0700 | [diff] [blame] | 542 | /* Reset report streams if we are reconfiguring IP addresses */ |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 543 | if (exp->ipfix_collector.as_u32 != collector.as_u32 || |
| 544 | exp->src_address.as_u32 != src.as_u32 || |
| 545 | exp->collector_port != collector_port) |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 546 | vnet_flow_reports_reset (exp); |
Juraj Sloboda | 618ab08 | 2016-07-06 06:11:00 -0700 | [diff] [blame] | 547 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 548 | exp->ipfix_collector.as_u32 = collector.as_u32; |
| 549 | exp->collector_port = collector_port; |
| 550 | exp->src_address.as_u32 = src.as_u32; |
| 551 | exp->fib_index = fib_index; |
| 552 | exp->path_mtu = path_mtu; |
| 553 | exp->template_interval = template_interval; |
| 554 | exp->udp_checksum = udp_checksum; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 555 | |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 556 | if (collector.as_u32) |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 557 | vlib_cli_output (vm, |
| 558 | "Collector %U, src address %U, " |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 559 | "fib index %d, path MTU %u, " |
| 560 | "template resend interval %us, " |
| 561 | "udp checksum %s", |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 562 | format_ip4_address, exp->ipfix_collector, |
| 563 | format_ip4_address, exp->src_address, fib_index, path_mtu, |
| 564 | template_interval, udp_checksum ? "enabled" : "disabled"); |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 565 | else |
| 566 | vlib_cli_output (vm, "IPFIX Collector is disabled"); |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 567 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 568 | /* Turn on the flow reporting process */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 569 | vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 573 | /* *INDENT-OFF* */ |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 574 | VLIB_CLI_COMMAND (set_ipfix_exporter_command, static) = { |
| 575 | .path = "set ipfix exporter", |
| 576 | .short_help = "set ipfix exporter " |
| 577 | "collector <ip4-address> [port <port>] " |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 578 | "src <ip4-address> [fib-id <fib-id>] " |
| 579 | "[path-mtu <path-mtu>] " |
Ignas Bacius | f3a522f | 2020-02-18 12:33:09 +0200 | [diff] [blame] | 580 | "[template-interval <template-interval>] " |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 581 | "[udp-checksum]", |
| 582 | .function = set_ipfix_exporter_command_fn, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 583 | }; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 584 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 585 | |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 586 | |
| 587 | static clib_error_t * |
| 588 | ipfix_flush_command_fn (vlib_main_t * vm, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 589 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 590 | { |
| 591 | /* poke the flow reporting process */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 592 | vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0); |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 593 | return 0; |
| 594 | } |
| 595 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 596 | /* *INDENT-OFF* */ |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 597 | VLIB_CLI_COMMAND (ipfix_flush_command, static) = { |
| 598 | .path = "ipfix flush", |
| 599 | .short_help = "flush the current ipfix data [for make test]", |
| 600 | .function = ipfix_flush_command_fn, |
| 601 | }; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 602 | /* *INDENT-ON* */ |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 603 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 604 | static clib_error_t * |
| 605 | flow_report_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 606 | { |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 607 | flow_report_main_t *frm = &flow_report_main; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 608 | ipfix_exporter_t *exp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 609 | |
| 610 | frm->vlib_main = vm; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 611 | frm->vnet_main = vnet_get_main (); |
| 612 | frm->unix_time_0 = time (0); |
| 613 | frm->vlib_time_0 = vlib_time_now (frm->vlib_main); |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 614 | /* |
| 615 | * Make sure that we can always access the first exporter for |
| 616 | * backwards compatibility reasons. |
| 617 | */ |
| 618 | pool_alloc (frm->exporters, IPFIX_EXPORTERS_MAX); |
| 619 | pool_get (frm->exporters, exp); |
| 620 | /* Verify that this is at index 0 */ |
| 621 | ASSERT (frm->exporters == exp); |
| 622 | exp->fib_index = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 623 | return 0; |
| 624 | } |
| 625 | |
Dave Barach | f8d5068 | 2019-05-14 18:01:44 -0400 | [diff] [blame] | 626 | VLIB_INIT_FUNCTION (flow_report_init); |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 627 | /* |
| 628 | * fd.io coding-style-patch-verification: ON |
| 629 | * |
| 630 | * Local Variables: |
| 631 | * eval: (c-set-style "gnu") |
| 632 | * End: |
| 633 | */ |