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