blob: 8d2b191fb8114a8377757bb4d7f8cc1a253da98f [file] [log] [blame]
Damjan Marion7cd468a2016-12-19 23:05:39 +01001/*
2 *------------------------------------------------------------------
Damjan Marion7cd468a2016-12-19 23:05:39 +01003 * Copyright (c) 2009 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
16 */
17
Florin Corase86a8ed2018-01-05 03:20:25 -080018#ifndef included_vlibmemory_api_common_h
19#define included_vlibmemory_api_common_h
Damjan Marion7cd468a2016-12-19 23:05:39 +010020
Florin Corase86a8ed2018-01-05 03:20:25 -080021#include <svm/svm_common.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010022#include <vlibapi/api.h>
Florin Corase86a8ed2018-01-05 03:20:25 -080023#include <vlibmemory/memory_api.h>
24#include <vlibmemory/memory_client.h>
25#include <vlibmemory/socket_api.h>
26#include <vlibmemory/socket_client.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010027
Florin Corase86a8ed2018-01-05 03:20:25 -080028void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
29u16 vl_client_get_first_plugin_msg_id (const char *plugin_name);
30void vl_api_send_pending_rpc_requests (vlib_main_t * vm);
31u8 *vl_api_serialize_message_table (api_main_t * am, u8 * vector);
32
33always_inline void
34vl_api_send_msg (vl_api_registration_t * rp, u8 * elem)
Damjan Marion7cd468a2016-12-19 23:05:39 +010035{
Florin Corase86a8ed2018-01-05 03:20:25 -080036 if (PREDICT_FALSE (rp->registration_type > REGISTRATION_TYPE_SHMEM))
37 {
38 vl_socket_api_send (rp, elem);
39 }
40 else
41 {
42 vl_msg_api_send_shmem (rp->vl_input_queue, (u8 *) & elem);
43 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010044}
45
Florin Corasaf0ff5a2018-01-10 08:17:03 -080046always_inline int
47vl_api_can_send_msg (vl_api_registration_t * rp)
48{
49 if (PREDICT_FALSE (rp->registration_type > REGISTRATION_TYPE_SHMEM))
50 return 1;
51 else
52 return vl_mem_api_can_send (rp->vl_input_queue);
53}
54
Florin Corase86a8ed2018-01-05 03:20:25 -080055always_inline vl_api_registration_t *
56vl_api_client_index_to_registration (u32 index)
Damjan Marion7cd468a2016-12-19 23:05:39 +010057{
Florin Corase86a8ed2018-01-05 03:20:25 -080058 if (PREDICT_FALSE (socket_main.current_rp != 0))
59 return socket_main.current_rp;
60
61 return (vl_mem_api_client_index_to_registration (index));
Damjan Marion7cd468a2016-12-19 23:05:39 +010062}
63
Florin Corasb384b542018-01-15 01:08:33 -080064always_inline u32
65vl_api_registration_file_index (vl_api_registration_t * reg)
66{
67 return reg->clib_file_index;
68}
69
70always_inline clib_file_t *
71vl_api_registration_file (vl_api_registration_t * reg)
72{
73 return clib_file_get (&file_main, vl_api_registration_file_index (reg));
74}
75
76always_inline void
77vl_api_registration_del_file (vl_api_registration_t * reg)
78{
79 clib_file_t *cf = vl_api_registration_file (reg);
80 if (cf)
81 clib_file_del (&file_main, cf);
82}
83
84always_inline clib_error_t *
85vl_api_send_fd_msg (vl_api_registration_t * reg, int fd_to_send)
86{
87 clib_file_t *cf = vl_api_registration_file (reg);
88 if (cf)
89 return vl_sock_api_send_fd_msg (cf->file_descriptor, fd_to_send);
90 return 0;
91}
92
93always_inline clib_error_t *
94vl_api_recv_fd_msg (vl_api_registration_t * reg, int *fd_to_recv, u32 wait)
95{
96 clib_file_t *cf = vl_api_registration_file (reg);
97 if (cf)
98 return vl_sock_api_recv_fd_msg (cf->file_descriptor, fd_to_recv, wait);
99 return 0;
100}
101
Florin Corase86a8ed2018-01-05 03:20:25 -0800102/*
103 * vl_api_clnt process data used by transports (socket api in particular)
104 */
105extern vlib_node_registration_t vl_api_clnt_node;
106extern volatile int **vl_api_queue_cursizes;
107
108typedef enum vl_api_clnt_process_events
Damjan Marion7cd468a2016-12-19 23:05:39 +0100109{
Florin Corase86a8ed2018-01-05 03:20:25 -0800110 QUEUE_SIGNAL_EVENT = 1,
111 SOCKET_READ_EVENT
112} vl_api_clnt_process_events_t;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100113
Florin Corase86a8ed2018-01-05 03:20:25 -0800114#define foreach_histogram_bucket \
115_(400) \
116_(200) \
117_(100) \
118_(10)
Damjan Marion7cd468a2016-12-19 23:05:39 +0100119
Florin Corase86a8ed2018-01-05 03:20:25 -0800120typedef enum
121{
122#define _(n) SLEEP_##n##_US,
123 foreach_histogram_bucket
124#undef _
125 SLEEP_N_BUCKETS,
126} histogram_index_t;
Dave Barach59b25652017-09-10 15:04:27 -0400127
Florin Corase86a8ed2018-01-05 03:20:25 -0800128extern u64 vector_rate_histogram[];
129
130/*
131 * sockclnt APIs XXX are these actually used anywhere?
132 */
133vl_api_registration_t *sockclnt_get_registration (u32 index);
134void socksvr_add_pending_output (struct clib_file *uf,
135 struct vl_api_registration_ *cf,
136 u8 * buffer, uword buffer_bytes);
137void vl_socket_process_msg (struct clib_file *uf,
138 struct vl_api_registration_ *rp, i8 * input_v);
139u32 sockclnt_open_index (char *client_name, char *hostname, int port);
140void sockclnt_close_index (u32 index);
141void vl_client_msg_api_send (vl_api_registration_t * cm, u8 * elem);
142
143#endif /* included_vlibmemory_api_common_h */
Damjan Marion7cd468a2016-12-19 23:05:39 +0100144
145/*
146 * fd.io coding-style-patch-verification: ON
147 *
148 * Local Variables:
149 * eval: (c-set-style "gnu")
150 * End:
151 */