test_ats_reservation_api.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2010-2015 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file ats/test_ats_reservation_api.c
  18. * @brief test ATS bandwidth reservation API
  19. * @author Christian Grothoff
  20. */
  21. #include "platform.h"
  22. #include "test_ats_lib.h"
  23. /**
  24. * Global timeout for the testcase.
  25. */
  26. #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
  27. /**
  28. * Definition of the test as a sequence of commands.
  29. */
  30. static struct Command test_commands[] = {
  31. /* 0: add initial address */
  32. {
  33. .code = CMD_ADD_ADDRESS,
  34. .label = "add-address-0-0",
  35. .details.add_address = {
  36. .pid = 0,
  37. .addr_num = 0,
  38. .session = 0,
  39. .properties = {
  40. /* use network with 65k quota! */
  41. .scope = GNUNET_NT_WAN
  42. }
  43. }
  44. },
  45. /* 1: some solver still require explicit start */
  46. {
  47. .code = CMD_REQUEST_CONNECTION_START,
  48. .label = "request-0",
  49. .details.request_connection_start = {
  50. .pid = 0
  51. }
  52. },
  53. /* 2: check we got an address */
  54. {
  55. .code = CMD_AWAIT_ADDRESS_SUGGESTION,
  56. .details.await_address_suggestion = {
  57. .add_label = "add-address-0-0"
  58. }
  59. },
  60. /* 3: sleep 7s, should give us 5s * 64k/s = 320k buffer;
  61. Note that this depends on MAX_BANDWIDTH_CARRY_S. We
  62. sleep more than 5s to show that only MAX_BANDWIDTH carries. */
  63. {
  64. .code = CMD_SLEEP,
  65. .label = "sleep",
  66. .details.sleep.delay = { 7 * 1000LL * 1000LL }
  67. },
  68. /* 4: reserve 128k -- should work (5s carry, so we had 320k) */
  69. {
  70. .code = CMD_RESERVE_BANDWIDTH,
  71. .details.reserve_bandwidth = {
  72. .pid = 0,
  73. .amount = 128 * 1024,
  74. .expected_result = GNUNET_YES
  75. }
  76. },
  77. /* 5: reserve another 192k -- should just work (now exactly pushing the limit) */
  78. {
  79. .code = CMD_RESERVE_BANDWIDTH,
  80. .label = "big reservation",
  81. .details.reserve_bandwidth = {
  82. .pid = 0,
  83. .amount = 192 * 1024,
  84. .expected_result = GNUNET_YES
  85. }
  86. },
  87. /* 6: reserve another 32k -- should now fail (if MAX_BANDWIDTH_CARRY_S
  88. is precisely observed) */
  89. {
  90. .code = CMD_RESERVE_BANDWIDTH,
  91. .label = "failing reservation",
  92. .details.reserve_bandwidth = {
  93. .pid = 0,
  94. .amount = 32 * 1024,
  95. .expected_result = GNUNET_SYSERR
  96. }
  97. },
  98. /* 7: sleep 3s, should give us 3s * 64k/s - 32k = 160k buffer */
  99. {
  100. .code = CMD_SLEEP,
  101. .label = "sleep",
  102. .details.sleep.delay = { 6 * 1000LL * 1000LL }
  103. },
  104. /* 8: reserve another 160k -- should now work */
  105. {
  106. .code = CMD_RESERVE_BANDWIDTH,
  107. .label = "successful final reservation",
  108. .details.reserve_bandwidth = {
  109. .pid = 0,
  110. .amount = 160 * 1024,
  111. .expected_result = GNUNET_YES
  112. }
  113. },
  114. /* 9: remove address */
  115. {
  116. .code = CMD_DEL_ADDRESS,
  117. .details.del_address = {
  118. .add_label = "add-address-0-0"
  119. }
  120. },
  121. /* 10: check we got disconnected */
  122. {
  123. .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
  124. .details.await_disconnect_suggestion = {
  125. .pid = 0
  126. }
  127. },
  128. /* 11: just for symmetry, also stop asking for the connection */
  129. {
  130. .code = CMD_REQUEST_CONNECTION_STOP,
  131. .details.request_connection_stop = {
  132. .connect_label = "request-0",
  133. }
  134. },
  135. /* Test ends successfully */
  136. {
  137. .code = CMD_END_PASS
  138. }
  139. };
  140. int
  141. main(int argc,
  142. char *argv[])
  143. {
  144. return TEST_ATS_run(argc,
  145. argv,
  146. test_commands,
  147. TIMEOUT);
  148. }
  149. /* end of file test_ats_reservation_api.c */