43 #define _(type, name) type name; 79 tw_timer_wheel_2t_1w_2048sl_t
tw;
122 memset (hs, 0,
sizeof (*hs));
144 memset (hs, 0xfa,
sizeof (*hs));
184 hs->
timer_handle = tw_timer_start_2t_1w_2048sl (&http_server_main.
tw,
195 tw_timer_stop_2t_1w_2048sl (&http_server_main.
tw, hs->
timer_handle);
238 "HTTP/1.1 200 OK\r\n";
241 "Content-Type: text/html\r\n" 242 "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" 243 "Connection: close \r\n" 244 "Pragma: no-cache\r\n" 245 "Content-Length: %d\r\n\r\n%v";
249 "Content-Type: text/html\r\n" 250 "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" 251 "Connection: close\r\n" 252 "Pragma: no-cache\r\n" 253 "Content-Length: 0\r\n\r\n";
257 "<html><head><title>%v</title></head>" 258 "<link rel=\"icon\" href=\"data:,\">" 262 "</pre></body></html>\r\n";
265 "<html><head><title>static reply</title></head>" 266 "<link rel=\"icon\" href=\"data:,\">" 267 "<body><pre>hello</pre></body></html>\r\n";
276 u8 **output_vecp = (
u8 **) arg;
280 output_vec = *output_vecp;
286 *output_vecp = output_vec;
299 bytes_to_send =
vec_len (data);
302 while (bytes_to_send > 0)
307 (hs->tx_fifo, bytes_to_send, data + offset);
310 if (actual_transfer <= 0)
331 offset += actual_transfer;
332 bytes_to_send -= actual_transfer;
356 u8 *
request = 0, *reply = 0, *http = 0, *html = 0;
379 for (i = 0; i <
vec_len (request) - 4; i++)
381 if (request[i] ==
'G' &&
382 request[i + 1] ==
'E' &&
383 request[i + 2] ==
'T' && request[i + 3] ==
' ')
398 if (request[i] ==
'/')
400 else if (request[i] ==
' ')
403 _vec_len (request) =
i;
422 html =
format (html,
"%v", reply);
463 .process_log2_n_stack_bytes = 16,
464 .runtime_data_bytes =
sizeof (
void *),
467 name = (
char *)
format (0,
"http-cli-%d", l);
495 u32 max_dequeue, cursize;
506 ASSERT (n_read == max_dequeue);
510 _vec_len (hs->
rx_buf) = cursize + n_read;
567 request_len =
vec_len (request);
574 for (i = 0; i < request_len - 4; i++)
576 if (request[i] ==
'G' &&
577 request[i + 1] ==
'E' &&
578 request[i + 2] ==
'T' && request[i + 3] ==
' ')
587 if (request[request_len - 1] != 0xa || request[request_len - 3] != 0xa
588 || request[request_len - 2] != 0xd || request[request_len - 4] != 0xd)
721 u32 segment_size = 128 << 20;
729 a->api_client_index = ~0;
730 a->name =
format (0,
"test_http_server");
765 return proto == TRANSPORT_PROTO_TLS || proto == TRANSPORT_PROTO_DTLS ||
766 proto == TRANSPORT_PROTO_QUIC;
775 char *uri =
"tcp://0.0.0.0/80";
782 uri = (
char *) hsm->
uri;
792 a->sep_ext.ext_cfg->crypto.ckpair_index = hsm->
ckpair_index;
796 if (a->sep_ext.ext_cfg)
820 for (i = 0; i <
vec_len (expired_timers); i++)
823 hs_handle = expired_timers[
i] & 0x7FFFFFFF;
836 uword *event_data = 0;
837 uword __clib_unused event_type;
847 tw_timer_expire_timers_2t_1w_2048sl (&hsm->
tw, now);
860 .name =
"http-server-process",
861 .state = VLIB_NODE_STATE_DISABLED,
896 VLIB_NODE_STATE_POLLING);
925 if (
unformat (line_input,
"static"))
930 else if (
unformat (line_input,
"private-segment-size %U",
933 if (seg_size >= 0x100000000ULL)
943 else if (
unformat (line_input,
"uri %s", &hsm->
uri))
980 .path =
"test http server",
981 .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)
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
vnet_interface_output_runtime_t * rt
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)
int vnet_app_add_cert_key_pair(vnet_app_add_cert_key_pair_args_t *a)
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
vnet_hw_if_output_node_runtime_t * r
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.
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)
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)
static void http_server_session_lookup_add(u32 thread_index, u32 s_index, u32 hs_index)
int vlib_cli_input(vlib_main_t *vm, unformat_input_t *input, vlib_cli_output_function_t *function, uword function_arg)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
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)
#define clib_memcpy(d, s, n)
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)
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
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.
description fragment has unexpected format
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...)
static int http_server_session_connected_callback(u32 app_index, u32 api_context, session_t *s, session_error_t err)
pthread_t thread[MAX_CONNS]
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)
struct _session_endpoint_cfg session_endpoint_cfg_t
static session_cb_vft_t http_server_session_cb_vft
#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
static void http_server_session_close_cb(void *hs_handlep)
u32 vlib_register_node(vlib_main_t *vm, vlib_node_registration_t *r)
#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
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
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)
static void session_endpoint_alloc_ext_cfg(session_endpoint_cfg_t *sep_ext, transport_endpt_ext_cfg_type_t type)
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()
sll srl srl sll sra u16x4 i
#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.
static int http_transport_needs_crypto(transport_proto_t proto)
u32 ** session_to_http_session
static const char test_srv_key_rsa[]
#define VLIB_CLI_COMMAND(x,...)
static vlib_main_t * vlib_get_first_main(void)
#define uword_to_pointer(u, type)
static http_session_t * http_server_session_get(u32 thread_index, u32 hs_index)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
int vnet_listen(vnet_listen_args_t *a)
static void clib_mem_free(void *p)
enum _transport_proto transport_proto_t
static void http_server_session_lookup_del(u32 thread_index, u32 s_index)
struct _vnet_app_add_cert_key_pair_args_ vnet_app_add_cert_key_pair_args_t
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
static void http_server_session_timer_stop(http_session_t *hs)
static void * clib_mem_alloc(uword size)
static uword pointer_to_uword(const void *p)
static void http_server_cleanup_callback(session_t *s, session_cleanup_ntf_t ntf)
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)
struct _vlib_node_registration vlib_node_registration_t
static clib_error_t * http_server_main_init(vlib_main_t *vm)
int parse_uri(char *uri, session_endpoint_cfg_t *sep)
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)
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)
#define SESSION_ENDPOINT_CFG_NULL
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.
enum session_error_ session_error_t
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)
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