FD.io VPP  v20.05.1-5-g09f167997
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 */
91  u32 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  /** Session cleanup timer wheel */
185  tw_timer_wheel_2t_1w_2048sl_t tw;
187 
188  /** Time base, so we can generate browser cache control http spew */
190 
191  /** Number of preallocated fifos, usually 0 */
193  /** Private segment size, usually 0 */
195  /** Size of the allocated rx, tx fifos, roughly 8K or so */
197  /** The bind URI, defaults to tcp://0.0.0.0/80 */
198  u8 *uri;
201 
203 
204 int http_static_server_enable_api (u32 fifo_size, u32 cache_limit,
205  u32 prealloc_fifos,
206  u32 private_segment_size,
207  u8 * www_root, u8 * uri);
208 
210  (void *fp, char *url, int type);
211 
212 #endif /* __included_http_static_h__ */
213 
214 /*
215  * fd.io coding-style-patch-verification: ON
216  *
217  * Local Variables:
218  * eval: (c-set-style "gnu")
219  * End:
220  */
#define foreach_app_session_field
flag for dgram mode
u8 * filename
Name of the file.
Definition: http_static.h:119
u32 node_index
Process node index for event scheduling.
Definition: http_static.h:182
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
http_static_main_t http_static_main
Definition: http_static.c:37
unsigned long u64
Definition: types.h:89
u32 fifo_size
Size of the allocated rx, tx fifos, roughly 8K or so.
Definition: http_static.h:196
u32 data_offset
Current data send offset.
Definition: http_static.h:104
Main data structure.
Definition: http_static.h:134
u32 private_segment_size
Private segment size, usually 0.
Definition: http_static.h:194
int debug_level
Enable debug messages.
Definition: http_static.h:144
clib_timebase_t timebase
Time base, so we can generate browser cache control http spew.
Definition: http_static.h:189
u8 * path
Fully-resolved file path.
Definition: http_static.h:100
u32 prealloc_fifos
Number of preallocated fifos, usually 0.
Definition: http_static.h:192
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
svm_msg_q_t ** vpp_queue
vpp message/event queue
Definition: http_static.h:147
vnet_main_t * vnet_main
Definition: http_static.h:45
http_static_server_main_t http_static_server_main
Definition: static_server.c:34
u64 cache_size
Current cache size.
Definition: http_static.h:159
Number of states.
Definition: http_static.h:64
unsigned int u32
Definition: types.h:88
vlib_main_t * vlib_main
Definition: http_static.h:44
int free_data
Need to free data in detach_cache_entry.
Definition: http_static.h:106
vl_api_fib_path_type_t type
Definition: fib_types.api:123
u8 * data
Contents of the file, as a u8 * vector.
Definition: http_static.h:121
file_data_cache_t * cache_pool
Unified file data cache pool.
Definition: http_static.h:150
Session is closed.
Definition: http_static.h:56
u8 * data
File data, a vector.
Definition: http_static.h:102
unsigned short u16
Definition: types.h:57
http_state_machine_called_from_t
Definition: http_static.h:67
Application session.
Definition: http_server.c:40
uword * get_url_handlers
Hash tables for built-in GET and POST handlers.
Definition: http_static.h:155
http_session_state_t
Session States.
Definition: http_static.h:53
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.
BVT(clib_bihash)
Definition: l2_fib.c:972
f64 last_used
Last time the cache entry was used.
Definition: http_static.h:123
u32 ** session_to_http_session
vpp session to http session index map
Definition: http_static.h:141
http_session_t ** sessions
Per thread vector of session pools.
Definition: http_static.h:137
clib_rwlock_t sessions_lock
Session pool reader writer lock.
Definition: http_static.h:139
u32 cache_pool_index
File cache pool index.
Definition: http_static.h:109
u32 app_index
Application index.
Definition: http_static.h:179
u32 my_client_index
API client handle.
Definition: http_static.h:176
Session has sent an HTML response.
Definition: http_static.h:62
void http_static_server_register_builtin_handler(void *fp, char *url, int type)
Register a builtin GET or POST handler.
http_state_machine_called_from_t called_from
state machine called from...
Definition: http_static.h:111
u32 first_index
Cache LRU listheads.
Definition: http_static.h:166
http_builtin_method_type_t
Definition: http_static.h:74
svm_queue_t * vl_input_queue
Server&#39;s event queue.
Definition: http_static.h:173
tw_timer_wheel_2t_1w_2048sl_t tw
Session cleanup timer wheel.
Definition: http_static.h:185
Session is established.
Definition: http_static.h:58
u32 next_index
Cache LRU links.
Definition: http_static.h:125
Session has sent an OK response.
Definition: http_static.h:60
u64 uword
Definition: types.h:112
int inuse
Reference count, so we don&#39;t recycle while referenced.
Definition: http_static.h:128
u8 * uri
The bind URI, defaults to tcp://0.0.0.0/80.
Definition: http_static.h:198
struct _svm_queue svm_queue_t
u64 cache_evictions
Number of cache evictions.
Definition: http_static.h:163
clib_spinlock_t tw_lock
Definition: http_static.h:186
In-memory file data cache entry.
Definition: http_static.h:116
u8 * www_root
root path to be served
Definition: http_static.h:170
u64 cache_limit
Max cache size in bytes.
Definition: http_static.h:161