diff options
| author | luqiuwen <[email protected]> | 2018-12-17 17:21:11 +0600 |
|---|---|---|
| committer | luqiuwen <[email protected]> | 2018-12-28 16:47:18 +0600 |
| commit | da5478eeb4cbe64b8ac0fb71013aa7fb72f78506 (patch) | |
| tree | 1c42163814365c8e3d6bac66e767a0db643fb0ff | |
| parent | b29825b0b42c15d15e16e5f21b8d49ad8af661a5 (diff) | |
#3 增加链路层信息记录功能的开关,增补mrtunnat.conf默认配置文件模板。
| -rw-r--r-- | conf/mrtunnat.conf | 14 | ||||
| -rw-r--r-- | tunnat/include/tunnat.h | 68 | ||||
| -rw-r--r-- | tunnat/src/core.cc | 107 | ||||
| -rw-r--r-- | tunnat/src/monit.cc | 10 | ||||
| -rw-r--r-- | tunnat/src/runtime.cc | 17 |
5 files changed, 135 insertions, 81 deletions
diff --git a/conf/mrtunnat.conf b/conf/mrtunnat.conf index 21a053f..1f72613 100644 --- a/conf/mrtunnat.conf +++ b/conf/mrtunnat.conf @@ -1,5 +1,13 @@ [tunnat] -lcore_id=4,5,6,7,8 +lcore_id=54 appsym=tunnat -phydev=enp6s0f0,enp6s0f1 -virtdev=vxlan0,vxlan1,vxlan2 +phydev=eth3 +virtdev=vxlan_fwd +expire_time=60 +nr_max_sessions=2048 +link_info_nr_max_sessions=8192 +link_info_nr_slots=2048 +link_info_expire_time=180 +reverse_tunnel=0 +use_recent_tunnel=0 +use_link_info_table=0
\ No newline at end of file diff --git a/tunnat/include/tunnat.h b/tunnat/include/tunnat.h index 3d4d421..caf606b 100644 --- a/tunnat/include/tunnat.h +++ b/tunnat/include/tunnat.h @@ -22,30 +22,69 @@ extern uint8_t g_ctrlzone_id; struct TunnatThreadInstance; +#ifndef MR_TUNNAT_DEFAULT_CFG_FILE +#define MR_TUNNAT_DEFAULT_CFG_FILE "/etc/mrtunnat.conf" +#endif + +#ifndef MR_TUNNAT_DEFAULT_MNT_FILE +#define MR_TUNNAT_DEFAULT_MNT_FILE "/var/run/mrzcpd/mrmonit.tunnat" +#endif + +#ifndef MR_TUNNAT_DEFAULT_APPSYM +#define MR_TUNNAT_DEFAULT_APPSYM "tunnat" +#endif + +#ifndef MR_TUNNAT_LCORE_MAX +#define MR_TUNNAT_LCORE_MAX 128 +#endif + +#ifndef MR_TUNNAT_DEFAULT_SESSION_MAX +#define MR_TUNNAT_DEFAULT_SESSION_MAX 8192 +#endif + +#ifndef MR_TUNNAT_DEFAULT_SESSION_SLOT_MAX +#define MR_TUNNAT_DEFAULT_SESSION_SLOT_MAX 4096 +#endif + +#ifndef MR_TUNNAT_DEFAULT_NR_BURST +#define MR_TUNNAT_DEFAULT_NR_BURST 32 +#endif + +#ifndef MR_TUNNAT_DEFAULT_SESSION_EXPIRE_TIME +#define MR_TUNNAT_DEFAULT_SESSION_EXPIRE_TIME 0 +#endif + /* 全局句柄 */ struct TunnatInstance { /* 应用名称,用于注册MR4句柄 */ - std::string str_appsym; + std::string str_appsym{MR_TUNNAT_DEFAULT_APPSYM}; /* MR4应用句柄 */ - struct mr_instance * mr_instance; + struct mr_instance * mr_instance{nullptr}; /* 配置文件路径 */ - std::string cfgfile; + std::string cfgfile{MR_TUNNAT_DEFAULT_CFG_FILE}; /* 状态监测文件路径 */ - std::string mntfile; + std::string mntfile{MR_TUNNAT_DEFAULT_MNT_FILE}; /* 运行数据面线程数量 */ - unsigned int nr_thread; + unsigned int nr_thread{1}; /* Burst数量 */ - unsigned int nr_burst; + unsigned int nr_burst{MR_TUNNAT_DEFAULT_NR_BURST}; /* 运行数据面线程核心掩码 */ - cpu_mask_t coremask; + cpu_mask_t coremask{0}; + /* 会话表最大会话数 */ - unsigned int nr_max_sessions; + unsigned int sess_tb_nr_max_sessions{MR_TUNNAT_DEFAULT_SESSION_MAX}; /* 会话表槽数量 */ - unsigned int nr_slots; + unsigned int sess_tb_nr_slots{MR_TUNNAT_DEFAULT_SESSION_SLOT_MAX}; /* 会话表超时淘汰时间 */ - unsigned int expire_time; + unsigned int sess_tb_expire_time{MR_TUNNAT_DEFAULT_SESSION_EXPIRE_TIME}; + /* 链路信息表最大会话数 */ + unsigned int link_info_tb_nr_max_sessions{MR_TUNNAT_DEFAULT_SESSION_MAX}; + /* 链路信息表槽数量 */ + unsigned int link_info_tb_nr_slots{MR_TUNNAT_DEFAULT_SESSION_SLOT_MAX}; + /* 链路信息表超时淘汰时间 */ + unsigned int link_info_tb_expire_time{MR_TUNNAT_DEFAULT_SESSION_EXPIRE_TIME}; struct _devs { @@ -61,12 +100,15 @@ struct TunnatInstance /* 线程运行句柄 */ TunnatThreadInstance * thread_instances[MR_SID_MAX]; + /* 是否根据一个方向自动创建另一方向的Tunnel信息 */ - bool is_auto_reserve_tunnel; + bool is_auto_reserve_tunnel{true}; /* 是否向最近使用的隧道注入找不到隧道信息的包 */ - bool is_use_recent_tunnel; + bool is_use_recent_tunnel{true}; + /* 是否启用链路信息记录表 */ + bool is_use_link_info_table{false}; - TunnatInstance(); + TunnatInstance() = default; ~TunnatInstance() = default; }; diff --git a/tunnat/src/core.cc b/tunnat/src/core.cc index b0428c7..d980602 100644 --- a/tunnat/src/core.cc +++ b/tunnat/src/core.cc @@ -16,56 +16,12 @@ extern "C" #include <MESA_prof_load.h> } -#ifndef MR_TUNNAT_DEFAULT_CFG_FILE -#define MR_TUNNAT_DEFAULT_CFG_FILE "/etc/mrtunnat.conf" -#endif - -#ifndef MR_TUNNAT_DEFAULT_MNT_FILE -#define MR_TUNNAT_DEFAULT_MNT_FILE "/var/run/mrzcpd/mrmonit.tunnat" -#endif - -#ifndef MR_TUNNAT_DEFAULT_APPSYM -#define MR_TUNNAT_DEFAULT_APPSYM "tunnat" -#endif - -#ifndef MR_TUNNAT_LCORE_MAX -#define MR_TUNNAT_LCORE_MAX 128 -#endif - -#ifndef MR_TUNNAT_DEFAULT_SESSION_MAX -#define MR_TUNNAT_DEFAULT_SESSION_MAX 8192 -#endif - -#ifndef MR_TUNNAT_DEFAULT_SESSION_SLOT_MAX -#define MR_TUNNAT_DEFAULT_SESSION_SLOT_MAX 4096 -#endif - -#ifndef MR_TUNNAT_DEFAULT_NR_BURST -#define MR_TUNNAT_DEFAULT_NR_BURST 32 -#endif - -#ifndef MR_TUNNAT_DEFAULT_SESSION_EXPIRE_TIME -#define MR_TUNNAT_DEFAULT_SESSION_EXPIRE_TIME 0 -#endif - unsigned int g_logger_to_stdout = 1; unsigned int g_logger_level = LOG_DEBUG; unsigned int g_keep_running = 1; uint8_t g_ctrlzone_id = 0; __thread TunnatThreadStat * TunnatThreadStat::thread_stat_object_; - -TunnatInstance::TunnatInstance() : str_appsym(MR_TUNNAT_DEFAULT_APPSYM), - cfgfile(MR_TUNNAT_DEFAULT_CFG_FILE), - mntfile(MR_TUNNAT_DEFAULT_MNT_FILE), - nr_burst(MR_TUNNAT_DEFAULT_NR_BURST), - nr_max_sessions(MR_TUNNAT_DEFAULT_SESSION_MAX), - nr_slots(MR_TUNNAT_DEFAULT_SESSION_SLOT_MAX), - expire_time(MR_TUNNAT_DEFAULT_SESSION_EXPIRE_TIME) -{ - return; -} - struct TunnatInstance * g_instance = NULL; /* 字符串拆分,根据字符拆分字符串 */ @@ -166,18 +122,29 @@ int tunnat_session_setup(TunnatInstance * instance) { /* 最大会话数 */ MESA_load_profile_uint_def(instance->cfgfile.c_str(), "tunnat", "nr_max_sessions", - &instance->nr_max_sessions, instance->nr_max_sessions); + &instance->sess_tb_nr_max_sessions, instance->sess_tb_nr_max_sessions); /* Hash表槽数量 */ MESA_load_profile_uint_def(instance->cfgfile.c_str(), "tunnat", "nr_slots", - &instance->nr_slots, instance->nr_slots); + &instance->sess_tb_nr_slots, instance->sess_tb_nr_slots); /* Hash表超时时间 */ MESA_load_profile_uint_def(instance->cfgfile.c_str(), "tunnat", "expire_time", - &instance->expire_time, instance->expire_time); + &instance->sess_tb_expire_time, instance->sess_tb_expire_time); + + /* 链路信息表 */ + MESA_load_profile_uint_def(instance->cfgfile.c_str(), "tunnat", "link_info_nr_max_sessions", + &instance->link_info_tb_nr_max_sessions, instance->link_info_tb_nr_max_sessions); + + MESA_load_profile_uint_def(instance->cfgfile.c_str(), "tunnat", "link_info_nr_slots", + &instance->link_info_tb_nr_slots, instance->link_info_tb_nr_slots); + + MESA_load_profile_uint_def(instance->cfgfile.c_str(), "tunnat", "link_info_expire_time", + &instance->link_info_tb_expire_time, instance->link_info_tb_expire_time); unsigned int __auto_reserve_tunnel; unsigned int __is_use_recent_tunnel; + unsigned int __is_use_link_info_table; MESA_load_profile_uint_def(instance->cfgfile.c_str(), "tunnat", "reverse_tunnel", &__auto_reserve_tunnel, (unsigned int)instance->is_auto_reserve_tunnel); @@ -185,8 +152,31 @@ int tunnat_session_setup(TunnatInstance * instance) MESA_load_profile_uint_def(instance->cfgfile.c_str(), "tunnat", "use_recent_tunnel", &__is_use_recent_tunnel, (unsigned int)instance->is_use_recent_tunnel); + MESA_load_profile_uint_def(instance->cfgfile.c_str(), "tunnat", "use_link_info_table", + &__is_use_link_info_table, (unsigned int)instance->is_use_link_info_table); + instance->is_auto_reserve_tunnel = __auto_reserve_tunnel > 0; instance->is_use_recent_tunnel = __is_use_recent_tunnel > 0; + instance->is_use_link_info_table = __is_use_link_info_table > 0; + + MR_INFO("\nTunnat Runtime Parameters: "); + MR_INFO(" Auto reverse tunnel : %s", instance->is_auto_reserve_tunnel ? "Enable" : "Disable"); + MR_INFO(" Use recent tunnel : %s", instance->is_use_recent_tunnel ? "Enable" : "Disable"); + MR_INFO(" Record link info : %s", instance->is_use_link_info_table ? "Enable" : "Disable"); + + MR_INFO(" "); + + MR_INFO("Tunnat SessionTable & LinkInfo Parameters: "); + MR_INFO(" SessionTable Max Sessions : %u", instance->sess_tb_nr_max_sessions); + MR_INFO(" SessionTable Slots : %u", instance->sess_tb_nr_slots); + MR_INFO(" SessionTable ExpireTime : %u", instance->sess_tb_expire_time); + + if(instance->is_use_link_info_table) + { + MR_INFO(" LinkInfoTable Max Sessions : %u", instance->link_info_tb_nr_max_sessions); + MR_INFO(" LinkInfoTable Slots : %u", instance->link_info_tb_nr_slots); + MR_INFO(" LinkInfoTable ExpireTime : %u", instance->link_info_tb_expire_time); + } return RT_SUCCESS; } @@ -265,11 +255,10 @@ int tunnat_thread_setup(TunnatInstance * instance, TunnatThreadInstance * th_ins th_instance->instance = instance; th_instance->ss_table = new SessionTable; th_instance->th_stat = new TunnatThreadStat; - th_instance->link_info_table = new LinkInfoTable; th_instance->tun_container_array = new TunnelContainerArray[instance->nr_burst]; - int ret = th_instance->ss_table->Init(instance->nr_max_sessions, - instance->nr_slots, instance->expire_time); + int ret = th_instance->ss_table->Init(instance->sess_tb_nr_max_sessions, + instance->sess_tb_nr_slots, instance->sess_tb_expire_time); if (ret < 0) { @@ -278,14 +267,18 @@ int tunnat_thread_setup(TunnatInstance * instance, TunnatThreadInstance * th_ins return RT_ERR; } - ret = th_instance->link_info_table->Init(instance->nr_max_sessions, - instance->nr_slots, instance->expire_time); - - if (ret < 0) + if(instance->is_use_link_info_table) { - MR_ERROR("Create LinkInfo table failed for thread %d. ", thread_id); - delete th_instance->link_info_table; - return RT_ERR; + th_instance->link_info_table = new LinkInfoTable; + ret = th_instance->link_info_table->Init(instance->link_info_tb_nr_max_sessions, + instance->link_info_tb_nr_slots, instance->link_info_tb_expire_time); + + if (ret < 0) + { + MR_ERROR("Create LinkInfo table failed for thread %d. ", thread_id); + delete th_instance->link_info_table; + return RT_ERR; + } } return 0; diff --git a/tunnat/src/monit.cc b/tunnat/src/monit.cc index 644842b..d379f97 100644 --- a/tunnat/src/monit.cc +++ b/tunnat/src/monit.cc @@ -61,10 +61,14 @@ static cJSON * monit_runtime(TunnatInstance * instance) /* Link-Info */ cJSON * j_linkinfo = cJSON_CreateArray(); - for(unsigned int thread_id = 0; thread_id < instance->nr_thread; thread_id++) + + if(instance->is_use_link_info_table) { - LinkInfoTable * link_info_table = instance->thread_instances[thread_id]->link_info_table; - cJSON_AddItemToArray(j_linkinfo, link_info_table->DumpToJSON()); + for (unsigned int thread_id = 0; thread_id < instance->nr_thread; thread_id++) + { + LinkInfoTable * link_info_table = instance->thread_instances[thread_id]->link_info_table; + cJSON_AddItemToArray(j_linkinfo, link_info_table->DumpToJSON()); + } } cJSON_AddItemToObject(j_runtime, "accumulative", j_value); diff --git a/tunnat/src/runtime.cc b/tunnat/src/runtime.cc index 2dd51cd..0ccdb85 100644 --- a/tunnat/src/runtime.cc +++ b/tunnat/src/runtime.cc @@ -214,10 +214,14 @@ static void __phy_to_virt_one_device(TunnatInstance * instance, TunnatThreadInst if (ret >= 0) { + if(instance->is_use_link_info_table) + { + __phy_to_virt_link_info_check(instance, th_instance, mbufs[i], + tun_container_array[i]); + } + __phy_to_virt_session_check(instance, th_instance, mbufs[i], tun_container_array[i]); - __phy_to_virt_link_info_check(instance, th_instance, mbufs[i], - tun_container_array[i]); __phy_to_virt_pkt_modify(instance, th_instance, mbufs[i], tun_container_array[i]); @@ -506,10 +510,13 @@ static void __virt_to_phy_one_device(TunnatInstance * instance, TunnatThreadInst for (int i = 0; i < nr_mbufs; i++) { - if(__virt_to_phy_pkt_virtual_link_id(instance, th_instance, mbufs[i]) == RT_SUCCESS) + if(instance->is_use_link_info_table) { - virtual_link_id_bufs[nr_virtual_link_id_bufs++] = mbufs[i]; - continue; + if (__virt_to_phy_pkt_virtual_link_id(instance, th_instance, mbufs[i]) == RT_SUCCESS) + { + virtual_link_id_bufs[nr_virtual_link_id_bufs++] = mbufs[i]; + continue; + } } if (__virt_to_phy_pkt_no_session(instance, th_instance, mbufs[i]) == RT_SUCCESS) |
