41 #define _(type, name) type name; 132 return &hsm->
sessions[thread_index][hs_index];
143 memset (hs, 0,
sizeof (*hs));
144 hs->session_index = hs - hsm->
sessions[thread_index];
162 memset (hs, 0xfa,
sizeof (*hs));
205 "HTTP/1.1 200 OK\r\n";
208 "Content-Type: text/html\r\n" 209 "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" 210 "Connection: close \r\n" 211 "Pragma: no-cache\r\n" 212 "Content-Length: %d\r\n\r\n%s";
216 "Content-Type: text/html\r\n" 217 "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" 218 "Connection: close\r\n" 219 "Pragma: no-cache\r\n" 220 "Content-Length: 0\r\n\r\n";
224 "<html><head><title>%v</title></head>" 225 "<link rel=\"icon\" href=\"data:,\">" 229 "</pre></body></html>\r\n";
232 "<html><head><title>static reply</title></head>" 233 "<link rel=\"icon\" href=\"data:,\">" 234 "<body><pre>hello</pre></body></html>\r\n";
243 u8 **output_vecp = (
u8 **) arg;
247 output_vec = *output_vecp;
253 *output_vecp = output_vec;
266 bytes_to_send =
vec_len (data);
269 while (bytes_to_send > 0)
274 (hs->tx_fifo, bytes_to_send, data + offset);
277 if (actual_transfer <= 0)
295 offset += actual_transfer;
296 bytes_to_send -= actual_transfer;
320 u8 *
request = 0, *reply = 0, *http = 0, *html = 0;
343 for (i = 0; i <
vec_len (request) - 4; i++)
345 if (request[i] ==
'G' &&
346 request[i + 1] ==
'E' &&
347 request[i + 2] ==
'T' && request[i + 3] ==
' ')
362 if (request[i] ==
'/')
364 else if (request[i] ==
' ')
367 _vec_len (request) =
i;
386 html =
format (html,
"%v", reply);
427 .process_log2_n_stack_bytes = 16,
428 .runtime_data_bytes =
sizeof (
void *),
431 name = (
char *)
format (0,
"http-cli-%d", l);
458 u32 max_dequeue, cursize;
469 ASSERT (n_read == max_dequeue);
473 _vec_len (hs->
rx_buf) = cursize + n_read;
532 request_len =
vec_len (request);
539 for (i = 0; i < request_len - 4; i++)
541 if (request[i] ==
'G' &&
542 request[i + 1] ==
'E' &&
543 request[i + 2] ==
'T' && request[i + 3] ==
' ')
552 if (request[request_len - 1] != 0xa || request[request_len - 3] != 0xa
553 || request[request_len - 2] != 0xd || request[request_len - 4] != 0xd)
595 hs->rx_fifo = s->server_rx_fifo;
596 hs->tx_fifo = s->server_tx_fifo;
682 u32 segment_size = 128 << 20;
690 a->api_client_index = ~0;
691 a->name =
format (0,
"test_http_server");
693 a->options = options;
712 a_cert->app_index = a->app_index;
718 a_key->app_index = a->app_index;
733 a->uri =
"tcp://0.0.0.0/80";
735 a->uri = (
char *) hsm->
uri;
786 else if (
unformat (input,
"private-segment-size %U",
789 if (seg_size >= 0x100000000ULL)
832 .path =
"test http server",
833 .short_help =
"test http server",
#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)
static void http_server_session_disconnect_callback(stream_session_t *s)
vlib_main_t vlib_global_main
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
static int http_server_create(vlib_main_t *vm)
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
const u32 test_srv_crt_rsa_len
static const char * html_header_template
void vlib_cli_input(vlib_main_t *vm, unformat_input_t *input, vlib_cli_output_function_t *function, uword function_arg)
svm_queue_t * vl_input_queue
static const char * http_response
int vnet_bind_uri(vnet_bind_args_t *a)
const u32 test_srv_key_rsa_len
static int session_rx_request(http_session_t *hs)
#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)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
void session_send_rpc_evt_to_thread(u32 thread_index, void *fp, void *rpc_args)
static void http_process_free(http_server_args *args)
static int http_server_session_accept_callback(stream_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)
static void alloc_http_process_callback(void *cb_args)
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 svm_fifo_is_empty(svm_fifo_t *f)
static svm_msg_q_t * session_manager_get_vpp_event_queue(u32 thread_index)
static int http_server_rx_callback_static(stream_session_t *s)
#define VLIB_INIT_FUNCTION(x)
struct _vnet_disconnect_args_t vnet_disconnect_args_t
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
struct _stream_session_cb_vft session_cb_vft_t
foreach_app_session_field u32 thread_index
static int http_server_listen()
#define clib_error_return(e, args...)
int svm_fifo_enqueue_nowait(svm_fifo_t *f, u32 max_bytes, const u8 *copy_from_here)
struct _stream_session_t stream_session_t
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
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 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)
static void http_server_session_reset_callback(stream_session_t *s)
#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 session_handle_t session_handle(stream_session_t *s)
#define pool_put(P, E)
Free an object E in pool P.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
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)
Unsets fifo event flag.
static const char * html_footer
u32 node_index
Node index.
const char test_srv_crt_rsa[]
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
static u8 svm_fifo_set_event(svm_fifo_t *f)
Sets fifo event flag.
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
static_always_inline uword vlib_get_thread_index(void)
static int http_server_attach()
static int http_server_session_connected_callback(u32 app_index, u32 api_context, stream_session_t *s, u8 is_fail)
#define vec_free(V)
Free vector's memory (no header).
#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.
int vnet_disconnect_session(vnet_disconnect_args_t *a)
u32 ** session_to_http_session
#define VLIB_CLI_COMMAND(x,...)
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 * clib_mem_alloc(uword size)
static vlib_main_t * vlib_get_main(void)
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)
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)
clib_error_t * vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
static int http_server_add_segment_callback(u32 client_index, u64 segment_handle)
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
static int http_server_rx_callback(stream_session_t *s)
struct clib_bihash_value offset
template key/value backing page structure
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
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,...)
struct _vnet_bind_args_t vnet_bind_args_t
static void http_cli_output(uword arg, u8 *buffer, uword buffer_bytes)
void send_data(http_session_t *hs, u8 *data)
const char test_srv_key_rsa[]
u32 * free_http_cli_process_node_indices
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