http_static: refactor to use http transport

Type: refactor

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I66396a1879eb3c87ef64783eab82a22896413cd0
This commit is contained in:
Florin Coras
2022-01-24 18:46:03 -08:00
committed by Damjan Marion
parent 1d88fb97be
commit 6a4a11f479
5 changed files with 285 additions and 783 deletions
+23 -2
View File
@@ -19,6 +19,8 @@
static http_main_t http_main;
#define HTTP_FIFO_THRESH (16 << 10)
const char *http_status_code_str[] = {
#define _(c, s, str) str,
foreach_http_status_code
@@ -126,7 +128,7 @@ http_ts_accept_callback (session_t *ts)
session_t *ts_listener, *as, *asl;
app_worker_t *app_wrk;
http_conn_t *lhc, *hc;
u32 hc_index;
u32 hc_index, thresh;
int rv;
ts_listener = listen_session_get_from_handle (ts->listener_handle);
@@ -186,6 +188,13 @@ http_ts_accept_callback (session_t *ts)
return rv;
}
/* Avoid enqueuing small chunks of data on transport tx notifications. If
* the fifo is small (under 16K) we set the threshold to it's size, meaning
* a notification will be given when the fifo empties.
*/
thresh = clib_min (svm_fifo_size (ts->tx_fifo), HTTP_FIFO_THRESH);
svm_fifo_set_deq_thresh (ts->tx_fifo, thresh);
http_conn_timer_start (hc);
return 0;
@@ -532,7 +541,7 @@ state_send_more_data (http_conn_t *hc, transport_send_params_t *sp)
if (sent && svm_fifo_set_event (ts->tx_fifo))
session_send_io_evt_to_thread (ts->tx_fifo, SESSION_IO_EVT_TX);
if (svm_fifo_max_enqueue (ts->tx_fifo) < 16 << 10)
if (svm_fifo_max_enqueue (ts->tx_fifo) < HTTP_FIFO_THRESH)
{
/* Deschedule http session and wait for deq notification if
* underlying ts tx fifo almost full */
@@ -832,6 +841,17 @@ http_app_tx_callback (void *session, transport_send_params_t *sp)
return 0;
}
static void
http_transport_get_endpoint (u32 hc_index, u32 thread_index,
transport_endpoint_t *tep, u8 is_lcl)
{
http_conn_t *hc = http_conn_get_w_thread (hc_index, thread_index);
session_t *ts;
ts = session_get_from_handle (hc->h_tc_session_handle);
session_get_endpoint (ts, tep, is_lcl);
}
static u8 *
format_http_connection (u8 *s, va_list *args)
{
@@ -937,6 +957,7 @@ static const transport_proto_vft_t http_proto = {
.custom_tx = http_app_tx_callback,
.get_connection = http_transport_get_connection,
.get_listener = http_transport_get_listener,
.get_transport_endpoint = http_transport_get_endpoint,
.format_connection = format_http_transport_connection,
.format_listener = format_http_transport_listener,
.transport_options = {
+1
View File
@@ -95,6 +95,7 @@ typedef enum http_content_type_
#define foreach_http_status_code \
_ (200, OK, "200 OK") \
_ (400, BAD_REQUEST, "400 Bad Request") \
_ (404, NOT_FOUND, "404 Not Found") \
_ (405, METHOD_NOT_ALLOWED, "405 Method Not Allowed") \
_ (500, INTERNAL_ERROR, "500 Internal Server Error")
+4 -5
View File
@@ -47,11 +47,10 @@ static void vl_api_http_static_enable_t_handler
mp->uri[ARRAY_LEN (mp->uri) - 1] = 0;
mp->www_root[ARRAY_LEN (mp->www_root) - 1] = 0;
rv = http_static_server_enable_api
(ntohl (mp->fifo_size),
ntohl (mp->cache_size_limit),
ntohl (mp->prealloc_fifos),
ntohl (mp->private_segment_size), mp->www_root, mp->uri);
rv =
hss_enable_api (ntohl (mp->fifo_size), ntohl (mp->cache_size_limit),
ntohl (mp->prealloc_fifos),
ntohl (mp->private_segment_size), mp->www_root, mp->uri);
REPLY_MACRO (VL_API_HTTP_STATIC_ENABLE_REPLY);
}
+11 -37
View File
@@ -64,20 +64,12 @@ typedef enum
HTTP_STATE_N_STATES,
} http_session_state_t;
typedef enum
{
CALLED_FROM_RX,
CALLED_FROM_TX,
CALLED_FROM_TIMER,
} http_state_machine_called_from_t;
typedef enum
{
HTTP_BUILTIN_METHOD_GET = 0,
HTTP_BUILTIN_METHOD_POST,
} http_builtin_method_type_t;
/** \brief Application session
*/
typedef struct
@@ -107,8 +99,6 @@ typedef struct
/** File cache pool index */
u32 cache_pool_index;
/** state machine called from... */
http_state_machine_called_from_t called_from;
} http_session_t;
/** \brief In-memory file data cache entry
@@ -136,16 +126,11 @@ typedef struct
/** Per thread vector of session pools */
http_session_t **sessions;
/** Session pool reader writer lock */
clib_rwlock_t sessions_lock;
/** vpp session to http session index map */
u32 **session_to_http_session;
clib_spinlock_t cache_lock;
/** Enable debug messages */
int debug_level;
/** vpp message/event queue */
svm_msg_q_t **vpp_queue;
/** Unified file data cache pool */
file_data_cache_t *cache_pool;
/** Hash table which maps file name to file data */
@@ -169,27 +154,17 @@ typedef struct
/** root path to be served */
u8 *www_root;
/** Server's event queue */
svm_queue_t *vl_input_queue;
/** API client handle */
u32 my_client_index;
/** Application index */
u32 app_index;
/** Process node index for event scheduling */
u32 node_index;
/** Cert and key pair for tls */
u32 ckpair_index;
/** Session cleanup timer wheel */
tw_timer_wheel_2t_1w_2048sl_t tw;
clib_spinlock_t tw_lock;
vlib_main_t *vlib_main;
/** Time base, so we can generate browser cache control http spew */
clib_timebase_t timebase;
/*
* Config
*/
/** Number of preallocated fifos, usually 0 */
u32 prealloc_fifos;
@@ -199,15 +174,14 @@ typedef struct
u32 fifo_size;
/** The bind URI, defaults to tcp://0.0.0.0/80 */
u8 *uri;
vlib_main_t *vlib_main;
} http_static_server_main_t;
/** Threshold for switching to ptr data in http msgs */
u32 use_ptr_thresh;
} hss_main_t;
extern http_static_server_main_t http_static_server_main;
extern hss_main_t hss_main;
int http_static_server_enable_api (u32 fifo_size, u32 cache_limit,
u32 prealloc_fifos,
u32 private_segment_size,
u8 * www_root, u8 * uri);
int hss_enable_api (u32 fifo_size, u32 cache_limit, u32 prealloc_fifos,
u32 private_segment_size, u8 *www_root, u8 *uri);
void http_static_server_register_builtin_handler
(void *fp, char *url, int type);
File diff suppressed because it is too large Load Diff