35 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 80 node_index = (
u64) (s->opaque[0]);
101 "Content-Type: text/html\r\n" 102 "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" 103 "Connection: close\r\n" 104 "Pragma: no-cache\r\n" "Content-Length: %d\r\n\r\n%s";
108 "Content-Type: text/html\r\n" 109 "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" 110 "Connection: close\r\n" "Pragma: no-cache\r\n" "Content-Length: 0\r\n\r\n";
115 "</head><link rel=\"icon\" href=\"data:,\"><body><pre>";
122 u8 **output_vecp = (
u8 **) arg;
126 output_vec = *output_vecp;
130 clib_memcpy (output_vec + offset, buffer, buffer_bytes);
132 *output_vecp = output_vec;
138 session_fifo_event_t evt;
145 bytes_to_send =
vec_len (data);
148 while (bytes_to_send > 0)
153 (s->server_tx_fifo, bytes_to_send, data + offset);
156 if (actual_transfer <= 0)
172 offset += actual_transfer;
173 bytes_to_send -= actual_transfer;
178 evt.fifo = s->server_tx_fifo;
211 u8 *http = 0, *html = 0;
216 request = (
u8 *) (
void *) (s->opaque[1]);
225 for (i = 0; i <
vec_len (request) - 4; i++)
227 if (request[i] ==
'G' &&
228 request[i + 1] ==
'E' &&
229 request[i + 2] ==
'T' && request[i + 3] ==
' ')
244 if (request[i] ==
'/')
246 else if (request[i] ==
' ')
249 _vec_len (request) =
i;
268 html =
format (html,
"%v", reply);
310 .process_log2_n_stack_bytes = 16,
311 .runtime_data_bytes =
sizeof (
void *),
314 name = (
char *)
format (0,
"http-cli-%d", l);
375 const u8 * seg_name,
u32 seg_size)
403 rx_fifo = s->server_rx_fifo;
413 _vec_len (hsm->
rx_buf) = max_dequeue;
417 ASSERT (actual_transfer > 0);
419 _vec_len (hsm->
rx_buf) = actual_transfer;
427 session_fifo_event_t evt;
429 evt.rpc_args.arg = s;
459 uword *event_data = 0, event_type;
469 memset (mp, 0,
sizeof (*mp));
470 mp->_vl_msg_id = VL_API_MEMCLNT_CREATE;
473 strncpy ((
char *) mp->
name,
"tcp_http_server",
sizeof (mp->
name) - 1);
502 u8 segment_name[128];
506 memset (a, 0,
sizeof (*a));
507 memset (options, 0,
sizeof (options));
511 a->options = options;
517 a->segment_name = segment_name;
518 a->segment_name_length =
ARRAY_LEN (segment_name);
534 memset (a, 0,
sizeof (*a));
536 a->uri =
"tcp://0.0.0.0/80";
580 #define foreach_tcp_http_server_api_msg \ 581 _(MEMCLNT_CREATE_REPLY, memclnt_create_reply) \ 589 #define _(N,n) do { \ 590 c->id = VL_API_##N; \ 592 c->handler = vl_api_##n##_t_handler; \ 593 c->cleanup = vl_noop_handler; \ 594 c->endian = vl_api_##n##_t_endian; \ 595 c->print = vl_api_##n##_t_print; \ 596 c->size = sizeof(vl_api_##n##_t); \ 599 c->message_bounce = 0; \ 600 vl_msg_api_config(c);} while (0); 630 .path =
"test http server",
631 .short_help =
"test http server",
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static void http_cli_output(uword arg, u8 *buffer, uword buffer_bytes)
sll srl srl sll sra u16x4 i
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...
vlib_node_runtime_t node_runtime
void vlib_cli_input(vlib_main_t *vm, unformat_input_t *input, vlib_cli_output_function_t *function, uword function_arg)
int vnet_bind_uri(vnet_bind_args_t *a)
void send_data(stream_session_t *s, u8 *data)
unix_shared_memory_queue_t * vl_input_queue
static const char * http_error_template
static f64 vlib_time_now(vlib_main_t *vm)
static int http_server_rx_callback(stream_session_t *s)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
struct _vlib_node_registration vlib_node_registration_t
static void alloc_http_process(stream_session_t *s)
static int builtin_add_segment_callback(u32 client_index, const u8 *seg_name, u32 seg_size)
static const char * http_response
static int server_attach()
struct _stream_session_t stream_session_t
struct _svm_fifo svm_fifo_t
static clib_error_t * tcp_http_server_api_hookup(vlib_main_t *vm)
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
unix_shared_memory_queue_t ** vpp_queue
static clib_error_t * server_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static void vl_api_memclnt_create_reply_t_handler(vl_api_memclnt_create_reply_t *mp)
#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 u32 svm_fifo_max_dequeue(svm_fifo_t *f)
static int builtin_session_connected_callback(u32 app_index, u32 api_context, stream_session_t *s, u8 is_fail)
struct _stream_session_cb_vft session_cb_vft_t
#define clib_error_return(e, args...)
struct vl_shmem_hdr_ * shmem_hdr
static int server_listen()
void stream_session_cleanup(stream_session_t *s)
Cleanup transport and session state.
static const char * html_header_template
struct _vnet_app_attach_args_t vnet_app_attach_args_t
http_server_main_t http_server_main
vl_shmem_hdr_t * shmem_hdr
int unix_shared_memory_queue_add(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
vlib_main_t vlib_global_main
#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.
u32 node_index
Node index.
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 unix_shared_memory_queue_t * session_manager_get_vpp_event_queue(u32 thread_index)
static_always_inline uword vlib_get_thread_index(void)
static vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
#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.
static void send_error(stream_session_t *s, char *str)
#define clib_memcpy(a, b, c)
int vnet_disconnect_session(vnet_disconnect_args_t *a)
int svm_fifo_enqueue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_from_here)
static int builtin_session_accept_callback(stream_session_t *s)
static int builtin_redirect_connect_callback(u32 client_index, void *mp)
void vlib_start_process(vlib_main_t *vm, uword process_index)
unix_shared_memory_queue_t * vl_input_queue
#define VLIB_CLI_COMMAND(x,...)
int vnet_application_attach(vnet_app_attach_args_t *a)
Attaches application.
#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 vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
static vlib_main_t * vlib_get_main(void)
uword * handler_by_get_request
static u64 stream_session_handle(stream_session_t *s)
void vl_api_memclnt_create_t_handler(vl_api_memclnt_create_t *mp)
static clib_error_t * builtin_http_server_main_init(vlib_main_t *vm)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static int create_api_loopback(vlib_main_t *vm)
static int server_create(vlib_main_t *vm)
static uword http_cli_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
struct clib_bihash_value offset
template key/value backing page structure
static const char * html_footer
#define foreach_tcp_http_server_api_msg
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.
int svm_fifo_dequeue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_here)
struct _vnet_bind_args_t vnet_bind_args_t
static void builtin_session_disconnect_callback(stream_session_t *s)
static void free_http_process(stream_session_t *s)
static session_cb_vft_t builtin_session_cb_vft
static void alloc_http_process_callback(void *s_arg)
static void builtin_session_reset_callback(stream_session_t *s)
u32 * free_http_cli_process_node_indices
struct _unix_shared_memory_queue unix_shared_memory_queue_t