[Asterisk-code-review] Added ARI resource /ari/channels/{channelId}/stats (...asterisk[master])
sungtae kim
asteriskteam at digium.com
Sat Mar 2 23:00:18 CST 2019
sungtae kim has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/11083
Change subject: Added ARI resource /ari/channels/{channelId}/stats
......................................................................
Added ARI resource /ari/channels/{channelId}/stats
Added ARI resource.
GET /ari/channels/{channelId}/stats : It returns given
channel's rtp statistics details.
Change-Id: I4343eec070438cec13f2a4f22e7fd9e574381376
---
M channels/chan_pjsip.c
M include/asterisk/channel.h
M include/asterisk/rtp_engine.h
M main/rtp_engine.c
M res/ari/ari_model_validators.c
M res/ari/ari_model_validators.h
M res/ari/resource_channels.c
M res/ari/resource_channels.h
M res/res_ari_channels.c
M rest-api/api-docs/channels.json
10 files changed, 899 insertions(+), 2 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/83/11083/1
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index e44f328..ef305fa 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -103,6 +103,8 @@
static int chan_pjsip_devicestate(const char *data);
static int chan_pjsip_queryoption(struct ast_channel *ast, int option, void *data, int *datalen);
static const char *chan_pjsip_get_uniqueid(struct ast_channel *ast);
+static struct ast_json *chan_pjsip_get_rtp_stats(struct ast_channel *chan, const int type);
+
/*! \brief PBX interface structure for channel registration */
struct ast_channel_tech chan_pjsip_tech = {
@@ -128,6 +130,7 @@
.queryoption = chan_pjsip_queryoption,
.func_channel_read = pjsip_acf_channel_read,
.get_pvt_uniqueid = chan_pjsip_get_uniqueid,
+ .get_rtp_stats = chan_pjsip_get_rtp_stats,
.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER | AST_CHAN_TP_SEND_TEXT_DATA
};
@@ -1245,6 +1248,61 @@
return uniqueid;
}
+static struct ast_json *chan_pjsip_get_rtp_stats(struct ast_channel *chan, const int type)
+{
+ struct ast_json *j_res;
+ struct ast_json *j_tmp;
+ struct ast_sip_channel_pvt *cpvt;
+ struct ast_sip_session *session;
+ struct ast_sip_session_media *media;
+ int i;
+ struct ast_rtp_instance_stats *stat;
+
+ ast_channel_lock(chan);
+
+ cpvt = ast_channel_tech_pvt(chan);
+ if (!cpvt) {
+ ast_channel_unlock(chan);
+ return NULL;
+ }
+
+ session = cpvt->session;
+ if (!session) {
+ ast_channel_unlock(chan);
+ return NULL;
+ }
+
+ j_res = ast_json_array_create();
+
+ if (type == 0 || type == 1) {
+ /* current */
+ media = session->active_media_state->default_session[AST_MEDIA_TYPE_AUDIO];
+ if (media && media->rtp) {
+ j_tmp = ast_rtp_instance_get_stats_all_json(media->rtp);
+ if (j_tmp) {
+ ast_json_object_set(j_tmp, "status", ast_json_string_create("current"));
+ ast_json_array_append(j_res, j_tmp);
+ }
+ }
+ }
+
+ if (type == 0 || type == 2) {
+ /* history */
+ for (i = 0; i < AST_VECTOR_SIZE(&session->media_stats); i++) {
+ stat = AST_VECTOR_GET(&session->media_stats, i);
+ j_tmp = ast_rtp_convert_stats_json(stat);
+ if (!j_tmp) {
+ continue;
+ }
+ ast_json_object_set(j_tmp, "status", ast_json_string_create("history"));
+ ast_json_array_append(j_res, j_tmp);
+ }
+ }
+
+ ast_channel_unlock(chan);
+ return j_res;
+}
+
struct indicate_data {
struct ast_sip_session *session;
int condition;
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index e2f7959..04fe71b 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -824,6 +824,9 @@
/*! \brief Display or transmit text with data*/
int (* const send_text_data)(struct ast_channel *chan, struct ast_msg_data *data);
+
+ /*! \brief Returns json-array type of rtp stats of the given channel */
+ struct ast_json * (* get_rtp_stats)(struct ast_channel *chan, const int type);
};
/*! Kill the channel channel driver technology descriptor. */
diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h
index 98d7773..57aaefe 100644
--- a/include/asterisk/rtp_engine.h
+++ b/include/asterisk/rtp_engine.h
@@ -2683,6 +2683,20 @@
struct stasis_message_type *ast_rtp_rtcp_received_type(void);
/*!
+ * \brief Convert given stat instance into json format
+ * \param stats
+ * \retval A json format stat
+ */
+struct ast_json *ast_rtp_convert_stats_json(const struct ast_rtp_instance_stats *stats);
+
+/*!
+ * \brief Retrieve statistics about an RTP instance in json format
+ * \param instance
+ * \retval json object of stats
+ */
+struct ast_json *ast_rtp_instance_get_stats_all_json(struct ast_rtp_instance *instance);
+
+/*!
* \since 12
* \brief \ref stasis topic for RTP and RTCP related messages
*
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index fd1613c..a986b8c 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -3740,3 +3740,69 @@
}
ao2_unlock(rtp);
}
+
+struct ast_json *ast_rtp_convert_stats_json(const struct ast_rtp_instance_stats *stats)
+{
+ struct ast_json *j_res;
+
+ j_res = ast_json_object_create();
+
+ ast_json_object_set(j_res, "txcount", ast_json_integer_create(stats->txcount));
+ ast_json_object_set(j_res, "rxcount", ast_json_integer_create(stats->rxcount));
+
+ ast_json_object_set(j_res, "txjitter", ast_json_real_create(stats->txjitter));
+ ast_json_object_set(j_res, "rxjitter", ast_json_real_create(stats->rxjitter));
+
+ ast_json_object_set(j_res, "remote_maxjitter", ast_json_real_create(stats->remote_maxjitter));
+ ast_json_object_set(j_res, "remote_minjitter", ast_json_real_create(stats->remote_minjitter));
+ ast_json_object_set(j_res, "remote_normdevjitter", ast_json_real_create(stats->remote_normdevjitter));
+ ast_json_object_set(j_res, "remote_stdevjitter", ast_json_real_create(stats->remote_stdevjitter));
+
+ ast_json_object_set(j_res, "local_maxjitter", ast_json_real_create(stats->local_maxjitter));
+ ast_json_object_set(j_res, "local_minjitter", ast_json_real_create(stats->local_minjitter));
+ ast_json_object_set(j_res, "local_normdevjitter", ast_json_real_create(stats->local_normdevjitter));
+ ast_json_object_set(j_res, "local_stdevjitter", ast_json_real_create(stats->local_stdevjitter));
+
+ ast_json_object_set(j_res, "txploss", ast_json_integer_create(stats->txploss));
+ ast_json_object_set(j_res, "rxploss", ast_json_integer_create(stats->rxploss));
+
+ ast_json_object_set(j_res, "remote_maxrxploss", ast_json_real_create(stats->remote_maxrxploss));
+ ast_json_object_set(j_res, "remote_minrxploss", ast_json_real_create(stats->remote_minrxploss));
+ ast_json_object_set(j_res, "remote_normdevrxploss", ast_json_real_create(stats->remote_normdevrxploss));
+ ast_json_object_set(j_res, "remote_stdevrxploss", ast_json_real_create(stats->remote_stdevrxploss));
+
+ ast_json_object_set(j_res, "local_maxrxploss", ast_json_real_create(stats->local_maxrxploss));
+ ast_json_object_set(j_res, "local_minrxploss", ast_json_real_create(stats->local_minrxploss));
+ ast_json_object_set(j_res, "local_normdevrxploss", ast_json_real_create(stats->local_normdevrxploss));
+ ast_json_object_set(j_res, "local_stdevrxploss", ast_json_real_create(stats->local_stdevrxploss));
+
+ ast_json_object_set(j_res, "rtt", ast_json_real_create(stats->rtt));
+ ast_json_object_set(j_res, "maxrtt", ast_json_real_create(stats->maxrtt));
+ ast_json_object_set(j_res, "minrtt", ast_json_real_create(stats->minrtt));
+ ast_json_object_set(j_res, "normdevrtt", ast_json_real_create(stats->normdevrtt));
+ ast_json_object_set(j_res, "stdevrtt", ast_json_real_create(stats->stdevrtt));
+
+ ast_json_object_set(j_res, "local_ssrc", ast_json_integer_create(stats->local_ssrc));
+ ast_json_object_set(j_res, "remote_ssrc", ast_json_integer_create(stats->remote_ssrc));
+
+ ast_json_object_set(j_res, "txoctetcount", ast_json_integer_create(stats->txoctetcount));
+ ast_json_object_set(j_res, "rxoctetcount", ast_json_integer_create(stats->rxoctetcount));
+
+ ast_json_object_set(j_res, "channel_unqiueid", ast_json_string_create(stats->channel_uniqueid));
+
+ return j_res;
+}
+
+struct ast_json *ast_rtp_instance_get_stats_all_json(struct ast_rtp_instance *instance)
+{
+ struct ast_rtp_instance_stats stats = {0,};
+ struct ast_json *j_res;
+
+ if(ast_rtp_instance_get_stats(instance, &stats, AST_RTP_INSTANCE_STAT_ALL)) {
+ return NULL;
+ }
+
+ j_res = ast_rtp_convert_stats_json(&stats);
+
+ return j_res;
+}
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c
index 44d9d77..6977125 100644
--- a/res/ari/ari_model_validators.c
+++ b/res/ari/ari_model_validators.c
@@ -1261,6 +1261,395 @@
return ast_ari_validate_channel;
}
+int ast_ari_validate_channelstat(struct ast_json *json)
+{
+ int res = 1;
+ struct ast_json_iter *iter;
+ int has_channel_unqiueid = 0;
+ int has_local_ssrc = 0;
+ int has_remote_ssrc = 0;
+ int has_rxcount = 0;
+ int has_rxoctetcount = 0;
+ int has_rxploss = 0;
+ int has_status = 0;
+ int has_txcount = 0;
+ int has_txoctetcount = 0;
+ int has_txploss = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("channel_unqiueid", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_channel_unqiueid = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field channel_unqiueid failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("local_maxjitter", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field local_maxjitter failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("local_maxrxploss", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field local_maxrxploss failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("local_minjitter", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field local_minjitter failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("local_minrxploss", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field local_minrxploss failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("local_normdevjitter", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field local_normdevjitter failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("local_normdevrxploss", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field local_normdevrxploss failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("local_ssrc", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_local_ssrc = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field local_ssrc failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("local_stdevjitter", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field local_stdevjitter failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("local_stdevrxploss", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field local_stdevrxploss failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("maxrtt", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field maxrtt failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("minrtt", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field minrtt failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("normdevrtt", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field normdevrtt failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("remote_maxjitter", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field remote_maxjitter failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("remote_maxrxploss", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field remote_maxrxploss failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("remote_minjitter", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field remote_minjitter failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("remote_minrxploss", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field remote_minrxploss failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("remote_normdevjitter", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field remote_normdevjitter failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("remote_normdevrxploss", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field remote_normdevrxploss failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("remote_ssrc", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_remote_ssrc = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field remote_ssrc failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("remote_stdevjitter", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field remote_stdevjitter failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("remote_stdevrxploss", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field remote_stdevrxploss failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("rtt", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field rtt failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("rxcount", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_rxcount = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field rxcount failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("rxjitter", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field rxjitter failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("rxoctetcount", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_rxoctetcount = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field rxoctetcount failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("rxploss", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_rxploss = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field rxploss failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("status", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_status = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field status failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("stdevrtt", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field stdevrtt failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("txcount", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_txcount = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field txcount failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("txjitter", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_double(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field txjitter failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("txoctetcount", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_txoctetcount = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field txoctetcount failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("txploss", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_txploss = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channelstat field txploss failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI Channelstat has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_channel_unqiueid) {
+ ast_log(LOG_ERROR, "ARI Channelstat missing required field channel_unqiueid\n");
+ res = 0;
+ }
+
+ if (!has_local_ssrc) {
+ ast_log(LOG_ERROR, "ARI Channelstat missing required field local_ssrc\n");
+ res = 0;
+ }
+
+ if (!has_remote_ssrc) {
+ ast_log(LOG_ERROR, "ARI Channelstat missing required field remote_ssrc\n");
+ res = 0;
+ }
+
+ if (!has_rxcount) {
+ ast_log(LOG_ERROR, "ARI Channelstat missing required field rxcount\n");
+ res = 0;
+ }
+
+ if (!has_rxoctetcount) {
+ ast_log(LOG_ERROR, "ARI Channelstat missing required field rxoctetcount\n");
+ res = 0;
+ }
+
+ if (!has_rxploss) {
+ ast_log(LOG_ERROR, "ARI Channelstat missing required field rxploss\n");
+ res = 0;
+ }
+
+ if (!has_status) {
+ ast_log(LOG_ERROR, "ARI Channelstat missing required field status\n");
+ res = 0;
+ }
+
+ if (!has_txcount) {
+ ast_log(LOG_ERROR, "ARI Channelstat missing required field txcount\n");
+ res = 0;
+ }
+
+ if (!has_txoctetcount) {
+ ast_log(LOG_ERROR, "ARI Channelstat missing required field txoctetcount\n");
+ res = 0;
+ }
+
+ if (!has_txploss) {
+ ast_log(LOG_ERROR, "ARI Channelstat missing required field txploss\n");
+ res = 0;
+ }
+
+ return res;
+}
+
+ari_validator ast_ari_validate_channelstat_fn(void)
+{
+ return ast_ari_validate_channelstat;
+}
+
int ast_ari_validate_dialed(struct ast_json *json)
{
int res = 1;
diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h
index 1ee74f4..f3f3a35 100644
--- a/res/ari/ari_model_validators.h
+++ b/res/ari/ari_model_validators.h
@@ -442,6 +442,24 @@
ari_validator ast_ari_validate_channel_fn(void);
/*!
+ * \brief Validator for Channelstat.
+ *
+ * A RTP stat of a channel.
+ *
+ * \param json JSON object to validate.
+ * \returns True (non-zero) if valid.
+ * \returns False (zero) if invalid.
+ */
+int ast_ari_validate_channelstat(struct ast_json *json);
+
+/*!
+ * \brief Function pointer to ast_ari_validate_channelstat().
+ *
+ * See \ref ast_ari_model_validators.h for more details.
+ */
+ari_validator ast_ari_validate_channelstat_fn(void);
+
+/*!
* \brief Validator for Dialed.
*
* Dialed channel information.
@@ -1479,6 +1497,40 @@
* - language: string (required)
* - name: string (required)
* - state: string (required)
+ * Channelstat
+ * - channel_unqiueid: string (required)
+ * - local_maxjitter: double
+ * - local_maxrxploss: double
+ * - local_minjitter: double
+ * - local_minrxploss: double
+ * - local_normdevjitter: double
+ * - local_normdevrxploss: double
+ * - local_ssrc: int (required)
+ * - local_stdevjitter: double
+ * - local_stdevrxploss: double
+ * - maxrtt: double
+ * - minrtt: double
+ * - normdevrtt: double
+ * - remote_maxjitter: double
+ * - remote_maxrxploss: double
+ * - remote_minjitter: double
+ * - remote_minrxploss: double
+ * - remote_normdevjitter: double
+ * - remote_normdevrxploss: double
+ * - remote_ssrc: int (required)
+ * - remote_stdevjitter: double
+ * - remote_stdevrxploss: double
+ * - rtt: double
+ * - rxcount: int (required)
+ * - rxjitter: double
+ * - rxoctetcount: int (required)
+ * - rxploss: int (required)
+ * - status: string (required)
+ * - stdevrtt: double
+ * - txcount: int (required)
+ * - txjitter: double
+ * - txoctetcount: int (required)
+ * - txploss: int (required)
* Dialed
* DialplanCEP
* - context: string (required)
diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c
index 08f97f1..a268dec 100644
--- a/res/ari/resource_channels.c
+++ b/res/ari/resource_channels.c
@@ -43,10 +43,13 @@
#include "asterisk/core_local.h"
#include "asterisk/dial.h"
#include "asterisk/max_forwards.h"
+#include "asterisk/vector.h"
+#include "asterisk/rtp_engine.h"
#include "resource_channels.h"
#include <limits.h>
+
/*!
* \brief Ensure channel is in a state that allows operation to be performed.
*
@@ -1946,3 +1949,29 @@
ast_ari_response_no_content(response);
}
+
+void ast_ari_channels_stats(struct ast_variable *headers,
+ struct ast_ari_channels_stats_args *args,
+ struct ast_ari_response *response)
+{
+ RAII_VAR(struct ast_channel *, chan, NULL, ast_channel_cleanup);
+ struct ast_json *j_res;
+
+ chan = ast_channel_get_by_name(args->channel_id);
+ if (!chan) {
+ ast_ari_response_error(response, 404, "Not Found",
+ "Channel not found");
+ return;
+ }
+
+ if (ast_channel_tech(chan)->get_rtp_stats) {
+ j_res = ast_channel_tech(chan)->get_rtp_stats(chan, 0);
+ }
+ else {
+ j_res = ast_json_array_create();
+ }
+
+ ast_ari_response_ok(response, j_res);
+
+ return;
+}
diff --git a/res/ari/resource_channels.h b/res/ari/resource_channels.h
index b071d08..671276d 100644
--- a/res/ari/resource_channels.h
+++ b/res/ari/resource_channels.h
@@ -781,5 +781,18 @@
* \param[out] response HTTP response
*/
void ast_ari_channels_dial(struct ast_variable *headers, struct ast_ari_channels_dial_args *args, struct ast_ari_response *response);
+/*! Argument struct for ast_ari_channels_stats() */
+struct ast_ari_channels_stats_args {
+ /*! Channel's id */
+ const char *channel_id;
+};
+/*!
+ * \brief RTP stats on a channel.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_channels_stats(struct ast_variable *headers, struct ast_ari_channels_stats_args *args, struct ast_ari_response *response);
#endif /* _ASTERISK_RESOURCE_CHANNELS_H */
diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c
index dae146c..ffd1a06 100644
--- a/res/res_ari_channels.c
+++ b/res/res_ari_channels.c
@@ -2660,6 +2660,64 @@
fin: __attribute__((unused))
return;
}
+/*!
+ * \brief Parameter parsing callback for /channels/{channelId}/stats.
+ * \param get_params GET parameters in the HTTP request.
+ * \param path_vars Path variables extracted from the request.
+ * \param headers HTTP headers.
+ * \param[out] response Response to the HTTP request.
+ */
+static void ast_ari_channels_stats_cb(
+ struct ast_tcptls_session_instance *ser,
+ struct ast_variable *get_params, struct ast_variable *path_vars,
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
+{
+ struct ast_ari_channels_stats_args args = {};
+ struct ast_variable *i;
+#if defined(AST_DEVMODE)
+ int is_valid;
+ int code;
+#endif /* AST_DEVMODE */
+
+ for (i = path_vars; i; i = i->next) {
+ if (strcmp(i->name, "channelId") == 0) {
+ args.channel_id = (i->value);
+ } else
+ {}
+ }
+ ast_ari_channels_stats(headers, &args, response);
+#if defined(AST_DEVMODE)
+ code = response->response_code;
+
+ switch (code) {
+ case 0: /* Implementation is still a stub, or the code wasn't set */
+ is_valid = response->message == NULL;
+ break;
+ case 500: /* Internal Server Error */
+ case 501: /* Not Implemented */
+ case 404: /* Channel cannot be found. */
+ is_valid = 1;
+ break;
+ default:
+ if (200 <= code && code <= 299) {
+ is_valid = ast_ari_validate_list(response->message,
+ ast_ari_validate_channelstat_fn());
+ } else {
+ ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/stats\n", code);
+ is_valid = 0;
+ }
+ }
+
+ if (!is_valid) {
+ ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/stats\n");
+ ast_ari_response_error(response, 500,
+ "Internal Server Error", "Response validation failed");
+ }
+#endif /* AST_DEVMODE */
+
+fin: __attribute__((unused))
+ return;
+}
/*! \brief REST handler for /api-docs/channels.json */
static struct stasis_rest_handlers channels_create = {
@@ -2823,6 +2881,15 @@
.children = { }
};
/*! \brief REST handler for /api-docs/channels.json */
+static struct stasis_rest_handlers channels_channelId_stats = {
+ .path_segment = "stats",
+ .callbacks = {
+ [AST_HTTP_GET] = ast_ari_channels_stats_cb,
+ },
+ .num_children = 0,
+ .children = { }
+};
+/*! \brief REST handler for /api-docs/channels.json */
static struct stasis_rest_handlers channels_channelId = {
.path_segment = "channelId",
.is_wildcard = 1,
@@ -2831,8 +2898,8 @@
[AST_HTTP_POST] = ast_ari_channels_originate_with_id_cb,
[AST_HTTP_DELETE] = ast_ari_channels_hangup_cb,
},
- .num_children = 14,
- .children = { &channels_channelId_continue,&channels_channelId_redirect,&channels_channelId_answer,&channels_channelId_ring,&channels_channelId_dtmf,&channels_channelId_mute,&channels_channelId_hold,&channels_channelId_moh,&channels_channelId_silence,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable,&channels_channelId_snoop,&channels_channelId_dial, }
+ .num_children = 15,
+ .children = { &channels_channelId_continue,&channels_channelId_redirect,&channels_channelId_answer,&channels_channelId_ring,&channels_channelId_dtmf,&channels_channelId_mute,&channels_channelId_hold,&channels_channelId_moh,&channels_channelId_silence,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable,&channels_channelId_snoop,&channels_channelId_dial,&channels_channelId_stats, }
};
/*! \brief REST handler for /api-docs/channels.json */
static struct stasis_rest_handlers channels = {
diff --git a/rest-api/api-docs/channels.json b/rest-api/api-docs/channels.json
index 08db224..4a3059f 100644
--- a/rest-api/api-docs/channels.json
+++ b/rest-api/api-docs/channels.json
@@ -1672,6 +1672,34 @@
]
}
]
+ },
+ {
+ "path": "/channels/{channelId}/stats",
+ "description": "RTP stats on a channel",
+ "operations": [
+ {
+ "httpMethod": "GET",
+ "summary": "RTP stats on a channel.",
+ "nickname": "stats",
+ "responseClass": "LIST[Channelstat]",
+ "parameters": [
+ {
+ "name": "channelId",
+ "description": "Channel's id",
+ "paramType": "path",
+ "required": true,
+ "allowMultiple": false,
+ "dataType": "string"
+ }
+ ],
+ "errorResponses": [
+ {
+ "code": 404,
+ "reason": "Channel cannot be found."
+ }
+ ]
+ }
+ ]
}
],
"models": {
@@ -1715,6 +1743,184 @@
}
}
},
+ "Channelstat": {
+ "id": "Channelstat",
+ "description": "A RTP stat of a channel.",
+ "properties": {
+ "txcount": {
+ "required": true,
+ "type": "int",
+ "description": "Number of packets transmitted."
+ },
+ "rxcount": {
+ "required": true,
+ "type": "int",
+ "description": "Number of packets received."
+ },
+ "txjitter": {
+ "required": false,
+ "type": "double",
+ "description": "Jitter on transmitted packets."
+ },
+ "rxjitter": {
+ "required": false,
+ "type": "double",
+ "description": "Jitter on received packets."
+ },
+ "remote_maxjitter": {
+ "required": false,
+ "type": "double",
+ "description": "Maximum jitter on remote side."
+ },
+ "remote_minjitter": {
+ "required": false,
+ "type": "double",
+ "description": "Minimum jitter on remote side."
+ },
+ "remote_normdevjitter": {
+ "required": false,
+ "type": "double",
+ "description": "Average jitter on remote side."
+ },
+ "remote_stdevjitter": {
+ "required": false,
+ "type": "double",
+ "description": "Standard deviation jitter on remote side."
+ },
+ "local_maxjitter": {
+ "required": false,
+ "type": "double",
+ "description": "Maximum jitter on local side."
+ },
+ "local_minjitter": {
+ "required": false,
+ "type": "double",
+ "description": "Minimum jitter on local side."
+ },
+ "local_normdevjitter": {
+ "required": false,
+ "type": "double",
+ "description": "Average jitter on local side."
+ },
+ "local_stdevjitter": {
+ "required": false,
+ "type": "double",
+ "description": "Standard deviation jitter on local side."
+ },
+ "txploss": {
+ "required": true,
+ "type": "int",
+ "description": "Number of transmitted packets lost."
+ },
+ "rxploss": {
+ "required": true,
+ "type": "int",
+ "description": "Number of received packets lost."
+ },
+ "remote_maxrxploss": {
+ "required": false,
+ "type": "double",
+ "description": "Maximum number of packets lost on remote side."
+ },
+ "remote_minrxploss": {
+ "required": false,
+ "type": "double",
+ "description": "Minimum number of packets lost on remote side."
+ },
+ "remote_normdevrxploss": {
+ "required": false,
+ "type": "double",
+ "description": "Average number of packets lost on remote side."
+ },
+ "remote_stdevrxploss": {
+ "required": false,
+ "type": "double",
+ "description": "Standard deviation packets lost on remote side."
+ },
+ "local_maxrxploss": {
+ "required": false,
+ "type": "double",
+ "description": "Maximum number of packets lost on local side."
+ },
+ "local_minrxploss": {
+ "required": false,
+ "type": "double",
+ "description": "Minimum number of packets lost on local side."
+ },
+ "local_normdevrxploss": {
+ "required": false,
+ "type": "double",
+ "description": "Average number of packets lost on local side."
+ },
+ "local_stdevrxploss": {
+ "required": false,
+ "type": "double",
+ "description": "Standard deviation packets lost on local side."
+ },
+ "rtt": {
+ "required": false,
+ "type": "double",
+ "description": "Total round trip time."
+ },
+ "maxrtt": {
+ "required": false,
+ "type": "double",
+ "description": "Maximum round trip time."
+ },
+ "minrtt": {
+ "required": false,
+ "type": "double",
+ "description": "Minimum round trip time."
+ },
+ "normdevrtt": {
+ "required": false,
+ "type": "double",
+ "description": "Average round trip time."
+ },
+ "stdevrtt": {
+ "required": false,
+ "type": "double",
+ "description": "Standard deviation round trip time."
+ },
+ "local_ssrc": {
+ "required": true,
+ "type": "int",
+ "description": "Our SSRC."
+ },
+ "remote_ssrc": {
+ "required": true,
+ "type": "int",
+ "description": "Their SSRC."
+ },
+ "txoctetcount": {
+ "required": true,
+ "type": "int",
+ "description": "Number of octets transmitted."
+ },
+ "rxoctetcount": {
+ "required": true,
+ "type": "int",
+ "description": "Number of octets received."
+ },
+ "channel_uniqueid": {
+ "required": true,
+ "type": "string",
+ "description": "The Asterisk channel's unique ID that owns this instance."
+ },
+ "status": {
+ "required": true,
+ "type": "string",
+ "description": "Channelstat's status.",
+ "allowableValues": {
+ "valueType": "LIST",
+ "values": [
+ "current",
+ "history"
+ ]
+ }
+ }
+ }
+ },
"Channel": {
"id": "Channel",
"description": "A specific communication connection between Asterisk and an Endpoint.",
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11083
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I4343eec070438cec13f2a4f22e7fd9e574381376
Gerrit-Change-Number: 11083
Gerrit-PatchSet: 1
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190302/efcc2310/attachment-0001.html>
More information about the asterisk-code-review
mailing list