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

This commit is contained in:
George Joseph
2019-04-08 10:51:45 -05:00
committed by Gerrit Code Review
8 changed files with 860 additions and 2 deletions

View File

@@ -1385,6 +1385,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;

View File

@@ -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.
*
@@ -1504,6 +1522,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)

View File

@@ -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;
}

View File

@@ -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 */