/* netsim.cc Copyright (C) 2016 Belledonne Communications, Grenoble, France This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #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: "<max_bandwidth<max_buffer_size<loss_rate<latency<consecutive_loss_probability<jitter_burst_density<jitter_strength<mode)<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,¶ms); app->sendResponse(NetsimResponse(app->getCore())); return; }