config.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "Enclave_t.h"
  2. #include "comms.hpp"
  3. #include "config.hpp"
  4. Config g_teems_config;
  5. bool ecall_config_load(EnclaveAPIParams *apiparams,
  6. EnclaveAPINodeConfig *apinodeconfigs,
  7. nodenum_t num_nodes, nodenum_t my_node_num)
  8. {
  9. g_teems_config.num_nodes = num_nodes;
  10. g_teems_config.num_ingestion_nodes = 0;
  11. g_teems_config.num_routing_nodes = 0;
  12. g_teems_config.num_storage_nodes = 0;
  13. g_teems_config.my_node_num = my_node_num;
  14. g_teems_config.user_count = apiparams->user_count;
  15. g_teems_config.msg_size = apiparams->msg_size;
  16. g_teems_config.m_priv_out = apiparams->m_priv_out;
  17. g_teems_config.m_priv_in = apiparams->m_priv_in;
  18. g_teems_config.m_pub_out = apiparams->m_pub_out;
  19. g_teems_config.m_pub_in = apiparams->m_pub_in;
  20. // Temporary vectors to store node numbers for nodes of different
  21. // types, where the node numbers are smaller than our own node
  22. // number
  23. std::vector<nodenum_t> ing_smaller, rte_smaller, str_smaller;
  24. uint16_t cumul_weight = 0;
  25. g_teems_config.weights.clear();
  26. g_teems_config.ingestion_nodes.clear();
  27. g_teems_config.routing_nodes.clear();
  28. g_teems_config.storage_nodes.clear();
  29. for (nodenum_t i=0; i<num_nodes; ++i) {
  30. NodeWeight nw;
  31. nw.startweight = cumul_weight;
  32. nw.weight = apinodeconfigs[i].weight;
  33. if (apinodeconfigs[i].roles & ROLE_INGESTION) {
  34. g_teems_config.num_ingestion_nodes += 1;
  35. if (i < my_node_num) {
  36. ing_smaller.push_back(i);
  37. } else {
  38. g_teems_config.ingestion_nodes.push_back(i);
  39. }
  40. }
  41. if (apinodeconfigs[i].roles & ROLE_ROUTING) {
  42. g_teems_config.num_routing_nodes += 1;
  43. if (i < my_node_num) {
  44. rte_smaller.push_back(i);
  45. } else {
  46. g_teems_config.routing_nodes.push_back(i);
  47. }
  48. }
  49. if (apinodeconfigs[i].roles & ROLE_STORAGE) {
  50. g_teems_config.num_storage_nodes += 1;
  51. if (i < my_node_num) {
  52. str_smaller.push_back(i);
  53. } else {
  54. g_teems_config.storage_nodes.push_back(i);
  55. }
  56. }
  57. cumul_weight += nw.weight;
  58. g_teems_config.weights.push_back(nw);
  59. }
  60. // Concatenate the *_smaller vectors to the ends of the
  61. // g_teems_config.*_nodes vectors. This way, each node has a list
  62. // of nodes of each role starting with itself and "looping around".
  63. // This should make the communication pattern have less of a
  64. // bottleneck.
  65. g_teems_config.ingestion_nodes.insert(
  66. g_teems_config.ingestion_nodes.end(),
  67. ing_smaller.begin(),
  68. ing_smaller.end());
  69. g_teems_config.routing_nodes.insert(
  70. g_teems_config.routing_nodes.end(),
  71. rte_smaller.begin(),
  72. rte_smaller.end());
  73. g_teems_config.storage_nodes.insert(
  74. g_teems_config.storage_nodes.end(),
  75. str_smaller.begin(),
  76. str_smaller.end());
  77. return comms_init_nodestate(apinodeconfigs, num_nodes, my_node_num);
  78. }