From 3424380630837171c50e4161e75fda0ddeaa39c0 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Mon, 27 Aug 2012 10:12:14 -0400 Subject: [PATCH] fixing minor issues observed during load testing --- .../mod_media_gateway/media_gateway_cli.c | 19 ++++++++++++- .../media_gateway_cmd_handler.c | 28 +++++++++++++------ .../mod_media_gateway/media_gateway_utils.c | 12 ++++++-- .../mod_media_gateway/mod_media_gateway.c | 2 +- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cli.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cli.c index 3a740a6f25..dff9da3294 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cli.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cli.c @@ -21,6 +21,7 @@ void get_peer_xml_buffer(char* prntBuf, MgPeerSta* cfm); void megaco_cli_print_usage(switch_stream_handle_t *stream); switch_status_t handle_show_activecalls_cli_cmd(switch_stream_handle_t *stream, megaco_profile_t* mg_profile); switch_status_t handle_show_stats(switch_stream_handle_t *stream, megaco_profile_t* mg_profile); +switch_status_t handle_show_stack_mem(switch_stream_handle_t *stream); /******************************************************************************/ @@ -194,6 +195,7 @@ switch_status_t mg_process_cli_cmd(const char *cmd, switch_stream_handle_t *stre }else if (!strcmp(argv[2], "show")) { /**********************************************************************************/ /* mg show activecalls*/ + if(zstr(argv[3])) { goto usage; } @@ -228,7 +230,7 @@ switch_status_t mg_process_cli_cmd(const char *cmd, switch_stream_handle_t *stre }else if(!strcasecmp(argv[3], "stackmem")){ /*******************************************************************/ megaco_profile_release(profile); - sng_mg_reg_info_show(); + handle_show_stack_mem(stream); /*******************************************************************/ #ifdef LEAK_TEST }else if(!strcasecmp(argv[3], "leak-report")){ @@ -305,6 +307,7 @@ void megaco_cli_print_usage(switch_stream_handle_t *stream) stream->write_function(stream, "mg profile show termstatus \n"); stream->write_function(stream, "mg profile show alltermstatus \n"); stream->write_function(stream, "mg profile show stackmem \n"); + stream->write_function(stream, "mg profile show stats \n"); stream->write_function(stream, "Usage: Logging \n"); stream->write_function(stream, "mg logging enable \n"); @@ -913,6 +916,20 @@ switch_status_t handle_show_stats(switch_stream_handle_t *stream, megaco_profile + return SWITCH_STATUS_SUCCESS; +} +/******************************************************************************/ +switch_status_t handle_show_stack_mem(switch_stream_handle_t *stream) +{ + U32 availMem = 0; + char buffer[4098]; + + memset(buffer,0,sizeof(buffer)); + + SGetMemInfoBuffer(S_REG, &availMem, buffer); + + stream->write_function(stream, "%s",buffer); + return SWITCH_STATUS_SUCCESS; } /******************************************************************************/ diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index 17a0f01527..0cf98ed137 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -595,16 +595,19 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i mg_context_t* mg_ctxt; int mediaId; MgMgcoLocalDesc *local = NULL; + char term_name[128]; /*CmSdpInfoSet *psdp = NULL;*/ - /* TODO - Kapil dummy line , will need to add with proper code */ + memset(&term_name,0,sizeof(term_name)); + inc_med_desc = &cmd->dl.descs[0]->u.media; /********************************************************************/ ctxtId = &inc_cmd->contextId; termLst = mg_get_term_id_list(inc_cmd); termId = termLst->terms[0]; - /* For Matt - termId->name.lcl.val - to get the termination id name */ + MG_MEM_COPY(&term_name, termId->name.lcl.val, sizeof(U8) * termId->name.lcl.len); + /********************************************************************/ /* Validating ADD request *******************************************/ @@ -683,13 +686,13 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i /********************************************************************/ }else{ /* Physical termination */ - term = megaco_find_termination(mg_profile, (char*)termId->name.lcl.val); + term = megaco_find_termination(mg_profile, term_name); mg_profile->mg_stats->total_num_of_phy_add_recvd++; if(NULL == term){ mg_profile->mg_stats->total_num_of_find_term_failed_error++; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, - " megaco_find_termination failed for term-id[%s] \n",(char*)termId->name.lcl.val); + " megaco_find_termination failed for term-id[%s] \n", term_name); mg_util_set_err_string(&errTxt, " Resource Failure "); err_code = MGT_MGCO_RSP_CODE_RSRC_ERROR; goto error; @@ -904,12 +907,16 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand int mediaId; /*MgMgcoAmmReq *cmd = &inc_cmd->u.mgCmdInd[0]->cmd.u.mod;*/ U32 txn_id = inc_cmd->transId.val; + char term_name[128]; + + memset(&term_name,0,sizeof(term_name)); /********************************************************************/ ctxtId = &inc_cmd->contextId; termLst = mg_get_term_id_list(inc_cmd); termId = termLst->terms[0]; - /* For Matt - termId->name.lcl.val - to get the termination id name */ + + MG_MEM_COPY(&term_name, termId->name.lcl.val, sizeof(U8) * termId->name.lcl.len); /********************************************************************/ /* Validation *******************************************/ @@ -964,7 +971,7 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand termId->name.lcl.val, ctxtId->type.val, ctxtId->val.val); #endif - term = megaco_find_termination(mg_profile, (char*)termId->name.lcl.val); + term = megaco_find_termination(mg_profile, term_name); if(NULL == term){ mg_profile->mg_stats->total_num_of_find_term_failed_error++; @@ -1200,7 +1207,9 @@ switch_status_t handle_mg_subtract_cmd(megaco_profile_t* mg_profile, MgMgcoComma mg_context_t* mg_ctxt = NULL; mg_termination_t* term = NULL; uint8_t wild = 0x00; + char term_name[128]; + memset(&term_name,0,sizeof(term_name)); wild = inc_cmd->u.mgCmdReq[0]->wild.pres; @@ -1208,6 +1217,7 @@ switch_status_t handle_mg_subtract_cmd(megaco_profile_t* mg_profile, MgMgcoComma ctxtId = &inc_cmd->contextId; termLst = mg_get_term_id_list(inc_cmd); termId = termLst->terms[0]; + MG_MEM_COPY(&term_name, termId->name.lcl.val, sizeof(U8) * termId->name.lcl.len); mg_profile->mg_stats->total_num_of_sub_recvd++; @@ -1277,14 +1287,14 @@ switch_status_t handle_mg_subtract_cmd(megaco_profile_t* mg_profile, MgMgcoComma }else if(MGT_TERMID_OTHER == termId->type.val){ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO," SUB Request for termination[%s] \n", (char*)termId->name.lcl.val); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO," SUB Request for termination[%s] \n", term_name); - term = megaco_find_termination(mg_profile, (char*)termId->name.lcl.val); + term = megaco_find_termination(mg_profile, term_name); if(NULL == term){ mg_profile->mg_stats->total_num_of_find_term_failed_error++; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, - "Subtract request Failed, no termination found for input term string[%s] \n", (char*)termId->name.lcl.val); + "Subtract request Failed, no termination found for input term string[%s] \n", term_name); mg_util_set_term_string(&errTxt,termId); err_code = MGT_MGCO_RSP_CODE_UNKNOWN_TERM_ID; goto error; diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c index 6cea2f1480..9ff581f916 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c @@ -86,12 +86,18 @@ switch_status_t mg_stack_termination_is_in_service(megaco_profile_t* mg_profile, mg_termination_t* term = NULL; term = megaco_find_termination(mg_profile, term_str); + if(term && MG_TERM_RTP == term->type) { return SWITCH_STATUS_SUCCESS; - }else if(term && (MG_TERM_TDM == term->type) && - switch_test_flag(term, MG_IN_SERVICE)){ - return SWITCH_STATUS_SUCCESS; + }else if(term && (MG_TERM_TDM == term->type)){ + if(switch_test_flag(term, MG_IN_SERVICE)){ + return SWITCH_STATUS_SUCCESS; + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " Term[%s] not in service\n", term_str); + return SWITCH_STATUS_FALSE; + } } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, " Failed to find term for term string[%s]\n", term_str); return SWITCH_STATUS_FALSE; } } diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c index d6d600f456..1306d658ba 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c @@ -556,8 +556,8 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) if ((CH_CMD_TYPE_IND == cmd->cmdType.val) && (MGT_TERMID_OTHER == termId->type.val) && (MGT_AUDITVAL != cmd->u.mgCmdInd[0]->cmd.type.val)){ - if(SWITCH_STATUS_FALSE == mg_stack_termination_is_in_service(mg_profile, (char*)termId->name.lcl.val, termId->name.lcl.len)){ MG_MEM_COPY(&prnt_buf, termId->name.lcl.val, sizeof(U8) * termId->name.lcl.len); + if(SWITCH_STATUS_FALSE == mg_stack_termination_is_in_service(mg_profile, prnt_buf, strlen(prnt_buf))){ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Termination[%s] not in service \n",(strlen(prnt_buf))?prnt_buf:"NULL"); mg_profile->mg_stats->total_num_of_term_not_in_service_error++; mg_util_set_term_string(&errTxt, termId);