Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
579e3201
提交
579e3201
authored
12月 10, 2016
作者:
colm
提交者:
Mike Jerris
1月 25, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-9775: add tests for dht buckets
上级
86d295de
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
283 行增加
和
0 行删除
+283
-0
Makefile.am
libs/libks/test/Makefile.am
+5
-0
testbuckets.c
libs/libks/test/testbuckets.c
+278
-0
没有找到文件。
libs/libks/test/Makefile.am
浏览文件 @
579e3201
...
...
@@ -4,6 +4,11 @@ check_PROGRAMS =
EXTRA_DIST
=
tap.h
check_PROGRAMS
+=
testbuckets
testbuckets_SOURCES
=
testbuckets.c tap.c
testbuckets_CFLAGS
=
$(AM_CFLAGS)
testbuckets_LDADD
=
$(TEST_LDADD)
check_PROGRAMS
+=
testpools
testpools_SOURCES
=
testpools.c tap.c
testpools_CFLAGS
=
$(AM_CFLAGS)
...
...
libs/libks/test/testbuckets.c
0 → 100644
浏览文件 @
579e3201
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wunused-variable"
//#include "ks.h"
#include "../src/dht/ks_dht.h"
ks_dhtrt_routetable_t
*
rt
;
ks_pool_t
*
pool
;
int
doquery
(
ks_dhtrt_routetable_t
*
rt
,
uint8_t
*
id
,
enum
ks_dht_nodetype_t
type
,
enum
ipfamily
family
)
{
ks_dhtrt_querynodes_t
query
;
memset
(
&
query
,
0
,
sizeof
(
query
));
query
.
max
=
30
;
memcpy
(
&
query
.
nodeid
.
id
,
id
,
KS_DHT_NODEID_SIZE
);
query
.
family
=
family
;
query
.
type
=
type
;
return
ks_dhtrt_findclosest_nodes
(
rt
,
&
query
);
}
void
test01
()
{
printf
(
"testbuckets - test01 start
\n
"
);
fflush
(
stdout
);
ks_dhtrt_routetable_t
*
rt
;
ks_dhtrt_initroute
(
&
rt
,
pool
);
ks_dhtrt_deinitroute
(
&
rt
);
ks_dhtrt_initroute
(
&
rt
,
pool
);
ks_dht_nodeid_t
nodeid
,
homeid
;
memset
(
homeid
.
id
,
0xdd
,
KS_DHT_NODEID_SIZE
);
homeid
.
id
[
19
]
=
0
;
char
ip
[]
=
"192.168.100.100"
;
unsigned
short
port
=
7000
;
ks_dht_node_t
*
peer
;
ks_status_t
status
;
status
=
ks_dhtrt_create_node
(
rt
,
homeid
,
ks_dht_local_t
,
ip
,
port
,
&
peer
);
if
(
status
==
KS_STATUS_FAIL
)
{
printf
(
"*** ks_dhtrt_create_node test01 failed
\n
"
);
exit
(
101
);
}
peer
=
ks_dhtrt_find_node
(
rt
,
homeid
);
if
(
peer
==
0
)
{
printf
(
"*** ks_dhtrt_find_node test01 failed
\n
"
);
fflush
(
stdout
);
exit
(
102
);
}
status
=
ks_dhtrt_create_node
(
rt
,
homeid
,
ks_dht_local_t
,
ip
,
port
,
&
peer
);
if
(
status
!=
KS_STATUS_FAIL
)
{
printf
(
"*** ks_dhtrt_create_node test01 allowed duplicate!!
\n
"
);
exit
(
103
);
}
status
=
ks_dhtrt_delete_node
(
rt
,
peer
);
if
(
status
==
KS_STATUS_FAIL
)
{
printf
(
"*** ks_dhtrt_delete_node test01 failed
\n
"
);
exit
(
104
);
}
printf
(
"*** testbuckets - test01 complete
\n
"
);
fflush
(
stdout
);
}
void
test02
()
{
ks_dht_node_t
*
peer
;
ks_dht_nodeid_t
nodeid
;
memset
(
nodeid
.
id
,
0xef
,
KS_DHT_NODEID_SIZE
);
char
ipv6
[]
=
"1234:1234:1234:1234"
;
char
ipv4
[]
=
"123.123.123.123"
;
unsigned
short
port
=
7000
;
enum
ipfamily
both
=
ifboth
;
ks_status_t
status
;
nodeid
.
id
[
0
]
=
1
;
status
=
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_local_t
,
ipv6
,
port
,
&
peer
);
nodeid
.
id
[
0
]
=
2
;
status
=
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_remote_t
,
ipv6
,
port
,
&
peer
);
nodeid
.
id
[
0
]
=
3
;
status
=
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_remote_t
,
ipv6
,
port
,
&
peer
);
nodeid
.
id
[
0
]
=
4
;
status
=
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_local_t
,
ipv6
,
port
,
&
peer
);
nodeid
.
id
[
1
]
=
1
;
status
=
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_remote_t
,
ipv6
,
port
,
&
peer
);
nodeid
.
id
[
19
]
=
1
;
status
=
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_remote_t
,
ipv4
,
port
,
&
peer
);
nodeid
.
id
[
19
]
=
2
;
status
=
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_remote_t
,
ipv4
,
port
,
&
peer
);
nodeid
.
id
[
19
]
=
3
;
status
=
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_remote_t
,
ipv4
,
port
,
&
peer
);
nodeid
.
id
[
19
]
=
4
;
status
=
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_local_t
,
ipv4
,
port
,
&
peer
);
int
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_local_t
,
both
);
printf
(
"
\n
*** local query count expected 3, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_remote_t
,
both
);
printf
(
"
\n
*** remote query count expected 6, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_both_t
,
both
);
printf
(
"
\n
*** both query count expected 9, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_local_t
,
ifv4
);
printf
(
"
\n
*** local AF_INET query count expected 1, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_local_t
,
ifv6
);
printf
(
"
\n
*** local AF_INET6 query count expected 2, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_both_t
,
ifv6
);
printf
(
"
\n
*** AF_INET6 count expected 5, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_remote_t
,
ifv4
);
printf
(
"
\n
*** remote AF_INET query count expected 3, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_remote_t
,
ifv6
);
printf
(
"
\n
*** remote AF_INET6 query count expected 3, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_both_t
,
ifv4
);
printf
(
"
\n
*** AF_INET count expected 4, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
return
;
}
/* this is similar to test2 but after mutiple table splits. */
void
test03
()
{
ks_dht_node_t
*
peer
;
ks_dht_nodeid_t
nodeid
;
memset
(
nodeid
.
id
,
0xef
,
KS_DHT_NODEID_SIZE
);
char
ipv6
[]
=
"1234:1234:1234:1234"
;
char
ipv4
[]
=
"123.123.123.123"
;
unsigned
short
port
=
7000
;
enum
ipfamily
both
=
ifboth
;
ks_status_t
status
;
for
(
int
i
=
0
;
i
<
200
;
++
i
)
{
if
(
i
%
10
==
0
)
{
++
nodeid
.
id
[
0
];
}
else
{
++
nodeid
.
id
[
1
];
}
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_remote_t
,
ipv4
,
port
,
&
peer
);
}
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
if
(
i
%
10
==
0
)
{
++
nodeid
.
id
[
0
];
}
else
{
++
nodeid
.
id
[
1
];
}
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_local_t
,
ipv4
,
port
,
&
peer
);
}
for
(
int
i
=
0
;
i
<
201
;
++
i
)
{
if
(
i
%
10
==
0
)
{
++
nodeid
.
id
[
0
];
}
else
{
++
nodeid
.
id
[
1
];
}
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_remote_t
,
ipv6
,
port
,
&
peer
);
}
int
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_local_t
,
both
);
printf
(
"
\n
** local query count expected 3, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_remote_t
,
both
);
printf
(
"
\n
*** remote query count expected 6, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_both_t
,
both
);
printf
(
"
\n
*** both query count expected 9, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_local_t
,
ifv4
);
printf
(
"
\n
*** local AF_INET query count expected 1, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_local_t
,
ifv6
);
printf
(
"
\n
*** local AF_INET6 query count expected 2, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_both_t
,
ifv6
);
printf
(
"
\n
*** AF_INET6 count expected 5, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_remote_t
,
ifv4
);
printf
(
"
\n
** remote AF_INET query count expected 3, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_remote_t
,
ifv6
);
printf
(
"
\n
*** remote AF_INET6 query count expected 3, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_both_t
,
ifv4
);
printf
(
"
\n
*** AF_INET count expected 4, actual %d
\n
"
,
qcount
);
fflush
(
stdout
);
return
;
}
void
test04
()
{
ks_dht_node_t
*
peer
;
ks_dht_nodeid_t
nodeid
;
memset
(
nodeid
.
id
,
0xef
,
KS_DHT_NODEID_SIZE
);
char
ipv6
[]
=
"1234:1234:1234:1234"
;
char
ipv4
[]
=
"123.123.123.123"
;
unsigned
short
port
=
7000
;
enum
ipfamily
both
=
ifboth
;
ks_status_t
status
;
for
(
int
i
=
0
,
i2
=
0
;
i
<
10000
;
++
i
)
{
if
(
i
%
40
==
0
)
{
++
nodeid
.
id
[
0
];
if
(
i2
%
40
==
0
)
{
++
nodeid
.
id
[
1
];
}
else
{
++
nodeid
.
id
[
2
];
}
}
else
{
++
nodeid
.
id
[
1
];
}
ks_dhtrt_create_node
(
rt
,
nodeid
,
ks_dht_remote_t
,
ipv4
,
port
,
&
peer
);
}
memset
(
nodeid
.
id
,
0x2f
,
KS_DHT_NODEID_SIZE
);
ks_time_t
t0
=
ks_time_now
();
int
qcount
=
doquery
(
rt
,
nodeid
.
id
,
ks_dht_both_t
,
ifv4
);
ks_time_t
t1
=
ks_time_now
();
int
tx
=
t1
-
t0
;
t1
/=
1000
;
printf
(
"*** query on 10k nodes in %d ms
\n
"
,
tx
);
return
;
}
int
main
(
int
argx
,
char
*
argv
[])
{
printf
(
"testdhtbuckets - start
\n
"
);
ks_init
();
ks_status_t
status
;
char
*
str
=
NULL
;
int
bytes
=
1024
;
ks_dht_nodeid_t
homeid
;
ks_dht_nodeid_t
nodeid
,
nodeid1
,
nodeid2
;
ks_dht_node_t
*
peer
,
*
peer1
,
*
peer2
;
memset
(
homeid
.
id
,
0xde
,
KS_DHT_NODEID_SIZE
);
memset
(
nodeid
.
id
,
0xef
,
KS_DHT_NODEID_SIZE
);
ks_init
();
status
=
ks_pool_open
(
&
pool
);
printf
(
"init/deinit routeable
\n
"
);
fflush
(
stdout
);
ks_dhtrt_initroute
(
&
rt
,
pool
);
ks_dhtrt_deinitroute
(
&
rt
);
ks_dhtrt_initroute
(
&
rt
,
pool
);
test01
();
test02
();
test03
();
test04
();
return
0
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论