start.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. if (!ecall_ingest_raw(msgs, tot_tokens)) {
  63. printf("Ingestion failed\n");
  64. return;
  65. }
  66. }
  67. // Once all the networking is set up, start doing whatever we were asked
  68. // to do on the command line
  69. void start(NetIO &netio, char **args)
  70. {
  71. if (*args && !strcmp(*args, "route")) {
  72. ++args;
  73. route_test(netio, args);
  74. return;
  75. }
  76. printf("Reading\n");
  77. for (nodenum_t node_num = 0; node_num < netio.num_nodes; ++node_num) {
  78. if (node_num == netio.me) continue;
  79. NodeIO &node = netio.node(node_num);
  80. node.recv_commands(
  81. // error_cb
  82. [](boost::system::error_code) {
  83. printf("Error\n");
  84. },
  85. // epoch_cb
  86. [](uint32_t epoch) {
  87. printf("Epoch %u\n", epoch);
  88. });
  89. }
  90. }