43 #define _(type, name) type name; 76 tw_timer_wheel_2t_1w_2048sl_t
tw;
119 memset (hs, 0,
sizeof (*hs));
120 hs->session_index = hs - hsm->
sessions[thread_index];
141 memset (hs, 0xfa,
sizeof (*hs));
180 hs->
timer_handle = tw_timer_start_2t_1w_2048sl (&http_server_main.
tw,
191 tw_timer_stop_2t_1w_2048sl (&http_server_main.
tw, hs->
timer_handle);
245 "HTTP/1.1 200 OK\r\n";
248 "Content-Type: text/html\r\n" 249 "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" 250 "Connection: close \r\n" 251 "Pragma: no-cache\r\n" 252 "Content-Length: %d\r\n\r\n%s";
256 "Content-Type: text/html\r\n" 257 "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" 258 "Connection: close\r\n" 259 "Pragma: no-cache\r\n" 260 "Content-Length: 0\r\n\r\n";
264 "<html><head><title>%v</title></head>" 265 "<link rel=\"icon\" href=\"data:,\">" 269 "</pre></body></html>\r\n";
272 "<html><head><title>static reply</title></head>" 273 "<link rel=\"icon\" href=\"data:,\">" 274 "<body><pre>hello</pre></body></html>\r\n";
283 u8 **output_vecp = (
u8 **) arg;
287 output_vec = *output_vecp;
293 *output_vecp = output_vec;
306 bytes_to_send =
vec_len (data);
309 while (bytes_to_send > 0)
314 (hs->tx_fifo, bytes_to_send, data + offset);
317 if (actual_transfer <= 0)
338 offset += actual_transfer;
339 bytes_to_send -= actual_transfer;
363 u8 *
request = 0, *reply = 0, *http = 0, *html = 0;
386 for (i = 0; i <
vec_len (request) - 4; i++)
388 if (request[i] ==
'G' &&
389 request[i + 1] ==
'E' &&
390 request[i + 2] ==
'T' && request[i + 3] ==
' ')
405 if (request[i] ==
'/')
407 else if (request[i] ==
' ')
410 _vec_len (request) =
i;
429 html =
format (html,
"%v", reply);
470 .process_log2_n_stack_bytes = 16,
471 .runtime_data_bytes =
sizeof (
void *),
474 name = (
char *)
format (0,
"http-cli-%d", l);
502 u32 max_dequeue, cursize;
513 ASSERT (n_read == max_dequeue);
517 _vec_len (hs->
rx_buf) = cursize + n_read;
574 request_len =
vec_len (request);
581 for (i = 0; i < request_len - 4; i++)
583 if (request[i] ==
'G' &&
584 request[i + 1] ==
'E' &&
585 request[i + 2] ==
'T' && request[i + 3] ==
' ')
594 if (request[request_len - 1] != 0xa || request[request_len - 3] != 0xa
595 || request[request_len - 2] != 0xd || request[request_len - 4] != 0xd)
723 u32 segment_size = 128 << 20;
731 a->api_client_index = ~0;
732 a->name =
format (0,
"test_http_server");
753 a_cert->app_index = a->app_index;
759 a_key->app_index = a->app_index;
774 a->uri =
"tcp://0.0.0.0/80";
776 a->uri = (
char *) hsm->
uri;
800 for (i = 0; i <
vec_len (expired_timers); i++)
803 hs_handle = expired_timers[
i] & 0x7FFFFFFF;
815 f64 now, timeout = 1.0;
816 uword *event_data = 0;
817 uword __clib_unused event_type;
827 tw_timer_expire_timers_2t_1w_2048sl (&hsm->
tw, now);
840 .name =
"http-server-process",
841 .state = VLIB_NODE_STATE_DISABLED,
876 VLIB_NODE_STATE_POLLING);
905 if (
unformat (line_input,
"static"))
910 else if (
unformat (line_input,
"private-segment-size %U",
913 if (seg_size >= 0x100000000ULL)
923 else if (
unformat (line_input,
"uri %s", &hsm->
uri))
960 .path =
"test http server",
961 .short_help =
"test http server",
static void http_server_session_timer_start(http_session_t *hs)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
#define foreach_app_session_field
flag for dgram mode
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
static void http_server_sessions_reader_unlock(void)
static int app_recv_stream_raw(svm_fifo_t *f, u8 *buf, u32 len, u8 clear_evt, u8 peek)
vlib_main_t vlib_global_main
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
static uword http_server_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
static int http_server_create(vlib_main_t *vm)
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
static const char * html_header_template
svm_queue_t * vl_input_queue
static const char * http_response
u32 session_index
Index in thread pool where session was allocated.
static int session_rx_request(http_session_t *hs)
static svm_msg_q_t * session_main_get_vpp_event_queue(u32 thread_index)
u32 timer_handle
Timeout timer handle.
#define clib_memcpy_fast(a, b, c)
static void http_server_sessions_writer_unlock(void)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
static int http_server_session_connected_callback(u32 app_index, u32 api_context, session_t *s, u8 is_fail)
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
u32 vpp_session_index
vpp session index, handle
void session_send_rpc_evt_to_thread(u32 thread_index, void *fp, void *rpc_args)
static int svm_fifo_is_empty_cons(svm_fifo_t *f)
Check if fifo is empty optimized for consumer.
static void http_process_free(http_server_args *args)
static int http_server_rx_callback_static(session_t *s)
struct _vnet_application_add_tls_cert_args_t vnet_app_add_tls_cert_args_t
static void http_server_session_lookup_add(u32 thread_index, u32 s_index, u32 hs_index)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
clib_error_t * vnet_app_add_tls_cert(vnet_app_add_tls_cert_args_t *a)
struct _vnet_bind_args_t vnet_listen_args_t
static void alloc_http_process_callback(void *cb_args)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static session_handle_t session_handle(session_t *s)
static void http_server_session_disconnect(http_session_t *hs)
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
static int http_server_session_accept_callback(session_t *s)
int(* builtin_app_rx_callback)(session_t *session)
Direct RX callback for built-in application.
#define VLIB_INIT_FUNCTION(x)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
struct _vnet_disconnect_args_t vnet_disconnect_args_t
static const u32 test_srv_key_rsa_len
static void http_expired_timers_dispatch(u32 *expired_timers)
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
foreach_app_session_field u32 thread_index
rx thread index
static int http_server_rx_callback(session_t *s)
static int http_server_listen()
#define clib_error_return(e, args...)
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
tw_timer_wheel_2t_1w_2048sl_t tw
static void http_server_sessions_writer_lock(void)
struct _vnet_app_attach_args_t vnet_app_attach_args_t
static void http_server_session_free(http_session_t *hs)
static void clib_spinlock_init(clib_spinlock_t *p)
static session_cb_vft_t http_server_session_cb_vft
clib_error_t * vnet_app_add_tls_key(vnet_app_add_tls_key_args_t *a)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void clib_rwlock_init(clib_rwlock_t *p)
static void clib_rwlock_reader_unlock(clib_rwlock_t *p)
static const char * html_header_static
#define pool_put(P, E)
Free an object E in pool P.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
int svm_fifo_enqueue(svm_fifo_t *f, u32 len, const u8 *src)
Enqueue data to fifo.
static void * vlib_node_get_runtime_data(vlib_main_t *vm, u32 node_index)
Get node runtime private data by node index.
static void svm_fifo_unset_event(svm_fifo_t *f)
Unset fifo event flag.
static const char * html_footer
u32 node_index
Node index.
static const char test_srv_crt_rsa[]
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
int vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
#define VLIB_REGISTER_NODE(x,...)
static_always_inline uword vlib_get_thread_index(void)
static int http_server_attach()
#define vec_free(V)
Free vector's memory (no header).
vlib_node_registration_t http_server_process_node
(constructor) VLIB_REGISTER_NODE (http_server_process_node)
#define clib_warning(format, args...)
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
u32 ** session_to_http_session
static const char test_srv_key_rsa[]
#define VLIB_CLI_COMMAND(x,...)
#define uword_to_pointer(u, type)
static http_session_t * http_server_session_get(u32 thread_index, u32 hs_index)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
u32 vlib_register_node(vlib_main_t *vm, vlib_node_registration_t *r)
static void clib_mem_free(void *p)
struct _vnet_application_add_tls_key_args_t vnet_app_add_tls_key_args_t
static void http_server_session_lookup_del(u32 thread_index, u32 s_index)
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
static void http_server_session_timer_stop(http_session_t *hs)
static void * clib_mem_alloc(uword size)
int vlib_cli_input(vlib_main_t *vm, unformat_input_t *input, vlib_cli_output_function_t *function, uword function_arg)
static uword pointer_to_uword(const void *p)
static vlib_main_t * vlib_get_main(void)
u8 thread_index
Index of the thread that allocated the session.
uword * handler_by_get_request
static http_session_t * http_server_session_alloc(u32 thread_index)
static void http_server_session_cleanup_cb(void *hs_handlep)
struct _vlib_node_registration vlib_node_registration_t
static clib_error_t * http_server_main_init(vlib_main_t *vm)
http_server_main_t http_server_main
static void alloc_http_process(http_server_args *args)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void vlib_rpc_call_main_thread(void *callback, u8 *args, u32 arg_size)
volatile u8 session_state
State in session layer state machine.
static void close_session(http_session_t *hs)
int vnet_bind_uri(vnet_listen_args_t *a)
static int http_server_add_segment_callback(u32 client_index, u64 segment_handle)
int vnet_disconnect_session(vnet_disconnect_args_t *a)
static clib_error_t * http_server_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
struct _svm_queue svm_queue_t
static const char * http_error_template
struct clib_bihash_value offset
template key/value backing page structure
static struct option options[]
static vlib_thread_main_t * vlib_get_thread_main()
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
static void http_server_session_cleanup(http_session_t *hs)
static const char * http_ok
int(* session_accept_callback)(session_t *new_session)
Notify server of newly accepted session.
http_session_t ** sessions
void vlib_start_process(vlib_main_t *vm, uword process_index)
static http_session_t * http_server_session_lookup(u32 thread_index, u32 s_index)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static void http_server_session_reset_callback(session_t *s)
static void http_cli_output(uword arg, u8 *buffer, uword buffer_bytes)
static const u32 test_srv_crt_rsa_len
void send_data(http_session_t *hs, u8 *data)
u32 * free_http_cli_process_node_indices
static void http_server_session_disconnect_callback(session_t *s)
static uword http_cli_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
static void http_server_sessions_reader_lock(void)
static void send_error(http_session_t *hs, char *str)
clib_rwlock_t sessions_lock