FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
vlib_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * vlib_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 */
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
53 #undef vl_printfun
54 
55 static inline void *
57  void *handle)
58 {
59  vl_print (handle, "vl_api_trace_plugin_msg_ids: %s first %u last %u\n",
60  a->plugin_name,
61  clib_host_to_net_u16 (a->first_msg_id),
62  clib_host_to_net_u16 (a->last_msg_id));
63  return handle;
64 }
65 
66 /* instantiate all the endian swap functions we know about */
67 #define vl_endianfun
69 #undef vl_endianfun
70 
71 u8 *
73 {
74  serialize_main_t _sm, *sm = &_sm;
75  hash_pair_t *hp;
77 
78  serialize_open_vector (sm, vector);
79 
80  /* serialize the count */
81  serialize_integer (sm, nmsg, sizeof (u32));
82 
83  /* *INDENT-OFF* */
85  ({
86  serialize_likely_small_unsigned_integer (sm, hp->value[0]);
87  serialize_cstring (sm, (char *) hp->key);
88  }));
89  /* *INDENT-ON* */
90 
91  return serialize_close_vector (sm);
92 }
93 
94 static void
96 {
99  uword *p;
100  api_main_t *am = &api_main;
101  vl_api_msg_range_t *rp;
102  u8 name[64];
103  u16 first_msg_id = ~0;
104  int rv = -7; /* VNET_API_ERROR_INVALID_VALUE */
105 
107  if (!regp)
108  return;
109 
110  if (am->msg_range_by_name == 0)
111  goto out;
112 
113  strncpy ((char *) name, (char *) mp->name, ARRAY_LEN (name) - 1);
114 
115  p = hash_get_mem (am->msg_range_by_name, name);
116  if (p == 0)
117  goto out;
118 
119  rp = vec_elt_at_index (am->msg_ranges, p[0]);
120  first_msg_id = rp->first_msg_id;
121  rv = 0;
122 
123 out:
124  rmp = vl_msg_api_alloc (sizeof (*rmp));
125  rmp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID_REPLY);
126  rmp->context = mp->context;
127  rmp->retval = ntohl (rv);
128  rmp->first_msg_id = ntohs (first_msg_id);
129  vl_api_send_msg (regp, (u8 *) rmp);
130 }
131 
132 void
134 {
135  api_main_t *am = &api_main;
138  u32 nmsg = vec_len (am->api_version_list);
139  int msg_size = sizeof (*rmp) + sizeof (rmp->api_versions[0]) * nmsg;
140  int i;
141 
143  if (!reg)
144  return;
145 
146  rmp = vl_msg_api_alloc (msg_size);
147  memset (rmp, 0, msg_size);
148  rmp->_vl_msg_id = ntohs (VL_API_API_VERSIONS_REPLY);
149 
150  /* fill in the message */
151  rmp->context = mp->context;
152  rmp->count = htonl (nmsg);
153 
154  for (i = 0; i < nmsg; ++i)
155  {
157  rmp->api_versions[i].major = htonl (vl->major);
158  rmp->api_versions[i].minor = htonl (vl->minor);
159  rmp->api_versions[i].patch = htonl (vl->patch);
160  strncpy ((char *) rmp->api_versions[i].name, vl->name, 64 - 1);
161  }
162 
163  vl_api_send_msg (reg, (u8 *) rmp);
164 }
165 
166 #define foreach_vlib_api_msg \
167 _(GET_FIRST_MSG_ID, get_first_msg_id) \
168 _(API_VERSIONS, api_versions)
169 
170 /*
171  * vl_api_init
172  */
173 static int
175 {
177  vl_msg_api_msg_config_t *c = &cfg;
178 
179  memset (c, 0, sizeof (*c));
180 
181 #define _(N,n) do { \
182  c->id = VL_API_##N; \
183  c->name = #n; \
184  c->handler = vl_api_##n##_t_handler; \
185  c->cleanup = vl_noop_handler; \
186  c->endian = vl_api_##n##_t_endian; \
187  c->print = vl_api_##n##_t_print; \
188  c->size = sizeof(vl_api_##n##_t); \
189  c->traced = 1; /* trace, so these msgs print */ \
190  c->replay = 0; /* don't replay client create/delete msgs */ \
191  c->message_bounce = 0; /* don't bounce this message */ \
192  vl_msg_api_config(c);} while (0);
193 
195 #undef _
196 
197  return 0;
198 }
199 
201 
202 /*
203  * Callback to send ourselves a plugin numbering-space trace msg
204  */
205 static void
206 send_one_plugin_msg_ids_msg (u8 * name, u16 first_msg_id, u16 last_msg_id)
207 {
209  api_main_t *am = &api_main;
211  svm_queue_t *q;
212 
213  mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
214  memset (mp, 0, sizeof (*mp));
215 
216  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_TRACE_PLUGIN_MSG_IDS);
217  strncpy ((char *) mp->plugin_name, (char *) name,
218  sizeof (mp->plugin_name) - 1);
219  mp->first_msg_id = clib_host_to_net_u16 (first_msg_id);
220  mp->last_msg_id = clib_host_to_net_u16 (last_msg_id);
221 
222  q = shmem_hdr->vl_input_queue;
223 
224  vl_msg_api_send_shmem (q, (u8 *) & mp);
225 }
226 
227 void
229 {
230  u8 *serialized_message_table;
231  api_main_t *am = &api_main;
232  u8 *chroot_file;
233  int fd, rv;
234 
235  /*
236  * Snapshoot the api message table.
237  */
238  if (strstr ((char *) am->save_msg_table_filename, "..")
239  || index ((char *) am->save_msg_table_filename, '/'))
240  {
241  clib_warning ("illegal save-message-table filename '%s'",
243  return;
244  }
245 
246  chroot_file = format (0, "/tmp/%s%c", am->save_msg_table_filename, 0);
247 
248  fd = creat ((char *) chroot_file, 0644);
249 
250  if (fd < 0)
251  {
252  clib_unix_warning ("creat");
253  return;
254  }
255 
256  serialized_message_table = vl_api_serialize_message_table (am, 0);
257 
258  rv = write (fd, serialized_message_table,
259  vec_len (serialized_message_table));
260 
261  if (rv != vec_len (serialized_message_table))
262  clib_unix_warning ("write");
263 
264  rv = close (fd);
265  if (rv < 0)
266  clib_unix_warning ("close");
267 
268  vec_free (chroot_file);
269  vec_free (serialized_message_table);
270 }
271 
272 static uword
274  vlib_frame_t * f)
275 {
276  int private_segment_rotor = 0, i, rv;
278  vl_shmem_hdr_t *shm;
279  svm_queue_t *q;
280  clib_error_t *e;
281  api_main_t *am = &api_main;
282  f64 dead_client_scan_time;
283  f64 sleep_time, start_time;
284  f64 vector_rate;
285  clib_error_t *error;
286  uword event_type;
287  uword *event_data = 0;
288  f64 now;
289 
290  if ((error = vl_sock_api_init (vm)))
291  {
292  clib_error_report (error);
293  clib_warning ("socksvr_api_init failed, quitting...");
294  return 0;
295  }
296 
297  if ((rv = vlib_api_init ()) < 0)
298  {
299  clib_warning ("vlib_api_init returned %d, quitting...", rv);
300  return 0;
301  }
302 
303  shm = am->shmem_hdr;
304  q = shm->vl_input_queue;
305 
307  (vm, vm->api_init_function_registrations, 1 /* call_once */ );
308  if (e)
309  clib_error_report (e);
310 
311  sleep_time = 10.0;
312  dead_client_scan_time = vlib_time_now (vm) + 10.0;
313 
314  /*
315  * Send plugin message range messages for each plugin we loaded
316  */
317  for (i = 0; i < vec_len (am->msg_ranges); i++)
318  {
319  vl_api_msg_range_t *rp = am->msg_ranges + i;
321  rp->last_msg_id);
322  }
323 
324  /*
325  * Save the api message table snapshot, if configured
326  */
327  if (am->save_msg_table_filename)
329 
330  /* $$$ pay attention to frame size, control CPU usage */
331  while (1)
332  {
333  /*
334  * There's a reason for checking the queue before
335  * sleeping. If the vlib application crashes, it's entirely
336  * possible for a client to enqueue a connect request
337  * during the process restart interval.
338  *
339  * Unless some force of physics causes the new incarnation
340  * of the application to process the request, the client will
341  * sit and wait for Godot...
342  */
343  vector_rate = vlib_last_vector_length_per_node (vm);
344  start_time = vlib_time_now (vm);
345  while (1)
346  {
347  if (vl_mem_api_handle_msg_main (vm, node))
348  {
349  vm->api_queue_nonempty = 0;
350  VL_MEM_API_LOG_Q_LEN ("q-underflow: len %d", 0);
351  sleep_time = 20.0;
352  break;
353  }
354 
355  /* Allow no more than 10us without a pause */
356  if (vlib_time_now (vm) > start_time + 10e-6)
357  {
358  int index = SLEEP_400_US;
359  if (vector_rate > 40.0)
360  sleep_time = 400e-6;
361  else if (vector_rate > 20.0)
362  {
363  index = SLEEP_200_US;
364  sleep_time = 200e-6;
365  }
366  else if (vector_rate >= 1.0)
367  {
368  index = SLEEP_100_US;
369  sleep_time = 100e-6;
370  }
371  else
372  {
373  index = SLEEP_10_US;
374  sleep_time = 10e-6;
375  }
376  vector_rate_histogram[index] += 1;
377  break;
378  }
379  }
380 
381  /*
382  * see if we have any private api shared-memory segments
383  * If so, push required context variables, and process
384  * a message.
385  */
386  if (PREDICT_FALSE (vec_len (am->vlib_private_rps)))
387  {
388  vl_mem_api_handle_msg_private (vm, node, private_segment_rotor++);
389  if (private_segment_rotor >= vec_len (am->vlib_private_rps))
390  private_segment_rotor = 0;
391  }
392 
393  vlib_process_wait_for_event_or_clock (vm, sleep_time);
394  vec_reset_length (event_data);
395  event_type = vlib_process_get_events (vm, &event_data);
396  now = vlib_time_now (vm);
397 
398  switch (event_type)
399  {
400  case QUEUE_SIGNAL_EVENT:
401  vm->queue_signal_pending = 0;
402  VL_MEM_API_LOG_Q_LEN ("q-awake: len %d", q->cursize);
403 
404  break;
405  case SOCKET_READ_EVENT:
406  for (i = 0; i < vec_len (event_data); i++)
407  {
408  a = pool_elt_at_index (socket_main.process_args, event_data[i]);
410  (i8 *) a->data);
411  vec_free (a->data);
413  }
414  break;
415 
416  /* Timeout... */
417  case -1:
418  break;
419 
420  default:
421  clib_warning ("unknown event type %d", event_type);
422  break;
423  }
424 
425  if (now > dead_client_scan_time)
426  {
427  vl_mem_api_dead_client_scan (am, shm, now);
428  dead_client_scan_time = vlib_time_now (vm) + 10.0;
429  }
430  }
431 
432  return 0;
433 }
434 /* *INDENT-OFF* */
436 {
437  .function = vl_api_clnt_process,
438  .type = VLIB_NODE_TYPE_PROCESS,
439  .name = "api-rx-from-ring",
440  .state = VLIB_NODE_STATE_DISABLED,
441 };
442 /* *INDENT-ON* */
443 
444 void
446 {
448  (enable
449  ? VLIB_NODE_STATE_POLLING
450  : VLIB_NODE_STATE_DISABLED));
451 }
452 
453 static uword
455  vlib_node_runtime_t * node, vlib_frame_t * frame)
456 {
457  uword n_packets = frame->n_vectors;
458  uword n_left_from;
459  u32 *from;
460  static u8 *long_msg;
461 
462  vec_validate (long_msg, 4095);
463  n_left_from = frame->n_vectors;
464  from = vlib_frame_args (frame);
465 
466  while (n_left_from > 0)
467  {
468  u32 bi0;
469  vlib_buffer_t *b0;
470  void *msg;
471  uword msg_len;
472 
473  bi0 = from[0];
474  b0 = vlib_get_buffer (vm, bi0);
475  from += 1;
476  n_left_from -= 1;
477 
478  msg = b0->data + b0->current_data;
479  msg_len = b0->current_length;
480  if (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
481  {
482  ASSERT (long_msg != 0);
483  _vec_len (long_msg) = 0;
484  vec_add (long_msg, msg, msg_len);
485  while (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
486  {
487  b0 = vlib_get_buffer (vm, b0->next_buffer);
488  msg = b0->data + b0->current_data;
489  msg_len = b0->current_length;
490  vec_add (long_msg, msg, msg_len);
491  }
492  msg = long_msg;
493  }
495  }
496 
497  /* Free what we've been given. */
498  vlib_buffer_free (vm, vlib_frame_args (frame), n_packets);
499 
500  return n_packets;
501 }
502 
503 /* *INDENT-OFF* */
505  .function = api_rx_from_node,
506  .type = VLIB_NODE_TYPE_INTERNAL,
507  .vector_size = 4,
508  .name = "api-rx-from-node",
509 };
510 /* *INDENT-ON* */
511 
512 static void
514 {
515  vl_api_rpc_call_reply_t *rmp;
516  int (*fp) (void *);
517  i32 rv = 0;
519 
520  if (mp->function == 0)
521  {
522  rv = -1;
523  clib_warning ("rpc NULL function pointer");
524  }
525 
526  else
527  {
528  if (mp->need_barrier_sync)
530 
531  fp = uword_to_pointer (mp->function, int (*)(void *));
532  rv = fp (mp->data);
533 
534  if (mp->need_barrier_sync)
536  }
537 
538  if (mp->send_reply)
539  {
541  if (q)
542  {
543  rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
544  rmp->_vl_msg_id = ntohs (VL_API_RPC_CALL_REPLY);
545  rmp->context = mp->context;
546  rmp->retval = rv;
547  vl_msg_api_send_shmem (q, (u8 *) & rmp);
548  }
549  }
550  if (mp->multicast)
551  {
552  clib_warning ("multicast not yet implemented...");
553  }
554 }
555 
556 static void
557 vl_api_rpc_call_reply_t_handler (vl_api_rpc_call_reply_t * mp)
558 {
559  clib_warning ("unimplemented");
560 }
561 
562 void
564 {
565  api_main_t *am = &api_main;
567  svm_queue_t *q;
568  int i;
569 
570  /*
571  * Use the "normal" control-plane mechanism for the main thread.
572  * Well, almost. if the main input queue is full, we cannot
573  * block. Otherwise, we can expect a barrier sync timeout.
574  */
575  q = shmem_hdr->vl_input_queue;
576 
577  for (i = 0; i < vec_len (vm->pending_rpc_requests); i++)
578  {
579  while (pthread_mutex_trylock (&q->mutex))
581 
582  while (PREDICT_FALSE (svm_queue_is_full (q)))
583  {
584  pthread_mutex_unlock (&q->mutex);
586  while (pthread_mutex_trylock (&q->mutex))
588  }
589 
591 
592  pthread_mutex_unlock (&q->mutex);
593  }
594  _vec_len (vm->pending_rpc_requests) = 0;
595 }
596 
597 always_inline void
598 vl_api_rpc_call_main_thread_inline (void *fp, u8 * data, u32 data_length,
599  u8 force_rpc)
600 {
601  vl_api_rpc_call_t *mp;
603 
604  /* Main thread and not a forced RPC: call the function directly */
605  if ((force_rpc == 0) && (vlib_get_thread_index () == 0))
606  {
607  void (*call_fp) (void *);
608 
610 
611  call_fp = fp;
612  call_fp (data);
613 
615  return;
616  }
617 
618  /* Otherwise, actually do an RPC */
619  mp = vl_msg_api_alloc_as_if_client (sizeof (*mp) + data_length);
620 
621  memset (mp, 0, sizeof (*mp));
622  clib_memcpy (mp->data, data, data_length);
623  mp->_vl_msg_id = ntohs (VL_API_RPC_CALL);
624  mp->function = pointer_to_uword (fp);
625  mp->need_barrier_sync = 1;
626 
627  vec_add1 (vm->pending_rpc_requests, (uword) mp);
628 }
629 
630 /*
631  * Check if called from worker threads.
632  * If so, make rpc call of fp through shmem.
633  * Otherwise, call fp directly
634  */
635 void
636 vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length)
637 {
638  vl_api_rpc_call_main_thread_inline (fp, data, data_length, /*force_rpc */
639  0);
640 }
641 
642 /*
643  * Always make rpc call of fp through shmem, useful for calling from threads
644  * not setup as worker threads, such as DPDK callback thread
645  */
646 void
647 vl_api_force_rpc_call_main_thread (void *fp, u8 * data, u32 data_length)
648 {
649  vl_api_rpc_call_main_thread_inline (fp, data, data_length, /*force_rpc */
650  1);
651 }
652 
653 static void
655 {
656  api_main_t *am = &api_main;
657  vl_api_msg_range_t *rp;
658  uword *p;
659 
660  /* Noop (except for tracing) during normal operation */
661  if (am->replay_in_progress == 0)
662  return;
663 
665  if (p == 0)
666  {
667  clib_warning ("WARNING: traced plugin '%s' not in current image",
668  mp->plugin_name);
669  return;
670  }
671 
672  rp = vec_elt_at_index (am->msg_ranges, p[0]);
673  if (rp->first_msg_id != clib_net_to_host_u16 (mp->first_msg_id))
674  {
675  clib_warning ("WARNING: traced plugin '%s' first message id %d not %d",
676  mp->plugin_name, clib_net_to_host_u16 (mp->first_msg_id),
677  rp->first_msg_id);
678  }
679 
680  if (rp->last_msg_id != clib_net_to_host_u16 (mp->last_msg_id))
681  {
682  clib_warning ("WARNING: traced plugin '%s' last message id %d not %d",
683  mp->plugin_name, clib_net_to_host_u16 (mp->last_msg_id),
684  rp->last_msg_id);
685  }
686 }
687 
688 #define foreach_rpc_api_msg \
689 _(RPC_CALL,rpc_call) \
690 _(RPC_CALL_REPLY,rpc_call_reply)
691 
692 #define foreach_plugin_trace_msg \
693 _(TRACE_PLUGIN_MSG_IDS,trace_plugin_msg_ids)
694 
695 /*
696  * Set the rpc callback at our earliest possible convenience.
697  * This avoids ordering issues between thread_init() -> start_workers and
698  * an init function which we could define here. If we ever intend to use
699  * vlib all by itself, we can't create a link-time dependency on
700  * an init function here and a typical "call foo_init first"
701  * guitar lick.
702  */
703 
704 extern void *rpc_call_main_thread_cb_fn;
705 
706 static clib_error_t *
708 {
709  api_main_t *am = &api_main;
710 #define _(N,n) \
711  vl_msg_api_set_handlers(VL_API_##N, #n, \
712  vl_api_##n##_t_handler, \
713  vl_noop_handler, \
714  vl_noop_handler, \
715  vl_api_##n##_t_print, \
716  sizeof(vl_api_##n##_t), 0 /* do not trace */);
718 #undef _
719 
720 #define _(N,n) \
721  vl_msg_api_set_handlers(VL_API_##N, #n, \
722  vl_api_##n##_t_handler, \
723  vl_noop_handler, \
724  vl_noop_handler, \
725  vl_api_##n##_t_print, \
726  sizeof(vl_api_##n##_t), 1 /* do trace */);
728 #undef _
729 
730  /* No reason to halt the parade to create a trace record... */
731  am->is_mp_safe[VL_API_TRACE_PLUGIN_MSG_IDS] = 1;
733  return 0;
734 }
735 
737 
738 /*
739  * fd.io coding-style-patch-verification: ON
740  *
741  * Local Variables:
742  * eval: (c-set-style "gnu")
743  * End:
744  */
#define foreach_vlib_api_msg
Definition: vlib_api.c:166
int vl_mem_api_handle_msg_private(vlib_main_t *vm, vlib_node_runtime_t *node, u32 reg_index)
Definition: memory_api.c:702
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:437
Message range (belonging to a plugin)
Definition: api_common.h:110
vl_api_registration_t * regp
Definition: socket_api.h:30
int vl_mem_api_handle_msg_main(vlib_main_t *vm, vlib_node_runtime_t *node)
Definition: memory_api.c:694
u32 vl(void *p)
Definition: threads.c:30
uword * pending_rpc_requests
Definition: main.h:215
static void send_one_plugin_msg_ids_msg(u8 *name, u16 first_msg_id, u16 last_msg_id)
Definition: vlib_api.c:206
VLIB_API_INIT_FUNCTION(rpc_api_hookup)
clib_error_t * vl_sock_api_init(vlib_main_t *vm)
Definition: socket_api.c:641
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
Definition: api_shared.c:568
static void vl_api_rpc_call_main_thread_inline(void *fp, u8 *data, u32 data_length, u8 force_rpc)
Definition: vlib_api.c:598
void vl_api_save_msg_table(void)
Definition: vlib_api.c:228
u8 * name
name of the plugin
Definition: api_common.h:112
int svm_queue_is_full(svm_queue_t *q)
Definition: queue.c:115
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:699
static void vl_api_get_first_msg_id_t_handler(vl_api_get_first_msg_id_t *mp)
Definition: vlib_api.c:95
a
Definition: bitmap.h:537
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:534
static void * vl_api_trace_plugin_msg_ids_t_print(vl_api_trace_plugin_msg_ids_t *a, void *handle)
Definition: vlib_api.c:56
unsigned long u64
Definition: types.h:89
Fixed length block allocator.
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:225
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
vl_socket_args_for_process_t * process_args
Definition: socket_api.h:58
Message configuration definition.
Definition: api_common.h:118
socket_main_t socket_main
Definition: socket_api.c:48
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
int i
api_version_t * api_version_list
api version list
Definition: api_common.h:327
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
void vl_socket_process_api_msg(clib_file_t *uf, vl_api_registration_t *rp, i8 *input_v)
Definition: socket_api.c:144
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
#define VL_MEM_API_LOG_Q_LEN(fmt, qlen)
Definition: memory_api.h:68
vlib_node_registration_t vl_api_clnt_node
(constructor) VLIB_REGISTER_NODE (vl_api_clnt_node)
Definition: vlib_api.c:435
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:212
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
Definition: vec.h:600
static f64 vlib_last_vector_length_per_node(vlib_main_t *vm)
Definition: main.h:316
static void vlib_worker_thread_barrier_check(void)
Definition: threads.h:399
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:104
_vlib_init_function_list_elt_t * api_init_function_registrations
Definition: main.h:183
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:542
#define always_inline
Definition: clib.h:92
static clib_error_t * rpc_api_hookup(vlib_main_t *vm)
Definition: vlib_api.c:707
void vl_mem_api_dead_client_scan(api_main_t *am, vl_shmem_hdr_t *shm, f64 now)
Definition: memory_api.c:573
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
int replay_in_progress
Replay in progress?
Definition: api_common.h:336
clib_error_t * vlib_call_init_exit_functions(vlib_main_t *vm, _vlib_init_function_list_elt_t *head, int call_once)
Definition: init.c:43
void vl_api_send_pending_rpc_requests(vlib_main_t *vm)
Definition: vlib_api.c:563
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
Definition: api_common.h:264
unsigned int u32
Definition: types.h:88
char name[64]
Definition: api_common.h:197
static uword vl_api_clnt_process(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
Definition: vlib_api.c:273
vl_shmem_hdr_t * shmem_hdr
u16 last_msg_id
last assigned message ID
Definition: api_common.h:114
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:108
void * rpc_call_main_thread_cb_fn
Definition: threads.c:1820
unsigned short u16
Definition: types.h:57
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:273
svm_region_t ** vlib_private_rps
Vector of all mapped shared-VM segments.
Definition: api_common.h:260
#define PREDICT_FALSE(x)
Definition: clib.h:105
signed char i8
Definition: types.h:45
volatile u32 queue_signal_pending
Definition: main.h:188
vl_api_module_version_t api_versions[count]
Definition: memclnt.api:131
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:201
static void vl_api_rpc_call_reply_t_handler(vl_api_rpc_call_reply_t *mp)
Definition: vlib_api.c:557
An API client registration, only in vpp/vlib.
Definition: api_common.h:44
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:153
svmdb_client_t * c
u16 n_vectors
Definition: node.h:380
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:221
vlib_main_t * vm
Definition: buffer.c:294
static vlib_node_registration_t api_rx_from_node_node
(constructor) VLIB_REGISTER_NODE (api_rx_from_node_node)
Definition: vlib_api.c:504
void serialize_open_vector(serialize_main_t *m, u8 *vector)
Definition: serialize.c:909
svm_queue_t * vl_api_client_index_to_input_queue(u32 index)
Definition: memory_api.c:754
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
u8 * vl_api_serialize_message_table(api_main_t *am, u8 *vector)
Definition: vlib_api.c:72
vl_api_msg_range_t * msg_ranges
vector of message ranges
Definition: api_common.h:279
#define clib_warning(format, args...)
Definition: error.h:59
#define vl_print(handle,...)
Definition: vlib_api.c:50
#define clib_memcpy(a, b, c)
Definition: string.h:75
u64 vector_rate_histogram[SLEEP_N_BUCKETS]
Definition: vlib_api.c:200
static void vl_api_rpc_call_t_handler(vl_api_rpc_call_t *mp)
Definition: vlib_api.c:513
static void serialize_integer(serialize_main_t *m, u64 x, u32 n_bytes)
Definition: serialize.h:185
#define ARRAY_LEN(x)
Definition: clib.h:59
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
svm_queue_t * vl_input_queue
Definition: memory_shared.h:84
u8 * save_msg_table_filename
Dump (msg-name, crc) snapshot here at startup.
Definition: api_common.h:339
signed int i32
Definition: types.h:81
#define uword_to_pointer(u, type)
Definition: types.h:136
#define foreach_rpc_api_msg
Definition: vlib_api.c:688
#define ASSERT(truth)
static uword hash_elts(void *v)
Definition: hash.h:118
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:126
#define clib_error_report(e)
Definition: error.h:113
static void * vlib_frame_args(vlib_frame_t *f)
Get pointer to frame scalar data.
Definition: node_funcs.h:284
void vl_api_api_versions_t_handler(vl_api_api_versions_t *mp)
Definition: vlib_api.c:133
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
Definition: node_funcs.h:147
static uword pointer_to_uword(const void *p)
Definition: types.h:131
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
#define foreach_plugin_trace_msg
Definition: vlib_api.c:692
u16 first_msg_id
first assigned message ID
Definition: api_common.h:113
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:636
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
Definition: hash.h:373
u64 uword
Definition: types.h:112
#define clib_unix_warning(format, args...)
Definition: error.h:68
volatile u32 api_queue_nonempty
Definition: main.h:189
struct _svm_queue svm_queue_t
static int vlib_api_init(void)
Definition: vlib_api.c:174
#define hash_get_mem(h, key)
Definition: hash.h:269
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1508
u8 * is_mp_safe
Message is mp safe vector.
Definition: api_common.h:224
void vl_api_force_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:647
u8 data[0]
Packet data.
Definition: buffer.h:172
static void vl_api_trace_plugin_msg_ids_t_handler(vl_api_trace_plugin_msg_ids_t *mp)
Definition: vlib_api.c:654
static uword api_rx_from_node(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: vlib_api.c:454
void * vl_msg_api_alloc_as_if_client(int nbytes)
void * serialize_close_vector(serialize_main_t *m)
Definition: serialize.c:919
uword * msg_index_by_name_and_crc
client message index hash table
Definition: api_common.h:324
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:111
uword * msg_range_by_name
Message range by name hash.
Definition: api_common.h:276
void vl_mem_api_enable_disable(vlib_main_t *vm, int enable)
Definition: vlib_api.c:445
api_main_t api_main
Definition: api_shared.c:35
void vl_msg_api_send_shmem_nolock(svm_queue_t *q, u8 *elem)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".