安装
-
从github克隆freeDiameter源码
git clone https://github.com/freeDiameter/freeDiameter.git
-
安装所需环境
阅读INSTALL.Ubuntu文件,根据提示安装所需环境
sudo apt-get -y install mercurial cmake make gcc bison flex libsctp-dev libgnutls-dev libgcrypt-dev libpq-dev libmysqlclient-dev ssl-cert debhelper fakeroot
不同的系统可能需要找到组件对应的版本才能正确安装
-
编译和安装
阅读INSTALL.Ubuntu文件,根据提示进行编译和安装
Create a build directory, and enter it # mkdir fDbuild # cd fDbuild Configure and generate the Makefiles # cmake ../freeDiameter # make edit_cache Compile all files: # make (OPTION) See available targets: # make help (OPTION) Check the software has a correct basic behavior on your environment. -- only if you did not disable the tests in step 6 # make test (OPTION) Install the software in configured locations: # sudo make install
-
运行
正确安装之后,使用freeDiameterd命令就能运行程序,详细的参数如下
Usage: freeDiameterd [OPTIONS]... -h, --help Print help and exit -V, --version Print version and exit -c, --config=filename Read configuration from this file instead of the default location (/usr/local/etc/freeDiameter/freeDiameter.conf) -D, --daemon Start program in background -p, --pidfile=filename Write PID to filename -s, --syslog Write log output to syslog (instead of stdout) -t, --datelogger Write log output to stdout prefixed with date Debug: These options are mostly useful for developers -d, --debug Increase verbosity of log messages if default logger is used -f, --dbg_func <func> Enable all traces within the function <func> -F, --dbg_file <file.c> Enable all traces within the file <file.c> (basename match) -g, --dbg_gnutls <int> Enable GNU TLS debug at level <int> -l, --dbglocale Set the locale for error messages -q, --quiet Decrease verbosity of log messages if default logger is used
运行测试用例test_app
配置文件
test_app
有server
和client
两种模式,因此需要运行两个freeDiameterd
进程,配置两个freeDiameter.conf
文件,以及两个扩展文件test_ser.conf
和test_cli.conf
,此外还需要test_app.fdx
文件和一些密钥文件。
test_app.fdx
test_app.fdx
的生成需要在extensions
的CMakeLists.txt
中将OFF
置为ON
,然后再进行编译,安装
FD_EXTENSION_SUBDIR(test_app "Testing application to send dummy message to another peer, like a Diameter 'ping'" OFF)
密钥文件
运行doc/sigle_host
中的make_certs.sh
生成
freeDiameter-1.conf
Identity = "peer1.localdomain";
Realm = "localdomain";
Port = 3868;
SecPort = 3869;
TLS_Cred = "peer1.cert.pem",
"peer1.key.pem";
TLS_CA = "cacert.pem";
LoadExtension = "/usr/local/lib/freeDiameter/test_app.fdx" : "test_ser.conf";
ConnectPeer = "peer2.localdomain" { ConnectTo = "127.0.0.1"; No_TLS; port = 30868; };
Identity = "peer1.localdomain";
- 设置了服务的标识(Identity),通常是服务的主机名或域名。Realm = "localdomain";
- 定义了服务的域名(Realm)。Port = 3868;
- 这行设置了服务监听的端口号,用于非加密的通信。SecPort = 3869;
- 这行设置了服务的加密端口号,用于TLS加密通信。TLS_Cred = "peer1.cert.pem", "peer1.key.pem";
- 这行定义了服务使用的TLS证书和私钥文件的路径。peer1.cert.pem
是证书文件,peer1.key.pem
是私钥文件。TLS_CA = "cacert.pem";
- 这行指定了信任的证书颁发机构(CA)的证书文件,用于TLS通信中的证书验证。LoadExtension = "/usr/local/lib/freeDiameter/test_app.fdx" : "test_ser.conf";
- 这行指定了一个扩展模块的路径和配置文件,test_app.fdx
是扩展模块文件,test_ser.conf
是该模块的配置文件。ConnectPeer = "peer2.localdomain" { ConnectTo = "127.0.0.1"; No_TLS; port = 30868; };
- 定义了一个要连接的对等体(ConnectPeer),并提供了以下参数:ConnectTo = "127.0.0.1";
- 指定了对等体的IP地址,这里是本地回环地址。No_TLS;
- 表示与这个对等体的连接不使用TLS加密。port = 30868;
- 指定了连接到该对等体使用的端口号。
freeDiameter-2.conf
Identity = "peer2.localdomain";
Realm = "localdomain";
Port = 30868;
SecPort = 30869;
TLS_Cred = "peer2.cert.pem",
"peer2.key.pem";
TLS_CA = "cacert.pem";
LoadExtension = "/usr/local/lib/freeDiameter/test_app.fdx" : "test_cli.conf";
ConnectPeer = "peer1.localdomain" { ConnectTo = "127.0.0.1"; No_TLS; };
test_ser.conf
# This application is defined as a Vendor-Specific application.
# Since freeDiameter does not have a IANA-assigned Vendor ID, we let a configurable value here:
vendor-id = 999999;
# The application id. Same remark as previously.
appli-id = 999999;
# The command code for Test-Request and Test-Answer. The range 0xfffffe-ffffff (dec: 16777215) is reserved for experimental use.
cmd-id = 16777214;
# The AVP id for the test.
avp-id = 345678;
# Another AVP id for long payload test. default to value 0, meaning this is not used.
long-avp-id = 1;
# Define the payload length of the long-avp. Default 5000 bytes.
long-avp-len = 5000;
#######################
# Configuration of the extension behavior
# The mode for the extension.
# - server: Answer incoming requests. The signal is ignored.
# - client: Send a request when the signal is received, and measure the time to receiving answer.
# - both: acts as client and server
mode = server;
test_cli.conf
# Configuration of the test message
# This application is defined as a Vendor-Specific application.
# Since freeDiameter does not have a IANA-assigned Vendor ID, we let a configurable value here:
vendor-id = 999999;
# The application id. Same remark as previously.
appli-id = 999999;
# The command code for Test-Request and Test-Answer. The range 0xfffffe-ffffff (dec: 16777215) is reserved for experimental use.
cmd-id = 16777214;
# The AVP id for the test.
avp-id = 345678;
# Another AVP id for long payload test. default to value 0, meaning this is not used.
long-avp-id = 1;
# Define the payload length of the long-avp. Default 5000 bytes.
long-avp-len = 5000;
#######################
# Configuration of the extension behavior
# The mode for the extension.
# - server: Answer incoming requests. The signal is ignored.
# - client: Send a request when the signal is received, and measure the time to receiving answer.
# - both: acts as client and server
mode = client;
# The behavior can be changed by specifying additional "benchmark;" keyword.
# When this keyword appears, it changes the behavior as follow:
# - server is silent on message reception, only the activity summary is displayed every 30 seconds
# - client attempts to send as many messages as possible during 10 seconds and counts them.
# The benchmark keyword can be followed optionally by two integers:
# duration is the time for the measurement, in seconds (default 10).
# concurrency is the number of messages that can be on the wire before waiting for an answer (default 100).
# benchmark;
#######################
# Client-specific configuration
# The Destination-Realm for the message
# (default is sending to same realm as local peer).
dest-realm = "localdomain";
# The Destination-Host for the message.
# (default is not providing this AVP).
dest-host = "peer1.localdomain";
# The User-Name for the message (may be useful for some routing tests).
# (default is not providing this AVP).
# user-name = "usrsname@localdomain";
# The signal that triggers sending the test message
# Note: Symbolic names are not recognized, you must use integers
signal = 10;
测试消息配置
vendor-id = 999999;
- 定义了该应用程序的供应商ID。appli-id = 999999;
- 定义了应用程序ID。cmd-id = 16777214;
- 设置了 Test-Request 和 Test-Answer 命令的代码。avp-id = 345678;
- 定义了测试使用的 AVP ID。long-avp-id = 1;
- 定义了用于长负载测试的另一个 AVP 的ID,默认值为0,表示不使用。long-avp-len = 5000;
- 定义了长 AVP 的负载长度,默认为5000字节。
扩展行为配置
-
mode = client;
- 定义了扩展的工作模式。这里是客户端模式,当接收到信号时发送请求并测量接收响应的时间。 -
benchmark;
如果出现此关键字,将改变行为:
- 服务器模式下,在消息接收时保持静默,每30秒显示一次活动摘要。
- 客户端模式下,在10秒内尽可能多地发送消息并计数。
-
duration
和concurrency
是可选参数,分别表示测量时间(默认10秒)和在等待响应之前可以在网络上的并发消息数量(默认100)。
客户端特定配置
dest-realm = "localdomain";
- 定义了消息的目标领域,默认是发送到与本地对等体相同的领域。dest-host = "peer1.localdomain";
- 定义了消息的目标主机。如果不提供此 AVP,则默认不提供。user-name = "usrsname@localdomain";
- 定义了消息的用户名称,可能对某些路由测试有用。这里被注释掉了,表示默认不提供。signal = 10;
- 定义了触发发送测试消息的信号。
运行
freeDiameterd -c ./freeDiameter-1.conf
freeDiameterd -c ./freeDimaeter-2.conf
服务端
客户端
向客户端发送信号10
bench测试