Skip to content

Commit

Permalink
Added a --num-commports argument to the wrench daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Dec 13, 2024
1 parent bbf053b commit 7d5e886
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions tools/wrench/wrench-daemon/include/SimulationLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SimulationLauncher {
~SimulationLauncher() = default;

void createSimulation(bool full_log,
unsigned long num_commports,
const std::string &platform_xml,
const std::string &controller_host,
int sleep_us);
Expand Down
2 changes: 2 additions & 0 deletions tools/wrench/wrench-daemon/include/WRENCHDaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class WRENCHDaemon {
public:
WRENCHDaemon(bool simulation_logging,
bool daemon_logging,
unsigned long num_commports,
int port_number,
int fixed_simulation_port_number,
const std::string &allowed_origin,
Expand Down Expand Up @@ -64,6 +65,7 @@ class WRENCHDaemon {

bool simulation_logging;
bool daemon_logging;
unsigned long num_commports;
int port_number;
int fixed_simulation_port_number;
std::string allowed_origin;
Expand Down
9 changes: 6 additions & 3 deletions tools/wrench/wrench-daemon/src/SimulationLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
* simple sets an error message variable and returns
*
* @param full_log: whether to show all simulation log
* @param num_commports: the number of comm ports to use
* @param platform_xml: XML platform description (an XML string - not a file path)
* @param controller_host: hostname of the host that will run the execution_controller
* @param sleep_us: number of microseconds to sleep at each iteration of the main loop
*/
void SimulationLauncher::createSimulation(bool full_log,
unsigned long num_commports,
const std::string &platform_xml,
const std::string &controller_host,
int sleep_us) {
Expand All @@ -35,11 +37,12 @@ void SimulationLauncher::createSimulation(bool full_log,

try {
// Set up command-line arguments
int argc = (full_log ? 2 : 1);
int argc = (full_log ? 3 : 2);
char **argv = (char **) calloc((size_t) argc, sizeof(char *));
argv[0] = strdup("wrench-daemon-simulation");
if (argc > 1) {
argv[1] = strdup("--wrench-full-log");
argv[1] = strdup(("--wrench-commport-pool-size=" + std::to_string(num_commports)).c_str());
if (argc > 2) {
argv[2] = strdup("--wrench-full-log");
}

simulation = wrench::Simulation::createSimulation();
Expand Down
4 changes: 4 additions & 0 deletions tools/wrench/wrench-daemon/src/WRENCHDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ std::vector<std::string> WRENCHDaemon::allowed_origins;
* @brief Constructor
* @param simulation_logging true if simulation logging should be printed
* @param daemon_logging true if daemon logging should be printed
* @param num_commports the number of commports to use
* @param port_number port number on which to listen for 'start simulation' requests
* @param simulation_port_number port number on which to listen for a new simulation (0 means: use a random port each time)
* @param allowed_origin allowed origin for http connection
Expand All @@ -44,11 +45,13 @@ std::vector<std::string> WRENCHDaemon::allowed_origins;
*/
WRENCHDaemon::WRENCHDaemon(bool simulation_logging,
bool daemon_logging,
unsigned long num_commports,
int port_number,
int simulation_port_number,
const std::string &allowed_origin,
int sleep_us) : simulation_logging(simulation_logging),
daemon_logging(daemon_logging),
num_commports(num_commports),
port_number(port_number),
fixed_simulation_port_number(simulation_port_number),
sleep_us(sleep_us) {
Expand Down Expand Up @@ -240,6 +243,7 @@ void WRENCHDaemon::startSimulation(const Request &req, Response &res) {
auto simulation_thread = std::thread([simulation_launcher, this, body, &guard, &signal]() {
// Create simulation
simulation_launcher->createSimulation(this->simulation_logging,
this->num_commports,
body["platform_xml"],
body["controller_hostname"],
this->sleep_us);
Expand Down
8 changes: 8 additions & 0 deletions tools/wrench/wrench-daemon/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ int main(int argc, char **argv) {
"Show full simulation log during execution")
("daemon-logging", po::bool_switch()->default_value(false),
"Show full daemon log during execution")
("num-commports", po::value<unsigned long>()->default_value(5000)->notifier(in(1, 100000, "port")),
"The number of commports that the simulation can use")
("port", po::value<int>()->default_value(8101)->notifier(in(1024, 49151, "port")),
"A port number, between 1024 and 4951, on which this daemon will listen for 'start simulation' requests")
("allow-origin", po::value<std::string>()->default_value(""),
Expand All @@ -69,6 +71,11 @@ int main(int argc, char **argv) {
cerr << "Error: " << e.what() << "\n";
exit(1);
}

unsigned long num_commports = 5000;
if (vm.count("num-commports")) {
num_commports = vm["num-commports"].as<unsigned long>();
}

int simulation_port = 0;
if (vm.count("simulation-port")) {
Expand All @@ -78,6 +85,7 @@ int main(int argc, char **argv) {
// Create and run the WRENCH daemon
WRENCHDaemon daemon(vm["simulation-logging"].as<bool>(),
vm["daemon-logging"].as<bool>(),
num_commports,
vm["port"].as<int>(),
simulation_port,
vm["allow-origin"].as<std::string>(),
Expand Down

0 comments on commit 7d5e886

Please sign in to comment.