From f262e748ea5718e7759eb78bf05f1f7313b7aa1e Mon Sep 17 00:00:00 2001 From: huangxin Date: Mon, 13 Mar 2023 17:03:02 +0800 Subject: [PATCH 01/11] =?UTF-8?q?OCT=201.=20=E4=BC=98=E5=8C=96vCPE=20BRAS?= =?UTF-8?q?=E5=90=8E=E7=BA=BF=E7=A8=8Blinux=E7=B3=BB=E7=BB=9F=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=8F=8F=E8=BF=B0=E7=AC=A6fd=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=8D=A0=E7=94=A8=201100+->300+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 16 +++++++-- srcs/CMakeLists.txt | 2 +- srcs/libs/CMakeLists.txt | 4 ++- srcs/libs/configure/config.c | 2 ++ srcs/libs/configure/config_help.c | 4 ++- srcs/libs/hardware/cpu.c | 27 +++------------ srcs/libs/hardware/disk.c | 26 +++----------- srcs/libs/hardware/hardware.c | 57 +++++++++++++++---------------- srcs/libs/hardware/ipmltools.c | 42 +++++++++-------------- srcs/libs/hardware/memory.c | 32 +++++------------ srcs/libs/include/config.h | 2 ++ srcs/libs/init/init_runtime.c | 5 ++- 12 files changed, 90 insertions(+), 129 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4c0eb5..bdfefa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) INCLUDE(CMakeDependentOption) OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF) -OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" OFF) +OPTION(VCPE_PPPOE "Enable vCPE work befof PPPoE mode" OFF) OPTION(USED_OPENDHCPD "DHCP server for vCPE" OFF) OPTION(USED_OPENDHCPDDNS "DHCP And DNS server for vCPE" OFF) OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF) @@ -18,6 +18,8 @@ INCLUDE(system_libs) SET(VCPE_VERSION "1.0.1") PROJECT(vCPE VERSION "${VCPE_VERSION}") CMAKE_DEPENDENT_OPTION(USED_HTTP_SVR "Build-in http(s) server support" ON "USED_OPENDHCPD OR USED_OPENDHCPDDNS" OFF) +CMAKE_DEPENDENT_OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" ON "VCPE_PPPOE" OFF) +CMAKE_DEPENDENT_OPTION(USED_ZMQ "ZeroMQ support for vCPE" ON "VCPE_PPPOE" OFF) # 数据库开关 OPTION(USED_REDIS "Add redis database support for vCPE" OFF) @@ -84,7 +86,7 @@ INCLUDE(./depend/third_libs.cmake) IF (USED_JSON_VALIDATE) LIST(APPEND COMMON_DEFINE "-DJSON_SCHEMA_ON") -ENDIF() +ENDIF () IF (USED_USER_VNI) LIST(APPEND COMMON_DEFINE "-DUSERVNI_ON") @@ -96,6 +98,16 @@ IF (USED_HTTP_SVR) MESSAGE("Select Option USED_HTTP_SVR") ENDIF () +IF (USED_ZMQ) + LIST(APPEND COMMON_DEFINE "-DZEROMQ_ON") + MESSAGE("Select Option USED_ZMQ") +ENDIF () + +IF (VCPE_PPPOE) + LIST(APPEND COMMON_DEFINE "-DPPPOE_ON") + MESSAGE("Select Option VCPE_PPPOE") +ENDIF () + IF (USED_LWIP) LIST(APPEND COMMON_DEFINE "-DLWIP_ON") MESSAGE("Select Option USED_LWIP") diff --git a/srcs/CMakeLists.txt b/srcs/CMakeLists.txt index c337c5b..f26eeef 100644 --- a/srcs/CMakeLists.txt +++ b/srcs/CMakeLists.txt @@ -16,7 +16,7 @@ SET(CMAKE_C_STANDARD 99) FILE(GLOB VCPE_HEADS include/*.h include/uthash/*.h include/s2j/*.h ./httpserver/include/*.h ./httpserver/src/haywire/*.h ./httpserver/src/haywire/configuration/*.h) -IF (USED_LWIP) +IF (VCPE_PPPOE) AUX_SOURCE_DIRECTORY(pppoe VCPE_SRC) AUX_SOURCE_DIRECTORY(user VCPE_SRC) ENDIF () diff --git a/srcs/libs/CMakeLists.txt b/srcs/libs/CMakeLists.txt index faaf2cd..4ca2b34 100644 --- a/srcs/libs/CMakeLists.txt +++ b/srcs/libs/CMakeLists.txt @@ -17,7 +17,9 @@ AUX_SOURCE_DIRECTORY(banner C_SRC) AUX_SOURCE_DIRECTORY(configure C_SRC) AUX_SOURCE_DIRECTORY(network C_SRC) AUX_SOURCE_DIRECTORY(task C_SRC) -AUX_SOURCE_DIRECTORY(mq C_SRC) +IF (USED_ZMQ) + AUX_SOURCE_DIRECTORY(mq C_SRC) +ENDIF () AUX_SOURCE_DIRECTORY(cmdline C_SRC) AUX_SOURCE_DIRECTORY(crypto C_SRC) AUX_SOURCE_DIRECTORY(hardware C_SRC) diff --git a/srcs/libs/configure/config.c b/srcs/libs/configure/config.c index 2500260..bd68487 100644 --- a/srcs/libs/configure/config.c +++ b/srcs/libs/configure/config.c @@ -98,10 +98,12 @@ static CFG_ITEM g_cfgItem[] = { DEF_CFG_ITEM(CFG_DB_SQLITE_DB_NAME, "database.sqlite_dbname", VAL_STR, "", "SQLite3 database file name"), DEF_CFG_ITEM(CFG_DB_SQLITE_PASSWD, "database.sqlite_passwd", VAL_STR, ".main", "SQLite3 database password"), #endif +#ifdef ZEROMQ_ON /* 消息队列相配置 */ /* ZeroMq配置 */ DEF_CFG_ITEM(CFG_MQ_SVR_PORT, "zero_mq.svr_port", VAL_INT, "6278", "ZeroMQ server port"), DEF_CFG_ITEM(CFG_MQ_DATA_PATH, "zero_mq.agent_addr", VAL_STR, "ipc:///tmp/msg_fifo0", "ZeroMQ Agent data path"), +#endif /* vxLan 隧道配置 */ DEF_CFG_ITEM(CFG_VXLAN_NIC_NAME, "vxlan_wan.nic", VAL_STR, "", "Network card name to send data"), DEF_CFG_ITEM(CFG_VXLAN_SUPPORT, "vxlan_wan.enable", VAL_BOOL, "1", "Is support vxLan tune"), diff --git a/srcs/libs/configure/config_help.c b/srcs/libs/configure/config_help.c index 218229c..49670a7 100644 --- a/srcs/libs/configure/config_help.c +++ b/srcs/libs/configure/config_help.c @@ -183,10 +183,12 @@ const char *cfg_get_mysql_database() { } #endif +#ifdef ZEROMQ_ON int cfg_get_zero_mq_port() { return (unsigned short)cfg_get_integral_value(CFG_MQ_SVR_PORT); } const char *cfg_get_zero_mq_data_path() { return cfg_get_string_value(CFG_MQ_DATA_PATH); -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/srcs/libs/hardware/cpu.c b/srcs/libs/hardware/cpu.c index ae080ef..9502d91 100644 --- a/srcs/libs/hardware/cpu.c +++ b/srcs/libs/hardware/cpu.c @@ -20,7 +20,7 @@ typedef struct { #define CMD_CPU_CORE ("cat /proc/cpuinfo| grep \"cpu cores\" | uniq | awk \'{print $4}\'") #define CMP_CPU_LOGIC_CORE ("cat /proc/cpuinfo| grep \"cpu cores\" | wc -l") -#define SUM_CPU_TIME(x) ((x).user + (x).nice + (x).sys + (x).idle + (x).irq) +#define SUM_CPU_TIME(x) ((x).user + (x).nice + (x).sys + (x).idle + (x).irq) static int g_isInit = FALSE; static CPU_INFO g_cpuInfo; @@ -103,7 +103,7 @@ static int get_cpu_time_info(unsigned long *pTotal, unsigned long *pIdle) { *pTotal = *pIdle = 0; for (i = 0; i < nCpu; i++) { - *pIdle += pCpu[i].cpu_times.idle; + *pIdle += pCpu[i].cpu_times.idle; *pTotal += SUM_CPU_TIME(pCpu[i].cpu_times); } @@ -135,25 +135,7 @@ static void cpuUsedRefresh() { } } -_Noreturn void cpuCalcCb(void *UNUSED(pArg)) { - do { - unsigned int period = cfg_get_cpu_refresh_period(); - - if (cfg_get_watch_cpu()) { - cpuUsedRefresh(); - } - - if (period < REFRESH_MAX_PERIOD && period >= 1) { - uv_sleep(1000 * period); - } else { - uv_sleep(1000); - } - } while (TRUE); -} - int cpu_watch_init() { - static uv_thread_t uvThread; - memset(&g_cpuInfo, 0, sizeof(CPU_INFO)); g_cpuInfo.nCpus = get_cpu_number(); @@ -163,9 +145,6 @@ int cpu_watch_init() { get_cpu_desc(&g_cpuInfo.cpuCoreDesc); g_isInit = TRUE; - - uv_thread_create(&uvThread, cpuCalcCb, NULL); - return ERR_SUCCESS; } @@ -184,6 +163,8 @@ int get_cpu_info(PCPU_INFO pInfo) { get_cpu_desc(&g_cpuInfo.cpuCoreDesc); g_isInit = TRUE; + } else if (cfg_get_watch_cpu()) { + cpuUsedRefresh(); } memcpy(pInfo, &g_cpuInfo, sizeof(CPU_INFO)); diff --git a/srcs/libs/hardware/disk.c b/srcs/libs/hardware/disk.c index c5fee99..da61056 100644 --- a/srcs/libs/hardware/disk.c +++ b/srcs/libs/hardware/disk.c @@ -12,7 +12,7 @@ #include "uthash/uthash.h" #include "config.h" -#define MAX_SIZE_LEN (16) +#define MAX_SIZE_LEN (16) //#define CMD_DISK_FILESYSTEM ("df -h | awk \'{if (NR > 1){print $0}}\'") #define CMD_DISK_FILESYSTEM ("df -h | awk \'{if (NR > 1){print $1\"|\"$2\"|\"$3\"|\"$4\"|\"$5\"|\"$6}}\'") @@ -105,6 +105,10 @@ int get_disk_info(PDISK_INFO pInfo) { return -ERR_INPUT_PARAMS; } + if (cfg_get_watch_disk()) { + disk_info_refresh(); + } + uv_rwlock_rdlock(&g_uvLock); pInfo->nItems = HASH_COUNT(g_diskPartInfo); pInfo->timestamp = time(NULL); @@ -122,32 +126,12 @@ int get_disk_info(PDISK_INFO pInfo) { return ERR_SUCCESS; } -_Noreturn void diskRefreshCb(void *UNUSED(pArg)) { - do { - unsigned int period = cfg_get_disk_refresh_period(); - - if (cfg_get_watch_disk()) { - disk_info_refresh(); - } - - if (period < REFRESH_MAX_PERIOD && period >= 1) { - uv_sleep(1000 * period); - } else { - uv_sleep(1000); - } - } while (TRUE); -} - int disk_watch_info() { - static uv_thread_t uvThread; - uv_rwlock_init(&g_uvLock); if (disk_info_refresh() != ERR_SUCCESS) { return -ERR_SYS_DISK_GET_INFO; } - uv_thread_create(&uvThread, diskRefreshCb, NULL); - return ERR_SUCCESS; } \ No newline at end of file diff --git a/srcs/libs/hardware/hardware.c b/srcs/libs/hardware/hardware.c index cafa018..6b941b9 100644 --- a/srcs/libs/hardware/hardware.c +++ b/srcs/libs/hardware/hardware.c @@ -9,51 +9,48 @@ #include "user_errno.h" #include "config.h" #include "misc.h" +#include "task_manager.h" static HARDWARE_INFO g_hardwareInfo; -_Noreturn void hardwareRefreshCb(void *UNUSED(pArg)) { - do { - unsigned int period = cfg_get_hardware_refresh_period(); +void hardwareRefreshCb(uv_timer_t *UNUSED(pArg)) { + if (cfg_get_watch_sensor()) { + get_sensor_info(&g_hardwareInfo.sensorInfo); + } + if (cfg_get_watch_disk()) { + get_disk_info(&g_hardwareInfo.diskInfo); + } + if (cfg_get_watch_cpu()) { + get_cpu_info(&g_hardwareInfo.cpuInfo); + } + if (cfg_get_watch_memory()) { + get_memory_info(&g_hardwareInfo.memInfo); + } - if (cfg_get_watch_sensor()) { - get_sensor_info(&g_hardwareInfo.sensorInfo); - } - - if (cfg_get_watch_disk()) { - get_disk_info(&g_hardwareInfo.diskInfo); - } - - if (cfg_get_watch_cpu()) { - get_cpu_info(&g_hardwareInfo.cpuInfo); - } - - if (cfg_get_watch_memory()) { - get_memory_info(&g_hardwareInfo.memInfo); - } - - if (period < REFRESH_MAX_PERIOD && period >= 1) { - uv_sleep(1000 * period); - } else { - uv_sleep(1000); - } - - uv_sleep(1000); - } while (TRUE); + printf("%s\n", get_hardware_json()); } int init_hardware() { - static uv_thread_t uvThread; + static uv_timer_t uvTm; + unsigned int period = cfg_get_hardware_refresh_period(); + + if (period >= REFRESH_MAX_PERIOD) { + period = 10000; + } else { + period *= 1000; + } + + uv_timer_init(get_task_manager(), &uvTm); memset(&g_hardwareInfo, 0, sizeof(HARDWARE_INFO)); - uv_thread_create(&uvThread, hardwareRefreshCb, NULL); - cpu_watch_init(); memory_watch_init(); disk_watch_info(); sensor_watch_init(); + uv_timer_start(&uvTm, hardwareRefreshCb, period, period); + return ERR_SUCCESS; } diff --git a/srcs/libs/hardware/ipmltools.c b/srcs/libs/hardware/ipmltools.c index 57bb077..13b84b3 100644 --- a/srcs/libs/hardware/ipmltools.c +++ b/srcs/libs/hardware/ipmltools.c @@ -12,10 +12,11 @@ #include "misc.h" #include "config.h" -#define MAX_SENSOR_STR (32) +#define MAX_SENSOR_STR (32) //#define CMD_SENSOR_INFO ("ipmitool sensor | awk '{gsub(/\|/, \"\"); print $0}'") -#define CMD_SENSOR_INFO ("ipmitool sensor") +#define CMD_SENSOR_INFO ("ipmitool sensor") +#define CMD_IPMITOOL_ENABLE ("whereis ipmitool | awk '{print $2}'") typedef struct { char name[MAX_SENSOR_STR]; ///< 传感器名称 @@ -42,9 +43,16 @@ static int sensor_info_refresh() { int errCode = ERR_SUCCESS; FILE *fp; char buf[1024]; + char *pRet = NULL; + + if (shell_with_output(CMD_IPMITOOL_ENABLE, &pRet) != ERR_SUCCESS || pRet == NULL || strlen(pRet) == 0) { + if (pRet) { + free(pRet); + } + return -ERR_ITEM_UNEXISTS; + } fp = popen(CMD_SENSOR_INFO, "r"); - if (fp == NULL) { return -ERR_OPEN_FILE; } @@ -132,6 +140,10 @@ int get_sensor_info(PSENSOR_INFO pInfo) { return -ERR_INPUT_PARAMS; } + if (cfg_get_watch_sensor()) { + sensor_info_refresh(); + } + uv_rwlock_rdlock(&g_uvLock); pInfo->nItems = HASH_COUNT(g_pSensorInfo); pInfo->timestamp = time(NULL); @@ -149,27 +161,9 @@ int get_sensor_info(PSENSOR_INFO pInfo) { return ERR_SUCCESS; } -_Noreturn void sensorRefreshCb(void *UNUSED(pArg)) { - do { - unsigned int period = cfg_get_sensor_refresh_period(); - - if (cfg_get_watch_sensor()) { - sensor_info_refresh(); - } - - if (period < REFRESH_MAX_PERIOD && period >= 1) { - uv_sleep(1000 * period); - } else { - uv_sleep(1000); - } - } while (TRUE); -} - int sensor_watch_init() { - - static uv_thread_t uvThread; - int i, devOk = FALSE; - int n = ARRAY_SIZE(g_ipmiDev); + int i, devOk = FALSE; + int n = ARRAY_SIZE(g_ipmiDev); uv_rwlock_init(&g_uvLock); @@ -188,7 +182,5 @@ int sensor_watch_init() { return -ERR_SYS_SENSOR_GET_INFO; } - uv_thread_create(&uvThread, sensorRefreshCb, NULL); - return ERR_SUCCESS; } \ No newline at end of file diff --git a/srcs/libs/hardware/memory.c b/srcs/libs/hardware/memory.c index 5d5cc9a..e777a1a 100644 --- a/srcs/libs/hardware/memory.c +++ b/srcs/libs/hardware/memory.c @@ -14,11 +14,11 @@ #define CMD_MEMORY_INFO ("cat /proc/meminfo | awk \'{print $1\"|\"$2\"|\"$3}\'") -#define M_SIZE (1024 * 1024) +#define M_SIZE (1024 * 1024) -#define KEY_NAME (32) -#define KEY_VALUE (32) -#define VALUE_UNIT (8) +#define KEY_NAME (32) +#define KEY_VALUE (32) +#define VALUE_UNIT (8) typedef struct { char itemName[KEY_NAME]; @@ -95,33 +95,13 @@ static int memory_info_refresh() { return errCode; } -_Noreturn void memRefreshCb(void *UNUSED(pArg)) { - do { - unsigned int period = cfg_get_mem_refresh_period(); - - if (cfg_get_watch_memory()) { - memory_info_refresh(); - } - - if (period < REFRESH_MAX_PERIOD && period >= 1) { - uv_sleep(1000 * period); - } else { - uv_sleep(1000); - } - } while (TRUE); -} - int memory_watch_init() { - static uv_thread_t uvThread; - uv_rwlock_init(&g_uvLock); if (memory_info_refresh() != ERR_SUCCESS) { return -ERR_SYS_DISK_GET_INFO; } - uv_thread_create(&uvThread, memRefreshCb, NULL); - return ERR_SUCCESS; } @@ -142,6 +122,10 @@ int get_memory_info(PMEMORY_INFO pInfo) { return -ERR_INPUT_PARAMS; } + if (cfg_get_watch_memory()) { + memory_info_refresh(); + } + uv_rwlock_rdlock(&g_uvLock); for (i = 0; i < n; i++) { diff --git a/srcs/libs/include/config.h b/srcs/libs/include/config.h index 8d8f40b..1730a78 100644 --- a/srcs/libs/include/config.h +++ b/srcs/libs/include/config.h @@ -61,8 +61,10 @@ typedef enum { CFG_DB_SQLITE_DB_NAME, CFG_DB_SQLITE_PASSWD, #endif +#ifdef ZEROMQ_ON CFG_MQ_SVR_PORT, CFG_MQ_DATA_PATH, +#endif CFG_VXLAN_NIC_NAME, CFG_VXLAN_SUPPORT, CFG_VXLAN_PEER_IP, diff --git a/srcs/libs/init/init_runtime.c b/srcs/libs/init/init_runtime.c index 19660fe..a72dd56 100644 --- a/srcs/libs/init/init_runtime.c +++ b/srcs/libs/init/init_runtime.c @@ -134,7 +134,7 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK if (cfg_get_hardware_watch_enable()) { init_hardware(); } - +#ifdef ZEROMQ_ON if ((ret = mq_init()) != ERR_SUCCESS) { LOG_MOD(error, ZLOG_MOD_INIT, "Message queue init error: %d\n", ret); } @@ -142,6 +142,7 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK if ((ret = mq_data_init()) != ERR_SUCCESS) { LOG_MOD(error, ZLOG_MOD_INIT, "Message queue init error: %d\n", ret); } +#endif #ifdef HTTPSERVER_ON http_svr_init(); #endif @@ -156,7 +157,9 @@ void user_uninit() { #ifdef HTTPSERVER_ON http_svr_uinit(); #endif +#ifdef ZEROMQ_ON mq_uninit(); +#endif zlog_fini(); uninit_config_system(); uv_loop_close(get_task_manager()); From cf5375c8931ecf73fd92f8b68577c4b52a9be49d Mon Sep 17 00:00:00 2001 From: huangxin Date: Mon, 13 Mar 2023 17:26:54 +0800 Subject: [PATCH 02/11] =?UTF-8?q?OCT=201.=20=E7=A7=BB=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=A1=AC=E4=BB=B6=E7=9B=91=E6=8E=A7=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/vcpe.cfg | 5 ----- srcs/libs/configure/config.c | 5 ----- srcs/libs/configure/config_help.c | 16 ---------------- srcs/libs/include/config.h | 10 ++-------- 4 files changed, 2 insertions(+), 34 deletions(-) diff --git a/config/vcpe.cfg b/config/vcpe.cfg index 319ff48..6b9f483 100644 --- a/config/vcpe.cfg +++ b/config/vcpe.cfg @@ -24,11 +24,6 @@ application: memory = true; # 是否开启内存监控 disk = true; # 是否开启磁盘空间占用监控 sensor = true; # 是否开启传感器状态监控 - - cpu_refresh = 1; # CPU 状态刷新频率(秒) - mem_refresh = 10; # 内存状态刷新频率(秒) - disk_refresh = 10; # 磁盘状态刷新频率(秒) - sensor_refresh = 10; # 传感器状态刷新频率(秒) }; # 数据库相关配置 diff --git a/srcs/libs/configure/config.c b/srcs/libs/configure/config.c index bd68487..abe896a 100644 --- a/srcs/libs/configure/config.c +++ b/srcs/libs/configure/config.c @@ -73,11 +73,6 @@ static CFG_ITEM g_cfgItem[] = { DEF_CFG_ITEM(CFG_WATCH_MEMORY, "watch_params.memory", VAL_BOOL, "1", "Monitor memory information"), DEF_CFG_ITEM(CFG_WATCH_DISK, "watch_params.disk", VAL_BOOL, "1", "Monitor disk partition information"), DEF_CFG_ITEM(CFG_WATCH_SENSOR, "watch_params.sensor", VAL_BOOL, "1", "Sensor information refresh frequency"), - /* 系统监控设备刷频率 */ - DEF_CFG_ITEM(CFG_CPU_REFRESH, "watch_params.cpu_refresh", VAL_INT, "10", "CPU information refresh frequency"), - DEF_CFG_ITEM(CFG_MEM_REFRESH, "watch_params.mem_refresh", VAL_INT, "10", "Memory information refresh frequency"), - DEF_CFG_ITEM(CFG_DISK_REFRESH, "watch_params.disk_refresh", VAL_INT, "10", "Disk information refresh frequency"), - DEF_CFG_ITEM(CFG_SENSOR_REFRESH, "watch_params.sensor_refresh", VAL_INT, "10", "Sensor information refresh frequency"), /* 数据库相配置 */ /* Redis配置 */ #ifdef USED_REDIS diff --git a/srcs/libs/configure/config_help.c b/srcs/libs/configure/config_help.c index 49670a7..1f7c22a 100644 --- a/srcs/libs/configure/config_help.c +++ b/srcs/libs/configure/config_help.c @@ -121,22 +121,6 @@ int cfg_get_watch_sensor() { return cfg_get_bool_value(CFG_WATCH_SENSOR); } -unsigned int cfg_get_cpu_refresh_period() { - return cfg_get_integral_value(CFG_CPU_REFRESH); -} - -unsigned int cfg_get_mem_refresh_period() { - return cfg_get_integral_value(CFG_MEM_REFRESH); -} - -unsigned int cfg_get_disk_refresh_period() { - return cfg_get_integral_value(CFG_DISK_REFRESH); -} - -unsigned int cfg_get_sensor_refresh_period() { - return cfg_get_integral_value(CFG_SENSOR_REFRESH); -} - #ifdef USED_SQLITE const char *cfg_get_sqlite_db_name() { return cfg_get_string_value(CFG_DB_SQLITE_DB_NAME); diff --git a/srcs/libs/include/config.h b/srcs/libs/include/config.h index 1730a78..687e981 100644 --- a/srcs/libs/include/config.h +++ b/srcs/libs/include/config.h @@ -41,10 +41,6 @@ typedef enum { CFG_WATCH_MEMORY, CFG_WATCH_DISK, CFG_WATCH_SENSOR, - CFG_CPU_REFRESH, - CFG_MEM_REFRESH, - CFG_DISK_REFRESH, - CFG_SENSOR_REFRESH, #ifdef USED_REDIS CFG_DB_REDIS_SERVER, CFG_DB_REDIS_PORT, @@ -94,10 +90,6 @@ int cfg_get_watch_cpu(); int cfg_get_watch_memory(); int cfg_get_watch_disk(); int cfg_get_watch_sensor(); -unsigned int cfg_get_cpu_refresh_period(); -unsigned int cfg_get_mem_refresh_period(); -unsigned int cfg_get_disk_refresh_period(); -unsigned int cfg_get_sensor_refresh_period(); #ifdef USED_REDIS const char *cfg_get_redis_server(); int cfg_get_redis_port(); @@ -114,8 +106,10 @@ const char *cfg_get_mysql_database(); const char *cfg_get_sqlite_db_name(); const char *cfg_get_sqlite_passwd(); #endif +#ifdef ZEROMQ_ON int cfg_get_zero_mq_port(); const char *cfg_get_zero_mq_data_path(); +#endif const char *cfg_get_string_value(CONFIG_ITEM_ID id); c_vector cfg_get_vector(CONFIG_ITEM_ID id); From 789ddbc71638528d459f2bce4e9e728456025149 Mon Sep 17 00:00:00 2001 From: huangxin Date: Mon, 13 Mar 2023 17:33:59 +0800 Subject: [PATCH 03/11] =?UTF-8?q?OCT=201.=20=E4=BC=98=E5=8C=96vCPE=20BRAS?= =?UTF-8?q?=E5=90=8E=E7=BA=BF=E7=A8=8Blinux=E7=B3=BB=E7=BB=9F=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=8F=8F=E8=BF=B0=E7=AC=A6fd=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=8D=A0=E7=94=A8=20340+->264=202.=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=A1=AC=E4=BB=B6=E4=BF=A1=E6=81=AF=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/libs/hardware/hardware.c | 2 +- srcs/libs/init/init_runtime.c | 4 +- srcs/opendhcp183/query.cpp | 123 +++++++++++++++++----------------- 3 files changed, 65 insertions(+), 64 deletions(-) diff --git a/srcs/libs/hardware/hardware.c b/srcs/libs/hardware/hardware.c index 6b941b9..3f12302 100644 --- a/srcs/libs/hardware/hardware.c +++ b/srcs/libs/hardware/hardware.c @@ -27,7 +27,7 @@ void hardwareRefreshCb(uv_timer_t *UNUSED(pArg)) { get_memory_info(&g_hardwareInfo.memInfo); } - printf("%s\n", get_hardware_json()); + //printf("%s\n", get_hardware_json()); } int init_hardware() { diff --git a/srcs/libs/init/init_runtime.c b/srcs/libs/init/init_runtime.c index a72dd56..a0f99f3 100644 --- a/srcs/libs/init/init_runtime.c +++ b/srcs/libs/init/init_runtime.c @@ -14,11 +14,13 @@ #include "inet_misc.h" #include "crypto.h" #include "hardware.h" -#include "msg_queue.h" #include "http_svr.h" #include "lib_config.h" #include "prj_config.h" #include "zlog_module.h" +#ifdef ZEROMQ_ON +#include "msg_queue.h" +#endif #define DEFAULT_CONFIG_FILE ("vcpe.cfg") #define DEFAULT_CONFIG_DIR ("config") diff --git a/srcs/opendhcp183/query.cpp b/srcs/opendhcp183/query.cpp index 4814432..fe5e883 100644 --- a/srcs/opendhcp183/query.cpp +++ b/srcs/opendhcp183/query.cpp @@ -25,6 +25,7 @@ using namespace std; #include "sds/sds.h" #include "inet_misc.h" #include "http_svr.h" +#include "task_manager.h" extern data2 cfig; extern bool kRunning; @@ -341,7 +342,7 @@ static int add_dhcpd_rangeset(const char **pRsp, const char *pRequest) { logDHCPMess(logBuff, 1); return ERR_PROTO_DECODE; } - + #ifdef JSON_SCHEMA_ON if (errCode == ERR_JSON_VALID_SCH) { *pRsp = pStrContent; @@ -488,7 +489,7 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) { PHASH_MAP s; HASH_FIND_INT(delMap, &st_addr, s); if (s == nullptr) { - s = (PHASH_MAP)malloc(sizeof(HASH_MAP)); + s = (PHASH_MAP)malloc(sizeof(HASH_MAP)); s->key = st_addr; s->value = en_addr; HASH_ADD_INT(delMap, key, s); @@ -765,68 +766,63 @@ static void on_http_response_cb(void *pData, free(pUserData); } -void iptvCacheCb(void *UNUSED(pArg)) { - do { - bool isReport = false; - const char *pUrl = config_get_agent_iptv_report_url(); - PIPTV_DEV_SET report = nullptr; - PIPTV_DEV_SET pDev, pTmp = nullptr; - uv_rwlock_wrlock(&g_uvCacheLock); - HASH_ITER(hh, g_iptvNewDevs, pDev, pTmp) { - PIPTV_DEV_SET pTemp; - const char *pDevMac = strdup(pDev->iptvMAC); - HASH_FIND_STR(g_iptvCacheDevs, pDevMac, pTemp); - // 新发现设备没有被上报过 - if (!pTemp) { - auto pCacheDev = (PIPTV_DEV_SET)malloc(sizeof(IPTV_DEV_SET)); - auto pRepDev = (PIPTV_DEV_SET)malloc(sizeof(IPTV_DEV_SET)); - - memcpy(pCacheDev, pDev, sizeof(IPTV_DEV_SET)); - memcpy(pRepDev, pDev, sizeof(IPTV_DEV_SET)); - HASH_ADD_STR(report, iptvMAC, pRepDev); - - isReport = true; - // 添加到缓存列表供后续查询 - HASH_ADD_STR(g_iptvCacheDevs, iptvMAC, pCacheDev); - LOG_MOD(debug, - ZLOG_MOD_OPENDHCPD, - "Add IPTV device %s vni %d to cache\n", - pCacheDev->iptvMAC, - pCacheDev->vni); - } - - HASH_DEL(g_iptvNewDevs, pDev); - free(pDev); - free((void *)pDevMac); - } - uv_rwlock_wrunlock(&g_uvCacheLock); - - if (isReport && pUrl && strlen(pUrl) > 0) { - cJSON *pRspMsg = cJSON_CreateObject(); - cJSON *pMsgArray = cJSON_CreateArray(); - cJSON_AddItemToObject(pRspMsg, "iptvDevs", pMsgArray); - - HASH_ITER(hh, report, pDev, pTmp) { - cJSON *pRspItem = cJSON_CreateObject(); - cJSON_AddStringToObject(pRspItem, "mac", pDev->iptvMAC); - cJSON_AddNumberToObject(pRspItem, "vni", pDev->vni); - pDev->isReport = 1; - cJSON_AddItemToArray(pMsgArray, pRspItem); - } - - const char *pStrPro = proto_create_new(pRspMsg, 200); - - // Report new IPTV device MAC - inet_http_post_async(pUrl, pStrPro, on_http_response_cb, (void *)pStrPro); - } +void iptvCacheCb(uv_timer_t *UNUSED(pArg)) { + bool isReport = false; + const char *pUrl = config_get_agent_iptv_report_url(); + PIPTV_DEV_SET report = nullptr; + PIPTV_DEV_SET pDev, pTmp = nullptr; + uv_rwlock_wrlock(&g_uvCacheLock); + HASH_ITER(hh, g_iptvNewDevs, pDev, pTmp) uv_sleep(10); + HASH_ITER(hh, report, pDev, pTmp) { + HASH_DEL(report, pDev); + free(pDev); + } + HASH_ITER(hh, report, pDev, pTmp) if (isReport && pUrl && strlen(pUrl) > 0) { + cJSON *pRspMsg = cJSON_CreateObject(); + cJSON *pMsgArray = cJSON_CreateArray(); + cJSON_AddItemToObject(pRspMsg, "iptvDevs", pMsgArray); HASH_ITER(hh, report, pDev, pTmp) { - HASH_DEL(report, pDev); - free(pDev); + cJSON *pRspItem = cJSON_CreateObject(); + cJSON_AddStringToObject(pRspItem, "mac", pDev->iptvMAC); + cJSON_AddNumberToObject(pRspItem, "vni", pDev->vni); + pDev->isReport = 1; + cJSON_AddItemToArray(pMsgArray, pRspItem); } - uv_sleep(10); - } while (true); + const char *pStrPro = proto_create_new(pRspMsg, 200); + + // Report new IPTV device MAC + inet_http_post_async(pUrl, pStrPro, on_http_response_cb, (void *)pStrPro); + } + uv_rwlock_wrunlock(&g_uvCacheLock); + HASH_ITER(hh, g_iptvNewDevs, pDev, pTmp) { + PIPTV_DEV_SET pTemp; + const char *pDevMac = strdup(pDev->iptvMAC); + HASH_FIND_STR(g_iptvCacheDevs, pDevMac, pTemp); + // 新发现设备没有被上报过 + if (!pTemp) { + auto pCacheDev = (PIPTV_DEV_SET)malloc(sizeof(IPTV_DEV_SET)); + auto pRepDev = (PIPTV_DEV_SET)malloc(sizeof(IPTV_DEV_SET)); + + memcpy(pCacheDev, pDev, sizeof(IPTV_DEV_SET)); + memcpy(pRepDev, pDev, sizeof(IPTV_DEV_SET)); + HASH_ADD_STR(report, iptvMAC, pRepDev); + + isReport = true; + // 添加到缓存列表供后续查询 + HASH_ADD_STR(g_iptvCacheDevs, iptvMAC, pCacheDev); + LOG_MOD(debug, + ZLOG_MOD_OPENDHCPD, + "Add IPTV device %s vni %d to cache\n", + pCacheDev->iptvMAC, + pCacheDev->vni); + } + + HASH_DEL(g_iptvNewDevs, pDev); + free(pDev); + free((void *)pDevMac); + } } /** @@ -950,10 +946,13 @@ static HTTP_ROUTE_INFO g_routeTable[] = { void opendhcp_init_http_server() { static int added = FALSE; static uv_thread_t uvThread; - + static uv_timer_t uvTm; if (!added) { uv_rwlock_init(&g_uvCacheLock); - uv_thread_create(&uvThread, iptvCacheCb, nullptr); + uv_timer_init(get_task_manager(), &uvTm); + + uv_timer_start(&uvTm, iptvCacheCb, 1000, 1000); + //uv_thread_create(&uvThread, iptvCacheCb, nullptr); for (auto &i : g_routeTable) { PHTTP_ROUTE_INFO p = &i; http_add_route(p->routeName, p->method, p->priority, p->cb, p->pUserData); From 44d3cb5984448fdb34cb5ad2cde9b3de8b338981 Mon Sep 17 00:00:00 2001 From: huangxin Date: Mon, 13 Mar 2023 17:39:33 +0800 Subject: [PATCH 04/11] =?UTF-8?q?OCT=201.=20=E5=88=A0=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/opendhcp183/query.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/srcs/opendhcp183/query.cpp b/srcs/opendhcp183/query.cpp index fe5e883..e1ff481 100644 --- a/srcs/opendhcp183/query.cpp +++ b/srcs/opendhcp183/query.cpp @@ -945,14 +945,12 @@ static HTTP_ROUTE_INFO g_routeTable[] = { void opendhcp_init_http_server() { static int added = FALSE; - static uv_thread_t uvThread; static uv_timer_t uvTm; if (!added) { uv_rwlock_init(&g_uvCacheLock); uv_timer_init(get_task_manager(), &uvTm); uv_timer_start(&uvTm, iptvCacheCb, 1000, 1000); - //uv_thread_create(&uvThread, iptvCacheCb, nullptr); for (auto &i : g_routeTable) { PHTTP_ROUTE_INFO p = &i; http_add_route(p->routeName, p->method, p->priority, p->cb, p->pUserData); From 7ebc4fd9d9e3bc0f5b386779949060e8a6635ed7 Mon Sep 17 00:00:00 2001 From: huangxin Date: Tue, 14 Mar 2023 09:55:40 +0800 Subject: [PATCH 05/11] =?UTF-8?q?OCT=201.=20=E7=A7=BB=E9=99=A4=E9=9D=9E?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E6=83=85=E5=86=B5=E4=B8=8B=E7=9A=84zmq?= =?UTF-8?q?=E5=BA=93=E8=B0=83=E7=94=A8=202.=20=E8=BF=9B=E7=A8=8B=E5=8F=A5?= =?UTF-8?q?=E6=9F=84=E4=BC=98=E5=8C=96266-->116?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- depend/third_libs.cmake | 5 +++-- srcs/libs/cmdline/cmd_menu.c | 7 +++++-- srcs/libs/{cmdline => mq}/mq_cmd.c | 0 3 files changed, 8 insertions(+), 4 deletions(-) rename srcs/libs/{cmdline => mq}/mq_cmd.c (100%) diff --git a/depend/third_libs.cmake b/depend/third_libs.cmake index 284cf67..71d7fb2 100644 --- a/depend/third_libs.cmake +++ b/depend/third_libs.cmake @@ -4,8 +4,9 @@ INCLUDE(FetchContent) PKG_SEARCH_MODULE(LIBCURL QUIET libcurl) PKG_SEARCH_MODULE(LIBSSL QUIET libssl) PKG_SEARCH_MODULE(LIBCRYPTO QUIET libcrypto) -PKG_SEARCH_MODULE(LIBZMQ QUIET libzmq) - +IF (USED_ZMQ) + PKG_SEARCH_MODULE(LIBZMQ QUIET libzmq) +ENDIF () IF ((NOT LIBZMQ_FOUND) OR (NOT LIBCRYPTO_FOUND) OR (NOT LIBSSL_FOUND) OR (NOT LIBCURL_FOUND)) LINUX_INSTALL_SYSTEM_PACKAGE() ENDIF () diff --git a/srcs/libs/cmdline/cmd_menu.c b/srcs/libs/cmdline/cmd_menu.c index 2984ebe..f57c451 100644 --- a/srcs/libs/cmdline/cmd_menu.c +++ b/srcs/libs/cmdline/cmd_menu.c @@ -186,8 +186,11 @@ static int on_cmd2(void *pTbl[], const char *pName, void *pInfo) { } pJsonStr = cJSON_PrintUnformatted(pJsonObj); - ret = mq_cmd_run(pSvr, pJsonStr); - +#ifdef ZEROMQ_ON + ret = mq_cmd_run(pSvr, pJsonStr); +#else + ret = ERR_SUCCESS; +#endif cJSON_Delete(pJsonObj); free((void *)pJsonStr); diff --git a/srcs/libs/cmdline/mq_cmd.c b/srcs/libs/mq/mq_cmd.c similarity index 100% rename from srcs/libs/cmdline/mq_cmd.c rename to srcs/libs/mq/mq_cmd.c From 5287e57f75297675d45d979423cd931f48a4fd7c Mon Sep 17 00:00:00 2001 From: huangxin Date: Tue, 14 Mar 2023 10:00:11 +0800 Subject: [PATCH 06/11] =?UTF-8?q?OCT=201.=20CMake=20OPTION=20=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E9=A1=BA=E5=BA=8F=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdfefa9..21c623b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,13 @@ OPTION(USED_OPENDHCPDDNS "DHCP And DNS server for vCPE" OFF) OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF) OPTION(USED_JSON_VALIDATE "Support json protocol field validate" OFF) OPTION(BUILD_TESTING "Enable tests" OFF) +# 数据库开关 +OPTION(USED_REDIS "Add redis database support for vCPE" OFF) +OPTION(USED_MYSQL "Add mysql database support for vCPE" OFF) +OPTION(USED_SQLITE "Add sqlite3 database support for vCPE" OFF) +CMAKE_DEPENDENT_OPTION(USED_HTTP_SVR "Build-in http(s) server support" ON "USED_OPENDHCPD OR USED_OPENDHCPDDNS" OFF) +CMAKE_DEPENDENT_OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" ON "VCPE_PPPOE" OFF) +CMAKE_DEPENDENT_OPTION(USED_ZMQ "ZeroMQ support for vCPE" ON "VCPE_PPPOE" OFF) LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/depend) IF (BUILD_TESTING) @@ -17,14 +24,6 @@ INCLUDE(system_libs) SET(VCPE_VERSION "1.0.1") PROJECT(vCPE VERSION "${VCPE_VERSION}") -CMAKE_DEPENDENT_OPTION(USED_HTTP_SVR "Build-in http(s) server support" ON "USED_OPENDHCPD OR USED_OPENDHCPDDNS" OFF) -CMAKE_DEPENDENT_OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" ON "VCPE_PPPOE" OFF) -CMAKE_DEPENDENT_OPTION(USED_ZMQ "ZeroMQ support for vCPE" ON "VCPE_PPPOE" OFF) - -# 数据库开关 -OPTION(USED_REDIS "Add redis database support for vCPE" OFF) -OPTION(USED_MYSQL "Add mysql database support for vCPE" OFF) -OPTION(USED_SQLITE "Add sqlite3 database support for vCPE" OFF) SET(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig") SET(URI_HOME "${CMAKE_SOURCE_DIR}/libs") From 8122c31a44748dc393f38270f533849fcb9e8f07 Mon Sep 17 00:00:00 2001 From: huangxin Date: Tue, 14 Mar 2023 11:02:03 +0800 Subject: [PATCH 07/11] =?UTF-8?q?OCT=201.=20=E6=9B=B4=E6=96=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21c623b..5ffb35d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ IF (BUILD_TESTING) ENDIF () INCLUDE(system_libs) -SET(VCPE_VERSION "1.0.1") +SET(VCPE_VERSION "1.2.0") PROJECT(vCPE VERSION "${VCPE_VERSION}") SET(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig") From c7e85cd0a52a48e60eea713eb78569ab098516a7 Mon Sep 17 00:00:00 2001 From: huangxin Date: Tue, 14 Mar 2023 14:14:14 +0800 Subject: [PATCH 08/11] =?UTF-8?q?OCT=201.=20=E6=9B=B4=E6=96=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=BE=9D=E8=B5=96=E5=AE=89=E8=A3=85=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- depend/third_libs.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/depend/third_libs.cmake b/depend/third_libs.cmake index 71d7fb2..7dd46b0 100644 --- a/depend/third_libs.cmake +++ b/depend/third_libs.cmake @@ -6,8 +6,11 @@ PKG_SEARCH_MODULE(LIBSSL QUIET libssl) PKG_SEARCH_MODULE(LIBCRYPTO QUIET libcrypto) IF (USED_ZMQ) PKG_SEARCH_MODULE(LIBZMQ QUIET libzmq) + IF (NOT LIBZMQ_FOUND) + LINUX_INSTALL_SYSTEM_PACKAGE() + ENDIF () ENDIF () -IF ((NOT LIBZMQ_FOUND) OR (NOT LIBCRYPTO_FOUND) OR (NOT LIBSSL_FOUND) OR (NOT LIBCURL_FOUND)) +IF ((NOT LIBCRYPTO_FOUND) OR (NOT LIBSSL_FOUND) OR (NOT LIBCURL_FOUND)) LINUX_INSTALL_SYSTEM_PACKAGE() ENDIF () From cd2005bdab2dce207c587901af49691a914fb593 Mon Sep 17 00:00:00 2001 From: huangxin Date: Wed, 15 Mar 2023 09:36:16 +0800 Subject: [PATCH 09/11] =?UTF-8?q?OCT=201.=20=E5=85=B3=E9=97=ADvcpe?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E3=80=81=E9=80=80=E5=87=BA=E5=90=91Agent?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=80=9A=E7=9F=A5=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/vcpe_main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/srcs/vcpe_main.c b/srcs/vcpe_main.c index 2fb59f3..683193e 100644 --- a/srcs/vcpe_main.c +++ b/srcs/vcpe_main.c @@ -7,7 +7,6 @@ #include "cmdline.h" #include "task_manager.h" #include "init.h" -#include "inet_misc.h" #include "config.h" #include "zlog_module.h" @@ -103,12 +102,13 @@ int main(int argc, char **argv) { pppoe_session_init(); #endif - const char *pStrSetup = proto_create_new(create_app_process_status(1), 200); - inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrSetup); - task_manager_run(); + // const char *pStrSetup = proto_create_new(create_app_process_status(1), 200); + // inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrSetup); - const char *pStrExit = proto_create_new(create_app_process_status(0), 200); - inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrExit); + task_manager_run(); + // + // const char *pStrExit = proto_create_new(create_app_process_status(0), 200); + // inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrExit); while (!is_system_cleanup()) { sleep(1); From 50aba54eaef3e5815f2b1f36b0ef1956b0372af7 Mon Sep 17 00:00:00 2001 From: huangxin Date: Wed, 15 Mar 2023 14:13:11 +0800 Subject: [PATCH 10/11] =?UTF-8?q?OCT=201.=20=E5=A2=9E=E5=8A=A0=E5=85=B3?= =?UTF-8?q?=E9=97=ADvcpe=E5=90=AF=E5=8A=A8=E3=80=81=E9=80=80=E5=87=BA?= =?UTF-8?q?=E5=90=91Agent=E5=8F=91=E9=80=81=E9=80=9A=E7=9F=A5=E5=AE=8F?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/vcpe.cfg | 4 ++-- srcs/vcpe_main.c | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/config/vcpe.cfg b/config/vcpe.cfg index 6b9f483..2458966 100644 --- a/config/vcpe.cfg +++ b/config/vcpe.cfg @@ -13,8 +13,8 @@ application: }; agent: { - iptv_report_url = "http://10.0.0.1:50012/vcpe/dhcp/info"; # IPTV 设备上报接口 - moniter_rep_url = "http://10.0.0.1:50012/vcpe/dhcp/restart"; # vCPE设备上下线接口 + iptv_report_url = ""; # IPTV 设备上报接口 + moniter_rep_url = ""; # vCPE设备上下线接口 }; # 硬件监控相关配置内容 diff --git a/srcs/vcpe_main.c b/srcs/vcpe_main.c index 683193e..65d8979 100644 --- a/srcs/vcpe_main.c +++ b/srcs/vcpe_main.c @@ -7,6 +7,9 @@ #include "cmdline.h" #include "task_manager.h" #include "init.h" +#ifdef NOTIFY_VCPE_STATUS +#include "inet_misc.h" +#endif #include "config.h" #include "zlog_module.h" @@ -47,6 +50,7 @@ static void lwip_init_env() { } #endif +#ifdef NOTIFY_VCPE_STATUS cJSON *create_app_process_status(int isStart) { cJSON *pRspMsg = cJSON_CreateObject(); #ifdef USERVNI_ON @@ -73,6 +77,7 @@ static void on_http_response_cb(void *pData, free(pUserData); } +#endif int main(int argc, char **argv) { int ret; @@ -102,13 +107,17 @@ int main(int argc, char **argv) { pppoe_session_init(); #endif - // const char *pStrSetup = proto_create_new(create_app_process_status(1), 200); - // inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrSetup); +#ifdef NOTIFY_VCPE_STATUS + const char *pStrSetup = proto_create_new(create_app_process_status(1), 200); + inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrSetup); +#endif task_manager_run(); - // - // const char *pStrExit = proto_create_new(create_app_process_status(0), 200); - // inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrExit); + +#ifdef NOTIFY_VCPE_STATUS + const char *pStrExit = proto_create_new(create_app_process_status(0), 200); + inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrExit); +#endif while (!is_system_cleanup()) { sleep(1); From 18e296c19cb4de6c030b81ee6d3e8b9b9d1fab31 Mon Sep 17 00:00:00 2001 From: huangxin Date: Wed, 15 Mar 2023 14:19:49 +0800 Subject: [PATCH 11/11] =?UTF-8?q?OCT=201.=20=E6=A0=B9=E6=8D=AE=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9=E5=BC=80=E5=85=B3=E5=86=B3=E5=AE=9A=E5=85=B3?= =?UTF-8?q?=E9=97=ADvcpe=E5=90=AF=E5=8A=A8=E3=80=81=E9=80=80=E5=87=BA?= =?UTF-8?q?=E5=90=91Agent=E5=8F=91=E9=80=81=E9=80=9A=E7=9F=A5=E5=AE=8F?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/vcpe.cfg | 2 +- srcs/vcpe_main.c | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/config/vcpe.cfg b/config/vcpe.cfg index 2458966..7292984 100644 --- a/config/vcpe.cfg +++ b/config/vcpe.cfg @@ -13,7 +13,7 @@ application: }; agent: { - iptv_report_url = ""; # IPTV 设备上报接口 + iptv_report_url = "http://10.0.0.1:50012/vcpe/dhcp/info"; # IPTV 设备上报接口 moniter_rep_url = ""; # vCPE设备上下线接口 }; diff --git a/srcs/vcpe_main.c b/srcs/vcpe_main.c index 65d8979..409781b 100644 --- a/srcs/vcpe_main.c +++ b/srcs/vcpe_main.c @@ -4,12 +4,11 @@ #include #include #include +#include #include "cmdline.h" #include "task_manager.h" #include "init.h" -#ifdef NOTIFY_VCPE_STATUS #include "inet_misc.h" -#endif #include "config.h" #include "zlog_module.h" @@ -50,7 +49,6 @@ static void lwip_init_env() { } #endif -#ifdef NOTIFY_VCPE_STATUS cJSON *create_app_process_status(int isStart) { cJSON *pRspMsg = cJSON_CreateObject(); #ifdef USERVNI_ON @@ -77,10 +75,11 @@ static void on_http_response_cb(void *pData, free(pUserData); } -#endif int main(int argc, char **argv) { - int ret; + int ret; + const char *pRspUrl; + #ifdef OPENDHCPDDNS_ON return dual_server_main(argc, argv); #else @@ -107,17 +106,19 @@ int main(int argc, char **argv) { pppoe_session_init(); #endif -#ifdef NOTIFY_VCPE_STATUS - const char *pStrSetup = proto_create_new(create_app_process_status(1), 200); - inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrSetup); -#endif + pRspUrl = config_get_agent_moniter_report_url(); + + if (pRspUrl && strlen(pRspUrl) > 0) { + const char *pStrSetup = proto_create_new(create_app_process_status(1), 200); + inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrSetup); + } task_manager_run(); -#ifdef NOTIFY_VCPE_STATUS - const char *pStrExit = proto_create_new(create_app_process_status(0), 200); - inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrExit); -#endif + if (pRspUrl && strlen(pRspUrl) > 0) { + const char *pStrExit = proto_create_new(create_app_process_status(0), 200); + inet_http_post_async(config_get_agent_moniter_report_url(), pStrExit, on_http_response_cb, (void *)pStrExit); + } while (!is_system_cleanup()) { sleep(1);