Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch-contrib
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch-contrib
Commits
c1a3bce0
提交
c1a3bce0
authored
12月 11, 2012
作者:
Christopher Rienzo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add mod_simple_lcr to contrib
上级
657d5b14
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
2121 行增加
和
0 行删除
+2121
-0
Makefile.am
crienzo/mod_simple_lcr/Makefile.am
+9
-0
simple_lcr.conf.xml
.../mod_simple_lcr/conf/autoload_configs/simple_lcr.conf.xml
+21
-0
areas.csv
crienzo/mod_simple_lcr/conf/ratedecks/areas.csv
+292
-0
ratedeck1.csv
crienzo/mod_simple_lcr/conf/ratedecks/ratedeck1.csv
+10
-0
ratedeck2.csv
crienzo/mod_simple_lcr/conf/ratedecks/ratedeck2.csv
+10
-0
mod_simple_lcr.c
crienzo/mod_simple_lcr/mod_simple_lcr.c
+1080
-0
route_trie.c
crienzo/mod_simple_lcr/route_trie.c
+413
-0
route_trie.h
crienzo/mod_simple_lcr/route_trie.h
+170
-0
Makefile
crienzo/mod_simple_lcr/test/Makefile
+3
-0
test.c
crienzo/mod_simple_lcr/test/test.c
+113
-0
没有找到文件。
crienzo/mod_simple_lcr/Makefile.am
0 → 100644
浏览文件 @
c1a3bce0
include
$(top_srcdir)/build/modmake.rulesam
MODNAME
=
mod_simple_lcr
mod_LTLIBRARIES
=
mod_simple_lcr.la
mod_simple_lcr_la_SOURCES
=
mod_simple_lcr.c route_trie.c
mod_simple_lcr_la_CFLAGS
=
$(AM_CFLAGS)
mod_simple_lcr_la_LIBADD
=
$(switch_builddir)
/libfreeswitch.la
mod_simple_lcr_la_LDFLAGS
=
-avoid-version
-module
-no-undefined
-shared
crienzo/mod_simple_lcr/conf/autoload_configs/simple_lcr.conf.xml
0 → 100644
浏览文件 @
c1a3bce0
<configuration
name=
"simple_lcr.conf"
description=
"fast and simple in-memory LCR"
>
<settings>
<!-- number of routes to reply with on queries -->
<param
name=
"max-routes"
value=
"3"
/>
<!-- NPANXX to state mappings -->
<param
name=
"areas"
value=
"$${base_dir}/conf/ratedecks/areas.csv"
/>
<param
name=
"areas-cid-strip"
value=
"0"
/>
<param
name=
"areas-cid-prefix"
value=
""
/>
<param
name=
"areas-dest-strip"
value=
"0"
/>
<param
name=
"areas-dest-prefix"
value=
""
/>
</settings>
<!-- routes -->
<carrier
name=
"A"
ratedeck=
"$${base_dir}/conf/ratedecks/ratedeck1.csv"
>
<gateway
prefix=
"sip:"
suffix=
"@127.0.0.1"
/>
</carrier>
<carrier
name=
"B"
ratedeck=
"$${base_dir}/conf/ratedecks/ratedeck2.csv"
>
<gateway
prefix=
"sip:"
suffix=
"@127.0.0.2"
/>
</carrier>
</configuration>
crienzo/mod_simple_lcr/conf/ratedecks/areas.csv
0 → 100644
浏览文件 @
c1a3bce0
201,NJ
202,DC
203,CT
205,AL
206,WA
207,ME
208,ID
209,CA
210,TX
212,NY
213,CA
214,TX
215,PA
216,OH
217,IL
218,MN
219,IN
224,IL
225,LA
228,MS
229,GA
231,MI
234,OH
239,FL
240,MD
248,MI
251,AL
252,NC
253,WA
254,TX
256,AL
260,IN
262,WI
267,PA
269,MI
270,KY
276,VA
281,TX
289,ON
301,MD
302,DE
303,CO
304,WV
305,FL
307,WY
308,NE
309,IL
310,CA
312,IL
313,MI
314,MO
315,NY
316,KS
317,IN
318,LA
319,IA
320,MN
321,FL
323,CA
325,TX
330,OH
331,IL
334,AL
336,NC
337,LA
339,MA
340,VI
347,NY
351,MA
352,FL
360,WA
361,TX
386,FL
401,RI
402,NE
404,GA
405,OK
406,MT
407,FL
408,CA
409,TX
410,MD
412,PA
413,MA
414,WI
415,CA
417,MO
419,OH
423,TN
424,CA
425,WA
430,TX
432,TX
434,VA
435,UT
440,OH
443,MD
464,IL
469,TX
470,GA
475,CT
478,GA
479,AR
480,AZ
484,PA
501,AR
502,KY
503,OR
504,LA
505,NM
507,MN
508,MA
509,WA
510,CA
512,TX
513,OH
515,IA
516,NY
517,MI
518,NY
520,AZ
530,CA
540,VA
541,OR
551,NJ
559,CA
561,FL
562,CA
563,IA
567,OH
570,PA
571,VA
573,MO
574,IN
580,OK
585,NY
586,MI
601,MS
602,AZ
603,NH
605,SD
606,KY
607,NY
608,WI
609,NJ
610,PA
612,MN
614,OH
615,TN
616,MI
617,MA
618,IL
619,CA
620,KS
623,AZ
626,CA
630,IL
631,NY
636,MO
641,IA
646,NY
650,CA
651,MN
660,MO
661,CA
662,MS
670,MP
671,GU
678,GA
679,MI
682,TX
684,AS
701,ND
702,NV
703,VA
704,NC
706,GA
707,CA
708,IL
712,IA
713,TX
714,CA
715,WI
716,NY
717,PA
718,NY
719,CO
720,CO
724,PA
727,FL
731,TN
732,NJ
734,MI
740,OH
747,CA
754,FL
757,VA
760,CA
762,GA
763,MN
765,IN
769,MS
770,GA
772,FL
773,IL
774,MA
775,NV
779,IL
781,MA
785,KS
786,FL
787,PR
801,UT
802,VT
803,SC
804,VA
805,CA
806,TX
808,HI
810,MI
812,IN
813,FL
814,PA
815,IL
816,MO
817,TX
818,CA
819,QC
828,NC
830,TX
831,CA
832,TX
843,SC
845,NY
847,IL
848,NJ
850,FL
856,NJ
857,MA
858,CA
859,KY
860,CT
862,NJ
863,FL
864,SC
865,TN
870,AR
872,IL
878,PA
901,TN
903,TX
904,FL
905,ON
906,MI
907,AK
908,NJ
909,CA
910,NC
912,GA
913,KS
914,NY
915,TX
916,CA
917,NY
918,OK
919,NC
920,WI
925,CA
928,AZ
931,TN
936,TX
937,OH
939,PR
940,TX
941,FL
947,MI
949,CA
951,CA
952,MN
954,FL
956,TX
959,CT
970,CO
971,OR
972,TX
973,NJ
978,MA
979,TX
980,NC
985,LA
989,MI
575,NM
crienzo/mod_simple_lcr/conf/ratedecks/ratedeck1.csv
0 → 100644
浏览文件 @
c1a3bce0
1,0.0032,0.0031
2,0.0032,0.0031
3,0.0032,0.0031
4,0.0032,0.0031
5,0.0032,0.0031
6,0.0032,0.0031
7,0.0032,0.0031
8,0.0032,0.0031
9,0.0032,0.0031
0,0.0032,0.0031
crienzo/mod_simple_lcr/conf/ratedecks/ratedeck2.csv
0 → 100644
浏览文件 @
c1a3bce0
1,0.0042,0.0021
2,0.0042,0.0021
3,0.0042,0.0021
4,0.0042,0.0021
5,0.0042,0.0021
6,0.0042,0.0021
7,0.0042,0.0021
8,0.0042,0.0021
9,0.0042,0.0021
0,0.0042,0.0021
crienzo/mod_simple_lcr/mod_simple_lcr.c
0 → 100644
浏览文件 @
c1a3bce0
差异被折叠。
点击展开。
crienzo/mod_simple_lcr/route_trie.c
0 → 100644
浏览文件 @
c1a3bce0
差异被折叠。
点击展开。
crienzo/mod_simple_lcr/route_trie.h
0 → 100644
浏览文件 @
c1a3bce0
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthm@freeswitch.org>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Christopher M. Rienzo <chris@rienzo.com>
*
* Maintainer: Christopher M. Rienzo <chris@rienzo.com>
*
* route_trie.h -- prefix tree of routes ordered by least cost ascending.
*
*/
#ifndef ROUTE_TRIE_H
#define ROUTE_TRIE_H
#include <stdint.h>
struct
route_trie
;
struct
route_array
;
struct
route
;
typedef
uint16_t
route_value_t
;
typedef
uint8_t
route_type_t
;
typedef
uint16_t
route_cost_t
;
typedef
uint8_t
route_size_t
;
/**
* Get the route value
* @param route the route
* @return the value
*/
route_value_t
route_get_value
(
struct
route
*
route
);
/**
* Get the user-defined value
* @param route the route
* @return type the type of route
*/
route_type_t
route_get_type
(
struct
route
*
route
);
/**
* Get the route cost
* @param route the route
* @return the cost
*/
route_cost_t
route_get_cost
(
struct
route
*
route
);
/**
* Create an array to store lookup results
*
* @param max_size the maximum number of results to store
* @return the array
*/
struct
route_array
*
route_array_create
(
route_size_t
max_size
);
/**
* Add a route to the array preserving the order of cost, ascending. The highest
* cost route is removed from the array to make room for a lower cost route.
* @param array the array
* @param route the route to add
*/
void
route_array_add
(
struct
route_array
*
array
,
struct
route
*
route
);
/**
* Get the size of the array
* @param array the array
* @return the array size
*/
route_size_t
route_array_get_size
(
struct
route_array
*
array
);
/**
* Get a route from the array
* @param array the array
* @param index the route index
* @return the route or NULL if out of bounds
*/
struct
route
*
route_array_get_route
(
struct
route_array
*
array
,
route_size_t
index
);
/**
* Reset the array for a new query
* @param array
*/
void
route_array_reset
(
struct
route_array
*
array
);
/**
* Destroy the route array
* @param array the array
*/
void
route_array_destroy
(
struct
route_array
*
array
);
/**
* Search array for matching value
* @param value to match
* @return 1 if array contains value
*/
int
route_array_contains
(
struct
route_array
*
array
,
route_value_t
value
);
/**
* Create a new route_trie
* @param max_routes the maximum number of routes to store per node
* @return the trie
*/
struct
route_trie
*
route_trie_create
(
route_size_t
max_routes
);
/**
* Add a route to the trie
* @param trie the trie
* @param prefix the route prefix
* @param cost the route cost
* @param value the routing information
* @param type the type of route
* @return 1 if successful
*/
int
route_trie_add
(
struct
route_trie
*
trie
,
const
char
*
prefix
,
route_cost_t
cost
,
route_value_t
value
,
route_type_t
type
);
/**
* Search for least cost routes.
* @param trie the trie
* @param key the number to search
* @param array the array to fill with routes, ordered by cost ascending
* @return the number of routes found
*/
route_size_t
route_trie_find
(
struct
route_trie
*
trie
,
const
char
*
key
,
struct
route_array
*
array
);
/**
* Get count of routes
* @param trie the trie
* @param key the number to search
* @return the number of routes
*/
int
route_trie_find_count
(
struct
route_trie
*
trie
,
const
char
*
key
);
/**
* Destroy the trie
* @param trie the trie
*/
void
route_trie_destroy
(
struct
route_trie
*
trie
);
#endif
/* ROUTE_TRIE_H */
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
crienzo/mod_simple_lcr/test/Makefile
0 → 100644
浏览文件 @
c1a3bce0
all
:
gcc
-g
test.c
-I
.
-I
.. ../route_trie.c
-o
test
-lrt
crienzo/mod_simple_lcr/test/test.c
0 → 100644
浏览文件 @
c1a3bce0
/*
* test.c
*
* Christopher M. Rienzo <chris@rienzo.com>
*
* test application for route_trie
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "../route_trie.h"
void
test_lookups
()
{
char
*
search
[]
=
{
""
,
"0"
,
"00"
,
"000"
,
"0000"
,
"23"
,
"234"
,
"2345"
,
"23456"
,
"234567"
,
"2345678"
,
"111111111"
,
"222222222"
,
"333333333"
,
"444444444"
,
"555555555"
,
"666666666"
,
"777777777"
,
"888888888"
,
"99999999"
,
"0000000000"
,
"abcd"
,
"+12345"
,
"61723+"
,
"aasdgs"
,
"!@#$%^&*"
,
"+1234"
,
NULL
};
char
*
routes
[]
=
{
"null"
,
"P1"
,
"CV"
,
"IP"
,
"FR"
,
"FW"
,
"L3"
,
"GX"
,
"IC"
,
"ERROR"
};
char
*
types
[]
=
{
"intra"
,
"inter"
};
int
i
;
int
success
=
0
;
struct
route_array
*
results
=
route_array_create
(
3
);
struct
route_trie
*
trie
=
route_trie_create
(
3
);
success
+=
route_trie_add
(
trie
,
"781897"
,
0
.
001
f
*
10000
,
1
,
0
);
success
+=
route_trie_add
(
trie
,
"774266"
,
0
.
0005
f
*
10000
,
1
,
1
);
success
+=
route_trie_add
(
trie
,
"234567"
,
0
.
01
f
*
10000
,
2
,
0
);
success
+=
route_trie_add
(
trie
,
"234567"
,
0
.
09
f
*
10000
,
3
,
1
);
success
+=
route_trie_add
(
trie
,
"234567"
,
0
.
07
f
*
10000
,
4
,
0
);
success
+=
route_trie_add
(
trie
,
"234567"
,
0
.
02
f
*
10000
,
5
,
1
);
success
+=
route_trie_add
(
trie
,
"234567"
,
0
.
025
f
*
10000
,
6
,
0
);
success
+=
route_trie_add
(
trie
,
"23"
,
0
.
05
f
*
10000
,
7
,
1
);
success
+=
route_trie_add
(
trie
,
"234"
,
0
.
02
f
*
10000
,
8
,
0
);
success
+=
route_trie_add
(
trie
,
"1234+"
,
0
.
1
f
*
10000
,
9
,
0
);
success
+=
route_trie_add
(
trie
,
"+1234"
,
0
.
1
f
*
10000
,
9
,
0
);
success
+=
route_trie_add
(
trie
,
"asdvasvn3q8a-vw9"
,
0
.
1
f
*
10000
,
9
,
0
);
success
+=
route_trie_add
(
trie
,
"!@#$%^&*()m"
,
0
.
1
f
*
10000
,
9
,
0
);
if
(
success
>
9
)
{
printf
(
"Bad data inserted into trie!
\n
"
);
}
else
if
(
success
<
9
)
{
printf
(
"Not enough data inserted into trie!
\n
"
);
}
for
(
i
=
0
;
search
[
i
];
i
++
)
{
route_array_reset
(
results
);
route_size_t
num_routes
=
route_trie_find
(
trie
,
search
[
i
],
results
);
if
(
num_routes
)
{
int
j
;
for
(
j
=
0
;
j
<
num_routes
;
j
++
)
{
struct
route
*
route
=
route_array_get_route
(
results
,
j
);
printf
(
"%s, route %s: type = %s cost = %f
\n
"
,
search
[
i
],
routes
[
route_get_value
(
route
)],
types
[
route_get_type
(
route
)],
(
float
)
route_get_cost
(
route
)
/
10000
.
0
f
);
}
}
else
{
printf
(
"%s: NO MATCH
\n
"
,
search
[
i
]);
}
}
route_array_destroy
(
results
);
route_trie_destroy
(
trie
);
}
void
test_performance
()
{
int
i
,
z
;
struct
route_array
*
results
=
route_array_create
(
4
);
char
dialstring
[
11
]
=
{
0
};
char
*
routes
[]
=
{
"null"
,
"A"
,
"B"
,
"C"
,
"D"
,
"E"
};
struct
timespec
ts
,
te
;
struct
route_trie
*
trie
=
route_trie_create
(
5
);
printf
(
"building trie of 1 mil nodes...
\n
"
);
for
(
i
=
0
;
i
<=
999999
;
i
++
)
{
char
prefix
[
7
]
=
{
0
};
sprintf
(
prefix
,
"%06d"
,
i
);
route_trie_add
(
trie
,
prefix
,
0
.
01
f
*
10000
,
1
,
0
);
route_trie_add
(
trie
,
prefix
,
0
.
005
f
*
10000
,
2
,
0
);
route_trie_add
(
trie
,
prefix
,
0
.
003
f
*
10000
,
3
,
0
);
route_trie_add
(
trie
,
prefix
,
0
.
002
f
*
10000
,
4
,
0
);
route_trie_add
(
trie
,
prefix
,
0
.
015
f
*
10000
,
5
,
0
);
}
printf
(
"executing 30 million lookups...
\n
"
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
for
(
z
=
0
;
z
<=
30000000
;
z
++
)
{
char
prefix
[
7
]
=
{
0
};
sprintf
(
prefix
,
"%06d"
,
z
%
1000000
);
route_array_reset
(
results
);
route_trie_find
(
trie
,
dialstring
,
results
);
}
clock_gettime
(
CLOCK_MONOTONIC
,
&
te
);
printf
(
"destroying trie
\n
"
);
route_array_destroy
(
results
);
route_trie_destroy
(
trie
);
printf
(
"Start time = %lu sec
\n
"
,
ts
.
tv_sec
);
printf
(
"End time = %lu sec
\n
"
,
te
.
tv_sec
);
printf
(
"Lookups per sec = %d
\n
"
,
30000000
/
(
te
.
tv_sec
-
ts
.
tv_sec
));
printf
(
"Mean lookup time = %f nsec
\n
"
,
(
te
.
tv_sec
-
ts
.
tv_sec
)
/
(
30000000
*
1e-9
));
}
int
main
(
int
argc
,
char
**
argv
)
{
test_lookups
();
test_performance
();
return
0
;
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论