FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 #include <vlib/vlib.h>
17 #include <vnet/vnet.h>
18 #include <vppinfra/error.h>
21 
22 #define foreach_ipfix_collector_error \
23 _(PROCESSED, "Number of IP-Fix packets processed") \
24 _(NO_LISTENER, "Number of IP-Fix packets with no listener")
25 
26 typedef enum
27 {
28 #define _(sym,str) IPFIX_COLLECTOR_ERROR_##sym,
30 #undef _
33 
35 #define _(sym,string) string,
37 #undef _
38 };
39 
40 typedef enum
41 {
45 
46 typedef struct
47 {
52 
54 
55 /* packet trace format function */
56 static u8 *
57 format_ipfix_collector_trace (u8 * s, va_list * args)
58 {
59  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
60  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
61  ipfix_collector_trace_t *t = va_arg (*args, ipfix_collector_trace_t *);
62 
63  s = format (s,
64  "IPFIX_COLLECTOR: set_id %u, next_node %u", t->set_id,
65  t->next_node);
66  return s;
67 }
68 
69 /**
70  * @brief Node to receive IP-Fix packets.
71  * @node ipfix-collector
72  *
73  * This function receives IP-FIX packets and forwards them to other graph nodes
74  * based on SetID field in IP-FIX.
75  *
76  * @param vm vlib_main_t corresponding to the current thread.
77  * @param node vlib_node_runtime_t data for this node.
78  * @param frame vlib_frame_t whose contents should be dispatched.
79  *
80  * @par Graph mechanics: buffer, next index usage
81  *
82  * <em>Uses:</em>
83  * - <code>vlib_buffer_get_current(p0)</code>
84  * - Parses IP-Fix packet to extract SetId which will be used to decide
85  * next node where packets should be enqueued.
86  *
87  * <em>Next Index:</em>
88  * - Dispatches the packet to other VPP graph nodes based on their registartion
89  * for the IP-Fix SetId using API ipfix_collector_reg_setid().
90  */
91 uword
95 {
96  u32 n_left_from, next_index, *from, *to_next;
97  word n_no_listener = 0;
98  word n_listener = 0;
99 
101  n_left_from = from_frame->n_vectors;
102 
103  next_index = node->cached_next_index;
104 
105  while (n_left_from > 0)
106  {
107  u32 n_left_to_next;
108 
109  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
110 
111  while (n_left_from >= 4 && n_left_to_next >= 2)
112  {
113  u32 bi0, bi1;
114  vlib_buffer_t *b0, *b1;
115  u32 next0, next1;
116  ipfix_message_header_t *ipfix0, *ipfix1;
117  ipfix_set_header_t *set0, *set1;
118  u16 set_id0, set_id1;
119  ipfix_client *client0, *client1;
120 
121  /* Prefetch next iteration. */
122  {
123  vlib_buffer_t *p2, *p3;
124 
125  p2 = vlib_get_buffer (vm, from[2]);
126  p3 = vlib_get_buffer (vm, from[3]);
127 
128  vlib_prefetch_buffer_header (p2, LOAD);
129  vlib_prefetch_buffer_header (p3, LOAD);
130 
131  CLIB_PREFETCH (p2->data,
132  (sizeof (ipfix_message_header_t) +
133  sizeof (ipfix_set_header_t)), LOAD);
134  CLIB_PREFETCH (p3->data,
135  (sizeof (ipfix_message_header_t) +
136  sizeof (ipfix_set_header_t)), LOAD);
137  }
138 
139  bi0 = from[0];
140  bi1 = from[1];
141  to_next[0] = bi0;
142  to_next[1] = bi1;
143  from += 2;
144  to_next += 2;
145  n_left_to_next -= 2;
146  n_left_from -= 2;
147 
148  b0 = vlib_get_buffer (vm, bi0);
149  b1 = vlib_get_buffer (vm, bi1);
150 
151  ipfix0 = vlib_buffer_get_current (b0);
152  ipfix1 = vlib_buffer_get_current (b1);
153 
154  set0 = (ipfix_set_header_t *) (ipfix0 + 1);
155  set1 = (ipfix_set_header_t *) (ipfix1 + 1);
156 
157  set_id0 = (u16) (clib_net_to_host_u32 (set0->set_id_length) >> 16);
158  set_id1 = (u16) (clib_net_to_host_u32 (set1->set_id_length) >> 16);
159 
160  client0 = ipfix_collector_get_client (set_id0);
161  client1 = ipfix_collector_get_client (set_id1);
162 
163  if (PREDICT_TRUE (NULL != client0))
164  {
165  next0 = client0->client_next_node;
166  n_listener++;
167  }
168  else
169  {
171  n_no_listener++;
172  }
173 
174  if (PREDICT_TRUE (NULL != client1))
175  {
176  next1 = client1->client_next_node;
177  n_listener++;
178  }
179  else
180  {
182  n_no_listener++;
183  }
184 
186  (sizeof (ipfix_message_header_t)
187  + sizeof (ipfix_set_header_t)));
189  (sizeof (ipfix_message_header_t)
190  + sizeof (ipfix_set_header_t)));
191 
192  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
193  {
195  b0, sizeof (*tr));
196  tr->next_node = (client0 ? client0->client_node : 0xFFFFFFFF);
197  tr->set_id = set_id0;
198  }
199  if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
200  {
202  b1, sizeof (*tr));
203  tr->next_node = (client1 ? client1->client_node : 0xFFFFFFFF);
204  tr->set_id = set_id1;
205  }
206 
208  to_next, n_left_to_next,
209  bi0, bi1, next0, next1);
210  }
211 
212  while (n_left_from > 0 && n_left_to_next > 0)
213  {
214  u32 bi0;
215  vlib_buffer_t *b0;
216  u32 next0;
217  ipfix_message_header_t *ipfix0;
218  ipfix_set_header_t *set0;
219  u16 set_id0;
220  ipfix_client *client0;
221 
222  bi0 = from[0];
223  to_next[0] = bi0;
224  from += 1;
225  to_next += 1;
226  n_left_from -= 1;
227  n_left_to_next -= 1;
228 
229  b0 = vlib_get_buffer (vm, bi0);
230  ipfix0 = vlib_buffer_get_current (b0);
231 
232  set0 = (ipfix_set_header_t *) (ipfix0 + 1);
233 
234  set_id0 = (u16) (clib_net_to_host_u32 (set0->set_id_length) >> 16);
235 
236  client0 = ipfix_collector_get_client (set_id0);
237 
238  if (PREDICT_TRUE (NULL != client0))
239  {
240  next0 = client0->client_next_node;
241  n_listener++;
242  }
243  else
244  {
246  n_no_listener++;
247  }
248 
250  (sizeof (ipfix_message_header_t)
251  + sizeof (ipfix_set_header_t)));
252  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
253  {
255  b0, sizeof (*tr));
256  tr->next_node = (client0 ? client0->client_node : 0xFFFFFFFF);
257  tr->set_id = set_id0;
258  }
259 
261  to_next, n_left_to_next,
262  bi0, next0);
263  }
264 
265  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
266  }
267  vlib_error_count (vm, node->node_index,
268  IPFIX_COLLECTOR_ERROR_NO_LISTENER, n_no_listener);
269  vlib_error_count (vm, node->node_index,
270  IPFIX_COLLECTOR_ERROR_PROCESSED, n_listener);
271  return from_frame->n_vectors;
272 }
273 
274 /* *INDENT-OFF* */
276  .function = ipfix_collector_node_fn,
277  .name = "ipfix-collector",
278  .vector_size = sizeof (u32),
279  .format_trace = format_ipfix_collector_trace,
281 
283  .error_strings = ipfix_collector_error_strings,
284 
285  .n_next_nodes = IPFIX_COLLECTOR_N_NEXT,
286 
287  /* edit / add dispositions here */
288  .next_nodes = {
289  [IPFIX_COLLECTOR_NEXT_DROP] = "error-drop",
290  },
291 };
292 /* *INDENT-ON* */
293 
294 /*
295  * fd.io coding-style-patch-verification: ON
296  *
297  * Local Variables:
298  * eval: (c-set-style "gnu")
299  * End:
300  */
vlib.h
ipfix_collector_get_client
static ipfix_client * ipfix_collector_get_client(u16 set_id)
Definition: ipfixcollector.h:107
vlib_prefetch_buffer_header
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:231
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
foreach_ipfix_collector_error
#define foreach_ipfix_collector_error
Definition: node.c:22
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
ipfix_set_header_t
Definition: ipfix_packet.h:115
IPFIX_COLLECTOR_N_ERROR
@ IPFIX_COLLECTOR_N_ERROR
Definition: node.c:31
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
IPFIX_COLLECTOR_NEXT_DROP
@ IPFIX_COLLECTOR_NEXT_DROP
Definition: node.c:42
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
ipfix_collector_node
vlib_node_registration_t ipfix_collector_node
(constructor) VLIB_REGISTER_NODE (ipfix_collector_node)
Definition: node.c:53
vlib_error_count
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:57
vlib_frame_t
Definition: node.h:372
ipfixcollector.h
CLIB_PREFETCH
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
ipfix_collector_next_t
ipfix_collector_next_t
Definition: node.c:40
error.h
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
format_ipfix_collector_trace
static u8 * format_ipfix_collector_trace(u8 *s, va_list *args)
Definition: node.c:57
ipfix_packet.h
ipfix_client::client_next_node
u32 client_next_node
ipfix-collector next index where packets have to be redirected.
Definition: ipfixcollector.h:59
uword
u64 uword
Definition: types.h:112
ipfix_collector_trace_t::pad
u16 pad
Definition: node.c:50
ipfix_client
IP-FIX collector internal client structure to store SetID to client node ID.
Definition: ipfixcollector.h:49
ipfix_collector_node_fn
uword ipfix_collector_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Node to receive IP-Fix packets.
Definition: node.c:92
ipfix_collector_trace_t::set_id
u16 set_id
Definition: node.c:49
ipfix_message_header_t
Definition: ipfix_packet.h:24
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
IPFIX_COLLECTOR_N_NEXT
@ IPFIX_COLLECTOR_N_NEXT
Definition: node.c:43
flowperpkt_error_t
flowperpkt_error_t
Definition: node.c:26
vlib_validate_buffer_enqueue_x1
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
format
description fragment has unexpected format
Definition: map.api:433
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
ipfix_collector_trace_t::next_node
u32 next_node
Definition: node.c:48
ipfix_collector_trace_t
Definition: node.c:46
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
u8
unsigned char u8
Definition: types.h:56
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
vlib_buffer_t::data
u8 data[]
Packet data.
Definition: buffer.h:204
ipfix_client::client_node
u32 client_node
Node index where packets have to be redirected.
Definition: ipfixcollector.h:56
word
i64 word
Definition: types.h:111
vlib_validate_buffer_enqueue_x2
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
Definition: buffer_node.h:70
vnet.h
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
vlib_get_next_frame
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:395
ipfix_set_header_t::set_id_length
u32 set_id_length
Definition: ipfix_packet.h:117
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
ipfix_collector_error_strings
static char * ipfix_collector_error_strings[]
Definition: node.c:34
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169