Use thread local storage for thread index
[vpp.git] / src / plugins / ioam / export-common / ioam_export.h
1 /*
2  * Copyright (c) 2016 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_ioam_export_h__
16 #define __included_ioam_export_h__
17
18 #include <vnet/vnet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/ip/ip_packet.h>
21 #include <vnet/ip/ip4_packet.h>
22 #include <vnet/ip/ip6_packet.h>
23 #include <vnet/ip/ip6_hop_by_hop.h>
24 #include <vnet/udp/udp.h>
25 #include <vnet/flow/ipfix_packet.h>
26
27 #include <vppinfra/pool.h>
28 #include <vppinfra/hash.h>
29 #include <vppinfra/error.h>
30 #include <vppinfra/elog.h>
31
32 #include <vlib/threads.h>
33
34 typedef struct ioam_export_buffer
35 {
36   /* Allocated buffer */
37   u32 buffer_index;
38   u64 touched_at;
39   u8 records_in_this_buffer;
40 } ioam_export_buffer_t;
41
42
43 typedef struct
44 {
45   /* API message ID base */
46   u16 msg_id_base;
47   u16 set_id;
48
49   /* TODO: to support multiple collectors all this has to be grouped and create a vector here */
50   u8 *record_header;
51   u32 sequence_number;
52   u32 domain_id;
53
54   /* ipfix collector, our ip address */
55   ip4_address_t ipfix_collector;
56   ip4_address_t src_address;
57
58   /* Pool of ioam_export_buffer_t */
59   ioam_export_buffer_t *buffer_pool;
60   /* Vector of per thread ioam_export_buffer_t to buffer pool index */
61   u32 *buffer_per_thread;
62   /* Lock per thread to swap buffers between worker and timer process */
63   volatile u32 **lockp;
64
65   /* time scale transform */
66   u32 unix_time_0;
67   f64 vlib_time_0;
68
69   /* convenience */
70   vlib_main_t *vlib_main;
71   vnet_main_t *vnet_main;
72   ethernet_main_t *ethernet_main;
73   u32 next_node_index;
74
75   uword my_hbh_slot;
76   u32 export_process_node_index;
77 } ioam_export_main_t;
78
79
80 #define DEFAULT_EXPORT_SIZE (3 * CLIB_CACHE_LINE_BYTES)
81 /*
82  *  Number of records in a buffer
83  * ~(MTU (1500) - [ip hdr(40) + UDP(8) + ipfix (24)]) / DEFAULT_EXPORT_SIZE
84  */
85 #define DEFAULT_EXPORT_RECORDS 7
86
87 inline static void
88 ioam_export_set_next_node (ioam_export_main_t * em, u8 * next_node_name)
89 {
90   vlib_node_t *next_node;
91
92   next_node = vlib_get_node_by_name (em->vlib_main, next_node_name);
93   em->next_node_index = next_node->index;
94 }
95
96 inline static void
97 ioam_export_reset_next_node (ioam_export_main_t * em)
98 {
99   vlib_node_t *next_node;
100
101   next_node = vlib_get_node_by_name (em->vlib_main, (u8 *) "ip4-lookup");
102   em->next_node_index = next_node->index;
103 }
104
105 always_inline ioam_export_buffer_t *
106 ioam_export_get_my_buffer (ioam_export_main_t * em, u32 thread_id)
107 {
108
109   if (vec_len (em->buffer_per_thread) > thread_id)
110     return (pool_elt_at_index
111             (em->buffer_pool, em->buffer_per_thread[thread_id]));
112   return (0);
113 }
114
115 inline static int
116 ioam_export_buffer_add_header (ioam_export_main_t * em, vlib_buffer_t * b0)
117 {
118   clib_memcpy (b0->data, em->record_header, vec_len (em->record_header));
119   b0->current_data = 0;
120   b0->current_length = vec_len (em->record_header);
121   b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
122   return (1);
123 }
124
125 inline static int
126 ioam_export_init_buffer (ioam_export_main_t * em, vlib_main_t * vm,
127                          ioam_export_buffer_t * eb)
128 {
129   vlib_buffer_t *b = 0;
130
131   if (!eb)
132     return (-1);
133   /* TODO: Perhaps buffer init from template here */
134   if (vlib_buffer_alloc (vm, &(eb->buffer_index), 1) != 1)
135     return (-2);
136   eb->records_in_this_buffer = 0;
137   eb->touched_at = vlib_time_now (vm);
138   b = vlib_get_buffer (vm, eb->buffer_index);
139   (void) ioam_export_buffer_add_header (em, b);
140   vnet_buffer (b)->sw_if_index[VLIB_RX] = 0;
141   vnet_buffer (b)->sw_if_index[VLIB_TX] = ~0;
142   return (1);
143 }
144
145 inline static void
146 ioam_export_thread_buffer_free (ioam_export_main_t * em)
147 {
148   vlib_main_t *vm = em->vlib_main;
149   ioam_export_buffer_t *eb = 0;
150   int i;
151   for (i = 0; i < vec_len (em->buffer_per_thread); i++)
152     {
153       eb = pool_elt_at_index (em->buffer_pool, em->buffer_per_thread[i]);
154       if (eb)
155         vlib_buffer_free (vm, &(eb->buffer_index), 1);
156     }
157   for (i = 0; i < vec_len (em->lockp); i++)
158     clib_mem_free ((void *) em->lockp[i]);
159   vec_free (em->buffer_per_thread);
160   pool_free (em->buffer_pool);
161   vec_free (em->lockp);
162   em->buffer_per_thread = 0;
163   em->buffer_pool = 0;
164   em->lockp = 0;
165 }
166
167 inline static int
168 ioam_export_thread_buffer_init (ioam_export_main_t * em, vlib_main_t * vm)
169 {
170   int no_of_threads = vec_len (vlib_worker_threads);
171   int i;
172   ioam_export_buffer_t *eb = 0;
173
174   pool_alloc_aligned (em->buffer_pool,
175                       no_of_threads - 1, CLIB_CACHE_LINE_BYTES);
176   vec_validate_aligned (em->buffer_per_thread,
177                         no_of_threads - 1, CLIB_CACHE_LINE_BYTES);
178   vec_validate_aligned (em->lockp, no_of_threads - 1, CLIB_CACHE_LINE_BYTES);
179
180   if (!em->buffer_per_thread || !em->buffer_pool || !em->lockp)
181     {
182       return (-1);
183     }
184   for (i = 0; i < no_of_threads; i++)
185     {
186       eb = 0;
187       pool_get_aligned (em->buffer_pool, eb, CLIB_CACHE_LINE_BYTES);
188       memset (eb, 0, sizeof (*eb));
189       em->buffer_per_thread[i] = eb - em->buffer_pool;
190       if (ioam_export_init_buffer (em, vm, eb) != 1)
191         {
192           ioam_export_thread_buffer_free (em);
193           return (-2);
194         }
195       em->lockp[i] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
196                                              CLIB_CACHE_LINE_BYTES);
197       memset ((void *) em->lockp[i], 0, CLIB_CACHE_LINE_BYTES);
198     }
199   return (1);
200 }
201
202 #define IPFIX_IOAM_EXPORT_ID 272
203 #define IPFIX_VXLAN_IOAM_EXPORT_ID 273
204
205 /* Used to build the rewrite */
206 /* data set packet */
207 typedef struct
208 {
209   ipfix_message_header_t h;
210   ipfix_set_header_t s;
211 } ipfix_data_packet_t;
212
213 typedef struct
214 {
215   ip4_header_t ip4;
216   udp_header_t udp;
217   ipfix_data_packet_t ipfix;
218 } ip4_ipfix_data_packet_t;
219
220
221 inline static void
222 ioam_export_header_cleanup (ioam_export_main_t * em,
223                             ip4_address_t * collector_address,
224                             ip4_address_t * src_address)
225 {
226   vec_free (em->record_header);
227   em->record_header = 0;
228 }
229
230 inline static int
231 ioam_export_header_create (ioam_export_main_t * em,
232                            ip4_address_t * collector_address,
233                            ip4_address_t * src_address)
234 {
235   ip4_header_t *ip;
236   udp_header_t *udp;
237   ipfix_message_header_t *h;
238   ipfix_set_header_t *s;
239   u8 *rewrite = 0;
240   ip4_ipfix_data_packet_t *tp;
241
242
243   /* allocate rewrite space */
244   vec_validate_aligned (rewrite,
245                         sizeof (ip4_ipfix_data_packet_t) - 1,
246                         CLIB_CACHE_LINE_BYTES);
247
248   tp = (ip4_ipfix_data_packet_t *) rewrite;
249   ip = (ip4_header_t *) & tp->ip4;
250   udp = (udp_header_t *) (ip + 1);
251   h = (ipfix_message_header_t *) (udp + 1);
252   s = (ipfix_set_header_t *) (h + 1);
253
254   ip->ip_version_and_header_length = 0x45;
255   ip->ttl = 254;
256   ip->protocol = IP_PROTOCOL_UDP;
257   ip->src_address.as_u32 = src_address->as_u32;
258   ip->dst_address.as_u32 = collector_address->as_u32;
259   udp->src_port = clib_host_to_net_u16 (UDP_DST_PORT_ipfix);
260   udp->dst_port = clib_host_to_net_u16 (UDP_DST_PORT_ipfix);
261   /* FIXUP: UDP length */
262   udp->length = clib_host_to_net_u16 (vec_len (rewrite) +
263                                       (DEFAULT_EXPORT_RECORDS *
264                                        DEFAULT_EXPORT_SIZE) - sizeof (*ip));
265
266   /* FIXUP: message header export_time */
267   /* FIXUP: message header sequence_number */
268   h->domain_id = clib_host_to_net_u32 (em->domain_id);
269
270   /*FIXUP: Setid length in octets if records exported are not default */
271   s->set_id_length = ipfix_set_id_length (em->set_id,
272                                           (sizeof (*s) +
273                                            (DEFAULT_EXPORT_RECORDS *
274                                             DEFAULT_EXPORT_SIZE)));
275
276   /* FIXUP: h version and length length in octets if records exported are not default */
277   h->version_length = version_length (sizeof (*h) +
278                                       (sizeof (*s) +
279                                        (DEFAULT_EXPORT_RECORDS *
280                                         DEFAULT_EXPORT_SIZE)));
281
282   /* FIXUP: ip length if records exported are not default */
283   /* FIXUP: ip checksum if records exported are not default */
284   ip->length = clib_host_to_net_u16 (vec_len (rewrite) +
285                                      (DEFAULT_EXPORT_RECORDS *
286                                       DEFAULT_EXPORT_SIZE));
287   ip->checksum = ip4_header_checksum (ip);
288   _vec_len (rewrite) = sizeof (ip4_ipfix_data_packet_t);
289   em->record_header = rewrite;
290   return (1);
291 }
292
293 inline static int
294 ioam_export_send_buffer (ioam_export_main_t * em, vlib_main_t * vm,
295                          ioam_export_buffer_t * eb)
296 {
297   ip4_header_t *ip;
298   udp_header_t *udp;
299   ipfix_message_header_t *h;
300   ipfix_set_header_t *s;
301   ip4_ipfix_data_packet_t *tp;
302   vlib_buffer_t *b0;
303   u16 new_l0, old_l0;
304   ip_csum_t sum0;
305   vlib_frame_t *nf = 0;
306   u32 *to_next;
307
308   b0 = vlib_get_buffer (vm, eb->buffer_index);
309   tp = vlib_buffer_get_current (b0);
310   ip = (ip4_header_t *) & tp->ip4;
311   udp = (udp_header_t *) (ip + 1);
312   h = (ipfix_message_header_t *) (udp + 1);
313   s = (ipfix_set_header_t *) (h + 1);
314
315   /* FIXUP: message header export_time */
316   h->export_time = clib_host_to_net_u32 ((u32)
317                                          (((f64) em->unix_time_0) +
318                                           (vlib_time_now (em->vlib_main) -
319                                            em->vlib_time_0)));
320
321   /* FIXUP: message header sequence_number */
322   h->sequence_number = clib_host_to_net_u32 (em->sequence_number++);
323
324   /* FIXUP: lengths if different from default */
325   if (PREDICT_FALSE (eb->records_in_this_buffer != DEFAULT_EXPORT_RECORDS))
326     {
327       s->set_id_length = ipfix_set_id_length (em->set_id /* set_id */ ,
328                                               b0->current_length -
329                                               (sizeof (*ip) + sizeof (*udp) +
330                                                sizeof (*h)));
331       h->version_length =
332         version_length (b0->current_length - (sizeof (*ip) + sizeof (*udp)));
333       sum0 = ip->checksum;
334       old_l0 = ip->length;
335       new_l0 = clib_host_to_net_u16 ((u16) b0->current_length);
336       sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
337                              length /* changed member */ );
338       ip->checksum = ip_csum_fold (sum0);
339       ip->length = new_l0;
340       udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip));
341     }
342
343   /* Enqueue pkts to ip4-lookup */
344
345   nf = vlib_get_frame_to_node (vm, em->next_node_index);
346   nf->n_vectors = 0;
347   to_next = vlib_frame_vector_args (nf);
348   nf->n_vectors = 1;
349   to_next[0] = eb->buffer_index;
350   vlib_put_frame_to_node (vm, em->next_node_index, nf);
351   return (1);
352
353 }
354
355 #define EXPORT_TIMEOUT (20.0)
356 #define THREAD_PERIOD (30.0)
357 inline static uword
358 ioam_export_process_common (ioam_export_main_t * em, vlib_main_t * vm,
359                             vlib_node_runtime_t * rt, vlib_frame_t * f,
360                             u32 index)
361 {
362   f64 now;
363   f64 timeout = 30.0;
364   uword event_type;
365   uword *event_data = 0;
366   int i;
367   ioam_export_buffer_t *eb = 0, *new_eb = 0;
368   u32 *vec_buffer_indices = 0;
369   u32 *vec_buffer_to_be_sent = 0;
370   u32 *thread_index = 0;
371   u32 new_pool_index = 0;
372
373   em->export_process_node_index = index;
374   /* Wait for Godot... */
375   vlib_process_wait_for_event_or_clock (vm, 1e9);
376   event_type = vlib_process_get_events (vm, &event_data);
377   if (event_type != 1)
378     clib_warning ("bogus kickoff event received, %d", event_type);
379   vec_reset_length (event_data);
380
381   while (1)
382     {
383       vlib_process_wait_for_event_or_clock (vm, timeout);
384       event_type = vlib_process_get_events (vm, &event_data);
385       switch (event_type)
386         {
387         case 2:         /* Stop and Wait for kickoff again */
388           timeout = 1e9;
389           break;
390         case 1:         /* kickoff : Check for unsent buffers */
391           timeout = THREAD_PERIOD;
392           break;
393         case ~0:                /* timeout */
394           break;
395         }
396       vec_reset_length (event_data);
397       now = vlib_time_now (vm);
398       /*
399        * Create buffers for threads that are not active enough
400        * to send out the export records
401        */
402       for (i = 0; i < vec_len (em->buffer_per_thread); i++)
403         {
404           /* If the worker thread is processing export records ignore further checks */
405           if (*em->lockp[i] == 1)
406             continue;
407           eb = pool_elt_at_index (em->buffer_pool, em->buffer_per_thread[i]);
408           if (eb->records_in_this_buffer > 0
409               && now > (eb->touched_at + EXPORT_TIMEOUT))
410             {
411               pool_get_aligned (em->buffer_pool, new_eb,
412                                 CLIB_CACHE_LINE_BYTES);
413               memset (new_eb, 0, sizeof (*new_eb));
414               if (ioam_export_init_buffer (em, vm, new_eb) == 1)
415                 {
416                   new_pool_index = new_eb - em->buffer_pool;
417                   vec_add (vec_buffer_indices, &new_pool_index, 1);
418                   vec_add (vec_buffer_to_be_sent, &em->buffer_per_thread[i],
419                            1);
420                   vec_add (thread_index, &i, 1);
421                 }
422               else
423                 {
424                   pool_put (em->buffer_pool, new_eb);
425                   /*Give up */
426                   goto CLEANUP;
427                 }
428             }
429         }
430       if (vec_len (thread_index) != 0)
431         {
432           /*
433            * Now swap the buffers out
434            */
435           for (i = 0; i < vec_len (thread_index); i++)
436             {
437               while (__sync_lock_test_and_set (em->lockp[thread_index[i]], 1))
438                 ;
439               em->buffer_per_thread[thread_index[i]] =
440                 vec_pop (vec_buffer_indices);
441               *em->lockp[thread_index[i]] = 0;
442             }
443
444           /* Send the buffers */
445           for (i = 0; i < vec_len (vec_buffer_to_be_sent); i++)
446             {
447               eb =
448                 pool_elt_at_index (em->buffer_pool, vec_buffer_to_be_sent[i]);
449               ioam_export_send_buffer (em, vm, eb);
450               pool_put (em->buffer_pool, eb);
451             }
452         }
453
454     CLEANUP:
455       /* Free any leftover/unused buffers and everything that was allocated */
456       for (i = 0; i < vec_len (vec_buffer_indices); i++)
457         {
458           new_eb = pool_elt_at_index (em->buffer_pool, vec_buffer_indices[i]);
459           vlib_buffer_free (vm, &new_eb->buffer_index, 1);
460           pool_put (em->buffer_pool, new_eb);
461         }
462       vec_free (vec_buffer_indices);
463       vec_free (vec_buffer_to_be_sent);
464       vec_free (thread_index);
465     }
466   return 0;                     /* not so much */
467 }
468
469 #define ioam_export_node_common(EM, VM, N, F, HTYPE, L, V, NEXT, FIXUP_FUNC)   \
470 do {                                                                           \
471   u32 n_left_from, *from, *to_next;                                            \
472   export_next_t next_index;                                                    \
473   u32 pkts_recorded = 0;                                                       \
474   ioam_export_buffer_t *my_buf = 0;                                            \
475   vlib_buffer_t *eb0 = 0;                                                      \
476   u32 ebi0 = 0;                                                                \
477   from = vlib_frame_vector_args (F);                                           \
478   n_left_from = (F)->n_vectors;                                                \
479   next_index = (N)->cached_next_index;                                         \
480   while (__sync_lock_test_and_set ((EM)->lockp[(VM)->thread_index], 1));       \
481   my_buf = ioam_export_get_my_buffer (EM, (VM)->thread_index);                 \
482   my_buf->touched_at = vlib_time_now (VM);                                     \
483   while (n_left_from > 0)                                                      \
484     {                                                                          \
485       u32 n_left_to_next;                                                      \
486       vlib_get_next_frame (VM, N, next_index, to_next, n_left_to_next);        \
487       while (n_left_from >= 4 && n_left_to_next >= 2)                          \
488         {                                                                      \
489           u32 next0 = NEXT;                                                    \
490           u32 next1 = NEXT;                                                    \
491           u32 bi0, bi1;                                                        \
492           HTYPE *ip0, *ip1;                                                    \
493           vlib_buffer_t *p0, *p1;                                              \
494           u32 ip_len0, ip_len1;                                                \
495           {                                                                    \
496             vlib_buffer_t *p2, *p3;                                            \
497             p2 = vlib_get_buffer (VM, from[2]);                                \
498             p3 = vlib_get_buffer (VM, from[3]);                                \
499             vlib_prefetch_buffer_header (p2, LOAD);                            \
500             vlib_prefetch_buffer_header (p3, LOAD);                            \
501             CLIB_PREFETCH (p2->data, 3 * CLIB_CACHE_LINE_BYTES, LOAD);         \
502             CLIB_PREFETCH (p3->data, 3 * CLIB_CACHE_LINE_BYTES, LOAD);         \
503           }                                                                    \
504           to_next[0] = bi0 = from[0];                                          \
505           to_next[1] = bi1 = from[1];                                          \
506           from += 2;                                                           \
507           to_next += 2;                                                        \
508           n_left_from -= 2;                                                    \
509           n_left_to_next -= 2;                                                 \
510           p0 = vlib_get_buffer (VM, bi0);                                      \
511           p1 = vlib_get_buffer (VM, bi1);                                      \
512           ip0 = vlib_buffer_get_current (p0);                                  \
513           ip1 = vlib_buffer_get_current (p1);                                  \
514           ip_len0 =                                                            \
515             clib_net_to_host_u16 (ip0->L) + sizeof (HTYPE);                    \
516           ip_len1 =                                                            \
517             clib_net_to_host_u16 (ip1->L) + sizeof (HTYPE);                    \
518           ebi0 = my_buf->buffer_index;                                         \
519           eb0 = vlib_get_buffer (VM, ebi0);                                    \
520           if (PREDICT_FALSE (eb0 == 0))                                        \
521             goto NO_BUFFER1;                                                   \
522           ip_len0 =                                                            \
523             ip_len0 > DEFAULT_EXPORT_SIZE ? DEFAULT_EXPORT_SIZE : ip_len0;     \
524           ip_len1 =                                                            \
525             ip_len1 > DEFAULT_EXPORT_SIZE ? DEFAULT_EXPORT_SIZE : ip_len1;     \
526           copy3cachelines (eb0->data + eb0->current_length, ip0, ip_len0);     \
527           FIXUP_FUNC(eb0, p0);                                                 \
528           eb0->current_length += DEFAULT_EXPORT_SIZE;                          \
529           my_buf->records_in_this_buffer++;                                    \
530           if (my_buf->records_in_this_buffer >= DEFAULT_EXPORT_RECORDS)        \
531             {                                                                  \
532               ioam_export_send_buffer (EM, VM, my_buf);                        \
533               ioam_export_init_buffer (EM, VM, my_buf);                        \
534             }                                                                  \
535           ebi0 = my_buf->buffer_index;                                         \
536           eb0 = vlib_get_buffer (VM, ebi0);                                    \
537           if (PREDICT_FALSE (eb0 == 0))                                        \
538             goto NO_BUFFER1;                                                   \
539           copy3cachelines (eb0->data + eb0->current_length, ip1, ip_len1);     \
540           FIXUP_FUNC(eb0, p1);                                                 \
541           eb0->current_length += DEFAULT_EXPORT_SIZE;                          \
542           my_buf->records_in_this_buffer++;                                    \
543           if (my_buf->records_in_this_buffer >= DEFAULT_EXPORT_RECORDS)        \
544             {                                                                  \
545               ioam_export_send_buffer (EM, VM, my_buf);                        \
546               ioam_export_init_buffer (EM, VM, my_buf);                        \
547             }                                                                  \
548           pkts_recorded += 2;                                                  \
549           if (PREDICT_FALSE (((node)->flags & VLIB_NODE_FLAG_TRACE)))          \
550             {                                                                  \
551               if (p0->flags & VLIB_BUFFER_IS_TRACED)                           \
552                 {                                                              \
553                   export_trace_t *t =                                          \
554                     vlib_add_trace (VM, node, p0, sizeof (*t));                \
555                   t->flow_label =                                              \
556                     clib_net_to_host_u32 (ip0->V);                             \
557                   t->next_index = next0;                                       \
558                 }                                                              \
559               if (p1->flags & VLIB_BUFFER_IS_TRACED)                           \
560                 {                                                              \
561                   export_trace_t *t =                                          \
562                     vlib_add_trace (VM, N, p1, sizeof (*t));                   \
563                   t->flow_label =                                              \
564                     clib_net_to_host_u32 (ip1->V);                             \
565                   t->next_index = next1;                                       \
566                 }                                                              \
567             }                                                                  \
568         NO_BUFFER1:                                                            \
569           vlib_validate_buffer_enqueue_x2 (VM, N, next_index,                  \
570                                            to_next, n_left_to_next,            \
571                                            bi0, bi1, next0, next1);            \
572         }                                                                      \
573       while (n_left_from > 0 && n_left_to_next > 0)                            \
574         {                                                                      \
575           u32 bi0;                                                             \
576           vlib_buffer_t *p0;                                                   \
577           u32 next0 = NEXT;                                                    \
578           HTYPE *ip0;                                                          \
579           u32 ip_len0;                                                         \
580           bi0 = from[0];                                                       \
581           to_next[0] = bi0;                                                    \
582           from += 1;                                                           \
583           to_next += 1;                                                        \
584           n_left_from -= 1;                                                    \
585           n_left_to_next -= 1;                                                 \
586           p0 = vlib_get_buffer (VM, bi0);                                      \
587           ip0 = vlib_buffer_get_current (p0);                                  \
588           ip_len0 =                                                            \
589             clib_net_to_host_u16 (ip0->L) + sizeof (HTYPE);                    \
590           ebi0 = my_buf->buffer_index;                                         \
591           eb0 = vlib_get_buffer (VM, ebi0);                                    \
592           if (PREDICT_FALSE (eb0 == 0))                                        \
593             goto NO_BUFFER;                                                    \
594           ip_len0 =                                                            \
595             ip_len0 > DEFAULT_EXPORT_SIZE ? DEFAULT_EXPORT_SIZE : ip_len0;     \
596           copy3cachelines (eb0->data + eb0->current_length, ip0, ip_len0);     \
597           FIXUP_FUNC(eb0, p0);                                                 \
598           eb0->current_length += DEFAULT_EXPORT_SIZE;                          \
599           my_buf->records_in_this_buffer++;                                    \
600           if (my_buf->records_in_this_buffer >= DEFAULT_EXPORT_RECORDS)        \
601             {                                                                  \
602               ioam_export_send_buffer (EM, VM, my_buf);                        \
603               ioam_export_init_buffer (EM, VM, my_buf);                        \
604             }                                                                  \
605           if (PREDICT_FALSE (((N)->flags & VLIB_NODE_FLAG_TRACE)               \
606                              && (p0->flags & VLIB_BUFFER_IS_TRACED)))          \
607             {                                                                  \
608               export_trace_t *t = vlib_add_trace (VM, (N), p0, sizeof (*t));   \
609               t->flow_label =                                                  \
610                 clib_net_to_host_u32 (ip0->V);                                 \
611               t->next_index = next0;                                           \
612             }                                                                  \
613           pkts_recorded += 1;                                                  \
614         NO_BUFFER:                                                             \
615           vlib_validate_buffer_enqueue_x1 (VM, N, next_index,                  \
616                                            to_next, n_left_to_next,            \
617                                            bi0, next0);                        \
618         }                                                                      \
619       vlib_put_next_frame (VM, N, next_index, n_left_to_next);                 \
620     }                                                                          \
621   vlib_node_increment_counter (VM, export_node.index,                          \
622                                EXPORT_ERROR_RECORDED, pkts_recorded);          \
623   *(EM)->lockp[(VM)->thread_index] = 0;                                        \
624 } while(0)
625
626 #endif /* __included_ioam_export_h__ */
627
628 /*
629  * fd.io coding-style-patch-verification: ON
630  *
631  * Local Variables:
632  * eval: (c-set-style "gnu")
633  * End:
634  */