Mercurial > hg > freeDiameter
annotate tests/testmesg.c @ 1281:ab6457399be2 1.2.1-rc1
Updated copyright information
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Sat, 03 Jan 2015 02:23:28 +0800 |
parents | 25fad6714991 |
children | 3f1e79e1273e |
rev | line source |
---|---|
0 | 1 /********************************************************************************************************* |
2 * Software License Agreement (BSD License) * | |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
0 | 4 * * |
1281
ab6457399be2
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1268
diff
changeset
|
5 * Copyright (c) 2015, WIDE Project and NICT * |
0 | 6 * All rights reserved. * |
7 * * | |
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * | |
9 * permitted provided that the following conditions are met: * | |
10 * * | |
11 * * Redistributions of source code must retain the above * | |
12 * copyright notice, this list of conditions and the * | |
13 * following disclaimer. * | |
14 * * | |
15 * * Redistributions in binary form must reproduce the above * | |
16 * copyright notice, this list of conditions and the * | |
17 * following disclaimer in the documentation and/or other * | |
18 * materials provided with the distribution. * | |
19 * * | |
20 * * Neither the name of the WIDE Project or NICT nor the * | |
21 * names of its contributors may be used to endorse or * | |
22 * promote products derived from this software without * | |
23 * specific prior written permission of WIDE Project and * | |
24 * NICT. * | |
25 * * | |
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * | |
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * | |
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * | |
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * | |
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * | |
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * | |
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * | |
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * | |
34 *********************************************************************************************************/ | |
35 | |
36 #include "tests.h" | |
37 | |
38 /* Main test routine */ | |
39 int main(int argc, char *argv[]) | |
40 { | |
41 struct msg * acr = NULL; | |
42 struct avp * pi = NULL, *avp1, *avp2; | |
43 unsigned char * buf = NULL; | |
44 | |
45 /* First, initialize the daemon modules */ | |
46 INIT_FD(); | |
47 | |
48 /* Create the message object from model */ | |
49 { | |
50 struct dict_object * acr_model = NULL; | |
51 | |
52 /* Now find the ACR dictionary object */ | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
53 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &acr_model, ENOENT ) ); |
0 | 54 |
55 /* Create the instance, using the templates */ | |
56 CHECK( 0, fd_msg_new ( acr_model, 0, &acr ) ); | |
57 | |
58 /* Check there is no child */ | |
59 CHECK( ENOENT, fd_msg_browse ( acr, MSG_BRW_FIRST_CHILD, NULL, NULL) ); | |
60 | |
61 #if 0 | |
62 /* For debug: dump the object */ | |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
63 fd_log_debug("Dumping Accounting-Request empty message:"); |
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
64 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, acr, fd_g_config->cnf_dict, 0, 1)); |
0 | 65 #endif |
66 } | |
67 | |
68 /* Create the Proxy-Info AVP from model */ | |
69 { | |
70 struct dict_object * pi_model = NULL; | |
71 | |
72 /* Now find the ACR dictionary object */ | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
73 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Proxy-Info", &pi_model, ENOENT ) ); |
0 | 74 |
75 /* Create the instance, using the templates */ | |
76 CHECK( 0, fd_msg_avp_new ( pi_model, 0, &pi ) ); | |
77 | |
78 #if 0 | |
79 /* For debug: dump the object */ | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
80 fd_log_debug("Dumping Proxy-Info AVP"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
81 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, pi, fd_g_config->cnf_dict, 0, 1)); |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
82 fd_log_debug("Dumping dictionary model"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
83 fd_log_debug("%s", fd_dict_dump_object(FD_DUMP_TEST_PARAMS, pi_model)); |
0 | 84 #endif |
85 | |
86 } | |
87 | |
88 /* Get a reference to the current last AVP in the message */ | |
89 { | |
90 int diff = 0; | |
91 | |
92 CHECK( 0, fd_msg_avp_new ( NULL, 0, &avp1 ) ); | |
93 CHECK( 0, fd_msg_avp_add ( acr, MSG_BRW_LAST_CHILD, avp1) ); | |
94 | |
95 CHECK( 0, fd_msg_browse ( acr, MSG_BRW_LAST_CHILD, &avp2, &diff) ); | |
96 CHECK( 1, diff ); | |
97 CHECK( avp1, avp2 ); | |
98 | |
99 /* Check that we cannot add this AVP to another object since it is already linked */ | |
100 CHECK( EINVAL, fd_msg_avp_add( pi, MSG_BRW_LAST_CHILD, avp1) ); | |
101 } | |
102 | |
103 /* Now add the Proxy-Info AVP at the end of the message */ | |
104 { | |
105 CHECK( 0, fd_msg_avp_add( acr, MSG_BRW_LAST_CHILD, pi) ); | |
106 #if 0 | |
107 /* For debug: dump the object */ | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
108 fd_log_debug("Dumping Accounting-Request with Proxy-Info AVP at the end"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
109 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, acr, fd_g_config->cnf_dict, 0, 1)); |
0 | 110 #endif |
111 } | |
112 | |
113 /* Check the last child is now the proxy-Info */ | |
114 { | |
115 CHECK( 0, fd_msg_browse ( acr, MSG_BRW_LAST_CHILD, &avp2, NULL) ); | |
116 CHECK( pi, avp2 ); | |
117 } | |
118 | |
119 /* Check that the avp before the proxy-info is the previous last one */ | |
120 { | |
121 int diff = 0; | |
122 CHECK( 0, fd_msg_browse ( pi, MSG_BRW_PREV, &avp2, &diff) ); | |
123 CHECK( avp1, avp2 ); | |
124 CHECK( 0, diff); | |
125 } | |
126 | |
127 /* Check that there are no AVP after the proxy-info */ | |
128 CHECK( ENOENT, fd_msg_browse ( pi, MSG_BRW_NEXT, NULL, NULL) ); | |
129 | |
130 /* Test the fd_msg_free function unlinks the object properly */ | |
131 { | |
132 struct dict_object * rr_model = NULL; | |
133 | |
134 /* Now find the dictionary object */ | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
135 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Route-Record", &rr_model, ENOENT ) ); |
0 | 136 |
137 /* Create the instance, using the templates */ | |
138 CHECK( 0, fd_msg_avp_new ( rr_model, 0, &avp1 ) ); | |
139 | |
140 /* Add the AVP at the end of the message */ | |
141 CHECK( 0, fd_msg_avp_add( pi, MSG_BRW_NEXT, avp1) ); | |
142 | |
143 /* Check the last AVP of the message is now this one */ | |
144 CHECK( 0, fd_msg_browse ( acr, MSG_BRW_LAST_CHILD, &avp2, NULL) ); | |
145 CHECK( avp1, avp2 ); | |
146 | |
147 /* Now delete it */ | |
148 CHECK( 0, fd_msg_free( avp1 ) ); | |
149 | |
150 /* Check the last AVP of the message is back to pi */ | |
151 CHECK( 0, fd_msg_browse ( acr, MSG_BRW_LAST_CHILD, &avp2, NULL) ); | |
152 CHECK( pi, avp2 ); | |
153 | |
154 /* Delete the whole message */ | |
155 CHECK( 0, fd_msg_free( acr ) ); | |
156 } | |
157 | |
158 /* Recreate the message object */ | |
159 { | |
160 struct dict_object * acr_model = NULL; | |
161 | |
162 /* Now find the ACR dictionary object */ | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
163 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &acr_model, ENOENT ) ); |
0 | 164 |
165 /* Create the instance, using the templates */ | |
166 CHECK( 0, fd_msg_new ( acr_model, 0, &acr ) ); | |
167 } | |
168 | |
169 /* Now let's create some additional Dictionary objects for the test */ | |
170 { | |
171 /* The constant values used here are totally arbitrary chosen */ | |
172 struct dict_object * vendor; | |
173 { | |
174 struct dict_vendor_data vendor_data = { 73565, "Vendor test" }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
175 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_VENDOR, &vendor_data , NULL, &vendor ) ); |
0 | 176 } |
177 | |
178 { | |
179 struct dict_application_data app_data = { 73566, "Application test" }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
180 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_APPLICATION, &app_data , vendor, NULL ) ); |
0 | 181 } |
182 | |
183 { | |
184 struct dict_avp_data avp_data = { 73567, 0, "AVP Test - no vendor - f32", 0, 0, AVP_TYPE_FLOAT32 }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
185 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, NULL ) ); |
0 | 186 } |
187 | |
890
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
188 { |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
189 struct dict_avp_data avp_data = { 139103, 0, "AVP Test - no vendor - f64", 0, 0, AVP_TYPE_FLOAT64 }; |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
190 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, NULL ) ); |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
191 } |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
192 |
0 | 193 { |
194 struct dict_object * type = NULL; | |
195 struct dict_type_data type_data = { AVP_TYPE_INTEGER64, "Int64 test" }; | |
196 struct dict_avp_data avp_data = { 73568, 73565, "AVP Test - i64", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_INTEGER64 }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
197 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_TYPE, &type_data , NULL, &type ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
198 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , type, NULL ) ); |
0 | 199 } |
200 | |
201 { | |
202 struct dict_object * type = NULL; | |
203 struct dict_type_data type_data = { AVP_TYPE_INTEGER32, "Enum32 test" }; | |
204 struct dict_enumval_data val1 = { "i32 const test (val 1)", { .i32 = 1 } }; | |
205 struct dict_enumval_data val2 = { "i32 const test (val 2)", { .i32 = 2 } }; | |
206 struct dict_enumval_data val3 = { "i32 const test (val -5)",{ .i32 = -5 } }; | |
207 struct dict_avp_data avp_data = { 73569, 73565, "AVP Test - enumi32", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_INTEGER32 }; | |
208 | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
209 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_TYPE, &type_data , NULL, &type ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
210 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , type, NULL ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
211 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_ENUMVAL, &val1 , type, NULL ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
212 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_ENUMVAL, &val2 , type, NULL ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
213 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_ENUMVAL, &val3 , type, NULL ) ); |
0 | 214 } |
215 | |
216 { | |
217 struct dict_object * type = NULL; | |
218 struct dict_type_data type_data = { AVP_TYPE_OCTETSTRING, "OS test" }; | |
219 struct dict_avp_data avp_data = { 73570, 73565, "AVP Test - os", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_OCTETSTRING }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
220 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_TYPE, &type_data , NULL, &type ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
221 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , type, NULL ) ); |
0 | 222 } |
223 | |
224 { | |
225 struct dict_object * type = NULL; | |
226 struct dict_type_data type_data = { AVP_TYPE_OCTETSTRING, "OS enum test" }; | |
227 struct dict_enumval_data val1 = { "os const test (Test)", { .os = { (unsigned char *)"Test", 4 } } }; | |
228 struct dict_enumval_data val2 = { "os const test (waaad)", { .os = { (unsigned char *)"waaad", 5 } } }; | |
229 struct dict_enumval_data val3 = { "os const test (waa)", { .os = { (unsigned char *)"waaad", 3 } } }; | |
230 struct dict_avp_data avp_data = { 73571, 73565, "AVP Test - enumos", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_OCTETSTRING }; | |
231 | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
232 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_TYPE, &type_data , NULL, &type ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
233 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , type, NULL ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
234 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_ENUMVAL, &val1 , type, NULL ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
235 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_ENUMVAL, &val2 , type, NULL ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
236 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_ENUMVAL, &val3 , type, NULL ) ); |
0 | 237 } |
238 | |
239 { | |
240 struct dict_object * gavp = NULL; | |
241 struct dict_avp_data avp_data = { 73572, 73565, "AVP Test - grouped", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_GROUPED }; | |
242 | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
243 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, &gavp ) ); |
0 | 244 |
245 /* Macro to search AVP and create a rule */ | |
246 #define ADD_RULE( _parent, _vendor, _avpname, _pos, _min, _max, _ord ) { \ | |
247 struct dict_object * _avp = NULL; \ | |
248 struct dict_avp_request _req = { (_vendor), 0, (_avpname) }; \ | |
249 struct dict_rule_data _data; \ | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
250 CHECK( 0, fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp, ENOENT));\ |
0 | 251 _data.rule_avp = _avp; \ |
252 _data.rule_position = (_pos); \ | |
253 _data.rule_order = (_ord); \ | |
254 _data.rule_min = (_min); \ | |
255 _data.rule_max = (_max); \ | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
256 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_RULE, &_data , (_parent), NULL ) ); \ |
0 | 257 } |
258 | |
259 ADD_RULE(gavp, 73565, "AVP Test - os", RULE_OPTIONAL, -1, -1, 0); | |
260 | |
261 } | |
262 | |
263 { | |
264 struct dict_object * application = NULL; | |
265 struct dict_object * command = NULL; | |
266 struct dict_cmd_data cmd_data = { 73573, "Test-Command-Request", CMD_FLAG_REQUEST, CMD_FLAG_REQUEST }; | |
267 | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
268 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Application test", &application, ENOENT ) ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
269 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_COMMAND, &cmd_data , application, &command ) ); |
0 | 270 ADD_RULE(command, 0, "AVP Test - no vendor - f32", RULE_FIXED_HEAD, -1, 1, 1); |
271 ADD_RULE(command, 73565, "AVP Test - i64", RULE_REQUIRED, -1, -1, 0); | |
272 ADD_RULE(command, 73565, "AVP Test - enumi32", RULE_OPTIONAL, -1, -1, 0); | |
273 ADD_RULE(command, 73565, "AVP Test - os", RULE_OPTIONAL, -1, -1, 0); | |
274 ADD_RULE(command, 73565, "AVP Test - enumos", RULE_OPTIONAL, -1, -1, 0); | |
275 ADD_RULE(command, 73565, "AVP Test - grouped", RULE_OPTIONAL, -1, -1, 0); | |
276 } | |
277 | |
278 { | |
890
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
279 struct dict_object * application = NULL; |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
280 struct dict_object * command = NULL; |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
281 struct dict_cmd_data cmd_data = { 73573, "Test-Command-Answer", CMD_FLAG_REQUEST, 0 }; |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
282 |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
283 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Application test", &application, ENOENT ) ); |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
284 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_COMMAND, &cmd_data , application, &command ) ); |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
285 } |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
286 |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
287 { |
0 | 288 struct dict_object * gavp = NULL; |
289 struct dict_avp_data avp_data = { 73574, 73565, "AVP Test - rules", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_GROUPED }; | |
290 | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
291 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, &gavp ) ); |
0 | 292 |
293 ADD_RULE(gavp, 0, "AVP Test - no vendor - f32", RULE_FIXED_HEAD, 0, 1, 1); | |
294 ADD_RULE(gavp, 73565, "AVP Test - i64", RULE_FIXED_HEAD, -1, 1, 2); | |
295 ADD_RULE(gavp, 73565, "AVP Test - enumi32", RULE_FIXED_HEAD, -1, 1, 3); | |
296 ADD_RULE(gavp, 73565, "AVP Test - os", RULE_REQUIRED, 2, 3, 0); | |
297 ADD_RULE(gavp, 73565, "AVP Test - enumos", RULE_OPTIONAL, 0, 1, 0); | |
298 ADD_RULE(gavp, 73565, "AVP Test - grouped", RULE_FIXED_TAIL, -1, 1, 1); | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
299 /* ABNF : |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
300 < no vendor - f32 > |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
301 < i64 > |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
302 < enumi32 > |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
303 2*3 { os } |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
304 *1 [ enumos ] |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
305 < grouped > |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
306 */ |
0 | 307 #if 0 |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
308 fd_log_debug("%s", fd_dict_dump_object(FD_DUMP_TEST_PARAMS, gavp)); |
0 | 309 #endif |
310 } | |
311 #if 0 | |
312 { | |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
313 fd_log_debug("%s", fd_dict_dump_object(FD_DUMP_TEST_PARAMS, vendor)); |
0 | 314 } |
315 #endif | |
316 } | |
317 | |
318 /* Now create some values and check the length is correctly handled */ | |
319 { | |
320 struct dict_object * cmd_model = NULL; | |
321 struct msg * msg = NULL; | |
322 struct dict_object * avp_model = NULL; | |
323 struct avp * avp = NULL; | |
324 union avp_value value; | |
325 | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
326 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Test-Command-Request", &cmd_model, ENOENT ) ); |
0 | 327 |
328 /* Check an error is trigged if the AVP has no value set */ | |
329 { | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
330 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "AVP Test - no vendor - f32", &avp_model, ENOENT ) ); |
0 | 331 |
332 CHECK( 0, fd_msg_new ( cmd_model, 0, &msg ) ); | |
333 CHECK( 0, fd_msg_avp_new ( avp_model, 0, &avp ) ); | |
334 | |
335 CHECK( 0, fd_msg_avp_add ( msg, MSG_BRW_FIRST_CHILD, avp ) ); | |
336 | |
337 CHECK( EINVAL, fd_msg_update_length ( avp ) ); | |
338 CHECK( EINVAL, fd_msg_update_length ( msg ) ); | |
339 | |
340 CHECK( 0, fd_msg_free( msg ) ); | |
341 } | |
342 | |
343 /* Check the sizes are handled properly */ | |
344 { | |
345 struct avp * avpi = NULL; | |
346 struct avp * avpch = NULL; | |
347 struct avp_hdr * avpdata = NULL; | |
348 struct msg_hdr * msgdata = NULL; | |
349 #define ADD_AVP( _parent, _position, _avpi, _avpvendor, _avpname) { \ | |
350 struct dict_object * _avp = NULL; \ | |
351 struct dict_avp_request _req = { (_avpvendor), 0, (_avpname) }; \ | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
352 CHECK( 0, fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp, ENOENT));\ |
0 | 353 CHECK( 0, fd_msg_avp_new ( _avp, 0, &_avpi ) ); \ |
354 CHECK( 0, fd_msg_avp_add ( (_parent), (_position), _avpi ) ); \ | |
355 } | |
356 /* Create a message with many AVP inside */ | |
357 CHECK( 0, fd_msg_new ( cmd_model, 0, &msg ) ); | |
358 CHECK( 0, fd_msg_hdr ( msg, &msgdata ) ); | |
359 | |
360 /* Avp no vendor, float32 => size = 12 */ | |
361 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0, "AVP Test - no vendor - f32" ); | |
362 value.f32 = 3.1415; | |
363 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
364 CHECK( 0, fd_msg_update_length ( avpi ) ); | |
365 #if 0 | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
366 fd_log_debug("AVP no vendor, value 3.1415:"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
367 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, avpi, fd_g_config->cnf_dict, 0, 0)); |
0 | 368 #endif |
369 CHECK( 0, fd_msg_avp_hdr ( avpi, &avpdata ) ); | |
370 CHECK( 12, avpdata->avp_len ); | |
371 | |
372 /* Check what happens when we delete the value */ | |
373 CHECK( 0, fd_msg_avp_setvalue ( avpi, NULL ) ); | |
374 CHECK( EINVAL, fd_msg_update_length ( avpi ) ); | |
375 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
376 | |
377 /* Add a vendor AVP, integer64 => size = 20 */ | |
378 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - i64" ); | |
379 value.i64 = 0x123456789abcdeLL; | |
380 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
381 CHECK( 0, fd_msg_update_length ( avpi ) ); | |
382 #if 0 | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
383 fd_log_debug("AVP vendor, value 0x123456789abcdeL:"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
384 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, avpi, fd_g_config->cnf_dict, 0, 0)); |
0 | 385 #endif |
386 CHECK( 0, fd_msg_avp_hdr ( avpi, &avpdata ) ); | |
387 CHECK( 20, avpdata->avp_len ); | |
388 | |
389 /* Check the size of the message is 20 (header) + 12 + 20 = 52 */ | |
390 CHECK( 0, fd_msg_update_length ( msg ) ); | |
391 CHECK( 52, msgdata->msg_length ); | |
392 | |
393 /* Add an AVP with an enum value */ | |
394 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumi32" ); | |
395 { | |
396 struct dict_object * type_model = NULL; | |
397 struct dict_object * value_model = NULL; | |
398 struct dict_enumval_request request; | |
399 | |
400 CHECK( 0, fd_msg_model ( avpi, &avp_model ) ); | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
401 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) ); |
0 | 402 memset(&request, 0, sizeof(request)); |
403 request.type_obj = type_model; | |
404 request.search.enum_name = "i32 const test (val 2)"; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
405 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) ); |
0 | 406 CHECK( 0, fd_dict_getval ( value_model, &request.search ) ); |
407 CHECK( 0, fd_msg_avp_setvalue ( avpi, &request.search.enum_value ) ); | |
408 #if 0 | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
409 fd_log_debug("AVP enum i32, value 2 (from const):"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
410 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, avpi, fd_g_config->cnf_dict, 0, 0)); |
0 | 411 #endif |
412 } | |
413 | |
414 /* Add an AVP with an enum value, negative */ | |
415 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumi32" ); | |
416 { | |
417 struct dict_object * type_model = NULL; | |
418 struct dict_object * value_model = NULL; | |
419 struct dict_enumval_request request; | |
420 | |
421 CHECK( 0, fd_msg_model ( avpi, &avp_model ) ); | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
422 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) ); |
0 | 423 memset(&request, 0, sizeof(request)); |
424 request.type_obj = type_model; | |
425 request.search.enum_name = "i32 const test (val -5)"; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
426 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) ); |
0 | 427 CHECK( 0, fd_dict_getval ( value_model, &request.search ) ); |
428 CHECK( 0, fd_msg_avp_setvalue ( avpi, &request.search.enum_value ) ); | |
429 #if 0 | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
430 fd_log_debug("AVP enum i32, value -5 (from const):"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
431 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, avpi, fd_g_config->cnf_dict, 0, 0)); |
0 | 432 #endif |
433 /* Check the size is correct ( 12 for header + 4 for value ) */ | |
434 CHECK( 0, fd_msg_update_length ( avpi ) ); | |
435 CHECK( 0, fd_msg_avp_hdr ( avpi, &avpdata ) ); | |
436 CHECK( 16, avpdata->avp_len ); | |
437 } | |
438 | |
439 /* Now add a value which is not a constant into an enumerated AVP */ | |
440 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumi32" ); | |
441 value.i32 = -10; | |
442 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
443 CHECK( 0, fd_msg_update_length ( avpi ) ); | |
444 #if 0 | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
445 fd_log_debug("AVP vendor enum i32, value -10 (not const):"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
446 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, avpi, fd_g_config->cnf_dict, 0, 0)); |
0 | 447 #endif |
448 | |
449 /* Add an octetstring AVP */ | |
450 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - os" ); | |
451 { | |
452 unsigned char buf[90]; | |
453 memcpy(&buf, "This\0 is a buffer of dat\a. It is not a string so we can have any c\0ntr\0l character here...\0\0", 89); | |
454 value.os.data = buf; | |
455 value.os.len = 89; | |
456 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
457 memset(&buf, 0, sizeof(buf)); /* Test that the OS value is really copied */ | |
458 CHECK( 0, fd_msg_update_length ( avpi ) ); | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
459 #if 0 |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
460 fd_log_debug("AVP octet string, 'This\\0 is a b...'"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
461 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, avpi, fd_g_config->cnf_dict, 0, 0)); |
0 | 462 #endif |
463 CHECK( 0, fd_msg_avp_hdr ( avpi, &avpdata ) ); | |
464 CHECK( 101, avpdata->avp_len ); | |
465 CHECK( 'T', avpdata->avp_value->os.data[0] ); | |
466 CHECK( 'i', avpdata->avp_value->os.data[6] ); | |
467 } | |
468 | |
469 /* Check the size of the message is 20 (header) + 12 + 20 + 16 * 3 + 101 + 3 (padding) = 204 */ | |
470 CHECK( 0, fd_msg_update_length ( msg ) ); | |
471 CHECK( 204, msgdata->msg_length ); | |
472 | |
473 /* Add an octetstring from an enumerated constant */ | |
474 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumos" ); | |
475 { | |
476 struct dict_object * type_model = NULL; | |
477 struct dict_object * value_model = NULL; | |
478 struct dict_enumval_request request; | |
479 | |
480 CHECK( 0, fd_msg_model ( avpi, &avp_model ) ); | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
481 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) ); |
0 | 482 memset(&request, 0, sizeof(request)); |
483 request.type_obj = type_model; | |
484 request.search.enum_name = "os const test (waaad)"; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
485 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) ); |
0 | 486 CHECK( 0, fd_dict_getval ( value_model, &request.search ) ); |
487 CHECK( 0, fd_msg_avp_setvalue ( avpi, &request.search.enum_value ) ); | |
488 #if 0 | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
489 fd_log_debug("AVP Enumuerated OctetString (from const):"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
490 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, avpi, fd_g_config->cnf_dict, 0, 0)); |
0 | 491 #endif |
492 /* Check the size is correct ( 12 for header + 5 for value ) */ | |
493 CHECK( 0, fd_msg_update_length ( avpi ) ); | |
494 CHECK( 0, fd_msg_avp_hdr ( avpi, &avpdata ) ); | |
495 CHECK( 17, avpdata->avp_len ); | |
496 } | |
497 | |
498 /* Add an octetstring from an enumerated constant */ | |
499 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumos" ); | |
500 { | |
501 struct dict_object * type_model = NULL; | |
502 struct dict_object * value_model = NULL; | |
503 struct dict_enumval_request request; | |
504 | |
505 CHECK( 0, fd_msg_model ( avpi, &avp_model ) ); | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
506 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) ); |
0 | 507 memset(&request, 0, sizeof(request)); |
508 request.type_obj = type_model; | |
509 request.search.enum_name = "os const test (waa)"; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
510 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) ); |
0 | 511 CHECK( 0, fd_dict_getval ( value_model, &request.search ) ); |
512 CHECK( 0, fd_msg_avp_setvalue ( avpi, &request.search.enum_value ) ); | |
513 #if 0 | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
514 fd_log_debug("AVP Enumuerated OctetString (from const):"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
515 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, avpi, fd_g_config->cnf_dict, 0, 0)); |
0 | 516 #endif |
517 /* Check the size is correct ( 12 for header + 3 for value ) */ | |
518 CHECK( 0, fd_msg_update_length ( avpi ) ); | |
519 CHECK( 0, fd_msg_avp_hdr ( avpi, &avpdata ) ); | |
520 CHECK( 15, avpdata->avp_len ); | |
521 } | |
522 | |
523 | |
524 /* Check the size of the message is 20 (header) + 12 + 20 + 16 * 3 + (101 + 3) + (17 + 3) + (15 + 1) = 240 */ | |
525 CHECK( 0, fd_msg_update_length ( msg ) ); | |
526 CHECK( 240, msgdata->msg_length ); | |
527 | |
528 /* Now test the grouped AVPs */ | |
529 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - grouped" ); | |
530 ADD_AVP( avpi, MSG_BRW_LAST_CHILD, avpch, 73565, "AVP Test - os" ); | |
531 { | |
532 value.os.data = (unsigned char *)"12345678"; | |
533 value.os.len = 8; | |
534 CHECK( 0, fd_msg_avp_setvalue ( avpch, &value ) ); | |
535 #if 0 | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
536 fd_log_debug("AVP octet string, '1234678'"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
537 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, avpch, fd_g_config->cnf_dict, 0, 0)); |
0 | 538 #endif |
539 CHECK( 0, fd_msg_update_length ( avpch ) ); | |
540 CHECK( 0, fd_msg_avp_hdr ( avpch, &avpdata ) ); | |
541 CHECK( 20, avpdata->avp_len ); | |
542 } | |
543 ADD_AVP( avpi, MSG_BRW_LAST_CHILD, avpch, 73565, "AVP Test - os" ); | |
544 { | |
545 value.os.data = (unsigned char *)"123456789"; | |
546 value.os.len = 9; | |
547 CHECK( 0, fd_msg_avp_setvalue ( avpch, &value ) ); | |
548 #if 0 | |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
931
diff
changeset
|
549 fd_log_debug("AVP octet string, '12346789'"); |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
550 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, avpch, fd_g_config->cnf_dict, 0, 0)); |
0 | 551 #endif |
552 } | |
553 | |
554 /* Check the size is updated recursively: (gavp hdr: 12) + (avp1: 20) + (avp2: 21 + 3) = 56 */ | |
555 CHECK( 0, fd_msg_update_length ( avpi ) ); | |
556 CHECK( 0, fd_msg_avp_hdr ( avpi, &avpdata ) ); | |
557 CHECK( 56, avpdata->avp_len ); | |
558 | |
559 /* Add another similar grouped AVP, to have lot of padding */ | |
560 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - grouped" ); | |
561 ADD_AVP( avpi, MSG_BRW_LAST_CHILD, avpch, 73565, "AVP Test - os" ); | |
562 { | |
563 value.os.data = (unsigned char *)"1"; | |
564 value.os.len = 1; | |
565 CHECK( 0, fd_msg_avp_setvalue ( avpch, &value ) ); | |
566 } | |
567 ADD_AVP( avpi, MSG_BRW_LAST_CHILD, avpch, 73565, "AVP Test - os" ); | |
568 { | |
569 value.os.data = (unsigned char *)"1234567"; | |
570 value.os.len = 7; | |
571 CHECK( 0, fd_msg_avp_setvalue ( avpch, &value ) ); | |
572 } | |
573 | |
574 /* Now check the global size of the message, if padding is correctly handled */ | |
575 /* size = 20 (header) + 12 + 20 + 16 * 3 + (101 + 3) + (17 + 3) + (15 + 1) | |
576 * + ( 12 + ( 20 + 21) + 3 ) # padding for the grouped AVP = 3 | |
577 * + ( 12 + ( (13 + 3) + 19 ) + 1 ) # and 1 for this one | |
578 * size = 240 + 56 + 48 = 344 | |
579 */ | |
580 CHECK( 0, fd_msg_update_length ( msg ) ); | |
581 #if 0 | |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
582 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, msg, fd_g_config->cnf_dict, 0, 1)); |
0 | 583 #endif |
584 CHECK( 344, msgdata->msg_length ); | |
585 | |
586 /* Set the application to the test application: 73566 */ | |
587 msgdata->msg_appl = 73566; | |
588 | |
589 /* Set the hop-by-hop ID to a random value: 0x4b44b41d */ | |
590 msgdata->msg_hbhid = 0x4b44b41d; | |
591 /* Set the end-to-end ID to a random value: 0xe2ee2e1d */ | |
592 msgdata->msg_eteid = 0xe2ee2e1d; | |
593 } | |
594 | |
595 /* Test the msg_bufferize function */ | |
596 { | |
597 | |
598 CHECK( 0, fd_msg_bufferize( msg, &buf, NULL ) ); | |
599 | |
600 /* Test the first bytes */ | |
601 CHECK( 0x01, buf[0] ); /* Version */ | |
602 CHECK( 0x00, buf[1] ); /* Length: 344 = 0x000158 */ | |
603 CHECK( 0x01, buf[2] ); | |
604 CHECK( 0x58, buf[3] ); | |
605 CHECK( 0x80, buf[4] ); /* flags: only "R" is set. */ | |
606 CHECK( 0x01, buf[5] ); /* Command code: 73573 = 0x011F65 */ | |
607 CHECK( 0x1F, buf[6] ); | |
608 CHECK( 0x65, buf[7] ); | |
609 CHECK( 0x00, buf[8] ); /* App ID: 73566 = 0x00011F5E */ | |
610 CHECK( 0x01, buf[9] ); | |
611 CHECK( 0x1F, buf[10] ); | |
612 CHECK( 0x5E, buf[11] ); | |
613 CHECK( 0x4b, buf[12] ); /* hop-by-hop id: 0x4b44b41d */ | |
614 CHECK( 0x44, buf[13] ); | |
615 CHECK( 0xb4, buf[14] ); | |
616 CHECK( 0x1d, buf[15] ); | |
617 CHECK( 0xe2, buf[16] ); /* end-to-end id: 0xe2ee2e1d */ | |
618 CHECK( 0xee, buf[17] ); | |
619 CHECK( 0x2e, buf[18] ); | |
620 CHECK( 0x1d, buf[19] ); | |
621 | |
622 CHECK( 0x00, buf[20] ); /* First AVP (AVP Test - no vendor - f32) begin: code 73567 = 0x00011F5F */ | |
623 CHECK( 0x01, buf[21] ); | |
624 CHECK( 0x1F, buf[22] ); | |
625 CHECK( 0x5F, buf[23] ); | |
626 CHECK( 0x00, buf[24] ); /* flags: 0 */ | |
627 CHECK( 0x00, buf[25] ); /* length: 12 = 0x00000c */ | |
628 CHECK( 0x00, buf[26] ); | |
629 CHECK( 0x0C, buf[27] ); | |
630 CHECK( 0x40, buf[28] ); /* Value: 3.1415: sign = '+' => most significant bit = 0 */ | |
631 CHECK( 0x49, buf[29] ); /* 2 <= 3.1415 < 4 => exponent = 1 => biaised (on 8 bits) = (decimal) 128 = (binary) 100 0000 0 */ | |
632 CHECK( 0x0e, buf[30] ); /* significand = (decimal) 1.57075 = (binary) 1.100 1001 0000 1110 0101 0110 */ | |
633 CHECK( 0x56, buf[31] ); /* total => 0100 0000 0100 1001 0000 1110 0101 0110 = (hexa) 40 49 0e 56*/ | |
634 | |
635 /* The other AVPs will be tested by successful parsing... */ | |
636 } | |
637 | |
638 /* Now free the message, we keep only the buffer. */ | |
639 CHECK( 0, fd_msg_free( msg ) ); | |
640 | |
641 } | |
642 | |
643 /* Test the parsing of buffers and messages */ | |
644 { | |
645 unsigned char * buf_cpy = NULL; | |
646 struct msg * msg; | |
647 | |
648 #define CPYBUF() { \ | |
649 buf_cpy = malloc(344); \ | |
650 CHECK( buf_cpy ? 1 : 0, 1); \ | |
651 memcpy(buf_cpy, buf, 344); \ | |
652 } | |
653 | |
654 /* Test the msg_parse_buffer function */ | |
655 { | |
656 CPYBUF(); | |
657 CHECK( EBADMSG, fd_msg_parse_buffer( &buf_cpy, 340, &msg) ); | |
658 | |
659 CPYBUF(); | |
660 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); | |
661 #if 0 | |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
662 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, msg, fd_g_config->cnf_dict, 0, 1)); |
0 | 663 #endif |
664 | |
665 /* reinit the msg */ | |
666 CHECK( 0, fd_msg_free ( msg ) ); | |
667 | |
668 } | |
669 | |
670 /* Test the fd_msg_search_avp function */ | |
671 { | |
672 struct dict_object * avp_model; | |
673 struct avp * found; | |
674 struct avp_hdr * avpdata = NULL; | |
675 | |
676 /* Now find the ACR dictionary object */ | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
677 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "AVP Test - no vendor - f32", &avp_model, ENOENT ) ); |
0 | 678 |
679 CPYBUF(); | |
680 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); | |
681 | |
682 /* Search this AVP instance in the msg */ | |
683 CHECK( 0, fd_msg_search_avp( msg, avp_model, &found ) ); | |
684 | |
685 /* Check the AVP value is 3.1415 */ | |
686 CHECK( 0, fd_msg_avp_hdr ( found, &avpdata ) ); | |
687 CHECK( 3.1415F, avpdata->avp_value->f32 ); | |
688 | |
689 /* reinit the msg */ | |
690 CHECK( 0, fd_msg_free ( msg ) ); | |
691 | |
692 } | |
693 | |
694 /* Test the msg_parse_dict function */ | |
695 { | |
696 /* Test with an unknown command code */ | |
697 { | |
698 CPYBUF(); | |
699 | |
700 /* Change the command-code */ | |
701 buf_cpy[5] = 0x11; | |
702 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); | |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
35
diff
changeset
|
703 CHECK( ENOTSUP, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); |
0 | 704 |
705 /* reset */ | |
706 CHECK( 0, fd_msg_free ( msg ) ); | |
707 } | |
708 | |
709 /* Test with an unknown Mandatory AVP */ | |
710 { | |
711 CPYBUF(); | |
712 | |
713 buf_cpy[20] = 0x11; /* New AVP code = 0x11011F5F, undefined */ | |
714 buf_cpy[24] = 0x40; /* Add the 'M' flag */ | |
715 | |
716 /* Check that we cannot support this message now */ | |
717 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); | |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
35
diff
changeset
|
718 CHECK( ENOTSUP, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); |
0 | 719 |
720 /* reset */ | |
721 CHECK( 0, fd_msg_free ( msg ) ); | |
722 } | |
723 | |
724 /* Test with an unknown optional AVP */ | |
725 { | |
726 CPYBUF(); | |
727 | |
728 buf_cpy[20] = 0x11; /* New AVP code = 0x11011F5F, undefined */ | |
729 | |
730 /* Check that we can support this message now */ | |
731 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); | |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
35
diff
changeset
|
732 CHECK( 0, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); |
0 | 733 |
734 #if 0 | |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
735 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, msg, fd_g_config->cnf_dict, 0, 1)); |
0 | 736 #endif |
737 | |
738 /* reset */ | |
739 CHECK( 0, fd_msg_free ( msg ) ); | |
740 } | |
741 | |
890
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
742 /* Test with an invalid AVP (definition mismatch with the dictionary) */ |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
743 { |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
744 CPYBUF(); |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
745 |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
746 buf_cpy[21] = 0x02; /* New AVP code = 0x00021F5F, f64 type in the dictionary */ |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
747 |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
748 |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
749 /* Check that we cannot support this message now */ |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
750 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
751 CHECK( EBADMSG, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
752 |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
753 /* reset */ |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
754 CHECK( 0, fd_msg_free ( msg ) ); |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
755 } |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
756 |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
757 { |
892
b2e8f1a3ef76
Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents:
891
diff
changeset
|
758 unsigned char * buftmp = NULL; |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
759 struct msg * error; |
890
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
760 /* Check the parse or error works as expected */ |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
761 CPYBUF(); |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
762 |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
763 buf_cpy[21] = 0x02; /* New AVP code = 0x00021F5F, f64 type in the dictionary */ |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
764 |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
765 /* Check that we cannot support this message now */ |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
766 CHECK( 0, fd_msg_init() ); |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
767 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
768 CHECK( EBADMSG, fd_msg_parse_or_error( &msg, &error ) ); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
769 CHECK( NULL, msg ); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
770 msg = error; |
890
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
771 |
892
b2e8f1a3ef76
Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents:
891
diff
changeset
|
772 CHECK( 0, fd_msg_bufferize( msg, &buftmp, NULL ) ); |
890
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
773 |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
774 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, msg, fd_g_config->cnf_dict, 0, 1)); |
890
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
775 |
892
b2e8f1a3ef76
Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents:
891
diff
changeset
|
776 TODO("Check the Failed-AVP is as expected"); |
b2e8f1a3ef76
Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents:
891
diff
changeset
|
777 |
b2e8f1a3ef76
Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents:
891
diff
changeset
|
778 |
890
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
779 /* reset */ |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
780 CHECK( 0, fd_msg_free ( msg ) ); |
892
b2e8f1a3ef76
Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents:
891
diff
changeset
|
781 free(buftmp); |
890
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
782 } |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
783 |
19a261c9a2e1
Added test case to reproduce bug reported by Zack http://lists.freediameter.net/pipermail/help/2012-November/000538.html
Sebastien Decugis <sdecugis@freediameter.net>
parents:
740
diff
changeset
|
784 |
0 | 785 CHECK( 0, fd_msg_parse_buffer( &buf, 344, &msg) ); |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
35
diff
changeset
|
786 CHECK( 0, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); |
0 | 787 #if 0 |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
788 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, msg, fd_g_config->cnf_dict, 0, 1)); |
0 | 789 #endif |
790 } | |
791 | |
792 /* Now test the msg_parse_rule function */ | |
793 { | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
794 struct fd_pei pei; |
0 | 795 |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
796 CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &pei ) ); |
0 | 797 |
798 /* Use the "AVP Test - rules" AVP to test the rules */ | |
799 { | |
800 struct avp * tavp = NULL; | |
801 struct avp * tempavp = NULL; | |
802 struct avp * childavp = NULL; | |
803 | |
804 ADD_AVP( msg, MSG_BRW_LAST_CHILD, tavp, 73565, "AVP Test - rules" ); | |
805 | |
806 /* Create a conforming message first */ | |
807 ADD_AVP( tavp, MSG_BRW_LAST_CHILD, childavp, 0, "AVP Test - no vendor - f32" ); | |
808 ADD_AVP( tavp, MSG_BRW_LAST_CHILD, childavp, 73565, "AVP Test - i64" ); | |
809 ADD_AVP( tavp, MSG_BRW_LAST_CHILD, childavp, 73565, "AVP Test - enumi32" ); | |
810 ADD_AVP( tavp, MSG_BRW_LAST_CHILD, childavp, 73565, "AVP Test - os" ); | |
811 ADD_AVP( tavp, MSG_BRW_LAST_CHILD, childavp, 73565, "AVP Test - os" ); | |
812 ADD_AVP( tavp, MSG_BRW_LAST_CHILD, childavp, 73565, "AVP Test - grouped" ); | |
813 | |
814 /* Check the message is still conform */ | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
815 CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &pei ) ); |
0 | 816 |
817 /* The first avp is optional in fixed position, so remove it and check the message is still OK */ | |
818 CHECK( 0, fd_msg_browse ( tavp, MSG_BRW_FIRST_CHILD, &childavp, NULL) ); | |
819 CHECK( 0, fd_msg_free ( childavp ) ); | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
820 CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &pei ) ); |
0 | 821 ADD_AVP( tavp, MSG_BRW_FIRST_CHILD, childavp, 0, "AVP Test - no vendor - f32" ); |
822 | |
823 | |
824 /* Now break some rules and check it is detected */ | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
825 #define CHECK_CONFLICT( _msg, _error, _conflictavp_name, _conflictavp_vnd ) { \ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
826 struct fd_pei _pei; \ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
827 CHECK( EBADMSG, fd_msg_parse_rules( _msg, fd_g_config->cnf_dict, &_pei ) ); \ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
828 if (_error) { \ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
829 CHECK( 0, strcmp( _error, _pei.pei_errcode ) ); \ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
830 } \ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
831 if ((_conflictavp_name) == NULL) { \ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
832 CHECK( NULL, _pei.pei_avp); \ |
0 | 833 } else { \ |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
834 struct dict_avp_request _req = { (_conflictavp_vnd), 0, (_conflictavp_name) }; \ |
0 | 835 struct dict_object * _avp; \ |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
836 struct dict_object * _conflict; \ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
837 CHECK( 1, (_pei.pei_avp) ? 1 : 0 ); \ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
838 CHECK( 0, fd_msg_model( _pei.pei_avp, &_conflict ) ); \ |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
839 CHECK( 0, fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp, ENOENT)); \ |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
840 CHECK( _avp, _conflict ); \ |
0 | 841 } \ |
842 } | |
843 | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
844 /* ABNF : |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
845 < no vendor - f32 > |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
846 < i64 > |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
847 < enumi32 > |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
848 2*3 { os } |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
849 *1 [ enumos ] |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
850 < grouped > |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
851 */ |
0 | 852 { |
853 /* Test the FIXED_HEAD rules positions: add another AVP before the third */ | |
854 CHECK( 0, fd_msg_browse ( tavp, MSG_BRW_FIRST_CHILD, &tempavp, NULL) ); /* tempavp is the novendor avp */ | |
855 CHECK( 0, fd_msg_browse ( tempavp, MSG_BRW_NEXT, &tempavp, NULL) ); /* tempavp is the i64 avp */ | |
856 ADD_AVP( tempavp, MSG_BRW_NEXT, childavp, 73565, "AVP Test - os" ); | |
857 | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
858 CHECK_CONFLICT( msg, "DIAMETER_MISSING_AVP", "AVP Test - enumi32", 73565 ); |
0 | 859 |
860 /* Now remove this AVP */ | |
861 CHECK( 0, fd_msg_free ( childavp ) ); | |
862 } | |
863 { | |
864 /* Remove the third AVP, same rule must conflict */ | |
865 CHECK( 0, fd_msg_browse ( tempavp, MSG_BRW_NEXT, &childavp, NULL) ); /* childavp is the enumi32 avp */ | |
866 CHECK( 0, fd_msg_free ( childavp ) ); | |
867 | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
868 CHECK_CONFLICT( msg, "DIAMETER_MISSING_AVP", "AVP Test - enumi32", 73565 ); |
0 | 869 |
870 /* Add the AVP back */ | |
871 ADD_AVP( tempavp, MSG_BRW_NEXT, childavp, 73565, "AVP Test - enumi32" ); | |
872 } | |
873 | |
874 { | |
875 /* Test the minimum value in the REQUIRED rule: delete one of the os AVPs */ | |
876 CHECK( 0, fd_msg_browse ( childavp, MSG_BRW_NEXT, &tempavp, NULL) ); /* tempavp is the os avp */ | |
877 CHECK( 0, fd_msg_free ( tempavp ) ); | |
878 | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
879 CHECK_CONFLICT( msg, "DIAMETER_MISSING_AVP", "AVP Test - os", 73565 ); /* The rule requires at least 2 AVP, we have only 1 */ |
0 | 880 |
881 /* Now add this AVP */ | |
882 ADD_AVP( childavp, MSG_BRW_NEXT, tempavp, 73565, "AVP Test - os" ); | |
883 } | |
884 { | |
885 /* Test the maximum value in the REQUIRED rule: add more of the os AVPs */ | |
886 ADD_AVP( childavp, MSG_BRW_NEXT, tempavp, 73565, "AVP Test - os" ); | |
887 ADD_AVP( childavp, MSG_BRW_NEXT, tempavp, 73565, "AVP Test - os" ); | |
888 | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
889 CHECK_CONFLICT( msg, "DIAMETER_AVP_OCCURS_TOO_MANY_TIMES", "AVP Test - os", 73565 ); /* The rule requires at most 3 AVP, we have 4 */ |
0 | 890 |
891 /* Now delete these AVP */ | |
892 CHECK( 0, fd_msg_free ( tempavp ) ); | |
893 CHECK( 0, fd_msg_browse ( childavp, MSG_BRW_NEXT, &tempavp, NULL) ); | |
894 CHECK( 0, fd_msg_free ( tempavp ) ); | |
895 } | |
896 | |
897 { | |
898 /* Test the maximum value in the OPTIONAL rule: add 2 enumos AVPs */ | |
899 ADD_AVP( childavp, MSG_BRW_NEXT, tempavp, 73565, "AVP Test - enumos" ); | |
900 | |
901 /* The message is still conform */ | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
902 CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &pei ) ); |
0 | 903 |
904 /* Now break the rule */ | |
905 ADD_AVP( childavp, MSG_BRW_NEXT, tempavp, 73565, "AVP Test - enumos" ); | |
906 | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
907 CHECK_CONFLICT( msg, "DIAMETER_AVP_OCCURS_TOO_MANY_TIMES", "AVP Test - enumos", 73565 ); |
0 | 908 |
909 /* Now delete this AVP */ | |
910 CHECK( 0, fd_msg_free ( tempavp ) ); | |
911 } | |
912 | |
913 { | |
914 /* Test the RULE_FIXED_TAIL rules positions: add another AVP at the end */ | |
915 ADD_AVP( tavp, MSG_BRW_LAST_CHILD, childavp, 73565, "AVP Test - os" ); | |
916 | |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
917 CHECK_CONFLICT( msg, "DIAMETER_MISSING_AVP", "AVP Test - grouped", 73565 ); |
0 | 918 |
919 /* Now remove this AVP */ | |
920 CHECK( 0, fd_msg_free ( childavp ) ); | |
921 } | |
922 } | |
923 } | |
995
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
924 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
925 /* Test the fd_msg_new_answer_from_req function */ |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
926 { |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
927 struct dict_object * cmd_model = NULL; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
928 struct msg * msg = NULL; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
929 struct avp * pi1, *pi2, *avp; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
930 char * host1="host1", * host2="host2"; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
931 union avp_value value; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
932 struct msg_hdr * msgdata = NULL; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
933 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
934 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Test-Command-Request", &cmd_model, ENOENT ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
935 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
936 /* Test default behavior without flags */ |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
937 { |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
938 /* Create a message with some AVPs inside */ |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
939 CHECK( 0, fd_msg_new ( cmd_model, 0, &msg ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
940 CHECK( 0, fd_msg_hdr ( msg, &msgdata ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
941 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
942 /* Add a session id */ |
1047
a130b6a13abb
Fix some compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
995
diff
changeset
|
943 CHECK( 0, fd_msg_new_session( msg, (os0_t)"testmsg", strlen("testmsg") ) ); |
995
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
944 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
945 /* Create two instances of Proxy-Info */ |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
946 ADD_AVP( msg, MSG_BRW_LAST_CHILD, pi1, 0, "Proxy-Info"); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
947 ADD_AVP( msg, MSG_BRW_LAST_CHILD, pi2, 0, "Proxy-Info"); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
948 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
949 ADD_AVP( pi1, MSG_BRW_LAST_CHILD, avp, 0, "Proxy-State"); |
1047
a130b6a13abb
Fix some compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
995
diff
changeset
|
950 value.os.data = (os0_t)"ps_pi1"; |
a130b6a13abb
Fix some compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
995
diff
changeset
|
951 value.os.len = strlen((char *)value.os.data); |
995
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
952 CHECK( 0, fd_msg_avp_setvalue ( avp, &value ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
953 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
954 ADD_AVP( pi2, MSG_BRW_LAST_CHILD, avp, 0, "Proxy-State"); |
1047
a130b6a13abb
Fix some compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
995
diff
changeset
|
955 value.os.data = (os0_t)"pi2_state"; |
a130b6a13abb
Fix some compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
995
diff
changeset
|
956 value.os.len = strlen((char *)value.os.data); |
995
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
957 CHECK( 0, fd_msg_avp_setvalue ( avp, &value ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
958 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
959 ADD_AVP( pi1, MSG_BRW_FIRST_CHILD, avp, 0, "Proxy-Host"); |
1047
a130b6a13abb
Fix some compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
995
diff
changeset
|
960 value.os.data = (os0_t)host1; |
995
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
961 value.os.len = strlen(host1); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
962 CHECK( 0, fd_msg_avp_setvalue ( avp, &value ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
963 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
964 ADD_AVP( pi2, MSG_BRW_LAST_CHILD, avp, 0, "Proxy-Host"); |
1047
a130b6a13abb
Fix some compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
995
diff
changeset
|
965 value.os.data = (os0_t)host2; |
995
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
966 value.os.len = strlen(host2); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
967 CHECK( 0, fd_msg_avp_setvalue ( avp, &value ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
968 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
969 ADD_AVP( pi2, MSG_BRW_LAST_CHILD, avp, 73565, "AVP Test - i64"); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
970 value.i64 = 0x123456789abcdeLL; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
971 CHECK( 0, fd_msg_avp_setvalue ( avp, &value ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
972 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
973 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
974 /* Now call the fd_msg_new_answer_from_req function */ |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
975 CHECK( 0, fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, &msg, 0 ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
976 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
977 /* Check there is a Session-Id AVP */ |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
978 { |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
979 struct session * sess; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
980 int new; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
981 CHECK( 0, fd_msg_sess_get(fd_g_config->cnf_dict, msg, &sess, &new) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
982 CHECK( 1, sess == NULL ? 0 : 1 ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
983 CHECK( 0, new ? 1 : 0 ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
984 } |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
985 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
986 /* Check there are two Proxy-Info with the two hosts */ |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
987 { |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
988 int got_h1 = 0, got_h2=0; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
989 CHECK( 0, fd_msg_browse ( msg, MSG_BRW_FIRST_CHILD, &avp, NULL) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
990 while(avp) { |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
991 struct avp_hdr * avpdata = NULL; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
992 CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
993 if (avpdata->avp_code == AC_PROXY_INFO) { |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
994 struct avp * iavp; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
995 CHECK( 0, fd_msg_browse ( avp, MSG_BRW_FIRST_CHILD, &iavp, NULL) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
996 while(iavp) { |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
997 struct avp_hdr * iavpdata = NULL; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
998 CHECK( 0, fd_msg_avp_hdr ( iavp, &iavpdata ) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
999 if (iavpdata->avp_code == AC_PROXY_HOST) { |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1000 if (!memcmp(host1, iavpdata->avp_value->os.data, strlen(host1))) |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1001 got_h1++; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1002 if (!memcmp(host2, iavpdata->avp_value->os.data, strlen(host2))) |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1003 got_h2++; |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1004 } |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1005 CHECK( 0, fd_msg_browse ( iavp, MSG_BRW_NEXT, &iavp, NULL) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1006 } |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1007 } |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1008 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1009 CHECK( 0, fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL) ); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1010 } |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1011 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1012 CHECK(1, got_h1); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1013 CHECK(1, got_h2); |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1014 } |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1015 |
1251
bdd7bf840c8d
Validated previous fix, seems to work
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
1016 /* Now test the behavior of fd_msg_rescode_set with a grouped AVP */ |
bdd7bf840c8d
Validated previous fix, seems to work
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
1017 CHECK( 0, fd_msg_rescode_set(msg, "DIAMETER_AVP_OCCURS_TOO_MANY_TIMES", NULL, pi1, 1) ); |
bdd7bf840c8d
Validated previous fix, seems to work
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
1018 |
bdd7bf840c8d
Validated previous fix, seems to work
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
1019 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, msg, fd_g_config->cnf_dict, 0, 1)); |
bdd7bf840c8d
Validated previous fix, seems to work
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
1020 |
bdd7bf840c8d
Validated previous fix, seems to work
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
1021 TODO("Check the Failed-AVP is as expected"); |
995
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1022 } |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1023 |
2016a0c46bda
Fixed Proxy-Info duplication, added a test case for this
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1024 } |
0 | 1025 } |
1026 | |
1027 /* Test the msg_avp_value_interpret and msg_avp_value_encode functions. use the Address type and Host-IP-Address AVPs */ | |
1028 { | |
1029 struct dict_object * cer_model = NULL; | |
1030 struct msg * cer = NULL; | |
1031 | |
1032 struct dict_object * hia_model = NULL; | |
1033 struct avp *avp4, *avp6; | |
1034 #define TEST_IP4 "192.168.100.101" | |
1035 char buf4[INET_ADDRSTRLEN]; | |
1036 #define TEST_IP6 "1111:2222:3333:4444:1234:5678:9abc:def0" | |
1037 char buf6[INET6_ADDRSTRLEN]; | |
1038 | |
1039 struct sockaddr_storage ss; | |
1040 struct sockaddr_in sin, *psin; | |
1041 struct sockaddr_in6 sin6, *psin6; | |
1042 | |
1043 /* Find the CER dictionary object */ | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
1044 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Capabilities-Exchange-Request", &cer_model, ENOENT ) ); |
0 | 1045 |
1046 /* Now find the Host-IP-Address dictionary object */ | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
1047 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Host-IP-Address", &hia_model, ENOENT ) ); |
0 | 1048 |
1049 /* Create the msg instance */ | |
1050 CHECK( 0, fd_msg_new ( cer_model, 0, &cer ) ); | |
1051 | |
1052 /* Create the avp instances */ | |
1053 CHECK( 0, fd_msg_avp_new ( hia_model, 0, &avp4 ) ); | |
1054 CHECK( 0, fd_msg_avp_new ( hia_model, 0, &avp6 ) ); | |
1055 | |
1056 /* Set the value of the IP avp */ | |
1057 sin.sin_family = AF_INET; | |
1058 CHECK( 1, inet_pton( AF_INET, TEST_IP4, &sin.sin_addr.s_addr ) ); | |
1059 CHECK( 0, fd_msg_avp_value_encode ( &sin, avp4 ) ); | |
1060 | |
1061 /* Set the value of the IP6 avp */ | |
1062 sin6.sin6_family = AF_INET6; | |
1063 CHECK( 1, inet_pton( AF_INET6, TEST_IP6, &sin6.sin6_addr.s6_addr ) ); | |
1064 CHECK( 0, fd_msg_avp_value_encode ( &sin6, avp6 ) ); | |
1065 | |
1066 /* Add these AVPs in the message */ | |
1067 CHECK( 0, fd_msg_avp_add( cer, MSG_BRW_LAST_CHILD, avp4) ); | |
1068 CHECK( 0, fd_msg_avp_add( cer, MSG_BRW_LAST_CHILD, avp6) ); | |
1069 | |
1070 /* Create the buffer for this message */ | |
1071 CHECK( 0, fd_msg_bufferize( cer, &buf, NULL ) ); | |
1072 | |
1073 /* Now free the message, we keep only the buffer. */ | |
1074 CHECK( 0, fd_msg_free( cer ) ); | |
1075 | |
1076 /* Check the content of the buffer is correct (skip command header) */ | |
1077 CHECK( 0x00, buf[20] ); /* First AVP (IP4) begins: code 257 = 0x00000101 */ | |
1078 CHECK( 0x00, buf[21] ); | |
1079 CHECK( 0x01, buf[22] ); | |
1080 CHECK( 0x01, buf[23] ); | |
1081 CHECK( 0x40, buf[24] ); /* flags: M */ | |
1082 CHECK( 0x00, buf[25] ); /* length: 8+6 = 0x00000e */ | |
1083 CHECK( 0x00, buf[26] ); | |
1084 CHECK( 0x0E, buf[27] ); | |
1085 CHECK( 0x00, buf[28] ); /* Value: AddressType 1 */ | |
1086 CHECK( 0x01, buf[29] ); | |
1087 CHECK( 192, buf[30] ); /* 192.168.100.101 */ | |
1088 CHECK( 168, buf[31] ); | |
1089 CHECK( 100, buf[32] ); | |
1090 CHECK( 101, buf[33] ); | |
1091 | |
1092 CHECK( 0x00, buf[34] ); /* Padding */ | |
1093 CHECK( 0x00, buf[35] ); | |
1094 | |
1095 CHECK( 0x00, buf[36] ); /* Second AVP (IP6) begins: code 257 = 0x00000101 */ | |
1096 CHECK( 0x00, buf[37] ); | |
1097 CHECK( 0x01, buf[38] ); | |
1098 CHECK( 0x01, buf[39] ); | |
1099 CHECK( 0x40, buf[40] ); /* flags: M */ | |
1100 CHECK( 0x00, buf[41] ); /* length: 8+18 = 0x00001a */ | |
1101 CHECK( 0x00, buf[42] ); | |
1102 CHECK( 0x1A, buf[43] ); | |
1103 CHECK( 0x00, buf[44] ); /* Value: AddressType 2 */ | |
1104 CHECK( 0x02, buf[45] ); | |
1105 CHECK( 0x11, buf[46] ); /* 1111:2222:3333:4444:1234:5678:9abc:def0 */ | |
1106 CHECK( 0x11, buf[47] ); | |
1107 CHECK( 0x22, buf[48] ); | |
1108 CHECK( 0x22, buf[49] ); | |
1109 CHECK( 0x33, buf[50] ); | |
1110 CHECK( 0x33, buf[51] ); | |
1111 CHECK( 0x44, buf[52] ); | |
1112 CHECK( 0x44, buf[53] ); | |
1113 CHECK( 0x12, buf[54] ); | |
1114 CHECK( 0x34, buf[55] ); | |
1115 CHECK( 0x56, buf[56] ); | |
1116 CHECK( 0x78, buf[57] ); | |
1117 CHECK( 0x9a, buf[58] ); | |
1118 CHECK( 0xbc, buf[59] ); | |
1119 CHECK( 0xde, buf[60] ); | |
1120 CHECK( 0xf0, buf[61] ); | |
1121 | |
1122 /* Ok, now let's recreate the message */ | |
1123 CHECK( 0, fd_msg_parse_buffer( &buf, 64, &cer) ); | |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
35
diff
changeset
|
1124 CHECK( 0, fd_msg_parse_dict( cer, fd_g_config->cnf_dict, NULL ) ); |
0 | 1125 |
1126 /* Get the pointers to the first and last AVP */ | |
1127 CHECK( 0, fd_msg_browse( cer, MSG_BRW_FIRST_CHILD, &avp4, NULL) ); | |
1128 CHECK( 0, fd_msg_browse( cer, MSG_BRW_LAST_CHILD, &avp6, NULL) ); | |
1129 | |
1130 /* Try and interpret the data in the AVPs */ | |
1131 CHECK( 0, fd_msg_avp_value_interpret ( avp4, &ss ) ); | |
1132 psin = (struct sockaddr_in *)&ss; | |
1133 CHECK( AF_INET, psin->sin_family ); | |
1134 CHECK( 0, (inet_ntop( AF_INET, &psin->sin_addr.s_addr, buf4, sizeof(buf4) ) == NULL) ? errno : 0 ); | |
1135 CHECK( 0, strcmp( buf4, TEST_IP4 ) ); | |
1136 | |
1137 CHECK( 0, fd_msg_avp_value_interpret ( avp6, &ss ) ); | |
1138 psin6 = (struct sockaddr_in6 *)&ss; | |
1139 CHECK( AF_INET6, psin6->sin6_family ); | |
1140 CHECK( 0, (inet_ntop( AF_INET6, &psin6->sin6_addr.s6_addr, buf6, sizeof(buf6) ) == NULL) ? errno : 0 ); | |
1141 CHECK( 0, strcasecmp( buf6, TEST_IP6 ) ); | |
1142 | |
1143 /* Ok, it's done */ | |
1144 CHECK( 0, fd_msg_free( cer ) ); | |
1145 } | |
1146 | |
1147 /* Check proper encoding / decoding for all basic types of AVP */ | |
1148 { | |
1149 { | |
1150 struct dict_avp_data avp_data = { 91001, 0, "AVP Test 2 - os", 0, 0, AVP_TYPE_OCTETSTRING }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
1151 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, NULL ) ); |
0 | 1152 } |
1153 { | |
1154 struct dict_avp_data avp_data = { 91002, 0, "AVP Test 2 - i32", 0, 0, AVP_TYPE_INTEGER32 }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
1155 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, NULL ) ); |
0 | 1156 } |
1157 { | |
1158 struct dict_avp_data avp_data = { 91003, 0, "AVP Test 2 - i64", 0, 0, AVP_TYPE_INTEGER64 }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
1159 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, NULL ) ); |
0 | 1160 } |
1161 { | |
1162 struct dict_avp_data avp_data = { 91004, 0, "AVP Test 2 - u32", 0, 0, AVP_TYPE_UNSIGNED32 }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
1163 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, NULL ) ); |
0 | 1164 } |
1165 { | |
1166 struct dict_avp_data avp_data = { 91005, 0, "AVP Test 2 - u64", 0, 0, AVP_TYPE_UNSIGNED64 }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
1167 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, NULL ) ); |
0 | 1168 } |
1169 { | |
1170 struct dict_avp_data avp_data = { 91006, 0, "AVP Test 2 - f32", 0, 0, AVP_TYPE_FLOAT32 }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
1171 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, NULL ) ); |
0 | 1172 } |
1173 { | |
1174 struct dict_avp_data avp_data = { 91007, 0, "AVP Test 2 - f64", 0, 0, AVP_TYPE_FLOAT64 }; | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
1175 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , NULL, NULL ) ); |
0 | 1176 } |
1177 | |
1178 { | |
1179 struct dict_object * cmd_model = NULL; | |
1180 struct msg * msg = NULL; | |
1181 struct avp * avp = NULL; | |
1182 union avp_value value; | |
1183 struct avp * avpi = NULL; | |
1184 struct avp_hdr * avpdata = NULL; | |
1185 struct msg_hdr * msgdata = NULL; | |
1186 | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
1187 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Test-Command-Request", &cmd_model, ENOENT ) ); |
0 | 1188 |
1189 /* Create a message */ | |
1190 CHECK( 0, fd_msg_new ( cmd_model, 0, &msg ) ); | |
1191 CHECK( 0, fd_msg_hdr ( msg, &msgdata ) ); | |
1192 | |
1193 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0, "AVP Test 2 - os" ); | |
1194 value.os.data = (unsigned char *) "waaad"; | |
1195 value.os.len = 6; | |
1196 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
1197 | |
1198 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0, "AVP Test 2 - i32" ); | |
1199 value.i32 = 0x123456; | |
1200 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
1201 | |
1202 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0, "AVP Test 2 - i32" ); | |
1203 value.i32 = -0x123456; | |
1204 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
1205 | |
1206 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0, "AVP Test 2 - i64" ); | |
1207 value.i64 = 0x11223344556677LL; | |
1208 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
1209 | |
1210 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0, "AVP Test 2 - i64" ); | |
1211 value.i64 = -0x11223344556677LL; | |
1212 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
1213 | |
1214 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0, "AVP Test 2 - u32" ); | |
1215 value.u32 = 0xFEDCBA98; | |
1216 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
1217 | |
1218 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0, "AVP Test 2 - u64" ); | |
1219 value.u64 = 0x123456789abcdef0LL; | |
1220 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
1221 | |
1222 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0, "AVP Test 2 - f32" ); | |
1223 value.f32 = 2097153.0F; | |
1224 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
1225 | |
1226 ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0, "AVP Test 2 - f64" ); | |
1227 value.f64 = -1099511627777LL; | |
1228 CHECK( 0, fd_msg_avp_setvalue ( avpi, &value ) ); | |
1229 | |
1230 /* Ok now bufferize */ | |
1231 CHECK( 0, fd_msg_bufferize( msg, &buf, NULL ) ); | |
1232 | |
1233 /* Test the first bytes */ | |
1234 CHECK( 0x01, buf[0] ); /* Version */ | |
1235 CHECK( 0x00, buf[1] ); /* Length: 148 = 0x000094 */ | |
1236 CHECK( 0x00, buf[2] ); | |
1237 CHECK( 0x94, buf[3] ); | |
1238 CHECK( 0x80, buf[4] ); /* flags: only "R" is set. */ | |
1239 CHECK( 0x01, buf[5] ); /* Command code: 73573 = 0x011F65 */ | |
1240 CHECK( 0x1F, buf[6] ); | |
1241 CHECK( 0x65, buf[7] ); | |
1242 CHECK( 0x00, buf[8] ); /* App ID */ | |
1243 CHECK( 0x01, buf[9] ); | |
1244 CHECK( 0x1F, buf[10] ); | |
1245 CHECK( 0x5E, buf[11] ); | |
1246 CHECK( 0x00, buf[12] ); /* hop-by-hop id */ | |
1247 CHECK( 0x00, buf[13] ); | |
1248 CHECK( 0x00, buf[14] ); | |
1249 CHECK( 0x00, buf[15] ); | |
1250 CHECK( 0x00, buf[16] ); /* end-to-end id */ | |
1251 CHECK( 0x00, buf[17] ); | |
1252 CHECK( 0x00, buf[18] ); | |
1253 CHECK( 0x00, buf[19] ); | |
1254 | |
1255 CHECK( 0x00, buf[20] ); /* First AVP (AVP Test 2 - os) begin: code 91001 = 0x00016379 */ | |
1256 CHECK( 0x01, buf[21] ); | |
1257 CHECK( 0x63, buf[22] ); | |
1258 CHECK( 0x79, buf[23] ); | |
1259 CHECK( 0x00, buf[24] ); /* flags: 0 */ | |
1260 CHECK( 0x00, buf[25] ); /* length: 14 = 0x00000e */ | |
1261 CHECK( 0x00, buf[26] ); | |
1262 CHECK( 0x0e, buf[27] ); | |
1263 | |
1264 CHECK( 0x77, buf[28] ); /* "waaad\0" + padding */ | |
1265 CHECK( 0x61, buf[29] ); | |
1266 CHECK( 0x61, buf[30] ); | |
1267 CHECK( 0x61, buf[31] ); | |
1268 CHECK( 0x64, buf[32] ); | |
1269 CHECK( 0x00, buf[33] ); | |
1270 CHECK( 0x00, buf[34] ); | |
1271 CHECK( 0x00, buf[35] ); | |
1272 | |
1273 /* 36 ~ 43 : 2nd AVP header (size at last octet) */ | |
1274 CHECK( 0x0c, buf[43] ); | |
1275 CHECK( 0x00, buf[44] ); /* 0x123456 stored in integer32 in network byte order */ | |
1276 CHECK( 0x12, buf[45] ); | |
1277 CHECK( 0x34, buf[46] ); | |
1278 CHECK( 0x56, buf[47] ); | |
1279 | |
1280 /* 48 ~ 55 : next AVP header */ | |
1281 CHECK( 0xff, buf[56] ); /* -0x123456 stored in integer32 in network byte order. */ | |
1282 CHECK( 0xed, buf[57] ); /* We assume that two's complement is the correct representation, although it's not clearly specified. */ | |
1283 CHECK( 0xcb, buf[58] ); /* 00 12 34 56 inversed => FF ED CB A9 */ | |
1284 CHECK( 0xaa, buf[59] ); /* then "+1" => FF ED CB AA */ | |
1285 | |
1286 /* 60 ~ 67 : next header */ | |
1287 CHECK( 0x10, buf[67] ); /* (the size) */ | |
1288 CHECK( 0x00, buf[68] ); /* 0x11223344556677 in network byte order */ | |
1289 CHECK( 0x11, buf[69] ); | |
1290 CHECK( 0x22, buf[70] ); | |
1291 CHECK( 0x33, buf[71] ); | |
1292 CHECK( 0x44, buf[72] ); | |
1293 CHECK( 0x55, buf[73] ); | |
1294 CHECK( 0x66, buf[74] ); | |
1295 CHECK( 0x77, buf[75] ); | |
1296 | |
1297 /* 76 ~ 83 : next header */ | |
1298 CHECK( 0xFF, buf[84] ); /* - 0x11223344556677 (in two's complement) */ | |
1299 CHECK( 0xEE, buf[85] ); /* gives FF EE DD CC BB AA 99 89 */ | |
1300 CHECK( 0xDD, buf[86] ); | |
1301 CHECK( 0xCC, buf[87] ); | |
1302 CHECK( 0xBB, buf[88] ); | |
1303 CHECK( 0xAA, buf[89] ); | |
1304 CHECK( 0x99, buf[90] ); | |
1305 CHECK( 0x89, buf[91] ); | |
1306 | |
1307 /* 92 ~ 99 : next header */ | |
1308 CHECK( 0x0c, buf[99] ); /* (the size) */ | |
1309 CHECK( 0xFE, buf[100]); /* 0xFEDCBA98 in network byte order */ | |
1310 CHECK( 0xDC, buf[101]); | |
1311 CHECK( 0xBA, buf[102]); | |
1312 CHECK( 0x98, buf[103]); | |
1313 | |
1314 /* 104 ~ 111 : next header */ | |
1315 CHECK( 0x10, buf[111] ); /* (the size) */ | |
1316 CHECK( 0x12, buf[112]); /* 0x123456789abcdef0LL in network byte order */ | |
1317 CHECK( 0x34, buf[113]); | |
1318 CHECK( 0x56, buf[114]); | |
1319 CHECK( 0x78, buf[115]); | |
1320 CHECK( 0x9a, buf[116]); | |
1321 CHECK( 0xbc, buf[117]); | |
1322 CHECK( 0xde, buf[118]); | |
1323 CHECK( 0xf0, buf[119]); | |
1324 | |
1325 /* 120 ~ 127 : next header */ | |
1326 CHECK( 0x0c, buf[127] ); /* (the size) */ | |
1327 CHECK( 0x4a, buf[128]); /* http://en.wikipedia.org/wiki/IEEE_754-1985 to get descvription of the format */ | |
1328 CHECK( 0x00, buf[129]); /* v = 2097153 = 2^21 + 2 ^ 0; sign : "+", 2^21 <= v < 2^22 => exponent = 21; biaised on 8 bits => 21 + 127 => 100 1010 0 */ | |
1329 CHECK( 0x00, buf[130]); /* v = (+1) * (1 ^ 21) * ( 1 + 2^-21 ) => significand 000 0000 0000 0000 0000 0100 */ | |
1330 CHECK( 0x04, buf[131]); /* result: 4a 00 00 04 */ | |
1331 | |
1332 /* 132 ~ 139 : next header */ | |
1333 CHECK( 0x10, buf[139] ); /* (the size) */ | |
1334 CHECK( 0xc2, buf[140]); /* -1099511627777L ( 2^40 + 1 ) in network byte order */ | |
1335 CHECK( 0x70, buf[141]); /* sign: - => most significant bit = 1 */ | |
1336 CHECK( 0x00, buf[142]); /* 2^40 <= v < 2^41 => biaised exponent on 11 bits: 1023 + 40: 100 0010 0111 */ | |
1337 CHECK( 0x00, buf[143]); /* significand: 1 + 2^-40 => 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 0000 0000 0000 */ | |
1338 CHECK( 0x00, buf[144]); /* result: c2 70 00 00 00 00 10 00 */ | |
1339 CHECK( 0x00, buf[145]); | |
1340 CHECK( 0x10, buf[146]); | |
1341 CHECK( 0x00, buf[147]); | |
1342 | |
1343 | |
1344 | |
1345 /* Okay, now delete the message and parse the buffer, then check we obtain the same values back */ | |
1346 #if 0 | |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
1347 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, msg, fd_g_config->cnf_dict, 0, 1)); |
0 | 1348 #endif |
1349 CHECK( 0, fd_msg_free( msg ) ); | |
1350 | |
1351 CHECK( 0, fd_msg_parse_buffer( &buf, 148, &msg) ); | |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
35
diff
changeset
|
1352 CHECK( 0, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); |
0 | 1353 #if 0 |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1047
diff
changeset
|
1354 fd_log_debug("%s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, msg, fd_g_config->cnf_dict, 0, 1)); |
0 | 1355 #endif |
1356 | |
1357 CHECK( 0, fd_msg_browse ( msg, MSG_BRW_FIRST_CHILD, &avp, NULL) ); | |
1358 CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) ); | |
1359 CHECK( 6, avpdata->avp_value->os.len ); | |
1360 CHECK( 'w', (char)(avpdata->avp_value->os.data[0]) ); | |
1361 CHECK( 'a', (char)(avpdata->avp_value->os.data[1]) ); | |
1362 CHECK( 'd', (char)(avpdata->avp_value->os.data[4]) ); | |
1363 CHECK( '\0', (char)(avpdata->avp_value->os.data[5]) ); | |
1364 | |
1365 CHECK( 0, fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL) ); | |
1366 CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) ); | |
1367 CHECK( 0x123456, avpdata->avp_value->i32 ); | |
1368 | |
1369 CHECK( 0, fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL) ); | |
1370 CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) ); | |
1371 CHECK( -0x123456, avpdata->avp_value->i32 ); | |
1372 | |
1373 CHECK( 0, fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL) ); | |
1374 CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) ); | |
1375 CHECK( 0x11223344556677LL, avpdata->avp_value->i64 ); | |
1376 | |
1377 CHECK( 0, fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL) ); | |
1378 CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) ); | |
1379 CHECK( -0x11223344556677LL, avpdata->avp_value->i64 ); | |
1380 | |
1381 CHECK( 0, fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL) ); | |
1382 CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) ); | |
1383 CHECK( 0xFEDCBA98, avpdata->avp_value->u32 ); | |
1384 | |
1385 CHECK( 0, fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL) ); | |
1386 CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) ); | |
1387 CHECK( 0x123456789abcdef0LL, avpdata->avp_value->u64 ); | |
1388 | |
1389 CHECK( 0, fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL) ); | |
1390 CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) ); | |
1391 CHECK( 2097153.0F, avpdata->avp_value->f32 ); | |
1392 | |
1393 CHECK( 0, fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL) ); | |
1394 CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) ); | |
1395 CHECK( -1099511627777LL, avpdata->avp_value->f64 ); | |
1396 | |
1397 CHECK( 0, fd_msg_free( msg ) ); | |
1398 } | |
1399 } | |
1400 | |
1401 | |
1402 /* That's all for the tests yet */ | |
1403 PASSTEST(); | |
1404 } | |
1405 |