From: Richard Mudgett Date: Wed, 20 Jul 2011 20:52:33 +0000 (+0000) Subject: Backport useful CLI "pri show channels" command to v1.8. X-Git-Tag: 1.8.6.0-rc1~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7394bcd281d9781d73da73effd9cd37133158dd;p=thirdparty%2Fasterisk.git Backport useful CLI "pri show channels" command to v1.8. The "pri show channels" command is useful for debuging to see if there are any stuck B channels. .......... r307964 | rmudgett | 2011-02-15 15:42:55 -0600 (Tue, 15 Feb 2011) | 9 lines Add CLI "pri show channels" command. List the current mapping of DAHDI B channels to Asterisk channel names and which calls are on hold or call-waiting. Calls on hold or call-waiting are not associated with any B channel. JIRA LIBPRI-27 JIRA SWP-2547 .......... r308205 | rmudgett | 2011-02-17 14:21:56 -0600 (Thu, 17 Feb 2011) | 1 line Add more verbage to CLI command 'pri show channels' usage. .......... r312579 | rmudgett | 2011-04-04 11:17:58 -0500 (Mon, 04 Apr 2011) | 59 lines Change also updates 'pri show channels' command with the "chan idle" column to report if a channel is available for use. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@329012 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index 65591ff13d..b94fc7faa2 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -14128,6 +14128,7 @@ static char *handle_pri_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_a } #endif /* defined(HAVE_PRI) */ +#if defined(HAVE_PRI) #if defined(HAVE_PRI_SERVICE_MESSAGES) static char *handle_pri_service_generic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a, int changestatus) { @@ -14271,6 +14272,39 @@ static char *handle_pri_service_disable_channel(struct ast_cli_entry *e, int cmd return handle_pri_service_generic(e, cmd, a, 2); } #endif /* defined(HAVE_PRI_SERVICE_MESSAGES) */ +#endif /* defined(HAVE_PRI) */ + +#if defined(HAVE_PRI) +static char *handle_pri_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + int span; + + switch (cmd) { + case CLI_INIT: + e->command = "pri show channels"; + e->usage = + "Usage: pri show channels\n" + " Displays PRI channel information such as the current mapping\n" + " of DAHDI B channels to Asterisk channel names and which calls\n" + " are on hold or call-waiting. Calls on hold or call-waiting\n" + " are not associated with any B channel.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc != 3) + return CLI_SHOWUSAGE; + + sig_pri_cli_show_channels_header(a->fd); + for (span = 0; span < NUM_SPANS; ++span) { + if (pris[span].pri.pri) { + sig_pri_cli_show_channels(a->fd, &pris[span].pri); + } + } + return CLI_SUCCESS; +} +#endif /* defined(HAVE_PRI) */ #if defined(HAVE_PRI) static char *handle_pri_show_spans(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) @@ -14282,7 +14316,7 @@ static char *handle_pri_show_spans(struct ast_cli_entry *e, int cmd, struct ast_ e->command = "pri show spans"; e->usage = "Usage: pri show spans\n" - " Displays PRI Information\n"; + " Displays PRI span information\n"; return NULL; case CLI_GENERATE: return NULL; @@ -14403,8 +14437,9 @@ static struct ast_cli_entry dahdi_pri_cli[] = { AST_CLI_DEFINE(handle_pri_service_enable_channel, "Return a channel to service"), AST_CLI_DEFINE(handle_pri_service_disable_channel, "Remove a channel from service"), #endif /* defined(HAVE_PRI_SERVICE_MESSAGES) */ - AST_CLI_DEFINE(handle_pri_show_spans, "Displays PRI Information"), - AST_CLI_DEFINE(handle_pri_show_span, "Displays PRI Information"), + AST_CLI_DEFINE(handle_pri_show_channels, "Displays PRI channel information"), + AST_CLI_DEFINE(handle_pri_show_spans, "Displays PRI span information"), + AST_CLI_DEFINE(handle_pri_show_span, "Displays PRI span information"), AST_CLI_DEFINE(handle_pri_show_debug, "Displays current PRI debug settings"), AST_CLI_DEFINE(handle_pri_set_debug_file, "Sends PRI debug output to the specified file"), AST_CLI_DEFINE(handle_pri_version, "Displays libpri version"), @@ -14995,7 +15030,7 @@ static char *dahdi_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cl } break; default: - ; + break; } } if (tmp->channel > 0) { diff --git a/channels/sig_pri.c b/channels/sig_pri.c index b610edff78..0aa613271d 100644 --- a/channels/sig_pri.c +++ b/channels/sig_pri.c @@ -124,6 +124,25 @@ static int pri_gendigittimeout = 8000; static int pri_active_dchan_index(struct sig_pri_span *pri); +static const char *sig_pri_call_level2str(enum sig_pri_call_level level) +{ + switch (level) { + case SIG_PRI_CALL_LEVEL_IDLE: + return "Idle"; + case SIG_PRI_CALL_LEVEL_SETUP: + return "Setup"; + case SIG_PRI_CALL_LEVEL_OVERLAP: + return "Overlap"; + case SIG_PRI_CALL_LEVEL_PROCEEDING: + return "Proceeding"; + case SIG_PRI_CALL_LEVEL_ALERTING: + return "Alerting"; + case SIG_PRI_CALL_LEVEL_CONNECT: + return "Connect"; + } + return "Unknown"; +} + static inline void pri_rel(struct sig_pri_span *pri) { ast_mutex_unlock(&pri->lock); @@ -7213,8 +7232,9 @@ int sig_pri_digit_begin(struct sig_pri_chan *pvt, struct ast_channel *ast, char } if (pvt->call_level < SIG_PRI_CALL_LEVEL_CONNECT) { ast_log(LOG_WARNING, - "Span %d: Digit '%c' may be ignored by peer. (Call level:%d)\n", - pvt->pri->span, digit, pvt->call_level); + "Span %d: Digit '%c' may be ignored by peer. (Call level:%d(%s))\n", + pvt->pri->span, digit, pvt->call_level, + sig_pri_call_level2str(pvt->call_level)); } } return 1; @@ -7634,6 +7654,55 @@ void sig_pri_chan_delete(struct sig_pri_chan *doomed) ast_free(doomed); } +#define SIG_PRI_SC_HEADER "%-4s %4s %-4s %-4s %-10s %-4s %s\n" +#define SIG_PRI_SC_LINE "%4d %4d %-4s %-4s %-10s %-4s %s" +void sig_pri_cli_show_channels_header(int fd) +{ + ast_cli(fd, SIG_PRI_SC_HEADER, "PRI", "", "B", "Chan", "Call", "PRI", "Channel"); + ast_cli(fd, SIG_PRI_SC_HEADER, "Span", "Chan", "Chan", "Idle", "Level", "Call", "Name"); +} + +void sig_pri_cli_show_channels(int fd, struct sig_pri_span *pri) +{ + char line[256]; + int idx; + struct sig_pri_chan *pvt; + + ast_mutex_lock(&pri->lock); + for (idx = 0; idx < pri->numchans; ++idx) { + if (!pri->pvts[idx]) { + continue; + } + pvt = pri->pvts[idx]; + sig_pri_lock_private(pvt); + sig_pri_lock_owner(pri, idx); + if (pvt->no_b_channel && sig_pri_is_chan_available(pvt)) { + /* Don't show held/call-waiting channels if they are not in use. */ + sig_pri_unlock_private(pvt); + continue; + } + + snprintf(line, sizeof(line), SIG_PRI_SC_LINE, + pri->span, + pvt->channel, + pvt->no_b_channel ? "No" : "Yes",/* Has media */ + sig_pri_is_chan_available(pvt) ? "Yes" : "No", + sig_pri_call_level2str(pvt->call_level), + pvt->call ? "Yes" : "No", + pvt->owner ? pvt->owner->name : ""); + + if (pvt->owner) { + ast_channel_unlock(pvt->owner); + } + sig_pri_unlock_private(pvt); + + ast_mutex_unlock(&pri->lock); + ast_cli(fd, "%s\n", line); + ast_mutex_lock(&pri->lock); + } + ast_mutex_unlock(&pri->lock); +} + static void build_status(char *s, size_t len, int status, int active) { if (!s || len < 1) { diff --git a/channels/sig_pri.h b/channels/sig_pri.h index e33052f4ae..8565edfdc0 100644 --- a/channels/sig_pri.h +++ b/channels/sig_pri.h @@ -521,6 +521,8 @@ void sig_pri_chan_delete(struct sig_pri_chan *doomed); int pri_is_up(struct sig_pri_span *pri); +void sig_pri_cli_show_channels_header(int fd); +void sig_pri_cli_show_channels(int fd, struct sig_pri_span *pri); void sig_pri_cli_show_spans(int fd, int span, struct sig_pri_span *pri); void sig_pri_cli_show_span(int fd, int *dchannels, struct sig_pri_span *pri);