OCT 1. 增加DHCP 测试工具接收业务相关功能

This commit is contained in:
黄昕 2023-05-04 17:42:33 +08:00
parent 85b6b108df
commit 641ddfd3d8
5 changed files with 115 additions and 22 deletions

View File

@ -53,6 +53,7 @@ typedef enum {
typedef struct { typedef struct {
U8 *p; U8 *p;
int buf_size; int buf_size;
unsigned int tm;
} BUF_INFO, *PBUF_INFO; } BUF_INFO, *PBUF_INFO;
typedef struct { typedef struct {

View File

@ -9,6 +9,9 @@
#include "zlog_module.h" #include "zlog_module.h"
#include "dhcp_network.h" #include "dhcp_network.h"
#define MAIN_WND_WIDTH (1024)
#define MAIN_WND_HEIGHT (768)
#define ZLOG_CFG_PATH "./config/zlog.conf" #define ZLOG_CFG_PATH "./config/zlog.conf"
static GtkBuilder *g_mainBuilder = NULL; static GtkBuilder *g_mainBuilder = NULL;
@ -53,7 +56,7 @@ static double calc_total_progress(PDHCP_INFO pInfo) {
pre_cnt += pInfo->step * 20; pre_cnt += pInfo->step * 20;
pre_cnt += pInfo->status * 5; pre_cnt += pInfo->status * 5;
return pre_cnt; return MIN(pre_cnt, 100.0);
} }
static gboolean calc_step_progress(PDHCP_INFO pInfo, DHCP_STEP step) { static gboolean calc_step_progress(PDHCP_INFO pInfo, DHCP_STEP step) {
@ -64,32 +67,37 @@ static gboolean calc_step_progress(PDHCP_INFO pInfo, DHCP_STEP step) {
return FALSE; return FALSE;
} }
void view_popup_menu_onDoSomething(GtkWidget *menuitem, gpointer userdata) { void view_popup_menu_onStatistics(GtkWidget *UNUSED(menuitem), gpointer UNUSED(userdata)) {
}
void view_popup_menu_onBinaryPkg(GtkWidget *UNUSED(menuitem), gpointer userdata) {
PDHCP_INFO pInfo = (PDHCP_INFO)userdata; PDHCP_INFO pInfo = (PDHCP_INFO)userdata;
//GtkWidget *deatilWnd = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "wndDetails")); //GtkWidget *deatilWnd = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "wndDetails"));
// //
g_print("Do something of %s\n", pInfo->treeId); //g_print("Do something of %s\n", pInfo->treeId);
//gtk_notebook_set_current_page(GTK_NOTEBOOK(tab), 0); //gtk_notebook_set_current_page(GTK_NOTEBOOK(tab), 0);
//gtk_widget_show(deatilWnd); //gtk_widget_show(deatilWnd);
details_wnd_show(pInfo); details_wnd_show(pInfo);
} }
void view_popup_menu(GtkWidget *treeview, GdkEventButton *event, gpointer userdata) { void view_popup_menu(GtkWidget *UNUSED(treeview), GdkEventButton *event, gpointer userdata) {
GtkWidget *menu, *menuitem; GtkWidget *menu, *menuitem;
menu = gtk_menu_new(); menu = gtk_menu_new();
menuitem = gtk_menu_item_new_with_label("详细信息"); menuitem = gtk_menu_item_new_with_label("数据包详情");
g_signal_connect(menuitem, "activate", (GCallback)view_popup_menu_onBinaryPkg, userdata);
g_signal_connect(menuitem, "activate", (GCallback)view_popup_menu_onDoSomething, userdata); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_menu_item_new_with_label("统计信息");
g_signal_connect(menuitem, "activate", (GCallback)view_popup_menu_onStatistics, userdata);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_show_all(menu); gtk_widget_show_all(menu);
gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent *)event); gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent *)event);
} }
gboolean view_onButtonPressed(GtkWidget *treeview, GdkEventButton *event, gpointer userdata) { gboolean view_onButtonPressed(GtkWidget *treeview, GdkEventButton *event, gpointer UNUSED(userdata)) {
gboolean showMenu = FALSE; gboolean showMenu = FALSE;
PDHCP_INFO p = NULL; PDHCP_INFO p = NULL;
@ -299,7 +307,7 @@ static gboolean tree_view_data_store_upgade(gpointer pInfo) {
return TRUE; return TRUE;
} }
static void mainWnd_on_destroy(GObject *object, gpointer user_data) { static void mainWnd_on_destroy(GObject *UNUSED(object), gpointer UNUSED(user_data)) {
task_manager_exit(); task_manager_exit();
g_thread_unref(g_pEvLoopThread); g_thread_unref(g_pEvLoopThread);
gtk_main_quit(); gtk_main_quit();
@ -327,7 +335,7 @@ int cacheDhcpAckBuffer(PDHCP_INFO pInfo, U8 *pBuf, int size) {
return -ERR_MALLOC_MEMORY; return -ERR_MALLOC_MEMORY;
} }
_Noreturn static void *dhcpThreadCb(void *pData) { _Noreturn static void *dhcpThreadCb(void *UNUSED(pData)) {
U8 *pkg; U8 *pkg;
int size = 0; int size = 0;
PDHCP_INFO pInfo, pTemp; PDHCP_INFO pInfo, pTemp;
@ -347,6 +355,7 @@ _Noreturn static void *dhcpThreadCb(void *pData) {
pInfo->pDiscBuf.buf_size = size; pInfo->pDiscBuf.buf_size = size;
pInfo->step = STEP_DISCOVER; pInfo->step = STEP_DISCOVER;
pInfo->status = STA_WAIT_START; pInfo->status = STA_WAIT_START;
pInfo->pDiscBuf.tm = time(NULL);
g_idle_add(tree_view_data_store_upgade, pInfo); g_idle_add(tree_view_data_store_upgade, pInfo);
} }
break; break;
@ -372,6 +381,7 @@ _Noreturn static void *dhcpThreadCb(void *pData) {
pInfo->pReqBuf.buf_size = size; pInfo->pReqBuf.buf_size = size;
pInfo->step = STEP_REQUEST; pInfo->step = STEP_REQUEST;
pInfo->status = STA_WAIT_START; pInfo->status = STA_WAIT_START;
pInfo->pReqBuf.tm = time(NULL);
g_idle_add(tree_view_data_store_upgade, pInfo); g_idle_add(tree_view_data_store_upgade, pInfo);
} }
} }
@ -391,6 +401,7 @@ _Noreturn static void *dhcpThreadCb(void *pData) {
} }
break; break;
case STEP_ACK: case STEP_ACK:
pInfo->step = STEP_END;
break; break;
case STEP_END: case STEP_END:
break; break;
@ -426,7 +437,7 @@ static void cleanupDHCPInfo() {
} }
} }
static void mainWnd_on_tb_start(GObject *object, gpointer user_data) { static void mainWnd_on_tb_start(GObject *object, gpointer UNUSED(user_data)) {
int i, j, index = 0; int i, j, index = 0;
GtkTreeIter iter; GtkTreeIter iter;
PDHCP_INFO pInfo; PDHCP_INFO pInfo;
@ -494,17 +505,42 @@ static void mainWnd_on_tb_start(GObject *object, gpointer user_data) {
g_runTask = TRUE; g_runTask = TRUE;
} }
static void mainWnd_on_tb_stop(GObject *object, gpointer user_data) { static void mainWnd_on_tb_stop(GObject *object, gpointer UNUSED(user_data)) {
GtkWidget *startButton = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbStart")); GtkWidget *startButton = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbStart"));
GtkWidget *nicSelect = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "cbNicName")); GtkWidget *nicSelect = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "cbNicName"));
GtkWidget *tbExpand = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbExpand"));
g_runTask = FALSE; g_runTask = FALSE;
gtk_widget_set_sensitive(GTK_WIDGET(object), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(object), FALSE);
gtk_widget_set_sensitive(startButton, TRUE); gtk_widget_set_sensitive(startButton, TRUE);
gtk_widget_set_sensitive(nicSelect, TRUE); gtk_widget_set_sensitive(nicSelect, TRUE);
gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(tbExpand), FALSE);
g_object_set(G_OBJECT(tbExpand), "stock_id", "gtk-indent", NULL);
} }
static void *uv_loop_thread(void *pData) { static void mainWnd_on_tb_expand(GObject *object, gpointer UNUSED(user_data)) {
GtkWidget *view = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "treeResult"));
if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(object))) {
gtk_tree_view_expand_all(GTK_TREE_VIEW(view));
g_object_set(object, "stock_id", "gtk-unindent", NULL);
} else {
gtk_tree_view_collapse_all(GTK_TREE_VIEW(view));
g_object_set(object, "stock_id", "gtk-indent", NULL);
}
}
static void mainWnd_on_tb_cleanup(GObject *UNUSED(object), gpointer UNUSED(user_data)) {
GtkWidget *view = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "treeResult"));
GtkTreeStore *store = GTK_TREE_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo"));
GtkWidget *tbStop = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbStop"));
gtk_tree_view_set_model(GTK_TREE_VIEW(view), NULL);
gtk_tree_store_clear(store);
cleanupDHCPInfo();
mainWnd_on_tb_stop(G_OBJECT(tbStop), NULL);
}
static void *uv_loop_thread(void *UNUSED(pData)) {
task_manager_run(); task_manager_run();
return NULL; return NULL;
} }
@ -540,6 +576,12 @@ int main(int args, char **argv) {
GtkWidget *tbStop = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbStop")); GtkWidget *tbStop = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbStop"));
g_signal_connect(tbStop, "clicked", G_CALLBACK(mainWnd_on_tb_stop), g_mainBuilder); g_signal_connect(tbStop, "clicked", G_CALLBACK(mainWnd_on_tb_stop), g_mainBuilder);
GtkWidget *tbExpand = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbExpand"));
g_signal_connect(tbExpand, "clicked", G_CALLBACK(mainWnd_on_tb_expand), g_mainBuilder);
GtkWidget *tbClean = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbCleanup"));
g_signal_connect(tbClean, "clicked", G_CALLBACK(mainWnd_on_tb_cleanup), g_mainBuilder);
GtkWidget *cbNic = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "cbNicName")); GtkWidget *cbNic = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "cbNicName"));
for (i = 0; i < info.nicCnt; i++) { for (i = 0; i < info.nicCnt; i++) {
GtkListStore *store = GTK_LIST_STORE(gtk_builder_get_object(g_mainBuilder, "lsNicName")); GtkListStore *store = GTK_LIST_STORE(gtk_builder_get_object(g_mainBuilder, "lsNicName"));
@ -586,6 +628,14 @@ int main(int args, char **argv) {
G_TYPE_FLOAT); G_TYPE_FLOAT);
#endif #endif
GdkDisplay *display = gdk_display_get_default();
GdkMonitor *monitor = gdk_display_get_primary_monitor(display);
GdkRectangle rect;
gdk_monitor_get_geometry(monitor, &rect);
gtk_widget_set_size_request(mainWnd, MAIN_WND_WIDTH, MAIN_WND_HEIGHT); // 设置窗口的最小大小
gtk_window_move(GTK_WINDOW(mainWnd), (rect.width - MAIN_WND_WIDTH) / 2, (rect.height - MAIN_WND_HEIGHT) / 2);
gtk_builder_connect_signals(g_mainBuilder, NULL); gtk_builder_connect_signals(g_mainBuilder, NULL);
gtk_widget_show(mainWnd); gtk_widget_show(mainWnd);

View File

@ -38,6 +38,7 @@
</object> </object>
<object class="GtkWindow" id="wndMain"> <object class="GtkWindow" id="wndMain">
<property name="width_request">1024</property> <property name="width_request">1024</property>
<property name="height_request">768</property>
<child> <child>
<object class="GtkVBox" id="vbWnd"> <object class="GtkVBox" id="vbWnd">
<property name="visible">True</property> <property name="visible">True</property>
@ -187,7 +188,7 @@
<object class="GtkToolButton" id="tbStart"> <object class="GtkToolButton" id="tbStart">
<property name="visible">True</property> <property name="visible">True</property>
<property name="is_important">True</property> <property name="is_important">True</property>
<property name="label" translatable="yes">Start</property> <property name="label" translatable="yes">&#x5F00;&#x59CB;</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-media-play</property> <property name="stock_id">gtk-media-play</property>
</object> </object>
@ -201,7 +202,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="sensitive">False</property> <property name="sensitive">False</property>
<property name="is_important">True</property> <property name="is_important">True</property>
<property name="label" translatable="yes">Stop</property> <property name="label" translatable="yes">&#x505C;&#x6B62;</property>
<property name="stock_id">gtk-media-stop</property> <property name="stock_id">gtk-media-stop</property>
</object> </object>
<packing> <packing>
@ -209,6 +210,48 @@
<property name="homogeneous">True</property> <property name="homogeneous">True</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkSeparatorToolItem" id="toolbutton1">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToggleToolButton" id="tbExpand">
<property name="visible">True</property>
<property name="label" translatable="yes">&#x5C55;&#x5F00;</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-unindent</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="tbCleanup">
<property name="visible">True</property>
<property name="label" translatable="yes">&#x6E05;&#x9664;</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-delete</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkSeparatorToolItem" id="toolbutton2">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>

View File

@ -154,7 +154,6 @@ U8 *dhcp_create_discover_req(PDHCP_INFO pInfo, int *pOutSize) {
static void on_dhcp_recv(uv_work_t *req) { static void on_dhcp_recv(uv_work_t *req) {
PDHCP_INFO pInfo; PDHCP_INFO pInfo;
U32 ip;
DHCP_RSP rspDhcp; DHCP_RSP rspDhcp;
DHCP_OPT optMsg, opt; DHCP_OPT optMsg, opt;
int ret; int ret;
@ -230,6 +229,7 @@ static void on_dhcp_recv(uv_work_t *req) {
cacheDhcpOfferBuffer(pInfo, pWork->pPkgBase, pWork->nSize); cacheDhcpOfferBuffer(pInfo, pWork->pPkgBase, pWork->nSize);
memcpy(&pInfo->offerRsp, &rspDhcp, sizeof(DHCP_RSP)); memcpy(&pInfo->offerRsp, &rspDhcp, sizeof(DHCP_RSP));
pInfo->pOfferBuf.tm = time(NULL);
break; break;
case DHCP_MSG_ACK: case DHCP_MSG_ACK:
pInfo->step = STEP_ACK; pInfo->step = STEP_ACK;
@ -237,6 +237,7 @@ static void on_dhcp_recv(uv_work_t *req) {
cacheDhcpAckBuffer(pInfo, pWork->pPkgBase, pWork->nSize); cacheDhcpAckBuffer(pInfo, pWork->pPkgBase, pWork->nSize);
memcpy(&pInfo->ackRsp, &rspDhcp, sizeof(DHCP_RSP)); memcpy(&pInfo->ackRsp, &rspDhcp, sizeof(DHCP_RSP));
pInfo->pAckBuf.tm = time(NULL);
break; break;
case DHCP_MSG_NAK: case DHCP_MSG_NAK:
break; break;
@ -244,9 +245,6 @@ static void on_dhcp_recv(uv_work_t *req) {
} }
int dhcp_tools_init_network(const char *pNicName) { int dhcp_tools_init_network(const char *pNicName) {
static RECV_CB_DATA rcData;
static uv_poll_t uvSocket;
static uv_timer_t uvTm;
int ret; int ret;
if (g_pNicName == NULL) { if (g_pNicName == NULL) {

View File

@ -562,6 +562,7 @@ static void on_sock_recv(uv_work_t *req) {
if (ret == ERR_SUCCESS) { if (ret == ERR_SUCCESS) {
LOG_MOD(debug, ZM_DHCP_NET, "User %u DHCP prepare assign ipaddress: [%s(%s)] --> %s\n", reqDhcp.uid, LOG_MOD(debug, ZM_DHCP_NET, "User %u DHCP prepare assign ipaddress: [%s(%s)] --> %s\n", reqDhcp.uid,
macStr, reqDhcp.hostName, u32_to_str_ip(ntohl(reqDhcp.cliAddr))); macStr, reqDhcp.hostName, u32_to_str_ip(ntohl(reqDhcp.cliAddr)));
// 可以向客户端回复租约信息
} else { } else {
LOG_MOD(error, ZM_DHCP_NET, "DHCP prepare assign ipaddress error: User %u [%s(%s)] resion %s\n", LOG_MOD(error, ZM_DHCP_NET, "DHCP prepare assign ipaddress error: User %u [%s(%s)] resion %s\n",
reqDhcp.uid, macStr, reqDhcp.hostName, getErrorEnumNameString(ret)); reqDhcp.uid, macStr, reqDhcp.hostName, getErrorEnumNameString(ret));