orchestratorMain.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * <lambda> - a positive integer that determines the absolute soundness parameter
  20. * for batched proofs
  21. * <servers_are_malicious> - a bool (given as T/t or F/f)
  22. * which is true when servers are in malicious security
  23. * and false when they are in HBC security
  24. */
  25. int main(int argc, char* argv[])
  26. {
  27. /*
  28. * PRELIMINARY SETUP CODE
  29. */
  30. #if USE_SSL
  31. mg_init_library(MG_FEATURES_SSL);
  32. #else
  33. mg_init_library(0);
  34. #endif
  35. string output = "default";
  36. if (argc > 1)
  37. output = argv[1];
  38. size_t lambda = 0;
  39. if (argc > 2)
  40. lambda = atoi(argv[2]);
  41. // Default to malicious security if not specified
  42. bool maliciousServers = true;
  43. if (argc > 3)
  44. maliciousServers = argv[3][0] == 't' || argv[3][0] == 'T';
  45. vector<string> serverIPs, clientIPs;
  46. vector<int> serverPorts, clientPorts;
  47. string dealerIP, dealerPortStr;
  48. int dealerPort = 0;
  49. std::map<std::string,std::string> targeter;
  50. targeter["129.97.119.208"] = "tick0";
  51. targeter["129.97.119.209"] = "tick1";
  52. string configDir = "cfg/" + output;
  53. // Read in from config files the server locations
  54. load_multiple_instances_config(serverIPs, serverPorts, configDir + "/serverIPs.cfg");
  55. // And now the client locations
  56. load_multiple_instances_config(clientIPs, clientPorts, configDir + "/clientIPs.cfg");
  57. // And finally the dealer location
  58. load_single_instance_config(dealerIP, dealerPortStr, dealerPort, configDir + "/dealerIP.cfg");
  59. size_t numServers = serverIPs.size();
  60. size_t numClients = clientIPs.size();
  61. /*
  62. * ORCHESTRATOR SETUP CODE
  63. */
  64. cout << "[ORC] This experiment is running with output code: " << output << endl;
  65. cout << "[ORC] This experiment is running with " << (maliciousServers ? "MALICIOUS" : "HBC") << " servers." << endl;
  66. cout << endl;
  67. cout << "[ORC] Starting BGN dealer server." << endl;
  68. vector<thread> serverStartup, clientStartup;
  69. serverStartup.push_back(thread(start_remote_actor, targeter[dealerIP], true, "d", output, lambda, maliciousServers));
  70. this_thread::sleep_for(ONE_SECOND);
  71. cout << "[ORC] Starting other servers." << endl;
  72. for (size_t i = 0; i < numServers; i++)
  73. {
  74. if (serverIPs[i] == dealerIP && serverPorts[i] == dealerPort)
  75. continue;
  76. serverStartup.push_back(thread(start_remote_actor, targeter[serverIPs[i]], true, "s" + to_string(i), output, lambda, maliciousServers));
  77. }
  78. cout << "[ORC] Waiting for confirmation that servers are ready to continue." << endl;
  79. for (size_t i = 0; i < numServers; i++)
  80. serverStartup[i].join();
  81. wait_for_servers_ready(dealerIP, dealerPort);
  82. cout << "[ORC] Starting clients." << endl;
  83. for (size_t i = 0; i < numClients; i++)
  84. {
  85. clientStartup.push_back(thread(start_remote_actor, targeter[clientIPs[i]], false, "c" + to_string(i), output, lambda, maliciousServers));
  86. this_thread::sleep_for(ONE_SECOND);
  87. }
  88. cout << "[ORC] Waiting for confirmation that servers have all clients logged." << endl;
  89. for (size_t i = 0; i < numClients; i++)
  90. clientStartup[i].join();
  91. wait_for_clients_ready(dealerIP, dealerPort, numClients);
  92. /*
  93. * MAIN ORCHESTRATOR LOOP CODE
  94. */
  95. cout << "[ORC] Beginning experiment." << endl;
  96. execute_experiment(dealerIP, dealerPort, "cfg/commands.cfg");
  97. /*
  98. * SHUTDOWN CODE
  99. */
  100. cout << "[ORC] Finishing experiment." << endl;
  101. cout << "[ORC] Sending shutdown commands to clients." << endl;
  102. shut_down_remote_actors(clientIPs, clientPorts);
  103. cout << "[ORC] Sending shutdown commands to servers." << endl;
  104. shut_down_remote_actors(serverIPs, serverPorts);
  105. return 0;
  106. }