diff --git a/dhcp_tools/main.h b/dhcp_tools/main.h index fdde175..e186629 100644 --- a/dhcp_tools/main.h +++ b/dhcp_tools/main.h @@ -10,6 +10,7 @@ typedef enum { COL_INDEX = 0, + COL_VNI, COL_MAC, COL_HOSTNAME, COL_DISCOVER, @@ -20,6 +21,7 @@ typedef enum { COL_STATUS, COL_ATTR_EDITABLE, + COL_ATTR_VISIABLE, NUM_COLS } COL_NAME; @@ -44,19 +46,19 @@ typedef struct { } BUF_INFO, *PBUF_INFO; typedef struct { - U32 index; - U32 vni; - U8 mac[6]; - S8 hostname[64]; - DHCP_STEP step; - DHCP_STATUS status; - BUF_INFO pDiscBuf; - BUF_INFO pOfferBuf; - BUF_INFO pReqBuf; - BUF_INFO pAckBuf; - DHCP_RSP offerRsp; - DHCP_RSP ackRsp; - UT_hash_handle hh; + U32 index; + U32 vni; + U8 mac[6]; + S8 hostname[64]; + DHCP_STEP step; + DHCP_STATUS status; + BUF_INFO pDiscBuf; + BUF_INFO pOfferBuf; + BUF_INFO pReqBuf; + BUF_INFO pAckBuf; + DHCP_RSP offerRsp; + DHCP_RSP ackRsp; + UT_hash_handle hh; } DHCP_INFO, *PDHCP_INFO; U32 rand_number(); diff --git a/dhcp_tools/main_wnd.c b/dhcp_tools/main_wnd.c index 3e4ace5..22af386 100644 --- a/dhcp_tools/main_wnd.c +++ b/dhcp_tools/main_wnd.c @@ -3,7 +3,6 @@ // #include #include -#include "common.h" #include "main.h" #include "misc.h" #include "task_manager.h" @@ -44,8 +43,7 @@ static void load_css(void) { display = gdk_display_get_default(); screen = gdk_display_get_default_screen(display); - gtk_style_context_add_provider_for_screen(screen, - GTK_STYLE_PROVIDER(provider), + gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); gtk_css_provider_load_from_file(provider, css_fp, &error); @@ -74,40 +72,66 @@ static void tree_view_data_store_create() { int i, j; PDHCP_INFO pInfo, pTemp; GtkTreeIter iter, iter_child, iter_sub; - GtkWidget *view = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "treeResult")); - GtkListStore *store = GTK_LIST_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo")); + GtkWidget *view = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "treeResult")); + GtkTreeStore *store = GTK_TREE_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo")); + GtkWidget *vniStart = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "sbVni")); + GtkWidget *numRequest = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "sbReqNum")); + int nRequest = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(numRequest)); + int nVni = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(vniStart)); gtk_tree_view_set_model(GTK_TREE_VIEW(view), NULL); - gtk_list_store_clear(store); + gtk_tree_store_clear(store); - HASH_ITER(hh, g_pDhcpInfo, pInfo, pTemp) { - char mac[24] = {0}; - sprintf(mac, - "%02X:%02X:%02X:%02X:%02X:%02X", - pInfo->mac[0], - pInfo->mac[1], - pInfo->mac[2], - pInfo->mac[3], - pInfo->mac[4], - pInfo->mac[5]); + for (i = 0; i < nRequest; i++) { + int isCreateRoot = FALSE; - gtk_list_store_append(store, &iter); + HASH_ITER(hh, g_pDhcpInfo, pInfo, pTemp) { + if (pInfo->vni == (nVni + i)) { + char idx[64] = {0}; + char mac[24] = {0}; + sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", pInfo->mac[0], pInfo->mac[1], pInfo->mac[2], + pInfo->mac[3], pInfo->mac[4], pInfo->mac[5]); - // clang-format off - gtk_list_store_set(store, + if (!isCreateRoot) { + sprintf(idx, "VNI %d", nVni + i); + // 创建根节点 + gtk_tree_store_append(store, &iter, NULL); + // clang-format off + gtk_tree_store_set(store, &iter, - COL_INDEX, pInfo->index, - COL_MAC, mac, - COL_HOSTNAME, pInfo->hostname, - COL_DISCOVER, calc_step_progress(pInfo, STEP_DISCOVER), - COL_OFFER, calc_step_progress(pInfo, STEP_OFFER), - COL_REQUEST, calc_step_progress(pInfo, STEP_REQUEST), - COL_ACK, calc_step_progress(pInfo, STEP_ACK), + COL_INDEX, idx, COL_RESULT, "", COL_STATUS, calc_total_progress(pInfo), COL_ATTR_EDITABLE, FALSE, + COL_ATTR_VISIABLE, FALSE, -1); - // clang-format on + // clang-format on + isCreateRoot = TRUE; + } + + gtk_tree_store_append(store, &iter_child, &iter); + + // clang-format off + // 创建子节点 + memset(idx, 0, 64); + sprintf(idx, "%u", pInfo->index); + gtk_tree_store_set(store, + &iter_child, + COL_INDEX, idx, + COL_MAC, mac, + COL_HOSTNAME, pInfo->hostname, + COL_DISCOVER, calc_step_progress(pInfo, STEP_DISCOVER), + COL_OFFER, calc_step_progress(pInfo, STEP_OFFER), + COL_REQUEST, calc_step_progress(pInfo, STEP_REQUEST), + COL_ACK, calc_step_progress(pInfo, STEP_ACK), + COL_RESULT, "", + COL_STATUS, calc_total_progress(pInfo), + COL_ATTR_EDITABLE, FALSE, + COL_ATTR_VISIABLE, TRUE, + -1); + // clang-format on + } + } } gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); @@ -165,9 +189,10 @@ static void tree_view_data_store_create() { } static gboolean tree_view_data_store_upgade(gpointer pInfo) { +#if 0 char buf[32] = {0}; GtkTreeIter iter; - GtkListStore *store = GTK_LIST_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo")); + GtkTreeStore *store = GTK_TREE_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo")); if (!pInfo) { return FALSE; @@ -177,7 +202,7 @@ static gboolean tree_view_data_store_upgade(gpointer pInfo) { if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, buf)) { // clang-format off - gtk_list_store_set(store, + gtk_tree_store_set(store, &iter, COL_DISCOVER, calc_step_progress(pInfo, STEP_DISCOVER), COL_OFFER, calc_step_progress(pInfo, STEP_OFFER), @@ -186,10 +211,11 @@ static gboolean tree_view_data_store_upgade(gpointer pInfo) { COL_RESULT, "", COL_STATUS, calc_total_progress(pInfo), COL_ATTR_EDITABLE, FALSE, + COL_ATTR_VISIABLE, TRUE, -1); // clang-format on } - +#endif return TRUE; } @@ -210,7 +236,7 @@ int cacheDhcpOfferBuffer(PDHCP_INFO pInfo, U8 *pBuf, int size) { return -ERR_MALLOC_MEMORY; } -static void *dhcpThreadCb(void *pData) { +_Noreturn static void *dhcpThreadCb(void *pData) { U8 *pkg; int size = 0; PDHCP_INFO pInfo, pTemp; @@ -286,7 +312,6 @@ static void *dhcpThreadCb(void *pData) { LOG_MSG(debug, "DHCP status mathine exit......\n"); g_thread_exit(NULL); - return NULL; } static void cleanupDHCPInfo() { @@ -341,28 +366,28 @@ G_MODULE_EXPORT void __mainWnd_on_tb_start(GObject *object, gpointer user_data) for (i = 0; i < nRequest; i++) { for (j = 0; j < nVniCnt; j++) { U32 macAddr = macVal + index; - pInfo = (PDHCP_INFO)malloc(sizeof(DHCP_INFO)); + pInfo = (PDHCP_INFO)malloc(sizeof(DHCP_INFO)); - if (pInfo == NULL) { - fprintf(stderr, "Malloc %lu bytes memory error of %d\n", sizeof(DHCP_INFO), i); - continue; - } + if (pInfo == NULL) { + fprintf(stderr, "Malloc %lu bytes memory error of %d\n", sizeof(DHCP_INFO), i); + continue; + } - memset(pInfo, 0, sizeof(DHCP_INFO)); + memset(pInfo, 0, sizeof(DHCP_INFO)); pInfo->index = index; - pInfo->vni = nVni + i; - pInfo->mac[0] = mac[0]; - pInfo->mac[1] = mac[1]; - pInfo->mac[2] = (macAddr & 0xFF000000) >> 24; - pInfo->mac[3] = (macAddr & 0xFF0000) >> 16; - pInfo->mac[4] = (macAddr & 0xFF00) >> 8; - pInfo->mac[5] = (macAddr & 0xFF); + pInfo->vni = nVni + i; + pInfo->mac[0] = mac[0]; + pInfo->mac[1] = mac[1]; + pInfo->mac[2] = (macAddr & 0xFF000000) >> 24; + pInfo->mac[3] = (macAddr & 0xFF0000) >> 16; + pInfo->mac[4] = (macAddr & 0xFF00) >> 8; + pInfo->mac[5] = (macAddr & 0xFF); sprintf(pInfo->hostname, "%s_%u", strPreHostname, pInfo->vni + index); - pInfo->step = STEP_BEGIN; - pInfo->status = STA_WAIT_START; + pInfo->step = STEP_BEGIN; + pInfo->status = STA_WAIT_START; - HASH_ADD_INT(g_pDhcpInfo, index, pInfo); + HASH_ADD_INT(g_pDhcpInfo, index, pInfo); index++; } } diff --git a/dhcp_tools/res/main.glade b/dhcp_tools/res/main.glade index 68a74b9..f66ca34 100644 --- a/dhcp_tools/res/main.glade +++ b/dhcp_tools/res/main.glade @@ -8,9 +8,11 @@ - + + + @@ -30,6 +32,8 @@ + + @@ -421,6 +425,19 @@ + + + False + VNI + 0.5 + + + + 1 + + + + MAC @@ -428,7 +445,8 @@ - 1 + 11 + 2 @@ -440,7 +458,8 @@ - 2 + 11 + 3 @@ -454,8 +473,9 @@ - 9 - 3 + 10 + 11 + 4 @@ -469,8 +489,9 @@ - 9 - 4 + 10 + 11 + 5 @@ -484,8 +505,9 @@ - 9 - 5 + 10 + 11 + 6 @@ -499,8 +521,9 @@ - 9 - 6 + 10 + 11 + 7 @@ -514,7 +537,7 @@ - 7 + 8 @@ -528,7 +551,7 @@ - 8 + 9