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
This commit is contained in:
Oliver Smith 2020-04-27 16:58:02 +02:00
parent d22fa8b1c1
commit 0193c914e4
4 changed files with 39 additions and 11 deletions

View File

@ -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,%u' % (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 = 2 # 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

View File

@ -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;
}
conn = create_connection(g_rss, cname);
codec = atoi(codec_str);
if (codec < 0 || codec >= _NUM_CODECS) {
cmd->reply = "Invalid codec";
goto error;
}
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");

View File

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

View File

@ -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=%u\n",
conn->local_host, conn->local_port, codec);
return conn;