Navigation


Changeset 1366:9294ed1c7ac8 in freeDiameter


Ignore:
Timestamp:
Jun 9, 2019, 10:44:30 PM (5 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Phase:
public
Message:

loadtest_cc: finish

Provide all necessary AVPs. Provide statistics on exit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/loadtest_cc/loadtest_cc.c

    r1364 r1366  
    4242
    4343static pthread_t gen_thr  = (pthread_t)NULL;
    44 struct disp_hdl *ccr_handler_hdl;
     44struct disp_hdl *ccr_local_hdl;
     45struct fd_rt_fwd_hdl *ccr_fwd_hdl;
    4546volatile int do_generate = 0;
    4647
     
    4849
    4950struct dict_object * aai_avp_do; /* cache the Auth-Application-Id dictionary object */
     51struct dict_object * crn_avp_do; /* cache the CC-Request-Number dictionary object */
     52struct dict_object * crt_avp_do; /* cache the CC-Request-Type dictionary object */
    5053struct dict_object * dh_avp_do; /* cache the Destination-Host dictionary object */
    5154struct dict_object * dr_avp_do; /* cache the Destination-Realm dictionary object */
    5255struct dict_object * rc_avp_do; /* cache the Result-Code dictionary object */
     56struct dict_object * sci_avp_do; /* cache the Service-Context-Id dictionary object */
    5357struct dict_object * si_avp_do; /* cache the Session-Id dictionary object */
    5458struct dict_object * pi_avp_do; /* cache the Proxy-Info dictionary object */
     
    5660struct dict_object * ps_avp_do; /* cache the Proxy-State dictionary object */
    5761
    58 
    59 static int ccr_handler(struct msg ** msg, struct avp * avp, struct session * sess, void * data, enum disp_action * act)
    60 {
     62struct statistics {
     63        uint64_t sent;
     64        uint64_t success;
     65        uint64_t error;
     66        time_t first;
     67        time_t last;
     68} statistics;
     69
     70static int handle_message(struct msg **msg) {
    6171        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        }
    6779
    6880        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
     110static 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");
    71116                CHECK_FCT(fd_msg_free(*msg));
    72117                *msg = NULL;
     
    74119        }
    75120
    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 */
    79121        CHECK_FCT(fd_msg_free(*msg));
    80122        *msg = NULL;
     123        return 0;
     124}
     125
     126static 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
    81134        return 0;
    82135}
     
    92145        const char *realm;
    93146        const char *session_id = "fixed-session-id-for-now";
     147        const char *service_context_id = "version2.clci.ipc@vodafone.com";
    94148        const char *proxy_host = "Dummy-Proxy-Host-to-Increase-Package-Size";
    95149        const char *proxy_state = "This is just date to increase the package size\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
     
    118172                return NULL;
    119173        }
     174
    120175        /* Destination-Host */
    121176        fd_msg_avp_new(dh_avp_do, 0, &avp);
     
    148203        }
    149204        fd_msg_avp_add(msg, MSG_BRW_LAST_CHILD, avp);
     205
    150206        /* Session-Id */
    151207        fd_msg_avp_new(si_avp_do, 0, &avp);
     
    159215        }
    160216        fd_msg_avp_add(msg, MSG_BRW_FIRST_CHILD, avp);
     217
    161218        /* Auth-Application-Id */
    162219        fd_msg_avp_new(aai_avp_do, 0, &avp);
     
    166223                fd_msg_free(msg);
    167224                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");
    168259                return NULL;
    169260        }
     
    207298        do {
    208299                if (do_generate) {
     300                        if (statistics.first == 0) {
     301                                statistics.first = time(NULL);
     302                        }
     303                        msg = create_message(target);
    209304                        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++;
    212308                } else {
    213309                        sleep(1);
     
    243339        CHECK_FCT( fd_disp_app_support ( data.app, NULL, 1, 0 ) );
    244340
    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));
    248349
    249350        CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Application-Id", &aai_avp_do, ENOENT),
    250351                     { 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."); });
    251357        CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Host", &dh_avp_do, ENOENT),
    252358                     { LOG_E("Unable to find 'Destination-Host' AVP in the loaded dictionaries."); });
     
    257363        CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &si_avp_do, ENOENT),
    258364                     { 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."); });
    259367        CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Proxy-Info", &pi_avp_do, ENOENT),
    260368                     { LOG_E("Unable to find 'Proxy-Info' AVP in the loaded dictionaries."); });
     
    276384void fd_ext_fini(void)
    277385{
     386        uint64_t missing;
    278387        /* stop sending */
    279388        do_generate = 0;
     
    283392
    284393        /* 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);
    289406
    290407        return;
Note: See TracChangeset for help on using the changeset viewer.