#include #include #include #include "sce.h" #include "log.h" #include "utils.h" static void *worker_thread_cycle(void *arg) { struct thread_ctx *thread_ctx = (struct thread_ctx *)arg; struct packet_io *handle = thread_ctx->ref_io; int n_packet_recv; LOG_INFO("%s: worker thread %d running", LOG_TAG_SCE, thread_ctx->thread_index); while (1) { n_packet_recv = packet_io_polling_nf_interface(handle, thread_ctx->thread_index, thread_ctx); if (n_packet_recv) { LOG_INFO("%s: worker thread %d recv %03d packets from nf_interface", LOG_TAG_SCE, thread_ctx->thread_index, n_packet_recv); } n_packet_recv = packet_io_polling_endpoint(handle, thread_ctx->thread_index, thread_ctx); if (n_packet_recv) { LOG_INFO("%s: worker thread %d recv %03d packets from endpoint", LOG_TAG_SCE, thread_ctx->thread_index, n_packet_recv); } // TODO reset session_table } LOG_ERROR("%s: worker thread %d exiting", LOG_TAG_SCE, thread_ctx->thread_index); return (void *)NULL; } int main(int argc, char **argv) { const char *profile = "./conf/sce.conf"; struct sce_ctx *ctx = sce_ctx_create(profile); if (ctx == NULL) { return -1; } for (int i = 0; i < ctx->nr_worker_threads; i++) { ctx->work_threads[i].tid = 0; ctx->work_threads[i].thread_index = i; ctx->work_threads[i].session_table = session_table_create(); ctx->work_threads[i].ref_io = ctx->io; ctx->work_threads[i].ref_metrics = ctx->metrics; ctx->work_threads[i].ref_enforcer = ctx->enforcer; } for (int i = 0; i < ctx->nr_worker_threads; i++) { struct thread_ctx *thread_ctx = &ctx->work_threads[i]; if (pthread_create(&thread_ctx->tid, NULL, worker_thread_cycle, (void *)thread_ctx) < 0) { LOG_ERROR("%s: unable to create worker thread %d, error %d: %s", LOG_TAG_SCE, i, errno, strerror(errno)); goto error_out; } } while (1) { sleep(20); global_metrics_dump(ctx->metrics); } error_out: for (int i = 0; i < ctx->nr_worker_threads; i++) { struct thread_ctx *thread_ctx = &ctx->work_threads[i]; session_table_destory(thread_ctx->session_table); } sce_ctx_destory(ctx); return 0; }