Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
3c81c293
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
3c81c293
编写于
10月 29, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
10月 29, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4044 from taosdata/hotfix/test
[TD-1824]
上级
18eb9e23
7d7cf7ac
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
221 addition
and
32 deletion
+221
-32
src/inc/taosmsg.h
src/inc/taosmsg.h
+4
-0
src/kit/shell/src/shellMain.c
src/kit/shell/src/shellMain.c
+4
-1
src/rpc/src/rpcMain.c
src/rpc/src/rpcMain.c
+7
-0
src/util/CMakeLists.txt
src/util/CMakeLists.txt
+1
-0
src/util/inc/tnettest.h
src/util/inc/tnettest.h
+21
-1
src/util/src/tnettest.c
src/util/src/tnettest.c
+184
-30
未找到文件。
src/inc/taosmsg.h
浏览文件 @
3c81c293
...
...
@@ -106,6 +106,10 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY12, "dummy12" )
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_DUMMY13
,
"dummy13"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_DUMMY14
,
"dummy14"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_NETWORK_TEST
,
"network-test"
)
#ifndef TAOS_MESSAGE_C
TSDB_MSG_TYPE_MAX
// 105
#endif
...
...
src/kit/shell/src/shellMain.c
浏览文件 @
3c81c293
...
...
@@ -80,7 +80,10 @@ int main(int argc, char* argv[]) {
shellParseArgument
(
argc
,
argv
,
&
args
);
if
(
args
.
netTestRole
&&
args
.
netTestRole
[
0
]
!=
0
)
{
taosNetTest
(
args
.
host
,
(
uint16_t
)
args
.
port
,
(
uint16_t
)
args
.
endPort
,
args
.
pktLen
,
args
.
netTestRole
);
taos_init
();
CmdArguments
cmdArgs
;
memcpy
(
&
cmdArgs
,
&
args
,
sizeof
(
SShellArguments
));
taosNetTest
(
&
cmdArgs
);
exit
(
0
);
}
...
...
src/rpc/src/rpcMain.c
浏览文件 @
3c81c293
...
...
@@ -1076,6 +1076,13 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) {
tDebug
(
"%s %p %p, %s is sent with error code:0x%x"
,
pRpc
->
label
,
pConn
,
(
void
*
)
pHead
->
ahandle
,
taosMsg
[
pHead
->
msgType
+
1
],
code
);
}
}
else
{
// msg is passed to app only parsing is ok
if
(
pHead
->
msgType
==
TSDB_MSG_TYPE_NETWORK_TEST
)
{
rpcSendQuickRsp
(
pConn
,
TSDB_CODE_SUCCESS
);
rpcFreeMsg
(
pRecv
->
msg
);
return
pConn
;
}
rpcProcessIncomingMsg
(
pConn
,
pHead
,
pContext
);
}
}
...
...
src/util/CMakeLists.txt
浏览文件 @
3c81c293
CMAKE_MINIMUM_REQUIRED
(
VERSION 2.8
)
PROJECT
(
TDengine
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/src/rpc/inc
)
AUX_SOURCE_DIRECTORY
(
src SRC
)
ADD_LIBRARY
(
tutil
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
tutil pthread osdetail lz4 z
)
...
...
src/util/inc/tnettest.h
浏览文件 @
3c81c293
...
...
@@ -20,7 +20,27 @@
extern
"C"
{
#endif
void
taosNetTest
(
const
char
*
host
,
uint16_t
port
,
uint16_t
endPort
,
int
pktLen
,
const
char
*
netTestRole
);
typedef
struct
CmdArguments
{
char
*
host
;
char
*
password
;
char
*
user
;
char
*
auth
;
char
*
database
;
char
*
timezone
;
bool
is_raw_time
;
bool
is_use_passwd
;
char
file
[
TSDB_FILENAME_LEN
];
char
dir
[
TSDB_FILENAME_LEN
];
int
threadNum
;
char
*
commands
;
int
abort
;
int
port
;
int
endPort
;
int
pktLen
;
char
*
netTestRole
;
}
CmdArguments
;
void
taosNetTest
(
CmdArguments
*
args
);
#ifdef __cplusplus
}
...
...
src/util/src/tnettest.c
浏览文件 @
3c81c293
...
...
@@ -15,11 +15,16 @@
#include "os.h"
#include "taosdef.h"
#include "taosmsg.h"
#include "taoserror.h"
#include "tulog.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tsocket.h"
#include "trpc.h"
#include "rpcHead.h"
#include "tutil.h"
#include "tnettest.h"
#define MAX_PKG_LEN (64*1000)
#define BUFFER_SIZE (MAX_PKG_LEN + 1024)
...
...
@@ -30,9 +35,15 @@ typedef struct {
uint16_t
pktLen
;
}
info_s
;
static
char
serverFqdn
[
TSDB_FQDN_LEN
];
extern
int
tsRpcMaxUdpSize
;
static
char
g_user
[
TSDB_USER_LEN
+
1
]
=
{
0
};
static
char
g_pass
[
TSDB_PASSWORD_LEN
+
1
]
=
{
0
};
static
char
g_serverFqdn
[
TSDB_FQDN_LEN
]
=
{
0
};
static
uint16_t
g_startPort
=
0
;
static
uint16_t
g_endPort
=
6042
;
static
uint32_t
g_pktLen
=
0
;
static
void
*
bindUdpPort
(
void
*
sarg
)
{
info_s
*
pinfo
=
(
info_s
*
)
sarg
;
...
...
@@ -321,19 +332,145 @@ static void checkPort(uint32_t hostIp, uint16_t startPort, uint16_t maxPort, uin
return
;
}
static
void
taosNetTestClient
(
const
char
*
serverFqdn
,
uint16_t
startPort
,
uint16_t
endPort
,
int
pktLen
)
{
uint32_t
serverIp
=
taosGetIpFromFqdn
(
serverFqdn
);
if
(
serverIp
==
0xFFFFFFFF
)
{
printf
(
"Failed to resolve FQDN:%s"
,
serverFqdn
);
exit
(
-
1
);
void
*
tnetInitRpc
(
char
*
secretEncrypt
,
char
spi
)
{
SRpcInit
rpcInit
;
void
*
pRpcConn
=
NULL
;
taosEncryptPass
((
uint8_t
*
)
g_pass
,
strlen
(
g_pass
),
secretEncrypt
);
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localPort
=
0
;
rpcInit
.
label
=
"NET-TEST"
;
rpcInit
.
numOfThreads
=
1
;
// every DB connection has only one thread
rpcInit
.
cfp
=
NULL
;
rpcInit
.
sessions
=
16
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
rpcInit
.
user
=
g_user
;
rpcInit
.
idleTime
=
2000
;
rpcInit
.
ckey
=
"key"
;
rpcInit
.
spi
=
spi
;
rpcInit
.
secret
=
secretEncrypt
;
pRpcConn
=
rpcOpen
(
&
rpcInit
);
return
pRpcConn
;
}
static
int
rpcCheckPortImpl
(
const
char
*
serverFqdn
,
uint16_t
port
,
uint16_t
pktLen
,
char
spi
)
{
SRpcEpSet
epSet
;
SRpcMsg
reqMsg
;
SRpcMsg
rspMsg
;
void
*
pRpcConn
;
char
secretEncrypt
[
32
]
=
{
0
};
pRpcConn
=
tnetInitRpc
(
secretEncrypt
,
spi
);
if
(
NULL
==
pRpcConn
)
{
return
-
1
;
}
checkPort
(
serverIp
,
startPort
,
endPort
,
pktLen
);
memset
(
&
epSet
,
0
,
sizeof
(
SRpcEpSet
));
epSet
.
inUse
=
0
;
epSet
.
numOfEps
=
1
;
epSet
.
port
[
0
]
=
port
;
strcpy
(
epSet
.
fqdn
[
0
],
serverFqdn
);
reqMsg
.
msgType
=
TSDB_MSG_TYPE_NETWORK_TEST
;
reqMsg
.
pCont
=
rpcMallocCont
(
pktLen
);
reqMsg
.
contLen
=
pktLen
;
reqMsg
.
code
=
0
;
reqMsg
.
handle
=
NULL
;
// rpc handle returned to app
reqMsg
.
ahandle
=
NULL
;
// app handle set by client
rpcSendRecv
(
pRpcConn
,
&
epSet
,
&
reqMsg
,
&
rspMsg
);
// handle response
if
((
rspMsg
.
code
!=
0
)
||
(
rspMsg
.
msgType
!=
TSDB_MSG_TYPE_NETWORK_TEST
+
1
))
{
//printf("code:%d[%s]\n", rspMsg.code, tstrerror(rspMsg.code));
return
-
1
;
}
rpcFreeCont
(
rspMsg
.
pCont
);
return
;
rpcClose
(
pRpcConn
);
return
0
;
}
static
void
rpcCheckPort
(
uint32_t
hostIp
)
{
int
ret
;
char
spi
;
for
(
uint16_t
port
=
g_startPort
;
port
<=
g_endPort
;
port
++
)
{
//printf("test: %s:%d\n", info.host, port);
printf
(
"
\n
"
);
//================ check tcp port ================
int32_t
pktLen
;
if
(
g_pktLen
<=
tsRpcMaxUdpSize
)
{
pktLen
=
tsRpcMaxUdpSize
+
1000
;
}
else
{
pktLen
=
g_pktLen
;
}
spi
=
1
;
ret
=
rpcCheckPortImpl
(
g_serverFqdn
,
port
,
pktLen
,
spi
);
if
(
ret
!=
0
)
{
spi
=
0
;
ret
=
rpcCheckPortImpl
(
g_serverFqdn
,
port
,
pktLen
,
spi
);
if
(
ret
!=
0
)
{
printf
(
"TCP port:%d test fail.
\t\t
"
,
port
);
}
else
{
//printf("tcp port:%d test ok.\t\t", port);
printf
(
"TCP port:
\033
[32m%d test OK
\033
[0m
\t\t
"
,
port
);
}
}
else
{
//printf("tcp port:%d test ok.\t\t", port);
printf
(
"TCP port:
\033
[32m%d test OK
\033
[0m
\t\t
"
,
port
);
}
//================ check udp port ================
if
(
g_pktLen
>=
tsRpcMaxUdpSize
)
{
pktLen
=
tsRpcMaxUdpSize
-
1000
;
}
else
{
pktLen
=
g_pktLen
;
}
spi
=
0
;
ret
=
rpcCheckPortImpl
(
g_serverFqdn
,
port
,
pktLen
,
spi
);
if
(
ret
!=
0
)
{
spi
=
1
;
ret
=
rpcCheckPortImpl
(
g_serverFqdn
,
port
,
pktLen
,
spi
);
if
(
ret
!=
0
)
{
printf
(
"udp port:%d test fail.
\t\n
"
,
port
);
}
else
{
//printf("udp port:%d test ok.\t\n", port);
printf
(
"UDP port:
\033
[32m%d test OK
\033
[0m
\t\n
"
,
port
);
}
}
else
{
//printf("udp port:%d test ok.\t\n", port);
printf
(
"UDP port:
\033
[32m%d test OK
\033
[0m
\t\n
"
,
port
);
}
}
printf
(
"
\n
"
);
return
;
}
static
void
taosNetTestClient
(
int
flag
)
{
uint32_t
serverIp
=
taosGetIpFromFqdn
(
g_serverFqdn
);
if
(
serverIp
==
0xFFFFFFFF
)
{
printf
(
"Failed to resolve FQDN:%s"
,
g_serverFqdn
);
exit
(
-
1
);
}
if
(
0
==
flag
)
{
checkPort
(
serverIp
,
g_startPort
,
g_endPort
,
g_pktLen
);
}
else
{
rpcCheckPort
(
serverIp
);
}
return
;
}
static
void
taosNetTestServer
(
uint16_t
startPort
,
uint16_t
endPort
,
int
pktLen
)
{
...
...
@@ -375,49 +512,66 @@ static void taosNetTestServer(uint16_t startPort, uint16_t endPort, int pktLen)
}
void
taosNetTest
(
const
char
*
host
,
uint16_t
port
,
uint16_t
endPort
,
int
pktLen
,
const
char
*
netTestRole
)
{
if
(
pktLen
>
MAX_PKG_LEN
)
{
printf
(
"test packet len overflow: %d, max len not greater than %d bytes
\n
"
,
pktLen
,
MAX_PKG_LEN
);
exit
(
-
1
);
void
taosNetTest
(
CmdArguments
*
args
)
{
if
(
0
==
args
->
pktLen
)
{
g_pktLen
=
1000
;
}
else
{
g_pktLen
=
args
->
pktLen
;
}
if
(
port
&&
endPort
)
{
if
(
port
>
endPort
)
{
printf
(
"endPort[%d] must not lesss port[%d]
\n
"
,
endPort
,
port
);
if
(
args
->
port
&&
args
->
endPort
)
{
if
(
args
->
port
>
args
->
endPort
)
{
printf
(
"endPort[%d] must not lesss port[%d]
\n
"
,
args
->
endPort
,
args
->
port
);
exit
(
-
1
);
}
}
if
(
host
&&
host
[
0
]
!=
0
)
{
if
(
strlen
(
host
)
>=
TSDB_EP_LEN
)
{
printf
(
"host invalid: %s
\n
"
,
host
);
if
(
args
->
host
&&
args
->
host
[
0
]
!=
0
)
{
if
(
strlen
(
args
->
host
)
>=
TSDB_EP_LEN
)
{
printf
(
"host invalid: %s
\n
"
,
args
->
host
);
exit
(
-
1
);
}
taosGetFqdnPortFromEp
(
host
,
serverFqdn
,
&
g_startPort
);
taosGetFqdnPortFromEp
(
args
->
host
,
g_
serverFqdn
,
&
g_startPort
);
}
else
{
tstrncpy
(
serverFqdn
,
"127.0.0.1"
,
TSDB_IPv4ADDR_LEN
);
tstrncpy
(
g_
serverFqdn
,
"127.0.0.1"
,
TSDB_IPv4ADDR_LEN
);
g_startPort
=
tsServerPort
;
}
if
(
port
)
{
g_startPort
=
port
;
if
(
args
->
port
)
{
g_startPort
=
args
->
port
;
}
if
(
endPort
)
{
g_endPort
=
endPort
;
if
(
args
->
endPort
)
{
g_endPort
=
args
->
endPort
;
}
if
(
port
>
endPort
)
{
if
(
g_startPort
>
g_
endPort
)
{
printf
(
"endPort[%d] must not lesss port[%d]
\n
"
,
g_endPort
,
g_startPort
);
exit
(
-
1
);
}
if
(
args
->
is_use_passwd
)
{
if
(
args
->
password
==
NULL
)
args
->
password
=
getpass
(
"Enter password: "
);
}
else
{
args
->
password
=
TSDB_DEFAULT_PASS
;
}
tstrncpy
(
g_pass
,
args
->
password
,
TSDB_PASSWORD_LEN
);
if
(
args
->
user
==
NULL
)
{
args
->
user
=
TSDB_DEFAULT_USER
;
}
tstrncpy
(
g_user
,
args
->
user
,
TSDB_USER_LEN
);
if
(
0
==
strcmp
(
"client"
,
netTestRole
))
{
printf
(
"host: %s
\t
start port: %d
\t
end port: %d
\t
packet len: %d
\n
"
,
serverFqdn
,
g_startPort
,
g_endPort
,
pktLen
);
taosNetTestClient
(
serverFqdn
,
g_startPort
,
g_endPort
,
pktLen
);
}
else
if
(
0
==
strcmp
(
"server"
,
netTestRole
))
{
taosNetTestServer
(
g_startPort
,
g_endPort
,
pktLen
);
if
(
0
==
strcmp
(
"client"
,
args
->
netTestRole
))
{
printf
(
"host: %s
\t
start port: %d
\t
end port: %d
\t
packet len: %d
\n
"
,
g_serverFqdn
,
g_startPort
,
g_endPort
,
g_pktLen
);
taosNetTestClient
(
0
);
}
else
if
(
0
==
strcmp
(
"clients"
,
args
->
netTestRole
))
{
printf
(
"host: %s
\t
start port: %d
\t
end port: %d
\t
packet len: %d
\n
"
,
g_serverFqdn
,
g_startPort
,
g_endPort
,
g_pktLen
);
taosNetTestClient
(
1
);
}
else
if
(
0
==
strcmp
(
"server"
,
args
->
netTestRole
))
{
taosNetTestServer
(
g_startPort
,
g_endPort
,
g_pktLen
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录