blob: bc837bb29395d8f7723935d657809dda21a33a4c [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
2 * Copyright (c) 2017 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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#include <vnet/session/application.h>
Florin Coras6cf30ad2017-04-04 23:08:23 -070017#include <vnet/session/application_interface.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050018#include <vnet/session/session.h>
19
Florin Coras6cf30ad2017-04-04 23:08:23 -070020/**
Dave Barach68b0fb02017-02-28 15:15:56 -050021 * Pool from which we allocate all applications
22 */
23static application_t *app_pool;
24
Florin Coras6cf30ad2017-04-04 23:08:23 -070025/**
Dave Barach68b0fb02017-02-28 15:15:56 -050026 * Hash table of apps by api client index
27 */
28static uword *app_by_api_client_index;
29
Florin Coras6cf30ad2017-04-04 23:08:23 -070030/**
31 * Default application event queue size
32 */
33static u32 default_app_evt_queue_size = 128;
34
Dave Barach68b0fb02017-02-28 15:15:56 -050035int
36application_api_queue_is_full (application_t * app)
37{
38 unix_shared_memory_queue_t *q;
39
40 /* builtin servers are always OK */
41 if (app->api_client_index == ~0)
42 return 0;
43
44 q = vl_api_client_index_to_input_queue (app->api_client_index);
45 if (!q)
46 return 1;
47
48 if (q->cursize == q->maxsize)
49 return 1;
50 return 0;
51}
52
53static void
54application_table_add (application_t * app)
55{
56 hash_set (app_by_api_client_index, app->api_client_index, app->index);
57}
58
59static void
60application_table_del (application_t * app)
61{
62 hash_unset (app_by_api_client_index, app->api_client_index);
63}
64
65application_t *
66application_lookup (u32 api_client_index)
67{
68 uword *p;
69 p = hash_get (app_by_api_client_index, api_client_index);
70 if (p)
71 return application_get (p[0]);
72
73 return 0;
74}
75
Florin Coras6cf30ad2017-04-04 23:08:23 -070076application_t *
77application_new ()
78{
79 application_t *app;
80 pool_get (app_pool, app);
81 memset (app, 0, sizeof (*app));
82 app->index = application_get_index (app);
83 app->connects_seg_manager = ~0;
Dave Wallace7b749fe2017-07-05 14:30:46 -040084 app->first_segment_manager = ~0;
85 if (CLIB_DEBUG > 1)
86 clib_warning ("[%d] New app (%d)", getpid (), app->index);
Florin Coras6cf30ad2017-04-04 23:08:23 -070087 return app;
88}
89
Dave Barach68b0fb02017-02-28 15:15:56 -050090void
91application_del (application_t * app)
92{
Florin Coras6cf30ad2017-04-04 23:08:23 -070093 segment_manager_t *sm;
94 u64 handle;
95 u32 index, *handles = 0;
96 int i;
97 vnet_unbind_args_t _a, *a = &_a;
Dave Barach68b0fb02017-02-28 15:15:56 -050098
Florin Coras6cf30ad2017-04-04 23:08:23 -070099 /*
Florin Corasa5464812017-04-19 13:00:05 -0700100 * The app event queue allocated in first segment is cleared with
101 * the segment manager. No need to explicitly free it.
102 */
Dave Wallace7b749fe2017-07-05 14:30:46 -0400103 if (CLIB_DEBUG > 1)
104 clib_warning ("[%d] Delete app (%d)", getpid (), app->index);
Florin Corasa5464812017-04-19 13:00:05 -0700105
106 /*
Florin Coras6cf30ad2017-04-04 23:08:23 -0700107 * Cleanup segment managers
108 */
Dave Wallace50376692017-07-20 16:36:01 -0400109 if ((app->connects_seg_manager != (u32) ~ 0) &&
110 (app->connects_seg_manager != app->first_segment_manager))
Dave Barach68b0fb02017-02-28 15:15:56 -0500111 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700112 sm = segment_manager_get (app->connects_seg_manager);
113 segment_manager_del (sm);
Dave Barach68b0fb02017-02-28 15:15:56 -0500114 }
115
Florin Coras6cf30ad2017-04-04 23:08:23 -0700116 /* *INDENT-OFF* */
117 hash_foreach (handle, index, app->listeners_table,
118 ({
119 vec_add1 (handles, handle);
120 }));
121 /* *INDENT-ON* */
122
123 /* Actual listener cleanup */
124 for (i = 0; i < vec_len (handles); i++)
125 {
Florin Corasf03a59a2017-06-09 21:07:32 -0700126 a->app_index = app->index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700127 a->handle = handles[i];
128 /* seg manager is removed when unbind completes */
129 vnet_unbind (a);
130 }
131
Dave Wallace7b749fe2017-07-05 14:30:46 -0400132 if (app->first_segment_manager != ~0)
133 {
134 sm = segment_manager_get (app->first_segment_manager);
135 segment_manager_first_segment_maybe_del (sm);
136 }
137
Dave Barach68b0fb02017-02-28 15:15:56 -0500138 application_table_del (app);
Dave Barach68b0fb02017-02-28 15:15:56 -0500139 pool_put (app_pool, app);
140}
141
Florin Corasd79b41e2017-03-04 05:37:52 -0800142static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700143application_verify_cb_fns (session_cb_vft_t * cb_fns)
Florin Corasd79b41e2017-03-04 05:37:52 -0800144{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700145 if (cb_fns->session_accept_callback == 0)
Florin Corasd79b41e2017-03-04 05:37:52 -0800146 clib_warning ("No accept callback function provided");
Florin Coras6cf30ad2017-04-04 23:08:23 -0700147 if (cb_fns->session_connected_callback == 0)
Florin Corasd79b41e2017-03-04 05:37:52 -0800148 clib_warning ("No session connected callback function provided");
149 if (cb_fns->session_disconnect_callback == 0)
150 clib_warning ("No session disconnect callback function provided");
151 if (cb_fns->session_reset_callback == 0)
152 clib_warning ("No session reset callback function provided");
153}
154
Florin Coras6cf30ad2017-04-04 23:08:23 -0700155int
156application_init (application_t * app, u32 api_client_index, u64 * options,
157 session_cb_vft_t * cb_fns)
Dave Barach68b0fb02017-02-28 15:15:56 -0500158{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700159 segment_manager_t *sm;
160 segment_manager_properties_t *props;
Florin Corasa5464812017-04-19 13:00:05 -0700161 u32 app_evt_queue_size, first_seg_size;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700162 int rv;
Dave Barach68b0fb02017-02-28 15:15:56 -0500163
Florin Coras6cf30ad2017-04-04 23:08:23 -0700164 app_evt_queue_size = options[APP_EVT_QUEUE_SIZE] > 0 ?
165 options[APP_EVT_QUEUE_SIZE] : default_app_evt_queue_size;
Dave Barach68b0fb02017-02-28 15:15:56 -0500166
Florin Coras6cf30ad2017-04-04 23:08:23 -0700167 /* Setup segment manager */
168 sm = segment_manager_new ();
169 sm->app_index = app->index;
170 props = &app->sm_properties;
171 props->add_segment_size = options[SESSION_OPTIONS_ADD_SEGMENT_SIZE];
172 props->rx_fifo_size = options[SESSION_OPTIONS_RX_FIFO_SIZE];
173 props->tx_fifo_size = options[SESSION_OPTIONS_TX_FIFO_SIZE];
174 props->add_segment = props->add_segment_size != 0;
Dave Barach10d8cc62017-05-30 09:30:07 -0400175 props->preallocated_fifo_pairs = options[APP_OPTIONS_PREALLOC_FIFO_PAIRS];
Florin Corasa5464812017-04-19 13:00:05 -0700176 props->use_private_segment = options[APP_OPTIONS_FLAGS]
177 & APP_OPTIONS_FLAGS_BUILTIN_APP;
Dave Barach2c25a622017-06-26 11:35:07 -0400178 props->private_segment_count = options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT];
179 props->private_segment_size = options[APP_OPTIONS_PRIVATE_SEGMENT_SIZE];
Dave Barach68b0fb02017-02-28 15:15:56 -0500180
Florin Corasa5464812017-04-19 13:00:05 -0700181 first_seg_size = options[SESSION_OPTIONS_SEGMENT_SIZE];
182 if ((rv = segment_manager_init (sm, props, first_seg_size)))
Florin Coras6cf30ad2017-04-04 23:08:23 -0700183 return rv;
Dave Barach68b0fb02017-02-28 15:15:56 -0500184
Florin Coras6cf30ad2017-04-04 23:08:23 -0700185 app->first_segment_manager = segment_manager_index (sm);
Dave Barach68b0fb02017-02-28 15:15:56 -0500186 app->api_client_index = api_client_index;
Florin Corasa5464812017-04-19 13:00:05 -0700187 app->flags = options[APP_OPTIONS_FLAGS];
Dave Barach68b0fb02017-02-28 15:15:56 -0500188 app->cb_fns = *cb_fns;
189
Florin Corasa5464812017-04-19 13:00:05 -0700190 /* Allocate app event queue in the first shared-memory segment */
191 app->event_queue = segment_manager_alloc_queue (sm, app_evt_queue_size);
192
Florin Corasd79b41e2017-03-04 05:37:52 -0800193 /* Check that the obvious things are properly set up */
Florin Coras6cf30ad2017-04-04 23:08:23 -0700194 application_verify_cb_fns (cb_fns);
Florin Corasd79b41e2017-03-04 05:37:52 -0800195
Dave Barach68b0fb02017-02-28 15:15:56 -0500196 /* Add app to lookup by api_client_index table */
197 application_table_add (app);
198
Florin Coras6cf30ad2017-04-04 23:08:23 -0700199 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500200}
201
202application_t *
203application_get (u32 index)
204{
205 return pool_elt_at_index (app_pool, index);
206}
207
Florin Corase04c2992017-03-01 08:17:34 -0800208application_t *
209application_get_if_valid (u32 index)
210{
211 if (pool_is_free_index (app_pool, index))
212 return 0;
213
214 return pool_elt_at_index (app_pool, index);
215}
216
Dave Barach68b0fb02017-02-28 15:15:56 -0500217u32
218application_get_index (application_t * app)
219{
220 return app - app_pool;
221}
222
Florin Coras6cf30ad2017-04-04 23:08:23 -0700223static segment_manager_t *
224application_alloc_segment_manager (application_t * app)
Dave Barach68b0fb02017-02-28 15:15:56 -0500225{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700226 segment_manager_t *sm = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500227
Florin Coras6cf30ad2017-04-04 23:08:23 -0700228 if (app->first_segment_manager != (u32) ~ 0)
Dave Barach68b0fb02017-02-28 15:15:56 -0500229 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700230 sm = segment_manager_get (app->first_segment_manager);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700231 return sm;
Dave Barach68b0fb02017-02-28 15:15:56 -0500232 }
233
Florin Coras6cf30ad2017-04-04 23:08:23 -0700234 sm = segment_manager_new ();
235 if (segment_manager_init (sm, &app->sm_properties, 0))
236 return 0;
237 return sm;
238}
239
240/**
241 * Start listening local transport endpoint for requested transport.
242 *
243 * Creates a 'dummy' stream session with state LISTENING to be used in session
244 * lookups, prior to establishing connection. Requests transport to build
245 * it's own specific listening connection.
246 */
247int
248application_start_listen (application_t * srv, session_type_t session_type,
249 transport_endpoint_t * tep, u64 * res)
250{
251 segment_manager_t *sm;
252 stream_session_t *s;
253 u64 handle;
254
255 s = listen_session_new (session_type);
256 s->app_index = srv->index;
257
258 if (stream_session_listen (s, tep))
259 goto err;
260
261 /* Allocate segment manager. All sessions derived out of a listen session
262 * have fifos allocated by the same segment manager. */
263 sm = application_alloc_segment_manager (srv);
264 if (sm == 0)
265 goto err;
266
267 /* Add to app's listener table. Useful to find all child listeners
268 * when app goes down, although, just for unbinding this is not needed */
269 handle = listen_session_get_handle (s);
270 hash_set (srv->listeners_table, handle, segment_manager_index (sm));
271
272 *res = handle;
273 return 0;
274
275err:
276 listen_session_del (s);
277 return -1;
278}
279
280/**
281 * Stop listening on session associated to handle
282 */
283int
284application_stop_listen (application_t * srv, u64 handle)
285{
286 stream_session_t *listener;
287 uword *indexp;
288 segment_manager_t *sm;
289
290 if (srv && hash_get (srv->listeners_table, handle) == 0)
291 {
292 clib_warning ("app doesn't own handle %llu!", handle);
293 return -1;
294 }
295
296 listener = listen_session_get_from_handle (handle);
297 stream_session_stop_listen (listener);
298
299 indexp = hash_get (srv->listeners_table, handle);
300 ASSERT (indexp);
301
302 sm = segment_manager_get (*indexp);
303 segment_manager_del (sm);
Dave Wallace7b749fe2017-07-05 14:30:46 -0400304 srv->first_segment_manager = ~0;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700305 hash_unset (srv->listeners_table, handle);
306 listen_session_del (listener);
307
Dave Barach68b0fb02017-02-28 15:15:56 -0500308 return 0;
309}
310
Florin Coras6cf30ad2017-04-04 23:08:23 -0700311int
312application_open_session (application_t * app, session_type_t sst,
313 transport_endpoint_t * tep, u32 api_context)
Dave Barach68b0fb02017-02-28 15:15:56 -0500314{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700315 segment_manager_t *sm;
316 transport_connection_t *tc = 0;
317 int rv;
318
319 /* Make sure we have a segment manager for connects */
320 if (app->connects_seg_manager == (u32) ~ 0)
321 {
322 sm = application_alloc_segment_manager (app);
323 if (sm == 0)
324 return -1;
325 app->connects_seg_manager = segment_manager_index (sm);
326 }
327
328 if ((rv = stream_session_open (app->index, sst, tep, &tc)))
329 return rv;
330
331 /* Store api_context for when the reply comes. Not the nicest thing
Florin Corasab0289a2017-08-14 11:25:25 -0700332 * but better than allocating a separate half-open pool. */
Florin Coras6cf30ad2017-04-04 23:08:23 -0700333 tc->s_index = api_context;
334
335 return 0;
336}
337
338segment_manager_t *
339application_get_connect_segment_manager (application_t * app)
340{
341 ASSERT (app->connects_seg_manager != (u32) ~ 0);
342 return segment_manager_get (app->connects_seg_manager);
343}
344
345segment_manager_t *
346application_get_listen_segment_manager (application_t * app,
347 stream_session_t * s)
348{
349 uword *smp;
350 smp = hash_get (app->listeners_table, listen_session_get_handle (s));
351 ASSERT (smp != 0);
352 return segment_manager_get (*smp);
353}
354
355static u8 *
356app_get_name_from_reg_index (application_t * app)
357{
358 u8 *app_name;
359
Dave Barach68b0fb02017-02-28 15:15:56 -0500360 vl_api_registration_t *regp;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700361 regp = vl_api_client_index_to_registration (app->api_client_index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500362 if (!regp)
Florin Coras6cf30ad2017-04-04 23:08:23 -0700363 app_name = format (0, "builtin-%d%c", app->index, 0);
Dave Barach68b0fb02017-02-28 15:15:56 -0500364 else
Florin Coras6cf30ad2017-04-04 23:08:23 -0700365 app_name = format (0, "%s%c", regp->name, 0);
Dave Barach68b0fb02017-02-28 15:15:56 -0500366
Florin Coras6cf30ad2017-04-04 23:08:23 -0700367 return app_name;
Dave Barach68b0fb02017-02-28 15:15:56 -0500368}
369
Dave Barach52851e62017-08-07 09:35:25 -0400370int
371application_is_proxy (application_t * app)
372{
373 return !(app->flags & APP_OPTIONS_FLAGS_IS_PROXY);
374}
375
Dave Barach68b0fb02017-02-28 15:15:56 -0500376u8 *
Florin Coras6cf30ad2017-04-04 23:08:23 -0700377format_application_listener (u8 * s, va_list * args)
Dave Barach68b0fb02017-02-28 15:15:56 -0500378{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700379 application_t *app = va_arg (*args, application_t *);
380 u64 handle = va_arg (*args, u64);
381 u32 index = va_arg (*args, u32);
Dave Barach68b0fb02017-02-28 15:15:56 -0500382 int verbose = va_arg (*args, int);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700383 stream_session_t *listener;
384 u8 *app_name, *str;
Dave Barach68b0fb02017-02-28 15:15:56 -0500385
Florin Coras6cf30ad2017-04-04 23:08:23 -0700386 if (app == 0)
Dave Barach68b0fb02017-02-28 15:15:56 -0500387 {
388 if (verbose)
Florin Coras6cf30ad2017-04-04 23:08:23 -0700389 s = format (s, "%-40s%-20s%-15s%-15s%-10s", "Connection", "App",
390 "API Client", "ListenerID", "SegManager");
Dave Barach68b0fb02017-02-28 15:15:56 -0500391 else
Florin Coras6cf30ad2017-04-04 23:08:23 -0700392 s = format (s, "%-40s%-20s", "Connection", "App");
Dave Barach68b0fb02017-02-28 15:15:56 -0500393
394 return s;
395 }
396
Florin Coras6cf30ad2017-04-04 23:08:23 -0700397 app_name = app_get_name_from_reg_index (app);
398 listener = listen_session_get_from_handle (handle);
399 str = format (0, "%U", format_stream_session, listener, verbose);
Dave Barach68b0fb02017-02-28 15:15:56 -0500400
Dave Barach68b0fb02017-02-28 15:15:56 -0500401 if (verbose)
402 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700403 s = format (s, "%-40s%-20s%-15u%-15u%-10u", str, app_name,
404 app->api_client_index, handle, index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500405 }
406 else
Florin Coras6cf30ad2017-04-04 23:08:23 -0700407 s = format (s, "%-40s%-20s", str, app_name);
408
409 vec_free (app_name);
410 return s;
411}
412
413void
414application_format_connects (application_t * app, int verbose)
415{
416 vlib_main_t *vm = vlib_get_main ();
417 segment_manager_t *sm;
418 u8 *app_name, *s = 0;
Dave Barach10d8cc62017-05-30 09:30:07 -0400419 int j;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700420
421 /* Header */
422 if (app == 0)
423 {
424 if (verbose)
425 vlib_cli_output (vm, "%-40s%-20s%-15s%-10s", "Connection", "App",
426 "API Client", "SegManager");
427 else
428 vlib_cli_output (vm, "%-40s%-20s", "Connection", "App");
429 return;
430 }
431
432 /* make sure */
433 if (app->connects_seg_manager == (u32) ~ 0)
434 return;
435
436 app_name = app_get_name_from_reg_index (app);
437
438 /* Across all fifo segments */
439 sm = segment_manager_get (app->connects_seg_manager);
440 for (j = 0; j < vec_len (sm->segment_indices); j++)
441 {
442 svm_fifo_segment_private_t *fifo_segment;
Dave Barach10d8cc62017-05-30 09:30:07 -0400443 svm_fifo_t *fifo;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700444 u8 *str;
445
446 fifo_segment = svm_fifo_get_segment (sm->segment_indices[j]);
Dave Barach10d8cc62017-05-30 09:30:07 -0400447 fifo = svm_fifo_segment_get_fifo_list (fifo_segment);
448 while (fifo)
Florin Coras6cf30ad2017-04-04 23:08:23 -0700449 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700450 u32 session_index, thread_index;
451 stream_session_t *session;
452
Florin Corasa5464812017-04-19 13:00:05 -0700453 session_index = fifo->master_session_index;
454 thread_index = fifo->master_thread_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700455
456 session = stream_session_get (session_index, thread_index);
457 str = format (0, "%U", format_stream_session, session, verbose);
458
459 if (verbose)
460 s = format (s, "%-40s%-20s%-15u%-10u", str, app_name,
461 app->api_client_index, app->connects_seg_manager);
462 else
463 s = format (s, "%-40s%-20s", str, app_name);
464
465 vlib_cli_output (vm, "%v", s);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700466 vec_reset_length (s);
467 vec_free (str);
Dave Barach10d8cc62017-05-30 09:30:07 -0400468
469 fifo = fifo->next;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700470 }
471 vec_free (s);
472 }
473
474 vec_free (app_name);
475}
476
477u8 *
478format_application (u8 * s, va_list * args)
479{
480 application_t *app = va_arg (*args, application_t *);
481 CLIB_UNUSED (int verbose) = va_arg (*args, int);
482 u8 *app_name;
483
484 if (app == 0)
485 {
486 if (verbose)
487 s = format (s, "%-10s%-20s%-15s%-15s%-15s%-15s", "Index", "Name",
488 "API Client", "Add seg size", "Rx fifo size",
489 "Tx fifo size");
490 else
491 s = format (s, "%-10s%-20s%-20s", "Index", "Name", "API Client");
492 return s;
493 }
494
495 app_name = app_get_name_from_reg_index (app);
496 if (verbose)
497 s = format (s, "%-10d%-20s%-15d%-15d%-15d%-15d", app->index, app_name,
498 app->api_client_index, app->sm_properties.add_segment_size,
499 app->sm_properties.rx_fifo_size,
500 app->sm_properties.tx_fifo_size);
501 else
502 s = format (s, "%-10d%-20s%-20d", app->index, app_name,
503 app->api_client_index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500504 return s;
505}
506
507static clib_error_t *
508show_app_command_fn (vlib_main_t * vm, unformat_input_t * input,
509 vlib_cli_command_t * cmd)
510{
511 application_t *app;
512 int do_server = 0;
513 int do_client = 0;
514 int verbose = 0;
515
Florin Coras6cf30ad2017-04-04 23:08:23 -0700516 if (!session_manager_is_enabled ())
Florin Corase04c2992017-03-01 08:17:34 -0800517 {
518 clib_error_return (0, "session layer is not enabled");
519 }
520
Dave Barach68b0fb02017-02-28 15:15:56 -0500521 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
522 {
523 if (unformat (input, "server"))
524 do_server = 1;
525 else if (unformat (input, "client"))
526 do_client = 1;
527 else if (unformat (input, "verbose"))
528 verbose = 1;
529 else
530 break;
531 }
532
533 if (do_server)
534 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700535 u64 handle;
536 u32 index;
Dave Barach68b0fb02017-02-28 15:15:56 -0500537 if (pool_elts (app_pool))
538 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700539 vlib_cli_output (vm, "%U", format_application_listener,
540 0 /* header */ , 0, 0,
Dave Barach68b0fb02017-02-28 15:15:56 -0500541 verbose);
542 /* *INDENT-OFF* */
543 pool_foreach (app, app_pool,
544 ({
Florin Coras6cf30ad2017-04-04 23:08:23 -0700545 /* App's listener sessions */
546 if (hash_elts (app->listeners_table) == 0)
547 continue;
548 hash_foreach (handle, index, app->listeners_table,
549 ({
550 vlib_cli_output (vm, "%U", format_application_listener, app,
551 handle, index, verbose);
552 }));
Dave Barach68b0fb02017-02-28 15:15:56 -0500553 }));
554 /* *INDENT-ON* */
555 }
556 else
557 vlib_cli_output (vm, "No active server bindings");
558 }
559
560 if (do_client)
561 {
562 if (pool_elts (app_pool))
563 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700564 application_format_connects (0, verbose);
565
Dave Barach68b0fb02017-02-28 15:15:56 -0500566 /* *INDENT-OFF* */
567 pool_foreach (app, app_pool,
568 ({
Florin Coras6cf30ad2017-04-04 23:08:23 -0700569 if (app->connects_seg_manager == (u32)~0)
570 continue;
571 application_format_connects (app, verbose);
Dave Barach68b0fb02017-02-28 15:15:56 -0500572 }));
573 /* *INDENT-ON* */
574 }
575 else
Florin Corase04c2992017-03-01 08:17:34 -0800576 vlib_cli_output (vm, "No active client bindings");
Dave Barach68b0fb02017-02-28 15:15:56 -0500577 }
578
Florin Coras6cf30ad2017-04-04 23:08:23 -0700579 /* Print app related info */
580 if (!do_server && !do_client)
581 {
582 vlib_cli_output (vm, "%U", format_application, 0, verbose);
583 pool_foreach (app, app_pool, (
584 {
585 vlib_cli_output (vm, "%U",
586 format_application, app,
587 verbose);
588 }
589 ));
590 }
591
Dave Barach68b0fb02017-02-28 15:15:56 -0500592 return 0;
593}
594
Florin Corase04c2992017-03-01 08:17:34 -0800595/* *INDENT-OFF* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500596VLIB_CLI_COMMAND (show_app_command, static) =
597{
Florin Corase04c2992017-03-01 08:17:34 -0800598 .path = "show app",
599 .short_help = "show app [server|client] [verbose]",
600 .function = show_app_command_fn,
601};
602/* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500603
604/*
605 * fd.io coding-style-patch-verification: ON
606 *
607 * Local Variables:
608 * eval: (c-set-style "gnu")
609 * End:
610 */