[Asterisk-code-review] res/res_ari: Added ARI resource /ari/channels/{channelId}/rtp_statistics (...asterisk[13])

sungtae kim asteriskteam at digium.com
Wed Mar 27 16:56:47 CDT 2019


sungtae kim has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/11200


Change subject: res/res_ari: Added ARI resource /ari/channels/{channelId}/rtp_statistics
......................................................................

res/res_ari: Added ARI resource /ari/channels/{channelId}/rtp_statistics

Added ARI resource for channel statistics.
GET /ari/channels/{channelId}/rtp_statistics : It returns given
channel's rtp statistics detail.

ASTERISK-28320

Change-Id: I4343eec070438cec13f2a4f22e7fd9e574381376
---
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
8 files changed, 861 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/00/11200/1

diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h
index 4b25e30..75300cc 100644
--- a/include/asterisk/rtp_engine.h
+++ b/include/asterisk/rtp_engine.h
@@ -2382,6 +2382,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 9b197d7..e1a1e0b 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -258,6 +258,20 @@
 
 
 /*!
+ * \brief Set given json object into target with name
+ *
+ * \param target Target json.
+ * \param name key of given object.
+ * \param obj Json value will be set.
+ */
+#define SET_AST_JSON_OBJ(target, name, obj) ({					\
+	struct ast_json *j_tmp = obj;						\
+	if (j_tmp) {						\
+		ast_json_object_set(target, name, j_tmp);						\
+	}						\
+})
+
+/*!
  * \internal
  * \brief Destructor for \c ast_rtp_payload_type
  */
@@ -2800,3 +2814,77 @@
 {
 	rtp->last_rx = time;
 }
+
+struct ast_json *ast_rtp_convert_stats_json(const struct ast_rtp_instance_stats *stats)
+{
+	struct ast_json *j_res;
+	int ret;
+
+	j_res = ast_json_object_create();
+	if (!j_res) {
+		return NULL;
+	}
+
+	/* set mandatory items */
+	ret = ast_json_object_set(j_res, "txcount", ast_json_integer_create(stats->txcount));
+	ret |= ast_json_object_set(j_res, "rxcount", ast_json_integer_create(stats->rxcount));
+
+	ret |= ast_json_object_set(j_res, "txploss", ast_json_integer_create(stats->txploss));
+	ret |= ast_json_object_set(j_res, "rxploss", ast_json_integer_create(stats->rxploss));
+
+	ret |= ast_json_object_set(j_res, "local_ssrc", ast_json_integer_create(stats->local_ssrc));
+	ret |= ast_json_object_set(j_res, "remote_ssrc", ast_json_integer_create(stats->remote_ssrc));
+
+	ret |= ast_json_object_set(j_res, "txoctetcount", ast_json_integer_create(stats->txoctetcount));
+	ret |= ast_json_object_set(j_res, "rxoctetcount", ast_json_integer_create(stats->rxoctetcount));
+
+	ret |= ast_json_object_set(j_res, "channel_uniqueid", ast_json_string_create(stats->channel_uniqueid));
+	if (ret) {
+		ast_log(LOG_WARNING, "Could not create rtp statistics info. channel: %s\n", stats->channel_uniqueid);
+		ast_json_unref(j_res);
+		return NULL;
+	}
+
+	/* set other items */
+	SET_AST_JSON_OBJ(j_res, "txjitter", ast_json_real_create(stats->txjitter));
+	SET_AST_JSON_OBJ(j_res, "rxjitter", ast_json_real_create(stats->rxjitter));
+
+	SET_AST_JSON_OBJ(j_res, "remote_maxjitter", ast_json_real_create(stats->remote_maxjitter));
+	SET_AST_JSON_OBJ(j_res, "remote_minjitter", ast_json_real_create(stats->remote_minjitter));
+	SET_AST_JSON_OBJ(j_res, "remote_normdevjitter", ast_json_real_create(stats->remote_normdevjitter));
+	SET_AST_JSON_OBJ(j_res, "remote_stdevjitter", ast_json_real_create(stats->remote_stdevjitter));
+
+	SET_AST_JSON_OBJ(j_res, "local_maxjitter", ast_json_real_create(stats->local_maxjitter));
+	SET_AST_JSON_OBJ(j_res, "local_minjitter", ast_json_real_create(stats->local_minjitter));
+	SET_AST_JSON_OBJ(j_res, "local_normdevjitter", ast_json_real_create(stats->local_normdevjitter));
+	SET_AST_JSON_OBJ(j_res, "local_stdevjitter", ast_json_real_create(stats->local_stdevjitter));
+
+	SET_AST_JSON_OBJ(j_res, "remote_maxrxploss", ast_json_real_create(stats->remote_maxrxploss));
+	SET_AST_JSON_OBJ(j_res, "remote_minrxploss", ast_json_real_create(stats->remote_minrxploss));
+	SET_AST_JSON_OBJ(j_res, "remote_normdevrxploss", ast_json_real_create(stats->remote_normdevrxploss));
+	SET_AST_JSON_OBJ(j_res, "remote_stdevrxploss", ast_json_real_create(stats->remote_stdevrxploss));
+
+	SET_AST_JSON_OBJ(j_res, "local_maxrxploss", ast_json_real_create(stats->local_maxrxploss));
+	SET_AST_JSON_OBJ(j_res, "local_minrxploss", ast_json_real_create(stats->local_minrxploss));
+	SET_AST_JSON_OBJ(j_res, "local_normdevrxploss", ast_json_real_create(stats->local_normdevrxploss));
+	SET_AST_JSON_OBJ(j_res, "local_stdevrxploss", ast_json_real_create(stats->local_stdevrxploss));
+
+	SET_AST_JSON_OBJ(j_res, "rtt", ast_json_real_create(stats->rtt));
+	SET_AST_JSON_OBJ(j_res, "maxrtt", ast_json_real_create(stats->maxrtt));
+	SET_AST_JSON_OBJ(j_res, "minrtt", ast_json_real_create(stats->minrtt));
+	SET_AST_JSON_OBJ(j_res, "normdevrtt", ast_json_real_create(stats->normdevrtt));
+	SET_AST_JSON_OBJ(j_res, "stdevrtt", ast_json_real_create(stats->stdevrtt));
+
+	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,};
+
+	if(ast_rtp_instance_get_stats(instance, &stats, AST_RTP_INSTANCE_STAT_ALL)) {
+		return NULL;
+	}
+
+	return ast_rtp_convert_stats_json(&stats);
+}
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c
index 071a24d..0b75f2b 100644
--- a/res/ari/ari_model_validators.c
+++ b/res/ari/ari_model_validators.c
@@ -1346,6 +1346,379 @@
 	return ast_ari_validate_dialplan_cep;
 }
 
+int ast_ari_validate_rtpstat(struct ast_json *json)
+{
+	int res = 1;
+	struct ast_json_iter *iter;
+	int has_channel_uniqueid = 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_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_uniqueid", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			has_channel_uniqueid = 1;
+			prop_is_valid = ast_ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI RTPstat field channel_uniqueid 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat field rxploss 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat 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 RTPstat field txploss failed validation\n");
+				res = 0;
+			}
+		} else
+		{
+			ast_log(LOG_ERROR,
+				"ARI RTPstat has undocumented field %s\n",
+				ast_json_object_iter_key(iter));
+			res = 0;
+		}
+	}
+
+	if (!has_channel_uniqueid) {
+		ast_log(LOG_ERROR, "ARI RTPstat missing required field channel_uniqueid\n");
+		res = 0;
+	}
+
+	if (!has_local_ssrc) {
+		ast_log(LOG_ERROR, "ARI RTPstat missing required field local_ssrc\n");
+		res = 0;
+	}
+
+	if (!has_remote_ssrc) {
+		ast_log(LOG_ERROR, "ARI RTPstat missing required field remote_ssrc\n");
+		res = 0;
+	}
+
+	if (!has_rxcount) {
+		ast_log(LOG_ERROR, "ARI RTPstat missing required field rxcount\n");
+		res = 0;
+	}
+
+	if (!has_rxoctetcount) {
+		ast_log(LOG_ERROR, "ARI RTPstat missing required field rxoctetcount\n");
+		res = 0;
+	}
+
+	if (!has_rxploss) {
+		ast_log(LOG_ERROR, "ARI RTPstat missing required field rxploss\n");
+		res = 0;
+	}
+
+	if (!has_txcount) {
+		ast_log(LOG_ERROR, "ARI RTPstat missing required field txcount\n");
+		res = 0;
+	}
+
+	if (!has_txoctetcount) {
+		ast_log(LOG_ERROR, "ARI RTPstat missing required field txoctetcount\n");
+		res = 0;
+	}
+
+	if (!has_txploss) {
+		ast_log(LOG_ERROR, "ARI RTPstat missing required field txploss\n");
+		res = 0;
+	}
+
+	return res;
+}
+
+ari_validator ast_ari_validate_rtpstat_fn(void)
+{
+	return ast_ari_validate_rtpstat;
+}
+
 int ast_ari_validate_bridge(struct ast_json *json)
 {
 	int res = 1;
diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h
index 54e852f..e5c803a 100644
--- a/res/ari/ari_model_validators.h
+++ b/res/ari/ari_model_validators.h
@@ -479,6 +479,24 @@
 ari_validator ast_ari_validate_dialplan_cep_fn(void);
 
 /*!
+ * \brief Validator for RTPstat.
+ *
+ * A statistics of a RTP.
+ *
+ * \param json JSON object to validate.
+ * \returns True (non-zero) if valid.
+ * \returns False (zero) if invalid.
+ */
+int ast_ari_validate_rtpstat(struct ast_json *json);
+
+/*!
+ * \brief Function pointer to ast_ari_validate_rtpstat().
+ *
+ * See \ref ast_ari_model_validators.h for more details.
+ */
+ari_validator ast_ari_validate_rtpstat_fn(void);
+
+/*!
  * \brief Validator for Bridge.
  *
  * The merging of media from one or more channels.
@@ -1484,6 +1502,39 @@
  * - context: string (required)
  * - exten: string (required)
  * - priority: long (required)
+ * RTPstat
+ * - channel_uniqueid: 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)
+ * - stdevrtt: double
+ * - txcount: int (required)
+ * - txjitter: double
+ * - txoctetcount: int (required)
+ * - txploss: int (required)
  * Bridge
  * - bridge_class: string (required)
  * - bridge_type: string (required)
diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c
index f5065f5..bdb3534 100644
--- a/res/ari/resource_channels.c
+++ b/res/ari/resource_channels.c
@@ -48,10 +48,13 @@
 #include "asterisk/format_cache.h"
 #include "asterisk/core_local.h"
 #include "asterisk/dial.h"
+#include "asterisk/max_forwards.h"
+#include "asterisk/rtp_engine.h"
 #include "resource_channels.h"
 
 #include <limits.h>
 
+
 /*!
  * \brief Finds the control object for a channel, filling the response with an
  * error, if appropriate.
@@ -1531,3 +1534,59 @@
 		args->snoop_id,
 		response);
 }
+
+void ast_ari_channels_rtpstatistics(struct ast_variable *headers,
+		struct ast_ari_channels_rtpstatistics_args *args,
+		struct ast_ari_response *response)
+{
+	RAII_VAR(struct ast_channel *, chan, NULL, ast_channel_cleanup);
+	RAII_VAR(struct ast_rtp_instance *, rtp, NULL, ao2_cleanup);
+	struct ast_json *j_res;
+	const struct ast_channel_tech *tech;
+	struct ast_rtp_glue *glue;
+
+	chan = ast_channel_get_by_name(args->channel_id);
+	if (!chan) {
+		ast_ari_response_error(response, 404, "Not Found",
+			"Channel not found");
+		return;
+	}
+
+	ast_channel_lock(chan);
+	tech = ast_channel_tech(chan);
+	if (!tech) {
+		ast_channel_unlock(chan);
+		ast_ari_response_error(response, 404, "Not Found",
+			"Channel's tech not found");
+		return;
+	}
+
+	glue = ast_rtp_instance_get_glue(tech->type);
+	if (!glue) {
+		ast_channel_unlock(chan);
+		ast_ari_response_error(response, 403, "Forbidden",
+			"Unsupported channel type");
+		return;
+	}
+
+	glue->get_rtp_info(chan, &rtp);
+	if (!rtp) {
+		ast_channel_unlock(chan);
+		ast_ari_response_error(response, 404, "Not Found",
+			"RTP info not found");
+		return;
+	}
+
+	j_res = ast_rtp_instance_get_stats_all_json(rtp);
+	if (!j_res) {
+		ast_channel_unlock(chan);
+		ast_ari_response_error(response, 404, "Not Found",
+			"Statistics not found");
+		return;
+	}
+
+	ast_channel_unlock(chan);
+	ast_ari_response_ok(response, j_res);
+
+	return;
+}
diff --git a/res/ari/resource_channels.h b/res/ari/resource_channels.h
index b9e5d02..3077297 100644
--- a/res/ari/resource_channels.h
+++ b/res/ari/resource_channels.h
@@ -737,5 +737,18 @@
  * \param[out] response HTTP response
  */
 void ast_ari_channels_snoop_channel_with_id(struct ast_variable *headers, struct ast_ari_channels_snoop_channel_with_id_args *args, struct ast_ari_response *response);
+/*! Argument struct for ast_ari_channels_rtpstatistics() */
+struct ast_ari_channels_rtpstatistics_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_rtpstatistics(struct ast_variable *headers, struct ast_ari_channels_rtpstatistics_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 a69887c..5119d64 100644
--- a/res/res_ari_channels.c
+++ b/res/res_ari_channels.c
@@ -2391,6 +2391,64 @@
 fin: __attribute__((unused))
 	return;
 }
+/*!
+ * \brief Parameter parsing callback for /channels/{channelId}/rtp_statistics.
+ * \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_rtpstatistics_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_rtpstatistics_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_rtpstatistics(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_rtpstat(
+				response->message);
+		} else {
+			ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/rtp_statistics\n", code);
+			is_valid = 0;
+		}
+	}
+
+	if (!is_valid) {
+		ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/rtp_statistics\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_channelId_continue = {
@@ -2545,6 +2603,15 @@
 	.children = { &channels_channelId_snoop_snoopId, }
 };
 /*! \brief REST handler for /api-docs/channels.json */
+static struct stasis_rest_handlers channels_channelId_rtp_statistics = {
+	.path_segment = "rtp_statistics",
+	.callbacks = {
+		[AST_HTTP_GET] = ast_ari_channels_rtpstatistics_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,
@@ -2553,8 +2620,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_move,&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, }
+	.num_children = 15,
+	.children = { &channels_channelId_continue,&channels_channelId_move,&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_rtp_statistics, }
 };
 /*! \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 afe95dc..4d26b54 100644
--- a/rest-api/api-docs/channels.json
+++ b/rest-api/api-docs/channels.json
@@ -1511,6 +1511,34 @@
 					]
 				}
 			]
+		},
+		{
+			"path": "/channels/{channelId}/rtp_statistics",
+			"description": "Get RTP statistics information for RTP on a channel",
+			"operations": [
+				{
+					"httpMethod": "GET",
+					"summary": "RTP stats on a channel.",
+					"nickname": "rtpstatistics",
+					"responseClass": "RTPstat",
+					"parameters": [
+						{
+							"name": "channelId",
+							"description": "Channel's id",
+							"paramType": "path",
+							"required": true,
+							"allowMultiple": false,
+							"dataType": "string"
+						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Channel cannot be found."
+						}
+					]
+				}
+			]
 		}
 	],
 	"models": {
@@ -1554,6 +1582,172 @@
 				}
 			}
 		},
+		"RTPstat": {
+			"id": "RTPstat",
+			"description": "A statistics of a RTP.",
+			"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."
+				}
+			}
+		},
 		"Channel": {
 			"id": "Channel",
 			"description": "A specific communication connection between Asterisk and an Endpoint.",

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11200
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I4343eec070438cec13f2a4f22e7fd9e574381376
Gerrit-Change-Number: 11200
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/20190327/cb2bd567/attachment-0001.html>


More information about the asterisk-code-review mailing list