blob: 2892bc59f12c2f677dc41db9d9fc8acea91dbcc3 [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#ifndef SRC_VNET_SESSION_APPLICATION_H_
17#define SRC_VNET_SESSION_APPLICATION_H_
18
19#include <vnet/vnet.h>
20#include <vnet/session/session.h>
Florin Coras6cf30ad2017-04-04 23:08:23 -070021#include <vnet/session/segment_manager.h>
Florin Corascea194d2017-10-02 00:18:51 -070022#include <vnet/session/application_namespace.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050023typedef enum
24{
25 APP_SERVER,
Florin Coras6cf30ad2017-04-04 23:08:23 -070026 APP_CLIENT,
27 APP_N_TYPES
Dave Barach68b0fb02017-02-28 15:15:56 -050028} application_type_t;
29
30typedef struct _stream_session_cb_vft
31{
32 /** Notify server of new segment */
33 int (*add_segment_callback) (u32 api_client_index, const u8 * seg_name,
34 u32 seg_size);
35
36 /** Notify server of newly accepted session */
37 int (*session_accept_callback) (stream_session_t * new_session);
38
Florin Corascea194d2017-10-02 00:18:51 -070039 /** Connection request callback */
Florin Corasab0289a2017-08-14 11:25:25 -070040 int (*session_connected_callback) (u32 app_index, u32 opaque,
Dave Barach68b0fb02017-02-28 15:15:56 -050041 stream_session_t * s, u8 code);
42
43 /** Notify app that session is closing */
44 void (*session_disconnect_callback) (stream_session_t * s);
45
46 /** Notify app that session was reset */
47 void (*session_reset_callback) (stream_session_t * s);
48
Florin Corascea194d2017-10-02 00:18:51 -070049 /** Direct RX callback, for built-in servers */
Florin Coras6792ec02017-03-13 03:49:51 -070050 int (*builtin_server_rx_callback) (stream_session_t * session);
Dave Barach68b0fb02017-02-28 15:15:56 -050051
Florin Corascea194d2017-10-02 00:18:51 -070052 /** Redirect connection to local server */
Dave Barach68b0fb02017-02-28 15:15:56 -050053 int (*redirect_connect_callback) (u32 api_client_index, void *mp);
54} session_cb_vft_t;
55
56typedef struct _application
57{
58 /** Index in server pool */
59 u32 index;
60
61 /** Flags */
62 u32 flags;
63
Florin Coras6cf30ad2017-04-04 23:08:23 -070064 /*
65 * Binary API interface to external app
66 */
67
Dave Barach68b0fb02017-02-28 15:15:56 -050068 /** Binary API connection index, ~0 if internal */
69 u32 api_client_index;
70
Florin Corascea194d2017-10-02 00:18:51 -070071 /** Namespace the application belongs to */
72 u32 ns_index;
73
Dave Barach68b0fb02017-02-28 15:15:56 -050074 /** Application listens for events on this svm queue */
75 unix_shared_memory_queue_t *event_queue;
76
Dave Barach68b0fb02017-02-28 15:15:56 -050077 /*
78 * Callbacks: shoulder-taps for the server/client
79 */
Florin Coras6cf30ad2017-04-04 23:08:23 -070080
Dave Barach68b0fb02017-02-28 15:15:56 -050081 session_cb_vft_t cb_fns;
Florin Coras6cf30ad2017-04-04 23:08:23 -070082
83 /*
84 * svm segment management
85 */
86 u32 connects_seg_manager;
87
Florin Corasc87c91d2017-08-16 19:55:49 -070088 /** Lookup tables for listeners. Value is segment manager index */
Florin Coras6cf30ad2017-04-04 23:08:23 -070089 uword *listeners_table;
90
Florin Coras7999e832017-10-31 01:51:04 -070091 /**
92 * First segment manager has in the the first segment the application's
Florin Corasc87c91d2017-08-16 19:55:49 -070093 * event fifo. Depending on what the app does, it may be either used for
Florin Coras7999e832017-10-31 01:51:04 -070094 * a listener or for connects.
95 */
Florin Coras6cf30ad2017-04-04 23:08:23 -070096 u32 first_segment_manager;
Florin Coras0e9c33b2017-08-14 22:33:41 -070097 u8 first_segment_manager_in_use;
Florin Coras6cf30ad2017-04-04 23:08:23 -070098
99 /** Segment manager properties. Shared by all segment managers */
Florin Corasad0c77f2017-11-09 18:00:15 -0800100 u32 sm_properties;
Florin Coras7999e832017-10-31 01:51:04 -0700101
102 u16 proxied_transports;
Dave Barach68b0fb02017-02-28 15:15:56 -0500103} application_t;
104
Florin Corascea194d2017-10-02 00:18:51 -0700105#define APP_INVALID_INDEX ((u32)~0)
Florin Corasa2ff7b82017-11-08 17:55:03 -0800106#define APP_DROP_INDEX (((u32)~0) - 1)
Florin Corascea194d2017-10-02 00:18:51 -0700107#define APP_NS_INVALID_INDEX ((u32)~0)
Florin Corasc87c91d2017-08-16 19:55:49 -0700108#define APP_INVALID_SEGMENT_MANAGER_INDEX ((u32) ~0)
109
Florin Coras6cf30ad2017-04-04 23:08:23 -0700110application_t *application_new ();
Florin Corascea194d2017-10-02 00:18:51 -0700111int application_init (application_t * app, u32 api_client_index,
112 u64 * options, session_cb_vft_t * cb_fns);
Dave Barach68b0fb02017-02-28 15:15:56 -0500113void application_del (application_t * app);
114application_t *application_get (u32 index);
Florin Corase04c2992017-03-01 08:17:34 -0800115application_t *application_get_if_valid (u32 index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500116application_t *application_lookup (u32 api_client_index);
117u32 application_get_index (application_t * app);
118
Florin Corascea194d2017-10-02 00:18:51 -0700119int application_start_listen (application_t * app,
120 session_endpoint_t * tep, u64 * handle);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700121int application_stop_listen (application_t * srv, u64 handle);
Florin Corascea194d2017-10-02 00:18:51 -0700122int application_open_session (application_t * app, session_endpoint_t * tep,
123 u32 api_context);
Dave Barach68b0fb02017-02-28 15:15:56 -0500124int application_api_queue_is_full (application_t * app);
125
Florin Coras6cf30ad2017-04-04 23:08:23 -0700126segment_manager_t *application_get_listen_segment_manager (application_t *
127 app,
128 stream_session_t *
129 s);
130segment_manager_t *application_get_connect_segment_manager (application_t *
131 app);
Dave Barach52851e62017-08-07 09:35:25 -0400132int application_is_proxy (application_t * app);
Florin Coras7999e832017-10-31 01:51:04 -0700133int application_is_builtin (application_t * app);
134int application_is_builtin_proxy (application_t * app);
Florin Corasc87c91d2017-08-16 19:55:49 -0700135int application_add_segment_notify (u32 app_index, u32 fifo_segment_index);
Florin Corascea194d2017-10-02 00:18:51 -0700136u32 application_session_table (application_t * app, u8 fib_proto);
137u32 application_local_session_table (application_t * app);
138u8 *application_name_from_index (u32 app_index);
139
140u8 application_has_local_scope (application_t * app);
141u8 application_has_global_scope (application_t * app);
Florin Coras1c710452017-10-17 00:03:13 -0700142u32 application_n_listeners (application_t * app);
Florin Coras7999e832017-10-31 01:51:04 -0700143stream_session_t *application_first_listener (application_t * app,
144 u8 fib_proto,
145 u8 transport_proto);
146void application_setup_proxy (application_t * app);
147void application_remove_proxy (application_t * app);
148
Dave Barach68b0fb02017-02-28 15:15:56 -0500149#endif /* SRC_VNET_SESSION_APPLICATION_H_ */
150
151/*
152 * fd.io coding-style-patch-verification: ON
153 *
154 * Local Variables:
155 * eval: (c-set-style "gnu")
156 * End:
157 */