api: API trace improvements
[vpp.git] / src / vlibmemory / memclnt_api.c
1 /*
2  *------------------------------------------------------------------
3  * memclnt_api.c VLIB API implementation
4  *
5  * Copyright (c) 2009 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 #include <fcntl.h>
21 #include <pthread.h>
22 #include <vppinfra/vec.h>
23 #include <vppinfra/hash.h>
24 #include <vppinfra/pool.h>
25 #include <vppinfra/format.h>
26 #include <vppinfra/byte_order.h>
27 #include <vppinfra/elog.h>
28 #include <vlib/vlib.h>
29 #include <vlib/unix/unix.h>
30 #include <vlibapi/api.h>
31 #include <vlibmemory/api.h>
32
33 /**
34  * @file
35  * @brief Binary API messaging via shared memory
36  * Low-level, primary provisioning interface
37  */
38 /*? %%clicmd:group_label Binary API CLI %% ?*/
39 /*? %%syscfg:group_label Binary API configuration %% ?*/
40
41 #define TRACE_VLIB_MEMORY_QUEUE 0
42
43 #include <vlibmemory/vl_memory_msg_enum.h> /* enumerate all vlib messages */
44
45 #define vl_typedefs /* define message structures */
46 #include <vlibmemory/vl_memory_api_h.h>
47 #undef vl_typedefs
48
49 /* instantiate all the print functions we know about */
50 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
51 #define vl_printfun
52 #include <vlibmemory/vl_memory_api_h.h>
53 #undef vl_printfun
54
55 /* instantiate all the endian swap functions we know about */
56 #define vl_endianfun
57 #include <vlibmemory/vl_memory_api_h.h>
58 #undef vl_endianfun
59
60 static void
61 vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t *mp)
62 {
63   vl_api_get_first_msg_id_reply_t *rmp;
64   vl_api_registration_t *regp;
65   uword *p;
66   api_main_t *am = vlibapi_get_main ();
67   vl_api_msg_range_t *rp;
68   u8 name[64];
69   u16 first_msg_id = ~0;
70   int rv = -7; /* VNET_API_ERROR_INVALID_VALUE */
71
72   regp = vl_api_client_index_to_registration (mp->client_index);
73   if (!regp)
74     return;
75
76   if (am->msg_range_by_name == 0)
77     goto out;
78   strncpy ((char *) name, (char *) mp->name, ARRAY_LEN (name));
79   name[ARRAY_LEN (name) - 1] = '\0';
80   p = hash_get_mem (am->msg_range_by_name, name);
81   if (p == 0)
82     goto out;
83
84   rp = vec_elt_at_index (am->msg_ranges, p[0]);
85   first_msg_id = rp->first_msg_id;
86   rv = 0;
87
88 out:
89   rmp = vl_msg_api_alloc (sizeof (*rmp));
90   rmp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID_REPLY);
91   rmp->context = mp->context;
92   rmp->retval = ntohl (rv);
93   rmp->first_msg_id = ntohs (first_msg_id);
94   vl_api_send_msg (regp, (u8 *) rmp);
95 }
96
97 void
98 vl_api_api_versions_t_handler (vl_api_api_versions_t *mp)
99 {
100   api_main_t *am = vlibapi_get_main ();
101   vl_api_api_versions_reply_t *rmp;
102   vl_api_registration_t *reg;
103   u32 nmsg = vec_len (am->api_version_list);
104   int msg_size = sizeof (*rmp) + sizeof (rmp->api_versions[0]) * nmsg;
105   int i;
106
107   reg = vl_api_client_index_to_registration (mp->client_index);
108   if (!reg)
109     return;
110
111   rmp = vl_msg_api_alloc (msg_size);
112   clib_memset (rmp, 0, msg_size);
113   rmp->_vl_msg_id = ntohs (VL_API_API_VERSIONS_REPLY);
114
115   /* fill in the message */
116   rmp->context = mp->context;
117   rmp->count = htonl (nmsg);
118
119   for (i = 0; i < nmsg; ++i)
120     {
121       api_version_t *vl = &am->api_version_list[i];
122       rmp->api_versions[i].major = htonl (vl->major);
123       rmp->api_versions[i].minor = htonl (vl->minor);
124       rmp->api_versions[i].patch = htonl (vl->patch);
125       strncpy ((char *) rmp->api_versions[i].name, vl->name,
126                ARRAY_LEN (rmp->api_versions[i].name));
127       rmp->api_versions[i].name[ARRAY_LEN (rmp->api_versions[i].name) - 1] =
128         '\0';
129     }
130
131   vl_api_send_msg (reg, (u8 *) rmp);
132 }
133
134 #define foreach_vlib_api_msg                                                  \
135   _ (GET_FIRST_MSG_ID, get_first_msg_id)                                      \
136   _ (API_VERSIONS, api_versions)
137
138 /*
139  * vl_api_init
140  */
141 static int
142 vlib_api_init (void)
143 {
144   vl_msg_api_msg_config_t cfg;
145   vl_msg_api_msg_config_t *c = &cfg;
146
147   cJSON_Hooks cjson_hooks = {
148     .malloc_fn = clib_mem_alloc,
149     .free_fn = clib_mem_free,
150   };
151   cJSON_InitHooks (&cjson_hooks);
152
153   clib_memset (c, 0, sizeof (*c));
154
155 #define _(N, n)                                                               \
156   do                                                                          \
157     {                                                                         \
158       c->id = VL_API_##N;                                                     \
159       c->name = #n;                                                           \
160       c->handler = vl_api_##n##_t_handler;                                    \
161       c->cleanup = vl_noop_handler;                                           \
162       c->endian = vl_api_##n##_t_endian;                                      \
163       c->print = vl_api_##n##_t_print;                                        \
164       c->size = sizeof (vl_api_##n##_t);                                      \
165       c->traced = 1;         /* trace, so these msgs print */                 \
166       c->replay = 0;         /* don't replay client create/delete msgs */     \
167       c->message_bounce = 0; /* don't bounce this message */                  \
168       vl_msg_api_config (c);                                                  \
169     }                                                                         \
170   while (0);
171
172   foreach_vlib_api_msg;
173 #undef _
174
175   return 0;
176 }
177
178 u64 vector_rate_histogram[SLEEP_N_BUCKETS];
179
180 /*
181  * Callback to send ourselves a plugin numbering-space trace msg
182  */
183 static void
184 send_one_plugin_msg_ids_msg (u8 *name, u16 first_msg_id, u16 last_msg_id)
185 {
186   vl_api_trace_plugin_msg_ids_t *mp;
187   api_main_t *am = vlibapi_get_main ();
188   vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
189   svm_queue_t *q;
190
191   mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
192   clib_memset (mp, 0, sizeof (*mp));
193
194   mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_TRACE_PLUGIN_MSG_IDS);
195   strncpy ((char *) mp->plugin_name, (char *) name,
196            sizeof (mp->plugin_name) - 1);
197   mp->first_msg_id = clib_host_to_net_u16 (first_msg_id);
198   mp->last_msg_id = clib_host_to_net_u16 (last_msg_id);
199
200   q = shmem_hdr->vl_input_queue;
201
202   vl_msg_api_send_shmem (q, (u8 *) &mp);
203 }
204
205 void
206 vl_api_save_msg_table (void)
207 {
208   u8 *serialized_message_table;
209   api_main_t *am = vlibapi_get_main ();
210   u8 *chroot_file;
211   int fd, rv;
212
213   /*
214    * Snapshoot the api message table.
215    */
216   if (strstr ((char *) am->save_msg_table_filename, "..") ||
217       index ((char *) am->save_msg_table_filename, '/'))
218     {
219       clib_warning ("illegal save-message-table filename '%s'",
220                     am->save_msg_table_filename);
221       return;
222     }
223
224   chroot_file = format (0, "/tmp/%s%c", am->save_msg_table_filename, 0);
225
226   fd = creat ((char *) chroot_file, 0644);
227
228   if (fd < 0)
229     {
230       clib_unix_warning ("creat");
231       return;
232     }
233
234   serialized_message_table = vl_api_serialize_message_table (am, 0);
235
236   rv =
237     write (fd, serialized_message_table, vec_len (serialized_message_table));
238
239   if (rv != vec_len (serialized_message_table))
240     clib_unix_warning ("write");
241
242   rv = close (fd);
243   if (rv < 0)
244     clib_unix_warning ("close");
245
246   vec_free (chroot_file);
247   vec_free (serialized_message_table);
248 }
249
250 clib_error_t *vat_builtin_main_init (vlib_main_t *vm) __attribute__ ((weak));
251 clib_error_t *
252 vat_builtin_main_init (vlib_main_t *vm)
253 {
254   return 0;
255 }
256
257 static uword
258 vl_api_clnt_process (vlib_main_t *vm, vlib_node_runtime_t *node,
259                      vlib_frame_t *f)
260 {
261   vlib_global_main_t *vgm = vlib_get_global_main ();
262   int private_segment_rotor = 0, i, rv;
263   vl_socket_args_for_process_t *a;
264   vl_shmem_hdr_t *shm;
265   svm_queue_t *q;
266   clib_error_t *e;
267   api_main_t *am = vlibapi_get_main ();
268   f64 dead_client_scan_time;
269   f64 sleep_time, start_time;
270   f64 vector_rate;
271   clib_error_t *error;
272   uword event_type;
273   uword *event_data = 0;
274   f64 now;
275
276   if ((error = vl_sock_api_init (vm)))
277     {
278       clib_error_report (error);
279       clib_warning ("socksvr_api_init failed, quitting...");
280       return 0;
281     }
282
283   if ((rv = vlib_api_init ()) < 0)
284     {
285       clib_warning ("vlib_api_init returned %d, quitting...", rv);
286       return 0;
287     }
288
289   shm = am->shmem_hdr;
290   q = shm->vl_input_queue;
291
292   e = vlib_call_init_exit_functions (vm, &vgm->api_init_function_registrations,
293                                      1 /* call_once */, 1 /* is_global */);
294   if (e)
295     clib_error_report (e);
296
297   e = vat_builtin_main_init (vm);
298   if (e)
299     clib_error_report (e);
300
301   sleep_time = 10.0;
302   dead_client_scan_time = vlib_time_now (vm) + 10.0;
303
304   /*
305    * Send plugin message range messages for each plugin we loaded
306    */
307   for (i = 0; i < vec_len (am->msg_ranges); i++)
308     {
309       vl_api_msg_range_t *rp = am->msg_ranges + i;
310       send_one_plugin_msg_ids_msg (rp->name, rp->first_msg_id,
311                                    rp->last_msg_id);
312     }
313
314   /*
315    * Save the api message table snapshot, if configured
316    */
317   if (am->save_msg_table_filename)
318     vl_api_save_msg_table ();
319
320   /* $$$ pay attention to frame size, control CPU usage */
321   while (1)
322     {
323       /*
324        * There's a reason for checking the queue before
325        * sleeping. If the vlib application crashes, it's entirely
326        * possible for a client to enqueue a connect request
327        * during the process restart interval.
328        *
329        * Unless some force of physics causes the new incarnation
330        * of the application to process the request, the client will
331        * sit and wait for Godot...
332        */
333       vector_rate = (f64) vlib_last_vectors_per_main_loop (vm);
334       start_time = vlib_time_now (vm);
335       while (1)
336         {
337           if (vl_mem_api_handle_rpc (vm, node) ||
338               vl_mem_api_handle_msg_main (vm, node))
339             {
340               vm->api_queue_nonempty = 0;
341               VL_MEM_API_LOG_Q_LEN ("q-underflow: len %d", 0);
342               sleep_time = 20.0;
343               break;
344             }
345
346           /* Allow no more than 10us without a pause */
347           if (vlib_time_now (vm) > start_time + 10e-6)
348             {
349               int index = SLEEP_400_US;
350               if (vector_rate > 40.0)
351                 sleep_time = 400e-6;
352               else if (vector_rate > 20.0)
353                 {
354                   index = SLEEP_200_US;
355                   sleep_time = 200e-6;
356                 }
357               else if (vector_rate >= 1.0)
358                 {
359                   index = SLEEP_100_US;
360                   sleep_time = 100e-6;
361                 }
362               else
363                 {
364                   index = SLEEP_10_US;
365                   sleep_time = 10e-6;
366                 }
367               vector_rate_histogram[index] += 1;
368               break;
369             }
370         }
371
372       /*
373        * see if we have any private api shared-memory segments
374        * If so, push required context variables, and process
375        * a message.
376        */
377       if (PREDICT_FALSE (vec_len (am->vlib_private_rps)))
378         {
379           if (private_segment_rotor >= vec_len (am->vlib_private_rps))
380             private_segment_rotor = 0;
381           vl_mem_api_handle_msg_private (vm, node, private_segment_rotor++);
382         }
383
384       vlib_process_wait_for_event_or_clock (vm, sleep_time);
385       vec_reset_length (event_data);
386       event_type = vlib_process_get_events (vm, &event_data);
387       now = vlib_time_now (vm);
388
389       switch (event_type)
390         {
391         case QUEUE_SIGNAL_EVENT:
392           vm->queue_signal_pending = 0;
393           VL_MEM_API_LOG_Q_LEN ("q-awake: len %d", q->cursize);
394
395           break;
396         case SOCKET_READ_EVENT:
397           for (i = 0; i < vec_len (event_data); i++)
398             {
399               vl_api_registration_t *regp;
400
401               a = pool_elt_at_index (socket_main.process_args, event_data[i]);
402               regp = vl_socket_get_registration (a->reg_index);
403               if (regp)
404                 {
405                   vl_socket_process_api_msg (regp, (i8 *) a->data);
406                   a = pool_elt_at_index (socket_main.process_args,
407                                          event_data[i]);
408                 }
409               vec_free (a->data);
410               pool_put (socket_main.process_args, a);
411             }
412           break;
413
414           /* Timeout... */
415         case -1:
416           break;
417
418         default:
419           clib_warning ("unknown event type %d", event_type);
420           break;
421         }
422
423       if (now > dead_client_scan_time)
424         {
425           vl_mem_api_dead_client_scan (am, shm, now);
426           dead_client_scan_time = vlib_time_now (vm) + 10.0;
427         }
428     }
429
430   return 0;
431 }
432
433 VLIB_REGISTER_NODE (vl_api_clnt_node) = {
434   .function = vl_api_clnt_process,
435   .type = VLIB_NODE_TYPE_PROCESS,
436   .name = "api-rx-from-ring",
437   .state = VLIB_NODE_STATE_DISABLED,
438   .process_log2_n_stack_bytes = 18,
439 };
440
441 void
442 vl_mem_api_enable_disable (vlib_main_t *vm, int enable)
443 {
444   vlib_node_set_state (
445     vm, vl_api_clnt_node.index,
446     (enable ? VLIB_NODE_STATE_POLLING : VLIB_NODE_STATE_DISABLED));
447 }
448
449 static uword
450 api_rx_from_node (vlib_main_t *vm, vlib_node_runtime_t *node,
451                   vlib_frame_t *frame)
452 {
453   uword n_packets = frame->n_vectors;
454   uword n_left_from;
455   u32 *from;
456   static u8 *long_msg;
457
458   vec_validate (long_msg, 4095);
459   n_left_from = frame->n_vectors;
460   from = vlib_frame_vector_args (frame);
461
462   while (n_left_from > 0)
463     {
464       u32 bi0;
465       vlib_buffer_t *b0;
466       void *msg;
467       uword msg_len;
468
469       bi0 = from[0];
470       b0 = vlib_get_buffer (vm, bi0);
471       from += 1;
472       n_left_from -= 1;
473
474       msg = b0->data + b0->current_data;
475       msg_len = b0->current_length;
476       if (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
477         {
478           ASSERT (long_msg != 0);
479           _vec_len (long_msg) = 0;
480           vec_add (long_msg, msg, msg_len);
481           while (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
482             {
483               b0 = vlib_get_buffer (vm, b0->next_buffer);
484               msg = b0->data + b0->current_data;
485               msg_len = b0->current_length;
486               vec_add (long_msg, msg, msg_len);
487             }
488           msg = long_msg;
489         }
490       vl_msg_api_handler_no_trace_no_free (msg);
491     }
492
493   /* Free what we've been given. */
494   vlib_buffer_free (vm, vlib_frame_vector_args (frame), n_packets);
495
496   return n_packets;
497 }
498
499 VLIB_REGISTER_NODE (api_rx_from_node_node, static) = {
500   .function = api_rx_from_node,
501   .type = VLIB_NODE_TYPE_INTERNAL,
502   .vector_size = 4,
503   .name = "api-rx-from-node",
504 };
505
506 static void
507 vl_api_rpc_call_t_handler (vl_api_rpc_call_t *mp)
508 {
509   vl_api_rpc_call_reply_t *rmp;
510   int (*fp) (void *);
511   i32 rv = 0;
512   vlib_main_t *vm = vlib_get_main ();
513
514   if (mp->function == 0)
515     {
516       rv = -1;
517       clib_warning ("rpc NULL function pointer");
518     }
519
520   else
521     {
522       if (mp->need_barrier_sync)
523         vlib_worker_thread_barrier_sync (vm);
524
525       fp = uword_to_pointer (mp->function, int (*) (void *));
526       rv = fp (mp->data);
527
528       if (mp->need_barrier_sync)
529         vlib_worker_thread_barrier_release (vm);
530     }
531
532   if (mp->send_reply)
533     {
534       svm_queue_t *q = vl_api_client_index_to_input_queue (mp->client_index);
535       if (q)
536         {
537           rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
538           rmp->_vl_msg_id = ntohs (VL_API_RPC_CALL_REPLY);
539           rmp->context = mp->context;
540           rmp->retval = rv;
541           vl_msg_api_send_shmem (q, (u8 *) &rmp);
542         }
543     }
544   if (mp->multicast)
545     {
546       clib_warning ("multicast not yet implemented...");
547     }
548 }
549
550 static void
551 vl_api_rpc_call_reply_t_handler (vl_api_rpc_call_reply_t *mp)
552 {
553   clib_warning ("unimplemented");
554 }
555
556 void
557 vl_api_send_pending_rpc_requests (vlib_main_t *vm)
558 {
559   vlib_main_t *vm_global = vlib_get_first_main ();
560
561   ASSERT (vm != vm_global);
562
563   clib_spinlock_lock_if_init (&vm_global->pending_rpc_lock);
564   vec_append (vm_global->pending_rpc_requests, vm->pending_rpc_requests);
565   vec_reset_length (vm->pending_rpc_requests);
566   clib_spinlock_unlock_if_init (&vm_global->pending_rpc_lock);
567 }
568
569 always_inline void
570 vl_api_rpc_call_main_thread_inline (void *fp, u8 *data, u32 data_length,
571                                     u8 force_rpc)
572 {
573   vl_api_rpc_call_t *mp;
574   vlib_main_t *vm_global = vlib_get_first_main ();
575   vlib_main_t *vm = vlib_get_main ();
576
577   /* Main thread and not a forced RPC: call the function directly */
578   if ((force_rpc == 0) && (vlib_get_thread_index () == 0))
579     {
580       void (*call_fp) (void *);
581
582       vlib_worker_thread_barrier_sync (vm);
583
584       call_fp = fp;
585       call_fp (data);
586
587       vlib_worker_thread_barrier_release (vm);
588       return;
589     }
590
591   /* Otherwise, actually do an RPC */
592   mp = vl_msg_api_alloc_as_if_client (sizeof (*mp) + data_length);
593
594   clib_memset (mp, 0, sizeof (*mp));
595   clib_memcpy_fast (mp->data, data, data_length);
596   mp->_vl_msg_id = ntohs (VL_API_RPC_CALL);
597   mp->function = pointer_to_uword (fp);
598   mp->need_barrier_sync = 1;
599
600   /* Add to the pending vector. Thread 0 requires locking. */
601   if (vm == vm_global)
602     clib_spinlock_lock_if_init (&vm_global->pending_rpc_lock);
603   vec_add1 (vm->pending_rpc_requests, (uword) mp);
604   if (vm == vm_global)
605     clib_spinlock_unlock_if_init (&vm_global->pending_rpc_lock);
606 }
607
608 /*
609  * Check if called from worker threads.
610  * If so, make rpc call of fp through shmem.
611  * Otherwise, call fp directly
612  */
613 void
614 vl_api_rpc_call_main_thread (void *fp, u8 *data, u32 data_length)
615 {
616   vl_api_rpc_call_main_thread_inline (fp, data, data_length, /*force_rpc */
617                                       0);
618 }
619
620 /*
621  * Always make rpc call of fp through shmem, useful for calling from threads
622  * not setup as worker threads, such as DPDK callback thread
623  */
624 void
625 vl_api_force_rpc_call_main_thread (void *fp, u8 *data, u32 data_length)
626 {
627   vl_api_rpc_call_main_thread_inline (fp, data, data_length, /*force_rpc */
628                                       1);
629 }
630
631 static void
632 vl_api_trace_plugin_msg_ids_t_handler (vl_api_trace_plugin_msg_ids_t *mp)
633 {
634   api_main_t *am = vlibapi_get_main ();
635   vl_api_msg_range_t *rp;
636   uword *p;
637
638   /* Noop (except for tracing) during normal operation */
639   if (am->replay_in_progress == 0)
640     return;
641
642   p = hash_get_mem (am->msg_range_by_name, mp->plugin_name);
643   if (p == 0)
644     {
645       clib_warning ("WARNING: traced plugin '%s' not in current image",
646                     mp->plugin_name);
647       return;
648     }
649
650   rp = vec_elt_at_index (am->msg_ranges, p[0]);
651   if (rp->first_msg_id != clib_net_to_host_u16 (mp->first_msg_id))
652     {
653       clib_warning ("WARNING: traced plugin '%s' first message id %d not %d",
654                     mp->plugin_name, clib_net_to_host_u16 (mp->first_msg_id),
655                     rp->first_msg_id);
656     }
657
658   if (rp->last_msg_id != clib_net_to_host_u16 (mp->last_msg_id))
659     {
660       clib_warning ("WARNING: traced plugin '%s' last message id %d not %d",
661                     mp->plugin_name, clib_net_to_host_u16 (mp->last_msg_id),
662                     rp->last_msg_id);
663     }
664 }
665
666 #define foreach_rpc_api_msg                                                   \
667   _ (RPC_CALL, rpc_call)                                                      \
668   _ (RPC_CALL_REPLY, rpc_call_reply)
669
670 #define foreach_plugin_trace_msg _ (TRACE_PLUGIN_MSG_IDS, trace_plugin_msg_ids)
671
672 /*
673  * Set the rpc callback at our earliest possible convenience.
674  * This avoids ordering issues between thread_init() -> start_workers and
675  * an init function which we could define here. If we ever intend to use
676  * vlib all by itself, we can't create a link-time dependency on
677  * an init function here and a typical "call foo_init first"
678  * guitar lick.
679  */
680
681 extern void *rpc_call_main_thread_cb_fn;
682
683 static clib_error_t *
684 rpc_api_hookup (vlib_main_t *vm)
685 {
686   api_main_t *am = vlibapi_get_main ();
687 #define _(N, n)                                                               \
688   vl_msg_api_set_handlers (VL_API_##N, #n, vl_api_##n##_t_handler,            \
689                            vl_noop_handler, vl_noop_handler,                  \
690                            vl_api_##n##_t_print, sizeof (vl_api_##n##_t),     \
691                            0 /* do not trace */, vl_api_##n##_t_print_json,   \
692                            vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson);
693   foreach_rpc_api_msg;
694 #undef _
695
696 #define _(N, n)                                                               \
697   vl_msg_api_set_handlers (VL_API_##N, #n, vl_api_##n##_t_handler,            \
698                            vl_noop_handler, vl_noop_handler,                  \
699                            vl_api_##n##_t_print, sizeof (vl_api_##n##_t),     \
700                            1 /* do trace */, vl_api_##n##_t_print_json,       \
701                            vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson);
702   foreach_plugin_trace_msg;
703 #undef _
704
705   am->api_trace_cfg[VL_API_TRACE_PLUGIN_MSG_IDS].replay_enable = 0;
706
707   /* No reason to halt the parade to create a trace record... */
708   am->is_mp_safe[VL_API_TRACE_PLUGIN_MSG_IDS] = 1;
709   rpc_call_main_thread_cb_fn = vl_api_rpc_call_main_thread;
710   return 0;
711 }
712
713 VLIB_API_INIT_FUNCTION (rpc_api_hookup);
714
715 /*
716  * fd.io coding-style-patch-verification: ON
717  *
718  * Local Variables:
719  * eval: (c-set-style "gnu")
720  * End:
721  */