#include #include #include "tfe_cmsg.h" #include "tfe_tap_rss.h" #include "tfe_acceptor_kni.h" #include "tfe_metrics.h" /****************************************************************************** * session_ctx ******************************************************************************/ struct session_ctx *session_ctx_new() { struct session_ctx *ctx = (struct session_ctx *)calloc(1, sizeof(struct session_ctx)); assert(ctx != NULL); return ctx; } void session_ctx_free(struct session_ctx *ctx) { if (ctx) { if (ctx->cmsg) { tfe_cmsg_destroy(ctx->cmsg); } free(ctx); ctx = 0; } } /****************************************************************************** * acceptor_ctx ******************************************************************************/ struct acceptor_ctx *acceptor_ctx_create(const char *profile) { struct acceptor_ctx *ctx = ALLOC(struct acceptor_ctx, 1); MESA_load_profile_int_def(profile, "system", "firewall_sids", (int *)&(ctx->firewall_sids), 1001); MESA_load_profile_int_def(profile, "system", "service_chaining_sids", (int *)&(ctx->sce_sids), 1002); MESA_load_profile_int_def(profile, "system", "nr_worker_threads", (int *)&(ctx->nr_worker_threads), 8); MESA_load_profile_uint_range(profile, "system", "cpu_affinity_mask", TFE_THREAD_MAX, (unsigned int *)ctx->cpu_affinity_mask); ctx->nr_worker_threads = MIN(ctx->nr_worker_threads, TFE_THREAD_MAX); CPU_ZERO(&ctx->coremask); for (int i = 0; i < ctx->nr_worker_threads; i++) { int cpu_id = ctx->cpu_affinity_mask[i]; CPU_SET(cpu_id, &ctx->coremask); } ctx->io = packet_io_create(profile, ctx->nr_worker_threads, &ctx->coremask); if (ctx->io == NULL) { goto error_out; } ctx->config = tfe_tap_config_create(profile, ctx->nr_worker_threads); if (ctx->config == NULL) { goto error_out; } ctx->metrics = global_metrics_create(); if (ctx->metrics == NULL) { goto error_out; } return ctx; error_out: acceptor_ctx_destory(ctx); return NULL; } void acceptor_ctx_destory(struct acceptor_ctx * ctx) { if (ctx) { packet_io_destory(ctx->io); tfe_tap_destory(ctx->config); global_metrics_destory(ctx->metrics); free(ctx); ctx = NULL; } return; }