test_ats2_lib.h 11 KB

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