FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
http_static.h
Go to the documentation of this file.
1 
2 /*
3  * http_static.h - skeleton vpp engine plug-in header file
4  *
5  * Copyright (c) <current-year> <your-organization>
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #ifndef __included_http_static_h__
19 #define __included_http_static_h__
20 
21 #include <vnet/vnet.h>
24 #include <vnet/session/session.h>
25 #include <vnet/ip/ip.h>
26 #include <vnet/ethernet/ethernet.h>
27 
28 #include <vppinfra/hash.h>
29 #include <vppinfra/error.h>
30 #include <vppinfra/time_range.h>
32 #include <vppinfra/bihash_vec8_8.h>
33 
34 /** @file http_static.h
35  * Static http server definitions
36  */
37 
38 typedef struct
39 {
40  /* API message ID base */
42 
43  /* convenience */
47 
49 
50 /** \brief Session States
51  */
52 
53 typedef enum
54 {
55  /** Session is closed */
57  /** Session is established */
59  /** Session has sent an OK response */
61  /** Session has sent an HTML response */
63  /** Number of states */
66 
67 typedef enum
68 {
73 
74 typedef enum
75 {
79 
80 
81 /** \brief Application session
82  */
83 typedef struct
84 {
85  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
86  /** Base class instance variables */
87 #define _(type, name) type name;
89 #undef _
90  /** rx thread index */
92  /** rx buffer */
93  u8 *rx_buf;
94  /** vpp session index, handle */
95  u32 vpp_session_index;
96  u64 vpp_session_handle;
97  /** Timeout timer handle */
98  u32 timer_handle;
99  /** Fully-resolved file path */
101  /** File data, a vector */
103  /** Current data send offset */
105  /** Need to free data in detach_cache_entry */
107 
108  /** File cache pool index */
110  /** state machine called from... */
113 
114 /** \brief In-memory file data cache entry
115  */
116 typedef struct
117 {
118  /** Name of the file */
120  /** Contents of the file, as a u8 * vector */
122  /** Last time the cache entry was used */
124  /** Cache LRU links */
127  /** Reference count, so we don't recycle while referenced */
128  int inuse;
130 
131 /** \brief Main data structure
132  */
133 
134 typedef struct
135 {
136  /** Per thread vector of session pools */
138  /** Session pool reader writer lock */
140  /** vpp session to http session index map */
142 
143  /** Enable debug messages */
145 
146  /** vpp message/event queue */
148 
149  /** Unified file data cache pool */
151  /** Hash table which maps file name to file data */
152  BVT (clib_bihash) name_to_data;
153 
154  /** Hash tables for built-in GET and POST handlers */
157 
158  /** Current cache size */
160  /** Max cache size in bytes */
162  /** Number of cache evictions */
164 
165  /** Cache LRU listheads */
168 
169  /** root path to be served */
171 
172  /** Server's event queue */
174 
175  /** API client handle */
177 
178  /** Application index */
180 
181  /** Process node index for event scheduling */
183 
184  /** Cert and key pair for tls */
186 
187  /** Session cleanup timer wheel */
188  tw_timer_wheel_2t_1w_2048sl_t tw;
190 
191  /** Time base, so we can generate browser cache control http spew */
193 
194  /** Number of preallocated fifos, usually 0 */
196  /** Private segment size, usually 0 */
198  /** Size of the allocated rx, tx fifos, roughly 8K or so */
200  /** The bind URI, defaults to tcp://0.0.0.0/80 */
201  u8 *uri;
204 
206 
207 int http_static_server_enable_api (u32 fifo_size, u32 cache_limit,
208  u32 prealloc_fifos,
209  u32 private_segment_size,
210  u8 * www_root, u8 * uri);
211 
213  (void *fp, char *url, int type);
214 
215 #endif /* __included_http_static_h__ */
216 
217 /*
218  * fd.io coding-style-patch-verification: ON
219  *
220  * Local Variables:
221  * eval: (c-set-style "gnu")
222  * End:
223  */
http_static_main_t::vnet_main
vnet_main_t * vnet_main
Definition: http_static.h:45
HTTP_BUILTIN_METHOD_GET
@ HTTP_BUILTIN_METHOD_GET
Definition: http_static.h:76
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
CALLED_FROM_TX
@ CALLED_FROM_TX
Definition: http_static.h:70
http_static_main_t::vlib_main
vlib_main_t * vlib_main
Definition: http_static.h:44
http_session_t::data_offset
u32 data_offset
Current data send offset.
Definition: http_static.h:104
HTTP_STATE_CLOSED
@ HTTP_STATE_CLOSED
Session is closed.
Definition: http_static.h:56
CALLED_FROM_TIMER
@ CALLED_FROM_TIMER
Definition: http_static.h:71
http_builtin_method_type_t
http_builtin_method_type_t
Definition: http_static.h:74
http_static_server_register_builtin_handler
void http_static_server_register_builtin_handler(void *fp, char *url, int type)
Register a builtin GET or POST handler.
Definition: static_server.c:525
http_static_server_main_t::timebase
clib_timebase_t timebase
Time base, so we can generate browser cache control http spew.
Definition: http_static.h:192
http_static_server_main_t::vpp_queue
svm_msg_q_t ** vpp_queue
vpp message/event queue
Definition: http_static.h:147
HTTP_BUILTIN_METHOD_POST
@ HTTP_BUILTIN_METHOD_POST
Definition: http_static.h:77
CLIB_CACHE_LINE_ALIGN_MARK
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
http_static_main_t
Definition: http_static.h:38
HTTP_STATE_OK_SENT
@ HTTP_STATE_OK_SENT
Session has sent an OK response.
Definition: http_static.h:60
http_static_server_main_t::ckpair_index
u32 ckpair_index
Cert and key pair for tls.
Definition: http_static.h:185
http_session_t::path
u8 * path
Fully-resolved file path.
Definition: http_static.h:100
svm_queue_t
struct _svm_queue svm_queue_t
http_static_server_main_t::uri
u8 * uri
The bind URI, defaults to tcp://0.0.0.0/80.
Definition: http_static.h:201
u16
unsigned short u16
Definition: types.h:57
bihash_vec8_8.h
http_static_server_main_t::node_index
u32 node_index
Process node index for event scheduling.
Definition: http_static.h:182
HTTP_STATE_SEND_MORE_DATA
@ HTTP_STATE_SEND_MORE_DATA
Session has sent an HTML response.
Definition: http_static.h:62
http_static_server_main_t::cache_limit
u64 cache_limit
Max cache size in bytes.
Definition: http_static.h:161
file_data_cache_t::next_index
u32 next_index
Cache LRU links.
Definition: http_static.h:125
http_static_server_main_t::fifo_size
u32 fifo_size
Size of the allocated rx, tx fifos, roughly 8K or so.
Definition: http_static.h:199
http_static_server_main_t::private_segment_size
u32 private_segment_size
Private segment size, usually 0.
Definition: http_static.h:197
http_static_server_main_t::debug_level
int debug_level
Enable debug messages.
Definition: http_static.h:144
ethernet.h
file_data_cache_t::data
u8 * data
Contents of the file, as a u8 * vector.
Definition: http_static.h:121
http_static_server_main_t::last_index
u32 last_index
Definition: http_static.h:167
http_static_main
http_static_main_t http_static_main
Definition: http_static.c:37
error.h
clib_timebase_t
Definition: time_range.h:28
http_static_server_main_t::get_url_handlers
uword * get_url_handlers
Hash tables for built-in GET and POST handlers.
Definition: http_static.h:155
HTTP_STATE_N_STATES
@ HTTP_STATE_N_STATES
Number of states.
Definition: http_static.h:64
HTTP_STATE_ESTABLISHED
@ HTTP_STATE_ESTABLISHED
Session is established.
Definition: http_static.h:58
clib_spinlock_s
Definition: lock.h:51
clib_rw_lock_
Definition: lock.h:139
uword
u64 uword
Definition: types.h:112
http_static_server_main_t::app_index
u32 app_index
Application index.
Definition: http_static.h:179
http_session_t::free_data
int free_data
Need to free data in detach_cache_entry.
Definition: http_static.h:106
BVT
BVT(clib_bihash)
The table of adjacencies indexed by the rewrite string.
Definition: l2_fib.c:1069
f64
double f64
Definition: types.h:142
http_session_t::data
u8 * data
File data, a vector.
Definition: http_static.h:102
http_static_server_main_t::first_index
u32 first_index
Cache LRU listheads.
Definition: http_static.h:166
http_session_t
Application session.
Definition: http_server.c:40
http_session_t::cache_pool_index
u32 cache_pool_index
File cache pool index.
Definition: http_static.h:109
http_static_server_main_t::cache_pool
file_data_cache_t * cache_pool
Unified file data cache pool.
Definition: http_static.h:150
CALLED_FROM_RX
@ CALLED_FROM_RX
Definition: http_static.h:69
http_static_server_main_t::sessions_lock
clib_rwlock_t sessions_lock
Session pool reader writer lock.
Definition: http_static.h:139
svm_msg_q_
Definition: message_queue.h:72
http_static_server_main_t::prealloc_fifos
u32 prealloc_fifos
Number of preallocated fifos, usually 0.
Definition: http_static.h:195
http_session_t::called_from
http_state_machine_called_from_t called_from
state machine called from...
Definition: http_static.h:111
http_static_main_t::msg_id_base
u16 msg_id_base
Definition: http_static.h:41
vnet_main_t
Definition: vnet.h:76
http_static_server_main_t::sessions
http_session_t ** sessions
Per thread vector of session pools.
Definition: http_static.h:137
http_static_server_main_t::www_root
u8 * www_root
root path to be served
Definition: http_static.h:170
time_range.h
u64
unsigned long u64
Definition: types.h:89
ip.h
u32
unsigned int u32
Definition: types.h:88
http_static_server_main
http_static_server_main_t http_static_server_main
Definition: static_server.c:34
http_static_server_main_t::vl_input_queue
svm_queue_t * vl_input_queue
Server's event queue.
Definition: http_static.h:173
file_data_cache_t::prev_index
u32 prev_index
Definition: http_static.h:126
http_static_server_main_t::cache_evictions
u64 cache_evictions
Number of cache evictions.
Definition: http_static.h:163
foreach_app_session_field
#define foreach_app_session_field
flag for dgram mode
Definition: application_interface.h:298
http_static_server_main_t::post_url_handlers
uword * post_url_handlers
Definition: http_static.h:156
http_static_server_main_t::cache_size
u64 cache_size
Current cache size.
Definition: http_static.h:159
http_session_state_t
http_session_state_t
Session States.
Definition: http_static.h:53
vlib_main_t
Definition: main.h:102
application_interface.h
hash.h
file_data_cache_t::filename
u8 * filename
Name of the file.
Definition: http_static.h:119
u8
unsigned char u8
Definition: types.h:56
http_static_server_main_t::session_to_http_session
u32 ** session_to_http_session
vpp session to http session index map
Definition: http_static.h:141
session.h
http_static_server_main_t::tw
tw_timer_wheel_2t_1w_2048sl_t tw
Session cleanup timer wheel.
Definition: http_static.h:188
http_state_machine_called_from_t
http_state_machine_called_from_t
Definition: http_static.h:67
http_static_server_main_t
Main data structure.
Definition: http_static.h:134
http_static_server_enable_api
int http_static_server_enable_api(u32 fifo_size, u32 cache_limit, u32 prealloc_fifos, u32 private_segment_size, u8 *www_root, u8 *uri)
API helper function for vl_api_http_static_enable_t messages.
Definition: static_server.c:1348
http_static_server_main_t::my_client_index
u32 my_client_index
API client handle.
Definition: http_static.h:176
vnet.h
http_static_server_main_t::tw_lock
clib_spinlock_t tw_lock
Definition: http_static.h:189
tw_timer_2t_1w_2048sl.h
file_data_cache_t::inuse
int inuse
Reference count, so we don't recycle while referenced.
Definition: http_static.h:128
file_data_cache_t::last_used
f64 last_used
Last time the cache entry was used.
Definition: http_static.h:123
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
file_data_cache_t
In-memory file data cache entry.
Definition: http_static.h:116
application.h
http_static_server_main_t::vlib_main
vlib_main_t * vlib_main
Definition: http_static.h:202