start.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include <stdlib.h>
  2. #include "Untrusted.hpp"
  3. #include "start.hpp"
  4. static void route_test(NetIO &netio, char **args)
  5. {
  6. // Count the number of arguments
  7. size_t nargs = 0;
  8. while (args[nargs]) {
  9. ++nargs;
  10. }
  11. uint16_t num_nodes = netio.num_nodes;
  12. size_t sq_nodes = num_nodes;
  13. sq_nodes *= sq_nodes;
  14. if (nargs != sq_nodes) {
  15. printf("Expecting %lu arguments, found %lu\n", sq_nodes, nargs);
  16. return;
  17. }
  18. // The arguments are num_nodes sets of num_nodes values. The jth
  19. // value in the ith set is the number of private routing tokens
  20. // ingestion node i holds for storage node j.
  21. // We are node i = netio.me, so ignore the other sets of values.
  22. uint32_t num_tokens[num_nodes];
  23. uint32_t tot_tokens = 0;
  24. for (nodenum_t j=0;j<num_nodes;++j) {
  25. num_tokens[j] = atoi(args[netio.me*num_nodes+j]);
  26. tot_tokens += num_tokens[j];
  27. }
  28. const Config &config = netio.config();
  29. uint16_t msg_size = config.msg_size;
  30. uint8_t *msgs = new uint8_t[tot_tokens * msg_size];
  31. uint8_t *nextmsg = msgs;
  32. uint32_t dest_uid_mask = (1 << DEST_UID_BITS) - 1;
  33. uint32_t rem_tokens = tot_tokens;
  34. while (rem_tokens > 0) {
  35. // Pick a random remaining token
  36. uint32_t r = uint32_t(lrand48()) % rem_tokens;
  37. for (nodenum_t j=0;j<num_nodes;++j) {
  38. if (r < num_tokens[j]) {
  39. // Use a token from node j
  40. *((uint32_t*)nextmsg) =
  41. (j << DEST_UID_BITS) + (r & dest_uid_mask);
  42. // Put a bunch of copies of r as the message body
  43. for (uint16_t i=1;i<msg_size/4;++i) {
  44. ((uint32_t*)nextmsg)[i] = r;
  45. }
  46. num_tokens[j] -= 1;
  47. rem_tokens -= 1;
  48. nextmsg += msg_size;
  49. } else {
  50. r -= num_tokens[j];
  51. }
  52. }
  53. }
  54. /*
  55. for (uint32_t i=0;i<tot_tokens;++i) {
  56. for(uint16_t j=0;j<msg_size/4;++j) {
  57. printf("%08x ", ((uint32_t*)msgs)[i*msg_size/4+j]);
  58. }
  59. printf("\n");
  60. }
  61. */
  62. // Precompute some WaksmanNetworks
  63. size_t num_sizes = ecall_precompute_sort(-1);
  64. for (int i=0;i<int(num_sizes);++i) {
  65. ecall_precompute_sort(i);
  66. }
  67. if (!ecall_ingest_raw(msgs, tot_tokens)) {
  68. printf("Ingestion failed\n");
  69. return;
  70. }
  71. ecall_routing_proceed([&](uint32_t round_num){
  72. printf("Round %u complete\n", round_num);
  73. //netio.close();
  74. });
  75. }
  76. // Once all the networking is set up, start doing whatever we were asked
  77. // to do on the command line
  78. void start(NetIO &netio, char **args)
  79. {
  80. if (*args && !strcmp(*args, "route")) {
  81. ++args;
  82. route_test(netio, args);
  83. return;
  84. }
  85. }