diff --git a/common/include/kni_utils.h b/common/include/kni_utils.h index 90cd726..d5749ab 100644 --- a/common/include/kni_utils.h +++ b/common/include/kni_utils.h @@ -71,7 +71,6 @@ struct kni_tcpopt_info{ #define KNI_FS_COLUMN_MAX 256 #define KNI_FS_LINE_MAX 256 enum kni_field{ - KNI_FIELD_INTCP_STM, KNI_FIELD_BYP_STM, KNI_FIELD_BYP_STM_POLICY, KNI_FIELD_BYP_STM_PME_NEW_FAIL, @@ -113,9 +112,7 @@ enum kni_field{ KNI_FIELD_TUPLE2STM_DEL_SUCC, KNI_FIELD_TUPLE2STM_DEL_FAIL, KNI_FIELD_KNI_INTCP_BYTES, - KNI_FIELD_TFE_INTCP_BYTES, KNI_FIELD_KNI_INTCP_STM, - KNI_FIELD_TFE_INTCP_STM, KNI_FIELD_TUPLE2STM_SEARCH_SUCC, KNI_FIELD_TUPLE2STM_SEARCH_FAIL, KNI_FIELD_SAPP_INJECT_SUCC, @@ -124,6 +121,8 @@ enum kni_field{ KNI_FIELD_BLOOM_SEARCH_FAIL, KNI_FIELD_BLOOM_ADD_SUCC, KNI_FIELD_BLOOM_ADD_FAIL, + KNI_FIELD_BLOOM_HIT, + KNI_FIELD_BLOOM_MISS, //KNI_FIELD_TFE_STATUS_BASE must be last KNI_FIELD_TFE_STATUS_BASE, }; diff --git a/conf/kni.conf b/conf/kni.conf index 51324ca..f513484 100644 --- a/conf/kni.conf +++ b/conf/kni.conf @@ -1,36 +1,36 @@ [global] log_path = ./log/kni/kni.log log_level = 10 -tfe_node_count = 3 -manage_eth = enp7s0 +tfe_node_count = 1 +manage_eth = eth0 #normal or tun -deploy_mode = tun +deploy_mode = normal tun_name = tun_kni src_mac_addr = 00:0e:c6:d6:72:c1 dst_mac_addr = fe:65:b7:03:50:bd [tfe0] enabled = 1 -dev_eth_symbol = ens1f5 +dev_eth_symbol = eth7 ip_addr = 192.168.100.2 [tfe1] enabled = 1 -dev_eth_symbol = ens1f6 +dev_eth_symbol = eth8 ip_addr = 192.168.100.3 [tfe2] enabled = 1 -dev_eth_symbol = ens1f7 +dev_eth_symbol = eth9 ip_addr = 192.168.100.4 [tfe_cmsg_receiver] -listen_eth = ens1.100 +listen_eth = eth2.100 listen_port = 2475 [watch_dog] switch = 1 -listen_eth = ens1.100 +listen_eth = eth2.100 listen_port = 2476 keepalive_idle = 2 keepalive_intvl = 1 @@ -88,4 +88,7 @@ mho_hash_slot_size = 160000 mho_hash_max_element_num = 640000 [field_stat] -stat_path = ./fs2_kni.status \ No newline at end of file +remote_switch = 1 +remote_ip = 192.168.10.152 +remote_port = 8125 +local_path = ./fs2_kni.status \ No newline at end of file diff --git a/entry/src/kni_entry.cpp b/entry/src/kni_entry.cpp index cc3d135..c850601 100644 --- a/entry/src/kni_entry.cpp +++ b/entry/src/kni_entry.cpp @@ -21,7 +21,13 @@ bypass: drome: pme_new_fail: destroy_pme #include "kni_send_logger.h" #include #include "tfe_mgr.h" -#include "dablooms.h" +#ifdef __cplusplus +extern "C" { +#endif + #include "dablooms.h" +#ifdef __cplusplus +} +#endif #include "kni_tun.h" struct kni_handle *g_kni_handle = NULL; @@ -280,6 +286,12 @@ static void pme_info_destroy(void *data){ } static struct pme_info* pme_info_new(const struct streaminfo *stream, int thread_seq){ + if(stream->addr.addrtype == ADDR_TYPE_IPV6){ + FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_IPV6_STM], 0, FS_OP_ADD, 1); + } + else{ + FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_IPV4_STM], 0, FS_OP_ADD, 1); + } void *logger = g_kni_handle->local_logger; struct pme_info* pmeinfo = ALLOC(struct pme_info, 1); pmeinfo->addr_type = (enum addr_type_t)stream->addr.addrtype; @@ -455,15 +467,6 @@ static void stream_destroy(struct pme_info *pmeinfo, int do_log){ KNI_LOG_DEBUG(logger, "Succeed at log_generate, stream traceid = %s", pmeinfo->stream_traceid); } } - //intercept traffic stat - FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_KNI_INTCP_BYTES], 0, FS_OP_ADD, - pmeinfo->server_bytes + pmeinfo->client_bytes); - FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_KNI_INTCP_STM], 0, FS_OP_ADD, 1); - if(pmeinfo->intercept_state == 1){ - FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_TFE_INTCP_BYTES], 0, FS_OP_ADD, - pmeinfo->server_bytes + pmeinfo->client_bytes); - FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_TFE_INTCP_STM], 0, FS_OP_ADD, 1); - } //free pme pme_info_destroy(pmeinfo); } @@ -723,6 +726,8 @@ static int send_to_tfe_normal_mode(char *raw_data, uint16_t raw_len, int thread_ } static int send_to_tfe_tun_mode(char *raw_data, uint16_t raw_len, addr_type_t addr_type){ + //intercept traffic stat + FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_KNI_INTCP_BYTES], 0, FS_OP_ADD, raw_len); struct kni_tun_handle *handle = g_kni_handle->tun_handle; char *dst_data = ALLOC(char, KNI_MTU); add_ether_header(dst_data, raw_data, raw_len, addr_type); @@ -1028,9 +1033,9 @@ static int first_data_intercept(struct streaminfo *stream, struct pme_info *pmei } else{ KNI_LOG_DEBUG(logger, "Succeed at send first packet to tfe%d, stream traceid = %s", pmeinfo->tfe_id, pmeinfo->stream_traceid); + FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_KNI_INTCP_STM], 0, FS_OP_ADD, 1); } FREE(&buff); - FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_INTCP_STM], 0, FS_OP_ADD, 1); return APP_STATE_DROPPKT | APP_STATE_GIVEME; } @@ -1045,7 +1050,15 @@ static int dabloom_search(struct pkt_info *pktinfo, int thread_seq){ KNI_LOG_ERROR(logger, "Failed at expiry_dablooms_search, errmsg = %s", expiry_dablooms_errno_trans((enum expiry_dablooms_errno)ret)); FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BLOOM_SEARCH_FAIL], 0, FS_OP_ADD, 1); } - FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BLOOM_SEARCH_SUCC], 0, FS_OP_ADD, 1); + else{ + FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BLOOM_SEARCH_SUCC], 0, FS_OP_ADD, 1); + if(ret == 1){ + FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BLOOM_HIT], 0, FS_OP_ADD, 1); + } + else{ + FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BLOOM_MISS], 0, FS_OP_ADD, 1); + } + } uint64_t count = 0; expiry_dablooms_element_count_get(g_kni_handle->threads_handle[thread_seq].dabloom_handle, &count); FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->line_ids[0], g_kni_fs_handle->column_ids[thread_seq], FS_OP_SET, count); @@ -1287,12 +1300,6 @@ extern "C" char kni_tcpall_entry(struct streaminfo *stream, void** pme, int thre int ret; int can_destroy; struct pme_info *pmeinfo = *(struct pme_info **)pme; - if(stream->addr.addrtype == ADDR_TYPE_IPV6){ - FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_IPV6_STM], 0, FS_OP_ADD, 1); - } - else{ - FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_IPV4_STM], 0, FS_OP_ADD, 1); - } /* a_packet == NULL && not op_state_close, continue close: a_packet may be null, if a_packet = null, do not send to tfe @@ -1507,6 +1514,7 @@ extern "C" char kni_polling_all_entry(const struct streaminfo *stream, void** pm tuple2stream_htable_search(tuple2stream_htable, ether_hdr, thread_seq); flag = 1; } + marsio_buff_free(g_kni_handle->marsio_handle->instance, rx_buffs, nr_recv, 0, 0); } } //tun mode @@ -1774,26 +1782,43 @@ static void fs_destroy(struct kni_field_stat_handle *fs_handle){ static struct kni_field_stat_handle * fs_init(const char *profile){ void *logger = g_kni_handle->local_logger; const char *section = "field_stat"; - char stat_path[KNI_PATH_MAX]; + char local_path[KNI_PATH_MAX]; struct kni_field_stat_handle *fs_handle = NULL; screen_stat_handle_t handle = NULL; const char *app_name = "fs2_kni"; - int value = 0; - int ret = MESA_load_profile_string_nodef(profile, section, "stat_path", stat_path, sizeof(stat_path)); - if(ret < 0){ - KNI_LOG_ERROR(logger, "MESA_prof_load: stat_path not set, profile = %s, section = %s", profile, section); - goto error_out; - } - KNI_LOG_ERROR(logger, "MESA_prof_load, [%s]:\n stat_path: %s\n", "field_stat", stat_path); + int value = 0, ret; + int remote_switch = 0; + char remote_ip[INET_ADDRSTRLEN]; + int remote_port; + MESA_load_profile_int_def(profile, section, "remote_switch", &remote_switch, 0); + MESA_load_profile_string_def(profile, section, "local_path", local_path, sizeof(local_path), "./fs2_kni.status"); + KNI_LOG_ERROR(logger, "MESA_prof_load, [%s]:\n remote_switch: %d\n local_path: %s", section, remote_switch, local_path); handle = FS_create_handle(); if(handle == NULL){ KNI_LOG_ERROR(logger, "Failed at create FS_create_handle"); goto error_out; } + if(remote_switch == 1){ + ret = MESA_load_profile_string_nodef(profile, section, "remote_ip", remote_ip, sizeof(remote_ip)); + if(ret < 0){ + KNI_LOG_ERROR(logger, "MESA_prof_load: remote_ip not set, profile is %s, section is %s", profile, section); + goto error_out; + } + ret = MESA_load_profile_int_nodef(profile, section, "remote_port", &remote_port); + if(ret < 0){ + KNI_LOG_ERROR(logger, "MESA_prof_load: remote_port not set, profile is %s, section is %s", profile, section); + goto error_out; + } + KNI_LOG_ERROR(logger, "MESA_prof_load, [%s]:\n remote_ip: %s\n remote_port: %d", section, remote_ip, remote_port); + FS_set_para(handle, STATS_SERVER_IP, remote_ip, strlen(remote_ip)); + FS_set_para(handle, STATS_SERVER_PORT, &remote_port, sizeof(remote_port)); + value=FS_OUTPUT_STATSD; + FS_set_para(handle, STATS_FORMAT, &value, sizeof(value)); + } fs_handle = ALLOC(struct kni_field_stat_handle, 1); fs_handle->handle = handle; FS_set_para(handle, APP_NAME, app_name, strlen(app_name) + 1); - FS_set_para(handle, OUTPUT_DEVICE, stat_path, strlen(stat_path)+1); + FS_set_para(handle, OUTPUT_DEVICE, local_path, strlen(local_path)+1); value = 0; FS_set_para(handle, FLUSH_BY_DATE, &value, sizeof(value)); value = 1; @@ -1806,7 +1831,6 @@ static struct kni_field_stat_handle * fs_init(const char *profile){ FS_set_para(handle, MAX_STAT_FIELD_NUM, &value, sizeof(value)); fs_handle = ALLOC(struct kni_field_stat_handle, 1); fs_handle->handle = handle; - fs_handle->fields[KNI_FIELD_INTCP_STM] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "intcp_stm"); fs_handle->fields[KNI_FIELD_BYP_STM] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "byp_stm"); fs_handle->fields[KNI_FIELD_BYP_STM_POLICY] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "byp_policy"); fs_handle->fields[KNI_FIELD_BYP_STM_PME_NEW_FAIL] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "byp_pme_new_F"); @@ -1839,9 +1863,7 @@ static struct kni_field_stat_handle * fs_init(const char *profile){ fs_handle->fields[KNI_FIELD_PME_FREE] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "pme_free"); //intercept traffic stat fs_handle->fields[KNI_FIELD_KNI_INTCP_BYTES] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "kni_intcp_B"); - fs_handle->fields[KNI_FIELD_TFE_INTCP_BYTES] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "tfe_intcp_B"); fs_handle->fields[KNI_FIELD_KNI_INTCP_STM] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "kni_intcp_stm"); - fs_handle->fields[KNI_FIELD_TFE_INTCP_STM] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "tfe_intcp_stm"); //htable fs_handle->fields[KNI_FIELD_ID2PME_ADD_SUCC] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "id2pme_add_S"); fs_handle->fields[KNI_FIELD_ID2PME_ADD_FAIL] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "id2pme_add_F"); @@ -1856,6 +1878,8 @@ static struct kni_field_stat_handle * fs_init(const char *profile){ fs_handle->fields[KNI_FIELD_SAPP_INJECT_SUCC] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "sapp_inject_S"); fs_handle->fields[KNI_FIELD_SAPP_INJECT_FAIL] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "sapp_inject_F"); fs_handle->fields[KNI_FIELD_BLOOM_SEARCH_SUCC] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_srch_S"); + fs_handle->fields[KNI_FIELD_BLOOM_HIT] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_hit"); + fs_handle->fields[KNI_FIELD_BLOOM_MISS] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_miss"); fs_handle->fields[KNI_FIELD_BLOOM_SEARCH_FAIL] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_srch_F"); fs_handle->fields[KNI_FIELD_BLOOM_ADD_SUCC] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_add_S"); fs_handle->fields[KNI_FIELD_BLOOM_ADD_FAIL] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_add_F"); @@ -1872,10 +1896,10 @@ static struct kni_field_stat_handle * fs_init(const char *profile){ char buff[KNI_PATH_MAX]; for(int i = 0; i < fs_handle->column_cnt; i++){ snprintf(buff, sizeof(buff), "tid%d", i); - fs_handle->column_ids[i] = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_SPEED, buff); + fs_handle->column_ids[i] = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); } snprintf(buff, sizeof(buff), "bloom_cnt"); - fs_handle->line_ids[0] = FS_register(handle, FS_STYLE_LINE, FS_CALC_SPEED, buff); + fs_handle->line_ids[0] = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); fs_handle->handle = handle; FS_start(handle); @@ -1929,7 +1953,7 @@ int dup_traffic_dabloom_init(const char *profile, void *logger){ MESA_load_profile_string_def(profile, section, "error_rate", error_rate_str, sizeof(error_rate_str), "0.05"); MESA_load_profile_int_def(profile, section, "expiry_time", &expiry_time, 30); KNI_LOG_ERROR(logger, "MESA_prof_load, [%s]:\n action: %d\n capacity: %d\n error_rate: %s\n expiry_time: %d", - section, capacity, error_rate_str, expiry_time); + section, g_kni_handle->dup_traffic_action, capacity, error_rate_str, expiry_time); error_rate = atof(error_rate_str); for(int i = 0; i < g_kni_handle->thread_count; i++){ struct expiry_dablooms_handle* dabloom_handle = expiry_dablooms_init(capacity, error_rate, expiry_time);