aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2018-10-01 15:06:42 +0200
committerOliver Smith <osmith@sysmocom.de>2018-10-04 11:36:19 +0200
commita386d6a5833a2466e9b59eee02044dec470b0bee (patch)
tree6982e2d81437fdffc9c36645a2134bdf8f216a66
parentd4eb8babd00c13ee51a1b29972e1c51e2f1965a0 (diff)
Add rate counters for call handlingosmith/statistics
This creates rate counters for: * Initiated calls * Failed calls * Connected calls * Released calls Related: OS#1679 Change-Id: I6d7963266a93be631a4e0e03a39916d07a88fe01
-rw-r--r--src/Makefile.am2
-rw-r--r--src/ctr.h25
-rw-r--r--src/main.c12
-rw-r--r--src/sip.c29
-rw-r--r--src/sip.h6
5 files changed, 62 insertions, 12 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7a955fa..971fe88 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,7 @@ bin_PROGRAMS = osmo-sip-connector
AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(SOFIASIP_CFLAGS)
noinst_HEADERS = \
- evpoll.h vty.h mncc_protocol.h app.h mncc.h sip.h call.h sdp.h logging.h
+ evpoll.h vty.h mncc_protocol.h app.h mncc.h sip.h call.h ctr.h sdp.h logging.h
osmo_sip_connector_SOURCES = \
sdp.c \
diff --git a/src/ctr.h b/src/ctr.h
new file mode 100644
index 0000000..b3460de
--- /dev/null
+++ b/src/ctr.h
@@ -0,0 +1,25 @@
+#pragma once
+#include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/stats.h>
+
+enum {
+ SIP_CTR_CALL_INITIATED,
+ SIP_CTR_CALL_FAILED,
+ SIP_CTR_CALL_CONNECTED,
+ SIP_CTR_CALL_RELEASED,
+};
+
+static const struct rate_ctr_desc sip_ctr_description[] = {
+ [SIP_CTR_CALL_INITIATED] = {"call:initiated", "Call(s) initiated."},
+ [SIP_CTR_CALL_FAILED] = {"call:failed", "Call(s) failed."},
+ [SIP_CTR_CALL_CONNECTED] = {"call:connected", "Call(s) connected."},
+ [SIP_CTR_CALL_RELEASED] = {"call:released", "Call(s) released."},
+};
+
+static const struct rate_ctr_group_desc sip_ctrg_desc = {
+ "sip-connector",
+ "SIP connector",
+ OSMO_STATS_CLASS_GLOBAL,
+ ARRAY_SIZE(sip_ctr_description),
+ sip_ctr_description
+};
diff --git a/src/main.c b/src/main.c
index 560995e..d07f51b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,6 +26,7 @@
#include "mncc.h"
#include "app.h"
#include "call.h"
+#include "ctr.h"
#include <osmocom/core/application.h>
#include <osmocom/core/utils.h>
@@ -113,6 +114,7 @@ int main(int argc, char **argv)
{
int rc;
GMainLoop *loop;
+ struct rate_ctr_group *ctrg;
/* initialize osmocom */
tall_mncc_ctx = talloc_named_const(NULL, 0, "MNCC CTX");
@@ -120,6 +122,14 @@ int main(int argc, char **argv)
osmo_init_logging2(tall_mncc_ctx, &mncc_sip_info);
osmo_stats_init(tall_mncc_ctx);
+ /* init statistics */
+ rate_ctr_init(tall_mncc_ctx);
+ ctrg = rate_ctr_group_alloc(tall_mncc_ctx, &sip_ctrg_desc, 0);
+ if (!ctrg) {
+ LOGP(DAPP, LOGL_ERROR, "Cannot allocate global counter group!\n");
+ exit(1);
+ }
+
mncc_sip_vty_init();
logging_vty_add_cmds(&mncc_sip_info);
osmo_stats_vty_add_cmds(&mncc_sip_info);
@@ -144,7 +154,7 @@ int main(int argc, char **argv)
mncc_connection_start(&g_app.mncc.conn);
/* sofia sip */
- sip_agent_init(&g_app.sip.agent, &g_app);
+ sip_agent_init(&g_app.sip.agent, &g_app, ctrg);
rc = sip_agent_start(&g_app.sip.agent);
if (rc < 0)
LOGP(DSIP, LOGL_ERROR,
diff --git a/src/sip.c b/src/sip.c
index adf20d8..e7af1e6 100644
--- a/src/sip.c
+++ b/src/sip.c
@@ -21,6 +21,7 @@
#include "sip.h"
#include "app.h"
#include "call.h"
+#include "ctr.h"
#include "logging.h"
#include "sdp.h"
@@ -77,6 +78,15 @@ static void call_connect(struct sip_call_leg *leg, const sip_t *sip)
leg->state = SIP_CC_CONNECTED;
other->connect_call(other);
nua_ack(leg->nua_handle, TAG_END());
+ // rate_ctr_inc2(agent->ctrg, SIP_CTR_CALL_CONNECTED);
+}
+
+static void new_call_failure(struct sip_agent *agent, nua_handle_t *nh,
+ int status, char const* phrase)
+{
+ nua_respond(nh, status, phrase, TAG_END());
+ nua_handle_destroy(nh);
+ rate_ctr_inc2(agent->ctrg, SIP_CTR_CALL_FAILED);
}
static void new_call(struct sip_agent *agent, nua_handle_t *nh,
@@ -90,16 +100,14 @@ static void new_call(struct sip_agent *agent, nua_handle_t *nh,
if (!sdp_screen_sdp(sip)) {
LOGP(DSIP, LOGL_ERROR, "No supported codec.\n");
- nua_respond(nh, SIP_406_NOT_ACCEPTABLE, TAG_END());
- nua_handle_destroy(nh);
+ new_call_failure(agent, nh, SIP_406_NOT_ACCEPTABLE);
return;
}
call = call_sip_create();
if (!call) {
LOGP(DSIP, LOGL_ERROR, "No supported codec.\n");
- nua_respond(nh, SIP_500_INTERNAL_SERVER_ERROR, TAG_END());
- nua_handle_destroy(nh);
+ new_call_failure(agent, nh, SIP_500_INTERNAL_SERVER_ERROR);
return;
}
@@ -110,8 +118,7 @@ static void new_call(struct sip_agent *agent, nua_handle_t *nh,
if (!to || !from) {
LOGP(DSIP, LOGL_ERROR, "Unknown from/to for invite.\n");
- nua_respond(nh, SIP_406_NOT_ACCEPTABLE, TAG_END());
- nua_handle_destroy(nh);
+ new_call_failure(agent, nh, SIP_406_NOT_ACCEPTABLE);
return;
}
@@ -128,8 +135,7 @@ static void new_call(struct sip_agent *agent, nua_handle_t *nh,
*/
if (!sdp_extract_sdp(leg, sip, true)) {
LOGP(DSIP, LOGL_ERROR, "leg(%p) no audio, releasing\n", leg);
- nua_respond(nh, SIP_406_NOT_ACCEPTABLE, TAG_END());
- nua_handle_destroy(nh);
+ new_call_failure(agent, nh, SIP_406_NOT_ACCEPTABLE);
call_leg_release(&leg->base);
return;
}
@@ -354,6 +360,8 @@ static void sip_release_call(struct call_leg *_leg)
nua_bye(leg->nua_handle, TAG_END());
break;
}
+
+ // rate_ctr_inc2(agent->ctrg, SIP_CTR_CALL_RELEASED);
}
static void sip_ring_call(struct call_leg *_leg)
@@ -364,6 +372,7 @@ static void sip_ring_call(struct call_leg *_leg)
leg = (struct sip_call_leg *) _leg;
nua_respond(leg->nua_handle, SIP_180_RINGING, TAG_END());
+ // rate_ctr_inc2(agent->ctrg, SIP_CTR_CALL_INITIATED);
}
static void sip_connect_call(struct call_leg *_leg)
@@ -495,9 +504,11 @@ static void sip_logger(void *stream, char const *fmt, va_list ap)
osmo_vlogp(DSIP, LOGL_NOTICE, "", 0, 0, fmt, ap);
}
-void sip_agent_init(struct sip_agent *agent, struct app_config *app)
+void sip_agent_init(struct sip_agent *agent, struct app_config *app,
+ struct rate_ctr_group *ctrg)
{
agent->app = app;
+ agent->ctrg = ctrg;
su_init();
su_home_init(&agent->home);
diff --git a/src/sip.h b/src/sip.h
index d25c0b1..e6b9b72 100644
--- a/src/sip.h
+++ b/src/sip.h
@@ -6,6 +6,7 @@
#include <sofia-sip/nua_tag.h>
#include <sofia-sip/su_glib.h>
#include <sofia-sip/nua.h>
+#include <osmocom/core/rate_ctr.h>
struct app_config;
struct call;
@@ -16,9 +17,12 @@ struct sip_agent {
su_root_t *root;
nua_t *nua;
+
+ struct rate_ctr_group *ctrg;
};
-void sip_agent_init(struct sip_agent *agent, struct app_config *app);
+void sip_agent_init(struct sip_agent *agent, struct app_config *app,
+ struct rate_ctr_group *ctrg);
int sip_agent_start(struct sip_agent *agent);
int sip_create_remote_leg(struct sip_agent *agent, struct call *call);