91 "Content-Type: text/html\r\n" 92 "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" 93 "Connection: close\r\n" 94 "Pragma: no-cache\r\n" "Content-Length: %d\r\n\r\n%s";
98 "Content-Type: text/html\r\n" 99 "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" 100 "Connection: close\r\n" "Pragma: no-cache\r\n" "Content-Length: 0\r\n\r\n";
105 "</head><link rel=\"icon\" href=\"data:,\"><body><pre>";
111 "<link rel=\"icon\" href=\"data:,\"><body><pre>hello</pre></body>" 119 u8 **output_vecp = (
u8 **) arg;
123 output_vec = *output_vecp;
127 clib_memcpy (output_vec + offset, buffer, buffer_bytes);
129 *output_vecp = output_vec;
135 session_fifo_event_t evt;
142 bytes_to_send =
vec_len (data);
145 while (bytes_to_send > 0)
150 (s->server_tx_fifo, bytes_to_send, data + offset);
153 if (actual_transfer <= 0)
169 offset += actual_transfer;
170 bytes_to_send -= actual_transfer;
175 evt.fifo = s->server_tx_fifo;
208 u8 *http = 0, *html = 0;
215 request = (
u8 *) (
void *) (args->
data);
222 for (i = 0; i <
vec_len (request) - 4; i++)
224 if (request[i] ==
'G' &&
225 request[i + 1] ==
'E' &&
226 request[i + 2] ==
'T' && request[i + 3] ==
' ')
241 if (request[i] ==
'/')
243 else if (request[i] ==
' ')
246 _vec_len (request) =
i;
265 html =
format (html,
"%v", reply);
305 .process_log2_n_stack_bytes = 16,
306 .runtime_data_bytes =
sizeof (
void *),
309 name = (
char *)
format (0,
"http-cli-%d", l);
341 rx_fifo = s->server_rx_fifo;
348 _vec_len (hsm->
rx_buf[s->thread_index]) = max_dequeue;
351 hsm->
rx_buf[s->thread_index]);
352 ASSERT (actual_transfer > 0);
353 _vec_len (hsm->
rx_buf[s->thread_index]) = actual_transfer;
376 session_fifo_event_t evt;
378 evt.rpc_args.arg = args;
401 request = hsm->
rx_buf[s->thread_index];
408 for (i = 0; i <
vec_len (request) - 4; i++)
410 if (request[i] ==
'G' &&
411 request[i + 1] ==
'E' &&
412 request[i + 2] ==
'T' && request[i + 3] ==
' ')
471 const u8 * seg_name,
u32 seg_size)
513 u8 segment_name[128];
516 u32 segment_size = 128 << 20;
518 memset (a, 0,
sizeof (*a));
519 memset (options, 0,
sizeof (options));
526 a->options = options;
534 a->segment_name = segment_name;
535 a->segment_name_length =
ARRAY_LEN (segment_name);
551 memset (a, 0,
sizeof (*a));
553 a->uri =
"tcp://0.0.0.0/80";
589 int rv, is_static = 0;
602 else if (
unformat (input,
"private-segment-size %U",
605 if (seg_size >= 0x100000000ULL)
645 .path =
"test http server",
646 .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)
vlib_main_t vlib_global_main
sll srl srl sll sra u16x4 i
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)
static int session_rx_request(stream_session_t *s)
unix_shared_memory_queue_t * vl_input_queue
static const char * http_error_template
static void alloc_http_process_callback(void *cb_args)
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 free_http_process(builtin_http_server_args *args)
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 _svm_fifo svm_fifo_t
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 alloc_http_process(builtin_http_server_args *args)
#define VLIB_INIT_FUNCTION(x)
struct _vnet_disconnect_args_t vnet_disconnect_args_t
static const char * html_header_static
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
Binary API shared-memory segment header pointer.
static int server_listen()
void stream_session_cleanup(stream_session_t *s)
Cleanup transport and session state.
struct _stream_session_t stream_session_t
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)
#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)
API main structure, used by both vpp and binary API clients.
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)
#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)
u32 vl_api_memclnt_create_internal(char *, unix_shared_memory_queue_t *)
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)
unix_shared_memory_queue_t * vl_input_queue
#define VLIB_CLI_COMMAND(x,...)
#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)
static int http_server_rx_callback_static(stream_session_t *s)
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)
uword * handler_by_get_request
static stream_session_t * session_get_from_handle(u64 handle)
static u64 session_handle(stream_session_t *s)
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)
clib_error_t * vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
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
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.
void vlib_start_process(vlib_main_t *vm, uword process_index)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
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 session_cb_vft_t builtin_session_cb_vft
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