Mercurial > hg > freeDiameter-dtls
annotate extensions/test_app/test_app.c @ 1230:992437a90bda
Enable mix of short and long messages in test_app
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Thu, 20 Jun 2013 11:01:19 +0800 |
parents | c2fbaf2985f4 |
children |
rev | line source |
---|---|
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
575
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
1127
1af09cc156d6
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
5 * Copyright (c) 2013, WIDE Project and NICT * |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 /* |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 * Test application for freeDiameter. |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
38 */ |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
39 |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
40 #include "test_app.h" |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
41 |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
42 /* Initialize the configuration */ |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
43 struct ta_conf * ta_conf = NULL; |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
44 static struct ta_conf _conf; |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
45 static pthread_t ta_stats_th = (pthread_t)NULL; |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
46 |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
47 static int ta_conf_init(void) |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
48 { |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
49 ta_conf = &_conf; |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
50 memset(ta_conf, 0, sizeof(struct ta_conf)); |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
51 |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
52 /* Set the default values */ |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
53 ta_conf->vendor_id = 999999; /* Dummy value */ |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
54 ta_conf->appli_id = 0xffffff; /* dummy value */ |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
55 ta_conf->cmd_id = 0xfffffe; /* Experimental */ |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
56 ta_conf->avp_id = 0xffffff; /* dummy value */ |
1220
c2fbaf2985f4
New options to test_app extension to generate long Diameter messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1201
diff
changeset
|
57 ta_conf->long_avp_len = 5000; |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
58 ta_conf->mode = MODE_SERV | MODE_CLI; |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
59 ta_conf->dest_realm = strdup(fd_g_config->cnf_diamrlm); |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
60 ta_conf->dest_host = NULL; |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
61 ta_conf->signal = TEST_APP_DEFAULT_SIGNAL; |
575
66f188b3ca84
Configurable parameters for the benchmark mode
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
572
diff
changeset
|
62 ta_conf->bench_concur = 100; |
66f188b3ca84
Configurable parameters for the benchmark mode
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
572
diff
changeset
|
63 ta_conf->bench_duration = 10; |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
64 |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
65 /* Initialize the mutex */ |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
66 CHECK_POSIX( pthread_mutex_init(&ta_conf->stats_lock, NULL) ); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
67 |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
68 return 0; |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
69 } |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
70 |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
71 static void ta_conf_dump(void) |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
72 { |
1230
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
73 LOG_D( "------- app_test configuration dump: ---------"); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
74 LOG_D( " Vendor Id .......... : %u", ta_conf->vendor_id); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
75 LOG_D( " Application Id ..... : %u", ta_conf->appli_id); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
76 LOG_D( " Command Id ......... : %u", ta_conf->cmd_id); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
77 LOG_D( " AVP Id ............. : %u", ta_conf->avp_id); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
78 LOG_D( " Long AVP Id ........ : %u", ta_conf->long_avp_id); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
79 LOG_D( " Long AVP len ....... : %zu", ta_conf->long_avp_len); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
80 LOG_D( " Mode ............... : %s%s%s%s", |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
81 ta_conf->mode & MODE_SERV ? "Serv" : "", |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
82 ta_conf->mode & MODE_CLI ? "Cli" : "", |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
83 ta_conf->mode & MODE_BENCH ? " (Benchmark)" : "", |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
84 ta_conf->mode & MODE_MIXSIZE ? " (Mix)" : "" |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
85 ); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
86 LOG_D( " Destination Realm .. : %s", ta_conf->dest_realm ?: "- none -"); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
87 LOG_D( " Destination Host ... : %s", ta_conf->dest_host ?: "- none -"); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
88 LOG_D( " Signal ............. : %i", ta_conf->signal); |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
89 LOG_D( "------- /app_test configuration dump ---------"); |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
90 } |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
91 |
575
66f188b3ca84
Configurable parameters for the benchmark mode
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
572
diff
changeset
|
92 /* Function to display statistics periodically */ |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
93 static void * ta_stats(void * arg) { |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
94 |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
95 struct timespec start, now; |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
96 struct ta_stats copy; |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
97 |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
98 /* Get the start time */ |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
99 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &start), ); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
100 |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
101 /* Now, loop until canceled */ |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
102 while (1) { |
575
66f188b3ca84
Configurable parameters for the benchmark mode
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
572
diff
changeset
|
103 /* Display statistics every XX seconds */ |
1197
16f2d2f15e5b
Allow better usage in benchmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
104 sleep(ta_conf->bench_duration + 3); |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
105 |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
106 /* Now, get the current stats */ |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
107 CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), ); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
108 memcpy(©, &ta_conf->stats, sizeof(struct ta_stats)); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
109 CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), ); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
110 |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
111 /* Get the current execution time */ |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
112 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), ); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
113 |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
114 /* Now, display everything */ |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
115 fd_log_debug( "------- app_test statistics ---------"); |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
116 if (now.tv_nsec >= start.tv_nsec) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
117 fd_log_debug( " Executing for: %d.%06ld sec", |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
118 (int)(now.tv_sec - start.tv_sec), |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
119 (long)(now.tv_nsec - start.tv_nsec) / 1000); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
120 } else { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
121 fd_log_debug( " Executing for: %d.%06ld sec", |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
122 (int)(now.tv_sec - 1 - start.tv_sec), |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
123 (long)(now.tv_nsec + 1000000000 - start.tv_nsec) / 1000); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
124 } |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
125 |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
126 if (ta_conf->mode & MODE_SERV) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
127 fd_log_debug( " Server: %llu message(s) echoed", copy.nb_echoed); |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
128 } |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
129 if (ta_conf->mode & MODE_CLI) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
130 fd_log_debug( " Client:"); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
131 fd_log_debug( " %llu message(s) sent", copy.nb_sent); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
132 fd_log_debug( " %llu error(s) received", copy.nb_errs); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
133 fd_log_debug( " %llu answer(s) received", copy.nb_recv); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
134 fd_log_debug( " fastest: %ld.%06ld sec.", copy.shortest / 1000000, copy.shortest % 1000000); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
135 fd_log_debug( " slowest: %ld.%06ld sec.", copy.longest / 1000000, copy.longest % 1000000); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
136 fd_log_debug( " Average: %ld.%06ld sec.", copy.avg / 1000000, copy.avg % 1000000); |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
137 } |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
741
diff
changeset
|
138 fd_log_debug( "-------------------------------------"); |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
139 } |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
140 |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
141 return NULL; /* never called */ |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
142 } |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
143 |
1201
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
144 static struct fd_hook_hdl * hookhdl[2] = { NULL, NULL }; |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
145 static void ta_hook_cb_silent(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata) { |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
146 } |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
147 static void ta_hook_cb_oneline(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata) { |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
148 char * buf = NULL; |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
149 size_t len; |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
150 |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
151 CHECK_MALLOC_DO( fd_msg_dump_summary(&buf, &len, NULL, msg, NULL, 0, 0), |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
152 { LOG_E("Error while dumping a message"); return; } ); |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
153 |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
154 LOG_N("{%d} %s: %s", type, (char *)other ?:"<nil>", buf ?:"<nil>"); |
1197
16f2d2f15e5b
Allow better usage in benchmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
155 |
1201
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
156 free(buf); |
1197
16f2d2f15e5b
Allow better usage in benchmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
157 } |
16f2d2f15e5b
Allow better usage in benchmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
158 |
16f2d2f15e5b
Allow better usage in benchmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
159 |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
160 /* entry point */ |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
161 static int ta_entry(char * conffile) |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
162 { |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
163 TRACE_ENTRY("%p", conffile); |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
164 |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
165 /* Initialize configuration */ |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
166 CHECK_FCT( ta_conf_init() ); |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
167 |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
168 /* Parse configuration file */ |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
169 if (conffile != NULL) { |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
170 CHECK_FCT( ta_conf_handle(conffile) ); |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
171 } |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
172 |
1230
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
173 if ((ta_conf->mode & MODE_MIXSIZE) && (!ta_conf->long_avp_id)) |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
174 ta_conf->long_avp_id = 0xfffffe; |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
175 |
992437a90bda
Enable mix of short and long messages in test_app
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1220
diff
changeset
|
176 LOG_N("Extension test_app initialized with configuration: '%s'", conffile); |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
177 ta_conf_dump(); |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
178 |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
179 /* Install objects definitions for this test application */ |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
180 CHECK_FCT( ta_dict_init() ); |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
181 |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
182 /* Install the handlers for incoming messages */ |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
183 if (ta_conf->mode & MODE_SERV) { |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
184 CHECK_FCT( ta_serv_init() ); |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
185 } |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
186 |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
187 /* Start the signal handler thread */ |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
188 if (ta_conf->mode & MODE_CLI) { |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
189 if (ta_conf->mode & MODE_BENCH) { |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
190 CHECK_FCT( ta_bench_init() ); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
191 } else { |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
192 CHECK_FCT( ta_cli_init() ); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
193 } |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
194 } |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
195 |
101
c16e97f91c59
Added advertisement of the test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
98
diff
changeset
|
196 /* Advertise the support for the test application in the peer */ |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
197 CHECK_FCT( fd_disp_app_support ( ta_appli, ta_vendor, 1, 0 ) ); |
101
c16e97f91c59
Added advertisement of the test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
98
diff
changeset
|
198 |
1197
16f2d2f15e5b
Allow better usage in benchmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
199 if (ta_conf->mode & MODE_BENCH) { |
16f2d2f15e5b
Allow better usage in benchmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
200 /* Register an empty hook to disable the default handling */ |
1201
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
201 CHECK_FCT( fd_hook_register( HOOK_MASK( HOOK_DATA_RECEIVED, HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_LOCAL, HOOK_MESSAGE_SENT, HOOK_MESSAGE_ROUTING_FORWARD, HOOK_MESSAGE_ROUTING_LOCAL ), |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
202 ta_hook_cb_silent, NULL, NULL, &hookhdl[0]) ); |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
203 CHECK_FCT( fd_hook_register( HOOK_MASK( HOOK_MESSAGE_ROUTING_ERROR, HOOK_MESSAGE_DROPPED ), |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
204 ta_hook_cb_oneline, NULL, NULL, &hookhdl[1]) ); |
1197
16f2d2f15e5b
Allow better usage in benchmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
205 |
16f2d2f15e5b
Allow better usage in benchmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
206 } |
16f2d2f15e5b
Allow better usage in benchmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
207 |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
208 /* Start the statistics thread */ |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
209 CHECK_POSIX( pthread_create(&ta_stats_th, NULL, ta_stats, NULL) ); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
210 |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
211 return 0; |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
212 } |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
213 |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
214 /* Unload */ |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
215 void fd_ext_fini(void) |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
216 { |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
217 if (ta_conf->mode & MODE_CLI) |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
218 ta_cli_fini(); |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
219 if (ta_conf->mode & MODE_SERV) |
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
220 ta_serv_fini(); |
1201
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
221 if (hookhdl[0]) |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
222 fd_hook_unregister( hookhdl[0] ); |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
223 if (hookhdl[1]) |
2c62bba0ef4b
Add some hooks in test_app in becnhmark mode
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1200
diff
changeset
|
224 fd_hook_unregister( hookhdl[1] ); |
572
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
225 CHECK_FCT_DO( fd_thr_term(&ta_stats_th), ); |
b1b56d4682d0
Added benchmark mode in test_app
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
226 CHECK_POSIX_DO( pthread_mutex_destroy(&ta_conf->stats_lock), ); |
93
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
227 } |
3910804c84db
Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
228 |
120
d7acdc46134d
Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
108
diff
changeset
|
229 EXTENSION_ENTRY("test_app", ta_entry); |