Commit d4ed0c7f authored by Simon Morlat's avatar Simon Morlat
Browse files

add network simulator settings in linphone-daemon

parent 0ef22d69
......@@ -78,6 +78,7 @@ linphone_daemon_SOURCES=daemon.cc \
commands/unregister.h \
commands/quit.h \
commands/contact.h \
commands/netsim.cc commands/netsim.h\
commands/version.h
linphone_daemon_pipetest_SOURCES=daemon-pipetest.c
......
#include "netsim.h"
using namespace std;
class NetsimResponse : public Response {
public:
NetsimResponse(LinphoneCore *core);
};
NetsimResponse::NetsimResponse(LinphoneCore *lc) : Response() {
ostringstream ost;
const OrtpNetworkSimulatorParams *params=linphone_core_get_network_simulator_params(lc);
ost << "State: ";
if (params->enabled) {
ost << "enabled\n";
} else {
ost << "disabled\n";
}
ost<<"max_bandwidth: "<<params->max_bandwidth<<endl;
ost<<"max_buffer_size: "<<params->max_buffer_size<<endl;
ost<<"loss_rate: "<<params->loss_rate<<endl;
ost<<"latency: "<<params->latency<<endl;
ost<<"consecutive_loss_probability: "<<params->consecutive_loss_probability<<endl;
ost<<"jitter_burst_density: "<<params->jitter_burst_density<<endl;
ost<<"jitter_strength: "<<params->jitter_strength<<endl;
ost<<"mode: "<<ortp_network_simulator_mode_to_string(params->mode)<<endl;
setBody(ost.str().c_str());
}
NetsimCommand::NetsimCommand(): DaemonCommand("netsim","netsim [enabled|disabled|parameters <parameters]",
"Configure the network simulator. Parameters are to be provided in the form param-name=param-value, separated with ';' only. Supported parameters are:\n"
"\tmax_bandwidth (kbit/s)\n"
"\tmax_buffer_size (bits)\n"
"\tloss_rate (percentage)\n"
"\tlatency (milliseconds)\n"
"\tconsecutive_loss_probability (0..1)\n"
"\tjitter_burst_density (frequency of bursts 0..1)\n"
"\tjitter_strength (percentage of max_bandwidth artifically consumed during bursts events)\n"
"\tmode (inbound, outbound, outbound-controlled)\n")
{
addExample(new DaemonCommandExample("netsim",
"Status: Ok\n\n"
"State: disabled\nmax_bandwidth: 384000\nmax_buffer_size: 384000\nloss_rate: 2"));
addExample(new DaemonCommandExample("netsim enable",
"Status: Ok\n\n"
"State: enabled\nmax_bandwidth: 384000\nmax_buffer_size: 384000\nloss_rate: 2"));
addExample(new DaemonCommandExample("netsim parameters loss_rate=5;consecutive_loss_probability=0.5",
"Status: Ok\n\n"
"State: enabled\nmax_bandwidth: 384000\nmax_buffer_size: 384000\nloss_rate: 2"));
}
void NetsimCommand::exec(Daemon* app, const char* args){
LinphoneCore *lc=app->getCore();
OrtpNetworkSimulatorParams params=*linphone_core_get_network_simulator_params(lc);
string subcommand;
istringstream ist(args);
ist >> subcommand;
if (ist.fail()) {
app->sendResponse(NetsimResponse(app->getCore()));
return;
}
if (subcommand.compare("enable")==0){
params.enabled=TRUE;
}else if (subcommand.compare("disable")==0){
params.enabled=FALSE;
}else if (subcommand.compare("parameters")==0){
string parameters;
char value[128]={0};
ist >> parameters;
if (fmtp_get_value(parameters.c_str(),"max_bandwidth",value, sizeof(value))){
params.max_bandwidth=atoi(value);
}
if (fmtp_get_value(parameters.c_str(),"max_buffer_size",value, sizeof(value))){
params.max_buffer_size=atoi(value);
}
if (fmtp_get_value(parameters.c_str(),"loss_rate",value, sizeof(value))){
params.loss_rate=atoi(value);
}
if (fmtp_get_value(parameters.c_str(),"latency",value, sizeof(value))){
params.latency=atoi(value);
}
if (fmtp_get_value(parameters.c_str(),"consecutive_loss_probability",value, sizeof(value))){
params.consecutive_loss_probability=atof(value);
}
if (fmtp_get_value(parameters.c_str(),"jitter_burst_density",value, sizeof(value))){
params.jitter_burst_density=atof(value);
}
if (fmtp_get_value(parameters.c_str(),"jitter_strength",value, sizeof(value))){
params.jitter_strength=atof(value);
}
if (fmtp_get_value(parameters.c_str(),"mode",value, sizeof(value))){
OrtpNetworkSimulatorMode mode=ortp_network_simulator_mode_from_string(value);
if (mode==OrtpNetworkSimulatorInvalid){
app->sendResponse(Response("Invalid mode"));
return;
}
params.mode=mode;
}
}
linphone_core_set_network_simulator_params(lc,&params);
app->sendResponse(NetsimResponse(app->getCore()));
return;
}
#ifndef COMMAND_NETSIM_H_
#define COMMAND_NETSIM_H_
#include "../daemon.h"
class NetsimCommand: public DaemonCommand {
public:
NetsimCommand();
virtual void exec(Daemon *app, const char *args);
};
#endif //COMMAND_NETSIM_H_
......@@ -50,6 +50,7 @@
#include "commands/unregister.h"
#include "commands/quit.h"
#include "commands/configcommand.h"
#include "commands/netsim.h"
#include "commands/version.h"
#include "private.h"
......@@ -469,6 +470,7 @@ void Daemon::initCommands() {
mCommands.push_back(new HelpCommand());
mCommands.push_back(new ConfigGetCommand());
mCommands.push_back(new ConfigSetCommand());
mCommands.push_back(new NetsimCommand());
}
void Daemon::uninitCommands() {
......
oRTP @ 496b5b1f
Subproject commit d515df047678da3777b5e4691dc069c6837f77bf
Subproject commit 496b5b1fd0053bf94e5e0fcecf9cd43713820ca1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment