2022-07-28 15:12:46 +08:00
|
|
|
/*
|
|
|
|
|
**********************************************************************************************
|
|
|
|
|
* File: main.cpp
|
|
|
|
|
* Description: stellar main entry
|
|
|
|
|
*
|
|
|
|
|
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
|
|
|
|
|
***********************************************************************************************
|
|
|
|
|
*/
|
2022-07-26 15:05:14 +08:00
|
|
|
|
2022-07-24 23:59:00 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <unistd.h>
|
2022-07-06 23:18:13 +08:00
|
|
|
|
2022-08-11 09:38:38 +08:00
|
|
|
#include "global_var.h"
|
|
|
|
|
#include "logger.h"
|
2022-07-06 23:18:13 +08:00
|
|
|
#include "packet_io.h"
|
|
|
|
|
#include "session_manager.h"
|
|
|
|
|
#include "plugin_manager.h"
|
|
|
|
|
#include "http.h"
|
|
|
|
|
|
2022-07-20 20:20:31 +08:00
|
|
|
struct stellar_event_base_loop_arg
|
2022-07-06 23:18:13 +08:00
|
|
|
{
|
2022-07-14 14:46:16 +08:00
|
|
|
struct packet_io_device *dev;
|
2022-07-27 14:11:29 +08:00
|
|
|
struct session_manager *session_mgr;
|
|
|
|
|
struct plugin_manager *plug_mgr;
|
2022-07-24 23:59:00 +08:00
|
|
|
int tid;
|
2022-07-06 23:18:13 +08:00
|
|
|
};
|
|
|
|
|
|
2022-07-24 23:59:00 +08:00
|
|
|
void *stellar_event_base_loop(void *arg)
|
2022-07-06 23:18:13 +08:00
|
|
|
{
|
2022-07-20 20:20:31 +08:00
|
|
|
struct stellar_packet *rx_pkt;
|
|
|
|
|
struct stellar_event *event;
|
2022-07-24 23:59:00 +08:00
|
|
|
struct stellar_event_base_loop_arg *thread_arg = (struct stellar_event_base_loop_arg *)arg;
|
2022-07-06 23:18:13 +08:00
|
|
|
while(1)
|
|
|
|
|
{
|
2022-08-11 09:38:38 +08:00
|
|
|
int fetch_num = packet_io_device_rx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1);
|
2022-07-06 23:18:13 +08:00
|
|
|
if(fetch_num > 0)
|
|
|
|
|
{
|
2022-07-24 23:59:00 +08:00
|
|
|
event = session_manager_commit(thread_arg->session_mgr, rx_pkt);
|
2022-07-06 23:18:13 +08:00
|
|
|
while(event)
|
|
|
|
|
{
|
2022-07-24 23:59:00 +08:00
|
|
|
plugin_manager_dispatch(thread_arg->plug_mgr ,event);
|
|
|
|
|
event = session_manager_fetch_event(thread_arg->session_mgr);
|
2022-07-06 23:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//clean session_manager event queue
|
2022-08-11 09:38:38 +08:00
|
|
|
packet_io_device_tx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1);
|
2022-07-06 23:18:13 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-08-09 15:58:46 +08:00
|
|
|
printf("no fetch num\n");
|
2022-07-06 23:18:13 +08:00
|
|
|
//dispatch to time event
|
|
|
|
|
|
|
|
|
|
//dispatch to trigger polling event
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-24 23:59:00 +08:00
|
|
|
return nullptr;
|
2022-07-06 23:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-07-28 20:30:48 +08:00
|
|
|
struct packet_io_device *
|
2022-07-28 21:22:44 +08:00
|
|
|
packet_io_init(const char *instance_name, const enum packet_io_run_mode mode, const int wrk_thread_num)
|
2022-07-06 23:18:13 +08:00
|
|
|
{
|
2022-08-10 10:20:12 +08:00
|
|
|
struct packet_io_instance *ppio_inst = packet_io_instance_create(instance_name, mode);
|
2022-07-28 20:30:48 +08:00
|
|
|
if (nullptr == ppio_inst) {
|
2022-07-26 15:05:14 +08:00
|
|
|
log_error(ST_ERR_PIO_INSTANCE, "packet_io instance init failed.");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-29 13:31:09 +08:00
|
|
|
struct packet_io_device *ppio_dev = packet_io_device_open(ppio_inst, "eth1", wrk_thread_num, wrk_thread_num);
|
2022-07-28 20:30:48 +08:00
|
|
|
if (nullptr == ppio_dev) {
|
2022-07-26 15:05:14 +08:00
|
|
|
log_error(ST_ERR_PIO_DEVICE, "packet_io device open failed.");
|
|
|
|
|
|
|
|
|
|
}
|
2022-07-28 20:30:48 +08:00
|
|
|
return ppio_dev;
|
2022-07-06 23:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
|
{
|
2022-08-11 09:38:38 +08:00
|
|
|
//packet_io_init
|
|
|
|
|
struct packet_io_device *dev = packet_io_init("stellar", PACKET_IO_RUN_MODE_PCAP_LIVE, 2);
|
2022-07-26 15:05:14 +08:00
|
|
|
|
2022-07-24 23:59:00 +08:00
|
|
|
//manager_init
|
2022-07-27 14:11:29 +08:00
|
|
|
struct session_manager *session_mgr = session_manager_init();
|
2022-07-27 15:51:07 +08:00
|
|
|
struct plugin_manager *plug_mgr = plugin_manager_create();
|
2022-07-06 23:18:13 +08:00
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
// register build-in plugin
|
2022-08-17 18:08:33 +08:00
|
|
|
plugin_manager_register(plug_mgr, "HTTP", SESSION_EVENT_ALL, http_entry);
|
2022-07-28 15:12:46 +08:00
|
|
|
|
2022-07-24 23:59:00 +08:00
|
|
|
// load external plugins
|
2022-07-27 18:32:22 +08:00
|
|
|
char file_path[] = "./plugs/plugins.inf";
|
2022-08-03 19:46:43 +08:00
|
|
|
plugin_manager_load(plug_mgr, file_path);
|
2022-07-06 23:18:13 +08:00
|
|
|
|
2022-07-24 23:59:00 +08:00
|
|
|
//create_worker_thread
|
|
|
|
|
stellar_event_base_loop_arg arg = {dev, session_mgr, plug_mgr, 0};
|
|
|
|
|
pthread_t worker_pid;
|
2022-08-11 09:38:38 +08:00
|
|
|
pthread_create(&worker_pid, nullptr, stellar_event_base_loop, (void *)&arg);
|
2022-07-06 23:18:13 +08:00
|
|
|
//main_loop
|
2022-07-24 23:59:00 +08:00
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
/* main loop code */
|
|
|
|
|
usleep(1);
|
|
|
|
|
}
|
2022-07-27 15:51:07 +08:00
|
|
|
|
2022-07-27 18:32:22 +08:00
|
|
|
plugin_manager_unload(plug_mgr);
|
2022-07-27 15:51:07 +08:00
|
|
|
plugin_manager_destory(plug_mgr);
|
2022-07-24 23:59:00 +08:00
|
|
|
|
2022-07-06 23:18:13 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|