|
|
|
@ -5,11 +5,11 @@
|
|
|
|
|
|
|
|
|
|
#include "admissions_info.h"
|
|
|
|
|
#include "http.h"
|
|
|
|
|
#include "route_config.h"
|
|
|
|
|
#include "module_database.h"
|
|
|
|
|
#include "route_config.h"
|
|
|
|
|
#include "tcp_server.h"
|
|
|
|
|
|
|
|
|
|
#define HTTP_ROUTER_CAPACITY 32
|
|
|
|
|
#define HTTP_ROUTER_ROUTES_CAPACITY 32
|
|
|
|
|
|
|
|
|
|
/* Assumption: entrypoint is always _start. This should be enhanced later */
|
|
|
|
|
struct route {
|
|
|
|
@ -23,16 +23,15 @@ struct route {
|
|
|
|
|
struct admissions_info admissions_info;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct http_router {
|
|
|
|
|
struct route routes[HTTP_ROUTER_CAPACITY];
|
|
|
|
|
size_t route_length;
|
|
|
|
|
struct route routes[HTTP_ROUTER_ROUTES_CAPACITY];
|
|
|
|
|
size_t routes_length;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
http_router_init(struct http_router *router)
|
|
|
|
|
{
|
|
|
|
|
router->route_length = 0;
|
|
|
|
|
router->routes_length = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
@ -43,38 +42,37 @@ http_router_add_route(struct http_router *router, struct route_config *config, s
|
|
|
|
|
assert(module != NULL);
|
|
|
|
|
assert(config->route != NULL);
|
|
|
|
|
assert(config->http_resp_content_type != NULL);
|
|
|
|
|
assert(router->routes_length <= HTTP_ROUTER_ROUTES_CAPACITY);
|
|
|
|
|
|
|
|
|
|
if (router->route_length < HTTP_ROUTER_CAPACITY) {
|
|
|
|
|
router->routes[router->route_length] = (struct route){
|
|
|
|
|
.route = config->route,
|
|
|
|
|
.module = module,
|
|
|
|
|
.relative_deadline_us = config->relative_deadline_us,
|
|
|
|
|
.relative_deadline = (uint64_t)config->relative_deadline_us * runtime_processor_speed_MHz,
|
|
|
|
|
.response_size = config->http_resp_size,
|
|
|
|
|
.response_content_type = config->http_resp_content_type
|
|
|
|
|
};
|
|
|
|
|
if (unlikely(router->routes_length == HTTP_ROUTER_ROUTES_CAPACITY)) { return -1; }
|
|
|
|
|
|
|
|
|
|
/* Move strings from config */
|
|
|
|
|
config->route = NULL;
|
|
|
|
|
config->http_resp_content_type = NULL;
|
|
|
|
|
router->routes[router->routes_length] = (struct route){
|
|
|
|
|
.route = config->route,
|
|
|
|
|
.module = module,
|
|
|
|
|
.relative_deadline_us = config->relative_deadline_us,
|
|
|
|
|
.relative_deadline = (uint64_t)config->relative_deadline_us * runtime_processor_speed_MHz,
|
|
|
|
|
.response_size = config->http_resp_size,
|
|
|
|
|
.response_content_type = config->http_resp_content_type
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Admissions Control */
|
|
|
|
|
uint64_t expected_execution = (uint64_t)config->expected_execution_us * runtime_processor_speed_MHz;
|
|
|
|
|
admissions_info_initialize(&router->routes[router->route_length].admissions_info,
|
|
|
|
|
config->admissions_percentile, expected_execution,
|
|
|
|
|
router->routes[router->route_length].relative_deadline);
|
|
|
|
|
/* Move strings from config */
|
|
|
|
|
config->route = NULL;
|
|
|
|
|
config->http_resp_content_type = NULL;
|
|
|
|
|
|
|
|
|
|
router->route_length++;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/* Admissions Control */
|
|
|
|
|
uint64_t expected_execution = (uint64_t)config->expected_execution_us * runtime_processor_speed_MHz;
|
|
|
|
|
admissions_info_initialize(&router->routes[router->routes_length].admissions_info,
|
|
|
|
|
config->admissions_percentile, expected_execution,
|
|
|
|
|
router->routes[router->routes_length].relative_deadline);
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
router->routes_length++;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline struct route *
|
|
|
|
|
http_router_match_route(struct http_router *router, char *route)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < router->route_length; i++) {
|
|
|
|
|
for (int i = 0; i < router->routes_length; i++) {
|
|
|
|
|
if (strncmp(route, router->routes[i].route, strlen(router->routes[i].route)) == 0) {
|
|
|
|
|
return &router->routes[i];
|
|
|
|
|
}
|
|
|
|
|