Changeset 1366:9294ed1c7ac8 in freeDiameter
- Timestamp:
- Jun 9, 2019, 10:44:30 PM (5 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/loadtest_cc/loadtest_cc.c
r1364 r1366 42 42 43 43 static pthread_t gen_thr = (pthread_t)NULL; 44 struct disp_hdl *ccr_handler_hdl; 44 struct disp_hdl *ccr_local_hdl; 45 struct fd_rt_fwd_hdl *ccr_fwd_hdl; 45 46 volatile int do_generate = 0; 46 47 … … 48 49 49 50 struct dict_object * aai_avp_do; /* cache the Auth-Application-Id dictionary object */ 51 struct dict_object * crn_avp_do; /* cache the CC-Request-Number dictionary object */ 52 struct dict_object * crt_avp_do; /* cache the CC-Request-Type dictionary object */ 50 53 struct dict_object * dh_avp_do; /* cache the Destination-Host dictionary object */ 51 54 struct dict_object * dr_avp_do; /* cache the Destination-Realm dictionary object */ 52 55 struct dict_object * rc_avp_do; /* cache the Result-Code dictionary object */ 56 struct dict_object * sci_avp_do; /* cache the Service-Context-Id dictionary object */ 53 57 struct dict_object * si_avp_do; /* cache the Session-Id dictionary object */ 54 58 struct dict_object * pi_avp_do; /* cache the Proxy-Info dictionary object */ … … 56 60 struct dict_object * ps_avp_do; /* cache the Proxy-State dictionary object */ 57 61 58 59 static int ccr_handler(struct msg ** msg, struct avp * avp, struct session * sess, void * data, enum disp_action * act) 60 { 62 struct statistics { 63 uint64_t sent; 64 uint64_t success; 65 uint64_t error; 66 time_t first; 67 time_t last; 68 } statistics; 69 70 static int handle_message(struct msg **msg) { 61 71 struct msg_hdr *hdr = NULL; 62 63 TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act); 64 65 if (msg == NULL) 66 return EINVAL; 72 struct avp_hdr *ahdr = NULL; 73 struct avp *rc; 74 75 if (msg == NULL) { 76 fd_log_error("[%s] NULL CCA message", MODULE_NAME); 77 return -1; 78 } 67 79 68 80 CHECK_FCT(fd_msg_hdr(*msg, &hdr)); 69 if (hdr->msg_flags & CMD_FLAG_REQUEST) { 70 fd_log_error("received Credit-Control-Request, dropping it"); 81 /* handle CCAs only */ 82 if ((hdr->msg_code != 272) || (hdr->msg_flags & CMD_FLAG_REQUEST)) { 83 fd_log_error("[%s] invalid message type (type %d, flags 0x%x)", MODULE_NAME, hdr->msg_code, hdr->msg_flags); 84 return -1; 85 } 86 87 /* Answer received, check it */ 88 if (fd_msg_search_avp(*msg, rc_avp_do, &rc) < 0 || rc == NULL) { 89 fd_log_error("[%s] Result-Code not found in CCA", MODULE_NAME); 90 return -1; 91 } 92 93 if (fd_msg_avp_hdr(rc, &ahdr) < 0) { 94 fd_log_error("[%s] error parsing Result-Code in CCA", MODULE_NAME); 95 return -1; 96 } 97 fd_log_debug("Credit-Control-Answer with Result-Code %d received", ahdr->avp_value->i32); 98 switch (ahdr->avp_value->i32/1000) { 99 case 2: 100 statistics.success++; 101 break; 102 default: 103 statistics.error++; 104 break; 105 } 106 107 return 0; 108 } 109 110 static int ccr_local_handler(struct msg ** msg, struct avp * avp, struct session * sess, void * data, enum disp_action * act) 111 { 112 fd_log_debug("[%s] CCR local handler called", MODULE_NAME); 113 114 if (handle_message(msg) < 0) { 115 fd_log_error("dropping message"); 71 116 CHECK_FCT(fd_msg_free(*msg)); 72 117 *msg = NULL; … … 74 119 } 75 120 76 /* Answer received, check it */77 fd_log_notice("Credit-Control-Answer received, this code should do something about it but doesn't yet");78 /* TODO */79 121 CHECK_FCT(fd_msg_free(*msg)); 80 122 *msg = NULL; 123 return 0; 124 } 125 126 static int ccr_fwd_handler(void *cb_data, struct msg **msg) 127 { 128 fd_log_debug("[%s] CCR FWD handler called", MODULE_NAME); 129 130 if (handle_message(msg) < 0) { 131 return 0; 132 } 133 81 134 return 0; 82 135 } … … 92 145 const char *realm; 93 146 const char *session_id = "fixed-session-id-for-now"; 147 const char *service_context_id = "version2.clci.ipc@vodafone.com"; 94 148 const char *proxy_host = "Dummy-Proxy-Host-to-Increase-Package-Size"; 95 149 const char *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XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; … … 118 172 return NULL; 119 173 } 174 120 175 /* Destination-Host */ 121 176 fd_msg_avp_new(dh_avp_do, 0, &avp); … … 148 203 } 149 204 fd_msg_avp_add(msg, MSG_BRW_LAST_CHILD, avp); 205 150 206 /* Session-Id */ 151 207 fd_msg_avp_new(si_avp_do, 0, &avp); … … 159 215 } 160 216 fd_msg_avp_add(msg, MSG_BRW_FIRST_CHILD, avp); 217 161 218 /* Auth-Application-Id */ 162 219 fd_msg_avp_new(aai_avp_do, 0, &avp); … … 166 223 fd_msg_free(msg); 167 224 fd_log_error("can't set value for 'Auth-Application-Id' for 'Credit-Control-Request' message"); 225 return NULL; 226 } 227 fd_msg_avp_add(msg, MSG_BRW_LAST_CHILD, avp); 228 229 /* Service-Context-Id */ 230 fd_msg_avp_new(sci_avp_do, 0, &avp); 231 memset(&val, 0, sizeof(val)); 232 val.os.data = (uint8_t *)service_context_id; 233 val.os.len = strlen(service_context_id); 234 if (fd_msg_avp_setvalue(avp, &val) != 0) { 235 fd_msg_free(msg); 236 fd_log_error("can't set value for 'Service-Context-Id' for 'Credit-Control-Request' message"); 237 return NULL; 238 } 239 fd_msg_avp_add(msg, MSG_BRW_LAST_CHILD, avp); 240 241 /* CC-Request-Type */ 242 fd_msg_avp_new(crt_avp_do, 0, &avp); 243 memset(&val, 0, sizeof(val)); 244 val.i32 = 1; /* Initial */ 245 if (fd_msg_avp_setvalue(avp, &val) != 0) { 246 fd_msg_free(msg); 247 fd_log_error("can't set value for 'CC-Request-Type' for 'Credit-Control-Request' message"); 248 return NULL; 249 } 250 fd_msg_avp_add(msg, MSG_BRW_LAST_CHILD, avp); 251 252 /* CC-Request-Number */ 253 fd_msg_avp_new(crn_avp_do, 0, &avp); 254 memset(&val, 0, sizeof(val)); 255 val.i32 = 1; 256 if (fd_msg_avp_setvalue(avp, &val) != 0) { 257 fd_msg_free(msg); 258 fd_log_error("can't set value for 'CC-Request-Number' for 'Credit-Control-Request' message"); 168 259 return NULL; 169 260 } … … 207 298 do { 208 299 if (do_generate) { 300 if (statistics.first == 0) { 301 statistics.first = time(NULL); 302 } 303 msg = create_message(target); 209 304 fd_msg_send(&msg, NULL, NULL); 210 fd_log_notice("sent message"); 211 sleep(1); 305 fd_log_debug("[%s] sent message", MODULE_NAME); 306 statistics.last = time(NULL); 307 statistics.sent++; 212 308 } else { 213 309 sleep(1); … … 243 339 CHECK_FCT( fd_disp_app_support ( data.app, NULL, 1, 0 ) ); 244 340 245 /* register handler for CCR */ 246 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Credit-Control-Request", &data.command, ENOENT) ); 247 CHECK_FCT( fd_disp_register( ccr_handler, DISP_HOW_CC, &data, NULL, &ccr_handler_hdl ) ); 341 /* the handling of requests is different if it might be locally handled or not */ 342 /* for possibly locally handled requests, fd_rt_fwd_register is not called, so we need to add handlers for both cases */ 343 /* register forward handler for CCR -- needs to look at all requests */ 344 CHECK_FCT(fd_rt_fwd_register(ccr_fwd_handler, NULL, RT_FWD_REQ, &ccr_fwd_hdl)); 345 /* register local handler for CCR - if not Destination-Host is set, or the local host is used */ 346 memset(&data, 0, sizeof(data)); 347 CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Credit-Control-Answer", &data.command, ENOENT)); 348 CHECK_FCT(fd_disp_register(ccr_local_handler, DISP_HOW_CC, &data, NULL, &ccr_local_hdl)); 248 349 249 350 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Application-Id", &aai_avp_do, ENOENT), 250 351 { LOG_E("Unable to find 'Auth-Application-Id' AVP in the loaded dictionaries."); }); 352 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "CC-Request-Number", &crn_avp_do, ENOENT), 353 { LOG_E("Unable to find 'CC-Request-Number' AVP in the loaded dictionaries."); }); 354 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "CC-Request-Type", &crt_avp_do, ENOENT), 355 356 { LOG_E("Unable to find 'CC-Request-Type' AVP in the loaded dictionaries."); }); 251 357 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Host", &dh_avp_do, ENOENT), 252 358 { LOG_E("Unable to find 'Destination-Host' AVP in the loaded dictionaries."); }); … … 257 363 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &si_avp_do, ENOENT), 258 364 { LOG_E("Unable to find 'Session-Id' AVP in the loaded dictionaries."); }); 365 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Service-Context-Id", &sci_avp_do, ENOENT), 366 { LOG_E("Unable to find 'Service-Context-Id' AVP in the loaded dictionaries."); }); 259 367 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Proxy-Info", &pi_avp_do, ENOENT), 260 368 { LOG_E("Unable to find 'Proxy-Info' AVP in the loaded dictionaries."); }); … … 276 384 void fd_ext_fini(void) 277 385 { 386 uint64_t missing; 278 387 /* stop sending */ 279 388 do_generate = 0; … … 283 392 284 393 /* Unregister the callbacks */ 285 if (ccr_handler_hdl) { 286 CHECK_FCT_DO( fd_disp_unregister(&ccr_handler_hdl, NULL), ); 287 ccr_handler_hdl = NULL; 288 } 394 if (ccr_local_hdl) { 395 CHECK_FCT_DO( fd_disp_unregister(&ccr_local_hdl, NULL), ); 396 ccr_local_hdl = NULL; 397 } 398 399 missing = statistics.sent - statistics.error - statistics.success; 400 401 fd_log_error("%lld messages sent in %llds (%.2f messages/second), %lld success (%.2f%%), %lld errors (%.2f%%), %lld missing (%.2f%%)", 402 (long long)statistics.sent, (long long)(statistics.last-statistics.first), (float)statistics.sent / (statistics.last-statistics.first), 403 (long long)statistics.success, 404 100*(float)statistics.success/statistics.sent, (long long)statistics.error, 100*(float)statistics.error/statistics.sent, 405 missing, 100*(float)missing/statistics.sent); 289 406 290 407 return;
Note: See TracChangeset
for help on using the changeset viewer.