From 7d5e886ff3d06a92815833e6d31d29603a27c468 Mon Sep 17 00:00:00 2001 From: Henri Casanova Date: Fri, 13 Dec 2024 12:30:07 -1000 Subject: [PATCH] Added a --num-commports argument to the wrench daemon --- tools/wrench/wrench-daemon/include/SimulationLauncher.h | 1 + tools/wrench/wrench-daemon/include/WRENCHDaemon.h | 2 ++ tools/wrench/wrench-daemon/src/SimulationLauncher.cpp | 9 ++++++--- tools/wrench/wrench-daemon/src/WRENCHDaemon.cpp | 4 ++++ tools/wrench/wrench-daemon/src/main.cpp | 8 ++++++++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tools/wrench/wrench-daemon/include/SimulationLauncher.h b/tools/wrench/wrench-daemon/include/SimulationLauncher.h index 100e06b1a8..27fe8110a0 100755 --- a/tools/wrench/wrench-daemon/include/SimulationLauncher.h +++ b/tools/wrench/wrench-daemon/include/SimulationLauncher.h @@ -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); diff --git a/tools/wrench/wrench-daemon/include/WRENCHDaemon.h b/tools/wrench/wrench-daemon/include/WRENCHDaemon.h index b88bdf706b..987af81536 100644 --- a/tools/wrench/wrench-daemon/include/WRENCHDaemon.h +++ b/tools/wrench/wrench-daemon/include/WRENCHDaemon.h @@ -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, @@ -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; diff --git a/tools/wrench/wrench-daemon/src/SimulationLauncher.cpp b/tools/wrench/wrench-daemon/src/SimulationLauncher.cpp index 95e8d28a86..015c76069a 100755 --- a/tools/wrench/wrench-daemon/src/SimulationLauncher.cpp +++ b/tools/wrench/wrench-daemon/src/SimulationLauncher.cpp @@ -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) { @@ -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(); diff --git a/tools/wrench/wrench-daemon/src/WRENCHDaemon.cpp b/tools/wrench/wrench-daemon/src/WRENCHDaemon.cpp index 67874c78d3..05b84dda2f 100644 --- a/tools/wrench/wrench-daemon/src/WRENCHDaemon.cpp +++ b/tools/wrench/wrench-daemon/src/WRENCHDaemon.cpp @@ -36,6 +36,7 @@ std::vector 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 @@ -44,11 +45,13 @@ std::vector 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) { @@ -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); diff --git a/tools/wrench/wrench-daemon/src/main.cpp b/tools/wrench/wrench-daemon/src/main.cpp index 16ba67be48..7feedb524e 100644 --- a/tools/wrench/wrench-daemon/src/main.cpp +++ b/tools/wrench/wrench-daemon/src/main.cpp @@ -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()->default_value(5000)->notifier(in(1, 100000, "port")), + "The number of commports that the simulation can use") ("port", po::value()->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()->default_value(""), @@ -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(); + } int simulation_port = 0; if (vm.count("simulation-port")) { @@ -78,6 +85,7 @@ int main(int argc, char **argv) { // Create and run the WRENCH daemon WRENCHDaemon daemon(vm["simulation-logging"].as(), vm["daemon-logging"].as(), + num_commports, vm["port"].as(), simulation_port, vm["allow-origin"].as(),