VPP-659 TCP improvements
[vpp.git] / src / vnet / session / application.h
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>
21
22 typedef enum
23 {
24   APP_SERVER,
25   APP_CLIENT
26 } application_type_t;
27
28 typedef struct _stream_session_cb_vft
29 {
30   /** Notify server of new segment */
31   int (*add_segment_callback) (u32 api_client_index, const u8 * seg_name,
32                                u32 seg_size);
33
34   /** Notify server of newly accepted session */
35   int (*session_accept_callback) (stream_session_t * new_session);
36
37   /* Connection request callback */
38   int (*session_connected_callback) (u32 api_client_index,
39                                      stream_session_t * s, u8 code);
40
41   /** Notify app that session is closing */
42   void (*session_disconnect_callback) (stream_session_t * s);
43
44   /** Notify app that session was reset */
45   void (*session_reset_callback) (stream_session_t * s);
46
47   /* Direct RX callback, for built-in servers */
48   int (*builtin_server_rx_callback) (stream_session_t * session,
49                                      session_fifo_event_t * ep);
50
51   /* Redirect connection to local server */
52   int (*redirect_connect_callback) (u32 api_client_index, void *mp);
53 } session_cb_vft_t;
54
55 typedef struct _application
56 {
57   /** Index in server pool */
58   u32 index;
59
60   /** Flags */
61   u32 flags;
62
63   /** Binary API connection index, ~0 if internal */
64   u32 api_client_index;
65
66   /* */
67   u32 api_context;
68
69   /** Application listens for events on this svm queue */
70   unix_shared_memory_queue_t *event_queue;
71
72   /** Stream session type */
73   u8 session_type;
74
75   /* Stream server mode: accept or connect */
76   u8 mode;
77
78   u32 session_manager_index;
79
80   /*
81    * Bind/Listen specific
82    */
83
84   /** Accept cookie, for multiple session flavors ($$$ maybe) */
85   u32 accept_cookie;
86
87   /** Index of the listen session or connect session */
88   u32 session_index;
89
90   /** Session thread index for client connect sessions */
91   u32 thread_index;
92
93   /*
94    * Callbacks: shoulder-taps for the server/client
95    */
96   session_cb_vft_t cb_fns;
97 } application_t;
98
99 application_t *application_new (application_type_t type, session_type_t sst,
100                                 u32 api_client_index, u32 flags,
101                                 session_cb_vft_t * cb_fns);
102 void application_del (application_t * app);
103 application_t *application_get (u32 index);
104 application_t *application_get_if_valid (u32 index);
105 application_t *application_lookup (u32 api_client_index);
106 u32 application_get_index (application_t * app);
107
108 int
109 application_server_init (application_t * server, u32 segment_size,
110                          u32 add_segment_size, u32 rx_fifo_size,
111                          u32 tx_fifo_size, u8 ** segment_name);
112 int application_api_queue_is_full (application_t * app);
113
114 #endif /* SRC_VNET_SESSION_APPLICATION_H_ */
115
116 /*
117  * fd.io coding-style-patch-verification: ON
118  *
119  * Local Variables:
120  * eval: (c-set-style "gnu")
121  * End:
122  */