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
This commit is contained in:
parent
5f6890a8f9
commit
71c0c7f631
|
@ -2682,6 +2682,20 @@ struct stasis_message_type *ast_rtp_rtcp_sent_type(void);
|
|||
*/
|
||||
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
|
||||
|
|
|
@ -277,6 +277,20 @@ static ast_rwlock_t static_RTP_PT_lock;
|
|||
static struct stasis_topic *rtp_topic;
|
||||
|
||||
|
||||
/*!
|
||||
* \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
|
||||
|
@ -3740,3 +3754,77 @@ void ast_rtp_instance_set_stream_num(struct ast_rtp_instance *rtp, int stream_nu
|
|||
}
|
||||
ao2_unlock(rtp);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1353,6 +1353,379 @@ ari_validator ast_ari_validate_dialplan_cep_fn(void)
|
|||
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;
|
||||
|
|
|
@ -477,6 +477,24 @@ int ast_ari_validate_dialplan_cep(struct ast_json *json);
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -1502,6 +1520,39 @@ ari_validator ast_ari_validate_application_fn(void);
|
|||
* - 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)
|
||||
|
|
|
@ -43,10 +43,12 @@
|
|||
#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 Ensure channel is in a state that allows operation to be performed.
|
||||
*
|
||||
|
@ -1966,3 +1968,59 @@ void ast_ari_channels_dial(struct ast_variable *headers,
|
|||
|
||||
ast_ari_response_no_content(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;
|
||||
}
|
||||
|
|
|
@ -809,5 +809,18 @@ int ast_ari_channels_dial_parse_body(
|
|||
* \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_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 */
|
||||
|
|
|
@ -2746,6 +2746,64 @@ static void ast_ari_channels_dial_cb(
|
|||
}
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -2921,6 +2979,15 @@ static struct stasis_rest_handlers channels_channelId_dial = {
|
|||
.children = { }
|
||||
};
|
||||
/*! \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,
|
||||
|
@ -2929,8 +2996,8 @@ static struct stasis_rest_handlers channels_channelId = {
|
|||
[AST_HTTP_POST] = ast_ari_channels_originate_with_id_cb,
|
||||
[AST_HTTP_DELETE] = ast_ari_channels_hangup_cb,
|
||||
},
|
||||
.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_dial, }
|
||||
.num_children = 16,
|
||||
.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_dial,&channels_channelId_rtp_statistics, }
|
||||
};
|
||||
/*! \brief REST handler for /api-docs/channels.json */
|
||||
static struct stasis_rest_handlers channels = {
|
||||
|
|
|
@ -1720,6 +1720,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": {
|
||||
|
@ -1763,6 +1791,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.",
|
||||
|
|
Loading…
Reference in New Issue