2 * Copyright (c) 2017-2019 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef SRC_VNET_SESSION_APPLICATION_H_
17 #define SRC_VNET_SESSION_APPLICATION_H_
19 #include <vnet/session/application_interface.h>
20 #include <vnet/session/application_namespace.h>
21 #include <vnet/session/session_types.h>
22 #include <vnet/session/segment_manager.h>
27 #define APP_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
29 #define APP_DBG(_fmt, _args...)
32 typedef struct app_worker_
34 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
36 /** Worker index in global worker pool*/
39 /** Worker index in app's map pool */
42 /** Index of owning app */
45 /** Application listens for events on this svm queue */
46 svm_msg_q_t *event_queue;
48 /** Segment manager used for outgoing connects issued by the app */
49 u32 connects_seg_manager;
51 /** Lookup tables for listeners. Value is segment manager index */
52 uword *listeners_table;
55 * First segment manager has in the the first segment the application's
56 * event fifo. Depending on what the app does, it may be either used for
57 * a listener or for connects.
59 u32 first_segment_manager;
60 u8 first_segment_manager_in_use;
62 /** API index for the worker. Needed for multi-process apps */
68 typedef struct app_worker_map_
73 typedef struct app_listener_
75 clib_bitmap_t *workers; /**< workers accepting connections */
76 u32 accept_rotor; /**< last worker to accept a connection */
83 typedef struct application_
85 /** App index in app pool */
91 /** Callbacks: shoulder-taps for the server/client */
92 session_cb_vft_t cb_fns;
94 /** Segment manager properties. Shared by all segment managers */
95 segment_manager_properties_t sm_properties;
97 /** Pool of mappings that keep track of workers associated to this app */
98 app_worker_map_t *worker_maps;
100 /** Name registered by builtin apps */
103 /** Namespace the application belongs to */
106 u16 proxied_transports;
108 /** Pool of listeners for the app */
109 app_listener_t *listeners;
115 /** Certificate to be used for listen sessions */
118 /** PEM encoded key */
121 /** Preferred tls engine */
126 typedef struct app_main_
129 * Pool from which we allocate all applications
131 application_t *app_pool;
134 * Hash table of apps by api client index
136 uword *app_by_api_client_index;
139 * Hash table of builtin apps by name
144 typedef struct app_init_args_
146 #define _(_type, _name) _type _name;
147 foreach_app_init_args
151 typedef struct _vnet_app_worker_add_del_args
153 u32 app_index; /**< App for which a new worker is requested */
154 u32 wrk_map_index; /**< Index to delete or return value if add */
155 u32 api_client_index; /**< Binary API client index */
156 ssvm_private_t *segment; /**< First segment in segment manager */
157 u64 segment_handle; /**< Handle for the segment */
158 svm_msg_q_t *evt_q; /**< Worker message queue */
159 u8 is_add; /**< Flag set if addition */
160 } vnet_app_worker_add_del_args_t;
162 #define APP_INVALID_INDEX ((u32)~0)
163 #define APP_NS_INVALID_INDEX ((u32)~0)
164 #define APP_INVALID_SEGMENT_MANAGER_INDEX ((u32) ~0)
166 app_listener_t *app_listener_get (application_t * app, u32 al_index);
167 int app_listener_alloc_and_init (application_t * app,
168 session_endpoint_cfg_t * sep,
169 app_listener_t ** listener);
170 void app_listener_cleanup (app_listener_t * app_listener);
171 session_handle_t app_listener_handle (app_listener_t * app_listener);
172 app_listener_t *app_listener_lookup (application_t * app,
173 session_endpoint_cfg_t * sep);
174 app_listener_t *app_listener_get_w_handle (session_handle_t handle);
175 app_listener_t *app_listener_get_w_session (session_t * ls);
176 app_worker_t *app_listener_select_worker (app_listener_t * al);
177 session_t *app_listener_get_session (app_listener_t * al);
178 session_t *app_listener_get_local_session (app_listener_t * al);
180 application_t *application_get (u32 index);
181 application_t *application_get_if_valid (u32 index);
182 application_t *application_lookup (u32 api_client_index);
183 application_t *application_lookup_name (const u8 * name);
184 app_worker_t *application_get_worker (application_t * app, u32 wrk_index);
185 app_worker_t *application_get_default_worker (application_t * app);
186 app_worker_t *application_listener_select_worker (session_t * ls);
187 int application_change_listener_owner (session_t * s, app_worker_t * app_wrk);
188 int application_is_proxy (application_t * app);
189 int application_is_builtin (application_t * app);
190 int application_is_builtin_proxy (application_t * app);
191 u32 application_session_table (application_t * app, u8 fib_proto);
192 u32 application_local_session_table (application_t * app);
193 const u8 *application_name_from_index (u32 app_or_wrk);
194 u8 application_has_local_scope (application_t * app);
195 u8 application_has_global_scope (application_t * app);
196 void application_setup_proxy (application_t * app);
197 void application_remove_proxy (application_t * app);
199 segment_manager_properties_t *application_get_segment_manager_properties (u32
202 segment_manager_properties_t
203 * application_segment_manager_properties (application_t * app);
209 app_worker_t *app_worker_alloc (application_t * app);
210 int application_alloc_worker_and_init (application_t * app,
211 app_worker_t ** wrk);
212 app_worker_t *app_worker_get (u32 wrk_index);
213 app_worker_t *app_worker_get_if_valid (u32 wrk_index);
214 application_t *app_worker_get_app (u32 wrk_index);
215 int app_worker_own_session (app_worker_t * app_wrk, session_t * s);
216 void app_worker_free (app_worker_t * app_wrk);
217 int app_worker_connect_session (app_worker_t * app, session_endpoint_t * tep,
219 int app_worker_start_listen (app_worker_t * app_wrk, app_listener_t * lstnr);
220 int app_worker_stop_listen (app_worker_t * app_wrk, app_listener_t * al);
221 int app_worker_init_accepted (session_t * s);
222 int app_worker_accept_notify (app_worker_t * app_wrk, session_t * s);
223 int app_worker_init_connected (app_worker_t * app_wrk, session_t * s);
224 int app_worker_connect_notify (app_worker_t * app_wrk, session_t * s,
226 segment_manager_t *app_worker_get_listen_segment_manager (app_worker_t *,
228 segment_manager_t *app_worker_get_connect_segment_manager (app_worker_t *);
230 * app_worker_get_or_alloc_connect_segment_manager (app_worker_t *);
231 int app_worker_alloc_connects_segment_manager (app_worker_t * app);
232 int app_worker_add_segment_notify (app_worker_t * app_wrk,
234 int app_worker_del_segment_notify (app_worker_t * app_wrk,
236 u32 app_worker_n_listeners (app_worker_t * app);
237 session_t *app_worker_first_listener (app_worker_t * app,
238 u8 fib_proto, u8 transport_proto);
239 int app_worker_send_event (app_worker_t * app, session_t * s, u8 evt);
240 int app_worker_lock_and_send_event (app_worker_t * app, session_t * s,
242 session_t *app_worker_proxy_listener (app_worker_t * app, u8 fib_proto,
244 u8 *format_app_worker (u8 * s, va_list * args);
245 u8 *format_app_worker_listener (u8 * s, va_list * args);
246 void app_worker_format_connects (app_worker_t * app_wrk, int verbose);
247 int vnet_app_worker_add_del (vnet_app_worker_add_del_args_t * a);
249 uword unformat_application_proto (unformat_input_t * input, va_list * args);
251 #endif /* SRC_VNET_SESSION_APPLICATION_H_ */
254 * fd.io coding-style-patch-verification: ON
257 * eval: (c-set-style "gnu")