Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 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 Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 21 | #include <vnet/session/segment_manager.h> |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 22 | #include <vnet/session/application_namespace.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 23 | typedef enum |
| 24 | { |
| 25 | APP_SERVER, |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 26 | APP_CLIENT, |
| 27 | APP_N_TYPES |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 28 | } application_type_t; |
| 29 | |
| 30 | typedef 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 Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 39 | /** Connection request callback */ |
Florin Coras | ab0289a | 2017-08-14 11:25:25 -0700 | [diff] [blame] | 40 | int (*session_connected_callback) (u32 app_index, u32 opaque, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 41 | 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 Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 49 | /** Direct RX callback, for built-in servers */ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 50 | int (*builtin_server_rx_callback) (stream_session_t * session); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 51 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 52 | /** Redirect connection to local server */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 53 | int (*redirect_connect_callback) (u32 api_client_index, void *mp); |
| 54 | } session_cb_vft_t; |
| 55 | |
| 56 | typedef struct _application |
| 57 | { |
| 58 | /** Index in server pool */ |
| 59 | u32 index; |
| 60 | |
| 61 | /** Flags */ |
| 62 | u32 flags; |
| 63 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 64 | /* |
| 65 | * Binary API interface to external app |
| 66 | */ |
| 67 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 68 | /** Binary API connection index, ~0 if internal */ |
| 69 | u32 api_client_index; |
| 70 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 71 | /** Namespace the application belongs to */ |
| 72 | u32 ns_index; |
| 73 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 74 | /** Application listens for events on this svm queue */ |
| 75 | unix_shared_memory_queue_t *event_queue; |
| 76 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 77 | /* |
| 78 | * Callbacks: shoulder-taps for the server/client |
| 79 | */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 80 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 81 | session_cb_vft_t cb_fns; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * svm segment management |
| 85 | */ |
| 86 | u32 connects_seg_manager; |
| 87 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 88 | /** Lookup tables for listeners. Value is segment manager index */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 89 | uword *listeners_table; |
| 90 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 91 | /** First segment manager has in the the first segment the application's |
| 92 | * event fifo. Depending on what the app does, it may be either used for |
| 93 | * a listener or for connects. */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 94 | u32 first_segment_manager; |
Florin Coras | 0e9c33b | 2017-08-14 22:33:41 -0700 | [diff] [blame] | 95 | u8 first_segment_manager_in_use; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 96 | |
| 97 | /** Segment manager properties. Shared by all segment managers */ |
| 98 | segment_manager_properties_t sm_properties; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 99 | } application_t; |
| 100 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 101 | #define APP_INVALID_INDEX ((u32)~0) |
| 102 | #define APP_NS_INVALID_INDEX ((u32)~0) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 103 | #define APP_INVALID_SEGMENT_MANAGER_INDEX ((u32) ~0) |
| 104 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 105 | application_t *application_new (); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 106 | int application_init (application_t * app, u32 api_client_index, |
| 107 | u64 * options, session_cb_vft_t * cb_fns); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 108 | void application_del (application_t * app); |
| 109 | application_t *application_get (u32 index); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 110 | application_t *application_get_if_valid (u32 index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 111 | application_t *application_lookup (u32 api_client_index); |
| 112 | u32 application_get_index (application_t * app); |
| 113 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 114 | int application_start_listen (application_t * app, |
| 115 | session_endpoint_t * tep, u64 * handle); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 116 | int application_stop_listen (application_t * srv, u64 handle); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 117 | int application_open_session (application_t * app, session_endpoint_t * tep, |
| 118 | u32 api_context); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 119 | int application_api_queue_is_full (application_t * app); |
| 120 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 121 | segment_manager_t *application_get_listen_segment_manager (application_t * |
| 122 | app, |
| 123 | stream_session_t * |
| 124 | s); |
| 125 | segment_manager_t *application_get_connect_segment_manager (application_t * |
| 126 | app); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 127 | int application_is_proxy (application_t * app); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 128 | int application_add_segment_notify (u32 app_index, u32 fifo_segment_index); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 129 | u32 application_session_table (application_t * app, u8 fib_proto); |
| 130 | u32 application_local_session_table (application_t * app); |
| 131 | u8 *application_name_from_index (u32 app_index); |
| 132 | |
| 133 | u8 application_has_local_scope (application_t * app); |
| 134 | u8 application_has_global_scope (application_t * app); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 135 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 136 | #endif /* SRC_VNET_SESSION_APPLICATION_H_ */ |
| 137 | |
| 138 | /* |
| 139 | * fd.io coding-style-patch-verification: ON |
| 140 | * |
| 141 | * Local Variables: |
| 142 | * eval: (c-set-style "gnu") |
| 143 | * End: |
| 144 | */ |