Merge branch 'nsg-4.3' of git.sangoma.com:smg_freeswitch into nsg-4.3

This commit is contained in:
Mathieu Rene
2012-06-20 12:31:07 -04:00
18 changed files with 757 additions and 252 deletions
@@ -0,0 +1,50 @@
<configuration name="media_gateway.conf" description="Media Gateway Configuration">
<mg_profiles>
<mg_profile name="profile-1">
<param name="protocol" value="MEGACO"/>
<param name="local-ip" value="192.168.1.50"/>
<param name="port" value="2944" />
<param name="domain-name" value="lab.sangoma.com" />
<param name="message-identifier" value="<mg.sangoma.com>" />
<param name="version" value="3"/>
<param name="default-codec" value="PCMA"/>
<param name="rtp-port-range" value="5000-6000"/>
<param name="rtp-termination-id-prefix" value="TermRtp"/>
<param name="rtp-termination-id-len" value="4"/> <!-- /* Allowed values = any digit from 0 to 9 */ -->
<physical_terminations>
<map termination-id-prefix="Term1/" termination-id-base="1" tech="freetdm" channel-prefix="wp2" channel-map="1-15,17-31"/>
<map termination-id-prefix="Term2/" termination-id-base="1" tech="freetdm" channel-prefix="wp3" channel-map="1-31"/>
</physical_terminations>
<peers>
<param name="peer" value = "peer-1" />
<param name="peer" value = "peer-2" />
<param name="peer" value = "peer-3" />
</peers>
</mg_profile>
</mg_profiles>
<mg_peers>
<mg_peer name="peer-1">
<param name="ip" value="192.168.1.49"/>
<param name="port" value="2944"/>
<param name="encoding-scheme" value="TEXT"/>
<param name="transport-type" value="UDP"/>
<param name="message-identifier" value="<remote1.mgc.com>" />
</mg_peer>
<mg_peer name="peer-2">
<param name="ip" value="192.168.1.55"/>
<param name="port" value="2944"/>
<param name="encoding-scheme" value="BINARY"/>
<param name="transport-type" value="UDP"/>
<param name="message-identifier" value="<remote2.mgc.com>" />
</mg_peer>
<mg_peer name="peer-3">
<param name="ip" value="192.168.1.44"/>
<param name="port" value="2944"/>
<param name="transport-type" value="UDP"/>
<param name="encoding-scheme" value="TEXT"/>
<param name="message-identifier" value="<remote3.mgc.com>" />
</mg_peer>
</mg_peers>
</configuration>
@@ -99,12 +99,35 @@ switch_status_t mg_process_cli_cmd(const char *cmd, switch_stream_handle_t *stre
/**********************************************************************************/
goto usage;
}
/**********************************************************************************/
}else if (!strcmp(argv[0], "logging")) {
/**********************************************************************************/
if (zstr(argv[1])) {
goto usage;
}
/******************************************************************/
if(!strcasecmp(argv[1], "enable")){
mg_enable_logging();
/******************************************************************/
}else if(!strcasecmp(argv[1], "disable")){
/******************************************************************/
mg_disable_logging();
/******************************************************************/
} else {
/******************************************************************/
goto usage;
}
/**********************************************************************************/
}else {
/**********************************************************************************/
goto usage;
}
/**********************************************************************************/
goto done;
usage:
stream->write_function(stream, "-ERR Usage: "MEGACO_FUNCTION_SYNTAX"\n");
stream->write_function(stream, "-ERR Usage: \n""\t"MEGACO_CLI_SYNTAX" \n \t"MEGACO_FUNCTION_SYNTAX"\n \t" MEGACO_LOGGING_CLI_SYNTAX "\n");
done:
switch_safe_free(dup);
@@ -19,7 +19,6 @@ int mgco_mu_gen_config(void);
int mgco_tucl_gen_config(void);
int mgco_mu_ssap_config(int idx);
int mgco_mg_tsap_config(megaco_profile_t* profile);
int mgco_mg_enble_debug(void);
int mgco_mg_ssap_config(megaco_profile_t* profile);
int mgco_mg_peer_config(megaco_profile_t* profile);
int mgco_mg_tpt_server_config(megaco_profile_t* profile);
@@ -97,6 +96,9 @@ switch_status_t sng_mgco_init(sng_mg_event_interface_t* event)
/*****************************************************************************************************************/
switch_status_t sng_mgco_stack_shutdown()
{
/* disable MG logging */
mg_disable_logging();
/* shutdown MG */
sng_mgco_mg_shutdown();
@@ -255,6 +257,8 @@ switch_status_t sng_mgco_start(megaco_profile_t* profile )
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " mgco_mg_tsap_enable_cntrl SUCCESS \n");
}
mgco_mg_enble_debug();
return SWITCH_STATUS_SUCCESS;
}
@@ -571,7 +575,7 @@ int mgco_mg_ssap_cntrl(int idx)
}
/******************************************************************************/
int mgco_mg_enble_debug()
int mg_enable_logging()
{
MgMngmt mgMngmt;
Pst pst; /* Post for layer manager */
@@ -597,6 +601,33 @@ int mgco_mg_enble_debug()
return(sng_cntrl_mg(&pst, &mgMngmt));
}
/******************************************************************************/
int mg_disable_logging()
{
MgMngmt mgMngmt;
Pst pst; /* Post for layer manager */
MgCntrl* cntrl;
memset(&mgMngmt, 0, sizeof(mgMngmt));
cntrl = &mgMngmt.t.cntrl;
/* initalize the post structure */
smPstInit(&pst);
/* insert the destination Entity */
pst.dstEnt = ENTMG;
mgMngmt.hdr.msgType = TCFG;
mgMngmt.hdr.entId.ent = ENTHI;
mgMngmt.hdr.entId.inst = S_INST;
mgMngmt.hdr.elmId.elmnt = STGEN;
cntrl->action = ADISIMM;
cntrl->subAction = SADBG;
cntrl->s.dbg.genDbgMask = 0xfffffdff;
return(sng_cntrl_mg(&pst, &mgMngmt));
}
/******************************************************************************/
int mgco_tucl_gen_config(void)
{
@@ -1230,7 +1261,7 @@ int sng_mgco_mg_get_status(int elemId, MgMngmt* cfm, megaco_profile_t* mg_cfg,
case STSERVER:
{
cntrl.t.ssta.s.mgTptSrvSta.tptAddr.type = CM_INET_IPV4ADDR_TYPE;
cntrl.t.ssta.s.mgTptSrvSta.tptAddr.u.ipv4TptAddr.port = ntohl(ipAddr);
cntrl.t.ssta.s.mgTptSrvSta.tptAddr.u.ipv4TptAddr.port = atoi(mg_cfg->port);
if(ROK == cmInetAddr((S8*)mg_cfg->my_ipaddr, &ipAddr))
{
cntrl.t.ssta.s.mgTptSrvSta.tptAddr.u.ipv4TptAddr.address = ntohl(ipAddr);
@@ -53,6 +53,8 @@ void handle_mgco_txn_ind(Pst *pst, SuId suId, MgMgcoMsg* msg);
void handle_mgco_audit_cfm(Pst *pst, SuId suId, MgMgtAudit* audit, Reason reason);
void handle_mg_alarm(Pst *pst, MgMngmt *sta);
void handle_tucl_alarm(Pst *pst, HiMngmt *sta);
int mg_enable_logging(void);
int mg_disable_logging(void);
switch_status_t sng_mgco_cfg(megaco_profile_t* profile);
@@ -12,6 +12,7 @@
static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) ;
static switch_xml_config_item_t *get_peer_instructions(mg_peer_profile_t *profile) ;
static int mg_sap_id;
static switch_status_t modify_mid(char* mid);
/****************************************************************************************************************************/
switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
@@ -19,7 +20,7 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
switch_xml_t cfg, xml, param, mg_interfaces, mg_interface, mg_peers, mg_peer, peer_interfaces ;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_event_t *event = NULL;
const char *file = "megaco.conf";
const char *file = "media_gateway.conf";
switch_xml_config_item_t *instructions = (profile ? get_instructions(profile) : NULL);
int count;
int idx;
@@ -57,12 +58,21 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
profile->total_peers++;
}
if(SWITCH_STATUS_FALSE == (status = modify_mid(profile->mid))){
goto done;
}
profile->idx = ++mg_sap_id;
/* we should break from here , profile name should be unique */
break;
}
if (!mg_interface) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error profile %s not found\n", profile->name);
return SWITCH_STATUS_FALSE;
}
/* go through the peer configuration and get the mg profile associated peers only */
if (!(mg_peers = switch_xml_child(cfg, "mg_peers"))) {
goto done;
@@ -87,6 +97,10 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
goto done;
}
if(SWITCH_STATUS_FALSE == (status = modify_mid(peer_profile->mid))){
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,"peer_profile name[%s], ipaddr[%s] port[%s], mid[%s] transport_type[%s], encoding_type[%s] \n",
peer_profile->name, peer_profile->ipaddr, peer_profile->port,peer_profile->mid, peer_profile->transport_type, peer_profile->encoding_type);
@@ -144,10 +158,25 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) {
static switch_xml_config_int_options_t opt_version = {
SWITCH_TRUE, /* enforce min */
1,
SWITCH_TRUE, /* Enforce Max */
SWITCH_TRUE, /* enforce Max */
3
};
static switch_xml_config_int_options_t opt_termination_id_len = {
SWITCH_TRUE, /* enforce min */
1,
SWITCH_TRUE, /* enforce Max */
9
};
static switch_xml_config_enum_item_t opt_default_codec_enum[] = {
{ "PCMA", MEGACO_CODEC_PCMA},
{ "PCMU", MEGACO_CODEC_PCMU},
{ "G.729", MEGACO_CODEC_G729},
{ "G.723.1", MEGACO_CODEC_G723_1},
{ "ILBC", MEGACO_CODEC_ILBC },
};
switch_xml_config_item_t instructions[] = {
/* parameter name type reloadable pointer default value options structure */
SWITCH_CONFIG_ITEM("protocol", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->protocol_type, "MEGACO", &switch_config_string_strdup, "", "MG Protocol type"),
@@ -156,6 +185,11 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) {
SWITCH_CONFIG_ITEM("port", SWITCH_CONFIG_STRING, 0, &profile->port, "2944", &switch_config_string_strdup, "", "port"),
SWITCH_CONFIG_ITEM("domain-name", SWITCH_CONFIG_STRING, 0, &profile->my_domain, "", &switch_config_string_strdup, "", "domain name"),
SWITCH_CONFIG_ITEM("message-identifier", SWITCH_CONFIG_STRING, 0, &profile->mid, "", &switch_config_string_strdup, "", "message identifier "),
SWITCH_CONFIG_ITEM("default-codec", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &profile->default_codec, "PCMU", &opt_default_codec_enum, "", "default codec"),
SWITCH_CONFIG_ITEM("rtp-port-range", SWITCH_CONFIG_STRING, CONFIG_REQUIRED, &profile->rtp_port_range, "1-65535", &switch_config_string_strdup, "", "rtp port range"),
SWITCH_CONFIG_ITEM("rtp-termination-id-prefix", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->rtp_termination_id_prefix, "", &switch_config_string_strdup, "", "rtp termination prefix"),
SWITCH_CONFIG_ITEM("rtp-termination-id-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &profile->rtp_termination_id_len, "", &opt_termination_id_len, "", "rtp termination id"),
SWITCH_CONFIG_ITEM_END()
};
@@ -165,3 +199,54 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) {
}
/****************************************************************************************************************************/
static switch_status_t modify_mid(char* mid)
{
char* dup = NULL;
char* val[10];
int count;
switch_assert(mid);
/* If MID type is IP then add mid into [] brackets ,
* If MID type is domain then add mid into <> brackets *
*/
dup = strdup(mid);
count = switch_split(dup, '.', val);
if(!count) {
/* Input string is not separated by '.', check if its separated by '-' as format could be xxx-xx-xxx/xxx-xx-xx-xxx */
free(dup);
dup = strdup(mid);
if(0 == (count = switch_split(dup, '-', val))){
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
return SWITCH_STATUS_FALSE;
}
}
if(('<' == val[0][0]) || ('[' == val[0][0])){
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MID[%s] is already prefixed with proper brackets \n",mid);
return SWITCH_STATUS_SUCCESS;
}
/*first check could be if count is 3 means domain name as generally we have xxx-xx-xxx/xxx.xx.xxx domain */
if(3 == count){
/* domain-type, add value into <> */
free(dup);
dup = strdup(mid);
sprintf(mid,"<%s>",dup);
}else if(4 == count){
/* IP address in xxx.xxx.xxx.xxx format */
free(dup);
dup = strdup(mid);
sprintf(mid,"[%s]",dup);
}else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
return SWITCH_STATUS_FALSE;
}
free(dup);
return SWITCH_STATUS_SUCCESS;
}
@@ -66,14 +66,16 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_media_gateway_load)
switch_core_hash_init(&megaco_globals.peer_profile_hash, pool);
switch_thread_rwlock_create(&megaco_globals.peer_profile_rwlock, pool);
SWITCH_ADD_API(api_interface, "megaco", "megaco", megaco_function, MEGACO_FUNCTION_SYNTAX);
SWITCH_ADD_API(api_interface, "mg", "media_gateway", megaco_function, MEGACO_FUNCTION_SYNTAX);
switch_console_set_complete("add megaco profile ::megaco::list_profiles start");
switch_console_set_complete("add megaco profile ::megaco::list_profiles stop");
switch_console_set_complete("add megaco profile ::megaco::list_profiles status");
switch_console_set_complete("add megaco profile ::megaco::list_profiles xmlstatus");
switch_console_set_complete("add megaco profile ::megaco::list_profiles peerxmlstatus");
switch_console_add_complete_func("::megaco::list_profiles", list_profiles);
switch_console_set_complete("add mg profile ::mg::list_profiles start");
switch_console_set_complete("add mg profile ::mg::list_profiles stop");
switch_console_set_complete("add mg profile ::mg::list_profiles status");
switch_console_set_complete("add mg profile ::mg::list_profiles xmlstatus");
switch_console_set_complete("add mg profile ::mg::list_profiles peerxmlstatus");
switch_console_set_complete("add mg logging ::mg::list_profiles enable");
switch_console_set_complete("add mg logging ::mg::list_profiles disable");
switch_console_add_complete_func("::mg::list_profiles", list_profiles);
/* Initialize MEGACO Stack */
@@ -116,14 +118,14 @@ void handle_sng_log(uint8_t level, char *fmt, ...)
case SNG_LOGLEVEL_DEBUG: log_level = SWITCH_LOG_DEBUG; break;
case SNG_LOGLEVEL_INFO: log_level = SWITCH_LOG_INFO; break;
case SNG_LOGLEVEL_WARN: log_level = SWITCH_LOG_WARNING; break;
case SNG_LOGLEVEL_ERROR: log_level = SWITCH_LOG_ERROR; break;
case SNG_LOGLEVEL_ERROR: log_level = SWITCH_LOG_DEBUG; break;
case SNG_LOGLEVEL_CRIT: log_level = SWITCH_LOG_CRIT; break;
default: log_level = SWITCH_LOG_DEBUG; break;
};
vsprintf(&print_buf[0], fmt, ptr);
switch_log_printf(SWITCH_CHANNEL_LOG, log_level, " MOD_MEGACO: %s \n", &print_buf[0]);
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, log_level, " MOD_MEGACO: %s \n", &print_buf[0]);
va_end(ptr);
}
@@ -15,6 +15,8 @@
#define MG_MAX_PEERS 5
#define MEGACO_CLI_SYNTAX "profile|logging"
#define MEGACO_LOGGING_CLI_SYNTAX "logging [enable|disable]"
#define MEGACO_FUNCTION_SYNTAX "profile [name] [start | stop] [status] [xmlstatus] [peerxmlstatus]"
struct megaco_globals {
@@ -30,6 +32,14 @@ typedef enum {
PF_RUNNING = (1 << 0)
} megaco_profile_flags_t;
typedef enum {
MEGACO_CODEC_PCMA,
MEGACO_CODEC_PCMU,
MEGACO_CODEC_G729,
MEGACO_CODEC_G723_1,
MEGACO_CODEC_ILBC,
} megaco_codec_t;
typedef struct mg_peer_profile_s{
char *name;
switch_memory_pool_t *pool;
@@ -45,18 +55,22 @@ typedef struct mg_peer_profile_s{
typedef struct megaco_profile_s {
char *name;
switch_memory_pool_t *pool;
switch_thread_rwlock_t *rwlock; /* < Reference counting rwlock */
megaco_profile_flags_t flags;
int idx; /* Trillium MEGACO SAP identification*/
char* mid; /* MG H.248 MID */
char* my_domain; /* local domain name */
char* my_ipaddr; /* local domain name */
char* port; /* port */
char* protocol_type; /* MEGACO/MGCP */
int protocol_version; /* Protocol supported version */
int total_peers;
char* peer_list[MG_MAX_PEERS]; /* MGC Peer ID LIST */
switch_memory_pool_t *pool;
switch_thread_rwlock_t *rwlock; /* < Reference counting rwlock */
megaco_profile_flags_t flags;
int idx; /* Trillium MEGACO SAP identification*/
char* mid; /* MG H.248 MID */
char* my_domain; /* local domain name */
char* my_ipaddr; /* local domain name */
char* port; /* port */
char* protocol_type; /* MEGACO/MGCP */
int protocol_version; /* Protocol supported version */
int total_peers;
megaco_codec_t default_codec;
char* rtp_port_range;
char* rtp_termination_id_prefix;
int rtp_termination_id_len;
char* peer_list[MG_MAX_PEERS]; /* MGC Peer ID LIST */
} megaco_profile_t;