|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
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));
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;
302 while (bytes_to_send > 0)
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;
422 html =
format (html,
"%v", reply);
463 .process_log2_n_stack_bytes = 16,
464 .runtime_data_bytes =
sizeof (
void *),
495 u32 max_dequeue, cursize;
506 ASSERT (n_read == max_dequeue);
510 _vec_len (hs->
rx_buf) = cursize + n_read;
574 for (
i = 0;
i < request_len - 4;
i++)
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;
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",
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static void clib_spinlock_init(clib_spinlock_t *p)
int vnet_listen(vnet_listen_args_t *a)
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
static void send_error(http_session_t *hs, char *str)
tw_timer_wheel_2t_1w_2048sl_t tw
enum session_error_ session_error_t
static void http_expired_timers_dispatch(u32 *expired_timers)
static void * vlib_node_get_runtime_data(vlib_main_t *vm, u32 node_index)
Get node runtime private data by node index.
static void http_process_free(http_server_args *args)
@ APP_OPTIONS_RX_FIFO_SIZE
u32 session_index
Index in thread pool where session was allocated.
static void http_server_session_lookup_del(u32 thread_index, u32 s_index)
static void http_server_session_lookup_add(u32 thread_index, u32 s_index, u32 hs_index)
static void svm_fifo_unset_event(svm_fifo_t *f)
Unset fifo event flag.
static void http_server_session_close_cb(void *hs_handlep)
#define clib_memcpy(d, s, n)
static vlib_cli_command_t http_server_create_command
(constructor) VLIB_CLI_COMMAND (http_server_create_command)
static clib_error_t * http_server_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
uword * handler_by_get_request
static uword pointer_to_uword(const void *p)
static const char * http_response
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
static void http_server_session_disconnect(http_session_t *hs)
static void http_server_sessions_reader_unlock(void)
static void clib_mem_free(void *p)
static void alloc_http_process(http_server_args *args)
int(* builtin_app_rx_callback)(session_t *session)
Direct RX callback for built-in application.
#define clib_error_return(e, args...)
struct _session_endpoint_cfg session_endpoint_cfg_t
static int app_recv_stream_raw(svm_fifo_t *f, u8 *buf, u32 len, u8 clear_evt, u8 peek)
pthread_t thread[MAX_CONNS]
struct _svm_queue svm_queue_t
static int http_server_attach()
u8 thread_index
Index of the thread that allocated the session.
#define pool_put(P, E)
Free an object E in pool P.
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
#define vec_delete(V, N, M)
Delete N elements starting at element M.
static void http_server_session_disconnect_callback(session_t *s)
@ APP_OPTIONS_SEGMENT_SIZE
foreach_app_session_field u32 thread_index
rx thread index
static void http_server_sessions_reader_lock(void)
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
static const char * http_ok
vnet_hw_if_output_node_runtime_t * r
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
static void clib_rwlock_reader_unlock(clib_rwlock_t *p)
void vlib_start_process(vlib_main_t *vm, uword process_index)
static void alloc_http_process_callback(void *cb_args)
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
http_session_t ** sessions
u32 vpp_session_index
vpp session index, handle
int(* session_accept_callback)(session_t *new_session)
Notify server of newly accepted session.
static void http_cli_output(uword arg, u8 *buffer, uword buffer_bytes)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
@ SESSION_CLEANUP_TRANSPORT
#define SESSION_ENDPOINT_CFG_NULL
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,...
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
@ SESSION_IO_EVT_BUILTIN_RX
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void session_endpoint_alloc_ext_cfg(session_endpoint_cfg_t *sep_ext, transport_endpt_ext_cfg_type_t type)
static const char * html_footer
static int http_server_session_connected_callback(u32 app_index, u32 api_context, session_t *s, session_error_t err)
struct _vnet_disconnect_args_t vnet_disconnect_args_t
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
u32 ** session_to_http_session
static int svm_fifo_is_empty_cons(svm_fifo_t *f)
Check if fifo is empty optimized for consumer.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
static http_session_t * http_server_session_get(u32 thread_index, u32 hs_index)
static const char test_srv_key_rsa[]
static svm_msg_q_t * session_main_get_vpp_event_queue(u32 thread_index)
struct clib_bihash_value offset
template key/value backing page structure
static_always_inline uword vlib_get_thread_index(void)
struct _vnet_bind_args_t vnet_listen_args_t
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
http_server_main_t http_server_main
static int http_server_listen()
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
@ SESSION_IO_EVT_TX_FLUSH
int vlib_cli_input(vlib_main_t *vm, unformat_input_t *input, vlib_cli_output_function_t *function, uword function_arg)
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
static void http_server_cleanup_callback(session_t *s, session_cleanup_ntf_t ntf)
void session_send_rpc_evt_to_thread(u32 thread_index, void *fp, void *rpc_args)
static void http_server_sessions_writer_lock(void)
static session_handle_t session_handle(session_t *s)
int svm_fifo_enqueue(svm_fifo_t *f, u32 len, const u8 *src)
Enqueue data to fifo.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
#define VLIB_CLI_COMMAND(x,...)
static int http_server_rx_callback_static(session_t *s)
int vnet_app_add_cert_key_pair(vnet_app_add_cert_key_pair_args_t *a)
struct _vlib_node_registration vlib_node_registration_t
int vnet_disconnect_session(vnet_disconnect_args_t *a)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static void clib_rwlock_init(clib_rwlock_t *p)
struct _vnet_app_add_cert_key_pair_args_ vnet_app_add_cert_key_pair_args_t
@ APP_OPTIONS_PREALLOC_FIFO_PAIRS
int vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
void send_data(http_session_t *hs, u8 *data)
#define vec_free(V)
Free vector's memory (no header).
clib_rwlock_t sessions_lock
@ APP_OPTIONS_TX_FIFO_SIZE
template key/value backing page structure
static http_session_t * http_server_session_alloc(u32 thread_index)
static void http_server_session_free(http_session_t *hs)
static const char test_srv_crt_rsa[]
@ APP_OPTIONS_ADD_SEGMENT_SIZE
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...
description fragment has unexpected format
static int http_server_rx_callback(session_t *s)
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
static const char * html_header_static
#define VLIB_INIT_FUNCTION(x)
static struct option options[]
enum _transport_proto transport_proto_t
static vlib_main_t * vlib_get_first_main(void)
u32 * free_http_cli_process_node_indices
static const char * html_header_template
static const u32 test_srv_crt_rsa_len
svm_queue_t * vl_input_queue
void vlib_rpc_call_main_thread(void *callback, u8 *args, u32 arg_size)
#define foreach_app_session_field
flag for dgram mode
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
int parse_uri(char *uri, session_endpoint_cfg_t *sep)
static session_cb_vft_t http_server_session_cb_vft
static void http_server_sessions_writer_unlock(void)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static int http_server_create(vlib_main_t *vm)
static int http_server_add_segment_callback(u32 client_index, u64 segment_handle)
static vlib_main_t * vlib_get_main(void)
static clib_error_t * http_server_main_init(vlib_main_t *vm)
vnet_interface_output_runtime_t * rt
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
#define uword_to_pointer(u, type)
#define clib_warning(format, args...)
static int session_rx_request(http_session_t *hs)
static uword http_cli_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
u32 vlib_register_node(vlib_main_t *vm, vlib_node_registration_t *r)
static void http_server_session_timer_start(http_session_t *hs)
static f64 vlib_time_now(vlib_main_t *vm)
struct _vnet_app_attach_args_t vnet_app_attach_args_t
static int http_transport_needs_crypto(transport_proto_t proto)
static vlib_thread_main_t * vlib_get_thread_main()
static uword http_server_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
static int http_server_session_accept_callback(session_t *s)
static http_session_t * http_server_session_lookup(u32 thread_index, u32 s_index)
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
volatile u8 session_state
State in session layer state machine.
@ TRANSPORT_ENDPT_EXT_CFG_CRYPTO
static void * clib_mem_alloc(uword size)
vlib_node_registration_t http_server_process_node
(constructor) VLIB_REGISTER_NODE (http_server_process_node)
static void http_server_session_reset_callback(session_t *s)
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
static const char * http_error_template
static const u32 test_srv_key_rsa_len
static void close_session(http_session_t *hs)
u32 timer_handle
Timeout timer handle.
#define VLIB_REGISTER_NODE(x,...)
static void http_server_session_timer_stop(http_session_t *hs)