test_ats_lib.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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_lib.h
  18. * @brief test ATS library with a generic interpreter for running ATS tests
  19. * @author Christian Grothoff
  20. */
  21. #ifndef TEST_ATS_LIB_H
  22. #define TEST_ATS_LIB_H
  23. #include "gnunet_util_lib.h"
  24. #include "gnunet_ats_service.h"
  25. #include "gnunet_testing_lib.h"
  26. /**
  27. * Commands for the interpreter.
  28. */
  29. enum CommandCode
  30. {
  31. /**
  32. * End the test (passing).
  33. */
  34. CMD_END_PASS = 0,
  35. /**
  36. * Call #GNUNET_ATS_address_add().
  37. */
  38. CMD_ADD_ADDRESS,
  39. /**
  40. * Call #GNUNET_ATS_address_del().
  41. */
  42. CMD_DEL_ADDRESS,
  43. /**
  44. * Wait for ATS to suggest address.
  45. */
  46. CMD_AWAIT_ADDRESS_SUGGESTION,
  47. /**
  48. * Wait for ATS to suggest disconnect.
  49. */
  50. CMD_AWAIT_DISCONNECT_SUGGESTION,
  51. /**
  52. * Ask ATS to connect to a peer, using
  53. * #GNUNET_ATS_connectivity_suggest().
  54. */
  55. CMD_REQUEST_CONNECTION_START,
  56. /**
  57. * Tell ATS we no longer need a connection to a peer, using
  58. * #GNUNET_ATS_connectivity_suggest_cancel().
  59. */
  60. CMD_REQUEST_CONNECTION_STOP,
  61. /**
  62. * Wait for certain address information to be provided.
  63. */
  64. CMD_AWAIT_ADDRESS_INFORMATION,
  65. /**
  66. * Update properties of an address, using
  67. * #GNUNET_ATS_address_update().
  68. */
  69. CMD_UPDATE_ADDRESS,
  70. /**
  71. * Add session to an address, using
  72. * #GNUNET_ATS_address_add_session().
  73. */
  74. CMD_ADD_SESSION,
  75. /**
  76. * Remove session from an address, using
  77. * #GNUNET_ATS_address_del_session().
  78. */
  79. CMD_DEL_SESSION,
  80. /**
  81. * Change performance preferences for a peer, testing
  82. * #GNUNET_ATS_performance_change_preference().
  83. */
  84. CMD_CHANGE_PREFERENCE,
  85. /**
  86. * Provide allocation quality feedback, testing
  87. * #GNUNET_ATS_performance_give_feedback().
  88. */
  89. CMD_PROVIDE_FEEDBACK,
  90. /**
  91. * Obtain list of all addresses, testing
  92. * #GNUNET_ATS_performance_list_addresses().
  93. */
  94. CMD_LIST_ADDRESSES,
  95. /**
  96. * Reserve bandwidth, testing
  97. * #GNUNET_ATS_reserve_bandwidth().
  98. */
  99. CMD_RESERVE_BANDWIDTH,
  100. /**
  101. * Wait for a bit.
  102. */
  103. CMD_SLEEP
  104. };
  105. /**
  106. * Details for the #CMD_ADD_ADDRESS command.
  107. */
  108. struct CommandAddAddress
  109. {
  110. /**
  111. * Number of the peer (used to generate PID).
  112. */
  113. unsigned int pid;
  114. /**
  115. * Number of the address (used to generate binary address).
  116. */
  117. unsigned int addr_num;
  118. /**
  119. * Session to supply, 0 for NULL.
  120. */
  121. unsigned int session;
  122. /**
  123. * Flags to set for the address.
  124. */
  125. enum GNUNET_HELLO_AddressInfo addr_flags;
  126. /**
  127. * Performance properties to supply.
  128. */
  129. struct GNUNET_ATS_Properties properties;
  130. /**
  131. * Expect the operation to fail (duplicate).
  132. */
  133. int expect_fail;
  134. /**
  135. * Here the result of the add address operation will be stored.
  136. */
  137. struct GNUNET_ATS_AddressRecord *ar;
  138. };
  139. /**
  140. * Details for the #CMD_DEL_ADDRESS command.
  141. */
  142. struct CommandDelAddress
  143. {
  144. /**
  145. * Label of the corresponding #CMD_ADD_ADDRESS that
  146. * we are now to remove.
  147. */
  148. const char *add_label;
  149. };
  150. /**
  151. * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
  152. */
  153. struct CommandAwaitAddressSuggestion
  154. {
  155. /**
  156. * For which peer do we expect a suggestion?
  157. */
  158. unsigned int pid;
  159. /**
  160. * If we expect the address suggested to match a particular
  161. * addition, specify the label of the add operation here. Otherwise
  162. * use NULL for "any" available address.
  163. */
  164. const char *add_label;
  165. };
  166. /**
  167. * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command.
  168. */
  169. struct CommandAwaitDisconnectSuggestion
  170. {
  171. /**
  172. * For which peer do we expect the disconnect?
  173. */
  174. unsigned int pid;
  175. };
  176. /**
  177. * Details for the #CMD_REQUEST_CONNECTION_START command.
  178. */
  179. struct CommandRequestConnectionStart
  180. {
  181. /**
  182. * Identity of the peer we would like to connect to.
  183. */
  184. unsigned int pid;
  185. /**
  186. * Location where we store the handle returned from
  187. * #GNUNET_ATS_connectivity_suggest().
  188. */
  189. struct GNUNET_ATS_ConnectivitySuggestHandle *csh;
  190. };
  191. /**
  192. * Details for the #CMD_REQUEST_CONNECTION_STOP command.
  193. */
  194. struct CommandRequestConnectionStop
  195. {
  196. /**
  197. * Label of the corresponding #CMD_REQUEST_CONNECTION_START that
  198. * we are now stopping.
  199. */
  200. const char *connect_label;
  201. };
  202. /**
  203. * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
  204. */
  205. struct CommandAwaitAddressInformation
  206. {
  207. /**
  208. * For which address do we expect information?
  209. * The address is identified by the respective
  210. * label of the corresponding add operation.
  211. */
  212. const char *add_label;
  213. /**
  214. * Label of a possible update operation that may
  215. * have modified the properties. NULL to use
  216. * the properties from the @e add_label.
  217. */
  218. const char *update_label;
  219. };
  220. /**
  221. * Details for the #CMD_UPDATE_ADDRESS command.
  222. */
  223. struct CommandUpdateAddress
  224. {
  225. /**
  226. * Label of the addresses's add operation.
  227. */
  228. const char *add_label;
  229. /**
  230. * Performance properties to supply.
  231. */
  232. struct GNUNET_ATS_Properties properties;
  233. };
  234. /**
  235. * Details for the #CMD_ADD_SESSION command.
  236. */
  237. struct CommandAddSession
  238. {
  239. /**
  240. * Label of the addresses's add operation.
  241. */
  242. const char *add_label;
  243. /**
  244. * Session to supply.
  245. */
  246. unsigned int session;
  247. };
  248. /**
  249. * Details for the #CMD_DEL_SESSION command.
  250. */
  251. struct CommandDelSession
  252. {
  253. /**
  254. * Label of the addresses's add operation.
  255. */
  256. const char *add_session_label;
  257. };
  258. /**
  259. * Details for the #CMD_CHANGE_PREFERENCE command.
  260. */
  261. struct CommandChangePreference
  262. {
  263. /**
  264. * Identity of the peer we have a preference change towards.
  265. */
  266. unsigned int pid;
  267. /* FIXME: preference details! */
  268. };
  269. /**
  270. * Details for the #CMD_PROVIDE_FEEDBACK command.
  271. */
  272. struct CommandProvideFeedback
  273. {
  274. /**
  275. * Identity of the peer we have a feedback for.
  276. */
  277. unsigned int pid;
  278. /**
  279. * Over which timeframe does the feedback apply?
  280. */
  281. struct GNUNET_TIME_Relative scope;
  282. /* FIXME: feedback details! */
  283. };
  284. /**
  285. * Details for the #CMD_LIST_ADDRESSES command.
  286. */
  287. struct CommandListAddresses
  288. {
  289. /**
  290. * Identity of the peer we want a list for.
  291. */
  292. unsigned int pid;
  293. /**
  294. * All addresses or just active?
  295. */
  296. int all;
  297. /**
  298. * Minimum number of addresses the callback may report.
  299. */
  300. unsigned int min_calls;
  301. /**
  302. * Maximum number of addresses the callback may report.
  303. */
  304. unsigned int max_calls;
  305. /**
  306. * Minimum number of active addresses the callback may report.
  307. */
  308. unsigned int min_active_calls;
  309. /**
  310. * Maximum number of active addresses the callback may report.
  311. */
  312. unsigned int max_active_calls;
  313. /**
  314. * Number of calls the command invoked the callback with
  315. * an address marked as active. (Set by command).
  316. */
  317. unsigned int active_calls;
  318. /**
  319. * Number of calls the command invoked the callback with
  320. * any address marked as available to ATS. (Set by command).
  321. */
  322. unsigned int calls;
  323. /**
  324. * Location where we store the return value from
  325. * #GNUNET_ATS_performance_list_addresses().
  326. */
  327. struct GNUNET_ATS_AddressListHandle *alh;
  328. };
  329. /**
  330. * Details for the #CMD_RESERVE_BANDWIDTH command.
  331. */
  332. struct CommandReserveBandwidth
  333. {
  334. /**
  335. * For which peer do we reserve bandwidth?
  336. */
  337. unsigned int pid;
  338. /**
  339. * How much should we try to reserve?
  340. */
  341. int32_t amount;
  342. /**
  343. * Should we expect this to work or fail?
  344. * #GNUNET_YES: must work
  345. * #GNUNET_NO: may work or fail
  346. * #GNUNET_SYSERR: must fail
  347. */
  348. int expected_result;
  349. /**
  350. * Location where we store the return value from
  351. * #GNUNET_ATS_reserve_bandwidth().
  352. */
  353. struct GNUNET_ATS_ReservationContext *rc;
  354. };
  355. /**
  356. * Details for the #CMD_SLEEP command.
  357. */
  358. struct CommandSleep
  359. {
  360. /**
  361. * How long should we wait before running the next command?
  362. */
  363. struct GNUNET_TIME_Relative delay;
  364. };
  365. /**
  366. * A command for the test case interpreter.
  367. */
  368. struct Command
  369. {
  370. /**
  371. * Command code to run.
  372. */
  373. enum CommandCode code;
  374. /**
  375. * Commands can be given a label so we can reference them later.
  376. */
  377. const char *label;
  378. /**
  379. * Additional arguments to commands, if any.
  380. */
  381. union
  382. {
  383. struct CommandAddAddress add_address;
  384. struct CommandDelAddress del_address;
  385. struct CommandAwaitAddressSuggestion await_address_suggestion;
  386. struct CommandAwaitDisconnectSuggestion await_disconnect_suggestion;
  387. struct CommandRequestConnectionStart request_connection_start;
  388. struct CommandRequestConnectionStop request_connection_stop;
  389. struct CommandAwaitAddressInformation await_address_information;
  390. struct CommandUpdateAddress update_address;
  391. struct CommandAddSession add_session;
  392. struct CommandDelSession del_session;
  393. struct CommandChangePreference change_preference;
  394. struct CommandProvideFeedback provide_feedback;
  395. struct CommandListAddresses list_addresses;
  396. struct CommandReserveBandwidth reserve_bandwidth;
  397. struct CommandSleep sleep;
  398. } details;
  399. };
  400. /**
  401. * Run ATS test.
  402. *
  403. * @param argc length of @a argv
  404. * @param argv command line
  405. * @param cmds commands to run with the interpreter
  406. * @param timeout how long is the test allowed to take?
  407. * @return 0 on success
  408. */
  409. int
  410. TEST_ATS_run (int argc,
  411. char *argv[],
  412. struct Command *cmds,
  413. struct GNUNET_TIME_Relative timeout);
  414. #endif