94 lines
2.4 KiB
C++
94 lines
2.4 KiB
C++
/*
|
|
**********************************************************************************************
|
|
* File: main.cpp
|
|
* Description: stellar main entry
|
|
*
|
|
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
|
|
***********************************************************************************************
|
|
*/
|
|
|
|
#include "./common/global_var.h"
|
|
#include "./packet_io/packet_io.h"
|
|
#include "./session_manager/session_manager.h"
|
|
#include "./plugin_manager/plugin_manager.h"
|
|
#include "../sdk/include/http.h"
|
|
#include "../sdk/include/logger.h"
|
|
|
|
struct packet_io_loop_arg
|
|
{
|
|
struct packet_io_device *dev;
|
|
int thread_id;
|
|
};
|
|
|
|
void packet_io_loop(struct packet_io_loop_arg *arg)
|
|
{
|
|
struct packet *rx_pkt;
|
|
struct session_event *event;
|
|
while(1)
|
|
{
|
|
int fetch_num = packet_io_device_rx(arg->dev, arg->thread_id, &rx_pkt, 1);
|
|
if(fetch_num > 0)
|
|
{
|
|
/*
|
|
event = session_manager_commit(rx_pkt);
|
|
while(event)
|
|
{
|
|
plugin_manager_dispatch(event);
|
|
event = session_manager_fetch_event();
|
|
}*/
|
|
printf("fetch_num:%d\n", fetch_num);
|
|
//clean session_manager event queue
|
|
packet_io_device_tx(arg->dev, arg->thread_id, &rx_pkt, 1);
|
|
}
|
|
else
|
|
{
|
|
printf("no fetch num\n");
|
|
//dispatch to time event
|
|
|
|
//dispatch to trigger polling event
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
|
|
struct packet_io_device *
|
|
packet_io_init(const char *instance_name, const enum packet_io_run_mode mode, const int wrk_thread_num)
|
|
{
|
|
struct packet_io_instance *ppio_inst = packet_io_instance_create(instance_name, mode, wrk_thread_num);
|
|
if (nullptr == ppio_inst) {
|
|
log_error(ST_ERR_PIO_INSTANCE, "packet_io instance init failed.");
|
|
return nullptr;
|
|
}
|
|
|
|
struct packet_io_device *ppio_dev = packet_io_device_open(ppio_inst, "eth1", wrk_thread_num, wrk_thread_num);
|
|
if (nullptr == ppio_dev) {
|
|
log_error(ST_ERR_PIO_DEVICE, "packet_io device open failed.");
|
|
|
|
}
|
|
return ppio_dev;
|
|
}
|
|
|
|
int main(int argc, char ** argv)
|
|
{
|
|
/* global engine instance init */
|
|
memset(&g_engine_instance, 0, sizeof(g_engine_instance));
|
|
|
|
g_engine_instance.config.packet_io.mode = PACKET_IO_RUN_MODE_PCAP_FILE;
|
|
strncpy(g_engine_instance.config.packet_io.dev_name[0], "./test.pcap", sizeof(NAME_MAX));
|
|
g_engine_instance.config.packet_io.dev_cnt = 1;
|
|
|
|
/* packet io init */
|
|
packet_io_init("stellar", g_engine_instance.config.packet_io.mode, 2);
|
|
|
|
//session_manager_session_event_register(http_decoder, SESSION_TYPE_HTTP);
|
|
struct packet_io_loop_arg arg;
|
|
while (1) {
|
|
//packet_io_loop();
|
|
}
|
|
//create_worker_thread
|
|
|
|
//main_loop
|
|
return 0;
|
|
}
|