void chfsnp_mgr_print_db(LOG *log, const CHFSNP_MGR *chfsnp_mgr) { uint32_t chfsnp_home_dir_num; uint32_t chfsnp_home_dir_pos; uint32_t chfsnp_num; uint32_t chfsnp_id; sys_log(log, "chfsnp mgr db root dir : %s\n", (char *)CHFSNP_MGR_DB_ROOT_DIR_STR(chfsnp_mgr)); sys_log(log, "chfsnp model : %u\n", CHFSNP_MGR_NP_MODEL(chfsnp_mgr)); sys_log(log, "chfsnp 1st hash algo id : %u\n", CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID(chfsnp_mgr)); sys_log(log, "chfsnp 2nd hash algo id : %u\n", CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID(chfsnp_mgr)); sys_log(log, "chfsnp item max num : %u\n", CHFSNP_MGR_NP_ITEM_MAX_NUM(chfsnp_mgr)); sys_log(log, "chfsnp max num : %u\n", CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr)); chfsnp_home_dir_num = (uint32_t)cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr)); for(chfsnp_home_dir_pos = 0; chfsnp_home_dir_pos < chfsnp_home_dir_num; chfsnp_home_dir_pos ++) { CSTRING *chfsnp_home_dir_cstr; chfsnp_home_dir_cstr = cvector_get_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), chfsnp_home_dir_pos); if(NULL_PTR == chfsnp_home_dir_cstr || EC_TRUE == cstring_is_empty(chfsnp_home_dir_cstr)) { sys_log(log, "home dir %u #: (null)\n", chfsnp_home_dir_pos); } else { sys_log(log, "home dir %u #: %.*s\n", chfsnp_home_dir_pos, cstring_get_len(chfsnp_home_dir_cstr), (char *)cstring_get_str(chfsnp_home_dir_cstr)); } } chfsnp_num = (uint32_t)cvector_size(CHFSNP_MGR_NP_VEC(chfsnp_mgr)); for(chfsnp_id = 0; chfsnp_id < chfsnp_num; chfsnp_id ++) { CHFSNP *chfsnp; chfsnp = CHFSNP_MGR_NP(chfsnp_mgr, chfsnp_id); if(NULL_PTR == chfsnp) { sys_log(log, "np %u #: (null)\n", chfsnp_id); } else { chfsnp_print(log, chfsnp); } } return; }
EC_BOOL taskcfgchk_route_print(LOG *log, const TASK_CFG *task_cfg, const UINT32 tcid, const UINT32 maski, const UINT32 maske) { TASKS_CFG *tasks_cfg; UINT32 pos; tasks_cfg = task_cfg_searchs(task_cfg, tcid, maski, maske); if(NULL_PTR == tasks_cfg) { sys_log(log, "error:taskcfgchk_route_print: no tasks cfg for tcid %s maski %s, maske %s\n", c_word_to_ipv4(tcid), c_word_to_ipv4(maski), c_word_to_ipv4(maske)); return (EC_FALSE); } CVECTOR_LOCK(TASKS_CFG_TASKR_CFG_VEC(tasks_cfg), LOC_TASKCFGCHK_0003); for(pos = 0; pos < cvector_size(TASKS_CFG_TASKR_CFG_VEC(tasks_cfg)); pos ++) { TASKR_CFG *taskr_cfg; taskr_cfg = (TASKR_CFG *)cvector_get_no_lock(TASKS_CFG_TASKR_CFG_VEC(tasks_cfg), pos); if(NULL_PTR == taskr_cfg) { continue; } sys_log(log, "[TASKCFGCHK] route No. %ld: des_tcid = %s, maskr = %s, next_tcid = %s\n", pos, TASKR_CFG_DES_TCID_STR(taskr_cfg), TASKR_CFG_MASKR_STR(taskr_cfg), TASKR_CFG_NEXT_TCID_STR(taskr_cfg)); } CVECTOR_UNLOCK(TASKS_CFG_TASKR_CFG_VEC(tasks_cfg), LOC_TASKCFGCHK_0004); return (EC_TRUE); }
static EC_BOOL taskcfgchk_conn_test(const TASK_CFG *task_cfg, const TASKS_CFG *local_tasks_cfg, const UINT32 remote_tcid) { UINT32 pos; CVECTOR_LOCK(TASK_CFG_TASKS_CFG_VEC(task_cfg), LOC_TASKCFGCHK_0008); for(pos = 0; pos < cvector_size(TASK_CFG_TASKS_CFG_VEC(task_cfg)); pos ++) { TASKS_CFG *remote_tasks_cfg; remote_tasks_cfg = (TASKS_CFG *)cvector_get_no_lock(TASK_CFG_TASKS_CFG_VEC(task_cfg), pos); if(NULL_PTR == remote_tasks_cfg) { continue; } if( (remote_tcid == TASKS_CFG_TCID(remote_tasks_cfg)) && ( EC_TRUE == tasks_cfg_is_intranet(local_tasks_cfg, remote_tasks_cfg) || EC_TRUE == tasks_cfg_is_externet(local_tasks_cfg, remote_tasks_cfg) || EC_TRUE == tasks_cfg_is_lannet(local_tasks_cfg, remote_tasks_cfg) || EC_TRUE == tasks_cfg_is_dbgnet(local_tasks_cfg, remote_tasks_cfg) || EC_TRUE == tasks_cfg_is_monnet(local_tasks_cfg, remote_tasks_cfg) ) ) { CVECTOR_UNLOCK(TASK_CFG_TASKS_CFG_VEC(task_cfg), LOC_TASKCFGCHK_0009); return (EC_TRUE); } } CVECTOR_UNLOCK(TASK_CFG_TASKS_CFG_VEC(task_cfg), LOC_TASKCFGCHK_0010); return (EC_FALSE); }
EC_BOOL chfsnp_mgr_show_cached_np(LOG *log, const CHFSNP_MGR *chfsnp_mgr) { uint32_t chfsnp_num; uint32_t chfsnp_pos; chfsnp_num = cvector_size(CHFSNP_MGR_NP_VEC(chfsnp_mgr)); for(chfsnp_pos = 0; chfsnp_pos < chfsnp_num; chfsnp_pos ++) { CHFSNP *chfsnp; chfsnp = CHFSNP_MGR_NP(chfsnp_mgr, chfsnp_pos); if(NULL_PTR != chfsnp) { CSTRING *home_dir; home_dir = CHFSNP_MGR_NP_HOME_DIR(chfsnp_mgr, chfsnp_pos); if(NULL_PTR == home_dir) { sys_log(log, "home dir: (null)\n"); } else { sys_log(log, "home dir: %s\n", (char *)cstring_get_str(home_dir)); } chfsnp_print(log, chfsnp); } } return (EC_TRUE); }
EC_BOOL taskcfgchk_net_all(LOG *log, const TASK_CFG *task_cfg) { UINT32 pos; CVECTOR_LOCK(TASK_CFG_TASKS_CFG_VEC(task_cfg), LOC_TASKCFGCHK_0015); for(pos = 0; pos < cvector_size(TASK_CFG_TASKS_CFG_VEC(task_cfg)); pos ++) { TASKS_CFG *tasks_cfg; TASK_CFG *des_task_cfg; tasks_cfg = (TASKS_CFG *)cvector_get_no_lock(TASK_CFG_TASKS_CFG_VEC(task_cfg), pos); if(NULL_PTR == tasks_cfg) { continue; } sys_log(log, "[TASKCFGCHK] ------------------------------ check tcid %s, maski %s, maske %s ----------------------------------\n", TASKS_CFG_TCID_STR(tasks_cfg), TASKS_CFG_MASKI_STR(tasks_cfg), TASKS_CFG_MASKE_STR(tasks_cfg) ); des_task_cfg = task_cfg_new(); task_cfg_filter(task_cfg, TASKS_CFG_TCID(tasks_cfg), des_task_cfg); task_cfg_print_xml(log, des_task_cfg, 0); task_cfg_free(des_task_cfg); } return (EC_TRUE); }
CROUTER_NODE *crouter_node_vec_find(CROUTER_NODE_VEC *crouter_node_vec, const UINT32 des_tcid) { UINT32 pos; CVECTOR_LOCK(CROUTER_NODE_VEC_NODES(crouter_node_vec), LOC_CROUTER_0033); for(pos = 0; pos < cvector_size(CROUTER_NODE_VEC_NODES(crouter_node_vec)); pos ++) { CROUTER_NODE *crouter_node; crouter_node = (CROUTER_NODE *)cvector_get_no_lock(CROUTER_NODE_VEC_NODES(crouter_node_vec), pos); if(NULL_PTR == crouter_node) { continue; } if(des_tcid == CROUTER_NODE_DES_TCID(crouter_node)) { CVECTOR_UNLOCK(CROUTER_NODE_VEC_NODES(crouter_node_vec), LOC_CROUTER_0034); return (crouter_node); } } CVECTOR_UNLOCK(CROUTER_NODE_VEC_NODES(crouter_node_vec), LOC_CROUTER_0035); return (NULL_PTR); }
TASKS_NODE * crouter_node_min_load_next_hop(const CROUTER_NODE *crouter_node) { UINT32 pos; UINT32 min_load; TASKS_NODE *min_tasks_node; min_load = ((UINT32)-1); min_tasks_node = NULL_PTR; CVECTOR_LOCK(CROUTER_NODE_NEXT_HOPS(crouter_node), LOC_CROUTER_0015); for(pos = 0; pos < cvector_size(CROUTER_NODE_NEXT_HOPS(crouter_node)); pos ++) { TASKS_NODE *tasks_node; UINT32 cur_load; tasks_node = (TASKS_NODE *)cvector_get_no_lock(CROUTER_NODE_NEXT_HOPS(crouter_node), pos); if(NULL_PTR == tasks_node) { continue; } cur_load = TASKS_NODE_LOAD(tasks_node);/*replace it when TASKS_NOE implement load*/ if(min_load > cur_load) { min_load = cur_load; min_tasks_node = tasks_node; } } CVECTOR_UNLOCK(CROUTER_NODE_NEXT_HOPS(crouter_node), LOC_CROUTER_0016); return (min_tasks_node); }
void test_cvector_size() { cvector vec; int tester = 1; /* start the test */ /* run the functions */ cvector_init(&vec, int_function_registry()); /* test the results */; FO_ASSERT_EQUAL(cvector_size(vec), 0); cvector_push_back(vec, &tester); FO_ASSERT_EQUAL(cvector_size(vec), 1); cvector_push_back(vec, &tester); FO_ASSERT_EQUAL(cvector_size(vec), 2); cvector_destroy(vec); }
EC_BOOL taskcfgchk_conn_print(LOG *log, const TASK_CFG *task_cfg, const UINT32 tcid, const UINT32 maski, const UINT32 maske, const UINT32 remote_tcid) { TASKS_CFG *local_tasks_cfg; UINT32 pos; local_tasks_cfg = task_cfg_searchs(task_cfg, tcid, maski, maske); if(NULL_PTR == local_tasks_cfg) { sys_log(log, "error:taskcfgchk_conn_print: no tasks cfg for tcid %s maski %s, maske %s\n", c_word_to_ipv4(tcid), c_word_to_ipv4(maski), c_word_to_ipv4(maske)); return (EC_FALSE); } CVECTOR_LOCK(TASK_CFG_TASKS_CFG_VEC(task_cfg), LOC_TASKCFGCHK_0005); for(pos = 0; pos < cvector_size(TASK_CFG_TASKS_CFG_VEC(task_cfg)); pos ++) { TASKS_CFG *remote_tasks_cfg; remote_tasks_cfg = (TASKS_CFG *)cvector_get_no_lock(TASK_CFG_TASKS_CFG_VEC(task_cfg), pos); if(NULL_PTR == remote_tasks_cfg) { continue; } if( (remote_tcid == TASKS_CFG_TCID(remote_tasks_cfg)) && ( EC_TRUE == tasks_cfg_is_intranet(local_tasks_cfg, remote_tasks_cfg) || EC_TRUE == tasks_cfg_is_externet(local_tasks_cfg, remote_tasks_cfg) || EC_TRUE == tasks_cfg_is_lannet(local_tasks_cfg, remote_tasks_cfg) || EC_TRUE == tasks_cfg_is_dbgnet(local_tasks_cfg, remote_tasks_cfg) || EC_TRUE == tasks_cfg_is_monnet(local_tasks_cfg, remote_tasks_cfg) ) ) { sys_log(log, "[TASKCFGCHK] tcid %s maski %s maske %s --> tcid %s maski %s maske %s\n", TASKS_CFG_TCID_STR(local_tasks_cfg), TASKS_CFG_MASKI_STR(local_tasks_cfg), TASKS_CFG_MASKE_STR(local_tasks_cfg), TASKS_CFG_TCID_STR(remote_tasks_cfg), TASKS_CFG_MASKI_STR(remote_tasks_cfg), TASKS_CFG_MASKE_STR(remote_tasks_cfg) ); CVECTOR_UNLOCK(TASK_CFG_TASKS_CFG_VEC(task_cfg), LOC_TASKCFGCHK_0006); return (EC_TRUE); } } CVECTOR_UNLOCK(TASK_CFG_TASKS_CFG_VEC(task_cfg), LOC_TASKCFGCHK_0007); return (EC_FALSE); }
void test_cvector_size() { cvector vec; int tester = 1; /* start the test */ printf("Test cvector_size:"); /* run the functions */ cvector_init(&vec, int_function_registry()); /* test the results */; CU_ASSERT_EQUAL(cvector_size(vec), 0); cvector_push_back(vec, &tester); CU_ASSERT_EQUAL(cvector_size(vec), 1); cvector_push_back(vec, &tester); CU_ASSERT_EQUAL(cvector_size(vec), 2); cvector_destroy(vec); test_failure(); printf("\n"); }
static uint32_t __chfsnp_mgr_get_np_id_of_path(const CHFSNP_MGR *chfsnp_mgr, const uint32_t path_len, const uint8_t *path) { uint32_t chfsnp_num; uint32_t chfsnp_id; ASSERT(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) == cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr))); CHFSNP_MGR_NP_HOME_DIR_VEC_LOCK(chfsnp_mgr, LOC_CHFSNPMGR_0023); chfsnp_num = CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr); for(chfsnp_id = 0; chfsnp_id < chfsnp_num; chfsnp_id ++) { CSTRING *chfsnp_home_dir_cstr; uint32_t chfsnp_home_dir_len; uint8_t *chfsnp_home_dir_str; chfsnp_home_dir_cstr = CHFSNP_MGR_NP_HOME_DIR(chfsnp_mgr, chfsnp_id); if(NULL_PTR == chfsnp_home_dir_cstr || EC_TRUE == cstring_is_empty(chfsnp_home_dir_cstr)) { continue; } chfsnp_home_dir_len = (uint32_t)cstring_get_len(chfsnp_home_dir_cstr); chfsnp_home_dir_str = cstring_get_str(chfsnp_home_dir_cstr); sys_log(LOGSTDOUT, "[DEBUG] __chfsnp_mgr_get_np_id_of_path: %.*s vs %s\n", path_len, (char *)path, (char *)cstring_get_str(chfsnp_home_dir_cstr)); sys_log(LOGSTDOUT, "[DEBUG] __chfsnp_mgr_get_np_id_of_path: path_len %u, chfsnp_home_dir_len %u\n", path_len, chfsnp_home_dir_len); if(path_len < chfsnp_home_dir_len) { continue; } /*now path_len >= chfsnp_home_dir_len*/ if(path_len != chfsnp_home_dir_len && '/' != path[ chfsnp_home_dir_len ]) { continue; } if(0 == BCMP(path, chfsnp_home_dir_str, chfsnp_home_dir_len)) { CHFSNP_MGR_NP_HOME_DIR_VEC_UNLOCK(chfsnp_mgr, LOC_CHFSNPMGR_0024); return (chfsnp_id); } } CHFSNP_MGR_NP_HOME_DIR_VEC_UNLOCK(chfsnp_mgr, LOC_CHFSNPMGR_0025); return (CHFSNP_ERR_ID); }
CROUTER_NODE *crouter_node_vec_find_no_lock(CROUTER_NODE_VEC *crouter_node_vec, const UINT32 des_tcid) { UINT32 pos; for(pos = 0; pos < cvector_size(CROUTER_NODE_VEC_NODES(crouter_node_vec)); pos ++) { CROUTER_NODE *crouter_node; crouter_node = (CROUTER_NODE *)cvector_get_no_lock(CROUTER_NODE_VEC_NODES(crouter_node_vec), pos); if(NULL_PTR == crouter_node) { continue; } if(des_tcid == CROUTER_NODE_DES_TCID(crouter_node)) { return (crouter_node); } } return (NULL_PTR); }
/*bind home_dir and name node, i.e., one name node owns unique home dir*/ EC_BOOL chfsnp_mgr_bind(CHFSNP_MGR *chfsnp_mgr, const CSTRING *path, const UINT32 chfsnp_id) { CSTRING *home_dir; CSTRING *home_dir_old; uint32_t home_dir_pos; ASSERT(cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr)) == CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr)); if(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) <= chfsnp_id) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: max np num %u but chfsnp id %u overflow\n", CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr), chfsnp_id); return (EC_FALSE); } home_dir_pos = __chfsnp_mgr_get_np_id_of_path(chfsnp_mgr, (uint32_t)cstring_get_len(path), cstring_get_str(path)); if(CHFSNP_ERR_ID != home_dir_pos) { home_dir = cvector_get_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), home_dir_pos); sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: some dir %s already bound to np %u, thus cannot accept binding %s\n", (char *)cstring_get_str(home_dir), home_dir_pos, (char *)cstring_get_str(path)); return (EC_FALSE); } home_dir = cstring_dup(path); if(NULL_PTR == home_dir) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: dup %s failed\n", (char *)cstring_get_str(path)); return (EC_FALSE); } home_dir_old = (CSTRING *)cvector_set(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), chfsnp_id, (void *)home_dir); if(NULL_PTR != home_dir_old) { cstring_free(home_dir_old); } return (EC_TRUE); }
TASKS_NODE *crouter_node_find_next_hop_by_tcid(CROUTER_NODE *crouter_node, const UINT32 next_hop_tcid) { UINT32 pos; CVECTOR_LOCK(CROUTER_NODE_NEXT_HOPS(crouter_node), LOC_CROUTER_0012); for(pos = 0; pos < cvector_size(CROUTER_NODE_NEXT_HOPS(crouter_node)); pos ++) { TASKS_NODE *tasks_node; tasks_node = (TASKS_NODE *)cvector_get_no_lock(CROUTER_NODE_NEXT_HOPS(crouter_node), pos); if(NULL_PTR == tasks_node) { continue; } if(next_hop_tcid == TASKS_NODE_TCID(tasks_node)) { CVECTOR_UNLOCK(CROUTER_NODE_NEXT_HOPS(crouter_node), LOC_CROUTER_0013); return (tasks_node); } } CVECTOR_UNLOCK(CROUTER_NODE_NEXT_HOPS(crouter_node), LOC_CROUTER_0014); return (NULL_PTR); }
void crouter_node_print_in_plain(LOG *log, const CROUTER_NODE *crouter_node, UINT32 *index) { UINT32 pos; CVECTOR_LOCK(CROUTER_NODE_NEXT_HOPS(crouter_node), LOC_CROUTER_0007); for(pos = 0; pos < cvector_size(CROUTER_NODE_NEXT_HOPS(crouter_node)); pos ++) { TASKS_NODE *tasks_node; tasks_node = (TASKS_NODE *)cvector_get_no_lock(CROUTER_NODE_NEXT_HOPS(crouter_node), pos); if(NULL_PTR == tasks_node) { sys_log(log, "Route No. %ld: des tcid %s, next hop [%ld]: (null)\n", (*index) ++, CROUTER_NODE_DES_TCID_STR(crouter_node), pos); continue; } sys_log(log, "Route No. %ld: des tcid %s, next hop [%ld]: ", (*index) ++, CROUTER_NODE_DES_TCID_STR(crouter_node), pos); tasks_node_print_in_plain(log, tasks_node); } CVECTOR_UNLOCK(CROUTER_NODE_NEXT_HOPS(crouter_node), LOC_CROUTER_0008); return; }
EC_BOOL taskcfgchk_net_print(LOG *log, const TASK_CFG *task_cfg, const UINT32 tcid, const UINT32 maski, const UINT32 maske) { TASKS_CFG *local_tasks_cfg; UINT32 pos; local_tasks_cfg = task_cfg_searchs(task_cfg, tcid, maski, maske); if(NULL_PTR == local_tasks_cfg) { sys_log(log, "error:taskcfgchk_net_print: no tasks cfg for tcid %s maski %s, maske %s\n", c_word_to_ipv4(tcid), c_word_to_ipv4(maski), c_word_to_ipv4(maske)); return (EC_FALSE); } CVECTOR_LOCK(TASK_CFG_TASKS_CFG_VEC(task_cfg), LOC_TASKCFGCHK_0001); for(pos = 0; pos < cvector_size(TASK_CFG_TASKS_CFG_VEC(task_cfg)); pos ++) { TASKS_CFG *remote_tasks_cfg; remote_tasks_cfg = (TASKS_CFG *)cvector_get_no_lock(TASK_CFG_TASKS_CFG_VEC(task_cfg), pos); if(NULL_PTR == remote_tasks_cfg) { continue; } if(EC_TRUE == tasks_cfg_is_intranet(local_tasks_cfg, remote_tasks_cfg)) { sys_log(log, "[TASKCFGCHK][I]tcid = %s, maski = %s, maske = %s, srvipaddr = %s, srvport = %ld\n", TASKS_CFG_TCID_STR(remote_tasks_cfg), TASKS_CFG_MASKI_STR(remote_tasks_cfg), TASKS_CFG_MASKE_STR(remote_tasks_cfg), TASKS_CFG_SRVIPADDR_STR(remote_tasks_cfg), TASKS_CFG_SRVPORT(remote_tasks_cfg)); } if(EC_TRUE == tasks_cfg_is_externet(local_tasks_cfg, remote_tasks_cfg)) { sys_log(log, "[TASKCFGCHK][E]tcid = %s, maski = %s, maske = %s, srvipaddr = %s, srvport = %ld\n", TASKS_CFG_TCID_STR(remote_tasks_cfg), TASKS_CFG_MASKI_STR(remote_tasks_cfg), TASKS_CFG_MASKE_STR(remote_tasks_cfg), TASKS_CFG_SRVIPADDR_STR(remote_tasks_cfg), TASKS_CFG_SRVPORT(remote_tasks_cfg)); } if(EC_TRUE == tasks_cfg_is_lannet(local_tasks_cfg, remote_tasks_cfg)) { sys_log(log, "[TASKCFGCHK][L]tcid = %s, maski = %s, maske = %s, srvipaddr = %s, srvport = %ld\n", TASKS_CFG_TCID_STR(remote_tasks_cfg), TASKS_CFG_MASKI_STR(remote_tasks_cfg), TASKS_CFG_MASKE_STR(remote_tasks_cfg), TASKS_CFG_SRVIPADDR_STR(remote_tasks_cfg), TASKS_CFG_SRVPORT(remote_tasks_cfg)); } if(EC_TRUE == tasks_cfg_is_dbgnet(local_tasks_cfg, remote_tasks_cfg)) { sys_log(log, "[TASKCFGCHK][D]tcid = %s, maski = %s, maske = %s, srvipaddr = %s, srvport = %ld\n", TASKS_CFG_TCID_STR(remote_tasks_cfg), TASKS_CFG_MASKI_STR(remote_tasks_cfg), TASKS_CFG_MASKE_STR(remote_tasks_cfg), TASKS_CFG_SRVIPADDR_STR(remote_tasks_cfg), TASKS_CFG_SRVPORT(remote_tasks_cfg)); } if(EC_TRUE == tasks_cfg_is_monnet(local_tasks_cfg, remote_tasks_cfg)) { sys_log(log, "[TASKCFGCHK][D]tcid = %s, maski = %s, maske = %s, srvipaddr = %s, srvport = %ld\n", TASKS_CFG_TCID_STR(remote_tasks_cfg), TASKS_CFG_MASKI_STR(remote_tasks_cfg), TASKS_CFG_MASKE_STR(remote_tasks_cfg), TASKS_CFG_SRVIPADDR_STR(remote_tasks_cfg), TASKS_CFG_SRVPORT(remote_tasks_cfg)); } } CVECTOR_UNLOCK(TASK_CFG_TASKS_CFG_VEC(task_cfg), LOC_TASKCFGCHK_0002); return (EC_TRUE); }
/** * @brief runs the labeled test files to determine accuracy * * This function will open each pair of files in the testdata directory to * analyze how accurate the copyright agent is. This function will respond with * the number of false negatives, false positives, and correct answers for each * file and total tally of these numbers. This will also produce 3 files, one * containing all matches that the copyright agent found, all the things that it * didn't find, and all of the false positives. */ void run_test_files(copyright copy) { /* locals */ cvector compare; copyright_iterator iter; cvector_iterator curr; FILE* istr, * m_out, * n_out, * p_out; char buffer[READMAX + 1]; char file_name[FILENAME_MAX]; char copy_buf[FILENAME_MAX]; char name_buf[FILENAME_MAX]; char* first, * last, * loc, tmp; int i, matches, correct = 0, falsep = 0, falsen = 0; /* grab the copyright files */ memset(copy_buf, '\0', sizeof(copy_buf)); memset(name_buf, '\0', sizeof(copy_buf)); snprintf(copy_buf, sizeof(copy_buf), "%s/mods-enabled/copyright/agent/copyright.dic", sysconfigdir); snprintf(name_buf, sizeof(name_buf), "%s/mods-enabled/copyright/agent/names.dic", sysconfigdir); /* create data structures */ copyright_init(©, copy_buf, name_buf); cvector_init(&compare, string_function_registry()); /* open the logging files */ m_out = fopen("Matches", "w"); n_out = fopen("False_Negatives", "w"); p_out = fopen("False_Positives", "w"); /* big problem if any of the log files didn't open correctly */ if(!m_out || !n_out || !p_out) { fprintf(cerr, "ERROR did not successfully open one of the log files\n"); fprintf(cerr, "ERROR the files that needed to be opened were:\n"); fprintf(cerr, "ERROR Matches, False_Positives, False_Negatives\n"); exit(-1); } /* loop over every file in the test directory */ for(i = 0; i < TESTFILE_NUMBER; i++) { sprintf(file_name, "%s%d_raw", test_dir, i); /* attempt to open the labeled test file */ istr = fopen(file_name, "r"); if(!istr) { fprintf(cerr, "ERROR Must run testing from correct directory. The\n"); fprintf(cerr, "ERROR correct directory is installation dependent but\n"); fprintf(cerr, "ERROR the working directory should include the folder:\n"); fprintf(cerr, "ERROR %s\n", test_dir); exit(-1); } /* initialize the buffer and read in any information */ memset(buffer, '\0', sizeof(buffer)); buffer[fread(buffer, sizeof(char), READMAX, istr)] = '\0'; matches = 0; /* set everything in the buffer to lower case */ for(first = buffer; *first; first++) { *first = tolower(*first); } /* loop through and find all <s>...</s> tags */ loc = buffer; while((first = strstr(loc, "<s>")) != NULL) { last = strstr(loc, "</s>"); if(last == NULL) { fprintf(cerr, "ERROR unmatched \"<s>\"\n"); fprintf(cerr, "ERROR in file: \"%s\"\n", file_name); exit(-1); } if(last <= first) { fprintf(cerr, "ERROR unmatched \"</s>\"\n"); fprintf(cerr, "ERROR in file: \"%s\"\n", file_name); exit(-1); } tmp = *last; *last = 0; cvector_push_back(compare, first + 3); *last = tmp; loc = last + 4; } /* close the previous file and open the corresponding raw data */ fclose(istr); file_name[strlen(file_name) - 4] = '\0'; istr = fopen(file_name, "r"); if(!istr) { fprintf(cerr, "ERROR Unmatched file in the test directory"); fprintf(cerr, "ERROR File with no match: \"%s\"_raw\n", file_name); fprintf(cerr, "ERROR File that caused error: \"%s\"\n", file_name); } /* perform the analysis on the current file */ copyright_analyze(copy, istr, REPORTALL); fclose(istr); /* loop over every match that the copyright object found */ for(iter = copyright_begin(copy); iter != copyright_end(copy); iter++) { cvector_iterator best = cvector_begin(compare); char score[2048]; char dst[2048]; memset(dst, '\0', sizeof(dst)); memset(score, '\0', sizeof(score)); /* log the coyright entry */ fprintf(m_out, "====%s================================\n", file_name); fprintf(m_out, "DICT: %s\tNAME: %s\n",copy_entry_dict(*iter), copy_entry_name(*iter)); fprintf(m_out, "TEXT[%s]\n",copy_entry_text(*iter)); /* loop over the vector looking for matches */ for(curr = cvector_begin(compare); curr != cvector_end(compare); curr++) { if(longest_common(dst, copy_entry_text(*iter), (char*)*curr) > strlen(score)) { strcpy(score, dst); best = curr; } } /* log the entry as found if it matched something in compare */ if(cvector_size(compare) != 0 && (strcmp(copy_entry_dict(*iter), "by") || strlen(score) > THRESHOLD)) { cvector_remove(compare, best); matches++; } else if(!strcmp(copy_entry_dict(*iter), "email") || !strcmp(copy_entry_dict(*iter), "url")) { matches++; } else { fprintf(p_out, "====%s================================\n", file_name); fprintf(p_out, "DICT: %s\tNAME: %s\n",copy_entry_dict(*iter), copy_entry_name(*iter)); fprintf(p_out, "TEXT[%s]\n",copy_entry_text(*iter)); } } /* log all the false negatives */ for(curr = cvector_begin(compare); curr != cvector_end(compare); curr++) { fprintf(n_out, "====%s================================\n", file_name); fprintf(n_out, "%s\n", (char*)*curr); } fprintf(cout, "====%s================================\n", file_name); fprintf(cout, "Correct: %d\n", matches); fprintf(cout, "False Positives: %d\n", copyright_size(copy) - matches); fprintf(cout, "False Negatives: %d\n", cvector_size(compare)); /* clean up for the next file */ correct += matches; falsep += copyright_size(copy) - matches; falsen += cvector_size(compare); cvector_clear(compare); } fprintf(cout, "==== Totals ================================\n"); fprintf(cout, "Total Found: %d\n", correct + falsep); fprintf(cout, "Correct: %d\n", correct); fprintf(cout, "False Positives: %d\n", falsep); fprintf(cout, "False Negatives: %d\n", falsen); fclose(m_out); fclose(n_out); fclose(p_out); copyright_destroy(copy); cvector_destroy(compare); }
static EC_BOOL taskcfgchk_route_test(LOG *log, const TASK_CFG *task_cfg, TASKS_CFG *src_tasks_cfg, const UINT32 des_tcid, const UINT32 max_hops) { UINT32 pos; if(EC_TRUE == taskcfgchk_conn_test(task_cfg, src_tasks_cfg, des_tcid)) { sys_log(log, "[TASKCFGCHK] %s ==> %s [SUCC]\n", TASKS_CFG_TCID_STR(src_tasks_cfg), c_word_to_ipv4(des_tcid)); return (EC_TRUE); } if(0 == max_hops) { sys_log(log, "[TASKCFGCHK] ==> %s [STOP]\n", TASKS_CFG_TCID_STR(src_tasks_cfg)); return (EC_FALSE); } CVECTOR_LOCK(TASKS_CFG_TASKR_CFG_VEC(src_tasks_cfg), LOC_TASKCFGCHK_0011); for(pos = 0; pos < cvector_size(TASKS_CFG_TASKR_CFG_VEC(src_tasks_cfg)); pos ++) { TASKR_CFG *taskr_cfg; UINT32 taskr_cfg_mask; taskr_cfg = (TASKR_CFG *)cvector_get_no_lock(TASKS_CFG_TASKR_CFG_VEC(src_tasks_cfg), pos); if(NULL_PTR == taskr_cfg) { continue; } taskr_cfg_mask = TASKR_CFG_MASKR(taskr_cfg); /*when des_tcid belong to the intranet of taskr_cfg, i.e., belong to the route*/ if((des_tcid & taskr_cfg_mask) == (TASKR_CFG_DES_TCID(taskr_cfg) & taskr_cfg_mask)) { TASKS_CFG *rt_tasks_cfg; dbg_log(SEC_0057_TASKCFGCHK, 5)(LOGSTDNULL, "[TASKCFGCHK] %s & %s == %s & %s\n", c_word_to_ipv4(des_tcid), c_word_to_ipv4(taskr_cfg_mask), TASKR_CFG_DES_TCID_STR(taskr_cfg), c_word_to_ipv4(taskr_cfg_mask) ); rt_tasks_cfg = task_cfg_searchs(task_cfg, TASKR_CFG_NEXT_TCID(taskr_cfg), CMPI_ANY_MASK, CMPI_ANY_MASK); if(NULL_PTR == rt_tasks_cfg) { continue; } sys_log(log, "[TASKCFGCHK] %s ==> %s\n", TASKS_CFG_TCID_STR(src_tasks_cfg), TASKR_CFG_NEXT_TCID_STR(taskr_cfg)); CVECTOR_UNLOCK(TASKS_CFG_TASKR_CFG_VEC(src_tasks_cfg), LOC_TASKCFGCHK_0012); if(EC_TRUE == taskcfgchk_route_test(log, task_cfg, rt_tasks_cfg, des_tcid, max_hops - 1))/*recursively*/ { return (EC_TRUE); } CVECTOR_LOCK(TASKS_CFG_TASKR_CFG_VEC(src_tasks_cfg), LOC_TASKCFGCHK_0013); } else { dbg_log(SEC_0057_TASKCFGCHK, 5)(LOGSTDNULL, "[TASKCFGCHK] %s & %s != %s & %s\n", c_word_to_ipv4(des_tcid), c_word_to_ipv4(taskr_cfg_mask), TASKR_CFG_DES_TCID_STR(taskr_cfg), c_word_to_ipv4(taskr_cfg_mask) ); } } CVECTOR_UNLOCK(TASKS_CFG_TASKR_CFG_VEC(src_tasks_cfg), LOC_TASKCFGCHK_0014); return (EC_FALSE); }
static EC_BOOL __chfsnp_mgr_load_db(CHFSNP_MGR *chfsnp_mgr, int chfsnp_mgr_fd) { UINT32 chfsnp_mgr_db_size; UINT8* chfsnp_mgr_db_buff; UINT32 chfsnp_mgr_db_offset; UINT32 chfsnp_home_dir_num; UINT32 chfsnp_home_dir_pos; uint32_t chfsnp_id; /*init offset*/ chfsnp_mgr_db_offset = 0; /*CHFSNP_MGR_NP_MODEL*/ chfsnp_mgr_db_size = sizeof(uint8_t); chfsnp_mgr_db_buff = (UINT8 *)&(CHFSNP_MGR_NP_MODEL(chfsnp_mgr)); if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load np model failed\n"); return (EC_FALSE); } /*CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID*/ chfsnp_mgr_db_size = sizeof(uint8_t); chfsnp_mgr_db_buff = (UINT8 *)&(CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID(chfsnp_mgr)); if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load 1st chash algo id failed\n"); return (EC_FALSE); } /*CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID*/ chfsnp_mgr_db_size = sizeof(uint8_t); chfsnp_mgr_db_buff = (UINT8 *)&(CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID(chfsnp_mgr)); if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load 2nd chash algo id failed\n"); return (EC_FALSE); } /*CHFSNP_MGR_NP_ITEM_MAX_NUM*/ chfsnp_mgr_db_size = sizeof(uint32_t); chfsnp_mgr_db_buff = (UINT8 *)&(CHFSNP_MGR_NP_ITEM_MAX_NUM(chfsnp_mgr)); if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load item max num failed\n"); return (EC_FALSE); } /*CHFSNP_MGR_NP_MAX_NUM*/ chfsnp_mgr_db_size = sizeof(uint32_t); chfsnp_mgr_db_buff = (UINT8 *)&(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr)); if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load disk max num failed\n"); return (EC_FALSE); } for(chfsnp_id = cvector_size(CHFSNP_MGR_NP_VEC(chfsnp_mgr)); chfsnp_id < CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr); chfsnp_id ++) { cvector_push_no_lock(CHFSNP_MGR_NP_VEC(chfsnp_mgr), NULL_PTR); } /*CHFSNP_MGR_NP_HOME_DIR_VEC*/ chfsnp_mgr_db_size = sizeof(UINT32); chfsnp_mgr_db_buff = (UINT8 *)&(chfsnp_home_dir_num); if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load home dir vec size failed\n"); return (EC_FALSE); } for(chfsnp_home_dir_pos = 0; chfsnp_home_dir_pos < chfsnp_home_dir_num; chfsnp_home_dir_pos ++) { CSTRING *chfsnp_home_dir_cstr; chfsnp_home_dir_cstr = cstring_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset); if(NULL_PTR == chfsnp_home_dir_cstr) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load home dir %u # failed\n", chfsnp_home_dir_pos); return (EC_FALSE); } if(EC_TRUE == cstring_is_empty(chfsnp_home_dir_cstr)) { cstring_free(chfsnp_home_dir_cstr); cvector_push_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), NULL_PTR); } else { cvector_push_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), (void *)chfsnp_home_dir_cstr); } } return (EC_TRUE); }
static EC_BOOL __chfsnp_mgr_flush_db(CHFSNP_MGR *chfsnp_mgr, int chfsnp_mgr_fd) { UINT32 chfsnp_mgr_db_size; UINT8* chfsnp_mgr_db_buff; UINT32 chfsnp_mgr_db_offset; UINT32 chfsnp_home_dir_num; UINT32 chfsnp_home_dir_pos; /*init offset*/ chfsnp_mgr_db_offset = 0; /*CHFSNP_MGR_NP_MODEL*/ chfsnp_mgr_db_size = sizeof(uint8_t); chfsnp_mgr_db_buff = (UINT8 *)&(CHFSNP_MGR_NP_MODEL(chfsnp_mgr)); if(EC_FALSE == c_file_flush(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_flush_db: flush np model failed"); return (EC_FALSE); } /*CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID*/ chfsnp_mgr_db_size = sizeof(uint8_t); chfsnp_mgr_db_buff = (UINT8 *)&(CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID(chfsnp_mgr)); if(EC_FALSE == c_file_flush(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_flush_db: flush 1st chash algo id failed"); return (EC_FALSE); } /*CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID*/ chfsnp_mgr_db_size = sizeof(uint8_t); chfsnp_mgr_db_buff = (UINT8 *)&(CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID(chfsnp_mgr)); if(EC_FALSE == c_file_flush(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_flush_db: flush 2nd chash algo id failed"); return (EC_FALSE); } /*CHFSNP_MGR_NP_ITEM_MAX_NUM*/ chfsnp_mgr_db_size = sizeof(uint32_t); chfsnp_mgr_db_buff = (UINT8 *)&(CHFSNP_MGR_NP_ITEM_MAX_NUM(chfsnp_mgr)); if(EC_FALSE == c_file_flush(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_flush_db: flush item max num failed"); return (EC_FALSE); } /*CHFSNP_MGR_NP_MAX_NUM*/ chfsnp_mgr_db_size = sizeof(uint32_t); chfsnp_mgr_db_buff = (UINT8 *)&(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr)); if(EC_FALSE == c_file_flush(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_flush_db: flush disk max num failed"); return (EC_FALSE); } /*CHFSNP_MGR_NP_HOME_DIR_VEC*/ chfsnp_home_dir_num = cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr)); chfsnp_mgr_db_size = sizeof(UINT32); chfsnp_mgr_db_buff = (UINT8 *)&(chfsnp_home_dir_num); if(EC_FALSE == c_file_flush(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_flush_db: flush home dir vec size failed"); return (EC_FALSE); } sys_log(LOGSTDOUT, "[DEBUG] __chfsnp_mgr_flush_db: np max num = %u\n", CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr)); sys_log(LOGSTDOUT, "[DEBUG] __chfsnp_mgr_flush_db: np home dir vec size = %u\n", cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr))); for(chfsnp_home_dir_pos = 0; chfsnp_home_dir_pos < chfsnp_home_dir_num; chfsnp_home_dir_pos ++) { CSTRING *chfsnp_home_dir_cstr; chfsnp_home_dir_cstr = cvector_get_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), chfsnp_home_dir_pos); if(EC_FALSE == cstring_flush(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_home_dir_cstr)) { sys_log(LOGSTDOUT, "error:__chfsnp_mgr_flush_db: flush home dir %u # failed\n", chfsnp_home_dir_pos); return (EC_FALSE); } } return (EC_TRUE); }
UINT32 crouter_node_count_next_hop(const CROUTER_NODE *crouter_node) { return cvector_size(CROUTER_NODE_NEXT_HOPS(crouter_node)); }