FD.io VPP  v19.01.3-6-g70449b9b9
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  strncpy ((char *) name, (char *) mp->name, ARRAY_LEN (name));
113  name[ARRAY_LEN (name) - 1] = '\0';
114  p = hash_get_mem (am->msg_range_by_name, name);
115  if (p == 0)
116  goto out;
117 
118  rp = vec_elt_at_index (am->msg_ranges, p[0]);
119  first_msg_id = rp->first_msg_id;
120  rv = 0;
121 
122 out:
123  rmp = vl_msg_api_alloc (sizeof (*rmp));
124  rmp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID_REPLY);
125  rmp->context = mp->context;
126  rmp->retval = ntohl (rv);
127  rmp->first_msg_id = ntohs (first_msg_id);
128  vl_api_send_msg (regp, (u8 *) rmp);
129 }
130 
131 void
133 {
134  api_main_t *am = &api_main;
137  u32 nmsg = vec_len (am->api_version_list);
138  int msg_size = sizeof (*rmp) + sizeof (rmp->api_versions[0]) * nmsg;
139  int i;
140 
142  if (!reg)
143  return;
144 
145  rmp = vl_msg_api_alloc (msg_size);
146  clib_memset (rmp, 0, msg_size);
147  rmp->_vl_msg_id = ntohs (VL_API_API_VERSIONS_REPLY);
148 
149  /* fill in the message */
150  rmp->context = mp->context;
151  rmp->count = htonl (nmsg);
152 
153  for (i = 0; i < nmsg; ++i)
154  {
156  rmp->api_versions[i].major = htonl (vl->major);
157  rmp->api_versions[i].minor = htonl (vl->minor);
158  rmp->api_versions[i].patch = htonl (vl->patch);
159  strncpy ((char *) rmp->api_versions[i].name, vl->name,
160  ARRAY_LEN (rmp->api_versions[i].name));
161  rmp->api_versions[i].name[ARRAY_LEN (rmp->api_versions[i].name) - 1] =
162  '\0';
163  }
164 
165  vl_api_send_msg (reg, (u8 *) rmp);
166 }
167 
168 #define foreach_vlib_api_msg \
169 _(GET_FIRST_MSG_ID, get_first_msg_id) \
170 _(API_VERSIONS, api_versions)
171 
172 /*
173  * vl_api_init
174  */
175 static int
177 {
179  vl_msg_api_msg_config_t *c = &cfg;
180 
181  clib_memset (c, 0, sizeof (*c));
182 
183 #define _(N,n) do { \
184  c->id = VL_API_##N; \
185  c->name = #n; \
186  c->handler = vl_api_##n##_t_handler; \
187  c->cleanup = vl_noop_handler; \
188  c->endian = vl_api_##n##_t_endian; \
189  c->print = vl_api_##n##_t_print; \
190  c->size = sizeof(vl_api_##n##_t); \
191  c->traced = 1; /* trace, so these msgs print */ \
192  c->replay = 0; /* don't replay client create/delete msgs */ \
193  c->message_bounce = 0; /* don't bounce this message */ \
194  vl_msg_api_config(c);} while (0);
195 
197 #undef _
198 
199  return 0;
200 }
201 
203 
204 /*
205  * Callback to send ourselves a plugin numbering-space trace msg
206  */
207 static void
208 send_one_plugin_msg_ids_msg (u8 * name, u16 first_msg_id, u16 last_msg_id)
209 {
211  api_main_t *am = &api_main;
212  vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
213  svm_queue_t *q;
214 
215  mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
216  clib_memset (mp, 0, sizeof (*mp));
217 
218  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_TRACE_PLUGIN_MSG_IDS);
219  strncpy ((char *) mp->plugin_name, (char *) name,
220  sizeof (mp->plugin_name) - 1);
221  mp->first_msg_id = clib_host_to_net_u16 (first_msg_id);
222  mp->last_msg_id = clib_host_to_net_u16 (last_msg_id);
223 
224  q = shmem_hdr->vl_input_queue;
225 
226  vl_msg_api_send_shmem (q, (u8 *) & mp);
227 }
228 
229 void
231 {
232  u8 *serialized_message_table;
233  api_main_t *am = &api_main;
234  u8 *chroot_file;
235  int fd, rv;
236 
237  /*
238  * Snapshoot the api message table.
239  */
240  if (strstr ((char *) am->save_msg_table_filename, "..")
241  || index ((char *) am->save_msg_table_filename, '/'))
242  {
243  clib_warning ("illegal save-message-table filename '%s'",
245  return;
246  }
247 
248  chroot_file = format (0, "/tmp/%s%c", am->save_msg_table_filename, 0);
249 
250  fd = creat ((char *) chroot_file, 0644);
251 
252  if (fd < 0)
253  {
254  clib_unix_warning ("creat");
255  return;
256  }
257 
258  serialized_message_table = vl_api_serialize_message_table (am, 0);
259 
260  rv = write (fd, serialized_message_table,
261  vec_len (serialized_message_table));
262 
263  if (rv != vec_len (serialized_message_table))
264  clib_unix_warning ("write");
265 
266  rv = close (fd);
267  if (rv < 0)
268  clib_unix_warning ("close");
269 
270  vec_free (chroot_file);
271  vec_free (serialized_message_table);
272 }
273 
274 static uword
276  vlib_frame_t * f)
277 {
278  int private_segment_rotor = 0, i, rv;
280  vl_shmem_hdr_t *shm;
281  svm_queue_t *q;
282  clib_error_t *e;
283  api_main_t *am = &api_main;
284  f64 dead_client_scan_time;
285  f64 sleep_time, start_time;
286  f64 vector_rate;
287  clib_error_t *error;
288  uword event_type;
289  uword *event_data = 0;
290  f64 now;
291 
292  if ((error = vl_sock_api_init (vm)))
293  {
294  clib_error_report (error);
295  clib_warning ("socksvr_api_init failed, quitting...");
296  return 0;
297  }
298 
299  if ((rv = vlib_api_init ()) < 0)
300  {
301  clib_warning ("vlib_api_init returned %d, quitting...", rv);
302  return 0;
303  }
304 
305  shm = am->shmem_hdr;
306  q = shm->vl_input_queue;
307 
309  (vm, vm->api_init_function_registrations, 1 /* call_once */ );
310  if (e)
311  clib_error_report (e);
312 
313  sleep_time = 10.0;
314  dead_client_scan_time = vlib_time_now (vm) + 10.0;
315 
316  /*
317  * Send plugin message range messages for each plugin we loaded
318  */
319  for (i = 0; i < vec_len (am->msg_ranges); i++)
320  {
321  vl_api_msg_range_t *rp = am->msg_ranges + i;
323  rp->last_msg_id);
324  }
325 
326  /*
327  * Save the api message table snapshot, if configured
328  */
329  if (am->save_msg_table_filename)
331 
332  /* $$$ pay attention to frame size, control CPU usage */
333  while (1)
334  {
335  /*
336  * There's a reason for checking the queue before
337  * sleeping. If the vlib application crashes, it's entirely
338  * possible for a client to enqueue a connect request
339  * during the process restart interval.
340  *
341  * Unless some force of physics causes the new incarnation
342  * of the application to process the request, the client will
343  * sit and wait for Godot...
344  */
345  vector_rate = vlib_last_vector_length_per_node (vm);
346  start_time = vlib_time_now (vm);
347  while (1)
348  {
349  if (vl_mem_api_handle_rpc (vm, node)
350  || vl_mem_api_handle_msg_main (vm, node))
351  {
352  vm->api_queue_nonempty = 0;
353  VL_MEM_API_LOG_Q_LEN ("q-underflow: len %d", 0);
354  sleep_time = 20.0;
355  break;
356  }
357 
358  /* Allow no more than 10us without a pause */
359  if (vlib_time_now (vm) > start_time + 10e-6)
360  {
361  int index = SLEEP_400_US;
362  if (vector_rate > 40.0)
363  sleep_time = 400e-6;
364  else if (vector_rate > 20.0)
365  {
366  index = SLEEP_200_US;
367  sleep_time = 200e-6;
368  }
369  else if (vector_rate >= 1.0)
370  {
371  index = SLEEP_100_US;
372  sleep_time = 100e-6;
373  }
374  else
375  {
376  index = SLEEP_10_US;
377  sleep_time = 10e-6;
378  }
379  vector_rate_histogram[index] += 1;
380  break;
381  }
382  }
383 
384  /*
385  * see if we have any private api shared-memory segments
386  * If so, push required context variables, and process
387  * a message.
388  */
389  if (PREDICT_FALSE (vec_len (am->vlib_private_rps)))
390  {
391  if (private_segment_rotor >= vec_len (am->vlib_private_rps))
392  private_segment_rotor = 0;
393  vl_mem_api_handle_msg_private (vm, node, private_segment_rotor++);
394  }
395 
396  vlib_process_wait_for_event_or_clock (vm, sleep_time);
397  vec_reset_length (event_data);
398  event_type = vlib_process_get_events (vm, &event_data);
399  now = vlib_time_now (vm);
400 
401  switch (event_type)
402  {
403  case QUEUE_SIGNAL_EVENT:
404  vm->queue_signal_pending = 0;
405  VL_MEM_API_LOG_Q_LEN ("q-awake: len %d", q->cursize);
406 
407  break;
408  case SOCKET_READ_EVENT:
409  for (i = 0; i < vec_len (event_data); i++)
410  {
411  a = pool_elt_at_index (socket_main.process_args, event_data[i]);
413  (i8 *) a->data);
414  vec_free (a->data);
416  }
417  break;
418 
419  /* Timeout... */
420  case -1:
421  break;
422 
423  default:
424  clib_warning ("unknown event type %d", event_type);
425  break;
426  }
427 
428  if (now > dead_client_scan_time)
429  {
430  vl_mem_api_dead_client_scan (am, shm, now);
431  dead_client_scan_time = vlib_time_now (vm) + 10.0;
432  }
433  }
434 
435  return 0;
436 }
437 /* *INDENT-OFF* */
439 {
440  .function = vl_api_clnt_process,
441  .type = VLIB_NODE_TYPE_PROCESS,
442  .name = "api-rx-from-ring",
443  .state = VLIB_NODE_STATE_DISABLED,
444 };
445 /* *INDENT-ON* */
446 
447 void
449 {
451  (enable
452  ? VLIB_NODE_STATE_POLLING
453  : VLIB_NODE_STATE_DISABLED));
454 }
455 
456 static uword
458  vlib_node_runtime_t * node, vlib_frame_t * frame)
459 {
460  uword n_packets = frame->n_vectors;
461  uword n_left_from;
462  u32 *from;
463  static u8 *long_msg;
464 
465  vec_validate (long_msg, 4095);
466  n_left_from = frame->n_vectors;
467  from = vlib_frame_vector_args (frame);
468 
469  while (n_left_from > 0)
470  {
471  u32 bi0;
472  vlib_buffer_t *b0;
473  void *msg;
474  uword msg_len;
475 
476  bi0 = from[0];
477  b0 = vlib_get_buffer (vm, bi0);
478  from += 1;
479  n_left_from -= 1;
480 
481  msg = b0->data + b0->current_data;
482  msg_len = b0->current_length;
483  if (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
484  {
485  ASSERT (long_msg != 0);
486  _vec_len (long_msg) = 0;
487  vec_add (long_msg, msg, msg_len);
488  while (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
489  {
490  b0 = vlib_get_buffer (vm, b0->next_buffer);
491  msg = b0->data + b0->current_data;
492  msg_len = b0->current_length;
493  vec_add (long_msg, msg, msg_len);
494  }
495  msg = long_msg;
496  }
498  }
499 
500  /* Free what we've been given. */
501  vlib_buffer_free (vm, vlib_frame_vector_args (frame), n_packets);
502 
503  return n_packets;
504 }
505 
506 /* *INDENT-OFF* */
508  .function = api_rx_from_node,
509  .type = VLIB_NODE_TYPE_INTERNAL,
510  .vector_size = 4,
511  .name = "api-rx-from-node",
512 };
513 /* *INDENT-ON* */
514 
515 static void
517 {
518  vl_api_rpc_call_reply_t *rmp;
519  int (*fp) (void *);
520  i32 rv = 0;
522 
523  if (mp->function == 0)
524  {
525  rv = -1;
526  clib_warning ("rpc NULL function pointer");
527  }
528 
529  else
530  {
531  if (mp->need_barrier_sync)
533 
534  fp = uword_to_pointer (mp->function, int (*)(void *));
535  rv = fp (mp->data);
536 
537  if (mp->need_barrier_sync)
539  }
540 
541  if (mp->send_reply)
542  {
544  if (q)
545  {
546  rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
547  rmp->_vl_msg_id = ntohs (VL_API_RPC_CALL_REPLY);
548  rmp->context = mp->context;
549  rmp->retval = rv;
550  vl_msg_api_send_shmem (q, (u8 *) & rmp);
551  }
552  }
553  if (mp->multicast)
554  {
555  clib_warning ("multicast not yet implemented...");
556  }
557 }
558 
559 static void
560 vl_api_rpc_call_reply_t_handler (vl_api_rpc_call_reply_t * mp)
561 {
562  clib_warning ("unimplemented");
563 }
564 
565 void
567 {
568  vlib_main_t *vm_global = &vlib_global_main;
569 
570  ASSERT (vm != vm_global);
571 
576 }
577 
578 always_inline void
579 vl_api_rpc_call_main_thread_inline (void *fp, u8 * data, u32 data_length,
580  u8 force_rpc)
581 {
582  vl_api_rpc_call_t *mp;
583  vlib_main_t *vm_global = &vlib_global_main;
585 
586  /* Main thread and not a forced RPC: call the function directly */
587  if ((force_rpc == 0) && (vlib_get_thread_index () == 0))
588  {
589  void (*call_fp) (void *);
590 
592 
593  call_fp = fp;
594  call_fp (data);
595 
597  return;
598  }
599 
600  /* Otherwise, actually do an RPC */
601  mp = vl_msg_api_alloc_as_if_client (sizeof (*mp) + data_length);
602 
603  clib_memset (mp, 0, sizeof (*mp));
604  clib_memcpy_fast (mp->data, data, data_length);
605  mp->_vl_msg_id = ntohs (VL_API_RPC_CALL);
606  mp->function = pointer_to_uword (fp);
607  mp->need_barrier_sync = 1;
608 
609  /* Add to the pending vector. Thread 0 requires locking. */
610  if (vm == vm_global)
612  vec_add1 (vm->pending_rpc_requests, (uword) mp);
613  if (vm == vm_global)
615 }
616 
617 /*
618  * Check if called from worker threads.
619  * If so, make rpc call of fp through shmem.
620  * Otherwise, call fp directly
621  */
622 void
623 vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length)
624 {
625  vl_api_rpc_call_main_thread_inline (fp, data, data_length, /*force_rpc */
626  0);
627 }
628 
629 /*
630  * Always make rpc call of fp through shmem, useful for calling from threads
631  * not setup as worker threads, such as DPDK callback thread
632  */
633 void
634 vl_api_force_rpc_call_main_thread (void *fp, u8 * data, u32 data_length)
635 {
636  vl_api_rpc_call_main_thread_inline (fp, data, data_length, /*force_rpc */
637  1);
638 }
639 
640 static void
642 {
643  api_main_t *am = &api_main;
644  vl_api_msg_range_t *rp;
645  uword *p;
646 
647  /* Noop (except for tracing) during normal operation */
648  if (am->replay_in_progress == 0)
649  return;
650 
652  if (p == 0)
653  {
654  clib_warning ("WARNING: traced plugin '%s' not in current image",
655  mp->plugin_name);
656  return;
657  }
658 
659  rp = vec_elt_at_index (am->msg_ranges, p[0]);
660  if (rp->first_msg_id != clib_net_to_host_u16 (mp->first_msg_id))
661  {
662  clib_warning ("WARNING: traced plugin '%s' first message id %d not %d",
663  mp->plugin_name, clib_net_to_host_u16 (mp->first_msg_id),
664  rp->first_msg_id);
665  }
666 
667  if (rp->last_msg_id != clib_net_to_host_u16 (mp->last_msg_id))
668  {
669  clib_warning ("WARNING: traced plugin '%s' last message id %d not %d",
670  mp->plugin_name, clib_net_to_host_u16 (mp->last_msg_id),
671  rp->last_msg_id);
672  }
673 }
674 
675 #define foreach_rpc_api_msg \
676 _(RPC_CALL,rpc_call) \
677 _(RPC_CALL_REPLY,rpc_call_reply)
678 
679 #define foreach_plugin_trace_msg \
680 _(TRACE_PLUGIN_MSG_IDS,trace_plugin_msg_ids)
681 
682 /*
683  * Set the rpc callback at our earliest possible convenience.
684  * This avoids ordering issues between thread_init() -> start_workers and
685  * an init function which we could define here. If we ever intend to use
686  * vlib all by itself, we can't create a link-time dependency on
687  * an init function here and a typical "call foo_init first"
688  * guitar lick.
689  */
690 
691 extern void *rpc_call_main_thread_cb_fn;
692 
693 static clib_error_t *
695 {
696  api_main_t *am = &api_main;
697 #define _(N,n) \
698  vl_msg_api_set_handlers(VL_API_##N, #n, \
699  vl_api_##n##_t_handler, \
700  vl_noop_handler, \
701  vl_noop_handler, \
702  vl_api_##n##_t_print, \
703  sizeof(vl_api_##n##_t), 0 /* do not trace */);
705 #undef _
706 
707 #define _(N,n) \
708  vl_msg_api_set_handlers(VL_API_##N, #n, \
709  vl_api_##n##_t_handler, \
710  vl_noop_handler, \
711  vl_noop_handler, \
712  vl_api_##n##_t_print, \
713  sizeof(vl_api_##n##_t), 1 /* do trace */);
715 #undef _
716 
717  /* No reason to halt the parade to create a trace record... */
718  am->is_mp_safe[VL_API_TRACE_PLUGIN_MSG_IDS] = 1;
720  return 0;
721 }
722 
724 
725 /*
726  * fd.io coding-style-patch-verification: ON
727  *
728  * Local Variables:
729  * eval: (c-set-style "gnu")
730  * End:
731  */
#define foreach_vlib_api_msg
Definition: vlib_api.c:168
int vl_mem_api_handle_msg_private(vlib_main_t *vm, vlib_node_runtime_t *node, u32 reg_index)
Definition: memory_api.c:747
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
Message range (belonging to a plugin)
Definition: api_common.h:111
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:713
u32 vl(void *p)
Definition: threads.c:31
uword * pending_rpc_requests
Definition: main.h:220
vlib_main_t vlib_global_main
Definition: main.c:1850
static void send_one_plugin_msg_ids_msg(u8 *name, u16 first_msg_id, u16 last_msg_id)
Definition: vlib_api.c:208
VLIB_API_INIT_FUNCTION(rpc_api_hookup)
clib_error_t * vl_sock_api_init(vlib_main_t *vm)
Definition: socket_api.c:683
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
Definition: api_shared.c:561
static void vl_api_rpc_call_main_thread_inline(void *fp, u8 *data, u32 data_length, u8 force_rpc)
Definition: vlib_api.c:579
void vl_api_save_msg_table(void)
Definition: vlib_api.c:230
u8 * name
name of the plugin
Definition: api_common.h:113
clib_spinlock_t pending_rpc_lock
Definition: main.h:222
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:673
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:538
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:529
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.
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:232
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:98
vl_socket_args_for_process_t * process_args
Definition: socket_api.h:58
Message configuration definition.
Definition: api_common.h:119
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:525
int i
api_version_t * api_version_list
api version list
Definition: api_common.h:325
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:193
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:70
vlib_node_registration_t vl_api_clnt_node
(constructor) VLIB_REGISTER_NODE (vl_api_clnt_node)
Definition: vlib_api.c:438
#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:204
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
Definition: vec.h:602
static f64 vlib_last_vector_length_per_node(vlib_main_t *vm)
Definition: main.h:323
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:110
_vlib_init_function_list_elt_t * api_init_function_registrations
Definition: main.h:186
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:516
#define always_inline
Definition: clib.h:98
static clib_error_t * rpc_api_hookup(vlib_main_t *vm)
Definition: vlib_api.c:694
void vl_mem_api_dead_client_scan(api_main_t *am, vl_shmem_hdr_t *shm, f64 now)
Definition: memory_api.c:592
#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:334
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:566
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
Definition: api_common.h:265
unsigned int u32
Definition: types.h:88
char name[64]
Definition: api_common.h:198
static uword vl_api_clnt_process(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
Definition: vlib_api.c:275
u16 last_msg_id
last assigned message ID
Definition: api_common.h:115
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:114
u8 data[data_len]
Definition: memclnt.api:96
void * rpc_call_main_thread_cb_fn
Definition: threads.c:1803
unsigned short u16
Definition: types.h:57
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
svm_region_t ** vlib_private_rps
Vector of all mapped shared-VM segments.
Definition: api_common.h:261
#define PREDICT_FALSE(x)
Definition: clib.h:111
signed char i8
Definition: types.h:45
u8 name[64]
Definition: memclnt.api:152
volatile u32 queue_signal_pending
Definition: main.h:190
int vl_mem_api_handle_rpc(vlib_main_t *vm, vlib_node_runtime_t *node)
Definition: memory_api.c:721
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:202
static void vl_api_rpc_call_reply_t_handler(vl_api_rpc_call_reply_t *mp)
Definition: vlib_api.c:560
An API client registration, only in vpp/vlib.
Definition: api_common.h:45
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:169
svmdb_client_t * c
u16 n_vectors
Definition: node.h:420
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:212
vlib_main_t * vm
Definition: buffer.c:301
static vlib_node_registration_t api_rx_from_node_node
(constructor) VLIB_REGISTER_NODE (api_rx_from_node_node)
Definition: vlib_api.c:507
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:799
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
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:280
#define clib_warning(format, args...)
Definition: error.h:59
#define vl_print(handle,...)
Definition: vlib_api.c:50
u64 vector_rate_histogram[SLEEP_N_BUCKETS]
Definition: vlib_api.c:202
static void vl_api_rpc_call_t_handler(vl_api_rpc_call_t *mp)
Definition: vlib_api.c:516
static void serialize_integer(serialize_main_t *m, u64 x, u32 n_bytes)
Definition: serialize.h:185
#define ARRAY_LEN(x)
Definition: clib.h:62
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:337
signed int i32
Definition: types.h:77
#define uword_to_pointer(u, type)
Definition: types.h:136
#define foreach_rpc_api_msg
Definition: vlib_api.c:675
#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:130
#define clib_error_report(e)
Definition: error.h:113
#define vec_append(v1, v2)
Append v2 after v1.
Definition: vec.h:822
void vl_api_api_versions_t_handler(vl_api_api_versions_t *mp)
Definition: vlib_api.c:132
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:148
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:679
u16 first_msg_id
first assigned message ID
Definition: api_common.h:114
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:623
#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
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
#define clib_unix_warning(format, args...)
Definition: error.h:68
volatile u32 api_queue_nonempty
Definition: main.h:191
struct _svm_queue svm_queue_t
static int vlib_api_init(void)
Definition: vlib_api.c:176
#define hash_get_mem(h, key)
Definition: hash.h:269
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1470
u8 * is_mp_safe
Message is mp safe vector.
Definition: api_common.h:225
void vl_api_force_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:634
u8 data[0]
Packet data.
Definition: buffer.h:176
static void vl_api_trace_plugin_msg_ids_t_handler(vl_api_trace_plugin_msg_ids_t *mp)
Definition: vlib_api.c:641
static uword api_rx_from_node(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: vlib_api.c:457
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:322
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:117
uword * msg_range_by_name
Message range by name hash.
Definition: api_common.h:277
void vl_mem_api_enable_disable(vlib_main_t *vm, int enable)
Definition: vlib_api.c:448
api_main_t api_main
Definition: api_shared.c:35
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:82
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:62
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".