orchestratorMain.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * orchestratorMain.cpp
  3. * - compiles to bin/orchestrator
  4. * - initiates a set of servers and clients, then commands them, for PRSONA experiments
  5. *
  6. * Stan Gurtler
  7. */
  8. #include <iostream>
  9. #include <fstream>
  10. #include <thread>
  11. #include "networkOrchestrator.hpp"
  12. using namespace std;
  13. /**
  14. * This program (bin/orchestrator) expects to be called as follows:
  15. * `bin/orchestrator <output> <servers_are_malicious>`
  16. *
  17. * <output> - a string that will name the files in which outputs for this run of
  18. * the experiment will be written (that is, timings and traffic data)
  19. * <servers_are_malicious> - a bool (given as T/t or F/f)
  20. * which is true when servers are in malicious security
  21. * and false when they are in HBC security
  22. */
  23. int main(int argc, char* argv[])
  24. {
  25. /*
  26. * PRELIMINARY SETUP CODE
  27. */
  28. #if USE_SSL
  29. mg_init_library(MG_FEATURES_SSL);
  30. #else
  31. mg_init_library(0);
  32. #endif
  33. string output = "default";
  34. if (argc > 1)
  35. output = argv[1];
  36. // Default to malicious security if not specified
  37. bool maliciousServers = true;
  38. if (argc > 2)
  39. {
  40. bool setting = argv[2][0] == 't' || argv[2][0] == 'T';
  41. maliciousServers = setting;
  42. }
  43. vector<string> serverIPs, clientIPs;
  44. vector<int> serverPorts, clientPorts;
  45. string dealerIP, dealerPortStr;
  46. int dealerPort = 0;
  47. std::map<std::string,std::string> targeter;
  48. targeter["129.97.119.208"] = "tick0";
  49. targeter["129.97.119.209"] = "tick1";
  50. // Read in from config files the server locations
  51. load_multiple_instances_config(serverIPs, serverPorts, "cfg/serverIPs.cfg");
  52. // And now the client locations
  53. load_multiple_instances_config(clientIPs, clientPorts, "cfg/clientIPs.cfg");
  54. // And finally the dealer location
  55. load_single_instance_config(dealerIP, dealerPortStr, dealerPort, "cfg/dealerIP.cfg");
  56. size_t numServers = serverIPs.size();
  57. size_t numClients = clientIPs.size();
  58. /*
  59. * ORCHESTRATOR SETUP CODE
  60. */
  61. cout << "[ORC] This experiment is running with output code: " << output << endl;
  62. cout << "[ORC] This experiment is running with " << (maliciousServers ? "MALICIOUS" : "HBC") << " servers." << endl;
  63. cout << endl;
  64. cout << "[ORC] Starting BGN dealer server." << endl;
  65. vector<thread> serverStartup, clientStartup;
  66. serverStartup.push_back(thread(start_remote_actor, targeter[dealerIP], true, "d", output, maliciousServers));
  67. this_thread::sleep_for(ONE_SECOND);
  68. cout << "[ORC] Starting other servers." << endl;
  69. for (size_t i = 0; i < numServers; i++)
  70. {
  71. if (serverIPs[i] == dealerIP && serverPorts[i] == dealerPort)
  72. continue;
  73. serverStartup.push_back(thread(start_remote_actor, targeter[serverIPs[i]], true, "s" + to_string(i), output, maliciousServers));
  74. }
  75. cout << "[ORC] Waiting for confirmation that servers are ready to continue." << endl;
  76. for (size_t i = 0; i < numServers; i++)
  77. serverStartup[i].join();
  78. wait_for_servers_ready(dealerIP, dealerPort);
  79. cout << "[ORC] Starting clients." << endl;
  80. for (size_t i = 0; i < numClients; i++)
  81. {
  82. clientStartup.push_back(thread(start_remote_actor, targeter[clientIPs[i]], false, "c" + to_string(i), output, maliciousServers));
  83. this_thread::sleep_for(ONE_SECOND);
  84. }
  85. cout << "[ORC] Waiting for confirmation that servers have all clients logged." << endl;
  86. for (size_t i = 0; i < numClients; i++)
  87. clientStartup[i].join();
  88. wait_for_clients_ready(dealerIP, dealerPort, numClients);
  89. /*
  90. * MAIN ORCHESTRATOR LOOP CODE
  91. */
  92. cout << "[ORC] Beginning experiment." << endl;
  93. execute_experiment(dealerIP, dealerPort, "cfg/commands.cfg");
  94. /*
  95. * SHUTDOWN CODE
  96. */
  97. cout << "[ORC] Finishing experiment." << endl;
  98. cout << "[ORC] Sending shutdown commands to clients." << endl;
  99. shut_down_remote_actors(clientIPs, clientPorts);
  100. cout << "[ORC] Sending shutdown commands to servers." << endl;
  101. shut_down_remote_actors(serverIPs, serverPorts);
  102. return 0;
  103. }