orchestratorMain.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. // Default to not proof batching if not specified
  39. size_t lambda = 0;
  40. if (argc > 2)
  41. lambda = atoi(argv[2]);
  42. // Default to malicious security if not specified
  43. bool maliciousServers = true;
  44. if (argc > 3)
  45. maliciousServers = argv[3][0] == 't' || argv[3][0] == 'T';
  46. vector<string> serverIPs, clientIPs;
  47. vector<int> serverPorts, clientPorts;
  48. string dealerIP, dealerPortStr;
  49. int dealerPort = 0;
  50. std::map<std::string,std::string> targeter;
  51. targeter["129.97.119.208"] = "tick0";
  52. targeter["129.97.119.209"] = "tick1";
  53. string configDir = "cfg/" + output;
  54. // Read in from config files the server locations
  55. load_multiple_instances_config(serverIPs, serverPorts, (configDir + "/serverIPs.cfg").c_str());
  56. // And now the client locations
  57. load_multiple_instances_config(clientIPs, clientPorts, (configDir + "/clientIPs.cfg").c_str());
  58. // And finally the dealer location
  59. load_single_instance_config(dealerIP, dealerPortStr, dealerPort, (configDir + "/dealerIP.cfg").c_str());
  60. size_t numServers = serverIPs.size();
  61. size_t numClients = clientIPs.size();
  62. /*
  63. * ORCHESTRATOR SETUP CODE
  64. */
  65. cout << "[ORC] This experiment is running with output code: " << output << endl;
  66. cout << "[ORC] This experiment is running with " << (maliciousServers ? "MALICIOUS" : "HBC") << " servers." << endl;
  67. cout << endl;
  68. cout << "[ORC] Starting BGN dealer server." << endl;
  69. vector<thread> serverStartup, clientStartup;
  70. serverStartup.push_back(thread(start_remote_actor, targeter[dealerIP], true, "d", output, lambda, maliciousServers));
  71. this_thread::sleep_for(ONE_SECOND);
  72. cout << "[ORC] Starting other servers." << endl;
  73. for (size_t i = 0; i < numServers; i++)
  74. {
  75. if (serverIPs[i] == dealerIP && serverPorts[i] == dealerPort)
  76. continue;
  77. serverStartup.push_back(thread(start_remote_actor, targeter[serverIPs[i]], true, "s" + to_string(i), output, lambda, maliciousServers));
  78. }
  79. cout << "[ORC] Waiting for confirmation that servers are ready to continue." << endl;
  80. for (size_t i = 0; i < numServers; i++)
  81. serverStartup[i].join();
  82. wait_for_servers_ready(dealerIP, dealerPort);
  83. cout << "[ORC] Starting clients." << endl;
  84. for (size_t i = 0; i < numClients; i++)
  85. {
  86. clientStartup.push_back(thread(start_remote_actor, targeter[clientIPs[i]], false, "c" + to_string(i), output, lambda, maliciousServers));
  87. this_thread::sleep_for(ONE_SECOND);
  88. }
  89. cout << "[ORC] Waiting for confirmation that servers have all clients logged." << endl;
  90. for (size_t i = 0; i < numClients; i++)
  91. clientStartup[i].join();
  92. wait_for_clients_ready(dealerIP, dealerPort, numClients);
  93. /*
  94. * MAIN ORCHESTRATOR LOOP CODE
  95. */
  96. cout << "[ORC] Beginning experiment." << endl;
  97. execute_experiment(dealerIP, dealerPort, "cfg/commands.cfg");
  98. /*
  99. * SHUTDOWN CODE
  100. */
  101. cout << "[ORC] Finishing experiment." << endl;
  102. cout << "[ORC] Sending shutdown commands to clients." << endl;
  103. shut_down_remote_actors(clientIPs, clientPorts);
  104. cout << "[ORC] Sending shutdown commands to servers." << endl;
  105. shut_down_remote_actors(serverIPs, serverPorts);
  106. return 0;
  107. }