aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2020-04-27 16:58:02 +0200
committerOliver Smith <osmith@sysmocom.de>2020-04-30 10:05:39 +0200
commit2d24cd48c98ab20c39196eebb722db7c820341e6 (patch)
treec0cf7694728d003841fa273094a81246efb97835
parentfb046ebc9ef7ed90d3674d1bc4ce9559aa596316 (diff)
rtpsource: CTRL call rtp_create: add codec arg
Instead of hardcoding FR in rtpsource, add an argument to set the codec from mncc_mt_loadgen.py via CTRL call rtp_create. Hardcode FR in mncc_mt_loadgen.py for now, a follow up patch will make it configurable there, too. Related: SYS#4924 Change-Id: If75e902b451d7e202a03e93afcd55bd24f517813
-rwxr-xr-xmncc_mt_loadgen.py6
-rw-r--r--rtpsource/ctrl_if.c33
-rw-r--r--rtpsource/internal.h4
-rw-r--r--rtpsource/rtp_provider.c18
-rw-r--r--rtpsource/rtp_provider.h3
-rw-r--r--rtpsource/rtpsource.c7
6 files changed, 60 insertions, 11 deletions
diff --git a/mncc_mt_loadgen.py b/mncc_mt_loadgen.py
index 021d619..5f15e3b 100755
--- a/mncc_mt_loadgen.py
+++ b/mncc_mt_loadgen.py
@@ -80,7 +80,8 @@ class RtpSourceCtrlActor(pykka.ThreadingActor):
def on_receive(self, message):
if message['type'] == 'rtp_create':
- (res, var, val) = self._set_var('rtp_create', message['cname'])
+ val = '%s,%s' % (message['cname'], message['codec'])
+ (res, var, val) = self._set_var('rtp_create', val)
v = val.split(',') # input looks like '1,127.23.23.23,37723'
return {'cname': v[0], 'remote_host': v[1], 'remote_port': int(v[2])}
elif message['type'] == 'rtp_connect':
@@ -113,7 +114,8 @@ class MTCallRtpsource(pykka.ThreadingActor):
self.msisdn_called = msisdn_called
self.msisdn_calling = msisdn_calling
# allocate a RTP connection @ rtpsource
- r = self.ctrl_act.ask({'type':'rtp_create', 'cname':self.callref})
+ codec = "GSM_FR" # FIXME: make configurable
+ r = self.ctrl_act.ask({'type':'rtp_create', 'cname':self.callref, 'codec':codec})
self.ext_rtp_host = r['remote_host']
self.ext_rtp_port = r['remote_port']
# start the MNCC call FSM
diff --git a/rtpsource/ctrl_if.c b/rtpsource/ctrl_if.c
index 708fb02..b021e26 100644
--- a/rtpsource/ctrl_if.c
+++ b/rtpsource/ctrl_if.c
@@ -21,27 +21,52 @@
#include <osmocom/ctrl/control_cmd.h>
#include "internal.h"
+#include "rtp_provider.h"
CTRL_CMD_DEFINE_WO_NOVRF(rtp_create, "rtp_create");
static int set_rtp_create(struct ctrl_cmd *cmd, void *data)
{
struct rtp_connection *conn;
- const char *cname = cmd->value;
+ const char *cname, *codec_str;
+ char *tmp, *saveptr;
+ enum codec_type codec;
+
+ tmp = talloc_strdup(cmd, cmd->value);
+ OSMO_ASSERT(tmp);
+
+ cname = strtok_r(tmp, ",", &saveptr);
+ codec_str = strtok_r(NULL, ",", &saveptr);
+
+ if (!cname || !codec_str) {
+ cmd->reply = "Format is cname,codec";
+ goto error;
+ }
if (find_connection_by_cname(g_rss, cname)) {
cmd->reply = "Connection already exists for cname";
- return CTRL_CMD_ERROR;
+ goto error;
+ }
+
+ codec = get_string_value(codec_type_names, codec_str);
+ if (codec < 0) {
+ cmd->reply = "Invalid codec name (try GSM_FR, GSM_EFR etc.)";
+ goto error;
}
- conn = create_connection(g_rss, cname);
+ conn = create_connection(g_rss, cname, codec);
if (!conn) {
cmd->reply = "Error creating RTP connection";
- return CTRL_CMD_ERROR;
+ goto error;
}
/* Respond */
cmd->reply = talloc_asprintf(cmd, "%s,%s,%d", conn->cname, conn->local_host, conn->local_port);
+ talloc_free(tmp);
return CTRL_CMD_REPLY;
+
+error:
+ talloc_free(tmp);
+ return CTRL_CMD_ERROR;
}
CTRL_CMD_DEFINE_WO_NOVRF(rtp_connect, "rtp_connect");
diff --git a/rtpsource/internal.h b/rtpsource/internal.h
index a4501a2..35f12d0 100644
--- a/rtpsource/internal.h
+++ b/rtpsource/internal.h
@@ -4,6 +4,8 @@
#include <osmocom/trau/osmo_ortp.h>
#include <osmocom/ctrl/control_if.h>
+enum codec_type;
+
enum {
DMAIN,
};
@@ -36,7 +38,7 @@ extern struct rtpsource_state *g_rss;
struct rtp_connection *find_connection_by_cname(struct rtpsource_state *rss, const char *cname);
-struct rtp_connection *create_connection(struct rtpsource_state *rss, const char *cname);
+struct rtp_connection *create_connection(struct rtpsource_state *rss, const char *cname, enum codec_type codec);
int connect_connection(struct rtp_connection *conn, const char *remote_host,
uint16_t remote_port, uint8_t pt);
diff --git a/rtpsource/rtp_provider.c b/rtpsource/rtp_provider.c
index 0d2b9c6..7e12db3 100644
--- a/rtpsource/rtp_provider.c
+++ b/rtpsource/rtp_provider.c
@@ -9,6 +9,24 @@
static LLIST_HEAD(g_providers);
static LLIST_HEAD(g_prov_instances);
+const struct value_string codec_type_names[] = {
+ { CODEC_ULAW, "ULAW" },
+ { CODEC_ALAW, "ALAW" },
+ { CODEC_GSM_FR, "GSM_FR" },
+ { CODEC_GSM_EFR, "GSM_EFR" },
+ { CODEC_GSM_HR, "GSM_HR" },
+ { CODEC_AMR_4_75, "AMR_4_75" },
+ { CODEC_AMR_5_15, "AMR_5_15" },
+ { CODEC_AMR_5_90, "AMR_5_90" },
+ { CODEC_AMR_6_70, "AMR_6_70" },
+ { CODEC_AMR_7_40, "AMR_7_40" },
+ { CODEC_AMR_7_95, "AMR_7_95" },
+ { CODEC_AMR_10_2, "AMR_10_2" },
+ { CODEC_AMR_12_2, "AMR_12_2" },
+ { CODEC_AMR_SID, "AMR_SID" },
+ { 0, NULL }
+};
+
void rtp_provider_register(struct rtp_provider *prov)
{
llist_add_tail(&prov->list, &g_providers);
diff --git a/rtpsource/rtp_provider.h b/rtpsource/rtp_provider.h
index 7048a3e..22ed858 100644
--- a/rtpsource/rtp_provider.h
+++ b/rtpsource/rtp_provider.h
@@ -1,6 +1,7 @@
#pragma once
#include <stdint.h>
#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/utils.h>
enum codec_type {
CODEC_ULAW,
@@ -20,6 +21,8 @@ enum codec_type {
_NUM_CODECS
};
+extern const struct value_string codec_type_names[];
+
struct rtp_provider_instance;
struct rtp_provider {
diff --git a/rtpsource/rtpsource.c b/rtpsource/rtpsource.c
index 3087262..d5ffce5 100644
--- a/rtpsource/rtpsource.c
+++ b/rtpsource/rtpsource.c
@@ -63,11 +63,10 @@ struct rtp_connection *find_connection_by_cname(struct rtpsource_state *rss, con
}
/* create a new RTP connection for given CNAME; includes binding of local RTP port */
-struct rtp_connection *create_connection(struct rtpsource_state *rss, const char *cname)
+struct rtp_connection *create_connection(struct rtpsource_state *rss, const char *cname, enum codec_type codec)
{
const struct rtp_provider *rtp_prov;
struct rtp_connection *conn;
- enum codec_type codec = CODEC_GSM_FR; // TODO: configurable
const char *host;
int port;
int rc;
@@ -101,8 +100,8 @@ struct rtp_connection *create_connection(struct rtpsource_state *rss, const char
llist_add_tail(&conn->list, &rss->connections);
- CLOGP(conn, DMAIN, LOGL_INFO, "Created RTP connection; local=%s:%u\n",
- conn->local_host, conn->local_port);
+ CLOGP(conn, DMAIN, LOGL_INFO, "Created RTP connection; local=%s:%u; codec=%s\n",
+ conn->local_host, conn->local_port, get_value_string(codec_type_names, codec));
return conn;